Skip to content

Commit

Permalink
Fixed weird invis issue when loading cubemaps
Browse files Browse the repository at this point in the history
This one occured on all GPUs.
  • Loading branch information
ousnius committed Dec 20, 2016
1 parent baefa1b commit c921596
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
24 changes: 12 additions & 12 deletions src/files/ResourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ GLMaterial* ResourceLoader::AddMaterial(const vector<string>& textureFiles, cons
wxString fileExt = fileName.GetExt().Lower();
string fileExtStr = string(fileExt.c_str());

// Cubemap
if (!textureID && i == 4)
textureID = SOIL_load_OGL_single_cubemap(textureFiles[i].c_str(), SOIL_DDS_CUBEMAP_FACE_ORDER, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MIPMAPS);

// Normal texture (GLI)
// All textures (GLI)
if (!textureID && fileExtStr == "dds" || fileExtStr == "ktx")
textureID = GLI_load_texture(textureFiles[i]);

// Normal texture and image (SOIL fallback)
// Cubemap fallback (SOIL)
if (!textureID && i == 4)
textureID = SOIL_load_OGL_single_cubemap(textureFiles[i].c_str(), SOIL_DDS_CUBEMAP_FACE_ORDER, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MIPMAPS | SOIL_FLAG_GL_MIPMAPS);

// Texture and image fallback (SOIL)
if (!textureID)
textureID = SOIL_load_OGL_texture(textureFiles[i].c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MIPMAPS | SOIL_FLAG_GL_MIPMAPS);

Expand Down Expand Up @@ -225,15 +225,15 @@ GLMaterial* ResourceLoader::AddMaterial(const vector<string>& textureFiles, cons
if (!data.IsEmpty()) {
byte* texBuffer = static_cast<byte*>(data.GetData());

// Cubemap
if (!textureID && i == 4)
textureID = SOIL_load_OGL_single_cubemap_from_memory(texBuffer, data.GetDataLen(), SOIL_DDS_CUBEMAP_FACE_ORDER, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MIPMAPS);

// Normal texture (GLI)
// All textures (GLI)
if (!textureID && fileExtStr == "dds" || fileExtStr == "ktx")
textureID = GLI_load_texture_from_memory((char*)texBuffer, data.GetDataLen());

// Normal texture and image (SOIL fallback)
// Cubemap fallback (SOIL)
if (!textureID && i == 4)
textureID = SOIL_load_OGL_single_cubemap_from_memory(texBuffer, data.GetDataLen(), SOIL_DDS_CUBEMAP_FACE_ORDER, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MIPMAPS | SOIL_FLAG_GL_MIPMAPS);

// Texture and image fallback (SOIL)
if (!textureID)
textureID = SOIL_load_OGL_texture_from_memory(texBuffer, data.GetDataLen(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MIPMAPS | SOIL_FLAG_GL_MIPMAPS);
}
Expand Down
6 changes: 1 addition & 5 deletions src/render/GLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ void GLShader::BindTexture(const GLint& index, const GLuint& texture, const stri
glUniform1i(texLoc, index);
glActiveTexture(GL_TEXTURE0 + index);

glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

glBindTexture(GL_TEXTURE_2D, texture);
}
}
Expand All @@ -327,10 +325,8 @@ void GLShader::BindCubemap(const GLint& index, const GLuint& texture, const stri
glUniform1i(texLoc, index);
glActiveTexture(GL_TEXTURE0 + index);

glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/render/GLSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int GLSurface::InitGLSettings() {
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

// Get supported line width range
GLfloat lineRange[2];
Expand Down Expand Up @@ -789,11 +790,8 @@ void GLSurface::RenderMesh(mesh* m) {
glDrawElements(GL_TRIANGLES, m->nTris * 3, GL_UNSIGNED_SHORT, (GLvoid*)0);
}

if (bTextured && m->textured && m->texcoord) {
glBindTexture(GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
if (bTextured && m->textured && m->texcoord)
glDisableVertexAttribArray(3);
}

// Render points
if (m->bShowPoints && m->vcolors) {
Expand Down

0 comments on commit c921596

Please sign in to comment.