From ed08b673c50b076042d8f0c49501372168142764 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 16 Feb 2018 16:04:32 -0500 Subject: Refactored renderer Renderer is basically now more C++'y, as it makes more use of classes (a lot of GL types have been wrapped), and the renderer itself is now a class. The monitor mesh is also now indexed. Tweaked the NTSC artifacting after inadvertently fixing a bug with the way the image was loaded. --- src/renderer/wrappers.h | 273 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 src/renderer/wrappers.h (limited to 'src/renderer/wrappers.h') diff --git a/src/renderer/wrappers.h b/src/renderer/wrappers.h new file mode 100644 index 0000000..c6edc11 --- /dev/null +++ b/src/renderer/wrappers.h @@ -0,0 +1,273 @@ +#ifndef WRAPPERS_H_1EE0965B +#define WRAPPERS_H_1EE0965B + +#include "gl.h" +#include + +class GLVertexArray { +public: + + GLVertexArray() + { + glGenVertexArrays(1, &id_); + } + + GLVertexArray(const GLVertexArray& other) = delete; + GLVertexArray& operator=(const GLVertexArray& other) = delete; + + GLVertexArray(GLVertexArray&& other) : GLVertexArray() + { + std::swap(id_, other.id_); + } + + GLVertexArray& operator=(GLVertexArray&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLVertexArray() + { + glDeleteVertexArrays(1, &id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +class GLFramebuffer { +public: + + GLFramebuffer() + { + glGenFramebuffers(1, &id_); + } + + GLFramebuffer(const GLFramebuffer& other) = delete; + GLFramebuffer& operator=(const GLFramebuffer& other) = delete; + + GLFramebuffer(GLFramebuffer&& other) : GLFramebuffer() + { + std::swap(id_, other.id_); + } + + GLFramebuffer& operator=(GLFramebuffer&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLFramebuffer() + { + glDeleteFramebuffers(1, &id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +class GLRenderbuffer { +public: + + GLRenderbuffer() + { + glGenRenderbuffers(1, &id_); + } + + GLRenderbuffer(const GLRenderbuffer& other) = delete; + GLRenderbuffer& operator=(const GLRenderbuffer& other) = delete; + + GLRenderbuffer(GLRenderbuffer&& other) : GLRenderbuffer() + { + std::swap(id_, other.id_); + } + + GLRenderbuffer& operator=(GLRenderbuffer&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLRenderbuffer() + { + glDeleteRenderbuffers(1, &id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +class GLBuffer { +public: + + GLBuffer() + { + glGenBuffers(1, &id_); + } + + GLBuffer(const GLBuffer& other) = delete; + GLBuffer& operator=(const GLBuffer& other) = delete; + + GLBuffer(GLBuffer&& other) : GLBuffer() + { + std::swap(id_, other.id_); + } + + GLBuffer& operator=(GLBuffer&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLBuffer() + { + glDeleteBuffers(1, &id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +class GLTexture { +public: + + GLTexture() + { + glGenTextures(1, &id_); + } + + GLTexture(const GLTexture& other) = delete; + GLTexture& operator=(const GLTexture& other) = delete; + + GLTexture(GLTexture&& other) : GLTexture() + { + std::swap(id_, other.id_); + } + + GLTexture& operator=(GLTexture&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLTexture() + { + glDeleteTextures(1, &id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +class GLShader { +public: + + GLShader(GLenum type) + { + id_ = glCreateShader(type); + } + + GLShader(const GLShader& other) = delete; + GLShader& operator=(const GLShader& other) = delete; + + GLShader(GLShader&& other) : GLShader(GL_VERTEX_SHADER) + { + std::swap(id_, other.id_); + } + + GLShader& operator=(GLShader&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLShader() + { + glDeleteShader(id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +class GLProgram { +public: + + GLProgram() + { + id_ = glCreateProgram(); + } + + GLProgram(const GLProgram& other) = delete; + GLProgram& operator=(const GLProgram& other) = delete; + + GLProgram(GLProgram&& other) : GLProgram() + { + std::swap(id_, other.id_); + } + + GLProgram& operator=(GLProgram&& other) + { + std::swap(id_, other.id_); + + return *this; + } + + ~GLProgram() + { + glDeleteProgram(id_); + } + + inline GLuint getId() const + { + return id_; + } + +private: + + GLuint id_; +}; + +#endif /* end of include guard: WRAPPERS_H_1EE0965B */ -- cgit 1.4.1