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

EGL Context antialiasing bug #1533

Closed
DanielDorn opened this issue Dec 30, 2018 · 1 comment
Closed

EGL Context antialiasing bug #1533

DanielDorn opened this issue Dec 30, 2018 · 1 comment

Comments

@DanielDorn
Copy link

DanielDorn commented Dec 30, 2018

Once again a bug in the EGL Context class now effecting antialiasing

This bug effects all versions of SFML supporting android,

to recreate this bug simply use the following code with the current version of sfml

int main(int argc, char* argv[])
{
	::tiny::RenderWindow window(::tiny::VideoMode(200, 200), "tiny works!", ::tiny::Style::Default, ::tiny::ContextSettings{ 32, 0, 4, 1, 1, ::tiny::ContextSettings::Default, false });
	window.setActive(true);
	::tiny::CircleShape shape(100.f);
	shape.setFillColor(::tiny::Color::Green);
	bool isDone = false;
	
	
	while(isDone == false)
	{
		::tiny::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == ::tiny::Event::Closed)
			{
				window.close();
				isDone = true;
			}

			if(event.type == ::tiny::Event::GainedFocus)
				::tiny::err() << "Gained Focus" << ::std::endl;
		}

		window.clear();
		window.draw(shape);
		window.display();
	}

	return 0;
}

Because we have set the antialiasing level to 4 it will draw nothing to the screen because of the following lines of bugged code in EglContext.cpp

EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixel, const ContextSettings& settings)
{
	// Set our video settings constraint
	const EGLint attributes[] = {
		EGL_BUFFER_SIZE, static_cast<EGLint>(bitsPerPixel),
		EGL_DEPTH_SIZE, static_cast<EGLint>(settings.depthBits),
		EGL_STENCIL_SIZE, static_cast<EGLint>(settings.stencilBits),
		EGL_SAMPLE_BUFFERS, static_cast<EGLint>(settings.antialiasingLevel),
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
		EGL_NONE
	};

	EGLint configCount;
	EGLConfig configs[1];

	// Ask EGL for the best config matching our video settings
	eglCheck(eglChooseConfig(display, attributes, configs, 1, &configCount));

	// TODO: This should check EGL_CONFORMANT and pick the first conformant configuration.

	return configs[0];
}

the bug coming from the getBestConfig function is caused because of incorrectly set attributes, EGL_SAMPLE_BUFFERS is not where we set the multisamples but rather the number of buffers for multisampling, currently EGL only support a value between 0 and 1, anything more then 1 will caused undefined behavior,

patch

EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixel, const ContextSettings& settings)
{
	EGLint multiSamplesBuffer = 0;

	if(settings.antialiasingLevel > 0)
		multiSamplesBuffer = 1;
		
	// Set our video settings constraint
	const EGLint attributes[] = {
		EGL_BUFFER_SIZE, static_cast<EGLint>(bitsPerPixel),
		EGL_DEPTH_SIZE, static_cast<EGLint>(settings.depthBits),
		EGL_STENCIL_SIZE, static_cast<EGLint>(settings.stencilBits),
		EGL_SAMPLE_BUFFERS, multiSamplesBuffer,
		EGL_SAMPLES, static_cast<EGLint>(settings.antialiasingLevel),
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
		EGL_NONE
	};

	EGLint configCount;
	EGLConfig configs[1];

	// Ask EGL for the best config matching our video settings
	eglCheck(eglChooseConfig(display, attributes, configs, 1, &configCount));

	// TODO: This should check EGL_CONFORMANT and pick the first conformant configuration.

	return configs[0];
}

this patch simply checks if antialiasing is enabled and sets a the samples buffer on or off accordingly, hope this helps anyone with this issue, cheers (=

@binary1248
Copy link
Member

This should be fixed with #1534.

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Dec 31, 2018
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Dec 31, 2018
@eXpl0it3r eXpl0it3r moved this from Discussion to Ready in SFML 2.6.0 Jan 2, 2019
eXpl0it3r pushed a commit that referenced this issue Jan 4, 2019
SFML 2.6.0 automation moved this from Ready to Done Jan 4, 2019
Unarelith pushed a commit to Unarelith/SFML that referenced this issue May 28, 2020
Unarelith pushed a commit to Unarelith/SFML that referenced this issue May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.6.0
  
Done
Development

No branches or pull requests

3 participants