Commit 909e7ca9 authored by nadro's avatar nadro

- Added support for cubemap lock in OpenGL.

- Enabled cubemaps feature in D3D9.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5281 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 64c70e41
...@@ -651,7 +651,7 @@ bool CD3D9Driver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const ...@@ -651,7 +651,7 @@ bool CD3D9Driver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
case EVDF_TEXTURE_COMPRESSED_DXT: case EVDF_TEXTURE_COMPRESSED_DXT:
return true; return true;
case EVDF_TEXTURE_CUBEMAP: case EVDF_TEXTURE_CUBEMAP:
return false; return true;
default: default:
return false; return false;
}; };
......
...@@ -216,7 +216,16 @@ public: ...@@ -216,7 +216,16 @@ public:
IImage* tmpImage = Driver->createImage(ECF_A8R8G8B8, Size); IImage* tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
#if 0 // This method doesn't work properly in some cases #if 0 // This method doesn't work properly in some cases
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData()); GLenum tmpTextureType = TextureType;
if (tmpTextureType == GL_TEXTURE_CUBE_MAP)
{
_IRR_DEBUG_BREAK_IF(layer > 5)
tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
}
glGetTexImage(tmpTextureType, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
if (IsRenderTarget) if (IsRenderTarget)
{ {
...@@ -257,7 +266,9 @@ public: ...@@ -257,7 +266,9 @@ public:
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmpTexture->getOpenGLTextureName(), 0); Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmpTexture->getOpenGLTextureName(), 0);
Driver->draw2DImage(this, true); glClear(GL_COLOR_BUFFER_BIT);
Driver->draw2DImage(this, layer, true);
glReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData()); glReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
...@@ -487,14 +498,7 @@ protected: ...@@ -487,14 +498,7 @@ protected:
{ {
_IRR_DEBUG_BREAK_IF(layer > 5) _IRR_DEBUG_BREAK_IF(layer > 5)
const GLenum cubeTextureType[6] = tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
tmpTextureType = cubeTextureType[layer];
} }
if (!IImage::isCompressedFormat(ColorFormat)) if (!IImage::isCompressedFormat(ColorFormat))
......
...@@ -1500,7 +1500,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect ...@@ -1500,7 +1500,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect
} }
void COpenGLDriver::draw2DImage(const video::ITexture* texture, bool flip) void COpenGLDriver::draw2DImage(const video::ITexture* texture, u32 layer, bool flip)
{ {
if (!texture || !CacheHandler->getTextureCache().set(0, texture)) if (!texture || !CacheHandler->getTextureCache().set(0, texture))
return; return;
...@@ -1516,22 +1516,92 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, bool flip) ...@@ -1516,22 +1516,92 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, bool flip)
Transformation3DChanged = true; Transformation3DChanged = true;
Quad2DVertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); CacheHandler->setClientState(true, false, false, true);
Quad2DVertices[1].Pos = core::vector3df(1.f, 1.f, 0.f);
Quad2DVertices[2].Pos = core::vector3df(1.f, -1.f, 0.f);
Quad2DVertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f);
f32 modificator = (flip) ? 1.f : 0.f; const core::vector3df positionData[4] = {
core::vector3df(-1.f, 1.f, 0.f),
core::vector3df(1.f, 1.f, 0.f),
core::vector3df(1.f, -1.f, 0.f),
core::vector3df(-1.f, -1.f, 0.f)
};
Quad2DVertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); glVertexPointer(2, GL_FLOAT, sizeof(core::vector3df), positionData);
Quad2DVertices[1].TCoords = core::vector2df(1.f, 0.f + modificator);
Quad2DVertices[2].TCoords = core::vector2df(1.f, 1.f - modificator);
Quad2DVertices[3].TCoords = core::vector2df(0.f, 1.f - modificator);
CacheHandler->setClientState(true, false, false, true); if (texture && texture->getType() == ETT_CUBEMAP)
{
const core::vector3df texcoordCubeData[6][4] = {
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].TCoords); // GL_TEXTURE_CUBE_MAP_POSITIVE_X
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos); {
core::vector3df(1.f, 1.f, 1.f),
core::vector3df(1.f, 1.f, -1.f),
core::vector3df(1.f, -1.f, -1.f),
core::vector3df(1.f, -1.f, 1.f)
},
// GL_TEXTURE_CUBE_MAP_NEGATIVE_X
{
core::vector3df(-1.f, 1.f, -1.f),
core::vector3df(-1.f, 1.f, 1.f),
core::vector3df(-1.f, -1.f, 1.f),
core::vector3df(-1.f, -1.f, -1.f)
},
// GL_TEXTURE_CUBE_MAP_POSITIVE_Y
{
core::vector3df(-1.f, 1.f, -1.f),
core::vector3df(1.f, 1.f, -1.f),
core::vector3df(1.f, 1.f, 1.f),
core::vector3df(-1.f, 1.f, 1.f)
},
// GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
{
core::vector3df(-1.f, -1.f, 1.f),
core::vector3df(-1.f, -1.f, -1.f),
core::vector3df(1.f, -1.f, -1.f),
core::vector3df(1.f, -1.f, 1.f)
},
// GL_TEXTURE_CUBE_MAP_POSITIVE_Z
{
core::vector3df(-1.f, 1.f, 1.f),
core::vector3df(-1.f, -1.f, 1.f),
core::vector3df(1.f, -1.f, 1.f),
core::vector3df(1.f, 1.f, 1.f)
},
// GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
{
core::vector3df(1.f, 1.f, -1.f),
core::vector3df(-1.f, 1.f, -1.f),
core::vector3df(-1.f, -1.f, -1.f),
core::vector3df(1.f, -1.f, -1.f)
}
};
const core::vector3df texcoordData[4] = {
texcoordCubeData[layer][(flip) ? 3 : 0],
texcoordCubeData[layer][(flip) ? 2 : 1],
texcoordCubeData[layer][(flip) ? 1 : 2],
texcoordCubeData[layer][(flip) ? 0 : 3]
};
glTexCoordPointer(3, GL_FLOAT, sizeof(core::vector3df), texcoordData);
}
else
{
f32 modificator = (flip) ? 1.f : 0.f;
core::vector2df texcoordData[4] = {
core::vector2df(0.f, 0.f + modificator),
core::vector2df(1.f, 0.f + modificator),
core::vector2df(1.f, 1.f - modificator),
core::vector2df(0.f, 1.f - modificator)
};
glTexCoordPointer(2, GL_FLOAT, sizeof(core::vector2df), texcoordData);
}
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices); glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, Quad2DIndices);
} }
......
...@@ -144,7 +144,7 @@ namespace video ...@@ -144,7 +144,7 @@ namespace video
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) _IRR_OVERRIDE_; const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false) _IRR_OVERRIDE_;
virtual void draw2DImage(const video::ITexture* texture, bool flip); virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip);
//! draws a set of 2d images, using a color and the alpha channel of the //! draws a set of 2d images, using a color and the alpha channel of the
//! texture if desired. //! texture if desired.
......
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