From 9e3f745a38e9919f830c9cf53d3b4da47ba6a576 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Mon, 22 Mar 2021 16:53:27 -0700 Subject: [PATCH] removed drawing folder; moved to graphics --- CMakeLists.txt | 9 ++++----- include/blah.h | 6 +++--- include/blah/containers/str.h | 9 +++++++++ include/blah/containers/vector.h | 1 + include/blah/{drawing => graphics}/batch.h | 11 ++++++++--- include/blah/graphics/blend.h | 1 + include/blah/graphics/mesh.h | 8 ++++++++ include/blah/graphics/renderpass.h | 7 +++++++ include/blah/graphics/sampler.h | 18 ++++++++++++++++++ include/blah/graphics/shader.h | 1 + .../blah/{drawing => graphics}/spritefont.h | 2 +- .../blah/{drawing => graphics}/subtexture.h | 0 include/blah/graphics/texture.h | 11 +++++++++++ include/blah/images/image.h | 3 ++- include/blah/images/packer.h | 2 +- src/{drawing => graphics}/batch.cpp | 2 +- src/{drawing => graphics}/spritefont.cpp | 2 +- src/{drawing => graphics}/subtexture.cpp | 2 +- 18 files changed, 78 insertions(+), 17 deletions(-) rename include/blah/{drawing => graphics}/batch.h (96%) rename include/blah/{drawing => graphics}/spritefont.h (98%) rename include/blah/{drawing => graphics}/subtexture.h (100%) rename src/{drawing => graphics}/batch.cpp (99%) rename src/{drawing => graphics}/spritefont.cpp (99%) rename src/{drawing => graphics}/subtexture.cpp (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85821ad..15aa378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,13 +11,16 @@ add_library(blah src/core/filesystem.cpp src/core/common.cpp src/core/time.cpp - + + src/graphics/batch.cpp src/graphics/blend.cpp src/graphics/framebuffer.cpp src/graphics/material.cpp src/graphics/mesh.cpp src/graphics/renderpass.cpp src/graphics/shader.cpp + src/graphics/spritefont.cpp + src/graphics/subtexture.cpp src/graphics/texture.cpp src/input/input.cpp @@ -25,10 +28,6 @@ add_library(blah src/input/binding_registry.cpp src/containers/str.cpp - - src/drawing/batch.cpp - src/drawing/spritefont.cpp - src/drawing/subtexture.cpp src/images/aseprite.cpp src/images/font.cpp diff --git a/include/blah.h b/include/blah.h index d2084cd..49adfad 100644 --- a/include/blah.h +++ b/include/blah.h @@ -9,9 +9,9 @@ #include "blah/containers/stackvector.h" #include "blah/containers/str.h" -#include "blah/drawing/batch.h" -#include "blah/drawing/spritefont.h" -#include "blah/drawing/subtexture.h" +#include "blah/graphics/batch.h" +#include "blah/graphics/spritefont.h" +#include "blah/graphics/subtexture.h" #include "blah/graphics/blend.h" #include "blah/graphics/framebuffer.h" diff --git a/include/blah/containers/str.h b/include/blah/containers/str.h index bff386c..48d02e8 100644 --- a/include/blah/containers/str.h +++ b/include/blah/containers/str.h @@ -10,6 +10,7 @@ namespace Blah class StrOf; using String = StrOf<64>; + // A simple String implementation class Str { public: @@ -138,8 +139,10 @@ namespace Blah // returns a substring of the string String substr(int start, int end) const; + // Splits the string into a vector of strings Vector split(char ch) const; + // replaces all occurances of old string with the new string Str& replace(const Str& old_str, const Str& new_str); // replaces all occurances of the given character in the string @@ -171,9 +174,14 @@ namespace Blah // returns a pointer to the heap buffer or to our stack allocation char* data() { return (m_buffer != nullptr ? m_buffer : ((char*)(this) + sizeof(Str))); } + + // returns a pointer to the heap buffer or to our stack allocation const char* data() const { return (m_buffer != nullptr ? m_buffer : ((char*)(this) + sizeof(Str))); } + // assigns the contents of the string void set(const Str& str) { set(str.cstr(), str.cstr() + str.m_length); } + + // assigns the contents of the string void set(const char* start, const char* end = nullptr); private: @@ -187,6 +195,7 @@ namespace Blah // combine string inline Str operator+(const Str& lhs, const Str& rhs) { Str str; str.append(lhs).append(rhs); return str; } + // A string with a local stack buffer of size T template class StrOf : public Str { diff --git a/include/blah/containers/vector.h b/include/blah/containers/vector.h index 9073d91..7c28599 100644 --- a/include/blah/containers/vector.h +++ b/include/blah/containers/vector.h @@ -6,6 +6,7 @@ namespace Blah { + // A lightweight Vector implementation template class Vector { diff --git a/include/blah/drawing/batch.h b/include/blah/graphics/batch.h similarity index 96% rename from include/blah/drawing/batch.h rename to include/blah/graphics/batch.h index 3ecdeed..f2a62ec 100644 --- a/include/blah/drawing/batch.h +++ b/include/blah/graphics/batch.h @@ -5,8 +5,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -15,9 +15,14 @@ namespace Blah { + // Spritebatcher Color Mode enum class ColorMode { + // Draws textures and shapes normally Normal, + + // Ignores the texture color but still uses transparency, essentially + // drawing the "shape" of the texture a solid color Wash }; @@ -38,7 +43,7 @@ namespace Blah inline TextAlign operator|(TextAlign lhs, TextAlign rhs) { return static_cast(static_cast(lhs) | static_cast(rhs)); } inline TextAlign operator&(TextAlign lhs, TextAlign rhs) { return static_cast(static_cast(lhs) & static_cast(rhs)); } - // A simple 2D sprite batcher, used for drawing shapes and textures + // A 2D sprite batcher, used for drawing shapes and textures class Batch { public: diff --git a/include/blah/graphics/blend.h b/include/blah/graphics/blend.h index e1b2a0e..87b82ea 100644 --- a/include/blah/graphics/blend.h +++ b/include/blah/graphics/blend.h @@ -46,6 +46,7 @@ namespace Blah RGBA = Red | Green | Blue | Alpha, }; + // BlendMode using for rendering struct BlendMode { // Normal, pre-multiplied, Blend Mode diff --git a/include/blah/graphics/mesh.h b/include/blah/graphics/mesh.h index 26e5d0d..15beeb4 100644 --- a/include/blah/graphics/mesh.h +++ b/include/blah/graphics/mesh.h @@ -5,6 +5,7 @@ namespace Blah { + // Supported Vertex value types enum class VertexType { None, @@ -20,6 +21,7 @@ namespace Blah UShort4 }; + // Vertex Attribute information struct VertexAttribute { // Location / Attribute Index @@ -32,6 +34,8 @@ namespace Blah bool normalized = false; }; + // Vertex Format information. + // Holds a list of attributes and total stride per-vertex. struct VertexFormat { // List of Attributes @@ -44,9 +48,13 @@ namespace Blah VertexFormat(std::initializer_list attributes, int stride = 0); }; + // Supported Vertex Index formats enum class IndexFormat { + // Indices are 16 bit unsigned integers UInt16, + + // Indices are 32 bit unsigned integers UInt32 }; diff --git a/include/blah/graphics/renderpass.h b/include/blah/graphics/renderpass.h index 0ab5875..df3d962 100644 --- a/include/blah/graphics/renderpass.h +++ b/include/blah/graphics/renderpass.h @@ -11,6 +11,7 @@ namespace Blah { + // Depth comparison function to use during a draw call enum class Compare { None, @@ -24,10 +25,16 @@ namespace Blah GreatorOrEqual }; + // Cull mode during a draw call enum class Cull { + // No Culling enabled None = 0, + + // Cull front faces Front = 1, + + // Cull back faces Back = 2, }; diff --git a/include/blah/graphics/sampler.h b/include/blah/graphics/sampler.h index 432c8f8..c75fb94 100644 --- a/include/blah/graphics/sampler.h +++ b/include/blah/graphics/sampler.h @@ -2,24 +2,42 @@ namespace Blah { + // Texture filter enum class TextureFilter { + // None will fallback to whatever default the driver sets None, + + // Linear interpolation Linear, + + // Nearest Neighbour interpolation Nearest }; + // Texture Wrap Mode enum class TextureWrap { + // None will fallback to whatever default the driver sets None, + + // Clamps the texture to the edges Clamp, + + // Repeats the texture Repeat }; + // Texture Sampler State, applied during rendering struct TextureSampler { + // Filter Mode TextureFilter filter; + + // Wrap X Mode TextureWrap wrap_x; + + // Wrap Y Mode TextureWrap wrap_y; TextureSampler() : diff --git a/include/blah/graphics/shader.h b/include/blah/graphics/shader.h index adec92e..c7d18af 100644 --- a/include/blah/graphics/shader.h +++ b/include/blah/graphics/shader.h @@ -72,6 +72,7 @@ namespace Blah class Shader; typedef std::shared_ptr ShaderRef; + // A shader used during Rendering class Shader { protected: diff --git a/include/blah/drawing/spritefont.h b/include/blah/graphics/spritefont.h similarity index 98% rename from include/blah/drawing/spritefont.h rename to include/blah/graphics/spritefont.h index 154a9ab..e0e1096 100644 --- a/include/blah/drawing/spritefont.h +++ b/include/blah/graphics/spritefont.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/blah/drawing/subtexture.h b/include/blah/graphics/subtexture.h similarity index 100% rename from include/blah/drawing/subtexture.h rename to include/blah/graphics/subtexture.h diff --git a/include/blah/graphics/texture.h b/include/blah/graphics/texture.h index 3b40222..61e4ba6 100644 --- a/include/blah/graphics/texture.h +++ b/include/blah/graphics/texture.h @@ -5,11 +5,22 @@ namespace Blah { enum class TextureFormat { + // Invalid Format None, + + // Single 8-bit channe; R, + + // 2 8-bit channels RG, + + // 4 8-bit channels RGBA, + + // Depth 24, Stencil 8 DepthStencil, + + // Total Formats Count }; diff --git a/include/blah/images/image.h b/include/blah/images/image.h index 9b295ff..7d681b2 100644 --- a/include/blah/images/image.h +++ b/include/blah/images/image.h @@ -8,7 +8,8 @@ namespace Blah { class Stream; - // A simple 2D Bitmap + // A 2D Bitmap stored on the CPU. + // For drawing images to the screen, use a Texture. class Image { public: diff --git a/include/blah/images/packer.h b/include/blah/images/packer.h index 56bf83d..faa451e 100644 --- a/include/blah/images/packer.h +++ b/include/blah/images/packer.h @@ -11,7 +11,7 @@ namespace Blah { // Texture Packer, which takes source images and combines - // them into a single large texture. + // them into a single large texture. Useful for 2D sprite batching. class Packer { public: diff --git a/src/drawing/batch.cpp b/src/graphics/batch.cpp similarity index 99% rename from src/drawing/batch.cpp rename to src/graphics/batch.cpp index 5a8a79a..6ebe4a3 100644 --- a/src/drawing/batch.cpp +++ b/src/graphics/batch.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/drawing/spritefont.cpp b/src/graphics/spritefont.cpp similarity index 99% rename from src/drawing/spritefont.cpp rename to src/graphics/spritefont.cpp index 4bd6917..3c75ed9 100644 --- a/src/drawing/spritefont.cpp +++ b/src/graphics/spritefont.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/drawing/subtexture.cpp b/src/graphics/subtexture.cpp similarity index 97% rename from src/drawing/subtexture.cpp rename to src/graphics/subtexture.cpp index f2e9ff8..e144390 100644 --- a/src/drawing/subtexture.cpp +++ b/src/graphics/subtexture.cpp @@ -1,4 +1,4 @@ -#include +#include #include using namespace Blah;