Commit 2dc10511 authored by hybrid's avatar hybrid

Added a name parameter to render target textures just as for usual textures.

Exposed findTexture in IVideoDriver to check if a texture was already loaded.
Reordered some more OpenGL render state settings in the materials.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@783 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 9fc207d1
......@@ -196,7 +196,7 @@ namespace video
\return Returns a pointer to the created texture or 0 if the texture could not
be created. If you no longer need the image, you should call ITexture::drop().
See IUnknown::drop() for more information. */
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size) = 0;
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name = 0) = 0;
//! Removes a texture from the texture cache and deletes it, freeing lot of memory.
/** Please note that after calling this, the pointer to the ITexture
......@@ -788,6 +788,9 @@ namespace video
//! Returns an image created from the last rendered frame.
virtual IImage* createScreenShot() = 0;
//! looks if the image is already loaded
virtual video::ITexture* findTexture(const c8* filename) = 0;
};
} // end namespace video
......
......@@ -763,9 +763,9 @@ bool CD3D8Driver::setRenderTarget(video::ITexture* texture, bool clearBackBuffer
}
//! Creates a render target texture.
ITexture* CD3D8Driver::createRenderTargetTexture(const core::dimension2d<s32>& size)
ITexture* CD3D8Driver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
return new CD3D8Texture(this, size, 0);
return new CD3D8Texture(this, size, name);
}
......
......@@ -175,7 +175,7 @@ namespace video
virtual IVideoDriver* getVideoDriver();
//! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size);
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
//! Clears the ZBuffer.
virtual void clearZBuffer();
......
......@@ -2045,9 +2045,9 @@ IVideoDriver* CD3D9Driver::getVideoDriver()
//! Creates a render target texture.
ITexture* CD3D9Driver::createRenderTargetTexture(const core::dimension2d<s32>& size)
ITexture* CD3D9Driver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
return new CD3D9Texture(this, size, 0);
return new CD3D9Texture(this, size, name);
}
......
......@@ -169,7 +169,7 @@ namespace video
virtual IVideoDriver* getVideoDriver();
//! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size);
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
//! Clears the ZBuffer.
virtual void clearZBuffer();
......
......@@ -1696,7 +1696,7 @@ s32 CNullDriver::addShaderMaterialFromFiles(const c8* vertexShaderProgramFileNam
}
//! Creates a render target texture.
ITexture* CNullDriver::createRenderTargetTexture(const core::dimension2d<s32>& size)
ITexture* CNullDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
return 0;
}
......
......@@ -248,7 +248,7 @@ namespace video
virtual void removeAllTextures();
//! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size);
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
//! Creates an 1bit alpha channel of the texture based of an color key.
virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor color);
......@@ -398,14 +398,14 @@ namespace video
//! Fills an SMaterial structure from attributes.
virtual void fillMaterialStructureFromAttributes(video::SMaterial& outMaterial, io::IAttributes* attributes);
//! looks if the image is already loaded
virtual video::ITexture* findTexture(const c8* filename);
protected:
//! deletes all textures
void deleteAllTextures();
//! looks if the image is already loaded
video::ITexture* findTexture(const c8* filename);
//! opens the file and loads it into the surface
video::ITexture* loadTextureFromFile(io::IReadFile* file, const c8* hashName = 0);
......
......@@ -550,19 +550,19 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &((S3DVertex2TCoords*)vertices)[0].Pos);
glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &((S3DVertex2TCoords*)vertices)[0].Normal);
// texture coordinates
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &((S3DVertex2TCoords*)vertices)[0].TCoords);
if (MultiTextureExtension)
{
extGlClientActiveTexture(GL_TEXTURE1_ARB);
glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &((S3DVertex2TCoords*)vertices)[0].TCoords2);
extGlClientActiveTexture(GL_TEXTURE0_ARB);
}
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &((S3DVertex2TCoords*)vertices)[0].TCoords);
break;
case EVT_TANGENTS:
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &((S3DVertexTangents*)vertices)[0].Pos);
glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &((S3DVertexTangents*)vertices)[0].Normal);
// texture coordinates
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &((S3DVertexTangents*)vertices)[0].TCoords);
if (MultiTextureExtension)
{
extGlClientActiveTexture(GL_TEXTURE1_ARB);
......@@ -572,10 +572,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
extGlClientActiveTexture(GL_TEXTURE2_ARB);
glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &((S3DVertexTangents*)vertices)[0].Binormal);
extGlClientActiveTexture(GL_TEXTURE0_ARB);
}
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &((S3DVertexTangents*)vertices)[0].TCoords);
break;
}
......@@ -615,9 +612,6 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
glFlush();
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
if (MultiTextureExtension)
{
if (vType==EVT_TANGENTS)
......@@ -625,13 +619,16 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
extGlClientActiveTexture(GL_TEXTURE2_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (vType!=EVT_STANDARD && MultiTextureExtension)
if (vType!=EVT_STANDARD)
{
extGlClientActiveTexture(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
extGlClientActiveTexture(GL_TEXTURE0_ARB);
}
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
......@@ -2068,21 +2065,23 @@ IGPUProgrammingServices* COpenGLDriver::getGPUProgrammingServices()
return this;
}
ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d<s32>& size)
ITexture* COpenGLDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
//disable mip-mapping
bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
video::ITexture* rtt = 0;
if (name==0)
name="rt";
#if defined(GL_EXT_framebuffer_object)
// if driver supports FrameBufferObjects, use them
if (queryFeature(EVDF_FRAMEBUFFER_OBJECT))
rtt = new COpenGLTexture(size, PackedDepthStencilExtension, "rt", this);
rtt = new COpenGLTexture(size, PackedDepthStencilExtension, name, this);
else
#endif
{
rtt = addTexture(size, "rt");
rtt = addTexture(size, name);
if (rtt)
rtt->grab();
}
......
......@@ -96,20 +96,20 @@ namespace video
//! destructor
virtual ~COpenGLDriver();
//! presents the rendered scene on the screen, returns false if failed
virtual bool endScene( s32 windowId, core::rect<s32>* sourceRect=0 );
//! clears the zbuffer
virtual bool beginScene(bool backBuffer, bool zBuffer, SColor color);
//! presents the rendered scene on the screen, returns false if failed
virtual bool endScene( s32 windowId, core::rect<s32>* sourceRect=0 );
//! sets transformation
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
//! draws a vertex primitive list
void drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const u16* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType);
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const u16* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType);
//! queries the features of the driver, returns true if feature is available
bool queryFeature(E_VIDEO_DRIVER_FEATURE feature)
virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature)
{
return COpenGLExtensionHandler::queryFeature(feature);
}
......@@ -222,7 +222,7 @@ namespace video
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state);
//! Can be called by an IMaterialRenderer to make its work easier.
void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderstates);
//! Sets a vertex shader constant.
......@@ -247,17 +247,17 @@ namespace video
//! Adds a new material renderer to the VideoDriver, using extGLGetObjectParameterivARB(shaderHandle, GL_OBJECT_COMPILE_STATUS_ARB, &status) pixel and/or
//! vertex shaders to render geometry.
s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
virtual s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);
//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry.
s32 addHighLevelShaderMaterial(const c8* vertexShaderProgram, const c8* vertexShaderEntryPointName,
virtual s32 addHighLevelShaderMaterial(const c8* vertexShaderProgram, const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget, const c8* pixelShaderProgram, const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget, IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial,
s32 userData);
//! Returns pointer to the IGPUProgrammingServices interface.
IGPUProgrammingServices* getGPUProgrammingServices();
virtual IGPUProgrammingServices* getGPUProgrammingServices();
//! Returns a pointer to the IVideoDriver interface. (Implementation for
//! IMaterialRendererServices)
......@@ -268,9 +268,9 @@ namespace video
//! call.
virtual u32 getMaximalPrimitiveCount();
ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size);
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color);
//! Clears the ZBuffer.
......@@ -301,7 +301,7 @@ namespace video
void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
// returns the current size of the screen or rendertarget
core::dimension2d<s32> getCurrentRenderTargetSize();
virtual core::dimension2d<s32> getCurrentRenderTargetSize();
void createMaterialRenderers();
......
......@@ -46,6 +46,8 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
// thanks to Murphy, the following line removed some
......@@ -54,7 +56,6 @@ public:
glDisable(GL_ALPHA_TEST);
}
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
};
......@@ -72,7 +73,6 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
// if (material.MaterialType != lastMaterial.MaterialType ||
......@@ -165,6 +165,7 @@ public:
Driver->setTexture(1, material.Textures[1]);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
......@@ -195,6 +196,8 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates)
{
glDisable(GL_ALPHA_TEST);
......@@ -203,8 +206,6 @@ public:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND);
}
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
virtual void OnUnsetMaterial()
......@@ -233,6 +234,7 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
......@@ -250,7 +252,6 @@ public:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
glDepthMask(GL_FALSE);
}
......@@ -289,7 +290,6 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
......@@ -343,7 +343,6 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
......@@ -383,7 +382,6 @@ public:
Driver->disableTextures(2);
Driver->setTexture(1, material.Textures[1]);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
......@@ -479,7 +477,6 @@ public:
Driver->disableTextures(2);
Driver->setTexture(1, material.Textures[1]);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
......@@ -524,7 +521,6 @@ public:
{
Driver->disableTextures(1);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
......@@ -573,7 +569,6 @@ public:
Driver->disableTextures(2);
Driver->setTexture(1, material.Textures[1]);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
......@@ -644,7 +639,6 @@ public:
Driver->disableTextures(2);
Driver->setTexture(1, material.Textures[1]);
Driver->setTexture(0, material.Textures[0]);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
......
......@@ -314,7 +314,8 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32
break;
}
if (i == num) return false;
if (i == num)
return false;
#ifdef GL_ARB_shader_objects
switch (UniformInfo[i].type)
......
......@@ -818,10 +818,10 @@ const core::matrix4& CSoftwareDriver::getTransform(E_TRANSFORMATION_STATE state)
}
//! Creates a render target texture.
ITexture* CSoftwareDriver::createRenderTargetTexture(const core::dimension2d<s32>& size)
ITexture* CSoftwareDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
CImage* img = new CImage(video::ECF_A1R5G5B5, size);
ITexture* tex = new CSoftwareTexture(img, 0);
ITexture* tex = new CSoftwareTexture(img, name);
img->drop();
return tex;
}
......
......@@ -82,7 +82,7 @@ namespace video
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state);
//! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size);
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
//! Clears the ZBuffer.
virtual void clearZBuffer();
......
......@@ -1818,11 +1818,11 @@ const core::matrix4& CSoftwareDriver2::getTransform(E_TRANSFORMATION_STATE state
}
//! Creates a render target texture.
ITexture* CSoftwareDriver2::createRenderTargetTexture(const core::dimension2d<s32>& size)
ITexture* CSoftwareDriver2::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
CImage* img = new CImage(ECF_SOFTWARE2, size);
ITexture* tex = new CSoftwareTexture2(img, 0, false);
ITexture* tex = new CSoftwareTexture2(img, name, false);
img->drop();
return tex;
}
......
......@@ -98,7 +98,7 @@ namespace video
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state);
//! Creates a render target texture.
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size);
virtual ITexture* createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name);
//! Clears the DepthBuffer.
virtual void clearZBuffer();
......
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