gfxTextureHandle.cpp
Engine/source/gfx/gfxTextureHandle.cpp
Detailed Description
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/gfxTextureHandle.h" 26 27#include "gfx/gfxDevice.h" 28#include "gfx/gfxTextureManager.h" 29 30 31GFXTexHandle GFXTexHandle::ZERO; 32GFXTexHandle GFXTexHandle::ONE; 33GFXTexHandle GFXTexHandle::ZUP; 34 35 36GFXTexHandle::GFXTexHandle( GFXTextureObject *obj ) 37{ 38 StrongObjectRef::set( obj ); 39} 40 41GFXTexHandle::GFXTexHandle( const GFXTexHandle &handle, const String &desc ) 42{ 43 StrongObjectRef::set( handle.getPointer() ); 44 45 #ifdef TORQUE_DEBUG 46 if ( getPointer() ) 47 getPointer()->mDebugDescription = desc; 48 #endif 49} 50 51GFXTexHandle::GFXTexHandle( const String &texName, GFXTextureProfile *profile, const String &desc ) 52{ 53 set( texName, profile, desc ); 54} 55 56GFXTexHandle::GFXTexHandle(const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc) 57{ 58 set(texNameR, texNameG, texNameB, texNameA, inputKey, profile, desc); 59} 60 61bool GFXTexHandle::set( const String &texName, GFXTextureProfile *profile, const String &desc ) 62{ 63 // Clear the existing texture first, so that 64 // its memory is free for the new allocation. 65 free(); 66 67 // Create and set the new texture. 68 AssertFatal( texName.isNotEmpty(), "Texture name is empty" ); 69 StrongObjectRef::set( TEXMGR->createTexture( texName, profile ) ); 70 71 #ifdef TORQUE_DEBUG 72 if ( getPointer() ) 73 getPointer()->mDebugDescription = desc; 74 #endif 75 76 return isValid(); 77} 78 79bool GFXTexHandle::set(const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc) 80{ 81 // Clear the existing texture first, so that 82 // its memory is free for the new allocation. 83 free(); 84 85 // Create and set the new texture. 86 AssertFatal( texNameR.isNotEmpty(), "Texture name is empty" ); 87 StrongObjectRef::set( TEXMGR->createCompositeTexture( texNameR, texNameG, texNameB, texNameA, inputKey, profile ) ); 88 89 #ifdef TORQUE_DEBUG 90 if ( getPointer() ) 91 getPointer()->mDebugDescription = desc; 92 #endif 93 94 return isValid(); 95} 96 97GFXTexHandle::GFXTexHandle( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc ) 98{ 99 set( bmp, profile, deleteBmp, desc ); 100} 101 102bool GFXTexHandle::set( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc ) 103{ 104 // Clear the existing texture first, so that 105 // its memory is free for the new allocation. 106 free(); 107 108 // Create and set the new texture. 109 AssertFatal( bmp, "Bitmap is NULL" ); 110 StrongObjectRef::set( TEXMGR->createTexture( bmp, String(), profile, deleteBmp ) ); 111 112 #ifdef TORQUE_DEBUG 113 if ( getPointer() ) 114 getPointer()->mDebugDescription = desc; 115 #endif 116 117 return isValid(); 118} 119 120GFXTexHandle::GFXTexHandle( DDSFile *dds, GFXTextureProfile *profile, bool deleteDDS, const String &desc ) 121{ 122 set( dds, profile, deleteDDS, desc ); 123} 124 125bool GFXTexHandle::set( DDSFile *dds, GFXTextureProfile *profile, bool deleteDDS, const String &desc ) 126{ 127 // Clear the existing texture first, so that 128 // its memory is free for the new allocation. 129 free(); 130 131 // Create and set the new texture. 132 AssertFatal( dds, "Bitmap is NULL" ); 133 StrongObjectRef::set( TEXMGR->createTexture( dds, profile, deleteDDS ) ); 134 135 #ifdef TORQUE_DEBUG 136 if ( getPointer() ) 137 getPointer()->mDebugDescription = desc; 138 #endif 139 140 return isValid(); 141} 142 143GFXTexHandle::GFXTexHandle( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels, S32 antialiasLevel) 144{ 145 set( width, height, format, profile, desc, numMipLevels, antialiasLevel ); 146} 147 148bool GFXTexHandle::set( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels, S32 antialiasLevel) 149{ 150 // Clear the existing texture first, so that 151 // its memory is free for the new allocation. 152 free(); 153 154 // Create and set the new texture. 155 StrongObjectRef::set( TEXMGR->createTexture( width, height, format, profile, numMipLevels, antialiasLevel ) ); 156 157 #ifdef TORQUE_DEBUG 158 if ( getPointer() ) 159 getPointer()->mDebugDescription = desc; 160 #endif 161 162 return isValid(); 163} 164 165bool GFXTexHandle::set(U32 width, U32 height, U32 depth, GFXFormat format, GFXTextureProfile* profile, const String& desc, U32 numMipLevels) 166{ 167 // Clear the existing texture first, so that 168 // its memory is free for the new allocation. 169 free(); 170 171 // Create and set the new texture. 172 StrongObjectRef::set(TEXMGR->createTexture(width, height, depth, format, profile, numMipLevels)); 173 174 #ifdef TORQUE_DEBUG 175 if ( getPointer() ) 176 getPointer()->mDebugDescription = desc; 177 #endif 178 179 return isValid(); 180} 181 182void GFXTexHandle::refresh() 183{ 184 TEXMGR->reloadTexture( getPointer() ); 185} 186