diff --git a/lib/irrlicht/CMakeLists.txt b/lib/irrlicht/CMakeLists.txt index 2a73d0533..7018bc254 100644 --- a/lib/irrlicht/CMakeLists.txt +++ b/lib/irrlicht/CMakeLists.txt @@ -187,6 +187,7 @@ source/Irrlicht/CZipReader.cpp source/Irrlicht/Irrlicht.cpp source/Irrlicht/irrXML.cpp source/Irrlicht/os.cpp +source/Irrlicht/COpenGLNormalMapRenderer.cpp source/Irrlicht/BuiltInFont.h source/Irrlicht/CAnimatedMeshSceneNode.h source/Irrlicht/CAttributeImpl.h @@ -339,6 +340,7 @@ source/Irrlicht/S4DVertex.h source/Irrlicht/SoftwareDriver2_compile_config.h source/Irrlicht/SoftwareDriver2_helper.h source/Irrlicht/wglext.h +source/Irrlicht/COpenGLNormalMapRenderer.h include/aabbox3d.h include/CDynamicMeshBuffer.h diff --git a/lib/irrlicht/source/Irrlicht/CNullDriver.h b/lib/irrlicht/source/Irrlicht/CNullDriver.h index 251062b68..96b429c79 100644 --- a/lib/irrlicht/source/Irrlicht/CNullDriver.h +++ b/lib/irrlicht/source/Irrlicht/CNullDriver.h @@ -700,17 +700,20 @@ namespace video //! normal map lookup 32 bit version inline f32 nml32(int x, int y, int pitch, int height, s32 *p) const { - if (x < 0) x = pitch-1; if (x >= pitch) x = 0; - if (y < 0) y = height-1; if (y >= height) y = 0; + if (x < 0) x = pitch-1; + if (x >= pitch) x = 0; + if (y < 0) y = height-1; + if (y >= height) y = 0; return (f32)(((p[(y * pitch) + x])>>16) & 0xff); } //! normal map lookup 16 bit version inline f32 nml16(int x, int y, int pitch, int height, s16 *p) const { - if (x < 0) x = pitch-1; if (x >= pitch) x = 0; - if (y < 0) y = height-1; if (y >= height) y = 0; - + if (x < 0) x = pitch-1; + if (x >= pitch) x = 0; + if (y < 0) y = height-1; + if (y >= height) y = 0; return (f32) getAverage ( p[(y * pitch) + x] ); } diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp index 1a1d61350..e866c7215 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp @@ -14,6 +14,7 @@ extern bool GLContextDebugBit; #include "COpenGLMaterialRenderer.h" #include "COpenGLShaderMaterialRenderer.h" #include "COpenGLSLMaterialRenderer.h" +#include "COpenGLNormalMapRenderer.h" #include "COpenGLParallaxMapRenderer.h" #include "os.h" @@ -29,7 +30,7 @@ namespace irr { namespace video { - bool useCoreContext; + bool useCoreContext; // ----------------------------------------------------------------------- // WINDOWS CONSTRUCTOR // ----------------------------------------------------------------------- @@ -85,107 +86,107 @@ static PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs_ARB; static HGLRC getMeAGLContext(HDC HDc, bool force_legacy_context) { - if (!force_legacy_context) - { - useCoreContext = true; - HGLRC hrc = 0; - int ctx44debug[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 4, - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + if (!force_legacy_context) + { + useCoreContext = true; + HGLRC hrc = 0; + int ctx44debug[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 4, + WGL_CONTEXT_MINOR_VERSION_ARB, 3, + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - int ctx44[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 4, - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx44[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 4, + WGL_CONTEXT_MINOR_VERSION_ARB, 3, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx44debug : ctx44); - if (hrc) - return hrc; + hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx44debug : ctx44); + if (hrc) + return hrc; - int ctx40debug[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 4, - WGL_CONTEXT_MINOR_VERSION_ARB, 0, - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx40debug[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 4, + WGL_CONTEXT_MINOR_VERSION_ARB, 0, + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - int ctx40[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 4, - WGL_CONTEXT_MINOR_VERSION_ARB, 0, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx40[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 4, + WGL_CONTEXT_MINOR_VERSION_ARB, 0, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx40debug : ctx40); - if (hrc) - return hrc; + hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx40debug : ctx40); + if (hrc) + return hrc; - int ctx33debug[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx33debug[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, + WGL_CONTEXT_MINOR_VERSION_ARB, 3, + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - int ctx33[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx33[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, + WGL_CONTEXT_MINOR_VERSION_ARB, 3, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx33debug : ctx33); - if (hrc) - return hrc; + hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx33debug : ctx33); + if (hrc) + return hrc; - int ctx31debug[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - WGL_CONTEXT_MINOR_VERSION_ARB, 1, - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx31debug[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, + WGL_CONTEXT_MINOR_VERSION_ARB, 1, + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - int ctx31[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - WGL_CONTEXT_MINOR_VERSION_ARB, 1, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0 - }; + int ctx31[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, + WGL_CONTEXT_MINOR_VERSION_ARB, 1, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + 0 + }; - hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx31debug : ctx31); - if (hrc) - return hrc; - } // if (!force_legacy_context) + hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx31debug : ctx31); + if (hrc) + return hrc; + } // if (!force_legacy_context) - useCoreContext = false; - int legacyctx[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 2, - WGL_CONTEXT_MINOR_VERSION_ARB, 1, - 0 - }; - HGLRC hrc = wglCreateContextAttribs_ARB(HDc, 0, legacyctx); - if (hrc) - return hrc; + useCoreContext = false; + int legacyctx[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, 2, + WGL_CONTEXT_MINOR_VERSION_ARB, 1, + 0 + }; + HGLRC hrc = wglCreateContextAttribs_ARB(HDc, 0, legacyctx); + if (hrc) + return hrc; - return NULL; + return NULL; } //! inits the open gl driver @@ -513,8 +514,8 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device) #ifdef WGL_ARB_create_context if (wglCreateContextAttribs_ARB) { - hrc = getMeAGLContext(HDc, Params.ForceLegacyDevice); - } + hrc = getMeAGLContext(HDc, Params.ForceLegacyDevice); + } else #endif hrc=wglCreateContext(HDc); @@ -797,11 +798,11 @@ bool COpenGLDriver::genericDriverInit() setAmbientLight(SColorf(0.0f,0.0f,0.0f,0.0f)); #ifdef GL_EXT_separate_specular_color - if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext) + if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext) glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif - if (!useCoreContext) - glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); + if (!useCoreContext) + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); Params.HandleSRGB &= ((FeatureAvailable[IRR_ARB_framebuffer_sRGB] || FeatureAvailable[IRR_EXT_framebuffer_sRGB]) && FeatureAvailable[IRR_EXT_texture_sRGB]); @@ -820,8 +821,8 @@ bool COpenGLDriver::genericDriverInit() // glEnable(GL_RESCALE_NORMAL_EXT); glClearDepth(1.0); - if (!useCoreContext) - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + if (!useCoreContext) + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST); glDepthFunc(GL_LEQUAL); @@ -837,8 +838,8 @@ bool COpenGLDriver::genericDriverInit() // set the renderstates setRenderStates3DMode(); - if (!useCoreContext) - glAlphaFunc(GL_GREATER, 0.f); + if (!useCoreContext) + glAlphaFunc(GL_GREATER, 0.f); // set fog mode setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog); @@ -885,6 +886,15 @@ void COpenGLDriver::createMaterialRenderers() // add normal map renderers s32 tmp = 0; video::IMaterialRenderer* renderer = 0; + if (!useCoreContext) + { + renderer = new COpenGLNormalMapRenderer(this, tmp, MaterialRenderers[EMT_SOLID].Renderer); + renderer->drop(); + renderer = new COpenGLNormalMapRenderer(this, tmp, MaterialRenderers[EMT_TRANSPARENT_ADD_COLOR].Renderer); + renderer->drop(); + renderer = new COpenGLNormalMapRenderer(this, tmp, MaterialRenderers[EMT_TRANSPARENT_VERTEX_ALPHA].Renderer); + renderer->drop(); + } // add parallax map renderers renderer = new COpenGLParallaxMapRenderer(this, tmp, MaterialRenderers[EMT_SOLID].Renderer); @@ -1025,29 +1035,31 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri case ETS_WORLD: { // OpenGL only has a model matrix, view and world is not existent. so lets fake these two. - if (!useCoreContext) - glMatrixMode(GL_MODELVIEW); + if (!useCoreContext) + glMatrixMode(GL_MODELVIEW); // first load the viewing transformation for user clip planes - if (!useCoreContext) - glLoadMatrixf((Matrices[ETS_VIEW]).pointer()); + if (!useCoreContext) + glLoadMatrixf((Matrices[ETS_VIEW]).pointer()); // we have to update the clip planes to the latest view matrix for (u32 i=0; igetDriverType() != EDT_OPENGL) { - if (!useCoreContext) - glDisable(GL_TEXTURE_2D); + if (!useCoreContext) + glDisable(GL_TEXTURE_2D); CurrentTexture.set(stage, 0); os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR); return false; } - if (!useCoreContext) - glEnable(GL_TEXTURE_2D); + if (!useCoreContext) + glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, static_cast(texture)->getOpenGLTextureName()); } @@ -2658,20 +2670,20 @@ void COpenGLDriver::setRenderStates3DMode() { // Reset Texture Stages glDisable(GL_BLEND); - if (!useCoreContext) - glDisable(GL_ALPHA_TEST); + if (!useCoreContext) + glDisable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // switch back the matrices - if (!useCoreContext) - glMatrixMode(GL_MODELVIEW); - if (!useCoreContext) - glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); + if (!useCoreContext) + glMatrixMode(GL_MODELVIEW); + if (!useCoreContext) + glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); - if (!useCoreContext) - glMatrixMode(GL_PROJECTION); - if (!useCoreContext) - glLoadMatrixf(Matrices[ETS_PROJECTION].pointer()); + if (!useCoreContext) + glMatrixMode(GL_PROJECTION); + if (!useCoreContext) + glLoadMatrixf(Matrices[ETS_PROJECTION].pointer()); ResetRenderStates = true; #ifdef GL_EXT_clip_volume_hint @@ -2838,27 +2850,27 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater glDisable(GL_COLOR_MATERIAL); break; case ECM_DIFFUSE: - if (!useCoreContext) - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + if (!useCoreContext) + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); break; case ECM_AMBIENT: - if (!useCoreContext) - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); + if (!useCoreContext) + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); break; case ECM_EMISSIVE: - if (!useCoreContext) - glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); + if (!useCoreContext) + glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); break; case ECM_SPECULAR: - if (!useCoreContext) - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); + if (!useCoreContext) + glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); break; case ECM_DIFFUSE_AND_AMBIENT: - if (!useCoreContext) - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + if (!useCoreContext) + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); break; } - if (material.ColorMaterial != ECM_NONE && !useCoreContext) + if (material.ColorMaterial != ECM_NONE && !useCoreContext) glEnable(GL_COLOR_MATERIAL); } @@ -2879,8 +2891,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater color[1] = material.AmbientColor.getGreen() * inv; color[2] = material.AmbientColor.getBlue() * inv; color[3] = material.AmbientColor.getAlpha() * inv; - if (!useCoreContext) - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); + if (!useCoreContext) + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); } if ((material.ColorMaterial != video::ECM_DIFFUSE) && @@ -2890,8 +2902,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater color[1] = material.DiffuseColor.getGreen() * inv; color[2] = material.DiffuseColor.getBlue() * inv; color[3] = material.DiffuseColor.getAlpha() * inv; - if (!useCoreContext) - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); + if (!useCoreContext) + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); } if (material.ColorMaterial != video::ECM_EMISSIVE) @@ -2900,8 +2912,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater color[1] = material.EmissiveColor.getGreen() * inv; color[2] = material.EmissiveColor.getBlue() * inv; color[3] = material.EmissiveColor.getAlpha() * inv; - if (!useCoreContext) - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); + if (!useCoreContext) + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); } } @@ -2913,14 +2925,14 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater GLfloat color[4]={0.f,0.f,0.f,1.f}; const f32 inv = 1.0f / 255.0f; - if (!useCoreContext) - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess); + if (!useCoreContext) + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess); // disable Specular colors if no shininess is set if ((material.Shininess != 0.0f) && (material.ColorMaterial != video::ECM_SPECULAR)) { #ifdef GL_EXT_separate_specular_color - if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext) + if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext) glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif color[0] = material.SpecularColor.getRed() * inv; @@ -2929,11 +2941,11 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater color[3] = material.SpecularColor.getAlpha() * inv; } #ifdef GL_EXT_separate_specular_color - else if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext) + else if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext) glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); #endif - if (!useCoreContext) - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); + if (!useCoreContext) + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); } // Texture filter @@ -2987,18 +2999,18 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater // shademode if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading)) { - if (material.GouraudShading && !useCoreContext) + if (material.GouraudShading && !useCoreContext) glShadeModel(GL_SMOOTH); - else if (!useCoreContext) + else if (!useCoreContext) glShadeModel(GL_FLAT); } // lighting if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting)) { - if (material.Lighting && !useCoreContext) + if (material.Lighting && !useCoreContext) glEnable(GL_LIGHTING); - else if (!useCoreContext) + else if (!useCoreContext) glDisable(GL_LIGHTING); } @@ -3079,18 +3091,18 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater // fog if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable) { - if (material.FogEnable && !useCoreContext) + if (material.FogEnable && !useCoreContext) glEnable(GL_FOG); - else if (!useCoreContext) + else if (!useCoreContext) glDisable(GL_FOG); } // normalization if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals) { - if (material.NormalizeNormals && !useCoreContext) + if (material.NormalizeNormals && !useCoreContext) glEnable(GL_NORMALIZE); - else if (!useCoreContext) + else if (!useCoreContext) glDisable(GL_NORMALIZE); } @@ -3470,9 +3482,11 @@ const wchar_t* COpenGLDriver::getName() const //! deletes all dynamic lights there are void COpenGLDriver::deleteAllDynamicLights() { - if (!useCoreContext) - for (s32 i=0; iqueryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1) || + !driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1)) + { + // this hardware is not able to do shaders. Fall back to + // base material. + outMaterialTypeNr = driver->addMaterialRenderer(this); + return; + } + + // check if already compiled normal map shaders are there. + + video::IMaterialRenderer* renderer = driver->getMaterialRenderer(EMT_NORMAL_MAP_SOLID); + + if (renderer) + { + // use the already compiled shaders + video::COpenGLNormalMapRenderer* nmr = reinterpret_cast(renderer); + CompiledShaders = false; + + VertexShader = nmr->VertexShader; + PixelShader = nmr->PixelShader; + + outMaterialTypeNr = driver->addMaterialRenderer(this); + } + else + { + // compile shaders on our own + init(outMaterialTypeNr, OPENGL_NORMAL_MAP_VSH, OPENGL_NORMAL_MAP_PSH, EVT_TANGENTS); + } + + // fallback if compilation has failed + if (-1==outMaterialTypeNr) + outMaterialTypeNr = driver->addMaterialRenderer(this); +} + + +//! Destructor +COpenGLNormalMapRenderer::~COpenGLNormalMapRenderer() +{ + if (CallBack == this) + CallBack = 0; + + if (!CompiledShaders) + { + // prevent this from deleting shaders we did not create + VertexShader = 0; + PixelShader.clear(); + } +} + + +//! Returns the render capability of the material. +s32 COpenGLNormalMapRenderer::getRenderCapability() const +{ + if (Driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1) && + Driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1)) + return 0; + + return 1; +} + + +//! Called by the engine when the vertex and/or pixel shader constants for an +//! material renderer should be set. +void COpenGLNormalMapRenderer::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + video::IVideoDriver* driver = services->getVideoDriver(); + + // set transposed world matrix + const core::matrix4& tWorld = driver->getTransform(video::ETS_WORLD).getTransposed(); + services->setVertexShaderConstant(tWorld.pointer(), 0, 4); + + // set transposed worldViewProj matrix + core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION)); + worldViewProj *= driver->getTransform(video::ETS_VIEW); + worldViewProj *= driver->getTransform(video::ETS_WORLD); + core::matrix4 tr(worldViewProj.getTransposed()); + services->setVertexShaderConstant(tr.pointer(), 8, 4); + + // here we fetch the fixed function lights from the driver + // and set them as constants + + u32 cnt = driver->getDynamicLightCount(); + + // Load the inverse world matrix. + core::matrix4 invWorldMat; + driver->getTransform(video::ETS_WORLD).getInverse(invWorldMat); + + for (u32 i=0; i<2; ++i) + { + video::SLight light; + + if (igetDynamicLight(i); + else + { + light.DiffuseColor.set(0,0,0); // make light dark + light.Radius = 1.0f; + } + + light.DiffuseColor.a = 1.0f/(light.Radius*light.Radius); // set attenuation + + // Transform the light by the inverse world matrix to get it into object space. + invWorldMat.transformVect(light.Position); + + services->setVertexShaderConstant( + reinterpret_cast(&light.Position), 12+(i*2), 1); + + services->setVertexShaderConstant( + reinterpret_cast(&light.DiffuseColor), 13+(i*2), 1); + } +} + + +} // end namespace video +} // end namespace irr + + +#endif + diff --git a/lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.h b/lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.h new file mode 100644 index 000000000..304802dc6 --- /dev/null +++ b/lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.h @@ -0,0 +1,49 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifndef __C_OPENGL_NORMAL_MAP_RENDERER_H_INCLUDED__ +#define __C_OPENGL_NORMAL_MAP_RENDERER_H_INCLUDED__ + +#include "IrrCompileConfig.h" +#ifdef _IRR_COMPILE_WITH_OPENGL_ + +#include "COpenGLShaderMaterialRenderer.h" +#include "IShaderConstantSetCallBack.h" + +namespace irr +{ +namespace video +{ + +//! Class for rendering normal maps with OpenGL +class COpenGLNormalMapRenderer : public COpenGLShaderMaterialRenderer, public IShaderConstantSetCallBack +{ +public: + + //! Constructor + COpenGLNormalMapRenderer(video::COpenGLDriver* driver, + s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial); + + //! Destructor + ~COpenGLNormalMapRenderer(); + + //! Called by the engine when the vertex and/or pixel shader constants for an + //! material renderer should be set. + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + + //! Returns the render capability of the material. + virtual s32 getRenderCapability() const; + +protected: + + bool CompiledShaders; +}; + + +} // end namespace video +} // end namespace irr + +#endif +#endif + diff --git a/src/graphics/particle_emitter.cpp b/src/graphics/particle_emitter.cpp index 4fab01682..cfc4e584e 100644 --- a/src/graphics/particle_emitter.cpp +++ b/src/graphics/particle_emitter.cpp @@ -521,14 +521,6 @@ void ParticleEmitter::setParticleType(const ParticleKind* type) m_node->setMaterialTexture(0, material->getTexture()); mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent - - // fallback for old render engine - if (material->getShaderType() == Material::SHADERTYPE_ADDITIVE) - mat0.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR; - else if (material->getShaderType() == Material::SHADERTYPE_ALPHA_BLEND) - mat0.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - else if (material->getShaderType() == Material::SHADERTYPE_ALPHA_TEST) - mat0.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; } else {