gfxResource.h

Engine/source/gfx/gfxResource.h

More...

Classes:

class

Mixin for the purpose of tracking GFX resources owned by a GFXDevice.

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#ifndef _GFXRESOURCE_H_
 25#define _GFXRESOURCE_H_
 26
 27#ifndef _TORQUE_TYPES_H_
 28#include "platform/types.h"
 29#endif
 30
 31#ifndef _TORQUE_STRING_H_
 32#include "core/util/str.h"
 33#endif
 34
 35class GFXDevice;
 36
 37/// Mixin for the purpose of tracking GFX resources owned by a GFXDevice.
 38///
 39/// There are many types of resource that are allocated from a GFXDevice that
 40/// must be participatory in device resets. For instance, all default pool
 41/// DirectX resources have to be involved when the device resets. Render
 42/// targets in all APIs need to unbind themselves when resets happen.
 43///
 44/// This system is also handy for accounting purposes. For instance, we may
 45/// want to traverse all registered VBs, IBs, Textures, or RTs in order to
 46/// determine what, if any, items are still allocated. This can be used in
 47/// leak reports, memory usage reports, etc.
 48class GFXResource
 49{
 50private:
 51   friend class GFXDevice;
 52
 53   GFXResource *mPrevResource;
 54   GFXResource *mNextResource;
 55   GFXDevice   *mOwningDevice;
 56
 57   /// Helper flag to check new resource allocations
 58   bool mFlagged;
 59
 60public:
 61   GFXResource();
 62   virtual ~GFXResource();
 63
 64   /// Registers this resource with the given device
 65   void registerResourceWithDevice(GFXDevice *device);
 66
 67   /// When called the resource should destroy all device sensitive information (e.g. D3D resources in D3DPOOL_DEFAULT
 68   virtual void zombify()=0;
 69
 70   /// When called the resource should restore all device sensitive information destroyed by zombify()
 71   virtual void resurrect()=0;
 72
 73   /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
 74   virtual const String describeSelf() const = 0;
 75
 76   inline GFXResource *getNextResource() const
 77   {
 78      return mNextResource;
 79   }
 80
 81   inline GFXResource *getPrevResource() const
 82   {
 83      return mPrevResource;
 84   }
 85
 86   inline GFXDevice *getOwningDevice() const
 87   {
 88      return mOwningDevice;
 89   }
 90
 91   inline bool isFlagged()
 92   {
 93      return mFlagged;
 94   }
 95
 96   inline void setFlag()
 97   {
 98      mFlagged = true;
 99   }
100
101   inline void clearFlag()
102   {
103      mFlagged = false;
104   }
105};
106
107#endif
108