Testing XAML App for OpenGL ES on Windows 10 Mobile Device

Today I played a bit with a UWP application based on “XAML App for OpenGL ES (Universal Windows)” template and realized that there is some specific bug probably related to the interaction between SwapChainPanel and OpenGL surface. First, I made the cube transparent by changing two lines of code in the vertex shader:

const std::string vs = STRING
(
    uniform mat4 uModelMatrix;
    uniform mat4 uViewMatrix;
    uniform mat4 uProjMatrix;
    attribute vec4 aPosition;
    attribute vec3 aColor;
    varying vec4 vColor;
    void main()
    {
        gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * aPosition;
        vColor = vec4(aColor, 0.1);
    }
);

Then I made the Grid background black and removed TextBlock from SwapChainPanel:

<Grid Background="Black">
    <SwapChainPanel x:Name="swapChainPanel">
    </SwapChainPanel>
</Grid>

And changed the fill color:

void SimpleRenderer::Draw()
{
    glEnable(GL_DEPTH_TEST);

    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
...
}

The main point of this experiment was commenting out debugger related stuff:

void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
{
//#if _DEBUG
//    if (IsDebuggerPresent())
//    {
//        DebugSettings->EnableFrameRateCounter = true;
//    }
//#endif

    if (mPage == nullptr)
    {
        mPage = ref new OpenGLESPage(&mOpenGLES);
    }

    // Place the page in the current window and ensure that it is active.
    Windows::UI::Xaml::Window::Current->Content = mPage;
    Windows::UI::Xaml::Window::Current->Activate();
}

Finally I got some interesting result. When my Lumia 650 is in portrait orientation the cube is transparent, but in landscape orientation the cube is completely opaque. See the video below:

TextBlock in SwapChainPanel or some windows/controls overlapping SwapChainPanel (for example, menu fly outs, etc…) make the cube opaque.

The source code of my sample application available here: https://github.com/dmitriano/AppForOpenGLES2

Leave a Reply

Your email address will not be published. Required fields are marked *