31 #include "graphics/opengl/glframebuffer.h"
32 #include "graphics/opengl/glutil.h"
90 void Clear()
override;
111 void SetTexture(
int index,
unsigned int textureId)
override;
119 Color color =
Color(1.0f, 1.0f, 1.0f, 1.0f))
override;
121 Color color =
Color(1.0f, 1.0f, 1.0f, 1.0f))
override;
125 int first[],
int count[],
int drawCount,
126 Color color =
Color(1.0f, 1.0f, 1.0f, 1.0f))
override;
128 int first[],
int count[],
int drawCount,
129 Color color =
Color(1.0f, 1.0f, 1.0f, 1.0f))
override;
131 int first[],
int count[],
int drawCount)
override;
144 void SetViewport(
int x,
int y,
int width,
int height)
override;
148 void SetColorMask(
bool red,
bool green,
bool blue,
bool alpha)
override;
195 void UpdateTextureParams(
int index);
197 void UpdateRenderingMode();
200 inline void BindVBO(GLuint vbo);
202 inline void BindVAO(GLuint vao);
205 unsigned int UploadVertexData(
DynamicBuffer& buffer,
void* data,
unsigned int size);
222 bool m_combinedMatrixOutdated =
true;
228 bool m_lighting =
false;
230 std::vector<Light> m_lights;
232 std::vector<bool> m_lightsEnabled;
235 std::vector<Texture> m_currentTextures;
237 std::vector<bool> m_texturesEnabled;
239 std::vector<TextureStageParams> m_textureStageParams;
242 std::set<Texture> m_allTextures;
253 struct VertexBufferInfo
258 VertexType vertexType = {};
260 unsigned int size = 0;
265 std::map<unsigned int, VertexBufferInfo> m_vboObjects;
267 unsigned int m_lastVboId = 0;
269 GLuint m_currentVBO = 0;
271 GLuint m_currentVAO = 0;
274 unsigned long m_vboMemory = 0;
277 std::map<std::string, std::unique_ptr<CFramebuffer>> m_framebuffers;
280 GLuint m_normalProgram = 0;
282 GLuint m_interfaceProgram = 0;
284 GLuint m_shadowProgram = 0;
289 unsigned int m_mode = 0;
void DeleteFramebuffer(std::string name) override
Deletes framebuffer.
Definition: gl33device.cpp:2019
void DrawStaticBuffer(unsigned int bufferId) override
Draws a static buffer.
Definition: gl33device.cpp:1717
void DestroyAllTextures() override
Deletes all textures created so far.
Definition: gl33device.cpp:929
void BeginScene() override
Begins drawing the 3D scene.
Definition: gl33device.cpp:601
bool IsShadowMappingSupported() override
Checks if shadow mapping is supported.
Definition: gl33device.cpp:2113
RenderMode
Render modes the graphics device can be in.
Definition: device.h:172
int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override
Definition: gl33device.cpp:1759
void SetFillMode(FillMode mode) override
Sets the current fill mode.
Definition: gl33device.cpp:1968
void Destroy() override
Destroys the device, releasing every acquired resource.
Definition: gl33device.cpp:547
Vertex of a primitive.
Definition: vertex.h:52
std::unique_ptr< CFrameBufferPixels > GetFrameBufferPixels() const override
Returns the pixels of the entire screen.
Definition: gl33device.cpp:1989
Vertex with secondary texture coordinates.
Definition: vertex.h:113
unsigned int offset
Dynamic buffer offset.
Definition: gl33device.h:57
void ConfigChanged(const DeviceConfig &newConfig) override
Changes configuration.
Definition: gl33device.cpp:582
GLuint vao
Auxiliary VAO for rendering primitives with DrawPrimitive*.
Definition: gl33device.h:51
FogMode
Type of fog calculation function.
Definition: device.h:218
Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) override
Definition: gl33device.cpp:749
void UpdateTexture(const Texture &texture, Math::IntPoint offset, ImageData *data, TexImgFormat format) override
Updates a part of texture from raw image data.
Definition: gl33device.cpp:895
void SetLight(int index, const Light &light) override
Sets the light at given index.
Definition: gl33device.cpp:710
void SetRenderMode(RenderMode mode) override
Sets current rendering mode.
Definition: gl33device.cpp:623
void SetColorMask(bool red, bool green, bool blue, bool alpha) override
Sets the color mask.
Definition: gl33device.cpp:1894
4x4 matrix
Definition: matrix.h:65
void SetDepthBias(float factor, float units) override
Sets the depth bias (constant value added to Z-coords)
Definition: gl33device.cpp:1904
TexWrapMode
Wrapping mode for texture coords.
Definition: texture.h:99
int GetMaxLightCount() override
Returns the maximum number of lights available.
Definition: gl33device.cpp:705
FillMode
Polygon fill mode.
Definition: device.h:251
int GetMaxTextureSize() override
Returns max texture size supported.
Definition: gl33device.cpp:2118
void SetTexture(int index, const Texture &texture) override
Definition: gl33device.cpp:950
void SetClearColor(const Color &color) override
Sets the clear color.
Definition: gl33device.cpp:1919
void DebugHook() override
Provides a hook to debug graphics code (implementation-specific)
Definition: gl33device.cpp:57
void SetDepthTestFunc(CompFunc func) override
Sets the function of depth test.
Definition: gl33device.cpp:1899
void SetTextureEnabled(int index, bool enabled) override
Enables/disables the given texture stage.
Definition: gl33device.cpp:984
CompFunc
Type of function used to compare values.
Definition: device.h:183
void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override
Sets the blending functions for source and destination operations.
Definition: gl33device.cpp:1914
CFramebuffer * CreateFramebuffer(std::string name, const FramebufferParams ¶ms) override
Creates new framebuffer with given name or nullptr if it's not possible.
Definition: gl33device.cpp:2003
Parameters for a texture unit.
Definition: texture.h:180
Material of a surface.
Definition: material.h:45
void DebugLights() override
Displays light positions to aid in debuggings.
Definition: gl33device.cpp:64
bool IsAnisotropySupported() override
Checks if anisotropy is supported.
Definition: gl33device.cpp:2098
void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override
Sets only the texture wrap modes (for faster than thru stage params)
Definition: gl33device.cpp:1041
bool IsFramebufferSupported() override
Checks if framebuffers are supported.
Definition: gl33device.cpp:2123
void SetTransform(TransformType type, const Math::Matrix &matrix) override
Sets the transform matrix of given type.
Definition: gl33device.cpp:649
TexImgFormat
Format of image data.
Definition: texture.h:42
General config for graphics device.
Definition: device.h:64
Properties of light in 3D scene.
Definition: light.h:54
void SetLightEnabled(int index, bool enabled) override
Enables/disables the light at given index.
Definition: gl33device.cpp:736
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: gl33device.cpp:1540
Parameters for texture creation.
Definition: texture.h:155
ShadeModel
Shade model used in rendering.
Definition: device.h:241
BlendFunc
Type of blending function.
Definition: device.h:199
Matrix struct and related functions.
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: gl33device.cpp:1929
int GetMaxSamples() override
Returns max samples supported.
Definition: gl33device.cpp:2108
unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex *vertices, int vertexCount) override
Creates a static buffer composed of given primitives with single texture vertices.
Definition: gl33device.cpp:1404
bool Create() override
Initializes the device, setting the initial state.
Definition: gl33device.cpp:170
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: gl33device.cpp:1072
void SetGlobalAmbient(const Color &color) override
Sets the global ambient color.
Definition: gl33device.cpp:1924
int GetMaxTextureStageCount() override
Returns the maximum number of multitexture stages.
Definition: gl33device.cpp:941
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:265
void DestroyStaticBuffer(unsigned int bufferId) override
Deletes a static buffer.
Definition: gl33device.cpp:1733
CullMode
Culling mode for polygons.
Definition: device.h:229
Colored vertex.
Definition: vertex.h:84
Namespace for (new) graphics code.
Definition: app.h:49
void SetMaterial(const Material &material) override
Sets the current material.
Definition: gl33device.cpp:696
Implementation-specific image data.
Definition: image.h:41
void EndScene() override
Ends drawing the 3D scene.
Definition: gl33device.cpp:610
RenderState
Render states that can be enabled/disabled.
Definition: device.h:155
void SetTextureStageParams(int index, const TextureStageParams ¶ms) override
Definition: gl33device.cpp:1002
void SetRenderState(RenderState state, bool enabled) override
Enables/disables the given render state.
Definition: gl33device.cpp:1843
void SetCullMode(CullMode mode) override
Sets the current cull mode.
Definition: gl33device.cpp:1949
Info about a texture.
Definition: texture.h:256
Texture CreateDepthTexture(int width, int height, int depth) override
Creates a depth texture with specific dimensions and depth.
Definition: gl33device.cpp:850
void SetViewport(int x, int y, int width, int height) override
Changes rendering viewport.
Definition: gl33device.cpp:1838
unsigned int size
Dynamic buffer size.
Definition: gl33device.h:55
3D (3x1) vector
Definition: vector.h:53
GLuint vbo
Dynamic buffer.
Definition: gl33device.h:53
Abstract graphics device - CDevice class and related structs/enums.
2D Point with integer coords
Definition: intpoint.h:41
void SetAlphaTestFunc(CompFunc func, float refValue) override
Sets the alpha test function and reference value.
Definition: gl33device.cpp:1909
virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices, int first[], int count[], int drawCount, Color color=Color(1.0f, 1.0f, 1.0f, 1.0f)) override
Renders primitives composed of lists of vertices with single texture.
Definition: gl33device.cpp:1213
RGBA color.
Definition: color.h:39
TransformType
Type of transformation in rendering pipeline.
Definition: device.h:143
void SetShadeModel(ShadeModel model) override
Sets the shade model.
Definition: gl33device.cpp:1958
Struct for dynamic buffers.
Definition: gl33device.h:48
void CopyFramebufferToTexture(Texture &texture, int xOffset, int yOffset, int x, int y, int width, int height) override
Copies content of framebuffer to texture.
Definition: gl33device.cpp:1976
void DestroyTexture(const Texture &texture) override
Deletes a given texture, freeing it from video memory.
Definition: gl33device.cpp:912
void SetShadowColor(float value) override
Sets shadow color.
Definition: gl33device.cpp:1963
Implementation of CDevice interface in OpenGL 3.3.
Definition: gl33device.h:71
Abstract interface of graphics device.
Definition: device.h:323
Abstract interface of default framebuffer and offscreen framebuffers.
Definition: framebuffer.h:67
void Clear() override
Clears the screen to blank.
Definition: gl33device.cpp:617
int GetMaxAnisotropyLevel() override
Returns max anisotropy level supported.
Definition: gl33device.cpp:2103
CFramebuffer * GetFramebuffer(std::string name) override
Returns framebuffer with given name or nullptr if it doesn't exist.
Definition: gl33device.cpp:1994
std::string GetName() override
Returns a name of this device.
Definition: gl33device.cpp:165