diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 33f01d41..27a94365 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -346,6 +346,8 @@ if(FRAMEWORK_GRAPHICS) ${CMAKE_CURRENT_LIST_DIR}/graphics/painterogl1.h ${CMAKE_CURRENT_LIST_DIR}/graphics/painterogl2.cpp ${CMAKE_CURRENT_LIST_DIR}/graphics/painterogl2.h + ${CMAKE_CURRENT_LIST_DIR}/graphics/painterdx9.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphics/painterdx9.h ${CMAKE_CURRENT_LIST_DIR}/graphics/painterogl2_shadersources.h ${CMAKE_CURRENT_LIST_DIR}/graphics/paintershaderprogram.cpp ${CMAKE_CURRENT_LIST_DIR}/graphics/paintershaderprogram.h diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 1d98c616..432e30bb 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -31,6 +31,10 @@ #include "painterogl2.h" #endif +#if defined(WIN32) && defined(DIRECTX) +#include "painterdx9.h" +#endif + #include #include #include "texturemanager.h" @@ -50,6 +54,10 @@ void Graphics::init() g_logger.info(stdext::format("GPU %s", glGetString(GL_RENDERER))); g_logger.info(stdext::format("OpenGL %s", glGetString(GL_VERSION))); +#if defined(WIN32) && defined(DIRECTX) + g_painterDX9 = new PainterDX9; +#endif + #if OPENGL_ES==2 g_painterOGL2 = new PainterOGL2; #elif OPENGL_ES==1 @@ -157,6 +165,11 @@ bool Graphics::parseOption(const std::string& option) bool Graphics::isPainterEngineAvailable(Graphics::PainterEngine painterEngine) { +#if defined(WIN32) && defined(DIRECTX) + if(g_painterDX9 && painterEngine == Painter_DirectX9) + return true; +#endif + #ifdef PAINTER_OGL2 if(g_painterOGL2 && painterEngine == Painter_OpenGL2) return true; @@ -175,6 +188,21 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine) Painter *fallbackPainter = nullptr; PainterEngine fallbackPainterEngine = Painter_Any; +#ifdef PAINTER_DX9 + // use this to force directx if its enabled (avoid changes in options module, etc, will be removed) + painterEngine = Painter_DirectX9; + + // always prefer DirectX9 on Windows + if(g_painterDX9) { + if(!painter && (painterEngine == Painter_DirectX9 || painterEngine == Painter_Any)) { + m_selectedPainterEngine = Painter_DirectX9; + painter = g_painterDX9; + } + fallbackPainter = g_painterDX9; + fallbackPainterEngine = Painter_DirectX9; + } +#endif + #ifdef PAINTER_OGL2 // always prefer OpenGL 2 over OpenGL 1 if(g_painterOGL2) { diff --git a/src/framework/graphics/graphics.h b/src/framework/graphics/graphics.h index eb455101..6a5d6ab6 100644 --- a/src/framework/graphics/graphics.h +++ b/src/framework/graphics/graphics.h @@ -35,7 +35,8 @@ public: enum PainterEngine { Painter_Any = 0, Painter_OpenGL1, - Painter_OpenGL2 + Painter_OpenGL2, + Painter_DirectX9 }; // @dontbind @@ -99,4 +100,4 @@ private: extern Graphics g_graphics; -#endif \ No newline at end of file +#endif diff --git a/src/framework/graphics/painter.h b/src/framework/graphics/painter.h index 37fcd006..f84d9260 100644 --- a/src/framework/graphics/painter.h +++ b/src/framework/graphics/painter.h @@ -37,7 +37,7 @@ public: CompositionMode_Add, CompositionMode_Replace, CompositionMode_DestBlending, - CompositionMode_Light, + CompositionMode_Light }; enum DrawMode { Triangles = GL_TRIANGLES, @@ -45,7 +45,7 @@ public: }; enum BlendEquation { BlendEquation_Add = 0x8006, // GL_FUNC_ADD - BlendEquation_Max = 0x8008, // GL_MAX + BlendEquation_Max = 0x8008 // GL_MAX }; struct PainterState { diff --git a/src/framework/graphics/painterdx9.cpp b/src/framework/graphics/painterdx9.cpp new file mode 100644 index 00000000..9bd591ca --- /dev/null +++ b/src/framework/graphics/painterdx9.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010-2013 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#if defined(WIN32) && defined(DIRECTX) + +#include "painterdx9.h" +#include "graphics.h" + +PainterDX9 *g_painterDX9 = nullptr; + +PainterDX9::PainterDX9() +{ +} + +#endif diff --git a/src/framework/graphics/painterdx9.h b/src/framework/graphics/painterdx9.h new file mode 100644 index 00000000..21edc736 --- /dev/null +++ b/src/framework/graphics/painterdx9.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010-2013 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef PAINTERDX9_H +#define PAINTERDX9_H + +#define PAINTER_DX9 + +#include "painter.h" + +/** + * Painter using DirectX9 fixed-function rendering pipeline. + */ +class PainterDX9 : public Painter +{ +public: + PainterDX9(); + + void bind() {} + void unbind() {} + + void refreshState() {} + + void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles) {} + void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture) {} + void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) {} + void drawUpsideDownTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) {} + void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) {} + void drawFilledRect(const Rect& dest) {} + void drawFilledTriangle(const Point& a, const Point& b, const Point& c) {} + void drawBoundingRect(const Rect& dest, int innerLineWidth) {} + + bool hasShaders() { return false; } + +}; + +extern PainterDX9 *g_painterDX9; + +#endif