diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 229d920d5..001eb7288 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1851,8 +1851,7 @@ shader_path (Shader path) path # The rendering back-end. # Note: A restart is required after changing this! # OpenGL is the default for desktop, and OGLES2 for Android. -# Shaders are supported by everything but OGLES1. -video_driver (Video driver) enum ,opengl,opengl3,ogles1,ogles2 +video_driver (Video driver) enum ,opengl,opengl3,ogles2 # Distance in nodes at which transparency depth sorting is enabled # Use this to limit the performance impact of transparency depth sorting diff --git a/irr/README.md b/irr/README.md index 640b82c6f..50e7338a5 100644 --- a/irr/README.md +++ b/irr/README.md @@ -20,7 +20,6 @@ The following libraries are required to be installed: Aside from standard search options (`ZLIB_INCLUDE_DIR`, `ZLIB_LIBRARY`, ...) the following options are available: * `ENABLE_OPENGL` - Enable OpenGL driver * `ENABLE_OPENGL3` (default: `OFF`) - Enable OpenGL 3+ driver -* `ENABLE_GLES1` - Enable OpenGL ES driver, legacy * `ENABLE_GLES2` - Enable OpenGL ES 2+ driver * `USE_SDL2` (default: platform-dependent, usually `ON`) - Use SDL2 instead of older native device code diff --git a/irr/include/EDriverTypes.h b/irr/include/EDriverTypes.h index 33f987889..f19e65ace 100644 --- a/irr/include/EDriverTypes.h +++ b/irr/include/EDriverTypes.h @@ -24,9 +24,6 @@ enum E_DRIVER_TYPE 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, diff --git a/irr/src/CEGLManager.cpp b/irr/src/CEGLManager.cpp index ffe7a44cf..daaa64fdf 100644 --- a/irr/src/CEGLManager.cpp +++ b/irr/src/CEGLManager.cpp @@ -152,9 +152,6 @@ EGLConfig CEGLManager::chooseConfig(EConfigStyle confStyle) // Find proper OpenGL BIT. EGLint eglOpenGLBIT = 0; switch (Params.DriverType) { - case EDT_OGLES1: - eglOpenGLBIT = EGL_OPENGL_ES_BIT; - break; case EDT_OGLES2: case EDT_WEBGL1: eglOpenGLBIT = EGL_OPENGL_ES2_BIT; @@ -459,9 +456,6 @@ bool CEGLManager::generateContext() EGLint OpenGLESVersion = 0; switch (Params.DriverType) { - case EDT_OGLES1: - OpenGLESVersion = 1; - break; case EDT_OGLES2: case EDT_WEBGL1: OpenGLESVersion = 2; diff --git a/irr/src/CIrrDeviceLinux.cpp b/irr/src/CIrrDeviceLinux.cpp index 5491d2037..5e3afae36 100644 --- a/irr/src/CIrrDeviceLinux.cpp +++ b/irr/src/CIrrDeviceLinux.cpp @@ -33,7 +33,7 @@ #include #endif -#if defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) +#if defined(_IRR_COMPILE_WITH_OGLES2_) #include "CEGLManager.h" #endif @@ -76,10 +76,6 @@ namespace video IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); #endif -#ifdef _IRR_COMPILE_WITH_OGLES1_ -IVideoDriver *createOGLES1Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif - #ifdef _IRR_COMPILE_WITH_OGLES2_ IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); #endif @@ -554,22 +550,6 @@ void CIrrDeviceLinux::createDriver() } #else os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); -#endif - break; - case video::EDT_OGLES1: -#ifdef _IRR_COMPILE_WITH_OGLES1_ - { - video::SExposedVideoData data; - data.OpenGLLinux.X11Window = XWindow; - data.OpenGLLinux.X11Display = XDisplay; - - ContextManager = new video::CEGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); - } -#else - os::Printer::log("No OpenGL-ES1 support compiled in.", ELL_ERROR); #endif break; case video::EDT_OGLES2: diff --git a/irr/src/CIrrDeviceOSX.mm b/irr/src/CIrrDeviceOSX.mm index 67c0ce05c..e335085e4 100644 --- a/irr/src/CIrrDeviceOSX.mm +++ b/irr/src/CIrrDeviceOSX.mm @@ -720,9 +720,8 @@ void CIrrDeviceMacOSX::createDriver() #endif break; - case video::EDT_OGLES1: case video::EDT_OGLES2: - os::Printer::log("This driver is not available in OSX. Try OpenGL or Software renderer.", ELL_ERROR); + os::Printer::log("This driver is not available on OSX.", ELL_ERROR); break; case video::EDT_NULL: diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index ffbd81950..58fba4f25 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -594,18 +594,14 @@ bool CIrrDeviceSDL::createWindowWithContext() SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); break; - case video::EDT_OGLES1: - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - break; case video::EDT_OGLES2: case video::EDT_WEBGL1: SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); break; - default:; + default: + _IRR_DEBUG_BREAK_IF(1); } if (CreationParams.DriverDebug) { diff --git a/irr/src/CIrrDeviceWin32.cpp b/irr/src/CIrrDeviceWin32.cpp index c2876fcce..fe5293988 100644 --- a/irr/src/CIrrDeviceWin32.cpp +++ b/irr/src/CIrrDeviceWin32.cpp @@ -29,7 +29,7 @@ #endif #endif -#if defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) +#if defined(_IRR_COMPILE_WITH_OGLES2_) #include "CEGLManager.h" #endif @@ -45,10 +45,6 @@ namespace video IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); #endif -#ifdef _IRR_COMPILE_WITH_OGLES1_ -IVideoDriver *createOGLES1Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif - #ifdef _IRR_COMPILE_WITH_OGLES2_ IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); #endif @@ -890,21 +886,6 @@ void CIrrDeviceWin32::createDriver() os::Printer::log("Could not create OpenGL driver.", ELL_ERROR); #else os::Printer::log("OpenGL driver was not compiled in.", ELL_ERROR); -#endif - break; - case video::EDT_OGLES1: -#ifdef _IRR_COMPILE_WITH_OGLES1_ - switchToFullScreen(); - - ContextManager = new video::CEGLManager(); - ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd)); - - VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); - - if (!VideoDriver) - os::Printer::log("Could not create OpenGL-ES1 driver.", ELL_ERROR); -#else - os::Printer::log("OpenGL-ES1 driver was not compiled in.", ELL_ERROR); #endif break; case video::EDT_OGLES2: diff --git a/irr/src/CMakeLists.txt b/irr/src/CMakeLists.txt index d5e9d47e7..2bc935b9f 100644 --- a/irr/src/CMakeLists.txt +++ b/irr/src/CMakeLists.txt @@ -130,12 +130,6 @@ else() option(ENABLE_OPENGL "Enable OpenGL" TRUE) endif() -if(USE_SDL2 OR EMSCRIPTEN OR APPLE) - set(ENABLE_GLES1 FALSE) -else() - option(ENABLE_GLES1 "Enable OpenGL ES" FALSE) -endif() - if(APPLE) set(ENABLE_GLES2 FALSE) set(ENABLE_WEBGL1 FALSE) @@ -172,14 +166,6 @@ if(ENABLE_OPENGL3) endif() endif() -if(ENABLE_GLES1) - add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) - set(OPENGLES_DIRECT_LINK TRUE) - if(DEVICE MATCHES "^(WINDOWS|X11)$") - add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_) - endif() -endif() - if(ENABLE_GLES2) add_definitions(-D_IRR_COMPILE_WITH_OGLES2_) if(DEVICE MATCHES "^(WINDOWS|X11)$" OR EMSCRIPTEN) @@ -204,7 +190,6 @@ endif() message(STATUS "Device: ${DEVICE}") message(STATUS "OpenGL: ${ENABLE_OPENGL}") message(STATUS "OpenGL 3: ${ENABLE_OPENGL3}") -message(STATUS "OpenGL ES: ${ENABLE_GLES1}") if (ENABLE_GLES2) message(STATUS "OpenGL ES 2: ON (unified)") else() @@ -220,13 +205,6 @@ find_package(ZLIB REQUIRED) find_package(JPEG REQUIRED) find_package(PNG REQUIRED) -if(ENABLE_GLES1) - # only tested on Android, probably works on Linux (is this needed anywhere else?) - find_library(OPENGLES_LIBRARY NAMES GLESv1_CM REQUIRED) - find_library(EGL_LIBRARY NAMES EGL REQUIRED) - - message(STATUS "Found OpenGLES: ${OPENGLES_LIBRARY}") -endif() if(ENABLE_GLES2) find_package(OpenGLES2 REQUIRED) endif() @@ -360,14 +338,6 @@ if(ENABLE_OPENGL) ) endif() -if(ENABLE_GLES1) - set(IRRDRVROBJ - ${IRRDRVROBJ} - COGLESDriver.cpp - COGLESExtensionHandler.cpp - ) -endif() - # the unified drivers if(ENABLE_OPENGL3 OR ENABLE_GLES2) @@ -509,7 +479,6 @@ target_link_libraries(IrrlichtMt PRIVATE "$<$:SDL2::SDL2>" "$<$:${OPENGL_LIBRARIES}>" - "$<$:${OPENGLES_LIBRARY}>" ${EGL_LIBRARY} # incl. transitive SDL2 dependencies for static linking diff --git a/irr/src/COGLESCommon.h b/irr/src/COGLESCommon.h deleted file mode 100644 index 1d439546a..000000000 --- a/irr/src/COGLESCommon.h +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#pragma once - -#ifdef _IRR_COMPILE_WITH_OGLES1_ - -#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_) -#include -#include -#elif defined(_IRR_OGLES1_USE_KHRONOS_API_HEADERS_) -#include -#include -typedef char GLchar; -#else // or only when defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) ? -#include -#include -#include -#endif - -#ifndef GL_BGRA -#define GL_BGRA 0x80E1; -#endif - -// Blending definitions. - -#if defined(GL_OES_blend_subtract) -#define GL_FUNC_ADD GL_FUNC_ADD_OES -#else -#define GL_FUNC_ADD 0 -#endif - -// FBO definitions. - -#ifdef GL_OES_framebuffer_object -#define GL_NONE 0 // iOS has missing definition of GL_NONE_OES -#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES -#define GL_DEPTH_COMPONENT16 GL_DEPTH_COMPONENT16_OES -#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES -#define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES -#define GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT_OES -#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 1 -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 2 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES -#define GL_FRAMEBUFFER_UNSUPPORTED GL_FRAMEBUFFER_UNSUPPORTED_OES -#else -#define GL_NONE 0 -#define GL_FRAMEBUFFER 0 -#define GL_DEPTH_COMPONENT16 0 -#define GL_COLOR_ATTACHMENT0 0 -#define GL_DEPTH_ATTACHMENT 0 -#define GL_STENCIL_ATTACHMENT 0 -#define GL_FRAMEBUFFER_COMPLETE 0 -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 1 -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 2 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 3 -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 4 -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 5 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 6 -#define GL_FRAMEBUFFER_UNSUPPORTED 7 -#endif - -#define GL_DEPTH_COMPONENT 0x1902 - -// Texture definitions. - -#ifdef GL_OES_texture_cube_map -#define GL_TEXTURE_CUBE_MAP GL_TEXTURE_CUBE_MAP_OES -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES -#else -#define GL_TEXTURE_CUBE_MAP 0 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0 -#endif - -// to check if this header is in the current compile unit (different GL implementation used different "GLCommon" headers in Irrlicht -#define IRR_COMPILE_GLES_COMMON - -// macro used with COGLES1Driver -#define TEST_GL_ERROR(cls) (cls)->testGLError(__LINE__) - -namespace irr -{ -namespace video -{ - -// Forward declarations. - -class COpenGLCoreFeature; - -template -class COpenGLCoreTexture; - -template -class COpenGLCoreRenderTarget; - -template -class COpenGLCoreCacheHandler; - -class COGLES1Driver; -typedef COpenGLCoreTexture COGLES1Texture; -typedef COpenGLCoreRenderTarget COGLES1RenderTarget; -typedef COpenGLCoreCacheHandler COGLES1CacheHandler; - -} -} - -#endif diff --git a/irr/src/COGLESDriver.cpp b/irr/src/COGLESDriver.cpp deleted file mode 100644 index d5feda58e..000000000 --- a/irr/src/COGLESDriver.cpp +++ /dev/null @@ -1,2346 +0,0 @@ -// 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 "COGLESDriver.h" -#include -#include "CNullDriver.h" -#include "IContextManager.h" - -#ifdef _IRR_COMPILE_WITH_OGLES1_ - -#include "COpenGLCoreTexture.h" -#include "COpenGLCoreRenderTarget.h" -#include "COpenGLCoreCacheHandler.h" - -#include "COGLESMaterialRenderer.h" - -#include "EVertexAttributes.h" -#include "CImage.h" -#include "os.h" - -namespace irr -{ -namespace video -{ - -COGLES1Driver::COGLES1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) : - CNullDriver(io, params.WindowSize), COGLES1ExtensionHandler(), CacheHandler(0), CurrentRenderMode(ERM_NONE), - ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(params.AntiAlias), - ColorFormat(ECF_R8G8B8), Params(params), ContextManager(contextManager) -{ -#ifdef _DEBUG - setDebugName("COGLESDriver"); -#endif - - core::dimension2d windowSize(0, 0); - - if (!ContextManager) - return; - - ContextManager->grab(); - ContextManager->generateSurface(); - ContextManager->generateContext(); - ExposedData = ContextManager->getContext(); - ContextManager->activateContext(ExposedData, false); - - windowSize = params.WindowSize; - - genericDriverInit(windowSize, params.Stencilbuffer); -} - -COGLES1Driver::~COGLES1Driver() -{ - deleteMaterialRenders(); - - CacheHandler->getTextureCache().clear(); - - removeAllRenderTargets(); - deleteAllTextures(); - removeAllOcclusionQueries(); - removeAllHardwareBuffers(); - - delete CacheHandler; - - if (ContextManager) { - ContextManager->destroyContext(); - ContextManager->destroySurface(); - ContextManager->terminate(); - ContextManager->drop(); - } -} - -// ----------------------------------------------------------------------- -// METHODS -// ----------------------------------------------------------------------- - -bool COGLES1Driver::genericDriverInit(const core::dimension2d &screenSize, bool stencilBuffer) -{ - Name = glGetString(GL_VERSION); - printVersion(); - - // print renderer information - VendorName = glGetString(GL_VENDOR); - os::Printer::log(VendorName.c_str(), ELL_INFORMATION); - - // load extensions - initExtensions(); - - // reset cache handler - delete CacheHandler; - CacheHandler = new COGLES1CacheHandler(this); - - StencilBuffer = stencilBuffer; - - DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); - DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); - DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); - DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices); - DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize); - DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias); - DriverAttributes->setAttribute("Version", Version); - DriverAttributes->setAttribute("AntiAlias", AntiAlias); - - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - for (s32 i = 0; i < ETS_COUNT; ++i) - setTransform(static_cast(i), core::IdentityMatrix); - - setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); - glClearDepthf(1.0f); - - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); - glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); - glDepthFunc(GL_LEQUAL); - glFrontFace(GL_CW); - glAlphaFunc(GL_GREATER, 0.f); - - // create material renderers - createMaterialRenderers(); - - // set the renderstates - setRenderStates3DMode(); - - // set fog mode - setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog); - - // create matrix for flipping textures - TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f)); - - // We need to reset once more at the beginning of the first rendering. - // This fixes problems with intermediate changes to the material during texture load. - ResetRenderStates = true; - - testGLError(__LINE__); - - return true; -} - -void COGLES1Driver::createMaterialRenderers() -{ - addAndDropMaterialRenderer(new COGLES1MaterialRenderer_SOLID(this)); - addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(this)); - addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(this)); - addAndDropMaterialRenderer(new COGLES1MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(this)); - addAndDropMaterialRenderer(new COGLES1MaterialRenderer_ONETEXTURE_BLEND(this)); -} - -bool COGLES1Driver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData &videoData, core::rect *sourceRect) -{ - CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect); - - if (ContextManager) - ContextManager->activateContext(videoData, true); - - clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); - - return true; -} - -bool COGLES1Driver::endScene() -{ - CNullDriver::endScene(); - - glFlush(); - - if (ContextManager) - return ContextManager->swapBuffers(); - - return false; -} - -//! Returns the transformation set by setTransform -const core::matrix4 &COGLES1Driver::getTransform(E_TRANSFORMATION_STATE state) const -{ - return Matrices[state]; -} - -//! sets transformation -void COGLES1Driver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) -{ - Matrices[state] = mat; - Transformation3DChanged = true; - - switch (state) { - case ETS_VIEW: - case ETS_WORLD: { - // OGLES1 only has a model matrix, view and world is not existent. so lets fake these two. - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); - } break; - case ETS_PROJECTION: { - GLfloat glmat[16]; - getGLMatrix(glmat, mat); - // flip z to compensate OGLES1s right-hand coordinate system - glmat[12] *= -1.0f; - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(glmat); - } break; - default: - break; - } -} - -bool COGLES1Driver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) -{ - if (!HWBuffer) - return false; - - const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; - const void *vertices = mb->getVertices(); - const u32 vertexCount = mb->getVertexCount(); - const E_VERTEX_TYPE vType = mb->getVertexType(); - const u32 vertexSize = getVertexPitchFromType(vType); - - // buffer vertex data, and convert colours... - core::array buffer(vertexSize * vertexCount); - buffer.set_used(vertexSize * vertexCount); - memcpy(buffer.pointer(), vertices, vertexSize * vertexCount); - - // in order to convert the colors into opengl format (RGBA) - switch (vType) { - case EVT_STANDARD: { - S3DVertex *pb = reinterpret_cast(buffer.pointer()); - const S3DVertex *po = static_cast(vertices); - for (u32 i = 0; i < vertexCount; i++) { - po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color.color)); - } - } break; - case EVT_2TCOORDS: { - S3DVertex2TCoords *pb = reinterpret_cast(buffer.pointer()); - const S3DVertex2TCoords *po = static_cast(vertices); - for (u32 i = 0; i < vertexCount; i++) { - po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color.color)); - } - } break; - case EVT_TANGENTS: { - S3DVertexTangents *pb = reinterpret_cast(buffer.pointer()); - const S3DVertexTangents *po = static_cast(vertices); - for (u32 i = 0; i < vertexCount; i++) { - po[i].Color.toOpenGLColor((u8 *)&(pb[i].Color.color)); - } - } break; - default: { - return false; - } - } - - // get or create buffer - bool newBuffer = false; - if (!HWBuffer->vbo_verticesID) { - glGenBuffers(1, &HWBuffer->vbo_verticesID); - if (!HWBuffer->vbo_verticesID) - return false; - newBuffer = true; - } else if (HWBuffer->vbo_verticesSize < vertexCount * vertexSize) { - newBuffer = true; - } - - glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); - - // copy data to graphics card - if (!newBuffer) - glBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, buffer.const_pointer()); - else { - HWBuffer->vbo_verticesSize = vertexCount * vertexSize; - - if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) - glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_STATIC_DRAW); - else - glBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_DYNAMIC_DRAW); - } - - glBindBuffer(GL_ARRAY_BUFFER, 0); - - return (!testGLError(__LINE__)); -} - -bool COGLES1Driver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) -{ - if (!HWBuffer) - return false; - - const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; - - const void *indices = mb->getIndices(); - u32 indexCount = mb->getIndexCount(); - - GLenum indexSize; - switch (mb->getIndexType()) { - case (EIT_16BIT): { - indexSize = sizeof(u16); - break; - } - case (EIT_32BIT): { - indexSize = sizeof(u32); - break; - } - default: { - return false; - } - } - - // get or create buffer - bool newBuffer = false; - if (!HWBuffer->vbo_indicesID) { - glGenBuffers(1, &HWBuffer->vbo_indicesID); - if (!HWBuffer->vbo_indicesID) - return false; - newBuffer = true; - } else if (HWBuffer->vbo_indicesSize < indexCount * indexSize) { - newBuffer = true; - } - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); - - // copy data to graphics card - if (!newBuffer) - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); - else { - HWBuffer->vbo_indicesSize = indexCount * indexSize; - - if (HWBuffer->Mapped_Index == scene::EHM_STATIC) - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW); - else - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW); - } - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - return (!testGLError(__LINE__)); -} - -//! updates hardware buffer if needed -bool COGLES1Driver::updateHardwareBuffer(SHWBufferLink *HWBuffer) -{ - if (!HWBuffer) - return false; - - if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { - if (HWBuffer->ChangedID_Vertex != HWBuffer->MeshBuffer->getChangedID_Vertex() || !static_cast(HWBuffer)->vbo_verticesID) { - - HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); - - if (!updateVertexHardwareBuffer(static_cast(HWBuffer))) - return false; - } - } - - if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { - if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() || !((SHWBufferLink_opengl *)HWBuffer)->vbo_indicesID) { - - HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); - - if (!updateIndexHardwareBuffer(static_cast(HWBuffer))) - return false; - } - } - - return true; -} - -//! Create hardware buffer from meshbuffer -COGLES1Driver::SHWBufferLink *COGLES1Driver::createHardwareBuffer(const scene::IMeshBuffer *mb) -{ - if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) - return 0; - - SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb); - - // add to map - HWBuffer->listPosition = HWBufferList.insert(HWBufferList.end(), HWBuffer); - - HWBuffer->ChangedID_Vertex = HWBuffer->MeshBuffer->getChangedID_Vertex(); - HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); - HWBuffer->Mapped_Vertex = mb->getHardwareMappingHint_Vertex(); - HWBuffer->Mapped_Index = mb->getHardwareMappingHint_Index(); - HWBuffer->vbo_verticesID = 0; - HWBuffer->vbo_indicesID = 0; - HWBuffer->vbo_verticesSize = 0; - HWBuffer->vbo_indicesSize = 0; - - if (!updateHardwareBuffer(HWBuffer)) { - deleteHardwareBuffer(HWBuffer); - return 0; - } - - return HWBuffer; -} - -void COGLES1Driver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) -{ - if (!_HWBuffer) - return; - - SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); - if (HWBuffer->vbo_verticesID) { - glDeleteBuffers(1, &HWBuffer->vbo_verticesID); - HWBuffer->vbo_verticesID = 0; - } - if (HWBuffer->vbo_indicesID) { - glDeleteBuffers(1, &HWBuffer->vbo_indicesID); - HWBuffer->vbo_indicesID = 0; - } - - CNullDriver::deleteHardwareBuffer(_HWBuffer); -} - -//! Draw hardware buffer -void COGLES1Driver::drawHardwareBuffer(SHWBufferLink *_HWBuffer) -{ - if (!_HWBuffer) - return; - - SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); - - updateHardwareBuffer(HWBuffer); // check if update is needed - - const scene::IMeshBuffer *mb = HWBuffer->MeshBuffer; - const void *vertices = mb->getVertices(); - const void *indexList = mb->getIndices(); - - if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { - glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); - vertices = 0; - } - - if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); - indexList = 0; - } - - drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, - mb->getPrimitiveCount(), mb->getVertexType(), - mb->getPrimitiveType(), mb->getIndexType()); - - if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) - glBindBuffer(GL_ARRAY_BUFFER, 0); - - if (HWBuffer->Mapped_Index != scene::EHM_NEVER) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} - -IRenderTarget *COGLES1Driver::addRenderTarget() -{ - COGLES1RenderTarget *renderTarget = new COGLES1RenderTarget(this); - RenderTargets.push_back(renderTarget); - - return renderTarget; -} - -// small helper function to create vertex buffer object adress offsets -static inline u8 *buffer_offset(const long offset) -{ - return ((u8 *)0 + offset); -} - -//! draws a vertex primitive list -void COGLES1Driver::drawVertexPrimitiveList(const void *vertices, u32 vertexCount, - const void *indexList, u32 primitiveCount, - E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) -{ - if (!checkPrimitiveCount(primitiveCount)) - return; - - setRenderStates3DMode(); - - drawVertexPrimitiveList2d3d(vertices, vertexCount, (const u16 *)indexList, primitiveCount, vType, pType, iType); -} - -void COGLES1Driver::drawVertexPrimitiveList2d3d(const void *vertices, u32 vertexCount, - const void *indexList, u32 primitiveCount, - E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType, bool threed) -{ - if (!primitiveCount || !vertexCount) - return; - - if (!threed && !checkPrimitiveCount(primitiveCount)) - return; - - CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); - - if (vertices) { - // convert colors to gl color format. - vertexCount *= 4; // reused as color component count - ColorBuffer.set_used(vertexCount); - u32 i; - - switch (vType) { - case EVT_STANDARD: { - const S3DVertex *p = static_cast(vertices); - for (i = 0; i < vertexCount; i += 4) { - p->Color.toOpenGLColor(&ColorBuffer[i]); - ++p; - } - } break; - case EVT_2TCOORDS: { - const S3DVertex2TCoords *p = static_cast(vertices); - for (i = 0; i < vertexCount; i += 4) { - p->Color.toOpenGLColor(&ColorBuffer[i]); - ++p; - } - } break; - case EVT_TANGENTS: { - const S3DVertexTangents *p = static_cast(vertices); - for (i = 0; i < vertexCount; i += 4) { - p->Color.toOpenGLColor(&ColorBuffer[i]); - ++p; - } - } break; - } - } - - // draw everything - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_VERTEX_ARRAY); - if ((pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES)) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); -#ifdef GL_OES_point_size_array - else if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_size_array] && (Material.Thickness == 0.0f)) - glEnableClientState(GL_POINT_SIZE_ARRAY_OES); -#endif - if (threed && (pType != scene::EPT_POINTS) && (pType != scene::EPT_POINT_SPRITES)) - glEnableClientState(GL_NORMAL_ARRAY); - - if (vertices) - glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); - - switch (vType) { - case EVT_STANDARD: - if (vertices) { - if (threed) - glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Normal); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - } else { - glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12)); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24)); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0); - } - - if (Feature.MaxTextureUnits > 0 && CacheHandler->getTextureCache().get(1)) { - glClientActiveTexture(GL_TEXTURE0 + 1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (vertices) - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - else - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); - } - break; - case EVT_2TCOORDS: - if (vertices) { - if (threed) - glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Normal); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); - glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); - } else { - glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12)); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24)); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28)); - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0)); - } - - if (Feature.MaxTextureUnits > 0) { - glClientActiveTexture(GL_TEXTURE0 + 1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (vertices) - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); - else - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(36)); - } - break; - case EVT_TANGENTS: - if (vertices) { - if (threed) - glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Normal); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); - glVertexPointer((threed ? 3 : 2), GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); - } else { - glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12)); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24)); - glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28)); - glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0)); - } - - if (Feature.MaxTextureUnits > 0) { - glClientActiveTexture(GL_TEXTURE0 + 1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (vertices) - glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Tangent); - else - glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(36)); - - glClientActiveTexture(GL_TEXTURE0 + 2); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (vertices) - glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Binormal); - else - glTexCoordPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(48)); - } - break; - } - - GLenum indexSize = 0; - - switch (iType) { - case (EIT_16BIT): { - indexSize = GL_UNSIGNED_SHORT; - break; - } - case (EIT_32BIT): { -#ifdef GL_OES_element_index_uint -#ifndef GL_UNSIGNED_INT -#define GL_UNSIGNED_INT 0x1405 -#endif - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_element_index_uint]) - indexSize = GL_UNSIGNED_INT; - else -#endif - indexSize = GL_UNSIGNED_SHORT; - break; - } - } - - switch (pType) { - case scene::EPT_POINTS: - case scene::EPT_POINT_SPRITES: { -#ifdef GL_OES_point_sprite - if (pType == scene::EPT_POINT_SPRITES && FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_sprite]) - glEnable(GL_POINT_SPRITE_OES); -#endif - // if ==0 we use the point size array - if (Material.Thickness != 0.f) { - float quadratic[] = {0.0f, 0.0f, 10.01f}; - glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, quadratic); - float maxParticleSize = 1.0f; - glGetFloatv(GL_POINT_SIZE_MAX, &maxParticleSize); - // maxParticleSize=maxParticleSize 0) { - if (vType == EVT_TANGENTS) { - glClientActiveTexture(GL_TEXTURE0 + 2); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - if ((vType != EVT_STANDARD) || CacheHandler->getTextureCache().get(1)) { - glClientActiveTexture(GL_TEXTURE0 + 1); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - glClientActiveTexture(GL_TEXTURE0); - } - -#ifdef GL_OES_point_size_array - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_point_size_array] && (Material.Thickness == 0.0f)) - glDisableClientState(GL_POINT_SIZE_ARRAY_OES); -#endif - - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - -//! draws a 2d image, using a color and the alpha channel of the texture -void COGLES1Driver::draw2DImage(const video::ITexture *texture, - const core::position2d &pos, - const core::rect &sourceRect, - const core::rect *clipRect, SColor color, - bool useAlphaChannelOfTexture) -{ - if (!texture) - return; - - if (!sourceRect.isValid()) - return; - - core::position2d targetPos(pos); - core::position2d sourcePos(sourceRect.UpperLeftCorner); - core::dimension2d sourceSize(sourceRect.getSize()); - if (clipRect) { - if (targetPos.X < clipRect->UpperLeftCorner.X) { - sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X; - if (sourceSize.Width <= 0) - return; - - sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X; - targetPos.X = clipRect->UpperLeftCorner.X; - } - - if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X) { - sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X; - if (sourceSize.Width <= 0) - return; - } - - if (targetPos.Y < clipRect->UpperLeftCorner.Y) { - sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y; - if (sourceSize.Height <= 0) - return; - - sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y; - targetPos.Y = clipRect->UpperLeftCorner.Y; - } - - if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y) { - sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y; - if (sourceSize.Height <= 0) - return; - } - } - - // clip these coordinates - - if (targetPos.X < 0) { - sourceSize.Width += targetPos.X; - if (sourceSize.Width <= 0) - return; - - sourcePos.X -= targetPos.X; - targetPos.X = 0; - } - - const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); - - if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width) { - sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width; - if (sourceSize.Width <= 0) - return; - } - - if (targetPos.Y < 0) { - sourceSize.Height += targetPos.Y; - if (sourceSize.Height <= 0) - return; - - sourcePos.Y -= targetPos.Y; - targetPos.Y = 0; - } - - if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height) { - sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height; - if (sourceSize.Height <= 0) - return; - } - - // ok, we've clipped everything. - // now draw it. - - // texcoords need to be flipped horizontally for RTTs - const bool isRTT = texture->isRenderTarget(); - const core::dimension2d &ss = texture->getOriginalSize(); - const f32 invW = 1.f / static_cast(ss.Width); - const f32 invH = 1.f / static_cast(ss.Height); - const core::rect tcoords( - sourcePos.X * invW, - (isRTT ? (sourcePos.Y + sourceSize.Height) : sourcePos.Y) * invH, - (sourcePos.X + sourceSize.Width) * invW, - (isRTT ? sourcePos.Y : (sourcePos.Y + sourceSize.Height)) * invH); - - const core::rect poss(targetPos, sourceSize); - - if (!CacheHandler->getTextureCache().set(0, texture)) - return; - - setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - vertices[0] = S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); - vertices[1] = S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); - vertices[2] = S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); - vertices[3] = S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); - drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); -} - -//! The same, but with a four element array of colors, one for each vertex -void COGLES1Driver::draw2DImage(const video::ITexture *texture, const core::rect &destRect, - const core::rect &sourceRect, const core::rect *clipRect, - const video::SColor *const colors, bool useAlphaChannelOfTexture) -{ - if (!texture) - return; - - // texcoords need to be flipped horizontally for RTTs - const bool isRTT = texture->isRenderTarget(); - const core::dimension2du &ss = texture->getOriginalSize(); - const f32 invW = 1.f / static_cast(ss.Width); - const f32 invH = 1.f / static_cast(ss.Height); - const core::rect tcoords( - sourceRect.UpperLeftCorner.X * invW, - (isRTT ? sourceRect.LowerRightCorner.Y : sourceRect.UpperLeftCorner.Y) * invH, - sourceRect.LowerRightCorner.X * invW, - (isRTT ? sourceRect.UpperLeftCorner.Y : sourceRect.LowerRightCorner.Y) * invH); - - const video::SColor temp[4] = { - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - }; - - const video::SColor *const useColor = colors ? colors : temp; - - if (!CacheHandler->getTextureCache().set(0, texture)) - return; - - setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || - useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, - true, useAlphaChannelOfTexture); - - if (clipRect) { - if (!clipRect->isValid()) - return; - - glEnable(GL_SCISSOR_TEST); - const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); - glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, - clipRect->getWidth(), clipRect->getHeight()); - } - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - vertices[0] = S3DVertex((f32)destRect.UpperLeftCorner.X, (f32)destRect.UpperLeftCorner.Y, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); - vertices[1] = S3DVertex((f32)destRect.LowerRightCorner.X, (f32)destRect.UpperLeftCorner.Y, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); - vertices[2] = S3DVertex((f32)destRect.LowerRightCorner.X, (f32)destRect.LowerRightCorner.Y, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); - vertices[3] = S3DVertex((f32)destRect.UpperLeftCorner.X, (f32)destRect.LowerRightCorner.Y, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); - drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); - - if (clipRect) - glDisable(GL_SCISSOR_TEST); -} - -void COGLES1Driver::draw2DImage(const video::ITexture *texture, u32 layer, bool flip) -{ - if (!texture || !CacheHandler->getTextureCache().set(0, texture)) - return; - - setRenderStates2DMode(false, true, true); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - Transformation3DChanged = true; - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - - vertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); - vertices[1].Pos = core::vector3df(1.f, 1.f, 0.f); - vertices[2].Pos = core::vector3df(1.f, -1.f, 0.f); - vertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f); - - f32 modificator = (flip) ? 1.f : 0.f; - - vertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); - vertices[1].TCoords = core::vector2df(1.f, 0.f + modificator); - vertices[2].TCoords = core::vector2df(1.f, 1.f - modificator); - vertices[3].TCoords = core::vector2df(0.f, 1.f - modificator); - - vertices[0].Color = 0xFFFFFFFF; - vertices[1].Color = 0xFFFFFFFF; - vertices[2].Color = 0xFFFFFFFF; - vertices[3].Color = 0xFFFFFFFF; - - drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); -} - -//! draws a set of 2d images, using a color and the alpha channel of the texture if desired. -void COGLES1Driver::draw2DImageBatch(const video::ITexture *texture, - const core::array> &positions, - const core::array> &sourceRects, - const core::rect *clipRect, - SColor color, - bool useAlphaChannelOfTexture) -{ - if (!texture) - return; - - const u32 drawCount = core::min_(positions.size(), sourceRects.size()); - if (!drawCount) - return; - - const core::dimension2d &ss = texture->getOriginalSize(); - if (!ss.Width || !ss.Height) - return; - const f32 invW = 1.f / static_cast(ss.Width); - const f32 invH = 1.f / static_cast(ss.Height); - const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); - - if (!CacheHandler->getTextureCache().set(0, texture)) - return; - - setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); - - core::array vertices; - core::array quadIndices; - vertices.reallocate(drawCount * 4); - quadIndices.reallocate(drawCount * 6); - - for (u32 i = 0; i < drawCount; ++i) { - if (!sourceRects[i].isValid()) - continue; - - core::position2d targetPos(positions[i]); - core::position2d sourcePos(sourceRects[i].UpperLeftCorner); - // This needs to be signed as it may go negative. - core::dimension2d sourceSize(sourceRects[i].getSize()); - if (clipRect) { - if (targetPos.X < clipRect->UpperLeftCorner.X) { - sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X; - if (sourceSize.Width <= 0) - continue; - - sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X; - targetPos.X = clipRect->UpperLeftCorner.X; - } - - if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X) { - sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X; - if (sourceSize.Width <= 0) - continue; - } - - if (targetPos.Y < clipRect->UpperLeftCorner.Y) { - sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y; - if (sourceSize.Height <= 0) - continue; - - sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y; - targetPos.Y = clipRect->UpperLeftCorner.Y; - } - - if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y) { - sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y; - if (sourceSize.Height <= 0) - continue; - } - } - - // clip these coordinates - - if (targetPos.X < 0) { - sourceSize.Width += targetPos.X; - if (sourceSize.Width <= 0) - continue; - - sourcePos.X -= targetPos.X; - targetPos.X = 0; - } - - if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width) { - sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width; - if (sourceSize.Width <= 0) - continue; - } - - if (targetPos.Y < 0) { - sourceSize.Height += targetPos.Y; - if (sourceSize.Height <= 0) - continue; - - sourcePos.Y -= targetPos.Y; - targetPos.Y = 0; - } - - if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height) { - sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height; - if (sourceSize.Height <= 0) - continue; - } - - // ok, we've clipped everything. - - const core::rect tcoords( - sourcePos.X * invW, - sourcePos.Y * invH, - (sourcePos.X + sourceSize.Width) * invW, - (sourcePos.Y + sourceSize.Height) * invH); - - const core::rect poss(targetPos, sourceSize); - - const u32 vstart = vertices.size(); - - vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); - vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.UpperLeftCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); - vertices.push_back(S3DVertex((f32)poss.LowerRightCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); - vertices.push_back(S3DVertex((f32)poss.UpperLeftCorner.X, (f32)poss.LowerRightCorner.Y, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); - - quadIndices.push_back(vstart); - quadIndices.push_back(vstart + 1); - quadIndices.push_back(vstart + 2); - quadIndices.push_back(vstart); - quadIndices.push_back(vstart + 2); - quadIndices.push_back(vstart + 3); - } - if (vertices.size()) - drawVertexPrimitiveList2d3d(vertices.pointer(), vertices.size(), - quadIndices.pointer(), vertices.size() / 2, - video::EVT_STANDARD, scene::EPT_TRIANGLES, - EIT_16BIT, false); -} - -//! draw a 2d rectangle -void COGLES1Driver::draw2DRectangle(SColor color, const core::rect &position, - const core::rect *clip) -{ - setRenderStates2DMode(color.getAlpha() < 255, false, false); - - core::rect pos = position; - - if (clip) - pos.clipAgainst(*clip); - - if (!pos.isValid()) - return; - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - vertices[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, color, 0, 0); - vertices[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, color, 0, 0); - vertices[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, color, 0, 0); - vertices[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, color, 0, 0); - drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); -} - -//! draw an 2d rectangle -void COGLES1Driver::draw2DRectangle(const core::rect &position, - SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, - const core::rect *clip) -{ - core::rect pos = position; - - if (clip) - pos.clipAgainst(*clip); - - if (!pos.isValid()) - return; - - setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || - colorRightUp.getAlpha() < 255 || - colorLeftDown.getAlpha() < 255 || - colorRightDown.getAlpha() < 255, - false, false); - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - vertices[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, colorLeftUp, 0, 0); - vertices[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0, 0, 0, 1, colorRightUp, 0, 0); - vertices[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, colorRightDown, 0, 0); - vertices[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0, 0, 0, 1, colorLeftDown, 0, 0); - drawVertexPrimitiveList2d3d(vertices, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN, EIT_16BIT, false); -} - -//! Draws a 2d line. -void COGLES1Driver::draw2DLine(const core::position2d &start, - const core::position2d &end, - SColor color) -{ - setRenderStates2DMode(color.getAlpha() < 255, false, false); - - u16 indices[] = {0, 1}; - S3DVertex vertices[2]; - vertices[0] = S3DVertex((f32)start.X, (f32)start.Y, 0, 0, 0, 1, color, 0, 0); - vertices[1] = S3DVertex((f32)end.X, (f32)end.Y, 0, 0, 0, 1, color, 1, 1); - drawVertexPrimitiveList2d3d(vertices, 2, indices, 1, video::EVT_STANDARD, scene::EPT_LINES, EIT_16BIT, false); -} - -//! creates a matrix in supplied GLfloat array to pass to OGLES1 -inline void COGLES1Driver::getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m) -{ - memcpy(gl_matrix, m.pointer(), 16 * sizeof(f32)); -} - -//! creates a opengltexturematrix from a D3D style texture matrix -inline void COGLES1Driver::getGLTextureMatrix(GLfloat *o, const core::matrix4 &m) -{ - o[0] = m[0]; - o[1] = m[1]; - o[2] = 0.f; - o[3] = 0.f; - - o[4] = m[4]; - o[5] = m[5]; - o[6] = 0.f; - o[7] = 0.f; - - o[8] = 0.f; - o[9] = 0.f; - o[10] = 1.f; - o[11] = 0.f; - - o[12] = m[8]; - o[13] = m[9]; - o[14] = 0.f; - o[15] = 1.f; -} - -ITexture *COGLES1Driver::createDeviceDependentTexture(const io::path &name, IImage *image) -{ - std::vector tmp { image }; - - COGLES1Texture *texture = new COGLES1Texture(name, tmp, ETT_2D, this); - - return texture; -} - -ITexture *COGLES1Driver::createDeviceDependentTextureCubemap(const io::path &name, const std::vector &image) -{ - COGLES1Texture *texture = new COGLES1Texture(name, image, ETT_CUBEMAP, this); - - return texture; -} - -//! Sets a material. All 3d drawing functions draw geometry now using this material. -void COGLES1Driver::setMaterial(const SMaterial &material) -{ - Material = material; - OverrideMaterial.apply(Material); - - for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) - setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); -} - -//! prints error if an error happened. -bool COGLES1Driver::testGLError(int code) -{ - if (!Params.DriverDebug) - return false; - - GLenum g = glGetError(); - switch (g) { - case GL_NO_ERROR: - return false; - case GL_INVALID_ENUM: - os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR); - break; - case GL_INVALID_VALUE: - os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR); - break; - case GL_INVALID_OPERATION: - os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR); - break; - case GL_STACK_OVERFLOW: - os::Printer::log("GL_STACK_OVERFLOW", core::stringc(code).c_str(), ELL_ERROR); - break; - case GL_STACK_UNDERFLOW: - os::Printer::log("GL_STACK_UNDERFLOW", core::stringc(code).c_str(), ELL_ERROR); - break; - case GL_OUT_OF_MEMORY: - os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); - break; - }; - return true; -} - -//! sets the needed renderstates -void COGLES1Driver::setRenderStates3DMode() -{ - if (CurrentRenderMode != ERM_3D) { - // Reset Texture Stages - CacheHandler->setBlend(false); - glDisable(GL_ALPHA_TEST); - CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - // switch back the matrices - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer()); - - GLfloat glmat[16]; - getGLMatrix(glmat, Matrices[ETS_PROJECTION]); - glmat[12] *= -1.0f; - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(glmat); - - ResetRenderStates = true; - } - - if (ResetRenderStates || LastMaterial != Material) { - // unset old material - - if (LastMaterial.MaterialType != Material.MaterialType && - static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) - MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); - - // set new material. - if (static_cast(Material.MaterialType) < MaterialRenderers.size()) - MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial( - Material, LastMaterial, ResetRenderStates, this); - - LastMaterial = Material; - CacheHandler->correctCacheMaterial(LastMaterial); - ResetRenderStates = false; - } - - if (static_cast(Material.MaterialType) < MaterialRenderers.size()) - MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, video::EVT_STANDARD); - - CurrentRenderMode = ERM_3D; -} - -GLint COGLES1Driver::getTextureWrapMode(u8 clamp) const -{ - switch (clamp) { - case ETC_CLAMP: - // return GL_CLAMP; not supported in ogl-es - return GL_CLAMP_TO_EDGE; - break; - case ETC_CLAMP_TO_EDGE: - return GL_CLAMP_TO_EDGE; - break; - case ETC_CLAMP_TO_BORDER: - // return GL_CLAMP_TO_BORDER; not supported in ogl-es - return GL_CLAMP_TO_EDGE; - break; - case ETC_MIRROR: -#ifdef GL_OES_texture_mirrored_repeat - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_texture_mirrored_repeat]) - return GL_MIRRORED_REPEAT_OES; - else -#endif - return GL_REPEAT; - break; - // the next three are not yet supported at all - case ETC_MIRROR_CLAMP: - case ETC_MIRROR_CLAMP_TO_EDGE: - case ETC_MIRROR_CLAMP_TO_BORDER: -#ifdef GL_OES_texture_mirrored_repeat - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_texture_mirrored_repeat]) - return GL_MIRRORED_REPEAT_OES; - else -#endif - return GL_CLAMP_TO_EDGE; - break; - case ETC_REPEAT: - default: - return GL_REPEAT; - break; - } -} - -//! Can be called by an IMaterialRenderer to make its work easier. -void COGLES1Driver::setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, - bool resetAllRenderStates) -{ - if (resetAllRenderStates || - lastmaterial.ColorMaterial != material.ColorMaterial) { - // we only have diffuse_and_ambient in ogl-es - if (material.ColorMaterial == ECM_DIFFUSE_AND_AMBIENT) - glEnable(GL_COLOR_MATERIAL); - else - glDisable(GL_COLOR_MATERIAL); - } - - if (resetAllRenderStates || - lastmaterial.AmbientColor != material.AmbientColor || - lastmaterial.DiffuseColor != material.DiffuseColor || - lastmaterial.EmissiveColor != material.EmissiveColor || - lastmaterial.ColorMaterial != material.ColorMaterial) { - GLfloat color[4]; - - const f32 inv = 1.0f / 255.0f; - - if ((material.ColorMaterial != video::ECM_AMBIENT) && - (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) { - color[0] = material.AmbientColor.getRed() * inv; - color[1] = material.AmbientColor.getGreen() * inv; - color[2] = material.AmbientColor.getBlue() * inv; - color[3] = material.AmbientColor.getAlpha() * inv; - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); - } - - if ((material.ColorMaterial != video::ECM_DIFFUSE) && - (material.ColorMaterial != video::ECM_DIFFUSE_AND_AMBIENT)) { - color[0] = material.DiffuseColor.getRed() * inv; - color[1] = material.DiffuseColor.getGreen() * inv; - color[2] = material.DiffuseColor.getBlue() * inv; - color[3] = material.DiffuseColor.getAlpha() * inv; - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); - } - - if (material.ColorMaterial != video::ECM_EMISSIVE) { - color[0] = material.EmissiveColor.getRed() * inv; - color[1] = material.EmissiveColor.getGreen() * inv; - color[2] = material.EmissiveColor.getBlue() * inv; - color[3] = material.EmissiveColor.getAlpha() * inv; - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); - } - } - - if (resetAllRenderStates || - lastmaterial.SpecularColor != material.SpecularColor || - lastmaterial.Shininess != material.Shininess) { - GLfloat color[] = {0.f, 0.f, 0.f, 1.f}; - const f32 inv = 1.0f / 255.0f; - - // disable Specular colors if no shininess is set - if ((material.Shininess != 0.0f) && - (material.ColorMaterial != video::ECM_SPECULAR)) { -#ifdef GL_EXT_separate_specular_color - if (FeatureAvailable[IRR_EXT_separate_specular_color]) - glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); -#endif - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess); - color[0] = material.SpecularColor.getRed() * inv; - color[1] = material.SpecularColor.getGreen() * inv; - color[2] = material.SpecularColor.getBlue() * inv; - color[3] = material.SpecularColor.getAlpha() * inv; - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); - } -#ifdef GL_EXT_separate_specular_color - else if (FeatureAvailable[IRR_EXT_separate_specular_color]) - glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); -#endif - } - - // TODO ogl-es - // fillmode - // if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud)) - // glPolygonMode(GL_FRONT_AND_BACK, material.Wireframe ? GL_LINE : material.PointCloud? GL_POINT : GL_FILL); - - // shademode - if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading)) { - if (material.GouraudShading) - glShadeModel(GL_SMOOTH); - else - glShadeModel(GL_FLAT); - } - - // lighting - if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting)) { - if (material.Lighting) - glEnable(GL_LIGHTING); - else - glDisable(GL_LIGHTING); - } - - // zbuffer - if (resetAllRenderStates || lastmaterial.ZBuffer != material.ZBuffer) { - switch (material.ZBuffer) { - case ECFN_DISABLED: - glDisable(GL_DEPTH_TEST); - break; - case ECFN_LESSEQUAL: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - break; - case ECFN_EQUAL: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_EQUAL); - break; - case ECFN_LESS: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - break; - case ECFN_NOTEQUAL: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_NOTEQUAL); - break; - case ECFN_GREATEREQUAL: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_GEQUAL); - break; - case ECFN_GREATER: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_GREATER); - break; - case ECFN_ALWAYS: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - break; - case ECFN_NEVER: - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_NEVER); - break; - } - } - - // zwrite - if (getWriteZBuffer(material)) { - glDepthMask(GL_TRUE); - } else { - glDepthMask(GL_FALSE); - } - - // back face culling - if (resetAllRenderStates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling)) { - if ((material.FrontfaceCulling) && (material.BackfaceCulling)) { - glCullFace(GL_FRONT_AND_BACK); - glEnable(GL_CULL_FACE); - } else if (material.BackfaceCulling) { - glCullFace(GL_BACK); - glEnable(GL_CULL_FACE); - } else if (material.FrontfaceCulling) { - glCullFace(GL_FRONT); - glEnable(GL_CULL_FACE); - } else - glDisable(GL_CULL_FACE); - } - - // fog - if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable) { - if (material.FogEnable) - glEnable(GL_FOG); - else - glDisable(GL_FOG); - } - - // normalization - if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals) { - if (material.NormalizeNormals) - glEnable(GL_NORMALIZE); - else - glDisable(GL_NORMALIZE); - } - - // Color Mask - if (resetAllRenderStates || lastmaterial.ColorMask != material.ColorMask) { - glColorMask( - (material.ColorMask & ECP_RED) ? GL_TRUE : GL_FALSE, - (material.ColorMask & ECP_GREEN) ? GL_TRUE : GL_FALSE, - (material.ColorMask & ECP_BLUE) ? GL_TRUE : GL_FALSE, - (material.ColorMask & ECP_ALPHA) ? GL_TRUE : GL_FALSE); - } - - // Blend Equation - if (material.BlendOperation == EBO_NONE) - CacheHandler->setBlend(false); - else { - CacheHandler->setBlend(true); - - if (queryFeature(EVDF_BLEND_OPERATIONS)) { - switch (material.BlendOperation) { - case EBO_ADD: -#if defined(GL_OES_blend_subtract) - CacheHandler->setBlendEquation(GL_FUNC_ADD_OES); -#endif - break; - case EBO_SUBTRACT: -#if defined(GL_OES_blend_subtract) - CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT_OES); -#endif - break; - case EBO_REVSUBTRACT: -#if defined(GL_OES_blend_subtract) - CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT_OES); -#endif - break; - default: - break; - } - } - } - - // Blend Factor - if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF? - && material.MaterialType != EMT_ONETEXTURE_BLEND) { - E_BLEND_FACTOR srcRGBFact = EBF_ZERO; - E_BLEND_FACTOR dstRGBFact = EBF_ZERO; - E_BLEND_FACTOR srcAlphaFact = EBF_ZERO; - E_BLEND_FACTOR dstAlphaFact = EBF_ZERO; - E_MODULATE_FUNC modulo = EMFN_MODULATE_1X; - u32 alphaSource = 0; - - unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, material.BlendFactor); - - if (queryFeature(EVDF_BLEND_SEPARATE)) { - CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), - getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); - } else { - CacheHandler->setBlendFunc(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact)); - } - } - - // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. - - // thickness - if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) { - if (AntiAlias) { - // glPointSize(core::clamp(static_cast(material.Thickness), DimSmoothedPoint[0], DimSmoothedPoint[1])); - // we don't use point smoothing - glPointSize(core::clamp(static_cast(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1])); - } else { - glPointSize(core::clamp(static_cast(material.Thickness), DimAliasedPoint[0], DimAliasedPoint[1])); - glLineWidth(core::clamp(static_cast(material.Thickness), DimAliasedLine[0], DimAliasedLine[1])); - } - } - - // Anti aliasing - if (resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing) { - if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) - glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); - else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) - glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); - - if ((AntiAlias >= 2) && (material.AntiAliasing & (EAAM_SIMPLE | EAAM_QUALITY))) - glEnable(GL_MULTISAMPLE); - else - glDisable(GL_MULTISAMPLE); - } - - // Texture parameters - setTextureRenderStates(material, resetAllRenderStates); -} - -//! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. -void COGLES1Driver::setTextureRenderStates(const SMaterial &material, bool resetAllRenderstates) -{ - // Set textures to TU/TIU and apply filters to them - - for (s32 i = Feature.MaxTextureUnits - 1; i >= 0; --i) { - CacheHandler->getTextureCache().set(i, material.TextureLayers[i].Texture); - - const COGLES1Texture *tmpTexture = CacheHandler->getTextureCache().get(i); - - if (!tmpTexture) - continue; - - GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); - - CacheHandler->setActiveTexture(GL_TEXTURE0 + i); - - { - const bool isRTT = tmpTexture->isRenderTarget(); - - glMatrixMode(GL_TEXTURE); - - if (!isRTT && Matrices[ETS_TEXTURE_0 + i].isIdentity()) - glLoadIdentity(); - else { - GLfloat glmat[16]; - if (isRTT) - getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i] * TextureFlipMatrix); - else - getGLTextureMatrix(glmat, Matrices[ETS_TEXTURE_0 + i]); - glLoadMatrixf(glmat); - } - } - - COGLES1Texture::SStatesCache &statesCache = tmpTexture->getStatesCache(); - - if (resetAllRenderstates) - statesCache.IsCached = false; - -#if defined(GL_EXT_texture_lod_bias) - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_lod_bias]) { - if (material.TextureLayers[i].LODBias) { - const float tmp = core::clamp(material.TextureLayers[i].LODBias * 0.125f, -MaxTextureLODBias, MaxTextureLODBias); - glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tmp); - } else - glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.f); - } -#endif - - if (!statesCache.IsCached || material.TextureLayers[i].MagFilter != statesCache.MagFilter) { - E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter; - glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, - magFilter == ETMAGF_NEAREST ? GL_NEAREST : (assert(magFilter == ETMAGF_LINEAR), GL_LINEAR)); - - statesCache.MagFilter = magFilter; - } - - if (material.UseMipMaps && tmpTexture->hasMipMaps()) { - if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter || - !statesCache.MipMapStatus) { - E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; - glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, - minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST : minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST - : minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR - : (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR)); - - statesCache.MinFilter = minFilter; - statesCache.MipMapStatus = true; - } - } else { - if (!statesCache.IsCached || material.TextureLayers[i].MinFilter != statesCache.MinFilter || - statesCache.MipMapStatus) { - E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; - glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, - (minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST : (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR)); - - statesCache.MinFilter = minFilter; - statesCache.MipMapStatus = false; - } - } - -#ifdef GL_EXT_texture_filter_anisotropic - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] && - (!statesCache.IsCached || material.TextureLayers[i].AnisotropicFilter != statesCache.AnisotropicFilter)) { - glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, - material.TextureLayers[i].AnisotropicFilter > 1 ? core::min_(MaxAnisotropy, material.TextureLayers[i].AnisotropicFilter) : 1); - - statesCache.AnisotropicFilter = material.TextureLayers[i].AnisotropicFilter; - } -#endif - - if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapU != statesCache.WrapU) { - glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU)); - statesCache.WrapU = material.TextureLayers[i].TextureWrapU; - } - - if (!statesCache.IsCached || material.TextureLayers[i].TextureWrapV != statesCache.WrapV) { - glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV)); - statesCache.WrapV = material.TextureLayers[i].TextureWrapV; - } - - statesCache.IsCached = true; - } - - // be sure to leave in texture stage 0 - CacheHandler->setActiveTexture(GL_TEXTURE0); -} - -//! sets the needed renderstates -void COGLES1Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) -{ - if (CurrentRenderMode != ERM_2D || Transformation3DChanged) { - // unset last 3d material - if (CurrentRenderMode == ERM_3D) { - if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) - MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); - } - if (Transformation3DChanged) { - glMatrixMode(GL_PROJECTION); - - const core::dimension2d &renderTargetSize = getCurrentRenderTargetSize(); - core::matrix4 m(core::matrix4::EM4CONST_NOTHING); - m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f); - m.setTranslation(core::vector3df(-1, 1, 0)); - glLoadMatrixf(m.pointer()); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - Transformation3DChanged = false; - } - } - - Material = (OverrideMaterial2DEnabled) ? OverrideMaterial2D : InitMaterial2D; - Material.Lighting = false; - Material.TextureLayers[0].Texture = (texture) ? const_cast(CacheHandler->getTextureCache().get(0)) : 0; - setTransform(ETS_TEXTURE_0, core::IdentityMatrix); - - setBasicRenderStates(Material, LastMaterial, false); - - LastMaterial = Material; - CacheHandler->correctCacheMaterial(LastMaterial); - - // no alphaChannel without texture - alphaChannel &= texture; - - if (alphaChannel || alpha) { - CacheHandler->setBlend(true); - CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - CacheHandler->setBlendEquation(GL_FUNC_ADD); - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, 0.f); - } else { - CacheHandler->setBlend(false); - glDisable(GL_ALPHA_TEST); - } - - if (texture) { - // Due to the transformation change, the previous line would call a reset each frame - // but we can safely reset the variable as it was false before - Transformation3DChanged = false; - - if (alphaChannel) { - // if alpha and alpha texture just modulate, otherwise use only the alpha channel - if (alpha) { - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } else { - 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_TEXTURE); - // rgb always modulates - 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_PRIMARY_COLOR); - } - } else { - if (alpha) { - 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); - // rgb always modulates - 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_PRIMARY_COLOR); - } else { - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } - } - } - - CurrentRenderMode = ERM_2D; -} - -//! \return Returns the name of the video driver. -const char *COGLES1Driver::getName() const -{ - return Name.c_str(); -} - -//! Sets the dynamic ambient light color. -void COGLES1Driver::setAmbientLight(const SColorf &color) -{ - CNullDriver::setAmbientLight(color); - GLfloat data[4] = {color.r, color.g, color.b, color.a}; - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data); -} - -// this code was sent in by Oliver Klems, thank you -void COGLES1Driver::setViewPort(const core::rect &area) -{ - core::rect vp = area; - core::rect rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); - vp.clipAgainst(rendert); - - if (vp.getHeight() > 0 && vp.getWidth() > 0) - CacheHandler->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight()); - - ViewPort = vp; -} - -void COGLES1Driver::setViewPortRaw(u32 width, u32 height) -{ - CacheHandler->setViewport(0, 0, width, height); - ViewPort = core::recti(0, 0, width, height); -} - -//! Sets the fog mode. -void COGLES1Driver::setFog(SColor c, E_FOG_TYPE fogType, f32 start, - f32 end, f32 density, bool pixelFog, bool rangeFog) -{ - CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog); - - glFogf(GL_FOG_MODE, GLfloat((fogType == EFT_FOG_LINEAR) ? GL_LINEAR : (fogType == EFT_FOG_EXP) ? GL_EXP - : GL_EXP2)); - -#ifdef GL_EXT_fog_coord - if (FeatureAvailable[IRR_EXT_fog_coord]) - glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH); -#endif - - if (fogType == EFT_FOG_LINEAR) { - glFogf(GL_FOG_START, start); - glFogf(GL_FOG_END, end); - } else - glFogf(GL_FOG_DENSITY, density); - - if (pixelFog) - glHint(GL_FOG_HINT, GL_NICEST); - else - glHint(GL_FOG_HINT, GL_FASTEST); - - SColorf color(c); - GLfloat data[4] = {color.r, color.g, color.b, color.a}; - glFogfv(GL_FOG_COLOR, data); -} - -//! Draws a 3d line. -void COGLES1Driver::draw3DLine(const core::vector3df &start, - const core::vector3df &end, SColor color) -{ - setRenderStates3DMode(); - - u16 indices[] = {0, 1}; - S3DVertex vertices[2]; - vertices[0] = S3DVertex(start.X, start.Y, start.Z, 0, 0, 1, color, 0, 0); - vertices[1] = S3DVertex(end.X, end.Y, end.Z, 0, 0, 1, color, 0, 0); - drawVertexPrimitiveList2d3d(vertices, 2, indices, 1, video::EVT_STANDARD, scene::EPT_LINES); -} - -//! Only used by the internal engine. Used to notify the driver that -//! the window was resized. -void COGLES1Driver::OnResize(const core::dimension2d &size) -{ - CNullDriver::OnResize(size); - CacheHandler->setViewport(0, 0, size.Width, size.Height); - Transformation3DChanged = true; -} - -//! Returns type of video driver -E_DRIVER_TYPE COGLES1Driver::getDriverType() const -{ - return EDT_OGLES1; -} - -//! returns color format -ECOLOR_FORMAT COGLES1Driver::getColorFormat() const -{ - return ColorFormat; -} - -//! Get a vertex shader constant index. -s32 COGLES1Driver::getVertexShaderConstantID(const c8 *name) -{ - return getPixelShaderConstantID(name); -} - -//! Get a pixel shader constant index. -s32 COGLES1Driver::getPixelShaderConstantID(const c8 *name) -{ - os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->getPixelShaderConstantID()."); - return -1; -} - -//! Sets a constant for the vertex shader based on an index. -bool COGLES1Driver::setVertexShaderConstant(s32 index, const f32 *floats, int count) -{ - // pass this along, as in GLSL the same routine is used for both vertex and fragment shaders - return setPixelShaderConstant(index, floats, count); -} - -//! Int interface for the above. -bool COGLES1Driver::setVertexShaderConstant(s32 index, const s32 *ints, int count) -{ - return setPixelShaderConstant(index, ints, count); -} - -bool COGLES1Driver::setVertexShaderConstant(s32 index, const u32 *ints, int count) -{ - return setPixelShaderConstant(index, ints, count); -} - -//! Sets a constant for the pixel shader based on an index. -bool COGLES1Driver::setPixelShaderConstant(s32 index, const f32 *floats, int count) -{ - os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant()."); - return false; -} - -//! Int interface for the above. -bool COGLES1Driver::setPixelShaderConstant(s32 index, const s32 *ints, int count) -{ - os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant()."); - return false; -} - -bool COGLES1Driver::setPixelShaderConstant(s32 index, const u32 *ints, int count) -{ - os::Printer::log("Error: Please use IMaterialRendererServices from IShaderConstantSetCallBack::OnSetConstants not VideoDriver->setPixelShaderConstant()."); - return false; -} - -//! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. -s32 COGLES1Driver::addHighLevelShaderMaterial( - const c8 *vertexShaderProgram, - const c8 *vertexShaderEntryPointName, - E_VERTEX_SHADER_TYPE vsCompileTarget, - const c8 *pixelShaderProgram, - const c8 *pixelShaderEntryPointName, - E_PIXEL_SHADER_TYPE psCompileTarget, - const c8 *geometryShaderProgram, - const c8 *geometryShaderEntryPointName, - E_GEOMETRY_SHADER_TYPE gsCompileTarget, - scene::E_PRIMITIVE_TYPE inType, - scene::E_PRIMITIVE_TYPE outType, - u32 verticesOut, - IShaderConstantSetCallBack *callback, - E_MATERIAL_TYPE baseMaterial, - s32 userData) -{ - os::Printer::log("No shader support."); - return -1; -} - -//! Returns a pointer to the IVideoDriver interface. (Implementation for -//! IMaterialRendererServices) -IVideoDriver *COGLES1Driver::getVideoDriver() -{ - return this; -} - -//! Returns pointer to the IGPUProgrammingServices interface. -IGPUProgrammingServices *COGLES1Driver::getGPUProgrammingServices() -{ - return this; -} - -ITexture *COGLES1Driver::addRenderTargetTexture(const core::dimension2d &size, - const io::path &name, const ECOLOR_FORMAT format) -{ - // disable mip-mapping - bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); - setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); - - bool supportForFBO = (Feature.ColorAttachment > 0); - - core::dimension2du destSize(size); - - if (!supportForFBO) { - destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); - destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); - } - - COGLES1Texture *renderTargetTexture = new COGLES1Texture(name, destSize, ETT_2D, format, this); - addTexture(renderTargetTexture); - renderTargetTexture->drop(); - - // restore mip-mapping - setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); - - return renderTargetTexture; -} - -ITexture *COGLES1Driver::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path &name, const ECOLOR_FORMAT format) -{ - // disable mip-mapping - bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); - setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false); - - bool supportForFBO = (Feature.ColorAttachment > 0); - - const core::dimension2d size(sideLen, sideLen); - core::dimension2du destSize(size); - - if (!supportForFBO) { - destSize = core::dimension2d(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height)); - destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false); - } - - COGLES1Texture *renderTargetTexture = new COGLES1Texture(name, destSize, ETT_CUBEMAP, format, this); - addTexture(renderTargetTexture); - renderTargetTexture->drop(); - - // restore mip-mapping - setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); - - return renderTargetTexture; -} - -//! Returns the maximum amount of primitives -u32 COGLES1Driver::getMaximalPrimitiveCount() const -{ - return 65535; -} - -bool COGLES1Driver::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) -{ - if (target && target->getDriverType() != EDT_OGLES1) { - os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL driver.", ELL_ERROR); - return false; - } - - bool supportForFBO = (Feature.ColorAttachment > 0); - - core::dimension2d destRenderTargetSize(0, 0); - - if (target) { - COGLES1RenderTarget *renderTarget = static_cast(target); - - if (supportForFBO) { - CacheHandler->setFBO(renderTarget->getBufferID()); - renderTarget->update(); - } - - destRenderTargetSize = renderTarget->getSize(); - - setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); - } else { - if (supportForFBO) - CacheHandler->setFBO(0); - else { - COGLES1RenderTarget *prevRenderTarget = static_cast(CurrentRenderTarget); - COGLES1Texture *renderTargetTexture = static_cast(prevRenderTarget->getTexture()); - - if (renderTargetTexture) { - const COGLES1Texture *prevTexture = CacheHandler->getTextureCache().get(0); - - CacheHandler->getTextureCache().set(0, renderTargetTexture); - - const core::dimension2d size = renderTargetTexture->getSize(); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.Width, size.Height); - - CacheHandler->getTextureCache().set(0, prevTexture); - } - } - - destRenderTargetSize = core::dimension2d(0, 0); - - setViewPortRaw(ScreenSize.Width, ScreenSize.Height); - } - - if (CurrentRenderTargetSize != destRenderTargetSize) { - CurrentRenderTargetSize = destRenderTargetSize; - - Transformation3DChanged = true; - } - - CurrentRenderTarget = target; - - if (!supportForFBO) { - clearFlag |= ECBF_COLOR; - clearFlag |= ECBF_DEPTH; - } - - clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); - - return true; -} - -void COGLES1Driver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) -{ - GLbitfield mask = 0; - - if (flag & ECBF_COLOR) { - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - const f32 inv = 1.0f / 255.0f; - glClearColor(color.getRed() * inv, color.getGreen() * inv, - color.getBlue() * inv, color.getAlpha() * inv); - - mask |= GL_COLOR_BUFFER_BIT; - } - - if (flag & ECBF_DEPTH) { - glDepthMask(GL_TRUE); - glClearDepthf(depth); - mask |= GL_DEPTH_BUFFER_BIT; - } - - if (flag & ECBF_STENCIL) { - glClearStencil(stencil); - mask |= GL_STENCIL_BUFFER_BIT; - } - - if (mask) - glClear(mask); -} - -//! Returns an image created from the last rendered frame. -// We want to read the front buffer to get the latest render finished. -// This is not possible under ogl-es, though, so one has to call this method -// outside of the render loop only. -IImage *COGLES1Driver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) -{ - if (target == video::ERT_MULTI_RENDER_TEXTURES || target == video::ERT_RENDER_TEXTURE || target == video::ERT_STEREO_BOTH_BUFFERS) - return 0; - GLint internalformat = GL_RGBA; - GLint type = GL_UNSIGNED_BYTE; - if (false && (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_IMG_read_format] || FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_OES_read_format] || FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_read_format_bgra])) { -#ifdef GL_IMPLEMENTATION_COLOR_READ_TYPE_OES - glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &internalformat); - glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &type); -#endif - // there are formats we don't support ATM - if (GL_UNSIGNED_SHORT_4_4_4_4 == type) - type = GL_UNSIGNED_SHORT_5_5_5_1; -#ifdef GL_EXT_read_format_bgra - else if (GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT == type) - type = GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT; -#endif - } - - IImage *newImage = 0; - if ((GL_RGBA == internalformat) -#ifdef GL_EXT_read_format_bgra - || (GL_BGRA_EXT == internalformat) -#endif - ) { - if (GL_UNSIGNED_BYTE == type) - newImage = new CImage(ECF_A8R8G8B8, ScreenSize); - else - newImage = new CImage(ECF_A1R5G5B5, ScreenSize); - } else { - if (GL_UNSIGNED_BYTE == type) - newImage = new CImage(ECF_R8G8B8, ScreenSize); - else - newImage = new CImage(ECF_R5G6B5, ScreenSize); - } - - u8 *pixels = static_cast(newImage->getData()); - if (!pixels) { - newImage->drop(); - return 0; - } - - glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); - - // opengl images are horizontally flipped, so we have to fix that here. - const s32 pitch = newImage->getPitch(); - u8 *p2 = pixels + (ScreenSize.Height - 1) * pitch; - u8 *tmpBuffer = new u8[pitch]; - for (u32 i = 0; i < ScreenSize.Height; i += 2) { - memcpy(tmpBuffer, pixels, pitch); - memcpy(pixels, p2, pitch); - memcpy(p2, tmpBuffer, pitch); - pixels += pitch; - p2 -= pitch; - } - delete[] tmpBuffer; - - if (testGLError(__LINE__)) { - newImage->drop(); - return 0; - } - - return newImage; -} - -void COGLES1Driver::removeTexture(ITexture *texture) -{ - CacheHandler->getTextureCache().remove(texture); - CNullDriver::removeTexture(texture); -} - -core::dimension2du COGLES1Driver::getMaxTextureSize() const -{ - return core::dimension2du(MaxTextureSize, MaxTextureSize); -} - -GLenum COGLES1Driver::getGLBlend(E_BLEND_FACTOR factor) const -{ - static GLenum const blendTable[] = { - GL_ZERO, - GL_ONE, - GL_DST_COLOR, - GL_ONE_MINUS_DST_COLOR, - GL_SRC_COLOR, - GL_ONE_MINUS_SRC_COLOR, - GL_SRC_ALPHA, - GL_ONE_MINUS_SRC_ALPHA, - GL_DST_ALPHA, - GL_ONE_MINUS_DST_ALPHA, - GL_SRC_ALPHA_SATURATE, - }; - - return blendTable[factor]; -} - -GLenum COGLES1Driver::getZBufferBits() const -{ - GLenum bits = 0; - - switch (Params.ZBufferBits) { - case 24: -#if defined(GL_OES_depth24) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth24)) - bits = GL_DEPTH_COMPONENT24_OES; - else -#endif - bits = GL_DEPTH_COMPONENT16; - break; - case 32: -#if defined(GL_OES_depth32) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32)) - bits = GL_DEPTH_COMPONENT32_OES; - else -#endif - bits = GL_DEPTH_COMPONENT16; - break; - default: - bits = GL_DEPTH_COMPONENT16; - break; - } - - return bits; -} - -bool COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, - GLenum &pixelType, void (**converter)(const void *, s32, void *)) const -{ - bool supported = false; - internalFormat = GL_RGBA; - pixelFormat = GL_RGBA; - pixelType = GL_UNSIGNED_BYTE; - *converter = 0; - - switch (format) { - case ECF_A1R5G5B5: - supported = true; - internalFormat = GL_RGBA; - pixelFormat = GL_RGBA; - pixelType = GL_UNSIGNED_SHORT_5_5_5_1; - *converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1; - break; - case ECF_R5G6B5: - supported = true; - internalFormat = GL_RGB; - pixelFormat = GL_RGB; - pixelType = GL_UNSIGNED_SHORT_5_6_5; - break; - case ECF_R8G8B8: - supported = true; - internalFormat = GL_RGB; - pixelFormat = GL_RGB; - pixelType = GL_UNSIGNED_BYTE; - break; - case ECF_A8R8G8B8: - supported = true; - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_IMG_texture_format_BGRA8888) || - queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_format_BGRA8888) || - queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_APPLE_texture_format_BGRA8888)) { - internalFormat = GL_BGRA; - pixelFormat = GL_BGRA; - } else { - internalFormat = GL_RGBA; - pixelFormat = GL_RGBA; - *converter = CColorConverter::convert_A8R8G8B8toA8B8G8R8; - } - pixelType = GL_UNSIGNED_BYTE; - break; - case ECF_D16: - supported = true; - internalFormat = GL_DEPTH_COMPONENT16; - pixelFormat = GL_DEPTH_COMPONENT; - pixelType = GL_UNSIGNED_SHORT; - break; - case ECF_D32: -#if defined(GL_OES_depth32) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32)) { - supported = true; - internalFormat = GL_DEPTH_COMPONENT32_OES; - pixelFormat = GL_DEPTH_COMPONENT; - pixelType = GL_UNSIGNED_INT; - } -#endif - break; - case ECF_D24S8: -#ifdef GL_OES_packed_depth_stencil - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_packed_depth_stencil)) { - supported = true; - internalFormat = GL_DEPTH24_STENCIL8_OES; - pixelFormat = GL_DEPTH_STENCIL_OES; - pixelType = GL_UNSIGNED_INT_24_8_OES; - } -#endif - break; - case ECF_R8: - break; - case ECF_R8G8: - break; - case ECF_R16: - break; - case ECF_R16G16: - break; - case ECF_R16F: - break; - case ECF_G16R16F: - break; - case ECF_A16B16G16R16F: - break; - case ECF_R32F: - break; - case ECF_G32R32F: - break; - case ECF_A32B32G32R32F: - break; - default: - break; - } - -#ifdef _IRR_IOS_PLATFORM_ - if (internalFormat == GL_BGRA) - internalFormat = GL_RGBA; -#endif - - return supported; -} - -bool COGLES1Driver::queryTextureFormat(ECOLOR_FORMAT format) const -{ - GLint dummyInternalFormat; - GLenum dummyPixelFormat; - GLenum dummyPixelType; - void (*dummyConverter)(const void *, s32, void *); - return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter); -} - -bool COGLES1Driver::needsTransparentRenderPass(const irr::video::SMaterial &material) const -{ - return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); -} - -COGLES1CacheHandler *COGLES1Driver::getCacheHandler() const -{ - return CacheHandler; -} - -} // end namespace -} // end namespace - -#endif // _IRR_COMPILE_WITH_OGLES1_ - -namespace irr -{ -namespace video -{ - -#ifndef _IRR_COMPILE_WITH_OGLES1_ -class IVideoDriver; -class IContextManager; -#endif - -IVideoDriver *createOGLES1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) -{ -#ifdef _IRR_COMPILE_WITH_OGLES1_ - return new COGLES1Driver(params, io, contextManager); -#else - return 0; -#endif // _IRR_COMPILE_WITH_OGLES1_ -} - -} // end namespace -} // end namespace diff --git a/irr/src/COGLESDriver.h b/irr/src/COGLESDriver.h deleted file mode 100644 index 8b9152cea..000000000 --- a/irr/src/COGLESDriver.h +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright (C) 2002-20014 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#pragma once - -#include "SIrrCreationParameters.h" - -#ifdef _IRR_COMPILE_WITH_OGLES1_ - -#include "CNullDriver.h" -#include "IMaterialRendererServices.h" -#include "EDriverFeatures.h" -#include "fast_atof.h" -#include "COGLESExtensionHandler.h" -#include "IContextManager.h" - -#define TEST_GL_ERROR(cls) (cls)->testGLError(__LINE__) - -namespace irr -{ -namespace video -{ - -class COGLES1Driver : public CNullDriver, public IMaterialRendererServices, public COGLES1ExtensionHandler -{ - friend class COpenGLCoreTexture; - -public: - //! constructor - COGLES1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); - - //! destructor - virtual ~COGLES1Driver(); - - virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), f32 clearDepth = 1.f, u8 clearStencil = 0, - const SExposedVideoData &videoData = SExposedVideoData(), core::rect *sourceRect = 0) override; - - bool endScene() override; - - //! sets transformation - void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4 &mat) override; - - 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 - bool updateHardwareBuffer(SHWBufferLink *HWBuffer) override; - - //! Create hardware buffer from mesh - SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer *mb) override; - - //! Delete hardware buffer (only some drivers can) - void deleteHardwareBuffer(SHWBufferLink *HWBuffer) override; - - //! Draw hardware buffer - void drawHardwareBuffer(SHWBufferLink *HWBuffer) override; - - IRenderTarget *addRenderTarget() override; - - //! 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) override; - - 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 - bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override - { - // return FeatureEnabled[feature] && COGLES1ExtensionHandler::queryFeature(feature); - return COGLES1ExtensionHandler::queryFeature(feature); - } - - //! Sets a material. - void setMaterial(const SMaterial &material) override; - - virtual void draw2DImage(const video::ITexture *texture, const core::position2d &destPos, - const core::rect &sourceRect, const core::rect *clipRect = 0, - SColor color = SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture = false) override; - - virtual void draw2DImage(const video::ITexture *texture, const core::rect &destRect, - const core::rect &sourceRect, const core::rect *clipRect = 0, - const video::SColor *const colors = 0, bool useAlphaChannelOfTexture = false) override; - - virtual void draw2DImage(const video::ITexture *texture, u32 layer, bool flip); - - //! 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> &positions, - const core::array> &sourceRects, - const core::rect *clipRect = 0, - SColor color = SColor(255, 255, 255, 255), - bool useAlphaChannelOfTexture = false) override; - - //! draw an 2d rectangle - virtual void draw2DRectangle(SColor color, const core::rect &pos, - const core::rect *clip = 0) override; - - //! Draws an 2d rectangle with a gradient. - virtual void draw2DRectangle(const core::rect &pos, - SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, - const core::rect *clip = 0) override; - - //! Draws a 2d line. - virtual void draw2DLine(const core::position2d &start, - const core::position2d &end, - SColor color = SColor(255, 255, 255, 255)) override; - - //! Draws a 3d line. - virtual void draw3DLine(const core::vector3df &start, - const core::vector3df &end, - SColor color = SColor(255, 255, 255, 255)) override; - - //! Returns the name of the video driver. - const char *getName() const override; - - //! Sets the dynamic ambient light color. - void setAmbientLight(const SColorf &color) override; - - //! sets a viewport - void setViewPort(const core::rect &area) override; - - //! Sets the fog mode. - virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start, - f32 end, f32 density, bool pixelFog, bool rangeFog) override; - - //! Only used internally by the engine - void OnResize(const core::dimension2d &size) override; - - //! Returns type of video driver - E_DRIVER_TYPE getDriverType() const override; - - //! get color format of the current color buffer - ECOLOR_FORMAT getColorFormat() const override; - - //! Returns the transformation set by setTransform - const core::matrix4 &getTransform(E_TRANSFORMATION_STATE state) const override; - - //! Can be called by an IMaterialRenderer to make its work easier. - virtual void setBasicRenderStates(const SMaterial &material, const SMaterial &lastmaterial, - bool resetAllRenderstates) override; - - //! 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. - s32 getVertexShaderConstantID(const c8 *name) override; - - //! Get a pixel shader constant index. - s32 getPixelShaderConstantID(const c8 *name) override; - - //! Sets a constant for the vertex shader based on an index. - bool setVertexShaderConstant(s32 index, const f32 *floats, int count) override; - - //! Int interface for the above. - bool setVertexShaderConstant(s32 index, const s32 *ints, int count) override; - - //! Uint interface for the above. - bool setVertexShaderConstant(s32 index, const u32 *ints, int count) override; - - //! Sets a constant for the pixel shader based on an index. - bool setPixelShaderConstant(s32 index, const f32 *floats, int count) override; - - //! Int interface for the above. - bool setPixelShaderConstant(s32 index, const s32 *ints, int count) override; - - //! Uint interface for the above. - bool setPixelShaderConstant(s32 index, const u32 *ints, int count) override; - - //! 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, const c8 *geometryShaderProgram, const c8 *geometryShaderEntryPointName, - E_GEOMETRY_SHADER_TYPE gsCompileTarget, scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType, - u32 verticesOut, IShaderConstantSetCallBack *callback, E_MATERIAL_TYPE baseMaterial, - s32 userData) override; - - //! Returns pointer to the IGPUProgrammingServices interface. - IGPUProgrammingServices *getGPUProgrammingServices() override; - - //! Returns a pointer to the IVideoDriver interface. - IVideoDriver *getVideoDriver() override; - - //! Returns the maximum amount of primitives - u32 getMaximalPrimitiveCount() const override; - - virtual ITexture *addRenderTargetTexture(const core::dimension2d &size, - const io::path &name, const ECOLOR_FORMAT format = ECF_UNKNOWN) override; - - //! Creates a render target texture for a cubemap - ITexture *addRenderTargetTextureCubemap(const irr::u32 sideLen, - const io::path &name, const ECOLOR_FORMAT format) override; - - virtual bool setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor = SColor(255, 0, 0, 0), - f32 clearDepth = 1.f, u8 clearStencil = 0) override; - - void clearBuffers(u16 flag, SColor color = SColor(255, 0, 0, 0), f32 depth = 1.f, u8 stencil = 0) override; - - //! Returns an image created from the last rendered frame. - IImage *createScreenShot(video::ECOLOR_FORMAT format = video::ECF_UNKNOWN, video::E_RENDER_TARGET target = video::ERT_FRAME_BUFFER) override; - - //! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number) - bool testGLError(int code = 0); - - //! Returns the graphics card vendor name. - core::stringc getVendorInfo() override - { - return VendorName; - } - - //! Get the maximal texture size for this driver - core::dimension2du getMaxTextureSize() const override; - - void removeTexture(ITexture *texture) override; - - //! Check if the driver supports creating textures with the given color format - bool queryTextureFormat(ECOLOR_FORMAT format) const override; - - //! Used by some SceneNodes to check if a material should be rendered in the transparent render pass - bool needsTransparentRenderPass(const irr::video::SMaterial &material) const override; - - //! Convert E_BLEND_FACTOR to OpenGL equivalent - GLenum getGLBlend(E_BLEND_FACTOR factor) const; - - //! Get ZBuffer bits. - GLenum getZBufferBits() const; - - bool getColorFormatParameters(ECOLOR_FORMAT format, GLint &internalFormat, GLenum &pixelFormat, - GLenum &pixelType, void (**converter)(const void *, s32, void *)) const; - - COGLES1CacheHandler *getCacheHandler() const; - -private: - //! inits the opengl-es driver - bool genericDriverInit(const core::dimension2d &screenSize, bool stencilBuffer); - - ITexture *createDeviceDependentTexture(const io::path &name, IImage *image) override; - - ITexture *createDeviceDependentTextureCubemap(const io::path &name, const std::vector &image) override; - - //! creates a transposed matrix in supplied GLfloat array to pass to OGLES1 - inline void getGLMatrix(GLfloat gl_matrix[16], const core::matrix4 &m); - inline void getGLTextureMatrix(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); - - 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); - - //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` - virtual void setViewPortRaw(u32 width, u32 height); - - COGLES1CacheHandler *CacheHandler; - - core::stringc Name; - core::matrix4 Matrices[ETS_COUNT]; - core::array ColorBuffer; - - //! enumeration for rendering modes such as 2d and 3d for minimizing 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; - - core::stringc VendorName; - - core::matrix4 TextureFlipMatrix; - - //! Color buffer format - ECOLOR_FORMAT ColorFormat; - - SIrrlichtCreationParameters Params; - - IContextManager *ContextManager; -}; - -} // end namespace video -} // end namespace irr - -#endif // _IRR_COMPILE_WITH_OGLES1_ diff --git a/irr/src/COGLESExtensionHandler.cpp b/irr/src/COGLESExtensionHandler.cpp deleted file mode 100644 index 866a984d8..000000000 --- a/irr/src/COGLESExtensionHandler.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2008 Christian Stehno -// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt -// 2017 modified by Michael Zeilfelder (unifying extension handlers) -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#include "COGLESExtensionHandler.h" - -#ifdef _IRR_COMPILE_WITH_OGLES1_ - -#include "irrString.h" -#include "SMaterial.h" -#include "fast_atof.h" - -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) -#include -#else -#include -#endif - -namespace irr -{ -namespace video -{ - -COGLES1ExtensionHandler::COGLES1ExtensionHandler() : - COGLESCoreExtensionHandler(), - MaxLights(0), pGlBlendEquationOES(0), pGlBlendFuncSeparateOES(0), - pGlBindFramebufferOES(0), pGlDeleteFramebuffersOES(0), - pGlGenFramebuffersOES(0), pGlCheckFramebufferStatusOES(0), - pGlFramebufferTexture2DOES(0), pGlGenerateMipmapOES(0) -{ -} - -void COGLES1ExtensionHandler::initExtensions() -{ - getGLVersion(); - - if (Version >= 100) - os::Printer::log("OpenGL ES driver version is 1.1.", ELL_INFORMATION); - else - os::Printer::log("OpenGL ES driver version is 1.0.", ELL_WARNING); - - getGLExtensions(); - - GLint val = 0; - - glGetIntegerv(GL_MAX_LIGHTS, &val); - MaxLights = static_cast(val); - - glGetIntegerv(GL_MAX_TEXTURE_UNITS, &val); - Feature.MaxTextureUnits = static_cast(val); - -#ifdef GL_EXT_texture_filter_anisotropic - if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) { - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val); - MaxAnisotropy = static_cast(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(val); -#ifdef GL_EXT_texture_lod_bias - if (FeatureAvailable[IRR_GL_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); - - Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast(MATERIAL_MAX_TEXTURES)); - Feature.ColorAttachment = 1; - - pGlBlendEquationOES = (PFNGLBLENDEQUATIONOESPROC)eglGetProcAddress("glBlendEquationOES"); - pGlBlendFuncSeparateOES = (PFNGLBLENDFUNCSEPARATEOESPROC)eglGetProcAddress("glBlendFuncSeparateOES"); - pGlBindFramebufferOES = (PFNGLBINDFRAMEBUFFEROESPROC)eglGetProcAddress("glBindFramebufferOES"); - pGlDeleteFramebuffersOES = (PFNGLDELETEFRAMEBUFFERSOESPROC)eglGetProcAddress("glDeleteFramebuffersOES"); - pGlGenFramebuffersOES = (PFNGLGENFRAMEBUFFERSOESPROC)eglGetProcAddress("glGenFramebuffersOES"); - pGlCheckFramebufferStatusOES = (PFNGLCHECKFRAMEBUFFERSTATUSOESPROC)eglGetProcAddress("glCheckFramebufferStatusOES"); - pGlFramebufferTexture2DOES = (PFNGLFRAMEBUFFERTEXTURE2DOESPROC)eglGetProcAddress("glFramebufferTexture2DOES"); - pGlGenerateMipmapOES = (PFNGLGENERATEMIPMAPOESPROC)eglGetProcAddress("glGenerateMipmapOES"); -} - -} // end namespace video -} // end namespace irr - -#endif // _IRR_COMPILE_WITH_OGLES2_ diff --git a/irr/src/COGLESExtensionHandler.h b/irr/src/COGLESExtensionHandler.h deleted file mode 100644 index a316afaad..000000000 --- a/irr/src/COGLESExtensionHandler.h +++ /dev/null @@ -1,189 +0,0 @@ -// 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 - -#pragma once - -#ifdef _IRR_COMPILE_WITH_OGLES1_ - -#include "EDriverFeatures.h" -#include "irrTypes.h" -#include "os.h" - -#include "COGLESCommon.h" - -#include "COGLESCoreExtensionHandler.h" - -namespace irr -{ -namespace video -{ - -class COGLES1ExtensionHandler : public COGLESCoreExtensionHandler -{ -public: - COGLES1ExtensionHandler(); - - void initExtensions(); - - 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_TEXTURE_NSQUARE: - case EVDF_STENCIL_BUFFER: - case EVDF_ALPHA_TO_COVERAGE: - case EVDF_COLOR_MASK: - case EVDF_POLYGON_OFFSET: - case EVDF_TEXTURE_MATRIX: - return true; - case EVDF_TEXTURE_NPOT: - return FeatureAvailable[IRR_GL_APPLE_texture_2D_limited_npot] || FeatureAvailable[IRR_GL_OES_texture_npot]; - case EVDF_MIP_MAP_AUTO_UPDATE: - return Version > 100; - case EVDF_BLEND_OPERATIONS: - return FeatureAvailable[IRR_GL_OES_blend_subtract]; - case EVDF_BLEND_SEPARATE: - return FeatureAvailable[IRR_GL_OES_blend_func_separate]; - case EVDF_FRAMEBUFFER_OBJECT: - return FeatureAvailable[IRR_GL_OES_framebuffer_object]; - case EVDF_VERTEX_BUFFER_OBJECT: - return Version > 100; - default: - return true; - }; - } - - inline void irrGlActiveTexture(GLenum texture) - { - glActiveTexture(texture); - } - - inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, - GLsizei imageSize, const void *data) - { - glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); - } - - inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum format, GLsizei imageSize, const void *data) - { - glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); - } - - inline void irrGlUseProgram(GLuint prog) - { - } - - inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) - { - if (pGlBindFramebufferOES) - pGlBindFramebufferOES(target, framebuffer); - } - - inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) - { - if (pGlDeleteFramebuffersOES) - pGlDeleteFramebuffersOES(n, framebuffers); - } - - inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) - { - if (pGlGenFramebuffersOES) - pGlGenFramebuffersOES(n, framebuffers); - } - - inline GLenum irrGlCheckFramebufferStatus(GLenum target) - { - if (pGlCheckFramebufferStatusOES) - return pGlCheckFramebufferStatusOES(target); - else - return 0; - } - - inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) - { - if (pGlFramebufferTexture2DOES) - pGlFramebufferTexture2DOES(target, attachment, textarget, texture, level); - } - - inline void irrGlGenerateMipmap(GLenum target) - { - if (pGlGenerateMipmapOES) - pGlGenerateMipmapOES(target); - } - - inline void irrGlActiveStencilFace(GLenum face) - { - } - - inline void irrGlDrawBuffer(GLenum mode) - { - } - - inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) - { - } - - inline void irrGlBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) - { - if (pGlBlendFuncSeparateOES) - pGlBlendFuncSeparateOES(srcRGB, dstRGB, srcAlpha, dstAlpha); - } - - inline void irrGlBlendEquation(GLenum mode) - { - if (pGlBlendEquationOES) - pGlBlendEquationOES(mode); - } - - inline void irrGlEnableIndexed(GLenum target, GLuint index) - { - } - - inline void irrGlDisableIndexed(GLenum target, GLuint index) - { - } - - inline void irrGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a) - { - } - - inline void irrGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst) - { - } - - inline void irrGlBlendFuncSeparateIndexed(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) - { - } - - inline void irrGlBlendEquationIndexed(GLuint buf, GLenum mode) - { - } - - inline void irrGlBlendEquationSeparateIndexed(GLuint buf, GLenum modeRGB, GLenum modeAlpha) - { - } - -protected: - u8 MaxLights; - - PFNGLBLENDEQUATIONOESPROC pGlBlendEquationOES; - PFNGLBLENDFUNCSEPARATEOESPROC pGlBlendFuncSeparateOES; - PFNGLBINDFRAMEBUFFEROESPROC pGlBindFramebufferOES; - PFNGLDELETEFRAMEBUFFERSOESPROC pGlDeleteFramebuffersOES; - PFNGLGENFRAMEBUFFERSOESPROC pGlGenFramebuffersOES; - PFNGLCHECKFRAMEBUFFERSTATUSOESPROC pGlCheckFramebufferStatusOES; - PFNGLFRAMEBUFFERTEXTURE2DOESPROC pGlFramebufferTexture2DOES; - PFNGLGENERATEMIPMAPOESPROC pGlGenerateMipmapOES; -}; - -} -} - -#endif diff --git a/irr/src/COGLESMaterialRenderer.h b/irr/src/COGLESMaterialRenderer.h deleted file mode 100644 index 69d1b81ff..000000000 --- a/irr/src/COGLESMaterialRenderer.h +++ /dev/null @@ -1,286 +0,0 @@ -// 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 - -#pragma once - -#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->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->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); - - // if (material.MaterialType != lastMaterial.MaterialType || - // material.MaterialTypeParam != lastMaterial.MaterialTypeParam || - // resetAllRenderstates) - { - E_BLEND_FACTOR srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact; - E_MODULATE_FUNC modulate; - u32 alphaSource; - unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); - - Driver->getCacheHandler()->setBlend(true); - - if (Driver->queryFeature(EVDF_BLEND_SEPARATE)) { - Driver->getCacheHandler()->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), - Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); - } else { - Driver->getCacheHandler()->setBlendFunc(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact)); - } - - 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); - - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, 0.f); - - if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || - textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) { - 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); - - Driver->getCacheHandler()->setBlend(false); - 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; - } -}; - -//! 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->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); - - Driver->getCacheHandler()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - Driver->getCacheHandler()->setBlend(true); - - 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); - } - } - - 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); - - Driver->getCacheHandler()->setBlend(false); - } - - //! 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->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); - - Driver->getCacheHandler()->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Driver->getCacheHandler()->setBlend(true); - - 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); - - glEnable(GL_ALPHA_TEST); - - glAlphaFunc(GL_GREATER, material.MaterialTypeParam); - } - } - - virtual void OnUnsetMaterial() - { - glDisable(GL_ALPHA_TEST); - Driver->getCacheHandler()->setBlend(false); - } - - //! 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->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_MODULATE); - } - } - - 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. - } -}; - -} // end namespace video -} // end namespace irr - -#endif diff --git a/irr/src/COpenGLCoreCacheHandler.h b/irr/src/COpenGLCoreCacheHandler.h index ae3661313..a1277bfed 100644 --- a/irr/src/COpenGLCoreCacheHandler.h +++ b/irr/src/COpenGLCoreCacheHandler.h @@ -84,12 +84,12 @@ class COpenGLCoreCacheHandler if (curTextureType != prevTextureType) { GL.BindTexture(prevTextureType, 0); -#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) +#if defined(IRR_COMPILE_GL_COMMON) GL.Disable(prevTextureType); GL.Enable(curTextureType); #endif } -#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) +#if defined(IRR_COMPILE_GL_COMMON) else if (!prevTexture) GL.Enable(curTextureType); #endif @@ -109,7 +109,7 @@ class COpenGLCoreCacheHandler GL.BindTexture(prevTextureType, 0); -#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) +#if defined(IRR_COMPILE_GL_COMMON) GL.Disable(prevTextureType); #endif } @@ -222,7 +222,7 @@ public: Driver->irrGlActiveTexture(ActiveTexture); -#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) +#if defined(IRR_COMPILE_GL_COMMON) GL.Disable(GL_TEXTURE_2D); #endif diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h index 218eabece..95cac4c22 100644 --- a/irr/src/COpenGLCoreTexture.h +++ b/irr/src/COpenGLCoreTexture.h @@ -296,8 +296,7 @@ public: delete[] tmpBuffer; } -#elif (defined(IRR_COMPILE_GLES2_COMMON) || defined(IRR_COMPILE_GLES_COMMON)) - // TODO: on ES2 we can likely also work with glCopyTexImage2D instead of rendering which should be faster. +#elif defined(IRR_COMPILE_GLES2_COMMON) COpenGLCoreTexture *tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver); GLuint tmpFBO = 0; diff --git a/irr/src/Irrlicht.cpp b/irr/src/Irrlicht.cpp index d119584e3..eb94fa4eb 100644 --- a/irr/src/Irrlicht.cpp +++ b/irr/src/Irrlicht.cpp @@ -100,10 +100,6 @@ extern "C" IRRLICHT_API bool IRRCALLCONV isDriverSupported(E_DRIVER_TYPE driver) case EDT_OPENGL: return true; #endif -#ifdef _IRR_COMPILE_WITH_OGLES1_ - case EDT_OGLES1: - return true; -#endif #ifdef _IRR_COMPILE_WITH_OGLES2_ case EDT_OGLES2: return true; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 18b9ff158..4400dd90e 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -418,7 +418,6 @@ std::vector RenderingEngine::getSupportedVideoDrivers() video::EDT_OPENGL, video::EDT_OPENGL3, video::EDT_OGLES2, - video::EDT_OGLES1, video::EDT_NULL, }; std::vector drivers; @@ -454,7 +453,6 @@ const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_ {(int)video::EDT_NULL, {"null", "NULL Driver"}}, {(int)video::EDT_OPENGL, {"opengl", "OpenGL"}}, {(int)video::EDT_OPENGL3, {"opengl3", "OpenGL 3+"}}, - {(int)video::EDT_OGLES1, {"ogles1", "OpenGL ES1"}}, {(int)video::EDT_OGLES2, {"ogles2", "OpenGL ES2"}}, }; return driver_info_map.at((int)type);