gfxPrimitiveBuffer.cpp 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "core/strings/stringFunctions.h"
  23. #include "console/console.h"
  24. #include "gfx/gfxDevice.h"
  25. #include "gfx/gfxPrimitiveBuffer.h"
  26. //-----------------------------------------------------------------------------
  27. #ifdef TORQUE_DEBUG
  28. GFXPrimitiveBuffer *GFXPrimitiveBuffer::smHead = NULL;
  29. U32 GFXPrimitiveBuffer::smActivePBCount = 0;
  30. void GFXPrimitiveBuffer::dumpActivePBs()
  31. {
  32. if(!smActivePBCount)
  33. {
  34. Con::printf("GFXPrimitiveBuffer::dumpActivePBs - no currently active PBs to dump. You are A-OK!");
  35. return;
  36. }
  37. Con::printf("GFXPrimitiveBuffer Usage Report - %d active PBs", smActivePBCount);
  38. Con::printf("---------------------------------------------------------------");
  39. Con::printf(" Addr #idx #prims Profiler Path RefCount");
  40. for(GFXPrimitiveBuffer *walk = smHead; walk; walk=walk->mDebugNext)
  41. {
  42. #if defined(TORQUE_ENABLE_PROFILER)
  43. Con::printf(" %x %6d %6d %s %d", walk, walk->mIndexCount, walk->mPrimitiveCount, walk->mDebugCreationPath.c_str(), walk->getRefCount());
  44. #else
  45. Con::printf(" %x %6d %6d %s %d", walk, walk->mIndexCount, walk->mPrimitiveCount, "", walk->getRefCount());
  46. #endif
  47. }
  48. Con::printf("----- dump complete -------------------------------------------");
  49. AssertFatal(false, "There is a primitive buffer leak, check the log for more details.");
  50. }
  51. #endif
  52. /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
  53. const String GFXPrimitiveBuffer::describeSelf() const
  54. {
  55. #if defined(TORQUE_DEBUG) && defined(TORQUE_ENABLE_PROFILER)
  56. return String::ToString("indexCount: %6d primCount: %6d refCount: %d path: %s",
  57. mIndexCount, mPrimitiveCount, getRefCount(), mDebugCreationPath.c_str());
  58. #else
  59. return String::ToString("indexCount: %6d primCount: %6d refCount: %d path: %s",
  60. mIndexCount, mPrimitiveCount, getRefCount(), "");
  61. #endif
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Set
  65. //-----------------------------------------------------------------------------
  66. void GFXPrimitiveBufferHandle::set(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType, String desc)
  67. {
  68. StrongRefPtr<GFXPrimitiveBuffer>::operator=( theDevice->allocPrimitiveBuffer(indexCount, primitiveCount, bufferType) );
  69. #ifdef TORQUE_DEBUG
  70. if( desc.isNotEmpty() )
  71. getPointer()->mDebugCreationPath = desc;
  72. #endif
  73. }
  74. //-----------------------------------------------------------------------------
  75. // immutable
  76. //-----------------------------------------------------------------------------
  77. void GFXPrimitiveBufferHandle::immutable(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, void* data, String desc)
  78. {
  79. StrongRefPtr<GFXPrimitiveBuffer>::operator=( theDevice->allocPrimitiveBuffer(indexCount, primitiveCount, GFXBufferTypeImmutable, data) );
  80. #ifdef TORQUE_DEBUG
  81. if( desc.isNotEmpty() )
  82. getPointer()->mDebugCreationPath = desc;
  83. #endif
  84. }