From 38f18eec569f88496465b04c152de905087ca9e2 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 19 Feb 2023 18:22:43 +0300 Subject: [PATCH 01/42] Drop unused stuff from IrrCompileConfig --- include/IrrCompileConfig.h | 182 ++++--------------------------------- 1 file changed, 19 insertions(+), 163 deletions(-) diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index fe1e29d..deade75 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -132,43 +132,6 @@ //! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. #define _IRR_MATERIAL_MAX_TEXTURES_ 4 -//! Add a leak-hunter to Irrlicht which helps finding unreleased reference counted objects. -//! NOTE: This is slow and should only be used for debugging -//#define _IRR_COMPILE_WITH_LEAK_HUNTER_ -#ifdef NO_IRR_COMPILE_WITH_LEAK_HUNTER_ -#undef _IRR_COMPILE_WITH_LEAK_HUNTER_ -#endif - -//! Enable profiling information in the engine -/** NOTE: The profiler itself always exists and can be used by applications. -This define is about the engine creating profile data -while it runs and enabling it will slow down the engine. */ -//#define _IRR_COMPILE_WITH_PROFILING_ -#ifdef NO_IRR_COMPILE_WITH_PROFILING_ -#undef _IRR_COMPILE_WITH_PROFILING_ -#endif - -//! Define _IRR_COMPILE_WITH_DIRECT3D_9_ to compile the Irrlicht engine with DIRECT3D9. -/** If you only want to use the software device or opengl you can disable those defines. -This switch is mostly disabled because people do not get the g++ compiler compile -directX header files, and directX is only available on Windows platforms. If you -are using Dev-Cpp, and want to compile this using a DX dev pack, you can define -_IRR_COMPILE_WITH_DX9_DEV_PACK_. So you simply need to add something like this -to the compiler settings: -DIRR_COMPILE_WITH_DX9_DEV_PACK -and this to the linker settings: -ld3dx9 -*/ -#if defined(_IRR_WINDOWS_API_) && defined(IRR_COMPILE_WITH_DX9_DEV_PACK) - -//! Define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ if you want to use DirectInput for joystick handling. -/** This only applies to Windows devices, currently only supported under Win32 device. -If not defined, Windows Multimedia library is used, which offers also broad support for joystick devices. */ -#define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ -#ifdef NO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ -#undef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ -#endif - -#endif - //! Define _IRR_COMPILE_WITH_OPENGL_ to compile the Irrlicht engine with OpenGL. /** If you do not wish the engine to be compiled with OpenGL, comment this define out. */ @@ -289,123 +252,11 @@ define out. */ #endif -//! Define _IRR_COMPILE_WITH_GUI_ to compile the engine with the built-in GUI -/** Disable this if you are using an external library to draw the GUI. If you disable this then -you will not be able to use anything provided by the GUI Environment, including loading fonts. */ -#define _IRR_COMPILE_WITH_GUI_ -#ifdef NO_IRR_COMPILE_WITH_GUI_ -#undef _IRR_COMPILE_WITH_GUI_ + +#if defined(_IRR_SOLARIS_PLATFORM_) + #undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #endif -//! Define _IRR_COMPILE_WITH_LIBJPEG_ to enable compiling the engine using libjpeg. -/** This enables the engine to read jpeg images. If you comment this out, -the engine will no longer read .jpeg images. */ -#define _IRR_COMPILE_WITH_LIBJPEG_ -#ifdef NO_IRR_COMPILE_WITH_LIBJPEG_ -#undef _IRR_COMPILE_WITH_LIBJPEG_ -#endif - -//! Define _IRR_COMPILE_WITH_LIBPNG_ to enable compiling the engine using libpng. -/** This enables the engine to read png images. If you comment this out, -the engine will no longer read .png images. */ -#define _IRR_COMPILE_WITH_LIBPNG_ -#ifdef NO_IRR_COMPILE_WITH_LIBPNG_ -#undef _IRR_COMPILE_WITH_LIBPNG_ -#endif - -//! Uncomment the following line if you want to ignore the deprecated warnings -//#define IGNORE_DEPRECATED_WARNING - -//! Define _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ to support BillboardSceneNodes -#define _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ -#ifdef NO_IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ -#undef _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ -#endif - -//! Define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ if you want to use bone based -/** animated meshes. If you compile without this, you will be unable to load -B3D, MS3D or X meshes */ -#define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ -#ifdef NO_IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ -#undef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ -#endif - -#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ -//! Define _IRR_COMPILE_WITH_B3D_LOADER_ if you want to use Blitz3D files -#define _IRR_COMPILE_WITH_B3D_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_B3D_LOADER_ -#undef _IRR_COMPILE_WITH_B3D_LOADER_ -#endif -//! Define _IRR_COMPILE_WITH_X_LOADER_ if you want to use Microsoft X files -#define _IRR_COMPILE_WITH_X_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_X_LOADER_ -#undef _IRR_COMPILE_WITH_X_LOADER_ -#endif -#endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ - -//! Define _IRR_COMPILE_WITH_OBJ_LOADER_ if you want to load Wavefront OBJ files -#define _IRR_COMPILE_WITH_OBJ_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_OBJ_LOADER_ -#undef _IRR_COMPILE_WITH_OBJ_LOADER_ -#endif - -//! Define _IRR_COMPILE_WITH_BMP_LOADER_ if you want to load .bmp files -//! Disabling this loader will also disable the built-in font -#define _IRR_COMPILE_WITH_BMP_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_BMP_LOADER_ -#undef _IRR_COMPILE_WITH_BMP_LOADER_ -#endif -//! Define _IRR_COMPILE_WITH_JPG_LOADER_ if you want to load .jpg files -#define _IRR_COMPILE_WITH_JPG_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_JPG_LOADER_ -#undef _IRR_COMPILE_WITH_JPG_LOADER_ -#endif -//! Define _IRR_COMPILE_WITH_PNG_LOADER_ if you want to load .png files -#define _IRR_COMPILE_WITH_PNG_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_PNG_LOADER_ -#undef _IRR_COMPILE_WITH_PNG_LOADER_ -#endif -//! Define _IRR_COMPILE_WITH_TGA_LOADER_ if you want to load .tga files -#define _IRR_COMPILE_WITH_TGA_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_TGA_LOADER_ -#undef _IRR_COMPILE_WITH_TGA_LOADER_ -#endif - -//! Define _IRR_COMPILE_WITH_JPG_WRITER_ if you want to write .jpg files -#define _IRR_COMPILE_WITH_JPG_WRITER_ -#ifdef NO_IRR_COMPILE_WITH_JPG_WRITER_ -#undef _IRR_COMPILE_WITH_JPG_WRITER_ -#endif -//! Define _IRR_COMPILE_WITH_PNG_WRITER_ if you want to write .png files -#define _IRR_COMPILE_WITH_PNG_WRITER_ -#ifdef NO_IRR_COMPILE_WITH_PNG_WRITER_ -#undef _IRR_COMPILE_WITH_PNG_WRITER_ -#endif - -//! Define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ if you want to open ZIP and GZIP archives -/** ZIP reading has several more options below to configure. */ -#define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ -#ifdef NO__IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ -#undef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ -#endif -#ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ -//! Define _IRR_COMPILE_WITH_ZLIB_ to enable compiling the engine using zlib. -/** This enables the engine to read from compressed .zip archives. If you -disable this feature, the engine can still read archives, but only uncompressed -ones. */ -#define _IRR_COMPILE_WITH_ZLIB_ -#ifdef NO_IRR_COMPILE_WITH_ZLIB_ -#undef _IRR_COMPILE_WITH_ZLIB_ -#endif -#endif - -//! Define __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ if you want to mount folders as archives -#define __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ -#ifdef NO__IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ -#undef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ -#endif - -// Some cleanup and standard stuff #ifdef _IRR_WINDOWS_API_ @@ -441,19 +292,25 @@ ones. */ #endif // _IRR_WINDOWS_API_ -#if defined(_IRR_SOLARIS_PLATFORM_) - #undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -#endif -//! Define __IRR_HAS_S64 if the irr::s64 type should be enable (needs long long, available on most platforms, but not part of ISO C++ 98) +#define _IRR_COMPILE_WITH_GUI_ +#define _IRR_COMPILE_WITH_LIBJPEG_ +#define _IRR_COMPILE_WITH_LIBPNG_ +#define _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ +#define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ +#define _IRR_COMPILE_WITH_B3D_LOADER_ +#define _IRR_COMPILE_WITH_X_LOADER_ +#define _IRR_COMPILE_WITH_OBJ_LOADER_ +#define _IRR_COMPILE_WITH_BMP_LOADER_ +#define _IRR_COMPILE_WITH_JPG_LOADER_ +#define _IRR_COMPILE_WITH_PNG_LOADER_ +#define _IRR_COMPILE_WITH_TGA_LOADER_ +#define _IRR_COMPILE_WITH_JPG_WRITER_ +#define _IRR_COMPILE_WITH_PNG_WRITER_ +#define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ +#define _IRR_COMPILE_WITH_ZLIB_ #define __IRR_HAS_S64 -#ifdef NO__IRR_HAS_S64 -#undef __IRR_HAS_S64 -#endif -#ifndef __has_feature - #define __has_feature(x) 0 // Compatibility with non-clang compilers. -#endif #ifdef _DEBUG //! A few attributes are written in CSceneManager when _IRR_SCENEMANAGER_DEBUG is enabled @@ -470,4 +327,3 @@ ones. */ #endif #endif // __IRR_COMPILE_CONFIG_H_INCLUDED__ - From 06db7b7ab7a4b439545a409d03d1e075506699ec Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 19 Feb 2023 22:44:02 +0300 Subject: [PATCH 02/42] Move platform detection to CMake --- .github/workflows/build.yml | 9 +- examples/AutomatedTest/main.cpp | 12 +- include/EDeviceTypes.h | 2 +- include/IEventReceiver.h | 8 +- include/IrrCompileConfig.h | 233 ------------------------------- include/IrrlichtDevice.h | 36 +---- include/SIrrCreationParameters.h | 2 +- include/exampleHelper.h | 2 +- include/irrUString.h | 4 +- source/Irrlicht/CMakeLists.txt | 202 ++++++++++++++++++++++++--- 10 files changed, 201 insertions(+), 309 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef5d462..41dc3d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,9 +48,7 @@ jobs: - name: Build run: | - sed '/#define _IRR_COMPILE_WITH_OGLES2_/ s|^//||g' -i include/IrrCompileConfig.h - sed '/#define _IRR_COMPILE_WITH_OPENGL_/ s|^|//|g' -i include/IrrCompileConfig.h - cmake . -DBUILD_EXAMPLES=1 + cmake . -DBUILD_EXAMPLES=1 -DENABLE_OPENGL=OFF -DENABLE_GLES2=ON make -j2 - name: Test (headless) @@ -61,7 +59,7 @@ jobs: - name: Test (Xvfb) run: | cd bin/Linux - LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest + LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest ogles2 linux-sdl: runs-on: ubuntu-latest @@ -77,8 +75,7 @@ jobs: - name: Build run: | - sed '/#define _IRR_COMPILE_WITH_SDL_DEVICE_/ s|^//||g' -i include/IrrCompileConfig.h - cmake . -DBUILD_EXAMPLES=1 + cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON make -j2 - name: Test (headless) diff --git a/examples/AutomatedTest/main.cpp b/examples/AutomatedTest/main.cpp index e724176..0141b2b 100644 --- a/examples/AutomatedTest/main.cpp +++ b/examples/AutomatedTest/main.cpp @@ -10,15 +10,17 @@ static int test_fail = 0; void test_irr_array(); void test_irr_string(); -static video::E_DRIVER_TYPE chooseDriver(const char *arg_) +static video::E_DRIVER_TYPE chooseDriver(core::stringc arg_) { - if (core::stringc(arg_) == "null") + if (arg_ == "null") return video::EDT_NULL; - - if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES1)) + if (arg_ == "ogles1") return video::EDT_OGLES1; - if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES2)) + if (arg_ == "ogles2") return video::EDT_OGLES2; + if (arg_ == "opengl") + return video::EDT_OPENGL; + std::cerr << "Unknown driver type: " << arg_.c_str() << ". Trying OpenGL." << std::endl; return video::EDT_OPENGL; } diff --git a/include/EDeviceTypes.h b/include/EDeviceTypes.h index be61460..a0c1ca7 100644 --- a/include/EDeviceTypes.h +++ b/include/EDeviceTypes.h @@ -31,7 +31,7 @@ namespace irr //! A device which uses Simple DirectMedia Layer /** The SDL device works under all platforms supported by SDL but first must be compiled - in by defining the _IRR_COMPILE_WITH_SDL_DEVICE_ macro in IrrCompileConfig.h */ + in by setting the USE_SDL2 CMake option to ON */ EIDT_SDL, //! This selection allows Irrlicht to choose the best device from the ones available. diff --git a/include/IEventReceiver.h b/include/IEventReceiver.h index 91588a3..ed82b5f 100644 --- a/include/IEventReceiver.h +++ b/include/IEventReceiver.h @@ -452,10 +452,10 @@ struct SEvent /** Unlike other events, joystick events represent the result of polling * each connected joystick once per run() of the device. Joystick events will * not be generated by default. If joystick support is available for the - * active device, _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ is defined, and - * @ref irr::IrrlichtDevice::activateJoysticks() has been called, an event of - * this type will be generated once per joystick per @ref IrrlichtDevice::run() - * regardless of whether the state of the joystick has actually changed. */ + * active device, and @ref irr::IrrlichtDevice::activateJoysticks() has been + * called, an event of this type will be generated once per joystick per + * @ref IrrlichtDevice::run() regardless of whether the state of the joystick + * has actually changed. */ struct SJoystickEvent { enum diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index deade75..7d3c458 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -20,243 +20,10 @@ #include // TODO: Although included elsewhere this is required at least for mingw -//! The defines for different operating system are: -//! _IRR_WINDOWS_ for all irrlicht supported Windows versions -//! _IRR_WINDOWS_API_ for Windows or XBox -//! _IRR_LINUX_PLATFORM_ for Linux (it is defined here if no other os is defined) -//! _IRR_SOLARIS_PLATFORM_ for Solaris -//! _IRR_OSX_PLATFORM_ for Apple systems running OSX -//! _IRR_IOS_PLATFORM_ for Apple devices running iOS -//! _IRR_ANDROID_PLATFORM_ for devices running Android -//! _IRR_POSIX_API_ for Posix compatible systems -//! Note: PLATFORM defines the OS specific layer, API can group several platforms - -//! DEVICE is the windowing system used, several PLATFORMs support more than one DEVICE -//! Irrlicht can be compiled with more than one device -//! _IRR_COMPILE_WITH_WINDOWS_DEVICE_ for Windows API based device -//! _IRR_COMPILE_WITH_OSX_DEVICE_ for Cocoa native windowing on OSX -//! _IRR_COMPILE_WITH_X11_DEVICE_ for Linux X11 based device -//! _IRR_COMPILE_WITH_SDL_DEVICE_ for platform independent SDL framework - -//! Passing defines to the compiler which have NO in front of the _IRR definename is an alternative -//! way which can be used to disable defines (instead of outcommenting them in this header). -//! So defines can be controlled from Makefiles or Projectfiles which allows building -//! different library versions without having to change the sources. -//! Example: NO_IRR_COMPILE_WITH_X11_ would disable X11 - -//! Uncomment this line to compile with the SDL device -//#define _IRR_COMPILE_WITH_SDL_DEVICE_ -#ifdef NO_IRR_COMPILE_WITH_SDL_DEVICE_ -#undef _IRR_COMPILE_WITH_SDL_DEVICE_ -#endif - -//! WIN32 for Windows32 -//! WIN64 for Windows64 -// The windows platform and API support SDL and WINDOW device -#if defined(_WIN32) || defined(_WIN64) -#define _IRR_WINDOWS_ -#define _IRR_WINDOWS_API_ -#ifndef _IRR_COMPILE_WITH_SDL_DEVICE_ -#define _IRR_COMPILE_WITH_WINDOWS_DEVICE_ -#endif -#endif - -#if defined(__APPLE__) -#if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED) -#define _IRR_IOS_PLATFORM_ -#define _IRR_COMPILE_WITH_IOS_DEVICE_ -#define NO_IRR_COMPILE_WITH_OPENGL_ -// The application state events and following methods: IrrlichtDevice::isWindowActive, IrrlichtDevice::isWindowFocused, -// IrrlichtDevice::isWindowMinimized works out of box only if you'll use built-in CIrrDelegateiOS, -// so _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ must be enabled in this case. If you need a custom UIApplicationDelegate -// you must disable _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ definition and handle all application events yourself. -#define _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ -#else -#define _IRR_OSX_PLATFORM_ -#ifndef _IRR_COMPILE_WITH_SDL_DEVICE_ -#define _IRR_COMPILE_WITH_OSX_DEVICE_ -#endif -#define NO_IRR_COMPILE_WITH_OGLES1_ -#define NO_IRR_COMPILE_WITH_OGLES2_ -#define NO_IRR_COMPILE_WITH_WEBGL1_ -#endif -#endif - -#if defined(__EMSCRIPTEN__) -#define _IRR_EMSCRIPTEN_PLATFORM_ -#define NO_IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -#define NO_IRR_COMPILE_WITH_OPENGL_ -#define NO_IRR_COMPILE_WITH_OGLES1_ -#define _IRR_COMPILE_WITH_OGLES2_ -#define _IRR_COMPILE_WITH_WEBGL1_ -#define _IRR_COMPILE_WITH_EGL_MANAGER_ -#define _IRR_COMPILE_WITH_SDL_DEVICE_ -#define NO_IRR_COMPILE_WITH_X11_DEVICE_ -#define _IRR_LINUX_PLATFORM_ // emscripten basically working like a unix -#endif // __EMSCRIPTEN__ - -#if defined(__ANDROID__) -#define _IRR_ANDROID_PLATFORM_ -#define _IRR_COMPILE_WITH_ANDROID_DEVICE_ -#define _IRR_COMPILE_ANDROID_ASSET_READER_ -#define NO_IRR_COMPILE_WITH_OPENGL_ -#endif - -#if defined(__SVR4) && defined(__sun) -#define _IRR_SOLARIS_PLATFORM_ -#if defined(__sparc) - #define __BIG_ENDIAN__ -#endif -#endif - -#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_IOS_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_) && !defined(_IRR_EMSCRIPTEN_PLATFORM_) -#ifndef _IRR_SOLARIS_PLATFORM_ -#define _IRR_LINUX_PLATFORM_ -#endif -#define _IRR_POSIX_API_ -#ifndef _IRR_COMPILE_WITH_SDL_DEVICE_ -#define _IRR_COMPILE_WITH_X11_DEVICE_ -#endif -#endif - - -//! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events. -#if !(defined(__FreeBSD__) || defined(__OpenBSD__)) -#define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -#endif -#ifdef NO_IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -#undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -#endif - //! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. #define _IRR_MATERIAL_MAX_TEXTURES_ 4 -//! Define _IRR_COMPILE_WITH_OPENGL_ to compile the Irrlicht engine with OpenGL. -/** If you do not wish the engine to be compiled with OpenGL, comment this -define out. */ -#define _IRR_COMPILE_WITH_OPENGL_ -#ifdef NO_IRR_COMPILE_WITH_OPENGL_ -#undef _IRR_COMPILE_WITH_OPENGL_ -#endif - -//! Define required options for OpenGL drivers. -#if defined(_IRR_COMPILE_WITH_OPENGL_) - #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - #define _IRR_OPENGL_USE_EXTPOINTER_ - #define _IRR_COMPILE_WITH_WGL_MANAGER_ - #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - #define _IRR_OPENGL_USE_EXTPOINTER_ - #define _IRR_COMPILE_WITH_GLX_MANAGER_ - #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) - #define _IRR_COMPILE_WITH_NSOGL_MANAGER_ - #elif defined(_IRR_SOLARIS_PLATFORM_) - #define _IRR_COMPILE_WITH_GLX_MANAGER_ - #elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_) - #define _IRR_OPENGL_USE_EXTPOINTER_ - #endif -#endif - -//! Define _IRR_COMPILE_WITH_OGLES1_ to compile the Irrlicht engine with OpenGL ES 1.1. -/** If you do not wish the engine to be compiled with OpenGL ES 1.1, comment this -define out. -Depending on platform you may have to enable _IRR_OGLES1_USE_KHRONOS_API_HEADERS_ as well when using it. -*/ -#if defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) -#define _IRR_COMPILE_WITH_OGLES1_ -#endif -#ifdef NO_IRR_COMPILE_WITH_OGLES1_ -#undef _IRR_COMPILE_WITH_OGLES1_ -#endif - -#ifdef _IRR_COMPILE_WITH_OGLES1_ -//! Define _IRR_OGLES1_USE_KHRONOS_API_HEADERS_ to use the OpenGL ES headers from the Debian Khronos-api package -//#define _IRR_OGLES1_USE_KHRONOS_API_HEADERS_ -#endif - -//! Define required options for OpenGL ES 1.1 drivers. -#if defined(_IRR_COMPILE_WITH_OGLES1_) -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) -#define _IRR_OGLES1_USE_EXTPOINTER_ -#ifndef _IRR_COMPILE_WITH_EGL_MANAGER_ -#define _IRR_COMPILE_WITH_EGL_MANAGER_ -#endif -#elif defined(_IRR_COMPILE_WITH_IOS_DEVICE_) -#ifndef _IRR_COMPILE_WITH_EAGL_MANAGER_ -#define _IRR_COMPILE_WITH_EAGL_MANAGER_ -#endif -#endif -#endif - -//! Define _IRR_COMPILE_WITH_OGLES2_ to compile the Irrlicht engine with OpenGL ES 2.0. -/** If you do not wish the engine to be compiled with OpenGL ES 2.0, comment this -define out. */ -#if defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) -#define _IRR_COMPILE_WITH_OGLES2_ -#else -//#define _IRR_COMPILE_WITH_OGLES2_ -#endif -#ifdef NO_IRR_COMPILE_WITH_OGLES2_ -#undef _IRR_COMPILE_WITH_OGLES2_ -#endif - -//! Define _IRR_COMPILE_WITH_WEBGL1_ to compile Irrlicht engine with a WebGL friendly -//! subset of the OpenGL ES 2.0 driver. -//#define _IRR_COMPILE_WITH_WEBGL1_ -#ifdef NO_IRR_COMPILE_WITH_WEBGL1_ -#undef _IRR_COMPILE_WITH_WEBGL1_ -#endif -#ifdef _IRR_COMPILE_WITH_WEBGL1_ -#define _IRR_COMPILE_WITH_OGLES2_ // it's a subset of OGL ES2, so always needed when using WebGL -#endif - -//! Define required options for OpenGL ES 2.0 drivers. -#if defined(_IRR_COMPILE_WITH_OGLES2_) -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(__EMSCRIPTEN__) -#define _IRR_OGLES2_USE_EXTPOINTER_ -#ifndef _IRR_COMPILE_WITH_EGL_MANAGER_ -#define _IRR_COMPILE_WITH_EGL_MANAGER_ -#endif -#elif defined(_IRR_COMPILE_WITH_IOS_DEVICE_) -#ifndef _IRR_COMPILE_WITH_EAGL_MANAGER_ -#define _IRR_COMPILE_WITH_EAGL_MANAGER_ -#endif -#endif -#endif - - - -//! Define _IRR_COMPILE_WITH_X11_ to compile the Irrlicht engine with X11 support. -/** If you do not wish the engine to be compiled with X11, comment this -define out. */ -// Only used in LinuxDevice. -#define _IRR_COMPILE_WITH_X11_ -#ifdef NO_IRR_COMPILE_WITH_X11_ -#undef _IRR_COMPILE_WITH_X11_ -#endif - -#if defined(_IRR_LINUX_PLATFORM_) && defined(_IRR_COMPILE_WITH_X11_) -//! XInput2 (library called Xi) is currently only used to support touch-input. -#define _IRR_LINUX_X11_XINPUT2_ -#ifdef NO_IRR_LINUX_X11_XINPUT2_ -#undef _IRR_LINUX_X11_XINPUT2_ -#endif - -//! X11 has by default only monochrome cursors, but using the Xcursor library we can also get color cursor support. -//! If you have the need for custom color cursors on X11 then enable this and make sure you also link -//! to the Xcursor library in your Makefile/Projectfile. -//#define _IRR_LINUX_XCURSOR_ -#ifdef NO_IRR_LINUX_XCURSOR_ -#undef _IRR_LINUX_XCURSOR_ -#endif - -#endif - - -#if defined(_IRR_SOLARIS_PLATFORM_) - #undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -#endif - #ifdef _IRR_WINDOWS_API_ diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index b967d70..07d4f9f 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -235,8 +235,8 @@ namespace irr as this would consume joystick info that 3rd party libraries might rely on. Call this method to activate joystick support in Irrlicht and to receive irr::SJoystickEvent events. \param joystickInfo On return, this will contain an array of each joystick that was found and activated. - \return true if joysticks are supported on this device and _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ - is defined, false if joysticks are not supported or support is compiled out. + \return true if joysticks are supported on this device, false if joysticks are not + supported or support is compiled out. */ virtual bool activateJoysticks(core::array& joystickInfo) =0; @@ -310,37 +310,7 @@ namespace irr for a configuration requested when creating the device. */ static bool isDriverSupported(video::E_DRIVER_TYPE driver) { - switch (driver) - { - case video::EDT_NULL: - return true; - case video::EDT_OPENGL: -#ifdef _IRR_COMPILE_WITH_OPENGL_ - return true; -#else - return false; -#endif - case video::EDT_OGLES1: -#ifdef _IRR_COMPILE_WITH_OGLES1_ - return true; -#else - return false; -#endif - case video::EDT_OGLES2: -#ifdef _IRR_COMPILE_WITH_OGLES2_ - return true; -#else - return false; -#endif - case video::EDT_WEBGL1: -#ifdef _IRR_COMPILE_WITH_WEBGL1_ - return true; -#else - return false; -#endif - default: - return false; - } + return true; } }; diff --git a/include/SIrrCreationParameters.h b/include/SIrrCreationParameters.h index f99fce5..c47f3e6 100644 --- a/include/SIrrCreationParameters.h +++ b/include/SIrrCreationParameters.h @@ -53,7 +53,7 @@ namespace irr UsePerformanceTimer(true), SDK_version_do_not_use(IRRLICHT_SDK_VERSION), PrivateData(0), -#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_) || defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_EMSCRIPTEN_PLATFORM_) +#ifdef IRR_MOBILE_PATHS OGLES2ShaderPath("media/Shaders/") #else OGLES2ShaderPath("../../media/Shaders/") diff --git a/include/exampleHelper.h b/include/exampleHelper.h index e1e7cb2..803ed6e 100755 --- a/include/exampleHelper.h +++ b/include/exampleHelper.h @@ -13,7 +13,7 @@ namespace irr static io::path getExampleMediaPath() { -#if defined (_IRR_IOS_PLATFORM_) || defined (_IRR_ANDROID_PLATFORM_) || defined (_IRR_OSX_PLATFORM_) || defined (_IRR_EMSCRIPTEN_PLATFORM_) +#ifdef IRR_MOBILE_PATHS return io::path("media/"); #else return io::path("../../media/"); diff --git a/include/irrUString.h b/include/irrUString.h index a50d497..61c36b8 100644 --- a/include/irrUString.h +++ b/include/irrUString.h @@ -174,7 +174,7 @@ inline core::array getUnicodeBOM(EUTF_ENCODE mode) COPY_ARRAY(BOM_ENCODE_UTF8, BOM_ENCODE_UTF8_LEN); break; case EUTFE_UTF16: - #ifdef __BIG_ENDIAN__ + #if __BYTE_ORDER == __BIG_ENDIAN COPY_ARRAY(BOM_ENCODE_UTF16_BE, BOM_ENCODE_UTF16_LEN); #else COPY_ARRAY(BOM_ENCODE_UTF16_LE, BOM_ENCODE_UTF16_LEN); @@ -187,7 +187,7 @@ inline core::array getUnicodeBOM(EUTF_ENCODE mode) COPY_ARRAY(BOM_ENCODE_UTF16_LE, BOM_ENCODE_UTF16_LEN); break; case EUTFE_UTF32: - #ifdef __BIG_ENDIAN__ + #if __BYTE_ORDER == __BIG_ENDIAN COPY_ARRAY(BOM_ENCODE_UTF32_BE, BOM_ENCODE_UTF32_LEN); #else COPY_ARRAY(BOM_ENCODE_UTF32_LE, BOM_ENCODE_UTF32_LEN); diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 208b573..76228d1 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -1,4 +1,5 @@ option(BUILD_SHARED_LIBS "Build shared library" TRUE) +option(USE_SDL2 "Use the SDL2 backend" FALSE) # Compiler flags @@ -56,46 +57,195 @@ if(NOT REVISION_SANITY_CHECK) message(FATAL_ERROR "IrrlichtMt revision number mismatches between CMake and headers.") endif() +# Platform-specific configuration + +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + set(SOLARIS TRUE) +endif() +if(APPLE AND NOT IOS) + set(OSX TRUE) +endif() + +# Device + +if(WIN32) + add_definitions(-D_IRR_WINDOWS_ -D_IRR_WINDOWS_API_) + set(DEVICE "WINDOWS") +elseif(IOS) + add_definitions(-D_IRR_IOS_PLATFORM_ -D_IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_) + if(USE_SDL2) + message(WARNING "SDL2 backend is not supported on iOS") + set(USE_SDL2 FALSE) + endif() + set(DEVICE "IOS") +elseif(OSX) + add_definitions(-D_IRR_OSX_PLATFORM_) + set(DEVICE "OSX") +elseif(ANDROID) + add_definitions(-D_IRR_ANDROID_PLATFORM_ -D_IRR_COMPILE_ANDROID_ASSET_READER_) + if(USE_SDL2) + message(WARNING "SDL2 backend is not supported on Android") + set(USE_SDL2 FALSE) + endif() + set(DEVICE "Android") +elseif(EMSCRIPTEN) + add_definitions(-D_IRR_EMSCRIPTEN_PLATFORM_ -D_IRR_COMPILE_WITH_EGL_MANAGER_) + set(LINUX_PLATFORM TRUE) + set(DEVICE "SDL") +elseif(SOLARIS) + add_definitions(-D_IRR_SOLARIS_PLATFORM_ -D_IRR_POSIX_API_) + set(DEVICE "X11") +else() + add_definitions(-D_IRR_POSIX_API_) + set(LINUX_PLATFORM TRUE) + set(DEVICE "X11") +endif() + +if(USE_SDL2) + set(DEVICE "SDL") +endif() + +option(USE_X11 "Use X11" TRUE) +if(USE_X11) + add_definitions(-D_IRR_COMPILE_WITH_X11_) +endif() + +if(LINUX_PLATFORM) + add_definitions(-D_IRR_LINUX_PLATFORM_) +endif() + +if(LINUX_PLATFORM AND USE_X11) + add_definitions(-D_IRR_COMPILE_WITH_X11_) + + option(USE_XINPUT2 "Use XInput2" TRUE) + if(USE_XINPUT2) + add_definitions(-D_IRR_LINUX_X11_XINPUT2_) + endif() + + option(USE_XCURSOR "Use XCursor" FALSE) + if(USE_XCURSOR) + add_definitions(-D_IRR_LINUX_XCURSOR_) + endif() +else() + set(USE_XINPUT2 FALSE) + set(USE_XCURSOR FALSE) +endif() + +add_definitions("-D_IRR_COMPILE_WITH_${DEVICE}_DEVICE_") + +# Joystick + +if(NOT (BSD OR SOLARIS OR EMSCRIPTEN)) + add_definitions(-D_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) +endif() + +# OpenGL + +if(IOS OR ANDROID OR EMSCRIPTEN) + set(ENABLE_OPENGL FALSE) +else() + option(ENABLE_OPENGL "Enable OpenGL" TRUE) +endif() + +if(EMSCRIPTEN OR OSX) + set(ENABLE_GLES1 FALSE) +else() + if(ANDROID OR IOS) + set(DEFAULT_GLES1 TRUE) + endif() + option(ENABLE_GLES1 "Enable OpenGL ES" ${DEFAULT_GLES1}) +endif() + +if(OSX) + set(ENABLE_GLES2 FALSE) + set(ENABLE_WEBGL1 FALSE) +else() + if(ANDROID OR IOS OR EMSCRIPTEN) + set(DEFAULT_GLES2 TRUE) + endif() + if(EMSCRIPTEN) + set(DEFAULT_WEBGL1 TRUE) + endif() + option(ENABLE_GLES2 "Enable OpenGL ES 2+" ${DEFAULT_GLES2}) + option(ENABLE_WEBGL1 "Enable WebGL (requires GLES2)" ${DEFAULT_WEBGL1}) + if(ENABLE_WEBGL1) + set(ENABLE_GLES2 TRUE) + endif() +endif() + +if(ENABLE_OPENGL) + add_definitions(-D_IRR_COMPILE_WITH_OPENGL_) + if(DEVICE STREQUAL "WINDOWS") + add_definitions(-D_IRR_COMPILE_WITH_WGL_MANAGER_ -D_IRR_OPENGL_USE_EXTPOINTER_) + elseif(DEVICE STREQUAL "X11") + add_definitions(-D_IRR_COMPILE_WITH_GLX_MANAGER_ -D_IRR_OPENGL_USE_EXTPOINTER_) + elseif(DEVICE STREQUAL "OSX") + add_definitions(-D_IRR_COMPILE_WITH_NSOGL_MANAGER_) + elseif(DEVICE STREQUAL "SDL") + add_definitions(-D_IRR_OPENGL_USE_EXTPOINTER_) + endif() +endif() + +if(ENABLE_GLES1) + add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) + if(DEVICE MATCHES "^WINDOWS|X11|ANDROID$") + add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_ -D_IRR_OGLES1_USE_EXTPOINTER_) + elseif(DEVICE STREQUAL "IOS") + add_definitions(-D_IRR_COMPILE_WITH_EAGL_MANAGER_) + endif() +endif() + +if(ENABLE_GLES2) + add_definitions(-D_IRR_COMPILE_WITH_OGLES2_) + if(DEVICE MATCHES "^WINDOWS|X11|ANDROID$" OR EMSCRIPTEN) + add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_ -D_IRR_OGLES2_USE_EXTPOINTER_) + elseif(DEVICE STREQUAL "IOS") + add_definitions(-D_IRR_COMPILE_WITH_EAGL_MANAGER_) + endif() +endif() + +if(ENABLE_WEBGL1) + add_definitions(-D_IRR_COMPILE_WITH_WEBGL1_) +endif() + +# Misc + +include(TestBigEndian) +TEST_BIG_ENDIAN(BIG_ENDIAN) +if(BIG_ENDIAN) + add_definitions(-D__BIG_ENDIAN__) +endif() + +# Configuration report + +message(STATUS "Device: ${DEVICE}") +message(STATUS "OpenGL: ${ENABLE_OPENGL}") +message(STATUS "OpenGL ES: ${ENABLE_GLES1}") +message(STATUS "OpenGL ES 2: ${ENABLE_GLES2}") +message(STATUS "WebGL: ${ENABLE_WEBGL1}") + # Required libs find_package(ZLIB REQUIRED) find_package(JPEG REQUIRED) find_package(PNG REQUIRED) -# To configure the features available in this Irrlicht build please edit include/IrrCompileConfig.h. -include(CheckSymbolExists) -set(CMAKE_REQUIRED_INCLUDES ${PROJECT_SOURCE_DIR}/include) -unset(OGLES1_ENABLED CACHE) -unset(OGLES2_ENABLED CACHE) -unset(OGL_ENABLED CACHE) -unset(XINPUT2_ENABLED CACHE) -unset(SDL_ENABLED CACHE) -# tell cmake about the dependency -set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_REQUIRED_INCLUDES}/IrrCompileConfig.h) - -check_symbol_exists(_IRR_COMPILE_WITH_OGLES1_ "IrrCompileConfig.h" OGLES1_ENABLED) -if(OGLES1_ENABLED) +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() -check_symbol_exists(_IRR_COMPILE_WITH_OGLES2_ "IrrCompileConfig.h" OGLES2_ENABLED) -if(OGLES2_ENABLED) +if(ENABLE_GLES2) find_package(OpenGLES2 REQUIRED) endif() -check_symbol_exists(_IRR_COMPILE_WITH_OPENGL_ "IrrCompileConfig.h" OGL_ENABLED) -if(OGL_ENABLED) +if(ENABLE_OPENGL) set(OpenGL_GL_PREFERENCE "LEGACY") find_package(OpenGL REQUIRED) endif() -if(UNIX AND NOT ANDROID AND NOT APPLE) - check_symbol_exists(_IRR_LINUX_X11_XINPUT2_ "IrrCompileConfig.h" XINPUT2_ENABLED) -endif() -check_symbol_exists(_IRR_COMPILE_WITH_SDL_DEVICE_ "IrrCompileConfig.h" SDL_ENABLED) -if(SDL_ENABLED) +if(USE_SDL2) find_package(SDL2 CONFIG REQUIRED) message(STATUS "Found SDL2: ${SDL2_LIBRARIES}") endif() @@ -113,7 +263,7 @@ elseif(APPLE) else() # Unix probably find_package(X11 REQUIRED) - if(XINPUT2_ENABLED AND NOT X11_Xi_FOUND) + if(${USE_XINPUT2} AND NOT X11_Xi_FOUND) message(FATAL_ERROR "XInput not found") endif() endif() @@ -307,6 +457,12 @@ target_link_libraries(IrrlichtMt PRIVATE ${link_libs}) if(NOT BUILD_SHARED_LIBS) target_compile_definitions(IrrlichtMt INTERFACE _IRR_STATIC_LIB_) endif() +if(WIN32) + target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) +endif() +if(APPLE OR ANDROID OR EMSCRIPTEN) + target_compile_definitions(IrrlichtMt PUBLIC IRR_MOBILE_PATHS) +endif() set_target_properties(IrrlichtMt PROPERTIES VERSION ${PROJECT_VERSION} From 5a2b8078908dfe4e3b27a988577c2dd151eb6470 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 20 Feb 2023 00:16:55 +0300 Subject: [PATCH 03/42] Move import/export macros into CMake --- include/IrrCompileConfig.h | 34 +++++----------------------------- source/Irrlicht/CMakeLists.txt | 15 ++++++++++----- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 7d3c458..5a4f898 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -25,39 +25,15 @@ #define _IRR_MATERIAL_MAX_TEXTURES_ 4 -#ifdef _IRR_WINDOWS_API_ - -// To build Irrlicht as a static library, you must define _IRR_STATIC_LIB_ in both the -// Irrlicht build, *and* in the user application, before #including -#ifndef _IRR_STATIC_LIB_ -#ifdef IRRLICHT_EXPORTS -#define IRRLICHT_API __declspec(dllexport) -#else -#define IRRLICHT_API __declspec(dllimport) -#endif // IRRLICHT_EXPORT -#else -#define IRRLICHT_API -#endif // _IRR_STATIC_LIB_ - -// Declare the calling convention. -#if defined(_STDCALL_SUPPORTED) +#ifdef _WIN32 #define IRRCALLCONV __stdcall #else -#define IRRCALLCONV __cdecl -#endif // STDCALL_SUPPORTED - -#else // _IRR_WINDOWS_API_ - -// Force symbol export in shared libraries built with gcc. -#if defined(__GNUC__) && !defined(_IRR_STATIC_LIB_) && defined(IRRLICHT_EXPORTS) -#define IRRLICHT_API __attribute__ ((visibility("default"))) -#else -#define IRRLICHT_API +#define IRRCALLCONV #endif -#define IRRCALLCONV - -#endif // _IRR_WINDOWS_API_ +#ifndef IRRLICHT_API +#define IRRLICHT_API +#endif #define _IRR_COMPILE_WITH_GUI_ diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 76228d1..eeb1029 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -4,7 +4,13 @@ option(USE_SDL2 "Use the SDL2 backend" FALSE) # Compiler flags add_definitions(-DIRRLICHT_EXPORTS) -if(NOT BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS) + if(WIN32) + add_definitions("-DIRRLICHT_API=__declspec(dllexport)") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + add_definitions("-DIRRLICHT_API=__attribute__ ((visibility(\"default\")))") + endif() +else() add_definitions(-D_IRR_STATIC_LIB_) endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -453,13 +459,12 @@ target_include_directories(IrrlichtMt target_link_libraries(IrrlichtMt PRIVATE ${link_libs}) -# Propagate static library flag to lib users, only needed for Windows -if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(IrrlichtMt INTERFACE _IRR_STATIC_LIB_) -endif() if(WIN32) target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) endif() +if(WIN32 AND BUILD_SHARED_LIBS) + target_compile_definitions(IrrlichtMt INTERFACE IRRLICHT_API=__declspec(dllimport)) +endif() if(APPLE OR ANDROID OR EMSCRIPTEN) target_compile_definitions(IrrlichtMt PUBLIC IRR_MOBILE_PATHS) endif() From 67f852be576027e07c94f08ff65f8065244e59a0 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 20 Feb 2023 00:55:45 +0300 Subject: [PATCH 04/42] Drop obsolete configuration macros --- include/IrrCompileConfig.h | 21 +---- include/irrMath.h | 8 -- include/irrTypes.h | 2 - source/Irrlicht/BuiltInFont.h | 15 ---- source/Irrlicht/CAnimatedMeshSceneNode.cpp | 2 + source/Irrlicht/CB3DMeshFileLoader.cpp | 6 -- source/Irrlicht/CB3DMeshWriter.cpp | 5 -- source/Irrlicht/CBillboardSceneNode.cpp | 3 - source/Irrlicht/CBoneSceneNode.cpp | 5 -- source/Irrlicht/CFileSystem.cpp | 2 - source/Irrlicht/CGUIEnvironment.cpp | 5 +- source/Irrlicht/CImageLoaderBMP.cpp | 5 -- source/Irrlicht/CImageLoaderBMP.h | 10 --- source/Irrlicht/CImageLoaderJPG.cpp | 41 +++------ source/Irrlicht/CImageLoaderJPG.h | 16 +--- source/Irrlicht/CImageLoaderPNG.cpp | 23 +---- source/Irrlicht/CImageLoaderPNG.h | 4 - source/Irrlicht/CImageLoaderTGA.cpp | 5 -- source/Irrlicht/CImageLoaderTGA.h | 9 -- source/Irrlicht/CImageWriterJPG.cpp | 12 +-- source/Irrlicht/CImageWriterJPG.h | 4 - source/Irrlicht/CImageWriterPNG.cpp | 19 +---- source/Irrlicht/CImageWriterPNG.h | 4 - source/Irrlicht/CMakeLists.txt | 6 ++ source/Irrlicht/CNullDriver.cpp | 98 +--------------------- source/Irrlicht/COBJMeshFileLoader.cpp | 5 -- source/Irrlicht/CSceneManager.cpp | 63 -------------- source/Irrlicht/CSkinnedMesh.cpp | 5 -- source/Irrlicht/CXMeshFileLoader.cpp | 5 -- source/Irrlicht/CZipReader.cpp | 14 +--- source/Irrlicht/CZipReader.h | 4 - 31 files changed, 30 insertions(+), 396 deletions(-) diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 5a4f898..7536a84 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -23,7 +23,7 @@ //! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. #define _IRR_MATERIAL_MAX_TEXTURES_ 4 - +#define _IRR_COMPILE_WITH_GUI_ #ifdef _WIN32 #define IRRCALLCONV __stdcall @@ -36,25 +36,6 @@ #endif -#define _IRR_COMPILE_WITH_GUI_ -#define _IRR_COMPILE_WITH_LIBJPEG_ -#define _IRR_COMPILE_WITH_LIBPNG_ -#define _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ -#define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ -#define _IRR_COMPILE_WITH_B3D_LOADER_ -#define _IRR_COMPILE_WITH_X_LOADER_ -#define _IRR_COMPILE_WITH_OBJ_LOADER_ -#define _IRR_COMPILE_WITH_BMP_LOADER_ -#define _IRR_COMPILE_WITH_JPG_LOADER_ -#define _IRR_COMPILE_WITH_PNG_LOADER_ -#define _IRR_COMPILE_WITH_TGA_LOADER_ -#define _IRR_COMPILE_WITH_JPG_WRITER_ -#define _IRR_COMPILE_WITH_PNG_WRITER_ -#define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ -#define _IRR_COMPILE_WITH_ZLIB_ -#define __IRR_HAS_S64 - - #ifdef _DEBUG //! A few attributes are written in CSceneManager when _IRR_SCENEMANAGER_DEBUG is enabled // NOTE: Those attributes were used always until 1.8.0 and became a global define for 1.8.1 diff --git a/include/irrMath.h b/include/irrMath.h index 994f8cd..af00f44 100644 --- a/include/irrMath.h +++ b/include/irrMath.h @@ -21,9 +21,7 @@ namespace core const s32 ROUNDING_ERROR_S32 = 0; -#ifdef __IRR_HAS_S64 const s64 ROUNDING_ERROR_S64 = 0; -#endif const f32 ROUNDING_ERROR_f32 = 0.000001f; const f64 ROUNDING_ERROR_f64 = 0.00000001; @@ -186,7 +184,6 @@ namespace core return ROUNDING_ERROR_S32; } -#ifdef __IRR_HAS_S64 template <> inline s64 roundingError() { @@ -198,7 +195,6 @@ namespace core { return ROUNDING_ERROR_S64; } -#endif template inline T relativeErrorFactor() @@ -310,13 +306,11 @@ namespace core return a <= tolerance; } -#ifdef __IRR_HAS_S64 //! returns if a equals zero, taking rounding errors into account inline bool iszero(const s64 a, const s64 tolerance = 0) { return abs_(a) <= tolerance; } -#endif inline s32 s32_min(s32 a, s32 b) { @@ -406,13 +400,11 @@ namespace core return static_cast(squareroot(static_cast(f))); } -#ifdef __IRR_HAS_S64 // calculate: sqrt ( x ) REALINLINE s64 squareroot(const s64 f) { return static_cast(squareroot(static_cast(f))); } -#endif // calculate: 1 / sqrt ( x ) REALINLINE f64 reciprocal_squareroot(const f64 x) diff --git a/include/irrTypes.h b/include/irrTypes.h index e67b395..eda3a21 100644 --- a/include/irrTypes.h +++ b/include/irrTypes.h @@ -38,13 +38,11 @@ typedef uint32_t u32; typedef int32_t s32; -#ifdef __IRR_HAS_S64 //! 64 bit unsigned variable. typedef uint64_t u64; //! 64 bit signed variable. typedef int64_t s64; -#endif // __IRR_HAS_S64 diff --git a/source/Irrlicht/BuiltInFont.h b/source/Irrlicht/BuiltInFont.h index 467a49d..be3a7f9 100644 --- a/source/Irrlicht/BuiltInFont.h +++ b/source/Irrlicht/BuiltInFont.h @@ -6,7 +6,6 @@ #define __BUILD_IN_FONT_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ // header file generated by Bin2H, copyright 2002 by N.Gebhardt. // Bin2H is Freeware. Download it freely from www.code3d.com. @@ -16,7 +15,6 @@ namespace irr { namespace gui { -#ifdef _IRR_COMPILE_WITH_BMP_LOADER_ const u8 BuiltInFontData[] = { 0x42, 0x4d, 0x4a, 0x20, 0x00, 0x00, 0x00, 0x00, @@ -1056,20 +1054,7 @@ const u8 BuiltInFontData[] = }; const u32 BuiltInFontDataSize = sizeof(BuiltInFontData); - -#else // !defined(_IRR_COMPILE_WITH_BMP_LOADER_) - - // built-in font cannot be loaded if there is no BMP loader - - const u8 * const BuiltInFontData=0; - - const u32 BuiltInFontDataSize = 0; - -#endif } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif - diff --git a/source/Irrlicht/CAnimatedMeshSceneNode.cpp b/source/Irrlicht/CAnimatedMeshSceneNode.cpp index 9d92e03..cea8ef2 100644 --- a/source/Irrlicht/CAnimatedMeshSceneNode.cpp +++ b/source/Irrlicht/CAnimatedMeshSceneNode.cpp @@ -7,7 +7,9 @@ #include "ISceneManager.h" #include "S3DVertex.h" #include "os.h" +#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ #include "CSkinnedMesh.h" +#endif #include "IDummyTransformationSceneNode.h" #include "IBoneSceneNode.h" #include "IMaterialRenderer.h" diff --git a/source/Irrlicht/CB3DMeshFileLoader.cpp b/source/Irrlicht/CB3DMeshFileLoader.cpp index ca86a6a..83ec373 100644 --- a/source/Irrlicht/CB3DMeshFileLoader.cpp +++ b/source/Irrlicht/CB3DMeshFileLoader.cpp @@ -7,8 +7,6 @@ // declared public domain #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_B3D_LOADER_ - #include "CB3DMeshFileLoader.h" #include "IVideoDriver.h" @@ -1055,7 +1053,3 @@ void CB3DMeshFileLoader::readFloats(f32* vec, u32 count) } // end namespace scene } // end namespace irr - - -#endif // _IRR_COMPILE_WITH_B3D_LOADER_ - diff --git a/source/Irrlicht/CB3DMeshWriter.cpp b/source/Irrlicht/CB3DMeshWriter.cpp index aaca168..0b588fc 100644 --- a/source/Irrlicht/CB3DMeshWriter.cpp +++ b/source/Irrlicht/CB3DMeshWriter.cpp @@ -6,8 +6,6 @@ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_B3D_WRITER_ - #include "CB3DMeshWriter.h" #include "os.h" #include "ISkinnedMesh.h" @@ -531,6 +529,3 @@ void CB3DMeshWriter::writeSizeFrom(io::IWriteFile* file, const u32 from, const u } // end namespace } // end namespace - -#endif // _IRR_COMPILE_WITH_B3D_WRITER_ - diff --git a/source/Irrlicht/CBillboardSceneNode.cpp b/source/Irrlicht/CBillboardSceneNode.cpp index a1464eb..c297978 100644 --- a/source/Irrlicht/CBillboardSceneNode.cpp +++ b/source/Irrlicht/CBillboardSceneNode.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ #include "CBillboardSceneNode.h" #include "IVideoDriver.h" #include "ISceneManager.h" @@ -281,5 +280,3 @@ ISceneNode* CBillboardSceneNode::clone(ISceneNode* newParent, ISceneManager* new } // end namespace scene } // end namespace irr - -#endif // _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ diff --git a/source/Irrlicht/CBoneSceneNode.cpp b/source/Irrlicht/CBoneSceneNode.cpp index 04ef8c7..4f05b84 100644 --- a/source/Irrlicht/CBoneSceneNode.cpp +++ b/source/Irrlicht/CBoneSceneNode.cpp @@ -3,8 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ - #include "CBoneSceneNode.h" namespace irr @@ -98,6 +96,3 @@ void CBoneSceneNode::updateAbsolutePositionOfAllChildren() } // namespace scene } // namespace irr - -#endif - diff --git a/source/Irrlicht/CFileSystem.cpp b/source/Irrlicht/CFileSystem.cpp index 45e8680..17ae7b3 100644 --- a/source/Irrlicht/CFileSystem.cpp +++ b/source/Irrlicht/CFileSystem.cpp @@ -54,9 +54,7 @@ CFileSystem::CFileSystem() //! reset current working directory getWorkingDirectory(); -#ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ ArchiveLoader.push_back(new CArchiveLoaderZIP(this)); -#endif } diff --git a/source/Irrlicht/CGUIEnvironment.cpp b/source/Irrlicht/CGUIEnvironment.cpp index 6d15706..8ad956d 100644 --- a/source/Irrlicht/CGUIEnvironment.cpp +++ b/source/Irrlicht/CGUIEnvironment.cpp @@ -25,8 +25,9 @@ #include "CGUIComboBox.h" #include "IWriteFile.h" - +#ifdef IRR_ENABLE_BUILTIN_FONT #include "BuiltInFont.h" +#endif #include "os.h" namespace irr @@ -143,6 +144,7 @@ CGUIEnvironment::~CGUIEnvironment() void CGUIEnvironment::loadBuiltInFont() { +#ifdef IRR_ENABLE_BUILTIN_FONT io::IReadFile* file = FileSystem->createMemoryReadFile(BuiltInFontData, BuiltInFontDataSize, DefaultFontName, false); @@ -161,6 +163,7 @@ void CGUIEnvironment::loadBuiltInFont() Fonts.push_back(f); file->drop(); +#endif } diff --git a/source/Irrlicht/CImageLoaderBMP.cpp b/source/Irrlicht/CImageLoaderBMP.cpp index 234c515..a913101 100644 --- a/source/Irrlicht/CImageLoaderBMP.cpp +++ b/source/Irrlicht/CImageLoaderBMP.cpp @@ -4,8 +4,6 @@ #include "CImageLoaderBMP.h" -#ifdef _IRR_COMPILE_WITH_BMP_LOADER_ - #include "IReadFile.h" #include "SColor.h" #include "CColorConverter.h" @@ -371,6 +369,3 @@ IImageLoader* createImageLoaderBMP() } // end namespace video } // end namespace irr - -#endif - diff --git a/source/Irrlicht/CImageLoaderBMP.h b/source/Irrlicht/CImageLoaderBMP.h index 5d993ce..6217f1b 100644 --- a/source/Irrlicht/CImageLoaderBMP.h +++ b/source/Irrlicht/CImageLoaderBMP.h @@ -15,9 +15,6 @@ namespace irr namespace video { -#if defined(_IRR_COMPILE_WITH_BMP_LOADER_) || defined(_IRR_COMPILE_WITH_BMP_WRITER_) - - // byte-align structures #include "irrpack.h" @@ -59,10 +56,6 @@ namespace video // Default alignment #include "irrunpack.h" -#endif // defined with loader or writer - -#ifdef _IRR_COMPILE_WITH_BMP_LOADER_ - /*! Surface Loader for Windows bitmaps */ @@ -91,10 +84,7 @@ private: }; -#endif // compiled with loader - } // end namespace video } // end namespace irr #endif - diff --git a/source/Irrlicht/CImageLoaderJPG.cpp b/source/Irrlicht/CImageLoaderJPG.cpp index 0d19d71..c7b5df2 100644 --- a/source/Irrlicht/CImageLoaderJPG.cpp +++ b/source/Irrlicht/CImageLoaderJPG.cpp @@ -4,8 +4,6 @@ #include "CImageLoaderJPG.h" -#ifdef _IRR_COMPILE_WITH_JPG_LOADER_ - #include "IReadFile.h" #include "CImage.h" #include "os.h" @@ -40,21 +38,18 @@ bool CImageLoaderJPG::isALoadableFileExtension(const io::path& filename) const return core::hasFileExtension ( filename, "jpg", "jpeg" ); } +// struct for handling jpeg errors +struct irr_jpeg_error_mgr +{ + // public jpeg error fields + struct jpeg_error_mgr pub; -#ifdef _IRR_COMPILE_WITH_LIBJPEG_ + // for longjmp, to return to caller on a fatal error + jmp_buf setjmp_buffer; - // struct for handling jpeg errors - struct irr_jpeg_error_mgr - { - // public jpeg error fields - struct jpeg_error_mgr pub; - - // for longjmp, to return to caller on a fatal error - jmp_buf setjmp_buffer; - - // for having access to the filename when printing the error messages - core::stringc* filename; - }; + // for having access to the filename when printing the error messages + core::stringc* filename; +}; void CImageLoaderJPG::init_source (j_decompress_ptr cinfo) { @@ -116,31 +111,20 @@ void CImageLoaderJPG::output_message(j_common_ptr cinfo) errMsg += *myerr->filename; os::Printer::log(errMsg.c_str(),temp1, ELL_ERROR); } -#endif // _IRR_COMPILE_WITH_LIBJPEG_ //! returns true if the file maybe is able to be loaded by this class bool CImageLoaderJPG::isALoadableFileFormat(io::IReadFile* file) const { - #ifndef _IRR_COMPILE_WITH_LIBJPEG_ - return false; - #else - if (!(file && file->seek(0))) return false; unsigned char header[3]; size_t headerLen = file->read(header, sizeof(header)); return headerLen >= 3 && !memcmp(header, "\xFF\xD8\xFF", 3); - #endif } //! creates a surface from the file IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const { - #ifndef _IRR_COMPILE_WITH_LIBJPEG_ - os::Printer::log("Can't load as not compiled with _IRR_COMPILE_WITH_LIBJPEG_:", file->getFileName(), ELL_DEBUG); - return 0; - #else - if (!file) return 0; @@ -288,8 +272,6 @@ IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const delete [] input; return image; - - #endif } @@ -302,6 +284,3 @@ IImageLoader* createImageLoaderJPG() } // end namespace video } // end namespace irr - -#endif - diff --git a/source/Irrlicht/CImageLoaderJPG.h b/source/Irrlicht/CImageLoaderJPG.h index 146adbe..7e727a3 100644 --- a/source/Irrlicht/CImageLoaderJPG.h +++ b/source/Irrlicht/CImageLoaderJPG.h @@ -7,17 +7,11 @@ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_JPG_LOADER_ - #include "IImageLoader.h" #include // required for jpeglib.h -#ifdef _IRR_COMPILE_WITH_LIBJPEG_ -extern "C" { - #include // use system lib - #include -} -#endif // _IRR_COMPILE_WITH_LIBJPEG_ +#include // use system lib +#include namespace irr @@ -48,8 +42,6 @@ public: IImage* loadImage(io::IReadFile* file) const override; private: - -#ifdef _IRR_COMPILE_WITH_LIBJPEG_ // several methods used via function pointers by jpeglib /* Receives control for a fatal error. Information sufficient to @@ -95,8 +87,6 @@ private: /* Terminate source --- called by jpeg_finish_decompress() after all data has been read. Often a no-op. */ static void term_source (j_decompress_ptr cinfo); - - #endif // _IRR_COMPILE_WITH_LIBJPEG_ }; @@ -105,5 +95,3 @@ private: #endif -#endif - diff --git a/source/Irrlicht/CImageLoaderPNG.cpp b/source/Irrlicht/CImageLoaderPNG.cpp index b468017..59709bf 100644 --- a/source/Irrlicht/CImageLoaderPNG.cpp +++ b/source/Irrlicht/CImageLoaderPNG.cpp @@ -4,11 +4,7 @@ #include "CImageLoaderPNG.h" -#ifdef _IRR_COMPILE_WITH_PNG_LOADER_ - -#ifdef _IRR_COMPILE_WITH_LIBPNG_ - #include // use system lib png -#endif // _IRR_COMPILE_WITH_LIBPNG_ +#include // use system lib png #include "CImage.h" #include "CReadFile.h" @@ -19,7 +15,6 @@ namespace irr namespace video { -#ifdef _IRR_COMPILE_WITH_LIBPNG_ // PNG function for error handling static void png_cpexcept_error(png_structp png_ptr, png_const_charp msg) { @@ -46,25 +41,19 @@ void PNGAPI user_read_data_fcn(png_structp png_ptr, png_bytep data, png_size_t l if (check != length) png_error(png_ptr, "Read Error"); } -#endif // _IRR_COMPILE_WITH_LIBPNG_ //! returns true if the file maybe is able to be loaded by this class //! based on the file extension (e.g. ".tga") bool CImageLoaderPng::isALoadableFileExtension(const io::path& filename) const { -#ifdef _IRR_COMPILE_WITH_LIBPNG_ return core::hasFileExtension ( filename, "png" ); -#else - return false; -#endif // _IRR_COMPILE_WITH_LIBPNG_ } //! returns true if the file maybe is able to be loaded by this class bool CImageLoaderPng::isALoadableFileFormat(io::IReadFile* file) const { -#ifdef _IRR_COMPILE_WITH_LIBPNG_ if (!file) return false; @@ -75,16 +64,12 @@ bool CImageLoaderPng::isALoadableFileFormat(io::IReadFile* file) const // Check if it really is a PNG file return !png_sig_cmp(buffer, 0, 8); -#else - return false; -#endif // _IRR_COMPILE_WITH_LIBPNG_ } // load in the image data IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const { -#ifdef _IRR_COMPILE_WITH_LIBPNG_ if (!file) return 0; @@ -267,9 +252,6 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const png_destroy_read_struct(&png_ptr,&info_ptr, 0); // Clean up memory return image; -#else - return 0; -#endif // _IRR_COMPILE_WITH_LIBPNG_ } @@ -281,6 +263,3 @@ IImageLoader* createImageLoaderPNG() }// end namespace irr }//end namespace video - -#endif - diff --git a/source/Irrlicht/CImageLoaderPNG.h b/source/Irrlicht/CImageLoaderPNG.h index 6e631b7..ed135db 100644 --- a/source/Irrlicht/CImageLoaderPNG.h +++ b/source/Irrlicht/CImageLoaderPNG.h @@ -11,8 +11,6 @@ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_PNG_LOADER_ - #include "IImageLoader.h" namespace irr @@ -41,5 +39,3 @@ public: } // end namespace irr #endif -#endif - diff --git a/source/Irrlicht/CImageLoaderTGA.cpp b/source/Irrlicht/CImageLoaderTGA.cpp index af4fad5..3286bdd 100644 --- a/source/Irrlicht/CImageLoaderTGA.cpp +++ b/source/Irrlicht/CImageLoaderTGA.cpp @@ -4,8 +4,6 @@ #include "CImageLoaderTGA.h" -#ifdef _IRR_COMPILE_WITH_TGA_LOADER_ - #include "IReadFile.h" #include "os.h" #include "CColorConverter.h" @@ -238,6 +236,3 @@ IImageLoader* createImageLoaderTGA() } // end namespace video } // end namespace irr - -#endif - diff --git a/source/Irrlicht/CImageLoaderTGA.h b/source/Irrlicht/CImageLoaderTGA.h index d8f7368..f31c682 100644 --- a/source/Irrlicht/CImageLoaderTGA.h +++ b/source/Irrlicht/CImageLoaderTGA.h @@ -15,8 +15,6 @@ namespace irr namespace video { -#if defined(_IRR_COMPILE_WITH_TGA_LOADER_) || defined(_IRR_COMPILE_WITH_TGA_WRITER_) - // byte-align structures #include "irrpack.h" @@ -46,10 +44,6 @@ namespace video // Default alignment #include "irrunpack.h" -#endif // compiled with loader or reader - -#ifdef _IRR_COMPILE_WITH_TGA_LOADER_ - /*! Surface Loader for targa images */ @@ -73,10 +67,7 @@ private: u8* loadCompressedImage(io::IReadFile *file, const STGAHeader& header) const; }; -#endif // compiled with loader - } // end namespace video } // end namespace irr #endif - diff --git a/source/Irrlicht/CImageWriterJPG.cpp b/source/Irrlicht/CImageWriterJPG.cpp index 97a64b8..1fb9fb3 100644 --- a/source/Irrlicht/CImageWriterJPG.cpp +++ b/source/Irrlicht/CImageWriterJPG.cpp @@ -4,15 +4,12 @@ #include "CImageWriterJPG.h" -#ifdef _IRR_COMPILE_WITH_JPG_WRITER_ - #include "CColorConverter.h" #include "IWriteFile.h" #include "CImage.h" #include "irrString.h" #include "os.h" -#ifdef _IRR_COMPILE_WITH_LIBJPEG_ #include // required for jpeglib.h extern "C" { @@ -181,7 +178,7 @@ static bool writeJPEGFile(io::IWriteFile* file, IImage* image, u32 quality) } // namespace video } // namespace irr -#endif // _IRR_COMPILE_WITH_LIBJPEG_ + namespace irr { @@ -209,15 +206,8 @@ bool CImageWriterJPG::isAWriteableFileExtension(const io::path& filename) const bool CImageWriterJPG::writeImage(io::IWriteFile *file, IImage *image, u32 quality) const { -#ifndef _IRR_COMPILE_WITH_LIBJPEG_ - return false; -#else return writeJPEGFile(file, image, quality); -#endif } } // namespace video } // namespace irr - -#endif - diff --git a/source/Irrlicht/CImageWriterJPG.h b/source/Irrlicht/CImageWriterJPG.h index ec8a1b8..facf67d 100644 --- a/source/Irrlicht/CImageWriterJPG.h +++ b/source/Irrlicht/CImageWriterJPG.h @@ -7,8 +7,6 @@ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_JPG_WRITER_ - #include "IImageWriter.h" namespace irr @@ -33,5 +31,3 @@ public: } #endif // _C_IMAGE_WRITER_JPG_H_INCLUDED__ -#endif - diff --git a/source/Irrlicht/CImageWriterPNG.cpp b/source/Irrlicht/CImageWriterPNG.cpp index 55ae00e..0e2a71e 100644 --- a/source/Irrlicht/CImageWriterPNG.cpp +++ b/source/Irrlicht/CImageWriterPNG.cpp @@ -4,17 +4,13 @@ #include "CImageWriterPNG.h" -#ifdef _IRR_COMPILE_WITH_PNG_WRITER_ - #include "CImageLoaderPNG.h" #include "CColorConverter.h" #include "IWriteFile.h" #include "irrString.h" #include "os.h" // for logging -#ifdef _IRR_COMPILE_WITH_LIBPNG_ - #include // use system lib png -#endif // _IRR_COMPILE_WITH_LIBPNG_ +#include // use system lib png namespace irr { @@ -26,7 +22,6 @@ IImageWriter* createImageWriterPNG() return new CImageWriterPNG; } -#ifdef _IRR_COMPILE_WITH_LIBPNG_ // PNG function for error handling static void png_cpexcept_error(png_structp png_ptr, png_const_charp msg) { @@ -51,7 +46,6 @@ void PNGAPI user_write_data_fcn(png_structp png_ptr, png_bytep data, png_size_t if (check != length) png_error(png_ptr, "Write Error"); } -#endif // _IRR_COMPILE_WITH_LIBPNG_ CImageWriterPNG::CImageWriterPNG() { @@ -62,16 +56,11 @@ CImageWriterPNG::CImageWriterPNG() bool CImageWriterPNG::isAWriteableFileExtension(const io::path& filename) const { -#ifdef _IRR_COMPILE_WITH_LIBPNG_ return core::hasFileExtension ( filename, "png" ); -#else - return false; -#endif } bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) const { -#ifdef _IRR_COMPILE_WITH_LIBPNG_ if (!file || !image) return false; @@ -206,13 +195,7 @@ bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) delete [] tmpImage; png_destroy_write_struct(&png_ptr, &info_ptr); return true; -#else - return false; -#endif } } // namespace video } // namespace irr - -#endif - diff --git a/source/Irrlicht/CImageWriterPNG.h b/source/Irrlicht/CImageWriterPNG.h index eec12ff..4d6619f 100644 --- a/source/Irrlicht/CImageWriterPNG.h +++ b/source/Irrlicht/CImageWriterPNG.h @@ -7,8 +7,6 @@ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_PNG_WRITER_ - #include "IImageWriter.h" namespace irr @@ -33,5 +31,3 @@ public: } // namespace irr #endif // _C_IMAGE_WRITER_PNG_H_INCLUDED__ -#endif - diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index eeb1029..7b51145 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -63,6 +63,12 @@ if(NOT REVISION_SANITY_CHECK) message(FATAL_ERROR "IrrlichtMt revision number mismatches between CMake and headers.") endif() +# Platform-independent configuration (hard-coded currently) +add_definitions( + -DIRR_ENABLE_BUILTIN_FONT + -D_IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ + ) + # Platform-specific configuration if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 775a22c..5834e01 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -32,57 +32,15 @@ IImageLoader* createImageLoaderJPG(); //! creates a loader which is able to load targa images IImageLoader* createImageLoaderTGA(); -//! creates a loader which is able to load psd images -IImageLoader* createImageLoaderPSD(); - -//! creates a loader which is able to load psd images -IImageLoader* createImageLoaderPVR(); - -//! creates a loader which is able to load dds images -IImageLoader* createImageLoaderDDS(); - -//! creates a loader which is able to load pcx images -IImageLoader* createImageLoaderPCX(); - //! creates a loader which is able to load png images IImageLoader* createImageLoaderPNG(); -//! creates a loader which is able to load WAL images -IImageLoader* createImageLoaderWAL(); - -//! creates a loader which is able to load halflife images -IImageLoader* createImageLoaderHalfLife(); - -//! creates a loader which is able to load lmp images -IImageLoader* createImageLoaderLMP(); - -//! creates a loader which is able to load ppm/pgm/pbm images -IImageLoader* createImageLoaderPPM(); - -//! creates a loader which is able to load rgb images -IImageLoader* createImageLoaderRGB(); - - -//! creates a writer which is able to save bmp images -IImageWriter* createImageWriterBMP(); - //! creates a writer which is able to save jpg images IImageWriter* createImageWriterJPG(); -//! creates a writer which is able to save tga images -IImageWriter* createImageWriterTGA(); - -//! creates a writer which is able to save psd images -IImageWriter* createImageWriterPSD(); - -//! creates a writer which is able to save pcx images -IImageWriter* createImageWriterPCX(); - //! creates a writer which is able to save png images IImageWriter* createImageWriterPNG(); -//! creates a writer which is able to save ppm images -IImageWriter* createImageWriterPPM(); //! constructor CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d& screenSize) @@ -124,68 +82,14 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d& scre if (FileSystem) FileSystem->grab(); - // create surface loader - -#ifdef _IRR_COMPILE_WITH_WAL_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderHalfLife()); - SurfaceLoader.push_back(video::createImageLoaderWAL()); -#endif -#ifdef _IRR_COMPILE_WITH_LMP_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderLMP()); -#endif -#ifdef _IRR_COMPILE_WITH_PPM_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderPPM()); -#endif -#ifdef _IRR_COMPILE_WITH_RGB_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderRGB()); -#endif -#ifdef _IRR_COMPILE_WITH_PSD_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderPSD()); -#endif -#ifdef _IRR_COMPILE_WITH_PVR_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderPVR()); -#endif -#if defined(_IRR_COMPILE_WITH_DDS_LOADER_) || defined(_IRR_COMPILE_WITH_DDS_DECODER_LOADER_) - SurfaceLoader.push_back(video::createImageLoaderDDS()); -#endif -#ifdef _IRR_COMPILE_WITH_PCX_LOADER_ - SurfaceLoader.push_back(video::createImageLoaderPCX()); -#endif -#ifdef _IRR_COMPILE_WITH_TGA_LOADER_ + // create surface loaders and writers SurfaceLoader.push_back(video::createImageLoaderTGA()); -#endif -#ifdef _IRR_COMPILE_WITH_PNG_LOADER_ SurfaceLoader.push_back(video::createImageLoaderPNG()); -#endif -#ifdef _IRR_COMPILE_WITH_JPG_LOADER_ SurfaceLoader.push_back(video::createImageLoaderJPG()); -#endif -#ifdef _IRR_COMPILE_WITH_BMP_LOADER_ SurfaceLoader.push_back(video::createImageLoaderBMP()); -#endif - -#ifdef _IRR_COMPILE_WITH_PPM_WRITER_ - SurfaceWriter.push_back(video::createImageWriterPPM()); -#endif -#ifdef _IRR_COMPILE_WITH_PCX_WRITER_ - SurfaceWriter.push_back(video::createImageWriterPCX()); -#endif -#ifdef _IRR_COMPILE_WITH_PSD_WRITER_ - SurfaceWriter.push_back(video::createImageWriterPSD()); -#endif -#ifdef _IRR_COMPILE_WITH_TGA_WRITER_ - SurfaceWriter.push_back(video::createImageWriterTGA()); -#endif -#ifdef _IRR_COMPILE_WITH_JPG_WRITER_ SurfaceWriter.push_back(video::createImageWriterJPG()); -#endif -#ifdef _IRR_COMPILE_WITH_PNG_WRITER_ SurfaceWriter.push_back(video::createImageWriterPNG()); -#endif -#ifdef _IRR_COMPILE_WITH_BMP_WRITER_ - SurfaceWriter.push_back(video::createImageWriterBMP()); -#endif // set ExposedData to 0 diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index c4fee23..11fa484 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -3,8 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_OBJ_LOADER_ - #include "COBJMeshFileLoader.h" #include "IMeshManipulator.h" #include "IVideoDriver.h" @@ -612,6 +610,3 @@ void COBJMeshFileLoader::cleanUp() } // end namespace scene } // end namespace irr - -#endif // _IRR_COMPILE_WITH_OBJ_LOADER_ - diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index 664e672..b664c77 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -15,27 +15,11 @@ #include "os.h" -// We need this include for the case of skinned mesh support without -// any such loader -#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ #include "CSkinnedMesh.h" -#endif - -#ifdef _IRR_COMPILE_WITH_X_LOADER_ #include "CXMeshFileLoader.h" -#endif - -#ifdef _IRR_COMPILE_WITH_OBJ_LOADER_ #include "COBJMeshFileLoader.h" -#endif - -#ifdef _IRR_COMPILE_WITH_B3D_LOADER_ #include "CB3DMeshFileLoader.h" -#endif - -#ifdef _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ #include "CBillboardSceneNode.h" -#endif // _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ #include "CAnimatedMeshSceneNode.h" #include "CCameraSceneNode.h" #include "CMeshSceneNode.h" @@ -96,15 +80,9 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, // TODO: now that we have multiple scene managers, these should be // shallow copies from the previous manager if there is one. - #ifdef _IRR_COMPILE_WITH_X_LOADER_ MeshLoaderList.push_back(new CXMeshFileLoader(this, FileSystem)); - #endif - #ifdef _IRR_COMPILE_WITH_OBJ_LOADER_ MeshLoaderList.push_back(new COBJMeshFileLoader(this, FileSystem)); - #endif - #ifdef _IRR_COMPILE_WITH_B3D_LOADER_ MeshLoaderList.push_back(new CB3DMeshFileLoader(this)); - #endif } @@ -316,7 +294,6 @@ IBillboardSceneNode* CSceneManager::addBillboardSceneNode(ISceneNode* parent, video::SColor colorTop, video::SColor colorBottom ) { -#ifdef _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ if (!parent) parent = this; @@ -325,9 +302,6 @@ IBillboardSceneNode* CSceneManager::addBillboardSceneNode(ISceneNode* parent, node->drop(); return node; -#else - return 0; -#endif } @@ -971,49 +945,12 @@ const video::SColorf& CSceneManager::getAmbientLight() const //! Get a skinned mesh, which is not available as header-only code ISkinnedMesh* CSceneManager::createSkinnedMesh() { -#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ return new CSkinnedMesh(); -#else - return 0; -#endif } //! Returns a mesh writer implementation if available IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type) { - switch(type) - { - case EMWT_IRR_MESH: - case EMWT_COLLADA: - return 0; - case EMWT_STL: -#ifdef _IRR_COMPILE_WITH_STL_WRITER_ - return new CSTLMeshWriter(this); -#else - return 0; -#endif - case EMWT_OBJ: -#ifdef _IRR_COMPILE_WITH_OBJ_WRITER_ - return new COBJMeshWriter(this, FileSystem); -#else - return 0; -#endif - - case EMWT_PLY: -#ifdef _IRR_COMPILE_WITH_PLY_WRITER_ - return new CPLYMeshWriter(); -#else - return 0; -#endif - - case EMWT_B3D: -#ifdef _IRR_COMPILE_WITH_B3D_WRITER_ - return new CB3DMeshWriter(); -#else - return 0; -#endif - } - return 0; } diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index 9f47f3b..5e01e06 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -3,8 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ - #include "CSkinnedMesh.h" #include "CBoneSceneNode.h" #include "IAnimatedMeshSceneNode.h" @@ -1539,6 +1537,3 @@ void CSkinnedMesh::calculateTangents( } // end namespace scene } // end namespace irr - -#endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ - diff --git a/source/Irrlicht/CXMeshFileLoader.cpp b/source/Irrlicht/CXMeshFileLoader.cpp index 2de099f..dfeefd3 100644 --- a/source/Irrlicht/CXMeshFileLoader.cpp +++ b/source/Irrlicht/CXMeshFileLoader.cpp @@ -4,8 +4,6 @@ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_X_LOADER_ - #include "CXMeshFileLoader.h" #include "os.h" @@ -2359,6 +2357,3 @@ bool CXMeshFileLoader::readMatrix(core::matrix4& mat) } // end namespace scene } // end namespace irr - -#endif // _IRR_COMPILE_WITH_X_LOADER_ - diff --git a/source/Irrlicht/CZipReader.cpp b/source/Irrlicht/CZipReader.cpp index d394313..500db90 100644 --- a/source/Irrlicht/CZipReader.cpp +++ b/source/Irrlicht/CZipReader.cpp @@ -7,16 +7,12 @@ #include "os.h" -#ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ - #include "CFileList.h" #include "CReadFile.h" #include "coreutil.h" #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_ZLIB_ - #include // use system lib -#endif +#include // use system lib namespace irr { @@ -464,8 +460,6 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) } case 8: { - #ifdef _IRR_COMPILE_WITH_ZLIB_ - const u32 uncompressedSize = e.header.DataDescriptor.UncompressedSize; c8* pBuf = new c8[ uncompressedSize ]; if (!pBuf) @@ -531,10 +525,6 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) } else return FileSystem->createMemoryReadFile(pBuf, uncompressedSize, Files[index].FullName, true); - - #else - return 0; // zlib not compiled, we cannot decompress the data. - #endif } case 12: { @@ -560,5 +550,3 @@ IReadFile* CZipReader::createAndOpenFile(u32 index) } // end namespace io } // end namespace irr - -#endif // __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ diff --git a/source/Irrlicht/CZipReader.h b/source/Irrlicht/CZipReader.h index 458b6db..02de98f 100644 --- a/source/Irrlicht/CZipReader.h +++ b/source/Irrlicht/CZipReader.h @@ -7,8 +7,6 @@ #include "IrrCompileConfig.h" -#ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ - #include "IReadFile.h" #include "irrArray.h" #include "irrString.h" @@ -226,6 +224,4 @@ namespace io } // end namespace io } // end namespace irr -#endif // __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ #endif // __C_ZIP_READER_H_INCLUDED__ - From d8e09f14bd4a279ded0845196f677fabe7947079 Mon Sep 17 00:00:00 2001 From: numzero Date: Wed, 22 Feb 2023 20:01:44 +0300 Subject: [PATCH 05/42] Drop _IRR_COMPILE_WITH_GUI_ --- include/IrrCompileConfig.h | 1 - source/Irrlicht/CGUIButton.cpp | 4 ---- source/Irrlicht/CGUIButton.h | 5 ----- source/Irrlicht/CGUICheckBox.cpp | 5 ----- source/Irrlicht/CGUICheckBox.h | 4 ---- source/Irrlicht/CGUIComboBox.cpp | 5 ----- source/Irrlicht/CGUIComboBox.h | 5 ----- source/Irrlicht/CGUIEditBox.cpp | 4 ---- source/Irrlicht/CGUIEditBox.h | 4 ---- source/Irrlicht/CGUIEnvironment.cpp | 5 ----- source/Irrlicht/CGUIEnvironment.h | 6 ------ source/Irrlicht/CGUIFileOpenDialog.cpp | 3 --- source/Irrlicht/CGUIFileOpenDialog.h | 5 ----- source/Irrlicht/CGUIFont.cpp | 4 ---- source/Irrlicht/CGUIFont.h | 5 ----- source/Irrlicht/CGUIImage.cpp | 5 ----- source/Irrlicht/CGUIImage.h | 4 ---- source/Irrlicht/CGUIListBox.cpp | 4 ---- source/Irrlicht/CGUIListBox.h | 4 ---- source/Irrlicht/CGUIScrollBar.cpp | 4 ---- source/Irrlicht/CGUIScrollBar.h | 5 ----- source/Irrlicht/CGUISkin.cpp | 4 ---- source/Irrlicht/CGUISkin.h | 6 ------ source/Irrlicht/CGUISpriteBank.cpp | 3 --- source/Irrlicht/CGUISpriteBank.h | 5 ----- source/Irrlicht/CGUIStaticText.cpp | 4 ---- source/Irrlicht/CGUIStaticText.h | 5 ----- source/Irrlicht/CGUITabControl.cpp | 4 ---- source/Irrlicht/CGUITabControl.h | 5 ----- source/Irrlicht/CIrrDeviceStub.cpp | 2 -- 30 files changed, 129 deletions(-) diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 7536a84..0259399 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -23,7 +23,6 @@ //! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. #define _IRR_MATERIAL_MAX_TEXTURES_ 4 -#define _IRR_COMPILE_WITH_GUI_ #ifdef _WIN32 #define IRRCALLCONV __stdcall diff --git a/source/Irrlicht/CGUIButton.cpp b/source/Irrlicht/CGUIButton.cpp index 704fd3d..d6ab543 100644 --- a/source/Irrlicht/CGUIButton.cpp +++ b/source/Irrlicht/CGUIButton.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIButton.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUISkin.h" #include "IGUIEnvironment.h" @@ -558,6 +557,3 @@ bool CGUIButton::isDrawingBorder() const } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIButton.h b/source/Irrlicht/CGUIButton.h index 9bd8612..6c718b1 100644 --- a/source/Irrlicht/CGUIButton.h +++ b/source/Irrlicht/CGUIButton.h @@ -6,8 +6,6 @@ #define __C_GUI_BUTTON_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIButton.h" #include "IGUISpriteBank.h" #include "ITexture.h" @@ -244,7 +242,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_BUTTON_H_INCLUDED__ - diff --git a/source/Irrlicht/CGUICheckBox.cpp b/source/Irrlicht/CGUICheckBox.cpp index 48ec5e8..6c5271f 100644 --- a/source/Irrlicht/CGUICheckBox.cpp +++ b/source/Irrlicht/CGUICheckBox.cpp @@ -4,8 +4,6 @@ #include "CGUICheckBox.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUISkin.h" #include "IGUIEnvironment.h" #include "IVideoDriver.h" @@ -227,6 +225,3 @@ bool CGUICheckBox::isDrawBorderEnabled() const } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUICheckBox.h b/source/Irrlicht/CGUICheckBox.h index adb46b4..facbfb0 100644 --- a/source/Irrlicht/CGUICheckBox.h +++ b/source/Irrlicht/CGUICheckBox.h @@ -6,8 +6,6 @@ #define __C_GUI_CHECKBOX_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUICheckBox.h" namespace irr @@ -61,5 +59,3 @@ namespace gui } // end namespace irr #endif // __C_GUI_CHECKBOX_H_INCLUDED__ - -#endif // _IRR_COMPILE_WITH_GUI_ diff --git a/source/Irrlicht/CGUIComboBox.cpp b/source/Irrlicht/CGUIComboBox.cpp index b35b47a..ecd3a9c 100644 --- a/source/Irrlicht/CGUIComboBox.cpp +++ b/source/Irrlicht/CGUIComboBox.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIComboBox.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUIEnvironment.h" #include "IVideoDriver.h" @@ -488,7 +487,3 @@ void CGUIComboBox::openCloseMenu() } // end namespace gui } // end namespace irr - - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIComboBox.h b/source/Irrlicht/CGUIComboBox.h index dbdae41..13996f0 100644 --- a/source/Irrlicht/CGUIComboBox.h +++ b/source/Irrlicht/CGUIComboBox.h @@ -6,8 +6,6 @@ #define __C_GUI_COMBO_BOX_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIComboBox.h" #include "IGUIStaticText.h" #include "irrString.h" @@ -107,7 +105,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_COMBO_BOX_H_INCLUDED__ - diff --git a/source/Irrlicht/CGUIEditBox.cpp b/source/Irrlicht/CGUIEditBox.cpp index a3851e6..cf4b64e 100644 --- a/source/Irrlicht/CGUIEditBox.cpp +++ b/source/Irrlicht/CGUIEditBox.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIEditBox.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUISkin.h" #include "IGUIEnvironment.h" @@ -1652,6 +1651,3 @@ bool CGUIEditBox::acceptsIME() } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIEditBox.h b/source/Irrlicht/CGUIEditBox.h index b0b5070..0626fec 100644 --- a/source/Irrlicht/CGUIEditBox.h +++ b/source/Irrlicht/CGUIEditBox.h @@ -6,8 +6,6 @@ #define __C_GUI_EDIT_BOX_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIEditBox.h" #include "irrArray.h" #include "IOSOperator.h" @@ -201,6 +199,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ #endif // __C_GUI_EDIT_BOX_H_INCLUDED__ - diff --git a/source/Irrlicht/CGUIEnvironment.cpp b/source/Irrlicht/CGUIEnvironment.cpp index 8ad956d..a7b2804 100644 --- a/source/Irrlicht/CGUIEnvironment.cpp +++ b/source/Irrlicht/CGUIEnvironment.cpp @@ -5,8 +5,6 @@ #include "CGUIEnvironment.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IVideoDriver.h" #include "CGUISkin.h" @@ -1110,6 +1108,3 @@ IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs, } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIEnvironment.h b/source/Irrlicht/CGUIEnvironment.h index ab74586..2a6097c 100644 --- a/source/Irrlicht/CGUIEnvironment.h +++ b/source/Irrlicht/CGUIEnvironment.h @@ -6,8 +6,6 @@ #define __C_GUI_ENVIRONMENT_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIEnvironment.h" #include "IGUIElement.h" #include "irrArray.h" @@ -231,8 +229,4 @@ private: } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__ - - diff --git a/source/Irrlicht/CGUIFileOpenDialog.cpp b/source/Irrlicht/CGUIFileOpenDialog.cpp index 6599bef..e68d7cd 100644 --- a/source/Irrlicht/CGUIFileOpenDialog.cpp +++ b/source/Irrlicht/CGUIFileOpenDialog.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIFileOpenDialog.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUISkin.h" #include "IGUIEnvironment.h" @@ -411,5 +410,3 @@ void CGUIFileOpenDialog::sendCancelEvent() } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ diff --git a/source/Irrlicht/CGUIFileOpenDialog.h b/source/Irrlicht/CGUIFileOpenDialog.h index 55b9ffa..c51f604 100644 --- a/source/Irrlicht/CGUIFileOpenDialog.h +++ b/source/Irrlicht/CGUIFileOpenDialog.h @@ -6,8 +6,6 @@ #define __C_GUI_FILE_OPEN_DIALOG_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIFileOpenDialog.h" #include "IGUIButton.h" #include "IGUIListBox.h" @@ -90,7 +88,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_FILE_OPEN_DIALOG_H_INCLUDED__ - diff --git a/source/Irrlicht/CGUIFont.cpp b/source/Irrlicht/CGUIFont.cpp index 1becf67..b7b6ed7 100644 --- a/source/Irrlicht/CGUIFont.cpp +++ b/source/Irrlicht/CGUIFont.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIFont.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "os.h" #include "coreutil.h" @@ -594,6 +593,3 @@ IGUISpriteBank* CGUIFont::getSpriteBank() const } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIFont.h b/source/Irrlicht/CGUIFont.h index 4cf93b8..c7b9337 100644 --- a/source/Irrlicht/CGUIFont.h +++ b/source/Irrlicht/CGUIFont.h @@ -6,8 +6,6 @@ #define __C_GUI_FONT_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIFontBitmap.h" #include "irrString.h" #include "IReadFile.h" @@ -111,7 +109,4 @@ private: } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_FONT_H_INCLUDED__ - diff --git a/source/Irrlicht/CGUIImage.cpp b/source/Irrlicht/CGUIImage.cpp index 2d2a08c..669428b 100644 --- a/source/Irrlicht/CGUIImage.cpp +++ b/source/Irrlicht/CGUIImage.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIImage.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUISkin.h" #include "IGUIEnvironment.h" @@ -177,7 +176,3 @@ core::rect CGUIImage::getDrawBounds() const } // end namespace gui } // end namespace irr - - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIImage.h b/source/Irrlicht/CGUIImage.h index 581fe1b..37d0abc 100644 --- a/source/Irrlicht/CGUIImage.h +++ b/source/Irrlicht/CGUIImage.h @@ -6,8 +6,6 @@ #define __C_GUI_IMAGE_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIImage.h" namespace irr @@ -102,6 +100,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_IMAGE_H_INCLUDED__ diff --git a/source/Irrlicht/CGUIListBox.cpp b/source/Irrlicht/CGUIListBox.cpp index f6f0e77..b00c7e3 100644 --- a/source/Irrlicht/CGUIListBox.cpp +++ b/source/Irrlicht/CGUIListBox.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIListBox.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "CGUIListBox.h" #include "IGUISkin.h" @@ -841,6 +840,3 @@ IGUIScrollBar* CGUIListBox::getVerticalScrollBar() const } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIListBox.h b/source/Irrlicht/CGUIListBox.h index 8e1566d..a615ed4 100644 --- a/source/Irrlicht/CGUIListBox.h +++ b/source/Irrlicht/CGUIListBox.h @@ -6,8 +6,6 @@ #define __C_GUI_LIST_BOX_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIListBox.h" #include "irrArray.h" @@ -178,6 +176,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif diff --git a/source/Irrlicht/CGUIScrollBar.cpp b/source/Irrlicht/CGUIScrollBar.cpp index 6d6d367..567251c 100644 --- a/source/Irrlicht/CGUIScrollBar.cpp +++ b/source/Irrlicht/CGUIScrollBar.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIScrollBar.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUISkin.h" #include "IGUIEnvironment.h" @@ -534,6 +533,3 @@ void CGUIScrollBar::refreshControls() } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIScrollBar.h b/source/Irrlicht/CGUIScrollBar.h index 170a2da..1a6d683 100644 --- a/source/Irrlicht/CGUIScrollBar.h +++ b/source/Irrlicht/CGUIScrollBar.h @@ -6,8 +6,6 @@ #define __C_GUI_SCROLL_BAR_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIScrollBar.h" #include "IGUIButton.h" @@ -101,7 +99,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif - diff --git a/source/Irrlicht/CGUISkin.cpp b/source/Irrlicht/CGUISkin.cpp index 08a5900..b417b72 100644 --- a/source/Irrlicht/CGUISkin.cpp +++ b/source/Irrlicht/CGUISkin.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUISkin.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUIFont.h" #include "IGUISpriteBank.h" @@ -973,6 +972,3 @@ void CGUISkin::draw2DRectangle(IGUIElement* element, } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUISkin.h b/source/Irrlicht/CGUISkin.h index 11cfb26..436124b 100644 --- a/source/Irrlicht/CGUISkin.h +++ b/source/Irrlicht/CGUISkin.h @@ -6,8 +6,6 @@ #define __C_GUI_SKIN_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUISkin.h" #include "irrString.h" @@ -234,8 +232,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif - - diff --git a/source/Irrlicht/CGUISpriteBank.cpp b/source/Irrlicht/CGUISpriteBank.cpp index c89bb26..8f5fb67 100644 --- a/source/Irrlicht/CGUISpriteBank.cpp +++ b/source/Irrlicht/CGUISpriteBank.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUISpriteBank.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUIEnvironment.h" #include "IVideoDriver.h" @@ -249,5 +248,3 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array& indices, } // namespace gui } // namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ diff --git a/source/Irrlicht/CGUISpriteBank.h b/source/Irrlicht/CGUISpriteBank.h index cfca788..2a324a7 100644 --- a/source/Irrlicht/CGUISpriteBank.h +++ b/source/Irrlicht/CGUISpriteBank.h @@ -6,8 +6,6 @@ #define __C_GUI_SPRITE_BANK_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUISpriteBank.h" namespace irr @@ -99,7 +97,4 @@ protected: } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif // __C_GUI_SPRITE_BANK_H_INCLUDED__ - diff --git a/source/Irrlicht/CGUIStaticText.cpp b/source/Irrlicht/CGUIStaticText.cpp index b9ab35a..29bbdb7 100644 --- a/source/Irrlicht/CGUIStaticText.cpp +++ b/source/Irrlicht/CGUIStaticText.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUIStaticText.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "IGUISkin.h" #include "IGUIEnvironment.h" @@ -592,6 +591,3 @@ s32 CGUIStaticText::getTextWidth() const } // end namespace gui } // end namespace irr - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUIStaticText.h b/source/Irrlicht/CGUIStaticText.h index 827e95f..41045d0 100644 --- a/source/Irrlicht/CGUIStaticText.h +++ b/source/Irrlicht/CGUIStaticText.h @@ -6,8 +6,6 @@ #define __C_GUI_STATIC_TEXT_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIStaticText.h" #include "irrArray.h" @@ -136,7 +134,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif - diff --git a/source/Irrlicht/CGUITabControl.cpp b/source/Irrlicht/CGUITabControl.cpp index 30a31c3..c08a579 100644 --- a/source/Irrlicht/CGUITabControl.cpp +++ b/source/Irrlicht/CGUITabControl.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUITabControl.h" -#ifdef _IRR_COMPILE_WITH_GUI_ #include "CGUIButton.h" #include "IGUISkin.h" @@ -1030,6 +1029,3 @@ void CGUITabControl::updateAbsolutePosition() } // end namespace irr } // end namespace gui - -#endif // _IRR_COMPILE_WITH_GUI_ - diff --git a/source/Irrlicht/CGUITabControl.h b/source/Irrlicht/CGUITabControl.h index d5e8315..5bca2b6 100644 --- a/source/Irrlicht/CGUITabControl.h +++ b/source/Irrlicht/CGUITabControl.h @@ -6,8 +6,6 @@ #define __C_GUI_TAB_CONTROL_H_INCLUDED__ #include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUITabControl.h" #include "irrArray.h" #include "IGUISkin.h" @@ -184,7 +182,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif - diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index 877a4bf..16028c8 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -88,10 +88,8 @@ CIrrDeviceStub::~CIrrDeviceStub() void CIrrDeviceStub::createGUIAndScene() { - #ifdef _IRR_COMPILE_WITH_GUI_ // create gui environment GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator); - #endif // create Scene manager SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl, GUIEnvironment); From a0e1e39ea784aa8d17ba9092a950d5ad85a51189 Mon Sep 17 00:00:00 2001 From: numzero Date: Wed, 22 Feb 2023 20:13:55 +0300 Subject: [PATCH 06/42] Drop _IRR_SCENEMANAGER_DEBUG --- include/IrrCompileConfig.h | 15 -------------- source/Irrlicht/CSceneManager.cpp | 34 ++----------------------------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 0259399..d186a2c 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -34,19 +34,4 @@ #define IRRLICHT_API #endif - -#ifdef _DEBUG - //! A few attributes are written in CSceneManager when _IRR_SCENEMANAGER_DEBUG is enabled - // NOTE: Those attributes were used always until 1.8.0 and became a global define for 1.8.1 - // which is only enabled in debug because it had a large (sometimes >5%) impact on speed. - // A better solution in the long run is to break the interface and remove _all_ attribute - // access in functions like CSceneManager::drawAll and instead put that information in some - // own struct/class or in CSceneManager. - // See http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=48211 for the discussion. - #define _IRR_SCENEMANAGER_DEBUG - #ifdef NO_IRR_SCENEMANAGER_DEBUG - #undef _IRR_SCENEMANAGER_DEBUG - #endif -#endif - #endif // __IRR_COMPILE_CONFIG_H_INCLUDED__ diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index b664c77..fd837cc 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -549,17 +549,6 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE break; } -#ifdef _IRR_SCENEMANAGER_DEBUG - s32 index = Parameters->findAttribute("calls"); - Parameters->setAttribute(index, Parameters->getAttributeAsInt(index)+1); - - if (!taken) - { - index = Parameters->findAttribute("culled"); - Parameters->setAttribute(index, Parameters->getAttributeAsInt(index)+1); - } -#endif - return taken; } @@ -580,15 +569,6 @@ void CSceneManager::drawAll() if (!Driver) return; -#ifdef _IRR_SCENEMANAGER_DEBUG - // reset attributes - Parameters->setAttribute("culled", 0); - Parameters->setAttribute("calls", 0); - Parameters->setAttribute("drawn_solid", 0); - Parameters->setAttribute("drawn_transparent", 0); - Parameters->setAttribute("drawn_transparent_effect", 0); -#endif - u32 i; // new ISO for scoping problem in some compilers // reset all transforms @@ -650,9 +630,6 @@ void CSceneManager::drawAll() for (i=0; irender(); -#ifdef _IRR_SCENEMANAGER_DEBUG - Parameters->setAttribute("drawn_solid", (s32) SolidNodeList.size() ); -#endif SolidNodeList.set_used(0); } @@ -665,9 +642,6 @@ void CSceneManager::drawAll() for (i=0; irender(); -#ifdef _IRR_SCENEMANAGER_DEBUG - Parameters->setAttribute ( "drawn_transparent", (s32) TransparentNodeList.size() ); -#endif TransparentNodeList.set_used(0); } @@ -680,9 +654,7 @@ void CSceneManager::drawAll() for (i=0; irender(); -#ifdef _IRR_SCENEMANAGER_DEBUG - Parameters->setAttribute("drawn_transparent_effect", (s32) TransparentEffectNodeList.size()); -#endif + TransparentEffectNodeList.set_used(0); } @@ -693,9 +665,7 @@ void CSceneManager::drawAll() for (i=0; irender(); -#ifdef _IRR_SCENEMANAGER_DEBUG - Parameters->setAttribute("drawn_gui_nodes", (s32) GuiNodeList.size()); -#endif + GuiNodeList.set_used(0); } clearDeletionList(); From 8efd4527f6553747384858da420bfab53c23e1e5 Mon Sep 17 00:00:00 2001 From: numzero Date: Wed, 22 Feb 2023 20:21:27 +0300 Subject: [PATCH 07/42] Drop _IRR_MATERIAL_MAX_TEXTURES_ --- include/IVideoDriver.h | 27 ++++----------------------- include/IrrCompileConfig.h | 4 ---- include/SMaterial.h | 2 +- source/Irrlicht/CNullDriver.cpp | 4 ++-- 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index a8cea13..e3ea221 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -56,32 +56,13 @@ namespace video ETS_WORLD, //! Projection transformation ETS_PROJECTION, - //! Texture transformation + //! Texture 0 transformation + //! Use ETS_TEXTURE_0 + texture_number to access other texture transformations ETS_TEXTURE_0, - //! Texture transformation + //! Texture 1 transformation ETS_TEXTURE_1, - //! Texture transformation - ETS_TEXTURE_2, - //! Texture transformation - ETS_TEXTURE_3, -#if _IRR_MATERIAL_MAX_TEXTURES_>4 - //! Texture transformation - ETS_TEXTURE_4, -#if _IRR_MATERIAL_MAX_TEXTURES_>5 - //! Texture transformation - ETS_TEXTURE_5, -#if _IRR_MATERIAL_MAX_TEXTURES_>6 - //! Texture transformation - ETS_TEXTURE_6, -#if _IRR_MATERIAL_MAX_TEXTURES_>7 - //! Texture transformation - ETS_TEXTURE_7, -#endif -#endif -#endif -#endif //! Only used internally - ETS_COUNT = ETS_TEXTURE_0 + _IRR_MATERIAL_MAX_TEXTURES_ + ETS_COUNT = ETS_TEXTURE_0 + MATERIAL_MAX_TEXTURES }; //! Special render targets, which usually map to dedicated hardware diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index d186a2c..0271289 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -20,10 +20,6 @@ #include // TODO: Although included elsewhere this is required at least for mingw - -//! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. -#define _IRR_MATERIAL_MAX_TEXTURES_ 4 - #ifdef _WIN32 #define IRRCALLCONV __stdcall #else diff --git a/include/SMaterial.h b/include/SMaterial.h index 43dadb6..92dc822 100644 --- a/include/SMaterial.h +++ b/include/SMaterial.h @@ -280,7 +280,7 @@ namespace video /** SMaterial might ignore some textures in most function, like assignment and comparison, when SIrrlichtCreationParameters::MaxTextureUnits is set to a lower number. */ - const u32 MATERIAL_MAX_TEXTURES = _IRR_MATERIAL_MAX_TEXTURES_; + const u32 MATERIAL_MAX_TEXTURES = 4; //! Struct for holding parameters for a material renderer // Note for implementors: Serialization is in CNullDriver diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 5834e01..2cbd47c 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -53,8 +53,8 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d& scre #endif DriverAttributes = new io::CAttributes(); - DriverAttributes->addInt("MaxTextures", _IRR_MATERIAL_MAX_TEXTURES_); - DriverAttributes->addInt("MaxSupportedTextures", _IRR_MATERIAL_MAX_TEXTURES_); + DriverAttributes->addInt("MaxTextures", MATERIAL_MAX_TEXTURES); + DriverAttributes->addInt("MaxSupportedTextures", MATERIAL_MAX_TEXTURES); DriverAttributes->addInt("MaxAnisotropy", 1); // DriverAttributes->addInt("MaxUserClipPlanes", 0); // DriverAttributes->addInt("MaxAuxBuffers", 0); From 5a95b40a0eb2a871492855d291f1e8461bca8d5d Mon Sep 17 00:00:00 2001 From: numzero Date: Wed, 22 Feb 2023 20:59:47 +0300 Subject: [PATCH 08/42] Reduce IrrCompileConfig usage to files that actually need it --- include/SIrrCreationParameters.h | 2 +- include/SMaterial.h | 1 + include/exampleHelper.h | 1 - include/irrMath.h | 1 - include/irrTypes.h | 1 - include/irrlicht.h | 2 +- include/matrix4.h | 1 + include/mt_opengl.h | 2 +- scripts/BindingGenerator.lua | 2 +- source/Irrlicht/Android/CAndroidAssetFileArchive.cpp | 1 - source/Irrlicht/Android/CAndroidAssetFileArchive.h | 1 - source/Irrlicht/Android/CAndroidAssetReader.cpp | 1 - source/Irrlicht/Android/CAndroidAssetReader.h | 1 - source/Irrlicht/Android/CIrrDeviceAndroid.h | 1 - source/Irrlicht/Android/CKeyEventWrapper.h | 1 - source/Irrlicht/BuiltInFont.h | 1 - source/Irrlicht/CAttributes.h | 1 - source/Irrlicht/CB3DMeshFileLoader.cpp | 1 - source/Irrlicht/CB3DMeshFileLoader.h | 1 - source/Irrlicht/CB3DMeshWriter.cpp | 1 - source/Irrlicht/CBillboardSceneNode.cpp | 1 - source/Irrlicht/CBoneSceneNode.cpp | 1 - source/Irrlicht/CEAGLManager.h | 1 - source/Irrlicht/CEGLManager.h | 1 - source/Irrlicht/CFileList.cpp | 1 - source/Irrlicht/CFileSystem.cpp | 1 - source/Irrlicht/CGLXManager.h | 1 - source/Irrlicht/CGUIButton.h | 1 - source/Irrlicht/CGUICheckBox.h | 1 - source/Irrlicht/CGUIComboBox.h | 1 - source/Irrlicht/CGUIEditBox.h | 1 - source/Irrlicht/CGUIEnvironment.h | 1 - source/Irrlicht/CGUIFileOpenDialog.h | 1 - source/Irrlicht/CGUIFont.h | 1 - source/Irrlicht/CGUIImage.h | 1 - source/Irrlicht/CGUIListBox.h | 1 - source/Irrlicht/CGUIScrollBar.h | 1 - source/Irrlicht/CGUISkin.h | 1 - source/Irrlicht/CGUISpriteBank.h | 1 - source/Irrlicht/CGUIStaticText.h | 1 - source/Irrlicht/CGUITabControl.h | 1 - source/Irrlicht/CImageLoaderBMP.h | 1 - source/Irrlicht/CImageLoaderJPG.h | 1 - source/Irrlicht/CImageLoaderPNG.h | 1 - source/Irrlicht/CImageLoaderTGA.h | 1 - source/Irrlicht/CImageWriterJPG.h | 1 - source/Irrlicht/CImageWriterPNG.h | 1 - source/Irrlicht/CIrrDeviceLinux.h | 1 - source/Irrlicht/CIrrDeviceOSX.h | 1 - source/Irrlicht/CIrrDeviceOSX.mm | 1 - source/Irrlicht/CIrrDeviceSDL.cpp | 1 - source/Irrlicht/CIrrDeviceSDL.h | 1 - source/Irrlicht/CIrrDeviceStub.cpp | 2 +- source/Irrlicht/CIrrDeviceWin32.cpp | 1 - source/Irrlicht/CIrrDeviceWin32.h | 1 - source/Irrlicht/CIrrDeviceiOS.h | 1 - source/Irrlicht/CNSOGLManager.h | 1 - source/Irrlicht/COBJMeshFileLoader.cpp | 1 - source/Irrlicht/COGLES2Common.h | 1 - source/Irrlicht/COGLES2Driver.h | 1 - source/Irrlicht/COGLES2ExtensionHandler.h | 1 - source/Irrlicht/COGLES2FixedPipelineRenderer.h | 1 - source/Irrlicht/COGLES2MaterialRenderer.h | 1 - source/Irrlicht/COGLES2Renderer2D.h | 1 - source/Irrlicht/COGLESCommon.h | 1 - source/Irrlicht/COGLESCoreExtensionHandler.h | 1 - source/Irrlicht/COGLESDriver.h | 1 - source/Irrlicht/COGLESExtensionHandler.h | 1 - source/Irrlicht/COGLESMaterialRenderer.h | 1 - source/Irrlicht/COpenGLCacheHandler.h | 1 - source/Irrlicht/COpenGLCommon.h | 1 - source/Irrlicht/COpenGLCoreCacheHandler.h | 1 - source/Irrlicht/COpenGLCoreFeature.h | 1 - source/Irrlicht/COpenGLCoreRenderTarget.h | 1 - source/Irrlicht/COpenGLCoreTexture.h | 1 - source/Irrlicht/COpenGLDriver.h | 1 - source/Irrlicht/COpenGLExtensionHandler.h | 1 - source/Irrlicht/COpenGLMaterialRenderer.h | 1 - source/Irrlicht/COpenGLSLMaterialRenderer.h | 1 - source/Irrlicht/COpenGLShaderMaterialRenderer.h | 1 - source/Irrlicht/CSDLManager.h | 1 - source/Irrlicht/CSceneManager.cpp | 1 - source/Irrlicht/CSkinnedMesh.cpp | 1 - source/Irrlicht/CWGLManager.h | 1 - source/Irrlicht/CWebGL1Driver.h | 1 - source/Irrlicht/CWebGLExtensionHandler.h | 1 - source/Irrlicht/CXMeshFileLoader.cpp | 1 - source/Irrlicht/CZipReader.cpp | 1 - source/Irrlicht/CZipReader.h | 1 - source/Irrlicht/Irrlicht.cpp | 1 - source/Irrlicht/SB3DStructs.h | 1 - source/Irrlicht/os.cpp | 1 - source/Irrlicht/os.h | 1 - 93 files changed, 7 insertions(+), 91 deletions(-) diff --git a/include/SIrrCreationParameters.h b/include/SIrrCreationParameters.h index c47f3e6..bad56e3 100644 --- a/include/SIrrCreationParameters.h +++ b/include/SIrrCreationParameters.h @@ -11,7 +11,7 @@ #include "ILogger.h" #include "position2d.h" #include "path.h" -#include "IrrCompileConfig.h" +#include "IrrCompileConfig.h" // for IRRLICHT_SDK_VERSION namespace irr { diff --git a/include/SMaterial.h b/include/SMaterial.h index 92dc822..88460e0 100644 --- a/include/SMaterial.h +++ b/include/SMaterial.h @@ -12,6 +12,7 @@ #include "EMaterialTypes.h" #include "EMaterialFlags.h" #include "SMaterialLayer.h" +#include "IrrCompileConfig.h" // for IRRLICHT_API namespace irr { diff --git a/include/exampleHelper.h b/include/exampleHelper.h index 803ed6e..a98ed96 100755 --- a/include/exampleHelper.h +++ b/include/exampleHelper.h @@ -5,7 +5,6 @@ #ifndef __EXAMPLE_HELPER_H_INCLUDED__ #define __EXAMPLE_HELPER_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "path.h" namespace irr diff --git a/include/irrMath.h b/include/irrMath.h index af00f44..c4e8619 100644 --- a/include/irrMath.h +++ b/include/irrMath.h @@ -5,7 +5,6 @@ #ifndef __IRR_MATH_H_INCLUDED__ #define __IRR_MATH_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "irrTypes.h" #include #include diff --git a/include/irrTypes.h b/include/irrTypes.h index eda3a21..98b1ed6 100644 --- a/include/irrTypes.h +++ b/include/irrTypes.h @@ -5,7 +5,6 @@ #ifndef __IRR_TYPES_H_INCLUDED__ #define __IRR_TYPES_H_INCLUDED__ -#include "IrrCompileConfig.h" #include namespace irr diff --git a/include/irrlicht.h b/include/irrlicht.h index 065ed60..e099cf7 100644 --- a/include/irrlicht.h +++ b/include/irrlicht.h @@ -29,7 +29,6 @@ #ifndef __IRRLICHT_H_INCLUDED__ #define __IRRLICHT_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "aabbox3d.h" #include "CIndexBuffer.h" #include "CMeshBuffer.h" @@ -135,6 +134,7 @@ #include "triangle3d.h" #include "vector2d.h" #include "vector3d.h" +#include "IrrCompileConfig.h" // for IRRLICHT_API and IRRCALLCONV /*! \mainpage Irrlicht Engine 1.9 API documentation * diff --git a/include/matrix4.h b/include/matrix4.h index c410973..efd353d 100644 --- a/include/matrix4.h +++ b/include/matrix4.h @@ -12,6 +12,7 @@ #include "aabbox3d.h" #include "rect.h" #include "irrString.h" +#include "IrrCompileConfig.h" // for IRRLICHT_API // enable this to keep track of changes to the matrix // and make simpler identity check for seldom changing matrices diff --git a/include/mt_opengl.h b/include/mt_opengl.h index e7876cf..7b76cd9 100755 --- a/include/mt_opengl.h +++ b/include/mt_opengl.h @@ -5,7 +5,7 @@ #include #include -#include "IrrCompileConfig.h" +#include "IrrCompileConfig.h" // for IRRLICHT_API #include "irrTypes.h" #include "IContextManager.h" #include diff --git a/scripts/BindingGenerator.lua b/scripts/BindingGenerator.lua index 0774cdd..ba77748 100755 --- a/scripts/BindingGenerator.lua +++ b/scripts/BindingGenerator.lua @@ -349,7 +349,7 @@ f:write[[ #include #include -#include "IrrCompileConfig.h" +#include "IrrCompileConfig.h" // for IRRLICHT_API #include "irrTypes.h" #include "IContextManager.h" #include diff --git a/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp b/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp index 53d06f8..f5c02d1 100644 --- a/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp +++ b/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_ANDROID_ASSET_READER_ diff --git a/source/Irrlicht/Android/CAndroidAssetFileArchive.h b/source/Irrlicht/Android/CAndroidAssetFileArchive.h index 7d7ab35..24a62f0 100644 --- a/source/Irrlicht/Android/CAndroidAssetFileArchive.h +++ b/source/Irrlicht/Android/CAndroidAssetFileArchive.h @@ -6,7 +6,6 @@ #define __C_ANDROID_ASSET_FILE_ARCHIVE_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_ANDROID_ASSET_READER_ diff --git a/source/Irrlicht/Android/CAndroidAssetReader.cpp b/source/Irrlicht/Android/CAndroidAssetReader.cpp index ef1529b..55383e2 100644 --- a/source/Irrlicht/Android/CAndroidAssetReader.cpp +++ b/source/Irrlicht/Android/CAndroidAssetReader.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_ANDROID_ASSET_READER_ diff --git a/source/Irrlicht/Android/CAndroidAssetReader.h b/source/Irrlicht/Android/CAndroidAssetReader.h index c9d96a5..7791a77 100644 --- a/source/Irrlicht/Android/CAndroidAssetReader.h +++ b/source/Irrlicht/Android/CAndroidAssetReader.h @@ -6,7 +6,6 @@ #define __C_ANDROID_ASSET_READER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_ANDROID_ASSET_READER_ diff --git a/source/Irrlicht/Android/CIrrDeviceAndroid.h b/source/Irrlicht/Android/CIrrDeviceAndroid.h index a1f13c3..4a3cd95 100644 --- a/source/Irrlicht/Android/CIrrDeviceAndroid.h +++ b/source/Irrlicht/Android/CIrrDeviceAndroid.h @@ -5,7 +5,6 @@ #ifndef __C_IRR_DEVICE_ANDROID_H_INCLUDED__ #define __C_IRR_DEVICE_ANDROID_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ diff --git a/source/Irrlicht/Android/CKeyEventWrapper.h b/source/Irrlicht/Android/CKeyEventWrapper.h index bac23ad..b6bc09b 100644 --- a/source/Irrlicht/Android/CKeyEventWrapper.h +++ b/source/Irrlicht/Android/CKeyEventWrapper.h @@ -4,7 +4,6 @@ #ifndef __C_IRR_KEY_EVENT_WRAPPER_H_INCLUDED__ #define __C_IRR_KEY_EVENT_WRAPPER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ diff --git a/source/Irrlicht/BuiltInFont.h b/source/Irrlicht/BuiltInFont.h index be3a7f9..5d88937 100644 --- a/source/Irrlicht/BuiltInFont.h +++ b/source/Irrlicht/BuiltInFont.h @@ -5,7 +5,6 @@ #ifndef __BUILD_IN_FONT_H_INCLUDED__ #define __BUILD_IN_FONT_H_INCLUDED__ -#include "IrrCompileConfig.h" // header file generated by Bin2H, copyright 2002 by N.Gebhardt. // Bin2H is Freeware. Download it freely from www.code3d.com. diff --git a/source/Irrlicht/CAttributes.h b/source/Irrlicht/CAttributes.h index 7156b8e..3d88115 100644 --- a/source/Irrlicht/CAttributes.h +++ b/source/Irrlicht/CAttributes.h @@ -5,7 +5,6 @@ #ifndef __C_ATTRIBUTES_H_INCLUDED__ #define __C_ATTRIBUTES_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IAttributes.h" #include "IAttribute.h" diff --git a/source/Irrlicht/CB3DMeshFileLoader.cpp b/source/Irrlicht/CB3DMeshFileLoader.cpp index 83ec373..448030b 100644 --- a/source/Irrlicht/CB3DMeshFileLoader.cpp +++ b/source/Irrlicht/CB3DMeshFileLoader.cpp @@ -6,7 +6,6 @@ // File format designed by Mark Sibly for the Blitz3D engine and has been // declared public domain -#include "IrrCompileConfig.h" #include "CB3DMeshFileLoader.h" #include "IVideoDriver.h" diff --git a/source/Irrlicht/CB3DMeshFileLoader.h b/source/Irrlicht/CB3DMeshFileLoader.h index 765405f..d19f190 100644 --- a/source/Irrlicht/CB3DMeshFileLoader.h +++ b/source/Irrlicht/CB3DMeshFileLoader.h @@ -6,7 +6,6 @@ // File format designed by Mark Sibly for the Blitz3D engine and has been // declared public domain -#include "IrrCompileConfig.h" #ifndef __C_B3D_MESH_LOADER_H_INCLUDED__ #define __C_B3D_MESH_LOADER_H_INCLUDED__ diff --git a/source/Irrlicht/CB3DMeshWriter.cpp b/source/Irrlicht/CB3DMeshWriter.cpp index 0b588fc..ac68f77 100644 --- a/source/Irrlicht/CB3DMeshWriter.cpp +++ b/source/Irrlicht/CB3DMeshWriter.cpp @@ -4,7 +4,6 @@ // TODO: replace printf's by logging messages -#include "IrrCompileConfig.h" #include "CB3DMeshWriter.h" #include "os.h" diff --git a/source/Irrlicht/CBillboardSceneNode.cpp b/source/Irrlicht/CBillboardSceneNode.cpp index c297978..da90c3a 100644 --- a/source/Irrlicht/CBillboardSceneNode.cpp +++ b/source/Irrlicht/CBillboardSceneNode.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "CBillboardSceneNode.h" #include "IVideoDriver.h" #include "ISceneManager.h" diff --git a/source/Irrlicht/CBoneSceneNode.cpp b/source/Irrlicht/CBoneSceneNode.cpp index 4f05b84..3d0f812 100644 --- a/source/Irrlicht/CBoneSceneNode.cpp +++ b/source/Irrlicht/CBoneSceneNode.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "CBoneSceneNode.h" namespace irr diff --git a/source/Irrlicht/CEAGLManager.h b/source/Irrlicht/CEAGLManager.h index c1f8845..65caa7a 100644 --- a/source/Irrlicht/CEAGLManager.h +++ b/source/Irrlicht/CEAGLManager.h @@ -5,7 +5,6 @@ #ifndef __C_EAGL_MANAGER_H_INCLUDED__ #define __C_EAGL_MANAGER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_EAGL_MANAGER_ diff --git a/source/Irrlicht/CEGLManager.h b/source/Irrlicht/CEGLManager.h index 2d61bd2..78e96c8 100755 --- a/source/Irrlicht/CEGLManager.h +++ b/source/Irrlicht/CEGLManager.h @@ -5,7 +5,6 @@ #ifndef __C_EGL_MANAGER_H_INCLUDED__ #define __C_EGL_MANAGER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_EGL_MANAGER_ diff --git a/source/Irrlicht/CFileList.cpp b/source/Irrlicht/CFileList.cpp index 15d5410..720b8bb 100644 --- a/source/Irrlicht/CFileList.cpp +++ b/source/Irrlicht/CFileList.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CFileList.h" -#include "IrrCompileConfig.h" #include "irrArray.h" #include "coreutil.h" diff --git a/source/Irrlicht/CFileSystem.cpp b/source/Irrlicht/CFileSystem.cpp index 17ae7b3..ba4a332 100644 --- a/source/Irrlicht/CFileSystem.cpp +++ b/source/Irrlicht/CFileSystem.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "CFileSystem.h" #include "IReadFile.h" diff --git a/source/Irrlicht/CGLXManager.h b/source/Irrlicht/CGLXManager.h index 85c3c94..9e4ce74 100644 --- a/source/Irrlicht/CGLXManager.h +++ b/source/Irrlicht/CGLXManager.h @@ -5,7 +5,6 @@ #ifndef __C_GLX_MANAGER_H_INCLUDED__ #define __C_GLX_MANAGER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_GLX_MANAGER_ diff --git a/source/Irrlicht/CGUIButton.h b/source/Irrlicht/CGUIButton.h index 6c718b1..0e42957 100644 --- a/source/Irrlicht/CGUIButton.h +++ b/source/Irrlicht/CGUIButton.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_BUTTON_H_INCLUDED__ #define __C_GUI_BUTTON_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIButton.h" #include "IGUISpriteBank.h" #include "ITexture.h" diff --git a/source/Irrlicht/CGUICheckBox.h b/source/Irrlicht/CGUICheckBox.h index facbfb0..8319243 100644 --- a/source/Irrlicht/CGUICheckBox.h +++ b/source/Irrlicht/CGUICheckBox.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_CHECKBOX_H_INCLUDED__ #define __C_GUI_CHECKBOX_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUICheckBox.h" namespace irr diff --git a/source/Irrlicht/CGUIComboBox.h b/source/Irrlicht/CGUIComboBox.h index 13996f0..2dab66f 100644 --- a/source/Irrlicht/CGUIComboBox.h +++ b/source/Irrlicht/CGUIComboBox.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_COMBO_BOX_H_INCLUDED__ #define __C_GUI_COMBO_BOX_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIComboBox.h" #include "IGUIStaticText.h" #include "irrString.h" diff --git a/source/Irrlicht/CGUIEditBox.h b/source/Irrlicht/CGUIEditBox.h index 0626fec..4a1b6e8 100644 --- a/source/Irrlicht/CGUIEditBox.h +++ b/source/Irrlicht/CGUIEditBox.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_EDIT_BOX_H_INCLUDED__ #define __C_GUI_EDIT_BOX_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIEditBox.h" #include "irrArray.h" #include "IOSOperator.h" diff --git a/source/Irrlicht/CGUIEnvironment.h b/source/Irrlicht/CGUIEnvironment.h index 2a6097c..f68b0da 100644 --- a/source/Irrlicht/CGUIEnvironment.h +++ b/source/Irrlicht/CGUIEnvironment.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_ENVIRONMENT_H_INCLUDED__ #define __C_GUI_ENVIRONMENT_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIEnvironment.h" #include "IGUIElement.h" #include "irrArray.h" diff --git a/source/Irrlicht/CGUIFileOpenDialog.h b/source/Irrlicht/CGUIFileOpenDialog.h index c51f604..a1d633c 100644 --- a/source/Irrlicht/CGUIFileOpenDialog.h +++ b/source/Irrlicht/CGUIFileOpenDialog.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_FILE_OPEN_DIALOG_H_INCLUDED__ #define __C_GUI_FILE_OPEN_DIALOG_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIFileOpenDialog.h" #include "IGUIButton.h" #include "IGUIListBox.h" diff --git a/source/Irrlicht/CGUIFont.h b/source/Irrlicht/CGUIFont.h index c7b9337..449df08 100644 --- a/source/Irrlicht/CGUIFont.h +++ b/source/Irrlicht/CGUIFont.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_FONT_H_INCLUDED__ #define __C_GUI_FONT_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIFontBitmap.h" #include "irrString.h" #include "IReadFile.h" diff --git a/source/Irrlicht/CGUIImage.h b/source/Irrlicht/CGUIImage.h index 37d0abc..c8a46f2 100644 --- a/source/Irrlicht/CGUIImage.h +++ b/source/Irrlicht/CGUIImage.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_IMAGE_H_INCLUDED__ #define __C_GUI_IMAGE_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIImage.h" namespace irr diff --git a/source/Irrlicht/CGUIListBox.h b/source/Irrlicht/CGUIListBox.h index a615ed4..a3e7255 100644 --- a/source/Irrlicht/CGUIListBox.h +++ b/source/Irrlicht/CGUIListBox.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_LIST_BOX_H_INCLUDED__ #define __C_GUI_LIST_BOX_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIListBox.h" #include "irrArray.h" diff --git a/source/Irrlicht/CGUIScrollBar.h b/source/Irrlicht/CGUIScrollBar.h index 1a6d683..d1d04b8 100644 --- a/source/Irrlicht/CGUIScrollBar.h +++ b/source/Irrlicht/CGUIScrollBar.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_SCROLL_BAR_H_INCLUDED__ #define __C_GUI_SCROLL_BAR_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIScrollBar.h" #include "IGUIButton.h" diff --git a/source/Irrlicht/CGUISkin.h b/source/Irrlicht/CGUISkin.h index 436124b..d6f8ef8 100644 --- a/source/Irrlicht/CGUISkin.h +++ b/source/Irrlicht/CGUISkin.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_SKIN_H_INCLUDED__ #define __C_GUI_SKIN_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUISkin.h" #include "irrString.h" diff --git a/source/Irrlicht/CGUISpriteBank.h b/source/Irrlicht/CGUISpriteBank.h index 2a324a7..affd6bf 100644 --- a/source/Irrlicht/CGUISpriteBank.h +++ b/source/Irrlicht/CGUISpriteBank.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_SPRITE_BANK_H_INCLUDED__ #define __C_GUI_SPRITE_BANK_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUISpriteBank.h" namespace irr diff --git a/source/Irrlicht/CGUIStaticText.h b/source/Irrlicht/CGUIStaticText.h index 41045d0..8e1babe 100644 --- a/source/Irrlicht/CGUIStaticText.h +++ b/source/Irrlicht/CGUIStaticText.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_STATIC_TEXT_H_INCLUDED__ #define __C_GUI_STATIC_TEXT_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUIStaticText.h" #include "irrArray.h" diff --git a/source/Irrlicht/CGUITabControl.h b/source/Irrlicht/CGUITabControl.h index 5bca2b6..4c2a054 100644 --- a/source/Irrlicht/CGUITabControl.h +++ b/source/Irrlicht/CGUITabControl.h @@ -5,7 +5,6 @@ #ifndef __C_GUI_TAB_CONTROL_H_INCLUDED__ #define __C_GUI_TAB_CONTROL_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IGUITabControl.h" #include "irrArray.h" #include "IGUISkin.h" diff --git a/source/Irrlicht/CImageLoaderBMP.h b/source/Irrlicht/CImageLoaderBMP.h index 6217f1b..1f94403 100644 --- a/source/Irrlicht/CImageLoaderBMP.h +++ b/source/Irrlicht/CImageLoaderBMP.h @@ -5,7 +5,6 @@ #ifndef __C_IMAGE_LOADER_BMP_H_INCLUDED__ #define __C_IMAGE_LOADER_BMP_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IImageLoader.h" diff --git a/source/Irrlicht/CImageLoaderJPG.h b/source/Irrlicht/CImageLoaderJPG.h index 7e727a3..0316394 100644 --- a/source/Irrlicht/CImageLoaderJPG.h +++ b/source/Irrlicht/CImageLoaderJPG.h @@ -5,7 +5,6 @@ #ifndef __C_IMAGE_LOADER_JPG_H_INCLUDED__ #define __C_IMAGE_LOADER_JPG_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IImageLoader.h" diff --git a/source/Irrlicht/CImageLoaderPNG.h b/source/Irrlicht/CImageLoaderPNG.h index ed135db..45a37fd 100644 --- a/source/Irrlicht/CImageLoaderPNG.h +++ b/source/Irrlicht/CImageLoaderPNG.h @@ -9,7 +9,6 @@ #ifndef __C_IMAGE_LOADER_PNG_H_INCLUDED__ #define __C_IMAGE_LOADER_PNG_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IImageLoader.h" diff --git a/source/Irrlicht/CImageLoaderTGA.h b/source/Irrlicht/CImageLoaderTGA.h index f31c682..4e67579 100644 --- a/source/Irrlicht/CImageLoaderTGA.h +++ b/source/Irrlicht/CImageLoaderTGA.h @@ -5,7 +5,6 @@ #ifndef __C_IMAGE_LOADER_TGA_H_INCLUDED__ #define __C_IMAGE_LOADER_TGA_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IImageLoader.h" diff --git a/source/Irrlicht/CImageWriterJPG.h b/source/Irrlicht/CImageWriterJPG.h index facf67d..dd98e91 100644 --- a/source/Irrlicht/CImageWriterJPG.h +++ b/source/Irrlicht/CImageWriterJPG.h @@ -5,7 +5,6 @@ #ifndef _C_IMAGE_WRITER_JPG_H_INCLUDED__ #define _C_IMAGE_WRITER_JPG_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IImageWriter.h" diff --git a/source/Irrlicht/CImageWriterPNG.h b/source/Irrlicht/CImageWriterPNG.h index 4d6619f..181d0c5 100644 --- a/source/Irrlicht/CImageWriterPNG.h +++ b/source/Irrlicht/CImageWriterPNG.h @@ -5,7 +5,6 @@ #ifndef _C_IMAGE_WRITER_PNG_H_INCLUDED__ #define _C_IMAGE_WRITER_PNG_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IImageWriter.h" diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index c456a1a..45d3f10 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -5,7 +5,6 @@ #ifndef __C_IRR_DEVICE_LINUX_H_INCLUDED__ #define __C_IRR_DEVICE_LINUX_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceOSX.h b/source/Irrlicht/CIrrDeviceOSX.h index b8cdb42..d1b2049 100644 --- a/source/Irrlicht/CIrrDeviceOSX.h +++ b/source/Irrlicht/CIrrDeviceOSX.h @@ -6,7 +6,6 @@ #ifndef __C_IRR_DEVICE_OSX_H_INCLUDED__ #define __C_IRR_DEVICE_OSX_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceOSX.mm b/source/Irrlicht/CIrrDeviceOSX.mm index e3b2a9a..4069cf1 100644 --- a/source/Irrlicht/CIrrDeviceOSX.mm +++ b/source/Irrlicht/CIrrDeviceOSX.mm @@ -4,7 +4,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 23f00d2..8dee4d1 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 7657718..4dbb2e7 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -7,7 +7,6 @@ #ifndef __C_IRR_DEVICE_SDL_H_INCLUDED__ #define __C_IRR_DEVICE_SDL_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index 16028c8..92cda75 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -9,10 +9,10 @@ #include "IGUIElement.h" #include "IGUIEnvironment.h" #include "os.h" -#include "IrrCompileConfig.h" #include "CTimer.h" #include "CLogger.h" #include "irrString.h" +#include "IrrCompileConfig.h" // for IRRLICHT_SDK_VERSION namespace irr { diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index ddff014..1033f9e 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ diff --git a/source/Irrlicht/CIrrDeviceWin32.h b/source/Irrlicht/CIrrDeviceWin32.h index 4af8d02..9ca44ac 100644 --- a/source/Irrlicht/CIrrDeviceWin32.h +++ b/source/Irrlicht/CIrrDeviceWin32.h @@ -5,7 +5,6 @@ #ifndef __C_IRR_DEVICE_WIN32_H_INCLUDED__ #define __C_IRR_DEVICE_WIN32_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #include "CIrrDeviceStub.h" diff --git a/source/Irrlicht/CIrrDeviceiOS.h b/source/Irrlicht/CIrrDeviceiOS.h index d383c18..6130d27 100644 --- a/source/Irrlicht/CIrrDeviceiOS.h +++ b/source/Irrlicht/CIrrDeviceiOS.h @@ -7,7 +7,6 @@ #ifndef __C_IRR_DEVICE_IOS_H_INCLUDED__ #define __C_IRR_DEVICE_IOS_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ diff --git a/source/Irrlicht/CNSOGLManager.h b/source/Irrlicht/CNSOGLManager.h index efe0b42..8744d16 100644 --- a/source/Irrlicht/CNSOGLManager.h +++ b/source/Irrlicht/CNSOGLManager.h @@ -5,7 +5,6 @@ #ifndef __C_NSOGL_MANAGER_H_INCLUDED__ #define __C_NSOGL_MANAGER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_NSOGL_MANAGER_ diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index 11fa484..c4be102 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "COBJMeshFileLoader.h" #include "IMeshManipulator.h" #include "IVideoDriver.h" diff --git a/source/Irrlicht/COGLES2Common.h b/source/Irrlicht/COGLES2Common.h index 2c844ce..a69f667 100644 --- a/source/Irrlicht/COGLES2Common.h +++ b/source/Irrlicht/COGLES2Common.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES2_COMMON_H_INCLUDED__ #define __C_OGLES2_COMMON_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES2_ diff --git a/source/Irrlicht/COGLES2Driver.h b/source/Irrlicht/COGLES2Driver.h index 8d31ff6..eaf4d99 100644 --- a/source/Irrlicht/COGLES2Driver.h +++ b/source/Irrlicht/COGLES2Driver.h @@ -6,7 +6,6 @@ #ifndef __C_OGLES2_DRIVER_H_INCLUDED__ #define __C_OGLES2_DRIVER_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "SIrrCreationParameters.h" diff --git a/source/Irrlicht/COGLES2ExtensionHandler.h b/source/Irrlicht/COGLES2ExtensionHandler.h index 2e81b37..73db08a 100644 --- a/source/Irrlicht/COGLES2ExtensionHandler.h +++ b/source/Irrlicht/COGLES2ExtensionHandler.h @@ -6,7 +6,6 @@ #ifndef __C_OGLES2_EXTENSION_HANDLER_H_INCLUDED__ #define __C_OGLES2_EXTENSION_HANDLER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES2_ diff --git a/source/Irrlicht/COGLES2FixedPipelineRenderer.h b/source/Irrlicht/COGLES2FixedPipelineRenderer.h index f5882f1..b50ef74 100644 --- a/source/Irrlicht/COGLES2FixedPipelineRenderer.h +++ b/source/Irrlicht/COGLES2FixedPipelineRenderer.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES2_FIXED_PIPELINE_SHADER_H_INCLUDED__ #define __C_OGLES2_FIXED_PIPELINE_SHADER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES2_ diff --git a/source/Irrlicht/COGLES2MaterialRenderer.h b/source/Irrlicht/COGLES2MaterialRenderer.h index 9c4c2c9..5483263 100644 --- a/source/Irrlicht/COGLES2MaterialRenderer.h +++ b/source/Irrlicht/COGLES2MaterialRenderer.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES2_SL_MATERIAL_RENDERER_H_INCLUDED__ #define __C_OGLES2_SL_MATERIAL_RENDERER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES2_ diff --git a/source/Irrlicht/COGLES2Renderer2D.h b/source/Irrlicht/COGLES2Renderer2D.h index 2521758..1d69828 100644 --- a/source/Irrlicht/COGLES2Renderer2D.h +++ b/source/Irrlicht/COGLES2Renderer2D.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES2_RENDERER_2D_H_INCLUDED__ #define __C_OGLES2_RENDERER_2D_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES2_ diff --git a/source/Irrlicht/COGLESCommon.h b/source/Irrlicht/COGLESCommon.h index a7b8eb3..57e5b7b 100644 --- a/source/Irrlicht/COGLESCommon.h +++ b/source/Irrlicht/COGLESCommon.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES_COMMON_H_INCLUDED__ #define __C_OGLES_COMMON_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES1_ diff --git a/source/Irrlicht/COGLESCoreExtensionHandler.h b/source/Irrlicht/COGLESCoreExtensionHandler.h index a557844..ce6ea1d 100644 --- a/source/Irrlicht/COGLESCoreExtensionHandler.h +++ b/source/Irrlicht/COGLESCoreExtensionHandler.h @@ -5,7 +5,6 @@ #ifndef __E_OGLES_CORE_EXTENSION_HANDLER_H_INCLUDED__ #define __E_OGLES_CORE_EXTENSION_HANDLER_H_INCLUDED__ -#include "IrrCompileConfig.h" // Can be included from different ES versions // (this is also the reason why this file is header-only as correct OGL ES headers have to be included first) diff --git a/source/Irrlicht/COGLESDriver.h b/source/Irrlicht/COGLESDriver.h index eb27f07..7428094 100644 --- a/source/Irrlicht/COGLESDriver.h +++ b/source/Irrlicht/COGLESDriver.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES1_DRIVER_H_INCLUDED__ #define __C_OGLES1_DRIVER_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "SIrrCreationParameters.h" diff --git a/source/Irrlicht/COGLESExtensionHandler.h b/source/Irrlicht/COGLESExtensionHandler.h index efed793..bcc3278 100644 --- a/source/Irrlicht/COGLESExtensionHandler.h +++ b/source/Irrlicht/COGLESExtensionHandler.h @@ -6,7 +6,6 @@ #ifndef __C_OGLES_EXTENSION_HANDLER_H_INCLUDED__ #define __C_OGLES_EXTENSION_HANDLER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES1_ diff --git a/source/Irrlicht/COGLESMaterialRenderer.h b/source/Irrlicht/COGLESMaterialRenderer.h index 5af6f73..b2f8861 100644 --- a/source/Irrlicht/COGLESMaterialRenderer.h +++ b/source/Irrlicht/COGLESMaterialRenderer.h @@ -5,7 +5,6 @@ #ifndef __C_OGLES1_MATERIAL_RENDERER_H_INCLUDED__ #define __C_OGLES1_MATERIAL_RENDERER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OGLES1_ #include "COGLESDriver.h" diff --git a/source/Irrlicht/COpenGLCacheHandler.h b/source/Irrlicht/COpenGLCacheHandler.h index f7d14c0..11c8a29 100644 --- a/source/Irrlicht/COpenGLCacheHandler.h +++ b/source/Irrlicht/COpenGLCacheHandler.h @@ -5,7 +5,6 @@ #ifndef __C_OPENGL_CACHE_HANDLER_H_INCLUDED__ #define __C_OPENGL_CACHE_HANDLER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OPENGL_ diff --git a/source/Irrlicht/COpenGLCommon.h b/source/Irrlicht/COpenGLCommon.h index 6f7b790..52a0604 100644 --- a/source/Irrlicht/COpenGLCommon.h +++ b/source/Irrlicht/COpenGLCommon.h @@ -5,7 +5,6 @@ #ifndef __C_OPENGL_COMMON_H_INCLUDED__ #define __C_OPENGL_COMMON_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OPENGL_ diff --git a/source/Irrlicht/COpenGLCoreCacheHandler.h b/source/Irrlicht/COpenGLCoreCacheHandler.h index 5726e5f..79b2800 100644 --- a/source/Irrlicht/COpenGLCoreCacheHandler.h +++ b/source/Irrlicht/COpenGLCoreCacheHandler.h @@ -5,7 +5,6 @@ #ifndef __C_OGLCORE_CACHE_HANDLER_H_INCLUDED__ #define __C_OGLCORE_CACHE_HANDLER_H_INCLUDED__ -#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) diff --git a/source/Irrlicht/COpenGLCoreFeature.h b/source/Irrlicht/COpenGLCoreFeature.h index 6ec5822..fe86f95 100644 --- a/source/Irrlicht/COpenGLCoreFeature.h +++ b/source/Irrlicht/COpenGLCoreFeature.h @@ -5,7 +5,6 @@ #ifndef __C_OGLCORE_FEATURE_H_INCLUDED__ #define __C_OGLCORE_FEATURE_H_INCLUDED__ -#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) diff --git a/source/Irrlicht/COpenGLCoreRenderTarget.h b/source/Irrlicht/COpenGLCoreRenderTarget.h index 6c542f5..0dd08eb 100644 --- a/source/Irrlicht/COpenGLCoreRenderTarget.h +++ b/source/Irrlicht/COpenGLCoreRenderTarget.h @@ -5,7 +5,6 @@ #ifndef __C_OGLCORE_RENDER_TARGET_H_INCLUDED__ #define __C_OGLCORE_RENDER_TARGET_H_INCLUDED__ -#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index 8897c58..c19215b 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -5,7 +5,6 @@ #ifndef __C_OGLCORE_TEXTURE_H_INCLUDED__ #define __C_OGLCORE_TEXTURE_H_INCLUDED__ -#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 3454036..c60d2ba 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -5,7 +5,6 @@ #ifndef __C_VIDEO_OPEN_GL_H_INCLUDED__ #define __C_VIDEO_OPEN_GL_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "SIrrCreationParameters.h" diff --git a/source/Irrlicht/COpenGLExtensionHandler.h b/source/Irrlicht/COpenGLExtensionHandler.h index 960b7f6..5d748d5 100644 --- a/source/Irrlicht/COpenGLExtensionHandler.h +++ b/source/Irrlicht/COpenGLExtensionHandler.h @@ -5,7 +5,6 @@ #ifndef __C_OPEN_GL_FEATURE_MAP_H_INCLUDED__ #define __C_OPEN_GL_FEATURE_MAP_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OPENGL_ diff --git a/source/Irrlicht/COpenGLMaterialRenderer.h b/source/Irrlicht/COpenGLMaterialRenderer.h index ed37e5d..6d33056 100644 --- a/source/Irrlicht/COpenGLMaterialRenderer.h +++ b/source/Irrlicht/COpenGLMaterialRenderer.h @@ -5,7 +5,6 @@ #ifndef __C_OPENGL_MATERIAL_RENDERER_H_INCLUDED__ #define __C_OPENGL_MATERIAL_RENDERER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OPENGL_ #include "IMaterialRenderer.h" diff --git a/source/Irrlicht/COpenGLSLMaterialRenderer.h b/source/Irrlicht/COpenGLSLMaterialRenderer.h index b6a4f82..a870a6e 100644 --- a/source/Irrlicht/COpenGLSLMaterialRenderer.h +++ b/source/Irrlicht/COpenGLSLMaterialRenderer.h @@ -5,7 +5,6 @@ #ifndef __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__ #define __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OPENGL_ diff --git a/source/Irrlicht/COpenGLShaderMaterialRenderer.h b/source/Irrlicht/COpenGLShaderMaterialRenderer.h index 80ca433..81f8c81 100644 --- a/source/Irrlicht/COpenGLShaderMaterialRenderer.h +++ b/source/Irrlicht/COpenGLShaderMaterialRenderer.h @@ -5,7 +5,6 @@ #ifndef __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__ #define __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_OPENGL_ diff --git a/source/Irrlicht/CSDLManager.h b/source/Irrlicht/CSDLManager.h index 6b0f254..3d9648c 100644 --- a/source/Irrlicht/CSDLManager.h +++ b/source/Irrlicht/CSDLManager.h @@ -5,7 +5,6 @@ #ifndef __C_SDL_MANAGER_H_INCLUDED__ #define __C_SDL_MANAGER_H_INCLUDED__ -#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && defined(_IRR_COMPILE_WITH_OPENGL_) diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index fd837cc..e22ddd5 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "CSceneManager.h" #include "IVideoDriver.h" #include "IFileSystem.h" diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index 5e01e06..f7cf1f0 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "CSkinnedMesh.h" #include "CBoneSceneNode.h" #include "IAnimatedMeshSceneNode.h" diff --git a/source/Irrlicht/CWGLManager.h b/source/Irrlicht/CWGLManager.h index bd75065..e2d1513 100644 --- a/source/Irrlicht/CWGLManager.h +++ b/source/Irrlicht/CWGLManager.h @@ -5,7 +5,6 @@ #ifndef __C_WGL_MANAGER_H_INCLUDED__ #define __C_WGL_MANAGER_H_INCLUDED__ -#include "IrrCompileConfig.h" #ifdef _IRR_COMPILE_WITH_WGL_MANAGER_ diff --git a/source/Irrlicht/CWebGL1Driver.h b/source/Irrlicht/CWebGL1Driver.h index ce26432..73c5a21 100644 --- a/source/Irrlicht/CWebGL1Driver.h +++ b/source/Irrlicht/CWebGL1Driver.h @@ -5,7 +5,6 @@ #ifndef __C_WEBGL1_DRIVER_H_INCLUDED__ #define __C_WEBGL1_DRIVER_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "SIrrCreationParameters.h" diff --git a/source/Irrlicht/CWebGLExtensionHandler.h b/source/Irrlicht/CWebGLExtensionHandler.h index 67ffaf7..9a78df3 100644 --- a/source/Irrlicht/CWebGLExtensionHandler.h +++ b/source/Irrlicht/CWebGLExtensionHandler.h @@ -5,7 +5,6 @@ #ifndef __E_WEGL_EXTENSION_HANDLER_H_INCLUDED__ #define __E_WEGL_EXTENSION_HANDLER_H_INCLUDED__ -#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_WEBGL1_) // Note: should also work with WebGL2 once we add that to Irrlicht diff --git a/source/Irrlicht/CXMeshFileLoader.cpp b/source/Irrlicht/CXMeshFileLoader.cpp index dfeefd3..7603ec5 100644 --- a/source/Irrlicht/CXMeshFileLoader.cpp +++ b/source/Irrlicht/CXMeshFileLoader.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" #include "CXMeshFileLoader.h" #include "os.h" diff --git a/source/Irrlicht/CZipReader.cpp b/source/Irrlicht/CZipReader.cpp index 500db90..071f735 100644 --- a/source/Irrlicht/CZipReader.cpp +++ b/source/Irrlicht/CZipReader.cpp @@ -11,7 +11,6 @@ #include "CReadFile.h" #include "coreutil.h" -#include "IrrCompileConfig.h" #include // use system lib namespace irr diff --git a/source/Irrlicht/CZipReader.h b/source/Irrlicht/CZipReader.h index 02de98f..6b16ab9 100644 --- a/source/Irrlicht/CZipReader.h +++ b/source/Irrlicht/CZipReader.h @@ -5,7 +5,6 @@ #ifndef __C_ZIP_READER_H_INCLUDED__ #define __C_ZIP_READER_H_INCLUDED__ -#include "IrrCompileConfig.h" #include "IReadFile.h" #include "irrArray.h" diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index 4438b51..826414f 100644 --- a/source/Irrlicht/Irrlicht.cpp +++ b/source/Irrlicht/Irrlicht.cpp @@ -2,7 +2,6 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h -#include "IrrCompileConfig.h" static const char* const copyright = "Irrlicht Engine (c) 2002-2017 Nikolaus Gebhardt"; // put string in binary diff --git a/source/Irrlicht/SB3DStructs.h b/source/Irrlicht/SB3DStructs.h index 8f88a85..ddd8bd6 100644 --- a/source/Irrlicht/SB3DStructs.h +++ b/source/Irrlicht/SB3DStructs.h @@ -6,7 +6,6 @@ // File format designed by Mark Sibly for the Blitz3D engine and has been // declared public domain -#include "IrrCompileConfig.h" #ifndef SB3DSTRUCTS_H #define SB3DSTRUCTS_H diff --git a/source/Irrlicht/os.cpp b/source/Irrlicht/os.cpp index 2b894bc..6b38657 100644 --- a/source/Irrlicht/os.cpp +++ b/source/Irrlicht/os.cpp @@ -4,7 +4,6 @@ #include "os.h" #include "irrString.h" -#include "IrrCompileConfig.h" #include "irrMath.h" #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) diff --git a/source/Irrlicht/os.h b/source/Irrlicht/os.h index 77012c2..c0aa83b 100644 --- a/source/Irrlicht/os.h +++ b/source/Irrlicht/os.h @@ -5,7 +5,6 @@ #ifndef __IRR_OS_H_INCLUDED__ #define __IRR_OS_H_INCLUDED__ -#include "IrrCompileConfig.h" // for endian check #include "irrTypes.h" #include "irrString.h" #include "path.h" From 01295c9ce6d6d5f006eb5cf204115c4b2418ac58 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 16:47:30 +0300 Subject: [PATCH 09/42] Add OpenGL3 renderer --- source/Irrlicht/CIrrDeviceSDL.cpp | 19 +- source/Irrlicht/CMakeLists.txt | 19 + source/Irrlicht/COGLESCoreExtensionHandler.h | 8 +- source/Irrlicht/COpenGLCoreRenderTarget.h | 4 +- source/Irrlicht/OpenGL/Common.h | 36 + source/Irrlicht/OpenGL/Driver.cpp | 2876 +++++++++++++++++ source/Irrlicht/OpenGL/Driver.h | 403 +++ source/Irrlicht/OpenGL/ExtensionHandler.cpp | 52 + source/Irrlicht/OpenGL/ExtensionHandler.h | 187 ++ .../Irrlicht/OpenGL/FixedPipelineRenderer.cpp | 334 ++ .../Irrlicht/OpenGL/FixedPipelineRenderer.h | 180 ++ source/Irrlicht/OpenGL/MaterialRenderer.cpp | 481 +++ source/Irrlicht/OpenGL/MaterialRenderer.h | 99 + source/Irrlicht/OpenGL/Renderer2D.cpp | 83 + source/Irrlicht/OpenGL/Renderer2D.h | 33 + 15 files changed, 4791 insertions(+), 23 deletions(-) create mode 100644 source/Irrlicht/OpenGL/Common.h create mode 100644 source/Irrlicht/OpenGL/Driver.cpp create mode 100644 source/Irrlicht/OpenGL/Driver.h create mode 100644 source/Irrlicht/OpenGL/ExtensionHandler.cpp create mode 100644 source/Irrlicht/OpenGL/ExtensionHandler.h create mode 100644 source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp create mode 100644 source/Irrlicht/OpenGL/FixedPipelineRenderer.h create mode 100644 source/Irrlicht/OpenGL/MaterialRenderer.cpp create mode 100644 source/Irrlicht/OpenGL/MaterialRenderer.h create mode 100644 source/Irrlicht/OpenGL/Renderer2D.cpp create mode 100644 source/Irrlicht/OpenGL/Renderer2D.h diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 8dee4d1..3b5a736 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -47,6 +47,10 @@ namespace irr #ifdef _IRR_COMPILE_WITH_WEBGL1_ IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); #endif + + #ifdef ENABLE_OPENGL3 + IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + #endif } // end namespace video } // end namespace irr @@ -457,23 +461,10 @@ void CIrrDeviceSDL::createDriver() { switch(CreationParams.DriverType) { - case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS: - os::Printer::log("DIRECT3D8 Driver is no longer supported in Irrlicht. Try another one.", ELL_ERROR); - break; - - case video::EDT_DIRECT3D9: - #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_ - os::Printer::log("SDL device does not support DIRECT3D9 driver. Try another one.", ELL_ERROR); - #else - os::Printer::log("DIRECT3D9 Driver was not compiled into this dll. Try another one.", ELL_ERROR); - #endif // _IRR_COMPILE_WITH_DIRECT3D_9_ - - break; - case video::EDT_OPENGL: #ifdef _IRR_COMPILE_WITH_OPENGL_ ContextManager = new video::CSDLManager(this); - VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); + VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); #else os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); #endif diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 7b51145..b78410c 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -153,6 +153,8 @@ endif() # OpenGL +option(ENABLE_OPENGL3 "Enable OpenGL 3+" FALSE) + if(IOS OR ANDROID OR EMSCRIPTEN) set(ENABLE_OPENGL FALSE) else() @@ -383,6 +385,19 @@ add_library(IRRVIDEOOBJ OBJECT ${IRRIMAGEOBJ} ) +if(ENABLE_OPENGL3) + if (NOT USE_SDL2) + message(SEND_ERROR "OpenGL3 support requires SDL2") + endif() + target_sources(IRRVIDEOOBJ PUBLIC + OpenGL/Driver.cpp + OpenGL/ExtensionHandler.cpp + OpenGL/FixedPipelineRenderer.cpp + OpenGL/MaterialRenderer.cpp + OpenGL/Renderer2D.cpp + ) +endif() + add_library(IRRIOOBJ OBJECT CFileList.cpp CFileSystem.cpp @@ -405,6 +420,10 @@ add_library(IRROTHEROBJ OBJECT os.cpp ) +if(ENABLE_OPENGL3) + target_compile_definitions(IRROTHEROBJ PRIVATE ENABLE_OPENGL3) +endif() + if(ANDROID) target_sources(IRROTHEROBJ PRIVATE Android/CIrrDeviceAndroid.cpp diff --git a/source/Irrlicht/COGLESCoreExtensionHandler.h b/source/Irrlicht/COGLESCoreExtensionHandler.h index ce6ea1d..1b4a2bb 100644 --- a/source/Irrlicht/COGLESCoreExtensionHandler.h +++ b/source/Irrlicht/COGLESCoreExtensionHandler.h @@ -2,13 +2,10 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h -#ifndef __E_OGLES_CORE_EXTENSION_HANDLER_H_INCLUDED__ -#define __E_OGLES_CORE_EXTENSION_HANDLER_H_INCLUDED__ - +#pragma once // Can be included from different ES versions // (this is also the reason why this file is header-only as correct OGL ES headers have to be included first) -#if defined(_IRR_COMPILE_WITH_OGLES2_) || defined(_IRR_COMPILE_WITH_OGLES1_) #include "irrMath.h" #include "COpenGLCoreFeature.h" @@ -773,6 +770,3 @@ namespace video }; } } - -#endif // defined(_IRR_COMPILE_WITH_OGLES2_) || defined(_IRR_COMPILE_WITH_OGLES1_) -#endif // __E_OGLES_CORE_EXTENSION_HANDLER_H_INCLUDED__ diff --git a/source/Irrlicht/COpenGLCoreRenderTarget.h b/source/Irrlicht/COpenGLCoreRenderTarget.h index 0dd08eb..7dff3c9 100644 --- a/source/Irrlicht/COpenGLCoreRenderTarget.h +++ b/source/Irrlicht/COpenGLCoreRenderTarget.h @@ -351,10 +351,10 @@ protected: case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS: + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR); break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: diff --git a/source/Irrlicht/OpenGL/Common.h b/source/Irrlicht/OpenGL/Common.h new file mode 100644 index 0000000..3f71f65 --- /dev/null +++ b/source/Irrlicht/OpenGL/Common.h @@ -0,0 +1,36 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// 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 + +#define GL_GLEXT_PROTOTYPES +#include +#include + +namespace irr +{ +namespace video +{ + + // Forward declarations. + + class COpenGLCoreFeature; + + template + class COpenGLCoreTexture; + + template + class COpenGLCoreRenderTarget; + + template + class COpenGLCoreCacheHandler; + + class COpenGL3Driver; + typedef COpenGLCoreTexture COpenGL3Texture; + typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; + typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; + +} +} diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp new file mode 100644 index 0000000..7c13e7c --- /dev/null +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -0,0 +1,2876 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" +#include "CNullDriver.h" +#include "IContextManager.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreRenderTarget.h" +#include "COpenGLCoreCacheHandler.h" + +#include "MaterialRenderer.h" +#include "FixedPipelineRenderer.h" +#include "Renderer2D.h" + +#include "EVertexAttributes.h" +#include "CImage.h" +#include "os.h" + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ +#include "android_native_app_glue.h" +#endif + +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ + +COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : + CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), + Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), + MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), + CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), + OGLES2ShaderPath(params.OGLES2ShaderPath), + ColorFormat(ECF_R8G8B8), ContextManager(contextManager) +{ +#ifdef _DEBUG + setDebugName("Driver"); +#endif + + if (!ContextManager) + return; + + ContextManager->grab(); + ContextManager->generateSurface(); + ContextManager->generateContext(); + ExposedData = ContextManager->getContext(); + ContextManager->activateContext(ExposedData, false); + GL.LoadAllProcedures(ContextManager); +} + +COpenGL3Driver::~COpenGL3Driver() +{ + deleteMaterialRenders(); + + CacheHandler->getTextureCache().clear(); + + removeAllRenderTargets(); + deleteAllTextures(); + removeAllOcclusionQueries(); + removeAllHardwareBuffers(); + + delete MaterialRenderer2DTexture; + delete MaterialRenderer2DNoTexture; + delete CacheHandler; + + if (ContextManager) + { + ContextManager->destroyContext(); + ContextManager->destroySurface(); + ContextManager->terminate(); + ContextManager->drop(); + } +} + + bool COpenGL3Driver::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 COpenGL3CacheHandler(this); + + StencilBuffer = stencilBuffer; + + DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); +// DriverAttributes->setAttribute("MaxLights", MaxLights); + DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); +// DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes); +// DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers); +// DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets); + 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); + + UserClipPlane.reallocate(0); + + 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_GENERATE_MIPMAP_HINT, GL_NICEST); + glFrontFace(GL_CW); + + // 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 COpenGL3Driver::loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData) + { + io::path vsPath(OGLES2ShaderPath); + vsPath += vertexShaderName; + + io::path fsPath(OGLES2ShaderPath); + fsPath += fragmentShaderName; + + *vertexShaderData = 0; + *fragmentShaderData = 0; + + io::IReadFile* vsFile = FileSystem->createAndOpenFile(vsPath); + if ( !vsFile ) + { + core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n"); + warning += core::stringw(vsPath) + L"\n"; + warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; + os::Printer::log(warning.c_str(), ELL_WARNING); + return; + } + + io::IReadFile* fsFile = FileSystem->createAndOpenFile(fsPath); + if ( !fsFile ) + { + core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n"); + warning += core::stringw(fsPath) + L"\n"; + warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; + os::Printer::log(warning.c_str(), ELL_WARNING); + return; + } + + long size = vsFile->getSize(); + if (size) + { + *vertexShaderData = new c8[size+1]; + vsFile->read(*vertexShaderData, size); + (*vertexShaderData)[size] = 0; + } + + size = fsFile->getSize(); + if (size) + { + // if both handles are the same we must reset the file + if (fsFile == vsFile) + fsFile->seek(0); + + *fragmentShaderData = new c8[size+1]; + fsFile->read(*fragmentShaderData, size); + (*fragmentShaderData)[size] = 0; + } + + vsFile->drop(); + fsFile->drop(); + } + + void COpenGL3Driver::createMaterialRenderers() + { + // Create callbacks. + + COpenGL3MaterialSolidCB* SolidCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolid2CB* Solid2LayerCB = new COpenGL3MaterialSolid2CB(); + COpenGL3MaterialLightmapCB* LightmapCB = new COpenGL3MaterialLightmapCB(1.f); + COpenGL3MaterialLightmapCB* LightmapAddCB = new COpenGL3MaterialLightmapCB(1.f); + COpenGL3MaterialLightmapCB* LightmapM2CB = new COpenGL3MaterialLightmapCB(2.f); + COpenGL3MaterialLightmapCB* LightmapM4CB = new COpenGL3MaterialLightmapCB(4.f); + COpenGL3MaterialLightmapCB* LightmapLightingCB = new COpenGL3MaterialLightmapCB(1.f); + COpenGL3MaterialLightmapCB* LightmapLightingM2CB = new COpenGL3MaterialLightmapCB(2.f); + COpenGL3MaterialLightmapCB* LightmapLightingM4CB = new COpenGL3MaterialLightmapCB(4.f); + COpenGL3MaterialSolid2CB* DetailMapCB = new COpenGL3MaterialSolid2CB(); + COpenGL3MaterialReflectionCB* SphereMapCB = new COpenGL3MaterialReflectionCB(); + COpenGL3MaterialReflectionCB* Reflection2LayerCB = new COpenGL3MaterialReflectionCB(); + COpenGL3MaterialSolidCB* TransparentAddColorCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB* TransparentAlphaChannelCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB* TransparentAlphaChannelRefCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB* TransparentVertexAlphaCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialReflectionCB* TransparentReflection2LayerCB = new COpenGL3MaterialReflectionCB(); + COpenGL3MaterialOneTextureBlendCB* OneTextureBlendCB = new COpenGL3MaterialOneTextureBlendCB(); + + // Create built-in materials. + + core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + core::stringc FragmentShader = OGLES2ShaderPath + "Solid.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SolidCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid2.vsh"; + FragmentShader = OGLES2ShaderPath + "Solid2Layer.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Solid2LayerCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid2.vsh"; + FragmentShader = OGLES2ShaderPath + "LightmapModulate.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapCB, EMT_SOLID, 0); + + FragmentShader = OGLES2ShaderPath + "LightmapAdd.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapAddCB, EMT_SOLID, 0); + + FragmentShader = OGLES2ShaderPath + "LightmapModulate.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM2CB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM4CB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingCB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM2CB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM4CB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid2.vsh"; + FragmentShader = OGLES2ShaderPath + "DetailMap.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, DetailMapCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "SphereMap.vsh"; + FragmentShader = OGLES2ShaderPath + "SphereMap.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SphereMapCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; + FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Reflection2LayerCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid.vsh"; + FragmentShader = OGLES2ShaderPath + "Solid.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0); + + FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannel.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannelRef.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelRefCB, EMT_SOLID, 0); + + FragmentShader = OGLES2ShaderPath + "TransparentVertexAlpha.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; + FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentReflection2LayerCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + VertexShader = OGLES2ShaderPath + "Solid.vsh"; + FragmentShader = OGLES2ShaderPath + "OneTextureBlend.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, OneTextureBlendCB, EMT_ONETEXTURE_BLEND, 0); + + // Drop callbacks. + + SolidCB->drop(); + Solid2LayerCB->drop(); + LightmapCB->drop(); + LightmapAddCB->drop(); + LightmapM2CB->drop(); + LightmapM4CB->drop(); + LightmapLightingCB->drop(); + LightmapLightingM2CB->drop(); + LightmapLightingM4CB->drop(); + DetailMapCB->drop(); + SphereMapCB->drop(); + Reflection2LayerCB->drop(); + TransparentAddColorCB->drop(); + TransparentAlphaChannelCB->drop(); + TransparentAlphaChannelRefCB->drop(); + TransparentVertexAlphaCB->drop(); + TransparentReflection2LayerCB->drop(); + OneTextureBlendCB->drop(); + + // Create 2D material renderers + + c8* vs2DData = 0; + c8* fs2DData = 0; + loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D.fsh"), &vs2DData, &fs2DData); + MaterialRenderer2DTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, true); + delete[] vs2DData; + delete[] fs2DData; + vs2DData = 0; + fs2DData = 0; + + loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D_noTex.fsh"), &vs2DData, &fs2DData); + MaterialRenderer2DNoTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, false); + delete[] vs2DData; + delete[] fs2DData; + } + + bool COpenGL3Driver::setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture) + { + Material.TextureLayer[layerIdx].Texture = const_cast(texture); // function uses const-pointer for texture because all draw functions use const-pointers already + return CacheHandler->getTextureCache().set(0, texture); + } + + bool COpenGL3Driver::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 COpenGL3Driver::endScene() + { + CNullDriver::endScene(); + + glFlush(); + + if (ContextManager) + return ContextManager->swapBuffers(); + + return false; + } + + + //! Returns the transformation set by setTransform + const core::matrix4& COpenGL3Driver::getTransform(E_TRANSFORMATION_STATE state) const + { + return Matrices[state]; + } + + + //! sets transformation + void COpenGL3Driver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) + { + Matrices[state] = mat; + Transformation3DChanged = true; + } + + + bool COpenGL3Driver::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); + + const void *buffer = vertices; + size_t bufferSize = vertexSize * vertexCount; + + //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 < bufferSize) + { + newBuffer = true; + } + + glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + + // copy data to graphics card + if (!newBuffer) + glBufferSubData(GL_ARRAY_BUFFER, 0, bufferSize, buffer); + else + { + HWBuffer->vbo_verticesSize = bufferSize; + + if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) + glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_STATIC_DRAW); + else + glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_DYNAMIC_DRAW); + } + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); + } + + + bool COpenGL3Driver::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 COpenGL3Driver::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() + || !static_cast(HWBuffer)->vbo_indicesID) + { + + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + + if (!updateIndexHardwareBuffer((SHWBufferLink_opengl*)HWBuffer)) + return false; + } + } + + return true; + } + + + //! Create hardware buffer from meshbuffer + COpenGL3Driver::SHWBufferLink *COpenGL3Driver::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 COpenGL3Driver::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 COpenGL3Driver::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* COpenGL3Driver::addRenderTarget() + { + COpenGL3RenderTarget* renderTarget = new COpenGL3RenderTarget(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 COpenGL3Driver::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 (!primitiveCount || !vertexCount) + return; + + if (!checkPrimitiveCount(primitiveCount)) + return; + + CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + + setRenderStates3DMode(); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glEnableVertexAttribArray(EVA_NORMAL); + glEnableVertexAttribArray(EVA_TCOORD0); + + switch (vType) + { + case EVT_STANDARD: + if (vertices) + { + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Normal); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + } + else + { + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), 0); + glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex), buffer_offset(12)); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), buffer_offset(24)); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), buffer_offset(28)); + } + + break; + case EVT_2TCOORDS: + glEnableVertexAttribArray(EVA_TCOORD1); + + if (vertices) + { + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Normal); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); + glVertexAttribPointer(EVA_TCOORD1, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); + } + else + { + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(0)); + glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(12)); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex2TCoords), buffer_offset(24)); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(28)); + glVertexAttribPointer(EVA_TCOORD1, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(36)); + } + break; + case EVT_TANGENTS: + glEnableVertexAttribArray(EVA_TANGENT); + glEnableVertexAttribArray(EVA_BINORMAL); + + if (vertices) + { + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Normal); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); + glVertexAttribPointer(EVA_TANGENT, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Tangent); + glVertexAttribPointer(EVA_BINORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Binormal); + } + else + { + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(0)); + glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(12)); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertexTangents), buffer_offset(24)); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(28)); + glVertexAttribPointer(EVA_TANGENT, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(36)); + glVertexAttribPointer(EVA_BINORMAL, 3, GL_FLOAT, false, 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: + glDrawArrays(GL_POINTS, 0, primitiveCount); + break; + case scene::EPT_LINE_STRIP: + glDrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList); + break; + case scene::EPT_LINE_LOOP: + glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList); + break; + case scene::EPT_LINES: + glDrawElements(GL_LINES, primitiveCount*2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_STRIP: + glDrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_FAN: + glDrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLES: + glDrawElements((LastMaterial.Wireframe) ? GL_LINES : (LastMaterial.PointCloud) ? GL_POINTS : GL_TRIANGLES, primitiveCount*3, indexSize, indexList); + break; + default: + break; + } + + switch (vType) + { + case EVT_2TCOORDS: + glDisableVertexAttribArray(EVA_TCOORD1); + break; + case EVT_TANGENTS: + glDisableVertexAttribArray(EVA_TANGENT); + glDisableVertexAttribArray(EVA_BINORMAL); + break; + default: + break; + } + + glDisableVertexAttribArray(EVA_POSITION); + glDisableVertexAttribArray(EVA_NORMAL); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_TCOORD0); + } + + + void COpenGL3Driver::draw2DImage(const video::ITexture* texture, const core::position2d& destPos, + const core::rect& sourceRect, const core::rect* clipRect, SColor color, + bool useAlphaChannelOfTexture) + { + if (!texture) + return; + + if (!sourceRect.isValid()) + return; + + core::position2d targetPos(destPos); + 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); + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture )) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glEnableVertexAttribArray(EVA_TCOORD0); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_TCOORD0); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + + void COpenGL3Driver::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; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture )) + return; + + setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || + useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, + true, useAlphaChannelOfTexture); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + f32 left = (f32)destRect.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)destRect.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)destRect.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)destRect.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + u16 indices[] = { 0, 1, 2, 3 }; + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glEnableVertexAttribArray(EVA_TCOORD0); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_TCOORD0); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + + if (clipRect) + glDisable(GL_SCISSOR_TEST); + + testGLError(__LINE__); + } + + void COpenGL3Driver::draw2DImage(const video::ITexture* texture, u32 layer, bool flip) + { + if (!texture) + return; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture )) + return; + + setRenderStates2DMode(false, true, true); + + u16 quad2DIndices[] = { 0, 1, 2, 3 }; + S3DVertex quad2DVertices[4]; + + quad2DVertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); + quad2DVertices[1].Pos = core::vector3df(1.f, 1.f, 0.f); + quad2DVertices[2].Pos = core::vector3df(1.f, -1.f, 0.f); + quad2DVertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f); + + f32 modificator = (flip) ? 1.f : 0.f; + + quad2DVertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); + quad2DVertices[1].TCoords = core::vector2df(1.f, 0.f + modificator); + quad2DVertices[2].TCoords = core::vector2df(1.f, 1.f - modificator); + quad2DVertices[3].TCoords = core::vector2df(0.f, 1.f - modificator); + + quad2DVertices[0].Color = SColor(0xFFFFFFFF); + quad2DVertices[1].Color = SColor(0xFFFFFFFF); + quad2DVertices[2].Color = SColor(0xFFFFFFFF); + quad2DVertices[3].Color = SColor(0xFFFFFFFF); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glEnableVertexAttribArray(EVA_TCOORD0); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(quad2DVertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(quad2DVertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(quad2DVertices))[0].TCoords); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, quad2DIndices); + glDisableVertexAttribArray(EVA_TCOORD0); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + + void COpenGL3Driver::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 irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); + + core::array vtx(drawCount * 4); + core::array indices(drawCount * 6); + + for (u32 i = 0; i < drawCount; i++) + { + 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 + (s32)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 + (s32)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; + } + + 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) + 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. + // now draw it. + + core::rect tcoords; + tcoords.UpperLeftCorner.X = (((f32)sourcePos.X)) / texture->getOriginalSize().Width ; + tcoords.UpperLeftCorner.Y = (((f32)sourcePos.Y)) / texture->getOriginalSize().Height; + tcoords.LowerRightCorner.X = tcoords.UpperLeftCorner.X + ((f32)(sourceSize.Width) / texture->getOriginalSize().Width); + tcoords.LowerRightCorner.Y = tcoords.UpperLeftCorner.Y + ((f32)(sourceSize.Height) / texture->getOriginalSize().Height); + + const core::rect poss(targetPos, sourceSize); + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + vtx.push_back(S3DVertex(left, top, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); + vtx.push_back(S3DVertex(right, top, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); + vtx.push_back(S3DVertex(right, down, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); + vtx.push_back(S3DVertex(left, down, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); + + const u32 curPos = vtx.size() - 4; + indices.push_back(0 + curPos); + indices.push_back(1 + curPos); + indices.push_back(2 + curPos); + + indices.push_back(0 + curPos); + indices.push_back(2 + curPos); + indices.push_back(3 + curPos); + } + + if (vtx.size()) + { + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glEnableVertexAttribArray(EVA_TCOORD0); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &vtx[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &vtx[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &vtx[0].TCoords); + glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, indices.pointer()); + glDisableVertexAttribArray(EVA_TCOORD0); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + } + + + //! draws a set of 2d images, using a color and the alpha channel + void COpenGL3Driver::draw2DImageBatch(const video::ITexture* texture, + const core::position2d& pos, + const core::array >& sourceRects, + const core::array& indices, s32 kerningWidth, + const core::rect* clipRect, SColor color, + bool useAlphaChannelOfTexture) + { + if (!texture) + return; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + const core::dimension2du& ss = texture->getOriginalSize(); + core::position2d targetPos(pos); + // texcoords need to be flipped horizontally for RTTs + const bool isRTT = texture->isRenderTarget(); + const f32 invW = 1.f / static_cast(ss.Width); + const f32 invH = 1.f / static_cast(ss.Height); + + core::array vertices; + core::array quadIndices; + vertices.reallocate(indices.size()*4); + quadIndices.reallocate(indices.size()*3); + + for (u32 i = 0; i < indices.size(); ++i) + { + const s32 currentIndex = indices[i]; + if (!sourceRects[currentIndex].isValid()) + break; + + const core::rect tcoords( + sourceRects[currentIndex].UpperLeftCorner.X * invW, + (isRTT ? sourceRects[currentIndex].LowerRightCorner.Y : sourceRects[currentIndex].UpperLeftCorner.Y) * invH, + sourceRects[currentIndex].LowerRightCorner.X * invW, + (isRTT ? sourceRects[currentIndex].UpperLeftCorner.Y : sourceRects[currentIndex].LowerRightCorner.Y) * invH); + + const core::rect poss(targetPos, sourceRects[currentIndex].getSize()); + + f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + const u32 vstart = vertices.size(); + vertices.push_back(S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); + vertices.push_back(S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); + vertices.push_back(S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); + vertices.push_back(S3DVertex(left, down, 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); + + targetPos.X += sourceRects[currentIndex].getWidth(); + } + + if (vertices.size()) + { + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glEnableVertexAttribArray(EVA_TCOORD0); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &vertices[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &vertices[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &vertices[0].TCoords); + glDrawElements(GL_TRIANGLES, quadIndices.size(), GL_UNSIGNED_SHORT, quadIndices.pointer()); + glDisableVertexAttribArray(EVA_TCOORD0); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + if (clipRect) + glDisable(GL_SCISSOR_TEST); + + testGLError(__LINE__); + } + + + //! draw a 2d rectangle + void COpenGL3Driver::draw2DRectangle(SColor color, + const core::rect& position, + const core::rect* clip) + { + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, 0, 0); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + + //! draw an 2d rectangle + void COpenGL3Driver::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; + + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || + colorRightUp.getAlpha() < 255 || + colorLeftDown.getAlpha() < 255 || + colorRightDown.getAlpha() < 255, false, false); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, colorLeftUp, 0, 0); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, colorRightUp, 0, 0); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + + //! Draws a 2d line. + void COpenGL3Driver::draw2DLine(const core::position2d& start, + const core::position2d& end, SColor color) + { + if (start==end) + drawPixel(start.X, start.Y, color); + else + { + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + f32 startX = (f32)start.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 endX = (f32)end.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 startY = 2.f - (f32)start.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 endY = 2.f - (f32)end.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + u16 indices[] = {0, 1}; + S3DVertex vertices[2]; + vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + } + + + //! Draws a pixel + void COpenGL3Driver::drawPixel(u32 x, u32 y, const SColor &color) + { + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) + return; + + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + f32 X = (f32)x / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 Y = 2.f - (f32)y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[1]; + vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glDrawArrays(GL_POINTS, 0, 1); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + ITexture* COpenGL3Driver::createDeviceDependentTexture(const io::path& name, IImage* image) + { + core::array imageArray(1); + imageArray.push_back(image); + + COpenGL3Texture* texture = new COpenGL3Texture(name, imageArray, ETT_2D, this); + + return texture; + } + + ITexture* COpenGL3Driver::createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) + { + COpenGL3Texture* texture = new COpenGL3Texture(name, image, ETT_CUBEMAP, this); + + return texture; + } + + //! Sets a material. + void COpenGL3Driver::setMaterial(const SMaterial& material) + { + Material = material; + OverrideMaterial.apply(Material); + + for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) + { + CacheHandler->getTextureCache().set(i, material.getTexture(i)); + setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); + } + } + + //! prints error if an error happened. + bool COpenGL3Driver::testGLError(int code) + { +#ifdef _DEBUG + 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_OUT_OF_MEMORY: + os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif + } + + //! prints error if an error happened. + bool COpenGL3Driver::testEGLError() + { +#if defined(EGL_VERSION_1_0) && defined(_DEBUG) + EGLint g = eglGetError(); + switch (g) + { + case EGL_SUCCESS: + return false; + case EGL_NOT_INITIALIZED : + os::Printer::log("Not Initialized", ELL_ERROR); + break; + case EGL_BAD_ACCESS: + os::Printer::log("Bad Access", ELL_ERROR); + break; + case EGL_BAD_ALLOC: + os::Printer::log("Bad Alloc", ELL_ERROR); + break; + case EGL_BAD_ATTRIBUTE: + os::Printer::log("Bad Attribute", ELL_ERROR); + break; + case EGL_BAD_CONTEXT: + os::Printer::log("Bad Context", ELL_ERROR); + break; + case EGL_BAD_CONFIG: + os::Printer::log("Bad Config", ELL_ERROR); + break; + case EGL_BAD_CURRENT_SURFACE: + os::Printer::log("Bad Current Surface", ELL_ERROR); + break; + case EGL_BAD_DISPLAY: + os::Printer::log("Bad Display", ELL_ERROR); + break; + case EGL_BAD_SURFACE: + os::Printer::log("Bad Surface", ELL_ERROR); + break; + case EGL_BAD_MATCH: + os::Printer::log("Bad Match", ELL_ERROR); + break; + case EGL_BAD_PARAMETER: + os::Printer::log("Bad Parameter", ELL_ERROR); + break; + case EGL_BAD_NATIVE_PIXMAP: + os::Printer::log("Bad Native Pixmap", ELL_ERROR); + break; + case EGL_BAD_NATIVE_WINDOW: + os::Printer::log("Bad Native Window", ELL_ERROR); + break; + case EGL_CONTEXT_LOST: + os::Printer::log("Context Lost", ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif + } + + + void COpenGL3Driver::setRenderStates3DMode() + { + if ( LockRenderStateMode ) + return; + + if (CurrentRenderMode != ERM_3D) + { + // Reset Texture Stages + CacheHandler->setBlend(false); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + ResetRenderStates = true; + } + + if (ResetRenderStates || LastMaterial != Material) + { + // unset old material + + // unset last 3d material + if (CurrentRenderMode == ERM_2D && MaterialRenderer2DActive) + { + MaterialRenderer2DActive->OnUnsetMaterial(); + MaterialRenderer2DActive = 0; + } + else 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; + } + + //! Can be called by an IMaterialRenderer to make its work easier. + void COpenGL3Driver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates) + { + // ZBuffer + switch (material.ZBuffer) + { + case ECFN_DISABLED: + CacheHandler->setDepthTest(false); + break; + case ECFN_LESSEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LEQUAL); + break; + case ECFN_EQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_EQUAL); + break; + case ECFN_LESS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LESS); + break; + case ECFN_NOTEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NOTEQUAL); + break; + case ECFN_GREATEREQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GEQUAL); + break; + case ECFN_GREATER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GREATER); + break; + case ECFN_ALWAYS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_ALWAYS); + break; + case ECFN_NEVER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NEVER); + break; + default: + break; + } + + // ZWrite + if (getWriteZBuffer(material)) + { + CacheHandler->setDepthMask(true); + } + else + { + CacheHandler->setDepthMask(false); + } + + // Back face culling + if ((material.FrontfaceCulling) && (material.BackfaceCulling)) + { + CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK); + CacheHandler->setCullFace(true); + } + else if (material.BackfaceCulling) + { + CacheHandler->setCullFaceFunc(GL_BACK); + CacheHandler->setCullFace(true); + } + else if (material.FrontfaceCulling) + { + CacheHandler->setCullFaceFunc(GL_FRONT); + CacheHandler->setCullFace(true); + } + else + { + CacheHandler->setCullFace(false); + } + + // Color Mask + CacheHandler->setColorMask(material.ColorMask); + + // Blend Equation + if (material.BlendOperation == EBO_NONE) + CacheHandler->setBlend(false); + else + { + CacheHandler->setBlend(true); + + switch (material.BlendOperation) + { + case EBO_ADD: + CacheHandler->setBlendEquation(GL_FUNC_ADD); + break; + case EBO_SUBTRACT: + CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT); + break; + case EBO_REVSUBTRACT: + CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + 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); + + CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), + getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); + } + + // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. + + if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) + 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); + } + + // Texture parameters + setTextureRenderStates(material, resetAllRenderStates); + } + + //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. + void COpenGL3Driver::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) + { + const COpenGL3Texture* tmpTexture = CacheHandler->getTextureCache()[i]; + + if (!tmpTexture) + continue; + + GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); + + CacheHandler->setActiveTexture(GL_TEXTURE0 + i); + + if (resetAllRenderstates) + tmpTexture->getStatesCache().IsCached = false; + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || + material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, + (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); + + tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; + tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; + } + + if (material.UseMipMaps && tmpTexture->hasMipMaps()) + { + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || + material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || !tmpTexture->getStatesCache().MipMapStatus) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + material.TextureLayer[i].TrilinearFilter ? GL_LINEAR_MIPMAP_LINEAR : + material.TextureLayer[i].BilinearFilter ? GL_LINEAR_MIPMAP_NEAREST : + GL_NEAREST_MIPMAP_NEAREST); + + tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; + tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; + tmpTexture->getStatesCache().MipMapStatus = true; + } + } + else + { + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || + material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || tmpTexture->getStatesCache().MipMapStatus) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); + + tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; + tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; + tmpTexture->getStatesCache().MipMapStatus = false; + } + } + + #ifdef GL_EXT_texture_filter_anisotropic + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] && + (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter)) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, + material.TextureLayer[i].AnisotropicFilter>1 ? core::min_(MaxAnisotropy, material.TextureLayer[i].AnisotropicFilter) : 1); + + tmpTexture->getStatesCache().AnisotropicFilter = material.TextureLayer[i].AnisotropicFilter; + } + #endif + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapU != tmpTexture->getStatesCache().WrapU) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayer[i].TextureWrapU)); + tmpTexture->getStatesCache().WrapU = material.TextureLayer[i].TextureWrapU; + } + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapV != tmpTexture->getStatesCache().WrapV) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayer[i].TextureWrapV)); + tmpTexture->getStatesCache().WrapV = material.TextureLayer[i].TextureWrapV; + } + + tmpTexture->getStatesCache().IsCached = true; + } + } + + + // Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode. + GLint COpenGL3Driver::getTextureWrapMode(u8 clamp) const + { + switch (clamp) + { + case ETC_CLAMP: + case ETC_CLAMP_TO_EDGE: + case ETC_CLAMP_TO_BORDER: + return GL_CLAMP_TO_EDGE; + case ETC_MIRROR: + return GL_REPEAT; + default: + return GL_REPEAT; + } + } + + + //! sets the needed renderstates + void COpenGL3Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) + { + if ( LockRenderStateMode ) + return; + + COpenGL3Renderer2D* nextActiveRenderer = texture ? MaterialRenderer2DTexture : MaterialRenderer2DNoTexture; + + if (CurrentRenderMode != ERM_2D) + { + // unset last 3d material + if (CurrentRenderMode == ERM_3D) + { + if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + } + + CurrentRenderMode = ERM_2D; + } + else if ( MaterialRenderer2DActive && MaterialRenderer2DActive != nextActiveRenderer) + { + MaterialRenderer2DActive->OnUnsetMaterial(); + } + + MaterialRenderer2DActive = nextActiveRenderer; + + MaterialRenderer2DActive->OnSetMaterial(Material, LastMaterial, true, 0); + 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); + } + else + CacheHandler->setBlend(false); + + Material.setTexture(0, const_cast(CacheHandler->getTextureCache().get(0))); + setTransform(ETS_TEXTURE_0, core::IdentityMatrix); + + if (texture) + { + if (OverrideMaterial2DEnabled) + setTextureRenderStates(OverrideMaterial2D, false); + else + setTextureRenderStates(InitMaterial2D, false); + } + + MaterialRenderer2DActive->OnRender(this, video::EVT_STANDARD); + } + + + void COpenGL3Driver::chooseMaterial2D() + { + if (!OverrideMaterial2DEnabled) + Material = InitMaterial2D; + + if (OverrideMaterial2DEnabled) + { + OverrideMaterial2D.Lighting=false; + OverrideMaterial2D.ZWriteEnable=EZW_OFF; + OverrideMaterial2D.ZBuffer=ECFN_DISABLED; // it will be ECFN_DISABLED after merge + OverrideMaterial2D.Lighting=false; + + Material = OverrideMaterial2D; + } + } + + + //! \return Returns the name of the video driver. + const wchar_t* COpenGL3Driver::getName() const + { + return Name.c_str(); + } + + void COpenGL3Driver::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 COpenGL3Driver::setViewPortRaw(u32 width, u32 height) + { + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); + } + + + //! Draws a shadow volume into the stencil buffer. + void COpenGL3Driver::drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible) + { + const u32 count=triangles.size(); + if (!StencilBuffer || !count) + return; + + bool fog = Material.FogEnable; + bool lighting = Material.Lighting; + E_MATERIAL_TYPE materialType = Material.MaterialType; + + Material.FogEnable = false; + Material.Lighting = false; + Material.MaterialType = EMT_SOLID; // Dedicated material in future. + + setRenderStates3DMode(); + + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LESS); + CacheHandler->setDepthMask(false); + + if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY))) + { + CacheHandler->setColorMask(ECP_NONE); + glEnable(GL_STENCIL_TEST); + } + + glEnableVertexAttribArray(EVA_POSITION); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(core::vector3df), triangles.const_pointer()); + + glStencilMask(~0); + glStencilFunc(GL_ALWAYS, 0, ~0); + + GLenum decr = GL_DECR; + GLenum incr = GL_INCR; + +#if defined(GL_OES_stencil_wrap) + if (FeatureAvailable[IRR_OES_stencil_wrap]) + { + decr = GL_DECR_WRAP_OES; + incr = GL_INCR_WRAP_OES; + } +#endif + + CacheHandler->setCullFace(true); + + if (zfail) + { + CacheHandler->setCullFaceFunc(GL_FRONT); + glStencilOp(GL_KEEP, incr, GL_KEEP); + glDrawArrays(GL_TRIANGLES, 0, count); + + CacheHandler->setCullFaceFunc(GL_BACK); + glStencilOp(GL_KEEP, decr, GL_KEEP); + glDrawArrays(GL_TRIANGLES, 0, count); + } + else // zpass + { + CacheHandler->setCullFaceFunc(GL_BACK); + glStencilOp(GL_KEEP, GL_KEEP, incr); + glDrawArrays(GL_TRIANGLES, 0, count); + + CacheHandler->setCullFaceFunc(GL_FRONT); + glStencilOp(GL_KEEP, GL_KEEP, decr); + glDrawArrays(GL_TRIANGLES, 0, count); + } + + glDisableVertexAttribArray(EVA_POSITION); + + glDisable(GL_STENCIL_TEST); + + Material.FogEnable = fog; + Material.Lighting = lighting; + Material.MaterialType = materialType; + } + + + void COpenGL3Driver::drawStencilShadow(bool clearStencilBuffer, + video::SColor leftUpEdge, video::SColor rightUpEdge, + video::SColor leftDownEdge, video::SColor rightDownEdge) + { + if (!StencilBuffer) + return; + + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(true, false, false); + + CacheHandler->setDepthMask(false); + CacheHandler->setColorMask(ECP_ALL); + + CacheHandler->setBlend(true); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_NOTEQUAL, 0, ~0); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + + u16 indices[] = {0, 1, 2, 3}; + S3DVertex vertices[4]; + vertices[0] = S3DVertex(-1.f, 1.f, 0.9f, 0, 0, 1, leftDownEdge, 0, 0); + vertices[1] = S3DVertex(1.f, 1.f, 0.9f, 0, 0, 1, leftUpEdge, 0, 0); + vertices[2] = S3DVertex(1.f, -1.f, 0.9f, 0, 0, 1, rightUpEdge, 0, 0); + vertices[3] = S3DVertex(-1.f, -1.f, 0.9f, 0, 0, 1, rightDownEdge, 0, 0); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + + if (clearStencilBuffer) + glClear(GL_STENCIL_BUFFER_BIT); + + glDisable(GL_STENCIL_TEST); + } + + + //! Draws a 3d line. + void COpenGL3Driver::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); + + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, indices); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + + //! Only used by the internal engine. Used to notify the driver that + //! the window was resized. + void COpenGL3Driver::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 COpenGL3Driver::getDriverType() const + { + return EDT_OGLES2; + } + + + //! returns color format + ECOLOR_FORMAT COpenGL3Driver::getColorFormat() const + { + return ColorFormat; + } + + + //! Get a vertex shader constant index. + s32 COpenGL3Driver::getVertexShaderConstantID(const c8* name) + { + return getPixelShaderConstantID(name); + } + + //! Get a pixel shader constant index. + s32 COpenGL3Driver::getPixelShaderConstantID(const c8* name) + { + os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID()."); + return -1; + } + + //! Sets a vertex shader constant. + void COpenGL3Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + } + + //! Sets a pixel shader constant. + void COpenGL3Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + } + + //! Sets a constant for the vertex shader based on an index. + bool COpenGL3Driver::setVertexShaderConstant(s32 index, const f32* floats, int count) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; + } + + //! Int interface for the above. + bool COpenGL3Driver::setVertexShaderConstant(s32 index, const s32* ints, int count) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; + } + + bool COpenGL3Driver::setVertexShaderConstant(s32 index, const u32* ints, int count) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; + } + + //! Sets a constant for the pixel shader based on an index. + bool COpenGL3Driver::setPixelShaderConstant(s32 index, const f32* floats, int count) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; + } + + //! Int interface for the above. + bool COpenGL3Driver::setPixelShaderConstant(s32 index, const s32* ints, int count) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; + } + + bool COpenGL3Driver::setPixelShaderConstant(s32 index, const u32* ints, int count) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; + } + + //! Adds a new material renderer to the VideoDriver, using pixel and/or + //! vertex shaders to render geometry. + s32 COpenGL3Driver::addShaderMaterial(const c8* vertexShaderProgram, + const c8* pixelShaderProgram, + IShaderConstantSetCallBack* callback, + E_MATERIAL_TYPE baseMaterial, s32 userData) + { + os::Printer::log("No shader support."); + return -1; + } + + + //! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. + s32 COpenGL3Driver::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) + { + s32 nr = -1; + COpenGL3MaterialRenderer* r = new COpenGL3MaterialRenderer( + this, nr, vertexShaderProgram, + pixelShaderProgram, + callback, baseMaterial, userData); + + r->drop(); + return nr; + } + + //! Returns a pointer to the IVideoDriver interface. (Implementation for + //! IMaterialRendererServices) + IVideoDriver* COpenGL3Driver::getVideoDriver() + { + return this; + } + + + //! Returns pointer to the IGPUProgrammingServices interface. + IGPUProgrammingServices* COpenGL3Driver::getGPUProgrammingServices() + { + return this; + } + + ITexture* COpenGL3Driver::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); + + COpenGL3Texture* renderTargetTexture = new COpenGL3Texture(name, size, ETT_2D, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + //restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; + } + + ITexture* COpenGL3Driver::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); + } + + COpenGL3Texture* renderTargetTexture = new COpenGL3Texture(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 COpenGL3Driver::getMaximalPrimitiveCount() const + { + return 65535; + } + + bool COpenGL3Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) + { + if (target && target->getDriverType() != EDT_OGLES2 && target->getDriverType() != EDT_WEBGL1) + { + os::Printer::log("Fatal Error: Tried to set a render target not owned by OGLES2 driver.", ELL_ERROR); + return false; + } + + core::dimension2d destRenderTargetSize(0, 0); + + if (target) + { + COpenGL3RenderTarget* renderTarget = static_cast(target); + + CacheHandler->setFBO(renderTarget->getBufferID()); + renderTarget->update(); + + destRenderTargetSize = renderTarget->getSize(); + + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); + } + else + { + CacheHandler->setFBO(0); + + destRenderTargetSize = core::dimension2d(0, 0); + + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); + } + + if (CurrentRenderTargetSize != destRenderTargetSize) + { + CurrentRenderTargetSize = destRenderTargetSize; + + Transformation3DChanged = true; + } + + CurrentRenderTarget = target; + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; + } + + void COpenGL3Driver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) + { + GLbitfield mask = 0; + u8 colorMask = 0; + bool depthMask = false; + + CacheHandler->getColorMask(colorMask); + CacheHandler->getDepthMask(depthMask); + + if (flag & ECBF_COLOR) + { + CacheHandler->setColorMask(ECP_ALL); + + 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) + { + CacheHandler->setDepthMask(true); + glClearDepthf(depth); + mask |= GL_DEPTH_BUFFER_BIT; + } + + if (flag & ECBF_STENCIL) + { + glClearStencil(stencil); + mask |= GL_STENCIL_BUFFER_BIT; + } + + if (mask) + glClear(mask); + + CacheHandler->setColorMask(colorMask); + CacheHandler->setDepthMask(depthMask); + } + + + //! 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* COpenGL3Driver::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; + { +// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat); +// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); + // there's a format we don't support ATM + if (GL_UNSIGNED_SHORT_4_4_4_4 == type) + { + internalformat = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } + } + + IImage* newImage = 0; + if (GL_RGBA == internalformat) + { + 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); + } + + if (!newImage) + return 0; + + u8* pixels = static_cast(newImage->getData()); + if (!pixels) + { + newImage->drop(); + return 0; + } + + glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); + testGLError(__LINE__); + + // 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; + + // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) + if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) + { + pixels = static_cast(newImage->getData()); + for (u32 i = 0; i < ScreenSize.Height; i++) + { + for (u32 j = 0; j < ScreenSize.Width; j++) + { + u32 c = *(u32*) (pixels + 4 * j); + *(u32*) (pixels + 4 * j) = (c & 0xFF00FF00) | + ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16); + } + pixels += pitch; + } + } + + if (testGLError(__LINE__)) + { + newImage->drop(); + return 0; + } + testGLError(__LINE__); + return newImage; + } + + void COpenGL3Driver::removeTexture(ITexture* texture) + { + CacheHandler->getTextureCache().remove(texture); + CNullDriver::removeTexture(texture); + } + + //! Set/unset a clipping plane. + bool COpenGL3Driver::setClipPlane(u32 index, const core::plane3df& plane, bool enable) + { + if (index >= UserClipPlane.size()) + UserClipPlane.push_back(SUserClipPlane()); + + UserClipPlane[index].Plane = plane; + UserClipPlane[index].Enabled = enable; + return true; + } + + //! Enable/disable a clipping plane. + void COpenGL3Driver::enableClipPlane(u32 index, bool enable) + { + UserClipPlane[index].Enabled = enable; + } + + //! Get the ClipPlane Count + u32 COpenGL3Driver::getClipPlaneCount() const + { + return UserClipPlane.size(); + } + + const core::plane3df& COpenGL3Driver::getClipPlane(irr::u32 index) const + { + if (index < UserClipPlane.size()) + return UserClipPlane[index].Plane; + else + { + _IRR_DEBUG_BREAK_IF(true) // invalid index + static const core::plane3df dummy; + return dummy; + } + } + + core::dimension2du COpenGL3Driver::getMaxTextureSize() const + { + return core::dimension2du(MaxTextureSize, MaxTextureSize); + } + + GLenum COpenGL3Driver::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 COpenGL3Driver::getZBufferBits() const + { + // TODO: never used, so not sure what this was really about (zbuffer used by device? Or for RTT's?) + + 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 COpenGL3Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, + GLenum& pixelType, void(**converter)(const void*, s32, void*)) const + { + bool supported = false; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_BYTE; + *converter = 0; + + switch (format) + { + case ECF_A1R5G5B5: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_SHORT_5_5_5_1; + *converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1; + break; + case ECF_R5G6B5: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_UNSIGNED_SHORT_5_6_5; + break; + case ECF_R8G8B8: + supported = true; + 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)) + { + pixelFormat = GL_BGRA; + } + else + { + pixelFormat = GL_RGBA; + *converter = CColorConverter::convert_A8R8G8B8toA8B8G8R8; + } + pixelType = GL_UNSIGNED_BYTE; + break; +#ifdef GL_EXT_texture_compression_s3tc + case ECF_DXT1: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + break; +#endif +#ifdef GL_EXT_texture_compression_s3tc + case ECF_DXT2: + case ECF_DXT3: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; +#endif +#ifdef GL_EXT_texture_compression_s3tc + case ECF_DXT4: + case ECF_DXT5: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; +#endif +#ifdef GL_IMG_texture_compression_pvrtc + case ECF_PVRTC_RGB2: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; + break; +#endif +#ifdef GL_IMG_texture_compression_pvrtc + case ECF_PVRTC_ARGB2: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + break; +#endif +#ifdef GL_IMG_texture_compression_pvrtc + case ECF_PVRTC_RGB4: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; + break; +#endif +#ifdef GL_IMG_texture_compression_pvrtc + case ECF_PVRTC_ARGB4: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + break; +#endif +#ifdef GL_IMG_texture_compression_pvrtc2 + case ECF_PVRTC2_ARGB2: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG; + break; +#endif +#ifdef GL_IMG_texture_compression_pvrtc2 + case ECF_PVRTC2_ARGB4: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG; + break; +#endif +#ifdef GL_OES_compressed_ETC1_RGB8_texture + case ECF_ETC1: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_ETC1_RGB8_OES; + break; +#endif +#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available + case ECF_ETC2_RGB: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_COMPRESSED_RGB8_ETC2; + break; +#endif +#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available + case ECF_ETC2_ARGB: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA8_ETC2_EAC; + break; +#endif + case ECF_D16: + supported = true; + 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; + 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; + pixelFormat = GL_DEPTH_STENCIL_OES; + pixelType = GL_UNSIGNED_INT_24_8_OES; + } +#endif + break; + case ECF_R8: +#if defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg)) + { + supported = true; + pixelFormat = GL_RED_EXT; + pixelType = GL_UNSIGNED_BYTE; + } +#endif + break; + case ECF_R8G8: +#if defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg)) + { + supported = true; + pixelFormat = GL_RG_EXT; + pixelType = GL_UNSIGNED_BYTE; + } +#endif + break; + case ECF_R16: + break; + case ECF_R16G16: + break; + case ECF_R16F: +#if defined(GL_OES_texture_half_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float) + ) + { + supported = true; + pixelFormat = GL_RED_EXT; + pixelType = GL_HALF_FLOAT_OES ; + } +#endif + break; + case ECF_G16R16F: +#if defined(GL_OES_texture_half_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float) + ) + { + supported = true; + pixelFormat = GL_RG_EXT; + pixelType = GL_HALF_FLOAT_OES ; + } +#endif + break; + case ECF_A16B16G16R16F: +#if defined(GL_OES_texture_half_float) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)) + { + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_HALF_FLOAT_OES ; + } +#endif + break; + case ECF_R32F: +#if defined(GL_OES_texture_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float) + ) + { + supported = true; + pixelFormat = GL_RED_EXT; + pixelType = GL_FLOAT; + } +#endif + break; + case ECF_G32R32F: +#if defined(GL_OES_texture_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float) + ) + { + supported = true; + pixelFormat = GL_RG_EXT; + pixelType = GL_FLOAT; + } +#endif + break; + case ECF_A32B32G32R32F: +#if defined(GL_OES_texture_float) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)) + { + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_FLOAT ; + } +#endif + break; + default: + break; + } + + // ES 2.0 says internalFormat must match pixelFormat (chapter 3.7.1 in Spec). + // Doesn't mention if "match" means "equal" or some other way of matching, but + // some bug on Emscripten and browsing discussions by others lead me to believe + // it means they have to be equal. Note that this was different in OpenGL. + internalFormat = pixelFormat; + +#ifdef _IRR_IOS_PLATFORM_ + if (internalFormat == GL_BGRA) + internalFormat = GL_RGBA; +#endif + + return supported; + } + + bool COpenGL3Driver::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 COpenGL3Driver::needsTransparentRenderPass(const irr::video::SMaterial& material) const + { + return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); + } + + const SMaterial& COpenGL3Driver::getCurrentMaterial() const + { + return Material; + } + + COpenGL3CacheHandler* COpenGL3Driver::getCacheHandler() const + { + return CacheHandler; + } + + +IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) +{ + COpenGL3Driver* driver = new COpenGL3Driver(params, io, contextManager); + driver->genericDriverInit(params.WindowSize, params.Stencilbuffer); // don't call in constructor, it uses virtual function calls of driver + return driver; +} + +} // end namespace +} // end namespace diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h new file mode 100644 index 0000000..dd2ad89 --- /dev/null +++ b/source/Irrlicht/OpenGL/Driver.h @@ -0,0 +1,403 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// 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" + +#include "Common.h" +#include "CNullDriver.h" +#include "IMaterialRendererServices.h" +#include "EDriverFeatures.h" +#include "fast_atof.h" +#include "ExtensionHandler.h" +#include "IContextManager.h" + +namespace irr +{ +namespace video +{ + + class COpenGL3FixedPipelineRenderer; + class COpenGL3Renderer2D; + + class COpenGL3Driver : public CNullDriver, public IMaterialRendererServices, public COpenGL3ExtensionHandler + { + friend class COpenGLCoreTexture; + friend IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + + protected: + //! constructor (use createOpenGL3Driver instead) + COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + + public: + + //! destructor + virtual ~COpenGL3Driver(); + + 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) + , vbo_verticesSize(0), vbo_indicesSize(0) + {} + + u32 vbo_verticesID; //tmp + u32 vbo_indicesID; //tmp + + u32 vbo_verticesSize; //tmp + u32 vbo_indicesSize; //tmp + }; + + bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + + //! updates hardware buffer if needed + 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; + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override + { + return FeatureEnabled[feature] && COpenGL3ExtensionHandler::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; + + // internally used + virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip); + + //! draws a set of 2d images + virtual void draw2DImageBatch(const video::ITexture* texture, + const core::position2d& pos, + const core::array >& sourceRects, + const core::array& indices, s32 kerningWidth = 0, + const core::rect* clipRect = 0, + SColor color = SColor(255, 255, 255, 255), + bool useAlphaChannelOfTexture = false) override; + + void draw2DImageBatch(const video::ITexture* texture, + const core::array >& positions, + const core::array >& sourceRects, + const core::rect* clipRect, + SColor color, + bool useAlphaChannelOfTexture) 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 single pixel + void drawPixel(u32 x, u32 y, const SColor & color) override; + + //! Draws a 3d line. + virtual void draw3DLine(const core::vector3df& start, + const core::vector3df& end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a pixel +// virtual void drawPixel(u32 x, u32 y, const SColor & color); + + //! Returns the name of the video driver. + const wchar_t* getName() const override; + + //! Returns the maximum texture size supported. + core::dimension2du getMaxTextureSize() const override; + + //! Draws a shadow volume into the stencil buffer. + void drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible=0) override; + + //! Fills the stencil shadow with color. + virtual void drawStencilShadow(bool clearStencilBuffer=false, + video::SColor leftUpEdge = video::SColor(0,0,0,0), + video::SColor rightUpEdge = video::SColor(0,0,0,0), + video::SColor leftDownEdge = video::SColor(0,0,0,0), + video::SColor rightDownEdge = video::SColor(0,0,0,0)) override; + + //! sets a viewport + void setViewPort(const core::rect& area) 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. + 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. + 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 vertex shader constant. + void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1) override; + + //! Sets a pixel shader constant. + void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1) 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 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram, + IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData) override; + + //! Adds a new material renderer to the VideoDriver + virtual s32 addHighLevelShaderMaterial( + const c8* vertexShaderProgram, + const c8* vertexShaderEntryPointName = 0, + E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, + const c8* pixelShaderProgram = 0, + const c8* pixelShaderEntryPointName = 0, + E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, + const c8* geometryShaderProgram = 0, + const c8* geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack* callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData=0) 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); + + //! checks if an OGLES1 error has happened and prints it + bool testEGLError(); + + //! Set/unset a clipping plane. + bool setClipPlane(u32 index, const core::plane3df& plane, bool enable = false) override; + + //! returns the current amount of user clip planes set. + u32 getClipPlaneCount() const; + + //! returns the 0 indexed Plane + const core::plane3df& getClipPlane(u32 index) const; + + //! Enable/disable a clipping plane. + void enableClipPlane(u32 index, bool enable) override; + + //! Returns the graphics card vendor name. + core::stringc getVendorInfo() override + { + return VendorName; + }; + + 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. + virtual GLenum getZBufferBits() const; + + virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, + GLenum& pixelType, void(**converter)(const void*, s32, void*)) const; + + //! Get current material. + const SMaterial& getCurrentMaterial() const; + + COpenGL3CacheHandler* getCacheHandler() const; + + protected: + //! inits the opengl-es driver + virtual bool genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer); + + void chooseMaterial2D(); + + ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; + + ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) override; + + //! Map Irrlicht wrap mode to OpenGL enum + GLint getTextureWrapMode(u8 clamp) const; + + //! sets the needed renderstates + void setRenderStates3DMode(); + + //! sets the needed renderstates + void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel); + + //! Prevent setRenderStateMode calls to do anything. + // hack to allow drawing meshbuffers in 2D mode. + // Better solution would be passing this flag through meshbuffers, + // but the way this is currently implemented in Irrlicht makes this tricky to implement + void lockRenderStateMode() + { + LockRenderStateMode = true; + } + + //! Allow setRenderStateMode calls to work again + void unlockRenderStateMode() + { + LockRenderStateMode = false; + } + + void draw2D3DVertexPrimitiveList(const void* vertices, + u32 vertexCount, const void* indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, + E_INDEX_TYPE iType, bool is3D); + + void createMaterialRenderers(); + + void loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData); + + bool setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture); + + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + + COpenGL3CacheHandler* CacheHandler; + core::stringw Name; + core::stringc VendorName; + SIrrlichtCreationParameters Params; + + //! bool to make all renderstates reset if set to true. + bool ResetRenderStates; + bool LockRenderStateMode; + u8 AntiAlias; + + struct SUserClipPlane + { + core::plane3df Plane; + bool Enabled; + }; + + core::array UserClipPlane; + + core::matrix4 TextureFlipMatrix; + +private: + + COpenGL3Renderer2D* MaterialRenderer2DActive; + COpenGL3Renderer2D* MaterialRenderer2DTexture; + COpenGL3Renderer2D* MaterialRenderer2DNoTexture; + + core::matrix4 Matrices[ETS_COUNT]; + + //! 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 Transformation3DChanged; + irr::io::path OGLES2ShaderPath; + + SMaterial Material, LastMaterial; + + //! Color buffer format + ECOLOR_FORMAT ColorFormat; + + IContextManager* ContextManager; + }; + +} // end namespace video +} // end namespace irr diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp new file mode 100644 index 0000000..297aa94 --- /dev/null +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2015 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// 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 "ExtensionHandler.h" + +#include "irrString.h" +#include "SMaterial.h" +#include "fast_atof.h" + +namespace irr +{ +namespace video +{ + void COpenGL3ExtensionHandler::initExtensions() + { + getGLVersion(); + + getGLExtensions(); + + GLint val=0; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_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; + } + +} // end namespace video +} // end namespace irr diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h new file mode 100644 index 0000000..1e6bd7f --- /dev/null +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -0,0 +1,187 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2015 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "EDriverFeatures.h" +#include "irrTypes.h" +#include "os.h" + +#include "Common.h" + +#include "COGLESCoreExtensionHandler.h" + +namespace irr +{ +namespace video +{ + + class COpenGL3ExtensionHandler : public COGLESCoreExtensionHandler + { + public: + COpenGL3ExtensionHandler() : COGLESCoreExtensionHandler() {} + + 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_MIP_MAP_AUTO_UPDATE: + case EVDF_VERTEX_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_2: + case EVDF_PIXEL_SHADER_2_0: + case EVDF_VERTEX_SHADER_2_0: + case EVDF_ARB_GLSL: + case EVDF_TEXTURE_NSQUARE: + case EVDF_TEXTURE_NPOT: + case EVDF_FRAMEBUFFER_OBJECT: + case EVDF_VERTEX_BUFFER_OBJECT: + case EVDF_COLOR_MASK: + case EVDF_ALPHA_TO_COVERAGE: + case EVDF_POLYGON_OFFSET: + case EVDF_BLEND_OPERATIONS: + case EVDF_BLEND_SEPARATE: + case EVDF_TEXTURE_MATRIX: + case EVDF_TEXTURE_CUBEMAP: + return true; + case EVDF_ARB_VERTEX_PROGRAM_1: + case EVDF_ARB_FRAGMENT_PROGRAM_1: + case EVDF_GEOMETRY_SHADER: + case EVDF_MULTIPLE_RENDER_TARGETS: + case EVDF_MRT_BLEND: + case EVDF_MRT_COLOR_MASK: + case EVDF_MRT_BLEND_FUNC: + case EVDF_OCCLUSION_QUERY: + return false; + case EVDF_TEXTURE_COMPRESSED_DXT: + return false; // NV Tegra need improvements here + case EVDF_TEXTURE_COMPRESSED_PVRTC: + return FeatureAvailable[IRR_GL_IMG_texture_compression_pvrtc]; + case EVDF_TEXTURE_COMPRESSED_PVRTC2: + return FeatureAvailable[IRR_GL_IMG_texture_compression_pvrtc2]; + case EVDF_TEXTURE_COMPRESSED_ETC1: + return FeatureAvailable[IRR_GL_OES_compressed_ETC1_RGB8_texture]; + case EVDF_TEXTURE_COMPRESSED_ETC2: + return false; + case EVDF_STENCIL_BUFFER: + return StencilBuffer; + default: + return false; + }; + } + + 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) + { + glUseProgram(prog); + } + + inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) + { + glBindFramebuffer(target, framebuffer); + } + + inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) + { + glDeleteFramebuffers(n, framebuffers); + } + + inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) + { + glGenFramebuffers(n, framebuffers); + } + + inline GLenum irrGlCheckFramebufferStatus(GLenum target) + { + return glCheckFramebufferStatus(target); + } + + inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) + { + glFramebufferTexture2D(target, attachment, textarget, texture, level); + } + + inline void irrGlGenerateMipmap(GLenum target) + { + glGenerateMipmap(target); + } + + inline void irrGlActiveStencilFace(GLenum face) + { + } + + inline void irrGlDrawBuffer(GLenum mode) + { + } + + inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) + { + } + + inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) + { + glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + } + + inline void irrGlBlendEquation(GLenum mode) + { + glBlendEquation(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) + { + } + }; + +} +} diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp new file mode 100644 index 0000000..4a20f02 --- /dev/null +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp @@ -0,0 +1,334 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "FixedPipelineRenderer.h" + +#include "IVideoDriver.h" + +namespace irr +{ +namespace video +{ + +// Base callback + +COpenGL3MaterialBaseCB::COpenGL3MaterialBaseCB() : + FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1), GlobalAmbientID(-1), MaterialAmbientID(-1), MaterialDiffuseID(-1), MaterialEmissiveID(-1), MaterialSpecularID(-1), MaterialShininessID(-1), + FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1), + FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)), + MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f) +{ +} + +void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial& material) +{ + LightEnable = material.Lighting; + MaterialAmbient = SColorf(material.AmbientColor); + MaterialDiffuse = SColorf(material.DiffuseColor); + MaterialEmissive = SColorf(material.EmissiveColor); + MaterialSpecular = SColorf(material.SpecularColor); + MaterialShininess = material.Shininess; + + FogEnable = material.FogEnable ? 1 : 0; + + Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; +} + +void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdateBase) + { + WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix"); + WVMatrixID = services->getVertexShaderConstantID("uWVMatrix"); + NMatrixID = services->getVertexShaderConstantID("uNMatrix"); + GlobalAmbientID = services->getVertexShaderConstantID("uGlobalAmbient"); + MaterialAmbientID = services->getVertexShaderConstantID("uMaterialAmbient"); + MaterialDiffuseID = services->getVertexShaderConstantID("uMaterialDiffuse"); + MaterialEmissiveID = services->getVertexShaderConstantID("uMaterialEmissive"); + MaterialSpecularID = services->getVertexShaderConstantID("uMaterialSpecular"); + MaterialShininessID = services->getVertexShaderConstantID("uMaterialShininess"); + FogEnableID = services->getVertexShaderConstantID("uFogEnable"); + FogTypeID = services->getVertexShaderConstantID("uFogType"); + FogColorID = services->getVertexShaderConstantID("uFogColor"); + FogStartID = services->getVertexShaderConstantID("uFogStart"); + FogEndID = services->getVertexShaderConstantID("uFogEnd"); + FogDensityID = services->getVertexShaderConstantID("uFogDensity"); + ThicknessID = services->getVertexShaderConstantID("uThickness"); + + FirstUpdateBase = false; + } + + const core::matrix4 W = driver->getTransform(ETS_WORLD); + const core::matrix4 V = driver->getTransform(ETS_VIEW); + const core::matrix4 P = driver->getTransform(ETS_PROJECTION); + + core::matrix4 Matrix = P * V * W; + services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16); + + Matrix = V * W; + services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16); + + Matrix.makeInverse(); + services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16); + + services->setPixelShaderConstant(FogEnableID, &FogEnable, 1); + + if (FogEnable) + { + SColor TempColor(0); + E_FOG_TYPE TempType = EFT_FOG_LINEAR; + bool TempPerFragment = false; + bool TempRange = false; + + driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange); + + FogType = (s32)TempType; + FogColor = SColorf(TempColor); + + services->setPixelShaderConstant(FogTypeID, &FogType, 1); + services->setPixelShaderConstant(FogColorID, reinterpret_cast(&FogColor), 4); + services->setPixelShaderConstant(FogStartID, &FogStart, 1); + services->setPixelShaderConstant(FogEndID, &FogEnd, 1); + services->setPixelShaderConstant(FogDensityID, &FogDensity, 1); + } + + services->setPixelShaderConstant(ThicknessID, &Thickness, 1); +} + +// EMT_SOLID + EMT_TRANSPARENT_ADD_COLOR + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA + +COpenGL3MaterialSolidCB::COpenGL3MaterialSolidCB() : + FirstUpdate(true), TMatrix0ID(-1), AlphaRefID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), AlphaRef(0.5f), TextureUsage0(0), TextureUnit0(0) +{ +} + +void COpenGL3MaterialSolidCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + AlphaRef = material.MaterialTypeParam; + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; +} + +void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + AlphaRefID = services->getVertexShaderConstantID("uAlphaRef"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(AlphaRefID, &AlphaRef, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); +} + +// EMT_SOLID_2_LAYER + EMT_DETAIL_MAP + +COpenGL3MaterialSolid2CB::COpenGL3MaterialSolid2CB() : + FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), + TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) +{ +} + +void COpenGL3MaterialSolid2CB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; + TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; +} + +void COpenGL3MaterialSolid2CB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + Matrix = driver->getTransform(ETS_TEXTURE_1); + services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); + services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); +} + +// EMT_LIGHTMAP + EMT_LIGHTMAP_ADD + EMT_LIGHTMAP_M2 + EMT_LIGHTMAP_M4 + +COpenGL3MaterialLightmapCB::COpenGL3MaterialLightmapCB(float modulate) : + FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), ModulateID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), + Modulate(modulate), TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) +{ +} + +void COpenGL3MaterialLightmapCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; + TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; +} + +void COpenGL3MaterialLightmapCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); + ModulateID = services->getVertexShaderConstantID("uModulate"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + Matrix = driver->getTransform(ETS_TEXTURE_1); + services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(ModulateID, &Modulate, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); + services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); +} + +// EMT_SPHERE_MAP + EMT_REFLECTION_2_LAYER + EMT_TRANSPARENT_REFLECTION_2_LAYER + +COpenGL3MaterialReflectionCB::COpenGL3MaterialReflectionCB() : + FirstUpdate(true), TMatrix0ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), + TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) +{ +} + +void COpenGL3MaterialReflectionCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; + TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; +} + +void COpenGL3MaterialReflectionCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); + services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); +} + +// EMT_ONETEXTURE_BLEND + +COpenGL3MaterialOneTextureBlendCB::COpenGL3MaterialOneTextureBlendCB() : + FirstUpdate(true), TMatrix0ID(-1), BlendTypeID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), BlendType(0), TextureUsage0(0), TextureUnit0(0) +{ +} + +void COpenGL3MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + BlendType = 0; + + E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) + { + if (alphaSource == EAS_VERTEX_COLOR) + { + BlendType = 1; + } + else if (alphaSource == EAS_TEXTURE) + { + BlendType = 2; + } + } + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; +} + +void COpenGL3MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + BlendTypeID = services->getVertexShaderConstantID("uBlendType"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(BlendTypeID, &BlendType, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); +} + +} +} diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h new file mode 100644 index 0000000..4a9bb95 --- /dev/null +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h @@ -0,0 +1,180 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "IShaderConstantSetCallBack.h" +#include "IMaterialRendererServices.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3MaterialBaseCB : public IShaderConstantSetCallBack +{ +public: + COpenGL3MaterialBaseCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdateBase; + + s32 WVPMatrixID; + s32 WVMatrixID; + s32 NMatrixID; + + s32 GlobalAmbientID; + s32 MaterialAmbientID; + s32 MaterialDiffuseID; + s32 MaterialEmissiveID; + s32 MaterialSpecularID; + s32 MaterialShininessID; + + s32 FogEnableID; + s32 FogTypeID; + s32 FogColorID; + s32 FogStartID; + s32 FogEndID; + s32 FogDensityID; + + s32 ThicknessID; + + bool LightEnable; + SColorf GlobalAmbient; + SColorf MaterialAmbient; + SColorf MaterialDiffuse; + SColorf MaterialEmissive; + SColorf MaterialSpecular; + f32 MaterialShininess; + + s32 FogEnable; + s32 FogType; + SColorf FogColor; + f32 FogStart; + f32 FogEnd; + f32 FogDensity; + + f32 Thickness; +}; + +class COpenGL3MaterialSolidCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialSolidCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 AlphaRefID; + s32 TextureUsage0ID; + s32 TextureUnit0ID; + + f32 AlphaRef; + s32 TextureUsage0; + s32 TextureUnit0; +}; + +class COpenGL3MaterialSolid2CB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialSolid2CB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 TMatrix1ID; + s32 TextureUsage0ID; + s32 TextureUsage1ID; + s32 TextureUnit0ID; + s32 TextureUnit1ID; + + s32 TextureUsage0; + s32 TextureUsage1; + s32 TextureUnit0; + s32 TextureUnit1; +}; + +class COpenGL3MaterialLightmapCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialLightmapCB(float modulate); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 TMatrix1ID; + s32 ModulateID; + s32 TextureUsage0ID; + s32 TextureUsage1ID; + s32 TextureUnit0ID; + s32 TextureUnit1ID; + + f32 Modulate; + s32 TextureUsage0; + s32 TextureUsage1; + s32 TextureUnit0; + s32 TextureUnit1; +}; + +class COpenGL3MaterialReflectionCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialReflectionCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 TextureUsage0ID; + s32 TextureUsage1ID; + s32 TextureUnit0ID; + s32 TextureUnit1ID; + + s32 TextureUsage0; + s32 TextureUsage1; + s32 TextureUnit0; + s32 TextureUnit1; +}; + +class COpenGL3MaterialOneTextureBlendCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialOneTextureBlendCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 BlendTypeID; + s32 TextureUsage0ID; + s32 TextureUnit0ID; + + s32 BlendType; + s32 TextureUsage0; + s32 TextureUnit0; +}; + +} +} diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.cpp b/source/Irrlicht/OpenGL/MaterialRenderer.cpp new file mode 100644 index 0000000..080835c --- /dev/null +++ b/source/Irrlicht/OpenGL/MaterialRenderer.cpp @@ -0,0 +1,481 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "MaterialRenderer.h" + +#include "EVertexAttributes.h" +#include "IGPUProgrammingServices.h" +#include "IShaderConstantSetCallBack.h" +#include "IVideoDriver.h" +#include "os.h" + +#include "Driver.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + + +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3Driver* driver, + s32& outMaterialTypeNr, + const c8* vertexShaderProgram, + const c8* pixelShaderProgram, + IShaderConstantSetCallBack* callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) + : Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) +{ +#ifdef _DEBUG + setDebugName("MaterialRenderer"); +#endif + + switch (baseMaterial) + { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_TRANSPARENT_ADD_COLOR: + FixedBlending = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); + + init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram); +} + + +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3Driver* driver, + IShaderConstantSetCallBack* callback, + E_MATERIAL_TYPE baseMaterial, s32 userData) +: Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) +{ + switch (baseMaterial) + { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_TRANSPARENT_ADD_COLOR: + FixedBlending = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); +} + + +COpenGL3MaterialRenderer::~COpenGL3MaterialRenderer() +{ + if (CallBack) + CallBack->drop(); + + if (Program) + { + GLuint shaders[8]; + GLint count; + glGetAttachedShaders(Program, 8, &count, shaders); + + count=core::min_(count,8); + for (GLint i=0; iaddMaterialRenderer(this); +} + + +bool COpenGL3MaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) +{ + if (CallBack && Program) + CallBack->OnSetConstants(this, UserData); + + return true; +} + + +void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial& material, + const video::SMaterial& lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices* services) +{ + COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler(); + + cacheHandler->setProgram(Program); + + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (Alpha) + { + cacheHandler->setBlend(true); + cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + else if (FixedBlending) + { + cacheHandler->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); + cacheHandler->setBlend(true); + } + else if (Blending) + { + E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), + Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); + + cacheHandler->setBlend(true); + } + + if (CallBack) + CallBack->OnSetMaterial(material); +} + + +void COpenGL3MaterialRenderer::OnUnsetMaterial() +{ +} + + +bool COpenGL3MaterialRenderer::isTransparent() const +{ + return (Alpha || Blending || FixedBlending); +} + + +s32 COpenGL3MaterialRenderer::getRenderCapability() const +{ + return 0; +} + + +bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shader) +{ + if (Program) + { + GLuint shaderHandle = glCreateShader(shaderType); + glShaderSource(shaderHandle, 1, &shader, NULL); + glCompileShader(shaderHandle); + + GLint status = 0; + + glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status); + + if (status != GL_TRUE) + { + os::Printer::log("GLSL shader failed to compile", ELL_ERROR); + + GLint maxLength=0; + GLint length; + + glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, + &maxLength); + + if (maxLength) + { + GLchar *infoLog = new GLchar[maxLength]; + glGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete [] infoLog; + } + + return false; + } + + glAttachShader(Program, shaderHandle); + } + + return true; +} + + +bool COpenGL3MaterialRenderer::linkProgram() +{ + if (Program) + { + glLinkProgram(Program); + + GLint status = 0; + + glGetProgramiv(Program, GL_LINK_STATUS, &status); + + if (!status) + { + os::Printer::log("GLSL shader program failed to link", ELL_ERROR); + + GLint maxLength=0; + GLsizei length; + + glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength); + + if (maxLength) + { + GLchar *infoLog = new GLchar[maxLength]; + glGetProgramInfoLog(Program, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete [] infoLog; + } + + return false; + } + + GLint num = 0; + + glGetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num); + + if (num == 0) + return true; + + GLint maxlen = 0; + + glGetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); + + if (maxlen == 0) + { + os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR); + return false; + } + + // seems that some implementations use an extra null terminator. + ++maxlen; + c8 *buf = new c8[maxlen]; + + UniformInfo.clear(); + UniformInfo.reallocate(num); + + for (GLint i=0; i < num; ++i) + { + SUniformInfo ui; + memset(buf, 0, maxlen); + + GLint size; + glGetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); + + core::stringc name = ""; + + // array support, workaround for some bugged drivers. + for (s32 i = 0; i < maxlen; ++i) + { + if (buf[i] == '[' || buf[i] == '\0') + break; + + name += buf[i]; + } + + ui.name = name; + ui.location = glGetUniformLocation(Program, buf); + + UniformInfo.push_back(ui); + } + + delete [] buf; + } + + return true; +} + + +void COpenGL3MaterialRenderer::setBasicRenderStates(const SMaterial& material, + const SMaterial& lastMaterial, + bool resetAllRenderstates) +{ + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); +} + +s32 COpenGL3MaterialRenderer::getVertexShaderConstantID(const c8* name) +{ + return getPixelShaderConstantID(name); +} + +s32 COpenGL3MaterialRenderer::getPixelShaderConstantID(const c8* name) +{ + for (u32 i = 0; i < UniformInfo.size(); ++i) + { + if (UniformInfo[i].name == name) + return i; + } + + return -1; +} + +void COpenGL3MaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) +{ + os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING); +} + +void COpenGL3MaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) +{ + os::Printer::log("Cannot set constant, use high level shader call.", ELL_WARNING); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count) +{ + return setPixelShaderConstant(index, floats, count); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const u32* ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count) +{ + if(index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) + { + case GL_FLOAT: + glUniform1fv(UniformInfo[index].location, count, floats); + break; + case GL_FLOAT_VEC2: + glUniform2fv(UniformInfo[index].location, count/2, floats); + break; + case GL_FLOAT_VEC3: + glUniform3fv(UniformInfo[index].location, count/3, floats); + break; + case GL_FLOAT_VEC4: + glUniform4fv(UniformInfo[index].location, count/4, floats); + break; + case GL_FLOAT_MAT2: + glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats); + break; + case GL_FLOAT_MAT3: + glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats); + break; + case GL_FLOAT_MAT4: + glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + { + if(floats) + { + const GLint id = (GLint)(*floats); + glUniform1iv(UniformInfo[index].location, 1, &id); + } + else + status = false; + } + break; + default: + status = false; + break; + } + + return status; +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count) +{ + if(index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) + { + case GL_INT: + case GL_BOOL: + glUniform1iv(UniformInfo[index].location, count, ints); + break; + case GL_INT_VEC2: + case GL_BOOL_VEC2: + glUniform2iv(UniformInfo[index].location, count/2, ints); + break; + case GL_INT_VEC3: + case GL_BOOL_VEC3: + glUniform3iv(UniformInfo[index].location, count/3, ints); + break; + case GL_INT_VEC4: + case GL_BOOL_VEC4: + glUniform4iv(UniformInfo[index].location, count/4, ints); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + glUniform1iv(UniformInfo[index].location, 1, ints); + break; + default: + status = false; + break; + } + + return status; +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const u32* ints, int count) +{ + os::Printer::log("Unsigned int support needs at least GLES 3.0", ELL_WARNING); + return false; +} + +IVideoDriver* COpenGL3MaterialRenderer::getVideoDriver() +{ + return Driver; +} + +} +} diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.h b/source/Irrlicht/OpenGL/MaterialRenderer.h new file mode 100644 index 0000000..f45e725 --- /dev/null +++ b/source/Irrlicht/OpenGL/MaterialRenderer.h @@ -0,0 +1,99 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "EMaterialTypes.h" +#include "IMaterialRenderer.h" +#include "IMaterialRendererServices.h" +#include "IGPUProgrammingServices.h" +#include "irrArray.h" +#include "irrString.h" + +#include "Common.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3Driver; + +class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices +{ +public: + + COpenGL3MaterialRenderer( + COpenGL3Driver* driver, + s32& outMaterialTypeNr, + const c8* vertexShaderProgram = 0, + const c8* pixelShaderProgram = 0, + IShaderConstantSetCallBack* callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + virtual ~COpenGL3MaterialRenderer(); + + GLuint getProgram() const; + + virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices* services); + + virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype); + + virtual void OnUnsetMaterial(); + + virtual bool isTransparent() const; + + virtual s32 getRenderCapability() const; + + void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) override; + + s32 getVertexShaderConstantID(const c8* name) override; + s32 getPixelShaderConstantID(const c8* name) override; + void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override; + void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override; + bool setVertexShaderConstant(s32 index, const f32* floats, int count) override; + bool setVertexShaderConstant(s32 index, const s32* ints, int count) override; + bool setVertexShaderConstant(s32 index, const u32* ints, int count) override; + bool setPixelShaderConstant(s32 index, const f32* floats, int count) override; + bool setPixelShaderConstant(s32 index, const s32* ints, int count) override; + bool setPixelShaderConstant(s32 index, const u32* ints, int count) override; + + IVideoDriver* getVideoDriver() override; + +protected: + + COpenGL3MaterialRenderer(COpenGL3Driver* driver, + IShaderConstantSetCallBack* callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true); + + bool createShader(GLenum shaderType, const char* shader); + bool linkProgram(); + + COpenGL3Driver* Driver; + IShaderConstantSetCallBack* CallBack; + + bool Alpha; + bool Blending; + bool FixedBlending; + + struct SUniformInfo + { + core::stringc name; + GLenum type; + GLint location; + }; + + GLuint Program; + core::array UniformInfo; + s32 UserData; +}; + + +} +} diff --git a/source/Irrlicht/OpenGL/Renderer2D.cpp b/source/Irrlicht/OpenGL/Renderer2D.cpp new file mode 100644 index 0000000..d0a2c0a --- /dev/null +++ b/source/Irrlicht/OpenGL/Renderer2D.cpp @@ -0,0 +1,83 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Renderer2D.h" + +#include "IGPUProgrammingServices.h" +#include "os.h" + +#include "Driver.h" + +#include "COpenGLCoreFeature.h" +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + +COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3Driver* driver, bool withTexture) : + COpenGL3MaterialRenderer(driver, 0, EMT_SOLID), + WithTexture(withTexture) +{ +#ifdef _DEBUG + setDebugName("Renderer2D"); +#endif + + int Temp = 0; + + init(Temp, vertexShaderProgram, pixelShaderProgram, false); + + COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler(); + + cacheHandler->setProgram(Program); + + // These states don't change later. + + ThicknessID = getPixelShaderConstantID("uThickness"); + if ( WithTexture ) + { + TextureUsageID = getPixelShaderConstantID("uTextureUsage"); + s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit"); + + s32 TextureUnit = 0; + setPixelShaderConstant(TextureUnitID, &TextureUnit, 1); + + s32 TextureUsage = 0; + setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); + } + + cacheHandler->setProgram(0); +} + +COpenGL3Renderer2D::~COpenGL3Renderer2D() +{ +} + +void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial& material, + const video::SMaterial& lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices* services) +{ + Driver->getCacheHandler()->setProgram(Program); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; + setPixelShaderConstant(ThicknessID, &Thickness, 1); + + if ( WithTexture ) + { + s32 TextureUsage = material.TextureLayer[0].Texture ? 1 : 0; + setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); + } +} + +bool COpenGL3Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) +{ + return true; +} + +} +} diff --git a/source/Irrlicht/OpenGL/Renderer2D.h b/source/Irrlicht/OpenGL/Renderer2D.h new file mode 100644 index 0000000..8df192b --- /dev/null +++ b/source/Irrlicht/OpenGL/Renderer2D.h @@ -0,0 +1,33 @@ +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "MaterialRenderer.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3Renderer2D : public COpenGL3MaterialRenderer +{ +public: + COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3Driver* driver, bool withTexture); + ~COpenGL3Renderer2D(); + + virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices* services); + + virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype); + +protected: + bool WithTexture; + s32 ThicknessID; + s32 TextureUsageID; +}; + + +} +} From cfa8dd78450f4a7f375fa6a12319ae7d067e9891 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 17:39:28 +0300 Subject: [PATCH 10/42] Request OpenGL 3.2 --- source/Irrlicht/CIrrDeviceSDL.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 3b5a736..8a74719 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -390,6 +390,9 @@ bool CIrrDeviceSDL::createWindow() return false; if (CreationParams.DriverType == video::EDT_OPENGL) { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); if (CreationParams.Bits == 16) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4); From 8c521939b9a93834df3b1536e1850101f31cb89c Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 17:41:03 +0300 Subject: [PATCH 11/42] Enumerate extensions in the OpenGL 3 way --- source/Irrlicht/mt_opengl_loader.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/mt_opengl_loader.cpp b/source/Irrlicht/mt_opengl_loader.cpp index 96d7587..26de3d3 100755 --- a/source/Irrlicht/mt_opengl_loader.cpp +++ b/source/Irrlicht/mt_opengl_loader.cpp @@ -756,11 +756,22 @@ void OpenGLProcedures::LoadAllProcedures(irr::video::IContextManager *cmgr) if (!NamedBufferPageCommitment) NamedBufferPageCommitment = (PFNGLNAMEDBUFFERPAGECOMMITMENTPROC_MT)cmgr->getProcAddress("glNamedBufferPageCommitmentARB"); if (!TexPageCommitment) TexPageCommitment = (PFNGLTEXPAGECOMMITMENTPROC_MT)cmgr->getProcAddress("glTexPageCommitmentARB"); + // OpenGL 3 way to enumerate extensions + int ext_count = 0; + GetIntegerv(NUM_EXTENSIONS, &ext_count); + extensions.reserve(ext_count); + for (int k = 0; k < ext_count; k++) + extensions.emplace((char *)GetStringi(EXTENSIONS, k)); + if (ext_count) + return; + + // OpenGL 2 / ES 2 way to enumerate extensions + auto ext_str = GetString(EXTENSIONS); + if (!ext_str) + return; // get the extension string, chop it up - std::string ext_string = std::string((char*)GetString(EXTENSIONS)); - std::stringstream ext_ss(ext_string); + std::stringstream ext_ss((char*)ext_str); std::string tmp; while (std::getline(ext_ss, tmp, ' ')) extensions.emplace(tmp); - } From 1f750cd7b26348aa799b2ebc9a779f670dba5f4f Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 20:31:51 +0300 Subject: [PATCH 12/42] Add debug handler --- source/Irrlicht/CIrrDeviceSDL.cpp | 1 + source/Irrlicht/OpenGL/Driver.cpp | 11 +++++++++++ source/Irrlicht/OpenGL/Driver.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 8a74719..a5ba6f6 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -393,6 +393,7 @@ bool CIrrDeviceSDL::createWindow() SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); if (CreationParams.Bits == 16) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4); diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 7c13e7c..671f338 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -31,6 +31,16 @@ namespace irr namespace video { +void APIENTRY COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +{ + ((COpenGL3Driver *)userParam)->debugCb(source, type, id, severity, length, message); +} + +void COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) +{ + printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); +} + COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), @@ -52,6 +62,7 @@ COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IF ExposedData = ContextManager->getContext(); ContextManager->activateContext(ExposedData, false); GL.LoadAllProcedures(ContextManager); + GL.DebugMessageCallback(debugCb, this); } COpenGL3Driver::~COpenGL3Driver() diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index dd2ad89..4920fde 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -397,6 +397,9 @@ private: ECOLOR_FORMAT ColorFormat; IContextManager* ContextManager; + + void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); + static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); }; } // end namespace video From 608aa150ffe23d0317854ac3a94f39a856fcdaca Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 20:32:06 +0300 Subject: [PATCH 13/42] Load extensions the OpenGL 3 way --- source/Irrlicht/OpenGL/ExtensionHandler.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index 297aa94..055738b 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -9,6 +9,7 @@ #include "irrString.h" #include "SMaterial.h" #include "fast_atof.h" +#include namespace irr { @@ -16,9 +17,22 @@ namespace video { void COpenGL3ExtensionHandler::initExtensions() { - getGLVersion(); + GLint major, minor; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + Version = 100 * major + 10 * minor; - getGLExtensions(); + GLint ext_count = 0; + GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); + for (int k = 0; k < ext_count; k++) { + auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k); + for (size_t j=0; j Date: Mon, 27 Feb 2023 21:23:11 +0300 Subject: [PATCH 14/42] Drop obsolete IVideoDriver features --- include/IVideoDriver.h | 119 ---------------- source/Irrlicht/CNullDriver.cpp | 107 --------------- source/Irrlicht/CNullDriver.h | 25 ++-- source/Irrlicht/OpenGL/Driver.cpp | 217 ------------------------------ source/Irrlicht/OpenGL/Driver.h | 19 --- 5 files changed, 12 insertions(+), 475 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index e3ea221..4f00f44 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -719,23 +719,6 @@ namespace video virtual void draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color = SColor(255,255,255,255)) =0; - //! Draws a 3d triangle. - /** This method calls drawVertexPrimitiveList for some triangles. - This method works with all drivers because it simply calls - drawVertexPrimitiveList, but it is hence not very fast. - Note that the triangle is drawn using the current - transformation matrix and material. So if you need to draw it - independently of the current transformation, use - \code - driver->setMaterial(someMaterial); - driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); - \endcode - for some properly set up material before drawing the triangle. - \param triangle The triangle to draw. - \param color Color of the line. */ - virtual void draw3DTriangle(const core::triangle3df& triangle, - SColor color = SColor(255,255,255,255)) =0; - //! Draws a 3d axis aligned box. /** This method simply calls draw3DLine for the edges of the box. Note that the box is drawn using the current transformation @@ -780,35 +763,6 @@ namespace video const core::rect& sourceRect, const core::rect* clipRect =0, SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false) =0; - //! Draws a set of 2d images, using a color and the alpha channel of the texture. - /** The images are drawn beginning at pos and concatenated in - one line. All drawings are clipped against clipRect (if != 0). - The subtextures are defined by the array of sourceRects and are - chosen by the indices given. - \param texture Texture to be drawn. - \param pos Upper left 2d destination position where the image - will be drawn. - \param sourceRects Source rectangles of the image. - \param indices List of indices which choose the actual - rectangle used each time. - \param kerningWidth Offset to Position on X - \param clipRect Pointer to rectangle on the screen where the - image is clipped to. - If this pointer is 0 then the image is not clipped. - \param color Color with which the image is drawn. - Note that the alpha component is used. If alpha is other than - 255, the image will be transparent. - \param useAlphaChannelOfTexture: If true, the alpha channel of - the texture is used to draw the image. */ - virtual void draw2DImageBatch(const video::ITexture* texture, - const core::position2d& pos, - const core::array >& sourceRects, - const core::array& indices, - s32 kerningWidth=0, - const core::rect* clipRect=0, - SColor color=SColor(255,255,255,255), - bool useAlphaChannelOfTexture=false) =0; - //! Draws a set of 2d images, using a color and the alpha channel of the texture. /** All drawings are clipped against clipRect (if != 0). The subtextures are defined by the array of sourceRects and are @@ -879,13 +833,6 @@ namespace video SColor colorLeftDown, SColor colorRightDown, const core::rect* clip =0) =0; - //! Draws the outline of a 2D rectangle. - /** \param pos Position of the rectangle. - \param color Color of the rectangle to draw. The alpha component - specifies how transparent the rectangle outline will be. */ - virtual void draw2DRectangleOutline(const core::recti& pos, - SColor color=SColor(255,255,255,255)) =0; - //! Draws a 2d line. /** In theory both start and end will be included in coloring. BUG: Currently d3d ignores the last pixel @@ -899,72 +846,6 @@ namespace video const core::position2d& end, SColor color=SColor(255,255,255,255)) =0; - //! Draws a pixel. - /** \param x The x-position of the pixel. - \param y The y-position of the pixel. - \param color Color of the pixel to draw. */ - virtual void drawPixel(u32 x, u32 y, const SColor& color) =0; - - //! Draws a non filled concyclic regular 2d polygon. - /** This method can be used to draw circles, but also - triangles, tetragons, pentagons, hexagons, heptagons, octagons, - enneagons, decagons, hendecagons, dodecagon, triskaidecagons, - etc. I think you'll got it now. And all this by simply - specifying the vertex count. Welcome to the wonders of - geometry. - \param center Position of center of circle (pixels). - \param radius Radius of circle in pixels. - \param color Color of the circle. - \param vertexCount Amount of vertices of the polygon. Specify 2 - to draw a line, 3 to draw a triangle, 4 for tetragons and a lot - (>10) for nearly a circle. */ - virtual void draw2DPolygon(core::position2d center, - f32 radius, - video::SColor color=SColor(100,255,255,255), - s32 vertexCount=10) =0; - - //! Draws a shadow volume into the stencil buffer. - /** To draw a stencil shadow, do this: First, draw all geometry. - Then use this method, to draw the shadow volume. Then, use - IVideoDriver::drawStencilShadow() to visualize the shadow. - Please note that the code for the opengl version of the method - is based on free code sent in by Philipp Dortmann, lots of - thanks go to him! - \param triangles Array of 3d vectors, specifying the shadow - volume. - \param zfail If set to true, zfail method is used, otherwise - zpass. - \param debugDataVisible The debug data that is enabled for this - shadow node - */ - virtual void drawStencilShadowVolume(const core::array& triangles, bool zfail=true, u32 debugDataVisible=0) =0; - - //! Fills the stencil shadow with color. - /** After the shadow volume has been drawn into the stencil - buffer using IVideoDriver::drawStencilShadowVolume(), use this - to draw the color of the shadow. - Please note that the code for the opengl version of the method - is based on free code sent in by Philipp Dortmann, lots of - thanks go to him! - \param clearStencilBuffer Set this to false, if you want to - draw every shadow with the same color, and only want to call - drawStencilShadow() once after all shadow volumes have been - drawn. Set this to true, if you want to paint every shadow with - its own color. - \param leftUpEdge Color of the shadow in the upper left corner - of screen. - \param rightUpEdge Color of the shadow in the upper right - corner of screen. - \param leftDownEdge Color of the shadow in the lower left - corner of screen. - \param rightDownEdge Color of the shadow in the lower right - corner of screen. */ - virtual void drawStencilShadow(bool clearStencilBuffer=false, - video::SColor leftUpEdge = video::SColor(255,0,0,0), - video::SColor rightUpEdge = video::SColor(255,0,0,0), - video::SColor leftDownEdge = video::SColor(255,0,0,0), - video::SColor rightDownEdge = video::SColor(255,0,0,0)) =0; - //! Draws a mesh buffer /** \param mb Buffer to draw */ virtual void drawMeshBuffer(const scene::IMeshBuffer* mb) =0; diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 2cbd47c..a76dbec 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -719,27 +719,6 @@ void CNullDriver::draw3DLine(const core::vector3df& start, } -//! Draws a 3d triangle. -void CNullDriver::draw3DTriangle(const core::triangle3df& triangle, SColor color) -{ - S3DVertex vertices[3]; - vertices[0].Pos=triangle.pointA; - vertices[0].Color=color; - vertices[0].Normal=triangle.getNormal().normalize(); - vertices[0].TCoords.set(0.f,0.f); - vertices[1].Pos=triangle.pointB; - vertices[1].Color=color; - vertices[1].Normal=vertices[0].Normal; - vertices[1].TCoords.set(0.5f,1.f); - vertices[2].Pos=triangle.pointC; - vertices[2].Color=color; - vertices[2].Normal=vertices[0].Normal; - vertices[2].TCoords.set(1.f,0.f); - const u16 indexList[] = {0,1,2}; - drawVertexPrimitiveList(vertices, 3, indexList, 1, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT); -} - - //! Draws a 3d axis aligned box. void CNullDriver::draw3DBox(const core::aabbox3d& box, SColor color) { @@ -779,31 +758,6 @@ void CNullDriver::draw2DImage(const video::ITexture* texture, const core::positi } - -//! draws a set of 2d images, using a color and the alpha channel of the -//! texture if desired. The images are drawn beginning at pos and concatenated -//! in one line. All drawings are clipped against clipRect (if != 0). -//! The subtextures are defined by the array of sourceRects and are chosen -//! by the indices given. -void CNullDriver::draw2DImageBatch(const video::ITexture* texture, - const core::position2d& pos, - const core::array >& sourceRects, - const core::array& indices, - s32 kerningWidth, - const core::rect* clipRect, SColor color, - bool useAlphaChannelOfTexture) -{ - core::position2d target(pos); - - for (u32 i=0; i& pos, const core::rect* clip) { @@ -877,38 +821,6 @@ void CNullDriver::draw2DLine(const core::position2d& start, { } -//! Draws a pixel -void CNullDriver::drawPixel(u32 x, u32 y, const SColor & color) -{ -} - - -//! Draws a non filled concyclic regular 2d polygon. -void CNullDriver::draw2DPolygon(core::position2d center, - f32 radius, video::SColor color, s32 count) -{ - if (count < 2) - return; - - core::position2d first; - core::position2d a,b; - - for (s32 j=0; j((s32)(sin(p)*radius), (s32)(cos(p)*radius)); - - if (j==0) - first = a; - else - draw2DLine(a, b, color); - } - - draw2DLine(a, first, color); -} - //! returns color format ECOLOR_FORMAT CNullDriver::getColorFormat() const @@ -979,25 +891,6 @@ const wchar_t* CNullDriver::getName() const } - -//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do -//! this: First, draw all geometry. Then use this method, to draw the shadow -//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. -void CNullDriver::drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible) -{ -} - - -//! Fills the stencil shadow with color. After the shadow volume has been drawn -//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this -//! to draw the color of the shadow. -void CNullDriver::drawStencilShadow(bool clearStencilBuffer, - video::SColor leftUpEdge, video::SColor rightUpEdge, - video::SColor leftDownEdge, video::SColor rightDownEdge) -{ -} - - //! Creates a boolean alpha channel of the texture based of an color key. void CNullDriver::makeColorKeyTexture(video::ITexture* texture, video::SColor color, diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index e6cdce6..3362045 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -126,9 +126,8 @@ namespace video virtual void draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color = SColor(255,255,255,255)) override; - //! Draws a 3d triangle. - virtual void draw3DTriangle(const core::triangle3df& triangle, - SColor color = SColor(255,255,255,255)) override; + [[deprecated]] virtual void draw3DTriangle(const core::triangle3df& triangle, + SColor color = SColor(255,255,255,255)) {} //! Draws a 3d axis aligned box. virtual void draw3DBox(const core::aabbox3d& box, @@ -154,14 +153,14 @@ namespace video Note that the alpha component is used: If alpha is other than 255, the image will be transparent. \param useAlphaChannelOfTexture: If true, the alpha channel of the texture is used to draw the image. */ - virtual void draw2DImageBatch(const video::ITexture* texture, + [[deprecated]] virtual void draw2DImageBatch(const video::ITexture* texture, const core::position2d& pos, const core::array >& sourceRects, const core::array& indices, s32 kerningWidth = 0, const core::rect* clipRect = 0, SColor color=SColor(255,255,255,255), - bool useAlphaChannelOfTexture=false) override; + bool useAlphaChannelOfTexture=false) {} //! Draws a set of 2d images, using a color and the alpha channel of the texture. /** All drawings are clipped against clipRect (if != 0). @@ -205,7 +204,7 @@ namespace video const core::rect* clip = 0) override; //! Draws the outline of a 2d rectangle - void draw2DRectangleOutline(const core::recti& pos, SColor color=SColor(255,255,255,255)) override; + [[deprecated]] virtual void draw2DRectangleOutline(const core::recti& pos, SColor color=SColor(255,255,255,255)) {} //! Draws a 2d line. virtual void draw2DLine(const core::position2d& start, @@ -213,11 +212,11 @@ namespace video SColor color=SColor(255,255,255,255)) override; //! Draws a pixel - void drawPixel(u32 x, u32 y, const SColor & color) override; + [[deprecated]] virtual void drawPixel(u32 x, u32 y, const SColor & color) {} //! Draws a non filled concyclic reqular 2d polygon. - virtual void draw2DPolygon(core::position2d center, - f32 radius, video::SColor Color, s32 vertexCount) override; + [[deprecated]] virtual void draw2DPolygon(core::position2d center, + f32 radius, video::SColor Color, s32 vertexCount) {} virtual void setFog(SColor color=SColor(0,255,255,255), E_FOG_TYPE fogType=EFT_FOG_LINEAR, @@ -268,17 +267,17 @@ namespace video //! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do //! this: First, draw all geometry. Then use this method, to draw the shadow //! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow. - virtual void drawStencilShadowVolume(const core::array& triangles, - bool zfail=true, u32 debugDataVisible=0) override; + [[deprecated]] virtual void drawStencilShadowVolume(const core::array& triangles, + bool zfail=true, u32 debugDataVisible=0) {} //! Fills the stencil shadow with color. After the shadow volume has been drawn //! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this //! to draw the color of the shadow. - virtual void drawStencilShadow(bool clearStencilBuffer=false, + [[deprecated]] virtual void drawStencilShadow(bool clearStencilBuffer=false, video::SColor leftUpEdge = video::SColor(0,0,0,0), video::SColor rightUpEdge = video::SColor(0,0,0,0), video::SColor leftDownEdge = video::SColor(0,0,0,0), - video::SColor rightDownEdge = video::SColor(0,0,0,0)) override; + video::SColor rightDownEdge = video::SColor(0,0,0,0)) {} //! Removes a texture from the texture cache and deletes it, freeing lot of diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 671f338..1a0bac0 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1231,102 +1231,6 @@ COpenGL3Driver::~COpenGL3Driver() } - //! draws a set of 2d images, using a color and the alpha channel - void COpenGL3Driver::draw2DImageBatch(const video::ITexture* texture, - const core::position2d& pos, - const core::array >& sourceRects, - const core::array& indices, s32 kerningWidth, - const core::rect* clipRect, SColor color, - bool useAlphaChannelOfTexture) - { - if (!texture) - return; - - chooseMaterial2D(); - if (!setMaterialTexture(0, texture)) - return; - - setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); - - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - - if (clipRect) - { - if (!clipRect->isValid()) - return; - - glEnable(GL_SCISSOR_TEST); - glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, - clipRect->getWidth(), clipRect->getHeight()); - } - - const core::dimension2du& ss = texture->getOriginalSize(); - core::position2d targetPos(pos); - // texcoords need to be flipped horizontally for RTTs - const bool isRTT = texture->isRenderTarget(); - const f32 invW = 1.f / static_cast(ss.Width); - const f32 invH = 1.f / static_cast(ss.Height); - - core::array vertices; - core::array quadIndices; - vertices.reallocate(indices.size()*4); - quadIndices.reallocate(indices.size()*3); - - for (u32 i = 0; i < indices.size(); ++i) - { - const s32 currentIndex = indices[i]; - if (!sourceRects[currentIndex].isValid()) - break; - - const core::rect tcoords( - sourceRects[currentIndex].UpperLeftCorner.X * invW, - (isRTT ? sourceRects[currentIndex].LowerRightCorner.Y : sourceRects[currentIndex].UpperLeftCorner.Y) * invH, - sourceRects[currentIndex].LowerRightCorner.X * invW, - (isRTT ? sourceRects[currentIndex].UpperLeftCorner.Y : sourceRects[currentIndex].LowerRightCorner.Y) * invH); - - const core::rect poss(targetPos, sourceRects[currentIndex].getSize()); - - f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - const u32 vstart = vertices.size(); - vertices.push_back(S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); - vertices.push_back(S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); - vertices.push_back(S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); - vertices.push_back(S3DVertex(left, down, 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); - - targetPos.X += sourceRects[currentIndex].getWidth(); - } - - if (vertices.size()) - { - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &vertices[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &vertices[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &vertices[0].TCoords); - glDrawElements(GL_TRIANGLES, quadIndices.size(), GL_UNSIGNED_SHORT, quadIndices.pointer()); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); - } - - if (clipRect) - glDisable(GL_SCISSOR_TEST); - - testGLError(__LINE__); - } - - //! draw a 2d rectangle void COpenGL3Driver::draw2DRectangle(SColor color, const core::rect& position, @@ -1980,127 +1884,6 @@ COpenGL3Driver::~COpenGL3Driver() } - //! Draws a shadow volume into the stencil buffer. - void COpenGL3Driver::drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible) - { - const u32 count=triangles.size(); - if (!StencilBuffer || !count) - return; - - bool fog = Material.FogEnable; - bool lighting = Material.Lighting; - E_MATERIAL_TYPE materialType = Material.MaterialType; - - Material.FogEnable = false; - Material.Lighting = false; - Material.MaterialType = EMT_SOLID; // Dedicated material in future. - - setRenderStates3DMode(); - - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_LESS); - CacheHandler->setDepthMask(false); - - if (!(debugDataVisible & (scene::EDS_SKELETON|scene::EDS_MESH_WIRE_OVERLAY))) - { - CacheHandler->setColorMask(ECP_NONE); - glEnable(GL_STENCIL_TEST); - } - - glEnableVertexAttribArray(EVA_POSITION); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(core::vector3df), triangles.const_pointer()); - - glStencilMask(~0); - glStencilFunc(GL_ALWAYS, 0, ~0); - - GLenum decr = GL_DECR; - GLenum incr = GL_INCR; - -#if defined(GL_OES_stencil_wrap) - if (FeatureAvailable[IRR_OES_stencil_wrap]) - { - decr = GL_DECR_WRAP_OES; - incr = GL_INCR_WRAP_OES; - } -#endif - - CacheHandler->setCullFace(true); - - if (zfail) - { - CacheHandler->setCullFaceFunc(GL_FRONT); - glStencilOp(GL_KEEP, incr, GL_KEEP); - glDrawArrays(GL_TRIANGLES, 0, count); - - CacheHandler->setCullFaceFunc(GL_BACK); - glStencilOp(GL_KEEP, decr, GL_KEEP); - glDrawArrays(GL_TRIANGLES, 0, count); - } - else // zpass - { - CacheHandler->setCullFaceFunc(GL_BACK); - glStencilOp(GL_KEEP, GL_KEEP, incr); - glDrawArrays(GL_TRIANGLES, 0, count); - - CacheHandler->setCullFaceFunc(GL_FRONT); - glStencilOp(GL_KEEP, GL_KEEP, decr); - glDrawArrays(GL_TRIANGLES, 0, count); - } - - glDisableVertexAttribArray(EVA_POSITION); - - glDisable(GL_STENCIL_TEST); - - Material.FogEnable = fog; - Material.Lighting = lighting; - Material.MaterialType = materialType; - } - - - void COpenGL3Driver::drawStencilShadow(bool clearStencilBuffer, - video::SColor leftUpEdge, video::SColor rightUpEdge, - video::SColor leftDownEdge, video::SColor rightDownEdge) - { - if (!StencilBuffer) - return; - - chooseMaterial2D(); - setMaterialTexture(0, 0); - - setRenderStates2DMode(true, false, false); - - CacheHandler->setDepthMask(false); - CacheHandler->setColorMask(ECP_ALL); - - CacheHandler->setBlend(true); - CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_NOTEQUAL, 0, ~0); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - vertices[0] = S3DVertex(-1.f, 1.f, 0.9f, 0, 0, 1, leftDownEdge, 0, 0); - vertices[1] = S3DVertex(1.f, 1.f, 0.9f, 0, 0, 1, leftUpEdge, 0, 0); - vertices[2] = S3DVertex(1.f, -1.f, 0.9f, 0, 0, 1, rightUpEdge, 0, 0); - vertices[3] = S3DVertex(-1.f, -1.f, 0.9f, 0, 0, 1, rightDownEdge, 0, 0); - - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); - - if (clearStencilBuffer) - glClear(GL_STENCIL_BUFFER_BIT); - - glDisable(GL_STENCIL_TEST); - } - - //! Draws a 3d line. void COpenGL3Driver::draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color) diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 4920fde..42c2deb 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -103,15 +103,6 @@ namespace video // internally used virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip); - //! draws a set of 2d images - virtual void draw2DImageBatch(const video::ITexture* texture, - const core::position2d& pos, - const core::array >& sourceRects, - const core::array& indices, s32 kerningWidth = 0, - const core::rect* clipRect = 0, - SColor color = SColor(255, 255, 255, 255), - bool useAlphaChannelOfTexture = false) override; - void draw2DImageBatch(const video::ITexture* texture, const core::array >& positions, const core::array >& sourceRects, @@ -150,16 +141,6 @@ namespace video //! Returns the maximum texture size supported. core::dimension2du getMaxTextureSize() const override; - //! Draws a shadow volume into the stencil buffer. - void drawStencilShadowVolume(const core::array& triangles, bool zfail, u32 debugDataVisible=0) override; - - //! Fills the stencil shadow with color. - virtual void drawStencilShadow(bool clearStencilBuffer=false, - video::SColor leftUpEdge = video::SColor(0,0,0,0), - video::SColor rightUpEdge = video::SColor(0,0,0,0), - video::SColor leftDownEdge = video::SColor(0,0,0,0), - video::SColor rightDownEdge = video::SColor(0,0,0,0)) override; - //! sets a viewport void setViewPort(const core::rect& area) override; From 4fba49691769581457e80e69e0ca3c47e8a4f57c Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 21:27:23 +0300 Subject: [PATCH 15/42] Unify plain image drawing --- source/Irrlicht/OpenGL/Driver.cpp | 224 +++--------------------------- 1 file changed, 20 insertions(+), 204 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 1a0bac0..7603d86 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -828,128 +828,8 @@ COpenGL3Driver::~COpenGL3Driver() if (!sourceRect.isValid()) return; - core::position2d targetPos(destPos); - 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); - - chooseMaterial2D(); - if (!setMaterialTexture(0, texture )) - return; - - setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); - - f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - u16 indices[] = {0, 1, 2, 3}; - S3DVertex vertices[4]; - vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); - vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); - vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); - vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); - - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + SColor colors[4] = {color, color, color, color}; + draw2DImage(texture, {destPos, sourceRect.getSize()}, sourceRect, clipRect, colors, useAlphaChannelOfTexture); } @@ -1083,6 +963,24 @@ COpenGL3Driver::~COpenGL3Driver() if (!texture) return; + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); core::array vtx(drawCount * 4); @@ -1095,82 +993,6 @@ COpenGL3Driver::~COpenGL3Driver() // 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 + (s32)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 + (s32)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; - } - - 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) - 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. // now draw it. core::rect tcoords; @@ -1181,12 +1003,6 @@ COpenGL3Driver::~COpenGL3Driver() const core::rect poss(targetPos, sourceSize); - chooseMaterial2D(); - if (!setMaterialTexture(0, texture)) - return; - - setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); - f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; From c5ce85314829a75ca5172132105e3595e80b3dfe Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 21:56:26 +0300 Subject: [PATCH 16/42] Unify quad drawing --- source/Irrlicht/OpenGL/Driver.cpp | 135 +++++++++++++----------------- source/Irrlicht/OpenGL/Driver.h | 7 ++ 2 files changed, 63 insertions(+), 79 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 7603d86..5e697e5 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -63,6 +63,7 @@ COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IF ContextManager->activateContext(ExposedData, false); GL.LoadAllProcedures(ContextManager); GL.DebugMessageCallback(debugCb, this); + initQuadsIndices(); } COpenGL3Driver::~COpenGL3Driver() @@ -89,6 +90,20 @@ COpenGL3Driver::~COpenGL3Driver() } } + void COpenGL3Driver::initQuadsIndices(int max_vertex_count) + { + int max_quad_count = max_vertex_count / 4; + QuadsIndices.reserve(6 * max_quad_count); + for (int k = 0; k < max_quad_count; k++) { + QuadsIndices.push_back(4 * k + 0); + QuadsIndices.push_back(4 * k + 1); + QuadsIndices.push_back(4 * k + 2); + QuadsIndices.push_back(4 * k + 0); + QuadsIndices.push_back(4 * k + 2); + QuadsIndices.push_back(4 * k + 3); + } + } + bool COpenGL3Driver::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) { Name = glGetString(GL_VERSION); @@ -886,23 +901,13 @@ COpenGL3Driver::~COpenGL3Driver() f32 down = 2.f - (f32)destRect.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; f32 top = 2.f - (f32)destRect.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - u16 indices[] = { 0, 1, 2, 3 }; S3DVertex vertices[4]; vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawQuad(vertices, true); if (clipRect) glDisable(GL_SCISSOR_TEST); @@ -921,7 +926,6 @@ COpenGL3Driver::~COpenGL3Driver() setRenderStates2DMode(false, true, true); - u16 quad2DIndices[] = { 0, 1, 2, 3 }; S3DVertex quad2DVertices[4]; quad2DVertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); @@ -941,19 +945,9 @@ COpenGL3Driver::~COpenGL3Driver() quad2DVertices[2].Color = SColor(0xFFFFFFFF); quad2DVertices[3].Color = SColor(0xFFFFFFFF); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(quad2DVertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(quad2DVertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(quad2DVertices))[0].TCoords); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, quad2DIndices); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawQuad(quad2DVertices, true); } - void COpenGL3Driver::draw2DImageBatch(const video::ITexture* texture, const core::array >& positions, const core::array >& sourceRects, @@ -984,7 +978,6 @@ COpenGL3Driver::~COpenGL3Driver() const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); core::array vtx(drawCount * 4); - core::array indices(drawCount * 6); for (u32 i = 0; i < drawCount; i++) { @@ -1020,30 +1013,12 @@ COpenGL3Driver::~COpenGL3Driver() vtx.push_back(S3DVertex(left, down, 0.0f, 0.0f, 0.0f, 0.0f, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); - - const u32 curPos = vtx.size() - 4; - indices.push_back(0 + curPos); - indices.push_back(1 + curPos); - indices.push_back(2 + curPos); - - indices.push_back(0 + curPos); - indices.push_back(2 + curPos); - indices.push_back(3 + curPos); } - if (vtx.size()) - { - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &vtx[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &vtx[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &vtx[0].TCoords); - glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, indices.pointer()); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); - } + drawQuads(vtx.const_pointer(), drawCount, true); + + if (clipRect) + glDisable(GL_SCISSOR_TEST); } @@ -1072,20 +1047,13 @@ COpenGL3Driver::~COpenGL3Driver() f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - u16 indices[] = {0, 1, 2, 3}; S3DVertex vertices[4]; vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, 0, 0); vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, 0, 0); vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0); vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawQuad(vertices, false); } @@ -1118,20 +1086,13 @@ COpenGL3Driver::~COpenGL3Driver() f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - u16 indices[] = {0, 1, 2, 3}; S3DVertex vertices[4]; vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, colorLeftUp, 0, 0); vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, colorRightUp, 0, 0); vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0); vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawQuad(vertices, false); } @@ -1155,18 +1116,11 @@ COpenGL3Driver::~COpenGL3Driver() f32 startY = 2.f - (f32)start.Y / (f32)renderTargetSize.Height * 2.f - 1.f; f32 endY = 2.f - (f32)end.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - u16 indices[] = {0, 1}; S3DVertex vertices[2]; vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawArrays(GL_LINES, vertices, 2, false); } } @@ -1189,15 +1143,45 @@ COpenGL3Driver::~COpenGL3Driver() S3DVertex vertices[1]; vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0); + drawArrays(GL_POINTS, vertices, 1, false); + } + + void COpenGL3Driver::drawQuads(const S3DVertex *vertices, int quad_count, bool textured) + { + assert(6 * std::size_t(quad_count) <= QuadsIndices.size()); glEnableVertexAttribArray(EVA_POSITION); glEnableVertexAttribArray(EVA_COLOR); + if (textured) + glEnableVertexAttribArray(EVA_TCOORD0); glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glDrawArrays(GL_POINTS, 0, 1); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glDrawElements(GL_TRIANGLES, 6 * quad_count, GL_UNSIGNED_SHORT, QuadsIndices.data()); + glDisableVertexAttribArray(EVA_TCOORD0); glDisableVertexAttribArray(EVA_COLOR); glDisableVertexAttribArray(EVA_POSITION); } + void COpenGL3Driver::drawArrays(GLenum type, const S3DVertex *vertices, int vertex_count, bool textured) + { + glEnableVertexAttribArray(EVA_POSITION); + glEnableVertexAttribArray(EVA_COLOR); + if (textured) + glEnableVertexAttribArray(EVA_TCOORD0); + glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); + glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); + glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); + glDrawArrays(type, 0, vertex_count); + glDisableVertexAttribArray(EVA_TCOORD0); + glDisableVertexAttribArray(EVA_COLOR); + glDisableVertexAttribArray(EVA_POSITION); + } + + void COpenGL3Driver::drawQuad(const S3DVertex (&vertices)[4], bool textured) + { + drawQuads(vertices, 1, textured); + } + ITexture* COpenGL3Driver::createDeviceDependentTexture(const io::path& name, IImage* image) { core::array imageArray(1); @@ -1706,18 +1690,11 @@ COpenGL3Driver::~COpenGL3Driver() { 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); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, indices); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawArrays(GL_LINES, vertices, 2, false); } diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 42c2deb..dc29297 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -332,6 +332,10 @@ namespace video //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` virtual void setViewPortRaw(u32 width, u32 height); + void drawQuad(const S3DVertex (&vertices)[4], bool textured); + void drawQuads(const S3DVertex *vertices, int quad_count, bool textured); + void drawArrays(GLenum type, const S3DVertex *vertices, int vertex_count, bool textured); + COpenGL3CacheHandler* CacheHandler; core::stringw Name; core::stringc VendorName; @@ -379,6 +383,9 @@ private: IContextManager* ContextManager; + std::vector QuadsIndices; + void initQuadsIndices(int max_vertex_count = 65536); + void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); }; From 48270029cd864eddccdb5cf41b92c9e0159ba10b Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 Feb 2023 23:36:56 +0300 Subject: [PATCH 17/42] Drop obsolete stuff --- source/Irrlicht/OpenGL/Driver.cpp | 78 ------------------------------- source/Irrlicht/OpenGL/Driver.h | 3 -- 2 files changed, 81 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 5e697e5..eb4150c 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -2133,38 +2133,6 @@ COpenGL3Driver::~COpenGL3Driver() return blendTable[factor]; } - GLenum COpenGL3Driver::getZBufferBits() const - { - // TODO: never used, so not sure what this was really about (zbuffer used by device? Or for RTT's?) - - 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 COpenGL3Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, GLenum& pixelType, void(**converter)(const void*, s32, void*)) const { @@ -2212,16 +2180,12 @@ COpenGL3Driver::~COpenGL3Driver() pixelFormat = GL_RGBA; pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; -#endif -#ifdef GL_EXT_texture_compression_s3tc case ECF_DXT2: case ECF_DXT3: supported = true; pixelFormat = GL_RGBA; pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; -#endif -#ifdef GL_EXT_texture_compression_s3tc case ECF_DXT4: case ECF_DXT5: supported = true; @@ -2229,48 +2193,6 @@ COpenGL3Driver::~COpenGL3Driver() pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; #endif -#ifdef GL_IMG_texture_compression_pvrtc - case ECF_PVRTC_RGB2: - supported = true; - pixelFormat = GL_RGB; - pixelType = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; - break; -#endif -#ifdef GL_IMG_texture_compression_pvrtc - case ECF_PVRTC_ARGB2: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; - break; -#endif -#ifdef GL_IMG_texture_compression_pvrtc - case ECF_PVRTC_RGB4: - supported = true; - pixelFormat = GL_RGB; - pixelType = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; - break; -#endif -#ifdef GL_IMG_texture_compression_pvrtc - case ECF_PVRTC_ARGB4: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - break; -#endif -#ifdef GL_IMG_texture_compression_pvrtc2 - case ECF_PVRTC2_ARGB2: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG; - break; -#endif -#ifdef GL_IMG_texture_compression_pvrtc2 - case ECF_PVRTC2_ARGB4: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG; - break; -#endif #ifdef GL_OES_compressed_ETC1_RGB8_texture case ECF_ETC1: supported = true; diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index dc29297..b732595 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -273,9 +273,6 @@ namespace video //! Convert E_BLEND_FACTOR to OpenGL equivalent GLenum getGLBlend(E_BLEND_FACTOR factor) const; - //! Get ZBuffer bits. - virtual GLenum getZBufferBits() const; - virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, GLenum& pixelType, void(**converter)(const void*, s32, void*)) const; From 05384fdc5e1e13b3a85c12f7af2aaebe835c0523 Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 28 Feb 2023 00:51:29 +0300 Subject: [PATCH 18/42] Unify drawing functions --- source/Irrlicht/OpenGL/Driver.cpp | 253 ++++++++++++++++-------------- source/Irrlicht/OpenGL/Driver.h | 11 +- 2 files changed, 140 insertions(+), 124 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index eb4150c..baa6f44 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -30,6 +30,98 @@ namespace irr { namespace video { + struct VertexAttribute { + enum class Mode { + Regular, + Normalized, + Integral, + }; + int Index; + int ComponentCount; + GLenum ComponentType; + Mode mode; + int Offset; + }; + + struct VertexType { + int VertexSize; + int AttributeCount; + VertexAttribute Attributes[]; + + VertexType(const VertexType &) = delete; + VertexType &operator= (const VertexType &) = delete; + }; + + static const VertexAttribute *begin(const VertexType &type) + { + return type.Attributes; + } + + static const VertexAttribute *end(const VertexType &type) + { + return type.Attributes + type.AttributeCount; + } + + static constexpr VertexType vtStandard = { + sizeof(S3DVertex), 4, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + }, + }; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winvalid-offsetof" + + static constexpr VertexType vt2TCoords = { + sizeof(S3DVertex2TCoords), 5, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex2TCoords, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords)}, + {EVA_TCOORD1, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords2)}, + }, + }; + + static constexpr VertexType vtTangents = { + sizeof(S3DVertexTangents), 6, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertexTangents, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, TCoords)}, + {EVA_TANGENT, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Tangent)}, + {EVA_BINORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Binormal)}, + }, + }; + +#pragma GCC diagnostic pop + + static const VertexType &getVertexTypeDescription(E_VERTEX_TYPE type) + { + switch (type) { + case EVT_STANDARD: return vtStandard; + case EVT_2TCOORDS: return vt2TCoords; + case EVT_TANGENTS: return vtTangents; + default: assert(false); + } + } + + static constexpr VertexType vt2DImage = { + sizeof(S3DVertex), 3, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + }, + }; + + static constexpr VertexType vtPrimitive = { + sizeof(S3DVertex), 2, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + }, + }; + void APIENTRY COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { @@ -692,75 +784,8 @@ COpenGL3Driver::~COpenGL3Driver() setRenderStates3DMode(); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - glEnableVertexAttribArray(EVA_NORMAL); - glEnableVertexAttribArray(EVA_TCOORD0); - - switch (vType) - { - case EVT_STANDARD: - if (vertices) - { - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Normal); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - } - else - { - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), 0); - glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex), buffer_offset(12)); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), buffer_offset(24)); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), buffer_offset(28)); - } - - break; - case EVT_2TCOORDS: - glEnableVertexAttribArray(EVA_TCOORD1); - - if (vertices) - { - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Normal); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords); - glVertexAttribPointer(EVA_TCOORD1, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), &(static_cast(vertices))[0].TCoords2); - } - else - { - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(0)); - glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(12)); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex2TCoords), buffer_offset(24)); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(28)); - glVertexAttribPointer(EVA_TCOORD1, 2, GL_FLOAT, false, sizeof(S3DVertex2TCoords), buffer_offset(36)); - } - break; - case EVT_TANGENTS: - glEnableVertexAttribArray(EVA_TANGENT); - glEnableVertexAttribArray(EVA_BINORMAL); - - if (vertices) - { - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Normal); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].TCoords); - glVertexAttribPointer(EVA_TANGENT, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Tangent); - glVertexAttribPointer(EVA_BINORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), &(static_cast(vertices))[0].Binormal); - } - else - { - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(0)); - glVertexAttribPointer(EVA_NORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(12)); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertexTangents), buffer_offset(24)); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(28)); - glVertexAttribPointer(EVA_TANGENT, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(36)); - glVertexAttribPointer(EVA_BINORMAL, 3, GL_FLOAT, false, sizeof(S3DVertexTangents), buffer_offset(48)); - } - break; - } - + auto &vTypeDesc = getVertexTypeDescription(vType); + beginDraw(vTypeDesc, reinterpret_cast(vertices)); GLenum indexSize = 0; switch (iType) @@ -813,23 +838,7 @@ COpenGL3Driver::~COpenGL3Driver() break; } - switch (vType) - { - case EVT_2TCOORDS: - glDisableVertexAttribArray(EVA_TCOORD1); - break; - case EVT_TANGENTS: - glDisableVertexAttribArray(EVA_TANGENT); - glDisableVertexAttribArray(EVA_BINORMAL); - break; - default: - break; - } - - glDisableVertexAttribArray(EVA_POSITION); - glDisableVertexAttribArray(EVA_NORMAL); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_TCOORD0); + endDraw(vTypeDesc); } @@ -907,7 +916,7 @@ COpenGL3Driver::~COpenGL3Driver() vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); - drawQuad(vertices, true); + drawQuad(vt2DImage, vertices); if (clipRect) glDisable(GL_SCISSOR_TEST); @@ -945,7 +954,7 @@ COpenGL3Driver::~COpenGL3Driver() quad2DVertices[2].Color = SColor(0xFFFFFFFF); quad2DVertices[3].Color = SColor(0xFFFFFFFF); - drawQuad(quad2DVertices, true); + drawQuad(vt2DImage, quad2DVertices); } void COpenGL3Driver::draw2DImageBatch(const video::ITexture* texture, @@ -976,6 +985,7 @@ COpenGL3Driver::~COpenGL3Driver() } const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); + assert(6 * std::size_t(drawCount) <= QuadsIndices.size()); core::array vtx(drawCount * 4); @@ -1015,7 +1025,7 @@ COpenGL3Driver::~COpenGL3Driver() tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); } - drawQuads(vtx.const_pointer(), drawCount, true); + drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), QuadsIndices.data(), 6 * drawCount); if (clipRect) glDisable(GL_SCISSOR_TEST); @@ -1053,7 +1063,7 @@ COpenGL3Driver::~COpenGL3Driver() vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0); vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0); - drawQuad(vertices, false); + drawQuad(vtPrimitive, vertices); } @@ -1092,7 +1102,7 @@ COpenGL3Driver::~COpenGL3Driver() vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0); vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0); - drawQuad(vertices, false); + drawQuad(vtPrimitive, vertices); } @@ -1120,7 +1130,7 @@ COpenGL3Driver::~COpenGL3Driver() vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); - drawArrays(GL_LINES, vertices, 2, false); + drawArrays(GL_LINES, vtPrimitive, vertices, 2); } } @@ -1143,43 +1153,44 @@ COpenGL3Driver::~COpenGL3Driver() S3DVertex vertices[1]; vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0); - drawArrays(GL_POINTS, vertices, 1, false); + drawArrays(GL_POINTS, vtPrimitive, vertices, 1); } - void COpenGL3Driver::drawQuads(const S3DVertex *vertices, int quad_count, bool textured) + void COpenGL3Driver::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) { - assert(6 * std::size_t(quad_count) <= QuadsIndices.size()); - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - if (textured) - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - glDrawElements(GL_TRIANGLES, 6 * quad_count, GL_UNSIGNED_SHORT, QuadsIndices.data()); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + drawArrays(GL_TRIANGLE_FAN, vertexType, vertices, 4); } - void COpenGL3Driver::drawArrays(GLenum type, const S3DVertex *vertices, int vertex_count, bool textured) + void COpenGL3Driver::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) { - glEnableVertexAttribArray(EVA_POSITION); - glEnableVertexAttribArray(EVA_COLOR); - if (textured) - glEnableVertexAttribArray(EVA_TCOORD0); - glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].Pos); - glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast(vertices))[0].Color); - glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast(vertices))[0].TCoords); - glDrawArrays(type, 0, vertex_count); - glDisableVertexAttribArray(EVA_TCOORD0); - glDisableVertexAttribArray(EVA_COLOR); - glDisableVertexAttribArray(EVA_POSITION); + beginDraw(vertexType, reinterpret_cast(vertices)); + glDrawArrays(primitiveType, 0, vertexCount); + endDraw(vertexType); } - void COpenGL3Driver::drawQuad(const S3DVertex (&vertices)[4], bool textured) + void COpenGL3Driver::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount) { - drawQuads(vertices, 1, textured); + beginDraw(vertexType, reinterpret_cast(vertices)); + glDrawElements(primitiveType, indexCount, GL_UNSIGNED_SHORT, indices); + endDraw(vertexType); + } + + void COpenGL3Driver::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) + { + for (auto attr: vertexType) { + glEnableVertexAttribArray(attr.Index); + switch (attr.mode) { + case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + } + } + } + + void COpenGL3Driver::endDraw(const VertexType &vertexType) + { + for (auto attr: vertexType) + glDisableVertexAttribArray(attr.Index); } ITexture* COpenGL3Driver::createDeviceDependentTexture(const io::path& name, IImage* image) @@ -1694,7 +1705,7 @@ COpenGL3Driver::~COpenGL3Driver() 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); - drawArrays(GL_LINES, vertices, 2, false); + drawArrays(GL_LINES, vtPrimitive, vertices, 2); } diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index b732595..6cbf7bd 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -20,6 +20,7 @@ namespace irr { namespace video { + struct VertexType; class COpenGL3FixedPipelineRenderer; class COpenGL3Renderer2D; @@ -329,9 +330,13 @@ namespace video //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` virtual void setViewPortRaw(u32 width, u32 height); - void drawQuad(const S3DVertex (&vertices)[4], bool textured); - void drawQuads(const S3DVertex *vertices, int quad_count, bool textured); - void drawArrays(GLenum type, const S3DVertex *vertices, int vertex_count, bool textured); + void drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]); + void drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount); + void drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount); + void drawElements(GLenum primitiveType, const VertexType &vertexType, uintptr_t vertices, uintptr_t indices, int indexCount); + + void beginDraw(const VertexType &vertexType, uintptr_t verticesBase); + void endDraw(const VertexType &vertexType); COpenGL3CacheHandler* CacheHandler; core::stringw Name; From 620f4869a173f1906b061fa5a0a4be518c292037 Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 2 Mar 2023 01:22:04 +0300 Subject: [PATCH 19/42] Drop obsolete video drivers --- include/EDriverTypes.h | 57 +------------------------------- include/SIrrCreationParameters.h | 2 +- include/irrlicht.h | 2 +- 3 files changed, 3 insertions(+), 58 deletions(-) diff --git a/include/EDriverTypes.h b/include/EDriverTypes.h index f5a2e92..1c23536 100644 --- a/include/EDriverTypes.h +++ b/include/EDriverTypes.h @@ -20,39 +20,12 @@ namespace video render and display any graphics. */ EDT_NULL, - //! The Irrlicht Engine Software renderer. - /** Runs on all platforms, with every hardware. It should only - be used for 2d graphics, but it can also perform some primitive - 3d functions. These 3d drawing functions are quite fast, but - very inaccurate, and don't even support clipping in 3D mode. */ - EDT_SOFTWARE, - - //! The Burning's Software Renderer, an alternative software renderer - /** Basically it can be described as the Irrlicht Software - renderer on steroids. It rasterizes 3D geometry perfectly: It - is able to perform correct 3d clipping, perspective correct - texture mapping, perspective correct color mapping, and renders - sub pixel correct, sub texel correct primitives. In addition, - it does bilinear texel filtering and supports more materials - than the EDT_SOFTWARE driver. This renderer has been written - entirely by Thomas Alten, thanks a lot for this huge - contribution. */ - EDT_BURNINGSVIDEO, - - //! Direct3D8 device is longer supported in Irrlicht. You have to go back to Irrlicht 1.8 if you still need that. - DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS, // keep enum to avoid breaking enumeration order (might be used in ini-files, serialization, etc) - - //! Direct3D 9 device, only available on Win32 platforms. - /** Performs hardware accelerated rendering of 3D and 2D - primitives. */ - EDT_DIRECT3D9, - //! OpenGL device, available on most platforms. /** Performs hardware accelerated rendering of 3D and 2D primitives. */ EDT_OPENGL, - //! OpenGL-ES 1.x driver, for embedded and mobile systems + //! OpenGL-ES 1.x driver, for embedded and mobile systems EDT_OGLES1, //! OpenGL-ES 2.x driver, for embedded and mobile systems @@ -66,34 +39,6 @@ namespace video EDT_COUNT }; - const c8* const DRIVER_TYPE_NAMES[] = - { - "NullDriver", - "Software Renderer", - "Burning's Video", - "Direct3D 8.1", - "Direct3D 9.0c", - "OpenGL 1.x/2.x/3.x", - "OpenGL ES1", - "OpenGL ES2", - "WebGL 1", - 0 - }; - - const c8* const DRIVER_TYPE_NAMES_SHORT[] = - { - "null", - "software", - "burning", - "d3d8", - "d3d9", - "opengl", - "ogles1", - "ogles2", - "webgl1", - 0 - }; - } // end namespace video } // end namespace irr diff --git a/include/SIrrCreationParameters.h b/include/SIrrCreationParameters.h index bad56e3..7439604 100644 --- a/include/SIrrCreationParameters.h +++ b/include/SIrrCreationParameters.h @@ -24,7 +24,7 @@ namespace irr //! Constructs a SIrrlichtCreationParameters structure with default values. SIrrlichtCreationParameters() : DeviceType(EIDT_BEST), - DriverType(video::EDT_BURNINGSVIDEO), + DriverType(video::EDT_OPENGL), WindowSize(core::dimension2d(800, 600)), WindowPosition(core::position2di(-1,-1)), Bits(32), diff --git a/include/irrlicht.h b/include/irrlicht.h index e099cf7..359f810 100644 --- a/include/irrlicht.h +++ b/include/irrlicht.h @@ -271,7 +271,7 @@ namespace irr device could not be created. */ extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice( - video::E_DRIVER_TYPE driverType = video::EDT_SOFTWARE, + video::E_DRIVER_TYPE driverType = video::EDT_OPENGL, // parentheses are necessary for some compilers const core::dimension2d& windowSize = (core::dimension2d(640,480)), u32 bits = 32, From d6716ec31b7399517655403d8963b7632bbbf6b3 Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 2 Mar 2023 02:41:58 +0300 Subject: [PATCH 20/42] Support GLES2 --- source/Irrlicht/COpenGLCoreRenderTarget.h | 12 ++++++++++-- source/Irrlicht/COpenGLCoreTexture.h | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/Irrlicht/COpenGLCoreRenderTarget.h b/source/Irrlicht/COpenGLCoreRenderTarget.h index 7dff3c9..f893c17 100644 --- a/source/Irrlicht/COpenGLCoreRenderTarget.h +++ b/source/Irrlicht/COpenGLCoreRenderTarget.h @@ -10,6 +10,14 @@ #include "IRenderTarget.h" +#ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT +#endif + namespace irr { namespace video @@ -351,10 +359,10 @@ protected: case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS: os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR); break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index c19215b..2ad8af1 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -433,9 +433,6 @@ public: else { #ifdef IRR_OPENGL_HAS_glGenerateMipmap - #if !defined(IRR_COMPILE_GLES2_COMMON) - glEnable(GL_TEXTURE_2D); // Hack some ATI cards need this glEnable according to https://www.khronos.org/opengl/wiki/Common_Mistakes - #endif Driver->irrGlGenerateMipmap(TextureType); #endif } From 1bbe341daa0649954b33a6be985e98d49418cbe3 Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 2 Mar 2023 02:42:29 +0300 Subject: [PATCH 21/42] Support both OpenGL3 and GLES2 on SDL2 --- include/EDriverTypes.h | 2 + source/Irrlicht/CIrrDeviceSDL.cpp | 257 ++++++++++++++---------------- 2 files changed, 125 insertions(+), 134 deletions(-) diff --git a/include/EDriverTypes.h b/include/EDriverTypes.h index 1c23536..0409757 100644 --- a/include/EDriverTypes.h +++ b/include/EDriverTypes.h @@ -35,6 +35,8 @@ namespace video //! WebGL1 friendly subset of OpenGL-ES 2.x driver for Emscripten EDT_WEBGL1, + EDT_OPENGL3, + //! No driver, just for counting the elements EDT_COUNT }; diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index a5ba6f6..48c5861 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -38,18 +38,37 @@ namespace irr { #ifdef _IRR_COMPILE_WITH_OPENGL_ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - #endif - - #ifdef _IRR_COMPILE_WITH_OGLES2_ - IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - #endif - - #ifdef _IRR_COMPILE_WITH_WEBGL1_ - IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + #else + static IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + { + os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); + return nullptr; + } #endif #ifdef ENABLE_OPENGL3 IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + #else + static IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + { + os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR); + return nullptr; + } + #endif + + static IVideoDriver* createOpenGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + { + return createOpenGL3Driver(params, io, contextManager); + } + + #ifdef _IRR_COMPILE_WITH_WEBGL1_ + IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + #else + static IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + { + os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR); + return nullptr; + } #endif } // end namespace video @@ -236,24 +255,6 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) // create keymap createKeyMap(); - if (CreationParams.Fullscreen) { - SDL_Flags |= SDL_WINDOW_FULLSCREEN; - } else { - if (Resizable) - SDL_Flags |= SDL_WINDOW_RESIZABLE; - if (CreationParams.WindowMaximized) - SDL_Flags |= SDL_WINDOW_MAXIMIZED; - } - if (CreationParams.DriverType == video::EDT_OPENGL) - { - SDL_Flags |= SDL_WINDOW_OPENGL; - if (!CreationParams.Doublebuffer) - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); - } -#ifdef _IRR_EMSCRIPTEN_PLATFORM_ - SDL_Flags |= SDL_WINDOW_OPENGL; -#endif //_IRR_EMSCRIPTEN_PLATFORM_ - // create window if (CreationParams.DriverType != video::EDT_NULL) { @@ -343,6 +344,16 @@ void CIrrDeviceSDL::logAttributes() bool CIrrDeviceSDL::createWindow() { + if (CreationParams.Fullscreen) { + SDL_Flags |= SDL_WINDOW_FULLSCREEN; + } else { + if (Resizable) + SDL_Flags |= SDL_WINDOW_RESIZABLE; + if (CreationParams.WindowMaximized) + SDL_Flags |= SDL_WINDOW_MAXIMIZED; + } + SDL_Flags |= SDL_WINDOW_OPENGL; + #ifdef _IRR_EMSCRIPTEN_PLATFORM_ if ( Width != 0 || Height != 0 ) emscripten_set_canvas_size( Width, Height); @@ -389,58 +400,73 @@ bool CIrrDeviceSDL::createWindow() if ( Close ) return false; - if (CreationParams.DriverType == video::EDT_OPENGL) { - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); - if (CreationParams.Bits == 16) { - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4); - SDL_GL_SetAttribute( - SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0); - } else { - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute( - SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0); - } - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits); - if (CreationParams.Doublebuffer) - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0); - if (CreationParams.Stereobuffer) - SDL_GL_SetAttribute(SDL_GL_STEREO, 1); - if (CreationParams.AntiAlias > 1) { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); - } - if (!Window) - Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); - if (!Window && CreationParams.AntiAlias > 1) { - while (--CreationParams.AntiAlias > 1) { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); - Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); - if (Window) - break; - } - if (!Window) { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); - Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); - if (Window) - os::Printer::log("AntiAliasing disabled due to lack of support!"); - } - } + switch (CreationParams.DriverType) { + case video::EDT_OPENGL: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + break; + case video::EDT_OPENGL3: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + 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:; + } - if (Window) - { - Context = SDL_GL_CreateContext(Window); - } - } else if (!Window) +#ifdef _DEBUG + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); +#endif + + if (CreationParams.Bits == 16) { + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0); + } else { + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0); + } + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0); + SDL_GL_SetAttribute(SDL_GL_STEREO, CreationParams.Stereobuffer); + if (CreationParams.AntiAlias > 1) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); + } + if (!Window) Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + if (!Window) { + os::Printer::log("Could not create window...", SDL_GetError(), ELL_WARNING); + } + if (!Window && CreationParams.AntiAlias > 1) { + while (--CreationParams.AntiAlias > 1) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias); + Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + if (Window) + break; + } + if (!Window) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); + if (Window) + os::Printer::log("AntiAliasing disabled due to lack of support!", ELL_WARNING); + } + } if ( !Window && CreationParams.Doublebuffer) { @@ -451,7 +477,14 @@ bool CIrrDeviceSDL::createWindow() } if ( !Window ) { - os::Printer::log( "Could not initialize display!" ); + os::Printer::log("Could not initialize display", SDL_GetError(), ELL_ERROR); + return false; + } + + Context = SDL_GL_CreateContext(Window); + if (!Context) { + os::Printer::log("Could not initialize context", SDL_GetError(), ELL_ERROR); + SDL_DestroyWindow(Window); return false; } @@ -463,66 +496,22 @@ bool CIrrDeviceSDL::createWindow() //! create the driver void CIrrDeviceSDL::createDriver() { + if (CreationParams.DriverType == video::EDT_NULL) { + VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); + return; + } + + ContextManager = new video::CSDLManager(this); switch(CreationParams.DriverType) { - case video::EDT_OPENGL: - #ifdef _IRR_COMPILE_WITH_OPENGL_ - ContextManager = new video::CSDLManager(this); - VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); - #else - os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); - #endif - break; - - case video::EDT_OGLES2: -#if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_) - { - video::SExposedVideoData data; - - ContextManager = new video::CEGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); - } -#else - os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR); -#endif - break; - - case video::EDT_WEBGL1: -#if defined(_IRR_COMPILE_WITH_WEBGL1_) && defined(_IRR_EMSCRIPTEN_PLATFORM_) - { - video::SExposedVideoData data; - - ContextManager = new video::CEGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); - } -#else - os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR); -#endif - break; - - case video::EDT_NULL: - VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); - break; - - default: - os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); - break; - } - - // In case we got the size from the canvas - if ( VideoDriver && CreationParams.WindowSize.Width == 0 && CreationParams.WindowSize.Height == 0 && Width > 0 && Height > 0 ) - { -#ifdef _IRR_EMSCRIPTEN_PLATFORM_ - SDL_CreateWindowAndRenderer(Width, Height, SDL_Flags, &Window, &Renderer); -#else //_IRR_EMSCRIPTEN_PLATFORM_ - Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags); -#endif //_IRR_EMSCRIPTEN_PLATFOR - VideoDriver->OnResize(core::dimension2d(Width, Height)); + case video::EDT_OPENGL: VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); break; + case video::EDT_OPENGL3: VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); break; + case video::EDT_OGLES2: VideoDriver = video::createOpenGLES2Driver(CreationParams, FileSystem, ContextManager); break; + case video::EDT_WEBGL1: VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); break; + default:; } + if (!VideoDriver) + os::Printer::log("Could not create video driver", ELL_ERROR); } From 1326dfbcb1f6e9f69f136dccd1e05f9bc30896f4 Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 2 Mar 2023 02:42:51 +0300 Subject: [PATCH 22/42] Error out on unsupported configurations --- source/Irrlicht/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index b78410c..4b3fa21 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -86,8 +86,7 @@ if(WIN32) elseif(IOS) add_definitions(-D_IRR_IOS_PLATFORM_ -D_IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_) if(USE_SDL2) - message(WARNING "SDL2 backend is not supported on iOS") - set(USE_SDL2 FALSE) + message(SEND_ERROR "SDL2 backend is not supported on iOS") endif() set(DEVICE "IOS") elseif(OSX) @@ -96,8 +95,7 @@ elseif(OSX) elseif(ANDROID) add_definitions(-D_IRR_ANDROID_PLATFORM_ -D_IRR_COMPILE_ANDROID_ASSET_READER_) if(USE_SDL2) - message(WARNING "SDL2 backend is not supported on Android") - set(USE_SDL2 FALSE) + message(SEND_ERROR "SDL2 backend is not supported on Android") endif() set(DEVICE "Android") elseif(EMSCRIPTEN) From 29320653463045fad20d6681cef563a37a1aeb9e Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 2 Mar 2023 03:03:17 +0300 Subject: [PATCH 23/42] Report as OpenGL 3 --- source/Irrlicht/OpenGL/Driver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index baa6f44..6a60316 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1722,7 +1722,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Returns type of video driver E_DRIVER_TYPE COpenGL3Driver::getDriverType() const { - return EDT_OGLES2; + return EDT_OPENGL3; } @@ -1905,9 +1905,9 @@ COpenGL3Driver::~COpenGL3Driver() bool COpenGL3Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { - if (target && target->getDriverType() != EDT_OGLES2 && target->getDriverType() != EDT_WEBGL1) + if (target && target->getDriverType() != EDT_OPENGL3) { - os::Printer::log("Fatal Error: Tried to set a render target not owned by OGLES2 driver.", ELL_ERROR); + os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL 3 driver.", ELL_ERROR); return false; } From 8dd8652f5ff3b046229a3e8ce299271a209375f3 Mon Sep 17 00:00:00 2001 From: numzero Date: Fri, 3 Mar 2023 20:29:36 +0300 Subject: [PATCH 24/42] Split new GL3/GLES2 drivers The classes are tiny wrappers currently but should they be customized, they are there --- source/Irrlicht/CIrrDeviceSDL.cpp | 11 +- source/Irrlicht/CMakeLists.txt | 44 +++-- source/Irrlicht/OpenGL/Common.h | 8 +- source/Irrlicht/OpenGL/Driver.cpp | 180 ++++++++++---------- source/Irrlicht/OpenGL/Driver.h | 9 +- source/Irrlicht/OpenGL/MaterialRenderer.cpp | 4 +- source/Irrlicht/OpenGL/MaterialRenderer.h | 8 +- source/Irrlicht/OpenGL/Renderer2D.cpp | 2 +- source/Irrlicht/OpenGL/Renderer2D.h | 2 +- source/Irrlicht/OpenGL3/Driver.cpp | 22 +++ source/Irrlicht/OpenGL3/Driver.h | 19 +++ source/Irrlicht/OpenGLES2/Driver.cpp | 22 +++ source/Irrlicht/OpenGLES2/Driver.h | 19 +++ 13 files changed, 226 insertions(+), 124 deletions(-) create mode 100644 source/Irrlicht/OpenGL3/Driver.cpp create mode 100644 source/Irrlicht/OpenGL3/Driver.h create mode 100644 source/Irrlicht/OpenGLES2/Driver.cpp create mode 100644 source/Irrlicht/OpenGLES2/Driver.h diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 48c5861..6ebf63b 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -56,10 +56,15 @@ namespace irr } #endif - static IVideoDriver* createOpenGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + #ifdef _IRR_COMPILE_WITH_OGLES2_ + IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + #else + static IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { - return createOpenGL3Driver(params, io, contextManager); + os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR); + return nullptr; } + #endif #ifdef _IRR_COMPILE_WITH_WEBGL1_ IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); @@ -506,7 +511,7 @@ void CIrrDeviceSDL::createDriver() { case video::EDT_OPENGL: VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); break; case video::EDT_OPENGL3: VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); break; - case video::EDT_OGLES2: VideoDriver = video::createOpenGLES2Driver(CreationParams, FileSystem, ContextManager); break; + case video::EDT_OGLES2: VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); break; case video::EDT_WEBGL1: VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); break; default:; } diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 4b3fa21..a2ca46e 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -198,6 +198,14 @@ if(ENABLE_OPENGL) endif() endif() +if(ENABLE_OPENGL3) + if (NOT USE_SDL2) + message(SEND_ERROR "OpenGL3 support requires SDL2") + endif() + set(USE_SDLGL ON) + set(USE_SDLGL3 ON) +endif() + if(ENABLE_GLES1) add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) if(DEVICE MATCHES "^WINDOWS|X11|ANDROID$") @@ -213,6 +221,9 @@ if(ENABLE_GLES2) add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_ -D_IRR_OGLES2_USE_EXTPOINTER_) elseif(DEVICE STREQUAL "IOS") add_definitions(-D_IRR_COMPILE_WITH_EAGL_MANAGER_) + elseif(DEVICE STREQUAL "SDL") + set(USE_SDLGL ON) + set(USE_SDLGLES2 ON) endif() endif() @@ -232,6 +243,7 @@ endif() message(STATUS "Device: ${DEVICE}") message(STATUS "OpenGL: ${ENABLE_OPENGL}") +message(STATUS "OpenGL 3: ${ENABLE_OPENGL3}") message(STATUS "OpenGL ES: ${ENABLE_GLES1}") message(STATUS "OpenGL ES 2: ${ENABLE_GLES2}") message(STATUS "WebGL: ${ENABLE_WEBGL1}") @@ -353,12 +365,6 @@ set(IRRDRVROBJ COpenGLExtensionHandler.cpp COGLESDriver.cpp COGLESExtensionHandler.cpp - COGLES2Driver.cpp - COGLES2ExtensionHandler.cpp - COGLES2FixedPipelineRenderer.cpp - COGLES2MaterialRenderer.cpp - COGLES2Renderer2D.cpp - CWebGL1Driver.cpp CGLXManager.cpp CWGLManager.cpp CEGLManager.cpp @@ -383,10 +389,7 @@ add_library(IRRVIDEOOBJ OBJECT ${IRRIMAGEOBJ} ) -if(ENABLE_OPENGL3) - if (NOT USE_SDL2) - message(SEND_ERROR "OpenGL3 support requires SDL2") - endif() +if(USE_SDLGL) target_sources(IRRVIDEOOBJ PUBLIC OpenGL/Driver.cpp OpenGL/ExtensionHandler.cpp @@ -396,6 +399,27 @@ if(ENABLE_OPENGL3) ) endif() +if(USE_SDLGL3) + target_sources(IRRVIDEOOBJ PUBLIC + OpenGL3/Driver.cpp + ) +endif() + +if(USE_SDLGLES2) + target_sources(IRRVIDEOOBJ PUBLIC + OpenGLES2/Driver.cpp + ) +else() + target_sources(IRRVIDEOOBJ PUBLIC + COGLES2Driver.cpp + COGLES2ExtensionHandler.cpp + COGLES2FixedPipelineRenderer.cpp + COGLES2MaterialRenderer.cpp + COGLES2Renderer2D.cpp + CWebGL1Driver.cpp + ) +endif() + add_library(IRRIOOBJ OBJECT CFileList.cpp CFileSystem.cpp diff --git a/source/Irrlicht/OpenGL/Common.h b/source/Irrlicht/OpenGL/Common.h index 3f71f65..a69bcc6 100644 --- a/source/Irrlicht/OpenGL/Common.h +++ b/source/Irrlicht/OpenGL/Common.h @@ -27,10 +27,10 @@ namespace video template class COpenGLCoreCacheHandler; - class COpenGL3Driver; - typedef COpenGLCoreTexture COpenGL3Texture; - typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; - typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; + class COpenGL3DriverBase; + typedef COpenGLCoreTexture COpenGL3Texture; + typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; + typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; } } diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 6a60316..27ab1ba 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -123,17 +123,17 @@ namespace video }; -void APIENTRY COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +void APIENTRY COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { - ((COpenGL3Driver *)userParam)->debugCb(source, type, id, severity, length, message); + ((COpenGL3DriverBase *)userParam)->debugCb(source, type, id, severity, length, message); } -void COpenGL3Driver::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) +void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) { printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); } -COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : +COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), @@ -158,7 +158,7 @@ COpenGL3Driver::COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IF initQuadsIndices(); } -COpenGL3Driver::~COpenGL3Driver() +COpenGL3DriverBase::~COpenGL3DriverBase() { deleteMaterialRenders(); @@ -182,7 +182,7 @@ COpenGL3Driver::~COpenGL3Driver() } } - void COpenGL3Driver::initQuadsIndices(int max_vertex_count) + void COpenGL3DriverBase::initQuadsIndices(int max_vertex_count) { int max_quad_count = max_vertex_count / 4; QuadsIndices.reserve(6 * max_quad_count); @@ -196,7 +196,7 @@ COpenGL3Driver::~COpenGL3Driver() } } - bool COpenGL3Driver::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) + bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) { Name = glGetString(GL_VERSION); printVersion(); @@ -261,7 +261,7 @@ COpenGL3Driver::~COpenGL3Driver() return true; } - void COpenGL3Driver::loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData) + void COpenGL3DriverBase::loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData) { io::path vsPath(OGLES2ShaderPath); vsPath += vertexShaderName; @@ -316,7 +316,7 @@ COpenGL3Driver::~COpenGL3Driver() fsFile->drop(); } - void COpenGL3Driver::createMaterialRenderers() + void COpenGL3DriverBase::createMaterialRenderers() { // Create callbacks. @@ -469,13 +469,13 @@ COpenGL3Driver::~COpenGL3Driver() delete[] fs2DData; } - bool COpenGL3Driver::setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture) + bool COpenGL3DriverBase::setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture) { Material.TextureLayer[layerIdx].Texture = const_cast(texture); // function uses const-pointer for texture because all draw functions use const-pointers already return CacheHandler->getTextureCache().set(0, texture); } - bool COpenGL3Driver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData& videoData, core::rect* sourceRect) + bool COpenGL3DriverBase::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData& videoData, core::rect* sourceRect) { CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect); @@ -487,7 +487,7 @@ COpenGL3Driver::~COpenGL3Driver() return true; } - bool COpenGL3Driver::endScene() + bool COpenGL3DriverBase::endScene() { CNullDriver::endScene(); @@ -501,21 +501,21 @@ COpenGL3Driver::~COpenGL3Driver() //! Returns the transformation set by setTransform - const core::matrix4& COpenGL3Driver::getTransform(E_TRANSFORMATION_STATE state) const + const core::matrix4& COpenGL3DriverBase::getTransform(E_TRANSFORMATION_STATE state) const { return Matrices[state]; } //! sets transformation - void COpenGL3Driver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) + void COpenGL3DriverBase::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) { Matrices[state] = mat; Transformation3DChanged = true; } - bool COpenGL3Driver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) + bool COpenGL3DriverBase::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) { if (!HWBuffer) return false; @@ -563,7 +563,7 @@ COpenGL3Driver::~COpenGL3Driver() } - bool COpenGL3Driver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) + bool COpenGL3DriverBase::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) { if (!HWBuffer) return false; @@ -627,7 +627,7 @@ COpenGL3Driver::~COpenGL3Driver() //! updates hardware buffer if needed - bool COpenGL3Driver::updateHardwareBuffer(SHWBufferLink *HWBuffer) + bool COpenGL3DriverBase::updateHardwareBuffer(SHWBufferLink *HWBuffer) { if (!HWBuffer) return false; @@ -663,7 +663,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Create hardware buffer from meshbuffer - COpenGL3Driver::SHWBufferLink *COpenGL3Driver::createHardwareBuffer(const scene::IMeshBuffer* mb) + COpenGL3DriverBase::SHWBufferLink *COpenGL3DriverBase::createHardwareBuffer(const scene::IMeshBuffer* mb) { if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) return 0; @@ -692,7 +692,7 @@ COpenGL3Driver::~COpenGL3Driver() } - void COpenGL3Driver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) + void COpenGL3DriverBase::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) { if (!_HWBuffer) return; @@ -714,7 +714,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Draw hardware buffer - void COpenGL3Driver::drawHardwareBuffer(SHWBufferLink *_HWBuffer) + void COpenGL3DriverBase::drawHardwareBuffer(SHWBufferLink *_HWBuffer) { if (!_HWBuffer) return; @@ -753,7 +753,7 @@ COpenGL3Driver::~COpenGL3Driver() } - IRenderTarget* COpenGL3Driver::addRenderTarget() + IRenderTarget* COpenGL3DriverBase::addRenderTarget() { COpenGL3RenderTarget* renderTarget = new COpenGL3RenderTarget(this); RenderTargets.push_back(renderTarget); @@ -770,7 +770,7 @@ COpenGL3Driver::~COpenGL3Driver() //! draws a vertex primitive list - void COpenGL3Driver::drawVertexPrimitiveList(const void* vertices, u32 vertexCount, + void COpenGL3DriverBase::drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) { @@ -842,7 +842,7 @@ COpenGL3Driver::~COpenGL3Driver() } - void COpenGL3Driver::draw2DImage(const video::ITexture* texture, const core::position2d& destPos, + void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, const core::position2d& destPos, const core::rect& sourceRect, const core::rect* clipRect, SColor color, bool useAlphaChannelOfTexture) { @@ -857,7 +857,7 @@ COpenGL3Driver::~COpenGL3Driver() } - void COpenGL3Driver::draw2DImage(const video::ITexture* texture, const core::rect& destRect, + void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, const core::rect& destRect, const core::rect& sourceRect, const core::rect* clipRect, const video::SColor* const colors, bool useAlphaChannelOfTexture) { @@ -924,7 +924,7 @@ COpenGL3Driver::~COpenGL3Driver() testGLError(__LINE__); } - void COpenGL3Driver::draw2DImage(const video::ITexture* texture, u32 layer, bool flip) + void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, u32 layer, bool flip) { if (!texture) return; @@ -957,7 +957,7 @@ COpenGL3Driver::~COpenGL3Driver() drawQuad(vt2DImage, quad2DVertices); } - void COpenGL3Driver::draw2DImageBatch(const video::ITexture* texture, + void COpenGL3DriverBase::draw2DImageBatch(const video::ITexture* texture, const core::array >& positions, const core::array >& sourceRects, const core::rect* clipRect, @@ -1033,7 +1033,7 @@ COpenGL3Driver::~COpenGL3Driver() //! draw a 2d rectangle - void COpenGL3Driver::draw2DRectangle(SColor color, + void COpenGL3DriverBase::draw2DRectangle(SColor color, const core::rect& position, const core::rect* clip) { @@ -1068,7 +1068,7 @@ COpenGL3Driver::~COpenGL3Driver() //! draw an 2d rectangle - void COpenGL3Driver::draw2DRectangle(const core::rect& position, + void COpenGL3DriverBase::draw2DRectangle(const core::rect& position, SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, const core::rect* clip) @@ -1107,7 +1107,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Draws a 2d line. - void COpenGL3Driver::draw2DLine(const core::position2d& start, + void COpenGL3DriverBase::draw2DLine(const core::position2d& start, const core::position2d& end, SColor color) { if (start==end) @@ -1136,7 +1136,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Draws a pixel - void COpenGL3Driver::drawPixel(u32 x, u32 y, const SColor &color) + void COpenGL3DriverBase::drawPixel(u32 x, u32 y, const SColor &color) { const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) @@ -1156,26 +1156,26 @@ COpenGL3Driver::~COpenGL3Driver() drawArrays(GL_POINTS, vtPrimitive, vertices, 1); } - void COpenGL3Driver::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) + void COpenGL3DriverBase::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) { drawArrays(GL_TRIANGLE_FAN, vertexType, vertices, 4); } - void COpenGL3Driver::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) + void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) { beginDraw(vertexType, reinterpret_cast(vertices)); glDrawArrays(primitiveType, 0, vertexCount); endDraw(vertexType); } - void COpenGL3Driver::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount) + void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount) { beginDraw(vertexType, reinterpret_cast(vertices)); glDrawElements(primitiveType, indexCount, GL_UNSIGNED_SHORT, indices); endDraw(vertexType); } - void COpenGL3Driver::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) + void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) { for (auto attr: vertexType) { glEnableVertexAttribArray(attr.Index); @@ -1187,13 +1187,13 @@ COpenGL3Driver::~COpenGL3Driver() } } - void COpenGL3Driver::endDraw(const VertexType &vertexType) + void COpenGL3DriverBase::endDraw(const VertexType &vertexType) { for (auto attr: vertexType) glDisableVertexAttribArray(attr.Index); } - ITexture* COpenGL3Driver::createDeviceDependentTexture(const io::path& name, IImage* image) + ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) { core::array imageArray(1); imageArray.push_back(image); @@ -1203,7 +1203,7 @@ COpenGL3Driver::~COpenGL3Driver() return texture; } - ITexture* COpenGL3Driver::createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) + ITexture* COpenGL3DriverBase::createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) { COpenGL3Texture* texture = new COpenGL3Texture(name, image, ETT_CUBEMAP, this); @@ -1211,7 +1211,7 @@ COpenGL3Driver::~COpenGL3Driver() } //! Sets a material. - void COpenGL3Driver::setMaterial(const SMaterial& material) + void COpenGL3DriverBase::setMaterial(const SMaterial& material) { Material = material; OverrideMaterial.apply(Material); @@ -1224,7 +1224,7 @@ COpenGL3Driver::~COpenGL3Driver() } //! prints error if an error happened. - bool COpenGL3Driver::testGLError(int code) + bool COpenGL3DriverBase::testGLError(int code) { #ifdef _DEBUG GLenum g = glGetError(); @@ -1252,7 +1252,7 @@ COpenGL3Driver::~COpenGL3Driver() } //! prints error if an error happened. - bool COpenGL3Driver::testEGLError() + bool COpenGL3DriverBase::testEGLError() { #if defined(EGL_VERSION_1_0) && defined(_DEBUG) EGLint g = eglGetError(); @@ -1310,7 +1310,7 @@ COpenGL3Driver::~COpenGL3Driver() } - void COpenGL3Driver::setRenderStates3DMode() + void COpenGL3DriverBase::setRenderStates3DMode() { if ( LockRenderStateMode ) return; @@ -1355,7 +1355,7 @@ COpenGL3Driver::~COpenGL3Driver() } //! Can be called by an IMaterialRenderer to make its work easier. - void COpenGL3Driver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates) + void COpenGL3DriverBase::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates) { // ZBuffer switch (material.ZBuffer) @@ -1493,7 +1493,7 @@ COpenGL3Driver::~COpenGL3Driver() } //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. - void COpenGL3Driver::setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates) + void COpenGL3DriverBase::setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates) { // Set textures to TU/TIU and apply filters to them @@ -1579,7 +1579,7 @@ COpenGL3Driver::~COpenGL3Driver() // Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode. - GLint COpenGL3Driver::getTextureWrapMode(u8 clamp) const + GLint COpenGL3DriverBase::getTextureWrapMode(u8 clamp) const { switch (clamp) { @@ -1596,7 +1596,7 @@ COpenGL3Driver::~COpenGL3Driver() //! sets the needed renderstates - void COpenGL3Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) + void COpenGL3DriverBase::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) { if ( LockRenderStateMode ) return; @@ -1652,7 +1652,7 @@ COpenGL3Driver::~COpenGL3Driver() } - void COpenGL3Driver::chooseMaterial2D() + void COpenGL3DriverBase::chooseMaterial2D() { if (!OverrideMaterial2DEnabled) Material = InitMaterial2D; @@ -1670,12 +1670,12 @@ COpenGL3Driver::~COpenGL3Driver() //! \return Returns the name of the video driver. - const wchar_t* COpenGL3Driver::getName() const + const wchar_t* COpenGL3DriverBase::getName() const { return Name.c_str(); } - void COpenGL3Driver::setViewPort(const core::rect& area) + void COpenGL3DriverBase::setViewPort(const core::rect& area) { core::rect vp = area; core::rect rendert(0, 0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); @@ -1688,7 +1688,7 @@ COpenGL3Driver::~COpenGL3Driver() } - void COpenGL3Driver::setViewPortRaw(u32 width, u32 height) + void COpenGL3DriverBase::setViewPortRaw(u32 width, u32 height) { CacheHandler->setViewport(0, 0, width, height); ViewPort = core::recti(0, 0, width, height); @@ -1696,7 +1696,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Draws a 3d line. - void COpenGL3Driver::draw3DLine(const core::vector3df& start, + void COpenGL3DriverBase::draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color) { setRenderStates3DMode(); @@ -1711,7 +1711,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Only used by the internal engine. Used to notify the driver that //! the window was resized. - void COpenGL3Driver::OnResize(const core::dimension2d& size) + void COpenGL3DriverBase::OnResize(const core::dimension2d& size) { CNullDriver::OnResize(size); CacheHandler->setViewport(0, 0, size.Width, size.Height); @@ -1720,79 +1720,79 @@ COpenGL3Driver::~COpenGL3Driver() //! Returns type of video driver - E_DRIVER_TYPE COpenGL3Driver::getDriverType() const + E_DRIVER_TYPE COpenGL3DriverBase::getDriverType() const { return EDT_OPENGL3; } //! returns color format - ECOLOR_FORMAT COpenGL3Driver::getColorFormat() const + ECOLOR_FORMAT COpenGL3DriverBase::getColorFormat() const { return ColorFormat; } //! Get a vertex shader constant index. - s32 COpenGL3Driver::getVertexShaderConstantID(const c8* name) + s32 COpenGL3DriverBase::getVertexShaderConstantID(const c8* name) { return getPixelShaderConstantID(name); } //! Get a pixel shader constant index. - s32 COpenGL3Driver::getPixelShaderConstantID(const c8* name) + s32 COpenGL3DriverBase::getPixelShaderConstantID(const c8* name) { os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID()."); return -1; } //! Sets a vertex shader constant. - void COpenGL3Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) + void COpenGL3DriverBase::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) { os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setPixelShaderConstant()."); } //! Sets a pixel shader constant. - void COpenGL3Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) + void COpenGL3DriverBase::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) { os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); } //! Sets a constant for the vertex shader based on an index. - bool COpenGL3Driver::setVertexShaderConstant(s32 index, const f32* floats, int count) + bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const f32* floats, int count) { os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); return false; } //! Int interface for the above. - bool COpenGL3Driver::setVertexShaderConstant(s32 index, const s32* ints, int count) + bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const s32* ints, int count) { os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); return false; } - bool COpenGL3Driver::setVertexShaderConstant(s32 index, const u32* ints, int count) + bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const u32* ints, int count) { os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); return false; } //! Sets a constant for the pixel shader based on an index. - bool COpenGL3Driver::setPixelShaderConstant(s32 index, const f32* floats, int count) + bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const f32* floats, int count) { os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); return false; } //! Int interface for the above. - bool COpenGL3Driver::setPixelShaderConstant(s32 index, const s32* ints, int count) + bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const s32* ints, int count) { os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); return false; } - bool COpenGL3Driver::setPixelShaderConstant(s32 index, const u32* ints, int count) + bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const u32* ints, int count) { os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); return false; @@ -1800,7 +1800,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Adds a new material renderer to the VideoDriver, using pixel and/or //! vertex shaders to render geometry. - s32 COpenGL3Driver::addShaderMaterial(const c8* vertexShaderProgram, + s32 COpenGL3DriverBase::addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram, IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData) @@ -1811,7 +1811,7 @@ COpenGL3Driver::~COpenGL3Driver() //! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. - s32 COpenGL3Driver::addHighLevelShaderMaterial( + s32 COpenGL3DriverBase::addHighLevelShaderMaterial( const c8* vertexShaderProgram, const c8* vertexShaderEntryPointName, E_VERTEX_SHADER_TYPE vsCompileTarget, @@ -1840,19 +1840,19 @@ COpenGL3Driver::~COpenGL3Driver() //! Returns a pointer to the IVideoDriver interface. (Implementation for //! IMaterialRendererServices) - IVideoDriver* COpenGL3Driver::getVideoDriver() + IVideoDriver* COpenGL3DriverBase::getVideoDriver() { return this; } //! Returns pointer to the IGPUProgrammingServices interface. - IGPUProgrammingServices* COpenGL3Driver::getGPUProgrammingServices() + IGPUProgrammingServices* COpenGL3DriverBase::getGPUProgrammingServices() { return this; } - ITexture* COpenGL3Driver::addRenderTargetTexture(const core::dimension2d& size, + ITexture* COpenGL3DriverBase::addRenderTargetTexture(const core::dimension2d& size, const io::path& name, const ECOLOR_FORMAT format) { //disable mip-mapping @@ -1869,7 +1869,7 @@ COpenGL3Driver::~COpenGL3Driver() return renderTargetTexture; } - ITexture* COpenGL3Driver::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path& name, const ECOLOR_FORMAT format) + ITexture* COpenGL3DriverBase::addRenderTargetTextureCubemap(const irr::u32 sideLen, const io::path& name, const ECOLOR_FORMAT format) { //disable mip-mapping bool generateMipLevels = getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); @@ -1898,14 +1898,14 @@ COpenGL3Driver::~COpenGL3Driver() //! Returns the maximum amount of primitives - u32 COpenGL3Driver::getMaximalPrimitiveCount() const + u32 COpenGL3DriverBase::getMaximalPrimitiveCount() const { return 65535; } - bool COpenGL3Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) + bool COpenGL3DriverBase::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { - if (target && target->getDriverType() != EDT_OPENGL3) + if (target && target->getDriverType() != getDriverType()) { os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL 3 driver.", ELL_ERROR); return false; @@ -1947,7 +1947,7 @@ COpenGL3Driver::~COpenGL3Driver() return true; } - void COpenGL3Driver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) + void COpenGL3DriverBase::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) { GLbitfield mask = 0; u8 colorMask = 0; @@ -1992,7 +1992,7 @@ COpenGL3Driver::~COpenGL3Driver() // 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* COpenGL3Driver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) + IImage* COpenGL3DriverBase::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; @@ -2078,14 +2078,14 @@ COpenGL3Driver::~COpenGL3Driver() return newImage; } - void COpenGL3Driver::removeTexture(ITexture* texture) + void COpenGL3DriverBase::removeTexture(ITexture* texture) { CacheHandler->getTextureCache().remove(texture); CNullDriver::removeTexture(texture); } //! Set/unset a clipping plane. - bool COpenGL3Driver::setClipPlane(u32 index, const core::plane3df& plane, bool enable) + bool COpenGL3DriverBase::setClipPlane(u32 index, const core::plane3df& plane, bool enable) { if (index >= UserClipPlane.size()) UserClipPlane.push_back(SUserClipPlane()); @@ -2096,18 +2096,18 @@ COpenGL3Driver::~COpenGL3Driver() } //! Enable/disable a clipping plane. - void COpenGL3Driver::enableClipPlane(u32 index, bool enable) + void COpenGL3DriverBase::enableClipPlane(u32 index, bool enable) { UserClipPlane[index].Enabled = enable; } //! Get the ClipPlane Count - u32 COpenGL3Driver::getClipPlaneCount() const + u32 COpenGL3DriverBase::getClipPlaneCount() const { return UserClipPlane.size(); } - const core::plane3df& COpenGL3Driver::getClipPlane(irr::u32 index) const + const core::plane3df& COpenGL3DriverBase::getClipPlane(irr::u32 index) const { if (index < UserClipPlane.size()) return UserClipPlane[index].Plane; @@ -2119,12 +2119,12 @@ COpenGL3Driver::~COpenGL3Driver() } } - core::dimension2du COpenGL3Driver::getMaxTextureSize() const + core::dimension2du COpenGL3DriverBase::getMaxTextureSize() const { return core::dimension2du(MaxTextureSize, MaxTextureSize); } - GLenum COpenGL3Driver::getGLBlend(E_BLEND_FACTOR factor) const + GLenum COpenGL3DriverBase::getGLBlend(E_BLEND_FACTOR factor) const { static GLenum const blendTable[] = { @@ -2144,7 +2144,7 @@ COpenGL3Driver::~COpenGL3Driver() return blendTable[factor]; } - bool COpenGL3Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, + bool COpenGL3DriverBase::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, GLenum& pixelType, void(**converter)(const void*, s32, void*)) const { bool supported = false; @@ -2360,7 +2360,7 @@ COpenGL3Driver::~COpenGL3Driver() return supported; } - bool COpenGL3Driver::queryTextureFormat(ECOLOR_FORMAT format) const + bool COpenGL3DriverBase::queryTextureFormat(ECOLOR_FORMAT format) const { GLint dummyInternalFormat; GLenum dummyPixelFormat; @@ -2369,28 +2369,20 @@ COpenGL3Driver::~COpenGL3Driver() return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter); } - bool COpenGL3Driver::needsTransparentRenderPass(const irr::video::SMaterial& material) const + bool COpenGL3DriverBase::needsTransparentRenderPass(const irr::video::SMaterial& material) const { return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); } - const SMaterial& COpenGL3Driver::getCurrentMaterial() const + const SMaterial& COpenGL3DriverBase::getCurrentMaterial() const { return Material; } - COpenGL3CacheHandler* COpenGL3Driver::getCacheHandler() const + COpenGL3CacheHandler* COpenGL3DriverBase::getCacheHandler() const { return CacheHandler; } - -IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) -{ - COpenGL3Driver* driver = new COpenGL3Driver(params, io, contextManager); - driver->genericDriverInit(params.WindowSize, params.Stencilbuffer); // don't call in constructor, it uses virtual function calls of driver - return driver; -} - } // end namespace } // end namespace diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 6cbf7bd..e95a633 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -25,19 +25,18 @@ namespace video class COpenGL3FixedPipelineRenderer; class COpenGL3Renderer2D; - class COpenGL3Driver : public CNullDriver, public IMaterialRendererServices, public COpenGL3ExtensionHandler + class COpenGL3DriverBase : public CNullDriver, public IMaterialRendererServices, public COpenGL3ExtensionHandler { - friend class COpenGLCoreTexture; - friend IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + friend class COpenGLCoreTexture; protected: //! constructor (use createOpenGL3Driver instead) - COpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); public: //! destructor - virtual ~COpenGL3Driver(); + virtual ~COpenGL3DriverBase(); 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; diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.cpp b/source/Irrlicht/OpenGL/MaterialRenderer.cpp index 080835c..20d684c 100644 --- a/source/Irrlicht/OpenGL/MaterialRenderer.cpp +++ b/source/Irrlicht/OpenGL/MaterialRenderer.cpp @@ -21,7 +21,7 @@ namespace video { -COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3Driver* driver, +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, @@ -57,7 +57,7 @@ COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3Driver* driver, } -COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3Driver* driver, +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData) : Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.h b/source/Irrlicht/OpenGL/MaterialRenderer.h index f45e725..dbac6cf 100644 --- a/source/Irrlicht/OpenGL/MaterialRenderer.h +++ b/source/Irrlicht/OpenGL/MaterialRenderer.h @@ -18,14 +18,14 @@ namespace irr namespace video { -class COpenGL3Driver; +class COpenGL3DriverBase; class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices { public: COpenGL3MaterialRenderer( - COpenGL3Driver* driver, + COpenGL3DriverBase* driver, s32& outMaterialTypeNr, const c8* vertexShaderProgram = 0, const c8* pixelShaderProgram = 0, @@ -65,7 +65,7 @@ public: protected: - COpenGL3MaterialRenderer(COpenGL3Driver* driver, + COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, IShaderConstantSetCallBack* callback = 0, E_MATERIAL_TYPE baseMaterial = EMT_SOLID, s32 userData = 0); @@ -75,7 +75,7 @@ protected: bool createShader(GLenum shaderType, const char* shader); bool linkProgram(); - COpenGL3Driver* Driver; + COpenGL3DriverBase* Driver; IShaderConstantSetCallBack* CallBack; bool Alpha; diff --git a/source/Irrlicht/OpenGL/Renderer2D.cpp b/source/Irrlicht/OpenGL/Renderer2D.cpp index d0a2c0a..8bedb17 100644 --- a/source/Irrlicht/OpenGL/Renderer2D.cpp +++ b/source/Irrlicht/OpenGL/Renderer2D.cpp @@ -18,7 +18,7 @@ namespace irr namespace video { -COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3Driver* driver, bool withTexture) : +COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture) : COpenGL3MaterialRenderer(driver, 0, EMT_SOLID), WithTexture(withTexture) { diff --git a/source/Irrlicht/OpenGL/Renderer2D.h b/source/Irrlicht/OpenGL/Renderer2D.h index 8df192b..806d1e7 100644 --- a/source/Irrlicht/OpenGL/Renderer2D.h +++ b/source/Irrlicht/OpenGL/Renderer2D.h @@ -14,7 +14,7 @@ namespace video class COpenGL3Renderer2D : public COpenGL3MaterialRenderer { public: - COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3Driver* driver, bool withTexture); + COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture); ~COpenGL3Renderer2D(); virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp new file mode 100644 index 0000000..925c6ea --- /dev/null +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" + +namespace irr { +namespace video { + + E_DRIVER_TYPE COpenGL3Driver::getDriverType() const { + return EDT_OPENGL3; + } + + IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + { + COpenGL3Driver* driver = new COpenGL3Driver(params, io, contextManager); + driver->genericDriverInit(params.WindowSize, params.Stencilbuffer); // don't call in constructor, it uses virtual function calls of driver + return driver; + } + +} +} diff --git a/source/Irrlicht/OpenGL3/Driver.h b/source/Irrlicht/OpenGL3/Driver.h new file mode 100644 index 0000000..cb30432 --- /dev/null +++ b/source/Irrlicht/OpenGL3/Driver.h @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once +#include "OpenGL/Driver.h" + +namespace irr { +namespace video { + + class COpenGL3Driver : public COpenGL3DriverBase { + friend IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + public: + using COpenGL3DriverBase::COpenGL3DriverBase; + E_DRIVER_TYPE getDriverType() const override; + }; + +} +} diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp new file mode 100644 index 0000000..2b03464 --- /dev/null +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" + +namespace irr { +namespace video { + + E_DRIVER_TYPE COpenGLES2Driver::getDriverType() const { + return EDT_OGLES2; + } + + IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) + { + COpenGLES2Driver* driver = new COpenGLES2Driver(params, io, contextManager); + driver->genericDriverInit(params.WindowSize, params.Stencilbuffer); // don't call in constructor, it uses virtual function calls of driver + return driver; + } + +} +} diff --git a/source/Irrlicht/OpenGLES2/Driver.h b/source/Irrlicht/OpenGLES2/Driver.h new file mode 100644 index 0000000..cdfb2fe --- /dev/null +++ b/source/Irrlicht/OpenGLES2/Driver.h @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once +#include "OpenGL/Driver.h" + +namespace irr { +namespace video { + + class COpenGLES2Driver : public COpenGL3DriverBase { + friend IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + public: + using COpenGL3DriverBase::COpenGL3DriverBase; + E_DRIVER_TYPE getDriverType() const override; + }; + +} +} From df28a4cc46dd2c3dc306351019ab3d36c4968ca3 Mon Sep 17 00:00:00 2001 From: numzero Date: Fri, 3 Mar 2023 21:23:07 +0300 Subject: [PATCH 25/42] Fix ifdefs around includes in CIrrDeviceSDL --- source/Irrlicht/CIrrDeviceSDL.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 6ebf63b..ecd8a8d 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -20,15 +20,10 @@ #include #ifdef _IRR_EMSCRIPTEN_PLATFORM_ -#ifdef _IRR_COMPILE_WITH_OGLES2_ -#include "CEGLManager.h" -#endif #include #endif -#ifdef _IRR_COMPILE_WITH_OPENGL_ #include "CSDLManager.h" -#endif static int SDLDeviceInstances = 0; From 2e9ed529b1d4eb486cdde320b9564c711ba1e508 Mon Sep 17 00:00:00 2001 From: numzero Date: Fri, 3 Mar 2023 21:59:11 +0300 Subject: [PATCH 26/42] =?UTF-8?q?Restore=20obsolete=20constants=20as=20the?= =?UTF-8?q?y=20are=20still=20used=20in=20some=20code=20I=20don=E2=80=99t?= =?UTF-8?q?=20want=20to=20touch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/EDriverTypes.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/EDriverTypes.h b/include/EDriverTypes.h index 0409757..71cea54 100644 --- a/include/EDriverTypes.h +++ b/include/EDriverTypes.h @@ -20,6 +20,13 @@ namespace video render and display any graphics. */ EDT_NULL, + // obsolete constants to make some code happy + // TODO delete + EDT_SOFTWARE, + EDT_BURNINGSVIDEO, + DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS, + EDT_DIRECT3D9, + //! OpenGL device, available on most platforms. /** Performs hardware accelerated rendering of 3D and 2D primitives. */ From a6d062ebd9513db64a9fb5e1ba7864319905c62c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 4 Mar 2023 22:27:43 +0300 Subject: [PATCH 27/42] Apply suggestions from code review Co-authored-by: sfan5 --- source/Irrlicht/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 7b51145..7a29d37 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -200,7 +200,7 @@ endif() if(ENABLE_GLES1) add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) - if(DEVICE MATCHES "^WINDOWS|X11|ANDROID$") + if(DEVICE MATCHES "^(WINDOWS|X11|ANDROID)$") add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_ -D_IRR_OGLES1_USE_EXTPOINTER_) elseif(DEVICE STREQUAL "IOS") add_definitions(-D_IRR_COMPILE_WITH_EAGL_MANAGER_) @@ -209,7 +209,7 @@ endif() if(ENABLE_GLES2) add_definitions(-D_IRR_COMPILE_WITH_OGLES2_) - if(DEVICE MATCHES "^WINDOWS|X11|ANDROID$" OR EMSCRIPTEN) + if(DEVICE MATCHES "^(WINDOWS|X11|ANDROID)$" OR EMSCRIPTEN) add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_ -D_IRR_OGLES2_USE_EXTPOINTER_) elseif(DEVICE STREQUAL "IOS") add_definitions(-D_IRR_COMPILE_WITH_EAGL_MANAGER_) @@ -275,7 +275,7 @@ elseif(APPLE) else() # Unix probably find_package(X11 REQUIRED) - if(${USE_XINPUT2} AND NOT X11_Xi_FOUND) + if(USE_XINPUT2 AND NOT X11_Xi_FOUND) message(FATAL_ERROR "XInput not found") endif() endif() From 6de0afa8b3b6304b080798024bac41cdc668e823 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 6 Mar 2023 13:58:38 +0300 Subject: [PATCH 28/42] Drop ETS_TEXTURE_1 The transformation state itself is still available via ETS_TEXTURE_0+1 --- include/IVideoDriver.h | 4 +--- source/Irrlicht/COGLES2FixedPipelineRenderer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index e3ea221..b220e5e 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -57,10 +57,8 @@ namespace video //! Projection transformation ETS_PROJECTION, //! Texture 0 transformation - //! Use ETS_TEXTURE_0 + texture_number to access other texture transformations + //! Use E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + texture_number) to access other texture transformations ETS_TEXTURE_0, - //! Texture 1 transformation - ETS_TEXTURE_1, //! Only used internally ETS_COUNT = ETS_TEXTURE_0 + MATERIAL_MAX_TEXTURES }; diff --git a/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp b/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp index 5b275d3..899dfd9 100644 --- a/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp +++ b/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp @@ -176,7 +176,7 @@ void COGLES2MaterialSolid2CB::OnSetConstants(IMaterialRendererServices* services core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - Matrix = driver->getTransform(ETS_TEXTURE_1); + Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); @@ -223,7 +223,7 @@ void COGLES2MaterialLightmapCB::OnSetConstants(IMaterialRendererServices* servic core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - Matrix = driver->getTransform(ETS_TEXTURE_1); + Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); services->setPixelShaderConstant(ModulateID, &Modulate, 1); From 5f76be9380048bcaf708974177579086043704f2 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 6 Mar 2023 14:10:05 +0300 Subject: [PATCH 29/42] Restore isDriverSupported, but in a cpp file --- include/IrrlichtDevice.h | 4 +++- source/Irrlicht/Irrlicht.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index 07d4f9f..c6a1978 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -14,6 +14,7 @@ #include "ICursorControl.h" #include "ITimer.h" #include "IOSOperator.h" +#include "IrrCompileConfig.h" namespace irr { @@ -34,6 +35,7 @@ namespace irr namespace video { class IContextManager; + extern "C" IRRLICHT_API bool IRRCALLCONV isDriverSupported(E_DRIVER_TYPE driver); } // end namespace video //! The Irrlicht device. You can create it with createDevice() or createDeviceEx(). @@ -310,7 +312,7 @@ namespace irr for a configuration requested when creating the device. */ static bool isDriverSupported(video::E_DRIVER_TYPE driver) { - return true; + return video::isDriverSupported(driver); } }; diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index 826414f..50348e7 100644 --- a/source/Irrlicht/Irrlicht.cpp +++ b/source/Irrlicht/Irrlicht.cpp @@ -113,6 +113,26 @@ namespace core namespace video { SMaterial IdentityMaterial; + + extern "C" IRRLICHT_API bool IRRCALLCONV isDriverSupported(E_DRIVER_TYPE driver) + { + switch (driver) { + case EDT_NULL: return true; +#ifdef _IRR_COMPILE_WITH_OPENGL_ + 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; +#endif +#ifdef _IRR_COMPILE_WITH_WEBGL1_ + case EDT_WEBGL1: return true; +#endif + default: return false; + } + } } } // end namespace irr From e484698ba27673b88233bedb571dd1df5edeae64 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 6 Mar 2023 14:21:58 +0300 Subject: [PATCH 30/42] Restrict X11 options to X11 device --- source/Irrlicht/CMakeLists.txt | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 7a29d37..cfd3bbe 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -113,38 +113,32 @@ else() set(DEVICE "X11") endif() -if(USE_SDL2) - set(DEVICE "SDL") -endif() - -option(USE_X11 "Use X11" TRUE) -if(USE_X11) - add_definitions(-D_IRR_COMPILE_WITH_X11_) -endif() - if(LINUX_PLATFORM) add_definitions(-D_IRR_LINUX_PLATFORM_) endif() +if(USE_SDL2) + set(DEVICE "SDL") +endif() + +add_definitions("-D_IRR_COMPILE_WITH_${DEVICE}_DEVICE_") + +# X11 + +if(DEVICE STREQUAL "X11") + option(USE_X11 "Use X11" TRUE) +else() + set(USE_X11 FALSE) +endif() + if(LINUX_PLATFORM AND USE_X11) - add_definitions(-D_IRR_COMPILE_WITH_X11_) - option(USE_XINPUT2 "Use XInput2" TRUE) - if(USE_XINPUT2) - add_definitions(-D_IRR_LINUX_X11_XINPUT2_) - endif() - option(USE_XCURSOR "Use XCursor" FALSE) - if(USE_XCURSOR) - add_definitions(-D_IRR_LINUX_XCURSOR_) - endif() else() set(USE_XINPUT2 FALSE) set(USE_XCURSOR FALSE) endif() -add_definitions("-D_IRR_COMPILE_WITH_${DEVICE}_DEVICE_") - # Joystick if(NOT (BSD OR SOLARIS OR EMSCRIPTEN)) @@ -421,6 +415,18 @@ elseif(APPLE) ) endif() +if(USE_X11) + target_compile_definitions(IRROTHEROBJ PRIVATE _IRR_COMPILE_WITH_X11_) +endif() + +if(USE_XINPUT2) + target_compile_definitions(IRROTHEROBJ PRIVATE _IRR_LINUX_X11_XINPUT2_) +endif() + +if(USE_XCURSOR) + target_compile_definitions(IRROTHEROBJ PRIVATE _IRR_LINUX_XCURSOR_) +endif() + add_library(IRRGUIOBJ OBJECT CGUIButton.cpp CGUICheckBox.cpp From b27981043772b209d895cf0414e1213878a6354c Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 6 Mar 2023 17:32:03 +0300 Subject: [PATCH 31/42] Consolidate import/export attribute definitions --- source/Irrlicht/CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index cfd3bbe..4d2ec7e 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -6,13 +6,16 @@ option(USE_SDL2 "Use the SDL2 backend" FALSE) add_definitions(-DIRRLICHT_EXPORTS) if(BUILD_SHARED_LIBS) if(WIN32) - add_definitions("-DIRRLICHT_API=__declspec(dllexport)") + set(API_IMPORT "__declspec(dllimport)") + set(API_EXPORT "__declspec(dllexport)") elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") - add_definitions("-DIRRLICHT_API=__attribute__ ((visibility(\"default\")))") + set(API_EXPORT "__attribute__ ((visibility(\"default\")))") # only necessary if default visibility is set to hidden endif() else() add_definitions(-D_IRR_STATIC_LIB_) endif() +add_definitions("-DIRRLICHT_API=${API_EXPORT}") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-D_DEBUG) endif() @@ -472,11 +475,9 @@ target_include_directories(IrrlichtMt target_link_libraries(IrrlichtMt PRIVATE ${link_libs}) if(WIN32) - target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) -endif() -if(WIN32 AND BUILD_SHARED_LIBS) - target_compile_definitions(IrrlichtMt INTERFACE IRRLICHT_API=__declspec(dllimport)) + target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) # used in _IRR_DEBUG_BREAK_IF definition in a public header endif() +target_compile_definitions(IrrlichtMt INTERFACE "IRRLICHT_API=${API_IMPORT}") if(APPLE OR ANDROID OR EMSCRIPTEN) target_compile_definitions(IrrlichtMt PUBLIC IRR_MOBILE_PATHS) endif() From 82d1feb93300196f2baea717d27bb3c92a39f3c7 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:17:47 +0300 Subject: [PATCH 32/42] Accommodate lack of ETS_TEXTURE_1 --- source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp index 4a20f02..bcf99ac 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp @@ -174,7 +174,7 @@ void COpenGL3MaterialSolid2CB::OnSetConstants(IMaterialRendererServices* service core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - Matrix = driver->getTransform(ETS_TEXTURE_1); + Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); @@ -221,7 +221,7 @@ void COpenGL3MaterialLightmapCB::OnSetConstants(IMaterialRendererServices* servi core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - Matrix = driver->getTransform(ETS_TEXTURE_1); + Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); services->setPixelShaderConstant(ModulateID, &Modulate, 1); From ea0ca7f91755afc0876472242d38f4841c24d1d7 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:33:58 +0300 Subject: [PATCH 33/42] Small Fixes --- source/Irrlicht/Irrlicht.cpp | 3 +++ source/Irrlicht/OpenGL/Driver.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index 50348e7..ed6b082 100644 --- a/source/Irrlicht/Irrlicht.cpp +++ b/source/Irrlicht/Irrlicht.cpp @@ -118,6 +118,9 @@ namespace video { switch (driver) { case EDT_NULL: return true; +#ifdef ENABLE_OPENGL3 + case EDT_OPENGL3: return true; +#endif #ifdef _IRR_COMPILE_WITH_OPENGL_ case EDT_OPENGL: return true; #endif diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 27ab1ba..9baefc2 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -5,6 +5,7 @@ // For conditions of distribution and use, see copyright notice in Irrlicht.h #include "Driver.h" +#include #include "CNullDriver.h" #include "IContextManager.h" From d84dc18e134792392629c8822f8ec4f0fabc16ab Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:38:47 +0300 Subject: [PATCH 34/42] Add OpenGL3 support to the autotests --- examples/AutomatedTest/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/AutomatedTest/main.cpp b/examples/AutomatedTest/main.cpp index 0141b2b..6e9d646 100644 --- a/examples/AutomatedTest/main.cpp +++ b/examples/AutomatedTest/main.cpp @@ -20,6 +20,8 @@ static video::E_DRIVER_TYPE chooseDriver(core::stringc arg_) return video::EDT_OGLES2; if (arg_ == "opengl") return video::EDT_OPENGL; + if (arg_ == "opengl3") + return video::EDT_OPENGL3; std::cerr << "Unknown driver type: " << arg_.c_str() << ". Trying OpenGL." << std::endl; return video::EDT_OPENGL; } From 233108383761a8cb3ca02f1ddf40cd806ccd0260 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:39:03 +0300 Subject: [PATCH 35/42] Add CI for the new OpenGL 3 driver --- .github/workflows/build.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 41dc3d6..8d1706e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,6 +83,33 @@ jobs: cd bin/Linux ./AutomatedTest null + linux-sdl-gl3: + runs-on: ubuntu-latest + container: + image: ubuntu:jammy + env: { LANG: "C.UTF-8" } + steps: + - uses: actions/checkout@v3 + - name: Install deps + run: | + apt-get update + apt-get install g++ cmake libsdl2-dev libpng-dev libjpeg-dev zlib1g-dev -qyy + + - name: Build + run: | + cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON -DENABLE_OPENGL3=ON + make -j2 + + - name: Test (headless) + run: | + cd bin/Linux + ./AutomatedTest null + + - name: Test (Xvfb) + run: | + cd bin/Linux + LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest opengl3 + win32: runs-on: ubuntu-20.04 steps: From 02c6449f0dc72cb9a3dc7c788dd6a404bff0b7e2 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:40:11 +0300 Subject: [PATCH 36/42] Add CI for the new GL ES 2 driver --- .github/workflows/build.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d1706e..f3d5f5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -110,6 +110,33 @@ jobs: cd bin/Linux LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest opengl3 + linux-sdl-gles2: + runs-on: ubuntu-latest + container: + image: ubuntu:jammy + env: { LANG: "C.UTF-8" } + steps: + - uses: actions/checkout@v3 + - name: Install deps + run: | + apt-get update + apt-get install g++ cmake libsdl2-dev libpng-dev libjpeg-dev zlib1g-dev -qyy + + - name: Build + run: | + cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON -DENABLE_GLES2=ON + make -j2 + + - name: Test (headless) + run: | + cd bin/Linux + ./AutomatedTest null + + - name: Test (Xvfb) + run: | + cd bin/Linux + LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest gles2 + win32: runs-on: ubuntu-20.04 steps: From f641500d017e7aa11cb9836d2c759ecfd3b5120d Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:45:40 +0300 Subject: [PATCH 37/42] Add xvfb (for tests) --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3d5f5c..2cf7d60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: - name: Install deps run: | apt-get update - apt-get install g++ cmake libsdl2-dev libpng-dev libjpeg-dev zlib1g-dev -qyy + apt-get install g++ cmake libsdl2-dev libpng-dev libjpeg-dev zlib1g-dev xvfb -qyy - name: Build run: | @@ -120,7 +120,7 @@ jobs: - name: Install deps run: | apt-get update - apt-get install g++ cmake libsdl2-dev libpng-dev libjpeg-dev zlib1g-dev -qyy + apt-get install g++ cmake libsdl2-dev libpng-dev libjpeg-dev zlib1g-dev xvfb -qyy - name: Build run: | From ba77d01c91a363ad932ecd26c3eaba82ddf7a6f0 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 19:16:06 +0300 Subject: [PATCH 38/42] Error out early on unsupported SDL2+GLES1 combo --- source/Irrlicht/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index a57258d..fa345ca 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -204,6 +204,9 @@ if(ENABLE_OPENGL3) endif() if(ENABLE_GLES1) + if (USE_SDL2) + message(SEND_ERROR "OpenGL ES 1 is not supported with SDL2") + endif() add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) if(DEVICE MATCHES "^(WINDOWS|X11|ANDROID)$") add_definitions(-D_IRR_COMPILE_WITH_EGL_MANAGER_ -D_IRR_OGLES1_USE_EXTPOINTER_) From 28d0e0644cea3ba03f52980be26f5b178d13561f Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 25 Mar 2023 11:05:40 +0300 Subject: [PATCH 39/42] Add shaders for COpenGL3DriverBase Currently, they are identical to OGLES2 shaders, except of version specification. --- media/Shaders/DetailMap.fsh | 72 ++++++++++++++++++ media/Shaders/LightmapAdd.fsh | 72 ++++++++++++++++++ media/Shaders/LightmapModulate.fsh | 74 +++++++++++++++++++ media/Shaders/OneTextureBlend.fsh | 77 ++++++++++++++++++++ media/Shaders/Reflection2Layer.fsh | 72 ++++++++++++++++++ media/Shaders/Reflection2Layer.vsh | 55 ++++++++++++++ media/Shaders/Renderer2D.fsh | 23 ++++++ media/Shaders/Renderer2D.vsh | 24 ++++++ media/Shaders/Renderer2D_noTex.fsh | 11 +++ media/Shaders/Solid.fsh | 64 ++++++++++++++++ media/Shaders/Solid.vsh | 47 ++++++++++++ media/Shaders/Solid2.vsh | 53 ++++++++++++++ media/Shaders/Solid2Layer.fsh | 74 +++++++++++++++++++ media/Shaders/SphereMap.fsh | 64 ++++++++++++++++ media/Shaders/SphereMap.vsh | 50 +++++++++++++ media/Shaders/TransparentAlphaChannel.fsh | 71 ++++++++++++++++++ media/Shaders/TransparentAlphaChannelRef.fsh | 69 ++++++++++++++++++ media/Shaders/TransparentVertexAlpha.fsh | 64 ++++++++++++++++ 18 files changed, 1036 insertions(+) create mode 100644 media/Shaders/DetailMap.fsh create mode 100644 media/Shaders/LightmapAdd.fsh create mode 100644 media/Shaders/LightmapModulate.fsh create mode 100644 media/Shaders/OneTextureBlend.fsh create mode 100644 media/Shaders/Reflection2Layer.fsh create mode 100644 media/Shaders/Reflection2Layer.vsh create mode 100644 media/Shaders/Renderer2D.fsh create mode 100644 media/Shaders/Renderer2D.vsh create mode 100644 media/Shaders/Renderer2D_noTex.fsh create mode 100644 media/Shaders/Solid.fsh create mode 100644 media/Shaders/Solid.vsh create mode 100644 media/Shaders/Solid2.vsh create mode 100644 media/Shaders/Solid2Layer.fsh create mode 100644 media/Shaders/SphereMap.fsh create mode 100644 media/Shaders/SphereMap.vsh create mode 100644 media/Shaders/TransparentAlphaChannel.fsh create mode 100644 media/Shaders/TransparentAlphaChannelRef.fsh create mode 100644 media/Shaders/TransparentVertexAlpha.fsh diff --git a/media/Shaders/DetailMap.fsh b/media/Shaders/DetailMap.fsh new file mode 100644 index 0000000..01c94d7 --- /dev/null +++ b/media/Shaders/DetailMap.fsh @@ -0,0 +1,72 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform int uTextureUsage1; +uniform sampler2D uTextureUnit0; +uniform sampler2D uTextureUnit1; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0); + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color0 = texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uTextureUsage1)) + Color1 = texture2D(uTextureUnit1, vTextureCoord1); + + vec4 FinalColor = vec4(Color0 + (Color1 - 0.5)) * vVertexColor + vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; +} diff --git a/media/Shaders/LightmapAdd.fsh b/media/Shaders/LightmapAdd.fsh new file mode 100644 index 0000000..895625f --- /dev/null +++ b/media/Shaders/LightmapAdd.fsh @@ -0,0 +1,72 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform int uTextureUsage1; +uniform sampler2D uTextureUnit0; +uniform sampler2D uTextureUnit1; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0); + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color0 = texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uTextureUsage1)) + Color1 = texture2D(uTextureUnit1, vTextureCoord1); + + vec4 FinalColor = (Color0 + Color1) * vVertexColor + vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; +} diff --git a/media/Shaders/LightmapModulate.fsh b/media/Shaders/LightmapModulate.fsh new file mode 100644 index 0000000..74e9df1 --- /dev/null +++ b/media/Shaders/LightmapModulate.fsh @@ -0,0 +1,74 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform float uModulate; +uniform int uTextureUsage0; +uniform int uTextureUsage1; +uniform sampler2D uTextureUnit0; +uniform sampler2D uTextureUnit1; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0); + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color0 = texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uTextureUsage1)) + Color1 = texture2D(uTextureUnit1, vTextureCoord1); + + vec4 FinalColor = (Color0 * Color1 * uModulate) * vVertexColor; + FinalColor += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; +} diff --git a/media/Shaders/OneTextureBlend.fsh b/media/Shaders/OneTextureBlend.fsh new file mode 100644 index 0000000..c348016 --- /dev/null +++ b/media/Shaders/OneTextureBlend.fsh @@ -0,0 +1,77 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uBlendType; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vVertexColor; + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color1 = texture2D(uTextureUnit0, vTextureCoord0); + + vec4 FinalColor = Color0 * Color1; + FinalColor += vSpecularColor; + + if (uBlendType == 1) + { + FinalColor.w = Color0.w; + } + else if (uBlendType == 2) + { + FinalColor.w = Color1.w; + } + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; +} diff --git a/media/Shaders/Reflection2Layer.fsh b/media/Shaders/Reflection2Layer.fsh new file mode 100644 index 0000000..bdc3c66 --- /dev/null +++ b/media/Shaders/Reflection2Layer.fsh @@ -0,0 +1,72 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform int uTextureUsage1; +uniform sampler2D uTextureUnit0; +uniform sampler2D uTextureUnit1; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0); + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color0 = texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uTextureUsage1)) + Color1 = texture2D(uTextureUnit1, vTextureCoord1); + + vec4 FinalColor = (Color0 * Color1) * vVertexColor + vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; +} diff --git a/media/Shaders/Reflection2Layer.vsh b/media/Shaders/Reflection2Layer.vsh new file mode 100644 index 0000000..aafac22 --- /dev/null +++ b/media/Shaders/Reflection2Layer.vsh @@ -0,0 +1,55 @@ +#version 100 + +/* Attributes */ + +attribute vec3 inVertexPosition; +attribute vec3 inVertexNormal; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; +attribute vec2 inTexCoord1; + +/* Uniforms */ + +uniform mat4 uWVPMatrix; +uniform mat4 uWVMatrix; +uniform mat4 uNMatrix; +uniform mat4 uTMatrix0; + +uniform vec4 uGlobalAmbient; +uniform vec4 uMaterialAmbient; +uniform vec4 uMaterialDiffuse; +uniform vec4 uMaterialEmissive; +uniform vec4 uMaterialSpecular; +uniform float uMaterialShininess; + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +void main() +{ + gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); + gl_PointSize = uThickness; + + vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0); + vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy; + + vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; + vec3 P = normalize(Position); + vec3 N = normalize(vec4(uNMatrix * vec4(inVertexNormal, 0.0)).xyz); + vec3 R = reflect(P, N); + + float V = 2.0 * sqrt(R.x*R.x + R.y*R.y + (R.z+1.0)*(R.z+1.0)); + vTextureCoord1 = vec2(R.x/V + 0.5, R.y/V + 0.5); + + vVertexColor = inVertexColor.bgra; + vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); + + vFogCoord = length(Position); +} diff --git a/media/Shaders/Renderer2D.fsh b/media/Shaders/Renderer2D.fsh new file mode 100644 index 0000000..89aef7e --- /dev/null +++ b/media/Shaders/Renderer2D.fsh @@ -0,0 +1,23 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage; +uniform sampler2D uTextureUnit; + +/* Varyings */ + +varying vec2 vTextureCoord; +varying vec4 vVertexColor; + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage)) + Color *= texture2D(uTextureUnit, vTextureCoord); + + gl_FragColor = Color; +} diff --git a/media/Shaders/Renderer2D.vsh b/media/Shaders/Renderer2D.vsh new file mode 100644 index 0000000..9142148 --- /dev/null +++ b/media/Shaders/Renderer2D.vsh @@ -0,0 +1,24 @@ +#version 100 + +/* Attributes */ + +attribute vec4 inVertexPosition; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; + +/* Uniforms */ + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord; +varying vec4 vVertexColor; + +void main() +{ + gl_Position = inVertexPosition; + gl_PointSize = uThickness; + vTextureCoord = inTexCoord0; + vVertexColor = inVertexColor.bgra; +} diff --git a/media/Shaders/Renderer2D_noTex.fsh b/media/Shaders/Renderer2D_noTex.fsh new file mode 100644 index 0000000..6000972 --- /dev/null +++ b/media/Shaders/Renderer2D_noTex.fsh @@ -0,0 +1,11 @@ +#version 100 + +precision mediump float; + +/* Varyings */ +varying vec4 vVertexColor; + +void main() +{ + gl_FragColor = vVertexColor; +} diff --git a/media/Shaders/Solid.fsh b/media/Shaders/Solid.fsh new file mode 100644 index 0000000..df1010e --- /dev/null +++ b/media/Shaders/Solid.fsh @@ -0,0 +1,64 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + Color += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/media/Shaders/Solid.vsh b/media/Shaders/Solid.vsh new file mode 100644 index 0000000..98d0dae --- /dev/null +++ b/media/Shaders/Solid.vsh @@ -0,0 +1,47 @@ +#version 100 + +/* Attributes */ + +attribute vec3 inVertexPosition; +attribute vec3 inVertexNormal; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; + +/* Uniforms */ + +uniform mat4 uWVPMatrix; +uniform mat4 uWVMatrix; +uniform mat4 uNMatrix; +uniform mat4 uTMatrix0; + +uniform vec4 uGlobalAmbient; +uniform vec4 uMaterialAmbient; +uniform vec4 uMaterialDiffuse; +uniform vec4 uMaterialEmissive; +uniform vec4 uMaterialSpecular; +uniform float uMaterialShininess; + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +void main() +{ + gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); + gl_PointSize = uThickness; + + vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0); + vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy; + + vVertexColor = inVertexColor.bgra; + vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); + + vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; + + vFogCoord = length(Position); +} diff --git a/media/Shaders/Solid2.vsh b/media/Shaders/Solid2.vsh new file mode 100644 index 0000000..c49ecfc --- /dev/null +++ b/media/Shaders/Solid2.vsh @@ -0,0 +1,53 @@ +#version 100 + +/* Attributes */ + +attribute vec3 inVertexPosition; +attribute vec3 inVertexNormal; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; +attribute vec2 inTexCoord1; + +/* Uniforms */ + +uniform mat4 uWVPMatrix; +uniform mat4 uWVMatrix; +uniform mat4 uNMatrix; +uniform mat4 uTMatrix0; +uniform mat4 uTMatrix1; + +uniform vec4 uGlobalAmbient; +uniform vec4 uMaterialAmbient; +uniform vec4 uMaterialDiffuse; +uniform vec4 uMaterialEmissive; +uniform vec4 uMaterialSpecular; +uniform float uMaterialShininess; + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +void main() +{ + gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); + gl_PointSize = uThickness; + + vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0); + vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy; + + vec4 TextureCoord1 = vec4(inTexCoord1.x, inTexCoord1.y, 1.0, 1.0); + vTextureCoord1 = vec4(uTMatrix1 * TextureCoord1).xy; + + vVertexColor = inVertexColor.bgra; + vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); + + vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; + + vFogCoord = length(Position); +} diff --git a/media/Shaders/Solid2Layer.fsh b/media/Shaders/Solid2Layer.fsh new file mode 100644 index 0000000..3c8a39d --- /dev/null +++ b/media/Shaders/Solid2Layer.fsh @@ -0,0 +1,74 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform int uTextureUsage1; +uniform sampler2D uTextureUnit0; +uniform sampler2D uTextureUnit1; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec2 vTextureCoord1; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0); + vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); + + if (bool(uTextureUsage0)) + Color0 = texture2D(uTextureUnit0, vTextureCoord0); + + if (bool(uTextureUsage1)) + Color1 = texture2D(uTextureUnit1, vTextureCoord1); + + vec4 FinalColor = (Color0 * vVertexColor.a + Color1 * (1.0 - vVertexColor.a)) * vVertexColor; + FinalColor += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + FinalColor = mix(FogColor, FinalColor, FogFactor); + } + + gl_FragColor = FinalColor; + +} diff --git a/media/Shaders/SphereMap.fsh b/media/Shaders/SphereMap.fsh new file mode 100644 index 0000000..df1010e --- /dev/null +++ b/media/Shaders/SphereMap.fsh @@ -0,0 +1,64 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + Color += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/media/Shaders/SphereMap.vsh b/media/Shaders/SphereMap.vsh new file mode 100644 index 0000000..5062d79 --- /dev/null +++ b/media/Shaders/SphereMap.vsh @@ -0,0 +1,50 @@ +#version 100 + +/* Attributes */ + +attribute vec3 inVertexPosition; +attribute vec3 inVertexNormal; +attribute vec4 inVertexColor; +attribute vec2 inTexCoord0; +attribute vec2 inTexCoord1; + +/* Uniforms */ + +uniform mat4 uWVPMatrix; +uniform mat4 uWVMatrix; +uniform mat4 uNMatrix; + +uniform vec4 uGlobalAmbient; +uniform vec4 uMaterialAmbient; +uniform vec4 uMaterialDiffuse; +uniform vec4 uMaterialEmissive; +uniform vec4 uMaterialSpecular; +uniform float uMaterialShininess; + +uniform float uThickness; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +void main() +{ + gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); + gl_PointSize = uThickness; + + vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; + vec3 P = normalize(Position); + vec3 N = normalize(vec4(uNMatrix * vec4(inVertexNormal, 0.0)).xyz); + vec3 R = reflect(P, N); + + float V = 2.0 * sqrt(R.x*R.x + R.y*R.y + (R.z+1.0)*(R.z+1.0)); + vTextureCoord0 = vec2(R.x/V + 0.5, R.y/V + 0.5); + + vVertexColor = inVertexColor.bgra; + vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); + + vFogCoord = length(Position); +} diff --git a/media/Shaders/TransparentAlphaChannel.fsh b/media/Shaders/TransparentAlphaChannel.fsh new file mode 100644 index 0000000..cef349a --- /dev/null +++ b/media/Shaders/TransparentAlphaChannel.fsh @@ -0,0 +1,71 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform float uAlphaRef; +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + { + Color *= texture2D(uTextureUnit0, vTextureCoord0); + + // TODO: uAlphaRef should rather control sharpness of alpha, don't know how to do that right now and this works in most cases. + if (Color.a < uAlphaRef) + discard; + } + Color += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/media/Shaders/TransparentAlphaChannelRef.fsh b/media/Shaders/TransparentAlphaChannelRef.fsh new file mode 100644 index 0000000..fab4eee --- /dev/null +++ b/media/Shaders/TransparentAlphaChannelRef.fsh @@ -0,0 +1,69 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform float uAlphaRef; +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + + if (Color.a < uAlphaRef) + discard; + + Color += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} diff --git a/media/Shaders/TransparentVertexAlpha.fsh b/media/Shaders/TransparentVertexAlpha.fsh new file mode 100644 index 0000000..df1010e --- /dev/null +++ b/media/Shaders/TransparentVertexAlpha.fsh @@ -0,0 +1,64 @@ +#version 100 + +precision mediump float; + +/* Uniforms */ + +uniform int uTextureUsage0; +uniform sampler2D uTextureUnit0; +uniform int uFogEnable; +uniform int uFogType; +uniform vec4 uFogColor; +uniform float uFogStart; +uniform float uFogEnd; +uniform float uFogDensity; + +/* Varyings */ + +varying vec2 vTextureCoord0; +varying vec4 vVertexColor; +varying vec4 vSpecularColor; +varying float vFogCoord; + +float computeFog() +{ + const float LOG2 = 1.442695; + float FogFactor = 0.0; + + if (uFogType == 0) // Exp + { + FogFactor = exp2(-uFogDensity * vFogCoord * LOG2); + } + else if (uFogType == 1) // Linear + { + float Scale = 1.0 / (uFogEnd - uFogStart); + FogFactor = (uFogEnd - vFogCoord) * Scale; + } + else if (uFogType == 2) // Exp2 + { + FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2); + } + + FogFactor = clamp(FogFactor, 0.0, 1.0); + + return FogFactor; +} + +void main() +{ + vec4 Color = vVertexColor; + + if (bool(uTextureUsage0)) + Color *= texture2D(uTextureUnit0, vTextureCoord0); + Color += vSpecularColor; + + if (bool(uFogEnable)) + { + float FogFactor = computeFog(); + vec4 FogColor = uFogColor; + FogColor.a = 1.0; + Color = mix(FogColor, Color, FogFactor); + } + + gl_FragColor = Color; +} From 219b7fd7d2d884fddb4c12723361c3c342fb9294 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 25 Mar 2023 11:11:09 +0300 Subject: [PATCH 40/42] Fix line endings in the new driver --- source/Irrlicht/OpenGL/Common.h | 72 +- source/Irrlicht/OpenGL/Driver.cpp | 4778 ++++++++--------- source/Irrlicht/OpenGL/Driver.h | 790 +-- source/Irrlicht/OpenGL/ExtensionHandler.cpp | 132 +- source/Irrlicht/OpenGL/ExtensionHandler.h | 374 +- .../Irrlicht/OpenGL/FixedPipelineRenderer.cpp | 668 +-- .../Irrlicht/OpenGL/FixedPipelineRenderer.h | 360 +- source/Irrlicht/OpenGL/MaterialRenderer.cpp | 962 ++-- source/Irrlicht/OpenGL/MaterialRenderer.h | 198 +- source/Irrlicht/OpenGL/Renderer2D.cpp | 166 +- source/Irrlicht/OpenGL/Renderer2D.h | 66 +- 11 files changed, 4283 insertions(+), 4283 deletions(-) diff --git a/source/Irrlicht/OpenGL/Common.h b/source/Irrlicht/OpenGL/Common.h index a69bcc6..4069307 100644 --- a/source/Irrlicht/OpenGL/Common.h +++ b/source/Irrlicht/OpenGL/Common.h @@ -1,36 +1,36 @@ -// Copyright (C) 2023 Vitaliy Lobachevskiy -// 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 - -#define GL_GLEXT_PROTOTYPES -#include -#include - -namespace irr -{ -namespace video -{ - - // Forward declarations. - - class COpenGLCoreFeature; - - template - class COpenGLCoreTexture; - - template - class COpenGLCoreRenderTarget; - - template - class COpenGLCoreCacheHandler; - - class COpenGL3DriverBase; - typedef COpenGLCoreTexture COpenGL3Texture; - typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; - typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; - -} -} +// Copyright (C) 2023 Vitaliy Lobachevskiy +// 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 + +#define GL_GLEXT_PROTOTYPES +#include +#include + +namespace irr +{ +namespace video +{ + + // Forward declarations. + + class COpenGLCoreFeature; + + template + class COpenGLCoreTexture; + + template + class COpenGLCoreRenderTarget; + + template + class COpenGLCoreCacheHandler; + + class COpenGL3DriverBase; + typedef COpenGLCoreTexture COpenGL3Texture; + typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; + typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; + +} +} diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 9baefc2..641536f 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1,2389 +1,2389 @@ -// Copyright (C) 2023 Vitaliy Lobachevskiy -// Copyright (C) 2014 Patryk Nadrowski -// Copyright (C) 2009-2010 Amundis -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#include "Driver.h" -#include -#include "CNullDriver.h" -#include "IContextManager.h" - -#include "COpenGLCoreTexture.h" -#include "COpenGLCoreRenderTarget.h" -#include "COpenGLCoreCacheHandler.h" - -#include "MaterialRenderer.h" -#include "FixedPipelineRenderer.h" -#include "Renderer2D.h" - -#include "EVertexAttributes.h" -#include "CImage.h" -#include "os.h" - -#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ -#include "android_native_app_glue.h" -#endif - -#include "mt_opengl.h" - -namespace irr -{ -namespace video -{ - struct VertexAttribute { - enum class Mode { - Regular, - Normalized, - Integral, - }; - int Index; - int ComponentCount; - GLenum ComponentType; - Mode mode; - int Offset; - }; - - struct VertexType { - int VertexSize; - int AttributeCount; - VertexAttribute Attributes[]; - - VertexType(const VertexType &) = delete; - VertexType &operator= (const VertexType &) = delete; - }; - - static const VertexAttribute *begin(const VertexType &type) - { - return type.Attributes; - } - - static const VertexAttribute *end(const VertexType &type) - { - return type.Attributes + type.AttributeCount; - } - - static constexpr VertexType vtStandard = { - sizeof(S3DVertex), 4, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, - {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Normal)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, - }, - }; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Winvalid-offsetof" - - static constexpr VertexType vt2TCoords = { - sizeof(S3DVertex2TCoords), 5, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Pos)}, - {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Normal)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex2TCoords, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords)}, - {EVA_TCOORD1, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords2)}, - }, - }; - - static constexpr VertexType vtTangents = { - sizeof(S3DVertexTangents), 6, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Pos)}, - {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Normal)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertexTangents, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, TCoords)}, - {EVA_TANGENT, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Tangent)}, - {EVA_BINORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Binormal)}, - }, - }; - -#pragma GCC diagnostic pop - - static const VertexType &getVertexTypeDescription(E_VERTEX_TYPE type) - { - switch (type) { - case EVT_STANDARD: return vtStandard; - case EVT_2TCOORDS: return vt2TCoords; - case EVT_TANGENTS: return vtTangents; - default: assert(false); - } - } - - static constexpr VertexType vt2DImage = { - sizeof(S3DVertex), 3, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, - }, - }; - - static constexpr VertexType vtPrimitive = { - sizeof(S3DVertex), 2, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, - }, - }; - - -void APIENTRY COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) -{ - ((COpenGL3DriverBase *)userParam)->debugCb(source, type, id, severity, length, message); -} - -void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) -{ - printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); -} - -COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : - CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), - Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), - MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), - CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), - OGLES2ShaderPath(params.OGLES2ShaderPath), - ColorFormat(ECF_R8G8B8), ContextManager(contextManager) -{ -#ifdef _DEBUG - setDebugName("Driver"); -#endif - - if (!ContextManager) - return; - - ContextManager->grab(); - ContextManager->generateSurface(); - ContextManager->generateContext(); - ExposedData = ContextManager->getContext(); - ContextManager->activateContext(ExposedData, false); - GL.LoadAllProcedures(ContextManager); - GL.DebugMessageCallback(debugCb, this); - initQuadsIndices(); -} - -COpenGL3DriverBase::~COpenGL3DriverBase() -{ - deleteMaterialRenders(); - - CacheHandler->getTextureCache().clear(); - - removeAllRenderTargets(); - deleteAllTextures(); - removeAllOcclusionQueries(); - removeAllHardwareBuffers(); - - delete MaterialRenderer2DTexture; - delete MaterialRenderer2DNoTexture; - delete CacheHandler; - - if (ContextManager) - { - ContextManager->destroyContext(); - ContextManager->destroySurface(); - ContextManager->terminate(); - ContextManager->drop(); - } -} - - void COpenGL3DriverBase::initQuadsIndices(int max_vertex_count) - { - int max_quad_count = max_vertex_count / 4; - QuadsIndices.reserve(6 * max_quad_count); - for (int k = 0; k < max_quad_count; k++) { - QuadsIndices.push_back(4 * k + 0); - QuadsIndices.push_back(4 * k + 1); - QuadsIndices.push_back(4 * k + 2); - QuadsIndices.push_back(4 * k + 0); - QuadsIndices.push_back(4 * k + 2); - QuadsIndices.push_back(4 * k + 3); - } - } - - bool COpenGL3DriverBase::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 COpenGL3CacheHandler(this); - - StencilBuffer = stencilBuffer; - - DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); - DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); -// DriverAttributes->setAttribute("MaxLights", MaxLights); - DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); -// DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes); -// DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers); -// DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets); - 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); - - UserClipPlane.reallocate(0); - - 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_GENERATE_MIPMAP_HINT, GL_NICEST); - glFrontFace(GL_CW); - - // 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 COpenGL3DriverBase::loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData) - { - io::path vsPath(OGLES2ShaderPath); - vsPath += vertexShaderName; - - io::path fsPath(OGLES2ShaderPath); - fsPath += fragmentShaderName; - - *vertexShaderData = 0; - *fragmentShaderData = 0; - - io::IReadFile* vsFile = FileSystem->createAndOpenFile(vsPath); - if ( !vsFile ) - { - core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n"); - warning += core::stringw(vsPath) + L"\n"; - warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; - os::Printer::log(warning.c_str(), ELL_WARNING); - return; - } - - io::IReadFile* fsFile = FileSystem->createAndOpenFile(fsPath); - if ( !fsFile ) - { - core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n"); - warning += core::stringw(fsPath) + L"\n"; - warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; - os::Printer::log(warning.c_str(), ELL_WARNING); - return; - } - - long size = vsFile->getSize(); - if (size) - { - *vertexShaderData = new c8[size+1]; - vsFile->read(*vertexShaderData, size); - (*vertexShaderData)[size] = 0; - } - - size = fsFile->getSize(); - if (size) - { - // if both handles are the same we must reset the file - if (fsFile == vsFile) - fsFile->seek(0); - - *fragmentShaderData = new c8[size+1]; - fsFile->read(*fragmentShaderData, size); - (*fragmentShaderData)[size] = 0; - } - - vsFile->drop(); - fsFile->drop(); - } - - void COpenGL3DriverBase::createMaterialRenderers() - { - // Create callbacks. - - COpenGL3MaterialSolidCB* SolidCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialSolid2CB* Solid2LayerCB = new COpenGL3MaterialSolid2CB(); - COpenGL3MaterialLightmapCB* LightmapCB = new COpenGL3MaterialLightmapCB(1.f); - COpenGL3MaterialLightmapCB* LightmapAddCB = new COpenGL3MaterialLightmapCB(1.f); - COpenGL3MaterialLightmapCB* LightmapM2CB = new COpenGL3MaterialLightmapCB(2.f); - COpenGL3MaterialLightmapCB* LightmapM4CB = new COpenGL3MaterialLightmapCB(4.f); - COpenGL3MaterialLightmapCB* LightmapLightingCB = new COpenGL3MaterialLightmapCB(1.f); - COpenGL3MaterialLightmapCB* LightmapLightingM2CB = new COpenGL3MaterialLightmapCB(2.f); - COpenGL3MaterialLightmapCB* LightmapLightingM4CB = new COpenGL3MaterialLightmapCB(4.f); - COpenGL3MaterialSolid2CB* DetailMapCB = new COpenGL3MaterialSolid2CB(); - COpenGL3MaterialReflectionCB* SphereMapCB = new COpenGL3MaterialReflectionCB(); - COpenGL3MaterialReflectionCB* Reflection2LayerCB = new COpenGL3MaterialReflectionCB(); - COpenGL3MaterialSolidCB* TransparentAddColorCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialSolidCB* TransparentAlphaChannelCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialSolidCB* TransparentAlphaChannelRefCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialSolidCB* TransparentVertexAlphaCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialReflectionCB* TransparentReflection2LayerCB = new COpenGL3MaterialReflectionCB(); - COpenGL3MaterialOneTextureBlendCB* OneTextureBlendCB = new COpenGL3MaterialOneTextureBlendCB(); - - // Create built-in materials. - - core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; - core::stringc FragmentShader = OGLES2ShaderPath + "Solid.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SolidCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid2.vsh"; - FragmentShader = OGLES2ShaderPath + "Solid2Layer.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Solid2LayerCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid2.vsh"; - FragmentShader = OGLES2ShaderPath + "LightmapModulate.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapCB, EMT_SOLID, 0); - - FragmentShader = OGLES2ShaderPath + "LightmapAdd.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapAddCB, EMT_SOLID, 0); - - FragmentShader = OGLES2ShaderPath + "LightmapModulate.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM2CB, EMT_SOLID, 0); - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM4CB, EMT_SOLID, 0); - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingCB, EMT_SOLID, 0); - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM2CB, EMT_SOLID, 0); - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM4CB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid2.vsh"; - FragmentShader = OGLES2ShaderPath + "DetailMap.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, DetailMapCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "SphereMap.vsh"; - FragmentShader = OGLES2ShaderPath + "SphereMap.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SphereMapCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; - FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Reflection2LayerCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid.vsh"; - FragmentShader = OGLES2ShaderPath + "Solid.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0); - - FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannel.fsh"; - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); - - FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannelRef.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelRefCB, EMT_SOLID, 0); - - FragmentShader = OGLES2ShaderPath + "TransparentVertexAlpha.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); - - VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; - FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentReflection2LayerCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); - - VertexShader = OGLES2ShaderPath + "Solid.vsh"; - FragmentShader = OGLES2ShaderPath + "OneTextureBlend.fsh"; - - addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", - EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, OneTextureBlendCB, EMT_ONETEXTURE_BLEND, 0); - - // Drop callbacks. - - SolidCB->drop(); - Solid2LayerCB->drop(); - LightmapCB->drop(); - LightmapAddCB->drop(); - LightmapM2CB->drop(); - LightmapM4CB->drop(); - LightmapLightingCB->drop(); - LightmapLightingM2CB->drop(); - LightmapLightingM4CB->drop(); - DetailMapCB->drop(); - SphereMapCB->drop(); - Reflection2LayerCB->drop(); - TransparentAddColorCB->drop(); - TransparentAlphaChannelCB->drop(); - TransparentAlphaChannelRefCB->drop(); - TransparentVertexAlphaCB->drop(); - TransparentReflection2LayerCB->drop(); - OneTextureBlendCB->drop(); - - // Create 2D material renderers - - c8* vs2DData = 0; - c8* fs2DData = 0; - loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D.fsh"), &vs2DData, &fs2DData); - MaterialRenderer2DTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, true); - delete[] vs2DData; - delete[] fs2DData; - vs2DData = 0; - fs2DData = 0; - - loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D_noTex.fsh"), &vs2DData, &fs2DData); - MaterialRenderer2DNoTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, false); - delete[] vs2DData; - delete[] fs2DData; - } - - bool COpenGL3DriverBase::setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture) - { - Material.TextureLayer[layerIdx].Texture = const_cast(texture); // function uses const-pointer for texture because all draw functions use const-pointers already - return CacheHandler->getTextureCache().set(0, texture); - } - - bool COpenGL3DriverBase::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 COpenGL3DriverBase::endScene() - { - CNullDriver::endScene(); - - glFlush(); - - if (ContextManager) - return ContextManager->swapBuffers(); - - return false; - } - - - //! Returns the transformation set by setTransform - const core::matrix4& COpenGL3DriverBase::getTransform(E_TRANSFORMATION_STATE state) const - { - return Matrices[state]; - } - - - //! sets transformation - void COpenGL3DriverBase::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) - { - Matrices[state] = mat; - Transformation3DChanged = true; - } - - - bool COpenGL3DriverBase::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); - - const void *buffer = vertices; - size_t bufferSize = vertexSize * vertexCount; - - //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 < bufferSize) - { - newBuffer = true; - } - - glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); - - // copy data to graphics card - if (!newBuffer) - glBufferSubData(GL_ARRAY_BUFFER, 0, bufferSize, buffer); - else - { - HWBuffer->vbo_verticesSize = bufferSize; - - if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) - glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_STATIC_DRAW); - else - glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_DYNAMIC_DRAW); - } - - glBindBuffer(GL_ARRAY_BUFFER, 0); - - return (!testGLError(__LINE__)); - } - - - bool COpenGL3DriverBase::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 COpenGL3DriverBase::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() - || !static_cast(HWBuffer)->vbo_indicesID) - { - - HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); - - if (!updateIndexHardwareBuffer((SHWBufferLink_opengl*)HWBuffer)) - return false; - } - } - - return true; - } - - - //! Create hardware buffer from meshbuffer - COpenGL3DriverBase::SHWBufferLink *COpenGL3DriverBase::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 COpenGL3DriverBase::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 COpenGL3DriverBase::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* COpenGL3DriverBase::addRenderTarget() - { - COpenGL3RenderTarget* renderTarget = new COpenGL3RenderTarget(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 COpenGL3DriverBase::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 (!primitiveCount || !vertexCount) - return; - - if (!checkPrimitiveCount(primitiveCount)) - return; - - CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); - - setRenderStates3DMode(); - - auto &vTypeDesc = getVertexTypeDescription(vType); - beginDraw(vTypeDesc, reinterpret_cast(vertices)); - 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: - glDrawArrays(GL_POINTS, 0, primitiveCount); - break; - case scene::EPT_LINE_STRIP: - glDrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList); - break; - case scene::EPT_LINE_LOOP: - glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList); - break; - case scene::EPT_LINES: - glDrawElements(GL_LINES, primitiveCount*2, indexSize, indexList); - break; - case scene::EPT_TRIANGLE_STRIP: - glDrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); - break; - case scene::EPT_TRIANGLE_FAN: - glDrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); - break; - case scene::EPT_TRIANGLES: - glDrawElements((LastMaterial.Wireframe) ? GL_LINES : (LastMaterial.PointCloud) ? GL_POINTS : GL_TRIANGLES, primitiveCount*3, indexSize, indexList); - break; - default: - break; - } - - endDraw(vTypeDesc); - } - - - void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, const core::position2d& destPos, - const core::rect& sourceRect, const core::rect* clipRect, SColor color, - bool useAlphaChannelOfTexture) - { - if (!texture) - return; - - if (!sourceRect.isValid()) - return; - - SColor colors[4] = {color, color, color, color}; - draw2DImage(texture, {destPos, sourceRect.getSize()}, sourceRect, clipRect, colors, useAlphaChannelOfTexture); - } - - - void COpenGL3DriverBase::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; - - chooseMaterial2D(); - if (!setMaterialTexture(0, texture )) - return; - - setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || - useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, - true, useAlphaChannelOfTexture); - - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - - if (clipRect) - { - if (!clipRect->isValid()) - return; - - glEnable(GL_SCISSOR_TEST); - glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, - clipRect->getWidth(), clipRect->getHeight()); - } - - f32 left = (f32)destRect.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 right = (f32)destRect.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 down = 2.f - (f32)destRect.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 top = 2.f - (f32)destRect.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - S3DVertex vertices[4]; - vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); - vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); - vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); - vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); - - drawQuad(vt2DImage, vertices); - - if (clipRect) - glDisable(GL_SCISSOR_TEST); - - testGLError(__LINE__); - } - - void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, u32 layer, bool flip) - { - if (!texture) - return; - - chooseMaterial2D(); - if (!setMaterialTexture(0, texture )) - return; - - setRenderStates2DMode(false, true, true); - - S3DVertex quad2DVertices[4]; - - quad2DVertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); - quad2DVertices[1].Pos = core::vector3df(1.f, 1.f, 0.f); - quad2DVertices[2].Pos = core::vector3df(1.f, -1.f, 0.f); - quad2DVertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f); - - f32 modificator = (flip) ? 1.f : 0.f; - - quad2DVertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); - quad2DVertices[1].TCoords = core::vector2df(1.f, 0.f + modificator); - quad2DVertices[2].TCoords = core::vector2df(1.f, 1.f - modificator); - quad2DVertices[3].TCoords = core::vector2df(0.f, 1.f - modificator); - - quad2DVertices[0].Color = SColor(0xFFFFFFFF); - quad2DVertices[1].Color = SColor(0xFFFFFFFF); - quad2DVertices[2].Color = SColor(0xFFFFFFFF); - quad2DVertices[3].Color = SColor(0xFFFFFFFF); - - drawQuad(vt2DImage, quad2DVertices); - } - - void COpenGL3DriverBase::draw2DImageBatch(const video::ITexture* texture, - const core::array >& positions, - const core::array >& sourceRects, - const core::rect* clipRect, - SColor color, bool useAlphaChannelOfTexture) - { - if (!texture) - return; - - chooseMaterial2D(); - if (!setMaterialTexture(0, texture)) - return; - - setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); - - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - - if (clipRect) - { - if (!clipRect->isValid()) - return; - - glEnable(GL_SCISSOR_TEST); - glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, - clipRect->getWidth(), clipRect->getHeight()); - } - - const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); - assert(6 * std::size_t(drawCount) <= QuadsIndices.size()); - - core::array vtx(drawCount * 4); - - for (u32 i = 0; i < drawCount; i++) - { - 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()); - - // now draw it. - - core::rect tcoords; - tcoords.UpperLeftCorner.X = (((f32)sourcePos.X)) / texture->getOriginalSize().Width ; - tcoords.UpperLeftCorner.Y = (((f32)sourcePos.Y)) / texture->getOriginalSize().Height; - tcoords.LowerRightCorner.X = tcoords.UpperLeftCorner.X + ((f32)(sourceSize.Width) / texture->getOriginalSize().Width); - tcoords.LowerRightCorner.Y = tcoords.UpperLeftCorner.Y + ((f32)(sourceSize.Height) / texture->getOriginalSize().Height); - - const core::rect poss(targetPos, sourceSize); - - f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - vtx.push_back(S3DVertex(left, top, 0.0f, - 0.0f, 0.0f, 0.0f, color, - tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); - vtx.push_back(S3DVertex(right, top, 0.0f, - 0.0f, 0.0f, 0.0f, color, - tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); - vtx.push_back(S3DVertex(right, down, 0.0f, - 0.0f, 0.0f, 0.0f, color, - tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); - vtx.push_back(S3DVertex(left, down, 0.0f, - 0.0f, 0.0f, 0.0f, color, - tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); - } - - drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), QuadsIndices.data(), 6 * drawCount); - - if (clipRect) - glDisable(GL_SCISSOR_TEST); - } - - - //! draw a 2d rectangle - void COpenGL3DriverBase::draw2DRectangle(SColor color, - const core::rect& position, - const core::rect* clip) - { - chooseMaterial2D(); - setMaterialTexture(0, 0); - - setRenderStates2DMode(color.getAlpha() < 255, false, false); - - core::rect pos = position; - - if (clip) - pos.clipAgainst(*clip); - - if (!pos.isValid()) - return; - - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - - f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - S3DVertex vertices[4]; - vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, 0, 0); - vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, 0, 0); - vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0); - vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0); - - drawQuad(vtPrimitive, vertices); - } - - - //! draw an 2d rectangle - void COpenGL3DriverBase::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; - - chooseMaterial2D(); - setMaterialTexture(0, 0); - - setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || - colorRightUp.getAlpha() < 255 || - colorLeftDown.getAlpha() < 255 || - colorRightDown.getAlpha() < 255, false, false); - - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - - f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - S3DVertex vertices[4]; - vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, colorLeftUp, 0, 0); - vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, colorRightUp, 0, 0); - vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0); - vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0); - - drawQuad(vtPrimitive, vertices); - } - - - //! Draws a 2d line. - void COpenGL3DriverBase::draw2DLine(const core::position2d& start, - const core::position2d& end, SColor color) - { - if (start==end) - drawPixel(start.X, start.Y, color); - else - { - chooseMaterial2D(); - setMaterialTexture(0, 0); - - setRenderStates2DMode(color.getAlpha() < 255, false, false); - - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - - f32 startX = (f32)start.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 endX = (f32)end.X / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 startY = 2.f - (f32)start.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - f32 endY = 2.f - (f32)end.Y / (f32)renderTargetSize.Height * 2.f - 1.f; - - S3DVertex vertices[2]; - vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); - vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); - - drawArrays(GL_LINES, vtPrimitive, vertices, 2); - } - } - - - //! Draws a pixel - void COpenGL3DriverBase::drawPixel(u32 x, u32 y, const SColor &color) - { - const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); - if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) - return; - - chooseMaterial2D(); - setMaterialTexture(0, 0); - - setRenderStates2DMode(color.getAlpha() < 255, false, false); - - f32 X = (f32)x / (f32)renderTargetSize.Width * 2.f - 1.f; - f32 Y = 2.f - (f32)y / (f32)renderTargetSize.Height * 2.f - 1.f; - - S3DVertex vertices[1]; - vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0); - - drawArrays(GL_POINTS, vtPrimitive, vertices, 1); - } - - void COpenGL3DriverBase::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) - { - drawArrays(GL_TRIANGLE_FAN, vertexType, vertices, 4); - } - - void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) - { - beginDraw(vertexType, reinterpret_cast(vertices)); - glDrawArrays(primitiveType, 0, vertexCount); - endDraw(vertexType); - } - - void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount) - { - beginDraw(vertexType, reinterpret_cast(vertices)); - glDrawElements(primitiveType, indexCount, GL_UNSIGNED_SHORT, indices); - endDraw(vertexType); - } - - void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) - { - for (auto attr: vertexType) { - glEnableVertexAttribArray(attr.Index); - switch (attr.mode) { - case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; - case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; - case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; - } - } - } - - void COpenGL3DriverBase::endDraw(const VertexType &vertexType) - { - for (auto attr: vertexType) - glDisableVertexAttribArray(attr.Index); - } - - ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) - { - core::array imageArray(1); - imageArray.push_back(image); - - COpenGL3Texture* texture = new COpenGL3Texture(name, imageArray, ETT_2D, this); - - return texture; - } - - ITexture* COpenGL3DriverBase::createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) - { - COpenGL3Texture* texture = new COpenGL3Texture(name, image, ETT_CUBEMAP, this); - - return texture; - } - - //! Sets a material. - void COpenGL3DriverBase::setMaterial(const SMaterial& material) - { - Material = material; - OverrideMaterial.apply(Material); - - for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) - { - CacheHandler->getTextureCache().set(i, material.getTexture(i)); - setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); - } - } - - //! prints error if an error happened. - bool COpenGL3DriverBase::testGLError(int code) - { -#ifdef _DEBUG - 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_OUT_OF_MEMORY: - os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); - break; - }; - return true; -#else - return false; -#endif - } - - //! prints error if an error happened. - bool COpenGL3DriverBase::testEGLError() - { -#if defined(EGL_VERSION_1_0) && defined(_DEBUG) - EGLint g = eglGetError(); - switch (g) - { - case EGL_SUCCESS: - return false; - case EGL_NOT_INITIALIZED : - os::Printer::log("Not Initialized", ELL_ERROR); - break; - case EGL_BAD_ACCESS: - os::Printer::log("Bad Access", ELL_ERROR); - break; - case EGL_BAD_ALLOC: - os::Printer::log("Bad Alloc", ELL_ERROR); - break; - case EGL_BAD_ATTRIBUTE: - os::Printer::log("Bad Attribute", ELL_ERROR); - break; - case EGL_BAD_CONTEXT: - os::Printer::log("Bad Context", ELL_ERROR); - break; - case EGL_BAD_CONFIG: - os::Printer::log("Bad Config", ELL_ERROR); - break; - case EGL_BAD_CURRENT_SURFACE: - os::Printer::log("Bad Current Surface", ELL_ERROR); - break; - case EGL_BAD_DISPLAY: - os::Printer::log("Bad Display", ELL_ERROR); - break; - case EGL_BAD_SURFACE: - os::Printer::log("Bad Surface", ELL_ERROR); - break; - case EGL_BAD_MATCH: - os::Printer::log("Bad Match", ELL_ERROR); - break; - case EGL_BAD_PARAMETER: - os::Printer::log("Bad Parameter", ELL_ERROR); - break; - case EGL_BAD_NATIVE_PIXMAP: - os::Printer::log("Bad Native Pixmap", ELL_ERROR); - break; - case EGL_BAD_NATIVE_WINDOW: - os::Printer::log("Bad Native Window", ELL_ERROR); - break; - case EGL_CONTEXT_LOST: - os::Printer::log("Context Lost", ELL_ERROR); - break; - }; - return true; -#else - return false; -#endif - } - - - void COpenGL3DriverBase::setRenderStates3DMode() - { - if ( LockRenderStateMode ) - return; - - if (CurrentRenderMode != ERM_3D) - { - // Reset Texture Stages - CacheHandler->setBlend(false); - CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - ResetRenderStates = true; - } - - if (ResetRenderStates || LastMaterial != Material) - { - // unset old material - - // unset last 3d material - if (CurrentRenderMode == ERM_2D && MaterialRenderer2DActive) - { - MaterialRenderer2DActive->OnUnsetMaterial(); - MaterialRenderer2DActive = 0; - } - else 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; - } - - //! Can be called by an IMaterialRenderer to make its work easier. - void COpenGL3DriverBase::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates) - { - // ZBuffer - switch (material.ZBuffer) - { - case ECFN_DISABLED: - CacheHandler->setDepthTest(false); - break; - case ECFN_LESSEQUAL: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_LEQUAL); - break; - case ECFN_EQUAL: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_EQUAL); - break; - case ECFN_LESS: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_LESS); - break; - case ECFN_NOTEQUAL: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_NOTEQUAL); - break; - case ECFN_GREATEREQUAL: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_GEQUAL); - break; - case ECFN_GREATER: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_GREATER); - break; - case ECFN_ALWAYS: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_ALWAYS); - break; - case ECFN_NEVER: - CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_NEVER); - break; - default: - break; - } - - // ZWrite - if (getWriteZBuffer(material)) - { - CacheHandler->setDepthMask(true); - } - else - { - CacheHandler->setDepthMask(false); - } - - // Back face culling - if ((material.FrontfaceCulling) && (material.BackfaceCulling)) - { - CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK); - CacheHandler->setCullFace(true); - } - else if (material.BackfaceCulling) - { - CacheHandler->setCullFaceFunc(GL_BACK); - CacheHandler->setCullFace(true); - } - else if (material.FrontfaceCulling) - { - CacheHandler->setCullFaceFunc(GL_FRONT); - CacheHandler->setCullFace(true); - } - else - { - CacheHandler->setCullFace(false); - } - - // Color Mask - CacheHandler->setColorMask(material.ColorMask); - - // Blend Equation - if (material.BlendOperation == EBO_NONE) - CacheHandler->setBlend(false); - else - { - CacheHandler->setBlend(true); - - switch (material.BlendOperation) - { - case EBO_ADD: - CacheHandler->setBlendEquation(GL_FUNC_ADD); - break; - case EBO_SUBTRACT: - CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT); - break; - case EBO_REVSUBTRACT: - CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - 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); - - CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), - getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); - } - - // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. - - if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) - 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); - } - - // Texture parameters - setTextureRenderStates(material, resetAllRenderStates); - } - - //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. - void COpenGL3DriverBase::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) - { - const COpenGL3Texture* tmpTexture = CacheHandler->getTextureCache()[i]; - - if (!tmpTexture) - continue; - - GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); - - CacheHandler->setActiveTexture(GL_TEXTURE0 + i); - - if (resetAllRenderstates) - tmpTexture->getStatesCache().IsCached = false; - - if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || - material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter) - { - glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, - (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); - - tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; - tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; - } - - if (material.UseMipMaps && tmpTexture->hasMipMaps()) - { - if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || - material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || !tmpTexture->getStatesCache().MipMapStatus) - { - glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, - material.TextureLayer[i].TrilinearFilter ? GL_LINEAR_MIPMAP_LINEAR : - material.TextureLayer[i].BilinearFilter ? GL_LINEAR_MIPMAP_NEAREST : - GL_NEAREST_MIPMAP_NEAREST); - - tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; - tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; - tmpTexture->getStatesCache().MipMapStatus = true; - } - } - else - { - if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || - material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || tmpTexture->getStatesCache().MipMapStatus) - { - glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, - (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); - - tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; - tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; - tmpTexture->getStatesCache().MipMapStatus = false; - } - } - - #ifdef GL_EXT_texture_filter_anisotropic - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] && - (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter)) - { - glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, - material.TextureLayer[i].AnisotropicFilter>1 ? core::min_(MaxAnisotropy, material.TextureLayer[i].AnisotropicFilter) : 1); - - tmpTexture->getStatesCache().AnisotropicFilter = material.TextureLayer[i].AnisotropicFilter; - } - #endif - - if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapU != tmpTexture->getStatesCache().WrapU) - { - glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayer[i].TextureWrapU)); - tmpTexture->getStatesCache().WrapU = material.TextureLayer[i].TextureWrapU; - } - - if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapV != tmpTexture->getStatesCache().WrapV) - { - glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayer[i].TextureWrapV)); - tmpTexture->getStatesCache().WrapV = material.TextureLayer[i].TextureWrapV; - } - - tmpTexture->getStatesCache().IsCached = true; - } - } - - - // Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode. - GLint COpenGL3DriverBase::getTextureWrapMode(u8 clamp) const - { - switch (clamp) - { - case ETC_CLAMP: - case ETC_CLAMP_TO_EDGE: - case ETC_CLAMP_TO_BORDER: - return GL_CLAMP_TO_EDGE; - case ETC_MIRROR: - return GL_REPEAT; - default: - return GL_REPEAT; - } - } - - - //! sets the needed renderstates - void COpenGL3DriverBase::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) - { - if ( LockRenderStateMode ) - return; - - COpenGL3Renderer2D* nextActiveRenderer = texture ? MaterialRenderer2DTexture : MaterialRenderer2DNoTexture; - - if (CurrentRenderMode != ERM_2D) - { - // unset last 3d material - if (CurrentRenderMode == ERM_3D) - { - if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) - MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); - } - - CurrentRenderMode = ERM_2D; - } - else if ( MaterialRenderer2DActive && MaterialRenderer2DActive != nextActiveRenderer) - { - MaterialRenderer2DActive->OnUnsetMaterial(); - } - - MaterialRenderer2DActive = nextActiveRenderer; - - MaterialRenderer2DActive->OnSetMaterial(Material, LastMaterial, true, 0); - 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); - } - else - CacheHandler->setBlend(false); - - Material.setTexture(0, const_cast(CacheHandler->getTextureCache().get(0))); - setTransform(ETS_TEXTURE_0, core::IdentityMatrix); - - if (texture) - { - if (OverrideMaterial2DEnabled) - setTextureRenderStates(OverrideMaterial2D, false); - else - setTextureRenderStates(InitMaterial2D, false); - } - - MaterialRenderer2DActive->OnRender(this, video::EVT_STANDARD); - } - - - void COpenGL3DriverBase::chooseMaterial2D() - { - if (!OverrideMaterial2DEnabled) - Material = InitMaterial2D; - - if (OverrideMaterial2DEnabled) - { - OverrideMaterial2D.Lighting=false; - OverrideMaterial2D.ZWriteEnable=EZW_OFF; - OverrideMaterial2D.ZBuffer=ECFN_DISABLED; // it will be ECFN_DISABLED after merge - OverrideMaterial2D.Lighting=false; - - Material = OverrideMaterial2D; - } - } - - - //! \return Returns the name of the video driver. - const wchar_t* COpenGL3DriverBase::getName() const - { - return Name.c_str(); - } - - void COpenGL3DriverBase::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 COpenGL3DriverBase::setViewPortRaw(u32 width, u32 height) - { - CacheHandler->setViewport(0, 0, width, height); - ViewPort = core::recti(0, 0, width, height); - } - - - //! Draws a 3d line. - void COpenGL3DriverBase::draw3DLine(const core::vector3df& start, - const core::vector3df& end, SColor color) - { - setRenderStates3DMode(); - - 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); - - drawArrays(GL_LINES, vtPrimitive, vertices, 2); - } - - - //! Only used by the internal engine. Used to notify the driver that - //! the window was resized. - void COpenGL3DriverBase::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 COpenGL3DriverBase::getDriverType() const - { - return EDT_OPENGL3; - } - - - //! returns color format - ECOLOR_FORMAT COpenGL3DriverBase::getColorFormat() const - { - return ColorFormat; - } - - - //! Get a vertex shader constant index. - s32 COpenGL3DriverBase::getVertexShaderConstantID(const c8* name) - { - return getPixelShaderConstantID(name); - } - - //! Get a pixel shader constant index. - s32 COpenGL3DriverBase::getPixelShaderConstantID(const c8* name) - { - os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID()."); - return -1; - } - - //! Sets a vertex shader constant. - void COpenGL3DriverBase::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) - { - os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setPixelShaderConstant()."); - } - - //! Sets a pixel shader constant. - void COpenGL3DriverBase::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) - { - os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); - } - - //! Sets a constant for the vertex shader based on an index. - bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const f32* floats, int count) - { - os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); - return false; - } - - //! Int interface for the above. - bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const s32* ints, int count) - { - os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); - return false; - } - - bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const u32* ints, int count) - { - os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); - return false; - } - - //! Sets a constant for the pixel shader based on an index. - bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const f32* floats, int count) - { - os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); - return false; - } - - //! Int interface for the above. - bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const s32* ints, int count) - { - os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); - return false; - } - - bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const u32* ints, int count) - { - os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); - return false; - } - - //! Adds a new material renderer to the VideoDriver, using pixel and/or - //! vertex shaders to render geometry. - s32 COpenGL3DriverBase::addShaderMaterial(const c8* vertexShaderProgram, - const c8* pixelShaderProgram, - IShaderConstantSetCallBack* callback, - E_MATERIAL_TYPE baseMaterial, s32 userData) - { - os::Printer::log("No shader support."); - return -1; - } - - - //! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. - s32 COpenGL3DriverBase::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) - { - s32 nr = -1; - COpenGL3MaterialRenderer* r = new COpenGL3MaterialRenderer( - this, nr, vertexShaderProgram, - pixelShaderProgram, - callback, baseMaterial, userData); - - r->drop(); - return nr; - } - - //! Returns a pointer to the IVideoDriver interface. (Implementation for - //! IMaterialRendererServices) - IVideoDriver* COpenGL3DriverBase::getVideoDriver() - { - return this; - } - - - //! Returns pointer to the IGPUProgrammingServices interface. - IGPUProgrammingServices* COpenGL3DriverBase::getGPUProgrammingServices() - { - return this; - } - - ITexture* COpenGL3DriverBase::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); - - COpenGL3Texture* renderTargetTexture = new COpenGL3Texture(name, size, ETT_2D, format, this); - addTexture(renderTargetTexture); - renderTargetTexture->drop(); - - //restore mip-mapping - setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); - - return renderTargetTexture; - } - - ITexture* COpenGL3DriverBase::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); - } - - COpenGL3Texture* renderTargetTexture = new COpenGL3Texture(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 COpenGL3DriverBase::getMaximalPrimitiveCount() const - { - return 65535; - } - - bool COpenGL3DriverBase::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) - { - if (target && target->getDriverType() != getDriverType()) - { - os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL 3 driver.", ELL_ERROR); - return false; - } - - core::dimension2d destRenderTargetSize(0, 0); - - if (target) - { - COpenGL3RenderTarget* renderTarget = static_cast(target); - - CacheHandler->setFBO(renderTarget->getBufferID()); - renderTarget->update(); - - destRenderTargetSize = renderTarget->getSize(); - - setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); - } - else - { - CacheHandler->setFBO(0); - - destRenderTargetSize = core::dimension2d(0, 0); - - setViewPortRaw(ScreenSize.Width, ScreenSize.Height); - } - - if (CurrentRenderTargetSize != destRenderTargetSize) - { - CurrentRenderTargetSize = destRenderTargetSize; - - Transformation3DChanged = true; - } - - CurrentRenderTarget = target; - - clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); - - return true; - } - - void COpenGL3DriverBase::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) - { - GLbitfield mask = 0; - u8 colorMask = 0; - bool depthMask = false; - - CacheHandler->getColorMask(colorMask); - CacheHandler->getDepthMask(depthMask); - - if (flag & ECBF_COLOR) - { - CacheHandler->setColorMask(ECP_ALL); - - 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) - { - CacheHandler->setDepthMask(true); - glClearDepthf(depth); - mask |= GL_DEPTH_BUFFER_BIT; - } - - if (flag & ECBF_STENCIL) - { - glClearStencil(stencil); - mask |= GL_STENCIL_BUFFER_BIT; - } - - if (mask) - glClear(mask); - - CacheHandler->setColorMask(colorMask); - CacheHandler->setDepthMask(depthMask); - } - - - //! 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* COpenGL3DriverBase::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; - { -// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat); -// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); - // there's a format we don't support ATM - if (GL_UNSIGNED_SHORT_4_4_4_4 == type) - { - internalformat = GL_RGBA; - type = GL_UNSIGNED_BYTE; - } - } - - IImage* newImage = 0; - if (GL_RGBA == internalformat) - { - 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); - } - - if (!newImage) - return 0; - - u8* pixels = static_cast(newImage->getData()); - if (!pixels) - { - newImage->drop(); - return 0; - } - - glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); - testGLError(__LINE__); - - // 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; - - // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) - if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) - { - pixels = static_cast(newImage->getData()); - for (u32 i = 0; i < ScreenSize.Height; i++) - { - for (u32 j = 0; j < ScreenSize.Width; j++) - { - u32 c = *(u32*) (pixels + 4 * j); - *(u32*) (pixels + 4 * j) = (c & 0xFF00FF00) | - ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16); - } - pixels += pitch; - } - } - - if (testGLError(__LINE__)) - { - newImage->drop(); - return 0; - } - testGLError(__LINE__); - return newImage; - } - - void COpenGL3DriverBase::removeTexture(ITexture* texture) - { - CacheHandler->getTextureCache().remove(texture); - CNullDriver::removeTexture(texture); - } - - //! Set/unset a clipping plane. - bool COpenGL3DriverBase::setClipPlane(u32 index, const core::plane3df& plane, bool enable) - { - if (index >= UserClipPlane.size()) - UserClipPlane.push_back(SUserClipPlane()); - - UserClipPlane[index].Plane = plane; - UserClipPlane[index].Enabled = enable; - return true; - } - - //! Enable/disable a clipping plane. - void COpenGL3DriverBase::enableClipPlane(u32 index, bool enable) - { - UserClipPlane[index].Enabled = enable; - } - - //! Get the ClipPlane Count - u32 COpenGL3DriverBase::getClipPlaneCount() const - { - return UserClipPlane.size(); - } - - const core::plane3df& COpenGL3DriverBase::getClipPlane(irr::u32 index) const - { - if (index < UserClipPlane.size()) - return UserClipPlane[index].Plane; - else - { - _IRR_DEBUG_BREAK_IF(true) // invalid index - static const core::plane3df dummy; - return dummy; - } - } - - core::dimension2du COpenGL3DriverBase::getMaxTextureSize() const - { - return core::dimension2du(MaxTextureSize, MaxTextureSize); - } - - GLenum COpenGL3DriverBase::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]; - } - - bool COpenGL3DriverBase::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, - GLenum& pixelType, void(**converter)(const void*, s32, void*)) const - { - bool supported = false; - pixelFormat = GL_RGBA; - pixelType = GL_UNSIGNED_BYTE; - *converter = 0; - - switch (format) - { - case ECF_A1R5G5B5: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_UNSIGNED_SHORT_5_5_5_1; - *converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1; - break; - case ECF_R5G6B5: - supported = true; - pixelFormat = GL_RGB; - pixelType = GL_UNSIGNED_SHORT_5_6_5; - break; - case ECF_R8G8B8: - supported = true; - 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)) - { - pixelFormat = GL_BGRA; - } - else - { - pixelFormat = GL_RGBA; - *converter = CColorConverter::convert_A8R8G8B8toA8B8G8R8; - } - pixelType = GL_UNSIGNED_BYTE; - break; -#ifdef GL_EXT_texture_compression_s3tc - case ECF_DXT1: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - break; - case ECF_DXT2: - case ECF_DXT3: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - break; - case ECF_DXT4: - case ECF_DXT5: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - break; -#endif -#ifdef GL_OES_compressed_ETC1_RGB8_texture - case ECF_ETC1: - supported = true; - pixelFormat = GL_RGB; - pixelType = GL_ETC1_RGB8_OES; - break; -#endif -#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available - case ECF_ETC2_RGB: - supported = true; - pixelFormat = GL_RGB; - pixelType = GL_COMPRESSED_RGB8_ETC2; - break; -#endif -#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available - case ECF_ETC2_ARGB: - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_COMPRESSED_RGBA8_ETC2_EAC; - break; -#endif - case ECF_D16: - supported = true; - 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; - 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; - pixelFormat = GL_DEPTH_STENCIL_OES; - pixelType = GL_UNSIGNED_INT_24_8_OES; - } -#endif - break; - case ECF_R8: -#if defined(GL_EXT_texture_rg) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg)) - { - supported = true; - pixelFormat = GL_RED_EXT; - pixelType = GL_UNSIGNED_BYTE; - } -#endif - break; - case ECF_R8G8: -#if defined(GL_EXT_texture_rg) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg)) - { - supported = true; - pixelFormat = GL_RG_EXT; - pixelType = GL_UNSIGNED_BYTE; - } -#endif - break; - case ECF_R16: - break; - case ECF_R16G16: - break; - case ECF_R16F: -#if defined(GL_OES_texture_half_float) && defined(GL_EXT_texture_rg) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) - && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float) - ) - { - supported = true; - pixelFormat = GL_RED_EXT; - pixelType = GL_HALF_FLOAT_OES ; - } -#endif - break; - case ECF_G16R16F: -#if defined(GL_OES_texture_half_float) && defined(GL_EXT_texture_rg) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) - && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float) - ) - { - supported = true; - pixelFormat = GL_RG_EXT; - pixelType = GL_HALF_FLOAT_OES ; - } -#endif - break; - case ECF_A16B16G16R16F: -#if defined(GL_OES_texture_half_float) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)) - { - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_HALF_FLOAT_OES ; - } -#endif - break; - case ECF_R32F: -#if defined(GL_OES_texture_float) && defined(GL_EXT_texture_rg) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) - && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float) - ) - { - supported = true; - pixelFormat = GL_RED_EXT; - pixelType = GL_FLOAT; - } -#endif - break; - case ECF_G32R32F: -#if defined(GL_OES_texture_float) && defined(GL_EXT_texture_rg) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) - && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float) - ) - { - supported = true; - pixelFormat = GL_RG_EXT; - pixelType = GL_FLOAT; - } -#endif - break; - case ECF_A32B32G32R32F: -#if defined(GL_OES_texture_float) - if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)) - { - supported = true; - pixelFormat = GL_RGBA; - pixelType = GL_FLOAT ; - } -#endif - break; - default: - break; - } - - // ES 2.0 says internalFormat must match pixelFormat (chapter 3.7.1 in Spec). - // Doesn't mention if "match" means "equal" or some other way of matching, but - // some bug on Emscripten and browsing discussions by others lead me to believe - // it means they have to be equal. Note that this was different in OpenGL. - internalFormat = pixelFormat; - -#ifdef _IRR_IOS_PLATFORM_ - if (internalFormat == GL_BGRA) - internalFormat = GL_RGBA; -#endif - - return supported; - } - - bool COpenGL3DriverBase::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 COpenGL3DriverBase::needsTransparentRenderPass(const irr::video::SMaterial& material) const - { - return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); - } - - const SMaterial& COpenGL3DriverBase::getCurrentMaterial() const - { - return Material; - } - - COpenGL3CacheHandler* COpenGL3DriverBase::getCacheHandler() const - { - return CacheHandler; - } - -} // end namespace -} // end namespace +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Driver.h" +#include +#include "CNullDriver.h" +#include "IContextManager.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreRenderTarget.h" +#include "COpenGLCoreCacheHandler.h" + +#include "MaterialRenderer.h" +#include "FixedPipelineRenderer.h" +#include "Renderer2D.h" + +#include "EVertexAttributes.h" +#include "CImage.h" +#include "os.h" + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ +#include "android_native_app_glue.h" +#endif + +#include "mt_opengl.h" + +namespace irr +{ +namespace video +{ + struct VertexAttribute { + enum class Mode { + Regular, + Normalized, + Integral, + }; + int Index; + int ComponentCount; + GLenum ComponentType; + Mode mode; + int Offset; + }; + + struct VertexType { + int VertexSize; + int AttributeCount; + VertexAttribute Attributes[]; + + VertexType(const VertexType &) = delete; + VertexType &operator= (const VertexType &) = delete; + }; + + static const VertexAttribute *begin(const VertexType &type) + { + return type.Attributes; + } + + static const VertexAttribute *end(const VertexType &type) + { + return type.Attributes + type.AttributeCount; + } + + static constexpr VertexType vtStandard = { + sizeof(S3DVertex), 4, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + }, + }; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winvalid-offsetof" + + static constexpr VertexType vt2TCoords = { + sizeof(S3DVertex2TCoords), 5, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex2TCoords, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords)}, + {EVA_TCOORD1, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords2)}, + }, + }; + + static constexpr VertexType vtTangents = { + sizeof(S3DVertexTangents), 6, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Pos)}, + {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Normal)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertexTangents, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, TCoords)}, + {EVA_TANGENT, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Tangent)}, + {EVA_BINORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Binormal)}, + }, + }; + +#pragma GCC diagnostic pop + + static const VertexType &getVertexTypeDescription(E_VERTEX_TYPE type) + { + switch (type) { + case EVT_STANDARD: return vtStandard; + case EVT_2TCOORDS: return vt2TCoords; + case EVT_TANGENTS: return vtTangents; + default: assert(false); + } + } + + static constexpr VertexType vt2DImage = { + sizeof(S3DVertex), 3, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + }, + }; + + static constexpr VertexType vtPrimitive = { + sizeof(S3DVertex), 2, { + {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + }, + }; + + +void APIENTRY COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +{ + ((COpenGL3DriverBase *)userParam)->debugCb(source, type, id, severity, length, message); +} + +void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) +{ + printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); +} + +COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : + CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), + Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), + MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), + CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), + OGLES2ShaderPath(params.OGLES2ShaderPath), + ColorFormat(ECF_R8G8B8), ContextManager(contextManager) +{ +#ifdef _DEBUG + setDebugName("Driver"); +#endif + + if (!ContextManager) + return; + + ContextManager->grab(); + ContextManager->generateSurface(); + ContextManager->generateContext(); + ExposedData = ContextManager->getContext(); + ContextManager->activateContext(ExposedData, false); + GL.LoadAllProcedures(ContextManager); + GL.DebugMessageCallback(debugCb, this); + initQuadsIndices(); +} + +COpenGL3DriverBase::~COpenGL3DriverBase() +{ + deleteMaterialRenders(); + + CacheHandler->getTextureCache().clear(); + + removeAllRenderTargets(); + deleteAllTextures(); + removeAllOcclusionQueries(); + removeAllHardwareBuffers(); + + delete MaterialRenderer2DTexture; + delete MaterialRenderer2DNoTexture; + delete CacheHandler; + + if (ContextManager) + { + ContextManager->destroyContext(); + ContextManager->destroySurface(); + ContextManager->terminate(); + ContextManager->drop(); + } +} + + void COpenGL3DriverBase::initQuadsIndices(int max_vertex_count) + { + int max_quad_count = max_vertex_count / 4; + QuadsIndices.reserve(6 * max_quad_count); + for (int k = 0; k < max_quad_count; k++) { + QuadsIndices.push_back(4 * k + 0); + QuadsIndices.push_back(4 * k + 1); + QuadsIndices.push_back(4 * k + 2); + QuadsIndices.push_back(4 * k + 0); + QuadsIndices.push_back(4 * k + 2); + QuadsIndices.push_back(4 * k + 3); + } + } + + bool COpenGL3DriverBase::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 COpenGL3CacheHandler(this); + + StencilBuffer = stencilBuffer; + + DriverAttributes->setAttribute("MaxTextures", (s32)Feature.MaxTextureUnits); + DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits); +// DriverAttributes->setAttribute("MaxLights", MaxLights); + DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy); +// DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes); +// DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers); +// DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets); + 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); + + UserClipPlane.reallocate(0); + + 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_GENERATE_MIPMAP_HINT, GL_NICEST); + glFrontFace(GL_CW); + + // 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 COpenGL3DriverBase::loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData) + { + io::path vsPath(OGLES2ShaderPath); + vsPath += vertexShaderName; + + io::path fsPath(OGLES2ShaderPath); + fsPath += fragmentShaderName; + + *vertexShaderData = 0; + *fragmentShaderData = 0; + + io::IReadFile* vsFile = FileSystem->createAndOpenFile(vsPath); + if ( !vsFile ) + { + core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n"); + warning += core::stringw(vsPath) + L"\n"; + warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; + os::Printer::log(warning.c_str(), ELL_WARNING); + return; + } + + io::IReadFile* fsFile = FileSystem->createAndOpenFile(fsPath); + if ( !fsFile ) + { + core::stringw warning(L"Warning: Missing shader files needed to simulate fixed function materials:\n"); + warning += core::stringw(fsPath) + L"\n"; + warning += L"Shaderpath can be changed in SIrrCreationParamters::OGLES2ShaderPath"; + os::Printer::log(warning.c_str(), ELL_WARNING); + return; + } + + long size = vsFile->getSize(); + if (size) + { + *vertexShaderData = new c8[size+1]; + vsFile->read(*vertexShaderData, size); + (*vertexShaderData)[size] = 0; + } + + size = fsFile->getSize(); + if (size) + { + // if both handles are the same we must reset the file + if (fsFile == vsFile) + fsFile->seek(0); + + *fragmentShaderData = new c8[size+1]; + fsFile->read(*fragmentShaderData, size); + (*fragmentShaderData)[size] = 0; + } + + vsFile->drop(); + fsFile->drop(); + } + + void COpenGL3DriverBase::createMaterialRenderers() + { + // Create callbacks. + + COpenGL3MaterialSolidCB* SolidCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolid2CB* Solid2LayerCB = new COpenGL3MaterialSolid2CB(); + COpenGL3MaterialLightmapCB* LightmapCB = new COpenGL3MaterialLightmapCB(1.f); + COpenGL3MaterialLightmapCB* LightmapAddCB = new COpenGL3MaterialLightmapCB(1.f); + COpenGL3MaterialLightmapCB* LightmapM2CB = new COpenGL3MaterialLightmapCB(2.f); + COpenGL3MaterialLightmapCB* LightmapM4CB = new COpenGL3MaterialLightmapCB(4.f); + COpenGL3MaterialLightmapCB* LightmapLightingCB = new COpenGL3MaterialLightmapCB(1.f); + COpenGL3MaterialLightmapCB* LightmapLightingM2CB = new COpenGL3MaterialLightmapCB(2.f); + COpenGL3MaterialLightmapCB* LightmapLightingM4CB = new COpenGL3MaterialLightmapCB(4.f); + COpenGL3MaterialSolid2CB* DetailMapCB = new COpenGL3MaterialSolid2CB(); + COpenGL3MaterialReflectionCB* SphereMapCB = new COpenGL3MaterialReflectionCB(); + COpenGL3MaterialReflectionCB* Reflection2LayerCB = new COpenGL3MaterialReflectionCB(); + COpenGL3MaterialSolidCB* TransparentAddColorCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB* TransparentAlphaChannelCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB* TransparentAlphaChannelRefCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialSolidCB* TransparentVertexAlphaCB = new COpenGL3MaterialSolidCB(); + COpenGL3MaterialReflectionCB* TransparentReflection2LayerCB = new COpenGL3MaterialReflectionCB(); + COpenGL3MaterialOneTextureBlendCB* OneTextureBlendCB = new COpenGL3MaterialOneTextureBlendCB(); + + // Create built-in materials. + + core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + core::stringc FragmentShader = OGLES2ShaderPath + "Solid.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SolidCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid2.vsh"; + FragmentShader = OGLES2ShaderPath + "Solid2Layer.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Solid2LayerCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid2.vsh"; + FragmentShader = OGLES2ShaderPath + "LightmapModulate.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapCB, EMT_SOLID, 0); + + FragmentShader = OGLES2ShaderPath + "LightmapAdd.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapAddCB, EMT_SOLID, 0); + + FragmentShader = OGLES2ShaderPath + "LightmapModulate.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM2CB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapM4CB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingCB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM2CB, EMT_SOLID, 0); + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, LightmapLightingM4CB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid2.vsh"; + FragmentShader = OGLES2ShaderPath + "DetailMap.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, DetailMapCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "SphereMap.vsh"; + FragmentShader = OGLES2ShaderPath + "SphereMap.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, SphereMapCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; + FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, Reflection2LayerCB, EMT_SOLID, 0); + + VertexShader = OGLES2ShaderPath + "Solid.vsh"; + FragmentShader = OGLES2ShaderPath + "Solid.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0); + + FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannel.fsh"; + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannelRef.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentAlphaChannelRefCB, EMT_SOLID, 0); + + FragmentShader = OGLES2ShaderPath + "TransparentVertexAlpha.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; + FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, TransparentReflection2LayerCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + + VertexShader = OGLES2ShaderPath + "Solid.vsh"; + FragmentShader = OGLES2ShaderPath + "OneTextureBlend.fsh"; + + addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main", + EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, OneTextureBlendCB, EMT_ONETEXTURE_BLEND, 0); + + // Drop callbacks. + + SolidCB->drop(); + Solid2LayerCB->drop(); + LightmapCB->drop(); + LightmapAddCB->drop(); + LightmapM2CB->drop(); + LightmapM4CB->drop(); + LightmapLightingCB->drop(); + LightmapLightingM2CB->drop(); + LightmapLightingM4CB->drop(); + DetailMapCB->drop(); + SphereMapCB->drop(); + Reflection2LayerCB->drop(); + TransparentAddColorCB->drop(); + TransparentAlphaChannelCB->drop(); + TransparentAlphaChannelRefCB->drop(); + TransparentVertexAlphaCB->drop(); + TransparentReflection2LayerCB->drop(); + OneTextureBlendCB->drop(); + + // Create 2D material renderers + + c8* vs2DData = 0; + c8* fs2DData = 0; + loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D.fsh"), &vs2DData, &fs2DData); + MaterialRenderer2DTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, true); + delete[] vs2DData; + delete[] fs2DData; + vs2DData = 0; + fs2DData = 0; + + loadShaderData(io::path("Renderer2D.vsh"), io::path("Renderer2D_noTex.fsh"), &vs2DData, &fs2DData); + MaterialRenderer2DNoTexture = new COpenGL3Renderer2D(vs2DData, fs2DData, this, false); + delete[] vs2DData; + delete[] fs2DData; + } + + bool COpenGL3DriverBase::setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture) + { + Material.TextureLayer[layerIdx].Texture = const_cast(texture); // function uses const-pointer for texture because all draw functions use const-pointers already + return CacheHandler->getTextureCache().set(0, texture); + } + + bool COpenGL3DriverBase::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 COpenGL3DriverBase::endScene() + { + CNullDriver::endScene(); + + glFlush(); + + if (ContextManager) + return ContextManager->swapBuffers(); + + return false; + } + + + //! Returns the transformation set by setTransform + const core::matrix4& COpenGL3DriverBase::getTransform(E_TRANSFORMATION_STATE state) const + { + return Matrices[state]; + } + + + //! sets transformation + void COpenGL3DriverBase::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) + { + Matrices[state] = mat; + Transformation3DChanged = true; + } + + + bool COpenGL3DriverBase::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); + + const void *buffer = vertices; + size_t bufferSize = vertexSize * vertexCount; + + //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 < bufferSize) + { + newBuffer = true; + } + + glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + + // copy data to graphics card + if (!newBuffer) + glBufferSubData(GL_ARRAY_BUFFER, 0, bufferSize, buffer); + else + { + HWBuffer->vbo_verticesSize = bufferSize; + + if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) + glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_STATIC_DRAW); + else + glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_DYNAMIC_DRAW); + } + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + return (!testGLError(__LINE__)); + } + + + bool COpenGL3DriverBase::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 COpenGL3DriverBase::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() + || !static_cast(HWBuffer)->vbo_indicesID) + { + + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + + if (!updateIndexHardwareBuffer((SHWBufferLink_opengl*)HWBuffer)) + return false; + } + } + + return true; + } + + + //! Create hardware buffer from meshbuffer + COpenGL3DriverBase::SHWBufferLink *COpenGL3DriverBase::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 COpenGL3DriverBase::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 COpenGL3DriverBase::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* COpenGL3DriverBase::addRenderTarget() + { + COpenGL3RenderTarget* renderTarget = new COpenGL3RenderTarget(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 COpenGL3DriverBase::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 (!primitiveCount || !vertexCount) + return; + + if (!checkPrimitiveCount(primitiveCount)) + return; + + CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + + setRenderStates3DMode(); + + auto &vTypeDesc = getVertexTypeDescription(vType); + beginDraw(vTypeDesc, reinterpret_cast(vertices)); + 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: + glDrawArrays(GL_POINTS, 0, primitiveCount); + break; + case scene::EPT_LINE_STRIP: + glDrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList); + break; + case scene::EPT_LINE_LOOP: + glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList); + break; + case scene::EPT_LINES: + glDrawElements(GL_LINES, primitiveCount*2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_STRIP: + glDrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLE_FAN: + glDrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); + break; + case scene::EPT_TRIANGLES: + glDrawElements((LastMaterial.Wireframe) ? GL_LINES : (LastMaterial.PointCloud) ? GL_POINTS : GL_TRIANGLES, primitiveCount*3, indexSize, indexList); + break; + default: + break; + } + + endDraw(vTypeDesc); + } + + + void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, const core::position2d& destPos, + const core::rect& sourceRect, const core::rect* clipRect, SColor color, + bool useAlphaChannelOfTexture) + { + if (!texture) + return; + + if (!sourceRect.isValid()) + return; + + SColor colors[4] = {color, color, color, color}; + draw2DImage(texture, {destPos, sourceRect.getSize()}, sourceRect, clipRect, colors, useAlphaChannelOfTexture); + } + + + void COpenGL3DriverBase::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; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture )) + return; + + setRenderStates2DMode(useColor[0].getAlpha() < 255 || useColor[1].getAlpha() < 255 || + useColor[2].getAlpha() < 255 || useColor[3].getAlpha() < 255, + true, useAlphaChannelOfTexture); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + f32 left = (f32)destRect.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)destRect.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)destRect.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)destRect.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, useColor[0], tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, useColor[3], tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, useColor[2], tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, useColor[1], tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y); + + drawQuad(vt2DImage, vertices); + + if (clipRect) + glDisable(GL_SCISSOR_TEST); + + testGLError(__LINE__); + } + + void COpenGL3DriverBase::draw2DImage(const video::ITexture* texture, u32 layer, bool flip) + { + if (!texture) + return; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture )) + return; + + setRenderStates2DMode(false, true, true); + + S3DVertex quad2DVertices[4]; + + quad2DVertices[0].Pos = core::vector3df(-1.f, 1.f, 0.f); + quad2DVertices[1].Pos = core::vector3df(1.f, 1.f, 0.f); + quad2DVertices[2].Pos = core::vector3df(1.f, -1.f, 0.f); + quad2DVertices[3].Pos = core::vector3df(-1.f, -1.f, 0.f); + + f32 modificator = (flip) ? 1.f : 0.f; + + quad2DVertices[0].TCoords = core::vector2df(0.f, 0.f + modificator); + quad2DVertices[1].TCoords = core::vector2df(1.f, 0.f + modificator); + quad2DVertices[2].TCoords = core::vector2df(1.f, 1.f - modificator); + quad2DVertices[3].TCoords = core::vector2df(0.f, 1.f - modificator); + + quad2DVertices[0].Color = SColor(0xFFFFFFFF); + quad2DVertices[1].Color = SColor(0xFFFFFFFF); + quad2DVertices[2].Color = SColor(0xFFFFFFFF); + quad2DVertices[3].Color = SColor(0xFFFFFFFF); + + drawQuad(vt2DImage, quad2DVertices); + } + + void COpenGL3DriverBase::draw2DImageBatch(const video::ITexture* texture, + const core::array >& positions, + const core::array >& sourceRects, + const core::rect* clipRect, + SColor color, bool useAlphaChannelOfTexture) + { + if (!texture) + return; + + chooseMaterial2D(); + if (!setMaterialTexture(0, texture)) + return; + + setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } + + const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); + assert(6 * std::size_t(drawCount) <= QuadsIndices.size()); + + core::array vtx(drawCount * 4); + + for (u32 i = 0; i < drawCount; i++) + { + 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()); + + // now draw it. + + core::rect tcoords; + tcoords.UpperLeftCorner.X = (((f32)sourcePos.X)) / texture->getOriginalSize().Width ; + tcoords.UpperLeftCorner.Y = (((f32)sourcePos.Y)) / texture->getOriginalSize().Height; + tcoords.LowerRightCorner.X = tcoords.UpperLeftCorner.X + ((f32)(sourceSize.Width) / texture->getOriginalSize().Width); + tcoords.LowerRightCorner.Y = tcoords.UpperLeftCorner.Y + ((f32)(sourceSize.Height) / texture->getOriginalSize().Height); + + const core::rect poss(targetPos, sourceSize); + + f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + vtx.push_back(S3DVertex(left, top, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y)); + vtx.push_back(S3DVertex(right, top, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y)); + vtx.push_back(S3DVertex(right, down, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y)); + vtx.push_back(S3DVertex(left, down, 0.0f, + 0.0f, 0.0f, 0.0f, color, + tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); + } + + drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), QuadsIndices.data(), 6 * drawCount); + + if (clipRect) + glDisable(GL_SCISSOR_TEST); + } + + + //! draw a 2d rectangle + void COpenGL3DriverBase::draw2DRectangle(SColor color, + const core::rect& position, + const core::rect* clip) + { + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + core::rect pos = position; + + if (clip) + pos.clipAgainst(*clip); + + if (!pos.isValid()) + return; + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, 0, 0); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, 0, 0); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, 0, 0); + + drawQuad(vtPrimitive, vertices); + } + + + //! draw an 2d rectangle + void COpenGL3DriverBase::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; + + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(colorLeftUp.getAlpha() < 255 || + colorRightUp.getAlpha() < 255 || + colorLeftDown.getAlpha() < 255 || + colorRightDown.getAlpha() < 255, false, false); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + f32 left = (f32)pos.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 right = (f32)pos.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 down = 2.f - (f32)pos.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 top = 2.f - (f32)pos.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[4]; + vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, colorLeftUp, 0, 0); + vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, colorRightUp, 0, 0); + vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, colorRightDown, 0, 0); + vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, colorLeftDown, 0, 0); + + drawQuad(vtPrimitive, vertices); + } + + + //! Draws a 2d line. + void COpenGL3DriverBase::draw2DLine(const core::position2d& start, + const core::position2d& end, SColor color) + { + if (start==end) + drawPixel(start.X, start.Y, color); + else + { + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + + f32 startX = (f32)start.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 endX = (f32)end.X / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 startY = 2.f - (f32)start.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + f32 endY = 2.f - (f32)end.Y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[2]; + vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); + vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); + + drawArrays(GL_LINES, vtPrimitive, vertices, 2); + } + } + + + //! Draws a pixel + void COpenGL3DriverBase::drawPixel(u32 x, u32 y, const SColor &color) + { + const core::dimension2d& renderTargetSize = getCurrentRenderTargetSize(); + if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height) + return; + + chooseMaterial2D(); + setMaterialTexture(0, 0); + + setRenderStates2DMode(color.getAlpha() < 255, false, false); + + f32 X = (f32)x / (f32)renderTargetSize.Width * 2.f - 1.f; + f32 Y = 2.f - (f32)y / (f32)renderTargetSize.Height * 2.f - 1.f; + + S3DVertex vertices[1]; + vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0); + + drawArrays(GL_POINTS, vtPrimitive, vertices, 1); + } + + void COpenGL3DriverBase::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) + { + drawArrays(GL_TRIANGLE_FAN, vertexType, vertices, 4); + } + + void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) + { + beginDraw(vertexType, reinterpret_cast(vertices)); + glDrawArrays(primitiveType, 0, vertexCount); + endDraw(vertexType); + } + + void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount) + { + beginDraw(vertexType, reinterpret_cast(vertices)); + glDrawElements(primitiveType, indexCount, GL_UNSIGNED_SHORT, indices); + endDraw(vertexType); + } + + void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) + { + for (auto attr: vertexType) { + glEnableVertexAttribArray(attr.Index); + switch (attr.mode) { + case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + } + } + } + + void COpenGL3DriverBase::endDraw(const VertexType &vertexType) + { + for (auto attr: vertexType) + glDisableVertexAttribArray(attr.Index); + } + + ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) + { + core::array imageArray(1); + imageArray.push_back(image); + + COpenGL3Texture* texture = new COpenGL3Texture(name, imageArray, ETT_2D, this); + + return texture; + } + + ITexture* COpenGL3DriverBase::createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) + { + COpenGL3Texture* texture = new COpenGL3Texture(name, image, ETT_CUBEMAP, this); + + return texture; + } + + //! Sets a material. + void COpenGL3DriverBase::setMaterial(const SMaterial& material) + { + Material = material; + OverrideMaterial.apply(Material); + + for (u32 i = 0; i < Feature.MaxTextureUnits; ++i) + { + CacheHandler->getTextureCache().set(i, material.getTexture(i)); + setTransform((E_TRANSFORMATION_STATE)(ETS_TEXTURE_0 + i), material.getTextureMatrix(i)); + } + } + + //! prints error if an error happened. + bool COpenGL3DriverBase::testGLError(int code) + { +#ifdef _DEBUG + 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_OUT_OF_MEMORY: + os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif + } + + //! prints error if an error happened. + bool COpenGL3DriverBase::testEGLError() + { +#if defined(EGL_VERSION_1_0) && defined(_DEBUG) + EGLint g = eglGetError(); + switch (g) + { + case EGL_SUCCESS: + return false; + case EGL_NOT_INITIALIZED : + os::Printer::log("Not Initialized", ELL_ERROR); + break; + case EGL_BAD_ACCESS: + os::Printer::log("Bad Access", ELL_ERROR); + break; + case EGL_BAD_ALLOC: + os::Printer::log("Bad Alloc", ELL_ERROR); + break; + case EGL_BAD_ATTRIBUTE: + os::Printer::log("Bad Attribute", ELL_ERROR); + break; + case EGL_BAD_CONTEXT: + os::Printer::log("Bad Context", ELL_ERROR); + break; + case EGL_BAD_CONFIG: + os::Printer::log("Bad Config", ELL_ERROR); + break; + case EGL_BAD_CURRENT_SURFACE: + os::Printer::log("Bad Current Surface", ELL_ERROR); + break; + case EGL_BAD_DISPLAY: + os::Printer::log("Bad Display", ELL_ERROR); + break; + case EGL_BAD_SURFACE: + os::Printer::log("Bad Surface", ELL_ERROR); + break; + case EGL_BAD_MATCH: + os::Printer::log("Bad Match", ELL_ERROR); + break; + case EGL_BAD_PARAMETER: + os::Printer::log("Bad Parameter", ELL_ERROR); + break; + case EGL_BAD_NATIVE_PIXMAP: + os::Printer::log("Bad Native Pixmap", ELL_ERROR); + break; + case EGL_BAD_NATIVE_WINDOW: + os::Printer::log("Bad Native Window", ELL_ERROR); + break; + case EGL_CONTEXT_LOST: + os::Printer::log("Context Lost", ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif + } + + + void COpenGL3DriverBase::setRenderStates3DMode() + { + if ( LockRenderStateMode ) + return; + + if (CurrentRenderMode != ERM_3D) + { + // Reset Texture Stages + CacheHandler->setBlend(false); + CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + ResetRenderStates = true; + } + + if (ResetRenderStates || LastMaterial != Material) + { + // unset old material + + // unset last 3d material + if (CurrentRenderMode == ERM_2D && MaterialRenderer2DActive) + { + MaterialRenderer2DActive->OnUnsetMaterial(); + MaterialRenderer2DActive = 0; + } + else 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; + } + + //! Can be called by an IMaterialRenderer to make its work easier. + void COpenGL3DriverBase::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates) + { + // ZBuffer + switch (material.ZBuffer) + { + case ECFN_DISABLED: + CacheHandler->setDepthTest(false); + break; + case ECFN_LESSEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LEQUAL); + break; + case ECFN_EQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_EQUAL); + break; + case ECFN_LESS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_LESS); + break; + case ECFN_NOTEQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NOTEQUAL); + break; + case ECFN_GREATEREQUAL: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GEQUAL); + break; + case ECFN_GREATER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_GREATER); + break; + case ECFN_ALWAYS: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_ALWAYS); + break; + case ECFN_NEVER: + CacheHandler->setDepthTest(true); + CacheHandler->setDepthFunc(GL_NEVER); + break; + default: + break; + } + + // ZWrite + if (getWriteZBuffer(material)) + { + CacheHandler->setDepthMask(true); + } + else + { + CacheHandler->setDepthMask(false); + } + + // Back face culling + if ((material.FrontfaceCulling) && (material.BackfaceCulling)) + { + CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK); + CacheHandler->setCullFace(true); + } + else if (material.BackfaceCulling) + { + CacheHandler->setCullFaceFunc(GL_BACK); + CacheHandler->setCullFace(true); + } + else if (material.FrontfaceCulling) + { + CacheHandler->setCullFaceFunc(GL_FRONT); + CacheHandler->setCullFace(true); + } + else + { + CacheHandler->setCullFace(false); + } + + // Color Mask + CacheHandler->setColorMask(material.ColorMask); + + // Blend Equation + if (material.BlendOperation == EBO_NONE) + CacheHandler->setBlend(false); + else + { + CacheHandler->setBlend(true); + + switch (material.BlendOperation) + { + case EBO_ADD: + CacheHandler->setBlendEquation(GL_FUNC_ADD); + break; + case EBO_SUBTRACT: + CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT); + break; + case EBO_REVSUBTRACT: + CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + 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); + + CacheHandler->setBlendFuncSeparate(getGLBlend(srcRGBFact), getGLBlend(dstRGBFact), + getGLBlend(srcAlphaFact), getGLBlend(dstAlphaFact)); + } + + // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. + + if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) + 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); + } + + // Texture parameters + setTextureRenderStates(material, resetAllRenderStates); + } + + //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. + void COpenGL3DriverBase::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) + { + const COpenGL3Texture* tmpTexture = CacheHandler->getTextureCache()[i]; + + if (!tmpTexture) + continue; + + GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); + + CacheHandler->setActiveTexture(GL_TEXTURE0 + i); + + if (resetAllRenderstates) + tmpTexture->getStatesCache().IsCached = false; + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || + material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, + (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); + + tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; + tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; + } + + if (material.UseMipMaps && tmpTexture->hasMipMaps()) + { + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || + material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || !tmpTexture->getStatesCache().MipMapStatus) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + material.TextureLayer[i].TrilinearFilter ? GL_LINEAR_MIPMAP_LINEAR : + material.TextureLayer[i].BilinearFilter ? GL_LINEAR_MIPMAP_NEAREST : + GL_NEAREST_MIPMAP_NEAREST); + + tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; + tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; + tmpTexture->getStatesCache().MipMapStatus = true; + } + } + else + { + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].BilinearFilter != tmpTexture->getStatesCache().BilinearFilter || + material.TextureLayer[i].TrilinearFilter != tmpTexture->getStatesCache().TrilinearFilter || tmpTexture->getStatesCache().MipMapStatus) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, + (material.TextureLayer[i].BilinearFilter || material.TextureLayer[i].TrilinearFilter) ? GL_LINEAR : GL_NEAREST); + + tmpTexture->getStatesCache().BilinearFilter = material.TextureLayer[i].BilinearFilter; + tmpTexture->getStatesCache().TrilinearFilter = material.TextureLayer[i].TrilinearFilter; + tmpTexture->getStatesCache().MipMapStatus = false; + } + } + + #ifdef GL_EXT_texture_filter_anisotropic + if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] && + (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter)) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, + material.TextureLayer[i].AnisotropicFilter>1 ? core::min_(MaxAnisotropy, material.TextureLayer[i].AnisotropicFilter) : 1); + + tmpTexture->getStatesCache().AnisotropicFilter = material.TextureLayer[i].AnisotropicFilter; + } + #endif + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapU != tmpTexture->getStatesCache().WrapU) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayer[i].TextureWrapU)); + tmpTexture->getStatesCache().WrapU = material.TextureLayer[i].TextureWrapU; + } + + if (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].TextureWrapV != tmpTexture->getStatesCache().WrapV) + { + glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayer[i].TextureWrapV)); + tmpTexture->getStatesCache().WrapV = material.TextureLayer[i].TextureWrapV; + } + + tmpTexture->getStatesCache().IsCached = true; + } + } + + + // Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode. + GLint COpenGL3DriverBase::getTextureWrapMode(u8 clamp) const + { + switch (clamp) + { + case ETC_CLAMP: + case ETC_CLAMP_TO_EDGE: + case ETC_CLAMP_TO_BORDER: + return GL_CLAMP_TO_EDGE; + case ETC_MIRROR: + return GL_REPEAT; + default: + return GL_REPEAT; + } + } + + + //! sets the needed renderstates + void COpenGL3DriverBase::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel) + { + if ( LockRenderStateMode ) + return; + + COpenGL3Renderer2D* nextActiveRenderer = texture ? MaterialRenderer2DTexture : MaterialRenderer2DNoTexture; + + if (CurrentRenderMode != ERM_2D) + { + // unset last 3d material + if (CurrentRenderMode == ERM_3D) + { + if (static_cast(LastMaterial.MaterialType) < MaterialRenderers.size()) + MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial(); + } + + CurrentRenderMode = ERM_2D; + } + else if ( MaterialRenderer2DActive && MaterialRenderer2DActive != nextActiveRenderer) + { + MaterialRenderer2DActive->OnUnsetMaterial(); + } + + MaterialRenderer2DActive = nextActiveRenderer; + + MaterialRenderer2DActive->OnSetMaterial(Material, LastMaterial, true, 0); + 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); + } + else + CacheHandler->setBlend(false); + + Material.setTexture(0, const_cast(CacheHandler->getTextureCache().get(0))); + setTransform(ETS_TEXTURE_0, core::IdentityMatrix); + + if (texture) + { + if (OverrideMaterial2DEnabled) + setTextureRenderStates(OverrideMaterial2D, false); + else + setTextureRenderStates(InitMaterial2D, false); + } + + MaterialRenderer2DActive->OnRender(this, video::EVT_STANDARD); + } + + + void COpenGL3DriverBase::chooseMaterial2D() + { + if (!OverrideMaterial2DEnabled) + Material = InitMaterial2D; + + if (OverrideMaterial2DEnabled) + { + OverrideMaterial2D.Lighting=false; + OverrideMaterial2D.ZWriteEnable=EZW_OFF; + OverrideMaterial2D.ZBuffer=ECFN_DISABLED; // it will be ECFN_DISABLED after merge + OverrideMaterial2D.Lighting=false; + + Material = OverrideMaterial2D; + } + } + + + //! \return Returns the name of the video driver. + const wchar_t* COpenGL3DriverBase::getName() const + { + return Name.c_str(); + } + + void COpenGL3DriverBase::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 COpenGL3DriverBase::setViewPortRaw(u32 width, u32 height) + { + CacheHandler->setViewport(0, 0, width, height); + ViewPort = core::recti(0, 0, width, height); + } + + + //! Draws a 3d line. + void COpenGL3DriverBase::draw3DLine(const core::vector3df& start, + const core::vector3df& end, SColor color) + { + setRenderStates3DMode(); + + 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); + + drawArrays(GL_LINES, vtPrimitive, vertices, 2); + } + + + //! Only used by the internal engine. Used to notify the driver that + //! the window was resized. + void COpenGL3DriverBase::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 COpenGL3DriverBase::getDriverType() const + { + return EDT_OPENGL3; + } + + + //! returns color format + ECOLOR_FORMAT COpenGL3DriverBase::getColorFormat() const + { + return ColorFormat; + } + + + //! Get a vertex shader constant index. + s32 COpenGL3DriverBase::getVertexShaderConstantID(const c8* name) + { + return getPixelShaderConstantID(name); + } + + //! Get a pixel shader constant index. + s32 COpenGL3DriverBase::getPixelShaderConstantID(const c8* name) + { + os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID()."); + return -1; + } + + //! Sets a vertex shader constant. + void COpenGL3DriverBase::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + } + + //! Sets a pixel shader constant. + void COpenGL3DriverBase::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + } + + //! Sets a constant for the vertex shader based on an index. + bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const f32* floats, int count) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; + } + + //! Int interface for the above. + bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const s32* ints, int count) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; + } + + bool COpenGL3DriverBase::setVertexShaderConstant(s32 index, const u32* ints, int count) + { + os::Printer::log("Error: Please call services->setVertexShaderConstant(), not VideoDriver->setVertexShaderConstant()."); + return false; + } + + //! Sets a constant for the pixel shader based on an index. + bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const f32* floats, int count) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; + } + + //! Int interface for the above. + bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const s32* ints, int count) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; + } + + bool COpenGL3DriverBase::setPixelShaderConstant(s32 index, const u32* ints, int count) + { + os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; + } + + //! Adds a new material renderer to the VideoDriver, using pixel and/or + //! vertex shaders to render geometry. + s32 COpenGL3DriverBase::addShaderMaterial(const c8* vertexShaderProgram, + const c8* pixelShaderProgram, + IShaderConstantSetCallBack* callback, + E_MATERIAL_TYPE baseMaterial, s32 userData) + { + os::Printer::log("No shader support."); + return -1; + } + + + //! Adds a new material renderer to the VideoDriver, using GLSL to render geometry. + s32 COpenGL3DriverBase::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) + { + s32 nr = -1; + COpenGL3MaterialRenderer* r = new COpenGL3MaterialRenderer( + this, nr, vertexShaderProgram, + pixelShaderProgram, + callback, baseMaterial, userData); + + r->drop(); + return nr; + } + + //! Returns a pointer to the IVideoDriver interface. (Implementation for + //! IMaterialRendererServices) + IVideoDriver* COpenGL3DriverBase::getVideoDriver() + { + return this; + } + + + //! Returns pointer to the IGPUProgrammingServices interface. + IGPUProgrammingServices* COpenGL3DriverBase::getGPUProgrammingServices() + { + return this; + } + + ITexture* COpenGL3DriverBase::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); + + COpenGL3Texture* renderTargetTexture = new COpenGL3Texture(name, size, ETT_2D, format, this); + addTexture(renderTargetTexture); + renderTargetTexture->drop(); + + //restore mip-mapping + setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels); + + return renderTargetTexture; + } + + ITexture* COpenGL3DriverBase::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); + } + + COpenGL3Texture* renderTargetTexture = new COpenGL3Texture(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 COpenGL3DriverBase::getMaximalPrimitiveCount() const + { + return 65535; + } + + bool COpenGL3DriverBase::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) + { + if (target && target->getDriverType() != getDriverType()) + { + os::Printer::log("Fatal Error: Tried to set a render target not owned by OpenGL 3 driver.", ELL_ERROR); + return false; + } + + core::dimension2d destRenderTargetSize(0, 0); + + if (target) + { + COpenGL3RenderTarget* renderTarget = static_cast(target); + + CacheHandler->setFBO(renderTarget->getBufferID()); + renderTarget->update(); + + destRenderTargetSize = renderTarget->getSize(); + + setViewPortRaw(destRenderTargetSize.Width, destRenderTargetSize.Height); + } + else + { + CacheHandler->setFBO(0); + + destRenderTargetSize = core::dimension2d(0, 0); + + setViewPortRaw(ScreenSize.Width, ScreenSize.Height); + } + + if (CurrentRenderTargetSize != destRenderTargetSize) + { + CurrentRenderTargetSize = destRenderTargetSize; + + Transformation3DChanged = true; + } + + CurrentRenderTarget = target; + + clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); + + return true; + } + + void COpenGL3DriverBase::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) + { + GLbitfield mask = 0; + u8 colorMask = 0; + bool depthMask = false; + + CacheHandler->getColorMask(colorMask); + CacheHandler->getDepthMask(depthMask); + + if (flag & ECBF_COLOR) + { + CacheHandler->setColorMask(ECP_ALL); + + 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) + { + CacheHandler->setDepthMask(true); + glClearDepthf(depth); + mask |= GL_DEPTH_BUFFER_BIT; + } + + if (flag & ECBF_STENCIL) + { + glClearStencil(stencil); + mask |= GL_STENCIL_BUFFER_BIT; + } + + if (mask) + glClear(mask); + + CacheHandler->setColorMask(colorMask); + CacheHandler->setDepthMask(depthMask); + } + + + //! 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* COpenGL3DriverBase::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; + { +// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat); +// glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); + // there's a format we don't support ATM + if (GL_UNSIGNED_SHORT_4_4_4_4 == type) + { + internalformat = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } + } + + IImage* newImage = 0; + if (GL_RGBA == internalformat) + { + 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); + } + + if (!newImage) + return 0; + + u8* pixels = static_cast(newImage->getData()); + if (!pixels) + { + newImage->drop(); + return 0; + } + + glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); + testGLError(__LINE__); + + // 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; + + // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) + if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) + { + pixels = static_cast(newImage->getData()); + for (u32 i = 0; i < ScreenSize.Height; i++) + { + for (u32 j = 0; j < ScreenSize.Width; j++) + { + u32 c = *(u32*) (pixels + 4 * j); + *(u32*) (pixels + 4 * j) = (c & 0xFF00FF00) | + ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16); + } + pixels += pitch; + } + } + + if (testGLError(__LINE__)) + { + newImage->drop(); + return 0; + } + testGLError(__LINE__); + return newImage; + } + + void COpenGL3DriverBase::removeTexture(ITexture* texture) + { + CacheHandler->getTextureCache().remove(texture); + CNullDriver::removeTexture(texture); + } + + //! Set/unset a clipping plane. + bool COpenGL3DriverBase::setClipPlane(u32 index, const core::plane3df& plane, bool enable) + { + if (index >= UserClipPlane.size()) + UserClipPlane.push_back(SUserClipPlane()); + + UserClipPlane[index].Plane = plane; + UserClipPlane[index].Enabled = enable; + return true; + } + + //! Enable/disable a clipping plane. + void COpenGL3DriverBase::enableClipPlane(u32 index, bool enable) + { + UserClipPlane[index].Enabled = enable; + } + + //! Get the ClipPlane Count + u32 COpenGL3DriverBase::getClipPlaneCount() const + { + return UserClipPlane.size(); + } + + const core::plane3df& COpenGL3DriverBase::getClipPlane(irr::u32 index) const + { + if (index < UserClipPlane.size()) + return UserClipPlane[index].Plane; + else + { + _IRR_DEBUG_BREAK_IF(true) // invalid index + static const core::plane3df dummy; + return dummy; + } + } + + core::dimension2du COpenGL3DriverBase::getMaxTextureSize() const + { + return core::dimension2du(MaxTextureSize, MaxTextureSize); + } + + GLenum COpenGL3DriverBase::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]; + } + + bool COpenGL3DriverBase::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, + GLenum& pixelType, void(**converter)(const void*, s32, void*)) const + { + bool supported = false; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_BYTE; + *converter = 0; + + switch (format) + { + case ECF_A1R5G5B5: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_UNSIGNED_SHORT_5_5_5_1; + *converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1; + break; + case ECF_R5G6B5: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_UNSIGNED_SHORT_5_6_5; + break; + case ECF_R8G8B8: + supported = true; + 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)) + { + pixelFormat = GL_BGRA; + } + else + { + pixelFormat = GL_RGBA; + *converter = CColorConverter::convert_A8R8G8B8toA8B8G8R8; + } + pixelType = GL_UNSIGNED_BYTE; + break; +#ifdef GL_EXT_texture_compression_s3tc + case ECF_DXT1: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + break; + case ECF_DXT2: + case ECF_DXT3: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; + case ECF_DXT4: + case ECF_DXT5: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; +#endif +#ifdef GL_OES_compressed_ETC1_RGB8_texture + case ECF_ETC1: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_ETC1_RGB8_OES; + break; +#endif +#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available + case ECF_ETC2_RGB: + supported = true; + pixelFormat = GL_RGB; + pixelType = GL_COMPRESSED_RGB8_ETC2; + break; +#endif +#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available + case ECF_ETC2_ARGB: + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_COMPRESSED_RGBA8_ETC2_EAC; + break; +#endif + case ECF_D16: + supported = true; + 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; + 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; + pixelFormat = GL_DEPTH_STENCIL_OES; + pixelType = GL_UNSIGNED_INT_24_8_OES; + } +#endif + break; + case ECF_R8: +#if defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg)) + { + supported = true; + pixelFormat = GL_RED_EXT; + pixelType = GL_UNSIGNED_BYTE; + } +#endif + break; + case ECF_R8G8: +#if defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg)) + { + supported = true; + pixelFormat = GL_RG_EXT; + pixelType = GL_UNSIGNED_BYTE; + } +#endif + break; + case ECF_R16: + break; + case ECF_R16G16: + break; + case ECF_R16F: +#if defined(GL_OES_texture_half_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float) + ) + { + supported = true; + pixelFormat = GL_RED_EXT; + pixelType = GL_HALF_FLOAT_OES ; + } +#endif + break; + case ECF_G16R16F: +#if defined(GL_OES_texture_half_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float) + ) + { + supported = true; + pixelFormat = GL_RG_EXT; + pixelType = GL_HALF_FLOAT_OES ; + } +#endif + break; + case ECF_A16B16G16R16F: +#if defined(GL_OES_texture_half_float) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)) + { + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_HALF_FLOAT_OES ; + } +#endif + break; + case ECF_R32F: +#if defined(GL_OES_texture_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float) + ) + { + supported = true; + pixelFormat = GL_RED_EXT; + pixelType = GL_FLOAT; + } +#endif + break; + case ECF_G32R32F: +#if defined(GL_OES_texture_float) && defined(GL_EXT_texture_rg) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg) + && queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float) + ) + { + supported = true; + pixelFormat = GL_RG_EXT; + pixelType = GL_FLOAT; + } +#endif + break; + case ECF_A32B32G32R32F: +#if defined(GL_OES_texture_float) + if (queryGLESFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)) + { + supported = true; + pixelFormat = GL_RGBA; + pixelType = GL_FLOAT ; + } +#endif + break; + default: + break; + } + + // ES 2.0 says internalFormat must match pixelFormat (chapter 3.7.1 in Spec). + // Doesn't mention if "match" means "equal" or some other way of matching, but + // some bug on Emscripten and browsing discussions by others lead me to believe + // it means they have to be equal. Note that this was different in OpenGL. + internalFormat = pixelFormat; + +#ifdef _IRR_IOS_PLATFORM_ + if (internalFormat == GL_BGRA) + internalFormat = GL_RGBA; +#endif + + return supported; + } + + bool COpenGL3DriverBase::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 COpenGL3DriverBase::needsTransparentRenderPass(const irr::video::SMaterial& material) const + { + return CNullDriver::needsTransparentRenderPass(material) || material.isAlphaBlendOperation(); + } + + const SMaterial& COpenGL3DriverBase::getCurrentMaterial() const + { + return Material; + } + + COpenGL3CacheHandler* COpenGL3DriverBase::getCacheHandler() const + { + return CacheHandler; + } + +} // end namespace +} // end namespace diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index e95a633..06907b7 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -1,395 +1,395 @@ -// Copyright (C) 2023 Vitaliy Lobachevskiy -// Copyright (C) 2014 Patryk Nadrowski -// Copyright (C) 2009-2010 Amundis -// 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" - -#include "Common.h" -#include "CNullDriver.h" -#include "IMaterialRendererServices.h" -#include "EDriverFeatures.h" -#include "fast_atof.h" -#include "ExtensionHandler.h" -#include "IContextManager.h" - -namespace irr -{ -namespace video -{ - struct VertexType; - - class COpenGL3FixedPipelineRenderer; - class COpenGL3Renderer2D; - - class COpenGL3DriverBase : public CNullDriver, public IMaterialRendererServices, public COpenGL3ExtensionHandler - { - friend class COpenGLCoreTexture; - - protected: - //! constructor (use createOpenGL3Driver instead) - COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - - public: - - //! destructor - virtual ~COpenGL3DriverBase(); - - 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) - , vbo_verticesSize(0), vbo_indicesSize(0) - {} - - u32 vbo_verticesID; //tmp - u32 vbo_indicesID; //tmp - - u32 vbo_verticesSize; //tmp - u32 vbo_indicesSize; //tmp - }; - - bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); - bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); - - //! updates hardware buffer if needed - 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; - - //! queries the features of the driver, returns true if feature is available - bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override - { - return FeatureEnabled[feature] && COpenGL3ExtensionHandler::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; - - // internally used - virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip); - - void draw2DImageBatch(const video::ITexture* texture, - const core::array >& positions, - const core::array >& sourceRects, - const core::rect* clipRect, - SColor color, - bool useAlphaChannelOfTexture) 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 single pixel - void drawPixel(u32 x, u32 y, const SColor & color) override; - - //! Draws a 3d line. - virtual void draw3DLine(const core::vector3df& start, - const core::vector3df& end, - SColor color = SColor(255, 255, 255, 255)) override; - - //! Draws a pixel -// virtual void drawPixel(u32 x, u32 y, const SColor & color); - - //! Returns the name of the video driver. - const wchar_t* getName() const override; - - //! Returns the maximum texture size supported. - core::dimension2du getMaxTextureSize() const override; - - //! sets a viewport - void setViewPort(const core::rect& area) 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. - 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. - 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 vertex shader constant. - void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1) override; - - //! Sets a pixel shader constant. - void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1) 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 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram, - IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData) override; - - //! Adds a new material renderer to the VideoDriver - virtual s32 addHighLevelShaderMaterial( - const c8* vertexShaderProgram, - const c8* vertexShaderEntryPointName = 0, - E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, - const c8* pixelShaderProgram = 0, - const c8* pixelShaderEntryPointName = 0, - E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, - const c8* geometryShaderProgram = 0, - const c8* geometryShaderEntryPointName = "main", - E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, - scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, - scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, - u32 verticesOut = 0, - IShaderConstantSetCallBack* callback = 0, - E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, - s32 userData=0) 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); - - //! checks if an OGLES1 error has happened and prints it - bool testEGLError(); - - //! Set/unset a clipping plane. - bool setClipPlane(u32 index, const core::plane3df& plane, bool enable = false) override; - - //! returns the current amount of user clip planes set. - u32 getClipPlaneCount() const; - - //! returns the 0 indexed Plane - const core::plane3df& getClipPlane(u32 index) const; - - //! Enable/disable a clipping plane. - void enableClipPlane(u32 index, bool enable) override; - - //! Returns the graphics card vendor name. - core::stringc getVendorInfo() override - { - return VendorName; - }; - - 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; - - virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, - GLenum& pixelType, void(**converter)(const void*, s32, void*)) const; - - //! Get current material. - const SMaterial& getCurrentMaterial() const; - - COpenGL3CacheHandler* getCacheHandler() const; - - protected: - //! inits the opengl-es driver - virtual bool genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer); - - void chooseMaterial2D(); - - ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; - - ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) override; - - //! Map Irrlicht wrap mode to OpenGL enum - GLint getTextureWrapMode(u8 clamp) const; - - //! sets the needed renderstates - void setRenderStates3DMode(); - - //! sets the needed renderstates - void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel); - - //! Prevent setRenderStateMode calls to do anything. - // hack to allow drawing meshbuffers in 2D mode. - // Better solution would be passing this flag through meshbuffers, - // but the way this is currently implemented in Irrlicht makes this tricky to implement - void lockRenderStateMode() - { - LockRenderStateMode = true; - } - - //! Allow setRenderStateMode calls to work again - void unlockRenderStateMode() - { - LockRenderStateMode = false; - } - - void draw2D3DVertexPrimitiveList(const void* vertices, - u32 vertexCount, const void* indexList, u32 primitiveCount, - E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, - E_INDEX_TYPE iType, bool is3D); - - void createMaterialRenderers(); - - void loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData); - - bool setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture); - - //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` - virtual void setViewPortRaw(u32 width, u32 height); - - void drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]); - void drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount); - void drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount); - void drawElements(GLenum primitiveType, const VertexType &vertexType, uintptr_t vertices, uintptr_t indices, int indexCount); - - void beginDraw(const VertexType &vertexType, uintptr_t verticesBase); - void endDraw(const VertexType &vertexType); - - COpenGL3CacheHandler* CacheHandler; - core::stringw Name; - core::stringc VendorName; - SIrrlichtCreationParameters Params; - - //! bool to make all renderstates reset if set to true. - bool ResetRenderStates; - bool LockRenderStateMode; - u8 AntiAlias; - - struct SUserClipPlane - { - core::plane3df Plane; - bool Enabled; - }; - - core::array UserClipPlane; - - core::matrix4 TextureFlipMatrix; - -private: - - COpenGL3Renderer2D* MaterialRenderer2DActive; - COpenGL3Renderer2D* MaterialRenderer2DTexture; - COpenGL3Renderer2D* MaterialRenderer2DNoTexture; - - core::matrix4 Matrices[ETS_COUNT]; - - //! 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 Transformation3DChanged; - irr::io::path OGLES2ShaderPath; - - SMaterial Material, LastMaterial; - - //! Color buffer format - ECOLOR_FORMAT ColorFormat; - - IContextManager* ContextManager; - - std::vector QuadsIndices; - void initQuadsIndices(int max_vertex_count = 65536); - - void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); - static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); - }; - -} // end namespace video -} // end namespace irr +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2014 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// 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" + +#include "Common.h" +#include "CNullDriver.h" +#include "IMaterialRendererServices.h" +#include "EDriverFeatures.h" +#include "fast_atof.h" +#include "ExtensionHandler.h" +#include "IContextManager.h" + +namespace irr +{ +namespace video +{ + struct VertexType; + + class COpenGL3FixedPipelineRenderer; + class COpenGL3Renderer2D; + + class COpenGL3DriverBase : public CNullDriver, public IMaterialRendererServices, public COpenGL3ExtensionHandler + { + friend class COpenGLCoreTexture; + + protected: + //! constructor (use createOpenGL3Driver instead) + COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); + + public: + + //! destructor + virtual ~COpenGL3DriverBase(); + + 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) + , vbo_verticesSize(0), vbo_indicesSize(0) + {} + + u32 vbo_verticesID; //tmp + u32 vbo_indicesID; //tmp + + u32 vbo_verticesSize; //tmp + u32 vbo_indicesSize; //tmp + }; + + bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer); + + //! updates hardware buffer if needed + 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; + + //! queries the features of the driver, returns true if feature is available + bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const override + { + return FeatureEnabled[feature] && COpenGL3ExtensionHandler::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; + + // internally used + virtual void draw2DImage(const video::ITexture* texture, u32 layer, bool flip); + + void draw2DImageBatch(const video::ITexture* texture, + const core::array >& positions, + const core::array >& sourceRects, + const core::rect* clipRect, + SColor color, + bool useAlphaChannelOfTexture) 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 single pixel + void drawPixel(u32 x, u32 y, const SColor & color) override; + + //! Draws a 3d line. + virtual void draw3DLine(const core::vector3df& start, + const core::vector3df& end, + SColor color = SColor(255, 255, 255, 255)) override; + + //! Draws a pixel +// virtual void drawPixel(u32 x, u32 y, const SColor & color); + + //! Returns the name of the video driver. + const wchar_t* getName() const override; + + //! Returns the maximum texture size supported. + core::dimension2du getMaxTextureSize() const override; + + //! sets a viewport + void setViewPort(const core::rect& area) 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. + 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. + 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 vertex shader constant. + void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1) override; + + //! Sets a pixel shader constant. + void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount = 1) 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 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram, + IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData) override; + + //! Adds a new material renderer to the VideoDriver + virtual s32 addHighLevelShaderMaterial( + const c8* vertexShaderProgram, + const c8* vertexShaderEntryPointName = 0, + E_VERTEX_SHADER_TYPE vsCompileTarget = EVST_VS_1_1, + const c8* pixelShaderProgram = 0, + const c8* pixelShaderEntryPointName = 0, + E_PIXEL_SHADER_TYPE psCompileTarget = EPST_PS_1_1, + const c8* geometryShaderProgram = 0, + const c8* geometryShaderEntryPointName = "main", + E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0, + scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES, + scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP, + u32 verticesOut = 0, + IShaderConstantSetCallBack* callback = 0, + E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID, + s32 userData=0) 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); + + //! checks if an OGLES1 error has happened and prints it + bool testEGLError(); + + //! Set/unset a clipping plane. + bool setClipPlane(u32 index, const core::plane3df& plane, bool enable = false) override; + + //! returns the current amount of user clip planes set. + u32 getClipPlaneCount() const; + + //! returns the 0 indexed Plane + const core::plane3df& getClipPlane(u32 index) const; + + //! Enable/disable a clipping plane. + void enableClipPlane(u32 index, bool enable) override; + + //! Returns the graphics card vendor name. + core::stringc getVendorInfo() override + { + return VendorName; + }; + + 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; + + virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, + GLenum& pixelType, void(**converter)(const void*, s32, void*)) const; + + //! Get current material. + const SMaterial& getCurrentMaterial() const; + + COpenGL3CacheHandler* getCacheHandler() const; + + protected: + //! inits the opengl-es driver + virtual bool genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer); + + void chooseMaterial2D(); + + ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; + + ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) override; + + //! Map Irrlicht wrap mode to OpenGL enum + GLint getTextureWrapMode(u8 clamp) const; + + //! sets the needed renderstates + void setRenderStates3DMode(); + + //! sets the needed renderstates + void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel); + + //! Prevent setRenderStateMode calls to do anything. + // hack to allow drawing meshbuffers in 2D mode. + // Better solution would be passing this flag through meshbuffers, + // but the way this is currently implemented in Irrlicht makes this tricky to implement + void lockRenderStateMode() + { + LockRenderStateMode = true; + } + + //! Allow setRenderStateMode calls to work again + void unlockRenderStateMode() + { + LockRenderStateMode = false; + } + + void draw2D3DVertexPrimitiveList(const void* vertices, + u32 vertexCount, const void* indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, + E_INDEX_TYPE iType, bool is3D); + + void createMaterialRenderers(); + + void loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData); + + bool setMaterialTexture(irr::u32 layerIdx, const irr::video::ITexture* texture); + + //! Same as `CacheHandler->setViewport`, but also sets `ViewPort` + virtual void setViewPortRaw(u32 width, u32 height); + + void drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]); + void drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount); + void drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, const u16 *indices, int indexCount); + void drawElements(GLenum primitiveType, const VertexType &vertexType, uintptr_t vertices, uintptr_t indices, int indexCount); + + void beginDraw(const VertexType &vertexType, uintptr_t verticesBase); + void endDraw(const VertexType &vertexType); + + COpenGL3CacheHandler* CacheHandler; + core::stringw Name; + core::stringc VendorName; + SIrrlichtCreationParameters Params; + + //! bool to make all renderstates reset if set to true. + bool ResetRenderStates; + bool LockRenderStateMode; + u8 AntiAlias; + + struct SUserClipPlane + { + core::plane3df Plane; + bool Enabled; + }; + + core::array UserClipPlane; + + core::matrix4 TextureFlipMatrix; + +private: + + COpenGL3Renderer2D* MaterialRenderer2DActive; + COpenGL3Renderer2D* MaterialRenderer2DTexture; + COpenGL3Renderer2D* MaterialRenderer2DNoTexture; + + core::matrix4 Matrices[ETS_COUNT]; + + //! 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 Transformation3DChanged; + irr::io::path OGLES2ShaderPath; + + SMaterial Material, LastMaterial; + + //! Color buffer format + ECOLOR_FORMAT ColorFormat; + + IContextManager* ContextManager; + + std::vector QuadsIndices; + void initQuadsIndices(int max_vertex_count = 65536); + + void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); + static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); + }; + +} // end namespace video +} // end namespace irr diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index 055738b..b9cb75a 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -1,66 +1,66 @@ -// Copyright (C) 2015 Patryk Nadrowski -// Copyright (C) 2009-2010 Amundis -// 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 "ExtensionHandler.h" - -#include "irrString.h" -#include "SMaterial.h" -#include "fast_atof.h" -#include - -namespace irr -{ -namespace video -{ - void COpenGL3ExtensionHandler::initExtensions() - { - GLint major, minor; - glGetIntegerv(GL_MAJOR_VERSION, &major); - glGetIntegerv(GL_MINOR_VERSION, &minor); - Version = 100 * major + 10 * minor; - - GLint ext_count = 0; - GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); - for (int k = 0; k < ext_count; k++) { - auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k); - for (size_t j=0; j(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; - } - -} // end namespace video -} // end namespace irr +// Copyright (C) 2015 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// 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 "ExtensionHandler.h" + +#include "irrString.h" +#include "SMaterial.h" +#include "fast_atof.h" +#include + +namespace irr +{ +namespace video +{ + void COpenGL3ExtensionHandler::initExtensions() + { + GLint major, minor; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + Version = 100 * major + 10 * minor; + + GLint ext_count = 0; + GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); + for (int k = 0; k < ext_count; k++) { + auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k); + for (size_t j=0; j(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; + } + +} // end namespace video +} // end namespace irr diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index 1e6bd7f..6fb47b8 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -1,187 +1,187 @@ -// Copyright (C) 2023 Vitaliy Lobachevskiy -// Copyright (C) 2015 Patryk Nadrowski -// Copyright (C) 2009-2010 Amundis -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#pragma once - -#include "EDriverFeatures.h" -#include "irrTypes.h" -#include "os.h" - -#include "Common.h" - -#include "COGLESCoreExtensionHandler.h" - -namespace irr -{ -namespace video -{ - - class COpenGL3ExtensionHandler : public COGLESCoreExtensionHandler - { - public: - COpenGL3ExtensionHandler() : COGLESCoreExtensionHandler() {} - - 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_MIP_MAP_AUTO_UPDATE: - case EVDF_VERTEX_SHADER_1_1: - case EVDF_PIXEL_SHADER_1_1: - case EVDF_PIXEL_SHADER_1_2: - case EVDF_PIXEL_SHADER_2_0: - case EVDF_VERTEX_SHADER_2_0: - case EVDF_ARB_GLSL: - case EVDF_TEXTURE_NSQUARE: - case EVDF_TEXTURE_NPOT: - case EVDF_FRAMEBUFFER_OBJECT: - case EVDF_VERTEX_BUFFER_OBJECT: - case EVDF_COLOR_MASK: - case EVDF_ALPHA_TO_COVERAGE: - case EVDF_POLYGON_OFFSET: - case EVDF_BLEND_OPERATIONS: - case EVDF_BLEND_SEPARATE: - case EVDF_TEXTURE_MATRIX: - case EVDF_TEXTURE_CUBEMAP: - return true; - case EVDF_ARB_VERTEX_PROGRAM_1: - case EVDF_ARB_FRAGMENT_PROGRAM_1: - case EVDF_GEOMETRY_SHADER: - case EVDF_MULTIPLE_RENDER_TARGETS: - case EVDF_MRT_BLEND: - case EVDF_MRT_COLOR_MASK: - case EVDF_MRT_BLEND_FUNC: - case EVDF_OCCLUSION_QUERY: - return false; - case EVDF_TEXTURE_COMPRESSED_DXT: - return false; // NV Tegra need improvements here - case EVDF_TEXTURE_COMPRESSED_PVRTC: - return FeatureAvailable[IRR_GL_IMG_texture_compression_pvrtc]; - case EVDF_TEXTURE_COMPRESSED_PVRTC2: - return FeatureAvailable[IRR_GL_IMG_texture_compression_pvrtc2]; - case EVDF_TEXTURE_COMPRESSED_ETC1: - return FeatureAvailable[IRR_GL_OES_compressed_ETC1_RGB8_texture]; - case EVDF_TEXTURE_COMPRESSED_ETC2: - return false; - case EVDF_STENCIL_BUFFER: - return StencilBuffer; - default: - return false; - }; - } - - 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) - { - glUseProgram(prog); - } - - inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) - { - glBindFramebuffer(target, framebuffer); - } - - inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) - { - glDeleteFramebuffers(n, framebuffers); - } - - inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) - { - glGenFramebuffers(n, framebuffers); - } - - inline GLenum irrGlCheckFramebufferStatus(GLenum target) - { - return glCheckFramebufferStatus(target); - } - - inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) - { - glFramebufferTexture2D(target, attachment, textarget, texture, level); - } - - inline void irrGlGenerateMipmap(GLenum target) - { - glGenerateMipmap(target); - } - - inline void irrGlActiveStencilFace(GLenum face) - { - } - - inline void irrGlDrawBuffer(GLenum mode) - { - } - - inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) - { - } - - inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) - { - glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); - } - - inline void irrGlBlendEquation(GLenum mode) - { - glBlendEquation(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) - { - } - }; - -} -} +// Copyright (C) 2023 Vitaliy Lobachevskiy +// Copyright (C) 2015 Patryk Nadrowski +// Copyright (C) 2009-2010 Amundis +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "EDriverFeatures.h" +#include "irrTypes.h" +#include "os.h" + +#include "Common.h" + +#include "COGLESCoreExtensionHandler.h" + +namespace irr +{ +namespace video +{ + + class COpenGL3ExtensionHandler : public COGLESCoreExtensionHandler + { + public: + COpenGL3ExtensionHandler() : COGLESCoreExtensionHandler() {} + + 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_MIP_MAP_AUTO_UPDATE: + case EVDF_VERTEX_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_1: + case EVDF_PIXEL_SHADER_1_2: + case EVDF_PIXEL_SHADER_2_0: + case EVDF_VERTEX_SHADER_2_0: + case EVDF_ARB_GLSL: + case EVDF_TEXTURE_NSQUARE: + case EVDF_TEXTURE_NPOT: + case EVDF_FRAMEBUFFER_OBJECT: + case EVDF_VERTEX_BUFFER_OBJECT: + case EVDF_COLOR_MASK: + case EVDF_ALPHA_TO_COVERAGE: + case EVDF_POLYGON_OFFSET: + case EVDF_BLEND_OPERATIONS: + case EVDF_BLEND_SEPARATE: + case EVDF_TEXTURE_MATRIX: + case EVDF_TEXTURE_CUBEMAP: + return true; + case EVDF_ARB_VERTEX_PROGRAM_1: + case EVDF_ARB_FRAGMENT_PROGRAM_1: + case EVDF_GEOMETRY_SHADER: + case EVDF_MULTIPLE_RENDER_TARGETS: + case EVDF_MRT_BLEND: + case EVDF_MRT_COLOR_MASK: + case EVDF_MRT_BLEND_FUNC: + case EVDF_OCCLUSION_QUERY: + return false; + case EVDF_TEXTURE_COMPRESSED_DXT: + return false; // NV Tegra need improvements here + case EVDF_TEXTURE_COMPRESSED_PVRTC: + return FeatureAvailable[IRR_GL_IMG_texture_compression_pvrtc]; + case EVDF_TEXTURE_COMPRESSED_PVRTC2: + return FeatureAvailable[IRR_GL_IMG_texture_compression_pvrtc2]; + case EVDF_TEXTURE_COMPRESSED_ETC1: + return FeatureAvailable[IRR_GL_OES_compressed_ETC1_RGB8_texture]; + case EVDF_TEXTURE_COMPRESSED_ETC2: + return false; + case EVDF_STENCIL_BUFFER: + return StencilBuffer; + default: + return false; + }; + } + + 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) + { + glUseProgram(prog); + } + + inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) + { + glBindFramebuffer(target, framebuffer); + } + + inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) + { + glDeleteFramebuffers(n, framebuffers); + } + + inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) + { + glGenFramebuffers(n, framebuffers); + } + + inline GLenum irrGlCheckFramebufferStatus(GLenum target) + { + return glCheckFramebufferStatus(target); + } + + inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) + { + glFramebufferTexture2D(target, attachment, textarget, texture, level); + } + + inline void irrGlGenerateMipmap(GLenum target) + { + glGenerateMipmap(target); + } + + inline void irrGlActiveStencilFace(GLenum face) + { + } + + inline void irrGlDrawBuffer(GLenum mode) + { + } + + inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) + { + } + + inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) + { + glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + } + + inline void irrGlBlendEquation(GLenum mode) + { + glBlendEquation(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) + { + } + }; + +} +} diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp index bcf99ac..2922470 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp @@ -1,334 +1,334 @@ -// Copyright (C) 2014 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#include "FixedPipelineRenderer.h" - -#include "IVideoDriver.h" - -namespace irr -{ -namespace video -{ - -// Base callback - -COpenGL3MaterialBaseCB::COpenGL3MaterialBaseCB() : - FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1), GlobalAmbientID(-1), MaterialAmbientID(-1), MaterialDiffuseID(-1), MaterialEmissiveID(-1), MaterialSpecularID(-1), MaterialShininessID(-1), - FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1), - FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)), - MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f) -{ -} - -void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial& material) -{ - LightEnable = material.Lighting; - MaterialAmbient = SColorf(material.AmbientColor); - MaterialDiffuse = SColorf(material.DiffuseColor); - MaterialEmissive = SColorf(material.EmissiveColor); - MaterialSpecular = SColorf(material.SpecularColor); - MaterialShininess = material.Shininess; - - FogEnable = material.FogEnable ? 1 : 0; - - Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; -} - -void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdateBase) - { - WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix"); - WVMatrixID = services->getVertexShaderConstantID("uWVMatrix"); - NMatrixID = services->getVertexShaderConstantID("uNMatrix"); - GlobalAmbientID = services->getVertexShaderConstantID("uGlobalAmbient"); - MaterialAmbientID = services->getVertexShaderConstantID("uMaterialAmbient"); - MaterialDiffuseID = services->getVertexShaderConstantID("uMaterialDiffuse"); - MaterialEmissiveID = services->getVertexShaderConstantID("uMaterialEmissive"); - MaterialSpecularID = services->getVertexShaderConstantID("uMaterialSpecular"); - MaterialShininessID = services->getVertexShaderConstantID("uMaterialShininess"); - FogEnableID = services->getVertexShaderConstantID("uFogEnable"); - FogTypeID = services->getVertexShaderConstantID("uFogType"); - FogColorID = services->getVertexShaderConstantID("uFogColor"); - FogStartID = services->getVertexShaderConstantID("uFogStart"); - FogEndID = services->getVertexShaderConstantID("uFogEnd"); - FogDensityID = services->getVertexShaderConstantID("uFogDensity"); - ThicknessID = services->getVertexShaderConstantID("uThickness"); - - FirstUpdateBase = false; - } - - const core::matrix4 W = driver->getTransform(ETS_WORLD); - const core::matrix4 V = driver->getTransform(ETS_VIEW); - const core::matrix4 P = driver->getTransform(ETS_PROJECTION); - - core::matrix4 Matrix = P * V * W; - services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16); - - Matrix = V * W; - services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16); - - Matrix.makeInverse(); - services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16); - - services->setPixelShaderConstant(FogEnableID, &FogEnable, 1); - - if (FogEnable) - { - SColor TempColor(0); - E_FOG_TYPE TempType = EFT_FOG_LINEAR; - bool TempPerFragment = false; - bool TempRange = false; - - driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange); - - FogType = (s32)TempType; - FogColor = SColorf(TempColor); - - services->setPixelShaderConstant(FogTypeID, &FogType, 1); - services->setPixelShaderConstant(FogColorID, reinterpret_cast(&FogColor), 4); - services->setPixelShaderConstant(FogStartID, &FogStart, 1); - services->setPixelShaderConstant(FogEndID, &FogEnd, 1); - services->setPixelShaderConstant(FogDensityID, &FogDensity, 1); - } - - services->setPixelShaderConstant(ThicknessID, &Thickness, 1); -} - -// EMT_SOLID + EMT_TRANSPARENT_ADD_COLOR + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA - -COpenGL3MaterialSolidCB::COpenGL3MaterialSolidCB() : - FirstUpdate(true), TMatrix0ID(-1), AlphaRefID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), AlphaRef(0.5f), TextureUsage0(0), TextureUnit0(0) -{ -} - -void COpenGL3MaterialSolidCB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - AlphaRef = material.MaterialTypeParam; - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; -} - -void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - AlphaRefID = services->getVertexShaderConstantID("uAlphaRef"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(AlphaRefID, &AlphaRef, 1); - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); -} - -// EMT_SOLID_2_LAYER + EMT_DETAIL_MAP - -COpenGL3MaterialSolid2CB::COpenGL3MaterialSolid2CB() : - FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), - TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) -{ -} - -void COpenGL3MaterialSolid2CB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; - TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; -} - -void COpenGL3MaterialSolid2CB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); - services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); - services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); -} - -// EMT_LIGHTMAP + EMT_LIGHTMAP_ADD + EMT_LIGHTMAP_M2 + EMT_LIGHTMAP_M4 - -COpenGL3MaterialLightmapCB::COpenGL3MaterialLightmapCB(float modulate) : - FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), ModulateID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), - Modulate(modulate), TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) -{ -} - -void COpenGL3MaterialLightmapCB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; - TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; -} - -void COpenGL3MaterialLightmapCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); - ModulateID = services->getVertexShaderConstantID("uModulate"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); - services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(ModulateID, &Modulate, 1); - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); - services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); -} - -// EMT_SPHERE_MAP + EMT_REFLECTION_2_LAYER + EMT_TRANSPARENT_REFLECTION_2_LAYER - -COpenGL3MaterialReflectionCB::COpenGL3MaterialReflectionCB() : - FirstUpdate(true), TMatrix0ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), - TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) -{ -} - -void COpenGL3MaterialReflectionCB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; - TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; -} - -void COpenGL3MaterialReflectionCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); - services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); -} - -// EMT_ONETEXTURE_BLEND - -COpenGL3MaterialOneTextureBlendCB::COpenGL3MaterialOneTextureBlendCB() : - FirstUpdate(true), TMatrix0ID(-1), BlendTypeID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), BlendType(0), TextureUsage0(0), TextureUnit0(0) -{ -} - -void COpenGL3MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - BlendType = 0; - - E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact; - E_MODULATE_FUNC modulate; - u32 alphaSource; - unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); - - if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) - { - if (alphaSource == EAS_VERTEX_COLOR) - { - BlendType = 1; - } - else if (alphaSource == EAS_TEXTURE) - { - BlendType = 2; - } - } - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; -} - -void COpenGL3MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - BlendTypeID = services->getVertexShaderConstantID("uBlendType"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(BlendTypeID, &BlendType, 1); - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); -} - -} -} +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "FixedPipelineRenderer.h" + +#include "IVideoDriver.h" + +namespace irr +{ +namespace video +{ + +// Base callback + +COpenGL3MaterialBaseCB::COpenGL3MaterialBaseCB() : + FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-1), GlobalAmbientID(-1), MaterialAmbientID(-1), MaterialDiffuseID(-1), MaterialEmissiveID(-1), MaterialSpecularID(-1), MaterialShininessID(-1), + FogEnableID(-1), FogTypeID(-1), FogColorID(-1), FogStartID(-1), + FogEndID(-1), FogDensityID(-1), ThicknessID(-1), LightEnable(false), MaterialAmbient(SColorf(0.f, 0.f, 0.f)), MaterialDiffuse(SColorf(0.f, 0.f, 0.f)), MaterialEmissive(SColorf(0.f, 0.f, 0.f)), MaterialSpecular(SColorf(0.f, 0.f, 0.f)), + MaterialShininess(0.f), FogEnable(0), FogType(1), FogColor(SColorf(0.f, 0.f, 0.f, 1.f)), FogStart(0.f), FogEnd(0.f), FogDensity(0.f), Thickness(1.f) +{ +} + +void COpenGL3MaterialBaseCB::OnSetMaterial(const SMaterial& material) +{ + LightEnable = material.Lighting; + MaterialAmbient = SColorf(material.AmbientColor); + MaterialDiffuse = SColorf(material.DiffuseColor); + MaterialEmissive = SColorf(material.EmissiveColor); + MaterialSpecular = SColorf(material.SpecularColor); + MaterialShininess = material.Shininess; + + FogEnable = material.FogEnable ? 1 : 0; + + Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; +} + +void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdateBase) + { + WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix"); + WVMatrixID = services->getVertexShaderConstantID("uWVMatrix"); + NMatrixID = services->getVertexShaderConstantID("uNMatrix"); + GlobalAmbientID = services->getVertexShaderConstantID("uGlobalAmbient"); + MaterialAmbientID = services->getVertexShaderConstantID("uMaterialAmbient"); + MaterialDiffuseID = services->getVertexShaderConstantID("uMaterialDiffuse"); + MaterialEmissiveID = services->getVertexShaderConstantID("uMaterialEmissive"); + MaterialSpecularID = services->getVertexShaderConstantID("uMaterialSpecular"); + MaterialShininessID = services->getVertexShaderConstantID("uMaterialShininess"); + FogEnableID = services->getVertexShaderConstantID("uFogEnable"); + FogTypeID = services->getVertexShaderConstantID("uFogType"); + FogColorID = services->getVertexShaderConstantID("uFogColor"); + FogStartID = services->getVertexShaderConstantID("uFogStart"); + FogEndID = services->getVertexShaderConstantID("uFogEnd"); + FogDensityID = services->getVertexShaderConstantID("uFogDensity"); + ThicknessID = services->getVertexShaderConstantID("uThickness"); + + FirstUpdateBase = false; + } + + const core::matrix4 W = driver->getTransform(ETS_WORLD); + const core::matrix4 V = driver->getTransform(ETS_VIEW); + const core::matrix4 P = driver->getTransform(ETS_PROJECTION); + + core::matrix4 Matrix = P * V * W; + services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16); + + Matrix = V * W; + services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16); + + Matrix.makeInverse(); + services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16); + + services->setPixelShaderConstant(FogEnableID, &FogEnable, 1); + + if (FogEnable) + { + SColor TempColor(0); + E_FOG_TYPE TempType = EFT_FOG_LINEAR; + bool TempPerFragment = false; + bool TempRange = false; + + driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange); + + FogType = (s32)TempType; + FogColor = SColorf(TempColor); + + services->setPixelShaderConstant(FogTypeID, &FogType, 1); + services->setPixelShaderConstant(FogColorID, reinterpret_cast(&FogColor), 4); + services->setPixelShaderConstant(FogStartID, &FogStart, 1); + services->setPixelShaderConstant(FogEndID, &FogEnd, 1); + services->setPixelShaderConstant(FogDensityID, &FogDensity, 1); + } + + services->setPixelShaderConstant(ThicknessID, &Thickness, 1); +} + +// EMT_SOLID + EMT_TRANSPARENT_ADD_COLOR + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA + +COpenGL3MaterialSolidCB::COpenGL3MaterialSolidCB() : + FirstUpdate(true), TMatrix0ID(-1), AlphaRefID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), AlphaRef(0.5f), TextureUsage0(0), TextureUnit0(0) +{ +} + +void COpenGL3MaterialSolidCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + AlphaRef = material.MaterialTypeParam; + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; +} + +void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + AlphaRefID = services->getVertexShaderConstantID("uAlphaRef"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(AlphaRefID, &AlphaRef, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); +} + +// EMT_SOLID_2_LAYER + EMT_DETAIL_MAP + +COpenGL3MaterialSolid2CB::COpenGL3MaterialSolid2CB() : + FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), + TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) +{ +} + +void COpenGL3MaterialSolid2CB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; + TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; +} + +void COpenGL3MaterialSolid2CB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); + services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); + services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); +} + +// EMT_LIGHTMAP + EMT_LIGHTMAP_ADD + EMT_LIGHTMAP_M2 + EMT_LIGHTMAP_M4 + +COpenGL3MaterialLightmapCB::COpenGL3MaterialLightmapCB(float modulate) : + FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), ModulateID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), + Modulate(modulate), TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) +{ +} + +void COpenGL3MaterialLightmapCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; + TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; +} + +void COpenGL3MaterialLightmapCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); + ModulateID = services->getVertexShaderConstantID("uModulate"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); + services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(ModulateID, &Modulate, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); + services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); +} + +// EMT_SPHERE_MAP + EMT_REFLECTION_2_LAYER + EMT_TRANSPARENT_REFLECTION_2_LAYER + +COpenGL3MaterialReflectionCB::COpenGL3MaterialReflectionCB() : + FirstUpdate(true), TMatrix0ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), + TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) +{ +} + +void COpenGL3MaterialReflectionCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; + TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; +} + +void COpenGL3MaterialReflectionCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); + services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); +} + +// EMT_ONETEXTURE_BLEND + +COpenGL3MaterialOneTextureBlendCB::COpenGL3MaterialOneTextureBlendCB() : + FirstUpdate(true), TMatrix0ID(-1), BlendTypeID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), BlendType(0), TextureUsage0(0), TextureUnit0(0) +{ +} + +void COpenGL3MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial& material) +{ + COpenGL3MaterialBaseCB::OnSetMaterial(material); + + BlendType = 0; + + E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact)) + { + if (alphaSource == EAS_VERTEX_COLOR) + { + BlendType = 1; + } + else if (alphaSource == EAS_TEXTURE) + { + BlendType = 2; + } + } + + TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; +} + +void COpenGL3MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) +{ + COpenGL3MaterialBaseCB::OnSetConstants(services, userData); + + IVideoDriver* driver = services->getVideoDriver(); + + if (FirstUpdate) + { + TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); + BlendTypeID = services->getVertexShaderConstantID("uBlendType"); + TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); + TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); + + FirstUpdate = false; + } + + core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); + services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); + + services->setPixelShaderConstant(BlendTypeID, &BlendType, 1); + services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); + services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); +} + +} +} diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h index 4a9bb95..aea935f 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h @@ -1,180 +1,180 @@ -// Copyright (C) 2014 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#pragma once - -#include "IShaderConstantSetCallBack.h" -#include "IMaterialRendererServices.h" - -namespace irr -{ -namespace video -{ - -class COpenGL3MaterialBaseCB : public IShaderConstantSetCallBack -{ -public: - COpenGL3MaterialBaseCB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdateBase; - - s32 WVPMatrixID; - s32 WVMatrixID; - s32 NMatrixID; - - s32 GlobalAmbientID; - s32 MaterialAmbientID; - s32 MaterialDiffuseID; - s32 MaterialEmissiveID; - s32 MaterialSpecularID; - s32 MaterialShininessID; - - s32 FogEnableID; - s32 FogTypeID; - s32 FogColorID; - s32 FogStartID; - s32 FogEndID; - s32 FogDensityID; - - s32 ThicknessID; - - bool LightEnable; - SColorf GlobalAmbient; - SColorf MaterialAmbient; - SColorf MaterialDiffuse; - SColorf MaterialEmissive; - SColorf MaterialSpecular; - f32 MaterialShininess; - - s32 FogEnable; - s32 FogType; - SColorf FogColor; - f32 FogStart; - f32 FogEnd; - f32 FogDensity; - - f32 Thickness; -}; - -class COpenGL3MaterialSolidCB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialSolidCB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 AlphaRefID; - s32 TextureUsage0ID; - s32 TextureUnit0ID; - - f32 AlphaRef; - s32 TextureUsage0; - s32 TextureUnit0; -}; - -class COpenGL3MaterialSolid2CB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialSolid2CB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 TMatrix1ID; - s32 TextureUsage0ID; - s32 TextureUsage1ID; - s32 TextureUnit0ID; - s32 TextureUnit1ID; - - s32 TextureUsage0; - s32 TextureUsage1; - s32 TextureUnit0; - s32 TextureUnit1; -}; - -class COpenGL3MaterialLightmapCB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialLightmapCB(float modulate); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 TMatrix1ID; - s32 ModulateID; - s32 TextureUsage0ID; - s32 TextureUsage1ID; - s32 TextureUnit0ID; - s32 TextureUnit1ID; - - f32 Modulate; - s32 TextureUsage0; - s32 TextureUsage1; - s32 TextureUnit0; - s32 TextureUnit1; -}; - -class COpenGL3MaterialReflectionCB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialReflectionCB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 TextureUsage0ID; - s32 TextureUsage1ID; - s32 TextureUnit0ID; - s32 TextureUnit1ID; - - s32 TextureUsage0; - s32 TextureUsage1; - s32 TextureUnit0; - s32 TextureUnit1; -}; - -class COpenGL3MaterialOneTextureBlendCB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialOneTextureBlendCB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 BlendTypeID; - s32 TextureUsage0ID; - s32 TextureUnit0ID; - - s32 BlendType; - s32 TextureUsage0; - s32 TextureUnit0; -}; - -} -} +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "IShaderConstantSetCallBack.h" +#include "IMaterialRendererServices.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3MaterialBaseCB : public IShaderConstantSetCallBack +{ +public: + COpenGL3MaterialBaseCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdateBase; + + s32 WVPMatrixID; + s32 WVMatrixID; + s32 NMatrixID; + + s32 GlobalAmbientID; + s32 MaterialAmbientID; + s32 MaterialDiffuseID; + s32 MaterialEmissiveID; + s32 MaterialSpecularID; + s32 MaterialShininessID; + + s32 FogEnableID; + s32 FogTypeID; + s32 FogColorID; + s32 FogStartID; + s32 FogEndID; + s32 FogDensityID; + + s32 ThicknessID; + + bool LightEnable; + SColorf GlobalAmbient; + SColorf MaterialAmbient; + SColorf MaterialDiffuse; + SColorf MaterialEmissive; + SColorf MaterialSpecular; + f32 MaterialShininess; + + s32 FogEnable; + s32 FogType; + SColorf FogColor; + f32 FogStart; + f32 FogEnd; + f32 FogDensity; + + f32 Thickness; +}; + +class COpenGL3MaterialSolidCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialSolidCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 AlphaRefID; + s32 TextureUsage0ID; + s32 TextureUnit0ID; + + f32 AlphaRef; + s32 TextureUsage0; + s32 TextureUnit0; +}; + +class COpenGL3MaterialSolid2CB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialSolid2CB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 TMatrix1ID; + s32 TextureUsage0ID; + s32 TextureUsage1ID; + s32 TextureUnit0ID; + s32 TextureUnit1ID; + + s32 TextureUsage0; + s32 TextureUsage1; + s32 TextureUnit0; + s32 TextureUnit1; +}; + +class COpenGL3MaterialLightmapCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialLightmapCB(float modulate); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 TMatrix1ID; + s32 ModulateID; + s32 TextureUsage0ID; + s32 TextureUsage1ID; + s32 TextureUnit0ID; + s32 TextureUnit1ID; + + f32 Modulate; + s32 TextureUsage0; + s32 TextureUsage1; + s32 TextureUnit0; + s32 TextureUnit1; +}; + +class COpenGL3MaterialReflectionCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialReflectionCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 TextureUsage0ID; + s32 TextureUsage1ID; + s32 TextureUnit0ID; + s32 TextureUnit1ID; + + s32 TextureUsage0; + s32 TextureUsage1; + s32 TextureUnit0; + s32 TextureUnit1; +}; + +class COpenGL3MaterialOneTextureBlendCB : public COpenGL3MaterialBaseCB +{ +public: + COpenGL3MaterialOneTextureBlendCB(); + + virtual void OnSetMaterial(const SMaterial& material); + virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); + +protected: + bool FirstUpdate; + + s32 TMatrix0ID; + s32 BlendTypeID; + s32 TextureUsage0ID; + s32 TextureUnit0ID; + + s32 BlendType; + s32 TextureUsage0; + s32 TextureUnit0; +}; + +} +} diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.cpp b/source/Irrlicht/OpenGL/MaterialRenderer.cpp index 20d684c..d7aa483 100644 --- a/source/Irrlicht/OpenGL/MaterialRenderer.cpp +++ b/source/Irrlicht/OpenGL/MaterialRenderer.cpp @@ -1,481 +1,481 @@ -// Copyright (C) 2014 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "MaterialRenderer.h" - -#include "EVertexAttributes.h" -#include "IGPUProgrammingServices.h" -#include "IShaderConstantSetCallBack.h" -#include "IVideoDriver.h" -#include "os.h" - -#include "Driver.h" - -#include "COpenGLCoreTexture.h" -#include "COpenGLCoreCacheHandler.h" - -namespace irr -{ -namespace video -{ - - -COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, - s32& outMaterialTypeNr, - const c8* vertexShaderProgram, - const c8* pixelShaderProgram, - IShaderConstantSetCallBack* callback, - E_MATERIAL_TYPE baseMaterial, - s32 userData) - : Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) -{ -#ifdef _DEBUG - setDebugName("MaterialRenderer"); -#endif - - switch (baseMaterial) - { - case EMT_TRANSPARENT_VERTEX_ALPHA: - case EMT_TRANSPARENT_ALPHA_CHANNEL: - Alpha = true; - break; - case EMT_TRANSPARENT_ADD_COLOR: - FixedBlending = true; - break; - case EMT_ONETEXTURE_BLEND: - Blending = true; - break; - default: - break; - } - - if (CallBack) - CallBack->grab(); - - init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram); -} - - -COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, - IShaderConstantSetCallBack* callback, - E_MATERIAL_TYPE baseMaterial, s32 userData) -: Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) -{ - switch (baseMaterial) - { - case EMT_TRANSPARENT_VERTEX_ALPHA: - case EMT_TRANSPARENT_ALPHA_CHANNEL: - Alpha = true; - break; - case EMT_TRANSPARENT_ADD_COLOR: - FixedBlending = true; - break; - case EMT_ONETEXTURE_BLEND: - Blending = true; - break; - default: - break; - } - - if (CallBack) - CallBack->grab(); -} - - -COpenGL3MaterialRenderer::~COpenGL3MaterialRenderer() -{ - if (CallBack) - CallBack->drop(); - - if (Program) - { - GLuint shaders[8]; - GLint count; - glGetAttachedShaders(Program, 8, &count, shaders); - - count=core::min_(count,8); - for (GLint i=0; iaddMaterialRenderer(this); -} - - -bool COpenGL3MaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) -{ - if (CallBack && Program) - CallBack->OnSetConstants(this, UserData); - - return true; -} - - -void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial& material, - const video::SMaterial& lastMaterial, - bool resetAllRenderstates, - video::IMaterialRendererServices* services) -{ - COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler(); - - cacheHandler->setProgram(Program); - - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); - - if (Alpha) - { - cacheHandler->setBlend(true); - cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - else if (FixedBlending) - { - cacheHandler->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); - cacheHandler->setBlend(true); - } - else if (Blending) - { - E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact; - E_MODULATE_FUNC modulate; - u32 alphaSource; - unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); - - cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), - Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); - - cacheHandler->setBlend(true); - } - - if (CallBack) - CallBack->OnSetMaterial(material); -} - - -void COpenGL3MaterialRenderer::OnUnsetMaterial() -{ -} - - -bool COpenGL3MaterialRenderer::isTransparent() const -{ - return (Alpha || Blending || FixedBlending); -} - - -s32 COpenGL3MaterialRenderer::getRenderCapability() const -{ - return 0; -} - - -bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shader) -{ - if (Program) - { - GLuint shaderHandle = glCreateShader(shaderType); - glShaderSource(shaderHandle, 1, &shader, NULL); - glCompileShader(shaderHandle); - - GLint status = 0; - - glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status); - - if (status != GL_TRUE) - { - os::Printer::log("GLSL shader failed to compile", ELL_ERROR); - - GLint maxLength=0; - GLint length; - - glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, - &maxLength); - - if (maxLength) - { - GLchar *infoLog = new GLchar[maxLength]; - glGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); - os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); - delete [] infoLog; - } - - return false; - } - - glAttachShader(Program, shaderHandle); - } - - return true; -} - - -bool COpenGL3MaterialRenderer::linkProgram() -{ - if (Program) - { - glLinkProgram(Program); - - GLint status = 0; - - glGetProgramiv(Program, GL_LINK_STATUS, &status); - - if (!status) - { - os::Printer::log("GLSL shader program failed to link", ELL_ERROR); - - GLint maxLength=0; - GLsizei length; - - glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength); - - if (maxLength) - { - GLchar *infoLog = new GLchar[maxLength]; - glGetProgramInfoLog(Program, maxLength, &length, infoLog); - os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); - delete [] infoLog; - } - - return false; - } - - GLint num = 0; - - glGetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num); - - if (num == 0) - return true; - - GLint maxlen = 0; - - glGetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); - - if (maxlen == 0) - { - os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR); - return false; - } - - // seems that some implementations use an extra null terminator. - ++maxlen; - c8 *buf = new c8[maxlen]; - - UniformInfo.clear(); - UniformInfo.reallocate(num); - - for (GLint i=0; i < num; ++i) - { - SUniformInfo ui; - memset(buf, 0, maxlen); - - GLint size; - glGetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); - - core::stringc name = ""; - - // array support, workaround for some bugged drivers. - for (s32 i = 0; i < maxlen; ++i) - { - if (buf[i] == '[' || buf[i] == '\0') - break; - - name += buf[i]; - } - - ui.name = name; - ui.location = glGetUniformLocation(Program, buf); - - UniformInfo.push_back(ui); - } - - delete [] buf; - } - - return true; -} - - -void COpenGL3MaterialRenderer::setBasicRenderStates(const SMaterial& material, - const SMaterial& lastMaterial, - bool resetAllRenderstates) -{ - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); -} - -s32 COpenGL3MaterialRenderer::getVertexShaderConstantID(const c8* name) -{ - return getPixelShaderConstantID(name); -} - -s32 COpenGL3MaterialRenderer::getPixelShaderConstantID(const c8* name) -{ - for (u32 i = 0; i < UniformInfo.size(); ++i) - { - if (UniformInfo[i].name == name) - return i; - } - - return -1; -} - -void COpenGL3MaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) -{ - os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING); -} - -void COpenGL3MaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) -{ - os::Printer::log("Cannot set constant, use high level shader call.", ELL_WARNING); -} - -bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count) -{ - return setPixelShaderConstant(index, floats, count); -} - -bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count) -{ - return setPixelShaderConstant(index, ints, count); -} - -bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const u32* ints, int count) -{ - return setPixelShaderConstant(index, ints, count); -} - -bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count) -{ - if(index < 0 || UniformInfo[index].location < 0) - return false; - - bool status = true; - - switch (UniformInfo[index].type) - { - case GL_FLOAT: - glUniform1fv(UniformInfo[index].location, count, floats); - break; - case GL_FLOAT_VEC2: - glUniform2fv(UniformInfo[index].location, count/2, floats); - break; - case GL_FLOAT_VEC3: - glUniform3fv(UniformInfo[index].location, count/3, floats); - break; - case GL_FLOAT_VEC4: - glUniform4fv(UniformInfo[index].location, count/4, floats); - break; - case GL_FLOAT_MAT2: - glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats); - break; - case GL_FLOAT_MAT3: - glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats); - break; - case GL_FLOAT_MAT4: - glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats); - break; - case GL_SAMPLER_2D: - case GL_SAMPLER_CUBE: - { - if(floats) - { - const GLint id = (GLint)(*floats); - glUniform1iv(UniformInfo[index].location, 1, &id); - } - else - status = false; - } - break; - default: - status = false; - break; - } - - return status; -} - -bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count) -{ - if(index < 0 || UniformInfo[index].location < 0) - return false; - - bool status = true; - - switch (UniformInfo[index].type) - { - case GL_INT: - case GL_BOOL: - glUniform1iv(UniformInfo[index].location, count, ints); - break; - case GL_INT_VEC2: - case GL_BOOL_VEC2: - glUniform2iv(UniformInfo[index].location, count/2, ints); - break; - case GL_INT_VEC3: - case GL_BOOL_VEC3: - glUniform3iv(UniformInfo[index].location, count/3, ints); - break; - case GL_INT_VEC4: - case GL_BOOL_VEC4: - glUniform4iv(UniformInfo[index].location, count/4, ints); - break; - case GL_SAMPLER_2D: - case GL_SAMPLER_CUBE: - glUniform1iv(UniformInfo[index].location, 1, ints); - break; - default: - status = false; - break; - } - - return status; -} - -bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const u32* ints, int count) -{ - os::Printer::log("Unsigned int support needs at least GLES 3.0", ELL_WARNING); - return false; -} - -IVideoDriver* COpenGL3MaterialRenderer::getVideoDriver() -{ - return Driver; -} - -} -} +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "MaterialRenderer.h" + +#include "EVertexAttributes.h" +#include "IGPUProgrammingServices.h" +#include "IShaderConstantSetCallBack.h" +#include "IVideoDriver.h" +#include "os.h" + +#include "Driver.h" + +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + + +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, + s32& outMaterialTypeNr, + const c8* vertexShaderProgram, + const c8* pixelShaderProgram, + IShaderConstantSetCallBack* callback, + E_MATERIAL_TYPE baseMaterial, + s32 userData) + : Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) +{ +#ifdef _DEBUG + setDebugName("MaterialRenderer"); +#endif + + switch (baseMaterial) + { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_TRANSPARENT_ADD_COLOR: + FixedBlending = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); + + init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram); +} + + +COpenGL3MaterialRenderer::COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, + IShaderConstantSetCallBack* callback, + E_MATERIAL_TYPE baseMaterial, s32 userData) +: Driver(driver), CallBack(callback), Alpha(false), Blending(false), FixedBlending(false), Program(0), UserData(userData) +{ + switch (baseMaterial) + { + case EMT_TRANSPARENT_VERTEX_ALPHA: + case EMT_TRANSPARENT_ALPHA_CHANNEL: + Alpha = true; + break; + case EMT_TRANSPARENT_ADD_COLOR: + FixedBlending = true; + break; + case EMT_ONETEXTURE_BLEND: + Blending = true; + break; + default: + break; + } + + if (CallBack) + CallBack->grab(); +} + + +COpenGL3MaterialRenderer::~COpenGL3MaterialRenderer() +{ + if (CallBack) + CallBack->drop(); + + if (Program) + { + GLuint shaders[8]; + GLint count; + glGetAttachedShaders(Program, 8, &count, shaders); + + count=core::min_(count,8); + for (GLint i=0; iaddMaterialRenderer(this); +} + + +bool COpenGL3MaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) +{ + if (CallBack && Program) + CallBack->OnSetConstants(this, UserData); + + return true; +} + + +void COpenGL3MaterialRenderer::OnSetMaterial(const video::SMaterial& material, + const video::SMaterial& lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices* services) +{ + COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler(); + + cacheHandler->setProgram(Program); + + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + if (Alpha) + { + cacheHandler->setBlend(true); + cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + else if (FixedBlending) + { + cacheHandler->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); + cacheHandler->setBlend(true); + } + else if (Blending) + { + E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam); + + cacheHandler->setBlendFuncSeparate(Driver->getGLBlend(srcRGBFact), Driver->getGLBlend(dstRGBFact), + Driver->getGLBlend(srcAlphaFact), Driver->getGLBlend(dstAlphaFact)); + + cacheHandler->setBlend(true); + } + + if (CallBack) + CallBack->OnSetMaterial(material); +} + + +void COpenGL3MaterialRenderer::OnUnsetMaterial() +{ +} + + +bool COpenGL3MaterialRenderer::isTransparent() const +{ + return (Alpha || Blending || FixedBlending); +} + + +s32 COpenGL3MaterialRenderer::getRenderCapability() const +{ + return 0; +} + + +bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shader) +{ + if (Program) + { + GLuint shaderHandle = glCreateShader(shaderType); + glShaderSource(shaderHandle, 1, &shader, NULL); + glCompileShader(shaderHandle); + + GLint status = 0; + + glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status); + + if (status != GL_TRUE) + { + os::Printer::log("GLSL shader failed to compile", ELL_ERROR); + + GLint maxLength=0; + GLint length; + + glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, + &maxLength); + + if (maxLength) + { + GLchar *infoLog = new GLchar[maxLength]; + glGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete [] infoLog; + } + + return false; + } + + glAttachShader(Program, shaderHandle); + } + + return true; +} + + +bool COpenGL3MaterialRenderer::linkProgram() +{ + if (Program) + { + glLinkProgram(Program); + + GLint status = 0; + + glGetProgramiv(Program, GL_LINK_STATUS, &status); + + if (!status) + { + os::Printer::log("GLSL shader program failed to link", ELL_ERROR); + + GLint maxLength=0; + GLsizei length; + + glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength); + + if (maxLength) + { + GLchar *infoLog = new GLchar[maxLength]; + glGetProgramInfoLog(Program, maxLength, &length, infoLog); + os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); + delete [] infoLog; + } + + return false; + } + + GLint num = 0; + + glGetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num); + + if (num == 0) + return true; + + GLint maxlen = 0; + + glGetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); + + if (maxlen == 0) + { + os::Printer::log("GLSL: failed to retrieve uniform information", ELL_ERROR); + return false; + } + + // seems that some implementations use an extra null terminator. + ++maxlen; + c8 *buf = new c8[maxlen]; + + UniformInfo.clear(); + UniformInfo.reallocate(num); + + for (GLint i=0; i < num; ++i) + { + SUniformInfo ui; + memset(buf, 0, maxlen); + + GLint size; + glGetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); + + core::stringc name = ""; + + // array support, workaround for some bugged drivers. + for (s32 i = 0; i < maxlen; ++i) + { + if (buf[i] == '[' || buf[i] == '\0') + break; + + name += buf[i]; + } + + ui.name = name; + ui.location = glGetUniformLocation(Program, buf); + + UniformInfo.push_back(ui); + } + + delete [] buf; + } + + return true; +} + + +void COpenGL3MaterialRenderer::setBasicRenderStates(const SMaterial& material, + const SMaterial& lastMaterial, + bool resetAllRenderstates) +{ + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); +} + +s32 COpenGL3MaterialRenderer::getVertexShaderConstantID(const c8* name) +{ + return getPixelShaderConstantID(name); +} + +s32 COpenGL3MaterialRenderer::getPixelShaderConstantID(const c8* name) +{ + for (u32 i = 0; i < UniformInfo.size(); ++i) + { + if (UniformInfo[i].name == name) + return i; + } + + return -1; +} + +void COpenGL3MaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) +{ + os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING); +} + +void COpenGL3MaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) +{ + os::Printer::log("Cannot set constant, use high level shader call.", ELL_WARNING); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count) +{ + return setPixelShaderConstant(index, floats, count); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGL3MaterialRenderer::setVertexShaderConstant(s32 index, const u32* ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count) +{ + if(index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) + { + case GL_FLOAT: + glUniform1fv(UniformInfo[index].location, count, floats); + break; + case GL_FLOAT_VEC2: + glUniform2fv(UniformInfo[index].location, count/2, floats); + break; + case GL_FLOAT_VEC3: + glUniform3fv(UniformInfo[index].location, count/3, floats); + break; + case GL_FLOAT_VEC4: + glUniform4fv(UniformInfo[index].location, count/4, floats); + break; + case GL_FLOAT_MAT2: + glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats); + break; + case GL_FLOAT_MAT3: + glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats); + break; + case GL_FLOAT_MAT4: + glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + { + if(floats) + { + const GLint id = (GLint)(*floats); + glUniform1iv(UniformInfo[index].location, 1, &id); + } + else + status = false; + } + break; + default: + status = false; + break; + } + + return status; +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count) +{ + if(index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) + { + case GL_INT: + case GL_BOOL: + glUniform1iv(UniformInfo[index].location, count, ints); + break; + case GL_INT_VEC2: + case GL_BOOL_VEC2: + glUniform2iv(UniformInfo[index].location, count/2, ints); + break; + case GL_INT_VEC3: + case GL_BOOL_VEC3: + glUniform3iv(UniformInfo[index].location, count/3, ints); + break; + case GL_INT_VEC4: + case GL_BOOL_VEC4: + glUniform4iv(UniformInfo[index].location, count/4, ints); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + glUniform1iv(UniformInfo[index].location, 1, ints); + break; + default: + status = false; + break; + } + + return status; +} + +bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const u32* ints, int count) +{ + os::Printer::log("Unsigned int support needs at least GLES 3.0", ELL_WARNING); + return false; +} + +IVideoDriver* COpenGL3MaterialRenderer::getVideoDriver() +{ + return Driver; +} + +} +} diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.h b/source/Irrlicht/OpenGL/MaterialRenderer.h index dbac6cf..f9282cc 100644 --- a/source/Irrlicht/OpenGL/MaterialRenderer.h +++ b/source/Irrlicht/OpenGL/MaterialRenderer.h @@ -1,99 +1,99 @@ -// Copyright (C) 2014 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#pragma once - -#include "EMaterialTypes.h" -#include "IMaterialRenderer.h" -#include "IMaterialRendererServices.h" -#include "IGPUProgrammingServices.h" -#include "irrArray.h" -#include "irrString.h" - -#include "Common.h" - -namespace irr -{ -namespace video -{ - -class COpenGL3DriverBase; - -class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices -{ -public: - - COpenGL3MaterialRenderer( - COpenGL3DriverBase* driver, - s32& outMaterialTypeNr, - const c8* vertexShaderProgram = 0, - const c8* pixelShaderProgram = 0, - IShaderConstantSetCallBack* callback = 0, - E_MATERIAL_TYPE baseMaterial = EMT_SOLID, - s32 userData = 0); - - virtual ~COpenGL3MaterialRenderer(); - - GLuint getProgram() const; - - virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, - bool resetAllRenderstates, IMaterialRendererServices* services); - - virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype); - - virtual void OnUnsetMaterial(); - - virtual bool isTransparent() const; - - virtual s32 getRenderCapability() const; - - void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) override; - - s32 getVertexShaderConstantID(const c8* name) override; - s32 getPixelShaderConstantID(const c8* name) override; - void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override; - void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override; - bool setVertexShaderConstant(s32 index, const f32* floats, int count) override; - bool setVertexShaderConstant(s32 index, const s32* ints, int count) override; - bool setVertexShaderConstant(s32 index, const u32* ints, int count) override; - bool setPixelShaderConstant(s32 index, const f32* floats, int count) override; - bool setPixelShaderConstant(s32 index, const s32* ints, int count) override; - bool setPixelShaderConstant(s32 index, const u32* ints, int count) override; - - IVideoDriver* getVideoDriver() override; - -protected: - - COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, - IShaderConstantSetCallBack* callback = 0, - E_MATERIAL_TYPE baseMaterial = EMT_SOLID, - s32 userData = 0); - - void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true); - - bool createShader(GLenum shaderType, const char* shader); - bool linkProgram(); - - COpenGL3DriverBase* Driver; - IShaderConstantSetCallBack* CallBack; - - bool Alpha; - bool Blending; - bool FixedBlending; - - struct SUniformInfo - { - core::stringc name; - GLenum type; - GLint location; - }; - - GLuint Program; - core::array UniformInfo; - s32 UserData; -}; - - -} -} +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#pragma once + +#include "EMaterialTypes.h" +#include "IMaterialRenderer.h" +#include "IMaterialRendererServices.h" +#include "IGPUProgrammingServices.h" +#include "irrArray.h" +#include "irrString.h" + +#include "Common.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3DriverBase; + +class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices +{ +public: + + COpenGL3MaterialRenderer( + COpenGL3DriverBase* driver, + s32& outMaterialTypeNr, + const c8* vertexShaderProgram = 0, + const c8* pixelShaderProgram = 0, + IShaderConstantSetCallBack* callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + virtual ~COpenGL3MaterialRenderer(); + + GLuint getProgram() const; + + virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices* services); + + virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype); + + virtual void OnUnsetMaterial(); + + virtual bool isTransparent() const; + + virtual s32 getRenderCapability() const; + + void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) override; + + s32 getVertexShaderConstantID(const c8* name) override; + s32 getPixelShaderConstantID(const c8* name) override; + void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override; + void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override; + bool setVertexShaderConstant(s32 index, const f32* floats, int count) override; + bool setVertexShaderConstant(s32 index, const s32* ints, int count) override; + bool setVertexShaderConstant(s32 index, const u32* ints, int count) override; + bool setPixelShaderConstant(s32 index, const f32* floats, int count) override; + bool setPixelShaderConstant(s32 index, const s32* ints, int count) override; + bool setPixelShaderConstant(s32 index, const u32* ints, int count) override; + + IVideoDriver* getVideoDriver() override; + +protected: + + COpenGL3MaterialRenderer(COpenGL3DriverBase* driver, + IShaderConstantSetCallBack* callback = 0, + E_MATERIAL_TYPE baseMaterial = EMT_SOLID, + s32 userData = 0); + + void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true); + + bool createShader(GLenum shaderType, const char* shader); + bool linkProgram(); + + COpenGL3DriverBase* Driver; + IShaderConstantSetCallBack* CallBack; + + bool Alpha; + bool Blending; + bool FixedBlending; + + struct SUniformInfo + { + core::stringc name; + GLenum type; + GLint location; + }; + + GLuint Program; + core::array UniformInfo; + s32 UserData; +}; + + +} +} diff --git a/source/Irrlicht/OpenGL/Renderer2D.cpp b/source/Irrlicht/OpenGL/Renderer2D.cpp index 8bedb17..96bdbda 100644 --- a/source/Irrlicht/OpenGL/Renderer2D.cpp +++ b/source/Irrlicht/OpenGL/Renderer2D.cpp @@ -1,83 +1,83 @@ -// Copyright (C) 2014 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#include "Renderer2D.h" - -#include "IGPUProgrammingServices.h" -#include "os.h" - -#include "Driver.h" - -#include "COpenGLCoreFeature.h" -#include "COpenGLCoreTexture.h" -#include "COpenGLCoreCacheHandler.h" - -namespace irr -{ -namespace video -{ - -COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture) : - COpenGL3MaterialRenderer(driver, 0, EMT_SOLID), - WithTexture(withTexture) -{ -#ifdef _DEBUG - setDebugName("Renderer2D"); -#endif - - int Temp = 0; - - init(Temp, vertexShaderProgram, pixelShaderProgram, false); - - COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler(); - - cacheHandler->setProgram(Program); - - // These states don't change later. - - ThicknessID = getPixelShaderConstantID("uThickness"); - if ( WithTexture ) - { - TextureUsageID = getPixelShaderConstantID("uTextureUsage"); - s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit"); - - s32 TextureUnit = 0; - setPixelShaderConstant(TextureUnitID, &TextureUnit, 1); - - s32 TextureUsage = 0; - setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); - } - - cacheHandler->setProgram(0); -} - -COpenGL3Renderer2D::~COpenGL3Renderer2D() -{ -} - -void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial& material, - const video::SMaterial& lastMaterial, - bool resetAllRenderstates, - video::IMaterialRendererServices* services) -{ - Driver->getCacheHandler()->setProgram(Program); - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); - - f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; - setPixelShaderConstant(ThicknessID, &Thickness, 1); - - if ( WithTexture ) - { - s32 TextureUsage = material.TextureLayer[0].Texture ? 1 : 0; - setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); - } -} - -bool COpenGL3Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) -{ - return true; -} - -} -} +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "Renderer2D.h" + +#include "IGPUProgrammingServices.h" +#include "os.h" + +#include "Driver.h" + +#include "COpenGLCoreFeature.h" +#include "COpenGLCoreTexture.h" +#include "COpenGLCoreCacheHandler.h" + +namespace irr +{ +namespace video +{ + +COpenGL3Renderer2D::COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture) : + COpenGL3MaterialRenderer(driver, 0, EMT_SOLID), + WithTexture(withTexture) +{ +#ifdef _DEBUG + setDebugName("Renderer2D"); +#endif + + int Temp = 0; + + init(Temp, vertexShaderProgram, pixelShaderProgram, false); + + COpenGL3CacheHandler* cacheHandler = Driver->getCacheHandler(); + + cacheHandler->setProgram(Program); + + // These states don't change later. + + ThicknessID = getPixelShaderConstantID("uThickness"); + if ( WithTexture ) + { + TextureUsageID = getPixelShaderConstantID("uTextureUsage"); + s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit"); + + s32 TextureUnit = 0; + setPixelShaderConstant(TextureUnitID, &TextureUnit, 1); + + s32 TextureUsage = 0; + setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); + } + + cacheHandler->setProgram(0); +} + +COpenGL3Renderer2D::~COpenGL3Renderer2D() +{ +} + +void COpenGL3Renderer2D::OnSetMaterial(const video::SMaterial& material, + const video::SMaterial& lastMaterial, + bool resetAllRenderstates, + video::IMaterialRendererServices* services) +{ + Driver->getCacheHandler()->setProgram(Program); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + + f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f; + setPixelShaderConstant(ThicknessID, &Thickness, 1); + + if ( WithTexture ) + { + s32 TextureUsage = material.TextureLayer[0].Texture ? 1 : 0; + setPixelShaderConstant(TextureUsageID, &TextureUsage, 1); + } +} + +bool COpenGL3Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) +{ + return true; +} + +} +} diff --git a/source/Irrlicht/OpenGL/Renderer2D.h b/source/Irrlicht/OpenGL/Renderer2D.h index 806d1e7..426a8b7 100644 --- a/source/Irrlicht/OpenGL/Renderer2D.h +++ b/source/Irrlicht/OpenGL/Renderer2D.h @@ -1,33 +1,33 @@ -// Copyright (C) 2014 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#pragma once - -#include "MaterialRenderer.h" - -namespace irr -{ -namespace video -{ - -class COpenGL3Renderer2D : public COpenGL3MaterialRenderer -{ -public: - COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture); - ~COpenGL3Renderer2D(); - - virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, - bool resetAllRenderstates, IMaterialRendererServices* services); - - virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype); - -protected: - bool WithTexture; - s32 ThicknessID; - s32 TextureUsageID; -}; - - -} -} +// Copyright (C) 2014 Patryk Nadrowski +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#pragma once + +#include "MaterialRenderer.h" + +namespace irr +{ +namespace video +{ + +class COpenGL3Renderer2D : public COpenGL3MaterialRenderer +{ +public: + COpenGL3Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COpenGL3DriverBase* driver, bool withTexture); + ~COpenGL3Renderer2D(); + + virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, + bool resetAllRenderstates, IMaterialRendererServices* services); + + virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype); + +protected: + bool WithTexture; + s32 ThicknessID; + s32 TextureUsageID; +}; + + +} +} From 4dda28450f340b27c9b5a5111113b0537059d217 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 25 Mar 2023 11:26:52 +0300 Subject: [PATCH 41/42] Provide sources as private to IRRVIDEOOBJ --- source/Irrlicht/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index ad11dd4..6d87069 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -377,7 +377,7 @@ add_library(IRRVIDEOOBJ OBJECT ) if(USE_SDLGL) - target_sources(IRRVIDEOOBJ PUBLIC + target_sources(IRRVIDEOOBJ PRIVATE OpenGL/Driver.cpp OpenGL/ExtensionHandler.cpp OpenGL/FixedPipelineRenderer.cpp @@ -387,17 +387,17 @@ if(USE_SDLGL) endif() if(USE_SDLGL3) - target_sources(IRRVIDEOOBJ PUBLIC + target_sources(IRRVIDEOOBJ PRIVATE OpenGL3/Driver.cpp ) endif() if(USE_SDLGLES2) - target_sources(IRRVIDEOOBJ PUBLIC + target_sources(IRRVIDEOOBJ PRIVATE OpenGLES2/Driver.cpp ) else() - target_sources(IRRVIDEOOBJ PUBLIC + target_sources(IRRVIDEOOBJ PRIVATE COGLES2Driver.cpp COGLES2ExtensionHandler.cpp COGLES2FixedPipelineRenderer.cpp From 70ee4b05aa4a78809552e6bc6c3ff7cfe6c012af Mon Sep 17 00:00:00 2001 From: numzero Date: Wed, 5 Apr 2023 22:52:43 +0300 Subject: [PATCH 42/42] Indicate chosen OpenGL ES 2 driver during configuration --- source/Irrlicht/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 6d87069..4d7141e 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -230,9 +230,15 @@ endif() message(STATUS "Device: ${DEVICE}") message(STATUS "OpenGL: ${ENABLE_OPENGL}") -message(STATUS "OpenGL 3: ${ENABLE_OPENGL3}") +message(STATUS "OpenGL 3: ${USE_SDLGL3}") message(STATUS "OpenGL ES: ${ENABLE_GLES1}") -message(STATUS "OpenGL ES 2: ${ENABLE_GLES2}") +if (USE_SDLGLES2) + message(STATUS "OpenGL ES 2: ON (unified)") +elseif (ENABLE_GLES2) + message(STATUS "OpenGL ES 2: ON (legacy)") +else() + message(STATUS "OpenGL ES 2: OFF") +endif() message(STATUS "WebGL: ${ENABLE_WEBGL1}") # Required libs