This commit is contained in:
AzaezelX 2019-04-16 09:36:00 -05:00
parent a0d1a076d5
commit 028f97c5ec
8 changed files with 0 additions and 3349 deletions

View file

@ -1 +0,0 @@
idiot me used glTexImage2D for the cubemap array code, obviously should be glTexImage3D

View file

@ -1,389 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLUtils.h"
#include "gfx/gl/gfxGLCubemap.h"
#include "gfx/gfxTextureManager.h"
#include "gfx/gfxCardProfile.h"
#include "gfx/bitmap/ddsFile.h"
#include "gfx/bitmap/imageUtils.h"
static GLenum faceList[6] =
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
GFXGLCubemap::GFXGLCubemap() :
mCubemap(0),
mDynamicTexSize(0),
mFaceFormat( GFXFormatR8G8B8A8 )
{
for(U32 i = 0; i < 6; i++)
mTextures[i] = NULL;
GFXTextureManager::addEventDelegate( this, &GFXGLCubemap::_onTextureEvent );
}
GFXGLCubemap::~GFXGLCubemap()
{
glDeleteTextures(1, &mCubemap);
GFXTextureManager::removeEventDelegate( this, &GFXGLCubemap::_onTextureEvent );
}
GLenum GFXGLCubemap::getEnumForFaceNumber(U32 face)
{
return faceList[face];
}
void GFXGLCubemap::fillCubeTextures(GFXTexHandle* faces)
{
AssertFatal( faces, "");
AssertFatal( faces[0]->mMipLevels > 0, "");
PRESERVE_CUBEMAP_TEXTURE();
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, faces[0]->mMipLevels - 1 );
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
U32 reqWidth = faces[0]->getWidth();
U32 reqHeight = faces[0]->getHeight();
GFXFormat regFaceFormat = faces[0]->getFormat();
const bool isCompressed = ImageUtil::isCompressedFormat(regFaceFormat);
mWidth = reqWidth;
mHeight = reqHeight;
mFaceFormat = regFaceFormat;
mMipMapLevels = getMax( (U32)1, faces[0]->mMipLevels);
AssertFatal(reqWidth == reqHeight, "GFXGLCubemap::fillCubeTextures - Width and height must be equal!");
for(U32 i = 0; i < 6; i++)
{
AssertFatal(faces[i], avar("GFXGLCubemap::fillCubeFaces - texture %i is NULL!", i));
AssertFatal((faces[i]->getWidth() == reqWidth) && (faces[i]->getHeight() == reqHeight), "GFXGLCubemap::fillCubeFaces - All textures must have identical dimensions!");
AssertFatal(faces[i]->getFormat() == regFaceFormat, "GFXGLCubemap::fillCubeFaces - All textures must have identical formats!");
mTextures[i] = faces[i];
GFXFormat faceFormat = faces[i]->getFormat();
GFXGLTextureObject* glTex = static_cast<GFXGLTextureObject*>(faces[i].getPointer());
if( isCompressed )
{
for( U32 mip = 0; mip < mMipMapLevels; ++mip )
{
const U32 mipWidth = getMax( U32(1), faces[i]->getWidth() >> mip );
const U32 mipHeight = getMax( U32(1), faces[i]->getHeight() >> mip );
const U32 mipDataSize = getCompressedSurfaceSize( mFaceFormat, mWidth, mHeight, mip );
U8* buf = glTex->getTextureData( mip );
glCompressedTexImage2D(faceList[i], mip, GFXGLTextureInternalFormat[mFaceFormat], mipWidth, mipHeight, 0, mipDataSize, buf);
delete[] buf;
}
}
else
{
U8* buf = glTex->getTextureData();
glTexImage2D(faceList[i], 0, GFXGLTextureInternalFormat[faceFormat], mWidth, mHeight,
0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], buf);
delete[] buf;
}
}
if( !isCompressed )
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
void GFXGLCubemap::initStatic(GFXTexHandle* faces)
{
if(mCubemap)
return;
if(faces)
{
AssertFatal(faces[0], "GFXGLCubemap::initStatic - empty texture passed");
glGenTextures(1, &mCubemap);
fillCubeTextures(faces);
}
}
void GFXGLCubemap::initStatic( DDSFile *dds )
{
if(mCubemap)
return;
AssertFatal( dds, "GFXGLCubemap::initStatic - Got null DDS file!" );
AssertFatal( dds->isCubemap(), "GFXGLCubemap::initStatic - Got non-cubemap DDS file!" );
AssertFatal( dds->mSurfaces.size() == 6, "GFXGLCubemap::initStatic - DDS has less than 6 surfaces!" );
mWidth = dds->getWidth();
mHeight = dds->getHeight();
mFaceFormat = dds->getFormat();
mMipMapLevels = dds->getMipLevels();
const bool isCompressed = ImageUtil::isCompressedFormat(mFaceFormat);
glGenTextures(1, &mCubemap);
PRESERVE_CUBEMAP_TEXTURE();
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, mMipMapLevels - 1);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
AssertFatal(mWidth == mHeight, "GFXGLCubemap::initStatic - Width and height must be equal!");
for(U32 i = 0; i < 6; i++)
{
if ( !dds->mSurfaces[i] )
{
// TODO: The DDS can skip surfaces, but i'm unsure what i should
// do here when creating the cubemap. Ignore it for now.
continue;
}
// convert to Z up
const U32 faceIndex = _zUpFaceIndex(i);
// Now loop thru the mip levels!
for (U32 mip = 0; mip < mMipMapLevels; ++mip)
{
const U32 mipWidth = getMax( U32(1), mWidth >> mip );
const U32 mipHeight = getMax( U32(1), mHeight >> mip );
if (isCompressed)
glCompressedTexImage2D(faceList[faceIndex], mip, GFXGLTextureInternalFormat[mFaceFormat], mipWidth, mipHeight, 0, dds->getSurfaceSize(mip), dds->mSurfaces[i]->mMips[mip]);
else
glTexImage2D(faceList[faceIndex], mip, GFXGLTextureInternalFormat[mFaceFormat], mipWidth, mipHeight, 0,
GFXGLTextureFormat[mFaceFormat], GFXGLTextureType[mFaceFormat], dds->mSurfaces[i]->mMips[mip]);
}
}
}
void GFXGLCubemap::initDynamic(U32 texSize, GFXFormat faceFormat, U32 mipLevels)
{
mDynamicTexSize = texSize;
mFaceFormat = faceFormat;
const bool isCompressed = ImageUtil::isCompressedFormat(faceFormat);
mMipMapLevels = getMax( (U32)1, getMaxMipmaps( texSize, texSize, 1 ) );
glGenTextures(1, &mCubemap);
PRESERVE_CUBEMAP_TEXTURE();
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, mMipMapLevels - 1);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
mWidth = texSize;
mHeight = texSize;
for(U32 i = 0; i < 6; i++)
{
if( ImageUtil::isCompressedFormat(faceFormat) )
{
for( U32 mip = 0; mip < mMipMapLevels; ++mip )
{
const U32 mipSize = getMax( U32(1), texSize >> mip );
const U32 mipDataSize = getCompressedSurfaceSize( mFaceFormat, texSize, texSize, mip );
glCompressedTexImage2D(faceList[i], mip, GFXGLTextureInternalFormat[mFaceFormat], mipSize, mipSize, 0, mipDataSize, NULL);
}
}
else
{
glTexImage2D( faceList[i], 0, GFXGLTextureInternalFormat[faceFormat], texSize, texSize,
0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], NULL);
}
}
if( !isCompressed )
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
void GFXGLCubemap::zombify()
{
glDeleteTextures(1, &mCubemap);
mCubemap = 0;
}
void GFXGLCubemap::resurrect()
{
// Handled in tmResurrect
}
void GFXGLCubemap::tmResurrect()
{
if(mDynamicTexSize)
initDynamic(mDynamicTexSize,mFaceFormat);
else
{
if ( mDDSFile )
initStatic( mDDSFile );
else
initStatic( mTextures );
}
}
void GFXGLCubemap::setToTexUnit(U32 tuNum)
{
static_cast<GFXGLDevice*>(getOwningDevice())->setCubemapInternal(tuNum, this);
}
void GFXGLCubemap::bind(U32 textureUnit) const
{
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
static_cast<GFXGLDevice*>(getOwningDevice())->getOpenglCache()->setCacheBindedTex(textureUnit, GL_TEXTURE_CUBE_MAP, mCubemap);
GFXGLStateBlockRef sb = static_cast<GFXGLDevice*>(GFX)->getCurrentStateBlock();
AssertFatal(sb, "GFXGLCubemap::bind - No active stateblock!");
if (!sb)
return;
const GFXSamplerStateDesc& ssd = sb->getDesc().samplers[textureUnit];
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, 0));
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
}
void GFXGLCubemap::_onTextureEvent( GFXTexCallbackCode code )
{
if ( code == GFXZombify )
zombify();
else
tmResurrect();
}
U8* GFXGLCubemap::getTextureData(U32 face, U32 mip)
{
AssertFatal(mMipMapLevels, "");
mip = (mip < mMipMapLevels) ? mip : 0;
const U32 bytesPerTexel = 4; //TODO make work with more formats!!!!!
const U32 dataSize = ImageUtil::isCompressedFormat(mFaceFormat)
? getCompressedSurfaceSize(mFaceFormat, mWidth, mHeight, mip)
: (mWidth >> mip) * (mHeight >> mip) * bytesPerTexel;
U8* data = new U8[dataSize];
PRESERVE_TEXTURE(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
if (ImageUtil::isCompressedFormat(mFaceFormat))
glGetCompressedTexImage(faceList[face], mip, data);
else
glGetTexImage(faceList[face], mip, GFXGLTextureFormat[mFaceFormat], GFXGLTextureType[mFaceFormat], data);
return data;
}
//-----------------------------------------------------------------------------
// Cubemap Array
//-----------------------------------------------------------------------------
GFXGLCubemapArray::GFXGLCubemapArray()
{
}
GFXGLCubemapArray::~GFXGLCubemapArray()
{
glDeleteTextures(1, &mCubemap);
}
void GFXGLCubemapArray::initStatic(GFXCubemapHandle *cubemaps, const U32 cubemapCount)
{
AssertFatal(cubemaps, "GFXGLCubemapArray- Got null GFXCubemapHandle!");
AssertFatal(*cubemaps, "GFXGLCubemapArray - Got empty cubemap!");
//all cubemaps must be the same size,format and number of mipmaps. Grab the details from the first cubemap
mSize = cubemaps[0]->getSize();
mFormat = cubemaps[0]->getFormat();
mMipMapLevels = cubemaps[0]->getMipMapLevels();
mNumCubemaps = cubemapCount;
const bool isCompressed = ImageUtil::isCompressedFormat(mFormat);
glGenTextures(1, &mCubemap);
PRESERVE_CUBEMAP_ARRAY_TEXTURE();
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, mMipMapLevels - 1);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
for (U32 i = 0; i < cubemapCount; i++)
{
GFXGLCubemap* glTex = static_cast<GFXGLCubemap*>(cubemaps[i].getPointer());
for (U32 face = 0; face < 6; face++)
{
for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++)
{
U8 *pixelData = glTex->getTextureData(face, currentMip);
const U32 mipSize = getMax(U32(1), mSize >> currentMip);
if (isCompressed)
{
const U32 mipDataSize = getCompressedSurfaceSize(mFormat, mSize, mSize, currentMip);
glCompressedTexImage2D(faceList[face], currentMip, GFXGLTextureInternalFormat[mFormat], mipSize, mipSize, 0, mipDataSize, pixelData);
}
else
{
glTexImage2D(faceList[face], currentMip, GFXGLTextureInternalFormat[mFormat], mipSize, mipSize,
0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
}
delete[] pixelData;
}
}
}
}
void GFXGLCubemapArray::setToTexUnit(U32 tuNum)
{
static_cast<GFXGLDevice*>(getOwningDevice())->setCubemapArrayInternal(tuNum, this);
}
void GFXGLCubemapArray::bind(U32 textureUnit) const
{
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
static_cast<GFXGLDevice*>(getOwningDevice())->getOpenglCache()->setCacheBindedTex(textureUnit, GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
GFXGLStateBlockRef sb = static_cast<GFXGLDevice*>(GFX)->getCurrentStateBlock();
AssertFatal(sb, "GFXGLCubemap::bind - No active stateblock!");
if (!sb)
return;
const GFXSamplerStateDesc& ssd = sb->getDesc().samplers[textureUnit];
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, 0));
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
}

View file

@ -1,113 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLCUBEMAP_H_
#define _GFXGLCUBEMAP_H_
#ifndef _GFXCUBEMAP_H_
#include "gfx/gfxCubemap.h"
#endif
#ifndef __RESOURCE_H__
#include "core/resource.h"
#endif
class GFXGLCubemap : public GFXCubemap
{
public:
GFXGLCubemap();
virtual ~GFXGLCubemap();
virtual void initStatic( GFXTexHandle *faces );
virtual void initStatic( DDSFile *dds );
virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0);
virtual U32 getSize() const { return mWidth; }
virtual GFXFormat getFormat() const { return mFaceFormat; }
// Convenience methods for GFXGLTextureTarget
U32 getWidth() { return mWidth; }
U32 getHeight() { return mHeight; }
U32 getHandle() { return mCubemap; }
// GFXResource interface
virtual void zombify();
virtual void resurrect();
/// Called by texCB; this is to ensure that all textures have been resurrected before we attempt to res the cubemap.
void tmResurrect();
static GLenum getEnumForFaceNumber(U32 face);///< Performs lookup to get a GLenum for the given face number
/// @return An array containing the texture data
/// @note You are responsible for deleting the returned data! (Use delete[])
U8* getTextureData(U32 face, U32 mip = 0);
protected:
friend class GFXDevice;
friend class GFXGLDevice;
/// The callback used to get texture events.
/// @see GFXTextureManager::addEventDelegate
void _onTextureEvent( GFXTexCallbackCode code );
GLuint mCubemap; ///< Internal GL handle
U32 mDynamicTexSize; ///< Size of faces for a dynamic texture (used in resurrect)
// Self explanatory
U32 mWidth;
U32 mHeight;
GFXFormat mFaceFormat;
GFXTexHandle mTextures[6]; ///< Keep refs to our textures for resurrection of static cubemaps
/// The backing DDSFile uses to restore the faces
/// when the surface is lost.
Resource<DDSFile> mDDSFile;
// should only be called by GFXDevice
virtual void setToTexUnit( U32 tuNum ); ///< Binds the cubemap to the given texture unit
virtual void bind(U32 textureUnit) const; ///< Notifies our owning device that we want to be set to the given texture unit (used for GL internal state tracking)
void fillCubeTextures(GFXTexHandle* faces); ///< Copies the textures in faces into the cubemap
};
class GFXGLCubemapArray : public GFXCubemapArray
{
public:
GFXGLCubemapArray();
virtual ~GFXGLCubemapArray();
virtual void initStatic(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
virtual void setToTexUnit(U32 tuNum);
// GFXResource interface
virtual void zombify() {}
virtual void resurrect() {}
protected:
friend class GFXGLDevice;
void bind(U32 textureUnit) const;
GLuint mCubemap; ///< Internal GL handle
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,281 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLDEVICE_H_
#define _GFXGLDEVICE_H_
#include "platform/platform.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxInit.h"
#include "gfx/gl/tGL/tGL.h"
#include "windowManager/platformWindow.h"
#include "gfx/gfxFence.h"
#include "gfx/gfxResource.h"
#include "gfx/gl/gfxGLStateBlock.h"
class GFXGLVertexBuffer;
class GFXGLPrimitiveBuffer;
class GFXGLTextureTarget;
class GFXGLCubemap;
class GFXGLCubemapArray;
class GFXGLStateCache;
class GFXGLVertexDecl;
class GFXGLDevice : public GFXDevice
{
public:
struct GLCapabilities
{
bool anisotropicFiltering;
bool bufferStorage;
bool shaderModel5;
bool textureStorage;
bool samplerObjects;
bool copyImage;
bool vertexAttributeBinding;
};
GLCapabilities mCapabilities;
void zombify();
void resurrect();
GFXGLDevice(U32 adapterIndex);
virtual ~GFXGLDevice();
static void enumerateAdapters( Vector<GFXAdapter*> &adapterList );
static GFXDevice *createInstance( U32 adapterIndex );
virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL );
virtual void activate() { }
virtual void deactivate() { }
virtual GFXAdapterType getAdapterType() { return OpenGL; }
virtual void enterDebugEvent(ColorI color, const char *name);
virtual void leaveDebugEvent();
virtual void setDebugMarker(ColorI color, const char *name);
virtual void enumerateVideoModes();
virtual U32 getTotalVideoMemory_GL_EXT();
virtual U32 getTotalVideoMemory();
virtual GFXCubemap * createCubemap();
virtual GFXCubemapArray *createCubemapArray();
virtual F32 getFillConventionOffset() const { return 0.0f; }
///@}
/// @name Render Target functions
/// @{
///
virtual GFXTextureTarget *allocRenderToTextureTarget(bool genMips = true);
virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window);
virtual void _updateRenderTargets();
///@}
/// @name Shader functions
/// @{
virtual F32 getPixelShaderVersion() const { return mPixelShaderVersion; }
virtual void setPixelShaderVersion( F32 version ) { mPixelShaderVersion = version; }
virtual void setShader(GFXShader *shader, bool force = false);
/// @attention GL cannot check if the given format supports blending or filtering!
virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile,
const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter);
/// Returns the number of texture samplers that can be used in a shader rendering pass
virtual U32 getNumSamplers() const;
/// Returns the number of simultaneous render targets supported by the device.
virtual U32 getNumRenderTargets() const;
virtual GFXShader* createShader();
virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil );
virtual void clearColorAttachment(const U32 attachment, const LinearColorF& color);
virtual bool beginSceneInternal();
virtual void endSceneInternal();
virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount );
virtual void drawIndexedPrimitive( GFXPrimitiveType primType,
U32 startVertex,
U32 minIndex,
U32 numVerts,
U32 startIndex,
U32 primitiveCount );
virtual void setClipRect( const RectI &rect );
virtual const RectI &getClipRect() const { return mClip; }
virtual void preDestroy() { Parent::preDestroy(); }
virtual U32 getMaxDynamicVerts() { return MAX_DYNAMIC_VERTS; }
virtual U32 getMaxDynamicIndices() { return MAX_DYNAMIC_INDICES; }
GFXFence *createFence();
GFXOcclusionQuery* createOcclusionQuery();
GFXGLStateBlockRef getCurrentStateBlock() { return mCurrentGLStateBlock; }
virtual void setupGenericShaders( GenericShaderType type = GSColor );
///
bool supportsAnisotropic() const { return mSupportsAnisotropic; }
GFXGLStateCache* getOpenglCache() { return mOpenglStateCache; }
GFXTextureObject* getDefaultDepthTex() const;
/// Returns the number of vertex streams supported by the device.
const U32 getNumVertexStreams() const { return mNumVertexStream; }
bool glUseMap() const { return mUseGlMap; }
protected:
/// Called by GFXDevice to create a device specific stateblock
virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc);
/// Called by GFXDevice to actually set a stateblock.
virtual void setStateBlockInternal(GFXStateBlock* block, bool force);
/// Called by base GFXDevice to actually set a const buffer
virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer);
virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture);
virtual void setCubemapInternal(U32 textureUnit, const GFXGLCubemap* texture);
virtual void setCubemapArrayInternal(U32 textureUnit, const GFXGLCubemapArray* texture);
virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable);
virtual void setLightMaterialInternal(const GFXLightMaterial mat);
virtual void setGlobalAmbientInternal(LinearColorF color);
/// @name State Initalization.
/// @{
/// State initalization. This MUST BE CALLED in setVideoMode after the device
/// is created.
virtual void initStates() { }
virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat );
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType,
void* data = NULL);
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void* data = NULL );
// NOTE: The GL device doesn't need a vertex declaration at
// this time, but we need to return something to keep the system
// from retrying to allocate one on every call.
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat );
virtual void setVertexDecl( const GFXVertexDecl *decl );
virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer );
virtual void setVertexStreamFrequency( U32 stream, U32 frequency );
private:
typedef GFXDevice Parent;
friend class GFXGLTextureObject;
friend class GFXGLCubemap;
friend class GFXGLCubemapArray;
friend class GFXGLWindowTarget;
friend class GFXGLPrimitiveBuffer;
friend class GFXGLVertexBuffer;
static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
U32 mAdapterIndex;
StrongRefPtr<GFXGLVertexBuffer> mCurrentVB[VERTEX_STREAM_COUNT];
U32 mCurrentVB_Divisor[VERTEX_STREAM_COUNT];
bool mNeedUpdateVertexAttrib;
StrongRefPtr<GFXGLPrimitiveBuffer> mCurrentPB;
U32 mDrawInstancesCount;
GFXShader* mCurrentShader;
GFXShaderRef mGenericShader[GS_COUNT];
GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT];
GFXShaderConstHandle *mModelViewProjSC[GS_COUNT];
/// Since GL does not have separate world and view matrices we need to track them
MatrixF m_mCurrentWorld;
MatrixF m_mCurrentView;
void* mContext;
void* mPixelFormat;
F32 mPixelShaderVersion;
bool mSupportsAnisotropic;
U32 mNumVertexStream;
U32 mMaxShaderTextures;
U32 mMaxFFTextures;
U32 mMaxTRColors;
RectI mClip;
GFXGLStateBlockRef mCurrentGLStateBlock;
GLenum mActiveTextureType[TEXTURE_STAGE_COUNT];
Vector< StrongRefPtr<GFXGLVertexBuffer> > mVolatileVBs; ///< Pool of existing volatile VBs so we can reuse previously created ones
Vector< StrongRefPtr<GFXGLPrimitiveBuffer> > mVolatilePBs; ///< Pool of existing volatile PBs so we can reuse previously created ones
GLsizei primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount);
void preDrawPrimitive();
void postDrawPrimitive(U32 primitiveCount);
GFXVertexBuffer* findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize); ///< Returns an existing volatile VB which has >= numVerts and the same vert flags/size, or creates a new VB if necessary
GFXPrimitiveBuffer* findVolatilePBO(U32 numIndices, U32 numPrimitives); ///< Returns an existing volatile PB which has >= numIndices, or creates a new PB if necessary
void vsyncCallback(); ///< Vsync callback
void initGLState(); ///< Guaranteed to be called after all extensions have been loaded, use to init card profiler, shader version, max samplers, etc.
GFXFence* _createPlatformSpecificFence(); ///< If our platform (e.g. OS X) supports a fence extenstion (e.g. GL_APPLE_fence) this will create one, otherwise returns NULL
void setPB(GFXGLPrimitiveBuffer* pb); ///< Sets mCurrentPB
GFXGLStateCache *mOpenglStateCache;
GFXWindowTargetRef *mWindowRT;
bool mUseGlMap;
};
#define GFXGL static_cast<GFXGLDevice*>(GFXDevice::get())
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,141 +0,0 @@
#ifndef GFX_GL_STATE_CACHE
#define GFX_GL_STATE_CACHE
/// GFXGLStateCache store OpenGL state to avoid performance penalities of glGet* calls
/// GL_TEXTURE_1D/2D/3D, GL_FRAMEBUFFER, GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER
class GFXGLStateCache
{
public:
GFXGLStateCache()
{
mActiveTexture = 0;
mBindedVBO = 0;
mBindedIBO = 0;
mBindedFBO_W = 0;
mBindedFBO_R = 0;
mVertexAttribActive = 0;
}
class TextureUnit
{
public:
TextureUnit() : mTexture1D(0), mTexture2D(0), mTexture3D(0), mTextureCube(0), mTextureCubeArray(0)
{
}
GLuint mTexture1D, mTexture2D, mTexture3D, mTextureCube, mTextureCubeArray;
};
/// after glBindTexture
void setCacheBindedTex(U32 texUnit, GLenum biding, GLuint handle)
{
mActiveTexture = texUnit;
switch (biding)
{
case GL_TEXTURE_2D:
mTextureUnits[mActiveTexture].mTexture2D = handle;
break;
case GL_TEXTURE_3D:
mTextureUnits[mActiveTexture].mTexture3D = handle;
break;
case GL_TEXTURE_1D:
mTextureUnits[mActiveTexture].mTexture1D = handle;
break;
case GL_TEXTURE_CUBE_MAP:
mTextureUnits[mActiveTexture].mTextureCube = handle;
break;
case GL_TEXTURE_CUBE_MAP_ARRAY:
mTextureUnits[mActiveTexture].mTextureCubeArray = handle;
break;
default:
AssertFatal(0, avar("GFXGLStateCache::setCacheBindedTex - binding (%x) not supported.", biding) );
return;
}
}
/// after opengl object binded
void setCacheBinded(GLenum biding, GLuint handle)
{
switch (biding)
{
case GL_TEXTURE_2D:
mTextureUnits[mActiveTexture].mTexture2D = handle;
break;
case GL_TEXTURE_3D:
mTextureUnits[mActiveTexture].mTexture3D = handle;
break;
case GL_TEXTURE_1D:
mTextureUnits[mActiveTexture].mTexture1D = handle;
break;
case GL_TEXTURE_CUBE_MAP:
mTextureUnits[mActiveTexture].mTextureCube = handle;
break;
case GL_TEXTURE_CUBE_MAP_ARRAY:
mTextureUnits[mActiveTexture].mTextureCubeArray = handle;
break;
case GL_FRAMEBUFFER:
mBindedFBO_W = mBindedFBO_R = handle;
break;
case GL_DRAW_FRAMEBUFFER:
mBindedFBO_W = handle;
break;
case GL_READ_FRAMEBUFFER:
mBindedFBO_R = handle;
break;
case GL_ARRAY_BUFFER:
mBindedVBO = handle;
break;
case GL_ELEMENT_ARRAY_BUFFER:
mBindedIBO = handle;
break;
default:
AssertFatal(0, avar("GFXGLStateCache::setCacheBinded - binding (%x) not supported.", biding) );
break;
}
}
GLuint getCacheBinded(GLenum biding) const
{
switch (biding)
{
case GL_TEXTURE_2D:
return mTextureUnits[mActiveTexture].mTexture2D;
case GL_TEXTURE_3D:
return mTextureUnits[mActiveTexture].mTexture3D;
case GL_TEXTURE_1D:
return mTextureUnits[mActiveTexture].mTexture1D;
case GL_TEXTURE_CUBE_MAP:
return mTextureUnits[mActiveTexture].mTextureCube;
case GL_TEXTURE_CUBE_MAP_ARRAY:
return mTextureUnits[mActiveTexture].mTextureCubeArray;
case GL_DRAW_FRAMEBUFFER:
return mBindedFBO_W;
case GL_READ_FRAMEBUFFER:
return mBindedFBO_R;
case GL_ARRAY_BUFFER:
return mBindedVBO;
case GL_ELEMENT_ARRAY_BUFFER:
return mBindedIBO;
default:
AssertFatal(0, avar("GFXGLStateCache::getCacheBinded - binding (%x) not supported.", biding) );
return 0;
}
}
/// after glActiveTexture
void setCacheActiveTexture(U32 unit) { mActiveTexture = unit; }
U32 getCacheActiveTexture() const { return mActiveTexture; }
/// for cache glEnableVertexAttribArray / glDisableVertexAttribArray
void setCacheVertexAttribActive(U32 activeMask) { mVertexAttribActive = activeMask; }
U32 getCacheVertexAttribActive() const { return mVertexAttribActive; }
protected:
GLuint mActiveTexture, mBindedVBO, mBindedIBO, mBindedFBO_W, mBindedFBO_R;
TextureUnit mTextureUnits[TEXTURE_STAGE_COUNT];
U32 mVertexAttribActive;
};
#endif

