gfxPrimitiveBuffer.cpp
Engine/source/gfx/gfxPrimitiveBuffer.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 "core/strings/stringFunctions.h" 25#include "console/console.h" 26 27#include "gfx/gfxDevice.h" 28#include "gfx/gfxPrimitiveBuffer.h" 29 30//----------------------------------------------------------------------------- 31#ifdef TORQUE_DEBUG 32GFXPrimitiveBuffer *GFXPrimitiveBuffer::smHead = NULL; 33U32 GFXPrimitiveBuffer::smActivePBCount = 0; 34 35void GFXPrimitiveBuffer::dumpActivePBs() 36{ 37 if(!smActivePBCount) 38 { 39 Con::printf("GFXPrimitiveBuffer::dumpActivePBs - no currently active PBs to dump. You are A-OK!"); 40 return; 41 } 42 43 Con::printf("GFXPrimitiveBuffer Usage Report - %d active PBs", smActivePBCount); 44 Con::printf("---------------------------------------------------------------"); 45 Con::printf(" Addr #idx #prims Profiler Path RefCount"); 46 for(GFXPrimitiveBuffer *walk = smHead; walk; walk=walk->mDebugNext) 47 { 48#if defined(TORQUE_ENABLE_PROFILER) 49 Con::printf(" %x %6d %6d %s %d", walk, walk->mIndexCount, walk->mPrimitiveCount, walk->mDebugCreationPath.c_str(), walk->getRefCount()); 50#else 51 Con::printf(" %x %6d %6d %s %d", walk, walk->mIndexCount, walk->mPrimitiveCount, "", walk->getRefCount()); 52#endif 53 } 54 Con::printf("----- dump complete -------------------------------------------"); 55 AssertFatal(false, "There is a primitive buffer leak, check the log for more details."); 56} 57 58#endif 59 60/// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer 61const String GFXPrimitiveBuffer::describeSelf() const 62{ 63#if defined(TORQUE_DEBUG) && defined(TORQUE_ENABLE_PROFILER) 64 return String::ToString("indexCount: %6d primCount: %6d refCount: %d path: %s", 65 mIndexCount, mPrimitiveCount, getRefCount(), mDebugCreationPath.c_str()); 66#else 67 return String::ToString("indexCount: %6d primCount: %6d refCount: %d path: %s", 68 mIndexCount, mPrimitiveCount, getRefCount(), ""); 69#endif 70} 71 72//----------------------------------------------------------------------------- 73// Set 74//----------------------------------------------------------------------------- 75void GFXPrimitiveBufferHandle::set(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType, String desc) 76{ 77 StrongRefPtr<GFXPrimitiveBuffer>::operator=( theDevice->allocPrimitiveBuffer(indexCount, primitiveCount, bufferType) ); 78 79#ifdef TORQUE_DEBUG 80 if( desc.isNotEmpty() ) 81 getPointer()->mDebugCreationPath = desc; 82#endif 83} 84 85//----------------------------------------------------------------------------- 86// immutable 87//----------------------------------------------------------------------------- 88void GFXPrimitiveBufferHandle::immutable(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, void* data, String desc) 89{ 90 StrongRefPtr<GFXPrimitiveBuffer>::operator=( theDevice->allocPrimitiveBuffer(indexCount, primitiveCount, GFXBufferTypeImmutable, data) ); 91 92#ifdef TORQUE_DEBUG 93 if( desc.isNotEmpty() ) 94 getPointer()->mDebugCreationPath = desc; 95#endif 96} 97