diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 1a70aa4e..cc522efa 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -356,14 +356,14 @@ void COpenGLDriver::createMaterialRenderers() lmr->drop(); // add remaining material renderer - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_DETAIL_MAP( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_SPHERE_MAP( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_REFLECTION_2_LAYER( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ADD_COLOR( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA( this)); - addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER( this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_DETAIL_MAP(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_SPHERE_MAP(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_REFLECTION_2_LAYER(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ADD_COLOR(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_VERTEX_ALPHA(this)); + addAndDropMaterialRenderer(new COpenGLMaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(this)); // add normal map renderers s32 tmp = 0; @@ -511,7 +511,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) if (!HWBuffer) return false; - if (!VertexBufferObjectExtension) + if (!FeatureAvailable[IRR_ARB_vertex_buffer_object]) return false; const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer; @@ -521,16 +521,16 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) u32 vertexSize = getVertexPitchFromType(vType); //buffer vertex data, and convert colours... - core::array buffer(vertexSize * vertexCount); - memcpy(buffer.pointer(), vertices, vertexSize * vertexCount); + core::array buffer(vertexSize * vertexCount); + memcpy(buffer.pointer(), vertices, vertexSize * vertexCount); - // in order to convert the colours into opengl format (RGBA) - switch (vType) + // in order to convert the colours into opengl format (RGBA) + switch (vType) { case EVT_STANDARD: { const S3DVertex* pb = reinterpret_cast(buffer.pointer()); - const S3DVertex* po = reinterpret_cast(vertices); + const S3DVertex* po = reinterpret_cast(vertices); for (u32 i=0; i(buffer.pointer()); - const S3DVertex2TCoords* po = reinterpret_cast(vertices); + const S3DVertex2TCoords* po = reinterpret_cast(vertices); for (u32 i=0; i(buffer.pointer()); - const S3DVertexTangents* po = reinterpret_cast(vertices); + const S3DVertexTangents* po = reinterpret_cast(vertices); for (u32 i=0; iMeshBuffer; const u16* indices=mb->getIndices(); u32 indexCount= mb->getIndexCount(); - u32 indexSize = 2; + u32 indexSize = 2; - - //get or create buffer - bool newBuffer=false; + //get or create buffer + bool newBuffer=false; if (!HWBuffer->vbo_indicesID) { extGlGenBuffers(1, &HWBuffer->vbo_indicesID); @@ -634,8 +632,6 @@ bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) } - - //! updates hardware buffer if needed bool COpenGLDriver::updateHardwareBuffer(SHWBufferLink *HWBuffer) { @@ -656,15 +652,15 @@ bool COpenGLDriver::updateHardwareBuffer(SHWBufferLink *HWBuffer) return true; } -//! Create hardware buffer from mesh + +//! Create hardware buffer from meshbuffer COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::IMeshBuffer* mb) { - if (!mb) return 0; - if (mb->getHardwareMappingHint()==scene::EHM_NEVER) return 0; + if (!mb || (mb->getHardwareMappingHint()==scene::EHM_NEVER)) + return 0; SHWBufferLink_opengl *HWBuffer=new SHWBufferLink_opengl(mb); - //add to list, in order of their meshbuffer pointer u32 n; for (n=0;nMeshBuffer; @@ -797,16 +796,21 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES)) glEnableClientState(GL_NORMAL_ARRAY); - if (vertices) glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); + if (vertices) + glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); switch (vType) { case EVT_STANDARD: - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Pos); + if (vertices) + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Pos); + else + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0); glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Normal); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].TCoords); - if (!vertices) glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Color); + if (!vertices) + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Color); if (MultiTextureExtension && CurrentTexture[1]) { @@ -816,7 +820,10 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun } break; case EVT_2TCOORDS: - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].Pos); + if (vertices) + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].Pos); + else + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), 0); glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].Normal); // texture coordinates glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].TCoords); @@ -831,7 +838,10 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun } break; case EVT_TANGENTS: - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Pos); + if (vertices) + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Pos); + else + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), 0); glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Normal); // texture coordinates glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].TCoords); @@ -930,11 +940,9 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - //! draws a 2d image, using a color and the alpha channel of the texture if //! desired. The image is drawn at pos, clipped against clipRect (if != 0). //! Only the subtexture defined by sourceRect is used. @@ -1980,8 +1988,8 @@ void COpenGLDriver::setViewPort(const core::rect& area) if (vp.getHeight()>0 && vp.getWidth()>0) glViewport(vp.UpperLeftCorner.X, - getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), - vp.getWidth(), vp.getHeight()); + getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), + vp.getWidth(), vp.getHeight()); ViewPort = vp; } @@ -2357,7 +2365,7 @@ ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d& #if defined(GL_EXT_framebuffer_object) // if driver supports FrameBufferObjects, use them if (queryFeature(EVDF_FRAMEBUFFER_OBJECT)) - rtt = new COpenGLTexture(size, FeatureAvailable[IRR_EXT_packed_depth_stencil], name, this); + rtt = new COpenGLTexture(size, FeatureAvailable[IRR_EXT_packed_depth_stencil], name, this); else #endif { @@ -2387,7 +2395,7 @@ u32 COpenGLDriver::getMaximalPrimitiveCount() const //! checks triangle count and print warning if wrong bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuffer, - bool clearZBuffer, SColor color) + bool clearZBuffer, SColor color) { // check for right driver type @@ -2405,6 +2413,8 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff ResetRenderStates=true; if (RenderTargetTexture!=0) { + glReadPixels(0, 0, RenderTargetTexture->getSize().Width, RenderTargetTexture->getSize().Height, GL_RGBA, GL_UNSIGNED_BYTE, RenderTargetTexture->lock()); + RenderTargetTexture->unlock(); if (RenderTargetTexture->isFrameBufferObject()) { RenderTargetTexture->unbindFrameBufferObject(); @@ -2468,18 +2478,20 @@ const core::dimension2d& COpenGLDriver::getCurrentRenderTargetSize() const return CurrentRendertargetSize; } + //! Clears the ZBuffer. void COpenGLDriver::clearZBuffer() { - GLboolean enabled = GL_TRUE; - glGetBooleanv(GL_DEPTH_WRITEMASK, &enabled); + GLboolean enabled = GL_TRUE; + glGetBooleanv(GL_DEPTH_WRITEMASK, &enabled); - glDepthMask(GL_TRUE); - glClear(GL_DEPTH_BUFFER_BIT); + glDepthMask(GL_TRUE); + glClear(GL_DEPTH_BUFFER_BIT); - glDepthMask(enabled); + glDepthMask(enabled); } + //! Returns an image created from the last rendered frame. IImage* COpenGLDriver::createScreenShot() { diff --git a/source/Irrlicht/COpenGLExtensionHandler.cpp b/source/Irrlicht/COpenGLExtensionHandler.cpp index 9e10d889..fa7be499 100644 --- a/source/Irrlicht/COpenGLExtensionHandler.cpp +++ b/source/Irrlicht/COpenGLExtensionHandler.cpp @@ -15,9 +15,7 @@ namespace video COpenGLExtensionHandler::COpenGLExtensionHandler() : StencilBuffer(false), MultiTextureExtension(false), MultiSamplingExtension(false), AnisotropyExtension(false), - SeparateStencilExtension(false), TextureCompressionExtension(false), - VertexBufferObjectExtension(false), MaxTextureUnits(1), MaxLights(1), MaxIndices(65535), MaxAnisotropy(1.0f), MaxUserClipPlanes(0), Version(0), ShaderLanguageVersion(0) @@ -102,9 +100,7 @@ void COpenGLExtensionHandler::initExtensions(bool stencilBuffer) MultiTextureExtension = FeatureAvailable[IRR_ARB_multitexture]; MultiSamplingExtension = FeatureAvailable[IRR_ARB_multisample]; AnisotropyExtension = FeatureAvailable[IRR_EXT_texture_filter_anisotropic]; - SeparateStencilExtension = FeatureAvailable[IRR_ATI_separate_stencil]; TextureCompressionExtension = FeatureAvailable[IRR_ARB_texture_compression]; - VertexBufferObjectExtension = FeatureAvailable[IRR_ARB_vertex_buffer_object]; StencilBuffer=stencilBuffer; #ifdef _IRR_WINDOWS_API_ diff --git a/source/Irrlicht/COpenGLExtensionHandler.h b/source/Irrlicht/COpenGLExtensionHandler.h index 23be54f4..243d5cee 100644 --- a/source/Irrlicht/COpenGLExtensionHandler.h +++ b/source/Irrlicht/COpenGLExtensionHandler.h @@ -663,9 +663,7 @@ class COpenGLExtensionHandler bool MultiTextureExtension; bool MultiSamplingExtension; bool AnisotropyExtension; - bool SeparateStencilExtension; bool TextureCompressionExtension; - bool VertexBufferObjectExtension; // Some non-boolean properties //! Maxmimum texture layers supported by the fixed pipeline diff --git a/source/Irrlicht/COpenGLTexture.h b/source/Irrlicht/COpenGLTexture.h index 5e84225f..84512f23 100644 --- a/source/Irrlicht/COpenGLTexture.h +++ b/source/Irrlicht/COpenGLTexture.h @@ -61,13 +61,13 @@ public: //! unlock function virtual void unlock(); - //! Returns original size of the texture. + //! Returns original size of the texture (image). virtual const core::dimension2d& getOriginalSize() const; //! Returns size of the texture. virtual const core::dimension2d& getSize() const; - //! returns driver type of texture (=the driver, who created the texture) + //! returns driver type of texture (=the driver, that created it) virtual E_DRIVER_TYPE getDriverType() const; //! returns color format of texture @@ -113,7 +113,7 @@ private: //! \param: newTexture is true if method is called from a newly created texture for the first time. Otherwise call with false to improve memory handling. void copyTexture(bool newTexture=true); - //! returns the size of a texture which would be the optimize size for rendering it + //! returns the size of a texture which would be optimal for rendering inline s32 getTextureSizeFromSurfaceSize(s32 size) const; core::dimension2d ImageSize;