Skip to content

Fixes OcclusionQuery for Android.GL#2598

Merged
nkast merged 5 commits into
kniEngine:mainfrom
squarebananas:OcclusionQueryGLES
Jun 20, 2026
Merged

Fixes OcclusionQuery for Android.GL#2598
nkast merged 5 commits into
kniEngine:mainfrom
squarebananas:OcclusionQueryGLES

Conversation

@squarebananas

@squarebananas squarebananas commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Fixes OcclusionQuery for Android with GLES.

QueryTarget.SamplesPassed is only available for OpenGL, not GLES. However, QueryTarget.SamplesPassedExt is supported for GLES, but only returns a result of 0 or 1 (where 1 represents one or more pixels visible) instead of the actual pixel count.

Although labelled as an extension, it is a core feature of GLES 3 and only an extension for GLES 2. Both names use the same enum value.

For GLES 2 (https://registry.khronos.org/OpenGL/extensions/EXT/EXT_occlusion_query_boolean.txt):

ANY_SAMPLES_PASSED_EXT 0x8C2F

For GLES 3 (https://registry.khronos.org/OpenGL/api/GLES3/gl3.h):

#define GL_ANY_SAMPLES_PASSED 0x8C2F

For testing, the XNA Lens Flare sample with Kni projects added can be found here: kniEngine/XNAGameStudio#1

@nkast

nkast commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

I see that we had 0x8C2F incorrectly named SamplesPassedExt, but it's a different type of query (AnySamplesPassed) that returns a boolean, and not an extension of SamplesPassed.

The Lens Flare sample depend on PixelCount returning the number of pixels, and it's not a simple check of (PixelCount>0).

occlusionAlpha = Math.Min(occlusionQuery.PixelCount / queryArea, 1);

I see that you adjusted querySize in the sample , and documented the PixelCount behavior for GLES/WebGL.

However I imagine that people who port similar projects to Android/Web/Oculus, might have a hard time spotting the difference in behavior. I think it is best for PixelCount to throw a PlatformNotSupported.
We could add a new Property to the OcclusionQuery to support the limited functionallity of GLES, something like AnyPixelPassed, IsOccluded, or something similar.

@squarebananas

Copy link
Copy Markdown
Contributor Author

I think it is best for PixelCount to throw a PlatformNotSupported.
We could add a new Property to the OcclusionQuery to support the limited functionallity of GLES, something like AnyPixelPassed, IsOccluded, or something similar.

Ok, I'll change PixelCount to PlatformNotSupportedException and add a new AnyPixelPassed property. I'll probably rename private _pixelCount to _queryResultValue as well.

@nkast

nkast commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

So, this fails, because of Blazor.
Should I merge this now , add a stub to get it compile, and rebase/resolve the WebGL PR later?

@squarebananas

Copy link
Copy Markdown
Contributor Author

So, this fails, because of Blazor. Should I merge this now , add a stub to get it compile, and rebase/resolve the WebGL PR later?

You mean because this PR would require #2599 and that would need BlazorGL to have the newer Wasm nuget versions for that? It will probably be fine to leave this blocked until then, but I've just added a stub in case anyway.

@nkast
nkast merged commit 8e2e619 into kniEngine:main Jun 20, 2026
1 check passed
@nkast

nkast commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

That's great. Merging.

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.

2 participants