mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-22 04:45:31 +00:00
Core implementation of Physical Based Rendering.
This commit is contained in:
parent
54f1d8c18e
commit
b4a1d18f42
148 changed files with 4464 additions and 1016 deletions
|
|
@ -32,7 +32,8 @@
|
|||
|
||||
GFXD3D11OcclusionQuery::GFXD3D11OcclusionQuery(GFXDevice *device)
|
||||
: GFXOcclusionQuery(device),
|
||||
mQuery(NULL)
|
||||
mQuery(NULL),
|
||||
mTesting(false)
|
||||
{
|
||||
#ifdef TORQUE_GATHER_METRICS
|
||||
mTimer = PlatformTimer::create();
|
||||
|
|
@ -73,8 +74,11 @@ bool GFXD3D11OcclusionQuery::begin()
|
|||
AssertISV(hRes != E_OUTOFMEMORY, "GFXD3D11OcclusionQuery::begin - Out of memory");
|
||||
}
|
||||
|
||||
// Add a begin marker to the command buffer queue.
|
||||
D3D11DEVICECONTEXT->Begin(mQuery);
|
||||
if (!mTesting)
|
||||
{
|
||||
D3D11DEVICECONTEXT->Begin(mQuery);
|
||||
mTesting = true;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_GATHER_METRICS
|
||||
mBeginFrame = GuiTSCtrl::getFrameCount();
|
||||
|
|
@ -90,6 +94,7 @@ void GFXD3D11OcclusionQuery::end()
|
|||
|
||||
// Add an end marker to the command buffer queue.
|
||||
D3D11DEVICECONTEXT->End(mQuery);
|
||||
mTesting = false;
|
||||
|
||||
#ifdef TORQUE_GATHER_METRICS
|
||||
AssertFatal( mBeginFrame == GuiTSCtrl::getFrameCount(), "GFXD3D11OcclusionQuery::end - ended query on different frame than begin!" );
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class GFXD3D11OcclusionQuery : public GFXOcclusionQuery
|
|||
{
|
||||
private:
|
||||
mutable ID3D11Query *mQuery;
|
||||
|
||||
bool mTesting;
|
||||
#ifdef TORQUE_GATHER_METRICS
|
||||
U32 mBeginFrame;
|
||||
U32 mTimeSinceEnd;
|
||||
|
|
|
|||
336
Engine/source/gfx/bitmap/cubemapSaver.cpp
Normal file
336
Engine/source/gfx/bitmap/cubemapSaver.cpp
Normal file
|
|
@ -0,0 +1,336 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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/bitmap/cubemapSaver.h"
|
||||
#include "platform/platform.h"
|
||||
#include "gfx/bitmap/ddsFile.h"
|
||||
#include "gfx/bitmap/imageUtils.h"
|
||||
#include "gfx/gfxDevice.h"
|
||||
#include "gfx/gfxTransformSaver.h"
|
||||
#include "gfx/gfxTextureManager.h"
|
||||
#include "materials/shaderData.h"
|
||||
#include "core/stream/fileStream.h"
|
||||
#include "math/mathUtils.h"
|
||||
#include "math/mTransform.h"
|
||||
|
||||
|
||||
namespace CubemapSaver
|
||||
{
|
||||
const U32 CubeFaces = 6;
|
||||
|
||||
void _setConstBuffer(GFXShaderConstHandle* handle, GFXShaderConstBuffer *cbuf, const VectorF &vLookatPt, const VectorF &vUpVec)
|
||||
{
|
||||
VectorF cross = mCross(vUpVec, vLookatPt);
|
||||
cross.normalizeSafe();
|
||||
|
||||
MatrixF matView(true);
|
||||
matView.setColumn(0, cross);
|
||||
matView.setColumn(1, vLookatPt);
|
||||
matView.setColumn(2, vUpVec);
|
||||
matView.setPosition(VectorF(0.0f, 0.0f, 1.0f));
|
||||
matView.inverse();
|
||||
|
||||
if (handle->isValid())
|
||||
cbuf->set(handle, matView);
|
||||
else
|
||||
Con::errorf("CubemapSaver: Failed to set a shader constant handle.");
|
||||
}
|
||||
|
||||
bool save(GFXCubemapHandle cubemap, const Torque::Path &path, GFXFormat compressionFormat)
|
||||
{
|
||||
if (!cubemap.isValid())
|
||||
{
|
||||
Con::errorf("CubemapSaver: cubemap handle is not valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
// This can sometimes occur outside a begin/end scene.
|
||||
const bool sceneBegun = GFX->canCurrentlyRender();
|
||||
if (!sceneBegun)
|
||||
GFX->beginScene();
|
||||
|
||||
GFXCubemap *pCubemap = cubemap.getPointer();
|
||||
U32 faceSize = pCubemap->getSize();
|
||||
|
||||
ShaderData *shaderData = nullptr;
|
||||
GFXShaderRef shader = Sim::findObject("CubemapSaveShader", shaderData) ? shaderData->getShader() : nullptr;
|
||||
if (!shader)
|
||||
{
|
||||
Con::errorf("CubemapSaver::save - could not find CubemapSaveShader");
|
||||
return false;
|
||||
}
|
||||
|
||||
GFXShaderConstHandle *matHandles[CubeFaces];
|
||||
|
||||
matHandles[0] = shader->getShaderConstHandle("$matrix0");
|
||||
matHandles[1] = shader->getShaderConstHandle("$matrix1");
|
||||
matHandles[2] = shader->getShaderConstHandle("$matrix2");
|
||||
matHandles[3] = shader->getShaderConstHandle("$matrix3");
|
||||
matHandles[4] = shader->getShaderConstHandle("$matrix4");
|
||||
matHandles[5] = shader->getShaderConstHandle("$matrix5");
|
||||
|
||||
GFXShaderConstBufferRef cbuffer = shader->allocConstBuffer();
|
||||
|
||||
GFXTextureTarget *pTarget = GFX->allocRenderToTextureTarget();
|
||||
GFX->pushActiveRenderTarget();
|
||||
|
||||
GFXFormat renderTargetFmt = GFXFormatR8G8B8A8;
|
||||
//setup render targets
|
||||
GFXTexHandle pTextures[CubeFaces];
|
||||
for (U32 i = 0; i < CubeFaces; i++)
|
||||
{
|
||||
pTextures[i].set(faceSize, faceSize, renderTargetFmt,
|
||||
&GFXRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
|
||||
pTarget->attachTexture(GFXTextureTarget::RenderSlot(GFXTextureTarget::Color0 + i), pTextures[i]);
|
||||
}
|
||||
|
||||
//create stateblock
|
||||
GFXStateBlockDesc desc;
|
||||
desc.setZReadWrite(false, false);
|
||||
desc.samplersDefined = true;
|
||||
desc.samplers[0].addressModeU = GFXAddressClamp;
|
||||
desc.samplers[0].addressModeV = GFXAddressClamp;
|
||||
desc.samplers[0].addressModeW = GFXAddressClamp;
|
||||
desc.samplers[0].magFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].minFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].mipFilter = GFXTextureFilterLinear;
|
||||
|
||||
//yep funky order and rotations with t3d z up
|
||||
_setConstBuffer(matHandles[0], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(-1.0f, 0.0f, 0.0f));
|
||||
_setConstBuffer(matHandles[1], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(1.0f, 0.0f, 0.0f));
|
||||
_setConstBuffer(matHandles[2], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(0.0f, 0.0f, -1.0f));
|
||||
_setConstBuffer(matHandles[3], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(0.0f, 0.0f, 1.0f));
|
||||
_setConstBuffer(matHandles[4], cbuffer, VectorF(0.0f, 0.0f, -1.0f), VectorF(0.0f, -1.0f, 0.0f));
|
||||
_setConstBuffer(matHandles[5], cbuffer, VectorF(0.0f, 0.0f, 1.0f), VectorF(0.0f, 1.0f, 0.0f));
|
||||
|
||||
GFXTransformSaver saver;
|
||||
GFX->setActiveRenderTarget(pTarget);
|
||||
GFX->clear(GFXClearTarget, ColorI(0, 0, 0, 0), 1.0f, 0);
|
||||
GFX->setStateBlockByDesc(desc);
|
||||
GFX->setWorldMatrix(MatrixF::Identity);
|
||||
GFX->setProjectionMatrix(MatrixF::Identity);
|
||||
GFX->setCubeTexture(0, pCubemap);
|
||||
GFX->setShaderConstBuffer(cbuffer);
|
||||
GFX->setShader(shader);
|
||||
GFX->drawPrimitive(GFXTriangleList, 0, 3);
|
||||
pTarget->resolve();
|
||||
|
||||
GBitmap *pBitmaps[CubeFaces];
|
||||
bool error = false;
|
||||
const bool compressedFormat = ImageUtil::isCompressedFormat(compressionFormat);
|
||||
for (U32 i = 0; i < CubeFaces; i++)
|
||||
{
|
||||
pBitmaps[i] = new GBitmap(faceSize, faceSize, false, renderTargetFmt);
|
||||
bool result = pTextures[i].copyToBmp(pBitmaps[i]);
|
||||
if (!result)
|
||||
{
|
||||
Con::errorf("CubemapSaver: cubemap number %u failed to copy", i);
|
||||
error = true;
|
||||
}
|
||||
//gen mip maps
|
||||
pBitmaps[i]->extrudeMipLevels();
|
||||
}
|
||||
|
||||
if (!error)
|
||||
{
|
||||
DDSFile *pDds = DDSFile::createDDSCubemapFileFromGBitmaps(pBitmaps);
|
||||
if (pDds)
|
||||
{
|
||||
// non compressed format needs swizzling
|
||||
if (!compressedFormat)
|
||||
ImageUtil::swizzleDDS(pDds, Swizzles::bgra);
|
||||
|
||||
if(compressedFormat)
|
||||
ImageUtil::ddsCompress(pDds, compressionFormat);
|
||||
|
||||
FileStream stream;
|
||||
stream.open(path, Torque::FS::File::Write);
|
||||
|
||||
if (stream.getStatus() == Stream::Ok)
|
||||
pDds->write(stream);
|
||||
else
|
||||
Con::errorf("CubemapSaver: failed to open file stream for file %s", path.getFullPath().c_str());
|
||||
|
||||
SAFE_DELETE(pDds);
|
||||
}
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < CubeFaces; i++)
|
||||
SAFE_DELETE(pBitmaps[i]);
|
||||
|
||||
//cleaup
|
||||
GFX->popActiveRenderTarget();
|
||||
GFX->setTexture(0, NULL);
|
||||
GFX->setShader(NULL);
|
||||
GFX->setShaderConstBuffer(NULL);
|
||||
GFX->setVertexBuffer(NULL);
|
||||
|
||||
// End it if we begun it.
|
||||
if (!sceneBegun)
|
||||
GFX->endScene();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getBitmaps(GFXCubemapHandle cubemap, GFXFormat compressionFormat, GBitmap* faceBitmaps[6])
|
||||
{
|
||||
if (!cubemap.isValid())
|
||||
{
|
||||
Con::errorf("CubemapSaver: cubemap handle is not valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
// This can sometimes occur outside a begin/end scene.
|
||||
const bool sceneBegun = GFX->canCurrentlyRender();
|
||||
if (!sceneBegun)
|
||||
GFX->beginScene();
|
||||
|
||||
GFXCubemap *pCubemap = cubemap.getPointer();
|
||||
U32 faceSize = pCubemap->getSize();
|
||||
|
||||
ShaderData *shaderData = nullptr;
|
||||
GFXShaderRef shader = Sim::findObject("CubemapSaveShader", shaderData) ? shaderData->getShader() : nullptr;
|
||||
if (!shader)
|
||||
{
|
||||
Con::errorf("CubemapSaver::save - could not find CubemapSaveShader");
|
||||
return false;
|
||||
}
|
||||
|
||||
GFXShaderConstHandle *matHandles[CubeFaces];
|
||||
|
||||
matHandles[0] = shader->getShaderConstHandle("$matrix0");
|
||||
matHandles[1] = shader->getShaderConstHandle("$matrix1");
|
||||
matHandles[2] = shader->getShaderConstHandle("$matrix2");
|
||||
matHandles[3] = shader->getShaderConstHandle("$matrix3");
|
||||
matHandles[4] = shader->getShaderConstHandle("$matrix4");
|
||||
matHandles[5] = shader->getShaderConstHandle("$matrix5");
|
||||
|
||||
GFXShaderConstBufferRef cbuffer = shader->allocConstBuffer();
|
||||
|
||||
GFXTextureTarget *pTarget = GFX->allocRenderToTextureTarget();
|
||||
GFX->pushActiveRenderTarget();
|
||||
|
||||
GFXFormat renderTargetFmt = GFXFormatR8G8B8A8;
|
||||
//setup render targets
|
||||
GFXTexHandle pTextures[CubeFaces];
|
||||
for (U32 i = 0; i < CubeFaces; i++)
|
||||
{
|
||||
pTextures[i].set(faceSize, faceSize, renderTargetFmt,
|
||||
&GFXRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__),
|
||||
1, GFXTextureManager::AA_MATCH_BACKBUFFER);
|
||||
|
||||
pTarget->attachTexture(GFXTextureTarget::RenderSlot(GFXTextureTarget::Color0 + i), pTextures[i]);
|
||||
}
|
||||
|
||||
//create stateblock
|
||||
GFXStateBlockDesc desc;
|
||||
desc.setZReadWrite(false, false);
|
||||
desc.samplersDefined = true;
|
||||
desc.samplers[0].addressModeU = GFXAddressClamp;
|
||||
desc.samplers[0].addressModeV = GFXAddressClamp;
|
||||
desc.samplers[0].addressModeW = GFXAddressClamp;
|
||||
desc.samplers[0].magFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].minFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].mipFilter = GFXTextureFilterLinear;
|
||||
|
||||
//yep funky order and rotations with t3d z up
|
||||
_setConstBuffer(matHandles[0], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(-1.0f, 0.0f, 0.0f));
|
||||
_setConstBuffer(matHandles[1], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(1.0f, 0.0f, 0.0f));
|
||||
_setConstBuffer(matHandles[2], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(0.0f, 0.0f, -1.0f));
|
||||
_setConstBuffer(matHandles[3], cbuffer, VectorF(0.0f, 1.0f, 0.0f), VectorF(0.0f, 0.0f, 1.0f));
|
||||
_setConstBuffer(matHandles[4], cbuffer, VectorF(0.0f, 0.0f, -1.0f), VectorF(0.0f, -1.0f, 0.0f));
|
||||
_setConstBuffer(matHandles[5], cbuffer, VectorF(0.0f, 0.0f, 1.0f), VectorF(0.0f, 1.0f, 0.0f));
|
||||
|
||||
GFXTransformSaver saver;
|
||||
GFX->setActiveRenderTarget(pTarget);
|
||||
GFX->clear(GFXClearTarget, ColorI(0, 0, 0, 0), 1.0f, 0);
|
||||
GFX->setStateBlockByDesc(desc);
|
||||
GFX->setWorldMatrix(MatrixF::Identity);
|
||||
GFX->setProjectionMatrix(MatrixF::Identity);
|
||||
GFX->setCubeTexture(0, pCubemap);
|
||||
GFX->setShaderConstBuffer(cbuffer);
|
||||
GFX->setShader(shader);
|
||||
GFX->drawPrimitive(GFXTriangleList, 0, 3);
|
||||
pTarget->resolve();
|
||||
|
||||
bool error = false;
|
||||
const bool compressedFormat = ImageUtil::isCompressedFormat(compressionFormat);
|
||||
for (U32 i = 0; i < CubeFaces; i++)
|
||||
{
|
||||
//faceBitmaps[i] = new GBitmap(faceSize, faceSize, false, renderTargetFmt);
|
||||
bool result = pTextures[i].copyToBmp(faceBitmaps[i]);
|
||||
if (!result)
|
||||
{
|
||||
Con::errorf("CubemapSaver: cubemap number %u failed to copy", i);
|
||||
error = true;
|
||||
}
|
||||
//gen mip maps
|
||||
faceBitmaps[i]->extrudeMipLevels();
|
||||
}
|
||||
|
||||
/*if (!error)
|
||||
{
|
||||
DDSFile *pDds = DDSFile::createDDSCubemapFileFromGBitmaps(pBitmaps);
|
||||
if (pDds)
|
||||
{
|
||||
// non compressed format needs swizzling
|
||||
if (!compressedFormat)
|
||||
ImageUtil::swizzleDDS(pDds, Swizzles::bgra);
|
||||
|
||||
if (compressedFormat)
|
||||
ImageUtil::ddsCompress(pDds, compressionFormat);
|
||||
|
||||
FileStream stream;
|
||||
stream.open(path, Torque::FS::File::Write);
|
||||
|
||||
if (stream.getStatus() == Stream::Ok)
|
||||
pDds->write(stream);
|
||||
else
|
||||
Con::errorf("CubemapSaver: failed to open file stream for file %s", path.getFullPath().c_str());
|
||||
|
||||
SAFE_DELETE(pDds);
|
||||
}
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < CubeFaces; i++)
|
||||
SAFE_DELETE(pBitmaps[i]);*/
|
||||
|
||||
//cleaup
|
||||
GFX->popActiveRenderTarget();
|
||||
GFX->setTexture(0, NULL);
|
||||
GFX->setShader(NULL);
|
||||
GFX->setShaderConstBuffer(NULL);
|
||||
GFX->setVertexBuffer(NULL);
|
||||
|
||||
// End it if we begun it.
|
||||
if (!sceneBegun)
|
||||
GFX->endScene();
|
||||
|
||||
if (error)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
41
Engine/source/gfx/bitmap/cubemapSaver.h
Normal file
41
Engine/source/gfx/bitmap/cubemapSaver.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2016 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 _CUBEMAP_SAVER_H_
|
||||
#define _CUBEMAP_SAVER_H_
|
||||
|
||||
#ifndef _GFXCUBEMAP_H_
|
||||
#include "gfx/gfxCubemap.h"
|
||||
#endif
|
||||
#ifndef __RESOURCE_H__
|
||||
#include "core/resource.h"
|
||||
#endif
|
||||
|
||||
namespace CubemapSaver
|
||||
{
|
||||
// save cubemap handle to a dds cubemap with optional compression
|
||||
bool save(GFXCubemapHandle cubemap, const Torque::Path &path, GFXFormat compressionFormat = GFXFormat_FIRST);
|
||||
|
||||
bool getBitmaps(GFXCubemapHandle cubemap, GFXFormat compressionFormat, GBitmap* faceBitmaps[6]);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -297,6 +297,7 @@ void GBitmap::allocateBitmap(const U32 in_width, const U32 in_height, const bool
|
|||
case GFXFormatR8G8B8X8:
|
||||
case GFXFormatR8G8B8A8: mBytesPerPixel = 4;
|
||||
break;
|
||||
case GFXFormatL16:
|
||||
case GFXFormatR5G6B5:
|
||||
case GFXFormatR5G5B5A1: mBytesPerPixel = 2;
|
||||
break;
|
||||
|
|
@ -371,6 +372,7 @@ void GBitmap::allocateBitmapWithMips(const U32 in_width, const U32 in_height, co
|
|||
case GFXFormatR8G8B8X8:
|
||||
case GFXFormatR8G8B8A8: mBytesPerPixel = 4;
|
||||
break;
|
||||
case GFXFormatL16:
|
||||
case GFXFormatR5G6B5:
|
||||
case GFXFormatR5G5B5A1: mBytesPerPixel = 2;
|
||||
break;
|
||||
|
|
@ -679,6 +681,7 @@ bool GBitmap::checkForTransparency()
|
|||
{
|
||||
// Non-transparent formats
|
||||
case GFXFormatL8:
|
||||
case GFXFormatL16:
|
||||
case GFXFormatR8G8B8:
|
||||
case GFXFormatR5G6B5:
|
||||
break;
|
||||
|
|
@ -754,7 +757,8 @@ bool GBitmap::getColor(const U32 x, const U32 y, ColorI& rColor) const
|
|||
case GFXFormatL8:
|
||||
rColor.set( *pLoc, *pLoc, *pLoc, *pLoc );
|
||||
break;
|
||||
|
||||
case GFXFormatL16:
|
||||
rColor.set(U8(U16((pLoc[0] << 8) + pLoc[2])), 0, 0, 0);
|
||||
case GFXFormatR8G8B8:
|
||||
case GFXFormatR8G8B8X8:
|
||||
rColor.set( pLoc[0], pLoc[1], pLoc[2], 255 );
|
||||
|
|
@ -803,6 +807,10 @@ bool GBitmap::setColor(const U32 x, const U32 y, const ColorI& rColor)
|
|||
*pLoc = rColor.alpha;
|
||||
break;
|
||||
|
||||
case GFXFormatL16:
|
||||
dMemcpy(pLoc, &rColor, 2 * sizeof(U8));
|
||||
break;
|
||||
|
||||
case GFXFormatR8G8B8:
|
||||
dMemcpy( pLoc, &rColor, 3 * sizeof( U8 ) );
|
||||
break;
|
||||
|
|
@ -1122,6 +1130,7 @@ bool GBitmap::read(Stream& io_rStream)
|
|||
break;
|
||||
case GFXFormatR8G8B8A8: mBytesPerPixel = 4;
|
||||
break;
|
||||
case GFXFormatL16:
|
||||
case GFXFormatR5G6B5:
|
||||
case GFXFormatR5G5B5A1: mBytesPerPixel = 2;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ static bool sReadPNG(Stream &stream, GBitmap *bitmap)
|
|||
png_set_expand(png_ptr);
|
||||
|
||||
if (bit_depth == 16)
|
||||
format = GFXFormatR5G6B5;
|
||||
format = GFXFormatL16;
|
||||
else
|
||||
format = GFXFormatA8;
|
||||
}
|
||||
|
|
@ -276,7 +276,7 @@ static bool sReadPNG(Stream &stream, GBitmap *bitmap)
|
|||
AssertFatal(rowBytes == width * 4,
|
||||
"Error, our rowbytes are incorrect for this transform... (4)");
|
||||
}
|
||||
else if (format == GFXFormatR5G6B5)
|
||||
else if (format == GFXFormatL16)
|
||||
{
|
||||
AssertFatal(rowBytes == width * 2,
|
||||
"Error, our rowbytes are incorrect for this transform... (2)");
|
||||
|
|
|
|||
|
|
@ -809,7 +809,6 @@ public:
|
|||
virtual U32 getNumRenderTargets() const = 0;
|
||||
|
||||
virtual void setShader( GFXShader *shader, bool force = false ) {}
|
||||
virtual void disableShaders( bool force = false ) {} // TODO Remove when T3D 4.0
|
||||
|
||||
/// Set the buffer! (Actual set happens on the next draw call, just like textures, state blocks, etc)
|
||||
void setShaderConstBuffer(GFXShaderConstBuffer* buffer);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,11 @@ GFXTexHandle::GFXTexHandle( const String &texName, GFXTextureProfile *profile, c
|
|||
set( texName, profile, desc );
|
||||
}
|
||||
|
||||
GFXTexHandle::GFXTexHandle(const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc)
|
||||
{
|
||||
set(texNameR, texNameG, texNameB, texNameA, inputKey, profile, desc);
|
||||
}
|
||||
|
||||
bool GFXTexHandle::set( const String &texName, GFXTextureProfile *profile, const String &desc )
|
||||
{
|
||||
// Clear the existing texture first, so that
|
||||
|
|
@ -70,6 +75,24 @@ bool GFXTexHandle::set( const String &texName, GFXTextureProfile *profile, const
|
|||
return isValid();
|
||||
}
|
||||
|
||||
bool GFXTexHandle::set(const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc)
|
||||
{
|
||||
// Clear the existing texture first, so that
|
||||
// its memory is free for the new allocation.
|
||||
free();
|
||||
|
||||
// Create and set the new texture.
|
||||
AssertFatal( texNameR.isNotEmpty(), "Texture name is empty" );
|
||||
StrongObjectRef::set( TEXMGR->createCompositeTexture( texNameR, texNameG, texNameB, texNameA, inputKey, profile ) );
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
if ( getPointer() )
|
||||
getPointer()->mDebugDescription = desc;
|
||||
#endif
|
||||
|
||||
return isValid();
|
||||
}
|
||||
|
||||
GFXTexHandle::GFXTexHandle( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc )
|
||||
{
|
||||
set( bmp, profile, deleteBmp, desc );
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ public:
|
|||
GFXTexHandle( const String &texName, GFXTextureProfile *profile, const String &desc );
|
||||
bool set( const String &texName, GFXTextureProfile *profile, const String &desc );
|
||||
|
||||
// load composite
|
||||
GFXTexHandle(const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc);
|
||||
bool set( const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc );
|
||||
|
||||
// register texture
|
||||
GFXTexHandle( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc );
|
||||
bool set( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc );
|
||||
|
|
|
|||
|
|
@ -1122,7 +1122,8 @@ GFXTextureObject *GFXTextureManager::createCompositeTexture(GBitmap*bmp[4], U32
|
|||
}
|
||||
|
||||
U8 rChan, gChan, bChan, aChan;
|
||||
|
||||
GBitmap *outBitmap = new GBitmap();
|
||||
outBitmap->allocateBitmap(bmp[0]->getWidth(), bmp[0]->getHeight(),false, GFXFormatR8G8B8A8);
|
||||
//pack additional bitmaps into the origional
|
||||
for (U32 x = 0; x < bmp[0]->getWidth(); x++)
|
||||
{
|
||||
|
|
@ -1145,7 +1146,7 @@ GFXTextureObject *GFXTextureManager::createCompositeTexture(GBitmap*bmp[4], U32
|
|||
else
|
||||
aChan = 255;
|
||||
|
||||
bmp[0]->setColor(x, y, ColorI(rChan, gChan, bChan, aChan));
|
||||
outBitmap->setColor(x, y, ColorI(rChan, gChan, bChan, aChan));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1153,12 +1154,15 @@ GFXTextureObject *GFXTextureManager::createCompositeTexture(GBitmap*bmp[4], U32
|
|||
if (cacheHit != NULL)
|
||||
{
|
||||
// Con::errorf("Cached texture '%s'", (resourceName.isNotEmpty() ? resourceName.c_str() : "unknown"));
|
||||
if (deleteBmp)
|
||||
delete bmp[0];
|
||||
if (deleteBmp)
|
||||
{
|
||||
delete outBitmap;
|
||||
delete[] bmp;
|
||||
}
|
||||
return cacheHit;
|
||||
}
|
||||
|
||||
return _createTexture(bmp[0], resourceName, profile, deleteBmp, NULL);
|
||||
return _createTexture(outBitmap, resourceName, profile, deleteBmp, NULL);
|
||||
}
|
||||
|
||||
GFXTextureObject* GFXTextureManager::_findPooledTexure( U32 width,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@
|
|||
#include "gfx/gl/tGL/tGL.h"
|
||||
|
||||
GFXGLOcclusionQuery::GFXGLOcclusionQuery(GFXDevice* device) :
|
||||
GFXOcclusionQuery(device), mQuery(-1)
|
||||
GFXOcclusionQuery(device),
|
||||
mQuery(-1),
|
||||
mTesting(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -37,16 +39,29 @@ GFXGLOcclusionQuery::~GFXGLOcclusionQuery()
|
|||
|
||||
bool GFXGLOcclusionQuery::begin()
|
||||
{
|
||||
if(mQuery == -1)
|
||||
if (GFXDevice::getDisableOcclusionQuery())
|
||||
return true;
|
||||
|
||||
if (!glIsQuery(mQuery))
|
||||
glGenQueries(1, &mQuery);
|
||||
|
||||
glBeginQuery(GL_SAMPLES_PASSED, mQuery);
|
||||
if (!mTesting)
|
||||
{
|
||||
glBeginQuery(GL_SAMPLES_PASSED, mQuery);
|
||||
mTesting = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GFXGLOcclusionQuery::end()
|
||||
{
|
||||
if (GFXDevice::getDisableOcclusionQuery())
|
||||
return;
|
||||
|
||||
if (!glIsQuery(mQuery))
|
||||
return;
|
||||
glEndQuery(GL_SAMPLES_PASSED);
|
||||
mTesting = false;
|
||||
}
|
||||
|
||||
GFXOcclusionQuery::OcclusionQueryStatus GFXGLOcclusionQuery::getStatus(bool block, U32* data)
|
||||
|
|
@ -55,16 +70,33 @@ GFXOcclusionQuery::OcclusionQueryStatus GFXGLOcclusionQuery::getStatus(bool bloc
|
|||
// then your system is GPU bound.
|
||||
PROFILE_SCOPE(GFXGLOcclusionQuery_getStatus);
|
||||
|
||||
if(mQuery == -1)
|
||||
if (GFXDevice::getDisableOcclusionQuery())
|
||||
return NotOccluded;
|
||||
|
||||
if (!glIsQuery(mQuery))
|
||||
return NotOccluded;
|
||||
|
||||
GLint numPixels = 0;
|
||||
GLint queryDone = false;
|
||||
|
||||
if (block)
|
||||
queryDone = true;
|
||||
{
|
||||
while (!queryDone)
|
||||
{
|
||||
//If we're stalled out, proceed with worst-case scenario -BJR
|
||||
if (GFX->mFrameTime->getElapsedMs()>4)
|
||||
{
|
||||
this->begin();
|
||||
this->end();
|
||||
return NotOccluded;
|
||||
}
|
||||
glGetQueryObjectiv(mQuery, GL_QUERY_RESULT_AVAILABLE, &queryDone);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glGetQueryObjectiv(mQuery, GL_QUERY_RESULT_AVAILABLE, &queryDone);
|
||||
}
|
||||
|
||||
if (queryDone)
|
||||
glGetQueryObjectiv(mQuery, GL_QUERY_RESULT, &numPixels);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
private:
|
||||
U32 mQuery;
|
||||
bool mTesting;
|
||||
};
|
||||
|
||||
#endif // _GFX_GL_OCCLUSIONQUERY_H_
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
#include "scene/sceneManager.h"
|
||||
#include "console/engineAPI.h"
|
||||
#include "math/mathUtils.h"
|
||||
#include "gfx/bitmap/cubemapSaver.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT( CubemapData );
|
||||
|
||||
|
|
@ -183,3 +184,18 @@ DefineEngineMethod( CubemapData, getFilename, const char*, (),,
|
|||
{
|
||||
return object->getFilename();
|
||||
}
|
||||
|
||||
DefineEngineMethod(CubemapData, save, void, (const char* filename, const GFXFormat format), ("", GFXFormatBC1),
|
||||
"Returns the script filename of where the CubemapData object was "
|
||||
"defined. This is used by the material editor.")
|
||||
{
|
||||
if (filename == "")
|
||||
filename = object->getName();
|
||||
|
||||
//add dds extension if needed
|
||||
String finalName = String(filename);
|
||||
if(!finalName.endsWith(".dds") || !finalName.endsWith(".DDS"))
|
||||
finalName += String(".dds");
|
||||
|
||||
CubemapSaver::save(object->mCubemap, finalName, format);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue