commenting

This commit is contained in:
Noel Berry 2020-12-23 16:57:49 -08:00
parent be989cdde9
commit eda7cc8398
4 changed files with 100 additions and 13 deletions

View File

@ -3,22 +3,51 @@
namespace Blah namespace Blah
{ {
// Graphics backend API used for rendering.
// All rendering ends up going through here.
namespace GraphicsBackend namespace GraphicsBackend
{ {
// Initializes the graphics backend
bool init(); bool init();
// Shuts down the graphics backend
void shutdown(); void shutdown();
// Returns info about the renderer
const GraphicsInfo* info(); const GraphicsInfo* info();
// Returns the renderer type
GraphicsRenderer renderer(); GraphicsRenderer renderer();
// Called once per frame
void frame(); void frame();
// Called before rendering begins
void before_render(); void before_render();
// Called after renderings ends
void after_render(); void after_render();
// Performs a draw call
void render(RenderCall* call); void render(RenderCall* call);
// Clears a buffer
void clear(const FrameBufferRef& target, uint32_t rgba); void clear(const FrameBufferRef& target, uint32_t rgba);
// Creates a new Texture.
// if the Texture is invalid, this should return an empty reference.
TextureRef create_texture(int width, int height, TextureFilter filter, TextureWrap wrap_x, TextureWrap wrap_y, TextureFormat format); TextureRef create_texture(int width, int height, TextureFilter filter, TextureWrap wrap_x, TextureWrap wrap_y, TextureFormat format);
// Creates a new FrameBuffer.
// if the FrameBuffer is invalid, this should return an empty reference.
FrameBufferRef create_framebuffer(int width, int height, const TextureFormat* attachments, int attachmentCount); FrameBufferRef create_framebuffer(int width, int height, const TextureFormat* attachments, int attachmentCount);
// Creates a new Shader.
// if the Shader is invalid, this should return an empty reference.
ShaderRef create_shader(const ShaderData* data); ShaderRef create_shader(const ShaderData* data);
// Creates a new Mesh.
// if the Mesh is invalid, this should return an empty reference.
MeshRef create_mesh(); MeshRef create_mesh();
} }
} }

View File

@ -12,7 +12,6 @@
namespace Blah namespace Blah
{ {
enum class ColorMode enum class ColorMode
{ {
Normal, Normal,
@ -39,30 +38,72 @@ namespace Blah
class Batch class Batch
{ {
public: public:
// The name of the Matrix Uniform in the Shader
const char* matrix_uniform;
// The name of the Texture Uniform in the Shader
const char* texture_uniform;
Batch(); Batch();
Batch(const Batch& other) = delete; Batch(const Batch& other) = delete;
Batch& operator=(const Batch& other) = delete; Batch& operator=(const Batch& other) = delete;
~Batch(); ~Batch();
// Pushes a new matrix onto the stack, and uses it for transforming all drawing.
// `absolute` means the matrix provided will not be transformed by the current stack.
void push_matrix(const Mat3x2& matrix, bool absolute = false); void push_matrix(const Mat3x2& matrix, bool absolute = false);
// Pops the matrix from the stack
Mat3x2 pop_matrix(); Mat3x2 pop_matrix();
// Pushes a Scissor rectangle. Note this is not transformed by the matrix stack
// or other scissors. Each push is screen-space.
void push_scissor(const Rect& scissor); void push_scissor(const Rect& scissor);
// Pops a Scissor rectangle from the stack
void pop_scissor(); void pop_scissor();
// Pushes a blend mode
void push_blend(const BlendMode& blend); void push_blend(const BlendMode& blend);
// Pops a blend mode
void pop_blend(); void pop_blend();
// Pushes a Material to use for all drawing. Note that the state of the Material
// is not copied - it will be drawn with the values of the Material at render.
void push_material(const MaterialRef& material); void push_material(const MaterialRef& material);
// Pops a Material
void pop_material(); void pop_material();
// Pushes a render layer. Lower values are rendered first. This is not super optimized
// and should generally be avoided.
void push_layer(int layer); void push_layer(int layer);
// Pops a Layer
void pop_layer(); void pop_layer();
// Pushes a Color Mode for drawing Textures
void push_color_mode(ColorMode mode); void push_color_mode(ColorMode mode);
// Pops a Color MOde
void pop_color_mode(); void pop_color_mode();
// Sets the current texture used for drawing. Note that certain functions will override
// this (ex the `str` and `tex` methods)
void set_texture(const TextureRef& texture); void set_texture(const TextureRef& texture);
// Draws the batch to the given target
void render(const FrameBufferRef& target); void render(const FrameBufferRef& target);
// Draws the batch to the given target, with the provided matrix
void render(const FrameBufferRef& target, const Mat4x4& matrix); void render(const FrameBufferRef& target, const Mat4x4& matrix);
// Clears the batch
void clear(); void clear();
// Clears and disposes all resources that the batch is using
void dispose(); void dispose();
void line(const Vec2& from, const Vec2& to, float t, Color color); void line(const Vec2& from, const Vec2& to, float t, Color color);
@ -105,12 +146,10 @@ namespace Blah
void tex(); void tex();
void tex(const Subtexture& subtexture, const Vec2& pos, Color color); void tex(const Subtexture& subtexture, const Vec2& pos, Color color);
void tex(const Subtexture& subtexture, const Vec2& pos, const Vec2& origin, const Vec2& scale, float rotation, Color color); void tex(const Subtexture& subtexture, const Vec2& pos, const Vec2& origin, const Vec2& scale, float rotation, Color color);
void str(const SpriteFont& font, const String& text, const Vec2& pos, Color color); void str(const SpriteFont& font, const String& text, const Vec2& pos, Color color);
void str(const SpriteFont& font, const String& text, const Vec2& pos, TextAlign align, float size, Color color); void str(const SpriteFont& font, const String& text, const Vec2& pos, TextAlign align, float size, Color color);
const char* matrix_uniform;
const char* texture_uniform;
private: private:
struct Vertex struct Vertex

View File

@ -2,10 +2,13 @@
using namespace Blah; using namespace Blah;
Subtexture::Subtexture() Subtexture::Subtexture() {}
{
} Subtexture::Subtexture(const TextureRef& texture)
: Subtexture(texture, Rect(0, 0, texture->width(), texture->height())) {}
Subtexture::Subtexture(const TextureRef& texture, Rect source)
: Subtexture(texture, source, Rect(0, 0, source.w, source.h)) {}
Subtexture::Subtexture(const TextureRef& texture, Rect source, Rect frame) Subtexture::Subtexture(const TextureRef& texture, Rect source, Rect frame)
: texture(texture), source(source), frame(frame) : texture(texture), source(source), frame(frame)

View File

@ -6,19 +6,35 @@ namespace Blah
{ {
struct Subtexture struct Subtexture
{ {
TextureRef texture; // Reference to our Texture
Rect source; TextureRef texture;
Rect frame;
Vec2 draw_coords[4]; // draw coords are automatically assigned through Update method // Source rectangle, in pixels
Vec2 tex_coords[4]; // tex coords are automatically assigned through Update method Rect source;
// Frame rectangle, in pixels. This describes padding around the image.
// This is useful for drawing images that have been trimmed. Ex. if the source
// is 32,32, but the original image was 64,64, the frame could be -16,-16,64,64
Rect frame;
// `draw_coords` are automatically assigned through `update` method
Vec2 draw_coords[4];
// `tex_coords` are automatically assigned through the `update` method
Vec2 tex_coords[4];
Subtexture(); Subtexture();
Subtexture(const TextureRef& texture);
Subtexture(const TextureRef& texture, Rect source);
Subtexture(const TextureRef& texture, Rect source, Rect frame); Subtexture(const TextureRef& texture, Rect source, Rect frame);
// Returns the width of the image
float width() const { return frame.w; } float width() const { return frame.w; }
// Returns the height of the image
float height() const { return frame.h; } float height() const { return frame.h; }
// updates the draw and tex coords // updates the `draw_coords` and `tex_coords`
void update(); void update();
}; };
} }