View file

@ -1,244 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef TORQUE_GFX_GL_GFXGLUTILS_H_
#define TORQUE_GFX_GL_GFXGLUTILS_H_
#include "core/util/preprocessorHelpers.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLStateCache.h"
#include "gfx/bitmap/imageUtils.h"
inline U32 getMaxMipmaps(U32 width, U32 height, U32 depth)
{
return getMax( getBinLog2(depth), getMax(getBinLog2(width), getBinLog2(height)));
}
inline GLenum minificationFilter(U32 minFilter, U32 mipFilter, U32 /*mipLevels*/)
{
// the compiler should interpret this as array lookups
switch( minFilter )
{
case GFXTextureFilterLinear:
switch( mipFilter )
{
case GFXTextureFilterLinear:
return GL_LINEAR_MIPMAP_LINEAR;
case GFXTextureFilterPoint:
return GL_LINEAR_MIPMAP_NEAREST;
default:
return GL_LINEAR;
}
default:
switch( mipFilter ) {
case GFXTextureFilterLinear:
return GL_NEAREST_MIPMAP_LINEAR;
case GFXTextureFilterPoint:
return GL_NEAREST_MIPMAP_NEAREST;
default:
return GL_NEAREST;
}
}
}
//Get the surface size of a compressed mip map level - see ddsLoader.cpp
inline U32 getCompressedSurfaceSize(GFXFormat format,U32 width, U32 height, U32 mipLevel=0 )
{
if(!ImageUtil::isCompressedFormat(format))
return 0;
// Bump by the mip level.
height = getMax(U32(1), height >> mipLevel);
width = getMax(U32(1), width >> mipLevel);
U32 sizeMultiple = 0;
if(format == GFXFormatBC1 || format == GFXFormatBC1_SRGB)
sizeMultiple = 8;
else
sizeMultiple = 16;
return getMax(U32(1), width/4) * getMax(U32(1), height/4) * sizeMultiple;
}
/// Simple class which preserves a given GL integer.
/// This class determines the integer to preserve on construction and restores
/// it on destruction.
class GFXGLPreserveInteger
{
public:
typedef void(STDCALL *BindFn)(GLenum, GLuint);
/// Preserve the integer.
/// @param binding The binding which should be set on destruction.
/// @param getBinding The parameter to be passed to glGetIntegerv to determine
/// the integer to be preserved.
/// @param binder The gl function to call to restore the integer.
GFXGLPreserveInteger(GLenum binding, GLint getBinding, BindFn binder) :
mBinding(binding), mPreserved(0), mBinder(binder)
{
AssertFatal(mBinder, "GFXGLPreserveInteger - Need a valid binder function");
mPreserved = GFXGL->getOpenglCache()->getCacheBinded(mBinding);
#if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
GLint bindedOnOpenglDriver;
glGetIntegerv(getBinding, &bindedOnOpenglDriver);
AssertFatal( mPreserved == bindedOnOpenglDriver, "GFXGLPreserveInteger - GFXGLDevice/OpenGL mismatch on cache binded resource.");
#endif
}
/// Restores the integer.
~GFXGLPreserveInteger()
{
mBinder(mBinding, mPreserved);
}
private:
GLenum mBinding;
GLint mPreserved;
BindFn mBinder;
};
class GFXGLPreserveTexture
{
public:
typedef void(STDCALL *BindFn)(GLenum, GLuint);
GFXGLPreserveTexture(GLenum binding, GLint getBinding, BindFn binder) :
mBinding(binding), mPreserved(0), mBinder(binder)
{
AssertFatal(mBinder, "GFXGLPreserveTexture - Need a valid binder function");
GFXGLDevice *gfx = GFXGL;
mPreserved = gfx->getOpenglCache()->getCacheBinded(mBinding);
mActiveTexture = gfx->getOpenglCache()->getCacheActiveTexture();
#if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
GLint activeTextureOnOpenglDriver, bindedTextureOnOpenglDriver;
glGetIntegerv(getBinding, &bindedTextureOnOpenglDriver);
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTextureOnOpenglDriver);
activeTextureOnOpenglDriver -= GL_TEXTURE0;
AssertFatal( mPreserved == bindedTextureOnOpenglDriver, "GFXGLPreserveTexture - GFXGLDevice/OpenGL mismatch on cache binded resource.");
AssertFatal( activeTextureOnOpenglDriver == mActiveTexture, "GFXGLPreserveTexture - GFXGLDevice/OpenGL mismatch on cache binded resource.");
#endif
}
/// Restores the texture.
~GFXGLPreserveTexture()
{
#if defined(TORQUE_DEBUG) && defined(TORQUE_DEBUG_GFX)
GLint activeTextureOnOpenglDriver;
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTextureOnOpenglDriver);
activeTextureOnOpenglDriver -= GL_TEXTURE0;
GLint cacheActiveTexture = GFXGL->getOpenglCache()->getCacheActiveTexture();
AssertFatal( cacheActiveTexture == activeTextureOnOpenglDriver, "GFXGLPreserveTexture - GFXGLDevice/OpenGL mismatch on cache ActiveTexture.");
#endif
mBinder(mBinding, mPreserved);
}
private:
GLenum mBinding;
GLint mPreserved;
BindFn mBinder;
S16 mActiveTexture;
};
/// Helper macro to preserve the current VBO binding.
#define PRESERVE_VERTEX_BUFFER() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_ARRAY_BUFFER, GL_ARRAY_BUFFER_BINDING, (GFXGLPreserveInteger::BindFn)glBindBuffer)
/// Helper macro to preserve the current element array binding.
#define PRESERVE_INDEX_BUFFER() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_ELEMENT_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER_BINDING, (GFXGLPreserveInteger::BindFn)glBindBuffer)
#define _GET_BUFFER_BINDING( BINDING ) \
BINDING == GL_ARRAY_BUFFER ? GL_ARRAY_BUFFER_BINDING : ( BINDING == GL_ELEMENT_ARRAY_BUFFER ? GL_ELEMENT_ARRAY_BUFFER_BINDING : 0 )
/// Helper macro to preserve the current element array binding.
#define PRESERVE_BUFFER( BINDING ) \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (BINDING, _GET_BUFFER_BINDING(BINDING), (GFXGLPreserveInteger::BindFn)glBindBuffer)
/// ASSERT: Never call glActiveTexture for a "bind to modify" or in a PRESERVER_TEXTURE MACRO scope.
/// Helper macro to preserve the current 1D texture binding.
#define PRESERVE_1D_TEXTURE() \
GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_1D, GL_TEXTURE_BINDING_1D, (GFXGLPreserveInteger::BindFn)glBindTexture)
/// Helper macro to preserve the current 2D texture binding.
#define PRESERVE_2D_TEXTURE() \
GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D, (GFXGLPreserveInteger::BindFn)glBindTexture)
/// Helper macro to preserve the current 3D texture binding.
#define PRESERVE_3D_TEXTURE() \
GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_3D, GL_TEXTURE_BINDING_3D, (GFXGLPreserveInteger::BindFn)glBindTexture)
/// Helper macro to preserve the current 3D texture binding.
#define PRESERVE_CUBEMAP_TEXTURE() \
GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BINDING_CUBE_MAP, (GFXGLPreserveInteger::BindFn)glBindTexture)
#define PRESERVE_CUBEMAP_ARRAY_TEXTURE() \
GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, (GFXGLPreserveInteger::BindFn)glBindTexture)
#define _GET_TEXTURE_BINDING(binding) \
binding == GL_TEXTURE_2D ? GL_TEXTURE_BINDING_2D : (binding == GL_TEXTURE_3D ? GL_TEXTURE_BINDING_3D : GL_TEXTURE_BINDING_1D )
#define PRESERVE_TEXTURE(binding) \
GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (binding, _GET_TEXTURE_BINDING(binding), (GFXGLPreserveInteger::BindFn)glBindTexture)
#define PRESERVE_FRAMEBUFFER() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_READ_FRAMEBUFFER, GL_READ_FRAMEBUFFER_BINDING, (GFXGLPreserveInteger::BindFn)glBindFramebuffer);\
GFXGLPreserveInteger TORQUE_CONCAT(preserve2_, __LINE__) (GL_DRAW_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER_BINDING, (GFXGLPreserveInteger::BindFn)glBindFramebuffer)
#if TORQUE_DEBUG
// Handy macro for checking the status of a framebuffer. Framebuffers can fail in
// all sorts of interesting ways, these are just the most common. Further, no existing GL profiling
// tool catches framebuffer errors when the framebuffer is created, so we actually need this.
#define CHECK_FRAMEBUFFER_STATUS()\
{\
GLenum status;\
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);\
switch(status) {\
case GL_FRAMEBUFFER_COMPLETE:\
break;\
case GL_FRAMEBUFFER_UNSUPPORTED:\
AssertFatal(false, "Unsupported FBO");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\
AssertFatal(false, "Incomplete FBO Attachment");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\
AssertFatal(false, "Incomplete FBO Missing Attachment");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:\
AssertFatal(false, "Incomplete FBO Draw buffer");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:\
AssertFatal(false, "Incomplete FBO Read buffer");\
break;\
default:\
/* programming error; will fail on all hardware */\
AssertFatal(false, "Something really bad happened with an FBO");\
}\
}
#else
#define CHECK_FRAMEBUFFER_STATUS()
#endif //TORQUE_DEBUG
#endif