47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
#pragma once
|
|
#include "image.h"
|
|
|
|
class Texture2D
|
|
{
|
|
GLuint m_tex;
|
|
int m_width;
|
|
int m_height;
|
|
GLint m_format;
|
|
GLint m_iformat;
|
|
public:
|
|
bool create(int width, int height, GLint internal_format = GL_RGBA8, GLint format = GL_RGBA, const uint8_t* data = nullptr);
|
|
bool create(const ui::Image& img);
|
|
void assign(GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA);
|
|
bool load(std::string filename);
|
|
void destroy() { LOG("TEX destroy %d", m_tex); glDeleteTextures(1, &m_tex); }
|
|
void bind() const { glBindTexture(GL_TEXTURE_2D, m_tex); }
|
|
void unbind() const { glBindTexture(GL_TEXTURE_2D, 0); }
|
|
void update(const uint8_t* data);
|
|
bool ready() const { return m_tex != 0; }
|
|
void create_mipmaps();
|
|
glm::vec2 size() const;
|
|
};
|
|
|
|
class Sampler
|
|
{
|
|
GLuint id;
|
|
GLint current_unit;
|
|
public:
|
|
bool create(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE);
|
|
void set(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE);
|
|
void set_filter(GLint filter_min, GLint filter_mag);
|
|
void bind(int unit);
|
|
void unbind();
|
|
bool ready() const { return id != 0; }
|
|
};
|
|
|
|
class TextureManager
|
|
{
|
|
public:
|
|
static std::map<uint16_t, Texture2D> m_textures;
|
|
static bool load(const char* path, bool generate_mipmpas = false);
|
|
static void assign(uint16_t id, GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA);
|
|
static Texture2D& get(uint16_t id);
|
|
static void invalidate();
|
|
};
|