|
Kemena3D
|
OpenGL 3.3 Core Profile graphics driver. More...
#include <kopengldriver.h>


Public Member Functions | |
| kOpenGLDriver ()=default | |
| ~kOpenGLDriver () override | |
| bool | init (kWindow *window) override |
| Creates an OpenGL 3.3 Core Profile context for the given window. | |
| void | destroy () override |
| Destroys the SDL GL context. | |
| void * | getNativeContext () override |
| Returns the raw SDL_GLContext handle. | |
| kString | getApiVersion () override |
| Returns the OpenGL version kString. | |
| kString | getShaderVersion () override |
| Returns the GLSL version kString. | |
| void | setClearColor (float r, float g, float b, float a) override |
| Sets the colour used to clear the colour buffer. | |
| void | clear (bool color, bool depth, bool stencil) override |
| Clears the selected buffers of the current framebuffer. | |
| void | setViewport (int x, int y, int width, int height) override |
| Sets the rendering viewport rectangle. | |
| void | setDepthTest (bool enable) override |
| Enables or disables depth testing. | |
| void | setDepthWrite (bool enable) override |
| Enables or disables writing to the depth buffer. | |
| void | setBlend (bool enable) override |
| Enables or disables alpha blending. | |
| void | setBlendFunc (kBlendFactor src, kBlendFactor dst) override |
| Sets the source and destination blend factors. | |
| void | setCullFace (bool enable) override |
| Enables or disables face culling. | |
| void | setCullMode (kCullMode mode) override |
| Selects which faces are culled. | |
| void | setFrontFace (kFrontFace face) override |
| Sets the winding order treated as front-facing. | |
| void | setMultisample (bool enable) override |
| Enables or disables multisample anti-aliasing. | |
| void | setSRGBEncoding (bool enable) override |
| Enables or disables sRGB framebuffer encoding. | |
| void | setSampleAlphaToCoverage (bool enable) override |
| Enables or disables alpha-to-coverage sampling. | |
| uint32_t | compileShaderProgram (const char *vertSrc, const char *fragSrc) override |
| Compiles and links a shader program from GLSL source. | |
| uint32_t | compileShaderProgramSpirv (const std::vector< uint8_t > &vertSpirv, const kString &vertEntry, const std::vector< uint8_t > &fragSpirv, const kString &fragEntry) override |
| Compiles and links a shader program from SPIR-V binaries. | |
| void | deleteShaderProgram (uint32_t id) override |
| Deletes a shader program. | |
| void | bindShaderProgram (uint32_t id) override |
| Makes a shader program current for subsequent draws. | |
| void | unbindShaderProgram () override |
| Unbinds the current shader program. | |
| void | setUniformBool (uint32_t progId, const kString &name, bool v) override |
| Sets a bool uniform. | |
| void | setUniformInt (uint32_t progId, const kString &name, int v) override |
| Sets an int uniform. | |
| void | setUniformUint (uint32_t progId, const kString &name, uint32_t v) override |
| Sets an unsigned int uniform. | |
| void | setUniformFloat (uint32_t progId, const kString &name, float v) override |
| Sets a float uniform. | |
| void | setUniformVec2 (uint32_t progId, const kString &name, const kVec2 &v) override |
| Sets a vec2 uniform. | |
| void | setUniformVec3 (uint32_t progId, const kString &name, const kVec3 &v) override |
| Sets a vec3 uniform. | |
| void | setUniformVec4 (uint32_t progId, const kString &name, const kVec4 &v) override |
| Sets a vec4 uniform. | |
| void | setUniformMat4 (uint32_t progId, const kString &name, const kMat4 &v) override |
| Sets a mat4 uniform. | |
| void | setUniformMat4Array (uint32_t progId, const kString &name, const std::vector< kMat4 > &v) override |
| Sets an array-of-mat4 uniform. | |
| uint32_t | createVertexArray () override |
| Creates a vertex array object. | |
| void | deleteVertexArray (uint32_t id) override |
| Deletes a vertex array object. | |
| void | bindVertexArray (uint32_t id) override |
| Binds a vertex array object. | |
| void | unbindVertexArray () override |
| Unbinds the current vertex array object. | |
| uint32_t | createBuffer () override |
| Creates a GPU buffer object. | |
| void | deleteBuffer (uint32_t id) override |
| Deletes a GPU buffer object. | |
| void | uploadIndexBuffer (uint32_t bufferId, const void *data, size_t size) override |
| Uploads index data into an element array buffer (static draw). | |
| void | uploadVertexBuffer (uint32_t bufferId, const void *data, size_t size) override |
| Uploads vertex data into an array buffer (static draw). | |
| void | setVertexAttribFloat (int location, int components, int stride, size_t offset) override |
| Defines a floating-point vertex attribute layout. | |
| void | setVertexAttribInt (int location, int components, int stride, size_t offset) override |
| Defines an integer vertex attribute layout. | |
| void | drawIndexed (uint32_t vaoId, int indexCount) override |
| Issues an indexed draw call (triangles) for the given VAO. | |
| void | drawArrays (uint32_t vaoId, kPrimitiveType type, int vertexCount) override |
| Issues a non-indexed draw call for the given VAO. | |
| void | bindTexture2D (int unit, uint32_t id) override |
| Binds a 2D texture to a texture unit. | |
| void | bindTexture2DArray (int unit, uint32_t id) override |
| Binds a 2D-array texture to a texture unit. | |
| void | bindTextureCube (int unit, uint32_t id) override |
| Binds a cubemap texture to a texture unit. | |
| void | unbindTexture2D (int unit) override |
| Unbinds the 2D texture on a unit. | |
| void | unbindTexture2DArray (int unit) override |
| Unbinds the 2D-array texture on a unit. | |
| void | unbindTextureCube (int unit) override |
| Unbinds the cubemap texture on a unit. | |
| void | generateMipmaps2D (uint32_t id) override |
| Generates the full mipmap chain for a 2D texture. | |
| void | readTexture2DRGB (uint32_t id, int mipLevel, float *pixels) override |
| Reads back an RGB float image from a 2D texture mip level. | |
| void | readPixelsRGBA (int x, int y, uint8_t &r, uint8_t &g, uint8_t &b, uint8_t &a) override |
| Reads a single RGBA pixel from the current read framebuffer. | |
| uint32_t | createFramebuffer () override |
| Creates a framebuffer object. | |
| void | deleteFramebuffer (uint32_t id) override |
| Deletes a framebuffer object. | |
| void | bindFramebuffer (uint32_t id) override |
| Binds an FBO as both read and draw target. | |
| void | bindReadFramebuffer (uint32_t id) override |
| Binds an FBO as the read target. | |
| void | bindDrawFramebuffer (uint32_t id) override |
| Binds an FBO as the draw target. | |
| void | unbindFramebuffer () override |
| Unbinds the current FBO, restoring the default framebuffer. | |
| bool | isFramebufferComplete () override |
| Checks framebuffer completeness. | |
| void | blitFramebufferColor (int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1) override |
| Blits the colour buffer between the read and draw framebuffers (nearest filter). | |
| void | setFramebufferDrawBuffer () override |
| Sets the draw buffer of the bound FBO to colour attachment 0. | |
| uint32_t | createRenderbuffer () override |
| Creates a renderbuffer object. | |
| void | deleteRenderbuffer (uint32_t id) override |
| Deletes a renderbuffer object. | |
| void | setupRenderbuffer (uint32_t rboId, int width, int height) override |
| Allocates depth/stencil storage for a renderbuffer. | |
| void | setupRenderbufferMSAA (uint32_t rboId, int samples, int width, int height) override |
| Allocates multisampled depth/stencil storage for a renderbuffer. | |
| void | attachRenderbufferDepthStencil (uint32_t fboId, uint32_t rboId) override |
| Attaches a renderbuffer as the depth/stencil attachment of an FBO. | |
| uint32_t | createFBOColorTexture (int width, int height) override |
| Creates a colour texture suitable for FBO attachment. | |
| uint32_t | createFBOColorTextureMSAA (int samples, int width, int height) override |
| Creates a multisampled colour texture suitable for FBO attachment. | |
| uint32_t | createFBODepthTexture (int width, int height) override |
| Creates a depth texture suitable for FBO attachment. | |
| uint32_t | createFBODepthTextureArray (int width, int height, int layers) override |
| Creates a layered depth texture array (e.g. for cascaded shadow maps). | |
| void | deleteFBOTexture (uint32_t id) override |
| Deletes an FBO-managed texture. | |
| void | attachFBOColorTexture (uint32_t fboId, uint32_t texId) override |
| Attaches a colour texture to colour attachment 0 of an FBO. | |
| void | attachFBOColorTextureMSAA (uint32_t fboId, uint32_t texId) override |
| Attaches a multisampled colour texture to colour attachment 0 of an FBO. | |
| void | attachFBODepthTexture (uint32_t fboId, uint32_t texId) override |
| Attaches a depth texture to the depth attachment of an FBO. | |
| void | attachFBODepthTextureLayer (uint32_t fboId, uint32_t texId, int layer) override |
| Attaches a single layer of a depth texture array as the depth attachment. | |
| void | resizeFBOColorTexture (uint32_t texId, int width, int height) override |
| Reallocates an FBO colour texture to a new size. | |
| void | resizeFBOColorTextureMSAA (uint32_t texId, int samples, int width, int height) override |
| Reallocates a multisampled FBO colour texture to a new size/sample count. | |
| Public Member Functions inherited from kemena::kDriver | |
| virtual | ~kDriver ()=default |
Additional Inherited Members | |
| Static Public Member Functions inherited from kemena::kDriver | |
| static kDriver * | getCurrent () |
| Returns the currently active driver (set via setCurrent()). | |
| static void | setCurrent (kDriver *driver) |
| Sets the globally active driver. | |
OpenGL 3.3 Core Profile graphics driver.
Created by kRenderer when the RENDERER_GL backend is selected. Wraps all raw OpenGL calls so that the rest of the engine remains API-agnostic.
Do not instantiate this class directly — use kRenderer::init() instead.
|
default |
|
override |
|
overridevirtual |
Attaches a colour texture to colour attachment 0 of an FBO.
| fboId | GL FBO id. |
| texId | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
Attaches a multisampled colour texture to colour attachment 0 of an FBO.
| fboId | GL FBO id. |
| texId | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
Attaches a depth texture to the depth attachment of an FBO.
| fboId | GL FBO id. |
| texId | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
Attaches a single layer of a depth texture array as the depth attachment.
| fboId | GL FBO id. |
| texId | GL texture-array id. |
| layer | Array layer to attach. |
Implements kemena::kDriver.
|
overridevirtual |
Attaches a renderbuffer as the depth/stencil attachment of an FBO.
| fboId | GL FBO id. |
| rboId | GL RBO id. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Makes a shader program current for subsequent draws.
| id | GL program id. |
Implements kemena::kDriver.
|
overridevirtual |
Binds a 2D texture to a texture unit.
| unit | Texture unit index. |
| id | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
Binds a 2D-array texture to a texture unit.
| unit | Texture unit index. |
| id | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
Binds a cubemap texture to a texture unit.
| unit | Texture unit index. |
| id | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
Blits the colour buffer between the read and draw framebuffers (nearest filter).
| srcX0 | Source rectangle left. |
| srcY0 | Source rectangle bottom. |
| srcX1 | Source rectangle right. |
| srcY1 | Source rectangle top. |
| dstX0 | Destination rectangle left. |
| dstY0 | Destination rectangle bottom. |
| dstX1 | Destination rectangle right. |
| dstY1 | Destination rectangle top. |
Implements kemena::kDriver.
|
overridevirtual |
Clears the selected buffers of the current framebuffer.
| color | Clear the colour buffer when true. |
| depth | Clear the depth buffer when true. |
| stencil | Clear the stencil buffer when true. |
Implements kemena::kDriver.
|
overridevirtual |
Compiles and links a shader program from GLSL source.
| vertSrc | Null-terminated vertex shader source. |
| fragSrc | Null-terminated fragment shader source. |
Implements kemena::kDriver.
|
overridevirtual |
Compiles and links a shader program from SPIR-V binaries.
Requires GL_ARB_gl_spirv or OpenGL 4.6; returns 0 if unsupported.
| vertSpirv | SPIR-V byte code for the vertex stage. |
| vertEntry | Entry-point name for the vertex stage. |
| fragSpirv | SPIR-V byte code for the fragment stage. |
| fragEntry | Entry-point name for the fragment stage. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
Creates a colour texture suitable for FBO attachment.
| width | Texture width in pixels. |
| height | Texture height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Creates a multisampled colour texture suitable for FBO attachment.
| samples | Number of MSAA samples. |
| width | Texture width in pixels. |
| height | Texture height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Creates a depth texture suitable for FBO attachment.
| width | Texture width in pixels. |
| height | Texture height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Creates a layered depth texture array (e.g. for cascaded shadow maps).
| width | Texture width in pixels. |
| height | Texture height in pixels. |
| layers | Number of array layers. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Destroys the SDL GL context.
Implements kemena::kDriver.
|
overridevirtual |
Issues a non-indexed draw call for the given VAO.
| vaoId | GL VAO id to bind. |
| type | Primitive topology to assemble. |
| vertexCount | Number of vertices to draw. |
Implements kemena::kDriver.
|
overridevirtual |
Issues an indexed draw call (triangles) for the given VAO.
| vaoId | GL VAO id to bind. |
| indexCount | Number of indices to draw. |
Implements kemena::kDriver.
|
overridevirtual |
Generates the full mipmap chain for a 2D texture.
| id | GL texture id. |
Implements kemena::kDriver.
|
overridevirtual |
Returns the OpenGL version kString.
Implements kemena::kDriver.
|
overridevirtual |
Returns the raw SDL_GLContext handle.
Implements kemena::kDriver.
|
overridevirtual |
Returns the GLSL version kString.
Implements kemena::kDriver.
|
overridevirtual |
Creates an OpenGL 3.3 Core Profile context for the given window.
Sets SDL GL attributes, creates the context, initialises GLEW, and applies default render state.
| window | SDL-backed window to create the context for. |
Implements kemena::kDriver.
|
overridevirtual |
Checks framebuffer completeness.
Implements kemena::kDriver.
|
overridevirtual |
Reads a single RGBA pixel from the current read framebuffer.
| x | Pixel x coordinate. |
| y | Pixel y coordinate. |
| r | Out: red component. |
| g | Out: green component. |
| b | Out: blue component. |
| a | Out: alpha component. |
Implements kemena::kDriver.
|
overridevirtual |
Reads back an RGB float image from a 2D texture mip level.
| id | GL texture id. |
| mipLevel | Mip level to read. |
| pixels | Destination buffer (RGB floats), sized by caller. |
Implements kemena::kDriver.
|
overridevirtual |
Reallocates an FBO colour texture to a new size.
| texId | GL texture id. |
| width | New width in pixels. |
| height | New height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Reallocates a multisampled FBO colour texture to a new size/sample count.
| texId | GL texture id. |
| samples | Number of MSAA samples. |
| width | New width in pixels. |
| height | New height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
Sets the source and destination blend factors.
| src | Source colour blend factor. |
| dst | Destination colour blend factor. |
Implements kemena::kDriver.
|
overridevirtual |
Sets the colour used to clear the colour buffer.
| r | Red component in [0,1]. |
| g | Green component in [0,1]. |
| b | Blue component in [0,1]. |
| a | Alpha component in [0,1]. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
Selects which faces are culled.
| mode | Front, back, or front-and-back. |
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
Enables or disables writing to the depth buffer.
| enable | true to enable. |
Implements kemena::kDriver.
|
overridevirtual |
Sets the draw buffer of the bound FBO to colour attachment 0.
Implements kemena::kDriver.
|
overridevirtual |
Sets the winding order treated as front-facing.
| face | CW or CCW. |
Implements kemena::kDriver.
|
overridevirtual |
Enables or disables multisample anti-aliasing.
| enable | true to enable. |
Implements kemena::kDriver.
|
overridevirtual |
Enables or disables alpha-to-coverage sampling.
| enable | true to enable. |
Implements kemena::kDriver.
|
overridevirtual |
Enables or disables sRGB framebuffer encoding.
| enable | true to enable. |
Implements kemena::kDriver.
|
overridevirtual |
Sets a bool uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets a float uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets an int uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets a mat4 uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets an array-of-mat4 uniform.
| progId | Program id. |
| name | Uniform array name. |
| v | Matrices to upload. |
Implements kemena::kDriver.
|
overridevirtual |
Sets an unsigned int uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets a vec2 uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets a vec3 uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Sets a vec4 uniform.
| progId | Program id. |
| name | Uniform name. |
| v | Value. |
Implements kemena::kDriver.
|
overridevirtual |
Allocates depth/stencil storage for a renderbuffer.
| rboId | GL RBO id. |
| width | Storage width in pixels. |
| height | Storage height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Allocates multisampled depth/stencil storage for a renderbuffer.
| rboId | GL RBO id. |
| samples | Number of MSAA samples. |
| width | Storage width in pixels. |
| height | Storage height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Defines a floating-point vertex attribute layout.
| location | Attribute location index. |
| components | Number of components per vertex (1-4). |
| stride | Byte stride between consecutive vertices. |
| offset | Byte offset of the attribute within the vertex. |
Implements kemena::kDriver.
|
overridevirtual |
Defines an integer vertex attribute layout.
| location | Attribute location index. |
| components | Number of components per vertex (1-4). |
| stride | Byte stride between consecutive vertices. |
| offset | Byte offset of the attribute within the vertex. |
Implements kemena::kDriver.
|
overridevirtual |
Sets the rendering viewport rectangle.
| x | Lower-left x origin in pixels. |
| y | Lower-left y origin in pixels. |
| width | Viewport width in pixels. |
| height | Viewport height in pixels. |
Implements kemena::kDriver.
|
overridevirtual |
Unbinds the current FBO, restoring the default framebuffer.
Implements kemena::kDriver.
|
overridevirtual |
Unbinds the current shader program.
Implements kemena::kDriver.
|
overridevirtual |
|
overridevirtual |
Unbinds the 2D-array texture on a unit.
| unit | Texture unit index. |
Implements kemena::kDriver.
|
overridevirtual |
Unbinds the cubemap texture on a unit.
| unit | Texture unit index. |
Implements kemena::kDriver.
|
overridevirtual |
Unbinds the current vertex array object.
Implements kemena::kDriver.
|
overridevirtual |
Uploads index data into an element array buffer (static draw).
| bufferId | GL buffer id. |
| data | Pointer to index data. |
| size | Size of the data in bytes. |
Implements kemena::kDriver.
|
overridevirtual |
Uploads vertex data into an array buffer (static draw).
| bufferId | GL buffer id. |
| data | Pointer to vertex data. |
| size | Size of the data in bytes. |
Implements kemena::kDriver.