more graphics cleanup - removing Shader Attribute Info

This commit is contained in:
Noel Berry
2020-12-24 03:01:05 -08:00
parent 4c4d495fa8
commit 134d26040c
13 changed files with 183 additions and 253 deletions

View File

@ -5,6 +5,7 @@
#include <blah/graphics/shader.h>
#include <blah/graphics/material.h>
#include <blah/math/calc.h>
#include <blah/app.h>
using namespace Blah;

View File

@ -1,6 +1,7 @@
#include <blah/drawing/spritefont.h>
#include <blah/images/font.h>
#include <blah/images/packer.h>
#include <blah/graphics/graphics.h>
#include <blah/log.h>
using namespace Blah;

View File

@ -1,9 +1,11 @@
#pragma once
#include <blah/graphics/graphics.h>
#include <blah/graphics/texture.h>
#include <blah/containers/stackvector.h>
#include <memory>
// 4 color attachments + 1 depth/stencil
#define BLAH_ATTACHMENTS 5
namespace Blah
{
typedef StackVector<TextureRef, BLAH_ATTACHMENTS> Attachments;

View File

@ -5,6 +5,7 @@
#include <blah/graphics/material.h>
#include <blah/graphics/shader.h>
#include <blah/log.h>
#include <blah/app.h>
#include <blah/internal/graphics_backend.h>
#include <blah/images/image.h>
#include <string.h>

View File

@ -1,78 +1,19 @@
#pragma once
#include <inttypes.h>
#include <blah/app.h>
#include <blah/math/point.h>
#include <blah/math/rect.h>
#include <blah/containers/str.h>
#include <blah/graphics/texture.h>
#include <blah/graphics/framebuffer.h>
#include <blah/graphics/mesh.h>
#include <blah/graphics/shader.h>
#include <blah/graphics/material.h>
#include <memory>
#define BLAH_ATTACHMENTS 5 // 4 color attachments + 1 depth/stencil
#define BLAH_UNIFORMS 16 // 16 shader uniforms
#define BLAH_ATTRIBUTES 16 // 16 shader attributes
#define BLAH_ATTRIBUTE_NAME 32 // max shader attribute name length
#define BLAH_UNIFORM_NAME 32 // max shader uniform name length
namespace Blah
{
class Stream;
class Image;
class Texture;
typedef std::shared_ptr<Texture> TextureRef;
class FrameBuffer;
typedef std::shared_ptr<FrameBuffer> FrameBufferRef;
class Material;
typedef std::shared_ptr<Material> MaterialRef;
class Shader;
typedef std::shared_ptr<Shader> ShaderRef;
class Mesh;
typedef std::shared_ptr<Mesh> MeshRef;
enum class GraphicsRenderer
{
None = -1,
OpenGL,
D3D11,
Metal,
Count
};
struct GraphicsInfo
{
bool instancing = false;
bool origin_bottom_left = false;
int max_texture_size = 0;
};
enum class TextureFilter
{
None,
Linear,
Nearest
};
enum class TextureWrap
{
None,
Clamp,
Repeat
};
enum class TextureFormat
{
None,
R,
RG,
RGB,
RGBA,
DepthStencil,
Count
};
enum class Compare
{
None,
@ -129,11 +70,11 @@ namespace Blah
enum class BlendMask
{
None = 0,
Red = 1,
Red = 1,
Green = 2,
Blue = 4,
Alpha = 8,
RGB = Red | Green | Blue,
RGB = Red | Green | Blue,
RGBA = Red | Green | Blue | Alpha,
};
@ -185,78 +126,6 @@ namespace Blah
static const BlendMode Subtract;
};
enum class UniformType
{
None,
Float,
Float2,
Float3,
Float4,
Mat3x2,
Mat4x4,
Texture
};
enum class VertexSemantics
{
None,
Position,
Normal,
Bitangent,
Color0,
Color1,
Color2,
Color3,
Indices,
Weight,
Texcoord0,
Texcoord1,
Texcoord2,
Texcoord3,
Texcoord4,
Texcoord5,
Texcoord6,
Texcoord7
};
enum class VertexAttributeType
{
None,
Byte,
Short,
Int,
Float
};
struct VertexAttribute
{
int index;
VertexSemantics semantics;
VertexAttributeType type;
int components;
bool normalized;
};
struct ShaderData
{
const char* vertex;
const char* fragment;
};
struct ShaderUniform
{
StrOf<BLAH_UNIFORM_NAME> name;
UniformType type;
int array_length;
};
struct ShaderAttribute
{
StrOf<BLAH_ATTRIBUTE_NAME> name;
StrOf<BLAH_ATTRIBUTE_NAME> semantic_name;
int semantic_location;
};
struct RenderCall
{
// Framebuffer to draw to
@ -302,6 +171,22 @@ namespace Blah
RenderCall();
};
enum class GraphicsRenderer
{
None = -1,
OpenGL,
D3D11,
Metal,
Count
};
struct GraphicsInfo
{
bool instancing = false;
bool origin_bottom_left = false;
int max_texture_size = 0;
};
namespace Graphics
{
const FrameBufferRef backbuffer;

View File

@ -5,7 +5,7 @@ using namespace Blah;
namespace
{
int calc_uniform_size(const ShaderUniform& uniform)
int calc_uniform_size(const UniformInfo& uniform)
{
int components = 0;
@ -31,8 +31,8 @@ Material::Material(const ShaderRef& shader)
BLAH_ASSERT(shader, "Material is being created with an invalid shader");
m_shader = shader;
Uniforms uniforms = shader->uniforms();
StackVector<size_t, BLAH_UNIFORMS> float_offsets;
auto& uniforms = shader->uniforms();
Vector<size_t> float_offsets;
size_t float_size = 0;
for (auto& uniform : uniforms)

View File

@ -1,10 +1,49 @@
#pragma once
#include <inttypes.h>
#include <blah/graphics/graphics.h>
#include <memory>
namespace Blah
{
enum class VertexSemantics
{
None,
Position,
Normal,
Bitangent,
Color0,
Color1,
Color2,
Color3,
Indices,
Weight,
Texcoord0,
Texcoord1,
Texcoord2,
Texcoord3,
Texcoord4,
Texcoord5,
Texcoord6,
Texcoord7
};
enum class VertexAttributeType
{
None,
Byte,
Short,
Int,
Float
};
struct VertexAttribute
{
int index;
VertexSemantics semantics;
VertexAttributeType type;
int components;
bool normalized;
};
class Mesh
{
public:

View File

@ -1,12 +1,34 @@
#pragma once
#include <blah/graphics/graphics.h>
#include <blah/containers/stackvector.h>
#include <blah/containers/str.h>
#include <memory>
namespace Blah
{
typedef StackVector<ShaderUniform, BLAH_UNIFORMS> Uniforms;
typedef StackVector<ShaderAttribute, BLAH_ATTRIBUTES> Attributes;
enum class UniformType
{
None,
Float,
Float2,
Float3,
Float4,
Mat3x2,
Mat4x4,
Texture
};
struct UniformInfo
{
String name;
UniformType type;
int array_length;
};
struct ShaderData
{
const char* vertex;
const char* fragment;
};
class Shader
{
@ -14,16 +36,10 @@ namespace Blah
virtual ~Shader() = default;
// Gets a list of Shader Uniforms from Shader
virtual Uniforms& uniforms() = 0;
virtual Vector<UniformInfo>& uniforms() = 0;
// Gets a list of Shader Uniforms from Shader
virtual const Uniforms& uniforms() const = 0;
// Gets a list of Shader Attributes from Shader
virtual Attributes& attributes() = 0;
// Gets a list of Shader Attributes from Shader
virtual const Attributes& attributes() const = 0;
virtual const Vector<UniformInfo>& uniforms() const = 0;
};
typedef std::shared_ptr<Shader> ShaderRef;

View File

@ -1,9 +1,33 @@
#pragma once
#include <blah/graphics/graphics.h>
#include <memory>
namespace Blah
{
enum class TextureFilter
{
None,
Linear,
Nearest
};
enum class TextureWrap
{
None,
Clamp,
Repeat
};
enum class TextureFormat
{
None,
R,
RG,
RGB,
RGBA,
DepthStencil,
Count
};
class Texture
{
public:

View File

@ -156,6 +156,11 @@ bool Rect::contains(const Vec2& pt) const
return pt.x >= x && pt.x < x + w && pt.y >= y && pt.y < y + h;
}
bool Rect::overlaps(const Rect& rect) const
{
return x + w >= rect.x && y + h >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
}
Rect Rect::overlap_rect(const Rect& against) const
{
Rect result(0, 0, 0, 0);

View File

@ -50,7 +50,7 @@ namespace Blah
bool contains(const Point& pt) const;
bool contains(const Vec2& pt) const;
bool overlaps(const Rect& rect) const { return x + w >= rect.x && y + h >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h; }
bool overlaps(const Rect& rect) const;
Rect overlap_rect(const Rect& other) const;
bool intersects(const Line& line) const;