Commit d3491565 authored by hybrid's avatar hybrid

Added RTT locking for OpenGL driver.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1455 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2275b5fa
...@@ -2630,7 +2630,7 @@ IImage* COpenGLDriver::createScreenShot() ...@@ -2630,7 +2630,7 @@ IImage* COpenGLDriver::createScreenShot()
#endif #endif
{ {
// opengl images are horizontally flipped, so we have to fix that here. // opengl images are horizontally flipped, so we have to fix that here.
s32 pitch=newImage->getPitch(); const s32 pitch=newImage->getPitch();
u8* p2 = pPixels + (ScreenSize.Height - 1) * pitch; u8* p2 = pPixels + (ScreenSize.Height - 1) * pitch;
u8* tmpBuffer = new u8[pitch]; u8* tmpBuffer = new u8[pitch];
for (s32 i=0; i < ScreenSize.Height; i += 2) for (s32 i=0; i < ScreenSize.Height; i += 2)
......
...@@ -65,6 +65,8 @@ namespace irr ...@@ -65,6 +65,8 @@ namespace irr
namespace video namespace video
{ {
class COpenGLTexture;
static const char* const OpenGLFeatureStrings[] = { static const char* const OpenGLFeatureStrings[] = {
"GL_3DFX_multisample", "GL_3DFX_multisample",
"GL_3DFX_tbuffer", "GL_3DFX_tbuffer",
...@@ -650,6 +652,8 @@ class COpenGLExtensionHandler ...@@ -650,6 +652,8 @@ class COpenGLExtensionHandler
IRR_OpenGL_Feature_Count IRR_OpenGL_Feature_Count
}; };
friend class COpenGLTexture;
// constructor // constructor
COpenGLExtensionHandler(); COpenGLExtensionHandler();
......
...@@ -30,7 +30,7 @@ COpenGLTexture::COpenGLTexture(IImage* origImage, const char* name, COpenGLDrive ...@@ -30,7 +30,7 @@ COpenGLTexture::COpenGLTexture(IImage* origImage, const char* name, COpenGLDrive
: ITexture(name), Driver(driver), Image(0), : ITexture(name), Driver(driver), Image(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT), TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
PixelType(GL_UNSIGNED_BYTE), PixelType(GL_UNSIGNED_BYTE),
ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0), Locks(0), ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0),
HasMipMaps(true), IsRenderTarget(false), AutomaticMipmapUpdate(false), UseStencil(false) HasMipMaps(true), IsRenderTarget(false), AutomaticMipmapUpdate(false), UseStencil(false)
{ {
#ifdef _DEBUG #ifdef _DEBUG
...@@ -56,7 +56,7 @@ COpenGLTexture::COpenGLTexture(const core::dimension2d<s32>& size, ...@@ -56,7 +56,7 @@ COpenGLTexture::COpenGLTexture(const core::dimension2d<s32>& size,
: ITexture(name), ImageSize(size), Driver(driver), Image(0), : ITexture(name), ImageSize(size), Driver(driver), Image(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA),
PixelType(GL_UNSIGNED_BYTE), PixelType(GL_UNSIGNED_BYTE),
ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0), Locks(0), ColorFrameBuffer(0), DepthRenderBuffer(0), StencilRenderBuffer(0),
HasMipMaps(false), IsRenderTarget(true), AutomaticMipmapUpdate(false), UseStencil(useStencil) HasMipMaps(false), IsRenderTarget(true), AutomaticMipmapUpdate(false), UseStencil(useStencil)
{ {
#ifdef _DEBUG #ifdef _DEBUG
...@@ -377,25 +377,62 @@ inline s32 COpenGLTexture::getTextureSizeFromSurfaceSize(s32 size) const ...@@ -377,25 +377,62 @@ inline s32 COpenGLTexture::getTextureSizeFromSurfaceSize(s32 size) const
//! lock function //! lock function
void* COpenGLTexture::lock() void* COpenGLTexture::lock()
{ {
if (Image) if (!Image)
Image = new CImage(ECF_A8R8G8B8, ImageSize);
if (IsRenderTarget)
{ {
++Locks; u8* pPixels = static_cast<u8*>(Image->lock());
return Image->lock(); if (!pPixels)
{
return 0;
}
// we need to keep the correct texture bound...
GLint tmpTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &tmpTexture);
glBindTexture(GL_TEXTURE_2D, TextureName);
// allows to read pixels in top-to-bottom order
#ifdef GL_MESA_pack_invert
if (Driver->FeatureAvailable[COpenGLExtensionHandler::IRR_MESA_pack_invert])
glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
#endif
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pPixels);
#ifdef GL_MESA_pack_invert
if (Driver->FeatureAvailable[COpenGLExtensionHandler::IRR_MESA_pack_invert])
glPixelStorei(GL_PACK_INVERT_MESA, GL_FALSE);
else
#endif
{
// opengl images are horizontally flipped, so we have to fix that here.
const s32 pitch=Image->getPitch();
u8* p2 = pPixels + (ImageSize.Height - 1) * pitch;
u8* tmpBuffer = new u8[pitch];
for (s32 i=0; i < ImageSize.Height; i += 2)
{
memcpy(tmpBuffer, pPixels, pitch);
memcpy(pPixels, p2, pitch);
memcpy(p2, tmpBuffer, pitch);
pPixels += pitch;
p2 -= pitch;
}
delete [] tmpBuffer;
}
Image->unlock();
//reset old bound texture
glBindTexture(GL_TEXTURE_2D, tmpTexture);
} }
else return Image->lock();
return 0;
} }
//! unlock function //! unlock function
void COpenGLTexture::unlock() void COpenGLTexture::unlock()
{ {
if (Image) Image->unlock();
{ copyTexture(false);
--Locks;
Image->unlock();
copyTexture(false);
}
} }
......
...@@ -129,8 +129,6 @@ private: ...@@ -129,8 +129,6 @@ private:
GLuint DepthRenderBuffer; // for FBO path GLuint DepthRenderBuffer; // for FBO path
GLuint StencilRenderBuffer; // for FBO path GLuint StencilRenderBuffer; // for FBO path
u32 Locks;
bool HasMipMaps; bool HasMipMaps;
bool IsRenderTarget; bool IsRenderTarget;
bool AutomaticMipmapUpdate; bool AutomaticMipmapUpdate;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment