'Assets', some refactor

This commit is contained in:
MihailRis
2022-03-03 18:14:34 +03:00
committed by GitHub
parent b7e8ff5bea
commit 2aba3e91db
19 changed files with 350 additions and 213 deletions
+18
View File
@@ -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;
}
+27
View File
@@ -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_ */
+6 -1
View File
@@ -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;