gfxCubemap.h

Engine/source/gfx/gfxCubemap.h

More...

Classes:

class

Cubemap array - data lives on the GPU only with this class, but the data is not immutable so it can be updated.

class

A reference counted handle to a cubemap array resource.

class

A reference counted handle to a cubemap resource.

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 _GFXCUBEMAP_H_
 25#define _GFXCUBEMAP_H_
 26
 27#ifndef _GFXTEXTUREHANDLE_H_
 28#include "gfx/gfxTextureHandle.h"
 29#endif
 30
 31class GFXDevice;
 32struct DDSFile;
 33
 34///
 35class GFXCubemap : public StrongRefBase, public GFXResource
 36{
 37   friend class GFXDevice;
 38   friend class GFXTextureManager;
 39
 40protected:
 41
 42   // should only be called by GFXDevice
 43   virtual void setToTexUnit( U32 tuNum ) = 0;
 44
 45   /// The path to the cubemap file.
 46   String mPath;
 47
 48   /// Sets the cubemap file path.
 49   void _setPath( const String &path ) { mPath = path; }
 50
 51
 52   U32 mMipMapLevels;
 53
 54   bool mInitialized;
 55public:
 56
 57   /// Create a static cubemap from a list of 6 face textures.
 58   virtual void initStatic( GFXTexHandle *faces ) = 0;
 59
 60   /// Create a static cubemap from a DDS cubemap file.
 61   virtual void initStatic( DDSFile *dds ) = 0;
 62
 63   ///create dynamic cubemap. mipLevels 0 is auto create mips, otherwise the value is how many mip levels you wish the cubemap to have
 64   virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0 ) = 0;
 65
 66   void initNormalize(U32 size);
 67      
 68   GFXCubemap();
 69   virtual ~GFXCubemap();
 70
 71   /// Returns the size of the faces.
 72   virtual U32 getSize() const = 0;
 73
 74   /// Returns the face texture format.
 75   virtual GFXFormat getFormat() const = 0;
 76
 77   /// Returns if this cubemap has been initialized
 78   virtual bool isInitialized() { return false; }
 79
 80   /// Returns the cubemap file path set at creation.
 81   const String& getPath() const { return mPath; }
 82
 83   // GFXResource interface
 84   /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
 85   virtual const String describeSelf() const;
 86
 87   /// Get the number of mip maps
 88   const U32 getMipMapLevels() const { return mMipMapLevels; }
 89
 90   /// Get Z up face index of the cubemap. DDS files will be stored Y up
 91   static U32 zUpFaceIndex(const U32 index);
 92};
 93
 94
 95/// A reference counted handle to a cubemap resource.
 96class GFXCubemapHandle : public StrongRefPtr<GFXCubemap>
 97{
 98public:
 99   GFXCubemapHandle() {}
100   GFXCubemapHandle( GFXCubemap *cubemap ) { StrongRefPtr<GFXCubemap>::set( cubemap ); }
101   GFXCubemapHandle( const String &cubemapDDS ) { set( cubemapDDS ); }
102
103   /// Set a cubemap from a DDS cubemap texture file.
104   bool set( const String &cubemapDDS );
105
106   /// Releases the texture handle.
107   void free() { StrongObjectRef::set( NULL ); }
108};
109
110/// Cubemap array - data lives on the GPU only with this class, but the data is not immutable so it can be updated
111class GFXCubemapArray : public StrongRefBase, public GFXResource
112{
113   friend class GFXDevice;
114   friend class GFXTextureManager;
115
116protected:
117   /// should only be called by GFXDevice
118   virtual void setToTexUnit( U32 tuNum ) = 0;
119   /// number of cubemaps in the array
120   U32 mNumCubemaps;
121   /// cubemap face size
122   U32 mSize;
123   /// number of mip levels
124   U32 mMipMapLevels;
125   /// format
126   GFXFormat mFormat;
127
128public:
129   GFXCubemapArray() :mNumCubemaps(0), mSize(0), mMipMapLevels(0), mFormat(GFXFormat_FIRST) {}
130   virtual ~GFXCubemapArray() {};
131   /// Initialize from an array of cubemaps
132   virtual void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount) = 0;
133   /// Initialize cubemapCount number of blank cubemaps in the array
134   virtual void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format) = 0;
135   /// Update cubemap in the array
136   virtual void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot) = 0;
137   /// Copy this cubemap to another - destination must be same format, same face size & at-least the same size(or larger)
138   virtual void copyTo(GFXCubemapArray *pDstCubemap) = 0;
139   /// Return number of textures in the array
140   const U32 getNumCubemaps() const { return mNumCubemaps; }
141   /// Get the number of mip maps
142   const U32 getMipMapLevels() const { return mMipMapLevels; }
143   /// Returns the size of the faces.
144   const U32 getSize() const { return mSize; }
145   /// Returns the format
146   const GFXFormat getFormat() const { return mFormat; }
147
148   virtual const String describeSelf() const;
149};
150
151/// A reference counted handle to a cubemap array resource.
152class GFXCubemapArrayHandle : public StrongRefPtr<GFXCubemapArray>
153{
154public:
155   GFXCubemapArrayHandle() {}
156   GFXCubemapArrayHandle(GFXCubemapArray *cubemapArray) { StrongRefPtr<GFXCubemapArray>::set(cubemapArray); }
157
158   /// Releases the texture handle.
159   void free() { StrongObjectRef::set(NULL); }
160};
161
162
163
164#endif // GFXCUBEMAP
165