Skip to content

Commit

Permalink
Fix messed up texture coords/normals in scenery3d because of wrong at…
Browse files Browse the repository at this point in the history
…tribute mapping
  • Loading branch information
fschauk committed Feb 28, 2017
1 parent f7bcbd2 commit a240f5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
14 changes: 7 additions & 7 deletions plugins/Scenery3d/src/S3DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,17 +1244,17 @@ void S3DRenderer::drawFromCubeMap()
cubeShader->setUniformValue(shaderManager.uniformLocation(cubeShader,ShaderMgr::UNIFORM_TEX_DIFFUSE),0);
cubeVertexBuffer.bind();
if(cubemappingMode>=S3DEnum::CM_CUBEMAP)
cubeShader->setAttributeBuffer(ShaderMgr::ATTLOC_TEXCOORD,GL_FLOAT,0,3);
cubeShader->setAttributeBuffer(StelOpenGLArray::ATTLOC_TEXCOORD,GL_FLOAT,0,3);
else // 2D tex coords are stored in the same buffer, but with an offset
cubeShader->setAttributeBuffer(ShaderMgr::ATTLOC_TEXCOORD,GL_FLOAT,cubeVertices.size() * sizeof(Vec3f),2);
cubeShader->enableAttributeArray(ShaderMgr::ATTLOC_TEXCOORD);
cubeShader->setAttributeBuffer(StelOpenGLArray::ATTLOC_TEXCOORD,GL_FLOAT,cubeVertices.size() * sizeof(Vec3f),2);
cubeShader->enableAttributeArray(StelOpenGLArray::ATTLOC_TEXCOORD);
cubeVertexBuffer.release();

//upload transformed vertex data
transformedCubeVertexBuffer.bind();
transformedCubeVertexBuffer.allocate(transformedCubeVertices.constData(), transformedCubeVertices.size() * sizeof(Vec3f));
cubeShader->setAttributeBuffer(ShaderMgr::ATTLOC_VERTEX, GL_FLOAT, 0,3);
cubeShader->enableAttributeArray(ShaderMgr::ATTLOC_VERTEX);
cubeShader->setAttributeBuffer(StelOpenGLArray::ATTLOC_VERTEX, GL_FLOAT, 0,3);
cubeShader->enableAttributeArray(StelOpenGLArray::ATTLOC_VERTEX);
transformedCubeVertexBuffer.release();

glEnable(GL_BLEND);
Expand Down Expand Up @@ -1289,8 +1289,8 @@ void S3DRenderer::drawFromCubeMap()
}
cubeIndexBuffer.release();

cubeShader->disableAttributeArray(ShaderMgr::ATTLOC_TEXCOORD);
cubeShader->disableAttributeArray(ShaderMgr::ATTLOC_VERTEX);
cubeShader->disableAttributeArray(StelOpenGLArray::ATTLOC_TEXCOORD);
cubeShader->disableAttributeArray(StelOpenGLArray::ATTLOC_VERTEX);

glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
Expand Down
10 changes: 5 additions & 5 deletions plugins/Scenery3d/src/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,11 @@ bool ShaderMgr::loadShader(QOpenGLShaderProgram& program, const QByteArray& vSha

//Set attribute locations to hardcoded locations.
//This enables us to use a single VAO configuration for all shaders!
program.bindAttributeLocation("a_vertex",ATTLOC_VERTEX);
program.bindAttributeLocation("a_normal", ATTLOC_NORMAL);
program.bindAttributeLocation("a_texcoord",ATTLOC_TEXCOORD);
program.bindAttributeLocation("a_tangent",ATTLOC_TANGENT);
program.bindAttributeLocation("a_bitangent",ATTLOC_BITANGENT);
program.bindAttributeLocation("a_vertex",StelOpenGLArray::ATTLOC_VERTEX);
program.bindAttributeLocation("a_normal", StelOpenGLArray::ATTLOC_NORMAL);
program.bindAttributeLocation("a_texcoord",StelOpenGLArray::ATTLOC_TEXCOORD);
program.bindAttributeLocation("a_tangent",StelOpenGLArray::ATTLOC_TANGENT);
program.bindAttributeLocation("a_bitangent",StelOpenGLArray::ATTLOC_BITANGENT);


//link program
Expand Down
15 changes: 0 additions & 15 deletions plugins/Scenery3d/src/ShaderManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ class ShaderMgr
ShaderMgr();
~ShaderMgr();

//! Enum for OpenGL shader attribute locations
enum ATTLOC
{
//! This is the OpenGL attribute location where vertex positions are mapped to
ATTLOC_VERTEX,
//! This is the OpenGL attribute location where vertex normals are mapped to
ATTLOC_NORMAL,
//! This is the OpenGL attribute location where vertex texture coordinates are mapped to
ATTLOC_TEXCOORD,
//! This is the OpenGL attribute location where vertex tangents are mapped to
ATTLOC_TANGENT,
//! This is the OpenGL attribute location where vertex bitangents are mapped to
ATTLOC_BITANGENT
};

//! Enum for OpenGL shader uniform locations (faster than accessing by string each time)
enum UNIFORM
{
Expand Down

0 comments on commit a240f5d

Please sign in to comment.