diff --git a/deps/glutils/include/glutils/glutils.hpp b/deps/glutils/include/glutils/glutils.hpp index 3c7db967d..1e8a61528 100644 --- a/deps/glutils/include/glutils/glutils.hpp +++ b/deps/glutils/include/glutils/glutils.hpp @@ -89,7 +89,7 @@ struct GLObject: public Base { return id; } - constexpr operator const GLuint&() const noexcept { + constexpr operator GLuint const&() const noexcept { return id; } @@ -135,7 +135,7 @@ struct FrameBuffer { return fbo.id; } - constexpr operator const GLuint&() const noexcept { + constexpr operator GLuint const&() const noexcept { return fbo.id; } @@ -158,14 +158,14 @@ struct FrameBuffer { class FrameBufferBind { private: - static const FrameBuffer *s_activeFb; - const FrameBuffer *m_restoreFb = nullptr; + static FrameBuffer const *s_activeFb; + FrameBuffer const *m_restoreFb = nullptr; public: - explicit FrameBufferBind(const FrameBuffer &fb) noexcept; + explicit FrameBufferBind(FrameBuffer const &fb) noexcept; ~FrameBufferBind() noexcept; }; -void bind(const FrameBuffer &fb) noexcept; +void bind(FrameBuffer const &fb) noexcept; struct ShaderVarSet { GLsizei len{}; @@ -176,7 +176,7 @@ struct ProgramSource { ox::Vector const shaderParams; GLsizei const rowLen = [this] { GLsizei len{}; - for (auto const&v : shaderParams) { + for (auto const &v : shaderParams) { len += v.len; } return len; @@ -187,23 +187,23 @@ struct ProgramSource { ox::String const geomShader{}; }; -ox::Result buildShaderProgram(ProgramSource const&src) noexcept; +ox::Result buildShaderProgram(ProgramSource const &src) noexcept; ox::Result buildShaderProgram( - ox::CStringView const&vert, - ox::CStringView const&frag, - ox::CStringView const&geo = "") noexcept; + ox::CStringView const &vert, + ox::CStringView const &frag, + ox::CStringView const &geo = "") noexcept; void setupShaderParams( - GLProgram const&shader, - ox::Vector const&vars, + GLProgram const &shader, + ox::Vector const &vars, GLsizei vertexRowLen) noexcept; -void setupShaderParams(GLProgram const&shader, ox::Vector const&vars) noexcept; +void setupShaderParams(GLProgram const &shader, ox::Vector const &vars) noexcept; -glutils::GLVertexArray generateVertexArrayObject() noexcept; +GLVertexArray generateVertexArrayObject() noexcept; -glutils::GLBuffer generateBuffer() noexcept; +GLBuffer generateBuffer() noexcept; [[nodiscard]] FrameBuffer generateFrameBuffer(int width, int height) noexcept; @@ -215,20 +215,20 @@ void resizeFrameBuffer(FrameBuffer &fb, int width, int height) noexcept; */ void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept; -void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const&sz) noexcept; +void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const &sz) noexcept; struct BufferSet { - glutils::GLVertexArray vao; - glutils::GLBuffer vbo; - glutils::GLBuffer ebo; - glutils::GLTexture tex; + GLVertexArray vao; + GLBuffer vbo; + GLBuffer ebo; + GLTexture tex; ox::Vector vertices; ox::Vector elements; }; -void sendVbo(BufferSet const&bs) noexcept; +void sendVbo(BufferSet const &bs) noexcept; -void sendEbo(BufferSet const&bs) noexcept; +void sendEbo(BufferSet const &bs) noexcept; void clearScreen() noexcept; diff --git a/deps/glutils/src/glutils.cpp b/deps/glutils/src/glutils.cpp index b705e6036..0e630666a 100644 --- a/deps/glutils/src/glutils.cpp +++ b/deps/glutils/src/glutils.cpp @@ -46,9 +46,9 @@ template struct GLObject; template struct GLObject; template struct GLObject; -const FrameBuffer *FrameBufferBind::s_activeFb = nullptr; +FrameBuffer const *FrameBufferBind::s_activeFb = nullptr; -FrameBufferBind::FrameBufferBind(const FrameBuffer &fb) noexcept: m_restoreFb(s_activeFb) { +FrameBufferBind::FrameBufferBind(FrameBuffer const &fb) noexcept: m_restoreFb(s_activeFb) { s_activeFb = &fb; glBindFramebuffer(GL_FRAMEBUFFER, fb); glViewport(0, 0, fb.width, fb.height); @@ -64,15 +64,15 @@ FrameBufferBind::~FrameBufferBind() noexcept { } } -void bind(const FrameBuffer &fb) noexcept { +void bind(FrameBuffer const &fb) noexcept { glBindFramebuffer(GL_FRAMEBUFFER, fb); glViewport(0, 0, fb.width, fb.height); } static ox::Result buildShader( - GLuint shaderType, - const GLchar *src, + GLuint const shaderType, + GLchar const *src, ox::StringViewCR shaderName) noexcept { GLShader shader(glCreateShader(shaderType)); glShaderSource(shader, 1, &src, nullptr); @@ -88,7 +88,7 @@ static ox::Result buildShader( return shader; } -ox::Result buildShaderProgram(ProgramSource const&src) noexcept { +ox::Result buildShaderProgram(ProgramSource const &src) noexcept { OX_REQUIRE_M(program, buildShaderProgram( src.vertShader, src.fragShader, @@ -98,11 +98,11 @@ ox::Result buildShaderProgram(ProgramSource const&src) noexcept { } void setupShaderParams( - GLProgram const&shader, - ox::Vector const&vars, + GLProgram const &shader, + ox::Vector const &vars, GLsizei vertexRowLen) noexcept { // setup vars - for (size_t lenWritten = 0; auto const&v : vars) { + for (size_t lenWritten = 0; auto const &v : vars) { auto const attr = static_cast(glGetAttribLocation(shader, v.name.c_str())); glEnableVertexAttribArray(attr); glVertexAttribPointer( @@ -113,19 +113,19 @@ void setupShaderParams( } } -void setupShaderParams(GLProgram const&shader, ox::Vector const&vars) noexcept { +void setupShaderParams(GLProgram const &shader, ox::Vector const &vars) noexcept { // get row len GLsizei vertexRowLen{}; - for (auto const&v : vars) { + for (auto const &v : vars) { vertexRowLen += v.len; } setupShaderParams(shader, vars, vertexRowLen); } ox::Result buildShaderProgram( - ox::CStringView const&vert, - ox::CStringView const&frag, - ox::CStringView const&geo) noexcept { + ox::CStringView const &vert, + ox::CStringView const &frag, + ox::CStringView const &geo) noexcept { GLProgram prgm(glCreateProgram()); OX_REQUIRE(vs, buildShader(GL_VERTEX_SHADER, vert.c_str(), "vshad")); glAttachShader(prgm, vs); @@ -162,16 +162,30 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept { // color texture glGenTextures(1, &fb.color.id); glBindTexture(GL_TEXTURE_2D, fb.color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGB, + width, + height, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + nullptr); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0); + glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0); // depth texture glGenRenderbuffers(1, &fb.depth.id); glBindRenderbuffer(GL_RENDERBUFFER, fb.depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb.depth); + glFramebufferRenderbuffer( + GL_FRAMEBUFFER, + GL_DEPTH_STENCIL_ATTACHMENT, + GL_RENDERBUFFER, + fb.depth); // verify FBO oxAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Frame Buffer is incomplete"); // restore primary FB @@ -189,7 +203,16 @@ void resizeFrameBuffer(FrameBuffer &fb, int width, int height) noexcept { glBindFramebuffer(GL_FRAMEBUFFER, fb); // color texture glBindTexture(GL_TEXTURE_2D, fb.color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGB, + width, + height, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // depth texture @@ -201,7 +224,7 @@ void resizeFrameBuffer(FrameBuffer &fb, int width, int height) noexcept { glBindRenderbuffer(GL_RENDERBUFFER, 0); } -void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept { +void resizeInitFrameBuffer(FrameBuffer &fb, int const width, int const height) noexcept { if (!fb) { fb = generateFrameBuffer(width, height); return; @@ -209,18 +232,18 @@ void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept { resizeFrameBuffer(fb, width, height); } -void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const&sz) noexcept { +void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const &sz) noexcept { resizeInitFrameBuffer(fb, sz.width, sz.height); } -void sendVbo(BufferSet const&bs) noexcept { - const auto bufferSize = static_cast(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size()); +void sendVbo(BufferSet const &bs) noexcept { + auto const bufferSize = static_cast(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size()); glBindBuffer(GL_ARRAY_BUFFER, bs.vbo); glBufferData(GL_ARRAY_BUFFER, bufferSize, bs.vertices.data(), GL_DYNAMIC_DRAW); } -void sendEbo(BufferSet const&bs) noexcept { - const auto bufferSize = static_cast(sizeof(decltype(bs.elements)::value_type) * bs.elements.size()); +void sendEbo(BufferSet const &bs) noexcept { + auto const bufferSize = static_cast(sizeof(decltype(bs.elements)::value_type) * bs.elements.size()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bs.ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferSize, bs.elements.data(), GL_STATIC_DRAW); }