add android port from irrlicht (based on commit 875d0cfac88c26994b82d68737b085ec1b84c5f8)

This commit is contained in:
Lucas Baudin 2016-02-24 12:34:08 +01:00
parent c0bfd46ee9
commit a470cd74d6
33 changed files with 14951 additions and 33 deletions

View File

@ -118,8 +118,8 @@ namespace video
//! Support for texture coord transformation via texture matrix
EVDF_TEXTURE_MATRIX,
//! Support for NVidia's CG shader language
EVDF_CG,
//! Support for DXTn compressed textures.
EVDF_TEXTURE_COMPRESSED_DXT,
//! Only used for counting the elements of this enum
EVDF_COUNT

View File

@ -51,6 +51,13 @@ namespace video
/** Performs hardware accelerated rendering of 3D and 2D
primitives. */
EDT_OPENGL,
//! OpenGL-ES 1.x driver, for embedded and mobile systems
EDT_OGLES1,
//! OpenGL-ES 2.x driver, for embedded and mobile systems
/** Supports shaders etc. */
EDT_OGLES2,
//! No driver, just for counting the elements
EDT_COUNT

View File

@ -0,0 +1,38 @@
#ifndef __E_VERTEX_ATTRIBUTES_H_INCLUDED__
#define __E_VERTEX_ATTRIBUTES_H_INCLUDED__
namespace irr
{
namespace video
{
//! Enumeration for all vertex attibutes there are.
enum E_VERTEX_ATTRIBUTES
{
EVA_POSITION = 0,
EVA_NORMAL,
EVA_COLOR,
EVA_TCOORD0,
EVA_TCOORD1,
EVA_TANGENT,
EVA_BINORMAL,
EVA_COUNT
};
//! Array holding the built in vertex attribute names
const char* const sBuiltInVertexAttributeNames[] =
{
"inVertexPosition",
"inVertexNormal",
"inVertexColor",
"inTexCoord0",
"inTexCoord1",
"inVertexTangent",
"inVertexBinormal",
0
};
} // end namespace video
} // end namespace irr
#endif //__E_VERTEX_ATTRIBUTES_H_INCLUDED__

View File

@ -38,6 +38,9 @@ public:
const SMaterial& lastMaterial,
bool resetAllRenderstates) = 0;
//! Return an index constant for the vertex shader based on a name.
virtual s32 getVertexShaderConstantID(const c8* name) = 0;
//! Sets a constant for the vertex shader based on a name.
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. Example: If you created a shader which has
@ -58,18 +61,15 @@ public:
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
\endcode
\param name Name of the variable
\param index Index of the variable
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful.
*/
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count) = 0;
//! Bool interface for the above.
virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count) = 0;
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count) = 0;
//! Int interface for the above.
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count) = 0;
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) = 0;
//! Sets a vertex shader constant.
/** Can be used if you created a shader using pixel/vertex shader
@ -79,21 +79,21 @@ public:
\param constantAmount: Amount of registers to be set. One register consists of 4 floats. */
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! Return an index constant for the pixel shader based on a name.
virtual s32 getPixelShaderConstantID(const c8* name) = 0;
//! Sets a constant for the pixel shader based on a name.
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. See setVertexShaderConstant() for an
example on how to use this.
\param name Name of the variable
\param index Index of the variable
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful. */
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count) = 0;
//! Bool interface for the above.
virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count) = 0;
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) = 0;
//! Int interface for the above.
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count) = 0;
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) = 0;
//! Sets a pixel shader constant.
/** Can be used if you created a shader using pixel/vertex shader
@ -103,6 +103,30 @@ public:
\param constantAmount Amount of registers to be set. One register consists of 4 floats. */
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! \deprecated. This method may be removed by Irrlicht 2.0
_IRR_DEPRECATED_ bool setVertexShaderConstant(const c8* name, const f32* floats, int count)
{
return setVertexShaderConstant(getVertexShaderConstantID(name), floats, count);
}
//! \deprecated. This method may be removed by Irrlicht 2.0
_IRR_DEPRECATED_ bool setVertexShaderConstant(const c8* name, const s32* ints, int count)
{
return setVertexShaderConstant(getVertexShaderConstantID(name), ints, count);
}
//! \deprecated. This method may be removed by Irrlicht 2.0
_IRR_DEPRECATED_ bool setPixelShaderConstant(const c8* name, const f32* floats, int count)
{
return setPixelShaderConstant(getPixelShaderConstantID(name), floats, count);
}
//! \deprecated. This method may be removed by Irrlicht 2.0
_IRR_DEPRECATED_ bool setPixelShaderConstant(const c8* name, const s32* ints, int count)
{
return setPixelShaderConstant(getPixelShaderConstantID(name), ints, count);
}
//! Get pointer to the IVideoDriver interface
/** \return Pointer to the IVideoDriver interface */
virtual IVideoDriver* getVideoDriver() = 0;

View File

@ -24,6 +24,8 @@
//! _IRR_LINUX_PLATFORM_ for Linux (it is defined here if no other os is defined)
//! _IRR_SOLARIS_PLATFORM_ for Solaris
//! _IRR_OSX_PLATFORM_ for Apple systems running OSX
//! _IRR_IPHONE_PLATFORM_ for Apple devices running iOS
//! _IRR_ANDROID_PLATFORM_ for devices running Android
//! _IRR_POSIX_API_ for Posix compatible systems
//! Note: PLATFORM defines the OS specific layer, API can group several platforms
@ -43,7 +45,6 @@
//! different library versions without having to change the sources.
//! Example: NO_IRR_COMPILE_WITH_X11_ would disable X11
//! Uncomment this line to compile with the SDL device
//#define _IRR_COMPILE_WITH_SDL_DEVICE_
#ifdef NO_IRR_COMPILE_WITH_SDL_DEVICE_
@ -93,15 +94,38 @@
#if !defined(MACOSX)
#define MACOSX // legacy support
#endif
#define _IRR_OSX_PLATFORM_
#define _IRR_OSX_PLATFORM_ // we only support OSX on these systems
#if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#define _IRR_IPHONE_PLATFORM_
#define _IRR_COMPILE_WITH_IPHONE_DEVICE_
#define _IRR_COMPILE_WITH_OGLES1_
#define _IRR_COMPILE_WITH_OGLES2_
#else
#define _IRR_COMPILE_WITH_OSX_DEVICE_
#endif
#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_)
#ifndef _IRR_SOLARIS_PLATFORM_
#if !defined(__linux__) && !defined(__FreeBSD__)
#define _IRR_LINUX_PLATFORM_
#endif
#define _IRR_ANDROID_PLATFORM_
#define _IRR_POSIX_API_
#if defined(_IRR_ANDROID_PLATFORM_)
#define _IRR_COMPILE_WITH_ANDROID_DEVICE_
#define _IRR_COMPILE_WITH_OGLES1_
#define _IRR_COMPILE_WITH_OGLES2_
#define _IRR_COMPILE_ANDROID_ASSET_READER_
#endif
#if defined(__SVR4) && defined(__sun)
#define _IRR_SOLARIS_PLATFORM_
#if defined(__sparc)
#define __BIG_ENDIAN__
#endif
#endif
#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
#ifndef _IRR_SOLARIS_PLATFORM_
#define _IRR_LINUX_PLATFORM_
#endif
#define _IRR_POSIX_API_
#define _IRR_COMPILE_WITH_X11_DEVICE_
@ -116,7 +140,20 @@
//! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht.
#define _IRR_MATERIAL_MAX_TEXTURES_ 8
#define _IRR_MATERIAL_MAX_TEXTURES_ 4
//! Whether to support XML and XML-based formats (irrmesh, collada...)
#define _IRR_COMPILE_WITH_XML_
#ifdef NO_IRR_COMPILE_WITH_XML_
#undef _IRR_COMPILE_WITH_XML_
#endif
//! Add a leak-hunter to Irrlicht which helps finding unreleased reference counted objects.
//! NOTE: This is slow and should only be used for debugging
//#define _IRR_COMPILE_WITH_LEAK_HUNTER_
#ifdef NO_IRR_COMPILE_WITH_LEAK_HUNTER_
#undef _IRR_COMPILE_WITH_LEAK_HUNTER_
#endif
//! Define _IRR_COMPILE_WITH_DIRECT3D_8_ and _IRR_COMPILE_WITH_DIRECT3D_9_ to
//! compile the Irrlicht engine with Direct3D8 and/or DIRECT3D9.
@ -138,25 +175,84 @@ headers, e.g. Summer 2004. This is a Microsoft issue, not an Irrlicht one.
//! Define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ if you want to use DirectInput for joystick handling.
/** This only applies to Windows devices, currently only supported under Win32 device.
If not defined, Windows Multimedia library is used, which offers also broad support for joystick devices. */
#undef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
#define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
#ifdef NO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
#undef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
#endif
// can't get this to compile currently under borland, can be removed if someone has a better solution
#if defined(__BORLANDC__)
#undef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
#endif
//! Only define _IRR_COMPILE_WITH_DIRECT3D_8_ if you have an appropriate DXSDK, e.g. Summer 2004
// #define _IRR_COMPILE_WITH_DIRECT3D_8_
#define _IRR_COMPILE_WITH_DIRECT3D_9_
#ifdef NO_IRR_COMPILE_WITH_DIRECT3D_8_
#undef _IRR_COMPILE_WITH_DIRECT3D_8_
#endif
#ifdef NO_IRR_COMPILE_WITH_DIRECT3D_9_
#undef _IRR_COMPILE_WITH_DIRECT3D_9_
#endif
#endif
//! Define _IRR_COMPILE_WITH_OPENGL_ to compile the Irrlicht engine with OpenGL.
/** If you do not wish the engine to be compiled with OpenGL, comment this
define out. */
#if !defined(_IRR_IPHONE_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
#define _IRR_COMPILE_WITH_OPENGL_
#endif
#ifdef NO_IRR_COMPILE_WITH_OPENGL_
#undef _IRR_COMPILE_WITH_OPENGL_
#endif
//! Define _IRR_COMPILE_WITH_OGLES1_ to compile the Irrlicht engine with OpenGL-ES 1.x.
/** If you do not wish the engine to be compiled with OpenGL-ES 1.x, comment
this define out.
You should only use this define if you really need the OpenGL-ES driver, and
it should be usually the only HW accelerated one. OpenGL is currently disabled
if using this driver, to avoid problems with the ogl-es emulators.
*/
// #define _IRR_COMPILE_WITH_OGLES1_
#ifdef NO_IRR_COMPILE_WITH_OGLES1_
#undef _IRR_COMPILE_WITH_OGLES1_
#endif
//! Define _IRR_COMPILE_WITH_OGLES2_ to compile the Irrlicht engine with OpenGL-ES 2.x.
/** If you do not wish the engine to be compiled with OpenGL-ES 2.x, comment
this define out.
You should only use this define if you really need the OpenGL-ES driver, and
it should be usually the only HW accelerated one. OpenGL is currently disabled
if using this driver, to avoid problems with the ogl-es emulators.
*/
// #define _IRR_COMPILE_WITH_OGLES2_
#ifdef NO_IRR_COMPILE_WITH_OGLES2_
#undef _IRR_COMPILE_WITH_OGLES2_
#endif
#ifndef IRR_OGLES2_SHADER_PATH
#ifdef _IRR_COMPILE_WITH_IPHONE_DEVICE_
#define IRR_OGLES2_SHADER_PATH ""
#else
#define IRR_OGLES2_SHADER_PATH "../../media/Shaders/"
#endif
#endif
//! Define _IRR_COMPILE_WITH_SOFTWARE_ to compile the Irrlicht engine with software driver
/** If you do not need the software driver, or want to use Burning's Video instead,
comment this define out */
#define _IRR_COMPILE_WITH_SOFTWARE_
#ifdef NO_IRR_COMPILE_WITH_SOFTWARE_
#undef _IRR_COMPILE_WITH_SOFTWARE_
#endif
//! Define _IRR_COMPILE_WITH_BURNINGSVIDEO_ to compile the Irrlicht engine with Burning's video driver
/** If you do not need this software driver, you can comment this define out. */
#define _IRR_COMPILE_WITH_BURNINGSVIDEO_
#ifdef NO_IRR_COMPILE_WITH_BURNINGSVIDEO_
#undef _IRR_COMPILE_WITH_BURNINGSVIDEO_
#endif
//! Define _IRR_COMPILE_WITH_X11_ to compile the Irrlicht engine with X11 support.
/** If you do not wish the engine to be compiled with X11, comment this
define out. */
@ -169,9 +265,32 @@ define out. */
//! Define _IRR_OPENGL_USE_EXTPOINTER_ if the OpenGL renderer should use OpenGL extensions via function pointers.
/** On some systems there is no support for the dynamic extension of OpenGL
via function pointers such that this has to be undef'ed. */
#ifdef _IRR_COMPILE_WITH_OPENGL_
#if !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_SOLARIS_PLATFORM_)
#define _IRR_OPENGL_USE_EXTPOINTER_
#endif
#endif
//! Define _IRR_OGLES1_USE_EXTPOINTER_ if the OpenGL-ES 1.x driver should use extensions via function pointers.
/** This should usually be enabled, but also depends on the specific
architecture. You can simply uncomment the define and recompile.
The iPhone does not have extension pointers, so disable it there always.
*/
#ifdef _IRR_COMPILE_WITH_OGLES1_
#if !defined(_IRR_IPHONE_PLATFORM_)
#define _IRR_OGLES1_USE_EXTPOINTER_
#endif
#endif
//! Define _IRR_OGLES2_USE_EXTPOINTER_ if the OpenGL-ES 2.x driver should use extensions via function pointers.
/** This should usually be enabled, but also depends on the specific
architecture. You can simply uncomment the define and recompile.
*/
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if !defined(_IRR_IPHONE_PLATFORM_)
#define _IRR_OGLES2_USE_EXTPOINTER_
#endif
#endif
//! On some Linux systems the XF86 vidmode extension or X11 RandR are missing. Use these flags
//! to remove the dependencies such that Irrlicht will compile on those systems, too.
@ -225,7 +344,7 @@ the engine will no longer read .jpeg images. */
//! Define _IRR_USE_NON_SYSTEM_JPEG_LIB_ to let irrlicht use the jpeglib which comes with irrlicht.
/** If this is commented out, Irrlicht will try to compile using the jpeg lib installed in the system.
This is only used when _IRR_COMPILE_WITH_LIBJPEG_ is defined. */
//#define _IRR_USE_NON_SYSTEM_JPEG_LIB_
#define _IRR_USE_NON_SYSTEM_JPEG_LIB_
#ifdef NO_IRR_USE_NON_SYSTEM_JPEG_LIB_
#undef _IRR_USE_NON_SYSTEM_JPEG_LIB_
#endif
@ -241,19 +360,83 @@ the engine will no longer read .png images. */
//! Define _IRR_USE_NON_SYSTEM_LIBPNG_ to let irrlicht use the libpng which comes with irrlicht.
/** If this is commented out, Irrlicht will try to compile using the libpng installed in the system.
This is only used when _IRR_COMPILE_WITH_LIBPNG_ is defined. */
//#define _IRR_USE_NON_SYSTEM_LIB_PNG_
#define _IRR_USE_NON_SYSTEM_LIB_PNG_
#ifdef NO_IRR_USE_NON_SYSTEM_LIB_PNG_
#undef _IRR_USE_NON_SYSTEM_LIB_PNG_
#endif
//! Define _IRR_D3D_NO_SHADER_DEBUGGING to disable shader debugging in D3D9
/** If _IRR_D3D_NO_SHADER_DEBUGGING is undefined in IrrCompileConfig.h,
it is possible to debug all D3D9 shaders in VisualStudio. All shaders
(which have been generated in memory or read from archives for example) will be emitted
into a temporary file at runtime for this purpose. To debug your shaders, choose
Debug->Direct3D->StartWithDirect3DDebugging in Visual Studio, and for every shader a
file named 'irr_dbg_shader_%%.vsh' or 'irr_dbg_shader_%%.psh' will be created. Drag'n'drop
the file you want to debug into visual studio. That's it. You can now set breakpoints and
watch registers, variables etc. This works with ASM, HLSL, and both with pixel and vertex shaders.
Note that the engine will run in D3D REF for this, which is a lot slower than HAL. */
#define _IRR_D3D_NO_SHADER_DEBUGGING
#ifdef NO_IRR_D3D_NO_SHADER_DEBUGGING
#undef _IRR_D3D_NO_SHADER_DEBUGGING
#endif
//! Define _IRR_D3D_USE_LEGACY_HLSL_COMPILER to enable the old HLSL compiler in recent DX SDKs
/** This enables support for ps_1_x shaders for recent DX SDKs. Otherwise, support
for this shader model is not available anymore in SDKs after Oct2006. You need to
distribute the OCT2006_d3dx9_31_x86.cab or OCT2006_d3dx9_31_x64.cab though, in order
to provide the user with the proper DLL. That's why it's disabled by default. */
//#define _IRR_D3D_USE_LEGACY_HLSL_COMPILER
#ifdef NO_IRR_D3D_USE_LEGACY_HLSL_COMPILER
#undef _IRR_D3D_USE_LEGACY_HLSL_COMPILER
#endif
//! Define _IRR_COMPILE_WITH_CG_ to enable Cg Shading Language support
//#define _IRR_COMPILE_WITH_CG_
#ifdef NO_IRR_COMPILE_WITH_CG_
#undef _IRR_COMPILE_WITH_CG_
#endif
#if !defined(_IRR_COMPILE_WITH_OPENGL_) && !defined(_IRR_COMPILE_WITH_DIRECT3D_9_)
#undef _IRR_COMPILE_WITH_CG_
#endif
//! Define _IRR_USE_NVIDIA_PERFHUD_ to opt-in to using the nVidia PerHUD tool
/** Enable, by opting-in, to use the nVidia PerfHUD performance analysis driver
tool <http://developer.nvidia.com/object/nvperfhud_home.html>. */
#undef _IRR_USE_NVIDIA_PERFHUD_
//! Define one of the three setting for Burning's Video Software Rasterizer
/** So if we were marketing guys we could say Irrlicht has 4 Software-Rasterizers.
In a Nutshell:
All Burnings Rasterizers use 32 Bit Backbuffer, 32Bit Texture & 32 Bit Z or WBuffer,
16 Bit/32 Bit can be adjusted on a global flag.
BURNINGVIDEO_RENDERER_BEAUTIFUL
32 Bit + Vertexcolor + Lighting + Per Pixel Perspective Correct + SubPixel/SubTexel Correct +
Bilinear Texturefiltering + WBuffer
BURNINGVIDEO_RENDERER_FAST
32 Bit + Per Pixel Perspective Correct + SubPixel/SubTexel Correct + WBuffer +
Bilinear Dithering TextureFiltering + WBuffer
BURNINGVIDEO_RENDERER_ULTRA_FAST
16Bit + SubPixel/SubTexel Correct + ZBuffer
*/
#define BURNINGVIDEO_RENDERER_BEAUTIFUL
//#define BURNINGVIDEO_RENDERER_FAST
//#define BURNINGVIDEO_RENDERER_ULTRA_FAST
//#define BURNINGVIDEO_RENDERER_CE
//! Uncomment the following line if you want to ignore the deprecated warnings
//#define IGNORE_DEPRECATED_WARNING
//! Define _IRR_COMPILE_WITH_IRR_SCENE_LOADER_ if you want to be able to load
/** .irr scenes using ISceneManager::loadScene */
#define _IRR_COMPILE_WITH_IRR_SCENE_LOADER_
#ifdef NO_IRR_COMPILE_WITH_IRR_SCENE_LOADER_
#undef _IRR_COMPILE_WITH_IRR_SCENE_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ if you want to use bone based
/** animated meshes. If you compile without this, you will be unable to load
B3D, MS3D or X meshes */
@ -268,8 +451,135 @@ B3D, MS3D or X meshes */
#ifdef NO_IRR_COMPILE_WITH_B3D_LOADER_
#undef _IRR_COMPILE_WITH_B3D_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_MS3D_LOADER_ if you want to Milkshape files
#define _IRR_COMPILE_WITH_MS3D_LOADER_
#ifdef NO_IRR_COMPILE_WITH_MS3D_LOADER_
#undef _IRR_COMPILE_WITH_MS3D_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_X_LOADER_ if you want to use Microsoft X files
#define _IRR_COMPILE_WITH_X_LOADER_
#ifdef NO_IRR_COMPILE_WITH_X_LOADER_
#undef _IRR_COMPILE_WITH_X_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_OGRE_LOADER_ if you want to load Ogre 3D files
#define _IRR_COMPILE_WITH_OGRE_LOADER_
#ifdef NO_IRR_COMPILE_WITH_OGRE_LOADER_
#undef _IRR_COMPILE_WITH_OGRE_LOADER_
#endif
#endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_
//! Define _IRR_COMPILE_WITH_IRR_MESH_LOADER_ if you want to load Irrlicht Engine .irrmesh files
#define _IRR_COMPILE_WITH_IRR_MESH_LOADER_
#ifdef NO_IRR_COMPILE_WITH_IRR_MESH_LOADER_
#undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_HALFLIFE_LOADER_ if you want to load Halflife animated files
#define _IRR_COMPILE_WITH_HALFLIFE_LOADER_
#ifdef NO_IRR_COMPILE_WITH_HALFLIFE_LOADER_
#undef _IRR_COMPILE_WITH_HALFLIFE_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_MD2_LOADER_ if you want to load Quake 2 animated files
#define _IRR_COMPILE_WITH_MD2_LOADER_
#ifdef NO_IRR_COMPILE_WITH_MD2_LOADER_
#undef _IRR_COMPILE_WITH_MD2_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_MD3_LOADER_ if you want to load Quake 3 animated files
#define _IRR_COMPILE_WITH_MD3_LOADER_
#ifdef NO_IRR_COMPILE_WITH_MD3_LOADER_
#undef _IRR_COMPILE_WITH_MD3_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_3DS_LOADER_ if you want to load 3D Studio Max files
#define _IRR_COMPILE_WITH_3DS_LOADER_
#ifdef NO_IRR_COMPILE_WITH_3DS_LOADER_
#undef _IRR_COMPILE_WITH_3DS_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_COLLADA_LOADER_ if you want to load Collada files
#define _IRR_COMPILE_WITH_COLLADA_LOADER_
#ifdef NO_IRR_COMPILE_WITH_COLLADA_LOADER_
#undef _IRR_COMPILE_WITH_COLLADA_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_CSM_LOADER_ if you want to load Cartography Shop files
#define _IRR_COMPILE_WITH_CSM_LOADER_
#ifdef NO_IRR_COMPILE_WITH_CSM_LOADER_
#undef _IRR_COMPILE_WITH_CSM_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_BSP_LOADER_ if you want to load Quake 3 BSP files
#define _IRR_COMPILE_WITH_BSP_LOADER_
#ifdef NO_IRR_COMPILE_WITH_BSP_LOADER_
#undef _IRR_COMPILE_WITH_BSP_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_DMF_LOADER_ if you want to load DeleD files
#define _IRR_COMPILE_WITH_DMF_LOADER_
#ifdef NO_IRR_COMPILE_WITH_DMF_LOADER_
#undef _IRR_COMPILE_WITH_DMF_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_LMTS_LOADER_ if you want to load LMTools files
#define _IRR_COMPILE_WITH_LMTS_LOADER_
#ifdef NO_IRR_COMPILE_WITH_LMTS_LOADER_
#undef _IRR_COMPILE_WITH_LMTS_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_MY3D_LOADER_ if you want to load MY3D files
#define _IRR_COMPILE_WITH_MY3D_LOADER_
#ifdef NO_IRR_COMPILE_WITH_MY3D_LOADER_
#undef _IRR_COMPILE_WITH_MY3D_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_OBJ_LOADER_ if you want to load Wavefront OBJ files
#define _IRR_COMPILE_WITH_OBJ_LOADER_
#ifdef NO_IRR_COMPILE_WITH_OBJ_LOADER_
#undef _IRR_COMPILE_WITH_OBJ_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_OCT_LOADER_ if you want to load FSRad OCT files
#define _IRR_COMPILE_WITH_OCT_LOADER_
#ifdef NO_IRR_COMPILE_WITH_OCT_LOADER_
#undef _IRR_COMPILE_WITH_OCT_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_LWO_LOADER_ if you want to load Lightwave3D files
#define _IRR_COMPILE_WITH_LWO_LOADER_
#ifdef NO_IRR_COMPILE_WITH_LWO_LOADER_
#undef _IRR_COMPILE_WITH_LWO_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_STL_LOADER_ if you want to load stereolithography files
#define _IRR_COMPILE_WITH_STL_LOADER_
#ifdef NO_IRR_COMPILE_WITH_STL_LOADER_
#undef _IRR_COMPILE_WITH_STL_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_PLY_LOADER_ if you want to load Polygon (Stanford Triangle) files
#define _IRR_COMPILE_WITH_PLY_LOADER_
#ifdef NO_IRR_COMPILE_WITH_PLY_LOADER_
#undef _IRR_COMPILE_WITH_PLY_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_SMF_LOADER_ if you want to load 3D World Studio mesh files
#define _IRR_COMPILE_WITH_SMF_LOADER_
#ifdef NO_IRR_COMPILE_WITH_SMF_LOADER_
#undef _IRR_COMPILE_WITH_SMF_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_IRR_WRITER_ if you want to write static .irrMesh files
#define _IRR_COMPILE_WITH_IRR_WRITER_
#ifdef NO_IRR_COMPILE_WITH_IRR_WRITER_
#undef _IRR_COMPILE_WITH_IRR_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_COLLADA_WRITER_ if you want to write Collada files
#define _IRR_COMPILE_WITH_COLLADA_WRITER_
#ifdef NO_IRR_COMPILE_WITH_COLLADA_WRITER_
#undef _IRR_COMPILE_WITH_COLLADA_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_STL_WRITER_ if you want to write .stl files
#define _IRR_COMPILE_WITH_STL_WRITER_
#ifdef NO_IRR_COMPILE_WITH_STL_WRITER_
#undef _IRR_COMPILE_WITH_STL_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_OBJ_WRITER_ if you want to write .obj files
#define _IRR_COMPILE_WITH_OBJ_WRITER_
#ifdef NO_IRR_COMPILE_WITH_OBJ_WRITER_
#undef _IRR_COMPILE_WITH_OBJ_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_PLY_WRITER_ if you want to write .ply files
#define _IRR_COMPILE_WITH_PLY_WRITER_
#ifdef NO_IRR_COMPILE_WITH_PLY_WRITER_
#undef _IRR_COMPILE_WITH_PLY_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_BMP_LOADER_ if you want to load .bmp files
//! Disabling this loader will also disable the built-in font
#define _IRR_COMPILE_WITH_BMP_LOADER_
@ -281,11 +591,66 @@ B3D, MS3D or X meshes */
#ifdef NO_IRR_COMPILE_WITH_JPG_LOADER_
#undef _IRR_COMPILE_WITH_JPG_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_PCX_LOADER_ if you want to load .pcx files
#define _IRR_COMPILE_WITH_PCX_LOADER_
#ifdef NO_IRR_COMPILE_WITH_PCX_LOADER_
#undef _IRR_COMPILE_WITH_PCX_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_PNG_LOADER_ if you want to load .png files
#define _IRR_COMPILE_WITH_PNG_LOADER_
#ifdef NO_IRR_COMPILE_WITH_PNG_LOADER_
#undef _IRR_COMPILE_WITH_PNG_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_PPM_LOADER_ if you want to load .ppm/.pgm/.pbm files
#define _IRR_COMPILE_WITH_PPM_LOADER_
#ifdef NO_IRR_COMPILE_WITH_PPM_LOADER_
#undef _IRR_COMPILE_WITH_PPM_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_PSD_LOADER_ if you want to load .psd files
#define _IRR_COMPILE_WITH_PSD_LOADER_
#ifdef NO_IRR_COMPILE_WITH_PSD_LOADER_
#undef _IRR_COMPILE_WITH_PSD_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_DDS_LOADER_ if you want to load compressed .dds files
// Patent problem isn't related to this loader.
#define _IRR_COMPILE_WITH_DDS_LOADER_
#ifdef NO_IRR_COMPILE_WITH_DDS_LOADER_
#undef _IRR_COMPILE_WITH_DDS_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_DDS_DECODER_LOADER_ if you want to load .dds files
//! loader will decompress these files and will send to the memory as uncompressed files.
// Outcommented because
// a) it doesn't compile on 64-bit currently
// b) anyone enabling it should be aware that S3TC compression algorithm which might be used in that loader
// is patented in the US by S3 and they do collect license fees when it's used in applications.
// So if you are unfortunate enough to develop applications for US market and their broken patent system be careful.
// #define _IRR_COMPILE_WITH_DDS_DECODER_LOADER_
#ifdef NO_IRR_COMPILE_WITH_DDS_DECODER_LOADER_
#undef _IRR_COMPILE_WITH_DDS_DECODER_LOADER_
#endif
#ifdef _IRR_COMPILE_WITH_DDS_DECODER_LOADER_
#undef _IRR_COMPILE_WITH_DDS_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_TGA_LOADER_ if you want to load .tga files
#define _IRR_COMPILE_WITH_TGA_LOADER_
#ifdef NO_IRR_COMPILE_WITH_TGA_LOADER_
#undef _IRR_COMPILE_WITH_TGA_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_WAL_LOADER_ if you want to load .wal files
#define _IRR_COMPILE_WITH_WAL_LOADER_
#ifdef NO_IRR_COMPILE_WITH_WAL_LOADER_
#undef _IRR_COMPILE_WITH_WAL_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_LMP_LOADER_ if you want to load .lmp files
#define _IRR_COMPILE_WITH_LMP_LOADER_
#ifdef NO_IRR_COMPILE_WITH_LMP_LOADER_
#undef _IRR_COMPILE_WITH_LMP_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_RGB_LOADER_ if you want to load Silicon Graphics .rgb/.rgba/.sgi/.int/.inta/.bw files
#define _IRR_COMPILE_WITH_RGB_LOADER_
#ifdef NO_IRR_COMPILE_WITH_RGB_LOADER_
#undef _IRR_COMPILE_WITH_RGB_LOADER_
#endif
//! Define _IRR_COMPILE_WITH_BMP_WRITER_ if you want to write .bmp files
#define _IRR_COMPILE_WITH_BMP_WRITER_
@ -297,11 +662,31 @@ B3D, MS3D or X meshes */
#ifdef NO_IRR_COMPILE_WITH_JPG_WRITER_
#undef _IRR_COMPILE_WITH_JPG_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_PCX_WRITER_ if you want to write .pcx files
#define _IRR_COMPILE_WITH_PCX_WRITER_
#ifdef NO_IRR_COMPILE_WITH_PCX_WRITER_
#undef _IRR_COMPILE_WITH_PCX_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_PNG_WRITER_ if you want to write .png files
#define _IRR_COMPILE_WITH_PNG_WRITER_
#ifdef NO_IRR_COMPILE_WITH_PNG_WRITER_
#undef _IRR_COMPILE_WITH_PNG_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_PPM_WRITER_ if you want to write .ppm files
#define _IRR_COMPILE_WITH_PPM_WRITER_
#ifdef NO_IRR_COMPILE_WITH_PPM_WRITER_
#undef _IRR_COMPILE_WITH_PPM_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_PSD_WRITER_ if you want to write .psd files
#define _IRR_COMPILE_WITH_PSD_WRITER_
#ifdef NO_IRR_COMPILE_WITH_PSD_WRITER_
#undef _IRR_COMPILE_WITH_PSD_WRITER_
#endif
//! Define _IRR_COMPILE_WITH_TGA_WRITER_ if you want to write .tga files
#define _IRR_COMPILE_WITH_TGA_WRITER_
#ifdef NO_IRR_COMPILE_WITH_TGA_WRITER_
#undef _IRR_COMPILE_WITH_TGA_WRITER_
#endif
//! Define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ if you want to open ZIP and GZIP archives
/** ZIP reading has several more options below to configure. */
@ -322,10 +707,38 @@ ones. */
/** If this is commented out, Irrlicht will try to compile using the zlib
installed on the system. This is only used when _IRR_COMPILE_WITH_ZLIB_ is
defined. */
//#define _IRR_USE_NON_SYSTEM_ZLIB_
#define _IRR_USE_NON_SYSTEM_ZLIB_
#ifdef NO_IRR_USE_NON_SYSTEM_ZLIB_
#undef _IRR_USE_NON_SYSTEM_ZLIB_
#endif
//! Define _IRR_COMPILE_WITH_ZIP_ENCRYPTION_ if you want to read AES-encrypted ZIP archives
#define _IRR_COMPILE_WITH_ZIP_ENCRYPTION_
#ifdef NO_IRR_COMPILE_WITH_ZIP_ENCRYPTION_
#undef _IRR_COMPILE_WITH_ZIP_ENCRYPTION_
#endif
//! Define _IRR_COMPILE_WITH_BZIP2_ if you want to support bzip2 compressed zip archives
/** bzip2 is superior to the original zip file compression modes, but requires
a certain amount of memory for decompression and adds several files to the
library. */
#define _IRR_COMPILE_WITH_BZIP2_
#ifdef NO_IRR_COMPILE_WITH_BZIP2_
#undef _IRR_COMPILE_WITH_BZIP2_
#endif
//! Define _IRR_USE_NON_SYSTEM_BZLIB_ to let irrlicht use the bzlib which comes with irrlicht.
/** If this is commented out, Irrlicht will try to compile using the bzlib
installed on the system. This is only used when _IRR_COMPILE_WITH_BZLIB_ is
defined. */
#define _IRR_USE_NON_SYSTEM_BZLIB_
#ifdef NO_IRR_USE_NON_SYSTEM_BZLIB_
#undef _IRR_USE_NON_SYSTEM_BZLIB_
#endif
//! Define _IRR_COMPILE_WITH_LZMA_ if you want to use LZMA compressed zip files.
/** LZMA is a very efficient compression code, known from 7zip. Irrlicht
currently only supports zip archives, though. */
#define _IRR_COMPILE_WITH_LZMA_
#ifdef NO_IRR_COMPILE_WITH_LZMA_
#undef _IRR_COMPILE_WITH_LZMA_
#endif
#endif
//! Define __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ if you want to mount folders as archives
@ -333,6 +746,16 @@ defined. */
#ifdef NO__IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_
#undef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_
#endif
//! Define __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_ if you want to open ID software PAK archives
#define __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_
#ifdef NO__IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_
#undef __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_
#endif
//! Define __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_ if you want to open Nebula Device NPK archives
#define __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
#ifdef NO__IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
#undef __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
#endif
//! Define __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_ if you want to open TAR archives
#define __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_
#ifdef NO__IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_
@ -402,12 +825,66 @@ precision will be lower but speed higher. currently X86 only
#endif
#endif
#ifndef _IRR_WINDOWS_API_
#undef _IRR_WCHAR_FILESYSTEM
// XBox does not have OpenGL or DirectX9
#if defined(_IRR_XBOX_PLATFORM_)
#undef _IRR_COMPILE_WITH_OPENGL_
#undef _IRR_COMPILE_WITH_DIRECT3D_9_
#endif
#if defined(__sparc__) || defined(__sun__)
#define __BIG_ENDIAN__
//! WinCE does not have OpenGL or DirectX9. use minimal loaders
#if defined(_WIN32_WCE)
#undef _IRR_COMPILE_WITH_OPENGL_
#undef _IRR_COMPILE_WITH_DIRECT3D_8_
#undef _IRR_COMPILE_WITH_DIRECT3D_9_
#undef BURNINGVIDEO_RENDERER_BEAUTIFUL
#undef BURNINGVIDEO_RENDERER_FAST
#undef BURNINGVIDEO_RENDERER_ULTRA_FAST
#define BURNINGVIDEO_RENDERER_CE
#undef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
#define _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
//#define _IRR_WCHAR_FILESYSTEM
#undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
//#undef _IRR_COMPILE_WITH_MD2_LOADER_
#undef _IRR_COMPILE_WITH_MD3_LOADER_
#undef _IRR_COMPILE_WITH_3DS_LOADER_
#undef _IRR_COMPILE_WITH_COLLADA_LOADER_
#undef _IRR_COMPILE_WITH_CSM_LOADER_
#undef _IRR_COMPILE_WITH_BSP_LOADER_
#undef _IRR_COMPILE_WITH_DMF_LOADER_
#undef _IRR_COMPILE_WITH_LMTS_LOADER_
#undef _IRR_COMPILE_WITH_MY3D_LOADER_
#undef _IRR_COMPILE_WITH_OBJ_LOADER_
#undef _IRR_COMPILE_WITH_OCT_LOADER_
#undef _IRR_COMPILE_WITH_OGRE_LOADER_
#undef _IRR_COMPILE_WITH_LWO_LOADER_
#undef _IRR_COMPILE_WITH_STL_LOADER_
#undef _IRR_COMPILE_WITH_IRR_WRITER_
#undef _IRR_COMPILE_WITH_COLLADA_WRITER_
#undef _IRR_COMPILE_WITH_STL_WRITER_
#undef _IRR_COMPILE_WITH_OBJ_WRITER_
//#undef _IRR_COMPILE_WITH_BMP_LOADER_
//#undef _IRR_COMPILE_WITH_JPG_LOADER_
#undef _IRR_COMPILE_WITH_PCX_LOADER_
//#undef _IRR_COMPILE_WITH_PNG_LOADER_
#undef _IRR_COMPILE_WITH_PPM_LOADER_
#undef _IRR_COMPILE_WITH_PSD_LOADER_
//#undef _IRR_COMPILE_WITH_TGA_LOADER_
#undef _IRR_COMPILE_WITH_WAL_LOADER_
#undef _IRR_COMPILE_WITH_BMP_WRITER_
#undef _IRR_COMPILE_WITH_JPG_WRITER_
#undef _IRR_COMPILE_WITH_PCX_WRITER_
#undef _IRR_COMPILE_WITH_PNG_WRITER_
#undef _IRR_COMPILE_WITH_PPM_WRITER_
#undef _IRR_COMPILE_WITH_PSD_WRITER_
#undef _IRR_COMPILE_WITH_TGA_WRITER_
#endif
#ifndef _IRR_WINDOWS_API_
#undef _IRR_WCHAR_FILESYSTEM
#endif
#if defined(_IRR_SOLARIS_PLATFORM_)
@ -420,5 +897,31 @@ precision will be lower but speed higher. currently X86 only
#undef __IRR_HAS_S64
#endif
// These depend on XML
#ifndef _IRR_COMPILE_WITH_XML_
#undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
#undef _IRR_COMPILE_WITH_IRR_WRITER_
#undef _IRR_COMPILE_WITH_COLLADA_WRITER_
#undef _IRR_COMPILE_WITH_COLLADA_LOADER_
#endif
#if defined(__BORLANDC__)
#include <tchar.h>
// Borland 5.5.1 does not have _strcmpi defined
#if __BORLANDC__ == 0x551
// #define _strcmpi strcmpi
#undef _tfinddata_t
#undef _tfindfirst
#undef _tfindnext
#define _tfinddata_t __tfinddata_t
#define _tfindfirst __tfindfirst
#define _tfindnext __tfindnext
typedef long intptr_t;
#endif
#endif
#endif // __IRR_COMPILE_CONFIG_H_INCLUDED__

View File

@ -300,6 +300,13 @@ namespace irr
/** Always set it to IRRLICHT_SDK_VERSION, which is done by default.
This is needed for sdk version checks. */
const c8* const SDK_version_do_not_use;
//! Define some private data storage.
/** Used when platform devices need access to OS specific data structures etc.
This is only used for Android at th emoment in order to access the native
Java RE. */
void *PrivateData;
};

View File

@ -358,6 +358,18 @@ void CColorConverter::convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP)
}
}
void CColorConverter::convert_A1R5G5B5toR5G5B5A1(const void* sP, s32 sN, void* dP)
{
const u16* sB = (const u16*)sP;
u16* dB = (u16*)dP;
for (s32 x = 0; x < sN; ++x)
{
*dB = (*sB<<1)|(*sB>>15);
++sB; ++dB;
}
}
void CColorConverter::convert_A1R5G5B5toA8R8G8B8(const void* sP, s32 sN, void* dP)
{
u16* sB = (u16*)sP;
@ -516,6 +528,30 @@ void CColorConverter::convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP)
}
}
void CColorConverter::convert_A8R8G8B8toR8G8B8A8(const void* sP, s32 sN, void* dP)
{
const u32* sB = (const u32*)sP;
u32* dB = (u32*)dP;
for (s32 x = 0; x < sN; ++x)
{
*dB++ = (*sB<<8) | (*sB>>24);
++sB;
}
}
void CColorConverter::convert_A8R8G8B8toA8B8G8R8(const void* sP, s32 sN, void* dP)
{
const u32* sB = (const u32*)sP;
u32* dB = (u32*)dP;
for (s32 x = 0; x < sN; ++x)
{
*dB++ = (*sB&0xff00ff00)|((*sB&0x00ff0000)>>16)|((*sB&0x000000ff)<<16);
++sB;
}
}
void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* dP)
{
u8* sB = (u8*)sP;
@ -534,6 +570,22 @@ void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* d
}
void CColorConverter::convert_R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP)
{
u8* sB = (u8*)sP;
u8* dB = (u8*)dP;
for (s32 x = 0; x < sN; ++x)
{
dB[2] = sB[0];
dB[1] = sB[1];
dB[0] = sB[2];
sB += 3;
dB += 3;
}
}
void CColorConverter::convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
{
u8 * sB = (u8 *)sP;
@ -697,8 +749,6 @@ void CColorConverter::convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, s32 sN
#endif
}
break;
default:
break;
}
}

View File

