'Assets', some refactor
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#include "Batch2D.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
Batch2D::Batch2D(size_t capacity) : capacity(capacity),
|
||||
offset(0),
|
||||
color(1.0f, 1.0f, 1.0f, 1.0f){
|
||||
const int attrs[] = {
|
||||
2, 2, 4, 0 //null terminator
|
||||
};
|
||||
|
||||
buffer = new float[capacity];
|
||||
mesh = new Mesh(nullptr, 0, attrs);
|
||||
}
|
||||
|
||||
Batch2D::~Batch2D(){
|
||||
delete buffer;
|
||||
delete mesh;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef SRC_GRAPHICS_BATCH2D_H_
|
||||
#define SRC_GRAPHICS_BATCH2D_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Mesh;
|
||||
|
||||
class Batch2D {
|
||||
float* buffer;
|
||||
size_t capacity;
|
||||
size_t offset;
|
||||
glm::vec4 color;
|
||||
Mesh* mesh;
|
||||
|
||||
void vertex(float x, float y,
|
||||
float u, float v,
|
||||
float r, float g, float b, float a);
|
||||
public:
|
||||
Batch2D(size_t capacity);
|
||||
~Batch2D();
|
||||
|
||||
void rect(float x, float y, float w, float h);
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif /* SRC_GRAPHICS_BATCH2D_H_ */
|
||||
@@ -12,7 +12,12 @@ Mesh::Mesh(const float* buffer, size_t vertices, const int* attrs) : vertices(ve
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertexSize * vertices, buffer, GL_STATIC_DRAW);
|
||||
if (buffer){
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertexSize * vertices, buffer, GL_STATIC_DRAW);
|
||||
} else {
|
||||
glBufferData(GL_ARRAY_BUFFER, 0, {}, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
|
||||
// attributes
|
||||
int offset = 0;
|
||||
|
||||
Reference in New Issue
Block a user