parent
52eb549715
commit
e74ba8594b
@ -0,0 +1,21 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - frame_buffer.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/13 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/13 (y/m/d)
|
||||||
|
* Description - OpenGL Frame buffer object
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LUNARIUM_FRAME_BUFFER_H_
|
||||||
|
#define LUNARIUM_FRAME_BUFFER_H_
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class FrameBuffer
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LUNARIUM_FRAME_BUFFER_H_
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - render_context.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/13 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/13 (y/m/d)
|
||||||
|
* Description - General setup/shutdown for the render system
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LUNARIUM_RENDER_CONTEXT_H_
|
||||||
|
#define LUNARIUM_RENDER_CONTEXT_H_
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class Window;
|
||||||
|
|
||||||
|
// NOTE:
|
||||||
|
// This class will probably not be exposed outside of the Core
|
||||||
|
// The Core will expose Renderer2D instead
|
||||||
|
class RenderContext
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Window* mpWindow;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LUNARIUM_RENDER_CONTEXT_H_
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - renderer2D.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/13 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/13 (y/m/d)
|
||||||
|
* Description - The main 2D render class
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LUNARIUM_RENDERER_2D_H_
|
||||||
|
#define LUNARIUM_RENDERER_2D_H_
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class Renderer2D
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LUNARIUM_RENDERER_2D_H_
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - vertex_buffer.cpp
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/13 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/13 (y/m/d)
|
||||||
|
* Description - OpenGL vertex buffer object
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "vertex_buffer.h"
|
||||||
|
#include <glad/gl.h>
|
||||||
|
|
||||||
|
#include <utils/logger.h>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
VertexBuffer::VertexBuffer(LayoutType ltype, const void* vertices, u32 size)
|
||||||
|
: mLayoutType(ltype), mSize(size), mIndex(0), mIsStatic(true)
|
||||||
|
{
|
||||||
|
glGenVertexArrays(1, &mVAO);
|
||||||
|
glGenBuffers(1, &mVBO);
|
||||||
|
|
||||||
|
Bind();
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
InitLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
VertexBuffer::VertexBuffer(LayoutType ltype, u32 size)
|
||||||
|
: mLayoutType(ltype), mSize(size), mIndex(0), mIsStatic(false)
|
||||||
|
{
|
||||||
|
glGenVertexArrays(1, &mVAO);
|
||||||
|
glGenBuffers(1, &mVBO);
|
||||||
|
|
||||||
|
Bind();
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
InitLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VertexBuffer::Bind()
|
||||||
|
{
|
||||||
|
glBindVertexArray(mVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, mVBO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VertexBuffer::Unbind()
|
||||||
|
{
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VertexBuffer::PushVertices(const void* vertices, u32 size)
|
||||||
|
{
|
||||||
|
if (mIsStatic)
|
||||||
|
{
|
||||||
|
Logger::Warn(LogCategory::GRAPHICS, "Cannot push vertices into a static buffer!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mIndex + size >= mSize)
|
||||||
|
{
|
||||||
|
// Vertices do not fit into the buffer
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add verts to the buffer
|
||||||
|
Bind();
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, mIndex, size, vertices);
|
||||||
|
Unbind();
|
||||||
|
|
||||||
|
mIndex += size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
// HELPER METHODS
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void VertexBuffer::InitLayout()
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (mLayoutType)
|
||||||
|
{
|
||||||
|
case LayoutType::LINE:
|
||||||
|
{
|
||||||
|
Logger::Error(LogCategory::GRAPHICS, "Vertex layout type LINE not supported yet!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LayoutType::QUAD:
|
||||||
|
{
|
||||||
|
// position
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 10 * sizeof(GLfloat), (GLvoid*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
// Texture coords
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 10 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
// Color
|
||||||
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 10 * sizeof(GLfloat), (GLvoid*)(5 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
|
||||||
|
// Texture sampler index
|
||||||
|
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 10 * sizeof(GLfloat), (GLvoid*)(9 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LayoutType::SPRITE:
|
||||||
|
{
|
||||||
|
Logger::Error(LogCategory::GRAPHICS, "Vertex layout type SPRITE not supported yet!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Logger::Warn(LogCategory::GRAPHICS, "UNKNOWN Vertex Layout Type: %d", mLayoutType);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - vertex_buffer.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/13 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/13 (y/m/d)
|
||||||
|
* Description - OpenGL vertex buffer object
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LUNARIUM_VERTEX_BUFFER_H_
|
||||||
|
#define LUNARIUM_VERTEX_BUFFER_H_
|
||||||
|
|
||||||
|
#include <core/common_defs.h>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
// For now this class will also contain the VAO for the buffer
|
||||||
|
class VertexBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum LayoutType
|
||||||
|
{
|
||||||
|
LINE,
|
||||||
|
QUAD,
|
||||||
|
SPRITE,
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
VertexBuffer(LayoutType ltype, const void* vertices, u32 size);
|
||||||
|
VertexBuffer(LayoutType ltype, u32 size);
|
||||||
|
|
||||||
|
void Bind();
|
||||||
|
void Unbind();
|
||||||
|
|
||||||
|
// Returns false if the data does not fit in the buffer
|
||||||
|
bool PushVertices(const void* vertices, u32 size);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
LayoutType mLayoutType;
|
||||||
|
bool mIsStatic;
|
||||||
|
u32 mVAO;
|
||||||
|
u32 mVBO;
|
||||||
|
u32 mSize;
|
||||||
|
u32 mIndex; // The next spot to push data into for a dynamic buffer
|
||||||
|
|
||||||
|
private: // HELPER METHODS
|
||||||
|
|
||||||
|
void InitLayout();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LUNARIUM_VERTEX_BUFFER_H_
|
||||||
Loading…
Reference in New Issue