Extra2D/include/renderer/texture.h

116 lines
2.7 KiB
C
Raw Permalink Normal View History

#pragma once
#include <renderer/rhi/rhi.h>
#include <types/ptr/ref_counted.h>
#include <types/ptr/intrusive_ptr.h>
#include <types/base/types.h>
#include <string>
namespace extra2d {
/**
* @brief
*
* RHI
*
*/
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
* @return
*/
int getWidth() const { return width_; }
/**
* @brief
* @return
*/
int getHeight() const { return height_; }
/**
* @brief
* @return
*/
TextureFormat getFormat() const { return format_; }
/**
* @brief RHI
* @return RHI
*/
TextureHandle getHandle() const { return handle_; }
/**
* @brief
* @return
*/
bool isLoaded() const { return handle_.isValid(); }
/**
* @brief
* @param path
* @return
*/
bool reloadFromFile(const std::string& path);
/**
* @brief
* @param data
* @param width
* @param height
* @param format
* @return
*/
bool reloadFromMemory(const uint8_t* data, int width, int height, TextureFormat format);
private:
/**
* @brief
* @param format
* @return
*/
static uint32_t getBytesPerPixel(TextureFormat format);
TextureHandle handle_; // RHI 纹理句柄
int width_ = 0; // 纹理宽度
int height_ = 0; // 纹理高度
TextureFormat format_ = TextureFormat::RGBA8; // 像素格式
};
} // namespace extra2d