A few more changes to dx9

This commit is contained in:
Henrique 2013-02-20 19:12:52 -03:00
parent bb304f9f4e
commit 33ce0aa704
6 changed files with 127 additions and 4 deletions

View File

@ -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

View File

@ -31,6 +31,10 @@
#include "painterogl2.h"
#endif
#if defined(WIN32) && defined(DIRECTX)
#include "painterdx9.h"
#endif
#include <framework/graphics/graphics.h>
#include <framework/graphics/texture.h>
#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) {

View File

@ -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
#endif

View File

@ -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 {

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/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

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/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