From e01f0ea4d0529dee829421e264f341be787d9e69 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 5 Jul 2023 00:02:52 +0300 Subject: [PATCH] [OpenGL] Add `const` to some functions --- include/opengl.hpp | 66 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/include/opengl.hpp b/include/opengl.hpp index b259381b..b85347bf 100644 --- a/include/opengl.hpp +++ b/include/opengl.hpp @@ -128,9 +128,9 @@ namespace OpenGL { #ifdef OPENGL_DESTRUCTORS ~VertexArray() { free(); } #endif - GLuint handle() { return m_handle; } - bool exists() { return m_handle != 0; } - void bind() { glBindVertexArray(m_handle); } + GLuint handle() const { return m_handle; } + bool exists() const { return m_handle != 0; } + void bind() const { glBindVertexArray(m_handle); } template void setAttributeFloat(GLuint index, GLint size, GLsizei stride, const void* offset, bool normalized = GL_FALSE) { @@ -299,11 +299,11 @@ namespace OpenGL { #ifdef OPENGL_DESTRUCTORS ~Texture() { free(); } #endif - GLuint handle() { return m_handle; } - bool exists() { return m_handle != 0; } - void bind() { glBindTexture(m_binding, m_handle); } - int width() { return m_width; } - int height() { return m_height; } + GLuint handle() const { return m_handle; } + bool exists() const { return m_handle != 0; } + void bind() const { glBindTexture(m_binding, m_handle); } + int width() const { return m_width; } + int height() const { return m_height; } void free() { glDeleteTextures(1, &m_handle); } }; @@ -327,10 +327,10 @@ namespace OpenGL { #ifdef OPENGL_DESTRUCTORS ~Framebuffer() { free(); } #endif - GLuint handle() { return m_handle; } - bool exists() { return m_handle != 0; } - void bind(GLenum target) { glBindFramebuffer(target, m_handle); } - void bind(FramebufferTypes target) { bind(static_cast(target)); } + GLuint handle() const { return m_handle; } + bool exists() const { return m_handle != 0; } + void bind(GLenum target) const { glBindFramebuffer(target, m_handle); } + void bind(FramebufferTypes target) const { bind(static_cast(target)); } void free() { glDeleteFramebuffers(1, &m_handle); } void createWithTexture(Texture& tex, GLenum mode = GL_FRAMEBUFFER, GLenum textureType = GL_TEXTURE_2D) { @@ -392,8 +392,8 @@ namespace OpenGL { return m_handle != 0; } - GLuint handle() { return m_handle; } - bool exists() { return m_handle != 0; } + GLuint handle() const { return m_handle; } + bool exists() const { return m_handle != 0; } }; struct Program { @@ -421,9 +421,9 @@ namespace OpenGL { return m_handle != 0; } - GLuint handle() { return m_handle; } - bool exists() { return m_handle != 0; } - void use() { glUseProgram(m_handle); } + GLuint handle() const { return m_handle; } + bool exists() const { return m_handle != 0; } + void use() const { glUseProgram(m_handle); } }; static void dispatchCompute(GLuint groupsX = 1, GLuint groupsY = 1, GLuint groupsZ = 1) { @@ -454,9 +454,9 @@ namespace OpenGL { #ifdef OPENGL_DESTRUCTORS ~VertexBuffer() { free(); } #endif - GLuint handle() { return m_handle; } - bool exists() { return m_handle != 0; } - void bind() { glBindBuffer(GL_ARRAY_BUFFER, m_handle); } + GLuint handle() const { return m_handle; } + bool exists() const { return m_handle != 0; } + void bind() const { glBindBuffer(GL_ARRAY_BUFFER, m_handle); } void free() { glDeleteBuffers(1, &m_handle); } // Reallocates the buffer on every call. Prefer the sub version if possible. @@ -667,23 +667,23 @@ namespace OpenGL { // We're never supporting 3D rectangles, because rectangles were never meant to be 3D in the first place // x, y: Coords of the top left vertex // width, height: Dimensions of the rectangle. Initialized to 0 if not specified. - template - struct Rectangle { - T x, y, width, height; + template + struct Rectangle { + T x, y, width, height; - std::pair topLeft() { return std::make_pair(x, y); } - std::pair topRight() { return std::make_pair(x + width, y); } - std::pair bottomLeft() { return std::make_pair(x, y + height); } - std::pair bottomRight() { return std::make_pair(x + width, y + height); } + std::pair topLeft() const { return std::make_pair(x, y); } + std::pair topRight() const { return std::make_pair(x + width, y); } + std::pair bottomLeft() const { return std::make_pair(x, y + height); } + std::pair bottomRight() const { return std::make_pair(x + width, y + height); } - Rectangle() : x(0), y(0), width(0), height(0) {} - Rectangle(T x, T y, T width, T height) : x(x), y(y), width(width), height(height) {} + Rectangle() : x(0), y(0), width(0), height(0) {} + Rectangle(T x, T y, T width, T height) : x(x), y(y), width(width), height(height) {} - bool isEmpty() { return width == 0 && height == 0; } - bool isLine() { return (width == 0 && height != 0) || (width != 0 && height == 0); } + bool isEmpty() const { return width == 0 && height == 0; } + bool isLine() const { return (width == 0 && height != 0) || (width != 0 && height == 0); } - void setEmpty() { x = y = width = height = 0; } - }; + void setEmpty() { x = y = width = height = 0; } + }; using Rect = Rectangle;