From 9ec80210af7dc32b1fee541e3f3b5bd95a7fc0ac Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 17 Feb 2014 11:50:13 +1100 Subject: [PATCH 01/14] Added simple script that makes all challenges trivial (0 laps, no time or energy limit). --- tools/simplify_challenges.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 tools/simplify_challenges.sh diff --git a/tools/simplify_challenges.sh b/tools/simplify_challenges.sh new file mode 100755 index 000000000..d17610928 --- /dev/null +++ b/tools/simplify_challenges.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# This script simplifies all challenges by removing any time +# limit, position requirement, etc, and setting the number +# of laps to 0. This is meant to quickly test the story +# mode without having to fully play all challenges. + +for i in data/challenges/*.challenge; do + echo "Simplifying $i" + cat $i | sed 's/position="[0-9]*"/position="99"/' \ + | sed 's/laps="[0-9]*"/laps="0"/' \ + | sed 's/energy="[0-9]*"/energy="0"/' \ + | sed 's/time="[0-9]*"/time="9999"/' \ + > $i.new + mv $i.new $i +done + +for i in data/grandprix/*.grandprix; do + echo "Simplyfing GP $i" + cat $i | sed 's/laps="[0-9]*"/laps="0"/' > $i.new + mv $i.new $i +done +echo +echo "All challenges simplified." +echo "PLEASE do not commit the changes back to our repository!" +echo "========================================================" + From 352393856c12e0f0af877752b037aa843aae6cf3 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 May 2014 22:51:12 +1000 Subject: [PATCH 02/14] Test commit. --- TODO.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TODO.md b/TODO.md index 670dc93c3..48f612f5e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,6 @@ +THIS IS A TEST!!!! + + ##TODO SuperTuxKart is looking for additional man power to make this From 844886075b8dcf9ea918721451b59c5d21b15e8f Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 May 2014 22:52:14 +1000 Subject: [PATCH 03/14] Fixed format for TODO file. --- TODO.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 48f612f5e..a3095eebd 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,7 @@ -THIS IS A TEST!!!! - - ##TODO +THIS IS A TEST. + SuperTuxKart is looking for additional man power to make this one of the best free linux games out there :) We need (in no particular order): From 09e8a39938e3a57fc75d1d8efd88e57f0d93797f Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 14 May 2014 07:56:45 +1000 Subject: [PATCH 04/14] More testing. --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index a3095eebd..fecc2019d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ ##TODO +THIS IS A 2nd TEST. THIS IS A TEST. SuperTuxKart is looking for additional man power to make this From 1be98dc5dbdcabcd2ce2a065cba7d6d4689effe1 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 23 Jun 2014 20:02:31 -0400 Subject: [PATCH 05/14] Support animated textures in non-static objects too --- src/animations/animation_base.cpp | 2 ++ src/tracks/track_object_presentation.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/animations/animation_base.cpp b/src/animations/animation_base.cpp index cd51bf3c1..784068288 100644 --- a/src/animations/animation_base.cpp +++ b/src/animations/animation_base.cpp @@ -33,6 +33,8 @@ AnimationBase::AnimationBase(const XMLNode &node) node.get("fps", &fps); for(unsigned int i=0; igetName() == "animated-texture") + continue; Ipo *ipo = new Ipo(*node.getNode(i), fps); m_all_ipos.push_back(ipo); } diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 266320998..ca4ddfadd 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -254,7 +254,7 @@ TrackObjectPresentationMesh::TrackObjectPresentationMesh(const XMLNode& xml_node else { m_mesh = irr_driver->getMesh(model_name); - + if (tangent) { scene::IMeshManipulator* manip = irr_driver->getVideoDriver()->getMeshManipulator(); @@ -368,6 +368,9 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node, scene::ISceneNod m_node = irr_driver->addMesh(m_mesh, parent); m_frame_start = 0; m_frame_end = 0; + + if (World::getWorld() != NULL && World::getWorld()->getTrack() != NULL) + World::getWorld()->getTrack()->handleAnimatedTextures(m_node, *xml_node); } //#ifdef DEBUG // std::string debug_name = model_name+" (track-object)"; From 69e342490e54538ecf787053ede55f64617404ad Mon Sep 17 00:00:00 2001 From: vlj Date: Tue, 24 Jun 2014 19:13:18 +0200 Subject: [PATCH 06/14] Fix ssao blur without compute. --- src/graphics/post_processing.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index d1822ce6a..90686a395 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -415,7 +415,7 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &a setTexture(0, in_fbo.getRTT()[0], GL_LINEAR, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - setTexture(1, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR); + setTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], GL_LINEAR, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glUniform1i(FullScreenShader::Gaussian17TapHShader::uniform_tex, 0); @@ -452,7 +452,7 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &a setTexture(0, auxiliary.getRTT()[0], GL_LINEAR, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - setTexture(1, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR); + setTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], GL_LINEAR, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glUniform1i(FullScreenShader::Gaussian17TapVShader::uniform_tex, 0); From edc38c993354ddca8a406be38317d6a4ca37c53a Mon Sep 17 00:00:00 2001 From: vlj Date: Tue, 24 Jun 2014 22:20:01 +0200 Subject: [PATCH 07/14] Use object_pass.vert for transparent objects. --- data/shaders/transparent.vert | 22 ---------------------- src/graphics/shaders.cpp | 21 +++++++++++++-------- src/graphics/shaders.hpp | 4 ++-- src/graphics/stkanimatedmesh.cpp | 4 ++-- src/graphics/stkmeshscenenode.cpp | 4 ++-- 5 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 data/shaders/transparent.vert diff --git a/data/shaders/transparent.vert b/data/shaders/transparent.vert deleted file mode 100644 index e6c6b13fe..000000000 --- a/data/shaders/transparent.vert +++ /dev/null @@ -1,22 +0,0 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TextureMatrix; - -#if __VERSION__ >= 130 -in vec3 Position; -in vec2 Texcoord; -in vec4 Color; -out vec2 uv; -out vec4 color; -#else -attribute vec3 Position; -attribute vec2 Texcoord; -varying vec2 uv; -#endif - - -void main() -{ - uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); - color = Color; -} diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 1d8bf1eb3..27f04e3de 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1360,19 +1360,24 @@ namespace MeshShader void TransparentShader::init() { Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/transparent.vert").c_str(), + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MVP = glGetUniformLocation(Program, "ModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); + if (!UserConfigParams::m_ubo_disabled) + { + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } } - void TransparentShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) + void TransparentShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); } @@ -1394,12 +1399,12 @@ namespace MeshShader void TransparentFogShader::init() { Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/transparent.vert").c_str(), + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparentfog.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MVP = glGetUniformLocation(Program, "ModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); uniform_fogmax = glGetUniformLocation(Program, "fogmax"); @@ -1415,9 +1420,9 @@ namespace MeshShader } } - void TransparentFogShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex) + void TransparentFogShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); glUniform1f(uniform_fogmax, fogmax); glUniform1f(uniform_startH, startH); diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index e1f3ae6ea..2bbf1eb02 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -288,7 +288,7 @@ public: static GLuint uniform_MVP, uniform_TM, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex); }; class TransparentFogShader @@ -299,7 +299,7 @@ public: static GLuint uniform_MVP, uniform_TM, uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex); }; class BillboardShader diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index b4464a46c..cc85017bf 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -230,13 +230,13 @@ void STKAnimatedMesh::render() for_in(mesh, TransparentMesh[TM_DEFAULT]) { TransparentMeshes::MeshSet.push_back(mesh); - TransparentMeshes::MVPSet.push_back(ModelViewProjectionMatrix); + TransparentMeshes::MVPSet.push_back(AbsoluteTransformation); } for_in(mesh, TransparentMesh[TM_ADDITIVE]) { TransparentMeshes::MeshSet.push_back(mesh); - TransparentMeshes::MVPSet.push_back(ModelViewProjectionMatrix); + TransparentMeshes::MVPSet.push_back(AbsoluteTransformation); } return; } diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 4f97ed8c7..a24ac18be 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -420,13 +420,13 @@ void STKMeshSceneNode::render() for_in(mesh, TransparentMesh[TM_DEFAULT]) { TransparentMeshes::MeshSet.push_back(mesh); - TransparentMeshes::MVPSet.push_back(ModelViewProjectionMatrix); + TransparentMeshes::MVPSet.push_back(AbsoluteTransformation); } for_in(mesh, TransparentMesh[TM_ADDITIVE]) { TransparentMeshes::MeshSet.push_back(mesh); - TransparentMeshes::MVPSet.push_back(ModelViewProjectionMatrix); + TransparentMeshes::MVPSet.push_back(AbsoluteTransformation); } if (!TransparentMesh[TM_BUBBLE].empty()) From 948c5e8aa25a152788cab85b9043110bcfec5589 Mon Sep 17 00:00:00 2001 From: vlj Date: Tue, 24 Jun 2014 23:17:41 +0200 Subject: [PATCH 08/14] Use explicit attribute location. Should help implementing basevertex later, and simplify vao creation a lot. --- data/shaders/displace.vert | 18 +-- data/shaders/grass_pass.vert | 20 +-- data/shaders/instanced_grass.vert | 8 +- data/shaders/instanced_object_pass.vert | 6 +- data/shaders/instanciedshadow.vert | 4 +- data/shaders/normalmap.vert | 21 +-- data/shaders/object_pass.vert | 20 +-- data/shaders/rsm.vert | 7 +- data/shaders/shadow.vert | 4 +- src/graphics/stkinstancedscenenode.cpp | 22 ++- src/graphics/stkmesh.cpp | 176 +++++++++++++----------- src/graphics/stkmesh.hpp | 3 +- 12 files changed, 139 insertions(+), 170 deletions(-) diff --git a/data/shaders/displace.vert b/data/shaders/displace.vert index 48b052077..bc9c68e6f 100644 --- a/data/shaders/displace.vert +++ b/data/shaders/displace.vert @@ -1,23 +1,13 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewMatrix; -#if __VERSION__ >= 130 -in vec3 Position; -in vec2 Texcoord; -in vec2 SecondTexcoord; +layout(location = 0) in vec3 Position; +layout(location = 3) in vec2 Texcoord; +layout(location = 4) in vec2 SecondTexcoord; + out vec2 uv; out vec2 uv_bis; out float camdist; -#else -attribute vec3 Position; -attribute vec2 Texcoord; -attribute vec2 SecondTexcoord; -varying vec2 uv; -varying vec2 uv_bis; -varying float camdist; -#endif - - void main() { gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); diff --git a/data/shaders/grass_pass.vert b/data/shaders/grass_pass.vert index 647697da3..b28217779 100644 --- a/data/shaders/grass_pass.vert +++ b/data/shaders/grass_pass.vert @@ -3,22 +3,14 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; -#if __VERSION__ >= 130 -in vec3 Position; -in vec3 Normal; -in vec2 Texcoord; -in vec4 Color; + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 2) in vec4 Color; +layout(location = 3) in vec2 Texcoord; + out vec3 nor; out vec2 uv; -#else -attribute vec3 Position; -attribute vec3 Normal; -attribute vec2 Texcoord; -attribute vec4 Color; -varying vec3 nor; -varying vec2 uv; -#endif - void main() { diff --git a/data/shaders/instanced_grass.vert b/data/shaders/instanced_grass.vert index 90e56c00c..50c9e65af 100644 --- a/data/shaders/instanced_grass.vert +++ b/data/shaders/instanced_grass.vert @@ -15,10 +15,10 @@ in vec3 Origin; in vec3 Orientation; in vec3 Scale; -in vec3 Position; -in vec3 Normal; -in vec2 Texcoord; -in vec4 Color; +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 2) in vec4 Color; +layout(location = 3) in vec2 Texcoord; out vec3 nor; out vec2 uv; diff --git a/data/shaders/instanced_object_pass.vert b/data/shaders/instanced_object_pass.vert index 493fa9139..ccabedfe9 100644 --- a/data/shaders/instanced_object_pass.vert +++ b/data/shaders/instanced_object_pass.vert @@ -19,9 +19,9 @@ in vec3 Origin; in vec3 Orientation; in vec3 Scale; -in vec3 Position; -in vec3 Normal; -in vec2 Texcoord; +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 3) in vec2 Texcoord; out vec3 nor; out vec2 uv; diff --git a/data/shaders/instanciedshadow.vert b/data/shaders/instanciedshadow.vert index e421aef03..d263a0669 100644 --- a/data/shaders/instanciedshadow.vert +++ b/data/shaders/instanciedshadow.vert @@ -11,8 +11,8 @@ in vec3 Origin; in vec3 Orientation; in vec3 Scale; -in vec3 Position; -in vec2 Texcoord; +layout(location = 0) in vec3 Position; +layout(location = 3) in vec2 Texcoord; #ifdef VSLayer out vec2 uv; diff --git a/data/shaders/normalmap.vert b/data/shaders/normalmap.vert index eb5570ddd..c992ebc19 100644 --- a/data/shaders/normalmap.vert +++ b/data/shaders/normalmap.vert @@ -10,24 +10,15 @@ layout (std140) uniform MatrixesData uniform mat4 ModelMatrix; uniform mat4 InverseModelMatrix; -#if __VERSION__ >= 130 -in vec3 Position; -in vec2 Texcoord; -in vec3 Tangent; -in vec3 Bitangent; + +layout(location = 0) in vec3 Position; +layout(location = 3) in vec2 Texcoord; +layout(location = 5) in vec3 Tangent; +layout(location = 6) in vec3 Bitangent; + out vec3 tangent; out vec3 bitangent; out vec2 uv; -#else -attribute vec3 Position; -attribute vec2 Texcoord; -attribute vec3 Tangent; -attribute vec3 Bitangent; -varying vec3 tangent; -varying vec3 bitangent; -varying vec2 uv; -#endif - void main() { diff --git a/data/shaders/object_pass.vert b/data/shaders/object_pass.vert index 3bd585e93..6b596cee8 100644 --- a/data/shaders/object_pass.vert +++ b/data/shaders/object_pass.vert @@ -24,25 +24,17 @@ uniform mat4 TextureMatrix = 0., 0., 1., 0., 0., 0., 0., 1.); -#if __VERSION__ >= 130 -in vec3 Position; -in vec2 Texcoord; + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 2) in vec4 Color; +layout(location = 3) in vec2 Texcoord; in vec2 SecondTexcoord; -in vec3 Normal; -in vec4 Color; + out vec3 nor; out vec2 uv; out vec2 uv_bis; out vec4 color; -#else -attribute vec3 Position; -attribute vec3 Normal; -attribute vec2 Texcoord; -attribute vec2 SecondTexcoord; -varying vec3 nor; -varying vec2 uv; -varying vec2 uv_bis; -#endif void main(void) diff --git a/data/shaders/rsm.vert b/data/shaders/rsm.vert index d5d08d48b..4b44144b2 100644 --- a/data/shaders/rsm.vert +++ b/data/shaders/rsm.vert @@ -9,9 +9,10 @@ uniform mat4 TextureMatrix = 0., 0., 0., 1.); -in vec3 Position; -in vec2 Texcoord; -in vec3 Normal; +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 3) in vec2 Texcoord; + out vec3 nor; out vec2 uv; diff --git a/data/shaders/shadow.vert b/data/shaders/shadow.vert index d7c389b2f..d1212e7ea 100644 --- a/data/shaders/shadow.vert +++ b/data/shaders/shadow.vert @@ -9,8 +9,8 @@ layout (std140) uniform MatrixesData uniform mat4 ModelMatrix; -in vec3 Position; -in vec2 Texcoord; +layout(location = 0) in vec3 Position; +layout(location = 3) in vec2 Texcoord; #ifdef VSLayer out vec2 uv; diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index c10e5ca6b..1b6ba4524 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -81,36 +81,33 @@ void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMateria switch (GeoMat) { case FPSM_DEFAULT: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::InstancedObjectPass1Shader::attrib_position, MeshShader::InstancedObjectRefPass1Shader::attrib_texcoord, -1, MeshShader::InstancedObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glGenBuffers(1, &instances_vbo); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW); setInstanceAttribPointer(); if (irr_driver->getGLSLVersion() >= 150) { - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::InstancedShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); setInstanceAttribPointer(); } break; case FPSM_ALPHA_REF_TEXTURE: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::InstancedObjectRefPass1Shader::attrib_position, MeshShader::InstancedObjectRefPass1Shader::attrib_texcoord, -1, MeshShader::InstancedObjectRefPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glGenBuffers(1, &instances_vbo); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW); setInstanceAttribPointer(); if (irr_driver->getGLSLVersion() >= 150) { - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::InstancedRefShadowShader::attrib_position, MeshShader::InstancedRefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); setInstanceAttribPointer(); } break; case FPSM_GRASS: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::InstancedGrassPass1Shader::attrib_position, MeshShader::InstancedGrassPass1Shader::attrib_texcoord, -1, MeshShader::InstancedGrassPass1Shader::attrib_normal, -1, -1, MeshShader::InstancedGrassPass1Shader::attrib_color, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glGenBuffers(1, &instances_vbo); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW); @@ -125,20 +122,17 @@ void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMateria switch (ShadedMat) { case SM_DEFAULT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::InstancedObjectPass2Shader::attrib_position, MeshShader::InstancedObjectPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); setInstanceAttribPointer(); break; case SM_ALPHA_REF_TEXTURE: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::InstancedObjectRefPass2Shader::attrib_position, MeshShader::InstancedObjectRefPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); setInstanceAttribPointer(); break; case SM_GRASS: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::InstancedGrassPass2Shader::attrib_position, MeshShader::InstancedGrassPass2Shader::attrib_texcoord, -1, MeshShader::InstancedGrassPass2Shader::attrib_normal, -1, -1, MeshShader::InstancedGrassPass2Shader::attrib_color, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); setInstanceAttribPointer(); break; diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 245180270..ce1cb8bbf 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -56,54 +56,78 @@ TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE typ return TM_DEFAULT; } -GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride) +video::E_VERTEX_TYPE getVTXTYPEFromStride(size_t stride) +{ + if (stride == sizeof(video::S3DVertex)) + return video::EVT_STANDARD; + else if (stride == sizeof(video::S3DVertex2TCoords)) + return video::EVT_2TCOORDS; + assert(stride == sizeof(video::S3DVertexTangents)); + return video::EVT_TANGENTS; +} + +GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type) { - if (attrib_position == -1) - return 0; GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); - glEnableVertexAttribArray(attrib_position); - if ((GLint)attrib_texcoord != -1) - glEnableVertexAttribArray(attrib_texcoord); - if ((GLint)attrib_second_texcoord != -1) - glEnableVertexAttribArray(attrib_second_texcoord); - if ((GLint)attrib_normal != -1) - glEnableVertexAttribArray(attrib_normal); - if ((GLint)attrib_tangent != -1) - glEnableVertexAttribArray(attrib_tangent); - if ((GLint)attrib_bitangent != -1) - glEnableVertexAttribArray(attrib_bitangent); - if ((GLint)attrib_color != -1) - glEnableVertexAttribArray(attrib_color); - glVertexAttribPointer(attrib_position, 3, GL_FLOAT, GL_FALSE, stride, 0); - if ((GLint)attrib_texcoord != -1) - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*) 28); - if ((GLint)attrib_second_texcoord != -1) + switch (type) { - if (stride < 44) - Log::error("material", "Second texcoords not present in VBO"); - glVertexAttribPointer(attrib_second_texcoord, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*) 36); + case video::EVT_STANDARD: + // Position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 0); + // Normal + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12); + // Color + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(type), (GLvoid*)24); + // Texcoord + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)28); + break; + case video::EVT_2TCOORDS: + break; + // Position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 0); + // Normal + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12); + // Color + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(type), (GLvoid*)24); + // Texcoord + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)28); + // SecondTexcoord + glEnableVertexAttribArray(4); + glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)36); + break; + case video::EVT_TANGENTS: + // Position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 0); + // Normal + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)12); + // Color + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(type), (GLvoid*)24); + // Texcoord + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)28); + // Tangent + glEnableVertexAttribArray(5); + glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)36); + // Bitangent + glEnableVertexAttribArray(6); + glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)48); + break; } - if ((GLint)attrib_normal != -1) - glVertexAttribPointer(attrib_normal, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*) 12); - if ((GLint)attrib_tangent != -1) - { - if (stride < 48) - Log::error("material", "Tangents not present in VBO"); - glVertexAttribPointer(attrib_tangent, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)36); - } - - if ((GLint)attrib_bitangent != -1) - { - if (stride < 60) - Log::error("material", "Bitangents not present in VBO"); - glVertexAttribPointer(attrib_bitangent, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)48); - } - if ((GLint)attrib_color != -1) - glVertexAttribPointer(attrib_color, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, (GLvoid*)24); - + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx); return vao; } @@ -659,25 +683,21 @@ void initvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedM switch (GeoMat) { case FPSM_DEFAULT: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::ObjectPass1Shader::attrib_position, MeshShader::ObjectPass1Shader::attrib_texcoord, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); - mesh.vao_rsm_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::RSMShader::attrib_position, MeshShader::RSMShader::attrib_texcoord, -1, MeshShader::RSMShader::attrib_normal, -1, -1, -1, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_rsm_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case FPSM_ALPHA_REF_TEXTURE: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::ObjectRefPass1Shader::attrib_position, MeshShader::ObjectRefPass1Shader::attrib_texcoord, -1, MeshShader::ObjectRefPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::RefShadowShader::attrib_position, MeshShader::RefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case FPSM_NORMAL_MAP: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::NormalMapShader::attrib_position, MeshShader::NormalMapShader::attrib_texcoord, -1, -1, MeshShader::NormalMapShader::attrib_tangent, MeshShader::NormalMapShader::attrib_bitangent, -1, mesh.Stride); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case FPSM_GRASS: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::GrassPass1Shader::attrib_position, MeshShader::GrassPass1Shader::attrib_texcoord, -1, MeshShader::GrassPass1Shader::attrib_normal, -1, -1, MeshShader::GrassPass1Shader::attrib_color, mesh.Stride); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::GrassShadowShader::attrib_position, MeshShader::GrassShadowShader::attrib_texcoord, -1, -1, -1, -1, MeshShader::GrassShadowShader::attrib_color, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; default: assert(0 && "Unknow material"); @@ -687,50 +707,41 @@ void initvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedM switch (ShadedMat) { case SM_SPHEREMAP: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::SphereMapShader::attrib_position, -1, -1, MeshShader::SphereMapShader::attrib_normal, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_SPLATTING: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::SplattingShader::attrib_position, MeshShader::SplattingShader::attrib_texcoord, MeshShader::SplattingShader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_ALPHA_REF_TEXTURE: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::ObjectRefPass2Shader::attrib_position, MeshShader::ObjectRefPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_RIMLIT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::ObjectRimLimitShader::attrib_position, MeshShader::ObjectRimLimitShader::attrib_texcoord, -1, MeshShader::ObjectRimLimitShader::attrib_normal, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_GRASS: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::GrassPass2Shader::attrib_position, MeshShader::GrassPass2Shader::attrib_texcoord, -1, -1, -1, -1, MeshShader::GrassPass2Shader::attrib_color, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_UNLIT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::ObjectUnlitShader::attrib_position, MeshShader::ObjectUnlitShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_DETAILS: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::DetailledObjectPass2Shader::attrib_position, MeshShader::DetailledObjectPass2Shader::attrib_texcoord, MeshShader::DetailledObjectPass2Shader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_UNTEXTURED: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::UntexturedObjectShader::attrib_position, -1, -1, -1, -1, -1, MeshShader::UntexturedObjectShader::attrib_color, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case SM_DEFAULT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::ObjectPass2Shader::attrib_position, MeshShader::ObjectPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; default: assert(0 && "unknow shaded material"); break; } - mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ColorizeShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); - mesh.vao_displace_mask_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::DisplaceShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_displace_mask_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); if (mesh.Stride >= 44) - mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::DisplaceShader::attrib_position, MeshShader::DisplaceShader::attrib_texcoord, MeshShader::DisplaceShader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride); + mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); } void initvaostate(GLMesh &mesh, TransparentMaterial TranspMat) @@ -738,22 +749,19 @@ void initvaostate(GLMesh &mesh, TransparentMaterial TranspMat) switch (TranspMat) { case TM_BUBBLE: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::BubbleShader::attrib_position, MeshShader::BubbleShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; case TM_DEFAULT: case TM_ADDITIVE: if (World::getWorld() != NULL && World::getWorld()->isFogEnabled()) - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::TransparentFogShader::attrib_position, MeshShader::TransparentFogShader::attrib_texcoord, -1, -1, -1, -1, MeshShader::TransparentFogShader::attrib_color, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); else - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, - MeshShader::TransparentShader::attrib_position, MeshShader::TransparentShader::attrib_texcoord, -1, -1, -1, -1, MeshShader::TransparentShader::attrib_color, mesh.Stride); + mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); break; } - mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ColorizeShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); - mesh.vao_displace_mask_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::DisplaceShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao_displace_mask_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); if (mesh.Stride >= 44) - mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::DisplaceShader::attrib_position, MeshShader::DisplaceShader::attrib_texcoord, MeshShader::DisplaceShader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride); + mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); } diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index c16e075b0..4e02bf39e 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -59,8 +59,9 @@ struct GLMesh { core::matrix4 TextureMatrix; }; -GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride); GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb); +video::E_VERTEX_TYPE getVTXTYPEFromStride(size_t stride); +GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type); void initvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat); void initvaostate(GLMesh &mesh, TransparentMaterial TranspMat); core::matrix4 computeMVP(const core::matrix4 &ModelViewProjectionMatrix); From 8e6fba318548107a6130860ce4cb742e6e23c54b Mon Sep 17 00:00:00 2001 From: vlj Date: Tue, 24 Jun 2014 23:57:29 +0200 Subject: [PATCH 09/14] Some fixes --- data/shaders/object_pass.vert | 2 +- src/graphics/stkmesh.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/data/shaders/object_pass.vert b/data/shaders/object_pass.vert index 6b596cee8..b84e810a6 100644 --- a/data/shaders/object_pass.vert +++ b/data/shaders/object_pass.vert @@ -29,7 +29,7 @@ layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; layout(location = 2) in vec4 Color; layout(location = 3) in vec2 Texcoord; -in vec2 SecondTexcoord; +layout(location = 4) in vec2 SecondTexcoord; out vec3 nor; out vec2 uv; diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index ce1cb8bbf..3d964384f 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -126,6 +126,8 @@ GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type) glEnableVertexAttribArray(6); glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)48); break; + default: + assert(0 && "Wrong vertex type"); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx); From 45e5fba979084d318a6c88904def77e1e1336511 Mon Sep 17 00:00:00 2001 From: vlj Date: Wed, 25 Jun 2014 01:13:23 +0200 Subject: [PATCH 10/14] Simplify vao management for non instanced nodes. --- src/graphics/render.cpp | 8 +- src/graphics/stkanimatedmesh.cpp | 14 +-- src/graphics/stkinstancedscenenode.cpp | 10 +- src/graphics/stkmesh.cpp | 144 ++++++------------------- src/graphics/stkmesh.hpp | 1 + src/graphics/stkmeshscenenode.cpp | 23 +--- 6 files changed, 48 insertions(+), 152 deletions(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 53ad6a8e5..6cbb9e3e2 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -540,7 +540,7 @@ void IrrDriver::renderSolidFirstPass() GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } - draw(mesh, mesh.vao_first_pass, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0); + draw(mesh, mesh.vao, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0); if (!mesh.textures[0]) { GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; @@ -554,7 +554,7 @@ void IrrDriver::renderSolidFirstPass() const GLMesh &mesh = *GroupedFPSM::MeshSet[i]; compressTexture(mesh.textures[0], true); setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - draw(mesh, mesh.vao_first_pass, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], GroupedFPSM::MeshSet[i]->TextureMatrix, 0); + draw(mesh, mesh.vao, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], GroupedFPSM::MeshSet[i]->TextureMatrix, 0); } glUseProgram(MeshShader::NormalMapShader::Program); for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) @@ -565,7 +565,7 @@ void IrrDriver::renderSolidFirstPass() setTexture(0, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); compressTexture(mesh.textures[0], true); setTexture(1, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - draw(mesh, mesh.vao_first_pass, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0, 1); + draw(mesh, mesh.vao, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0, 1); } } } @@ -912,7 +912,7 @@ void IrrDriver::renderShadows() continue; compressTexture(mesh.textures[0], true); setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - draw(mesh, mesh.vao_rsm_pass, rsm_matrix, GroupedFPSM::MVPSet[i], 0); + draw(mesh, mesh.vao, rsm_matrix, GroupedFPSM::MVPSet[i], 0); } } diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index cc85017bf..793b0e621 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -27,18 +27,8 @@ void STKAnimatedMesh::cleanGLMeshes() GLMesh mesh = GLmeshes[i]; if (!mesh.vertex_buffer) continue; - if (mesh.vao_first_pass) - glDeleteVertexArrays(1, &(mesh.vao_first_pass)); - if (mesh.vao_second_pass) - glDeleteVertexArrays(1, &(mesh.vao_second_pass)); - if (mesh.vao_glow_pass) - glDeleteVertexArrays(1, &(mesh.vao_glow_pass)); - if (mesh.vao_displace_pass) - glDeleteVertexArrays(1, &(mesh.vao_displace_pass)); - if (mesh.vao_displace_mask_pass) - glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass)); - if (mesh.vao_shadow_pass) - glDeleteVertexArrays(1, &(mesh.vao_shadow_pass)); + if (mesh.vao) + glDeleteVertexArrays(1, &(mesh.vao)); glDeleteBuffers(1, &(mesh.vertex_buffer)); glDeleteBuffers(1, &(mesh.index_buffer)); } diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index 1b6ba4524..020b160f3 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -25,16 +25,10 @@ void STKInstancedSceneNode::cleanGL() GLMesh mesh = GLmeshes[i]; if (!mesh.vertex_buffer) continue; - if (mesh.vao_first_pass) - glDeleteVertexArrays(1, &(mesh.vao_first_pass)); + if (mesh.vao) + glDeleteVertexArrays(1, &(mesh.vao)); if (mesh.vao_second_pass) glDeleteVertexArrays(1, &(mesh.vao_second_pass)); - if (mesh.vao_glow_pass) - glDeleteVertexArrays(1, &(mesh.vao_glow_pass)); - if (mesh.vao_displace_pass) - glDeleteVertexArrays(1, &(mesh.vao_displace_pass)); - if (mesh.vao_displace_mask_pass) - glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass)); if (mesh.vao_shadow_pass) glDeleteVertexArrays(1, &(mesh.vao_shadow_pass)); glDeleteBuffers(1, &(mesh.vertex_buffer)); diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 3d964384f..c3bff6c10 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -71,6 +71,7 @@ GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type) GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); + assert(vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); switch (type) { @@ -129,7 +130,7 @@ GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type) default: assert(0 && "Wrong vertex type"); } - + assert(idx); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx); return vao; } @@ -250,8 +251,8 @@ void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio MeshShader::GrassPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, windDir, 0); - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -276,8 +277,8 @@ void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelMatrix, const c setTexture(MeshShader::SphereMapShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); MeshShader::SphereMapShader::setUniforms(ModelMatrix, InverseModelMatrix, irr_driver->getSceneManager()->getAmbientLight()); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -356,8 +357,8 @@ void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionM MeshShader::SplattingShader::setUniforms(ModelViewProjectionMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -383,8 +384,8 @@ void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjec MeshShader::ObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -412,8 +413,8 @@ void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio MeshShader::GrassPass2Shader::setUniforms(ModelViewProjectionMatrix, windDir); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -426,8 +427,8 @@ void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelMatrix) MeshShader::UntexturedObjectShader::setUniforms(ModelMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -453,8 +454,8 @@ void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjec MeshShader::ObjectRimLimitShader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -480,8 +481,8 @@ void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio MeshShader::ObjectUnlitShader::setUniforms(ModelViewProjectionMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -509,8 +510,8 @@ void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelView MeshShader::DetailledObjectPass2Shader::setUniforms(ModelViewProjectionMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -536,8 +537,8 @@ void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio MeshShader::ObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix); - assert(mesh.vao_second_pass); - glBindVertexArray(mesh.vao_second_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -553,8 +554,8 @@ void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewPro MeshShader::TransparentShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0); - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -588,8 +589,8 @@ void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelView glUseProgram(MeshShader::TransparentFogShader::Program); MeshShader::TransparentFogShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0); - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -608,8 +609,8 @@ void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatr MeshShader::BubbleShader::setUniforms(ModelViewProjectionMatrix, 0, time, transparency); - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -624,8 +625,8 @@ void drawShadowRef(const GLMesh &mesh, const core::matrix4 &ModelMatrix) setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); MeshShader::RefShadowShader::setUniforms(ModelMatrix, 0); - assert(mesh.vao_shadow_pass); - glBindVertexArray(mesh.vao_shadow_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElementsInstanced(ptype, count, itype, 0, 4); } @@ -638,8 +639,8 @@ void drawShadow(const GLMesh &mesh, const core::matrix4 &ModelMatrix) MeshShader::ShadowShader::setUniforms(ModelMatrix); - assert(mesh.vao_shadow_pass); - glBindVertexArray(mesh.vao_shadow_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElementsInstanced(ptype, count, itype, 0, 4); } @@ -682,88 +683,11 @@ bool isObject(video::E_MATERIAL_TYPE type) void initvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat) { - switch (GeoMat) - { - case FPSM_DEFAULT: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_rsm_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case FPSM_ALPHA_REF_TEXTURE: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case FPSM_NORMAL_MAP: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case FPSM_GRASS: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - default: - assert(0 && "Unknow material"); - break; - } - - switch (ShadedMat) - { - case SM_SPHEREMAP: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_SPLATTING: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_ALPHA_REF_TEXTURE: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_RIMLIT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_GRASS: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_UNLIT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_DETAILS: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_UNTEXTURED: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case SM_DEFAULT: - mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - default: - assert(0 && "unknow shaded material"); - break; - } - - mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_displace_mask_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - if (mesh.Stride >= 44) - mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); } void initvaostate(GLMesh &mesh, TransparentMaterial TranspMat) { - switch (TranspMat) - { - case TM_BUBBLE: - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - case TM_DEFAULT: - case TM_ADDITIVE: - if (World::getWorld() != NULL && World::getWorld()->isFogEnabled()) - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - else - mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - break; - } - mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - mesh.vao_displace_mask_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); - if (mesh.Stride >= 44) - mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); + mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride)); } diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 4e02bf39e..b4ebd442f 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -42,6 +42,7 @@ enum TransparentMaterial }; struct GLMesh { + GLuint vao; GLuint vao_first_pass; GLuint vao_second_pass; GLuint vao_glow_pass; diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index a24ac18be..58d85c7d8 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -82,18 +82,8 @@ void STKMeshSceneNode::cleanGLMeshes() GLMesh mesh = GLmeshes[i]; if (!mesh.vertex_buffer) continue; - if (mesh.vao_first_pass) - glDeleteVertexArrays(1, &(mesh.vao_first_pass)); - if (mesh.vao_second_pass) - glDeleteVertexArrays(1, &(mesh.vao_second_pass)); - if (mesh.vao_glow_pass) - glDeleteVertexArrays(1, &(mesh.vao_glow_pass)); - if (mesh.vao_displace_pass) - glDeleteVertexArrays(1, &(mesh.vao_displace_pass)); - if (mesh.vao_displace_mask_pass) - glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass)); - if (mesh.vao_shadow_pass) - glDeleteVertexArrays(1, &(mesh.vao_shadow_pass)); + if (mesh.vao) + glDeleteVertexArrays(1, &(mesh.vao)); glDeleteBuffers(1, &(mesh.vertex_buffer)); glDeleteBuffers(1, &(mesh.index_buffer)); } @@ -126,8 +116,8 @@ void STKMeshSceneNode::drawGlow(const GLMesh &mesh) MeshShader::ColorizeShader::setUniforms(AbsoluteTransformation, cb->getRed(), cb->getGreen(), cb->getBlue()); - assert(mesh.vao_glow_pass); - glBindVertexArray(mesh.vao_glow_pass); + assert(mesh.vao); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); } @@ -152,8 +142,7 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) glUseProgram(MeshShader::DisplaceMaskShader::Program); MeshShader::DisplaceMaskShader::setUniforms(ModelViewProjectionMatrix); - assert(mesh.vao_displace_mask_pass); - glBindVertexArray(mesh.vao_displace_mask_pass); + glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); // Render the effect @@ -171,8 +160,6 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) float(UserConfigParams::m_height)), 0, 1, 2); - assert(mesh.vao_displace_pass); - glBindVertexArray(mesh.vao_displace_pass); glDrawElements(ptype, count, itype, 0); } From a93b96d0b135709e8bbfd4ecc98201b7e75d9ce3 Mon Sep 17 00:00:00 2001 From: vlj Date: Wed, 25 Jun 2014 01:22:03 +0200 Subject: [PATCH 11/14] Use UBO matrixes in displace. --- data/shaders/displace.vert | 24 ++++++++++++++++++++---- src/graphics/shaders.cpp | 17 ++++++++--------- src/graphics/shaders.hpp | 6 +++--- src/graphics/stkmeshscenenode.cpp | 8 ++------ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/data/shaders/displace.vert b/data/shaders/displace.vert index bc9c68e6f..ff4294e3e 100644 --- a/data/shaders/displace.vert +++ b/data/shaders/displace.vert @@ -1,5 +1,21 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 ModelViewMatrix; +#ifdef UBO_DISABLED +uniform mat4 ViewMatrix; +uniform mat4 ProjectionMatrix; +uniform mat4 InverseViewMatrix; +uniform mat4 InverseProjectionMatrix; +#else +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; + vec2 screen; +}; +#endif + +uniform mat4 ModelMatrix; layout(location = 0) in vec3 Position; layout(location = 3) in vec2 Texcoord; @@ -10,8 +26,8 @@ out vec2 uv_bis; out float camdist; void main() { - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); + gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); uv = Texcoord; uv_bis = SecondTexcoord; - camdist = length(ModelViewMatrix * vec4(Position, 1.)); + camdist = length(ViewMatrix * ModelMatrix * vec4(Position, 1.)); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 27f04e3de..6f747bd2c 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1733,12 +1733,14 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/displace.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MVP = glGetUniformLocation(Program, "ModelMatrix"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void DisplaceMaskShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) + void DisplaceMaskShader::setUniforms(const core::matrix4 &ModelMatrix) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer()); } GLuint DisplaceShader::Program; @@ -1746,7 +1748,6 @@ namespace MeshShader GLuint DisplaceShader::attrib_texcoord; GLuint DisplaceShader::attrib_second_texcoord; GLuint DisplaceShader::uniform_MVP; - GLuint DisplaceShader::uniform_MV; GLuint DisplaceShader::uniform_displacement_tex; GLuint DisplaceShader::uniform_mask_tex; GLuint DisplaceShader::uniform_color_tex; @@ -1761,8 +1762,7 @@ namespace MeshShader attrib_position = glGetAttribLocation(Program, "Position"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); + uniform_MVP = glGetUniformLocation(Program, "ModelMatrix"); uniform_displacement_tex = glGetUniformLocation(Program, "displacement_tex"); uniform_color_tex = glGetUniformLocation(Program, "color_tex"); uniform_mask_tex = glGetUniformLocation(Program, "mask_tex"); @@ -1772,10 +1772,9 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void DisplaceShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) + void DisplaceShader::setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer()); glUniform2f(uniform_dir, dir.X, dir.Y); glUniform2f(uniform_dir2, dir2.X, dir2.Y); glUniform1i(uniform_displacement_tex, TU_displacement_tex); diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 2bbf1eb02..6086d2262 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -398,7 +398,7 @@ public: static GLuint uniform_MVP; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class DisplaceShader @@ -406,10 +406,10 @@ class DisplaceShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord; - static GLuint uniform_MVP, uniform_MV, uniform_displacement_tex, uniform_mask_tex, uniform_color_tex, uniform_dir, uniform_dir2; + static GLuint uniform_MVP, uniform_displacement_tex, uniform_mask_tex, uniform_color_tex, uniform_dir, uniform_dir2; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex); }; class SkyboxShader diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 58d85c7d8..f9a60888e 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -131,16 +131,12 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); - core::matrix4 ModelViewMatrix = irr_driver->getViewMatrix(); - ModelViewMatrix *= AbsoluteTransformation; - // Generate displace mask // Use RTT_TMP4 as displace mask irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind(); glUseProgram(MeshShader::DisplaceMaskShader::Program); - MeshShader::DisplaceMaskShader::setUniforms(ModelViewProjectionMatrix); + MeshShader::DisplaceMaskShader::setUniforms(AbsoluteTransformation); glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); @@ -153,7 +149,7 @@ void STKMeshSceneNode::drawDisplace(const GLMesh &mesh) setTexture(1, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_LINEAR, GL_LINEAR, true); setTexture(2, irr_driver->getRenderTargetTexture(RTT_COLOR), GL_LINEAR, GL_LINEAR, true); glUseProgram(MeshShader::DisplaceShader::Program); - MeshShader::DisplaceShader::setUniforms(ModelViewProjectionMatrix, ModelViewMatrix, + MeshShader::DisplaceShader::setUniforms(AbsoluteTransformation, core::vector2df(cb->getDirX(), cb->getDirY()), core::vector2df(cb->getDir2X(), cb->getDir2Y()), core::vector2df(float(UserConfigParams::m_width), From 9bc2203adf1d6c24d342f4e002ee5b6a322313d4 Mon Sep 17 00:00:00 2001 From: vlj Date: Wed, 25 Jun 2014 01:43:51 +0200 Subject: [PATCH 12/14] Remove break at wrong position --- src/graphics/stkmesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index c3bff6c10..ec44f1a9e 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -90,7 +90,6 @@ GLuint createVAO(GLuint vbo, GLuint idx, video::E_VERTEX_TYPE type) glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), (GLvoid*)28); break; case video::EVT_2TCOORDS: - break; // Position glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(type), 0); @@ -151,6 +150,7 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb) result.Stride = getVertexPitchFromType(vType); const c8* vbuf = static_cast(vertices); glBufferData(GL_ARRAY_BUFFER, vertexCount * result.Stride, vbuf, GL_STATIC_DRAW); + assert(vertexCount); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.index_buffer); const void* indices = mb->getIndices(); From a56d6405dc01d9326f0fd8d2b3f71417ba4f5ff7 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 25 Jun 2014 22:18:36 +0200 Subject: [PATCH 13/14] Simplify code for checking best refresh rate on linux, which I added previously. --- lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp index 5825c2830..b9cd2505c 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp @@ -264,7 +264,7 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset) // enumerate video modes s32 modeCount; XF86VidModeModeInfo** modes; - float refresh_rate; + float refresh_rate, refresh_rate_old; XF86VidModeGetAllModeLines(display, screennr, &modeCount, &modes); @@ -273,22 +273,17 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset) { if (bestMode==-1 && modes[i]->hdisplay >= Width && modes[i]->vdisplay >= Height) { - float pixels_per_second = modes[i]->dotclock * 1000.0; - float pixels_per_frame = modes[i]->htotal * modes[i]->vtotal; - refresh_rate = pixels_per_second / pixels_per_frame; bestMode = i; } else if (bestMode!=-1 && modes[i]->hdisplay == modes[bestMode]->hdisplay && modes[i]->vdisplay == modes[bestMode]->vdisplay) { - float pixels_per_second = modes[i]->dotclock * 1000.0; - float pixels_per_frame = modes[i]->htotal * modes[i]->vtotal; - float refresh_rate_tmp = pixels_per_second / pixels_per_frame; + refresh_rate_old = (modes[bestMode]->dotclock * 1000.0) / (modes[bestMode]->htotal * modes[bestMode]->vtotal); + refresh_rate = (modes[i]->dotclock * 1000.0) / (modes[i]->htotal * modes[i]->vtotal); - if (refresh_rate_tmp > refresh_rate) + if (refresh_rate > refresh_rate_old) { - refresh_rate = refresh_rate_tmp; bestMode = i; } } @@ -298,9 +293,6 @@ bool CIrrDeviceLinux::switchToFullscreen(bool reset) modes[i]->hdisplay <= modes[bestMode]->hdisplay && modes[i]->vdisplay <= modes[bestMode]->vdisplay) { - float pixels_per_second = modes[i]->dotclock * 1000.0; - float pixels_per_frame = modes[i]->htotal * modes[i]->vtotal; - refresh_rate = pixels_per_second / pixels_per_frame; bestMode = i; } } From d0091d9977ff5a18c12bb65c1bd59cf762408b75 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 25 Jun 2014 22:22:14 +0200 Subject: [PATCH 14/14] Fixed accidentaly noticed typo in comment --- src/main_loop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main_loop.cpp b/src/main_loop.cpp index ace649423..a24789f70 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -176,7 +176,7 @@ void MainLoop::run() PROFILER_SYNC_FRAME(); PROFILER_POP_CPU_MARKER(); - } // while !m_exit + } // while !m_abort } // run