1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "rendering/Texture.h"
- Texture::Texture()
- : format(TextureFormat::unknown()), texture(0), maxMipMaps(0) {
- }
- Texture::~Texture() {
- GL::deleteTexture(texture);
- }
- void Texture::init(const TextureFormat& format, int maxMipMaps) {
- if(texture != 0) {
- return;
- }
- Texture::format = format;
- Texture::maxMipMaps = maxMipMaps;
- texture = GL::genTexture();
- setNearestFilter();
- setRepeatWrap();
- }
- 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();
- }
|