aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/COpenGLTexture.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/COpenGLTexture.h205
1 files changed, 205 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/COpenGLTexture.h b/libraries/irrlicht-1.8/source/Irrlicht/COpenGLTexture.h
new file mode 100644
index 0000000..8bff1a8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/COpenGLTexture.h
@@ -0,0 +1,205 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __C_OPEN_GL_TEXTURE_H_INCLUDED__
6#define __C_OPEN_GL_TEXTURE_H_INCLUDED__
7
8#include "ITexture.h"
9#include "IImage.h"
10
11#include "IrrCompileConfig.h"
12#ifdef _IRR_COMPILE_WITH_OPENGL_
13
14#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
15 #define GL_GLEXT_LEGACY 1
16#else
17 #define GL_GLEXT_PROTOTYPES 1
18#endif
19#ifdef _IRR_WINDOWS_API_
20 // include windows headers for HWND
21 #define WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <GL/gl.h>
24#ifdef _MSC_VER
25 #pragma comment(lib, "OpenGL32.lib")
26#endif
27#elif defined(_IRR_OSX_PLATFORM_)
28 #include <OpenGL/gl.h>
29#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
30 #define NO_SDL_GLEXT
31 #include <SDL/SDL_video.h>
32 #include <SDL/SDL_opengl.h>
33#else
34 #if defined(_IRR_OSX_PLATFORM_)
35 #include <OpenGL/gl.h>
36 #else
37 #include <GL/gl.h>
38 #endif
39#endif
40
41
42namespace irr
43{
44namespace video
45{
46
47class COpenGLDriver;
48//! OpenGL texture.
49class COpenGLTexture : public ITexture
50{
51public:
52
53 //! constructor
54 COpenGLTexture(IImage* surface, const io::path& name, void* mipmapData=0, COpenGLDriver* driver=0);
55
56 //! destructor
57 virtual ~COpenGLTexture();
58
59 //! lock function
60 virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0);
61
62 //! unlock function
63 virtual void unlock();
64
65 //! Returns original size of the texture (image).
66 virtual const core::dimension2d<u32>& getOriginalSize() const;
67
68 //! Returns size of the texture.
69 virtual const core::dimension2d<u32>& getSize() const;
70
71 //! returns driver type of texture (=the driver, that created it)
72 virtual E_DRIVER_TYPE getDriverType() const;
73
74 //! returns color format of texture
75 virtual ECOLOR_FORMAT getColorFormat() const;
76
77 //! returns pitch of texture (in bytes)
78 virtual u32 getPitch() const;
79
80 //! return open gl texture name
81 GLuint getOpenGLTextureName() const;
82
83 //! return whether this texture has mipmaps
84 virtual bool hasMipMaps() const;
85
86 //! Regenerates the mip map levels of the texture.
87 /** Useful after locking and modifying the texture
88 \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. */
89 virtual void regenerateMipMapLevels(void* mipmapData=0);
90
91 //! Is it a render target?
92 virtual bool isRenderTarget() const;
93
94 //! Is it a FrameBufferObject?
95 virtual bool isFrameBufferObject() const;
96
97 //! Bind RenderTargetTexture
98 virtual void bindRTT();
99
100 //! Unbind RenderTargetTexture
101 virtual void unbindRTT();
102
103 //! sets whether this texture is intended to be used as a render target.
104 void setIsRenderTarget(bool isTarget);
105
106protected:
107
108 //! protected constructor with basic setup, no GL texture name created, for derived classes
109 COpenGLTexture(const io::path& name, COpenGLDriver* driver);
110
111 //! get the desired color format based on texture creation flags and the input format.
112 ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format);
113
114 //! Get the OpenGL color format parameters based on the given Irrlicht color format
115 GLint getOpenGLFormatAndParametersFromColorFormat(
116 ECOLOR_FORMAT format, GLint& filtering, GLenum& colorformat, GLenum& type);
117
118 //! get important numbers of the image and hw texture
119 void getImageValues(IImage* image);
120
121 //! copies the texture into an OpenGL texture.
122 /** \param newTexture True if method is called for a newly created texture for the first time. Otherwise call with false to improve memory handling.
123 \param mipmapData Pointer to raw mipmap data, including all necessary mip levels, in the same format as the main texture image.
124 \param mipLevel If set to non-zero, only that specific miplevel is updated, using the MipImage member. */
125 void uploadTexture(bool newTexture=false, void* mipmapData=0, u32 mipLevel=0);
126
127 core::dimension2d<u32> ImageSize;
128 core::dimension2d<u32> TextureSize;
129 ECOLOR_FORMAT ColorFormat;
130 COpenGLDriver* Driver;
131 IImage* Image;
132 IImage* MipImage;
133
134 GLuint TextureName;
135 GLint InternalFormat;
136 GLenum PixelFormat;
137 GLenum PixelType;
138
139 u8 MipLevelStored;
140 bool HasMipMaps;
141 bool MipmapLegacyMode;
142 bool IsRenderTarget;
143 bool AutomaticMipmapUpdate;
144 bool ReadOnlyLock;
145 bool KeepImage;
146};
147
148//! OpenGL FBO texture.
149class COpenGLFBOTexture : public COpenGLTexture
150{
151public:
152
153 //! FrameBufferObject constructor
154 COpenGLFBOTexture(const core::dimension2d<u32>& size, const io::path& name,
155 COpenGLDriver* driver = 0, const ECOLOR_FORMAT format = ECF_UNKNOWN);
156
157 //! destructor
158 virtual ~COpenGLFBOTexture();
159
160 //! Is it a FrameBufferObject?
161 virtual bool isFrameBufferObject() const;
162
163 //! Bind RenderTargetTexture
164 virtual void bindRTT();
165
166 //! Unbind RenderTargetTexture
167 virtual void unbindRTT();
168
169 ITexture* DepthTexture;
170protected:
171 GLuint ColorFrameBuffer;
172};
173
174
175//! OpenGL FBO depth texture.
176class COpenGLFBODepthTexture : public COpenGLTexture
177{
178public:
179 //! FrameBufferObject depth constructor
180 COpenGLFBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COpenGLDriver* driver=0, bool useStencil=false);
181
182 //! destructor
183 virtual ~COpenGLFBODepthTexture();
184
185 //! Bind RenderTargetTexture
186 virtual void bindRTT();
187
188 //! Unbind RenderTargetTexture
189 virtual void unbindRTT();
190
191 bool attach(ITexture*);
192
193protected:
194 GLuint DepthRenderBuffer;
195 GLuint StencilRenderBuffer;
196 bool UseStencil;
197};
198
199
200} // end namespace video
201} // end namespace irr
202
203#endif
204#endif // _IRR_COMPILE_WITH_OPENGL_
205