Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GL_BGRA format #3867

Closed
wants to merge 2 commits into from
Closed

Adds GL_BGRA format #3867

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 25, 2015

Makes possible to draw Cairo or other BGRA swizzled images without calling super expensive swapRgb function.

@tgfrerer
Copy link
Member

+1 =)

@@ -253,6 +255,8 @@ int ofGetGlTypeFromInternal(int glInternalFormat){

case GL_STENCIL_INDEX:
return GL_UNSIGNED_BYTE;
case GL_BGRA:
return GL_BGRA;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that should say GL_BGRA? i believe it should say GL_UNSIGNED_BYTE, in which case you could add it above next to GL_RGB etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Fixed!

@arturoc
Copy link
Member

arturoc commented May 25, 2015

The internal format of a texture can't be GL_BGRA only GL_RGBA: https://www.opengl.org/sdk/docs/man/html/glTexImage2D.xhtml.

Then you upload using tex.loadData(data,GL_BGRA) with the new ofPixels based on pixel format instead of number of channels this should be happening automatically already just by allocating the pixels as OF_PIXELS_BGRA

@arturoc arturoc closed this May 25, 2015
@arturoc
Copy link
Member

arturoc commented May 25, 2015

this: 70ab62c should fix it, now you can do tex.loadData(cairo.getImageSurfacePixels()) without specifying the format at all since the pixels already have the correct format. also when saving it'll avoid swapping the pixels twice as i think was doing before.

@ghost
Copy link
Author

ghost commented May 25, 2015

Then you upload using loadData(data,GL_BGRA) with the new ofPixels based on pixel format instead of number of channels this should be happening automatically already just by allocating the pixels as OF_PIXELS_BGRA

Ah, you're right! The trick was to allocate ofTexture as well:

  texture.allocate(w, h, GL_RGBA);
  buffer.allocate(w, h, OF_PIXELS_BGRA);

Don't know why, but explicitly allocating it as GL_RGBA fixes the render.

@ghost ghost deleted the gl-bgra branch May 25, 2015 18:58
@arturoc
Copy link
Member

arturoc commented May 25, 2015

yes the autoallocate in loadData is kind of handy for very basic things but as soon as you want to do something slightly different is not very reliable. it passes the format as internal which in lots of cases is not correct. i added a TODO some days ago to fix it by adding a function that guesses the internal from the format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants