Files
cuber/cbt/opengl/texture.hpp
T
portersky 90d013695d feat: add OpenGL abstraction layer with RAII resources
- Replace window class with cbt::opengl::context
- Add buffer resource (VBO, EBO, UBO, SSBO) with move semantics
- Add texture resource with format/type enums and filtering
- Add descriptor_set for Vulkan-style resource binding
- All resources use RAII with proper cleanup
2026-05-05 21:58:34 +02:00

58 lines
1.2 KiB
C++

#pragma once
#include <cstddef>
#include <vector>
#include "glad/glad.h"
namespace cbt::opengl {
enum class texture_target {
_1d = GL_TEXTURE_1D,
_2d = GL_TEXTURE_2D,
_3d = GL_TEXTURE_3D,
cube = GL_TEXTURE_CUBE_MAP,
};
enum class texture_format {
rgb = GL_RGB,
rgba = GL_RGBA,
rg = GL_RG,
red = GL_RED,
depth = GL_DEPTH_COMPONENT,
};
enum class texture_type {
ubyte = GL_UNSIGNED_BYTE,
ushort = GL_UNSIGNED_SHORT,
uint = GL_UNSIGNED_INT,
float_ = GL_FLOAT,
};
class texture {
GLuint m_id = 0;
texture_target m_target = texture_target::_2d;
public:
texture();
explicit texture(texture_target target);
~texture();
texture(const texture&) = delete;
texture& operator=(const texture&) = delete;
texture(texture&& other) noexcept;
texture& operator=(texture&& other) noexcept;
auto bind(GLuint unit = 0) -> void;
auto unbind() -> void;
auto upload(const void* data, int width, int height, texture_format format, texture_type type) -> void;
auto set_filter(GLenum min_filter, GLenum mag_filter) -> void;
auto set_wrap(GLenum wrap_s, GLenum wrap_t) -> void;
auto generate_mipmaps() -> void;
auto id() const -> GLuint;
auto valid() const -> bool;
};
}