Cloudef / wlc

High-level Wayland compositor library
MIT License
330 stars 58 forks source link

write_pixels color format #142

Open crondog opened 8 years ago

crondog commented 8 years ago

So after doing https://github.com/Cloudef/wlc/pull/141 I have noticed that the border color which is being drawn by sway is rendered incorrectly. Sway is sending the colors in rgba format for everything however only the borders are drawn incorrectly. For some reason write_pixels is using bgra even though GL_RGBA is used. When I change format_map to GL_BGRA_EXT it works but doesn't seem right. I am out of ideas on how to fix it properly. I am still quite bad at opengl. Any ideas?

Cloudef commented 8 years ago

The reason is that the pixels are written as uint32 per pixel, so in little endian it's reversed.

crondog commented 8 years ago

If that is the case then why are there no problems when using swaybar. They both use the same code https://github.com/SirCmpwn/sway/blob/master/wayland/cairo.c#L3 https://github.com/SirCmpwn/sway/blob/window-borders/sway/render.c#L8

Cloudef commented 8 years ago

But does swaybar render directly inside wlc? AFAIK It's separate process and doesn't probably even draw using opengl?

crondog commented 8 years ago

Ah no it doesn't. Ok ill try and sort something out

mikkeloscar commented 8 years ago

This does not work: https://github.com/SirCmpwn/sway/commit/7dc335bb46451ce984cb89bb7ed45ca932b2324d#commitcomment-16679816

I get:

[main.c:39] [wlc] gles2: function write_pixels at line 808: glTexSubImage2D(0x0DE1, 0, g.origin.x, g.origin.y, g.size.w, g.size.h, format_map[format].format, format_map[format].type, data) == GL_INVALID_OPERATION

So I assume GL_UNSIGNED_INT is not supported.

It seems like all the cairo formats are native endian, so I'm not sure how to do it without depending on endianness at some point in the conversion, unless gles supports it some other way than above.

Cloudef commented 8 years ago

GL_UNSIGNED_INT is not supported in GLES2

Cloudef commented 8 years ago

You could look at cairo's gl implementation, but what I looked the things they do are not pretty :)

ddevault commented 8 years ago

I was operating under the assumption that it'd be okay to use the wrong endianness and just fix it by writing the wrong endianness in sway and looking the other way.