Landscape Renderer: Create and bind 1D mat map texture before using

The landscape renderer used to store texture data into the default 1D
texture, which works but is a bad idea for several reasons (and would
have broken if we had a reason to use another 1D texture anywhere else).
liquid_container
Nicolas Hake 2016-02-24 19:15:57 +01:00
parent f64f131f1b
commit bfd9989fc6
2 changed files with 9 additions and 1 deletions

View File

@ -54,7 +54,7 @@ const char *const SEPERATOR_TEXTURE = "--SEP--";
C4LandscapeRenderGL::C4LandscapeRenderGL()
{
ZeroMem(Surfaces, sizeof(Surfaces));
hMaterialTexture = 0;
hMaterialTexture = matMapTexture = 0;
hVBO = 0;
hVAOIDNoLight = 0;
hVAOIDLight = 0;
@ -146,6 +146,8 @@ void C4LandscapeRenderGL::Clear()
}
if (hMaterialTexture) glDeleteTextures(1, &hMaterialTexture);
hMaterialTexture = 0;
if (matMapTexture) glDeleteTextures(1, &matMapTexture);
matMapTexture = 0;
if (hVBO != 0)
{
@ -297,6 +299,9 @@ bool C4LandscapeRenderGL::InitMaterialTexture(C4TextureMap *pTexs)
// Clear error error(s?)
while(glGetError()) {}
// Alloc 1D matmap texture
glGenTextures(1, &matMapTexture);
// Alloc 2D texture array
glGenTextures(1, &hMaterialTexture);
@ -1009,6 +1014,7 @@ void C4LandscapeRenderGL::Draw(const C4TargetFacet &cgo, const C4FoWRegion *Ligh
{
uint32_t MatMap[2*256];
BuildMatMap(MatMap);
glBindTexture(GL_TEXTURE_1D, matMapTexture);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, 2*256, 0, GL_RGBA, GL_UNSIGNED_BYTE, MatMap);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}

View File

@ -123,6 +123,8 @@ private:
unsigned int hVAOIDNoLight;
unsigned int hVAOIDLight;
// 1D texture for material map
GLuint matMapTexture;
// 2D texture array of material textures
GLuint hMaterialTexture;
// material texture positions in texture array