Work at 3ds support and backend upgrades
- Track textures (not sure if this is done tbh) - Add lithium formatters and move TextureID, TextureFormat and TextureFilter to lithium - Only include gl-helper if any glDriver is included - Add Li::Rect for UV stuff - Add Li::Texture as Info holder (still thinking of making them to ptrs - Add Check if textures are still loaded on exit
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/formatters.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
|
||||
template <>
|
||||
struct std::formatter<PD::TextureFilter> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::TextureFilter& value, FormatContext& ctx) const {
|
||||
std::string_view ret = "Unknown";
|
||||
switch (value) {
|
||||
case PD::TextureFilter::Linear:
|
||||
ret = "Linear";
|
||||
break;
|
||||
case PD::TextureFilter::Nearest:
|
||||
ret = "Nearest";
|
||||
break;
|
||||
}
|
||||
return std::format_to(ctx.out(), "{}", ret);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<PD::TextureFormat> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::TextureFormat& value, FormatContext& ctx) const {
|
||||
std::string_view ret = "Unknown";
|
||||
switch (value) {
|
||||
case PD::TextureFormat::RGBA32:
|
||||
ret = "RGBA32";
|
||||
break;
|
||||
case PD::TextureFormat::RGB24:
|
||||
ret = "RGB24";
|
||||
break;
|
||||
case PD::TextureFormat::A8:
|
||||
ret = "A8";
|
||||
break;
|
||||
}
|
||||
return std::format_to(ctx.out(), "{}", ret);
|
||||
}
|
||||
};
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <pd/core/mat.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LiBackendFlags = PD::u32;
|
||||
enum LiBackendFlags_ {
|
||||
@@ -11,23 +12,12 @@ enum LiBackendFlags_ {
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
using TextureID = ptr;
|
||||
enum class TextureFilter {
|
||||
Linear,
|
||||
Nearest,
|
||||
};
|
||||
|
||||
enum class TextureFormat {
|
||||
RGBA32,
|
||||
RGB24,
|
||||
A8,
|
||||
};
|
||||
|
||||
// Pre interface class
|
||||
class PD_API GfxDriver : public DriverInterface {
|
||||
public:
|
||||
GfxDriver(std::string_view name);
|
||||
virtual ~GfxDriver() = default;
|
||||
virtual ~GfxDriver();
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() { SysDeinit(); }
|
||||
@@ -36,12 +26,13 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
void SetViewPort(int x, int y);
|
||||
virtual void BindTexture(TextureID id) {}
|
||||
void Reset();
|
||||
virtual TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {
|
||||
return 0;
|
||||
virtual Li::Texture LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {
|
||||
return Li::Texture();
|
||||
}
|
||||
virtual void DeleteTexture(const TextureID& tex) {}
|
||||
virtual void DeleteTexture(const Li::Texture& tex) {}
|
||||
virtual void Draw(const Pool<Li::Command>& commands) {}
|
||||
|
||||
protected:
|
||||
@@ -50,6 +41,8 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
virtual void SysReset() {}
|
||||
virtual void Submit(size_t count, size_t start) {}
|
||||
virtual void ResetPools() = 0;
|
||||
void RegisterTexture(const Li::Texture& tex);
|
||||
void UnregisterTexture(const Li::Texture& tex);
|
||||
|
||||
// Counters
|
||||
size_t CountDrawcalls = 0;
|
||||
@@ -61,6 +54,7 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
TextureID CurrentTex = 0;
|
||||
Mat4 Projection;
|
||||
ivec2 ViewPort;
|
||||
std::unordered_map<TextureID, Li::Texture> pTextureRegestry;
|
||||
};
|
||||
|
||||
struct DefaultGfxConfig {
|
||||
@@ -152,11 +146,15 @@ class PD_API Gfx {
|
||||
static void Draw(const Pool<Li::Command>& commands) {
|
||||
driver->Draw(commands);
|
||||
}
|
||||
static TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {
|
||||
static Li::Texture LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {
|
||||
return driver->LoadTexture(pixels, w, h, type, filter);
|
||||
}
|
||||
static void DeleteTexture(const Li::Texture& tex) {
|
||||
driver->DeleteTexture(tex);
|
||||
}
|
||||
|
||||
static const char* GetDriverName() { return driver->GetName(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user