Commit c8e9be1a authored by Robert Menzel's avatar Robert Menzel
Browse files

fixed texel setting/getting for byte textures

parent 65640d2d
......@@ -57,8 +57,8 @@ glm::vec4 TextureData::getTexel( glm::uvec2 _texCoord )
_texCoord.y = std::max( 0u, _texCoord.y );
// clamp values larger than the texture size to the maximum:
_texCoord.x = std::min( 0, getWidth() );
_texCoord.y = std::min( 0, getHeight() );
_texCoord.x = std::min( _texCoord.x, (unsigned int) getWidth() );
_texCoord.y = std::min( _texCoord.y, (unsigned int) getHeight() );
// the byte offset into pData of the desired texel:
size_t texelOffset = _texCoord.y * getBytesPerScanline();
......@@ -75,14 +75,14 @@ glm::vec4 TextureData::getTexel( glm::uvec2 _texCoord )
if ( getNumberOfChannels() > 3 ) result.a = data[3]/128.0f;
} else if ( mType == GL_UNSIGNED_BYTE ) {
GLshort *data = (GLshort *) (pData+texelOffset);
GLubyte *data = (GLubyte *) (pData+texelOffset);
result.r = data[0]/255.0f; // to 0..1
if ( getNumberOfChannels() > 1 ) result.g = data[1]/255.0f;
if ( getNumberOfChannels() > 2 ) result.b = data[2]/255.0f;
if ( getNumberOfChannels() > 3 ) result.a = data[3]/255.0f;
} else if ( mType == GL_SHORT ) {
GLubyte *data = (GLubyte *) (pData+texelOffset);
GLshort *data = (GLshort *) (pData+texelOffset);
result.r = data[0]/32768.0f; // to -1..1
if ( getNumberOfChannels() > 1 ) result.g = data[1]/32768.0f;
if ( getNumberOfChannels() > 2 ) result.b = data[2]/32768.0f;
......@@ -137,8 +137,8 @@ void TextureData::setTexel( glm::uvec2 _texCoord, glm::vec4 _color )
_texCoord.y = std::max( 0u, _texCoord.y );
// clamp values larger than the texture size to the maximum:
_texCoord.x = std::min( 0, getWidth() );
_texCoord.y = std::min( 0, getHeight() );
_texCoord.x = std::min( _texCoord.x, (unsigned int) getWidth() );
_texCoord.y = std::min( _texCoord.y, (unsigned int) getHeight() );
// the byte offset into pData of the desired texel:
size_t texelOffset = _texCoord.y * getBytesPerScanline();
......@@ -156,7 +156,7 @@ void TextureData::setTexel( glm::uvec2 _texCoord, glm::vec4 _color )
if ( getNumberOfChannels() > 3 ) data[3] = color.a;
} else if ( mType == GL_UNSIGNED_BYTE ) {
GLshort *data = (GLshort *) (pData+texelOffset);
GLubyte *data = (GLubyte *) (pData+texelOffset);
glm::ivec4 color = glm::ivec4( _color * glm::vec4(255.0f) );
color = glm::clamp( color, glm::ivec4(0), glm::ivec4(255) );
......@@ -167,7 +167,7 @@ void TextureData::setTexel( glm::uvec2 _texCoord, glm::vec4 _color )
if ( getNumberOfChannels() > 3 ) data[3] = color.a;
} else if ( mType == GL_SHORT ) {
GLubyte *data = (GLubyte *) (pData+texelOffset);
GLshort *data = (GLshort *) (pData+texelOffset);
glm::ivec4 color = glm::ivec4( _color * glm::vec4(32768.0f) );
color = glm::clamp( color, glm::ivec4(-32768), glm::ivec4(32767) );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment