kick
|
00001 // 00002 // Created by morten on 31/05/14. 00003 // 00004 00005 #include "texture_cube.h" 00006 00007 00008 namespace kick { 00009 TextureCube::TextureCube(TextureSampler textureSampler) 00010 { 00011 glGenTextures(1, &mTextureid); 00012 setTextureSampler(textureSampler); 00013 } 00014 00015 TextureCube::TextureCube(TextureCube&& m) 00016 : mTextureid(m.mTextureid) 00017 { 00018 m.mTextureid = 0; 00019 } 00020 00021 TextureCube::~TextureCube(){ 00022 glDeleteTextures(1, &mTextureid); 00023 } 00024 00025 void TextureCube::bind(int textureSlot){ 00026 glActiveTexture(GL_TEXTURE0 + textureSlot); 00027 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureid); 00028 } 00029 00030 void TextureCube::setData(int width, int height, char* data, int cubemapIndex, const ImageFormat& imageFormat){ 00031 this->mWidth = width; 00032 this->mHeight = height; 00033 this->mImageFormat = imageFormat; 00034 GLint border = 0; // must be 0 00035 00036 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureid); 00037 00038 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+cubemapIndex, imageFormat.mipmapLevel, imageFormat.internalFormat, width, height/6, border, imageFormat.format, imageFormat.type, data); 00039 mFacesSet[cubemapIndex] = 1; 00040 if (mFacesSet.all() && imageFormat.mipmap != Mipmap::None){ 00041 glGenerateMipmap(GL_TEXTURE_CUBE_MAP); 00042 } 00043 } 00044 00045 void TextureCube::setTextureSampler(const TextureSampler & textureSampler){ 00046 this->mTextureSampler = textureSampler; 00047 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureid); 00048 00049 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, static_cast<GLint>(textureSampler.wrapS)); 00050 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, static_cast<GLint>(textureSampler.wrapT)); 00051 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(textureSampler.filterMag)); 00052 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(textureSampler.filterMin)); 00053 00054 } 00055 00056 TextureSampler TextureCube::textureSampler() const{ 00057 return mTextureSampler; 00058 } 00059 00060 ImageFormat TextureCube::imageFormat() const { 00061 return mImageFormat; 00062 } 00063 }