@ -59,6 +59,7 @@ public:
static void convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP);
static void convert_A1R5G5B5toA8R8G8B8(const void* sP, s32 sN, void* dP);
static void convert_A1R5G5B5toA1R5G5B5(const void* sP, s32 sN, void* dP);
static void convert_A1R5G5B5toR5G5B5A1(const void* sP, s32 sN, void* dP);
static void convert_A1R5G5B5toR5G6B5(const void* sP, s32 sN, void* dP);
static void convert_A8R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP);
@ -71,9 +72,12 @@ public:
static void convert_R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP);
static void convert_R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP);
static void convert_R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP);
static void convert_R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP);
static void convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP);
static void convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP);
static void convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* dP);
static void convert_A8R8G8B8toR8G8B8A8(const void* sP, s32 sN, void* dP);
static void convert_A8R8G8B8toA8B8G8R8(const void* sP, s32 sN, void* dP);
static void convert_R5G6B5toR5G6B5(const void* sP, s32 sN, void* dP);
static void convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,550 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_DRIVER_H_INCLUDED__
#define __C_OGLES2_DRIVER_H_INCLUDED__
#include "IrrCompileConfig.h"
#if defined(_IRR_WINDOWS_API_)
// include windows headers for HWND
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
#include "MacOSX/CIrrDeviceMacOSX.h"
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include "iOS/CIrrDeviceiOS.h"
#endif
#include "SIrrCreationParameters.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#else
#include <EGL/eglplatform.h>
#endif
#include "CNullDriver.h"
#include "IMaterialRendererServices.h"
#include "EDriverFeatures.h"
#include "fast_atof.h"
#ifdef _MSC_VER
#pragma comment(lib, "libEGL.lib")
#pragma comment(lib, "libGLESv2.lib")
#endif
#include "COGLES2ExtensionHandler.h"
namespace irr
{
namespace video
{
class COGLES2CallBridge;
class COGLES2Texture;
class COGLES2FixedPipelineRenderer;
class COGLES2Renderer2D;
class COGLES2NormalMapRenderer;
class COGLES2ParallaxMapRenderer;
class COGLES2Driver : public CNullDriver, public IMaterialRendererServices, public COGLES2ExtensionHandler
{
friend class COGLES2CallBridge;
friend class COGLES2Texture;
public:
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_CONSOLE_DEVICE_)
COGLES2Driver(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data,
io::IFileSystem* io);
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
COGLES2Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceMacOSX *device);
#endif
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
COGLES2Driver(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data,
io::IFileSystem* io, CIrrDeviceIPhone* device);
#endif
//! destructor
virtual ~COGLES2Driver();
//! clears the zbuffer
virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
SColor color=SColor(255, 0, 0, 0),
const SExposedVideoData& videoData=SExposedVideoData(),
core::rect<s32>* sourceRect=0);
//! presents the rendered scene on the screen, returns false if failed
virtual bool endScene();
//! sets transformation
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
struct SHWBufferLink_opengl : public SHWBufferLink
{
SHWBufferLink_opengl(const scene::IMeshBuffer *meshBuffer): SHWBufferLink(meshBuffer), vbo_verticesID(0), vbo_indicesID(0) {}
u32 vbo_verticesID; //tmp
u32 vbo_indicesID; //tmp
u32 vbo_verticesSize; //tmp
u32 vbo_indicesSize; //tmp
};
bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
//! updates hardware buffer if needed
virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer);
//! Create hardware buffer from mesh
virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb);
//! Delete hardware buffer (only some drivers can)
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
//! Draw hardware buffer
virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer);
//! draws a vertex primitive list
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
void drawVertexPrimitiveList2d3d(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
E_INDEX_TYPE iType = EIT_16BIT, bool threed = true);
//! queries the features of the driver, returns true if feature is available
virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
{
return FeatureEnabled[feature] && COGLES2ExtensionHandler::queryFeature(feature);
}
//! Sets a material.
virtual void setMaterial(const SMaterial& material);
//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
virtual void draw2DImage(const video::ITexture* texture,
const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false);
//! draws a set of 2d images
virtual void draw2DImageBatch(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::array<core::rect<s32> >& sourceRects,
const core::array<s32>& indices, s32 kerningWidth = 0,
const core::rect<s32>* clipRect = 0,
SColor color = SColor(255, 255, 255, 255),
bool useAlphaChannelOfTexture = false);
//! Draws a part of the texture into the rectangle.
virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors = 0, bool useAlphaChannelOfTexture = false);
void draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect,
SColor color,
bool useAlphaChannelOfTexture);
//! draw an 2d rectangle
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip = 0);
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip = 0);
//! Draws a 2d line.
virtual void draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end,
SColor color = SColor(255, 255, 255, 255));
//! Draws a single pixel
virtual void drawPixel(u32 x, u32 y, const SColor & color);
//! Draws a 3d line.
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end,
SColor color = SColor(255, 255, 255, 255));
//! Draws a pixel
// virtual void drawPixel(u32 x, u32 y, const SColor & color);
//! Returns the name of the video driver.
virtual const wchar_t* getName() const;
//! deletes all dynamic lights there are
virtual void deleteAllDynamicLights();
//! adds a dynamic light
virtual s32 addDynamicLight(const SLight& light);
//! Turns a dynamic light on or off
/** \param lightIndex: the index returned by addDynamicLight
\param turnOn: true to turn the light on, false to turn it off */
virtual void turnLightOn(s32 lightIndex, bool turnOn);
//! returns the maximal amount of dynamic lights the device can handle
virtual u32 getMaximalDynamicLightAmount() const;
//! Sets the dynamic ambient light color.
virtual void setAmbientLight(const SColorf& color);
//! return the dynamic ambient light color.
const SColorf& getAmbientLight() const;
//! Returns the maximum texture size supported.
virtual core::dimension2du getMaxTextureSize() const;
//! Draws a shadow volume into the stencil buffer.
virtual void drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail);
//! Fills the stencil shadow with color.
virtual void drawStencilShadow(bool clearStencilBuffer = false,
video::SColor leftUpEdge = video::SColor(0, 0, 0, 0),
video::SColor rightUpEdge = video::SColor(0, 0, 0, 0),
video::SColor leftDownEdge = video::SColor(0, 0, 0, 0),
video::SColor rightDownEdge = video::SColor(0, 0, 0, 0));
//! sets a viewport
virtual void setViewPort(const core::rect<s32>& area);
//! Only used internally by the engine
virtual void OnResize(const core::dimension2d<u32>& size);
//! Returns type of video driver
virtual E_DRIVER_TYPE getDriverType() const;
//! get color format of the current color buffer
virtual ECOLOR_FORMAT getColorFormat() const;
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
//! Can be called by an IMaterialRenderer to make its work easier.
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderstates);
//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call.
virtual void setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates);
//! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name);
//! Get a pixel shader constant index.
virtual s32 getPixelShaderConstantID(const c8* name);
//! Sets a vertex shader constant.
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1);
//! Sets a pixel shader constant.
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1);
//! Sets a constant for the vertex shader based on an index.
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
//! Sets a constant for the pixel shader based on an index.
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
//! sets the current Texture
bool setActiveTexture(u32 stage, const video::ITexture* texture);
//! check if active texture is not equal null.
bool isActiveTexture(u32 stage);
//! disables all textures beginning with fromStage.
bool disableTextures(u32 fromStage = 0);
//! Adds a new material renderer to the VideoDriver
virtual s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);
//! Adds a new material renderer to the VideoDriver
virtual s32 addHighLevelShaderMaterial(
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName = 0,
E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1,
const c8* pixelShaderProgram = 0,
const c8* pixelShaderEntryPointName = 0,
E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1,
const c8* geometryShaderProgram = 0,
const c8* geometryShaderEntryPointName = "main",
E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
u32 verticesOut = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
s32 userData=0,
E_GPU_SHADING_LANGUAGE shadingLang = EGSL_DEFAULT);
//! Returns pointer to the IGPUProgrammingServices interface.
virtual IGPUProgrammingServices* getGPUProgrammingServices();
//! Returns a pointer to the IVideoDriver interface.
virtual IVideoDriver* getVideoDriver();
//! Returns the maximum amount of primitives
virtual u32 getMaximalPrimitiveCount() const;
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN);
virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color);
//! set or reset special render targets
// virtual bool setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget,
// bool clearZBuffer, SColor color);
//! Sets multiple render targets
// virtual bool setRenderTarget(const core::array<video::IRenderTarget>& texture,
// bool clearBackBuffer=true, bool clearZBuffer=true, SColor color=SColor(0,0,0,0));
//! Clears the ZBuffer.
virtual void clearZBuffer();
//! Returns an image created from the last rendered frame.
virtual IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER);
//! checks if an OpenGL error has happend and prints it
bool testGLError();
//! checks if an OGLES1 error has happend and prints it
bool testEGLError();
//! Set/unset a clipping plane.
virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable = false);
//! returns the current amount of user clip planes set.
u32 getClipPlaneCount() const;
//! returns the 0 indexed Plane
const core::plane3df& getClipPlane(u32 index) const;
//! Enable/disable a clipping plane.
virtual void enableClipPlane(u32 index, bool enable);
//! Returns the graphics card vendor name.
virtual core::stringc getVendorInfo()
{
return vendorName;
};
ITexture* createDepthTexture(ITexture* texture, bool shared = true);
void removeDepthTexture(ITexture* texture);
void deleteFramebuffers(s32 n, const u32 *framebuffers);
void deleteRenderbuffers(s32 n, const u32 *renderbuffers);
// returns the current size of the screen or rendertarget
virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const;
//! Convert E_BLEND_FACTOR to OpenGL equivalent
GLenum getGLBlend(E_BLEND_FACTOR factor) const;
//! Get ZBuffer bits.
GLenum getZBufferBits() const;
//! Get current material.
const SMaterial& getCurrentMaterial() const;
//! Get bridge calls.
COGLES2CallBridge* getBridgeCalls() const;
private:
// Bridge calls.
COGLES2CallBridge* BridgeCalls;
void uploadClipPlane(u32 index);
//! inits the opengl-es driver
bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer);
//! returns a device dependent texture from a software surface (IImage)
virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData);
//! creates a transposed matrix in supplied GLfloat array to pass to OGLES1
inline void createGLMatrix(float gl_matrix[16], const core::matrix4& m);
inline void createGLTextureMatrix(float gl_matrix[16], const core::matrix4& m);
//! Map Irrlicht wrap mode to OpenGL enum
GLint getTextureWrapMode(u8 clamp) const;
//! sets the needed renderstates
void setRenderStates3DMode();
//! sets the needed renderstates
void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
void createMaterialRenderers();
core::stringw Name;
core::matrix4 Matrices[ETS_COUNT];
//! enumeration for rendering modes such as 2d and 3d for minizing the switching of renderStates.
enum E_RENDER_MODE
{
ERM_NONE = 0, // no render state has been set yet.
ERM_2D, // 2d drawing rendermode
ERM_3D // 3d rendering mode
};
E_RENDER_MODE CurrentRenderMode;
//! bool to make all renderstates reset if set to true.
bool ResetRenderStates;
bool Transformation3DChanged;
u8 AntiAlias;
SMaterial Material, LastMaterial;
COGLES2Texture* RenderTargetTexture;
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
core::array<ITexture*> DepthTextures;
struct SUserClipPlane
{
core::plane3df Plane;
bool Enabled;
};
core::array<SUserClipPlane> UserClipPlane;
core::dimension2d<u32> CurrentRendertargetSize;
core::stringc vendorName;
core::matrix4 TextureFlipMatrix;
//! Color buffer format
ECOLOR_FORMAT ColorFormat;
//! All the lights that have been requested; a hardware limited
//! number of them will be used at once.
struct RequestedLight
{
RequestedLight(SLight const & lightData)
: LightData(lightData), DesireToBeOn(true) { }
SLight LightData;
bool DesireToBeOn;
};
core::array<RequestedLight> RequestedLights;
SColorf AmbientLight;
COGLES2Renderer2D* MaterialRenderer2D;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
HDC HDc;
#endif
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
CIrrDeviceIPhone* Device;
GLuint ViewFramebuffer;
GLuint ViewRenderbuffer;
GLuint ViewDepthRenderbuffer;
#else
NativeWindowType EglWindow;
void* EglDisplay;
void* EglSurface;
void* EglContext;
#endif
};
//! This bridge between Irlicht pseudo OpenGL calls
//! and true OpenGL calls.
class COGLES2CallBridge
{
public:
COGLES2CallBridge(COGLES2Driver* driver);
// Blending calls.
void setBlendFunc(GLenum source, GLenum destination);
void setBlend(bool enable);
// Cull face calls.
void setCullFaceFunc(GLenum mode);
void setCullFace(bool enable);
// Depth calls.
void setDepthFunc(GLenum mode);
void setDepthMask(bool enable);
void setDepthTest(bool enable);
// Program calls.
void setProgram(GLuint program);
// Texture calls.
void setActiveTexture(GLenum texture);
void setTexture(u32 stage);
// Viewport calls.
void setViewport(const core::rect<s32>& viewport);
private:
COGLES2Driver* Driver;
GLenum BlendSource;
GLenum BlendDestination;
bool Blend;
GLenum CullFaceMode;
bool CullFace;
GLenum DepthFunc;
bool DepthMask;
bool DepthTest;
GLuint Program;
GLenum ActiveTexture;
const ITexture* Texture[MATERIAL_MAX_TEXTURES];
core::rect<s32> Viewport;
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OPENGL_
#endif

View File

@ -0,0 +1,262 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2ExtensionHandler.h"
#include "COGLES2Driver.h"
#include "fast_atof.h"
#include "irrString.h"
namespace irr
{
namespace video
{
static const char* const OGLES2FeatureStrings[COGLES2ExtensionHandler::IRR_OGLES2_Feature_Count] =
{
"GL_AMD_compressed_3DC_texture",
"GL_AMD_compressed_ATC_texture",
"GL_AMD_performance_monitor",
"GL_AMD_program_binary_Z400",
"GL_ANGLE_framebuffer_blit",
"GL_ANGLE_framebuffer_multisample",
"GL_ANGLE_instanced_arrays",
"GL_ANGLE_pack_reverse_row_order",
"GL_ANGLE_texture_compression_dxt3",
"GL_ANGLE_texture_compression_dxt5",
"GL_ANGLE_texture_usage",
"GL_ANGLE_translated_shader_source",
"GL_APPLE_copy_texture_levels",
"GL_APPLE_framebuffer_multisample",
"GL_APPLE_rgb_422",
"GL_APPLE_sync",
"GL_APPLE_texture_2D_limited_npot",
"GL_APPLE_texture_format_BGRA8888",
"GL_APPLE_texture_max_level",
"GL_ARB_texture_env_combine",
"GL_ARB_texture_env_dot3",
"GL_ARM_mali_program_binary",
"GL_ARM_mali_shader_binary",
"GL_ARM_rgba8",
"GL_DMP_shader_binary",
"GL_EXT_blend_minmax",
"GL_EXT_color_buffer_half_float",
"GL_EXT_debug_label",
"GL_EXT_debug_marker",
"GL_EXT_discard_framebuffer",
"GL_EXT_frag_depth",
"GL_EXT_map_buffer_range",
"GL_EXT_multisampled_render_to_texture",
"GL_EXT_multiview_draw_buffers",
"GL_EXT_multi_draw_arrays",
"GL_EXT_occlusion_query_boolean",
"GL_EXT_read_format_bgra",
"GL_EXT_robustness",
"GL_EXT_separate_shader_objects",
"GL_EXT_shader_framebuffer_fetch",
"GL_EXT_shader_texture_lod",
"GL_EXT_shadow_samplers",
"GL_EXT_sRGB",
"GL_EXT_texture_compression_dxt1",
"GL_EXT_texture_filter_anisotropic",
"GL_EXT_texture_format_BGRA8888",
"GL_EXT_texture_lod_bias",
"GL_EXT_texture_rg",
"GL_EXT_texture_storage",
"GL_EXT_texture_type_2_10_10_10_REV",
"GL_EXT_unpack_subimage",
"GL_FJ_shader_binary_GCCSO",
"GL_IMG_multisampled_render_to_texture",
"GL_IMG_program_binary",
"GL_IMG_read_format",
"GL_IMG_shader_binary",
"GL_IMG_texture_compression_pvrtc",
"GL_IMG_texture_env_enhanced_fixed_function",
"GL_IMG_texture_format_BGRA8888",
"GL_IMG_user_clip_plane",
"GL_IMG_vertex_program",
"GL_KHR_debug",
"GL_KHR_texture_compression_astc_ldr",
"GL_NV_coverage_sample",
"GL_NV_depth_nonlinear",
"GL_NV_draw_buffers",
"GL_NV_EGL_stream_consumer_external",
"GL_NV_fbo_color_attachments",
"GL_NV_fence",
"GL_NV_read_buffer",
"GL_NV_read_buffer_front",
"GL_NV_read_depth",
"GL_NV_read_depth_stencil",
"GL_NV_read_stencil",
"GL_NV_texture_compression_s3tc_update",
"GL_NV_texture_npot_2D_mipmap",
"GL_OES_blend_equation_separate",
"GL_OES_blend_func_separate",
"GL_OES_blend_subtract",
"GL_OES_byte_coordinates",
"GL_OES_compressed_ETC1_RGB8_texture",
"GL_OES_compressed_paletted_texture",
"GL_OES_depth24",
"GL_OES_depth32",
"GL_OES_depth_texture",
"GL_OES_draw_texture",
"GL_OES_EGL_image",
"GL_OES_EGL_image_external",
"GL_OES_EGL_sync",
"GL_OES_element_index_uint",
"GL_OES_extended_matrix_palette",
"GL_OES_fbo_render_mipmap",
"GL_OES_fixed_point",
"GL_OES_fragment_precision_high",
"GL_OES_framebuffer_object",
"GL_OES_get_program_binary",
"GL_OES_mapbuffer",
"GL_OES_matrix_get",
"GL_OES_matrix_palette",
"GL_OES_packed_depth_stencil",
"GL_OES_point_size_array",
"GL_OES_point_sprite",
"GL_OES_query_matrix",
"GL_OES_read_format",
"GL_OES_required_internalformat",
"GL_OES_rgb8_rgba8",
"GL_OES_single_precision",
"GL_OES_standard_derivatives",
"GL_OES_stencil1",
"GL_OES_stencil4",
"GL_OES_stencil8",
"GL_OES_stencil_wrap",
"GL_OES_surfaceless_context",
"GL_OES_texture_3D",
"GL_OES_texture_cube_map",
"GL_OES_texture_env_crossbar",
"GL_OES_texture_float",
"GL_OES_texture_float_linear",
"GL_OES_texture_half_float",
"GL_OES_texture_half_float_linear",
"GL_OES_texture_mirrored_repeat",
"GL_OES_texture_npot",
"GL_OES_vertex_array_object",
"GL_OES_vertex_half_float",
"GL_OES_vertex_type_10_10_10_2",
"GL_QCOM_alpha_test",
"GL_QCOM_binning_control",
"GL_QCOM_driver_control",
"GL_QCOM_extended_get",
"GL_QCOM_extended_get2",
"GL_QCOM_performance_monitor_global_mode",
"GL_QCOM_tiled_rendering",
"GL_QCOM_writeonly_rendering",
"GL_SUN_multi_draw_arrays",
"GL_VIV_shader_binary"
};
COGLES2ExtensionHandler::COGLES2ExtensionHandler() :
EGLVersion(0), Version(0), MaxTextureUnits(0), MaxSupportedTextures(0),
MaxAnisotropy(1), MaxTextureSize(1),
MaxIndices(0xffff), MaxTextureLODBias(0.f),
StencilBuffer(false)
{
for (u32 i=0; i<IRR_OGLES2_Feature_Count; ++i)
FeatureAvailable[i] = false;
}
void COGLES2ExtensionHandler::dump() const
{
for (u32 i=0; i<IRR_OGLES2_Feature_Count; ++i)
os::Printer::log(OGLES2FeatureStrings[i], FeatureAvailable[i] ? " true" : " false");
}
void COGLES2ExtensionHandler::initExtensions(COGLES2Driver* driver,
#ifdef EGL_VERSION_1_0
EGLDisplay display,
#endif
bool withStencil)
{
#ifdef EGL_VERSION_1_0
const f32 egl_ver = core::fast_atof(reinterpret_cast<const c8*>(eglQueryString(display, EGL_VERSION)));
EGLVersion = static_cast<u16>(core::floor32(egl_ver)*100+core::round32(core::fract(egl_ver)*10.0f));
core::stringc eglExtensions = eglQueryString(display, EGL_EXTENSIONS);
os::Printer::log(eglExtensions.c_str());
#endif
const core::stringc stringVer(glGetString(GL_VERSION));
const f32 ogl_ver = core::fast_atof(stringVer.c_str() + 10);
Version = static_cast<u16>(core::floor32(ogl_ver) * 100 + core::round32(core::fract(ogl_ver) * 10.0f));
core::stringc extensions = glGetString(GL_EXTENSIONS);
os::Printer::log(extensions.c_str());
// typo in the simulator (note the postfixed s)
if (extensions.find("GL_IMG_user_clip_planes"))
FeatureAvailable[IRR_IMG_user_clip_plane] = true;
{
const u32 size = extensions.size() + 1;
c8* str = new c8[size];
strncpy(str, extensions.c_str(), extensions.size());
str[extensions.size()] = ' ';
c8* p = str;
for (u32 i=0; i<size; ++i)
{
if (str[i] == ' ')
{
str[i] = 0;
if (*p)
for (u32 j=0; j<IRR_OGLES2_Feature_Count; ++j)
{
if (!strcmp(OGLES2FeatureStrings[j], p))
{
FeatureAvailable[j] = true;
break;
}
}
p = p + strlen(p) + 1;
}
}
delete [] str;
}
GLint val=0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val);
MaxSupportedTextures = core::min_(MATERIAL_MAX_TEXTURES, static_cast<u32>(val));
#ifdef GL_EXT_texture_filter_anisotropic
if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic])
{
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
MaxAnisotropy = static_cast<u8>(val);
}
#endif
#ifdef GL_MAX_ELEMENTS_INDICES
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val);
MaxIndices=val;
#endif
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
MaxTextureSize=static_cast<u32>(val);
#ifdef GL_EXT_texture_lod_bias
if (FeatureAvailable[IRR_EXT_texture_lod_bias])
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
#endif
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
MaxTextureUnits = core::min_(MaxSupportedTextures, static_cast<u8>(MATERIAL_MAX_TEXTURES));
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES2_

View File

