cubemapData.cpp
Engine/source/gfx/sim/cubemapData.cpp
Public Functions
ConsoleDocClass(CubemapData , "@brief Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> create static or dynamic <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cubemaps.\n\n</a>" "This object is used with Material, <a href="/coding/class/classwaterobject/">WaterObject</a> , and other objects <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> cubemap <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reflections.\n\n</a>" "A simple declaration of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> static <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cubemap:\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classcubemapdata/">CubemapData</a>(SkyboxCubemap)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " cubeFace[0]=\"./skybox_1\";\n" " cubeFace[1] = \"./skybox_2\";\n" " cubeFace[2] = \"./skybox_3\";\n" " cubeFace[3] = \"./skybox_4\";\n" " cubeFace[4] = \"./skybox_5\";\n" " cubeFace[5] = \"./skybox_6\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" "@note The dynamic cubemap functionality in <a href="/coding/class/classcubemapdata/">CubemapData</a> has been depreciated in favor of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ReflectorDesc.\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ReflectorDesc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineMethod(CubemapData , getFilename , const char * , () , "Returns the script filename of where the <a href="/coding/class/classcubemapdata/">CubemapData</a> object was " "defined. This is used by the material editor." )
DefineEngineMethod(CubemapData , save , void , (const char *filename, const GFXFormat format) , ("", GFXFormatBC1) , "Returns the script filename of where the <a href="/coding/class/classcubemapdata/">CubemapData</a> object was " "defined. This is used by the material editor." )
DefineEngineMethod(CubemapData , updateFaces , void , () , "Update the assigned cubemaps faces." )
Detailed Description
Public Functions
ConsoleDocClass(CubemapData , "@brief Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> create static or dynamic <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cubemaps.\n\n</a>" "This object is used with Material, <a href="/coding/class/classwaterobject/">WaterObject</a> , and other objects <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> cubemap <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reflections.\n\n</a>" "A simple declaration of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> static <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cubemap:\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classcubemapdata/">CubemapData</a>(SkyboxCubemap)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " cubeFace[0]=\"./skybox_1\";\n" " cubeFace[1] = \"./skybox_2\";\n" " cubeFace[2] = \"./skybox_3\";\n" " cubeFace[3] = \"./skybox_4\";\n" " cubeFace[4] = \"./skybox_5\";\n" " cubeFace[5] = \"./skybox_6\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" "@note The dynamic cubemap functionality in <a href="/coding/class/classcubemapdata/">CubemapData</a> has been depreciated in favor of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ReflectorDesc.\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ReflectorDesc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineMethod(CubemapData , getFilename , const char * , () , "Returns the script filename of where the <a href="/coding/class/classcubemapdata/">CubemapData</a> object was " "defined. This is used by the material editor." )
DefineEngineMethod(CubemapData , save , void , (const char *filename, const GFXFormat format) , ("", GFXFormatBC1) , "Returns the script filename of where the <a href="/coding/class/classcubemapdata/">CubemapData</a> object was " "defined. This is used by the material editor." )
DefineEngineMethod(CubemapData , updateFaces , void , () , "Update the assigned cubemaps faces." )
IMPLEMENT_CONOBJECT(CubemapData )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "gfx/sim/cubemapData.h" 26 27#include "core/stream/bitStream.h" 28#include "console/consoleTypes.h" 29#include "gfx/gfxCubemap.h" 30#include "gfx/gfxDevice.h" 31#include "gfx/gfxTextureManager.h" 32#include "gfx/gfxTransformSaver.h" 33#include "gfx/gfxDebugEvent.h" 34#include "gfx/gfxAPI.h" 35#include "scene/sceneManager.h" 36#include "console/engineAPI.h" 37#include "math/mathUtils.h" 38#include "gfx/bitmap/cubemapSaver.h" 39 40IMPLEMENT_CONOBJECT( CubemapData ); 41 42CubemapData::CubemapData() 43{ 44 mCubemap = NULL; 45} 46 47CubemapData::~CubemapData() 48{ 49 mCubemap = NULL; 50} 51 52ConsoleDocClass( CubemapData, 53 "@brief Used to create static or dynamic cubemaps.\n\n" 54 "This object is used with Material, WaterObject, and other objects for cubemap reflections.\n\n" 55 "A simple declaration of a static cubemap:\n" 56 "@tsexample\n" 57 "singleton CubemapData( SkyboxCubemap )\n" 58 "{\n" 59 " cubeFace[0] = \"./skybox_1\";\n" 60 " cubeFace[1] = \"./skybox_2\";\n" 61 " cubeFace[2] = \"./skybox_3\";\n" 62 " cubeFace[3] = \"./skybox_4\";\n" 63 " cubeFace[4] = \"./skybox_5\";\n" 64 " cubeFace[5] = \"./skybox_6\";\n" 65 "};\n" 66 "@endtsexample\n" 67 "@note The dynamic cubemap functionality in CubemapData has been depreciated in favor of ReflectorDesc.\n" 68 "@see ReflectorDesc\n" 69 "@ingroup GFX\n" ); 70 71void CubemapData::initPersistFields() 72{ 73 addField( "cubeFace", TypeStringFilename, Offset(mCubeFaceFile, CubemapData), 6, 74 "@brief The 6 cubemap face textures for a static cubemap.\n\n" 75 "They are in the following order:\n" 76 " - cubeFace[0] is -X\n" 77 " - cubeFace[1] is +X\n" 78 " - cubeFace[2] is -Z\n" 79 " - cubeFace[3] is +Z\n" 80 " - cubeFace[4] is -Y\n" 81 " - cubeFace[5] is +Y\n" ); 82 83 addField("cubeMap", TypeStringFilename, Offset(mCubeMapFile, CubemapData), 84 "@brief Cubemap dds file.\n\n"); 85 86} 87 88bool CubemapData::onAdd() 89{ 90 if( !Parent::onAdd() ) 91 return false; 92 93 // Do NOT call this here as it forces every single cubemap defined to load its images, immediately, without mercy 94 // createMap(); 95 96 return true; 97} 98 99void CubemapData::createMap() 100{ 101 if( !mCubemap ) 102 { 103 bool initSuccess = true; 104 //check mCubeMapFile first 105 if (!mCubeMapFile.isEmpty()) 106 { 107 mCubemap = TEXMGR->createCubemap(mCubeMapFile); 108 return; 109 } 110 else 111 { 112 for (U32 i = 0; i < 6; i++) 113 { 114 if (!mCubeFaceFile[i].isEmpty()) 115 { 116 if (!mCubeFace[i].set(mCubeFaceFile[i], &GFXStaticTextureSRGBProfile, avar("%s() - mCubeFace[%d] (line %d)", __FUNCTION__, i, __LINE__))) 117 { 118 Con::errorf("CubemapData::createMap - Failed to load texture '%s'", mCubeFaceFile[i].c_str()); 119 initSuccess = false; 120 } 121 } 122 } 123 } 124 125 if( initSuccess ) 126 { 127 mCubemap = GFX->createCubemap(); 128 if (mCubeFace == NULL || mCubeFace->isNull()) return; 129 mCubemap->initStatic( mCubeFace ); 130 } 131 } 132} 133 134void CubemapData::updateFaces() 135{ 136 bool initSuccess = true; 137 138 for( U32 i=0; i<6; i++ ) 139 { 140 //check mCubeMapFile first 141 if (!mCubeMapFile.isEmpty()) 142 { 143 mCubemap = TEXMGR->createCubemap(mCubeMapFile); 144 return; 145 } 146 else 147 { 148 if (!mCubeFaceFile[i].isEmpty()) 149 { 150 if (!mCubeFace[i].set(mCubeFaceFile[i], &GFXStaticTextureSRGBProfile, avar("%s() - mCubeFace[%d] (line %d)", __FUNCTION__, i, __LINE__))) 151 { 152 initSuccess = false; 153 Con::errorf("CubemapData::createMap - Failed to load texture '%s'", mCubeFaceFile[i].c_str()); 154 } 155 } 156 } 157 } 158 159 if( initSuccess ) 160 { 161 mCubemap = NULL; 162 mCubemap = GFX->createCubemap(); 163 164 mCubemap->initStatic( mCubeFace ); 165 } 166} 167 168void CubemapData::setCubemapFile(FileName newCubemapFile) 169{ 170 mCubeMapFile = newCubemapFile; 171} 172 173void CubemapData::setCubeFaceFile(U32 index, FileName newFaceFile) 174{ 175 if (index >= 6) 176 return; 177 178 mCubeFaceFile[index] = newFaceFile; 179} 180 181void CubemapData::setCubeFaceTexture(U32 index, GFXTexHandle newFaceTexture) 182{ 183 if (index >= 6) 184 return; 185 186 mCubeFace[index] = newFaceTexture; 187} 188 189DefineEngineMethod( CubemapData, updateFaces, void, (),, 190 "Update the assigned cubemaps faces." ) 191{ 192 object->updateFaces(); 193} 194 195DefineEngineMethod( CubemapData, getFilename, const char*, (),, 196 "Returns the script filename of where the CubemapData object was " 197 "defined. This is used by the material editor." ) 198{ 199 return object->getFilename(); 200} 201 202DefineEngineMethod(CubemapData, save, void, (const char* filename, const GFXFormat format), ("", GFXFormatBC1), 203 "Returns the script filename of where the CubemapData object was " 204 "defined. This is used by the material editor.") 205{ 206 if (dStrEqual(filename, "")) 207 filename = object->getName(); 208 209 //add dds extension if needed 210 String finalName = String(filename); 211 if(!finalName.endsWith(".dds") || !finalName.endsWith(".DDS")) 212 finalName += String(".dds"); 213 214 CubemapSaver::save(object->mCubemap, finalName, format); 215} 216