mirror of
https://github.com/NoelFB/blah.git
synced 2025-07-18 19:41:52 +08:00
large organizational & cleanup refactor
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
#include <blah/graphics/batch.h>
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/graphics/framebuffer.h>
|
||||
#include <blah/graphics/target.h>
|
||||
#include <blah/graphics/mesh.h>
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/graphics/material.h>
|
||||
#include <blah/math/calc.h>
|
||||
#include <blah/core/app.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/app.h>
|
||||
#include <cmath>
|
||||
|
||||
using namespace Blah;
|
||||
@ -185,7 +185,7 @@ namespace
|
||||
#define INSERT_BATCH() \
|
||||
do { \
|
||||
m_batches.expand(); \
|
||||
for (int i = m_batches.size() - 1; i > m_batch_insert; i --) \
|
||||
for (auto i = m_batches.size() - 1; i > m_batch_insert; i --) \
|
||||
m_batches[i] = std::move(m_batches[i - 1]); \
|
||||
m_batches[m_batch_insert++] = m_batch; \
|
||||
m_batch.offset += m_batch.elements; \
|
||||
@ -378,7 +378,7 @@ void Batch::set_sampler(const TextureSampler& sampler)
|
||||
m_batch.sampler = sampler;
|
||||
}
|
||||
|
||||
void Batch::render(const FrameBufferRef& target)
|
||||
void Batch::render(const TargetRef& target)
|
||||
{
|
||||
Point size;
|
||||
if (!target)
|
||||
@ -389,7 +389,7 @@ void Batch::render(const FrameBufferRef& target)
|
||||
render(target, Mat4x4::create_ortho_offcenter(0, (float)size.x, (float)size.y, 0, 0.01f, 1000.0f));
|
||||
}
|
||||
|
||||
void Batch::render(const FrameBufferRef& target, const Mat4x4& matrix)
|
||||
void Batch::render(const TargetRef& target, const Mat4x4& matrix)
|
||||
{
|
||||
// nothing to draw
|
||||
if ((m_batches.size() <= 0 && m_batch.elements <= 0) || m_indices.size() <= 0)
|
||||
|
@ -1,53 +0,0 @@
|
||||
#include <blah/graphics/framebuffer.h>
|
||||
#include "../internal/graphics_backend.h"
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
FrameBufferRef FrameBuffer::create(int width, int height)
|
||||
{
|
||||
return create(width, height, { TextureFormat::RGBA });
|
||||
}
|
||||
|
||||
FrameBufferRef FrameBuffer::create(int width, int height, const AttachmentFormats& attachments)
|
||||
{
|
||||
BLAH_ASSERT(width > 0 && height > 0, "FrameBuffer width and height must be larger than 0");
|
||||
BLAH_ASSERT(attachments.size() > 0, "At least one attachment must be provided");
|
||||
|
||||
int color_count = 0;
|
||||
int depth_count = 0;
|
||||
|
||||
for (int i = 0; i < attachments.size(); i++)
|
||||
{
|
||||
BLAH_ASSERT((int)attachments[i] > (int)TextureFormat::None && (int)attachments[i] < (int)TextureFormat::Count, "Invalid texture format");
|
||||
|
||||
if (attachments[i] == TextureFormat::DepthStencil)
|
||||
depth_count++;
|
||||
else
|
||||
color_count++;
|
||||
}
|
||||
|
||||
BLAH_ASSERT(depth_count <= 1, "FrameBuffer can only have 1 Depth/Stencil Texture");
|
||||
BLAH_ASSERT(color_count <= Attachments::MaxCapacity - 1, "Exceeded maximum Color attachment count");
|
||||
|
||||
return GraphicsBackend::create_framebuffer(width, height, attachments.data(), attachments.size());
|
||||
}
|
||||
|
||||
TextureRef& FrameBuffer::attachment(int index)
|
||||
{
|
||||
return attachments()[index];
|
||||
}
|
||||
|
||||
const TextureRef& FrameBuffer::attachment(int index) const
|
||||
{
|
||||
return attachments()[index];
|
||||
}
|
||||
|
||||
int FrameBuffer::width() const
|
||||
{
|
||||
return attachments()[0]->width();
|
||||
}
|
||||
|
||||
int FrameBuffer::height() const
|
||||
{
|
||||
return attachments()[0]->height();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#include <blah/graphics/material.h>
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace Blah;
|
||||
@ -19,7 +19,7 @@ namespace
|
||||
case UniformType::Mat3x2: components = 6; break;
|
||||
case UniformType::Mat4x4: components = 16; break;
|
||||
default:
|
||||
BLAH_ERROR("Unespected Uniform Type");
|
||||
BLAH_ASSERT(false, "Unespected Uniform Type");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <blah/graphics/renderpass.h>
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include "../internal/graphics_backend.h"
|
||||
|
||||
using namespace Blah;
|
||||
@ -66,11 +66,7 @@ void RenderPass::perform()
|
||||
}
|
||||
|
||||
// get the total drawable size
|
||||
Vec2 draw_size;
|
||||
if (!pass.target)
|
||||
draw_size = Vec2(App::draw_width(), App::draw_height());
|
||||
else
|
||||
draw_size = Vec2(pass.target->width(), pass.target->height());
|
||||
auto draw_size = Vec2(pass.target->width(), pass.target->height());
|
||||
|
||||
// Validate Viewport
|
||||
if (!pass.has_viewport)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/core/app.h>
|
||||
#include <blah/app.h>
|
||||
#include "../internal/graphics_backend.h"
|
||||
|
||||
using namespace Blah;
|
||||
@ -21,7 +21,8 @@ ShaderRef Shader::create(const ShaderData& data)
|
||||
for (auto& it : uniforms)
|
||||
if (it.type == UniformType::None)
|
||||
{
|
||||
BLAH_ERROR_FMT("Uniform '%s' has an invalid type!\n\tOnly Float/Float2/Float3/Float4/Mat3x2/Mat4x4/Texture are allowed!", it.name.cstr());
|
||||
auto error = String::fmt("Uniform '%s' has an invalid type!\n\tOnly Float/Float2/Float3/Float4/Mat3x2/Mat4x4/Texture are allowed!", it.name.cstr());
|
||||
BLAH_ASSERT(false, error.cstr());
|
||||
return ShaderRef();
|
||||
}
|
||||
|
||||
@ -30,7 +31,8 @@ ShaderRef Shader::create(const ShaderData& data)
|
||||
for (int j = i + 1; j < uniforms.size(); j ++)
|
||||
if (uniforms[i].name == uniforms[j].name)
|
||||
{
|
||||
BLAH_ERROR_FMT("Shader Uniform names '%s' overlap! All Names must be unique.", uniforms[0].name.cstr());
|
||||
auto error = String::fmt("Shader Uniform names '%s' overlap! All Names must be unique.", uniforms[0].name.cstr());
|
||||
BLAH_ASSERT(false, error.cstr());
|
||||
return ShaderRef();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <blah/graphics/spritefont.h>
|
||||
#include <blah/images/font.h>
|
||||
#include <blah/images/packer.h>
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
@ -123,7 +123,7 @@ float SpriteFont::width_of_line(const String& text, int start) const
|
||||
float width = 0;
|
||||
|
||||
Codepoint last = 0;
|
||||
for (int i = start; i < text.length(); i ++)
|
||||
for (auto i = start; i < text.length(); i ++)
|
||||
{
|
||||
if (text[i] == '\n')
|
||||
return width;
|
||||
@ -139,7 +139,9 @@ float SpriteFont::width_of_line(const String& text, int start) const
|
||||
width += get_kerning(last, next);
|
||||
|
||||
// move to thext utf8 character
|
||||
i += text.utf8_length(i) - 1;
|
||||
auto len = text.utf8_length(i);
|
||||
if (len > 0)
|
||||
i += len - 1;
|
||||
|
||||
last = next;
|
||||
}
|
||||
@ -153,7 +155,7 @@ float SpriteFont::height_of(const String& text) const
|
||||
return 0;
|
||||
|
||||
float height = line_height();
|
||||
for (int i = 0; i < text.length(); i ++)
|
||||
for (auto i = 0; i < text.length(); i ++)
|
||||
{
|
||||
if (text[i] == '\n')
|
||||
height += line_height();
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <blah/graphics/subtexture.h>
|
||||
#include <blah/math/calc.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
|
53
src/graphics/target.cpp
Normal file
53
src/graphics/target.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <blah/graphics/target.h>
|
||||
#include "../internal/graphics_backend.h"
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
TargetRef Target::create(int width, int height)
|
||||
{
|
||||
return create(width, height, { TextureFormat::RGBA });
|
||||
}
|
||||
|
||||
TargetRef Target::create(int width, int height, const AttachmentFormats& textures)
|
||||
{
|
||||
BLAH_ASSERT(width > 0 && height > 0, "Target width and height must be larger than 0");
|
||||
BLAH_ASSERT(textures.size() > 0, "At least one texture must be provided");
|
||||
|
||||
int color_count = 0;
|
||||
int depth_count = 0;
|
||||
|
||||
for (int i = 0; i < textures.size(); i++)
|
||||
{
|
||||
BLAH_ASSERT((int)textures[i] > (int)TextureFormat::None && (int)textures[i] < (int)TextureFormat::Count, "Invalid texture format");
|
||||
|
||||
if (textures[i] == TextureFormat::DepthStencil)
|
||||
depth_count++;
|
||||
else
|
||||
color_count++;
|
||||
}
|
||||
|
||||
BLAH_ASSERT(depth_count <= 1, "Target can only have 1 Depth/Stencil Texture");
|
||||
BLAH_ASSERT(color_count <= Attachments::capacity - 1, "Exceeded maximum Color texture count");
|
||||
|
||||
return GraphicsBackend::create_target(width, height, textures.data(), textures.size());
|
||||
}
|
||||
|
||||
TextureRef& Target::texture(int index)
|
||||
{
|
||||
return textures()[index];
|
||||
}
|
||||
|
||||
const TextureRef& Target::texture(int index) const
|
||||
{
|
||||
return textures()[index];
|
||||
}
|
||||
|
||||
int Target::width() const
|
||||
{
|
||||
return textures()[0]->width();
|
||||
}
|
||||
|
||||
int Target::height() const
|
||||
{
|
||||
return textures()[0]->height();
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/images/image.h>
|
||||
#include <blah/streams/stream.h>
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include "../internal/graphics_backend.h"
|
||||
|
||||
using namespace Blah;
|
||||
|
Reference in New Issue
Block a user