29 #include "graphics/opengl/glutil.h"
41 struct GLDevicePrivate;
71 void Clear()
override;
89 void SetTexture(
int index,
unsigned int textureId)
override;
98 Color color =
Color(1.0f, 1.0f, 1.0f, 1.0f))
override;
100 Color color =
Color(1.0f, 1.0f, 1.0f, 1.0f))
override;
114 void SetViewport(
int x,
int y,
int width,
int height)
override;
118 void SetColorMask(
bool red,
bool green,
bool blue,
bool alpha)
override;
165 void UpdateLightPosition(
int index);
167 void UpdateTextureParams(
int index);
169 void UpdateTextureStatus();
171 inline void BindVBO(GLuint vbo);
190 bool m_lighting =
false;
192 std::vector<Light> m_lights;
194 std::vector<bool> m_lightsEnabled;
197 std::vector<Texture> m_currentTextures;
199 std::vector<bool> m_texturesEnabled;
201 std::vector<TextureStageParams> m_textureStageParams;
204 std::set<Texture> m_allTextures;
207 std::map<std::string, std::unique_ptr<CFramebuffer>> m_framebuffers;
221 unsigned int bufferId = 0;
222 VertexType vertexType = {};
229 int m_glMajor = 1, m_glMinor = 1;
231 bool m_anisotropyAvailable =
false;
233 int m_maxAnisotropy = 1;
235 int m_maxSamples = 1;
237 FramebufferSupport m_framebufferSupport = FBS_NONE;
239 std::map<unsigned int, VboObjectInfo> m_vboObjects;
241 unsigned int m_lastVboId = 0;
243 GLuint m_currentVBO = 0;
246 bool m_perPixelLighting =
false;
249 GLuint m_program = 0;
253 GLint uni_ProjectionMatrix = 0;
255 GLint uni_ViewMatrix = 0;
257 GLint uni_ModelMatrix = 0;
259 GLint uni_ShadowMatrix = 0;
261 GLint uni_NormalMatrix = 0;
264 GLint uni_PrimaryTexture = 0;
266 GLint uni_SecondaryTexture = 0;
268 GLint uni_ShadowTexture = 0;
271 GLint uni_TextureEnabled[3] = {};
275 GLint uni_AlphaTestEnabled = 0;
277 GLint uni_AlphaReference = 0;
280 GLint uni_FogEnabled = 0;
282 GLint uni_FogRange = 0;
284 GLint uni_FogColor = 0;
287 GLint uni_ShadowColor = 0;
290 GLint uni_LightingEnabled = 0;
292 GLint uni_LightEnabled[8] = {};
void BeginScene() override
Begins drawing the 3D scene.
Definition: gl21device.cpp:403
void CopyFramebufferToTexture(Texture &texture, int xOffset, int yOffset, int x, int y, int width, int height) override
Copies content of framebuffer to texture.
Definition: gl21device.cpp:1684
Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) override
Definition: gl21device.cpp:548
Implementation of CDevice interface in OpenGL.
Definition: gl21device.h:54
void Clear() override
Clears the screen to blank.
Definition: gl21device.cpp:412
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex *vertices, int vertexCount) override
Creates a static buffer composed of given primitives with single texture vertices.
Definition: gl21device.cpp:1238
void SetShadeModel(ShadeModel model) override
Sets the shade model.
Definition: gl21device.cpp:1664
Vertex of a primitive.
Definition: vertex.h:52
Vertex with secondary texture coordinates.
Definition: vertex.h:113
void SetDepthBias(float factor, float units) override
Sets the depth bias (constant value added to Z-coords)
Definition: gl21device.cpp:1612
void SetGlobalAmbient(const Color &color) override
Sets the global ambient color.
Definition: gl21device.cpp:1632
int GetMaxAnisotropyLevel() override
Returns max anisotropy level supported.
Definition: gl21device.cpp:1754
int GetMaxTextureSize() override
Returns max texture size supported.
Definition: gl21device.cpp:1769
FogMode
Type of fog calculation function.
Definition: device.h:163
4x4 matrix
Definition: matrix.h:65
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:99
void SetColorMask(bool red, bool green, bool blue, bool alpha) override
Sets the color mask.
Definition: gl21device.cpp:1602
void SetTextureStageParams(int index, const TextureStageParams ¶ms) override
Definition: gl21device.cpp:911
FillMode
Polygon fill mode.
Definition: device.h:196
void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override
Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) ...
Definition: gl21device.cpp:1637
void DestroyTexture(const Texture &texture) override
Deletes a given texture, freeing it from video memory.
Definition: gl21device.cpp:800
void SetLight(int index, const Light &light) override
Sets the light at given index.
Definition: gl21device.cpp:474
int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override
Definition: gl21device.cpp:1466
void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) override
Sets the texture coordinate generation mode for given texture unit.
Definition: gl21device.cpp:921
void DrawStaticBuffer(unsigned int bufferId) override
Draws a static buffer.
Definition: gl21device.cpp:1376
CompFunc
Type of function used to compare values.
Definition: device.h:128
void SetLightEnabled(int index, bool enabled) override
Enables/disables the light at given index.
Definition: gl21device.cpp:535
Parameters for a texture unit.
Definition: texture.h:180
Material of a surface.
Definition: material.h:45
void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override
Sets the blending functions for source and destination operations.
Definition: gl21device.cpp:1622
int GetMaxTextureStageCount() override
Returns the maximum number of multitexture stages.
Definition: gl21device.cpp:829
CFramebuffer * GetFramebuffer(std::string name) override
Returns framebuffer with given name or nullptr if it doesn't exist.
Definition: gl21device.cpp:1703
Parameters for texture coordinate generation.
Definition: texture.h:234
void SetRenderState(RenderState state, bool enabled) override
Enables/disables the given render state.
Definition: gl21device.cpp:1550
void ConfigChanged(const DeviceConfig &newConfig) override
Changes configuration.
Definition: gl21device.cpp:393
General config for graphics device.
Definition: device.h:55
Properties of light in 3D scene.
Definition: light.h:54
void SetFillMode(FillMode mode) override
Sets the current fill mode.
Definition: gl21device.cpp:1676
void SetCullMode(CullMode mode) override
Sets the current cull mode.
Definition: gl21device.cpp:1655
void SetViewport(int x, int y, int width, int height) override
Changes rendering viewport.
Definition: gl21device.cpp:1545
void SetMaterial(const Material &material) override
Sets the current material.
Definition: gl21device.cpp:460
bool Create() override
Initializes the device, setting the initial state.
Definition: gl21device.cpp:163
Parameters for texture creation.
Definition: texture.h:155
ShadeModel
Shade model used in rendering.
Definition: device.h:186
BlendFunc
Type of blending function.
Definition: device.h:144
std::unique_ptr< CFrameBufferPixels > GetFrameBufferPixels() const override
Returns the pixels of the entire screen.
Definition: gl21device.cpp:1698
void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex *vertices, int vertexCount) override
Updates the static buffer composed of given primitives with single texture vertices.
Definition: gl21device.cpp:1298
CFramebuffer * CreateFramebuffer(std::string name, const FramebufferParams ¶ms) override
Creates new framebuffer with given name or nullptr if it's not possible.
Definition: gl21device.cpp:1712
int GetMaxSamples() override
Returns max samples supported.
Definition: gl21device.cpp:1759
Image loaded from file.
Definition: image.h:54
Contains parameters for new framebuffer.
Definition: framebuffer.h:34
PrimitiveType
Type of primitive to render.
Definition: device.h:210
bool IsAnisotropySupported() override
Checks if anisotropy is supported.
Definition: gl21device.cpp:1749
bool IsShadowMappingSupported() override
Checks if shadow mapping is supported.
Definition: gl21device.cpp:1764
CullMode
Culling mode for polygons.
Definition: device.h:174
Colored vertex.
Definition: vertex.h:84
Namespace for (new) graphics code.
Definition: app.h:49
Implementation-specific image data.
Definition: image.h:41
int GetMaxLightCount() override
Returns the maximum number of lights available.
Definition: gl21device.cpp:469
void DeleteFramebuffer(std::string name) override
Deletes framebuffer.
Definition: gl21device.cpp:1736
void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override
Sets only the texture wrap modes (for faster than thru stage params)
Definition: gl21device.cpp:1128
RenderState
Render states that can be enabled/disabled.
Definition: device.h:112
Info about a texture.
Definition: texture.h:256
void SetTexture(int index, const Texture &texture) override
Definition: gl21device.cpp:838
void SetTextureEnabled(int index, bool enabled) override
Enables/disables the given texture stage.
Definition: gl21device.cpp:876
bool IsFramebufferSupported() override
Checks if framebuffers are supported.
Definition: gl21device.cpp:1776
void Destroy() override
Destroys the device, releasing every acquired resource.
Definition: gl21device.cpp:370
3D (3x1) vector
Definition: vector.h:53
void DestroyStaticBuffer(unsigned int bufferId) override
Deletes a static buffer.
Definition: gl21device.cpp:1450
void SetShadowColor(float value) override
Sets shadow color.
Definition: gl21device.cpp:1671
Texture CreateDepthTexture(int width, int height, int depth) override
Creates a depth texture with specific dimensions and depth.
Definition: gl21device.cpp:754
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color=Color(1.0f, 1.0f, 1.0f, 1.0f)) override
Renders primitive composed of vertices with single texture.
Definition: gl21device.cpp:1159
Abstract graphics device - CDevice class and related structs/enums.
void SetTransform(TransformType type, const Math::Matrix &matrix) override
Sets the transform matrix of given type.
Definition: gl21device.cpp:418
RGBA color.
Definition: color.h:39
void DebugHook() override
Provides a hook to debug graphics code (implementation-specific)
Definition: gl21device.cpp:55
void EndScene() override
Ends drawing the 3D scene.
Definition: gl21device.cpp:408
TransformType
Type of transformation in rendering pipeline.
Definition: device.h:100
void SetAlphaTestFunc(CompFunc func, float refValue) override
Sets the alpha test function and reference value.
Definition: gl21device.cpp:1617
void SetClearColor(const Color &color) override
Sets the clear color.
Definition: gl21device.cpp:1627
void SetDepthTestFunc(CompFunc func) override
Sets the function of depth test.
Definition: gl21device.cpp:1607
Abstract interface of graphics device.
Definition: device.h:268
void DestroyAllTextures() override
Deletes all textures created so far.
Definition: gl21device.cpp:817
Abstract interface of default framebuffer and offscreen framebuffers.
Definition: framebuffer.h:67
void DebugLights() override
Displays light positions to aid in debuggings.
Definition: gl21device.cpp:62