@ -0,0 +1,263 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_EXTENSION_HANDLER_H_INCLUDED__
#define __C_OGLES2_EXTENSION_HANDLER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#else
#include <EGL/egl.h>
#include <GLES2/gl2.h>
// seems to be missing...
typedef char GLchar;
#if defined(_IRR_OGLES2_USE_EXTPOINTER_)
#include "gles2-ext.h"
#endif
#endif
#include "os.h"
#include "EDriverFeatures.h"
namespace irr
{
namespace video
{
class COGLES2Driver;
class COGLES2ExtensionHandler
{
public:
enum EOGLES2Features
{
IRR_AMD_compressed_3DC_texture=0, // 39
IRR_AMD_compressed_ATC_texture, // 40
IRR_AMD_performance_monitor, // 50
IRR_AMD_program_binary_Z400, // 48
IRR_ANGLE_framebuffer_blit, // 84
IRR_ANGLE_framebuffer_multisample, // 84
IRR_ANGLE_instanced_arrays, // 109
IRR_ANGLE_pack_reverse_row_order, // 110
IRR_ANGLE_texture_compression_dxt3, // 111
IRR_ANGLE_texture_compression_dxt5, // 111
IRR_ANGLE_texture_usage, // 112
IRR_ANGLE_translated_shader_source, // 113
IRR_APPLE_copy_texture_levels, // 123
IRR_APPLE_framebuffer_multisample, // 78
IRR_APPLE_rgb_422, // 76
IRR_APPLE_sync, // 124
IRR_APPLE_texture_2D_limited_npot, // 59
IRR_APPLE_texture_format_BGRA8888, // 79
IRR_APPLE_texture_max_level, // 80
IRR_ARB_texture_env_combine, //ogl, IMG simulator
IRR_ARB_texture_env_dot3, //ogl, IMG simulator
IRR_ARM_mali_program_binary, // 120
IRR_ARM_mali_shader_binary, // 81
IRR_ARM_rgba8, // 82
IRR_DMP_shader_binary, // 88
IRR_EXT_blend_minmax, // 65
IRR_EXT_color_buffer_half_float, // 97
IRR_EXT_debug_label, // 98
IRR_EXT_debug_marker, // 99
IRR_EXT_discard_framebuffer, // 64
IRR_EXT_frag_depth, // 86
IRR_EXT_map_buffer_range, // 121
IRR_EXT_multisampled_render_to_texture, // 106
IRR_EXT_multiview_draw_buffers, // 125
IRR_EXT_multi_draw_arrays, // 69
IRR_EXT_occlusion_query_boolean, // 100
IRR_EXT_read_format_bgra, // 66
IRR_EXT_robustness, // 107
IRR_EXT_separate_shader_objects, // 101
IRR_EXT_shader_framebuffer_fetch, // 122
IRR_EXT_shader_texture_lod, // 77
IRR_EXT_shadow_samplers, // 102
IRR_EXT_sRGB, // 105
IRR_EXT_texture_compression_dxt1, // 49
IRR_EXT_texture_filter_anisotropic, // 41
IRR_EXT_texture_format_BGRA8888, // 51
IRR_EXT_texture_lod_bias, // 60
IRR_EXT_texture_rg, // 103
IRR_EXT_texture_storage, // 108
IRR_EXT_texture_type_2_10_10_10_REV, // 42
IRR_EXT_unpack_subimage, // 90
IRR_FJ_shader_binary_GCCSO, // 114
IRR_IMG_multisampled_render_to_texture, // 74
IRR_IMG_program_binary, // 67
IRR_IMG_read_format, // 53
IRR_IMG_shader_binary, // 68
IRR_IMG_texture_compression_pvrtc, // 54
IRR_IMG_texture_env_enhanced_fixed_function, // 58
IRR_IMG_texture_format_BGRA8888, // replaced by EXT version
IRR_IMG_user_clip_plane, // 57, was clip_planes
IRR_IMG_vertex_program, // non-standard
IRR_KHR_debug, // 118
IRR_KHR_texture_compression_astc_ldr, // 117
IRR_NV_coverage_sample, // 72
IRR_NV_depth_nonlinear, // 73
IRR_NV_draw_buffers, // 91
IRR_NV_EGL_stream_consumer_external, // 104
IRR_NV_fbo_color_attachments, // 92
IRR_NV_fence, // 52
IRR_NV_read_buffer, // 93
IRR_NV_read_buffer_front, // part of 93
IRR_NV_read_depth, // part of 94
IRR_NV_read_depth_stencil, // 94
IRR_NV_read_stencil, // part of 94
IRR_NV_texture_compression_s3tc_update, // 95
IRR_NV_texture_npot_2D_mipmap, // 96
IRR_OES_blend_equation_separate, // 1
IRR_OES_blend_func_separate, // 2
IRR_OES_blend_subtract, // 3
IRR_OES_byte_coordinates, // 4
IRR_OES_compressed_ETC1_RGB8_texture, // 5
IRR_OES_compressed_paletted_texture, // 6
IRR_OES_depth24, // 24
IRR_OES_depth32, // 25
IRR_OES_depth_texture, // 43
IRR_OES_draw_texture, // 7
IRR_OES_EGL_image, // 23
IRR_OES_EGL_image_external, // 87
IRR_OES_EGL_sync, // 75
IRR_OES_element_index_uint, // 26
IRR_OES_extended_matrix_palette, // 8
IRR_OES_fbo_render_mipmap, // 27
IRR_OES_fixed_point, // 9
IRR_OES_fragment_precision_high, // 28
IRR_OES_framebuffer_object, // 10
IRR_OES_get_program_binary, // 47
IRR_OES_mapbuffer, // 29
IRR_OES_matrix_get, // 11
IRR_OES_matrix_palette, // 12
IRR_OES_packed_depth_stencil, // 44
IRR_OES_point_size_array, // 14
IRR_OES_point_sprite, // 15
IRR_OES_query_matrix, // 16
IRR_OES_read_format, // 17
IRR_OES_required_internalformat, // 115
IRR_OES_rgb8_rgba8, // 30
IRR_OES_single_precision, // 18
IRR_OES_standard_derivatives, // 45
IRR_OES_stencil1, // 31
IRR_OES_stencil4, // 32
IRR_OES_stencil8, // 33
IRR_OES_stencil_wrap, // 19
IRR_OES_surfaceless_context, // 116
IRR_OES_texture_3D, // 34
IRR_OES_texture_cube_map, // 20
IRR_OES_texture_env_crossbar, // 21
IRR_OES_texture_float, // 36
IRR_OES_texture_float_linear, // 35
IRR_OES_texture_half_float, // 36
IRR_OES_texture_half_float_linear, // 35
IRR_OES_texture_mirrored_repeat, // 22
IRR_OES_texture_npot, // 37
IRR_OES_vertex_array_object, // 71
IRR_OES_vertex_half_float, // 38
IRR_OES_vertex_type_10_10_10_2, // 46
IRR_QCOM_alpha_test, // 89
IRR_QCOM_binning_control, // 119
IRR_QCOM_driver_control, // 55
IRR_QCOM_extended_get, // 62
IRR_QCOM_extended_get2, // 63
IRR_QCOM_performance_monitor_global_mode, // 56
IRR_QCOM_tiled_rendering, // 70
IRR_QCOM_writeonly_rendering, // 61
IRR_SUN_multi_draw_arrays, // 69
IRR_VIV_shader_binary, // 85
IRR_OGLES2_Feature_Count
};
//! queries the features of the driver, returns true if feature is available
bool queryOpenGLFeature(EOGLES2Features feature) const
{
return FeatureAvailable[feature];
}
protected:
COGLES2ExtensionHandler();
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
{
switch (feature)
{
case EVDF_RENDER_TO_TARGET:
case EVDF_HARDWARE_TL:
case EVDF_MULTITEXTURE:
case EVDF_BILINEAR_FILTER:
case EVDF_MIP_MAP:
case EVDF_MIP_MAP_AUTO_UPDATE:
case EVDF_VERTEX_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_1:
case EVDF_PIXEL_SHADER_1_2:
case EVDF_PIXEL_SHADER_2_0:
case EVDF_VERTEX_SHADER_2_0:
case EVDF_ARB_GLSL:
case EVDF_TEXTURE_NSQUARE:
case EVDF_TEXTURE_NPOT:
case EVDF_FRAMEBUFFER_OBJECT:
case EVDF_VERTEX_BUFFER_OBJECT:
case EVDF_COLOR_MASK:
case EVDF_ALPHA_TO_COVERAGE:
case EVDF_POLYGON_OFFSET:
case EVDF_TEXTURE_MATRIX:
return true;
case EVDF_ARB_VERTEX_PROGRAM_1:
case EVDF_ARB_FRAGMENT_PROGRAM_1:
case EVDF_GEOMETRY_SHADER:
case EVDF_MULTIPLE_RENDER_TARGETS:
case EVDF_MRT_BLEND:
case EVDF_MRT_COLOR_MASK:
case EVDF_MRT_BLEND_FUNC:
case EVDF_OCCLUSION_QUERY:
return false;
case EVDF_BLEND_OPERATIONS:
return false;
case EVDF_TEXTURE_COMPRESSED_DXT:
return false; // NV Tegra need improvements here
case EVDF_STENCIL_BUFFER:
return StencilBuffer;
default:
return false;
};
}
void dump() const;
void initExtensions(COGLES2Driver* driver,
#ifdef EGL_VERSION_1_0
EGLDisplay display,
#endif
bool withStencil);
protected:
u16 EGLVersion;
u16 Version;
u8 MaxTextureUnits;
u8 MaxSupportedTextures;
u8 MaxAnisotropy;
u32 MaxIndices;
u32 MaxTextureSize;
f32 MaxTextureLODBias;
//! Minimal and maximal supported thickness for lines without smoothing
GLfloat DimAliasedLine[2];
//! Minimal and maximal supported thickness for points without smoothing
GLfloat DimAliasedPoint[2];
bool StencilBuffer;
bool FeatureAvailable[IRR_OGLES2_Feature_Count];
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES2_
#endif

View File

@ -0,0 +1,173 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2FixedPipelineRenderer.h"
#include "IGPUProgrammingServices.h"
#include "os.h"
#include "COGLES2Driver.h"
namespace irr
{
namespace video
{
//! Constructor
COGLES2FixedPipelineRenderer::COGLES2FixedPipelineRenderer(const c8* vertexShaderProgram,
const c8* pixelShaderProgram, E_MATERIAL_TYPE baseMaterial,
COGLES2Driver* driver)
: COGLES2MaterialRenderer(driver, 0, baseMaterial)
{
#ifdef _DEBUG
setDebugName("COGLES2FixedPipelineRenderer");
#endif
yy = (int)baseMaterial;
int Temp = 0;
SharedRenderer = reinterpret_cast<COGLES2MaterialRenderer*>(driver->getMaterialRenderer(EMT_SOLID));
if (SharedRenderer)
SharedRenderer->grab();
else
init(Temp, vertexShaderProgram, pixelShaderProgram, false);
}
//! Destructor
COGLES2FixedPipelineRenderer::~COGLES2FixedPipelineRenderer()
{
if(SharedRenderer)
SharedRenderer->drop();
}
void COGLES2FixedPipelineRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
if (SharedRenderer)
Driver->getBridgeCalls()->setProgram(SharedRenderer->getProgram());
else
Driver->getBridgeCalls()->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (FixedBlending)
{
Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
Driver->getBridgeCalls()->setBlend(true);
}
else if (Blending)
{
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam);
Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact));
Driver->getBridgeCalls()->setBlend(true);
}
else
Driver->getBridgeCalls()->setBlend(false);
}
bool COGLES2FixedPipelineRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (SharedRenderer)
return SharedRenderer->OnRender(service, vtxtype);
else
{
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
s32 materialType = 0;
switch(Driver->getCurrentMaterial().MaterialType)
{
case EMT_SOLID_2_LAYER:
materialType = 1;
break;
case EMT_LIGHTMAP:
case EMT_LIGHTMAP_ADD:
case EMT_LIGHTMAP_M2:
case EMT_LIGHTMAP_M4:
case EMT_LIGHTMAP_LIGHTING:
case EMT_LIGHTMAP_LIGHTING_M2:
case EMT_LIGHTMAP_LIGHTING_M4:
materialType = 2;
break;
case EMT_DETAIL_MAP:
materialType = 3;
break;
case EMT_SPHERE_MAP:
materialType = 4;
break;
case EMT_REFLECTION_2_LAYER:
materialType = 5;
break;
case EMT_TRANSPARENT_ALPHA_CHANNEL:
materialType = 6;
break;
case EMT_TRANSPARENT_ALPHA_CHANNEL_REF:
materialType = 7;
break;
case EMT_TRANSPARENT_VERTEX_ALPHA:
materialType = 8;
break;
case EMT_TRANSPARENT_REFLECTION_2_LAYER:
materialType = 9;
break;
default:
break;
}
IMaterialRendererServices::setPixelShaderConstant("uMaterialType", &materialType, 1);
/* Transform Matrices Upload */
core::matrix4 world = Driver->getTransform(ETS_WORLD);
IMaterialRendererServices::setPixelShaderConstant("uWorldMatrix", world.pointer(), 16);
core::matrix4 worldViewProj = Driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= Driver->getTransform(video::ETS_VIEW);
worldViewProj *= Driver->getTransform(ETS_WORLD);
IMaterialRendererServices::setPixelShaderConstant("uMvpMatrix", worldViewProj.pointer(), 16);
/* Textures Upload */
s32 TextureUsage0 = Driver->isActiveTexture(0);
s32 TextureUsage1 = Driver->isActiveTexture(1);
IMaterialRendererServices::setPixelShaderConstant("uTextureUsage0", &TextureUsage0, 1);
IMaterialRendererServices::setPixelShaderConstant("uTextureUsage1", &TextureUsage1, 1);
core::matrix4 textureMatrix0 = Driver->getTransform(video::ETS_TEXTURE_0);
core::matrix4 textureMatrix1 = Driver->getTransform(video::ETS_TEXTURE_0);
IMaterialRendererServices::setPixelShaderConstant("uTextureMatrix0", textureMatrix0.pointer(), 16);
IMaterialRendererServices::setPixelShaderConstant("uTextureMatrix1", textureMatrix1.pointer(), 16);
s32 TextureUnit0 = 0;
s32 TextureUnit1 = 1;
IMaterialRendererServices::setPixelShaderConstant("uTextureUnit0", &TextureUnit0, 1);
IMaterialRendererServices::setPixelShaderConstant("uTextureUnit1", &TextureUnit1, 1);
return true;
}
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -0,0 +1,49 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_FIXED_PIPELINE_SHADER_H_INCLUDED__
#define __C_OGLES2_FIXED_PIPELINE_SHADER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2MaterialRenderer.h"
namespace irr
{
namespace video
{
//! Class for rendering fixed pipeline stuff with OpenGL ES 2.0
class COGLES2FixedPipelineRenderer : public COGLES2MaterialRenderer
{
public:
//! Constructor
COGLES2FixedPipelineRenderer(const c8* vertexShaderProgram,
const c8* pixelShaderProgram, E_MATERIAL_TYPE baseMaterial,
COGLES2Driver* driver);
//! Destructor
~COGLES2FixedPipelineRenderer();
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
protected:
int yy;
COGLES2MaterialRenderer* SharedRenderer;
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -0,0 +1,461 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2MaterialRenderer.h"
#include "IGPUProgrammingServices.h"
#include "IShaderConstantSetCallBack.h"
#include "IMaterialRendererServices.h"
#include "IVideoDriver.h"
#include "os.h"
#include "COGLES2Driver.h"
#include "COGLES2MaterialRenderer.h"
namespace irr
{
namespace video
{
//! Constructor
COGLES2MaterialRenderer::COGLES2MaterialRenderer(COGLES2Driver* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
: Driver(driver), CallBack(callback), Program(0), Alpha(false), Blending(false), FixedBlending(false), UserData(userData)
{
#ifdef _DEBUG
setDebugName("COGLES2MaterialRenderer");
#endif
if (baseMaterial == EMT_TRANSPARENT_VERTEX_ALPHA || baseMaterial == EMT_TRANSPARENT_ALPHA_CHANNEL ||
baseMaterial == EMT_TRANSPARENT_ALPHA_CHANNEL_REF || baseMaterial == EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA ||
baseMaterial == EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA)
{
Alpha = true;
}
else if (baseMaterial == EMT_TRANSPARENT_ADD_COLOR || baseMaterial == EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR ||
baseMaterial == EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR)
{
FixedBlending = true;
}
else if (baseMaterial == EMT_ONETEXTURE_BLEND)
Blending = true;
if (CallBack)
CallBack->grab();
init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram);
}
//! constructor only for use by derived classes who want to
//! create a fall back material for example.
COGLES2MaterialRenderer::COGLES2MaterialRenderer(COGLES2Driver* driver,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial, s32 userData)
: Driver(driver), CallBack(callback), Program(0), Alpha(false), Blending(false), FixedBlending(false), UserData(userData)
{
if (baseMaterial == EMT_TRANSPARENT_VERTEX_ALPHA || baseMaterial == EMT_TRANSPARENT_ALPHA_CHANNEL ||
baseMaterial == EMT_TRANSPARENT_ALPHA_CHANNEL_REF || baseMaterial == EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA ||
baseMaterial == EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA)
{
Alpha = true;
}
else if (baseMaterial == EMT_TRANSPARENT_ADD_COLOR || baseMaterial == EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR ||
baseMaterial == EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR)
{
FixedBlending = true;
}
else if (baseMaterial == EMT_ONETEXTURE_BLEND)
Blending = true;
if (CallBack)
CallBack->grab();
}
//! Destructor
COGLES2MaterialRenderer::~COGLES2MaterialRenderer()
{
if (CallBack)
CallBack->drop();
if (Program)
{
GLuint shaders[8];
GLint count;
glGetAttachedShaders(Program, 8, &count, shaders);
count=core::min_(count,8);
for (GLint i=0; i<count; ++i)
glDeleteShader(shaders[i]);
glDeleteProgram(Program);
Program = 0;
}
UniformInfo.clear();
}
GLuint COGLES2MaterialRenderer::getProgram() const
{
return Program;
}
void COGLES2MaterialRenderer::init(s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
bool addMaterial)
{
outMaterialTypeNr = -1;
Program = glCreateProgram();
if (!Program)
return;
if (vertexShaderProgram)
if (!createShader(GL_VERTEX_SHADER, vertexShaderProgram))
return;
if (pixelShaderProgram)
if (!createShader(GL_FRAGMENT_SHADER, pixelShaderProgram))
return;
for ( size_t i = 0; i < EVA_COUNT; ++i )
glBindAttribLocation( Program, i, sBuiltInVertexAttributeNames[i]);
if (!linkProgram())
return;
// register myself as new material
if (addMaterial)
outMaterialTypeNr = Driver->addMaterialRenderer(this);
}
bool COGLES2MaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
// call callback to set shader constants
if (CallBack && Program)
CallBack->OnSetConstants(this, UserData);
return true;
}
void COGLES2MaterialRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
Driver->getBridgeCalls()->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (FixedBlending)
{
Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
Driver->getBridgeCalls()->setBlend(true);
}
else if (Blending)
{
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam);
Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact));
Driver->getBridgeCalls()->setBlend(true);
}
else
Driver->getBridgeCalls()->setBlend(false);
if (CallBack)
CallBack->OnSetMaterial(material);
}
void COGLES2MaterialRenderer::OnUnsetMaterial()
{
}
//! Returns if the material is transparent.
bool COGLES2MaterialRenderer::isTransparent() const
{
return (Alpha || Blending || FixedBlending);
}
bool COGLES2MaterialRenderer::createShader(GLenum shaderType, const char* shader)
{
if (Program)
{
GLuint shaderHandle = glCreateShader(shaderType);
glShaderSource(shaderHandle, 1, &shader, NULL);
glCompileShader(shaderHandle);
GLint status = 0;
glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE)
{
os::Printer::log("GLSL shader failed to compile", ELL_ERROR);
// check error message and log it
GLint maxLength=0;
GLint length;
glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH,
&maxLength);
if (maxLength)
{
GLchar *infoLog = new GLchar[maxLength];
glGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog);
os::Printer::log(reinterpret_cast<const c8*>(infoLog), ELL_ERROR);
delete [] infoLog;
}
return false;
}
glAttachShader(Program, shaderHandle);
}
return true;
}
bool COGLES2MaterialRenderer::linkProgram()
{
if (Program)
{
glLinkProgram(Program);
GLint status = 0;
glGetProgramiv(Program, GL_LINK_STATUS, &status);
if (!status)
{
os::Printer::log("GLSL shader program failed to link", ELL_ERROR);
// check error message and log it
GLint maxLength=0;
GLsizei length;
glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength);
if (maxLength)
{
GLchar *infoLog = new GLchar[maxLength];
glGetProgramInfoLog(Program, maxLength, &length, infoLog);
os::Printer::log(reinterpret_cast<const c8*>(infoLog), ELL_ERROR);
delete [] infoLog;
}
return false;
}
// get uniforms information
GLint num = 0;
glGetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num);
if (num == 0)
{
// no uniforms
return true;
}
GLint maxlen = 0;
glGetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen);
if (maxlen == 0)
{
os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR);
return false;
}
// seems that some implementations use an extra null terminator
++maxlen;
c8 *buf = new c8[maxlen];
UniformInfo.clear();
UniformInfo.reallocate(num);
for (GLint i=0; i < num; ++i)
{
SUniformInfo ui;
memset(buf, 0, maxlen);
GLint size;
glGetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar*>(buf));
ui.name = buf;
ui.location = glGetUniformLocation(Program, buf);
UniformInfo.push_back(ui);
}
delete [] buf;
}
return true;
}
void COGLES2MaterialRenderer::setBasicRenderStates(const SMaterial& material,
const SMaterial& lastMaterial,
bool resetAllRenderstates)
{
// forward
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
s32 COGLES2MaterialRenderer::getVertexShaderConstantID(const c8* name)
{
return getPixelShaderConstantID(name);
}
s32 COGLES2MaterialRenderer::getPixelShaderConstantID(const c8* name)
{
for (u32 i = 0; i < UniformInfo.size(); ++i)
{
if (UniformInfo[i].name == name)
return i;
}
return -1;
}
void COGLES2MaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
}
void COGLES2MaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
os::Printer::log("Cannot set constant, use high level shader call.", ELL_WARNING);
}
bool COGLES2MaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
return setPixelShaderConstant(index, floats, count);
}
bool COGLES2MaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
return setPixelShaderConstant(index, ints, count);
}
bool COGLES2MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
if(index < 0 || UniformInfo[index].location < 0)
return false;
bool status = true;
switch (UniformInfo[index].type)
{
case GL_FLOAT:
glUniform1fv(UniformInfo[index].location, count, floats);
break;
case GL_FLOAT_VEC2:
glUniform2fv(UniformInfo[index].location, count/2, floats);
break;
case GL_FLOAT_VEC3:
glUniform3fv(UniformInfo[index].location, count/3, floats);
break;
case GL_FLOAT_VEC4:
glUniform4fv(UniformInfo[index].location, count/4, floats);
break;
case GL_FLOAT_MAT2:
glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats);
break;
case GL_FLOAT_MAT3:
glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats);
break;
case GL_FLOAT_MAT4:
glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
{
if(floats)
{
const GLint id = (GLint)(*floats);
glUniform1iv(UniformInfo[index].location, 1, &id);
}
else
status = false;
}
break;
default:
status = false;
break;
}
return status;
}
bool COGLES2MaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
if(index < 0 || UniformInfo[index].location < 0)
return false;
bool status = true;
switch (UniformInfo[index].type)
{
case GL_INT:
case GL_BOOL:
glUniform1iv(UniformInfo[index].location, count, ints);
break;
case GL_INT_VEC2:
case GL_BOOL_VEC2:
glUniform2iv(UniformInfo[index].location, count/2, ints);
break;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
glUniform3iv(UniformInfo[index].location, count/3, ints);
break;
case GL_INT_VEC4:
case GL_BOOL_VEC4:
glUniform4iv(UniformInfo[index].location, count/4, ints);
break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
glUniform1iv(UniformInfo[index].location, 1, ints);
break;
default:
status = false;
break;
}
return status;
}
IVideoDriver* COGLES2MaterialRenderer::getVideoDriver()
{
return Driver;
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -0,0 +1,122 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_SL_MATERIAL_RENDERER_H_INCLUDED__
#define __C_OGLES2_SL_MATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#else
#include <GLES2/gl2.h>
#include <EGL/eglplatform.h>
#endif
#include "EMaterialTypes.h"
#include "EVertexAttributes.h"
#include "IMaterialRenderer.h"
#include "IMaterialRendererServices.h"
#include "IGPUProgrammingServices.h"
#include "IShaderConstantSetCallBack.h"
#include "irrArray.h"
#include "irrString.h"
namespace irr
{
namespace video
{
class COGLES2Driver;
//! Class for using GLSL shaders with OpenGL ES 2.0
//! Please note: This renderer implements its own IMaterialRendererServices
class COGLES2MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
{
public:
//! Constructor
COGLES2MaterialRenderer(
COGLES2Driver* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram = 0,
const c8* pixelShaderProgram = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
//! Destructor
virtual ~COGLES2MaterialRenderer();
GLuint getProgram() const;
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
virtual void OnUnsetMaterial();
//! Returns if the material is transparent.
virtual bool isTransparent() const;
// implementations for the render services
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates);
virtual s32 getVertexShaderConstantID(const c8* name);
virtual s32 getPixelShaderConstantID(const c8* name);
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
virtual IVideoDriver* getVideoDriver();
protected:
//! constructor only for use by derived classes who want to
//! create a fall back material for example.
COGLES2MaterialRenderer(COGLES2Driver* driver,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
s32 userData = 0);
void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true);
bool createShader(GLenum shaderType, const char* shader);
bool linkProgram();
COGLES2Driver* Driver;
IShaderConstantSetCallBack* CallBack;
bool Alpha;
bool Blending;
bool FixedBlending;
struct SUniformInfo
{
core::stringc name;
GLenum type;
GLint location;
};
GLuint Program;
core::array<SUniformInfo> UniformInfo;
s32 UserData;
};
} // end namespace video
} // end namespace irr
#endif // compile with OpenGL ES 2.0
#endif // if included

View File

