# Changes 0.2.4-1

- Add GIT_BRANCH (for development and stable)
- Write  Documentation of
  - pd-core (exept of vec.hpp)
  - pd-app
  - pd-drivers
  - pd-lib3ds
  - pd-image
  - pd-image
  - pd-ui7
This commit is contained in:
2025-03-02 21:11:58 +01:00
parent af3d3e0b5b
commit 7d3f619169
56 changed files with 2481 additions and 536 deletions

View File

@ -25,19 +25,25 @@ 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>
#include <pd/core/vec.hpp>
namespace PD {
namespace LI {
/// @brief Reform the Drawcommand by generating the Vertexbuffer into it
/**
* Lithium Draw Command (containing a list of vertex and index data
* only for this specific command itself)
*/
class Command : public SmartCtor<Command> {
public:
Command() {}
~Command() {}
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;
@ -47,58 +53,140 @@ class Command : public SmartCtor<Command> {
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
/**
* 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; }
private:
/// Using Default std::vector here
/**
* 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;
};
} // namespace LI

View File

@ -26,35 +26,40 @@ SOFTWARE.
#include <pd/core/common.hpp>
/** Alias for Lithium Text Flags */
using LITextFlags = PD::u32;
/** LITextFlags */
enum LITextFlags_ {
LITextFlags_None = 0,
LITextFlags_AlignRight = 1 << 0,
LITextFlags_AlignMid = 1 << 1,
LITextFlags_Shaddow = 1 << 2, // Draws the text twice
LITextFlags_Wrap = 1 << 3, // May be runs better with TMS
LITextFlags_Short = 1 << 4, // May be runs better with TMS
LITextFlags_Scroll = 1 << 5, // Not implemented
LITextFlags_RenderOOS = 1 << 6 // Render Out of Screen
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,
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 {
/// @brief Required to Set the TexENV
/** RenderMode [Required to modify TexENV] */
enum RenderMode {
RenderMode_RGBA,
RenderMode_Font,
RenderMode_RGBA, ///< RGBA [for textures or solid colors]
RenderMode_Font, ///< A8 [for textures only crated by 1 color channel]
};
} // namespace LI
} // namespace PD

View File

@ -25,70 +25,156 @@ SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/core/vec.hpp>
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class Font : public SmartCtor<Font> {
public:
/** Codepoint Data holder */
class Codepoint {
public:
Codepoint() {}
~Codepoint() {}
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() {}
~Font() {}
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

View File

@ -25,23 +25,34 @@ 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>
#include <pd/core/vec.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() {}
~StaticObject() {}
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) {
@ -49,6 +60,11 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* 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;
@ -58,6 +74,10 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* 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()) {
@ -66,6 +86,10 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* 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()) {
@ -74,18 +98,30 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* Add the Layer by a specific number
* @param base_layer baselayer or number to add on top of the commands layer
*/
void ReLayer(int base_layer) {
for (auto& it : cpy) {
it->Layer(it->Layer() + base_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);
}
}
/**
* Get a Reference to the Copy Commands List
* @return command list reference
*/
std::vector<Command::Ref>& List() {
if (cpy.size() != 0) {
return cpy;
@ -94,72 +130,184 @@ class StaticObject : public SmartCtor<StaticObject> {
}
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() {}
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() {}
~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;
std::string text; // TextWrap
/** Text Wrap / Short */
std::string text;
};
/**
* Static Text [abillity to Prerender Texts into a list of Commands]
*/
class StaticText : public SmartCtor<StaticText> {
public:
StaticText() {}
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() {}
~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();
/**
* 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; }
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

View File

@ -28,64 +28,156 @@ SOFTWARE.
namespace PD {
namespace LI {
/// @brief Container that holds top and bottom corners of a quad
/**
* 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);
}
/// This Constructor Fixes the issue of rewriting some Stuff in the Text
/// Renderer
/**
* 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];
@ -98,8 +190,8 @@ class Rect {
}
private:
vec4 top;
vec4 bot;
vec4 top; ///< Top left and right corner positions.
vec4 bot; ///< Bottom left and right corner positions.
};
} // namespace LI
} // namespace PD

View File

@ -25,6 +25,7 @@ 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>
@ -33,20 +34,48 @@ SOFTWARE.
#include <pd/lithium/screen.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
#include <pd/core/vec.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;
@ -55,7 +84,16 @@ class Renderer : public SmartCtor<Renderer> {
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!");
@ -76,6 +114,10 @@ class Renderer : public SmartCtor<Renderer> {
}
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;
@ -84,149 +126,256 @@ class Renderer : public SmartCtor<Renderer> {
current_tex = v;
}
/// @brief Draws a Rect based on current Texture
/// @param pos Pos
/// @param size Size
/// @param color Color
/// @param uv UV Map
/**
* 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));
/// @brief Draw a Solid Rect (uses white tex)
/// @note acts as a simplified Draw rect Wrapper
/// @param pos Position
/// @param size Size
/// @param color Color
/**
* 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);
/// @brief Render a Triangle
/// @param a Position Alpha
/// @param b Position Bravo
/// @param c Position Delta
/// @param color Color
/// @note Defaults to Solif 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);
/// @brief Draw a Circle (Supports Textures)
/// @param center_pos Center Position
/// @param r Radius
/// @param color Color
/// @param segments Segments to use
/// @note Textures could look a bit janky due to uv mapping
/**
* 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);
/// @brief Draw a Line between to Positions
/// @param a Position Alpha
/// @param b Position Bravo
/// @param color Color
/// @param t Thickness
/**
* 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());
/// @brief 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
/**
* 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 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 ///
// 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);
/// @brief 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
/**
* 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);
/// @brief Returns Viewport with xy
/** Returns Viewport with xy */
vec4 GetViewport();
/// @brief Push a Self Created command
/** Push a Self Created command */
void PushCommand(Command::Ref cmd) {
cmd->Index(cmd_idx++); // Indexing
draw_list[Screen32(screen)].push_back(cmd);
}
/// @brief Automatically sets up a command
/** Automatically sets up a command */
void SetupCommand(Command::Ref cmd);
/// @brief Creates a default Quad Render Command
/** Creates a default Quad Render Command */
void QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, u32 col);
/// @brief Create a Default Triangle
/** Create a Default Triangle */
void TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b,
const vec2& c, u32 col);
/// @brief 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)
/// @note Funktion macht noch faxxen (Text nicht sichtbar)
/**
* 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 ///
// Helper Funcitons
/**
* Update the 3DS citro3d texenv for specific RenderMode
* @param mode RenderMode to use.
*/
void UpdateRenderMode(const RenderMode& mode);
/// One Screen Only... ///
/** Current Screen */
Screen::Ref screen;
/// Reference Screens ///
/** Screen Regestry */
Screen::Ref screens[2];
/// Context Related ///
// 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;
Texture::Ref white = nullptr; // Single color
/** 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
/** Text Map System */
std::map<std::string, TextBox> tms;
// (Auto) Static Text
/** (Auto) Static Text */
std::unordered_map<u32, StaticText::Ref> ast;
/// Text Rendering ///
// 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 ///
// Special
/** Current Rotation (RECTS) */
float rot = 0.f;
/// Rendering ///
// Use dual drawlist
// 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 ///
// 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
/** 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
// Matrix
/** Precalculated Projectrion Matrix for top screen */
C3D_Mtx top_proj;
/** Precalculated Projectrion Matrix for bottom screen */
C3D_Mtx bot_proj;
};
} // namespace LI

View File

@ -30,9 +30,21 @@ SOFTWARE.
#include <pd/core/vec.hpp>
namespace PD {
/**
* 3DS Screen (RenderTarget)
*/
class Screen : public SmartCtor<Screen> {
public:
enum Screen_ { Top, Bottom, TopRight };
/** 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,
@ -51,27 +63,36 @@ class Screen : public SmartCtor<Screen> {
DisplayTransferFlags);
}
}
~Screen() {}
~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

View File

@ -30,19 +30,37 @@ SOFTWARE.
#include <pd/lithium/texture.hpp>
namespace PD {
/**
* Tex 3DS Spritesheet integration to Lithium
*/
class SpriteSheet : public SmartCtor<SpriteSheet> {
public:
SpriteSheet() {}
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

View File

@ -27,26 +27,33 @@ SOFTWARE.
#include <citro3d.h>
#include <pd/core/common.hpp>
#include <pd/lithium/rect.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,
RGB24,
A8,
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
};
/** Texture Filters */
enum Filter {
NEAREST,
LINEAR,
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/// @brief Default constructor
/** Default constructor */
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
/// @brief Load file Constructor
/// @param path path to file
/**
* 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);
@ -54,23 +61,27 @@ class Texture : public SmartCtor<Texture> {
this->LoadFile(path);
}
}
/// @brief Load Memory constructor
/// @param data File Data reference
/**
* 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);
}
/// @brief Load Pixels constructor
/// @param data Pixel Buffer reference
/// @param w width
/// @param h height
/// @param type Buffer Type
/// @param filter Filter
/**
* 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);
}
/// @brief Deconstructor (aka auto delete)
/** Deconstructor (aka auto delete) */
~Texture() {
if (autounload) {
Delete();
@ -119,7 +130,7 @@ class Texture : public SmartCtor<Texture> {
return vec2(tex->width, tex->height);
}
vec2 GetSize() const { return size; }
C3D_Tex* GetTex() const { return tex; };
C3D_Tex* GetTex() const { return tex; }
LI::Rect GetUV() const { return uv; }
bool IsValid() const { return tex != 0; }