Permalink
Browse files

Vertex Format Reset Optimization (#1372)

Clear the current vertex format on begin instead of calling the default constructor to avoid reallocating its flags vector and speed up vertex format declaring.
  • Loading branch information...
RobertBColton committed Aug 29, 2018
1 parent 92ccfca commit 8876f6141c575b7ee45dab3adea1fccfb7688331
@@ -41,7 +41,7 @@ std::unordered_map<size_t, int> vertexFormatCache;

// current vertex format being specified
// NOTE: this is not reset until the next vertex_format_begin
// NOTE: this uses the stack until vertex_format_end to speed up creation
// NOTE: this has static storage duration to avoid reallocation overhead (e.g, new is slow)
enigma::VertexFormat currentVertexFormat;

#define RESOURCE_EXISTS(id, container) return (id >= 0 && (unsigned)id < enigma::container.size() && enigma::container[id] != nullptr);
@@ -59,7 +59,10 @@ vector<IndexBuffer*> indexBuffers;
namespace enigma_user {

void vertex_format_begin() {
currentVertexFormat = enigma::VertexFormat();
// resetting the current vertex format this way is faster
// than simply calling the default constructor because we
// avoid reallocating the flags vector this way
currentVertexFormat.Clear();
}

unsigned vertex_format_get_hash() {
@@ -55,6 +55,11 @@ struct VertexFormat {

VertexFormat(): stride(0), stride_size(0), hash(0) {}

void Clear() {
hash = stride = stride_size = 0;
flags.clear();
}

void AddAttribute(int type, int attribute) {
using namespace enigma_user;

0 comments on commit 8876f61

Please sign in to comment.