mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-06 14:00:39 +00:00
GL work
This commit is contained in:
parent
ec9e8c3563
commit
95962cbcbc
21 changed files with 4102 additions and 108 deletions
|
|
@ -31,7 +31,7 @@
|
|||
#include "gfx/bitmap/imageUtils.h"
|
||||
|
||||
|
||||
GLenum GFXGLCubemap::faceList[6] =
|
||||
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,
|
||||
|
|
@ -55,6 +55,11 @@ GFXGLCubemap::~GFXGLCubemap()
|
|||
GFXTextureManager::removeEventDelegate( this, &GFXGLCubemap::_onTextureEvent );
|
||||
}
|
||||
|
||||
GLenum GFXGLCubemap::getEnumForFaceNumber(U32 face)
|
||||
{
|
||||
return faceList[face];
|
||||
}
|
||||
|
||||
void GFXGLCubemap::fillCubeTextures(GFXTexHandle* faces)
|
||||
{
|
||||
AssertFatal( faces, "");
|
||||
|
|
@ -280,3 +285,225 @@ void GFXGLCubemap::_onTextureEvent( GFXTexCallbackCode code )
|
|||
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);
|
||||
}
|
||||
|
||||
//TODO: really need a common private 'init' function to avoid code double up with these init* functions
|
||||
void GFXGLCubemapArray::init(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++)
|
||||
//U32 currentMip = 0;
|
||||
{
|
||||
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
|
||||
{*/ //TODO figure out xyzOffsets
|
||||
glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, 0, mipSize, mipSize, i * face, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
|
||||
//}
|
||||
delete[] pixelData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Just allocate the cubemap array but we don't upload any data
|
||||
void GFXGLCubemapArray::init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format)
|
||||
{
|
||||
//all cubemaps must be the same size,format and number of mipmaps. Grab the details from the first cubemap
|
||||
mSize = cubemapFaceSize;
|
||||
mFormat = format;
|
||||
mMipMapLevels = ImageUtil::getMaxMipCount(cubemapFaceSize, cubemapFaceSize);
|
||||
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::updateTexture(const GFXCubemapHandle &cubemap, const U32 slot)
|
||||
{
|
||||
AssertFatal(slot <= mNumCubemaps, "GFXD3D11CubemapArray::updateTexture - trying to update a cubemap texture that is out of bounds!");
|
||||
|
||||
const bool isCompressed = ImageUtil::isCompressedFormat(mFormat);
|
||||
|
||||
GFXGLCubemap* glTex = static_cast<GFXGLCubemap*>(cubemap.getPointer());
|
||||
for (U32 face = 0; face < 6; face++)
|
||||
{
|
||||
for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++)
|
||||
//U32 currentMip = 0;
|
||||
{
|
||||
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
|
||||
{*/ //TODO figure out xyzOffsets
|
||||
glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, 0, mipSize, mipSize, slot * face, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
|
||||
//}
|
||||
delete[] pixelData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GFXGLCubemapArray::copyTo(GFXCubemapArray *pDstCubemap)
|
||||
{
|
||||
AssertFatal(pDstCubemap, "GFXGLCubemapArray::copyTo - Got null GFXCubemapArray");
|
||||
|
||||
const U32 dstCount = pDstCubemap->getNumCubemaps();
|
||||
const GFXFormat dstFmt = pDstCubemap->getFormat();
|
||||
const U32 dstSize = pDstCubemap->getSize();
|
||||
const U32 dstMips = pDstCubemap->getMipMapLevels();
|
||||
|
||||
AssertFatal(dstCount > mNumCubemaps, "GFXGLCubemapArray::copyTo - Destination too small");
|
||||
AssertFatal(dstFmt == mFormat, "GFXGLCubemapArray::copyTo - Destination format doesn't match");
|
||||
AssertFatal(dstSize == mSize, "GFXGLCubemapArray::copyTo - Destination size doesn't match");
|
||||
AssertFatal(dstMips == mMipMapLevels, "GFXGLCubemapArray::copyTo - Destination mip levels doesn't match");
|
||||
|
||||
GFXGLCubemapArray* pDstCube = static_cast<GFXGLCubemapArray*>(pDstCubemap);
|
||||
|
||||
for (U32 cubeMap = 0; cubeMap < mNumCubemaps; cubeMap++)
|
||||
{
|
||||
for (U32 face = 0; face < CubeFaces; face++)
|
||||
{
|
||||
for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++)
|
||||
//U32 currentMip = 0;
|
||||
{
|
||||
//U8 *pixelData = pDstCube->get->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
|
||||
{*/ //TODO figure out xyzOffsets
|
||||
glCopyImageSubData(mCubemap, GL_TEXTURE_CUBE_MAP_ARRAY, cubeMap * face, 0, 0, 0, pDstCube->mCubemap, GL_TEXTURE_CUBE_MAP_ARRAY, cubeMap * face, 0, 0, 0, mipSize, mipSize, 6);
|
||||
//glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
|
||||
//glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, 0, mipSize, mipSize, CubeFaces, 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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@
|
|||
#include "core/resource.h"
|
||||
#endif
|
||||
|
||||
const U32 CubeFaces = 6;
|
||||
const U32 MaxMipMaps = 13; //todo this needs a proper static value somewhere to sync up with other classes like GBitmap
|
||||
|
||||
|
||||
class GFXGLCubemap : public GFXCubemap
|
||||
{
|
||||
|
|
@ -55,7 +58,11 @@ public:
|
|||
/// 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) { return faceList[face]; } ///< Performs lookup to get a GLenum for the given face number
|
||||
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:
|
||||
|
||||
|
|
@ -85,7 +92,29 @@ protected:
|
|||
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
|
||||
|
||||
static GLenum faceList[6]; ///< Lookup table
|
||||
};
|
||||
|
||||
class GFXGLCubemapArray : public GFXCubemapArray
|
||||
{
|
||||
public:
|
||||
GFXGLCubemapArray();
|
||||
virtual ~GFXGLCubemapArray();
|
||||
//virtual void initStatic(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
|
||||
virtual void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
|
||||
virtual void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format);
|
||||
virtual void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot);
|
||||
virtual void copyTo(GFXCubemapArray *pDstCubemap);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -448,6 +448,13 @@ GFXCubemap* GFXGLDevice::createCubemap()
|
|||
return cube;
|
||||
};
|
||||
|
||||
GFXCubemapArray *GFXGLDevice::createCubemapArray()
|
||||
{
|
||||
GFXGLCubemapArray* cubeArray = new GFXGLCubemapArray();
|
||||
cubeArray->registerResourceWithDevice(this);
|
||||
return cubeArray;
|
||||
}
|
||||
|
||||
void GFXGLDevice::endSceneInternal()
|
||||
{
|
||||
// nothing to do for opengl
|
||||
|
|
@ -675,6 +682,22 @@ void GFXGLDevice::setCubemapInternal(U32 textureUnit, const GFXGLCubemap* textur
|
|||
}
|
||||
}
|
||||
|
||||
void GFXGLDevice::setCubemapArrayInternal(U32 textureUnit, const GFXGLCubemapArray* texture)
|
||||
{
|
||||
if (texture)
|
||||
{
|
||||
mActiveTextureType[textureUnit] = GL_TEXTURE_CUBE_MAP_ARRAY;
|
||||
texture->bind(textureUnit);
|
||||
}
|
||||
else if (mActiveTextureType[textureUnit] != GL_ZERO)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
||||
glBindTexture(mActiveTextureType[textureUnit], 0);
|
||||
getOpenglCache()->setCacheBindedTex(textureUnit, mActiveTextureType[textureUnit], 0);
|
||||
mActiveTextureType[textureUnit] = GL_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
void GFXGLDevice::setMatrix( GFXMatrixType mtype, const MatrixF &mat )
|
||||
{
|
||||
// ONLY NEEDED ON FFP
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class GFXGLVertexBuffer;
|
|||
class GFXGLPrimitiveBuffer;
|
||||
class GFXGLTextureTarget;
|
||||
class GFXGLCubemap;
|
||||
class GFXGLCubemapArray;
|
||||
class GFXGLStateCache;
|
||||
class GFXGLVertexDecl;
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ public:
|
|||
virtual U32 getTotalVideoMemory();
|
||||
|
||||
virtual GFXCubemap * createCubemap();
|
||||
virtual GFXCubemapArray *createCubemapArray() { return NULL; } //TODO: implement
|
||||
virtual GFXCubemapArray *createCubemapArray();
|
||||
|
||||
virtual F32 getFillConventionOffset() const { return 0.0f; }
|
||||
|
||||
|
|
@ -170,7 +171,8 @@ protected:
|
|||
virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer);
|
||||
|
||||
virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture);
|
||||
virtual void setCubemapInternal(U32 cubemap, const GFXGLCubemap* 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);
|
||||
|
|
@ -207,11 +209,12 @@ private:
|
|||
|
||||
friend class GFXGLTextureObject;
|
||||
friend class GFXGLCubemap;
|
||||
friend class GFXGLCubemapArray;
|
||||
friend class GFXGLWindowTarget;
|
||||
friend class GFXGLPrimitiveBuffer;
|
||||
friend class GFXGLVertexBuffer;
|
||||
|
||||
static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
|
||||
static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
|
||||
|
||||
U32 mAdapterIndex;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ static U32 shaderConstTypeSize(GFXShaderConstType type)
|
|||
case GFXSCT_Int:
|
||||
case GFXSCT_Sampler:
|
||||
case GFXSCT_SamplerCube:
|
||||
case GFXSCT_SamplerCubeArray:
|
||||
return 4;
|
||||
case GFXSCT_Float2:
|
||||
case GFXSCT_Int2:
|
||||
|
|
@ -625,6 +626,9 @@ void GFXGLShader::initConstantDescs()
|
|||
case GL_SAMPLER_CUBE:
|
||||
desc.constType = GFXSCT_SamplerCube;
|
||||
break;
|
||||
case GL_SAMPLER_CUBE_MAP_ARRAY:
|
||||
desc.constType = GFXSCT_SamplerCubeArray;
|
||||
break;
|
||||
default:
|
||||
AssertFatal(false, "GFXGLShader::initConstantDescs - unrecognized uniform type");
|
||||
// If we don't recognize the constant don't add its description.
|
||||
|
|
@ -656,7 +660,7 @@ void GFXGLShader::initHandles()
|
|||
|
||||
HandleMap::Iterator handle = mHandles.find(desc.name);
|
||||
S32 sampler = -1;
|
||||
if(desc.constType == GFXSCT_Sampler || desc.constType == GFXSCT_SamplerCube)
|
||||
if(desc.constType == GFXSCT_Sampler || desc.constType == GFXSCT_SamplerCube || desc.constType == GFXSCT_SamplerCubeArray)
|
||||
{
|
||||
S32 idx = mSamplerNamesOrdered.find_next(desc.name);
|
||||
AssertFatal(idx != -1, "");
|
||||
|
|
@ -699,7 +703,7 @@ void GFXGLShader::initHandles()
|
|||
for (HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter)
|
||||
{
|
||||
GFXGLShaderConstHandle* handle = iter->value;
|
||||
if(handle->isValid() && (handle->getType() == GFXSCT_Sampler || handle->getType() == GFXSCT_SamplerCube))
|
||||
if(handle->isValid() && (handle->getType() == GFXSCT_Sampler || handle->getType() == GFXSCT_SamplerCube || handle->getType() == GFXSCT_SamplerCubeArray))
|
||||
{
|
||||
// Set sampler number on our program.
|
||||
glUniform1i(handle->mLocation, handle->mSamplerNum);
|
||||
|
|
@ -831,6 +835,7 @@ void GFXGLShader::setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer)
|
|||
case GFXSCT_Int:
|
||||
case GFXSCT_Sampler:
|
||||
case GFXSCT_SamplerCube:
|
||||
case GFXSCT_SamplerCubeArray:
|
||||
glUniform1iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
|
||||
break;
|
||||
case GFXSCT_Int2:
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ public:
|
|||
class TextureUnit
|
||||
{
|
||||
public:
|
||||
TextureUnit() : mTexture1D(0), mTexture2D(0), mTexture3D(0), mTextureCube(0)
|
||||
TextureUnit() : mTexture1D(0), mTexture2D(0), mTexture3D(0), mTextureCube(0), mTextureCubeArray(0)
|
||||
{
|
||||
|
||||
}
|
||||
GLuint mTexture1D, mTexture2D, mTexture3D, mTextureCube;
|
||||
GLuint mTexture1D, mTexture2D, mTexture3D, mTextureCube, mTextureCubeArray;
|
||||
};
|
||||
|
||||
/// after glBindTexture
|
||||
|
|
@ -45,6 +45,9 @@ public:
|
|||
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;
|
||||
|
|
@ -68,6 +71,9 @@ public:
|
|||
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;
|
||||
|
|
@ -101,6 +107,8 @@ public:
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -191,6 +191,9 @@ GFXGLPreserveTexture TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_3D, GL_TEXTU
|
|||
#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 )
|
||||
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ void RenderProbeMgr::_setupStaticParameters()
|
|||
if (!curEntry.mIsEnabled)
|
||||
continue;
|
||||
|
||||
if (curEntry.mIsSkylight)
|
||||
if (curEntry.mProbeShapeType == ProbeRenderInst::ProbeShapeType::Skylight || curEntry.mIsSkylight)
|
||||
{
|
||||
skylightPos = curEntry.getPosition();
|
||||
skylightPrefilterMap = curEntry.mPrefilterCubemap;
|
||||
|
|
@ -680,11 +680,13 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
{
|
||||
if (curEntry.mPrefilterCubemap.isValid() && curEntry.mPrefilterCubemap.isValid())
|
||||
{
|
||||
U32 specSample = probeShaderConsts->mSkylightSpecularMap->getSamplerRegister();
|
||||
U32 irradSample = probeShaderConsts->mSkylightIrradMap->getSamplerRegister();
|
||||
S32 specSample = probeShaderConsts->mSkylightSpecularMap->getSamplerRegister();
|
||||
if (specSample != -1)
|
||||
GFX->setCubeTexture(specSample, curEntry.mPrefilterCubemap);
|
||||
|
||||
GFX->setCubeTexture(probeShaderConsts->mSkylightSpecularMap->getSamplerRegister(), curEntry.mPrefilterCubemap);
|
||||
GFX->setCubeTexture(probeShaderConsts->mSkylightIrradMap->getSamplerRegister(), curEntry.mIrradianceCubemap);
|
||||
S32 irradSample = probeShaderConsts->mSkylightIrradMap->getSamplerRegister();
|
||||
if (irradSample != -1)
|
||||
GFX->setCubeTexture(irradSample, curEntry.mIrradianceCubemap);
|
||||
|
||||
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 1.0f);
|
||||
hasSkylight = true;
|
||||
|
|
@ -718,8 +720,13 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
|
|||
shaderConsts->setSafe(probeShaderConsts->mProbeBoxMaxSC, probeBoxMaxArray);
|
||||
shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataSC, probeConfigArray);
|
||||
|
||||
GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray);
|
||||
GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray);
|
||||
S32 specSample = probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister();
|
||||
if (specSample != -1)
|
||||
GFX->setCubeArrayTexture(specSample, mPrefilterArray);
|
||||
|
||||
S32 irradSample = probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister();
|
||||
if (irradSample != -1)
|
||||
GFX->setCubeArrayTexture(irradSample, mIrradianceArray);
|
||||
|
||||
if (!hasSkylight)
|
||||
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 0.0f);
|
||||
|
|
@ -779,8 +786,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
//updateProbes();
|
||||
|
||||
// Early out if nothing to draw.
|
||||
if (!ProbeRenderInst::all.size() || !RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (mEffectiveProbeCount == 0
|
||||
|| mCubeMapCount != 0 && !hasSkylight))
|
||||
if (!RenderProbeMgr::smRenderReflectionProbes || !state->isDiffusePass() || (!ProbeRenderInst::all.size() || mEffectiveProbeCount == 0 || mCubeMapCount != 0 ) && !hasSkylight)
|
||||
{
|
||||
getProbeArrayEffect()->setSkip(true);
|
||||
return;
|
||||
|
|
@ -793,6 +799,19 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
// Initialize and set the per-frame parameters after getting
|
||||
// the vector light material as we use lazy creation.
|
||||
//_setupPerFrameParameters(state);
|
||||
|
||||
//Visualization
|
||||
String useDebugAtten = Con::getVariable("$Probes::showAttenuation", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_ATTENUATION", useDebugAtten);
|
||||
|
||||
String useDebugSpecCubemap = Con::getVariable("$Probes::showSpecularCubemaps", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_SPECCUBEMAP", useDebugSpecCubemap);
|
||||
|
||||
String useDebugDiffuseCubemap = Con::getVariable("$Probes::showDiffuseCubemaps", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_DIFFCUBEMAP", useDebugDiffuseCubemap);
|
||||
|
||||
String useDebugContrib = Con::getVariable("$Probes::showProbeContrib", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_CONTRIB", useDebugContrib);
|
||||
|
||||
//Array rendering
|
||||
//U32 probeCount = ProbeRenderInst::all.size();
|
||||
|
|
@ -804,23 +823,14 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
mProbeArrayEffect->setCubemapTexture(7, skylightIrradMap);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
||||
if (mEffectiveProbeCount != 0)
|
||||
{
|
||||
mProbeArrayEffect->setCubemapArrayTexture(4, mPrefilterArray);
|
||||
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
|
||||
|
||||
String useDebugAtten = Con::getVariable("$Probes::showAttenuation", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_ATTENUATION", useDebugAtten);
|
||||
|
||||
String useDebugSpecCubemap = Con::getVariable("$Probes::showSpecularCubemaps", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_SPECCUBEMAP", useDebugSpecCubemap);
|
||||
|
||||
String useDebugDiffuseCubemap = Con::getVariable("$Probes::showDiffuseCubemaps", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_DIFFCUBEMAP", useDebugDiffuseCubemap);
|
||||
|
||||
String useDebugContrib = Con::getVariable("$Probes::showProbeContrib", "0");
|
||||
mProbeArrayEffect->setShaderMacro("DEBUGVIZ_CONTRIB", useDebugContrib);
|
||||
|
||||
if (useDebugContrib == String("1"))
|
||||
{
|
||||
MRandomLCG RandomGen;
|
||||
|
|
@ -841,15 +851,12 @@ void RenderProbeMgr::render( SceneRenderState *state )
|
|||
else if (i == 2)
|
||||
contribColors[i] = Point4F(0, 0, 1, 1);
|
||||
else
|
||||
contribColors[i] = Point4F(RandomGen.randF(0, 1), RandomGen.randF(0, 1), RandomGen.randF(0, 1),1);
|
||||
contribColors[i] = Point4F(RandomGen.randF(0, 1), RandomGen.randF(0, 1), RandomGen.randF(0, 1), 1);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$probeContribColors", contribColors);
|
||||
}
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);
|
||||
|
||||
mProbeArrayEffect->setShaderConst("$numProbes", (float)mEffectiveProbeCount);
|
||||
mProbeArrayEffect->setShaderConst("$inProbePosArray", probePositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$inRefPosArray", probeRefPositionsData);
|
||||
mProbeArrayEffect->setShaderConst("$worldToObjArray", probeWorldToObjData);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue