roxlu / windows-opengl-context

Experimental code for this issue https://github.com/google/filament/issues/1921

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating Shared OpenGL Contexts

I created this repository while looking into an issue with Filament. This repository contains 3 tests:

  • test-research.cpp: Contains a summary of how to create a OpenGL context on Windows and some background info.

  • test-shared-context.cpp: Contains code that creates a couple of OpenGL contexts using the recommended flow (e.g. using a temporary context).

  • test-shared-context-threading.cpp: Similar to test-shared-context.cpp but here, we simulate how Filament creates a shared context, most importantly that we create the context in a separate thread.

Building with Clang

  • Make sure that you have Clang installed into C:/Program Files/LLVM
  • Make sure that you have CMake 3.15+ installed
  • Make sure you have Ninja installed.
  • Open a x64 Native Tools Command Prompt for VS 2019
  • Go into the build directory
  • Run release.bat clang

Building with MSVC

  • Make sure that you have Clang installed into C:/Program Files/LLVM
  • Make sure that you have CMake 3.15+ installed
  • Make sure you have Ninja installed.
  • Open a x64 Native Tools Command Prompt for VS 2019
  • Go into the build directory
  • Run release.bat

Solution (?)

baldurk pointed me to something which seems to be the cause of the issue. I'm creating a new OpenGl context in a separate thread and try to use the OpenGl context from the main as a shared context. Though the OpenGl context from the main thread is still current. When I unset the current OpenGl context from the main thread things seem to work! See this, where I unset the current context.

IMPORTANT: when you create an OpenGl context and you want to share this context with a context that you create in another thread, make sure that the context is not current.

About

Experimental code for this issue https://github.com/google/filament/issues/1921


Languages

Language:C 96.9%Language:C++ 2.8%Language:Batchfile 0.2%Language:CMake 0.1%