mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 07:21:51 +00:00
fix graphics settings & reduce extra GL calls
This commit is contained in:
parent
25ce4a5077
commit
5b868ae857
7 changed files with 22 additions and 16 deletions
|
|
@ -372,7 +372,7 @@ void Batch2D::sprite(
|
||||||
void Batch2D::flush() {
|
void Batch2D::flush() {
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
return;
|
return;
|
||||||
mesh->reload(buffer.get(), index);
|
mesh->reload(buffer.get(), index, true);
|
||||||
mesh->draw(gl::to_glenum(primitive));
|
mesh->draw(gl::to_glenum(primitive));
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -292,13 +292,13 @@ void Batch3D::point(const glm::vec3& coord, const glm::vec4& tint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch3D::flush() {
|
void Batch3D::flush() {
|
||||||
mesh->reload(buffer.get(), index);
|
mesh->reload(buffer.get(), index, true);
|
||||||
mesh->draw();
|
mesh->draw();
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch3D::flushPoints() {
|
void Batch3D::flushPoints() {
|
||||||
mesh->reload(buffer.get(), index);
|
mesh->reload(buffer.get(), index, true);
|
||||||
mesh->draw(GL_POINTS);
|
mesh->draw(GL_POINTS);
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ void LineBatch::box(float x, float y, float z, float w, float h, float d,
|
||||||
void LineBatch::flush(){
|
void LineBatch::flush(){
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
return;
|
return;
|
||||||
mesh->reload(buffer.get(), index);
|
mesh->reload(buffer.get(), index, true);
|
||||||
mesh->draw(GL_LINES);
|
mesh->draw(GL_LINES);
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,15 @@ public:
|
||||||
void reload(
|
void reload(
|
||||||
const VertexStructure* vertexBuffer,
|
const VertexStructure* vertexBuffer,
|
||||||
size_t vertexCount,
|
size_t vertexCount,
|
||||||
const std::vector<IndexBufferData>& indices
|
const std::vector<IndexBufferData>& indices,
|
||||||
|
bool streaming
|
||||||
);
|
);
|
||||||
|
|
||||||
void reload(const VertexStructure* vertexBuffer, size_t vertexCount) {
|
void reload(
|
||||||
|
const VertexStructure* vertexBuffer, size_t vertexCount, bool streaming
|
||||||
|
) {
|
||||||
static const std::vector<IndexBufferData> indices {};
|
static const std::vector<IndexBufferData> indices {};
|
||||||
reload(vertexBuffer, vertexCount, indices);
|
reload(vertexBuffer, vertexCount, indices, streaming);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Draw mesh with specified primitives type
|
/// @brief Draw mesh with specified primitives type
|
||||||
|
|
@ -61,6 +64,8 @@ public:
|
||||||
|
|
||||||
/// @brief Draw mesh as triangles
|
/// @brief Draw mesh as triangles
|
||||||
void draw() const;
|
void draw() const;
|
||||||
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "graphics/core/Mesh.inl"
|
#include "graphics/core/Mesh.inl"
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ Mesh<VertexStructure>::Mesh(
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
glGenBuffers(1, &vbo);
|
glGenBuffers(1, &vbo);
|
||||||
|
|
||||||
reload(vertexBuffer, vertices, std::move(indices));
|
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
|
reload(vertexBuffer, vertices, std::move(indices), false);
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (int i = 0; attrs[i].count; i++) {
|
for (int i = 0; attrs[i].count; i++) {
|
||||||
|
|
@ -82,20 +82,22 @@ template <typename VertexStructure>
|
||||||
void Mesh<VertexStructure>::reload(
|
void Mesh<VertexStructure>::reload(
|
||||||
const VertexStructure* vertexBuffer,
|
const VertexStructure* vertexBuffer,
|
||||||
size_t vertexCount,
|
size_t vertexCount,
|
||||||
const std::vector<IndexBufferData>& indices
|
const std::vector<IndexBufferData>& indices,
|
||||||
|
bool streaming
|
||||||
) {
|
) {
|
||||||
this->vertexCount = vertexCount;
|
this->vertexCount = vertexCount;
|
||||||
glBindVertexArray(vao);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
if (vertexBuffer != nullptr && vertexCount != 0) {
|
if (vertexBuffer != nullptr && vertexCount != 0) {
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
vertexCount * sizeof(VertexStructure),
|
vertexCount * sizeof(VertexStructure),
|
||||||
vertexBuffer,
|
vertexBuffer,
|
||||||
GL_STREAM_DRAW
|
streaming ? GL_STREAM_DRAW : GL_STATIC_DRAW
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
glBufferData(GL_ARRAY_BUFFER, 0, {}, GL_STREAM_DRAW);
|
glBufferData(
|
||||||
|
GL_ARRAY_BUFFER, 0, {}, streaming ? GL_STREAM_DRAW : GL_STATIC_DRAW
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < ibos.size(); i++) {
|
for (int i = 0; i < ibos.size(); i++) {
|
||||||
|
|
@ -116,7 +118,6 @@ void Mesh<VertexStructure>::reload(
|
||||||
GL_STATIC_DRAW
|
GL_STATIC_DRAW
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexStructure>
|
template <typename VertexStructure>
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void MainBatch::flush() {
|
||||||
texture = blank.get();
|
texture = blank.get();
|
||||||
}
|
}
|
||||||
texture->bind();
|
texture->bind();
|
||||||
mesh->reload(buffer.get(), index);
|
mesh->reload(buffer.get(), index, true);
|
||||||
mesh->draw();
|
mesh->draw();
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ private:
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool lightsDebug = false;
|
bool lightsDebug = false;
|
||||||
bool gbufferPipeline = false;
|
bool gbufferPipeline = false;
|
||||||
bool dirtySettings = false;
|
bool dirtySettings = true;
|
||||||
|
|
||||||
/// @brief Render block selection lines
|
/// @brief Render block selection lines
|
||||||
void renderBlockSelection();
|
void renderBlockSelection();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue