Commit 2f3ca311 authored by nadro's avatar nadro

- Renamed COpenGLCallBridge to COpenGLCacheHandler and moved this class to dedicated files.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5156 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 172b399f
// Copyright (C) 2015 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "COpenGLCacheHandler.h"
#ifdef _IRR_COMPILE_WITH_OPENGL_
#include "COpenGLDriver.h"
#include "COpenGLTexture.h"
namespace irr
{
namespace video
{
/* COpenGLCacheHandler::STextureCache */
COpenGLCacheHandler::STextureCache::STextureCache(COpenGLCacheHandler* cacheHandler, u32 textureCount) :
CacheHandler(cacheHandler), TextureCount(textureCount)
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
Texture[i] = 0;
}
}
COpenGLCacheHandler::STextureCache::~STextureCache()
{
clear();
}
const COpenGLTexture* COpenGLCacheHandler::STextureCache::operator[](int index) const
{
if (static_cast<u32>(index) < MATERIAL_MAX_TEXTURES)
return Texture[static_cast<u32>(index)];
return 0;
}
bool COpenGLCacheHandler::STextureCache::set(u32 index, const ITexture* texture)
{
bool status = false;
E_DRIVER_TYPE type = EDT_OPENGL;
if (index < MATERIAL_MAX_TEXTURES && index < TextureCount)
{
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB + index);
const COpenGLTexture* prevTexture = Texture[index];
if (texture != prevTexture)
{
if (texture)
{
type = texture->getDriverType();
if (type == EDT_OPENGL)
{
texture->grab();
if (!prevTexture)
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, static_cast<const COpenGLTexture*>(texture)->getOpenGLTextureName());
}
else
{
texture = 0;
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
}
}
if (!texture)
{
glBindTexture(GL_TEXTURE_2D, 0);
if (prevTexture)
glDisable(GL_TEXTURE_2D);
}
Texture[index] = static_cast<const COpenGLTexture*>(texture);
if (prevTexture)
prevTexture->drop();
}
status = true;
}
return (status && type == EDT_OPENGL);
}
void COpenGLCacheHandler::STextureCache::remove(ITexture* texture)
{
if (!texture)
return;
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
if (Texture[i] == texture)
{
Texture[i] = 0;
texture->drop();
}
}
}
void COpenGLCacheHandler::STextureCache::clear()
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
if (Texture[i])
{
const COpenGLTexture* prevTexture = Texture[i];
Texture[i] = 0;
prevTexture->drop();
}
}
}
/* COpenGLCacheHandler */
COpenGLCacheHandler::COpenGLCacheHandler(COpenGLDriver* driver) :
TextureCache(STextureCache(this, driver->MaxSupportedTextures)), Driver(driver), FrameBufferCount(0),
AlphaMode(GL_ALWAYS), AlphaRef(0.f), AlphaTest(false), BlendEquation(0), BlendSourceRGB(0), BlendDestinationRGB(0),
BlendSourceAlpha(0), BlendDestinationAlpha(0), Blend(0), ColorMask(0), CullFaceMode(GL_BACK), CullFace(false),
DepthFunc(GL_LESS), DepthMask(true), DepthTest(false), FrameBufferID(0), MatrixMode(GL_MODELVIEW), ActiveTexture(GL_TEXTURE0_ARB),
ClientActiveTexture(GL_TEXTURE0_ARB), ClientStateVertex(false), ClientStateNormal(false),ClientStateColor(false),
ClientStateTexCoord0(false), ViewportX(0), ViewportY(0)
{
FrameBufferCount = core::max_(static_cast<GLuint>(1), static_cast<GLuint>(Driver->MaxMultipleRenderTargets));
BlendEquation = new GLenum[FrameBufferCount];
BlendSourceRGB = new GLenum[FrameBufferCount];
BlendDestinationRGB = new GLenum[FrameBufferCount];
BlendSourceAlpha = new GLenum[FrameBufferCount];
BlendDestinationAlpha = new GLenum[FrameBufferCount];
Blend = new bool[FrameBufferCount];
ColorMask = new bool[FrameBufferCount][4];
// Initial OpenGL values from specification.
glAlphaFunc(AlphaMode, AlphaRef);
glDisable(GL_ALPHA_TEST);
if (Driver->queryFeature(EVDF_BLEND_OPERATIONS))
{
#if defined(GL_VERSION_1_4)
Driver->extGlBlendEquation(GL_FUNC_ADD);
#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op)
Driver->extGlBlendEquation(GL_FUNC_ADD_EXT);
#endif
}
for (u32 i = 0; i < FrameBufferCount; ++i)
{
#if defined(GL_VERSION_1_4)
BlendEquation[i] = GL_FUNC_ADD;
#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op)
BlendEquation[i] = GL_FUNC_ADD_EXT;
#endif
BlendSourceRGB[i] = GL_ONE;
BlendDestinationRGB[i] = GL_ZERO;
BlendSourceAlpha[i] = GL_ONE;
BlendDestinationAlpha[i] = GL_ZERO;
Blend[i] = false;
for (u32 j = 0; j < 4; ++j)
ColorMask[i][j] = true;
}
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_BLEND);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glCullFace(CullFaceMode);
glDisable(GL_CULL_FACE);
glDepthFunc(DepthFunc);
glDepthMask(GL_TRUE);
glDisable(GL_DEPTH_TEST);
glMatrixMode(MatrixMode);
if (Driver->MultiTextureExtension)
{
Driver->extGlActiveTexture(ActiveTexture);
Driver->extGlClientActiveTexture(ClientActiveTexture);
}
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
const core::dimension2d<u32> ScreenSize = Driver->getScreenSize();
ViewportWidth = ScreenSize.Width;
ViewportHeight = ScreenSize.Height;
glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);
}
COpenGLCacheHandler::~COpenGLCacheHandler()
{
delete[] BlendEquation;
delete[] BlendSourceRGB;
delete[] BlendDestinationRGB;
delete[] BlendSourceAlpha;
delete[] BlendDestinationAlpha;
delete[] Blend;
delete[] ColorMask;
}
void COpenGLCacheHandler::setAlphaFunc(GLenum mode, GLclampf ref)
{
if (AlphaMode != mode || AlphaRef != ref)
{
glAlphaFunc(mode, ref);
AlphaMode = mode;
AlphaRef = ref;
}
}
void COpenGLCacheHandler::setAlphaTest(bool enable)
{
if (AlphaTest != enable)
{
if (enable)
glEnable(GL_ALPHA_TEST);
else
glDisable(GL_ALPHA_TEST);
AlphaTest = enable;
}
}
void COpenGLCacheHandler::setBlendEquation(GLenum mode)
{
if (BlendEquation[0] != mode)
{
Driver->extGlBlendEquation(mode);
for (GLuint i = 0; i < FrameBufferCount; ++i)
BlendEquation[i] = mode;
}
}
void COpenGLCacheHandler::setBlendEquationIndexed(GLuint index, GLenum mode)
{
if (index < FrameBufferCount && BlendEquation[index] != mode)
{
Driver->extGlBlendEquationIndexed(index, mode);
BlendEquation[index] = mode;
}
}
void COpenGLCacheHandler::setBlendFunc(GLenum source, GLenum destination)
{
if (BlendSourceRGB[0] != source || BlendDestinationRGB[0] != destination ||
BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination)
{
glBlendFunc(source, destination);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
BlendSourceRGB[i] = source;
BlendDestinationRGB[i] = destination;
BlendSourceAlpha[i] = source;
BlendDestinationAlpha[i] = destination;
}
}
}
void COpenGLCacheHandler::setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
{
if (BlendSourceRGB[0] != sourceRGB || BlendDestinationRGB[0] != destinationRGB ||
BlendSourceAlpha[0] != sourceAlpha || BlendDestinationAlpha[0] != destinationAlpha)
{
Driver->extGlBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
BlendSourceRGB[i] = sourceRGB;
BlendDestinationRGB[i] = destinationRGB;
BlendSourceAlpha[i] = sourceAlpha;
BlendDestinationAlpha[i] = destinationAlpha;
}
}
}
else
{
setBlendFunc(sourceRGB, destinationRGB);
}
}
void COpenGLCacheHandler::setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination)
{
if (index < FrameBufferCount && (BlendSourceRGB[index] != source || BlendDestinationRGB[index] != destination ||
BlendSourceAlpha[index] != source || BlendDestinationAlpha[index] != destination))
{
Driver->extGlBlendFuncIndexed(index, source, destination);
BlendSourceRGB[index] = source;
BlendDestinationRGB[index] = destination;
BlendSourceAlpha[index] = source;
BlendDestinationAlpha[index] = destination;
}
}
void COpenGLCacheHandler::setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
{
if (index < FrameBufferCount && (BlendSourceRGB[index] != sourceRGB || BlendDestinationRGB[index] != destinationRGB ||
BlendSourceAlpha[index] != sourceAlpha || BlendDestinationAlpha[index] != destinationAlpha))
{
Driver->extGlBlendFuncSeparateIndexed(index, sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
BlendSourceRGB[index] = sourceRGB;
BlendDestinationRGB[index] = destinationRGB;
BlendSourceAlpha[index] = sourceAlpha;
BlendDestinationAlpha[index] = destinationAlpha;
}
}
else
{
setBlendFuncIndexed(index, sourceRGB, destinationRGB);
}
}
void COpenGLCacheHandler::setBlend(bool enable)
{
if (Blend[0] != enable)
{
if (enable)
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
for (GLuint i = 0; i < FrameBufferCount; ++i)
Blend[i] = enable;
}
}
void COpenGLCacheHandler::setBlendIndexed(GLuint index, bool enable)
{
if (index < FrameBufferCount && Blend[index] != enable)
{
if (enable)
Driver->extGlEnableIndexed(GL_BLEND, index);
else
Driver->extGlDisableIndexed(GL_BLEND, index);
Blend[index] = enable;
}
}
void COpenGLCacheHandler::setColorMask(bool red, bool green, bool blue, bool alpha)
{
if (ColorMask[0][0] != red || ColorMask[0][1] != green || ColorMask[0][2] != blue || ColorMask[0][3] != alpha)
{
glColorMask(red, green, blue, alpha);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
ColorMask[i][0] = red;
ColorMask[i][1] = green;
ColorMask[i][2] = blue;
ColorMask[i][3] = alpha;
}
}
}
void COpenGLCacheHandler::setColorMaskIndexed(GLuint index, bool red, bool green, bool blue, bool alpha)
{
if (index < FrameBufferCount && (ColorMask[index][0] != red || ColorMask[index][1] != green || ColorMask[index][2] != blue || ColorMask[index][3] != alpha))
{
Driver->extGlColorMaskIndexed(index, red, green, blue, alpha);
ColorMask[index][0] = red;
ColorMask[index][1] = green;
ColorMask[index][2] = blue;
ColorMask[index][3] = alpha;
}
}
void COpenGLCacheHandler::setClientState(bool vertex, bool normal, bool color, bool texCoord0)
{
if (ClientStateVertex != vertex)
{
if (vertex)
glEnableClientState(GL_VERTEX_ARRAY);
else
glDisableClientState(GL_VERTEX_ARRAY);
ClientStateVertex = vertex;
}
if (ClientStateNormal != normal)
{
if (normal)
glEnableClientState(GL_NORMAL_ARRAY);
else
glDisableClientState(GL_NORMAL_ARRAY);
ClientStateNormal = normal;
}
if (ClientStateColor != color)
{
if (color)
glEnableClientState(GL_COLOR_ARRAY);
else
glDisableClientState(GL_COLOR_ARRAY);
ClientStateColor = color;
}
if (ClientStateTexCoord0 != texCoord0)
{
setClientActiveTexture(GL_TEXTURE0_ARB);
if (texCoord0)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
ClientStateTexCoord0 = texCoord0;
}
}
void COpenGLCacheHandler::setCullFaceFunc(GLenum mode)
{
if (CullFaceMode != mode)
{
glCullFace(mode);
CullFaceMode = mode;
}
}
void COpenGLCacheHandler::setCullFace(bool enable)
{
if (CullFace != enable)
{
if (enable)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
CullFace = enable;
}
}
void COpenGLCacheHandler::setDepthFunc(GLenum mode)
{
if (DepthFunc != mode)
{
glDepthFunc(mode);
DepthFunc = mode;
}
}
void COpenGLCacheHandler::setDepthMask(bool enable)
{
if (DepthMask != enable)
{
if (enable)
glDepthMask(GL_TRUE);
else
glDepthMask(GL_FALSE);
DepthMask = enable;
}
}
void COpenGLCacheHandler::setDepthTest(bool enable)
{
if (DepthTest != enable)
{
if (enable)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);
DepthTest = enable;
}
}
void COpenGLCacheHandler::getFBO(GLuint& id) const
{
id = FrameBufferID;
}
void COpenGLCacheHandler::setFBO(GLuint id)
{
if (FrameBufferID != id)
{
#if defined(GL_EXT_framebuffer_object)
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_EXT, id);
#endif
FrameBufferID = id;
}
}
void COpenGLCacheHandler::setMatrixMode(GLenum mode)
{
if (MatrixMode != mode)
{
glMatrixMode(mode);
MatrixMode = mode;
}
}
void COpenGLCacheHandler::setActiveTexture(GLenum texture)
{
if (Driver->MultiTextureExtension && ActiveTexture != texture)
{
Driver->extGlActiveTexture(texture);
ActiveTexture = texture;
}
}
void COpenGLCacheHandler::setClientActiveTexture(GLenum texture)
{
if (Driver->MultiTextureExtension && ClientActiveTexture != texture)
{
Driver->extGlClientActiveTexture(texture);
ClientActiveTexture = texture;
}
}
void COpenGLCacheHandler::setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight)
{
if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight)
{
glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
ViewportX = viewportX;
ViewportY = viewportY;
ViewportWidth = viewportWidth;
ViewportHeight = viewportHeight;
}
}
} // end namespace
} // end namespace
#endif // _IRR_COMPILE_WITH_OPENGL_
// Copyright (C) 2015 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OPEN_GL_CACHE_HANDLER_H_INCLUDED__
#define __C_OPEN_GL_CACHE_HANDLER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OPENGL_
#include "COpenGLExtensionHandler.h"
#include "SMaterial.h"
namespace irr
{
namespace video
{
class COpenGLDriver;
class COpenGLTexture;
class COpenGLCacheHandler
{
class STextureCache
{
public:
STextureCache();
STextureCache(COpenGLCacheHandler* cacheHandler, u32 textureCount);
~STextureCache();
const COpenGLTexture* operator[](int index) const;
bool set(u32 index, const ITexture* texture);
void remove(ITexture* texture);
void clear();
private:
COpenGLCacheHandler* CacheHandler;
const COpenGLTexture* Texture[MATERIAL_MAX_TEXTURES];
u32 TextureCount;
};
public:
COpenGLCacheHandler(COpenGLDriver* driver);
~COpenGLCacheHandler();
void reset();
// Alpha calls.
void setAlphaFunc(GLenum mode, GLclampf ref);
void setAlphaTest(bool enable);
// Blending calls.
void setBlendEquation(GLenum mode);
void setBlendEquationIndexed(GLuint index, GLenum mode);
void setBlendFunc(GLenum source, GLenum destination);
void setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha);
void setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination);
void setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha);
void setBlend(bool enable);
void setBlendIndexed(GLuint index, bool enable);
// Client state calls.
void setClientState(bool vertex, bool normal, bool color, bool texCoord0);
// Color Mask.
void setColorMask(bool red, bool green, bool blue, bool alpha);
void setColorMaskIndexed(GLuint index, bool red, bool green, bool blue, bool alpha);
// Cull face calls.
void setCullFaceFunc(GLenum mode);
void setCullFace(bool enable);
// Depth calls.
void setDepthFunc(GLenum mode);
void setDepthMask(bool enable);
void setDepthTest(bool enable);
// FBO calls.
void getFBO(GLuint& id) const;
void setFBO(GLuint id);
// Matrix calls.
void setMatrixMode(GLenum mode);
// Texture calls.
void setActiveTexture(GLenum texture);
void setClientActiveTexture(GLenum texture);
// Viewport calls.
void setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight);
// Texture cache.
STextureCache TextureCache;
private:
COpenGLDriver* Driver;
GLuint FrameBufferCount;
GLenum AlphaMode;
GLclampf AlphaRef;
bool AlphaTest;
GLenum* BlendEquation;
GLenum* BlendSourceRGB;
GLenum* BlendDestinationRGB;
GLenum* BlendSourceAlpha;
GLenum* BlendDestinationAlpha;
bool* Blend;
bool (*ColorMask)[4];
GLenum CullFaceMode;
bool CullFace;
GLenum DepthFunc;
bool DepthMask;
bool DepthTest;
GLuint FrameBufferID;
GLenum MatrixMode;
GLenum ActiveTexture;
GLenum ClientActiveTexture;
bool ClientStateVertex;
bool ClientStateNormal;
bool ClientStateColor;
bool ClientStateTexCoord0;
GLint ViewportX;
GLint ViewportY;
GLsizei ViewportWidth;
GLsizei ViewportHeight;
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OPENGL_
#endif
......@@ -8,6 +8,7 @@
#ifdef _IRR_COMPILE_WITH_OPENGL_
#include "COpenGLCacheHandler.h"
#include "COpenGLTexture.h"
#include "COpenGLRenderTarget.h"
#include "COpenGLMaterialRenderer.h"
......@@ -47,7 +48,7 @@ const u16 COpenGLDriver::Quad2DIndices[4] = { 0, 1, 2, 3 };
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
//! Windows constructor and init code
COpenGLDriver::COpenGLDriver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device)
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), BridgeCalls(0),
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
Params(params), HDc(0), Window(static_cast<HWND>(params.WindowId)), Win32Device(device),
......@@ -477,7 +478,7 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device)
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
//! Windows constructor and init code
COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceMacOSX *device)
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), BridgeCalls(0),
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
Params(params), OSXDevice(device), DeviceType(EIDT_OSX)
......@@ -497,7 +498,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFil
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
//! Linux constructor and init code
COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device)
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), BridgeCalls(0),
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
Params(params), X11Device(device), DeviceType(EIDT_X11)
......@@ -583,7 +584,7 @@ bool COpenGLDriver::initDriver(CIrrDeviceLinux* device)
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
//! SDL constructor and init code
COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device)
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), BridgeCalls(0),
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
Params(params), SDLDevice(device), DeviceType(EIDT_SDL)
......@@ -605,7 +606,7 @@ COpenGLDriver::~COpenGLDriver()
deleteMaterialRenders();
BridgeCalls->TextureCache.clear();
CacheHandler->TextureCache.clear();
// I get a blue screen on my laptop, when I do not delete the
// textures manually before releasing the dc. Oh how I love this.
removeAllRenderTargets();
......@@ -613,7 +614,7 @@ COpenGLDriver::~COpenGLDriver()
removeAllOcclusionQueries();
removeAllHardwareBuffers();
delete BridgeCalls;
delete CacheHandler;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
if (DeviceType == EIDT_WIN32)
......@@ -661,8 +662,9 @@ bool COpenGLDriver::genericDriverInit()
// load extensions
initExtensions(Params.Stencilbuffer);
delete BridgeCalls;
BridgeCalls = new COpenGLCallBridge(this);
// reset cache handler
delete CacheHandler;
CacheHandler = new COpenGLCacheHandler(this);
if (queryFeature(EVDF_ARB_GLSL))
{
......@@ -898,7 +900,7 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
case ETS_WORLD:
{
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
BridgeCalls->setMatrixMode(GL_MODELVIEW);
CacheHandler->setMatrixMode(GL_MODELVIEW);
// first load the viewing transformation for user clip planes
glLoadMatrixf((Matrices[ETS_VIEW]).pointer());
......@@ -914,7 +916,7 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
break;
case ETS_PROJECTION:
{
BridgeCalls->setMatrixMode(GL_PROJECTION);
CacheHandler->setMatrixMode(GL_PROJECTION);
glLoadMatrixf(mat.pointer());
}
break;
......@@ -1387,9 +1389,9 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
setRenderStates3DMode();
if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES))
BridgeCalls->setClientState(true, true, true, true);
CacheHandler->setClientState(true, true, true, true);
else
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
//due to missing defines in OSX headers, we have to be more specific with this check
//#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
......@@ -1440,9 +1442,9 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0);
}
if (MultiTextureExtension && BridgeCalls->TextureCache[1])
if (MultiTextureExtension && CacheHandler->TextureCache[1])
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
......@@ -1468,7 +1470,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
if (MultiTextureExtension)
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].TCoords2);
......@@ -1493,14 +1495,14 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
if (MultiTextureExtension)
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Tangent);
else
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36));
BridgeCalls->setClientActiveTexture(GL_TEXTURE2_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE2_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Binormal);
......@@ -1516,15 +1518,15 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
{
if (vType==EVT_TANGENTS)
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE2_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE2_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if ((vType!=EVT_STANDARD) || BridgeCalls->TextureCache[1])
if ((vType!=EVT_STANDARD) || CacheHandler->TextureCache[1])
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
BridgeCalls->setClientActiveTexture(GL_TEXTURE0_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE0_ARB);
}
}
......@@ -1695,7 +1697,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
getColorBuffer(vertices, vertexCount, vType);
// draw everything
BridgeCalls->TextureCache.set(0, Material.getTexture(0));
CacheHandler->TextureCache.set(0, Material.getTexture(0));
if (Material.MaterialType==EMT_ONETEXTURE_BLEND)
{
E_BLEND_FACTOR srcFact;
......@@ -1709,9 +1711,9 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
setRenderStates2DMode(Material.MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA, (Material.getTexture(0) != 0), Material.MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL);
if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES))
BridgeCalls->setClientState(true, false, true, true);
CacheHandler->setClientState(true, false, true, true);
else
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
//due to missing defines in OSX headers, we have to be more specific with this check
//#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
......@@ -1760,9 +1762,9 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), 0);
}
if (MultiTextureExtension && BridgeCalls->TextureCache[1])
if (MultiTextureExtension && CacheHandler->TextureCache[1])
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);
......@@ -1785,7 +1787,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
if (MultiTextureExtension)
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].TCoords2);
......@@ -1813,12 +1815,12 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
if (MultiTextureExtension)
{
if ((vType!=EVT_STANDARD) || BridgeCalls->TextureCache[1])
if ((vType!=EVT_STANDARD) || CacheHandler->TextureCache[1])
{
BridgeCalls->setClientActiveTexture(GL_TEXTURE1_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
BridgeCalls->setClientActiveTexture(GL_TEXTURE0_ARB);
CacheHandler->setClientActiveTexture(GL_TEXTURE0_ARB);
}
}
......@@ -1843,7 +1845,7 @@ void COpenGLDriver::draw2DImageBatch(const video::ITexture* texture,
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
disableTextures(1);
if (!BridgeCalls->TextureCache.set(0, texture))
if (!CacheHandler->TextureCache.set(0, texture))
return;
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
......@@ -1855,7 +1857,7 @@ void COpenGLDriver::draw2DImageBatch(const video::ITexture* texture,
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, true);
CacheHandler->setClientState(true, false, true, true);
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].TCoords);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2090,7 +2092,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
const core::rect<s32> poss(targetPos, sourceSize);
disableTextures(1);
if (!BridgeCalls->TextureCache.set(0, texture))
if (!CacheHandler->TextureCache.set(0, texture))
return;
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
......@@ -2112,7 +2114,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture,
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, true);
CacheHandler->setClientState(true, false, true, true);
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].TCoords);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2162,7 +2164,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect
const video::SColor* const useColor = colors ? colors : temp;
disableTextures(1);
if (!BridgeCalls->TextureCache.set(0, texture))
if (!CacheHandler->TextureCache.set(0, texture))
return;
setRenderStates2DMode(useColor[0].getAlpha()<255 || useColor[1].getAlpha()<255 ||
useColor[2].getAlpha()<255 || useColor[3].getAlpha()<255,
......@@ -2197,7 +2199,7 @@ void COpenGLDriver::draw2DImage(const video::ITexture* texture, const core::rect
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, true);
CacheHandler->setClientState(true, false, true, true);
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].TCoords);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2239,7 +2241,7 @@ void COpenGLDriver::draw2DImageBatch(const video::ITexture* texture,
return;
disableTextures(1);
if (!BridgeCalls->TextureCache.set(0, texture))
if (!CacheHandler->TextureCache.set(0, texture))
return;
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
......@@ -2267,7 +2269,7 @@ void COpenGLDriver::draw2DImageBatch(const video::ITexture* texture,
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, true);
CacheHandler->setClientState(true, false, true, true);
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].TCoords);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2373,7 +2375,7 @@ void COpenGLDriver::draw2DRectangle(const core::rect<s32>& position,
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2414,7 +2416,7 @@ void COpenGLDriver::draw2DLine(const core::position2d<s32>& start,
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 2, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2452,7 +2454,7 @@ void COpenGLDriver::drawPixel(u32 x, u32 y, const SColor &color)
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 1, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -2479,7 +2481,7 @@ bool COpenGLDriver::disableTextures(u32 fromStage)
bool result=true;
for (u32 i=fromStage; i<MaxSupportedTextures; ++i)
{
result &= BridgeCalls->TextureCache.set(i, 0);
result &= CacheHandler->TextureCache.set(i, 0);
}
return result;
}
......@@ -2532,7 +2534,7 @@ void COpenGLDriver::setMaterial(const SMaterial& material)
for (u32 i = 0; i < MaxTextureUnits; ++i)
{
BridgeCalls->TextureCache.set(i, material.getTexture(i));
CacheHandler->TextureCache.set(i, material.getTexture(i));
setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i));
}
}
......@@ -2580,15 +2582,15 @@ void COpenGLDriver::setRenderStates3DMode()
if (CurrentRenderMode != ERM_3D)
{
// Reset Texture Stages
BridgeCalls->setBlend(false);
BridgeCalls->setAlphaTest(false);
BridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
CacheHandler->setBlend(false);
CacheHandler->setAlphaTest(false);
CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// switch back the matrices
BridgeCalls->setMatrixMode(GL_MODELVIEW);
CacheHandler->setMatrixMode(GL_MODELVIEW);
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
BridgeCalls->setMatrixMode(GL_PROJECTION);
CacheHandler->setMatrixMode(GL_PROJECTION);
glLoadMatrixf(Matrices[ETS_PROJECTION].pointer());
ResetRenderStates = true;
......@@ -2896,39 +2898,39 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
switch (material.ZBuffer)
{
case ECFN_DISABLED:
BridgeCalls->setDepthTest(false);
CacheHandler->setDepthTest(false);
break;
case ECFN_LESSEQUAL:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_LEQUAL);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_LEQUAL);
break;
case ECFN_EQUAL:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_EQUAL);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_EQUAL);
break;
case ECFN_LESS:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_LESS);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_LESS);
break;
case ECFN_NOTEQUAL:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_NOTEQUAL);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_NOTEQUAL);
break;
case ECFN_GREATEREQUAL:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_GEQUAL);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_GEQUAL);
break;
case ECFN_GREATER:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_GREATER);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_GREATER);
break;
case ECFN_ALWAYS:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_ALWAYS);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_ALWAYS);
break;
case ECFN_NEVER:
BridgeCalls->setDepthTest(true);
BridgeCalls->setDepthFunc(GL_NEVER);
CacheHandler->setDepthTest(true);
CacheHandler->setDepthFunc(GL_NEVER);
break;
default:
break;
......@@ -2937,36 +2939,36 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
// ZWrite
if (getWriteZBuffer(material))
{
BridgeCalls->setDepthMask(true);
CacheHandler->setDepthMask(true);
}
else
{
BridgeCalls->setDepthMask(false);
CacheHandler->setDepthMask(false);
}
// Back face culling
if ((material.FrontfaceCulling) && (material.BackfaceCulling))
{
BridgeCalls->setCullFaceFunc(GL_FRONT_AND_BACK);
BridgeCalls->setCullFace(true);
CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK);
CacheHandler->setCullFace(true);
}
else if (material.BackfaceCulling)
{
BridgeCalls->setCullFaceFunc(GL_BACK);
BridgeCalls->setCullFace(true);
CacheHandler->setCullFaceFunc(GL_BACK);
CacheHandler->setCullFace(true);
}
else if (material.FrontfaceCulling)
{
BridgeCalls->setCullFaceFunc(GL_FRONT);
BridgeCalls->setCullFace(true);
CacheHandler->setCullFaceFunc(GL_FRONT);
CacheHandler->setCullFace(true);
}
else
{
BridgeCalls->setCullFace(false);
CacheHandler->setCullFace(false);
}
// Color Mask
BridgeCalls->setColorMask(
CacheHandler->setColorMask(
(material.ColorMask & ECP_RED)?GL_TRUE:GL_FALSE,
(material.ColorMask & ECP_GREEN)?GL_TRUE:GL_FALSE,
(material.ColorMask & ECP_BLUE)?GL_TRUE:GL_FALSE,
......@@ -2974,10 +2976,10 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
// Blend Equation
if (material.BlendOperation == EBO_NONE)
BridgeCalls->setBlend(false);
CacheHandler->setBlend(false);
else
{
BridgeCalls->setBlend(true);
CacheHandler->setBlend(true);
#if defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op) || defined(GL_VERSION_1_4)
if (queryFeature(EVDF_BLEND_OPERATIONS))
......@@ -2986,83 +2988,83 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
{
case EBO_SUBTRACT:
#if defined(GL_VERSION_1_4)
BridgeCalls->setBlendEquation(GL_FUNC_SUBTRACT);
CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT);
#elif defined(GL_EXT_blend_subtract)
BridgeCalls->setBlendEquation(GL_FUNC_SUBTRACT_EXT);
CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT_EXT);
#endif
break;
case EBO_REVSUBTRACT:
#if defined(GL_VERSION_1_4)
BridgeCalls->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
#elif defined(GL_EXT_blend_subtract)
BridgeCalls->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_EXT);
CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_EXT);
#endif
break;
case EBO_MIN:
#if defined(GL_VERSION_1_4)
BridgeCalls->setBlendEquation(GL_MIN);
CacheHandler->setBlendEquation(GL_MIN);
#elif defined(GL_EXT_blend_minmax)
BridgeCalls->setBlendEquation(GL_MIN_EXT);
CacheHandler->setBlendEquation(GL_MIN_EXT);
#endif
break;
case EBO_MAX:
#if defined(GL_VERSION_1_4)
BridgeCalls->setBlendEquation(GL_MAX);
CacheHandler->setBlendEquation(GL_MAX);
#elif defined(GL_EXT_blend_minmax)
BridgeCalls->setBlendEquation(GL_MAX_EXT);
CacheHandler->setBlendEquation(GL_MAX_EXT);
#endif
break;
case EBO_MIN_FACTOR:
#if defined(GL_AMD_blend_minmax_factor)
if (FeatureAvailable[IRR_AMD_blend_minmax_factor])
BridgeCalls->setBlendEquation(GL_FACTOR_MIN_AMD);
CacheHandler->setBlendEquation(GL_FACTOR_MIN_AMD);
#endif
// fallback in case of missing extension
#if defined(GL_VERSION_1_4)
#if defined(GL_AMD_blend_minmax_factor)
else
#endif
BridgeCalls->setBlendEquation(GL_MIN);
CacheHandler->setBlendEquation(GL_MIN);
#endif
break;
case EBO_MAX_FACTOR:
#if defined(GL_AMD_blend_minmax_factor)
if (FeatureAvailable[IRR_AMD_blend_minmax_factor])
BridgeCalls->setBlendEquation(GL_FACTOR_MAX_AMD);
CacheHandler->setBlendEquation(GL_FACTOR_MAX_AMD);
#endif
// fallback in case of missing extension
#if defined(GL_VERSION_1_4)
#if defined(GL_AMD_blend_minmax_factor)
else
#endif
BridgeCalls->setBlendEquation(GL_MAX);
CacheHandler->setBlendEquation(GL_MAX);
#endif
break;
case EBO_MIN_ALPHA:
#if defined(GL_SGIX_blend_alpha_minmax)
if (FeatureAvailable[IRR_SGIX_blend_alpha_minmax])
BridgeCalls->setBlendEquation(GL_ALPHA_MIN_SGIX);
CacheHandler->setBlendEquation(GL_ALPHA_MIN_SGIX);
// fallback in case of missing extension
else
if (FeatureAvailable[IRR_EXT_blend_minmax])
BridgeCalls->setBlendEquation(GL_MIN_EXT);
CacheHandler->setBlendEquation(GL_MIN_EXT);
#endif
break;
case EBO_MAX_ALPHA:
#if defined(GL_SGIX_blend_alpha_minmax)
if (FeatureAvailable[IRR_SGIX_blend_alpha_minmax])
BridgeCalls->setBlendEquation(GL_ALPHA_MAX_SGIX);
CacheHandler->setBlendEquation(GL_ALPHA_MAX_SGIX);
// fallback in case of missing extension
else
if (FeatureAvailable[IRR_EXT_blend_minmax])
BridgeCalls->setBlendEquation(GL_MAX_EXT);
CacheHandler->setBlendEquation(GL_MAX_EXT);
#endif
break;
default:
#if defined(GL_VERSION_1_4)
BridgeCalls->setBlendEquation(GL_FUNC_ADD);
CacheHandler->setBlendEquation(GL_FUNC_ADD);
#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op)
BridgeCalls->setBlendEquation(GL_FUNC_ADD_EXT);
CacheHandler->setBlendEquation(GL_FUNC_ADD_EXT);
#endif
break;
}
......@@ -3084,12 +3086,12 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
if (queryFeature(EVDF_BLEND_SEPARATE))
{
BridgeCalls->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact),
CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact),
getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact));
}
else
{
BridgeCalls->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact));
CacheHandler->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact));
}
}
......@@ -3194,18 +3196,18 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
fixedPipeline = true;
}
const COpenGLTexture* tmpTexture = BridgeCalls->TextureCache[i];
const COpenGLTexture* tmpTexture = CacheHandler->TextureCache[i];
if (!tmpTexture)
continue;
BridgeCalls->setActiveTexture(GL_TEXTURE0_ARB + i);
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB + i);
if (fixedPipeline)
{
const bool isRTT = tmpTexture->isRenderTarget();
BridgeCalls->setMatrixMode(GL_TEXTURE);
CacheHandler->setMatrixMode(GL_TEXTURE);
if (!isRTT && Matrices[ETS_TEXTURE_0 + i].isIdentity())
glLoadIdentity();
......@@ -3328,7 +3330,7 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset
}
// be sure to leave in texture stage 0
BridgeCalls->setActiveTexture(GL_TEXTURE0_ARB);
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB);
}
......@@ -3360,7 +3362,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
}
if (Transformation3DChanged)
{
BridgeCalls->setMatrixMode(GL_PROJECTION);
CacheHandler->setMatrixMode(GL_PROJECTION);
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
core::matrix4 m(core::matrix4::EM4CONST_NOTHING);
......@@ -3368,12 +3370,12 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
m.setTranslation(core::vector3df(-1,1,0));
glLoadMatrixf(m.pointer());
BridgeCalls->setMatrixMode(GL_MODELVIEW);
CacheHandler->setMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375f, 0.375f, 0.0f);
// Make sure we set first texture matrix
BridgeCalls->setActiveTexture(GL_TEXTURE0_ARB);
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB);
Transformation3DChanged = false;
}
......@@ -3382,7 +3384,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
setBasicRenderStates(InitMaterial2D, LastMaterial, true);
LastMaterial = InitMaterial2D;
}
BridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#ifdef GL_EXT_clip_volume_hint
if (FeatureAvailable[IRR_EXT_clip_volume_hint])
glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_FASTEST);
......@@ -3401,14 +3403,14 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
if (alphaChannel || alpha)
{
BridgeCalls->setBlend(true);
BridgeCalls->setAlphaTest(true);
BridgeCalls->setAlphaFunc(GL_GREATER, 0.f);
CacheHandler->setBlend(true);
CacheHandler->setAlphaTest(true);
CacheHandler->setAlphaFunc(GL_GREATER, 0.f);
}
else
{
BridgeCalls->setBlend(false);
BridgeCalls->setAlphaTest(false);
CacheHandler->setBlend(false);
CacheHandler->setAlphaTest(false);
}
if (texture)
......@@ -3418,7 +3420,7 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
else
setTextureRenderStates(InitMaterial2D, false);
Material.setTexture(0, const_cast<COpenGLTexture*>(BridgeCalls->TextureCache[0]));
Material.setTexture(0, const_cast<COpenGLTexture*>(CacheHandler->TextureCache[0]));
setTransform(ETS_TEXTURE_0, core::IdentityMatrix);
// Due to the transformation change, the previous line would call a reset each frame
// but we can safely reset the variable as it was false before
......@@ -3696,7 +3698,7 @@ void COpenGLDriver::setViewPort(const core::rect<s32>& area)
vp.clipAgainst(rendert);
if (vp.getHeight() > 0 && vp.getWidth() > 0)
BridgeCalls->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight());
CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight());
ViewPort = vp;
}
......@@ -3737,7 +3739,7 @@ void COpenGLDriver::drawStencilShadowVolume(const core::array<core::vector3df>&
glEnable(GL_STENCIL_TEST);
}
BridgeCalls->setClientState(true, false, false, false);
CacheHandler->setClientState(true, false, false, false);
glVertexPointer(3,GL_FLOAT,sizeof(core::vector3df),triangles.const_pointer());
glStencilMask(~0);
glStencilFunc(GL_ALWAYS, 0, ~0);
......@@ -3870,10 +3872,10 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// draw a shadow rectangle covering the entire screen using stencil buffer
BridgeCalls->setMatrixMode(GL_MODELVIEW);
CacheHandler->setMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
BridgeCalls->setMatrixMode(GL_PROJECTION);
CacheHandler->setMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
......@@ -3890,7 +3892,7 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 4, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -3914,7 +3916,7 @@ void COpenGLDriver::drawStencilShadow(bool clearStencilBuffer, video::SColor lef
// restore settings
glPopMatrix();
BridgeCalls->setMatrixMode(GL_MODELVIEW);
CacheHandler->setMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}
......@@ -3976,7 +3978,7 @@ void COpenGLDriver::draw3DLine(const core::vector3df& start,
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
getColorBuffer(Quad2DVertices, 2, EVT_STANDARD);
BridgeCalls->setClientState(true, false, true, false);
CacheHandler->setClientState(true, false, true, false);
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(Quad2DVertices))[0].Pos);
......@@ -4012,7 +4014,7 @@ void COpenGLDriver::removeTexture(ITexture* texture)
void COpenGLDriver::OnResize(const core::dimension2d<u32>& size)
{
CNullDriver::OnResize(size);
BridgeCalls->setViewport(0, 0, size.Width, size.Height);
CacheHandler->setViewport(0, 0, size.Width, size.Height);
Transformation3DChanged = true;
}
......@@ -4211,18 +4213,18 @@ bool COpenGLDriver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor
if (supportForFBO)
{
BridgeCalls->setFBO(renderTarget->getBufferID());
CacheHandler->setFBO(renderTarget->getBufferID());
renderTarget->update();
}
destRenderTargetSize = renderTarget->getSize();
BridgeCalls->setViewport(0, 0, destRenderTargetSize.Width, destRenderTargetSize.Height);
CacheHandler->setViewport(0, 0, destRenderTargetSize.Width, destRenderTargetSize.Height);
}
else
{
if (supportForFBO)
BridgeCalls->setFBO(0);
CacheHandler->setFBO(0);
else
{
COpenGLRenderTarget* prevRenderTarget = static_cast<COpenGLRenderTarget*>(CurrentRenderTarget);
......@@ -4230,20 +4232,20 @@ bool COpenGLDriver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor
if (renderTargetTexture)
{
const COpenGLTexture* prevTexture = BridgeCalls->TextureCache[0];
const COpenGLTexture* prevTexture = CacheHandler->TextureCache[0];
BridgeCalls->TextureCache.set(0, renderTargetTexture);
CacheHandler->TextureCache.set(0, renderTargetTexture);
const core::dimension2d<u32> size = renderTargetTexture->getSize();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.Width, size.Height);
BridgeCalls->TextureCache.set(0, prevTexture);
CacheHandler->TextureCache.set(0, prevTexture);
}
}
destRenderTargetSize = core::dimension2d<u32>(0, 0);
BridgeCalls->setViewport(0, 0, ScreenSize.Width, ScreenSize.Height);
CacheHandler->setViewport(0, 0, ScreenSize.Width, ScreenSize.Height);
}
if (CurrentRenderTargetSize != destRenderTargetSize)
......@@ -4282,7 +4284,7 @@ void COpenGLDriver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil)
if (flag & ECBF_COLOR)
{
BridgeCalls->setColorMask(true, true, true, true);
CacheHandler->setColorMask(true, true, true, true);
const f32 inv = 1.0f / 255.0f;
glClearColor(color.getRed() * inv, color.getGreen() * inv,
......@@ -4293,7 +4295,7 @@ void COpenGLDriver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil)
if (flag & ECBF_DEPTH)
{
BridgeCalls->setDepthMask(true);
CacheHandler->setDepthMask(true);
glClearDepth(depth);
mask |= GL_DEPTH_BUFFER_BIT;
}
......@@ -4610,547 +4612,9 @@ const SMaterial& COpenGLDriver::getCurrentMaterial() const
return Material;
}
COpenGLCallBridge* COpenGLDriver::getBridgeCalls() const
COpenGLCacheHandler* COpenGLDriver::getCacheHandler() const
{
return BridgeCalls;
}
/* COpenGLCallBridge::STextureCache */
COpenGLCallBridge::STextureCache::STextureCache(COpenGLCallBridge* cacheHandler, u32 textureCount) :
CacheHandler(cacheHandler), TextureCount(textureCount)
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
Texture[i] = 0;
}
}
COpenGLCallBridge::STextureCache::~STextureCache()
{
clear();
}
const COpenGLTexture* COpenGLCallBridge::STextureCache::operator[](int index) const
{
if (static_cast<u32>(index) < MATERIAL_MAX_TEXTURES)
return Texture[static_cast<u32>(index)];
return 0;
}
bool COpenGLCallBridge::STextureCache::set(u32 index, const ITexture* texture)
{
bool status = false;
E_DRIVER_TYPE type = EDT_OPENGL;
if (index < MATERIAL_MAX_TEXTURES && index < TextureCount)
{
CacheHandler->setActiveTexture(GL_TEXTURE0_ARB + index);
const COpenGLTexture* prevTexture = Texture[index];
if (texture != prevTexture)
{
if (texture)
{
type = texture->getDriverType();
if (type == EDT_OPENGL)
{
texture->grab();
if (!prevTexture)
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, static_cast<const COpenGLTexture*>(texture)->getOpenGLTextureName());
}
else
{
texture = 0;
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
}
}
if (!texture)
{
glBindTexture(GL_TEXTURE_2D, 0);
if (prevTexture)
glDisable(GL_TEXTURE_2D);
}
Texture[index] = static_cast<const COpenGLTexture*>(texture);
if (prevTexture)
prevTexture->drop();
}
status = true;
}
return (status && type == EDT_OPENGL);
}
void COpenGLCallBridge::STextureCache::remove(ITexture* texture)
{
if (!texture)
return;
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
if (Texture[i] == texture)
{
Texture[i] = 0;
texture->drop();
}
}
}
void COpenGLCallBridge::STextureCache::clear()
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
if (Texture[i])
{
const COpenGLTexture* prevTexture = Texture[i];
Texture[i] = 0;
prevTexture->drop();
}
}
}
/* COpenGLCallBridge */
COpenGLCallBridge::COpenGLCallBridge(COpenGLDriver* driver) :
TextureCache(STextureCache(this, driver->MaxSupportedTextures)), Driver(driver),
AlphaMode(GL_ALWAYS), AlphaRef(0.0f), AlphaTest(false),
ClientStateVertex(false), ClientStateNormal(false), ClientStateColor(false), ClientStateTexCoord0(false),
CullFaceMode(GL_BACK), CullFace(false),
DepthFunc(GL_LESS), DepthMask(true), DepthTest(false), FrameBufferID(0), MatrixMode(GL_MODELVIEW),
ActiveTexture(GL_TEXTURE0_ARB), ClientActiveTexture(GL_TEXTURE0_ARB), ViewportX(0), ViewportY(0)
{
FrameBufferCount = core::max_(static_cast<GLuint>(1), static_cast<GLuint>(Driver->MaxMultipleRenderTargets));
BlendEquation = new GLenum[FrameBufferCount];
BlendSourceRGB = new GLenum[FrameBufferCount];
BlendDestinationRGB = new GLenum[FrameBufferCount];
BlendSourceAlpha = new GLenum[FrameBufferCount];
BlendDestinationAlpha = new GLenum[FrameBufferCount];
Blend = new bool[FrameBufferCount];
ColorMask = new bool[FrameBufferCount][4];
for (u32 i = 0; i < FrameBufferCount; ++i)
{
#if defined(GL_VERSION_1_4)
BlendEquation[i] = GL_FUNC_ADD;
#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op)
BlendEquation[i] = GL_FUNC_ADD_EXT;
#endif
BlendSourceRGB[i] = GL_ONE;
BlendDestinationRGB[i] = GL_ZERO;
BlendSourceAlpha[i] = GL_ONE;
BlendDestinationAlpha[i] = GL_ZERO;
Blend[i] = false;
for (u32 j = 0; j < 4; ++j)
ColorMask[i][j] = true;
}
// Initial OpenGL values from specification.
glAlphaFunc(GL_ALWAYS, 0.0f);
glDisable(GL_ALPHA_TEST);
if (Driver->queryFeature(EVDF_BLEND_OPERATIONS))
{
#if defined(GL_VERSION_1_4)
Driver->extGlBlendEquation(GL_FUNC_ADD);
#elif defined(GL_EXT_blend_subtract) || defined(GL_EXT_blend_minmax) || defined(GL_EXT_blend_logic_op)
Driver->extGlBlendEquation(GL_FUNC_ADD_EXT);
#endif
}
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_BLEND);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
if(Driver->MultiTextureExtension)
{
Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
Driver->extGlClientActiveTexture(GL_TEXTURE0_ARB);
}
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
const core::dimension2d<u32> ScreenSize = Driver->getScreenSize();
ViewportWidth = ScreenSize.Width;
ViewportHeight = ScreenSize.Height;
glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);
}
COpenGLCallBridge::~COpenGLCallBridge()
{
delete[] BlendEquation;
delete[] BlendSourceRGB;
delete[] BlendDestinationRGB;
delete[] BlendSourceAlpha;
delete[] BlendDestinationAlpha;
delete[] Blend;
delete[] ColorMask;
}
void COpenGLCallBridge::setAlphaFunc(GLenum mode, GLclampf ref)
{
if(AlphaMode != mode || AlphaRef != ref)
{
glAlphaFunc(mode, ref);
AlphaMode = mode;
AlphaRef = ref;
}
}
void COpenGLCallBridge::setAlphaTest(bool enable)
{
if(AlphaTest != enable)
{
if (enable)
glEnable(GL_ALPHA_TEST);
else
glDisable(GL_ALPHA_TEST);
AlphaTest = enable;
}
}
void COpenGLCallBridge::setBlendEquation(GLenum mode)
{
if (BlendEquation[0] != mode)
{
Driver->extGlBlendEquation(mode);
for (GLuint i = 0; i < FrameBufferCount; ++i)
BlendEquation[i] = mode;
}
}
void COpenGLCallBridge::setBlendEquationIndexed(GLuint index, GLenum mode)
{
if (index < FrameBufferCount && BlendEquation[index] != mode)
{
Driver->extGlBlendEquationIndexed(index, mode);
BlendEquation[index] = mode;
}
}
void COpenGLCallBridge::setBlendFunc(GLenum source, GLenum destination)
{
if (BlendSourceRGB[0] != source || BlendDestinationRGB[0] != destination ||
BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination)
{
glBlendFunc(source, destination);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
BlendSourceRGB[i] = source;
BlendDestinationRGB[i] = destination;
BlendSourceAlpha[i] = source;
BlendDestinationAlpha[i] = destination;
}
}
}
void COpenGLCallBridge::setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
{
if (BlendSourceRGB[0] != sourceRGB || BlendDestinationRGB[0] != destinationRGB ||
BlendSourceAlpha[0] != sourceAlpha || BlendDestinationAlpha[0] != destinationAlpha)
{
Driver->extGlBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
BlendSourceRGB[i] = sourceRGB;
BlendDestinationRGB[i] = destinationRGB;
BlendSourceAlpha[i] = sourceAlpha;
BlendDestinationAlpha[i] = destinationAlpha;
}
}
}
else
{
setBlendFunc(sourceRGB, destinationRGB);
}
}
void COpenGLCallBridge::setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination)
{
if (index < FrameBufferCount && (BlendSourceRGB[index] != source || BlendDestinationRGB[index] != destination ||
BlendSourceAlpha[index] != source || BlendDestinationAlpha[index] != destination))
{
Driver->extGlBlendFuncIndexed(index, source, destination);
BlendSourceRGB[index] = source;
BlendDestinationRGB[index] = destination;
BlendSourceAlpha[index] = source;
BlendDestinationAlpha[index] = destination;
}
}
void COpenGLCallBridge::setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
{
if (index < FrameBufferCount && (BlendSourceRGB[index] != sourceRGB || BlendDestinationRGB[index] != destinationRGB ||
BlendSourceAlpha[index] != sourceAlpha || BlendDestinationAlpha[index] != destinationAlpha))
{
Driver->extGlBlendFuncSeparateIndexed(index, sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
BlendSourceRGB[index] = sourceRGB;
BlendDestinationRGB[index] = destinationRGB;
BlendSourceAlpha[index] = sourceAlpha;
BlendDestinationAlpha[index] = destinationAlpha;
}
}
else
{
setBlendFuncIndexed(index, sourceRGB, destinationRGB);
}
}
void COpenGLCallBridge::setBlend(bool enable)
{
if (Blend[0] != enable)
{
if (enable)
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
for (GLuint i = 0; i < FrameBufferCount; ++i)
Blend[i] = enable;
}
}
void COpenGLCallBridge::setBlendIndexed(GLuint index, bool enable)
{
if (index < FrameBufferCount && Blend[index] != enable)
{
if (enable)
Driver->extGlEnableIndexed(GL_BLEND, index);
else
Driver->extGlDisableIndexed(GL_BLEND, index);
Blend[index] = enable;
}
}
void COpenGLCallBridge::setColorMask(bool red, bool green, bool blue, bool alpha)
{
if (ColorMask[0][0] != red || ColorMask[0][1] != green || ColorMask[0][2] != blue || ColorMask[0][3] != alpha)
{
glColorMask(red, green, blue, alpha);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
ColorMask[i][0] = red;
ColorMask[i][1] = green;
ColorMask[i][2] = blue;
ColorMask[i][3] = alpha;
}
}
}
void COpenGLCallBridge::setColorMaskIndexed(GLuint index, bool red, bool green, bool blue, bool alpha)
{
if (index < FrameBufferCount && (ColorMask[index][0] != red || ColorMask[index][1] != green || ColorMask[index][2] != blue || ColorMask[index][3] != alpha))
{
Driver->extGlColorMaskIndexed(index, red, green, blue, alpha);
ColorMask[index][0] = red;
ColorMask[index][1] = green;
ColorMask[index][2] = blue;
ColorMask[index][3] = alpha;
}
}
void COpenGLCallBridge::setClientState(bool vertex, bool normal, bool color, bool texCoord0)
{
if(ClientStateVertex != vertex)
{
if(vertex)
glEnableClientState(GL_VERTEX_ARRAY);
else
glDisableClientState(GL_VERTEX_ARRAY);
ClientStateVertex = vertex;
}
if(ClientStateNormal != normal)
{
if(normal)
glEnableClientState(GL_NORMAL_ARRAY);
else
glDisableClientState(GL_NORMAL_ARRAY);
ClientStateNormal = normal;
}
if(ClientStateColor != color)
{
if(color)
glEnableClientState(GL_COLOR_ARRAY);
else
glDisableClientState(GL_COLOR_ARRAY);
ClientStateColor = color;
}
if(ClientStateTexCoord0 != texCoord0)
{
setClientActiveTexture(GL_TEXTURE0_ARB);
if(texCoord0)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
ClientStateTexCoord0 = texCoord0;
}
}
void COpenGLCallBridge::setCullFaceFunc(GLenum mode)
{
if(CullFaceMode != mode)
{
glCullFace(mode);
CullFaceMode = mode;
}
}
void COpenGLCallBridge::setCullFace(bool enable)
{
if(CullFace != enable)
{
if (enable)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
CullFace = enable;
}
}
void COpenGLCallBridge::setDepthFunc(GLenum mode)
{
if(DepthFunc != mode)
{
glDepthFunc(mode);
DepthFunc = mode;
}
}
void COpenGLCallBridge::setDepthMask(bool enable)
{
if(DepthMask != enable)
{
if (enable)
glDepthMask(GL_TRUE);
else
glDepthMask(GL_FALSE);
DepthMask = enable;
}
}
void COpenGLCallBridge::setDepthTest(bool enable)
{
if(DepthTest != enable)
{
if (enable)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);
DepthTest = enable;
}
}
void COpenGLCallBridge::getFBO(GLuint& id) const
{
id = FrameBufferID;
}
void COpenGLCallBridge::setFBO(GLuint id)
{
if (FrameBufferID != id)
{
#if defined(GL_EXT_framebuffer_object)
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_EXT, id);
#endif
FrameBufferID = id;
}
}
void COpenGLCallBridge::setMatrixMode(GLenum mode)
{
if (MatrixMode != mode)
{
glMatrixMode(mode);
MatrixMode = mode;
}
}
void COpenGLCallBridge::setActiveTexture(GLenum texture)
{
if (Driver->MultiTextureExtension && ActiveTexture != texture)
{
Driver->extGlActiveTexture(texture);
ActiveTexture = texture;
}
}
void COpenGLCallBridge::setClientActiveTexture(GLenum texture)
{
if (Driver->MultiTextureExtension && ClientActiveTexture != texture)
{
Driver->extGlClientActiveTexture(texture);
ClientActiveTexture = texture;
}
}
void COpenGLCallBridge::setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight)
{
if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight)
{
glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
ViewportX = viewportX;
ViewportY = viewportY;
ViewportWidth = viewportWidth;
ViewportHeight = viewportHeight;
}
return CacheHandler;
}
......
......@@ -29,12 +29,12 @@ namespace irr
namespace video
{
class COpenGLCallBridge;
class COpenGLCacheHandler;
class COpenGLTexture;
class COpenGLDriver : public CNullDriver, public IMaterialRendererServices, public COpenGLExtensionHandler
{
friend class COpenGLCallBridge;
friend class COpenGLCacheHandler;
friend class COpenGLTexture;
public:
// Information about state of fixed pipeline activity.
......@@ -409,8 +409,7 @@ namespace video
//! Get current material.
const SMaterial& getCurrentMaterial() const;
//! Get bridge calls.
COpenGLCallBridge* getBridgeCalls() const;
COpenGLCacheHandler* getCacheHandler() const;
private:
......@@ -454,8 +453,7 @@ namespace video
void renderArray(const void* indexList, u32 primitiveCount,
scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
// Bridge calls.
COpenGLCallBridge* BridgeCalls;
COpenGLCacheHandler* CacheHandler;
core::stringw Name;
core::matrix4 Matrices[ETS_COUNT];
......@@ -535,149 +533,6 @@ namespace video
E_DEVICE_TYPE DeviceType;
};
//! This is a bridge between Irlicht pseudo OpenGL calls and real OpenGL calls.
class COpenGLCallBridge
{
class STextureCache
{
public:
STextureCache(COpenGLCallBridge* cacheHandler, u32 textureCount);
~STextureCache();
const COpenGLTexture* operator[](int index) const;
bool set(u32 index, const ITexture* texture);
void remove(ITexture* texture);
void clear();
private:
COpenGLCallBridge* CacheHandler;
const COpenGLTexture* Texture[MATERIAL_MAX_TEXTURES];
u32 TextureCount;
};
public:
COpenGLCallBridge(COpenGLDriver* driver);
~COpenGLCallBridge();
// Alpha calls.
void setAlphaFunc(GLenum mode, GLclampf ref);
void setAlphaTest(bool enable);
// Blending calls.
void setBlendEquation(GLenum mode);
void setBlendEquationIndexed(GLuint index, GLenum mode);
void setBlendFunc(GLenum source, GLenum destination);
void setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha);
void setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination);
void setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha);
void setBlend(bool enable);
void setBlendIndexed(GLuint index, bool enable);
// Client state calls.
void setClientState(bool vertex, bool normal, bool color, bool texCoord0);
// Color Mask.
void setColorMask(bool red, bool green, bool blue, bool alpha);
void setColorMaskIndexed(GLuint index, bool red, bool green, bool blue, bool alpha);
// Cull face calls.
void setCullFaceFunc(GLenum mode);
void setCullFace(bool enable);
// Depth calls.
void setDepthFunc(GLenum mode);
void setDepthMask(bool enable);
void setDepthTest(bool enable);
// FBO calls.
void getFBO(GLuint& id) const;
void setFBO(GLuint id);
// Matrix calls.
void setMatrixMode(GLenum mode);
// Texture calls.
void setActiveTexture(GLenum texture);
void setClientActiveTexture(GLenum texture);
// Viewport calls.
void setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight);
// Texture cache.
STextureCache TextureCache;
private:
COpenGLDriver* Driver;
GLuint FrameBufferCount;
GLenum AlphaMode;
GLclampf AlphaRef;
bool AlphaTest;
GLenum* BlendEquation;
GLenum* BlendSourceRGB;
GLenum* BlendDestinationRGB;
GLenum* BlendSourceAlpha;
GLenum* BlendDestinationAlpha;
bool* Blend;
bool ClientStateVertex;
bool ClientStateNormal;
bool ClientStateColor;
bool ClientStateTexCoord0;
bool (*ColorMask)[4];
GLenum CullFaceMode;
bool CullFace;
GLenum DepthFunc;
bool DepthMask;
bool DepthTest;
GLuint FrameBufferID;
GLenum MatrixMode;
GLenum ActiveTexture;
GLenum ClientActiveTexture;
GLint ViewportX;
GLint ViewportY;
GLsizei ViewportWidth;
GLsizei ViewportHeight;
};
} // end namespace video
} // end namespace irr
......
......@@ -9,6 +9,7 @@
#ifdef _IRR_COMPILE_WITH_OPENGL_
#include "COpenGLDriver.h"
#include "COpenGLCacheHandler.h"
#include "IMaterialRenderer.h"
namespace irr
......@@ -75,16 +76,16 @@ public:
u32 alphaSource;
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
Driver->getBridgeCalls()->setBlend(true);
Driver->getCacheHandler()->setBlend(true);
if (Driver->queryFeature(EVDF_BLEND_SEPARATE))
{
Driver->getBridgeCalls()->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
Driver->getCacheHandler()->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact));
}
else
{
Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact));
Driver->getCacheHandler()->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact));
}
#ifdef GL_ARB_texture_env_combine
......@@ -153,7 +154,7 @@ public:
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
#endif
Driver->getBridgeCalls()->setBlend(false);
Driver->getCacheHandler()->setBlend(false);
}
//! Returns if the material is transparent.
......@@ -191,7 +192,7 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
#ifdef GL_ARB_texture_env_combine
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
......@@ -219,14 +220,14 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#ifdef GL_ARB_texture_env_combine
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);
#else
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
#endif
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE0_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB);
}
}
......@@ -254,8 +255,8 @@ public:
Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
Driver->getBridgeCalls()->setBlend(true);
Driver->getCacheHandler()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
Driver->getCacheHandler()->setBlend(true);
if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
......@@ -263,7 +264,7 @@ public:
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
Driver->getBridgeCalls()->setBlend(false);
Driver->getCacheHandler()->setBlend(false);
}
//! Returns if the material is transparent.
......@@ -296,8 +297,8 @@ public:
Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getCacheHandler()->setBlend(true);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
......@@ -330,7 +331,7 @@ public:
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE );
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE );
#endif
Driver->getBridgeCalls()->setBlend(false);
Driver->getCacheHandler()->setBlend(false);
}
//! Returns if the material is transparent.
......@@ -363,10 +364,10 @@ public:
Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setAlphaTest(true);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam);
Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getCacheHandler()->setBlend(true);
Driver->getCacheHandler()->setAlphaTest(true);
Driver->getCacheHandler()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
......@@ -397,8 +398,8 @@ public:
#else
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE );
#endif
Driver->getBridgeCalls()->setAlphaTest(false);
Driver->getBridgeCalls()->setBlend(false);
Driver->getCacheHandler()->setAlphaTest(false);
Driver->getCacheHandler()->setBlend(false);
}
//! Returns if the material is transparent.
......@@ -433,15 +434,15 @@ public:
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
Driver->getBridgeCalls()->setAlphaTest(true);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, 0.5f);
Driver->getCacheHandler()->setAlphaTest(true);
Driver->getCacheHandler()->setAlphaFunc(GL_GREATER, 0.5f);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
Driver->getBridgeCalls()->setAlphaTest(false);
Driver->getCacheHandler()->setAlphaTest(false);
}
//! Returns if the material is transparent.
......@@ -498,7 +499,7 @@ public:
{
// lightmap
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
#ifdef GL_ARB_texture_env_combine
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
......@@ -552,7 +553,7 @@ public:
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.0f);
#endif
}
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE0_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB);
}
}
}
......@@ -561,14 +562,14 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
#ifdef GL_ARB_texture_env_combine
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.f );
#else
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.f );
#endif
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE0_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}
......@@ -605,7 +606,7 @@ public:
// detail map on second layer
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
#ifdef GL_ARB_texture_env_combine
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD_SIGNED_ARB);
......@@ -625,9 +626,9 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE0_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB);
}
}
......@@ -703,7 +704,7 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
#ifdef GL_ARB_texture_env_combine
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
......@@ -727,14 +728,14 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE0_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB);
}
}
......@@ -762,8 +763,8 @@ public:
Driver->disableTextures(2);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getBridgeCalls()->setBlend(true);
Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Driver->getCacheHandler()->setBlend(true);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
......@@ -784,7 +785,7 @@ public:
#endif
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
#ifdef GL_ARB_texture_env_combine
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
......@@ -812,16 +813,16 @@ public:
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE1_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->getBridgeCalls()->setActiveTexture(GL_TEXTURE0_ARB);
Driver->getCacheHandler()->setActiveTexture(GL_TEXTURE0_ARB);
}
Driver->getBridgeCalls()->setBlend(false);
Driver->getCacheHandler()->setBlend(false);
}
//! Returns if the material is transparent.
......
......@@ -92,7 +92,7 @@ bool checkFBOStatus(COpenGLDriver* Driver)
}
COpenGLRenderTarget::COpenGLRenderTarget(COpenGLDriver* driver) : AssignedDepth(false), AssignedStencil(false), RequestTextureUpdate(false), RequestDepthStencilUpdate(false),
BufferID(0), SupportForFBO(false), SupportForMRT(false), BridgeCalls(0), Driver(driver)
BufferID(0), SupportForFBO(false), SupportForMRT(false), Driver(driver)
{
#ifdef _DEBUG
setDebugName("COpenGLRenderTarget");
......@@ -101,7 +101,6 @@ COpenGLRenderTarget::COpenGLRenderTarget(COpenGLDriver* driver) : AssignedDepth(
DriverType = EDT_OPENGL;
Size = Driver->getScreenSize();
BridgeCalls = Driver->getBridgeCalls();
#if defined(GL_VERSION_3_0) || defined(GL_ARB_framebuffer_object) || defined(GL_EXT_framebuffer_object)
SupportForFBO = Driver->FeatureAvailable[COpenGLDriver::IRR_EXT_framebuffer_object] || Driver->FeatureAvailable[COpenGLDriver::IRR_ARB_framebuffer_object];
......
......@@ -20,7 +20,7 @@ namespace video
{
class COpenGLDriver;
class COpenGLCallBridge;
class COpenGLCacheHandler;
class COpenGLRenderTarget : public IRenderTarget
{
......@@ -53,8 +53,6 @@ protected:
bool SupportForFBO;
bool SupportForMRT;
COpenGLCallBridge* BridgeCalls;
COpenGLDriver* Driver;
};
......
......@@ -20,6 +20,7 @@
#include "IVideoDriver.h"
#include "os.h"
#include "COpenGLDriver.h"
#include "COpenGLCacheHandler.h"
#include "COpenGLMaterialRenderer.h"
namespace irr
......@@ -231,7 +232,7 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
COpenGLCallBridge* bridgeCalls = Driver->getBridgeCalls();
COpenGLCacheHandler* cacheHandler = Driver->getCacheHandler();
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
......@@ -245,13 +246,13 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
if (Alpha)
{
bridgeCalls->setBlend(true);
bridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
cacheHandler->setBlend(true);
cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else if (FixedBlending)
{
bridgeCalls->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
bridgeCalls->setBlend(true);
cacheHandler->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
cacheHandler->setBlend(true);
}
else if (Blending)
{
......@@ -262,20 +263,20 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
if (Driver->queryFeature(EVDF_BLEND_SEPARATE))
{
bridgeCalls->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact));
}
else
{
bridgeCalls->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact));
cacheHandler->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact));
}
bridgeCalls->setBlend(true);
cacheHandler->setBlend(true);
}
else if (AlphaTest)
{
bridgeCalls->setAlphaTest(true);
bridgeCalls->setAlphaFunc(GL_GREATER, 0.5f);
cacheHandler->setAlphaTest(true);
cacheHandler->setAlphaFunc(GL_GREATER, 0.5f);
}
if (CallBack)
......
......@@ -11,6 +11,7 @@
#include "IVideoDriver.h"
#include "os.h"
#include "COpenGLDriver.h"
#include "COpenGLCacheHandler.h"
#include "COpenGLMaterialRenderer.h"
namespace irr
......@@ -161,7 +162,7 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi
else
Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE);
COpenGLCallBridge* bridgeCalls = Driver->getBridgeCalls();
COpenGLCacheHandler* cacheHandler = Driver->getCacheHandler();
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
......@@ -208,13 +209,13 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi
if (Alpha)
{
bridgeCalls->setBlend(true);
bridgeCalls->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
cacheHandler->setBlend(true);
cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else if (FixedBlending)
{
bridgeCalls->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
bridgeCalls->setBlend(true);
cacheHandler->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
cacheHandler->setBlend(true);
}
else if (Blending)
{
......@@ -225,20 +226,20 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi
if (Driver->queryFeature(EVDF_BLEND_SEPARATE))
{
bridgeCalls->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact),
Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact));
}
else
{
bridgeCalls->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact));
cacheHandler->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact));
}
bridgeCalls->setBlend(true);
cacheHandler->setBlend(true);
}
else if (AlphaTest)
{
bridgeCalls->setAlphaTest(true);
bridgeCalls->setAlphaFunc(GL_GREATER, 0.5f);
cacheHandler->setAlphaTest(true);
cacheHandler->setAlphaFunc(GL_GREATER, 0.5f);
}
if (CallBack)
......
......@@ -9,6 +9,7 @@
#include "irrTypes.h"
#include "COpenGLTexture.h"
#include "COpenGLDriver.h"
#include "COpenGLCacheHandler.h"
#include "os.h"
#include "CColorConverter.h"
......@@ -108,8 +109,8 @@ COpenGLTexture::COpenGLTexture(const io::path& name, const core::dimension2d<u32
setDebugName("COpenGLTexture");
#endif
COpenGLCallBridge* bridgeCalls = Driver->getBridgeCalls();
const COpenGLTexture* prevTexture = bridgeCalls->TextureCache[0];
COpenGLCacheHandler* cacheHandler = Driver->getCacheHandler();
const COpenGLTexture* prevTexture = cacheHandler->TextureCache[0];
DriverType = EDT_OPENGL;
......@@ -140,7 +141,7 @@ COpenGLTexture::COpenGLTexture(const io::path& name, const core::dimension2d<u32
glGenTextures(1, &TextureName);
bridgeCalls->TextureCache.set(0, this);
cacheHandler->TextureCache.set(0, this);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilteringType);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
......@@ -156,14 +157,14 @@ COpenGLTexture::COpenGLTexture(const io::path& name, const core::dimension2d<u32
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, OriginalSize.Width, OriginalSize.Height, 0, PixelFormat, PixelType, 0);
bridgeCalls->TextureCache.set(0, prevTexture);
cacheHandler->TextureCache.set(0, prevTexture);
}
//! destructor
COpenGLTexture::~COpenGLTexture()
{
Driver->getBridgeCalls()->TextureCache.remove(this);
Driver->getCacheHandler()->TextureCache.remove(this);
if (TextureName)
glDeleteTextures(1, &TextureName);
......@@ -478,8 +479,8 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
return;
}
COpenGLCallBridge* bridgeCalls = Driver->getBridgeCalls();
const COpenGLTexture* prevTexture = bridgeCalls->TextureCache[0];
COpenGLCacheHandler* cacheHandler = Driver->getCacheHandler();
const COpenGLTexture* prevTexture = cacheHandler->TextureCache[0];
// get correct opengl color data values
GLenum oldInternalFormat = InternalFormat;
......@@ -489,7 +490,7 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
if (!newTexture)
InternalFormat=oldInternalFormat;
bridgeCalls->TextureCache.set(0, this);
cacheHandler->TextureCache.set(0, this);
if (Driver->testGLError())
os::Printer::log("Could not bind Texture", ELL_ERROR);
......@@ -603,7 +604,7 @@ void COpenGLTexture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
if (Driver->testGLError())
os::Printer::log("Could not glTexImage2D", ELL_ERROR);
bridgeCalls->TextureCache.set(0, prevTexture);
cacheHandler->TextureCache.set(0, prevTexture);
}
......
......@@ -830,6 +830,8 @@
<Unit filename="COctreeTriangleSelector.h" />
<Unit filename="COgreMeshFileLoader.cpp" />
<Unit filename="COgreMeshFileLoader.h" />
<Unit filename="COpenGLCacheHandler.cpp" />
<Unit filename="COpenGLCacheHandler.h" />
<Unit filename="COpenGLDriver.cpp" />
<Unit filename="COpenGLDriver.h" />
<Unit filename="COpenGLExtensionHandler.cpp" />
......
......@@ -1102,6 +1102,7 @@
<ClInclude Include="IZBuffer.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="S2DVertex.h" />
<ClInclude Include="COpenGLCacheHandler.h" />
<ClInclude Include="COpenGLDriver.h" />
<ClInclude Include="COpenGLExtensionHandler.h" />
<ClInclude Include="COpenGLMaterialRenderer.h" />
......@@ -1351,6 +1352,7 @@
<ClCompile Include="CTRTextureGouraudNoZ.cpp" />
<ClCompile Include="CTRTextureGouraudWire.cpp" />
<ClCompile Include="CZBuffer.cpp" />
<ClCompile Include="COpenGLCacheHandler.cpp" />
<ClCompile Include="COpenGLDriver.cpp" />
<ClCompile Include="COpenGLExtensionHandler.cpp" />
<ClCompile Include="COpenGLNormalMapRenderer.cpp" />
......
......@@ -849,6 +849,9 @@
<ClInclude Include="S2DVertex.h">
<Filter>Irrlicht\video\Software</Filter>
</ClInclude>
<ClInclude Include="COpenGLCacheHandler.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
<ClInclude Include="COpenGLDriver.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
......@@ -1616,6 +1619,9 @@
<ClCompile Include="CZBuffer.cpp">
<Filter>Irrlicht\video\Software</Filter>
</ClCompile>
<ClCompile Include="COpenGLCacheHandler.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
<ClCompile Include="COpenGLDriver.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
......
......@@ -1101,6 +1101,7 @@
<ClInclude Include="IZBuffer.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="S2DVertex.h" />
<ClInclude Include="COpenGLCacheHandler.h" />
<ClInclude Include="COpenGLDriver.h" />
<ClInclude Include="COpenGLExtensionHandler.h" />
<ClInclude Include="COpenGLMaterialRenderer.h" />
......@@ -1351,6 +1352,7 @@
<ClCompile Include="CTRTextureGouraudNoZ.cpp" />
<ClCompile Include="CTRTextureGouraudWire.cpp" />
<ClCompile Include="CZBuffer.cpp" />
<ClCompile Include="COpenGLCacheHandler.cpp" />
<ClCompile Include="COpenGLDriver.cpp" />
<ClCompile Include="COpenGLExtensionHandler.cpp" />
<ClCompile Include="COpenGLNormalMapRenderer.cpp" />
......
......@@ -855,6 +855,9 @@
<ClInclude Include="S2DVertex.h">
<Filter>Irrlicht\video\Software</Filter>
</ClInclude>
<ClInclude Include="COpenGLCacheHandler.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
<ClInclude Include="COpenGLDriver.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
......@@ -1616,6 +1619,9 @@
<ClCompile Include="CZBuffer.cpp">
<Filter>Irrlicht\video\Software</Filter>
</ClCompile>
<ClCompile Include="COpenGLCacheHandler.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
<ClCompile Include="COpenGLDriver.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
......
......@@ -1101,6 +1101,7 @@
<ClInclude Include="IZBuffer.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="S2DVertex.h" />
<ClInclude Include="COpenGLCacheHandler.h" />
<ClInclude Include="COpenGLDriver.h" />
<ClInclude Include="COpenGLExtensionHandler.h" />
<ClInclude Include="COpenGLMaterialRenderer.h" />
......@@ -1351,6 +1352,7 @@
<ClCompile Include="CTRTextureGouraudNoZ.cpp" />
<ClCompile Include="CTRTextureGouraudWire.cpp" />
<ClCompile Include="CZBuffer.cpp" />
<ClCompile Include="COpenGLCacheHandler.cpp" />
<ClCompile Include="COpenGLDriver.cpp" />
<ClCompile Include="COpenGLExtensionHandler.cpp" />
<ClCompile Include="COpenGLNormalMapRenderer.cpp" />
......
......@@ -855,6 +855,9 @@
<ClInclude Include="S2DVertex.h">
<Filter>Irrlicht\video\Software</Filter>
</ClInclude>
<ClInclude Include="COpenGLCacheHandler.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
<ClInclude Include="COpenGLDriver.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
......@@ -1616,6 +1619,9 @@
<ClCompile Include="CZBuffer.cpp">
<Filter>Irrlicht\video\Software</Filter>
</ClCompile>
<ClCompile Include="COpenGLCacheHandler.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
<ClCompile Include="COpenGLDriver.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
......
......@@ -1111,6 +1111,7 @@
<ClInclude Include="IZBuffer.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="S2DVertex.h" />
<ClInclude Include="COpenGLCacheHandler.h" />
<ClInclude Include="COpenGLDriver.h" />
<ClInclude Include="COpenGLExtensionHandler.h" />
<ClInclude Include="COpenGLMaterialRenderer.h" />
......@@ -1361,6 +1362,7 @@
<ClCompile Include="CTRTextureGouraudNoZ.cpp" />
<ClCompile Include="CTRTextureGouraudWire.cpp" />
<ClCompile Include="CZBuffer.cpp" />
<ClCompile Include="COpenGLCacheHandler.cpp" />
<ClCompile Include="COpenGLDriver.cpp" />
<ClCompile Include="COpenGLExtensionHandler.cpp" />
<ClCompile Include="COpenGLNormalMapRenderer.cpp" />
......
......@@ -855,6 +855,9 @@
<ClInclude Include="S2DVertex.h">
<Filter>Irrlicht\video\Software</Filter>
</ClInclude>
<ClInclude Include="COpenGLCacheHandler.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
<ClInclude Include="COpenGLDriver.h">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClInclude>
......@@ -1616,6 +1619,9 @@
<ClCompile Include="CZBuffer.cpp">
<Filter>Irrlicht\video\Software</Filter>
</ClCompile>
<ClCompile Include="COpenGLCacheHandler.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
<ClCompile Include="COpenGLDriver.cpp">
<Filter>Irrlicht\video\OpenGL</Filter>
</ClCompile>
......
......@@ -2187,6 +2187,14 @@
<Filter
Name="OpenGL"
>
<File
RelativePath="COpenGLCacheHandler.cpp"
>
</File>
<File
RelativePath="COpenGLCacheHandler.h"
>
</File>
<File
RelativePath="COpenGLDriver.cpp"
>
......
......@@ -38,7 +38,7 @@ IRRMESHOBJ = $(IRRMESHLOADER) $(IRRMESHWRITER) \
IRROBJ = CBillboardSceneNode.o CCameraSceneNode.o CDummyTransformationSceneNode.o CEmptySceneNode.o CGeometryCreator.o CLightSceneNode.o CMeshManipulator.o CMetaTriangleSelector.o COctreeSceneNode.o COctreeTriangleSelector.o CSceneCollisionManager.o CSceneManager.o CShadowVolumeSceneNode.o CSkyBoxSceneNode.o CSkyDomeSceneNode.o CTerrainSceneNode.o CTerrainTriangleSelector.o CVolumeLightSceneNode.o CCubeSceneNode.o CSphereSceneNode.o CTextSceneNode.o CTriangleBBSelector.o CTriangleSelector.o CWaterSurfaceSceneNode.o CMeshCache.o CDefaultSceneNodeAnimatorFactory.o CDefaultSceneNodeFactory.o CSceneLoaderIrr.o
IRRPARTICLEOBJ = CParticleAnimatedMeshSceneNodeEmitter.o CParticleBoxEmitter.o CParticleCylinderEmitter.o CParticleMeshEmitter.o CParticlePointEmitter.o CParticleRingEmitter.o CParticleSphereEmitter.o CParticleAttractionAffector.o CParticleFadeOutAffector.o CParticleGravityAffector.o CParticleRotationAffector.o CParticleSystemSceneNode.o CParticleScaleAffector.o
IRRANIMOBJ = CSceneNodeAnimatorCameraFPS.o CSceneNodeAnimatorCameraMaya.o CSceneNodeAnimatorCollisionResponse.o CSceneNodeAnimatorDelete.o CSceneNodeAnimatorFlyCircle.o CSceneNodeAnimatorFlyStraight.o CSceneNodeAnimatorFollowSpline.o CSceneNodeAnimatorRotation.o CSceneNodeAnimatorTexture.o
IRRDRVROBJ = CNullDriver.o COpenGLDriver.o COpenGLNormalMapRenderer.o COpenGLParallaxMapRenderer.o COpenGLRenderTarget.o COpenGLShaderMaterialRenderer.o COpenGLTexture.o COpenGLSLMaterialRenderer.o COpenGLExtensionHandler.o CD3D9Driver.o CD3D9HLSLMaterialRenderer.o CD3D9NormalMapRenderer.o CD3D9ParallaxMapRenderer.o CD3D9ShaderMaterialRenderer.o CD3D9Texture.o
IRRDRVROBJ = CNullDriver.o COpenGLCacheHandler.o COpenGLDriver.o COpenGLNormalMapRenderer.o COpenGLParallaxMapRenderer.o COpenGLRenderTarget.o COpenGLShaderMaterialRenderer.o COpenGLTexture.o COpenGLSLMaterialRenderer.o COpenGLExtensionHandler.o CD3D9Driver.o CD3D9HLSLMaterialRenderer.o CD3D9NormalMapRenderer.o CD3D9ParallaxMapRenderer.o CD3D9ShaderMaterialRenderer.o CD3D9Texture.o
IRRIMAGEOBJ = CColorConverter.o CImage.o CImageLoaderBMP.o CImageLoaderDDS.o CImageLoaderJPG.o CImageLoaderPCX.o CImageLoaderPNG.o CImageLoaderPSD.o CImageLoaderTGA.o CImageLoaderPPM.o CImageLoaderWAL.o CImageLoaderRGB.o \
CImageWriterBMP.o CImageWriterJPG.o CImageWriterPCX.o CImageWriterPNG.o CImageWriterPPM.o CImageWriterPSD.o CImageWriterTGA.o
IRRVIDEOOBJ = CVideoModeList.o CFPSCounter.o $(IRRDRVROBJ) $(IRRIMAGEOBJ)
......
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