spacebox/src/Texture.hpp

69 lines
2.0 KiB
C++
Raw Normal View History

/* /\ +--------------------------------------------------------------+
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - originally created at [http://nugget.fun] |
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+
[Texture.hpp]
The Texture class abstracts the file opening, data loading and binding steps of Open GL
texture creation. Currently it only supports loading GL_TEXTURE_2D with GL_RGB8 pixels
and automatic GL_NEAREST mipmapping. Support may be added for users to pass in their own
pixel data, to customize mipmapping, and more. The class can also be used in a custom
way by passing the Texture ID to GL functions instead of using the class's member
functions.
*/
2021-10-18 17:33:33 -04:00
#ifndef SB_TEXTURE_H_
#define SB_TEXTURE_H_
2021-10-18 17:33:33 -04:00
#include <sstream>
#include <stdexcept>
2021-10-02 19:21:07 -04:00
#include "glm/vec2.hpp"
#include "SDL.h"
#include "SDL_image.h"
#include "sdl2-gfx/SDL2_rotozoom.h"
#include "filesystem.hpp"
2021-09-24 02:43:38 -04:00
#include "GLObject.hpp"
2021-10-02 19:21:07 -04:00
#include "Log.hpp"
2021-10-18 17:33:33 -04:00
namespace sb
{
2021-10-18 17:33:33 -04:00
class Texture : public GLObject
{
private:
2021-09-24 02:43:38 -04:00
2021-10-18 17:33:33 -04:00
fs::path path = "";
2021-10-18 17:33:33 -04:00
public:
2021-10-18 17:33:33 -04:00
Texture();
Texture(fs::path);
void associate(fs::path);
void generate();
void generate(glm::vec2);
void load();
void load(fs::path);
void load(SDL_RWops*);
void load(SDL_Surface*);
void load(void*, GLenum = GL_RGBA, GLenum = GL_UNSIGNED_BYTE);
void load(void*, glm::vec2, GLenum = GL_RGBA, GLenum = GL_UNSIGNED_BYTE);
void bind() const override;
glm::vec2 size() const;
bool operator==(const Texture&) const;
2021-10-18 17:33:33 -04:00
};
2021-10-18 17:33:33 -04:00
void texture_deleter(GLuint*);
2021-10-18 17:33:33 -04:00
}
2021-09-24 02:43:38 -04:00
#endif