diff --git a/Engine/source/T3D/accumulationVolume.cpp b/Engine/source/T3D/accumulationVolume.cpp index f868207e6..2d44d7178 100644 --- a/Engine/source/T3D/accumulationVolume.cpp +++ b/Engine/source/T3D/accumulationVolume.cpp @@ -265,7 +265,7 @@ void AccumulationVolume::setTexture( const String& name ) mTextureName = name; if ( isClientObject() && mTextureName.isNotEmpty() ) { - mAccuTexture.set(mTextureName, &GFXDefaultStaticDiffuseProfile, "AccumulationVolume::mAccuTexture"); + mAccuTexture.set(mTextureName, &GFXStaticTextureSRGBProfile, "AccumulationVolume::mAccuTexture"); if ( mAccuTexture.isNull() ) Con::warnf( "AccumulationVolume::setTexture - Unable to load texture: %s", mTextureName.c_str() ); } diff --git a/Engine/source/T3D/convexShape.cpp b/Engine/source/T3D/convexShape.cpp index 82683d3f8..b5134be65 100644 --- a/Engine/source/T3D/convexShape.cpp +++ b/Engine/source/T3D/convexShape.cpp @@ -1226,7 +1226,7 @@ void ConvexShape::_renderDebug( ObjectRenderInst *ri, SceneRenderState *state, B PrimBuild::begin( GFXLineList, edgeList.size() * 2 ); - PrimBuild::color( ColorI::WHITE * 0.8f ); + PrimBuild::color( LinearColorF(ColorI::WHITE) * 0.8f ); for ( S32 j = 0; j < edgeList.size(); j++ ) { @@ -1260,11 +1260,13 @@ void ConvexShape::_renderDebug( ObjectRenderInst *ri, SceneRenderState *state, B for ( S32 i = 0; i < faceList.size(); i++ ) { ColorI color = faceColorsx[ i % 4 ]; + LinearColorF tCol = LinearColorF(color); S32 div = ( i / 4 ) * 4; if ( div > 0 ) - color /= div; - color.alpha = 255; - + tCol /= div; + tCol.alpha = 1; + color = tCol.toColorI(); + Point3F pnt; objToWorld.mulP( faceList[i].centroid, &pnt ); drawer->drawCube( desc, size, pnt, color, NULL ); @@ -1295,11 +1297,13 @@ void ConvexShape::_renderDebug( ObjectRenderInst *ri, SceneRenderState *state, B objToWorld.mulP( p0 ); objToWorld.mulP( p1 ); - ColorI color = faceColorsx[ j % 4 ]; - S32 div = ( j / 4 ) * 4; - if ( div > 0 ) - color /= div; - color.alpha = 255; + ColorI color = faceColorsx[j % 4]; + LinearColorF tCol = LinearColorF(color); + S32 div = (j / 4) * 4; + if (div > 0) + tCol /= div; + tCol.alpha = 1; + color = tCol.toColorI(); PrimBuild::color( color ); PrimBuild::vertex3fv( p0 ); diff --git a/Engine/source/T3D/fps/guiClockHud.cpp b/Engine/source/T3D/fps/guiClockHud.cpp index 3b8220769..e823466e9 100644 --- a/Engine/source/T3D/fps/guiClockHud.cpp +++ b/Engine/source/T3D/fps/guiClockHud.cpp @@ -42,9 +42,9 @@ class GuiClockHud : public GuiControl bool mShowFill; bool mTimeReversed; - ColorF mFillColor; - ColorF mFrameColor; - ColorF mTextColor; + LinearColorF mFillColor; + LinearColorF mFrameColor; + LinearColorF mTextColor; S32 mTimeOffset; @@ -117,7 +117,7 @@ void GuiClockHud::onRender(Point2I offset, const RectI &updateRect) // Background first if (mShowFill) - drawUtil->drawRectFill(updateRect, mFillColor); + drawUtil->drawRectFill(updateRect, mFillColor.toColorI()); // Convert ms time into hours, minutes and seconds. S32 time = S32(getTime()); @@ -131,13 +131,13 @@ void GuiClockHud::onRender(Point2I offset, const RectI &updateRect) // Center the text offset.x += (getWidth() - mProfile->mFont->getStrWidth((const UTF8 *)buf)) / 2; offset.y += (getHeight() - mProfile->mFont->getHeight()) / 2; - drawUtil->setBitmapModulation(mTextColor); + drawUtil->setBitmapModulation(mTextColor.toColorI()); drawUtil->drawText(mProfile->mFont, offset, buf); drawUtil->clearBitmapModulation(); // Border last if (mShowFrame) - drawUtil->drawRect(updateRect, mFrameColor); + drawUtil->drawRect(updateRect, mFrameColor.toColorI()); } diff --git a/Engine/source/T3D/fps/guiCrossHairHud.cpp b/Engine/source/T3D/fps/guiCrossHairHud.cpp index 01761b707..723941b8c 100644 --- a/Engine/source/T3D/fps/guiCrossHairHud.cpp +++ b/Engine/source/T3D/fps/guiCrossHairHud.cpp @@ -42,8 +42,8 @@ class GuiCrossHairHud : public GuiBitmapCtrl { typedef GuiBitmapCtrl Parent; - ColorF mDamageFillColor; - ColorF mDamageFrameColor; + LinearColorF mDamageFillColor; + LinearColorF mDamageFrameColor; Point2I mDamageRectSize; Point2I mDamageOffset; @@ -178,7 +178,7 @@ void GuiCrossHairHud::drawDamage(Point2I offset, F32 damage, F32 opacity) rect.point.x -= mDamageRectSize.x / 2; // Draw the border - GFX->getDrawUtil()->drawRect(rect, mDamageFrameColor); + GFX->getDrawUtil()->drawRect(rect, mDamageFrameColor.toColorI()); // Draw the damage % fill rect.point += Point2I(1, 1); @@ -187,5 +187,5 @@ void GuiCrossHairHud::drawDamage(Point2I offset, F32 damage, F32 opacity) if (rect.extent.x == 1) rect.extent.x = 2; if (rect.extent.x > 0) - GFX->getDrawUtil()->drawRectFill(rect, mDamageFillColor); + GFX->getDrawUtil()->drawRectFill(rect, mDamageFillColor.toColorI()); } diff --git a/Engine/source/T3D/fps/guiHealthBarHud.cpp b/Engine/source/T3D/fps/guiHealthBarHud.cpp index 7c4d6e2b2..73994c82b 100644 --- a/Engine/source/T3D/fps/guiHealthBarHud.cpp +++ b/Engine/source/T3D/fps/guiHealthBarHud.cpp @@ -45,9 +45,9 @@ class GuiHealthBarHud : public GuiControl bool mDisplayEnergy; bool mFlip; - ColorF mFillColor; - ColorF mFrameColor; - ColorF mDamageFillColor; + LinearColorF mFillColor; + LinearColorF mFrameColor; + LinearColorF mDamageFillColor; S32 mPulseRate; F32 mPulseThreshold; @@ -163,7 +163,7 @@ void GuiHealthBarHud::onRender(Point2I offset, const RectI &updateRect) // Background first if (mShowFill) - GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor); + GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor.toColorI()); // Pulse the damage fill if it's below the threshold if (mPulseRate != 0) @@ -196,9 +196,9 @@ void GuiHealthBarHud::onRender(Point2I offset, const RectI &updateRect) else rect.point.y = bottomY - rect.extent.y; } - GFX->getDrawUtil()->drawRectFill(rect, mDamageFillColor); + GFX->getDrawUtil()->drawRectFill(rect, mDamageFillColor.toColorI()); // Border last if (mShowFrame) - GFX->getDrawUtil()->drawRect(updateRect, mFrameColor); + GFX->getDrawUtil()->drawRect(updateRect, mFrameColor.toColorI()); } diff --git a/Engine/source/T3D/fps/guiHealthTextHud.cpp b/Engine/source/T3D/fps/guiHealthTextHud.cpp index f4fe33ed4..99a63d34b 100644 --- a/Engine/source/T3D/fps/guiHealthTextHud.cpp +++ b/Engine/source/T3D/fps/guiHealthTextHud.cpp @@ -41,10 +41,10 @@ class GuiHealthTextHud : public GuiControl bool mShowEnergy; bool mShowTrueHealth; - ColorF mFillColor; - ColorF mFrameColor; - ColorF mTextColor; - ColorF mWarnColor; + LinearColorF mFillColor; + LinearColorF mFrameColor; + LinearColorF mTextColor; + LinearColorF mWarnColor; F32 mWarnLevel; F32 mPulseThreshold; @@ -167,7 +167,7 @@ void GuiHealthTextHud::onRender(Point2I offset, const RectI &updateRect) // If enabled draw background first if (mShowFill) - drawUtil->drawRectFill(updateRect, mFillColor); + drawUtil->drawRectFill(updateRect, mFillColor.toColorI()); // Prepare text and center it S32 val = (S32)mValue; @@ -176,7 +176,7 @@ void GuiHealthTextHud::onRender(Point2I offset, const RectI &updateRect) offset.x += (getBounds().extent.x - mProfile->mFont->getStrWidth((const UTF8 *)buf)) / 2; offset.y += (getBounds().extent.y - mProfile->mFont->getHeight()) / 2; - ColorF tColor = mTextColor; + LinearColorF tColor = mTextColor; // If warning level is exceeded switch to warning color if(mValue < mWarnLevel) @@ -192,11 +192,11 @@ void GuiHealthTextHud::onRender(Point2I offset, const RectI &updateRect) } } - drawUtil->setBitmapModulation(tColor); + drawUtil->setBitmapModulation(tColor.toColorI()); drawUtil->drawText(mProfile->mFont, offset, buf); drawUtil->clearBitmapModulation(); // If enabled draw the border last if (mShowFrame) - drawUtil->drawRect(updateRect, mFrameColor); + drawUtil->drawRect(updateRect, mFrameColor.toColorI()); } \ No newline at end of file diff --git a/Engine/source/T3D/fps/guiShapeNameHud.cpp b/Engine/source/T3D/fps/guiShapeNameHud.cpp index aa8c84892..60a14a596 100644 --- a/Engine/source/T3D/fps/guiShapeNameHud.cpp +++ b/Engine/source/T3D/fps/guiShapeNameHud.cpp @@ -47,11 +47,11 @@ class GuiShapeNameHud : public GuiControl { typedef GuiControl Parent; // field data - ColorF mFillColor; - ColorF mFrameColor; - ColorF mTextColor; - ColorF mLabelFillColor; - ColorF mLabelFrameColor; + LinearColorF mFillColor; + LinearColorF mFrameColor; + LinearColorF mTextColor; + LinearColorF mLabelFillColor; + LinearColorF mLabelFrameColor; F32 mVerticalOffset; F32 mDistanceFade; @@ -162,7 +162,7 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect) { // Background fill first if (mShowFill) - GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor); + GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor.toColorI()); // Must be in a TS Control GuiTSCtrl *parent = dynamic_cast(getParent()); @@ -274,7 +274,7 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect) // Border last if (mShowFrame) - GFX->getDrawUtil()->drawRect(updateRect, mFrameColor); + GFX->getDrawUtil()->drawRect(updateRect, mFrameColor.toColorI()); } @@ -302,16 +302,16 @@ void GuiShapeNameHud::drawName(Point2I offset, const char *name, F32 opacity) // Background fill first if (mShowLabelFill) - drawUtil->drawRectFill(RectI(offset, extent), mLabelFillColor); + drawUtil->drawRectFill(RectI(offset, extent), mLabelFillColor.toColorI()); // Deal with opacity and draw. mTextColor.alpha = opacity; - drawUtil->setBitmapModulation(mTextColor); + drawUtil->setBitmapModulation(mTextColor.toColorI()); drawUtil->drawText(mProfile->mFont, offset + mLabelPadding, name); drawUtil->clearBitmapModulation(); // Border last if (mShowLabelFrame) - drawUtil->drawRect(RectI(offset, extent), mLabelFrameColor); + drawUtil->drawRect(RectI(offset, extent), mLabelFrameColor.toColorI()); } diff --git a/Engine/source/T3D/fx/explosion.h b/Engine/source/T3D/fx/explosion.h index 19e91ad4e..a030776fe 100644 --- a/Engine/source/T3D/fx/explosion.h +++ b/Engine/source/T3D/fx/explosion.h @@ -113,8 +113,8 @@ class ExplosionData : public GameBaseData { // interpolated from start to end time. F32 lightStartRadius; F32 lightEndRadius; - ColorF lightStartColor; - ColorF lightEndColor; + LinearColorF lightStartColor; + LinearColorF lightEndColor; F32 lightStartBrightness; F32 lightEndBrightness; F32 lightNormalOffset; diff --git a/Engine/source/T3D/fx/fxFoliageReplicator.cpp b/Engine/source/T3D/fx/fxFoliageReplicator.cpp index 5646f6594..b62644eb0 100644 --- a/Engine/source/T3D/fx/fxFoliageReplicator.cpp +++ b/Engine/source/T3D/fx/fxFoliageReplicator.cpp @@ -166,7 +166,7 @@ void fxFoliageRenderList::SetupClipPlanes( SceneRenderState* state, const F32 fa //------------------------------------------------------------------------------ -inline void fxFoliageRenderList::DrawQuadBox(const Box3F& QuadBox, const ColorF Colour) +inline void fxFoliageRenderList::DrawQuadBox(const Box3F& QuadBox, const LinearColorF Colour) { // Define our debug box. static Point3F BoxPnts[] = { @@ -1260,7 +1260,7 @@ bool fxFoliageReplicator::onAdd() { // Yes, so load foliage texture. if( mFieldData.mFoliageFile != NULL && dStrlen(mFieldData.mFoliageFile) > 0 ) - mFieldData.mFoliageTexture = GFXTexHandle( mFieldData.mFoliageFile, &GFXDefaultStaticDiffuseProfile, avar("%s() - mFieldData.mFoliageTexture (line %d)", __FUNCTION__, __LINE__) ); + mFieldData.mFoliageTexture = GFXTexHandle( mFieldData.mFoliageFile, &GFXStaticTextureSRGBProfile, avar("%s() - mFieldData.mFoliageTexture (line %d)", __FUNCTION__, __LINE__) ); if ((GFXTextureObject*) mFieldData.mFoliageTexture == NULL) Con::printf("fxFoliageReplicator: %s is an invalid or missing foliage texture file.", mFieldData.mFoliageFile); @@ -1407,7 +1407,7 @@ void fxFoliageReplicator::computeAlphaTex() ColorI c((U8) (255.0f * ItemAlpha), 0, 0); mAlphaLookup->setColor(i, 0, c); } - mAlphaTexture.set(mAlphaLookup, &GFXDefaultStaticDiffuseProfile, false, String("fxFoliage Replicator Alpha Texture") ); + mAlphaTexture.set(mAlphaLookup, &GFXStaticTextureSRGBProfile, false, String("fxFoliage Replicator Alpha Texture") ); } // Renders a triangle stripped oval @@ -1619,7 +1619,7 @@ void fxFoliageReplicator::renderQuad(fxFoliageQuadrantNode* quadNode, const Matr { // Draw the Quad Box (Debug Only). if (UseDebug) - mFrustumRenderSet.DrawQuadBox(quadNode->QuadrantBox, ColorF(0.0f, 1.0f, 0.1f, 1.0f)); + mFrustumRenderSet.DrawQuadBox(quadNode->QuadrantBox, LinearColorF(0.0f, 1.0f, 0.1f, 1.0f)); if (quadNode->Level != 0) { for (U32 i = 0; i < 4; i++) renderQuad(quadNode->QuadrantChildNode[i], RenderTransform, UseDebug); @@ -1632,7 +1632,7 @@ void fxFoliageReplicator::renderQuad(fxFoliageQuadrantNode* quadNode, const Matr } else { // Use a different color to say "I think I'm not visible!" if (UseDebug) - mFrustumRenderSet.DrawQuadBox(quadNode->QuadrantBox, ColorF(1.0f, 0.8f, 0.1f, 1.0f)); + mFrustumRenderSet.DrawQuadBox(quadNode->QuadrantBox, LinearColorF(1.0f, 0.8f, 0.1f, 1.0f)); } } } @@ -1791,7 +1791,7 @@ void fxFoliageReplicator::unpackUpdate(NetConnection * con, BitStream * stream) // Load Foliage Texture on the client. if( mFieldData.mFoliageFile != NULL && dStrlen(mFieldData.mFoliageFile) > 0 ) - mFieldData.mFoliageTexture = GFXTexHandle( mFieldData.mFoliageFile, &GFXDefaultStaticDiffuseProfile, avar("%s() - mFieldData.mFoliageTexture (line %d)", __FUNCTION__, __LINE__) ); + mFieldData.mFoliageTexture = GFXTexHandle( mFieldData.mFoliageFile, &GFXStaticTextureSRGBProfile, avar("%s() - mFieldData.mFoliageTexture (line %d)", __FUNCTION__, __LINE__) ); if ((GFXTextureObject*) mFieldData.mFoliageTexture == NULL) Con::printf("fxFoliageReplicator: %s is an invalid or missing foliage texture file.", mFieldData.mFoliageFile); diff --git a/Engine/source/T3D/fx/fxFoliageReplicator.h b/Engine/source/T3D/fx/fxFoliageReplicator.h index c9f8a0804..9b7bad58f 100644 --- a/Engine/source/T3D/fx/fxFoliageReplicator.h +++ b/Engine/source/T3D/fx/fxFoliageReplicator.h @@ -126,7 +126,7 @@ public: public: bool IsQuadrantVisible(const Box3F VisBox, const MatrixF& RenderTransform); void SetupClipPlanes(SceneRenderState* state, const F32 FarClipPlane); - void DrawQuadBox(const Box3F& QuadBox, const ColorF Colour); + void DrawQuadBox(const Box3F& QuadBox, const LinearColorF Colour); }; @@ -317,7 +317,7 @@ public: bool mHideFoliage; bool mShowPlacementArea; U32 mPlacementBandHeight; - ColorF mPlaceAreaColour; + LinearColorF mPlaceAreaColour; tagFieldData() { diff --git a/Engine/source/T3D/fx/fxShapeReplicator.h b/Engine/source/T3D/fx/fxShapeReplicator.h index e83f0e113..6d894ae8a 100644 --- a/Engine/source/T3D/fx/fxShapeReplicator.h +++ b/Engine/source/T3D/fx/fxShapeReplicator.h @@ -147,7 +147,7 @@ public: bool mHideReplications; bool mShowPlacementArea; U32 mPlacementBandHeight; - ColorF mPlaceAreaColour; + LinearColorF mPlaceAreaColour; tagFieldData() { diff --git a/Engine/source/T3D/fx/groundCover.cpp b/Engine/source/T3D/fx/groundCover.cpp index d67fd1d71..63b5e3a2f 100644 --- a/Engine/source/T3D/fx/groundCover.cpp +++ b/Engine/source/T3D/fx/groundCover.cpp @@ -113,7 +113,7 @@ protected: U32 type; F32 windAmplitude; Box3F worldBox; - ColorF lmColor; + LinearColorF lmColor; }; /// This is the x,y index for this cell. @@ -239,7 +239,7 @@ void GroundCoverCell::_rebuildVB() const S32 &type = (*iter).type; const Point3F &size = (*iter).size; const F32 &windAmplitude = (*iter).windAmplitude; - GFXVertexColor color = (ColorI)(*iter).lmColor; + color = LinearColorF((*iter).lmColor).toColorI(); U8 *col = (U8 *)const_cast( (const U32 *)color ); vertPtr->point = position; @@ -944,7 +944,7 @@ void GroundCover::_initialize( U32 cellCount, U32 cellPlacementCount ) Material* mat = dynamic_cast(mMatInst->getMaterial()); if(mat) { - GFXTexHandle tex(mat->mDiffuseMapFilename[0], &GFXDefaultStaticDiffuseProfile, "GroundCover texture aspect ratio check" ); + GFXTexHandle tex(mat->mDiffuseMapFilename[0], &GFXStaticTextureSRGBProfile, "GroundCover texture aspect ratio check" ); if(tex.isValid()) { U32 w = tex.getWidth(); diff --git a/Engine/source/T3D/fx/lightning.cpp b/Engine/source/T3D/fx/lightning.cpp index 767cb44f1..9be145075 100644 --- a/Engine/source/T3D/fx/lightning.cpp +++ b/Engine/source/T3D/fx/lightning.cpp @@ -303,7 +303,7 @@ bool LightningData::preload(bool server, String &errorStr) { if (strikeTextureNames[i][0]) { - strikeTextures[i] = GFXTexHandle(strikeTextureNames[i], &GFXDefaultStaticDiffuseProfile, avar("%s() - strikeTextures[%d] (line %d)", __FUNCTION__, i, __LINE__)); + strikeTextures[i] = GFXTexHandle(strikeTextureNames[i], &GFXStaticTextureProfile, avar("%s() - strikeTextures[%d] (line %d)", __FUNCTION__, i, __LINE__)); mNumStrikeTextures++; } } diff --git a/Engine/source/T3D/fx/lightning.h b/Engine/source/T3D/fx/lightning.h index ed08bbd82..93a54ffc7 100644 --- a/Engine/source/T3D/fx/lightning.h +++ b/Engine/source/T3D/fx/lightning.h @@ -191,8 +191,8 @@ class Lightning : public GameBase F32 chanceToHitTarget; F32 strikeRadius; F32 boltStartRadius; - ColorF color; - ColorF fadeColor; + LinearColorF color; + LinearColorF fadeColor; bool useFog; GFXStateBlockRef mLightningSB; diff --git a/Engine/source/T3D/fx/particle.cpp b/Engine/source/T3D/fx/particle.cpp index bf9e987f8..cb307ccbb 100644 --- a/Engine/source/T3D/fx/particle.cpp +++ b/Engine/source/T3D/fx/particle.cpp @@ -200,7 +200,7 @@ void ParticleData::initPersistFields() "Deprecated. Use textureName instead." ); // Interpolation variables - addField( "colors", TYPEID< ColorF >(), Offset(colors, ParticleData), PDC_NUM_KEYS, + addField( "colors", TYPEID< LinearColorF >(), Offset(colors, ParticleData), PDC_NUM_KEYS, "@brief Particle RGBA color keyframe values.\n\n" "The particle color will linearly interpolate between the color/time keys " "over the lifetime of the particle." ); @@ -488,7 +488,7 @@ bool ParticleData::preload(bool server, String &errorStr) // texture is *not* an error since the emitter may provide one. if (textureName && textureName[0]) { - textureHandle = GFXTexHandle(textureName, &GFXDefaultStaticDiffuseProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); + textureHandle = GFXTexHandle(textureName, &GFXStaticTextureSRGBProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); if (!textureHandle) { errorStr = String::ToString("Missing particle texture: %s", textureName); @@ -613,7 +613,7 @@ bool ParticleData::reload(char errorBuffer[256]) bool error = false; if (textureName && textureName[0]) { - textureHandle = GFXTexHandle(textureName, &GFXDefaultStaticDiffuseProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); + textureHandle = GFXTexHandle(textureName, &GFXStaticTextureSRGBProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); if (!textureHandle) { dSprintf(errorBuffer, 256, "Missing particle texture: %s", textureName); diff --git a/Engine/source/T3D/fx/particle.h b/Engine/source/T3D/fx/particle.h index 14db8c096..35a0c9792 100644 --- a/Engine/source/T3D/fx/particle.h +++ b/Engine/source/T3D/fx/particle.h @@ -67,7 +67,7 @@ class ParticleData : public SimDataBlock U32 numFrames; U32 framesPerSec; - ColorF colors[ PDC_NUM_KEYS ]; + LinearColorF colors[ PDC_NUM_KEYS ]; F32 sizes[ PDC_NUM_KEYS ]; F32 times[ PDC_NUM_KEYS ]; @@ -118,7 +118,7 @@ struct Particle // are these necessary to store here? - they are interpolated in real time - ColorF color; + LinearColorF color; F32 size; F32 spinSpeed; diff --git a/Engine/source/T3D/fx/particleEmitter.cpp b/Engine/source/T3D/fx/particleEmitter.cpp index d07145278..63d590bad 100644 --- a/Engine/source/T3D/fx/particleEmitter.cpp +++ b/Engine/source/T3D/fx/particleEmitter.cpp @@ -603,7 +603,7 @@ bool ParticleEmitterData::preload(bool server, String &errorStr) // load emitter texture if specified if (textureName && textureName[0]) { - textureHandle = GFXTexHandle(textureName, &GFXDefaultStaticDiffuseProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); + textureHandle = GFXTexHandle(textureName, &GFXStaticTextureSRGBProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); if (!textureHandle) { errorStr = String::ToString("Missing particle emitter texture: %s", textureName); @@ -833,10 +833,10 @@ bool ParticleEmitter::onNewDataBlock( GameBaseData *dptr, bool reload ) //----------------------------------------------------------------------------- // getCollectiveColor //----------------------------------------------------------------------------- -ColorF ParticleEmitter::getCollectiveColor() +LinearColorF ParticleEmitter::getCollectiveColor() { U32 count = 0; - ColorF color = ColorF(0.0f, 0.0f, 0.0f); + LinearColorF color = LinearColorF(0.0f, 0.0f, 0.0f); count = n_parts; for( Particle* part = part_list_head.next; part != NULL; part = part->next ) @@ -937,7 +937,7 @@ void ParticleEmitter::setSizes( F32 *sizeList ) //----------------------------------------------------------------------------- // setColors //----------------------------------------------------------------------------- -void ParticleEmitter::setColors( ColorF *colorList ) +void ParticleEmitter::setColors( LinearColorF *colorList ) { for( S32 i=0; i orderedVector(__FILE__, __LINE__); @@ -1653,7 +1653,7 @@ void ParticleEmitter::copyToVB( const Point3F &camPos, const ColorF &ambientColo void ParticleEmitter::setupBillboard( Particle *part, Point3F *basePts, const MatrixF &camView, - const ColorF &ambientColor, + const LinearColorF &ambientColor, ParticleVertexType *lVerts ) { F32 width = part->size * 0.5f; @@ -1663,7 +1663,7 @@ void ParticleEmitter::setupBillboard( Particle *part, mSinCos(spinAngle, sy, cy); const F32 ambientLerp = mClampF( mDataBlock->ambientFactor, 0.0f, 1.0f ); - ColorF partCol = mLerp( part->color, ( part->color * ambientColor ), ambientLerp ); + LinearColorF partCol = mLerp( part->color, ( part->color * ambientColor ), ambientLerp ); // fill four verts, use macro and unroll loop #define fillVert(){ \ @@ -1673,7 +1673,7 @@ void ParticleEmitter::setupBillboard( Particle *part, camView.mulV( lVerts->point ); \ lVerts->point *= width; \ lVerts->point += part->pos; \ - lVerts->color = partCol; } \ + lVerts->color = partCol.toColorI(); } \ // Here we deal with UVs for animated particle (billboard) if (part->dataBlock->animateTexture && !part->dataBlock->animTexFrames.empty()) @@ -1737,7 +1737,7 @@ void ParticleEmitter::setupBillboard( Particle *part, //----------------------------------------------------------------------------- void ParticleEmitter::setupOriented( Particle *part, const Point3F &camPos, - const ColorF &ambientColor, + const LinearColorF &ambientColor, ParticleVertexType *lVerts ) { Point3F dir; @@ -1766,8 +1766,8 @@ void ParticleEmitter::setupOriented( Particle *part, Point3F end = part->pos + dir; const F32 ambientLerp = mClampF( mDataBlock->ambientFactor, 0.0f, 1.0f ); - ColorF partCol = mLerp( part->color, ( part->color * ambientColor ), ambientLerp ); - + LinearColorF partCol = mLerp( part->color, ( part->color * ambientColor ), ambientLerp ); + const ColorI color = partCol.toColorI(); // Here we deal with UVs for animated particle (oriented) if (part->dataBlock->animateTexture) { @@ -1779,55 +1779,55 @@ void ParticleEmitter::setupOriented( Particle *part, uv[1] = uv[0] + (part->dataBlock->animTexTiling.x + 1); uv[2] = uv[1] + 1; uv[3] = uv[0] + 1; + + lVerts->point = start + crossDir; + lVerts->color = color; + // Here and below, we copy UVs from particle datablock's current frame's UVs (oriented) + lVerts->texCoord = part->dataBlock->animTexUVs[uv[0]]; + ++lVerts; - lVerts->point = start + crossDir; - lVerts->color = partCol; - // Here and below, we copy UVs from particle datablock's current frame's UVs (oriented) - lVerts->texCoord = part->dataBlock->animTexUVs[uv[0]]; - ++lVerts; + lVerts->point = start - crossDir; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[1]]; + ++lVerts; - lVerts->point = start - crossDir; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[1]]; - ++lVerts; + lVerts->point = end - crossDir; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[2]]; + ++lVerts; - lVerts->point = end - crossDir; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[2]]; - ++lVerts; + lVerts->point = end + crossDir; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[3]]; + ++lVerts; - lVerts->point = end + crossDir; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[3]]; - ++lVerts; - - return; + return; } lVerts->point = start + crossDir; - lVerts->color = partCol; + lVerts->color = color; // Here and below, we copy UVs from particle datablock's texCoords (oriented) lVerts->texCoord = part->dataBlock->texCoords[1]; ++lVerts; lVerts->point = start - crossDir; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[2]; ++lVerts; lVerts->point = end - crossDir; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[3]; ++lVerts; lVerts->point = end + crossDir; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[0]; ++lVerts; } void ParticleEmitter::setupAligned( const Particle *part, - const ColorF &ambientColor, + const LinearColorF &ambientColor, ParticleVertexType *lVerts ) { // The aligned direction will always be normalized. @@ -1877,8 +1877,8 @@ void ParticleEmitter::setupAligned( const Particle *part, Point3F end = part->pos + right; const F32 ambientLerp = mClampF( mDataBlock->ambientFactor, 0.0f, 1.0f ); - ColorF partCol = mLerp( part->color, ( part->color * ambientColor ), ambientLerp ); - + LinearColorF partCol = mLerp( part->color, ( part->color * ambientColor ), ambientLerp ); + const ColorI color = partCol.toColorI(); // Here we deal with UVs for animated particle if (part->dataBlock->animateTexture) { @@ -1891,46 +1891,46 @@ void ParticleEmitter::setupAligned( const Particle *part, uv[2] = uv[1] + 1; uv[3] = uv[0] + 1; - lVerts->point = start + cross; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[0]]; - ++lVerts; + lVerts->point = start + cross; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[0]]; + ++lVerts; - lVerts->point = start - cross; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[1]]; - ++lVerts; + lVerts->point = start - cross; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[1]]; + ++lVerts; - lVerts->point = end - cross; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[2]]; - ++lVerts; + lVerts->point = end - cross; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[2]]; + ++lVerts; - lVerts->point = end + cross; - lVerts->color = partCol; - lVerts->texCoord = part->dataBlock->animTexUVs[uv[3]]; - ++lVerts; + lVerts->point = end + cross; + lVerts->color = color; + lVerts->texCoord = part->dataBlock->animTexUVs[uv[3]]; + ++lVerts; } else { // Here and below, we copy UVs from particle datablock's texCoords lVerts->point = start + cross; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[0]; ++lVerts; lVerts->point = start - cross; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[1]; ++lVerts; lVerts->point = end - cross; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[2]; ++lVerts; lVerts->point = end + cross; - lVerts->color = partCol; + lVerts->color = color; lVerts->texCoord = part->dataBlock->texCoords[3]; ++lVerts; } diff --git a/Engine/source/T3D/fx/particleEmitter.h b/Engine/source/T3D/fx/particleEmitter.h index 453b21694..122dbcb00 100644 --- a/Engine/source/T3D/fx/particleEmitter.h +++ b/Engine/source/T3D/fx/particleEmitter.h @@ -134,7 +134,7 @@ class ParticleEmitter : public GameBase static Point3F mWindVelocity; static void setWindVelocity( const Point3F &vel ){ mWindVelocity = vel; } - ColorF getCollectiveColor(); + LinearColorF getCollectiveColor(); /// Sets sizes of particles based on sizelist provided /// @param sizeList List of sizes @@ -142,7 +142,7 @@ class ParticleEmitter : public GameBase /// Sets colors for particles based on color list provided /// @param colorList List of colors - void setColors( ColorF *colorList ); + void setColors( LinearColorF *colorList ); ParticleEmitterData *getDataBlock(){ return mDataBlock; } bool onNewDataBlock( GameBaseData *dptr, bool reload ); @@ -196,16 +196,16 @@ class ParticleEmitter : public GameBase inline void setupBillboard( Particle *part, Point3F *basePts, const MatrixF &camView, - const ColorF &ambientColor, + const LinearColorF &ambientColor, ParticleVertexType *lVerts ); inline void setupOriented( Particle *part, const Point3F &camPos, - const ColorF &ambientColor, + const LinearColorF &ambientColor, ParticleVertexType *lVerts ); inline void setupAligned( const Particle *part, - const ColorF &ambientColor, + const LinearColorF &ambientColor, ParticleVertexType *lVerts ); /// Updates the bounding box for the particle system @@ -222,7 +222,7 @@ class ParticleEmitter : public GameBase // Rendering protected: void prepRenderImage( SceneRenderState *state ); - void copyToVB( const Point3F &camPos, const ColorF &ambientColor ); + void copyToVB( const Point3F &camPos, const LinearColorF &ambientColor ); // PEngine interface private: @@ -254,7 +254,7 @@ class ParticleEmitter : public GameBase S32 mElapsedTimeMS; F32 sizes[ ParticleData::PDC_NUM_KEYS ]; - ColorF colors[ ParticleData::PDC_NUM_KEYS ]; + LinearColorF colors[ ParticleData::PDC_NUM_KEYS ]; GFXVertexBufferHandle mVertBuff; diff --git a/Engine/source/T3D/fx/precipitation.cpp b/Engine/source/T3D/fx/precipitation.cpp index 1a1af9192..4f7694482 100644 --- a/Engine/source/T3D/fx/precipitation.cpp +++ b/Engine/source/T3D/fx/precipitation.cpp @@ -248,7 +248,7 @@ Precipitation::Precipitation() mDropAnimateMS = 0; mUseLighting = false; - mGlowIntensity = ColorF( 0,0,0,0 ); + mGlowIntensity = LinearColorF( 0,0,0,0 ); mReflect = false; @@ -604,7 +604,7 @@ void Precipitation::initMaterials() mDropShader = NULL; mSplashShader = NULL; - if( dStrlen(pd->mDropName) > 0 && !mDropHandle.set(pd->mDropName, &GFXDefaultStaticDiffuseProfile, avar("%s() - mDropHandle (line %d)", __FUNCTION__, __LINE__)) ) + if( dStrlen(pd->mDropName) > 0 && !mDropHandle.set(pd->mDropName, &GFXStaticTextureSRGBProfile, avar("%s() - mDropHandle (line %d)", __FUNCTION__, __LINE__)) ) Con::warnf("Precipitation::initMaterials - failed to locate texture '%s'!", pd->mDropName); if ( dStrlen(pd->mDropShaderName) > 0 ) @@ -625,7 +625,7 @@ void Precipitation::initMaterials() } } - if( dStrlen(pd->mSplashName) > 0 && !mSplashHandle.set(pd->mSplashName, &GFXDefaultStaticDiffuseProfile, avar("%s() - mSplashHandle (line %d)", __FUNCTION__, __LINE__)) ) + if( dStrlen(pd->mSplashName) > 0 && !mSplashHandle.set(pd->mSplashName, &GFXStaticTextureSRGBProfile, avar("%s() - mSplashHandle (line %d)", __FUNCTION__, __LINE__)) ) Con::warnf("Precipitation::initMaterials - failed to locate texture '%s'!", pd->mSplashName); if ( dStrlen(pd->mSplashShaderName) > 0 ) @@ -1581,7 +1581,7 @@ void Precipitation::renderObject(ObjectRenderInst *ri, SceneRenderState *state, // shader. Once the lighting and shadow systems // are added into TSE we can expand this to include // the N nearest lights to the camera + the ambient. - ColorF ambient( 1, 1, 1 ); + LinearColorF ambient( 1, 1, 1 ); if ( mUseLighting ) { const LightInfo *sunlight = LIGHTMGR->getSpecialLight(LightManager::slSunLightType); diff --git a/Engine/source/T3D/fx/precipitation.h b/Engine/source/T3D/fx/precipitation.h index 80f76f2bb..358a19f80 100644 --- a/Engine/source/T3D/fx/precipitation.h +++ b/Engine/source/T3D/fx/precipitation.h @@ -160,7 +160,7 @@ class Precipitation : public GameBase bool mUseLighting; ///< This enables shading of the drops and splashes ///< by the sun color. - ColorF mGlowIntensity; ///< Set it to 0 to disable the glow or use it to control + LinearColorF mGlowIntensity; ///< Set it to 0 to disable the glow or use it to control ///< the intensity of each channel. bool mReflect; ///< This enables the precipitation to be rendered diff --git a/Engine/source/T3D/fx/ribbon.cpp b/Engine/source/T3D/fx/ribbon.cpp index ef5276857..9dddd8131 100644 --- a/Engine/source/T3D/fx/ribbon.cpp +++ b/Engine/source/T3D/fx/ribbon.cpp @@ -562,16 +562,16 @@ void Ribbon::createBuffers(SceneRenderState *state, GFXVertexBufferHandlemSizes[0]; - ColorF tColor = mDataBlock->mColours[0]; + LinearColorF tColor = mDataBlock->mColours[0]; for (U8 j = 0; j < RibbonData::NumFields-1; j++) { F32 curPosition = mDataBlock->mTimes[j]; F32 curRadius = mDataBlock->mSizes[j]; - ColorF curColor = mDataBlock->mColours[j]; + LinearColorF curColor = mDataBlock->mColours[j]; F32 nextPosition = mDataBlock->mTimes[j+1]; F32 nextRadius = mDataBlock->mSizes[j+1]; - ColorF nextColor = mDataBlock->mColours[j+1]; + LinearColorF nextColor = mDataBlock->mColours[j+1]; if ( curPosition < 0 || curPosition > interpol ) @@ -603,7 +603,7 @@ void Ribbon::createBuffers(SceneRenderState *state, GFXVertexBufferHandlemUseFadeOut) color.alpha *= mFadeOut; @@ -623,7 +623,7 @@ void Ribbon::createBuffers(SceneRenderState *state, GFXVertexBufferHandlemTileScale; - verts[count].color = color; + verts[count].color = color.toColorI(); verts[count].texCoord[1] = Point2F(interpol, 0); verts[count].texCoord[0] = Point2F(0.0f, texCoords); verts[count].normal.set(diff); @@ -651,7 +651,7 @@ void Ribbon::createBuffers(SceneRenderState *state, GFXVertexBufferHandlemUseFadeOut) color.alpha *= mFadeOut; - verts[count].color = color; + verts[count].color = color.toColorI(); verts[count].texCoord[1] = Point2F(interpol, 1); verts[count].texCoord[0] = Point2F(1.0f, texCoords); verts[count].normal.set(diff); diff --git a/Engine/source/T3D/fx/ribbon.h b/Engine/source/T3D/fx/ribbon.h index 10ca8d40b..36faf03c1 100644 --- a/Engine/source/T3D/fx/ribbon.h +++ b/Engine/source/T3D/fx/ribbon.h @@ -54,7 +54,7 @@ public: }; F32 mSizes[NumFields]; ///< The radius for each keyframe. - ColorF mColours[NumFields]; ///< The colour of the ribbon for each keyframe. + LinearColorF mColours[NumFields]; ///< The colour of the ribbon for each keyframe. F32 mTimes[NumFields]; ///< The relative time for each keyframe. U32 mRibbonLength; ///< The amount of segments that will make up the ribbon. diff --git a/Engine/source/T3D/fx/splash.cpp b/Engine/source/T3D/fx/splash.cpp index 0e9a2c6f4..812c1bb2f 100644 --- a/Engine/source/T3D/fx/splash.cpp +++ b/Engine/source/T3D/fx/splash.cpp @@ -282,7 +282,7 @@ bool SplashData::preload(bool server, String &errorStr) { if (textureName[i] && textureName[i][0]) { - textureHandle[i] = GFXTexHandle(textureName[i], &GFXDefaultStaticDiffuseProfile, avar("%s() - textureHandle[%d] (line %d)", __FUNCTION__, i, __LINE__) ); + textureHandle[i] = GFXTexHandle(textureName[i], &GFXStaticTextureSRGBProfile, avar("%s() - textureHandle[%d] (line %d)", __FUNCTION__, i, __LINE__) ); } } } diff --git a/Engine/source/T3D/fx/splash.h b/Engine/source/T3D/fx/splash.h index 53362e6c0..1239f2184 100644 --- a/Engine/source/T3D/fx/splash.h +++ b/Engine/source/T3D/fx/splash.h @@ -54,7 +54,7 @@ struct SplashRingPoint struct SplashRing { Vector points; - ColorF color; + LinearColorF color; F32 lifetime; F32 elapsedTime; F32 v; @@ -114,7 +114,7 @@ public: F32 startRadius; F32 times[ NUM_TIME_KEYS ]; - ColorF colors[ NUM_TIME_KEYS ]; + LinearColorF colors[ NUM_TIME_KEYS ]; StringTableEntry textureName[NUM_TEX]; GFXTexHandle textureHandle[NUM_TEX]; @@ -152,7 +152,7 @@ private: F32 mRadius; F32 mVelocity; F32 mHeight; - ColorF mColor; + LinearColorF mColor; F32 mTimeSinceLastRing; bool mDead; F32 mElapsedTime; diff --git a/Engine/source/T3D/guiMaterialPreview.cpp b/Engine/source/T3D/guiMaterialPreview.cpp index b97ed959c..1fa053a12 100644 --- a/Engine/source/T3D/guiMaterialPreview.cpp +++ b/Engine/source/T3D/guiMaterialPreview.cpp @@ -77,8 +77,8 @@ bool GuiMaterialPreview::onWake() if (!mFakeSun) mFakeSun = LightManager::createLightInfo(); - mFakeSun->setColor( ColorF( 1.0f, 1.0f, 1.0f ) ); - mFakeSun->setAmbient( ColorF( 0.5f, 0.5f, 0.5f ) ); + mFakeSun->setColor( LinearColorF( 1.0f, 1.0f, 1.0f ) ); + mFakeSun->setAmbient( LinearColorF( 0.5f, 0.5f, 0.5f ) ); mFakeSun->setDirection( VectorF( 0.0f, 0.707f, -0.707f ) ); mFakeSun->setPosition( mFakeSun->getDirection() * -10000.0f ); mFakeSun->setRange( 2000000.0f ); @@ -89,7 +89,7 @@ bool GuiMaterialPreview::onWake() // This function allows the viewport's ambient color to be changed. This is exposed to script below. void GuiMaterialPreview::setAmbientLightColor( F32 r, F32 g, F32 b ) { - ColorF temp(r, g, b); + LinearColorF temp(r, g, b); temp.clamp(); GuiMaterialPreview::mFakeSun->setAmbient( temp ); } @@ -97,7 +97,7 @@ void GuiMaterialPreview::setAmbientLightColor( F32 r, F32 g, F32 b ) // This function allows the light's color to be changed. This is exposed to script below. void GuiMaterialPreview::setLightColor( F32 r, F32 g, F32 b ) { - ColorF temp(r, g, b); + LinearColorF temp(r, g, b); temp.clamp(); GuiMaterialPreview::mFakeSun->setColor( temp ); } @@ -437,8 +437,8 @@ void GuiMaterialPreview::resetViewport() mOrbitPos = mModel->getShape()->center; // Reset the viewport's lighting. - GuiMaterialPreview::mFakeSun->setColor( ColorF( 1.0f, 1.0f, 1.0f ) ); - GuiMaterialPreview::mFakeSun->setAmbient( ColorF( 0.5f, 0.5f, 0.5f ) ); + GuiMaterialPreview::mFakeSun->setColor( LinearColorF( 1.0f, 1.0f, 1.0f ) ); + GuiMaterialPreview::mFakeSun->setAmbient( LinearColorF( 0.5f, 0.5f, 0.5f ) ); GuiMaterialPreview::mFakeSun->setDirection( VectorF( 0.0f, 0.707f, -0.707f ) ); } @@ -482,14 +482,14 @@ DefineEngineMethod(GuiMaterialPreview, reset, void, (),, } // This function allows the user to change the light's color. -DefineEngineMethod(GuiMaterialPreview, setLightColor, void, ( ColorF color ),, +DefineEngineMethod(GuiMaterialPreview, setLightColor, void, ( LinearColorF color ),, "Sets the color of the light in the scene.\n") { object->setLightColor( color.red, color.green, color.blue ); } // This function allows the user to change the viewports's ambient color. -DefineEngineMethod(GuiMaterialPreview, setAmbientLightColor, void, ( ColorF color ),, +DefineEngineMethod(GuiMaterialPreview, setAmbientLightColor, void, ( LinearColorF color ),, "Sets the color of the ambient light in the scene.\n") { object->setAmbientLightColor( color.red, color.green, color.blue ); diff --git a/Engine/source/T3D/guiObjectView.cpp b/Engine/source/T3D/guiObjectView.cpp index 1cbef0fc3..13c46380c 100644 --- a/Engine/source/T3D/guiObjectView.cpp +++ b/Engine/source/T3D/guiObjectView.cpp @@ -590,7 +590,7 @@ void GuiObjectView::setCameraRotation( const EulerF& rotation ) } //------------------------------------------------------------------------------ -void GuiObjectView::setLightColor( const ColorF& color ) +void GuiObjectView::setLightColor( const LinearColorF& color ) { mLightColor = color; if( mLight ) @@ -599,7 +599,7 @@ void GuiObjectView::setLightColor( const ColorF& color ) //------------------------------------------------------------------------------ -void GuiObjectView::setLightAmbient( const ColorF& color ) +void GuiObjectView::setLightAmbient( const LinearColorF& color ) { mLightAmbient = color; if( mLight ) @@ -952,7 +952,7 @@ DefineEngineMethod( GuiObjectView, setCameraSpeed, void, (F32 factor),, //----------------------------------------------------------------------------- -DefineEngineMethod( GuiObjectView, setLightColor, void, ( ColorF color),, +DefineEngineMethod( GuiObjectView, setLightColor, void, ( LinearColorF color),, "@brief Set the light color on the sun object used to render the model.\n\n" "@param color Color of sunlight.\n" "@tsexample\n" @@ -968,7 +968,7 @@ DefineEngineMethod( GuiObjectView, setLightColor, void, ( ColorF color),, //----------------------------------------------------------------------------- -DefineEngineMethod( GuiObjectView, setLightAmbient, void, (ColorF color),, +DefineEngineMethod( GuiObjectView, setLightAmbient, void, (LinearColorF color),, "@brief Set the light ambient color on the sun object used to render the model.\n\n" "@param color Ambient color of sunlight.\n" "@tsexample\n" diff --git a/Engine/source/T3D/guiObjectView.h b/Engine/source/T3D/guiObjectView.h index da4898e61..792e59c43 100644 --- a/Engine/source/T3D/guiObjectView.h +++ b/Engine/source/T3D/guiObjectView.h @@ -145,10 +145,10 @@ class GuiObjectView : public GuiTSCtrl LightInfo* mLight; /// - ColorF mLightColor; + LinearColorF mLightColor; /// - ColorF mLightAmbient; + LinearColorF mLightAmbient; /// Point3F mLightDirection; @@ -255,10 +255,10 @@ class GuiObjectView : public GuiTSCtrl /// @{ /// - void setLightColor( const ColorF& color ); + void setLightColor( const LinearColorF& color ); /// - void setLightAmbient( const ColorF& color ); + void setLightAmbient( const LinearColorF& color ); /// void setLightDirection( const Point3F& direction ); diff --git a/Engine/source/T3D/item.h b/Engine/source/T3D/item.h index 5da9e0f56..68720952b 100644 --- a/Engine/source/T3D/item.h +++ b/Engine/source/T3D/item.h @@ -51,7 +51,7 @@ struct ItemData: public ShapeBaseData { bool lightOnlyStatic; S32 lightType; - ColorF lightColor; + LinearColorF lightColor; S32 lightTime; F32 lightRadius; diff --git a/Engine/source/T3D/levelInfo.cpp b/Engine/source/T3D/levelInfo.cpp index 947172836..c442bcda1 100644 --- a/Engine/source/T3D/levelInfo.cpp +++ b/Engine/source/T3D/levelInfo.cpp @@ -371,7 +371,7 @@ void LevelInfo::setLevelAccuTexture(const String& name) mAccuTextureName = name; if (isClientObject() && mAccuTextureName.isNotEmpty()) { - mAccuTexture.set(mAccuTextureName, &GFXDefaultStaticDiffuseProfile, "AccumulationVolume::mAccuTexture"); + mAccuTexture.set(mAccuTextureName, &GFXStaticTextureSRGBProfile, "AccumulationVolume::mAccuTexture"); if (mAccuTexture.isNull()) Con::warnf("AccumulationVolume::setTexture - Unable to load texture: %s", mAccuTextureName.c_str()); else diff --git a/Engine/source/T3D/lightAnimData.cpp b/Engine/source/T3D/lightAnimData.cpp index c5ef93b0f..77e948935 100644 --- a/Engine/source/T3D/lightAnimData.cpp +++ b/Engine/source/T3D/lightAnimData.cpp @@ -302,7 +302,7 @@ void LightAnimData::animate( LightInfo *lightInfo, LightAnimState *state ) lightInfo->setTransform( transform ); - ColorF color = state->color; + LinearColorF color = state->color; mColor.animate( time, color ); lightInfo->setColor( color ); diff --git a/Engine/source/T3D/lightAnimData.h b/Engine/source/T3D/lightAnimData.h index d8c933674..9467b5247 100644 --- a/Engine/source/T3D/lightAnimData.h +++ b/Engine/source/T3D/lightAnimData.h @@ -74,7 +74,7 @@ struct LightAnimState MatrixF transform; /// The set light color before animation occurs. - ColorF color; + LinearColorF color; }; diff --git a/Engine/source/T3D/lightBase.cpp b/Engine/source/T3D/lightBase.cpp index b7cd4ea88..76c0298c0 100644 --- a/Engine/source/T3D/lightBase.cpp +++ b/Engine/source/T3D/lightBase.cpp @@ -57,7 +57,7 @@ ConsoleDocClass( LightBase, LightBase::LightBase() : mIsEnabled( true ), - mColor( ColorF::WHITE ), + mColor( LinearColorF::WHITE ), mBrightness( 1.0f ), mCastShadows( false ), mStaticRefreshFreq( 250 ), diff --git a/Engine/source/T3D/lightBase.h b/Engine/source/T3D/lightBase.h index 2501c4ca8..af2c35071 100644 --- a/Engine/source/T3D/lightBase.h +++ b/Engine/source/T3D/lightBase.h @@ -51,7 +51,7 @@ protected: bool mIsEnabled; - ColorF mColor; + LinearColorF mColor; F32 mBrightness; diff --git a/Engine/source/T3D/lightDescription.cpp b/Engine/source/T3D/lightDescription.cpp index 660a491ae..02076d0be 100644 --- a/Engine/source/T3D/lightDescription.cpp +++ b/Engine/source/T3D/lightDescription.cpp @@ -32,7 +32,7 @@ LightDescription::LightDescription() - : color( ColorF::WHITE ), + : color( LinearColorF::WHITE ), brightness( 1.0f ), range( 5.0f ), castShadows( false ), diff --git a/Engine/source/T3D/lightDescription.h b/Engine/source/T3D/lightDescription.h index fda00ebc2..ab2e1bf3c 100644 --- a/Engine/source/T3D/lightDescription.h +++ b/Engine/source/T3D/lightDescription.h @@ -97,7 +97,7 @@ public: bool _preload( bool server, String &errorStr ); - ColorF color; + LinearColorF color; F32 brightness; F32 range; bool castShadows; diff --git a/Engine/source/T3D/lightFlareData.cpp b/Engine/source/T3D/lightFlareData.cpp index 72cbb94f8..7eada6bf9 100644 --- a/Engine/source/T3D/lightFlareData.cpp +++ b/Engine/source/T3D/lightFlareData.cpp @@ -126,7 +126,7 @@ LightFlareData::LightFlareData() { dMemset( mElementRect, 0, sizeof( RectF ) * MAX_ELEMENTS ); dMemset( mElementScale, 0, sizeof( F32 ) * MAX_ELEMENTS ); - dMemset( mElementTint, 0, sizeof( ColorF ) * MAX_ELEMENTS ); + dMemset( mElementTint, 0, sizeof( LinearColorF ) * MAX_ELEMENTS ); dMemset( mElementRotate, 0, sizeof( bool ) * MAX_ELEMENTS ); dMemset( mElementUseLightColor, 0, sizeof( bool ) * MAX_ELEMENTS ); @@ -524,7 +524,7 @@ void LightFlareData::prepRender(SceneRenderState *state, LightFlareState *flareS // // These are the factors which affect the "alpha" of the flare effect. // Modulate more in as appropriate. - ColorF baseColor = ColorF::WHITE * lightSourceBrightnessScale * occlusionFade; + LinearColorF baseColor = LinearColorF::WHITE * lightSourceBrightnessScale * occlusionFade; // Setup the vertex buffer for the maximum flare elements. const U32 vertCount = 4 * mElementCount; @@ -544,7 +544,7 @@ void LightFlareData::prepRender(SceneRenderState *state, LightFlareState *flareS Point3F *basePos = mElementRotate[i] ? rotatedBasePoints : sBasePoints; - ColorF color( baseColor * mElementTint[i] ); + LinearColorF color( baseColor * mElementTint[i] ); if ( mElementUseLightColor[i] ) color *= lightInfo->getColor(); color.clamp(); @@ -571,22 +571,23 @@ void LightFlareData::prepRender(SceneRenderState *state, LightFlareState *flareS size.y = getMax( size.y, 1.0f ); size *= oneOverViewportExtent; - vert->color = color; + const ColorI colori = color.toColorI(); + vert->color = colori; vert->point = ( basePos[0] * size ) + pos; vert->texCoord.set( texCoordMin.x, texCoordMax.y ); vert++; - vert->color = color; + vert->color = colori; vert->point = ( basePos[1] * size ) + pos; vert->texCoord.set( texCoordMax.x, texCoordMax.y ); vert++; - vert->color = color; + vert->color = colori; vert->point = ( basePos[2] * size ) + pos; vert->texCoord.set( texCoordMax.x, texCoordMin.y ); vert++; - vert->color = color; + vert->color = colori; vert->point = ( basePos[3] * size ) + pos; vert->texCoord.set( texCoordMin.x, texCoordMin.y ); vert++; @@ -633,7 +634,7 @@ bool LightFlareData::_preload( bool server, String &errorStr ) if ( !server ) { if ( mFlareTextureName.isNotEmpty() ) - mFlareTexture.set( mFlareTextureName, &GFXDefaultStaticDiffuseProfile, "FlareTexture" ); + mFlareTexture.set( mFlareTextureName, &GFXStaticTextureSRGBProfile, "FlareTexture" ); } return true; diff --git a/Engine/source/T3D/lightFlareData.h b/Engine/source/T3D/lightFlareData.h index 333bf1bf5..e0517abda 100644 --- a/Engine/source/T3D/lightFlareData.h +++ b/Engine/source/T3D/lightFlareData.h @@ -123,7 +123,7 @@ protected: RectF mElementRect[MAX_ELEMENTS]; F32 mElementDist[MAX_ELEMENTS]; F32 mElementScale[MAX_ELEMENTS]; - ColorF mElementTint[MAX_ELEMENTS]; + LinearColorF mElementTint[MAX_ELEMENTS]; bool mElementRotate[MAX_ELEMENTS]; bool mElementUseLightColor[MAX_ELEMENTS]; diff --git a/Engine/source/T3D/physicalZone.cpp b/Engine/source/T3D/physicalZone.cpp index dc62f7760..f7307ef21 100644 --- a/Engine/source/T3D/physicalZone.cpp +++ b/Engine/source/T3D/physicalZone.cpp @@ -233,7 +233,7 @@ void PhysicalZone::renderObject( ObjectRenderInst *ri, drawer->drawPolyhedron( desc, mPolyhedron, ColorI( 0, 255, 0, 45 ) ); desc.setFillModeWireframe(); - drawer->drawPolyhedron( desc, mPolyhedron, ColorF::BLACK ); + drawer->drawPolyhedron( desc, mPolyhedron, ColorI::BLACK ); } //-------------------------------------------------------------------------- diff --git a/Engine/source/T3D/player.cpp b/Engine/source/T3D/player.cpp index 916a64c39..6b4e00aef 100644 --- a/Engine/source/T3D/player.cpp +++ b/Engine/source/T3D/player.cpp @@ -3893,7 +3893,7 @@ void Player::updateActionThread() ParticleEmitter * emitter = new ParticleEmitter; emitter->onNewDataBlock( mDataBlock->footPuffEmitter, false ); - ColorF colorList[ ParticleData::PDC_NUM_KEYS]; + LinearColorF colorList[ ParticleData::PDC_NUM_KEYS]; for( U32 x = 0; x < getMin( Material::NUM_EFFECT_COLOR_STAGES, ParticleData::PDC_NUM_KEYS ); ++ x ) colorList[ x ].set( material->mEffectColor[ x ].red, diff --git a/Engine/source/T3D/pointLight.cpp b/Engine/source/T3D/pointLight.cpp index 7376e8adc..6f9fd757d 100644 --- a/Engine/source/T3D/pointLight.cpp +++ b/Engine/source/T3D/pointLight.cpp @@ -167,7 +167,7 @@ void PointLight::_renderViz( SceneRenderState *state ) desc.setBlend( true ); // Base the sphere color on the light color. - ColorI color( mColor ); + ColorI color = mColor.toColorI(); color.alpha = 16; draw->drawSphere( desc, mRadius, getPosition(), color ); diff --git a/Engine/source/T3D/portal.cpp b/Engine/source/T3D/portal.cpp index 1318c632a..0f1a3cb3e 100644 --- a/Engine/source/T3D/portal.cpp +++ b/Engine/source/T3D/portal.cpp @@ -294,7 +294,7 @@ void Portal::_renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseM GFX->getDrawUtil()->drawPolygon( desc, mPortalPolygonWS.address(), mPortalPolygonWS.size(), color ); desc.setFillModeWireframe(); - GFX->getDrawUtil()->drawPolygon( desc, mPortalPolygonWS.address(), mPortalPolygonWS.size(), ColorF::RED ); + GFX->getDrawUtil()->drawPolygon( desc, mPortalPolygonWS.address(), mPortalPolygonWS.size(), ColorI::RED ); // Render rest. diff --git a/Engine/source/T3D/proximityMine.cpp b/Engine/source/T3D/proximityMine.cpp index 89ffe9577..bf43ab8c9 100644 --- a/Engine/source/T3D/proximityMine.cpp +++ b/Engine/source/T3D/proximityMine.cpp @@ -653,7 +653,7 @@ void ProximityMine::renderObject( ObjectRenderInst* ri, // Render the trigger area if ( mState == Armed || mState == Triggered ) { - const ColorF drawColor(1, 0, 0, 0.05f); + const LinearColorF drawColor(1, 0, 0, 0.05f); if ( drawColor.alpha > 0 ) { GFXStateBlockDesc desc; diff --git a/Engine/source/T3D/shapeBase.cpp b/Engine/source/T3D/shapeBase.cpp index 1fa265486..e612aa148 100644 --- a/Engine/source/T3D/shapeBase.cpp +++ b/Engine/source/T3D/shapeBase.cpp @@ -2389,7 +2389,7 @@ void ShapeBase::emitDust( ParticleEmitter* emitter, F32 triggerHeight, const Poi Material* material = ( rayInfo.material ? dynamic_cast< Material* >( rayInfo.material->getMaterial() ) : 0 ); if( material && material->mShowDust ) { - ColorF colorList[ ParticleData::PDC_NUM_KEYS ]; + LinearColorF colorList[ ParticleData::PDC_NUM_KEYS ]; for( U32 x = 0; x < getMin( Material::NUM_EFFECT_COLOR_STAGES, ParticleData::PDC_NUM_KEYS ); ++ x ) colorList[ x ] = material->mEffectColor[ x ]; diff --git a/Engine/source/T3D/shapeBase.h b/Engine/source/T3D/shapeBase.h index 49d810d13..98a42f73b 100644 --- a/Engine/source/T3D/shapeBase.h +++ b/Engine/source/T3D/shapeBase.h @@ -390,7 +390,7 @@ struct ShapeBaseImageData: public GameBaseData { S32 lightType; ///< Indicates the type of the light. /// /// One of: ConstantLight, PulsingLight, WeaponFireLight. - ColorF lightColor; + LinearColorF lightColor; S32 lightDuration; ///< The duration in SimTime of Pulsing or WeaponFire type lights. F32 lightRadius; ///< Extent of light. F32 lightBrightness; ///< Brightness of the light ( if it is WeaponFireLight ). diff --git a/Engine/source/T3D/spotLight.cpp b/Engine/source/T3D/spotLight.cpp index 1ec22cd48..4cc8ccb57 100644 --- a/Engine/source/T3D/spotLight.cpp +++ b/Engine/source/T3D/spotLight.cpp @@ -202,7 +202,7 @@ void SpotLight::_renderViz( SceneRenderState *state ) desc.setBlend( true ); // Base the color on the light color. - ColorI color( mColor ); + ColorI color = mColor.toColorI(); color.alpha = 16; F32 radius = mRange * mSin( mDegToRad( mOuterConeAngle * 0.5f ) ); diff --git a/Engine/source/T3D/vehicles/guiSpeedometer.cpp b/Engine/source/T3D/vehicles/guiSpeedometer.cpp index 847c24a8c..9d92bd5e2 100644 --- a/Engine/source/T3D/vehicles/guiSpeedometer.cpp +++ b/Engine/source/T3D/vehicles/guiSpeedometer.cpp @@ -41,7 +41,7 @@ class GuiSpeedometerHud : public GuiBitmapCtrl F32 mMaxAngle; ///< Max pos of needle F32 mMinAngle; ///< Min pos of needle Point2F mCenter; ///< Center of needle rotation - ColorF mColor; ///< Needle Color + LinearColorF mColor; ///< Needle Color F32 mNeedleLength; F32 mNeedleWidth; F32 mTailLength; diff --git a/Engine/source/T3D/vehicles/wheeledVehicle.cpp b/Engine/source/T3D/vehicles/wheeledVehicle.cpp index 765c15b92..17cfdfe6a 100644 --- a/Engine/source/T3D/vehicles/wheeledVehicle.cpp +++ b/Engine/source/T3D/vehicles/wheeledVehicle.cpp @@ -1235,7 +1235,7 @@ void WheeledVehicle::updateWheelParticles(F32 dt) if( material)//&& material->mShowDust ) { - ColorF colorList[ ParticleData::PDC_NUM_KEYS ]; + LinearColorF colorList[ ParticleData::PDC_NUM_KEYS ]; for( U32 x = 0; x < getMin( Material::NUM_EFFECT_COLOR_STAGES, ParticleData::PDC_NUM_KEYS ); ++ x ) colorList[ x ] = material->mEffectColor[ x ]; diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index fe55d4b29..df89a788a 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -1021,7 +1021,7 @@ DefineConsoleFunction( strrchrpos, S32, ( const char* str, const char* chr, S32 //---------------------------------------------------------------- -DefineConsoleFunction(ColorFloatToInt, ColorI, (ColorF color), , +DefineConsoleFunction(ColorFloatToInt, ColorI, (LinearColorF color), , "Convert from a float color to an integer color (0.0 - 1.0 to 0 to 255).\n" "@param color Float color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha.\n" "@return Converted color value (0 - 255)\n\n" @@ -1030,10 +1030,10 @@ DefineConsoleFunction(ColorFloatToInt, ColorI, (ColorF color), , "@endtsexample\n" "@ingroup Strings") { - return (ColorI)color; + return color.toColorI(); } -DefineConsoleFunction(ColorIntToFloat, ColorF, (ColorI color), , +DefineConsoleFunction(ColorIntToFloat, LinearColorF, (ColorI color), , "Convert from a integer color to an float color (0 to 255 to 0.0 - 1.0).\n" "@param color Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha.\n" "@return Converted color value (0.0 - 1.0)\n\n" @@ -1042,7 +1042,7 @@ DefineConsoleFunction(ColorIntToFloat, ColorF, (ColorI color), , "@endtsexample\n" "@ingroup Strings") { - return (ColorF)color; + return LinearColorF(color); } DefineConsoleFunction(ColorRGBToHEX, const char*, (ColorI color), , @@ -1080,10 +1080,8 @@ DefineConsoleFunction(ColorHEXToRGB, ColorI, (const char* hex), , "@endtsexample\n" "@ingroup Strings") { - S32 rgb = dAtoui(hex, 16); - ColorI color; - color.set(rgb & 0x000000FF, (rgb & 0x0000FF00) >> 8, (rgb & 0x00FF0000) >> 16); + color.set(String(hex)); return color; } diff --git a/Engine/source/console/consoleTypes.cpp b/Engine/source/console/consoleTypes.cpp index 09765bf34..e43473476 100644 --- a/Engine/source/console/consoleTypes.cpp +++ b/Engine/source/console/consoleTypes.cpp @@ -567,13 +567,13 @@ ConsoleSetType( TypeFlag ) //----------------------------------------------------------------------------- // TypeColorF //----------------------------------------------------------------------------- -ConsoleType(ColorF, TypeColorF, ColorF, "") -ImplementConsoleTypeCasters( TypeColorF, ColorF ) +ConsoleType(LinearColorF, TypeColorF, LinearColorF, "") +ImplementConsoleTypeCasters( TypeColorF, LinearColorF ) ConsoleGetType( TypeColorF ) { // Fetch color. - const ColorF* color = (ColorF*)dptr; + const LinearColorF* color = (LinearColorF*)dptr; // Fetch stock color name. StringTableEntry colorName = StockColor::name( *color ); @@ -591,7 +591,7 @@ ConsoleGetType( TypeColorF ) ConsoleSetType( TypeColorF ) { - ColorF *tmpColor = (ColorF *) dptr; + LinearColorF *tmpColor = (LinearColorF *) dptr; if(argc == 1) { // Is only a single argument passed? diff --git a/Engine/source/console/consoleTypes.h b/Engine/source/console/consoleTypes.h index 1285a213d..a5da7661e 100644 --- a/Engine/source/console/consoleTypes.h +++ b/Engine/source/console/consoleTypes.h @@ -122,7 +122,7 @@ DefineConsoleType( TypeParticleParameterString, const char * ) DefineConsoleType( TypeFlag, S32 ) DefineConsoleType( TypeColorI, ColorI ) -DefineConsoleType( TypeColorF, ColorF ) +DefineConsoleType( TypeColorF, LinearColorF ) DefineConsoleType( TypeSimObjectName, SimObject* ) DefineConsoleType( TypeShader, GFXShader * ) diff --git a/Engine/source/console/engineStructs.cpp b/Engine/source/console/engineStructs.cpp index 730e599aa..a71922073 100644 --- a/Engine/source/console/engineStructs.cpp +++ b/Engine/source/console/engineStructs.cpp @@ -63,8 +63,8 @@ IMPLEMENT_STRUCT( ColorI, END_IMPLEMENT_STRUCT; -IMPLEMENT_STRUCT( ColorF, - ColorF,, +IMPLEMENT_STRUCT( LinearColorF, + LinearColorF,, "RGBA color quadruple in 32bit floating-point precision per channel." ) FIELD( red, red, 1, "Red channel value." ) diff --git a/Engine/source/console/engineStructs.h b/Engine/source/console/engineStructs.h index 00ea098ee..8cbfad329 100644 --- a/Engine/source/console/engineStructs.h +++ b/Engine/source/console/engineStructs.h @@ -38,7 +38,7 @@ namespace Torque { } class ColorI; -class ColorF; +class LinearColorF; DECLARE_STRUCT_R(Vector< bool >); @@ -46,6 +46,6 @@ DECLARE_STRUCT_R(Vector< S32 >); DECLARE_STRUCT_R(Vector< F32 >); DECLARE_STRUCT_R(Torque::UUID); DECLARE_STRUCT_R(ColorI); -DECLARE_STRUCT_R(ColorF); +DECLARE_STRUCT_R(LinearColorF); #endif // !_ENGINESTRUCTS_H_ diff --git a/Engine/source/console/propertyParsing.cpp b/Engine/source/console/propertyParsing.cpp index 85cec8dc6..a97a84403 100644 --- a/Engine/source/console/propertyParsing.cpp +++ b/Engine/source/console/propertyParsing.cpp @@ -377,7 +377,7 @@ namespace PropertyInfo //----------------------------------------------------------------------------- // Colors //----------------------------------------------------------------------------- - bool default_scan(const String &data, ColorF & result) + bool default_scan(const String &data, LinearColorF & result) { if(StringUnit::getUnitCount(data," ") == 3) { @@ -389,7 +389,7 @@ namespace PropertyInfo return true; } - bool default_print(String & result, ColorF const & data) + bool default_print(String & result, LinearColorF const & data) { if(data.alpha == 1.0f) result = String::ToString("%g %g %g",data.red,data.green,data.blue); diff --git a/Engine/source/console/propertyParsing.h b/Engine/source/console/propertyParsing.h index 5ee60ac90..90272f9da 100644 --- a/Engine/source/console/propertyParsing.h +++ b/Engine/source/console/propertyParsing.h @@ -24,7 +24,7 @@ #define _PROPERTYPARSING_H_ class ColorI; -class ColorF; +class LinearColorF; class Point2I; class Point2F; class Point3F; @@ -110,8 +110,8 @@ namespace PropertyInfo bool default_print( String & result, const MatrixF & data ); // Colors - bool default_scan(const String &data, ColorF & result); - bool default_print(String & result, const ColorF & data); + bool default_scan(const String &data, LinearColorF & result); + bool default_print(String & result, const LinearColorF & data); bool default_scan(const String &data, ColorI & result); bool default_print(String & result, const ColorI & data); diff --git a/Engine/source/core/color.cpp b/Engine/source/core/color.cpp index a28ef430f..273a2a658 100644 --- a/Engine/source/core/color.cpp +++ b/Engine/source/core/color.cpp @@ -23,13 +23,13 @@ #include "platform/platform.h" #include "core/color.h" -const ColorF ColorF::ZERO( 0, 0, 0, 0 ); -const ColorF ColorF::ONE( 1, 1, 1, 1 ); -const ColorF ColorF::WHITE( 1, 1, 1 ); -const ColorF ColorF::BLACK( 0, 0, 0 ); -const ColorF ColorF::RED( 1, 0, 0 ); -const ColorF ColorF::GREEN( 0, 1, 0 ); -const ColorF ColorF::BLUE( 0, 0, 1 ); +const LinearColorF LinearColorF::ZERO( 0, 0, 0, 0 ); +const LinearColorF LinearColorF::ONE( 1, 1, 1, 1 ); +const LinearColorF LinearColorF::WHITE( 1, 1, 1 ); +const LinearColorF LinearColorF::BLACK( 0, 0, 0 ); +const LinearColorF LinearColorF::RED( 1, 0, 0 ); +const LinearColorF LinearColorF::GREEN( 0, 1, 0 ); +const LinearColorF LinearColorF::BLUE( 0, 0, 1 ); const ColorI ColorI::ZERO( 0, 0, 0, 0 ); const ColorI ColorI::ONE( 255, 255, 255, 255 ); @@ -54,9 +54,9 @@ const ColorI ColorI::BLUE( 0, 0, 255 ); //----------------------------------------------------------------------------- -typedef HashTable typeNameToColorFHash; +typedef HashTable typeNameToColorFHash; typedef HashTable typeNameToColorIHash; -typedef HashTable typeColorFToNameHash; +typedef HashTable typeColorFToNameHash; typedef HashTable typeColorIToNameHash; static typeNameToColorFHash mNameToColorF; @@ -299,7 +299,7 @@ bool StockColor::isColor( const char* pStockColorName ) //----------------------------------------------------------------------------- -const ColorF& StockColor::colorF( const char* pStockColorName ) +const LinearColorF& StockColor::colorF( const char* pStockColorName ) { // Sanity! AssertFatal( pStockColorName != NULL, "Cannot fetch a NULL stock color name." ); @@ -347,7 +347,7 @@ const ColorI& StockColor::colorI( const char* pStockColorName ) //----------------------------------------------------------------------------- -StringTableEntry StockColor::name( const ColorF& color ) +StringTableEntry StockColor::name( const LinearColorF& color ) { // Find stock color name. typeColorFToNameHash::Iterator colorNameItr = mColorFToName.find( color ); @@ -403,7 +403,7 @@ const StockColorItem* StockColor::getColorItem( const S32 index ) //----------------------------------------------------------------------------- -ColorF::ColorF( const char* pStockColorName ) +LinearColorF::LinearColorF( const char* pStockColorName ) { // Set stock color. *this = StockColor::colorF( pStockColorName ); @@ -411,7 +411,7 @@ ColorF::ColorF( const char* pStockColorName ) //----------------------------------------------------------------------------- -void ColorF::set( const char* pStockColorName ) +void LinearColorF::set( const char* pStockColorName ) { // Set stock color. *this = StockColor::colorF( pStockColorName ); @@ -419,14 +419,14 @@ void ColorF::set( const char* pStockColorName ) //----------------------------------------------------------------------------- -const ColorF& ColorF::StockColor( const char* pStockColorName ) +const LinearColorF& LinearColorF::StockColor( const char* pStockColorName ) { return StockColor::colorF( pStockColorName ); } //----------------------------------------------------------------------------- -StringTableEntry ColorF::StockColor( void ) +StringTableEntry LinearColorF::StockColor( void ) { // Return stock color name. return StockColor::name( *this ); @@ -465,6 +465,77 @@ StringTableEntry ColorI::StockColor( void ) //----------------------------------------------------------------------------- +#ifdef TORQUE_USE_LEGACY_GAMMA +//legacy pow 2.2 - powf(color, 2.2f); +float LinearColorF::sSrgbToLinear[256] = +{ + 0.000000f, 0.000005f, 0.000023f, 0.000057f, 0.000107f, 0.000175f, 0.000262f, 0.000367f, 0.000493f, + 0.000638f, 0.000805f, 0.000992f, 0.001202f, 0.001433f, 0.001687f, 0.001963f, 0.002263f, 0.002586f, + 0.002932f, 0.003303f, 0.003697f, 0.004116f, 0.004560f, 0.005028f, 0.005522f, 0.006041f, 0.006585f, + 0.007155f, 0.007751f, 0.008373f, 0.009021f, 0.009696f, 0.010398f, 0.011126f, 0.011881f, 0.012664f, + 0.013473f, 0.014311f, 0.015175f, 0.016068f, 0.016988f, 0.017936f, 0.018913f, 0.019918f, 0.020951f, + 0.022013f, 0.023104f, 0.024223f, 0.025371f, 0.026549f, 0.027755f, 0.028991f, 0.030257f, 0.031551f, + 0.032876f, 0.034230f, 0.035614f, 0.037029f, 0.038473f, 0.039947f, 0.041452f, 0.042987f, 0.044553f, + 0.046149f, 0.047776f, 0.049433f, 0.051122f, 0.052842f, 0.054592f, 0.056374f, 0.058187f, 0.060032f, + 0.061907f, 0.063815f, 0.065754f, 0.067725f, 0.069727f, 0.071761f, 0.073828f, 0.075926f, 0.078057f, + 0.080219f, 0.082414f, 0.084642f, 0.086901f, 0.089194f, 0.091518f, 0.093876f, 0.096266f, 0.098689f, + 0.101145f, 0.103634f, 0.106156f, 0.108711f, 0.111299f, 0.113921f, 0.116576f, 0.119264f, 0.121986f, + 0.124741f, 0.127530f, 0.130352f, 0.133209f, 0.136099f, 0.139022f, 0.141980f, 0.144972f, 0.147998f, + 0.151058f, 0.154152f, 0.157281f, 0.160444f, 0.163641f, 0.166872f, 0.170138f, 0.173439f, 0.176774f, + 0.180144f, 0.183549f, 0.186989f, 0.190463f, 0.193972f, 0.197516f, 0.201096f, 0.204710f, 0.208360f, + 0.212044f, 0.215764f, 0.219520f, 0.223310f, 0.227137f, 0.230998f, 0.234895f, 0.238828f, 0.242796f, + 0.246800f, 0.250840f, 0.254916f, 0.259027f, 0.263175f, 0.267358f, 0.271577f, 0.275833f, 0.280124f, + 0.284452f, 0.288816f, 0.293216f, 0.297653f, 0.302126f, 0.306635f, 0.311181f, 0.315763f, 0.320382f, + 0.325037f, 0.329729f, 0.334458f, 0.339223f, 0.344026f, 0.348865f, 0.353741f, 0.358654f, 0.363604f, + 0.368591f, 0.373615f, 0.378676f, 0.383775f, 0.388910f, 0.394083f, 0.399293f, 0.404541f, 0.409826f, + 0.415148f, 0.420508f, 0.425905f, 0.431340f, 0.436813f, 0.442323f, 0.447871f, 0.453456f, 0.459080f, + 0.464741f, 0.470440f, 0.476177f, 0.481952f, 0.487765f, 0.493616f, 0.499505f, 0.505432f, 0.511398f, + 0.517401f, 0.523443f, 0.529523f, 0.535642f, 0.541798f, 0.547994f, 0.554227f, 0.560499f, 0.566810f, + 0.573159f, 0.579547f, 0.585973f, 0.592438f, 0.598942f, 0.605484f, 0.612066f, 0.618686f, 0.625345f, + 0.632043f, 0.638779f, 0.645555f, 0.652370f, 0.659224f, 0.666117f, 0.673049f, 0.680020f, 0.687031f, + 0.694081f, 0.701169f, 0.708298f, 0.715465f, 0.722672f, 0.729919f, 0.737205f, 0.744530f, 0.751895f, + 0.759300f, 0.766744f, 0.774227f, 0.781751f, 0.789314f, 0.796917f, 0.804559f, 0.812241f, 0.819964f, + 0.827726f, 0.835528f, 0.843370f, 0.851252f, 0.859174f, 0.867136f, 0.875138f, 0.883180f, 0.891262f, + 0.899384f, 0.907547f, 0.915750f, 0.923993f, 0.932277f, 0.940601f, 0.948965f, 0.957370f, 0.965815f, + 0.974300f, 0.982826f, 0.991393f, 1.000000f +}; +#else +//sRGB - color < 0.04045f ? (1.0f / 12.92f) * color : powf((color + 0.055f) * (1.0f / 1.055f), 2.4f); +float LinearColorF::sSrgbToLinear[256] = +{ + 0.000000f, 0.000304f, 0.000607f, 0.000911f, 0.001214f, 0.001518f, 0.001821f, 0.002125f, 0.002428f, + 0.002732f, 0.003035f, 0.003347f, 0.003677f, 0.004025f, 0.004391f, 0.004777f, 0.005182f, 0.005605f, + 0.006049f, 0.006512f, 0.006995f, 0.007499f, 0.008023f, 0.008568f, 0.009134f, 0.009721f, 0.010330f, + 0.010960f, 0.011612f, 0.012286f, 0.012983f, 0.013702f, 0.014444f, 0.015209f, 0.015996f, 0.016807f, + 0.017642f, 0.018500f, 0.019382f, 0.020289f, 0.021219f, 0.022174f, 0.023153f, 0.024158f, 0.025187f, + 0.026241f, 0.027321f, 0.028426f, 0.029557f, 0.030713f, 0.031896f, 0.033105f, 0.034340f, 0.035601f, + 0.036889f, 0.038204f, 0.039546f, 0.040915f, 0.042311f, 0.043735f, 0.045186f, 0.046665f, 0.048172f, + 0.049707f, 0.051269f, 0.052861f, 0.054480f, 0.056128f, 0.057805f, 0.059511f, 0.061246f, 0.063010f, + 0.064803f, 0.066626f, 0.068478f, 0.070360f, 0.072272f, 0.074214f, 0.076185f, 0.078187f, 0.080220f, + 0.082283f, 0.084376f, 0.086500f, 0.088656f, 0.090842f, 0.093059f, 0.095307f, 0.097587f, 0.099899f, + 0.102242f, 0.104616f, 0.107023f, 0.109462f, 0.111932f, 0.114435f, 0.116971f, 0.119538f, 0.122139f, + 0.124772f, 0.127438f, 0.130136f, 0.132868f, 0.135633f, 0.138432f, 0.141263f, 0.144128f, 0.147027f, + 0.149960f, 0.152926f, 0.155926f, 0.158961f, 0.162029f, 0.165132f, 0.168269f, 0.171441f, 0.174647f, + 0.177888f, 0.181164f, 0.184475f, 0.187821f, 0.191202f, 0.194618f, 0.198069f, 0.201556f, 0.205079f, + 0.208637f, 0.212231f, 0.215861f, 0.219526f, 0.223228f, 0.226966f, 0.230740f, 0.234551f, 0.238398f, + 0.242281f, 0.246201f, 0.250158f, 0.254152f, 0.258183f, 0.262251f, 0.266356f, 0.270498f, 0.274677f, + 0.278894f, 0.283149f, 0.287441f, 0.291771f, 0.296138f, 0.300544f, 0.304987f, 0.309469f, 0.313989f, + 0.318547f, 0.323143f, 0.327778f, 0.332452f, 0.337164f, 0.341914f, 0.346704f, 0.351533f, 0.356400f, + 0.361307f, 0.366253f, 0.371238f, 0.376262f, 0.381326f, 0.386430f, 0.391573f, 0.396755f, 0.401978f, + 0.407240f, 0.412543f, 0.417885f, 0.423268f, 0.428691f, 0.434154f, 0.439657f, 0.445201f, 0.450786f, + 0.456411f, 0.462077f, 0.467784f, 0.473532f, 0.479320f, 0.485150f, 0.491021f, 0.496933f, 0.502886f, + 0.508881f, 0.514918f, 0.520996f, 0.527115f, 0.533276f, 0.539480f, 0.545725f, 0.552011f, 0.558340f, + 0.564712f, 0.571125f, 0.577581f, 0.584078f, 0.590619f, 0.597202f, 0.603827f, 0.610496f, 0.617207f, + 0.623960f, 0.630757f, 0.637597f, 0.644480f, 0.651406f, 0.658375f, 0.665387f, 0.672443f, 0.679543f, + 0.686685f, 0.693872f, 0.701102f, 0.708376f, 0.715694f, 0.723055f, 0.730461f, 0.737911f, 0.745404f, + 0.752942f, 0.760525f, 0.768151f, 0.775822f, 0.783538f, 0.791298f, 0.799103f, 0.806952f, 0.814847f, + 0.822786f, 0.830770f, 0.838799f, 0.846873f, 0.854993f, 0.863157f, 0.871367f, 0.879622f, 0.887923f, + 0.896269f, 0.904661f, 0.913099f, 0.921582f, 0.930111f, 0.938686f, 0.947307f, 0.955974f, 0.964686f, + 0.973445f, 0.982251f, 0.991102f, 1.000000f +}; +#endif +//----------------------------------------------------------------------------- + ConsoleFunction( getStockColorCount, S32, 1, 1, "() - Gets a count of available stock colors.\n" "@return A count of available stock colors." ) { @@ -513,7 +584,7 @@ ConsoleFunction( getStockColorF, const char*, 2, 2, "(stockColorName) - Gets a f return StringTable->EmptyString(); // Fetch stock color. - const ColorF& color = StockColor::colorF( pStockColorName ); + const LinearColorF& color = StockColor::colorF( pStockColorName ); // Format stock color. char* returnBuffer = Con::getReturnBuffer(256); diff --git a/Engine/source/core/color.h b/Engine/source/core/color.h index e429ac962..075662599 100644 --- a/Engine/source/core/color.h +++ b/Engine/source/core/color.h @@ -36,54 +36,48 @@ const F32 gGamma = 2.2f; const F32 gOneOverGamma = 1.f / 2.2f; +const F32 gOneOver255 = 1.f / 255.f; class ColorI; - -class ColorF +//32bit color in linear space +class LinearColorF { - public: +public: F32 red; F32 green; F32 blue; F32 alpha; - public: - ColorF() { } - ColorF(const ColorF& in_rCopy); - ColorF(const F32 in_r, - const F32 in_g, - const F32 in_b, - const F32 in_a = 1.0f); - - ColorF( const char* pStockColorName ); - - void set(const F32 in_r, - const F32 in_g, - const F32 in_b, - const F32 in_a = 1.0f); +public: + LinearColorF() : red(0), green(0), blue(0), alpha(0) {} + LinearColorF(const LinearColorF& in_rCopy); + LinearColorF(const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a = 1.0f); + LinearColorF(const ColorI &color); + LinearColorF(const char* pStockColorName); + void set( const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a = 1.0f ); void set( const char* pStockColorName ); - static const ColorF& StockColor( const char* pStockColorName ); + static const LinearColorF& StockColor( const char* pStockColorName ); StringTableEntry StockColor( void ); - ColorF& operator*=(const ColorF& in_mul); // Can be useful for lighting - ColorF operator*(const ColorF& in_mul) const; - ColorF& operator+=(const ColorF& in_rAdd); - ColorF operator+(const ColorF& in_rAdd) const; - ColorF& operator-=(const ColorF& in_rSub); - ColorF operator-(const ColorF& in_rSub) const; + LinearColorF& operator*=(const LinearColorF& in_mul); // Can be useful for lighting + LinearColorF operator*(const LinearColorF& in_mul) const; + LinearColorF& operator+=(const LinearColorF& in_rAdd); + LinearColorF operator+(const LinearColorF& in_rAdd) const; + LinearColorF& operator-=(const LinearColorF& in_rSub); + LinearColorF operator-(const LinearColorF& in_rSub) const; - ColorF& operator*=(const F32 in_mul); - ColorF operator*(const F32 in_mul) const; - ColorF& operator/=(const F32 in_div); - ColorF operator/(const F32 in_div) const; + LinearColorF& operator*=(const F32 in_mul); + LinearColorF operator*(const F32 in_mul) const; + LinearColorF& operator/=(const F32 in_div); + LinearColorF operator/(const F32 in_div) const; - ColorF operator-() const; + LinearColorF operator-() const; - bool operator==(const ColorF&) const; - bool operator!=(const ColorF&) const; + bool operator==(const LinearColorF&) const; + bool operator!=(const LinearColorF&) const; operator F32*() { return &red; } operator const F32*() const { return &red; } @@ -95,39 +89,38 @@ class ColorF U32 getRGBAPack() const; U32 getABGRPack() const; - operator ColorI() const; - - void interpolate(const ColorF& in_rC1, - const ColorF& in_rC2, + void interpolate(const LinearColorF& in_rC1, + const LinearColorF& in_rC2, const F32 in_factor); - bool isValidColor() const { return (red >= 0.0f && red <= 1.0f) && - (green >= 0.0f && green <= 1.0f) && - (blue >= 0.0f && blue <= 1.0f) && - (alpha >= 0.0f && alpha <= 1.0f); } + bool isClamped() const { return (red >= 0.0f && red <= 1.0f) && + (green >= 0.0f && green <= 1.0f) && + (blue >= 0.0f && blue <= 1.0f) && + (alpha >= 0.0f && alpha <= 1.0f); } void clamp(); - - ColorF toLinear(); - ColorF toGamma(); - //calculate luminance, make sure color is linear first + + //calculate luminance F32 luminance(); - static const ColorF ZERO; - static const ColorF ONE; - static const ColorF WHITE; - static const ColorF BLACK; - static const ColorF RED; - static const ColorF GREEN; - static const ColorF BLUE; + //convert to ColorI - slow operation, avoid when possible + ColorI toColorI(const bool keepAsLinear = false); + + static const LinearColorF ZERO; + static const LinearColorF ONE; + static const LinearColorF WHITE; + static const LinearColorF BLACK; + static const LinearColorF RED; + static const LinearColorF GREEN; + static const LinearColorF BLUE; + + static F32 sSrgbToLinear[256]; }; -//-------------------------------------- ColorI's are missing some of the operations -// present in ColorF since they cannot recover -// properly from over/underflow. +//8bit color in srgb space class ColorI { - public: +public: U8 red; U8 green; U8 blue; @@ -143,17 +136,13 @@ class ColorI U32 brightness; //Brightness/Value/Lightness }; - public: - ColorI() { } +public: + ColorI() : red(0), green(0), blue(0), alpha(0) {} ColorI(const ColorI& in_rCopy); ColorI(const Hsb& color); - ColorI(const U8 in_r, - const U8 in_g, - const U8 in_b, - const U8 in_a = U8(255)); + ColorI(const U8 in_r, const U8 in_g, const U8 in_b, const U8 in_a = U8(255)); ColorI(const ColorI& in_rCopy, const U8 in_a); - - ColorI( const char* pStockColorName ); + ColorI(const char* pStockColorName); void set(const Hsb& color); @@ -173,25 +162,10 @@ class ColorI static const ColorI& StockColor( const char* pStockColorName ); StringTableEntry StockColor( void ); - - ColorI& operator*=(const F32 in_mul); - ColorI operator*(const F32 in_mul) const; - - ColorI operator+(const ColorI& in_rAdd) const; - ColorI& operator+=(const ColorI& in_rAdd); - - ColorI& operator*=(const S32 in_mul); - ColorI& operator/=(const S32 in_mul); - ColorI operator*(const S32 in_mul) const; - ColorI operator/(const S32 in_mul) const; - + bool operator==(const ColorI&) const; bool operator!=(const ColorI&) const; - - void interpolate(const ColorI& in_rC1, - const ColorI& in_rC2, - const F32 in_factor); - + U32 getARGBPack() const; U32 getRGBAPack() const; U32 getABGRPack() const; @@ -210,13 +184,11 @@ class ColorI String getHex() const; S32 convertFromHex(const String& hex) const; - operator ColorF() const; - operator const U8*() const { return &red; } - ColorI toLinear(); - ColorI toGamma(); - + //convert linear color to srgb - slow operation, avoid when possible + ColorI fromLinear(); + static const ColorI ZERO; static const ColorI ONE; static const ColorI WHITE; @@ -247,11 +219,11 @@ public: } inline const char* getColorName( void ) const { return mColorName; } - inline const ColorF& getColorF( void ) const { return mColorF; } + inline const LinearColorF& getColorF( void ) const { return mColorF; } inline const ColorI& getColorI( void ) const { return mColorI; } const char* mColorName; - ColorF mColorF; + LinearColorF mColorF; ColorI mColorI; }; @@ -261,9 +233,9 @@ class StockColor { public: static bool isColor( const char* pStockColorName ); - static const ColorF& colorF( const char* pStockColorName ); + static const LinearColorF& colorF( const char* pStockColorName ); static const ColorI& colorI( const char* pStockColorName ); - static StringTableEntry name( const ColorF& color ); + static StringTableEntry name( const LinearColorF& color ); static StringTableEntry name( const ColorI& color ); static S32 getCount( void ); @@ -274,12 +246,9 @@ public: }; //------------------------------------------------------------------------------ -//-------------------------------------- INLINES (ColorF) +//-------------------------------------- INLINES (LinearColorF) // -inline void ColorF::set(const F32 in_r, - const F32 in_g, - const F32 in_b, - const F32 in_a) +inline void LinearColorF::set(const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a) { red = in_r; green = in_g; @@ -287,7 +256,7 @@ inline void ColorF::set(const F32 in_r, alpha = in_a; } -inline ColorF::ColorF(const ColorF& in_rCopy) +inline LinearColorF::LinearColorF(const LinearColorF& in_rCopy) { red = in_rCopy.red; green = in_rCopy.green; @@ -295,15 +264,12 @@ inline ColorF::ColorF(const ColorF& in_rCopy) alpha = in_rCopy.alpha; } -inline ColorF::ColorF(const F32 in_r, - const F32 in_g, - const F32 in_b, - const F32 in_a) +inline LinearColorF::LinearColorF(const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a) { set(in_r, in_g, in_b, in_a); } -inline ColorF& ColorF::operator*=(const ColorF& in_mul) +inline LinearColorF& LinearColorF::operator*=(const LinearColorF& in_mul) { red *= in_mul.red; green *= in_mul.green; @@ -313,108 +279,98 @@ inline ColorF& ColorF::operator*=(const ColorF& in_mul) return *this; } -inline ColorF ColorF::operator*(const ColorF& in_mul) const +inline LinearColorF LinearColorF::operator*(const LinearColorF& in_mul) const { - return ColorF(red * in_mul.red, - green * in_mul.green, - blue * in_mul.blue, - alpha * in_mul.alpha); + LinearColorF tmp(*this); + tmp *= in_mul; + return tmp; } -inline ColorF& ColorF::operator+=(const ColorF& in_rAdd) +inline LinearColorF& LinearColorF::operator+=(const LinearColorF& in_rAdd) { - red += in_rAdd.red; + red += in_rAdd.red; green += in_rAdd.green; - blue += in_rAdd.blue; + blue += in_rAdd.blue; alpha += in_rAdd.alpha; - return *this; } -inline ColorF ColorF::operator+(const ColorF& in_rAdd) const +inline LinearColorF LinearColorF::operator+(const LinearColorF& in_rAdd) const { - return ColorF(red + in_rAdd.red, - green + in_rAdd.green, - blue + in_rAdd.blue, - alpha + in_rAdd.alpha); + LinearColorF temp(*this); + temp += in_rAdd; + return temp; } -inline ColorF& ColorF::operator-=(const ColorF& in_rSub) +inline LinearColorF& LinearColorF::operator-=(const LinearColorF& in_rSub) { - red -= in_rSub.red; + red -= in_rSub.red; green -= in_rSub.green; - blue -= in_rSub.blue; + blue -= in_rSub.blue; alpha -= in_rSub.alpha; - return *this; } -inline ColorF ColorF::operator-(const ColorF& in_rSub) const +inline LinearColorF LinearColorF::operator-(const LinearColorF& in_rSub) const { - return ColorF(red - in_rSub.red, - green - in_rSub.green, - blue - in_rSub.blue, - alpha - in_rSub.alpha); + LinearColorF tmp(*this); + tmp -= in_rSub; + return tmp; } -inline ColorF& ColorF::operator*=(const F32 in_mul) +inline LinearColorF& LinearColorF::operator*=(const F32 in_mul) { red *= in_mul; green *= in_mul; blue *= in_mul; alpha *= in_mul; - return *this; } -inline ColorF ColorF::operator*(const F32 in_mul) const +inline LinearColorF LinearColorF::operator*(const F32 in_mul) const { - return ColorF(red * in_mul, - green * in_mul, - blue * in_mul, - alpha * in_mul); + LinearColorF tmp(*this); + tmp *= in_mul; + return tmp; } -inline ColorF& ColorF::operator/=(const F32 in_div) +inline LinearColorF& LinearColorF::operator/=(const F32 in_div) { AssertFatal(in_div != 0.0f, "Error, div by zero..."); F32 inv = 1.0f / in_div; - red *= inv; + red *= inv; green *= inv; - blue *= inv; + blue *= inv; alpha *= inv; - return *this; } -inline ColorF ColorF::operator/(const F32 in_div) const +inline LinearColorF LinearColorF::operator/(const F32 in_div) const { AssertFatal(in_div != 0.0f, "Error, div by zero..."); F32 inv = 1.0f / in_div; - - return ColorF(red * inv, - green * inv, - blue * inv, - alpha * inv); + LinearColorF tmp(*this); + tmp /= inv; + return tmp; } -inline ColorF ColorF::operator-() const +inline LinearColorF LinearColorF::operator-() const { - return ColorF(-red, -green, -blue, -alpha); + return LinearColorF(-red, -green, -blue, -alpha); } -inline bool ColorF::operator==(const ColorF& in_Cmp) const +inline bool LinearColorF::operator==(const LinearColorF& in_Cmp) const { return (red == in_Cmp.red && green == in_Cmp.green && blue == in_Cmp.blue && alpha == in_Cmp.alpha); } -inline bool ColorF::operator!=(const ColorF& in_Cmp) const +inline bool LinearColorF::operator!=(const LinearColorF& in_Cmp) const { return (red != in_Cmp.red || green != in_Cmp.green || blue != in_Cmp.blue || alpha != in_Cmp.alpha); } -inline U32 ColorF::getARGBPack() const +inline U32 LinearColorF::getARGBPack() const { return (U32(alpha * 255.0f + 0.5) << 24) | (U32(red * 255.0f + 0.5) << 16) | @@ -422,7 +378,7 @@ inline U32 ColorF::getARGBPack() const (U32(blue * 255.0f + 0.5) << 0); } -inline U32 ColorF::getRGBAPack() const +inline U32 LinearColorF::getRGBAPack() const { return ( U32( red * 255.0f + 0.5) << 0 ) | ( U32( green * 255.0f + 0.5) << 8 ) | @@ -430,7 +386,7 @@ inline U32 ColorF::getRGBAPack() const ( U32( alpha * 255.0f + 0.5) << 24 ); } -inline U32 ColorF::getABGRPack() const +inline U32 LinearColorF::getABGRPack() const { return (U32(alpha * 255.0f + 0.5) << 24) | (U32(blue * 255.0f + 0.5) << 16) | @@ -439,61 +395,43 @@ inline U32 ColorF::getABGRPack() const } -inline void ColorF::interpolate(const ColorF& in_rC1, - const ColorF& in_rC2, +inline void LinearColorF::interpolate(const LinearColorF& in_rC1, + const LinearColorF& in_rC2, const F32 in_factor) { + if (in_factor <= 0 || in_rC1 == in_rC2) + { + red = in_rC1.red; + green = in_rC1.green; + blue =in_rC1.blue; + alpha = in_rC1.alpha; + return; + } + else if (in_factor >= 1) + { + red = in_rC2.red; + green = in_rC2.green; + blue = in_rC2.blue; + alpha = in_rC2.alpha; + return; + } + F32 f2 = 1.0f - in_factor; - red = (in_rC1.red * f2) + (in_rC2.red * in_factor); + red = (in_rC1.red * f2) + (in_rC2.red * in_factor); green = (in_rC1.green * f2) + (in_rC2.green * in_factor); - blue = (in_rC1.blue * f2) + (in_rC2.blue * in_factor); + blue = (in_rC1.blue * f2) + (in_rC2.blue * in_factor); alpha = (in_rC1.alpha * f2) + (in_rC2.alpha * in_factor); } -inline void ColorF::clamp() +inline void LinearColorF::clamp() { - if (red > 1.0f) - red = 1.0f; - else if (red < 0.0f) - red = 0.0f; - - if (green > 1.0f) - green = 1.0f; - else if (green < 0.0f) - green = 0.0f; - - if (blue > 1.0f) - blue = 1.0f; - else if (blue < 0.0f) - blue = 0.0f; - - if (alpha > 1.0f) - alpha = 1.0f; - else if (alpha < 0.0f) - alpha = 0.0f; + red = mClampF(red, 0.0f, 1.0f); + green = mClampF(green, 0.0f, 1.0f); + blue = mClampF(blue, 0.0f, 1.0f); + alpha = mClampF(alpha, 0.0f, 1.0f); } -inline ColorF ColorF::toGamma() -{ - ColorF color; - color.red = mPow(red,gOneOverGamma); - color.green = mPow(green, gOneOverGamma); - color.blue = mPow(blue, gOneOverGamma); - color.alpha = alpha; - return color; -} - -inline ColorF ColorF::toLinear() -{ - ColorF color; - color.red = mPow(red,gGamma); - color.green = mPow(green, gGamma); - color.blue = mPow(blue, gGamma); - color.alpha = alpha; - return color; -} - -inline F32 ColorF::luminance() +inline F32 LinearColorF::luminance() { // ITU BT.709 //return red * 0.2126f + green * 0.7152f + blue * 0.0722f; @@ -719,70 +657,6 @@ inline ColorI::ColorI(const ColorI& in_rCopy, set(in_rCopy, in_a); } -inline ColorI& ColorI::operator*=(const F32 in_mul) -{ - red = U8((F32(red) * in_mul) + 0.5f); - green = U8((F32(green) * in_mul) + 0.5f); - blue = U8((F32(blue) * in_mul) + 0.5f); - alpha = U8((F32(alpha) * in_mul) + 0.5f); - - return *this; -} - -inline ColorI& ColorI::operator*=(const S32 in_mul) -{ - red = red * in_mul; - green = green * in_mul; - blue = blue * in_mul; - alpha = alpha * in_mul; - - return *this; -} - -inline ColorI& ColorI::operator/=(const S32 in_mul) -{ - AssertFatal(in_mul != 0.0f, "Error, div by zero..."); - red = red / in_mul; - green = green / in_mul; - blue = blue / in_mul; - alpha = alpha / in_mul; - - return *this; -} - -inline ColorI ColorI::operator+(const ColorI &in_add) const -{ - ColorI tmp; - - tmp.red = red + in_add.red; - tmp.green = green + in_add.green; - tmp.blue = blue + in_add.blue; - tmp.alpha = alpha + in_add.alpha; - - return tmp; -} - -inline ColorI ColorI::operator*(const F32 in_mul) const -{ - ColorI temp(*this); - temp *= in_mul; - return temp; -} - -inline ColorI ColorI::operator*(const S32 in_mul) const -{ - ColorI temp(*this); - temp *= in_mul; - return temp; -} - -inline ColorI ColorI::operator/(const S32 in_mul) const -{ - ColorI temp(*this); - temp /= in_mul; - return temp; -} - inline bool ColorI::operator==(const ColorI& in_Cmp) const { return (red == in_Cmp.red && green == in_Cmp.green && blue == in_Cmp.blue && alpha == in_Cmp.alpha); @@ -793,27 +667,6 @@ inline bool ColorI::operator!=(const ColorI& in_Cmp) const return (red != in_Cmp.red || green != in_Cmp.green || blue != in_Cmp.blue || alpha != in_Cmp.alpha); } -inline ColorI& ColorI::operator+=(const ColorI& in_rAdd) -{ - red += in_rAdd.red; - green += in_rAdd.green; - blue += in_rAdd.blue; - alpha += in_rAdd.alpha; - - return *this; -} - -inline void ColorI::interpolate(const ColorI& in_rC1, - const ColorI& in_rC2, - const F32 in_factor) -{ - F32 f2= 1.0f - in_factor; - red = U8(((F32(in_rC1.red) * f2) + (F32(in_rC2.red) * in_factor)) + 0.5f); - green = U8(((F32(in_rC1.green) * f2) + (F32(in_rC2.green) * in_factor)) + 0.5f); - blue = U8(((F32(in_rC1.blue) * f2) + (F32(in_rC2.blue) * in_factor)) + 0.5f); - alpha = U8(((F32(in_rC1.alpha) * f2) + (F32(in_rC2.alpha) * in_factor)) + 0.5f); -} - inline U32 ColorI::getARGBPack() const { return (U32(alpha) << 24) | @@ -971,35 +824,72 @@ inline String ColorI::getHex() const return result; } -inline ColorI ColorI::toGamma() +inline LinearColorF::LinearColorF( const ColorI &color) { - ColorF color = (ColorF)*this; - return (ColorI)color.toGamma(); + red = sSrgbToLinear[color.red], + green = sSrgbToLinear[color.green], + blue = sSrgbToLinear[color.blue], + alpha = F32(color.alpha * gOneOver255); } -inline ColorI ColorI::toLinear() +inline ColorI LinearColorF::toColorI(const bool keepAsLinear) { - ColorF color = (ColorF)*this; - return (ColorI)color.toLinear(); + if (isClamped()) + { + if (keepAsLinear) + { + return ColorI(U8(red * 255.0f + 0.5), U8(green * 255.0f + 0.5), U8(blue * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); + } + else + { + #ifdef TORQUE_USE_LEGACY_GAMMA + float r = mPow(red, gOneOverGamma); + float g = mPow(green, gOneOverGamma); + float b = mPow(blue, gOneOverGamma); + return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); + #else + float r = red < 0.0031308f ? 12.92f * red : 1.055 * mPow(red, 1.0f / 2.4f) - 0.055f; + float g = green < 0.0031308f ? 12.92f * green : 1.055 * mPow(green, 1.0f / 2.4f) - 0.055f; + float b = blue < 0.0031308f ? 12.92f * blue : 1.055 * mPow(blue, 1.0f / 2.4f) - 0.055f; + return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); + #endif + } + } + else + { + LinearColorF color = LinearColorF(*this); + color.clamp(); + + if (keepAsLinear) + { + return ColorI(U8(color.red * 255.0f + 0.5), U8(color.green * 255.0f + 0.5), U8(color.blue * 255.0f + 0.5), U8(color.alpha * 255.0f + 0.5)); + } + else + { + #ifdef TORQUE_USE_LEGACY_GAMMA + float r = mPow(red, gOneOverGamma); + float g = mPow(green, gOneOverGamma); + float b = mPow(blue, gOneOverGamma); + return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); + #else + float r = red < 0.0031308f ? 12.92f * red : 1.055 * mPow(red, 1.0f / 2.4f) - 0.055f; + float g = green < 0.0031308f ? 12.92f * green : 1.055 * mPow(green, 1.0f / 2.4f) - 0.055f; + float b = blue < 0.0031308f ? 12.92f * blue : 1.055 * mPow(blue, 1.0f / 2.4f) - 0.055f; + return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); + #endif + } + } } -//-------------------------------------- INLINE CONVERSION OPERATORS -inline ColorF::operator ColorI() const +inline ColorI ColorI::fromLinear() { - return ColorI(U8(red * 255.0f + 0.5), - U8(green * 255.0f + 0.5), - U8(blue * 255.0f + 0.5), - U8(alpha * 255.0f + 0.5)); -} - -inline ColorI::operator ColorF() const -{ - const F32 inv255 = 1.0f / 255.0f; - - return ColorF(F32(red) * inv255, - F32(green) * inv255, - F32(blue) * inv255, - F32(alpha) * inv255); + //manually create LinearColorF, otherwise it will try and convert to linear first + LinearColorF linearColor = LinearColorF(F32(red) * 255.0f + 0.5f, + F32(red) * 255.0f + 0.5f, + F32(red) * 255.0f + 0.5f, + F32(alpha) * 255.0f + 0.5f); + //convert back to srgb + return linearColor.toColorI(); } #endif //_COLOR_H_ diff --git a/Engine/source/core/stream/stream.cpp b/Engine/source/core/stream/stream.cpp index 247feef76..4618aeade 100644 --- a/Engine/source/core/stream/stream.cpp +++ b/Engine/source/core/stream/stream.cpp @@ -271,9 +271,9 @@ bool Stream::write(const ColorI& rColor) return success; } -bool Stream::write(const ColorF& rColor) +bool Stream::write(const LinearColorF& rColor) { - ColorI temp = rColor; + ColorI temp = LinearColorF(rColor).toColorI(); return write(temp); } @@ -287,7 +287,7 @@ bool Stream::read(ColorI* pColor) return success; } -bool Stream::read(ColorF* pColor) +bool Stream::read(LinearColorF* pColor) { ColorI temp; bool success = read(&temp); diff --git a/Engine/source/core/stream/stream.h b/Engine/source/core/stream/stream.h index b52d8f987..2db20dde3 100644 --- a/Engine/source/core/stream/stream.h +++ b/Engine/source/core/stream/stream.h @@ -41,7 +41,7 @@ /// @} class ColorI; -class ColorF; +class LinearColorF; struct NetAddress; class RawData; class String; @@ -155,11 +155,11 @@ public: /// Write an integral color to the stream. bool write(const ColorI&); /// Write a floating point color to the stream. - bool write(const ColorF&); + bool write(const LinearColorF&); /// Read an integral color from the stream. bool read(ColorI*); /// Read a floating point color from the stream. - bool read(ColorF*); + bool read(LinearColorF*); /// Write a network address to the stream. bool write(const NetAddress &); diff --git a/Engine/source/core/util/rgb2luv.cpp b/Engine/source/core/util/rgb2luv.cpp index 71225f729..790b96cdf 100644 --- a/Engine/source/core/util/rgb2luv.cpp +++ b/Engine/source/core/util/rgb2luv.cpp @@ -31,12 +31,12 @@ namespace ConvertRGB { -ColorF toLUV( const ColorF &rgbColor ) +LinearColorF toLUV( const LinearColorF &rgbColor ) { static const Point3F scXYZLUVDot( 1.0f, 15.0f, 3.0f ); static const Point2F sc49( 4.0f, 9.0f ); - ColorF xyzColor = ConvertRGB::toXYZ( rgbColor ); + LinearColorF xyzColor = ConvertRGB::toXYZ( rgbColor ); const Point2F &xyz_xy = *((Point2F *)&xyzColor); @@ -44,12 +44,12 @@ ColorF toLUV( const ColorF &rgbColor ) uvColor.convolve( xyz_xy ); uvColor /= mDot( *(Point3F *)&xyzColor, scXYZLUVDot ); - return ColorF( uvColor.x, uvColor.y, xyzColor.green, rgbColor.alpha ); + return LinearColorF( uvColor.x, uvColor.y, xyzColor.green, rgbColor.alpha ); } -ColorF toLUVScaled( const ColorF &rgbColor ) +LinearColorF toLUVScaled( const LinearColorF &rgbColor ) { - ColorF luvColor = toLUV( rgbColor ); + LinearColorF luvColor = toLUV( rgbColor ); luvColor.red /= 0.62f; luvColor.green /= 0.62f; return luvColor; diff --git a/Engine/source/core/util/rgb2luv.h b/Engine/source/core/util/rgb2luv.h index 9bb20bd65..7685cc969 100644 --- a/Engine/source/core/util/rgb2luv.h +++ b/Engine/source/core/util/rgb2luv.h @@ -29,9 +29,9 @@ namespace ConvertRGB { - ColorF toLUV( const ColorF &rgbColor ); - ColorF toLUVScaled( const ColorF &rgbColor ); - ColorF fromLUV( const ColorF &luvColor ); + LinearColorF toLUV( const LinearColorF &rgbColor ); + LinearColorF toLUVScaled( const LinearColorF &rgbColor ); + LinearColorF fromLUV( const LinearColorF &luvColor ); }; #endif \ No newline at end of file diff --git a/Engine/source/core/util/rgb2xyz.cpp b/Engine/source/core/util/rgb2xyz.cpp index e402971d0..4b5739832 100644 --- a/Engine/source/core/util/rgb2xyz.cpp +++ b/Engine/source/core/util/rgb2xyz.cpp @@ -46,20 +46,20 @@ static const F32 scXYZ2RGB[] = 0.0f, 0.0f, 0.0f, 1.0f, }; -ColorF toXYZ( const ColorF &rgbColor ) +LinearColorF toXYZ( const LinearColorF &rgbColor ) { const MatrixF &rgb2xyz = *((MatrixF *)scRGB2XYZ); - ColorF retColor = rgbColor; + LinearColorF retColor = rgbColor; rgb2xyz.mul( *(Point4F *)&retColor ); return retColor; } -ColorF fromXYZ( const ColorF &xyzColor ) +LinearColorF fromXYZ( const LinearColorF &xyzColor ) { const MatrixF &xyz2rgb = *((MatrixF *)scXYZ2RGB); - ColorF retColor = xyzColor; + LinearColorF retColor = xyzColor; xyz2rgb.mul( *(Point4F *)&retColor ); return retColor; } diff --git a/Engine/source/core/util/rgb2xyz.h b/Engine/source/core/util/rgb2xyz.h index f5e9e9c50..18ae0d227 100644 --- a/Engine/source/core/util/rgb2xyz.h +++ b/Engine/source/core/util/rgb2xyz.h @@ -27,8 +27,8 @@ namespace ConvertRGB { - ColorF toXYZ( const ColorF &rgbColor ); - ColorF fromXYZ( const ColorF &xyzColor ); + LinearColorF toXYZ( const LinearColorF &rgbColor ); + LinearColorF fromXYZ( const LinearColorF &xyzColor ); }; #endif \ No newline at end of file diff --git a/Engine/source/environment/VolumetricFog.cpp b/Engine/source/environment/VolumetricFog.cpp index 999a4d527..d0ed20665 100644 --- a/Engine/source/environment/VolumetricFog.cpp +++ b/Engine/source/environment/VolumetricFog.cpp @@ -1074,7 +1074,7 @@ void VolumetricFog::render(ObjectRenderInst *ri, SceneRenderState *state, BaseMa mPPShaderConsts->setSafe(mPPModelViewProjSC, xform); - const ColorF &sunlight = state->getAmbientLightColor(); + const LinearColorF &sunlight = state->getAmbientLightColor(); Point3F ambientColor(sunlight.red, sunlight.green, sunlight.blue); mShaderConsts->setSafe(mAmbientColorSC, ambientColor); @@ -1204,7 +1204,7 @@ void VolumetricFog::InitTexture() mIsTextured = false; if (mTextureName.isNotEmpty()) - mTexture.set(mTextureName, &GFXDefaultStaticDiffuseProfile, "VolumetricFogMod"); + mTexture.set(mTextureName, &GFXStaticTextureSRGBProfile, "VolumetricFogMod"); if (!mTexture.isNull()) { @@ -1218,7 +1218,7 @@ void VolumetricFog::InitTexture() } } -void VolumetricFog::setFogColor(ColorF color) +void VolumetricFog::setFogColor(LinearColorF color) { mFogColor.set(255 * color.red,255 * color.green,255 * color.blue); setMaskBits(FogColorMask); @@ -1266,7 +1266,7 @@ bool VolumetricFog::isInsideFog() return mCamInFog; } -DefineEngineMethod(VolumetricFog, SetFogColorF, void, (ColorF new_color), , +DefineEngineMethod(VolumetricFog, SetFogColorF, void, (LinearColorF new_color), , "@brief Changes the color of the fog\n\n." "@params new_color the new fog color (rgb 0.0 - 1.0, a is ignored.") { diff --git a/Engine/source/environment/VolumetricFog.h b/Engine/source/environment/VolumetricFog.h index ce06aafaf..92da5aa14 100644 --- a/Engine/source/environment/VolumetricFog.h +++ b/Engine/source/environment/VolumetricFog.h @@ -227,7 +227,7 @@ class VolumetricFog : public SceneObject // Methods for modifying & networking various fog elements // Used in script - void setFogColor(ColorF color); + void setFogColor(LinearColorF color); void setFogColor(ColorI color); void setFogDensity(F32 density); void setFogModulation(F32 strength, Point2F speed1, Point2F speed2); diff --git a/Engine/source/environment/VolumetricFogRTManager.cpp b/Engine/source/environment/VolumetricFogRTManager.cpp index 8c98983b2..7b7b00d50 100644 --- a/Engine/source/environment/VolumetricFogRTManager.cpp +++ b/Engine/source/environment/VolumetricFogRTManager.cpp @@ -150,7 +150,7 @@ bool VolumetricFogRTManager::Init() mHeight = mFloor(mPlatformWindow->getClientExtent().y / mTargetScale); mDepthBuffer = GFXTexHandle(mWidth, mHeight, GFXFormatR32F, - &GFXDefaultRenderTargetProfile, avar("%s() - mDepthBuffer (line %d)", __FUNCTION__, __LINE__)); + &GFXRenderTargetProfile, avar("%s() - mDepthBuffer (line %d)", __FUNCTION__, __LINE__)); if (!mDepthBuffer.isValid()) { Con::errorf("VolumetricFogRTManager Fatal Error: Unable to create Depthbuffer"); @@ -164,7 +164,7 @@ bool VolumetricFogRTManager::Init() mDepthTarget.setTexture(mDepthBuffer); mFrontBuffer = GFXTexHandle(mWidth, mHeight, GFXFormatR32F, - &GFXDefaultRenderTargetProfile, avar("%s() - mFrontBuffer (line %d)", __FUNCTION__, __LINE__)); + &GFXRenderTargetProfile, avar("%s() - mFrontBuffer (line %d)", __FUNCTION__, __LINE__)); if (!mFrontBuffer.isValid()) { Con::errorf("VolumetricFogRTManager Fatal Error: Unable to create front buffer"); @@ -240,7 +240,7 @@ bool VolumetricFogRTManager::Resize() mFrontBuffer->kill(); mFrontBuffer = GFXTexHandle(mWidth, mHeight, GFXFormatR32F, - &GFXDefaultRenderTargetProfile, avar("%s() - mFrontBuffer (line %d)", __FUNCTION__, __LINE__)); + &GFXRenderTargetProfile, avar("%s() - mFrontBuffer (line %d)", __FUNCTION__, __LINE__)); if (!mFrontBuffer.isValid()) { Con::errorf("VolumetricFogRTManager::Resize() Fatal Error: Unable to create front buffer"); @@ -249,7 +249,7 @@ bool VolumetricFogRTManager::Resize() mFrontTarget.setTexture(mFrontBuffer); mDepthBuffer = GFXTexHandle(mWidth, mHeight, GFXFormatR32F, - &GFXDefaultRenderTargetProfile, avar("%s() - mDepthBuffer (line %d)", __FUNCTION__, __LINE__)); + &GFXRenderTargetProfile, avar("%s() - mDepthBuffer (line %d)", __FUNCTION__, __LINE__)); if (!mDepthBuffer.isValid()) { Con::errorf("VolumetricFogRTManager::Resize() Fatal Error: Unable to create Depthbuffer"); diff --git a/Engine/source/environment/basicClouds.cpp b/Engine/source/environment/basicClouds.cpp index 979579c2f..88cd394e9 100644 --- a/Engine/source/environment/basicClouds.cpp +++ b/Engine/source/environment/basicClouds.cpp @@ -341,10 +341,10 @@ void BasicClouds::_initTexture() } if ( mTexName[i].isNotEmpty() ) - mTexture[i].set( mTexName[i], &GFXDefaultStaticDiffuseProfile, "BasicClouds" ); + mTexture[i].set( mTexName[i], &GFXStaticTextureSRGBProfile, "BasicClouds" ); if ( mTexture[i].isNull() ) - mTexture[i].set( GFXTextureManager::getWarningTexturePath(), &GFXDefaultStaticDiffuseProfile, "BasicClouds" ); + mTexture[i].set( GFXTextureManager::getWarningTexturePath(), &GFXStaticTextureSRGBProfile, "BasicClouds" ); } } diff --git a/Engine/source/environment/cloudLayer.cpp b/Engine/source/environment/cloudLayer.cpp index 3fe02368f..e30f1ecd1 100644 --- a/Engine/source/environment/cloudLayer.cpp +++ b/Engine/source/environment/cloudLayer.cpp @@ -353,12 +353,12 @@ void CloudLayer::renderObject( ObjectRenderInst *ri, SceneRenderState *state, Ba mShaderConsts->setSafe( mEyePosWorldSC, camPos ); LightInfo *lightinfo = LIGHTMGR->getSpecialLight(LightManager::slSunLightType); - const ColorF &sunlight = state->getAmbientLightColor(); + const LinearColorF &sunlight = state->getAmbientLightColor(); Point3F ambientColor( sunlight.red, sunlight.green, sunlight.blue ); mShaderConsts->setSafe( mAmbientColorSC, ambientColor ); - const ColorF &sunColor = lightinfo->getColor(); + const LinearColorF &sunColor = lightinfo->getColor(); Point3F data( sunColor.red, sunColor.green, sunColor.blue ); mShaderConsts->setSafe( mSunColorSC, data ); @@ -398,10 +398,10 @@ void CloudLayer::_initTexture() } if ( mTextureName.isNotEmpty() ) - mTexture.set( mTextureName, &GFXDefaultStaticDiffuseProfile, "CloudLayer" ); + mTexture.set( mTextureName, &GFXStaticTextureSRGBProfile, "CloudLayer" ); if ( mTexture.isNull() ) - mTexture.set( GFXTextureManager::getWarningTexturePath(), &GFXDefaultStaticDiffuseProfile, "CloudLayer" ); + mTexture.set( GFXTextureManager::getWarningTexturePath(), &GFXStaticTextureSRGBProfile, "CloudLayer" ); } void CloudLayer::_initBuffers() diff --git a/Engine/source/environment/cloudLayer.h b/Engine/source/environment/cloudLayer.h index 076c3a631..96c98cf8a 100644 --- a/Engine/source/environment/cloudLayer.h +++ b/Engine/source/environment/cloudLayer.h @@ -125,7 +125,7 @@ protected: Point2F mTexDirection[TEX_COUNT]; F32 mTexSpeed[TEX_COUNT]; - ColorF mBaseColor; + LinearColorF mBaseColor; F32 mExposure; F32 mCoverage; F32 mWindSpeed; diff --git a/Engine/source/environment/river.cpp b/Engine/source/environment/river.cpp index 2ac9f2b97..0ff02c6d9 100644 --- a/Engine/source/environment/river.cpp +++ b/Engine/source/environment/river.cpp @@ -924,7 +924,7 @@ void River::setShaderParams( SceneRenderState *state, BaseMatInstance* mat, cons // set pixel shader constants //----------------------------------- - ColorF c( mWaterFogData.color ); + LinearColorF c( mWaterFogData.color ); matParams->setSafe(paramHandles.mBaseColorSC, c); // By default we need to show a true reflection is fullReflect is enabled and diff --git a/Engine/source/environment/scatterSky.cpp b/Engine/source/environment/scatterSky.cpp index a29d02f9e..1b3a60843 100644 --- a/Engine/source/environment/scatterSky.cpp +++ b/Engine/source/environment/scatterSky.cpp @@ -122,10 +122,10 @@ ScatterSky::ScatterSky() mAmbientScale.set( 1.0f, 1.0f, 1.0f, 1.0f ); mSunColor.set( 0, 0, 0, 1.0f ); - mSunScale = ColorF::WHITE; + mSunScale = LinearColorF::WHITE; mFogColor.set( 0, 0, 0, 1.0f ); - mFogScale = ColorF::WHITE; + mFogScale = LinearColorF::WHITE; mExposure = 1.0f; mNightInterpolant = 0; @@ -548,7 +548,7 @@ void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream) stream->read( &mScale ); - ColorF tmpColor( 0, 0, 0 ); + LinearColorF tmpColor( 0, 0, 0 ); stream->read( &tmpColor ); @@ -1093,7 +1093,7 @@ void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, Bas } // Vertex color. - ColorF moonVertColor( 1.0f, 1.0f, 1.0f, mNightInterpolant ); + LinearColorF moonVertColor( 1.0f, 1.0f, 1.0f, mNightInterpolant ); // Copy points to buffer. @@ -1104,7 +1104,7 @@ void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, Bas for ( S32 i = 0; i < 4; i++ ) { - pVert->color.set( moonVertColor ); + pVert->color.set( moonVertColor.toColorI()); pVert->point.set( points[i] ); pVert->texCoord.set( sCoords[i].x, sCoords[i].y ); pVert++; @@ -1182,8 +1182,8 @@ void ScatterSky::_interpolateColors() mMieScattering = (mCurves[1].getVal( mTimeOfDay) * mSunSize ); //Scale the size of the sun's disk - ColorF moonTemp = mMoonTint; - ColorF nightTemp = mNightColor; + LinearColorF moonTemp = mMoonTint; + LinearColorF nightTemp = mNightColor; moonTemp.interpolate( mNightColor, mMoonTint, mCurves[4].getVal( mTimeOfDay ) ); nightTemp.interpolate( mMoonTint, mNightColor, mCurves[4].getVal( mTimeOfDay ) ); @@ -1195,12 +1195,12 @@ void ScatterSky::_interpolateColors() mSunColor.interpolate( mSunColor, mMoonTint, mCurves[3].getVal( mTimeOfDay ) );//mNightInterpolant ); } -void ScatterSky::_getSunColor( ColorF *outColor ) +void ScatterSky::_getSunColor( LinearColorF *outColor ) { PROFILE_SCOPE( ScatterSky_GetSunColor ); U32 count = 0; - ColorF tmpColor( 0, 0, 0 ); + LinearColorF tmpColor( 0, 0, 0 ); VectorF tmpVec( 0, 0, 0 ); tmpVec = mLightDir; @@ -1221,11 +1221,11 @@ void ScatterSky::_getSunColor( ColorF *outColor ) (*outColor) /= count; } -void ScatterSky::_getAmbientColor( ColorF *outColor ) +void ScatterSky::_getAmbientColor( LinearColorF *outColor ) { PROFILE_SCOPE( ScatterSky_GetAmbientColor ); - ColorF tmpColor( 0, 0, 0, 0 ); + LinearColorF tmpColor( 0, 0, 0, 0 ); U32 count = 0; // Disable mieScattering for purposes of calculating the ambient color. @@ -1246,7 +1246,7 @@ void ScatterSky::_getAmbientColor( ColorF *outColor ) mMieScattering = oldMieScattering; } -void ScatterSky::_getFogColor( ColorF *outColor ) +void ScatterSky::_getFogColor( LinearColorF *outColor ) { PROFILE_SCOPE( ScatterSky_GetFogColor ); @@ -1261,7 +1261,7 @@ void ScatterSky::_getFogColor( ColorF *outColor ) originalYaw = yaw; pitch = mDegToRad( 10.0f ); - ColorF tmpColor( 0, 0, 0 ); + LinearColorF tmpColor( 0, 0, 0 ); U32 i = 0; for ( i = 0; i < 10; i++ ) @@ -1309,7 +1309,7 @@ F32 ScatterSky::_getRayleighPhase( F32 fCos2 ) return 0.75 + 0.75 * fCos2; } -void ScatterSky::_getColor( const Point3F &pos, ColorF *outColor ) +void ScatterSky::_getColor( const Point3F &pos, LinearColorF *outColor ) { PROFILE_SCOPE( ScatterSky_GetColor ); @@ -1379,7 +1379,7 @@ void ScatterSky::_getColor( const Point3F &pos, ColorF *outColor ) F32 miePhase = _getMiePhase( fCos, fCos2, g, g2 ); Point3F color = rayleighColor + (miePhase * mieColor); - ColorF tmp( color.x, color.y, color.z, color.y ); + LinearColorF tmp( color.x, color.y, color.z, color.y ); Point3F expColor( 0, 0, 0 ); expColor.x = 1.0f - exp(-mExposure * color.x); @@ -1388,7 +1388,7 @@ void ScatterSky::_getColor( const Point3F &pos, ColorF *outColor ) tmp.set( expColor.x, expColor.y, expColor.z, 1.0f ); - if ( !tmp.isValidColor() ) + if ( !tmp.isClamped() ) { F32 len = expColor.len(); if ( len > 0 ) diff --git a/Engine/source/environment/scatterSky.h b/Engine/source/environment/scatterSky.h index ff0e595a0..dc3aecc52 100644 --- a/Engine/source/environment/scatterSky.h +++ b/Engine/source/environment/scatterSky.h @@ -119,10 +119,10 @@ protected: void _generateSkyPoints(); - void _getColor( const Point3F &pos, ColorF *outColor ); - void _getFogColor( ColorF *outColor ); - void _getAmbientColor( ColorF *outColor ); - void _getSunColor( ColorF *outColor ); + void _getColor( const Point3F &pos, LinearColorF *outColor ); + void _getFogColor( LinearColorF *outColor ); + void _getAmbientColor( LinearColorF *outColor ); + void _getSunColor( LinearColorF *outColor ); void _interpolateColors(); void _conformLights(); @@ -161,7 +161,7 @@ protected: F32 mOuterRadius; F32 mScale; - ColorF mWavelength; + LinearColorF mWavelength; F32 mWavelength4[3]; F32 mRayleighScaleDepth; F32 mMieScaleDepth; @@ -185,16 +185,16 @@ protected: F32 mBrightness; - ColorF mNightColor; - ColorF mNightFogColor; + LinearColorF mNightColor; + LinearColorF mNightFogColor; - ColorF mAmbientColor; ///< Not a field - ColorF mSunColor; ///< Not a field - ColorF mFogColor; ///< Not a field + LinearColorF mAmbientColor; ///< Not a field + LinearColorF mSunColor; ///< Not a field + LinearColorF mFogColor; ///< Not a field - ColorF mAmbientScale; - ColorF mSunScale; - ColorF mFogScale; + LinearColorF mAmbientScale; + LinearColorF mSunScale; + LinearColorF mFogScale; LightInfo *mLight; @@ -211,7 +211,7 @@ protected: String mMoonMatName; BaseMatInstance *mMoonMatInst; F32 mMoonScale; - ColorF mMoonTint; + LinearColorF mMoonTint; VectorF mMoonLightDir; CubemapData *mNightCubemap; String mNightCubemapName; @@ -241,7 +241,7 @@ protected: GFXShaderConstHandle *mNightInterpolantAndExposureSC; GFXShaderConstHandle *mUseCubemapSC; F32 mColorizeAmt; - ColorF mColorize; + LinearColorF mColorize; GFXShaderConstHandle *mColorizeSC; }; diff --git a/Engine/source/environment/skyBox.cpp b/Engine/source/environment/skyBox.cpp index 00d0a6b4d..daadcf885 100644 --- a/Engine/source/environment/skyBox.cpp +++ b/Engine/source/environment/skyBox.cpp @@ -198,7 +198,7 @@ void SkyBox::prepRenderImage( SceneRenderState *state ) void SkyBox::_renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mi ) { - GFXDEBUGEVENT_SCOPE( SkyBox_RenderObject, ColorF::WHITE ); + GFXDEBUGEVENT_SCOPE( SkyBox_RenderObject, ColorI::WHITE ); GFXTransformSaver saver; GFX->setVertexBuffer( mVB ); diff --git a/Engine/source/environment/skyBox.h b/Engine/source/environment/skyBox.h index eeb2c24b5..466b3e05e 100644 --- a/Engine/source/environment/skyBox.h +++ b/Engine/source/environment/skyBox.h @@ -111,7 +111,7 @@ protected: Material *mFogBandMat; BaseMatInstance *mFogBandMatInst; - ColorF mLastFogColor; + LinearColorF mLastFogColor; bool mDrawBottom; bool mIsVBDirty; diff --git a/Engine/source/environment/sun.cpp b/Engine/source/environment/sun.cpp index 54390450a..d83d7078b 100644 --- a/Engine/source/environment/sun.cpp +++ b/Engine/source/environment/sun.cpp @@ -394,7 +394,7 @@ void Sun::setElevation( F32 elevation ) setMaskBits( UpdateMask ); // TODO: Break out the masks to save some space! } -void Sun::setColor( const ColorF &color ) +void Sun::setColor( const LinearColorF &color ) { mLightColor = color; _conformLights(); @@ -490,7 +490,7 @@ void Sun::_renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatI points[i] += mLightWorldPos; } - ColorF vertColor; + LinearColorF vertColor; if ( mCoronaUseLightColor ) vertColor = mLightColor; else @@ -503,7 +503,7 @@ void Sun::_renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatI for ( S32 i = 0; i < 4; i++ ) { - pVert->color.set( vertColor ); + pVert->color.set( vertColor.toColorI()); pVert->point.set( points[i] ); pVert->texCoord.set( sCoords[i].x, sCoords[i].y ); pVert++; diff --git a/Engine/source/environment/sun.h b/Engine/source/environment/sun.h index 27ce97ae6..503526fab 100644 --- a/Engine/source/environment/sun.h +++ b/Engine/source/environment/sun.h @@ -50,9 +50,9 @@ protected: F32 mSunElevation; - ColorF mLightColor; + LinearColorF mLightColor; - ColorF mLightAmbient; + LinearColorF mLightAmbient; F32 mBrightness; @@ -79,7 +79,7 @@ protected: BaseMatInstance *mCoronaMatInst; MatrixSet *mMatrixSet; F32 mCoronaScale; - ColorF mCoronaTint; + LinearColorF mCoronaTint; bool mCoronaUseLightColor; // These are not user specified. @@ -136,7 +136,7 @@ public: void setElevation( F32 elevation ); /// - void setColor( const ColorF &color ); + void setColor( const LinearColorF &color ); /// void animate( F32 duration, F32 startAzimuth, F32 endAzimuth, F32 startElevation, F32 endElevation ); diff --git a/Engine/source/environment/timeOfDay.cpp b/Engine/source/environment/timeOfDay.cpp index a954c5fa6..b1338bf77 100644 --- a/Engine/source/environment/timeOfDay.cpp +++ b/Engine/source/environment/timeOfDay.cpp @@ -378,7 +378,7 @@ F32 TimeOfDay::_calcAzimuth( F32 lat, F32 dec, F32 mer ) return mAtan2( mSin(mer), mCos(mer) * mSin(lat) - mTan(dec) * mCos(lat) ) + M_PI_F; } -void TimeOfDay::_getSunColor( ColorF *outColor ) const +void TimeOfDay::_getSunColor( LinearColorF *outColor ) const { const COLOR_TARGET *ct = NULL; @@ -451,8 +451,8 @@ void TimeOfDay::_initColors() // NOTE: The elevation targets represent distances // from PI/2 radians (strait up). - ColorF c; - ColorF bc; + LinearColorF c; + LinearColorF bc; // e is for elevation F32 e = M_PI_F / 13.0f; // (semicircle in radians)/(number of color target entries); @@ -495,7 +495,7 @@ void TimeOfDay::_initColors() _addColorTarget(M_PI_F, c, 1.0f, c); // Midnight at equanox. } -void TimeOfDay::_addColorTarget( F32 ele, const ColorF &color, F32 bandMod, const ColorF &bandColor ) +void TimeOfDay::_addColorTarget( F32 ele, const LinearColorF &color, F32 bandMod, const LinearColorF &bandColor ) { COLOR_TARGET newTarget; diff --git a/Engine/source/environment/timeOfDay.h b/Engine/source/environment/timeOfDay.h index 25beddc12..53aa9563d 100644 --- a/Engine/source/environment/timeOfDay.h +++ b/Engine/source/environment/timeOfDay.h @@ -34,9 +34,9 @@ class TimeOfDay; struct COLOR_TARGET { F32 elevation; // maximum target elevation - ColorF color; //normalized 0 = 1.0 ... + LinearColorF color; //normalized 0 = 1.0 ... F32 bandMod; //6 is max - ColorF bandColor; + LinearColorF bandColor; }; typedef Vector COLOR_TARGETS; @@ -108,7 +108,7 @@ public: { return (mCurrentColor.blue + mCurrentColor.green + mCurrentColor.red) / 3; } */ static TimeOfDayUpdateSignal& getTimeOfDayUpdateSignal() { return smTimeOfDayUpdateSignal; } - void getSunColor( ColorF *outColor ) const { _getSunColor( outColor ); } + void getSunColor( LinearColorF *outColor ) const { _getSunColor( outColor ); } void addTimeEvent( F32 triggerElevation, const UTF8 *identifier ); @@ -150,10 +150,10 @@ protected: /// @param color [in] target color. /// @param bandMod [in] /// @param bandColor [in] - void _addColorTarget( F32 ele, const ColorF &color, F32 bandMod, const ColorF &bandColor ); + void _addColorTarget( F32 ele, const LinearColorF &color, F32 bandMod, const LinearColorF &bandColor ); // Grab our sun and sky colors based upon sun elevation. - void _getSunColor( ColorF *outColor ) const; + void _getSunColor( LinearColorF *outColor ) const; static bool setTimeOfDay( void *object, const char *index, const char *data ); static bool setPlay( void *object, const char *index, const char *data ); @@ -196,9 +196,9 @@ protected: bool mAnimate; /* - ColorF mCurrentColor; + LinearColorF mCurrentColor; F32 mBandMod; - ColorF mCurrentBandColor; + LinearColorF mCurrentBandColor; // PersistFields preparation bool mConvertedToRads; diff --git a/Engine/source/environment/waterBlock.cpp b/Engine/source/environment/waterBlock.cpp index 60bf0d727..4a4edc15f 100644 --- a/Engine/source/environment/waterBlock.cpp +++ b/Engine/source/environment/waterBlock.cpp @@ -424,7 +424,7 @@ void WaterBlock::setShaderParams( SceneRenderState *state, BaseMatInstance *mat, // set pixel shader constants //----------------------------------- - ColorF c( mWaterFogData.color ); + LinearColorF c( mWaterFogData.color ); matParams->setSafe( paramHandles.mBaseColorSC, c ); // By default we need to show a true reflection is fullReflect is enabled and diff --git a/Engine/source/environment/waterObject.cpp b/Engine/source/environment/waterObject.cpp index 72046e74f..adb81e6d1 100644 --- a/Engine/source/environment/waterObject.cpp +++ b/Engine/source/environment/waterObject.cpp @@ -1022,7 +1022,7 @@ void WaterObject::setShaderParams( SceneRenderState *state, BaseMatInstance *mat matParams->setSafe(paramHandles.mDistortionParamsSC, distortionParams ); LightInfo *sun = LIGHTMGR->getSpecialLight(LightManager::slSunLightType); - const ColorF &sunlight = state->getAmbientLightColor(); + const LinearColorF &sunlight = state->getAmbientLightColor(); Point3F ambientColor = mEmissive ? Point3F::One : sunlight; matParams->setSafe(paramHandles.mAmbientColorSC, ambientColor ); matParams->setSafe(paramHandles.mLightDirSC, sun->getDirection() ); @@ -1036,7 +1036,7 @@ void WaterObject::setShaderParams( SceneRenderState *state, BaseMatInstance *mat Point4F specularParams( mSpecularColor.red, mSpecularColor.green, mSpecularColor.blue, mSpecularPower ); if ( !mEmissive ) { - const ColorF &sunColor = sun->getColor(); + const LinearColorF &sunColor = sun->getColor(); F32 brightness = sun->getBrightness(); specularParams.x *= sunColor.red * brightness; specularParams.y *= sunColor.green * brightness; @@ -1159,22 +1159,22 @@ bool WaterObject::initMaterial( S32 idx ) void WaterObject::initTextures() { if ( mRippleTexName.isNotEmpty() ) - mRippleTex.set( mRippleTexName, &GFXDefaultStaticDiffuseProfile, "WaterObject::mRippleTex" ); + mRippleTex.set( mRippleTexName, &GFXStaticTextureSRGBProfile, "WaterObject::mRippleTex" ); if ( mRippleTex.isNull() ) - mRippleTex.set( GFXTextureManager::getWarningTexturePath(), &GFXDefaultStaticDiffuseProfile, "WaterObject::mRippleTex" ); + mRippleTex.set( GFXTextureManager::getWarningTexturePath(), &GFXStaticTextureSRGBProfile, "WaterObject::mRippleTex" ); if ( mDepthGradientTexName.isNotEmpty() ) - mDepthGradientTex.set( mDepthGradientTexName, &GFXDefaultStaticDiffuseProfile, "WaterObject::mDepthGradientTex" ); + mDepthGradientTex.set( mDepthGradientTexName, &GFXStaticTextureSRGBProfile, "WaterObject::mDepthGradientTex" ); if ( mDepthGradientTex.isNull() ) - mDepthGradientTex.set( GFXTextureManager::getWarningTexturePath(), &GFXDefaultStaticDiffuseProfile, "WaterObject::mDepthGradientTex" ); + mDepthGradientTex.set( GFXTextureManager::getWarningTexturePath(), &GFXStaticTextureSRGBProfile, "WaterObject::mDepthGradientTex" ); if ( mNamedDepthGradTex.isRegistered() ) mNamedDepthGradTex.setTexture( mDepthGradientTex ); if ( mFoamTexName.isNotEmpty() ) - mFoamTex.set( mFoamTexName, &GFXDefaultStaticDiffuseProfile, "WaterObject::mFoamTex" ); + mFoamTex.set( mFoamTexName, &GFXStaticTextureSRGBProfile, "WaterObject::mFoamTex" ); if ( mFoamTex.isNull() ) - mFoamTex.set( GFXTextureManager::getWarningTexturePath(), &GFXDefaultStaticDiffuseProfile, "WaterObject::mFoamTex" ); + mFoamTex.set( GFXTextureManager::getWarningTexturePath(), &GFXStaticTextureSRGBProfile, "WaterObject::mFoamTex" ); if ( mCubemapName.isNotEmpty() ) Sim::findObject( mCubemapName, mCubemap ); diff --git a/Engine/source/environment/waterObject.h b/Engine/source/environment/waterObject.h index f5939bf0a..94862e4c6 100644 --- a/Engine/source/environment/waterObject.h +++ b/Engine/source/environment/waterObject.h @@ -212,7 +212,7 @@ protected: F32 mFresnelBias; F32 mFresnelPower; F32 mSpecularPower; - ColorF mSpecularColor; + LinearColorF mSpecularColor; bool mEmissive; // Reflection diff --git a/Engine/source/environment/waterPlane.cpp b/Engine/source/environment/waterPlane.cpp index 0e1cc31df..3e5904a31 100644 --- a/Engine/source/environment/waterPlane.cpp +++ b/Engine/source/environment/waterPlane.cpp @@ -664,7 +664,7 @@ void WaterPlane::setShaderParams( SceneRenderState *state, BaseMatInstance* mat, // set pixel shader constants //----------------------------------- - ColorF c( mWaterFogData.color ); + LinearColorF c( mWaterFogData.color ); matParams->setSafe( paramHandles.mBaseColorSC, c ); // By default we need to show a true reflection is fullReflect is enabled and diff --git a/Engine/source/gfx/D3D11/gfxD3D11Cubemap.cpp b/Engine/source/gfx/D3D11/gfxD3D11Cubemap.cpp index f009e83c9..145a64385 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Cubemap.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Cubemap.cpp @@ -24,6 +24,7 @@ #include "gfx/gfxCardProfile.h" #include "gfx/gfxTextureManager.h" #include "gfx/D3D11/gfxD3D11EnumTranslate.h" +#include "gfx/bitmap/imageUtils.h" GFXD3D11Cubemap::GFXD3D11Cubemap() : mTexture(NULL), mSRView(NULL), mDSView(NULL) { @@ -65,14 +66,6 @@ void GFXD3D11Cubemap::_onTextureEvent(GFXTexCallbackCode code) initDynamic(mTexSize); } -bool GFXD3D11Cubemap::isCompressed(GFXFormat format) -{ - if (format >= GFXFormatDXT1 && format <= GFXFormatDXT5) - return true; - - return false; -} - void GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) { AssertFatal( faces, "GFXD3D11Cubemap::initStatic - Got null GFXTexHandle!" ); @@ -81,7 +74,7 @@ void GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) // NOTE - check tex sizes on all faces - they MUST be all same size mTexSize = faces->getWidth(); mFaceFormat = faces->getFormat(); - bool compressed = isCompressed(mFaceFormat); + bool compressed = ImageUtil::isCompressedFormat(mFaceFormat); UINT bindFlags = D3D11_BIND_SHADER_RESOURCE; UINT miscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; @@ -91,15 +84,15 @@ void GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) miscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; } - U32 mipLevels = faces->getPointer()->getMipLevels(); - if (mipLevels > 1 && !compressed) + mMipMapLevels = faces->getPointer()->getMipLevels(); + if (mMipMapLevels < 1 && !compressed) mAutoGenMips = true; D3D11_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC)); desc.Width = mTexSize; desc.Height = mTexSize; - desc.MipLevels = mAutoGenMips ? 0 : mipLevels; + desc.MipLevels = mAutoGenMips ? 0 : mMipMapLevels; desc.ArraySize = 6; desc.Format = GFXD3D11TextureFormat[mFaceFormat]; desc.SampleDesc.Count = 1; @@ -113,15 +106,15 @@ void GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) if (FAILED(hr)) { - AssertFatal(false, "GFXD3D11Cubemap:initStatic(GFXTexhandle *faces) - failed to create texcube texture"); + AssertFatal(false, "GFXD3D11Cubemap:initStatic(GFXTexhandle *faces) - CreateTexture2D failure"); } for (U32 i = 0; i < CubeFaces; i++) { GFXD3D11TextureObject *texObj = static_cast((GFXTextureObject*)faces[i]); - for (U32 currentMip = 0; currentMip < mipLevels; currentMip++) + for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++) { - U32 subResource = D3D11CalcSubresource(currentMip, i, mipLevels); + U32 subResource = D3D11CalcSubresource(currentMip, i, mMipMapLevels); D3D11DEVICECONTEXT->CopySubresourceRegion(mTexture, subResource, 0, 0, 0, texObj->get2DTex(), currentMip, NULL); } } @@ -129,7 +122,7 @@ void GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) D3D11_SHADER_RESOURCE_VIEW_DESC SMViewDesc; SMViewDesc.Format = GFXD3D11TextureFormat[mFaceFormat]; SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - SMViewDesc.TextureCube.MipLevels = mAutoGenMips ? -1 : mipLevels; + SMViewDesc.TextureCube.MipLevels = mAutoGenMips ? -1 : mMipMapLevels; SMViewDesc.TextureCube.MostDetailedMip = 0; hr = D3D11DEVICE->CreateShaderResourceView(mTexture, &SMViewDesc, &mSRView); @@ -138,8 +131,16 @@ void GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) AssertFatal(false, "GFXD3D11Cubemap::initStatic(GFXTexHandle *faces) - texcube shader resource view creation failure"); } + //Generate mips if (mAutoGenMips && !compressed) + { D3D11DEVICECONTEXT->GenerateMips(mSRView); + //get mip level count + D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; + mSRView->GetDesc(&viewDesc); + mMipMapLevels = viewDesc.TextureCube.MipLevels; + } + } void GFXD3D11Cubemap::initStatic(DDSFile *dds) @@ -151,45 +152,53 @@ void GFXD3D11Cubemap::initStatic(DDSFile *dds) // NOTE - check tex sizes on all faces - they MUST be all same size mTexSize = dds->getWidth(); mFaceFormat = dds->getFormat(); - U32 levels = dds->getMipLevels(); + mMipMapLevels = dds->getMipLevels(); D3D11_TEXTURE2D_DESC desc; desc.Width = mTexSize; desc.Height = mTexSize; - desc.MipLevels = levels; - desc.ArraySize = 6; + desc.MipLevels = mMipMapLevels; + desc.ArraySize = CubeFaces; desc.Format = GFXD3D11TextureFormat[mFaceFormat]; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE | D3D11_RESOURCE_MISC_GENERATE_MIPS; + desc.CPUAccessFlags = 0; + desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; - D3D11_SUBRESOURCE_DATA* pData = new D3D11_SUBRESOURCE_DATA[6 + levels]; - - for (U32 i = 0; imSurfaces[i]) + if (!dds->mSurfaces[currentFace]) continue; - for(U32 j = 0; j < levels; j++) + // convert to Z up + const U32 faceIndex = _zUpFaceIndex(currentFace); + + for(U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++) { - pData[i + j].pSysMem = dds->mSurfaces[i]->mMips[j]; - pData[i + j].SysMemPitch = dds->getSurfacePitch(j); - pData[i + j].SysMemSlicePitch = dds->getSurfaceSize(j); + const U32 dataIndex = faceIndex * mMipMapLevels + currentMip; + pData[dataIndex].pSysMem = dds->mSurfaces[currentFace]->mMips[currentMip]; + pData[dataIndex].SysMemPitch = dds->getSurfacePitch(currentMip); + pData[dataIndex].SysMemSlicePitch = 0; } + } - HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, pData, &mTexture); + HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, pData, &mTexture); + if (FAILED(hr)) + { + AssertFatal(false, "GFXD3D11Cubemap::initStatic(DDSFile *dds) - CreateTexture2D failure"); + } delete [] pData; D3D11_SHADER_RESOURCE_VIEW_DESC SMViewDesc; SMViewDesc.Format = GFXD3D11TextureFormat[mFaceFormat]; SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - SMViewDesc.TextureCube.MipLevels = levels; + SMViewDesc.TextureCube.MipLevels = mMipMapLevels; SMViewDesc.TextureCube.MostDetailedMip = 0; hr = D3D11DEVICE->CreateShaderResourceView(mTexture, &SMViewDesc, &mSRView); @@ -209,7 +218,8 @@ void GFXD3D11Cubemap::initDynamic(U32 texSize, GFXFormat faceFormat) mAutoGenMips = true; mTexSize = texSize; mFaceFormat = faceFormat; - bool compressed = isCompressed(mFaceFormat); + mMipMapLevels = 0; + bool compressed = ImageUtil::isCompressedFormat(mFaceFormat); UINT bindFlags = D3D11_BIND_SHADER_RESOURCE; UINT miscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; @@ -250,6 +260,16 @@ void GFXD3D11Cubemap::initDynamic(U32 texSize, GFXFormat faceFormat) AssertFatal(false, "GFXD3D11Cubemap::initDynamic - CreateTexture2D call failure"); } + //Generate mips + if (mAutoGenMips && !compressed) + { + D3D11DEVICECONTEXT->GenerateMips(mSRView); + //get mip level count + D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; + mSRView->GetDesc(&viewDesc); + mMipMapLevels = viewDesc.TextureCube.MipLevels; + } + D3D11_RENDER_TARGET_VIEW_DESC viewDesc; viewDesc.Format = desc.Format; viewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; diff --git a/Engine/source/gfx/D3D11/gfxD3D11Cubemap.h b/Engine/source/gfx/D3D11/gfxD3D11Cubemap.h index f24933d08..fa1fd538c 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Cubemap.h +++ b/Engine/source/gfx/D3D11/gfxD3D11Cubemap.h @@ -71,7 +71,6 @@ private: void releaseSurfaces(); - bool isCompressed(GFXFormat format); /// The callback used to get texture events. /// @see GFXTextureManager::addEventDelegate void _onTextureEvent(GFXTexCallbackCode code); diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp index ba6b72523..0e9409cab 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp @@ -45,14 +45,6 @@ #pragma comment(lib, "dxgi.lib") #pragma comment(lib, "d3d11.lib") -GFXAdapter::CreateDeviceInstanceDelegate GFXD3D11Device::mCreateDeviceInstance(GFXD3D11Device::createInstance); - -GFXDevice *GFXD3D11Device::createInstance(U32 adapterIndex) -{ - GFXD3D11Device* dev = new GFXD3D11Device(adapterIndex); - return dev; -} - class GFXPCD3D11RegisterDevice { public: @@ -79,6 +71,14 @@ static void sgPCD3D11DeviceHandleCommandLine(S32 argc, const char **argv) // Register the command line parsing hook static ProcessRegisterCommandLine sgCommandLine(sgPCD3D11DeviceHandleCommandLine); +GFXAdapter::CreateDeviceInstanceDelegate GFXD3D11Device::mCreateDeviceInstance(GFXD3D11Device::createInstance); + +GFXDevice *GFXD3D11Device::createInstance(U32 adapterIndex) +{ + GFXD3D11Device* dev = new GFXD3D11Device(adapterIndex); + return dev; +} + GFXD3D11Device::GFXD3D11Device(U32 index) { mDeviceSwizzle32 = &Swizzles::bgra; @@ -88,6 +88,9 @@ GFXD3D11Device::GFXD3D11Device(U32 index) mAdapterIndex = index; mD3DDevice = NULL; + mD3DDeviceContext = NULL; + mD3DDevice1 = NULL; + mD3DDeviceContext1 = NULL; mUserAnnotation = NULL; mVolatileVB = NULL; @@ -104,10 +107,6 @@ GFXD3D11Device::GFXD3D11Device(U32 index) mPixVersion = 0.0; - mVertexShaderTarget = String::EmptyString; - mPixelShaderTarget = String::EmptyString; - mShaderModel = String::EmptyString; - mDrawInstancesCount = 0; mCardProfiler = NULL; @@ -122,6 +121,7 @@ GFXD3D11Device::GFXD3D11Device(U32 index) mCurrentConstBuffer = NULL; mOcclusionQuerySupported = false; + mCbufferPartialSupported = false; mDebugLayers = false; @@ -149,7 +149,7 @@ GFXD3D11Device::~GFXD3D11Device() // Free the vertex declarations. VertexDeclMap::Iterator iter = mVertexDecls.begin(); - for (; iter != mVertexDecls.end(); iter++) + for (; iter != mVertexDecls.end(); ++iter) delete iter->value; // Forcibly clean up the pools @@ -162,6 +162,7 @@ GFXD3D11Device::~GFXD3D11Device() SAFE_RELEASE(mDeviceDepthStencil); SAFE_RELEASE(mDeviceBackbuffer); SAFE_RELEASE(mUserAnnotation); + SAFE_RELEASE(mD3DDeviceContext1); SAFE_RELEASE(mD3DDeviceContext); SAFE_DELETE(mCardProfiler); @@ -179,6 +180,7 @@ GFXD3D11Device::~GFXD3D11Device() #endif SAFE_RELEASE(mSwapChain); + SAFE_RELEASE(mD3DDevice1); SAFE_RELEASE(mD3DDevice); } @@ -220,7 +222,7 @@ DXGI_SWAP_CHAIN_DESC GFXD3D11Device::setupPresentParams(const GFXVideoMode &mode d3dpp.BufferCount = !smDisableVSync ? 2 : 1; // triple buffering when vsync is on. d3dpp.BufferDesc.Width = mode.resolution.x; d3dpp.BufferDesc.Height = mode.resolution.y; - d3dpp.BufferDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8]; + d3dpp.BufferDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB]; d3dpp.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; d3dpp.OutputWindow = hwnd; d3dpp.SampleDesc = sampleDesc; @@ -287,7 +289,7 @@ void GFXD3D11Device::enumerateAdapters(Vector &adapterList) UINT numModes = 0; DXGI_MODE_DESC* displayModes = NULL; - DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM; + DXGI_FORMAT format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB]; // Get the number of elements hr = pOutput->GetDisplayModeList(format, 0, &numModes, NULL); @@ -315,47 +317,10 @@ void GFXD3D11Device::enumerateAdapters(Vector &adapterList) toAdd->mAvailableModes.push_back(vmAdd); } - //Check adapater can handle feature level 10 - D3D_FEATURE_LEVEL deviceFeature; - ID3D11Device *pTmpDevice = nullptr; - // Create temp Direct3D11 device. - bool suitable = true; - UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT; - hr = D3D11CreateDevice(EnumAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, createDeviceFlags, NULL, 0, D3D11_SDK_VERSION, &pTmpDevice, &deviceFeature, NULL); - - if (FAILED(hr)) - suitable = false; - - if (deviceFeature < D3D_FEATURE_LEVEL_10_0) - suitable = false; - - //double check we support required bgra format for LEVEL_10_0 & LEVEL_10_1 - if (deviceFeature == D3D_FEATURE_LEVEL_10_0 || deviceFeature == D3D_FEATURE_LEVEL_10_1) - { - U32 formatSupported = 0; - pTmpDevice->CheckFormatSupport(DXGI_FORMAT_B8G8R8A8_UNORM, &formatSupported); - U32 flagsRequired = D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_DISPLAY; - if (!(formatSupported && flagsRequired)) - { - Con::printf("DXGI adapter: %s does not support BGRA", Description.c_str()); - suitable = false; - } - } - delete[] displayModes; - SAFE_RELEASE(pTmpDevice); SAFE_RELEASE(pOutput); SAFE_RELEASE(EnumAdapter); - - if (suitable) - { - adapterList.push_back(toAdd); - } - else - { - Con::printf("DXGI adapter: %s does not support D3D11 feature level 10 or better", Description.c_str()); - delete toAdd; - } + adapterList.push_back(toAdd); } SAFE_RELEASE(DXGIFactory); @@ -391,7 +356,7 @@ void GFXD3D11Device::enumerateVideoModes() UINT numModes = 0; DXGI_MODE_DESC* displayModes = NULL; - DXGI_FORMAT format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8]; + DXGI_FORMAT format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB]; // Get the number of elements hr = pOutput->GetDisplayModeList(format, 0, &numModes, NULL); @@ -430,8 +395,8 @@ void GFXD3D11Device::enumerateVideoModes() void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window) { AssertFatal(window, "GFXD3D11Device::init - must specify a window!"); - HWND hwnd = (HWND)window->getSystemWindow(PlatformWindow::WindowSystem_Windows); - SetFocus(hwnd);//ensure window has focus + + HWND winHwnd = (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows ); UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT; #ifdef TORQUE_DEBUG @@ -439,77 +404,88 @@ void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window) mDebugLayers = true; #endif + DXGI_SWAP_CHAIN_DESC d3dpp = setupPresentParams(mode, winHwnd); + + D3D_FEATURE_LEVEL deviceFeature; + // TODO support at least feature level 10 to match GL + D3D_FEATURE_LEVEL pFeatureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0 }; + U32 nFeatureCount = ARRAYSIZE(pFeatureLevels); D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_HARDWARE;// use D3D_DRIVER_TYPE_REFERENCE for reference device - // create a device & device context - HRESULT hres = D3D11CreateDevice(NULL, - driverType, - NULL, - createDeviceFlags, - NULL, - 0, - D3D11_SDK_VERSION, - &mD3DDevice, - &mFeatureLevel, - &mD3DDeviceContext); + // create a device, device context and swap chain using the information in the d3dpp struct + HRESULT hres = D3D11CreateDeviceAndSwapChain(NULL, + driverType, + NULL, + createDeviceFlags, + pFeatureLevels, + nFeatureCount, + D3D11_SDK_VERSION, + &d3dpp, + &mSwapChain, + &mD3DDevice, + &deviceFeature, + &mD3DDeviceContext); if(FAILED(hres)) { #ifdef TORQUE_DEBUG - //try again without debug device layer enabled - createDeviceFlags &= ~D3D11_CREATE_DEVICE_DEBUG; - hres = D3D11CreateDevice(NULL, - driverType, - NULL, - createDeviceFlags, - NULL, - 0, - D3D11_SDK_VERSION, - &mD3DDevice, - &mFeatureLevel, - &mD3DDeviceContext); - //if we failed again than we definitely have a problem - if (FAILED(hres)) - AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!"); - - Con::warnf("GFXD3D11Device::init - Debug layers not detected!"); - mDebugLayers = false; - #else + //try again without debug device layer enabled + createDeviceFlags &= ~D3D11_CREATE_DEVICE_DEBUG; + hres = D3D11CreateDeviceAndSwapChain(NULL, driverType,NULL,createDeviceFlags,NULL, 0, + D3D11_SDK_VERSION, + &d3dpp, + &mSwapChain, + &mD3DDevice, + &deviceFeature, + &mD3DDeviceContext); + //if we failed again than we definitely have a problem + if (FAILED(hres)) AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!"); + + Con::warnf("GFXD3D11Device::init - Debug layers not detected!"); + mDebugLayers = false; + #else + AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!"); #endif } -#ifdef TORQUE_DEBUG - _suppressDebugMessages(); -#endif + // Grab DX 11.1 device and context if available and also ID3DUserDefinedAnnotation + hres = mD3DDevice->QueryInterface(__uuidof(ID3D11Device1), reinterpret_cast(&mD3DDevice1)); + if (SUCCEEDED(hres)) + { + //11.1 context + mD3DDeviceContext->QueryInterface(__uuidof(ID3D11DeviceContext1), reinterpret_cast(&mD3DDeviceContext1)); + // ID3DUserDefinedAnnotation + mD3DDeviceContext->QueryInterface(IID_PPV_ARGS(&mUserAnnotation)); + //Check what is supported, windows 7 supports very little from 11.1 + D3D11_FEATURE_DATA_D3D11_OPTIONS options; + mD3DDevice1->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &options, + sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS)); + + //Cbuffer partial updates + if (options.ConstantBufferOffsetting && options.ConstantBufferPartialUpdate) + mCbufferPartialSupported = true; + } + + + + //set the fullscreen state here if we need to + if(mode.fullScreen) + { + hres = mSwapChain->SetFullscreenState(TRUE, NULL); + if(FAILED(hres)) + { + AssertFatal(false, "GFXD3D11Device::init- Failed to set fullscreen state!"); + } + } mTextureManager = new GFXD3D11TextureManager(); // Now reacquire all the resources we trashed earlier reacquireDefaultPoolResources(); - //set vert/pixel shader targets - switch (mFeatureLevel) - { - case D3D_FEATURE_LEVEL_11_0: - mVertexShaderTarget = "vs_5_0"; - mPixelShaderTarget = "ps_5_0"; + if (deviceFeature >= D3D_FEATURE_LEVEL_11_0) mPixVersion = 5.0f; - mShaderModel = "50"; - break; - case D3D_FEATURE_LEVEL_10_1: - mVertexShaderTarget = "vs_4_1"; - mPixelShaderTarget = "ps_4_1"; - mPixVersion = 4.1f; - mShaderModel = "41"; - break; - case D3D_FEATURE_LEVEL_10_0: - mVertexShaderTarget = "vs_4_0"; - mPixelShaderTarget = "ps_4_0"; - mPixVersion = 4.0f; - mShaderModel = "40"; - break; - default: - AssertFatal(false, "GFXD3D11Device::init - We don't support this feature level"); - } + else + AssertFatal(false, "GFXD3D11Device::init - We don't support anything below feature level 11."); D3D11_QUERY_DESC queryDesc; queryDesc.Query = D3D11_QUERY_OCCLUSION; @@ -527,6 +503,68 @@ void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window) mCardProfiler = new GFXD3D11CardProfiler(); mCardProfiler->init(); + D3D11_TEXTURE2D_DESC desc; + desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + desc.CPUAccessFlags = 0; + desc.Format = GFXD3D11TextureFormat[GFXFormatD24S8]; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.Width = mode.resolution.x; + desc.Height = mode.resolution.y; + desc.SampleDesc.Count =1; + desc.SampleDesc.Quality =0; + desc.MiscFlags = 0; + + HRESULT hr = mD3DDevice->CreateTexture2D(&desc, NULL, &mDeviceDepthStencil); + if(FAILED(hr)) + { + AssertFatal(false, "GFXD3D11Device::init - couldn't create device's depth-stencil surface."); + } + + D3D11_DEPTH_STENCIL_VIEW_DESC depthDesc; + depthDesc.Format = GFXD3D11TextureFormat[GFXFormatD24S8]; + depthDesc.Flags =0 ; + depthDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + depthDesc.Texture2D.MipSlice = 0; + + hr = mD3DDevice->CreateDepthStencilView(mDeviceDepthStencil, &depthDesc, &mDeviceDepthStencilView); + + if(FAILED(hr)) + { + AssertFatal(false, "GFXD3D11Device::init - couldn't create depth stencil view"); + } + + hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mDeviceBackbuffer); + if(FAILED(hr)) + AssertFatal(false, "GFXD3D11Device::init - coudln't retrieve backbuffer ref"); + + //create back buffer view + D3D11_RENDER_TARGET_VIEW_DESC RTDesc; + + RTDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB]; + RTDesc.Texture2D.MipSlice = 0; + RTDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + + hr = mD3DDevice->CreateRenderTargetView(mDeviceBackbuffer, &RTDesc, &mDeviceBackBufferView); + + if(FAILED(hr)) + AssertFatal(false, "GFXD3D11Device::init - couldn't create back buffer target view"); + +#ifdef TORQUE_DEBUG + String backBufferName = "MainBackBuffer"; + String depthSteniclName = "MainDepthStencil"; + String backBuffViewName = "MainBackBuffView"; + String depthStencViewName = "MainDepthView"; + mDeviceBackbuffer->SetPrivateData(WKPDID_D3DDebugObjectName, backBufferName.size(), backBufferName.c_str()); + mDeviceDepthStencil->SetPrivateData(WKPDID_D3DDebugObjectName, depthSteniclName.size(), depthSteniclName.c_str()); + mDeviceDepthStencilView->SetPrivateData(WKPDID_D3DDebugObjectName, depthStencViewName.size(), depthStencViewName.c_str()); + mDeviceBackBufferView->SetPrivateData(WKPDID_D3DDebugObjectName, backBuffViewName.size(), backBuffViewName.c_str()); + + _suppressDebugMessages(); + +#endif + gScreenShot = new ScreenShotD3D11; mInitialized = true; @@ -576,35 +614,14 @@ GFXWindowTarget * GFXD3D11Device::allocWindowTarget(PlatformWindow *window) { AssertFatal(window,"GFXD3D11Device::allocWindowTarget - no window provided!"); + // Allocate the device. + init(window->getVideoMode(), window); + // Set up a new window target... GFXD3D11WindowTarget *gdwt = new GFXD3D11WindowTarget(); gdwt->mWindow = window; gdwt->mSize = window->getClientExtent(); - - if (!mInitialized) - { - gdwt->mSecondaryWindow = false; - // Allocate the device. - init(window->getVideoMode(), window); - gdwt->initPresentationParams(); - gdwt->createSwapChain(); - gdwt->createBuffersAndViews(); - - mSwapChain = gdwt->getSwapChain(); - mDeviceBackbuffer = gdwt->getBackBuffer(); - mDeviceDepthStencil = gdwt->getDepthStencil(); - mDeviceBackBufferView = gdwt->getBackBufferView(); - mDeviceDepthStencilView = gdwt->getDepthStencilView(); - - } - else //additional window/s - { - gdwt->mSecondaryWindow = true; - gdwt->initPresentationParams(); - gdwt->createSwapChain(); - gdwt->createBuffersAndViews(); - } - + gdwt->initPresentationParams(); gdwt->registerResourceWithDevice(this); return gdwt; @@ -618,15 +635,13 @@ GFXTextureTarget* GFXD3D11Device::allocRenderToTextureTarget() return targ; } -void GFXD3D11Device::beginReset() +void GFXD3D11Device::reset(DXGI_SWAP_CHAIN_DESC &d3dpp) { if (!mD3DDevice) return; mInitialized = false; - releaseDefaultPoolResources(); - // Clean up some commonly dangling state. This helps prevents issues with // items that are destroyed by the texture manager callbacks and recreated // later, but still left bound. @@ -637,26 +652,117 @@ void GFXD3D11Device::beginReset() mD3DDeviceContext->ClearState(); - //release old buffers and views - SAFE_RELEASE(mDeviceDepthStencilView); - SAFE_RELEASE(mDeviceBackBufferView); - SAFE_RELEASE(mDeviceDepthStencil); - SAFE_RELEASE(mDeviceBackbuffer); -} + DXGI_MODE_DESC displayModes; + displayModes.Format = d3dpp.BufferDesc.Format; + displayModes.Height = d3dpp.BufferDesc.Height; + displayModes.Width = d3dpp.BufferDesc.Width; + displayModes.RefreshRate = d3dpp.BufferDesc.RefreshRate; + displayModes.Scaling = d3dpp.BufferDesc.Scaling; + displayModes.ScanlineOrdering = d3dpp.BufferDesc.ScanlineOrdering; -void GFXD3D11Device::endReset(GFXD3D11WindowTarget *windowTarget) -{ - //grab new references - mDeviceBackbuffer = windowTarget->getBackBuffer(); - mDeviceDepthStencil = windowTarget->getDepthStencil(); - mDeviceBackBufferView = windowTarget->getBackBufferView(); - mDeviceDepthStencilView = windowTarget->getDepthStencilView(); + HRESULT hr; + if (!d3dpp.Windowed) + { + hr = mSwapChain->ResizeTarget(&displayModes); + + if (FAILED(hr)) + { + AssertFatal(false, "D3D11Device::reset - failed to resize target!"); + } + } + + // First release all the stuff we allocated from D3DPOOL_DEFAULT + releaseDefaultPoolResources(); + + //release the backbuffer, depthstencil, and their views + SAFE_RELEASE(mDeviceBackBufferView); + SAFE_RELEASE(mDeviceBackbuffer); + SAFE_RELEASE(mDeviceDepthStencilView); + SAFE_RELEASE(mDeviceDepthStencil); + + hr = mSwapChain->ResizeBuffers(d3dpp.BufferCount, d3dpp.BufferDesc.Width, d3dpp.BufferDesc.Height, d3dpp.BufferDesc.Format, d3dpp.Windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); + + if (FAILED(hr)) + { + AssertFatal(false, "D3D11Device::reset - failed to resize back buffer!"); + } + + //recreate backbuffer view. depth stencil view and texture + D3D11_TEXTURE2D_DESC desc; + desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + desc.CPUAccessFlags = 0; + desc.Format = GFXD3D11TextureFormat[GFXFormatD24S8]; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.Width = d3dpp.BufferDesc.Width; + desc.Height = d3dpp.BufferDesc.Height; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.MiscFlags = 0; + + hr = mD3DDevice->CreateTexture2D(&desc, NULL, &mDeviceDepthStencil); + if (FAILED(hr)) + { + AssertFatal(false, "GFXD3D11Device::reset - couldn't create device's depth-stencil surface."); + } + + D3D11_DEPTH_STENCIL_VIEW_DESC depthDesc; + depthDesc.Format = GFXD3D11TextureFormat[GFXFormatD24S8]; + depthDesc.Flags = 0; + depthDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + depthDesc.Texture2D.MipSlice = 0; + + hr = mD3DDevice->CreateDepthStencilView(mDeviceDepthStencil, &depthDesc, &mDeviceDepthStencilView); + + if (FAILED(hr)) + { + AssertFatal(false, "GFXD3D11Device::reset - couldn't create depth stencil view"); + } + + hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mDeviceBackbuffer); + if (FAILED(hr)) + AssertFatal(false, "GFXD3D11Device::reset - coudln't retrieve backbuffer ref"); + + //create back buffer view + D3D11_RENDER_TARGET_VIEW_DESC RTDesc; + + RTDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB]; + RTDesc.Texture2D.MipSlice = 0; + RTDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + + hr = mD3DDevice->CreateRenderTargetView(mDeviceBackbuffer, &RTDesc, &mDeviceBackBufferView); + + if (FAILED(hr)) + AssertFatal(false, "GFXD3D11Device::reset - couldn't create back buffer target view"); mD3DDeviceContext->OMSetRenderTargets(1, &mDeviceBackBufferView, mDeviceDepthStencilView); - // Now reacquire all the resources we trashed earlier - reacquireDefaultPoolResources(); + hr = mSwapChain->SetFullscreenState(!d3dpp.Windowed, NULL); + + if (FAILED(hr)) + { + AssertFatal(false, "D3D11Device::reset - failed to change screen states!"); + } + + //Microsoft recommend this, see DXGI documentation + if (!d3dpp.Windowed) + { + displayModes.RefreshRate.Numerator = 0; + displayModes.RefreshRate.Denominator = 0; + hr = mSwapChain->ResizeTarget(&displayModes); + + if (FAILED(hr)) + { + AssertFatal(false, "D3D11Device::reset - failed to resize target!"); + } + } + mInitialized = true; + + // Now re aquire all the resources we trashed earlier + reacquireDefaultPoolResources(); + // Mark everything dirty and flush to card, for sanity. updateStates(true); } @@ -668,12 +774,11 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type) if(mGenericShader[GSColor] == NULL) { ShaderData *shaderData; - //shader model 4.0 is enough for the generic shaders - const char* shaderModel = "4.0"; + shaderData = new ShaderData(); shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/colorV.hlsl")); shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/colorP.hlsl")); - shaderData->setField("pixVersion", shaderModel); + shaderData->setField("pixVersion", "5.0"); shaderData->registerObject(); mGenericShader[GSColor] = shaderData->getShader(); mGenericShaderBuffer[GSColor] = mGenericShader[GSColor]->allocConstBuffer(); @@ -683,7 +788,7 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type) shaderData = new ShaderData(); shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/modColorTextureV.hlsl")); shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/modColorTextureP.hlsl")); - shaderData->setField("pixVersion", shaderModel); + shaderData->setField("pixVersion", "5.0"); shaderData->registerObject(); mGenericShader[GSModColorTexture] = shaderData->getShader(); mGenericShaderBuffer[GSModColorTexture] = mGenericShader[GSModColorTexture]->allocConstBuffer(); @@ -693,7 +798,7 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type) shaderData = new ShaderData(); shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/addColorTextureV.hlsl")); shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/addColorTextureP.hlsl")); - shaderData->setField("pixVersion", shaderModel); + shaderData->setField("pixVersion", "5.0"); shaderData->registerObject(); mGenericShader[GSAddColorTexture] = shaderData->getShader(); mGenericShaderBuffer[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->allocConstBuffer(); @@ -703,7 +808,7 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type) shaderData = new ShaderData(); shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/textureV.hlsl")); shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/textureP.hlsl")); - shaderData->setField("pixVersion", shaderModel); + shaderData->setField("pixVersion", "5.0"); shaderData->registerObject(); mGenericShader[GSTexture] = shaderData->getShader(); mGenericShaderBuffer[GSTexture] = mGenericShader[GSTexture]->allocConstBuffer(); @@ -763,7 +868,7 @@ void GFXD3D11Device::setShaderConstBufferInternal(GFXShaderConstBuffer* buffer) //----------------------------------------------------------------------------- -void GFXD3D11Device::clear(U32 flags, ColorI color, F32 z, U32 stencil) +void GFXD3D11Device::clear(U32 flags, const LinearColorF& color, F32 z, U32 stencil) { // Make sure we have flushed our render target state. _updateRenderTargets(); @@ -775,12 +880,7 @@ void GFXD3D11Device::clear(U32 flags, ColorI color, F32 z, U32 stencil) mD3DDeviceContext->OMGetRenderTargets(1, &rtView, &dsView); - const FLOAT clearColor[4] = { - static_cast(color.red) * (1.0f / 255.0f), - static_cast(color.green) * (1.0f / 255.0f), - static_cast(color.blue) * (1.0f / 255.0f), - static_cast(color.alpha) * (1.0f / 255.0f) - }; + const FLOAT clearColor[4] = { color.red, color.green, color.blue, color.alpha }; if (flags & GFXClearTarget && rtView) mD3DDeviceContext->ClearRenderTargetView(rtView, clearColor); @@ -1355,7 +1455,6 @@ String GFXD3D11Device::_createTempShaderInternal(const GFXVertexFormat *vertexFo //make shader mainBodyData.append("VertOut main(VertIn IN){VertOut OUT;"); - bool addedPadding = false; for (U32 i = 0; i < elemCount; i++) { const GFXVertexElement &element = vertexFormat->getElement(i); @@ -1363,8 +1462,6 @@ String GFXD3D11Device::_createTempShaderInternal(const GFXVertexFormat *vertexFo String semanticOut = semantic; String type; - AssertFatal(!(addedPadding && !element.isSemantic(GFXSemantic::PADDING)), "Padding added before data"); - if (element.isSemantic(GFXSemantic::POSITION)) { semantic = "POSITION"; @@ -1400,11 +1497,6 @@ String GFXD3D11Device::_createTempShaderInternal(const GFXVertexFormat *vertexFo semantic = String::ToString("BLENDWEIGHT%d", element.getSemanticIndex()); semanticOut = semantic; } - else if (element.isSemantic(GFXSemantic::PADDING)) - { - addedPadding = true; - continue; - } else { //Anything that falls thru to here will be a texture coord. @@ -1566,12 +1658,6 @@ GFXVertexDecl* GFXD3D11Device::allocVertexDecl( const GFXVertexFormat *vertexFor vd[i].SemanticName = "BLENDINDICES"; vd[i].SemanticIndex = element.getSemanticIndex(); } - else if (element.isSemantic(GFXSemantic::PADDING)) - { - i--; - elemCount--; - continue; - } else { //Anything that falls thru to here will be a texture coord. diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.h b/Engine/source/gfx/D3D11/gfxD3D11Device.h index 07f1162fb..98781678b 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.h +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.h @@ -39,6 +39,9 @@ #define D3D11 static_cast(GFX) #define D3D11DEVICE D3D11->getDevice() #define D3D11DEVICECONTEXT D3D11->getDeviceContext() +// DX 11.1 - always check these are not NULL, dodgy support with win 7 +#define D3D11DEVICE1 D3D11->getDevice1() +#define D3D11DEVICECONTEXT1 D3D11->getDeviceContext1() class PlatformWindow; class GFXD3D11ShaderConstBuffer; @@ -126,6 +129,9 @@ protected: IDXGISwapChain *mSwapChain; ID3D11Device* mD3DDevice; ID3D11DeviceContext* mD3DDeviceContext; + // DX 11.1 + ID3D11Device1* mD3DDevice1; + ID3D11DeviceContext1* mD3DDeviceContext1; ID3DUserDefinedAnnotation* mUserAnnotation; GFXShader* mCurrentShader; @@ -137,18 +143,12 @@ protected: F32 mPixVersion; - D3D_FEATURE_LEVEL mFeatureLevel; - // Shader Model targers - String mVertexShaderTarget; - String mPixelShaderTarget; - // String for use with shader macros in the form of shader model version * 10 - String mShaderModel; - bool mDebugLayers; DXGI_SAMPLE_DESC mMultisampleDesc; bool mOcclusionQuerySupported; + bool mCbufferPartialSupported; U32 mDrawInstancesCount; @@ -181,7 +181,7 @@ protected: virtual void setMatrix( GFXMatrixType /*mtype*/, const MatrixF &/*mat*/ ) { }; virtual void setLightInternal(U32 /*lightStage*/, const GFXLightInfo /*light*/, bool /*lightEnable*/) { }; virtual void setLightMaterialInternal(const GFXLightMaterial /*mat*/) { }; - virtual void setGlobalAmbientInternal(ColorF /*color*/) { }; + virtual void setGlobalAmbientInternal(LinearColorF /*color*/) { }; // } @@ -243,7 +243,7 @@ public: // Misc rendering control // { - virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ); + virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ); virtual bool beginSceneInternal(); virtual void endSceneInternal(); @@ -291,10 +291,13 @@ public: ID3D11DeviceContext* getDeviceContext(){ return mD3DDeviceContext; } ID3D11Device* getDevice(){ return mD3DDevice; } + IDXGISwapChain* getSwapChain() { return mSwapChain; } + //DX 11.1 + ID3D11DeviceContext1* getDeviceContext1() { return mD3DDeviceContext1; } + ID3D11Device1* getDevice1() { return mD3DDevice1; } /// Reset - void beginReset(); - void endReset(GFXD3D11WindowTarget *windowTarget); + void reset( DXGI_SWAP_CHAIN_DESC &d3dpp ); virtual void setupGenericShaders( GenericShaderType type = GSColor ); @@ -308,13 +311,6 @@ public: // Default multisample parameters DXGI_SAMPLE_DESC getMultisampleType() const { return mMultisampleDesc; } - // Get feature level this gfx device supports - D3D_FEATURE_LEVEL getFeatureLevel() const { return mFeatureLevel; } - // Shader Model targers - const String &getVertexShaderTarget() const { return mVertexShaderTarget; } - const String &getPixelShaderTarget() const { return mPixelShaderTarget; } - const String &getShaderModel() const { return mShaderModel; } - // grab the sampler map const SamplerMap &getSamplersMap() const { return mSamplersMap; } SamplerMap &getSamplersMap() { return mSamplersMap; } diff --git a/Engine/source/gfx/D3D11/gfxD3D11EnumTranslate.cpp b/Engine/source/gfx/D3D11/gfxD3D11EnumTranslate.cpp index 72acdd083..92e30fdc2 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11EnumTranslate.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11EnumTranslate.cpp @@ -54,11 +54,11 @@ void GFXD3D11EnumTranslate::init() GFXD3D11TextureFormat[GFXFormatA8L8] = DXGI_FORMAT_R8G8_UNORM; GFXD3D11TextureFormat[GFXFormatA8] = DXGI_FORMAT_A8_UNORM; GFXD3D11TextureFormat[GFXFormatL8] = DXGI_FORMAT_R8_UNORM; - GFXD3D11TextureFormat[GFXFormatDXT1] = DXGI_FORMAT_BC1_UNORM; - GFXD3D11TextureFormat[GFXFormatDXT2] = DXGI_FORMAT_BC1_UNORM; - GFXD3D11TextureFormat[GFXFormatDXT3] = DXGI_FORMAT_BC2_UNORM; - GFXD3D11TextureFormat[GFXFormatDXT4] = DXGI_FORMAT_BC2_UNORM; - GFXD3D11TextureFormat[GFXFormatDXT5] = DXGI_FORMAT_BC3_UNORM; + GFXD3D11TextureFormat[GFXFormatBC1] = DXGI_FORMAT_BC1_UNORM; + GFXD3D11TextureFormat[GFXFormatBC2] = DXGI_FORMAT_BC2_UNORM; + GFXD3D11TextureFormat[GFXFormatBC3] = DXGI_FORMAT_BC3_UNORM; + GFXD3D11TextureFormat[GFXFormatBC4] = DXGI_FORMAT_BC4_UNORM; + GFXD3D11TextureFormat[GFXFormatBC5] = DXGI_FORMAT_BC5_UNORM; GFXD3D11TextureFormat[GFXFormatR32G32B32A32F] = DXGI_FORMAT_R32G32B32A32_FLOAT; GFXD3D11TextureFormat[GFXFormatR16G16B16A16F] = DXGI_FORMAT_R16G16B16A16_FLOAT; GFXD3D11TextureFormat[GFXFormatL16] = DXGI_FORMAT_R16_UNORM; @@ -72,8 +72,14 @@ void GFXD3D11EnumTranslate::init() GFXD3D11TextureFormat[GFXFormatD24S8] = DXGI_FORMAT_D24_UNORM_S8_UINT; GFXD3D11TextureFormat[GFXFormatD24FS8] = DXGI_FORMAT_UNKNOWN; GFXD3D11TextureFormat[GFXFormatD16] = DXGI_FORMAT_D16_UNORM; + //sRGB GFXD3D11TextureFormat[GFXFormatR8G8B8A8_SRGB] = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; - GFXD3D11TextureFormat[GFXFormatR8G8B8A8_LINEAR_FORCE] = DXGI_FORMAT_R8G8B8A8_UNORM; + GFXD3D11TextureFormat[GFXFormatR8G8B8_SRGB] = DXGI_FORMAT_B8G8R8X8_UNORM_SRGB; + GFXD3D11TextureFormat[GFXFormatBC1_SRGB] = DXGI_FORMAT_BC1_UNORM_SRGB; + GFXD3D11TextureFormat[GFXFormatBC2_SRGB] = DXGI_FORMAT_BC2_UNORM_SRGB; + GFXD3D11TextureFormat[GFXFormatBC3_SRGB] = DXGI_FORMAT_BC3_UNORM_SRGB; + + //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ GFXD3D11TextureFilter[GFXTextureFilterNone] = D3D11_FILTER_MIN_MAG_MIP_POINT; diff --git a/Engine/source/gfx/D3D11/gfxD3D11Shader.cpp b/Engine/source/gfx/D3D11/gfxD3D11Shader.cpp index 054e19bc6..e102636bd 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Shader.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Shader.cpp @@ -204,39 +204,6 @@ bool GFXD3D11ConstBufferLayout::setMatrix(const ParamDesc& pd, const GFXShaderCo return false; } - else if (pd.constType == GFXSCT_Float4x3) - { - const U32 csize = 48; - - // Loop through and copy - bool ret = false; - U8* currDestPointer = basePointer + pd.offset; - const U8* currSourcePointer = static_cast(data); - const U8* endData = currSourcePointer + size; - while (currSourcePointer < endData) - { -#ifdef TORQUE_DOUBLE_CHECK_43MATS - Point4F col; - ((MatrixF*)currSourcePointer)->getRow(3, &col); - AssertFatal(col.x == 0.0f && col.y == 0.0f && col.z == 0.0f && col.w == 1.0f, "3rd row used"); -#endif - - if (dMemcmp(currDestPointer, currSourcePointer, csize) != 0) - { - dMemcpy(currDestPointer, currSourcePointer, csize); - ret = true; - } - else if (pd.constType == GFXSCT_Float4x3) - { - ret = true; - } - - currDestPointer += csize; - currSourcePointer += sizeof(MatrixF); - } - - return ret; - } else { PROFILE_SCOPE(GFXD3D11ConstBufferLayout_setMatrix_not4x4); @@ -251,6 +218,9 @@ bool GFXD3D11ConstBufferLayout::setMatrix(const ParamDesc& pd, const GFXShaderCo case GFXSCT_Float3x3 : csize = 44; //This takes up 16+16+12 break; + case GFXSCT_Float4x3: + csize = 48; + break; default: AssertFatal(false, "Unhandled case!"); return false; @@ -269,6 +239,10 @@ bool GFXD3D11ConstBufferLayout::setMatrix(const ParamDesc& pd, const GFXShaderCo dMemcpy(currDestPointer, currSourcePointer, csize); ret = true; } + else if (pd.constType == GFXSCT_Float4x3) + { + ret = true; + } currDestPointer += csize; currSourcePointer += sizeof(MatrixF); @@ -303,6 +277,8 @@ GFXD3D11ShaderConstBuffer::GFXD3D11ShaderConstBuffer( GFXD3D11Shader* shader, mPixelConstBufferLayout = pixelLayout; mPixelConstBuffer = new GenericConstBuffer(pixelLayout); + mDeviceContext = D3D11DEVICECONTEXT; + _createBuffers(); } @@ -431,7 +407,7 @@ void GFXD3D11ShaderConstBuffer::set(GFXShaderConstHandle* handle, const PlaneF& SET_CONSTANT(handle, fv, mVertexConstBuffer, mPixelConstBuffer); } -void GFXD3D11ShaderConstBuffer::set(GFXShaderConstHandle* handle, const ColorF& fv) +void GFXD3D11ShaderConstBuffer::set(GFXShaderConstHandle* handle, const LinearColorF& fv) { SET_CONSTANT(handle, fv, mVertexConstBuffer, mPixelConstBuffer); } @@ -654,8 +630,6 @@ void GFXD3D11ShaderConstBuffer::activate( GFXD3D11ShaderConstBuffer *prevShaderB } } - ID3D11DeviceContext* devCtx = D3D11DEVICECONTEXT; - D3D11_MAPPED_SUBRESOURCE pConstData; ZeroMemory(&pConstData, sizeof(D3D11_MAPPED_SUBRESOURCE)); @@ -670,11 +644,11 @@ void GFXD3D11ShaderConstBuffer::activate( GFXD3D11ShaderConstBuffer *prevShaderB for (U32 i = 0; i < subBuffers.size(); ++i) { const ConstSubBufferDesc &desc = subBuffers[i]; - devCtx->UpdateSubresource(mConstantBuffersV[i], 0, NULL, buf + desc.start, desc.size, 0); + mDeviceContext->UpdateSubresource(mConstantBuffersV[i], 0, NULL, buf + desc.start, desc.size, 0); nbBuffers++; } - devCtx->VSSetConstantBuffers(0, nbBuffers, mConstantBuffersV); + mDeviceContext->VSSetConstantBuffers(0, nbBuffers, mConstantBuffersV); } nbBuffers = 0; @@ -688,11 +662,11 @@ void GFXD3D11ShaderConstBuffer::activate( GFXD3D11ShaderConstBuffer *prevShaderB for (U32 i = 0; i < subBuffers.size(); ++i) { const ConstSubBufferDesc &desc = subBuffers[i]; - devCtx->UpdateSubresource(mConstantBuffersP[i], 0, NULL, buf + desc.start, desc.size, 0); + mDeviceContext->UpdateSubresource(mConstantBuffersP[i], 0, NULL, buf + desc.start, desc.size, 0); nbBuffers++; } - devCtx->PSSetConstantBuffers(0, nbBuffers, mConstantBuffersP); + mDeviceContext->PSSetConstantBuffers(0, nbBuffers, mConstantBuffersP); } #ifdef TORQUE_DEBUG @@ -790,8 +764,9 @@ bool GFXD3D11Shader::_init() d3dMacros[i+smGlobalMacros.size()].Definition = mMacros[i].value.c_str(); } + //TODO support D3D_FEATURE_LEVEL properly with shaders instead of hard coding at hlsl 5 d3dMacros[macroCount - 2].Name = "TORQUE_SM"; - d3dMacros[macroCount - 2].Definition = D3D11->getShaderModel().c_str(); + d3dMacros[macroCount - 2].Definition = "50"; memset(&d3dMacros[macroCount - 1], 0, sizeof(D3D_SHADER_MACRO)); @@ -809,21 +784,18 @@ bool GFXD3D11Shader::_init() mSamplerDescriptions.clear(); mShaderConsts.clear(); - String vertTarget = D3D11->getVertexShaderTarget(); - String pixTarget = D3D11->getPixelShaderTarget(); - if ( !Con::getBoolVariable( "$shaders::forceLoadCSF", false ) ) { - if (!mVertexFile.isEmpty() && !_compileShader( mVertexFile, vertTarget, d3dMacros, mVertexConstBufferLayout, mSamplerDescriptions ) ) + if (!mVertexFile.isEmpty() && !_compileShader( mVertexFile, "vs_5_0", d3dMacros, mVertexConstBufferLayout, mSamplerDescriptions ) ) return false; - if (!mPixelFile.isEmpty() && !_compileShader( mPixelFile, pixTarget, d3dMacros, mPixelConstBufferLayout, mSamplerDescriptions ) ) + if (!mPixelFile.isEmpty() && !_compileShader( mPixelFile, "ps_5_0", d3dMacros, mPixelConstBufferLayout, mSamplerDescriptions ) ) return false; } else { - if ( !_loadCompiledOutput( mVertexFile, vertTarget, mVertexConstBufferLayout, mSamplerDescriptions ) ) + if ( !_loadCompiledOutput( mVertexFile, "vs_5_0", mVertexConstBufferLayout, mSamplerDescriptions ) ) { if ( smLogErrors ) Con::errorf( "GFXD3D11Shader::init - Unable to load precompiled vertex shader for '%s'.", mVertexFile.getFullPath().c_str() ); @@ -831,7 +803,7 @@ bool GFXD3D11Shader::_init() return false; } - if ( !_loadCompiledOutput( mPixelFile, pixTarget, mPixelConstBufferLayout, mSamplerDescriptions ) ) + if ( !_loadCompiledOutput( mPixelFile, "ps_5_0", mPixelConstBufferLayout, mSamplerDescriptions ) ) { if ( smLogErrors ) Con::errorf( "GFXD3D11Shader::init - Unable to load precompiled pixel shader for '%s'.", mPixelFile.getFullPath().c_str() ); @@ -877,12 +849,12 @@ bool GFXD3D11Shader::_compileShader( const Torque::Path &filePath, ID3DBlob* errorBuff = NULL; ID3D11ShaderReflection* reflectionTable = NULL; -#ifdef TORQUE_DEBUG - U32 flags = D3DCOMPILE_DEBUG | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_WARNINGS_ARE_ERRORS; -#else - U32 flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_OPTIMIZATION_LEVEL3; //TODO double check load times with D3DCOMPILE_OPTIMIZATION_LEVEL3 - //recommended flags for NSight, uncomment to use. NSight should be used in release mode only. *Still works with above flags however - //flags = D3DCOMPILE_DEBUG | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_PREFER_FLOW_CONTROL | D3DCOMPILE_SKIP_OPTIMIZATION; +#ifdef TORQUE_GFX_VISUAL_DEBUG //for use with NSight, GPU Perf studio, VS graphics debugger + U32 flags = D3DCOMPILE_DEBUG | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_PREFER_FLOW_CONTROL | D3DCOMPILE_SKIP_OPTIMIZATION; +#elif defined(TORQUE_DEBUG) //debug build + U32 flags = D3DCOMPILE_DEBUG | D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_WARNINGS_ARE_ERRORS; +#else //release build + U32 flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_OPTIMIZATION_LEVEL3; #endif #ifdef D3D11_DEBUG_SPEW @@ -1054,20 +1026,20 @@ bool GFXD3D11Shader::_compileShader( const Torque::Path &filePath, return result; } -void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *pTable, +void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *refTable, GenericConstBufferLayout *bufferLayoutIn, Vector &samplerDescriptions ) { PROFILE_SCOPE( GFXD3D11Shader_GetShaderConstants ); - AssertFatal(pTable, "NULL constant table not allowed, is this an assembly shader?"); + AssertFatal(refTable, "NULL constant table not allowed, is this an assembly shader?"); GFXD3D11ConstBufferLayout *bufferLayout = (GFXD3D11ConstBufferLayout*)bufferLayoutIn; Vector &subBuffers = bufferLayout->getSubBufferDesc(); subBuffers.clear(); D3D11_SHADER_DESC tableDesc; - HRESULT hr = pTable->GetDesc(&tableDesc); + HRESULT hr = refTable->GetDesc(&tableDesc); if (FAILED(hr)) { AssertFatal(false, "Shader Reflection table unable to be created"); @@ -1077,7 +1049,7 @@ void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *pTable, U32 bufferOffset = 0; for (U32 i = 0; i < tableDesc.ConstantBuffers; i++) { - ID3D11ShaderReflectionConstantBuffer* constantBuffer = pTable->GetConstantBufferByIndex(i); + ID3D11ShaderReflectionConstantBuffer* constantBuffer = refTable->GetConstantBufferByIndex(i); D3D11_SHADER_BUFFER_DESC constantBufferDesc; if (constantBuffer->GetDesc(&constantBufferDesc) == S_OK) @@ -1162,7 +1134,7 @@ void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *pTable, { GFXShaderConstDesc desc; D3D11_SHADER_INPUT_BIND_DESC bindDesc; - pTable->GetResourceBindingDesc(i, &bindDesc); + refTable->GetResourceBindingDesc(i, &bindDesc); switch (bindDesc.Type) { diff --git a/Engine/source/gfx/D3D11/gfxD3D11Shader.h b/Engine/source/gfx/D3D11/gfxD3D11Shader.h index fc4cac62c..b20ea8e3c 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Shader.h +++ b/Engine/source/gfx/D3D11/gfxD3D11Shader.h @@ -297,6 +297,8 @@ public: class GFXD3D11ShaderConstBuffer : public GFXShaderConstBuffer { friend class GFXD3D11Shader; + // Cache device context + ID3D11DeviceContext* mDeviceContext; public: @@ -324,7 +326,7 @@ public: virtual void set(GFXShaderConstHandle* handle, const Point3F& fv); virtual void set(GFXShaderConstHandle* handle, const Point4F& fv); virtual void set(GFXShaderConstHandle* handle, const PlaneF& fv); - virtual void set(GFXShaderConstHandle* handle, const ColorF& fv); + virtual void set(GFXShaderConstHandle* handle, const LinearColorF& fv); virtual void set(GFXShaderConstHandle* handle, const S32 f); virtual void set(GFXShaderConstHandle* handle, const Point2I& fv); virtual void set(GFXShaderConstHandle* handle, const Point3I& fv); @@ -434,7 +436,7 @@ protected: GenericConstBufferLayout *bufferLayout, Vector &samplerDescriptions ); - void _getShaderConstants( ID3D11ShaderReflection* pTable, + void _getShaderConstants( ID3D11ShaderReflection* refTable, GenericConstBufferLayout *bufferLayout, Vector &samplerDescriptions ); diff --git a/Engine/source/gfx/D3D11/gfxD3D11StateBlock.cpp b/Engine/source/gfx/D3D11/gfxD3D11StateBlock.cpp index 9686f12e2..72cbd3c76 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11StateBlock.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11StateBlock.cpp @@ -151,29 +151,32 @@ GFXD3D11StateBlock::GFXD3D11StateBlock(const GFXStateBlockDesc& desc) mSamplerDesc[i].MinLOD = 0; mSamplerDesc[i].MaxLOD = FLT_MAX; + const bool comparison = gfxSamplerState.samplerFunc != GFXCmpNever; + if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterPoint) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_POINT; else if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterLinear) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR : D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterPoint) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT : D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterLinear) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR : D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; else if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterLinear && gfxSamplerState.mipFilter == GFXTextureFilterPoint) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT : D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; else if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterLinear && gfxSamplerState.mipFilter == GFXTextureFilterLinear) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR : D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterLinear && gfxSamplerState.mipFilter == GFXTextureFilterPoint) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT : D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear) - mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR : D3D11_FILTER_MIN_MAG_MIP_LINEAR; else - mSamplerDesc[i].Filter = D3D11_FILTER_ANISOTROPIC; + mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_ANISOTROPIC : D3D11_FILTER_ANISOTROPIC; mSamplerDesc[i].BorderColor[0] = 1.0f; mSamplerDesc[i].BorderColor[1] = 1.0f; mSamplerDesc[i].BorderColor[2] = 1.0f; mSamplerDesc[i].BorderColor[3] = 1.0f; + mSamplerDesc[i].ComparisonFunc = GFXD3D11CmpFunc[gfxSamplerState.samplerFunc]; hr = D3D11DEVICE->CreateSamplerState(&mSamplerDesc[i], &mSamplerStates[i]); if (FAILED(hr)) diff --git a/Engine/source/gfx/D3D11/gfxD3D11Target.cpp b/Engine/source/gfx/D3D11/gfxD3D11Target.cpp index 33c5d9ef2..6c46107e8 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Target.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Target.cpp @@ -248,10 +248,10 @@ void GFXD3D11TextureTarget::activate() stateApplied(); // Now set all the new surfaces into the appropriate slots. - ID3D11RenderTargetView* rtViews[MaxRenderSlotId] = { NULL, NULL, NULL, NULL, NULL, NULL}; + ID3D11RenderTargetView* rtViews[MaxRenderSlotId] = { NULL, NULL, NULL, NULL, NULL, NULL }; ID3D11DepthStencilView* dsView = (ID3D11DepthStencilView*)(mTargetViews[GFXTextureTarget::DepthStencil]); - for (U32 i = 0; i < 4; i++) + for (U32 i = 0; i < 6; i++) { rtViews[i] = (ID3D11RenderTargetView*)mTargetViews[GFXTextureTarget::Color0 + i]; } @@ -263,7 +263,7 @@ void GFXD3D11TextureTarget::activate() void GFXD3D11TextureTarget::deactivate() { //re-gen mip maps - for (U32 i = 0; i < 4; i++) + for (U32 i = 0; i < 6; i++) { ID3D11ShaderResourceView* pSRView = mTargetSRViews[GFXTextureTarget::Color0 + i]; if (pSRView) @@ -314,34 +314,21 @@ void GFXD3D11TextureTarget::resurrect() GFXD3D11WindowTarget::GFXD3D11WindowTarget() { - mWindow = NULL; - mBackBuffer = NULL; - mDepthStencilView = NULL; - mDepthStencil = NULL; - mBackBufferView = NULL; - mSecondaryWindow = false; + mWindow = NULL; + mBackbuffer = NULL; } GFXD3D11WindowTarget::~GFXD3D11WindowTarget() { - SAFE_RELEASE(mDepthStencilView) - SAFE_RELEASE(mDepthStencil); - SAFE_RELEASE(mBackBufferView); - SAFE_RELEASE(mBackBuffer); - SAFE_RELEASE(mSwapChain); + SAFE_RELEASE(mBackbuffer); } void GFXD3D11WindowTarget::initPresentationParams() { // Get some video mode related info. - const GFXVideoMode &vm = mWindow->getVideoMode(); - HWND hwnd = (HWND)mWindow->getSystemWindow(PlatformWindow::WindowSystem_Windows); - - // Do some validation... - if (vm.fullScreen && mSecondaryWindow) - { - AssertFatal(false, "GFXD3D11WindowTarget::initPresentationParams - Cannot go fullscreen with secondary window!"); - } + GFXVideoMode vm = mWindow->getVideoMode(); + Win32Window* win = static_cast(mWindow); + HWND hwnd = win->getHWND(); mPresentationParams = D3D11->setupPresentParams(vm, hwnd); } @@ -360,178 +347,40 @@ GFXFormat GFXD3D11WindowTarget::getFormat() bool GFXD3D11WindowTarget::present() { - return (mSwapChain->Present(!D3D11->smDisableVSync, 0) == S_OK); + return (D3D11->getSwapChain()->Present(!D3D11->smDisableVSync, 0) == S_OK); } -void GFXD3D11WindowTarget::createSwapChain() +void GFXD3D11WindowTarget::setImplicitSwapChain() { - //create dxgi factory & swapchain - IDXGIFactory1* DXGIFactory; - HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast(&DXGIFactory)); - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::createSwapChain - couldn't create dxgi factory."); - - hr = DXGIFactory->CreateSwapChain(D3D11DEVICE, &mPresentationParams, &mSwapChain); - - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::createSwapChain - couldn't create swap chain."); - - SAFE_RELEASE(DXGIFactory); -} - -void GFXD3D11WindowTarget::createBuffersAndViews() -{ - //release old if they exist - SAFE_RELEASE(mDepthStencilView); - SAFE_RELEASE(mDepthStencil); - SAFE_RELEASE(mBackBufferView); - SAFE_RELEASE(mBackBuffer); - - //grab video mode - const GFXVideoMode &vm = mWindow->getVideoMode(); - //create depth/stencil - D3D11_TEXTURE2D_DESC desc; - desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; - desc.CPUAccessFlags = 0; - desc.Format = GFXD3D11TextureFormat[GFXFormatD24S8]; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.Width = vm.resolution.x; - desc.Height = vm.resolution.y; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.MiscFlags = 0; - - HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, NULL, &mDepthStencil); - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::createBuffersAndViews - couldn't create device's depth-stencil surface."); - - D3D11_DEPTH_STENCIL_VIEW_DESC depthDesc; - depthDesc.Format = GFXD3D11TextureFormat[GFXFormatD24S8]; - depthDesc.Flags = 0; - depthDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - depthDesc.Texture2D.MipSlice = 0; - - hr = D3D11DEVICE->CreateDepthStencilView(mDepthStencil, &depthDesc, &mDepthStencilView); - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::createBuffersAndViews - couldn't create depth stencil view"); - - setBackBuffer(); - - //create back buffer view - D3D11_RENDER_TARGET_VIEW_DESC RTDesc; - RTDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8]; - RTDesc.Texture2D.MipSlice = 0; - RTDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - - hr = D3D11DEVICE->CreateRenderTargetView(mBackBuffer, &RTDesc, &mBackBufferView); - - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::createBuffersAndViews - couldn't create back buffer target view"); - - //debug names -#ifdef TORQUE_DEBUG - if (!mSecondaryWindow) - { - String backBufferName = "MainBackBuffer"; - String depthSteniclName = "MainDepthStencil"; - String backBuffViewName = "MainBackBuffView"; - String depthStencViewName = "MainDepthView"; - mBackBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, backBufferName.size(), backBufferName.c_str()); - mDepthStencil->SetPrivateData(WKPDID_D3DDebugObjectName, depthSteniclName.size(), depthSteniclName.c_str()); - mDepthStencilView->SetPrivateData(WKPDID_D3DDebugObjectName, depthStencViewName.size(), depthStencViewName.c_str()); - mBackBufferView->SetPrivateData(WKPDID_D3DDebugObjectName, backBuffViewName.size(), backBuffViewName.c_str()); - } -#endif + if (!mBackbuffer) + D3D11->mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackbuffer); } void GFXD3D11WindowTarget::resetMode() { - HRESULT hr; - if (mSwapChain) - { - // The current video settings. - DXGI_SWAP_CHAIN_DESC desc; - hr = mSwapChain->GetDesc(&desc); - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to get swap chain description!"); - - bool fullscreen = !desc.Windowed; - Point2I backbufferSize(desc.BufferDesc.Width, desc.BufferDesc.Height); - - // The settings we are now applying. - const GFXVideoMode &vm = mWindow->getVideoMode(); - - // Early out if none of the settings which require a device reset - // have changed. - if (backbufferSize == vm.resolution && - fullscreen == vm.fullScreen) - return; - } - - //release old buffers and views - SAFE_RELEASE(mDepthStencilView) - SAFE_RELEASE(mDepthStencil); - SAFE_RELEASE(mBackBufferView); - SAFE_RELEASE(mBackBuffer); - - if(!mSecondaryWindow) - D3D11->beginReset(); - mWindow->setSuppressReset(true); // Setup our presentation params. initPresentationParams(); - if (!mPresentationParams.Windowed) - { - mPresentationParams.BufferDesc.RefreshRate.Numerator = 0; - mPresentationParams.BufferDesc.RefreshRate.Denominator = 0; - hr = mSwapChain->ResizeTarget(&mPresentationParams.BufferDesc); - - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to resize target!"); - - } - - hr = mSwapChain->ResizeBuffers(mPresentationParams.BufferCount, mPresentationParams.BufferDesc.Width, mPresentationParams.BufferDesc.Height, - mPresentationParams.BufferDesc.Format, mPresentationParams.Windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); - - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to resize back buffer!"); - - hr = mSwapChain->SetFullscreenState(!mPresentationParams.Windowed, NULL); - - if (FAILED(hr)) - AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to change screen states!"); + // Otherwise, we have to reset the device, if we're the implicit swapchain. + D3D11->reset(mPresentationParams); // Update our size, too. mSize = Point2I(mPresentationParams.BufferDesc.Width, mPresentationParams.BufferDesc.Height); mWindow->setSuppressReset(false); - - //re-create buffers and views - createBuffersAndViews(); - - if (!mSecondaryWindow) - D3D11->endReset(this); + GFX->beginReset(); } void GFXD3D11WindowTarget::zombify() { - SAFE_RELEASE(mBackBuffer); + SAFE_RELEASE(mBackbuffer); } void GFXD3D11WindowTarget::resurrect() { - setBackBuffer(); -} - -void GFXD3D11WindowTarget::setBackBuffer() -{ - if (!mBackBuffer) - mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer); + setImplicitSwapChain(); } void GFXD3D11WindowTarget::activate() @@ -542,10 +391,10 @@ void GFXD3D11WindowTarget::activate() ID3D11RenderTargetView* rtViews[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; D3D11DEVICECONTEXT->OMSetRenderTargets(8, rtViews, NULL); - D3D11DEVICECONTEXT->OMSetRenderTargets(1, &mBackBufferView, mDepthStencilView); + D3D11DEVICECONTEXT->OMSetRenderTargets(1, &D3D11->mDeviceBackBufferView, D3D11->mDeviceDepthStencilView); DXGI_SWAP_CHAIN_DESC pp; - mSwapChain->GetDesc(&pp); + D3D11->mSwapChain->GetDesc(&pp); // Update our video mode here, too. GFXVideoMode vm; @@ -563,35 +412,5 @@ void GFXD3D11WindowTarget::resolveTo(GFXTextureObject *tex) D3D11_TEXTURE2D_DESC desc; ID3D11Texture2D* surf = ((GFXD3D11TextureObject*)(tex))->get2DTex(); surf->GetDesc(&desc); - D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, mBackBuffer, 0, desc.Format); -} - -IDXGISwapChain *GFXD3D11WindowTarget::getSwapChain() -{ - mSwapChain->AddRef(); - return mSwapChain; -} - -ID3D11Texture2D *GFXD3D11WindowTarget::getBackBuffer() -{ - mBackBuffer->AddRef(); - return mBackBuffer; -} - -ID3D11Texture2D *GFXD3D11WindowTarget::getDepthStencil() -{ - mDepthStencil->AddRef(); - return mDepthStencil; -} - -ID3D11RenderTargetView* GFXD3D11WindowTarget::getBackBufferView() -{ - mBackBufferView->AddRef(); - return mBackBufferView; -} - -ID3D11DepthStencilView* GFXD3D11WindowTarget::getDepthStencilView() -{ - mDepthStencilView->AddRef(); - return mDepthStencilView; + D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, D3D11->mDeviceBackbuffer, 0, desc.Format); } \ No newline at end of file diff --git a/Engine/source/gfx/D3D11/gfxD3D11Target.h b/Engine/source/gfx/D3D11/gfxD3D11Target.h index 44233e0e2..055f11ccf 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Target.h +++ b/Engine/source/gfx/D3D11/gfxD3D11Target.h @@ -76,11 +76,7 @@ class GFXD3D11WindowTarget : public GFXWindowTarget friend class GFXD3D11Device; /// Our backbuffer - ID3D11Texture2D *mBackBuffer; - ID3D11Texture2D *mDepthStencil; - ID3D11RenderTargetView* mBackBufferView; - ID3D11DepthStencilView* mDepthStencilView; - IDXGISwapChain *mSwapChain; + ID3D11Texture2D *mBackbuffer; /// Maximum size we can render to. Point2I mSize; @@ -89,9 +85,6 @@ class GFXD3D11WindowTarget : public GFXWindowTarget /// Internal interface that notifies us we need to reset our video mode. void resetMode(); - /// Is this a secondary window - bool mSecondaryWindow; - public: GFXD3D11WindowTarget(); @@ -102,9 +95,7 @@ public: virtual bool present(); void initPresentationParams(); - void createSwapChain(); - void createBuffersAndViews(); - void setBackBuffer(); + void setImplicitSwapChain(); virtual void activate(); @@ -112,13 +103,6 @@ public: void resurrect(); virtual void resolveTo( GFXTextureObject *tex ); - - // These are all reference counted and must be released by whomever uses the get* function - IDXGISwapChain *getSwapChain(); - ID3D11Texture2D *getBackBuffer(); - ID3D11Texture2D *getDepthStencil(); - ID3D11RenderTargetView* getBackBufferView(); - ID3D11DepthStencilView* getDepthStencilView(); }; #endif diff --git a/Engine/source/gfx/D3D11/gfxD3D11TextureManager.cpp b/Engine/source/gfx/D3D11/gfxD3D11TextureManager.cpp index ba90c4064..2fdfb28e7 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11TextureManager.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11TextureManager.cpp @@ -23,6 +23,7 @@ #include "gfx/D3D11/gfxD3D11Device.h" #include "gfx/D3D11/gfxD3D11EnumTranslate.h" #include "gfx/bitmap/bitmapUtils.h" +#include "gfx/bitmap/imageUtils.h" #include "gfx/gfxCardProfile.h" #include "gfx/gfxStringEnumTranslate.h" #include "core/strings/unicode.h" @@ -139,7 +140,7 @@ void GFXD3D11TextureManager::_innerCreateTexture( GFXD3D11TextureObject *retTex, } else { - UINT numQualityLevels = 0; + U32 numQualityLevels = 0; switch (antialiasLevel) { @@ -151,7 +152,6 @@ void GFXD3D11TextureManager::_innerCreateTexture( GFXD3D11TextureObject *retTex, default: { antialiasLevel = 0; - UINT numQualityLevels; D3D11DEVICE->CheckMultisampleQualityLevels(d3dTextureFormat, antialiasLevel, &numQualityLevels); AssertFatal(numQualityLevels, "Invalid AA level!"); break; @@ -287,7 +287,7 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *p const bool supportsAutoMips = GFX->getCardProfiler()->queryProfile("autoMipMapLevel", true); // Helper bool - const bool isCompressedTexFmt = aTexture->mFormat >= GFXFormatDXT1 && aTexture->mFormat <= GFXFormatDXT5; + const bool isCompressedTexFmt = ImageUtil::isCompressedFormat(aTexture->mFormat); // Settings for mipmap generation U32 maxDownloadMip = pDL->getNumMipLevels(); @@ -312,10 +312,10 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *p switch(texture->mFormat) { - case GFXFormatR8G8B8: + case GFXFormatR8G8B8: + case GFXFormatR8G8B8_SRGB: { PROFILE_SCOPE(Swizzle24_Upload); - AssertFatal(pDL->getFormat() == GFXFormatR8G8B8, "Assumption failed"); U8* Bits = new U8[pDL->getWidth(i) * pDL->getHeight(i) * 4]; dMemcpy(Bits, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * 3); @@ -330,6 +330,7 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *p case GFXFormatR8G8B8A8: case GFXFormatR8G8B8X8: + case GFXFormatR8G8B8A8_SRGB: { PROFILE_SCOPE(Swizzle32_Upload); copyBuffer = new U8[pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel()]; @@ -360,9 +361,9 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *p switch( texture->mFormat ) { case GFXFormatR8G8B8: + case GFXFormatR8G8B8_SRGB: { PROFILE_SCOPE(Swizzle24_Upload); - AssertFatal(pDL->getFormat() == GFXFormatR8G8B8, "Assumption failed"); U8* Bits = new U8[pDL->getWidth(i) * pDL->getHeight(i) * 4]; dMemcpy(Bits, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * 3); @@ -375,6 +376,7 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *p case GFXFormatR8G8B8A8: case GFXFormatR8G8B8X8: + case GFXFormatR8G8B8A8_SRGB: { PROFILE_SCOPE(Swizzle32_Upload); dev->getDeviceSwizzle32()->ToBuffer(mapping.pData, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel()); @@ -417,7 +419,7 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *inTex, void *raw) U8* Bits = NULL; - if(texture->mFormat == GFXFormatR8G8B8) + if(texture->mFormat == GFXFormatR8G8B8 || texture->mFormat == GFXFormatR8G8B8_SRGB) { // convert 24 bit to 32 bit Bits = new U8[texture->getWidth() * texture->getHeight() * texture->getDepth() * 4]; @@ -430,8 +432,10 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *inTex, void *raw) switch(texture->mFormat) { case GFXFormatR8G8B8: + case GFXFormatR8G8B8_SRGB: case GFXFormatR8G8B8A8: case GFXFormatR8G8B8X8: + case GFXFormatR8G8B8A8_SRGB: bytesPerPix = 4; break; } @@ -444,7 +448,7 @@ bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *inTex, void *raw) box.top = 0; box.bottom = texture->getHeight(); - if(texture->mFormat == GFXFormatR8G8B8) // converted format also for volume textures + if(texture->mFormat == GFXFormatR8G8B8 || texture->mFormat == GFXFormatR8G8B8_SRGB) // converted format also for volume textures dev->getDeviceContext()->UpdateSubresource(texture->get3DTex(), 0, &box, Bits, texture->getWidth() * bytesPerPix, texture->getHeight() * bytesPerPix); else dev->getDeviceContext()->UpdateSubresource(texture->get3DTex(), 0, &box, raw, texture->getWidth() * bytesPerPix, texture->getHeight() * bytesPerPix); diff --git a/Engine/source/gfx/D3D11/gfxD3D11TextureObject.cpp b/Engine/source/gfx/D3D11/gfxD3D11TextureObject.cpp index 22af430f0..7fdd8201e 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11TextureObject.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11TextureObject.cpp @@ -74,7 +74,7 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect / mLockTex->getWidth() != getWidth() || mLockTex->getHeight() != getHeight() ) { - mLockTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) ); + mLockTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) ); } PROFILE_START(GFXD3D11TextureObject_lockRT); @@ -180,8 +180,8 @@ bool GFXD3D11TextureObject::copyToBmp(GBitmap* bmp) // check format limitations // at the moment we only support RGBA for the source (other 4 byte formats should // be easy to add though) - AssertFatal(mFormat == GFXFormatR8G8B8A8 || mFormat == GFXFormatR8G8B8A8_LINEAR_FORCE, "copyToBmp: invalid format"); - if (mFormat != GFXFormatR8G8B8A8 && mFormat != GFXFormatR8G8B8A8_LINEAR_FORCE) + AssertFatal(mFormat == GFXFormatR8G8B8A8 || mFormat == GFXFormatR8G8B8A8_LINEAR_FORCE || mFormat == GFXFormatR8G8B8A8_SRGB, "copyToBmp: invalid format"); + if (mFormat != GFXFormatR8G8B8A8 && mFormat != GFXFormatR8G8B8A8_LINEAR_FORCE && mFormat != GFXFormatR8G8B8A8_SRGB) return false; PROFILE_START(GFXD3D11TextureObject_copyToBmp); @@ -197,7 +197,8 @@ bool GFXD3D11TextureObject::copyToBmp(GBitmap* bmp) const U32 sourceBytesPerPixel = 4; U32 destBytesPerPixel = 0; - if (bmp->getFormat() == GFXFormatR8G8B8A8 || bmp->getFormat() == GFXFormatR8G8B8A8_LINEAR_FORCE) + const GFXFormat fmt = bmp->getFormat(); + if (fmt == GFXFormatR8G8B8A8 || fmt == GFXFormatR8G8B8A8_LINEAR_FORCE || fmt == GFXFormatR8G8B8A8_SRGB) destBytesPerPixel = 4; else if(bmp->getFormat() == GFXFormatR8G8B8) destBytesPerPixel = 3; diff --git a/Engine/source/gfx/Null/gfxNullDevice.h b/Engine/source/gfx/Null/gfxNullDevice.h index 28d6ad4e9..8fa5477fa 100644 --- a/Engine/source/gfx/Null/gfxNullDevice.h +++ b/Engine/source/gfx/Null/gfxNullDevice.h @@ -101,7 +101,7 @@ protected: virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable); virtual void setLightMaterialInternal(const GFXLightMaterial mat) { }; - virtual void setGlobalAmbientInternal(ColorF color) { }; + virtual void setGlobalAmbientInternal(LinearColorF color) { }; /// @name State Initalization. /// @{ @@ -150,7 +150,7 @@ public: virtual GFXShader* createShader() { return NULL; }; - virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ) { }; + virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ) { }; virtual bool beginSceneInternal() { return true; }; virtual void endSceneInternal() { }; diff --git a/Engine/source/gfx/bitmap/ddsData.h b/Engine/source/gfx/bitmap/ddsData.h new file mode 100644 index 000000000..6c406ad34 --- /dev/null +++ b/Engine/source/gfx/bitmap/ddsData.h @@ -0,0 +1,779 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// https://github.com/Microsoft/DirectXTex +//////////////////////////////////////////////////////////////////////////////// + +#ifndef _DDSDATA_H_ +#define _DDSDATA_H_ + +#ifndef _TORQUE_TYPES_H_ +#include "platform/types.h" +#endif + +#include "core/util/fourcc.h" + +#ifdef TORQUE_OS_WIN +#include +#endif + +namespace dds +{ + /////////////////////////////////////////////////////////////////////////////////// + // DXGI Formats // + /////////////////////////////////////////////////////////////////////////////////// +#ifndef TORQUE_OS_WIN + //From directx SDK + typedef enum DXGI_FORMAT + { + DXGI_FORMAT_UNKNOWN = 0, + DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, + DXGI_FORMAT_R32G32B32A32_FLOAT = 2, + DXGI_FORMAT_R32G32B32A32_UINT = 3, + DXGI_FORMAT_R32G32B32A32_SINT = 4, + DXGI_FORMAT_R32G32B32_TYPELESS = 5, + DXGI_FORMAT_R32G32B32_FLOAT = 6, + DXGI_FORMAT_R32G32B32_UINT = 7, + DXGI_FORMAT_R32G32B32_SINT = 8, + DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, + DXGI_FORMAT_R16G16B16A16_FLOAT = 10, + DXGI_FORMAT_R16G16B16A16_UNORM = 11, + DXGI_FORMAT_R16G16B16A16_UINT = 12, + DXGI_FORMAT_R16G16B16A16_SNORM = 13, + DXGI_FORMAT_R16G16B16A16_SINT = 14, + DXGI_FORMAT_R32G32_TYPELESS = 15, + DXGI_FORMAT_R32G32_FLOAT = 16, + DXGI_FORMAT_R32G32_UINT = 17, + DXGI_FORMAT_R32G32_SINT = 18, + DXGI_FORMAT_R32G8X24_TYPELESS = 19, + DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, + DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, + DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, + DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, + DXGI_FORMAT_R10G10B10A2_UNORM = 24, + DXGI_FORMAT_R10G10B10A2_UINT = 25, + DXGI_FORMAT_R11G11B10_FLOAT = 26, + DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, + DXGI_FORMAT_R8G8B8A8_UNORM = 28, + DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, + DXGI_FORMAT_R8G8B8A8_UINT = 30, + DXGI_FORMAT_R8G8B8A8_SNORM = 31, + DXGI_FORMAT_R8G8B8A8_SINT = 32, + DXGI_FORMAT_R16G16_TYPELESS = 33, + DXGI_FORMAT_R16G16_FLOAT = 34, + DXGI_FORMAT_R16G16_UNORM = 35, + DXGI_FORMAT_R16G16_UINT = 36, + DXGI_FORMAT_R16G16_SNORM = 37, + DXGI_FORMAT_R16G16_SINT = 38, + DXGI_FORMAT_R32_TYPELESS = 39, + DXGI_FORMAT_D32_FLOAT = 40, + DXGI_FORMAT_R32_FLOAT = 41, + DXGI_FORMAT_R32_UINT = 42, + DXGI_FORMAT_R32_SINT = 43, + DXGI_FORMAT_R24G8_TYPELESS = 44, + DXGI_FORMAT_D24_UNORM_S8_UINT = 45, + DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, + DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, + DXGI_FORMAT_R8G8_TYPELESS = 48, + DXGI_FORMAT_R8G8_UNORM = 49, + DXGI_FORMAT_R8G8_UINT = 50, + DXGI_FORMAT_R8G8_SNORM = 51, + DXGI_FORMAT_R8G8_SINT = 52, + DXGI_FORMAT_R16_TYPELESS = 53, + DXGI_FORMAT_R16_FLOAT = 54, + DXGI_FORMAT_D16_UNORM = 55, + DXGI_FORMAT_R16_UNORM = 56, + DXGI_FORMAT_R16_UINT = 57, + DXGI_FORMAT_R16_SNORM = 58, + DXGI_FORMAT_R16_SINT = 59, + DXGI_FORMAT_R8_TYPELESS = 60, + DXGI_FORMAT_R8_UNORM = 61, + DXGI_FORMAT_R8_UINT = 62, + DXGI_FORMAT_R8_SNORM = 63, + DXGI_FORMAT_R8_SINT = 64, + DXGI_FORMAT_A8_UNORM = 65, + DXGI_FORMAT_R1_UNORM = 66, + DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, + DXGI_FORMAT_R8G8_B8G8_UNORM = 68, + DXGI_FORMAT_G8R8_G8B8_UNORM = 69, + DXGI_FORMAT_BC1_TYPELESS = 70, + DXGI_FORMAT_BC1_UNORM = 71, + DXGI_FORMAT_BC1_UNORM_SRGB = 72, + DXGI_FORMAT_BC2_TYPELESS = 73, + DXGI_FORMAT_BC2_UNORM = 74, + DXGI_FORMAT_BC2_UNORM_SRGB = 75, + DXGI_FORMAT_BC3_TYPELESS = 76, + DXGI_FORMAT_BC3_UNORM = 77, + DXGI_FORMAT_BC3_UNORM_SRGB = 78, + DXGI_FORMAT_BC4_TYPELESS = 79, + DXGI_FORMAT_BC4_UNORM = 80, + DXGI_FORMAT_BC4_SNORM = 81, + DXGI_FORMAT_BC5_TYPELESS = 82, + DXGI_FORMAT_BC5_UNORM = 83, + DXGI_FORMAT_BC5_SNORM = 84, + DXGI_FORMAT_B5G6R5_UNORM = 85, + DXGI_FORMAT_B5G5R5A1_UNORM = 86, + DXGI_FORMAT_B8G8R8A8_UNORM = 87, + DXGI_FORMAT_B8G8R8X8_UNORM = 88, + DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, + DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, + DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, + DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, + DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, + DXGI_FORMAT_BC6H_TYPELESS = 94, + DXGI_FORMAT_BC6H_UF16 = 95, + DXGI_FORMAT_BC6H_SF16 = 96, + DXGI_FORMAT_BC7_TYPELESS = 97, + DXGI_FORMAT_BC7_UNORM = 98, + DXGI_FORMAT_BC7_UNORM_SRGB = 99, + DXGI_FORMAT_AYUV = 100, + DXGI_FORMAT_Y410 = 101, + DXGI_FORMAT_Y416 = 102, + DXGI_FORMAT_NV12 = 103, + DXGI_FORMAT_P010 = 104, + DXGI_FORMAT_P016 = 105, + DXGI_FORMAT_420_OPAQUE = 106, + DXGI_FORMAT_YUY2 = 107, + DXGI_FORMAT_Y210 = 108, + DXGI_FORMAT_Y216 = 109, + DXGI_FORMAT_NV11 = 110, + DXGI_FORMAT_AI44 = 111, + DXGI_FORMAT_IA44 = 112, + DXGI_FORMAT_P8 = 113, + DXGI_FORMAT_A8P8 = 114, + DXGI_FORMAT_B4G4R4A4_UNORM = 115, + DXGI_FORMAT_FORCE_UINT = 0xffffffff + } DXGI_FORMAT; +#endif + + /////////////////////////////////////////////////////////////////////////////////// + // D3DFMT Formats // + /////////////////////////////////////////////////////////////////////////////////// + enum D3DFMT + { + D3DFMT_UNKNOWN = 0, + + D3DFMT_R8G8B8 = 20, + D3DFMT_A8R8G8B8 = 21, + D3DFMT_X8R8G8B8 = 22, + D3DFMT_R5G6B5 = 23, + D3DFMT_X1R5G5B5 = 24, + D3DFMT_A1R5G5B5 = 25, + D3DFMT_A4R4G4B4 = 26, + D3DFMT_R3G3B2 = 27, + D3DFMT_A8 = 28, + D3DFMT_A8R3G3B2 = 29, + D3DFMT_X4R4G4B4 = 30, + D3DFMT_A2B10G10R10 = 31, + D3DFMT_A8B8G8R8 = 32, + D3DFMT_X8B8G8R8 = 33, + D3DFMT_G16R16 = 34, + D3DFMT_A2R10G10B10 = 35, + D3DFMT_A16B16G16R16 = 36, + + D3DFMT_A8P8 = 40, + D3DFMT_P8 = 41, + + D3DFMT_L8 = 50, + D3DFMT_A8L8 = 51, + D3DFMT_A4L4 = 52, + + D3DFMT_V8U8 = 60, + D3DFMT_L6V5U5 = 61, + D3DFMT_X8L8V8U8 = 62, + D3DFMT_Q8W8V8U8 = 63, + D3DFMT_V16U16 = 64, + D3DFMT_A2W10V10U10 = 67, + + D3DFMT_UYVY = MakeFourCC('U', 'Y', 'V', 'Y'), + D3DFMT_R8G8_B8G8 = MakeFourCC('R', 'G', 'B', 'G'), + D3DFMT_YUY2 = MakeFourCC('Y', 'U', 'Y', '2'), + D3DFMT_G8R8_G8B8 = MakeFourCC('G', 'R', 'G', 'B'), + D3DFMT_DXT1 = MakeFourCC('D', 'X', 'T', '1'), + D3DFMT_DXT2 = MakeFourCC('D', 'X', 'T', '2'), + D3DFMT_DXT3 = MakeFourCC('D', 'X', 'T', '3'), + D3DFMT_DXT4 = MakeFourCC('D', 'X', 'T', '4'), + D3DFMT_DXT5 = MakeFourCC('D', 'X', 'T', '5'), + + D3DFMT_ATI1 = MakeFourCC('A', 'T', 'I', '1'), + D3DFMT_AT1N = MakeFourCC('A', 'T', '1', 'N'), + D3DFMT_ATI2 = MakeFourCC('A', 'T', 'I', '2'), + D3DFMT_AT2N = MakeFourCC('A', 'T', '2', 'N'), + + D3DFMT_BC4U = MakeFourCC('B', 'C', '4', 'U'), + D3DFMT_BC4S = MakeFourCC('B', 'C', '4', 'S'), + D3DFMT_BC5U = MakeFourCC('B', 'C', '5', 'U'), + D3DFMT_BC5S = MakeFourCC('B', 'C', '5', 'S'), + + D3DFMT_ETC = MakeFourCC('E', 'T', 'C', ' '), + D3DFMT_ETC1 = MakeFourCC('E', 'T', 'C', '1'), + D3DFMT_ATC = MakeFourCC('A', 'T', 'C', ' '), + D3DFMT_ATCA = MakeFourCC('A', 'T', 'C', 'A'), + D3DFMT_ATCI = MakeFourCC('A', 'T', 'C', 'I'), + + D3DFMT_POWERVR_2BPP = MakeFourCC('P', 'T', 'C', '2'), + D3DFMT_POWERVR_4BPP = MakeFourCC('P', 'T', 'C', '4'), + + D3DFMT_D16_LOCKABLE = 70, + D3DFMT_D32 = 71, + D3DFMT_D15S1 = 73, + D3DFMT_D24S8 = 75, + D3DFMT_D24X8 = 77, + D3DFMT_D24X4S4 = 79, + D3DFMT_D16 = 80, + + D3DFMT_D32F_LOCKABLE = 82, + D3DFMT_D24FS8 = 83, + + D3DFMT_L16 = 81, + + D3DFMT_VERTEXDATA = 100, + D3DFMT_INDEX16 = 101, + D3DFMT_INDEX32 = 102, + + D3DFMT_Q16W16V16U16 = 110, + + D3DFMT_MULTI2_ARGB8 = MakeFourCC('M', 'E', 'T', '1'), + + D3DFMT_R16F = 111, + D3DFMT_G16R16F = 112, + D3DFMT_A16B16G16R16F = 113, + + D3DFMT_R32F = 114, + D3DFMT_G32R32F = 115, + D3DFMT_A32B32G32R32F = 116, + + D3DFMT_CxV8U8 = 117, + + D3DFMT_DX10 = MakeFourCC('D', 'X', '1', '0'), + + D3DFMT_FORCE_DWORD = 0x7fffffff + }; + + /////////////////////////////////////////////////////////////////////////////////// + // Defines // + /////////////////////////////////////////////////////////////////////////////////// + #pragma pack(push,1) + + #define DDS_HEADER_SIZE 124 + #define DDS_HEADER_DX10_SIZE 20 + #define DDS_MAGIC 0x20534444 // "DDS " + #define DDS_FOURCC 0x00000004 // DDPF_FOURCC + #define DDS_RGB 0x00000040 // DDPF_RGB + #define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS + #define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE + #define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS + #define DDS_ALPHAPIXELS 0x00000001 // DDPF_ALPHAPIXELS + #define DDS_ALPHA 0x00000002 // DDPF_ALPHA + #define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8 + #define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV + #define DDS_YUV 0x00000200 //DDPF_YUV + + #define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT + #define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT + #define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH + #define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH + #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE + + #define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT + #define DDS_WIDTH 0x00000004 // DDSD_WIDTH + + #define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE + #define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP + #define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX + + #define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP + #define DDS_CUBEMAP_POSITIVEX 0x00000400 // DDSCAPS2_CUBEMAP_POSITIVEX + #define DDS_CUBEMAP_NEGATIVEX 0x00000800 // DDSCAPS2_CUBEMAP_NEGATIVEX + #define DDS_CUBEMAP_POSITIVEY 0x00001000 // DDSCAPS2_CUBEMAP_POSITIVEY + #define DDS_CUBEMAP_NEGATIVEY 0x00002000 // DDSCAPS2_CUBEMAP_NEGATIVEY + #define DDS_CUBEMAP_POSITIVEZ 0x00004000 // DDSCAPS2_CUBEMAP_POSITIVEZ + #define DDS_CUBEMAP_NEGATIVEZ 0x00008000 // DDSCAPS2_CUBEMAP_NEGATIVEZ + + #define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP | DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\ + DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\ + DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ ) + + #define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME + + /////////////////////////////////////////////////////////////////////////////////// + // Enums // + /////////////////////////////////////////////////////////////////////////////////// + // Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION + enum DDS_RESOURCE_DIMENSION + { + DDS_DIMENSION_TEXTURE1D = 2, + DDS_DIMENSION_TEXTURE2D = 3, + DDS_DIMENSION_TEXTURE3D = 4, + }; + + // Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG + enum DDS_RESOURCE_MISC_FLAG + { + DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L, + }; + + enum DDS_MISC_FLAGS2 + { + DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L, + }; + + enum DDS_ALPHA_MODE + { + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_PREMULTIPLIED = 2, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, + }; + + enum D3D10_RESOURCE_DIMENSION + { + D3D10_RESOURCE_DIMENSION_UNKNOWN = 0, + D3D10_RESOURCE_DIMENSION_BUFFER = 1, + D3D10_RESOURCE_DIMENSION_TEXTURE1D = 2, + D3D10_RESOURCE_DIMENSION_TEXTURE2D = 3, + D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4 + }; + + enum D3D10_RESOURCE_MISC_FLAG + { + D3D10_RESOURCE_MISC_GENERATE_MIPS = 0x1L, + D3D10_RESOURCE_MISC_SHARED = 0x2L, + D3D10_RESOURCE_MISC_TEXTURECUBE = 0x4L, + D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX = 0x10L, + D3D10_RESOURCE_MISC_GDI_COMPATIBLE = 0x20L, + }; + + /////////////////////////////////////////////////////////////////////////////////// + // Structs // + /////////////////////////////////////////////////////////////////////////////////// + + struct DDS_PIXELFORMAT + { + U32 size; + U32 flags; + U32 fourCC; + U32 bpp; + U32 RBitMask; + U32 GBitMask; + U32 BBitMask; + U32 ABitMask; + + bool operator==(const DDS_PIXELFORMAT& _test) const + { + return ( size == _test.size && + flags == _test.flags && + fourCC == _test.fourCC && + bpp == _test.bpp && + RBitMask == _test.RBitMask && + GBitMask == _test.GBitMask && + BBitMask == _test.BBitMask && + ABitMask == _test.ABitMask); + } + }; + + struct DDS_HEADER + { + U32 size; + U32 flags; + U32 height; + U32 width; + U32 pitchOrLinearSize; + U32 depth; // only if DDS_HEADER_FLAGS_VOLUME is set in dwFlags + U32 mipMapCount; + U32 reserved1[11]; + DDS_PIXELFORMAT ddspf; + U32 surfaceFlags; + U32 cubemapFlags; + U32 reserved2[3]; + }; + + struct DDS_HEADER_DXT10 + { + DXGI_FORMAT dxgiFormat; + U32 resourceDimension; + U32 miscFlag; // see DDS_RESOURCE_MISC_FLAG + U32 arraySize; + U32 miscFlags2; // see DDS_MISC_FLAGS2 + }; + + /////////////////////////////////////////////////////////////////////////////////// + // Pixel Formats // + /////////////////////////////////////////////////////////////////////////////////// + + const DDS_PIXELFORMAT DDSPF_DXT1 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_DXT2 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_DXT2, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_DXT3 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_DXT3, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_DXT4 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_DXT5 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_DXT5, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_BC4_UNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_BC4U, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_BC4_SNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_BC4S, 0, 0, 0, 0, 0 }; + + //todo check diff between this and ('B','C','5','U') + const DDS_PIXELFORMAT DDSPF_ATI2 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_ATI2, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_ATI1 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_ATI1, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_BC5_UNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_BC5U, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_BC5_SNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_BC5S, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_R8G8_B8G8 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_G8R8_G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_YUY2 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }; + + const DDS_PIXELFORMAT DDSPF_A8R8G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }; + + const DDS_PIXELFORMAT DDSPF_X8R8G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }; + + const DDS_PIXELFORMAT DDSPF_A8B8G8R8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }; + + const DDS_PIXELFORMAT DDSPF_X8B8G8R8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }; + + const DDS_PIXELFORMAT DDSPF_G16R16 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }; + + const DDS_PIXELFORMAT DDSPF_R5G6B5 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 }; + + const DDS_PIXELFORMAT DDSPF_A1R5G5B5 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 }; + + const DDS_PIXELFORMAT DDSPF_A4R4G4B4 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 }; + + const DDS_PIXELFORMAT DDSPF_R8G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }; + + const DDS_PIXELFORMAT DDSPF_L8 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 }; + + const DDS_PIXELFORMAT DDSPF_L16 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 }; + + const DDS_PIXELFORMAT DDSPF_A8L8 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 }; + + const DDS_PIXELFORMAT DDSPF_A4L4 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x0000000f, 0x0000, 0x0000, 0x000000f0 }; + + const DDS_PIXELFORMAT DDSPF_A8 = + { sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff }; + + const DDS_PIXELFORMAT DDSPF_V8U8 = + { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 }; + + const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 = + { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }; + + const DDS_PIXELFORMAT DDSPF_V16U16 = + { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }; + + // D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue + + // This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat) + const DDS_PIXELFORMAT DDSPF_DX10 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, D3DFMT_DX10, 0, 0, 0, 0, 0 }; + + #pragma pack(pop) + + /////////////////////////////////////////////////////////////////////////////////// + // Functions // + /////////////////////////////////////////////////////////////////////////////////// + + //get DDS_PIXELFORMAT struct from GFXFormat - todo more formats + const DDS_PIXELFORMAT getDDSFormat(const GFXFormat format) + { + switch (format) + { + case GFXFormatA4L4: return DDSPF_A4L4; + case GFXFormatL8: return DDSPF_L8; + case GFXFormatA8: return DDSPF_A8; + case GFXFormatA8L8: return DDSPF_A8L8; + case GFXFormatL16: return DDSPF_L16; + case GFXFormatR5G6B5: return DDSPF_R5G6B5; + case GFXFormatR5G5B5A1: return DDSPF_A1R5G5B5; + case GFXFormatR8G8B8: return DDSPF_R8G8B8; + case GFXFormatR8G8B8A8: return DDSPF_A8R8G8B8; + case GFXFormatR8G8B8X8: return DDSPF_X8R8G8B8; + case GFXFormatB8G8R8A8: return DDSPF_A8B8G8R8; + case GFXFormatR16G16B16A16F: + case GFXFormatR32G32B32A32F: return DDSPF_DX10; + //compressed + case GFXFormatBC1: return DDSPF_DXT1; + case GFXFormatBC2: return DDSPF_DXT3; + case GFXFormatBC3: return DDSPF_DXT5; + case GFXFormatBC4: return DDSPF_ATI1; + case GFXFormatBC5: return DDSPF_ATI2; + default: + { + Con::errorf("dds::getDDSFormat: unknown format"); + return DDSPF_A8R8G8B8; + } + } + } + + //get DXGI_FORMAT from GFXFormat - todo more formats + const DXGI_FORMAT getDXGIFormat(const GFXFormat format) + { + switch (format) + { + //byte + case GFXFormatR5G6B5: return DXGI_FORMAT_B5G6R5_UNORM; + case GFXFormatR5G5B5A1: return DXGI_FORMAT_B5G5R5A1_UNORM; + case GFXFormatB8G8R8A8: return DXGI_FORMAT_R8G8B8A8_UNORM; + case GFXFormatR8G8B8A8: return DXGI_FORMAT_B8G8R8A8_UNORM; + case GFXFormatR8G8B8X8: return DXGI_FORMAT_B8G8R8X8_UNORM; + case GFXFormatR10G10B10A2: return DXGI_FORMAT_R10G10B10A2_UNORM; + //uint + case GFXFormatR16G16: return DXGI_FORMAT_R16G16_UINT; + case GFXFormatR16G16B16A16: return DXGI_FORMAT_R16G16B16A16_UINT; + //float + case GFXFormatR16F: return DXGI_FORMAT_R16_FLOAT; + case GFXFormatR32F: return DXGI_FORMAT_R32_FLOAT; + case GFXFormatR16G16B16A16F: return DXGI_FORMAT_R16G16B16A16_FLOAT; + case GFXFormatR32G32B32A32F: return DXGI_FORMAT_R32G32B32A32_FLOAT; + //compressed + case GFXFormatBC1: return DXGI_FORMAT_BC1_UNORM; + case GFXFormatBC2: return DXGI_FORMAT_BC2_UNORM; + case GFXFormatBC3: return DXGI_FORMAT_BC3_UNORM; + case GFXFormatBC4: return DXGI_FORMAT_BC4_UNORM; + case GFXFormatBC5: return DXGI_FORMAT_BC5_UNORM; + default: + { + Con::errorf("dds::getDXGIFormat: unknown format"); + return DXGI_FORMAT_UNKNOWN; + } + } + } + + //get GFXFormat from D3DFMT - todo more formats + const GFXFormat getGFXFormat(const D3DFMT format) + { + switch (format) + { + //byte + case D3DFMT_A4L4: return GFXFormatA4L4; + case D3DFMT_L8: return GFXFormatL8; + case D3DFMT_A8: return GFXFormatA8; + case D3DFMT_A8L8: return GFXFormatA8L8; + case D3DFMT_L16: return GFXFormatL16; + case D3DFMT_R5G6B5: return GFXFormatR5G6B5; + case D3DFMT_A1R5G5B5: return GFXFormatR5G5B5A1; + case D3DFMT_R8G8B8: return GFXFormatR8G8B8; + case D3DFMT_A8R8G8B8: return GFXFormatR8G8B8A8; + case D3DFMT_X8R8G8B8: return GFXFormatR8G8B8A8; + case D3DFMT_A8B8G8R8: return GFXFormatB8G8R8A8; + case D3DFMT_X8B8G8R8: return GFXFormatB8G8R8A8; + //uint + case D3DFMT_G16R16: return GFXFormatR16G16; + case D3DFMT_A16B16G16R16: return GFXFormatR16G16B16A16; + //float + case D3DFMT_R16F: return GFXFormatR16F; + case D3DFMT_R32F: return GFXFormatR32F; + case D3DFMT_A16B16G16R16F: return GFXFormatR16G16B16A16F; + case D3DFMT_A32B32G32R32F: return GFXFormatR32G32B32A32F; + //compressed + case D3DFMT_DXT1: return GFXFormatBC1; + case D3DFMT_DXT2: + case D3DFMT_DXT3: return GFXFormatBC2; + case D3DFMT_DXT4: + case D3DFMT_DXT5: return GFXFormatBC3; + case D3DFMT_ATI1: return GFXFormatBC4; + case D3DFMT_ATI2: return GFXFormatBC5; + default: + { + Con::errorf("dds::getGFXFormat: unknown format"); + return GFXFormat_FIRST; + } + } + } + + //get GFXFormat from DXGI_FORMAT - todo more formats + const GFXFormat getGFXFormat(const DXGI_FORMAT format) + { + switch (format) + { + //byte + case DXGI_FORMAT_B5G6R5_UNORM: return GFXFormatR5G6B5; + case DXGI_FORMAT_B5G5R5A1_UNORM: return GFXFormatR5G5B5A1; + case DXGI_FORMAT_R8G8B8A8_UNORM: return GFXFormatB8G8R8A8; + case DXGI_FORMAT_B8G8R8A8_UNORM: return GFXFormatR8G8B8A8; + case DXGI_FORMAT_B8G8R8X8_UNORM: return GFXFormatR8G8B8X8; + case DXGI_FORMAT_R10G10B10A2_UNORM: return GFXFormatR10G10B10A2; + //uint + case DXGI_FORMAT_R16G16_UINT: return GFXFormatR16G16; + case DXGI_FORMAT_R16G16B16A16_UINT: return GFXFormatR16G16B16A16; + //float + case DXGI_FORMAT_R16_FLOAT: return GFXFormatR16F; + case DXGI_FORMAT_R32_FLOAT: return GFXFormatR32F; + case DXGI_FORMAT_R16G16B16A16_FLOAT: return GFXFormatR16G16B16A16F; + case DXGI_FORMAT_R32G32B32A32_FLOAT: return GFXFormatR32G32B32A32F; + //compressed + case DXGI_FORMAT_BC1_UNORM: return GFXFormatBC1; + case DXGI_FORMAT_BC2_UNORM: return GFXFormatBC2; + case DXGI_FORMAT_BC3_UNORM: return GFXFormatBC3; + case DXGI_FORMAT_BC4_UNORM: return GFXFormatBC4; + case DXGI_FORMAT_BC5_UNORM: return GFXFormatBC5; + default: + { + Con::errorf("dds::getGFXFormatDxgi: unknown format"); + return GFXFormat_FIRST; + } + } + } + + //get GFXFormat from DDS_PIXELFORMAT struct - todo more formats + const GFXFormat getGFXFormat(const DDS_PIXELFORMAT &format) + { + if (format == DDSPF_DXT1) + return GFXFormatBC1; + else if (format == DDSPF_DXT2) + return GFXFormatBC2; + else if (format == DDSPF_DXT3) + return GFXFormatBC2; + else if (format == DDSPF_DXT4) + return GFXFormatBC3; + else if (format == DDSPF_DXT5) + return GFXFormatBC3; + else if (format == DDSPF_ATI1) + return GFXFormatBC4; + else if (format == DDSPF_ATI2) + return GFXFormatBC5; + else if (format == DDSPF_A8R8G8B8) + return GFXFormatR8G8B8A8; + else if (format == DDSPF_X8R8G8B8) + return GFXFormatR8G8B8A8; + else if (format == DDSPF_A8B8G8R8) + return GFXFormatB8G8R8A8; + else if (format == DDSPF_X8B8G8R8) + return GFXFormatB8G8R8A8; + else if (format == DDSPF_R8G8B8) + return GFXFormatR8G8B8; + else if (format == DDSPF_A8L8) + return GFXFormatA8L8; + else if (format == DDSPF_A4L4) + return GFXFormatA4L4; + else if (format == DDSPF_A8) + return GFXFormatA8; + else if (format == DDSPF_L8) + return GFXFormatL8; + else if (format == DDSPF_R5G6B5) + return GFXFormatR5G6B5; + else if (format == DDSPF_A1R5G5B5) + return GFXFormatR5G5B5A1; + else + { + Con::errorf("dds::getGFXFormat: unknown format"); + return GFXFormat_FIRST; + } + } + + //get GFXFormat from fourcc value - todo more formats + const GFXFormat getGFXFormat(const U32 fourcc) + { + switch (fourcc) + { + case D3DFMT_DXT1: return GFXFormatBC1; + case D3DFMT_DXT2: + case D3DFMT_DXT3: return GFXFormatBC2; + case D3DFMT_DXT4: + case D3DFMT_DXT5: return GFXFormatBC3; + case D3DFMT_ATI1: return GFXFormatBC4; + case D3DFMT_ATI2: return GFXFormatBC5; + case D3DFMT_A16B16G16R16F: return GFXFormatR16G16B16A16F; + case D3DFMT_A32B32G32R32F: return GFXFormatR32G32B32A32F; + default: + { + Con::errorf("dds::getGFXFormatFourcc: unknown format"); + return GFXFormat_FIRST; + } + } + } + + const bool validateHeader(const DDS_HEADER &header) + { + if (header.size != DDS_HEADER_SIZE) + { + Con::errorf("DDS_HEADER - incorrect header size. Expected 124 bytes."); + return false; + } + + if (!(header.flags & DDS_HEADER_FLAGS_TEXTURE)) + { + Con::errorf("DDS_HEADER - incorrect surface description flags."); + return false; + } + + if ((header.flags & (DDS_HEADER_FLAGS_LINEARSIZE | DDS_HEADER_FLAGS_PITCH)) == (DDS_HEADER_FLAGS_LINEARSIZE | DDS_HEADER_FLAGS_PITCH)) + { + // Both are invalid! + Con::errorf("DDS_HEADER - encountered both DDSD_LINEARSIZE and DDSD_PITCH!"); + return false; + } + + return true; + } + + const bool validateHeaderDx10(const DDS_HEADER_DXT10 &header) + { + if (sizeof(DDS_HEADER_DXT10) != DDS_HEADER_DX10_SIZE) + { + Con::errorf("DDS_HEADER_DXT10 - incorrect header size. Expected 20 bytes."); + return false; + } + + return true; + } + +} + +#endif \ No newline at end of file diff --git a/Engine/source/gfx/bitmap/ddsLoader.cpp b/Engine/source/gfx/bitmap/ddsFile.cpp similarity index 54% rename from Engine/source/gfx/bitmap/ddsLoader.cpp rename to Engine/source/gfx/bitmap/ddsFile.cpp index 6e32f0e6d..669f2445e 100644 --- a/Engine/source/gfx/bitmap/ddsLoader.cpp +++ b/Engine/source/gfx/bitmap/ddsFile.cpp @@ -22,7 +22,9 @@ #include "platform/platform.h" #include "gfx/bitmap/ddsFile.h" - +#include "gfx/bitmap/ddsData.h" +#include "gfx/bitmap/bitmapUtils.h" +#include "gfx/bitmap/imageUtils.h" #include "gfx/gfxDevice.h" #include "core/util/fourcc.h" #include "console/console.h" @@ -31,56 +33,11 @@ #include "gfx/bitmap/gBitmap.h" #include "console/engineAPI.h" - +#include S32 DDSFile::smActiveCopies = 0; U32 DDSFile::smDropMipCount = 0; -// These were copied from the DX9 docs. The names are changed -// from the "real" defines since not all platforms have them. -enum DDSSurfaceDescFlags -{ - DDSDCaps = 0x00000001l, - DDSDHeight = 0x00000002l, - DDSDWidth = 0x00000004l, - DDSDPitch = 0x00000008l, - DDSDPixelFormat = 0x00001000l, - DDSDMipMapCount = 0x00020000l, - DDSDLinearSize = 0x00080000l, - DDSDDepth = 0x00800000l, -}; - -enum DDSPixelFormatFlags -{ - DDPFAlphaPixels = 0x00000001, - DDPFFourCC = 0x00000004, - DDPFRGB = 0x00000040, - DDPFLUMINANCE = 0x00020000 -}; - - -enum DDSCapFlags -{ - DDSCAPSComplex = 0x00000008, - DDSCAPSTexture = 0x00001000, - DDSCAPSMipMap = 0x00400000, - - DDSCAPS2Cubemap = 0x00000200, - DDSCAPS2Cubemap_POSITIVEX = 0x00000400, - DDSCAPS2Cubemap_NEGATIVEX = 0x00000800, - DDSCAPS2Cubemap_POSITIVEY = 0x00001000, - DDSCAPS2Cubemap_NEGATIVEY = 0x00002000, - DDSCAPS2Cubemap_POSITIVEZ = 0x00004000, - DDSCAPS2Cubemap_NEGATIVEZ = 0x00008000, - DDSCAPS2Volume = 0x00200000, -}; - -#define FOURCC_DXT1 (MakeFourCC('D','X','T','1')) -#define FOURCC_DXT2 (MakeFourCC('D','X','T','2')) -#define FOURCC_DXT3 (MakeFourCC('D','X','T','3')) -#define FOURCC_DXT4 (MakeFourCC('D','X','T','4')) -#define FOURCC_DXT5 (MakeFourCC('D','X','T','5')) - DDSFile::DDSFile( const DDSFile &dds ) : mFlags( dds.mFlags ), mHeight( dds.mHeight ), @@ -133,13 +90,13 @@ U32 DDSFile::getSurfacePitch( U32 mipLevel ) const switch(mFormat) { - case GFXFormatDXT1: + case GFXFormatBC1: + case GFXFormatBC4: sizeMultiple = 8; break; - case GFXFormatDXT2: - case GFXFormatDXT3: - case GFXFormatDXT4: - case GFXFormatDXT5: + case GFXFormatBC2: + case GFXFormatBC3: + case GFXFormatBC5: sizeMultiple = 16; break; default: @@ -172,13 +129,13 @@ U32 DDSFile::getSurfaceSize( U32 height, U32 width, U32 mipLevel ) const switch(mFormat) { - case GFXFormatDXT1: + case GFXFormatBC1: + case GFXFormatBC4: sizeMultiple = 8; break; - case GFXFormatDXT2: - case GFXFormatDXT3: - case GFXFormatDXT4: - case GFXFormatDXT5: + case GFXFormatBC2: + case GFXFormatBC3: + case GFXFormatBC5: sizeMultiple = 16; break; default: @@ -197,25 +154,34 @@ U32 DDSFile::getSurfaceSize( U32 height, U32 width, U32 mipLevel ) const U32 DDSFile::getSizeInBytes() const { // TODO: This doesn't take mDepth into account, so - // it doesn't work right for volume or cubemap textures! + // it doesn't work right for volume textures! U32 bytes = 0; - for ( U32 i=0; i < mMipMapCount; i++ ) - bytes += getSurfaceSize( mHeight, mWidth, i ); + if (mFlags.test(CubeMapFlag)) + { + for(U32 cubeFace=0;cubeFace < Cubemap_Surface_Count;cubeFace++) + for (U32 i = 0; i < mMipMapCount; i++) + bytes += getSurfaceSize(mHeight, mWidth, i); + } + else + { + for (U32 i = 0; i < mMipMapCount; i++) + bytes += getSurfaceSize(mHeight, mWidth, i); + } return bytes; } U32 DDSFile::getSizeInBytes( GFXFormat format, U32 height, U32 width, U32 mipLevels ) { - AssertFatal( format >= GFXFormatDXT1 && format <= GFXFormatDXT5, - "DDSFile::getSizeInBytes - Must be a DXT format!" ); + AssertFatal( ImageUtil::isCompressedFormat(format), + "DDSFile::getSizeInBytes - Must be a Block Compression format!" ); // From the directX docs: // max(1, width ÷ 4) x max(1, height ÷ 4) x 8(DXT1) or 16(DXT2-5) U32 sizeMultiple = 0; - if ( format == GFXFormatDXT1 ) + if ( format == GFXFormatBC1 || format == GFXFormatBC1_SRGB || format == GFXFormatBC4) sizeMultiple = 8; else sizeMultiple = 16; @@ -236,317 +202,146 @@ U32 DDSFile::getSizeInBytes( GFXFormat format, U32 height, U32 width, U32 mipLev bool DDSFile::readHeader(Stream &s) { - U32 tmp; - + U32 fourcc; // Read the FOURCC - s.read(&tmp); + s.read(&fourcc); - if(tmp != MakeFourCC('D', 'D', 'S', ' ')) + if(fourcc != DDS_MAGIC) { Con::errorf("DDSFile::readHeader - unexpected magic number, wanted 'DDS '!"); return false; } - // Read the size of the header. - s.read(&tmp); + //dds headers + dds::DDS_HEADER header = {}; + dds::DDS_HEADER_DXT10 dx10header = {}; + //todo DX10 formats + bool hasDx10Header = false; - if(tmp != 124) + //read in header + s.read(DDS_HEADER_SIZE, &header); + //check for dx10 header support + if ((header.ddspf.flags & DDS_FOURCC) && (header.ddspf.fourCC == dds::D3DFMT_DX10)) { - Con::errorf("DDSFile::readHeader - incorrect header size. Expected 124 bytes."); + //read in dx10 header + s.read(DDS_HEADER_DX10_SIZE, &dx10header); + if (!dds::validateHeaderDx10(dx10header)) + return false; + + hasDx10Header = true; + } + + //make sure our dds header is valid + if (!dds::validateHeader(header)) return false; + + // store details + mPitchOrLinearSize = header.pitchOrLinearSize; + mMipMapCount = header.mipMapCount ? header.mipMapCount : 1; + mHeight = header.height; + mWidth = header.width; + mDepth = header.depth; + mFourCC = header.ddspf.fourCC; + + //process dx10 header + if (hasDx10Header) + { + if (dx10header.arraySize > 1) + { + Con::errorf("DDSFile::readHeader - DX10 arrays not supported"); + return false; + } + + mFormat = dds::getGFXFormat(dx10header.dxgiFormat); + //make sure getGFXFormat gave us a valid format + if (mFormat == GFXFormat_FIRST) + return false; + //cubemap + if (dx10header.miscFlag & dds::D3D10_RESOURCE_MISC_TEXTURECUBE) + { + mFlags.set(CubeMap_All_Flags | ComplexFlag); + } + + mHasTransparency = ImageUtil::isAlphaFormat(mFormat); + + //mip map flag + if (mMipMapCount > 1) + mFlags.set(MipMapsFlag | ComplexFlag); + + if (ImageUtil::isCompressedFormat(mFormat)) + mFlags.set(CompressedData); + else + { + mBytesPerPixel = header.ddspf.bpp / 8; + mFlags.set(RGBData); + } + + // we finished now + return true; } - // Read some flags... - U32 ddsdFlags; - s.read(&ddsdFlags); + //process regular header - // "Always include DDSD_CAPS, DDSD_PIXELFORMAT, DDSD_WIDTH, DDSD_HEIGHT." - if(!(ddsdFlags & (DDSDCaps | DDSDPixelFormat | DDSDWidth | DDSDHeight))) + //D3DFMT_DX10 is caught above, no need to check now + if (header.ddspf.flags & DDS_FOURCC) { - Con::errorf("DDSFile::readHeader - incorrect surface description flags."); - return false; - } + mFormat = dds::getGFXFormat(mFourCC); + //make sure getGFXFormat gave us a valid format + if (mFormat == GFXFormat_FIRST) + return false; - // Read height and width (always present) - s.read(&mHeight); - s.read(&mWidth); - - // Read pitch or linear size. - - // First make sure we have valid flags (either linear size or pitch). - if((ddsdFlags & (DDSDLinearSize | DDSDPitch)) == (DDSDLinearSize | DDSDPitch)) - { - // Both are invalid! - Con::errorf("DDSFile::readHeader - encountered both DDSD_LINEARSIZE and DDSD_PITCH!"); - return false; - } - - // Ok, some flags are set, so let's do some reading. - s.read(&mPitchOrLinearSize); - - if(ddsdFlags & DDSDLinearSize) - { - mFlags.set(LinearSizeFlag); // ( mHeight / 4 ) * ( mWidth / 4 ) * DDSSIZE - } - else if (ddsdFlags & DDSDPitch) - { - mFlags.set(PitchSizeFlag); // ( mWidth / 4 ) * DDSSIZE ??? + if (ImageUtil::isCompressedFormat(mFormat)) + mFlags.set(CompressedData); + else + { + mBytesPerPixel = header.ddspf.bpp / 8; + mFlags.set(RGBData); + } } else { - // Neither set! This appears to be depressingly common. - // Con::warnf("DDSFile::readHeader - encountered neither DDSD_LINEARSIZE nor DDSD_PITCH!"); - } + mFormat = dds::getGFXFormat(header.ddspf); + //make sure getGFXFormat gave us a valid format + if (mFormat == GFXFormat_FIRST) + return false; - // Do we need to read depth? If so, we are a volume texture! - s.read(&mDepth); - - if(ddsdFlags & DDSDDepth) - { - mFlags.set(VolumeFlag); - } - else - { - // Wipe it if the flag wasn't set! - mDepth = 0; - } - - // Deal with mips! - s.read(&mMipMapCount); - - if(ddsdFlags & DDSDMipMapCount) - { - mFlags.set(MipMapsFlag); - } - else - { - // Wipe it if the flag wasn't set! - mMipMapCount = 1; - } - - // Deal with 11 DWORDS of reserved space (this reserved space brought to - // you by DirectDraw and the letters F and U). - for(U32 i=0; i<11; i++) - s.read(&tmp); - - // Now we're onto the pixel format! - s.read(&tmp); - - if(tmp != 32) - { - Con::errorf("DDSFile::readHeader - pixel format chunk has unexpected size!"); - return false; - } - - U32 ddpfFlags; - - s.read(&ddpfFlags); - - // Read the next few values so we can deal with them all in one go. - U32 pfFourCC, pfBitCount, pfRMask, pfGMask, pfBMask, pfAlphaMask; - - s.read(&pfFourCC); - s.read(&pfBitCount); - s.read(&pfRMask); - s.read(&pfGMask); - s.read(&pfBMask); - s.read(&pfAlphaMask); - - // Sanity check flags... - if(!(ddpfFlags & (DDPFRGB | DDPFFourCC | DDPFLUMINANCE))) - { - Con::errorf("DDSFile::readHeader - incoherent pixel flags, neither RGB, FourCC, or Luminance!"); - return false; - } - - // For now let's just dump the header info. - if(ddpfFlags & DDPFLUMINANCE) - { + mBytesPerPixel = header.ddspf.bpp / 8; mFlags.set(RGBData); - - mBytesPerPixel = pfBitCount / 8; - - bool hasAlpha = ddpfFlags & DDPFAlphaPixels; - - mHasTransparency = hasAlpha; - - // Try to match a format. - if(hasAlpha) - { - // If it has alpha it is one of... - // GFXFormatA8L8 - // GFXFormatA4L4 - - if(pfBitCount == 16) - mFormat = GFXFormatA8L8; - else if(pfBitCount == 8) - mFormat = GFXFormatA4L4; - else - { - Con::errorf("DDSFile::readHeader - unable to match alpha Luminance format!"); - return false; - } - } - else - { - // Otherwise it is one of... - // GFXFormatL16 - // GFXFormatL8 - - if(pfBitCount == 16) - mFormat = GFXFormatL16; - else if(pfBitCount == 8) - mFormat = GFXFormatL8; - else - { - Con::errorf("DDSFile::readHeader - unable to match non-alpha Luminance format!"); - return false; - } - } - } - else if(ddpfFlags & DDPFRGB) - { - mFlags.set(RGBData); - - //Con::printf("RGB Pixel format of DDS:"); - //Con::printf(" bitcount = %d (16, 24, 32)", pfBitCount); - mBytesPerPixel = pfBitCount / 8; - //Con::printf(" red mask = %x", pfRMask); - //Con::printf(" green mask = %x", pfGMask); - //Con::printf(" blue mask = %x", pfBMask); - - bool hasAlpha = false; - - if(ddpfFlags & DDPFAlphaPixels) - { - hasAlpha = true; - //Con::printf(" alpha mask = %x", pfAlphaMask); - } - else - { - //Con::printf(" no alpha."); - } - - mHasTransparency = hasAlpha; - - // Try to match a format. - if(hasAlpha) - { - // If it has alpha it is one of... - // GFXFormatR8G8B8A8 - // GFXFormatR5G5B5A1 - // GFXFormatA8 - - if(pfBitCount == 32) - mFormat = GFXFormatR8G8B8A8; - else if(pfBitCount == 16) - mFormat = GFXFormatR5G5B5A1; - else if(pfBitCount == 8) - mFormat = GFXFormatA8; - else - { - Con::errorf("DDSFile::readHeader - unable to match alpha RGB format!"); - return false; - } - } - else - { - // Otherwise it is one of... - // GFXFormatR8G8B8 - // GFXFormatR8G8B8X8 - // GFXFormatR5G6B5 - // GFXFormatL8 - - if(pfBitCount == 24) - mFormat = GFXFormatR8G8B8; - else if(pfBitCount == 32) - mFormat = GFXFormatR8G8B8X8; - else if(pfBitCount == 16) - mFormat = GFXFormatR5G6B5; - else if(pfBitCount == 8) - { - // luminance - mFormat = GFXFormatL8; - } - else - { - Con::errorf("DDSFile::readHeader - unable to match non-alpha RGB format!"); - return false; - } - } - - - // Sweet, all done. - } - else if (ddpfFlags & DDPFFourCC) - { - mHasTransparency = (ddpfFlags & DDPFAlphaPixels); - mFlags.set(CompressedData); - -/* Con::printf("FourCC Pixel format of DDS:"); - Con::printf(" fourcc = '%c%c%c%c'", ((U8*)&pfFourCC)[0], ((U8*)&pfFourCC)[1], ((U8*)&pfFourCC)[2], ((U8*)&pfFourCC)[3]); */ - - // Ok, make a format determination. - switch(pfFourCC) - { - case FOURCC_DXT1: - mFormat = GFXFormatDXT1; - break; - case FOURCC_DXT2: - mFormat = GFXFormatDXT2; - break; - case FOURCC_DXT3: - mFormat = GFXFormatDXT3; - break; - case FOURCC_DXT4: - mFormat = GFXFormatDXT4; - break; - case FOURCC_DXT5: - mFormat = GFXFormatDXT5; - break; - default: - Con::errorf("DDSFile::readHeader - unknown fourcc = '%c%c%c%c'", ((U8*)&pfFourCC)[0], ((U8*)&pfFourCC)[1], ((U8*)&pfFourCC)[2], ((U8*)&pfFourCC)[3]); - break; - } - } - // Deal with final caps bits... Is this really necessary? + //mip map flag + if (mMipMapCount > 1) + mFlags.set(MipMapsFlag | ComplexFlag); - U32 caps1, caps2; - s.read(&caps1); - s.read(&caps2); - s.read(&tmp); - s.read(&tmp); // More icky reserved space. + //set transparency flag + mHasTransparency = (header.ddspf.flags & DDS_ALPHAPIXELS); - // Screw caps1. - // if(!(caps1 & DDSCAPS_TEXTURE))) - // { - // } + if (header.flags & DDS_HEADER_FLAGS_LINEARSIZE) + mFlags.set(LinearSizeFlag); + else if (header.flags & DDS_HEADER_FLAGS_PITCH) + mFlags.set(PitchSizeFlag); - // Caps2 has cubemap/volume info. Care about that. - if(caps2 & DDSCAPS2Cubemap) + //set cubemap flags + if (header.cubemapFlags & DDS_CUBEMAP) { - mFlags.set(CubeMapFlag); - + mFlags.set(CubeMapFlag | ComplexFlag); // Store the face flags too. - if ( caps2 & DDSCAPS2Cubemap_POSITIVEX ) mFlags.set( CubeMap_PosX_Flag ); - if ( caps2 & DDSCAPS2Cubemap_NEGATIVEX ) mFlags.set( CubeMap_NegX_Flag ); - if ( caps2 & DDSCAPS2Cubemap_POSITIVEY ) mFlags.set( CubeMap_PosY_Flag ); - if ( caps2 & DDSCAPS2Cubemap_NEGATIVEY ) mFlags.set( CubeMap_NegY_Flag ); - if ( caps2 & DDSCAPS2Cubemap_POSITIVEZ ) mFlags.set( CubeMap_PosZ_Flag ); - if ( caps2 & DDSCAPS2Cubemap_NEGATIVEZ ) mFlags.set( CubeMap_NegZ_Flag ); + if (header.cubemapFlags & DDS_CUBEMAP_POSITIVEX) mFlags.set(CubeMap_PosX_Flag); + if (header.cubemapFlags & DDS_CUBEMAP_NEGATIVEX) mFlags.set(CubeMap_NegX_Flag); + if (header.cubemapFlags & DDS_CUBEMAP_POSITIVEY) mFlags.set(CubeMap_PosY_Flag); + if (header.cubemapFlags & DDS_CUBEMAP_NEGATIVEY) mFlags.set(CubeMap_NegY_Flag); + if (header.cubemapFlags & DDS_CUBEMAP_POSITIVEZ) mFlags.set(CubeMap_PosZ_Flag); + if (header.cubemapFlags & DDS_CUBEMAP_NEGATIVEZ) mFlags.set(CubeMap_NegZ_Flag); } - // MS has ANOTHER reserved word here. This one particularly sucks. - s.read(&tmp); + return true; } bool DDSFile::read(Stream &s, U32 dropMipCount) { - if( !readHeader(s) || mMipMapCount == 0 ) + if( !readHeader(s) ) { Con::errorf("DDSFile::read - error reading header!"); return false; @@ -618,96 +413,82 @@ bool DDSFile::read(Stream &s, U32 dropMipCount) bool DDSFile::writeHeader( Stream &s ) { - // Read the FOURCC - s.write( 4, "DDS " ); + // write DDS magic + U32 magic = DDS_MAGIC; + s.write(magic); - U32 tmp = 0; + dds::DDS_HEADER header = {}; + dds::DDS_HEADER_DXT10 dx10header = {}; - // Read the size of the header. - s.write( 124 ); + bool hasDx10Header = false; + //flags + U32 surfaceFlags = DDS_SURFACE_FLAGS_TEXTURE; + U32 cubemapFlags = 0; + U32 headerFlags = DDS_HEADER_FLAGS_TEXTURE; - // Read some flags... - U32 ddsdFlags = DDSDCaps | DDSDPixelFormat | DDSDWidth | DDSDHeight; - - if ( mFlags.test( CompressedData ) ) - ddsdFlags |= DDSDLinearSize; - else - ddsdFlags |= DDSDPitch; + //pixel format + const dds::DDS_PIXELFORMAT &format = dds::getDDSFormat(mFormat); - if ( mMipMapCount > 0 ) - ddsdFlags |= DDSDMipMapCount; - - s.write( ddsdFlags ); - - // Read height and width (always present) - s.write( mHeight ); - s.write( mWidth ); - - // Ok, some flags are set, so let's do some reading. - s.write( mPitchOrLinearSize ); - - // Do we need to read depth? If so, we are a volume texture! - s.write( mDepth ); - - // Deal with mips! - s.write( mMipMapCount ); - - // Deal with 11 DWORDS of reserved space (this reserved space brought to - // you by DirectDraw and the letters F and U). - for(U32 i=0; i<11; i++) - s.write( tmp ); // is this right? - - // Now we're onto the pixel format! - - // This is the size, in bits, - // of the pixel format data. - tmp = 32; - s.write( tmp ); - - U32 ddpfFlags; - - U32 fourCC = 0; - - if ( mFlags.test( CompressedData ) ) + // todo better dx10 support + if (format.fourCC == dds::D3DFMT_DX10) { - ddpfFlags = DDPFFourCC; - if (mFormat == GFXFormatDXT1) - fourCC = FOURCC_DXT1; - if (mFormat == GFXFormatDXT3) - fourCC = FOURCC_DXT3; - if (mFormat == GFXFormatDXT5) - fourCC = FOURCC_DXT5; + dx10header.dxgiFormat = dds::getDXGIFormat(mFormat); + dx10header.arraySize = 1; + dx10header.resourceDimension = dds::D3D10_RESOURCE_DIMENSION_TEXTURE2D; + dx10header.miscFlag = 0; + dx10header.miscFlags2 = 0; + hasDx10Header = true; } + + if (mFlags.test(CompressedData)) + headerFlags |= DDS_HEADER_FLAGS_LINEARSIZE; else - ddpfFlags = mBytesPerPixel == 4 ? DDPFRGB | DDPFAlphaPixels : DDPFRGB; + headerFlags |= DDS_HEADER_FLAGS_PITCH; - s.write( ddpfFlags ); + if (mMipMapCount > 1) + { + surfaceFlags |= DDS_SURFACE_FLAGS_MIPMAP; + headerFlags |= DDS_HEADER_FLAGS_MIPMAP; + } - // Read the next few values so we can deal with them all in one go. - //U32 pfFourCC, pfBitCount, pfRMask, pfGMask, pfBMask, pfAlphaMask; + //cubemap flags + if (mFlags.test(CubeMapFlag)) + { + surfaceFlags |= DDS_SURFACE_FLAGS_CUBEMAP; + cubemapFlags |= DDS_CUBEMAP_ALLFACES; + } - s.write( fourCC ); - s.write( mBytesPerPixel * 8 ); - s.write( 0x000000FF ); - s.write( 0x00FF0000 ); - s.write( 0x0000FF00 ); - s.write( 0xFF000000 ); + //volume texture + if (mDepth > 0) + { + headerFlags |= DDS_HEADER_FLAGS_VOLUME; + dx10header.resourceDimension = dds::D3D10_RESOURCE_DIMENSION_TEXTURE3D; + } - // Deal with final caps bits... Is this really necessary? - - U32 caps1 = DDSCAPSTexture; - if ( mMipMapCount > 0 ) - caps1 |= DDSCAPSComplex | DDSCAPSMipMap; + //main dds header + header.size = sizeof(dds::DDS_HEADER); + header.flags = headerFlags; + header.height = mHeight; + header.width = mWidth; + header.pitchOrLinearSize = mPitchOrLinearSize; + header.depth = mDepth; + header.ddspf = format; + header.mipMapCount = mMipMapCount; + header.surfaceFlags = surfaceFlags; + header.cubemapFlags = cubemapFlags; + memset(header.reserved1, 0, sizeof(header.reserved1)); + memset(header.reserved2, 0, sizeof(header.reserved2)); - tmp = 0; + //check our header is ok + if (!dds::validateHeader(header)) + return false; - s.write( caps1 ); - s.write( tmp ); - s.write( tmp ); - s.write( tmp );// More icky reserved space. - - // MS has ANOTHER reserved word here. This one particularly sucks. - s.write( tmp ); + //Write out the header + s.write(DDS_HEADER_SIZE, &header); + + //Write out dx10 header + if (hasDx10Header) + s.write(DDS_HEADER_DX10_SIZE, &dx10header); return true; } @@ -720,13 +501,16 @@ bool DDSFile::write( Stream &s ) return false; } - // At this point we know what sort of image we contain. So we should - // allocate some buffers, and read it in. - // How many surfaces are we talking about? if(mFlags.test(CubeMapFlag)) { // Do something with cubemaps. + for (U32 cubeFace = 0; cubeFace < Cubemap_Surface_Count; cubeFace++) + { + // write the mips + for (S32 i = 0; i < mMipMapCount; i++) + mSurfaces[cubeFace]->writeNextMip(this, s, mHeight, mWidth, i); + } } else if (mFlags.test(VolumeFlag)) { @@ -912,6 +696,82 @@ DDSFile *DDSFile::createDDSFileFromGBitmap( const GBitmap *gbmp ) return ret; } +DDSFile *DDSFile::createDDSCubemapFileFromGBitmaps(GBitmap **gbmps) +{ + if (gbmps == NULL) + return NULL; + + AssertFatal(gbmps[0], "createDDSCubemapFileFromGBitmaps bitmap 0 is null"); + AssertFatal(gbmps[1], "createDDSCubemapFileFromGBitmaps bitmap 1 is null"); + AssertFatal(gbmps[2], "createDDSCubemapFileFromGBitmaps bitmap 2 is null"); + AssertFatal(gbmps[3], "createDDSCubemapFileFromGBitmaps bitmap 3 is null"); + AssertFatal(gbmps[4], "createDDSCubemapFileFromGBitmaps bitmap 4 is null"); + AssertFatal(gbmps[5], "createDDSCubemapFileFromGBitmaps bitmap 5 is null"); + + DDSFile *ret = new DDSFile; + //all cubemaps have the same dimensions and formats + GBitmap *pBitmap = gbmps[0]; + + if (pBitmap->getFormat() != GFXFormatR8G8B8A8) + { + Con::errorf("createDDSCubemapFileFromGBitmaps: Only GFXFormatR8G8B8A8 supported for now"); + return NULL; + } + + // Set up the DDSFile properties that matter. Since this is a GBitmap, there + // are assumptions that can be made + ret->mHeight = pBitmap->getHeight(); + ret->mWidth = pBitmap->getWidth(); + ret->mDepth = 0; + ret->mFormat = pBitmap->getFormat(); + ret->mFlags.set( RGBData | CubeMapFlag | CubeMap_PosX_Flag | CubeMap_NegX_Flag | CubeMap_PosY_Flag | + CubeMap_NegY_Flag | CubeMap_PosZ_Flag | CubeMap_NegZ_Flag); + ret->mBytesPerPixel = pBitmap->getBytesPerPixel(); + //todo implement mip mapping + ret->mMipMapCount = pBitmap->getNumMipLevels(); + ret->mHasTransparency = pBitmap->getHasTransparency(); + + for (U32 cubeFace = 0; cubeFace < Cubemap_Surface_Count; cubeFace++) + { + ret->mSurfaces.push_back(new SurfaceData()); + // Load the mips + for (S32 i = 0; i < ret->mMipMapCount; i++) + { + const U32 mipSz = ret->getSurfaceSize(i); + ret->mSurfaces.last()->mMips.push_back(new U8[mipSz]); + + U8 *mipMem = ret->mSurfaces.last()->mMips.last(); + //straight copy + dMemcpy(mipMem, gbmps[cubeFace]->getBits(i), mipSz); + } + } + + return ret; +} + +bool DDSFile::decompressToGBitmap(GBitmap *dest) +{ + // TBD: do we support other formats? + if (mFormat != GFXFormatBC1 && mFormat != GFXFormatBC2 && mFormat != GFXFormatBC3) + return false; + + dest->allocateBitmapWithMips(getWidth(), getHeight(), getMipLevels(), GFXFormatR8G8B8A8); + + // Decompress and copy mips... + + U32 numMips = getMipLevels(); + + for (U32 i = 0; i < numMips; i++) + { + U8 *addr = dest->getAddress(0, 0, i); + const U8 *mipBuffer = mSurfaces[0]->mMips[i]; + ImageUtil::decompress(mipBuffer, addr, getWidth(i), getHeight(i), mFormat); + + } + + return true; +} + DefineEngineFunction( getActiveDDSFiles, S32, (),, "Returns the count of active DDSs files in memory.\n" "@ingroup Rendering\n" ) diff --git a/Engine/source/gfx/bitmap/ddsFile.h b/Engine/source/gfx/bitmap/ddsFile.h index 3a530e610..8e726c54a 100644 --- a/Engine/source/gfx/bitmap/ddsFile.h +++ b/Engine/source/gfx/bitmap/ddsFile.h @@ -65,6 +65,7 @@ struct DDSFile CubeMap_NegY_Flag = BIT(11), CubeMap_PosZ_Flag = BIT(12), CubeMap_NegZ_Flag = BIT(13), + CubeMap_All_Flags = CubeMapFlag|CubeMap_PosX_Flag | CubeMap_NegX_Flag | CubeMap_PosY_Flag | CubeMap_NegY_Flag | CubeMap_PosZ_Flag | CubeMap_NegZ_Flag, }; /// The index into mSurfaces for each @@ -115,9 +116,6 @@ struct DDSFile Vector mMips; - // Helper function to read in a mipchain. - bool readMipChain(); - void dumpImage(DDSFile *dds, U32 mip, const char *file); /// Helper for reading a mip level. @@ -200,6 +198,9 @@ struct DDSFile } static DDSFile *createDDSFileFromGBitmap( const GBitmap *gbmp ); + //Create a single cubemap texture from 6 GBitmap + static DDSFile *createDDSCubemapFileFromGBitmaps(GBitmap **gbmps); + bool decompressToGBitmap(GBitmap *dest); }; #endif // _DDSFILE_H_ \ No newline at end of file diff --git a/Engine/source/gfx/bitmap/ddsUtils.cpp b/Engine/source/gfx/bitmap/ddsUtils.cpp deleted file mode 100644 index b5e5fa4a8..000000000 --- a/Engine/source/gfx/bitmap/ddsUtils.cpp +++ /dev/null @@ -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. -//----------------------------------------------------------------------------- - -#include "squish/squish.h" -#include "gfx/bitmap/ddsFile.h" -#include "gfx/bitmap/ddsUtils.h" - -//------------------------------------------------------------------------------ - -// If false is returned, from this method, the source DDS is not modified -bool DDSUtil::squishDDS( DDSFile *srcDDS, const GFXFormat dxtFormat ) -{ - // Sanity check - if( srcDDS->mBytesPerPixel != 4 ) - { - AssertFatal( false, "Squish wants 32-bit source data" ); - return false; - } - - // Build flags, start with fast compress - U32 squishFlags = squish::kColourRangeFit; - - // Flag which format we are using - switch( dxtFormat ) - { - case GFXFormatDXT1: - squishFlags |= squish::kDxt1; - break; - - case GFXFormatDXT2: - case GFXFormatDXT3: - squishFlags |= squish::kDxt3; - break; - - case GFXFormatDXT4: - case GFXFormatDXT5: - squishFlags |= squish::kDxt5; - break; - - default: - AssertFatal( false, "Assumption failed" ); - return false; - break; - } - - // We got this far, so assume we can finish (gosh I hope so) - srcDDS->mFormat = dxtFormat; - srcDDS->mFlags.set( DDSFile::CompressedData ); - - // If this has alpha, set the flag - if( srcDDS->mFormat == GFXFormatR8G8B8A8 ) - squishFlags |= squish::kWeightColourByAlpha; - - // The source surface is the original surface of the file - DDSFile::SurfaceData *srcSurface = srcDDS->mSurfaces.last(); - - // Create a new surface, this will be the DXT compressed surface. Once we - // are done, we can discard the old surface, and replace it with this one. - DDSFile::SurfaceData *newSurface = new DDSFile::SurfaceData(); - - for( S32 i = 0; i < srcDDS->mMipMapCount; i++ ) - { - const U8 *srcBits = srcSurface->mMips[i]; - - const U32 mipSz = srcDDS->getSurfaceSize(i); - U8 *dstBits = new U8[mipSz]; - newSurface->mMips.push_back( dstBits ); - - PROFILE_START(SQUISH_DXT_COMPRESS); - - // Compress with Squish - squish::CompressImage( srcBits, srcDDS->getWidth(i), srcDDS->getHeight(i), - dstBits, squishFlags ); - - PROFILE_END(); - } - - // Now delete the source surface, and return. - srcDDS->mSurfaces.pop_back(); - delete srcSurface; - srcDDS->mSurfaces.push_back( newSurface ); - - return true; -} - -//------------------------------------------------------------------------------ - -void DDSUtil::swizzleDDS( DDSFile *srcDDS, const Swizzle &swizzle ) -{ - for( S32 i = 0; i < srcDDS->mMipMapCount; i++ ) - { - swizzle.InPlace( srcDDS->mSurfaces.last()->mMips[i], srcDDS->getSurfaceSize( i ) ); - } -} \ No newline at end of file diff --git a/Engine/source/gfx/bitmap/gBitmap.cpp b/Engine/source/gfx/bitmap/gBitmap.cpp index 54d267aa8..fadf0a6c5 100644 --- a/Engine/source/gfx/bitmap/gBitmap.cpp +++ b/Engine/source/gfx/bitmap/gBitmap.cpp @@ -347,6 +347,77 @@ void GBitmap::allocateBitmap(const U32 in_width, const U32 in_height, const bool } } +//-------------------------------------------------------------------------- +void GBitmap::allocateBitmapWithMips(const U32 in_width, const U32 in_height, const U32 in_numMips, const GFXFormat in_format) +{ + //-------------------------------------- Some debug checks... + U32 svByteSize = mByteSize; + U8 *svBits = mBits; + + AssertFatal(in_width != 0 && in_height != 0, "GBitmap::allocateBitmap: width or height is 0"); + + mInternalFormat = in_format; + mWidth = in_width; + mHeight = in_height; + + mBytesPerPixel = 1; + switch (mInternalFormat) + { + case GFXFormatA8: + case GFXFormatL8: mBytesPerPixel = 1; + break; + case GFXFormatR8G8B8: mBytesPerPixel = 3; + break; + case GFXFormatR8G8B8X8: + case GFXFormatR8G8B8A8: mBytesPerPixel = 4; + break; + case GFXFormatR5G6B5: + case GFXFormatR5G5B5A1: mBytesPerPixel = 2; + break; + default: + AssertFatal(false, "GBitmap::GBitmap: misunderstood format specifier"); + break; + } + + // Set up the mip levels, if necessary... + mNumMipLevels = 1; + U32 allocPixels = in_width * in_height * mBytesPerPixel; + mMipLevelOffsets[0] = 0; + + + if (in_numMips != 0) + { + U32 currWidth = in_width; + U32 currHeight = in_height; + + do + { + mMipLevelOffsets[mNumMipLevels] = mMipLevelOffsets[mNumMipLevels - 1] + + (currWidth * currHeight * mBytesPerPixel); + currWidth >>= 1; + currHeight >>= 1; + if (currWidth == 0) currWidth = 1; + if (currHeight == 0) currHeight = 1; + + mNumMipLevels++; + allocPixels += currWidth * currHeight * mBytesPerPixel; + } while (currWidth != 1 || currHeight != 1 && mNumMipLevels != in_numMips); + } + AssertFatal(mNumMipLevels <= c_maxMipLevels, "GBitmap::allocateBitmap: too many miplevels"); + + // Set up the memory... + mByteSize = allocPixels; + mBits = new U8[mByteSize]; + + dMemset(mBits, 0xFF, mByteSize); + + if (svBits != NULL) + { + dMemcpy(mBits, svBits, getMin(mByteSize, svByteSize)); + delete[] svBits; + } +} + //-------------------------------------------------------------------------- void GBitmap::extrudeMipLevels(bool clearBorders) { @@ -410,6 +481,38 @@ void GBitmap::extrudeMipLevels(bool clearBorders) } } +//-------------------------------------------------------------------------- +void GBitmap::chopTopMips(U32 mipsToChop) +{ + U32 scalePower = getMin(mipsToChop, getNumMipLevels() - 1); + U32 newMipCount = getNumMipLevels() - scalePower; + + U32 realWidth = getMax((U32)1, getWidth() >> scalePower); + U32 realHeight = getMax((U32)1, getHeight() >> scalePower); + + U8 *destBits = mBits; + + U32 destOffsets[c_maxMipLevels]; + + for (U32 i = scalePower; i GBitmap::_search(const Torque::Path &path) return Resource< GBitmap >( NULL ); } +U32 GBitmap::getSurfaceSize(const U32 mipLevel) const +{ + // Bump by the mip level. + U32 height = getMax(U32(1), mHeight >> mipLevel); + U32 width = getMax(U32(1), mWidth >> mipLevel); + + if (mInternalFormat >= GFXFormatBC1 && mInternalFormat <= GFXFormatBC3) + { + // From the directX docs: + // max(1, width ÷ 4) x max(1, height ÷ 4) x 8(DXT1) or 16(DXT2-5) + + U32 sizeMultiple = 0; + + switch (mInternalFormat) + { + case GFXFormatBC1: + sizeMultiple = 8; + break; + case GFXFormatBC2: + case GFXFormatBC3: + sizeMultiple = 16; + break; + default: + AssertISV(false, "DDSFile::getSurfaceSize - invalid compressed texture format, we only support DXT1-5 right now."); + break; + } + + return getMax(U32(1), width / 4) * getMax(U32(1), height / 4) * sizeMultiple; + } + else + { + return height * width* mBytesPerPixel; + } +} + DefineEngineFunction( getBitmapInfo, String, ( const char *filename ),, "Returns image info in the following format: width TAB height TAB bytesPerPixel. " "It will return an empty string if the file is not found.\n" diff --git a/Engine/source/gfx/bitmap/gBitmap.h b/Engine/source/gfx/bitmap/gBitmap.h index 5c4b201ff..7ff215a81 100644 --- a/Engine/source/gfx/bitmap/gBitmap.h +++ b/Engine/source/gfx/bitmap/gBitmap.h @@ -47,7 +47,7 @@ class Stream; class RectI; class Point2I; class ColorI; -class ColorF; +class LinearColorF; //------------------------------------------------------------------------------ //-------------------------------------- GBitmap @@ -151,7 +151,13 @@ public: const bool in_extrudeMipLevels = false, const GFXFormat in_format = GFXFormatR8G8B8 ); + void allocateBitmapWithMips(const U32 in_width, + const U32 in_height, + const U32 in_numMips, + const GFXFormat in_format = GFXFormatR8G8B8); + void extrudeMipLevels(bool clearBorders = false); + void chopTopMips(U32 mipsToChop); void extrudeMipLevelsDetail(); U32 getNumMipLevels() const { return mNumMipLevels; } @@ -182,6 +188,8 @@ public: U32 getByteSize() const { return mByteSize; } U32 getBytesPerPixel() const { return mBytesPerPixel; } + U32 getSurfaceSize(const U32 mipLevel) const; + /// Use these functions to set and get the mHasTransparency value /// This is used to indicate that this bitmap has pixels that have /// an alpha value less than 255 (used by the auto-Material mapper) @@ -194,9 +202,10 @@ public: /// the bitmap bits and to check for alpha values less than 255 bool checkForTransparency(); - ColorF sampleTexel(F32 u, F32 v) const; + LinearColorF sampleTexel(F32 u, F32 v) const; bool getColor(const U32 x, const U32 y, ColorI& rColor) const; bool setColor(const U32 x, const U32 y, const ColorI& rColor); + U8 getChanelValueAt(U32 x, U32 y, U32 chan); /// This method will combine bitmapA and bitmapB using the operation specified /// by combineOp. The result will be stored in the bitmap that this method is diff --git a/Engine/source/gfx/bitmap/imageUtils.cpp b/Engine/source/gfx/bitmap/imageUtils.cpp new file mode 100644 index 000000000..0d550f704 --- /dev/null +++ b/Engine/source/gfx/bitmap/imageUtils.cpp @@ -0,0 +1,304 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#include "platform/platform.h" +#include "gfx/bitmap/imageUtils.h" +#include "gfx/bitmap/ddsFile.h" +#include "platform/threads/threadPool.h" +#include "squish/squish.h" + +namespace ImageUtil +{ + // get squish quality flag + S32 _getSquishQuality(const CompressQuality quality) + { + switch (quality) + { + case LowQuality: + return squish::kColourRangeFit; + case MediumQuality: + return squish::kColourClusterFit; + case HighQuality: + return squish::kColourIterativeClusterFit; + default: + return squish::kColourRangeFit;//default is low quality + } + } + + // get squish compression flag + S32 _getSquishFormat(const GFXFormat compressFormat) + { + switch (compressFormat) + { + case GFXFormatBC1: + return squish::kDxt1; + case GFXFormatBC2: + return squish::kDxt3; + case GFXFormatBC3: + return squish::kDxt5; + case GFXFormatBC4: + return squish::kBc4; + case GFXFormatBC5: + return squish::kBc5; + default: + return squish::kDxt1; + } + } + + //Thread work job for compression + struct CompressJob : public ThreadPool::WorkItem + { + S32 width; + S32 height; + S32 flags; + const U8 *pSrc; + U8 *pDst; + GFXFormat format; + CompressQuality quality; + + CompressJob(const U8 *srcRGBA, U8 *dst, const S32 w, const S32 h, const GFXFormat compressFormat, const CompressQuality compressQuality) + : pSrc(srcRGBA),pDst(dst), width(w), height(h), format(compressFormat),quality(compressQuality) {} + + protected: + virtual void execute() + { + rawCompress(pSrc,pDst, width, height, format,quality); + } + }; + + + // compress raw pixel data, expects rgba format + bool rawCompress(const U8 *srcRGBA, U8 *dst, const S32 width, const S32 height, const GFXFormat compressFormat, const CompressQuality compressQuality) + { + if (!isCompressedFormat(compressFormat)) + return false; + + S32 squishFlags = _getSquishQuality(compressQuality); + S32 squishFormat = _getSquishFormat(compressFormat); + + squishFlags |= squishFormat; + + squish::CompressImage(srcRGBA, width,height,dst,squishFlags); + + return true; + } + + // compress DDSFile + bool ddsCompress(DDSFile *srcDDS, const GFXFormat compressFormat,const CompressQuality compressQuality) + { + if (srcDDS->mBytesPerPixel != 4) + { + Con::errorf("ImageCompress::ddsCompress: data must be 32bit"); + return false; + } + + //can't compress DDSFile if it is already compressed + if (ImageUtil::isCompressedFormat(srcDDS->mFormat)) + { + Con::errorf("ImageCompress::ddsCompress: file is already compressed"); + return false; + } + + const bool cubemap = srcDDS->mFlags.test(DDSFile::CubeMapFlag); + const U32 mipCount = srcDDS->mMipMapCount; + // We got this far, so assume we can finish (gosh I hope so) + srcDDS->mFormat = compressFormat; + srcDDS->mFlags.set(DDSFile::CompressedData); + + //grab global thread pool + ThreadPool* pThreadPool = &ThreadPool::GLOBAL(); + + if (cubemap) + { + static U32 nCubeFaces = 6; + Vector dstDataStore; + dstDataStore.setSize(nCubeFaces * mipCount); + + for (S32 cubeFace = 0; cubeFace < nCubeFaces; cubeFace++) + { + DDSFile::SurfaceData *srcSurface = srcDDS->mSurfaces[cubeFace]; + for (U32 currentMip = 0; currentMip < mipCount; currentMip++) + { + const U32 dataIndex = cubeFace * mipCount + currentMip; + const U8 *srcBits = srcSurface->mMips[currentMip]; + const U32 mipSz = srcDDS->getSurfaceSize(currentMip); + U8 *dstBits = new U8[mipSz]; + dstDataStore[dataIndex] = dstBits; + + ThreadSafeRef item(new CompressJob(srcBits, dstBits, srcDDS->getWidth(currentMip), srcDDS->getHeight(currentMip), compressFormat, compressQuality)); + pThreadPool->queueWorkItem(item); + + } + } + + //wait for work items to finish + pThreadPool->waitForAllItems(); + + for (S32 cubeFace = 0; cubeFace < nCubeFaces; cubeFace++) + { + DDSFile::SurfaceData *pSrcSurface = srcDDS->mSurfaces[cubeFace]; + for (U32 currentMip = 0; currentMip < mipCount; currentMip++) + { + const U32 dataIndex = cubeFace * mipCount + currentMip; + delete[] pSrcSurface->mMips[currentMip]; + pSrcSurface->mMips[currentMip] = dstDataStore[dataIndex]; + } + } + } + else + { + // The source surface is the original surface of the file + DDSFile::SurfaceData *pSrcSurface = srcDDS->mSurfaces.last(); + + // Create a new surface, this will be the DXT compressed surface. Once we + // are done, we can discard the old surface, and replace it with this one. + DDSFile::SurfaceData *pNewSurface = new DDSFile::SurfaceData(); + //no point using threading if only 1 mip + const bool useThreading = bool(mipCount > 1); + for (U32 currentMip = 0; currentMip < mipCount; currentMip++) + { + const U8 *pSrcBits = pSrcSurface->mMips[currentMip]; + + const U32 mipSz = srcDDS->getSurfaceSize(currentMip); + U8 *pDstBits = new U8[mipSz]; + pNewSurface->mMips.push_back(pDstBits); + + if (useThreading) + { + // Create CompressJob item + ThreadSafeRef item(new CompressJob(pSrcBits, pDstBits, srcDDS->getWidth(currentMip), srcDDS->getHeight(currentMip), compressFormat, compressQuality)); + pThreadPool->queueWorkItem(item); + } + else + rawCompress(pSrcBits, pDstBits, srcDDS->getWidth(currentMip), srcDDS->getHeight(currentMip), compressFormat, compressQuality); + + } + //block and wait for CompressJobs to finish + if(useThreading) + pThreadPool->waitForAllItems(); + + // Now delete the source surface and replace with new compressed surface + srcDDS->mSurfaces.pop_back(); + delete pSrcSurface; + srcDDS->mSurfaces.push_back(pNewSurface); + } + + return true; + } + + bool decompress(const U8 *src, U8 *dstRGBA,const S32 width,const S32 height, const GFXFormat srcFormat) + { + if (!isCompressedFormat(srcFormat)) + return false; + + S32 squishFlag = _getSquishFormat(srcFormat); + squish::DecompressImage(dstRGBA, width, height, src, squishFlag); + + return true; + } + + void swizzleDDS(DDSFile *srcDDS, const Swizzle &swizzle) + { + if (srcDDS->mFlags.test(DDSFile::CubeMapFlag)) + { + for (S32 cubeFace = 0; cubeFace < DDSFile::Cubemap_Surface_Count; cubeFace++) + { + for (S32 i = 0; i < srcDDS->mMipMapCount; i++) + { + swizzle.InPlace(srcDDS->mSurfaces[cubeFace]->mMips[i], srcDDS->getSurfaceSize(i)); + } + } + } + else + { + for (S32 i = 0; i < srcDDS->mMipMapCount; i++) + { + swizzle.InPlace(srcDDS->mSurfaces.last()->mMips[i], srcDDS->getSurfaceSize(i)); + } + } + } + + bool isCompressedFormat(const GFXFormat format) + { + if (format >= GFXFormatBC1 && format <= GFXFormatBC3_SRGB) + return true; + else + return false; + } + + bool isAlphaFormat(const GFXFormat format) + { + switch (format) + { + case GFXFormatA8: + case GFXFormatA4L4: + case GFXFormatA8L8: + case GFXFormatR5G5B5A1: + case GFXFormatR8G8B8A8: + case GFXFormatB8G8R8A8: + case GFXFormatR16G16B16A16F: + case GFXFormatR32G32B32A32F: + case GFXFormatR10G10B10A2: + //case GFXFormatBC1://todo BC1 can store alpha + case GFXFormatBC2: + case GFXFormatBC3: + return true; + default: + return false; + } + } + + bool isSRGBFormat(const GFXFormat format) + { + switch (format) + { + case GFXFormatR8G8B8_SRGB: + case GFXFormatR8G8B8A8_SRGB: + case GFXFormatBC1_SRGB: + case GFXFormatBC2_SRGB: + case GFXFormatBC3_SRGB: + return true; + default: + return false; + }; + } + + GFXFormat toSRGBFormat(const GFXFormat format) + { + switch (format) + { + case GFXFormatR8G8B8: + return GFXFormatR8G8B8_SRGB; + case GFXFormatR8G8B8X8: + case GFXFormatR8G8B8A8: + return GFXFormatR8G8B8A8_SRGB; + case GFXFormatBC1: + return GFXFormatBC1_SRGB; + case GFXFormatBC2: + return GFXFormatBC2_SRGB; + case GFXFormatBC3: + return GFXFormatBC3_SRGB; + default: + return format; + }; + } +} \ No newline at end of file diff --git a/Engine/source/gfx/bitmap/ddsUtils.h b/Engine/source/gfx/bitmap/imageUtils.h similarity index 50% rename from Engine/source/gfx/bitmap/ddsUtils.h rename to Engine/source/gfx/bitmap/imageUtils.h index 0db66c8a4..2cbb278e6 100644 --- a/Engine/source/gfx/bitmap/ddsUtils.h +++ b/Engine/source/gfx/bitmap/imageUtils.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC +// 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 @@ -20,15 +20,43 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#ifndef _DDS_UTILS_H_ -#define _DDS_UTILS_H_ +#ifndef _IMAGE_UTILS_H_ +#define _IMAGE_UTILS_H_ + +#ifndef _SWIZZLE_H_ +#include "core/util/swizzle.h" +#endif +#ifndef _GFXENUMS_H_ +#include "gfx/gfxEnums.h" +#endif struct DDSFile; -namespace DDSUtil +namespace ImageUtil { - bool squishDDS( DDSFile *srcDDS, const GFXFormat dxtFormat ); - void swizzleDDS( DDSFile *srcDDS, const Swizzle &swizzle ); + enum CompressQuality + { + LowQuality, + MediumQuality, + HighQuality + }; + + // compress raw pixel data, expects rgba format + bool rawCompress(const U8 *srcRGBA, U8 *dst, const S32 width, const S32 height, const GFXFormat compressFormat, const CompressQuality compressQuality = LowQuality); + // compress DDSFile + bool ddsCompress(DDSFile *srcDDS, const GFXFormat compressFormat, const CompressQuality compressQuality = LowQuality); + // decompress compressed pixel data, dest data should be rgba format + bool decompress(const U8 *src, U8 *dstRGBA, const S32 width, const S32 height, const GFXFormat srcFormat); + //swizzle dds file + void swizzleDDS(DDSFile *srcDDS, const Swizzle &swizzle); + //check if a GFXFormat is compressed + bool isCompressedFormat(const GFXFormat format); + bool isSRGBFormat(const GFXFormat format); + //check if a GFXFormat has an alpha channel + bool isAlphaFormat(const GFXFormat format); + + //convert to sRGB format + GFXFormat toSRGBFormat(const GFXFormat format); }; #endif \ No newline at end of file diff --git a/Engine/source/gfx/genericConstBuffer.h b/Engine/source/gfx/genericConstBuffer.h index 1c3824bf8..afa097be7 100644 --- a/Engine/source/gfx/genericConstBuffer.h +++ b/Engine/source/gfx/genericConstBuffer.h @@ -172,7 +172,7 @@ public: inline void set(const GenericConstBufferLayout::ParamDesc& pd, const Point3F& fv) { internalSet(pd, GFXSCT_Float3, sizeof(Point3F), &fv); } inline void set(const GenericConstBufferLayout::ParamDesc& pd, const Point4F& fv) { internalSet(pd, GFXSCT_Float4, sizeof(Point4F), &fv); } inline void set(const GenericConstBufferLayout::ParamDesc& pd, const PlaneF& fv) { internalSet(pd, GFXSCT_Float4, sizeof(PlaneF), &fv); } - inline void set(const GenericConstBufferLayout::ParamDesc& pd, const ColorF& fv) { internalSet(pd, GFXSCT_Float4, sizeof(Point4F), &fv); } + inline void set(const GenericConstBufferLayout::ParamDesc& pd, const LinearColorF& fv) { internalSet(pd, GFXSCT_Float4, sizeof(Point4F), &fv); } inline void set(const GenericConstBufferLayout::ParamDesc& pd, const S32 f) { internalSet(pd, GFXSCT_Int, sizeof(S32), &f); } inline void set(const GenericConstBufferLayout::ParamDesc& pd, const Point2I& fv) { internalSet(pd, GFXSCT_Int2, sizeof(Point2I), &fv); } inline void set(const GenericConstBufferLayout::ParamDesc& pd, const Point3I& fv) { internalSet(pd, GFXSCT_Int3, sizeof(Point3I), &fv); } diff --git a/Engine/source/gfx/gfxAPI.cpp b/Engine/source/gfx/gfxAPI.cpp index f2e480706..d4e614276 100644 --- a/Engine/source/gfx/gfxAPI.cpp +++ b/Engine/source/gfx/gfxAPI.cpp @@ -173,6 +173,7 @@ ImplementEnumType( GFXFormat, { GFXFormatR8G8B8, "GFXFormatR8G8B8" }, { GFXFormatR8G8B8A8, "GFXFormatR8G8B8A8" }, + { GFXFormatR8G8B8A8_SRGB, "GFXFormatR8G8B8A8_SRGB" }, { GFXFormatR8G8B8X8, "GFXFormatR8G8B8X8" }, { GFXFormatR32F, "GFXFormatR32F" }, { GFXFormatR5G6B5, "GFXFormatR5G6B5" }, @@ -182,11 +183,11 @@ ImplementEnumType( GFXFormat, { GFXFormatA8L8, "GFXFormatA8L8" }, { GFXFormatA8, "GFXFormatA8" }, { GFXFormatL8, "GFXFormatL8" }, - { GFXFormatDXT1, "GFXFormatDXT1" }, - { GFXFormatDXT2, "GFXFormatDXT2" }, - { GFXFormatDXT3, "GFXFormatDXT3" }, - { GFXFormatDXT4, "GFXFormatDXT4" }, - { GFXFormatDXT5, "GFXFormatDXT5" }, + { GFXFormatBC1, "GFXFormatBC1" }, + { GFXFormatBC2, "GFXFormatBC2" }, + { GFXFormatBC3, "GFXFormatBC3" }, + { GFXFormatBC4, "GFXFormatBC4" }, + { GFXFormatBC5, "GFXFormatBC5" }, { GFXFormatD32, "GFXFormatD32" }, { GFXFormatD24X8, "GFXFormatD24X8" }, { GFXFormatD24S8, "GFXFormatD24S8" }, diff --git a/Engine/source/gfx/gfxCubemap.cpp b/Engine/source/gfx/gfxCubemap.cpp index 69d55f511..3cce8bda8 100644 --- a/Engine/source/gfx/gfxCubemap.cpp +++ b/Engine/source/gfx/gfxCubemap.cpp @@ -35,6 +35,23 @@ GFXCubemap::~GFXCubemap() TEXMGR->releaseCubemap( this ); } +U32 GFXCubemap::_zUpFaceIndex(const U32 index) +{ + switch (index) + { + case 2: + return 4; + case 3: + return 5; + case 4: + return 2; + case 5: + return 3; + default: + return index; + }; +} + void GFXCubemap::initNormalize( U32 size ) { Point3F axis[6] = @@ -83,7 +100,7 @@ void GFXCubemap::initNormalize( U32 size ) } } - tex.set(bitmap, &GFXDefaultStaticDiffuseProfile, true, "Cubemap"); + tex.set(bitmap, &GFXStaticTextureSRGBProfile, true, "Cubemap"); } initStatic(faces); diff --git a/Engine/source/gfx/gfxCubemap.h b/Engine/source/gfx/gfxCubemap.h index 79a2bbd91..f056ee65b 100644 --- a/Engine/source/gfx/gfxCubemap.h +++ b/Engine/source/gfx/gfxCubemap.h @@ -47,6 +47,10 @@ protected: /// Sets the cubemap file path. void _setPath( const String &path ) { mPath = path; } + /// Get Z up face index of the cubemap. DDS files will be stored Y up + U32 _zUpFaceIndex(const U32 index); + + U32 mMipMapLevels; public: /// Create a static cubemap from a list of 6 face textures. @@ -74,6 +78,9 @@ public: // GFXResource interface /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer virtual const String describeSelf() const; + + /// Get the number of mip maps + const U32 getMipMapLevels() const { return mMipMapLevels; } }; diff --git a/Engine/source/gfx/gfxDevice.cpp b/Engine/source/gfx/gfxDevice.cpp index 7280a7a33..54c00f1e7 100644 --- a/Engine/source/gfx/gfxDevice.cpp +++ b/Engine/source/gfx/gfxDevice.cpp @@ -145,7 +145,7 @@ GFXDevice::GFXDevice() } mGlobalAmbientColorDirty = false; - mGlobalAmbientColor = ColorF(0.0f, 0.0f, 0.0f, 1.0f); + mGlobalAmbientColor = LinearColorF(0.0f, 0.0f, 0.0f, 1.0f); mLightMaterialDirty = false; dMemset(&mCurrentLightMaterial, 0, sizeof(GFXLightMaterial)); @@ -213,11 +213,11 @@ void GFXDevice::deviceInited() // Initialize the static helper textures. GBitmap temp( 2, 2, false, GFXFormatR8G8B8A8 ); temp.fill( ColorI::ONE ); - GFXTexHandle::ONE.set( &temp, &GFXDefaultStaticDiffuseProfile, false, "GFXTexHandle::ONE" ); + GFXTexHandle::ONE.set( &temp, &GFXStaticTextureSRGBProfile, false, "GFXTexHandle::ONE" ); temp.fill( ColorI::ZERO ); - GFXTexHandle::ZERO.set( &temp, &GFXDefaultStaticDiffuseProfile, false, "GFXTexHandle::ZERO" ); + GFXTexHandle::ZERO.set( &temp, &GFXStaticTextureSRGBProfile, false, "GFXTexHandle::ZERO" ); temp.fill( ColorI( 128, 128, 255 ) ); - GFXTexHandle::ZUP.set( &temp, &GFXDefaultStaticNormalMapProfile, false, "GFXTexHandle::ZUP" ); + GFXTexHandle::ZUP.set( &temp, &GFXNormalMapProfile, false, "GFXTexHandle::ZUP" ); } bool GFXDevice::destroy() @@ -739,7 +739,7 @@ void GFXDevice::setLightMaterial(const GFXLightMaterial& mat) mStateDirty = true; } -void GFXDevice::setGlobalAmbientColor(const ColorF& color) +void GFXDevice::setGlobalAmbientColor(const LinearColorF& color) { if(mGlobalAmbientColor != color) { @@ -1315,10 +1315,9 @@ DefineEngineFunction( getBestHDRFormat, GFXFormat, (),, // Figure out the best HDR format. This is the smallest // format which supports blending and filtering. Vector formats; - //formats.push_back( GFXFormatR10G10B10A2 ); TODO: replace with SRGB format once DX9 is gone - BJR - formats.push_back( GFXFormatR16G16B16A16F ); - formats.push_back( GFXFormatR16G16B16A16 ); - GFXFormat format = GFX->selectSupportedFormat( &GFXDefaultRenderTargetProfile, + formats.push_back(GFXFormatR16G16B16A16F); + formats.push_back( GFXFormatR10G10B10A2 ); + GFXFormat format = GFX->selectSupportedFormat( &GFXRenderTargetProfile, formats, true, true, diff --git a/Engine/source/gfx/gfxDevice.h b/Engine/source/gfx/gfxDevice.h index ef3bbce13..197249b47 100644 --- a/Engine/source/gfx/gfxDevice.h +++ b/Engine/source/gfx/gfxDevice.h @@ -543,7 +543,7 @@ protected: bool mLightDirty[LIGHT_STAGE_COUNT]; bool mLightsDirty; - ColorF mGlobalAmbientColor; + LinearColorF mGlobalAmbientColor; bool mGlobalAmbientColorDirty; /// @} @@ -615,7 +615,7 @@ protected: virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture) = 0; virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable) = 0; - virtual void setGlobalAmbientInternal(ColorF color) = 0; + virtual void setGlobalAmbientInternal(LinearColorF color) = 0; virtual void setLightMaterialInternal(const GFXLightMaterial mat) = 0; virtual bool beginSceneInternal() = 0; @@ -827,7 +827,7 @@ public: /// @{ /// - virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ) = 0; + virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ) = 0; virtual bool beginScene(); virtual void endScene(); virtual void beginField(); @@ -928,7 +928,7 @@ public: /// @{ void setLight(U32 stage, GFXLightInfo* light); void setLightMaterial(const GFXLightMaterial& mat); - void setGlobalAmbientColor(const ColorF& color); + void setGlobalAmbientColor(const LinearColorF& color); /// @} diff --git a/Engine/source/gfx/gfxDrawUtil.cpp b/Engine/source/gfx/gfxDrawUtil.cpp index 958ca0a51..0e7a4b3e9 100644 --- a/Engine/source/gfx/gfxDrawUtil.cpp +++ b/Engine/source/gfx/gfxDrawUtil.cpp @@ -278,7 +278,8 @@ U32 GFXDrawUtil::drawTextN( GFont *font, const Point2I &ptDraw, const UTF16 *in_ } // Queue char for rendering.. - mFontRenderBatcher->queueChar(c, ptX, mBitmapModulation); + GFXVertexColor color = mBitmapModulation; + mFontRenderBatcher->queueChar(c, ptX, color); } @@ -474,7 +475,7 @@ void GFXDrawUtil::drawRect( const Point2F &upperLeft, const Point2F &lowerRight, verts[8].point.set( upperLeft.x + ulOffset + nw.x, upperLeft.y + ulOffset + nw.y, 0.0f ); // same as 0 verts[9].point.set( upperLeft.x + ulOffset - nw.x, upperLeft.y + ulOffset - nw.y, 0.0f ); // same as 1 - for (S32 i=0; i<10; i++) + for (S32 i = 0; i < 10; i++) verts[i].color = color; verts.unlock(); @@ -530,8 +531,7 @@ void GFXDrawUtil::drawRectFill( const Point2F &upperLeft, const Point2F &lowerRi verts[1].point.set( lowerRight.x + ne.x + ulOffset, upperLeft.y + ne.y + ulOffset, 0.0f); verts[2].point.set( upperLeft.x - ne.x + ulOffset, lowerRight.y - ne.y + ulOffset, 0.0f); verts[3].point.set( lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset, 0.0f); - - for (S32 i=0; i<4; i++) + for (S32 i = 0; i < 4; i++) verts[i].color = color; verts.unlock(); @@ -613,7 +613,6 @@ void GFXDrawUtil::drawLine( F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, cons verts[0].point.set( x1, y1, z1 ); verts[1].point.set( x2, y2, z2 ); - verts[0].color = color; verts[1].color = color; @@ -714,7 +713,6 @@ void GFXDrawUtil::_drawWireTriangle( const GFXStateBlockDesc &desc, const Point3 { GFXVertexBufferHandle verts(mDevice, 4, GFXBufferTypeVolatile); verts.lock(); - // Set up the line strip verts[0].point = p0; verts[0].color = color; @@ -747,7 +745,6 @@ void GFXDrawUtil::_drawSolidTriangle( const GFXStateBlockDesc &desc, const Point { GFXVertexBufferHandle verts(mDevice, 3, GFXBufferTypeVolatile); verts.lock(); - // Set up the line strip verts[0].point = p0; verts[0].color = color; @@ -779,7 +776,6 @@ void GFXDrawUtil::drawPolygon( const GFXStateBlockDesc& desc, const Point3F* poi const bool isWireframe = ( desc.fillMode == GFXFillWireframe ); const U32 numVerts = isWireframe ? numPoints + 1 : numPoints; GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numVerts, GFXBufferTypeVolatile ); - verts.lock(); for( U32 i = 0; i < numPoints; ++ i ) { @@ -831,7 +827,6 @@ void GFXDrawUtil::_drawWireCube( const GFXStateBlockDesc &desc, const Point3F &s verts.lock(); Point3F halfSize = size * 0.5f; - // setup 6 line loops U32 vertexIndex = 0; for(S32 i = 0; i < 6; i++) @@ -874,7 +869,6 @@ void GFXDrawUtil::_drawSolidCube( const GFXStateBlockDesc &desc, const Point3F & verts.lock(); Point3F halfSize = size * 0.5f; - // setup 6 line loops U32 vertexIndex = 0; U32 idx; @@ -953,7 +947,6 @@ void GFXDrawUtil::_drawWirePolyhedron( const GFXStateBlockDesc &desc, const AnyP GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numEdges * 2, GFXBufferTypeVolatile); // Fill it with the vertices for the edges. - verts.lock(); for( U32 i = 0; i < numEdges; ++ i ) { @@ -998,7 +991,6 @@ void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const Any // put all the polyhedron's points in there. GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numPoints, GFXBufferTypeVolatile ); - verts.lock(); for( U32 i = 0; i < numPoints; ++ i ) { @@ -1087,7 +1079,7 @@ void GFXDrawUtil::drawObjectBox( const GFXStateBlockDesc &desc, const Point3F &s scaledObjMat.scale( size ); scaledObjMat.setPosition( pos ); - + //to linear is done in primbuilder PrimBuild::color( color ); PrimBuild::begin( GFXLineList, 48 ); @@ -1158,7 +1150,6 @@ void GFXDrawUtil::_drawSolidCapsule( const GFXStateBlockDesc &desc, const Point3 S32 numPoints = sizeof(circlePoints)/sizeof(Point2F); GFXVertexBufferHandle verts(mDevice, numPoints * 2 + 2, GFXBufferTypeVolatile); verts.lock(); - for (S32 i=0; i verts(mDevice, numPoints * 3 + 2, GFXBufferTypeVolatile); verts.lock(); - F32 sign = -1.f; S32 indexDown = 0; //counting down from numPoints S32 indexUp = 0; //counting up from 0 @@ -1340,7 +1330,6 @@ void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &ba S32 numPoints = sizeof(circlePoints) / sizeof(Point2F); GFXVertexBufferHandle verts(mDevice, numPoints *4 + 2, GFXBufferTypeVolatile); verts.lock(); - F32 sign = -1.f; S32 indexDown = 0; //counting down from numPoints S32 indexUp = 0; //counting up from 0 @@ -1379,7 +1368,6 @@ void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &ba verts[vertindex + 1].color = color; } - verts.unlock(); mDevice->setStateBlockByDesc( desc ); @@ -1452,7 +1440,6 @@ void GFXDrawUtil::drawSolidPlane( const GFXStateBlockDesc &desc, const Point3F & { GFXVertexBufferHandle verts(mDevice, 4, GFXBufferTypeVolatile); verts.lock(); - verts[0].point = pos + Point3F( -size.x / 2.0f, -size.y / 2.0f, 0 ); verts[0].color = color; verts[1].point = pos + Point3F( -size.x / 2.0f, size.y / 2.0f, 0 ); @@ -1508,7 +1495,6 @@ void GFXDrawUtil::drawPlaneGrid( const GFXStateBlockDesc &desc, const Point3F &p GFXVertexBufferHandle verts( mDevice, numVertices, GFXBufferTypeVolatile ); verts.lock(); - U32 vertCount = 0; if( plane == PlaneXY || plane == PlaneXZ ) diff --git a/Engine/source/gfx/gfxEnums.h b/Engine/source/gfx/gfxEnums.h index ba5664b41..85b224b02 100644 --- a/Engine/source/gfx/gfxEnums.h +++ b/Engine/source/gfx/gfxEnums.h @@ -178,11 +178,12 @@ enum GFXFormat // 24 bit texture formats... GFXFormatR8G8B8,// first in group... - + GFXFormatR8G8B8_SRGB, // 32 bit texture formats... GFXFormatR8G8B8A8,// first in group... GFXFormatR8G8B8X8, GFXFormatB8G8R8A8, + GFXFormatR8G8B8A8_SRGB, GFXFormatR32F, GFXFormatR16G16, GFXFormatR16G16F, @@ -192,9 +193,6 @@ enum GFXFormat GFXFormatD24S8, GFXFormatD24FS8, - // sRGB formats - GFXFormatR8G8B8A8_SRGB, - // Guaranteed RGBA8 (for apis which really dont like bgr) GFXFormatR8G8B8A8_LINEAR_FORCE, @@ -205,12 +203,16 @@ enum GFXFormat // 128 bit texture formats... GFXFormatR32G32B32A32F,// first in group... - // unknown size... - GFXFormatDXT1,// first in group... - GFXFormatDXT2, - GFXFormatDXT3, - GFXFormatDXT4, - GFXFormatDXT5, + // unknown size...Block compression + GFXFormatBC1, //dxt1 + GFXFormatBC2, //dxt2/3 + GFXFormatBC3, //dxt4/5 + GFXFormatBC4, //3dc+ / ati1 + GFXFormatBC5, //3dc / ati2 + // compressed sRGB formats + GFXFormatBC1_SRGB, + GFXFormatBC2_SRGB, + GFXFormatBC3_SRGB, GFXFormat_COUNT, @@ -220,7 +222,7 @@ enum GFXFormat GFXFormat_32BIT = GFXFormatR8G8B8A8, GFXFormat_64BIT = GFXFormatR16G16B16A16, GFXFormat_128BIT = GFXFormatR32G32B32A32F, - GFXFormat_UNKNOWNSIZE = GFXFormatDXT1, + GFXFormat_UNKNOWNSIZE = GFXFormatBC1 }; /// Returns the byte size of the pixel for non-compressed formats. diff --git a/Engine/source/gfx/gfxFence.cpp b/Engine/source/gfx/gfxFence.cpp index c6c69c769..3c4bcbdb5 100644 --- a/Engine/source/gfx/gfxFence.cpp +++ b/Engine/source/gfx/gfxFence.cpp @@ -49,7 +49,7 @@ void GFXGeneralFence::_init() mInitialized = true; // Allocate resources - mInitialized &= mRTTexHandle.set( 2, 2, GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile, avar("%s() - mInitialized (line %d)", __FUNCTION__, __LINE__) ); + mInitialized &= mRTTexHandle.set( 2, 2, GFXFormatR8G8B8X8, &GFXRenderTargetProfile, avar("%s() - mInitialized (line %d)", __FUNCTION__, __LINE__) ); mRenderTarget = GFX->allocRenderToTextureTarget(); mInitialized &= ( mRenderTarget != NULL ); @@ -120,7 +120,7 @@ void GFXGeneralFence::_onTextureEvent( GFXTexCallbackCode code ) break; case GFXResurrect: - mRTTexHandle.set( 2, 2, GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile, avar("%s() - GFXGeneralFence->mRTTexHandle (line %d)", __FUNCTION__, __LINE__) ); + mRTTexHandle.set( 2, 2, GFXFormatR8G8B8X8, &GFXRenderTargetProfile, avar("%s() - GFXGeneralFence->mRTTexHandle (line %d)", __FUNCTION__, __LINE__) ); break; } } @@ -132,7 +132,7 @@ void GFXGeneralFence::zombify() void GFXGeneralFence::resurrect() { - mRTTexHandle.set( 2, 2, GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile, avar("%s() - mRTTexHandle (line %d)", __FUNCTION__, __LINE__) ); + mRTTexHandle.set( 2, 2, GFXFormatR8G8B8X8, &GFXRenderTargetProfile, avar("%s() - mRTTexHandle (line %d)", __FUNCTION__, __LINE__) ); } const String GFXGeneralFence::describeSelf() const diff --git a/Engine/source/gfx/gfxFormatUtils.cpp b/Engine/source/gfx/gfxFormatUtils.cpp index 433d6b8a9..ce5674a39 100644 --- a/Engine/source/gfx/gfxFormatUtils.cpp +++ b/Engine/source/gfx/gfxFormatUtils.cpp @@ -67,11 +67,11 @@ GFXFormatInfo::Data GFXFormatInfo::smFormatInfos[ GFXFormat_COUNT ] = GFXFormatInfo::Data( 16, true, false, true ), // GFXFormatR32G32B32A32F // Compressed formats... - GFXFormatInfo::Data( 0, false, true, false ), // GFXFormatDXT1 - GFXFormatInfo::Data( 0, true, true, false ), // GFXFormatDXT2 - GFXFormatInfo::Data( 0, true, true, false ), // GFXFormatDXT3 - GFXFormatInfo::Data( 0, true, true, false ), // GFXFormatDXT4 - GFXFormatInfo::Data( 0, true, true, false ), // GFXFormatDXT5 + GFXFormatInfo::Data( 0, false, true, false ), // GFXFormatBC1 + GFXFormatInfo::Data( 0, true, true, false ), // GFXFormatBC2 + GFXFormatInfo::Data( 0, true, true, false ), // GFXFormatBC3 + GFXFormatInfo::Data( 0, false, true, false ), // GFXFormatBC4 + GFXFormatInfo::Data( 0, false, true, false ), // GFXFormatBC5 }; //----------------------------------------------------------------------------- diff --git a/Engine/source/gfx/gfxShader.h b/Engine/source/gfx/gfxShader.h index f9059fbc0..473412728 100644 --- a/Engine/source/gfx/gfxShader.h +++ b/Engine/source/gfx/gfxShader.h @@ -59,7 +59,7 @@ class Point2I; class Point2F; -class ColorF; +class LinearColorF; class MatrixF; class GFXShader; class GFXVertexFormat; @@ -176,7 +176,7 @@ public: virtual void set(GFXShaderConstHandle* handle, const Point3F& fv) = 0; virtual void set(GFXShaderConstHandle* handle, const Point4F& fv) = 0; virtual void set(GFXShaderConstHandle* handle, const PlaneF& fv) = 0; - virtual void set(GFXShaderConstHandle* handle, const ColorF& fv) = 0; + virtual void set(GFXShaderConstHandle* handle, const LinearColorF& fv) = 0; virtual void set(GFXShaderConstHandle* handle, const S32 f) = 0; virtual void set(GFXShaderConstHandle* handle, const Point2I& fv) = 0; virtual void set(GFXShaderConstHandle* handle, const Point3I& fv) = 0; diff --git a/Engine/source/gfx/gfxStateBlock.cpp b/Engine/source/gfx/gfxStateBlock.cpp index 1c4c305cf..2ab02fc23 100644 --- a/Engine/source/gfx/gfxStateBlock.cpp +++ b/Engine/source/gfx/gfxStateBlock.cpp @@ -281,6 +281,7 @@ GFXSamplerStateDesc::GFXSamplerStateDesc() magFilter = GFXTextureFilterLinear; minFilter = GFXTextureFilterLinear; mipFilter = GFXTextureFilterLinear; + samplerFunc = GFXCmpNever; maxAnisotropy = 1; alphaArg1 = GFXTATexture; alphaArg2 = GFXTADiffuse; diff --git a/Engine/source/gfx/gfxStateBlock.h b/Engine/source/gfx/gfxStateBlock.h index a083c5cc3..930cdd54b 100644 --- a/Engine/source/gfx/gfxStateBlock.h +++ b/Engine/source/gfx/gfxStateBlock.h @@ -47,6 +47,8 @@ struct GFXSamplerStateDesc GFXTextureFilterType minFilter; GFXTextureFilterType mipFilter; + GFXCmpFunc samplerFunc; + /// The maximum anisotropy used when one of the filter types /// is set to anisotropic. /// diff --git a/Engine/source/gfx/gfxStringEnumTranslate.cpp b/Engine/source/gfx/gfxStringEnumTranslate.cpp index c564fbb29..8d353556b 100644 --- a/Engine/source/gfx/gfxStringEnumTranslate.cpp +++ b/Engine/source/gfx/gfxStringEnumTranslate.cpp @@ -134,6 +134,7 @@ void GFXStringEnumTranslate::init() INIT_LOOKUPTABLE( GFXStringTextureFormat, GFXFormat, const char * ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8A8 ); + GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8A8_SRGB); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8X8 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatB8G8R8A8 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR32F ); @@ -144,11 +145,11 @@ void GFXStringEnumTranslate::init() GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatA8L8 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatA8 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatL8 ); - GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatDXT1 ); - GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatDXT2 ); - GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatDXT3 ); - GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatDXT4 ); - GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatDXT5 ); + GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC1 ); + GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC2 ); + GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC3 ); + GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC4 ); + GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC5 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD32 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD24X8 ); GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD24S8 ); diff --git a/Engine/source/gfx/gfxStructs.h b/Engine/source/gfx/gfxStructs.h index 0d1672712..3f2602331 100644 --- a/Engine/source/gfx/gfxStructs.h +++ b/Engine/source/gfx/gfxStructs.h @@ -64,17 +64,17 @@ public: Point3F mPos; VectorF mDirection; - ColorF mColor; - ColorF mAmbient; + LinearColorF mColor; + LinearColorF mAmbient; F32 mRadius; F32 mInnerConeAngle; F32 mOuterConeAngle; /// @todo Revisit below (currently unused by fixed function lights) Point3F position; - ColorF ambient; - ColorF diffuse; - ColorF specular; + LinearColorF ambient; + LinearColorF diffuse; + LinearColorF specular; VectorF spotDirection; F32 spotExponent; F32 spotCutoff; @@ -88,10 +88,10 @@ public: // Material definition for FF lighting struct GFXLightMaterial { - ColorF ambient; - ColorF diffuse; - ColorF specular; - ColorF emissive; + LinearColorF ambient; + LinearColorF diffuse; + LinearColorF specular; + LinearColorF emissive; F32 shininess; }; diff --git a/Engine/source/gfx/gfxTarget.h b/Engine/source/gfx/gfxTarget.h index d0c7f47ad..ae1cc0097 100644 --- a/Engine/source/gfx/gfxTarget.h +++ b/Engine/source/gfx/gfxTarget.h @@ -161,7 +161,7 @@ public: enum RenderSlot { DepthStencil, - Color0, Color1, Color2, Color3, Color4, + Color0, Color1, Color2, Color3, Color4, Color5, MaxRenderSlotId, }; diff --git a/Engine/source/gfx/gfxTextureHandle.cpp b/Engine/source/gfx/gfxTextureHandle.cpp index 4ea34d8e0..e9be24c62 100644 --- a/Engine/source/gfx/gfxTextureHandle.cpp +++ b/Engine/source/gfx/gfxTextureHandle.cpp @@ -145,7 +145,7 @@ bool GFXTexHandle::set( U32 width, U32 height, U32 depth, void *pixels, GFXForma free(); // Create and set the new texture. - StrongObjectRef::set( TEXMGR->createTexture( width, height, depth, pixels, format, profile ) ); + StrongObjectRef::set( TEXMGR->createTexture( width, height, depth, pixels, format, profile,numMipLevels ) ); #ifdef TORQUE_DEBUG if ( getPointer() ) diff --git a/Engine/source/gfx/gfxTextureManager.cpp b/Engine/source/gfx/gfxTextureManager.cpp index e9a3e57d4..c6aa0757b 100644 --- a/Engine/source/gfx/gfxTextureManager.cpp +++ b/Engine/source/gfx/gfxTextureManager.cpp @@ -26,7 +26,7 @@ #include "gfx/gfxDevice.h" #include "gfx/gfxCardProfile.h" #include "gfx/gfxStringEnumTranslate.h" -#include "gfx/bitmap/ddsUtils.h" +#include "gfx/bitmap/imageUtils.h" #include "core/strings/stringFunctions.h" #include "core/util/safeDelete.h" #include "core/resourceManager.h" @@ -251,9 +251,11 @@ GFXTextureObject *GFXTextureManager::_lookupTexture( const char *hashName, const { GFXTextureObject *ret = hashFind( hashName ); - // TODO: Profile checking HERE + //compare just the profile flags and not the entire profile, names could be different but otherwise identical flags + if (ret && (ret->mProfile->compareFlags(*profile))) + return ret; - return ret; + return NULL; } GFXTextureObject *GFXTextureManager::_lookupTexture( const DDSFile *ddsFile, const GFXTextureProfile *profile ) @@ -370,9 +372,9 @@ GFXTextureObject *GFXTextureManager::_createTexture( GBitmap *bmp, } // If _validateTexParams kicked back a different format, than there needs to be - // a conversion + // a conversion unless it's a sRGB format DDSFile *bmpDDS = NULL; - if( realBmp->getFormat() != realFmt ) + if( realBmp->getFormat() != realFmt && !profile->isSRGB() ) { const GFXFormat oldFmt = realBmp->getFormat(); @@ -390,22 +392,20 @@ GFXTextureObject *GFXTextureManager::_createTexture( GBitmap *bmp, // This shouldn't live here, I don't think switch( realFmt ) { - case GFXFormatDXT1: - case GFXFormatDXT2: - case GFXFormatDXT3: - case GFXFormatDXT4: - case GFXFormatDXT5: + case GFXFormatBC1: + case GFXFormatBC2: + case GFXFormatBC3: // If this is a Normal Map profile, than the data needs to be conditioned // to use the swizzle trick if( ret->mProfile->getType() == GFXTextureProfile::NormalMap ) { PROFILE_START(DXT_DXTNMSwizzle); static DXT5nmSwizzle sDXT5nmSwizzle; - DDSUtil::swizzleDDS( bmpDDS, sDXT5nmSwizzle ); + ImageUtil::swizzleDDS( bmpDDS, sDXT5nmSwizzle ); PROFILE_END(); } - convSuccess = DDSUtil::squishDDS( bmpDDS, realFmt ); + convSuccess = ImageUtil::ddsCompress( bmpDDS, realFmt ); break; default: AssertFatal(false, "Attempting to convert to a non-DXT format"); @@ -534,7 +534,7 @@ GFXTextureObject *GFXTextureManager::_createTexture( DDSFile *dds, GFXFormat fmt = dds->mFormat; _validateTexParams( dds->getHeight(), dds->getWidth(), profile, numMips, fmt ); - if( fmt != dds->mFormat ) + if( fmt != dds->mFormat && !profile->isSRGB()) { Con::errorf( "GFXTextureManager - failed to validate texture parameters for DDS file '%s'", fileName ); return NULL; @@ -629,50 +629,7 @@ GFXTextureObject *GFXTextureManager::createTexture( const Torque::Path &path, GF // We need to handle path's that have had "incorrect" // extensions parsed out of the file name - Torque::Path correctPath = path; - - bool textureExt = false; - - // Easiest case to handle is when there isn't an extension - if (path.getExtension().isEmpty()) - textureExt = true; - - // Since "dds" isn't registered with GBitmap currently we - // have to test it separately - if (sDDSExt.equal( path.getExtension(), String::NoCase ) ) - textureExt = true; - - // Now loop through the rest of the GBitmap extensions - // to see if we have any matches - for ( U32 i = 0; i < GBitmap::sRegistrations.size(); i++ ) - { - // If we have gotten a match (either in this loop or before) - // then we can exit - if (textureExt) - break; - - const GBitmap::Registration ® = GBitmap::sRegistrations[i]; - const Vector &extensions = reg.extensions; - - for ( U32 j = 0; j < extensions.size(); ++j ) - { - if ( extensions[j].equal( path.getExtension(), String::NoCase ) ) - { - // Found a valid texture extension - textureExt = true; - break; - } - } - } - - // If we didn't find a valid texture extension then assume that - // the parsed out "extension" was actually intended to be part of - // the texture name so add it back - if (!textureExt) - { - correctPath.setFileName( Torque::Path::Join( path.getFileName(), '.', path.getExtension() ) ); - correctPath.setExtension( String::EmptyString ); - } + Torque::Path correctPath = validatePath(path); // Check the cache first... String pathNoExt = Torque::Path::Join( correctPath.getRoot(), ':', correctPath.getPath() ); @@ -786,7 +743,7 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width, U32 height, GFXFo GFXFormat checkFmt = format; _validateTexParams( localWidth, localHeight, profile, numMips, checkFmt ); - AssertFatal( checkFmt == format, "Anonymous texture didn't get the format it wanted." ); +// AssertFatal( checkFmt == format, "Anonymous texture didn't get the format it wanted." ); GFXTextureObject *outTex = NULL; @@ -836,12 +793,13 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width, U32 depth, void *pixels, GFXFormat format, - GFXTextureProfile *profile ) + GFXTextureProfile *profile, + U32 numMipLevels) { PROFILE_SCOPE( GFXTextureManager_CreateTexture_3D ); // Create texture... - GFXTextureObject *ret = _createTextureObject( height, width, depth, format, profile, 1 ); + GFXTextureObject *ret = _createTextureObject( height, width, depth, format, profile, numMipLevels ); if(!ret) { @@ -868,6 +826,339 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width, return ret; } +Torque::Path GFXTextureManager::validatePath(const Torque::Path &path) +{ + // We need to handle path's that have had "incorrect" + // extensions parsed out of the file name + Torque::Path correctPath = path; + + bool textureExt = false; + + // Easiest case to handle is when there isn't an extension + if (path.getExtension().isEmpty()) + textureExt = true; + + // Since "dds" isn't registered with GBitmap currently we + // have to test it separately + if (sDDSExt.equal(path.getExtension(), String::NoCase)) + textureExt = true; + + // Now loop through the rest of the GBitmap extensions + // to see if we have any matches + for (U32 i = 0; i < GBitmap::sRegistrations.size(); i++) + { + // If we have gotten a match (either in this loop or before) + // then we can exit + if (textureExt) + break; + + const GBitmap::Registration ® = GBitmap::sRegistrations[i]; + const Vector &extensions = reg.extensions; + + for (U32 j = 0; j < extensions.size(); ++j) + { + if (extensions[j].equal(path.getExtension(), String::NoCase)) + { + // Found a valid texture extension + textureExt = true; + break; + } + } + } + + // If we didn't find a valid texture extension then assume that + // the parsed out "extension" was actually intended to be part of + // the texture name so add it back + if (!textureExt) + { + correctPath.setFileName(Torque::Path::Join(path.getFileName(), '.', path.getExtension())); + correctPath.setExtension(String::EmptyString); + } + return correctPath; +} + +GBitmap *GFXTextureManager::loadUncompressedTexture(const Torque::Path &path, GFXTextureProfile *profile) +{ + PROFILE_SCOPE(GFXTextureManager_loadUncompressedTexture); + + GBitmap *retBitmap = NULL; + + // Resource handles used for loading. Hold on to them + // throughout this function so that change notifications + // don't get added, then removed, and then re-added. + + Resource< DDSFile > dds; + Resource< GBitmap > bitmap; + + // We need to handle path's that have had "incorrect" + // extensions parsed out of the file name + Torque::Path correctPath = validatePath(path); + + U32 scalePower = profile ? getTextureDownscalePower(profile) : 0; + + // Check the cache first... + String pathNoExt = Torque::Path::Join(correctPath.getRoot(), ':', correctPath.getPath()); + pathNoExt = Torque::Path::Join(pathNoExt, '/', correctPath.getFileName()); + + // If this is a valid file (has an extension) than load it + Path realPath; + if (Torque::FS::IsFile(correctPath)) + { + PROFILE_SCOPE(GFXTextureManager_loadUncompressedTexture_INNNER1) + // Check for DDS + if (sDDSExt.equal(correctPath.getExtension(), String::NoCase)) + { + dds = DDSFile::load(correctPath, scalePower); + if (dds != NULL) + { + realPath = dds.getPath(); + retBitmap = new GBitmap(); + if (!dds->decompressToGBitmap(retBitmap)) + { + delete retBitmap; + retBitmap = NULL; + } + } + } + else // Let GBitmap take care of it + { + bitmap = GBitmap::load(correctPath); + if (bitmap != NULL) + { + realPath = bitmap.getPath(); + retBitmap = new GBitmap(*bitmap); + + if (scalePower && + isPow2(retBitmap->getWidth()) && + isPow2(retBitmap->getHeight()) && + profile->canDownscale()) + { + retBitmap->extrudeMipLevels(); + retBitmap->chopTopMips(scalePower); + } + } + } + } + else + { + PROFILE_SCOPE(GFXTextureManager_loadUncompressedTexture_INNNER2) + // NOTE -- We should probably remove the code from GBitmap that tries different + // extensions for things GBitmap loads, and move it here. I think it should + // be a bit more involved than just a list of extensions. Some kind of + // extension registration thing, maybe. + + // Check to see if there is a .DDS file with this name (if no extension is provided) + Torque::Path tryDDSPath = pathNoExt; + if (tryDDSPath.getExtension().isNotEmpty()) + tryDDSPath.setFileName(tryDDSPath.getFullFileName()); + tryDDSPath.setExtension(sDDSExt); + + if (Torque::FS::IsFile(tryDDSPath)) + { + dds = DDSFile::load(tryDDSPath, scalePower); + if (dds != NULL) + { + realPath = dds.getPath(); + // Decompress dds into the GBitmap + retBitmap = new GBitmap(); + if (!dds->decompressToGBitmap(retBitmap)) + { + delete retBitmap; + retBitmap = NULL; + } + } + } + + // Otherwise, retTexObj stays NULL, and fall through to the generic GBitmap + // load. + } + + // If we still don't have a texture object yet, feed the correctPath to GBitmap and + // it will try a bunch of extensions + if (retBitmap == NULL) + { + PROFILE_SCOPE(GFXTextureManager_loadUncompressedTexture_INNNER3) + // Find and load the texture. + bitmap = GBitmap::load(correctPath); + + if (bitmap != NULL) + { + retBitmap = new GBitmap(*bitmap); + + if (scalePower && + isPow2(retBitmap->getWidth()) && + isPow2(retBitmap->getHeight()) && + profile->canDownscale()) + { + retBitmap->extrudeMipLevels(); + retBitmap->chopTopMips(scalePower); + } + } + } + + return retBitmap; +} + +GFXTextureObject *GFXTextureManager::createCompositeTexture(const Torque::Path &pathR, const Torque::Path &pathG, const Torque::Path &pathB, const Torque::Path &pathA, U32 inputKey[4], + GFXTextureProfile *profile) +{ + PROFILE_SCOPE(GFXTextureManager_createCompositeTexture); + + String inputKeyStr = String::ToString("%d%d%d%d", inputKey[0], inputKey[1], inputKey[2], inputKey[3]); + + String resourceTag = pathR.getFileName() + pathG.getFileName() + pathB.getFileName() + pathA.getFileName() + inputKeyStr; //associate texture object with a key combo + + GFXTextureObject *cacheHit = _lookupTexture(resourceTag, profile); + if (cacheHit != NULL) return cacheHit; + + GBitmap*bitmap[4]; + bitmap[0] = loadUncompressedTexture(pathR, profile); + if (!pathG.isEmpty()) + bitmap[1] = loadUncompressedTexture(pathG, profile); + else + bitmap[1] = NULL; + + if (!pathB.isEmpty()) + bitmap[2] = loadUncompressedTexture(pathB, profile); + else + bitmap[2] = NULL; + if (!pathA.isEmpty()) + bitmap[3] = loadUncompressedTexture(pathA, profile); + else + bitmap[3] = NULL; + + + Path realPath; + GFXTextureObject *retTexObj = NULL; + realPath = validatePath(pathR); //associate path with r channel texture in. + + retTexObj = createCompositeTexture(bitmap, inputKey, resourceTag, profile, false); + + if (retTexObj) + { + // Store the path for later use. + retTexObj->mPath = resourceTag; + + // Register the texture file for change notifications. + FS::AddChangeNotification(retTexObj->getPath(), this, &GFXTextureManager::_onFileChanged); + } + + // Could put in a final check for 'retTexObj == NULL' here as an error message. + for (U32 i = 0; i < 4; i++) + { + if (bitmap[i]) + { + bitmap[i]->deleteImage(); + delete bitmap[i]; + } + } + return retTexObj; +} + +void GFXTextureManager::saveCompositeTexture(const Torque::Path &pathR, const Torque::Path &pathG, const Torque::Path &pathB, const Torque::Path &pathA, U32 inputKey[4], + const Torque::Path &saveAs,GFXTextureProfile *profile) +{ + PROFILE_SCOPE(GFXTextureManager_saveCompositeTexture); + + String inputKeyStr = String::ToString("%d%d%d%d", inputKey[0], inputKey[1], inputKey[2], inputKey[3]); + + String resourceTag = pathR.getFileName() + pathG.getFileName() + pathB.getFileName() + pathA.getFileName() + inputKeyStr; //associate texture object with a key combo + + GFXTextureObject *cacheHit = _lookupTexture(resourceTag, profile); + if (cacheHit != NULL) + { + cacheHit->dumpToDisk("png", saveAs.getFullPath()); + return; + } + GBitmap*bitmap[4]; + bitmap[0] = loadUncompressedTexture(pathR, profile); + if (!pathG.isEmpty()) + bitmap[1] = loadUncompressedTexture(pathG, profile); + else + bitmap[1] = NULL; + + if (!pathB.isEmpty()) + bitmap[2] = loadUncompressedTexture(pathB, profile); + else + bitmap[2] = NULL; + if (!pathA.isEmpty()) + bitmap[3] = loadUncompressedTexture(pathA, profile); + else + bitmap[3] = NULL; + + + Path realPath; + GFXTextureObject *retTexObj = NULL; + realPath = validatePath(pathR); //associate path with r channel texture in. + + retTexObj = createCompositeTexture(bitmap, inputKey, resourceTag, profile, false); + if (retTexObj != NULL) + retTexObj->dumpToDisk("png", saveAs.getFullPath()); + return; +} + +DefineEngineFunction(saveCompositeTexture, void, (const char* pathR, const char* pathG, const char* pathB, const char* pathA, + const char * inputKeyString, const char* saveAs), + ("", "", "", "", "", ""), "File1,file2,file3,file4,[chanels for r g b and a locations],saveAs") +{ + U32 inputKey[4] = {0,0,0,0}; + + if (dStrcmp(inputKeyString, "") != 0) + { + dSscanf(inputKeyString, "%i %i %i %i", &inputKey[0], &inputKey[1], &inputKey[2], &inputKey[3]); + } + GFX->getTextureManager()->saveCompositeTexture(pathR, pathG, pathB, pathA, inputKey, saveAs, &GFXTexturePersistentProfile); +} + +GFXTextureObject *GFXTextureManager::createCompositeTexture(GBitmap*bmp[4], U32 inputKey[4], + const String &resourceName, GFXTextureProfile *profile, bool deleteBmp) +{ + if (!bmp[0]) + { + Con::errorf(ConsoleLogEntry::General, "GFXTextureManager::createCompositeTexture() - Got NULL bitmap(R)!"); + return NULL; + } + + U8 rChan, gChan, bChan, aChan; + + //pack additional bitmaps into the origional + for (U32 x = 0; x < bmp[0]->getWidth(); x++) + { + for (U32 y = 0; y < bmp[0]->getHeight(); y++) + { + rChan = bmp[0]->getChanelValueAt(x, y, inputKey[0]); + + if (bmp[1]) + gChan = bmp[1]->getChanelValueAt(x, y, inputKey[1]); + else + gChan = 255; + + if (bmp[2]) + bChan = bmp[2]->getChanelValueAt(x, y, inputKey[2]); + else + bChan = 255; + + if (bmp[3]) + aChan = bmp[3]->getChanelValueAt(x, y, inputKey[3]); + else + aChan = 255; + + bmp[0]->setColor(x, y, ColorI(rChan, gChan, bChan, aChan)); + } + } + + GFXTextureObject *cacheHit = _lookupTexture(resourceName, profile); + if (cacheHit != NULL) + { + // Con::errorf("Cached texture '%s'", (resourceName.isNotEmpty() ? resourceName.c_str() : "unknown")); + if (deleteBmp) + delete bmp[0]; + return cacheHit; + } + + return _createTexture(bmp[0], resourceName, profile, deleteBmp, NULL); +} + GFXTextureObject* GFXTextureManager::_findPooledTexure( U32 width, U32 height, GFXFormat format, @@ -1033,13 +1324,16 @@ void GFXTextureManager::_validateTexParams( const U32 width, const U32 height, GFXFormat testingFormat = inOutFormat; if( profile->getCompression() != GFXTextureProfile::NONE ) { - const S32 offset = profile->getCompression() - GFXTextureProfile::DXT1; - testingFormat = GFXFormat( GFXFormatDXT1 + offset ); + const S32 offset = profile->getCompression() - GFXTextureProfile::BC1; + testingFormat = GFXFormat( GFXFormatBC1 + offset ); // No auto-gen mips on compressed textures autoGenSupp = false; } + if (profile->isSRGB()) + testingFormat = ImageUtil::toSRGBFormat(testingFormat); + // inOutFormat is not modified by this method GFXCardProfiler* cardProfiler = GFX->getCardProfiler(); bool chekFmt = cardProfiler->checkFormat(testingFormat, profile, autoGenSupp); diff --git a/Engine/source/gfx/gfxTextureManager.h b/Engine/source/gfx/gfxTextureManager.h index dadd9534c..d33582c5e 100644 --- a/Engine/source/gfx/gfxTextureManager.h +++ b/Engine/source/gfx/gfxTextureManager.h @@ -116,7 +116,8 @@ public: U32 depth, void *pixels, GFXFormat format, - GFXTextureProfile *profile ); + GFXTextureProfile *profile, + U32 numMipLevels = 1); virtual GFXTextureObject *createTexture( U32 width, U32 height, @@ -125,6 +126,19 @@ public: U32 numMipLevels, S32 antialiasLevel); + Torque::Path validatePath(const Torque::Path &path); + GBitmap *loadUncompressedTexture(const Torque::Path &path, GFXTextureProfile *profile); + virtual GFXTextureObject *createCompositeTexture(const Torque::Path &pathR, const Torque::Path &pathG, const Torque::Path &pathB, const Torque::Path &pathA, U32 inputKey[4], + GFXTextureProfile *profile); + + void saveCompositeTexture(const Torque::Path &pathR, const Torque::Path &pathG, const Torque::Path &pathB, const Torque::Path &pathA, U32 inputKey[4], + const Torque::Path &saveAs,GFXTextureProfile *profile); + + virtual GFXTextureObject *createCompositeTexture(GBitmap*bmp[4], U32 inputKey[4], + const String &resourceName, + GFXTextureProfile *profile, + bool deleteBmp); + void deleteTexture( GFXTextureObject *texture ); void reloadTexture( GFXTextureObject *texture ); diff --git a/Engine/source/gfx/gfxTextureObject.cpp b/Engine/source/gfx/gfxTextureObject.cpp index 655bb0164..ffb675192 100644 --- a/Engine/source/gfx/gfxTextureObject.cpp +++ b/Engine/source/gfx/gfxTextureObject.cpp @@ -212,7 +212,7 @@ F32 GFXTextureObject::getMaxVCoord() const U32 GFXTextureObject::getEstimatedSizeInBytes() const { // We have to deal with DDS specially. - if ( mFormat >= GFXFormatDXT1 ) + if ( mFormat >= GFXFormatBC1 ) return DDSFile::getSizeInBytes( mFormat, mTextureSize.x, mTextureSize.y, mMipLevels ); // Else we need to calculate the size ourselves. diff --git a/Engine/source/gfx/gfxTextureProfile.cpp b/Engine/source/gfx/gfxTextureProfile.cpp index 80a2fbceb..98a63439c 100644 --- a/Engine/source/gfx/gfxTextureProfile.cpp +++ b/Engine/source/gfx/gfxTextureProfile.cpp @@ -31,38 +31,58 @@ // Set up defaults... -GFX_ImplementTextureProfile(GFXDefaultRenderTargetProfile, - GFXTextureProfile::DiffuseMap, - GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::RenderTarget, + +GFX_ImplementTextureProfile(GFXRenderTargetProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::RenderTarget, GFXTextureProfile::NONE); -GFX_ImplementTextureProfile(GFXDefaultStaticDiffuseProfile, - GFXTextureProfile::DiffuseMap, - GFXTextureProfile::Static, +GFX_ImplementTextureProfile(GFXRenderTargetSRGBProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::RenderTarget | GFXTextureProfile::SRGB, GFXTextureProfile::NONE); -GFX_ImplementTextureProfile(GFXDefaultStaticNormalMapProfile, - GFXTextureProfile::NormalMap, - GFXTextureProfile::Static, +GFX_ImplementTextureProfile(GFXStaticTextureProfile, GFXTextureProfile::DiffuseMap, + GFXTextureProfile::Static, GFXTextureProfile::NONE); -GFX_ImplementTextureProfile(GFXDefaultStaticDXT5nmProfile, - GFXTextureProfile::NormalMap, - GFXTextureProfile::Static, - GFXTextureProfile::DXT5); -GFX_ImplementTextureProfile(GFXDefaultPersistentProfile, - GFXTextureProfile::DiffuseMap, - GFXTextureProfile::PreserveSize | GFXTextureProfile::Static | GFXTextureProfile::KeepBitmap, +GFX_ImplementTextureProfile(GFXStaticTextureSRGBProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::Static | GFXTextureProfile::SRGB, GFXTextureProfile::NONE); -GFX_ImplementTextureProfile(GFXSystemMemProfile, - GFXTextureProfile::DiffuseMap, +GFX_ImplementTextureProfile(GFXTexturePersistentProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::PreserveSize | GFXTextureProfile::Static | GFXTextureProfile::KeepBitmap, + GFXTextureProfile::NONE); +GFX_ImplementTextureProfile(GFXTexturePersistentSRGBProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::PreserveSize | GFXTextureProfile::Static | GFXTextureProfile::KeepBitmap | GFXTextureProfile::SRGB, + GFXTextureProfile::NONE); +GFX_ImplementTextureProfile(GFXSystemMemTextureProfile, + GFXTextureProfile::DiffuseMap, GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::SystemMemory, GFXTextureProfile::NONE); -GFX_ImplementTextureProfile(GFXDefaultZTargetProfile, - GFXTextureProfile::DiffuseMap, - GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::ZTarget | GFXTextureProfile::NoDiscard, +GFX_ImplementTextureProfile(GFXNormalMapProfile, + GFXTextureProfile::NormalMap, + GFXTextureProfile::Static, + GFXTextureProfile::NONE); +GFX_ImplementTextureProfile(GFXNormalMapBC3Profile, + GFXTextureProfile::NormalMap, + GFXTextureProfile::Static, + GFXTextureProfile::BC3); +GFX_ImplementTextureProfile(GFXNormalMapBC5Profile, + GFXTextureProfile::NormalMap, + GFXTextureProfile::Static, + GFXTextureProfile::BC5); +GFX_ImplementTextureProfile(GFXZTargetProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::ZTarget | GFXTextureProfile::NoDiscard, GFXTextureProfile::NONE); GFX_ImplementTextureProfile(GFXDynamicTextureProfile, GFXTextureProfile::DiffuseMap, GFXTextureProfile::Dynamic, GFXTextureProfile::NONE); +GFX_ImplementTextureProfile(GFXDynamicTextureSRGBProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::Dynamic | GFXTextureProfile::SRGB, + GFXTextureProfile::NONE); //----------------------------------------------------------------------------- diff --git a/Engine/source/gfx/gfxTextureProfile.h b/Engine/source/gfx/gfxTextureProfile.h index 270a41947..2fd866ab5 100644 --- a/Engine/source/gfx/gfxTextureProfile.h +++ b/Engine/source/gfx/gfxTextureProfile.h @@ -86,6 +86,7 @@ public: NoPadding = BIT(6), ///< Do not pad this texture if it's non pow2. KeepBitmap = BIT(7), ///< Always keep a copy of this texture's bitmap. (Potentially in addition to the API managed copy?) ZTarget = BIT(8), ///< This texture will be used as a Z target. + SRGB = BIT(9), ///< sRGB texture /// Track and pool textures of this type for reuse. /// @@ -94,15 +95,15 @@ public: /// the pool to contain unused textures which will remain /// in memory until a flush occurs. /// - Pooled = BIT(9), + Pooled = BIT(10), /// A hint that the device is not allowed to discard the content /// of a target texture after presentation or deactivated. /// /// This is mainly a depth buffer optimization. - NoDiscard = BIT(10), + NoDiscard = BIT(11), - /// Texture is managed by another process, thus should not be modified + NoModify = BIT(11) }; @@ -110,14 +111,17 @@ public: enum Compression { NONE, - DXT1, - DXT2, - DXT3, - DXT4, - DXT5, + BC1, + BC2, + BC3, + BC4, + BC5, }; GFXTextureProfile(const String &name, Types type, U32 flags, Compression compression = NONE); + // Equality operators + inline bool operator==(const GFXTextureProfile &in_Cmp) const { return (mName == in_Cmp.mName && mProfile == in_Cmp.mProfile); } + inline bool operator!=(const GFXTextureProfile &in_Cmp) const { return !(*this == in_Cmp); } // Accessors String getName() const { return mName; }; @@ -167,15 +171,16 @@ public: inline bool noMip() const { return testFlag(NoMipmap); } inline bool isPooled() const { return testFlag(Pooled); } inline bool canDiscard() const { return !testFlag(NoDiscard); } - inline bool canModify() const { return !testFlag(NoModify); } - + inline bool isSRGB() const { return testFlag(SRGB); } + //compare profile flags for equality + inline bool compareFlags(const GFXTextureProfile& in_Cmp) const{ return (mProfile == in_Cmp.mProfile); } private: /// These constants control the packing for the profile; if you add flags, types, or /// compression info then make sure these are giving enough bits! enum Constants { TypeBits = 2, - FlagBits = 11, + FlagBits = 12, CompressionBits = 3, }; @@ -203,23 +208,26 @@ private: #define GFX_DeclareTextureProfile(name) extern GFXTextureProfile name #define GFX_ImplementTextureProfile(name, type, flags, compression) GFXTextureProfile name(#name, type, flags, compression) -// Set up some defaults.. - +// Default Texture profiles // Texture we can render to. -GFX_DeclareTextureProfile(GFXDefaultRenderTargetProfile); -// Standard diffuse texture that stays in system memory. -GFX_DeclareTextureProfile(GFXDefaultPersistentProfile); -// Generic diffusemap. This works in most cases. -GFX_DeclareTextureProfile(GFXDefaultStaticDiffuseProfile); -// Generic normal map. -GFX_DeclareTextureProfile(GFXDefaultStaticNormalMapProfile); -// DXT5 swizzled normal map -GFX_DeclareTextureProfile(GFXDefaultStaticDXT5nmProfile); +GFX_DeclareTextureProfile(GFXRenderTargetProfile); +GFX_DeclareTextureProfile(GFXRenderTargetSRGBProfile); +// Standard static diffuse textures +GFX_DeclareTextureProfile(GFXStaticTextureProfile); +GFX_DeclareTextureProfile(GFXStaticTextureSRGBProfile); +// Standard static diffuse textures that are persistent in memory +GFX_DeclareTextureProfile(GFXTexturePersistentProfile); +GFX_DeclareTextureProfile(GFXTexturePersistentSRGBProfile); // Texture that resides in system memory - used to copy data to -GFX_DeclareTextureProfile(GFXSystemMemProfile); +GFX_DeclareTextureProfile(GFXSystemMemTextureProfile); +// normal map profiles +GFX_DeclareTextureProfile(GFXNormalMapProfile); +GFX_DeclareTextureProfile(GFXNormalMapBC3Profile); +GFX_DeclareTextureProfile(GFXNormalMapBC5Profile); // Depth buffer texture -GFX_DeclareTextureProfile(GFXDefaultZTargetProfile); +GFX_DeclareTextureProfile(GFXZTargetProfile); // Dynamic Texure GFX_DeclareTextureProfile(GFXDynamicTextureProfile); +GFX_DeclareTextureProfile(GFXDynamicTextureSRGBProfile); #endif diff --git a/Engine/source/gfx/gfxVertexColor.cpp b/Engine/source/gfx/gfxVertexColor.cpp index 1eebf2938..dd5fb6207 100644 --- a/Engine/source/gfx/gfxVertexColor.cpp +++ b/Engine/source/gfx/gfxVertexColor.cpp @@ -21,5 +21,6 @@ //----------------------------------------------------------------------------- #include "gfx/gfxVertexColor.h" +#include "core/color.h" -Swizzle *GFXVertexColor::mDeviceSwizzle = &Swizzles::null; +Swizzle *GFXVertexColor::mDeviceSwizzle = &Swizzles::null; \ No newline at end of file diff --git a/Engine/source/gfx/gfxVertexColor.h b/Engine/source/gfx/gfxVertexColor.h index 4e8620de8..8a8d08609 100644 --- a/Engine/source/gfx/gfxVertexColor.h +++ b/Engine/source/gfx/gfxVertexColor.h @@ -26,43 +26,48 @@ #ifndef _SWIZZLE_H_ #include "core/util/swizzle.h" #endif - - -class ColorI; - +#include "core/color.h" class GFXVertexColor { private: - U32 packedColorData; + U32 mPackedColorData; static Swizzle *mDeviceSwizzle; public: static void setSwizzle( Swizzle *val ) { mDeviceSwizzle = val; } - GFXVertexColor() : packedColorData( 0xFFFFFFFF ) {} // White with full alpha + GFXVertexColor() : mPackedColorData( 0xFFFFFFFF ) {} // White with full alpha GFXVertexColor( const ColorI &color ) { set( color ); } void set( U8 red, U8 green, U8 blue, U8 alpha = 255 ) { - packedColorData = red << 0 | green << 8 | blue << 16 | alpha << 24; - mDeviceSwizzle->InPlace( &packedColorData, sizeof( packedColorData ) ); + //we must set the color in linear space + LinearColorF linearColor = LinearColorF(ColorI(red, green, blue, alpha)); + mPackedColorData = linearColor.getRGBAPack(); + mDeviceSwizzle->InPlace( &mPackedColorData, sizeof( mPackedColorData ) ); } void set( const ColorI &color ) { - mDeviceSwizzle->ToBuffer( &packedColorData, (U8 *)&color, sizeof( packedColorData ) ); + //we must set the color in linear space + LinearColorF linearColor = LinearColorF(color); + mPackedColorData = linearColor.getRGBAPack(); + mDeviceSwizzle->InPlace(&mPackedColorData, sizeof(mPackedColorData)); } GFXVertexColor &operator=( const ColorI &color ) { set( color ); return *this; } - operator const U32 *() const { return &packedColorData; } - const U32& getPackedColorData() const { return packedColorData; } + operator const U32 *() const { return &mPackedColorData; } + const U32& getPackedColorData() const { return mPackedColorData; } - void getColor( ColorI *color ) const + void getColor( ColorI *outColor ) const { - mDeviceSwizzle->ToBuffer( color, &packedColorData, sizeof( packedColorData ) ); - } + ColorI linearColor; + mDeviceSwizzle->ToBuffer( &linearColor, &mPackedColorData, sizeof( mPackedColorData ) ); + //convert color back to srgb space + *outColor = linearColor.fromLinear(); + } }; #endif diff --git a/Engine/source/gfx/gl/gfxGLCubemap.cpp b/Engine/source/gfx/gl/gfxGLCubemap.cpp index 295b2c96f..91e951abc 100644 --- a/Engine/source/gfx/gl/gfxGLCubemap.cpp +++ b/Engine/source/gfx/gl/gfxGLCubemap.cpp @@ -28,6 +28,7 @@ #include "gfx/gfxTextureManager.h" #include "gfx/gfxCardProfile.h" #include "gfx/bitmap/ddsFile.h" +#include "gfx/bitmap/imageUtils.h" GLenum GFXGLCubemap::faceList[6] = @@ -71,11 +72,11 @@ void GFXGLCubemap::fillCubeTextures(GFXTexHandle* faces) U32 reqWidth = faces[0]->getWidth(); U32 reqHeight = faces[0]->getHeight(); GFXFormat regFaceFormat = faces[0]->getFormat(); - const bool isCompressed = isCompressedFormat(regFaceFormat); + const bool isCompressed = ImageUtil::isCompressedFormat(regFaceFormat); mWidth = reqWidth; mHeight = reqHeight; mFaceFormat = regFaceFormat; - mMipLevels = getMax( (U32)1, faces[0]->mMipLevels); + 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++) @@ -90,7 +91,7 @@ void GFXGLCubemap::fillCubeTextures(GFXTexHandle* faces) GFXGLTextureObject* glTex = static_cast(faces[i].getPointer()); if( isCompressed ) { - for( U32 mip = 0; mip < mMipLevels; ++mip ) + 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 ); @@ -136,26 +137,16 @@ void GFXGLCubemap::initStatic( DDSFile *dds ) AssertFatal( dds->isCubemap(), "GFXGLCubemap::initStatic - Got non-cubemap DDS file!" ); AssertFatal( dds->mSurfaces.size() == 6, "GFXGLCubemap::initStatic - DDS has less than 6 surfaces!" ); - // HACK: I cannot put the genie back in the bottle and assign a - // DDSFile pointer back to a Resource<>. - // - // So we do a second lookup which works out ok for now, but shows - // the weakness in the ResourceManager not having a common base - // reference type. - // - mDDSFile = ResourceManager::get().load( dds->getSourcePath() ); - AssertFatal( mDDSFile == dds, "GFXGLCubemap::initStatic - Couldn't find DDSFile resource!" ); - mWidth = dds->getWidth(); mHeight = dds->getHeight(); mFaceFormat = dds->getFormat(); - mMipLevels = dds->getMipLevels(); - + 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, mMipLevels - 1); + 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); @@ -173,12 +164,19 @@ void GFXGLCubemap::initStatic( DDSFile *dds ) continue; } + // convert to Z up + const U32 faceIndex = _zUpFaceIndex(i); + // Now loop thru the mip levels! - for (U32 mip = 0; mip < mMipLevels; ++mip) + for (U32 mip = 0; mip < mMipMapLevels; ++mip) { const U32 mipWidth = getMax( U32(1), mWidth >> mip ); const U32 mipHeight = getMax( U32(1), mHeight >> mip ); - glCompressedTexImage2D(faceList[i], mip, GFXGLTextureInternalFormat[mFaceFormat], mipWidth, mipHeight, 0, dds->getSurfaceSize(mip), dds->mSurfaces[i]->mMips[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]); } } } @@ -187,13 +185,13 @@ void GFXGLCubemap::initDynamic(U32 texSize, GFXFormat faceFormat) { mDynamicTexSize = texSize; mFaceFormat = faceFormat; - const bool isCompressed = isCompressedFormat(faceFormat); - mMipLevels = getMax( (U32)1, getMaxMipmaps( texSize, texSize, 1 ) ); + 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, mMipLevels - 1); + 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); @@ -204,9 +202,9 @@ void GFXGLCubemap::initDynamic(U32 texSize, GFXFormat faceFormat) for(U32 i = 0; i < 6; i++) { - if( isCompressedFormat(faceFormat) ) + if( ImageUtil::isCompressedFormat(faceFormat) ) { - for( U32 mip = 0; mip < mMipLevels; ++mip ) + for( U32 mip = 0; mip < mMipMapLevels; ++mip ) { const U32 mipSize = getMax( U32(1), texSize >> mip ); const U32 mipDataSize = getCompressedSurfaceSize( mFaceFormat, texSize, texSize, mip ); diff --git a/Engine/source/gfx/gl/gfxGLCubemap.h b/Engine/source/gfx/gl/gfxGLCubemap.h index 458043eb8..7477d4a32 100644 --- a/Engine/source/gfx/gl/gfxGLCubemap.h +++ b/Engine/source/gfx/gl/gfxGLCubemap.h @@ -46,7 +46,6 @@ public: // Convenience methods for GFXGLTextureTarget U32 getWidth() { return mWidth; } U32 getHeight() { return mHeight; } - U32 getNumMipLevels() { return mMipLevels; } U32 getHandle() { return mCubemap; } // GFXResource interface @@ -73,7 +72,6 @@ protected: // Self explanatory U32 mWidth; U32 mHeight; - U32 mMipLevels; GFXFormat mFaceFormat; GFXTexHandle mTextures[6]; ///< Keep refs to our textures for resurrection of static cubemaps diff --git a/Engine/source/gfx/gl/gfxGLDevice.cpp b/Engine/source/gfx/gl/gfxGLDevice.cpp index bc348671b..f41bfc832 100644 --- a/Engine/source/gfx/gl/gfxGLDevice.cpp +++ b/Engine/source/gfx/gl/gfxGLDevice.cpp @@ -180,6 +180,9 @@ void GFXGLDevice::initGLState() GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); + + //enable sRGB + glEnable(GL_FRAMEBUFFER_SRGB); } void GFXGLDevice::vsyncCallback() @@ -450,7 +453,7 @@ void GFXGLDevice::endSceneInternal() mCanCurrentlyRender = false; } -void GFXGLDevice::clear(U32 flags, ColorI color, F32 z, U32 stencil) +void GFXGLDevice::clear(U32 flags, const LinearColorF& color, F32 z, U32 stencil) { // Make sure we have flushed our render target state. _updateRenderTargets(); @@ -470,10 +473,7 @@ void GFXGLDevice::clear(U32 flags, ColorI color, F32 z, U32 stencil) glColorMask(true, true, true, true); glDepthMask(true); glStencilMask(0xFFFFFFFF); - - - ColorF c = color; - glClearColor(c.red, c.green, c.blue, c.alpha); + glClearColor(color.red, color.green, color.blue, color.alpha); glClearDepth(z); glClearStencil(stencil); @@ -581,7 +581,8 @@ void GFXGLDevice::drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 { preDrawPrimitive(); - vertexStart += mCurrentVB[0]->mBufferVertexOffset; + if(mCurrentVB[0]) + vertexStart += mCurrentVB[0]->mBufferVertexOffset; if(mDrawInstancesCount) glDrawArraysInstanced(GFXGLPrimType[primType], vertexStart, primCountToIndexCount(primType, primitiveCount), mDrawInstancesCount); @@ -629,7 +630,7 @@ void GFXGLDevice::setLightMaterialInternal(const GFXLightMaterial mat) // ONLY NEEDED ON FFP } -void GFXGLDevice::setGlobalAmbientInternal(ColorF color) +void GFXGLDevice::setGlobalAmbientInternal(LinearColorF color) { // ONLY NEEDED ON FFP } diff --git a/Engine/source/gfx/gl/gfxGLDevice.h b/Engine/source/gfx/gl/gfxGLDevice.h index f2bf4afe1..a271f9e2b 100644 --- a/Engine/source/gfx/gl/gfxGLDevice.h +++ b/Engine/source/gfx/gl/gfxGLDevice.h @@ -116,7 +116,7 @@ public: virtual GFXShader* createShader(); - virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ); + virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ); virtual bool beginSceneInternal(); virtual void endSceneInternal(); @@ -171,7 +171,7 @@ protected: virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable); virtual void setLightMaterialInternal(const GFXLightMaterial mat); - virtual void setGlobalAmbientInternal(ColorF color); + virtual void setGlobalAmbientInternal(LinearColorF color); /// @name State Initalization. /// @{ diff --git a/Engine/source/gfx/gl/gfxGLEnumTranslate.cpp b/Engine/source/gfx/gl/gfxGLEnumTranslate.cpp index 3a00a639f..bfed4f047 100644 --- a/Engine/source/gfx/gl/gfxGLEnumTranslate.cpp +++ b/Engine/source/gfx/gl/gfxGLEnumTranslate.cpp @@ -142,11 +142,17 @@ void GFXGLEnumTranslate::init() GFXGLTextureInternalFormat[GFXFormatD24X8] = GL_DEPTH24_STENCIL8; GFXGLTextureInternalFormat[GFXFormatD24S8] = GL_DEPTH24_STENCIL8; GFXGLTextureInternalFormat[GFXFormatR16G16B16A16] = GL_RGBA16; - GFXGLTextureInternalFormat[GFXFormatDXT1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - GFXGLTextureInternalFormat[GFXFormatDXT2] = GL_ZERO; - GFXGLTextureInternalFormat[GFXFormatDXT3] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - GFXGLTextureInternalFormat[GFXFormatDXT4] = GL_ZERO; - GFXGLTextureInternalFormat[GFXFormatDXT5] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + GFXGLTextureInternalFormat[GFXFormatBC1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + GFXGLTextureInternalFormat[GFXFormatBC2] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + GFXGLTextureInternalFormat[GFXFormatBC3] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + GFXGLTextureInternalFormat[GFXFormatBC4] = GL_COMPRESSED_RED_RGTC1; + GFXGLTextureInternalFormat[GFXFormatBC5] = GL_COMPRESSED_RG_RGTC2; + //sRGB + GFXGLTextureInternalFormat[GFXFormatR8G8B8_SRGB] = GL_SRGB8; + GFXGLTextureInternalFormat[GFXFormatR8G8B8A8_SRGB] = GL_SRGB8_ALPHA8; + GFXGLTextureInternalFormat[GFXFormatBC1_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; + GFXGLTextureInternalFormat[GFXFormatBC2_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; + GFXGLTextureInternalFormat[GFXFormatBC3_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; GFXGLTextureFormat[GFXFormatA8] = GL_RED; GFXGLTextureFormat[GFXFormatL8] = GL_RED; @@ -163,11 +169,17 @@ void GFXGLEnumTranslate::init() GFXGLTextureFormat[GFXFormatD24X8] = GL_DEPTH_STENCIL; GFXGLTextureFormat[GFXFormatD24S8] = GL_DEPTH_STENCIL; GFXGLTextureFormat[GFXFormatR16G16B16A16] = GL_RGBA; - GFXGLTextureFormat[GFXFormatDXT1] = GL_RGBA; - GFXGLTextureFormat[GFXFormatDXT2] = GL_ZERO; - GFXGLTextureFormat[GFXFormatDXT3] = GL_RGBA; - GFXGLTextureFormat[GFXFormatDXT4] = GL_ZERO; - GFXGLTextureFormat[GFXFormatDXT5] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC1] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC2] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC3] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC4] = GL_RED; + GFXGLTextureFormat[GFXFormatBC5] = GL_RG; + //sRGB + GFXGLTextureFormat[GFXFormatR8G8B8_SRGB] = GL_RGB; + GFXGLTextureFormat[GFXFormatR8G8B8A8_SRGB] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC1_SRGB] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC2_SRGB] = GL_RGBA; + GFXGLTextureFormat[GFXFormatBC3_SRGB] = GL_RGBA; GFXGLTextureType[GFXFormatA8] = GL_UNSIGNED_BYTE; GFXGLTextureType[GFXFormatL8] = GL_UNSIGNED_BYTE; @@ -184,13 +196,18 @@ void GFXGLEnumTranslate::init() GFXGLTextureType[GFXFormatD24X8] = GL_UNSIGNED_INT_24_8; GFXGLTextureType[GFXFormatD24S8] = GL_UNSIGNED_INT_24_8; GFXGLTextureType[GFXFormatR16G16B16A16] = GL_UNSIGNED_SHORT; - GFXGLTextureType[GFXFormatDXT1] = GL_UNSIGNED_BYTE; - GFXGLTextureType[GFXFormatDXT2] = GL_ZERO; - GFXGLTextureType[GFXFormatDXT3] = GL_UNSIGNED_BYTE; - GFXGLTextureType[GFXFormatDXT4] = GL_ZERO; - GFXGLTextureType[GFXFormatDXT5] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC1] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC2] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC3] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC4] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC5] = GL_UNSIGNED_BYTE; + // sRGB + GFXGLTextureType[GFXFormatR8G8B8_SRGB] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatR8G8B8A8_SRGB] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC1_SRGB] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC2_SRGB] = GL_UNSIGNED_BYTE; + GFXGLTextureType[GFXFormatBC3_SRGB] = GL_UNSIGNED_BYTE; - GFXGLTextureType[GFXFormatR8G8B8A8_SRGB] = GL_SRGB8_ALPHA8; static GLint Swizzle_GFXFormatA8[] = { GL_NONE, GL_NONE, GL_NONE, GL_RED }; static GLint Swizzle_GFXFormatL[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA }; diff --git a/Engine/source/gfx/gl/gfxGLShader.cpp b/Engine/source/gfx/gl/gfxGLShader.cpp index 0fa80f3a7..55f05543a 100644 --- a/Engine/source/gfx/gl/gfxGLShader.cpp +++ b/Engine/source/gfx/gl/gfxGLShader.cpp @@ -197,7 +197,7 @@ void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const PlaneF& fv) internalSet(handle, fv); } -void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const ColorF& fv) +void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const LinearColorF& fv) { internalSet(handle, fv); } @@ -423,17 +423,14 @@ bool GFXGLShader::_init() Vector macros; macros.merge( mMacros ); macros.merge( smGlobalMacros ); - - // Add the shader version to the macros. - const U32 mjVer = (U32)mFloor( mPixVersion ); - const U32 mnVer = (U32)( ( mPixVersion - F32( mjVer ) ) * 10.01f ); + macros.increment(); macros.last().name = "TORQUE_SM"; - macros.last().value = String::ToString( mjVer * 10 + mnVer ); + macros.last().value = 40; macros.increment(); macros.last().name = "TORQUE_VERTEX_SHADER"; - macros.last().value = ""; - + macros.last().value = ""; + // Default to true so we're "successful" if a vertex/pixel shader wasn't specified. bool compiledVertexShader = true; bool compiledPixelShader = true; diff --git a/Engine/source/gfx/gl/gfxGLShader.h b/Engine/source/gfx/gl/gfxGLShader.h index d87f4843e..80fa4d9d9 100644 --- a/Engine/source/gfx/gl/gfxGLShader.h +++ b/Engine/source/gfx/gl/gfxGLShader.h @@ -121,7 +121,7 @@ public: virtual void set(GFXShaderConstHandle* handle, const Point3F& fv); virtual void set(GFXShaderConstHandle* handle, const Point4F& fv); virtual void set(GFXShaderConstHandle* handle, const PlaneF& fv); - virtual void set(GFXShaderConstHandle* handle, const ColorF& fv); + virtual void set(GFXShaderConstHandle* handle, const LinearColorF& fv); virtual void set(GFXShaderConstHandle* handle, const S32 f); virtual void set(GFXShaderConstHandle* handle, const Point2I& fv); virtual void set(GFXShaderConstHandle* handle, const Point3I& fv); diff --git a/Engine/source/gfx/gl/gfxGLStateBlock.cpp b/Engine/source/gfx/gl/gfxGLStateBlock.cpp index 1a104ab27..4a9471a35 100644 --- a/Engine/source/gfx/gl/gfxGLStateBlock.cpp +++ b/Engine/source/gfx/gl/gfxGLStateBlock.cpp @@ -58,7 +58,13 @@ GFXGLStateBlock::GFXGLStateBlock(const GFXStateBlockDesc& desc) : glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]); glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]); glSamplerParameteri(id, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]); - if(static_cast< GFXGLDevice* >( GFX )->supportsAnisotropic() ) + + //compare modes + const bool comparison = ssd.samplerFunc != GFXCmpNever; + glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, comparison ? GL_COMPARE_R_TO_TEXTURE_ARB : GL_NONE ); + glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, GFXGLCmpFunc[ssd.samplerFunc]); + + if (static_cast< GFXGLDevice* >(GFX)->supportsAnisotropic()) glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, ssd.maxAnisotropy); mSamplersMap[ssd] = id; @@ -99,7 +105,7 @@ void GFXGLStateBlock::activate(const GFXGLStateBlock* oldState) #define STATE_CHANGE(state) (!oldState || oldState->mDesc.state != mDesc.state) #define TOGGLE_STATE(state, enum) if(mDesc.state) glEnable(enum); else glDisable(enum) -#define CHECK_TOGGLE_STATE(state, enum) if(!oldState || oldState->mDesc.state != mDesc.state) {if(mDesc.state) glEnable(enum); else glDisable(enum);} +#define CHECK_TOGGLE_STATE(state, enum) if(!oldState || oldState->mDesc.state != mDesc.state) if(mDesc.state) glEnable(enum); else glDisable(enum) // Blending CHECK_TOGGLE_STATE(blendEnable, GL_BLEND); diff --git a/Engine/source/gfx/gl/gfxGLTextureManager.cpp b/Engine/source/gfx/gl/gfxGLTextureManager.cpp index 750dc1c92..636426240 100644 --- a/Engine/source/gfx/gl/gfxGLTextureManager.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureManager.cpp @@ -92,8 +92,10 @@ void GFXGLTextureManager::innerCreateTexture( GFXGLTextureObject *retTex, bool forceMips) { // No 24 bit formats. They trigger various oddities because hardware (and Apple's drivers apparently...) don't natively support them. - if(format == GFXFormatR8G8B8) + if (format == GFXFormatR8G8B8) format = GFXFormatR8G8B8A8; + else if (format == GFXFormatR8G8B8_SRGB) + format = GFXFormatR8G8B8A8_SRGB; retTex->mFormat = format; retTex->mIsZombie = false; @@ -110,7 +112,7 @@ void GFXGLTextureManager::innerCreateTexture( GFXGLTextureObject *retTex, // Create it // @todo OPENGL - Creating mipmaps for compressed formats. Not supported on OpenGL ES and bugged on AMD. We use mipmaps present on file. - if( forceMips && !retTex->mIsNPoT2 && !isCompressedFormat(format) ) + if( forceMips && !retTex->mIsNPoT2 && !ImageUtil::isCompressedFormat(format) ) { retTex->mMipLevels = numMipLevels > 1 ? numMipLevels : 0; } @@ -159,7 +161,7 @@ void GFXGLTextureManager::innerCreateTexture( GFXGLTextureObject *retTex, { //If it wasn't for problems on amd drivers this next part could be really simplified and we wouldn't need to go through manually creating our //mipmap pyramid and instead just use glGenerateMipmap - if(isCompressedFormat(format)) + if(ImageUtil::isCompressedFormat(format)) { AssertFatal(binding == GL_TEXTURE_2D, "GFXGLTextureManager::innerCreateTexture - Only compressed 2D textures are supported"); @@ -226,40 +228,32 @@ void GFXGLTextureManager::innerCreateTexture( GFXGLTextureObject *retTex, // loadTexture - GBitmap //----------------------------------------------------------------------------- -static void _fastTextureLoad(GFXGLTextureObject* texture, GBitmap* pDL) +static void _textureUpload(const S32 width, const S32 height,const S32 bytesPerPixel,const GFXGLTextureObject* texture, const GFXFormat fmt, const U8* data,const S32 mip=0, Swizzle *pSwizzle = NULL) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->getBuffer()); - U32 bufSize = pDL->getWidth(0) * pDL->getHeight(0) * pDL->getBytesPerPixel(); + U32 bufSize = width * height * bytesPerPixel; glBufferData(GL_PIXEL_UNPACK_BUFFER, bufSize, NULL, GL_STREAM_DRAW); - - if(pDL->getFormat() == GFXFormatR8G8B8A8 || pDL->getFormat() == GFXFormatR8G8B8X8) + + if(pSwizzle) { PROFILE_SCOPE(Swizzle32_Upload); U8* pboMemory = (U8*)dMalloc(bufSize); - GFX->getDeviceSwizzle32()->ToBuffer(pboMemory, pDL->getBits(0), bufSize); - glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, bufSize, pboMemory ); + pSwizzle->ToBuffer(pboMemory, data, bufSize); + glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, bufSize, pboMemory); dFree(pboMemory); } else { PROFILE_SCOPE(SwizzleNull_Upload); - glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, bufSize, pDL->getBits(0) ); + glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, bufSize, data); } - - if(texture->getBinding() == GL_TEXTURE_2D) - glTexSubImage2D(texture->getBinding(), 0, 0, 0, pDL->getWidth(0), pDL->getHeight(0), GFXGLTextureFormat[pDL->getFormat()], GFXGLTextureType[pDL->getFormat()], NULL); - else - glTexSubImage1D(texture->getBinding(), 0, 0, (pDL->getWidth(0) > 1 ? pDL->getWidth(0) : pDL->getHeight(0)), GFXGLTextureFormat[pDL->getFormat()], GFXGLTextureType[pDL->getFormat()], NULL); - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); -} -static void _slowTextureLoad(GFXGLTextureObject* texture, GBitmap* pDL) -{ - if(texture->getBinding() == GL_TEXTURE_2D) - glTexSubImage2D(texture->getBinding(), 0, 0, 0, pDL->getWidth(0), pDL->getHeight(0), GFXGLTextureFormat[pDL->getFormat()], GFXGLTextureType[pDL->getFormat()], pDL->getBits(0)); - else - glTexSubImage1D(texture->getBinding(), 0, 0, (pDL->getWidth(0) > 1 ? pDL->getWidth(0) : pDL->getHeight(0)), GFXGLTextureFormat[pDL->getFormat()], GFXGLTextureType[pDL->getFormat()], pDL->getBits(0)); + if (texture->getBinding() == GL_TEXTURE_2D) + glTexSubImage2D(texture->getBinding(), mip, 0, 0, width, height, GFXGLTextureFormat[fmt], GFXGLTextureType[fmt], NULL); + else + glTexSubImage1D(texture->getBinding(), mip, 0, (width > 1 ? width : height), GFXGLTextureFormat[fmt], GFXGLTextureType[fmt], NULL); + + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL) @@ -276,27 +270,22 @@ bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL) // No 24bit formats. if(pDL->getFormat() == GFXFormatR8G8B8) pDL->setFormat(GFXFormatR8G8B8A8); + else if (pDL->getFormat() == GFXFormatR8G8B8_SRGB) + pDL->setFormat(GFXFormatR8G8B8A8_SRGB); // Bind to edit PRESERVE_TEXTURE(texture->getBinding()); glBindTexture(texture->getBinding(), texture->getHandle()); - texture->mFormat = pDL->getFormat(); - if(pDL->getFormat() == GFXFormatR8G8B8A8 || pDL->getFormat() == GFXFormatR8G8B8X8) - _fastTextureLoad(texture, pDL); - else - _slowTextureLoad(texture, pDL); + _textureUpload(pDL->getWidth(),pDL->getHeight(),pDL->getBytesPerPixel(),texture,pDL->getFormat(), pDL->getBits(), 0); - if(texture->getMipLevels() != 1) - glGenerateMipmap(texture->getBinding()); + if(!ImageUtil::isCompressedFormat(pDL->getFormat())) + glGenerateMipmap(texture->getBinding()); return true; } bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds) { - PROFILE_SCOPE(GFXGLTextureManager_loadTextureDDS); - - AssertFatal(!(dds->mFormat == GFXFormatDXT2 || dds->mFormat == GFXFormatDXT4), "GFXGLTextureManager::_loadTexture - OpenGL does not support DXT2 or DXT4 compressed textures"); GFXGLTextureObject* texture = static_cast(aTexture); AssertFatal(texture->getBinding() == GL_TEXTURE_2D, @@ -307,42 +296,36 @@ bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds) PRESERVE_TEXTURE(texture->getBinding()); glBindTexture(texture->getBinding(), texture->getHandle()); - texture->mFormat = dds->mFormat; U32 numMips = dds->mSurfaces[0]->mMips.size(); + const GFXFormat fmt = texture->mFormat; for(U32 i = 0; i < numMips; i++) { PROFILE_SCOPE(GFXGLTexMan_loadSurface); - if(isCompressedFormat(dds->mFormat)) + if(ImageUtil::isCompressedFormat(texture->mFormat)) { - if((!isPow2(dds->getWidth()) || !isPow2(dds->getHeight()))) + if((!isPow2(dds->getWidth()) || !isPow2(dds->getHeight())) && GFX->getCardProfiler()->queryProfile("GL::Workaround::noCompressedNPoTTextures")) { - U32 squishFlag = squish::kDxt1; - switch (dds->mFormat) - { - case GFXFormatDXT3: - squishFlag = squish::kDxt3; - break; - case GFXFormatDXT5: - squishFlag = squish::kDxt5; - break; - default: - break; - } U8* uncompressedTex = new U8[dds->getWidth(i) * dds->getHeight(i) * 4]; - squish::DecompressImage(uncompressedTex, dds->getWidth(i), dds->getHeight(i), dds->mSurfaces[0]->mMips[i], squishFlag); + ImageUtil::decompress(dds->mSurfaces[0]->mMips[i],uncompressedTex, dds->getWidth(i), dds->getHeight(i), fmt); glTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GL_RGBA, GL_UNSIGNED_BYTE, uncompressedTex); delete[] uncompressedTex; } else - glCompressedTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GFXGLTextureInternalFormat[dds->mFormat], dds->getSurfaceSize(dds->getHeight(), dds->getWidth(), i), dds->mSurfaces[0]->mMips[i]); + glCompressedTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GFXGLTextureInternalFormat[fmt], dds->getSurfaceSize(dds->getHeight(), dds->getWidth(), i), dds->mSurfaces[0]->mMips[i]); } else - glTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GFXGLTextureFormat[dds->mFormat], GFXGLTextureType[dds->mFormat], dds->mSurfaces[0]->mMips[i]); + { + Swizzle *pSwizzle = NULL; + if (fmt == GFXFormatR8G8B8A8 || fmt == GFXFormatR8G8B8X8 || fmt == GFXFormatR8G8B8A8_SRGB || fmt == GFXFormatR8G8B8A8_LINEAR_FORCE || fmt == GFXFormatB8G8R8A8) + pSwizzle = &Swizzles::bgra; + + _textureUpload(dds->getWidth(i), dds->getHeight(i),dds->mBytesPerPixel, texture, fmt, dds->mSurfaces[0]->mMips[i],i, pSwizzle); + } } - if(numMips !=1 && !isCompressedFormat(dds->mFormat)) + if(numMips !=1 && !ImageUtil::isCompressedFormat(texture->mFormat)) glGenerateMipmap(texture->getBinding()); return true; diff --git a/Engine/source/gfx/gl/gfxGLTextureObject.cpp b/Engine/source/gfx/gl/gfxGLTextureObject.cpp index 0cbad6b03..9b01a201e 100644 --- a/Engine/source/gfx/gl/gfxGLTextureObject.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureObject.cpp @@ -57,7 +57,7 @@ GFXGLTextureObject::~GFXGLTextureObject() GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect) { - AssertFatal(mBinding != GL_TEXTURE_3D, "GFXGLTextureObject::lock - We don't support locking 3D textures yet"); + //AssertFatal(mBinding != GL_TEXTURE_3D, "GFXGLTextureObject::lock - We don't support locking 3D textures yet"); U32 width = mTextureSize.x >> mipLevel; U32 height = mTextureSize.y >> mipLevel; @@ -76,7 +76,7 @@ GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect) mLockedRect.pitch = mLockedRectRect.extent.x * mBytesPerTexel; // CodeReview [ags 12/19/07] This one texel boundary is necessary to keep the clipmap code from crashing. Figure out why. - U32 size = (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * mBytesPerTexel; + U32 size = (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * getDepth() * mBytesPerTexel; AssertFatal(!mFrameAllocatorMark && !mFrameAllocatorPtr, ""); mFrameAllocatorMark = FrameAllocator::getWaterMark(); mFrameAllocatorPtr = (U8*)FrameAllocator::alloc( size ); @@ -103,8 +103,11 @@ void GFXGLTextureObject::unlock(U32 mipLevel) glBindTexture(mBinding, mHandle); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mBuffer); glBufferData(GL_PIXEL_UNPACK_BUFFER, (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * mBytesPerTexel, mFrameAllocatorPtr, GL_STREAM_DRAW); - - if(mBinding == GL_TEXTURE_2D) + S32 z = getDepth(); + if (mBinding == GL_TEXTURE_3D) + glTexSubImage3D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, z, + mLockedRectRect.extent.x, mLockedRectRect.extent.y, z, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL); + else if(mBinding == GL_TEXTURE_2D) glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL); else if(mBinding == GL_TEXTURE_1D) @@ -146,12 +149,13 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp) // check format limitations // at the moment we only support RGBA for the source (other 4 byte formats should // be easy to add though) - AssertFatal(mFormat == GFXFormatR8G8B8A8, "GFXGLTextureObject::copyToBmp - invalid format"); - AssertFatal(bmp->getFormat() == GFXFormatR8G8B8A8 || bmp->getFormat() == GFXFormatR8G8B8, "GFXGLTextureObject::copyToBmp - invalid format"); - if(mFormat != GFXFormatR8G8B8A8) + AssertFatal(mFormat == GFXFormatR8G8B8A8 || mFormat == GFXFormatR8G8B8A8_SRGB , "GFXGLTextureObject::copyToBmp - invalid format"); + AssertFatal(bmp->getFormat() == GFXFormatR8G8B8A8 || bmp->getFormat() == GFXFormatR8G8B8 || bmp->getFormat() == GFXFormatR8G8B8A8_SRGB, "GFXGLTextureObject::copyToBmp - invalid format"); + + if(mFormat != GFXFormatR8G8B8A8 && mFormat != GFXFormatR8G8B8A8_SRGB) return false; - if(bmp->getFormat() != GFXFormatR8G8B8A8 && bmp->getFormat() != GFXFormatR8G8B8) + if(bmp->getFormat() != GFXFormatR8G8B8A8 && bmp->getFormat() != GFXFormatR8G8B8 && bmp->getFormat() != GFXFormatR8G8B8A8_SRGB ) return false; AssertFatal(bmp->getWidth() == getWidth(), "GFXGLTextureObject::copyToBmp - invalid size"); @@ -253,7 +257,7 @@ U8* GFXGLTextureObject::getTextureData( U32 mip ) AssertFatal( mMipLevels, ""); mip = (mip < mMipLevels) ? mip : 0; - const U32 dataSize = isCompressedFormat(mFormat) + const U32 dataSize = ImageUtil::isCompressedFormat(mFormat) ? getCompressedSurfaceSize( mFormat, mTextureSize.x, mTextureSize.y, mip ) : (mTextureSize.x >> mip) * (mTextureSize.y >> mip) * mBytesPerTexel; @@ -261,7 +265,7 @@ U8* GFXGLTextureObject::getTextureData( U32 mip ) PRESERVE_TEXTURE(mBinding); glBindTexture(mBinding, mHandle); - if( isCompressedFormat(mFormat) ) + if( ImageUtil::isCompressedFormat(mFormat) ) glGetCompressedTexImage( mBinding, mip, data ); else glGetTexImage(mBinding, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], data); diff --git a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp index 9eec1f988..35011c357 100644 --- a/Engine/source/gfx/gl/gfxGLTextureTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureTarget.cpp @@ -103,7 +103,7 @@ public: virtual U32 getWidth() { return mTex->getWidth(); } virtual U32 getHeight() { return mTex->getHeight(); } virtual U32 getDepth() { return 0; } - virtual bool hasMips() { return mTex->getNumMipLevels() != 1; } + virtual bool hasMips() { return mTex->getMipMapLevels() != 1; } virtual GLenum getBinding() { return GFXGLCubemap::getEnumForFaceNumber(mFace); } virtual GFXFormat getFormat() { return mTex->getFormat(); } virtual bool isCompatible(const GFXGLTextureObject* tex) @@ -162,7 +162,7 @@ void _GFXGLTextureTargetFBOImpl::applyState() PRESERVE_FRAMEBUFFER(); glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); - + glEnable(GL_FRAMEBUFFER_SRGB); bool drawbufs[16]; int bufsize = 0; for (int i = 0; i < 16; i++) diff --git a/Engine/source/gfx/gl/gfxGLUtils.h b/Engine/source/gfx/gl/gfxGLUtils.h index 35d1722bb..2cb6450a6 100644 --- a/Engine/source/gfx/gl/gfxGLUtils.h +++ b/Engine/source/gfx/gl/gfxGLUtils.h @@ -26,6 +26,7 @@ #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) { @@ -59,27 +60,10 @@ inline GLenum minificationFilter(U32 minFilter, U32 mipFilter, U32 /*mipLevels*/ } } -// Check if format is compressed format. -// Even though dxt2/4 are not supported, they are included because they are a compressed format. -// Assert checks on supported formats are done elsewhere. -inline bool isCompressedFormat( GFXFormat format ) -{ - bool compressed = false; - if(format == GFXFormatDXT1 || format == GFXFormatDXT2 - || format == GFXFormatDXT3 - || format == GFXFormatDXT4 - || format == GFXFormatDXT5 ) - { - compressed = true; - } - - return compressed; -} - //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(!isCompressedFormat(format)) + if(!ImageUtil::isCompressedFormat(format)) return 0; // Bump by the mip level. @@ -87,7 +71,7 @@ inline U32 getCompressedSurfaceSize(GFXFormat format,U32 width, U32 height, U32 width = getMax(U32(1), width >> mipLevel); U32 sizeMultiple = 0; - if(format == GFXFormatDXT1) + if(format == GFXFormatBC1 || format == GFXFormatBC1_SRGB) sizeMultiple = 8; else sizeMultiple = 16; diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp index c02339777..36a73c854 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.cpp +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.cpp @@ -36,8 +36,8 @@ GFX_ImplementTextureProfile( BackBufferDepthProfile, GFXTextureProfile::NONE ); GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d) - : GFXWindowTarget(win), mDevice(d), mContext(NULL), mCopyFBO(0) - , mFullscreenContext(NULL), mBackBufferFBO(0), mSecondaryWindow(false) + : GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL) + , mCopyFBO(0), mBackBufferFBO(0) { win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal); } @@ -52,14 +52,7 @@ GFXGLWindowTarget::~GFXGLWindowTarget() void GFXGLWindowTarget::resetMode() { - // Do some validation... - bool fullscreen = mWindow->getVideoMode().fullScreen; - if (fullscreen && mSecondaryWindow) - { - AssertFatal(false, "GFXGLWindowTarget::resetMode - Cannot go fullscreen with secondary window!"); - } - - if(fullscreen != mWindow->isFullscreen()) + if(mWindow->getVideoMode().fullScreen != mWindow->isFullscreen()) { _teardownCurrentMode(); _setupNewMode(); @@ -118,9 +111,10 @@ void GFXGLWindowTarget::resolveTo(GFXTextureObject* obj) inline void GFXGLWindowTarget::_setupAttachments() { glBindFramebuffer( GL_FRAMEBUFFER, mBackBufferFBO); + glEnable(GL_FRAMEBUFFER_SRGB); GFXGL->getOpenglCache()->setCacheBinded(GL_FRAMEBUFFER, mBackBufferFBO); const Point2I dstSize = getSize(); - mBackBufferColorTex.set(dstSize.x, dstSize.y, getFormat(), &PostFxTargetProfile, "backBuffer"); + mBackBufferColorTex.set(dstSize.x, dstSize.y, getFormat(), &GFXRenderTargetSRGBProfile, "backBuffer"); GFXGLTextureObject *color = static_cast(mBackBufferColorTex.getPointer()); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color->getHandle(), 0); mBackBufferDepthTex.set(dstSize.x, dstSize.y, GFXFormatD24S8, &BackBufferDepthProfile, "backBuffer"); diff --git a/Engine/source/gfx/gl/gfxGLWindowTarget.h b/Engine/source/gfx/gl/gfxGLWindowTarget.h index 10f1f0cc8..9b0936fc7 100644 --- a/Engine/source/gfx/gl/gfxGLWindowTarget.h +++ b/Engine/source/gfx/gl/gfxGLWindowTarget.h @@ -39,7 +39,7 @@ public: virtual GFXFormat getFormat() { // TODO: Fix me! - return GFXFormatR8G8B8A8; + return GFXFormatR8G8B8A8_SRGB; } void makeActive(); virtual bool present(); @@ -50,9 +50,6 @@ public: virtual void resolveTo(GFXTextureObject* obj); void _onAppSignal(WindowId wnd, S32 event); - - // create pixel format for the window - void createPixelFormat(); private: friend class GFXGLDevice; @@ -61,8 +58,6 @@ private: GFXTexHandle mBackBufferColorTex, mBackBufferDepthTex; Point2I size; GFXDevice* mDevice; - /// Is this a secondary window - bool mSecondaryWindow; void* mContext; void* mFullscreenContext; void _teardownCurrentMode(); diff --git a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp index 9eaf0c68d..3f3245c91 100644 --- a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp +++ b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp @@ -86,6 +86,7 @@ void GFXGLDevice::enumerateAdapters( Vector &adapterList ) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); SDL_GLContext tempContext = SDL_GL_CreateContext( tempWindow ); if( !tempContext ) @@ -191,21 +192,19 @@ U32 GFXGLDevice::getTotalVideoMemory() GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window ) { - GFXGLWindowTarget* ggwt = new GFXGLWindowTarget(window, this); + AssertFatal(!mContext, "This GFXGLDevice is already assigned to a window"); + + GFXGLWindowTarget* ggwt = 0; + if( !mContext ) + { + // no context, init the device now + init(window->getVideoMode(), window); + ggwt = new GFXGLWindowTarget(window, this); + ggwt->registerResourceWithDevice(this); + ggwt->mContext = mContext; + } - //first window - if (!mContext) - { - init(window->getVideoMode(), window); - ggwt->mSecondaryWindow = false; - } - else - ggwt->mSecondaryWindow = true; - - ggwt->registerResourceWithDevice(this); - ggwt->mContext = mContext; - - return ggwt; + return ggwt; } GFXFence* GFXGLDevice::_createPlatformSpecificFence() diff --git a/Engine/source/gfx/gl/tGL/tGL.cpp b/Engine/source/gfx/gl/tGL/tGL.cpp index de412ca19..b13fec60a 100644 --- a/Engine/source/gfx/gl/tGL/tGL.cpp +++ b/Engine/source/gfx/gl/tGL/tGL.cpp @@ -41,12 +41,7 @@ namespace GL void gglPerformExtensionBinds(void *context) { - #ifdef TORQUE_OS_WIN - if (!gladLoadWGL(wglGetCurrentDC())) - { - AssertFatal(false, "Unable to load GLAD WGL extensions. Make sure your OpenGL drivers are up to date!"); - } - #endif + } } diff --git a/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp b/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp index f391f511b..eaf7d1449 100644 --- a/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp +++ b/Engine/source/gfx/gl/win32/gfxGLDevice.win.cpp @@ -255,6 +255,14 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window ) HDC hdcGL = GetDC( hwnd ); AssertFatal( hdcGL != NULL, "Failed to create device context" ); + // Create pixel format descriptor... + PIXELFORMATDESCRIPTOR pfd; + CreatePixelFormat( &pfd, 32, 0, 0, false ); // 32 bit color... We do not need depth or stencil, OpenGL renders into a FBO and then copy the image to window + if( !SetPixelFormat( hdcGL, ChoosePixelFormat( hdcGL, &pfd ), &pfd ) ) + { + AssertFatal( false, "GFXGLDevice::init - cannot get the one and only pixel format we check for." ); + } + int OGL_MAJOR = 3; int OGL_MINOR = 2; @@ -269,7 +277,7 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window ) if (!wglMakeCurrent(hdcGL, tempGLRC)) AssertFatal(false, "Couldn't make temp GL context."); - if( gglHasWExtension( ARB_create_context) ) + if( gglHasWExtension(hdcGL, ARB_create_context) ) { int const create_attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, OGL_MAJOR, @@ -322,21 +330,13 @@ U32 GFXGLDevice::getTotalVideoMemory() //------------------------------------------------------------------------------ -GFXWindowTarget *GFXGLDevice::allocWindowTarget(PlatformWindow *window) +GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window ) { + AssertFatal(!mContext, ""); + + init(window->getVideoMode(), window); GFXGLWindowTarget *ggwt = new GFXGLWindowTarget(window, this); ggwt->registerResourceWithDevice(this); - ggwt->createPixelFormat(); - - //first window - if (!mContext) - { - init(window->getVideoMode(), window); - ggwt->mSecondaryWindow = false; - } - else - ggwt->mSecondaryWindow = true; - ggwt->mContext = mContext; AssertFatal(ggwt->mContext, "GFXGLDevice::allocWindowTarget - failed to allocate window target!"); @@ -364,22 +364,6 @@ void GFXGLWindowTarget::_setupNewMode() { } -void GFXGLWindowTarget::createPixelFormat() -{ - HWND hwnd = GETHWND(mWindow); - // Create a device context - HDC hdcGL = GetDC(hwnd); - AssertFatal(hdcGL != NULL, "GFXGLWindowTarget::createPixelFormat() - Failed to create device context"); - - // Create pixel format descriptor... - PIXELFORMATDESCRIPTOR pfd; - CreatePixelFormat(&pfd, 32, 0, 0, false); // 32 bit color... We do not need depth or stencil, OpenGL renders into a FBO and then copy the image to window - if (!SetPixelFormat(hdcGL, ChoosePixelFormat(hdcGL, &pfd), &pfd)) - { - AssertFatal(false, "GFXGLWindowTarget::createPixelFormat() - cannot get the one and only pixel format we check for."); - } -} - void GFXGLWindowTarget::_makeContextCurrent() { HWND hwnd = GETHWND(getWindow()); diff --git a/Engine/source/gfx/primBuilder.cpp b/Engine/source/gfx/primBuilder.cpp index 0c661a8e8..f47cb116f 100644 --- a/Engine/source/gfx/primBuilder.cpp +++ b/Engine/source/gfx/primBuilder.cpp @@ -301,9 +301,9 @@ void color( const ColorI &inColor ) mCurColor = inColor; } -void color( const ColorF &inColor ) +void color( const LinearColorF &inColor ) { - mCurColor = inColor; + mCurColor = LinearColorF(inColor).toColorI(); } void color3i( U8 red, U8 green, U8 blue ) diff --git a/Engine/source/gfx/primBuilder.h b/Engine/source/gfx/primBuilder.h index 07fc2b007..6132a417e 100644 --- a/Engine/source/gfx/primBuilder.h +++ b/Engine/source/gfx/primBuilder.h @@ -69,7 +69,7 @@ namespace PrimBuild inline void vertex3i( S32 x, S32 y, S32 z ) { vertex3f((F32)x, (F32)y, (F32)z); } void color( const ColorI & ); - void color( const ColorF & ); + void color( const LinearColorF & ); void color3i( U8 red, U8 green, U8 blue ); void color4i( U8 red, U8 green, U8 blue, U8 alpha ); void color3f( F32 red, F32 green, F32 blue ); diff --git a/Engine/source/gfx/sim/cubemapData.cpp b/Engine/source/gfx/sim/cubemapData.cpp index 2d0100c77..c967bf2c3 100644 --- a/Engine/source/gfx/sim/cubemapData.cpp +++ b/Engine/source/gfx/sim/cubemapData.cpp @@ -100,7 +100,7 @@ void CubemapData::createMap() { if( !mCubeFaceFile[i].isEmpty() ) { - if(!mCubeFace[i].set(mCubeFaceFile[i], &GFXDefaultStaticDiffuseProfile, avar("%s() - mCubeFace[%d] (line %d)", __FUNCTION__, i, __LINE__) )) + if(!mCubeFace[i].set(mCubeFaceFile[i], &GFXStaticTextureSRGBProfile, avar("%s() - mCubeFace[%d] (line %d)", __FUNCTION__, i, __LINE__) )) { Con::errorf("CubemapData::createMap - Failed to load texture '%s'", mCubeFaceFile[i].c_str()); initSuccess = false; @@ -123,7 +123,7 @@ void CubemapData::updateFaces() { if( !mCubeFaceFile[i].isEmpty() ) { - if(!mCubeFace[i].set(mCubeFaceFile[i], &GFXDefaultStaticDiffuseProfile, avar("%s() - mCubeFace[%d] (line %d)", __FUNCTION__, i, __LINE__) )) + if(!mCubeFace[i].set(mCubeFaceFile[i], &GFXStaticTextureProfile, avar("%s() - mCubeFace[%d] (line %d)", __FUNCTION__, i, __LINE__) )) { initSuccess = false; Con::errorf("CubemapData::createMap - Failed to load texture '%s'", mCubeFaceFile[i].c_str()); diff --git a/Engine/source/gfx/sim/debugDraw.cpp b/Engine/source/gfx/sim/debugDraw.cpp index cfa6bf47e..3bb149f3b 100644 --- a/Engine/source/gfx/sim/debugDraw.cpp +++ b/Engine/source/gfx/sim/debugDraw.cpp @@ -139,7 +139,7 @@ void DebugDrawer::setupStateBlocks() mRenderAlpha = GFX->createStateBlock(d); } -void DebugDrawer::drawBoxOutline(const Point3F &a, const Point3F &b, const ColorF &color) +void DebugDrawer::drawBoxOutline(const Point3F &a, const Point3F &b, const LinearColorF &color) { Point3F point0(a.x, a.y, a.z); Point3F point1(a.x, b.y, a.z); @@ -170,7 +170,7 @@ void DebugDrawer::drawBoxOutline(const Point3F &a, const Point3F &b, const Color drawLine(point3, point7, color); } -void DebugDrawer::drawTransformedBoxOutline(const Point3F &a, const Point3F &b, const ColorF &color, const MatrixF& transform) +void DebugDrawer::drawTransformedBoxOutline(const Point3F &a, const Point3F &b, const LinearColorF &color, const MatrixF& transform) { Point3F point0(a.x, a.y, a.z); Point3F point1(a.x, b.y, a.z); @@ -234,16 +234,23 @@ void DebugDrawer::render(bool clear) // Set up the state block... GFXStateBlockRef currSB; - if(p->type==DebugPrim::Capsule){ + if(p->type==DebugPrim::Capsule) + { currSB = mRenderAlpha; - }else if(p->useZ){ + } + else if(p->useZ) + { currSB = mRenderZOnSB; - }else{ + } + else + { currSB = mRenderZOffSB; } + GFX->setStateBlock( currSB ); Point3F d; + const ColorI color = p->color.toColorI(); switch(p->type) { @@ -265,20 +272,23 @@ void DebugDrawer::render(bool clear) Point3F &start = p->a, &end = p->b; Point3F direction = end - start; F32 length = direction.len(); - if( length>ARROW_LENGTH ){ + if( length>ARROW_LENGTH ) + { //cylinder with arrow on end direction *= (1.0f/length); Point3F baseArrow = end - (direction*ARROW_LENGTH); - GFX->getDrawUtil()->drawCone(currSB->getDesc(), baseArrow, end, ARROW_RADIUS, p->color); - GFX->getDrawUtil()->drawCylinder(currSB->getDesc(), start, baseArrow, CYLINDER_RADIUS, p->color); - }else if( length>0 ){ + GFX->getDrawUtil()->drawCone(currSB->getDesc(), baseArrow, end, ARROW_RADIUS, color); + GFX->getDrawUtil()->drawCylinder(currSB->getDesc(), start, baseArrow, CYLINDER_RADIUS, color); + } + else if( length>0 ) + { //short, so just draw arrow - GFX->getDrawUtil()->drawCone(currSB->getDesc(), start, end, ARROW_RADIUS, p->color); + GFX->getDrawUtil()->drawCone(currSB->getDesc(), start, end, ARROW_RADIUS, color); } } break; case DebugPrim::Capsule: - GFX->getDrawUtil()->drawCapsule(currSB->getDesc(), p->a, p->b.x, p->b.y, p->color); + GFX->getDrawUtil()->drawCapsule(currSB->getDesc(), p->a, p->b.x, p->b.y, color); break; case DebugPrim::OutlinedText: { @@ -288,26 +298,26 @@ void DebugDrawer::render(bool clear) { GFX->setClipRect(GFX->getViewport()); Point2I where = Point2I(result.x, result.y); - - GFX->getDrawUtil()->setBitmapModulation(p->color2); + //only switch statement that uses p->color2 + GFX->getDrawUtil()->setBitmapModulation(p->color2.toColorI()); GFX->getDrawUtil()->drawText(mFont, Point2I(where.x-1, where.y), p->mText); GFX->getDrawUtil()->drawText(mFont, Point2I(where.x+1, where.y), p->mText); GFX->getDrawUtil()->drawText(mFont, Point2I(where.x, where.y-1), p->mText); GFX->getDrawUtil()->drawText(mFont, Point2I(where.x, where.y+1), p->mText); - GFX->getDrawUtil()->setBitmapModulation(p->color); + GFX->getDrawUtil()->setBitmapModulation(color); GFX->getDrawUtil()->drawText(mFont, where, p->mText); } } break; case DebugPrim::Box: d = p->a - p->b; - GFX->getDrawUtil()->drawCube(currSB->getDesc(), d * 0.5, (p->a + p->b) * 0.5, p->color); + GFX->getDrawUtil()->drawCube(currSB->getDesc(), d * 0.5, (p->a + p->b) * 0.5, color); break; case DebugPrim::Line: PrimBuild::begin( GFXLineStrip, 2); - PrimBuild::color(p->color); + PrimBuild::color(color); PrimBuild::vertex3fv(p->a); PrimBuild::vertex3fv(p->b); @@ -321,7 +331,7 @@ void DebugDrawer::render(bool clear) if (MathUtils::mProjectWorldToScreen(p->a, &result, GFX->getViewport(), GFX->getWorldMatrix(), GFX->getProjectionMatrix())) { GFX->setClipRect(GFX->getViewport()); - GFX->getDrawUtil()->setBitmapModulation(p->color); + GFX->getDrawUtil()->setBitmapModulation(color); GFX->getDrawUtil()->drawText(mFont, Point2I(result.x, result.y), p->mText); } } @@ -346,7 +356,7 @@ void DebugDrawer::render(bool clear) #endif } -void DebugDrawer::drawBox(const Point3F &a, const Point3F &b, const ColorF &color) +void DebugDrawer::drawBox(const Point3F &a, const Point3F &b, const LinearColorF &color) { if(isFrozen || !isDrawing) return; @@ -364,7 +374,7 @@ void DebugDrawer::drawBox(const Point3F &a, const Point3F &b, const ColorF &colo mHead = n; } -void DebugDrawer::drawLine(const Point3F &a, const Point3F &b, const ColorF &color) +void DebugDrawer::drawLine(const Point3F &a, const Point3F &b, const LinearColorF &color) { if(isFrozen || !isDrawing) return; @@ -382,7 +392,7 @@ void DebugDrawer::drawLine(const Point3F &a, const Point3F &b, const ColorF &col mHead = n; } -void DebugDrawer::drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const ColorF &color) +void DebugDrawer::drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const LinearColorF &color) { if(isFrozen || !isDrawing) return; @@ -402,7 +412,7 @@ void DebugDrawer::drawCapsule(const Point3F &a, const F32 &radius, const F32 &he } -void DebugDrawer::drawDirectionLine(const Point3F &a, const Point3F &b, const ColorF &color) +void DebugDrawer::drawDirectionLine(const Point3F &a, const Point3F &b, const LinearColorF &color) { if(isFrozen || !isDrawing) return; @@ -420,7 +430,7 @@ void DebugDrawer::drawDirectionLine(const Point3F &a, const Point3F &b, const Co mHead = n; } -void DebugDrawer::drawOutlinedText(const Point3F& pos, const String& text, const ColorF &color, const ColorF &colorOutline) +void DebugDrawer::drawOutlinedText(const Point3F& pos, const String& text, const LinearColorF &color, const LinearColorF &colorOutline) { if(isFrozen || !isDrawing) return; @@ -439,7 +449,7 @@ void DebugDrawer::drawOutlinedText(const Point3F& pos, const String& text, const mHead = n; } -void DebugDrawer::drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color) +void DebugDrawer::drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const LinearColorF &color) { if(isFrozen || !isDrawing) return; @@ -458,7 +468,7 @@ void DebugDrawer::drawTri(const Point3F &a, const Point3F &b, const Point3F &c, mHead = n; } -void DebugDrawer::drawPolyhedron( const AnyPolyhedron& polyhedron, const ColorF& color ) +void DebugDrawer::drawPolyhedron( const AnyPolyhedron& polyhedron, const LinearColorF& color ) { const PolyhedronData::Edge* edges = polyhedron.getEdges(); const Point3F* points = polyhedron.getPoints(); @@ -534,11 +544,11 @@ void DebugDrawer::drawPolyhedronDebugInfo( const AnyPolyhedron& polyhedron, cons p.convolve( scale ); transform.mulP( p ); - drawText( p, String::ToString( "%i: (%.2f, %.2f, %.2f)", i, p.x, p.y, p.z ), ColorF::WHITE ); + drawText( p, String::ToString( "%i: (%.2f, %.2f, %.2f)", i, p.x, p.y, p.z ), LinearColorF::WHITE ); } } -void DebugDrawer::drawText(const Point3F& pos, const String& text, const ColorF &color) +void DebugDrawer::drawText(const Point3F& pos, const String& text, const LinearColorF &color) { if(isFrozen || !isDrawing) return; @@ -571,13 +581,13 @@ void DebugDrawer::setLastZTest(bool enabled) mHead->useZ = enabled; } -DefineEngineMethod( DebugDrawer, drawLine, void, ( Point3F a, Point3F b, ColorF color ), ( ColorF::WHITE ), +DefineEngineMethod( DebugDrawer, drawLine, void, ( Point3F a, Point3F b, LinearColorF color ), ( LinearColorF::WHITE ), "Draws a line primitive between two 3d points." ) { object->drawLine( a, b, color ); } -DefineEngineMethod( DebugDrawer, drawBox, void, ( Point3F a, Point3F b, ColorF color ), ( ColorF::WHITE ), +DefineEngineMethod( DebugDrawer, drawBox, void, ( Point3F a, Point3F b, LinearColorF color ), ( LinearColorF::WHITE ), "Draws an axis aligned box primitive within the two 3d points." ) { object->drawBox( a, b, color ); diff --git a/Engine/source/gfx/sim/debugDraw.h b/Engine/source/gfx/sim/debugDraw.h index a0b00d6d5..e40889dc0 100644 --- a/Engine/source/gfx/sim/debugDraw.h +++ b/Engine/source/gfx/sim/debugDraw.h @@ -122,19 +122,19 @@ public: /// /// @{ - void drawBoxOutline(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f)); - void drawTransformedBoxOutline(const Point3F &a, const Point3F &b, const ColorF &color, const MatrixF& transform); + void drawBoxOutline(const Point3F &a, const Point3F &b, const LinearColorF &color = LinearColorF(1.0f, 1.0f, 1.0f)); + void drawTransformedBoxOutline(const Point3F &a, const Point3F &b, const LinearColorF &color, const MatrixF& transform); - void drawBox(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); - void drawLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); - void drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); - void drawText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); - void drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f)); - void drawDirectionLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f)); - void drawOutlinedText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f), const ColorF &colorOutline = ColorF(0.0f, 0.0f, 0.0f)); + void drawBox(const Point3F &a, const Point3F &b, const LinearColorF &color = LinearColorF(1.0f,1.0f,1.0f)); + void drawLine(const Point3F &a, const Point3F &b, const LinearColorF &color = LinearColorF(1.0f,1.0f,1.0f)); + void drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const LinearColorF &color = LinearColorF(1.0f,1.0f,1.0f)); + void drawText(const Point3F& pos, const String& text, const LinearColorF &color = LinearColorF(1.0f,1.0f,1.0f)); + void drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const LinearColorF &color = LinearColorF(1.0f, 1.0f, 1.0f)); + void drawDirectionLine(const Point3F &a, const Point3F &b, const LinearColorF &color = LinearColorF(1.0f, 1.0f, 1.0f)); + void drawOutlinedText(const Point3F& pos, const String& text, const LinearColorF &color = LinearColorF(1.0f, 1.0f, 1.0f), const LinearColorF &colorOutline = LinearColorF(0.0f, 0.0f, 0.0f)); /// Render a wireframe view of the given polyhedron. - void drawPolyhedron( const AnyPolyhedron& polyhedron, const ColorF& color = ColorF( 1.f, 1.f, 1.f ) ); + void drawPolyhedron( const AnyPolyhedron& polyhedron, const LinearColorF& color = LinearColorF( 1.f, 1.f, 1.f ) ); /// Render the plane indices, edge indices, edge direction indicators, and point coordinates /// of the given polyhedron for debugging. @@ -169,8 +169,8 @@ private: struct DebugPrim { /// Color used for this primitive. - ColorF color; - ColorF color2; + LinearColorF color; + LinearColorF color2; /// Points used to store positional data. Exact semantics determined by type. Point3F a, b, c; diff --git a/Engine/source/gfx/sim/gfxStateBlockData.cpp b/Engine/source/gfx/sim/gfxStateBlockData.cpp index 3e2792bbc..6bd3effee 100644 --- a/Engine/source/gfx/sim/gfxStateBlockData.cpp +++ b/Engine/source/gfx/sim/gfxStateBlockData.cpp @@ -353,6 +353,9 @@ void GFXSamplerStateData::initPersistFields() addField("resultArg", TypeGFXTextureArgument, Offset(mState.resultArg, GFXSamplerStateData), "The selection of the destination register for the result of this stage. The default is GFXTACurrent." ); + + addField("samplerFunc", TypeGFXCmpFunc, Offset(mState.samplerFunc, GFXSamplerStateData), + "Compares sampled data against existing sampled data. The default is GFXCmpNever."); } /// Copies the data of this object into desc diff --git a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp index 29d81231f..b357fc3b5 100644 --- a/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp @@ -307,22 +307,22 @@ void GuiBitmapButtonCtrl::setBitmap( const String& name ) if( mUseModifiers ) baseName += modifiers[ i ]; - mTextures[ i ].mTextureNormal = GFXTexHandle( baseName, &GFXDefaultPersistentProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__)); + mTextures[ i ].mTextureNormal = GFXTexHandle( baseName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__)); if( mUseStates ) { if( !mTextures[ i ].mTextureNormal ) - mTextures[ i ].mTextureNormal = GFXTexHandle( baseName + s_n, &GFXDefaultPersistentProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__)); + mTextures[ i ].mTextureNormal = GFXTexHandle( baseName + s_n, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__)); - mTextures[ i ].mTextureHilight = GFXTexHandle( baseName + s_h, &GFXDefaultPersistentProfile, avar("%s() - mTextureHighlight (line %d)", __FUNCTION__, __LINE__)); + mTextures[ i ].mTextureHilight = GFXTexHandle( baseName + s_h, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureHighlight (line %d)", __FUNCTION__, __LINE__)); if( !mTextures[ i ].mTextureHilight ) mTextures[ i ].mTextureHilight = mTextures[ i ].mTextureNormal; - mTextures[ i ].mTextureDepressed = GFXTexHandle( baseName + s_d, &GFXDefaultPersistentProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__)); + mTextures[ i ].mTextureDepressed = GFXTexHandle( baseName + s_d, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__)); if( !mTextures[ i ].mTextureDepressed ) mTextures[ i ].mTextureDepressed = mTextures[ i ].mTextureHilight; - mTextures[ i ].mTextureInactive = GFXTexHandle( baseName + s_i, &GFXDefaultPersistentProfile, avar("%s() - mTextureInactive (line %d)", __FUNCTION__, __LINE__)); + mTextures[ i ].mTextureInactive = GFXTexHandle( baseName + s_i, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureInactive (line %d)", __FUNCTION__, __LINE__)); if( !mTextures[ i ].mTextureInactive ) mTextures[ i ].mTextureInactive = mTextures[ i ].mTextureNormal; } diff --git a/Engine/source/gui/buttons/guiIconButtonCtrl.cpp b/Engine/source/gui/buttons/guiIconButtonCtrl.cpp index e9d654d2a..aaa374fa5 100644 --- a/Engine/source/gui/buttons/guiIconButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiIconButtonCtrl.cpp @@ -207,7 +207,7 @@ void GuiIconButtonCtrl::setBitmap(const char *name) if (*mBitmapName) { - mTextureNormal = GFXTexHandle( name, &GFXDefaultPersistentProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) ); + mTextureNormal = GFXTexHandle( name, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) ); } else { diff --git a/Engine/source/gui/buttons/guiSwatchButtonCtrl.cpp b/Engine/source/gui/buttons/guiSwatchButtonCtrl.cpp index fcccca0e4..686ba0b04 100644 --- a/Engine/source/gui/buttons/guiSwatchButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiSwatchButtonCtrl.cpp @@ -58,7 +58,7 @@ ConsoleDocClass( GuiSwatchButtonCtrl, //----------------------------------------------------------------------------- GuiSwatchButtonCtrl::GuiSwatchButtonCtrl() - : mSwatchColor(1, 1, 1, 1), mUseSRGB(false) + : mSwatchColor(1, 1, 1, 1) { mButtonText = StringTable->insert( "" ); setExtent(140, 30); @@ -72,8 +72,6 @@ GuiSwatchButtonCtrl::GuiSwatchButtonCtrl() void GuiSwatchButtonCtrl::initPersistFields() { addField("color", TypeColorF, Offset(mSwatchColor, GuiSwatchButtonCtrl), "The foreground color of GuiSwatchButtonCtrl"); - addField( "useSRGB", TypeBool, Offset( mUseSRGB, GuiSwatchButtonCtrl ), "Render using sRGB scale" ); - addField( "gridBitmap", TypeString, Offset( mGridBitmap, GuiSwatchButtonCtrl ), "The bitmap used for the transparent grid" ); Parent::initPersistFields(); @@ -108,10 +106,7 @@ void GuiSwatchButtonCtrl::onRender( Point2I offset, const RectI &updateRect ) drawer->drawBitmapStretch( mGrid, renderRect ); // Draw swatch color as fill... - if (!mUseSRGB) - drawer->drawRectFill( renderRect, mSwatchColor.toGamma() ); - else - drawer->drawRectFill(renderRect, mSwatchColor); + drawer->drawRectFill(renderRect, mSwatchColor.toColorI()); // Draw any borders... drawer->drawRect( renderRect, borderColor ); diff --git a/Engine/source/gui/buttons/guiSwatchButtonCtrl.h b/Engine/source/gui/buttons/guiSwatchButtonCtrl.h index 866864685..ac7b2f992 100644 --- a/Engine/source/gui/buttons/guiSwatchButtonCtrl.h +++ b/Engine/source/gui/buttons/guiSwatchButtonCtrl.h @@ -39,8 +39,7 @@ class GuiSwatchButtonCtrl : public GuiButtonBaseCtrl protected: /// The color to display on the button. - ColorF mSwatchColor; - bool mUseSRGB; ///< use sRGB color scale + LinearColorF mSwatchColor; /// Bitmap used for mGrid String mGridBitmap; @@ -52,10 +51,10 @@ class GuiSwatchButtonCtrl : public GuiButtonBaseCtrl GuiSwatchButtonCtrl(); /// Return the color displayed in the swatch. - ColorF getColor() { return mSwatchColor; } + LinearColorF getColor() { return mSwatchColor; } /// Set the color to display in the swatch. - void setColor( const ColorF &color ) { mSwatchColor = color; } + void setColor( const LinearColorF &color ) { mSwatchColor = color; } // GuiButtonBaseCtrl virtual bool onWake(); diff --git a/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp b/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp index ad65b5782..fb2b9a5f9 100644 --- a/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp +++ b/Engine/source/gui/buttons/guiToolboxButtonCtrl.cpp @@ -130,7 +130,7 @@ void GuiToolboxButtonCtrl::setNormalBitmap( StringTableEntry bitmapName ) return; if ( *mNormalBitmapName ) - mTextureNormal = GFXTexHandle( mNormalBitmapName, &GFXDefaultPersistentProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) ); + mTextureNormal = GFXTexHandle( mNormalBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) ); else mTextureNormal = NULL; @@ -145,7 +145,7 @@ void GuiToolboxButtonCtrl::setLoweredBitmap( StringTableEntry bitmapName ) return; if ( *mLoweredBitmapName ) - mTextureLowered = GFXTexHandle( mLoweredBitmapName, &GFXDefaultPersistentProfile, avar("%s() - mTextureLowered (line %d)", __FUNCTION__, __LINE__) ); + mTextureLowered = GFXTexHandle( mLoweredBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureLowered (line %d)", __FUNCTION__, __LINE__) ); else mTextureLowered = NULL; @@ -160,7 +160,7 @@ void GuiToolboxButtonCtrl::setHoverBitmap( StringTableEntry bitmapName ) return; if ( *mHoverBitmapName ) - mTextureHover = GFXTexHandle( mHoverBitmapName, &GFXDefaultPersistentProfile, avar("%s() - mTextureHover (line %d)", __FUNCTION__, __LINE__) ); + mTextureHover = GFXTexHandle( mHoverBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureHover (line %d)", __FUNCTION__, __LINE__) ); else mTextureHover = NULL; diff --git a/Engine/source/gui/controls/guiColorPicker.cpp b/Engine/source/gui/controls/guiColorPicker.cpp index 5043c8a46..98f9620b3 100644 --- a/Engine/source/gui/controls/guiColorPicker.cpp +++ b/Engine/source/gui/controls/guiColorPicker.cpp @@ -32,11 +32,11 @@ /// @name Common colors we use /// @{ -ColorF colorWhite(1.,1.,1.); -ColorF colorWhiteBlend(1.,1.,1.,.75); -ColorF colorBlack(.0,.0,.0); -ColorF colorAlpha(0.0f, 0.0f, 0.0f, 0.0f); -ColorF colorAlphaW(1.0f, 1.0f, 1.0f, 0.0f); +LinearColorF colorWhite(1.,1.,1.); +LinearColorF colorWhiteBlend(1.,1.,1.,.75); +LinearColorF colorBlack(.0,.0,.0); +LinearColorF colorAlpha(0.0f, 0.0f, 0.0f, 0.0f); +LinearColorF colorAlphaW(1.0f, 1.0f, 1.0f, 0.0f); ColorI GuiColorPickerCtrl::mColorRange[7] = { ColorI(255,0,0), // Red @@ -52,7 +52,7 @@ ColorI GuiColorPickerCtrl::mColorRange[7] = { IMPLEMENT_CONOBJECT(GuiColorPickerCtrl); ConsoleDocClass( GuiColorPickerCtrl, - "@brief Editor GUI used for picking a ColorF from a palette.\n\n" + "@brief Editor GUI used for picking a LinearColorF from a palette.\n\n" "@note Editor use only.\n\n" "@internal" ); @@ -61,8 +61,8 @@ GuiColorPickerCtrl::GuiColorPickerCtrl() { setExtent(140, 30); mDisplayMode = pPallet; - mBaseColor = ColorF(1.,.0,1.); - mPickColor = ColorF(.0,.0,.0); + mBaseColor = LinearColorF(1.,.0,1.); + mPickColor = LinearColorF(.0,.0,.0); mSelectorPos = Point2I(0,0); mMouseDown = mMouseOver = false; mActive = true; @@ -73,7 +73,6 @@ GuiColorPickerCtrl::GuiColorPickerCtrl() mSelectColor = false; mSetColor = mSetColor.BLACK; mBitmap = NULL; - mUseSRGB = false; } GuiColorPickerCtrl::~GuiColorPickerCtrl() @@ -105,7 +104,6 @@ void GuiColorPickerCtrl::initPersistFields() addGroup("ColorPicker"); addField("baseColor", TypeColorF, Offset(mBaseColor, GuiColorPickerCtrl)); addField("pickColor", TypeColorF, Offset(mPickColor, GuiColorPickerCtrl)); - addField("useSRGB", TypeBool, Offset(mUseSRGB, GuiColorPickerCtrl), "Render using sRGB scale"); addField("selectorGap", TypeS32, Offset(mSelectorGap, GuiColorPickerCtrl)); addField("displayMode", TYPEID< PickMode >(), Offset(mDisplayMode, GuiColorPickerCtrl) ); addField("actionOnMove", TypeBool,Offset(mActionOnMove, GuiColorPickerCtrl)); @@ -116,25 +114,19 @@ void GuiColorPickerCtrl::initPersistFields() } // Function to draw a box which can have 4 different colors in each corner blended together -void GuiColorPickerCtrl::drawBlendBox(RectI &bounds, ColorF &c1, ColorF &c2, ColorF &c3, ColorF &c4) +void GuiColorPickerCtrl::drawBlendBox(RectI &bounds, LinearColorF &c1, LinearColorF &c2, LinearColorF &c3, LinearColorF &c4) { GFX->setStateBlock(mStateBlock); S32 l = bounds.point.x, r = bounds.point.x + bounds.extent.x; S32 t = bounds.point.y, b = bounds.point.y + bounds.extent.y; - ColorF col[4]; + LinearColorF col[4]; col[0] = c1; col[1] = c2; col[2] = c3; col[3] = c4; - if (!mUseSRGB) - { - for (U32 i = 0; i < 4; i++) - col[i] = col[i].toGamma(); - } - //A couple of checks to determine if color blend //A couple of checks to determine if color blend if (c1 == colorWhite && c3 == colorAlpha && c4 == colorBlack) { @@ -224,17 +216,8 @@ void GuiColorPickerCtrl::drawBlendRangeBox(RectI &bounds, bool vertical, U8 numC ColorI *col = new ColorI[numColors]; dMemcpy(col, colors, numColors * sizeof(ColorI)); - if (mUseSRGB) - { - for (U16 i = 0; i < numColors - 1; i++) + for (U16 i = 0; i < numColors - 1; i++) col[i] = colors[i]; - } - else - { - for (U16 i = 0; i < numColors - 1; i++) - col[i] = colors[i].toGamma(); - } - for (U16 i = 0; i < numColors - 1; i++) { @@ -273,6 +256,8 @@ void GuiColorPickerCtrl::drawBlendRangeBox(RectI &bounds, bool vertical, U8 numC } PrimBuild::end(); } + + SAFE_DELETE_ARRAY(col); } void GuiColorPickerCtrl::drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode) @@ -281,23 +266,24 @@ void GuiColorPickerCtrl::drawSelector(RectI &bounds, Point2I &selectorPos, Selec return; U16 sMax = mSelectorGap*2; + const ColorI color = colorWhiteBlend.toColorI(); switch (mode) { case sVertical: // Now draw the vertical selector Up -> Pos if (selectorPos.y != bounds.point.y+1) - GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, colorWhiteBlend); + GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, color); // Down -> Pos if (selectorPos.y != bounds.point.y+bounds.extent.y) - GFX->getDrawUtil()->drawLine(selectorPos.x, selectorPos.y + sMax, selectorPos.x, bounds.point.y + bounds.extent.y, colorWhiteBlend); + GFX->getDrawUtil()->drawLine(selectorPos.x, selectorPos.y + sMax, selectorPos.x, bounds.point.y + bounds.extent.y, color); break; case sHorizontal: // Now draw the horizontal selector Left -> Pos if (selectorPos.x != bounds.point.x) - GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, colorWhiteBlend); + GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, color); // Right -> Pos if (selectorPos.x != bounds.point.x) - GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, colorWhiteBlend); + GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, color); break; } } @@ -339,7 +325,7 @@ void GuiColorPickerCtrl::renderColorBox(RectI &bounds) drawBlendBox( blendRect, colorAlpha, colorAlpha, colorBlack, colorBlack ); blendRect.point.y += blendRect.extent.y - 1; blendRect.extent.y = 2; - GFX->getDrawUtil()->drawRect( blendRect, colorBlack); + GFX->getDrawUtil()->drawRect( blendRect, colorBlack.toColorI()); drawSelector( pickerBounds, selectorPos, sHorizontal ); drawSelector( pickerBounds, selectorPos, sVertical ); break; @@ -366,7 +352,7 @@ void GuiColorPickerCtrl::renderColorBox(RectI &bounds) break; case pPallet: default: - GFX->getDrawUtil()->drawRectFill( pickerBounds, mBaseColor ); + GFX->getDrawUtil()->drawRectFill( pickerBounds, mBaseColor.toColorI()); break; } } @@ -404,7 +390,7 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) U32 buf_x = offset.x + mSelectorPos.x + 1; U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); - GFXTexHandle bb( resolution.x, resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); + GFXTexHandle bb(resolution.x, resolution.y, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__)); Point2I tmpPt(buf_x, buf_y); @@ -417,7 +403,7 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) mBitmap = NULL; } - mBitmap = new GBitmap(bb.getWidth(), bb.getHeight()); + mBitmap = new GBitmap(bb.getWidth(), bb.getHeight(),false,GFXFormatR8G8B8A8); bb.copyToBmp(mBitmap); @@ -435,7 +421,7 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) ColorI tmp; mBitmap->getColor(buf_x, buf_y, tmp); - mPickColor = (ColorF)tmp; + mPickColor = (LinearColorF)tmp; // Now do onAction() if we are allowed if (mActionOnMove) @@ -449,7 +435,7 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) renderChildControls(offset, updateRect); } -void GuiColorPickerCtrl::setSelectorPos(const ColorF & color) +void GuiColorPickerCtrl::setSelectorPos(const LinearColorF & color) { if (mBitmap && !mPositionChanged) { @@ -469,7 +455,7 @@ void GuiColorPickerCtrl::setSelectorPos(const ColorF & color) } } -Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp) +Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp) { RectI rect; Point2I ext = getExtent(); @@ -506,7 +492,7 @@ Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offse ColorI tmp; U32 buf_x; U32 buf_y; - ColorF curColor; + LinearColorF curColor; F32 val(10000.0f); F32 closestVal(10000.0f); bool closestSet = false; @@ -521,7 +507,7 @@ Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offse //Get the color at that position bmp.getColor(buf_x, buf_y, tmp); - curColor = (ColorF)tmp; + curColor = (LinearColorF)tmp; //Evaluate how close the color is to our desired color val = mFabs(color.red - curColor.red) + mFabs(color.green - curColor.green) + mFabs(color.blue - curColor.blue); @@ -660,14 +646,14 @@ void GuiColorPickerCtrl::onMouseUp(const GuiEvent &) const char *GuiColorPickerCtrl::getScriptValue() { static char temp[256]; - ColorF color = getValue(); + LinearColorF color = getValue(); dSprintf( temp, 256, "%f %f %f %f", color.red, color.green, color.blue, color.alpha ); return temp; } void GuiColorPickerCtrl::setScriptValue(const char *value) { - ColorF newValue; + LinearColorF newValue; dSscanf(value, "%f %f %f %f", &newValue.red, &newValue.green, &newValue.blue, &newValue.alpha); setValue(newValue); } @@ -687,7 +673,7 @@ DefineConsoleMethod(GuiColorPickerCtrl, updateColor, void, (), , "Forces update object->updateColor(); } -DefineEngineMethod(GuiColorPickerCtrl, setSelectorColor, void, (ColorF color), , +DefineEngineMethod(GuiColorPickerCtrl, setSelectorColor, void, (LinearColorF color), , "Sets the current position of the selector based on a color.n" "@param color Color to look for.n") { diff --git a/Engine/source/gui/controls/guiColorPicker.h b/Engine/source/gui/controls/guiColorPicker.h index c742cea79..58dee46e5 100644 --- a/Engine/source/gui/controls/guiColorPicker.h +++ b/Engine/source/gui/controls/guiColorPicker.h @@ -81,16 +81,15 @@ class GuiColorPickerCtrl : public GuiControl /// @{ void renderColorBox(RectI &bounds); ///< Function that draws the actual color box void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); /// < Function that draws the selection indicator - void drawBlendBox(RectI &bounds, ColorF &c1, ColorF &c2, ColorF &c3, ColorF &c4); + void drawBlendBox(RectI &bounds, LinearColorF &c1, LinearColorF &c2, LinearColorF &c3, LinearColorF &c4); void drawBlendRangeBox(RectI &bounds, bool vertical, U8 numColors, ColorI *colors); /// @} /// @name Core Variables /// @{ - ColorF mPickColor; ///< Color that has been picked from control - ColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode) + LinearColorF mPickColor; ///< Color that has been picked from control + LinearColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode) PickMode mDisplayMode; ///< Current color display mode of the selector - bool mUseSRGB; ///< use sRGB color scale Point2I mSelectorPos; ///< Current position of the selector bool mPositionChanged; ///< Current position has changed since last render? @@ -99,10 +98,10 @@ class GuiColorPickerCtrl : public GuiControl bool mActionOnMove; ///< Perform onAction() when position has changed? bool mSelectColor; - ColorF mSetColor; + LinearColorF mSetColor; GBitmap* mBitmap; - Point2I findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp); + Point2I findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp); S32 mSelectorGap; ///< The half-way "gap" between the selector pos and where the selector is allowed to draw. @@ -125,9 +124,9 @@ class GuiColorPickerCtrl : public GuiControl /// @name Color Value Functions /// @{ /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful - void setValue(ColorF &value) {mBaseColor = value;} + void setValue(LinearColorF &value) {mBaseColor = value;} /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves) - ColorF getValue() { return mDisplayMode == pPallet ? mBaseColor : mPickColor; } + LinearColorF getValue() { return mDisplayMode == pPallet ? mBaseColor : mPickColor; } const char *getScriptValue(); void setScriptValue(const char *value); void updateColor() {mPositionChanged = true;} @@ -136,7 +135,7 @@ class GuiColorPickerCtrl : public GuiControl /// @name Selector Functions /// @{ void setSelectorPos(const Point2I &pos); ///< Set new pos (in local coords) - void setSelectorPos(const ColorF & color); + void setSelectorPos(const LinearColorF & color); Point2I getSelectorPos() {return mSelectorPos;} /// @} diff --git a/Engine/source/gui/controls/guiGradientCtrl.cpp b/Engine/source/gui/controls/guiGradientCtrl.cpp index 647b9eaf1..20454b73d 100644 --- a/Engine/source/gui/controls/guiGradientCtrl.cpp +++ b/Engine/source/gui/controls/guiGradientCtrl.cpp @@ -115,7 +115,7 @@ void GuiGradientSwatchCtrl::onRender( Point2I offset, const RectI &updateRect ) drawer->drawBitmapStretch( mGrid, renderRect ); // Draw swatch color as fill... - drawer->drawRectFill( renderRect, mSwatchColor ); + drawer->drawRectFill( renderRect, mSwatchColor.toColorI()); // Draw any borders... drawer->drawRect( renderRect, borderColor ); @@ -218,14 +218,14 @@ GuiGradientCtrl::GuiGradientCtrl() setExtent(140, 30); mDisplayMode = pHorizColorRange; mSaveDisplayMode = pHorizColorRange; - mBaseColor = ColorF(1.,.0,1.); - mPickColor = ColorF(.0,.0,.0); + mBaseColor = LinearColorF(1.,.0,1.); + mPickColor = LinearColorF(.0,.0,.0); mMouseDown = mMouseOver = false; mActive = true; mPositionChanged = false; mActionOnMove = false; mShowReticle = true; - colorWhiteBlend = ColorF(1.,1.,1.,.75); + colorWhiteBlend = LinearColorF(1.,1.,1.,.75); mSwatchFactor = 7; } @@ -410,7 +410,7 @@ void GuiGradientCtrl::onMouseDown(const GuiEvent &event) Point2I resolution = getRoot()->getExtent(); GFXTexHandle bb( resolution.x, resolution.y, - GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); + GFXFormatR8G8B8A8, &GFXRenderTargetSRGBProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); Point2I tmpPt( event.mousePoint.x, event.mousePoint.y ); GFXTarget *targ = GFX->getActiveRenderTarget(); @@ -420,7 +420,7 @@ void GuiGradientCtrl::onMouseDown(const GuiEvent &event) ColorI tmp; bmp.getColor( event.mousePoint.x, event.mousePoint.y, tmp ); - addColorRange( globalToLocalCoord(event.mousePoint), ColorF(tmp) ); + addColorRange( globalToLocalCoord(event.mousePoint), LinearColorF(tmp) ); mMouseDown = true; } @@ -506,7 +506,7 @@ void GuiGradientCtrl::reInitSwatches( GuiGradientCtrl::PickMode ) mColorRange[i].swatch->registerObject(); addObject(mColorRange[i].swatch); mColorRange[i].swatch->setPosition( Point2I( mColorRange[i].pos, b ) );// needs to be adjusted - mColorRange[i].swatch->setColor(ColorF(mColorRange[i].color)); + mColorRange[i].swatch->setColor(LinearColorF(mColorRange[i].color)); } } @@ -518,12 +518,12 @@ void GuiGradientCtrl::reInitSwatches( GuiGradientCtrl::PickMode ) mAlphaRange[i].swatch->registerObject(); addObject(mAlphaRange[i].swatch); mAlphaRange[i].swatch->setPosition( Point2I( mAlphaRange[i].pos, b ) );// needs to be adjusted - mAlphaRange[i].swatch->setColor(ColorF(mAlphaRange[i].color)); + mAlphaRange[i].swatch->setColor(LinearColorF(mAlphaRange[i].color)); } } } -void GuiGradientCtrl::addColorRange(Point2I pos, const ColorF& color) +void GuiGradientCtrl::addColorRange(Point2I pos, const LinearColorF& color) { if( pos.x + mSwatchFactor < mBlendRangeBox.point.x && pos.x + mSwatchFactor > mBlendRangeBox.extent.x ) @@ -611,7 +611,7 @@ DefineConsoleMethod(GuiGradientCtrl, getColorCount, S32, (), , "Get color count" return 0; } -DefineConsoleMethod(GuiGradientCtrl, getColor, ColorF, (S32 idx), , "Get color value") +DefineConsoleMethod(GuiGradientCtrl, getColor, LinearColorF, (S32 idx), , "Get color value") { if( object->getDisplayMode() == GuiGradientCtrl::pHorizColorRange ) @@ -631,5 +631,5 @@ DefineConsoleMethod(GuiGradientCtrl, getColor, ColorF, (S32 idx), , "Get color v } } - return ColorF::ONE; + return LinearColorF::ONE; } \ No newline at end of file diff --git a/Engine/source/gui/controls/guiGradientCtrl.h b/Engine/source/gui/controls/guiGradientCtrl.h index 3d569f57e..75f3f85ef 100644 --- a/Engine/source/gui/controls/guiGradientCtrl.h +++ b/Engine/source/gui/controls/guiGradientCtrl.h @@ -74,7 +74,7 @@ public: { GuiGradientSwatchCtrl* swatch; S32 pos; - ColorF color; + LinearColorF color; }; Vector mColorRange; @@ -93,8 +93,8 @@ private: /// @name Core Variables /// @{ - ColorF mPickColor; ///< Color that has been picked from control - ColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode) + LinearColorF mPickColor; ///< Color that has been picked from control + LinearColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode) PickMode mDisplayMode; ///< Current color display mode of the selector PickMode mSaveDisplayMode; @@ -105,11 +105,11 @@ private: GFXStateBlockRef mStateBlock; - ColorF colorWhite; - ColorF colorWhiteBlend; - ColorF colorBlack; - ColorF colorAlpha; - ColorF colorAlphaW; + LinearColorF colorWhite; + LinearColorF colorWhiteBlend; + LinearColorF colorBlack; + LinearColorF colorAlpha; + LinearColorF colorAlphaW; /// @} String mColorFunction; @@ -126,9 +126,9 @@ public: /// @name Color Value Functions /// @{ /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful - void setValue(ColorF &value) {mBaseColor = value;} + void setValue(LinearColorF &value) {mBaseColor = value;} /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves) - ColorF getValue() {return mPickColor;} + LinearColorF getValue() {return mPickColor;} void updateColor() {mPositionChanged = true;} /// @} @@ -148,7 +148,7 @@ public: void inspectPreApply(); void inspectPostApply(); void reInitSwatches( GuiGradientCtrl::PickMode ); - void addColorRange(Point2I pos, const ColorF& color); + void addColorRange(Point2I pos, const LinearColorF& color); void removeColorRange( GuiGradientSwatchCtrl* swatch ); void sortColorRange(); diff --git a/Engine/source/gui/controls/guiListBoxCtrl.cpp b/Engine/source/gui/controls/guiListBoxCtrl.cpp index 992d64903..8c0dabb11 100644 --- a/Engine/source/gui/controls/guiListBoxCtrl.cpp +++ b/Engine/source/gui/controls/guiListBoxCtrl.cpp @@ -626,7 +626,7 @@ DefineEngineMethod( GuiListBoxCtrl, addItem, S32, (const char* newItem, const ch green = dAtof(GuiListBoxCtrl::getStringElement( color, 1 )); blue = dAtof(GuiListBoxCtrl::getStringElement( color, 2 )); - return object->addItemWithColor( newItem, ColorF(red, green, blue) ); + return object->addItemWithColor( newItem, LinearColorF(red, green, blue) ); } else if(elementCount == 1) { @@ -654,13 +654,13 @@ S32 GuiListBoxCtrl::addItem( StringTableEntry text, void *itemData ) return insertItem( mItems.size(), text, itemData ); } -S32 GuiListBoxCtrl::addItemWithColor( StringTableEntry text, ColorF color, void *itemData ) +S32 GuiListBoxCtrl::addItemWithColor( StringTableEntry text, LinearColorF color, void *itemData ) { // This just calls insert item at the end of the list return insertItemWithColor( mItems.size(), text, color, itemData ); } -DefineEngineMethod( GuiListBoxCtrl, setItemColor, void, (S32 index, ColorF color),, +DefineEngineMethod( GuiListBoxCtrl, setItemColor, void, (S32 index, LinearColorF color),, "@brief Sets the color of a single list entry at the specified index id.\n\n" "@param index Index id to modify the color of in the list.\n" "@param color Color value to set the list entry to.\n" @@ -677,7 +677,7 @@ DefineEngineMethod( GuiListBoxCtrl, setItemColor, void, (S32 index, ColorF color object->setItemColor( index, color ); } -void GuiListBoxCtrl::setItemColor(S32 index, const ColorF& color) +void GuiListBoxCtrl::setItemColor(S32 index, const LinearColorF& color) { if ((index >= mItems.size()) || index < 0) { @@ -767,7 +767,7 @@ S32 GuiListBoxCtrl::insertItem( S32 index, StringTableEntry text, void *itemData } -S32 GuiListBoxCtrl::insertItemWithColor( S32 index, StringTableEntry text, ColorF color, void *itemData ) +S32 GuiListBoxCtrl::insertItemWithColor( S32 index, StringTableEntry text, LinearColorF color, void *itemData ) { // If the index is greater than our list size, insert it at the end if( index >= mItems.size() ) @@ -780,7 +780,7 @@ S32 GuiListBoxCtrl::insertItemWithColor( S32 index, StringTableEntry text, Color return -1; } - if( color == ColorF(-1, -1, -1) ) + if( color == LinearColorF(-1, -1, -1) ) { Con::warnf("GuiListBoxCtrl::insertItem - cannot add NULL color" ); return -1; @@ -1065,7 +1065,7 @@ void GuiListBoxCtrl::onRender( Point2I offset, const RectI &updateRect ) { // Set the size of the color box to be drawn next to the item text colorBoxSize = 3; - boxColor = ColorI(mItems[i]->color); + boxColor = ColorI(mItems[i]->color.toColorI()); // Draw the box first ColorI black = ColorI(0, 0, 0); drawBox( Point2I(offset.x + mProfile->mTextOffset.x + colorBoxSize, offset.y + ( i * mItemSize.y ) + 8), colorBoxSize, black, boxColor ); @@ -1085,7 +1085,7 @@ void GuiListBoxCtrl::onRenderItem(const RectI& itemRect, LBItem *item) if( item->isSelected ) GFX->getDrawUtil()->drawRectFill( itemRect, mProfile->mFillColorSEL ); - GFX->getDrawUtil()->setBitmapModulation( item->hasColor ? (ColorI)item->color : mProfile->mFontColor); + GFX->getDrawUtil()->setBitmapModulation( item->hasColor ? item->color.toColorI() : mProfile->mFontColor); renderJustifiedText(itemRect.point + Point2I( 2, 0 ), itemRect.extent, item->itemText); } diff --git a/Engine/source/gui/controls/guiListBoxCtrl.h b/Engine/source/gui/controls/guiListBoxCtrl.h index 7c03edf9f..1c0159205 100644 --- a/Engine/source/gui/controls/guiListBoxCtrl.h +++ b/Engine/source/gui/controls/guiListBoxCtrl.h @@ -70,7 +70,7 @@ public: String itemTooltip; bool isSelected; void* itemData; - ColorF color; + LinearColorF color; bool hasColor; }; @@ -102,12 +102,12 @@ public: void setItemText( S32 index, StringTableEntry text ); S32 addItem( StringTableEntry text, void *itemData = NULL ); - S32 addItemWithColor( StringTableEntry text, ColorF color = ColorF(-1, -1, -1), void *itemData = NULL); + S32 addItemWithColor( StringTableEntry text, LinearColorF color = LinearColorF(-1, -1, -1), void *itemData = NULL); S32 insertItem( S32 index, StringTableEntry text, void *itemData = NULL ); - S32 insertItemWithColor( S32 index, StringTableEntry text, ColorF color = ColorF(-1, -1, -1), void *itemData = NULL); + S32 insertItemWithColor( S32 index, StringTableEntry text, LinearColorF color = LinearColorF(-1, -1, -1), void *itemData = NULL); S32 findItemText( StringTableEntry text, bool caseSensitive = false ); - void setItemColor(S32 index, const ColorF& color); + void setItemColor(S32 index, const LinearColorF& color); void clearItemColor(S32 index); void deleteItem( S32 index ); diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.cpp b/Engine/source/gui/controls/guiTreeViewCtrl.cpp index e4fb9ab00..1c6343f04 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.cpp +++ b/Engine/source/gui/controls/guiTreeViewCtrl.cpp @@ -1871,7 +1871,7 @@ bool GuiTreeViewCtrl::buildIconTable(const char * icons) dStrncpy( buf, start, getMin( sizeof( buf ) / sizeof( buf[ 0 ] ) - 1, len ) ); buf[ len ] = '\0'; - mIconTable[ numIcons ] = GFXTexHandle( buf, &GFXDefaultPersistentProfile, avar( "%s() - mIconTable[%d] (line %d)", __FUNCTION__, numIcons, __LINE__ ) ); + mIconTable[ numIcons ] = GFXTexHandle( buf, &GFXTexturePersistentProfile, avar( "%s() - mIconTable[%d] (line %d)", __FUNCTION__, numIcons, __LINE__ ) ); } else mIconTable[ numIcons ] = GFXTexHandle(); @@ -3942,7 +3942,7 @@ void GuiTreeViewCtrl::onRender(Point2I offset, const RectI &updateRect) if (mDragMidPoint == NomDragMidPoint || !mSupportMouseDragging ) return; - ColorF greyLine(0.5,0.5,0.5,1); + ColorI greyLine(128,128,128); Point2F squarePt; // CodeReview: LineWidth is not supported in Direct3D. This is lame. [5/10/2007 Pat] @@ -4257,7 +4257,6 @@ bool GuiTreeViewCtrl::renderTooltip( const Point2I &hoverPos, const Point2I& cur { Item* item; BitSet32 flags = 0; - char buf[ 2048 ]; if( _hitTest( cursorPos, item, flags ) && (!item->mTooltip.isEmpty() || mUseInspectorTooltips) ) { bool render = true; @@ -4302,6 +4301,7 @@ bool GuiTreeViewCtrl::renderTooltip( const Point2I &hoverPos, const Point2I& cur { if( mUseInspectorTooltips ) { + char buf[2048]; item->getTooltipText( sizeof( buf ), buf ); tipText = buf; } diff --git a/Engine/source/gui/core/guiOffscreenCanvas.cpp b/Engine/source/gui/core/guiOffscreenCanvas.cpp index e974873fd..47eb409a3 100644 --- a/Engine/source/gui/core/guiOffscreenCanvas.cpp +++ b/Engine/source/gui/core/guiOffscreenCanvas.cpp @@ -89,13 +89,13 @@ void GuiOffscreenCanvas::_setupTargets() // Update color if (!mTargetTexture.isValid() || mTargetSize != mTargetTexture.getWidthHeight()) { - mTargetTexture.set( mTargetSize.x, mTargetSize.y, mTargetFormat, &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, 0 ); + mTargetTexture.set( mTargetSize.x, mTargetSize.y, mTargetFormat, &GFXRenderTargetSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, 0 ); } // Update depth if needed if (mUseDepth && (!mTargetDepth.isValid() || mTargetSize != mTargetDepth.getWidthHeight())) { - mTargetDepth.set( mTargetSize.x, mTargetSize.y, GFXFormatD24S8, &GFXDefaultZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, 0 ); + mTargetDepth.set( mTargetSize.x, mTargetSize.y, GFXFormatD24S8, &GFXRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, 0 ); mTarget->attachTexture( GFXTextureTarget::RenderSlot(GFXTextureTarget::DepthStencil), mTargetDepth ); } @@ -178,7 +178,7 @@ void GuiOffscreenCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = tr // Clear the current viewport area GFX->setViewport( screenRect ); - GFX->clear( GFXClearTarget, ColorF(0,0,0,0), 1.0f, 0 ); + GFX->clear( GFXClearTarget, LinearColorF(0,0,0,0), 1.0f, 0 ); resetUpdateRegions(); @@ -204,7 +204,7 @@ void GuiOffscreenCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = tr // Fill Blue if no Dialogs if(this->size() == 0) - GFX->clear( GFXClearTarget, ColorF(0,0,0,1), 1.0f, 0 ); + GFX->clear( GFXClearTarget, LinearColorF(0,0,0,1), 1.0f, 0 ); GFX->setClipRect( contentRect ); diff --git a/Engine/source/gui/core/guiTypes.cpp b/Engine/source/gui/core/guiTypes.cpp index 870ef1355..7fbbe62c0 100644 --- a/Engine/source/gui/core/guiTypes.cpp +++ b/Engine/source/gui/core/guiTypes.cpp @@ -63,12 +63,12 @@ ConsoleDocClass( GuiCursor, GFX_ImplementTextureProfile(GFXGuiCursorProfile, GFXTextureProfile::DiffuseMap, GFXTextureProfile::PreserveSize | - GFXTextureProfile::Static, + GFXTextureProfile::Static | GFXTextureProfile::SRGB, GFXTextureProfile::NONE); GFX_ImplementTextureProfile(GFXDefaultGUIProfile, GFXTextureProfile::DiffuseMap, GFXTextureProfile::PreserveSize | - GFXTextureProfile::Static | + GFXTextureProfile::Static | GFXTextureProfile::SRGB | GFXTextureProfile::NoPadding, GFXTextureProfile::NONE); @@ -200,7 +200,7 @@ bool GuiControlProfile::protectedSetBitmap( void *object, const char *index, con //verify the bitmap if (profile->mBitmapName && profile->mBitmapName[0] && dStricmp(profile->mBitmapName, "texhandle") != 0 && - !profile->mTextureObject.set( profile->mBitmapName, &GFXDefaultPersistentProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__) )) + !profile->mTextureObject.set( profile->mBitmapName, &GFXTexturePersistentProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__) )) Con::errorf("Failed to load profile bitmap (%s)",profile->mBitmapName); // If we've got a special border, make sure it's usable. @@ -566,7 +566,7 @@ S32 GuiControlProfile::constructBitmapArray() if( mTextureObject.isNull() ) { - if ( !mBitmapName || !mBitmapName[0] || !mTextureObject.set( mBitmapName, &GFXDefaultPersistentProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__) )) + if ( !mBitmapName || !mBitmapName[0] || !mTextureObject.set( mBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__) )) return 0; } @@ -655,7 +655,7 @@ void GuiControlProfile::incLoadCount() // if (mBitmapName && mBitmapName[0] && dStricmp(mBitmapName, "texhandle") != 0 && - !mTextureObject.set( mBitmapName, &GFXDefaultPersistentProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__) )) + !mTextureObject.set( mBitmapName, &GFXTexturePersistentSRGBProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__) )) Con::errorf("Failed to load profile bitmap (%s)",mBitmapName); constructBitmapArray(); diff --git a/Engine/source/gui/editor/guiEaseViewCtrl.cpp b/Engine/source/gui/editor/guiEaseViewCtrl.cpp index 59713b682..ae97c36cb 100644 --- a/Engine/source/gui/editor/guiEaseViewCtrl.cpp +++ b/Engine/source/gui/editor/guiEaseViewCtrl.cpp @@ -88,8 +88,8 @@ void GuiEaseViewCtrl::onRender(Point2I offset, const RectI &updateRect) // Draw axis. - GFX->getDrawUtil()->drawLine( zeroX, zeroY + 0.0f, zeroX, zeroY + plotH, mAxisColor ); - GFX->getDrawUtil()->drawLine( zeroX, zeroY + plotH, zeroX + plotW, zeroY + plotH, mAxisColor ); + GFX->getDrawUtil()->drawLine( zeroX, zeroY + 0.0f, zeroX, zeroY + plotH, mAxisColor.toColorI()); + GFX->getDrawUtil()->drawLine( zeroX, zeroY + plotH, zeroX + plotW, zeroY + plotH, mAxisColor.toColorI()); F32 numPoints = W; F32 lastX = zeroX; @@ -105,7 +105,7 @@ void GuiEaseViewCtrl::onRender(Point2I offset, const RectI &updateRect) x = zeroX + x * plotW; y = zeroY + plotH - y * plotH; - GFX->getDrawUtil()->drawLine( lastX, lastY, x, y, mEaseColor ); + GFX->getDrawUtil()->drawLine( lastX, lastY, x, y, mEaseColor.toColorI()); lastX = x; lastY = y; diff --git a/Engine/source/gui/editor/guiEaseViewCtrl.h b/Engine/source/gui/editor/guiEaseViewCtrl.h index 612ed4b14..28737f33a 100644 --- a/Engine/source/gui/editor/guiEaseViewCtrl.h +++ b/Engine/source/gui/editor/guiEaseViewCtrl.h @@ -41,8 +41,8 @@ class GuiEaseViewCtrl : public GuiControl protected: EaseF mEase; // ease we are visualizing - ColorF mAxisColor; // color to draw axis in - ColorF mEaseColor; // color to draw ease in + LinearColorF mAxisColor; // color to draw axis in + LinearColorF mEaseColor; // color to draw ease in F32 mEaseWidth; // width of lines public: diff --git a/Engine/source/gui/editor/guiEditCtrl.cpp b/Engine/source/gui/editor/guiEditCtrl.cpp index af6026f60..09644d990 100644 --- a/Engine/source/gui/editor/guiEditCtrl.cpp +++ b/Engine/source/gui/editor/guiEditCtrl.cpp @@ -848,7 +848,7 @@ void GuiEditCtrl::onRender(Point2I offset, const RectI &updateRect) if( mSnapTargets[ axis ] ) { RectI bounds = mSnapTargets[ axis ]->getGlobalBounds(); - drawer->drawRect( bounds, ColorF( .5, .5, .5, .5 ) ); + drawer->drawRect( bounds, ColorI( 128, 128, 128, 128 ) ); } } } @@ -868,8 +868,8 @@ void GuiEditCtrl::drawNuts(RectI &box, ColorI &outlineColor, ColorI &nutColor) if( mDrawBorderLines ) { - ColorF lineColor( 0.7f, 0.7f, 0.7f, 0.25f ); - ColorF lightLineColor( 0.5f, 0.5f, 0.5f, 0.1f ); + ColorI lineColor( 179, 179, 179, 64 ); + ColorI lightLineColor( 128, 128, 128, 26); if(lx > 0 && ty > 0) { @@ -2860,7 +2860,7 @@ class GuiEditorRuler : public GuiControl void onRender(Point2I offset, const RectI &updateRect) { - GFX->getDrawUtil()->drawRectFill(updateRect, ColorF(1,1,1,1)); + GFX->getDrawUtil()->drawRectFill(updateRect, ColorI::WHITE); Point2I choffset(0,0); if( mRefCtrl != NULL ) @@ -2880,7 +2880,7 @@ class GuiEditorRuler : public GuiControl start = 4; if(!(pos % 100)) start = 1; - GFX->getDrawUtil()->drawLine(x, offset.y + start, x, offset.y + 10, ColorF(0,0,0,1)); + GFX->getDrawUtil()->drawLine(x, offset.y + start, x, offset.y + 10, ColorI::BLACK); } } } @@ -2898,7 +2898,7 @@ class GuiEditorRuler : public GuiControl start = 4; if(!(pos % 100)) start = 1; - GFX->getDrawUtil()->drawLine(offset.x + start, y, offset.x + 10, y, ColorF(0,0,0,1)); + GFX->getDrawUtil()->drawLine(offset.x + start, y, offset.x + 10, y, ColorI::BLACK); } } } diff --git a/Engine/source/gui/editor/guiFilterCtrl.cpp b/Engine/source/gui/editor/guiFilterCtrl.cpp index 39f16a99b..a00d4f670 100644 --- a/Engine/source/gui/editor/guiFilterCtrl.cpp +++ b/Engine/source/gui/editor/guiFilterCtrl.cpp @@ -192,7 +192,7 @@ void GuiFilterCtrl::onRender(Point2I offset, const RectI &updateRect) { GFX->getDrawUtil()->drawLine( pos.x, pos.y + ( ext.y * ( 1.0f - mIdentity.x ) ), pos.x + ext.x, pos.y + ( ext.y * ( 1.0f - mIdentity.y ) ), - ColorF( 0.9f, 0.9f, 0.9f ) ); + ColorI( 230, 230, 230 ) ); } // draw the curv @@ -207,7 +207,7 @@ void GuiFilterCtrl::onRender(Point2I offset, const RectI &updateRect) S32 y = (S32)(ext.y*(1.0f-mFilter.getValue(index))); verts[i].point.set( (F32)(pos.x + i), (F32)(pos.y + y), 0.0f ); - verts[i].color = GFXVertexColor( ColorF( 0.4f, 0.4f, 0.4f ) ); + verts[i].color = ColorI( 103, 103, 103 ); } verts.unlock(); diff --git a/Engine/source/gui/editor/guiGraphCtrl.cpp b/Engine/source/gui/editor/guiGraphCtrl.cpp index 6dc224365..8b1c14108 100644 --- a/Engine/source/gui/editor/guiGraphCtrl.cpp +++ b/Engine/source/gui/editor/guiGraphCtrl.cpp @@ -90,12 +90,12 @@ GuiGraphCtrl::GuiGraphCtrl() AssertWarn( MaxPlots == 6, "Only 6 plot colors initialized. Update following code if you change MaxPlots." ); - mGraphColor[ 0 ] = ColorF( 1.0, 1.0, 1.0 ); - mGraphColor[ 1 ] = ColorF( 1.0, 0.0, 0.0 ); - mGraphColor[ 2 ] = ColorF( 0.0, 1.0, 0.0 ); - mGraphColor[ 3 ] = ColorF( 0.0, 0.0, 1.0 ); - mGraphColor[ 4 ] = ColorF( 0.0, 1.0, 1.0 ); - mGraphColor[ 5 ] = ColorF( 0.0, 0.0, 0.0 ); + mGraphColor[ 0 ] = LinearColorF( 1.0, 1.0, 1.0 ); + mGraphColor[ 1 ] = LinearColorF( 1.0, 0.0, 0.0 ); + mGraphColor[ 2 ] = LinearColorF( 0.0, 1.0, 0.0 ); + mGraphColor[ 3 ] = LinearColorF( 0.0, 0.0, 1.0 ); + mGraphColor[ 4 ] = LinearColorF( 0.0, 1.0, 1.0 ); + mGraphColor[ 5 ] = LinearColorF( 0.0, 0.0, 0.0 ); } //----------------------------------------------------------------------------- diff --git a/Engine/source/gui/editor/guiGraphCtrl.h b/Engine/source/gui/editor/guiGraphCtrl.h index 7aca2c4ff..99139fbd7 100644 --- a/Engine/source/gui/editor/guiGraphCtrl.h +++ b/Engine/source/gui/editor/guiGraphCtrl.h @@ -52,7 +52,7 @@ class GuiGraphCtrl : public GuiControl StringTableEntry mAutoPlot[ MaxPlots ]; U32 mAutoPlotDelay[ MaxPlots ]; SimTime mAutoPlotLastDisplay[ MaxPlots ]; - ColorF mGraphColor[ MaxPlots ]; + LinearColorF mGraphColor[ MaxPlots ]; Vector< F32 > mGraphData[ MaxPlots ]; F32 mGraphMax[ MaxPlots ]; GraphType mGraphType[ MaxPlots ]; diff --git a/Engine/source/gui/editor/guiInspectorTypes.cpp b/Engine/source/gui/editor/guiInspectorTypes.cpp index f1bda5316..0b107b5fd 100644 --- a/Engine/source/gui/editor/guiInspectorTypes.cpp +++ b/Engine/source/gui/editor/guiInspectorTypes.cpp @@ -662,7 +662,7 @@ bool GuiInspectorTypeImageFileName::renderTooltip( const Point2I &hoverPos, cons if ( !filename || !filename[0] ) return false; - GFXTexHandle texture( filename, &GFXDefaultStaticDiffuseProfile, avar("%s() - tooltip texture (line %d)", __FUNCTION__, __LINE__) ); + GFXTexHandle texture( filename, &GFXStaticTextureSRGBProfile, avar("%s() - tooltip texture (line %d)", __FUNCTION__, __LINE__) ); if ( texture.isNull() ) return false; @@ -1058,7 +1058,7 @@ bool GuiInspectorTypeEaseF::updateRects() } //----------------------------------------------------------------------------- -// GuiInspectorTypeColor (Base for ColorI/ColorF) +// GuiInspectorTypeColor (Base for ColorI/LinearColorF) //----------------------------------------------------------------------------- GuiInspectorTypeColor::GuiInspectorTypeColor() : mBrowseButton( NULL ) @@ -1209,7 +1209,7 @@ void GuiInspectorTypeColorI::setValue( StringTableEntry newValue ) IMPLEMENT_CONOBJECT(GuiInspectorTypeColorF); ConsoleDocClass( GuiInspectorTypeColorF, - "@brief Inspector field type for ColorF\n\n" + "@brief Inspector field type for LinearColorF\n\n" "Editor use only.\n\n" "@internal" ); @@ -1234,7 +1234,7 @@ void GuiInspectorTypeColorF::setValue( StringTableEntry newValue ) // Now we also set our color swatch button to the new color value. if ( mBrowseButton ) { - ColorF color(1,0,1,1); + LinearColorF color(1,0,1,1); dSscanf( newValue, "%f %f %f %f", &color.red, &color.green, &color.blue, &color.alpha ); mBrowseButton->setColor( color ); } diff --git a/Engine/source/gui/editor/guiInspectorTypes.h b/Engine/source/gui/editor/guiInspectorTypes.h index eff813b34..858501a28 100644 --- a/Engine/source/gui/editor/guiInspectorTypes.h +++ b/Engine/source/gui/editor/guiInspectorTypes.h @@ -346,7 +346,7 @@ public: }; //----------------------------------------------------------------------------- -// TypeColor GuiInspectorField Class (Base for ColorI/ColorF) +// TypeColor GuiInspectorField Class (Base for ColorI/LinearColorF) //----------------------------------------------------------------------------- class GuiSwatchButtonCtrl; diff --git a/Engine/source/gui/editor/guiParticleGraphCtrl.cpp b/Engine/source/gui/editor/guiParticleGraphCtrl.cpp index 68ecf81c4..342646fb1 100644 --- a/Engine/source/gui/editor/guiParticleGraphCtrl.cpp +++ b/Engine/source/gui/editor/guiParticleGraphCtrl.cpp @@ -43,7 +43,7 @@ GuiParticleGraphCtrl::GuiParticleGraphCtrl() for(S32 i = 0; i < MaxPlots; i++) { - mPlots[i].mGraphColor = ColorF(1.0, 1.0, 1.0); + mPlots[i].mGraphColor = LinearColorF(1.0, 1.0, 1.0); VECTOR_SET_ASSOCIATION(mPlots[i].mGraphData); mPlots[i].mGraphMax.x = 1; mPlots[i].mGraphMax.y = 50; @@ -55,38 +55,38 @@ GuiParticleGraphCtrl::GuiParticleGraphCtrl() mPlots[i].mGraphScale = 0.05f; } - mPlots[0].mGraphColor = ColorF(1.0f, 0.2f, 0.2f); - mPlots[1].mGraphColor = ColorF(1.0f, 0.5f, 0.5f); - mPlots[2].mGraphColor = ColorF(0.0f, 1.0f, 0.0f); - mPlots[3].mGraphColor = ColorF(0.0f, 0.0f, 1.0f); - mPlots[4].mGraphColor = ColorF(0.0f, 1.0f, 1.0f); - mPlots[5].mGraphColor = ColorF(0.0f, 0.0f, 0.0f); - mPlots[6].mGraphColor = ColorF(0.5f, 0.5f, 0.5f); - mPlots[7].mGraphColor = ColorF(0.5f, 0.0f, 0.0f); - mPlots[8].mGraphColor = ColorF(0.0f, 0.5f, 0.0f); - mPlots[9].mGraphColor = ColorF(0.0f, 0.0f, 0.5f); - mPlots[10].mGraphColor = ColorF(0.0f, 0.5f, 0.5f); - mPlots[11].mGraphColor = ColorF(0.25f, 0.25f, 0.25f); - mPlots[12].mGraphColor = ColorF(0.5f, 0.5f, 0.5f); - mPlots[13].mGraphColor = ColorF(0.5f, 0.0f, 0.0f); - mPlots[14].mGraphColor = ColorF(0.0f, 0.5f, 0.0f); - mPlots[15].mGraphColor = ColorF(0.0f, 0.0f, 0.5f); - mPlots[16].mGraphColor = ColorF(0.0f, 0.5f, 0.5f); - mPlots[17].mGraphColor = ColorF(0.25f, 0.25f, 0.25f); - mPlots[18].mGraphColor = ColorF(1.0f, 0.2f, 0.2f); - mPlots[19].mGraphColor = ColorF(1.0f, 0.5f, 0.5f); - mPlots[20].mGraphColor = ColorF(0.0f, 1.0f, 0.0f); - mPlots[21].mGraphColor = ColorF(0.0f, 0.0f, 1.0f); - mPlots[22].mGraphColor = ColorF(0.0f, 1.0f, 1.0f); - mPlots[23].mGraphColor = ColorF(0.0f, 0.0f, 0.0f); - mPlots[24].mGraphColor = ColorF(0.5f, 0.5f, 0.5f); - mPlots[25].mGraphColor = ColorF(0.5f, 0.0f, 0.0f); - mPlots[26].mGraphColor = ColorF(0.0f, 0.5f, 0.0f); - mPlots[27].mGraphColor = ColorF(0.0f, 0.0f, 0.5f); - mPlots[28].mGraphColor = ColorF(1.0f, 0.0f, 0.0f); - mPlots[29].mGraphColor = ColorF(0.0f, 1.0f, 0.0f); - mPlots[30].mGraphColor = ColorF(0.0f, 0.0f, 1.0f); - mPlots[31].mGraphColor = ColorF(0.5f, 0.0f, 0.0f); + mPlots[0].mGraphColor = LinearColorF(1.0f, 0.2f, 0.2f); + mPlots[1].mGraphColor = LinearColorF(1.0f, 0.5f, 0.5f); + mPlots[2].mGraphColor = LinearColorF(0.0f, 1.0f, 0.0f); + mPlots[3].mGraphColor = LinearColorF(0.0f, 0.0f, 1.0f); + mPlots[4].mGraphColor = LinearColorF(0.0f, 1.0f, 1.0f); + mPlots[5].mGraphColor = LinearColorF(0.0f, 0.0f, 0.0f); + mPlots[6].mGraphColor = LinearColorF(0.5f, 0.5f, 0.5f); + mPlots[7].mGraphColor = LinearColorF(0.5f, 0.0f, 0.0f); + mPlots[8].mGraphColor = LinearColorF(0.0f, 0.5f, 0.0f); + mPlots[9].mGraphColor = LinearColorF(0.0f, 0.0f, 0.5f); + mPlots[10].mGraphColor = LinearColorF(0.0f, 0.5f, 0.5f); + mPlots[11].mGraphColor = LinearColorF(0.25f, 0.25f, 0.25f); + mPlots[12].mGraphColor = LinearColorF(0.5f, 0.5f, 0.5f); + mPlots[13].mGraphColor = LinearColorF(0.5f, 0.0f, 0.0f); + mPlots[14].mGraphColor = LinearColorF(0.0f, 0.5f, 0.0f); + mPlots[15].mGraphColor = LinearColorF(0.0f, 0.0f, 0.5f); + mPlots[16].mGraphColor = LinearColorF(0.0f, 0.5f, 0.5f); + mPlots[17].mGraphColor = LinearColorF(0.25f, 0.25f, 0.25f); + mPlots[18].mGraphColor = LinearColorF(1.0f, 0.2f, 0.2f); + mPlots[19].mGraphColor = LinearColorF(1.0f, 0.5f, 0.5f); + mPlots[20].mGraphColor = LinearColorF(0.0f, 1.0f, 0.0f); + mPlots[21].mGraphColor = LinearColorF(0.0f, 0.0f, 1.0f); + mPlots[22].mGraphColor = LinearColorF(0.0f, 1.0f, 1.0f); + mPlots[23].mGraphColor = LinearColorF(0.0f, 0.0f, 0.0f); + mPlots[24].mGraphColor = LinearColorF(0.5f, 0.5f, 0.5f); + mPlots[25].mGraphColor = LinearColorF(0.5f, 0.0f, 0.0f); + mPlots[26].mGraphColor = LinearColorF(0.0f, 0.5f, 0.0f); + mPlots[27].mGraphColor = LinearColorF(0.0f, 0.0f, 0.5f); + mPlots[28].mGraphColor = LinearColorF(1.0f, 0.0f, 0.0f); + mPlots[29].mGraphColor = LinearColorF(0.0f, 1.0f, 0.0f); + mPlots[30].mGraphColor = LinearColorF(0.0f, 0.0f, 1.0f); + mPlots[31].mGraphColor = LinearColorF(0.5f, 0.0f, 0.0f); mVertexClickSize = 6; mSelectedPlot = 0; @@ -134,11 +134,11 @@ void GuiParticleGraphCtrl::onRender(Point2I offset, const RectI &updateRect) pDrawUtil->drawRect(rect, mProfile->mBorderColor); } - GuiControlProfile* profile = dynamic_cast(Sim::findObject("GuiDefaultProfile")); - Resource font = profile->mFont; + GuiControlProfile* profile = dynamic_cast(Sim::findObject("GuiDefaultProfile")); + Resource font = profile->mFont; GFXVideoMode videoMode = GFXInit::getDesktopResolution(); - ColorF color(1.0f, 1.0f, 1.0f, 0.5f); + ColorI color(255, 255, 255, 128); pDrawUtil->drawRectFill(updateRect, color); for (S32 k = 0; k < MaxPlots; k++) @@ -184,7 +184,7 @@ void GuiParticleGraphCtrl::onRender(Point2I offset, const RectI &updateRect) // check if this isn't our first loop through, if it is we won't have starting points if(sample > 0) { - pDrawUtil->drawLine( lastPosX, lastPosY , posX, posY , mPlots[k].mGraphColor ); + pDrawUtil->drawLine( lastPosX, lastPosY , posX, posY , mPlots[k].mGraphColor.toColorI() ); } else { mPlots[k].mNutList.clear(); @@ -205,7 +205,7 @@ void GuiParticleGraphCtrl::onRender(Point2I offset, const RectI &updateRect) mLastSelectedPoint = mSelectedPoint; } - ColorI nutColor (mPlots[k].mGraphColor); + ColorI nutColor (mPlots[k].mGraphColor.toColorI()); if(k == mSelectedPlot && sample == mLastSelectedPoint) { @@ -220,7 +220,7 @@ void GuiParticleGraphCtrl::onRender(Point2I offset, const RectI &updateRect) blue = 1.0 - blue; // nut color - nutColor = ColorI(ColorF(red, green, blue)); + nutColor = LinearColorF(red, green, blue).toColorI(); } // draw the seleciton nut @@ -660,7 +660,7 @@ Point2F GuiParticleGraphCtrl::getGraphExtent(S32 plotID) return resultV; } -ColorF GuiParticleGraphCtrl::getGraphColor(S32 plotID) +LinearColorF GuiParticleGraphCtrl::getGraphColor(S32 plotID) { return mPlots[plotID].mGraphColor; } @@ -1151,7 +1151,7 @@ DefineConsoleMethod(GuiParticleGraphCtrl, getPlotIndex, S32, (S32 plotID, F32 x, return object->getPlotIndex(plotID, x, y); } -DefineConsoleMethod(GuiParticleGraphCtrl, getGraphColor, ColorF, (S32 plotID), , "(int plotID)" +DefineConsoleMethod(GuiParticleGraphCtrl, getGraphColor, LinearColorF, (S32 plotID), , "(int plotID)" "Get the color of the graph passed." "@return Returns the color of the graph as a string of RGB values formatted as \"R G B\"") { diff --git a/Engine/source/gui/editor/guiParticleGraphCtrl.h b/Engine/source/gui/editor/guiParticleGraphCtrl.h index e7ec5e079..4ee59b98a 100644 --- a/Engine/source/gui/editor/guiParticleGraphCtrl.h +++ b/Engine/source/gui/editor/guiParticleGraphCtrl.h @@ -61,7 +61,7 @@ public: struct PlotInfo { - ColorF mGraphColor; + LinearColorF mGraphColor; Vector mGraphData; Vector mNutList; Point2F mGraphMax; @@ -136,7 +136,7 @@ public: // Get Functions Point2F getGraphExtent(S32 plotID); - ColorF getGraphColor(S32 plotID); + LinearColorF getGraphColor(S32 plotID); S32 getSelectedPlot(); S32 getSelectedPoint(); Point2F getPlotPoint(S32 plotID, S32 samples); diff --git a/Engine/source/gui/editor/guiShapeEdPreview.cpp b/Engine/source/gui/editor/guiShapeEdPreview.cpp index 0274dbdf0..481544851 100644 --- a/Engine/source/gui/editor/guiShapeEdPreview.cpp +++ b/Engine/source/gui/editor/guiShapeEdPreview.cpp @@ -1433,7 +1433,7 @@ void GuiShapeEdPreview::renderWorld(const RectI &updateRect) GFXStateBlockDesc desc; desc.fillMode = GFXFillWireframe; - GFX->getDrawUtil()->drawCube( desc, boxSize, mModel->getShape()->center, ColorF::WHITE ); + GFX->getDrawUtil()->drawCube( desc, boxSize, mModel->getShape()->center, ColorI::WHITE ); } // Render the selected object bounding box @@ -1450,7 +1450,7 @@ void GuiShapeEdPreview::renderWorld(const RectI &updateRect) const Box3F& bounds = mesh->getBounds(); GFXStateBlockDesc desc; desc.fillMode = GFXFillWireframe; - GFX->getDrawUtil()->drawCube( desc, bounds.getExtents(), bounds.getCenter(), ColorF::RED ); + GFX->getDrawUtil()->drawCube( desc, bounds.getExtents(), bounds.getCenter(), ColorI::RED ); GFX->popWorldMatrix(); } @@ -1490,9 +1490,9 @@ void GuiShapeEdPreview::renderGui(Point2I offset, const RectI& updateRect) if ( mModel ) { if ( mRenderNodes && mHoverNode != -1 ) - renderNodeName( mHoverNode, ColorF::WHITE ); + renderNodeName( mHoverNode, LinearColorF::WHITE ); if ( mSelectedNode != -1 ) - renderNodeName( mSelectedNode, ColorF::WHITE ); + renderNodeName( mSelectedNode, LinearColorF::WHITE ); } } @@ -1530,7 +1530,7 @@ void GuiShapeEdPreview::renderSunDirection() const if ( mEditingSun ) { // Render four arrows aiming in the direction of the sun's light - ColorI color( mFakeSun->getColor() ); + ColorI color = LinearColorF( mFakeSun->getColor()).toColorI(); F32 length = mModel->getShape()->bounds.len() * 0.8f; // Get the sun's vectors @@ -1587,18 +1587,18 @@ void GuiShapeEdPreview::renderNodes() const if ( ( i == mSelectedNode ) || ( i == mHoverNode ) ) continue; - renderNodeAxes( i, ColorF::WHITE ); + renderNodeAxes( i, LinearColorF::WHITE ); } // Render the hovered node if ( mHoverNode != -1 ) - renderNodeAxes( mHoverNode, ColorF::GREEN ); + renderNodeAxes( mHoverNode, LinearColorF::GREEN ); } // Render the selected node (even if mRenderNodes is false) if ( mSelectedNode != -1 ) { - renderNodeAxes( mSelectedNode, ColorF::GREEN ); + renderNodeAxes( mSelectedNode, LinearColorF::GREEN ); const MatrixF& nodeMat = mModel->mNodeTransforms[mSelectedNode]; mGizmo->set( nodeMat, nodeMat.getPosition(), Point3F::One); @@ -1606,7 +1606,7 @@ void GuiShapeEdPreview::renderNodes() const } } -void GuiShapeEdPreview::renderNodeAxes(S32 index, const ColorF& nodeColor) const +void GuiShapeEdPreview::renderNodeAxes(S32 index, const LinearColorF& nodeColor) const { if(mModel->mNodeTransforms.size() <= index || index < 0) return; @@ -1623,15 +1623,15 @@ void GuiShapeEdPreview::renderNodeAxes(S32 index, const ColorF& nodeColor) const GFX->pushWorldMatrix(); GFX->multWorld( mModel->mNodeTransforms[index] ); - - GFX->getDrawUtil()->drawCube( desc, xAxis * scale, Point3F::Zero, nodeColor ); - GFX->getDrawUtil()->drawCube( desc, yAxis * scale, Point3F::Zero, nodeColor ); - GFX->getDrawUtil()->drawCube( desc, zAxis * scale, Point3F::Zero, nodeColor ); + const ColorI color = LinearColorF(nodeColor).toColorI(); + GFX->getDrawUtil()->drawCube( desc, xAxis * scale, Point3F::Zero, color ); + GFX->getDrawUtil()->drawCube( desc, yAxis * scale, Point3F::Zero, color ); + GFX->getDrawUtil()->drawCube( desc, zAxis * scale, Point3F::Zero, color ); GFX->popWorldMatrix(); } -void GuiShapeEdPreview::renderNodeName(S32 index, const ColorF& textColor) const +void GuiShapeEdPreview::renderNodeName(S32 index, const LinearColorF& textColor) const { if(index < 0 || index >= mModel->getShape()->nodes.size() || index >= mProjectedNodes.size()) return; @@ -1640,7 +1640,7 @@ void GuiShapeEdPreview::renderNodeName(S32 index, const ColorF& textColor) const Point2I pos( mProjectedNodes[index].x, mProjectedNodes[index].y + sNodeRectSize + 6 ); - GFX->getDrawUtil()->setBitmapModulation( textColor ); + GFX->getDrawUtil()->setBitmapModulation( LinearColorF(textColor).toColorI()); GFX->getDrawUtil()->drawText( mProfile->mFont, pos, nodeName.c_str() ); } diff --git a/Engine/source/gui/editor/guiShapeEdPreview.h b/Engine/source/gui/editor/guiShapeEdPreview.h index 63789aaac..248b7be62 100644 --- a/Engine/source/gui/editor/guiShapeEdPreview.h +++ b/Engine/source/gui/editor/guiShapeEdPreview.h @@ -164,8 +164,8 @@ protected: // Rendering void renderGrid(); void renderNodes() const; - void renderNodeAxes(S32 index, const ColorF& nodeColor) const; - void renderNodeName(S32 index, const ColorF& textColor) const; + void renderNodeAxes(S32 index, const LinearColorF& nodeColor) const; + void renderNodeName(S32 index, const LinearColorF& textColor) const; void renderSunDirection() const; void renderCollisionMeshes() const; diff --git a/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp b/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp index d0f9549e1..b4eb118fc 100644 --- a/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp +++ b/Engine/source/gui/game/guiChunkedBitmapCtrl.cpp @@ -137,7 +137,7 @@ void GuiChunkedBitmapCtrl::renderRegion(const Point2I &offset, const Point2I &ex F32 widthScale = F32(extent.x) / F32(mTexHandle.getWidth()); F32 heightScale = F32(extent.y) / F32(mTexHandle.getHeight()); - GFX->setBitmapModulation(ColorF(1,1,1)); + GFX->setBitmapModulation(LinearColorF(1,1,1)); for(U32 i = 0; i < widthCount; i++) { for(U32 j = 0; j < heightCount; j++) diff --git a/Engine/source/gui/game/guiFadeinBitmapCtrl.cpp b/Engine/source/gui/game/guiFadeinBitmapCtrl.cpp index 18181d040..3af8130ac 100644 --- a/Engine/source/gui/game/guiFadeinBitmapCtrl.cpp +++ b/Engine/source/gui/game/guiFadeinBitmapCtrl.cpp @@ -194,7 +194,7 @@ void GuiFadeinBitmapCtrl::onRender(Point2I offset, const RectI &updateRect) // Render overlay on top of bitmap. - ColorI color = mFadeColor; + ColorI color = mFadeColor.toColorI(); color.alpha = alpha; GFX->getDrawUtil()->drawRectFill( offset, getExtent() + offset, color ); diff --git a/Engine/source/gui/game/guiFadeinBitmapCtrl.h b/Engine/source/gui/game/guiFadeinBitmapCtrl.h index d65b08dd1..c3508a3de 100644 --- a/Engine/source/gui/game/guiFadeinBitmapCtrl.h +++ b/Engine/source/gui/game/guiFadeinBitmapCtrl.h @@ -41,7 +41,7 @@ class GuiFadeinBitmapCtrl : public GuiBitmapCtrl protected: /// Color we fade in from and fade out to. - ColorF mFadeColor; + LinearColorF mFadeColor; /// Reference time on which to base all fade timings. U32 mStartTime; diff --git a/Engine/source/gui/worldEditor/editorIconRegistry.cpp b/Engine/source/gui/worldEditor/editorIconRegistry.cpp index 6dd1f2cc6..8507d2ad2 100644 --- a/Engine/source/gui/worldEditor/editorIconRegistry.cpp +++ b/Engine/source/gui/worldEditor/editorIconRegistry.cpp @@ -58,7 +58,7 @@ void EditorIconRegistry::loadFromPath( const String &path, bool overwrite ) String defaultIconFile = path + "default"; mDefaultIcon.set( defaultIconFile, - &GFXDefaultPersistentProfile, + &GFXTexturePersistentSRGBProfile, avar("%s() - mIcons[] (line %d)", __FUNCTION__, __LINE__) ); } @@ -66,7 +66,7 @@ void EditorIconRegistry::loadFromPath( const String &path, bool overwrite ) void EditorIconRegistry::add( const String &className, const String &imageFile, bool overwrite ) { // First see if we can load the image. - GFXTexHandle icon( imageFile, &GFXDefaultPersistentProfile, + GFXTexHandle icon( imageFile, &GFXTexturePersistentSRGBProfile, avar("%s() - mIcons[] (line %d)", __FUNCTION__, __LINE__) ); if ( icon.isNull() ) return; diff --git a/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp b/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp index e862620e4..6bc043d09 100644 --- a/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp +++ b/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp @@ -1035,7 +1035,7 @@ void GuiConvexEditorCtrl::drawFacePlane( ConvexShape *shape, S32 faceId ) GFX->setVertexBuffer( vb ); - GFXTexHandle tex( "core/art/grids/512_transp", &GFXDefaultStaticDiffuseProfile, "ConvexEditor_grid" ); + GFXTexHandle tex( "core/art/grids/512_transp", &GFXStaticTextureSRGBProfile, "ConvexEditor_grid" ); GFX->setTexture( 0, tex ); GFX->setupGenericShaders(); GFX->drawPrimitive( GFXTriangleList, 0, points.size() / 3 ); diff --git a/Engine/source/gui/worldEditor/guiMissionArea.cpp b/Engine/source/gui/worldEditor/guiMissionArea.cpp index 9b3670713..4e67e4d7c 100644 --- a/Engine/source/gui/worldEditor/guiMissionArea.cpp +++ b/Engine/source/gui/worldEditor/guiMissionArea.cpp @@ -116,7 +116,7 @@ bool GuiMissionAreaCtrl::onAdd() if (*mHandleBitmap) { - mHandleTexture = GFXTexHandle( mHandleBitmap, &GFXDefaultPersistentProfile, avar("%s() - mHandleTexture (line %d)", __FUNCTION__, __LINE__) ); + mHandleTexture = GFXTexHandle( mHandleBitmap, &GFXTexturePersistentSRGBProfile, avar("%s() - mHandleTexture (line %d)", __FUNCTION__, __LINE__) ); mHandleTextureSize = Point2I( mHandleTexture->getWidth(), mHandleTexture->getHeight() ); mHandleTextureHalfSize = Point2F(mHandleTextureSize.x, mHandleTextureSize.y) * 0.5f; } diff --git a/Engine/source/gui/worldEditor/terrainEditor.cpp b/Engine/source/gui/worldEditor/terrainEditor.cpp index c2462ac71..cf0429417 100644 --- a/Engine/source/gui/worldEditor/terrainEditor.cpp +++ b/Engine/source/gui/worldEditor/terrainEditor.cpp @@ -658,7 +658,7 @@ void SelectionBrush::rebuild() //... move the selection } -void SelectionBrush::render(Vector & vertexBuffer, S32 & verts, S32 & elems, S32 & prims, const ColorF & inColorFull, const ColorF & inColorNone, const ColorF & outColorFull, const ColorF & outColorNone) const +void SelectionBrush::render(Vector & vertexBuffer, S32 & verts, S32 & elems, S32 & prims, const LinearColorF & inColorFull, const LinearColorF & inColorNone, const LinearColorF & outColorFull, const LinearColorF & outColorNone) const { //... render the selection } @@ -1296,10 +1296,10 @@ void TerrainEditor::renderScene(const RectI &) return; if(!mSelectionHidden) - renderSelection(mDefaultSel, ColorF::RED, ColorF::GREEN, ColorF::BLUE, ColorF::BLUE, true, false); + renderSelection(mDefaultSel, LinearColorF::RED, LinearColorF::GREEN, LinearColorF::BLUE, LinearColorF::BLUE, true, false); if(mRenderBrush && mMouseBrush->size()) - renderBrush(*mMouseBrush, ColorF::GREEN, ColorF::RED, ColorF::BLUE, ColorF::BLUE, false, true); + renderBrush(*mMouseBrush, LinearColorF::GREEN, LinearColorF::RED, LinearColorF::BLUE, LinearColorF::BLUE, false, true); if(mRenderBorder) renderBorder(); @@ -1386,7 +1386,7 @@ void TerrainEditor::renderPoints( const Vector &pointList ) //------------------------------------------------------------------------------ -void TerrainEditor::renderSelection( const Selection & sel, const ColorF & inColorFull, const ColorF & inColorNone, const ColorF & outColorFull, const ColorF & outColorNone, bool renderFill, bool renderFrame ) +void TerrainEditor::renderSelection( const Selection & sel, const LinearColorF & inColorFull, const LinearColorF & inColorNone, const LinearColorF & outColorFull, const LinearColorF & outColorNone, bool renderFill, bool renderFrame ) { PROFILE_SCOPE( TerrainEditor_RenderSelection ); @@ -1395,7 +1395,7 @@ void TerrainEditor::renderSelection( const Selection & sel, const ColorF & inCol return; Vector vertexBuffer; - ColorF color; + LinearColorF color; ColorI iColor; vertexBuffer.setSize(sel.size() * 5); @@ -1428,7 +1428,7 @@ void TerrainEditor::renderSelection( const Selection & sel, const ColorF & inCol color.interpolate( outColorFull, outColorNone, weight ); } // - iColor = color; + iColor = color.toColorI(); GFXVertexPCT *verts = &(vertexBuffer[i * 5]); @@ -1479,17 +1479,17 @@ void TerrainEditor::renderSelection( const Selection & sel, const ColorF & inCol color.interpolate(outColorFull, outColorNone, weight ); } - iColor = color; + iColor = color.toColorI(); } else { if ( center ) { - iColor = inColorNone; + iColor = LinearColorF(inColorNone).toColorI(); } else { - iColor = outColorFull; + iColor = LinearColorF(outColorFull).toColorI(); } } @@ -1525,7 +1525,7 @@ void TerrainEditor::renderSelection( const Selection & sel, const ColorF & inCol GFX->drawPrimitive( GFXLineStrip , i*5, 4); } -void TerrainEditor::renderBrush( const Brush & brush, const ColorF & inColorFull, const ColorF & inColorNone, const ColorF & outColorFull, const ColorF & outColorNone, bool renderFill, bool renderFrame ) +void TerrainEditor::renderBrush( const Brush & brush, const LinearColorF & inColorFull, const LinearColorF & inColorNone, const LinearColorF & outColorFull, const LinearColorF & outColorNone, bool renderFill, bool renderFrame ) { } diff --git a/Engine/source/gui/worldEditor/terrainEditor.h b/Engine/source/gui/worldEditor/terrainEditor.h index 53c2aa79d..a2ed6b6de 100644 --- a/Engine/source/gui/worldEditor/terrainEditor.h +++ b/Engine/source/gui/worldEditor/terrainEditor.h @@ -173,7 +173,7 @@ public: const char *getType() const { return "selection"; } void rebuild(); - void render(Vector & vertexBuffer, S32 & verts, S32 & elems, S32 & prims, const ColorF & inColorFull, const ColorF & inColorNone, const ColorF & outColorFull, const ColorF & outColorNone) const; + void render(Vector & vertexBuffer, S32 & verts, S32 & elems, S32 & prims, const LinearColorF & inColorFull, const LinearColorF & inColorNone, const LinearColorF & outColorFull, const LinearColorF & outColorNone) const; void setSize(const Point2I &){} protected: @@ -416,8 +416,8 @@ class TerrainEditor : public EditTSCtrl void updateBrush(Brush & brush, const Point2I & gPos); // - void renderSelection(const Selection & sel, const ColorF & inColorFull, const ColorF & inColorNone, const ColorF & outColorFull, const ColorF & outColorNone, bool renderFill, bool renderFrame); - void renderBrush(const Brush & brush, const ColorF & inColorFull, const ColorF & inColorNone, const ColorF & outColorFull, const ColorF & outColorNone, bool renderFill, bool renderFrame); + void renderSelection(const Selection & sel, const LinearColorF & inColorFull, const LinearColorF & inColorNone, const LinearColorF & outColorFull, const LinearColorF & outColorNone, bool renderFill, bool renderFrame); + void renderBrush(const Brush & brush, const LinearColorF & inColorFull, const LinearColorF & inColorNone, const LinearColorF & outColorFull, const LinearColorF & outColorNone, bool renderFill, bool renderFrame); void renderBorder(); public: diff --git a/Engine/source/gui/worldEditor/worldEditor.cpp b/Engine/source/gui/worldEditor/worldEditor.cpp index 67c60601e..d4c4c55ab 100644 --- a/Engine/source/gui/worldEditor/worldEditor.cpp +++ b/Engine/source/gui/worldEditor/worldEditor.cpp @@ -1839,9 +1839,9 @@ bool WorldEditor::onAdd() // create the default class entry mDefaultClassEntry.mName = 0; mDefaultClassEntry.mIgnoreCollision = false; - mDefaultClassEntry.mDefaultHandle = GFXTexHandle(mDefaultHandle, &GFXDefaultStaticDiffuseProfile, avar("%s() - mDefaultClassEntry.mDefaultHandle (line %d)", __FUNCTION__, __LINE__)); - mDefaultClassEntry.mSelectHandle = GFXTexHandle(mSelectHandle, &GFXDefaultStaticDiffuseProfile, avar("%s() - mDefaultClassEntry.mSelectHandle (line %d)", __FUNCTION__, __LINE__)); - mDefaultClassEntry.mLockedHandle = GFXTexHandle(mLockedHandle, &GFXDefaultStaticDiffuseProfile, avar("%s() - mDefaultClassEntry.mLockedHandle (line %d)", __FUNCTION__, __LINE__)); + mDefaultClassEntry.mDefaultHandle = GFXTexHandle(mDefaultHandle, &GFXStaticTextureSRGBProfile, avar("%s() - mDefaultClassEntry.mDefaultHandle (line %d)", __FUNCTION__, __LINE__)); + mDefaultClassEntry.mSelectHandle = GFXTexHandle(mSelectHandle, &GFXStaticTextureSRGBProfile, avar("%s() - mDefaultClassEntry.mSelectHandle (line %d)", __FUNCTION__, __LINE__)); + mDefaultClassEntry.mLockedHandle = GFXTexHandle(mLockedHandle, &GFXStaticTextureSRGBProfile, avar("%s() - mDefaultClassEntry.mLockedHandle (line %d)", __FUNCTION__, __LINE__)); if(!(mDefaultClassEntry.mDefaultHandle && mDefaultClassEntry.mSelectHandle && mDefaultClassEntry.mLockedHandle)) return false; diff --git a/Engine/source/lighting/advanced/advancedLightBinManager.cpp b/Engine/source/lighting/advanced/advancedLightBinManager.cpp index 802a8545d..c10a1cbe3 100644 --- a/Engine/source/lighting/advanced/advancedLightBinManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightBinManager.cpp @@ -645,7 +645,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light MaterialParameters *matParams = matInstance->getMaterialParameters(); // Set color in the right format, set alpha to the luminance value for the color. - ColorF col = lightInfo->getColor(); + LinearColorF col = lightInfo->getColor(); // TODO: The specularity control of the light // is being scaled by the overall lumiance. @@ -658,7 +658,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light F32 lumiance = mDot(*((const Point3F *)&lightInfo->getColor()), colorToLumiance ); col.alpha *= lumiance; - matParams->setSafe( lightColor, col.toLinear() ); + matParams->setSafe( lightColor, col ); matParams->setSafe( lightBrightness, lightInfo->getBrightness() ); switch( lightInfo->getType() ) @@ -672,9 +672,9 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light // Set small number for alpha since it represents existing specular in // the vector light. This prevents a divide by zero. - ColorF ambientColor = renderState->getAmbientLightColor(); + LinearColorF ambientColor = renderState->getAmbientLightColor(); ambientColor.alpha = 0.00001f; - matParams->setSafe( lightAmbient, ambientColor.toLinear() ); + matParams->setSafe( lightAmbient, ambientColor ); // If no alt color is specified, set it to the average of // the ambient and main color to avoid artifacts. @@ -682,13 +682,13 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light // TODO: Trilight disabled until we properly implement it // in the light info! // - //ColorF lightAlt = lightInfo->getAltColor(); - ColorF lightAlt( ColorF::BLACK ); // = lightInfo->getAltColor(); + //LinearColorF lightAlt = lightInfo->getAltColor(); + LinearColorF lightAlt( LinearColorF::BLACK ); // = lightInfo->getAltColor(); if ( lightAlt.red == 0.0f && lightAlt.green == 0.0f && lightAlt.blue == 0.0f ) lightAlt = (lightInfo->getColor() + renderState->getAmbientLightColor()) / 2.0f; - ColorF trilightColor = lightAlt; - matParams->setSafe(lightTrilight, trilightColor.toLinear()); + LinearColorF trilightColor = lightAlt; + matParams->setSafe(lightTrilight, trilightColor); } break; @@ -787,7 +787,7 @@ bool LightMatInstance::setupPass( SceneRenderState *state, const SceneData &sgDa getMaterialParameters()->set( mLightMapParamsSC, lmParams->shadowDarkenColor ); } else - getMaterialParameters()->set( mLightMapParamsSC, ColorF::WHITE ); + getMaterialParameters()->set( mLightMapParamsSC, LinearColorF::WHITE ); } // Now override stateblock with our own diff --git a/Engine/source/lighting/advanced/advancedLightManager.cpp b/Engine/source/lighting/advanced/advancedLightManager.cpp index 5842ec717..0b14a12a4 100644 --- a/Engine/source/lighting/advanced/advancedLightManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightManager.cpp @@ -85,7 +85,7 @@ bool AdvancedLightManager::isCompatible() const // TODO: Test for the necessary texture formats! bool autoMips; - if(!GFX->getCardProfiler()->checkFormat(GFXFormatR16F, &GFXDefaultRenderTargetProfile, autoMips)) + if(!GFX->getCardProfiler()->checkFormat(GFXFormatR16F, &GFXRenderTargetProfile, autoMips)) return false; return true; @@ -106,7 +106,7 @@ void AdvancedLightManager::activate( SceneManager *sceneManager ) Vector formats; formats.push_back( GFXFormatR16G16B16A16F ); //formats.push_back( GFXFormatR16G16B16A16 ); - GFXFormat blendTargetFormat = GFX->selectSupportedFormat( &GFXDefaultRenderTargetProfile, + GFXFormat blendTargetFormat = GFX->selectSupportedFormat( &GFXRenderTargetProfile, formats, true, true, diff --git a/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp b/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp index ae80df058..44d13d313 100644 --- a/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp @@ -249,11 +249,7 @@ Var* GBufferConditionerGLSL::printMethodHeader( MethodType methodType, const Str // The gbuffer has no mipmaps, so use tex2dlod when // possible so that the shader compiler can optimize. - meta->addStatement( new GenOp( " #if TORQUE_SM >= 30\r\n" ) ); - meta->addStatement( new GenOp( " @ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, deferredSampler, screenUV ) ); - meta->addStatement( new GenOp( " #else\r\n" ) ); - meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n", bufferSampleDecl, deferredSampler, screenUV ) ); - meta->addStatement( new GenOp( " #endif\r\n\r\n" ) ); + meta->addStatement( new GenOp( "@ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, deferredSampler, screenUV ) ); // We don't use this way of passing var's around, so this should cause a crash // if something uses this improperly diff --git a/Engine/source/lighting/basic/blTerrainSystem.cpp b/Engine/source/lighting/basic/blTerrainSystem.cpp index eb286cbdc..d6fb3f9d5 100644 --- a/Engine/source/lighting/basic/blTerrainSystem.cpp +++ b/Engine/source/lighting/basic/blTerrainSystem.cpp @@ -96,7 +96,7 @@ protected: BitVector mShadowMask; ShadowVolumeBSP * mShadowVolume; - ColorF * mLightmap; + LinearColorF * mLightmap; /// The dimension of the lightmap in pixels. const U32 mLightMapSize; @@ -104,7 +104,7 @@ protected: /// The dimension of the terrain height map sample array. const U32 mTerrainBlockSize; - ColorF *sgBakedLightmap; + LinearColorF *sgBakedLightmap; Vector sgLights; bool sgMarkStaticShadow(void *terrainproxy, SceneObject *sceneobject, LightInfo *light); //void postLight(bool lastLight); @@ -122,7 +122,7 @@ protected: bool markObjectShadow(ObjectProxy *); bool sgIsCorrectStaticObjectType(SceneObject *obj); - inline ColorF _getValue( S32 row, S32 column ); + inline LinearColorF _getValue( S32 row, S32 column ); public: @@ -173,8 +173,8 @@ blTerrainProxy::~blTerrainProxy() //------------------------------------------------------------------------------- void blTerrainProxy::init() { - mLightmap = new ColorF[ mLightMapSize * mLightMapSize ]; - dMemset(mLightmap, 0, mLightMapSize * mLightMapSize * sizeof(ColorF)); + mLightmap = new LinearColorF[ mLightMapSize * mLightMapSize ]; + dMemset(mLightmap, 0, mLightMapSize * mLightMapSize * sizeof(LinearColorF)); mShadowMask.setSize( mTerrainBlockSize * mTerrainBlockSize ); } @@ -190,7 +190,7 @@ bool blTerrainProxy::preLight(LightInfo * light) return(true); } -inline ColorF blTerrainProxy::_getValue( S32 row, S32 column ) +inline LinearColorF blTerrainProxy::_getValue( S32 row, S32 column ) { while( row < 0 ) row += mLightMapSize; @@ -282,7 +282,7 @@ void blTerrainProxy::light(LightInfo * light) for( U32 j=0; j < mLightMapSize; j++ ) { - ColorF val; + LinearColorF val; val = _getValue( i-1, j-1 ) * kernel[0][0]; val += _getValue( i-1, j ) * kernel[0][1]; val += _getValue( i-1, j+1 ) * kernel[0][2]; @@ -583,7 +583,7 @@ void blTerrainProxy::lightVector(LightInfo * light) } // Set the final lightmap color. - mLightmap[i++] += ColorF::WHITE * mClampF( 1.0f - shadowed, 0.0f, 1.0f ); + mLightmap[i++] += LinearColorF::WHITE * mClampF( 1.0f - shadowed, 0.0f, 1.0f ); } } } @@ -688,7 +688,7 @@ bool blTerrainSystem::createPersistChunkFromProxy(SceneLighting::ObjectProxy* ob } // Given a ray, this will return the color from the lightmap of this object, return true if handled -bool blTerrainSystem::getColorFromRayInfo(const RayInfo & collision, ColorF& result) const +bool blTerrainSystem::getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const { TerrainBlock *terrain = dynamic_cast(collision.object); if (!terrain) diff --git a/Engine/source/lighting/basic/blTerrainSystem.h b/Engine/source/lighting/basic/blTerrainSystem.h index 9de7c4fe4..2098d43e5 100644 --- a/Engine/source/lighting/basic/blTerrainSystem.h +++ b/Engine/source/lighting/basic/blTerrainSystem.h @@ -43,7 +43,7 @@ public: virtual bool createPersistChunkFromProxy(SceneLighting::ObjectProxy* objproxy, PersistInfo::PersistChunk **ret); // Given a ray, this will return the color from the lightmap of this object, return true if handled - virtual bool getColorFromRayInfo(const RayInfo & collision, ColorF& result) const; + virtual bool getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const; }; #endif // !_BLTERRAINSYSTEM_H_ diff --git a/Engine/source/lighting/common/blobShadow.cpp b/Engine/source/lighting/common/blobShadow.cpp index 48bfb1e52..a564ff654 100644 --- a/Engine/source/lighting/common/blobShadow.cpp +++ b/Engine/source/lighting/common/blobShadow.cpp @@ -138,7 +138,7 @@ void BlobShadow::generateGenericShadowBitmap(S32 dim) } } - smGenericShadowTexture.set( bitmap, &GFXDefaultStaticDiffuseProfile, true, "BlobShadow" ); + smGenericShadowTexture.set( bitmap, &GFXStaticTextureSRGBProfile, true, "BlobShadow" ); } //-------------------------------------------------------------- diff --git a/Engine/source/lighting/common/lightMapParams.h b/Engine/source/lighting/common/lightMapParams.h index 7a1b2bcec..4d495537f 100644 --- a/Engine/source/lighting/common/lightMapParams.h +++ b/Engine/source/lighting/common/lightMapParams.h @@ -47,7 +47,7 @@ public: // for console protected fields. bool representedInLightmap; ///< This light is represented in lightmaps (static light, default: false) - ColorF shadowDarkenColor; ///< The color that should be used to multiply-blend dynamic shadows onto lightmapped geometry (ignored if 'representedInLightmap' is false) + LinearColorF shadowDarkenColor; ///< The color that should be used to multiply-blend dynamic shadows onto lightmapped geometry (ignored if 'representedInLightmap' is false) bool includeLightmappedGeometryInShadow; ///< This light should render lightmapped geometry during its shadow-map update (ignored if 'representedInLightmap' is false) }; diff --git a/Engine/source/lighting/lightInfo.h b/Engine/source/lighting/lightInfo.h index e485dba70..0966b771f 100644 --- a/Engine/source/lighting/lightInfo.h +++ b/Engine/source/lighting/lightInfo.h @@ -115,11 +115,11 @@ protected: Type mType; /// The primary light color. - ColorF mColor; + LinearColorF mColor; F32 mBrightness; - ColorF mAmbient; + LinearColorF mAmbient; MatrixF mTransform; @@ -172,14 +172,14 @@ public: VectorF getDirection() const { return mTransform.getForwardVector(); } void setDirection( const VectorF &val ); - const ColorF& getColor() const { return mColor; } - void setColor( const ColorF &val ) { mColor = val; } + const LinearColorF& getColor() const { return mColor; } + void setColor( const LinearColorF &val ) { mColor = val; } F32 getBrightness() const { return mBrightness; } void setBrightness( F32 val ) { mBrightness = val; } - const ColorF& getAmbient() const { return mAmbient; } - void setAmbient( const ColorF &val ) { mAmbient = val; } + const LinearColorF& getAmbient() const { return mAmbient; } + void setAmbient( const LinearColorF &val ) { mAmbient = val; } const Point3F& getRange() const { return mRange; } void setRange( const Point3F &range ) { mRange = range; } diff --git a/Engine/source/lighting/lightingInterfaces.h b/Engine/source/lighting/lightingInterfaces.h index 54f8f7aea..dc4db77a4 100644 --- a/Engine/source/lighting/lightingInterfaces.h +++ b/Engine/source/lighting/lightingInterfaces.h @@ -117,7 +117,7 @@ public: // Runtime / dynamic methods // // Given a ray, this will return the color from the lightmap of this object, return true if handled - virtual bool getColorFromRayInfo(const RayInfo & collision, ColorF& result) const { return false; } + virtual bool getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const { return false; } }; #endif diff --git a/Engine/source/lighting/shadowMap/lightShadowMap.cpp b/Engine/source/lighting/shadowMap/lightShadowMap.cpp index 8974cce88..7e18abbb8 100644 --- a/Engine/source/lighting/shadowMap/lightShadowMap.cpp +++ b/Engine/source/lighting/shadowMap/lightShadowMap.cpp @@ -210,18 +210,18 @@ void LightShadowMap::calcLightMatrices( MatrixF &outLightMatrix, const Frustum & //SceneManager::setVisibleDistance(width * 2.0f); #if 0 - DebugDrawer::get()->drawFrustum(viewFrustum, ColorF(1.0f, 0.0f, 0.0f)); - DebugDrawer::get()->drawBox(viewBB.minExtents, viewBB.maxExtents, ColorF(0.0f, 1.0f, 0.0f)); - DebugDrawer::get()->drawBox(lightViewBB.minExtents, lightViewBB.maxExtents, ColorF(0.0f, 0.0f, 1.0f)); - DebugDrawer::get()->drawBox(newLightPos - Point3F(1,1,1), newLightPos + Point3F(1,1,1), ColorF(1,1,0)); - DebugDrawer::get()->drawLine(newLightPos, newLightPos + mLight.mDirection*3.0f, ColorF(0,1,1)); + DebugDrawer::get()->drawFrustum(viewFrustum, LinearColorF(1.0f, 0.0f, 0.0f)); + DebugDrawer::get()->drawBox(viewBB.minExtents, viewBB.maxExtents, LinearColorF(0.0f, 1.0f, 0.0f)); + DebugDrawer::get()->drawBox(lightViewBB.minExtents, lightViewBB.maxExtents, LinearColorF(0.0f, 0.0f, 1.0f)); + DebugDrawer::get()->drawBox(newLightPos - Point3F(1,1,1), newLightPos + Point3F(1,1,1), LinearColorF(1,1,0)); + DebugDrawer::get()->drawLine(newLightPos, newLightPos + mLight.mDirection*3.0f, LinearColorF(0,1,1)); Point3F a(newLightPos); Point3F b(newLightPos); Point3F offset(width, height,0.0f); a -= offset; b += offset; - DebugDrawer::get()->drawBox(a, b, ColorF(0.5f, 0.5f, 0.5f)); + DebugDrawer::get()->drawBox(a, b, LinearColorF(0.5f, 0.5f, 0.5f)); #endif } break; @@ -719,7 +719,7 @@ GFXTextureObject* ShadowMapParams::getCookieTex() cookie != mCookieTex->getPath() ) ) { mCookieTex.set( cookie, - &GFXDefaultStaticDiffuseProfile, + &GFXStaticTextureSRGBProfile, "ShadowMapParams::getCookieTex()" ); } else if ( cookie.isEmpty() ) diff --git a/Engine/source/materials/matInstance.cpp b/Engine/source/materials/matInstance.cpp index bfc87054b..33b6357c9 100644 --- a/Engine/source/materials/matInstance.cpp +++ b/Engine/source/materials/matInstance.cpp @@ -141,7 +141,7 @@ void MatInstParameters::set(MaterialParameterHandle* handle, const Point4F& fv) MATINSTPARAMSET(handle, fv); } -void MatInstParameters::set(MaterialParameterHandle* handle, const ColorF& fv) +void MatInstParameters::set(MaterialParameterHandle* handle, const LinearColorF& fv) { MATINSTPARAMSET(handle, fv); } diff --git a/Engine/source/materials/matInstance.h b/Engine/source/materials/matInstance.h index ed498fa23..11178a42c 100644 --- a/Engine/source/materials/matInstance.h +++ b/Engine/source/materials/matInstance.h @@ -161,7 +161,7 @@ public: virtual void set(MaterialParameterHandle* handle, const Point2F& fv); virtual void set(MaterialParameterHandle* handle, const Point3F& fv); virtual void set(MaterialParameterHandle* handle, const Point4F& fv); - virtual void set(MaterialParameterHandle* handle, const ColorF& fv); + virtual void set(MaterialParameterHandle* handle, const LinearColorF& fv); virtual void set(MaterialParameterHandle* handle, const S32 f); virtual void set(MaterialParameterHandle* handle, const Point2I& fv); virtual void set(MaterialParameterHandle* handle, const Point3I& fv); diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 947b7b9b9..d4ec8ed7d 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -115,6 +115,7 @@ Material::Material() for( U32 i=0; imTexSlot[i].texObject = _createTexture( filename, &GFXDefaultStaticDiffuseProfile ); + rpd->mTexSlot[i].texObject = _createTexture( filename, &GFXStaticTextureSRGBProfile ); if ( !rpd->mTexSlot[i].texObject ) { mMaterial->logError("Failed to load texture %s", _getTexturePath(filename).c_str()); diff --git a/Engine/source/materials/processedFFMaterial.cpp b/Engine/source/materials/processedFFMaterial.cpp index 46065bca1..8f767eeb4 100644 --- a/Engine/source/materials/processedFFMaterial.cpp +++ b/Engine/source/materials/processedFFMaterial.cpp @@ -248,7 +248,7 @@ void ProcessedFFMaterial::setSceneInfo(SceneRenderState * state, const SceneData void ProcessedFFMaterial::_setPrimaryLightInfo(const MatrixF &_objTrans, LightInfo* light, U32 pass) { // Just in case - GFX->setGlobalAmbientColor(ColorF(0.0f, 0.0f, 0.0f, 1.0f)); + GFX->setGlobalAmbientColor(LinearColorF(0.0f, 0.0f, 0.0f, 1.0f)); if ( light->getType() == LightInfo::Ambient ) { // Ambient light @@ -260,10 +260,10 @@ void ProcessedFFMaterial::_setPrimaryLightInfo(const MatrixF &_objTrans, LightIn GFX->setLight(1, NULL); // This is a quick hack that lets us use FF lights GFXLightMaterial lightMat; - lightMat.ambient = ColorF(1.0f, 1.0f, 1.0f, 1.0f); - lightMat.diffuse = ColorF(1.0f, 1.0f, 1.0f, 1.0f); - lightMat.emissive = ColorF(0.0f, 0.0f, 0.0f, 0.0f); - lightMat.specular = ColorF(0.0f, 0.0f, 0.0f, 0.0f); + lightMat.ambient = LinearColorF(1.0f, 1.0f, 1.0f, 1.0f); + lightMat.diffuse = LinearColorF(1.0f, 1.0f, 1.0f, 1.0f); + lightMat.emissive = LinearColorF(0.0f, 0.0f, 0.0f, 0.0f); + lightMat.specular = LinearColorF(0.0f, 0.0f, 0.0f, 0.0f); lightMat.shininess = 128.0f; GFX->setLightMaterial(lightMat); diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index 6960212c9..1622d50e6 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -275,6 +275,8 @@ void ProcessedMaterial::_initPassStateBlock( RenderPassData *rpd, GFXStateBlockD result.samplers[i].addressModeU = GFXAddressClamp; result.samplers[i].addressModeV = GFXAddressClamp; result.samplers[i].addressModeW = GFXAddressClamp; + result.samplers[i].minFilter = GFXTextureFilterLinear; + result.samplers[i].magFilter = GFXTextureFilterLinear; break; } @@ -389,7 +391,7 @@ void ProcessedMaterial::_setStageData() // DiffuseMap if( mMaterial->mDiffuseMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_DiffuseMap, _createTexture( mMaterial->mDiffuseMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_DiffuseMap, _createTexture( mMaterial->mDiffuseMapFilename[i], &GFXStaticTextureSRGBProfile) ); if (!mStages[i].getTex( MFT_DiffuseMap )) { //If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass. So we'll @@ -399,14 +401,14 @@ void ProcessedMaterial::_setStageData() // Load a debug texture to make it clear to the user // that the texture for this stage was missing. - mStages[i].setTex( MFT_DiffuseMap, _createTexture( GFXTextureManager::getMissingTexturePath().c_str(), &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_DiffuseMap, _createTexture( GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile) ); } } // OverlayMap if( mMaterial->mOverlayMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_OverlayMap, _createTexture( mMaterial->mOverlayMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_OverlayMap, _createTexture( mMaterial->mOverlayMapFilename[i], &GFXStaticTextureSRGBProfile ) ); if(!mStages[i].getTex( MFT_OverlayMap )) mMaterial->logError("Failed to load overlay map %s for stage %i", _getTexturePath(mMaterial->mOverlayMapFilename[i]).c_str(), i); } @@ -414,7 +416,7 @@ void ProcessedMaterial::_setStageData() // LightMap if( mMaterial->mLightMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_LightMap, _createTexture( mMaterial->mLightMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_LightMap, _createTexture( mMaterial->mLightMapFilename[i], &GFXStaticTextureSRGBProfile ) ); if(!mStages[i].getTex( MFT_LightMap )) mMaterial->logError("Failed to load light map %s for stage %i", _getTexturePath(mMaterial->mLightMapFilename[i]).c_str(), i); } @@ -422,7 +424,7 @@ void ProcessedMaterial::_setStageData() // ToneMap if( mMaterial->mToneMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_ToneMap, _createTexture( mMaterial->mToneMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_ToneMap, _createTexture( mMaterial->mToneMapFilename[i], &GFXStaticTextureProfile) ); if(!mStages[i].getTex( MFT_ToneMap )) mMaterial->logError("Failed to load tone map %s for stage %i", _getTexturePath(mMaterial->mToneMapFilename[i]).c_str(), i); } @@ -430,7 +432,7 @@ void ProcessedMaterial::_setStageData() // DetailMap if( mMaterial->mDetailMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_DetailMap, _createTexture( mMaterial->mDetailMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_DetailMap, _createTexture( mMaterial->mDetailMapFilename[i], &GFXStaticTextureProfile) ); if(!mStages[i].getTex( MFT_DetailMap )) mMaterial->logError("Failed to load detail map %s for stage %i", _getTexturePath(mMaterial->mDetailMapFilename[i]).c_str(), i); } @@ -438,7 +440,7 @@ void ProcessedMaterial::_setStageData() // NormalMap if( mMaterial->mNormalMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_NormalMap, _createTexture( mMaterial->mNormalMapFilename[i], &GFXDefaultStaticNormalMapProfile ) ); + mStages[i].setTex( MFT_NormalMap, _createTexture( mMaterial->mNormalMapFilename[i], &GFXNormalMapProfile) ); if(!mStages[i].getTex( MFT_NormalMap )) mMaterial->logError("Failed to load normal map %s for stage %i", _getTexturePath(mMaterial->mNormalMapFilename[i]).c_str(), i); } @@ -446,7 +448,7 @@ void ProcessedMaterial::_setStageData() // Detail Normal Map if( mMaterial->mDetailNormalMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_DetailNormalMap, _createTexture( mMaterial->mDetailNormalMapFilename[i], &GFXDefaultStaticNormalMapProfile ) ); + mStages[i].setTex( MFT_DetailNormalMap, _createTexture( mMaterial->mDetailNormalMapFilename[i], &GFXNormalMapProfile) ); if(!mStages[i].getTex( MFT_DetailNormalMap )) mMaterial->logError("Failed to load normal map %s for stage %i", _getTexturePath(mMaterial->mDetailNormalMapFilename[i]).c_str(), i); } @@ -454,7 +456,7 @@ void ProcessedMaterial::_setStageData() // SpecularMap if( mMaterial->mSpecularMapFilename[i].isNotEmpty() ) { - mStages[i].setTex( MFT_SpecularMap, _createTexture( mMaterial->mSpecularMapFilename[i], &GFXDefaultStaticDiffuseProfile ) ); + mStages[i].setTex( MFT_SpecularMap, _createTexture( mMaterial->mSpecularMapFilename[i], &GFXStaticTextureProfile) ); if(!mStages[i].getTex( MFT_SpecularMap )) mMaterial->logError("Failed to load specular map %s for stage %i", _getTexturePath(mMaterial->mSpecularMapFilename[i]).c_str(), i); } diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index a86d3144d..4fb2acc94 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -76,6 +76,7 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/ mWorldToObjSC = shader->getShaderConstHandle(ShaderGenVars::worldToObj); mViewToObjSC = shader->getShaderConstHandle(ShaderGenVars::viewToObj); mCubeTransSC = shader->getShaderConstHandle(ShaderGenVars::cubeTrans); + mCubeMipsSC = shader->getShaderConstHandle(ShaderGenVars::cubeMips); mObjTransSC = shader->getShaderConstHandle(ShaderGenVars::objTrans); mCubeEyePosSC = shader->getShaderConstHandle(ShaderGenVars::cubeEyePos); mEyePosSC = shader->getShaderConstHandle(ShaderGenVars::eyePos); @@ -270,7 +271,7 @@ U32 ProcessedShaderMaterial::getNumStages() // If this stage has diffuse color, it's active if ( mMaterial->mDiffuse[i].alpha > 0 && - mMaterial->mDiffuse[i] != ColorF::WHITE ) + mMaterial->mDiffuse[i] != LinearColorF::WHITE ) stageActive = true; // If we have a Material that is vertex lit @@ -394,9 +395,12 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, if ( fd.features[ MFT_NormalMap ] ) { - if ( mStages[stageNum].getTex( MFT_NormalMap )->mFormat == GFXFormatDXT5 && + if ( mStages[stageNum].getTex( MFT_NormalMap )->mFormat == GFXFormatBC3 && !mStages[stageNum].getTex( MFT_NormalMap )->mHasTransparency ) - fd.features.addFeature( MFT_IsDXTnm ); + fd.features.addFeature( MFT_IsBC3nm ); + else if ( mStages[stageNum].getTex(MFT_NormalMap)->mFormat == GFXFormatBC5 && + !mStages[stageNum].getTex(MFT_NormalMap)->mHasTransparency ) + fd.features.addFeature( MFT_IsBC5nm ); } // Now for some more advanced features that we @@ -461,7 +465,7 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, // If we have a diffuse map and the alpha on the diffuse isn't // zero and the color isn't pure white then multiply the color. else if ( mMaterial->mDiffuse[stageNum].alpha > 0.0f && - mMaterial->mDiffuse[stageNum] != ColorF::WHITE ) + mMaterial->mDiffuse[stageNum] != LinearColorF::WHITE ) fd.features.addFeature( MFT_DiffuseColor ); // If lightmaps or tonemaps are enabled or we @@ -1096,7 +1100,7 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons if ( handles->mSubSurfaceParamsSC->isValid() ) { Point4F subSurfParams; - dMemcpy( &subSurfParams, &mMaterial->mSubSurfaceColor[stageNum], sizeof(ColorF) ); + dMemcpy( &subSurfParams, &mMaterial->mSubSurfaceColor[stageNum], sizeof(LinearColorF) ); subSurfParams.w = mMaterial->mSubSurfaceRolloff[stageNum]; shaderConsts->set(handles->mSubSurfaceParamsSC, subSurfParams); } diff --git a/Engine/source/materials/processedShaderMaterial.h b/Engine/source/materials/processedShaderMaterial.h index b107a52e8..ee0781b95 100644 --- a/Engine/source/materials/processedShaderMaterial.h +++ b/Engine/source/materials/processedShaderMaterial.h @@ -65,6 +65,7 @@ public: GFXShaderConstHandle* mWorldToObjSC; GFXShaderConstHandle* mViewToObjSC; GFXShaderConstHandle* mCubeTransSC; + GFXShaderConstHandle* mCubeMipsSC; GFXShaderConstHandle* mObjTransSC; GFXShaderConstHandle* mCubeEyePosSC; GFXShaderConstHandle* mEyePosSC; diff --git a/Engine/source/materials/sceneData.h b/Engine/source/materials/sceneData.h index 14c289d35..99fc8ef52 100644 --- a/Engine/source/materials/sceneData.h +++ b/Engine/source/materials/sceneData.h @@ -71,13 +71,13 @@ struct SceneData LightInfo* lights[8]; /// - ColorF ambientLightColor; + LinearColorF ambientLightColor; // fog F32 fogDensity; F32 fogDensityOffset; F32 fogHeightFalloff; - ColorF fogColor; + LinearColorF fogColor; // misc const MatrixF *objTrans; diff --git a/Engine/source/materials/shaderMaterialParameters.cpp b/Engine/source/materials/shaderMaterialParameters.cpp index d929014f8..4c48156c2 100644 --- a/Engine/source/materials/shaderMaterialParameters.cpp +++ b/Engine/source/materials/shaderMaterialParameters.cpp @@ -131,7 +131,7 @@ void ShaderMaterialParameters::set(MaterialParameterHandle* handle, const PlaneF SHADERMATPARAM_SET(handle, fv); } -void ShaderMaterialParameters::set(MaterialParameterHandle* handle, const ColorF& fv) +void ShaderMaterialParameters::set(MaterialParameterHandle* handle, const LinearColorF& fv) { SHADERMATPARAM_SET(handle, fv); } diff --git a/Engine/source/materials/shaderMaterialParameters.h b/Engine/source/materials/shaderMaterialParameters.h index 021d7729d..4a26251db 100644 --- a/Engine/source/materials/shaderMaterialParameters.h +++ b/Engine/source/materials/shaderMaterialParameters.h @@ -73,7 +73,7 @@ public: virtual void set(MaterialParameterHandle* handle, const Point3F& fv); virtual void set(MaterialParameterHandle* handle, const Point4F& fv); virtual void set(MaterialParameterHandle* handle, const PlaneF& fv); - virtual void set(MaterialParameterHandle* handle, const ColorF& fv); + virtual void set(MaterialParameterHandle* handle, const LinearColorF& fv); virtual void set(MaterialParameterHandle* handle, const S32 f); virtual void set(MaterialParameterHandle* handle, const Point2I& fv); virtual void set(MaterialParameterHandle* handle, const Point3I& fv); diff --git a/Engine/source/persistence/taml/taml.cpp b/Engine/source/persistence/taml/taml.cpp index 9f433af11..21e1e3d0b 100644 --- a/Engine/source/persistence/taml/taml.cpp +++ b/Engine/source/persistence/taml/taml.cpp @@ -1190,8 +1190,8 @@ bool Taml::generateTamlSchema() pColorEnumsRestrictionElement->LinkEndChild( pColorEnumsAttributeEnumerationElement ); } - // ColorF. - TiXmlComment* pColorFValuesComment = new TiXmlComment( "ColorF Values" ); + // LinearColorF. + TiXmlComment* pColorFValuesComment = new TiXmlComment( "LinearColorF Values" ); pSchemaElement->LinkEndChild( pColorFValuesComment ); TiXmlElement* pColorFValuesTypeElement = new TiXmlElement( "xs:simpleType" ); pColorFValuesTypeElement->SetAttribute( "name", "ColorF_Values" ); @@ -1203,7 +1203,7 @@ bool Taml::generateTamlSchema() pColorFValuesElementB->SetAttribute( "value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b" ); pColorFValuesElementA->LinkEndChild( pColorFValuesElementB ); - TiXmlComment* pColorFComment = new TiXmlComment( "ColorF Console Type" ); + TiXmlComment* pColorFComment = new TiXmlComment( "LinearColorF Console Type" ); pSchemaElement->LinkEndChild( pColorFComment ); TiXmlElement* pColorFTypeElement = new TiXmlElement( "xs:simpleType" ); pColorFTypeElement->SetAttribute( "name", "ColorF_ConsoleType" ); diff --git a/Engine/source/persistence/taml/tamlCustom.h b/Engine/source/persistence/taml/tamlCustom.h index cc018f041..261c77dde 100644 --- a/Engine/source/persistence/taml/tamlCustom.h +++ b/Engine/source/persistence/taml/tamlCustom.h @@ -112,16 +112,16 @@ public: set( pFieldName, pFieldValue ); } - inline void setFieldValue( const char* pFieldName, const ColorF& fieldValue ) + inline void setFieldValue( const char* pFieldName, const LinearColorF& fieldValue ) { // Fetch the field value. - const char* pFieldValue = Con::getData( TypeColorF, &const_cast(fieldValue), 0 ); + const char* pFieldValue = Con::getData( TypeColorF, &const_cast(fieldValue), 0 ); // Did we get a field value? if ( pFieldValue == NULL ) { // No, so warn. - Con::warnf( "Taml: Failed to add node field name '%s' with ColorF value.", pFieldName ); + Con::warnf( "Taml: Failed to add node field name '%s' with LinearColorF value.", pFieldName ); pFieldValue = StringTable->EmptyString(); } @@ -211,7 +211,7 @@ public: set( pFieldName, fieldValue ); } - inline void getFieldValue( ColorF& fieldValue ) const + inline void getFieldValue( LinearColorF& fieldValue ) const { fieldValue.set( 1.0f, 1.0f, 1.0f, 1.0f ); @@ -476,7 +476,7 @@ public: return registerField( pNodeField ); } - inline TamlCustomField* addField( const char* pFieldName, const ColorF& fieldValue ) + inline TamlCustomField* addField( const char* pFieldName, const LinearColorF& fieldValue ) { TamlCustomField* pNodeField = TamlCustomFieldFactory.createObject(); pNodeField->setFieldValue( pFieldName, fieldValue ); diff --git a/Engine/source/platformSDL/sdlPlatformGL.cpp b/Engine/source/platformSDL/sdlPlatformGL.cpp index 47eab147b..b7a6a2c92 100644 --- a/Engine/source/platformSDL/sdlPlatformGL.cpp +++ b/Engine/source/platformSDL/sdlPlatformGL.cpp @@ -24,6 +24,7 @@ namespace PlatformGL SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorOGL); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag); + SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); #ifdef TORQUE_GL_SOFTWARE SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 0); #endif diff --git a/Engine/source/platformWin32/winWindow.cpp b/Engine/source/platformWin32/winWindow.cpp index bede84739..74738f3b5 100644 --- a/Engine/source/platformWin32/winWindow.cpp +++ b/Engine/source/platformWin32/winWindow.cpp @@ -30,7 +30,6 @@ #include "math/mRandom.h" #include "core/stream/fileStream.h" #include "T3D/resource.h" -#include #include "gfx/gfxInit.h" #include "gfx/gfxDevice.h" #include "core/strings/unicode.h" diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index c407dec8f..ce6e9ffc0 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -144,6 +144,11 @@ GFX_ImplementTextureProfile( PostFxTextureProfile, GFXTextureProfile::Static | GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap, GFXTextureProfile::NONE ); +GFX_ImplementTextureProfile( PostFxTextureSRGBProfile, + GFXTextureProfile::DiffuseMap, + GFXTextureProfile::Static | GFXTextureProfile::PreserveSize | GFXTextureProfile::NoMipmap | GFXTextureProfile::SRGB, + GFXTextureProfile::NONE); + GFX_ImplementTextureProfile( VRTextureProfile, GFXTextureProfile::DiffuseMap, GFXTextureProfile::PreserveSize | @@ -275,7 +280,7 @@ PostEffect::PostEffect() mTargetViewport( PFXTargetViewport_TargetSize ), mTargetSize( Point2I::Zero ), mTargetFormat( GFXFormatR8G8B8A8 ), - mTargetClearColor( ColorF::BLACK ), + mTargetClearColor( LinearColorF::BLACK ), mOneFrameOnly( false ), mOnThisFrame( true ), mRTSizeSC( NULL ), @@ -306,6 +311,7 @@ PostEffect::PostEffect() mDeltaTimeSC( NULL ), mInvCameraMatSC( NULL ) { + dMemset( mTexSRGB, 0, sizeof(bool) * NumTextures); dMemset( mActiveTextures, 0, sizeof( GFXTextureObject* ) * NumTextures ); dMemset( mActiveNamedTarget, 0, sizeof( NamedTexTarget* ) * NumTextures ); dMemset( mActiveTextureViewport, 0, sizeof( RectI ) * NumTextures ); @@ -358,6 +364,9 @@ void PostEffect::initPersistFields() "Input textures to this effect ( samplers ).\n" "@see PFXTextureIdentifiers" ); + addField("textureSRGB", TypeBool, Offset(mTexSRGB, PostEffect), NumTextures, + "Set input texture to be sRGB"); + addField( "renderTime", TYPEID< PFXRenderTime >(), Offset( mRenderTime, PostEffect ), "When to process this effect during the frame." ); @@ -411,6 +420,10 @@ bool PostEffect::onAdd() texFilename[0] == '#' ) continue; + GFXTextureProfile *profile = &PostFxTextureProfile; + if (mTexSRGB[i]) + profile = &PostFxTextureSRGBProfile; + // Try to load the texture. bool success = mTextures[i].set( texFilename, &PostFxTextureProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); if (!success) @@ -730,7 +743,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state ) if (mAmbientColorSC->isValid() && state) { - const ColorF &sunlight = state->getAmbientLightColor(); + const LinearColorF &sunlight = state->getAmbientLightColor(); Point3F ambientColor( sunlight.red, sunlight.green, sunlight.blue ); mShaderConsts->set( mAmbientColorSC, ambientColor ); @@ -751,7 +764,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state ) if ( mWaterColorSC->isValid() ) { - ColorF color( state->getSceneManager()->getWaterFogData().color ); + LinearColorF color( state->getSceneManager()->getWaterFogData().color ); mShaderConsts->set( mWaterColorSC, color ); } @@ -1067,7 +1080,7 @@ void PostEffect::_setupTarget( const SceneRenderState *state, bool *outClearTarg mTargetDepthStencil.getWidthHeight() != targetSize ) { mTargetDepthStencil.set( targetSize.x, targetSize.y, GFXFormatD24S8, - &GFXDefaultZTargetProfile, "PostEffect::_setupTarget" ); + &GFXZTargetProfile, "PostEffect::_setupTarget" ); if ( mTargetClear == PFXTargetClear_OnCreate ) *outClearTarget = true; @@ -1696,7 +1709,7 @@ DefineEngineFunction( dumpRandomNormalMap, void, (),, { GFXTexHandle tex; - tex.set( 64, 64, GFXFormatR8G8B8A8, &GFXDefaultPersistentProfile, "" ); + tex.set( 64, 64, GFXFormatR8G8B8A8, &GFXTexturePersistentProfile, "" ); GFXLockedRect *rect = tex.lock(); U8 *f = rect->bits; diff --git a/Engine/source/postFx/postEffect.h b/Engine/source/postFx/postEffect.h index 812738ba3..fc086e77d 100644 --- a/Engine/source/postFx/postEffect.h +++ b/Engine/source/postFx/postEffect.h @@ -86,6 +86,7 @@ public: protected: FileName mTexFilename[NumTextures]; + bool mTexSRGB[NumTextures]; GFXTexHandle mTextures[NumTextures]; @@ -169,7 +170,7 @@ protected: /// The color to prefill the named target when /// first created by the effect. - ColorF mTargetClearColor; + LinearColorF mTargetClearColor; PFXRenderTime mRenderTime; PFXTargetClear mTargetClear; diff --git a/Engine/source/renderInstance/renderDeferredMgr.cpp b/Engine/source/renderInstance/renderDeferredMgr.cpp index d1ef53610..434fd585a 100644 --- a/Engine/source/renderInstance/renderDeferredMgr.cpp +++ b/Engine/source/renderInstance/renderDeferredMgr.cpp @@ -152,39 +152,34 @@ bool RenderDeferredMgr::_updateTargets() // reload materials, the conditioner needs to alter the generated shaders } - GFXFormat colorFormat = mTargetFormat; - - /* - bool independentMrtBitDepth = GFX->getCardProfiler()->queryProfile("independentMrtBitDepth", false); - //If independent bit depth on a MRT is supported than just use 8bit channels for the albedo color. - if(independentMrtBitDepth) - colorFormat = GFXFormatR8G8B8A8; - */ + // TODO: these formats should be passed in and not hard-coded + const GFXFormat colorFormat = GFXFormatR8G8B8A8_SRGB; + const GFXFormat matInfoFormat = GFXFormatR8G8B8A8; // andrewmac: Deferred Shading Color Buffer if (mColorTex.getFormat() != colorFormat || mColorTex.getWidthHeight() != mTargetSize || GFX->recentlyReset()) { - mColorTarget.release(); - mColorTex.set(mTargetSize.x, mTargetSize.y, colorFormat, - &GFXDefaultRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), - 1, GFXTextureManager::AA_MATCH_BACKBUFFER); - mColorTarget.setTexture(mColorTex); + mColorTarget.release(); + mColorTex.set(mTargetSize.x, mTargetSize.y, colorFormat, + &GFXRenderTargetSRGBProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), + 1, GFXTextureManager::AA_MATCH_BACKBUFFER); + mColorTarget.setTexture(mColorTex); - for (U32 i = 0; i < mTargetChainLength; i++) - mTargetChain[i]->attachTexture(GFXTextureTarget::Color1, mColorTarget.getTexture()); + for (U32 i = 0; i < mTargetChainLength; i++) + mTargetChain[i]->attachTexture(GFXTextureTarget::Color1, mColorTarget.getTexture()); } // andrewmac: Deferred Shading Material Info Buffer - if (mMatInfoTex.getFormat() != colorFormat || mMatInfoTex.getWidthHeight() != mTargetSize || GFX->recentlyReset()) + if (mMatInfoTex.getFormat() != matInfoFormat || mMatInfoTex.getWidthHeight() != mTargetSize || GFX->recentlyReset()) { - mMatInfoTarget.release(); - mMatInfoTex.set(mTargetSize.x, mTargetSize.y, colorFormat, - &GFXDefaultRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), - 1, GFXTextureManager::AA_MATCH_BACKBUFFER); - mMatInfoTarget.setTexture(mMatInfoTex); + mMatInfoTarget.release(); + mMatInfoTex.set(mTargetSize.x, mTargetSize.y, matInfoFormat, + &GFXRenderTargetProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), + 1, GFXTextureManager::AA_MATCH_BACKBUFFER); + mMatInfoTarget.setTexture(mMatInfoTex); - for (U32 i = 0; i < mTargetChainLength; i++) - mTargetChain[i]->attachTexture(GFXTextureTarget::Color2, mMatInfoTarget.getTexture()); + for (U32 i = 0; i < mTargetChainLength; i++) + mTargetChain[i]->attachTexture(GFXTextureTarget::Color2, mMatInfoTarget.getTexture()); } GFX->finalizeReset(); @@ -671,7 +666,8 @@ void ProcessedDeferredMaterial::_determineFeatures( U32 stageNum, } // Always allow these. - else if ( type == MFT_IsDXTnm || + else if ( type == MFT_IsBC3nm || + type == MFT_IsBC5nm || type == MFT_TexAnim || type == MFT_NormalMap || type == MFT_DetailNormalMap || @@ -800,7 +796,7 @@ U32 ProcessedDeferredMaterial::getNumStages() // If this stage has diffuse color, it's active if ( mMaterial->mDiffuse[i].alpha > 0 && - mMaterial->mDiffuse[i] != ColorF::WHITE ) + mMaterial->mDiffuse[i] != LinearColorF::WHITE ) stageActive = true; // If we have a Material that is vertex lit @@ -1102,16 +1098,19 @@ void RenderDeferredMgr::_initShaders() // Create StateBlocks GFXStateBlockDesc desc; desc.setCullMode( GFXCullNone ); - desc.setBlend( true ); + desc.setBlend( false ); desc.setZReadWrite( false, false ); desc.samplersDefined = true; - desc.samplers[0].addressModeU = GFXAddressWrap; - desc.samplers[0].addressModeV = GFXAddressWrap; - desc.samplers[0].addressModeW = GFXAddressWrap; - desc.samplers[0].magFilter = GFXTextureFilterLinear; - desc.samplers[0].minFilter = GFXTextureFilterLinear; - desc.samplers[0].mipFilter = GFXTextureFilterLinear; - desc.samplers[0].textureColorOp = GFXTOPModulate; + for (int i = 0; i < TEXTURE_STAGE_COUNT; i++) + { + desc.samplers[i].addressModeU = GFXAddressWrap; + desc.samplers[i].addressModeV = GFXAddressWrap; + desc.samplers[i].addressModeW = GFXAddressWrap; + desc.samplers[i].magFilter = GFXTextureFilterLinear; + desc.samplers[i].minFilter = GFXTextureFilterLinear; + desc.samplers[i].mipFilter = GFXTextureFilterLinear; + desc.samplers[i].textureColorOp = GFXTOPModulate; + } mStateblock = GFX->createStateBlock( desc ); diff --git a/Engine/source/renderInstance/renderFormatChanger.cpp b/Engine/source/renderInstance/renderFormatChanger.cpp index a4568c877..01e0ef8aa 100644 --- a/Engine/source/renderInstance/renderFormatChanger.cpp +++ b/Engine/source/renderInstance/renderFormatChanger.cpp @@ -223,7 +223,7 @@ void RenderFormatToken::_updateTargets() || mTargetColorTexture[i].getWidthHeight() != rtSize) { mTargetColorTexture[i].set( rtSize.x, rtSize.y, mColorFormat, - &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), + &GFXRenderTargetSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, mTargetAALevel ); mTargetChain[i]->attachTexture( GFXTextureTarget::Color0, mTargetColorTexture[i] ); } @@ -240,7 +240,7 @@ void RenderFormatToken::_updateTargets() || mTargetDepthStencilTexture[i].getWidthHeight() != rtSize) { mTargetDepthStencilTexture[i].set( rtSize.x, rtSize.y, mDepthFormat, - &GFXDefaultZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), + &GFXZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, mTargetAALevel ); mTargetChain[i]->attachTexture( GFXTextureTarget::DepthStencil, mTargetDepthStencilTexture[i] ); } diff --git a/Engine/source/renderInstance/renderOcclusionMgr.cpp b/Engine/source/renderInstance/renderOcclusionMgr.cpp index 7e084130f..98be3451b 100644 --- a/Engine/source/renderInstance/renderOcclusionMgr.cpp +++ b/Engine/source/renderInstance/renderOcclusionMgr.cpp @@ -73,7 +73,7 @@ void RenderOcclusionMgr::init() delete mMatInstance; mMaterial = MATMGR->allocateAndRegister( String::EmptyString ); - mMaterial->mDiffuse[0] = ColorF( 1, 0, 1, 1 ); + mMaterial->mDiffuse[0] = LinearColorF( 1, 0, 1, 1 ); mMaterial->mEmissive[0] = true; mMaterial->mAutoGenerated = true; diff --git a/Engine/source/renderInstance/renderPassManager.cpp b/Engine/source/renderInstance/renderPassManager.cpp index 3ed2671dc..d4d5ad568 100644 --- a/Engine/source/renderInstance/renderPassManager.cpp +++ b/Engine/source/renderInstance/renderPassManager.cpp @@ -299,7 +299,7 @@ GFXTextureObject *RenderPassManager::getDepthTargetTexture() const Point2I rtSize = GFX->getActiveRenderTarget()->getSize(); mDepthBuff.set(rtSize.x, rtSize.y, GFXFormatD24S8, - &GFXDefaultZTargetProfile, avar("%s() - mDepthBuff (line %d)", __FUNCTION__, __LINE__)); + &GFXZTargetProfile, avar("%s() - mDepthBuff (line %d)", __FUNCTION__, __LINE__)); return mDepthBuff.getPointer(); } diff --git a/Engine/source/renderInstance/renderTexTargetBinManager.cpp b/Engine/source/renderInstance/renderTexTargetBinManager.cpp index 6a8339e89..d1a7e1bc8 100644 --- a/Engine/source/renderInstance/renderTexTargetBinManager.cpp +++ b/Engine/source/renderInstance/renderTexTargetBinManager.cpp @@ -170,7 +170,7 @@ bool RenderTexTargetBinManager::_updateTargets() || mTargetChainTextures[i][j].getFormat() != mTargetFormat) { ret &= mTargetChainTextures[i][j].set( mTargetSize.x, mTargetSize.y, mTargetFormat, - &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), + &GFXRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, GFXTextureManager::AA_MATCH_BACKBUFFER ); mTargetChain[i]->attachTexture( GFXTextureTarget::RenderSlot(GFXTextureTarget::Color0 + j), mTargetChainTextures[i][j] ); diff --git a/Engine/source/scene/fogStructs.h b/Engine/source/scene/fogStructs.h index 874d2542e..8e4853ee7 100644 --- a/Engine/source/scene/fogStructs.h +++ b/Engine/source/scene/fogStructs.h @@ -29,7 +29,7 @@ struct FogData F32 density; F32 densityOffset; F32 atmosphereHeight; - ColorF color; + LinearColorF color; FogData() { diff --git a/Engine/source/scene/reflectionManager.cpp b/Engine/source/scene/reflectionManager.cpp index ac1b03021..339906dd0 100644 --- a/Engine/source/scene/reflectionManager.cpp +++ b/Engine/source/scene/reflectionManager.cpp @@ -59,13 +59,14 @@ MODULE_END; GFX_ImplementTextureProfile( ReflectRenderTargetProfile, GFXTextureProfile::DiffuseMap, - GFXTextureProfile::PreserveSize | GFXTextureProfile::RenderTarget | GFXTextureProfile::Pooled, + GFXTextureProfile::PreserveSize | GFXTextureProfile::RenderTarget | GFXTextureProfile::SRGB | GFXTextureProfile::Pooled, GFXTextureProfile::NONE ); GFX_ImplementTextureProfile( RefractTextureProfile, GFXTextureProfile::DiffuseMap, GFXTextureProfile::PreserveSize | GFXTextureProfile::RenderTarget | + GFXTextureProfile::SRGB | GFXTextureProfile::Pooled, GFXTextureProfile::NONE ); @@ -83,7 +84,7 @@ U32 ReflectionManager::smFrameReflectionMS = 10; F32 ReflectionManager::smRefractTexScale = 0.5f; ReflectionManager::ReflectionManager() - : mReflectFormat( GFXFormatR8G8B8A8 ), + : mReflectFormat( GFXFormatR8G8B8A8_SRGB ), mUpdateRefract( true ), mLastUpdateMs( 0 ) { diff --git a/Engine/source/scene/reflector.cpp b/Engine/source/scene/reflector.cpp index 9289a39b7..dfe54537d 100644 --- a/Engine/source/scene/reflector.cpp +++ b/Engine/source/scene/reflector.cpp @@ -614,7 +614,7 @@ void PlaneReflector::updateReflection( const ReflectParams ¶ms ) // In the future we may want to fix this instead by having the scatterSky // render a skirt or something in its lower half. // - ColorF clearColor = gClientSceneGraph->getAmbientLightColor(); + LinearColorF clearColor = gClientSceneGraph->getAmbientLightColor(); GFX->clear( GFXClearZBuffer | GFXClearStencil | GFXClearTarget, clearColor, 1.0f, 0 ); if(GFX->getCurrentRenderStyle() == GFXDevice::RS_StereoSideBySide) diff --git a/Engine/source/scene/sceneManager.cpp b/Engine/source/scene/sceneManager.cpp index 3c928bdc6..caa117e9a 100644 --- a/Engine/source/scene/sceneManager.cpp +++ b/Engine/source/scene/sceneManager.cpp @@ -117,7 +117,7 @@ SceneManager::SceneManager( bool isClient ) mVisibleGhostDistance( 0 ), mNearClip( 0.1f ), mLightManager( NULL ), - mAmbientLightColor( ColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ), + mAmbientLightColor( LinearColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ), mDefaultRenderPass( NULL ) { VECTOR_SET_ASSOCIATION( mBatchQueryList ); @@ -211,7 +211,7 @@ void SceneManager::renderScene( SceneRenderState* renderState, U32 objectMask, S AssertFatal( baseObject != NULL, "SceneManager::renderScene - findZone() did not return an object" ); } - ColorF zoneAmbient; + LinearColorF zoneAmbient; if( baseObject && baseObject->getZoneAmbientLightColor( baseZone, zoneAmbient ) ) mAmbientLightColor.setTargetValue( zoneAmbient ); else diff --git a/Engine/source/scene/sceneManager.h b/Engine/source/scene/sceneManager.h index 3e7e65b61..57da5d5c2 100644 --- a/Engine/source/scene/sceneManager.h +++ b/Engine/source/scene/sceneManager.h @@ -158,7 +158,7 @@ class SceneManager /// @name Lighting /// @{ - typedef InterpolatedChangeProperty< ColorF > AmbientLightInterpolator; + typedef InterpolatedChangeProperty< LinearColorF > AmbientLightInterpolator; /// Light manager that is active for the scene. LightManager* mLightManager; @@ -271,7 +271,7 @@ class SceneManager bool setLightManager( const char *lmName ); /// Return the current global ambient light color. - const ColorF& getAmbientLightColor() const { return mAmbientLightColor.getCurrentValue(); } + const LinearColorF& getAmbientLightColor() const { return mAmbientLightColor.getCurrentValue(); } /// Set the time it takes for a new ambient light color to take full effect. void setAmbientLightTransitionTime( SimTime time ) { mAmbientLightColor.setTransitionTime( time ); } diff --git a/Engine/source/scene/sceneRenderState.h b/Engine/source/scene/sceneRenderState.h index edcc583bd..1f3a751e6 100644 --- a/Engine/source/scene/sceneRenderState.h +++ b/Engine/source/scene/sceneRenderState.h @@ -94,7 +94,7 @@ class SceneRenderState Point3F mVectorEye; /// Global ambient light color. - ColorF mAmbientLightColor; + LinearColorF mAmbientLightColor; /// Forces bin based post effects to be disabled /// during rendering with this scene state. @@ -183,10 +183,10 @@ class SceneRenderState /// light. /// /// @return The ambient light color for rendering. - ColorF getAmbientLightColor() const { return mAmbientLightColor; } + LinearColorF getAmbientLightColor() const { return mAmbientLightColor; } /// Set the global ambient light color to render with. - void setAmbientLightColor( const ColorF& color ) { mAmbientLightColor = color; } + void setAmbientLightColor( const LinearColorF& color ) { mAmbientLightColor = color; } /// If true then Advanced Lighting bin draws are disabled during rendering with /// this scene state. diff --git a/Engine/source/scene/zones/sceneSimpleZone.cpp b/Engine/source/scene/zones/sceneSimpleZone.cpp index 9d968b5e2..49f6d565c 100644 --- a/Engine/source/scene/zones/sceneSimpleZone.cpp +++ b/Engine/source/scene/zones/sceneSimpleZone.cpp @@ -143,7 +143,7 @@ void SceneSimpleZone::setUseAmbientLightColor( bool value ) //----------------------------------------------------------------------------- -void SceneSimpleZone::setAmbientLightColor( const ColorF& color ) +void SceneSimpleZone::setAmbientLightColor( const LinearColorF& color ) { mAmbientLightColor = color; if( isServerObject() ) @@ -152,7 +152,7 @@ void SceneSimpleZone::setAmbientLightColor( const ColorF& color ) //----------------------------------------------------------------------------- -bool SceneSimpleZone::getZoneAmbientLightColor( U32 zone, ColorF& outColor ) const +bool SceneSimpleZone::getZoneAmbientLightColor( U32 zone, LinearColorF& outColor ) const { AssertFatal( zone == getZoneRangeStart(), "SceneSimpleZone::getZoneAmbientLightColor - Invalid zone ID!" ); @@ -356,6 +356,6 @@ bool SceneSimpleZone::_setUseAmbientLightColor( void* object, const char* index, bool SceneSimpleZone::_setAmbientLightColor( void* object, const char* index, const char* data ) { SceneSimpleZone* zone = reinterpret_cast< SceneSimpleZone* >( object ); - zone->setAmbientLightColor( EngineUnmarshallData< ColorF >()( data ) ); + zone->setAmbientLightColor( EngineUnmarshallData< LinearColorF >()( data ) ); return false; } diff --git a/Engine/source/scene/zones/sceneSimpleZone.h b/Engine/source/scene/zones/sceneSimpleZone.h index 4d08a9f8f..6da5f039f 100644 --- a/Engine/source/scene/zones/sceneSimpleZone.h +++ b/Engine/source/scene/zones/sceneSimpleZone.h @@ -61,7 +61,7 @@ class SceneSimpleZone : public SceneZoneSpace bool mUseAmbientLightColor; /// Ambient light color in this zone. - ColorF mAmbientLightColor; + LinearColorF mAmbientLightColor; /// @} @@ -102,12 +102,12 @@ class SceneSimpleZone : public SceneZoneSpace void setUseAmbientLightColor( bool value ); /// Return the ambient light color for this zone. - ColorF getAmbientLightColor() const { return mAmbientLightColor; } + LinearColorF getAmbientLightColor() const { return mAmbientLightColor; } /// Set the ambient light color for the zone. /// @note This only takes effect if useAmbientLightColor() return true. /// @see setUseAmbientLightColor - void setAmbientLightColor( const ColorF& color ); + void setAmbientLightColor( const LinearColorF& color ); /// @} @@ -131,7 +131,7 @@ class SceneSimpleZone : public SceneZoneSpace virtual U32 getPointZone( const Point3F &p ); virtual bool getOverlappingZones( const Box3F& aabb, U32* outZones, U32& outNumZones ); virtual void traverseZones( SceneTraversalState* state ); - virtual bool getZoneAmbientLightColor( U32 zone, ColorF& outColor ) const; + virtual bool getZoneAmbientLightColor( U32 zone, LinearColorF& outColor ) const; virtual void traverseZones( SceneTraversalState* state, U32 startZoneId ); /// @} diff --git a/Engine/source/scene/zones/sceneZoneSpace.h b/Engine/source/scene/zones/sceneZoneSpace.h index 2b792a53d..7c04279d2 100644 --- a/Engine/source/scene/zones/sceneZoneSpace.h +++ b/Engine/source/scene/zones/sceneZoneSpace.h @@ -211,7 +211,7 @@ class SceneZoneSpace : public SceneSpace /// Get the ambient light color of the given zone in this space or return false if the /// given zone does not have an ambient light color assigned to it. - virtual bool getZoneAmbientLightColor( U32 zone, ColorF& outColor ) const { return false; } + virtual bool getZoneAmbientLightColor( U32 zone, LinearColorF& outColor ) const { return false; } /// @name Containment Tests /// @{ diff --git a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp index 0d14c84b3..4646c0791 100644 --- a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp @@ -337,7 +337,7 @@ void ParallaxFeatGLSL::processPix( Vector &componentList, Var *normalMap = getNormalMapTex(); // Call the library function to do the rest. - if (fd.features.hasFeature(MFT_IsDXTnm, getProcessIndex())) + if (fd.features.hasFeature(MFT_IsBC3nm, getProcessIndex())) { meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @ );\r\n", texCoord, normalMap, texCoord, negViewTS, parallaxInfo)); diff --git a/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp b/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp index 262efd451..7581cebbd 100644 --- a/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp @@ -91,7 +91,7 @@ void PixelSpecularGLSL::processPix( Vector &componentList, if (specularColor) final = new GenOp( "@ * @", final, specularColor ); } - else if ( fd.features[MFT_NormalMap] && !fd.features[MFT_IsDXTnm] ) + else if ( fd.features[MFT_NormalMap] && !fd.features[MFT_IsBC3nm] && !fd.features[MFT_IsBC5nm]) { Var *bumpColor = (Var*)LangElement::find( "bumpNormal" ); final = new GenOp( "@ * @.a", final, bumpColor ); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index e66a16252..abdf9d2db 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -146,8 +146,9 @@ LangElement *ShaderFeatureGLSL::expandNormalMap( LangElement *sampleNormalOp, const MaterialFeatureData &fd ) { MultiLine *meta = new MultiLine; - - if ( fd.features.hasFeature( MFT_IsDXTnm, getProcessIndex() ) ) + const bool hasBc3 = fd.features.hasFeature(MFT_IsBC3nm, getProcessIndex()); + const bool hasBc5 = fd.features.hasFeature(MFT_IsBC5nm, getProcessIndex()); + if (hasBc3 || hasBc5) { if ( fd.features[MFT_ImposterVert] ) { @@ -155,12 +156,18 @@ LangElement *ShaderFeatureGLSL::expandNormalMap( LangElement *sampleNormalOp, // encodes them with the z axis in the alpha component. meta->addStatement( new GenOp( " @ = float4( normalize( @.xyw * 2.0 - 1.0 ), 0.0 ); // Obj DXTnm\r\n", normalDecl, sampleNormalOp ) ); } - else + else if (hasBc3) { - // DXT Swizzle trick + // BC3 Swizzle trick meta->addStatement( new GenOp( " @ = float4( @.ag * 2.0 - 1.0, 0.0, 0.0 ); // DXTnm\r\n", normalDecl, sampleNormalOp ) ); meta->addStatement( new GenOp( " @.z = sqrt( 1.0 - dot( @.xy, @.xy ) ); // DXTnm\r\n", normalVar, normalVar, normalVar ) ); } + else if (hasBc5) + { + // BC5 + meta->addStatement(new GenOp(" @ = float4( @.gr * 2.0 - 1.0, 0.0, 0.0 ); // bc5nm\r\n", normalDecl, sampleNormalOp ) ); + meta->addStatement(new GenOp(" @.z = sqrt( 1.0 - dot( @.xy, @.xy ) ); // bc5nm\r\n", normalVar, normalVar, normalVar ) ); + } } else { @@ -878,8 +885,6 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, colorDecl, diffuseMap, inTex ) ); - if (!fd.features[MFT_Imposter]) - meta->addStatement( new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor) ); meta->addStatement( new GenOp( " @;\r\n", assignColor( diffColor, Material::Mul, NULL, targ) ) ); } @@ -953,28 +958,16 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, } #endif - if(is_sm3) - { - meta->addStatement(new GenOp( " @ = tex2Dlod(@, float4(@, 0.0, mipLod));\r\n", - new DecOp(diffColor), diffuseMap, inTex)); - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - } - else - { - meta->addStatement(new GenOp( " @ = tex2D(@, @);\r\n", - new DecOp(diffColor), diffuseMap, inTex)); - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - } + + meta->addStatement(new GenOp( " @ = tex2Dlod(@, float4(@, 0.0, mipLod));\r\n", + new DecOp(diffColor), diffuseMap, inTex)); + meta->addStatement(new GenOp( " @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ) ) ); } else { meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex)); - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ))); } } diff --git a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp index 28e3cd00c..0827c7bee 100644 --- a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp +++ b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp @@ -47,7 +47,8 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_VertTransform, new VertPositionGLSL ); FEATUREMGR->registerFeature( MFT_RTLighting, new RTLightingFeatGLSL ); - FEATUREMGR->registerFeature( MFT_IsDXTnm, new NamedFeatureGLSL( "DXTnm" ) ); + FEATUREMGR->registerFeature( MFT_IsBC3nm, new NamedFeatureGLSL( "BC3nm" ) ); + FEATUREMGR->registerFeature( MFT_IsBC5nm, new NamedFeatureGLSL( "BC5nm" ) ); FEATUREMGR->registerFeature( MFT_TexAnim, new TexAnimGLSL ); FEATUREMGR->registerFeature( MFT_DiffuseMap, new DiffuseMapFeatGLSL ); FEATUREMGR->registerFeature( MFT_OverlayMap, new OverlayTexFeatGLSL ); diff --git a/Engine/source/shaderGen/HLSL/bumpHLSL.cpp b/Engine/source/shaderGen/HLSL/bumpHLSL.cpp index c3cd97c94..c7502f129 100644 --- a/Engine/source/shaderGen/HLSL/bumpHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/bumpHLSL.cpp @@ -342,7 +342,7 @@ void ParallaxFeatHLSL::processPix( Vector &componentList, Var *bumpMapTexture = (Var*)LangElement::find("bumpMapTex"); // Call the library function to do the rest. - if (fd.features.hasFeature(MFT_IsDXTnm, getProcessIndex())) + if (fd.features.hasFeature(MFT_IsBC3nm, getProcessIndex())) { meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @ );\r\n", texCoord, bumpMapTexture, normalMap, texCoord, negViewTS, parallaxInfo)); diff --git a/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp b/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp index 021434447..90ec892d5 100644 --- a/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp @@ -95,7 +95,7 @@ void PixelSpecularHLSL::processPix( Vector &componentList, if (specularColor) final = new GenOp( "@ * @", final, specularColor ); } - else if ( fd.features[MFT_NormalMap] && !fd.features[MFT_IsDXTnm] ) + else if ( fd.features[MFT_NormalMap] && !fd.features[MFT_IsBC3nm] && !fd.features[MFT_IsBC5nm]) { Var *bumpColor = (Var*)LangElement::find( "bumpNormal" ); final = new GenOp( "@ * @.a", final, bumpColor ); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 894e3bdfa..b7f7f7dd7 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -146,8 +146,9 @@ LangElement *ShaderFeatureHLSL::expandNormalMap( LangElement *sampleNormalOp, const MaterialFeatureData &fd ) { MultiLine *meta = new MultiLine; - - if ( fd.features.hasFeature( MFT_IsDXTnm, getProcessIndex() ) ) + const bool hasBc3 = fd.features.hasFeature(MFT_IsBC3nm, getProcessIndex() ); + const bool hasBc5 = fd.features.hasFeature(MFT_IsBC5nm, getProcessIndex() ); + if ( hasBc3 || hasBc5 ) { if ( fd.features[MFT_ImposterVert] ) { @@ -155,12 +156,18 @@ LangElement *ShaderFeatureHLSL::expandNormalMap( LangElement *sampleNormalOp, // encodes them with the z axis in the alpha component. meta->addStatement( new GenOp( " @ = float4( normalize( @.xyw * 2.0 - 1.0 ), 0.0 ); // Obj DXTnm\r\n", normalDecl, sampleNormalOp ) ); } - else + else if( hasBc3 ) { - // DXT Swizzle trick + // BC3 Swizzle trick meta->addStatement( new GenOp( " @ = float4( @.ag * 2.0 - 1.0, 0.0, 0.0 ); // DXTnm\r\n", normalDecl, sampleNormalOp ) ); meta->addStatement( new GenOp( " @.z = sqrt( 1.0 - dot( @.xy, @.xy ) ); // DXTnm\r\n", normalVar, normalVar, normalVar ) ); } + else if (hasBc5) + { + // BC5 + meta->addStatement(new GenOp(" @ = float4( @.gr * 2.0 - 1.0, 0.0, 0.0 ); // bc5nm\r\n", normalDecl, sampleNormalOp ) ); + meta->addStatement(new GenOp(" @.z = sqrt( 1.0 - dot( @.xy, @.xy ) ); // bc5nm\r\n", normalVar, normalVar, normalVar )) ; + } } else { @@ -874,10 +881,6 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, if ( fd.features[MFT_CubeMap] ) { meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", colorDecl, diffuseMapTex, diffuseMap, inTex)); - - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); - meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ))); } else if(fd.features[MFT_DiffuseMapAtlas]) @@ -951,9 +954,6 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, #endif meta->addStatement(new GenOp(" @ = @.SampleLevel(@,@,mipLod);\r\n", new DecOp(diffColor), diffuseMapTex, diffuseMap, inTex)); - - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ) ) ); } @@ -961,8 +961,6 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, { meta->addStatement(new GenOp("@ = @.Sample(@, @);\r\n", colorDecl, diffuseMapTex, diffuseMap, inTex)); - if (!fd.features[MFT_Imposter]) - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul, NULL, targ))); } } diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp index 16cdf514d..68c48435d 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp @@ -46,7 +46,8 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_VertTransform, new VertPositionHLSL ); FEATUREMGR->registerFeature( MFT_RTLighting, new RTLightingFeatHLSL ); - FEATUREMGR->registerFeature( MFT_IsDXTnm, new NamedFeatureHLSL( "DXTnm" ) ); + FEATUREMGR->registerFeature( MFT_IsBC3nm, new NamedFeatureHLSL( "BC3nm" ) ); + FEATUREMGR->registerFeature( MFT_IsBC5nm, new NamedFeatureHLSL( "BC5nm" ) ); FEATUREMGR->registerFeature( MFT_TexAnim, new TexAnimHLSL ); FEATUREMGR->registerFeature( MFT_DiffuseMap, new DiffuseMapFeatHLSL ); FEATUREMGR->registerFeature( MFT_OverlayMap, new OverlayTexFeatHLSL ); diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index f4aca6cf5..2210c69fd 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -29,6 +29,7 @@ const String ShaderGenVars::worldToCamera("$worldToCamera"); const String ShaderGenVars::worldToObj("$worldToObj"); const String ShaderGenVars::viewToObj("$viewToObj"); const String ShaderGenVars::cubeTrans("$cubeTrans"); +const String ShaderGenVars::cubeMips("$cubeMips"); const String ShaderGenVars::objTrans("$objTrans"); const String ShaderGenVars::cubeEyePos("$cubeEyePos"); const String ShaderGenVars::eyePos("$eyePos"); diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index 52ff016d0..809c9a34d 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -38,6 +38,7 @@ struct ShaderGenVars const static String worldToObj; const static String viewToObj; const static String cubeTrans; + const static String cubeMips; const static String objTrans; const static String cubeEyePos; const static String eyePos; diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index 42a1a5118..6f9edbe6d 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -266,7 +266,6 @@ void TerrainBaseMapFeatGLSL::processPix( Vector &componentLis baseColor->setType( "vec4" ); baseColor->setName( "baseColor" ); meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) ); - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor)); ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; @@ -574,7 +573,7 @@ void TerrainDetailMapFeatGLSL::processPix( Vector &component Var *normalMap = _getNormalMapTex(); // Call the library function to do the rest. - if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex)) + if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex)) { meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n", inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend)); diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp index 8ebbd641f..094613785 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp @@ -273,8 +273,6 @@ void TerrainBaseMapFeatHLSL::processPix( Vector &componentLis diffuseTex->constNum = diffuseMap->constNum; meta->addStatement(new GenOp(" @ = @.Sample( @, @.xy );\r\n", new DecOp(baseColor), diffuseTex, diffuseMap, texCoord)); - meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor)); - ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; if (fd.features.hasFeature(MFT_isDeferred)) @@ -508,7 +506,7 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component } // Call the library function to do the rest. - if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex)) + if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex)) { meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @.z * @ );\r\n", inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend)); diff --git a/Engine/source/terrain/terrCell.cpp b/Engine/source/terrain/terrCell.cpp index 7f2bdd08b..d96811f45 100644 --- a/Engine/source/terrain/terrCell.cpp +++ b/Engine/source/terrain/terrCell.cpp @@ -1040,14 +1040,14 @@ void TerrCell::getRenderPrimitive( GFXPrimitive *prim, void TerrCell::renderBounds() const { - ColorI color; + LinearColorF color; color.interpolate( ColorI::RED, ColorI::GREEN, (F32)mLevel / 3.0f ); GFXStateBlockDesc desc; desc.setZReadWrite( true, false ); desc.fillMode = GFXFillWireframe; - GFX->getDrawUtil()->drawCube( desc, mBounds, color ); + GFX->getDrawUtil()->drawCube( desc, mBounds, color.toColorI()); } void TerrCell::preloadMaterials() diff --git a/Engine/source/terrain/terrCellMaterial.cpp b/Engine/source/terrain/terrCellMaterial.cpp index 6f539b6ae..cd1f123d0 100644 --- a/Engine/source/terrain/terrCellMaterial.cpp +++ b/Engine/source/terrain/terrCellMaterial.cpp @@ -436,10 +436,13 @@ bool TerrainCellMaterial::_createPass( Vector *materials, features.addFeature( MFT_TerrainNormalMap, featureIndex ); normalMaps.last().set( mat->getNormalMap(), - &GFXDefaultStaticNormalMapProfile, "TerrainCellMaterial::_createPass() - NormalMap" ); + &GFXNormalMapProfile, "TerrainCellMaterial::_createPass() - NormalMap" ); - if ( normalMaps.last().getFormat() == GFXFormatDXT5 ) - features.addFeature( MFT_IsDXTnm, featureIndex ); + GFXFormat normalFmt = normalMaps.last().getFormat(); + if ( normalFmt == GFXFormatBC3 ) + features.addFeature( MFT_IsBC3nm, featureIndex ); + else if ( normalFmt == GFXFormatBC5) + features.addFeature( MFT_IsBC5nm, featureIndex); // Do we need and can we do parallax mapping? if ( !disableParallaxMaps && @@ -610,7 +613,7 @@ bool TerrainCellMaterial::_createPass( Vector *materials, desc.samplers[sampler].minFilter = GFXTextureFilterLinear; matInfo->detailTex.set( matInfo->mat->getDetailMap(), - &GFXDefaultStaticDiffuseProfile, "TerrainCellMaterial::_createPass() - DetailMap" ); + &GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - DetailMap" ); } matInfo->macroInfoVConst = pass->shader->getShaderConstHandle( avar( "$macroScaleAndFade%d", i ) ); @@ -634,7 +637,7 @@ bool TerrainCellMaterial::_createPass( Vector *materials, desc.samplers[sampler].minFilter = GFXTextureFilterLinear; matInfo->macroTex.set( matInfo->mat->getMacroMap(), - &GFXDefaultStaticDiffuseProfile, "TerrainCellMaterial::_createPass() - MacroMap" ); + &GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - MacroMap" ); } //end macro texture diff --git a/Engine/source/terrain/terrData.cpp b/Engine/source/terrain/terrData.cpp index ec102ba78..eff266385 100644 --- a/Engine/source/terrain/terrData.cpp +++ b/Engine/source/terrain/terrData.cpp @@ -176,7 +176,6 @@ ImplementEnumType(baseTexFormat, { TerrainBlock::NONE, "NONE", "No cached terrain.\n" }, { TerrainBlock::DDS, "DDS", "Cache the terrain in a DDS format.\n" }, { TerrainBlock::PNG, "PNG", "Cache the terrain in a PNG format.\n" }, -{ TerrainBlock::JPG, "JPG", "Cache the terrain in a JPG format.\n" }, EndImplementEnumType; TerrainBlock::TerrainBlock() @@ -189,7 +188,7 @@ TerrainBlock::TerrainBlock() mDetailsDirty( false ), mLayerTexDirty( false ), mBaseTexSize( 1024 ), - mBaseTexFormat( TerrainBlock::JPG ), + mBaseTexFormat( TerrainBlock::DDS ), mCell( NULL ), mBaseMaterial( NULL ), mDefaultMatInst( NULL ), @@ -873,7 +872,7 @@ GFXTextureObject* TerrainBlock::getLightMapTex() if ( mLightMapTex.isNull() && mLightMap ) { mLightMapTex.set( mLightMap, - &GFXDefaultStaticDiffuseProfile, + &GFXStaticTextureProfile, false, "TerrainBlock::getLightMapTex()" ); } @@ -966,7 +965,7 @@ bool TerrainBlock::onAdd() _updateBaseTexture( true ); // The base texture should have been cached by now... so load it. - mBaseTex.set( baseCachePath, &GFXDefaultStaticDiffuseProfile, "TerrainBlock::mBaseTex" ); + mBaseTex.set( baseCachePath, &GFXStaticTextureSRGBProfile, "TerrainBlock::mBaseTex" ); GFXTextureManager::addEventDelegate( this, &TerrainBlock::_onTextureEvent ); MATMGR->getFlushSignal().notify( this, &TerrainBlock::_onFlushMaterials ); diff --git a/Engine/source/terrain/terrData.h b/Engine/source/terrain/terrData.h index 2982de3e9..f7b3fb179 100644 --- a/Engine/source/terrain/terrData.h +++ b/Engine/source/terrain/terrData.h @@ -78,7 +78,7 @@ public: enum BaseTexFormat { - NONE, DDS, PNG, JPG + NONE, DDS, PNG }; static const char* formatToExtension(BaseTexFormat format) @@ -89,8 +89,6 @@ public: return "dds"; case PNG: return "png"; - case JPG: - return "jpg"; default: return ""; } diff --git a/Engine/source/terrain/terrFile.cpp b/Engine/source/terrain/terrFile.cpp index c96ca2021..3a639d0b0 100644 --- a/Engine/source/terrain/terrFile.cpp +++ b/Engine/source/terrain/terrFile.cpp @@ -457,7 +457,7 @@ void TerrainFile::_loadLegacy( FileStream &stream ) if ( materials[i].isEmpty() ) continue; - terrainMat.set( materials[i], &GFXDefaultPersistentProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); + terrainMat.set( materials[i], &GFXTexturePersistentSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); if ( terrainMat ) continue; @@ -470,7 +470,7 @@ void TerrainFile::_loadLegacy( FileStream &stream ) { matRelPath.setPath( String(Con::getVariable( "$defaultGame" )) + path.substr( n, path.length() - n ) ); - terrainMat.set( matRelPath, &GFXDefaultPersistentProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); + terrainMat.set( matRelPath, &GFXTexturePersistentSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); if ( terrainMat ) { materials[i] = matRelPath.getFullPath(); diff --git a/Engine/source/terrain/terrRender.cpp b/Engine/source/terrain/terrRender.cpp index 4883d9600..be67d58eb 100644 --- a/Engine/source/terrain/terrRender.cpp +++ b/Engine/source/terrain/terrRender.cpp @@ -48,7 +48,7 @@ #include "gfx/gfxTransformSaver.h" #include "gfx/bitmap/gBitmap.h" #include "gfx/bitmap/ddsFile.h" -#include "gfx/bitmap/ddsUtils.h" +#include "gfx/bitmap/imageUtils.h" #include "terrain/terrMaterial.h" #include "gfx/gfxDebugEvent.h" #include "gfx/gfxCardProfile.h" @@ -83,10 +83,11 @@ void TerrainBlock::_updateMaterials() { TerrainMaterial *mat = mFile->mMaterials[i]; - if( !mat->getDiffuseMap().isEmpty() ) - mBaseTextures[i].set( mat->getDiffuseMap(), - &GFXDefaultStaticDiffuseProfile, - "TerrainBlock::_updateMaterials() - DiffuseMap" ); + if (!mat->getDiffuseMap().isEmpty()) + { + mBaseTextures[i].set(mat->getDiffuseMap(), &GFXStaticTextureSRGBProfile, + "TerrainBlock::_updateMaterials() - DiffuseMap"); + } else mBaseTextures[ i ] = GFXTexHandle(); @@ -232,12 +233,12 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache) // use it to render to else we create one. if ( mBaseTex.isValid() && mBaseTex->isRenderTarget() && - mBaseTex->getFormat() == GFXFormatR8G8B8A8 && + mBaseTex->getFormat() == GFXFormatR8G8B8A8_SRGB && mBaseTex->getWidth() == destSize.x && mBaseTex->getHeight() == destSize.y ) blendTex = mBaseTex; else - blendTex.set( destSize.x, destSize.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, "" ); + blendTex.set( destSize.x, destSize.y, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, "" ); GFX->pushActiveRenderTarget(); @@ -324,7 +325,7 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache) blendBmp.extrudeMipLevels(); DDSFile *blendDDS = DDSFile::createDDSFileFromGBitmap( &blendBmp ); - DDSUtil::squishDDS( blendDDS, GFXFormatDXT1 ); + ImageUtil::ddsCompress( blendDDS, GFXFormatBC1 ); // Write result to file stream blendDDS->write( fs ); @@ -342,7 +343,7 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache) return; } - GBitmap bitmap(blendTex->getWidth(), blendTex->getHeight(), false, GFXFormatR8G8B8); + GBitmap bitmap(blendTex->getWidth(), blendTex->getHeight(), false, GFXFormatR8G8B8A8); blendTex->copyToBmp(&bitmap); bitmap.writeBitmap(formatToExtension(mBaseTexFormat), stream); } diff --git a/Engine/source/ts/collada/colladaAppMaterial.cpp b/Engine/source/ts/collada/colladaAppMaterial.cpp index a29964ad0..3e8f1966e 100644 --- a/Engine/source/ts/collada/colladaAppMaterial.cpp +++ b/Engine/source/ts/collada/colladaAppMaterial.cpp @@ -59,16 +59,16 @@ ColladaAppMaterial::ColladaAppMaterial(const char* matName) flags |= TSMaterialList::S_Wrap; flags |= TSMaterialList::T_Wrap; - diffuseColor = ColorF::ONE; - specularColor = ColorF::ONE; + diffuseColor = LinearColorF::ONE; + specularColor = LinearColorF::ONE; specularPower = 8.0f; doubleSided = false; } ColladaAppMaterial::ColladaAppMaterial(const domMaterial *pMat) : mat(pMat), - diffuseColor(ColorF::ONE), - specularColor(ColorF::ONE), + diffuseColor(LinearColorF::ONE), + specularColor(LinearColorF::ONE), specularPower(8.0f), doubleSided(false) { @@ -174,7 +174,7 @@ void ColladaAppMaterial::resolveFloat(const domCommon_float_or_param_type* value } } -void ColladaAppMaterial::resolveColor(const domCommon_color_or_texture_type* value, ColorF* dst) +void ColladaAppMaterial::resolveColor(const domCommon_color_or_texture_type* value, LinearColorF* dst) { if (value && value->getColor()) { dst->red = value->getColor()->getValue()[0]; diff --git a/Engine/source/ts/collada/colladaAppMaterial.h b/Engine/source/ts/collada/colladaAppMaterial.h index 1be1e5b3e..e6dceafa6 100644 --- a/Engine/source/ts/collada/colladaAppMaterial.h +++ b/Engine/source/ts/collada/colladaAppMaterial.h @@ -44,8 +44,8 @@ public: String diffuseMap; String normalMap; String specularMap; - ColorF diffuseColor; - ColorF specularColor; + LinearColorF diffuseColor; + LinearColorF specularColor; F32 specularPower; bool doubleSided; @@ -56,7 +56,7 @@ public: String getName() const { return name; } void resolveFloat(const domCommon_float_or_param_type* value, F32* dst); - void resolveColor(const domCommon_color_or_texture_type* value, ColorF* dst); + void resolveColor(const domCommon_color_or_texture_type* value, LinearColorF* dst); // Determine the material transparency template void resolveTransparency(const T shader, F32* dst) @@ -66,7 +66,7 @@ public: resolveFloat(shader->getTransparency(), dst); // Multiply the transparency by the transparent color - ColorF transColor(1.0f, 1.0f, 1.0f, 1.0f); + LinearColorF transColor(1.0f, 1.0f, 1.0f, 1.0f); if (shader->getTransparent() && shader->getTransparent()->getColor()) { const domCommon_color_or_texture_type::domColor* color = shader->getTransparent()->getColor(); transColor.set(color->getValue()[0], color->getValue()[1], color->getValue()[2], color->getValue()[3]); diff --git a/Engine/source/ts/collada/colladaAppMesh.cpp b/Engine/source/ts/collada/colladaAppMesh.cpp index d85f7dd66..c1420d1cd 100644 --- a/Engine/source/ts/collada/colladaAppMesh.cpp +++ b/Engine/source/ts/collada/colladaAppMesh.cpp @@ -878,7 +878,11 @@ void ColladaAppMesh::getMorphVertexData(const domMorph* morph, F32 time, const M } if (colors_array) { for (S32 iVert = 0; iVert < vertTuples.size(); iVert++) - colors_array[iVert] += targetColors[iVert] * (F32)targetWeights[iTarget]; + { + LinearColorF tCol = colors_array[iVert]; + tCol += LinearColorF(targetColors[iVert]) * (F32)targetWeights[iTarget]; + colors_array[iVert] = tCol.toColorI(); + } } } } diff --git a/Engine/source/ts/collada/colladaLights.cpp b/Engine/source/ts/collada/colladaLights.cpp index 390ad6ee7..bb699e4ff 100644 --- a/Engine/source/ts/collada/colladaLights.cpp +++ b/Engine/source/ts/collada/colladaLights.cpp @@ -35,7 +35,7 @@ // Collada elements are very similar, but are arranged as separate, unrelated // classes. These template functions are used to provide a simple way to access the // common elements. -template static void resolveLightColor(T* light, ColorF& color) +template static void resolveLightColor(T* light, LinearColorF& color) { if (light->getColor()) { @@ -80,7 +80,7 @@ static void processNodeLights(AppNode* appNode, const MatrixF& offset, SimGroup* } LightBase* pLight = 0; - ColorF color(ColorF::WHITE); + LinearColorF color(LinearColorF::WHITE); Point3F attenuation(0, 1, 1); if (technique->getAmbient()) { diff --git a/Engine/source/ts/tsLastDetail.cpp b/Engine/source/ts/tsLastDetail.cpp index 24f1144e2..863e79f3f 100644 --- a/Engine/source/ts/tsLastDetail.cpp +++ b/Engine/source/ts/tsLastDetail.cpp @@ -31,7 +31,7 @@ #include "renderInstance/renderImposterMgr.h" #include "gfx/gfxTransformSaver.h" #include "gfx/bitmap/ddsFile.h" -#include "gfx/bitmap/ddsUtils.h" +#include "gfx/bitmap/imageUtils.h" #include "gfx/gfxTextureManager.h" #include "math/mRandom.h" #include "core/stream/fileStream.h" @@ -240,12 +240,12 @@ void TSLastDetail::update( bool forceUpdate ) // Get the diffuse texture and from its size and // the imposter dimensions we can generate the UVs. - GFXTexHandle diffuseTex( diffuseMapPath, &GFXDefaultStaticDiffuseProfile, String::EmptyString ); + GFXTexHandle diffuseTex( diffuseMapPath, &GFXStaticTextureSRGBProfile, String::EmptyString ); Point2I texSize( diffuseTex->getWidth(), diffuseTex->getHeight() ); _validateDim(); - S32 downscaledDim = mDim >> GFXTextureManager::getTextureDownscalePower(&GFXDefaultStaticDiffuseProfile); + S32 downscaledDim = mDim >> GFXTextureManager::getTextureDownscalePower(&GFXStaticTextureSRGBProfile); // Ok... pack in bitmaps till we run out. Vector imposterUVs; @@ -482,14 +482,14 @@ void TSLastDetail::_update() // DEBUG: Some code to force usage of a test image. //GBitmap* tempMap = GBitmap::load( "./forest/data/test1234.png" ); //tempMap->extrudeMipLevels(); - //mTexture.set( tempMap, &GFXDefaultStaticDiffuseProfile, false ); + //mTexture.set( tempMap, &GFXStaticTextureSRGBProfile, false ); //delete tempMap; DDSFile *ddsDest = DDSFile::createDDSFileFromGBitmap( &destBmp ); - DDSUtil::squishDDS( ddsDest, GFXFormatDXT3 ); + ImageUtil::ddsCompress( ddsDest, GFXFormatBC2 ); DDSFile *ddsNormals = DDSFile::createDDSFileFromGBitmap( &destNormal ); - DDSUtil::squishDDS( ddsNormals, GFXFormatDXT5 ); + ImageUtil::ddsCompress( ddsNormals, GFXFormatBC3 ); // Finally save the imposters to disk. FileStream fs; diff --git a/Engine/source/ts/tsMaterialList.cpp b/Engine/source/ts/tsMaterialList.cpp index 78a8a720a..5236b4bbb 100644 --- a/Engine/source/ts/tsMaterialList.cpp +++ b/Engine/source/ts/tsMaterialList.cpp @@ -291,12 +291,12 @@ bool TSMaterialList::renameMaterial(U32 i, const String& newName) GFXTexHandle texHandle; if (mLookupPath.isEmpty()) { - texHandle.set( newName, &GFXDefaultStaticDiffuseProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) ); + texHandle.set( newName, &GFXStaticTextureSRGBProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) ); } else { String fullPath = String::ToString( "%s/%s", mLookupPath.c_str(), newName.c_str() ); - texHandle.set( fullPath, &GFXDefaultStaticDiffuseProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) ); + texHandle.set( fullPath, &GFXStaticTextureSRGBProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) ); } if (!texHandle.isValid()) return false; diff --git a/Engine/source/util/imposterCapture.cpp b/Engine/source/util/imposterCapture.cpp index 7984268e8..ffc36bad8 100644 --- a/Engine/source/util/imposterCapture.cpp +++ b/Engine/source/util/imposterCapture.cpp @@ -118,7 +118,7 @@ void ImposterCaptureMaterialHook::init( BaseMatInstance *inMat ) mDiffuseMatInst->getFeaturesDelegate().bind( &ImposterCaptureMaterialHook::_overrideFeatures ); mDiffuseMatInst->init( features, inMat->getVertexFormat() ); - features.addFeature( MFT_IsDXTnm ); + features.addFeature( MFT_IsBC3nm ); features.addFeature( MFT_NormalMap ); features.addFeature( MFT_NormalsOut ); features.addFeature( MFT_AccuMap ); @@ -176,7 +176,7 @@ ImposterCapture::~ImposterCapture() void ImposterCapture::_colorAverageFilter( U32 dimensions, const U8 *inBmpBits, U8 *outBmpBits ) { - ColorF color; + LinearColorF color; U32 count = 0; U32 index, index2; @@ -372,10 +372,10 @@ void ImposterCapture::begin( TSShapeInstance *shapeInst, mRadius = radius; mCenter = center; - mBlackTex.set( mDim, mDim, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); - mWhiteTex.set( mDim, mDim, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); - mNormalTex.set( mDim, mDim, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); - mDepthBuffer.set( mDim, mDim, GFXFormatD24S8, &GFXDefaultZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); + mBlackTex.set( mDim, mDim, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); + mWhiteTex.set( mDim, mDim, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); + mNormalTex.set( mDim, mDim, GFXFormatR8G8B8A8, &GFXRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); + mDepthBuffer.set( mDim, mDim, GFXFormatD24S8, &GFXZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) ); // copy the black render target data into a bitmap mBlackBmp = new GBitmap; diff --git a/Templates/Full/game/art/gui/optionsDlg.gui b/Templates/Full/game/art/gui/optionsDlg.gui index 9f12a272a..6c2004097 100644 --- a/Templates/Full/game/art/gui/optionsDlg.gui +++ b/Templates/Full/game/art/gui/optionsDlg.gui @@ -1314,66 +1314,6 @@ canSaveDynamicFields = "0"; }; }; - new GuiControl() { - position = "0 190"; - extent = "352 15"; - minExtent = "8 2"; - horizSizing = "width"; - vertSizing = "bottom"; - profile = "GuiDefaultProfile"; - visible = "1"; - active = "1"; - tooltipProfile = "GuiToolTipProfile"; - hovertime = "1000"; - isContainer = "1"; - internalName = "GammaSliderContainer"; - canSave = "1"; - canSaveDynamicFields = "0"; - - new GuiSliderCtrl() { - range = "2.0 2.5"; - ticks = "0"; - snap = "0"; - value = "2.2"; - position = "76 -1"; - extent = "268 15"; - minExtent = "8 2"; - horizSizing = "right"; - vertSizing = "bottom"; - profile = "GuiSliderProfile"; - visible = "1"; - active = "1"; - variable = "$pref::Video::Gamma"; - tooltipProfile = "GuiToolTipProfile"; - hovertime = "1000"; - isContainer = "0"; - canSave = "1"; - canSaveDynamicFields = "0"; - }; - new GuiTextCtrl() { - text = "Gamma:"; - maxLength = "255"; - margin = "0 0 0 0"; - padding = "0 0 0 0"; - anchorTop = "1"; - anchorBottom = "0"; - anchorLeft = "1"; - anchorRight = "0"; - position = "22 -4"; - extent = "105 18"; - minExtent = "8 2"; - horizSizing = "right"; - vertSizing = "bottom"; - profile = "GuiTextProfile"; - visible = "1"; - active = "1"; - tooltipProfile = "GuiToolTipProfile"; - hovertime = "1000"; - isContainer = "0"; - canSave = "1"; - canSaveDynamicFields = "0"; - }; - }; new GuiControl() { position = "0 208"; extent = "352 15"; diff --git a/Templates/Full/game/core/scripts/client/defaults.cs b/Templates/Full/game/core/scripts/client/defaults.cs index 20774856e..d100b4add 100644 --- a/Templates/Full/game/core/scripts/client/defaults.cs +++ b/Templates/Full/game/core/scripts/client/defaults.cs @@ -77,15 +77,6 @@ $pref::Video::Gamma = 2.2; $pref::Video::Contrast = 1.0; $pref::Video::Brightness = 0; -// Console-friendly defaults -if($platform $= "xenon") -{ - // Save some fillrate on the X360, and take advantage of the HW scaling - $pref::Video::Resolution = "1152 640"; - $pref::Video::mode = $pref::Video::Resolution SPC "true 32 60 0"; - $pref::Video::fullScreen = 1; -} - /// This is the path used by ShaderGen to cache procedural /// shaders. If left blank ShaderGen will only cache shaders /// to memory and not to disk. @@ -160,7 +151,7 @@ $pref::SFX::channelVolume6 = 1; $pref::SFX::channelVolume7 = 1; $pref::SFX::channelVolume8 = 1; -$pref::PostEffect::PreferedHDRFormat = "GFXFormatR8G8B8A8"; +$pref::PostEffect::PreferedHDRFormat = "GFXFormatR16G16B16A16F"; /// This is an scalar which can be used to reduce the /// reflection textures on all objects to save fillrate. diff --git a/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs b/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs index 21777cf2d..e0a802243 100644 --- a/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs +++ b/Templates/Full/game/core/scripts/client/lighting/advanced/deferredShading.cs @@ -35,6 +35,7 @@ new GFXStateBlockData( AL_DeferredShadingState : PFX_DefaultStateBlock ) samplerStates[1] = SamplerWrapLinear; samplerStates[2] = SamplerWrapLinear; samplerStates[3] = SamplerWrapLinear; + samplerStates[4] = SamplerWrapLinear; }; new ShaderData( AL_DeferredShader ) diff --git a/Templates/Full/game/core/scripts/client/postFx/GammaPostFX.cs b/Templates/Full/game/core/scripts/client/postFx/GammaPostFX.cs index a61a3af9d..b6923de40 100644 --- a/Templates/Full/game/core/scripts/client/postFx/GammaPostFX.cs +++ b/Templates/Full/game/core/scripts/client/postFx/GammaPostFX.cs @@ -48,14 +48,14 @@ singleton PostEffect( GammaPostFX ) renderTime = "PFXBeforeBin"; renderBin = "EditorBin"; - renderPriority = 9999; + renderPriority = 9998; shader = GammaShader; stateBlock = GammaStateBlock; texture[0] = "$backBuffer"; texture[1] = $HDRPostFX::colorCorrectionRamp; - targetFormat = getBestHDRFormat(); + textureSRGB[1] = true; }; function GammaPostFX::preProcess( %this ) diff --git a/Templates/Full/game/core/scripts/client/postFx/hdr.cs b/Templates/Full/game/core/scripts/client/postFx/hdr.cs index f4e3dfdec..13ee07b91 100644 --- a/Templates/Full/game/core/scripts/client/postFx/hdr.cs +++ b/Templates/Full/game/core/scripts/client/postFx/hdr.cs @@ -275,10 +275,6 @@ function HDRPostFX::preProcess( %this ) function HDRPostFX::onEnabled( %this ) { - // We don't allow hdr on OSX yet. - if ( $platform $= "macos" ) - return false; - // See what HDR format would be best. %format = getBestHDRFormat(); if ( %format $= "" || %format $= "GFXFormatR8G8B8A8" ) diff --git a/Templates/Full/game/core/scripts/client/renderManager.cs b/Templates/Full/game/core/scripts/client/renderManager.cs index ea7f84d03..f9f0988d2 100644 --- a/Templates/Full/game/core/scripts/client/renderManager.cs +++ b/Templates/Full/game/core/scripts/client/renderManager.cs @@ -32,8 +32,8 @@ function initRenderManager() new RenderFormatToken(AL_FormatToken) { enabled = "false"; - - format = getBestHDRFormat(); + //When hdr is enabled this will be changed to the appropriate format + format = "GFXFormatR8G8B8A8_SRGB"; depthFormat = "GFXFormatD24S8"; aaLevel = 0; // -1 = match backbuffer diff --git a/Templates/Full/game/levels/Outpost.postfxpreset.cs b/Templates/Full/game/levels/Outpost.postfxpreset.cs index 01f6d1ae5..14aa45fb0 100644 --- a/Templates/Full/game/levels/Outpost.postfxpreset.cs +++ b/Templates/Full/game/levels/Outpost.postfxpreset.cs @@ -18,7 +18,7 @@ $PostFXManager::Settings::HDR::blueShiftColor = "1.05 0.97 1.27"; $PostFXManager::Settings::HDR::brightPassThreshold = "0.631579"; $PostFXManager::Settings::HDR::enableBloom = "1"; $PostFXManager::Settings::HDR::enableBlueShift = "0"; -$PostFXManager::Settings::HDR::enableToneMapping = "1"; +$PostFXManager::Settings::HDR::enableToneMapping = "0.5"; $PostFXManager::Settings::HDR::gaussMean = "0.0526316"; $PostFXManager::Settings::HDR::gaussMultiplier = "0.31746"; $PostFXManager::Settings::HDR::gaussStdDev = "0.8"; diff --git a/Templates/Full/game/shaders/common/VolumetricFog/VFogP.hlsl b/Templates/Full/game/shaders/common/VolumetricFog/VFogP.hlsl index 9fdf5c882..7de14a87d 100644 --- a/Templates/Full/game/shaders/common/VolumetricFog/VFogP.hlsl +++ b/Templates/Full/game/shaders/common/VolumetricFog/VFogP.hlsl @@ -56,7 +56,7 @@ float4 main( ConnectData IN ) : TORQUE_TARGET0 float2 uvscreen=((IN.htpos.xy/IN.htpos.w) + 1.0 ) / 2.0; uvscreen.y = 1.0 - uvscreen.y; - float obj_test = TORQUE_PREPASS_UNCONDITION(deferredTex, uvscreen).w * preBias; + float obj_test = TORQUE_DEFERRED_UNCONDITION(deferredTex, uvscreen).w * preBias; float depth = TORQUE_TEX2D(depthBuffer, uvscreen).r; float front = TORQUE_TEX2D(frontBuffer, uvscreen).r; diff --git a/Templates/Full/game/shaders/common/lighting/advanced/dbgDepthVisualizeP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/dbgDepthVisualizeP.hlsl index b04330f06..c859bcab0 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/dbgDepthVisualizeP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/dbgDepthVisualizeP.hlsl @@ -28,6 +28,6 @@ TORQUE_UNIFORM_SAMPLER1D(depthViz, 1); float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 { - float depth = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ).w; + float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w; return float4( TORQUE_TEX1D( depthViz, depth ).rgb, 1.0 ); } diff --git a/Templates/Full/game/shaders/common/lighting/advanced/dbgNormalVisualizeP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/dbgNormalVisualizeP.hlsl index 8ba3e0d39..c0979b079 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/dbgNormalVisualizeP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/dbgNormalVisualizeP.hlsl @@ -27,6 +27,6 @@ TORQUE_UNIFORM_SAMPLER2D(deferredTex, 0); float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 { - float3 normal = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ).xyz; + float3 normal = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).xyz; return float4( ( normal + 1.0 ) * 0.5, 1.0 ); } \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl index eac5d80d6..301c9e35c 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/deferredShadingP.hlsl @@ -35,7 +35,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 float4 colorBuffer = TORQUE_TEX2D( colorBufferTex, IN.uv0 ); float4 matInfo = TORQUE_TEX2D( matInfoTex, IN.uv0 ); float specular = saturate(lightBuffer.a); - float depth = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ).w; + float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w; if (depth>0.9999) return float4(0,0,0,0); diff --git a/Templates/Full/game/shaders/common/lighting/advanced/particlePointLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/particlePointLightP.hlsl index c3cb05dd0..a0156eb85 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/particlePointLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/particlePointLightP.hlsl @@ -49,7 +49,7 @@ float4 main( ConvexConnectP IN ) : TORQUE_TARGET0 float2 uvScene = getUVFromSSPos(ssPos, rtParams0); // Sample/unpack the normal/z data - float4 deferredSample = TORQUE_PREPASS_UNCONDITION(deferredBuffer, uvScene); + float4 deferredSample = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene); float3 normal = deferredSample.rgb; float depth = deferredSample.a; diff --git a/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl index 14364ec16..317feb0b3 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/pointLightP.hlsl @@ -161,7 +161,7 @@ float4 main( ConvexConnectP IN ) : TORQUE_TARGET0 } // Sample/unpack the normal/z data - float4 deferredSample = TORQUE_PREPASS_UNCONDITION( deferredBuffer, uvScene ); + float4 deferredSample = TORQUE_DEFERRED_UNCONDITION( deferredBuffer, uvScene ); float3 normal = deferredSample.rgb; float depth = deferredSample.a; diff --git a/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl index d9958ebc5..196286dc2 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/spotLightP.hlsl @@ -99,7 +99,7 @@ float4 main( ConvexConnectP IN ) : TORQUE_TARGET0 } // Sample/unpack the normal/z data - float4 deferredSample = TORQUE_PREPASS_UNCONDITION( deferredBuffer, uvScene ); + float4 deferredSample = TORQUE_DEFERRED_UNCONDITION( deferredBuffer, uvScene ); float3 normal = deferredSample.rgb; float depth = deferredSample.a; diff --git a/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl index 1fd2ab8dd..c5efde242 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/vectorLightP.hlsl @@ -213,7 +213,7 @@ float4 main( FarFrustumQuadConnectP IN ) : TORQUE_TARGET0 subsurface = float3(0.337255, 0.772549, 0.262745); } // Sample/unpack the normal/z data - float4 deferredSample = TORQUE_PREPASS_UNCONDITION( deferredBuffer, IN.uv0 ); + float4 deferredSample = TORQUE_DEFERRED_UNCONDITION( deferredBuffer, IN.uv0 ); float3 normal = deferredSample.rgb; float depth = deferredSample.a; diff --git a/Templates/Full/game/shaders/common/particlesP.hlsl b/Templates/Full/game/shaders/common/particlesP.hlsl index c3fb6ceb9..155107d8b 100644 --- a/Templates/Full/game/shaders/common/particlesP.hlsl +++ b/Templates/Full/game/shaders/common/particlesP.hlsl @@ -84,7 +84,7 @@ float4 main( Conn IN ) : TORQUE_TARGET0 float2 tc = IN.pos.xy * float2(1.0, -1.0) / IN.pos.w; tc = viewportCoordToRenderTarget(saturate( ( tc + 1.0 ) * 0.5 ), deferredTargetParams); - float sceneDepth = TORQUE_PREPASS_UNCONDITION(deferredTex, tc).w; + float sceneDepth = TORQUE_DEFERRED_UNCONDITION(deferredTex, tc).w; float depth = IN.pos.w * oneOverFar; float diff = sceneDepth - depth; #ifdef CLIP_Z diff --git a/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl b/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl index 923cdeadd..8c8abd480 100644 --- a/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl @@ -40,7 +40,7 @@ float distanceToPlane(float4 plane, float3 pos) float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 { //Sample the pre-pass - float4 deferred = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ); + float4 deferred = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ); //Get depth float depth = deferred.w; diff --git a/Templates/Full/game/shaders/common/postFx/dof/DOF_DownSample_P.hlsl b/Templates/Full/game/shaders/common/postFx/dof/DOF_DownSample_P.hlsl index 8c9028654..907c3d122 100644 --- a/Templates/Full/game/shaders/common/postFx/dof/DOF_DownSample_P.hlsl +++ b/Templates/Full/game/shaders/common/postFx/dof/DOF_DownSample_P.hlsl @@ -88,10 +88,10 @@ half4 main( Pixel IN ) : TORQUE_TARGET0 [unroll] // coc[i] causes this anyway for (int i = 0; i < 4; i++) { - depth[0] = TORQUE_PREPASS_UNCONDITION(depthSampler, (IN.tcDepth0.xy + rowOfs[i])).w; - depth[1] = TORQUE_PREPASS_UNCONDITION(depthSampler, (IN.tcDepth1.xy + rowOfs[i])).w; - depth[2] = TORQUE_PREPASS_UNCONDITION(depthSampler, (IN.tcDepth2.xy + rowOfs[i])).w; - depth[3] = TORQUE_PREPASS_UNCONDITION(depthSampler, (IN.tcDepth3.xy + rowOfs[i])).w; + depth[0] = TORQUE_DEFERRED_UNCONDITION(depthSampler, (IN.tcDepth0.xy + rowOfs[i])).w; + depth[1] = TORQUE_DEFERRED_UNCONDITION(depthSampler, (IN.tcDepth1.xy + rowOfs[i])).w; + depth[2] = TORQUE_DEFERRED_UNCONDITION(depthSampler, (IN.tcDepth2.xy + rowOfs[i])).w; + depth[3] = TORQUE_DEFERRED_UNCONDITION(depthSampler, (IN.tcDepth3.xy + rowOfs[i])).w; coc = max(coc, clamp(dofEqWorld4X * half4(depth)+dofEqWorld4Y, zero4, maxWorldCoC4)); } diff --git a/Templates/Full/game/shaders/common/postFx/dof/DOF_Final_P.hlsl b/Templates/Full/game/shaders/common/postFx/dof/DOF_Final_P.hlsl index cb7342d40..9a7cb3d5e 100644 --- a/Templates/Full/game/shaders/common/postFx/dof/DOF_Final_P.hlsl +++ b/Templates/Full/game/shaders/common/postFx/dof/DOF_Final_P.hlsl @@ -71,7 +71,7 @@ half4 InterpolateDof( half3 small, half3 med, half3 large, half t ) // d0, the small to medium blur over distance d1, and the medium to // large blur over distance d2, where d0 + d1 + d2 = 1. //float4 dofLerpScale = float4( -1 / d0, -1 / d1, -1 / d2, 1 / d2 ); - //float4 dofLerpBias = float4( 1, (1 – d2) / d1, 1 / d2, (d2 – 1) / d2 ); + //float4 dofLerpBias = float4( 1, (1 � d2) / d1, 1 / d2, (d2 � 1) / d2 ); weights = half4(saturate( t * dofLerpScale + dofLerpBias )); weights.yz = min( weights.yz, 1 - weights.xy ); @@ -115,7 +115,7 @@ half4 main( PFXVertToPix IN ) : TORQUE_TARGET0 //med.rgb = large; //nearCoc = 0; - depth = half(TORQUE_PREPASS_UNCONDITION( depthSampler, IN.uv3 ).w); + depth = half(TORQUE_DEFERRED_UNCONDITION( depthSampler, IN.uv3 ).w); //return half4(depth.rrr,1); //return half4(nearCoc.rrr,1.0); diff --git a/Templates/Full/game/shaders/common/postFx/edgeaa/edgeDetectP.hlsl b/Templates/Full/game/shaders/common/postFx/edgeaa/edgeDetectP.hlsl index d9988341c..c8bfb2153 100644 --- a/Templates/Full/game/shaders/common/postFx/edgeaa/edgeDetectP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/edgeaa/edgeDetectP.hlsl @@ -50,7 +50,7 @@ float GetEdgeWeight(float2 uv0, in float2 targetSize) for(int i = 0; i < 9; i++) { float2 uv = uv0 + offsets[i] * PixelSize; - float4 gbSample = TORQUE_PREPASS_UNCONDITION( deferredBuffer, uv ); + float4 gbSample = TORQUE_DEFERRED_UNCONDITION( deferredBuffer, uv ); Depth[i] = gbSample.a; Normal[i] = gbSample.rgb; } diff --git a/Templates/Full/game/shaders/common/postFx/fogP.hlsl b/Templates/Full/game/shaders/common/postFx/fogP.hlsl index 437d8c396..5d349249f 100644 --- a/Templates/Full/game/shaders/common/postFx/fogP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/fogP.hlsl @@ -34,7 +34,7 @@ uniform float4 rtParams0; float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 { //float2 deferredCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy; - float depth = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ).w; + float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w; //return float4( depth, 0, 0, 0.7 ); float factor = computeSceneFog( eyePosWorld, @@ -43,5 +43,5 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 fogData.y, fogData.z ); - return hdrEncode( float4( toLinear(fogColor.rgb), 1.0 - saturate( factor ) ) ); + return hdrEncode( float4( fogColor.rgb, 1.0 - saturate( factor ) ) ); } \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/postFx/gammaP.hlsl b/Templates/Full/game/shaders/common/postFx/gammaP.hlsl index 21b86fe4e..1e13d068b 100644 --- a/Templates/Full/game/shaders/common/postFx/gammaP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/gammaP.hlsl @@ -40,9 +40,6 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 color.g = TORQUE_TEX1D( colorCorrectionTex, color.g ).g; color.b = TORQUE_TEX1D( colorCorrectionTex, color.b ).b; - // Apply gamma correction - color.rgb = pow( saturate(color.rgb), OneOverGamma ); - // Apply contrast color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f; diff --git a/Templates/Full/game/shaders/common/postFx/gl/fogP.glsl b/Templates/Full/game/shaders/common/postFx/gl/fogP.glsl index 9dbc435fe..302efeb71 100644 --- a/Templates/Full/game/shaders/common/postFx/gl/fogP.glsl +++ b/Templates/Full/game/shaders/common/postFx/gl/fogP.glsl @@ -48,5 +48,5 @@ void main() fogData.y, fogData.z ); - OUT_col = hdrEncode( vec4( toLinear(fogColor.rgb), 1.0 - saturate( factor ) ) ); -} \ No newline at end of file + OUT_col = hdrEncode( vec4( fogColor.rgb, 1.0 - saturate( factor ) ) ); +} diff --git a/Templates/Full/game/shaders/common/postFx/gl/gammaP.glsl b/Templates/Full/game/shaders/common/postFx/gl/gammaP.glsl index a170bf39f..04533e494 100644 --- a/Templates/Full/game/shaders/common/postFx/gl/gammaP.glsl +++ b/Templates/Full/game/shaders/common/postFx/gl/gammaP.glsl @@ -44,9 +44,6 @@ void main() color.g = texture( colorCorrectionTex, color.g ).g; color.b = texture( colorCorrectionTex, color.b ).b; - // Apply gamma correction - color.rgb = pow( clamp(color.rgb, vec3(0.0),vec3(1.0)), vec3(OneOverGamma) ); - // Apply contrast color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f; diff --git a/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl b/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl index f87616a6e..07f7276c3 100644 --- a/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl @@ -87,15 +87,6 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 sample.r = TORQUE_TEX1D( colorCorrectionTex, sample.r ).r; sample.g = TORQUE_TEX1D( colorCorrectionTex, sample.g ).g; sample.b = TORQUE_TEX1D( colorCorrectionTex, sample.b ).b; - - // Apply gamma correction - sample.rgb = pow( saturate(sample.rgb), g_fOneOverGamma ); - - // Apply contrast - sample.rgb = ((sample.rgb - 0.5f) * Contrast) + 0.5f; - - // Apply brightness - sample.rgb += Brightness; return sample; } diff --git a/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl b/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl index 8437cb04b..4b173d4d3 100644 --- a/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl +++ b/Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl @@ -93,14 +93,5 @@ void main() _sample.g = texture( colorCorrectionTex, _sample.g ).g; _sample.b = texture( colorCorrectionTex, _sample.b ).b; - // Apply gamma correction - _sample.rgb = pow( _sample.rgb, vec3(g_fOneOverGamma) ); - - // Apply contrast - _sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f; - - // Apply brightness - _sample.rgb += Brightness; - OUT_col = _sample; } diff --git a/Templates/Full/game/shaders/common/postFx/lightRay/lightRayOccludeP.hlsl b/Templates/Full/game/shaders/common/postFx/lightRay/lightRayOccludeP.hlsl index 1a0e4222f..5db6ecb5b 100644 --- a/Templates/Full/game/shaders/common/postFx/lightRay/lightRayOccludeP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/lightRay/lightRayOccludeP.hlsl @@ -36,7 +36,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 float4 col = float4( 0, 0, 0, 1 ); // Get the depth at this pixel. - float depth = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ).w; + float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w; // If the depth is equal to 1.0, read from the backbuffer // and perform the exposure calculation on the result. diff --git a/Templates/Full/game/shaders/common/postFx/motionBlurP.hlsl b/Templates/Full/game/shaders/common/postFx/motionBlurP.hlsl index 50839fe1e..90b8f6f25 100644 --- a/Templates/Full/game/shaders/common/postFx/motionBlurP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/motionBlurP.hlsl @@ -37,7 +37,7 @@ float4 main(PFXVertToPix IN) : TORQUE_TARGET0 float samples = 5; // First get the deferred texture for uv channel 0 - float4 deferred = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ); + float4 deferred = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ); // Next extract the depth float depth = deferred.a; diff --git a/Templates/Full/game/shaders/common/postFx/ssao/SSAO_Blur_P.hlsl b/Templates/Full/game/shaders/common/postFx/ssao/SSAO_Blur_P.hlsl index 0a49622cf..a47261397 100644 --- a/Templates/Full/game/shaders/common/postFx/ssao/SSAO_Blur_P.hlsl +++ b/Templates/Full/game/shaders/common/postFx/ssao/SSAO_Blur_P.hlsl @@ -49,7 +49,7 @@ uniform float blurNormalTol; void sample( float2 uv, float weight, float4 centerTap, inout int usedCount, inout float occlusion, inout float total ) { //return; - float4 tap = TORQUE_PREPASS_UNCONDITION( deferredMap, uv ); + float4 tap = TORQUE_DEFERRED_UNCONDITION( deferredMap, uv ); if ( abs( tap.a - centerTap.a ) < blurDepthTol ) { @@ -65,7 +65,7 @@ void sample( float2 uv, float weight, float4 centerTap, inout int usedCount, ino float4 main( VertToPix IN ) : TORQUE_TARGET0 { //float4 centerTap; - float4 centerTap = TORQUE_PREPASS_UNCONDITION( deferredMap, IN.uv0.zw ); + float4 centerTap = TORQUE_DEFERRED_UNCONDITION( deferredMap, IN.uv0.zw ); //return centerTap; diff --git a/Templates/Full/game/shaders/common/postFx/ssao/SSAO_P.hlsl b/Templates/Full/game/shaders/common/postFx/ssao/SSAO_P.hlsl index 66aa3e8d3..67365e846 100644 --- a/Templates/Full/game/shaders/common/postFx/ssao/SSAO_P.hlsl +++ b/Templates/Full/game/shaders/common/postFx/ssao/SSAO_P.hlsl @@ -143,7 +143,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 float3 reflectNormal = normalize( TORQUE_TEX2DLOD( randNormalTex, noiseMapUV ).xyz * 2.0 - 1.0 ); //return float4( reflectNormal, 1 ); - float4 deferred = TORQUE_PREPASS_UNCONDITION( deferredMap, IN.uv0 ); + float4 deferred = TORQUE_DEFERRED_UNCONDITION( deferredMap, IN.uv0 ); float3 normal = deferred.xyz; float depth = deferred.a; //return float4( ( depth ).xxx, 1 ); @@ -183,7 +183,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 //if ( radiusDepth.x < 1.0 / targetSize.x ) // return color; //radiusDepth.xyz = 0.0009; - + [unroll] for ( i = 0; i < sSampleCount; i++ ) { baseRay = reflect( ptSphere[i], reflectNormal ); @@ -197,7 +197,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 se = ep + ray; - occluderFragment = TORQUE_PREPASS_UNCONDITION( deferredMap, se.xy ); + occluderFragment = TORQUE_DEFERRED_UNCONDITION( deferredMap, se.xy ); depthDiff = se.z - occluderFragment.a; @@ -232,7 +232,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 //if ( radiusDepth.x < 1.0 / targetSize.x ) // return color; //radiusDepth.xyz = 0.0009; - + [unroll] for ( i = sSampleCount; i < totalSampleCount; i++ ) { baseRay = reflect( ptSphere[i], reflectNormal ); @@ -246,7 +246,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 se = ep + ray; - occluderFragment = TORQUE_PREPASS_UNCONDITION( deferredMap, se.xy ); + occluderFragment = TORQUE_DEFERRED_UNCONDITION( deferredMap, se.xy ); depthDiff = se.z - occluderFragment.a; diff --git a/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl b/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl index b7d126f54..aab43c45c 100644 --- a/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl @@ -55,7 +55,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 { //float2 deferredCoord = IN.uv0; //IN.uv0 = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy; - float depth = TORQUE_PREPASS_UNCONDITION( deferredTex, IN.uv0 ).w; + float depth = TORQUE_DEFERRED_UNCONDITION( deferredTex, IN.uv0 ).w; //return float4( depth.rrr, 1 ); // Skip fogging the extreme far plane so that diff --git a/Templates/Full/game/shaders/common/shaderModelAutoGen.hlsl b/Templates/Full/game/shaders/common/shaderModelAutoGen.hlsl index 33531cbf6..d70847e46 100644 --- a/Templates/Full/game/shaders/common/shaderModelAutoGen.hlsl +++ b/Templates/Full/game/shaders/common/shaderModelAutoGen.hlsl @@ -27,9 +27,9 @@ // Portability helpers for autogenConditioners #if (TORQUE_SM >= 10 && TORQUE_SM <=30) - #define TORQUE_PREPASS_UNCONDITION(tex, coords) deferredUncondition(tex, coords) + #define TORQUE_DEFERRED_UNCONDITION(tex, coords) deferredUncondition(tex, coords) #elif TORQUE_SM >= 40 - #define TORQUE_PREPASS_UNCONDITION(tex, coords) deferredUncondition(tex, texture_##tex, coords) + #define TORQUE_DEFERRED_UNCONDITION(tex, coords) deferredUncondition(tex, texture_##tex, coords) #endif #endif //_TORQUE_SHADERMODEL_AUTOGEN_ diff --git a/Templates/Full/game/shaders/common/water/gl/waterBasicP.glsl b/Templates/Full/game/shaders/common/water/gl/waterBasicP.glsl index 9ece76b72..aba0cfa7e 100644 --- a/Templates/Full/game/shaders/common/water/gl/waterBasicP.glsl +++ b/Templates/Full/game/shaders/common/water/gl/waterBasicP.glsl @@ -120,7 +120,7 @@ void main() { // Modulate baseColor by the ambientColor. vec4 waterBaseColor = baseColor * vec4( ambientColor.rgb, 1 ); - waterBaseColor = toLinear(waterBaseColor); + waterBaseColor = waterBaseColor; // Get the bumpNorm... vec3 bumpNorm = ( texture( bumpMap, IN_rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x; diff --git a/Templates/Full/game/shaders/common/water/gl/waterP.glsl b/Templates/Full/game/shaders/common/water/gl/waterP.glsl index 512eebda9..98fab6a33 100644 --- a/Templates/Full/game/shaders/common/water/gl/waterP.glsl +++ b/Templates/Full/game/shaders/common/water/gl/waterP.glsl @@ -324,7 +324,7 @@ void main() // Calculate the water "base" color based on depth. vec4 waterBaseColor = baseColor * texture( depthGradMap, saturate( delta / depthGradMax ) ); - waterBaseColor = toLinear(waterBaseColor); + waterBaseColor = waterBaseColor; // Modulate baseColor by the ambientColor. waterBaseColor *= vec4( ambientColor.rgb, 1 ); diff --git a/Templates/Full/game/shaders/common/water/waterBasicP.hlsl b/Templates/Full/game/shaders/common/water/waterBasicP.hlsl index f34a4e551..ae97fab8e 100644 --- a/Templates/Full/game/shaders/common/water/waterBasicP.hlsl +++ b/Templates/Full/game/shaders/common/water/waterBasicP.hlsl @@ -117,7 +117,7 @@ float4 main( ConnectData IN ) : TORQUE_TARGET0 { // Modulate baseColor by the ambientColor. float4 waterBaseColor = baseColor * float4( ambientColor.rgb, 1 ); - waterBaseColor = toLinear(waterBaseColor); + waterBaseColor = waterBaseColor; // Get the bumpNorm... float3 bumpNorm = ( TORQUE_TEX2D( bumpMap, IN.rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x; diff --git a/Templates/Full/game/shaders/common/water/waterP.hlsl b/Templates/Full/game/shaders/common/water/waterP.hlsl index 25820d403..6d36c8029 100644 --- a/Templates/Full/game/shaders/common/water/waterP.hlsl +++ b/Templates/Full/game/shaders/common/water/waterP.hlsl @@ -155,7 +155,7 @@ float4 main( ConnectData IN ) : TORQUE_TARGET0 float2 deferredCoord = viewportCoordToRenderTarget( IN.posPostWave, rtParams1 ); - float startDepth = TORQUE_PREPASS_UNCONDITION( deferredTex, deferredCoord ).w; + float startDepth = TORQUE_DEFERRED_UNCONDITION( deferredTex, deferredCoord ).w; // The water depth in world units of the undistorted pixel. float startDelta = ( startDepth - pixelDepth ); @@ -180,7 +180,7 @@ float4 main( ConnectData IN ) : TORQUE_TARGET0 deferredCoord = viewportCoordToRenderTarget( distortPos, rtParams1 ); // Get deferred depth at the position of this distorted pixel. - float deferredDepth = TORQUE_PREPASS_UNCONDITION( deferredTex, deferredCoord ).w; + float deferredDepth = TORQUE_DEFERRED_UNCONDITION( deferredTex, deferredCoord ).w; if ( deferredDepth > 0.99 ) deferredDepth = 5.0; @@ -212,7 +212,7 @@ float4 main( ConnectData IN ) : TORQUE_TARGET0 deferredCoord = viewportCoordToRenderTarget( distortPos, rtParams1 ); // Get deferred depth at the position of this distorted pixel. - deferredDepth = TORQUE_PREPASS_UNCONDITION( deferredTex, deferredCoord ).w; + deferredDepth = TORQUE_DEFERRED_UNCONDITION( deferredTex, deferredCoord ).w; if ( deferredDepth > 0.99 ) deferredDepth = 5.0; delta = ( deferredDepth - pixelDepth ) * farPlaneDist; @@ -311,7 +311,7 @@ float4 main( ConnectData IN ) : TORQUE_TARGET0 // Calculate the water "base" color based on depth. float4 waterBaseColor = baseColor * TORQUE_TEX1D( depthGradMap, saturate( delta / depthGradMax ) ); - waterBaseColor = toLinear(waterBaseColor); + waterBaseColor = waterBaseColor; // Modulate baseColor by the ambientColor. waterBaseColor *= float4( ambientColor.rgb, 1 ); diff --git a/Templates/Full/game/tools/gui/colorPicker.ed.gui b/Templates/Full/game/tools/gui/colorPicker.ed.gui index d8f15e76b..c203ca52e 100644 --- a/Templates/Full/game/tools/gui/colorPicker.ed.gui +++ b/Templates/Full/game/tools/gui/colorPicker.ed.gui @@ -718,22 +718,6 @@ canSave = "1"; canSaveDynamicFields = "0"; }; - new GuiCheckBoxCtrl() { - text = "use sRGB"; - groupNum = "-1"; - buttonType = "ToggleButton"; - useMouseEvents = "0"; - position = "360 105"; - extent = "66 16"; - minExtent = "8 2"; - horizSizing = "right"; - vertSizing = "bottom"; - profile = "GuiCheckBoxProfile"; - visible = "1"; - active = "1"; - variable = "$displayAsSRGB"; - command = "useSRGBctrl($displayAsSRGB);"; - }; }; }; //--- OBJECT WRITE END --- @@ -743,15 +727,6 @@ $ColorPickerCancelCallback = ""; $ColorPickerUpdateCallback = ""; $ColorCallbackType = 1; // ColorI -function useSRGBctrl(%colorScale) -{ -ColorPickerDlg.useSRGB = %colorScale; -ColorRangeSelect.useSRGB = %colorScale; -ColorBlendSelect.useSRGB = %colorScale; -myColor.useSRGB = %colorScale; -oldColor.useSRGB = %colorScale; -} - // This function pushes the color picker dialog and returns to a callback the selected value function GetColorI( %currentColor, %callback, %root, %updateCallback, %cancelCallback ) {