I am doing university work for a game engine and we needed to do an agnostic code. They told us to do the rest on our own and I am on the right track however, when I try and pass the parameters for the function it says it doesn't pass for the arguments? This I believe is due to the class parameter that I have on there. Am I being an idiot or ?
Error: (without Buffer Layout) function arguments don't match. Or with the code you can see it says "Expected an expression"
Please help!
Vertex Buffer
/* \file OpenGLVertexBuffer.cpp */
#include "engine_pch.h"
#include <glad/glad.h>
#include "include/independent/platform/OpenGL/OpenGLVertexBuffer.h"
namespace Engine
{
void BufferLayout::addElement(BufferElement element)
{
m_elements.push_back(element);
calcStrideAndOffset();
}
void BufferLayout::calcStrideAndOffset()
{
uint32_t l_offset = 0;
for (auto& element : m_elements)
{
element.m_offset = l_offset;
l_offset += element.m_size;
}
m_stride = l_offset;
}
OpenGLVertexBuffer::OpenGLVertexBuffer(void * vertices, uint32_t size, BufferLayout layout) : m_layout(layout)
{
glCreateBuffers(1, &m_OpenGL_ID);
glBindBuffer(GL_ARRAY_BUFFER, m_OpenGL_ID);
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_DYNAMIC_DRAW);
}
OpenGLVertexBuffer::~OpenGLVertexBuffer()
{
glDeleteBuffers(1, &m_OpenGL_ID);
}
void OpenGLVertexBuffer::edit(void * vertices, uint32_t size, uint32_t offset)
{
glBindBuffer(GL_ARRAY_BUFFER, m_OpenGL_ID);
glBufferSubData(GL_ARRAY_BUFFER, offset, size, vertices);
}
}
Rendering API
/* \file renderAPI.cpp */
#include "engine_pch.h"
#include "rendering/RenderAPI.h"
#include "rendering/indexBuffer.h"
#include "rendering/vertexBuffer.h"
#include "platform/OpenGL/OpenGLIndexBuffer.h"
#include "platform/OpenGL/OpenGLVertexBuffer.h"
#include "systems/log.h"
namespace Engine
{
RenderAPI::API Engine::RenderAPI::s_API = RenderAPI::API::OpenGL;
IndexBuffer * IndexBuffer::create(uint32_t * indices, uint32_t count)
{
switch (RenderAPI::getAPI())
{
case RenderAPI::API::None:
Log::error("No supported Rendering API");
case RenderAPI::API::OpenGL:
return new OpenGLIndexBuffer(indices, count);
case RenderAPI::API::Direct3D:
Log::error("Direct3D not currently Supported!");
case RenderAPI::API::Vulkan:
Log::error("Vulkan not currently Supported!");
}
}
VertexBuffer * VertexBuffer::edit(void* vertices, uint32_t size, uint32_t offset)
{
switch (RenderAPI::getAPI())
{
case RenderAPI::API::None:
Log::error("No Supported Rendering API");
case RenderAPI::API::OpenGL:
//return new OpenGLVertexBuffer(vertices, sizeof(size), offset);
new OpenGLVertexBuffer(vertices, size, <BufferLayout> offset);
}
}
}