-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[rcore] Issue with texture with transparency when using open gl es2.0 (google angle) on macos #3179
Comments
Does the same happen if you set a BlendMode? E.g.:
|
@ubkp no it does not help It looks like it is a RGB vs sRGB buffer issue vs blending issue, according to this thread I have no idea how to fix it yet |
@ypujante Please, could you try using different alpha premultiply modes: BeginDrawing();
ClearBackground(BLACK);
BeginBlendMode(BLEND_MULTIPLIED); // Try also with BLEND_ALPHA_PREMULTIPLY
DrawRectangle(10, 10, 100, 100, ImGuiCol_FrameBg);
EndBlendMode();
EndDrawing(); |
@ypujante Just finished reading the thread you shared and it seems the issue could be in the ANGLE implementation, did you try building it for web platform? It is supposed to also use ANGLE backend, despite the WebGL implementation, just to confirm the isssue is due to ANGLE. |
@raysan5 I did try with pretty much every blend mode possible and none of them fixed the problem In my latest attempts (described in the thread you mention) I did have a (minor) breakthrough if I add the hint But now there is a frame rate issue which, even in unlocked mode, seems to be very low (but not below 60fps). Something seems very odd (if it was purely a performance issue why would it stick to 60fps...) I am going to research this further as I just encountered this problem. But if that leads nowhere then I will go down one more layer into the Angle library. I have been trying to avoid this as much as possible since it requires installing build tools and others to compile (not a cmake based library...) and it is pretty daunting... |
Yeah, I read it, that's very strange... but actually, it's stranger the severe performance hit!
Please, don't... it could be a real rabbit-hole of despair, I think it does not worth it... |
@raysan5 I did go down the rabbit hole :) Compiling the library is actually not that bad. It is the debugging/stepping in the code that is a challenge... until I figured out how to do it with CLion... That being said, after many hours of more investigating, I have compiled my findings which I have posted on the Angle forum. I don't have a solution yet, but still investigating. If you feel like you want to close this issue, it's ok. I will still post what I come with either way. At this stage I am pretty convinced that it is not a raylib issue. Finding the glfw hint really was the significant breakthrough that forced using metal and was clearly completely misunderstood by the article I had read on how to use Angle on macOS (the internet....), since they were using the non metal implementation in the end (which is really fast but renders wrong with alpha). |
@ypujante Wow! Thanks for reporting! I'll keep this issue open for a while, I'm curious about the cause of this issue. Also, did you try this example with a Rapsberry Pi for I would also recommend giving a try to |
No I did not get a chance to try with a different platform. How would I go about trying |
Actually it's quite straight forward, raylib examples Makefile comes preconfigured for it, but I can try it right now because I already have the environment setup (basically, emscripten installed). In any case, here some detailed instructions: https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5) Results in some minutes... |
@ypujante Just updated the previous comment, for some reason yesterday I was not able to uplaod images... It seems that WebGL backend results are the expected ones (afaik, internally it uses ANGLE, most probably mapped to Direct3D). |
@raysan5 Thank you very much for running this test. And of course the result is exactly as expected with the proper color... I am getting more and more convinced that there is an issue with Angle when using the gl/clg renderer (ANGLE (Apple, Apple M2 Max, OpenGL 4.1 Metal - 83.1)). I think I reached a conclusion for my project which I will share soon after I collect more data. |
In order to get a feeling of what is really going on with the various limitations I ran a benchmark on my machine. The benchmark code is the following: // glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, GLFW_ANGLE_PLATFORM_TYPE_METAL);
std::random_device rd; // a seed source for the random number engine
std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()
std::uniform_int_distribution<> random_color(64, 255);
std::uniform_int_distribution<> random_x(0, 700);
std::uniform_int_distribution<> random_y(0, 350);
constexpr int N = 100000;
InitWindow(800, 450, "raylib issue");
// SetTargetFPS(60);
glfwSwapInterval(0);
long frame = 0;
auto begin = std::chrono::steady_clock::now();
while(!WindowShouldClose())
{
frame++;
BeginDrawing();
ClearBackground(BLACK);
for(int i = 0; i < N; i++)
DrawRectangle(random_x(gen), random_y(gen), 100, 100, Color{(unsigned char) random_color(gen), (unsigned char) random_color(gen), (unsigned char) random_color(gen), 255});
DrawFPS(190, 300);
EndDrawing();
}
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - begin).count();
std::cout << frame << " frames in " << elapsed <<" seconds => " << static_cast<float>(frame) / static_cast<float>(elapsed) << " fps\n";
CloseWindow();
return 0; The 3 "platforms" for the benchmark are
100k Rectangles / no limitThis test displays enough triangles that we are well below the 60fps threshold.
10k Rectangles / no limitThis test displays less triangles and as a result can achieve more than 60fps.
10k Rectangles / 60fps capSame test as the previous one but with a 60fps cap.
Observations
ConclusionThis was run on my machine so take everything I say with a grain of salt as numbers may vary if run on a different machine of course. It seems that Angle / Metal overall is the winner. Yes there is a clear limitation when uncapped, but I am not entirely sure of the value of running uncapped, certainly not in my use case... |
@ypujante @raysan5 Sorry I'm a bit late, but I managed to replicate the issue on Issue ScreenshotCode ExampleMinimal reproduction code to test the issue:
And:
|
@ubkp Thank you so much for taking the time to test this out and reproducing the problem! I will add your findings to my thread on the Angle forum. It is clearly an issue with Angle... |
@ypujante No problem :) Some updates:
Edit 1: it's working correctly. Edit 2: the issue, for me, was actually on the |
@ubkp Note that on my test, it worked as expected for |
@raysan5 Asked a friend here to test it on his machine (Windows 11 with Chrome), he was able to reproduce the issue:
Outputs this: |
@ubkp Re-testing again, that's what I got: I'm using latest raylib from github master branch, please, could you check the console output in case of Windows 11 test? EDIT: Tested code: #include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib alpha test");
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(BLACK);
DrawRectangle(10, 10, 100, 100, (Color){ 40, 73, 122, 137});
DrawRectangle(10, 120, 100, 100, (Color){ 40, 73, 122, 255});
EndDrawing();
}
CloseWindow();
return 0;
} Compilation line:
|
@raysan5 Thank you very much for testing! Recompiled it with the latest master branch (6094869) using exactly your code and your compilation line. And the results are exactly like yours on both Linux: And Windows:
Edit 1: it was my fault. Edit 2: the issue, for me, was actually on the |
@ypujante Just to be sure, could you please check if you're not missing the |
@ubkp Sorry, I don't understand, |
@raysan5 You're absolutely right. If you comment or remove the Full test:
Output: Now, removing the
Output: I'm really sorry, I didn't know that the CSS background on Edit: typos. |
@ubkp Wow! That's a good catch! Sincerely, I can't remember when it was added or how it affected rendering!!! So... it seem it mixes with the framebuffer color.... interesting... 🤔 |
I think there is something there... clearly there is a way to reproduce it outside the macOS / Angle platform! |
@ypujante could it be that ANGLE implementation is intended to work on web and already considers the |
@ypujante @raysan5 I think I found an explanation for this issue and three possible solutions. This answer on StackOverflow explains it perfectly. To sum it up: the transparency problem is due to compositing. The possible solutions, as mentioned on that answer, are:
IMHO, the third option is the best because:
I'll send a PR with the proposed changes shortly. |
@raysan5 I do not know exactly, but the last answer on the Google Angle forum stated this:
At the end of the day, due to my earlier benchmark and @ubkp tests, depending on the platform, the recommended approaches are the following:
|
After @raysan5 reply on the PR, I realized I'm on a totally wrong approach here. I was trying to work around the issue, instead of fixing the actual problem: why |
@ypujante @ubkp sincerely, I think at this point the best solution is just leave it as it is. The problem has been tracked down and it seems to be beyond OpenGL, but on the underlaying composite system of the target platform, that's far beyond raylib domain. The current solutions should work for any user:
Maybe document it in the Wiki (despite this issue is already a good documentation) for users facing this same problem. @ubkp As per the Google Angle forum description, problem seems to be on EGL configuration. This issue should be tested on Thank you very much you both for the deep investigation on this issue! Waiting for your comments to definitely close this issue. |
@raysan5 Yeah, I think you're right. At the moment I can't find a definitive solution for it. I'm still puzzled about why On my part, feel free to close the issue. If I come across any new information about it, I'll post an update. |
Yes I agree it's time to move on which is what I implied when I commented with the benchmark |
@ypujante @ubkp thanks again for all your time and effort tracking this issue! Closing it! 😄 |
This is a follow up to my post on discord
The issue on macOS is that when using OpenGL ES 2.0 (implemented by Google Angle on macOS), then the texture is rendered with a "halo" where there is transparency:
When using the macOS (deprecated) built-in OpenGL there is no such issue:
The code is very simple and does not do anything fancy:
I am attaching a fully self-contained project which demonstrates the issue. It contains raylib 4.5 (but note that I did try with the latest version on master with the same outcome). There is a README with instructions on how to build and run:
Build
It is a CMake project, so it builds very simply:
The option
USE_GOOGLE_ANGLE_MAC_OS
isON
by default which demonstrates the problem. If you set toOFF
(make sure to delete the build dir and redo all the steps), it won't use OpenGL ES 2.0/Google Angle at which point there is no issue.Run
build/raylib_issue.app/Content/MacOS/raylib_issue
(to see the log in the output)Note that I do not know if it is a raylib issue, a GLFW issue, a Google Angle issue or anything else. The Google Angle libraries are coming from Google Chrome (I did not build them), so I assume they should be working quite well...
raylib-issue.zip
The text was updated successfully, but these errors were encountered: