Improve convolutional layer rendering.

Now all n individual images of w×h are packaged as a w×(n×h) image, with
the texture coordinates properly mapped so the individual rectangles
still get the proper texture.

This optimization causes slight glitches around the edges of the tiles,
but is so much faster that I think it's worth it.
This commit is contained in:
2018-02-23 15:19:30 +01:00
parent d5dd49b3d6
commit 99cf0740fe
4 changed files with 33 additions and 25 deletions

View File

@@ -7,6 +7,7 @@
#include <chrono>
#include <thread>
#include "glutils.hpp"
#include "Range.hpp"
using namespace fmri;
using namespace std;
@@ -21,11 +22,21 @@ static void handleGLError(GLenum error) {
}
}
GLuint fmri::loadTexture(DType const *data, int width, int height)
static void rescaleSubImages(vector<float>& textureBuffer, int subImages) {
auto cur = textureBuffer.begin();
const auto increment = textureBuffer.size() / subImages;
while (cur != textureBuffer.end()) {
rescale(cur, cur + increment, 0, 1);
advance(cur, increment);
}
}
GLuint fmri::loadTexture(DType const *data, int width, int height, int subImages)
{
// Load and scale texture
vector<float> textureBuffer(data, data + (width * height));
rescale(textureBuffer.begin(), textureBuffer.end(), 0, 1);
rescaleSubImages(textureBuffer, subImages);
const float color[] = {1, 1, 1}; // Background color for textures.
GLuint texture;