gfxGLCubemap.h

Engine/source/gfx/gl/gfxGLCubemap.h

More...

Classes:

Detailed Description

Public Variables

const U32 CubeFaces 
const U32 MaxMipMaps 
  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 _GFXGLCUBEMAP_H_
 25#define _GFXGLCUBEMAP_H_
 26
 27#ifndef _GFXCUBEMAP_H_
 28#include "gfx/gfxCubemap.h"
 29#endif
 30#ifndef __RESOURCE_H__
 31#include "core/resource.h"
 32#endif
 33
 34const U32 CubeFaces = 6;
 35const U32 MaxMipMaps = 13; //todo this needs a proper static value somewhere to sync up with other classes like GBitmap
 36
 37
 38class GFXGLCubemap : public GFXCubemap
 39{
 40public:
 41   GFXGLCubemap();
 42   virtual ~GFXGLCubemap();
 43
 44   virtual void initStatic( GFXTexHandle *faces );
 45   virtual void initStatic( DDSFile *dds );
 46   virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8, U32 mipLevels = 0);
 47   virtual U32 getSize() const { return mWidth; }
 48   virtual GFXFormat getFormat() const { return mFaceFormat; }
 49
 50   virtual bool isInitialized() { return mCubemap != 0 ? true : false; }
 51
 52   // Convenience methods for GFXGLTextureTarget
 53   U32 getWidth() { return mWidth; }
 54   U32 getHeight() { return mHeight; }
 55   U32 getHandle() { return mCubemap; }
 56   
 57   // GFXResource interface
 58   virtual void zombify();
 59   virtual void resurrect();
 60   
 61   /// Called by texCB; this is to ensure that all textures have been resurrected before we attempt to res the cubemap.
 62   void tmResurrect();
 63   
 64   static GLenum getEnumForFaceNumber(U32 face);///< Performs lookup to get a GLenum for the given face number
 65
 66   /// @return An array containing the texture data
 67   /// @note You are responsible for deleting the returned data! (Use delete[])
 68   U8* getTextureData(U32 face, U32 mip = 0);
 69
 70protected:
 71
 72   friend class GFXDevice;
 73   friend class GFXGLDevice;
 74
 75   /// The callback used to get texture events.
 76   /// @see GFXTextureManager::addEventDelegate
 77   void _onTextureEvent( GFXTexCallbackCode code );
 78   
 79   GLuint mCubemap; ///< Internal GL handle
 80   U32 mDynamicTexSize; ///< Size of faces for a dynamic texture (used in resurrect)
 81   
 82   // Self explanatory
 83   U32 mWidth;
 84   U32 mHeight;
 85   GFXFormat mFaceFormat;
 86      
 87   GFXTexHandle mTextures[6]; ///< Keep refs to our textures for resurrection of static cubemaps
 88   
 89   /// The backing DDSFile uses to restore the faces
 90   /// when the surface is lost.
 91   Resource<DDSFile> mDDSFile;
 92
 93   // should only be called by GFXDevice
 94   virtual void setToTexUnit( U32 tuNum ); ///< Binds the cubemap to the given texture unit
 95   virtual void bind(U32 textureUnit) const; ///< Notifies our owning device that we want to be set to the given texture unit (used for GL internal state tracking)
 96   void fillCubeTextures(GFXTexHandle* faces); ///< Copies the textures in faces into the cubemap
 97   
 98};
 99
100class GFXGLCubemapArray : public GFXCubemapArray
101{
102public:
103   GFXGLCubemapArray();
104   virtual ~GFXGLCubemapArray();
105   //virtual void initStatic(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
106   virtual void init(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
107   virtual void init(const U32 cubemapCount, const U32 cubemapFaceSize, const GFXFormat format);
108   virtual void updateTexture(const GFXCubemapHandle &cubemap, const U32 slot);
109   virtual void copyTo(GFXCubemapArray *pDstCubemap);
110   virtual void setToTexUnit(U32 tuNum);
111
112   // GFXResource interface
113   virtual void zombify() {}
114   virtual void resurrect() {}
115
116protected:
117   friend class GFXGLDevice;
118   void bind(U32 textureUnit) const;
119   GLuint mCubemap; ///< Internal GL handle
120
121};
122
123#endif
124