.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.glcanvas.GLContext:

==========================================================================================================================================
|phoenix_title|  **wx.glcanvas.GLContext**
==========================================================================================================================================

An instance of a :ref:`wx.glcanvas.GLContext`  represents the state of an OpenGL state machine and the connection between OpenGL and the system.          

The OpenGL state includes everything that can be set with the OpenGL API: colors, rendering variables, buffer data ids, texture objects, etc. It is possible to have multiple rendering contexts share buffer data and textures. This feature is specially useful when the application use multiple threads for updating data into the memory of the graphics card. 

Whether one only rendering context is used with or bound to multiple output windows or if each window has its own bound context is a developer decision. It is important to take into account that ``GPU`` makers may set different pointers to the same ``OGL`` function for different contexts. The way these pointers are retrieved from the ``OGL`` driver should be used again for each new context. 

Binding (making current) a rendering context with another instance of a :ref:`wx.glcanvas.GLCanvas`  however works only if the both :ref:`wx.glcanvas.GLCanvas`  instances were created with the same attributes. 

OpenGL version 3 introduced a new type of specification profile, the modern core profile. The old compatibility profile maintains all legacy features. Since wxWidgets 3.1.0 you can choose the type of context and even ask for a specified ``OGL`` version number. However, its advised to use only core profile as the compatibility profile may run a bit slower. 

OpenGL core profile specification defines several flags at context creation that determine not only the type of context but also some features. Some of these flags can be set in the list of attributes used at :ref:`wx.glcanvas.GLCanvas`  constructor. But since wxWidgets 3.1.0 it is strongly encouraged to use the new mechanism: setting the context attributes with a :ref:`wx.glcanvas.GLContextAttrs`  object and the canvas attributes with a :ref:`wx.glcanvas.GLAttributes`  object. 

The best way of knowing if your OpenGL environment supports a specific type of context is creating a :ref:`wx.glcanvas.GLContext`  instance and checking :meth:`wx.glcanvas.GLContext.IsOK` . If it returns ``False``, then simply delete that instance and create a new one with other attributes. 

``HAS_OPENGL_ES`` is defined on platforms that only have this implementation available (e.g. the iPhone) and don't support the full specification. 







         



.. seealso:: :ref:`wx.glcanvas.GLCanvas`, :ref:`wx.glcanvas.GLContextAttrs`, :ref:`wx.glcanvas.GLAttributes`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>GLContext</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.glcanvas.GLContext_inheritance.png" alt="Inheritance diagram of GLContext" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.glcanvas.GLContext.html" title="wx.glcanvas.GLContext" alt="" coords="5,83,180,112"/> <area shape="rect" id="node2" href="wx.Object.html" title="wx.Object" alt="" coords="49,5,136,35"/> </map> 
   </p>
   </div>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.glcanvas.GLContext.__init__`                                          Constructor.
:meth:`~wx.glcanvas.GLContext.IsOK`                                              Checks if the underlying OpenGL rendering context was correctly created by the system with the requested attributes.
:meth:`~wx.glcanvas.GLContext.SetCurrent`                                        Makes the OpenGL state that is represented by this rendering context current with the :ref:`wx.glcanvas.GLCanvas`  `win`.
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.glcanvas.GLContext(Object)

   **Possible constructors**::

       GLContext(win, other=None, ctxAttrs=None)
       
   
   An instance of a GLContext represents the state of an OpenGL state
   machine and the connection between OpenGL and the system.



   .. method:: __init__(self, win, other=None, ctxAttrs=None)

      Constructor.                  




      :param `win`: The canvas that is used to initialize this context. This parameter is needed only temporarily, and the caller may do anything with it (e.g. destroy the window) after the constructor returned. 

        It will be possible to bind (make current) this context to any other :ref:`wx.glcanvas.GLCanvas`  that has been created with equivalent attributes as win.   
      :type `win`: wx.glcanvas.GLCanvas
      :param `other`: Context to share some data with or ``None`` (the default) for no sharing.   
      :type `other`: wx.glcanvas.GLContext
      :param `ctxAttrs`: A :ref:`wx.glcanvas.GLContextAttrs`  pointer to the attributes used for defining the flags when ``OGL`` >= 3.2 is requested. This is the preferred method since wxWidgets 3.1.0. The previous method (still available for backwards compatibility) is to define the attributes at :ref:`wx.glcanvas.GLCanvas`  constructor. If this parameter is ``None`` (the default) then that previous method is taken. If no attributes are defined at all, then those provided by the ``GPU`` driver defaults will be used.   
      :type `ctxAttrs`: wx.glcanvas.GLContextAttrs








                  





   .. method:: IsOK(self)

      Checks if the underlying OpenGL rendering context was correctly created by the system with the requested attributes.                  

      If this function returns ``False`` then the :ref:`wx.glcanvas.GLContext`  object is useless and should be deleted and recreated with different attributes. 

                

      :rtype: `bool`







      .. versionadded:: 4.1/wxWidgets-3.1.0  
     








   .. method:: SetCurrent(self, win)

      Makes the OpenGL state that is represented by this rendering context current with the :ref:`wx.glcanvas.GLCanvas`  `win`.                  

                


      :param `win`: 
      :type `win`: wx.glcanvas.GLCanvas




      :rtype: `bool`







      .. note:: 

         `win`  can be a different :ref:`wx.glcanvas.GLCanvas`  window than the one that was passed to the constructor of this rendering context. If ``RC``  is an object of type :ref:`wx.glcanvas.GLContext`, the statements `"RC.SetCurrent(win);"`  and `"win.SetCurrent(RC);"`  are equivalent, see :meth:`wx.glcanvas.GLCanvas.SetCurrent` .   







