File: gltools.rst

package info (click to toggle)
psychopy 2023.2.4%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 124,456 kB
  • sloc: python: 126,213; javascript: 11,982; makefile: 152; sh: 120; xml: 9
file content (216 lines) | stat: -rw-r--r-- 4,606 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
:mod:`psychopy.tools.gltools`
-----------------------------

.. automodule:: psychopy.tools.gltools
.. currentmodule:: psychopy.tools.gltools

Shaders
~~~~~~~

Tools for creating, compiling, using, and inspecting shader programs.

.. autosummary::
    :toctree: ../generated/

    createProgram
    createProgramObjectARB
    compileShader
    compileShaderObjectARB
    embedShaderSourceDefs
    deleteObject
    deleteObjectARB
    attachShader
    attachObjectARB
    detachShader
    detachObjectARB
    linkProgram
    linkProgramObjectARB
    validateProgram
    validateProgramARB
    useProgram
    useProgramObjectARB
    getInfoLog
    getUniformLocations
    getAttribLocations

Query
~~~~~

Tools for using OpenGL query objects.

.. autosummary::
    :toctree: ../generated/

    createQueryObject
    QueryObjectInfo
    beginQuery
    endQuery
    getQuery
    getAbsTimeGPU

Framebuffer Objects (FBO)
~~~~~~~~~~~~~~~~~~~~~~~~~

Tools for creating Framebuffer Objects (FBOs).

.. autosummary::
    :toctree: ../generated/

    createFBO
    attach
    isComplete
    deleteFBO
    blitFBO
    useFBO

Renderbuffers
~~~~~~~~~~~~~

Tools for creating Renderbuffers.

.. autosummary::
    :toctree: ../generated/

    createRenderbuffer
    deleteRenderbuffer


Textures
~~~~~~~~

Tools for creating textures.

.. autosummary::
    :toctree: ../generated/

    createTexImage2D
    createTexImage2dFromFile
    createTexImage2DMultisample
    deleteTexture
    bindTexture
    unbindTexture
    createCubeMap

Vertex Buffer/Array Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tools for creating and working with Vertex Buffer Objects (VBOs) and Vertex
Array Objects (VAOs).

.. autosummary::
    :toctree: ../generated/

    VertexArrayInfo
    createVAO
    drawVAO
    deleteVAO
    VertexBufferInfo
    createVBO
    bindVBO
    unbindVBO
    mapBuffer
    unmapBuffer
    deleteVBO
    setVertexAttribPointer
    enableVertexAttribArray
    disableVertexAttribArray

Materials and Lighting
~~~~~~~~~~~~~~~~~~~~~~

Tools for specifying the appearance of faces and shading. Note that these tools
use the legacy OpenGL pipeline which may not be available on your platform. Use
fragment/vertex shaders instead for newer applications.

.. autosummary::
    :toctree: ../generated/

    createMaterial
    useMaterial
    createLight
    useLights
    setAmbientLight

Meshes
~~~~~~

Tools for loading or procedurally generating meshes (3D models).

.. autosummary::
    :toctree: ../generated/

    ObjMeshInfo
    loadObjFile
    loadMtlFile
    createUVSphere
    createPlane
    createMeshGridFromArrays
    createMeshGrid
    createBox
    transformMeshPosOri
    calculateVertexNormals

Miscellaneous
~~~~~~~~~~~~~

Miscellaneous tools for working with OpenGL.

.. autosummary::
    :toctree: ../generated/

    getIntegerv
    getFloatv
    getString
    getOpenGLInfo
    getModelViewMatrix
    getProjectionMatrix


Examples
~~~~~~~~
**Working with Framebuffer Objects (FBOs):**

Creating an empty framebuffer with no attachments::

    fbo = createFBO()  # invalid until attachments are added

Create a render target with multiple color texture attachments::

    colorTex = createTexImage2D(1024,1024)  # empty texture
    depthRb = createRenderbuffer(800,600,internalFormat=GL.GL_DEPTH24_STENCIL8)

    GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, fbo.id)
    attach(GL.GL_COLOR_ATTACHMENT0, colorTex)
    attach(GL.GL_DEPTH_ATTACHMENT, depthRb)
    attach(GL.GL_STENCIL_ATTACHMENT, depthRb)
    # or attach(GL.GL_DEPTH_STENCIL_ATTACHMENT, depthRb)
    GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0)

Attach FBO images using a context. This automatically returns to the previous
FBO binding state when complete. This is useful if you don't know the current
binding state::

    with useFBO(fbo):
        attach(GL.GL_COLOR_ATTACHMENT0, colorTex)
        attach(GL.GL_DEPTH_ATTACHMENT, depthRb)
        attach(GL.GL_STENCIL_ATTACHMENT, depthRb)

How to set userData some custom function might access::

    fbo.userData['flags'] = ['left_eye', 'clear_before_use']

Binding an FBO for drawing/reading::

    GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb.id)

Depth-only framebuffers are valid, sometimes need for generating shadows::

    depthTex = createTexImage2D(800, 600,
                                internalFormat=GL.GL_DEPTH_COMPONENT24,
                                pixelFormat=GL.GL_DEPTH_COMPONENT)
    fbo = createFBO([(GL.GL_DEPTH_ATTACHMENT, depthTex)])

Deleting a framebuffer when done with it. This invalidates the framebuffer's ID
and makes it available for use::

    deleteFBO(fbo)