From 51dffc416a30417aedb533cb9fb817bca1c7a81c Mon Sep 17 00:00:00 2001 From: DS Date: Mon, 6 Feb 2023 15:05:44 +0100 Subject: [PATCH 001/123] Add WindowMaximized creation parameter and isWindowMaximized() (#142) --- include/IrrlichtDevice.h | 6 +++ include/SIrrCreationParameters.h | 5 ++ source/Irrlicht/CIrrDeviceLinux.cpp | 16 ++++++- source/Irrlicht/CIrrDeviceLinux.h | 4 ++ source/Irrlicht/CIrrDeviceSDL.cpp | 37 ++++++++------- source/Irrlicht/CIrrDeviceSDL.h | 4 +- source/Irrlicht/CIrrDeviceStub.cpp | 7 +++ source/Irrlicht/CIrrDeviceStub.h | 73 +++++++++++++++-------------- source/Irrlicht/CIrrDeviceWin32.cpp | 17 ++++++- source/Irrlicht/CIrrDeviceWin32.h | 5 ++ 10 files changed, 120 insertions(+), 54 deletions(-) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index 43107eb5..b967d70b 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -156,6 +156,12 @@ namespace irr /** \return True if window is minimized. */ virtual bool isWindowMinimized() const = 0; + //! Checks if the Irrlicht window is maximized + //! Only fully works on SDL. Returns false, or the last value set via + //! maximizeWindow() and restoreWindow(), on other backends. + /** \return True if window is maximized. */ + virtual bool isWindowMaximized() const = 0; + //! Checks if the Irrlicht window is running in fullscreen mode /** \return True if window is fullscreen. */ virtual bool isFullscreen() const = 0; diff --git a/include/SIrrCreationParameters.h b/include/SIrrCreationParameters.h index 66165732..f99fce58 100644 --- a/include/SIrrCreationParameters.h +++ b/include/SIrrCreationParameters.h @@ -30,6 +30,7 @@ namespace irr Bits(32), ZBufferBits(24), Fullscreen(false), + WindowMaximized(false), WindowResizable(2), Stencilbuffer(true), Vsync(false), @@ -73,6 +74,7 @@ namespace irr Bits = other.Bits; ZBufferBits = other.ZBufferBits; Fullscreen = other.Fullscreen; + WindowMaximized = other.WindowMaximized; WindowResizable = other.WindowResizable; Stencilbuffer = other.Stencilbuffer; Vsync = other.Vsync; @@ -127,6 +129,9 @@ namespace irr /** Otherwise the device runs in windowed mode. Default: false. */ bool Fullscreen; + //! Maximised window. (Only supported on SDL.) Default: false + bool WindowMaximized; + //! Should a non-fullscreen window be resizable. /** Might not be supported by all devices. Ignored when Fullscreen is true. Values: 0 = not resizable, 1 = resizable, 2 = system decides default itself diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index 91d1e470..b447015b 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -118,7 +118,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param) currentTouchedCount(0), #endif Width(param.WindowSize.Width), Height(param.WindowSize.Height), - WindowHasFocus(false), WindowMinimized(false), + WindowHasFocus(false), WindowMinimized(false), WindowMaximized(param.WindowMaximized), ExternalWindow(false), AutorepeatSupport(0) { #ifdef _DEBUG @@ -168,6 +168,9 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param) return; createGUIAndScene(); + + if (param.WindowMaximized) + maximizeWindow(); } @@ -1200,6 +1203,13 @@ bool CIrrDeviceLinux::isWindowMinimized() const } +//! returns last state from maximizeWindow() and restoreWindow() +bool CIrrDeviceLinux::isWindowMaximized() const +{ + return WindowMaximized; +} + + //! returns color format of the window. video::ECOLOR_FORMAT CIrrDeviceLinux::getColorFormat() const { @@ -1284,6 +1294,8 @@ void CIrrDeviceLinux::maximizeWindow() } XMapWindow(XDisplay, XWindow); + + WindowMaximized = true; #endif } @@ -1310,6 +1322,8 @@ void CIrrDeviceLinux::restoreWindow() } XMapWindow(XDisplay, XWindow); + + WindowMaximized = false; #endif } diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index fe1ede03..c456a1a7 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -64,6 +64,9 @@ namespace irr //! returns if window is minimized. bool isWindowMinimized() const override; + //! returns last state from maximizeWindow() and restoreWindow() + bool isWindowMaximized() const override; + //! returns color format of the window. video::ECOLOR_FORMAT getColorFormat() const override; @@ -415,6 +418,7 @@ namespace irr u32 Width, Height; bool WindowHasFocus; bool WindowMinimized; + bool WindowMaximized; bool ExternalWindow; int AutorepeatSupport; diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 8452c6b9..83c763c6 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -111,7 +111,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) Window((SDL_Window*)param.WindowId), SDL_Flags(0), MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0), Width(param.WindowSize.Width), Height(param.WindowSize.Height), - Resizable(param.WindowResizable == 1 ? true : false), WindowMinimized(false) + Resizable(param.WindowResizable == 1 ? true : false) { #ifdef _DEBUG setDebugName("CIrrDeviceSDL"); @@ -139,10 +139,14 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) // create keymap createKeyMap(); - if ( CreationParams.Fullscreen ) + if (CreationParams.Fullscreen) { SDL_Flags |= SDL_WINDOW_FULLSCREEN; - else if ( Resizable ) - SDL_Flags |= SDL_WINDOW_RESIZABLE; + } 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; @@ -160,6 +164,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) createWindow(); } + SDL_VERSION(&Info.version); #ifndef _IRR_EMSCRIPTEN_PLATFORM_ @@ -636,12 +641,6 @@ bool CIrrDeviceSDL::run() case SDL_WINDOWEVENT: switch (SDL_event.window.event) { - case SDL_WINDOWEVENT_MAXIMIZED: - WindowMinimized = true; - break; - case SDL_WINDOWEVENT_RESTORED: - WindowMinimized = false; - break; case SDL_WINDOWEVENT_RESIZED: if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height)) { @@ -862,16 +861,16 @@ void CIrrDeviceSDL::setResizable(bool resize) //! Minimizes window if possible void CIrrDeviceSDL::minimizeWindow() { - if (Window) { + if (Window) SDL_MinimizeWindow(Window); - } } //! Maximize window void CIrrDeviceSDL::maximizeWindow() { - // do nothing + if (Window) + SDL_MaximizeWindow(Window); } //! Get the position of this window on screen @@ -884,7 +883,13 @@ core::position2di CIrrDeviceSDL::getWindowPosition() //! Restore original window size void CIrrDeviceSDL::restoreWindow() { - // do nothing + if (Window) + SDL_RestoreWindow(Window); +} + +bool CIrrDeviceSDL::isWindowMaximized() const +{ + return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MAXIMIZED) != 0; } bool CIrrDeviceSDL::isFullscreen() const @@ -919,14 +924,14 @@ bool CIrrDeviceSDL::isWindowActive() const //! returns if window has focus. bool CIrrDeviceSDL::isWindowFocused() const { - return SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS; + return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS) != 0; } //! returns if window is minimized. bool CIrrDeviceSDL::isWindowMinimized() const { - return WindowMinimized; + return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MINIMIZED) != 0; } diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 5a38d774..29927182 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -76,6 +76,9 @@ namespace irr //! Restores the window size. void restoreWindow() override; + //! Checks if the window is maximized. + bool isWindowMaximized() const override; + //! Checks if the Irrlicht window is running in fullscreen mode /** \return True if window is fullscreen. */ bool isFullscreen() const override; @@ -283,7 +286,6 @@ namespace irr u32 Width, Height; bool Resizable; - bool WindowMinimized; struct SKeyMap { diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index 95e7c5d1..877a4bf3 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -272,6 +272,13 @@ void CIrrDeviceStub::setInputReceivingSceneManager(scene::ISceneManager* sceneMa } +//! Checks if the window is maximized. +bool CIrrDeviceStub::isWindowMaximized() const +{ + return false; +} + + //! Checks if the window is running in fullscreen mode bool CIrrDeviceStub::isFullscreen() const { diff --git a/source/Irrlicht/CIrrDeviceStub.h b/source/Irrlicht/CIrrDeviceStub.h index c6e00593..5b7d92ff 100644 --- a/source/Irrlicht/CIrrDeviceStub.h +++ b/source/Irrlicht/CIrrDeviceStub.h @@ -94,6 +94,9 @@ namespace irr //! Returns the operation system opertator object. IOSOperator* getOSOperator() override; + //! Checks if the window is maximized. + bool isWindowMaximized() const override; + //! Checks if the window is running in fullscreen mode. bool isFullscreen() const override; @@ -103,41 +106,41 @@ namespace irr //! Activate any joysticks, and generate events for them. bool activateJoysticks(core::array & joystickInfo) override; - //! Activate accelerometer. - bool activateAccelerometer(float updateInterval = 0.016666f) override; - - //! Deactivate accelerometer. - bool deactivateAccelerometer() override; - - //! Is accelerometer active. - bool isAccelerometerActive() override; - - //! Is accelerometer available. - bool isAccelerometerAvailable() override; - - //! Activate gyroscope. - bool activateGyroscope(float updateInterval = 0.016666f) override; - - //! Deactivate gyroscope. - bool deactivateGyroscope() override; - - //! Is gyroscope active. - bool isGyroscopeActive() override; - - //! Is gyroscope available. - bool isGyroscopeAvailable() override; - - //! Activate device motion. - bool activateDeviceMotion(float updateInterval = 0.016666f) override; - - //! Deactivate device motion. - bool deactivateDeviceMotion() override; - - //! Is device motion active. - bool isDeviceMotionActive() override; - - //! Is device motion available. - bool isDeviceMotionAvailable() override; + //! Activate accelerometer. + bool activateAccelerometer(float updateInterval = 0.016666f) override; + + //! Deactivate accelerometer. + bool deactivateAccelerometer() override; + + //! Is accelerometer active. + bool isAccelerometerActive() override; + + //! Is accelerometer available. + bool isAccelerometerAvailable() override; + + //! Activate gyroscope. + bool activateGyroscope(float updateInterval = 0.016666f) override; + + //! Deactivate gyroscope. + bool deactivateGyroscope() override; + + //! Is gyroscope active. + bool isGyroscopeActive() override; + + //! Is gyroscope available. + bool isGyroscopeAvailable() override; + + //! Activate device motion. + bool activateDeviceMotion(float updateInterval = 0.016666f) override; + + //! Deactivate device motion. + bool deactivateDeviceMotion() override; + + //! Is device motion active. + bool isDeviceMotionActive() override; + + //! Is device motion available. + bool isDeviceMotionAvailable() override; //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior. //! When set to 0 no double- and tripleclicks will be generated. diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index 0c513040..ddff014b 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -784,7 +784,8 @@ namespace irr //! constructor CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) : CIrrDeviceStub(params), HWnd(0), Resized(false), - ExternalWindow(false), Win32CursorControl(0), JoyControl(0) + ExternalWindow(false), Win32CursorControl(0), JoyControl(0), + WindowMaximized(params.WindowMaximized) { #ifdef _DEBUG setDebugName("CIrrDeviceWin32"); @@ -923,6 +924,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) // inform driver about the window size etc. resizeIfNecessary(); + + if (params.WindowMaximized) + maximizeWindow(); } @@ -1154,6 +1158,13 @@ bool CIrrDeviceWin32::isWindowMinimized() const } +//! returns last state from maximizeWindow() and restoreWindow() +bool CIrrDeviceWin32::isWindowMaximized() const +{ + return WindowMaximized; +} + + //! switches to fullscreen bool CIrrDeviceWin32::switchToFullScreen() { @@ -1278,6 +1289,8 @@ void CIrrDeviceWin32::maximizeWindow() GetWindowPlacement(HWnd, &wndpl); wndpl.showCmd = SW_SHOWMAXIMIZED; SetWindowPlacement(HWnd, &wndpl); + + WindowMaximized = true; } @@ -1289,6 +1302,8 @@ void CIrrDeviceWin32::restoreWindow() GetWindowPlacement(HWnd, &wndpl); wndpl.showCmd = SW_SHOWNORMAL; SetWindowPlacement(HWnd, &wndpl); + + WindowMaximized = false; } core::position2di CIrrDeviceWin32::getWindowPosition() diff --git a/source/Irrlicht/CIrrDeviceWin32.h b/source/Irrlicht/CIrrDeviceWin32.h index 8cd324bc..4af8d027 100644 --- a/source/Irrlicht/CIrrDeviceWin32.h +++ b/source/Irrlicht/CIrrDeviceWin32.h @@ -57,6 +57,9 @@ namespace irr //! returns if window is minimized bool isWindowMinimized() const override; + //! returns last state from maximizeWindow() and restoreWindow() + bool isWindowMaximized() const override; + //! notifies the device that it should close itself void closeDevice() override; @@ -413,6 +416,8 @@ namespace irr CCursorControl* Win32CursorControl; SJoystickWin32Control* JoyControl; + + bool WindowMaximized; }; } // end namespace irr From cd3e7845344a413a73d2649e3e99d51f14eb12fb Mon Sep 17 00:00:00 2001 From: ndren Date: Sat, 18 Feb 2023 15:16:17 +0000 Subject: [PATCH 002/123] Refactor SDL input code to fix menu exit (#146) --- source/Irrlicht/CIrrDeviceSDL.cpp | 107 ++++++++++++++++++++++++++++-- source/Irrlicht/CIrrDeviceSDL.h | 9 +++ 2 files changed, 109 insertions(+), 7 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 83c763c6..23f00d25 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -8,6 +8,8 @@ #include "CIrrDeviceSDL.h" #include "IEventReceiver.h" +#include "IGUIElement.h" +#include "IGUIEnvironment.h" #include "os.h" #include "CTimer.h" #include "irrString.h" @@ -105,6 +107,98 @@ EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEv } #endif + +bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key) +{ + switch ( key ) + { + // keys which are known to have safe special character interpretation + // could need changes over time (removals and additions!) + case KEY_RETURN: + case KEY_PAUSE: + case KEY_ESCAPE: + case KEY_PRIOR: + case KEY_NEXT: + case KEY_HOME: + case KEY_END: + case KEY_LEFT: + case KEY_UP: + case KEY_RIGHT: + case KEY_DOWN: + case KEY_TAB: + case KEY_PRINT: + case KEY_SNAPSHOT: + case KEY_INSERT: + case KEY_BACK: + case KEY_DELETE: + case KEY_HELP: + case KEY_APPS: + case KEY_SLEEP: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_F17: + case KEY_F18: + case KEY_F19: + case KEY_F20: + case KEY_F21: + case KEY_F22: + case KEY_F23: + case KEY_F24: + case KEY_NUMLOCK: + case KEY_SCROLL: + case KEY_LCONTROL: + case KEY_RCONTROL: + return true; + + default: + return false; + } +} + +int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) { + // SDL in-place ORs values with no character representation with 1<<30 + // https://wiki.libsdl.org/SDL2/SDLKeycodeLookup + if (assumedChar & (1<<30)) + return 0; + + switch (key) { + case KEY_PRIOR: + case KEY_NEXT: + case KEY_HOME: + case KEY_END: + case KEY_LEFT: + case KEY_UP: + case KEY_RIGHT: + case KEY_DOWN: + case KEY_NUMLOCK: + return 0; + default: + return assumedChar; + } +} + +void CIrrDeviceSDL::resetReceiveTextInputEvents() { + gui::IGUIElement *elem = GUIEnvironment->getFocus(); + if (elem && elem->acceptsIME()) + SDL_StartTextInput(); + else + SDL_StopTextInput(); +} + //! constructor CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) : CIrrDeviceStub(param), @@ -611,6 +705,10 @@ bool CIrrDeviceSDL::run() else key = (EKEY_CODE)KeyMap[idx].Win32Key; + // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already + if (SDL_IsTextInputActive() && !keyIsKnownSpecial(key) && (SDL_event.key.keysym.mod & KMOD_CTRL) == 0) + break; + #ifdef _IRR_WINDOWS_API_ // handle alt+f4 in Windows, because SDL seems not to if ( (SDL_event.key.keysym.mod & KMOD_LALT) && key == KEY_F4) @@ -624,12 +722,7 @@ bool CIrrDeviceSDL::run() irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN); irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0; irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL ) != 0; - // These keys are handled differently in CGUIEditBox.cpp (may become out of date!) - // Control key is used in special character combinations, so keep that too - // Pass through the keysym only then so no extra text gets input - irrevent.KeyInput.Char = 0; - if (mp.SDLKey == SDLK_DELETE || mp.SDLKey == SDLK_RETURN || mp.SDLKey == SDLK_BACKSPACE || irrevent.KeyInput.Control) - irrevent.KeyInput.Char = mp.SDLKey; + irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key); postEventFromUser(irrevent); } break; @@ -663,7 +756,7 @@ bool CIrrDeviceSDL::run() default: break; } // end switch - + resetReceiveTextInputEvents(); } // end while #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 29927182..7657718f 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -264,6 +264,15 @@ namespace irr static EM_BOOL MouseLeaveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); #endif + // Check if a key is a known special character with no side effects on text boxes. + static bool keyIsKnownSpecial(EKEY_CODE key); + + // Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0). + static int findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key); + + // Check if a text box is in focus. Enable or disable SDL_TEXTINPUT events only if in focus. + void resetReceiveTextInputEvents(); + //! create the driver void createDriver(); From 5527b9f373ef4267a2b44f816be07ddab48a289d Mon Sep 17 00:00:00 2001 From: DS Date: Mon, 20 Feb 2023 13:22:28 +0100 Subject: [PATCH 003/123] SDL: Use SDL_WINDOW_FULLSCREEN_DESKTOP and allow to maximize+fullscreen at once (#156) --- source/Irrlicht/CIrrDeviceSDL.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 23f00d25..1af434b8 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -234,13 +234,17 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) createKeyMap(); if (CreationParams.Fullscreen) { +#ifdef _IRR_EMSCRIPTEN_PLATFORM_ SDL_Flags |= SDL_WINDOW_FULLSCREEN; - } else { - if (Resizable) - SDL_Flags |= SDL_WINDOW_RESIZABLE; - if (CreationParams.WindowMaximized) - SDL_Flags |= SDL_WINDOW_MAXIMIZED; +#else + SDL_Flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; +#endif } + 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; From 38f18eec569f88496465b04c152de905087ca9e2 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 19 Feb 2023 18:22:43 +0300 Subject: [PATCH 004/123] 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 fe1e29d1..deade755 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 ea297196b7135faac820073d0ce107e43a734d48 Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 21 Feb 2023 18:30:14 +0100 Subject: [PATCH 005/123] Resolve some -Wreorder warnings --- source/Irrlicht/CIrrDeviceLinux.h | 7 +++---- source/Irrlicht/CWriteFile.cpp | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index c456a1a7..ea50d7c7 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -414,6 +414,9 @@ namespace irr bool HasNetWM; // text is utf-8 mutable core::stringc Clipboard; +#endif +#if defined(_IRR_LINUX_X11_XINPUT2_) + int currentTouchedCount; #endif u32 Width, Height; bool WindowHasFocus; @@ -454,10 +457,6 @@ namespace irr }; core::array ActiveJoysticks; #endif - -#if defined(_IRR_LINUX_X11_XINPUT2_) - int currentTouchedCount; -#endif }; diff --git a/source/Irrlicht/CWriteFile.cpp b/source/Irrlicht/CWriteFile.cpp index aa07b49e..2af6936a 100644 --- a/source/Irrlicht/CWriteFile.cpp +++ b/source/Irrlicht/CWriteFile.cpp @@ -12,7 +12,7 @@ namespace io CWriteFile::CWriteFile(const io::path& fileName, bool append) -: FileSize(0), Filename(fileName) +: Filename(fileName), FileSize(0) { #ifdef _DEBUG setDebugName("CWriteFile"); From 839bdc1a658773ea9525bec547e2b887664a14ba Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 21 Feb 2023 18:54:07 +0100 Subject: [PATCH 006/123] Fix -Wignored-qualifiers warnings in irrUString.h --- include/irrUString.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/irrUString.h b/include/irrUString.h index a50d497f..5b2b8578 100644 --- a/include/irrUString.h +++ b/include/irrUString.h @@ -963,11 +963,11 @@ public: #endif if (sizeof(wchar_t) == 4) - append(reinterpret_cast(c)); + append(reinterpret_cast(c)); else if (sizeof(wchar_t) == 2) - append(reinterpret_cast(c)); + append(reinterpret_cast(c)); else if (sizeof(wchar_t) == 1) - append(reinterpret_cast(c)); + append(reinterpret_cast(c)); } @@ -982,11 +982,11 @@ public: #endif if (sizeof(wchar_t) == 4) - append(reinterpret_cast(c), length); + append(reinterpret_cast(c), length); else if (sizeof(wchar_t) == 2) - append(reinterpret_cast(c), length); + append(reinterpret_cast(c), length); else if (sizeof(wchar_t) == 1) - append(reinterpret_cast(c), length); + append(reinterpret_cast(c), length); } @@ -1116,11 +1116,11 @@ public: ustring16& operator=(const wchar_t* const c) { if (sizeof(wchar_t) == 4) - *this = reinterpret_cast(c); + *this = reinterpret_cast(c); else if (sizeof(wchar_t) == 2) - *this = reinterpret_cast(c); + *this = reinterpret_cast(c); else if (sizeof(wchar_t) == 1) - *this = reinterpret_cast(c); + *this = reinterpret_cast(c); return *this; } @@ -3049,14 +3049,14 @@ public: //! Gets the encoding of the Unicode string this class contains. //! \return An enum describing the current encoding of this string. - const unicode::EUTF_ENCODE getEncoding() const + unicode::EUTF_ENCODE getEncoding() const { return encoding; } //! Gets the endianness of the Unicode string this class contains. //! \return An enum describing the endianness of this string. - const unicode::EUTF_ENDIAN getEndianness() const + unicode::EUTF_ENDIAN getEndianness() const { if (encoding == unicode::EUTFE_UTF16_LE || encoding == unicode::EUTFE_UTF32_LE) From 09e6eeb65b03d0bec1dfbcc008bd57fd5cd5802c Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 21 Feb 2023 19:29:32 +0100 Subject: [PATCH 007/123] Remove irr::core::hash Its use of std::unary_function was deprecated. And it wasn't used anywhere. --- include/irrUString.h | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/include/irrUString.h b/include/irrUString.h index 5b2b8578..8e553fd7 100644 --- a/include/irrUString.h +++ b/include/irrUString.h @@ -3612,33 +3612,5 @@ inline std::wostream& operator<<(std::wostream& out, const ustring16& in) return out; } -namespace unicode -{ - -//! Hashing algorithm for hashing a ustring. Used for things like unordered_maps. -//! Algorithm taken from std::hash. -class hash : public std::unary_function -{ - public: - size_t operator()(const core::ustring& s) const - { - size_t ret = 2166136261U; - size_t index = 0; - size_t stride = 1 + s.size_raw() / 10; - - core::ustring::const_iterator i = s.begin(); - while (i != s.end()) - { - // TODO: Don't force u32 on an x64 OS. Make it agnostic. - ret = 16777619U * ret ^ (size_t)s[(u32)index]; - index += stride; - i += stride; - } - return (ret); - } -}; - -} // end namespace unicode - } // end namespace core } // end namespace irr From 06db7b7ab7a4b439545a409d03d1e075506699ec Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 19 Feb 2023 22:44:02 +0300 Subject: [PATCH 008/123] 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 ef5d4623..41dc3d67 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 e7241767..0141b2bb 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 be614607..a0c1ca7c 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 91588a3c..ed82b5f9 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 deade755..7d3c4589 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 b967d70b..07d4f9f8 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 f99fce58..c47f3e69 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 e1e7cb2e..803ed6ee 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 a50d497f..61c36b85 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 208b5733..76228d1f 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 009/123] 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 7d3c4589..5a4f8984 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 76228d1f..eeb1029a 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 010/123] 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 5a4f8984..7536a849 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 994f8cd2..af00f440 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 e67b3958..eda3a21c 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 467a49d1..be3a7f93 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 9d92e038..cea8ef29 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 ca86a6a4..83ec3736 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 aaca1680..0b588fc0 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 a1464eb1..c297978e 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 04ef8c7d..4f05b842 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 45e8680c..17ae7b33 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 6d15706b..8ad956de 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 234c5157..a913101a 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 5d993ce5..6217f1b2 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 0d19d713..c7b5df20 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 146adbe8..7e727a38 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 b4680173..59709bfb 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 6e631b72..ed135db9 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 af4fad55..3286bddd 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 d8f7368b..f31c6825 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 97a64b84..1fb9fb37 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 ec8a1b85..facf67d2 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 55ae00ec..0e2a71ec 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 eec12ff0..4d6619f5 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 eeb1029a..7b511455 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 775a22c9..5834e01c 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 c4fee234..11fa484a 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 664e672d..b664c772 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 9f47f3b6..5e01e060 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 2de099fe..dfeefd33 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 d394313d..500db900 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 458b6db4..02de98fb 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 011/123] 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 7536a849..0259399c 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 704fd3d2..d6ab543d 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 9bd86122..6c718b1a 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 48ec5e8a..6c5271ff 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 adb46b41..facbfb05 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 b35b47a6..ecd3a9c2 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 dbdae41b..13996f0d 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 a3851e60..cf4b64ee 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 b0b50706..0626fec4 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 8ad956de..a7b28042 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 ab745865..2a6097c0 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 6599bef5..e68d7cda 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 55b9ffa7..c51f6049 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 1becf675..b7b6ed75 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 4cf93b89..c7b93374 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 2d2a08cb..669428b9 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 581fe1b5..37d0abc6 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 f6f0e778..b00c7e38 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 8e1566d6..a615ed4e 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 6d6d3675..567251c6 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 170a2da0..1a6d6837 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 08a59007..b417b720 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 11cfb26b..436124b6 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 c89bb26e..8f5fb673 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 cfca788f..2a324a70 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 b9ab35a9..29bbdb70 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 827e95ff..41045d0a 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 30a31c39..c08a5799 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 d5e8315f..5bca2b64 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 877a4bf3..16028c8c 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 012/123] 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 0259399c..d186a2cb 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 b664c772..fd837ccf 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 013/123] 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 a8cea131..e3ea2210 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 d186a2cb..02712894 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 43dadb6e..92dc822a 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 5834e01c..2cbd47cd 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 014/123] 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 c47f3e69..bad56e3d 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 92dc822a..88460e00 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 803ed6ee..a98ed960 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 af00f440..c4e86190 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 eda3a21c..98b1ed6d 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 065ed60a..e099cf79 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 c4109737..efd353de 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 e7876cf9..7b76cd98 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 0774cdd6..ba777489 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 53d06f8c..f5c02d16 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 7d7ab351..24a62f05 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 ef1529be..55383e28 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 c9d96a54..7791a771 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 a1f13c3a..4a3cd953 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 bac23ad6..b6bc09bf 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 be3a7f93..5d88937d 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 7156b8ee..3d881156 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 83ec3736..448030ba 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 765405f7..d19f190e 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 0b588fc0..ac68f77e 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 c297978e..da90c3a1 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 4f05b842..3d0f812b 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 c1f88455..65caa7aa 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 2d61bd2c..78e96c88 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 15d5410e..720b8bb5 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 17ae7b33..ba4a332c 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 85c3c94d..9e4ce74e 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 6c718b1a..0e429573 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 facbfb05..8319243e 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 13996f0d..2dab66f1 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 0626fec4..4a1b6e8f 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 2a6097c0..f68b0daf 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 c51f6049..a1d633c4 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 c7b93374..449df086 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 37d0abc6..c8a46f26 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 a615ed4e..a3e7255a 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 1a6d6837..d1d04b89 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 436124b6..d6f8ef8f 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 2a324a70..affd6bfd 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 41045d0a..8e1babe9 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 5bca2b64..4c2a0549 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 6217f1b2..1f944032 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 7e727a38..03163941 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 ed135db9..45a37fd3 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 f31c6825..4e675793 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 facf67d2..dd98e913 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 4d6619f5..181d0c50 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 c456a1a7..45d3f10c 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 b8cdb42b..d1b2049e 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 e3b2a9ab..4069cf19 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 23f00d25..8dee4d1f 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 7657718f..4dbb2e76 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 16028c8c..92cda75d 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 ddff014b..1033f9ed 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 4af8d027..9ca44acc 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 d383c182..6130d275 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 efe0b421..8744d16e 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 11fa484a..c4be102d 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 2c844ce3..a69f6674 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 8d31ff63..eaf4d99f 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 2e81b373..73db08a8 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 f5882f17..b50ef74e 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 9c4c2c9f..5483263e 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 25217580..1d69828b 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 a7b8eb3e..57e5b7bd 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 a5578447..ce6ea1d0 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 eb27f076..74280946 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 efed7939..bcc3278b 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 5af6f73e..b2f88611 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 f7d14c03..11c8a296 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 6f7b790f..52a0604a 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 5726e5f2..79b28007 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 6ec58227..fe86f955 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 6c542f5d..0dd08ebc 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 8897c585..c19215b8 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 34540368..c60d2ba8 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 960b7f6d..5d748d59 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 ed37e5d5..6d330561 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 b6a4f821..a870a6eb 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 80ca4332..81f8c811 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 6b0f254d..3d9648c6 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 fd837ccf..e22ddd59 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 5e01e060..f7cf1f05 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 bd750650..e2d15130 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 ce264322..73c5a21f 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 67ffaf75..9a78df3c 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 dfeefd33..7603ec58 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 500db900..071f735b 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 02de98fb..6b16ab9d 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 4438b51c..826414fb 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 8f88a850..ddd8bd63 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 2b894bcd..6b386574 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 77012c28..c0aa83b0 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 015/123] 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 8dee4d1f..3b5a7361 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 7b511455..b78410c9 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 ce6ea1d0..1b4a2bb3 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 0dd08ebc..7dff3c92 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 00000000..3f71f650 --- /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 00000000..7c13e7c7 --- /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 00000000..dd2ad89e --- /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 00000000..297aa943 --- /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 00000000..1e6bd7f0 --- /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 00000000..4a20f020 --- /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 00000000..4a9bb95b --- /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 00000000..080835c9 --- /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 00000000..f45e7254 --- /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 00000000..d0a2c0ae --- /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 00000000..8df192b4 --- /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 016/123] 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 3b5a7361..8a74719e 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 017/123] 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 96d7587c..26de3d3c 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 018/123] 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 8a74719e..a5ba6f69 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 7c13e7c7..671f338a 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 dd2ad89e..4920fdea 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 019/123] 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 297aa943..055738b9 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 020/123] 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 e3ea2210..4f00f44b 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 2cbd47cd..a76dbecf 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 e6cdce66..33620452 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 671f338a..1a0bac0e 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 4920fdea..42c2debc 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 021/123] 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 1a0bac0e..7603d869 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 022/123] 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 7603d869..5e697e54 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 42c2debc..dc292973 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 023/123] 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 5e697e54..eb4150c5 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 dc292973..b7325954 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 024/123] 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 eb4150c5..baa6f444 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 b7325954..6cbf7bd2 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 025/123] 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 f5a2e929..1c235364 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 bad56e3d..74396048 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 e099cf79..359f810f 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 026/123] 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 7dff3c92..f893c174 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 c19215b8..2ad8af12 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 027/123] 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 1c235364..04097573 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 a5ba6f69..48c58616 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 028/123] 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 b78410c9..4b3fa21b 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 029/123] 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 baa6f444..6a60316d 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 030/123] 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 48c58616..6ebf63b9 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 4b3fa21b..a2ca46e4 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 3f71f650..a69bcc62 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 6a60316d..27ab1bad 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 6cbf7bd2..e95a633c 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 080835c9..20d684c8 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 f45e7254..dbac6cf6 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 d0a2c0ae..8bedb179 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 8df192b4..806d1e7c 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 00000000..925c6eaf --- /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 00000000..cb30432c --- /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 00000000..2b034644 --- /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 00000000..cdfb2fec --- /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 031/123] 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 6ebf63b9..ecd8a8da 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 032/123] =?UTF-8?q?Restore=20obsolete=20constants=20as=20t?= =?UTF-8?q?hey=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 04097573..71cea544 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 033/123] 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 7b511455..7a29d378 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 1d43ea17ca8ee9a01262e9e34c5c89579b97397f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 5 Mar 2023 21:44:44 +0100 Subject: [PATCH 034/123] Bump revision --- CMakeLists.txt | 2 +- include/IrrCompileConfig.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7b244a9..a15d263f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ else() cmake_policy(VERSION 3.9) endif() -set(IRRLICHTMT_REVISION 9) +set(IRRLICHTMT_REVISION 10) project(Irrlicht VERSION 1.9.0.${IRRLICHTMT_REVISION} diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index fe1e29d1..0d308e90 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -6,8 +6,8 @@ #define __IRR_COMPILE_CONFIG_H_INCLUDED__ //! Identifies the IrrlichtMt fork customized for the Minetest engine -#define IRRLICHT_VERSION_MT_REVISION 9 -#define IRRLICHT_VERSION_MT "mt9" +#define IRRLICHT_VERSION_MT_REVISION 10 +#define IRRLICHT_VERSION_MT "mt10" //! Irrlicht SDK Version #define IRRLICHT_VERSION_MAJOR 1 From 6de0afa8b3b6304b080798024bac41cdc668e823 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 6 Mar 2023 13:58:38 +0300 Subject: [PATCH 035/123] 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 e3ea2210..b220e5e6 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 5b275d37..899dfd9a 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 036/123] 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 07d4f9f8..c6a19787 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 826414fb..50348e7f 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 037/123] 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 7a29d378..cfd3bbe1 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 038/123] 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 cfd3bbe1..4d2ec7ec 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 5a5a7d04b71b576ac9eed1bb58110009f8b46d0b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 11 Mar 2023 17:04:09 +0300 Subject: [PATCH 039/123] Drop IrrCompileConfig (#163) --- .github/workflows/build.yml | 9 +- examples/AutomatedTest/main.cpp | 12 +- include/EDeviceTypes.h | 2 +- include/IEventReceiver.h | 8 +- include/IVideoDriver.h | 27 +- include/IrrCompileConfig.h | 446 +----------------- include/IrrlichtDevice.h | 38 +- include/SIrrCreationParameters.h | 4 +- include/SMaterial.h | 3 +- include/exampleHelper.h | 3 +- include/irrMath.h | 9 - include/irrTypes.h | 3 - include/irrUString.h | 4 +- include/irrlicht.h | 2 +- include/matrix4.h | 1 + include/mt_opengl.h | 2 +- scripts/BindingGenerator.lua | 2 +- .../Android/CAndroidAssetFileArchive.cpp | 1 - .../Android/CAndroidAssetFileArchive.h | 1 - .../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 | 16 - source/Irrlicht/CAnimatedMeshSceneNode.cpp | 2 + source/Irrlicht/CAttributes.h | 1 - source/Irrlicht/CB3DMeshFileLoader.cpp | 7 - source/Irrlicht/CB3DMeshFileLoader.h | 1 - source/Irrlicht/CB3DMeshWriter.cpp | 6 - source/Irrlicht/CBillboardSceneNode.cpp | 4 - source/Irrlicht/CBoneSceneNode.cpp | 6 - source/Irrlicht/CEAGLManager.h | 1 - source/Irrlicht/CEGLManager.h | 1 - source/Irrlicht/CFileList.cpp | 1 - source/Irrlicht/CFileSystem.cpp | 3 - source/Irrlicht/CGLXManager.h | 1 - source/Irrlicht/CGUIButton.cpp | 4 - source/Irrlicht/CGUIButton.h | 6 - source/Irrlicht/CGUICheckBox.cpp | 5 - source/Irrlicht/CGUICheckBox.h | 5 - source/Irrlicht/CGUIComboBox.cpp | 5 - source/Irrlicht/CGUIComboBox.h | 6 - source/Irrlicht/CGUIEditBox.cpp | 4 - source/Irrlicht/CGUIEditBox.h | 5 - source/Irrlicht/CGUIEnvironment.cpp | 10 +- source/Irrlicht/CGUIEnvironment.h | 7 - source/Irrlicht/CGUIFileOpenDialog.cpp | 3 - source/Irrlicht/CGUIFileOpenDialog.h | 6 - source/Irrlicht/CGUIFont.cpp | 4 - source/Irrlicht/CGUIFont.h | 6 - source/Irrlicht/CGUIImage.cpp | 5 - source/Irrlicht/CGUIImage.h | 5 - source/Irrlicht/CGUIListBox.cpp | 4 - source/Irrlicht/CGUIListBox.h | 5 - source/Irrlicht/CGUIScrollBar.cpp | 4 - source/Irrlicht/CGUIScrollBar.h | 6 - source/Irrlicht/CGUISkin.cpp | 4 - source/Irrlicht/CGUISkin.h | 7 - source/Irrlicht/CGUISpriteBank.cpp | 3 - source/Irrlicht/CGUISpriteBank.h | 6 - source/Irrlicht/CGUIStaticText.cpp | 4 - source/Irrlicht/CGUIStaticText.h | 6 - source/Irrlicht/CGUITabControl.cpp | 4 - source/Irrlicht/CGUITabControl.h | 6 - source/Irrlicht/CImageLoaderBMP.cpp | 5 - source/Irrlicht/CImageLoaderBMP.h | 11 - source/Irrlicht/CImageLoaderJPG.cpp | 41 +- source/Irrlicht/CImageLoaderJPG.h | 17 +- source/Irrlicht/CImageLoaderPNG.cpp | 23 +- source/Irrlicht/CImageLoaderPNG.h | 5 - source/Irrlicht/CImageLoaderTGA.cpp | 5 - source/Irrlicht/CImageLoaderTGA.h | 10 - source/Irrlicht/CImageWriterJPG.cpp | 12 +- source/Irrlicht/CImageWriterJPG.h | 5 - source/Irrlicht/CImageWriterPNG.cpp | 19 +- source/Irrlicht/CImageWriterPNG.h | 5 - 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 | 4 +- source/Irrlicht/CIrrDeviceWin32.cpp | 1 - source/Irrlicht/CIrrDeviceWin32.h | 1 - source/Irrlicht/CIrrDeviceiOS.h | 1 - source/Irrlicht/CMakeLists.txt | 228 +++++++-- source/Irrlicht/CNSOGLManager.h | 1 - source/Irrlicht/CNullDriver.cpp | 102 +--- source/Irrlicht/COBJMeshFileLoader.cpp | 6 - source/Irrlicht/COGLES2Common.h | 1 - source/Irrlicht/COGLES2Driver.h | 1 - source/Irrlicht/COGLES2ExtensionHandler.h | 1 - .../Irrlicht/COGLES2FixedPipelineRenderer.cpp | 4 +- .../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 - .../Irrlicht/COpenGLShaderMaterialRenderer.h | 1 - source/Irrlicht/CSDLManager.h | 1 - source/Irrlicht/CSceneManager.cpp | 98 +--- source/Irrlicht/CSkinnedMesh.cpp | 6 - source/Irrlicht/CWGLManager.h | 1 - source/Irrlicht/CWebGL1Driver.h | 1 - source/Irrlicht/CWebGLExtensionHandler.h | 1 - source/Irrlicht/CXMeshFileLoader.cpp | 6 - source/Irrlicht/CZipReader.cpp | 15 +- source/Irrlicht/CZipReader.h | 5 - source/Irrlicht/Irrlicht.cpp | 21 +- source/Irrlicht/SB3DStructs.h | 1 - source/Irrlicht/os.cpp | 1 - source/Irrlicht/os.h | 1 - 125 files changed, 288 insertions(+), 1179 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef5d4623..41dc3d67 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 e7241767..0141b2bb 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 be614607..a0c1ca7c 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 91588a3c..ed82b5f9 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/IVideoDriver.h b/include/IVideoDriver.h index a8cea131..b220e5e6 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -56,32 +56,11 @@ namespace video ETS_WORLD, //! Projection transformation ETS_PROJECTION, - //! Texture transformation + //! Texture 0 transformation + //! Use E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + texture_number) to access other texture transformations ETS_TEXTURE_0, - //! Texture 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 0d308e90..33361aa6 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -20,454 +20,14 @@ #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 - -//! 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. */ -#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 - -//! 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_ -#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_ - -// 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 -#endif - #define IRRCALLCONV - -#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_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 - // 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 +#ifndef IRRLICHT_API +#define IRRLICHT_API #endif #endif // __IRR_COMPILE_CONFIG_H_INCLUDED__ - diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index b967d70b..c6a19787 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(). @@ -235,8 +237,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 +312,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 video::isDriverSupported(driver); } }; diff --git a/include/SIrrCreationParameters.h b/include/SIrrCreationParameters.h index f99fce58..bad56e3d 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 { @@ -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/SMaterial.h b/include/SMaterial.h index 43dadb6e..88460e00 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 { @@ -280,7 +281,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/include/exampleHelper.h b/include/exampleHelper.h index e1e7cb2e..a98ed960 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 @@ -13,7 +12,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/irrMath.h b/include/irrMath.h index 994f8cd2..c4e86190 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 @@ -21,9 +20,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 +183,6 @@ namespace core return ROUNDING_ERROR_S32; } -#ifdef __IRR_HAS_S64 template <> inline s64 roundingError() { @@ -198,7 +194,6 @@ namespace core { return ROUNDING_ERROR_S64; } -#endif template inline T relativeErrorFactor() @@ -310,13 +305,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 +399,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 e67b3958..98b1ed6d 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 @@ -38,13 +37,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/include/irrUString.h b/include/irrUString.h index 8e553fd7..b0b730f0 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/include/irrlicht.h b/include/irrlicht.h index 065ed60a..e099cf79 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 c4109737..efd353de 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 e7876cf9..7b76cd98 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 0774cdd6..ba777489 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 53d06f8c..f5c02d16 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 7d7ab351..24a62f05 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 ef1529be..55383e28 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 c9d96a54..7791a771 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 a1f13c3a..4a3cd953 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 bac23ad6..b6bc09bf 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 467a49d1..5d88937d 100644 --- a/source/Irrlicht/BuiltInFont.h +++ b/source/Irrlicht/BuiltInFont.h @@ -5,8 +5,6 @@ #ifndef __BUILD_IN_FONT_H_INCLUDED__ #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 +14,6 @@ namespace irr { namespace gui { -#ifdef _IRR_COMPILE_WITH_BMP_LOADER_ const u8 BuiltInFontData[] = { 0x42, 0x4d, 0x4a, 0x20, 0x00, 0x00, 0x00, 0x00, @@ -1056,20 +1053,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 9d92e038..cea8ef29 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/CAttributes.h b/source/Irrlicht/CAttributes.h index 7156b8ee..3d881156 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 ca86a6a4..448030ba 100644 --- a/source/Irrlicht/CB3DMeshFileLoader.cpp +++ b/source/Irrlicht/CB3DMeshFileLoader.cpp @@ -6,9 +6,6 @@ // File format designed by Mark Sibly for the Blitz3D engine and has been // declared public domain -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_B3D_LOADER_ - #include "CB3DMeshFileLoader.h" #include "IVideoDriver.h" @@ -1055,7 +1052,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/CB3DMeshFileLoader.h b/source/Irrlicht/CB3DMeshFileLoader.h index 765405f7..d19f190e 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 aaca1680..ac68f77e 100644 --- a/source/Irrlicht/CB3DMeshWriter.cpp +++ b/source/Irrlicht/CB3DMeshWriter.cpp @@ -4,9 +4,6 @@ // TODO: replace printf's by logging messages -#include "IrrCompileConfig.h" - -#ifdef _IRR_COMPILE_WITH_B3D_WRITER_ #include "CB3DMeshWriter.h" #include "os.h" @@ -531,6 +528,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 a1464eb1..da90c3a1 100644 --- a/source/Irrlicht/CBillboardSceneNode.cpp +++ b/source/Irrlicht/CBillboardSceneNode.cpp @@ -2,8 +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_BILLBOARD_SCENENODE_ #include "CBillboardSceneNode.h" #include "IVideoDriver.h" #include "ISceneManager.h" @@ -281,5 +279,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 04ef8c7d..3d0f812b 100644 --- a/source/Irrlicht/CBoneSceneNode.cpp +++ b/source/Irrlicht/CBoneSceneNode.cpp @@ -2,9 +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_SKINNED_MESH_SUPPORT_ - #include "CBoneSceneNode.h" namespace irr @@ -98,6 +95,3 @@ void CBoneSceneNode::updateAbsolutePositionOfAllChildren() } // namespace scene } // namespace irr - -#endif - diff --git a/source/Irrlicht/CEAGLManager.h b/source/Irrlicht/CEAGLManager.h index c1f88455..65caa7aa 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 2d61bd2c..78e96c88 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 15d5410e..720b8bb5 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 45e8680c..ba4a332c 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" @@ -54,9 +53,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/CGLXManager.h b/source/Irrlicht/CGLXManager.h index 85c3c94d..9e4ce74e 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.cpp b/source/Irrlicht/CGUIButton.cpp index 704fd3d2..d6ab543d 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 9bd86122..0e429573 100644 --- a/source/Irrlicht/CGUIButton.h +++ b/source/Irrlicht/CGUIButton.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_BUTTON_H_INCLUDED__ #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 +241,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 48ec5e8a..6c5271ff 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 adb46b41..8319243e 100644 --- a/source/Irrlicht/CGUICheckBox.h +++ b/source/Irrlicht/CGUICheckBox.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_CHECKBOX_H_INCLUDED__ #define __C_GUI_CHECKBOX_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUICheckBox.h" namespace irr @@ -61,5 +58,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 b35b47a6..ecd3a9c2 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 dbdae41b..2dab66f1 100644 --- a/source/Irrlicht/CGUIComboBox.h +++ b/source/Irrlicht/CGUIComboBox.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_COMBO_BOX_H_INCLUDED__ #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 +104,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 a3851e60..cf4b64ee 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 b0b50706..4a1b6e8f 100644 --- a/source/Irrlicht/CGUIEditBox.h +++ b/source/Irrlicht/CGUIEditBox.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_EDIT_BOX_H_INCLUDED__ #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 +198,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 6d15706b..a7b28042 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" @@ -25,8 +23,9 @@ #include "CGUIComboBox.h" #include "IWriteFile.h" - +#ifdef IRR_ENABLE_BUILTIN_FONT #include "BuiltInFont.h" +#endif #include "os.h" namespace irr @@ -143,6 +142,7 @@ CGUIEnvironment::~CGUIEnvironment() void CGUIEnvironment::loadBuiltInFont() { +#ifdef IRR_ENABLE_BUILTIN_FONT io::IReadFile* file = FileSystem->createMemoryReadFile(BuiltInFontData, BuiltInFontDataSize, DefaultFontName, false); @@ -161,6 +161,7 @@ void CGUIEnvironment::loadBuiltInFont() Fonts.push_back(f); file->drop(); +#endif } @@ -1107,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 ab745865..f68b0daf 100644 --- a/source/Irrlicht/CGUIEnvironment.h +++ b/source/Irrlicht/CGUIEnvironment.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_ENVIRONMENT_H_INCLUDED__ #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 +228,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 6599bef5..e68d7cda 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 55b9ffa7..a1d633c4 100644 --- a/source/Irrlicht/CGUIFileOpenDialog.h +++ b/source/Irrlicht/CGUIFileOpenDialog.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_FILE_OPEN_DIALOG_H_INCLUDED__ #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 +87,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 1becf675..b7b6ed75 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 4cf93b89..449df086 100644 --- a/source/Irrlicht/CGUIFont.h +++ b/source/Irrlicht/CGUIFont.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_FONT_H_INCLUDED__ #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 +108,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 2d2a08cb..669428b9 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 581fe1b5..c8a46f26 100644 --- a/source/Irrlicht/CGUIImage.h +++ b/source/Irrlicht/CGUIImage.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_IMAGE_H_INCLUDED__ #define __C_GUI_IMAGE_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIImage.h" namespace irr @@ -102,6 +99,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 f6f0e778..b00c7e38 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 8e1566d6..a3e7255a 100644 --- a/source/Irrlicht/CGUIListBox.h +++ b/source/Irrlicht/CGUIListBox.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_LIST_BOX_H_INCLUDED__ #define __C_GUI_LIST_BOX_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIListBox.h" #include "irrArray.h" @@ -178,6 +175,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 6d6d3675..567251c6 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 170a2da0..d1d04b89 100644 --- a/source/Irrlicht/CGUIScrollBar.h +++ b/source/Irrlicht/CGUIScrollBar.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_SCROLL_BAR_H_INCLUDED__ #define __C_GUI_SCROLL_BAR_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIScrollBar.h" #include "IGUIButton.h" @@ -101,7 +98,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 08a59007..b417b720 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 11cfb26b..d6f8ef8f 100644 --- a/source/Irrlicht/CGUISkin.h +++ b/source/Irrlicht/CGUISkin.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_SKIN_H_INCLUDED__ #define __C_GUI_SKIN_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUISkin.h" #include "irrString.h" @@ -234,8 +231,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 c89bb26e..8f5fb673 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 cfca788f..affd6bfd 100644 --- a/source/Irrlicht/CGUISpriteBank.h +++ b/source/Irrlicht/CGUISpriteBank.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_SPRITE_BANK_H_INCLUDED__ #define __C_GUI_SPRITE_BANK_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUISpriteBank.h" namespace irr @@ -99,7 +96,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 b9ab35a9..29bbdb70 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 827e95ff..8e1babe9 100644 --- a/source/Irrlicht/CGUIStaticText.h +++ b/source/Irrlicht/CGUIStaticText.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_STATIC_TEXT_H_INCLUDED__ #define __C_GUI_STATIC_TEXT_H_INCLUDED__ -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_GUI_ - #include "IGUIStaticText.h" #include "irrArray.h" @@ -136,7 +133,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 30a31c39..c08a5799 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 d5e8315f..4c2a0549 100644 --- a/source/Irrlicht/CGUITabControl.h +++ b/source/Irrlicht/CGUITabControl.h @@ -5,9 +5,6 @@ #ifndef __C_GUI_TAB_CONTROL_H_INCLUDED__ #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 +181,4 @@ namespace gui } // end namespace gui } // end namespace irr -#endif // _IRR_COMPILE_WITH_GUI_ - #endif - diff --git a/source/Irrlicht/CImageLoaderBMP.cpp b/source/Irrlicht/CImageLoaderBMP.cpp index 234c5157..a913101a 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 5d993ce5..1f944032 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" @@ -15,9 +14,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 +55,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 +83,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 0d19d713..c7b5df20 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 146adbe8..03163941 100644 --- a/source/Irrlicht/CImageLoaderJPG.h +++ b/source/Irrlicht/CImageLoaderJPG.h @@ -5,19 +5,12 @@ #ifndef __C_IMAGE_LOADER_JPG_H_INCLUDED__ #define __C_IMAGE_LOADER_JPG_H_INCLUDED__ -#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 +41,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 +86,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 +94,3 @@ private: #endif -#endif - diff --git a/source/Irrlicht/CImageLoaderPNG.cpp b/source/Irrlicht/CImageLoaderPNG.cpp index b4680173..59709bfb 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 6e631b72..45a37fd3 100644 --- a/source/Irrlicht/CImageLoaderPNG.h +++ b/source/Irrlicht/CImageLoaderPNG.h @@ -9,9 +9,6 @@ #ifndef __C_IMAGE_LOADER_PNG_H_INCLUDED__ #define __C_IMAGE_LOADER_PNG_H_INCLUDED__ -#include "IrrCompileConfig.h" - -#ifdef _IRR_COMPILE_WITH_PNG_LOADER_ #include "IImageLoader.h" @@ -41,5 +38,3 @@ public: } // end namespace irr #endif -#endif - diff --git a/source/Irrlicht/CImageLoaderTGA.cpp b/source/Irrlicht/CImageLoaderTGA.cpp index af4fad55..3286bddd 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 d8f7368b..4e675793 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" @@ -15,8 +14,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 +43,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 +66,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 97a64b84..1fb9fb37 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 ec8a1b85..dd98e913 100644 --- a/source/Irrlicht/CImageWriterJPG.h +++ b/source/Irrlicht/CImageWriterJPG.h @@ -5,9 +5,6 @@ #ifndef _C_IMAGE_WRITER_JPG_H_INCLUDED__ #define _C_IMAGE_WRITER_JPG_H_INCLUDED__ -#include "IrrCompileConfig.h" - -#ifdef _IRR_COMPILE_WITH_JPG_WRITER_ #include "IImageWriter.h" @@ -33,5 +30,3 @@ public: } #endif // _C_IMAGE_WRITER_JPG_H_INCLUDED__ -#endif - diff --git a/source/Irrlicht/CImageWriterPNG.cpp b/source/Irrlicht/CImageWriterPNG.cpp index 55ae00ec..0e2a71ec 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 eec12ff0..181d0c50 100644 --- a/source/Irrlicht/CImageWriterPNG.h +++ b/source/Irrlicht/CImageWriterPNG.h @@ -5,9 +5,6 @@ #ifndef _C_IMAGE_WRITER_PNG_H_INCLUDED__ #define _C_IMAGE_WRITER_PNG_H_INCLUDED__ -#include "IrrCompileConfig.h" - -#ifdef _IRR_COMPILE_WITH_PNG_WRITER_ #include "IImageWriter.h" @@ -33,5 +30,3 @@ public: } // namespace irr #endif // _C_IMAGE_WRITER_PNG_H_INCLUDED__ -#endif - diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index ea50d7c7..2d8945c9 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 b8cdb42b..d1b2049e 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 e3b2a9ab..4069cf19 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 1af434b8..711cb564 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 7657718f..4dbb2e76 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 877a4bf3..92cda75d 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 { @@ -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); diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index ddff014b..1033f9ed 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 4af8d027..9ca44acc 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 d383c182..6130d275 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/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 208b5733..4d2ec7ec 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -1,11 +1,21 @@ option(BUILD_SHARED_LIBS "Build shared library" TRUE) +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) + set(API_IMPORT "__declspec(dllimport)") + set(API_EXPORT "__declspec(dllexport)") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + 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() @@ -56,46 +66,195 @@ 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") + 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(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) + option(USE_XINPUT2 "Use XInput2" TRUE) + option(USE_XCURSOR "Use XCursor" FALSE) +else() + set(USE_XINPUT2 FALSE) + set(USE_XCURSOR FALSE) +endif() + +# 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 +272,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() @@ -259,6 +418,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 @@ -303,9 +474,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_) +if(WIN32) + 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() set_target_properties(IrrlichtMt PROPERTIES diff --git a/source/Irrlicht/CNSOGLManager.h b/source/Irrlicht/CNSOGLManager.h index efe0b421..8744d16e 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/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 775a22c9..2cbd47cd 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) @@ -95,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); @@ -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 c4fee234..c4be102d 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -2,9 +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_OBJ_LOADER_ - #include "COBJMeshFileLoader.h" #include "IMeshManipulator.h" #include "IVideoDriver.h" @@ -612,6 +609,3 @@ void COBJMeshFileLoader::cleanUp() } // end namespace scene } // end namespace irr - -#endif // _IRR_COMPILE_WITH_OBJ_LOADER_ - diff --git a/source/Irrlicht/COGLES2Common.h b/source/Irrlicht/COGLES2Common.h index 2c844ce3..a69f6674 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 8d31ff63..eaf4d99f 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 2e81b373..73db08a8 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.cpp b/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp index 5b275d37..899dfd9a 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); diff --git a/source/Irrlicht/COGLES2FixedPipelineRenderer.h b/source/Irrlicht/COGLES2FixedPipelineRenderer.h index f5882f17..b50ef74e 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 9c4c2c9f..5483263e 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 25217580..1d69828b 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 a7b8eb3e..57e5b7bd 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 a5578447..ce6ea1d0 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 eb27f076..74280946 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 efed7939..bcc3278b 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 5af6f73e..b2f88611 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 f7d14c03..11c8a296 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 6f7b790f..52a0604a 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 5726e5f2..79b28007 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 6ec58227..fe86f955 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 6c542f5d..0dd08ebc 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 8897c585..c19215b8 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 34540368..c60d2ba8 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 960b7f6d..5d748d59 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 ed37e5d5..6d330561 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 b6a4f821..a870a6eb 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 80ca4332..81f8c811 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 6b0f254d..3d9648c6 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 664e672d..e22ddd59 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" @@ -15,27 +14,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 +79,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 +293,6 @@ IBillboardSceneNode* CSceneManager::addBillboardSceneNode(ISceneNode* parent, video::SColor colorTop, video::SColor colorBottom ) { -#ifdef _IRR_COMPILE_WITH_BILLBOARD_SCENENODE_ if (!parent) parent = this; @@ -325,9 +301,6 @@ IBillboardSceneNode* CSceneManager::addBillboardSceneNode(ISceneNode* parent, node->drop(); return node; -#else - return 0; -#endif } @@ -575,17 +548,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; } @@ -606,15 +568,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 @@ -676,9 +629,6 @@ void CSceneManager::drawAll() for (i=0; irender(); -#ifdef _IRR_SCENEMANAGER_DEBUG - Parameters->setAttribute("drawn_solid", (s32) SolidNodeList.size() ); -#endif SolidNodeList.set_used(0); } @@ -691,9 +641,6 @@ void CSceneManager::drawAll() for (i=0; irender(); -#ifdef _IRR_SCENEMANAGER_DEBUG - Parameters->setAttribute ( "drawn_transparent", (s32) TransparentNodeList.size() ); -#endif TransparentNodeList.set_used(0); } @@ -706,9 +653,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); } @@ -719,9 +664,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(); @@ -971,49 +914,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 9f47f3b6..f7cf1f05 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -2,9 +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_SKINNED_MESH_SUPPORT_ - #include "CSkinnedMesh.h" #include "CBoneSceneNode.h" #include "IAnimatedMeshSceneNode.h" @@ -1539,6 +1536,3 @@ void CSkinnedMesh::calculateTangents( } // end namespace scene } // end namespace irr - -#endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ - diff --git a/source/Irrlicht/CWGLManager.h b/source/Irrlicht/CWGLManager.h index bd750650..e2d15130 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 ce264322..73c5a21f 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 67ffaf75..9a78df3c 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 2de099fe..7603ec58 100644 --- a/source/Irrlicht/CXMeshFileLoader.cpp +++ b/source/Irrlicht/CXMeshFileLoader.cpp @@ -2,9 +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_X_LOADER_ #include "CXMeshFileLoader.h" #include "os.h" @@ -2359,6 +2356,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 d394313d..071f735b 100644 --- a/source/Irrlicht/CZipReader.cpp +++ b/source/Irrlicht/CZipReader.cpp @@ -7,16 +7,11 @@ #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 +459,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 +524,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 +549,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 458b6db4..6b16ab9d 100644 --- a/source/Irrlicht/CZipReader.h +++ b/source/Irrlicht/CZipReader.h @@ -5,9 +5,6 @@ #ifndef __C_ZIP_READER_H_INCLUDED__ #define __C_ZIP_READER_H_INCLUDED__ -#include "IrrCompileConfig.h" - -#ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ #include "IReadFile.h" #include "irrArray.h" @@ -226,6 +223,4 @@ namespace io } // end namespace io } // end namespace irr -#endif // __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ #endif // __C_ZIP_READER_H_INCLUDED__ - diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index 4438b51c..50348e7f 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 @@ -114,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 diff --git a/source/Irrlicht/SB3DStructs.h b/source/Irrlicht/SB3DStructs.h index 8f88a850..ddd8bd63 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 2b894bcd..6b386574 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 77012c28..c0aa83b0 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 21c61e99735045682e2b9b70180c9af5ca563b5c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 11 Mar 2023 15:12:05 +0100 Subject: [PATCH 040/123] Bump revision early --- CMakeLists.txt | 2 +- include/IrrCompileConfig.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a15d263f..c289434f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ else() cmake_policy(VERSION 3.9) endif() -set(IRRLICHTMT_REVISION 10) +set(IRRLICHTMT_REVISION 11) project(Irrlicht VERSION 1.9.0.${IRRLICHTMT_REVISION} diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 33361aa6..da3a6024 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -6,8 +6,8 @@ #define __IRR_COMPILE_CONFIG_H_INCLUDED__ //! Identifies the IrrlichtMt fork customized for the Minetest engine -#define IRRLICHT_VERSION_MT_REVISION 10 -#define IRRLICHT_VERSION_MT "mt10" +#define IRRLICHT_VERSION_MT_REVISION 11 +#define IRRLICHT_VERSION_MT "mt11" //! Irrlicht SDK Version #define IRRLICHT_VERSION_MAJOR 1 From 82d1feb93300196f2baea717d27bb3c92a39f3c7 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 18:17:47 +0300 Subject: [PATCH 041/123] 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 4a20f020..bcf99ac6 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 042/123] 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 50348e7f..ed6b0828 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 27ab1bad..9baefc29 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 043/123] 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 0141b2bb..6e9d646d 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 044/123] 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 41dc3d67..8d1706eb 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 045/123] 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 8d1706eb..f3d5f5c1 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 046/123] 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 f3d5f5c1..2cf7d603 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 047/123] 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 a57258d2..fa345cad 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 df8881898d08234920696e32f777ee31b7431386 Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 14 Mar 2023 18:48:34 +0300 Subject: [PATCH 048/123] Remove CIrrDeviceiOS --- source/Irrlicht/CEAGLManager.h | 86 ---- source/Irrlicht/CEAGLManager.mm | 273 ----------- source/Irrlicht/CIrrDeviceiOS.h | 76 --- source/Irrlicht/CIrrDeviceiOS.mm | 819 ------------------------------- source/Irrlicht/Irrlicht.cpp | 9 - 5 files changed, 1263 deletions(-) delete mode 100644 source/Irrlicht/CEAGLManager.h delete mode 100644 source/Irrlicht/CEAGLManager.mm delete mode 100644 source/Irrlicht/CIrrDeviceiOS.h delete mode 100644 source/Irrlicht/CIrrDeviceiOS.mm diff --git a/source/Irrlicht/CEAGLManager.h b/source/Irrlicht/CEAGLManager.h deleted file mode 100644 index 65caa7aa..00000000 --- a/source/Irrlicht/CEAGLManager.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#ifndef __C_EAGL_MANAGER_H_INCLUDED__ -#define __C_EAGL_MANAGER_H_INCLUDED__ - - -#ifdef _IRR_COMPILE_WITH_EAGL_MANAGER_ - -#include "SIrrCreationParameters.h" -#include "SExposedVideoData.h" -#include "IContextManager.h" - -namespace irr -{ -namespace video -{ - // EAGL manager. - class CEAGLManager : public IContextManager - { - public: - //! Constructor. - CEAGLManager(); - - //! Destructor. - virtual ~CEAGLManager(); - - // Initialize EAGL. - /* This method checks if a view has CAEAGLLayer and grabs it if it does, anyway surface and context - aren't create. */ - bool initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data); - - // Terminate EAGL. - /* Terminate EAGL context. This method break both existed surface and context. */ - void terminate(); - - // Create EAGL surface. - /* This method configure CAEAGLLayer. */ - bool generateSurface(); - - // Destroy EAGL surface. - /* This method reset CAEAGLLayer states. */ - void destroySurface(); - - // Create EAGL context. - /* This method create and activate EAGL context. */ - bool generateContext(); - - // Destroy EAGL context. - /* This method destroy EAGL context. */ - void destroyContext(); - - const SExposedVideoData& getContext() const; - - bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero); - - // Swap buffers. - bool swapBuffers(); - - private: - SIrrlichtCreationParameters Params; - SExposedVideoData Data; - - bool Configured; - - void* DataStorage; - - struct SFrameBuffer - { - SFrameBuffer() : BufferID(0), ColorBuffer(0), DepthBuffer(0) - { - } - - u32 BufferID; - u32 ColorBuffer; - u32 DepthBuffer; - }; - - SFrameBuffer FrameBuffer; - }; -} -} - -#endif -#endif diff --git a/source/Irrlicht/CEAGLManager.mm b/source/Irrlicht/CEAGLManager.mm deleted file mode 100644 index 931f92a4..00000000 --- a/source/Irrlicht/CEAGLManager.mm +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (C) 2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#include "CEAGLManager.h" - -#ifdef _IRR_COMPILE_WITH_EAGL_MANAGER_ - -#include "irrString.h" -#include "os.h" - -#import -#import - -#if defined(_IRR_COMPILE_WITH_OGLES1_) -#include -#include -#elif defined(_IRR_COMPILE_WITH_OGLES2_) -#include -#include -#endif - -namespace irr -{ -namespace video -{ - -struct SEAGLManagerDataStorage -{ - SEAGLManagerDataStorage() : Layer(0), Context(0) - { - } - - CAEAGLLayer* Layer; - EAGLContext* Context; -}; - -CEAGLManager::CEAGLManager() : IContextManager(), Configured(false), DataStorage(0) -{ -#ifdef _DEBUG - setDebugName("CEAGLManager"); -#endif - - DataStorage = new SEAGLManagerDataStorage(); -} - -CEAGLManager::~CEAGLManager() -{ - destroyContext(); - destroySurface(); - terminate(); - - delete static_cast(DataStorage); -} - -bool CEAGLManager::initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data) -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - if (dataStorage->Layer != nil) - return true; - - Params = params; - Data = data; - - UIView* view = (__bridge UIView*)data.OpenGLiOS.View; - - if (view == nil || ![[view layer] isKindOfClass:[CAEAGLLayer class]]) - { - os::Printer::log("Could not get EAGL display."); - return false; - } - - dataStorage->Layer = (CAEAGLLayer*)[view layer]; - - return true; -} - -void CEAGLManager::terminate() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - [EAGLContext setCurrentContext:0]; - - destroySurface(); - - if (dataStorage->Layer != nil) - dataStorage->Layer = 0; -} - -bool CEAGLManager::generateSurface() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - CAEAGLLayer* layer = dataStorage->Layer; - - if (layer == nil) - return false; - - if (Configured) - return true; - - NSDictionary* attribs = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:NO], - kEAGLDrawablePropertyRetainedBacking, - (Params.Bits > 16) ? kEAGLColorFormatRGBA8 : kEAGLColorFormatRGB565, - kEAGLDrawablePropertyColorFormat, - nil]; - - [layer setOpaque:(Params.WithAlphaChannel) ? YES : NO]; - [layer setDrawableProperties:attribs]; - - Configured = true; - - return true; -} - -void CEAGLManager::destroySurface() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - CAEAGLLayer* layer = dataStorage->Layer; - - if (layer == nil) - return; - - [layer setOpaque:NO]; - [layer setDrawableProperties:nil]; - - Configured = false; -} - -bool CEAGLManager::generateContext() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - if (dataStorage->Context != nil || !Configured) - return false; - - EAGLRenderingAPI OpenGLESVersion = kEAGLRenderingAPIOpenGLES2; - - switch (Params.DriverType) - { - case EDT_OGLES1: - OpenGLESVersion = kEAGLRenderingAPIOpenGLES1; - break; - case EDT_OGLES2: - OpenGLESVersion = kEAGLRenderingAPIOpenGLES2; - break; - default: - break; - } - - dataStorage->Context = [[EAGLContext alloc] initWithAPI:OpenGLESVersion]; - - if (dataStorage->Context == nil) - { - os::Printer::log("Could not create EAGL context.", ELL_ERROR); - return false; - } - - Data.OpenGLiOS.Context = (__bridge void*)dataStorage->Context; - - os::Printer::log("EAGL context created with OpenGLESVersion: ", core::stringc(static_cast(OpenGLESVersion)), ELL_DEBUG); - - return true; -} - -void CEAGLManager::destroyContext() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - [dataStorage->Context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:nil]; - - if (FrameBuffer.BufferID != 0) - { - glDeleteFramebuffersOES(1, &FrameBuffer.BufferID); - FrameBuffer.BufferID = 0; - } - - if (FrameBuffer.ColorBuffer != 0) - { - glDeleteRenderbuffersOES(1, &FrameBuffer.ColorBuffer); - FrameBuffer.ColorBuffer = 0; - } - - if (FrameBuffer.DepthBuffer != 0) - { - glDeleteRenderbuffersOES(1, &FrameBuffer.DepthBuffer); - FrameBuffer.DepthBuffer = 0; - } - - [EAGLContext setCurrentContext:0]; - - if (dataStorage->Context != nil) - dataStorage->Context = 0; - - Data.OpenGLiOS.Context = 0; -} - -bool CEAGLManager::activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero) -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - EAGLContext* context = dataStorage->Context; - - bool status = false; - - if (context != nil) - { - status = ([EAGLContext currentContext] == context || [EAGLContext setCurrentContext:context]); - } - - if (status) - { - if (FrameBuffer.ColorBuffer == 0) - { - glGenRenderbuffersOES(1, &FrameBuffer.ColorBuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer); - [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:dataStorage->Layer]; - } - - if (FrameBuffer.DepthBuffer == 0) - { - GLenum depth = (Params.ZBufferBits >= 24) ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16_OES; - - glGenRenderbuffersOES(1, &FrameBuffer.DepthBuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.DepthBuffer); - glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depth, Params.WindowSize.Width, Params.WindowSize.Height); - } - - if (FrameBuffer.BufferID == 0) - { - glGenFramebuffersOES(1, &FrameBuffer.BufferID); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, FrameBuffer.BufferID); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, FrameBuffer.DepthBuffer); - } - - glBindFramebufferOES(GL_FRAMEBUFFER_OES, FrameBuffer.BufferID); - } - else - { - os::Printer::log("Could not make EGL context current."); - } - - return status; -} - -const SExposedVideoData& CEAGLManager::getContext() const -{ - return Data; -} - -bool CEAGLManager::swapBuffers() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - EAGLContext* context = dataStorage->Context; - - bool status = false; - - if (context != nil && context == [EAGLContext currentContext]) - { - glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer); - [context presentRenderbuffer:GL_RENDERBUFFER_OES]; - - status = true; - } - - return status; -} - -} -} - -#endif diff --git a/source/Irrlicht/CIrrDeviceiOS.h b/source/Irrlicht/CIrrDeviceiOS.h deleted file mode 100644 index 6130d275..00000000 --- a/source/Irrlicht/CIrrDeviceiOS.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2002-2008 Nikolaus Gebhardt -// Copyright (C) 2008 Redshift Software, Inc. -// Copyright (C) 2012-2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_IRR_DEVICE_IOS_H_INCLUDED__ -#define __C_IRR_DEVICE_IOS_H_INCLUDED__ - - -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ - -#include "CIrrDeviceStub.h" -#include "IrrlichtDevice.h" - -namespace irr -{ - - class CIrrDeviceiOS : public CIrrDeviceStub - { - public: - CIrrDeviceiOS(const SIrrlichtCreationParameters& params); - virtual ~CIrrDeviceiOS(); - - bool run() override; - void yield() override; - void sleep(u32 timeMs, bool pauseTimer) override; - - void setWindowCaption(const wchar_t* text) override; - - bool isWindowActive() const override; - bool isWindowFocused() const override; - bool isWindowMinimized() const override; - - void closeDevice() override; - - void setResizable(bool resize = false) override; - - void minimizeWindow() override; - void maximizeWindow() override; - void restoreWindow() override; - - core::position2di getWindowPosition() override; - - bool activateAccelerometer(float updateInterval = 0.016666f) override; - bool deactivateAccelerometer() override; - bool isAccelerometerActive() override; - bool isAccelerometerAvailable() override; - bool activateGyroscope(float updateInterval = 0.016666f) override; - bool deactivateGyroscope() override; - bool isGyroscopeActive() override; - bool isGyroscopeAvailable() override; - bool activateDeviceMotion(float updateInterval = 0.016666f) override; - bool deactivateDeviceMotion() override; - bool isDeviceMotionActive() override; - bool isDeviceMotionAvailable() override; - - E_DEVICE_TYPE getType() const override; - - private: - void createWindow(); - void createViewAndDriver(); - - void* DataStorage; - - bool Close; - }; - -} - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ -extern void irrlicht_main(); -#endif - -#endif -#endif diff --git a/source/Irrlicht/CIrrDeviceiOS.mm b/source/Irrlicht/CIrrDeviceiOS.mm deleted file mode 100644 index 3a0575d3..00000000 --- a/source/Irrlicht/CIrrDeviceiOS.mm +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright (C) 2002-2008 Nikolaus Gebhardt -// Copyright (C) 2008 Redshift Software, Inc. -// Copyright (C) 2012 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#import "CIrrDeviceiOS.h" - -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ - -#include "IFileSystem.h" -#include "CTimer.h" -#include "CEAGLManager.h" - -#import -#import - -/* Important information */ - -// The application state events and following methods: IrrlichtDevice::isWindowActive, IrrlichtDevice::isWindowFocused -// and 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 -// handle all application events yourself. - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - -namespace irr -{ - class CIrrDeviceiOS; -} - -/* CIrrDelegateiOS */ - -@interface CIrrDelegateiOS : NSObject - -- (void)setDevice:(irr::CIrrDeviceiOS*)device; -- (bool)isActive; -- (bool)hasFocus; - -@property (strong, nonatomic) UIWindow* window; - -@end - -@implementation CIrrDelegateiOS -{ - irr::CIrrDeviceiOS* Device; - bool Active; - bool Focus; -} - -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)options -{ - Device = nil; - Active = true; - Focus = false; - - [self performSelectorOnMainThread:@selector(runIrrlicht) withObject:nil waitUntilDone:NO]; - - return YES; -} - -- (void)applicationWillTerminate:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_WILL_TERMINATE; - - Device->postEventFromUser(ev); - - Device->closeDevice(); - } -} - -- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_MEMORY_WARNING; - - Device->postEventFromUser(ev); - } -} - -- (void)applicationWillResignActive:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_WILL_PAUSE; - - Device->postEventFromUser(ev); - } - - Focus = false; -} - -- (void)applicationDidEnterBackground:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_DID_PAUSE; - - Device->postEventFromUser(ev); - } - - Active = false; -} - -- (void)applicationWillEnterForeground:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_WILL_RESUME; - - Device->postEventFromUser(ev); - } - - Active = true; -} - -- (void)applicationDidBecomeActive:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_DID_RESUME; - - Device->postEventFromUser(ev); - } - - Focus = true; -} - -- (void)runIrrlicht -{ - irrlicht_main(); -} - -- (void)setDevice:(irr::CIrrDeviceiOS*)device -{ - Device = device; -} - -- (bool)isActive -{ - return Active; -} - -- (bool)hasFocus -{ - return Focus; -} - -@end - -#endif - -/* CIrrViewiOS */ - -@interface CIrrViewiOS : UIView - -- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device; - -@end - -@implementation CIrrViewiOS -{ - irr::CIrrDeviceiOS* Device; - float Scale; -} - -- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device; -{ - self = [super initWithFrame:frame]; - - if (self) - { - Device = device; - Scale = ([self respondsToSelector:@selector(setContentScaleFactor:)]) ? [[UIScreen mainScreen] scale] : 1.f; - } - - return self; -} - -- (BOOL)isMultipleTouchEnabled -{ - return YES; -} - -- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_PRESSED_DOWN; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_MOVED; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_LEFT_UP; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_LEFT_UP; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -@end - -/* CIrrViewEAGLiOS */ - -@interface CIrrViewEAGLiOS : CIrrViewiOS - -@end - -@implementation CIrrViewEAGLiOS - -+ (Class)layerClass -{ - return [CAEAGLLayer class]; -} - -@end - -namespace irr -{ - namespace video - { - IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - - IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - } - - struct SIrrDeviceiOSDataStorage - { - SIrrDeviceiOSDataStorage() : Window(0), ViewController(0), View(0), MotionManager(0), ReferenceAttitude(0) - { - MotionManager = [[CMMotionManager alloc] init]; - } - - UIWindow* Window; - UIViewController* ViewController; - CIrrViewiOS* View; - CMMotionManager* MotionManager; - CMAttitude* ReferenceAttitude; - }; - - CIrrDeviceiOS::CIrrDeviceiOS(const SIrrlichtCreationParameters& params) : CIrrDeviceStub(params), DataStorage(0), Close(false) - { -#ifdef _DEBUG - setDebugName("CIrrDeviceiOS"); -#endif - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - [delegate setDevice:this]; -#endif - - DataStorage = new SIrrDeviceiOSDataStorage(); - - FileSystem->changeWorkingDirectoryTo([[[NSBundle mainBundle] resourcePath] UTF8String]); - - createWindow(); - createViewAndDriver(); - - if (!VideoDriver) - return; - - createGUIAndScene(); - } - - CIrrDeviceiOS::~CIrrDeviceiOS() - { - deactivateDeviceMotion(); - deactivateGyroscope(); - deactivateAccelerometer(); - - delete static_cast(DataStorage); - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - [delegate setDevice:nil]; -#endif - } - - bool CIrrDeviceiOS::run() - { - if (!Close) - { - const CFTimeInterval timeInSeconds = 0.000002; - - s32 result = 0; - - do - { - result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeInSeconds, TRUE); - } - while (result == kCFRunLoopRunHandledSource); - - os::Timer::tick(); - - //! Update events - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - //! Accelerometer - if (motionManager.isAccelerometerActive) - { - irr::SEvent ev; - ev.EventType = irr::EET_ACCELEROMETER_EVENT; - ev.AccelerometerEvent.X = motionManager.accelerometerData.acceleration.x; - ev.AccelerometerEvent.Y = motionManager.accelerometerData.acceleration.y; - ev.AccelerometerEvent.Z = motionManager.accelerometerData.acceleration.z; - - postEventFromUser(ev); - } - - //! Gyroscope - if (motionManager.isGyroActive) - { - irr::SEvent ev; - ev.EventType = irr::EET_GYROSCOPE_EVENT; - ev.GyroscopeEvent.X = motionManager.gyroData.rotationRate.x; - ev.GyroscopeEvent.Y = motionManager.gyroData.rotationRate.y; - ev.GyroscopeEvent.Z = motionManager.gyroData.rotationRate.z; - - postEventFromUser(ev); - } - - //! Device Motion - if (motionManager.isDeviceMotionActive) - { - CMAttitude* currentAttitude = motionManager.deviceMotion.attitude; - CMAttitude* referenceAttitude = dataStorage->ReferenceAttitude; - - if (referenceAttitude != nil) - [currentAttitude multiplyByInverseOfAttitude: referenceAttitude]; - else - referenceAttitude = motionManager.deviceMotion.attitude; - - irr::SEvent ev; - ev.EventType = irr::EET_DEVICE_MOTION_EVENT; - ev.AccelerometerEvent.X = currentAttitude.roll; - ev.AccelerometerEvent.Y = currentAttitude.pitch; - ev.AccelerometerEvent.Z = currentAttitude.yaw; - - postEventFromUser(ev); - } - } - - return !Close; - } - - void CIrrDeviceiOS::yield() - { - struct timespec ts = {0,0}; - nanosleep(&ts, NULL); - } - - void CIrrDeviceiOS::sleep(u32 timeMs, bool pauseTimer=false) - { - bool wasStopped = Timer ? Timer->isStopped() : true; - - struct timespec ts; - ts.tv_sec = (time_t) (timeMs / 1000); - ts.tv_nsec = (long) (timeMs % 1000) * 1000000; - - if (pauseTimer && !wasStopped) - Timer->stop(); - - nanosleep(&ts, NULL); - - if (pauseTimer && !wasStopped) - Timer->start(); - } - - void CIrrDeviceiOS::setWindowCaption(const wchar_t* text) - { - } - - bool CIrrDeviceiOS::isWindowActive() const - { -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - - return [delegate isActive]; -#else - return false; -#endif - } - - bool CIrrDeviceiOS::isWindowFocused() const - { -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - - return [delegate hasFocus]; -#else - return false; -#endif - } - - bool CIrrDeviceiOS::isWindowMinimized() const - { -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - - return ![delegate isActive]; -#else - return false; -#endif - } - - void CIrrDeviceiOS::closeDevice() - { - CFRunLoopStop(CFRunLoopGetMain()); - - Close = true; - } - - void CIrrDeviceiOS::setResizable(bool resize) - { - } - - void CIrrDeviceiOS::minimizeWindow() - { - } - - void CIrrDeviceiOS::maximizeWindow() - { - } - - void CIrrDeviceiOS::restoreWindow() - { - } - - core::position2di CIrrDeviceiOS::getWindowPosition() - { - return core::position2di(0, 0); - } - - bool CIrrDeviceiOS::activateAccelerometer(float updateInterval) - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isAccelerometerAvailable) - { - if (!motionManager.isAccelerometerActive) - { - motionManager.accelerometerUpdateInterval = updateInterval; - [motionManager startAccelerometerUpdates]; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::deactivateAccelerometer() - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isAccelerometerAvailable) - { - if (motionManager.isAccelerometerActive) - [motionManager stopAccelerometerUpdates]; - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::isAccelerometerActive() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isAccelerometerActive); - } - - bool CIrrDeviceiOS::isAccelerometerAvailable() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isAccelerometerAvailable); - } - - bool CIrrDeviceiOS::activateGyroscope(float updateInterval) - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isGyroAvailable) - { - if (!motionManager.isGyroActive) - { - motionManager.gyroUpdateInterval = updateInterval; - [motionManager startGyroUpdates]; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::deactivateGyroscope() - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isGyroAvailable) - { - if (motionManager.isGyroActive) - [motionManager stopGyroUpdates]; - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::isGyroscopeActive() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isGyroActive); - } - - bool CIrrDeviceiOS::isGyroscopeAvailable() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isGyroAvailable); - } - - bool CIrrDeviceiOS::activateDeviceMotion(float updateInterval) - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isDeviceMotionAvailable) - { - if (!motionManager.isDeviceMotionActive) - { - dataStorage->ReferenceAttitude = nil; - - motionManager.deviceMotionUpdateInterval = updateInterval; - [motionManager startDeviceMotionUpdates]; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::deactivateDeviceMotion() - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isDeviceMotionAvailable) - { - if (motionManager.isDeviceMotionActive) - { - [motionManager stopDeviceMotionUpdates]; - - dataStorage->ReferenceAttitude = nil; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::isDeviceMotionActive() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isDeviceMotionActive); - } - - bool CIrrDeviceiOS::isDeviceMotionAvailable() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isDeviceMotionAvailable); - } - - E_DEVICE_TYPE CIrrDeviceiOS::getType() const - { - return EIDT_IOS; - } - - void CIrrDeviceiOS::createWindow() - { - if (CreationParams.DriverType != video::EDT_NULL) - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - UIView* externalView = (__bridge UIView*)CreationParams.WindowId; - - if (externalView == nil) - { - dataStorage->Window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - dataStorage->ViewController = [[UIViewController alloc] init]; - dataStorage->Window.rootViewController = dataStorage->ViewController; - - [dataStorage->Window makeKeyAndVisible]; - } - else - { - dataStorage->Window = externalView.window; - - UIResponder* currentResponder = externalView.nextResponder; - - do - { - if ([currentResponder isKindOfClass:[UIViewController class]]) - { - dataStorage->ViewController = (UIViewController*)currentResponder; - - currentResponder = nil; - } - else if ([currentResponder isKindOfClass:[UIView class]]) - { - currentResponder = currentResponder.nextResponder; - } - else - { - currentResponder = nil; - - // Could not find view controller. - _IRR_DEBUG_BREAK_IF(true); - } - } - while (currentResponder != nil); - } - } - } - - void CIrrDeviceiOS::createViewAndDriver() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - video::SExposedVideoData data; - data.OpenGLiOS.Window = (__bridge void*)dataStorage->Window; - data.OpenGLiOS.ViewController = (__bridge void*)dataStorage->ViewController; - - UIView* externalView = (__bridge UIView*)CreationParams.WindowId; - - CGRect resolution = (externalView == nil) ? [[UIScreen mainScreen] bounds] : externalView.bounds; - - switch (CreationParams.DriverType) - { - case video::EDT_OGLES1: -#ifdef _IRR_COMPILE_WITH_OGLES1_ - { - CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this]; - CreationParams.WindowSize = core::dimension2d(view.frame.size.width, view.frame.size.height); - - dataStorage->View = view; - data.OpenGLiOS.View = (__bridge void*)view; - - ContextManager = new video::CEAGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); - - if (!VideoDriver) - os::Printer::log("Could not create OpenGL ES 1.x driver.", ELL_ERROR); - } -#else - os::Printer::log("No OpenGL ES 1.x support compiled in.", ELL_ERROR); -#endif - break; - - case video::EDT_OGLES2: -#ifdef _IRR_COMPILE_WITH_OGLES2_ - { - CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this]; - CreationParams.WindowSize = core::dimension2d(view.frame.size.width, view.frame.size.height); - - dataStorage->View = view; - data.OpenGLiOS.View = (__bridge void*)view; - - ContextManager = new video::CEAGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); - - if (!VideoDriver) - os::Printer::log("Could not create OpenGL ES 2.x driver.", ELL_ERROR); - } -#else - os::Printer::log("No OpenGL ES 2.x support compiled in.", ELL_ERROR); -#endif - break; - - case video::EDT_SOFTWARE: - case video::EDT_BURNINGSVIDEO: - case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS: - case video::EDT_DIRECT3D9: - case video::EDT_OPENGL: - os::Printer::log("This driver is not available in iOS. Try OpenGL ES.", ELL_ERROR); - 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; - } - - if (externalView == nil) - dataStorage->ViewController.view = dataStorage->View; - else - [externalView addSubview:dataStorage->View]; - } -} - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ -int main(int argc, char** argv) -{ - int result = UIApplicationMain(argc, argv, 0, NSStringFromClass([CIrrDelegateiOS class])); - - return result; -} -#endif - -#endif diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index 50348e7f..e598ec35 100644 --- a/source/Irrlicht/Irrlicht.cpp +++ b/source/Irrlicht/Irrlicht.cpp @@ -29,10 +29,6 @@ static const char* const copyright = "Irrlicht Engine (c) 2002-2017 Nikolaus Geb #include "CIrrDeviceSDL.h" #endif -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ -#include "CIrrDeviceiOS.h" -#endif - #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ #include "Android/CIrrDeviceAndroid.h" #endif @@ -78,11 +74,6 @@ namespace irr if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST)) dev = new CIrrDeviceLinux(params); #endif - -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ - if (params.DeviceType == EIDT_IOS || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceiOS(params); -#endif #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST)) From 25a7074c9af510b6d93d8e84309997e45bad094f Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 14 Mar 2023 18:48:55 +0300 Subject: [PATCH 049/123] Remove all mentions of iOS --- include/EDeviceTypes.h | 4 ---- include/SExposedVideoData.h | 16 ---------------- include/SIrrCreationParameters.h | 1 - source/Irrlicht/CFileSystem.cpp | 2 +- source/Irrlicht/CMakeLists.txt | 26 ++++++-------------------- source/Irrlicht/os.cpp | 2 +- 6 files changed, 8 insertions(+), 43 deletions(-) diff --git a/include/EDeviceTypes.h b/include/EDeviceTypes.h index a0c1ca7c..853e825e 100644 --- a/include/EDeviceTypes.h +++ b/include/EDeviceTypes.h @@ -24,10 +24,6 @@ namespace irr //! A device native to Mac OSX /** This device uses Apple's Cocoa API and works in Mac OSX 10.2 and above. */ EIDT_OSX, - - //! A device native to the iOS - /** This device should be used with the OpenGL-ES driver. */ - EIDT_IOS, //! A device which uses Simple DirectMedia Layer /** The SDL device works under all platforms supported by SDL but first must be compiled diff --git a/include/SExposedVideoData.h b/include/SExposedVideoData.h index ba47f1ec..5e86562b 100644 --- a/include/SExposedVideoData.h +++ b/include/SExposedVideoData.h @@ -78,21 +78,6 @@ struct SExposedVideoData //! The EGLNativeWindowType object. void* Window; }; - - struct SOpenGLiOS - { - //! The EAGLContext object. - void* Context; - - //! The subview UIView object where the drawing happens. - void* View; - - //! The UIViewController object. - void* ViewController; - - //! The UIWindow object. - void* Window; - }; struct SOGLESAndroid { @@ -107,7 +92,6 @@ struct SExposedVideoData SOpenGLLinux OpenGLLinux; SOpenGLOSX OpenGLOSX; SOpenGLFB OpenGLFB; - SOpenGLiOS OpenGLiOS; SOGLESAndroid OGLESAndroid; }; }; diff --git a/include/SIrrCreationParameters.h b/include/SIrrCreationParameters.h index bad56e3d..5c1f8da9 100644 --- a/include/SIrrCreationParameters.h +++ b/include/SIrrCreationParameters.h @@ -235,7 +235,6 @@ namespace irr /** If this is set to a value other than 0, the Irrlicht Engine will be created in an already existing window. For Windows, set this to the HWND of the window you want. - For iOS, assign UIView to this variable. The windowSize and FullScreen options will be ignored when using the WindowId parameter. Default this is set to 0. To make Irrlicht run inside the custom window, you still will diff --git a/source/Irrlicht/CFileSystem.cpp b/source/Irrlicht/CFileSystem.cpp index ba4a332c..3ee35d9b 100644 --- a/source/Irrlicht/CFileSystem.cpp +++ b/source/Irrlicht/CFileSystem.cpp @@ -24,7 +24,7 @@ #include // for _chdir #include // for _access #include -#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)) +#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_)) #include #include #include diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 4d2ec7ec..e993ace1 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -77,23 +77,13 @@ add_definitions( 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) +elseif(APPLE) add_definitions(-D_IRR_OSX_PLATFORM_) set(DEVICE "OSX") elseif(ANDROID) @@ -150,26 +140,26 @@ endif() # OpenGL -if(IOS OR ANDROID OR EMSCRIPTEN) +if(ANDROID OR EMSCRIPTEN) set(ENABLE_OPENGL FALSE) else() option(ENABLE_OPENGL "Enable OpenGL" TRUE) endif() -if(EMSCRIPTEN OR OSX) +if(EMSCRIPTEN OR APPLE) set(ENABLE_GLES1 FALSE) else() - if(ANDROID OR IOS) + if(ANDROID) set(DEFAULT_GLES1 TRUE) endif() option(ENABLE_GLES1 "Enable OpenGL ES" ${DEFAULT_GLES1}) endif() -if(OSX) +if(APPLE) set(ENABLE_GLES2 FALSE) set(ENABLE_WEBGL1 FALSE) else() - if(ANDROID OR IOS OR EMSCRIPTEN) + if(ANDROID OR EMSCRIPTEN) set(DEFAULT_GLES2 TRUE) endif() if(EMSCRIPTEN) @@ -199,8 +189,6 @@ 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() @@ -208,8 +196,6 @@ 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() diff --git a/source/Irrlicht/os.cpp b/source/Irrlicht/os.cpp index 6b386574..cdd1a26c 100644 --- a/source/Irrlicht/os.cpp +++ b/source/Irrlicht/os.cpp @@ -17,7 +17,7 @@ #define bswap_32(X) _byteswap_ulong(X) #define bswap_64(X) _byteswap_uint64(X) #define localtime _localtime_s -#elif defined(_IRR_OSX_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) +#elif defined(_IRR_OSX_PLATFORM_) #include #define bswap_16(X) OSReadSwapInt16(&X,0) #define bswap_32(X) OSReadSwapInt32(&X,0) From 5a1565072abeecf9fc5a3ffc450d5ab8ff660021 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 13 Mar 2023 22:28:09 +0300 Subject: [PATCH 050/123] Drop unused dependency on FileSystem in mesh loaders --- source/Irrlicht/COBJMeshFileLoader.cpp | 10 ++-------- source/Irrlicht/COBJMeshFileLoader.h | 4 +--- source/Irrlicht/CSceneManager.cpp | 4 ++-- source/Irrlicht/CXMeshFileLoader.cpp | 3 +-- source/Irrlicht/CXMeshFileLoader.h | 3 +-- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index c4be102d..740f8e5f 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -24,23 +24,18 @@ namespace scene #endif //! Constructor -COBJMeshFileLoader::COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs) -: SceneManager(smgr), FileSystem(fs) +COBJMeshFileLoader::COBJMeshFileLoader(scene::ISceneManager* smgr) +: SceneManager(smgr) { #ifdef _DEBUG setDebugName("COBJMeshFileLoader"); #endif - - if (FileSystem) - FileSystem->grab(); } //! destructor COBJMeshFileLoader::~COBJMeshFileLoader() { - if (FileSystem) - FileSystem->drop(); } @@ -76,7 +71,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) u32 smoothingGroup=0; const io::path fullName = file->getFileName(); - const io::path relPath = FileSystem->getFileDir(fullName)+"/"; c8* buf = new c8[filesize]; memset(buf, 0, filesize); diff --git a/source/Irrlicht/COBJMeshFileLoader.h b/source/Irrlicht/COBJMeshFileLoader.h index c03197a7..c706a5d6 100644 --- a/source/Irrlicht/COBJMeshFileLoader.h +++ b/source/Irrlicht/COBJMeshFileLoader.h @@ -7,7 +7,6 @@ #include #include "IMeshLoader.h" -#include "IFileSystem.h" #include "ISceneManager.h" #include "irrString.h" #include "SMeshBuffer.h" @@ -23,7 +22,7 @@ class COBJMeshFileLoader : public IMeshLoader public: //! Constructor - COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs); + COBJMeshFileLoader(scene::ISceneManager* smgr); //! destructor virtual ~COBJMeshFileLoader(); @@ -104,7 +103,6 @@ private: void cleanUp(); scene::ISceneManager* SceneManager; - io::IFileSystem* FileSystem; core::array Materials; }; diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index e22ddd59..440a44dd 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -79,8 +79,8 @@ 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. - MeshLoaderList.push_back(new CXMeshFileLoader(this, FileSystem)); - MeshLoaderList.push_back(new COBJMeshFileLoader(this, FileSystem)); + MeshLoaderList.push_back(new CXMeshFileLoader(this)); + MeshLoaderList.push_back(new COBJMeshFileLoader(this)); MeshLoaderList.push_back(new CB3DMeshFileLoader(this)); } diff --git a/source/Irrlicht/CXMeshFileLoader.cpp b/source/Irrlicht/CXMeshFileLoader.cpp index 7603ec58..2a365ac1 100644 --- a/source/Irrlicht/CXMeshFileLoader.cpp +++ b/source/Irrlicht/CXMeshFileLoader.cpp @@ -10,7 +10,6 @@ #include "coreutil.h" #include "ISceneManager.h" #include "IVideoDriver.h" -#include "IFileSystem.h" #include "IReadFile.h" #ifdef _DEBUG @@ -24,7 +23,7 @@ namespace scene { //! Constructor -CXMeshFileLoader::CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs) +CXMeshFileLoader::CXMeshFileLoader(scene::ISceneManager* smgr) : AnimatedMesh(0), Buffer(0), P(0), End(0), BinaryNumCount(0), Line(0), CurFrame(0), MajorVersion(0), MinorVersion(0), BinaryFormat(false), FloatSize(0) { diff --git a/source/Irrlicht/CXMeshFileLoader.h b/source/Irrlicht/CXMeshFileLoader.h index cfedfd04..ca934a88 100644 --- a/source/Irrlicht/CXMeshFileLoader.h +++ b/source/Irrlicht/CXMeshFileLoader.h @@ -14,7 +14,6 @@ namespace irr { namespace io { - class IFileSystem; class IReadFile; } // end namespace io namespace scene @@ -27,7 +26,7 @@ class CXMeshFileLoader : public IMeshLoader public: //! Constructor - CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs); + CXMeshFileLoader(scene::ISceneManager* smgr); //! returns true if the file maybe is able to be loaded by this class //! based on the file extension (e.g. ".cob") From 0160cdc51d020d590b7275178872ec93564dc857 Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 14 Mar 2023 18:25:05 +0300 Subject: [PATCH 051/123] Drop unused dependency of SceneManager on GUIEnvironment --- include/ISceneManager.h | 5 ----- source/Irrlicht/CIrrDeviceStub.cpp | 2 +- source/Irrlicht/CIrrDeviceStub.h | 3 +-- source/Irrlicht/CSceneManager.cpp | 24 +++++------------------- source/Irrlicht/CSceneManager.h | 9 +-------- 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/include/ISceneManager.h b/include/ISceneManager.h index 660d0aa8..60d2d49c 100644 --- a/include/ISceneManager.h +++ b/include/ISceneManager.h @@ -345,11 +345,6 @@ namespace scene This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ virtual video::IVideoDriver* getVideoDriver() = 0; - //! Get the active GUIEnvironment - /** \return Pointer to the GUIEnvironment - This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ - virtual gui::IGUIEnvironment* getGUIEnvironment() = 0; - //! Get the active FileSystem /** \return Pointer to the FileSystem This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index 92cda75d..69906737 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -92,7 +92,7 @@ void CIrrDeviceStub::createGUIAndScene() GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator); // create Scene manager - SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl, GUIEnvironment); + SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl); setEventReceiver(UserReceiver); } diff --git a/source/Irrlicht/CIrrDeviceStub.h b/source/Irrlicht/CIrrDeviceStub.h index 5b7d92ff..fd069b1a 100644 --- a/source/Irrlicht/CIrrDeviceStub.h +++ b/source/Irrlicht/CIrrDeviceStub.h @@ -24,8 +24,7 @@ namespace irr namespace scene { - ISceneManager* createSceneManager(video::IVideoDriver* driver, - io::IFileSystem* fs, gui::ICursorControl* cc, gui::IGUIEnvironment *gui); + ISceneManager* createSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, gui::ICursorControl* cc); } namespace io diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index 440a44dd..568c7543 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -34,9 +34,8 @@ namespace scene //! constructor CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, - gui::ICursorControl* cursorControl, IMeshCache* cache, - gui::IGUIEnvironment* gui) -: ISceneNode(0, 0), Driver(driver), FileSystem(fs), GUIEnvironment(gui), + gui::ICursorControl* cursorControl, IMeshCache* cache) +: ISceneNode(0, 0), Driver(driver), FileSystem(fs), CursorControl(cursorControl), ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0), Parameters(0), MeshCache(cache), CurrentRenderPass(ESNRP_NONE) @@ -58,9 +57,6 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, if (CursorControl) CursorControl->grab(); - if (GUIEnvironment) - GUIEnvironment->grab(); - // create mesh cache if not there already if (!MeshCache) MeshCache = new CMeshCache(); @@ -105,9 +101,6 @@ CSceneManager::~CSceneManager() if (CollisionManager) CollisionManager->drop(); - if (GUIEnvironment) - GUIEnvironment->drop(); - u32 i; for (i=0; idrop(); @@ -209,12 +202,6 @@ video::IVideoDriver* CSceneManager::getVideoDriver() } -//! returns the GUI Environment -gui::IGUIEnvironment* CSceneManager::getGUIEnvironment() -{ - return GUIEnvironment; -} - //! Get the active FileSystem /** \return Pointer to the FileSystem This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ @@ -888,7 +875,7 @@ IMeshCache* CSceneManager::getMeshCache() //! Creates a new scene manager. ISceneManager* CSceneManager::createNewSceneManager(bool cloneContent) { - CSceneManager* manager = new CSceneManager(Driver, FileSystem, CursorControl, MeshCache, GUIEnvironment); + CSceneManager* manager = new CSceneManager(Driver, FileSystem, CursorControl, MeshCache); if (cloneContent) manager->cloneMembers(this, manager); @@ -926,10 +913,9 @@ IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type) // creates a scenemanager ISceneManager* createSceneManager(video::IVideoDriver* driver, - io::IFileSystem* fs, gui::ICursorControl* cursorcontrol, - gui::IGUIEnvironment *guiEnvironment) + io::IFileSystem* fs, gui::ICursorControl* cursorcontrol) { - return new CSceneManager(driver, fs, cursorcontrol, 0, guiEnvironment ); + return new CSceneManager(driver, fs, cursorcontrol, nullptr); } diff --git a/source/Irrlicht/CSceneManager.h b/source/Irrlicht/CSceneManager.h index caf9dbea..1a749954 100644 --- a/source/Irrlicht/CSceneManager.h +++ b/source/Irrlicht/CSceneManager.h @@ -32,8 +32,7 @@ namespace scene //! constructor CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, - gui::ICursorControl* cursorControl, IMeshCache* cache = 0, - gui::IGUIEnvironment *guiEnvironment = 0); + gui::ICursorControl* cursorControl, IMeshCache* cache = nullptr); //! destructor virtual ~CSceneManager(); @@ -50,9 +49,6 @@ namespace scene //! returns the video driver video::IVideoDriver* getVideoDriver() override; - //! return the gui environment - gui::IGUIEnvironment* getGUIEnvironment() override; - //! return the filesystem io::IFileSystem* getFileSystem() override; @@ -285,9 +281,6 @@ namespace scene //! file system io::IFileSystem* FileSystem; - //! GUI Enviroment ( Debug Purpose ) - gui::IGUIEnvironment* GUIEnvironment; - //! cursor control gui::ICursorControl* CursorControl; From 52a0b9d8e532569b0ac152636d28ab49f2688ce8 Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 14 Mar 2023 18:34:47 +0300 Subject: [PATCH 052/123] Drop dependency on FileSystem from SceneManager --- examples/AutomatedTest/main.cpp | 6 +++- include/ISceneManager.h | 17 +---------- source/Irrlicht/CIrrDeviceStub.cpp | 2 +- source/Irrlicht/CIrrDeviceStub.h | 2 +- source/Irrlicht/CSceneManager.cpp | 49 +++--------------------------- source/Irrlicht/CSceneManager.h | 12 +------- 6 files changed, 14 insertions(+), 74 deletions(-) diff --git a/examples/AutomatedTest/main.cpp b/examples/AutomatedTest/main.cpp index 0141b2bb..5df7a291 100644 --- a/examples/AutomatedTest/main.cpp +++ b/examples/AutomatedTest/main.cpp @@ -85,8 +85,12 @@ int main(int argc, char *argv[]) const io::path mediaPath = getExampleMediaPath(); - scene::IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "coolguy_opt.x"); + auto mesh_file = device->getFileSystem()->createAndOpenFile(mediaPath + "coolguy_opt.x"); + check(mesh_file, "mesh file loading"); + scene::IAnimatedMesh* mesh = smgr->getMesh(mesh_file); check(mesh, "mesh loading"); + if (mesh_file) + mesh_file->drop(); if (mesh) { video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png"); diff --git a/include/ISceneManager.h b/include/ISceneManager.h index 60d2d49c..9379a9cc 100644 --- a/include/ISceneManager.h +++ b/include/ISceneManager.h @@ -318,20 +318,10 @@ namespace scene * \endcode * If you would like to implement and add your own file format loader to Irrlicht, * see addExternalMeshLoader(). - * \param filename: Filename of the mesh to load. - * \param alternativeCacheName: In case you want to have the mesh under another name in the cache (to create real copies) + * \param file File handle of the mesh to load. * \return Null if failed, otherwise pointer to the mesh. * This pointer should not be dropped. See IReferenceCounted::drop() for more information. **/ - virtual IAnimatedMesh* getMesh(const io::path& filename, const io::path& alternativeCacheName=io::path("")) = 0; - - //! Get pointer to an animateable mesh. Loads the file if not loaded already. - /** Works just as getMesh(const char* filename). If you want to - remove a loaded mesh from the cache again, use removeMesh(). - \param file File handle of the mesh to load. - \return NULL if failed and pointer to the mesh if successful. - This pointer should not be dropped. See - IReferenceCounted::drop() for more information. */ virtual IAnimatedMesh* getMesh(io::IReadFile* file) = 0; //! Get interface to the mesh cache which is shared between all existing scene managers. @@ -345,11 +335,6 @@ namespace scene This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ virtual video::IVideoDriver* getVideoDriver() = 0; - //! Get the active FileSystem - /** \return Pointer to the FileSystem - This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ - virtual io::IFileSystem* getFileSystem() = 0; - //! Adds a scene node for rendering an animated mesh model. /** \param mesh: Pointer to the loaded animated mesh to be displayed. \param parent: Parent of the scene node. Can be NULL if no parent. diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index 69906737..3fde44ac 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -92,7 +92,7 @@ void CIrrDeviceStub::createGUIAndScene() GUIEnvironment = gui::createGUIEnvironment(FileSystem, VideoDriver, Operator); // create Scene manager - SceneManager = scene::createSceneManager(VideoDriver, FileSystem, CursorControl); + SceneManager = scene::createSceneManager(VideoDriver, CursorControl); setEventReceiver(UserReceiver); } diff --git a/source/Irrlicht/CIrrDeviceStub.h b/source/Irrlicht/CIrrDeviceStub.h index fd069b1a..10e5d72e 100644 --- a/source/Irrlicht/CIrrDeviceStub.h +++ b/source/Irrlicht/CIrrDeviceStub.h @@ -24,7 +24,7 @@ namespace irr namespace scene { - ISceneManager* createSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, gui::ICursorControl* cc); + ISceneManager* createSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cc); } namespace io diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index 568c7543..8a16dd21 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -33,9 +33,9 @@ namespace scene { //! constructor -CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, +CSceneManager::CSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorControl, IMeshCache* cache) -: ISceneNode(0, 0), Driver(driver), FileSystem(fs), +: ISceneNode(0, 0), Driver(driver), CursorControl(cursorControl), ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0), Parameters(0), MeshCache(cache), CurrentRenderPass(ESNRP_NONE) @@ -51,9 +51,6 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, if (Driver) Driver->grab(); - if (FileSystem) - FileSystem->grab(); - if (CursorControl) CursorControl->grab(); @@ -92,9 +89,6 @@ CSceneManager::~CSceneManager() if (Driver) Driver->removeAllHardwareBuffers(); - if (FileSystem) - FileSystem->drop(); - if (CursorControl) CursorControl->drop(); @@ -125,29 +119,6 @@ CSceneManager::~CSceneManager() } -//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped. -IAnimatedMesh* CSceneManager::getMesh(const io::path& filename, const io::path& alternativeCacheName) -{ - io::path cacheName = alternativeCacheName.empty() ? filename : alternativeCacheName; - IAnimatedMesh* msh = MeshCache->getMeshByName(cacheName); - if (msh) - return msh; - - io::IReadFile* file = FileSystem->createAndOpenFile(filename); - if (!file) - { - os::Printer::log("Could not load mesh, because file could not be opened: ", filename, ELL_ERROR); - return 0; - } - - msh = getUncachedMesh(file, filename, cacheName); - - file->drop(); - - return msh; -} - - //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped. IAnimatedMesh* CSceneManager::getMesh(io::IReadFile* file) { @@ -202,15 +173,6 @@ video::IVideoDriver* CSceneManager::getVideoDriver() } -//! Get the active FileSystem -/** \return Pointer to the FileSystem -This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ -io::IFileSystem* CSceneManager::getFileSystem() -{ - return FileSystem; -} - - //! adds a scene node for rendering a static mesh //! the returned pointer must not be dropped. IMeshSceneNode* CSceneManager::addMeshSceneNode(IMesh* mesh, ISceneNode* parent, s32 id, @@ -875,7 +837,7 @@ IMeshCache* CSceneManager::getMeshCache() //! Creates a new scene manager. ISceneManager* CSceneManager::createNewSceneManager(bool cloneContent) { - CSceneManager* manager = new CSceneManager(Driver, FileSystem, CursorControl, MeshCache); + CSceneManager* manager = new CSceneManager(Driver, CursorControl, MeshCache); if (cloneContent) manager->cloneMembers(this, manager); @@ -912,10 +874,9 @@ IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type) // creates a scenemanager -ISceneManager* createSceneManager(video::IVideoDriver* driver, - io::IFileSystem* fs, gui::ICursorControl* cursorcontrol) +ISceneManager* createSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorcontrol) { - return new CSceneManager(driver, fs, cursorcontrol, nullptr); + return new CSceneManager(driver, cursorcontrol, nullptr); } diff --git a/source/Irrlicht/CSceneManager.h b/source/Irrlicht/CSceneManager.h index 1a749954..4b1beec8 100644 --- a/source/Irrlicht/CSceneManager.h +++ b/source/Irrlicht/CSceneManager.h @@ -31,15 +31,11 @@ namespace scene public: //! constructor - CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, - gui::ICursorControl* cursorControl, IMeshCache* cache = nullptr); + CSceneManager(video::IVideoDriver* driver, gui::ICursorControl* cursorControl, IMeshCache* cache = 0); //! destructor virtual ~CSceneManager(); - //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped. - IAnimatedMesh* getMesh(const io::path& filename, const io::path& alternativeCacheName) override; - //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped. IAnimatedMesh* getMesh(io::IReadFile* file) override; @@ -49,9 +45,6 @@ namespace scene //! returns the video driver video::IVideoDriver* getVideoDriver() override; - //! return the filesystem - io::IFileSystem* getFileSystem() override; - //! adds a scene node for rendering an animated mesh model virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1, const core::vector3df& position = core::vector3df(0,0,0), @@ -278,9 +271,6 @@ namespace scene //! video driver video::IVideoDriver* Driver; - //! file system - io::IFileSystem* FileSystem; - //! cursor control gui::ICursorControl* CursorControl; From 0acf0de2db690217ae38c5369e8e5a5ceb1ece26 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 20 Mar 2023 14:41:11 +0100 Subject: [PATCH 053/123] Delete changes.txt Gets in the way of cherry-picking and isn't up to date anyway. --- changes.txt | 5527 --------------------------------------------------- 1 file changed, 5527 deletions(-) delete mode 100644 changes.txt diff --git a/changes.txt b/changes.txt deleted file mode 100644 index 4bbdae64..00000000 --- a/changes.txt +++ /dev/null @@ -1,5527 +0,0 @@ --------------------------- -Changes in ogl-es (not yet released - will be merged with trunk at some point) - -- Add support for (experimental) WebGL1 driver for emscripten (still work in process) -- Add support for emscripten. Thanks @labsin for the patch. -- Add IVideoDriver::getAmbientLight function so shaders can access global ambient light easier -- Merge material changes for COGLES1MaterialRenderer_LIGHTMAP and COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL which had been done in OGL in trunk (r2740) to ensure materials look the same on all platforms. -- Added support for PVR textures. Loader offer support for compressed DXT1-5, PVRTC/PVRTC-II, ETC1/ETC2 texture formats. - --------------------------- -Changes in 1.9 (not yet released) -- IBillboardSceneNode got functions to access meshbuffers. So uv-coordinates can now be modified directly (previously only possible via texture matrix). -- vector3d scalar operator/ and operator/= no longer multiply by the inverse but use the expected division. - Costs some speed, but fixes floating point troubles caused by this optimization (like x/x no longer being 1.0). -- Add equals and set_data functions to core::array for easier working with blocks of data. -- SIrrlichtCreationParameters::IgnoreInput set to false works again on X11. - Thanks @ Victor Gaydov for report + patch + very good test cases! (bug #401) - This had been broken since Irrlicht 1.6 -- Add steer parameter to CSceneNodeAnimatorFollowSpline which allows rotating node toward direction of movement. - Thanks @ Bate for the patch (patch #175) -- Add a workaround for XWarpPointer bug that causes mouse to jump when users have set a Coordinate Transformation Matrix for their mouse on X11. - This was mentioned in bug #450 by vikaig. - The fix needs compiling with _IRR_LINUX_X11_XINPUT2_ enabled (so far disabled by default) -- Add IGeometryCreator::createTorusMesh to create donuts. -- Don't try loading broken image files twice with same loader anymore. -- Make CImageLoaderJPG thread safe. Thanks @ Edoardo Lolletti for report and patch (patch #324) -- Add ETCF_SUPPORT_VERTEXT_TEXTURE flag which can be used to enable vertex texture sampling support in Direct3D 9. - Note that this was enabled for a long time in 1.9 svn, but is now disabled by default. -- CGUIListBox now serializes the state of "Selected". Feature wish by chronologicaldot (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=52719) -- Bugfix: Changing focus with tab-keys now also work when elements are inside a modal screen. -- COBJMeshFileLoader using a bit more exact color conversion for 0-1 to 0-255 range (same now as SColorf::toSColor uses). -- Speedup for COBJMeshWriter -- Add blinkMode parameter to IGUIEnvironment::addModalScreen, so blinking can be suppressed -- Speedup: Avoid string copy in CXMLReaderImpl::getAttributeByName -- Fix bug in rect::clipAgainst that had caused rects completely outside to the left-top of the rect to be clipped against ending up with both corners outside. - It still worked for UI in most cases as the resulting rectangle still had an area of 0. -- Add getAlign functions to IGUIElement -- Add optional multitouch support to X11 (but disabled in IrrCompileConfig by default). Thanks @TheBrokenRail for a patch proposal based on example code from esjeon (patch #322). -- Slightly changed close window handling on X11 (optimized and avoids problems on some shells). Thanks @TheBrokenRail for a patch (was part of patch #322). -- Add getActiveColor functions to IGUIStaticText and IGUIButton (get currently used color). -- Add IGUIEnvironment::addToDeletionQueue to allow save removal of gui elements while iterating over them (like the same named function in ISceneManager). -- IGUIEnvironment::drawAll has now a parameter to allow disabling automatic resize to screensize. Makes it easier to use partial screens with full alignment support. -- No longer try to set WM_QUIT when using an external Window on Win32. - Thx @Marko Mahnic for the patch (https://sourceforge.net/p/irrlicht/bugs/449) -- ply meshloader now also supports textures with uv-labels named texture_u/texture_v. - Thx @acy for bugreport and test-model (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=4&t=52646) -- Fix potential reading/writing 1 byte behind it's own buffer in PLY loader. - Thanks @wolfgang for report and patch (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52627&p=305573#p305573) -- ICursorControl::isVisible is now always returning the flag set in setVisible. - This changes the behaviour on Win32 somewhat when Windows returned a CURSOR_SUPPRESSED state (touch-screen input). - Previously we set IsVisible it to false when CURSOR_SUPPRESSED was set. - Also we handle the CURSOR_SUPPRESSED state slightly different now and still try to hide cursors once when requested. -- Improvements to B3D writer for speed, readability and handling of low framerate animations. - Thanks @JLouisB for the patch (For more info, see: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=50067&start=15) -- Add another render pass ESNRP_GUI which is drawn last and is p.E. useful for rendering gui nodes in the scenemanager. -- BurningVideo: 0.52 - - 10 year anniversary update - - Lighting model reworked. moved to eyespace like openGL. [Specular Highlights, Fog, Sphere/Reflection Map] - - increased internal s4DVertex to support 4 Textures and 4 Colors [switchable] - - Textures are handled as sRGB during Mipmap Generation. More accurate, less visual disruption - - 2D is drawn as 3D like hardware drivers. [switchable]. enables viewport scaling, material2D, scissor - - Texture Spatial Resolution Limiting working. [lower memory consumption,SOFTWARE_DRIVER_2_TEXTURE_MAXSIZE] - - NormalMap for 1 Light accurate. still all lights are accumulated - - SuperTuxKart 8.0.1 playable - - Internal Backbuffer Scaling and Interlacing - - Known Problems - - Depthbuffer range not equal to Hardware Drivers. Problems with Orthographic Stencil Shadows - - Triangle MipMap Selection. Wrong for TextureAtlas and Billboards -- Fix CPLYMeshFileLoader checking for wrong vertex count when switching between 16/32 bit. Thanks @randomMesh for reporting. -- Fix bug that AnimatedMeshSceneNode ignored ReadOnlyMaterials flag when checking materials for transparent render passes. -- Unify checks if materials should use transparent render pass with new IVideoDriver::needsTransparentRenderPass function. -- Material.ZWriteEnable is now of type E_ZWRITE instead of bool. This allows now setting materials to always "on" independent of material type and transparency. - This breaks compiling. To have old values replace false with EZW_OFF and true with EWZ_AUTO. -- Materials EMT_REFLECTION_2_LAYER and EMT_TRANSPARENT_REFLECTION_2_LAYER on OpenGL are now same as in D3D9. Before GL used a sphere-map for those instead of reflection. -- Bugfix: CGUIToolBar automatic placement no longer outside of screen when there are modals screens when creating it. - Or when there are other window elements going over full window-size. - Thanks to Stephen Lynx for the bugreport and to Sérgio Augusto Vianna for writing a test case with a bug example. - Changes: a) Never move the toolbar below it's parents lower border. b) No longer check all element-types, but only try to be below other toolbars or menues. -- Add a normalType parameter to IGeometryCreator::createCylinderMesh -- Add a normalsUpdate parameter to IMeshManipulator::transform to allow updating the normals with the inverse-transpose of the transformation matrix. -- Bugfix: quaternion::slerp now uses lerpN instead of lerp to keep result normalized. -- Add function quaternion::lerpN which is like lerp but normalizes the result. -- Add function ISceneManager::createShadowVolumeSceneNode to allow custom ISceneNode's to use shadows. -- CGUITabControl serialization changed to allow using custom tabs (before only CGUITab could be serialized). - There was a lot of rewriting involved, including some minor interface changes (IGUITab* can now be added directly for example). - See http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52344 for a thread about this. - Thanks @chronologicaldot for bringing this up, writing a patch proposal and even writing test. -- CGUITabControl no longer eats EMIE_LMOUSE_PRESSED_DOWN (doesn't seem to need it, was just done for a planned feature which is not implemented yet). -- Removing a tab in CGUITabControl will now also remove the tab-element. Fixes problems like tabs still being around & visible when you removed the active tab. -- Add example 28.CubeMapping. - Based originally on EnvCubeMap example from irrSpintz engine. - Including a cubemap texture from Emil Persson, aka Humus from http://www.humus.name -- IGeometryCreator::createCubeMesh has a new parameter to allow creating different types of cube meshes. - Added a new cube-mesh with meshbuffers per side. - Also single buffer cube-mesh now normalizes it's normals. -- Bugfix: CBillboardTextSceneNode no longer disregards IsVisible flag -- FPS-camera rotation now smoother. - First bug was that it would sometimes skip back because it worked with wrong values for the screen-center position. - Second (and bigger) bug was that it ignored all cursor-movement which happened between device->run() and the point where - the animator did run. Tiny side-effect your camera will now rotate generally faster. -- Fix ms3d loader to work on big endian systems which need floats to be aligned in memory. Thanks @ kas1e, Corto and Salas for the patch (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52538). -- Bugfix: COBJMeshFileLoder no longer overwrites transparency value with 1.0 when it's set before the diffuse color value in the mtl file. Thanks @Boshen for bugreport (#445). -- Bugfix: OpenGL no longer antialiasing stencil buffer when driver has antialiasing disabled. -- Add IShadowVolumeSceneNode::setOptimization to allow disabling optimizations for meshes were contour shadows fail. -- Stencil shadows work now also with directional light -- Add example 27.PostProcessing written by Boshen Guan -- Drivers can now try to create textures from images in more exotic color formats (like floating point formats). It depends on the driver how much that works (so far mainly OpenGL can handle it somewhat). -- Fix OpenGL to no longer switch colors red and blue in 24-bit RGB format. But warnings added to documentation to avoid 24-bit textures as they are generally just trouble. -- No longer try to convert ECF_R5G6B5 to ECF_A1R5G5B5 on OpenGL (just made texture-loading seem to fail). -- Add parameter SIrrlichtCreationParameters.WindowResizable. Mainly to work around troubles with SDL+OpenGL on some platforms where resizing later can be tricky/impossible. -- Add operator[] to vector2d and vector3d -- Bugfix: IrrlichtDevice::isWindowMinimized no longer returns true when it's maximized on Windows. -- Ignore degenerated faces in obj file loader when they would generate triangles where 2 vertices use identical indices. -- Add CMatrix4::transformVec4 to transform vectors with 4 elements (thx @ devsh) -- Add ITexture::getOriginalColorFormat to access color format of images used to create a texture -- Add IMemoryReadFile interface which allows direct access to memory block used as file. -- Add IReadFile::getType() interface to all users to find out what kind of class implements that interface. -- .dae/Collada reader/writer now handle whitespace in texture-filenames with escape characters (handle them as xs:anyURI). -- Add function string::insert. -- EditBox now still allows overwriting characters when the text-length is at max. -- Bugfix: CMatrix4::transformPlane was calculating the wrong plane-normal before. -- SViewFrustum::recalculateBoundingBox no longer includes camera position in the bounding-box. Only using frustum corners now. Thx @DevSH for bugreport & patch. -- Camera uses now OGL projection matrices with OpenGL driver. Fixes wrong near-plane values with OpenGL (showed too much before). -- Add a flag to most CMatrix4::buildProjectionMatrix functions to allow creating OpenGL projection matrices (target range of -w to w instead of 0 to w). -- Bugfix: CCameraSceneNode resets the IsOrthogonal flag to false now when it recalculates a projection matrix. -- SViewFrustum::setFrom and SViewFrustum constructor now use a parameter to allow to set the correct near clipping plane when the projection matrix doesn't use a target depth range of 0 to z, but for example -z to z. So OGL projections matrices can now also use it. -- Remove code to read boundingbox element in Collada reader as it's not in Collada specification. -- .dae/Collada reader now converts from Collada's right-handed to Irrlicht's left handed coordinate system (switching z to -z) -- Add irr::string::eraseTrailingFloatZeros to kick out trailing 0's for strings generated from floats. -- .dae/Collada writer now converts from Irrlicht's left-handed to Collada's right-handed coordinate system (switching z to -z) -- Switch Collada writer to utf8 xml's. -- Add IXMLWriterUTF8 -- IColladaMeshWriter::writeScene got an additional flag to decide if root should be written. -- _IRR_MATERIAL_MAX_TEXTURES_ now set to 8 by default. So we can use now 8 textures per material without recompiling the engine. - Additionally there's a new global variable irr::video::MATERIAL_MAX_TEXTURES_USED which can be set to lower numbers to avoid most of the costs coming with this for people not needing more textures. - But using more textures via _IRR_MATERIAL_MAX_TEXTURES_ also has become less calculation intensive than it was in the past, so in release builds the difference is hardly noticeable. -- Serialization fixes for materials in irr format (in IVideoDriver::createAttributesFromMaterial/fillMaterialStructureFromAttributes). -- Add serialization for ToolTip to IGUIElement. Thanks @chronologicaldot for patch (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=52374) -- Try recovering lost device in D3D9 for 3 seconds when device reset fails after resizing Window. -- Add typedefs like value_type and size_type to array, list and map like std containers have. Thanks @SLC for idea (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=52363) -- Remove unused enum E_LOST_RESOURCE -- CGUIComboBox uses now EGDS_SCROLLBAR_SIZE instead of EGDS_WINDOW_BUTTON_WIDTH for the width of the listbox button to allow changing that without changing window topbar height. - Thanks @LunaRebirth for reporting. (Forum: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=52297&p=303682#p303682) -- CGUIListbox, CGUITreeView and CGUITable now resize scrollbars when EGDS_SCROLLBAR_SIZE in the skin changes without having to re-create the elements. - This also fixes the problem that drawing looked wrong when this value got changed after the elements were created. - Thanks @LunaRebirth for reporting. (Forum: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=52297&p=303682#p303682) -- Scrollbar buttons can no longer get larger than half the ScrollBar element to avoid them overlapping. -- Add IVideoDriver::swapMaterialRenderers to allow swapping the renderer used to render a certain material. -- IMeshManipulator functions createMeshWith1TCoords, createMeshWith2TCoords and createMeshWithTangents no longer weld vertices while converting meshes. Use IMeshManipulator::createMeshWelded if you need that welding. -- Add ITerrainSceneNode::setFixedBorderLOD to handle connecting terrain nodes without gaps. Thanks @diho for the bugreport, testcase and a patch proposal (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=9&t=51220). -- PLY loader now works with files which use "st" instead of "uv" for texture coordinates (like generated from Blender or Assimp). Thanks @JLouisB for patch (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=9&t=52261). -- STL writer does now also write binary files when EMWF_WRITE_BINARY flag is used. Based on patch from JLouisB (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=9&t=52261). - (EMWF_WRITE_COMPRESSED also still works for downward compatibility) -- Improved PLY exporter. Thanks for Patch from JLouisB. (Forum: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=9&t=52261): - - Support for UV and vertex colors. - - Support for binary PLY files export with the EMWF_WRITE_BINARY flag - - Fix for the meshes with 32 bits index -- Fix wrong colors on big endian platforms with burnings renders. Thx @kas1e for reporting and @curaga for the patch (#318). Forum bug discussion at http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52177. -- Fix bug #440 where OpenGL driver enabled second texture for single-texture materials when setMaterial was called twice. Thx@ "number Zero" for bugreport and test-case. -- Irrlicht icon now loaded with LR_DEFAULTSIZE to better support larger icon requests. Thx@ luthyr for report and bugfix. -- Cursor on X11 behaves now like on Win32 and doesn't try to clip positions to the window -- IImage::copyToWithAlpha has a new parameter to allow combining alpha value instead of replacing them. This uses new blitters called BLITTER_TEXTURE_COMBINE_ALPHA. Thx @chronologicaldot for providing this patch and @burningreggae for his feedback. -- Add _IRR_COMPILE_WITH_PARTICLES_ to control compilation of particle system -- Add IGUIImage::setDrawBackground to allow disabling background drawing even when no texture is set. -- Fix: IGUIContextMenu now raises sub-menu when they would otherwise be displayed below bottom-border of root gui element. -- Prevent initializing/quitting SDL several times when using more than one Irrlicht device. -- Reduce log-messages for "loaded texture" and "loaded mesh" from ELL_INFORMATION to ELL_DEBUG. -- Add IGUIButton::setOverrideColor to allow overriding text-color (same function as statictexts and editboxes have). -- Add functions IGUIButton::getClickShiftState and IGUIButton::getClickControlState to get shift/ctrl key-state when a button was clicked. Thanks @StarSonata for patch. -- Add function ISceneManager::clearAllRegisteredNodesForRendering. -- Add function IVideoDriver::queryTextureFormat to allow checking if a driver supports textures with a specific color format. -- ISceneManager::getMesh can now creates meshes with alternative cache-names. -- Lets the BSP loader find textures inserted with relative paths. Thx@ curaga for patch -- Slightly simplified ALLOC_STRATEGY_DOUBLE in arrays -- Add alternative BoundingBox calculation for BillboardSceneNode which can take in a camera node. Thx @Seven and @JacKDuRdEn for bugreports. -- FPS camera now supports keyboard rotation. -- Base FPS-camera movement on last position of mouse instead of always center (works better on platforms where cursor-placement is not allowed) -- Octrees with other vertex types than EVT_2TCOORDS can now also use VBO's. -- Add IOctreeSceneNode interface to control polygon clipping checks for octree scene nodes. -- Add support for different geometric primitives to meshbuffers. Thanks @gerdb for patch proposal (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=45999) -- change SEvent::SUserEvent.UserData1 and SEvent::SUserEvent.UserData1 from s32 to size_t to avoid cutting numbers on some 64-bit platforms (SDL and Windows) -- Improve speed of draw3DBox (OpenGL and D3D9). Thanks @zerochen for patch (https://sourceforge.net/p/irrlicht/patches/256) -- Support more keys on OSX "[]\". Thanks @neoascetic for patch (#313). -- Fix IBillboardTextSceneNode::setTextColor which did nothing in the past. It now maps to setColor instead. -- Add access functions to IBillboardTextSceneNode (getText, getFont). -- Add access functions to ITextSceneNode (getText, getTextColor, setFont, getFont). -- Try harder to move Window to custom WindowPosition set in SIrrlichtCreationParameters on X11. Thx@ Hernan Ezequiel Di Giorgi for the patch (#304). -- Fix bug in virtual filessystem which prevented createFileList from working. Thx @Cube for reporting a problem. -- ITriangleSelector now can also return meshbuffer collision information. -- core::string::split now adds delimiter to token before delimiter when keepSeparators is true. That way we never end up with 2 tokens for an original string with a single character. -- Bugfix: SMesh::recalculateBoundingBox() does now ignore empty boundingboxes of meshbuffers instead of adding them. -- IIrrXMLReader::getAttributeValueAsInt and IIrrXMLReader::getAttributeValueAsFloat can now return a custom default-value when the attribute is not found. -- core::string::split now handles ignoreEmptyTokens=false correct. Thanks @manni63 for bugreport: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=51551&p=299375#p299375 -- Bugfix: Previously when some material had a texture matrix and another didn't those materials were still considered identical. Which had prevented correct switching between materials with and without texture matrices. -- IWriteFile::write now returning size_t (like fwrite in c-lib). Also sizeToWrite parameter changed from u32 to size_t. -- IReadFile::read now returning size_t (like fread in c-lib). Also sizeToRead parameter changed from u32 to size_t. -- add clear function to strings. -- Collision manager now using const camera pointers. -- Several fixes for SceneNodeAnimatorCollisionResponse, based on http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=33098&p=290746 - Thanks to all people who reported and to JLouisB and kinkreet for the patches: - - Gravity is now fps independent - - Values of gravity now like documented (wasn't 1 unit = 1m before, had been 1m = current frames per second, so maybe 100 units = 1m). - Note that jump-values for fps-camera must also change when adapting gravity! - Several examples got adapted for new ranges. - - Pausing timer now pauses animator. Also doesn't reset values anymore with pauses. - - Clones no longer have 1000 times the gravity of original animator. - - Should now be fps independent -- Speedup CTriangleSelector (mainly for animated meshes) -- CTriangleSelector now supports 32-bit meshbuffers. Thanks @Wol101 for reporting and patch-proposal. -- Fix: CTriangleSelector no longer resets it's boundingbox to 0,0,0 (was wrong when a meshbuffer was not around 0) -- Fix: Collada writer now uses wrap_p for third texture wrap value instead of invalid wrap_w (thx @Yoran for bugreport) -- Several getter functions in IAttributes made const (thx @Erik Schultheis for the patch) -- Fix: CTriangleSelector no longer ignores meshbuffer transformations from skinned meshes (thx @AlexAzazel for report and test-model). -- Randomizer now returns range 0..randMax as documented and no longer 1..randMax as it did before. randMax got reduced by 1. - Note: You will generally get different numbers than before! If you need the exact old calculations, please check the corresponding sources in Irrlicht 1.8 in os.cpp/.h -- Resetting Randomizer with 0 or no longer breaks it (will be set to 1). Same for other numbers for which it wasn't defined. -- Add SMaterialLayer::TextureWrapW for cubemap texture wrap mode at W axis. -- Add cubemap texture support for D3D9 and OpenGL drivers. -- Do no longer re-calculate md2 frames when they don't change (thx @npc for reporting) -- Add multibyteToWString wrapper functions around mbstowcs which work with Irrlicht string class. -- Fix: addFileArchive now grab()'s the archive when you pass one in by pointer. -- Fix: Prevent division by 0 in CGUIScrollBar::setPos -- Fix: Add missing serialization to CSceneNodeAnimatorCameraFPS and CSceneNodeAnimatorCameraMaya -- Fix: File-open dialog now restores the original locale after modifying it internally -- Fix first calculation of the camerascenenode boundingsphere. -- Fix bug with ignored opening brace in .X files with DeclData section. Thx @Alin for bugreport and patch. -- Fix problem with OpenGL textures cache. -- Add clear buffer flags and marked some methods used for clear buffers as deprecated. -- Fix skinned meshes not playing their last frame. Also clarified animation documentation to describe current behavior more exactly. -- Add IWriteFile::flush interface (thx @ JLouisB for the patch). -- CLightSceneNode::updateAbsolutePosition does now light recalculations. This is to fix using animators with lights. -- Fix Collada export for objects with rotations around more than 1 axis. -- Add ISceneNodeAnimatorCameraMaya::setTargetMinDistance and getTargetMinDistance. -- Add override font to IGUITreeView -- CGUIComboBox now updates selection-list when font changes while it's open (thx @ rubixcuber for bugreport) -- CAnimatedMeshSceneNode::setMesh does now set the animation speed again to that of the mesh (had been changed in 1.7, but not for obvious reasons) -- .x meshloader regards now AnimTicksPerSecond (thx @qian for a test-model and bugreport) -- Interface getMeshType moved from IAnimatedMesh up to IMesh. -- Add b3d mesh-writer. Static writer written by Hendu, support for animated meshes added by JLouisB, testing and bugfixes by CuteAlien. -- Node-collision functions of SceneCollisionManager like getSceneNodeFromScreenCoordinatesBB will now ignore collisions against empty boundingboxes. -- Cameras return again an empty boundingbox (at 0,0,0) instead of returning the frustum boundingbox (was changed in very old Irrlicht version). - You can access the frustum boundingbox through the frustum itself. - This means cameras no longer show up in the node-collision of the SceneCollisionManager (showing up there because of their frustum bounding-box was too confusing). -- Fix problem in IrrlichtDevice::setResizable on X11 that caused window titlebars to hide occasionally under the taskbar in some systems (Ubuntu, Mint). -- Added new IRenderTarget interface. -- Replace the swprintf and snprintf defines by swprintf_irr and snprintf_irr to avoid conflicts with the standard libraries (and other libraries). -- XBox support removed as it would need DX8 (this was about the original XBox). -- Support for Direct3D 8 removed after svn revision 5052 due to lack of maintenance. -- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX removed. This was a bugfix for VS2003 (in combination with .NET) which we haven't supported in a while. -- VS 2005 support removed after svn revision 5048. -- WinCE 6 supported removed after svn revision 5046. -- NVidia CG support removed after svn revision 5045 due to lack of maintenance. NVidia has also stopped supporting this. -- TA burningvideo: - enabled triangle fan again so that skybox works.[need more testmeshes if other trianglefan than skybox doesn't work] - correct vc2013 project files for x64,static lib - correct alphablend vs add [was broken] -- Add a new core::rect constructor which takes a dimension parameter and set's left-top to 0. -- mtl (obj) format reader and write now regards texture scaling and translation. (thx @thanhle for noticing and patch proposal). -- Added Visual Studio 2013 project files. -- Added new color formats: ECF_R8, ECF_R8G8, ECF_D16, ECF_D32, ECF_D24S8. -- Can now enable/disable background drawing for IGUITable. -- Bugfix: Cloning CBillboardSceneNode now copies colors and sizes. -- EditBox works now with numpad on X11 -- Added helper functions for converting between wchar and utf-8. Patch provided by Hendu. -- Added sphere frustum culling support. Patch provided by Hendu. -- Fixed issues with setViewPort method under OpenGL. (reported by anontypist) -- Fixed several selection, highlighting and clipping bugs in CGUITreeview (thx @ AReichl for the patch + test) -- Removed DllMain from the static windows build (thx @ AReichl for reporting) -- Fixed maximize/minimize under Linux by supporting NETWM hints. Patch provided by hendu. -- ISceneNode::deserializeAttributes uses now old values for parameters which are not in the attributes (thx @entity for noticing). -- Add interface for easier access to scrollbars for IGUIListBox, IGUITreeView and IGUITable -- Fix serializing colors as strings. Was previously mixing up strings with number-arrays and hex color values. Now using hex color values always, but also fixed the the handling when it get's number-array strings. -- Fix IAttributes::setAttribute implementation for textures (did do nothing before). -- Added support for separate blending in OpenGL and D3D9 drivers. -- Added pack_textureBlendFuncSeparate and unpack_textureBlendFuncSeparate functions, which allow to use separate blending functions in OpenGL. -- Added BlendFactor field to SMaterial which allow user to set blending factor per SMaterial set call without use EMT_ONETEXTURE_BLEND type. -- Fixed issue with blending operation set to EBO_NONE and some transparent material types. -- Add a code profiler (stop-watch style) -- Add IGUITable::getItemHeight to access item (row) height -- Add override font to IGUITable -- IGUITable can now disable the active column. -- IGUIElement::getElementFromPoint now virtual -- Fixed issue with wrongly enabled Z-writing for transparent shader materials. Thanks Hendu for this fix. -- Allow more control over particle behavior. This also changed the default behavior. -- ISceneNodeAnimators can now be disabled and paused. -- Maya camera no longer get's stuck in "rotating" state when a mouse-up event is lost (thx @ JLouisB for reporting). -- Focus behavior of IGUIEnvironment now controllable (right-click focus, mouse-over focus). Disabled elements no longer get the focus unless users enforce it. -- Buttons can now now have 7 more image-states, 1 more sprite-state and the sprites are now scaleable. -- Spritebanks can now draw scaled sprites and are a little easier to use. -- Improved i18n key input for X11 (languages like cyrillic work now). -- Fix bug that ListBox would not allow to 'tab' to the next element (thx @ FlavourBoat for reporting) -- IGUIEnvironment::getNextElement now public (was only in CGUIEnvironment before). -- Add an overwrite mode to editbox. Patch provided by Adam(aka kingadami). -- Add IGUIImages::setDrawBounds/getDrawBounds to allow coding stuff like progress bars. -- Add IGUIImages::setSourceRect/getSourceRect to allow using only parts of an image (can also be used to mirror and scroll them). -- Dev-Cpp project file removed (wasn't really supported for some time already) -- Collada dae-loader now set's the vertex colors (thx @sf17k for report and test-models) -- IAttributes interface changed. Parameters are now passed by const-ref instead of per value. -- Fix c::b project obj folder names. Some static builds had used the shared folders (thx @ gerdb for reporting) -- Add ITexture::getSource which can be used to check where the last IVideoDriver::getTexture call found the texture. -- Add IMeshTextureLoader interface and replace texture-loading algorithms in most meshloaders. -- CGUICheckBox no longer gives up focus on EMIE_LMOUSE_LEFT_UP (thx @Demre and @REDDemon for reporting) -- Bugfix: IGUIElement::addChild now prevents setting an element as it's own child. -- GUI editor improvements (prevent crash, improve UI) -- Add IrrlichtDevice::setWindowSize. -- Bugfix: getFont for xml-fonts now also works for fonts inside archives (thx @Neirdan for bugreport) -- Added function irr::core::mergeFilename -- Add ISceneNodeAnimator::setStartTime/getStartTime to allow resetting movement animators. -- Improve speed for finalizing skinned meshes (removal of unnecessary frames after loading) (thx @ichtyander for the testmodel) -- Collada loader now instantiates camera nodes which had been ignore so far (thx @NemoStein for the test .dae) -- line2d::intersectWith has a new parameter to allow ignoring intersections with coincident lines -- vector2d::equals now has an tolerance parameter for passing the epsilon (like vector3d had). Note that this changes the default - behavior of vector2d::equals as well as functions using it like the operators for ==, !=, <, >, <=, >= when using vector2d with f64 - as the tolerance is increased in that case (for f32 and integer values it shouldn't make any difference). -- Material renderers which offers blending feature (eg. EMT_TRANSPARENT_ALPHA_CHANNEL, EMT_ONETEXTURE_BLEND etc.) require SMaterial::BlendOperation set to other value than EBO_NONE. -- Removed support for built-in T&L variables in ASM/GLSL shaders (variables related to vertices eg. gl_MultiTexCoord0 are still supported). This change allow us to reduce CPU overhead in shader material renderers. -- IGUIEnvironment::hasFocus has now a parameter checkSubElements as subelements are usually seen as part of an element. Default unfortunately must be false due to backward compatibility. -- Add IGUIElement::isTrulyVisible which works like ISceneNode::isTrulyVisible and checks for parent visibility as well. -- Improved DDS loader and added support for DXTn (DXT1-5) compressed textures in OpenGL and Direct3D9 drivers. -- Add function ISceneNode::getTransformedBoundingBoxEdges. -- Improve automatic compiling under Solaris (proposed by curaga) -- Add in IGUICheckBox: setDrawBackground, isDrawBackgroundEnabled, setDrawBorder, isDrawBorderEnabled -- IGUISpinBox now passes on the EGET_BUTTON_CLICKED, EGET_EDITBOX_CHANGED and EGET_EDITBOX_ENTER events from it's sub-elements. -- IGUISpinBox no longer validates values after each character type but only on KEY_ENTER and when losing focus. New behavior can be set with IGUISpinBox::setValidateOn -- IAttributes::getAttributeAs functions now can have a customizable default-parameter to return when attributeName is not found -- Added ECFN_DISABLED value (it works like ECFN_NEVER worked before) and changed ECFN_NEVER behaviour - (it works like its equivalent value in OpenGL/Direct3D). -- Removed boolean interface from IShaderConstantSetCallBack, please use integer interface instead of them. -- Add a LeakHunter class which can be enabled with compile-flag _IRR_COMPILE_WITH_LEAK_HUNTER_ to find leaking IReferenceCounted objects. -- Add _IRR_COMPILE_WITH_XML_ define to allow compiling Irrlicht without xml (patch written by curaga) -- Add functions to set/get cursor character and blinktime to IGUIEditBox -- Collada exporter calculates values for orthographic camera now on export -- Collada exporter now exports the camera up-vector correctly. -- Add IColladaMeshWriter::findGeometryNameForNode -- Add getters IGUIButton::isDrawBorderEnabled and IGUIButton::isDrawBackgroundEnabled - -- changed CSkyBoxSceneNode to drawIndexedTriangleList instead of drawIndexedTriangleFan (because software renderers don't have fans.. and i needed the demo functionable) -- added x64 to vs2008 project ( buildAllExamples_v9 ) [paths: obj64, win64-visualstudio] -- burningvideo: getMaxTextureSize adjusted [ changed meaning of SOFTWARE_DRIVER_2_TEXTURE_MAXSIZE -- burningvideo: mipmaplevel adjusted ( not that bad bokeh...(sometimes) ) - --------------------------- -Changes in 1.8.5 - - Update script to generate tutorial.html's in example folders. Add missing ones. Update existing ones. Thanks @Guillian J for noticing those were outdated. - - Update libpng to 1.6.37 (from 1.6.23) - - Fix CIrrDeviceSDL::getVideoModeList which didn't return video modes before. Thx @kas1e for report and patch. - - CIrrDeviceMacOSX now sets the SEvent.MouseInput Shift and Control values on mouse events like the other devices. Thanks @ Zero King for patch (#321) - - isWindowFocused in IrrDeviceSDL device now returns the input focus like the other devices. Before it was returning a mouse-over-window state. - - Prevent SDL device from dropping OpenGL resources on Win32 when setResizable was called with OpenGL driver. Thanks @ kas1e for reporting (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52083&start=0) - And thanks to http://www.bytehazard.com/articles/sdlres.html for the workaround. - - Fix isWindowActive when using SDL device. Before it was only active when the mouse was over the window. Thanks @ kas1e for reporting (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52083&start=0) - - Fix SViewFrustum::clipLine. Was before clipping at wrong points (inverse places along lines). - - Fix compilation on OSX and prevent capturing mouse cursor when Window is not on top (Patch #319) - Thanks at Artem Shoobovych for bugreport and patch (https://sourceforge.net/p/irrlicht/patches/319/) - - Fix serialization of OverrideTextColorEnabled flag in CGUITab. Thanks @ chronologicaldot for reporting (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52344&p=303891#p303891) - - CFileSystem::getAbsolutePath no longer wrongly converts an empty filename to "/" on unix platforms. - This fixes the bug that CFileSystem::createAndOpenFile("") returned a (strange behaving) non-null file pointer. - Additional check also added in createAndOpenFile to early out on empty names. - - Fix bug in cursor positions when compiled with newer Windows SDK's (v110 in VS2012) and running on Systems >= Windows Vista in windowed mode. - Thanks @Mustapha Tachouct for the bugreport and patch proposal. Also thanks @BakeMyCake for an earlier report. - - IOSOperator::getSysteMemory() no longer returns incorrect values with >2GB. Thanks @Eduline - human development for report and patch. - - Increase KEY_KEY_CODES_COUNT to fix problem with laptop keyboards which return the keycode 0xff for the function key. Thx @Klokancz for bugreport and patch. - - Fix bug when calling activateJoysticks on windows several times. It had appened joystick information instead of replacing it, thereby increasing joystick number on each call. - Only happened compiling with _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ (which is the default). Linux and SDL implementation not affected. - Thx @Andrea Demetrio for the bugreport. - - Fix bug in fast_atof when reading floating point numbers with more than 16 digits past the dot. Those produced completely wrong results (sometimes even causing INF numbers). - This bug also did cause many meshloaders to have problems with certain meshes (basically all text-based formats are affected). - - Accuracy of fast_atof is back to older Irrlicht versions (fixes test warnings, usually not a noticable problem). - - Fix crash in eventhandling when calling remove() on a contextmenu while it has focus. - - CImageLoaderJPG::isALoadableFileFormat uses a test which allows to load more jpg formats (for example uncompressed jpg's). Thx @Yaron Cohen-Tal for report, test-image and his help with the patch. - --------------------------- -Changes in 1.8.4 (9th July 2016, svn r5321) - - Tests on Unix now have a short pause between switching drivers to avoid certain X11 errors. - - Fix CEnumAttribute::getInt() which could crash (thx @ luthyr for reporting) - - No longer try to run tests for drivers not supported on a platform - - Update lights and renderTargetTexture tests to work with Windows 10 (can't have so tiny Windows anymore). - - Deprecate CMatrix4::transformBox as the result is no longer a boundingbox. Use CMatrix4::transformBoxEx instead (which has been available for a long time). - - Fix CSceneCollisionManager::getPickedNodeBB which could sometimes miss collisions. - - Add -U__STRICT_ANSI__ option to c::b project files to allow compiling with -std=c++11 and add an error when trying to compile with Irrlicht with __STRICT_ANSI__ - - Update libpng to 1.6.23 - - Update zlib to 1.2.8 - - Fix some compile warnings in aes which got handled as errors by some c++11 compilers. - - Get rid of some misleading-indentation warnings in gcc6 - - Fix serialization of the InputReceiverEnabled flag in CCameraSceneNode - - Fix pasting text from X11 applications to Irrlicht. Thanks @est31 for the patch. - - Tests give now a warning when stabilizing screenshots failed. Aslo trying more often now (a hack as taking screenshots otherwise fails often in windowed mode on some systems). - --------------------------- -Changes in 1.8.3 (13.9.2015) - - Fix the fix for compiling on GCC5 (thanks to est31 for report and patch) - --------------------------- -Changes in 1.8.2 (30.8.2015) - - - Add VS2013 project files - - Fix compiling with IRR_LINUX_XCURSOR_ - - Fix compiling with NO_IRR_COMPILE_WITH_LIBJPEG_ (thx to anontypist for report and patch). - - Fix compiling on GCC5 on MinGW (thanks to Slipxy for finding the bug and to osense for reporting it). - - Fix loading of .X and .B3D models with non-normalized quaternion rotations (thanks to JLouisB for a test-model). - - Fix compiling on Free BSD (thanks to leper for reporting and patch) - - Fix bug with multiple SetPixelFormat calls. (reported and fixed by anontypist) - - Fix bug related to memory release in PNG image loader. Thanks elephoenix for it. - - Fix crash in CGUIListBox when users pressed end key folled by any other key in an empty, focused list box (thanks at porcus for report and patch). - - Fix use of enabling defines for wal2 (halflife) image loader. Thanks to hendu for noticing. - - Fix userClipPlane test by inserting the stabilizeScreenBackground call - - Demo enables antialiasing now correct (thanks to Mel for noticing). - - Update glext.h (bug #429) - - Example 22 no longer select a random texture after loading a new texture (thanks at mongoose7 for reporting). - - Fix bug in IGUISkin serialization which messed up serialization of the button-pressed offsets (thanks at Midnight for reporting). - - IGUIStaticText::getTextHeight returns now the correct height for texts with newlines even WordWrap is not set. - - Crashfix for CGUIEditBox. CGUIEditBox::setMultiLine must break text when changed or other functions like getTextDimension can crash afterward for strings with newline characters. - - CGUIEditBox and the GUI-Editor now convert pasted text correctly using mbstowcs. - - C::B project files work again on newer Linux-distributions which have cleaned up their dev-lib dependencies. - - Makefile for the new IrrFontTool links now correctly to libfontconfig - --------------------------- -Changes in 1.8.1 (17.11.2013) - - - Improved OpenGL performance under OSX (Thanks devonsoft for reporting). - - Fixed OSX compilation issues. - - [KNOWN BUG] Software driver doesn't work properly under OSX 10.9. - - For speed improvement the following attributes accessible by ISceneManager::getParameters() are no longer updated in release: - "culled", "calls", "drawn_solid", "drawn_transparent", "drawn_transparent_effect". - They can be enabled by compiling Irrlicht with the define _IRR_SCENEMANAGER_DEBUG. - Thanks @hendu for reporting, see http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=48211 for the discussion. - - Fix compile problem with CIrrDeviceSDL on VS2008 (and maybe other systems). Thanks @HellFlip for reporting. - - Fix quaternion::rotationFromTo() (Thanks @takamoto for reporting) - - Fix iszero for s64 (Thanks @chronologicaldot for reporting) - - Fix crash in SoftwareDriver2 when Material was EMT_DETAIL_MAP but texture[1] was not set (Thanks for fix by chronologicaldot) - - Fix buffer overrun in x-loader (Thanks for fix by Otaka) - - Fix cursor visibility update problem under Windows 8 (Thanks @luthyr for reporting) - - Fix irredit links in loadScene/saveScene docs. - - Fix issue in CAnimatedMeshSceneNode::clone which caused a crash. (reported and fixed by luthyr) - - Fix compiling errors for c++ builder (thx @Greatwolf for many patches and @cfanderek for reminding) - - Initialized IColladaMeshWriter::GeometryWriting which was uninitialized. - - Fix linker trouble with irr::core::equalsByUl when compiling Irrlicht as managed code (thx @ Memorial76 for a report + testcase) - - Fix crashes in CCubeSceneNode::clone and CSphereSceneNode::clone (reported by marsupial) - - Fix the clipping in the listbox drawing which was only showing the right line of the sunken pane (reported by Mloren and Abraxas). - - Initialize slider in example 05 correct (reported by Zerochen) - - Fix crash in CMeshSceneNode::clone when the mesh had no shadow (reported by christianclavet, bug-fix found by Nadro) - --------------------------- -Changes in 1.8 (7.11.2012) - - - Let sphere mesh use full opaque color, just as all the other ones do - - - Gcc on Win32 (MinGW) now also works with the _w file access functions when compiled with _IRR_WCHAR_FILESYSTEM. (thx @ alexzk for reporting compile troubles) - - - Fix a bunch of off-by one errors in irr::core::string in functions equals_substring_ignore_case, findFirst, findFirstChar, findNext, findLast, findLastChar, replace, remove and removeChars. - This prevents some potential memory access errors, find functions no longer try to find the \0, replace no longer replaces the \0 and remove no longer tries to remove it (which did remove the last character instead). - - - matrix4::setRotationAxisRadians added - - - user clipplanes fixed - - - Skip rendering of lines, points, and polygons, as these lead to crahses due to wrong access to the vertex lists. A fix would need major rewrite of the vertex cache, or at least some other render methods. - - - Add mipmap generation for makeColorKeyTexture - - - Add another saveScene overload which allows to pass in a user-created XMLWriter. Patch suggested by eversilver. - - - quaternion conversions to and from matrix4 no longer invert rotations. - To test if your code was affected by this you can set IRR_TEST_BROKEN_QUATERNION_USE in quaternion.h and try to compile your application. - Then on all compile-errors when you pass the matrix to the quaternion you can replace the matrix with the transposed matrix. - For all errors you get on getMatrix() you can use quaternion::getMatrix_transposed instead. - - - CGUIEnvironment::loadGui - loading a gui into a target-element no longer messes up when the gui-file contained guienvironment serialization. - - - Colladawriter now exports materials per node when those are used in Irrlicht - - - Colladawriter now writing matrices for node transformations as old solution did not work with CDummyTransformationSceneNode's. - - - Colladawriter no longer create an extra node for the scenemanger as has that job in Collada. - - - Colladwriter no longer makes all Scenenodes children of ambient-light as that can be parallel on the same layer instead. - - - Colladareader now creates the ambient-light correct instead of creating a point-light for it. - - - Add new parameter to array reallocate function. This prevents a reallocation in case the array would become smaller. As the reallocation operation is quite time consuming, this can be avoided on request now, on the expense of more memory consumption. - - - Add IAnimatedMeshSceneNode::getLoopMode (asked for by JLouisB) - - - CSceneNodeAnimatorCameraFPS now resets the key-input when it was disabled (thx @ gerdb for reporting and patch-proposal) - - - Properly destroy OpenGL resources on linux (thx @curaga for the patch) - - - Fix diplay bux in the attribute-panel of the GUIEditor. Fixes bug 3517314 (thx @Darkcoder for reporting). - - - Allow caching cursor position on X11 to work around slow XQueryPointer calls (thx @Hendu for reporting+patch proposal) - - - Make sure after EGET_EDITBOX_ENTER and EGET_COMBO_BOX_CHANGED event processing no more code is executed for the corresponding editbox or combobox objects to allow clearing the environment on those actions (see comments on bug-id 2995838). - - - Fix string::replace which failed replacing substrings at the end when the replacement was longer - - - Struct packing works now with gcc 4.7 changes on MinGW (thx @Sudi for reporting). - - - Struct packing uses now same solution throughout (by including headers in corresponding places) - - - User can now set characters used for decimal point in fast_atof for localisation. - - - Add parameter useAlphaChannel to second IGUIEnvironment::addImage function. - - - Get rid of unnecessary warning "Could not load sprite bank because the file does not exist" for "#defaultfont". - - - Fix MRT disabling. Bug found and fixed by hendu. - - - core:::array::reallocate returning now immediately when it has nothing to do. Should reduce a lot of memory thrashing on irrArrays. - - - Start mesh animations at first OnAnimate , before start-frame was rather random. Thx @Auria for reporting and patch proposal. - - - renderTargetTexture now working with ECF_R5G6B5 - - - add -fPic in c::b linux fast math shared build. - - - Fix by Auria for starting the animated meshes only at first OnAnimate instead of at random times and animation frames. - - - Add support for MAX_COMBINED_TEXTURES, which allows more texture support than with the original fixed pipeline texture check under OpenGL. Now, more than 4 textures should also work with newer gfx cards and drivers, which often only support 4 fixed pipeline textures. - - - triangle3d::isPointInsideFast now using some epsilon to catch all points on the borders. - - - triangle3d::getIntersectionOfPlaneWithLine calculates now with higher precision for more exact results. - - - triangle3d::isOnSameSide (used by isPointInside) calculates now with higher precision and uses some epsilon to make it work with larger integers and less floating point troubles. Slightly slower now. - - - new function equalsByUlp to test for spacing between floating point numbers. - - - speedup for collada writing. - - - speedup for xml-writing. - - - Fix 8bit grey image TGAs, which were not working due to missing palette. Also switched to RGB8 format, as otherwise a loss in precision would occur. Thanks to Klunk for the error report and a test image. - - - fixed issues with a D3D driver and Aero effects. - - - Fix font-drawing in CGUIButton to use EGDF_BUTTON again (thx @DJLinux for reporting). - - - Add texture cache with proper reference handling. This avoids deletion of textures while still being active on the GPU. Test case and fix by m(att)giuca - - - CFileSystem::removeFileArchive now checking for normalized path - - - Fix zip's with passwords on 64-bit systems (thx @ Dr. Gladman for writing the bugfix) - - - replace asserts in tests with macro assert_log to allow running all tests through on problems. - - - added IGUIElement::setName and IGUIElement::getName (similar to ISceneNode) - - - irr::s64 support - - - line2d::getClosestPoint can now also get the closest point on the line additional to only checking for closest point on the line-segment. - - - avoid division by zero in line2d::getClosestPoint when start- and endpoint are identical - - - Support for sw drivers under OSX - - - Fix font-loading which got broken by fixed xml-loading. Thanks @ pc0de for finding and providing a test and patch. - - - Don't crash draw2DSpriteBatch when it get's no textures. - - - Add support for int passing in setShaderConstant - - - Support for better collada texture wrapping support on loading. - - - Fix for render context change where only the window id is given. We now try to change only the window ID, keeping context and display unchanged. Suggestion by vovo4ka from the forum. - - - XML-reader now ignores all whitespace-only EXN_TEXT elements as old way didn't work in cross-platform way (and arguably also not well on Windows). - - - CXMLReader initializes IsEmptyElement now. - - - line2d::intersectWith and and line2d::getClosestPoint work now also with integers. - - - - line2d::intersectWith and and line2d::getClosestPoint work now also with integers. - - - line2d::getMiddle and line3d::getMiddle work now also with integers. But can be slower for compilers which are not optimizing division by 2 to multiplication by 0.5 for floats. - - - Add Nadro's initial Cg support. Example 10 is enhanced to allow also Cg shaders. - - - Add mipmap support from FBO extension, patch by Nadro. - - - Add vertex optimization algorithm submitted by curaga - - - rename texureBlend functions to textureBlend - - - Add threshold for slerp calculation, switching between linear and slerp at this point. - - - Fix for bug 3401933 - vertex color interpolation with shadow volumes in the scene - - - Fixed bug in button sprites reported by RdR - - - Fixed button state sprite animations for pressed, focused and hovered. - - - Added serialization for terrain smooth factor, patch by RdR - - - Implemented more button states for sprite banks, patch submitted by RdR - - - Add IGUIEnvironment::getHovered to get the element most recently known to be under the mouse cursor - - - Add FPS settings for animated meshes, which allows to push animation speed from files to Irrlicht animation system - - - Maya camera updates - - - Add support for bsp brush entities. Written by Hendu. - - - weighted normals recalculation fixed - - - Billboard improvements - - - API docs updates - - - triangle selector improvements - - - OSX improvements by Auria - - - Add new methods for adding and removing file archives based on ifilearchive pointers. - - - Add getBackgroundColor, isDrawBackgroundEnabled and isDrawBorderEnabled to IGUIStaticText (thx 4 patch from Nalin). - - - Reduction of multiple skinning the same mesh and frame in one render cycle - - - Added ISceneNodeAnimatorCameraFPS::getKeyMap and a new ISceneNodeAnimatorCameraFPS::setKeyMap. - - - CSceneNodeAnimatorCameraFPS uses now SKeyMap instead of SCamKeyMap (structs were identical which was confusing and there wasn't any explanation in comments, so I decided to simplify it). - - - Add some workaround to MeshViewer to show how we can currently fix the FPS-cam when users to alt-tab while moving. We can improve that some day when we have focus-events, but this works for now. - - - Fix LZMA decompression - - - Ply normal fixes - - - HW buffers only support rendering with both vertex and index buffers - - - Enables VBOs for water node - - - Octree support for non-standard vertex meshes - - - Fix rotationFromTo - - - Added ConstIterator - - - Fix for getScreenCoordinatesFrom3DPosition to use proper RTT sizes - - - Add IGUIComboBox::setMaxSelectionRows and IGUIComboBox::getMaxSelectionRows - - - Scenemanager switches from type ESNT_UNKNOWN to type ESNT_SCENE_MANAGER. - - - Add getActiveFont to all elements which have setOverrideFont for cleaner code - - - Add getOverrideFont to all elements which have setOverrideFont to have a consistent interface - - - IGUIEditBox: added missing serialization for Border - - - IGUIEditBox: remove bug that added spaces to the end of each line - - - IGUIEditBox: fix crash that happened when wordwrapping was enabled, spaces were entered beyond the border and then cursor-key was pressed. - - - IGUIEditBox::setDrawBackground added. - - - CGUISkin::draw3DSunkenPane no longer ignores fillBackGround in non-flat mode. Also borderlines are no longer drawn overlapping to avoid ugly corners. - - - CDummyTransformationSceneNode::clone() added. - - - IParticleSystemSceneNode::doParticleSystem now public to allow rendering outside scenegraph. - - - getRelativeFilenames updates and fixes - - - Renamed IOSOperator::getOperationSystemVersion to getOperatingSystemVersion. Changed return type from wchar_t to core::stringc, as that's the internal representation the name is built on. - - - Added IGUITabControl::insertTab, IGUITabControl::removeTab, IGUITabControl::clear and IGUITabControl::getTabAt - - - Add 32bit support to some mesh manipulator methods - - - Fix mipmap locking under OpenGL - - - Improvement of screenshot function to support more color formats and targets - - - getAngle fix to avoid NaNs - - - Available gfx memory output in log messages - - - Improved 2d render settings and caching - - - Initial suppport for sRGB render functions - - - Improved terrain scene node rendering - - - Paletted png image support fixed - - - Gamma settings in image loaders improved - - - Support for relative filenames in serialization - - - Access to selectors inside meta selectors implemented - - - DirectInput joystick support - - - Support for scaling with draw2dimage with burnings video - - - More gl extensions have correctly initialised return values - - - Some fixes for quaternion to euler function - - - Properly return nullptr if RTT creation fails on low levels - - - Added IGUIListBox::getItemAt - - - Add more image formats tried to load by q3 level loader - - - Add fast_atof improvements from assimp, also strtoul10 method - - - Add blend equation function for MRTs - - - Add new material fields for blend operation and polygon offset (depth bias). - - - Reorder texture stage assignments - - - Improved VSync handling - - - Fix Ogre loader for materials with more than one texture - - - Fix createMeshCopy material handling - - - Framework target for OSX project added - - - Terrain scene node fixes - - - Fix HSL color class - - - Fix color selection GUI element - - - Transparency issues in particle system fixed - - - Particle sphere emitter rand values fixed - - - Support Unicode SHY dynamic hypen in word wrap - - - Fix OBJ reader sometimes running over EOF - - - Added IGUITable::getColumnWidth - - - Billboard text animates in OnAnimate now - - - Fix mountpoint reader to properly sync file names and firectories - - - Added the ability to open an archive from an IReadFile*, added a FileToHeader tool with instructions of how to make a portable app that consists of a single executable file. - - - Added suppport for right-to-left (RTL) text, supplied by Auria from STK - - - Added ISceneManager::createSceneNodeAnimator to create animators by name - - - The Makefile now creates a symlink from the soname to the binary name during install. Binary compatibility is only confirmed between same minor releases. - - - Added SMF mesh loader, loads meshes from 3D World Studio. Originally written by Joseph Ellis - - - The loader selection process now consistently checks loader lists in reverse order, so new loaders added to Irrlicht override the internal ones. This applies when adding external mesh, image, scene and archive loaders, image writers, plus node, animator and GUI element factories. - - - Added getters to retrieve mesh, scene and archive loaders. - - - Added ISceneLoader interface and .irr loader. Users can now add their own scene loaders to the scene manager and use them by calling loadScene. - - - Renamed IGUIElement::bringToBack to sendToBack, like in Windows - - - Send EGET_ELEMENT_CLOSED event when context menus should be closed (thx @ Mloren for reporting). - - - Added treeview to GUI editor, provided by Armen - - - Added root type for GUI environment - - - zip archive fixes: Fix directory tags in file list. Fix loading of stream zip files which have file sizes only in the central directory. - - - Fixed panel scrollbars in GUI editor, reported by Armen - - - Fix b3d loading of files with mixed mesh/bone sections. - - - Fix particle emitters which used integer random numbers so far. The distributions of the particles should be much better (and the code also somewhat faster) now. - - - Add new random method frand: Returns a random number in the interval [0..1] and gives better distributions than using fmodf on the integer number. - - - Add node parameter to saveScene and loadScene. saveScene saves the given node and all descendants to the file (if 0, the full scene is saved as before). loadScene loads all elements of the scene as childs of the given node. As before, 0 would load the file on the top level (scenemanager). - - - Add method to make a filename relative to a given directory. - - - Fix setMesh to correctly update the joints cache. - - - Fix setting transition time of skinned meshes back to 0. - - - Add some getters to IGUIImage: getImage, getColor - - - Fix OpenGL FBODepthTexture to create less overhead - - - Fix MRT disabling under OpenGL - - - API change: Added write only lock mode for textures. The lock method has changed the signature and uses an enum parameter now instead of a bool. The default is still to lock for read/write (previously 'false'). The old 'true' value should be replaced by ETLM_READ_ONLY. - - - Speedup deleting of particles - - - Add function IParticleSystemSceneNode::clearParticles - - - Fix RTT render states under OpenGL - - - Fix AntiAliasing setup under Windows/OpenGL in case no AA is available - - - Fix transformation matrices when RTT used - - - API change: getScreenCoordinatesFrom3DPosition has a new parameter, which needs to be set to true to get the original behavior. Now, the method returns coordinates which would fit as render coordinates of a currently enabled viewport. With the parameter set to true the result would fit only after the viewport is reset to full window rendering. - - - More checks for Stencilbuffer - - - Improve render state resets - - - Fix MRT handling - - - Fix file search - - - Add flag and method to disable clipping of the text to the gui element rectangle in GUI static text. - - - addShadowVolumeSceneNode now replaces an existing shadow. One should avoid to call this method multiple times without changing any parameter, as it is quite time consuming and cannot recognize the duplicate calls. - - - Add function IGUIEnvironment::removeFont (TODO: Does not remove the texture from cache so far) - - - Fixed mem leak in mountfilesystem - - - Update to libjpeg 8b, zlib 1.2.5, bzip2 1.0.6, libpng 1.4.4 and lzma from 9.20 SDK - - - Functions in IMeshCache expecting IAnimatedMesh* parameters removed as similar functions with IMesh* can be used since a while. Fixes also problems when IAnimatedMesh* got upcasted to IMesh*. (thx @ Greenya for reporting) - - - Fix blend states for MRTs - - - 64bit targets for MSVC added - - - The following functions will now use a "ISceneNode *" instead of a "const ISceneNode *": - ITriangleSelector::getSceneNodeForTriangle, ISceneNodeAnimatorCollisionResponse::getCollisionNode, ISceneCollisionManager::getCollisionPoint and ISceneCollisionManager::getCollisionResultPosition. - As collision functions often are followed by changing node positions users where so far forced to using const_casts (found by Greenya). - - - Add vector3d::getAs3Values (patch provided by slavik262) - - - Add function to SViewFrustum to get corners of the near plane (patch provided by Matt Kline, aka slavik262) - - - ParticleFadeOutAffector::setFadeOutTime can no longer be set to invalid values - - - ParticleFadeOutAffector uses now throughout u32 for fadeOutTime (found by greenya) - - - Add missing access function CParticleSystemSceneNode::getAffectors() (seen by B@z) - - - Add missing setters/getters for particle emitters (seen by B@z) - - - Compile-defines can now be disabled from Makefiles/Projectfiles instead of having to change IrrCompileConfig.h each time. - - - IGUITabControl::setActiveTab should only take IGUITab* and not IGUIElement* (thx to greenya for finding) - - - Add new skin-colors: EGDC_GRAY_WINDOW_SYMBOL, EGDC_EDITABLE, EGDC_GRAY_EDITABLE, EGDC_FOCUSED_EDITABLE - - - Disabled state is now extended to sub-elements - - - Make disabled state for several elements more visible - - - Bugfix: Icons in tabcontrol get now affected immediately by skin-changes - - - Proper cleanup if visual not created - - - XML reader bugfix - - - Disable mipmaps in 2d mode everywhere - - - Add xml example written by Yoran Bosman. - - - Fix cursor cleanup under Linux when using multiple devices - - - Fix collada parser - - - Fix MRT reset under D3D - - - Add a generic attribute interface for querying video driver attributes which are not necessarily of type bool. This interface allows to check certain supported features, such as the number of user clip planes, supported lights and textures, MRTs, and other things. The interface might change in the future, but it's fully functional already. The supported attributes are listed in the API docs of the function: -The following names can be queried for the given types: - * MaxTextures (int) The maximum number of simultaneous textures supported by the driver. This can be less than the supported number of textures of the driver. Use _IRR_MATERIAL_MAX_TEXTURES_ to adapt the number. - * MaxSupportedTextures (int) The maximum number of simultaneous textures supported by the fixed function pipeline of the (hw) driver. The actual supported number of textures supported by the engine can be lower. - * MaxLights (int) Number of hardware lights supported in the fixed function pipeline of the driver, typically 6-8. Use light manager or deferred shading for more. - * MaxAnisotropy (int) Number of anisotropy levels supported for filtering. At least 1, max is typically at 16 or 32. - * MaxUserClipPlanes (int) Number of additional clip planes, which can be set by the user via dedicated driver methods. - * MaxAuxBuffers (int) Special render buffers, which are currently not really usable inside Irrlicht. Only supported by OpenGL - * MaxMultipleRenderTargets (int) Number of render targets which can be bound simultaneously. Rendering to MRTs is done via shaders. - * MaxIndices (int) Number of indices which can be used in one render call (i.e. one mesh buffer). - * MaxTextureSize (int) Dimension that a texture may have, both in width and height. - * MaxGeometryVerticesOut (int) Number of vertices the geometry shader can output in one pass. Only OpenGL so far. - * MaxTextureLODBias (float) Maximum value for LOD bias. Is usually at around 16, but can be lower on some systems. - * Version (int) Version of the driver. Should be Major*100+Minor - * ShaderLanguageVersion (int) Version of the high level shader language. Should be Major*100+Minor. - - - Fix getRotationDegrees - - - Add creation parameter which allows to disable highres timers on Windows upon device creation. - - - Several transparency setup bugs fixed. Now, alpha_vertex_blend uses proper alpha blending instead of a mixed add/alpha blending. - - - Added a method to get real time and date in a human readable struct - - - Fix add folder archives method to support files without trailing slashes. - - - fix transparent_reflection_2_layers - - - Add support for MSVC 2010 - - - Fix "unsupported format" warning on RTT usage - - - Add IGUIElement::bringToBack (patch written by DtD, although I'm to blame for the function-name) - - - BurningVideo - - add Normalmap Rendering (one light only), pushed Burningvideo to 0.46 - - add Stencil Shadow Rendering (one color only and 32 bit only), - pushed Burningvideo to 0.47 - - internal vertexformat changed - - changed fixpoint from 9 to 10 bit fract resolution - - renamed createBurningVideoDriver to createBurningVideoDriver and uses SIrrlichtCreationParameters like opengl - - internal interfaces for the trianglerenders unified. - - - Example 11, changed the light billboards to use the light color. - allow to disable the bump/parallax on the earth like in the room ( with transparency ) - - - added DDS Image files, DXT2, DXT3, DXT4, DXT5, based on code from nvidia and Randy Reddig - - - added Halflife 1 Model Loader (based on code by Fabio Concas) - Halflife 1.1.0.8, Counter-Strike 1.6 working - -> Load all Textures ( can even optimize it to texture atlas ), all bone animation, all submodels. - -> But to make use of the values (named animation, mouth animation) - the Interface for IAnimatedMeshSceneNode has to be redone. - - TODO: - ->can handle float frames numbers, the interface for getMesh should be reworked - This is my idea of a new getMesh interface for IAnimatedMesh - - //! Returns the IMesh interface for a frame. - /** \param frameA: Frame number as zero based index. - The Blend Factor is in the fractional part of frameA - The Mesh will be calculated as - frame = integer(frameA) * (1-fractional(frameA )) + frameB * fractional(frameA) - FrameNr KeyFrameA KeyFrameB - 40.0 1 0 - 40.1 0.9 0.1 - 40.5 0.5 0.5 - 40.9 0.1 0.9 - 41.0 0 1 - \param frameB: Frame number as zero based index. The other KeyFrame which is blended with FrameA. - \param userParam: for Example Level of detail, or something else - */ - virtual IMesh* getMesh(f32 frameA, s32 frameB = 0,s32 param = 0) = 0; - - For now i used the (unused, always 255) detail level parameter and set a blend percentage as - s32 frameNr = (s32) getFrameNr(); - s32 frameBlend = (s32) (core::fract ( getFrameNr() ) * 1000.f); - return Mesh->getMesh(frameNr, frameBlend, StartFrame, EndFrame); - - So no interface is affected. - - -> TODO: Quaternion Rotation is done private hand made and should be done with irrlicht quaternions - - - Included 357kb Yodan.mdl mesh and copyright info file from Doug Hillyer - to the media directory, used in example 7. collision as 4th model. - - - added Halflife 1 Texture Loader - Valve uses WAL archive types like quake2. textures are inside model files - I reworked the existing ImageloaderWAL and added named Halflife textures to wal2 ( they have no extension ) - and an LMP (palette/texture) loader into the same file (all using 32bit now) - - - added WAD Archive Loader (Quake2 (WAL2) and Halflife (WAL3) are supported) - - - CFileList - added Offset Parameter to SFileListEntry and removed the private array from the archive loaders. - CFileList::addItem now uses automatic incremental id if id = 0 - - - added void splitFilename, splits a path into components - - - added parameter make_lower to substring ( copy just lower case ) - string subString(u32 begin, s32 length, bool make_lower = false ) const - - - ColorConverter added - //! converts a 8 bit palettized or non palettized image (A8) into R8G8B8 - static void convert8BitTo24Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad = 0, bool flip=false); - //! converts a 8 bit palettized or non palettized image (A8) into A8R8G8B8 - static void convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad = 0, bool flip=false); - - - In IGUITreeView "clearChilds" and "hasChilds" deprecated for "clearChildren" and "hasChildren" (thx @Greenya for noticing) - - - add CGUIEditBox::getOverrideColor and CGUIEditBox::isOverrideColorEnabled - - - add dimension2d::operator- - - - Add logging level ELL_DEBUG - - - Add parameter DisplayAdapter to creation params to allow selecting the card when more than one card is in the system. - - - Added support for custom cursors - - - WM_SYSCOMMAND - SC_KEYMENU message is now ignored (F10 and ALT in Win32 windowed mode) - - - Avoid argument lookup ambiguity in swap when used in combination with stl. Using same trick as boost now and use 2 different template parameters in it. - - - Add UseMipMap flag in material - - - Add occlusion query support. Based on code by Nadro - - - Add support for vertex_array_bgra extension in OpenGL driver. This will speed up OpenGL rendering quite a lot as it skips the silly color conversion thing we have to do otherwise. - - - Replace raw xml char implementation with template struct in order to decouple the type from POD types. May also help for 64bit problems or changes needed there. - - - Fixed bug causing memory access violation in string::replace found and patched by Nalin. - - - Fix windows32 class unregister - - - Add parameter to line2d::intersectWith to allow getting intersections outside the segments (thx Yoran). - - - External windows are not destroyed anymore - - - clamp values in getRotationDegrees to avoid nan values - - - texture size in terrain mesh fixed - - - ms3d fixes - - - Add new matrix methods for infinite projection matrix - - - Support new OpenGL 2.x shader creation - ------------------------------ -Changes in 1.7.4 (not yet released) - - - fixed getDepthFunction in IQ3Shader which always returned ECFN_EQUAL due to missing break (found by the cppcheck tool) - - - STL loader improved to handle arbitrary file starts - - - Compiler problem with gcc4.6 and big endian systems fixed - - - Change include order to get example 21 compiling on MinGW. - - - Irrlicht.dll has correct name now again (was named libIrrlicht.dll in c::b). This fixes bugreport 3518765 reported by tetho. - - - Fix linker path in example 16 for C::B project file (linker path was in include path section). - - - Link with opengl32 and gdi32 in Example 14 in C::B. - - - Remove --no-export-all-symbols which got recently added to the windows build as that flag is not known by gcc on Windows. - - - Fix bug in example 23 where Width and Height got mixed up. Thanks @Lazier for reporting. - - - Fix for R5G6B5 converter submitted by XMight - - - Fix conversion warning under mingw, found by Randajad - - - Set EMF_NORMALIZE_NORMALS correct for syndey model in Demo (thanks @ Midnight for reporting). - - - SceneNodeAnimatorFlyCircle fixes serialization of RadiusEllipsoid (was writing Radius). Thx @ wing64 for reporting. - - - Yield on Linux now uses nanosleep with 1ns as 0 isn't guaranteed to yield (thx @ hendu for finding + fix) - ------------------------------ -Changes in 1.7.3 (20.02.2012) - - - SceneNodeAnimatorFlyCircle fixes serialization of RadiusEllipsoid (was writing Radius). Thx @ wing64 for reporting. - - - Yield on Linux now uses nanosleep with 1ns as 0 isn't guaranteed to yield (thx @ hendu for finding + fix) - - - GUIEditor attributes have now scrollbar to be editable - - - Remove warning when compiling line2d::intersectWith with other types than f32. - - - Document that triangle3d::isPointInside should not be used with int's. - - - triangle3d::isPointInsideFast handles 'on-border' cases now consistently. - - - Some more editbox fixes - - - Harden Linux joystick usage, in case the driver returns illegal values - - - Some more editbox fixes - - - Harden Linux joystick usage, in case the driver returns illegal values - - - Bugfix: vector2d.normalize() and vector3d.normalize() had returned wrong results with very short vectors since Irrlicht 1.5. Thanks to Willem Swart for Bugreport + testcase. - - - Unknown keymappings now use the X11 keycode instead of 0 to make such keys at least usable in games. - - - KeyMapping for KeyInput.Key on X11 ignores states like shift&ctrl now like on Windows. - - - Additional keymappings for X11 (tested with german and us keyboards which seem to work now in all cases). - - - Fix crash in multiline editbox when pasting several lines into it on Windows (found by Reiko) - - - example 09.Meshviewer no longer catches keys while a modal dialog is open - - - Fix SSharedMeshBuffer - - - Fix right handed ortho matrix - - - editbox no longer displays cursor when disabled - - - editbox autoscrolling now at least works good enough to actually show the text which the user is typing in. - - - editbox no longer moves text into next line when it fails wrapping creating senseless empty lines which mess up scrolling. - - - Fix crash in editbox when scrolling up with empty first lines caused by textwrapping. - - - Fix endianess conversions - - - Changes to isPointInside - - - Fix focus problem when removing an unfocused modal dialog reported by Reiko here: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=44358 - - - Fix md2 normals problem again - - - Add integer template specialization for vector3d::getSphericalCoordinateAngles which rounds angles to nearest integer now. - - - Recalculate FrameRect and ScrollPos in CGUIEditBox when AbsoluteRect gets changed (thx @ serengeor for report + testcase) - - - Fix crash in editbox - - - Fix crash in editbox - - - Fix 'k' in bigfont.png (thx @ Scrappi for reporting) - - - fix serialization for CBillboardSceneNode, it had missed 2 color (thx for finding + patch from pc0de) - - - EMIE_MOUSE_WHEEL messages now handled correctly in several gui-element when wheel isn't just 1.0 or -1.0 (thx @ Reiko for reporting) - - - Fix problems in Textwrapping in CGUIStaticText. Did use wrong size and did ignore last word of the text (thx @ Reiko for bugreport) - - - Fix crash in collada (.dae) loading - - - Fix bug handling in case RTT is not properly created - - - Fix SColorf interpolation - - - Fix bug handling in case RTT is not properly created - - - Fix SColorf interpolation - - - Fix memory-leaks in example 22 MaterialViewer - - - Fix array::erase which did destroy objects more than once when used with a range (thx @ RedDragCZ for reporting + testcase). - - - Copy now all membervariables for CCameraSceneNode when cloning. - - - ICameraSceneNode::IsOrthogonal is correctly serialized and cloned now. - - - CGUIScrollBar passes unused mousemove-events now to parent element. Fixes focus-bug in ComboBox reported by REDDemon here: http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=43474&highlight= - - - Fix getAngle and getAngleWith - - - Fix clipping in CGUITabControl - - - Fix clipping in CGUITable, reported by ceyron - - - Skip bone weights and additional information in ms3d file if no joint was defined before. - - - Fix mem leak in CImage, found by mloren. - - - Fix tga writing, reported by xirtamatrix - - - Tab-positions care now about the borders correctly - - - TabControl now respositions it's tabs when setTabVerticalAlignment is changed (thx @ ceyron for reporting+testcase) - - - CGUIModalScreen now no longer takes focus itself, but tries to give it first child when possible to fix modal windows losing focus all the time - - - Modal screens no longer blinks when gui-elements call removeFocus on themself (thx @ yaten for reporting+testcase) - - - Fix crash in multiline-editbox when selecting with mouse (thx @ ceyron for reporting and testcase) - - - Fix render context creation for OpenGL under Windows. - - - Fix the reset problem of d3d9 driver in combination with hardware buffers. - - - Fix .x loader in case of unused vertices. - - - Avoid empty line in texts with very large words. Text wrapping would introduce an empty line in earlier versions. - - - Add a new attribute which assigns hw mapping hint to the whole Mesh. - - - Allow creation of water scene node without mesh. - - - Fix regeneration of skydome. - - - Fix scene node type and factory support for volume light - - - Q3 maps no longer crash when faces try accessing lightmaps which are not mentioned to be loaded in the file. - - - Fix crash on null-readfile in texture loading - - - Get particles saved before 1.7.2 (for example in irrEdit) working again (thx to smashly for problem reporting) - - - Fix IGUIScrollBar setMax and setMin which had been restricted wrongly (reported by REDDemon) - - - Fix CNullDriver::createImage - Creating the image from a texture-rectangle which doesn't start at 0,0 works now again (thx @ ceyron for bugreport+testcase) - - - Menu no longer sets highlight state when clicking disabled menu-item (reported by Mloren) - - - Treeview can now be disabled - ------------------------------ -Changes in 1.7.2 (15.11.2010) - - - Fix in d3d9 driver, which caused a crash when device creation failed. Bug found and fixed by Kostya - - - Fix a wrong access to Value instead of ValueW. Found and fixed by vroad. - - - Fix line loop rendering in d3d drivers. Fix submitted by tonic. - - - Fix tar recognition in tar reader. - - - Fix blend mode setup in OpenGL driver, when using the material2d override, as pointed out by Auria - - - Avoid crash due to tcoords2 handling. Might need some more fixing to work correctly. - - - Fix 2d line intersections. Has had problems with consecutive, but non-overlapping line segments and with overlapping line segments. - - - Fix image creation from texture, found by dataslayer - - - Fix crashes when taking Screenhots for DirectX in Windowed mode (thx to agamemnus for reporting) - - - StaticText does now serialize the background color - - - Fix gui-elements which didn't care when skin-colors changed. That made it impossible to make the gui slowly transparent (thx to PI for reporting). - Note that it couldn't be completely fixed for the SpinBox without breaking the interface, so for that element you have to enforce this by calling for example element->setValue(element->getValue()) once. - - - Fix CXMLReaderImpl::getAttributeValueAsInt which returned wrong values with large integers (thx to squisher for finding) - - - Fix compile problem in swap when using irrlicht in combination with stl (backport from trunk r3281) - - - Add EGET_TREEVIEW_NODE_COLLAPSE and deprecate EGET_TREEVIEW_NODE_COLLAPS (found by greenya) - - - Fix serialization in CParticleSystemSceneNode (found by B@z) - - - Prevent crash in BillboardTextSceneNode when a custom font is used. Found and fixed by Nalin (bugtracker id: 3020487) - - - Fix problem in animation system that currentFrame got messed up after long pauses (especially when not starting at frame 0). - See forum thread (http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?p=210537#210537) and bug id 2898876. - Also remove BeginFrameTime in CAnimatedMeshSceneNode as it hasn't been used anymore since some time. - - - Add framerate and current frame information for animations in example 09 and do some minor cleanup. - - - Added another test for xml-reader. - - - Fix serialization in several particle emitters and affectors (thx to Ion Dune for reporting). - - - Fix compile-error on VS for vector2d::getAngleTrig when used with integers. (thx to greenya for reporting) - - - Fix bug in dimension2d::getInterpolated that caused wrong results when used with integers as template parameter. (thx to Greenya for noticing a warning which made me look over this code). - - - Remove 2 minor memory leaks in meshloaders (found by tool cppcheck-1.43) - - - reduce file dependencies for IGUIEventReceiver.h (thx ngc92) - - - Initialize GUIEvent.Element in several places (found by greenya) - - - Add EGDS_MESSAGE_BOX_MAX_TEXT_WIDTH and deprecated EGDS_MESSAGE_BOX_MAX_TEST_WIDTH (thx to greenya for reporting). - - - Fix colors in irr files. - - - Fix several places where "used" in core::string was used wrongly preventing some memory corruption - - - Remove additional slash in pathnames in X-Loader - - - Fix crash in CGUIListBox when environment was cleared on events - - - Bugfix: Clear up depth-textures which could not be attached in OpenGL to prevent crashes. - - - Fix arrowMesh boundingbox. - - - Fix rounding problem in getInterpolated in the color classes - - - Scrollbar in GUIListbox now uses default id -1 instead of 0 - - - Fix octree clipping issues. - - - Fix obj loader. - - - clone function fixes. - - - Fix tooltips. - - - Fix Ogre parser. - ------------------------------ -Changes in 1.7.1 (17.02.2010) - - - Fix octree with frustum+parent checks enabled (didn't clip at all before). Now using plane-checks instead of edge-checks for frustum-box intersection. - - - Prevent that X11 selects larger resolutions in fullscreen even when perfect fits are available. - - - Ignore setResizable also on X11 when we're fullscreen to avoid messing up the window mode. - - - Work around a crash when pressing ESC after closing a Messagebox (found by Acki) - - - Prevent borland compile warnings in SColorHSL::FromRGB and in SVertexColorThresholdManipulator (found by mdeininger) - - - Improve Windows version detection rules (Patch from brferreira) - - - Make it compile on Borland compilers (thx to mdeininger) - - - Make sure that CAnimatedMeshSceneNode::clone calls the virtual updateAbsolutePosition for the new object - - - Fix that clones got dropped too often when SceneNodes without parent got cloned (found by Ulf) - - - Make sure TAB is still recognized on X11 when shift+tab is pressed. This does also fix going to the previous tabstop on X11. - - - Send EGET_ELEMENT_LEFT also when there won't be a new hovered element - - - Update docs for EGET_ELEMENT_LEFT and EGET_ELEMENT_HOVERED - - - Fix tooltips: Remove them when the element is hidden or removed (thx to seven for finding) - - - Fix tooltips: Make (more) sure they don't get confused by gui-subelements - - - Fix tooltips: Get faster relaunch times working - - - Fix tooltips: Make sure hovered element is never the tooltip itself - - - Fix string::remove which got in an endless loop when remove was called with an empty string (found and fixed by Ulf) - - - Correctly release the GLSL shaders - - - Make sure we only release an X11 atom when it was actually created - - - Fix aabbox collision test, which not only broke the collision test routines, but also frustum culling, octree tests, etc. - - - Fix compilation problem under OSX due to wrong glProgramParameteri usage - - - mem leak in OBJ loader fixed - - - Removed some default parameters to reduce ambigious situations - ---------------------------- -Changes in 1.7 (03.02.2010) - - - Implement minimize and deminimize under OSX. - - - Define sorting order for vector2d and vector3d in operators <, <=, > and >= to fix bugs 2783509 and 2783510. Operators order now by X,Y,Z and use float tolerances. - - - Ogre mesh 32bit indices fixed. - - - Fix tooltips for gui-elements with sub-element like IGUISpinBox (id: 2927079, found by ArakisTheKitsune) - - - ITimer no longer stops when started twice - - - wchar_t filesystem updates under Windows. - - - Joystick POV fixed under Windows, ids fixed under OSX. - - - Some updates to skinned mesh for better bones support and scaling animations. - - - OSX supports external window id in creation parameters now. - - - Fix bbox collision tests. - - - Updates for win32 key handling - - - new convenience method for flat plane creation. - - - Sky dome and other meshes use VBOs by default now. - - - Speed up b3d loading for files with many frames, material color flags and vertex color support enhanced. - - - Add hasType to IGUIElement as a dynamic_cast substitute. - - - Add another parameter to IGUISkin::draw3DWindowBackground to allow getting the client area without actually drawing - - - Add function getClientRect to IGUIWindow for getting the draw-able area - - - Fix bug that menus on IGUIWindows with titlebar got drawn too high (id: 2714400) - - - Renamed OctTree to Octree - - - Allow getting a ConstIterator from a non-const core:list - - - Add swap functions to irrMath and to the core classes. - - - Deprecate map::isEmpty() and replace it with map::empty() to make it similar to other base classes. - - - Allow to set the logging level already in SIrrlichtCreationParameters. - - - Add clearSystemMessages to devices (implemented only for Linux and Win32 so far). - - - Support changing the render window from beginScene also with OpenGL driver. - - - Add getMaterial2D which allows to alter the 2d render state settings, such as filtering, anti-aliasing, thickness, etc. - - - Fix incorrect cursorpos for resizable windows on Windows Vista (found and patched by buffer) - - - Change the beginScene window parameter from void* to SExposedVideoData&. This will allow to manage contexts for OpenGL at some point. - - - Add bzip2 and LZMA decompression modes for zip loader. - - - Add OBJ_TEXTURE_PATH and B3D_TEXTURE_PATH to SceneParameters to allow setting texture-paths for obj and b3d. - - - Irrlicht keeps now filenames additionally to the internally used names, thereby fixing some problems with uppercase-filenames on Linux. - - - Bugfix: Mousewheel no longer sends EMIE_MOUSE_WHEEL messages twice on Linux. - - - Use latest jpeglib - - - refactoring: E_ATTRIBUTE_TYPE and IAttribute have now own headers - - - CStringWArrayAttribute speedup - - - SceneNodeAnimatorFollowSpline can now loop and pingpong - - - Meshviewer.example got some fast-scale buttons. - - - Support AES-encrypted zip files. Should work with 128, 196, and 256 bit AES. This addition also adds a new PRNG, SHA, and other algorithms to the engine, though no interface is yet added for them. The implementation of the encryption algorithms is provided by Dr Brian Gladman. - - - flattenFilename and getAbsolutePath fixed and properly added at several places. - - - Added geometry shaders for OpenGL. A first version of the code was submitted by Matthew Kielan (devsh). - - - Bugfix: irrArray should no longer crash when using other allocators. - - - Add MaterialViewer example. - - - Texture activation now back in setMaterial, which simplifies writing external material renderers (OpenGL only). - - - Checkbox uses now disabled text color when disabled. - - - Changed colors for window-title caption to keep them readable when not active. - - - Draw sub-menus to left side if they would be outside main-window otherwise. - - - Give ListBox better defaults for the ScrollBar stepsizes. - - - Double and triple click events now for each mouse-button. Old events for that got removed. - - - Fix adding archives twice, which caused multiple archives of the same name and type covering each other. This one required a texture name change from using backslashes to slashes under Windows. - - - Give access to texture mipmaps. You can provide custom mipmap textures upon generation, regeneration, and locking. - Make sure the provided data is large enough and covers all miplevels. Also the returned pointer (from lock) will only cover the smaller data of the mipmap level dimension chosen (level 0 is the original texture). - - - Separate TextureWrap mode into U and V fields - - - Add mirror texture wrap modes - - - windows show now active/inactive state - - - remove unneeded drop/grab calls found by manik_sheeri - - - fix rounding problem in IGUIElements which have EGUIA_SCALE alignments. - - - MessageBox supports now automatic resizing and images. - Deprecated EGDS_MESSAGE_BOX_WIDTH and EGDS_MESSAGE_BOX_HEIGHT - - - Let maya-cam animator react on a setTarget call to the camera which happened outside it's own control - - - New contextmenue features: - automatic checking for checked flag. - close handling now customizable - serialization can handle incomplete xml's - setEventParent now in public interface - New function findItemWithCommandId - New function insertItem - - - new vector3d::getSphericalCoordinateAngles method. - - - new triangle3d::isTotalOutsideBox method. - - - Newly introduced VertexManipulator interface. This allows for very easy creation of vertex manipulation algorithms. Several manipulators, e.g. vertex color changer and transformation algorithms are already available. - - - createMeshWith1TCoords avoids vertex duplication - - - getRotation now handles matrices with scaling as well - - - Ogre format animations now supported. - - - irrArray: Fixed issues with push_front and reallocation - Changed behavior for set_pointer and clear, when free_when_destroyed is false - - - NPK (Nebula device archive) reader added, it's an uncompressed PAK-like format - - - SSkinMeshBuffer::MoveTo* methods renamed to convertTo* - - - Multiple Render Target (MRT) support added, including some enhanced blend features where supported - - - Directory changing fixed for virtual file systems (Archives etc) - - - Fix texture matrix init in scene manager and driver - - - More draw2dimage support in software drivers - - - Sphere node now properly chooses a good tesselation based on the parameters - - - Active camera not registered twice anymore - - - Parallax/normal map shader rotation bug under OpenGL fixed - - - bump map handling for obj files fixed - - - Fog serialization added - - - New context menu features added - - - Bounding Box updates for skinned meshes fixed - - - The current FPS for an animated scene node can be queried now, added some variables to serialization - - - Scrollbars fixed - - - Fixed 2d vertex primitive method to correctly handle transparency - - - Fullscreen handling has been enhanced for Windows, now proper resolution is restored on Alt-Tab etc. - - - Cameras can now be added to the scene node without automatically activating them - Clone method added - - - New video driver method getMaxTextureSize - - - PAK archive reader fixed - - - TRANSPARENT_ALPHA_CHANNEL_REF uses modulate to enable lighting - - - LIGHTMAP_ADD now always uses add operator - - - Some Unicode file system fixes - - - destructor of irrString not virtual anymore, please don't derive from irrString - Some new methods added, for searching and splitting - Assignment operator optimized - - - new lightness method for SColor - - - draw3DTriangle now renders filled polygons, old behavior can be achieved by setting EMT_WIREFRAME - ------------------------------ -Changes in 1.6.1 (13.01.2010) - - - Fix pingpong for CSceneNodeAnimatorFlyStraight (found by gbox) - - - Fix bug with IGUIEditBox where the cursor position is reset on text change. - - - Make sure the window top-left corner on Windows is not negative on start so that Windows sytem-menu is always visible. - - - Fix problem that the window did sometimes not get the keyboard focus in X11 in fullscreen. Add more debug output in case focus grabbing goes wrong. - - - Fix screensize in videodriver when we didn't get the requested window size. This also prevents that gui-clicks are no longer synchronized with gui-drawing and elements can't be hit anymore. - - - Bugfix: Prevent a crash when getTypeName was called for the guienvironment. EGUIET_ELEMENT got changed for this. - - - Bugfix: Horizontal centered font with linebreaks draw now all lines. For example multiline TextSceneNodes work again. - - - Bugfix: spinbox can no longer get in an endless loop due to floating point rounding error (found by slavik262) - - - !!API change!! Disabled AntiAliasing of Lines in material default - Please enable this manually per material when sure that it won't lead to SW rendering. - - - IGUIComboBox: clicking on the statictext displaying the active selection does now close and open listbox correctly. (Bug found by Reiko) - - - Scrollbuttons in IGUITabControl adapt now to tab-height. - - - Fix texturing of cylinder mesh - - - Fix modal dialog position (found by LoneBoco: http://sourceforge.net/tracker/?func=detail&aid=2900266&group_id=74339&atid=540676) - - - Fix DMF loading - - - Fixing left+right special keys (ctrl, shift, alt) on Win32 (thanks to pc0de for good patch-ideas). - - - Make stringarrays for enums in IGUISkin a little safer - - - Add support for keys KEY_PRINT, KEY_HOME (on numpad) and KEY_NUMLOCK on Linux. - - - Fix material handling in createMeshWith1TCoords - - - Fix another (OldValue == NewValue) before drop()/grap(), this time in CTextureAttribute::setTexture. - - - Fix LIGHTMAP_LIGHTING for D3D drivers. - - - AntiAliasing disabled for debug render elements. - - - Bugfix: CGUIToolBar::addButton does no longer mess up when no image is set and does now actually work with the text. - - - Fix ninja animation range which got messed up a little when b3d animations got fixed (thx gbox for finding) - ---------------------------- -Changes in 1.6 (23.09.2009) - - - Added IFileSystem::createEmptyFileList, exposed IFileList::sort, addItem and added getID - - - Fix MAKE_IRR_ID so it can be used from outside the irr namespace (Micha's patch) - - - Renamed some methods in ISkinnedMesh to match the official Irrlicht naming scheme according to createXXX() - - - Change debug data to draw using lines instead of arrows, which is much faster. Patch by pc0de - - - Fix a bug with FPS camera animator causing stutters. Patch by FuzzYspo0N - - - Fix scrolling controls in CGUITabControl - - - Fix a bug when getting optimal texture size in D3D drivers, by Jetro Lauha (tonic) - - - Added EGDS_TITLEBARTEXT_DISTANCE_X and EGDS_TITLEBARTEXT_DISTANCE_Y to GUI, submitted by FuzzYspo0N - - - Fix for UFT8 filenames displayed in file dialog, patch by MadHyde. - - - Added const method for array::binary_search, potentially slow as it doesn't sort the list! - - - Add support for scaling button images. - - - Irrlicht can now come with multiple device types compiled in, the device to use is selected by SIrrlichtCreationParameters.DeviceType. This defaults to EIDT_BEST which automatically select the best device available starting with native, then X11, SDL and finally the console. - - - Added support for EXP2 fog distribution. This required a change in the setFog parameters where now an enum value instead of the bool linear is given. - - - IFileSystem changes: - - - Renamed the following functions- - IFileArchive::getArchiveType to getType - IFileSystem::registerFileArchive to addFileArchive - IFileSystem::unregisterFileArchive to removeFileArchive - IFileArchive::openFile to createAndOpenFile - - - New enum, E_FILE_ARCHIVE_TYPE. getType on IArchiveLoader and IFileArchive now both return this. - - - IFileSystem::addFileArchive takes a parameter to specify the archive type rather always using the file extension. IFileSystem::addZipFileArchive, addFolderFileArchive and addPakFileArchive now use this but these functions are now marked as deprecated. Users should now use addFileArchive instead. - - - Added TAR archive loader. - - - The ZIP archive loader can now load gzip files, combined with the TAR loader this means Irrlicht now has native support for .tar.gz - Currently this must be done in two calls, for example: - fileSystem->addFileArchive("path/to/myArchive.tar.gz"); - fileSystem->addFileArchive("myArchive.tar"); - - - Fix highlighting in IGUIEditBox where kerning pairs are used in the font. For example in future italic, OS or other custom fonts. - - - IOSOperator::getTextFromClipboard returns now const c8* instead of c8* - - - Support for copy&paste on linux (X11) added (fixing bug 2804014 found by Pan) - - - bugfix for 2795321 found by egrath: Don't rely anymore on broken XkbSetDetectableAutoRepeat. - - - bugfix: CMountPointReader::openFile no longer returns true for empty files. Corresponding test added. - - - Direct3D now also uses screen coordinates in 2d mode, just like OpenGL. This means that screen coords are going from 0..ScreenWidth and 0..ScreenHeight instead of -1..1. - - - ALT+F4 keypress now closes Windows SDL device - - - Allow Direct3D drivers in SDL, patch by Halifax - - - Added compiler error when attempting to compile with VC6. - - - Use setWindowTextA in Windows device for WIN64 platform, posted by veegun - - - ELL_ERROR log events are now created when shaders fail to compile or link, reported by Halan - - - irrList now uses irrAllocator, fixed by Nox - - - Added IGUIWindow::setDraggable and IGUIWindow::isDraggable, by Nox - - - Added SGI RGB file reader by Gary Conway, for loading Silicon Graphics .rgb, .rgba, .sgi, .int and .inta textures - - - Renamed setResizeAble to setResizable - - - Added new device method minimizeWindow which minimizes the window (just as if the minimize button has been clicked). - - - SkyDome is now serialized correctly - - - Added PLY mesh reader and writer - - - Ensure ListBox on combo box doesn't hang off the bottom of the GUI root, by Matthias Specht - - - Made IGUIElements recalculate clipping rectangle after setNotClipped, reported by Aelis440 - - - Bug fix for the combo box where it showed white text instead of skin color before being focused, fix posted by drewbacca - - - EGDS_MESSAGE_BOX_HEIGHT is now honoured, bug reported by Spkka - - - Fixed a bug in the edit box where events are sometimes sent to a null parent, reported by Sudi. - - - Coordinate system fix for OpenGL in SDL device - - - Added generic console device. You can now use Irrlicht to create and manipuate graphics on a shell where no graphics hardware - or windowing system is available. To enable it uncomment #define _IRR_USE_CONSOLE_DEVICE_ in IrrCompileConfig.h - - The console device can now present images from the software drivers and display them as ASCII art in the console - - By default it replaces the default font in the skin, to prevent fonts from being huge. - - - Fixed problems with changing cursor visibility while mouse is pressed on windows - - - Allow control of background drawing in listbox - - - Allow control of drawing background and titlebar in windows - - - Improved window serialization - - - Add mouse events EMIE_MOUSE_DOUBLE_CLICK and EMIE_MOUSE_TRIPLE_CLICK (thx to Ulf for patch proposal) - - - Set "ButtonStates" for mouse events also on Linux (was only for Windows formerly) - - - Add Shift+Control states to mouse event - - - bugfix (2003238): serialize modal screens - - - allow stacking modal screens - - - allowing hiding modals - - - replace many IsVisible checks with virtual isVisible() checks in IGUIElement - - - bugfix: reset selected row when clearing CGUITable - - - adding events EGET_EDITBOX_CHANGED and EGET_EDITBOX_MARKING_CHANGED - - - prevent editbox from recalculating its textbreaking each frame - - - let spinbox react on each textchange without waiting for enter to prevent getting value changes without corresponding EGET_SPINBOX_CHANGED events. - - - new test for zipreader - - - prevent dropping objects accidentally in many set functions - - - Reversed change in vector3d::normalize. - Works now again as documented and a corresponding test has been added. - Does fix bug 2770709 (https://sourceforge.net/tracker/?func=detail&aid=2770709&group_id=74339&atid=540676) - - - Animations can now be paused by setting the fps to 0. - - - Avoid fp-precision problem in getPickedNodeBB (see also http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=33838&highlight=). - This change might also fix the problem with picking nodes found by aanderse (http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=32890&highlight=) - - - implemented isALoadableFileFormat ( File *file ) for the Archive Loader - - - PixelBlend16 and PixelBlend16_simd are working for the new rules. - - - bugfix. CLightSceneNode didn't correctly update it's attributes - - - vector template and equals tests - also set the equal test for s32 to behave like the f32 routine. - The function equals always implements a weak test. - that means a tolerance MUST always be used if you use the equal function. default is 1. - - - VideoDriver drawPixel - The HW renderes are using the alpha components for blending. - The Software Renderes and image loaders are using CImage::setPixel copy. - so setPixel is engaged to either blends or copy the pixel - default: false - - Burningvideo - added RenderMaterial EMT_SPHERE_MAP - pushed burningsvideo to 0.43 - added RenderMaterial EMT_REFLECTION_2_LAYER - pushed burningsvideo to 0.44 - set EMT_TRANSPARENT_ALPHA_CHANNEL_REF - to use AlphaRef 0.5 like Direct3D - - One Note: in OpenGL there is know difference between sphere_map and reflection layer - both using GL_TEXTURE_GEN_MODE GL_SPHERE_MAP, whereas in d3d one time using camera_normal - on sphere and reflection on refletcion_layer. - - The visual difference is that on sphere map the "image is not moving" when you rotate the - viewer. For Burning i took the opengl visual. always moving - - - rename quake3 SEntity to IEntity to be confom with IShader - - - fixed createMeshWith2TCoords, normals were missing during copy. - - - added - //! Creates a copy of the mesh, which will only consist of S3DVertex vertices. - IMesh* CMeshManipulator::createMeshWith1TCoords(IMesh* mesh) const - - - added io::IFileSystem* CSceneManager::getFileSystem() - - - added virtual const c8* ISceneManager::getAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type); - - - added CSceneNodeAnimatorFlyCircle::radiusEllipsoid. - if radiusEllipsoid == 0 the default circle animation is done - else radiusEllipsoid forms the b-axe of the ellipsoid. - -> gummiball bouncing - - - added ISceneManager::createFlyStraightAnimator variable bool ping-pong - used in loop mode to device if start from beginning ( default ) or make ping-pong - -> straight bouncing - - - changed IFileSystem::registerFileArchive - remove the index of the hierarchy and added a new interface method - //! move the hirarchy of the filesystem. moves sourceIndex relative up or down - virtual bool moveFileArchive( u32 sourceIndex, s32 relative ) = 0; - - - bugfix and changes in SViewFrustum::SViewFrustum - wrong size of Matrices copy. - renamed E_TRANSFORMATION_STATE_2 to E_TRANSFORMATION_STATE_FRUSTUM - therefore also changed SViewFrustum::setTransformState to not tap - - in the pitfall again of wrong memory... - - - moved - //! EMT_ONETEXTURE_BLEND: has BlendFactor Alphablending - inline bool textureBlendFunc_hasAlpha ( E_BLEND_FACTOR factor ) const - from the material renderes ( 3x declared ) to SMaterial.h - - - updated managed light example to use standard driver selection - - - BurningsVideo - - LightModel reworked. - Point Light & Direction Light works for Diffuse Color as expected - Specular and Fog still have problems ( needs new pixel shader ) - pushed burningsvideo to 0.42 for this major step - - - removed obsolete matrix transformations - renamed E_TRANSFORMATION_STATE_2 to E_TRANSFORMATION_STATE_BURNING - - - cleaned line3d.h vector3d.h template behavior. - many mixed f32/f64 implementations are here. i'm not sure if this should be - the default behavior to use f64 for example for 1.0/x value, because they - benefit from more precisions, but in my point of view the user is responsible - of choosing a vector3d or vector3d. - - - added core::squareroot to irrmath.h - -> for having candidates for faster math in the same file - - - added AllowZWriteOnTransparent from SceneManager to burningsvideo - - -added hasAlpha() to ITexture - This info can be used for e.q to downgrade a transparent alpha channel blit - to add if the texture has no alpha channel. - -- FileSystem 2.0 SUPER MASTER MAJOR API CHANGE !!! - - The FileSystem is now build internally like for e.g. the image- and meshloaders. - There exists a known list of ArchiveLoaders, which know how to produce a Archive. - The Loaders and the Archives can be attached/detached on runtime. - - The FileNames are now stored as io::path. where c16 is toggled between char/wchar - with the #define flag _IRR_WCHAR_FILESYSTEM, to supported unicode backends (default:off) - Replaced most (const c8* filename) to string references. - - Basically the FileSystem is divided into two regions. Native and Virtual. - Native means using the backend OS. - Virtual means only use currently attached IArchives. - - Browsing - each FileSystem has it's own workdirectory and it's own methods to - - create a FileTree - - add/remove files & directory ( to be done ) - Hint: store a savegame in a zip archive... - - basic browsing for all archives is implemented. - Example 21. Quake3Explorer shows this - - TODO: - - a file filter should be implemented. - - The IArchive should have a function to create a filetree - for now CFileList is used. - - Class Hierarchy: - - IArchiveLoader: is able to produce a IFileArchive - - ZipLoader - - PakLoader - - MountPointReader ( formaly known as CUnzipReader ) - - IFileArchive: - -ZipArchive - -PakArchive - -MountPoint (known as FolderFile) - - IFileSystem - - addArchiveLoader - - - changed implementation of isALoadableFileExtension in all loaders - to have consistent behavior - - added a parameter to IFileList * createFileList - setFileListSystem - allows to query files in any of the game archives - standard behavior listtype = SYSTEM ( default) - - - CLimitReadFile - added multiple file random-access support. - solved problems with mixed compressed & uncompressed files in a zip - -- IrrlichtDevice - added: - virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ) = 0; - virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue ) = 0; - and calculating methods to DeviceStub. - - - irrlicht.h - changed exported irrlicht.dll routines createDevice, createDeviceEx, IdentityMatrix - to extern "C" name mangling. - - - ParticleSystem - removed the private (old?,wrong?) interface from the ParticleEffectors - to match the parent class irr::io::IAttributeExchangingObject::deserializeAttributes - -- Generic - - vector3d& normalize() optimized - added reciprocal_squareroot for f64 - - - dimension2d - added operator dimension2d& operator=(const dimension2d& other) - to cast between different types - - - vector2d bugfix operator+= - - - C3DSMeshLoader renamed chunks const u16 to a enum - removing "variable declared but never used warning" - - - added a global const identity Material - changed all references *((video::SMaterial*)0) to point to IdentityMaterial - removed warning: "a NULL reference is not allowed" - - - modified IRRLICHT_MATH to not support reciprocal stuff - but to use faster float-to-int conversion. - - - core::matrix4 - USE_MATRIX_TEST - - i tried to optimize the identity-check ( w.r.t. performance) - i didn't succeed so well, so i made a define for the matrix isIdentity -check - for now it's sometimes faster to always calculate versus identity-check - but if there are a lot of scenenodes/ particles one can profit from the - fast_inverse matrix, when no scaling is used. further approvement could - be done on inverse for just translation! ( many static scenenodes are not rotated, - they are just placed somewhere in the world) - one thing to take in account is that sizeof(matrix) is 64 byte and - with the additional bool/u32 makes it 66 byte which is not really cache-friendly.. - - - added buildRotateFromTo - Builds a matrix that rotates from one vector to another - - - irr::array. changed allocating routine in push_back - - added a new method setAllocStrategy, - safe ( used + 1 ), double ( used * 2 + 1) - better default strategies will be implemented - - - removed binary_search_const - i added it quite a long time ago, but it doesnt make real sense - a call to a sort method should happen always. i just wanted to safe - a few cycles.. - - added binary_search_multi - searches for a multi-set ( more than 1 entry in the sorted array) - returns start and end-index - - - changed some identity matrix settings to use core::IdentityMatrix - - - added deletePathFromFilename to generic string functions in coreutil.h and - removed from CZipReader and CPakReader - - - s32 deserializeAttributes used instead of virtual void deserializeAttributes in - ParticleSystem ( wrong virtual was used) - -- strings & Locale - - started to add locale support - - added verify to string - - added some helper functions - -- XBOX - i have access to a XBOX development machine now. I started to compile - for the XBOX. Question: Who did the previous implementation?. There - is no XBOX-Device inhere. maybe it's forbidden because of using the offical - Microsoft XDK. I will implement a native or sdl device based on opendk. - irrlicht compiles without errors on the xbox but can't be used. - -- Windows Mobile - reworked a little. added the mobile example to the windows solution for - cross development. - added maximal 128x128 texture size for windows mobile ( memory issues ) - -- Collision Speed Up - - The Collision Speed Up greatly improves with many small static child-nodes - - - added COctTreeTriangleSelector::getTriangles for 3dline from user Piraaate - - - modified createOctTreeTriangleSelector and createTriangleSelector - to allow node == 0, to be added to a meta selector - - - CSceneNodeAnimatorCollisionResponse has the same problem as CSceneNodeAnimatorFPS - on first update: - Problem. you start setting the map. (setWorld). First update cames 4000 ms later. - The Animator applies the missing force... big problem... - changed to react on first update like camera. - - - add Variable FirstUpdate. if set to true ( on all changes ) - then position, lasttime, and falling are initialized - - -added #define OCTTREE_USE_HARDWARE in Octree.h - - if defined octtree uses internally a derived scene::MeshBuffer which has - the possibility to use the Hardware Vertex Buffer for static vertices and - dirty indices;-) - - if defined OCTTREE_USE_HARDWARE octree uses internally a derived scene::CMeshBuffer - so it's not just a replacement inside the octree. It also in the OctTreeSceneNode. - #define OCTTREE_PARENTTEST is also used. It's skip testing on fully outside and takes everything on fully inside - - - virtual void ISceneNode::updateAbsolutePosition() - - changed inline CMatrix4 CMatrix4::operator*(const CMatrix4& m2) const - - - changed inline bool CMatrix4::isIdentity() const - to look first on Translation, because this is the most challenging element - - - virtual core::matrix4 getRelativeTransformation() const - Hierarchy on Identity-Check - 1) ->getRelativeTransform -> 9 floating point checks to be passed as Identity - 2) ->isIdentity () -> 16 floating point checks to be passed as Identity - - - inline void CMatrix4::transformBoxEx(core::aabbox3d& box) const - added isIdentity() check - -- changed CSceneNodeAnimatorCollisionResponse - - added CSceneNodeAnimatorCollisionResponse::setGravity - needed to set the differents Forces for the Animator. for eq. water.. - - added CSceneNodeAnimatorCollisionResponse::setAnimateTarget - - added CSceneNodeAnimatorCollisionResponse::getAnimateTarget - - changed CSceneNodeAnimatorCollisionResponse::animateNode to react on FirstUpdate - - TODO: set Gravity to Physically frame independent values.. - current response uses an frame depdended acceleration vector. - ~9.81 m/s^2 was achieved at around 50 fps with a setting of -0.03 - may effect existing application.. - -- SceneNodes - - CSkyDomeSceneNode - moved radius ( default 1000 ) to constructor - added Normals - added DebugInfo - added Material.ZBuffer, added SceneManager - - - CVolumeLightSceneNode: - changed default blending OneTextureBlendgl_src_color gl_src_alpha to - EMT_TRANSPARENT_ADD_COLOR ( gl_src_color gl_one ) - which gives the same effect on non-transparent-materials. - Following the unspoken guide-line, lowest effect as default - - - changed SceneNode Skydome from f64 to f32 - - - AnimatedMesh Debug Data: - mesh normals didn't rotate with the scenenode fixed ( matrix-multiplication order) - - - Camera SceneNode setPosition - Camera now finally allow to change position and target and updates all - effected animators.. - -- Device: - added the current mousebutton state to the Mouse Event - so i need to get the current mouse state from the OS - -- GUI - - - CGUIFont: - - added virtual void setInvisibleCharacters( const wchar_t *s ) = 0; - define which characters should not be drawn ( send to driver) by the font. - default: setInvisibleCharacters ( L" " ); - - - added MultiLine rendering - should avoid to us CStaticText breaking text in future - - - CGUIListBox - - changed Scrollbar LargeStepSize to ItemHeight - which easy enables to scroll line by line - - - CGUIScrollBar - - bug: event lost when moving outside the window - - bug: Scrollbar notifyListBox notify when the scrollbar is clicked. - - changed timed event in draw to OnPostRender - - - added GUI Image List from Reinhard Ostermeier, modified to work - - - FileOpenDialog - changed the static text for the filename to an edit box. - - - changed the interface for addEditBox to match with addStaticText - - - changed the interface for addSpinBox to match with addEditBox - - - added MouseWheel to Spinbox - - - changed CGUITable CLICK_AREA from 3 to 12 to enable clicking on the visible marker - - - CGUISpritebank - removed some crashes with empty Sprite banks - - - IGUIScrollBar - added SetMin before min was always 0 - changed ScrollWheel Direction on horizontal to move right on wheel up, left on wheel down - - - IComboBox: added ItemData - - - optimized IsVisible check in IGUIElement::draw - -- Image Loaders - - added TGA file type 2 ( grayscale uncompressed ) - - added TGA file type (1) 8 Bit indexed color uncompressed - - ColorConverter: - - added convert_B8G8R8toA8R8G8B8 - - added convert_B8G8R8A8toA8R8G8B8 - -- Media Files - - added missing shaders and textures to map-20kdm2. - Taken from free implementation - - ball.wav. adjusted DC-Offset, amplified to -4dB, trim cross-zero - - impact.wav clip-restoration, trim cross-zero - - added gun.md2, gun.pcx to media-files - - added new irrlicht logo irrlicht3.png - -- OctTree - -added - #define OCTTREE_PARENTTEST ( default: disabled ) - used to leave-out children test if the parent passed a complete frustum. - plus: leaves out children test - minus: all edges have to be checked - - added MeshBuffer Hardware Hint Vertex to octtree - -- CQuake3ShaderSceneNode: - - removed function releaseMesh - Shader doesn't copy the original mesh anymore ( saving memory ) - so therefore this (for others often misleading ) function was removed - - changed constructor to take a (shared) destination meshbuffer for rendering - reducing vertex-memory to a half - - don't copy the original vertices anymore - - added deformvertexes autosprite - - added deformvertexes move - - added support for RTCW and Raven BSPs ( qmap2 ) - - added polygonoffset (TODO: not perfect) - - added added nomipmaps - - added rgbgen const - - added alphagen - - added MesBuffer Hardware Hint Vertex/Index to Quake3: static geometry, dynamic indices - - added Quake3Explorer examples - - added wave noise - - added tcmod transform - - added whiteimage - - added collision to Quake3Explorer - - renamed SMD3QuaterionTag* to SMD3QuaternionTag* ( typo ) - - updated quake3:blendfunc - - added crouch to Quake3Explorer - (modifying the ellipsiodRadius of the camera animator ) - added crouch to CSceneNodeAnimatorCameraFPS - still problems with stand up and collision - - Quake3MapLoader - modified memory allocation for faster loading - - Quake3LoadParam - added Parameter to the Mesh-Loader - - added - The still existing missing caulking of curved surfaces. - using round in the coordinates doesn't solve the problem. - but for the demo bsp mesh it solves the problem... (luck) - so for now it's switchable. - TJUNCTION_SOLVER_ROUND - default:off - -- BurningVideo - - pushed BurningsVideo to 0.40 - - added blendfunc gl_one_minus_dst_alpha gl_one - - added blendfunc gl_dst_color gl_zero - - added blendfunc gl_dst_color src_alpha - - modified AlphaChannel_Ref renderer to support alpha test lessequal - - addded 32 Bit Index Buffer - - added sourceRect/destRect check to 2D-Blitter ( slower, but resolves crash ) - - added setTextureCreationFlag video::ETCF_ALLOW_NON_POWER_2 - Burning checks this flag and when set, it bypasses the power2 size check, - which is necessary on 3D but can be avoided on 2D. - used on fonts automatically. - - added Support for Destination Alpha - -- Direct3D8 - - added 32 Bit Index Buffer - - compile for XBOX - -- Direct3D9 - - fixed crash on RTT Textures DepthBuffer freed twice. - added deleteAllTextures to destructor - -- NullDriver - - removeallTextures. added setMaterial ( SMaterial() ) to clean pointers for freed textures - - - ISceneCollisionManager::getSceneNodeAndCollisionPointFromRay() allows selection by BB and triangle on a heirarchy of scene nodes. - - - Triangle selectors created from animated mesh scene nodes will update themselves as required to stay in sync with the node. - - - IVideoDriver has methods to enumerate the available image loaders and writers. - - - Octtree scene nodes are now IMeshSceneNodes rather than ISceneNodes, and so you can call getMesh() on them. - - - New scene parameter B3D_LOADER_IGNORE_MIPMAP_FLAG to ignore the often missing mipmap flag in b3d files. If this parameter is true, the old pre Irrlicht-1.5 behavior is restored. - - - Added Mipmap LOD Bias attribute to MaterialLayer. - - - Added ColorMask support to selectively disable color planes on rendering. - - - Added support for all available depth test functions. - - - Add an outNode to getCollisionPoint() that returns the scene node that was hit, as well as the triangle. - - - Initial support for Alpha To Coverage, needs some more fixing until it works on all supported platforms. - - - Added support for Anti-Aliasing modes per material - - - Added an ICollisionCallback to ISceneNodeAnimatorCollisionResponse, to inform the application that a collision has occurred. Thanks to garrittg for this. - - - Added an startPosition parameter to createFlyCircleAnimator() to allow starting the animator at any position on the circle. - - - Many uses of dimension2d changed to dimension2d, including IImage, ITexture and screen dimensions. You will have to change (at least) createDevice() calls to use dimension2d - - - Added Doublebuffer flag to SIrrCreationParameters, for better finetuning - - - Added Stereo-Framebuffer support for professional OpenGL cards - - - Added IFileSystem::createMemoryWriteFile() to allow creation of an IWriteFile interface that uses an application supplied memory buffer. - - - Added an IVideoDriver::writeImageToFile() overload that can take an IWriteFile interface. - - - (Internal) Replaced CMemoryReadFile with CMemoryFile, that also implements an IWriteFile interface. - - - Added an optional light manager to the scene manager to allow the user application to turn lights on and off during scene rendering. This can be used to produce "zoned" lighting. See example 20.ManagedLights. - - - Added a method to flip the Y movement of the FPS camera. - - - The Anisotropy filter can now be set to the AF value per texture layer. So no forced MAX_ANISOTROPY anymore. .irr files will probably fail, though. - - - AntiAlias parameter in SIrrCreationParameters is now an u8 value specifying the multisampling level (0 for disabled, 4,6,8, and others for anti-aliasing) - - - D3D devices use DISCARD for windowed renderbuffers now, can be faster. - - - Changed behavior of PixelBlend16() / PixelBlend16_simd() so that they treat the 1 bit alpha of the source pixel as boolean, i.e. they draw either the source pixel, or the destination pixel, rather than "blending". (Issue revealed by the fix to IVideoDriver::makeColorKeyTexture()). - - - IVideoDriver::makeColorKeyTexture() bug fixed so that only alphas, not whole texel colors, are zeroed. An optional parameter allows using the old (buggy) behavior for backwards compatibility. - - - position2d is now a synonym for vector2d. position2d is therefore marked as deprecated, although it's unlikely to be removed. - - - ISceneNodeAnimator now has a hasFinished() method. - - - ISceneNodeAnimatorCollisionResponse exposes the target node. Setting the node again resets the last position, allowing the node to be teleported. - - - Add a hitPosition out parameter to ISceneCollisionManager::getCollisionResultPosition() - this is a (small) API breaking change. - -------------------------------------- -Changes in version 1.5.2 (16.12.2009) - - - Properly check boundaries in getFont and setFont. - - - Reinit values in the driver when scene manager is cleared. - - - Normals handling fixed in createMeshWithTangents, existing normals are not always destroyed now. - - - Fix terrain smoothing, bug found by loverlinfish - - - SOLARIS recognition removed. Please specify the platform define manually. This allows for compilation under sparc/Linux and sparc/Solaris - - - Some uninitialized variables fixed - - - FreeBSD joystick support added (for Debian package) - - - Fix cursor problems found by buffer and by rvl2 as described in http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=34823&highlight= - - - OSX/XCode updates - - - MS3D loader bug fixed - - - Float parse bug fixed - -------------------------------------- -Changes in version 1.5.1 (05.08.2009) - - - Make sure a missing font does not corrupt the skin. - - - Fix getAngle in vector2d as suggested by xray. This has only a minor impact on s32 vectors. - - - bugfix: CGUIFont::getCharacterFromPos regards now kerning (found by Arras) - - - Add support for range fog in some OpenGL versions. - - - Fix for shadow volume removal, submitted by vitek. - - - Avoid using X11 autorepeat to deal with broken X11 versions. - - - Speculars are properly exported into mtl files now, instead of corrupting them. - - - Binary type loading in attributes fixed. - - - bugfix: Use make_lower throughout for spritebank filenames (found and patched by Ion Dune) - - - STL loader fixed: Right-handedness corrected, normals and bboxes are correctly added now. - - - bugfix: CUnZipReader::openFile no longer returns true for empty files. Corresponding test added. - - - Big endian issues in .x loader fixed. - - - HSLColor methods repaired. - - - copyToScaling fixed. - - - Fixed problem with highlighting menus when mouse was outside sub-menu area. - - - bugfix (2796207): menu acted (wrongly) on left-click down instead of left-click up. - - - bswap16 fallback macro fixed - - - getBaseName fixed to work correct with dots in filenames. - - - static method isDriverSupported allows for simple check of available drivers. - - - Some defines added to check for the Irrlicht version of the library. - - - Make sure all renderstates are properly initialized - - - Wrong size for main depth buffer fixed. - - - Fix 3ds shininess to the allowed range. - - - Fix loading of Collada files from irrEdit 1.2 - - - Remove texture pointers after texture clear. - - - WindowsCE pathnames fixed. - - - Some virtuals are now overridden as expected. - - - Incomplete FBOs are properly signalled now - - - Update to libpng 1.2.35, fixed issues on 64bit machines with system's libpng. - - - Fixed wrong grab/drop in setOverrideFont - - - Added draw2dRectOutline - - - rectf and recti added. - - - Fix ALPHA_CHANNEL_REF to a fixed check for alpha==127 as expected. - - - Fixed OSX device bug where screen size was not set in fullscreen mode. - - - cursor setVisible changed to be called less often. - - - OpenGL version calculation fixed. - - - OSX device now supports shift and ctrl keys. - - - Fixed ambient light issues in burningsvideo. - - - device reset for d3d fixed when using VBOs. - - - Fix dimension2d += - - - MD2 mesh loader: Now uses much less memory, reduced number of allocations when loading meshes. - - - OpenGL render state (texture wrongly cached) fixed. - - - Fixed animator removal. - - - Checnged collision checks for children of invisible elements to also be ignored (as they're actually invisible due to inheritance). - - - Fix terrain to use 32bit only when necessary, make terrain use hw buffers. Heightmap loading and height calculation fixed. Visibility and LOD calculations updated. - - - Some mem leaks fixed - - - FPS camera resets the cursor better - ------------------------------------ -Changes in version 1.5 (15.12.2008) - - - Construction calls for FPS camera changed to take speed in units/milliseconds, just as the setSpeed method does. - - - Code::Blocks workspaces added. C::B projects (using gcc) now output to /lib/gcc and /bin/gcc, when built on either Windows or Linux. - - - Added a test suite in the /tests directory. This can be used to perform regression tests, and should be updated with new tests to verify fixes or validate new features. - - - Changed the preferred way of altering light node's radius: Use the new member methods of ILightSceneNode instead of directly modifying the SLight structure. - - - Changed the initial attenuation back to (0,1/radius,0). To override this value simply change the attenuation in the SLight (lightnode->getLightData().Attenuation.set(x,y,z)) - - - Dirty fix for OSX device setResizable and a bug fix to do with resizing the device. - - - Terrain heightmap and texture were flipped in order to draw them as expected (looking onto the terrain from high above will just look like the actual texture/heightmap). - - - Significant internal change to the way that FPS camera jump speed and collision response animator gravity interact. The behavior is now much more realistic, but it will require you to adjust your jump speed and gravity. - - - Skybox won't be culled anymore by nearplane or farplane. - - - BBoxes of animated meshes (skinned meshes) are updated again. - - - Lost devices (as found with D3D) are properly handled now. So the screen can be resized or minimized without crashing the app. - - - Renamed IGUIElement::setRelativePosition(const core::rect& r) to IGUIElement::setRelativePositionProportional(), as it has radically different functionality from setRelativePosition(const core::rect& r) - - - Added IGUIElement::setRelativePosition(const core::position2di & position) to set a new position while retaining the existing height and width. - - - Many Collada fixes. z_up coords are supported now, texture coords are properly loaded. Transparency is supported. - - - Camera scene node rotation and target can now be bound together so that changing one automatically changes the other (as the FPS camera has always done). See ICameraSceneNode::bindTargetAndRotation() - - - Removed the extra libpng files for OSX. OSX now also uses the default libpng. - - - Enhanced PCX support with some more color formats and write support. - - - Fixed LMTS problems with extra data in files. - - - Removed VS6 .dsw / .dsp project files - VS6 is no longer supported. - - - Particles can be scaled during animations. Particle scaling needs to happen in the emitter now, instead of in the Particle system scene node. Deprecation methods will guide the user. - - - ISceneNode::setParent and addChild now updates node SceneManager pointers if the node was from another SceneManager. - - - Basic support for joystick input events on Windows, Linux, SDL and OSX. Tested with wired Logitech and Thrustmaster wired controllers and XBox 360 wireless controller ( http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver ) - - - Fixed scaled octree nodes being incorrectly frustum culled. - - - FSAA under OpenGL and Win32 added. Now all hw drivers and platforms should support it. - - - Unlimited RTT fix for D3D systems. Depth buffers are now shared if possible, otherwise a new depth buffer is generated. In order to save VidMem one should create RTTs starting with the largest one. - - - Avoid RTTs with nonFBO-support under OpenGL which are larger than the screen. Since we rely on rendering into textures in this case we need to clamp the size by the screensize. - - - Fixes for getAbsoluteFilename under Linux in order to return a filename instead of en empty string in case the file doesn't exist. - - - Use absolute path names when creating / finding textures. - - - Font tool implementation for Linux with xft, by Neil Burlock. - - - Support for normals and UV coords from DeclData in .x files. - - - Modified line2d::intersectWith() to cover more cases. - - - Added IVideoDriver::drawPixel(). - - - Moved the window pointer from endScene to beginScene, as this is required for OpenGL support of external window pointers. - - - Fix for terrain culling. - - - Added minimize button to win32 window (if resizable) - - - Major API change: RTTs are now created via addRenderTargetTexture instead of createRenderTargetTexture, which allows to retrieve them from the texture cache, but also changes the way of removing the RTTs, and especially one must not drop the pointer anymore. - - - WindowsCE-Bugfix - - - disableFeature can be used to override feature support of the video driver. - - - draw2DImage can now also handle RTTs under OpenGL (which were flipped before). - - - Ogre mesh format fixes for proper texture support. - - - Added .obj mesh writer. - - - Some core::string constructors made explicit to avoid unintended conversions. Just add core::stringc() or core::stringw() around the old code to avoid warnings. - - - IdentityMatrix is now a properly defined global, with external visibility on all platforms. - - - Bugfix for context releases with glx 1.3 on error. - - - Removed constraints for sizes of the terrain scene node. - - - Support for 32bit indices in a special MeshBuffer class. - - - isBetweenPoints return true now even for the begin and end points, i.e. line segments are now including their start and end. - - - Fix XML reader creation for non-existing files and invalid callbacks. - - - Changed interpretation of MaterialTypeParam==0 in transparent materials. Now it's consistent with all other values, but one has to set the value to 0.5 to get the old behavior (slightly faster rendering, but no smooth borders) - - - Replaced transformBox by transformBoxEx in some internal methods to avoid major malfunction of the transformations. - - - Fix use of zip file inside zip files. - - - Avoid loading textures which are not used by the mesh in b3d loader. - - - Added scaleTCoords methods to MeshManipulator - - - Enable use of other meshes for shadow mesh generation, can be used to speed up shadow generation and rendering for complex meshes. Patch based on a version by tonic. - - - Fixed usage of SIrrCreationParameters struct, which dind't have copy constructor and assignment operator anymore, since the Irrlicht version string was made const. - - - New glext.h (version 41) and glxext.h (version 20) supporting OpenGL 3.0 - - - Added support for read-only locking of textures. Can speed up those calls. - - - Added support for locking RTTs under OpenGL. - - - Implementation of UserData events from system events. - - - ICameraSceneNode::setIsOrthogonal replaced by a parameter to setProjectionMatrix. - - - All meshbuffers are now dynamically allocated to avoid problems with grabbed buffers, which may be deleted before the last drop happens (due to static memory allocation). - - - Enhanced scene graph traversal with example from rogerborg. - - - FPS camera disabling of event receiver works better now. - - - scene deserialization allows for a user defined callback after a new scene node is created. - - - Fixed tangent mesh loading from .irrmesh files. - - - OpenGL clamp modes are now properly set. - - - IMeshManipulator::transformMesh renamed to transform, also supports meshbuffers now. - scaleMesh renamed to scale, supports meshbuffers as well. - - - vector3d::rotationToDirection added. - - - New mesh generators for cone and cylinder. - - - Hardware accelerated Vertex and Index Buffer support finally integrated into Irrlicht. Thanks to a resource handling idea by Klasker and the almost immediate implementation by Luke, Irrlicht now supports VBOs under OpenGL and D3D. - Hardware buffers make rendering the same vertices much faster. To use this feature with a mesh, simply set a usage type via MeshBuffer->setHardwareMappingHint(scene::EHM_STATIC). The driver will upload the vertices and indices on the next draw and reuse this information without the need to upload it each frame. - Vertex and Index buffers can also be updated separately, which is e.g. useful for the terrain node's LOD. - - - Changed FBO creation according to Nadro's patch. Seems to have zbuffer problems currently. - - - Update to libpng 1.2.29 - - - Compiler flag for PerfHUD support added. - - - recalculateNormals and tangent space creation enhancements by ryanclark. - - - Added getColorFormat methods for device and driver, returning the color format of the device's window and the driver's framebuffer. - - - Added isFullscreen method. - - - Added isWindowFocused and isWindowMinimized methods. - - - Screenshots are now always made from the frontbuffer, so always the last completely rendered image is captured. However, overlapping windows may corrupt those parts of the screenshot (as was previously happening with d3d already). - - - New device creation parameter to disable Irrlicht's system event handling. - - - New device creation parameter to specify depth bits. - - - New device creation parameter to request alpha channel in framebuffer. - - - Draw2DImage methods under OpenGL now also handle RTTs correctly. - - - Fixed RTT bug which lead to strangely clamped textures. - - - Speed improvement for screenshots on some Intel cards under OpenGL. - - - My3D file loader fixed. - - - Terrain mesh performance increased. - - - Fixed mem leak in cube node. - - - Compiler errors in shaders won't corrupt the material renderer list anymore. - - - Quake3 shader files now have properly working texture matrices again. - - - FPS and Maya style cameras are now standard cameras with a special animator. - - ISceneNodeAnimator now inherits IEventReceiver - - New method ISceneNodeAnimator::isEventReceiverEnabled, returns false by default - - CCameraSceneNode::OnEvent passes events to animators with enabled event receivers - - ISceneNodeAnimatorCameraFPS and ISceneNodeAnimatorCameraMaya interfaces for changing camera settings at run-time. - - - Changed SExposedVideoData to use void* instead of s32. Fixed 64bit portability. - - - Added support for front face culling. - - - Fix for HLSL shaders in one file. - - - Billboard::setColor bug fix by rogerborg. - - - Scene node sorting uses squared distances now. - - - Enhanced API for hte math functions. Many of them will now return a reference to *this for chained method invocations. - - - prevent .x loader to load .xml files. - - - AntiAlias support for OSX device. - - - Period character handling bug fixed. - - - New filesystem methods for filename handling. - - - added getVideoModeList and getDesktopResolution support for OSX - - - Octree supports tangent meshes now. Some performance improvements for the generation. - - - Fix mouse pointer and fullscreen mode problems in OSX. - - - Make cube and sphere scene node a mesh scene node (for access to the cube/sphere mesh). - - - Support for normal maps in 3ds files. Mem leak fixed. Loading for files with keyframe data fixed. - - - BillboardTextSceneNode is now an IBillboardSceneNode and an ITextSceneNode. - - - Support for external windows under Linux. - - - .X loader bug fixes. - - - Better debug visualization for MeshSceneNodes. - - - Fixed bug in material serialization when using the NullDriver. - - - Fix for Win32 CursorControl::setVisible - - - Support for LWO files. - - - Support for Collada 1.4 files. - - - Better and faster terrain smoothing by Frosty Topaz. - - - Fixed a performance bug in ISceneNode constructor reported by izhbq412 - - - Win32 device now makes the cursor invisible immediately when setVisible(false) is called. - - - Command line tool for mesh conversion added. - - - Added volume light scene node - - - .obj files now won't duplicate vertices unnecessarily. This allows recalculation of smooth normals and other things, and is also faster when rendering. The loading is a little slower now. - They also support normal maps and texture clamping now. Group support added, can be ignored via scene manager attribute scene::OBJ_LOADER_IGNORE_GROUPS. - Normals will be calculated if the file doesn't provide them. - - - Better fix for hires timers on dual core machines by RogerBorg - - - added Initial Windows Mobile 6 Version. - - Windows Mobile 6 SDK - - Visual Studio 2005 - - - Added checks to avoid buffer overrun in b3d loader. Enabled normals calculation in all cases, previously it was not done for lightmapped meshes. - Fixed transparency support. Added mipmap creation flag support which might disable mipmap creation too often. Should be checked. - - - Burningvideo: MipMap Selection repaired - - - renamed private Driver function getTextureSizeFromImageSize to getTextureSizeFromSurfaceSize - - - Added collision manager speedup patch by RogerBorg. - - - D3D drivers now releases the IImage member from initialization, thus freeing lots of memory. The image is accessible via the driver anyway. - - - SDL device character handling enhanced. - - - MeshBuffers can now access the elements of the S3DVertex base class in all vertex types directly, instead of using the getVertices() pointer access. This simplifies simple mesh manipulations as it does not require a switch statement over all vertex types. - - - More OpenGL renderstate bugs fixed - - - GLSL changes for setting arrays. Also allow for only pixel or vertex shader to be set. - - - Bugfix for removeChild in AnimatedMeshSceneNode. - - - Some bugfixes for Joint handling and skinned meshes. Added getJointCount in IAnimatedMeshSceneNode and isStatic in ISkinnedMesh. - - - Added WAL image format support based on the original loader by Murphy McCauley, written for Irrlicht around version 0.7. - - - OpenGL RTTs now also support alpha values. - - - New method driver->getVendorInfo() to query information about the actual hardware driver. - - - Fixed somed CQuake3ShaderSceneNode problems. - - - Changed BurningsVideo internal Vertex Format. version changed to 0.39 - - - SceneManager: - Removed the seperate rendering states for quake3 Shader Scene Nodes. - Nodes are now solid or transparent. ( but still more states are needed ) - - - GUI: - - - Editbox didn't draw children - - Checking IsEnabled is now consistent across all GUI elements - - Move window to front bug fixed. - - Disabling the BMP loader now compiles without the built-in font - - Added setTextAlignment to IGUIComboBox - - Avoid dropping skin pointer which is in use. - - Better warning for fonts without regions (sometimes wrong file is loaded by the user). - - Fixed a bug in CGUISpriteBank which caused a crash when a non-looping animated sprite reached the end of its animation. - - Modal screens no longer flash invisible children when rejecting a focus change. - - Finally added StarSonata patch with table element and TabControl additions. Table is based on MultiColor listbox by Acki, and has loads of changes by CuteAlien. - -------------------------------------------- -Changes in version 1.4.2 (22.9.2008) - - - Unified the handling of zwrite enable with transparent materials on all hw accelerated drivers. This means that all transparent materials will now disable ZWrite, ignoring the material flag. - There is a scene manager attribute, though, which will revert this behavior to the usual SMaterial driven way. Simply call - SceneManager->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true) and set the SMaterial flag as desired. - - - Some changes for texture matrices in q3 shaders. - - - Added BlindSide's irrAllocator patch for proper TextureMatrix release under Win32 with any CRT library. - - - Added VC9 project files. - - - Added getEmitter for particle system scene nodes. - - - Fixed rounding problem in getScreenCoordinatesFrom3DPosition - - - Fixed Software renderer color flicker, was a shift bug I believe. - - - irrMap fix to make root node always black, by rogerborg. - - - Possible core dump fixed in particle system node, by CuteAlien. - - - Mem leak fixed in b3d loader. - - - Avoid double rendering of child nodes of joints. - - - Support for d3d draw2dimage clipping by CuteAlien. - - - Fixed an animation transition bug, pointed out by wuallen. - - - Fixed the major problem with OpenGL drivers, that claim to be 2.x compatible, but don't offer NPOT support (well, they do, but only in sw rendering...). Now we check for the extension string only. - - - Fixed .obj loader bug which inserted vertices in wrong buffers. - - - Fixed minor mem leak in Linux device. - -------------------------------------------- -Changes in version 1.4.1 (04 Jun 2008) - - - MD3 meshes are movable again. - - - New JPG image writer version by Vitek. - - - Texture matrix fixes, all methods should now work as expected. - - - Some container methods now return the this pointer after member functions have been called on them, in order to allow call chains. - - - Some new methods for SColorf access, for uniform API of all colors. - - - bug fix for SMaterialLayer equality check. Did only check the TextureMatrix pointers, instead of the matrices. - - - New getMesh method for the SceneManager, which takes an IReadFile instead of a filename. - - - Support for flags _WIN32 and _WIN64 in addition to WIN32 and WIN64 added, this simplifies usage of Irrlicht headers under MSVC. - - - Fixed a crash in GUIMeshViewer - - - new string method findLastChar by Halifax - - - GUIEditBox got the 1 pixel shift after click fixed. - - - Some debug visualization has been fixed for skinned meshes - - - Undef PI symbol before declaring core::PI to avoid compilation problems - - - SAnimatedMesh now properly returns properties of Meshes[0] if those exist, such that it should be usable in place of an SMesh again. - - - Fixed 2d initialisation in opengl and d3d9 driver. This should fix problems with render states mixing up and distrubing, e.g. skin effects. - - - Avoid a crash when passing setSkin the current skin - - - - Fixed current frame calculation for non-looped animations. Bug reported by greenya. - - - Fixed bug in CBillboardSceneNode::setColor, reported by rogerborg - - - Fixed clipping of menu, toolbar and combo box GUI elements, reported by greenya - - setNotClipped now applies all the way up to the root of the GUI environment, rather than just to the next parent - - - Made new scene managers use the original manager's GUIEnvironment, reported by MasterGod - - - Fixed IGUICheckBox::setEnabled, reported by Dorth - - - Fixed the FollowSpline animator to avoid crashes when only one waypoint is given. - - - OpenGL VolumeShadow now uses glPolygonOffset to avoid zbuffer artifacts. - - - Fixed meshbuffer corruption in append methods. - - - Fixed mem leaks in irrArray. - - - Fixed minor bugs in ISceneNode and ISceneManager. - - - Fixed the MeshCache handling of GeometryCreator meshes. - - - Terrain LOD bugfix. - - - Some Collada 1.3 loader enhancements and bug fixes. - - - Fixed a bug in CGUISpriteBank which caused a crash when a non-looping animated sprite reached the end of its animation. - - - Enhanced the .obj loader with the patch from ryanclark. This allows for recalculation of smoothed normals of the mesh, also should decrease the tri count on some meshes. - - - Avoid the global Logger to be destroyed too early. - - - Function setbit was renamed to setbit_cond to avoid name clashes. - - - Fixed .x animations with multiple references to the same joint from different meshes. Fixed texture path problems. - - - Support for Milkshape 1.8 files, also with multiple weights per joint. - - - The config file now also supports _IRR_OSX_PLATFORM_ and _IRR_USE_OSX_DEVICE_. This allows to use the Linux device (X11 support) on OSX. - - - Avoid terrain scene node crash when heightmap cannot be loaded. - - - Speed improvements for WaterSceneNode. - - - FlyCircle animator now also works for upvectors (Direction parameter) which are not (0,1,0). Is also faster now, since most calculations are done on init. Thanks to Dorth for working on this. - - - The 3ds loader correctly creates a texture matrix when texture tiling properties are found in the file. - - - Fix for S3DVertex comparison operators. Used some wrong logic. - - - Bugfix getCurrentRenderTargetSize in D3D drivers. Due to signature differences a wrong virtual method was chosen. Thanks to Jiang for finding it. - -------------------------------------------- -Changes in version 1.4 (30 Nov 2007) - - - Major API change: All material properties which are available per texture layer (curently texture, texture matrix, texture filters, and texture wrap mode) are separated into a new struct SMaterialLayer. You can access them via the array TextureLayer[] in SMaterial. The texture matrix methods in SMaterial are still alive, and also textures can be accessed via methods in SMaterial now. But still, many places in user code need some update (usually changing material.Textures[i] to material.TextureLayer[i].Texture etc.) - - - Major API rewriting for proper const usage. Now, most getter methods are const and so are the larger parameters and return values. Moreover, many methods taking only unsigned numbers now use u32 instead of s32 in order to recognize this limitation from the method's signature. - - - the base class for nearly all Irrlicht classes has been renamed from IUnknown to IReferenceCounted - - - Fixed Skybox texture orientations. They are now displayed non-flipped. Existing skyboxes have to be changed, though: Exchange left and right texture. Textures from Terragen and other tools can be used directly, now. Quake maps will also need the right/left exchange. - - - Added ITexture::isRenderTarget() - - - Added STL mesh file format reader and writer. - - - Added IMeshManipulator::createMeshWelded which creates a copy of the mesh with similar vertices welded together. - - - Irrlicht now has its own file format for static meshes. It is based on xml and has the - extension .irrmesh. Irrlicht is able to write every IMesh to this file format, and of course to - read it back again. - - - Irrlicht is now able to write Meshes out into files. Use ISceneManager::createMeshWriter() - to obtain an interface with which you can write out meshes. Currently, an own .irrmesh - file format is supported as well as the COLLADA file format. - - - fixed the keyboard autorepeat difference between Linux and Windows. Thanks to denton we now have only KeyPressed events on both systems in case of autorepeat. - - - Added several new particle emitters and affectors from IrrSpintz. Also some new getter and setter methods were added. - - - D3D transparent materials do not disable zbuffer writing automatically anymore. This has to be done by the user to keep those settings configurable. - - - OpenGL texture now also require a regenerateMipmapLevels() after unlocking. This is the same as for d3d devices now. - - - Point sprite support in the driver. Point sprites use just one 3d vertex and a size to create a textured billboard on the GPU. This can provide fast particle systems, especially in combination with shaders. The proper particle extension will follow later on as it needs some more refactoring. - - - OpenGL 2D drawing accuracy fix by tuXXX - - - Added OnResize and getCurrentRenderTargetSize to the software video drivers. - - - Added Spot light type for dynamic lights. Note that both position and direction for all dynamic lights are now determined by the LightSceneNode, the SLight attributes are only used for internal purposes. - API change! One can easily work around this change by setting the LightSceneNode's Position and Rotation instead of the SLight's. This change won't provoke a compile error, though, and can hence go unrecognized besides the visual problems. - The lights use a default direction (0,0,-1) which is rotated by the usual scene node transformations and can hence be modified by scene node animators. - A change in the Radius usage can lead to strange artifacts. Just increase the Radius in this case. further handling of Radius is to be discussed. - - - Added per pixel fog support for OpenGL. - - - Added driver support for user defined clip planes, based on mandrav's patch. - The OpenGL version is more picky about ModelView matrices, so it's best to set the projection plane at the time it is used. - - - .obj files now load relative indices correctly. Collada files load textures. - - - A new MeshBuffer implementation is publicly available. It supports a shared vertex list for all MeshBuffers, used for MS3D meshes. - - - MeshBuffers can recalculate their BoundingBoxes on their own now, no need for MeshManipulators. New append methods help to merge MeshBuffers. take care that the types match! - - - The new texture generation mode is working. With ETCF_NO_ALPHA_CHANNEL textures are generated without ALPHA bits reserved. - - - D3D9 hardware mipmap updates are re-enabled, problems should be reported. - - - In some cases fullscreeen modes under win32 should have a better frame rate now. - - - Fixed the hillplane mesh to work with non-quadratic dimensions as well. Changed the interface also, so use a u32 dimension to specify the tilecount now. - - - Hires timers are disabled on windows systems with more than one CPU, due to bugs - in the BIOS of many multi-core motherboards. To enable hires timers in your project, - use SetProcessAffinityMask to set to use only one CPU before creating the device. - - - OpenGL render targets now the same way up as the other drivers. If you have - written opengl shaders that use render targets then you'll need to change your - texture coordinates accordingly. - - - Fixed some OpenGL renderstate stuff. setBasicRenderstate returns with - active texture layer 0. The material renderer must return from OnUnset - with the same active texture layer. The alpha test is disabled and the - texture mode should be GL_MODULATE. - - - Fixed CSoftwareTexture2::getOriginalSize, reported by CaptainPants. Added a - new method CSoftwareTexture2::getMaxMipMapSize to return the size of the largest - mipmap, which is used by texelarea instead of getOriginalSize. - - - Changed parameter order of addArrowMesh and added default parameters such - that it's enough to set the color (or even just the name). - - - Fixed bugs in MY3D and OBJ loader. - - - Added IMeshCache::clearUnusedMeshes(). This allows the user to remove - meshes that are sitting in the mesh cache but aren't used by any scene nodes. - This is useful for example when changing levels. - - - Added IUnknown::getReferenceCount() - - - createDevice now reports errors if the driverType is unknown, previously it - created a window but populated it with a null driver without any warning. - - - Fixed a bug in CBillboardTextSceneNode::setText where the old text was not - cleared. - - - Changed irrArray::linear_search to use the == operator rather than < - This may be slower in some cases, but it no longer returns false positives - when searching arrays of classes that override the < operator but - !(x for relative positioning within their parents - - - getFileSystem added to the GUI environment - - - New IGUISpriteBank, used to hold 2d image data like fonts and GUI icons. - Icons provided by the built-in font are now accessed through the skin's sprite bank. - Users can override the icons by setting a different sprite bank and setting new sprites. - - - Skins are now serializable and are loaded/saved with the GUI. - - - IGUIStaticText getter/setter functions patch by rogerborg. - -- added 3d TextSceneNode2. to view a Text in real 3D Space - in fact it is a combination of Billboard & TextSceneNode - -- Burning Video (the second but only complete software renderer) - - New Compile Config BURNINGVIDEO_RENDERER_ULTRA_FAST - - New Compile Config BURNINGVIDEO_RENDERER_FAST - touching the 20fps border in the demo ( P4 mobile 2Ghz ). 15fps average. - ( Compile config Release Fast-FPU ) - - - VertexCache for Tansformed & Light Vertices - boost small drawPrimitive Calls ( 2DRectangle, Billboard ) and Real Index Triangles - - - Bilinear Dither - - clipping test ( compare instead of generic plane normal ) - - support for NOT using vertexcolor - #define SOFTWARE_DRIVER_2_USE_VERTEX_COLOR - -- added vertex to color to billboard. - shade top & shade down. - to support some static lighting effect on billboards - -- Implemented line rendering for SoftwareDriver - -- XMLWriter fix for 32bit wchar_t (esp. for big endian) - -- updated to latest PNG library - -- implemented CImagerWriterJpeg::writeImage - -- The ISceneManager::addCameraSceneNodeFPS() has a new parameter named 'jumpSpeed' - and a Key Map Entry. - -- added param to IIImageWriteFile::writeImage - control Parameter for the backend ( e.g. jpeg compression level ) - -- addContextMenu: CGUIEnvironment::addContextMenu set the focus on the submenu. - -- Added IFileSystem::createMemoryReadFile for accessing memory like a file. - -- Added core::map class submitted by Nastase Catalin (Kat'Oun) - -- Fix vertex colors for .x and .ms3d, alpha bug in .obj - -- Fixed 16bit depth screens under Windows. - -- Implemented getMeshBuffer(SMaterial) for all AnimatedMeshes. - It was returning 0 for all implementations previously. User defined IMesh derivates - will also have to implement it now due to the removed empty implementation. - -- Added yield() method to IrrlichtDevice which allows to pause the Irrlicht process for - a very short time. This allows other processes to execute without a major - penalty for the Irrlicht application. - -- Added sleep() methd to IrrlichtDevice, for pausing the Irrlicht process for a longer - amount of time. - -- Auto-split mesh to 16bit buffers in 3ds loader - -- 8bit RGB332 image format support - -- isActive() under Linux now behaves like the Windows variant: True iff window has focus - -- Fixed(?) the glXGetProcAddress problems with different drivers - -- B3D changes by Luke: - Texture scaling bugfix, support for alpha blending, new option to normalise weights, - animation code optimization, fixed memory leak - -- ROUNDING_ERROR is now ROUNDING_ERROR_f32 or ROUNDING_ERROR_f64 - -- Material ZBuffer flag changed to a u32 value - Reason: change ( off or on ) to , off, lequal, equal - Necessary for multi-pass if previous stage has had transparency - -- DebugDataVisible is now an enum of flags - show normals is supported ( uses the new build in arrowmesh ) - -- New Function: GeometryCreator - addArrowMesh. build a closed cylinder and a cone - used to show normals as debug feature - -- New Function: - CMeshManipulator::transformMesh(scene::IMesh* mesh, const core::matrix4& m) const - transforms VertexPosition and VertexNormal - -- BUGFIX: CGUIButton notified Pressed when Mouse was clicked Inside ( correct ) - but also left up outside rectangle ( incorrect) - -- BUGFIX: Octree:getPolys(const scene::SViewFrustum& frustum, SIndexData* idxdata) - was recursive calling invisible children - -- CFileList: Changed FileListEntry sorting to - a) Directory comes first - b) sorting ignores case - so it feel's more like common browers - -- added a Texture transform to IVideoDriver::setTransform - -- quaternion::getmatrix - in fact the getmatrix version is returning the transposed. - i'm quite sure that this is the wrong implementation. - so this should be verified to remove the getmatrix_transposed version... - -- Quake3 Map Loader: - new loading method - - Bezier Patches with LOD more than 3 - - Multiple Meshes, stay compatible with the previous version - - Indexed Triangle List - - initial support for quake3 Shaders and Entities - - Shaders are parsed. When it's possible to resolve a 2 Texture Scheme it's taken - Shaders exist in namespace scene::quake3 - - The Example Quake3Map shows how to continue applying the Q3Shaders with SceneNodes - ( for example animmap converts to TextureAnimator.) - TODO: use the Irrlicht Variable Syntax to remove redundant code.. - -- added getVertexPitch() to IMeshBuffer interface - -- added generic isupper, isspace.. functions to coreutil.h to remove dependencies for ctype.h - ( future: it's possibly to use binary comparison test..) - removed 1000's include of string.h and moved one to irrstring.h - in preparing of complete removing the MSVC. - -- moved fast_atof.h to the public include - added strtol10 to remove dependencies for stdlib.h - anyway math.h is needed for powf - -- core::vector3d - added getInterpolated_quadratic. - vector3d getInterpolated_quadratic(const vector3d& v2, const vector3d& v3, const T d) const - // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d; - -- irrstring: added param start to findLast(T c, s32 start = -1 ) - reason: to continue searching reverse on a specific position - (parameter is checked against boundaries ) - -- added operation reciprocal_squareroot to irrmath. - core::reciprocal_squareroot = 1.f / sqrtf ( x ) - changed the core::vector3df normalize vector. - specialized templates are not allowed in irrlicht currently, so it's only for f32 for now. - a C function and a NVidia Version are in irrmath.h - -- add Primitives to CFPSCounter - and changed interpolation to 1500ms instead of 2000ms - and rounding to ceiling.. - -- added Interface setAmbientLight to ISceneManager - it was a Bug, because SceneManager always calls Driver therefore AmbientLight has to be set in SceneManager. - -- changed GUIFont & FontTool to support kerning ( on a global basis ) - very basic mode.. apply an offset for position - useful for example if you want to apply an outline stroke in your favorite - and therefore let the texture grow. - and to correct the border back on drawing, specify the parameter in IGUIFont. - this is quite useful if you want to use more artistic fonts. - default = 0 - better kerning would need a seperate coordinate set for each symbol. - -- changed MD2_FRAME_SHIFT to lower framerate - -> lower IPol - problems can occur if somebody uses hardcoded frame-numbers instead - of Animation name... - -- changed spelling "frustrum" to "frustum" - - -> changed also SViewFrustrum.h to SViewFrustum.h - -- changed Parameter AutomaticCulling from bool to enum E_CULLING_TYPE - to support more than two culling modes. - - added Frustum culling ( it's a copy & paste from the octree ) - added initial bounding sphere - used for culling point lights.. - -- Added getSystemMemory and getProcessorSpeedMHz for Windows and Linux to the OSOperator, submitted by Vitek. - -------------------------------------------- -Changes in version 1.2 (29 Nov 2006) - -- Added Solaris/Sparc port (basically some compiler define statements). Irrlicht and the examples should compile out-of-the-box on Suns with the usual Makefiles and gnumake. - -- Added texture matrix support for hardware accelerated drivers. This allows for efficient texture coord manipulations for complete meshes at once. - -- Multisampling with OpenGL under Linux added - -- Non-power-of-two textures are left unscaled if the driver supports such textures. - -- new draw2DImage method that speeds up drawing many quads from the same texture. Font drawing is improved by this under OpenGL. - -- TGA files are now always correctly flipped and loaded if compressed. All PNG color formats are now supported, including correct alpha handling. - -- 3ds mesh loader fix in texture loading, now loads some textures that were not loaded before, but might introduce problems with very recent files. OGRE mesh loader bugfixes and lightmap support. Several B3d mesh loader updates. Obj and mtl loader enhancements. - -- A new compile flag (IRR_OPENGL_USE_EXTPOINTER) allows Irrlicht to either use OpenGL extension function pointers or direct OpenGL calls. - -- OpenGL now uses frame buffer objects for render targets larger than the screen, supplied by Mandrav - -- Split ESNRP_LIGHT_AND_CAMERA passes into ESNRP_LIGHT and ESNRP_CAMERA to fix a problem with lights being rendered before cameras in OpenGL (thanks again to Vitek for finding this). ESNRP_LIGHT_AND_CAMERA is now deprecated. - -- Fixed many OpenGL render state problems which were related to wrong texture states. The textures are now enabled and disabled by the material renderers in OnSetMaterial. Also enabled the texture state cache which helps preventing texture changes just as the one for D3Dx. Thanks to hey_i_am_real for some good hints on where the problem was located. - -- Added compile flag _IRR_COMPILE_WITH_X11_ which is by default enabled. Disabling the flag removes all X11 dependencies from Irrlicht and allows for a headless Linux Irrlicht server - added by request :-) - -- Win32 OpenGL driver tries to use the requested bpp size. - -- Default texture format is now A8R8G8B8 if not explicitly specified. This fixes some color artifacts with lightmaps. Bugfix submitted by hey_i_am_real. - -- In OnPostRender all transformations were taken as relative and multiplied with the root transformation matrix every time due to a wrong check for the real root node. This shoudl increase render performance for scenes with lots of (invisible) nodes. - -- Added correct list copy constructor. - -- Color selection dialog added. - -- New GUI skin "Burning Skin". - it's a black & white skin. look elegant on true-color. - and looks ok on 1-Bit ( e.g. no vertex color in burnings video ) - -- GUIStatic text is correctly grayed out if disabled. - -- Added getHeight method for terrain node submitted by Spintz. It calculates the height from the base mesh instead of requiring ray casts and collision detection and is much faster. - -- New methods core::lerp to linearly interpolate two floats and SColor.getLuminance to calculate luminance of RGB color. - -- MAJOR API CHANGE: - Fixed matrix access methods mat(x,y). These were previously said to be (row,column) but actually were (column, row). This lead to some confusion and made their use quite tricky. Irrlicht code is updated for the new method, but applications will silently fail now (i.e. compile without errors, but not working as expected). - -- Update to zlib-1.2.3 - -- Fixed vertex alpha handling in DirectX drivers. - -- Image writers fixed and working (at least for little endian systems). - -- VSync under Linux fixed and correctly working. - -- New os::Byteswap::byteswap methods which can be used for byteswapping (endianess correction) in mesh loaders and image loaders. - -- New video driver feature to check for multitexture feature. - -- Direct3D drivers update the devicelost variable if reseeting failed with this return code. - -- VideoModeList under Linux is correctly filled now. No glX calls are made if GLX extension is not found - only software drivers are available then. RandR extension can be enabled with a new compile flag in IrrCompileConfig.h, either instead of XF86VidMode or in addition. - -- Big Endian support for MS3D loader. - -- Apfelbaum software renderer: basic mipmap support (per triangle), switch for using w-buffer instad z-buffer ( default on ) - -- Better FPU support: Changed various fpu-call's in whole project (main reason to use faster float to int conversion on x86. ( fistp )) - -- changed Visual Studio 7.1 vcproj project config "Release Fast FPU" to __fastcall in /QIfist - -- CGUIFont added True Alpha Font Support. (currently it's a little hack, but it'a good starting point. Fonts are back compatible. To use the new feature make first pixel half transparent in the font file.) - -- Scolor: replaced s16 color with u16 color, replaced s32 color with u32 color to get rid of unnecessary arithmetic shift - -- Colorconverter: X8R8G8B8toA1R5G5B5, set Alpha High, minor: A1R5G5B5toA8R8G8B8 changed if (a) to conditional set - -- CImage: added boxfilter (weigthed average), (generic, slow) - -- The scene manager now sets an ambient light color when calling ISceneManager::drawAll(). - You can influence this by calling ISceneManager::setAmbientLight(). That light color - is also stored when saving .irr files via ISceneManager::saveScene(). - -- Loaded COLLADA files which contained only one single mesh now behave like all the - other loaded meshes, and the #meshname workaround has been removed. - -- File lists are now sorted. - -- Dynamically checking the OpenGL version now instead of at compile time to call the supported methods of the executing machine, not that one of the compile host. This should fix the extension check and the automatic mipmap update. - -- Fixed vertex alpha handling of 2D images with OpenGL. - -- Default depth buffer under Windows now 24bit to avoid zbuffer fighting. - -- Fixed light count in OpenGL. - -- Particle emitters can now be enabled/disabled via a new method. - -- Sky dome is rotatable just like the sky box. - -- Rotation animator can be applied to several nodes now, before it only rotated the first one it was applied to. - -- Support for drawing other vertex primitive lists such as triangle strips. - -- Default specular color is white again, thus simply enabling shininess is enough to get speculars. - -- Some .x loader and animator improvements. Vertex color support. - -- isActive now also work under Linux. - -------------------------------------------- - -Changes in version 1.1 (06 Aug 2006) - -- New example to show some features of the .irr format - -- Added support for making screenshots in all video drivers and a general - possibility to save any IImage to several file formats. - Some image writers are not yet implemented. As a testcase screenshots - are now available in the demo by pressing F9. - This code was contributed by Travis Vitek. - -- Changed EAMTS_OCT to EAMT_OCT. - -- Improved .3ds and .obj file importers. - -- Added support for .b3d (Blitz Basic) submitted by Luke Hoschke and - .pak (Quake archive) files submitted by skreamz. - -- Added sky dome implementation contributed by Anders la Cour-Harbo (alc). - -- In addition to the Cube scene node (formerly test scene node) there is now also a sphere scene node available, - with an adjustable amount of polygons. Use ISceneManager::addSphereSceneNode to create it. - Thx to Alfaz93 for making available his code on which this node is based on. - Note that both nodes now use default material settings, e.g. lighting is enabled by default. - -- Fixed Linux keyhandling for many keys. - -- The aspect ratio has been inverted in the matrix, which means when setting a new aspect ratio - for cameras, set it to screen.width/screen.height now instead of screen.height/screen.width - as previously. - -- added support for reading/importing binary .x files. - -- .ms3d and .x normals are now correctly transformed in animations, bounding - boxes are slightly better transformed, but not yet correct. - -- Added possibility to load and save Irrlicht scenes to and from xml files via - ISceneManager::saveScene and ISceneManager::loadScene. Note that not all - scene nodes are supported yet, but most features should already work. - -- Bounding box of the Skybox corrected (set to null) - -- The SMaterial structure now supports 4 textures. (Currently ignored by the renderers and their materials.) - -- Test scene node renamed to CubeSceneNode. - -- Added scene node animator factories. This is the same as scene node - factories, but for scene node animators. - -- Added scene node factories. This is an interface making it possible to dynamicly - create scene nodes. To be able to add custom scene nodes to Irrlicht and - to make it possible for the scene manager to save and load those external scene nodes, simply - implement this interface and register it in you scene manager via ISceneManager:: - registerSceneNodeFactory - -- Introduced IMeshSceneNode interface with the possibility to set readonly materials to make - it possible to use the mesh materials directly instead of overriding them. In this way - it is possible to change the materials of a mesh causing all mesh scene nodes - referencing this mesh to change, too. - -- Added possibility to load OGRE .mesh files directly, thanks to Christian Stehno who contributed - a loader for this. - -- Merged with Irrlicht 1.0 for MacOS - -- Added a method getType() to ISceneNodeAnimator. - -- There is now a system to serialize and deserialize attributes of scene nodes. In this way - it should be quite simple to to expose the attributes of your scene node for scripting - languages, editors, debuggers or xml serialization purposes. - -- Irrlicht containers and strings now have allocators, making it possible to - use them across .dll boundaries. - -- Changed the name of scene nodes from wide character to to char* for speed and memory reasons. - -- Renamed IStringParameter class to IAttributes and enhanced it to be able to - serialize its content into and from xml. - -- Textures now have a method getName(). - -- Added the methods getTextureCount() and getTextureByIndex() to IVideoDriver. - -- Most classes now derive virtually from IUnknown. - -------------------------------------------- -Changes in version 1.0 (19 Apr 2006) - -- Irrlicht now will load d3d 9 dlls (like d3dx9_27.dll) manually if needed. If you compile irrlicht - with an SDK which needs one of these dlls, irrlicht will now also start up on a pc without - these Dlls installed. Note that now these dlls will also only be loaded if your application - uses shaders. If the dlls are missing, shader support will be disabled. - -- The Apfelbaum Software Software Renderer now works in 32 bit and is capable of rendering dynamic - lighting as well as doing alpha channel blending. - -- Added support for the Code::Blocks IDE (http://www.codeblocks.org) - -- It is now possible to draw temporarily to foreign windows, by specifying a window handle when - calling IVideoDriver::endScene(). Note: This does not work in fullscreen mode and is not - implemented for all devices (only for D3D8, D3D9, Software1 and Software2, and only for Windows). - In addition, you can also specify the source rectangle to present. - -- Picking is now more accurate and also works with view ports and better with orthogonal cameras. - -- Scene Nodes now have an additional flag, IsDebugObject. This denotes if a - scene node is a debug object. Debug objects have some special properties, - for example they can be easily excluded - from collision detection, picking or from serialization, etc. - -- Scene Nodes now have the possibility to return their type using - virtual ESCENE_NODE_TYPE getType(). - -- Improved support for orthogonal rendering: Skyboxes and billboards can be - used with orthogonal cameras now, too. - -- Fixed a bug in collision - -- Fixed some marshalling bugs in Irrlicht.NET - -- Some fixes to make gcc 4 happy. - -- Fixed a bug which caused the engine to crash when trying to use the - apfelbaum software rasterizer with linux - -- Several improvements to Irrlicht.NET, for example string output for vectors, viewfrustrum access - for cameras, drawing of bounding boxes, support for orthogonal cameras. - -- Updated DMF importer to support new DeleD functionalities, solid materials will now be - shown correctly again in Irrlicht. Thanks to Salvatore "Il Buzzo". - -- Added a method to change the return value of ICameraSceneNode::isOrthogonal - -- Improved md2 animation playback - -- Fixed the REFLECTION_2_LAYER materials. Now also works for OpenGL. Had to change the parameters - of this material (for all drivers), the reflection is now at texture 2 and the diffuse map at - texture 1. This was the other way round before. - -- Added examples for csharp, visualbasic, delphi.net and boo. - -- Several other small bug fixes. - -------------------------------------------------------------------------------------- -Changes in version 0.14.0 (30 November 2005) - -- Irrlicht now includes another video driver type. Together with D3D8, D3D9, OpenGL, the NULL - driver and the Software Renderer, an Irrlicht user now has the decision between 6 renderers: - The new included renderer is The Apfelbaum Software Renderer, an alternative software renderer - for Irrlicht. 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. In short: It looks a lot like the already available hardware - accelerated drivers, but without hardware. :) This renderer has been written entirely by - Thomas Alten, thanks a lot for this huge contribution. - -- Irrlicht now supports anisotropic filtering. Use the SMaterial::AnisotropicFilter member or - EMF_ANISOTROPIC_FILTER flag to enable it. I implemented this for all 3 hardware accelerated - drivers: D3D8, D3D9 and OpenGL. - -- Irrlicht now supports the recently released new microsoft compiler. Irrlicht versions compiled - with older verions of this compiler can now also be used with the new one, which wasn't possible - previously because of a name mangeling issue. - -- All 2D drawing functions can now be used to draw into textures (render targets). This also - means for example that the whole GUI environment can be rendered into textures. - -- Irrlicht.NET now supports shaders. - -- Irrlicht now loads all textures in 32 bit mode by default. (Previously this - was 16bit). To change this behavior back again, use - device->getVideoDriver()->setTextureCreationFlag(ETCF_ALWAYS_16_BIT, true); - -- Irrlicht.NET now supports Particlesystems and Shaders. Thanks to a code - contribution by Delight. - -- Fixed a bug in the mipmap generation. Now mipmaps are not that blurry - anymore and the rendering quality has been improved a lot. - -- It is now possible to assign a userData int to callback functions of shaders. In this way it - it easily possible to use the same callback method for multiple materials and distinguish - between them during the call. - -- Directional lights are now supported in the OpenGL and D3D drivers. To switch on directional - lighting, set the light type to ELT_DIRECTIONAL in the SLight structure. - -- Fixed several bugs in the GLSL implementation. Thanks to Michael Zoech for - sending in his improvements. - -- For the windows version of Irrlicht, the engine now displays an icon in the - program window, if there is one available in the start path with the name "irr.ico". - -- It is now possible to use images with alpha channels on buttons. Use the new - IGUIButton::setUseAlphaChannel() method to enable this feature. - -- The scene manager has a new method getSceneNodeFromName() which finds a scene node by its name. - -- It is now also possible to attach scene nodes to joints/bones of sceletal animated .x files. - (Using IAnimatedMesh->getXJointNode() ). This was previously only possible with milkshape models. - -- Billboards now draw their bounding box when debugdata is set to visible for them. - -- Lights now draw their bounding box and radius when debugdata is set to visible for them. - -- Upgraded to irrXML 1.2. Thanks to some hints by Patrik Mller, irrXML, the XML parser used - by the Irrlicht Engine now has CDATA support and some other useful new features. - -- Support for VisualC++ (Express) 2005. Added a project file and a IrrlichtPropsVC2005.vsprops - file which sets the no deprecate define and adds needed libraries. - -- Fixed size of the bounding box of billboards. - -- Billboards are now also culled by default, increasing rendering speed a bit. - -- Fixed a bug which caused the .ms3d loader to crash when loading .ms3d files - without materials. Thanks to sdi2000 for posting this. - -- Fixed a bug causing the possibility to crash when destructing the scene - graph or a scene node with children. - -- Fixed some bugs which caused invalid RTT operations, when for example the - render target texture was smaller than the screen. - -- Fixed a heavy bug in Irrlicht.NET causing lots of memory leaks when drawing text. - -- Fixed a bug in the attachement of scene nodes to animated X files. - -- Fixed a bug in the .NET Vector3D addition operator. - -- Updated to Salvatore Russo's DMF loader version 1.3. Notes by him: - This version just adds some new functionalities. First of all Alpha Blended Textures are now - supported by DeleD as well as loader. Because of some trouble with Irrlicht 0.12.0 TGA loading, - TGA textures are always flipped so I've added a parameter so that you can choose to - flip or not all TGA textures coords, this way: - SceneManager->getParameters()->setParameter(scene::DMF_FLIP_ALPHA_TEXTURES, true); - you can also set material transparent reference value by setting: - SceneManager->getParameters()->setParameter(scene::DMF_ALPHA_CHANNEL_REF, 0.01); - you can use every value beetween 0 and 1, but to respect DeleD rapresentation - 0.01 is OK, just a note, if you set 0, it's just like you set 0.5, this means - that each pixel found corresponding to a position in alpha map that has a value<127 - won't be drawn. - -- Fixed a small bug in the line breaking algorithm. - -- Fixed a bug which caused the engine to display strange artifact pixels when drawing 2D images - like text in screens which odd resolutions. - -- Slightly changed the interface of createDevice and createDeviceEx(): the version parameter - now is a char* instead of wchar_t*. Also, IrrlichtDevice::getVersion() now returns char* - instead of wchar_t*. - -- Fixed some parts in the source to make Irrlicht compile in Linux 64. - -- Renamed the EDT_DIRECTX8, EDT_DIRECTX9, _IRR_COMPILE_WITH_DIRECTX_8_ and - _IRR_COMPILE_WITH_DIRECTX_8_ enumeration literals to EDT_DIRECT3D8, EDT_DIRECT3D9, - _IRR_COMPILE_WITH_DIRECT3D_8_ and _IRR_COMPILE_WITH_DIRECT3D_9_. You might need to - update your code and compilation settings with these new names. - -- Added the remaining '..' directory in the linux version of the file list - -- Updated to a faster version of the TerrainSceneNode by Spintz. Much thanks again! - -- Fixed a bug causing billboards to be displayed upside down. - -- The D3D drivers now won't crash anymore when they get feeded with nullpointers as shader constants. - -- Irrlicht now identifies the Linux platform it runs on and returns a more detailed string - when calling getOperationSystemVersion(). - -- Fixed some bugs in several collision test methods thanks to Spintz. - -- Updated font tool - -- Made the list::iterator constructor which took a sklistnode as parameter private, - to make Irrlicht compatible with the Errlicht interface. - -------------------------------------------------------------------------------------- -Changes in version 0.12.0 (24 August 2005) - -- It is now possible to have multiple scene managers. Use ISceneManager::createNewSceneManager() - to create a new one. This can be used to easily draw and/or store two independent scenes at - the same time. - -- Irrlicht now supports GLSL, the OpenGL Shading Language, which means Irrlicht now - supports 14 shading modes/languages: ARB Vertex Programs, ARB Pixel Programs, HLSL, - GLSL 100, GLSL 110VS1.1, VS2.0, VS3.0, PS1.1, PS1.2, PS1.3, PS1.4, PS2.0, PS3.0. - Lots of thanks go to William Finlayson for implementing this and making available his code - to be used in Irrlicht. - -- Added support for pixel shader 3.0 and vertex shader 3.0. - -- Irrlicht now supports detail maps, use EMT_DETAIL_MAP for this. The new terrain scene node - tutorial shows how to use detail maps. - -- Again some changes have been made in Irrlicht.NET. For example it is now a little bit more memory - friendly, I removed several bugs and made the terrain scene node, realtime shadows and key codes - available. - In addition, I extended the .net example application a lot, just try it out. - -- I've worked around a heavy bug in the microsoft compiler which caused lots of bugs in Irrlicht.NET. - They are all fixed now. See http://support.microsoft.com/default.aspx?kbid=823071 for details. - -- The timer of the engine has been enhanced a lot, which maybe needs a little change in your - project if you are upgrading from an older version of Irrlicht. It is now possible - to set the speed of the timer, a new time value, and to start and stop it. Also, all - calls to getTime() will now return the same value within the same drawing frame. - The timer will only advance when ITimer::tick() is called. IrrlichtDevice::run() will - call this method automatically, but if you aren't using this method, and you are wondering - why your scene is not animating anymore, just call Device->getTimer()->tick() before - drawing your scene. If you need the system time, not the new virtual time, - use ITimer::getRealTime(). - -- The material EMT_TRANSPARENT_ALPHA_CHANNEL now is using a configurable alpha ref value. - The default value is 127, which means people who are using this material for drawing - things like grass, trees etc will get nice results automatically when changing to 0.12.0. - To change to a different alpha ref value, just change SMaterial::MaterialTypeParam value. - See EMT_TRANSPARENT_ALPHA_CHANNEL for details. - Also, this fixes two bugs: - - A bug causing the D3D versions not looking like the OpenGL version. - - A second bug which caused the texture to look like disappearing when looking at from far away. - -- Upgraded to a new dmf loader version by Salvatore Russo which is able to use a texture path - and material directories. Set DMF_USE_MATERIALS_DIRS and DMF_TEXTURE_PATH using the - ISceneManager::getParameters() method. - -- It is now possible to set a separate scale for the second texture coordinate set in the - terrain scene node when calling ITerrainSceneNode::scaleTexture(). This is useful when using - detail maps on the terrain. - -- Added a new material flag named EMF_NORMALIZE_NORMALS. You can enable this if you need - to scale a dynamic lighted model. Usually, its normals will get scaled too then and it - will get darker. If you enable the EMF_NORMALIZE_NORMALS flag, the normals will be - normalized again. - -- When loading Milkshape .ms3d files, Irrlicht also loads materials and tries to apply the textures. - Thanks to atomice for this patch. - -- The ISceneManager::addCameraSceneNodeFPS() has a new parameter named 'noVerticalMovement' with which - it is possible to disable vertical movement of the FPS camera and make the camera behave just like - in most ego shooters today. - -- Made Irrlicht 64 bit compatible, removing some 32 bit only constructs. However, I wasn't able to - test it out extensively. If you are compiling Irrlicht for a 64 bit windows environment and get - a linker problem, try playerdark's solution: - "The linker settings are so that no machine is specified in the drop down field, instead, - the command line option /MACHINE:x86 is set manually which interferes with the 64 bit linker - of course. Removing that from the 64 bit version (and replacing it with the drop down selection - in the 32 bit version for that matter) fixed the linker problem." - -- There is now a IrrlichtDevice::postEventFromUser() method available, to make it possible to - post key or mouse input events to the engine if you are using an own input library for - example for doing joystick input. - -- The GUI Environment now has an own basic RTTI system, and all IGUIElement derived classes - have a method named getType(). This is needed for the .NET wrapper but will be used - later for serializing and deserializing. - If you wrote your own GUIElements, you need to set the type for your element as first parameter - in the constructor of IGUIElement. For own (=unknown) elements, simply use EGUIET_ELEMENT. - -- Thanks to William Finlayson, Irrlicht now also supports RTT (render to texture) when - rendering using OpenGL. - -- Thanks to William Finlayson, the EMT_REFLECTION_2_LAYER is now implemented in the - OpenGL version of Irrlicht, too. - -- There is now a mesh cache interface available. With this, is is possible to get access to - all loaded meshes, and to remove them to free memory. You can get access to the cache - using ISceneManager::getMeshCache(). Please note that the addMesh() method of ISceneManager - now is now longer available, you can find it now in the IMeshCache interface. - -- The VideoDriver now has a method for clearing the zbuffer at any time: IVideoDriver::clearZBuffer(). - With this, it is for example easily possible to overlay two scenes. - -- Fixed a bug which caused Irrlicht to crash when loading grayscale jpeg files. - -- Somebody sent me an .x file (tank_human1_crashes_irrlicht.zip) which caused Irrlicht to crash. - It seems I've lost that mail, but maybe you are reading this: It's fixed now. :) - -- Fixed a bug which caused the diffuse maps of lightmaps to disappear under certain circumstances - in OpenGL. - -- Its now possible to make IGUIStaticText draw its background. - -- Removed the first two default parameters from - IGPUProgrammingServices::addShaderMaterialFromFiles() to prevent SWIG - to create non compilable wrapper code. - -- Fixed a small bug which caused the terrain scene node to be culled incorrectly. - -- Changed the names the driver return (now "OpenGL 1.5", "Direct3D 9.0" and "Direct3D 8.1") - -- Added a new macro _IRR_DEBUG_BREAK_IF which is now used instead of the _asm int 3 break points in - debug mode. - -- Fixed a bug were the software renderer didn't clip 2d rectangles. This effect was visible for - example when using list boxes, selecting an entry at the end an scrolling up so that it wasn't - visible anymore. - -- There is now a new gui event available (named EGET_COMBO_BOX_CHANGED) which will be - sent when the selected item in a combo box has been changed. Finally. - -- Fixed a Problem which caused an empty window to be created when a rendering device - could not be initialized under special circumstances. Thanks to Sascha Plumhoff for - the bug report. - -- Fixed a bug with the FileList in Linux, reported by DrAnonymous and fixed by William Finlayson. - -- Fixed some bad documentation bugs. - -- The XWindow handle is now exposed too, via IVideoDriver::getExposedVideoData(). - -------------------------------------------------------------------------------------- -Changes in version 0.11.0 (08 July 2005) - -- Antialiasing is now supported by Irrlicht in the D3D8 and D3D9 renderer. To switch - it on, use createDeviceEx() and set SIrrlichtCreationParameters::AntiAlias to true. - -- Irrlicht.NET can now run inside a pre created Windows.Form window. - -- I'm no longer providing a Visual Studio 7.0 project/solution file for the Irrlicht - Engine sourcecode, only 7.1 and 6.0 are supported. If you are using Visual Studio 7.0, - just open the .dsp file for Visual Studio 6.0, it will be converted automatically. - -- Irrlicht.NET includes now all basic GUI Elements and can capture GUI events. There are - still some features missing, but it is already enough to do simple things like showing - message boxes, displaying images, getting input strings, etc. - -- Improved the .NET documentation a bit. - -- There is a full implemented ISceneCollisionManager now available in Irrlicht.NET. - -- The Linux OpenGL renderer now supports mip mapping. - -- It is now possible to compile Irrlicht as shared lib in Linux. To do this, go into the source - folder and run 'make sharedlib'. This should create a libIrrlicht.so.0.11.0 file in - lib/Linux. To install it in /usr/local/lib, you can run 'make install'. - -- The drawing of the GUI system has been refactored and a lot of redundant code has - been removed. - -- The new method IVideoDriver::draw2DRectangle() is able to draw rectangles not only - filled with a single color, but with a gradient from four colors. This is implemented - in all drivers except the Software driver which still uses one color for this method. - -- It is now possible to customize the GUI system's skin a lot more: Simply implement your - own IGUISkin interface and implement the draw..() methods. - -- There are now two build-in skins available: Windows Classic and Windows Metallic. The - default skin is now Windows Metallic, if you want to change back to the old skin, use the - following code: - gui::IGUISkin* newskin = environment->createSkin(gui::EGST_WINDOWS_CLASSIC); - environment->setSkin(newskin); - newskin->drop(); - -- Added improved keyboard input handling for the Linux version of Irrlicht, thanks to - Fabien Coutant for the fix. - -- Fixed a bug in the Linux OpenGLDriver which caused to load a wrong OpenGL extension - and made multitexturing look quite strange. Thanks to hybrid for spotting out that - bug. - -- COLLADA file loading now works the same like the loading of other meshes: Just - call ISceneManager::getMesh("yourfile") and display it using for example - ISceneManager::addAnimatedMesh(yourLoadedMesh); - To make it possible to create instances from meshes, lights and cameras in COLLADA - files again as in irrlicht 0.10, just enable the collada instance creating mode: - SceneManager->getParameters()->setParameter(COLLADA_CREATE_SCENE_INSTANCES, true); - -- Added lots of useful methods to the IStringParameters class. It is now possible to - set not only strings but also boolean, integer and float values as parameters. -- Fixed a bug with the TRANSPARENT_ALPHA_CHANNEL materials in all renderers to make them - work more as expected: They didn't write to the zbuffer. If you are using this - material and you don't want the new setting, just set the ZWriteEnable flag in the - SMaterial structure of your transparent material to false. Thanks to Fabien to - point this out. - -- There are now some new defines making it possible to use system installed libs instead of - the ones which come with Irrlicht: _IRR_USE_NON_SYSTEM_JPEG_LIB_, - _IRR_USE_NON_SYSTEM_LIB_PNG_ and _IRR_USE_NON_SYSTEM_ZLIB_, which are defined by default - in the file IrrCompileConfig.h - -- Renamed ISceneManager::getStringParameters() to ISceneManager::getParameters() -- Changed the define _IRR_D3D_SHADER_DEBUGGING to _IRR_D3D_NO_SHADER_DEBUGGING to be - able to make it defined by default and to let it be included in the doxygen documentation. - -- The SceneManager now does not do any culling tests for cameras, lights and skyboxes. - -- Added a transformBoxEx() method to matrix4 which transforms a bounding box more accurate. - -- Small edit box copy & paste bug fixed thanks to Fish HF - -- Fixed a bug which caused the engine to read windows messages when embedded in - a custom win32 control when called IrrlichtDevice::setResizeAble(). Thanks for - Duncan Mac Leod to find that bug. - -- Fixed a bug in the HLSL renderer which caused Irrlicht to crash, if no vertex shader - was specified. Thanks to mightypanda for reporting this. - -- Fixed a bug in the normal map generation thanks to jox. Parallax mapping and - normalmapping now even look a lot better because of this. ;) - -- Updated to irrXML 1.1: - - The XML parser is now also able to parse embedded text correctly when it is shorter than - 2 characters. - - The XML parser now treats whitespace quite smart and doesn't report it when it is - obviously used for formatting the xml file. (Text won't be reported when it only contains - whitespace and is shorter than 3 characters) - - The XML parser won't crash anymore when the xml file is malformed and an attribute has - an opening but no closing attribute. - - Removed a documentation which claimed that the xml parser doesn't work as the xml standard - when replacing special characters, which wasn't true. - -------------------------------------------------------------------------------------- -Changes in version 0.10.0 (26 May 2005) - -- The engine is now able to use parallax mapping. It's implemented for D3D9, D3D8 and OpenGL. - The perPixelLighing tutorial shows how to use it. Thanks go to Terry Welsh who wrote - the 'Parallax Mapping with Offset Limiting'-paper on which the Irrlicht implementation - is based and who allowed me to use his texture for use in the example. - -- Added render to texture support. Currently, only the D3D9, D3D8 and the software renderer - are able to use this feature. There is a new example, showing how to render scenes into - a texture. - -- Irrlicht now can load .png textures. There is also a new compile configuration - define to exclude the png loading option: _IRR_COMPILE_WITH_LIBPNG_. Thanks to - rt who originally wrote the png loader and who allowed me to use and modify his code - and place it under the Irrlicht Engine license. - -- Added support for COLLADA files. COLLADA is an open Digital Asset Exchange Schema for the - interactive 3D industry. There are exporters and importers for this format available - for most of the big 3d packages at http://collada.org. Irrlicht can import COLLADA files - by using the ISceneManager::getMesh() method. As COLLADA need not contain only one single mesh - but multiple meshes and a whole scene setup with lights, cameras and mesh instances, - this loader sets up a scene as described by the COLLADA file instead of loading - and returning one mesh. The returned mesh is just a dummy object. However, if the - COLLADA file does not include any tags, only meshes will be loaded by the - engine and no scene nodes should be created. Meshes included in - the scene will be added into the scene manager with the following naming scheme: - path/to/file/file.dea#meshname. The loading of such meshes is logged. - Currently, this loader is able to create meshes (made of only polygons), lights, - and cameras. Materials and animations are currently not supported but this will - change with future releases. - -- Added Delgine DeleD .dmf mesh loading support. I simply added Salvatore Russo's .dmf loader to - Irrlicht, and changed some parts of it. Thanks to Salvatore for his work and for allowing - me to use his code in Irrlicht and put it under Irrlicht's license. - -- Specular highlights are now finally usable the engine. To activate, simply set the shininess - of a scene node to a value other than 0: sceneNode->getMaterial(0).Shininess = 20.0f; - You can also change the color of the highlights using - sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255);. The specular color of the - dynamic lights will influence the highlight color, too, but they are set to a useful - value by default when creating the light. This feature is currently only available in - the D3D drivers. - -- Added a new material type: EMT_TRANSPARENT_ALPHA_CHANNEL_REF. This draws a pixel of the - material only when the alpha channel has a value greater than 128. It is ideal for drawing - for example leaves of plants and does not use alpha blending, so it is a lot faster than - EMT_TRANSPARENT_ALPHA_CHANNEL. - -- There is now a createDeviceEx() method with which it is possible to create an Irrlicht Engine - device into an already existing window. This currently only works in Windows. - This method will be extended in the future with other options. - -- Irrlicht.NET has been extended with ports of the SceneNodeAnimators, TriangleSelectors - the FileSystem and Font drawing. Also the documentation of it has been improved a lot. - -- There are two new tutorials/examples available. One demonstrates how to use render to texture - feature, the other one shows how to run Irrlicht inside a precreated Win32 window/widget. - This means there are now 17 examples available in the SDK. - -- The software renderer now renders 3d geometry transparent when its material is - somewhat transparent. - -- The XML Parser has been enhanced. Several small bugs have been fixed and there are some - new features: The parser can now read ASCII, UTF-8, UTF-16 and UTF-32 (both little and - big endian) files, and return the parsed string data in one selectable format from the - same list. In addition, it is now completely independent from Irrlicht. If you wish to - use the parser without the engine, take a look at the newly created project at - http://irrxml.sourceforge.net. - -- Upgraded to DirectX Exporter Mod 1.3.1 - -- Upgraded dev-cpp project file to Dev-C++ 4.9.9.2. Removed dependency to zlib and - jpeglib for devcpp, the necessary .c files are now simply included in the project. - -- Renamed the VisualStudio and DevCpp sub directories in the SDK to Win32-gcc, - Win32-VisualStudio. - -- Fixed a bug in irrXML causing it to replace xml characters wrongly sometimes. - -- The C++ decorations at createDevice() have been added again, because lots of people - started to mix the gcc and the microsoft .DLL and got confused why the thing crashed - at random positions. - -- Moved heapsink and heapsort into the core namespace. - -- Updated to My3D version 3.15 - -- Fixed the wrongly drawn alpha channel material in OpenGL driver and a problem with the - VertexAlpha material in the same driver. - -- Implemented multipass rendering in the OCTTree scene node now too. This means that octtrees can - now contain transparent materials as well. - -- Improved string comparison speed, especially when comparing with pointer to char or w_char, - no more temporary strings are being constructed now. In addition, there are some new - string comparison methods in this class. - -- Added string::replace() method. - -- Added string::trim() method. - -- Addes string::erase() method. - -- Fixed a bug in array which caused data corruption if an element which already inside the - the array was pushed_back. Thanks to vox for reporting this and to provide a solutin - -- Added ISceneManager::addMesh() method. - -- Added IMeshManipulator::recalculateNormals(IMeshBuffer*) method. - -- The file array.h has been renamed to irrArray.h - -- Due to a bug, Irrlicht 0.9 didn't cull the scene nodes anymore which resulted in a huge - performance loss. This is fixed now. - -- After lots releases ignoring the 'make the fps camera smoother request', it is now - finally integrated. - -- Removed audiere dependency and the mp3 file, reeducing SDK download size. - -- A bug was fixed causing the binding of the wrong fragment program sometimes in OpenGL. - -- Lots of internal filenames have been renamed. All CVideo* files have been renamed to - fit the other name conventions, CD3D9Driver.h into CD3D9Driver.h for example. - -- The IMaterialRenderer interface now has the new method getRenderCapability() which - returns if the material is able to be rendererd with all settings on current hardware. - -- Added IMeshManipulator::setVertexColors(); - -- Added float color reading support in the 3DS loader. - -- video::EVDF_BILINEAR_FILER renamed to EVDF_BILINEAR_FILTER - -- core::equals function added. - -- fixed a small bug in fast_atof thanks to jox - -- Added a method ICamera::isOrthogonal() which is being used by - ISceneCollisionManager::getRayFromScreenCoordinates(), thanks to a bug report and fix by - jox in this thread: http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=6243 - -- Added some fixes to the GUI environment to make the parent and child pointers be more - consistent as suggested by jox in this thread: http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=6220 - -- Fixed a bug which caused the ambient light not to be reset after a window resize in D3D8 and 9. - Thanks to jox for this bug report and fix. - -- vector3df equals method added. - -- added SColorf::getInterpolated() method - -- Moved ITextSceneNode interface to include folder. - -- Fixed a small bug in the My3DLoader which failed sometimes finding the right textures. - -- Fixed bounding box problem with meshes without joints in .X file loader, thanks to - jox. (http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=6669) - -- Fixed IFileSystem::getWorkingDirectory in Linux version. - (http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=6678) - -------------------------------------------------------------------------------------- -Changes in version 0.9 (28 Mar 2005) - -- There is now a 100% working terrain renderer available. The old buggy and unfinished terrain - scene node has been replaced by a new TerrainSceneNode which is based on Spintz's - GeoMipMapSceneNode and Soconnes terrain renderer. Lots of thanks for their work on - this and that they allowed it to be modified and integrated into Irrlicht. - -- It is now possible for a scene node to draw itself in multiple passes. This means it can - register itself for multiple render passes (E_SCENE_NODE_RENDER_PASS) and during rendering - it can query the current render pass using ISceneManager::getSceneNodeRenderPass(). With - this, SceneNodes can contain solid and transparent materials at the same time and will be - rendered in the correct order from now on. - The IAnimatedMeshSceneNode and the IMeshSceneNode implement this feature, so it is now - possible to create for example cars with transparent windows without the need of a separate - scene node. Because of this change, all render time enumeration values have been renamed. - -- Irrlicht is now able to load OCT files directly. OCT files - can be created with Paul Nette's Radiosity Processor from http://www.fluidstudios.com - or exported from Blender with Murphy McCauley's exporter. This exporter can be found - in the directory \exporters\OCTTools of the Irrlicht SDK or from his homepage - http://www.constantthought.com/project/OCTTools. A lot of thanks go to Murphy McCauley - for this work on this and his permission to include his OCTTools into Irrlicht. - -- Irrlicht is now able to load Cartography shop 4 (.csm) files directly. A lot of - thanks go to Saurav Mohapatra for this work on this and his permission to adapt and - include his IrrCSM library into Irrlicht. If you are using .csm files, please note that - you'll have to set the path of the textures before loading meshes. You can do this using - SceneManager->getStringParameters()->setParameter(scene::CSM_TEXTURE_PATH, - "path/to/your/textures");. The original loader can be obtained from - http://www.geocities.com/standard_template/index.html - -- Irrlicht is now able to load Pulsar LMTools (.lmts) files directly because it now - integrates a modified version of Jonas Petersen's lmts loader in version 1.5 (from - http://development.mindfloaters.de/). Lots of thanks go to him for creating this - loader and giving his permission to add it to Irrlicht. If you are using this loader, - please note that you can set the path of the textures before loading .lmts files. - You can do this using SceneManager->getStringParameters()->setParameter( - scene::LMTS_TEXTURE_PATH, "path/to/your/textures"); - -- Irrlicht is now able to load my3D files directly. The My3DTools 3.12 loader by - Zhuck Dimitry was (a bit modified and) integrated into the engine. Lots of thanks - go to him for his work and for giving his permission to do that. Newer versions - of this loader can be found at http://my3dproject.nm.ru. The exporters for this - file format have also been added into the \exporters directory of the SDK. - -- To be able to replace built-in meshloaders with newer external versions without the - need of recompiling the engine, now mesh loaders which are added to the engine using - ISceneManager::addExternalMeshLoader() are prefered over built-in mesh loaders. - Thanks to for his suggestion of this. - -- D3D8 and D3D9 support for dev-cpp has been improved. If you are using Dev-Cpp and - a DirectX-Devpack for recompiling the engine, just add - -DIRR_COMPILE_WITH_DX9_DEV_PACK to your compiler - settings and something like -ld3dx9 -ld3dx8 to the linker settings and - press 'compile'. - -- The SceneManager now contains an interface for storing and exchanging parameters. - ISceneManager::getStringParameters() returns IStringParameters, which can be used for - example by extensions like external mesh loaders to set and read independent parameters. - This is also currently used by the newly built in CMS, LMTS and MY3D loader: It is possible to - set a value 'CSM_TexturePath', 'LMTS_TexturePath' or 'MY3D_TexturePath' to let them know - the path of the textures. - -- IAnimatedMeshSceneNode now has two new methods for being able to have more influcence - on the animation playback: It is now possible to set the playback mode to looped or - non looped with IAnimatedMeshSceneNode::setLoopMode() and it is possible to set - a callback interface which will be called when animation playback has finished - using IAnimatedMeshSceneNode::setAnimationEndCallback(). Thanks to Electron for his - suggestion for this addition. - -- The software renderer has a new triangle renderer specialized on disabled zread and write. - This means that skyboxes are now rendered in the correct order when using the software - renderer. - -- Multitexturing and other extensions in Linux are now turned on by default. There is a new - #define in the file IrrCompileConfig.h for disabling this again: LINUX_OPENGL_USE_EXTENSIONS - -- There is now a EET_USER_EVENT user event type for making it possible to send custom - events through the system. - -- The setTarget()-method of the FPSCameraSceneNode now is finally correctly implemented. - -- Changing parents of scene nodes is now much safer. The parent member of a scene node now is - set to 0 in all cases and should never point to invalid data when rearranging the scene node - tree. In addition, there is now a getParent() method in the ISceneNode class. - -- Debug breakpoints using "_asm int 3" are now only being used when in debug mode and - using Micosoft's compiler. Now more exotic compilers like BorlandC++ will like - Irrlicht better because of this. - -- Updated zlib version to 1.2.2 - -- An implementation of 3D triangle clipping in the software renderer has been started. It - is not 100% ready, but it is a beginning. This means now for version 0.9, that there are - not that much artifact triangles drawn anymore. But this means also that drawing is - a lot faster and that triangles clipped at the border of the screen will disappear - too fast. If anyone wants to finish the drawClippedIndexedTriangleListT() method - in the CSoftwareDriver class, he is welcome :) - -- There is a new parameter in the IVideoDriver::createImageFromData() which causes the - image to be able to own foreign memory. - -- A renderstate setting has been fixed which caused to disable mip maps on wrong geometry - when there was other geometry which had no mip maps. At least this bug doesn't appear - on my hardware any more, I hope this means the problem it is now fixed. - -- A bug in the D3D version of the stencil shadows has been fixed thanks to Murphy. Sometimes - you could see a small shadow similar to the the real shadow in the scene. This should now - be fixed. - -- Irrlicht can now draw non filled concyclic reqular 2d polyons like triangles, tetragons, - pentagons, hexagons, heptagons, octagons, enneagons, decagons, hendecagons, dodecagon and - triskaidecagons. And circles. Yes, I was a little bit bored. Christian Lins made a - suggestion to add 2D circle drawing support to Irrlicht, and I did this, but also added - support for drawing these figures using the same method. Check out - IVideoDriver::draw2DPolygon(). - -- Removed a memory leak when creating hlsl pixel shaders. - -- I've made varoius updates to the documentation and moved to doxygen 1.4 - -- Fixed a bug in the xml reader which caused it to crash when reading empty xml files. - -- Removed the buggy bsp tree scene node from the engine. - -- Tweaked some settings with some GUI elements. - -- ISceneNode::getAbsolutePosition now should be way faster. - -- Applied a fix by William Finlayson to the opengl stencil shadow drawing code which - fixes several bugs. - -- There is now a min_ and max_ template function available in the core namespace. - -- Added some bugfixes to MayaCameraSceneNode by jox. An even more improved version can - be found at http://development.mindfloaters.de/Downloads.12.0.html. - -- core::array now has a push_front method. - -- core::array now has an insert method. (Thanks to jox) - -- IrrlichtDevice now has a getEventReceiver() method. - -- Fixed a mouse wheel - mouse coordinates bug thanks to a bug report and fix by jox. - -- Changed the first parameter in IGUIContextMenu::addItem(wchar_t* text, ...) to const. - Thanks to jox.. again. :) - -- Fixed ignore path bug in zip file reader thanks to Pr3t3nd3r. It is now possible - to use zip files with the complete path to the files from the archive. - -- Fixed matrix4::rotateVect method after a suggestion by several users. (I think Electron, - Pr3t3nd3r, Jox) Thanks all :) - -- Fixed a bug in CGUIEditbox that enables you to write more characters than the max set - limit, thanks to Rush for the bug report and fix. - -- Added getAngleTrig() method to vector2d as suggested by Pr3t3nd3r, thanks! - -- After a suggestion by schick, plane3d now stores the normal vector first, and then - the distance to the origin. - -- A bug was fixed which caused 2D elements to be drawn with a second texture set in OpenGL - mode when 3D geometry with >1 textures has been rendered before. This effect has often - been reported as darkened 2D gui in the forum. - -- A bug in IrrCompileConfig prevented users to be able to recompile irrlicht with D3D9 - with gcc. This is now fixed, thanks to Jedive. - -- The project setup for Dev-C++ is now nicer. Added lots of folders and cleaned up the - whole setup a little bit with this. - -- Fixed a small bug in CGUIScrollbar reported by Klaus Niederkrueger. - -- The Checkbox rect is now clipped correctly, thanks to jox for that bug report. - -- The debug names of all scene nodes and GUI elements are now set correctly. - -- Applied a patch making it possible to compile Irrlicht without OpenGL in Linux. - -- core::rect::clipAgainst was fixed thanks to a bug report and correction by Jox. - -------------------------------------------------------------------------------------- -Changes in version 0.8 (19 Feb 2005) - -- Irrlicht now supports HLSL. This is possible using the new - IGPUProgrammingServices::addHighLevelShaderMaterial() methods. Also, methods for setting high - level shader constants have been added. - -- Irrlicht.NET now supports events and cursor control. This means now you can read mouse - and keyboard input from .NET projects like C# and VB.net too. - -- There are three new built in materials for doing normal/bump mapping available: - EMT_NORMAL_MAP_SOLID, EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR and - EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA. If the hardware does not - support these, the materials will fall back to their base materials. To be able to - use these materials, there is the new vertex type 'S3DVertexTangents', the material - does not work with any other vertex types. There are some new methods to create meshes - with this vertex type (IMeshManipulator::createMeshWithTangents()). - -- A new example/tutorial (11.PerPixelLighting) shows how to use per pixel lighting - in your applications. - -- The software renderer now works in Linux, too. - -- Irrlicht now has a built-in normal map generator. It creates on the fly 32 and 16 bit - normal maps from height maps (IVideoDriver::makeNormalMapTexture). As most other things - in Irrlicht, the generator does not depend on D3D, D3DX or OpenGL. - -- Added shader debugging capabilities to Irrlicht. If _IRR_D3D_SHADER_DEBUGGING is - defined in IrrCompileConfig.h (commented out by default), it is now possible to - debug all D3D9 shaders in VisualStudio. All shaders (which have been generated in memory - or read from archives for example) will be emitted into a temporary file for this purpose. - To debug your shaders, choose Debug->Direct3D->StartWithDirect3DDebugging in Visual Studio, - and for every shader a file named 'irr_dbg_shader_%%.vsh' or 'irr_dbg_shader_%%.psh' - will be created. Drag'n'drop the file you want to debug into visual studio. That's it. - You can now set breakpoints and watch registers etc. This works both with ASM, HLSL, - pixel and vertex shaders. - Note that the engine will run in D3D REF for this, which is a lot slower than HAL. - -- Support for compressed .tga texture loading added. (Support from 0.4.1 was buggy) - Thanks to neojzs for posting his improvement. - -- Support for 32 bit .bmp texture loading added. - -- Global particles are now possible. Use IParticleSystem::setParticlesAreGlobal() - to switch between global and local particles. A demonstration of this can be seen in the - new tutorial (11.SpecialFX2). - -- It is now possible to let IGUIImages draw themselves using the alpha channel of the texture - they show. Use IGUIImage::setUseAlphaChannel() for this. - -- ITexture now has a method for rebuilding the mip map levels: regenerateMipMapLevels(). - This is useful for example after locking and modifying the texture. - -- Gravity acceleration speed in CollisionResponseAnimator was changed thanks to a suggestion - by Morrog. The accelerationPerSecond value has been removed beacause of this, you - can now control everything just with the gravity vector. Note that the gravity value - must now be a little bit smaller to achieve the same effect as before. - -- Fixed a problem with several material renderers which weren't able to update their states - at the right time sometimes. A new method OnRender() will be called every time the - material is actually used. - -- Adjusted all tutorials to fit some interface changes. - -- Changed the opengl shader of tutorial 10 to fit the d3d shaders. The now look the same. - -- The MeshManipulator has a new method createMeshWithTangents() which creates a mesh - with normals, tangents and binormals from any mesh. - -- Wrong 2D alpha channel renderstates have been set when using D3D9 and 8. This has been fixed now. - -- When loading 32 bit images with an alpha channel and storing them internally as 16 bit, the - alpha channel got lost. This is now fixed, the remaining one bit alpha channel is now - stored correctly. - -- There is a new overloaded IGUIEnvironment::addImage method, which creates an image directly with - a texture as parameter, adjusting its size to the original size of the texture. - -- A small bug in rect::isValid() has been fixed, thanks to jox. - -- Fixed a bug in D3D8, D3D9 and OpenGL, which caused Materials be set and unset with an unequal - amount when mixing 3d with 2d grafics or stencil buffer shadows. - -- If you are recompiling the whole engine with Visual Studio 6 (which means - Irrlicht.dll, NOT the application which is using Irrlicht), DirectX9 support is disabled - now by default, because Microsoft stopped support for DX9 on VS6 in December - 2004. You can reenable this by uncommenting the new define at the bottom of - IrrCompileConfig.h, if you have an old SDK for example. - -- The mixed fvf and vertex shader system in D3D8 caused a slight issue in Irrlicht ending up - in really messed up render states sometimes. This is now fixed. - -- A major bug with the OpenGL renderer which occurred on some OpenGL implementations - has been removed thanks to a bugfix by Murphy and a great report and some investigations - by ElectroDruid. - -- Sorting transparent scene nodes was broken in all previous versions of Irrlicht. This - didn't attract a lot attention because most users used the ADD_COLOR transparencies for which - the sorting is not relevant. Thanks to Morrog and mmm76, sorting now is right. -- After the application window is resized, getViewport() no longer returns viewport as the - first time the window has been created. - -- The draw primitive functions are no longer wrongly checking the maximum primitive count with - the vertex amount value. Thanks to Spintz for the bug report. - -- Template materials in X files just like exported in the panda exporter are now - supported, thanks to JoeWright. - -- Changed the stringc typedef slightly to make it work with people not using - namespace irr. Thanks to schick. - -- Refactored the MeshManipulator code, which in some cases now uses template methods for performing - calculations on different vertex types. - -- Fixed an interface problem with newer versions of libJPEG. - Thanks to Fabien Coutant and Simon Barner for some help and clues into the right direction. - Was not able to add system specific zlib/jpeglib support due to issues on - some strange systems/users and a lack of time, sorry. - -- Typo in plane3d and triangle3d: method isFrontFacting renamed to isFrontFacing. - -------------------------------------------------------------------------------------- -Changes in version 0.7.1: (26 Sep 2004) - -- Fixed some bugs which prevented the engine to compile with gcc 3.4.1. - -- Fixed a problem with the OpenGL driver, which caused the renderstates not to be reset correctly - when drawing scene nodes with reflective materials. - -- Fixed error in Irrlicht's software mip map generation, which caused that some mipmap levels - looked strange. This fix was found by jox, the hardcore bug fixer, - so many thanks go to him. Again. :) - -- Disabled hardware mip map generation in D3D9 again, because it seems to cause problems on - some hardware. I don't have any hardware where this problem occurs, but I hope this helps. - -- Fixed a small bug in fast_atof submitted in the forum by da_dude. - -- Fixed string operator + after a bug report by osre and a fix suggestion by jox. - -- IEventReceiver now has a virtual destructor for the people who needed it. - -- 3DS-Loader patched due to some suggestions of Daniel Azkona Coya. - -------------------------------------------------------------------------------------- -Changes in version 0.7: (11 Sep 2004) - -- The first version of Irrlicht.NET is included in this release. It is a managed C++ - wrapper .DLL which makes the most important features of the engine available for all - .NET languages. The wrapper is incomplete, but it can already be used. - You can find the documentation for this .DLL in the compiled help file doc\IrrlichtNET.chm. - There are also two very basic examples available, which show how to use Irrlicht.NET - from C# and VisualBasic. - -- Low level vertex and pixel shader programming is now possible. There are - now some methods with which you can write GPU programs in vertex/pixel shader assembler - using Direct3D 8 and 9 and in ARB vertex and fragment program assembler for OpenGL. - You can use the IGPUProgrammingServices interface which can be reached by - IVideoDriver->getGPUProgrammingServices() for this. The new material types you can create - with this can be combined with all other already existing material types. - For example, it is possible to create a new material which uses a vertex shader to - calculate texture coordinates and diffuse colors, and let this be rendered by the built in - material video::EMT_TRANSPARENT_ADD_COLOR. - Support for high level programming languages like GLSL or HLSL is planned for the - following releases. Also note that you won't be able to use all techniques shaders offer with - Irrlicht, due to its current high level abstraction of the 3D APIs. For example, the engine - does not expose vertex streams or vertex buffers currently. - -- There is a new tutorial showing how to use shaders with the engine. In addition, all - old tutorials have been rewritten and adapted. For example, the hello world - tutorial now also shows how to set up visual studio .NET to use it with - the engine. - -- Hardware mip map level generation of textures is now supported when using D3D9. - -- Internal pointers and data of the video drivers can now be exposed for experienced users with - VideoDriver::getExposedVideoData(). For example, you can get a pointer to the IDirect3DDevice9 - interface and the HWND window handle, if the engine is running with D3D9. - -- The createDevice() function has a new additional parameter: bool vsync. With this, it is now - possible to enable or disable the waiting for the vertical retrace period. This is implemented - in D3D9, D3D8, and the Windows OpenGL driver only, the software driver will ignore this flag. - -- The engine now behaves like in the documentation: irr::createDevice() returns 0, if - the desired driver could not be initialized. - -- There is a new SceneNode available: The ITextSceneNode is able to display 2D text at a - position in 3D space. Use ISceneManager::addTextSceneNode() to create one. - -- Finally now all VideoDrivers have a draw2DLine() implementation, thanks to some additions sent in - by Vash TheStampede. - -- Applied some changes to the compilation configuration, so that it should now - be easier to use the engine with XBOX projects. Thanks to MattyBoy for sending - in some clues for this. - -- Some improvements for the linux version of the engine: The NULL device is finally fully operational with Linux - too, and also all examples and even the techdemo compile and run with this OS. - -- The default field of view in the cameras of the irrlicht engine was a little bit - extreme, so I changed it now from core::PI / 3.5f to core::PI / 2.5f. - -- Added a new draw2DImage method for partially draw a 2d Texture, as sent in by zola with - implementations for OpenGL, D3D8 and D3D9. Software implementation is missing. - -- The string class is now able to convert integer values into a string or append it as string - to itself. - -- Added a getDriverType() method to the IVideoDriver interface. - -- Added a getTransform() method to the IVideoDriver interface. - -- The EMT_TRANSPARENT_ALPHA_CHANNEL material in OpenGL is now implemented. - -- The integrated XML Parser now works better with different text file formats. (ASCII, UFT-16,..) - -- IGUIEdit Box now feels more like a windows editbox, thanks to some changes by Jox - -- Added a new method to IVideoDriver: createImageFromData as suggested by Oliver Klems. - -- Fixed a the EMT_TRANSPARENT_ALPHA_CHANNEL problem in D3D8 and D3D9 due to a suggestion by Jox. - -- Added 3 methods created by zola to the quaternion class: fromAngleAxis(), toEuler() and - operator*(vector3df&). - -- A bug in a matrix multiplication operator was fixed. - -- Changed visual studio project files to version 7.1, but provided 7.0 project files - for people with that version. - -- Added SceneNodeAnimatorRotation rotation fix as posted by warui - -- Added normalization fix to vector2d and 3d. Warui suggested a fix like that in the forum. - The one I made has the same result, but is a little bit faster. - -- Fixed some problems with the drawStencilShadow() method in the OpenGL implementation of the - IVideoDriver interface after some suggestions by Nicholas Bray. - -- Added IGUIButton::setPressed() and isPressed(). - -- Fixed checkPrimitiveCount() bug in NullDevice. - -- Applied jox's matrix4::getRotationDegrees() fix, many thanks for posting this! - -- Changed aabbox3d::getExtend() to getExtent(). - -- Changed IXMLReader::isEmtpyElement() to isEmptyElement() - -- Fixed a bug in CSceneManager::getSceneNodeFromId() which caused the engine to crash sometimes. - -- Fixed a bug in CGUISkin::setSize reported by REAPER. This method never worked before. - -- Improved texture mapping and normals of the TestSceneNode, thanks go again to Jox. - -- ScrollBar is now posting mousewheel events, thanks go to REAPER to post this bug and a fix for it. - -- Added - operator to vector2d and vector3d, thanks to calimero - -- Fixed a bug in vector2d::getAngle() and vector2d::rotateBy() thanks to Jox. - -- Fixed a bug in quaternion::set(f32 x, f32 y, f32 z) thanks again to Jox. - -- Fixed a bug in list::insert_before and list::insert_after, reported by Haddock. - -- Fixed a bug in XML Parser which caused a seqfault on linux. Thanks for G.o.D reporting this problem. - -- EDriverType enumeration renamed to E_DRIVER_TYPE - -- SceneNodeRenderTime enumeration renamed to E_SCENE_NODE_RENDER_PASS - -------------------------------------------------------------------------------------- -Changes in version 0.6: (09 Mar 2004) - -- Irrlicht now includes its own XML parser. It provides forward-only, read-only - access to a stream of non validated XML data. It can read everywhere Irrlicht can, - also in compressed .zip-Files for example. Use IFileSystem::createXMLReader() to - use it. - -- Like the new XMLReader, there is also a IXMLWriter available for making it easier - to write xml files. - -- There is a new tutorial available in the SDK. It is for more advanced users, and - shows how to create a 3d model viewer with the engine easily. It shows how to - use menus, tabcontrols, edit-, message- and sky boxes. - The resulting program can also be used as tool, to check if the engine - loads exported 3d models correctly. - -- Again, there are some new GUI widgets available: A ComboBox, a ToolBar, a PushButton - and an ImageButton. The last two are simply the old IGUIButton, but it is now able - to display additional images and behave like a PushButton. - -- It is now possible to make the drawing window resizeable, if it is in windowed mode. - Use IVideoDriver::setResizeAble(true) to do this. - -- The .x file reader and animation player now should work with 99% of all text .x files. - This is achieved by most of the following bug fixes. - -- Fixed a huge bug in the .x file reader, which caused that negative coordinates were - interpreted as positive ones sometimes. This caused that sometimes .x animations - were played wrong. - -- Slerp interpolation of the quaternion class fixed. This means that also some bugs - in the animation of .x files are removed now. - -- Added virtual joints to not weighted vertices to improve .x file animations. - -- The FileSystem is now 100% implemented. Finally it is now possible to write files - too. There is a new Class IWriteFile and the corresponding - IFileSystem::createAndWriteFile() - -- Added lots of text and sample code to the documentation. In most parts - documentation should be clearer now. - -- The ISceneManager has a clear() method, which clears the whole scene, all scene nodes - are removed. - -- All ISceneNodes now own a new method called removeAll(), which deletes all children - of the node. - -- Fixed a bug which prevented the possibility to compile directx8 without - having installed directx9. - -- Fixed a bug in 3d line dawing in D3D 8 and 9. - -- All video drivers now print out the gfx adapter type, vendor and driver version - into the log strings. - -- The D3D9 device is now as fast as the D3D8 device. - -- The string class has an additional new constructor for creating a string from - character data with a specific length. - -- Bug fixed in string class assignment operator which might cause a crash in very - special circumstances. - -- Added a findNext() method to the string class. - -- The ISceneNode class now has a isDebugDataVisible() method. - -- Some lines were changed to make the source of the engine compatible to VS.NET 2003. - -- Some functionality of the IFileList and IFileSystem was missing in the Linux version - of the engine. This caused the FileOpen-Dialog not to work. I fixed this problem. - -- The Middle and Right mouse button were swapped in the Linux version. This is now - fixed. - -- Multitexturing should now work with most linux systems too, thanks to a bug - report by Martin Piskernig. - -- The logger now has an additional log() method which accepts another combination - of strings. - -- Fixed a bug which caused fonts to be displayed very transparent in OpenGL. - -- Removed one of the redundant overloaded IGUIEnvironment::updateAbsolutePosition() - methods. - -- Fixed lots of clipping problems in all GUI Widgets. - -- core::rect has the new methods getCenter() and isValid(). - -- Scrollbar buttons are now disabled if it is not possible to scroll. - -------------------------------------------------------------------------------------- -Changes in version 0.5: (17 Feb 2004) - -------------------------------------- -/ Highlights in short: -/ * DirectX 9 support -/ * .x file support in all render devices including opengl and software -/ * new materials like lightmaps with dynamic lighting -/ * fog -/ * stencil buffer shadows now also work in OpenGL device -/ * more gui widgets: tab controls, edit boxes, menus -/ * spline animation support -/ * mouse wheel support -/ * triangle fan drawing -/ * quaternions -/ * improved keyboard input control -/ * lots of bugfixes including improved quake 3 map support -------------------------------------- - -- DirectX 9 is now supported by Irrlicht. This does not mean that it replaces - DirectX 8. The engine now supports both. You can now select between OpenGL, - DirectX8, DirectX9, Software and the Null device. - -- The engine now is able to read and display .x files. Using - Microsoft's excellent .x file exporter for Maya or MAX which comes - with the DX8 and DX9 SDK, it is now possible to create content for - the engine easily. Using .X files with Irrlicht is independent of D3D, - they can be used with OpenGL and with Linux for example too. - Currently only text file .x files are supported, and some animated .x - files may be displayed not 100% correctly, because the animation player - may still have some small bugs. It works perfectly with most .x files which - come with the DX9-SDK. Some skinned mesh .x files which use - quaternions for animating joints have some problems, there might be a - bug somewhere. I commented the lines with a possible bug in CXAnimationPlayer.cpp. - -- The GUI Environment now supports edit boxes. They should support unicode input - from every keyboard around the world, scrolling, copying and pasting (exchanging - data with the clipboard directly), maximum character amount, marking and all - shortcuts like ctrl+X, ctrl+V, ctrg+C, shift+Left, shift+Right, Home, End, - and so on. Wow, I never programmed an edit box, its much more work than it - seems to be. - -- Tabcontrols are now available in the GUI environment. It is also - possible to create tabs without tabcontrols, to be able to create - invisible gui elements for grouping other elements together. - -- Another new supported GUI Element are context menus. They support - ordinary text menu items, separators and sub menus. In Addition, - a standard menu as seen at the top of most windows can be - created easily with them. - -- Rewrote all tutorials to fit the new API. - -- Spline animations are now supported thanks to a spline scene node animator - written by Matthias Gall. - -- Taskswitching now works with Direct3D 8 and 9 devices in fullscreen mode. - -- Added Material types EMT_LIGHTMAP_LIGHTING, EMT_LIGHTMAP_LIGHTING_M2, - EMT_LIGHTMAP_LIGHTING_M4 and EMT_LIGHTMAP_ADD. - -- The engine now supports drawing of trianglefans. To do this, use - IVideoDriver::drawIndexedTriangleFan(). Mario Gruber sent in code for this, - so lots of thanks go to him! - -- It is now possible to draw 3d objects with fog. Simply switch on the fog flag - in the objects material. To change to way fog is drawn (per pixel/vertex, color, - linear/expontential) use IVideoDriver::setFog(); - -- With IrrlichtDevice::getOSOperator() a pointer to an interface is returned, with - which it is possible to do some operation system specific operations. Currently - there are only 3 methods supported, but more will be added in the future. - -- Mouse wheel input is now supported. - -- The Key Event structure of SEvent now contains a Char entry, describing the - corresponding character of the pressed key. Also two bools were added, - specifying if shift or ctrl was pressed too. - -- The version of the Operating System is now printed out into the log at - startup. - -- There is now a non-const getBoundingBox() method in IMeshBuffer and - IMesh available. - -- IGUIElement now has a method getElementFromId(), which searches children - (and its children if wanted) for an element with a specific id. If you - want to search all items, just do - IGUIEnvironment::getRootGUIElement::getElementFromId(). - -- ISceneNode::updateAbsolutePosition() is now public - -- Small bug fixed in CMeshManipulator::scaleMesh(). - -- The engine now supports Quaternions. - -- A bug was fixed causing the windows caption not to be displayed in - Windows 95/98/ME. - -- IGUIEnvironment::getBuildInFont() was renamed to getBuiltInFont(). - -- IGUIElement::bringToFront() is able to brint a child to the front. - Windows for example are now using this new feature. - -- Changed the texture mapping of the test scene node a little bit based on - code sent in by Dr Andros C Bragianos. - -- Added code to fix some bug in some ATI drivers. Thanks to ariaci for posting - this code. - -- Stencil buffer shadows now also work with the OpenGL device, they worked only - in D3D in earlier versions. Lots of thanks go to Philipp Dortmann, who - sent in a modification to the opengl driver! - -- IGUIStaticText::setWordWarp() renamed to setWordWrap(), - IGUIStaticText::enableOverrrideColor() renamed to enableOverrideColor() - [thanks to saigumi] - -- A bug was fixed, causing that the window was not able to be closed with Alt+F4 - in Win95/98. - -- Optimized the Octree-Scene node a little bit for getting more rendering speed. - Culling is now done with the real frustum, not the bounding box around it. - Speed increase is about 5%, it's not much but ok. - -- Bug fixed in the Quake 3 .bsp file loader, which caused holes to appear in - some maps. - -- Combination of 3D displaying and drawing GUI elements was improved, and the - priority of input receiving of 3d cameras and gui elements swapped. - -- A bug in the static text was fixed, which caused it to draw itself outside - of its clipping rectangle. - -- KeyFocus and MouseFocus methods in GUIEnvironment are now merged into one method. - -- The Clamptexturecoordinates flag in the material was removed. - -- IVideoDriver::draw3DLine in all devices was improved. - -- The devcpp-version of the binary DLL which comes with the SDK is now faster. - I'll compile this version from now on always with optimization switched on. - -- Other, Minor New/Changed methods in public interfaces: - * buildShadowMatrix in matrix4 - * getRotationDegrees in matrix4 (sent in by Chev) - * rotateVect in matrix4 - * linear_search in array - * recalculateBoundingBox in MeshManipulator - * ISceneManager::addStaticText() now has a parameter for word wrapping - * getCharacterFromPos() in IGUIFont - * drawMeshBuffer() in IVideoDriver; - * interpolate() in matrix4 - * getLast in array - -------------------------------------------------------------------------------------- -Changes in version 0.4.2: (13 Dec 2003) - -- The engine does no more use only 16 bit textures internaly. Now all - other texture formats are supported too. This means higher precision - and better quality images. In this context, the ISurface interface has - been replaced by IImage, and the ISurfaceLoader by IImageLoader. - -- By changing the texture creation mode of the IVideoDriver, it is now - possible to influence how textures are created: You can choose between - 'optimized for speed', 'optimized for quality' or simply set constant - bit depth like 'always 32 bit'. Also, you can now enable and disable - Mip map generation with these flags. Take a look at - IVideoDriver::setTextureCreationFlag() for details. - -- There is now some support for outdoor or terrain rendering available. - You can create a static mesh from a heightmap and a texture using - ISceneManager::addTerrainMesh(). You can specify a huge texture if you - like, even bigger as your hardware allows to render, because the texture - will be splitted up if necessary. - Another possibility for doing terrain rendering is the new Terrain Scene - node. But it is only in a very early alpha stage, I disabled for example - the use of different level of details. - -- It is now possible to load software images into memory from files on - disk, without creating a hardware texture. You can do this by calling - IVideoDriver::createImageFromFile(). This is very useful for example - for loading heighmaps for terrain renderers. - -- The Quake 3 Map Loader now supports curved surfaces, thanks to by Dean P. Macri - who sent in his code. (He also sent in lots of other cool stuff, which I will merge - with the code of next releases, lots of thanks to him!) - -- It is now possible to control what text is printed out to the console and - the debug window of Visual Studio. By getting a pointer to the ILogger - interface, is is possible to adjust if Warning, Error or Informational - texts should be printed out. In addition, now every text can be caught - by the event receiver. - -- The engine is now capable of loading .PCX files. Only a few PCX formats - are supported currently, but at least the common used formats - of most textures of the quake 2 models. Thanks go to Dean P. Macri who - sent in the code for the new PCXLoader! - -- A new Scene node is available, which simply does nothing. It is useful for doing - advanced transformations or for structuring the scene graph. - -- The ISceneManager::addOctTreeSceneNode() now takes AnimatedMeshes as parameter. - If this new method is called, the first frame in the animated mesh is taken as - mesh to construct the octree. This means that you won't have to write - addOctTreeSceneNode(yourMesh->getMesh(0)) anymore, but can use - addOctTreeSceneNode(yourMesh), which is a little bit more intuitive. - -- The Driver type enumeration have been adapted to the Irrlicht - naming conventions. For example instead of writing DT_OPENGL, now write - EDT_OPENGL. - -- The ITexture interface has two new methods for getting the size of the - texture: ITexture::getSize() and ITexture::getOriginalSize(). This replaces - the old getDimension()-method and allows to disable bugs which are generated - by the automatic scaling to optimal sizes of textures. - -- There are some new keycodes available: KEY_COMMA, KEY_PLUS, KEY_MINUS, KEY_PERIOD. - -- There are now 3 lightmap Material types: EMT_LIGHTMAP, EMT_LIGHTMAP_M2 and - EMT_LIGHTMAP_M4, which are making the lightmaps 2 or 4 times brighter. If you used - the Material EMT_LIGHTMAP in your code, you should replace it now with - EMT_LIGHTMAP_M4. - -- The transformation enumeration names have been adapted to the irrlicht - naming conventions. For example instead of writing TS_VIEW, now write - ETS_VIEW. - -- Video driver feature enumeration names have been changed from - EK3DVDF_... to EVDF_... - -- The GUIEnvironment now has a new method: getRootGUIElement(). With this it - is possible now to add external created custom GUI Elements to the gui environment, - without an existing internal GUI element as parent. - -- The setViewPort()-Method of the OpenGL-device now works, too. Nothing stands now - in the way of creating splitscreen applications using the OpenGL device. - Oliver Klems sent code for this, I slightly modified it. Thank you! - -- Corrected a bug, which made the EMT_REFLECTION_2_LAYER Material disappear on some - hardware. - -- Sirshane sent in a bug fix: It is now possible to make the mouse cursor - invisible in the Linux version of the engine. Thanx sirshane! - -- getFrameNr() of IAnimatedMeshSceneNode is now public. - -- Again a small bug in the 3ds file loader was fixed. - -- A small bug causing light positions being transformed in the OpenGL - driver differently compared to D3D. Thanx to Matthias Gall for reporting - this! - -- Typing error fixed: ISceneCollisionMananger::getRayFromScreenCoordiantes renamed to - getRayFromScreenCoordinates. - -- Linux support with multitexturing and mipmap generation has been improved. - -- A bug was fixed which caused the Engine not to run when compiled - as dynamic library under linux. Thanks to Shane Parker who pointed out - the problem. - -- A bug was fixed in position2d.h in the operator +=, and the list iterator now - has per and postfix operators. Thanks to Isometric God for spotting this out. - -- A bug was fixed in the Metatriangleselector, causing it to detect only collisions - with the last TriangleSelector in it. - -------------------------------------------------------------------------------------- -Changes in version 0.4.1: (18 Sep 2003) - - -- Input events are now processed faster than repaint and window events. This - means that input commands now effect things directly, in earlier versions - there could be a delay when there were low frames per second. Some people - noticed this when moving with the fps camera in large levels: The camera - sometimes stopped seconds after the button was released. This is now fixed. - -- A Message Box is now available in the GUI Environment. It looks like the - windows message boxes and supports OK, Cancel, Yes and No buttons, which - can be combined freely. Also, it shows multiline text and adjusts its size - based on the amount of text it shows, so it should be very useful for displaying - (debug) messages during runtime. - -- It is now possible to make all windows (message boxes, file open dialogs, - simple windows) modal. - -- IGUIStaticText now supports multiline text via automatic word warp and manual - line breaking with '\n'. You only need to switch it on with - yourText->setWordWrap(true); - -- Non default MD2 animations are now supported. Which means simply that you can - enumerate the names of all md2 animations and the AnimatedMeshSceneNode now supports - a setMD2Animation() with a character string as parameter instead of a constant. - -- You do not need an event receiver anymore for sending user events to the active - camera, this is now done autmaticly. In addition, it is now possible to - set a new event receiver during runtime of the engine using IrrlichtDevice:: - setEventReceiver(). - -- It is now possible to disable and enable the input receiver of a camera. This - is useful for example for removing the users control of the camera. To do this, - call camera->setInputReceiverEnabled(false); - -- The first person shooter camera now supports a keymap: You can define your own - key mapping to control the camera when you create it with ISceneManager:: - addCameraSceneNodeFPS(). - -- Thanks to Jon Pry, the engine now also loads compressed TGA texture files. Now only - 8 bit palette using TGAs are missing. :) - -- There are methods for converting 3d coordinates in 2d coordinates and the other - way round. You can find them as two new methods of the ISceneCollisionManager: - getRayFromScreenCoordiantes() and getScreenCoordinatesFrom3DPosition(). - -- There are now access methods in IGUIWindow for getting pointers to the - maximize, minimize and close buttons, to be able to remove them for - example. - -- Before starting up the engine, a version check now is performed and a warning is - written, if Irrlicht.DLL version and header version of your application do - not match. - -- A bug with the skybox has been fixed: In OpenGL, it was possible to see the - borders of the skybox. In addition, when a skybox was visible, there were - errors in the texture coordinates of other meshes. This is all fixed now. - -- A bug has been fixed causing the engine to crash when removing gui childs - which where created inside the .dll but are removed from outside. - -- A bug was fixed causing the engine to crash when drawing debug data of - octtree scene nodes with geometry data with vertices with one texture - coordiante. - -- Multitexturing now works with linux, too. Thanx to Jon Pry again, for showing - me where the problem was. - -- The bug (reported by saigumi) preventing scene nodes attached to a camera - from moving correctly is now fixed. - -- The "Climb-Walls" bug (reported first by Matthias Gall) is fixed. Gravity - acceleration is now quadratic instead of linear. - -- A warning is now printed out, if more vertices are rendererd with one call - than the hardware supports. - -- Other, Minor New/Changed methods in public interfaces: - * get and setText() in IGUISkin - * += operators are now available in the string class. - * setRelativePosition() in IGUIElement - * enumeration EKEY_CODES renamed to EKEY_CODE - * getMaximalPrimitiveCount() in IVideoDriver - * getAnimationCount() in IAnimatedMeshMD2 - * getAnimationName() in IAnimatedMeshMD2 - -------------------------------------------------------------------------------------- -Changes in version 0.4: (04 Sep 2003) - -- Collision detection and reponse based on ellipsoids in now implemented. - There is a new method available in the ISceneCollisionMananger, which returns - a collision response point. In addition, a new SceneNodeAnimator is available, - which causes a scene node, to which it is attached to, not to move through - walls, to climb stairs and to be affected by gravity. This scene node animator - can be attached to any scene node. For example adding it to the FPSCamera, it makes - the user possible to walk through the 3d world as in first person shooters. - -- There is now a full featured Particle System included in the engine for - creating fire, explosions, snow, smoke and so on. - It is customizeable and extensible. There is a ParticleSystemScene node - available in the SceneManager and some standard particle emitters and - affectors are already implemented. - -- Realistic water: The engine now features an IWaterSurfaceScene node, which - animates a static mesh with water waves. In combination with the new - EMT_REFLECTION or EMT_TRANSPARENT_REFLECTION material type, you can easily - create realistic animated water surfaces. - -- Triangle base picking is now possible using the ISceneCollisionMananager. - If a collision happened, the intersection point and the triangle causing - the intersection is returned. - -- Stencil shadows are now drawn using the ZFail method by default, but it is - possible to choose ZPass, if wished. This means that the camera may now move - inside the shadow volumes and no errors will occur. In addition a stencil - shadow bug is now fixed: In 0.3 there where no shadows visible in the TechDemo. - -- The interface of ISceneNode has changed: There is no more a RelativeTransformation - and AnimatedRelativeTransformation matrix. They have been replaced by 3 vectors: - RelativeTranslation, RelativeRotation and RelativeScale, which can be accessed by - the corresponing get() and set() methods. This simplifies the interface - a lot. Also, the set/getRelativePosition was renamed to set/getPosition. - -- The new IAnimatedMeshMD2 interface now returns start, begin time and - fps of every MD2 animation type. In this context, IAnimatedMeshSceneNode - got a new method called setMD2Animation(), which accepts a single constant - like EMAT_ATTACK, which starts and plays the fitting animation (attack - animation in this case), simplifying the interface a lot. - -- Some scene nodes can now draw debug data like their bounding boxes. - This feature is switched on for a single node by calling - ISceneNode::setDebugDataVisible(true). Looks really interesting for - animated scene nodes like particle systems or animated meshes. - -- There is now a IGUIInOutFader avaiable, which is able to fade in or - out the whole screen or parts of it. - -- The new IVideoModeList is a list with all available video modes. It can - be retrieved with IrrlichtDevice::getVideoModeList(). If you are confused - now, because you think you have to create an Irrlicht Device with a video - mode before being able to get the video mode list, let me tell you that - there is no need to start up an Irrlicht Device with DT_DIRECTX8, DT_OPENGL or - DT_SOFTWARE: For this (and for lots of other reasons) the null device, - DT_NULL exists. - -- With the new IMeshManipulator interface accessible with - ISceneManager::getMeshManipulator() it is possible to perform some basic - operations on meshes: Flipping all surfaces, recalculating all normals, - scaling the mesh, creating a new texture mapping and so on. - -- A new material for creating water surfaces or glass with reflections on it - is available: EMT_REFLECTION_2_LAYER and EMT_TRANSPARENT_REFLECTION_2_LAYER. - It has uses a reflection map, and an additional optional texture. - The transparency of this material is set by the alpha color value in the vertices. - -- Another new material is EMT_SOLID_2_LAYER. It is a material with 2 textures, - blended together with the alpha value of the vertex color. This material is - currently only available in DirectX. - -- Trilinear Filtering is now supported by the engine. - There is a new option in SMaterial: TrilinearFilter and EMF_TRILINEAR_FILTER. - -- The addChild() method of the IAnimatedMeshSceneNode for adding SceneNodes to - joints of skeletal animated meshes was removed. - Instead there is now a new method: getMS3DJointNode(). This returns a pointer - to a child node, which has the same transformation as the corresponding joint. - In this way it is possible to do more advanced operations with joints and - attaching scene nodes to joints. Also, the IAnimatedMeshMS3D interface now gives - access to all joints. In this way, you can easily enumerate all names of all - joints in the mesh. - -- Font and color of every IGUIStaticText can now be set separately, without - modifying the IGUISkin. - -- There is now a ELEMENT_LEFT gui event, which all hovered elements receive when they - are left. - -- All features of the FileOpenDialog are now working. - -- Debug informations are now printed out to the console window - also on the win32 platform. - -- FPSCamera now supports setTarget(). Its not precise but working. - -- Textures of 3ds files are now loaded from the same directory in which the - 3ds file is. If the texture is not found there, the texture is tried to be - loaded from the current working directory. - -- A small bug in the 3ds file loader has been fixed. There were 3ds files exported - by anim8or, where the reading of the 3ds file never stopped. - -- It is now possible to configure the minimal amount of polygons contained - in every node in an OctTree via addOctTreeSceneNode(). - -- There is a new template class in the core namespace: triangle3d. With this, - it is easy to find intersections between lines and triangles, find out if - a point is within a triangle and so on. - -- A small bug in ISceneManager::addHillPlaneMesh() was fixed: Now the right tile - amount is created. - -- There is a new SceneNode available: IDummyTransformationSceneNode. It exists - for making it possible to insert matrix transformations anywhere into the - scene graph. - -- Added a new SceneNode animator for deleting Scene nodes automatically after some - time. Create it with ISceneManager::createDeleteAnimator(). - -- The techdemo now is interactive. After a short non-interactive flight over - the quake 3 level, you are placed as player inside the level, may move around, - shoot fire balls and take a look at some animated characters which are placed - on the map. - -- I fixed a bug which caused the screen get black when choosing shadows and fullscreen - on some special 3d adapters. - -- I fixed some bugs in the linux port: The timer returned an incorrect time, causing - wrong animations everywhere and the releasing of keys and mouse buttons was not - sent as event. In addition, I placed a copy of the zlib.a and jpeglib.a into the - /lib/Linux directory and changed the Makefiles of the examples and the source - of the engine for doing this automatically in the future, so I hope there will be no - problems with other versions of zlib and jpeglib anymore. - -- There are 2 new tutorials: One showing how to do collision detection and - for special effects. - -- Other, Minor New/Changed methods in public interfaces: - * getVersion() in IrrlichtDevice - * getLengthSQ() in vector3d - * getInterpolated() in vector3d - * getInterpolated() in SColor - * getAngle() in vector2d - * getAngleWith() in vector2d - * getPrimitiveCountDrawed() in IVideoDriver renamed to getPrimitiveCountDrawn() - * getSceneNodeFromSceenCoordinates() renamed to getSceneNodeFromScreenCoordinates() - * getMeshType() in IAnimatedMesh - * getInterpolated() in aabbox - * setMD2Animation() in IAnimatedMeshSceneNode - * getFullFileName() in IFileList - * addShadowVolumeSceneNode() in IAnimatedMeshSceneNode extended with zfail parameter - * drawStencilShadowVolume() in IVideoDriver extended with zfail parameter - * getDistanceFromSQ() in vector3d - * subString() in string - * findFirst() in string - * findLast() in string - * getTriangleSelector() in ISceneNode - * setTriangleSelector() in ISceneNode - * draw3DTriangle() in IVideoDriver - * setShadowColor() in ISceneManager - * getShadowColor() in ISceneManager - * addToDeletionQueue() in ISceneManager - * getSceneNodeFromId() in ISceneManager - -------------------------------------------------------------------------------------- -Changes in version 0.3: (18 Jul 2003) - -- Linux port: The Irrlicht Engine now compiles and runs on Linux. Currently only - the OpenGL driver is available. The Software driver would be there too, if - somebody could tell me a fast way to blit a A1R5G5B5 surface to the screen - using X. - All examples do compile and run, but there are some things missing: - * It is not yet possible to make the mouse cursor invisibe. - * The timer seems not to return the currect time. - * Multitexturing does not work correctly on all gfx adapters. - -- Ms3D Animations: The engine is now able to play skeletal animations directy - from Milkshape 3D (.ms3d) files. It is also possible to attach objects to - parts of the animated mesh. For example a weapon to the left hand of - the animated model. - -- Because the swprintf function in Windows32 does not match the ISO C standard, - and it does in linux and all other platforms, there is now a define in Irrlicht.h, - to make the code be the same on all platforms: - #define swprintf _snwprintf - This simply means that you need to add a parameter to your swprintf calls if - you used this function in your win32 irrlicht engine projects. For example instead - of writing - wchar_t tmp[255]; - swprint(tmp, "FPS: %d", fps); - you now write - wchar_t tmp[255]; - swprint(tmp, 255, "FPS: %d", fps); - -- Automatic culling has changed a little bit: It is now done by the SceneManager. - Scene nodes now only need to return a valid, non transformed bounding box to be - culled automatically. It is explained in the CustomSceneNode Tutorial how this works. - -- It is now possible to use the engine easily for 2D graphics: There are now to new - methods in the IVideoDriver, which create an 1bit alpha channel for textures - using an color key. The methods are both named makeColorKeyTexture. There is a - tutorial '2d graphics' which explains how this works. - -- The rect template class was removed and replaced by the rectEx class. There - is now only one rectangle template available, called 'rect' for simplifying - the interface. - -- The texture coordinate bug in Milkshape 3d models with lots of shared vertices - was fixed. - -- Bugfix with GUI environment hovering invisible elements. - -- There are two new tutorials: One for 2d graphics, and one for user interface. - -- Tutorial changes: - * All backslashes replaced by slashes in file names in - all tutorials for linux compatibility. - * RectEx replaces with rect in 1.HelloWorld - * Added second parameter to swprintf in 2.Quake3Map - * Added bounding box creation to 3.CustomSceneNode - * Added second parameter to swprintf in 4.Movement - -- New/Changed methods in public interfaces: - * getClosestPoint in line3d - * getMatrixOfMeshPart in IAnimatedMesh - * removeChild in ISceneNode now returns true or false - * addChild in IAnimatedMeshSceneNode - * setParent in ISceneNode - -------------------------------------------------------------------------------------- -Changes in version 0.2.5: (22 Jun 2003) - -- A new material type is available: EMT_TRANSPARENT_VERTEX_ALPHA, which - realizes transparency based on the vertex alpha color. It currently is - only implemented in the DirectX device. - -- There is now an ISceneCollisionManager available. Get it with - getSceneCollisionManager() from the ISceneManager. It currently only implements - picking, but more is coming soon. - -- Automatic Culling based on Bounding Boxes is implemented now. It can be switched on - or off for every SceneNode seperately using ISceneNode::setAutomaticCulling(). - It is on by default. - -- It is now possible to remove loaded textures for freeing memory or reloading them. - Use IVideoDriver::removeTexture() or removeAllTextures(). - -- New drawing methods in the IVideoDriver interface: - * Draw3dLine(), drawing a 3d line. - * Draw3dBox(), which draws an axis aligned bounding box. - * Draw2dLine(), currently only supported by the Software device. - -- MD2 bugfixes: - * There was a small bug with texture coordinates. - * Frames are now correctly interpolated when playing animations. - -- Bugfix in the 3ds file format loader: Single objects in the 3ds file with multiple - materials attached are now loaded correctly. - -- list.h renamed to irrlist.h due to compatibility issues. - -- Now works with Dev-C++ 5 Beta 8. (4.9.8.0) - -- New/Changed methods in public interfaces: - * 'getInverse' in matrix4. - * 'transformBox' in matrix4. - * 'repair' in aabbox. - * 'intersectsWithLine' in aabbox. - * 'getVector' in line3d. - * 'getMiddle' in line3d. - * 'normalize' method in vector3d and vector2d now returns reference to vector. - * 'getTransformedBoundingBox' in ISceneNode. - * 'getChildren' in ISceneNode - * 'setRotation' in ISceneNode - * 'addHillPlaneMesh' in ISceneManager now accepts a texture repeat count parameter. - - -------------------------------------------------------------------------------------- -Changes in version 0.2: (19 May 2003) - -- The engine is now able to load .3ds files, with their materials and textures. - -- There are some new SceneNodeAnimators: A fly straight animator and a texture animator. - -- Texture coordinates can now be set to clamp or wrap mode with - a flag in the SMaterial struct. - -- Skyboxes are implemented. - -- Billboards now work 100% correctly. - -- The IAnimatedMeshSceneNode is now able to draw shadows of itself. To enable this, just call - addShadowVolumeSceneNode(). Please note that shadows are currently just experimental, - there are some bugs, and they only only in Direct3D mode. - -- A small bug in the view frustum and the octree fixed. - -- The default aspect ratio in all camera scene nodes was changed. - -- Some changes and extenstions to the core::matrix4, SViewFrustum, plane3d and - aabbox were made. The plane3dex was removed, there is now only one plane implementation - available. Implemented some ideas and suggestions by Mark Jeacocke. Thanx a lot! - -- The interface for adding dynamic lights has been enhanced. There are some new methods - for handling dynamic light in the IVideoDriver interface. For example, it is now possible - to change the ambient light. - -- There is a new parameter in the createDevice() function, which specifies if the - stencil buffer should be activated. Also, now all parameters have default parameters. - -- There is now a timer object to get the current timer. It can be received using - the getTimer() method from the IrrlichtDevice. - -- The first person shooter camera is now able to be moved by external using - setRelativePosition() and the sceneNodeAnimators. In addition, it now supports - multiple FPS cameras. - -- Mesh format loading extenstions are now possible. To extend the engine with a - mesh format it currently does not support (e.g. .cob), just implement a - IMeshLoader interface and add it to the engine calling - ISceneManager::addExternalMeshLoader(). - -- It is now possible to extend the Irrlicht Engine easily with new texture file format - loaders. If there is an image file format the engine does not support (for example - .gif files) the IImageLoader interface can be implemented to load .gif files - and added to the engine via IVideoDriver::addExternalSurfaceLoader(). - -------------------------------------------------------------------------------------- -Changes in version 0.1.5: (03 Apr 2003) - -- The zlib and libjpeg are now included in the SDK. - -- It is now possible to let the scene manager generate a hilly plane on the fly. - -- The Interface for handling dynamic lights was simplified. - -- The OpenGL 2D and 3D device is now full implemented. - -- There is now a way to access to root scene node from the scene manager, and so it - is possible to add external created custom scene nodes to the scene. - -- There is a new Camera control scene node available in the engine: First Person Shooter - Camera Control. Look with mouse movement, move and strafe with the cursor keys. - -- The engine now compiles with g++ and the Microsoft compilers, which enables it to - develop applications for the engine with VisualC++6.0, VisualC++.NET and Dev-C++. - -- There is now a ICursorControl available in the engine, which is able to modify the - mouse cursor: Get/Set the position of the cursor, make it invisible or visible. - -- video::Color was renamed to video::SColor to fit the Irrlicht Engine naming conventions - and for g++ compatibility issues in the Vertices. - -------------------------------------------------------------------------------------- -Release notes of version 0.1: (14 Mar 2003) - - This is an alpha version of the SDK. So please note that there are - features missing in the engine and maybe also some bugs. The following - list is a complete list of parts of this alpha SDK which do not work - 100% correct. All other parts which can be found in the documentation - and accessed with the Irrlicht header files work and can already be - used. - -- OpenGL Device - The OpenGL Device is currently only able to load textures and draw basic - 3D primitives. No 2D functions, complex materials and dynamic light are - implemented. Please use the DirectX8 or the Software Device instead. - In the next release (0.2) the OpenGL device will be complete. - -- Software Device - Dynamic lighting, multitexturing, 3d clipping and bilinear filtering are - not implemented because the Software Device was intented to to only 2d - functions, the primitive 3d functions are only an addition. Until the - first non beta release (1.0) of the Engine, some more 3d functionality - will be added. - -- BspTree - The binary space partition scene node does not work correctly and has - some bugs in it, which might lead to crashes. Please use the OctTree - scene node instead. There is nearly no difference between the interface - of them. - -- MeshViewerGUIElement - The camera control of this element is currently disabled. - -- FileOpenDialog - Not all functions are implemented. - -- Render to Texture support - Is not implemented yet. - -- MS3D Skeletal Animation - A loaded mesh is currently not animated and only drawn static. - -- Quake 3 maps - No support for curved surfaces yet. - -- Linux Support - The engine currently only runs with Windows platforms. A linux version - will be available somewhere between the versions 0.2 and 0.5, it depends - on the need of the users. - -------------------------------------------------------------------------------------- From 739a9eaf7c14e1240a13d1556974a43a30fbf326 Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 9 Feb 2022 19:28:45 +0000 Subject: [PATCH 054/123] IVideoDriver::setMaterialRendererName now using u32 for index like other similar functions Other functions like getMaterialRendererName got switched to u32 in the past. I can see no reason why this one was left out, so changing it to be same as the rest. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6300 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IVideoDriver.h | 2 +- source/Irrlicht/CNullDriver.cpp | 6 +++--- source/Irrlicht/CNullDriver.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index b220e5e6..ed4e6fa5 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -1279,7 +1279,7 @@ namespace video E_MATERIAL_TYPE enum or a value which was returned by addMaterialRenderer(). \param name: New name of the material renderer. */ - virtual void setMaterialRendererName(s32 idx, const c8* name) =0; + virtual void setMaterialRendererName(u32 idx, const c8* name) =0; //! Swap the material renderers used for certain id's /** Swap the IMaterialRenderers responsible for rendering specific diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 2cbd47cd..21e143a4 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -1824,10 +1824,10 @@ s32 CNullDriver::addMaterialRenderer(IMaterialRenderer* renderer, const char* na //! Sets the name of a material renderer. -void CNullDriver::setMaterialRendererName(s32 idx, const char* name) +void CNullDriver::setMaterialRendererName(u32 idx, const char* name) { - if (idx < s32(sizeof(sBuiltInMaterialTypeNames) / sizeof(char*))-1 || - idx >= (s32)MaterialRenderers.size()) + if (idx < (sizeof(sBuiltInMaterialTypeNames) / sizeof(char*))-1 || + idx >= MaterialRenderers.size()) return; MaterialRenderers[idx].Name = name; diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index e6cdce66..625ff1a6 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -585,7 +585,7 @@ namespace video bool writeImageToFile(IImage* image, io::IWriteFile * file, u32 param = 0) override; //! Sets the name of a material renderer. - void setMaterialRendererName(s32 idx, const char* name) override; + void setMaterialRendererName(u32 idx, const char* name) override; //! Swap the material renderers used for certain id's void swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames) override; From d1f441787a82a89c305796bfe13ba01da83ee3f6 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 10 Mar 2022 12:24:03 +0000 Subject: [PATCH 055/123] Avoid warnings when working with CMatrix4 git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6303 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/matrix4.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/matrix4.h b/include/matrix4.h index efd353de..ebbba589 100644 --- a/include/matrix4.h +++ b/include/matrix4.h @@ -1156,10 +1156,10 @@ namespace core template inline void CMatrix4::rotateVect( vector3df& vect ) const { - vector3df tmp = vect; - vect.X = tmp.X*M[0] + tmp.Y*M[4] + tmp.Z*M[8]; - vect.Y = tmp.X*M[1] + tmp.Y*M[5] + tmp.Z*M[9]; - vect.Z = tmp.X*M[2] + tmp.Y*M[6] + tmp.Z*M[10]; + vector3d tmp(static_cast(vect.X), static_cast(vect.Y), static_cast(vect.Z)); + vect.X = static_cast(tmp.X*M[0] + tmp.Y*M[4] + tmp.Z*M[8]); + vect.Y = static_cast(tmp.X*M[1] + tmp.Y*M[5] + tmp.Z*M[9]); + vect.Z = static_cast(tmp.X*M[2] + tmp.Y*M[6] + tmp.Z*M[10]); } //! An alternate transform vector method, writing into a second vector @@ -1183,10 +1183,10 @@ namespace core template inline void CMatrix4::inverseRotateVect( vector3df& vect ) const { - vector3df tmp = vect; - vect.X = tmp.X*M[0] + tmp.Y*M[1] + tmp.Z*M[2]; - vect.Y = tmp.X*M[4] + tmp.Y*M[5] + tmp.Z*M[6]; - vect.Z = tmp.X*M[8] + tmp.Y*M[9] + tmp.Z*M[10]; + vector3d tmp(static_cast(vect.X), static_cast(vect.Y), static_cast(vect.Z)); + vect.X = static_cast(tmp.X*M[0] + tmp.Y*M[1] + tmp.Z*M[2]); + vect.Y = static_cast(tmp.X*M[4] + tmp.Y*M[5] + tmp.Z*M[6]); + vect.Z = static_cast(tmp.X*M[8] + tmp.Y*M[9] + tmp.Z*M[10]); } template From 679d3a8ba747186188bdfba9989908ddfe640716 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 10 Mar 2022 12:51:10 +0000 Subject: [PATCH 056/123] Avoid some more warnings when working with CMatrix4 git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6304 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/matrix4.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/matrix4.h b/include/matrix4.h index ebbba589..e879c04c 100644 --- a/include/matrix4.h +++ b/include/matrix4.h @@ -1192,15 +1192,15 @@ namespace core template inline void CMatrix4::transformVect( vector3df& vect) const { - f32 vector[3]; + T vector[3]; vector[0] = vect.X*M[0] + vect.Y*M[4] + vect.Z*M[8] + M[12]; vector[1] = vect.X*M[1] + vect.Y*M[5] + vect.Z*M[9] + M[13]; vector[2] = vect.X*M[2] + vect.Y*M[6] + vect.Z*M[10] + M[14]; - vect.X = vector[0]; - vect.Y = vector[1]; - vect.Z = vector[2]; + vect.X = static_cast(vector[0]); + vect.Y = static_cast(vector[1]); + vect.Z = static_cast(vector[2]); } template From b0c03b6f3b49e2c176df341bc1c3263701946be5 Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 30 Mar 2022 10:49:13 +0000 Subject: [PATCH 057/123] Add documentation that sourceRect of draw2dImage is based on the OriginalSize git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6324 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IVideoDriver.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index ed4e6fa5..2fcb0ab9 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -764,7 +764,7 @@ namespace video \param texture Texture to be drawn. \param destPos Upper left 2d destination position where the image will be drawn. - \param sourceRect Source rectangle in the image. + \param sourceRect Source rectangle in the texture (based on it's OriginalSize) \param clipRect Pointer to rectangle on the screen where the image is clipped to. If this pointer is NULL the image is not clipped. @@ -786,7 +786,7 @@ namespace video \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 sourceRects Source rectangles of the texture (based on it's OriginalSize) \param indices List of indices which choose the actual rectangle used each time. \param kerningWidth Offset to Position on X @@ -814,7 +814,7 @@ namespace video \param texture Texture to be drawn. \param positions Array of upper left 2d destinations where the images will be drawn. - \param sourceRects Source rectangles of the image. + \param sourceRects Source rectangles of the texture (based on it's OriginalSize) \param clipRect Pointer to rectangle on the screen where the images are clipped to. If this pointer is 0 then the image is not clipped. @@ -834,7 +834,7 @@ namespace video /** Suggested and first implemented by zola. \param texture The texture to draw from \param destRect The rectangle to draw into - \param sourceRect The rectangle denoting a part of the texture + \param sourceRect The rectangle denoting a part of the texture (based on it's OriginalSize) \param clipRect Clips the destination rectangle (may be 0) \param colors Array of 4 colors denoting the color values of the corners of the destRect From c5ee8c83971a13861b98bbc75c6cac3c1e9741eb Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 19 Apr 2022 12:21:44 +0000 Subject: [PATCH 058/123] CVertexBuffer no longer re-allocates stuff when type doesn't change git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6339 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/CVertexBuffer.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/CVertexBuffer.h b/include/CVertexBuffer.h index e382dc5a..aa8049f3 100644 --- a/include/CVertexBuffer.h +++ b/include/CVertexBuffer.h @@ -97,6 +97,9 @@ namespace scene void setType(video::E_VERTEX_TYPE vertexType) override { + if ( Vertices && Vertices->getType() == vertexType ) + return; + IVertexList *NewVertices=0; switch (vertexType) From 263f24352364b370500aab94e237a22a21631435 Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 25 Apr 2022 14:24:43 +0000 Subject: [PATCH 059/123] S3DVertex initialize color always. It's derived classes now both accept const S3DVertex& constructor. color intitialization has some cost, but we initialized all other values already (vectors are always set to 0). Don't think it's a good idea to have one value around which is random. S3DVertex2TCoords(S3DVertex& o) to S3DVertex2TCoords(const S3DVertex& o) simply because it makes more sense S3DVertexTangents(const S3DVertex& o) added because I'll need it later (and no idea why only S3DVertex2TCoords got one of those before). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6359 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/S3DVertex.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/S3DVertex.h b/include/S3DVertex.h index 2040f9d1..3d78e203 100644 --- a/include/S3DVertex.h +++ b/include/S3DVertex.h @@ -44,7 +44,7 @@ const char* const sBuiltInVertexTypeNames[] = struct S3DVertex { //! default constructor - S3DVertex() {} + S3DVertex() : Color(0xffffffff) {} //! constructor S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv) @@ -142,7 +142,7 @@ struct S3DVertex2TCoords : public S3DVertex : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {} //! constructor from S3DVertex - S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {} + S3DVertex2TCoords(const S3DVertex& o) : S3DVertex(o) {} //! Second set of texture coordinates core::vector2d TCoords2; @@ -214,6 +214,9 @@ struct S3DVertexTangents : public S3DVertex const core::vector3df& binormal=core::vector3df()) : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { } + //! constructor from S3DVertex + S3DVertexTangents(const S3DVertex& o) : S3DVertex(o) {} + //! Tangent vector along the x-axis of the texture core::vector3df Tangent; From 15e3f15b48073f4085f81b9a063b709c7872eab7 Mon Sep 17 00:00:00 2001 From: engineer_apple Date: Sun, 1 May 2022 09:50:32 +0000 Subject: [PATCH 060/123] SpriteBank: error check on non existing textureNumber seen in broken Fonts. unified getFrameNr git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6368 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CGUISpriteBank.cpp | 53 +++++++++++++++++++----------- source/Irrlicht/CGUISpriteBank.h | 14 +------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/source/Irrlicht/CGUISpriteBank.cpp b/source/Irrlicht/CGUISpriteBank.cpp index 8f5fb673..6dd7aa3f 100644 --- a/source/Irrlicht/CGUISpriteBank.cpp +++ b/source/Irrlicht/CGUISpriteBank.cpp @@ -31,10 +31,7 @@ CGUISpriteBank::CGUISpriteBank(IGUIEnvironment* env) : CGUISpriteBank::~CGUISpriteBank() { - // drop textures - for (u32 i=0; idrop(); + clear(); // drop video driver if (Driver) @@ -132,15 +129,38 @@ s32 CGUISpriteBank::addTextureAsSprite(video::ITexture* texture) return Sprites.size() - 1; } +// get FrameNr for time. return true on exisiting frame +inline bool CGUISpriteBank::getFrameNr(u32& frame,u32 index, u32 time, bool loop) const +{ + frame = 0; + if (index >= Sprites.size()) + return false; + + const SGUISprite& sprite = Sprites[index]; + const u32 frameSize = sprite.Frames.size(); + if (frameSize < 1) + return false; + + if (sprite.frameTime) + { + u32 f = (time / sprite.frameTime); + if (loop) + frame = f % frameSize; + else + frame = (f >= frameSize) ? frameSize - 1 : f; + } + return true; +} + //! draws a sprite in 2d with scale and color void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos, const core::rect* clip, const video::SColor& color, u32 starttime, u32 currenttime, bool loop, bool center) { - if (index >= Sprites.size() || Sprites[index].Frames.empty() ) + u32 frame = 0; + if (!getFrameNr(frame, index, currenttime - starttime, loop)) return; - u32 frame = getFrameNr(index, currenttime - starttime, loop); const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber); if (!tex) return; @@ -162,10 +182,10 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::rect& destRect, const core::rect* clip, const video::SColor * const colors, u32 timeTicks, bool loop) { - if (index >= Sprites.size() || Sprites[index].Frames.empty() ) + u32 frame = 0; + if (!getFrameNr(frame,index, timeTicks, loop)) return; - u32 frame = getFrameNr(index, timeTicks, loop); const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber); if (!tex) return; @@ -200,21 +220,16 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array& indices, { const u32 index = indices[i]; - if (index >= Sprites.size() || Sprites[index].Frames.empty() ) - continue; - // work out frame number u32 frame = 0; - if (Sprites[index].frameTime) - { - u32 f = ((currenttime - starttime) / Sprites[index].frameTime); - if (loop) - frame = f % Sprites[index].Frames.size(); - else - frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; - } + if (!getFrameNr(frame, index, currenttime - starttime, loop)) + return; const u32 texNum = Sprites[index].Frames[frame].textureNumber; + if (texNum >= drawBatches.size()) + { + continue; + } SDrawBatch& currentBatch = drawBatches[texNum]; const u32 rn = Sprites[index].Frames[frame].rectNumber; diff --git a/source/Irrlicht/CGUISpriteBank.h b/source/Irrlicht/CGUISpriteBank.h index affd6bfd..5bd115bc 100644 --- a/source/Irrlicht/CGUISpriteBank.h +++ b/source/Irrlicht/CGUISpriteBank.h @@ -64,19 +64,7 @@ public: protected: - inline u32 getFrameNr(u32 index, u32 time, bool loop) const - { - u32 frame = 0; - if (Sprites[index].frameTime && Sprites[index].Frames.size() ) - { - u32 f = (time / Sprites[index].frameTime); - if (loop) - frame = f % Sprites[index].Frames.size(); - else - frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; - } - return frame; - } + bool getFrameNr(u32& frameNr, u32 index, u32 time, bool loop) const; struct SDrawBatch { From 6a9e0f109c0be5529730d55d5b6d6862d4b78a24 Mon Sep 17 00:00:00 2001 From: cutealien Date: Fri, 13 May 2022 14:56:22 +0000 Subject: [PATCH 061/123] Avoid potential number overflows. Found by VS code analyser git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6393 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CB3DMeshWriter.cpp | 2 +- source/Irrlicht/CImage.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CB3DMeshWriter.cpp b/source/Irrlicht/CB3DMeshWriter.cpp index ac68f77e..3b5e49aa 100644 --- a/source/Irrlicht/CB3DMeshWriter.cpp +++ b/source/Irrlicht/CB3DMeshWriter.cpp @@ -94,7 +94,7 @@ bool CB3DMeshWriter::writeMesh(io::IWriteFile* file, IMesh* const mesh, s32 flag u32 numTexture = texs.size(); for (u32 i = 0; i < numTexture; i++) { - file->write(texs[i].TextureName.c_str(), texs[i].TextureName.size() + 1); + file->write(texs[i].TextureName.c_str(), (size_t)texs[i].TextureName.size() + 1); file->write(&texs[i].Flags, 7*4); } diff --git a/source/Irrlicht/CImage.cpp b/source/Irrlicht/CImage.cpp index fcbeacf3..5d1e9fa1 100644 --- a/source/Irrlicht/CImage.cpp +++ b/source/Irrlicht/CImage.cpp @@ -194,7 +194,7 @@ void CImage::copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT fo { if (pitch==Pitch) { - memcpy(target, Data, height*pitch); + memcpy(target, Data, (size_t)height*pitch); return; } else From 424eb85f4d6a4f9d7238e469e27cc4f82bffd477 Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 15 May 2022 13:43:32 +0000 Subject: [PATCH 062/123] Minor const changes. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6402 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CB3DMeshWriter.cpp | 2 +- source/Irrlicht/CB3DMeshWriter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CB3DMeshWriter.cpp b/source/Irrlicht/CB3DMeshWriter.cpp index 3b5e49aa..2b4a679a 100644 --- a/source/Irrlicht/CB3DMeshWriter.cpp +++ b/source/Irrlicht/CB3DMeshWriter.cpp @@ -476,7 +476,7 @@ core::array CB3DMeshWriter::getRootJoints(const ISkinnedM return roots; } -u32 CB3DMeshWriter::getUVlayerCount(IMesh* mesh) +u32 CB3DMeshWriter::getUVlayerCount(const IMesh* mesh) { const u32 numBeshBuffers = mesh->getMeshBufferCount(); for (u32 i = 0; i < numBeshBuffers; i++) diff --git a/source/Irrlicht/CB3DMeshWriter.h b/source/Irrlicht/CB3DMeshWriter.h index 4a74f215..86a35d93 100644 --- a/source/Irrlicht/CB3DMeshWriter.h +++ b/source/Irrlicht/CB3DMeshWriter.h @@ -37,7 +37,7 @@ private: u32 getJointChunkSize(const ISkinnedMesh* mesh, ISkinnedMesh::SJoint* joint); core::array getRootJoints(const ISkinnedMesh* mesh); - u32 getUVlayerCount(IMesh *mesh); + u32 getUVlayerCount(const IMesh *mesh); ISkinnedMesh* getSkinned (IMesh *mesh); inline void writeVector2(io::IWriteFile* file, const core::vector2df& vec); From 3ce4b2b5dceb2c0c0d265d04a9aac72aba544c3a Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 30 May 2022 20:13:28 +0000 Subject: [PATCH 063/123] Prevent crash when creating CCameraSceneNode while rendertarget has height 0 git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6405 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CCameraSceneNode.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Irrlicht/CCameraSceneNode.cpp b/source/Irrlicht/CCameraSceneNode.cpp index aaa752f4..77d8c28f 100644 --- a/source/Irrlicht/CCameraSceneNode.cpp +++ b/source/Irrlicht/CCameraSceneNode.cpp @@ -28,16 +28,16 @@ CCameraSceneNode::CCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 i // set default projection Fovy = core::PI / 2.5f; // Field of view, in radians. + Aspect = 4.0f / 3.0f; // Aspect ratio. const video::IVideoDriver* const d = mgr?mgr->getVideoDriver():0; if (d) { - Aspect = (f32)d->getCurrentRenderTargetSize().Width / - (f32)d->getCurrentRenderTargetSize().Height; + if ( d->getCurrentRenderTargetSize().Height ) + Aspect = (f32)d->getCurrentRenderTargetSize().Width / + (f32)d->getCurrentRenderTargetSize().Height; HasD3DStyleProjectionMatrix = d->getDriverType() != video::EDT_OPENGL; } - else - Aspect = 4.0f / 3.0f; // Aspect ratio. ViewArea.setFarNearDistance(ZFar - ZNear); recalculateProjectionMatrix(); From 98df6eae77d646eb8958ce39988d2c0c8da0b1ba Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 30 Jun 2022 16:23:48 +0000 Subject: [PATCH 064/123] Unify & improve log messages Lots of places where coders did not realize our Printer::log with hint adds a ": " string between message and hint Which caused uglier messages in a few places (added documentation for that, maybe helps?) Some added info in a few places Some whitespace unification Some spelling unification git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6414 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CImageLoaderPNG.cpp | 12 ++++++------ source/Irrlicht/CImageLoaderTGA.cpp | 2 +- source/Irrlicht/CImageWriterPNG.cpp | 8 ++++---- source/Irrlicht/CIrrDeviceLinux.cpp | 16 ++++++++-------- source/Irrlicht/CIrrDeviceSDL.cpp | 4 ++-- source/Irrlicht/COBJMeshFileLoader.cpp | 2 +- source/Irrlicht/CSkinnedMesh.cpp | 12 ++++++------ source/Irrlicht/CWGLManager.cpp | 2 +- source/Irrlicht/CXMeshFileLoader.cpp | 4 ++-- source/Irrlicht/os.h | 2 ++ 10 files changed, 33 insertions(+), 31 deletions(-) diff --git a/source/Irrlicht/CImageLoaderPNG.cpp b/source/Irrlicht/CImageLoaderPNG.cpp index 59709bfb..665634c1 100644 --- a/source/Irrlicht/CImageLoaderPNG.cpp +++ b/source/Irrlicht/CImageLoaderPNG.cpp @@ -80,14 +80,14 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const // Read the first few bytes of the PNG file if( file->read(buffer, 8) != 8 ) { - os::Printer::log("LOAD PNG: can't read file\n", file->getFileName(), ELL_ERROR); + os::Printer::log("LOAD PNG: can't read file (filesize < 8)", file->getFileName(), ELL_ERROR); return 0; } // Check if it really is a PNG file if( png_sig_cmp(buffer, 0, 8) ) { - os::Printer::log("LOAD PNG: not really a png\n", file->getFileName(), ELL_ERROR); + os::Printer::log("LOAD PNG: not really a png (wrong signature)", file->getFileName(), ELL_ERROR); return 0; } @@ -96,7 +96,7 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warn); if (!png_ptr) { - os::Printer::log("LOAD PNG: Internal PNG create read struct failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("LOAD PNG: Internal PNG create read struct failure", file->getFileName(), ELL_ERROR); return 0; } @@ -104,7 +104,7 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - os::Printer::log("LOAD PNG: Internal PNG create info struct failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("LOAD PNG: Internal PNG create info struct failure", file->getFileName(), ELL_ERROR); png_destroy_read_struct(&png_ptr, NULL, NULL); return 0; } @@ -212,7 +212,7 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const image = new CImage(ECF_R8G8B8, core::dimension2d(Width, Height)); if (!image) { - os::Printer::log("LOAD PNG: Internal PNG create image struct failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("LOAD PNG: Internal PNG create image struct failure", file->getFileName(), ELL_ERROR); png_destroy_read_struct(&png_ptr, NULL, NULL); return 0; } @@ -221,7 +221,7 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const RowPointers = new png_bytep[Height]; if (!RowPointers) { - os::Printer::log("LOAD PNG: Internal PNG create row pointers failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("LOAD PNG: Internal PNG create row pointers failure", file->getFileName(), ELL_ERROR); png_destroy_read_struct(&png_ptr, NULL, NULL); delete image; return 0; diff --git a/source/Irrlicht/CImageLoaderTGA.cpp b/source/Irrlicht/CImageLoaderTGA.cpp index 3286bddd..d5e24a58 100644 --- a/source/Irrlicht/CImageLoaderTGA.cpp +++ b/source/Irrlicht/CImageLoaderTGA.cpp @@ -106,7 +106,7 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const if (!checkImageDimensions(header.ImageWidth, header.ImageHeight)) { - os::Printer::log("Rejecting TGA with unreasonable size.", ELL_ERROR); + os::Printer::log("Image dimensions too large in file", file->getFileName(), ELL_ERROR); return 0; } diff --git a/source/Irrlicht/CImageWriterPNG.cpp b/source/Irrlicht/CImageWriterPNG.cpp index 0e2a71ec..2f5260a8 100644 --- a/source/Irrlicht/CImageWriterPNG.cpp +++ b/source/Irrlicht/CImageWriterPNG.cpp @@ -69,7 +69,7 @@ bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warning); if (!png_ptr) { - os::Printer::log("PNGWriter: Internal PNG create write struct failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("PNGWriter: Internal PNG create write struct failure", file->getFileName(), ELL_ERROR); return false; } @@ -77,7 +77,7 @@ bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - os::Printer::log("PNGWriter: Internal PNG create info struct failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("PNGWriter: Internal PNG create info struct failure", file->getFileName(), ELL_ERROR); png_destroy_write_struct(&png_ptr, NULL); return false; } @@ -126,7 +126,7 @@ bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) u8* tmpImage = new u8[image->getDimension().Height*lineWidth]; if (!tmpImage) { - os::Printer::log("PNGWriter: Internal PNG create image failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("PNGWriter: Internal PNG create image failure", file->getFileName(), ELL_ERROR); png_destroy_write_struct(&png_ptr, &info_ptr); return false; } @@ -160,7 +160,7 @@ bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) u8** RowPointers = new png_bytep[image->getDimension().Height]; if (!RowPointers) { - os::Printer::log("PNGWriter: Internal PNG create row pointers failure\n", file->getFileName(), ELL_ERROR); + os::Printer::log("PNGWriter: Internal PNG create row pointers failure", file->getFileName(), ELL_ERROR); png_destroy_write_struct(&png_ptr, &info_ptr); delete [] tmpImage; return false; diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index b447015b..3c190991 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -287,26 +287,26 @@ void IrrPrintXGrabError(int grabResult, const c8 * grabCommand ) { if ( grabResult == GrabSuccess ) { -// os::Printer::log(grabCommand, ": GrabSuccess", ELL_INFORMATION); +// os::Printer::log(grabCommand, "GrabSuccess", ELL_INFORMATION); return; } switch ( grabResult ) { case AlreadyGrabbed: - os::Printer::log(grabCommand, ": AlreadyGrabbed", ELL_WARNING); + os::Printer::log(grabCommand, "AlreadyGrabbed", ELL_WARNING); break; case GrabNotViewable: - os::Printer::log(grabCommand, ": GrabNotViewable", ELL_WARNING); + os::Printer::log(grabCommand, "GrabNotViewable", ELL_WARNING); break; case GrabFrozen: - os::Printer::log(grabCommand, ": GrabFrozen", ELL_WARNING); + os::Printer::log(grabCommand, "GrabFrozen", ELL_WARNING); break; case GrabInvalidTime: - os::Printer::log(grabCommand, ": GrabInvalidTime", ELL_WARNING); + os::Printer::log(grabCommand, "GrabInvalidTime", ELL_WARNING); break; default: - os::Printer::log(grabCommand, ": grab failed with unknown problem", ELL_WARNING); + os::Printer::log(grabCommand, "grab failed with unknown problem", ELL_WARNING); break; } } @@ -380,7 +380,7 @@ bool CIrrDeviceLinux::createWindow() } #ifdef _DEBUG else - os::Printer::log("Visual chosen: ", core::stringc(static_cast(VisualInfo->visualid)).c_str(), ELL_DEBUG); + os::Printer::log("Visual chosen", core::stringc(static_cast(VisualInfo->visualid)).c_str(), ELL_DEBUG); #endif // create color map @@ -1796,7 +1796,7 @@ Bool PredicateIsEventType(Display *display, XEvent *event, XPointer arg) { if ( event && event->type == *(int*)arg ) { -// os::Printer::log("remove event:", core::stringc((int)arg).c_str(), ELL_INFORMATION); +// os::Printer::log("remove event", core::stringc((int)arg).c_str(), ELL_INFORMATION); return True; } return False; diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 711cb564..26683a72 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -220,7 +220,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) #endif if (SDL_Init(flags) < 0) { - os::Printer::log( "Unable to initialize SDL!", SDL_GetError()); + os::Printer::log("Unable to initialize SDL!", SDL_GetError()); Close = true; } else @@ -447,7 +447,7 @@ bool CIrrDeviceSDL::createWindow() } if ( !Window ) { - os::Printer::log( "Could not initialize display!" ); + os::Printer::log("Could not initialize display!" ); return false; } diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index 740f8e5f..43ea51e0 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -224,7 +224,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) v.Pos = vertexBuffer[Idx[0]]; else { - os::Printer::log("Invalid vertex index in this line:", wordBuffer.c_str(), ELL_ERROR); + os::Printer::log("Invalid vertex index in this line", wordBuffer.c_str(), ELL_ERROR); delete [] buf; return 0; } diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index f7cf1f05..75e2ca64 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -1134,27 +1134,27 @@ void CSkinnedMesh::finalize() if ( redundantPosKeys > 0 ) { - os::Printer::log("Skinned Mesh - redundant position frames kicked:", core::stringc(redundantPosKeys).c_str(), ELL_DEBUG); + os::Printer::log("Skinned Mesh - redundant position frames kicked", core::stringc(redundantPosKeys).c_str(), ELL_DEBUG); } if ( unorderedPosKeys > 0 ) { - irr::os::Printer::log("Skinned Mesh - unsorted position frames kicked:", irr::core::stringc(unorderedPosKeys).c_str(), irr::ELL_DEBUG); + irr::os::Printer::log("Skinned Mesh - unsorted position frames kicked", irr::core::stringc(unorderedPosKeys).c_str(), irr::ELL_DEBUG); } if ( redundantScaleKeys > 0 ) { - os::Printer::log("Skinned Mesh - redundant scale frames kicked:", core::stringc(redundantScaleKeys).c_str(), ELL_DEBUG); + os::Printer::log("Skinned Mesh - redundant scale frames kicked", core::stringc(redundantScaleKeys).c_str(), ELL_DEBUG); } if ( unorderedScaleKeys > 0 ) { - irr::os::Printer::log("Skinned Mesh - unsorted scale frames kicked:", irr::core::stringc(unorderedScaleKeys).c_str(), irr::ELL_DEBUG); + irr::os::Printer::log("Skinned Mesh - unsorted scale frames kicked", irr::core::stringc(unorderedScaleKeys).c_str(), irr::ELL_DEBUG); } if ( redundantRotationKeys > 0 ) { - os::Printer::log("Skinned Mesh - redundant rotation frames kicked:", core::stringc(redundantRotationKeys).c_str(), ELL_DEBUG); + os::Printer::log("Skinned Mesh - redundant rotation frames kicked", core::stringc(redundantRotationKeys).c_str(), ELL_DEBUG); } if ( unorderedRotationKeys > 0 ) { - irr::os::Printer::log("Skinned Mesh - unsorted rotation frames kicked:", irr::core::stringc(unorderedRotationKeys).c_str(), irr::ELL_DEBUG); + irr::os::Printer::log("Skinned Mesh - unsorted rotation frames kicked", irr::core::stringc(unorderedRotationKeys).c_str(), irr::ELL_DEBUG); } } diff --git a/source/Irrlicht/CWGLManager.cpp b/source/Irrlicht/CWGLManager.cpp index 0d7ef42c..4cd6ea8b 100644 --- a/source/Irrlicht/CWGLManager.cpp +++ b/source/Irrlicht/CWGLManager.cpp @@ -464,7 +464,7 @@ bool CWGLManager::activateContext(const SExposedVideoData& videoData, bool resto { if (!wglMakeCurrent((HDC)PrimaryContext.OpenGLWin32.HDc, (HGLRC)PrimaryContext.OpenGLWin32.HRc)) { - os::Printer::log("Render Context switch failed."); + os::Printer::log("Render Context switch (back to main) failed."); return false; } CurrentContext=PrimaryContext; diff --git a/source/Irrlicht/CXMeshFileLoader.cpp b/source/Irrlicht/CXMeshFileLoader.cpp index 2a365ac1..c06cd177 100644 --- a/source/Irrlicht/CXMeshFileLoader.cpp +++ b/source/Irrlicht/CXMeshFileLoader.cpp @@ -479,7 +479,7 @@ bool CXMeshFileLoader::parseDataObject() // parse specific object #ifdef _XREADER_DEBUG - os::Printer::log("debug DataObject:", objectName.c_str(), ELL_DEBUG); + os::Printer::log("debug DataObject", objectName.c_str(), ELL_DEBUG); #endif if (objectName == "template") @@ -832,7 +832,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SXMesh &mesh) } #ifdef _XREADER_DEBUG - os::Printer::log("debug DataObject in mesh:", objectName.c_str(), ELL_DEBUG); + os::Printer::log("debug DataObject in mesh", objectName.c_str(), ELL_DEBUG); #endif if (objectName == "MeshNormals") diff --git a/source/Irrlicht/os.h b/source/Irrlicht/os.h index c0aa83b0..dc1a154a 100644 --- a/source/Irrlicht/os.h +++ b/source/Irrlicht/os.h @@ -38,6 +38,8 @@ namespace os static void print(const c8* message, ELOG_LEVEL ll = ELL_INFORMATION); static void log(const c8* message, ELOG_LEVEL ll = ELL_INFORMATION); static void log(const wchar_t* message, ELOG_LEVEL ll = ELL_INFORMATION); + + // The string ": " is added between message and hint static void log(const c8* message, const c8* hint, ELOG_LEVEL ll = ELL_INFORMATION); static void log(const c8* message, const io::path& hint, ELOG_LEVEL ll = ELL_INFORMATION); static ILogger* Logger; From a7f9afd2898a39cec175d877774b729c61630274 Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 25 Sep 2022 11:18:55 +0000 Subject: [PATCH 065/123] Avoid ambigious conversions when compiling with c++20 Yay, more ugly casts needed. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6427 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/S3DVertex.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/S3DVertex.h b/include/S3DVertex.h index 3d78e203..aba81a79 100644 --- a/include/S3DVertex.h +++ b/include/S3DVertex.h @@ -25,7 +25,7 @@ enum E_VERTEX_TYPE EVT_2TCOORDS, //! Vertex with a tangent and binormal vector, video::S3DVertexTangents. - /** Usually used for tangent space normal mapping. + /** Usually used for tangent space normal mapping. Usually tangent and binormal get send to shaders as texture coordinate sets 1 and 2. */ EVT_TANGENTS @@ -150,21 +150,21 @@ struct S3DVertex2TCoords : public S3DVertex //! Equality operator bool operator==(const S3DVertex2TCoords& other) const { - return ((static_cast(*this)==other) && + return ((static_cast(*this)==static_cast(other)) && (TCoords2 == other.TCoords2)); } //! Inequality operator bool operator!=(const S3DVertex2TCoords& other) const { - return ((static_cast(*this)!=other) || + return ((static_cast(*this)!=static_cast(other)) || (TCoords2 != other.TCoords2)); } bool operator<(const S3DVertex2TCoords& other) const { return ((static_cast(*this) < other) || - ((static_cast(*this) == other) && (TCoords2 < other.TCoords2))); + ((static_cast(*this) == static_cast(other)) && (TCoords2 < other.TCoords2))); } static E_VERTEX_TYPE getType() @@ -186,7 +186,7 @@ struct S3DVertex2TCoords : public S3DVertex //! Vertex with a tangent and binormal vector. -/** Usually used for tangent space normal mapping. +/** Usually used for tangent space normal mapping. Usually tangent and binormal get send to shaders as texture coordinate sets 1 and 2. */ struct S3DVertexTangents : public S3DVertex @@ -225,14 +225,14 @@ struct S3DVertexTangents : public S3DVertex bool operator==(const S3DVertexTangents& other) const { - return ((static_cast(*this)==other) && + return ((static_cast(*this)==static_cast(other)) && (Tangent == other.Tangent) && (Binormal == other.Binormal)); } bool operator!=(const S3DVertexTangents& other) const { - return ((static_cast(*this)!=other) || + return ((static_cast(*this)!=static_cast(other)) || (Tangent != other.Tangent) || (Binormal != other.Binormal)); } @@ -240,8 +240,8 @@ struct S3DVertexTangents : public S3DVertex bool operator<(const S3DVertexTangents& other) const { return ((static_cast(*this) < other) || - ((static_cast(*this) == other) && (Tangent < other.Tangent)) || - ((static_cast(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal))); + ((static_cast(*this) == static_cast(other)) && (Tangent < other.Tangent)) || + ((static_cast(*this) == static_cast(other)) && (Tangent == other.Tangent) && (Binormal < other.Binormal))); } static E_VERTEX_TYPE getType() From 3cf75cdce41a9d1e40dc2398cca295bf28d54d2e Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 27 Sep 2022 16:02:39 +0000 Subject: [PATCH 066/123] Fix IGUIElements not getting a tab order because of invisible or disabled parents. First problem was that IGUIElement::getNextElement wasn't passing includeInvisible and includeDisabled flags recursively, so anything deeper than one level could fail if an element was disabled/invisible in between while it was created. Second problem was that setTabOrder(-1) did ignore disabled elements. So when any parent was disabled when elements were created they never got a tab order. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6428 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IGUIElement.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/IGUIElement.h b/include/IGUIElement.h index 4026b7eb..15fd3d15 100644 --- a/include/IGUIElement.h +++ b/include/IGUIElement.h @@ -433,7 +433,7 @@ public: if (el) { // find the highest element number - el->getNextElement(-1, true, IsTabGroup, first, closest, true); + el->getNextElement(-1, true, IsTabGroup, first, closest, true, true); if (first) { TabOrder = first->getTabOrder() + 1; @@ -706,7 +706,7 @@ public: } } // search within children - if ((*it)->getNextElement(startOrder, reverse, group, first, closest)) + if ((*it)->getNextElement(startOrder, reverse, group, first, closest, includeInvisible, includeDisabled)) { return true; } From 2bff14790434a36ab2a360b83eaebbd70e1e74ef Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 29 Sep 2022 14:12:12 +0000 Subject: [PATCH 067/123] Fix: Make CBillboardSceneNode bounding-box large enough to fit the billboard inside. It still won't work yet for scaled boundingboxes (or parents being scaled). But at least it's now large enough for typical unscaled boundingboxes. Before it was always too small - even for the simplest quadratic billboard case seen without rotation. Now it's always a bit too large, but that's way less of a problem (collisions still work and culling simply happens a bit less often, but not too often which is way worse) git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6431 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CBillboardSceneNode.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/Irrlicht/CBillboardSceneNode.cpp b/source/Irrlicht/CBillboardSceneNode.cpp index da90c3a1..c1776d4d 100644 --- a/source/Irrlicht/CBillboardSceneNode.cpp +++ b/source/Irrlicht/CBillboardSceneNode.cpp @@ -141,7 +141,7 @@ void CBillboardSceneNode::updateMesh(const irr::scene::ICameraSceneNode* camera) //! returns the axis aligned bounding box of this node const core::aabbox3d& CBillboardSceneNode::getBoundingBox() const { - // Really wrong when scaled. + // Really wrong when scaled (as the node does not scale it's vertices - maybe it should?) return BBoxSafe; } @@ -162,9 +162,9 @@ void CBillboardSceneNode::setSize(const core::dimension2d& size) if (core::equals(Size.Height, 0.0f)) Size.Height = 1.0f; - const f32 avg = (Size.Width + Size.Height)/6; - BBoxSafe.MinEdge.set(-avg,-avg,-avg); - BBoxSafe.MaxEdge.set(avg,avg,avg); + const f32 extent = 0.5f*sqrt(Size.Width*Size.Width + Size.Height*Size.Height); + BBoxSafe.MinEdge.set(-extent,-extent,-extent); + BBoxSafe.MaxEdge.set(extent,extent,extent); } @@ -182,9 +182,9 @@ void CBillboardSceneNode::setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWi TopEdgeWidth = 1.0f; } - const f32 avg = (core::max_(Size.Width,TopEdgeWidth) + Size.Height)/6; - BBoxSafe.MinEdge.set(-avg,-avg,-avg); - BBoxSafe.MaxEdge.set(avg,avg,avg); + const f32 extent = 0.5f*sqrt(Size.Width*Size.Width + Size.Height*Size.Height); + BBoxSafe.MinEdge.set(-extent,-extent,-extent); + BBoxSafe.MaxEdge.set(extent,extent,extent); } From 8ffa7eafea218d12db29be08240ea233259372a1 Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 4 Oct 2022 12:32:27 +0000 Subject: [PATCH 068/123] Fix warning git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6434 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CBillboardSceneNode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CBillboardSceneNode.cpp b/source/Irrlicht/CBillboardSceneNode.cpp index c1776d4d..b61a8eaa 100644 --- a/source/Irrlicht/CBillboardSceneNode.cpp +++ b/source/Irrlicht/CBillboardSceneNode.cpp @@ -162,7 +162,7 @@ void CBillboardSceneNode::setSize(const core::dimension2d& size) if (core::equals(Size.Height, 0.0f)) Size.Height = 1.0f; - const f32 extent = 0.5f*sqrt(Size.Width*Size.Width + Size.Height*Size.Height); + const f32 extent = 0.5f*sqrtf(Size.Width*Size.Width + Size.Height*Size.Height); BBoxSafe.MinEdge.set(-extent,-extent,-extent); BBoxSafe.MaxEdge.set(extent,extent,extent); } @@ -182,7 +182,7 @@ void CBillboardSceneNode::setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWi TopEdgeWidth = 1.0f; } - const f32 extent = 0.5f*sqrt(Size.Width*Size.Width + Size.Height*Size.Height); + const f32 extent = 0.5f*sqrtf(Size.Width*Size.Width + Size.Height*Size.Height); BBoxSafe.MinEdge.set(-extent,-extent,-extent); BBoxSafe.MaxEdge.set(extent,extent,extent); } From edb381bd5050712d1eb8875fe3a405000dd09a3d Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 11 Oct 2022 22:54:44 +0000 Subject: [PATCH 069/123] Avoid some broken calculations for IBoneSceneNode positions. This is based on bugreport #458 reported by viwrap who also made a nice test-case model. Note: While solution seems to work and would even be faster, I'm not 100% sure yet if there are no downsides. The other solution seems to regard last column in matrices - thought I don't think we ever set or use that. And I also haven't found out yet _why_ the original solution goes wrong. But animation system uses right-hand quaternions unlike rest of Irrlicht which is obviously a bit dangerous, will have to check the conversions some day. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6438 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CSkinnedMesh.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index 75e2ca64..07e86d6b 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -1347,9 +1347,24 @@ void CSkinnedMesh::recoverJointsFromMesh(core::array &jointChil { IBoneSceneNode* node=jointChildSceneNodes[i]; SJoint *joint=AllJoints[i]; - node->setPosition(joint->LocalAnimatedMatrix.getTranslation()); - node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees()); - node->setScale(joint->LocalAnimatedMatrix.getScale()); + + if ( joint->UseAnimationFrom ) // Seems to work better (else solution seems to mess up sometimes) and would be faster. Any disadvantage? + { + node->setPosition(joint->Animatedposition); + core::quaternion qrot = joint->Animatedrotation; + qrot.W *= -1.f; // Animation system uses right-handed rotations? Argh... + irr::core::vector3df euler; + qrot.toEuler(euler); + euler *= core::RADTODEG; + node->setRotation(euler); + node->setScale(joint->Animatedscale); + } + else + { + node->setPosition(joint->LocalAnimatedMatrix.getTranslation()); + node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees()); + node->setScale(joint->LocalAnimatedMatrix.getScale()); + } node->positionHint=joint->positionHint; node->scaleHint=joint->scaleHint; From 9f9d22ca332c3aca65b53162da316f3dd0e3a58d Mon Sep 17 00:00:00 2001 From: cutealien Date: Sat, 15 Oct 2022 15:46:03 +0000 Subject: [PATCH 070/123] Fix some problems with CMatrix4::getRotationDegrees - Only the getRotationDegrees without parameter is allowed to try fixing scale. My fault when I added a new function which takes scale parameter, that one is not allowed to be changed. On the up-side - we know have for the first time an option which works in cases only scale and rotation had been used and the user still has the correct scale. Before any solution for that was broken - getRotationDegrees fixes 2 places which caused wrong results due to floating point inaccuracies New test for that got added - Document the current restrains and problems of getRotationDegrees and getScale some more. - Improve docs for other matrix4 functions. - Add some comments about further improvements (I'll try if I find time) Note: Irrlicht still assumes in at least 2 places (getting bone animations and Collada loader) that matrix decomposing works. Which it doesn't yet for matrices which switch handedness (or have further transformations like skewing axes) The bone animation is mostly fine for now with recent workaround (but that might cause other problems as it may be used too often), haven't checked Collada yet in detail. TL/DR: This improves things with getRotationDegrees, but does not yet fix all troubles. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6439 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/matrix4.h | 92 +++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/include/matrix4.h b/include/matrix4.h index e879c04c..1245546b 100644 --- a/include/matrix4.h +++ b/include/matrix4.h @@ -143,7 +143,7 @@ namespace core //! Set this matrix to the product of two matrices /** Calculate b*a, no optimization used, - use it if you know you never have a identity matrix */ + use it if you know you never have an identity matrix */ CMatrix4& setbyproduct_nocheck(const CMatrix4& other_a,const CMatrix4& other_b ); //! Multiply by another matrix. @@ -151,7 +151,8 @@ namespace core CMatrix4 operator*(const CMatrix4& other) const; //! Multiply by another matrix. - /** Calculate and return other*this */ + /** Like calling: (*this) = (*this) * other + */ CMatrix4& operator*=(const CMatrix4& other); //! Multiply by scalar. @@ -187,14 +188,25 @@ namespace core //! Make a rotation matrix from Euler angles. The 4th row and column are unmodified. CMatrix4& setRotationDegrees( const vector3d& rotation ); - //! Get the rotation, as set by setRotation() when you already know the scale. - /** If you already know the scale then this function is faster than the other getRotationDegrees overload. - NOTE: You will have the same end-rotation as used in setRotation, but it might not use the same axis values. + //! Get the rotation, as set by setRotation() when you already know the scale used to create the matrix + /** NOTE: The scale needs to be the correct one used to create this matrix. + You can _not_ use the result of getScale(), but have to save your scale + variable in another place (like ISceneNode does). + NOTE: No scale value can be 0 or the result is undefined. + NOTE: It does not necessarily return the *same* Euler angles as those set by setRotationDegrees(), + but the rotation will be equivalent, i.e. will have the same result when used to rotate a vector or node. + NOTE: It will (usually) give wrong results when further transformations have been added in the matrix (like shear). + WARNING: There have been troubles with this function over the years and we may still have missed some corner cases. + It's generally safer to keep the rotation and scale you used to create the matrix around and work with those. */ core::vector3d getRotationDegrees(const vector3d& scale) const; //! Returns the rotation, as set by setRotation(). /** NOTE: You will have the same end-rotation as used in setRotation, but it might not use the same axis values. + NOTE: This only works correct if no other matrix operations have been done on the inner 3x3 matrix besides + setting rotation (so no scale/shear). Thought it (probably) works as long as scale doesn't flip handedness. + NOTE: It does not necessarily return the *same* Euler angles as those set by setRotationDegrees(), + but the rotation will be equivalent, i.e. will have the same result when used to rotate a vector or node. */ core::vector3d getRotationDegrees() const; @@ -828,11 +840,9 @@ namespace core //! Returns the absolute values of the scales of the matrix. /** - Note that this returns the absolute (positive) values unless only scale is set. - Unfortunately it does not appear to be possible to extract any original negative - values. The best that we could do would be to arbitrarily make one scale - negative if one or three of them were negative. - FIXME - return the original values. + Note: You only get back original values if the matrix only set the scale. + Otherwise the result is a scale you can use to normalize the matrix axes, + but it's usually no longer what you did set with setScale. */ template inline vector3d CMatrix4::getScale() const @@ -895,33 +905,16 @@ namespace core } - //! Returns a rotation that is equivalent to that set by setRotationDegrees(). - /** This code was sent in by Chev. Note that it does not necessarily return - the *same* Euler angles as those set by setRotationDegrees(), but the rotation will - be equivalent, i.e. will have the same result when used to rotate a vector or node. - This code was originally written by by Chev. + //! Returns a rotation which (mostly) works in combination with the given scale + /** + This code was originally written by by Chev (assuming no scaling back then, + we can be blamed for all problems added by regarding scale) */ template inline core::vector3d CMatrix4::getRotationDegrees(const vector3d& scale_) const { const CMatrix4 &mat = *this; - core::vector3d scale(scale_); - // we need to check for negative scale on to axes, which would bring up wrong results - if (scale.Y<0 && scale.Z<0) - { - scale.Y =-scale.Y; - scale.Z =-scale.Z; - } - else if (scale.X<0 && scale.Z<0) - { - scale.X =-scale.X; - scale.Z =-scale.Z; - } - else if (scale.X<0 && scale.Y<0) - { - scale.X =-scale.X; - scale.Y =-scale.Y; - } + const core::vector3d scale(core::iszero(scale_.X) ? FLT_MAX : scale_.X , core::iszero(scale_.Y) ? FLT_MAX : scale_.Y, core::iszero(scale_.Z) ? FLT_MAX : scale_.Z); const core::vector3d invScale(core::reciprocal(scale.X),core::reciprocal(scale.Y),core::reciprocal(scale.Z)); f64 Y = -asin(core::clamp(mat[2]*invScale.X, -1.0, 1.0)); @@ -930,7 +923,7 @@ namespace core f64 rotx, roty, X, Z; - if (!core::iszero(C)) + if (!core::iszero((T)C)) { const f64 invC = core::reciprocal(C); rotx = mat[10] * invC * invScale.Z; @@ -957,14 +950,37 @@ namespace core } //! Returns a rotation that is equivalent to that set by setRotationDegrees(). - /** This code was sent in by Chev. Note that it does not necessarily return - the *same* Euler angles as those set by setRotationDegrees(), but the rotation will - be equivalent, i.e. will have the same result when used to rotate a vector or node. - This code was originally written by by Chev. */ template inline core::vector3d CMatrix4::getRotationDegrees() const { - return getRotationDegrees(getScale()); + // Note: Using getScale() here make it look like it could do matrix decomposition. + // It can't! It works (or should work) as long as rotation doesn't flip the handedness + // aka scale swapping 1 or 3 axes. (I think we could catch that as well by comparing + // crossproduct of first 2 axes to direction of third axis, but TODO) + // And maybe it should also offer the solution for the simple calculation + // without regarding scaling as Irrlicht did before 1.7 + core::vector3d scale(getScale()); + + // We assume the matrix uses rotations instead of negative scaling 2 axes. + // Otherwise it fails even for some simple cases, like rotating around + // 2 axes by 180° which getScale thinks is a negative scaling. + if (scale.Y<0 && scale.Z<0) + { + scale.Y =-scale.Y; + scale.Z =-scale.Z; + } + else if (scale.X<0 && scale.Z<0) + { + scale.X =-scale.X; + scale.Z =-scale.Z; + } + else if (scale.X<0 && scale.Y<0) + { + scale.X =-scale.X; + scale.Y =-scale.Y; + } + + return getRotationDegrees(scale); } From 6f3435f349e778af21f172d9c954e7cdb44efe7c Mon Sep 17 00:00:00 2001 From: cutealien Date: Sat, 19 Nov 2022 16:41:11 +0000 Subject: [PATCH 071/123] Prevent potential 0 pointer access when release not acquired joystick. Found by clang analyser. Not sure if it could really ever have happened, but won't hurt to fix git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6443 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CIrrDeviceWin32.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index 1033f9ed..7b12232c 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -121,8 +121,8 @@ namespace irr if (dev) { dev->Unacquire(); + dev->Release(); } - dev->Release(); } if (DirectInputDevice) From 9c2c91776eb067b505490df6d447bdd636ce0df6 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 22 Dec 2022 14:56:44 +0000 Subject: [PATCH 072/123] Fix spelling of enums in header comments git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6445 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IGUIComboBox.h | 4 ++-- include/IGUIStaticText.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/IGUIComboBox.h b/include/IGUIComboBox.h index 8d238341..4a7eda7e 100644 --- a/include/IGUIComboBox.h +++ b/include/IGUIComboBox.h @@ -54,9 +54,9 @@ namespace gui //! Sets text justification of the text area /** \param horizontal: EGUIA_UPPERLEFT for left justified (default), - EGUIA_LOWEERRIGHT for right justified, or EGUIA_CENTER for centered text. + EGUIA_LOWERRIGHT for right justified, or EGUIA_CENTER for centered text. \param vertical: EGUIA_UPPERLEFT to align with top edge, - EGUIA_LOWEERRIGHT for bottom edge, or EGUIA_CENTER for centered text (default). */ + EGUIA_LOWERRIGHT for bottom edge, or EGUIA_CENTER for centered text (default). */ virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) = 0; //! Set the maximal number of rows for the selection listbox diff --git a/include/IGUIStaticText.h b/include/IGUIStaticText.h index 33db281e..5d4f9ec7 100644 --- a/include/IGUIStaticText.h +++ b/include/IGUIStaticText.h @@ -88,9 +88,9 @@ namespace gui //! Sets text justification mode /** \param horizontal: EGUIA_UPPERLEFT for left justified (default), - EGUIA_LOWEERRIGHT for right justified, or EGUIA_CENTER for centered text. + EGUIA_LOWERRIGHT for right justified, or EGUIA_CENTER for centered text. \param vertical: EGUIA_UPPERLEFT to align with top edge (default), - EGUIA_LOWEERRIGHT for bottom edge, or EGUIA_CENTER for centered text. */ + EGUIA_LOWERRIGHT for bottom edge, or EGUIA_CENTER for centered text. */ virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) = 0; //! Enables or disables word wrap for using the static text as multiline text control. From 939b3f7bfb2a9dce8258003347d7d0a5132db844 Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 4 Jan 2023 19:51:24 +0000 Subject: [PATCH 073/123] Avoid undefined arithmetic on nullptr in buffer_offset function Not quite sure why it was done that way. Maybe to ensure we work with byte-pointers of correct size or something? Anyway, this doesn't seem to be defined in c++, so let's try working with a cast instead. Just something cppcheck tool complained about. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6447 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/COpenGLDriver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index b0f122b0..c213283b 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -746,10 +746,10 @@ IRenderTarget* COpenGLDriver::addRenderTarget() } -// small helper function to create vertex buffer object adress offsets -static inline u8* buffer_offset(const long offset) +// small helper function to create vertex buffer object address offsets +static inline const GLvoid * buffer_offset(const long offset) { - return ((u8*)0 + offset); + return (const GLvoid *)offset; } From c5373262ca1acff4f26b820d69d6c472634456ee Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 19 Jan 2023 23:26:20 +0000 Subject: [PATCH 074/123] Use qualifed id instead of virtual function calls in CVertexBuffer constructors Another find by cppcheck tool git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6448 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/CVertexBuffer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/CVertexBuffer.h b/include/CVertexBuffer.h index aa8049f3..7a913505 100644 --- a/include/CVertexBuffer.h +++ b/include/CVertexBuffer.h @@ -75,18 +75,18 @@ namespace scene CVertexBuffer(video::E_VERTEX_TYPE vertexType) : Vertices(0), MappingHint(EHM_NEVER), ChangedID(1) { - setType(vertexType); + CVertexBuffer::setType(vertexType); } CVertexBuffer(const IVertexBuffer &VertexBufferCopy) : Vertices(0), MappingHint(EHM_NEVER), ChangedID(1) { - setType(VertexBufferCopy.getType()); - reallocate(VertexBufferCopy.size()); + CVertexBuffer::setType(VertexBufferCopy.getType()); + CVertexBuffer::reallocate(VertexBufferCopy.size()); for (u32 n=0;n Date: Mon, 6 Mar 2023 14:34:16 +0000 Subject: [PATCH 075/123] Fix: Listbox was sometimes sending EGET_LISTBOX_SELECTED_AGAIN instead of EGET_LISTBOX_CHANGED. When pressed mouse was moved over an item before releasing the mouse button it was sending immediately EGET_LISTBOX_SELECTED_AGAIN instead of expected EGET_LISTBOX_CHANGED (mouse move changes do not send any events). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6454 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CGUIListBox.cpp | 38 ++++++++++++++++++++------------- source/Irrlicht/CGUIListBox.h | 3 ++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/source/Irrlicht/CGUIListBox.cpp b/source/Irrlicht/CGUIListBox.cpp index b00c7e38..cbd3ae5b 100644 --- a/source/Irrlicht/CGUIListBox.cpp +++ b/source/Irrlicht/CGUIListBox.cpp @@ -22,10 +22,10 @@ namespace gui CGUIListBox::CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle, bool clip, bool drawBack, bool moveOverSelect) -: IGUIListBox(environment, parent, id, rectangle), Selected(-1), +: IGUIListBox(environment, parent, id, rectangle), Selected(-1), HoverSelected(-1), ItemHeight(0),ItemHeightOverride(0), TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0), - ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack), + ScrollBar(0), SelectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack), MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true) { #ifdef _DEBUG @@ -116,7 +116,7 @@ void CGUIListBox::removeItem(u32 id) else if ((u32)Selected > id) { Selected -= 1; - selectTime = os::Timer::getTime(); + SelectTime = os::Timer::getTime(); } Items.erase(id); @@ -148,6 +148,7 @@ void CGUIListBox::clear() Items.clear(); ItemsIconWidth = 0; Selected = -1; + HoverSelected = -1; ScrollBar->setPos(0); @@ -192,7 +193,7 @@ void CGUIListBox::recalculateItemHeight() //! returns id of selected item. returns -1 if no item is selected. s32 CGUIListBox::getSelected() const { - return Selected; + return HoverSelected >= 0 ? HoverSelected : Selected; } @@ -204,7 +205,8 @@ void CGUIListBox::setSelected(s32 id) else Selected = id; - selectTime = os::Timer::getTime(); + HoverSelected = -1; + SelectTime = os::Timer::getTime(); recalculateScrollPos(); } @@ -454,14 +456,19 @@ void CGUIListBox::selectNew(s32 ypos, bool onlyHover) u32 now = os::Timer::getTime(); s32 oldSelected = Selected; - Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); - if (Selected<0 && !Items.empty()) - Selected = 0; + HoverSelected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); + if (HoverSelected<0 && !Items.empty()) + HoverSelected = 0; + if (!onlyHover) + { + Selected = HoverSelected; + HoverSelected = -1; + } recalculateScrollPos(); - gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < selectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED; - selectTime = now; + gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < SelectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED; + SelectTime = now; // post the news if (Parent && !onlyHover) { @@ -527,13 +534,14 @@ void CGUIListBox::draw() frameRect.LowerRightCorner.Y -= ScrollBar->getPos(); bool hl = (HighlightWhenNotFocused || Environment->hasFocus(this) || Environment->hasFocus(ScrollBar)); + const irr::s32 selected = getSelected(); for (s32 i=0; i<(s32)Items.size(); ++i) { if (frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y && frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y) { - if (i == Selected && hl) + if (i == selected && hl) skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), frameRect, &clientClip); core::rect textRect = frameRect; @@ -547,24 +555,24 @@ void CGUIListBox::draw() iconPos.Y += textRect.getHeight() / 2; iconPos.X += ItemsIconWidth/2; - if ( i==Selected && hl ) + if ( i==selected && hl ) { IconBank->draw2DSprite( (u32)Items[i].Icon, iconPos, &clientClip, hasItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) ? getItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_ICON_HIGHLIGHT), - selectTime, os::Timer::getTime(), false, true); + SelectTime, os::Timer::getTime(), false, true); } else { IconBank->draw2DSprite( (u32)Items[i].Icon, iconPos, &clientClip, hasItemOverrideColor(i, EGUI_LBC_ICON) ? getItemOverrideColor(i, EGUI_LBC_ICON) : getItemDefaultColor(EGUI_LBC_ICON), - 0 , (i==Selected) ? os::Timer::getTime() : 0, false, true); + 0 , (i==selected) ? os::Timer::getTime() : 0, false, true); } } textRect.UpperLeftCorner.X += ItemsIconWidth+3; - if ( i==Selected && hl ) + if ( i==selected && hl ) { Font->draw(Items[i].Text.c_str(), textRect, hasItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) ? diff --git a/source/Irrlicht/CGUIListBox.h b/source/Irrlicht/CGUIListBox.h index a3e7255a..37fffa84 100644 --- a/source/Irrlicht/CGUIListBox.h +++ b/source/Irrlicht/CGUIListBox.h @@ -154,6 +154,7 @@ namespace gui core::array< ListItem > Items; s32 Selected; + s32 HoverSelected; // When >= 0 we're in the middle of changing selection while mouse is pressed. We need to know so selected again isn't called too often. s32 ItemHeight; s32 ItemHeightOverride; s32 TotalItemHeight; @@ -161,7 +162,7 @@ namespace gui gui::IGUIFont* Font; gui::IGUISpriteBank* IconBank; gui::IGUIScrollBar* ScrollBar; - u32 selectTime; + u32 SelectTime; u32 LastKeyTime; core::stringw KeyBuffer; bool Selecting; From 53b9eaa83172478f9ddffb88d946801a1c57c8f0 Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 23 Aug 2022 17:19:23 +0200 Subject: [PATCH 076/123] Implement X11 primary selection --- include/IOSOperator.h | 13 +++- source/Irrlicht/CIrrDeviceLinux.cpp | 94 +++++++++++++++++++++-------- source/Irrlicht/CIrrDeviceLinux.h | 15 ++++- source/Irrlicht/COSOperator.cpp | 30 ++++++++- source/Irrlicht/COSOperator.h | 8 ++- 5 files changed, 128 insertions(+), 32 deletions(-) diff --git a/include/IOSOperator.h b/include/IOSOperator.h index b195aed7..6e5768aa 100644 --- a/include/IOSOperator.h +++ b/include/IOSOperator.h @@ -26,12 +26,23 @@ public: } //! Copies text to the clipboard + //! \param text: text in utf-8 virtual void copyToClipboard(const c8* text) const = 0; + //! Copies text to the primary selection + //! This is a no-op on some platforms. + //! \param text: text in utf-8 + virtual void copyToPrimarySelection(const c8* text) const = 0; + //! Get text from the clipboard - /** \return Returns 0 if no string is in there. */ + //! \return Returns 0 if no string is in there, otherwise an utf-8 string. virtual const c8* getTextFromClipboard() const = 0; + //! Get text from the primary selection + //! This is a no-op on some platforms. + //! \return Returns 0 if no string is in there, otherwise an utf-8 string. + virtual const c8* getTextFromPrimarySelection() const = 0; + //! Get the total and available system RAM /** \param totalBytes: will contain the total system memory in Kilobytes (1024 B) \param availableBytes: will contain the available memory in Kilobytes (1024 B) diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index 3c190991..0efc8f4f 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -1000,12 +1000,15 @@ bool CIrrDeviceLinux::run() send_response(req->property); }; - if (req->selection != X_ATOM_CLIPBOARD || + if ((req->selection != X_ATOM_CLIPBOARD && + req->selection != XA_PRIMARY) || req->owner != XWindow) { // we are not the owner, refuse request send_response_refuse(); break; } + const core::stringc &text_buffer = req->selection == X_ATOM_CLIPBOARD ? + Clipboard : PrimarySelection; // for debugging: //~ { @@ -1026,8 +1029,8 @@ bool CIrrDeviceLinux::run() req->target, X_ATOM_UTF8_STRING, 8, // format = 8-bit PropModeReplace, - (unsigned char *)Clipboard.c_str(), - Clipboard.size()); + (unsigned char *)text_buffer.c_str(), + text_buffer.size()); send_response(req->target); break; } @@ -1052,8 +1055,8 @@ bool CIrrDeviceLinux::run() set_property_and_notify( X_ATOM_UTF8_STRING, 8, - Clipboard.c_str(), - Clipboard.size() + text_buffer.c_str(), + text_buffer.size() ); } else { @@ -1676,47 +1679,49 @@ void CIrrDeviceLinux::pollJoysticks() } +#if defined(_IRR_COMPILE_WITH_X11_) //! gets text from the clipboard //! \return Returns 0 if no string is in there, otherwise utf-8 text. -const c8 *CIrrDeviceLinux::getTextFromClipboard() const +const c8 *CIrrDeviceLinux::getTextFromSelection(Atom selection, core::stringc &text_buffer) const { -#if defined(_IRR_COMPILE_WITH_X11_) - Window ownerWindow = XGetSelectionOwner(XDisplay, X_ATOM_CLIPBOARD); + Window ownerWindow = XGetSelectionOwner(XDisplay, selection); if (ownerWindow == XWindow) { - return Clipboard.c_str(); + return text_buffer.c_str(); } - Clipboard = ""; + text_buffer = ""; if (ownerWindow == None) { - return Clipboard.c_str(); + return text_buffer.c_str(); } // delete the property to be set beforehand XDeleteProperty(XDisplay, XWindow, XA_PRIMARY); - XConvertSelection(XDisplay, X_ATOM_CLIPBOARD, X_ATOM_UTF8_STRING, XA_PRIMARY, + XConvertSelection(XDisplay, selection, X_ATOM_UTF8_STRING, XA_PRIMARY, XWindow, CurrentTime); XFlush(XDisplay); // wait for event via a blocking call XEvent event_ret; + std::pair args(XWindow, selection); XIfEvent(XDisplay, &event_ret, [](Display *_display, XEvent *event, XPointer arg) { + auto p = reinterpret_cast *>(arg); return (Bool) (event->type == SelectionNotify && - event->xselection.requestor == *(Window *)arg && - event->xselection.selection == X_ATOM_CLIPBOARD && + event->xselection.requestor == p->first && + event->xselection.selection == p->second && event->xselection.target == X_ATOM_UTF8_STRING); - }, (XPointer)&XWindow); + }, (XPointer)&args); _IRR_DEBUG_BREAK_IF(!(event_ret.type == SelectionNotify && event_ret.xselection.requestor == XWindow && - event_ret.xselection.selection == X_ATOM_CLIPBOARD && + event_ret.xselection.selection == selection && event_ret.xselection.target == X_ATOM_UTF8_STRING)); Atom property_set = event_ret.xselection.property; if (event_ret.xselection.property == None) { // request failed => empty string - return Clipboard.c_str(); + return text_buffer.c_str(); } // check for data @@ -1743,15 +1748,15 @@ const c8 *CIrrDeviceLinux::getTextFromClipboard() const // for debugging: //~ { //~ char *type_name = XGetAtomName(XDisplay, type); - //~ fprintf(stderr, "CIrrDeviceLinux::getTextFromClipboard: actual type: %s (=%ld)\n", + //~ fprintf(stderr, "CIrrDeviceLinux::getTextFromSelection: actual type: %s (=%ld)\n", //~ type_name, type); //~ XFree(type_name); //~ } if (type != X_ATOM_UTF8_STRING && type != X_ATOM_UTF8_MIME_TYPE) { - os::Printer::log("CIrrDeviceLinux::getTextFromClipboard: did not get utf-8 string", + os::Printer::log("CIrrDeviceLinux::getTextFromSelection: did not get utf-8 string", ELL_WARNING); - return Clipboard.c_str(); + return text_buffer.c_str(); } if (bytesLeft > 0) { @@ -1760,20 +1765,49 @@ const c8 *CIrrDeviceLinux::getTextFromClipboard() const bytesLeft, 0, AnyPropertyType, &type, &format, &numItems, &dummy, &data); if (result == Success) - Clipboard = (irr::c8 *)data; + text_buffer = (irr::c8 *)data; XFree (data); } // delete the property again, to inform the owner about the successful transfer XDeleteProperty(XDisplay, XWindow, property_set); - return Clipboard.c_str(); + return text_buffer.c_str(); +} +#endif +//! gets text from the clipboard +//! \return Returns 0 if no string is in there, otherwise utf-8 text. +const c8 *CIrrDeviceLinux::getTextFromClipboard() const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + return getTextFromSelection(X_ATOM_CLIPBOARD, Clipboard); #else return nullptr; #endif } +//! gets text from the primary selection +//! \return Returns 0 if no string is in there, otherwise utf-8 text. +const c8 *CIrrDeviceLinux::getTextFromPrimarySelection() const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + return getTextFromSelection(XA_PRIMARY, PrimarySelection); +#else + return nullptr; +#endif +} + +#if defined(_IRR_COMPILE_WITH_X11_) +bool CIrrDeviceLinux::becomeSelectionOwner(Atom selection) const +{ + XSetSelectionOwner (XDisplay, selection, XWindow, CurrentTime); + XFlush (XDisplay); + Window owner = XGetSelectionOwner(XDisplay, selection); + return owner == XWindow; +} +#endif + //! copies text to the clipboard void CIrrDeviceLinux::copyToClipboard(const c8 *text) const { @@ -1781,15 +1815,23 @@ void CIrrDeviceLinux::copyToClipboard(const c8 *text) const // Actually there is no clipboard on X but applications just say they own the clipboard and return text when asked. // Which btw. also means that on X you lose clipboard content when closing applications. Clipboard = text; - XSetSelectionOwner (XDisplay, X_ATOM_CLIPBOARD, XWindow, CurrentTime); - XFlush (XDisplay); - Window owner = XGetSelectionOwner(XDisplay, X_ATOM_CLIPBOARD); - if (owner != XWindow) { + if (!becomeSelectionOwner(X_ATOM_CLIPBOARD)) { os::Printer::log("CIrrDeviceLinux::copyToClipboard: failed to set owner", ELL_WARNING); } #endif } +//! copies text to the primary selection +void CIrrDeviceLinux::copyToPrimarySelection(const c8 *text) const +{ +#if defined(_IRR_COMPILE_WITH_X11_) + PrimarySelection = text; + if (!becomeSelectionOwner(XA_PRIMARY)) { + os::Printer::log("CIrrDeviceLinux::copyToPrimarySelection: failed to set owner", ELL_WARNING); + } +#endif +} + #ifdef _IRR_COMPILE_WITH_X11_ // return true if the passed event has the type passed in parameter arg Bool PredicateIsEventType(Display *display, XEvent *event, XPointer arg) diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index 2d8945c9..544a7364 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -97,11 +97,20 @@ namespace irr //! \return Returns 0 if no string is in there, otherwise utf-8 text. virtual const c8 *getTextFromClipboard() const; + //! gets text from the primary selection + //! \return Returns 0 if no string is in there, otherwise utf-8 text. + virtual const c8 *getTextFromPrimarySelection() const; + //! copies text to the clipboard - //! This sets the clipboard selection and _not_ the primary selection which you have on X on the middle mouse button. + //! This sets the clipboard selection and _not_ the primary selection. //! @param text The text in utf-8 virtual void copyToClipboard(const c8 *text) const; + //! copies text to the primary selection + //! This sets the primary selection which you have on X on the middle mouse button. + //! @param text The text in utf-8 + virtual void copyToPrimarySelection(const c8 *text) const; + //! Remove all messages pending in the system message loop void clearSystemMessages() override; @@ -141,6 +150,9 @@ namespace irr bool createInputContext(); void destroyInputContext(); EKEY_CODE getKeyCode(XEvent &event); + + const c8 *getTextFromSelection(Atom selection, core::stringc &text_buffer) const; + bool becomeSelectionOwner(Atom selection) const; #endif //! Implementation of the linux cursor control @@ -413,6 +425,7 @@ namespace irr bool HasNetWM; // text is utf-8 mutable core::stringc Clipboard; + mutable core::stringc PrimarySelection; #endif #if defined(_IRR_LINUX_X11_XINPUT2_) int currentTouchedCount; diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp index 25b04ad8..906035aa 100644 --- a/source/Irrlicht/COSOperator.cpp +++ b/source/Irrlicht/COSOperator.cpp @@ -54,7 +54,6 @@ const core::stringc& COSOperator::getOperatingSystemVersion() const //! copies text to the clipboard -//! \param text: text in utf-8 void COSOperator::copyToClipboard(const c8 *text) const { if (strlen(text)==0) @@ -102,8 +101,20 @@ void COSOperator::copyToClipboard(const c8 *text) const } +//! copies text to the primary selection +void COSOperator::copyToPrimarySelection(const c8 *text) const +{ + if (strlen(text)==0) + return; + +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if ( IrrDeviceLinux ) + IrrDeviceLinux->copyToPrimarySelection(text); +#endif +} + + //! gets text from the clipboard -//! \return Returns 0 if no string is in there, otherwise an utf-8 string. const c8* COSOperator::getTextFromClipboard() const { #if defined(_IRR_WINDOWS_API_) @@ -147,6 +158,21 @@ const c8* COSOperator::getTextFromClipboard() const } +//! gets text from the primary selection +const c8* COSOperator::getTextFromPrimarySelection() const +{ +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if ( IrrDeviceLinux ) + return IrrDeviceLinux->getTextFromPrimarySelection(); + return 0; + +#else + + return 0; +#endif +} + + bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const { #if defined(_IRR_WINDOWS_API_) diff --git a/source/Irrlicht/COSOperator.h b/source/Irrlicht/COSOperator.h index 6ef0f9ba..6510579e 100644 --- a/source/Irrlicht/COSOperator.h +++ b/source/Irrlicht/COSOperator.h @@ -27,13 +27,17 @@ public: const core::stringc& getOperatingSystemVersion() const override; //! copies text to the clipboard - //! \param text: text in utf-8 void copyToClipboard(const c8 *text) const override; + //! copies text to the primary selection + void copyToPrimarySelection(const c8 *text) const override; + //! gets text from the clipboard - //! \return Returns 0 if no string is in there, otherwise an utf-8 string. const c8* getTextFromClipboard() const override; + //! gets text from the primary selection + const c8* getTextFromPrimarySelection() const override; + //! gets the total and available system RAM in kB //! \param Total: will contain the total system memory //! \param Avail: will contain the available memory From d86abb40c1276ec74c72caef664d8efe3915c190 Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 23 Aug 2022 18:55:08 +0200 Subject: [PATCH 077/123] CGUIEditBox: Use primary selection This is essentially the same as the commit in the minetest repo for GUIEditBox. --- source/Irrlicht/CGUIEditBox.cpp | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/source/Irrlicht/CGUIEditBox.cpp b/source/Irrlicht/CGUIEditBox.cpp index cf4b64ee..24b8099a 100644 --- a/source/Irrlicht/CGUIEditBox.cpp +++ b/source/Irrlicht/CGUIEditBox.cpp @@ -1135,6 +1135,34 @@ bool CGUIEditBox::processMouse(const SEvent& event) return true; } } + case EMIE_MMOUSE_PRESSED_DOWN: { + if (!AbsoluteClippingRect.isPointInside(core::position2d( + event.MouseInput.X, event.MouseInput.Y))) + return false; + + if (!Environment->hasFocus(this)) { + BlinkStartTime = os::Timer::getTime(); + } + + // move cursor and disable marking + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + MouseMarking = false; + setTextMarkers(CursorPos, CursorPos); + + // paste from the primary selection + inputString([&] { + irr::core::stringw inserted_text; + if (!Operator) + return inserted_text; + const c8 *inserted_text_utf8 = Operator->getTextFromPrimarySelection(); + if (!inserted_text_utf8) + return inserted_text; + core::multibyteToWString(inserted_text, inserted_text_utf8); + return inserted_text; + }()); + + return true; + } default: break; } @@ -1624,6 +1652,17 @@ void CGUIEditBox::setTextMarkers(s32 begin, s32 end) { MarkBegin = begin; MarkEnd = end; + + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { + // copy to primary selection + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + core::stringc s; + wStringToMultibyte(s, Text.subString(realmbgn, realmend - realmbgn)); + Operator->copyToPrimarySelection(s.c_str()); + } + sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); } } From 8da1bcf58bd8ff4d08d93c26599f8e22e68a8df4 Mon Sep 17 00:00:00 2001 From: Desour Date: Wed, 14 Sep 2022 20:38:49 +0200 Subject: [PATCH 078/123] SDL: Support clipboard --- source/Irrlicht/COSOperator.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp index 906035aa..4f441786 100644 --- a/source/Irrlicht/COSOperator.cpp +++ b/source/Irrlicht/COSOperator.cpp @@ -17,7 +17,9 @@ #endif #endif -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#include +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) #include "CIrrDeviceLinux.h" #endif #if defined(_IRR_COMPILE_WITH_OSX_DEVICE_) @@ -59,8 +61,10 @@ void COSOperator::copyToClipboard(const c8 *text) const if (strlen(text)==0) return; -// Windows version -#if defined(_IRR_WINDOWS_API_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + SDL_SetClipboardText(text); + +#elif defined(_IRR_WINDOWS_API_) if (!OpenClipboard(NULL) || text == 0) return; @@ -117,7 +121,14 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const //! gets text from the clipboard const c8* COSOperator::getTextFromClipboard() const { -#if defined(_IRR_WINDOWS_API_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + static char *text = nullptr; + if (text) + SDL_free(text); + text = SDL_GetClipboardText(); + return text; + +#elif defined(_IRR_WINDOWS_API_) if (!OpenClipboard(NULL)) return 0; From 799c8b936f9a2cc4f3a8bc56237fb9a8dedf853e Mon Sep 17 00:00:00 2001 From: Desour Date: Wed, 14 Sep 2022 22:48:06 +0200 Subject: [PATCH 079/123] SDL: Support primary selection Requires SDL >= 2.25.0 (newest master). --- source/Irrlicht/COSOperator.cpp | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp index 4f441786..132232fe 100644 --- a/source/Irrlicht/COSOperator.cpp +++ b/source/Irrlicht/COSOperator.cpp @@ -19,6 +19,7 @@ #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #include +#include #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) #include "CIrrDeviceLinux.h" #endif @@ -28,6 +29,19 @@ #include "fast_atof.h" +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +static bool sdl_supports_primary_selection = [] { +#if SDL_VERSION_ATLEAST(2, 25, 0) + SDL_version linked_version; + SDL_GetVersion(&linked_version); + return (linked_version.major == 2 && linked_version.minor >= 25) + || linked_version.major > 2; +#else + return false; +#endif +}(); +#endif + namespace irr { @@ -111,7 +125,13 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const if (strlen(text)==0) return; -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#if SDL_VERSION_ATLEAST(2, 25, 0) + if (sdl_supports_primary_selection) + SDL_SetPrimarySelectionText(text); +#endif + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) if ( IrrDeviceLinux ) IrrDeviceLinux->copyToPrimarySelection(text); #endif @@ -172,7 +192,19 @@ const c8* COSOperator::getTextFromClipboard() const //! gets text from the primary selection const c8* COSOperator::getTextFromPrimarySelection() const { -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) +#if SDL_VERSION_ATLEAST(2, 25, 0) + if (sdl_supports_primary_selection) { + static char *text = nullptr; + if (text) + SDL_free(text); + text = SDL_GetPrimarySelectionText(); + return text; + } +#endif + return 0; + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) if ( IrrDeviceLinux ) return IrrDeviceLinux->getTextFromPrimarySelection(); return 0; From 28d0e0644cea3ba03f52980be26f5b178d13561f Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 25 Mar 2023 11:05:40 +0300 Subject: [PATCH 080/123] 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 00000000..01c94d78 --- /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 00000000..895625f5 --- /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 00000000..74e9df19 --- /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 00000000..c348016c --- /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 00000000..bdc3c668 --- /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 00000000..aafac22b --- /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 00000000..89aef7e5 --- /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 00000000..91421489 --- /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 00000000..60009723 --- /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 00000000..df1010e6 --- /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 00000000..98d0daef --- /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 00000000..c49ecfc4 --- /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 00000000..3c8a39dd --- /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 00000000..df1010e6 --- /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 00000000..5062d795 --- /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 00000000..cef349a4 --- /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 00000000..fab4eeea --- /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 00000000..df1010e6 --- /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 081/123] 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 a69bcc62..4069307c 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 9baefc29..641536fc 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 e95a633c..06907b7a 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 055738b9..b9cb75a1 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 1e6bd7f0..6fb47b8b 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 bcf99ac6..29224709 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 4a9bb95b..aea935fa 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 20d684c8..d7aa4837 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 dbac6cf6..f9282ccb 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 8bedb179..96bdbda2 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 806d1e7c..426a8b77 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 082/123] 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 ad11dd45..6d870697 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 a67f3003de693998ab3ec9864383d7155175c353 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Mar 2023 14:07:42 +0200 Subject: [PATCH 083/123] Revert "Avoid some broken calculations for IBoneSceneNode positions." This was reported to cause broken models in some cases. reverts commit edb381bd5050712d1eb8875fe3a405000dd09a3d --- source/Irrlicht/CSkinnedMesh.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index 07e86d6b..75e2ca64 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -1347,24 +1347,9 @@ void CSkinnedMesh::recoverJointsFromMesh(core::array &jointChil { IBoneSceneNode* node=jointChildSceneNodes[i]; SJoint *joint=AllJoints[i]; - - if ( joint->UseAnimationFrom ) // Seems to work better (else solution seems to mess up sometimes) and would be faster. Any disadvantage? - { - node->setPosition(joint->Animatedposition); - core::quaternion qrot = joint->Animatedrotation; - qrot.W *= -1.f; // Animation system uses right-handed rotations? Argh... - irr::core::vector3df euler; - qrot.toEuler(euler); - euler *= core::RADTODEG; - node->setRotation(euler); - node->setScale(joint->Animatedscale); - } - else - { - node->setPosition(joint->LocalAnimatedMatrix.getTranslation()); - node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees()); - node->setScale(joint->LocalAnimatedMatrix.getScale()); - } + node->setPosition(joint->LocalAnimatedMatrix.getTranslation()); + node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees()); + node->setScale(joint->LocalAnimatedMatrix.getScale()); node->positionHint=joint->positionHint; node->scaleHint=joint->scaleHint; From ba1cd19983f9a5d6824aa0fcf0714bc102699cc9 Mon Sep 17 00:00:00 2001 From: DS Date: Sun, 26 Mar 2023 14:13:58 +0200 Subject: [PATCH 084/123] Use non-static member vars for SDL clipboard / primary selection buffers --- source/Irrlicht/COSOperator.cpp | 33 +++++++++++++++++++-------------- source/Irrlicht/COSOperator.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp index 132232fe..1c3baf90 100644 --- a/source/Irrlicht/COSOperator.cpp +++ b/source/Irrlicht/COSOperator.cpp @@ -30,7 +30,7 @@ #include "fast_atof.h" #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) -static bool sdl_supports_primary_selection = [] { +static const bool sdl_supports_primary_selection = [] { #if SDL_VERSION_ATLEAST(2, 25, 0) SDL_version linked_version; SDL_GetVersion(&linked_version); @@ -62,6 +62,15 @@ COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVer } +COSOperator::~COSOperator() +{ +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + SDL_free(ClipboardSelectionText); + SDL_free(PrimarySelectionText); +#endif +} + + //! returns the current operating system version as string. const core::stringc& COSOperator::getOperatingSystemVersion() const { @@ -142,11 +151,9 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const const c8* COSOperator::getTextFromClipboard() const { #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) - static char *text = nullptr; - if (text) - SDL_free(text); - text = SDL_GetClipboardText(); - return text; + SDL_free(ClipboardSelectionText); + ClipboardSelectionText = SDL_GetClipboardText(); + return ClipboardSelectionText; #elif defined(_IRR_WINDOWS_API_) if (!OpenClipboard(NULL)) @@ -195,19 +202,17 @@ const c8* COSOperator::getTextFromPrimarySelection() const #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #if SDL_VERSION_ATLEAST(2, 25, 0) if (sdl_supports_primary_selection) { - static char *text = nullptr; - if (text) - SDL_free(text); - text = SDL_GetPrimarySelectionText(); - return text; + SDL_free(PrimarySelectionText); + PrimarySelectionText = SDL_GetPrimarySelectionText(); + return PrimarySelectionText; } #endif return 0; #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - if ( IrrDeviceLinux ) - return IrrDeviceLinux->getTextFromPrimarySelection(); - return 0; + if ( IrrDeviceLinux ) + return IrrDeviceLinux->getTextFromPrimarySelection(); + return 0; #else diff --git a/source/Irrlicht/COSOperator.h b/source/Irrlicht/COSOperator.h index 6510579e..941dacc1 100644 --- a/source/Irrlicht/COSOperator.h +++ b/source/Irrlicht/COSOperator.h @@ -23,6 +23,11 @@ public: #endif COSOperator(const core::stringc& osversion); + ~COSOperator(); + + COSOperator(const COSOperator &) = delete; + COSOperator &operator=(const COSOperator &) = delete; + //! returns the current operation system version as string. const core::stringc& getOperatingSystemVersion() const override; @@ -56,6 +61,12 @@ private: mutable core::stringc ClipboardBuf; #endif +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + // These need to be freed with SDL_free + mutable char *ClipboardSelectionText = nullptr; + mutable char *PrimarySelectionText = nullptr; +#endif + }; } // end namespace From 58a96b7d2399ede5e953518b784ecffd4751b765 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 2 Apr 2023 22:12:46 +0300 Subject: [PATCH 085/123] Mark the repo as root in the editorconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Necessary due to CR/LF mess, it shouldn’t inherit the LF setting from Minetest. --- .editorconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.editorconfig b/.editorconfig index 379fba40..080ba5b5 100755 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,5 @@ +root = true + [*] charset = utf-8 From 70ee4b05aa4a78809552e6bc6c3ff7cfe6c012af Mon Sep 17 00:00:00 2001 From: numzero Date: Wed, 5 Apr 2023 22:52:43 +0300 Subject: [PATCH 086/123] 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 6d870697..4d7141eb 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 From f5d3448b171be983280fc67ce911bfbf0bd42ff0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Apr 2023 11:35:30 +0200 Subject: [PATCH 087/123] Document new CMake options --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0d17e194..a0c496c6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,11 @@ The following libraries are required to be installed: Aside from standard search options (`ZLIB_INCLUDE_DIR`, `ZLIB_LIBRARY`, ...) the following options are available: * `BUILD_SHARED_LIBS` (default: `ON`) - Build IrrlichtMt as a shared library * `BUILD_EXAMPLES` (default: `OFF`) - Build example applications +* `ENABLE_OPENGL` - Enable OpenGL driver +* `ENABLE_OPENGL3` (default: `OFF`) - Enable OpenGL 3+ driver +* `ENABLE_GLES1` - Enable OpenGL ES driver, legacy +* `ENABLE_GLES2` - Enable OpenGL ES 2+ driver +* `USE_SDL2` (default: `OFF`) - Use SDL2 instead of native platform device e.g. on a Linux system you might want to build for local use like this: From a677f5a01ac428d16e0e83b021dd0e8cb1ee9f53 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Apr 2023 11:41:12 +0200 Subject: [PATCH 088/123] Only try to link libraries when relevant feature is enabled fixes #182 --- source/Irrlicht/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 4d7141eb..f2a3b5fd 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -277,7 +277,7 @@ elseif(APPLE) find_library(IOKIT_LIB IOKit REQUIRED) add_definitions(-DGL_SILENCE_DEPRECATION) -else() +elseif(NOT USE_SDL2) # Unix probably find_package(X11 REQUIRED) if(USE_XINPUT2 AND NOT X11_Xi_FOUND) @@ -292,21 +292,21 @@ set(link_includes "${ZLIB_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${PNG_INCLUDE_DIR}" - "${SDL2_INCLUDE_DIRS}" + "$<$:${SDL2_INCLUDE_DIRS}>" ${OPENGL_INCLUDE_DIR} ${OPENGLES2_INCLUDE_DIR} ${EGL_INCLUDE_DIR} "$<$:${ANDROID_NDK}/sources/android/native_app_glue>" - ${X11_INCLUDE_DIR} + "$<$:${X11_INCLUDE_DIR}>" ) set(link_libs "${ZLIB_LIBRARY}" "${JPEG_LIBRARY}" "${PNG_LIBRARY}" - "${SDL2_LIBRARIES}" + "$<$:${SDL2_LIBRARIES}>" ${OPENGL_LIBRARIES} ${OPENGLES_LIBRARY} @@ -318,8 +318,8 @@ set(link_libs ${IOKIT_LIB} "$<$:gdi32>" "$<$:winmm>" - ${X11_X11_LIB} - ${X11_Xi_LIB} + "$<$:${X11_X11_LIB}>" + "$<$:${X11_Xi_LIB}>" ) # Source files From e850bd102a238865c09525c1a0511384d110817b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Apr 2023 11:58:18 +0200 Subject: [PATCH 089/123] Minor adjustments to configuration flow --- source/Irrlicht/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index f2a3b5fd..686b0d29 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -70,7 +70,7 @@ endif() add_definitions( -DIRR_ENABLE_BUILTIN_FONT -D_IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ - ) +) # Platform-specific configuration @@ -89,7 +89,7 @@ elseif(APPLE) elseif(ANDROID) add_definitions(-D_IRR_ANDROID_PLATFORM_ -D_IRR_COMPILE_ANDROID_ASSET_READER_) if(USE_SDL2) - message(SEND_ERROR "SDL2 backend is not supported on Android") + message(FATAL_ERROR "SDL2 device is not (yet) supported on Android") endif() set(DEVICE "Android") elseif(EMSCRIPTEN) @@ -111,6 +111,8 @@ endif() if(USE_SDL2) set(DEVICE "SDL") +elseif(DEVICE STREQUAL "SDL") + message(FATAL_ERROR "SDL was used but not enabled?!") endif() add_definitions("-D_IRR_COMPILE_WITH_${DEVICE}_DEVICE_") @@ -188,7 +190,7 @@ endif() if(ENABLE_OPENGL3) if (NOT USE_SDL2) - message(SEND_ERROR "OpenGL3 support requires SDL2") + message(FATAL_ERROR "OpenGL 3 driver requires SDL2") endif() set(USE_SDLGL ON) set(USE_SDLGL3 ON) @@ -196,7 +198,7 @@ endif() if(ENABLE_GLES1) if (USE_SDL2) - message(SEND_ERROR "OpenGL ES 1 is not supported with SDL2") + message(FATAL_ERROR "OpenGL ES 1 is not supported with SDL2") endif() add_definitions(-D_IRR_COMPILE_WITH_OGLES1_) if(DEVICE MATCHES "^(WINDOWS|X11|ANDROID)$") @@ -230,7 +232,7 @@ endif() message(STATUS "Device: ${DEVICE}") message(STATUS "OpenGL: ${ENABLE_OPENGL}") -message(STATUS "OpenGL 3: ${USE_SDLGL3}") +message(STATUS "OpenGL 3: ${ENABLE_OPENGL3}") message(STATUS "OpenGL ES: ${ENABLE_GLES1}") if (USE_SDLGLES2) message(STATUS "OpenGL ES 2: ON (unified)") From ca5f005b74a20d7e188df2c981130dbd47a93244 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Apr 2023 12:07:53 +0200 Subject: [PATCH 090/123] Fix OpenGL3 driver to compile standalone also test this configuration in CI --- .github/workflows/build.yml | 6 +++--- source/Irrlicht/CMakeLists.txt | 2 +- source/Irrlicht/COpenGLCoreCacheHandler.h | 3 --- source/Irrlicht/COpenGLCoreFeature.h | 3 --- source/Irrlicht/COpenGLCoreRenderTarget.h | 3 --- source/Irrlicht/COpenGLCoreTexture.h | 3 --- source/Irrlicht/CSDLManager.cpp | 4 +--- source/Irrlicht/CSDLManager.h | 2 +- 8 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2cf7d603..4ae889f4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,7 +97,7 @@ jobs: - name: Build run: | - cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON -DENABLE_OPENGL3=ON + cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON -DENABLE_OPENGL=OFF -DENABLE_OPENGL3=ON make -j2 - name: Test (headless) @@ -124,7 +124,7 @@ jobs: - name: Build run: | - cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON -DENABLE_GLES2=ON + cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON -DENABLE_OPENGL=OFF -DENABLE_GLES2=ON make -j2 - name: Test (headless) @@ -135,7 +135,7 @@ jobs: - name: Test (Xvfb) run: | cd bin/Linux - LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest gles2 + LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest ogles2 win32: runs-on: ubuntu-20.04 diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 686b0d29..278622ba 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -260,7 +260,7 @@ endif() if(ENABLE_GLES2) find_package(OpenGLES2 REQUIRED) endif() -if(ENABLE_OPENGL) +if(ENABLE_OPENGL OR ENABLE_OPENGL3) set(OpenGL_GL_PREFERENCE "LEGACY") find_package(OpenGL REQUIRED) endif() diff --git a/source/Irrlicht/COpenGLCoreCacheHandler.h b/source/Irrlicht/COpenGLCoreCacheHandler.h index 79b28007..ebe0a193 100644 --- a/source/Irrlicht/COpenGLCoreCacheHandler.h +++ b/source/Irrlicht/COpenGLCoreCacheHandler.h @@ -6,8 +6,6 @@ #define __C_OGLCORE_CACHE_HANDLER_H_INCLUDED__ -#if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) - #include "SMaterial.h" #include "ITexture.h" @@ -643,4 +641,3 @@ protected: } #endif -#endif diff --git a/source/Irrlicht/COpenGLCoreFeature.h b/source/Irrlicht/COpenGLCoreFeature.h index fe86f955..fa930bd0 100644 --- a/source/Irrlicht/COpenGLCoreFeature.h +++ b/source/Irrlicht/COpenGLCoreFeature.h @@ -6,8 +6,6 @@ #define __C_OGLCORE_FEATURE_H_INCLUDED__ -#if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) - #include "irrTypes.h" namespace irr @@ -37,4 +35,3 @@ public: } #endif -#endif diff --git a/source/Irrlicht/COpenGLCoreRenderTarget.h b/source/Irrlicht/COpenGLCoreRenderTarget.h index f893c174..f96fb87d 100644 --- a/source/Irrlicht/COpenGLCoreRenderTarget.h +++ b/source/Irrlicht/COpenGLCoreRenderTarget.h @@ -6,8 +6,6 @@ #define __C_OGLCORE_RENDER_TARGET_H_INCLUDED__ -#if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) - #include "IRenderTarget.h" #ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS @@ -400,4 +398,3 @@ protected: } #endif -#endif diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index 2ad8af12..15a827e9 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -6,8 +6,6 @@ #define __C_OGLCORE_TEXTURE_H_INCLUDED__ -#if defined(_IRR_COMPILE_WITH_OPENGL_) || defined(_IRR_COMPILE_WITH_OGLES1_) || defined(_IRR_COMPILE_WITH_OGLES2_) - #include "irrArray.h" #include "SMaterialLayer.h" #include "ITexture.h" @@ -666,4 +664,3 @@ protected: } #endif -#endif diff --git a/source/Irrlicht/CSDLManager.cpp b/source/Irrlicht/CSDLManager.cpp index 3132b60a..b8c61a4d 100644 --- a/source/Irrlicht/CSDLManager.cpp +++ b/source/Irrlicht/CSDLManager.cpp @@ -4,7 +4,7 @@ #include "CSDLManager.h" -#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && defined(_IRR_COMPILE_WITH_OPENGL_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #include "CIrrDeviceSDL.h" #include "COpenGLCommon.h" @@ -34,8 +34,6 @@ const SExposedVideoData& CSDLManager::getContext() const bool CSDLManager::activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero) { - // unclear if this is still needed: - glFrontFace(GL_CW); return true; } diff --git a/source/Irrlicht/CSDLManager.h b/source/Irrlicht/CSDLManager.h index 3d9648c6..f1472424 100644 --- a/source/Irrlicht/CSDLManager.h +++ b/source/Irrlicht/CSDLManager.h @@ -6,7 +6,7 @@ #define __C_SDL_MANAGER_H_INCLUDED__ -#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && defined(_IRR_COMPILE_WITH_OPENGL_) +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #include "IContextManager.h" From 36a3a7f349d6fe1755d89a25cfa5bd359b6995ae Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Apr 2023 12:10:29 +0200 Subject: [PATCH 091/123] Don't compile unused driver sources --- source/Irrlicht/CMakeLists.txt | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 278622ba..3aa3f5f3 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -353,13 +353,6 @@ add_library(IRROBJ OBJECT set(IRRDRVROBJ CNullDriver.cpp - COpenGLCacheHandler.cpp - COpenGLDriver.cpp - COpenGLShaderMaterialRenderer.cpp - COpenGLSLMaterialRenderer.cpp - COpenGLExtensionHandler.cpp - COGLESDriver.cpp - COGLESExtensionHandler.cpp CGLXManager.cpp CWGLManager.cpp CEGLManager.cpp @@ -367,6 +360,25 @@ set(IRRDRVROBJ mt_opengl_loader.cpp ) +if(ENABLE_OPENGL) + set(IRRDRVROBJ + ${IRRDRVROBJ} + COpenGLCacheHandler.cpp + COpenGLDriver.cpp + COpenGLShaderMaterialRenderer.cpp + COpenGLSLMaterialRenderer.cpp + COpenGLExtensionHandler.cpp + ) +endif() + +if(ENABLE_GLES1) + set(IRRDRVROBJ + ${IRRDRVROBJ} + COGLESDriver.cpp + COGLESExtensionHandler.cpp + ) +endif() + set(IRRIMAGEOBJ CColorConverter.cpp CImage.cpp @@ -404,7 +416,7 @@ if(USE_SDLGLES2) target_sources(IRRVIDEOOBJ PRIVATE OpenGLES2/Driver.cpp ) -else() +elseif(ENABLE_GLES2) target_sources(IRRVIDEOOBJ PRIVATE COGLES2Driver.cpp COGLES2ExtensionHandler.cpp From 54314691ec17f0fa4700bf6fbd4925f25ac81021 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Apr 2023 15:00:12 +0200 Subject: [PATCH 092/123] Fix mistake in a677f5a01ac428d16e0e83b021dd0e8cb1ee9f53 --- source/Irrlicht/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 3aa3f5f3..0bb71e3b 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -308,7 +308,7 @@ set(link_libs "${ZLIB_LIBRARY}" "${JPEG_LIBRARY}" "${PNG_LIBRARY}" - "$<$:${SDL2_LIBRARIES}>" + "$<$:${SDL2_LIBRARIES}>" ${OPENGL_LIBRARIES} ${OPENGLES_LIBRARY} From 718ba69e1b81fe8149bdd637379cb37c7394d9c4 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 2 Apr 2023 21:06:09 +0300 Subject: [PATCH 093/123] OpenGL3: Drop unused fixed-function emulation materials --- media/Shaders/DetailMap.fsh | 72 --------- media/Shaders/LightmapAdd.fsh | 72 --------- media/Shaders/LightmapModulate.fsh | 74 ---------- media/Shaders/Reflection2Layer.fsh | 72 --------- media/Shaders/Reflection2Layer.vsh | 55 ------- media/Shaders/Solid2.vsh | 53 ------- media/Shaders/Solid2Layer.fsh | 74 ---------- media/Shaders/SphereMap.fsh | 64 -------- media/Shaders/SphereMap.vsh | 50 ------- source/Irrlicht/OpenGL/Driver.cpp | 121 ++++------------ source/Irrlicht/OpenGL/Driver.h | 2 + .../Irrlicht/OpenGL/FixedPipelineRenderer.cpp | 137 +----------------- .../Irrlicht/OpenGL/FixedPipelineRenderer.h | 74 +--------- 13 files changed, 31 insertions(+), 889 deletions(-) delete mode 100644 media/Shaders/DetailMap.fsh delete mode 100644 media/Shaders/LightmapAdd.fsh delete mode 100644 media/Shaders/LightmapModulate.fsh delete mode 100644 media/Shaders/Reflection2Layer.fsh delete mode 100644 media/Shaders/Reflection2Layer.vsh delete mode 100644 media/Shaders/Solid2.vsh delete mode 100644 media/Shaders/Solid2Layer.fsh delete mode 100644 media/Shaders/SphereMap.fsh delete mode 100644 media/Shaders/SphereMap.vsh diff --git a/media/Shaders/DetailMap.fsh b/media/Shaders/DetailMap.fsh deleted file mode 100644 index 01c94d78..00000000 --- a/media/Shaders/DetailMap.fsh +++ /dev/null @@ -1,72 +0,0 @@ -#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 deleted file mode 100644 index 895625f5..00000000 --- a/media/Shaders/LightmapAdd.fsh +++ /dev/null @@ -1,72 +0,0 @@ -#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 deleted file mode 100644 index 74e9df19..00000000 --- a/media/Shaders/LightmapModulate.fsh +++ /dev/null @@ -1,74 +0,0 @@ -#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/Reflection2Layer.fsh b/media/Shaders/Reflection2Layer.fsh deleted file mode 100644 index bdc3c668..00000000 --- a/media/Shaders/Reflection2Layer.fsh +++ /dev/null @@ -1,72 +0,0 @@ -#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 deleted file mode 100644 index aafac22b..00000000 --- a/media/Shaders/Reflection2Layer.vsh +++ /dev/null @@ -1,55 +0,0 @@ -#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/Solid2.vsh b/media/Shaders/Solid2.vsh deleted file mode 100644 index c49ecfc4..00000000 --- a/media/Shaders/Solid2.vsh +++ /dev/null @@ -1,53 +0,0 @@ -#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 deleted file mode 100644 index 3c8a39dd..00000000 --- a/media/Shaders/Solid2Layer.fsh +++ /dev/null @@ -1,74 +0,0 @@ -#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 deleted file mode 100644 index df1010e6..00000000 --- a/media/Shaders/SphereMap.fsh +++ /dev/null @@ -1,64 +0,0 @@ -#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 deleted file mode 100644 index 5062d795..00000000 --- a/media/Shaders/SphereMap.vsh +++ /dev/null @@ -1,50 +0,0 @@ -#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/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 641536fc..6dec58f1 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -317,140 +317,73 @@ COpenGL3DriverBase::~COpenGL3DriverBase() fsFile->drop(); } + void COpenGL3DriverBase::addDummyMaterial(E_MATERIAL_TYPE type) { + auto index = addMaterialRenderer(getMaterialRenderer(EMT_SOLID), "DUMMY"); + assert(index == type); + } + 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. + // The addition order must be the same as in the E_MATERIAL_TYPE enumeration. Thus the + // addDummyMaterial calls for materials no longer supported. - core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + const core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + + // EMT_SOLID 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); + addDummyMaterial(EMT_SOLID_2_LAYER); + addDummyMaterial(EMT_LIGHTMAP); + addDummyMaterial(EMT_LIGHTMAP_ADD); + addDummyMaterial(EMT_LIGHTMAP_M2); + addDummyMaterial(EMT_LIGHTMAP_M4); + addDummyMaterial(EMT_LIGHTMAP_LIGHTING); + addDummyMaterial(EMT_LIGHTMAP_LIGHTING_M2); + addDummyMaterial(EMT_LIGHTMAP_LIGHTING_M4); + addDummyMaterial(EMT_DETAIL_MAP); + addDummyMaterial(EMT_SPHERE_MAP); + addDummyMaterial(EMT_REFLECTION_2_LAYER); + addDummyMaterial(EMT_TRANSPARENT_ADD_COLOR); + // EMT_TRANSPARENT_ALPHA_CHANNEL 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); + // EMT_TRANSPARENT_ALPHA_CHANNEL_REF 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); + // EMT_TRANSPARENT_VERTEX_ALPHA 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"; + addDummyMaterial(EMT_TRANSPARENT_REFLECTION_2_LAYER); - 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"; + // EMT_ONETEXTURE_BLEND 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 diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 06907b7a..c91ccfea 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -384,6 +384,8 @@ private: IContextManager* ContextManager; + void addDummyMaterial(E_MATERIAL_TYPE type); + std::vector QuadsIndices; void initQuadsIndices(int max_vertex_count = 65536); diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp index 29224709..421788ac 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp @@ -1,3 +1,4 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy // 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 @@ -137,142 +138,6 @@ void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services 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() : diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h index aea935fa..cfbb3b66 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h @@ -1,3 +1,4 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy // 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 @@ -82,79 +83,6 @@ protected: 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: From 6a152e86298502e587da4744c9f5bfab1d0ddf81 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 2 Apr 2023 21:19:58 +0300 Subject: [PATCH 094/123] OpenGL3: Drop unused material property uniforms --- media/Shaders/Solid.vsh | 7 ------- source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp | 9 ++------- source/Irrlicht/OpenGL/FixedPipelineRenderer.h | 7 ------- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/media/Shaders/Solid.vsh b/media/Shaders/Solid.vsh index 98d0daef..c260409b 100644 --- a/media/Shaders/Solid.vsh +++ b/media/Shaders/Solid.vsh @@ -14,13 +14,6 @@ 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 */ diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp index 421788ac..004e2574 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp @@ -15,7 +15,7 @@ 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), + FirstUpdateBase(true), WVPMatrixID(-1), WVMatrixID(-1), NMatrixID(-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) @@ -45,12 +45,7 @@ void COpenGL3MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, 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"); diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h index cfbb3b66..9613d20b 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h @@ -28,13 +28,6 @@ protected: s32 WVMatrixID; s32 NMatrixID; - s32 GlobalAmbientID; - s32 MaterialAmbientID; - s32 MaterialDiffuseID; - s32 MaterialEmissiveID; - s32 MaterialSpecularID; - s32 MaterialShininessID; - s32 FogEnableID; s32 FogTypeID; s32 FogColorID; From 462657960d9a71de142937cb29e30917d57845af Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 2 Apr 2023 21:24:36 +0300 Subject: [PATCH 095/123] OpenGL3: Drop always-zero vSpecularColor from the shaders --- media/Shaders/OneTextureBlend.fsh | 2 -- media/Shaders/Solid.fsh | 2 -- media/Shaders/Solid.vsh | 2 -- media/Shaders/TransparentAlphaChannel.fsh | 2 -- media/Shaders/TransparentAlphaChannelRef.fsh | 3 --- media/Shaders/TransparentVertexAlpha.fsh | 2 -- 6 files changed, 13 deletions(-) diff --git a/media/Shaders/OneTextureBlend.fsh b/media/Shaders/OneTextureBlend.fsh index c348016c..7ecb7e1a 100644 --- a/media/Shaders/OneTextureBlend.fsh +++ b/media/Shaders/OneTextureBlend.fsh @@ -18,7 +18,6 @@ uniform float uFogDensity; varying vec2 vTextureCoord0; varying vec4 vVertexColor; -varying vec4 vSpecularColor; varying float vFogCoord; float computeFog() @@ -54,7 +53,6 @@ void main() Color1 = texture2D(uTextureUnit0, vTextureCoord0); vec4 FinalColor = Color0 * Color1; - FinalColor += vSpecularColor; if (uBlendType == 1) { diff --git a/media/Shaders/Solid.fsh b/media/Shaders/Solid.fsh index df1010e6..c85c6baf 100644 --- a/media/Shaders/Solid.fsh +++ b/media/Shaders/Solid.fsh @@ -17,7 +17,6 @@ uniform float uFogDensity; varying vec2 vTextureCoord0; varying vec4 vVertexColor; -varying vec4 vSpecularColor; varying float vFogCoord; float computeFog() @@ -50,7 +49,6 @@ void main() if (bool(uTextureUsage0)) Color *= texture2D(uTextureUnit0, vTextureCoord0); - Color += vSpecularColor; if (bool(uFogEnable)) { diff --git a/media/Shaders/Solid.vsh b/media/Shaders/Solid.vsh index c260409b..7379e5bb 100644 --- a/media/Shaders/Solid.vsh +++ b/media/Shaders/Solid.vsh @@ -20,7 +20,6 @@ uniform float uThickness; varying vec2 vTextureCoord0; varying vec4 vVertexColor; -varying vec4 vSpecularColor; varying float vFogCoord; void main() @@ -32,7 +31,6 @@ void main() 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; diff --git a/media/Shaders/TransparentAlphaChannel.fsh b/media/Shaders/TransparentAlphaChannel.fsh index cef349a4..8491068a 100644 --- a/media/Shaders/TransparentAlphaChannel.fsh +++ b/media/Shaders/TransparentAlphaChannel.fsh @@ -18,7 +18,6 @@ uniform float uFogDensity; varying vec2 vTextureCoord0; varying vec4 vVertexColor; -varying vec4 vSpecularColor; varying float vFogCoord; float computeFog() @@ -57,7 +56,6 @@ void main() if (Color.a < uAlphaRef) discard; } - Color += vSpecularColor; if (bool(uFogEnable)) { diff --git a/media/Shaders/TransparentAlphaChannelRef.fsh b/media/Shaders/TransparentAlphaChannelRef.fsh index fab4eeea..ac762f0c 100644 --- a/media/Shaders/TransparentAlphaChannelRef.fsh +++ b/media/Shaders/TransparentAlphaChannelRef.fsh @@ -18,7 +18,6 @@ uniform float uFogDensity; varying vec2 vTextureCoord0; varying vec4 vVertexColor; -varying vec4 vSpecularColor; varying float vFogCoord; float computeFog() @@ -55,8 +54,6 @@ void main() if (Color.a < uAlphaRef) discard; - Color += vSpecularColor; - if (bool(uFogEnable)) { float FogFactor = computeFog(); diff --git a/media/Shaders/TransparentVertexAlpha.fsh b/media/Shaders/TransparentVertexAlpha.fsh index df1010e6..c85c6baf 100644 --- a/media/Shaders/TransparentVertexAlpha.fsh +++ b/media/Shaders/TransparentVertexAlpha.fsh @@ -17,7 +17,6 @@ uniform float uFogDensity; varying vec2 vTextureCoord0; varying vec4 vVertexColor; -varying vec4 vSpecularColor; varying float vFogCoord; float computeFog() @@ -50,7 +49,6 @@ void main() if (bool(uTextureUsage0)) Color *= texture2D(uTextureUnit0, vTextureCoord0); - Color += vSpecularColor; if (bool(uFogEnable)) { From fc0440ff8900aeb71af7ce3bc6d44464e0cca727 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 8 Apr 2023 01:23:20 +0300 Subject: [PATCH 096/123] Drop IImageLoader::loadImages as only IImageLoader::loadImage is usable --- include/IImageLoader.h | 11 ------ source/Irrlicht/CNullDriver.cpp | 68 +++++++++++---------------------- 2 files changed, 22 insertions(+), 57 deletions(-) diff --git a/include/IImageLoader.h b/include/IImageLoader.h index 13eef977..61552afb 100644 --- a/include/IImageLoader.h +++ b/include/IImageLoader.h @@ -45,17 +45,6 @@ public: /** \param file File handle to check. \return Pointer to newly created image, or 0 upon error. */ virtual IImage* loadImage(io::IReadFile* file) const = 0; - - //! Creates a multiple surfaces from the file eg. whole cube map. - /** \param file File handle to check. - \param type Pointer to E_TEXTURE_TYPE where a recommended type of the texture will be stored. - \return Array of pointers to newly created images. */ - virtual core::array loadImages(io::IReadFile* file, E_TEXTURE_TYPE* type) const - { - core::array image; - - return image; - } }; diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index a02431cf..d3b72804 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -1196,57 +1196,33 @@ core::array CNullDriver::createImagesFromFile(io::IReadFile* file, E_TE core::array imageArray; - if (file) - { - s32 i; + if (!file) + return imageArray; - // try to load file based on file extension - for (i = SurfaceLoader.size() - 1; i >= 0; --i) - { - if (SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())) - { - // reset file position which might have changed due to previous loadImage calls - file->seek(0); - imageArray = SurfaceLoader[i]->loadImages(file, type); + // try to load file based on file extension + for (int i = SurfaceLoader.size() - 1; i >= 0; --i) { + if (!SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())) + continue; - if (imageArray.size() == 0) - { - file->seek(0); - IImage* image = SurfaceLoader[i]->loadImage(file); - - if (image) - imageArray.push_back(image); - } - - if (imageArray.size() > 0) - return imageArray; - } + file->seek(0); // reset file position which might have changed due to previous loadImage calls + if (IImage *image = SurfaceLoader[i]->loadImage(file)) { + imageArray.push_back(image); + return imageArray; } + } - // try to load file based on what is in it - for (i = SurfaceLoader.size() - 1; i >= 0; --i) - { - // dito - file->seek(0); - if (SurfaceLoader[i]->isALoadableFileFormat(file) - && !SurfaceLoader[i]->isALoadableFileExtension(file->getFileName()) // extension was tried above already - ) - { - file->seek(0); - imageArray = SurfaceLoader[i]->loadImages(file, type); + // try to load file based on what is in it + for (int i = SurfaceLoader.size() - 1; i >= 0; --i) { + if (SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())) + continue; // extension was tried above already + file->seek(0); // dito + if (!SurfaceLoader[i]->isALoadableFileFormat(file)) + continue; - if (imageArray.size() == 0) - { - file->seek(0); - IImage* image = SurfaceLoader[i]->loadImage(file); - - if (image) - imageArray.push_back(image); - } - - if (imageArray.size() > 0) - return imageArray; - } + file->seek(0); + if (IImage *image = SurfaceLoader[i]->loadImage(file)) { + imageArray.push_back(image); + return imageArray; } } From 5eb607f86fa514c24da80650a507889fa0c871e9 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 8 Apr 2023 01:36:43 +0300 Subject: [PATCH 097/123] Drop createImagesFromFile in favor of createImageFromFile --- include/IVideoDriver.h | 42 +---------------- source/Irrlicht/CNullDriver.cpp | 84 ++++++++++----------------------- source/Irrlicht/CNullDriver.h | 4 +- 3 files changed, 30 insertions(+), 100 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index f93d7612..ef8e38e1 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -959,28 +959,6 @@ namespace video \return The current texture creation flag enabled mode. */ virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const =0; - //! Creates a software images from a file. - /** No hardware texture will be created for those images. This - method is useful for example if you want to read a heightmap - for a terrain renderer. - \param filename Name of the file from which the images are created. - \param type Pointer to E_TEXTURE_TYPE where a recommended type of the texture will be stored. - \return The array of created images. - If you no longer need those images, you should call IImage::drop() on each of them. - See IReferenceCounted::drop() for more information. */ - virtual core::array createImagesFromFile(const io::path& filename, E_TEXTURE_TYPE* type = 0) = 0; - - //! Creates a software images from a file. - /** No hardware texture will be created for those images. This - method is useful for example if you want to read a heightmap - for a terrain renderer. - \param file File from which the image is created. - \param type Pointer to E_TEXTURE_TYPE where a recommended type of the texture will be stored. - \return The array of created images. - If you no longer need those images, you should call IImage::drop() on each of them. - See IReferenceCounted::drop() for more information. */ - virtual core::array createImagesFromFile(io::IReadFile* file, E_TEXTURE_TYPE* type = 0) = 0; - //! Creates a software image from a file. /** No hardware texture will be created for this image. This method is useful for example if you want to read a heightmap @@ -990,15 +968,7 @@ namespace video \return The created image. If you no longer need the image, you should call IImage::drop(). See IReferenceCounted::drop() for more information. */ - IImage* createImageFromFile(const io::path& filename) - { - core::array imageArray = createImagesFromFile(filename); - - for (u32 i = 1; i < imageArray.size(); ++i) - imageArray[i]->drop(); - - return (imageArray.size() > 0) ? imageArray[0] : 0; - } + virtual IImage* createImageFromFile(const io::path& filename) = 0; //! Creates a software image from a file. /** No hardware texture will be created for this image. This @@ -1008,15 +978,7 @@ namespace video \return The created image. If you no longer need the image, you should call IImage::drop(). See IReferenceCounted::drop() for more information. */ - IImage* createImageFromFile(io::IReadFile* file) - { - core::array imageArray = createImagesFromFile(file); - - for (u32 i = 1; i < imageArray.size(); ++i) - imageArray[i]->drop(); - - return (imageArray.size() > 0) ? imageArray[0] : 0; - } + virtual IImage* createImageFromFile(io::IReadFile* file) = 0; //! Writes the provided image to a file. /** Requires that there is a suitable image writer registered diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index d3b72804..43b59d03 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -553,39 +553,21 @@ ITexture* CNullDriver::getTexture(io::IReadFile* file) //! opens the file and loads it into the surface video::ITexture* CNullDriver::loadTextureFromFile(io::IReadFile* file, const io::path& hashName ) { - ITexture* texture = 0; + ITexture *texture = nullptr; - E_TEXTURE_TYPE type = ETT_2D; - - core::array imageArray = createImagesFromFile(file, &type); - - if (checkImage(imageArray)) - { - switch (type) - { - case ETT_2D: - texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), imageArray[0]); - break; - case ETT_CUBEMAP: - if (imageArray.size() >= 6 && imageArray[0] && imageArray[1] && imageArray[2] && imageArray[3] && imageArray[4] && imageArray[5]) - { - texture = createDeviceDependentTextureCubemap(hashName.size() ? hashName : file->getFileName(), imageArray); - } - break; - default: - _IRR_DEBUG_BREAK_IF(true); - break; - } + IImage *image = createImageFromFile(file); + if (!image) + return nullptr; + core::array imageArray; + imageArray.push_back(image); + if (checkImage(imageArray)) { + texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image); if (texture) os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG); } - for (u32 i = 0; i < imageArray.size(); ++i) - { - if (imageArray[i]) - imageArray[i]->drop(); - } + image->drop(); return texture; } @@ -1168,36 +1150,26 @@ bool CNullDriver::getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const return (TextureCreationFlags & flag)!=0; } -core::array CNullDriver::createImagesFromFile(const io::path& filename, E_TEXTURE_TYPE* type) +IImage *CNullDriver::createImageFromFile(const io::path& filename) { - // TO-DO -> use 'move' feature from C++11 standard. + if (!filename.size()) + return nullptr; - core::array imageArray; - - if (filename.size() > 0) - { - io::IReadFile* file = FileSystem->createAndOpenFile(filename); - - if (file) - { - imageArray = createImagesFromFile(file, type); - file->drop(); - } - else - os::Printer::log("Could not open file of image", filename, ELL_WARNING); + io::IReadFile* file = FileSystem->createAndOpenFile(filename); + if (!file) { + os::Printer::log("Could not open file of image", filename, ELL_WARNING); + return nullptr; } - return imageArray; + IImage *image = createImageFromFile(file); + file->drop(); + return image; } -core::array CNullDriver::createImagesFromFile(io::IReadFile* file, E_TEXTURE_TYPE* type) +IImage *CNullDriver::createImageFromFile(io::IReadFile* file) { - // TO-DO -> use 'move' feature from C++11 standard. - - core::array imageArray; - if (!file) - return imageArray; + return nullptr; // try to load file based on file extension for (int i = SurfaceLoader.size() - 1; i >= 0; --i) { @@ -1205,10 +1177,8 @@ core::array CNullDriver::createImagesFromFile(io::IReadFile* file, E_TE continue; file->seek(0); // reset file position which might have changed due to previous loadImage calls - if (IImage *image = SurfaceLoader[i]->loadImage(file)) { - imageArray.push_back(image); - return imageArray; - } + if (IImage *image = SurfaceLoader[i]->loadImage(file)) + return image; } // try to load file based on what is in it @@ -1220,13 +1190,11 @@ core::array CNullDriver::createImagesFromFile(io::IReadFile* file, E_TE continue; file->seek(0); - if (IImage *image = SurfaceLoader[i]->loadImage(file)) { - imageArray.push_back(image); - return imageArray; - } + if (IImage *image = SurfaceLoader[i]->loadImage(file)) + return image; } - return imageArray; + return nullptr; } diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index e6b27d87..95fc0d9e 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -314,9 +314,9 @@ namespace video //! Returns if a texture creation flag is enabled or disabled. bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const override; - core::array createImagesFromFile(const io::path& filename, E_TEXTURE_TYPE* type = 0) override; + IImage *createImageFromFile(const io::path& filename) override; - core::array createImagesFromFile(io::IReadFile* file, E_TEXTURE_TYPE* type = 0) override; + IImage *createImageFromFile(io::IReadFile* file) override; //! Creates a software image from a byte array. /** \param useForeignMemory: If true, the image will use the data pointer From e01f285c8fee31bffa4b34dc8a393085f2d0d143 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 8 Apr 2023 01:45:11 +0300 Subject: [PATCH 098/123] Extract and use singular CNullDriver::checkImage --- source/Irrlicht/CNullDriver.cpp | 170 +++++++++++++++----------------- source/Irrlicht/CNullDriver.h | 2 + 2 files changed, 84 insertions(+), 88 deletions(-) diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 43b59d03..6ef7c17a 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -344,10 +344,7 @@ ITexture* CNullDriver::addTexture(const core::dimension2d& size, const io:: IImage* image = new CImage(format, size); ITexture* t = 0; - core::array imageArray(1); - imageArray.push_back(image); - - if (checkImage(imageArray)) + if (checkImage(image)) { t = createDeviceDependentTexture(name, image); } @@ -376,10 +373,7 @@ ITexture* CNullDriver::addTexture(const io::path& name, IImage* image) ITexture* t = 0; - core::array imageArray(1); - imageArray.push_back(image); - - if (checkImage(imageArray)) + if (checkImage(image)) { t = createDeviceDependentTexture(name, image); } @@ -559,9 +553,7 @@ video::ITexture* CNullDriver::loadTextureFromFile(io::IReadFile* file, const io: if (!image) return nullptr; - core::array imageArray; - imageArray.push_back(image); - if (checkImage(imageArray)) { + if (checkImage(image)) { texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image); if (texture) os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG); @@ -1039,90 +1031,92 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const return true; } +bool CNullDriver::checkImage(IImage *image) const +{ + ECOLOR_FORMAT format = image->getColorFormat(); + core::dimension2d size = image->getDimension(); + + switch (format) + { + case ECF_DXT1: + case ECF_DXT2: + case ECF_DXT3: + case ECF_DXT4: + case ECF_DXT5: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT)) + { + os::Printer::log("DXT texture compression not available.", ELL_ERROR); + return false; + } + else if (size.getOptimalSize(true, false) != size) + { + os::Printer::log("Invalid size of image for DXT texture, size of image must be power of two.", ELL_ERROR); + return false; + } + break; + case ECF_PVRTC_RGB2: + case ECF_PVRTC_ARGB2: + case ECF_PVRTC_RGB4: + case ECF_PVRTC_ARGB4: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC)) + { + os::Printer::log("PVRTC texture compression not available.", ELL_ERROR); + return false; + } + else if (size.getOptimalSize(true, false) != size) + { + os::Printer::log("Invalid size of image for PVRTC compressed texture, size of image must be power of two and squared.", ELL_ERROR); + return false; + } + break; + case ECF_PVRTC2_ARGB2: + case ECF_PVRTC2_ARGB4: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2)) + { + os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR); + return false; + } + break; + case ECF_ETC1: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1)) + { + os::Printer::log("ETC1 texture compression not available.", ELL_ERROR); + return false; + } + break; + case ECF_ETC2_RGB: + case ECF_ETC2_ARGB: + if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2)) + { + os::Printer::log("ETC2 texture compression not available.", ELL_ERROR); + return false; + } + break; + default: + break; + } + return true; +} + bool CNullDriver::checkImage(const core::array& image) const { - bool status = true; + if (!image.size()) + return false; - if (image.size() > 0) - { - ECOLOR_FORMAT lastFormat = image[0]->getColorFormat(); - core::dimension2d lastSize = image[0]->getDimension(); + ECOLOR_FORMAT lastFormat = image[0]->getColorFormat(); + core::dimension2d lastSize = image[0]->getDimension(); - for (u32 i = 0; i < image.size() && status; ++i) - { - ECOLOR_FORMAT format = image[i]->getColorFormat(); - core::dimension2d size = image[i]->getDimension(); + for (u32 i = 0; i < image.size(); ++i) { + ECOLOR_FORMAT format = image[i]->getColorFormat(); + core::dimension2d size = image[i]->getDimension(); - switch (format) - { - case ECF_DXT1: - case ECF_DXT2: - case ECF_DXT3: - case ECF_DXT4: - case ECF_DXT5: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_DXT)) - { - os::Printer::log("DXT texture compression not available.", ELL_ERROR); - status = false; - } - else if (size.getOptimalSize(true, false) != size) - { - os::Printer::log("Invalid size of image for DXT texture, size of image must be power of two.", ELL_ERROR); - status = false; - } - break; - case ECF_PVRTC_RGB2: - case ECF_PVRTC_ARGB2: - case ECF_PVRTC_RGB4: - case ECF_PVRTC_ARGB4: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC)) - { - os::Printer::log("PVRTC texture compression not available.", ELL_ERROR); - status = false; - } - else if (size.getOptimalSize(true, false) != size) - { - os::Printer::log("Invalid size of image for PVRTC compressed texture, size of image must be power of two and squared.", ELL_ERROR); - status = false; - } - break; - case ECF_PVRTC2_ARGB2: - case ECF_PVRTC2_ARGB4: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_PVRTC2)) - { - os::Printer::log("PVRTC2 texture compression not available.", ELL_ERROR); - status = false; - } - break; - case ECF_ETC1: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC1)) - { - os::Printer::log("ETC1 texture compression not available.", ELL_ERROR); - status = false; - } - break; - case ECF_ETC2_RGB: - case ECF_ETC2_ARGB: - if (!queryFeature(EVDF_TEXTURE_COMPRESSED_ETC2)) - { - os::Printer::log("ETC2 texture compression not available.", ELL_ERROR); - status = false; - } - break; - default: - break; - } + if (!checkImage(image[i])) + return false; - if (format != lastFormat || size != lastSize) - status = false; - } + if (format != lastFormat || size != lastSize) + return false; } - else - { - status = false; - } - - return status; + return true; } //! Enables or disables a texture creation flag. diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index 95fc0d9e..d3d933c6 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -670,6 +670,8 @@ namespace video //! checks triangle count and print warning if wrong bool checkPrimitiveCount(u32 prmcnt) const; + bool checkImage(IImage *image) const; + bool checkImage(const core::array& image) const; // adds a material renderer and drops it afterwards. To be used for internal creation From aa1696a7e6a275e613e7323e7f9553b7b7a0b7e0 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 8 Apr 2023 20:08:03 +0300 Subject: [PATCH 099/123] Use a buffer for quads indices also use glDrawRangeElements for quad drawing --- source/Irrlicht/OpenGL/Driver.cpp | 16 ++++++++++++---- source/Irrlicht/OpenGL/Driver.h | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 6dec58f1..461a2f14 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -186,6 +186,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::initQuadsIndices(int max_vertex_count) { int max_quad_count = max_vertex_count / 4; + std::vector QuadsIndices; QuadsIndices.reserve(6 * max_quad_count); for (int k = 0; k < max_quad_count; k++) { QuadsIndices.push_back(4 * k + 0); @@ -195,6 +196,11 @@ COpenGL3DriverBase::~COpenGL3DriverBase() QuadsIndices.push_back(4 * k + 2); QuadsIndices.push_back(4 * k + 3); } + glGenBuffers(1, &QuadIndexBuffer); + glBindBuffer(GL_ARRAY_BUFFER, QuadIndexBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(QuadsIndices[0]) * QuadsIndices.size(), QuadsIndices.data(), GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + QuadIndexCount = QuadsIndices.size(); } bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) @@ -919,7 +925,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } const irr::u32 drawCount = core::min_(positions.size(), sourceRects.size()); - assert(6 * std::size_t(drawCount) <= QuadsIndices.size()); + assert(6 * drawCount <= QuadIndexCount); // FIXME split the batch? or let it crash? core::array vtx(drawCount * 4); @@ -959,7 +965,9 @@ COpenGL3DriverBase::~COpenGL3DriverBase() tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); } - drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), QuadsIndices.data(), 6 * drawCount); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, QuadIndexBuffer); + drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), vtx.size(), 0, 6 * drawCount); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if (clipRect) glDisable(GL_SCISSOR_TEST); @@ -1102,10 +1110,10 @@ COpenGL3DriverBase::~COpenGL3DriverBase() endDraw(vertexType); } - void COpenGL3DriverBase::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, int vertexCount, const u16 *indices, int indexCount) { beginDraw(vertexType, reinterpret_cast(vertices)); - glDrawElements(primitiveType, indexCount, GL_UNSIGNED_SHORT, indices); + glDrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL_UNSIGNED_SHORT, indices); endDraw(vertexType); } diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index c91ccfea..84cc62be 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -331,7 +331,7 @@ namespace video 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, const void *vertices, int vertexCount, 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); @@ -386,7 +386,8 @@ private: void addDummyMaterial(E_MATERIAL_TYPE type); - std::vector QuadsIndices; + unsigned QuadIndexCount; + GLuint QuadIndexBuffer = 0; void initQuadsIndices(int max_vertex_count = 65536); void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); From 2d81374b3470aace9ccc42478e98c92aed479279 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 11 Apr 2023 14:36:44 +0200 Subject: [PATCH 100/123] Revert "Fix: Listbox was sometimes sending EGET_LISTBOX_SELECTED_AGAIN instead of EGET_LISTBOX_CHANGED." This broke scrolling in listboxes, as they would always reset to top position. reverts commit 1967d71cfba23fb54ac88cea64673f73af13bfda --- source/Irrlicht/CGUIListBox.cpp | 38 +++++++++++++-------------------- source/Irrlicht/CGUIListBox.h | 3 +-- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/source/Irrlicht/CGUIListBox.cpp b/source/Irrlicht/CGUIListBox.cpp index cbd3ae5b..b00c7e38 100644 --- a/source/Irrlicht/CGUIListBox.cpp +++ b/source/Irrlicht/CGUIListBox.cpp @@ -22,10 +22,10 @@ namespace gui CGUIListBox::CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle, bool clip, bool drawBack, bool moveOverSelect) -: IGUIListBox(environment, parent, id, rectangle), Selected(-1), HoverSelected(-1), +: IGUIListBox(environment, parent, id, rectangle), Selected(-1), ItemHeight(0),ItemHeightOverride(0), TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0), - ScrollBar(0), SelectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack), + ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack), MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true) { #ifdef _DEBUG @@ -116,7 +116,7 @@ void CGUIListBox::removeItem(u32 id) else if ((u32)Selected > id) { Selected -= 1; - SelectTime = os::Timer::getTime(); + selectTime = os::Timer::getTime(); } Items.erase(id); @@ -148,7 +148,6 @@ void CGUIListBox::clear() Items.clear(); ItemsIconWidth = 0; Selected = -1; - HoverSelected = -1; ScrollBar->setPos(0); @@ -193,7 +192,7 @@ void CGUIListBox::recalculateItemHeight() //! returns id of selected item. returns -1 if no item is selected. s32 CGUIListBox::getSelected() const { - return HoverSelected >= 0 ? HoverSelected : Selected; + return Selected; } @@ -205,8 +204,7 @@ void CGUIListBox::setSelected(s32 id) else Selected = id; - HoverSelected = -1; - SelectTime = os::Timer::getTime(); + selectTime = os::Timer::getTime(); recalculateScrollPos(); } @@ -456,19 +454,14 @@ void CGUIListBox::selectNew(s32 ypos, bool onlyHover) u32 now = os::Timer::getTime(); s32 oldSelected = Selected; - HoverSelected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); - if (HoverSelected<0 && !Items.empty()) - HoverSelected = 0; - if (!onlyHover) - { - Selected = HoverSelected; - HoverSelected = -1; - } + Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); + if (Selected<0 && !Items.empty()) + Selected = 0; recalculateScrollPos(); - gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < SelectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED; - SelectTime = now; + gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < selectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED; + selectTime = now; // post the news if (Parent && !onlyHover) { @@ -534,14 +527,13 @@ void CGUIListBox::draw() frameRect.LowerRightCorner.Y -= ScrollBar->getPos(); bool hl = (HighlightWhenNotFocused || Environment->hasFocus(this) || Environment->hasFocus(ScrollBar)); - const irr::s32 selected = getSelected(); for (s32 i=0; i<(s32)Items.size(); ++i) { if (frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y && frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y) { - if (i == selected && hl) + if (i == Selected && hl) skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), frameRect, &clientClip); core::rect textRect = frameRect; @@ -555,24 +547,24 @@ void CGUIListBox::draw() iconPos.Y += textRect.getHeight() / 2; iconPos.X += ItemsIconWidth/2; - if ( i==selected && hl ) + if ( i==Selected && hl ) { IconBank->draw2DSprite( (u32)Items[i].Icon, iconPos, &clientClip, hasItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) ? getItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_ICON_HIGHLIGHT), - SelectTime, os::Timer::getTime(), false, true); + selectTime, os::Timer::getTime(), false, true); } else { IconBank->draw2DSprite( (u32)Items[i].Icon, iconPos, &clientClip, hasItemOverrideColor(i, EGUI_LBC_ICON) ? getItemOverrideColor(i, EGUI_LBC_ICON) : getItemDefaultColor(EGUI_LBC_ICON), - 0 , (i==selected) ? os::Timer::getTime() : 0, false, true); + 0 , (i==Selected) ? os::Timer::getTime() : 0, false, true); } } textRect.UpperLeftCorner.X += ItemsIconWidth+3; - if ( i==selected && hl ) + if ( i==Selected && hl ) { Font->draw(Items[i].Text.c_str(), textRect, hasItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) ? diff --git a/source/Irrlicht/CGUIListBox.h b/source/Irrlicht/CGUIListBox.h index 37fffa84..a3e7255a 100644 --- a/source/Irrlicht/CGUIListBox.h +++ b/source/Irrlicht/CGUIListBox.h @@ -154,7 +154,6 @@ namespace gui core::array< ListItem > Items; s32 Selected; - s32 HoverSelected; // When >= 0 we're in the middle of changing selection while mouse is pressed. We need to know so selected again isn't called too often. s32 ItemHeight; s32 ItemHeightOverride; s32 TotalItemHeight; @@ -162,7 +161,7 @@ namespace gui gui::IGUIFont* Font; gui::IGUISpriteBank* IconBank; gui::IGUIScrollBar* ScrollBar; - u32 SelectTime; + u32 selectTime; u32 LastKeyTime; core::stringw KeyBuffer; bool Selecting; From 09043e3da74246a8a355479630508b8dd13c6683 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 11 Apr 2023 18:19:36 +0200 Subject: [PATCH 101/123] Update MinGW dependencies --- scripts/ci-build-mingw.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/ci-build-mingw.sh b/scripts/ci-build-mingw.sh index 8173aa64..ba4efcae 100755 --- a/scripts/ci-build-mingw.sh +++ b/scripts/ci-build-mingw.sh @@ -5,21 +5,19 @@ variant=win32 [[ "$(basename "$CXX")" == "x86_64-"* ]] && variant=win64 -libjpeg_version=2.1.2 -libpng_version=1.6.37 -zlib_version=1.2.11 +libjpeg_version=2.1.5.1 +libpng_version=1.6.39 +zlib_version=1.2.13 mkdir -p libs pushd libs libs=$PWD -tmp= -[ "$variant" = win32 ] && tmp=dw2/ [ -e libjpeg.zip ] || \ wget "http://minetest.kitsunemimi.pw/libjpeg-$libjpeg_version-$variant.zip" -O libjpeg.zip [ -e libpng.zip ] || \ - wget "http://minetest.kitsunemimi.pw/${tmp}libpng-$libpng_version-$variant.zip" -O libpng.zip + wget "http://minetest.kitsunemimi.pw/libpng-$libpng_version-$variant.zip" -O libpng.zip [ -e zlib.zip ] || \ - wget "http://minetest.kitsunemimi.pw/${tmp}zlib-$zlib_version-$variant.zip" -O zlib.zip + wget "http://minetest.kitsunemimi.pw/zlib-$zlib_version-$variant.zip" -O zlib.zip [ -d libjpeg ] || unzip -o libjpeg.zip -d libjpeg [ -d libpng ] || unzip -o libpng.zip -d libpng [ -d zlib ] || unzip -o zlib.zip -d zlib From 7a3fc62ada4001d5bb6c97ed26ec19a4e7c9d9ac Mon Sep 17 00:00:00 2001 From: nephele <105942296+nephele-gh@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:16:35 +0200 Subject: [PATCH 102/123] Haiku: build fix --- source/Irrlicht/CFileSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Irrlicht/CFileSystem.cpp b/source/Irrlicht/CFileSystem.cpp index 3ee35d9b..cddda94b 100644 --- a/source/Irrlicht/CFileSystem.cpp +++ b/source/Irrlicht/CFileSystem.cpp @@ -796,7 +796,7 @@ IFileList* CFileSystem::createFileList() size = buf.st_size; isDirectory = S_ISDIR(buf.st_mode); } - #if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__) + #if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__) && !defined(__HAIKU__) // only available on some systems else { From 896c825b9e8690fcc9118458fd686a3ef1f006ac Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 14 Apr 2023 19:58:13 +0100 Subject: [PATCH 103/123] Fix ComboBox changing on scroll when in a scroll container (#192) --- source/Irrlicht/CGUIComboBox.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CGUIComboBox.cpp b/source/Irrlicht/CGUIComboBox.cpp index ecd3a9c2..0494aa3e 100644 --- a/source/Irrlicht/CGUIComboBox.cpp +++ b/source/Irrlicht/CGUIComboBox.cpp @@ -320,6 +320,10 @@ bool CGUIComboBox::OnEvent(const SEvent& event) } case EMIE_MOUSE_WHEEL: { + // Try scrolling parent first + if (IGUIElement::OnEvent(event)) + return true; + s32 oldSelected = Selected; setSelected( Selected + ((event.MouseInput.Wheel < 0) ? 1 : -1)); @@ -329,11 +333,12 @@ bool CGUIComboBox::OnEvent(const SEvent& event) if (Selected >= (s32)Items.size()) setSelected((s32)Items.size() -1); - if (Selected != oldSelected) - { + if (Selected != oldSelected) { sendSelectionChangedEvent(); return true; } + + return false; } default: break; From c4ab49201b128bbaf4d58f00d685faa6ee3cb2c1 Mon Sep 17 00:00:00 2001 From: Ben Gardner Date: Sat, 15 Apr 2023 02:43:40 -0500 Subject: [PATCH 104/123] Fix compile warning when appending UTF-8/ASCII strings to ustring16 String constants are (const char *), but UTF-8 strings must be treated as an array of bytes when fiddling with the bits. The following comparison fails without this change, as uchar8_t is a signed char, which cannot be 0xC0: const uchar8_t* c2 = other; ... else if (c2[l] == 0xC0 || c2[l] == 0xC1) ... --- include/irrUString.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/irrUString.h b/include/irrUString.h index b0b730f0..bd6953b4 100644 --- a/include/irrUString.h +++ b/include/irrUString.h @@ -1323,7 +1323,7 @@ public: // Determine if the string is long enough for a BOM. u32 len = 0; - const uchar8_t* p = other; + const u8* p = reinterpret_cast(other); do { ++len; @@ -1338,10 +1338,10 @@ public: } // If a BOM was found, don't include it in the string. - const uchar8_t* c2 = other; + const u8* c2 = reinterpret_cast(other); if (c_bom != unicode::EUTFE_NONE) { - c2 = other + unicode::BOM_UTF8_LEN; + c2 += unicode::BOM_UTF8_LEN; length -= unicode::BOM_UTF8_LEN; } From 1d782702e12713f5e887040d2b4beb203b6b99b0 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 16:52:15 +0300 Subject: [PATCH 105/123] OpenGL3: new version format --- source/Irrlicht/OpenGL/Common.h | 14 ++++++++++++++ source/Irrlicht/OpenGL/Driver.cpp | 12 ++++++++---- source/Irrlicht/OpenGL/Driver.h | 4 ++++ source/Irrlicht/OpenGL3/Driver.cpp | 16 ++++++++++++++++ source/Irrlicht/OpenGL3/Driver.h | 6 ++++++ source/Irrlicht/OpenGLES2/Driver.cpp | 11 +++++++++++ source/Irrlicht/OpenGLES2/Driver.h | 6 ++++++ 7 files changed, 65 insertions(+), 4 deletions(-) diff --git a/source/Irrlicht/OpenGL/Common.h b/source/Irrlicht/OpenGL/Common.h index 4069307c..2155a9a9 100644 --- a/source/Irrlicht/OpenGL/Common.h +++ b/source/Irrlicht/OpenGL/Common.h @@ -32,5 +32,19 @@ namespace video typedef COpenGLCoreRenderTarget COpenGL3RenderTarget; typedef COpenGLCoreCacheHandler COpenGL3CacheHandler; + enum class OpenGLSpec: u8 { + Core, + Compat, + ES, + // WebGL, // TODO + }; + + struct OpenGLVersion { + OpenGLSpec Spec; + u8 Major; + u8 Minor; + u8 Release; + }; + } } diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 461a2f14..e47fc736 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -203,8 +203,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() QuadIndexCount = QuadsIndices.size(); } - bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) - { + void COpenGL3DriverBase::initVersion() { Name = glGetString(GL_VERSION); printVersion(); @@ -212,7 +211,12 @@ COpenGL3DriverBase::~COpenGL3DriverBase() VendorName = glGetString(GL_VENDOR); os::Printer::log(VendorName.c_str(), ELL_INFORMATION); - // load extensions + Version = getVersionFromOpenGL(); + } + + bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) + { + initVersion(); initExtensions(); // reset cache handler @@ -231,7 +235,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices); DriverAttributes->setAttribute("MaxTextureSize", (s32)MaxTextureSize); DriverAttributes->setAttribute("MaxTextureLODBias", MaxTextureLODBias); - DriverAttributes->setAttribute("Version", Version); + DriverAttributes->setAttribute("Version", 100 * Version.Major + Version.Minor); DriverAttributes->setAttribute("AntiAlias", AntiAlias); glPixelStorei(GL_PACK_ALIGNMENT, 1); diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 84cc62be..1122c790 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -285,6 +285,9 @@ namespace video //! inits the opengl-es driver virtual bool genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer); + void initVersion(); + virtual OpenGLVersion getVersionFromOpenGL() const = 0; + void chooseMaterial2D(); ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; @@ -341,6 +344,7 @@ namespace video core::stringw Name; core::stringc VendorName; SIrrlichtCreationParameters Params; + OpenGLVersion Version; //! bool to make all renderstates reset if set to true. bool ResetRenderStates; diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 925c6eaf..975bf557 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -11,8 +11,24 @@ namespace video { return EDT_OPENGL3; } + OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const { + GLint major, minor, profile; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile); + // The spec is clear a context can’t be both core and compatibility at the same time. + // However, the returned value is a mask. Ask Khronos why. -- numzero + if (profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + return {OpenGLSpec::Compat, (u8)major, (u8)minor, 0}; + if (profile & GL_CONTEXT_CORE_PROFILE_BIT) + return {OpenGLSpec::Core, (u8)major, (u8)minor, 0}; + os::Printer::log("Got unrecognized OpenGL profile", ELL_ERROR); + return {OpenGLSpec::Core, (u8)major, (u8)minor, 0}; + } + IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { + os::Printer::log("Using COpenGL3Driver", ELL_INFORMATION); 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 index cb30432c..66dc01b4 100644 --- a/source/Irrlicht/OpenGL3/Driver.h +++ b/source/Irrlicht/OpenGL3/Driver.h @@ -8,11 +8,17 @@ namespace irr { namespace video { + /// OpenGL 3+ driver + /// + /// For OpenGL 3.2 and higher. Compatibility profile is required currently. 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; + + protected: + OpenGLVersion getVersionFromOpenGL() const override; }; } diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 2b034644..2e293fe4 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -11,8 +11,19 @@ namespace video { return EDT_OGLES2; } + OpenGLVersion COpenGLES2Driver::getVersionFromOpenGL() const { + auto version_string = reinterpret_cast(glGetString(GL_VERSION)); + int major, minor; + if (sscanf(version_string, "OpenGL ES %d.%d", &major, &minor) != 2) { + os::Printer::log("Failed to parse OpenGL ES version string", version_string, ELL_ERROR); + return {OpenGLSpec::ES, 0, 0, 0}; + } + return {OpenGLSpec::ES, (u8)major, (u8)minor, 0}; + } + IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { + os::Printer::log("Using COpenGLES2Driver", ELL_INFORMATION); 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 index cdfb2fec..3dc234d7 100644 --- a/source/Irrlicht/OpenGLES2/Driver.h +++ b/source/Irrlicht/OpenGLES2/Driver.h @@ -8,11 +8,17 @@ namespace irr { namespace video { + /// OpenGL ES 2+ driver + /// + /// For OpenGL ES 2.0 and higher. 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; + + protected: + OpenGLVersion getVersionFromOpenGL() const override; }; } From ab628e641c9f840a2cf38a8fc879763f8187a1e8 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 18:10:02 +0300 Subject: [PATCH 106/123] OpenGL3: Add two missing OpenGL extensions to COGLESCoreExtensionHandler --- source/Irrlicht/COGLESCoreExtensionHandler.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/Irrlicht/COGLESCoreExtensionHandler.h b/source/Irrlicht/COGLESCoreExtensionHandler.h index 1b4a2bb3..4ac8b2c5 100644 --- a/source/Irrlicht/COGLESCoreExtensionHandler.h +++ b/source/Irrlicht/COGLESCoreExtensionHandler.h @@ -334,6 +334,8 @@ namespace video IRR_GL_SUN_multi_draw_arrays, // 69 IRR_GL_VIV_shader_binary, // 85 WGL_ARB_context_flush_control, // 191 + IRR_GL_EXT_draw_range_elements, // 112 again? + IRR_GL_ARB_framebuffer_object, // 45 again? IRR_OGLES_Feature_Count }; @@ -685,7 +687,9 @@ namespace video "GL_QCOM_writeonly_rendering", "GL_SUN_multi_draw_arrays", "GL_VIV_shader_binary", - "WGL_ARB_context_flush_control" + "WGL_ARB_context_flush_control", + "GL_EXT_draw_range_elements", + "GL_ARB_framebuffer_object", }; return OGLESFeatureStrings[index]; From 4ee1ab261eb88b07dfc7e9d539a29d5ba75c0318 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 18:11:08 +0300 Subject: [PATCH 107/123] OpenGL3: Add driver-dependent feature checks --- source/Irrlicht/OpenGL/Driver.cpp | 2 +- source/Irrlicht/OpenGL/Driver.h | 2 + source/Irrlicht/OpenGL/ExtensionHandler.cpp | 67 ++++++++------------- source/Irrlicht/OpenGL/ExtensionHandler.h | 12 +++- source/Irrlicht/OpenGL3/Driver.cpp | 27 +++++++++ source/Irrlicht/OpenGL3/Driver.h | 1 + source/Irrlicht/OpenGLES2/Driver.cpp | 35 +++++++++++ source/Irrlicht/OpenGLES2/Driver.h | 1 + 8 files changed, 102 insertions(+), 45 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index e47fc736..4148657b 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -217,7 +217,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) { initVersion(); - initExtensions(); + initFeatures(); // reset cache handler delete CacheHandler; diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 1122c790..b0ba42b1 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -288,6 +288,8 @@ namespace video void initVersion(); virtual OpenGLVersion getVersionFromOpenGL() const = 0; + virtual void initFeatures() = 0; + void chooseMaterial2D(); ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index b9cb75a1..f9858bea 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -15,52 +15,33 @@ namespace irr { namespace video { - void COpenGL3ExtensionHandler::initExtensions() + void COpenGL3ExtensionHandler::initExtensionsOld() { - 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(glGetString(GL_EXTENSIONS)); + const char *pos = extensions_string; + while (const char *next = strchr(pos, ' ')) { + std::string name{pos, next}; + addExtension(name.c_str()); + pos = next + 1; } - - 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; + addExtension(pos); } + void COpenGL3ExtensionHandler::initExtensionsNew() + { + GLint ext_count = 0; + GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); + for (int k = 0; k < ext_count; k++) + addExtension(reinterpret_cast(GL.GetStringi(GL_EXTENSIONS, k))); + } + + void COpenGL3ExtensionHandler::addExtension(const char *name) { + for (size_t j=0; j= 3); + initExtensionsNew(); + + // COGLESCoreExtensionHandler::Feature + static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); + Feature.BlendOperation = true; + Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; + Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + + // COGLESCoreExtensionHandler + if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) + MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); + DimAliasedPoint[0] = 1.0f; + DimAliasedPoint[1] = 1.0f; + + GLint val = 0; + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val); + StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT; + } + IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { os::Printer::log("Using COpenGL3Driver", ELL_INFORMATION); diff --git a/source/Irrlicht/OpenGL3/Driver.h b/source/Irrlicht/OpenGL3/Driver.h index 66dc01b4..ca9e94af 100644 --- a/source/Irrlicht/OpenGL3/Driver.h +++ b/source/Irrlicht/OpenGL3/Driver.h @@ -19,6 +19,7 @@ namespace video { protected: OpenGLVersion getVersionFromOpenGL() const override; + void initFeatures() override; }; } diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 2e293fe4..085b4459 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -21,6 +21,41 @@ namespace video { return {OpenGLSpec::ES, (u8)major, (u8)minor, 0}; } + void COpenGLES2Driver::initFeatures() { + assert (Version.Major >= 2); + if (Version.Major >= 3) + initExtensionsNew(); + else + initExtensionsOld(); + + // COGLESCoreExtensionHandler::Feature + static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed"); + Feature.BlendOperation = true; + Feature.ColorAttachment = 1; + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers]) + Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers]) + Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + + // COGLESCoreExtensionHandler + if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) + MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_range_elements]) + MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias]) + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); + + if (Version.Major >= 3 || FeatureAvailable[IRR_GL_ARB_framebuffer_object]) { + GLint val = 0; + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val); + StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT; + } + } + IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) { os::Printer::log("Using COpenGLES2Driver", ELL_INFORMATION); diff --git a/source/Irrlicht/OpenGLES2/Driver.h b/source/Irrlicht/OpenGLES2/Driver.h index 3dc234d7..327b4cf8 100644 --- a/source/Irrlicht/OpenGLES2/Driver.h +++ b/source/Irrlicht/OpenGLES2/Driver.h @@ -19,6 +19,7 @@ namespace video { protected: OpenGLVersion getVersionFromOpenGL() const override; + void initFeatures() override; }; } From 5f88555ed362fb1678074b1ae7e5352096cf5ef2 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 18:17:45 +0300 Subject: [PATCH 108/123] OpenGL3: restore MRT support --- source/Irrlicht/OpenGL/ExtensionHandler.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index e19a3bf0..fcf771e0 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -145,10 +145,12 @@ namespace video inline void irrGlDrawBuffer(GLenum mode) { + glDrawBuffer(mode); } inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) { + glDrawBuffers(n, bufs); } inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) From efb660e7ed265cbf018f6639d2dbf7eb3a52f12a Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 18:17:59 +0300 Subject: [PATCH 109/123] OpenGL3: drop unused ExtensionHandler functions --- source/Irrlicht/OpenGL/ExtensionHandler.h | 32 ----------------------- 1 file changed, 32 deletions(-) diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index fcf771e0..5bd1dad5 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -139,10 +139,6 @@ namespace video glGenerateMipmap(target); } - inline void irrGlActiveStencilFace(GLenum face) - { - } - inline void irrGlDrawBuffer(GLenum mode) { glDrawBuffer(mode); @@ -163,34 +159,6 @@ namespace video 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) - { - } - private: void addExtension(const char *name); }; From 8cf02ea27f42b8735c0b31c420740476ea027b78 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 19:33:23 +0300 Subject: [PATCH 110/123] OpenGL3: ExtensionHandler::initExtensionsNew: use GetInteger --- source/Irrlicht/OpenGL/ExtensionHandler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index f9858bea..40ecba8c 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -29,8 +29,7 @@ namespace video void COpenGL3ExtensionHandler::initExtensionsNew() { - GLint ext_count = 0; - GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count); + int ext_count = GetInteger(GL_NUM_EXTENSIONS); for (int k = 0; k < ext_count; k++) addExtension(reinterpret_cast(GL.GetStringi(GL_EXTENSIONS, k))); } From 523590e16c3091de56b11f3c36a1bfc06eeb0c92 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 20:12:42 +0300 Subject: [PATCH 111/123] OpenGL3: Refuse 3.0 and 3.1 --- source/Irrlicht/OpenGL3/Driver.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index ad886298..228cae9a 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -29,6 +29,8 @@ namespace video { void COpenGL3Driver::initFeatures() { assert (Version.Spec == OpenGLSpec::Compat); assert (Version.Major >= 3); + if (Version.Major == 3) + assert (Version.Minor >= 2); initExtensionsNew(); // COGLESCoreExtensionHandler::Feature From df07b3bf991856f4fc0c9e069bc5f01ee26ed639 Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 15 Apr 2023 20:11:11 +0300 Subject: [PATCH 112/123] OpenGL3: Remove stencil buffer presence test --- source/Irrlicht/OpenGL3/Driver.cpp | 4 ---- source/Irrlicht/OpenGLES2/Driver.cpp | 6 ------ 2 files changed, 10 deletions(-) diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 228cae9a..0926e744 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -49,10 +49,6 @@ namespace video { glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); DimAliasedPoint[0] = 1.0f; DimAliasedPoint[1] = 1.0f; - - GLint val = 0; - glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val); - StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT; } IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 085b4459..4293d956 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -48,12 +48,6 @@ namespace video { glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); - - if (Version.Major >= 3 || FeatureAvailable[IRR_GL_ARB_framebuffer_object]) { - GLint val = 0; - glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val); - StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT; - } } IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) From 78d0819a2c2275c69cfb66c87b20b70f83a282a5 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 16 Apr 2023 00:20:30 +0300 Subject: [PATCH 113/123] Add missing include --- source/Irrlicht/OpenGL3/Driver.cpp | 1 + source/Irrlicht/OpenGLES2/Driver.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 0926e744..7f63a45a 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Irrlicht.h #include "Driver.h" +#include namespace irr { namespace video { diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 4293d956..714a9da3 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Irrlicht.h #include "Driver.h" +#include namespace irr { namespace video { From 2e477a07d1ed5b599794f8cc882fd3805cec85ce Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 16 Apr 2023 01:00:41 +0300 Subject: [PATCH 114/123] OpenGL3: Add version check helper --- source/Irrlicht/OpenGL/Driver.cpp | 8 ++++++++ source/Irrlicht/OpenGL/Driver.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 4148657b..2274aa9a 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -214,6 +214,14 @@ COpenGL3DriverBase::~COpenGL3DriverBase() Version = getVersionFromOpenGL(); } + bool COpenGL3DriverBase::isVersionAtLeast(int major, int minor) const noexcept { + if (Version.Major < major) + return false; + if (Version.Major > major) + return true; + return Version.Minor >= minor; + } + bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) { initVersion(); diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index b0ba42b1..0b5a3854 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -290,6 +290,8 @@ namespace video virtual void initFeatures() = 0; + bool isVersionAtLeast(int major, int minor = 0) const noexcept; + void chooseMaterial2D(); ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override; From 44f7c22bbf0eef69a0190d7325306b0cbe1b1fdf Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 16 Apr 2023 01:03:33 +0300 Subject: [PATCH 115/123] OpenGL3: Version asserts --- source/Irrlicht/OpenGL3/Driver.cpp | 4 +--- source/Irrlicht/OpenGLES2/Driver.cpp | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 7f63a45a..e3d7714c 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -29,9 +29,7 @@ namespace video { void COpenGL3Driver::initFeatures() { assert (Version.Spec == OpenGLSpec::Compat); - assert (Version.Major >= 3); - if (Version.Major == 3) - assert (Version.Minor >= 2); + assert (isVersionAtLeast(3, 2)); initExtensionsNew(); // COGLESCoreExtensionHandler::Feature diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 714a9da3..0055bd8a 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -23,6 +23,7 @@ namespace video { } void COpenGLES2Driver::initFeatures() { + assert (Version.Spec == OpenGLSpec::ES); assert (Version.Major >= 2); if (Version.Major >= 3) initExtensionsNew(); From 13680ef42d35fbfb5ad5b5876b95c190229a93e1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 16 Apr 2023 17:58:43 +0300 Subject: [PATCH 116/123] OpenGL3: Use DrawBuffer[s] from mt_opengl --- source/Irrlicht/OpenGL/ExtensionHandler.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index 5bd1dad5..913b9bd0 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -9,6 +9,7 @@ #include "EDriverFeatures.h" #include "irrTypes.h" #include "os.h" +#include #include "Common.h" @@ -141,12 +142,12 @@ namespace video inline void irrGlDrawBuffer(GLenum mode) { - glDrawBuffer(mode); + GL.DrawBuffer(mode); } inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) { - glDrawBuffers(n, bufs); + GL.DrawBuffers(n, bufs); } inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) From 81ad195aa31b7cb7c54de9910791b0288b3d228b Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 20 Apr 2023 17:37:15 +0300 Subject: [PATCH 117/123] OpenGL3: New extension listing system --- source/Irrlicht/COGLESCoreExtensionHandler.h | 6 +---- source/Irrlicht/OpenGL/Driver.cpp | 6 ++--- source/Irrlicht/OpenGL/ExtensionHandler.cpp | 24 ++++++++++++-------- source/Irrlicht/OpenGL/ExtensionHandler.h | 12 +++++++++- source/Irrlicht/OpenGL3/Driver.cpp | 7 ++++-- source/Irrlicht/OpenGLES2/Driver.cpp | 14 ++++++++---- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/source/Irrlicht/COGLESCoreExtensionHandler.h b/source/Irrlicht/COGLESCoreExtensionHandler.h index 4ac8b2c5..1b4a2bb3 100644 --- a/source/Irrlicht/COGLESCoreExtensionHandler.h +++ b/source/Irrlicht/COGLESCoreExtensionHandler.h @@ -334,8 +334,6 @@ namespace video IRR_GL_SUN_multi_draw_arrays, // 69 IRR_GL_VIV_shader_binary, // 85 WGL_ARB_context_flush_control, // 191 - IRR_GL_EXT_draw_range_elements, // 112 again? - IRR_GL_ARB_framebuffer_object, // 45 again? IRR_OGLES_Feature_Count }; @@ -687,9 +685,7 @@ namespace video "GL_QCOM_writeonly_rendering", "GL_SUN_multi_draw_arrays", "GL_VIV_shader_binary", - "WGL_ARB_context_flush_control", - "GL_EXT_draw_range_elements", - "GL_ARB_framebuffer_object", + "WGL_ARB_context_flush_control" }; return OGLESFeatureStrings[index]; diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 2274aa9a..cb9f5ca1 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1504,16 +1504,14 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } - #ifdef GL_EXT_texture_filter_anisotropic - if (FeatureAvailable[COGLESCoreExtensionHandler::IRR_GL_EXT_texture_filter_anisotropic] && + if (AnisotropicFilterSupported && (!tmpTexture->getStatesCache().IsCached || material.TextureLayer[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter)) { - glTexParameteri(tmpTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, + glTexParameteri(tmpTextureType, GL.TEXTURE_MAX_ANISOTROPY, 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) { diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index 40ecba8c..2e9757ba 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -20,11 +20,11 @@ namespace video auto extensions_string = reinterpret_cast(glGetString(GL_EXTENSIONS)); const char *pos = extensions_string; while (const char *next = strchr(pos, ' ')) { - std::string name{pos, next}; - addExtension(name.c_str()); + addExtension(std::string{pos, next}); pos = next + 1; } addExtension(pos); + updateLegacyExtensionList(); } void COpenGL3ExtensionHandler::initExtensionsNew() @@ -32,15 +32,21 @@ namespace video int ext_count = GetInteger(GL_NUM_EXTENSIONS); for (int k = 0; k < ext_count; k++) addExtension(reinterpret_cast(GL.GetStringi(GL_EXTENSIONS, k))); + updateLegacyExtensionList(); } - void COpenGL3ExtensionHandler::addExtension(const char *name) { - for (size_t j=0; j + #include "EDriverFeatures.h" #include "irrTypes.h" #include "os.h" @@ -28,6 +30,9 @@ namespace video void initExtensionsOld(); void initExtensionsNew(); + /// Checks whether a named extension is present + bool queryExtension(const std::string &name) const noexcept; + bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const { switch (feature) @@ -160,8 +165,13 @@ namespace video glBlendEquation(mode); } + bool AnisotropicFilterSupported = false; + private: - void addExtension(const char *name); + void addExtension(std::string name); + void updateLegacyExtensionList(); + + std::unordered_set Extensions; }; } diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index e3d7714c..41650044 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -4,6 +4,7 @@ #include "Driver.h" #include +#include "mt_opengl.h" namespace irr { namespace video { @@ -32,6 +33,8 @@ namespace video { assert (isVersionAtLeast(3, 2)); initExtensionsNew(); + AnisotropicFilterSupported = isVersionAtLeast(4, 6) || queryExtension("GL_ARB_texture_filter_anisotropic") || queryExtension("GL_EXT_texture_filter_anisotropic"); + // COGLESCoreExtensionHandler::Feature static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); Feature.BlendOperation = true; @@ -40,8 +43,8 @@ namespace video { Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); // COGLESCoreExtensionHandler - if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) - MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + if (AnisotropicFilterSupported) + MaxAnisotropy = GetInteger(GL.MAX_TEXTURE_MAX_ANISOTROPY); MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 0055bd8a..c899a7b0 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -30,23 +30,27 @@ namespace video { else initExtensionsOld(); + const bool MRTSupported = Version.Major >= 3 || queryExtension("GL_EXT_draw_buffers"); + AnisotropicFilterSupported = queryExtension("GL_EXT_texture_filter_anisotropic"); + const bool TextureLODBiasSupported = queryExtension("GL_EXT_texture_lod_bias"); + // COGLESCoreExtensionHandler::Feature static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed"); Feature.BlendOperation = true; Feature.ColorAttachment = 1; - if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers]) + if (MRTSupported) Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; - if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers]) + if (MRTSupported) Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); // COGLESCoreExtensionHandler - if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic]) + if (AnisotropicFilterSupported) MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); - if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_range_elements]) + if (Version.Major >= 3 || queryExtension("GL_EXT_draw_range_elements")) MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); - if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias]) + if (TextureLODBiasSupported) glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); From 1f15fd0805766b0ef87c894a06d2aba6cba66f7b Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 20 Apr 2023 17:44:14 +0300 Subject: [PATCH 118/123] OpenGL3: Support min/max blend modes --- source/Irrlicht/OpenGL/Driver.cpp | 12 ++++++++++++ source/Irrlicht/OpenGL/ExtensionHandler.h | 1 + source/Irrlicht/OpenGL3/Driver.cpp | 1 + source/Irrlicht/OpenGLES2/Driver.cpp | 1 + 4 files changed, 15 insertions(+) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index cb9f5ca1..8994be63 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1405,6 +1405,18 @@ COpenGL3DriverBase::~COpenGL3DriverBase() case EBO_REVSUBTRACT: CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); break; + case EBO_MIN: + if (BlendMinMaxSupported) + CacheHandler->setBlendEquation(GL_MIN); + else + os::Printer::log("Attempt to use EBO_MIN without driver support", ELL_WARNING); + break; + case EBO_MAX: + if (BlendMinMaxSupported) + CacheHandler->setBlendEquation(GL_MAX); + else + os::Printer::log("Attempt to use EBO_MAX without driver support", ELL_WARNING); + break; default: break; } diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index 9645823f..57106f0c 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -166,6 +166,7 @@ namespace video } bool AnisotropicFilterSupported = false; + bool BlendMinMaxSupported = false; private: void addExtension(std::string name); diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 41650044..66574793 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -34,6 +34,7 @@ namespace video { initExtensionsNew(); AnisotropicFilterSupported = isVersionAtLeast(4, 6) || queryExtension("GL_ARB_texture_filter_anisotropic") || queryExtension("GL_EXT_texture_filter_anisotropic"); + BlendMinMaxSupported = true; // COGLESCoreExtensionHandler::Feature static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index c899a7b0..5766e8a5 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -32,6 +32,7 @@ namespace video { const bool MRTSupported = Version.Major >= 3 || queryExtension("GL_EXT_draw_buffers"); AnisotropicFilterSupported = queryExtension("GL_EXT_texture_filter_anisotropic"); + BlendMinMaxSupported = (Version.Major >= 3) || FeatureAvailable[IRR_GL_EXT_blend_minmax]; const bool TextureLODBiasSupported = queryExtension("GL_EXT_texture_lod_bias"); // COGLESCoreExtensionHandler::Feature From 6a2a56923351a65c6b79008f51aef0a40db31795 Mon Sep 17 00:00:00 2001 From: Desour Date: Thu, 13 Apr 2023 23:00:58 +0200 Subject: [PATCH 119/123] Add IImage::copyToNoScaling (Useful for const-correctness.) --- include/IImage.h | 6 ++++ source/Irrlicht/CImage.cpp | 71 ++++++++++++++++++++++++-------------- source/Irrlicht/CImage.h | 3 ++ 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/include/IImage.h b/include/IImage.h index 20d3d54e..2e090a2a 100644 --- a/include/IImage.h +++ b/include/IImage.h @@ -329,6 +329,12 @@ public: //! Sets a pixel virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend = false ) = 0; + //! Copies this surface into another, if it has the exact same size and format. + /** NOTE: mipmaps are ignored + \return True if it was copied, false otherwise. + */ + virtual bool copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0) const = 0; + //! Copies the image into the target, scaling the image to fit /** NOTE: mipmaps are ignored */ virtual void copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0) =0; diff --git a/source/Irrlicht/CImage.cpp b/source/Irrlicht/CImage.cpp index 5d1e9fa1..5c27a77a 100644 --- a/source/Irrlicht/CImage.cpp +++ b/source/Irrlicht/CImage.cpp @@ -173,6 +173,50 @@ void CImage::copyToWithAlpha(IImage* target, const core::position2d& pos, c } +//! copies this surface into another, if it has the exact same size and format. +bool CImage::copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format, u32 pitch) const +{ + if (IImage::isCompressedFormat(Format)) + { + os::Printer::log("IImage::copyToNoScaling method doesn't work with compressed images.", ELL_WARNING); + return false; + } + + if (!target || !width || !height || !Size.Width || !Size.Height) + return false; + + const u32 bpp=getBitsPerPixelFromFormat(format)/8; + if (0==pitch) + pitch = width*bpp; + + if (!(Format==format && Size.Width==width && Size.Height==height)) + return false; + + if (pitch==Pitch) + { + memcpy(target, Data, (size_t)height*pitch); + } + else + { + u8* tgtpos = (u8*) target; + u8* srcpos = Data; + const u32 bwidth = width*bpp; + const u32 rest = pitch-bwidth; + for (u32 y=0; y Date: Sat, 25 Mar 2023 01:40:13 +0100 Subject: [PATCH 120/123] Add the platform-dependent stuff from renderingengine.cpp --- include/IrrlichtDevice.h | 9 ++ source/Irrlicht/CIrrDeviceLinux.cpp | 136 ++++++++++++++++++++++++++++ source/Irrlicht/CIrrDeviceLinux.h | 8 ++ source/Irrlicht/CIrrDeviceStub.cpp | 13 +++ source/Irrlicht/CIrrDeviceStub.h | 6 ++ source/Irrlicht/CIrrDeviceWin32.cpp | 31 +++++++ source/Irrlicht/CIrrDeviceWin32.h | 6 ++ 7 files changed, 209 insertions(+) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index c6a19787..4fc5be22 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -132,6 +132,11 @@ namespace irr /** \param text: New text of the window caption. */ virtual void setWindowCaption(const wchar_t* text) = 0; + //! Sets the window icon. + /** \param img The icon texture. + \return False if no icon was set. */ + virtual bool setWindowIcon(const video::IImage *img) = 0; + //! Returns if the window is active. /** If the window is inactive, nothing needs to be drawn. So if you don't want to draw anything @@ -307,6 +312,10 @@ namespace irr used. */ virtual E_DEVICE_TYPE getType() const = 0; + //! Get the display density in dots per inch. + //! Returns 0.0f on failure. + virtual float getDisplayDensity() const = 0; + //! Check if a driver type is supported by the engine. /** Even if true is returned the driver may not be available for a configuration requested when creating the device. */ diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index 0efc8f4f..9d4033b5 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -24,6 +24,8 @@ #include "SIrrCreationParameters.h" #include "SExposedVideoData.h" #include "IGUISpriteBank.h" +#include "IImageLoader.h" +#include "IFileSystem.h" #include #include @@ -171,6 +173,8 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param) if (param.WindowMaximized) maximizeWindow(); + + setupTopLevelXorgWindow(); } @@ -282,6 +286,72 @@ bool CIrrDeviceLinux::switchToFullscreen() } +void CIrrDeviceLinux::setupTopLevelXorgWindow() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType == video::EDT_NULL) + return; // no display and window + + os::Printer::log("Configuring X11-specific top level window properties", ELL_DEBUG); + + // Set application name and class hints. For now name and class are the same. + // Note: SDL uses the executable name here (i.e. "minetest"). + XClassHint *classhint = XAllocClassHint(); + classhint->res_name = const_cast("Minetest"); + classhint->res_class = const_cast("Minetest"); + + XSetClassHint(XDisplay, XWindow, classhint); + XFree(classhint); + + // FIXME: In the future WMNormalHints should be set ... e.g see the + // gtk/gdk code (gdk/x11/gdksurface-x11.c) for the setup_top_level + // method. But for now (as it would require some significant changes) + // leave the code as is. + + // The following is borrowed from the above gdk source for setting top + // level windows. The source indicates and the Xlib docs suggest that + // this will set the WM_CLIENT_MACHINE and WM_LOCAL_NAME. This will not + // set the WM_CLIENT_MACHINE to a Fully Qualified Domain Name (FQDN) which is + // required by the Extended Window Manager Hints (EWMH) spec when setting + // the _NET_WM_PID (see further down) but running Minetest in an env + // where the window manager is on another machine from Minetest (therefore + // making the PID useless) is not expected to be a problem. Further + // more, using gtk/gdk as the model it would seem that not using a FQDN is + // not an issue for modern Xorg window managers. + + os::Printer::log("Setting Xorg window manager Properties", ELL_DEBUG); + + XSetWMProperties (XDisplay, XWindow, NULL, NULL, NULL, 0, NULL, NULL, NULL); + + // Set the _NET_WM_PID window property according to the EWMH spec. _NET_WM_PID + // (in conjunction with WM_CLIENT_MACHINE) can be used by window managers to + // force a shutdown of an application if it doesn't respond to the destroy + // window message. + + os::Printer::log("Setting Xorg _NET_WM_PID extended window manager property", ELL_DEBUG); + + Atom NET_WM_PID = XInternAtom(XDisplay, "_NET_WM_PID", false); + + pid_t pid = getpid(); + + XChangeProperty(XDisplay, XWindow, NET_WM_PID, + XA_CARDINAL, 32, PropModeReplace, + reinterpret_cast(&pid),1); + + // Set the WM_CLIENT_LEADER window property here. Minetest has only one + // window and that window will always be the leader. + + os::Printer::log("Setting Xorg WM_CLIENT_LEADER property", ELL_DEBUG); + + Atom WM_CLIENT_LEADER = XInternAtom(XDisplay, "WM_CLIENT_LEADER", false); + + XChangeProperty (XDisplay, XWindow, WM_CLIENT_LEADER, + XA_WINDOW, 32, PropModeReplace, + reinterpret_cast(&XWindow), 1); +#endif +} + + #if defined(_IRR_COMPILE_WITH_X11_) void IrrPrintXGrabError(int grabResult, const c8 * grabCommand ) { @@ -1178,6 +1248,50 @@ void CIrrDeviceLinux::setWindowCaption(const wchar_t* text) } +//! Sets the window icon. +bool CIrrDeviceLinux::setWindowIcon(const video::IImage *img) +{ + if (CreationParams.DriverType == video::EDT_NULL) + return false; // no display and window + + u32 height = img->getDimension().Height; + u32 width = img->getDimension().Width; + + size_t icon_buffer_len = 2 + height * width; + long *icon_buffer = new long[icon_buffer_len]; + + icon_buffer[0] = width; + icon_buffer[1] = height; + + for (u32 x = 0; x < width; x++) { + for (u32 y = 0; y < height; y++) { + video::SColor col = img->getPixel(x, y); + long pixel_val = 0; + pixel_val |= (u8)col.getAlpha() << 24; + pixel_val |= (u8)col.getRed() << 16; + pixel_val |= (u8)col.getGreen() << 8; + pixel_val |= (u8)col.getBlue(); + icon_buffer[2 + x + y * width] = pixel_val; + } + } + + if (XDisplay == NULL) { + os::Printer::log("Could not find x11 display for setting its icon.", ELL_ERROR); + delete[] icon_buffer; + return false; + } + + Atom net_wm_icon = XInternAtom(XDisplay, "_NET_WM_ICON", False); + Atom cardinal = XInternAtom(XDisplay, "CARDINAL", False); + XChangeProperty(XDisplay, XWindow, net_wm_icon, cardinal, 32, PropModeReplace, + (const unsigned char *)icon_buffer, icon_buffer_len); + + delete[] icon_buffer; + + return true; +} + + //! notifies the device that it should close itself void CIrrDeviceLinux::closeDevice() { @@ -1866,6 +1980,28 @@ void CIrrDeviceLinux::clearSystemMessages() #endif //_IRR_COMPILE_WITH_X11_ } +//! Get the display density in dots per inch. +float CIrrDeviceLinux::getDisplayDensity() const +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (XDisplay != NULL) { + /* try x direct */ + int dh = DisplayHeight(XDisplay, 0); + int dw = DisplayWidth(XDisplay, 0); + int dh_mm = DisplayHeightMM(XDisplay, 0); + int dw_mm = DisplayWidthMM(XDisplay, 0); + + if (dh_mm != 0 && dw_mm != 0) { + float dpi_height = floor(dh / (dh_mm * 0.039370) + 0.5); + float dpi_width = floor(dw / (dw_mm * 0.039370) + 0.5); + return std::max(dpi_height, dpi_width); + } + } +#endif //_IRR_COMPILE_WITH_X11_ + + return 0.0f; +} + void CIrrDeviceLinux::initXAtoms() { #ifdef _IRR_COMPILE_WITH_X11_ diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index 544a7364..5ac6eae9 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -54,6 +54,9 @@ namespace irr //! sets the caption of the window void setWindowCaption(const wchar_t* text) override; + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + //! returns if window is active. if not, nothing need to be drawn bool isWindowActive() const override; @@ -120,6 +123,9 @@ namespace irr return EIDT_X11; } + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + #ifdef _IRR_COMPILE_WITH_X11_ // convert an Irrlicht texture to a X11 cursor Cursor TextureToCursor(irr::video::ITexture * tex, const core::rect& sourceRect, const core::position2d &hotspot); @@ -146,6 +152,8 @@ namespace irr bool switchToFullscreen(); + void setupTopLevelXorgWindow(); + #ifdef _IRR_COMPILE_WITH_X11_ bool createInputContext(); void destroyInputContext(); diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index 3fde44ac..647257c7 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -136,6 +136,13 @@ ITimer* CIrrDeviceStub::getTimer() } +//! Sets the window icon. +bool CIrrDeviceStub::setWindowIcon(const video::IImage *img) +{ + return false; +} + + //! Returns the version of the engine. const char* CIrrDeviceStub::getVersion() const { @@ -385,6 +392,12 @@ void CIrrDeviceStub::clearSystemMessages() { } +//! Get the display density in dots per inch. +float CIrrDeviceStub::getDisplayDensity() const +{ + return 0.0f; +} + //! Checks whether the input device should take input from the IME bool CIrrDeviceStub::acceptsIME() { diff --git a/source/Irrlicht/CIrrDeviceStub.h b/source/Irrlicht/CIrrDeviceStub.h index 10e5d72e..3ffa8f38 100644 --- a/source/Irrlicht/CIrrDeviceStub.h +++ b/source/Irrlicht/CIrrDeviceStub.h @@ -71,6 +71,9 @@ namespace irr //! Returns a pointer to the ITimer object. With it the current Time can be received. ITimer* getTimer() override; + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + //! Returns the version of the engine. const char* getVersion() const override; @@ -151,6 +154,9 @@ namespace irr //! Remove all messages pending in the system message loop void clearSystemMessages() override; + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + //! Resize the render window. void setWindowSize(const irr::core::dimension2d& size) override {} diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index 7b12232c..5eb0680a 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -1112,6 +1112,26 @@ void CIrrDeviceWin32::setWindowCaption(const wchar_t* text) } +//! Sets the window icon. +bool CIrrDeviceWin32::setWindowIcon(const video::IImage *img) +{ + // Ignore the img, instead load the ICON from resource file + // (This is minetest-specific!) + const HICON hicon = LoadIcon(GetModuleHandle(NULL), + MAKEINTRESOURCE(130) // The ID of the ICON defined in + // winresource.rc + ); + + if (hicon) { + SendMessage(HWnd, WM_SETICON, ICON_BIG, reinterpret_cast(hicon)); + SendMessage(HWnd, WM_SETICON, ICON_SMALL, + reinterpret_cast(hicon)); + return true; + } + return false; +} + + //! notifies the device that it should close itself void CIrrDeviceWin32::closeDevice() { @@ -1373,6 +1393,17 @@ void CIrrDeviceWin32::clearSystemMessages() {} } + +//! Get the display density in dots per inch. +float CIrrDeviceWin32::getDisplayDensity() const +{ + HDC hdc = GetDC(HWnd); + float dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(HWnd, hdc); + return dpi; +} + + // Convert an Irrlicht texture to a Windows cursor // Based on http://www.codeguru.com/cpp/w-p/win32/cursors/article.php/c4529/ HCURSOR CIrrDeviceWin32::TextureToCursor(HWND hwnd, irr::video::ITexture * tex, const core::rect& sourceRect, const core::position2d &hotspot) diff --git a/source/Irrlicht/CIrrDeviceWin32.h b/source/Irrlicht/CIrrDeviceWin32.h index 9ca44acc..6737e780 100644 --- a/source/Irrlicht/CIrrDeviceWin32.h +++ b/source/Irrlicht/CIrrDeviceWin32.h @@ -47,6 +47,9 @@ namespace irr //! sets the caption of the window void setWindowCaption(const wchar_t* text) override; + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + //! returns if window is active. if not, nothing need to be drawn bool isWindowActive() const override; @@ -96,6 +99,9 @@ namespace irr return EIDT_WIN32; } + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + //! Compares to the last call of this function to return double and triple clicks. //! \return Returns only 1,2 or 3. A 4th click will start with 1 again. u32 checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_EVENT inputEvent ) override From 49b6ccde72a2a438f4ffade974a4d36b624d5a48 Mon Sep 17 00:00:00 2001 From: Desour Date: Sat, 25 Mar 2023 02:52:42 +0100 Subject: [PATCH 121/123] SDL: Implement getDisplayDensity() and setWindowIcon() --- source/Irrlicht/CIrrDeviceSDL.cpp | 62 ++++++++++++++++++++++++++++++- source/Irrlicht/CIrrDeviceSDL.h | 6 +++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index c1e7527b..96c834f6 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -9,6 +9,8 @@ #include "IEventReceiver.h" #include "IGUIElement.h" #include "IGUIEnvironment.h" +#include "IImageLoader.h" +#include "IFileSystem.h" #include "os.h" #include "CTimer.h" #include "irrString.h" @@ -243,7 +245,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) #endif if (SDL_Init(flags) < 0) { - os::Printer::log("Unable to initialize SDL!", SDL_GetError()); + os::Printer::log("Unable to initialize SDL", SDL_GetError(), ELL_ERROR); Close = true; } else @@ -871,6 +873,29 @@ bool CIrrDeviceSDL::activateJoysticks(core::array & joystickInfo) return false; } + +//! Get the display density in dots per inch. +float CIrrDeviceSDL::getDisplayDensity() const +{ + if (!Window) + return 0.0f; + + int window_w; + int window_h; + SDL_GetWindowSize(Window, &window_w, &window_h); + + int drawable_w; + int drawable_h; + SDL_GL_GetDrawableSize(Window, &drawable_w, &drawable_h); + + // assume 96 dpi + float dpi_w = (float)drawable_w / (float)window_w * 96.0f; + float dpi_h = (float)drawable_h / (float)window_h * 96.0f; + + return std::max(dpi_w, dpi_h); +} + + void CIrrDeviceSDL::SwapWindow() { SDL_GL_SwapWindow(Window); @@ -908,6 +933,41 @@ void CIrrDeviceSDL::setWindowCaption(const wchar_t* text) } +//! Sets the window icon. +bool CIrrDeviceSDL::setWindowIcon(const video::IImage *img) +{ + if (!Window) + return false; + + u32 height = img->getDimension().Height; + u32 width = img->getDimension().Width; + + SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 32, + 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + + if (!surface) { + os::Printer::log("Failed to create SDL suface", ELL_ERROR); + return false; + } + + SDL_LockSurface(surface); + bool succ = img->copyToNoScaling(surface->pixels, width, height, video::ECF_A8R8G8B8, surface->pitch); + SDL_UnlockSurface(surface); + + if (!succ) { + os::Printer::log("Could not copy icon image. Is the format not ECF_A8R8G8B8?", ELL_ERROR); + SDL_FreeSurface(surface); + return false; + } + + SDL_SetWindowIcon(Window, surface); + + SDL_FreeSurface(surface); + + return true; +} + + //! notifies the device that it should close itself void CIrrDeviceSDL::closeDevice() { diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 4dbb2e76..35a2a069 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -48,6 +48,9 @@ namespace irr //! sets the caption of the window void setWindowCaption(const wchar_t* text) override; + //! Sets the window icon. + bool setWindowIcon(const video::IImage *img) override; + //! returns if window is active. if not, nothing need to be drawn bool isWindowActive() const override; @@ -94,6 +97,9 @@ namespace irr return EIDT_SDL; } + //! Get the display density in dots per inch. + float getDisplayDensity() const override; + void SwapWindow(); //! Implementation of the linux cursor control From 1387370260330a4c8500634c8c24cc699639d039 Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 20 Apr 2023 17:40:51 +0300 Subject: [PATCH 122/123] OpenGL3: Sort out texture color format support --- source/Irrlicht/OpenGL/Driver.cpp | 223 +--------------------- source/Irrlicht/OpenGL/Driver.h | 9 + source/Irrlicht/OpenGL/ExtensionHandler.h | 14 +- source/Irrlicht/OpenGL3/Driver.cpp | 18 ++ source/Irrlicht/OpenGLES2/Driver.cpp | 71 +++++++ 5 files changed, 107 insertions(+), 228 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 8994be63..f49228ba 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -2111,226 +2111,17 @@ COpenGL3DriverBase::~COpenGL3DriverBase() 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; + auto &info = TextureFormats[format]; + internalFormat = info.InternalFormat; + pixelFormat = info.PixelFormat; + pixelType = info.PixelType; + *converter = info.Converter; + return info.InternalFormat != 0; } 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); + return TextureFormats[format].InternalFormat != 0; } bool COpenGL3DriverBase::needsTransparentRenderPass(const irr::video::SMaterial& material) const diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 0b5a3854..862c79d5 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -365,6 +365,15 @@ namespace video core::matrix4 TextureFlipMatrix; + using FColorConverter = void(*)(const void *source, s32 count, void *dest); + struct STextureFormatInfo { + GLenum InternalFormat; + GLenum PixelFormat; + GLenum PixelType; + FColorConverter Converter; + }; + STextureFormatInfo TextureFormats[ECF_UNKNOWN] = {}; + private: COpenGL3Renderer2D* MaterialRenderer2DActive; diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index 57106f0c..84641dd4 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -70,16 +70,6 @@ namespace video 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: @@ -101,13 +91,13 @@ namespace video 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); + os::Printer::log("Compressed textures aren't supported", ELL_ERROR); } 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); + os::Printer::log("Compressed textures aren't supported", ELL_ERROR); } inline void irrGlUseProgram(GLuint prog) diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 66574793..70343a85 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -33,6 +33,24 @@ namespace video { assert (isVersionAtLeast(3, 2)); initExtensionsNew(); + TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable + TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; // GL_RGB565 is an extension until 4.1 + TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; // WARNING: may not be renderable + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}; + TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; + TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; + TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; + TextureFormats[ECF_R32F] = {GL_R32F, GL_RED, GL_FLOAT}; + TextureFormats[ECF_G32R32F] = {GL_RG32F, GL_RG, GL_FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA32F, GL_RGBA, GL_FLOAT}; + TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R16] = {GL_R16, GL_RED, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_R16G16] = {GL_RG16, GL_RG, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; // WARNING: may not be renderable (?!) + TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + AnisotropicFilterSupported = isVersionAtLeast(4, 6) || queryExtension("GL_ARB_texture_filter_anisotropic") || queryExtension("GL_EXT_texture_filter_anisotropic"); BlendMinMaxSupported = true; diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 5766e8a5..2e80e1be 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -4,6 +4,7 @@ #include "Driver.h" #include +#include namespace irr { namespace video { @@ -30,6 +31,76 @@ namespace video { else initExtensionsOld(); + if (Version.Major >= 3) { + // NOTE floating-point formats may not be suitable for render targets. + TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; + TextureFormats[ECF_R5G6B5] = {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; + TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; + TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; + TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; + TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; + TextureFormats[ECF_R32F] = {GL_R32F, GL_RED, GL_FLOAT}; + TextureFormats[ECF_G32R32F] = {GL_RG32F, GL_RG, GL_FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA32F, GL_RGBA, GL_FLOAT}; + TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + + if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE}; + else if (FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; + + if (FeatureAvailable[IRR_GL_OES_depth32]) + TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; + } else { + // NOTE These are *texture* formats. They may or may not be suitable + // for render targets. The specs only talks on *sized* formats for the + // latter but forbids creating textures with sized internal formats, + // reserving them for renderbuffers. + + static const GLenum HALF_FLOAT_OES = 0x8D61; // not equal to GL_HALF_FLOAT + TextureFormats[ECF_A1R5G5B5] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; + TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; + TextureFormats[ECF_R8G8B8] = {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; + + if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE}; + else if (FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) + TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; + + if (FeatureAvailable[IRR_GL_OES_texture_half_float]) { + TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA, GL_RGBA, HALF_FLOAT_OES}; + } + if (FeatureAvailable[IRR_GL_OES_texture_float]) { + TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA, GL_RGBA, GL_FLOAT}; + } + if (FeatureAvailable[IRR_GL_EXT_texture_rg]) { + TextureFormats[ECF_R8] = {GL_RED, GL_RED, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL_RG, GL_RG, GL_UNSIGNED_BYTE}; + + if (FeatureAvailable[IRR_GL_OES_texture_half_float]) { + TextureFormats[ECF_R16F] = {GL_RED, GL_RED, HALF_FLOAT_OES}; + TextureFormats[ECF_G16R16F] = {GL_RG, GL_RG, HALF_FLOAT_OES}; + } + if (FeatureAvailable[IRR_GL_OES_texture_float]) { + TextureFormats[ECF_R32F] = {GL_RED, GL_RED, GL_FLOAT}; + TextureFormats[ECF_G32R32F] = {GL_RG, GL_RG, GL_FLOAT}; + } + } + + if (FeatureAvailable[IRR_GL_OES_depth_texture]) { + TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + if (FeatureAvailable[IRR_GL_OES_depth32]) + TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; + if (FeatureAvailable[IRR_GL_OES_packed_depth_stencil]) + TextureFormats[ECF_D24S8] = {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + } + } + const bool MRTSupported = Version.Major >= 3 || queryExtension("GL_EXT_draw_buffers"); AnisotropicFilterSupported = queryExtension("GL_EXT_texture_filter_anisotropic"); BlendMinMaxSupported = (Version.Major >= 3) || FeatureAvailable[IRR_GL_EXT_blend_minmax]; From b958fdc271ed754836c688cb0d3e2b0b1d853047 Mon Sep 17 00:00:00 2001 From: numzero Date: Thu, 11 May 2023 21:47:20 +0300 Subject: [PATCH 123/123] Fix casing for Android device name (`MATCHES` is case sensitive) --- source/Irrlicht/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 0bb71e3b..2ddd04cd 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -201,14 +201,14 @@ if(ENABLE_GLES1) message(FATAL_ERROR "OpenGL ES 1 is not supported with SDL2") endif() 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_) endif() 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 "SDL") set(USE_SDLGL ON)