#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_
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
#define GL_GLEXT_LEGACY 1
#else
#define GL_GLEXT_PROTOTYPES 1
#endif
#ifdef _IRR_WINDOWS_API_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <GL/gl.h>
#ifdef _MSC_VER
#pragma comment(lib, "OpenGL32.lib")
#endif
#elif defined(_IRR_OSX_PLATFORM_)
#include <OpenGL/gl.h>
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
#define NO_SDL_GLEXT
#include <SDL/SDL_video.h>
#include <SDL/SDL_opengl.h>
#else
#if defined(_IRR_OSX_PLATFORM_)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#endif
namespace irr
{
namespace video
{
class COpenGLDriver;
class COpenGLTexture : public ITexture
{
public:
COpenGLTexture(IImage* surface, const io::path& name, void* mipmapData=0, COpenGLDriver* driver=0);
virtual ~COpenGLTexture();
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0);
virtual void unlock();
virtual const core::dimension2d<u32>& getOriginalSize() const;
virtual const core::dimension2d<u32>& getSize() const;
virtual E_DRIVER_TYPE getDriverType() const;
virtual ECOLOR_FORMAT getColorFormat() const;
virtual u32 getPitch() const;
GLuint getOpenGLTextureName() const;
virtual bool hasMipMaps() const;
virtual void regenerateMipMapLevels(void* mipmapData=0);
virtual bool isRenderTarget() const;
virtual bool isFrameBufferObject() const;
virtual void bindRTT();
virtual void unbindRTT();
void setIsRenderTarget(bool isTarget);
protected:
COpenGLTexture(const io::path& name, COpenGLDriver* driver);
ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format);
GLint getOpenGLFormatAndParametersFromColorFormat(
ECOLOR_FORMAT format, GLint& filtering, GLenum& colorformat, GLenum& type);
void getImageValues(IImage* image);
void uploadTexture(bool newTexture=false, void* mipmapData=0, u32 mipLevel=0);
core::dimension2d<u32> ImageSize;
core::dimension2d<u32> TextureSize;
ECOLOR_FORMAT ColorFormat;
COpenGLDriver* Driver;
IImage* Image;
IImage* MipImage;
GLuint TextureName;
GLint InternalFormat;
GLenum PixelFormat;
GLenum PixelType;
u8 MipLevelStored;
bool HasMipMaps;
bool IsRenderTarget;
bool AutomaticMipmapUpdate;
bool ReadOnlyLock;
bool KeepImage;
};
class COpenGLFBOTexture : public COpenGLTexture
{
public:
COpenGLFBOTexture(const core::dimension2d<u32>& size, const io::path& name,
COpenGLDriver* driver = 0, const ECOLOR_FORMAT format = ECF_UNKNOWN);
virtual ~COpenGLFBOTexture();
virtual bool isFrameBufferObject() const;
virtual void bindRTT();
virtual void unbindRTT();
ITexture* DepthTexture;
protected:
GLuint ColorFrameBuffer;
};
class COpenGLFBODepthTexture : public COpenGLTexture
{
public:
COpenGLFBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COpenGLDriver* driver=0, bool useStencil=false);
virtual ~COpenGLFBODepthTexture();
virtual void bindRTT();
virtual void unbindRTT();
bool attach(ITexture*);
protected:
GLuint DepthRenderBuffer;
GLuint StencilRenderBuffer;
bool UseStencil;
};
}
}
#endif
#endif