Restructure texture handling.

This commit is contained in:
2017-11-27 13:59:41 +01:00
parent 3231e078b3
commit a75a435bc5
2 changed files with 10 additions and 13 deletions

View File

@@ -17,24 +17,20 @@ MultiImageVisualisation::MultiImageVisualisation(const fmri::LayerData &layer)
CHECK_EQ(1, images) << "Only single input image is supported" << endl; CHECK_EQ(1, images) << "Only single input image is supported" << endl;
vertexBuffer = std::make_unique<float[]>(channels * 12);
auto dataPtr = layer.data();
for (auto i = 0; i < images; ++i) {
for (auto j = 0; j < channels; ++j) {
textureReferences[make_pair(i, j)] = loadTexture(dataPtr, width, height);
dataPtr += width * height;
}
}
int columns = sqrt(channels); int columns = sqrt(channels);
while (channels % columns) columns++; while (channels % columns) columns++;
int rows = channels / columns;
// Create the quads for the images. // Create the quads for the images.
int r = 0, c = 0; int r = 0, c = 0;
int v = 0; int v = 0;
vertexBuffer = std::make_unique<float[]>(channels * 12);
textureReferences.resize(channels);
auto dataPtr = layer.data();
for (int i = 0; i < channels; ++i) { for (int i = 0; i < channels; ++i) {
textureReferences[i] = loadTexture(dataPtr, width, height);
vertexBuffer[v++] = 0; vertexBuffer[v++] = 0;
vertexBuffer[v++] = 0 + 3 * r; vertexBuffer[v++] = 0 + 3 * r;
vertexBuffer[v++] = 0 - 3 * c; vertexBuffer[v++] = 0 - 3 * c;
@@ -55,13 +51,14 @@ MultiImageVisualisation::MultiImageVisualisation(const fmri::LayerData &layer)
c = 0; c = 0;
++r; ++r;
} }
dataPtr += width * height;
} }
} }
MultiImageVisualisation::~MultiImageVisualisation() MultiImageVisualisation::~MultiImageVisualisation()
{ {
for (auto entry : textureReferences) { for (auto entry : textureReferences) {
glDeleteTextures(0, &entry.second); glDeleteTextures(0, &entry);
} }
} }

View File

@@ -17,7 +17,7 @@ namespace fmri
void render() override; void render() override;
private: private:
std::map<std::pair<int, int>, GLuint> textureReferences; std::vector<GLuint> textureReferences;
std::unique_ptr<float[]> vertexBuffer; std::unique_ptr<float[]> vertexBuffer;
}; };
} }