diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index ee27dafe..5bcffa53 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -216,6 +216,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, ExposedData.OpenGLLinux.X11Context = glXGetCurrentContext(); ExposedData.OpenGLLinux.X11Display = glXGetCurrentDisplay(); ExposedData.OpenGLLinux.X11Window = (unsigned long)params.WindowId; + Drawable = glXGetCurrentDrawable(); genericDriverInit(params.WindowSize, params.Stencilbuffer); @@ -368,7 +369,6 @@ bool COpenGLDriver::genericDriverInit(const core::dimension2d& screenSize, createMaterialRenderers(); // set the renderstates - ResetRenderStates = true; setRenderStates3DMode(); // set fog mode @@ -433,7 +433,7 @@ void COpenGLDriver::createMaterialRenderers() //! presents the rendered scene on the screen, returns false if failed -bool COpenGLDriver::endScene( void* windowId, core::rect* sourceRect ) +bool COpenGLDriver::endScene(void* windowId, core::rect* sourceRect) { CNullDriver::endScene(); @@ -442,7 +442,7 @@ bool COpenGLDriver::endScene( void* windowId, core::rect* sourceRect ) #ifdef _IRR_USE_WINDOWS_DEVICE_ return SwapBuffers(HDc) == TRUE; #elif defined(_IRR_USE_LINUX_DEVICE_) - glXSwapBuffers((Display*)ExposedData.OpenGLLinux.X11Display, ExposedData.OpenGLLinux.X11Window); + glXSwapBuffers((Display*)ExposedData.OpenGLLinux.X11Display, Drawable); return true; #elif defined(_IRR_USE_OSX_DEVICE_) _device->flush(); @@ -563,7 +563,6 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) return false; #if defined(GL_ARB_vertex_buffer_object) - const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer; const void* vertices=mb->getVertices(); const u32 vertexCount=mb->getVertexCount(); @@ -580,7 +579,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) case EVT_STANDARD: { S3DVertex* pb = reinterpret_cast(buffer.pointer()); - const S3DVertex* po = reinterpret_cast(vertices); + const S3DVertex* po = static_cast(vertices); for (u32 i=0; i(buffer.pointer()); - const S3DVertex2TCoords* po = reinterpret_cast(vertices); + const S3DVertex2TCoords* po = static_cast(vertices); for (u32 i=0; i(buffer.pointer()); - const S3DVertexTangents* po = reinterpret_cast(vertices); + const S3DVertexTangents* po = static_cast(vertices); for (u32 i=0; ivbo_verticesID ); //copy data to graphics card + glGetError(); // clear error storage if (!newBuffer) extGlBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, buffer.const_pointer()); else @@ -645,8 +645,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) extGlBindBuffer(GL_ARRAY_BUFFER, 0); - return true; - + return (glGetError() == GL_NO_ERROR); #else return false; #endif @@ -662,7 +661,6 @@ bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) return false; #if defined(GL_ARB_vertex_buffer_object) - const scene::IMeshBuffer* mb = HWBuffer->MeshBuffer; const u16* indices=mb->getIndices(); @@ -685,6 +683,7 @@ bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); //copy data to graphics card + glGetError(); // clear error storage if (!newBuffer) extGlBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); else @@ -701,7 +700,7 @@ bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) extGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - return true; + return (glGetError() == GL_NO_ERROR); #else return false; #endif @@ -742,7 +741,6 @@ bool COpenGLDriver::updateHardwareBuffer(SHWBufferLink *HWBuffer) COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::IMeshBuffer* mb) { #if defined(GL_ARB_vertex_buffer_object) - if (!mb || (mb->getHardwareMappingHint()==scene::EHM_NEVER)) return 0; @@ -854,7 +852,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun { case EVT_STANDARD: { - const S3DVertex* p = reinterpret_cast(vertices); + const S3DVertex* p = static_cast(vertices); for ( i=0; iColor.toOpenGLColor(&ColorBuffer[i]); @@ -864,7 +862,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun break; case EVT_2TCOORDS: { - const S3DVertex2TCoords* p = reinterpret_cast(vertices); + const S3DVertex2TCoords* p = static_cast(vertices); for ( i=0; iColor.toOpenGLColor(&ColorBuffer[i]); @@ -874,7 +872,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun break; case EVT_TANGENTS: { - const S3DVertexTangents* p = reinterpret_cast(vertices); + const S3DVertexTangents* p = static_cast(vertices); for ( i=0; iColor.toOpenGLColor(&ColorBuffer[i]); @@ -906,9 +904,9 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun case EVT_STANDARD: if (vertices) { - glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Normal); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].TCoords); - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].Pos); + glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); } else { @@ -923,7 +921,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun extGlClientActiveTexture(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (vertices) - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(reinterpret_cast(vertices))[0].TCoords); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); else glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); } @@ -931,9 +929,9 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun case EVT_2TCOORDS: if (vertices) { - glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].Normal); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].TCoords); - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].Pos); + glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); } else { @@ -949,7 +947,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun extGlClientActiveTexture(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (vertices) - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(reinterpret_cast(vertices))[0].TCoords2); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); else glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36)); } @@ -957,9 +955,9 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun case EVT_TANGENTS: if (vertices) { - glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Normal); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].TCoords); - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Pos); + glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Normal); + glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); + glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); } else { @@ -974,14 +972,14 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun extGlClientActiveTexture(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (vertices) - glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Tangent); + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Tangent); else glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36)); extGlClientActiveTexture(GL_TEXTURE2_ARB); glEnableClientState ( GL_TEXTURE_COORD_ARRAY ); if (vertices) - glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(reinterpret_cast(vertices))[0].Binormal); + glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Binormal); else glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(48)); } @@ -1274,7 +1272,6 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect } - //! draws a set of 2d images, using a color and the alpha channel of the //! texture if desired. The images are drawn beginning at pos and concatenated //! in one line. All drawings are clipped against clipRect (if != 0). @@ -1350,7 +1347,6 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, } - //! draw a 2d rectangle void COpenGLDriver::draw2DRectangle(SColor color, const core::rect& position, const core::rect* clip) @@ -1372,7 +1368,6 @@ void COpenGLDriver::draw2DRectangle(SColor color, const core::rect& positio } - //! draw an 2d rectangle void COpenGLDriver::draw2DRectangle(const core::rect& position, SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, @@ -1414,7 +1409,6 @@ void COpenGLDriver::draw2DRectangle(const core::rect& position, } - //! Draws a 2d line. void COpenGLDriver::draw2DLine(const core::position2d& start, const core::position2d& end, @@ -1467,7 +1461,6 @@ bool COpenGLDriver::setTexture(u32 stage, const video::ITexture* texture) } - //! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled. //! Returns whether disabling was successful or not. bool COpenGLDriver::disableTextures(u32 fromStage) @@ -1479,7 +1472,6 @@ bool COpenGLDriver::disableTextures(u32 fromStage) } - //! creates a matrix in supplied GLfloat array to pass to OpenGL inline void COpenGLDriver::createGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m) { @@ -1907,7 +1899,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef (0.375, 0.375, 0.0); + glTranslatef(0.375, 0.375, 0.0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); @@ -2488,7 +2480,7 @@ ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d& if (rtt) { rtt->grab(); - static_cast(rtt)->setRenderTarget(true); + static_cast(rtt)->setIsRenderTarget(true); } } @@ -2608,7 +2600,7 @@ IImage* COpenGLDriver::createScreenShot() { IImage* newImage = new CImage(ECF_R8G8B8, ScreenSize); - u8* pPixels = reinterpret_cast(newImage->lock()); + u8* pPixels = static_cast(newImage->lock()); if (!pPixels) { newImage->drop(); diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 8251ce6c..d6baadca 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -393,6 +393,8 @@ namespace video HDC HDc; // Private GDI Device Context HWND Window; HGLRC HRc; // Permanent Rendering Context + #elif defined(_IRR_USE_LINUX_DEVICE_) + GLXDrawable Drawable; #elif defined(_IRR_USE_OSX_DEVICE_) CIrrDeviceMacOSX *_device; #endif diff --git a/source/Irrlicht/COpenGLMaterialRenderer.h b/source/Irrlicht/COpenGLMaterialRenderer.h index b6c87144..9ced2797 100644 --- a/source/Irrlicht/COpenGLMaterialRenderer.h +++ b/source/Irrlicht/COpenGLMaterialRenderer.h @@ -91,7 +91,7 @@ public: Driver->setTexture(0, material.getTexture(0)); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); - if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) + if (resetAllRenderstates || (material.MaterialType != lastMaterial.MaterialType)) { // thanks to Murphy, the following line removed some // bugs with several OpenGL implementations. diff --git a/source/Irrlicht/COpenGLTexture.cpp b/source/Irrlicht/COpenGLTexture.cpp index 07c46703..0fc254f9 100644 --- a/source/Irrlicht/COpenGLTexture.cpp +++ b/source/Irrlicht/COpenGLTexture.cpp @@ -406,7 +406,7 @@ const core::dimension2d& COpenGLTexture::getOriginalSize() const } -//! Returns of the texture. +//! Returns size of the texture. const core::dimension2d& COpenGLTexture::getSize() const { if (Image) @@ -501,7 +501,7 @@ bool COpenGLTexture::isRenderTarget() const } -void COpenGLTexture::setRenderTarget(bool isTarget) +void COpenGLTexture::setIsRenderTarget(bool isTarget) { IsRenderTarget = isTarget; } diff --git a/source/Irrlicht/COpenGLTexture.h b/source/Irrlicht/COpenGLTexture.h index b76d09a0..dc8ef23c 100644 --- a/source/Irrlicht/COpenGLTexture.h +++ b/source/Irrlicht/COpenGLTexture.h @@ -99,7 +99,7 @@ public: void unbindFrameBufferObject(); //! sets whether this texture is intended to be used as a render target. - void setRenderTarget(bool isTarget); + void setIsRenderTarget(bool isTarget); private: