1234567891011121314151617181920212223242526272829303132333435 |
- #include "client/rendering/wrapper/Texture.h"
- Texture::Texture(Mode mode) : texture(0) {
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- switch(mode) {
- case NEAREST:
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- break;
- case LINEAR:
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- break;
- }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- }
- Texture::~Texture() {
- glDeleteTextures(1, &texture);
- }
- void Texture::setRGBAData(int width, int height, const u32* data) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
- }
- void Texture::setRGBFloatData(int width, int height, const float* data) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, data);
- }
- void Texture::bind(uint index) const {
- glActiveTexture(GL_TEXTURE0 + index);
- glBindTexture(GL_TEXTURE_2D, texture);
- }
|