From 012cf599b451847a57fdf2182141633b708d9dcf Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 5 Apr 2014 19:21:57 +0200 Subject: [PATCH 01/10] Use 2D version of glFramebufferTexture glFramebufferTexture is not supported on GL 3.1 context, while glFramebufferTexture2D is. Also fix an inverted comparaison. --- src/graphics/glwrap.cpp | 4 ++-- src/graphics/glwrap.hpp | 2 +- src/graphics/rtts.cpp | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 616515818..63940deb2 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -57,7 +57,7 @@ PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; PFNGLTEXIMAGE3DPROC glTexImage3D; PFNGLGENERATEMIPMAPPROC glGenerateMipmap; PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; @@ -199,7 +199,7 @@ void initGL() glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)IRR_OGL_LOAD_EXTENSION("glVertexAttribIPointer"); glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glGenFramebuffers"); glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glBindFramebuffer"); - glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture"); + glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture2D"); glTexImage3D = (PFNGLTEXIMAGE3DPROC)IRR_OGL_LOAD_EXTENSION("glTexImage3D"); glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)IRR_OGL_LOAD_EXTENSION("glGenerateMipmap"); glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatus"); diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 12ed49d50..a7ecbc57d 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -74,7 +74,7 @@ extern PFNGLBUFFERSUBDATAPROC glBufferSubData; extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; extern PFNGLTEXIMAGE3DPROC glTexImage3D; extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index c2d156951..74e191182 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -36,7 +36,7 @@ static GLuint generateFBO(GLuint ColorAttachement) GLuint fbo; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ColorAttachement, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColorAttachement, 0); GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); return fbo; @@ -45,7 +45,7 @@ static GLuint generateFBO(GLuint ColorAttachement) static GLuint generateFBO(GLuint ColorAttachement, GLuint DepthAttachement) { GLuint fbo = generateFBO(ColorAttachement); - glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, DepthAttachement, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DepthAttachement, 0); GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); return fbo; @@ -116,9 +116,9 @@ RTT::RTT() FrameBuffers[FBO_EIGHTH2] = generateFBO(RenderTargetTextures[RTT_EIGHTH2]); FrameBuffers[FBO_COMBINED_TMP1_TMP2] = generateFBO(RenderTargetTextures[RTT_TMP1]); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, RenderTargetTextures[RTT_TMP2], 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, RenderTargetTextures[RTT_TMP2], 0); - if (irr_driver->getGLSLVersion() < 150) + if (irr_driver->getGLSLVersion() >= 150) { glGenFramebuffers(1, &shadowFBO); glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO); @@ -128,8 +128,8 @@ RTT::RTT() glGenTextures(1, &shadowDepthTex); glBindTexture(GL_TEXTURE_2D_ARRAY, shadowDepthTex); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, shadowColorTex, 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowDepthTex, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, shadowColorTex, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_ARRAY, shadowDepthTex, 0); GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); } From 4f7bc981bd88e9cc72d1b60e19495a4be0e59b7a Mon Sep 17 00:00:00 2001 From: Max Teufel Date: Sat, 18 Jan 2014 09:55:49 +0100 Subject: [PATCH 02/10] Declare use of OpenGL 3.2 on OS X --- lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm b/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm index 4cac8693d..50ef28a9b 100644 --- a/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm +++ b/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm @@ -642,6 +642,7 @@ bool CIrrDeviceMacOSX::createWindow() NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias, NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0), NSOpenGLPFADoubleBuffer, + NSOpenGLPFAOpenGLProfile, (NSOpenGLPixelFormatAttribute)NSOpenGLProfileVersion3_2Core, (NSOpenGLPixelFormatAttribute)nil }; From 04176d52a89a029b45e8bcb7309037a3688ad9d9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 5 Apr 2014 20:16:15 +0200 Subject: [PATCH 03/10] Do not create shadow vao for ctx < gl 3.2 --- src/graphics/stkinstancedscenenode.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index 78049e13c..f3c01bbee 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -77,9 +77,12 @@ void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMateria glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW); setInstanceAttribPointer(); - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::InstancedShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); - glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); - 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); + glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); + setInstanceAttribPointer(); + } break; case FPSM_ALPHA_REF_TEXTURE: mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, @@ -88,9 +91,12 @@ void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, GeometricMateria glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); glBufferData(GL_ARRAY_BUFFER, instance_pos.size() * sizeof(float), instance_pos.data(), GL_STATIC_DRAW); setInstanceAttribPointer(); - 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); - glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); - 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); + glBindBuffer(GL_ARRAY_BUFFER, instances_vbo); + setInstanceAttribPointer(); + } break; case FPSM_GRASS: mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, From a951a8c8854f875ccef289e9f473860995d47015 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 5 Apr 2014 20:48:50 +0200 Subject: [PATCH 04/10] Wrong glsl check when compressing textures. --- src/graphics/glwrap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 63940deb2..80e45bb2d 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -309,7 +309,7 @@ void transformTexturesTosRGB(irr::video::ITexture *tex) memcpy(data, tex->lock(), w * h * 4); tex->unlock(); glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex)); - if (irr_driver->getGLSLVersion() < 320) + if (irr_driver->getGLSLVersion() < 150) { if (tex->hasAlpha()) glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)data); From 150ee87471486436e3bd954ecf58f8fbc8e5ecf8 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 5 Apr 2014 20:53:38 +0200 Subject: [PATCH 05/10] Use glFrameBufferTexture on shadows buffer We're sure there is at least gl 3.2 support. --- src/graphics/glwrap.cpp | 2 ++ src/graphics/glwrap.hpp | 1 + src/graphics/rtts.cpp | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 80e45bb2d..51581bed8 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -58,6 +58,7 @@ PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; PFNGLTEXIMAGE3DPROC glTexImage3D; PFNGLGENERATEMIPMAPPROC glGenerateMipmap; PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; @@ -200,6 +201,7 @@ void initGL() glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glGenFramebuffers"); glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glBindFramebuffer"); glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture2D"); + glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture"); glTexImage3D = (PFNGLTEXIMAGE3DPROC)IRR_OGL_LOAD_EXTENSION("glTexImage3D"); glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)IRR_OGL_LOAD_EXTENSION("glGenerateMipmap"); glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatus"); diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index a7ecbc57d..da1552b04 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -75,6 +75,7 @@ extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; extern PFNGLTEXIMAGE3DPROC glTexImage3D; extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 74e191182..033631b58 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -128,8 +128,8 @@ RTT::RTT() glGenTextures(1, &shadowDepthTex); glBindTexture(GL_TEXTURE_2D_ARRAY, shadowDepthTex); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, shadowColorTex, 0); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_ARRAY, shadowDepthTex, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, shadowColorTex, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowDepthTex, 0); GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); } From ada1d2617c022a46ec75d8f61aec24fcfe3c0fa2 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 5 Apr 2014 21:21:01 +0200 Subject: [PATCH 06/10] Clear SSAO fbo at least once. On intel driver (windows) texture swizzling seem not to work everytime so use an untouched rtt instead of swizzling SSAO rtt if ssao is disabled. --- src/graphics/render.cpp | 5 ----- src/graphics/rtts.cpp | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index c43f9975a..d444bb5f3 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -441,11 +441,6 @@ void IrrDriver::renderSolidSecondPass() setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST); setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST); setTexture(2, m_rtts->getRenderTarget(RTT_SSAO), GL_NEAREST, GL_NEAREST); - if (!UserConfigParams::m_ssao) - { - GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } m_scene_manager->drawAll(m_renderpass); } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 033631b58..4532035f2 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -100,6 +100,10 @@ RTT::RTT() RenderTargetTextures[RTT_EIGHTH2] = generateRTT(eighth, GL_RGBA16F, GL_BGRA, GL_FLOAT); FrameBuffers[FBO_SSAO] = generateFBO(RenderTargetTextures[RTT_SSAO]); + // Clear this FBO to 1s so that if no SSAO is computed we can still use it. + glClearColor(1., 1., 1., 1.); + glClear(GL_COLOR_BUFFER_BIT); + FrameBuffers[FBO_NORMAL_AND_DEPTHS] = generateFBO(RenderTargetTextures[RTT_NORMAL_AND_DEPTH], DepthStencilTexture); FrameBuffers[FBO_COLORS] = generateFBO(RenderTargetTextures[RTT_COLOR], DepthStencilTexture); FrameBuffers[FBO_MLAA_COLORS] = generateFBO(RenderTargetTextures[RTT_MLAA_COLORS], DepthStencilTexture); From dd51124680864d6457d046e3e06352aaae0cc353 Mon Sep 17 00:00:00 2001 From: vlj Date: Sun, 6 Apr 2014 17:40:51 +0200 Subject: [PATCH 07/10] Fix specular light buffer not written to. --- src/graphics/render.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index d444bb5f3..999a0951a 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -766,6 +766,9 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, for (unsigned i = 0; i < sun_ortho_matrix.size(); i++) sun_ortho_matrix[i] *= getInvViewMatrix(); glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2)); + irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver(); + GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; + gl_driver->extGlDrawBuffers(2, bufs); glClear(GL_COLOR_BUFFER_BIT); const u32 lightcount = m_lights.size(); From 456d57f7ce3a42bd1087b2d3b0e4a5e0a6c7fb81 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sun, 6 Apr 2014 18:31:15 -0400 Subject: [PATCH 08/10] Instancing : don't crash when shaders are off --- src/tracks/track_object_presentation.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 1d37b3dbe..c118f747c 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -160,6 +160,8 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo scene::ISceneNode* parent, ModelDefinitionLoader& model_def_loader) : TrackObjectPresentationSceneNode(xml_node) { + m_instancing_group = NULL; + std::string instancing_model; xml_node.get("instancing_model", &instancing_model); @@ -168,9 +170,12 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo m_node->setRotation(m_init_hpr); m_node->setScale(m_init_scale); m_node->updateAbsolutePosition(); - m_instancing_group = model_def_loader.instanciate(m_node->getAbsolutePosition(), - m_node->getAbsoluteTransformation().getRotationDegrees(), m_node->getAbsoluteTransformation().getScale(), - instancing_model); + if (irr_driver->isGLSL()) + { + m_instancing_group = model_def_loader.instanciate(m_node->getAbsolutePosition(), + m_node->getAbsoluteTransformation().getRotationDegrees(), m_node->getAbsoluteTransformation().getScale(), + instancing_model); + } } TrackObjectPresentationInstancing::~TrackObjectPresentationInstancing() From a413fa3f15d6a07a87d5fc31150295aae5614e07 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sun, 6 Apr 2014 18:46:25 -0400 Subject: [PATCH 09/10] Add proper instancing fallback when shaders are off --- src/graphics/stkinstancedscenenode.cpp | 16 +++++++++++++--- src/tracks/model_definition_loader.cpp | 7 +++++++ src/tracks/model_definition_loader.hpp | 2 ++ src/tracks/track_object_presentation.cpp | 6 ++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index f3c01bbee..5378bdafc 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -8,8 +8,11 @@ STKInstancedSceneNode::STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode const irr::core::vector3df& scale) : CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale) { - createGLMeshes(); - setAutomaticCulling(0); + if (irr_driver->isGLSL()) + { + createGLMeshes(); + setAutomaticCulling(0); + } } void STKInstancedSceneNode::cleanGL() @@ -39,7 +42,8 @@ void STKInstancedSceneNode::cleanGL() STKInstancedSceneNode::~STKInstancedSceneNode() { - cleanGL(); + if (irr_driver->isGLSL()) + cleanGL(); } void STKInstancedSceneNode::createGLMeshes() @@ -306,6 +310,12 @@ static void drawSMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMa void STKInstancedSceneNode::render() { + if (!irr_driver->isGLSL()) + { + CMeshSceneNode::render(); + return; + } + setFirstTimeMaterial(); if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS) diff --git a/src/tracks/model_definition_loader.cpp b/src/tracks/model_definition_loader.cpp index 4212d361a..97b944f35 100644 --- a/src/tracks/model_definition_loader.cpp +++ b/src/tracks/model_definition_loader.cpp @@ -145,3 +145,10 @@ void ModelDefinitionLoader::clear() { m_lod_groups.clear(); } + +// ---------------------------------------------------------------------------- + +scene::IMesh* ModelDefinitionLoader::getFirstMeshFor(const std::string& name) +{ + return irr_driver->getMesh(m_lod_groups[name][0].m_model_file); +} \ No newline at end of file diff --git a/src/tracks/model_definition_loader.hpp b/src/tracks/model_definition_loader.hpp index 51e645478..3c750348d 100644 --- a/src/tracks/model_definition_loader.hpp +++ b/src/tracks/model_definition_loader.hpp @@ -90,6 +90,8 @@ public: void clear(); + + scene::IMesh* getFirstMeshFor(const std::string& name); }; // ModelDefinitionLoader #endif // HEADER_LOD_NODE_LOADER_HPP diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index c118f747c..061280cf2 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -26,6 +26,7 @@ #include "graphics/material_manager.hpp" #include "graphics/particle_emitter.hpp" #include "graphics/particle_kind_manager.hpp" +#include "graphics/stkinstancedscenenode.hpp" #include "io/file_manager.hpp" #include "io/xml_node.hpp" #include "input/device_manager.hpp" @@ -176,6 +177,11 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo m_node->getAbsoluteTransformation().getRotationDegrees(), m_node->getAbsoluteTransformation().getScale(), instancing_model); } + else + { + m_instancing_group = new STKInstancedSceneNode(model_def_loader.getFirstMeshFor(instancing_model), + m_node, irr_driver->getSceneManager(), -1); + } } TrackObjectPresentationInstancing::~TrackObjectPresentationInstancing() From ca2b5a72379d700c92217e1b40235c1c884e6b09 Mon Sep 17 00:00:00 2001 From: vlj Date: Mon, 7 Apr 2014 01:03:14 +0200 Subject: [PATCH 10/10] Fix normal map and srgb --- data/shaders/normalmap.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index 125bd3aaa..fe08ff17e 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -19,7 +19,7 @@ vec2 EncodeNormal(vec3 n); void main() { // normal in Tangent Space - vec3 TS_normal = 2.0 * texture (normalMap, uv).rgb - 1.0; + vec3 TS_normal = 2.0 * pow(texture(normalMap, uv).rgb, vec3(1./2.2)) - 1.0; // Because of interpolation, we need to renormalize vec3 Frag_tangent = normalize(tangent); vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent));