Otclient  14/8/2020
graphics.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef GRAPHICS_H
24 #define GRAPHICS_H
25 
26 #include "declarations.h"
27 #include "painter.h"
28 
29 // @bindsingleton g_graphics
30 class Graphics
31 {
32 public:
33  Graphics();
34 
40  };
41 
42  // @dontbind
43  void init();
44  // @dontbind
45  void terminate();
46 
47  bool parseOption(const std::string& option);
48 
49  bool isPainterEngineAvailable(PainterEngine painterEngine);
50  bool selectPainterEngine(PainterEngine painterEngine);
51  PainterEngine getPainterEngine() { return m_selectedPainterEngine; }
52 
53  void resize(const Size& size);
54 
55  int getMaxTextureSize() { return m_maxTextureSize; }
56  const Size& getViewportSize() { return m_viewportSize; }
57 
58  std::string getVendor() { return (const char*)glGetString(GL_VENDOR); }
59  std::string getRenderer() { return (const char*)glGetString(GL_RENDERER); }
60  std::string getVersion() { return (const char*)glGetString(GL_VERSION); }
61  std::string getExtensions() { return (const char*)glGetString(GL_EXTENSIONS); }
62 
63  void setShouldUseShaders(bool enable) { m_shouldUseShaders = enable; }
64 
65  bool ok() { return m_ok; }
66  bool canUseDrawArrays();
67  bool canUseShaders();
68  bool canUseFBO();
70  bool canUseHardwareBuffers();
72  bool canUseMipmaps();
73  bool canUseHardwareMipmaps();
74  bool canUseClampToEdge();
76  bool canUseBlendEquation();
77  bool canCacheBackbuffer();
78  bool shouldUseShaders() { return m_shouldUseShaders; }
79  bool hasScissorBug();
80 
81 private:
82  Size m_viewportSize;
83 
84  int m_maxTextureSize;
85  int m_alphaBits;
87  stdext::boolean<true> m_useDrawArrays;
88  stdext::boolean<true> m_useFBO;
89  stdext::boolean<false> m_useHardwareBuffers;
90  stdext::boolean<true> m_useBilinearFiltering;
91  stdext::boolean<true> m_useNonPowerOfTwoTextures;
92  stdext::boolean<true> m_useMipmaps;
93  stdext::boolean<true> m_useHardwareMipmaps;
94  stdext::boolean<true> m_useClampToEdge;
95  stdext::boolean<true> m_shouldUseShaders;
96  stdext::boolean<true> m_cacheBackbuffer;
97  PainterEngine m_prefferedPainterEngine;
98  PainterEngine m_selectedPainterEngine;
99 };
100 
101 extern Graphics g_graphics;
102 
103 #endif
Graphics::selectPainterEngine
bool selectPainterEngine(PainterEngine painterEngine)
Definition: graphics.cpp:185
Graphics::getPainterEngine
PainterEngine getPainterEngine()
Definition: graphics.h:51
Graphics::ok
bool ok()
Definition: graphics.h:65
Graphics::canUseBlendFuncSeparate
bool canUseBlendFuncSeparate()
Definition: graphics.cpp:375
Graphics::getViewportSize
const Size & getViewportSize()
Definition: graphics.h:56
Graphics::Graphics
Graphics()
Definition: graphics.cpp:46
Graphics::Painter_DirectX9
@ Painter_DirectX9
Definition: graphics.h:39
Graphics::Painter_OpenGL1
@ Painter_OpenGL1
Definition: graphics.h:37
Graphics::canUseBilinearFiltering
bool canUseBilinearFiltering()
Definition: graphics.cpp:308
Graphics::isPainterEngineAvailable
bool isPainterEngineAvailable(PainterEngine painterEngine)
Definition: graphics.cpp:166
Graphics::canUseBlendEquation
bool canUseBlendEquation()
Definition: graphics.cpp:388
Graphics::setShouldUseShaders
void setShouldUseShaders(bool enable)
Definition: graphics.h:63
Graphics::canUseDrawArrays
bool canUseDrawArrays()
Definition: graphics.cpp:267
Graphics::hasScissorBug
bool hasScissorBug()
Definition: graphics.cpp:416
Graphics::getMaxTextureSize
int getMaxTextureSize()
Definition: graphics.h:55
Graphics
Definition: graphics.h:30
stdext::boolean< false >
Graphics::getExtensions
std::string getExtensions()
Definition: graphics.h:61
Graphics::canCacheBackbuffer
bool canCacheBackbuffer()
Definition: graphics.cpp:401
Graphics::canUseClampToEdge
bool canUseClampToEdge()
Definition: graphics.cpp:363
painter.h
Graphics::PainterEngine
PainterEngine
Definition: graphics.h:35
Graphics::canUseHardwareMipmaps
bool canUseHardwareMipmaps()
Definition: graphics.cpp:349
Graphics::canUseFBO
bool canUseFBO()
Definition: graphics.cpp:293
Graphics::resize
void resize(const Size &size)
Definition: graphics.cpp:253
Graphics::canUseShaders
bool canUseShaders()
Definition: graphics.cpp:279
Graphics::canUseHardwareBuffers
bool canUseHardwareBuffers()
Definition: graphics.cpp:314
Graphics::terminate
void terminate()
Definition: graphics.cpp:112
Graphics::canUseMipmaps
bool canUseMipmaps()
Definition: graphics.cpp:343
Graphics::parseOption
bool parseOption(const std::string &option)
Definition: graphics.cpp:137
Graphics::getVersion
std::string getVersion()
Definition: graphics.h:60
Graphics::shouldUseShaders
bool shouldUseShaders()
Definition: graphics.h:78
Graphics::Painter_Any
@ Painter_Any
Definition: graphics.h:36
Graphics::canUseNonPowerOfTwoTextures
bool canUseNonPowerOfTwoTextures()
Definition: graphics.cpp:329
declarations.h
Graphics::getRenderer
std::string getRenderer()
Definition: graphics.h:59
Graphics::getVendor
std::string getVendor()
Definition: graphics.h:58
Graphics::Painter_OpenGL2
@ Painter_OpenGL2
Definition: graphics.h:38
Graphics::init
void init()
Definition: graphics.cpp:52
TSize< int >
g_graphics
Graphics g_graphics
Definition: graphics.cpp:44