simplified texture and framebuffer create methods

This commit is contained in:
Noel Berry
2021-03-24 00:56:43 -07:00
parent 1570e9becf
commit bd9736df03
5 changed files with 25 additions and 55 deletions

View File

@ -5,20 +5,18 @@ using namespace Blah;
FrameBufferRef FrameBuffer::create(int width, int height)
{
static const TextureFormat attachment = TextureFormat::RGBA;
return create(width, height, &attachment, 1);
return create(width, height, { TextureFormat::RGBA });
}
FrameBufferRef FrameBuffer::create(int width, int height, const TextureFormat* attachments, int attachment_count)
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(attachment_count <= Attachments::MaxCapacity, "Exceeded maximum attachment count");
BLAH_ASSERT(attachment_count > 0, "At least one attachment must be provided");
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 < attachment_count; i++)
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");
@ -31,5 +29,5 @@ FrameBufferRef FrameBuffer::create(int width, int height, const TextureFormat* a
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, attachment_count);
return GraphicsBackend::create_framebuffer(width, height, attachments.data(), attachments.size());
}

View File

@ -335,9 +335,9 @@ const float* Material::get_value(const char* name, i64* length) const
offset += calc_uniform_size(uniform);
}
Log::warn("No Uniform '%s' exists", name);
*length = 0;
return nullptr;
Log::warn("No Uniform '%s' exists", name);
}
const Vector<TextureRef>& Material::textures() const

View File

@ -8,54 +8,28 @@ using namespace Blah;
TextureRef Texture::create(const Image& image)
{
auto tex = create(image.width, image.height, TextureFormat::RGBA);
if (tex)
tex->set_data((unsigned char*)image.pixels);
return tex;
return create(image.width, image.height, TextureFormat::RGBA, (unsigned char*)image.pixels);
}
TextureRef Texture::create(int width, int height, unsigned char* rgba)
{
auto tex = create(width, height, TextureFormat::RGBA);
if (tex)
tex->set_data(rgba);
return tex;
}
TextureRef Texture::create(int width, int height, TextureFormat format)
TextureRef Texture::create(int width, int height, TextureFormat format, unsigned char* data)
{
BLAH_ASSERT(width > 0 && height > 0, "Texture width and height must be larger than 0");
BLAH_ASSERT((int)format > (int)TextureFormat::None && (int)format < (int)TextureFormat::Count, "Invalid texture format");
return GraphicsBackend::create_texture(width, height, format);
auto tex = GraphicsBackend::create_texture(width, height, format);
if (tex && data != nullptr)
tex->set_data(data);
return tex;
}
TextureRef Texture::create(Stream& stream)
{
Image img = Image(stream);
if (img.pixels && img.width > 0 && img.height > 0)
{
auto tex = create(img.width, img.height, TextureFormat::RGBA);
if (tex)
tex->set_data((unsigned char*)img.pixels);
return tex;
}
return TextureRef();
return create(Image(stream));
}
TextureRef Texture::create(const char* file)
TextureRef Texture::create(const FilePath& file)
{
Image img = Image(file);
if (img.pixels)
{
auto tex = create(img.width, img.height, TextureFormat::RGBA);
if (tex)
tex->set_data((unsigned char*)img.pixels);
return tex;
}
return TextureRef();
return create(Image(file));
}