Large refactor of texture loading.

In this new implementation, everything is loaded on a separate thread,
but the textures are initialized on the main OpenGL thread.

This is all to work around the fact that you cannot create a separate
GL context in GLUT.
This commit is contained in:
2018-04-12 16:52:09 +02:00
parent 30aa25a09e
commit 265bc61b98
14 changed files with 158 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <memory>
#include <GL/gl.h>
namespace fmri
@@ -13,19 +14,12 @@ namespace fmri
class Texture
{
public:
/**
* Allocate a new texture
*/
Texture() noexcept;
Texture(const float* data, int width, int height, GLuint format, int subImages = 1);
Texture(std::unique_ptr<float[]> &&data, int width, int height, GLuint format, int subImages = 1);
Texture(Texture &&) noexcept;
Texture(const Texture &) = delete;
/**
* Own an existing texture
* @param id original texture ID.
*/
explicit Texture(GLuint id) noexcept;
~Texture();
Texture &operator=(Texture &&) noexcept;
@@ -36,10 +30,19 @@ namespace fmri
* @param target valid target for glBindTexture.
*/
void bind(GLenum target) const;
void configure(GLenum target) const;
void configure(GLenum target);
private:
GLuint id;
int width;
int height;
GLuint format;
std::unique_ptr<float[]> data;
void ensureReference();
void preCalc(int subImages);
int getStride();
};
}