123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "wrapper/Texture.h"
- Texture::Texture(const TextureFormat& format) : format(format), texture(0) {
- glGenTextures(1, &texture);
- setNearestFilter();
- setRepeatWrap();
- }
- Texture::Texture() : Texture(TextureFormat::unknown()) {
- }
- Texture::~Texture() {
- glDeleteTextures(1, &texture);
- }
- void Texture::setFormat(const TextureFormat& tf) {
- format = tf;
- }
- void Texture::setFilter(GLint param) {
- bind();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
- }
- void Texture::setNearestFilter() {
- setFilter(GL_NEAREST);
- }
- void Texture::setLinearFilter() {
- setFilter(GL_LINEAR);
- }
- void Texture::setWrap(GLint param) {
- bind();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param);
- }
- void Texture::setRepeatWrap() {
- setWrap(GL_REPEAT);
- }
- void Texture::setClampWrap() {
- setWrap(GL_CLAMP_TO_EDGE);
- }
- void Texture::setData(int width, int height, const void* data) {
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexImage2D(GL_TEXTURE_2D, 0, format.internalformat, width, height, 0, format.format, format.type, data);
- }
- void Texture::bind() const {
- glBindTexture(GL_TEXTURE_2D, texture);
- }
- void Texture::bindTo(int index) const {
- glActiveTexture(GL_TEXTURE0 + index);
- bind();
- }
|