@ -0,0 +1,80 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2NormalMapRenderer.h"
#include "IGPUProgrammingServices.h"
#include "os.h"
#include "COGLES2Driver.h"
namespace irr
{
namespace video
{
//! Constructor
COGLES2NormalMapRenderer::COGLES2NormalMapRenderer(const c8* vertexShaderProgram,
const c8* pixelShaderProgram, E_MATERIAL_TYPE baseMaterial,
COGLES2Driver* driver)
: COGLES2MaterialRenderer(driver, 0, baseMaterial)
{
#ifdef _DEBUG
setDebugName("COGLES2NormalMapRenderer");
#endif
int Temp = 0;
SharedRenderer = reinterpret_cast<COGLES2MaterialRenderer*>(driver->getMaterialRenderer(EMT_NORMAL_MAP_SOLID));
if (SharedRenderer)
SharedRenderer->grab();
else
init(Temp, vertexShaderProgram, pixelShaderProgram, false);
}
//! Destructor
COGLES2NormalMapRenderer::~COGLES2NormalMapRenderer()
{
if(SharedRenderer)
SharedRenderer->drop();
}
void COGLES2NormalMapRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
if (SharedRenderer)
SharedRenderer->OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
else
COGLES2MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
}
bool COGLES2NormalMapRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (SharedRenderer)
return SharedRenderer->OnRender(service, vtxtype);
else
{
/* Vertex Shader part */
return true;
}
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -0,0 +1,50 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_NORMAL_MAP_RENDERER_H_INCLUDED__
#define __C_OGLES2_NORMAL_MAP_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2MaterialRenderer.h"
namespace irr
{
namespace video
{
//! Class for normal mapping in OpenGL ES 2.0
class COGLES2NormalMapRenderer : public COGLES2MaterialRenderer
{
public:
//! Constructor
COGLES2NormalMapRenderer(const c8* vertexShaderProgram,
const c8* pixelShaderProgram, E_MATERIAL_TYPE baseMaterial,
COGLES2Driver* driver);
//! Destructor
~COGLES2NormalMapRenderer();
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
protected:
COGLES2MaterialRenderer* SharedRenderer;
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -0,0 +1,80 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2ParallaxMapRenderer.h"
#include "IGPUProgrammingServices.h"
#include "os.h"
#include "COGLES2Driver.h"
namespace irr
{
namespace video
{
//! Constructor
COGLES2ParallaxMapRenderer::COGLES2ParallaxMapRenderer(const c8* vertexShaderProgram,
const c8* pixelShaderProgram, E_MATERIAL_TYPE baseMaterial,
COGLES2Driver* driver)
: COGLES2MaterialRenderer(driver, 0, baseMaterial)
{
#ifdef _DEBUG
setDebugName("COGLES2ParallaxMapRenderer");
#endif
int Temp = 0;
SharedRenderer = reinterpret_cast<COGLES2MaterialRenderer*>(driver->getMaterialRenderer(EMT_PARALLAX_MAP_SOLID));
if (SharedRenderer)
SharedRenderer->grab();
else
init(Temp, vertexShaderProgram, pixelShaderProgram, false);
}
//! Destructor
COGLES2ParallaxMapRenderer::~COGLES2ParallaxMapRenderer()
{
if(SharedRenderer)
SharedRenderer->drop();
}
void COGLES2ParallaxMapRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
if (SharedRenderer)
SharedRenderer->OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
else
COGLES2MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
}
bool COGLES2ParallaxMapRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (SharedRenderer)
return SharedRenderer->OnRender(service, vtxtype);
else
{
/* Vertex Shader part */
return true;
}
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -0,0 +1,51 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_PARALLAX_MAP_RENDERER_H_INCLUDED__
#define __C_OGLES2_PARALLAX_MAP_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2MaterialRenderer.h"
namespace irr
{
namespace video
{
//! Class for parallax mapping in OpenGL ES 2.0
class COGLES2ParallaxMapRenderer : public COGLES2MaterialRenderer
{
public:
//! Constructor
COGLES2ParallaxMapRenderer(const c8* vertexShaderProgram,
const c8* pixelShaderProgram, E_MATERIAL_TYPE baseMaterial,
COGLES2Driver* driver);
//! Destructor
~COGLES2ParallaxMapRenderer();
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
protected:
COGLES2MaterialRenderer* SharedRenderer;
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -0,0 +1,100 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2Renderer2D.h"
#include "IGPUProgrammingServices.h"
#include "os.h"
#include "COGLES2Driver.h"
namespace irr
{
namespace video
{
//! Constructor
COGLES2Renderer2D::COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver)
: COGLES2MaterialRenderer(driver, 0, EMT_SOLID), RenderTargetSize(core::dimension2d<u32>(0,0)),
Matrix(core::matrix4::EM4CONST_NOTHING), Texture(0)
{
#ifdef _DEBUG
setDebugName("COGLES2Renderer2D");
#endif
int Temp = 0;
init(Temp, vertexShaderProgram, pixelShaderProgram, false);
Driver->getBridgeCalls()->setProgram(Program);
// These states doesn't change later.
MatrixID = getPixelShaderConstantID("uOrthoMatrix");
UseTextureID = getPixelShaderConstantID("uUseTexture");
s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit");
int TextureUnit = 0;
setPixelShaderConstant(TextureUnitID, &TextureUnit, 1);
Driver->getBridgeCalls()->setProgram(0);
}
//! Destructor
COGLES2Renderer2D::~COGLES2Renderer2D()
{
}
void COGLES2Renderer2D::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates,
video::IMaterialRendererServices* services)
{
Driver->getBridgeCalls()->setProgram(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
bool COGLES2Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);
const core::dimension2d<u32>& renderTargetSize = Driver->getCurrentRenderTargetSize();
if (RenderTargetSize != renderTargetSize)
{
Matrix.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f);
Matrix.setTranslation(core::vector3df(-1,1,0));
setPixelShaderConstant(MatrixID, Matrix.pointer(), 16);
RenderTargetSize = renderTargetSize;
}
int UseTexture = Texture ? 1 : 0;
setPixelShaderConstant(UseTextureID, &UseTexture, 1);
return true;
}
void COGLES2Renderer2D::setTexture(const ITexture* texture)
{
Texture = texture;
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -0,0 +1,56 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_RENDERER_2D_H_INCLUDED__
#define __C_OGLES2_RENDERER_2D_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "COGLES2MaterialRenderer.h"
namespace irr
{
namespace video
{
//! Class for renderer 2D in OpenGL ES 2.0
class COGLES2Renderer2D : public COGLES2MaterialRenderer
{
public:
//! Constructor
COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver);
//! Destructor
~COGLES2Renderer2D();
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services);
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
void setTexture(const ITexture* texture);
protected:
core::dimension2d<u32> RenderTargetSize;
core::matrix4 Matrix;
const ITexture* Texture;
s32 MatrixID;
s32 UseTextureID;
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -0,0 +1,771 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "irrTypes.h"
#include "COGLES2Texture.h"
#include "COGLES2Driver.h"
#include "os.h"
#include "CImage.h"
#include "CColorConverter.h"
#include "irrString.h"
#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#endif
namespace
{
#ifndef GL_BGRA
// we need to do this for the IMG_BGRA8888 extension
int GL_BGRA=GL_RGBA;
#endif
}
namespace irr
{
namespace video
{
//! constructor for usual textures
COGLES2Texture::COGLES2Texture(IImage* origImage, const io::path& name, void* mipmapData, COGLES2Driver* driver)
: ITexture(name), ColorFormat(ECF_A8R8G8B8), Driver(driver), Image(0), MipImage(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0),
IsRenderTarget(false), AutomaticMipmapUpdate(false),
ReadOnlyLock(false), KeepImage(true)
{
#ifdef _DEBUG
setDebugName("COGLES2Texture");
#endif
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
getImageValues(origImage);
glGenTextures(1, &TextureName);
if (ImageSize==TextureSize)
{
Image = Driver->createImage(ColorFormat, ImageSize);
origImage->copyTo(Image);
}
else
{
Image = Driver->createImage(ColorFormat, TextureSize);
// scale texture
origImage->copyToScaling(Image);
}
uploadTexture(true, mipmapData);
if (!KeepImage)
{
Image->drop();
Image=0;
}
}
//! constructor for basic setup (only for derived classes)
COGLES2Texture::COGLES2Texture(const io::path& name, COGLES2Driver* driver)
: ITexture(name), ColorFormat(ECF_A8R8G8B8), Driver(driver), Image(0), MipImage(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT),
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0), HasMipMaps(true),
IsRenderTarget(false), AutomaticMipmapUpdate(false),
ReadOnlyLock(false), KeepImage(true)
{
#ifdef _DEBUG
setDebugName("COGLES2Texture");
#endif
}
//! destructor
COGLES2Texture::~COGLES2Texture()
{
if (TextureName)
glDeleteTextures(1, &TextureName);
if (Image)
Image->drop();
}
//! Choose best matching color format, based on texture creation flags
ECOLOR_FORMAT COGLES2Texture::getBestColorFormat(ECOLOR_FORMAT format)
{
ECOLOR_FORMAT destFormat = ECF_A8R8G8B8;
switch (format)
{
case ECF_A1R5G5B5:
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
destFormat = ECF_A1R5G5B5;
break;
case ECF_R5G6B5:
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
destFormat = ECF_A1R5G5B5;
break;
case ECF_A8R8G8B8:
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) ||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
destFormat = ECF_A1R5G5B5;
break;
case ECF_R8G8B8:
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) ||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
destFormat = ECF_A1R5G5B5;
default:
break;
}
if (Driver->getTextureCreationFlag(ETCF_NO_ALPHA_CHANNEL))
{
switch (destFormat)
{
case ECF_A1R5G5B5:
destFormat = ECF_R5G6B5;
break;
case ECF_A8R8G8B8:
destFormat = ECF_R8G8B8;
break;
default:
break;
}
}
return destFormat;
}
// prepare values ImageSize, TextureSize, and ColorFormat based on image
void COGLES2Texture::getImageValues(IImage* image)
{
if (!image)
{
os::Printer::log("No image for OpenGL texture.", ELL_ERROR);
return;
}
ImageSize = image->getDimension();
if ( !ImageSize.Width || !ImageSize.Height)
{
os::Printer::log("Invalid size of image for OpenGL Texture.", ELL_ERROR);
return;
}
const f32 ratio = (f32)ImageSize.Width/(f32)ImageSize.Height;
if ((ImageSize.Width>Driver->MaxTextureSize) && (ratio >= 1.0f))
{
ImageSize.Width = Driver->MaxTextureSize;
ImageSize.Height = (u32)(Driver->MaxTextureSize/ratio);
}
else if (ImageSize.Height>Driver->MaxTextureSize)
{
ImageSize.Height = Driver->MaxTextureSize;
ImageSize.Width = (u32)(Driver->MaxTextureSize*ratio);
}
TextureSize=ImageSize.getOptimalSize(false);
ColorFormat = getBestColorFormat(image->getColorFormat());
}
//! copies the the texture into an open gl texture.
void COGLES2Texture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
{
// check which image needs to be uploaded
IImage* image = level?MipImage:Image;
if (!image)
{
os::Printer::log("No image for OGLES2 texture to upload", ELL_ERROR);
return;
}
#ifndef GL_BGRA
// whoa, pretty badly implemented extension...
if (Driver->FeatureAvailable[COGLES2ExtensionHandler::IRR_IMG_texture_format_BGRA8888] || Driver->FeatureAvailable[COGLES2ExtensionHandler::IRR_EXT_texture_format_BGRA8888])
GL_BGRA=0x80E1;
else
GL_BGRA=GL_RGBA;
#endif
GLenum oldInternalFormat = InternalFormat;
void(*convert)(const void*, s32, void*)=0;
switch (Image->getColorFormat())
{
case ECF_A1R5G5B5:
InternalFormat=GL_RGBA;
PixelFormat=GL_RGBA;
PixelType=GL_UNSIGNED_SHORT_5_5_5_1;
convert=CColorConverter::convert_A1R5G5B5toR5G5B5A1;
break;
case ECF_R5G6B5:
InternalFormat=GL_RGB;
PixelFormat=GL_RGB;
PixelType=GL_UNSIGNED_SHORT_5_6_5;
break;
case ECF_R8G8B8:
InternalFormat=GL_RGB;
PixelFormat=GL_RGB;
PixelType=GL_UNSIGNED_BYTE;
convert=CColorConverter::convert_R8G8B8toB8G8R8;
break;
case ECF_A8R8G8B8:
PixelType=GL_UNSIGNED_BYTE;
if (!Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_IMG_texture_format_BGRA8888) && !Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_EXT_texture_format_BGRA8888))
{
convert=CColorConverter::convert_A8R8G8B8toA8B8G8R8;
InternalFormat=GL_RGBA;
PixelFormat=GL_RGBA;
}
else
{
InternalFormat=GL_BGRA;
PixelFormat=GL_BGRA;
}
break;
default:
os::Printer::log("Unsupported texture format", ELL_ERROR);
break;
}
// Hack for iPhone SDK, which requires a different InternalFormat
#ifdef _IRR_IPHONE_PLATFORM_
if (InternalFormat==GL_BGRA)
InternalFormat=GL_RGBA;
#endif
// make sure we don't change the internal format of existing matrices
if (!newTexture)
InternalFormat=oldInternalFormat;
Driver->setActiveTexture(0, this);
Driver->getBridgeCalls()->setTexture(0);
if (Driver->testGLError())
os::Printer::log("Could not bind Texture", ELL_ERROR);
// mipmap handling for main texture
if (!level && newTexture)
{
#ifndef DISABLE_MIPMAPPING
// auto generate if possible and no mipmap data is given
if (HasMipMaps && !mipmapData)
{
if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY))
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
else
glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
AutomaticMipmapUpdate=true;
}
else
{
// Either generate manually due to missing capability
// or use predefined mipmap data
AutomaticMipmapUpdate=false;
regenerateMipMapLevels(mipmapData);
}
if (HasMipMaps) // might have changed in regenerateMipMapLevels
{
// enable bilinear mipmap filter
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
StatesCache.BilinearFilter = true;
StatesCache.TrilinearFilter = false;
StatesCache.MipMapStatus = true;
}
else
#else
HasMipMaps=false;
os::Printer::log("Did not create OpenGL texture mip maps.", ELL_INFORMATION);
#endif
{
// enable bilinear filter without mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
StatesCache.BilinearFilter = true;
StatesCache.TrilinearFilter = false;
StatesCache.MipMapStatus = false;
}
}
// now get image data and upload to GPU
void* source = image->lock();
IImage* tmpImage=0;
if (convert)
{
tmpImage = new CImage(image->getColorFormat(), image->getDimension());
void* dest = tmpImage->lock();
convert(source, image->getDimension().getArea(), dest);
image->unlock();
source = dest;
}
if (newTexture)
glTexImage2D(GL_TEXTURE_2D, level, InternalFormat, image->getDimension().Width,
image->getDimension().Height, 0, PixelFormat, PixelType, source);
else
glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width,
image->getDimension().Height, PixelFormat, PixelType, source);
if (convert)
{
tmpImage->unlock();
tmpImage->drop();
}
else
image->unlock();
if (AutomaticMipmapUpdate)
glGenerateMipmap(GL_TEXTURE_2D);
if (Driver->testGLError())
os::Printer::log("Could not glTexImage2D", ELL_ERROR);
}
//! lock function
void* COGLES2Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
{
// store info about which image is locked
IImage* image = (mipmapLevel==0)?Image:MipImage;
return image->lock();
}
//! unlock function
void COGLES2Texture::unlock()
{
// test if miplevel or main texture was locked
IImage* image = MipImage?MipImage:Image;
if (!image)
return;
// unlock image to see changes
image->unlock();
// copy texture data to GPU
if (!ReadOnlyLock)
uploadTexture(false, 0, MipLevelStored);
ReadOnlyLock = false;
// cleanup local image
if (MipImage)
{
MipImage->drop();
MipImage=0;
}
else if (!KeepImage)
{
Image->drop();
Image=0;
}
// update information
if (Image)
ColorFormat=Image->getColorFormat();
else
ColorFormat=ECF_A8R8G8B8;
}
//! Returns size of the original image.
const core::dimension2d<u32>& COGLES2Texture::getOriginalSize() const
{
return ImageSize;
}
//! Returns size of the texture.
const core::dimension2d<u32>& COGLES2Texture::getSize() const
{
return TextureSize;
}
//! returns driver type of texture, i.e. the driver, which created the texture
E_DRIVER_TYPE COGLES2Texture::getDriverType() const
{
return EDT_OGLES2;
}
//! returns color format of texture
ECOLOR_FORMAT COGLES2Texture::getColorFormat() const
{
return ColorFormat;
}
//! returns pitch of texture (in bytes)
u32 COGLES2Texture::getPitch() const
{
if (Image)
return Image->getPitch();
else
return 0;
}
//! return open gl texture name
GLuint COGLES2Texture::getOpenGLTextureName() const
{
return TextureName;
}
//! Returns whether this texture has mipmaps
bool COGLES2Texture::hasMipMaps() const
{
return HasMipMaps;
}
//! Regenerates the mip map levels of the texture. Useful after locking and
//! modifying the texture
void COGLES2Texture::regenerateMipMapLevels(void* mipmapData)
{
if (AutomaticMipmapUpdate || !HasMipMaps || !Image)
return;
if ((Image->getDimension().Width==1) && (Image->getDimension().Height==1))
return;
// Manually create mipmaps or use prepared version
u32 width=Image->getDimension().Width;
u32 height=Image->getDimension().Height;
u32 i=0;
u8* target = static_cast<u8*>(mipmapData);
do
{
if (width>1)
width>>=1;
if (height>1)
height>>=1;
++i;
if (!target)
target = new u8[width*height*Image->getBytesPerPixel()];
// create scaled version if no mipdata available
if (!mipmapData)
Image->copyToScaling(target, width, height, Image->getColorFormat());
glTexImage2D(GL_TEXTURE_2D, i, InternalFormat, width, height,
0, PixelFormat, PixelType, target);
// get next prepared mipmap data if available
if (mipmapData)
{
mipmapData = static_cast<u8*>(mipmapData)+width*height*Image->getBytesPerPixel();
target = static_cast<u8*>(mipmapData);
}
}
while (width!=1 || height!=1);
// cleanup
if (!mipmapData)
delete [] target;
}
bool COGLES2Texture::isRenderTarget() const
{
return IsRenderTarget;
}
void COGLES2Texture::setIsRenderTarget(bool isTarget)
{
IsRenderTarget = isTarget;
}
bool COGLES2Texture::isFrameBufferObject() const
{
return false;
}
//! Bind Render Target Texture
void COGLES2Texture::bindRTT()
{
}
//! Unbind Render Target Texture
void COGLES2Texture::unbindRTT()
{
}
//! Get an access to texture states cache.
COGLES2Texture::SStatesCache& COGLES2Texture::getStatesCache() const
{
return StatesCache;
}
/* FBO Textures */
// helper function for render to texture
static bool checkOGLES2FBOStatus(COGLES2Driver* Driver);
//! RTT ColorFrameBuffer constructor
COGLES2FBOTexture::COGLES2FBOTexture(const core::dimension2d<u32>& size,
const io::path& name, COGLES2Driver* driver,
ECOLOR_FORMAT format)
: COGLES2Texture(name, driver), DepthTexture(0), ColorFrameBuffer(0)
{
#ifdef _DEBUG
setDebugName("COGLES2Texture_FBO");
#endif
ImageSize = size;
TextureSize = size;
HasMipMaps = false;
IsRenderTarget = true;
ColorFormat = getBestColorFormat(format);
switch (ColorFormat)
{
case ECF_A8R8G8B8:
InternalFormat = GL_RGBA;
PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_BYTE;
break;
case ECF_R8G8B8:
InternalFormat = GL_RGB;
PixelFormat = GL_RGB;
PixelType = GL_UNSIGNED_BYTE;
break;
break;
case ECF_A1R5G5B5:
InternalFormat = GL_RGBA;
PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_SHORT_5_5_5_1;
break;
break;
case ECF_R5G6B5:
InternalFormat = GL_RGB;
PixelFormat = GL_RGB;
PixelType = GL_UNSIGNED_SHORT_5_6_5;
break;
default:
os::Printer::log( "color format not handled", ELL_WARNING );
break;
}
// generate frame buffer
glGenFramebuffers(1, &ColorFrameBuffer);
bindRTT();
// generate color texture
glGenTextures(1, &TextureName);
Driver->setActiveTexture(0, this);
Driver->getBridgeCalls()->setTexture(0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
StatesCache.BilinearFilter = true;
StatesCache.WrapU = ETC_CLAMP_TO_EDGE;
StatesCache.WrapV = ETC_CLAMP_TO_EDGE;
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, ImageSize.Width, ImageSize.Height, 0, PixelFormat, PixelType, 0);
#ifdef _DEBUG
driver->testGLError();
#endif
// attach color texture to frame buffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureName, 0);
#ifdef _DEBUG
checkOGLES2FBOStatus(Driver);
#endif
unbindRTT();
}
//! destructor
COGLES2FBOTexture::~COGLES2FBOTexture()
{
if (DepthTexture)
if (DepthTexture->drop())
Driver->removeDepthTexture(DepthTexture);
if (ColorFrameBuffer)
glDeleteFramebuffers(1, &ColorFrameBuffer);
}
bool COGLES2FBOTexture::isFrameBufferObject() const
{
return true;
}
//! Bind Render Target Texture
void COGLES2FBOTexture::bindRTT()
{
if (ColorFrameBuffer != 0)
glBindFramebuffer(GL_FRAMEBUFFER, ColorFrameBuffer);
}
//! Unbind Render Target Texture
void COGLES2FBOTexture::unbindRTT()
{
if (ColorFrameBuffer != 0)
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
/* FBO Depth Textures */
//! RTT DepthBuffer constructor
COGLES2FBODepthTexture::COGLES2FBODepthTexture(
const core::dimension2d<u32>& size,
const io::path& name,
COGLES2Driver* driver,
bool useStencil)
: COGLES2Texture(name, driver), DepthRenderBuffer(0),
StencilRenderBuffer(0), UseStencil(useStencil)
{
#ifdef _DEBUG
setDebugName("COGLES2TextureFBO_Depth");
#endif
ImageSize = size;
TextureSize = size;
InternalFormat = GL_RGBA;
PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_BYTE;
HasMipMaps = false;
if (useStencil)
{
glGenRenderbuffers(1, &DepthRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, DepthRenderBuffer);
#ifdef GL_OES_packed_depth_stencil
if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_OES_packed_depth_stencil))
{
// generate packed depth stencil buffer
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, ImageSize.Width, ImageSize.Height);
StencilRenderBuffer = DepthRenderBuffer; // stencil is packed with depth
}
else // generate separate stencil and depth textures
#endif
{
glRenderbufferStorage(GL_RENDERBUFFER, Driver->getZBufferBits(), ImageSize.Width, ImageSize.Height);
glGenRenderbuffers(1, &StencilRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, StencilRenderBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, ImageSize.Width, ImageSize.Height);
}
}
else
{
// generate depth buffer
glGenRenderbuffers(1, &DepthRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, DepthRenderBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, Driver->getZBufferBits(), ImageSize.Width, ImageSize.Height);
}
}
//! destructor
COGLES2FBODepthTexture::~COGLES2FBODepthTexture()
{
if (DepthRenderBuffer)
glDeleteRenderbuffers(1, &DepthRenderBuffer);
if (StencilRenderBuffer && StencilRenderBuffer != DepthRenderBuffer)
glDeleteRenderbuffers(1, &StencilRenderBuffer);
}
//combine depth texture and rtt
bool COGLES2FBODepthTexture::attach(ITexture* renderTex)
{
if (!renderTex)
return false;
COGLES2FBOTexture* rtt = static_cast<COGLES2FBOTexture*>(renderTex);
rtt->bindRTT();
// attach stencil texture to stencil buffer
if (UseStencil)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, StencilRenderBuffer);
// attach depth renderbuffer to depth buffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthRenderBuffer);
// check the status
if (!checkOGLES2FBOStatus(Driver))
{
os::Printer::log("FBO incomplete");
return false;
}
rtt->DepthTexture=this;
grab(); // grab the depth buffer, not the RTT
rtt->unbindRTT();
return true;
}
//! Bind Render Target Texture
void COGLES2FBODepthTexture::bindRTT()
{
}
//! Unbind Render Target Texture
void COGLES2FBODepthTexture::unbindRTT()
{
}
bool checkOGLES2FBOStatus(COGLES2Driver* Driver)
{
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch (status)
{
case GL_FRAMEBUFFER_COMPLETE:
return true;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
os::Printer::log("FBO missing an image attachment", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR);
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
os::Printer::log("FBO format unsupported", ELL_ERROR);
break;
default:
break;
}
os::Printer::log("FBO error", ELL_ERROR);
return false;
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES2_

View File

@ -0,0 +1,208 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES2_TEXTURE_H_INCLUDED__
#define __C_OGLES2_TEXTURE_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES2/gl.h>
#else
#include <GLES2/gl2.h>
#endif
#include "ITexture.h"
#include "IImage.h"
#include "SMaterialLayer.h"
namespace irr
{
namespace video
{
class COGLES2Driver;
//! OpenGL ES 2.0 texture.
class COGLES2Texture : public ITexture
{
public:
//! Cache structure.
struct SStatesCache
{
SStatesCache() : WrapU(ETC_REPEAT), WrapV(ETC_REPEAT), BilinearFilter(false),
TrilinearFilter(false), AnisotropicFilter(0), MipMapStatus(false), IsCached(false), LODBias(0)
{
}
u8 WrapU;
u8 WrapV;
bool BilinearFilter;
bool TrilinearFilter;
u8 AnisotropicFilter;
bool MipMapStatus;
s8 LODBias;
bool IsCached;
};
//! constructor
COGLES2Texture(IImage* surface, const io::path& name, void* mipmapData=0, COGLES2Driver* driver=0);
//! destructor
virtual ~COGLES2Texture();
//! lock function
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0);
//! unlock function
virtual void unlock();
//! Returns original size of the texture (image).
virtual const core::dimension2d<u32>& getOriginalSize() const;
//! Returns size of the texture.
virtual const core::dimension2d<u32>& getSize() const;
//! returns driver type of texture (=the driver, that created it)
virtual E_DRIVER_TYPE getDriverType() const;
//! 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
GLuint getOpenGLTextureName() const;
//! return whether this texture has mipmaps
virtual bool hasMipMaps() const;
//! 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);
//! Is it a render target?
virtual bool isRenderTarget() const;
//! Is it a FrameBufferObject?
virtual bool isFrameBufferObject() const;
//! Bind RenderTargetTexture
virtual void bindRTT();
//! Unbind RenderTargetTexture
virtual void unbindRTT();
//! sets whether this texture is intended to be used as a render target.
void setIsRenderTarget(bool isTarget);
//! Get an access to texture states cache.
SStatesCache& getStatesCache() const;
protected:
//! protected constructor with basic setup, no GL texture name created, for derived classes
COGLES2Texture(const io::path& name, COGLES2Driver* driver);
//! get the desired color format based on texture creation flags and the input format.
ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format);
//! get important numbers of the image and hw texture
void getImageValues(IImage* image);
//! copies the texture into an OpenGL texture.
/** \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);
core::dimension2d<u32> ImageSize;
core::dimension2d<u32> TextureSize;
ECOLOR_FORMAT ColorFormat;
COGLES2Driver* 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;
mutable SStatesCache StatesCache;
};
//! OpenGL ES 2.0 FBO texture.
class COGLES2FBOTexture : public COGLES2Texture
{
public:
//! FrameBufferObject constructor
COGLES2FBOTexture(const core::dimension2d<u32>& size, const io::path& name,
COGLES2Driver* driver = 0, const ECOLOR_FORMAT format = ECF_UNKNOWN);
//! destructor
virtual ~COGLES2FBOTexture();
//! Is it a FrameBufferObject?
virtual bool isFrameBufferObject() const;
//! Bind RenderTargetTexture
virtual void bindRTT();
//! Unbind RenderTargetTexture
virtual void unbindRTT();
ITexture* DepthTexture;
protected:
GLuint ColorFrameBuffer;
};
//! OpenGL ES 2.0 FBO depth texture.
class COGLES2FBODepthTexture : public COGLES2Texture
{
public:
//! FrameBufferObject depth constructor
COGLES2FBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COGLES2Driver* driver=0, bool useStencil=false);
//! destructor
virtual ~COGLES2FBODepthTexture();
//! Bind RenderTargetTexture
virtual void bindRTT();
//! Unbind RenderTargetTexture
virtual void unbindRTT();
bool attach(ITexture*);
protected:
GLuint DepthRenderBuffer;
GLuint StencilRenderBuffer;
bool UseStencil;
};
} // end namespace video
} // end namespace irr
#endif
#endif // _IRR_COMPILE_WITH_OGLES2_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,417 @@
// Copyright (C) 2002-2008 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES_DRIVER_H_INCLUDED__
#define __C_OGLES_DRIVER_H_INCLUDED__
#include "IrrCompileConfig.h"
#if defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
#include "MacOSX/CIrrDeviceMacOSX.h"
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include "iOS/CIrrDeviceiOS.h"
#endif
#include "SIrrCreationParameters.h"
#ifdef _IRR_COMPILE_WITH_OGLES1_
#include "CNullDriver.h"
#include "IMaterialRendererServices.h"
#include "EDriverFeatures.h"
#include "fast_atof.h"
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
#include <EGL/egl.h>
#include <GLES/gl.h>
#include "android_native_app_glue.h"
#else
#include <GLES/egl.h>
#include <GLES/gl.h>
#endif
#ifdef _MSC_VER
#pragma comment(lib, "libgles_cm.lib")
#endif
#include "COGLESExtensionHandler.h"
namespace irr
{
namespace video
{
class COGLES1Texture;
class COGLES1Driver : public CNullDriver, public IMaterialRendererServices, public COGLES1ExtensionHandler
{
friend class COGLES1Texture;
public:
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
COGLES1Driver(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data,
io::IFileSystem* io);
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
COGLES1Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceMacOSX *device);
#endif
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
COGLES1Driver(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data,
io::IFileSystem* io, CIrrDeviceIPhone* device);
#endif
//! destructor
virtual ~COGLES1Driver();
//! clears the zbuffer
virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
SColor color=SColor(255,0,0,0),
const SExposedVideoData& videoData=SExposedVideoData(),
core::rect<s32>* sourceRect=0);
//! presents the rendered scene on the screen, returns false if failed
virtual bool endScene();
//! sets transformation
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
struct SHWBufferLink_opengl : public SHWBufferLink
{
SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer): SHWBufferLink(_MeshBuffer), vbo_verticesID(0),vbo_indicesID(0){}
GLuint vbo_verticesID; //tmp
GLuint vbo_indicesID; //tmp
GLuint vbo_verticesSize; //tmp
GLuint vbo_indicesSize; //tmp
};
bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
//! updates hardware buffer if needed
virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer);
//! Create hardware buffer from mesh
virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb);
//! Delete hardware buffer (only some drivers can)
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
//! Draw hardware buffer
virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer);
//! draws a vertex primitive list
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
void drawVertexPrimitiveList2d3d(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType=EIT_16BIT, bool threed=true);
//! queries the features of the driver, returns true if feature is available
virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
{
// return FeatureEnabled[feature] && COGLES1ExtensionHandler::queryFeature(feature);
return COGLES1ExtensionHandler::queryFeature(feature);
}
//! Sets a material.
virtual void setMaterial(const SMaterial& material);
//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false);
//! draws a set of 2d images
virtual void draw2DImage(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::array<core::rect<s32> >& sourceRects,
const core::array<s32>& indices,
const core::rect<s32>* clipRect=0,
SColor color=SColor(255,255,255,255),
bool useAlphaChannelOfTexture=false);
//! draws a set of 2d images, using a color and the alpha channel of the texture if desired.
virtual void draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect=0,
SColor color=SColor(255,255,255,255),
bool useAlphaChannelOfTexture=false);
//! Draws a part of the texture into the rectangle.
virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false);
//! draw an 2d rectangle
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip = 0);
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip = 0);
//! Draws a 2d line.
virtual void draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255));
//! Draws a single pixel
virtual void drawPixel(u32 x, u32 y, const SColor & color);
//! Draws a 3d line.
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end,
SColor color = SColor(255,255,255,255));
//! Returns the name of the video driver.
virtual const wchar_t* getName() const;
//! deletes all dynamic lights there are
virtual void deleteAllDynamicLights();
//! adds a dynamic light
virtual s32 addDynamicLight(const SLight& light);
//! Turns a dynamic light on or off
//! \param lightIndex: the index returned by addDynamicLight
//! \param turnOn: true to turn the light on, false to turn it off
virtual void turnLightOn(s32 lightIndex, bool turnOn);
//! returns the maximal amount of dynamic lights the device can handle
virtual u32 getMaximalDynamicLightAmount() const;
//! Sets the dynamic ambient light color.
virtual void setAmbientLight(const SColorf& color);
//! Draws a shadow volume into the stencil buffer.
virtual void drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail);
//! Fills the stencil shadow with color.
virtual void drawStencilShadow(bool clearStencilBuffer=false,
video::SColor leftUpEdge = video::SColor(0,0,0,0),
video::SColor rightUpEdge = video::SColor(0,0,0,0),
video::SColor leftDownEdge = video::SColor(0,0,0,0),
video::SColor rightDownEdge = video::SColor(0,0,0,0));
//! sets a viewport
virtual void setViewPort(const core::rect<s32>& area);
//! Sets the fog mode.
virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start,
f32 end, f32 density, bool pixelFog, bool rangeFog);
//! Only used internally by the engine
virtual void OnResize(const core::dimension2d<u32>& size);
//! Returns type of video driver
virtual E_DRIVER_TYPE getDriverType() const;
//! get color format of the current color buffer
virtual ECOLOR_FORMAT getColorFormat() const;
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
//! Can be called by an IMaterialRenderer to make its work easier.
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderstates);
//! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name);
//! Get a pixel shader constant index.
virtual s32 getPixelShaderConstantID(const c8* name);
//! Sets a constant for the vertex shader based on an index.
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
//! Sets a constant for the pixel shader based on an index.
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
//! Sets a vertex shader constant.
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a pixel shader constant.
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! sets the current Texture
bool setActiveTexture(u32 stage, const video::ITexture* texture);
//! disables all textures beginning with fromStage.
bool disableTextures(u32 fromStage=0);
//! Adds a new material renderer to the VideoDriver
virtual s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);
//! Adds a new material renderer to the VideoDriver
virtual s32 addHighLevelShaderMaterial(const c8* vertexShaderProgram, const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget, const c8* pixelShaderProgram, const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget, IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial,
s32 userData);
//! Returns pointer to the IGPUProgrammingServices interface.
virtual IGPUProgrammingServices* getGPUProgrammingServices();
//! Returns a pointer to the IVideoDriver interface.
virtual IVideoDriver* getVideoDriver();
//! Returns the maximum amount of primitives
virtual u32 getMaximalPrimitiveCount() const;
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN);
virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color);
//! Clears the ZBuffer.
virtual void clearZBuffer();
//! Returns an image created from the last rendered frame.
virtual IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER);
//! checks if an OpenGL error has happend and prints it
bool testGLError();
//! checks if an OGLES1 error has happend and prints it
bool testEGLError();
//! Set/unset a clipping plane.
virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false);
//! Enable/disable a clipping plane.
virtual void enableClipPlane(u32 index, bool enable);
//! Returns the graphics card vendor name.
virtual core::stringc getVendorInfo() {return vendorName;};
//! Get the maximal texture size for this driver
core::dimension2du getMaxTextureSize() const;
ITexture* createDepthTexture(ITexture* texture, bool shared=true);
void removeDepthTexture(ITexture* texture);
private:
void uploadClipPlane(u32 index);
//! inits the opengl-es driver
bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer);
//! returns a device dependent texture from a software surface (IImage)
virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData=0);
//! creates a transposed matrix in supplied GLfloat array to pass to OGLES1
inline void createGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m);
inline void createGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4& m);
//! Set GL pipeline to desired texture wrap modes of the material
void setWrapMode(const SMaterial& material);
//! Get OpenGL wrap enum from Irrlicht enum
GLint getTextureWrapMode(u8 clamp) const;
//! sets the needed renderstates
void setRenderStates3DMode();
//! sets the needed renderstates
void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
// returns the current size of the screen or rendertarget
virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const;
void createMaterialRenderers();
//! Assign a hardware light to the specified requested light, if any
//! free hardware lights exist.
//! \param[in] lightIndex: the index of the requesting light
void assignHardwareLight(u32 lightIndex);
core::stringw Name;
core::matrix4 Matrices[ETS_COUNT];
core::array<u8> ColorBuffer;
//! enumeration for rendering modes such as 2d and 3d for minizing the switching of renderStates.
enum E_RENDER_MODE
{
ERM_NONE = 0, // no render state has been set yet.
ERM_2D, // 2d drawing rendermode
ERM_3D // 3d rendering mode
};
E_RENDER_MODE CurrentRenderMode;
//! bool to make all renderstates reset if set to true.
bool ResetRenderStates;
bool Transformation3DChanged;
u8 AntiAlias;
SMaterial Material, LastMaterial;
COGLES1Texture* RenderTargetTexture;
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
core::array<ITexture*> DepthTextures;
core::array<core::plane3df> UserClipPlane;
core::array<bool> UserClipPlaneEnabled;
core::dimension2d<u32> CurrentRendertargetSize;
core::stringc vendorName;
core::matrix4 TextureFlipMatrix;
//! Color buffer format
ECOLOR_FORMAT ColorFormat;
//! All the lights that have been requested; a hardware limited
//! number of them will be used at once.
struct RequestedLight
{
RequestedLight(SLight const & lightData)
: LightData(lightData), HardwareLightIndex(-1), DesireToBeOn(true) { }
SLight LightData;
s32 HardwareLightIndex; // GL_LIGHT0 - GL_LIGHT7
bool DesireToBeOn;
};
core::array<RequestedLight> RequestedLights;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
HDC HDc;
#endif
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
CIrrDeviceIPhone* Device;
GLuint ViewFramebuffer;
GLuint ViewRenderbuffer;
GLuint ViewDepthRenderbuffer;
#else
NativeWindowType EglWindow;
EGLDisplay EglDisplay;
EGLSurface EglSurface;
EGLContext EglContext;
#endif
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OPENGL_
#endif

View File

@ -0,0 +1,281 @@
// Copyright (C) 2008 Christian Stehno
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES1_
#include "COGLESExtensionHandler.h"
#include "COGLESDriver.h"
#include "fast_atof.h"
#include "irrString.h"
namespace irr
{
namespace video
{
static const char* const OGLESFeatureStrings[] =
{
"GL_AMD_compressed_3DC_texture",
"GL_AMD_compressed_ATC_texture",
"GL_AMD_performance_monitor",
"GL_AMD_program_binary_Z400",
"GL_ANGLE_framebuffer_blit",
"GL_ANGLE_framebuffer_multisample",
"GL_APPLE_copy_texture_levels",
"GL_APPLE_framebuffer_multisample",
"GL_APPLE_rgb_422",
"GL_APPLE_sync",
"GL_APPLE_texture_2D_limited_npot",
"GL_APPLE_texture_format_BGRA8888",
"GL_APPLE_texture_max_level",
"GL_ARB_texture_env_combine",
"GL_ARB_texture_env_dot3",
"GL_ARM_mali_shader_binary",
"GL_ARM_rgba8",
"GL_DMP_shader_binary",
"GL_EXT_blend_minmax",
"GL_EXT_discard_framebuffer",
"GL_EXT_frag_depth",
"GL_EXT_map_buffer_range",
"GL_EXT_multi_draw_arrays",
"GL_EXT_multisampled_render_to_texture",
"GL_EXT_read_format_bgra",
"GL_EXT_robustness",
"GL_EXT_shader_texture_lod",
"GL_EXT_sRGB",
"GL_EXT_texture_compression_dxt1",
"GL_EXT_texture_filter_anisotropic",
"GL_EXT_texture_format_BGRA8888",
"GL_EXT_texture_lod_bias",
"GL_EXT_texture_storage",
"GL_EXT_texture_type_2_10_10_10_REV",
"GL_IMG_multisampled_render_to_texture",
"GL_IMG_program_binary",
"GL_IMG_read_format",
"GL_IMG_shader_binary",
"GL_IMG_texture_compression_pvrtc",
"GL_IMG_texture_env_enhanced_fixed_function",
"GL_IMG_texture_format_BGRA8888",
"GL_IMG_user_clip_plane",
"GL_IMG_vertex_program",
"GL_NV_coverage_sample",
"GL_NV_depth_nonlinear",
"GL_NV_fence",
"GL_OES_blend_equation_separate",
"GL_OES_blend_func_separate",
"GL_OES_blend_subtract",
"GL_OES_byte_coordinates",
"GL_OES_compressed_ETC1_RGB8_texture",
"GL_OES_compressed_paletted_texture",
"GL_OES_depth24",
"GL_OES_depth32",
"GL_OES_depth_texture",
"GL_OES_draw_texture",
"GL_OES_EGL_image",
"GL_OES_EGL_image_external",
"GL_OES_EGL_sync",
"GL_OES_element_index_uint",
"GL_OES_extended_matrix_palette",
"GL_OES_fbo_render_mipmap",
"GL_OES_fixed_point",
"GL_OES_fragment_precision_high",
"GL_OES_framebuffer_object",
"GL_OES_get_program_binary",
"GL_OES_mapbuffer",
"GL_OES_matrix_get",
"GL_OES_matrix_palette",
"GL_OES_packed_depth_stencil",
"GL_OES_point_size_array",
"GL_OES_point_sprite",
"GL_OES_query_matrix",
"GL_OES_read_format",
"GL_OES_required_internalformat",
"GL_OES_rgb8_rgba8",
"GL_OES_single_precision",
"GL_OES_standard_derivatives",
"GL_OES_stencil1",
"GL_OES_stencil4",
"GL_OES_stencil8",
"GL_OES_stencil_wrap",
"GL_OES_texture_3D",
"GL_OES_texture_cube_map",
"GL_OES_texture_env_crossbar",
"GL_OES_texture_float",
"GL_OES_texture_float_linear",
"GL_OES_texture_half_float",
"GL_OES_texture_half_float_linear",
"GL_OES_texture_mirrored_repeat",
"GL_OES_texture_npot",
"GL_OES_vertex_array_object",
"GL_OES_vertex_half_float",
"GL_OES_vertex_type_10_10_10_2",
"GL_QCOM_driver_control",
"GL_QCOM_extended_get",
"GL_QCOM_extended_get2",
"GL_QCOM_performance_monitor_global_mode",
"GL_QCOM_tiled_rendering",
"GL_QCOM_writeonly_rendering",
"GL_SUN_multi_draw_arrays",
"GL_VIV_shader_binary"
};
COGLES1ExtensionHandler::COGLES1ExtensionHandler() :
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
pGlDrawTexiOES(0), pGlDrawTexfOES(0),
pGlDrawTexivOES(0), pGlDrawTexfvOES(0),
pGlBindRenderbufferOES(0), pGlDeleteRenderbuffersOES(0),
pGlGenRenderbuffersOES(0), pGlRenderbufferStorageOES(0),
pGlBindFramebufferOES(0), pGlDeleteFramebuffersOES(0),
pGlGenFramebuffersOES(0), pGlCheckFramebufferStatusOES(0),
pGlFramebufferRenderbufferOES(0), pGlFramebufferTexture2DOES(0),
pGlGenerateMipMapOES(0),
#endif
EGLVersion(0), Version(0), MaxTextureUnits(0), MaxLights(0),
MaxAnisotropy(1), MaxUserClipPlanes(0), MaxAuxBuffers(0),
MaxMultipleRenderTargets(1), MaxIndices(65535), MaxTextureSize(1),
MaxTextureLODBias(0.f), CommonProfile(false),
MultiTextureExtension(false), MultiSamplingExtension(false),
StencilBuffer(false)
{
for (u32 i=0; i<IRR_OGLES_Feature_Count; ++i)
FeatureAvailable[i]=false;
DimAliasedLine[0]=1.f;
DimAliasedLine[1]=1.f;
DimAliasedPoint[0]=1.f;
DimAliasedPoint[1]=1.f;
DimSmoothedLine[0]=1.f;
DimSmoothedLine[1]=1.f;
DimSmoothedPoint[0]=1.f;
DimSmoothedPoint[1]=1.f;
}
void COGLES1ExtensionHandler::dump() const
{
for (u32 i=0; i<IRR_OGLES_Feature_Count; ++i)
os::Printer::log(OGLESFeatureStrings[i], FeatureAvailable[i]?" true":" false");
}
void COGLES1ExtensionHandler::initExtensions(COGLES1Driver* driver,
#ifdef EGL_VERSION_1_0
EGLDisplay display,
#endif
bool withStencil)
{
#ifdef EGL_VERSION_1_0
const f32 egl_ver = core::fast_atof(reinterpret_cast<const c8*>(eglQueryString(display, EGL_VERSION)));
EGLVersion = static_cast<u16>(core::floor32(egl_ver)*100+core::round32(core::fract(egl_ver)*10.0f));
core::stringc eglExtensions = eglQueryString(display, EGL_EXTENSIONS);
os::Printer::log(eglExtensions.c_str());
#endif
const core::stringc stringVer(glGetString(GL_VERSION));
CommonProfile = (stringVer[11]=='M');
const f32 ogl_ver = core::fast_atof(stringVer.c_str()+13);
Version = static_cast<u16>(core::floor32(ogl_ver)*100+core::round32(core::fract(ogl_ver)*10.0f));
core::stringc extensions = glGetString(GL_EXTENSIONS);
os::Printer::log(extensions.c_str());
// typo in the simulator (note the postfixed s)
if (extensions.find("GL_IMG_user_clip_planes"))
FeatureAvailable[IRR_IMG_user_clip_plane] = true;
{
const u32 size = extensions.size()+1;
c8* str = new c8[size];
strncpy(str, extensions.c_str(), extensions.size());
str[extensions.size()]=' ';
c8* p = str;
for (u32 i=0; i<size; ++i)
{
if (str[i] == ' ')
{
str[i] = 0;
if (*p)
for (u32 j=0; j<IRR_OGLES_Feature_Count; ++j)
{
if (!strcmp(OGLESFeatureStrings[j], p))
{
FeatureAvailable[j] = true;
break;
}
}
p = p + strlen(p) + 1;
}
}
delete [] str;
}
GLint val=0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &val);
MaxSupportedTextures = core::min_(MATERIAL_MAX_TEXTURES, static_cast<u32>(val));
MultiTextureExtension = true;
glGetIntegerv(GL_MAX_LIGHTS, &val);
MaxLights = static_cast<u8>(val);
#ifdef GL_EXT_texture_filter_anisotropic
if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic])
{
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
MaxAnisotropy = static_cast<u8>(val);
}
#endif
#ifdef GL_MAX_ELEMENTS_INDICES
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val);
MaxIndices=val;
#endif
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
MaxTextureSize=static_cast<u32>(val);
#ifdef GL_EXT_texture_lod_bias
if (FeatureAvailable[IRR_EXT_texture_lod_bias])
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
#endif
if ((Version>100) || FeatureAvailable[IRR_IMG_user_clip_plane])
{
glGetIntegerv(GL_MAX_CLIP_PLANES, &val);
MaxUserClipPlanes = static_cast<u8>(val);
}
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, DimSmoothedLine);
glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, DimSmoothedPoint);
MaxTextureUnits = core::min_(MaxSupportedTextures, static_cast<u8>(MATERIAL_MAX_TEXTURES));
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
if (FeatureAvailable[IRR_OES_draw_texture])
{
pGlDrawTexiOES = (PFNGLDRAWTEXIOES) eglGetProcAddress("glDrawTexiOES");
pGlDrawTexfOES = (PFNGLDRAWTEXFOES) eglGetProcAddress("glDrawTexfOES");
pGlDrawTexivOES = (PFNGLDRAWTEXIVOES) eglGetProcAddress("glDrawTexivOES");
pGlDrawTexfvOES = (PFNGLDRAWTEXFVOES) eglGetProcAddress("glDrawTexfvOES");
}
if (FeatureAvailable[IRR_OES_framebuffer_object])
{
pGlBindRenderbufferOES = (PFNGLBINDRENDERBUFFEROES) eglGetProcAddress("glBindRenderbufferOES");
pGlDeleteRenderbuffersOES = (PFNGLDELETERENDERBUFFERSOES) eglGetProcAddress("glDeletedRenderbuffersOES");
pGlGenRenderbuffersOES = (PFNGLGENRENDERBUFFERSOES) eglGetProcAddress("glGenRenderbuffersOES");
pGlRenderbufferStorageOES = (PFNGLRENDERBUFFERSTORAGEOES) eglGetProcAddress("glRenderbufferStorageOES");
pGlBindFramebufferOES = (PFNGLBINDFRAMEBUFFEROES) eglGetProcAddress("glBindFramebufferOES");
pGlDeleteFramebuffersOES = (PFNGLDELETEFRAMEBUFFERSOES) eglGetProcAddress("glDeleteFramebuffersOES");
pGlGenFramebuffersOES = (PFNGLGENFRAMEBUFFERSOES) eglGetProcAddress("glGenFramebuffersOES");
pGlCheckFramebufferStatusOES = (PFNGLCHECKFRAMEBUFFERSTATUSOES) eglGetProcAddress("glCheckFramebufferStatusOES");
pGlFramebufferRenderbufferOES = (PFNGLFRAMEBUFFERRENDERBUFFEROES) eglGetProcAddress("glFramebufferRenderbufferOES");
pGlFramebufferTexture2DOES = (PFNGLFRAMEBUFFERTEXTURE2DOES) eglGetProcAddress("glFramebufferTexture2DOES");
pGlGenerateMipMapOES = (PFNGLGENERATEMIPMAPOES) eglGetProcAddress("glGenerateMipMapOES");
}
#endif
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES1_

View File

@ -0,0 +1,472 @@
// Copyright (C) 2008 Christian Stehno
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#ifndef __C_OGLES_EXTENSION_HANDLER_H_INCLUDED__
#define __C_OGLES_EXTENSION_HANDLER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES1_
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#elif defined(_IRR_ANDROID_PLATFORM_)
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <EGL/egl.h>
#else
#include <GLES/egl.h>
#include <GLES/gl.h>
// seems to be missing...
typedef char GLchar;
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
#include "gles-ext.h"
#endif
#endif
#include "os.h"
#include "EDriverFeatures.h"
namespace irr
{
namespace video
{
class COGLES1Driver;
class COGLES1ExtensionHandler
{
public:
enum EOGLESFeatures
{
IRR_AMD_compressed_3DC_texture = 0, //39
IRR_AMD_compressed_ATC_texture, //40
IRR_AMD_performance_monitor, //50
IRR_AMD_program_binary_Z400, //48
IRR_ANGLE_framebuffer_blit, // 84
IRR_ANGLE_framebuffer_multisample, // 85
IRR_APPLE_copy_texture_levels, // 123
IRR_APPLE_framebuffer_multisample, // 79
IRR_APPLE_rgb_422, // 77
IRR_APPLE_sync, // 124
IRR_APPLE_texture_2D_limited_npot, // 59
IRR_APPLE_texture_format_BGRA8888, // 80
IRR_APPLE_texture_max_level, // 81
IRR_ARB_texture_env_combine, //ogl, IMG simulator
IRR_ARB_texture_env_dot3, //ogl, IMG simulator
IRR_ARM_mali_shader_binary, // 82
IRR_ARM_rgba8, // 83
IRR_DMP_shader_binary, // 89
IRR_EXT_blend_minmax, // 65
IRR_EXT_discard_framebuffer, // 64
IRR_EXT_frag_depth, // 87
IRR_EXT_map_buffer_range, // 121
IRR_EXT_multisampled_render_to_texture, // 106
IRR_EXT_multi_draw_arrays, // 69
IRR_EXT_robustness, // 107
IRR_EXT_read_format_bgra, // 66
IRR_EXT_shader_texture_lod, // 78
IRR_EXT_sRGB, // 105
IRR_EXT_texture_compression_dxt1, //49
IRR_EXT_texture_filter_anisotropic, //41
IRR_EXT_texture_format_BGRA8888, //51
IRR_EXT_texture_lod_bias, // 60
IRR_EXT_texture_storage, // 108
IRR_EXT_texture_type_2_10_10_10_REV, //42
IRR_IMG_multisampled_render_to_texture, // 75
IRR_IMG_program_binary, // 67
IRR_IMG_read_format, //53
IRR_IMG_shader_binary, // 68
IRR_IMG_texture_compression_pvrtc, //54
IRR_IMG_texture_env_enhanced_fixed_function, // 58
IRR_IMG_texture_format_BGRA8888, // replaced by EXT version
IRR_IMG_user_clip_plane, // 57, was clip_planes
IRR_IMG_vertex_program, // non-standard
IRR_NV_coverage_sample, // 73
IRR_NV_depth_nonlinear, // 74
IRR_NV_fence, //52
IRR_OES_blend_equation_separate, //1
IRR_OES_blend_func_separate, //2
IRR_OES_blend_subtract, //3
IRR_OES_byte_coordinates, //4
IRR_OES_compressed_ETC1_RGB8_texture, //5
IRR_OES_compressed_paletted_texture, //6
IRR_OES_depth24, //24
IRR_OES_depth32, //25
IRR_OES_depth_texture, //43
IRR_OES_draw_texture, //7
IRR_OES_EGL_image, //23
IRR_OES_EGL_image_external, // 88
IRR_OES_EGL_sync, // 76
IRR_OES_element_index_uint, //26
IRR_OES_extended_matrix_palette, //8
IRR_OES_fbo_render_mipmap, //27
IRR_OES_fixed_point, //9
IRR_OES_fragment_precision_high, //28
IRR_OES_framebuffer_object, //10
IRR_OES_get_program_binary, //47
IRR_OES_mapbuffer, //29
IRR_OES_matrix_get, //11
IRR_OES_matrix_palette, //12
IRR_OES_packed_depth_stencil, //44
IRR_OES_point_size_array, //14
IRR_OES_point_sprite, //15
IRR_OES_query_matrix, //16
IRR_OES_read_format, //17
IRR_OES_required_internalformat, // 115
IRR_OES_rgb8_rgba8, //30
IRR_OES_single_precision, //18
IRR_OES_standard_derivatives, //45
IRR_OES_stencil1, //31
IRR_OES_stencil4, //32
IRR_OES_stencil8, //33
IRR_OES_stencil_wrap, //19
IRR_OES_texture_3D, //34
IRR_OES_texture_cube_map, //20
IRR_OES_texture_env_crossbar, //21
IRR_OES_texture_float, //36
IRR_OES_texture_float_linear, //35
IRR_OES_texture_half_float, //36
IRR_OES_texture_half_float_linear, //35
IRR_OES_texture_mirrored_repeat, //22
IRR_OES_texture_npot, //37
IRR_OES_vertex_array_object, // 72
IRR_OES_vertex_half_float, //38
IRR_OES_vertex_type_10_10_10_2, //46
IRR_QCOM_driver_control, //55
IRR_QCOM_extended_get, // 62
IRR_QCOM_extended_get2, // 63
IRR_QCOM_performance_monitor_global_mode, //56
IRR_QCOM_tiled_rendering, // 71
IRR_QCOM_writeonly_rendering, // 61
IRR_SUN_multi_draw_arrays, // 70
IRR_VIV_shader_binary, // 86
IRR_OGLES_Feature_Count
};
//! queries the features of the driver, returns true if feature is available
bool queryOpenGLFeature(EOGLESFeatures feature) const
{
return FeatureAvailable[feature];
}
u16 EGLVersion;
u16 Version;
u8 MaxTextureUnits;
u8 MaxSupportedTextures;
u8 MaxLights;
u8 MaxAnisotropy;
u8 MaxUserClipPlanes;
u8 MaxAuxBuffers;
u8 MaxMultipleRenderTargets;
u32 MaxIndices;
u32 MaxTextureSize;
f32 MaxTextureLODBias;
//! Minimal and maximal supported thickness for lines without smoothing
GLfloat DimAliasedLine[2];
//! Minimal and maximal supported thickness for points without smoothing
GLfloat DimAliasedPoint[2];
//! Minimal and maximal supported thickness for lines with smoothing
GLfloat DimSmoothedLine[2];
//! Minimal and maximal supported thickness for points with smoothing
GLfloat DimSmoothedPoint[2];
bool CommonProfile;
bool MultiTextureExtension;
bool MultiSamplingExtension;
bool StencilBuffer;
protected:
bool FeatureAvailable[IRR_OGLES_Feature_Count];
COGLES1ExtensionHandler();
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
{
switch (feature)
{
case EVDF_RENDER_TO_TARGET:
case EVDF_HARDWARE_TL:
return true;
case EVDF_MULTITEXTURE:
return MultiTextureExtension;
case EVDF_BILINEAR_FILTER:
case EVDF_MIP_MAP:
return true;
case EVDF_MIP_MAP_AUTO_UPDATE:
return Version>100; // Supported in version 1.1
case EVDF_STENCIL_BUFFER:
return StencilBuffer;
case EVDF_TEXTURE_NSQUARE:
return true; // non-square is always supported
case EVDF_TEXTURE_NPOT:
return FeatureAvailable[IRR_APPLE_texture_2D_limited_npot];
default:
return false;
}
}
void dump() const;
void initExtensions(COGLES1Driver* driver,
#ifdef EGL_VERSION_1_0
EGLDisplay display,
#endif
bool withStencil);
public:
void extGlBindFramebuffer(GLenum target, GLuint framebuffer)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlBindFramebufferOES)
pGlBindFramebufferOES(target, framebuffer);
#elif defined(GL_OES_framebuffer_object)
glBindFramebufferOES(target, framebuffer);
#else
os::Printer::log("glBindFramebuffer not supported", ELL_ERROR);
#endif
}
void extGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlDeleteFramebuffersOES)
pGlDeleteFramebuffersOES(n, framebuffers);
#elif defined(GL_OES_framebuffer_object)
glDeleteFramebuffersOES(n, framebuffers);
#else
os::Printer::log("glDeleteFramebuffers not supported", ELL_ERROR);
#endif
}
void extGlGenFramebuffers(GLsizei n, GLuint *framebuffers)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlGenFramebuffersOES)
pGlGenFramebuffersOES(n, framebuffers);
#elif defined(GL_OES_framebuffer_object)
glGenFramebuffersOES(n, framebuffers);
#else
os::Printer::log("glGenFramebuffers not supported", ELL_ERROR);
#endif
}
GLenum extGlCheckFramebufferStatus(GLenum target)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlCheckFramebufferStatusOES)
return pGlCheckFramebufferStatusOES(target);
else
return 0;
#elif defined(GL_OES_framebuffer_object)
return glCheckFramebufferStatusOES(target);
#else
os::Printer::log("glCheckFramebufferStatus not supported", ELL_ERROR);
return 0;
#endif
}
void extGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlFramebufferTexture2DOES)
pGlFramebufferTexture2DOES(target, attachment, textarget, texture, level);
#elif defined(GL_OES_framebuffer_object)
glFramebufferTexture2DOES(target, attachment, textarget, texture, level);
#else
os::Printer::log("glFramebufferTexture2D not supported", ELL_ERROR);
#endif
}
void extGlBindRenderbuffer(GLenum target, GLuint renderbuffer)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlBindRenderbufferOES)
pGlBindRenderbufferOES(target, renderbuffer);
#elif defined(GL_OES_framebuffer_object)
glBindRenderbufferOES(target, renderbuffer);
#else
os::Printer::log("glBindRenderbuffer not supported", ELL_ERROR);
#endif
}
void extGlDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlDeleteRenderbuffersOES)
pGlDeleteRenderbuffersOES(n, renderbuffers);
#elif defined(GL_OES_framebuffer_object)
glDeleteRenderbuffersOES(n, renderbuffers);
#else
os::Printer::log("glDeleteRenderbuffers not supported", ELL_ERROR);
#endif
}
void extGlGenRenderbuffers(GLsizei n, GLuint *renderbuffers)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlGenRenderbuffersOES)
pGlGenRenderbuffersOES(n, renderbuffers);
#elif defined(GL_OES_framebuffer_object)
glGenRenderbuffersOES(n, renderbuffers);
#else
os::Printer::log("glGenRenderbuffers not supported", ELL_ERROR);
#endif
}
void extGlRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlRenderbufferStorageOES)
pGlRenderbufferStorageOES(target, internalformat, width, height);
#elif defined(GL_OES_framebuffer_object)
glRenderbufferStorageOES(target, internalformat, width, height);
#else
os::Printer::log("glRenderbufferStorage not supported", ELL_ERROR);
#endif
}
void extGlFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
{
#ifdef _IRR_OGLES1_USE_EXTPOINTER_
if (pGlFramebufferRenderbufferOES)
pGlFramebufferRenderbufferOES(target, attachment, renderbuffertarget, renderbuffer);
#elif defined(GL_OES_framebuffer_object)
glFramebufferRenderbufferOES(target, attachment, renderbuffertarget, renderbuffer);
#else
os::Printer::log("glFramebufferRenderbuffer not supported", ELL_ERROR);
#endif
}
void extGlDrawTex(GLfloat X, GLfloat Y, GLfloat Z, GLfloat W, GLfloat H)
{
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
if (pGlDrawTexfOES)
pGlDrawTexfOES(X, Y, Z, W, H);
#elif defined(GL_OES_draw_texture)
glDrawTexfOES(X, Y, Z, W, H);
#else
os::Printer::log("glDrawTexture not supported", ELL_ERROR);
#endif
}
void extGlDrawTex(GLint X, GLint Y, GLint Z, GLint W, GLint H)
{
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
if (pGlDrawTexiOES)
pGlDrawTexiOES(X, Y, Z, W, H);
#elif defined(GL_OES_draw_texture)
glDrawTexiOES(X, Y, Z, W, H);
#else
os::Printer::log("glDrawTexture not supported", ELL_ERROR);
#endif
}
void extGlDrawTex(GLfloat* coords)
{
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
if (pGlDrawTexfvOES)
pGlDrawTexfvOES(coords);
#elif defined(GL_OES_draw_texture)
glDrawTexfvOES(coords);
#else
os::Printer::log("glDrawTexture not supported", ELL_ERROR);
#endif
}
void extGlDrawTex(GLint* coords)
{
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
if (pGlDrawTexivOES)
pGlDrawTexivOES(coords);
#elif defined(GL_OES_draw_texture)
glDrawTexivOES(coords);
#else
os::Printer::log("glDrawTexture not supported", ELL_ERROR);
#endif
}
// we need to implement some methods which have been extensions in the original OpenGL driver
void extGlActiveTexture(GLenum texture)
{
glActiveTexture(texture);
}
void extGlClientActiveTexture(GLenum texture)
{
glClientActiveTexture(texture);
}
void extGlGenBuffers(GLsizei n, GLuint *buffers)
{
glGenBuffers(n, buffers);
}
void extGlBindBuffer(GLenum target, GLuint buffer)
{
glBindBuffer(target, buffer);
}
void extGlBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
{
glBufferData(target, size, data, usage);
}
void extGlBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)
{
glBufferSubData(target, offset, size, data);
}
void extGlDeleteBuffers(GLsizei n, const GLuint *buffers)
{
glDeleteBuffers(n, buffers);
}
void extGlPointParameterf(GLint loc, GLfloat f)
{
glPointParameterf(loc, f);
}
void extGlPointParameterfv(GLint loc, const GLfloat *v)
{
glPointParameterfv(loc, v);
}
// private:
#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
typedef void (GL_APIENTRYP PFNGLDRAWTEXIOES) (GLint x, GLint y, GLint z, GLint width, GLint height);
typedef void (GL_APIENTRYP PFNGLDRAWTEXIVOES) (const GLint* coords);
typedef void (GL_APIENTRYP PFNGLDRAWTEXFOES) (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
typedef void (GL_APIENTRYP PFNGLDRAWTEXFVOES) (const GLfloat* coords);
typedef GLboolean (GL_APIENTRYP PFNGLISRENDERBUFFEROES) (GLuint renderbuffer);
typedef void (GL_APIENTRYP PFNGLBINDRENDERBUFFEROES) (GLenum target, GLuint renderbuffer);
typedef void (GL_APIENTRYP PFNGLDELETERENDERBUFFERSOES) (GLsizei n, const GLuint* renderbuffers);
typedef void (GL_APIENTRYP PFNGLGENRENDERBUFFERSOES) (GLsizei n, GLuint* renderbuffers);
typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEOES) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
typedef void (GL_APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVOES) (GLenum target, GLenum pname, GLint* params);
typedef GLboolean (GL_APIENTRYP PFNGLISFRAMEBUFFEROES) (GLuint framebuffer);
typedef void (GL_APIENTRYP PFNGLBINDFRAMEBUFFEROES) (GLenum target, GLuint framebuffer);
typedef void (GL_APIENTRYP PFNGLDELETEFRAMEBUFFERSOES) (GLsizei n, const GLuint* framebuffers);
typedef void (GL_APIENTRYP PFNGLGENFRAMEBUFFERSOES) (GLsizei n, GLuint* framebuffers);
typedef GLenum (GL_APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSOES) (GLenum target);
typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEROES) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DOES) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
typedef void (GL_APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVOES) (GLenum target, GLenum attachment, GLenum pname, GLint* params);
typedef void (GL_APIENTRYP PFNGLGENERATEMIPMAPOES) (GLenum target);
PFNGLDRAWTEXIOES pGlDrawTexiOES;
PFNGLDRAWTEXFOES pGlDrawTexfOES;
PFNGLDRAWTEXIVOES pGlDrawTexivOES;
PFNGLDRAWTEXFVOES pGlDrawTexfvOES;
PFNGLBINDRENDERBUFFEROES pGlBindRenderbufferOES;
PFNGLDELETERENDERBUFFERSOES pGlDeleteRenderbuffersOES;
PFNGLGENRENDERBUFFERSOES pGlGenRenderbuffersOES;
PFNGLRENDERBUFFERSTORAGEOES pGlRenderbufferStorageOES;
PFNGLBINDFRAMEBUFFEROES pGlBindFramebufferOES;
PFNGLDELETEFRAMEBUFFERSOES pGlDeleteFramebuffersOES;
PFNGLGENFRAMEBUFFERSOES pGlGenFramebuffersOES;
PFNGLCHECKFRAMEBUFFERSTATUSOES pGlCheckFramebufferStatusOES;
PFNGLFRAMEBUFFERRENDERBUFFEROES pGlFramebufferRenderbufferOES;
PFNGLFRAMEBUFFERTEXTURE2DOES pGlFramebufferTexture2DOES;
PFNGLGENERATEMIPMAPOES pGlGenerateMipMapOES;
#endif
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES1_
#endif

View File

@ -0,0 +1,637 @@
// Copyright (C) 2002-2008 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_OGLES1_MATERIAL_RENDERER_H_INCLUDED__
#define __C_OGLES1_MATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES1_
#include "COGLESDriver.h"
#include "IMaterialRenderer.h"
namespace irr
{
namespace video
{
//! Base class for all internal OGLES1 material renderers
class COGLES1MaterialRenderer : public IMaterialRenderer
{
public:
//! Constructor
COGLES1MaterialRenderer(video::COGLES1Driver* driver) : Driver(driver)
{
}
protected:
video::COGLES1Driver* Driver;
};
//! Solid material renderer
class COGLES1MaterialRenderer_SOLID : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_SOLID(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (resetAllRenderstates || (material.MaterialType != lastMaterial.MaterialType))
{
// thanks to Murphy, the following line removed some
// bugs with several OGLES1 implementations.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}
};
//! Generic Texture Blend
class COGLES1MaterialRenderer_ONETEXTURE_BLEND : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_ONETEXTURE_BLEND(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
// if (material.MaterialType != lastMaterial.MaterialType ||
// material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
// resetAllRenderstates)
{
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, (f32) modulate );
glBlendFunc( getGLBlend(srcFact), getGLBlend(dstFact) );
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.f);
glEnable(GL_BLEND);
if ( textureBlendFunc_hasAlpha(srcFact) || textureBlendFunc_hasAlpha(dstFact) )
{
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
}
}
}
virtual void OnUnsetMaterial()
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.f );
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
//! Returns if the material is transparent.
/** Is not always transparent, but mostly. */
virtual bool isTransparent() const
{
return true;
}
private:
u32 getGLBlend ( E_BLEND_FACTOR factor ) const
{
u32 r = 0;
switch ( factor )
{
case EBF_ZERO: r = GL_ZERO; break;
case EBF_ONE: r = GL_ONE; break;
case EBF_DST_COLOR: r = GL_DST_COLOR; break;
case EBF_ONE_MINUS_DST_COLOR: r = GL_ONE_MINUS_DST_COLOR; break;
case EBF_SRC_COLOR: r = GL_SRC_COLOR; break;
case EBF_ONE_MINUS_SRC_COLOR: r = GL_ONE_MINUS_SRC_COLOR; break;
case EBF_SRC_ALPHA: r = GL_SRC_ALPHA; break;
case EBF_ONE_MINUS_SRC_ALPHA: r = GL_ONE_MINUS_SRC_ALPHA; break;
case EBF_DST_ALPHA: r = GL_DST_ALPHA; break;
case EBF_ONE_MINUS_DST_ALPHA: r = GL_ONE_MINUS_DST_ALPHA; break;
case EBF_SRC_ALPHA_SATURATE: r = GL_SRC_ALPHA_SATURATE; break;
}
return r;
}
};
//! Solid 2 layer material renderer
class COGLES1MaterialRenderer_SOLID_2_LAYER : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_SOLID_2_LAYER(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(2);
Driver->setActiveTexture(1, material.getTexture(1));
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PRIMARY_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
}
}
}
virtual void OnUnsetMaterial()
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
Driver->extGlActiveTexture(GL_TEXTURE0);
}
}
};
//! Transparent add color material renderer
class COGLES1MaterialRenderer_TRANSPARENT_ADD_COLOR : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_TRANSPARENT_ADD_COLOR(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if ((material.MaterialType != lastMaterial.MaterialType) || resetAllRenderstates)
{
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND);
}
}
virtual void OnUnsetMaterial()
{
glDisable(GL_BLEND);
}
//! Returns if the material is transparent.
virtual bool isTransparent() const
{
return true;
}
};
//! Transparent vertex alpha material renderer
class COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR );
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR );
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
}
virtual void OnUnsetMaterial()
{
// default values
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE );
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE );
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS );
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE );
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
glDisable(GL_BLEND);
}
//! Returns if the material is transparent.
virtual bool isTransparent() const
{
return true;
}
};
//! Transparent alpha channel material renderer
class COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, material.MaterialTypeParam);
}
}
virtual void OnUnsetMaterial()
{
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
}
//! Returns if the material is transparent.
virtual bool isTransparent() const
{
return true;
}
};
//! Transparent alpha channel material renderer
class COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5f);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
}
virtual void OnUnsetMaterial()
{
glDisable(GL_ALPHA_TEST);
}
//! Returns if the material is transparent.
virtual bool isTransparent() const
{
return false; // this material is not really transparent because it does no blending.
}
};
//! material renderer for all kinds of lightmaps
class COGLES1MaterialRenderer_LIGHTMAP : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_LIGHTMAP(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(2);
Driver->setActiveTexture(1, material.getTexture(1));
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
// diffuse map
switch (material.MaterialType)
{
case EMT_LIGHTMAP_LIGHTING:
case EMT_LIGHTMAP_LIGHTING_M2:
case EMT_LIGHTMAP_LIGHTING_M4:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
break;
case EMT_LIGHTMAP_ADD:
case EMT_LIGHTMAP:
case EMT_LIGHTMAP_M2:
case EMT_LIGHTMAP_M4:
default:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
break;
}
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
// lightmap
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
if (material.MaterialType == EMT_LIGHTMAP_ADD)
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED);
else
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
switch (material.MaterialType)
{
case EMT_LIGHTMAP_M4:
case EMT_LIGHTMAP_LIGHTING_M4:
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 4.0f);
break;
case EMT_LIGHTMAP_M2:
case EMT_LIGHTMAP_LIGHTING_M2:
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0f);
break;
default:
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
}
}
}
}
virtual void OnUnsetMaterial()
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.f );
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Driver->extGlActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}
};
//! detail map material renderer
class COGLES1MaterialRenderer_DETAIL_MAP : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_DETAIL_MAP(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(2);
Driver->setActiveTexture(1, material.getTexture(1));
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
// diffuse map
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
// detail map
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED);
glTexEnvi(GL_TEXTURE_ENV,GL_SRC0_RGB,GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV,GL_SRC1_RGB, GL_TEXTURE);
Driver->extGlActiveTexture(GL_TEXTURE0);
}
}
}
};
//! sphere map material renderer
class COGLES1MaterialRenderer_SPHERE_MAP : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_SPHERE_MAP(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(1);
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
// glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// glEnable(GL_TEXTURE_GEN_S);
// glEnable(GL_TEXTURE_GEN_T);
}
}
virtual void OnUnsetMaterial()
{
// glDisable(GL_TEXTURE_GEN_S);
// glDisable(GL_TEXTURE_GEN_T);
}
};
//! reflection 2 layer material renderer
class COGLES1MaterialRenderer_REFLECTION_2_LAYER : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_REFLECTION_2_LAYER(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(2);
Driver->setActiveTexture(1, material.getTexture(1));
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
}
// glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// glEnable(GL_TEXTURE_GEN_S);
// glEnable(GL_TEXTURE_GEN_T);
}
}
virtual void OnUnsetMaterial()
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
// glDisable(GL_TEXTURE_GEN_S);
// glDisable(GL_TEXTURE_GEN_T);
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE0);
}
}
};
//! reflection 2 layer material renderer
class COGLES1MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER : public COGLES1MaterialRenderer
{
public:
COGLES1MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(video::COGLES1Driver* d)
: COGLES1MaterialRenderer(d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
Driver->disableTextures(2);
Driver->setActiveTexture(1, material.getTexture(1));
Driver->setActiveTexture(0, material.getTexture(0));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
}
// glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
// glEnable(GL_TEXTURE_GEN_S);
// glEnable(GL_TEXTURE_GEN_T);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
glEnable(GL_BLEND);
}
}
virtual void OnUnsetMaterial()
{
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
// glDisable(GL_TEXTURE_GEN_S);
// glDisable(GL_TEXTURE_GEN_T);
if (Driver->queryFeature(EVDF_MULTITEXTURE))
{
Driver->extGlActiveTexture(GL_TEXTURE0);
}
glDisable(GL_BLEND);
}
//! Returns if the material is transparent.
virtual bool isTransparent() const
{
return true;
}
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -0,0 +1,804 @@
// Copyright (C) 2002-2008 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES1_
#include "irrTypes.h"
#include "COGLESTexture.h"
#include "COGLESDriver.h"
#include "os.h"
#include "CImage.h"
#include "CColorConverter.h"
#include "irrString.h"
namespace
{
#ifndef GL_BGRA
// we need to do this for the IMG_BGRA8888 extension
int GL_BGRA=GL_RGBA;
#endif
}
namespace irr
{
namespace video
{
//! constructor for usual textures
COGLES1Texture::COGLES1Texture(IImage* origImage, const io::path& name, COGLES1Driver* driver, void* mipmapData)
: ITexture(name), Driver(driver), Image(0), MipImage(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA),
// TODO ogl-es
// PixelFormat(GL_BGRA),
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0),
HasMipMaps(true), IsRenderTarget(false), AutomaticMipmapUpdate(false),
UseStencil(false), ReadOnlyLock(false), KeepImage(true)
{
#ifdef _DEBUG
setDebugName("COGLES1Texture");
#endif
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
getImageValues(origImage);
glGenTextures(1, &TextureName);
Image = new CImage(ColorFormat, TextureSize);
if (ImageSize==TextureSize)
origImage->copyTo(Image);
else
// scale texture
origImage->copyToScaling(Image);
uploadTexture(true, mipmapData);
if (!KeepImage)
{
Image->drop();
Image=0;
}
}
//! constructor for basic setup (only for derived classes)
COGLES1Texture::COGLES1Texture(const io::path& name, COGLES1Driver* driver)
: ITexture(name), Driver(driver), Image(0), MipImage(0),
TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA),
PixelType(GL_UNSIGNED_BYTE), MipLevelStored(0),
HasMipMaps(true), IsRenderTarget(false), AutomaticMipmapUpdate(false),
ReadOnlyLock(false), KeepImage(true)
{
#ifdef _DEBUG
setDebugName("COGLES1Texture");
#endif
}
//! destructor
COGLES1Texture::~COGLES1Texture()
{
glDeleteTextures(1, &TextureName);
if (Image)
Image->drop();
}
ECOLOR_FORMAT COGLES1Texture::getBestColorFormat(ECOLOR_FORMAT format)
{
ECOLOR_FORMAT destFormat = ECF_A8R8G8B8;
switch (format)
{
case ECF_A1R5G5B5:
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
destFormat = ECF_A1R5G5B5;
break;
case ECF_R5G6B5:
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
destFormat = ECF_A1R5G5B5;
break;
case ECF_A8R8G8B8:
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) ||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
destFormat = ECF_A1R5G5B5;
break;
case ECF_R8G8B8:
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) ||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
destFormat = ECF_A1R5G5B5;
break;
}
if (Driver->getTextureCreationFlag(ETCF_NO_ALPHA_CHANNEL))
{
switch (destFormat)
{
case ECF_A1R5G5B5:
destFormat = ECF_R5G6B5;
break;
case ECF_A8R8G8B8:
destFormat = ECF_R8G8B8;
break;
default:
break;
}
}
return destFormat;
}
void COGLES1Texture::getImageValues(IImage* image)
{
if (!image)
{
os::Printer::log("No image for OGLES1 texture.", ELL_ERROR);
return;
}
ImageSize = image->getDimension();
if ( !ImageSize.Width || !ImageSize.Height)
{
os::Printer::log("Invalid size of image for OGLES1 Texture.", ELL_ERROR);
return;
}
const f32 ratio = (f32)ImageSize.Width/(f32)ImageSize.Height;
if ((ImageSize.Width>Driver->MaxTextureSize) && (ratio >= 1.0f))
{
ImageSize.Width = Driver->MaxTextureSize;
ImageSize.Height = (u32)(Driver->MaxTextureSize/ratio);
}
else if (ImageSize.Height>Driver->MaxTextureSize)
{
ImageSize.Height = Driver->MaxTextureSize;
ImageSize.Width = (u32)(Driver->MaxTextureSize*ratio);
}
TextureSize=ImageSize.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT));
ColorFormat = getBestColorFormat(image->getColorFormat());
}
//! copies the the texture into an open gl texture.
void COGLES1Texture::uploadTexture(bool newTexture, void* mipmapData, u32 level)
{
IImage* image = level?MipImage:Image;
if (!image)
{
os::Printer::log("No image for OGLES1 texture to upload", ELL_ERROR);
return;
}
#ifndef GL_BGRA
// whoa, pretty badly implemented extension...
if (Driver->FeatureAvailable[COGLES1ExtensionHandler::IRR_IMG_texture_format_BGRA8888] || Driver->FeatureAvailable[COGLES1ExtensionHandler::IRR_EXT_texture_format_BGRA8888])
GL_BGRA=0x80E1;
else
GL_BGRA=GL_RGBA;
#endif
GLenum oldInternalFormat = InternalFormat;
void(*convert)(const void*, s32, void*)=0;
switch (Image->getColorFormat())
{
case ECF_A1R5G5B5:
InternalFormat=GL_RGBA;
PixelFormat=GL_RGBA;
PixelType=GL_UNSIGNED_SHORT_5_5_5_1;
convert=CColorConverter::convert_A1R5G5B5toR5G5B5A1;
break;
case ECF_R5G6B5:
InternalFormat=GL_RGB;
PixelFormat=GL_RGB;
PixelType=GL_UNSIGNED_SHORT_5_6_5;
break;
case ECF_R8G8B8:
InternalFormat=GL_RGB;
PixelFormat=GL_RGB;
PixelType=GL_UNSIGNED_BYTE;
convert=CColorConverter::convert_R8G8B8toB8G8R8;
break;
case ECF_A8R8G8B8:
PixelType=GL_UNSIGNED_BYTE;
if (!Driver->queryOpenGLFeature(COGLES1ExtensionHandler::IRR_IMG_texture_format_BGRA8888) && !Driver->queryOpenGLFeature(COGLES1ExtensionHandler::IRR_EXT_texture_format_BGRA8888))
{
convert=CColorConverter::convert_A8R8G8B8toA8B8G8R8;
InternalFormat=GL_RGBA;
PixelFormat=GL_RGBA;
}
else
{
InternalFormat=GL_BGRA;
PixelFormat=GL_BGRA;
}
break;
default:
os::Printer::log("Unsupported texture format", ELL_ERROR);
break;
}
// Hack for iPhone SDK, which requires a different InternalFormat
#ifdef _IRR_IPHONE_PLATFORM_
if (InternalFormat==GL_BGRA)
InternalFormat=GL_RGBA;
#endif
// make sure we don't change the internal format of existing matrices
if (!newTexture)
InternalFormat=oldInternalFormat;
Driver->setActiveTexture(0, this);
if (Driver->testGLError())
os::Printer::log("Could not bind Texture", ELL_ERROR);
if (!level && newTexture)
{
#ifndef DISABLE_MIPMAPPING
if (HasMipMaps && !mipmapData && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE))
{
// automatically generate and update mipmaps
glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
AutomaticMipmapUpdate=true;
}
else
{
AutomaticMipmapUpdate=false;
regenerateMipMapLevels(mipmapData);
}
if (HasMipMaps) // might have changed in regenerateMipMapLevels
{
// enable bilinear mipmap filter
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
#else
HasMipMaps=false;
os::Printer::log("Did not create OGLES1 texture mip maps.", ELL_ERROR);
#endif
{
// enable bilinear filter without mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
}
void* source = image->lock();
IImage* tmpImage=0;
if (convert)
{
tmpImage = new CImage(image->getColorFormat(), image->getDimension());
void* dest = tmpImage->lock();
convert(source, image->getDimension().getArea(), dest);
image->unlock();
source = dest;
}
if (newTexture)
glTexImage2D(GL_TEXTURE_2D, level, InternalFormat, image->getDimension().Width,
image->getDimension().Height, 0, PixelFormat, PixelType, source);
else
glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width,
image->getDimension().Height, PixelFormat, PixelType, source);
if (convert)
{
tmpImage->unlock();
tmpImage->drop();
}
else
image->unlock();
if (Driver->testGLError())
os::Printer::log("Could not glTexImage2D", ELL_ERROR);
}
//! lock function
void* COGLES1Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel)
{
// store info about which image is locked
IImage* image = (mipmapLevel==0)?Image:MipImage;
ReadOnlyLock |= (mode==ETLM_READ_ONLY);
MipLevelStored = mipmapLevel;
if (!Image)
Image = new CImage(ECF_A8R8G8B8, ImageSize);
if (IsRenderTarget)
{
u8* pPixels = static_cast<u8*>(Image->lock());
if (!pPixels)
{
return 0;
}
// we need to keep the correct texture bound...
GLint tmpTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &tmpTexture);
glBindTexture(GL_TEXTURE_2D, TextureName);
// TODO ogl-es
// glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, pPixels);
// opengl images are horizontally flipped, so we have to fix that here.
const u32 pitch=Image->getPitch();
u8* p2 = pPixels + (ImageSize.Height - 1) * pitch;
u8* tmpBuffer = new u8[pitch];
for (u32 i=0; i < ImageSize.Height; i += 2)
{
memcpy(tmpBuffer, pPixels, pitch);
memcpy(pPixels, p2, pitch);
memcpy(p2, tmpBuffer, pitch);
pPixels += pitch;
p2 -= pitch;
}
delete [] tmpBuffer;
Image->unlock();
//reset old bound texture
glBindTexture(GL_TEXTURE_2D, tmpTexture);
}
return Image->lock();
}
//! unlock function
void COGLES1Texture::unlock()
{
Image->unlock();
if (!ReadOnlyLock)
uploadTexture(false);
ReadOnlyLock = false;
}
//! Returns size of the original image.
const core::dimension2d<u32>& COGLES1Texture::getOriginalSize() const
{
return ImageSize;
}
//! Returns size of the texture.
const core::dimension2d<u32>& COGLES1Texture::getSize() const
{
if (Image)
return Image->getDimension();
else
return ImageSize;
}
//! returns driver type of texture, i.e. the driver, which created the texture
E_DRIVER_TYPE COGLES1Texture::getDriverType() const
{
return EDT_OGLES1;
}
//! returns color format of texture
ECOLOR_FORMAT COGLES1Texture::getColorFormat() const
{
if (Image)
return Image->getColorFormat();
else
return ECF_A8R8G8B8;
}
//! returns pitch of texture (in bytes)
u32 COGLES1Texture::getPitch() const
{
if (Image)
return Image->getPitch();
else
return 0;
}
//! return open gl texture name
GLuint COGLES1Texture::getOGLES1TextureName() const
{
return TextureName;
}
//! Returns whether this texture has mipmaps
bool COGLES1Texture::hasMipMaps() const
{
return HasMipMaps;
}
//! Regenerates the mip map levels of the texture.
void COGLES1Texture::regenerateMipMapLevels(void* mipmapData)
{
if (AutomaticMipmapUpdate || !HasMipMaps || !Image)
return;
if ((Image->getDimension().Width==1) && (Image->getDimension().Height==1))
return;
// Manually create mipmaps
u32 width=Image->getDimension().Width;
u32 height=Image->getDimension().Height;
u32 i=0;
if (mipmapData)
{
do
{
if (width>1)
width>>=1;
if (height>1)
height>>=1;
++i;
glTexImage2D(GL_TEXTURE_2D, i, InternalFormat, width, height,
0, PixelFormat, PixelType, mipmapData);
mipmapData = ((u8*)mipmapData)+width*height*Image->getBytesPerPixel();
}
while (width!=1 || height!=1);
}
else
{
u8* target = new u8[Image->getImageDataSizeInBytes()];
do
{
if (width>1)
width>>=1;
if (height>1)
height>>=1;
++i;
Image->copyToScaling(target, width, height, Image->getColorFormat());
glTexImage2D(GL_TEXTURE_2D, i, InternalFormat, width, height,
0, PixelFormat, PixelType, target);
}
while (width!=1 || height!=1);
delete [] target;
}
}
bool COGLES1Texture::isRenderTarget() const
{
return IsRenderTarget;
}
bool COGLES1Texture::isFrameBufferObject() const
{
return false;
}
void COGLES1Texture::setIsRenderTarget(bool isTarget)
{
IsRenderTarget = isTarget;
}
//! Bind Render Target Texture
void COGLES1Texture::bindRTT()
{
glViewport(0, 0, getSize().Width, getSize().Height);
}
//! Unbind Render Target Texture
void COGLES1Texture::unbindRTT()
{
glBindTexture(GL_TEXTURE_2D, getOGLES1TextureName());
// Copy Our ViewPort To The Texture
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, getSize().Width, getSize().Height);
}
/* FBO Textures */
#ifdef GL_OES_framebuffer_object
// helper function for render to texture
static bool checkFBOStatus(COGLES1Driver* Driver);
#endif
//! RTT ColorFrameBuffer constructor
COGLES1FBOTexture::COGLES1FBOTexture(const core::dimension2d<u32>& size,
const io::path& name,
COGLES1Driver* driver, ECOLOR_FORMAT format)
: COGLES1Texture(name, driver), DepthTexture(0), ColorFrameBuffer(0)
{
#ifdef _DEBUG
setDebugName("COGLES1Texture_FBO");
#endif
ECOLOR_FORMAT col = getBestColorFormat(format);
switch (col)
{
case ECF_A8R8G8B8:
#ifdef GL_OES_rgb8_rgba8
if (driver->queryOpenGLFeature(video::COGLES1ExtensionHandler::IRR_OES_rgb8_rgba8))
InternalFormat = GL_RGBA8_OES;
else
#endif
InternalFormat = GL_RGB5_A1_OES;
break;
case ECF_R8G8B8:
#ifdef GL_OES_rgb8_rgba8
if (driver->queryOpenGLFeature(video::COGLES1ExtensionHandler::IRR_OES_rgb8_rgba8))
InternalFormat = GL_RGB8_OES;
else
#endif
InternalFormat = GL_RGB565_OES;
break;
case ECF_A1R5G5B5:
InternalFormat = GL_RGB5_A1_OES;
break;
case ECF_R5G6B5:
InternalFormat = GL_RGB565_OES;
break;
}
PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_BYTE;
ImageSize = size;
HasMipMaps = false;
IsRenderTarget = true;
#ifdef GL_OES_framebuffer_object
// generate frame buffer
Driver->extGlGenFramebuffers(1, &ColorFrameBuffer);
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_OES, ColorFrameBuffer);
// generate color texture
glGenTextures(1, &TextureName);
glBindTexture(GL_TEXTURE_2D, TextureName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, ImageSize.Width,
ImageSize.Height, 0, PixelFormat, PixelType, 0);
// attach color texture to frame buffer
Driver->extGlFramebufferTexture2D(GL_FRAMEBUFFER_OES,
GL_COLOR_ATTACHMENT0_OES,
GL_TEXTURE_2D,
TextureName,
0);
#endif
unbindRTT();
}
//! destructor
COGLES1FBOTexture::~COGLES1FBOTexture()
{
if (DepthTexture)
if (DepthTexture->drop())
Driver->removeDepthTexture(DepthTexture);
if (ColorFrameBuffer)
Driver->extGlDeleteFramebuffers(1, &ColorFrameBuffer);
}
bool COGLES1FBOTexture::isFrameBufferObject() const
{
return true;
}
//! Bind Render Target Texture
void COGLES1FBOTexture::bindRTT()
{
#ifdef GL_OES_framebuffer_object
if (ColorFrameBuffer != 0)
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_OES, ColorFrameBuffer);
#endif
}
//! Unbind Render Target Texture
void COGLES1FBOTexture::unbindRTT()
{
#ifdef GL_OES_framebuffer_object
if (ColorFrameBuffer != 0)
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_OES, 0);
#endif
}
/* FBO Depth Textures */
//! RTT DepthBuffer constructor
COGLES1FBODepthTexture::COGLES1FBODepthTexture(
const core::dimension2d<u32>& size,
const io::path& name,
COGLES1Driver* driver,
bool useStencil)
: COGLES1FBOTexture(size, name, driver), DepthRenderBuffer(0),
StencilRenderBuffer(0), UseStencil(useStencil)
{
#ifdef _DEBUG
setDebugName("COGLES1TextureFBO_Depth");
#endif
ImageSize = size;
#ifdef GL_OES_depth24
InternalFormat = GL_DEPTH_COMPONENT24_OES;
#elif defined(GL_OES_depth32)
InternalFormat = GL_DEPTH_COMPONENT32_OES;
#else
InternalFormat = GL_DEPTH_COMPONENT16_OES;
#endif
PixelFormat = GL_RGBA;
PixelType = GL_UNSIGNED_BYTE;
HasMipMaps = false;
if (useStencil)
{
#ifdef GL_OES_packed_depth_stencil
glGenTextures(1, &DepthRenderBuffer);
glBindTexture(GL_TEXTURE_2D, DepthRenderBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (Driver->queryOpenGLFeature(COGLES1ExtensionHandler::IRR_OES_packed_depth_stencil))
{
// generate packed depth stencil texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, ImageSize.Width,
ImageSize.Height, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, 0);
StencilRenderBuffer = DepthRenderBuffer; // stencil is packed with depth
return;
}
#endif
#if defined(GL_OES_framebuffer_object) && (defined(GL_OES_stencil1) || defined(GL_OES_stencil4) || defined(GL_OES_stencil8))
// generate stencil buffer
Driver->extGlGenRenderbuffers(1, &StencilRenderBuffer);
Driver->extGlBindRenderbuffer(GL_RENDERBUFFER_OES, StencilRenderBuffer);
Driver->extGlRenderbufferStorage(GL_RENDERBUFFER_OES,
#if defined(GL_OES_stencil8)
GL_STENCIL_INDEX8_OES,
#elif defined(GL_OES_stencil4)
GL_STENCIL_INDEX4_OES,
#elif defined(GL_OES_stencil1)
GL_STENCIL_INDEX1_OES,
#endif
ImageSize.Width, ImageSize.Height);
#endif
}
#ifdef GL_OES_framebuffer_object
// generate depth buffer
Driver->extGlGenRenderbuffers(1, &DepthRenderBuffer);
Driver->extGlBindRenderbuffer(GL_RENDERBUFFER_OES, DepthRenderBuffer);
Driver->extGlRenderbufferStorage(GL_RENDERBUFFER_OES,
InternalFormat, ImageSize.Width, ImageSize.Height);
#endif
}
//! destructor
COGLES1FBODepthTexture::~COGLES1FBODepthTexture()
{
if (DepthRenderBuffer && UseStencil)
glDeleteTextures(1, &DepthRenderBuffer);
else
Driver->extGlDeleteRenderbuffers(1, &DepthRenderBuffer);
if (StencilRenderBuffer && StencilRenderBuffer != DepthRenderBuffer)
glDeleteTextures(1, &StencilRenderBuffer);
}
//combine depth texture and rtt
void COGLES1FBODepthTexture::attach(ITexture* renderTex)
{
if (!renderTex)
return;
video::COGLES1FBOTexture* rtt = static_cast<video::COGLES1FBOTexture*>(renderTex);
rtt->bindRTT();
#ifdef GL_OES_framebuffer_object
if (UseStencil)
{
// attach stencil texture to stencil buffer
Driver->extGlFramebufferTexture2D(GL_FRAMEBUFFER_OES,
GL_STENCIL_ATTACHMENT_OES,
GL_TEXTURE_2D,
StencilRenderBuffer,
0);
// attach depth texture to depth buffer
Driver->extGlFramebufferTexture2D(GL_FRAMEBUFFER_OES,
GL_DEPTH_ATTACHMENT_OES,
GL_TEXTURE_2D,
DepthRenderBuffer,
0);
}
else
{
// attach depth renderbuffer to depth buffer
Driver->extGlFramebufferRenderbuffer(GL_FRAMEBUFFER_OES,
GL_DEPTH_ATTACHMENT_OES,
GL_RENDERBUFFER_OES,
DepthRenderBuffer);
}
// check the status
if (!checkFBOStatus(Driver))
os::Printer::log("FBO incomplete");
#endif
rtt->DepthTexture=this;
grab(); // grab the depth buffer, not the RTT
rtt->unbindRTT();
}
//! Bind Render Target Texture
void COGLES1FBODepthTexture::bindRTT()
{
}
//! Unbind Render Target Texture
void COGLES1FBODepthTexture::unbindRTT()
{
}
#ifdef GL_OES_framebuffer_object
bool checkFBOStatus(COGLES1Driver* Driver)
{
GLenum status = Driver->extGlCheckFramebufferStatus(GL_FRAMEBUFFER_OES);
switch (status)
{
//Our FBO is perfect, return true
case GL_FRAMEBUFFER_COMPLETE_OES:
return true;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES:
os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES:
os::Printer::log("FBO missing an image attachment", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES:
os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES:
os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR);
break;
// not part of all implementations
#ifdef GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_OES
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_OES:
os::Printer::log("FBO has invalid draw buffer", ELL_ERROR);
break;
#endif
// not part of all implementations
#ifdef GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_OES
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_OES:
os::Printer::log("FBO has invalid read buffer", ELL_ERROR);
break;
#endif
// not part of fbo_object anymore, but won't harm as it is just a return value
#ifdef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_OES
case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_OES:
os::Printer::log("FBO has a duplicate image attachment", ELL_ERROR);
break;
#endif
case GL_FRAMEBUFFER_UNSUPPORTED_OES:
os::Printer::log("FBO format unsupported", ELL_ERROR);
break;
default:
break;
}
os::Printer::log("FBO error", ELL_ERROR);
return false;
}
#endif
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_OGLES1_

