Go back to using pointers instead of vectors.

No need to incur that performance overhead.
This commit is contained in:
2017-11-23 16:18:10 +01:00
parent 44f467c81c
commit 9de25b0f37
2 changed files with 11 additions and 11 deletions

View File

@@ -22,15 +22,15 @@ static inline void computeColor(float intensity, float limit, float* destination
FlatLayerVisualisation::FlatLayerVisualisation(const fmri::LayerData &layer) : FlatLayerVisualisation::FlatLayerVisualisation(const fmri::LayerData &layer) :
faceCount(layer.numEntries() * 4), faceCount(layer.numEntries() * 4),
vertexBuffer(faceCount * 3), vertexBuffer(new float[faceCount * 3]),
colorBuffer(faceCount * 3), colorBuffer(new float[faceCount * 3]),
indexBuffer(faceCount * 3) indexBuffer(new int[faceCount * 3])
{ {
auto& shape = layer.shape(); auto& shape = layer.shape();
CHECK_EQ(shape.size(), 2) << "layer should be flat!" << endl; CHECK_EQ(shape.size(), 2) << "layer should be flat!" << endl;
CHECK_EQ(shape[0], 1) << "Only single images supported." << endl; CHECK_EQ(shape[0], 1) << "Only single images supported." << endl;
const int limit = static_cast<const int>(layer.numEntries()); const auto limit = (int) layer.numEntries();
auto data = layer.data(); auto data = layer.data();
const auto [minElem, maxElem] = minmax_element(data, data + limit); const auto [minElem, maxElem] = minmax_element(data, data + limit);
@@ -84,9 +84,9 @@ void FlatLayerVisualisation::render()
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.data()); glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
glColorPointer(3, GL_FLOAT, 0, colorBuffer.data()); glColorPointer(3, GL_FLOAT, 0, colorBuffer.get());
glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, indexBuffer.data()); glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, indexBuffer.get());
glDisable(GL_VERTEX_ARRAY); glDisable(GL_VERTEX_ARRAY);
glDisable(GL_COLOR_ARRAY); glDisable(GL_COLOR_ARRAY);

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <vector> #include <memory>
#include "LayerData.hpp" #include "LayerData.hpp"
#include "LayerVisualisation.hpp" #include "LayerVisualisation.hpp"
@@ -16,8 +16,8 @@ namespace fmri
private: private:
std::size_t faceCount; std::size_t faceCount;
std::vector<float> vertexBuffer; std::unique_ptr<float[]> vertexBuffer;
std::vector<float> colorBuffer; std::unique_ptr<float[]> colorBuffer;
std::vector<int> indexBuffer; std::unique_ptr<int[]> indexBuffer;
}; };
} }