Skip to content

Commit

Permalink
BREAKING CHANGE: Texture::initialize substituted by generic method with
Browse files Browse the repository at this point in the history
better control over texture and channel format. Old code specifying format using
GL_ values will need to be converted.
  • Loading branch information
febret committed Apr 6, 2015
1 parent 8468f0f commit 473e17e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/text2texture/StringTextureSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void StringTextureSource::refreshTexture(Texture* texture, const DrawContext& co
DrawInterface* di = context.renderer->getRenderer();

// Initialize the texture and render target (if needed)
if(!texture->isInitialized()) texture->initialize(textSize[0], textSize[1], GL_RGBA);
if(!texture->isInitialized()) texture->initialize(textSize[0], textSize[1]);
if(myRenderTarget == NULL)
{
myRenderTarget = context.renderer->createRenderTarget(RenderTarget::RenderToTexture);
Expand Down
12 changes: 6 additions & 6 deletions include/omega/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ namespace omega
//! Channel format
enum ChannelFormat {
FormatUInt,
FormatUByte
FormatUByte,
FormatFloat
};

public:
//! Initializes this texture object
//! @param format - a pixel format such as GL_RGB, GL_RGBA, etc.
void initialize(int width, int height, uint format = 0);

//! Initializes this texture object using a specific texture type,
//! channel type and channel format.
void initialize(int width, int height, TextureType tt, ChannelType ct, ChannelFormat cf);
void initialize(int width, int height,
TextureType tt = Type2D,
ChannelType ct = ChannelRGBA,
ChannelFormat cf = FormatUByte);

bool isInitialized() { return myInitialized; }

Expand Down
64 changes: 44 additions & 20 deletions src/omega/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,59 @@ Texture::Texture(GpuContext* context):
///////////////////////////////////////////////////////////////////////////////
void Texture::initialize(int width, int height, TextureType tt, ChannelType ct, ChannelFormat cf)
{

}

///////////////////////////////////////////////////////////////////////////////
void Texture::initialize(int width, int height, uint format)
{
myWidth = width;
myHeight = height;
myWidth = width;
myHeight = height;

myGlFormat = GL_RGBA;
if(format != 0)
switch(ct)
{
myGlFormat = format;
case ChannelRGB:
myGlFormat = GL_RGB;
break;
case ChannelRGBA:
myGlFormat = GL_RGBA;
break;
case ChannelDepth:
myGlFormat = GL_DEPTH_COMPONENT;
break;
}
myChannelType = ct;

//Now generate the OpenGL texture object
glGenTextures(1, &myId);
glBindTexture(GL_TEXTURE_2D, myId);
if(myGlFormat == GL_DEPTH_COMPONENT)
uint textureType;
switch(tt)
{
glTexImage2D(GL_TEXTURE_2D, 0, myGlFormat, myWidth, myHeight, 0, myGlFormat, GL_FLOAT, NULL);
case Type2D:
textureType = GL_TEXTURE_2D;
break;
case TypeRectangle:
textureType = GL_TEXTURE_RECTANGLE;
break;
}
else
myTextureType = tt;

uint channelFormat;
switch(cf)
{
glTexImage2D(GL_TEXTURE_2D, 0, myGlFormat, myWidth, myHeight, 0, myGlFormat, GL_UNSIGNED_BYTE, NULL);
case FormatFloat:
channelFormat = GL_FLOAT;
break;
case FormatUInt:
channelFormat = GL_UNSIGNED_INT;
break;
case FormatUByte:
channelFormat = GL_UNSIGNED_BYTE;
break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

myChannelFormat = cf;

//Now generate the OpenGL texture object
glGenTextures(1, &myId);
glBindTexture(textureType, myId);
glTexImage2D(textureType, 0, myGlFormat, myWidth, myHeight, 0, myGlFormat, channelFormat, NULL);

glTexParameteri(textureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(textureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if(sUsePbo)
{
glGenBuffers(1, &myPboId);
Expand Down

0 comments on commit 473e17e

Please sign in to comment.