2008-05-22 04:51:37 -07:00
// Copyright (C) 2002-2008 Nikolaus Gebhardt
2007-05-20 11:03:49 -07:00
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
# ifndef __C_OPEN_GL_TEXTURE_H_INCLUDED__
# define __C_OPEN_GL_TEXTURE_H_INCLUDED__
# include "ITexture.h"
# include "IImage.h"
# include "IrrCompileConfig.h"
# ifdef _IRR_COMPILE_WITH_OPENGL_
# ifdef _IRR_WINDOWS_API_
// include windows headers for HWND
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <GL/gl.h>
# include "glext.h"
# ifdef _MSC_VER
# pragma comment(lib, "OpenGL32.lib")
# pragma comment(lib, "GLu32.lib")
# endif
# else
# if defined(_IRR_OPENGL_USE_EXTPOINTER_)
# define GL_GLEXT_LEGACY 1
# endif
2008-01-04 03:10:37 -08:00
# if defined(_IRR_USE_OSX_DEVICE_)
2007-08-28 06:39:23 -07:00
# include <OpenGL/gl.h>
# else
# include <GL/gl.h>
# endif
2007-05-20 11:03:49 -07:00
# if defined(_IRR_OPENGL_USE_EXTPOINTER_)
# include "glext.h"
# endif
# endif
namespace irr
{
namespace video
{
class COpenGLDriver ;
//! OpenGL texture.
class COpenGLTexture : public ITexture
{
public :
//! constructor
COpenGLTexture ( IImage * surface , const char * name , COpenGLDriver * driver = 0 ) ;
//! FrameBufferObject constructor
2008-06-27 08:38:48 -07:00
COpenGLTexture ( const core : : dimension2d < s32 > & size , const char * name , COpenGLDriver * driver = 0 , bool useStencil = false ) ;
2007-05-20 11:03:49 -07:00
//! destructor
virtual ~ COpenGLTexture ( ) ;
//! lock function
virtual void * lock ( ) ;
//! unlock function
virtual void unlock ( ) ;
2007-12-05 16:00:23 -08:00
//! Returns original size of the texture (image).
2007-09-15 17:18:13 -07:00
virtual const core : : dimension2d < s32 > & getOriginalSize ( ) const ;
2007-05-20 11:03:49 -07:00
//! Returns size of the texture.
2007-09-15 17:18:13 -07:00
virtual const core : : dimension2d < s32 > & getSize ( ) const ;
2007-05-20 11:03:49 -07:00
2007-12-05 16:00:23 -08:00
//! returns driver type of texture (=the driver, that created it)
2007-09-15 17:18:13 -07:00
virtual E_DRIVER_TYPE getDriverType ( ) const ;
2007-05-20 11:03:49 -07:00
//! returns color format of texture
virtual ECOLOR_FORMAT getColorFormat ( ) const ;
//! returns pitch of texture (in bytes)
virtual u32 getPitch ( ) const ;
//! return open gl texture name
2007-09-15 17:18:13 -07:00
GLuint getOpenGLTextureName ( ) const ;
2007-05-20 11:03:49 -07:00
//! return whether this texture has mipmaps
2007-05-22 00:20:16 -07:00
virtual bool hasMipMaps ( ) const ;
2007-05-20 11:03:49 -07:00
//! Regenerates the mip map levels of the texture. Useful after
//! locking and modifying the texture
virtual void regenerateMipMapLevels ( ) ;
2007-09-19 05:52:35 -07:00
//! Is it a render target?
virtual bool isRenderTarget ( ) const ;
2007-05-20 11:03:49 -07:00
//! Is it a FrameBufferObject?
2007-09-15 17:18:13 -07:00
bool isFrameBufferObject ( ) const ;
2007-05-20 11:03:49 -07:00
//! Bind FrameBufferObject (valid only if isFrameBufferObject() returns true).
void bindFrameBufferObject ( ) ;
//! Unbind FrameBufferObject (valid only if isFrameBufferObject() returns true).
void unbindFrameBufferObject ( ) ;
2007-09-19 05:52:35 -07:00
//! sets whether this texture is intended to be used as a render target.
2008-08-03 05:28:21 -07:00
void setIsRenderTarget ( bool isTarget ) ;
2007-09-19 05:52:35 -07:00
2007-05-20 11:03:49 -07:00
private :
2007-07-17 16:47:10 -07:00
//! get the desired color format based on texture creation flags and the input format.
ECOLOR_FORMAT getBestColorFormat ( ECOLOR_FORMAT format ) ;
//! convert the image into an internal image with better properties for this driver.
2007-05-20 11:03:49 -07:00
void getImageData ( IImage * image ) ;
//! copies the the texture into an open gl texture.
//! \param: newTexture is true if method is called from a newly created texture for the first time. Otherwise call with false to improve memory handling.
void copyTexture ( bool newTexture = true ) ;
2007-12-05 16:00:23 -08:00
//! returns the size of a texture which would be optimal for rendering
2007-09-15 17:18:13 -07:00
inline s32 getTextureSizeFromSurfaceSize ( s32 size ) const ;
2007-05-20 11:03:49 -07:00
core : : dimension2d < s32 > ImageSize ;
COpenGLDriver * Driver ;
IImage * Image ;
GLuint TextureName ;
GLint InternalFormat ;
GLenum PixelFormat ;
GLenum PixelType ;
GLuint ColorFrameBuffer ; // for FBO path
GLuint DepthRenderBuffer ; // for FBO path
GLuint StencilRenderBuffer ; // for FBO path
2008-06-27 08:38:48 -07:00
bool HasMipMaps ;
bool IsRenderTarget ;
bool AutomaticMipmapUpdate ;
bool UseStencil ;
2007-05-20 11:03:49 -07:00
} ;
} // end namespace video
} // end namespace irr
# endif
# endif // _IRR_COMPILE_WITH_OPENGL_