Properly implement texture Mipmap generation

* Add missing GL_GENERATE_MIPMAP
* Add one-time retrieval of glGetIntegerv(GL_MAJOR_VERSION, *)
* Opt for Mipmap generation methos based on OGL version major (<3.0 = GL_GENERATE_MIPMAP, >=3.0 = glGenerateMipmap)
This commit is contained in:
Thimo 2020-11-08 14:54:59 +01:00
parent ae8ffdd2e3
commit 0c69b4a31e
2 changed files with 11 additions and 1 deletions

View File

@ -221,6 +221,7 @@ namespace Strawberry
public const uint GL_TEXTURE_DEPTH = 0x8071; public const uint GL_TEXTURE_DEPTH = 0x8071;
public const uint GL_TEXTURE_WRAP_R = 0x8072; public const uint GL_TEXTURE_WRAP_R = 0x8072;
public const uint GL_MAX_3D_TEXTURE_SIZE = 0x8073; public const uint GL_MAX_3D_TEXTURE_SIZE = 0x8073;
public const uint GL_GENERATE_MIPMAP = 0x8191;
public const uint GL_UNSIGNED_BYTE_2_3_3_REV = 0x8362; public const uint GL_UNSIGNED_BYTE_2_3_3_REV = 0x8362;
public const uint GL_UNSIGNED_SHORT_5_6_5 = 0x8363; public const uint GL_UNSIGNED_SHORT_5_6_5 = 0x8363;
public const uint GL_UNSIGNED_SHORT_5_6_5_REV = 0x8364; public const uint GL_UNSIGNED_SHORT_5_6_5_REV = 0x8364;

View File

@ -6,11 +6,16 @@ namespace Strawberry
public int Width { get; private set; } public int Width { get; private set; }
public int Height { get; private set; } public int Height { get; private set; }
private static int32 OGLMajorV = -1;
public this(int width, int height, uint8* pixels, bool indLinear, bool indClamp) public this(int width, int height, uint8* pixels, bool indLinear, bool indClamp)
{ {
Width = width; Width = width;
Height = height; Height = height;
if (OGLMajorV == -1)
GL.glGetIntegerv(GL.GL_MAJOR_VERSION, &OGLMajorV);
GL.glGenTextures(1, &Handle); GL.glGenTextures(1, &Handle);
GL.glBindTexture(GL.GL_TEXTURE_2D, Handle); GL.glBindTexture(GL.GL_TEXTURE_2D, Handle);
@ -26,9 +31,13 @@ namespace Strawberry
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
} }
if (OGLMajorV < 3) // OpenGL > 1.4 && < 3.0
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE);
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels);
GL.glGenerateMipmap(GL.GL_TEXTURE_2D); // Unavailable in OpenGL 2.1. if (OGLMajorV >= 3) // OpenGL >= 3.0
GL.glGenerateMipmap(GL.GL_TEXTURE_2D);
// Clear state // Clear state
GL.glBindTexture(GL.GL_TEXTURE_2D, 0); GL.glBindTexture(GL.GL_TEXTURE_2D, 0);