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