110 lines
3.1 KiB
C++
110 lines
3.1 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2020 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_GRAPHICS_TEXTURE_HPP
|
|
#define OUR_DICK_GRAPHICS_TEXTURE_HPP
|
|
|
|
#include "image.hpp"
|
|
#include "gl_include.hpp"
|
|
|
|
namespace gfx{
|
|
|
|
//class representing an opengl 2D texture
|
|
class texture
|
|
{
|
|
public:
|
|
//all available wrapping styles as a strongly typed enum
|
|
enum class wrap : GLint{
|
|
CLAMP_EDGE = GL_CLAMP_TO_EDGE,
|
|
CLAMP_BORDER = GL_CLAMP_TO_BORDER,
|
|
MIRROR_REPEAT = GL_MIRRORED_REPEAT,
|
|
REPEAT = GL_REPEAT,
|
|
MIRROR_CLAMP_EDGE = GL_MIRROR_CLAMP_TO_EDGE,
|
|
};
|
|
//all available minfilter styles as a strongly typed enum
|
|
enum class minfilter : GLint{
|
|
NEAREST = GL_NEAREST,
|
|
LINEAR = GL_LINEAR,
|
|
NMIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
|
|
LMIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
|
|
NMIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
|
|
LMIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
|
|
};
|
|
//all available magfilter styles as a strongly typed enum
|
|
enum class magfilter : GLint{
|
|
NEAREST = GL_NEAREST,
|
|
LINEAR = GL_LINEAR,
|
|
};
|
|
private:
|
|
GLuint m_tex_id = 0; //handle to texture object
|
|
int m_width = 0;
|
|
int m_height = 0;
|
|
|
|
public:
|
|
//create the texture with no image data
|
|
texture();
|
|
texture(GLenum format, GLsizei w, GLsizei h, GLenum type);
|
|
//create the texture with image data from 'i'
|
|
texture(const image& i);
|
|
//TODO image data from raw unsigned char array
|
|
texture(const texture&) = delete;
|
|
texture(texture&&);
|
|
~texture();
|
|
|
|
texture& operator=(const texture&) = delete;
|
|
texture& operator=(texture&&);
|
|
|
|
GLuint raw()const;
|
|
|
|
//overwrite the current image data with 'i'
|
|
bool set_image(const image& i);
|
|
void resize(GLenum format, GLsizei w, GLsizei h, GLenum type);
|
|
|
|
//set the size of the texture, will wrap the image according to the chosen wrap mode
|
|
void set_width(int w);
|
|
void set_height(int h);
|
|
void set_size(int w, int h);
|
|
|
|
//change wrap mode for both x and y
|
|
void set_wrap_mode(wrap w);
|
|
void set_wrap_mode(wrap w, wrap h);
|
|
//change wrap mode for one direction
|
|
void set_wrap_x(wrap w);
|
|
void set_wrap_y(wrap h);
|
|
|
|
void set_border_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a = 1.0f);
|
|
void set_filter(minfilter min, magfilter mag);
|
|
void set_mag_filter(magfilter m);
|
|
void set_min_filter(minfilter m);
|
|
|
|
int get_width()const;
|
|
int get_height()const;
|
|
|
|
//release ownership of this texture object
|
|
GLuint release();
|
|
|
|
//bind to GL_TEXTURE_2D
|
|
void bind()const;
|
|
//bind to given texture unit and load into given program uniform location
|
|
void bind_unit(GLuint tunit)const;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|