This repository has been archived on 2019-09-17. You can view files and clone it, but cannot push or open issues or pull requests.
Files
research-project/src/fmri/Texture.hpp
Bert Peters 265bc61b98 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.
2018-04-12 16:52:09 +02:00

49 lines
1.1 KiB
C++

#pragma once
#include <memory>
#include <GL/gl.h>
namespace fmri
{
/**
* Simple owning Texture class.
*
* Encapsulates an OpenGL texture, and enables RAII for it. Copying
* is disallowed for this reason.
*/
class Texture
{
public:
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;
~Texture();
Texture &operator=(Texture &&) noexcept;
Texture &operator=(const Texture &) = delete;
/**
* Bind the owned texture to the given spot.
* @param target valid target for glBindTexture.
*/
void bind(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();
};
}