Initial Cross Platform Work
This commit is contained in:
76
include/pd/lithium/backend.hpp
Normal file
76
include/pd/lithium/backend.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LIBackendFlags = PD::u32;
|
||||
enum LIBackendFlags_ {
|
||||
LIBackendFlags_None = 0,
|
||||
LIBackendFlags_FlipUV_Y = 1 << 0, // Essential for Font Loading
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class Backend {
|
||||
public:
|
||||
Backend(const std::string& name = "NullBackend") : pName(name) {}
|
||||
~Backend() = default;
|
||||
// Using Legacy SmartCTOR API here
|
||||
PD_SMART_CTOR(Backend)
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void NewFrame() {}
|
||||
|
||||
virtual void BindTexture(TexAddress addr) {}
|
||||
|
||||
virtual void RenderDrawData(const Vec<Command::Ref>& Commands) {}
|
||||
|
||||
virtual Texture::Ref LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
Texture::Type type = Texture::Type::RGBA32,
|
||||
Texture::Filter filter = Texture::Filter::LINEAR) {
|
||||
// Texture loading not supported (when this func not get override)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** Backend identification name */
|
||||
const std::string pName = "NullBackend";
|
||||
LIBackendFlags Flags = 0;
|
||||
ivec2 ViewPort;
|
||||
fvec4 ClearColor;
|
||||
// Optional Index Counter
|
||||
int IndexCounter = 0;
|
||||
// Optional Vertex Counter
|
||||
int VertexCounter = 0;
|
||||
// Optional Frame Counter
|
||||
int FrameCounter = 0;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,215 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/**
|
||||
* Lithium Draw Command (containing a list of vertex and index data
|
||||
* only for this specific command itself)
|
||||
*/
|
||||
class Command : public SmartCtor<Command> {
|
||||
public:
|
||||
Command() = default;
|
||||
~Command() = default;
|
||||
|
||||
/**
|
||||
* Copy Constructor [to Copy the Data of a Command Reference]
|
||||
*/
|
||||
Command(Command::Ref v) {
|
||||
this->index = v->index;
|
||||
this->index_buf = v->index_buf;
|
||||
this->layer = v->layer;
|
||||
this->mode = v->mode;
|
||||
this->tex = v->tex;
|
||||
this->vertex_buf = v->vertex_buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Commands layer
|
||||
* @param v layer value
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Layer(int v) {
|
||||
layer = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Layer
|
||||
* @return layer value
|
||||
*/
|
||||
int Layer() const { return layer; }
|
||||
|
||||
/**
|
||||
* Setter for the Commands Index [used in sorting]
|
||||
* @param v index value
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Index(int v) {
|
||||
index = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Index
|
||||
* @return index value
|
||||
*/
|
||||
int Index() const { return index; }
|
||||
|
||||
/**
|
||||
* Setter for the Commands Texture
|
||||
* @param v Texture reference
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Tex(Texture::Ref v) {
|
||||
tex = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Texture reference
|
||||
* @return Texture reference
|
||||
*/
|
||||
Texture::Ref Tex() const { return tex; }
|
||||
|
||||
/**
|
||||
* Function to Push a Vertex to the vertexbuffer
|
||||
* @param v Vertex to push
|
||||
* @return command reference
|
||||
*/
|
||||
Command& PushVertex(const Vertex& v) {
|
||||
vertex_buf.push_back(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to the Index list [used to write index data
|
||||
* to the real indexbuffer]
|
||||
* @return const reference to commands idx buffer
|
||||
*/
|
||||
const std::vector<u16>& IndexList() const { return index_buf; }
|
||||
/**
|
||||
* Access to the Vertex list [used to write vertices
|
||||
* data to the real vertexbuffer]
|
||||
* @return const reference to commands vertex buffer
|
||||
*/
|
||||
const std::vector<Vertex>& VertexList() const { return vertex_buf; }
|
||||
|
||||
// ADVANCED
|
||||
|
||||
/**
|
||||
* Advanced function to access index list
|
||||
*
|
||||
* - This function is UNSAFE to use cause it allows to modify index data
|
||||
* @return reference to index list
|
||||
*/
|
||||
std::vector<u16>& IndexList() { return index_buf; }
|
||||
/**
|
||||
* Advanced function to access vertex list
|
||||
*
|
||||
* - This function is UNSAFE to use cause it allows to modify index data
|
||||
* - Using this in StaticText to change Position color and stuff after it is
|
||||
* rendered into commands
|
||||
* @return reference to vertex list
|
||||
*/
|
||||
std::vector<Vertex>& VertexList() { return vertex_buf; }
|
||||
|
||||
/**
|
||||
* Function to Push an index value to indexbuffer
|
||||
* @param v Index value
|
||||
* @return command reference
|
||||
*/
|
||||
Command& PushIndex(u16 v) {
|
||||
index_buf.push_back(vertex_buf.size() + v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Commands RenderMode
|
||||
* @param v RenderMode
|
||||
* @return command reference
|
||||
*/
|
||||
Command& Rendermode(const RenderMode& v) {
|
||||
mode = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Commands RenderMode
|
||||
* @return RenderMode
|
||||
*/
|
||||
RenderMode Rendermode() const { return mode; }
|
||||
|
||||
/** Setter for Scissor Mode */
|
||||
Command& SetScissorMode(ScissorMode mode) {
|
||||
scissor = mode;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Getter for Scissor Mode */
|
||||
ScissorMode GetScissorMode() const { return scissor; }
|
||||
|
||||
/** Setter for Scissor Area */
|
||||
Command& ScissorRect(const vec4& v) {
|
||||
scissor_area = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Getter for Scissor Area */
|
||||
vec4 ScissorRect() const { return scissor_area; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Vertex Buffer
|
||||
*
|
||||
* - Using default vector here as its data will be copied later
|
||||
*/
|
||||
std::vector<Vertex> vertex_buf;
|
||||
/**
|
||||
* Index Buffer
|
||||
*
|
||||
* - Using default vector here as its data will be copied later
|
||||
*/
|
||||
std::vector<u16> index_buf;
|
||||
/** Layer */
|
||||
int layer;
|
||||
/** Texture Reference */
|
||||
Texture::Ref tex;
|
||||
/** Index */
|
||||
int index;
|
||||
/** RenderMode (Default to RenderMode_RGBA) */
|
||||
RenderMode mode = RenderMode_RGBA;
|
||||
/** Scissor Mode (for defined area to render) */
|
||||
ScissorMode scissor = ScissorMode_None;
|
||||
/** scissor box (top left and bottom right) */
|
||||
vec4 scissor_area;
|
||||
};
|
||||
} // namespace LI
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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>
|
||||
// #include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/**
|
||||
* Lithium Draw Command (containing a list of vertex and index data
|
||||
* only for this specific command itself)
|
||||
*/
|
||||
class Command : public SmartCtor<Command> {
|
||||
public:
|
||||
Command() = default;
|
||||
~Command() = default;
|
||||
|
||||
Command& AppendIndex(u16 idx) {
|
||||
IndexBuffer.Add(VertexBuffer.Size() + idx);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Command& AppendVertex(const Vertex& v) {
|
||||
VertexBuffer.Add(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec<Vertex> VertexBuffer;
|
||||
Vec<u16> IndexBuffer;
|
||||
ivec4 ScissorRect;
|
||||
bool ScissorEnabled = false;
|
||||
int Layer;
|
||||
int Index;
|
||||
Texture::Ref Tex;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
145
include/pd/lithium/drawlist.hpp
Normal file
145
include/pd/lithium/drawlist.hpp
Normal file
@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/lithium/command.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
|
||||
public:
|
||||
DrawList(Texture::Ref solid) {
|
||||
WhitePixel = solid;
|
||||
CurrentTex = solid;
|
||||
}
|
||||
~DrawList() {}
|
||||
|
||||
Command::Ref PreGenerateCmd();
|
||||
void AddCommand(Command::Ref v) { pDrawList.Add(v); }
|
||||
void Clear() { pDrawList.Clear(); }
|
||||
|
||||
void SetFont(Font::Ref font) { pCurrentFont = font; }
|
||||
void SetFontScale(float scale) { pFontScale = scale; }
|
||||
|
||||
void DrawSolid() { CurrentTex = WhitePixel; }
|
||||
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
|
||||
|
||||
// SECTION: Draw API //
|
||||
|
||||
void DrawRect(const fvec2& pos, const fvec2& size, u32 color,
|
||||
int thickness = 1);
|
||||
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
|
||||
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
|
||||
int thickness = 1);
|
||||
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
u32 color);
|
||||
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
|
||||
int thickness = 1);
|
||||
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
||||
int num_segments);
|
||||
void DrawText(const fvec2& p, const std::string& text, u32 color);
|
||||
|
||||
/**
|
||||
* Take list of points and display it as a line on screen
|
||||
* @param points List of Positions
|
||||
* @param clr Color of the Line
|
||||
* @param flags Additional Flags (Close for go back to starting point)
|
||||
* @param thickness Thickness of the Line
|
||||
*/
|
||||
void DrawPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
||||
int thickness = 1);
|
||||
/**
|
||||
* Take a List ofpoints and display it as Filled Shape
|
||||
* @note Keep in mind to setup the list of points clockwise
|
||||
* @param points List of Points
|
||||
* @param clr Color of the shape
|
||||
*/
|
||||
void DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
|
||||
|
||||
// SECTION: PATH API //
|
||||
|
||||
/**
|
||||
* Function to reserve Memory to prevent overhead on
|
||||
* pusing a lot of points with PathNext
|
||||
* @param num_points Number of Positions you want to add
|
||||
*/
|
||||
void PathReserve(size_t num_points) {
|
||||
pPath.Reserve(pPath.Size() + num_points);
|
||||
}
|
||||
/**
|
||||
* Clear current Path
|
||||
* @note PathStroke and PathFill will automatically clear
|
||||
*/
|
||||
void PathClear() { pPath.Clear(); }
|
||||
/**
|
||||
* Add a Point to the Path
|
||||
* @note Keep in mind that this function is used for
|
||||
* setting the starting point
|
||||
* @param v Position to add
|
||||
*/
|
||||
void PathAdd(const fvec2& v) { pPath.Add(v); }
|
||||
/**
|
||||
* Path Stroke Create Line from point to point
|
||||
* @note For Primitives like Rect or Triangle mak sure to use
|
||||
* UI7DrawFlags_Close to add a line back to the starting point
|
||||
* @param clr Color od the line
|
||||
* @param thickness Thickness of the line
|
||||
* @param flags Additional Drawflags
|
||||
*/
|
||||
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
||||
DrawPolyLine(pPath, clr, flags, thickness);
|
||||
pPath.Clear();
|
||||
}
|
||||
/**
|
||||
* Fill a Path with a Color
|
||||
* @note **IMPORTANT: ** Paths need to be setup clockwise
|
||||
* to be rendered correctly
|
||||
* @param clr Fill Color
|
||||
*/
|
||||
void PathFill(u32 clr) {
|
||||
DrawConvexPolyFilled(pPath, clr);
|
||||
pPath.Clear();
|
||||
}
|
||||
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
||||
int segments);
|
||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
||||
/// @param a Top Left Position
|
||||
/// @param b Bottom Right Position
|
||||
/// @param rounding rounding
|
||||
/// @param flags DrawFlags (for special rounding rules)
|
||||
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
||||
|
||||
int Layer = 0;
|
||||
float pFontScale = 0.7f;
|
||||
Font::Ref pCurrentFont = nullptr;
|
||||
Texture::Ref CurrentTex = nullptr;
|
||||
Texture::Ref WhitePixel = nullptr;
|
||||
PD::Vec<Command::Ref> pDrawList;
|
||||
PD::Vec<fvec2> pPath;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
|
||||
/** Alias for Lithium Text Flags */
|
||||
using LITextFlags = PD::u32;
|
||||
|
||||
/** LITextFlags */
|
||||
enum LITextFlags_ {
|
||||
LITextFlags_None = 0, ///< Do nothing
|
||||
LITextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||
LITextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||
LITextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||
LITextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
|
||||
LITextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
|
||||
LITextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
|
||||
LITextFlags_RenderOOS = 1 << 6 ///< Render Out of Screen
|
||||
};
|
||||
|
||||
/** Aliad for Lithium Render Flags */
|
||||
using LIRenderFlags = PD::u32;
|
||||
/** LIRenderFlags */
|
||||
enum LIRenderFlags_ {
|
||||
LIRenderFlags_None = 0, ///< Nothing
|
||||
LIRenderFlags_TMS = 1 << 0, ///< Text Map System
|
||||
LIRenderFlags_LRS = 1 << 1, ///< Layer Render System
|
||||
LIRenderFlags_AST = 1 << 2, ///< Auto Static Text
|
||||
/** Default Enables all of them */
|
||||
LIRenderFlags_Default =
|
||||
LIRenderFlags_TMS | LIRenderFlags_LRS | LIRenderFlags_AST,
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/** RenderMode [Required to modify TexENV] */
|
||||
enum RenderMode {
|
||||
RenderMode_RGBA, ///< RGBA [for textures or solid colors]
|
||||
RenderMode_Font, ///< A8 [for textures only crated by 1 color channel]
|
||||
};
|
||||
/** Scissor Mode (for ClipRect related rendering) */
|
||||
enum ScissorMode {
|
||||
ScissorMode_None = 0, ///< No Scissor
|
||||
ScissorMode_Inverted = 1, ///< Render Pixels outside the box
|
||||
ScissorMode_Normal = 3, ///< Only render pixels inside the box
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,181 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/** Font Loader for Lithium */
|
||||
class Font : public SmartCtor<Font> {
|
||||
public:
|
||||
/** Codepoint Data holder */
|
||||
class Codepoint {
|
||||
public:
|
||||
Codepoint() = default;
|
||||
~Codepoint() = default;
|
||||
|
||||
/**
|
||||
* Codepoint ID Getter
|
||||
* @return 32Bit codepoint value
|
||||
*/
|
||||
u32 cp() const { return m_cp; }
|
||||
/**
|
||||
* Codepoint ID Setter
|
||||
* @param v codepoint id
|
||||
* @return DataHolder reference
|
||||
*/
|
||||
Codepoint& cp(u32 v) {
|
||||
m_cp = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the UV Coords
|
||||
* @return uv coords
|
||||
*/
|
||||
vec4 uv() const { return m_uv; }
|
||||
/**
|
||||
* Setter for the UV Coords
|
||||
* @param v uv coords
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& uv(const vec4& v) {
|
||||
m_uv = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Texture reference
|
||||
* @return Texture Reference
|
||||
*/
|
||||
Texture::Ref tex() const { return m_tex; }
|
||||
/**
|
||||
* Setter for the Texture Reference
|
||||
* @param v Texture Reference
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& tex(Texture::Ref v) {
|
||||
m_tex = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the size
|
||||
* @return Size
|
||||
*/
|
||||
vec2 size() const { return m_size; }
|
||||
/**
|
||||
* Setter for the Size
|
||||
* @param v size
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& size(const vec2& v) {
|
||||
m_size = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter for the Position offset
|
||||
* @return offset
|
||||
*/
|
||||
float off() const { return m_off; }
|
||||
/**
|
||||
* Setter for the Render Offset
|
||||
* @param v offset
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& off(float v) {
|
||||
m_off = v;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* Getter to check if Codepoint is invalid
|
||||
* @return true if invalid
|
||||
*/
|
||||
bool invalid() const { return m_invalid; }
|
||||
/**
|
||||
* Setter for invald state
|
||||
* @param v true or false
|
||||
* @return DataHolder Reference
|
||||
*/
|
||||
Codepoint& invalid(bool v) {
|
||||
m_invalid = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
/** 32Bit Codepoint ID */
|
||||
u32 m_cp = 0;
|
||||
/** UvMap */
|
||||
vec4 m_uv;
|
||||
/** Texture Reference */
|
||||
Texture::Ref m_tex = nullptr;
|
||||
/** Codepoint Size */
|
||||
vec2 m_size;
|
||||
/** Render Position Offset */
|
||||
float m_off = 0;
|
||||
/** Invalid check (for skip in renderer) */
|
||||
bool m_invalid = false;
|
||||
};
|
||||
Font() = default;
|
||||
~Font() = default;
|
||||
/**
|
||||
* Load a TTF File
|
||||
* @param path Path to the TTF file
|
||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
||||
*/
|
||||
void LoadTTF(const std::string& path, int px_height = 32);
|
||||
/**
|
||||
* Load 3DS System Font
|
||||
*/
|
||||
void LoadSystemFont();
|
||||
/**
|
||||
* Getter for PixelHeight
|
||||
* @return pixelheigt
|
||||
*/
|
||||
int PixelHeight() const { return pixel_height; }
|
||||
/**
|
||||
* Getter for Codepoint reference
|
||||
* @return codepoint dataholder reference
|
||||
*/
|
||||
Codepoint& GetCodepoint(u32 c);
|
||||
/**
|
||||
* Check if Systemfont is used
|
||||
* @return true if is system font
|
||||
*/
|
||||
bool SystemFont() const { return sysfont; }
|
||||
|
||||
private:
|
||||
/** sysfont set to true if LoadSystemFont got called */
|
||||
bool sysfont;
|
||||
/** Pixelheight */
|
||||
int pixel_height;
|
||||
/** List of textures (codepoints are using) */
|
||||
std::vector<Texture::Ref> textures;
|
||||
/** 32Bit Codepoint Dataholder Reference Map */
|
||||
std::map<u32, Codepoint> cpmap;
|
||||
};
|
||||
} // namespace LI
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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>
|
||||
#include <pd/lithium/backend.hpp>
|
||||
#include <pd/lithium/pd_p_api.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LITextFlags = PD::u32;
|
||||
enum LITextFlags_ {
|
||||
LITextFlags_None = 0, ///< Do nothing
|
||||
LITextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||
LITextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||
LITextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||
LITextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
|
||||
LITextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
|
||||
LITextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/** Font Loader for Lithium */
|
||||
class PD_LITHIUM_API Font : public SmartCtor<Font> {
|
||||
public:
|
||||
/** Codepoint Data holder */
|
||||
struct Codepoint {
|
||||
u32 pCodepoint = 0;
|
||||
fvec4 SimpleUV;
|
||||
Texture::Ref Tex;
|
||||
fvec2 Size;
|
||||
float Offset = 0.f;
|
||||
bool pInvalid = false;
|
||||
};
|
||||
Font(Backend::Ref backend) { pBackend = backend; };
|
||||
~Font() = default;
|
||||
/**
|
||||
* Load a TTF File
|
||||
* @param path Path to the TTF file
|
||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
||||
*/
|
||||
void LoadTTF(const std::string& path, int px_height = 32);
|
||||
/**
|
||||
* Getter for Codepoint reference
|
||||
* @return codepoint dataholder reference
|
||||
*/
|
||||
Codepoint& GetCodepoint(u32 c);
|
||||
|
||||
/**
|
||||
* Get Text Bounding Box
|
||||
*/
|
||||
fvec2 GetTextBounds(const std::string& text, float scale);
|
||||
/**
|
||||
* Extended Draw Text Function that vreates a Command List
|
||||
*/
|
||||
void CmdTextEx(Vec<Command::Ref>& cmds, const fvec2& pos, u32 color,
|
||||
float scale, const std::string& text, LITextFlags flags = 0,
|
||||
const fvec2& box = 0);
|
||||
|
||||
/** Pixelheight */
|
||||
int PixelHeight;
|
||||
int DefaultPixelHeight = 24;
|
||||
|
||||
private:
|
||||
/** List of textures (codepoints are using) */
|
||||
std::vector<Texture::Ref> Textures;
|
||||
/** 32Bit Codepoint Dataholder Reference Map */
|
||||
std::map<u32, Codepoint> CodeMap;
|
||||
Backend::Ref pBackend = nullptr;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,349 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class Renderer;
|
||||
/**
|
||||
* Prerendered Object that can be edidet at runtime
|
||||
* and supports diffrent textures as well
|
||||
*/
|
||||
class StaticObject : public SmartCtor<StaticObject> {
|
||||
public:
|
||||
StaticObject() = default;
|
||||
~StaticObject() = default;
|
||||
|
||||
/**
|
||||
* Push a Draw Command to the Static Object
|
||||
* @param v Command to add
|
||||
*/
|
||||
void PushCommand(Command::Ref v) { cmds.push_back(v); }
|
||||
|
||||
/**
|
||||
* Copy the root Object to a copy buffer for modification
|
||||
*/
|
||||
void ReCopy() {
|
||||
cpy.clear();
|
||||
for (auto it : cmds) {
|
||||
cpy.push_back(Command::New(it));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the Color of a specific Command in the List
|
||||
* @param idx Index of the Command
|
||||
* @param col new COlor to replace with
|
||||
*/
|
||||
void ReColorQuad(int idx, u32 col) {
|
||||
if (idx > (int)cpy.size()) {
|
||||
return;
|
||||
}
|
||||
for (auto& it : cpy[idx]->VertexList()) {
|
||||
it.Color(col);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the every Command in the Object by a specific offset
|
||||
* @param off offset position to apply
|
||||
*/
|
||||
void MoveIt(vec2 off) {
|
||||
for (auto& it : cpy) {
|
||||
for (auto& jt : it->VertexList()) {
|
||||
jt.pos += off;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Color of all Commands in the List
|
||||
* @param col new Color to use
|
||||
*/
|
||||
void ReColor(u32 col) {
|
||||
for (auto& it : cpy) {
|
||||
for (auto& jt : it->VertexList()) {
|
||||
jt.Color(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a New Layer to all Objects
|
||||
* @param layer new layer to set to all its commands
|
||||
*/
|
||||
void ReLayer(int layer) {
|
||||
for (auto& it : cpy) {
|
||||
it->Layer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the Commands Index by setting a start index
|
||||
* @param start Start index position
|
||||
*/
|
||||
void ReIndex(int start) {
|
||||
for (int i = 0; i < (int)cpy.size(); i++) {
|
||||
cpy[i]->Index(start + i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a Custom Scissor Mode for Object Copy List
|
||||
* @param m New Mode to Set
|
||||
*/
|
||||
void ReSetScissorMode(ScissorMode m) {
|
||||
for (auto& i : cpy) {
|
||||
i->SetScissorMode(m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Custom Scissor Rect to All Objects
|
||||
* @param v Scissor Rect to set
|
||||
*/
|
||||
void ReScissorRect(const vec4& v) {
|
||||
for (auto& i : cpy) {
|
||||
i->ScissorRect(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Reference to the Copy Commands List
|
||||
* @return command list reference
|
||||
*/
|
||||
std::vector<Command::Ref>& List() {
|
||||
if (cpy.size() != 0) {
|
||||
return cpy;
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
||||
private:
|
||||
/** Copy Buffer */
|
||||
std::vector<Command::Ref> cpy;
|
||||
/** Source Buffer */
|
||||
std::vector<Command::Ref> cmds;
|
||||
};
|
||||
/**
|
||||
* Text Box container for TMS and AST
|
||||
*/
|
||||
class TextBox {
|
||||
public:
|
||||
TextBox() = default;
|
||||
/**
|
||||
* Baisc Constructor
|
||||
* @param s Size of the text
|
||||
* @param time creation time
|
||||
*/
|
||||
TextBox(const vec2& s, float time) {
|
||||
size = s;
|
||||
time_created = time;
|
||||
optional = false;
|
||||
}
|
||||
~TextBox() = default;
|
||||
|
||||
/**
|
||||
* Setter for Time created
|
||||
* @param v time
|
||||
*/
|
||||
void TimeCreated(float v) { time_created = v; }
|
||||
/**
|
||||
* Setter for Size
|
||||
* @param v size
|
||||
*/
|
||||
void Size(const vec2& v) { size = v; }
|
||||
/**
|
||||
* Setter for is optional
|
||||
*
|
||||
* - optional text contains the result string of wrap/short
|
||||
* @param v optional
|
||||
*/
|
||||
void Optional(bool v) { optional = v; }
|
||||
/**
|
||||
* set Result of Short Text or Wrap Text
|
||||
* @param v text
|
||||
*/
|
||||
void Text(const std::string& v) { text = v; }
|
||||
|
||||
/**
|
||||
* Get Size
|
||||
* @return size
|
||||
*/
|
||||
vec2 Size() const { return size; }
|
||||
/**
|
||||
* Get Time Created / Updated
|
||||
* @param time created/updated
|
||||
*/
|
||||
float TimeCreated() const { return time_created; }
|
||||
/**
|
||||
* Check if Optional or not
|
||||
* @return is optional
|
||||
*/
|
||||
bool Optional() const { return optional; }
|
||||
/**
|
||||
* Get Optional Text
|
||||
* @return text
|
||||
*/
|
||||
std::string Text() const { return text; }
|
||||
|
||||
private:
|
||||
/** Text Size */
|
||||
vec2 size;
|
||||
/** Time Created / Updated */
|
||||
float time_created;
|
||||
/** Is Optional */
|
||||
bool optional;
|
||||
/** Text Wrap / Short */
|
||||
std::string text;
|
||||
};
|
||||
/**
|
||||
* Static Text [abillity to Prerender Texts into a list of Commands]
|
||||
*/
|
||||
class StaticText : public SmartCtor<StaticText> {
|
||||
public:
|
||||
StaticText() = default;
|
||||
/**
|
||||
* Wrap Constructor to Setup
|
||||
* @param ren Renderer direct pointer reference
|
||||
* @param pos Position
|
||||
* @param clr Color
|
||||
* @param text Text to Render
|
||||
* @param flags Text Flags
|
||||
* @param box Additional textbox for specific flags
|
||||
*/
|
||||
StaticText(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
|
||||
LITextFlags flags = 0, const vec2& box = 0) {
|
||||
Setup(ren, pos, clr, text, flags, box);
|
||||
}
|
||||
~StaticText() = default;
|
||||
/**
|
||||
* Function that Sets Up the Rendering
|
||||
* @param ren Renderer direct pointer reference
|
||||
* @param pos Position
|
||||
* @param clr Color
|
||||
* @param text Text to Render
|
||||
* @param flags Text Flags
|
||||
* @param box Additional textbox for specific flags
|
||||
*/
|
||||
void Setup(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
|
||||
LITextFlags flags = 0, const vec2& box = 0);
|
||||
|
||||
/**
|
||||
* Get Text Size
|
||||
* @return size
|
||||
*/
|
||||
vec2 GetDim() const { return tdim; }
|
||||
/**
|
||||
* Get Text Posiotion
|
||||
* @return position
|
||||
*/
|
||||
vec2 GetPos() const { return pos; }
|
||||
/**
|
||||
* Setter to Update Color
|
||||
* @param col color
|
||||
*/
|
||||
void SetColor(u32 col);
|
||||
/**
|
||||
* Setter to raplace the texts Commands Position
|
||||
* @param pos new position
|
||||
*/
|
||||
void SetPos(const vec2& pos);
|
||||
/**
|
||||
* Set Layer of the Text
|
||||
* @param l layer
|
||||
*/
|
||||
void SetLayer(int l);
|
||||
|
||||
/**
|
||||
* Function to unset the used variable
|
||||
*/
|
||||
void SetUnused() { used = false; }
|
||||
/**
|
||||
* Function to check if the text got rendered
|
||||
* @return is used
|
||||
*/
|
||||
bool Used() const { return used; }
|
||||
/**
|
||||
* Function to check if the text got setup
|
||||
* @return is setup
|
||||
*/
|
||||
bool IsSetup() { return text != nullptr; }
|
||||
|
||||
/**
|
||||
* Draw the Text
|
||||
*/
|
||||
void Draw();
|
||||
|
||||
/** Get the Raw Object for Custom API's */
|
||||
StaticObject::Ref GetRawObject() { return text; }
|
||||
|
||||
/**
|
||||
* Set Font used by the static Text
|
||||
* @param fnt Font used
|
||||
*/
|
||||
void Font(Font::Ref fnt) { font = fnt; }
|
||||
/**
|
||||
* Get Font used by the Text
|
||||
* @return Font Reference
|
||||
*/
|
||||
Font::Ref Font() { return font; }
|
||||
|
||||
/**
|
||||
* Set a Custom Scissor Mode Static Text
|
||||
* @param m New Mode to Set
|
||||
*/
|
||||
void SetScissorMode(ScissorMode m) { text->ReSetScissorMode(m); }
|
||||
|
||||
/**
|
||||
* Set Custom Scissor Rect to Static Text
|
||||
* @param v Scissor Rect to set
|
||||
*/
|
||||
void ScissorRect(const vec4& v) { text->ReScissorRect(v); }
|
||||
|
||||
private:
|
||||
/** Font */
|
||||
Font::Ref font;
|
||||
/** Text got Rendered */
|
||||
bool used;
|
||||
/** Renderer pointer Reference */
|
||||
Renderer* ren;
|
||||
/** Text Size */
|
||||
vec2 tdim;
|
||||
/** Text Position */
|
||||
vec2 pos;
|
||||
/** Static Text Object */
|
||||
StaticObject::Ref text;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,31 +1,52 @@
|
||||
// THIS FILE WAS GENERATED BY build_shaders.py!!!
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 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 <cstddef>
|
||||
|
||||
extern unsigned char li7_shader[];
|
||||
extern size_t li7_shader_size;
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||
#ifdef PD_LITHIUM_BUILD_SHARED
|
||||
#define PD_LITHIUM_API __declspec(dllexport)
|
||||
#else
|
||||
#define PD_LITHIUM_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(__APPLE__) // macOS (untested yet)
|
||||
#ifdef PD_LITHIUM_BUILD_SHARED
|
||||
#define PD_LITHIUM_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_LITHIUM_API
|
||||
#endif
|
||||
#elif defined(__linux__) // Linux (untested yet)
|
||||
#ifdef PD_LITHIUM_BUILD_SHARED
|
||||
#define PD_LITHIUM_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_LITHIUM_API
|
||||
#endif
|
||||
#elif defined(__3DS__) // 3ds Specific
|
||||
// Only Static supported
|
||||
#define PD_LITHIUM_API
|
||||
#else
|
||||
#define PD_LITHIUM_API
|
||||
#endif
|
@ -1,197 +1,192 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/**
|
||||
* Container that holds position of a rectangle's corners.
|
||||
*/
|
||||
class Rect {
|
||||
public:
|
||||
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 vec4& t, const vec4& 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 vec2& tl, const vec2& tr, const vec2& bl, const vec2& br) {
|
||||
top = vec4(tl, tr);
|
||||
bot = vec4(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 vec4& uv) {
|
||||
top = vec4(uv.x(), uv.y(), uv.z(), uv.y());
|
||||
bot = vec4(uv.x(), uv.w(), uv.z(), uv.w());
|
||||
}
|
||||
|
||||
~Rect() = default;
|
||||
|
||||
/**
|
||||
* Get the top left and right corner positions.
|
||||
* @return Top positions.
|
||||
*/
|
||||
vec4 Top() const { return top; }
|
||||
|
||||
/**
|
||||
* Get the bottom left and right corner positions.
|
||||
* @return Bottom positions.
|
||||
*/
|
||||
vec4 Bot() const { return bot; }
|
||||
|
||||
/**
|
||||
* Set the top left and right corner positions.
|
||||
* @param v New top positions.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& Top(const vec4& v) {
|
||||
top = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bottom left and right corner positions.
|
||||
* @param v New bottom positions.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& Bot(const vec4& v) {
|
||||
bot = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the top-left corner position.
|
||||
* @return Top-left position as vec2.
|
||||
*/
|
||||
vec2 TopLeft() const { return vec2(top[0], top[1]); }
|
||||
|
||||
/**
|
||||
* Get the top-right corner position.
|
||||
* @return Top-right position as vec2.
|
||||
*/
|
||||
vec2 TopRight() const { return vec2(top[2], top[3]); }
|
||||
|
||||
/**
|
||||
* Get the bottom-left corner position.
|
||||
* @return Bottom-left position as vec2.
|
||||
*/
|
||||
vec2 BotLeft() const { return vec2(bot[0], bot[1]); }
|
||||
|
||||
/**
|
||||
* Get the bottom-right corner position.
|
||||
* @return Bottom-right position as vec2.
|
||||
*/
|
||||
vec2 BotRight() const { return vec2(bot[2], bot[3]); }
|
||||
|
||||
/**
|
||||
* Set the top-left corner position.
|
||||
* @param v New top-left position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& TopLeft(const vec2& v) {
|
||||
top[0] = v[0];
|
||||
top[1] = v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the top-right corner position.
|
||||
* @param v New top-right position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& TopRight(const vec2& v) {
|
||||
top[2] = v[0];
|
||||
top[3] = v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bottom-left corner position.
|
||||
* @param v New bottom-left position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& BotLeft(const vec2& v) {
|
||||
bot[0] = v[0];
|
||||
bot[1] = v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bottom-right corner position.
|
||||
* @param v New bottom-right position.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& BotRight(const vec2& v) {
|
||||
bot[2] = v[0];
|
||||
bot[3] = v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap X and Y coordinates for all corners.
|
||||
*
|
||||
* - Used in SpiteSheet for the rotated images.
|
||||
*/
|
||||
void SwapVec2XY() {
|
||||
for (int i = 0; i < 4; i += 2) {
|
||||
float t = top[i];
|
||||
top[i] = top[i + 1];
|
||||
top[i + 1] = t;
|
||||
t = bot[i];
|
||||
bot[i] = bot[i + 1];
|
||||
bot[i + 1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
vec4 top; ///< Top left and right corner positions.
|
||||
vec4 bot; ///< Bottom left and right corner positions.
|
||||
};
|
||||
} // namespace LI
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 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 {
|
||||
/**
|
||||
* Container that holds position of a rectangle's corners.
|
||||
*/
|
||||
class Rect {
|
||||
public:
|
||||
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);
|
||||
}
|
||||
|
||||
~Rect() = default;
|
||||
|
||||
/**
|
||||
* Get the top left and right corner positions.
|
||||
* @return Top positions.
|
||||
*/
|
||||
fvec4 Top() const { return top; }
|
||||
|
||||
/**
|
||||
* Get the bottom left and right corner positions.
|
||||
* @return Bottom positions.
|
||||
*/
|
||||
fvec4 Bot() const { return bot; }
|
||||
|
||||
/**
|
||||
* Set the top left and right corner positions.
|
||||
* @param v New top positions.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& Top(const fvec4& v) {
|
||||
top = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bottom left and right corner positions.
|
||||
* @param v New bottom positions.
|
||||
* @return Reference to the updated Rect.
|
||||
*/
|
||||
Rect& Bot(const fvec4& v) {
|
||||
bot = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the top-left corner position.
|
||||
* @return Top-left position as vec2.
|
||||
*/
|
||||
fvec2 TopLeft() const { return vec2(top.x, top.y); }
|
||||
|
||||
/**
|
||||
* Get the top-right corner position.
|
||||
* @return Top-right position as vec2.
|
||||
*/
|
||||
fvec2 TopRight() const { return vec2(top.z, top.w); }
|
||||
|
||||
/**
|
||||
* Get the bottom-left corner position.
|
||||
* @return Bottom-left position as vec2.
|
||||
*/
|
||||
fvec2 BotLeft() const { return vec2(bot.x, bot.y); }
|
||||
|
||||
/**
|
||||
* Get the bottom-right corner position.
|
||||
* @return Bottom-right position as vec2.
|
||||
*/
|
||||
fvec2 BotRight() const { return vec2(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap X and Y coordinates for all corners.
|
||||
*
|
||||
* - Used in SpiteSheet for the rotated images.
|
||||
*/
|
||||
void SwapVec2XY() {
|
||||
top.SwapXY();
|
||||
top.SwapZW();
|
||||
bot.SwapXY();
|
||||
bot.SwapZW();
|
||||
}
|
||||
|
||||
private:
|
||||
fvec4 top; ///< Top left and right corner positions.
|
||||
fvec4 bot; ///< Bottom left and right corner positions.
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,382 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/lib3ds/memory.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/flags.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/objects.hpp>
|
||||
#include <pd/lithium/screen.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/**
|
||||
* Lithium base renderer Class.
|
||||
*/
|
||||
class Renderer : public SmartCtor<Renderer> {
|
||||
public:
|
||||
/**
|
||||
* Constructor setting up the 2d Rendering Engine
|
||||
* @param flags Flags to use [can be changed at runtime].
|
||||
*/
|
||||
Renderer(LIRenderFlags flags = LIRenderFlags_Default);
|
||||
/**
|
||||
* Deconstructor that unloads all the renderer data
|
||||
*/
|
||||
~Renderer();
|
||||
|
||||
/**
|
||||
* Prepare render stage for rendering.
|
||||
*/
|
||||
void PrepareRender();
|
||||
/**
|
||||
* Render a screens Command list.
|
||||
* @param s Screen to Draw its list on.
|
||||
*/
|
||||
void Render(Screen::Ref s);
|
||||
/**
|
||||
* Finalize rendering stage.
|
||||
*/
|
||||
void FinalizeRender();
|
||||
|
||||
/**
|
||||
* Register Screens (For UI7, probably move this).
|
||||
* @param bottom set if you register bottom ot top screen.
|
||||
* @param s Screen to register.
|
||||
*/
|
||||
void RegisterScreen(bool bottom, Screen::Ref s) { screens[bottom] = s; }
|
||||
/**
|
||||
* Set the Screen next commands will be add to
|
||||
* @param s Screen of choice
|
||||
*/
|
||||
void OnScreen(Screen::Ref s) {
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
this->screen = s;
|
||||
area_size = screen->GetSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cobst reference to active screen.
|
||||
* @return current screen.
|
||||
*/
|
||||
Screen::Ref CurrentScreen() const { return screen; }
|
||||
/**
|
||||
* Get Screen of screen regestry.
|
||||
* @param bottom bottom ot top screen.
|
||||
* @return screen reference
|
||||
*/
|
||||
Screen::Ref GetScreen(bool bottom) {
|
||||
auto res = screens[bottom];
|
||||
Assert(res.get(), "Screen is not registered!");
|
||||
return res;
|
||||
}
|
||||
|
||||
void Rotation(float v) { rot = v; }
|
||||
float Rotation() const { return rot; }
|
||||
void TextScale(float v) { text_size = v; }
|
||||
void DefaultTextScale() { text_size = default_text_size; }
|
||||
float TextScale() const { return text_size; }
|
||||
void Layer(int v) { current_layer = v; }
|
||||
int Layer() const { return current_layer; }
|
||||
LIRenderFlags& GetFlags() { return flags; }
|
||||
void Font(Font::Ref v) {
|
||||
font = v;
|
||||
font_update = true;
|
||||
}
|
||||
Font::Ref Font() const { return font; }
|
||||
|
||||
/**
|
||||
* Use a specific Texture for Next Rectangle.
|
||||
* @param v texture reference to use.
|
||||
*/
|
||||
void UseTex(Texture::Ref v = nullptr) {
|
||||
if (v == nullptr) {
|
||||
current_tex = white;
|
||||
return;
|
||||
}
|
||||
current_tex = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a Rect based on current Texture
|
||||
* @param pos Position of the Rect
|
||||
* @param size Size of the Rect
|
||||
* @param color Color of the Rect [0xffffffff]
|
||||
* for full visible texture
|
||||
* @param uv UV Map (if texture needs a custom uv)
|
||||
* @note This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawRect(const vec2& pos, const vec2& size, u32 color,
|
||||
const Rect& uv = vec4(0.f, 1.f, 1.f, 0.f));
|
||||
/**
|
||||
* Draw a Solid Rect (uses white tex)
|
||||
* @note
|
||||
* - acts as a simplified Draw rect Wrapper
|
||||
* - This function is part of Simple Draw API.
|
||||
* @param pos Position of the rect
|
||||
* @param size Size of the rect
|
||||
* @param color Color of the rect
|
||||
*/
|
||||
void DrawRectSolid(const vec2& pos, const vec2& size, u32 color);
|
||||
/**
|
||||
* Render a Triangle
|
||||
* @param a Position A
|
||||
* @param b Position B
|
||||
* @param c Position C
|
||||
* @param color Color of the triangle
|
||||
* @note
|
||||
* - Uses Solid color [white tex]
|
||||
* - This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawTriangle(const vec2& a, const vec2& b, const vec2& c, u32 color);
|
||||
/**
|
||||
* Draw a Circle (Supports Textures)
|
||||
* @param center_pos Center Position
|
||||
* @param r Radius of the circle
|
||||
* @param color Color of the circle
|
||||
* @param segments Segments to use
|
||||
* @note
|
||||
* - Textures could look a bit janky due to uv mapping
|
||||
* - This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawCircle(const vec2& center_pos, float r, u32 color, int segments);
|
||||
/**
|
||||
* Draw a Line between to Positions
|
||||
* @param a Position A
|
||||
* @param b Position B
|
||||
* @param color Color of the line
|
||||
* @param t Thickness
|
||||
* @note This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawLine(const vec2& a, const vec2& b, u32 color, int t);
|
||||
/**
|
||||
* Render a Text
|
||||
* @param pos Position of the text
|
||||
* @param color Color of the Text
|
||||
* @param text Text to Render
|
||||
* @param flags flags to use
|
||||
* @param ap optional size for specific flags
|
||||
* @note This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawText(const vec2& pos, u32 color, const std::string& text,
|
||||
u32 flags = 0, const vec2& ap = vec2());
|
||||
/**
|
||||
* Draw a Texture as 2D Image
|
||||
* @param pos Position
|
||||
* @param tex Texture reference
|
||||
* @param scale Scale (cause maybe wants to be resized)
|
||||
* @note
|
||||
* - Acts as a Simplified wrapper to DrawRect
|
||||
* - This function is part of Simple Draw API.
|
||||
*/
|
||||
void DrawImage(const vec2& pos, Texture::Ref tex,
|
||||
const vec2& scale = vec2(1.f));
|
||||
|
||||
// Debug STUFF
|
||||
|
||||
/** DEBUG Get the Number of Vertices of last Frame */
|
||||
u32 Vertices() const { return vertices; }
|
||||
/** DEBUG Get the Number of Indices of last frame */
|
||||
u32 Indices() const { return indices; }
|
||||
/** DEBUG Get the Number of Commands of last frame */
|
||||
u32 Commands() const { return commands; }
|
||||
/** DEBUG Get the Number of Drawcalls of last frame */
|
||||
u32 DrawCalls() const { return drawcalls; }
|
||||
/** Auto Static Text Number of Texts */
|
||||
u32 AstUsage() const { return ast.size(); }
|
||||
/** Text Map System number of texts */
|
||||
u32 TmsUsage() const { return tms.size(); }
|
||||
|
||||
// TOOLS
|
||||
|
||||
/** Rotate a rect corner position by sine and cosine value */
|
||||
static void RotateCorner(vec2& v, float s, float c);
|
||||
/** Create a Rect by Position, Size and rotation angle */
|
||||
static Rect CreateRect(const vec2& pos, const vec2& size, float angle);
|
||||
/** Create a Line Rect by 2 Position and a thickness value */
|
||||
static Rect CreateLine(const vec2& a, const vec2& b, int t);
|
||||
/** Check if a pos and size are inside a vec4 rect */
|
||||
static bool InBox(const vec2& pos, const vec2& size, const vec4& rect);
|
||||
/** Check if a pos is inside a vec4 rect */
|
||||
static bool InBox(const vec2& pos, const vec4& rect);
|
||||
/** Check if one or all of three positions are somehow inside a vec4 rect */
|
||||
static bool InBox(const vec2& alpha, const vec2& bravo, const vec2& charlie,
|
||||
const vec4& rect);
|
||||
/**
|
||||
* Get The Address of a Screen
|
||||
* @note **IMPORTANT** THIS IS FOR 32Bit System
|
||||
*
|
||||
* Should find a better way to do this for porting this lib
|
||||
*/
|
||||
static u32 Screen32(Screen::Ref s) { return (u32)s.get(); }
|
||||
/** Function to optimize command order for rendering */
|
||||
static void OptiCommandList(std::vector<Command::Ref>& list);
|
||||
/** Returns Viewport with xy */
|
||||
vec4 GetViewport();
|
||||
/** Push a Self Created command */
|
||||
void PushCommand(Command::Ref cmd) {
|
||||
cmd->Index(cmd_idx++); // Indexing
|
||||
draw_list[Screen32(screen)].push_back(cmd);
|
||||
}
|
||||
/** Automatically sets up a command */
|
||||
void SetupCommand(Command::Ref cmd);
|
||||
/** Creates a default Quad Render Command */
|
||||
void QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, u32 col);
|
||||
/** Create a Default Triangle */
|
||||
void TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b,
|
||||
const vec2& c, u32 col);
|
||||
/**
|
||||
* Create List of a Text Commands
|
||||
* @param cmds Link to a command List
|
||||
* @param pos Position
|
||||
* @param color Color
|
||||
* @param text Text
|
||||
* @param flags Flags
|
||||
* @param box (Size for wrapping / Offset for Centered Text)
|
||||
*/
|
||||
void TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos, u32 color,
|
||||
const std::string& text, LITextFlags flags, const vec2& box);
|
||||
vec2 GetTextDimensions(const std::string& text);
|
||||
/**
|
||||
* Function to short a text and replace the rest by ...
|
||||
* @param text Text to short
|
||||
* @param maxlen Maximum width
|
||||
* @param newsize New Textbox size
|
||||
* @return shorted text
|
||||
*/
|
||||
std::string ShortText(const std::string& text, int maxlen, vec2& newsize);
|
||||
/**
|
||||
* Function to Wrap Text by specific width
|
||||
*
|
||||
* **NOT IMPLEMENTED YET**
|
||||
* @param text text to wrap
|
||||
* @param maxlen maximum width per line
|
||||
* @param newsize new textbox size
|
||||
* @return wrapped text
|
||||
*/
|
||||
std::string WrapText(const std::string& text, int maxlen, vec2& newsize);
|
||||
|
||||
private:
|
||||
// Helper Funcitons
|
||||
|
||||
/**
|
||||
* Update the 3DS citro3d texenv for specific RenderMode
|
||||
* @param mode RenderMode to use.
|
||||
*/
|
||||
void UpdateRenderMode(const RenderMode& mode);
|
||||
|
||||
/** Current Screen */
|
||||
Screen::Ref screen;
|
||||
/** Screen Regestry */
|
||||
Screen::Ref screens[2];
|
||||
|
||||
// Context Related
|
||||
|
||||
/** Renderer flags */
|
||||
LIRenderFlags flags = LIRenderFlags_Default;
|
||||
/** Area Size */
|
||||
vec2 area_size;
|
||||
/** Current Layer */
|
||||
int current_layer = 0;
|
||||
/** Current Texture */
|
||||
Texture::Ref current_tex = nullptr;
|
||||
/** Single Color Texture (for solid color objs) */
|
||||
Texture::Ref white = nullptr;
|
||||
/** Current Font Reference */
|
||||
Font::Ref font = nullptr;
|
||||
/** Font updated */
|
||||
bool font_update;
|
||||
/** Current Rendermode */
|
||||
RenderMode mode = RenderMode_RGBA;
|
||||
/** Text Map System */
|
||||
std::map<std::string, TextBox> tms;
|
||||
/** (Auto) Static Text */
|
||||
std::unordered_map<u32, StaticText::Ref> ast;
|
||||
|
||||
// Text Rendering
|
||||
|
||||
/** Default FOnt height */
|
||||
const float default_font_h = 24.f;
|
||||
/** Default Text Scale */
|
||||
const float default_text_size = 0.7f;
|
||||
/** Current Text Scale */
|
||||
float text_size = 0.7f;
|
||||
// Special
|
||||
|
||||
/** Current Rotation (RECTS) */
|
||||
float rot = 0.f;
|
||||
// Rendering
|
||||
|
||||
/** Map of drawlist by 32Bit memory Address of their Screen */
|
||||
std::unordered_map<u32, std::vector<Command::Ref>> draw_list;
|
||||
/** Vertex Buffer in linear Ram */
|
||||
std::vector<Vertex, LinearAllocator<Vertex>> vertex_buf;
|
||||
/** 16Bit index buffer in linear Ram */
|
||||
std::vector<u16, LinearAllocator<u16>> index_buf;
|
||||
/** vertex index (render stage) */
|
||||
u32 vertex_idx = 0;
|
||||
/** index buf index (render stage) */
|
||||
u32 index_idx = 0;
|
||||
/** command index (used for debug count) */
|
||||
u32 cmd_idx = 0;
|
||||
|
||||
// Debug
|
||||
|
||||
/** Num of Vertices */
|
||||
u32 vertices = 0;
|
||||
/** Num of indices */
|
||||
u32 indices = 0;
|
||||
/** Num of Commands */
|
||||
u32 commands = 0;
|
||||
/** Num of Drawcalls */
|
||||
u32 drawcalls = 0;
|
||||
|
||||
// Shader
|
||||
|
||||
/** Shader code */
|
||||
DVLB_s* dvlb = nullptr;
|
||||
/** Shader program */
|
||||
shaderProgram_s shader;
|
||||
/** Shader Attribute info */
|
||||
C3D_AttrInfo attr;
|
||||
/** projection matrix location */
|
||||
int uLoc_projection = 0;
|
||||
|
||||
// Matrix
|
||||
|
||||
/** Precalculated Projectrion Matrix for top screen */
|
||||
C3D_Mtx top_proj;
|
||||
/** Precalculated Projectrion Matrix for bottom screen */
|
||||
C3D_Mtx bot_proj;
|
||||
};
|
||||
} // namespace LI
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/lithium/backend.hpp>
|
||||
#include <pd/lithium/drawlist.hpp>
|
||||
#include <pd/lithium/font.hpp>
|
||||
#include <pd/lithium/pd_p_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
|
||||
public:
|
||||
Renderer(Backend::Ref backend);
|
||||
~Renderer() = default;
|
||||
|
||||
void Render();
|
||||
|
||||
// SECTION: ADVANCED API
|
||||
|
||||
void AddCommand(Command::Ref v) { DrawList.Add(v); }
|
||||
void RegisterDrawList(DrawList::Ref list) { pDrawLists.Add(list); }
|
||||
Command::Ref PreGenerateCmd();
|
||||
|
||||
// SECTION: Open Command and Object creation API
|
||||
static void RotateCorner(fvec2& pos, float sinus, float cosinus);
|
||||
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
||||
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
|
||||
static void CmdQuad(Command::Ref cmd, const Rect& quad, const Rect& uv,
|
||||
u32 color);
|
||||
static void CmdTriangle(Command::Ref cmd, const fvec2 a, const fvec2 b,
|
||||
const fvec2 c, u32 clr);
|
||||
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
||||
int thickness = 1);
|
||||
static void CmdConvexPolyFilled(Command::Ref cmd, const Vec<fvec2>& points,
|
||||
u32 clr, Texture::Ref tex);
|
||||
|
||||
// SECTION: InBounds Checks
|
||||
|
||||
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
|
||||
static bool InBox(const fvec2& pos, const fvec4& area);
|
||||
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||
const fvec4& area);
|
||||
|
||||
// SECTION: Data //
|
||||
|
||||
Texture::Ref WhitePixel = nullptr;
|
||||
Backend::Ref pBackend = nullptr;
|
||||
Texture::Ref CurrentTex = nullptr;
|
||||
int Layer = 0;
|
||||
|
||||
private:
|
||||
PD::Vec<Command::Ref> DrawList;
|
||||
PD::Vec<DrawList::Ref> pDrawLists;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,98 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 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 <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* 3DS Screen (RenderTarget)
|
||||
*/
|
||||
class Screen : public SmartCtor<Screen> {
|
||||
public:
|
||||
/** Screens */
|
||||
enum Screen_ {
|
||||
Top, ///< Top Screen
|
||||
Bottom, ///< Bottom Screen
|
||||
TopRight ///< Top Right Screen area
|
||||
};
|
||||
/**
|
||||
* Constructor to create Screen by Screen Type
|
||||
* @param screen Screen to grab default init values for
|
||||
*/
|
||||
Screen(Screen_ screen) : type(screen) {
|
||||
if (screen == Top) {
|
||||
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
} else if (screen == Bottom) {
|
||||
target = C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_BOTTOM, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
} else if (screen == TopRight) {
|
||||
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_RIGHT,
|
||||
DisplayTransferFlags);
|
||||
}
|
||||
}
|
||||
~Screen() = default;
|
||||
|
||||
/** Clear the Screen */
|
||||
void Clear() { C3D_RenderTargetClear(target, C3D_CLEAR_ALL, 0x00000000, 0); }
|
||||
/** Set the Screen active for Rendering */
|
||||
void Use() { C3D_FrameDrawOn(target); }
|
||||
|
||||
/** Get the Screens Size */
|
||||
vec2 GetSize() const {
|
||||
return vec2(target->frameBuf.height, target->frameBuf.width);
|
||||
}
|
||||
|
||||
/** Get the Screen Type */
|
||||
Screen_ ScreenType() const { return type; }
|
||||
|
||||
/** Get the Raw Rendertarget object */
|
||||
C3D_RenderTarget* Get() const { return target; }
|
||||
/** Operartor to get the raw RenderTarget */
|
||||
operator C3D_RenderTarget*() const { return target; }
|
||||
|
||||
private:
|
||||
/** Screen Type */
|
||||
Screen_ type;
|
||||
/** Default Init Flags */
|
||||
const u32 DisplayTransferFlags =
|
||||
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
|
||||
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
|
||||
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
|
||||
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
|
||||
/** RenderTarget */
|
||||
C3D_RenderTarget* target;
|
||||
};
|
||||
} // namespace PD
|
@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 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 <citro3d.h>
|
||||
#include <tex3ds.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Tex 3DS Spritesheet integration to Lithium
|
||||
*/
|
||||
class SpriteSheet : public SmartCtor<SpriteSheet> {
|
||||
public:
|
||||
SpriteSheet() = default;
|
||||
/**
|
||||
* Constructor to directly load a spritesheet
|
||||
* @param path Path to spritesheet
|
||||
*/
|
||||
SpriteSheet(const std::string& path) { this->LoadFile(path); }
|
||||
/**
|
||||
* Deconstructor to unload the Spritesheet
|
||||
*/
|
||||
~SpriteSheet();
|
||||
|
||||
/**
|
||||
* Function to load a Spritesheet
|
||||
* @param path Path to the file
|
||||
*/
|
||||
void LoadFile(const std::string& path);
|
||||
/** Get a Textures Reference */
|
||||
Texture::Ref Get(int idx);
|
||||
/** Get Number of Textures in spritesheet */
|
||||
int NumTextures() const;
|
||||
|
||||
/** Operator to get Texture reference */
|
||||
Texture::Ref operator[](int idx) { return Get(idx); }
|
||||
|
||||
private:
|
||||
/** Storage of the Spritesheets textures */
|
||||
std::vector<Texture::Ref> textures;
|
||||
};
|
||||
} // namespace PD
|
@ -1,153 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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 <citro3d.h>
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
|
||||
namespace PD {
|
||||
/**
|
||||
* Lithium Texture Loader / DataHolder
|
||||
*/
|
||||
class Texture : public SmartCtor<Texture> {
|
||||
public:
|
||||
/** Texture Type */
|
||||
enum Type {
|
||||
RGBA32, ///< RGBA 32
|
||||
RGB24, ///< RGB24
|
||||
A8, ///< A8
|
||||
};
|
||||
/** Texture Filters */
|
||||
enum Filter {
|
||||
NEAREST, ///< Nearest
|
||||
LINEAR, ///< Linear
|
||||
};
|
||||
/** Default constructor */
|
||||
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
|
||||
/**
|
||||
* Load file Constructor
|
||||
* @param path path to file
|
||||
* @param t3x set true if file is a t3x file
|
||||
*/
|
||||
Texture(const std::string& path, bool t3x = false) : uv(0.f, 1.f, 1.f, 0.f) {
|
||||
if (t3x) {
|
||||
this->LoadT3X(path);
|
||||
} else {
|
||||
this->LoadFile(path);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Load Memory constructor
|
||||
* @param data File Data reference
|
||||
*/
|
||||
Texture(const std::vector<u8>& data) : uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadMemory(data);
|
||||
}
|
||||
/**
|
||||
* Load Pixels constructor
|
||||
* @param data Pixel Buffer reference
|
||||
* @param w width
|
||||
* @param h height
|
||||
* @param type Buffer Type [Default RGBA32]
|
||||
* @param filter Filter [DEFAULT NEAREST]
|
||||
*/
|
||||
Texture(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST)
|
||||
: uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadPixels(data, w, h, type, filter);
|
||||
}
|
||||
/** Deconstructor (aka auto delete) */
|
||||
~Texture() {
|
||||
if (autounload) {
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Deletes image (if not already unloaded)
|
||||
void Delete();
|
||||
|
||||
/// @brief Load a png/jpg/bmp from fs into a gpu tex
|
||||
/// @param path path to image file
|
||||
void LoadFile(const std::string& path);
|
||||
/// @brief Load a png/jpg/bmp from memory
|
||||
/// @param data reference to data buffer of the file
|
||||
void LoadMemory(const std::vector<u8>& data);
|
||||
/// @brief Create Texture out of Pixel Data
|
||||
/// @param data Data reference
|
||||
/// @param w width
|
||||
/// @param h heigt
|
||||
/// @param type Type of the databuffer
|
||||
/// @param filter Filter (NEAREST OR LINEAR)
|
||||
void LoadPixels(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST);
|
||||
|
||||
/// @brief Load a texture of a T3X File
|
||||
/// @note This is used for single texture T3X
|
||||
/// Not for SpriteSheets
|
||||
/// @param path path to .t3x file
|
||||
void LoadT3X(const std::string& path);
|
||||
|
||||
/// @brief Input a Texture that you had set up on your own
|
||||
/// @param tex Texture reference (deletes itself)
|
||||
/// @param rszs The size of the source image
|
||||
/// @param uvs Your uv Setup
|
||||
void LoadExternal(C3D_Tex* tex, vec2 rszs, LI::Rect uvs) {
|
||||
this->Delete();
|
||||
this->tex = tex;
|
||||
this->size = rszs;
|
||||
this->uv = uvs;
|
||||
}
|
||||
|
||||
vec2 GetRealSize() {
|
||||
if (!tex) {
|
||||
return vec2();
|
||||
}
|
||||
return vec2(tex->width, tex->height);
|
||||
}
|
||||
vec2 GetSize() const { return size; }
|
||||
C3D_Tex* GetTex() const { return tex; }
|
||||
LI::Rect GetUV() const { return uv; }
|
||||
bool IsValid() const { return tex != 0; }
|
||||
|
||||
bool AutoUnLoad() const { return autounload; }
|
||||
void AutoUnLoad(bool v) { autounload = v; }
|
||||
|
||||
operator C3D_Tex*() const { return tex; }
|
||||
operator vec2() const { return size; }
|
||||
operator LI::Rect() const { return uv; }
|
||||
operator bool() const { return tex != 0; }
|
||||
|
||||
private:
|
||||
void MakeTex(std::vector<u8>& buf, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST);
|
||||
vec2 size;
|
||||
LI::Rect uv;
|
||||
C3D_Tex* tex = nullptr;
|
||||
bool autounload = true;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
using TexAddress = uintptr_t;
|
||||
/**
|
||||
* Lithium Texture Data Holder
|
||||
* Memory management is handled by backend
|
||||
*/
|
||||
class Texture : public SmartCtor<Texture> {
|
||||
public:
|
||||
/** Texture Type */
|
||||
enum Type {
|
||||
RGBA32, ///< RGBA 32
|
||||
RGB24, ///< RGB24
|
||||
A8, ///< A8
|
||||
};
|
||||
/** Texture Filters */
|
||||
enum Filter {
|
||||
NEAREST, ///< Nearest
|
||||
LINEAR, ///< Linear
|
||||
};
|
||||
/** Default constructor */
|
||||
Texture() : UV(0.f, 0.f, 1.f, 1.f) {}
|
||||
Texture(TexAddress addr, ivec2 size,
|
||||
LI::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
|
||||
Address = addr;
|
||||
Size = size;
|
||||
UV = uv;
|
||||
}
|
||||
|
||||
void CopyOther(Texture::Ref tex) {
|
||||
Address = tex->Address;
|
||||
Size = tex->Size;
|
||||
UV = tex->UV;
|
||||
}
|
||||
|
||||
ivec2 GetSize() const { return Size; }
|
||||
LI::Rect GetUV() const { return UV; }
|
||||
|
||||
operator ivec2() const { return Size; }
|
||||
operator LI::Rect() const { return UV; }
|
||||
|
||||
TexAddress Address;
|
||||
ivec2 Size;
|
||||
LI::Rect UV;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
@ -1,62 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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/common.hpp>
|
||||
#include <pd/core/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class Vertex {
|
||||
public:
|
||||
Vertex() {}
|
||||
Vertex(const vec2& p, const vec2& u, u32 c) {
|
||||
pos[0] = p[0];
|
||||
pos[1] = p[1];
|
||||
uv = u;
|
||||
color = c;
|
||||
}
|
||||
~Vertex() {}
|
||||
|
||||
Vertex& Pos(const vec2& v) {
|
||||
pos = v;
|
||||
return *this;
|
||||
}
|
||||
Vertex& Uv(const vec2& v) {
|
||||
uv = v;
|
||||
return *this;
|
||||
}
|
||||
Vertex& Color(u32 v) {
|
||||
color = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// private:
|
||||
vec2 pos;
|
||||
vec2 uv;
|
||||
u32 color;
|
||||
};
|
||||
} // namespace LI
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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 Vertex {
|
||||
public:
|
||||
Vertex() {}
|
||||
Vertex(const fvec2& p, const fvec2& u, u32 c) {
|
||||
Pos.x = p.x;
|
||||
Pos.y = p.y;
|
||||
UV = u;
|
||||
Color = c;
|
||||
}
|
||||
~Vertex() {}
|
||||
|
||||
// private:
|
||||
fvec2 Pos;
|
||||
fvec2 UV;
|
||||
u32 Color;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
Reference in New Issue
Block a user