12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "rendering/Texture.h"
- Texture::Texture(const TextureFormat& format, int maxMipMaps)
- : format(format), texture(GL::genTexture()), maxMipMaps(maxMipMaps) {
- setNearestFilter();
- setRepeatWrap();
- }
- Texture::Texture(int maxMipMaps)
- : Texture(TextureFormat::unknown(), maxMipMaps) {
- }
- Texture::~Texture() {
- GL::deleteTexture(texture);
- }
- void Texture::setFormat(const TextureFormat& tf) {
- format = tf;
- }
- void Texture::setNearestFilter() {
- bind();
- if(maxMipMaps > 0) {
- GL::setMipMapNearFilter2D();
- } else {
- GL::setNearFilter2D();
- }
- }
- void Texture::setLinearFilter() {
- bind();
- if(maxMipMaps > 0) {
- GL::setMipMapLinearFilter2D();
- } else {
- GL::setLinearFilter2D();
- }
- }
- void Texture::setRepeatWrap() {
- bind();
- GL::setRepeatWrap2D();
- }
- void Texture::setClampWrap() {
- bind();
- GL::setClampWrap2D();
- }
- void Texture::setData(int width, int height, const void* data) {
- bind();
- GL::texImage2D(format.format, width, height, data);
- if(maxMipMaps > 0) {
- GL::generateMipmap2D(maxMipMaps);
- }
- }
- void Texture::bind() const {
- GL::bindTexture2D(texture);
- }
- void Texture::bindTo(int index) const {
- GL::activeTexture(index);
- bind();
- }
|