gfxGLCubemap.h

Engine/source/gfx/gl/gfxGLCubemap.h

More...

Classes:

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 _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
34
35class GFXGLCubemap : public GFXCubemap
36{
37public:
38   GFXGLCubemap();
39   virtual ~GFXGLCubemap();
40
41   virtual void initStatic( GFXTexHandle *faces );
42   virtual void initStatic( DDSFile *dds );
43   virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8 );
44   virtual U32 getSize() const { return mWidth; }
45   virtual GFXFormat getFormat() const { return mFaceFormat; }
46
47   // Convenience methods for GFXGLTextureTarget
48   U32 getWidth() { return mWidth; }
49   U32 getHeight() { return mHeight; }
50   U32 getNumMipLevels() { return mMipLevels; }
51   U32 getHandle() { return mCubemap; }
52   
53   // GFXResource interface
54   virtual void zombify();
55   virtual void resurrect();
56   
57   /// Called by texCB; this is to ensure that all textures have been resurrected before we attempt to res the cubemap.
58   void tmResurrect();
59   
60   static GLenum getEnumForFaceNumber(U32 face) { return faceList[face]; } ///< Performs lookup to get a GLenum for the given face number
61
62protected:
63
64   friend class GFXDevice;
65   friend class GFXGLDevice;
66
67   /// The callback used to get texture events.
68   /// @see GFXTextureManager::addEventDelegate
69   void _onTextureEvent( GFXTexCallbackCode code );
70   
71   GLuint mCubemap; ///< Internal GL handle
72   U32 mDynamicTexSize; ///< Size of faces for a dynamic texture (used in resurrect)
73   
74   // Self explanatory
75   U32 mWidth;
76   U32 mHeight;
77   U32 mMipLevels;
78   GFXFormat mFaceFormat;
79      
80   GFXTexHandle mTextures[6]; ///< Keep refs to our textures for resurrection of static cubemaps
81   
82   /// The backing DDSFile uses to restore the faces
83   /// when the surface is lost.
84   Resource<DDSFile> mDDSFile;
85
86   // should only be called by GFXDevice
87   virtual void setToTexUnit( U32 tuNum ); ///< Binds the cubemap to the given texture unit
88   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)
89   void fillCubeTextures(GFXTexHandle* faces); ///< Copies the textures in faces into the cubemap
90   
91   static GLenum faceList[6]; ///< Lookup table
92};
93
94#endif
95