From 52e362e1b281342c6c19b0c32bd33ee01d0c9c01 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sat, 26 Dec 2020 14:59:39 -0800 Subject: [PATCH] little bit more cleanup & naming fixes --- private/blah/internal/graphics_backend_gl.cpp | 12 ++-- public/blah/graphics/blend.h | 57 +++++++++++-------- public/blah/graphics/framebuffer.h | 13 ++++- public/blah/graphics/material.h | 15 +++-- public/blah/graphics/mesh.h | 14 ++++- public/blah/graphics/renderpass.cpp | 10 ++-- public/blah/graphics/shader.h | 13 ++++- public/blah/graphics/texture.h | 13 ++++- 8 files changed, 99 insertions(+), 48 deletions(-) diff --git a/private/blah/internal/graphics_backend_gl.cpp b/private/blah/internal/graphics_backend_gl.cpp index 5034c37..ee0a920 100644 --- a/private/blah/internal/graphics_backend_gl.cpp +++ b/private/blah/internal/graphics_backend_gl.cpp @@ -1294,12 +1294,12 @@ namespace Blah // Blend Mode { - GLenum colorOp = gl_get_blend_func(pass.blend.colorOp); - GLenum alphaOp = gl_get_blend_func(pass.blend.alphaOp); - GLenum colorSrc = gl_get_blend_factor(pass.blend.colorSrc); - GLenum colorDst = gl_get_blend_factor(pass.blend.colorDst); - GLenum alphaSrc = gl_get_blend_factor(pass.blend.alphaSrc); - GLenum alphaDst = gl_get_blend_factor(pass.blend.alphaDst); + GLenum colorOp = gl_get_blend_func(pass.blend.color_op); + GLenum alphaOp = gl_get_blend_func(pass.blend.alpha_op); + GLenum colorSrc = gl_get_blend_factor(pass.blend.color_src); + GLenum colorDst = gl_get_blend_factor(pass.blend.color_dst); + GLenum alphaSrc = gl_get_blend_factor(pass.blend.alpha_src); + GLenum alphaDst = gl_get_blend_factor(pass.blend.alpha_dst); gl.Enable(GL_BLEND); gl.BlendEquationSeparate(colorOp, alphaOp); diff --git a/public/blah/graphics/blend.h b/public/blah/graphics/blend.h index 41789f9..a6624c9 100644 --- a/public/blah/graphics/blend.h +++ b/public/blah/graphics/blend.h @@ -48,12 +48,18 @@ namespace Blah struct BlendMode { - BlendOp colorOp; - BlendFactor colorSrc; - BlendFactor colorDst; - BlendOp alphaOp; - BlendFactor alphaSrc; - BlendFactor alphaDst; + // Normal, pre-multiplied, Blend Mode + static const BlendMode Normal; + + // Subtractive Blend Mode + static const BlendMode Subtract; + + BlendOp color_op; + BlendFactor color_src; + BlendFactor color_dst; + BlendOp alpha_op; + BlendFactor alpha_src; + BlendFactor alpha_dst; BlendMask mask; uint32_t rgba; @@ -61,36 +67,39 @@ namespace Blah BlendMode(BlendOp op, BlendFactor src, BlendFactor dst) { - colorOp = op; - colorSrc = src; - colorDst = dst; - alphaOp = op; - alphaSrc = src; - alphaDst = dst; + color_op = op; + color_src = src; + color_dst = dst; + alpha_op = op; + alpha_src = src; + alpha_dst = dst; mask = BlendMask::RGBA; rgba = 0xffffffff; } BlendMode(BlendOp rgbOp, BlendFactor rgbSrc, BlendFactor rgbDst, BlendOp aOp, BlendFactor aSrc, BlendFactor aDst, BlendMask blendMask, uint32_t blendColor) { - colorOp = rgbOp; - colorSrc = rgbSrc; - colorDst = rgbDst; - alphaOp = aOp; - alphaSrc = aSrc; - alphaDst = aDst; + color_op = rgbOp; + color_src = rgbSrc; + color_dst = rgbDst; + alpha_op = aOp; + alpha_src = aSrc; + alpha_dst = aDst; mask = blendMask; rgba = blendColor; } - inline bool operator==(const BlendMode& rhs) const { - return colorOp == rhs.colorOp && colorSrc == rhs.colorSrc && colorDst == rhs.colorDst && - alphaOp == rhs.alphaOp && alphaSrc == rhs.alphaSrc && alphaDst == rhs.alphaDst && + inline bool operator==(const BlendMode& rhs) const + { + return + color_op == rhs.color_op && color_src == rhs.color_src && color_dst == rhs.color_dst && + alpha_op == rhs.alpha_op && alpha_src == rhs.alpha_src && alpha_dst == rhs.alpha_dst && mask == rhs.mask && rgba == rhs.rgba; } - inline bool operator!=(const BlendMode& rhs) const { return !(*this == rhs); } - static const BlendMode Normal; - static const BlendMode Subtract; + inline bool operator!=(const BlendMode& rhs) const + { + return !(*this == rhs); + } }; } \ No newline at end of file diff --git a/public/blah/graphics/framebuffer.h b/public/blah/graphics/framebuffer.h index 473d23e..a9c7f25 100644 --- a/public/blah/graphics/framebuffer.h +++ b/public/blah/graphics/framebuffer.h @@ -16,7 +16,18 @@ namespace Blah class FrameBuffer { + protected: + FrameBuffer() = default; + public: + // Copy / Moves not allowed + FrameBuffer(const FrameBuffer&) = delete; + FrameBuffer(FrameBuffer&&) = delete; + FrameBuffer& operator=(const FrameBuffer&) = delete; + FrameBuffer& operator=(FrameBuffer&&) = delete; + + // Default Destructor + virtual ~FrameBuffer() = default; // Creates a new FrameBuffer with a single Color attachment // If the FrameBuffer creation fails, it will return an invalid FrameBufferRef. @@ -26,8 +37,6 @@ namespace Blah // If the FrameBuffer creation fails, it will return an invalid FrameBufferRef. static FrameBufferRef create(int width, int height, const TextureFormat* attachments, int attachmentCount); - virtual ~FrameBuffer() = default; - // Gets the list of Attachments from the FrameBuffer virtual Attachments& attachments() = 0; diff --git a/public/blah/graphics/material.h b/public/blah/graphics/material.h index 0497af2..517e22e 100644 --- a/public/blah/graphics/material.h +++ b/public/blah/graphics/material.h @@ -9,16 +9,21 @@ namespace Blah class Material; typedef std::shared_ptr MaterialRef; - class Material + class Material final { private: Material(const ShaderRef& shader); - Material(const Material& src) = delete; - Material(Material&& src) = delete; - Material& operator=(const Material& src) = delete; - Material& operator=(Material&& src) = delete; public: + // Copy / Moves not allowed + Material(const Material&) = delete; + Material(Material&&) = delete; + Material& operator=(const Material&) = delete; + Material& operator=(Material&&) = delete; + + // Default destructor + ~Material() = default; + // Creates a new Material from the given Shader. // If the Shader is invalid, it will return an invalid MaterialRef. static MaterialRef create(const ShaderRef& shader); diff --git a/public/blah/graphics/mesh.h b/public/blah/graphics/mesh.h index 7871326..68840fd 100644 --- a/public/blah/graphics/mesh.h +++ b/public/blah/graphics/mesh.h @@ -49,13 +49,23 @@ namespace Blah class Mesh { + protected: + Mesh() = default; + public: + // Copy / Moves not allowed + Mesh(const Mesh&) = delete; + Mesh(Mesh&&) = delete; + Mesh& operator=(const Mesh&) = delete; + Mesh& operator=(Mesh&&) = delete; + + // Default Destructor + virtual ~Mesh() = default; + // Creates a new Mesh. // If the Mesh creation fails, it will return an invalid Mesh. static MeshRef create(); - virtual ~Mesh() = default; - // Sets the Vertex Format of the Mesh void vertex_format(const VertexAttribute* attributes, int attribute_count, int stride = -1); diff --git a/public/blah/graphics/renderpass.cpp b/public/blah/graphics/renderpass.cpp index 14f8fed..1cec11e 100644 --- a/public/blah/graphics/renderpass.cpp +++ b/public/blah/graphics/renderpass.cpp @@ -26,21 +26,21 @@ void RenderPass::perform() // Validate Material if (!material) { - Log::warn("Trying to draw with an invalid Material"); + Log::warn("Trying to draw with an invalid Material; skipping render pass"); return; } // Validate Shader if (!material->shader()) { - Log::warn("Trying to draw with an invalid Shader"); + Log::warn("Trying to draw with an invalid Shader; skipping render pass"); return; } // Validate Mesh if (!mesh) { - Log::warn("Trying to draw with an invalid Mesh"); + Log::warn("Trying to draw with an invalid Mesh; skipping render pass"); return; } @@ -59,7 +59,7 @@ void RenderPass::perform() if (pass.index_start + pass.index_count > index_count) { Log::warn( - "Trying to draw more indices than exist in the index buffer (%i-%i / %i)", + "Trying to draw more indices than exist in the index buffer (%i-%i / %i); trimming extra indices", pass.index_start, pass.index_start + pass.index_count, index_count); @@ -75,7 +75,7 @@ void RenderPass::perform() if (pass.instance_count > instance_count) { Log::warn( - "Trying to draw more instances than exist in the index buffer (%i / %i)", + "Trying to draw more instances than exist in the index buffer (%i / %i); trimming extra instances", pass.instance_count, instance_count); diff --git a/public/blah/graphics/shader.h b/public/blah/graphics/shader.h index c079b94..4ce355a 100644 --- a/public/blah/graphics/shader.h +++ b/public/blah/graphics/shader.h @@ -35,14 +35,23 @@ namespace Blah class Shader { + protected: + Shader() = default; + public: + // Copy / Moves not allowed + Shader(const Shader&) = delete; + Shader(Shader&&) = delete; + Shader& operator=(const Shader&) = delete; + Shader& operator=(Shader&&) = delete; + + // Default Destructor + virtual ~Shader() = default; // Creates a Shader with the given Shader Data. // If the Shader creation fails, it will return an invalid ShaderRef. static ShaderRef create(const ShaderData* data); - virtual ~Shader() = default; - // Gets a list of Shader Uniforms from Shader virtual Vector& uniforms() = 0; diff --git a/public/blah/graphics/texture.h b/public/blah/graphics/texture.h index f9b8a82..f0b6517 100644 --- a/public/blah/graphics/texture.h +++ b/public/blah/graphics/texture.h @@ -35,7 +35,18 @@ namespace Blah class Texture { + protected: + Texture() = default; + public: + // Copy / Moves not allowed + Texture(const Texture&) = delete; + Texture(Texture&&) = delete; + Texture& operator=(const Texture&) = delete; + Texture& operator=(Texture&&) = delete; + + // Default Destructor + virtual ~Texture() = default; // Creates a new Texture. // If the Texture creation fails, it will return an invalid TextureRef. @@ -57,8 +68,6 @@ namespace Blah // If the Texture creation fails, it will return an invalid TextureRef. static TextureRef create(const char* file); - virtual ~Texture() = default; - // gets the width of the texture virtual int width() const = 0;