2012-09-19 11:15:01 -04:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
# ifndef _GFXGLCUBEMAP_H_
# define _GFXGLCUBEMAP_H_
# ifndef _GFXCUBEMAP_H_
# include "gfx/gfxCubemap.h"
# endif
# ifndef __RESOURCE_H__
# include "core/resource.h"
# endif
2019-04-15 23:11:18 -05:00
const U32 CubeFaces = 6 ;
const U32 MaxMipMaps = 13 ; //todo this needs a proper static value somewhere to sync up with other classes like GBitmap
2012-09-19 11:15:01 -04:00
class GFXGLCubemap : public GFXCubemap
{
public :
GFXGLCubemap ( ) ;
virtual ~ GFXGLCubemap ( ) ;
virtual void initStatic ( GFXTexHandle * faces ) ;
virtual void initStatic ( DDSFile * dds ) ;
2018-09-16 18:19:04 -05:00
virtual void initDynamic ( U32 texSize , GFXFormat faceFormat = GFXFormatR8G8B8A8 , U32 mipLevels = 0 ) ;
2012-09-19 11:15:01 -04:00
virtual U32 getSize ( ) const { return mWidth ; }
virtual GFXFormat getFormat ( ) const { return mFaceFormat ; }
2019-04-26 01:57:07 -05:00
virtual bool isInitialized ( ) { return mCubemap ! = 0 ? true : false ; }
2012-09-19 11:15:01 -04:00
// Convenience methods for GFXGLTextureTarget
U32 getWidth ( ) { return mWidth ; }
U32 getHeight ( ) { return mHeight ; }
U32 getHandle ( ) { return mCubemap ; }
// GFXResource interface
virtual void zombify ( ) ;
virtual void resurrect ( ) ;
/// Called by texCB; this is to ensure that all textures have been resurrected before we attempt to res the cubemap.
void tmResurrect ( ) ;
2019-04-15 23:11:18 -05:00
static GLenum getEnumForFaceNumber ( U32 face ) ; ///< Performs lookup to get a GLenum for the given face number
/// @return An array containing the texture data
/// @note You are responsible for deleting the returned data! (Use delete[])
U8 * getTextureData ( U32 face , U32 mip = 0 ) ;
2012-09-19 11:15:01 -04:00
protected :
friend class GFXDevice ;
friend class GFXGLDevice ;
/// The callback used to get texture events.
/// @see GFXTextureManager::addEventDelegate
void _onTextureEvent ( GFXTexCallbackCode code ) ;
GLuint mCubemap ; ///< Internal GL handle
U32 mDynamicTexSize ; ///< Size of faces for a dynamic texture (used in resurrect)
// Self explanatory
U32 mWidth ;
U32 mHeight ;
GFXFormat mFaceFormat ;
GFXTexHandle mTextures [ 6 ] ; ///< Keep refs to our textures for resurrection of static cubemaps
/// The backing DDSFile uses to restore the faces
/// when the surface is lost.
Resource < DDSFile > mDDSFile ;
// should only be called by GFXDevice
virtual void setToTexUnit ( U32 tuNum ) ; ///< Binds the cubemap to the given texture unit
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)
void fillCubeTextures ( GFXTexHandle * faces ) ; ///< Copies the textures in faces into the cubemap
2019-04-15 23:11:18 -05:00
} ;
class GFXGLCubemapArray : public GFXCubemapArray
{
public :
GFXGLCubemapArray ( ) ;
virtual ~ GFXGLCubemapArray ( ) ;
//virtual void initStatic(GFXCubemapHandle *cubemaps, const U32 cubemapCount);
virtual void init ( GFXCubemapHandle * cubemaps , const U32 cubemapCount ) ;
virtual void init ( const U32 cubemapCount , const U32 cubemapFaceSize , const GFXFormat format ) ;
virtual void updateTexture ( const GFXCubemapHandle & cubemap , const U32 slot ) ;
virtual void copyTo ( GFXCubemapArray * pDstCubemap ) ;
virtual void setToTexUnit ( U32 tuNum ) ;
// GFXResource interface
virtual void zombify ( ) { }
virtual void resurrect ( ) { }
protected :
friend class GFXGLDevice ;
void bind ( U32 textureUnit ) const ;
GLuint mCubemap ; ///< Internal GL handle
2012-09-19 11:15:01 -04:00
} ;
# endif