mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
refactor: renderer (#29)
* refactor(render): move render files to subdirectory, add RAII vertex buffer/array classes * refactor(render): encapsulate OpenGL textures into Texture class * refactor(texture): encapsulate textures with unique_ptr and bind methods Replace raw GLuint framebuffer textures with std::unique_ptr<Texture>. Update TextureManager to return const Texture* instead of GLuint. Use Texture::bind() for active texture binding. Add RGBA16F and RGB formats. Add texture parameter methods. Update destructors accordingly. * refactor(render): use Texture, VertexBuffer, VertexArray classes * feat(render): add FrameBuffer class to encapsulate framebuffer operations * refactor(render): extract world rendering into WorldRenderer class * refactor(render): rename projection and model matrix members for clarity * chore(render): remove unused matrix members * fix(texture-manager): correct delet_texture typo and add null checks for textures
This commit is contained in:
36
include/Cubed/render/vertex_buffer.hpp
Normal file
36
include/Cubed/render/vertex_buffer.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
namespace Cubed {
|
||||
|
||||
enum class BufferType : GLenum {
|
||||
ARRAY_BUFFER = GL_ARRAY_BUFFER,
|
||||
ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER
|
||||
};
|
||||
|
||||
enum class BufferUsage : GLenum {
|
||||
STATIC_DRAW = GL_STATIC_DRAW,
|
||||
DYNAMIC_DRAW = GL_DYNAMIC_DRAW
|
||||
};
|
||||
|
||||
class VertexBuffer {
|
||||
public:
|
||||
VertexBuffer(BufferType type = BufferType::ARRAY_BUFFER);
|
||||
VertexBuffer(const VertexBuffer&) = delete;
|
||||
VertexBuffer(VertexBuffer&&) noexcept;
|
||||
VertexBuffer& operator=(const VertexBuffer&) = delete;
|
||||
VertexBuffer& operator=(VertexBuffer&&) noexcept;
|
||||
~VertexBuffer();
|
||||
|
||||
void bind() const;
|
||||
static void unbind();
|
||||
GLuint id() const;
|
||||
void buffer_data(const void* data, GLsizeiptr size,
|
||||
BufferUsage usage = BufferUsage::STATIC_DRAW) const;
|
||||
|
||||
private:
|
||||
GLuint m_vbo = 0;
|
||||
BufferType m_type = BufferType::ARRAY_BUFFER;
|
||||
|
||||
GLenum get_buffer_target() const;
|
||||
};
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user