Extra2D/include/renderer/texture.h

107 lines
2.3 KiB
C
Raw Normal View History

#pragma once
#include <types/ptr/ref_counted.h>
#include <types/ptr/intrusive_ptr.h>
#include <renderer/render_types.h>
#include <types/base/types.h>
#include <string>
// 前向声明 OpenGL 类型
typedef unsigned int GLuint;
namespace extra2d {
/**
* @brief
*
* OpenGL
*
*/
class Texture : public RefCounted {
public:
/**
* @brief
*/
Texture();
/**
* @brief
*/
~Texture() override;
/**
* @brief
* @param path
* @return
*/
bool loadFromFile(const std::string& path);
/**
* @brief
* @param data
* @param width
* @param height
* @param format
* @return
*/
bool loadFromMemory(const uint8_t* data, int width, int height, TextureFormat format);
/**
* @brief
* @param width
* @param height
* @param format
* @return
*/
bool create(int width, int height, TextureFormat format);
/**
* @brief
* @param slot
*/
void bind(uint32_t slot = 0) const;
/**
* @brief
*/
void unbind() const;
/**
* @brief
* @return
*/
int getWidth() const { return width_; }
/**
* @brief
* @return
*/
int getHeight() const { return height_; }
/**
* @brief
* @return
*/
TextureFormat getFormat() const { return format_; }
/**
* @brief OpenGL
* @return OpenGL
*/
GLuint getHandle() const { return texture_; }
/**
* @brief
* @return
*/
bool isLoaded() const { return texture_ != 0; }
private:
GLuint texture_ = 0; // OpenGL 纹理对象
int width_ = 0; // 纹理宽度
int height_ = 0; // 纹理高度
TextureFormat format_ = TextureFormat::RGBA8; // 像素格式
};
} // namespace extra2d