Fix GL_LINEAR_MIPMAP_LINEAR error
This commit is contained in:
parent
d872eb0b55
commit
8fd8d5ec29
@ -3,9 +3,9 @@
|
|||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
Fix known issues:
|
Fix known issues:
|
||||||
- [ ] Fix GL_LINEAR_MIPMAP_LINEAR error
|
|
||||||
- [ ] Use cached textures when loading meshes instead of always loading the textures again for each mesh
|
- [ ] Use cached textures when loading meshes instead of always loading the textures again for each mesh
|
||||||
- [ ] Fix apparently incorrect light radius of lights visible through scaled portals
|
- [ ] Fix apparently incorrect light radius of lights visible through scaled portals
|
||||||
|
- [x] Fix GL_LINEAR_MIPMAP_LINEAR error
|
||||||
|
|
||||||
Add new features:
|
Add new features:
|
||||||
- [ ] Text and UI rendering
|
- [ ] Text and UI rendering
|
||||||
|
|||||||
@ -675,7 +675,8 @@ void game::Sector::BakeLightmap()
|
|||||||
GL_RGB,
|
GL_RGB,
|
||||||
GL_RGB,
|
GL_RGB,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
GL_LINEAR
|
true, // LINEAR
|
||||||
|
false // No mipmaps
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,31 @@
|
|||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
|
||||||
gfx::Texture::Texture(GLuint width, GLuint height, const void* data, GLint internalformat, GLenum format, GLenum type, GLenum filter) {
|
static void GetGLFilterModes(bool linear, bool mipmaps, GLenum& filter_min, GLenum& filter_mag) {
|
||||||
|
if (linear)
|
||||||
|
{
|
||||||
|
filter_min = GL_LINEAR;
|
||||||
|
filter_mag = GL_LINEAR;
|
||||||
|
|
||||||
|
if (mipmaps)
|
||||||
|
{
|
||||||
|
filter_min = GL_LINEAR_MIPMAP_LINEAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filter_min = GL_NEAREST;
|
||||||
|
filter_mag = GL_NEAREST;
|
||||||
|
|
||||||
|
if (mipmaps)
|
||||||
|
{
|
||||||
|
// Mipmaps always linear
|
||||||
|
filter_min = GL_NEAREST_MIPMAP_LINEAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::Texture::Texture(GLuint width, GLuint height, const void* data, GLint internalformat, GLenum format, GLenum type, bool linear, bool mipmaps) {
|
||||||
glGenTextures(1, &m_id);
|
glGenTextures(1, &m_id);
|
||||||
|
|
||||||
if (!m_id)
|
if (!m_id)
|
||||||
@ -14,12 +38,18 @@ gfx::Texture::Texture(GLuint width, GLuint height, const void* data, GLint inter
|
|||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, data);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
GLenum filter_min, filter_mag;
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
GetGLFilterModes(linear, mipmaps, filter_min, filter_mag);
|
||||||
|
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_min);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_mag);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
|
if (mipmaps)
|
||||||
|
{
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
@ -39,8 +69,9 @@ std::shared_ptr<gfx::Texture> gfx::Texture::LoadFromFile(const std::string& file
|
|||||||
|
|
||||||
std::shared_ptr<Texture> texture;
|
std::shared_ptr<Texture> texture;
|
||||||
try {
|
try {
|
||||||
texture = std::make_shared<Texture>(width, height, data, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR_MIPMAP_LINEAR);
|
texture = std::make_shared<Texture>(width, height, data, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, true, true);
|
||||||
} catch (const std::exception& e) {
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
throw; // Rethrow the exception after freeing the data
|
throw; // Rethrow the exception after freeing the data
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class Texture : public NonCopyableNonMovable
|
|||||||
GLuint m_id;
|
GLuint m_id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Texture(GLuint width, GLuint height, const void* data, GLint internalformat, GLenum format, GLenum type, GLenum filter = GL_NEAREST);
|
Texture(GLuint width, GLuint height, const void* data, GLint internalformat, GLenum format, GLenum type, bool linear, bool mipmaps);
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
GLuint GetId() const { return m_id; }
|
GLuint GetId() const { return m_id; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user