Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
gl_renderer.h
1 #pragma once
2 
3 #include <unordered_map>
4 
5 #include "renderer.h"
6 #include "../types.h"
7 #include "../texture.h"
8 #include "../threads/mutex.h"
9 
10 namespace smlt {
11 
12 constexpr const char* const LIGHT_POSITION_PROPERTY = "s_light_position";
13 constexpr const char* const LIGHT_AMBIENT_PROPERTY = "s_light_ambient";
14 constexpr const char* const LIGHT_DIFFUSE_PROPERTY = "s_light_diffuse";
15 constexpr const char* const LIGHT_SPECULAR_PROPERTY = "s_light_specular";
16 constexpr const char* const LIGHT_CONSTANT_ATTENUATION_PROPERTY = "s_light_constant_attenuation";
17 constexpr const char* const LIGHT_LINEAR_ATTENUATION_PROPERTY = "s_light_linear_attenuation";
18 constexpr const char* const LIGHT_QUADRATIC_ATTENUATION_PROPERTY = "s_light_quadratic_attenuation";
19 constexpr const char* const VIEW_MATRIX_PROPERTY = "s_view";
20 constexpr const char* const MODELVIEW_PROJECTION_MATRIX_PROPERTY = "s_modelview_projection";
21 constexpr const char* const PROJECTION_MATRIX_PROPERTY = "s_projection";
22 constexpr const char* const MODELVIEW_MATRIX_PROPERTY = "s_modelview";
23 constexpr const char* const INVERSE_TRANSPOSE_MODELVIEW_MATRIX_PROPERTY = "s_inverse_transpose_modelview";
24 
25 #ifdef __DREAMCAST__
26 // The Dreamcast only supports 2 multitexture units
27 #define _S_GL_MAX_TEXTURE_UNITS 1
28 #elif defined(__PSP__)
29 // PSPGL doesn't support multitexturing at all (!)
30 #define _S_GL_MAX_TEXTURE_UNITS 1
31 #else
32 #define _S_GL_MAX_TEXTURE_UNITS 8
33 #endif
34 
35 #define _S_GL_SUPPORTS_MULTITEXTURE (_S_GL_MAX_TEXTURE_UNITS > 1)
36 
37 #ifdef __PSP__
38 #define _S_GL_SUPPORTS_COLOR_MATERIAL 0
39 #else
40 #define _S_GL_SUPPORTS_COLOR_MATERIAL 1
41 #endif
42 
43 /*
44  * Shared functionality between the GL1.x and GL2.x renderers
45  * I hate mixin style classes (implementation inheritance) but as
46  * we need to implement methods from the Renderer base class this
47  * is the most straightforward way to share the code.
48 */
49 
50 class GLRenderer : public Renderer {
51 protected:
52  GLRenderer(Window* window):
53  Renderer(window) {}
54 
55  void on_texture_register(TextureID tex_id, Texture *texture) override;
56  void on_texture_unregister(TextureID tex_id, Texture* texture) override;
57  void on_texture_prepare(Texture* texture) override;
58  bool texture_format_is_native(TextureFormat fmt) override;
59 
60  uint32_t convert_format(TextureFormat format);
61  uint32_t convert_type(TextureFormat format);
62 
63  thread::Mutex texture_object_mutex_;
64  std::unordered_map<TextureID, uint32_t> texture_objects_;
65 
66 };
67 
68 }
smlt::GLRenderer
Definition: gl_renderer.h:50
smlt
Definition: animation.cpp:25
smlt::Window
Definition: window.h:65
smlt::Texture
Definition: texture.h:158
smlt::UniqueID< TexturePtr >
smlt::Renderer
Definition: renderer.h:40
smlt::thread::Mutex
Definition: mutex.h:25
smlt::GLRenderer::texture_format_is_native
bool texture_format_is_native(TextureFormat fmt) override
Definition: gl_renderer.cpp:379