From 9de25b0f37ba573f3b55aacb59c595a1493ad022 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Thu, 23 Nov 2017 16:18:10 +0100 Subject: [PATCH] Go back to using pointers instead of vectors. No need to incur that performance overhead. --- src/FlatLayerVisualisation.cpp | 14 +++++++------- src/FlatLayerVisualisation.hpp | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/FlatLayerVisualisation.cpp b/src/FlatLayerVisualisation.cpp index 1f9a9bd..3aabda9 100644 --- a/src/FlatLayerVisualisation.cpp +++ b/src/FlatLayerVisualisation.cpp @@ -22,15 +22,15 @@ static inline void computeColor(float intensity, float limit, float* destination FlatLayerVisualisation::FlatLayerVisualisation(const fmri::LayerData &layer) : faceCount(layer.numEntries() * 4), - vertexBuffer(faceCount * 3), - colorBuffer(faceCount * 3), - indexBuffer(faceCount * 3) + vertexBuffer(new float[faceCount * 3]), + colorBuffer(new float[faceCount * 3]), + indexBuffer(new int[faceCount * 3]) { auto& shape = layer.shape(); CHECK_EQ(shape.size(), 2) << "layer should be flat!" << endl; CHECK_EQ(shape[0], 1) << "Only single images supported." << endl; - const int limit = static_cast(layer.numEntries()); + const auto limit = (int) layer.numEntries(); auto data = layer.data(); const auto [minElem, maxElem] = minmax_element(data, data + limit); @@ -84,9 +84,9 @@ void FlatLayerVisualisation::render() glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.data()); - glColorPointer(3, GL_FLOAT, 0, colorBuffer.data()); - glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, indexBuffer.data()); + glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get()); + glColorPointer(3, GL_FLOAT, 0, colorBuffer.get()); + glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, indexBuffer.get()); glDisable(GL_VERTEX_ARRAY); glDisable(GL_COLOR_ARRAY); diff --git a/src/FlatLayerVisualisation.hpp b/src/FlatLayerVisualisation.hpp index 2d72e8e..8a03f90 100644 --- a/src/FlatLayerVisualisation.hpp +++ b/src/FlatLayerVisualisation.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "LayerData.hpp" #include "LayerVisualisation.hpp" @@ -16,8 +16,8 @@ namespace fmri private: std::size_t faceCount; - std::vector vertexBuffer; - std::vector colorBuffer; - std::vector indexBuffer; + std::unique_ptr vertexBuffer; + std::unique_ptr colorBuffer; + std::unique_ptr indexBuffer; }; }