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:
2026-03-18 09:31:47 +01:00
parent d4c59e5b61
commit e04046720b
28 changed files with 791 additions and 243 deletions

View File

@@ -0,0 +1,25 @@
#pragma once
#include <pd/core/core.hpp>
#include <pd/lithium/texture.hpp>
namespace PD {
namespace Li {
enum class AtlasState {
Invalid,
ReqCreate,
ReqUpdate,
ReqDestroy,
};
class Atlas {
public:
Atlas() {}
~Atlas() {}
private:
AtlasState pState = AtlasState::Invalid;
TextureID pID;
};
} // namespace Li
} // namespace PD

View File

@@ -0,0 +1,109 @@
#pragma once
#include <pd/lithium/atlas.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.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);
}
};
template <>
struct std::formatter<PD::Li::Rect> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::Rect& value, FormatContext& ctx) const {
// {l, t, r, t, l, b, r, b}
return std::format_to(ctx.out(), "{}, {}, {}, {}, {}, {}, {}, {}",
value.Top.x, value.Top.y, value.Top.z, value.Top.w,
value.Bot.x, value.Bot.y, value.Bot.z, value.Bot.w);
}
};
template <>
struct std::formatter<PD::Li::Texture> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::Texture& value, FormatContext& ctx) const {
// {ID, [w, h], [l, t, r, t, l, b, r, b]}
return std::format_to(ctx.out(), "{}, [{}], [{}]", value.GetID(),
value.GetSize(), value.GetUV());
}
};
template <>
struct std::formatter<PD::Li::Vertex> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::Vertex& value, FormatContext& ctx) const {
// { [x, y], [u, v], colorhex }
return std::format_to(ctx.out(), "[{}], [{}], #{:08X}", value.pos, value.uv,
value.color);
}
};
template <>
struct std::formatter<PD::Li::AtlasState> : std::formatter<std::string> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const PD::Li::AtlasState& value, FormatContext& ctx) const {
std::string_view ret = "Unknown";
switch (value) {
case PD::Li::AtlasState::Invalid:
ret = "Invalid";
break;
case PD::Li::AtlasState::ReqCreate:
ret = "RequestCreate";
break;
case PD::Li::AtlasState::ReqUpdate:
ret = "RequestUpdate";
break;
case PD::Li::AtlasState::ReqDestroy:
ret = "RequestDestroy";
break;
}
return std::format_to(ctx.out(), "{}", ret);
}
};

149
include/pd/lithium/rect.hpp Normal file
View File

@@ -0,0 +1,149 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
namespace PD {
namespace Li {
class Rect {
public:
Rect() : Top(0), Bot(0) {}
~Rect() = default;
/**
* Constructor that initializes the rectangle using top and bottom positions.
* @param t Top left and right corner positions.
* @param b Bottom left and right corner positions.
*/
Rect(const fvec4& t, const fvec4& b) {
Top = t;
Bot = b;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
* @param tl Top left corner position.
* @param tr Top right corner position.
* @param bl Bottom left corner position.
* @param br Bottom right corner position.
*/
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
Top = fvec4(tl, tr);
Bot = fvec4(bl, br);
}
/**
* Constructor that initializes the rectangle using a UV mapping vector.
*
* - The old API used vec4 for UV mapping.
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
*
* @param uv Vec4 UV map.
*/
Rect(const fvec4& uv) {
Top = vec4(uv.x, uv.y, uv.z, uv.y);
Bot = vec4(uv.x, uv.w, uv.z, uv.w);
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
/**
* Get the top-right corner position.
* @return Top-right position as vec2.
*/
fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
/**
* Get the bottom-right corner position.
* @return Bottom-right position as vec2.
*/
fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); }
/**
* Set the top-left corner position.
* @param v New top-left position.
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const fvec2& v) {
Top.x = v.x;
Top.y = v.y;
return *this;
}
/**
* Set the top-right corner position.
* @param v New top-right position.
* @return Reference to the updated Rect.
*/
Rect& TopRight(const fvec2& v) {
Top.z = v.x;
Top.w = v.y;
return *this;
}
/**
* Set the bottom-left corner position.
* @param v New bottom-left position.
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const fvec2& v) {
Bot.x = v.x;
Bot.y = v.y;
return *this;
}
/**
* Set the bottom-right corner position.
* @param v New bottom-right position.
* @return Reference to the updated Rect.
*/
Rect& BotRight(const fvec2& v) {
Bot.z = v.x;
Bot.w = v.y;
return *this;
}
bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; }
void SwapVec2XY() {
Top.SwapXY();
Top.SwapZW();
Bot.SwapXY();
Bot.SwapZW();
}
/** Data Section */
fvec4 Top;
fvec4 Bot;
};
} // namespace Li
} // namespace PD

View File

@@ -0,0 +1,46 @@
#pragma once
#include <pd/core/core.hpp>
#include <pd/lithium/rect.hpp>
namespace PD {
using TextureID = ptr;
enum class TextureFilter {
Linear,
Nearest,
};
enum class TextureFormat {
RGBA32,
RGB24,
A8,
};
namespace Li {
class Texture {
public:
Texture() : pID(0), pSize(0, 0), pUV(fvec4(0, 0, 1, 1)) {}
Texture(TextureID id, ivec2 size)
: pID(id), pSize(size), pUV(fvec4(0, 0, 1, 1)) {}
const ivec2& GetSize() const { return pSize; }
TextureID GetID() { return pID; }
const TextureID& GetID() const { return pID; }
const Rect& GetUV() const { return pUV; }
void SetSize(int x, int y) {
pSize.x = x;
pSize.y = y;
}
void SetSize(const ivec2& size) { pSize = size; }
void SetID(TextureID id) { pID = id; }
void SetUV(const Rect& uv) { pUV = uv; }
void SetUV(const fvec4& uv) { pUV = uv; }
void SetUV(float t, float l, float b, float r) { SetUV(fvec4(t, l, b, r)); }
private:
TextureID pID;
ivec2 pSize;
Rect pUV;
};
} // namespace Li
} // namespace PD