Skip to content

Commit da0029e

Browse files
author
Daniel Limberger
committed
Update README.md
1 parent 31741c4 commit da0029e

1 file changed

Lines changed: 18 additions & 46 deletions

File tree

README.md

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,12 @@ glbinding::Binding::initialize(false); // lazy function pointer resolution
345345
346346
*glbinding* has built-in support for multiple contexts. The only requirement is, that the currently active context has to be specified. This feature mixes well with multi-threaded applications, but keep in mind that concurrent use of one context often result in non-meaningful communication with the OpenGL driver.
347347
348-
To use multiple contexts, use your favorite context creation library (e.g., glut, SDL, egl, glfw, Qt) to request as much contexts as required. The functions to make a context current should be provided by this library and is not part of *glbinding* (except that you can get the current context handle). When using multiple contexts, first, each has to be initialized when active:
348+
In order to use multiple contexts, use your favorite context creation library (e.g., glut, SDL, egl, glfw, Qt) to request the required contexts.
349+
The functions to make a context current should be provided by these libraries and is not part of *glbinding* (except that you can get the current context handle).
350+
When using multiple contexts, *glbinding* has to be initialized for each context (when current).
349351
350-
```cpp
351-
// use context library to make current, e.g., glfwMakeCurrent(...)
352-
glbinding::Binding::initialize();
353-
```
354-
355-
Second, contexts switches are required to be communicated to *glinding* explicitly in order to have correctly dispatched function pointers:
352+
Since each context can correspond to a different feature set of OpenGL and the drivers are free to assign their function pointers, *glbinding* cannot assume any equalities of requested function pointers.
353+
Thus, contexts switches have to be communicated to *glbinding* explicitly in order to have correctly dispatched function pointers:
356354
357355
```cpp
358356
// use the current active context
@@ -362,34 +360,22 @@ glbinding::Binding::useCurrentContext();
362360
glbinding::Binding::useContext(ContextHandle context);
363361
```
364362

365-
This feature is mainly intended for platforms where function pointers for different requested OpenGL features may vary.
366-
367-
**VS..**
368-
369-
##### Multiple OpenGL Contexts usage TODO
370-
371-
OpenGL allows for multiple contexts per program/process to be created and used. The one limitation is that only one context can be *current* at a given time. As each context can correspond to a different feature set of OpenGL and the drivers are free to assign their function pointers, glbinding **cannot** assume any equalities of requested function pointers. This means a user *must* tell glbinding of all contexts he wants to use and when the switches of *current* contexts occured.
372-
Concluding, a user have to call the initialize method once per OpenGL context (when it is current) and has to update the current context if it has changed.
373363

374364

375365

376366
### Multi-Threading Support
377367

378368
Concurrent use of *glbinding* is mainly intended to the usage of multiple contexts in different threads (multiple threads operating on a single OpenGL context requires locking, which *glbinding* will not provide).
379-
For this, *glbinding* supports multiple active contexts, one per thread. This necessitates that *glbinding* gets informed in each thread which context is currently active (see [multi-context](#multi-context-support)).
380-
381-
**VS TODO**
369+
For it, *glbinding* supports multiple active contexts, one per thread.
370+
This necessitates that *glbinding* gets informed in each thread which context is currently active (see [multi-context](#multi-context-support)).
371+
Note: multi-threaded communication with OpenGL will most likely result in a meaningless sequence of OpenGL calls.
372+
To avoid this, semantic groups of OpenGL calls should be treated as critical sections.
382373

383-
##### Multi-threaded OpenGL Context usage ToDO Remove?
374+
##### Multiple OpenGL Contexts in Multiple Threads
384375

385-
If you want to use one OpenGL context in multiple threads, you have to call the initialize method once per thread. This is required because the *current* status of an OpenGL context is dependend on the current thread, i.e., you can have different contexts *current* in different threads. In order to allow for this, glbinding has to differentiate between registered OpenGL contexts per thread.
386-
387-
Beware of using one OpenGL context in multiple threads concurrently! Most likely, it won't result in a meaningful sequence of OpenGL calls. If you really want to use one OpenGL context in multiple threads, be sure to treat semantic groups of OpenGL calls as critical sections.
388-
389-
390-
##### Multiple OpenGL Contexts in multiple Threads todo Remove?
391-
392-
The combination of multiple OpenGL contexts and multiple threads for OpenGL usage is supported by glbinding. You must tell glbinding which OpenGL context is used in which thread by calling the initialize method once the context is used first (```glbinding::Binding::initialize()```) and if you want to switch the *current* context for one thread, you have to update the current context, too (```glbinding::Binding::useCurrentContext()```). We strongly discourage the use of one context in multiple threads and we don't see real added value in using multiple contexts in one thread, so the main use case would be to use one OpenGL context per thread. This means you mainly have to register the context you want to use per thread once and leave it as is.
376+
The combination of multiple OpenGL contexts and multiple threads for OpenGL usage is supported by *glbinding* in general.
377+
You must tell *glbinding* which OpenGL context is used in which thread by calling the initialize method once the context is used first (```glbinding::Binding::initialize()```) and if you want to switch the current context for one thread, you have to update the current context, too (```glbinding::Binding::useCurrentContext()```).
378+
However, we strongly discourage the use of one context in multiple threads.
393379

394380

395381

@@ -414,15 +400,6 @@ The unresolved callback provides information about the (unresolved) wrapped Open
414400
Example for error checking:
415401

416402
```cpp
417-
#include <iostream>
418-
419-
#include <glbinding/callbacks.h>
420-
#include <glbinding/gl/gl.h>
421-
422-
using namespace glbinding;
423-
using namespace gl;
424-
425-
// ...
426403
setCallbackMaskExcept(CallbackMask::After, { "glGetError" });
427404
setAfterCallback([](const FunctionCall &)
428405
{
@@ -431,19 +408,12 @@ setAfterCallback([](const FunctionCall &)
431408
std::cout << "error: " << std::hex << error << std::endl;
432409
});
433410

434-
// ... OpenGL code
411+
// OpenGL Code ...
435412
```
436413
437414
Example for logging:
438415
439416
```cpp
440-
#include <iostream>
441-
442-
#include <glbinding/callbacks.h>
443-
444-
using namespace glbinding;
445-
446-
// ...
447417
setCallbackMask(CallbackMask::After | CallbackMask::ParametersAndReturnValue);
448418
glbinding::setAfterCallback([](const glbinding::FunctionCall & call)
449419
{
@@ -462,10 +432,12 @@ glbinding::setAfterCallback([](const glbinding::FunctionCall & call)
462432
std::cout << std::endl;
463433
});
464434
465-
// ... OpenGL code
435+
// OpenGL Code ...
466436
```
467437

468438

439+
440+
469441
### Alternative Signatures
470442

471443
The OpenGL API is designed without function overloading using only simple parameter types.
@@ -490,7 +462,7 @@ glTexParametere(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
490462
glTexParametere(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
491463
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 64, 64, 0, GL_RED, GL_UNSIGNED_BYTE, terrain.data());
492464
```
493-
Note that these function signatures are *only* defined in the ```gl``` namespace.
465+
Note that these function signatures are only defined in the ```gl``` namespace.
494466
If you want to use per-feature API header and the patched signatures together in your project, you have to use either the ```gl``` namespace in addition to other ones or manually import the used alternative signatures into the other namespace using ```using``` declarations.
495467
496468

0 commit comments

Comments
 (0)