View File

@ -0,0 +1,177 @@
// Copyright (C) 2002-2008 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_OGLES1_TEXTURE_H_INCLUDED__
#define __C_OGLES1_TEXTURE_H_INCLUDED__
#include "ITexture.h"
#include "IImage.h"
#include "IrrCompileConfig.h"
#if defined(_IRR_COMPILE_WITH_OGLES1_)
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#elif defined(_IRR_ANDROID_PLATFORM_)
#include <GLES/gl.h>
#include <GLES/glext.h>
#else
#include <GLES/egl.h>
#endif
namespace irr
{
namespace video
{
class COGLES1Driver;
//! OGLES1 texture.
class COGLES1Texture : public ITexture
{
public:
//! constructor
COGLES1Texture(IImage* surface, const io::path& name, COGLES1Driver* driver=0, void* mipmapData=0);
//! destructor
virtual ~COGLES1Texture();
//! lock function
virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0);
//! unlock function
virtual void unlock();
//! Returns original size of the texture (image).
virtual const core::dimension2d<u32>& getOriginalSize() const;
//! Returns size of the texture.
virtual const core::dimension2d<u32>& getSize() const;
//! returns driver type of texture (=the driver, that created it)
virtual E_DRIVER_TYPE getDriverType() const;
//! 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
GLuint getOGLES1TextureName() const;
//! return whether this texture has mipmaps
virtual bool hasMipMaps() const;
//! Regenerates the mip map levels of the texture.
virtual void regenerateMipMapLevels(void* mipmapData=0);
//! Is it a render target?
virtual bool isRenderTarget() const;
//! Is it a FrameBufferObject?
virtual bool isFrameBufferObject() const;
//! Bind RenderTargetTexture
void bindRTT();
//! Unbind RenderTargetTexture
void unbindRTT();
//! sets whether this texture is intended to be used as a render target.
void setIsRenderTarget(bool isTarget);
protected:
//! protected constructor with basic setup, no GL texture name created, for derived classes
COGLES1Texture(const io::path& name, COGLES1Driver* driver);
//! 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.
void getImageValues(IImage* image);
//! copies the the texture into an open gl texture.
void uploadTexture(bool newTexture=true, void* mipmapData=0, u32 mipLevel=0);
core::dimension2d<u32> ImageSize;
core::dimension2d<u32> TextureSize;
ECOLOR_FORMAT ColorFormat;
COGLES1Driver* Driver;
IImage* Image;
IImage* MipImage;
GLuint TextureName;
GLint InternalFormat;
GLenum PixelFormat;
GLenum PixelType;
u32 MipLevelStored;
bool HasMipMaps;
bool IsRenderTarget;
bool AutomaticMipmapUpdate;
bool UseStencil;
bool ReadOnlyLock;
bool KeepImage;
};
//! OGLES1 FBO texture.
class COGLES1FBOTexture : public COGLES1Texture
{
public:
//! FrameBufferObject constructor
COGLES1FBOTexture(const core::dimension2d<u32>& size, const io::path& name, COGLES1Driver* driver=0, ECOLOR_FORMAT format = ECF_UNKNOWN);
//! destructor
virtual ~COGLES1FBOTexture();
//! Is it a FrameBufferObject?
virtual bool isFrameBufferObject() const;
//! Bind RenderTargetTexture
virtual void bindRTT();
//! Unbind RenderTargetTexture
virtual void unbindRTT();
ITexture* DepthTexture;
protected:
GLuint ColorFrameBuffer;
};
//! OGLES1 FBO depth texture.
class COGLES1FBODepthTexture : public COGLES1FBOTexture
{
public:
//! FrameBufferObject depth constructor
COGLES1FBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COGLES1Driver* driver=0, bool useStencil=false);
//! destructor
virtual ~COGLES1FBODepthTexture();
//! Bind RenderTargetTexture
virtual void bindRTT();
//! Unbind RenderTargetTexture
virtual void unbindRTT();
void attach(ITexture*);
protected:
GLuint DepthRenderBuffer;
GLuint StencilRenderBuffer;
bool UseStencil;
};
} // end namespace video
} // end namespace irr
#endif
#endif // _IRR_COMPILE_WITH_OGLES1_

View File

@ -14,7 +14,7 @@
#if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__)
#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <linux/sysctl.h>
#endif
#endif

File diff suppressed because it is too large Load Diff