2011-01-14 05:24:40 -08:00
|
|
|
// Copyright (C) 2002-2011 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_
|
|
|
|
|
2009-04-17 06:46:35 -07:00
|
|
|
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
|
|
|
|
#define GL_GLEXT_LEGACY 1
|
2009-07-14 08:43:53 -07:00
|
|
|
#else
|
|
|
|
#define GL_GLEXT_PROTOTYPES 1
|
2009-04-17 06:46:35 -07:00
|
|
|
#endif
|
2007-05-20 11:03:49 -07:00
|
|
|
#ifdef _IRR_WINDOWS_API_
|
|
|
|
// include windows headers for HWND
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma comment(lib, "OpenGL32.lib")
|
|
|
|
#endif
|
2009-07-28 10:09:24 -07:00
|
|
|
#elif defined(_IRR_OSX_PLATFORM_)
|
2009-04-17 06:46:35 -07:00
|
|
|
#include <OpenGL/gl.h>
|
2009-07-28 10:09:24 -07:00
|
|
|
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
2009-04-17 06:46:35 -07:00
|
|
|
#define NO_SDL_GLEXT
|
|
|
|
#include <SDL/SDL_video.h>
|
|
|
|
#include <SDL/SDL_opengl.h>
|
2007-05-20 11:03:49 -07:00
|
|
|
#else
|
2009-02-28 23:39:52 -08:00
|
|
|
#if defined(_IRR_OSX_PLATFORM_)
|
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
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace video
|
|
|
|
{
|
|
|
|
|
|
|
|
class COpenGLDriver;
|
|
|
|
//! OpenGL texture.
|
|
|
|
class COpenGLTexture : public ITexture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
2009-11-21 15:24:31 -08:00
|
|
|
COpenGLTexture(IImage* surface, const io::path& name, void* mipmapData=0, COpenGLDriver* driver=0);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~COpenGLTexture();
|
|
|
|
|
|
|
|
//! lock function
|
2010-12-14 15:32:54 -08:00
|
|
|
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! unlock function
|
|
|
|
virtual void unlock();
|
|
|
|
|
2007-12-05 16:00:23 -08:00
|
|
|
//! Returns original size of the texture (image).
|
2009-01-19 05:48:22 -08:00
|
|
|
virtual const core::dimension2d<u32>& getOriginalSize() const;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! Returns size of the texture.
|
2009-01-19 05:48:22 -08:00
|
|
|
virtual const core::dimension2d<u32>& 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
|
|
|
|
2009-11-21 15:24:31 -08:00
|
|
|
//! Regenerates the mip map levels of the texture.
|
|
|
|
/** Useful after locking and modifying the texture
|
|
|
|
\param mipmapData Pointer to raw mipmap data, including all necessary mip levels, in the same format as the main texture image. If not set the mipmaps are derived from the main image. */
|
|
|
|
virtual void regenerateMipMapLevels(void* mipmapData=0);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
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?
|
2008-10-28 09:51:22 -07:00
|
|
|
virtual bool isFrameBufferObject() const;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2008-08-18 05:36:17 -07:00
|
|
|
//! Bind RenderTargetTexture
|
2008-10-28 09:51:22 -07:00
|
|
|
virtual void bindRTT();
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2008-08-18 05:36:17 -07:00
|
|
|
//! Unbind RenderTargetTexture
|
2008-10-28 09:51:22 -07:00
|
|
|
virtual void unbindRTT();
|
2007-05-20 11:03:49 -07:00
|
|
|
|
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
|
|
|
|
2008-10-28 09:51:22 -07:00
|
|
|
protected:
|
|
|
|
|
|
|
|
//! protected constructor with basic setup, no GL texture name created, for derived classes
|
2009-08-24 02:12:27 -07:00
|
|
|
COpenGLTexture(const io::path& name, COpenGLDriver* driver);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
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);
|
|
|
|
|
2009-11-04 07:08:14 -08:00
|
|
|
//! Get the OpenGL color format parameters based on the given Irrlicht color format
|
|
|
|
GLint getOpenGLFormatAndParametersFromColorFormat(
|
|
|
|
ECOLOR_FORMAT format, GLint& filtering, GLenum& colorformat, GLenum& type);
|
|
|
|
|
2009-11-21 15:24:31 -08:00
|
|
|
//! get important numbers of the image and hw texture
|
|
|
|
void getImageValues(IImage* image);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2008-10-28 09:51:22 -07:00
|
|
|
//! copies the texture into an OpenGL texture.
|
2009-11-21 15:24:31 -08:00
|
|
|
/** \param newTexture True if method is called for a newly created texture for the first time. Otherwise call with false to improve memory handling.
|
|
|
|
\param mipmapData Pointer to raw mipmap data, including all necessary mip levels, in the same format as the main texture image.
|
|
|
|
\param mipLevel If set to non-zero, only that specific miplevel is updated, using the MipImage member. */
|
|
|
|
void uploadTexture(bool newTexture=false, void* mipmapData=0, u32 mipLevel=0);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2009-01-19 05:48:22 -08:00
|
|
|
core::dimension2d<u32> ImageSize;
|
|
|
|
core::dimension2d<u32> TextureSize;
|
2008-11-13 14:26:41 -08:00
|
|
|
ECOLOR_FORMAT ColorFormat;
|
2007-05-20 11:03:49 -07:00
|
|
|
COpenGLDriver* Driver;
|
|
|
|
IImage* Image;
|
2009-11-21 15:24:31 -08:00
|
|
|
IImage* MipImage;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
GLuint TextureName;
|
|
|
|
GLint InternalFormat;
|
|
|
|
GLenum PixelFormat;
|
|
|
|
GLenum PixelType;
|
|
|
|
|
2009-11-21 15:24:31 -08:00
|
|
|
u8 MipLevelStored;
|
2008-06-27 08:38:48 -07:00
|
|
|
bool HasMipMaps;
|
|
|
|
bool IsRenderTarget;
|
|
|
|
bool AutomaticMipmapUpdate;
|
2008-08-07 04:59:42 -07:00
|
|
|
bool ReadOnlyLock;
|
2008-11-13 14:26:41 -08:00
|
|
|
bool KeepImage;
|
2007-05-20 11:03:49 -07:00
|
|
|
};
|
|
|
|
|
2008-10-28 09:51:22 -07:00
|
|
|
//! OpenGL FBO texture.
|
|
|
|
class COpenGLFBOTexture : public COpenGLTexture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! FrameBufferObject constructor
|
2009-08-24 02:12:27 -07:00
|
|
|
COpenGLFBOTexture(const core::dimension2d<u32>& size, const io::path& name,
|
2009-05-24 02:35:39 -07:00
|
|
|
COpenGLDriver* driver = 0, const ECOLOR_FORMAT format = ECF_UNKNOWN);
|
2008-10-28 09:51:22 -07:00
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~COpenGLFBOTexture();
|
|
|
|
|
|
|
|
//! Is it a FrameBufferObject?
|
|
|
|
virtual bool isFrameBufferObject() const;
|
|
|
|
|
|
|
|
//! Bind RenderTargetTexture
|
|
|
|
virtual void bindRTT();
|
|
|
|
|
|
|
|
//! Unbind RenderTargetTexture
|
|
|
|
virtual void unbindRTT();
|
|
|
|
|
2008-11-03 05:13:28 -08:00
|
|
|
ITexture* DepthTexture;
|
|
|
|
protected:
|
|
|
|
GLuint ColorFrameBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//! OpenGL FBO depth texture.
|
2010-12-23 05:49:37 -08:00
|
|
|
class COpenGLFBODepthTexture : public COpenGLTexture
|
2008-11-03 05:13:28 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! FrameBufferObject depth constructor
|
2009-08-24 02:12:27 -07:00
|
|
|
COpenGLFBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COpenGLDriver* driver=0, bool useStencil=false);
|
2008-11-03 05:13:28 -08:00
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~COpenGLFBODepthTexture();
|
|
|
|
|
|
|
|
//! Bind RenderTargetTexture
|
|
|
|
virtual void bindRTT();
|
|
|
|
|
|
|
|
//! Unbind RenderTargetTexture
|
|
|
|
virtual void unbindRTT();
|
|
|
|
|
2009-01-18 14:39:03 -08:00
|
|
|
bool attach(ITexture*);
|
2008-11-03 05:13:28 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
GLuint DepthRenderBuffer;
|
|
|
|
GLuint StencilRenderBuffer;
|
2008-10-28 09:51:22 -07:00
|
|
|
bool UseStencil;
|
|
|
|
};
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
} // end namespace video
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif // _IRR_COMPILE_WITH_OPENGL_
|
|
|
|
|