gfxNullDevice.cpp
Engine/source/gfx/Null/gfxNullDevice.cpp
Classes:
class
class
class
class
class
class
class
Public Variables
Detailed Description
Public Variables
GFXNullRegisterDevice pNullRegisterDevice
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/Null/gfxNullDevice.h" 26 27#include "core/strings/stringFunctions.h" 28#include "gfx/gfxCubemap.h" 29#include "gfx/screenshot.h" 30#include "gfx/gfxPrimitiveBuffer.h" 31#include "gfx/gfxCardProfile.h" 32#include "gfx/gfxTextureManager.h" 33#include "gfx/bitmap/gBitmap.h" 34#include "core/util/safeDelete.h" 35 36 37GFXAdapter::CreateDeviceInstanceDelegate GFXNullDevice::mCreateDeviceInstance(GFXNullDevice::createInstance); 38 39class GFXNullCardProfiler: public GFXCardProfiler 40{ 41private: 42 typedef GFXCardProfiler Parent; 43public: 44 45 /// 46 virtual const String &getRendererString() const { static String sRS("GFX Null Device Renderer"); return sRS; } 47 48protected: 49 50 virtual void setupCardCapabilities() { }; 51 52 virtual bool _queryCardCap(const String &query, U32 &foundResult){ return false; } 53 virtual bool _queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips) { inOutAutogenMips = false; return false; } 54 55public: 56 virtual void init() 57 { 58 mCardDescription = "GFX Null Device Card"; 59 mChipSet = "NULL Device"; 60 mVersionString = "0"; 61 62 Parent::init(); // other code notes that not calling this is "BAD". 63 }; 64}; 65 66class GFXNullTextureObject : public GFXTextureObject 67{ 68public: 69 GFXNullTextureObject(GFXDevice * aDevice, GFXTextureProfile *profile); 70 ~GFXNullTextureObject() { kill(); }; 71 72 virtual void pureVirtualCrash() { }; 73 74 virtual GFXLockedRect * lock( U32 mipLevel = 0, RectI *inRect = NULL ) { return NULL; }; 75 virtual void unlock( U32 mipLevel = 0) {}; 76 virtual bool copyToBmp(GBitmap *) { return false; }; 77 78 virtual void zombify() {} 79 virtual void resurrect() {} 80}; 81 82GFXNullTextureObject::GFXNullTextureObject(GFXDevice * aDevice, GFXTextureProfile *profile) : 83 GFXTextureObject(aDevice, profile) 84{ 85 mProfile = profile; 86 mTextureSize.set( 0, 0, 0 ); 87} 88 89class GFXNullTextureManager : public GFXTextureManager 90{ 91protected: 92 virtual GFXTextureObject *_createTextureObject( U32 height, 93 U32 width, 94 U32 depth, 95 GFXFormat format, 96 GFXTextureProfile *profile, 97 U32 numMipLevels, 98 bool forceMips = false, 99 S32 antialiasLevel = 0, 100 GFXTextureObject *inTex = NULL ) 101 { 102 GFXNullTextureObject *retTex; 103 if ( inTex ) 104 { 105 AssertFatal( dynamic_cast<GFXNullTextureObject*>( inTex ), "GFXNullTextureManager::_createTexture() - Bad inTex type!" ); 106 retTex = static_cast<GFXNullTextureObject*>( inTex ); 107 } 108 else 109 { 110 retTex = new GFXNullTextureObject( GFX, profile ); 111 retTex->registerResourceWithDevice( GFX ); 112 } 113 114 SAFE_DELETE( retTex->mBitmap ); 115 retTex->mBitmap = new GBitmap(width, height); 116 return retTex; 117 }; 118 119 /// Load a texture from a proper DDSFile instance. 120 virtual bool _loadTexture(GFXTextureObject *texture, DDSFile *dds){ return true; }; 121 122 /// Load data into a texture from a GBitmap using the internal API. 123 virtual bool _loadTexture(GFXTextureObject *texture, GBitmap *bmp){ return true; }; 124 125 /// Load data into a texture from a raw buffer using the internal API. 126 /// 127 /// Note that the size of the buffer is assumed from the parameters used 128 /// for this GFXTextureObject's _createTexture call. 129 virtual bool _loadTexture(GFXTextureObject *texture, void *raw){ return true; }; 130 131 /// Refresh a texture using the internal API. 132 virtual bool _refreshTexture(GFXTextureObject *texture){ return true; }; 133 134 /// Free a texture (but do not delete the GFXTextureObject) using the internal 135 /// API. 136 /// 137 /// This is only called during zombification for textures which need it, so you 138 /// don't need to do any internal safety checks. 139 virtual bool _freeTexture(GFXTextureObject *texture, bool zombify=false) { return true; }; 140 141 virtual U32 _getTotalVideoMemory() { return 0; }; 142 virtual U32 _getFreeVideoMemory() { return 0; }; 143}; 144 145class GFXNullCubemap : public GFXCubemap 146{ 147 friend class GFXDevice; 148private: 149 // should only be called by GFXDevice 150 virtual void setToTexUnit( U32 tuNum ) { }; 151 152public: 153 virtual void initStatic( GFXTexHandle *faces ) { }; 154 virtual void initStatic( DDSFile *dds ) { }; 155 virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0) { }; 156 virtual U32 getSize() const { return 0; } 157 virtual GFXFormat getFormat() const { return GFXFormatR8G8B8A8; } 158 159 virtual ~GFXNullCubemap(){}; 160 161 virtual void zombify() {} 162 virtual void resurrect() {} 163}; 164 165class GFXNullCubemapArray : public GFXCubemapArray 166{ 167 friend class GFXDevice; 168private: 169 // should only be called by GFXDevice 170 virtual void setToTexUnit(U32 tuNum) { }; 171 172public: 173 virtual void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount) { }; 174 virtual void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format) { }; 175 virtual void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot) { }; 176 virtual void copyTo(GFXCubemapArray *pDstCubemap) { } 177 virtual ~GFXNullCubemapArray() {}; 178 virtual void zombify() {} 179 virtual void resurrect() {} 180}; 181 182class GFXNullTextureArray : public GFXTextureArray 183{ 184public: 185 void zombify() override {} 186 void resurrect() override {} 187 void Release() override {} 188 void setToTexUnit(U32 tuNum) override { } 189 void init() override { } 190 191protected: 192 void _setTexture(const GFXTexHandle& texture, U32 slot) override { } 193}; 194 195class GFXNullVertexBuffer : public GFXVertexBuffer 196{ 197 unsigned char* tempBuf; 198public: 199 GFXNullVertexBuffer( GFXDevice *device, 200 U32 numVerts, 201 const GFXVertexFormat *vertexFormat, 202 U32 vertexSize, 203 GFXBufferType bufferType ) : 204 GFXVertexBuffer(device, numVerts, vertexFormat, vertexSize, bufferType) {tempBuf =<a href="/coding/file/types_8lint_8h/#types_8lint_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;}; 205 virtual void lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr); 206 virtual void unlock(); 207 virtual void prepare(); 208 209 virtual void zombify() {} 210 virtual void resurrect() {} 211}; 212 213void GFXNullVertexBuffer::lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr) 214{ 215 tempBuf = new unsigned char[(vertexEnd - vertexStart) * mVertexSize]; 216 *vertexPtr = (void*) tempBuf; 217 lockedVertexStart = vertexStart; 218 lockedVertexEnd = vertexEnd; 219} 220 221void GFXNullVertexBuffer::unlock() 222{ 223 delete[] tempBuf; 224 tempBuf = NULL; 225} 226 227void GFXNullVertexBuffer::prepare() 228{ 229} 230 231class GFXNullPrimitiveBuffer : public GFXPrimitiveBuffer 232{ 233private: 234 U16* temp; 235public: 236 GFXNullPrimitiveBuffer( GFXDevice *device, 237 U32 indexCount, 238 U32 primitiveCount, 239 GFXBufferType bufferType ) : 240 GFXPrimitiveBuffer(device, indexCount, primitiveCount, bufferType), temp( NULL ) {}; 241 242 virtual void lock(U32 indexStart, U32 indexEnd, void **indexPtr); ///< locks this primitive buffer for writing into 243 virtual void unlock(); ///< unlocks this primitive buffer. 244 virtual void prepare() { }; ///< prepares this primitive buffer for use on the device it was allocated on 245 246 virtual void zombify() {} 247 virtual void resurrect() {} 248}; 249 250void GFXNullPrimitiveBuffer::lock(U32 indexStart, U32 indexEnd, void **indexPtr) 251{ 252 temp = new U16[indexEnd - indexStart]; 253 *indexPtr = temp; 254} 255 256void GFXNullPrimitiveBuffer::unlock() 257{ 258 delete[] temp; 259 temp = NULL; 260} 261 262// 263// GFXNullStateBlock 264// 265class GFXNullStateBlock : public GFXStateBlock 266{ 267public: 268 /// Returns the hash value of the desc that created this block 269 virtual U32 getHashValue() const { return 0; }; 270 271 /// Returns a GFXStateBlockDesc that this block represents 272 virtual const GFXStateBlockDesc& getDesc() const { return mDefaultDesc; } 273 274 // 275 // GFXResource 276 // 277 virtual void zombify() { } 278 /// When called the resource should restore all device sensitive information destroyed by zombify() 279 virtual void resurrect() { } 280private: 281 GFXStateBlockDesc mDefaultDesc; 282}; 283 284// 285// GFXNullDevice 286// 287 288GFXDevice *GFXNullDevice::createInstance( U32 adapterIndex ) 289{ 290 return new GFXNullDevice(); 291} 292 293GFXNullDevice::GFXNullDevice() 294{ 295 clip.set(0, 0, 800, 800); 296 297 mTextureManager = new GFXNullTextureManager(); 298 gScreenShot = new ScreenShot(); 299 mCardProfiler = new GFXNullCardProfiler(); 300 mCardProfiler->init(); 301} 302 303GFXNullDevice::~GFXNullDevice() 304{ 305} 306 307GFXVertexBuffer *GFXNullDevice::allocVertexBuffer( U32 numVerts, 308 const GFXVertexFormat *vertexFormat, 309 U32 vertSize, 310 GFXBufferType bufferType, 311 void* data ) 312{ 313 return new GFXNullVertexBuffer(GFX, numVerts, vertexFormat, vertSize, bufferType); 314} 315 316GFXPrimitiveBuffer *GFXNullDevice::allocPrimitiveBuffer( U32 numIndices, 317 U32 numPrimitives, 318 GFXBufferType bufferType, 319 void* data ) 320{ 321 return new GFXNullPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType); 322} 323 324GFXCubemap* GFXNullDevice::createCubemap() 325{ 326 return new GFXNullCubemap(); 327}; 328 329GFXCubemapArray* GFXNullDevice::createCubemapArray() 330{ 331 return new GFXNullCubemapArray(); 332}; 333 334GFXTextureArray* GFXNullDevice::createTextureArray() 335{ 336 return new GFXNullTextureArray(); 337}; 338 339void GFXNullDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList ) 340{ 341 // Add the NULL renderer 342 GFXAdapter *toAdd = new GFXAdapter(); 343 344 toAdd->mIndex = 0; 345 toAdd->mType = NullDevice; 346 toAdd->mCreateDeviceInstanceDelegate = mCreateDeviceInstance; 347 348 GFXVideoMode vm; 349 vm.bitDepth = 32; 350 vm.resolution.set(800,600); 351 toAdd->mAvailableModes.push_back(vm); 352 353 dStrcpy(toAdd->mName, "GFX Null Device", GFXAdapter::MaxAdapterNameLen); 354 355 adapterList.push_back(toAdd); 356} 357 358void GFXNullDevice::init( const GFXVideoMode &mode, PlatformWindow *window ) 359{ 360 mCardProfiler = new GFXNullCardProfiler(); 361 mCardProfiler->init(); 362} 363 364GFXStateBlockRef GFXNullDevice::createStateBlockInternal(const GFXStateBlockDesc& desc) 365{ 366 return new GFXNullStateBlock(); 367} 368 369// 370// Register this device with GFXInit 371// 372class GFXNullRegisterDevice 373{ 374public: 375 GFXNullRegisterDevice() 376 { 377 GFXInit::getRegisterDeviceSignal().notify(&GFXNullDevice::enumerateAdapters); 378 } 379}; 380 381static GFXNullRegisterDevice pNullRegisterDevice; 382