Logo   Home Table of Contents    News  Dev Blogs  Gallery  Timeline  Legend  Tags  Sponsors 
Join us on... 
Banner

Current: Month Day, Year

9.1.4 Code of opengl/buffers.py

opengl/buffers provides all functions to render openGL objects. These functions can be used to render all kinds of objects. The file contains 4 classes:

Class OpenGlBuffers

This class holds the classical 3 openGL buffers: VertexBuffer, NormalBuffer, TexCoordBuffer. It does the bindings as well and provides a function for writing the changed data.

Variables

These variables are all preset by __init__.
namedescription
vert_pos_buffes reference to vertex buffer.
normal_buffer reference to normal buffer.
tex_coord_buffer reference to texture coordinates buffer (UV).
memory_pos memory_pos holds the the value of the source numpy array for the verices (gl_coord).
len_memory length in bytes of the vert_pos_buffer needed

Methods:

nameparametersreturnsdescription
VertexBuffer posNone creates the vertex buffer and puts the vertex-coordinates into that buffer. This buffer is used dynamic.
NormalBuffer posNone creates the normal buffer and puts the normals into that buffer.
TexCoordBuffer posNone creates the texture coordinates buffer and puts the values into that buffer.
GetBuffers pos
norm
tpos
None Calls VertexBuffer, NormalBuffer, TexCoordBuffer with the given values.
BindBuffersToShader shaderNone set shader attribute buffer 0, 1 for vertex buffer and normal buffer, in case self.tex_coord_buffer this bound to 2. shader.enableAttributeArray is called in each case.
Tweak NoneNone Tweaks the vertex buffer with new values.
Delete NoneNone Deletes (destroys) the vertex, normal and tex_coord buffer.

Class RenderedObject

This class is used to render an object like body or clothes. It can also be used to draw other objects.

Variables

These variables are all preset by __init__.
namedescription
parent parent object, which is used to access multiple functions.
glob reference to global object.
env reference to environment object.
object object to render.
boundingbox reference to boundingbox.
glbuffers reference to OpenGlBuffers object.
position Current position as QVector3D.
functions OpenGL functions from parent object.
shaders reference to shaders from parent object.
texture reference to diffuse texture (preset to None).
litsphere reference to litsphere texture (preset to None).
aomap reference to ambient occlusion map (preset to None).
nomap reference to normal map (preset to None).
mrmap reference to metal-roughness map (preset to None).
emmap reference to emission map (preset to None).
mefac metallic factor (Preset to 0).
z_depth z-depth of object.
name Name of the object.
getindex Reference to index function (from object, getOpenGLIndex). Determines if hidden vertices are also used.
scale Scale of the object. Preset to (1, 1, 1).
x_rotation Rotation around x axis. Preset to 0.0.
y_rotation Rotation around y axis. Preset to 0.0.
z_rotation Rotation around z axis. Preset to 0.0.
mvp_matrix empty MVP matrix for later use.
model_matrix empty model matrix for later use.
normal_matrix empty normal matrix for later use.
proxy If type is proxy, proxy is linked to basemesh, otherwise it is linked to object (this is used for material selection).

Methods:

nameparametersreturnsdescription
delete NoneNone Deletes the glBuffers of the object.
setMaterial material
modify (boolean)
None set shader and creates textures from material according to shader type. All shaders use a diffuse texture, used objects are marked by proxy (which is either basemesh or object). Also colorates object and loads a mask if needed.
setTexture textureNone Setter for diffuse texture.
setPosition posNone Setter for position.
setScale scaleNone Setter for scale.
setXRotation rotNone Setter for x rotation.
setYRotation rotNone Setter for y rotation.
setZRotation rotNone Setter for z rotation.
geomToShader shader
proj_view_matrix
campos
None creates the geometry. It first get the uniforms uMvpMatrix, uModelMatrix, uNormalMatrix, viewPos from the shaders. Then binds the buffers to the shaders, sets model matrix to idendity and translates, rotates and scales object. Then the model view matrix and normal_matrix ist calculated. All uniform values not being -1 are set with setUniformValue.
glReset NoneNone resets shader by disabling certain parameters and sets glActiveTexture to gl.GL_TEXTURE0.
drawObject NoneNone get index from object and calls glDrawElements
draw proj_view_matrix
campos
light
xrayed boolean
None The main draw function. GL_DEPTH_TEST is enabled. Then xrayed version is handled first with special shader. After that lightWeight is calculated (phong, specular focus). Next step is transparency. AlphaCoverage demands samples buffers, so if these are not given do not use alphaToCoverage, use BLEND instead. Blend function is set according to transparency. After that diffuse texture is always bind. The next steps are litsphere, for phong: AOTexture and NOTexture and for pbr all textures and skybox. Also glass parameters are set. Then drawObject is called and glReset.
drawWireframe proj_view_matrix
campos
black
white
None creates a wireframe model, either uses an own shader 'wireframe' or the old glPolygonMode function for apple (which is internally a phong shader). glPolygonMode is used with glDrawElements twice with white and black.

Class RenderedLines

This class is used to render lines for e.g. grids.

Variables

These variables are all preset by __init__.
namedescription
functions OpenGL functions from parent object.
shader reference to shader.
name Name of the object.
infront Paint always in front.
position Current position as QVector3D.
scale Scale of the object. Preset to (1, 1, 1).
y_rotation Rotation around y axis. Preset to 0.0.
mvp_matrix empty MVP matrix for later use.
model_matrix empty model matrix for later use.
normal_matrix empty normal matrix for later use.
glbuffers reference to OpenGlBuffers object.
indices array of indices.
mvp_matrix_location holds value of shader.uniforms["uMvpMatrix"]
model_matrix_location holds value of shader.uniforms["uModelMatrix"]

Methods:

nameparametersreturnsdescription
delete NoneNone Deletes the glBuffers of the object.
setPosition posNone Setter for position.
setYRotation rotNone Setter for y rotation.
draw proj_view_matrixNone The main draw function. Creates the geometry and then binds the buffers to the shaders, sets model matrix to idendity and translates, rotates and scales object. Then the model view matrix and normal_matrix ist calculated. glDrawElements is called with indices.

Class RenderedSimple

This class is used to render a simple object like floor or a bone

Variables

These variables are all preset by __init__.
namedescription
functions OpenGL functions from parent object.
name Name of the object.
scale Scale of the object. Preset to (1, 1, 1).
mvp_matrix empty MVP matrix for later use.
model_matrix empty model matrix for later use.
normal_matrix empty normal matrix for later use.
rotation rotation matrix.
position Current position as QVector3D.
glbuffers reference to OpenGlBuffers object.
indices array of indices.
infront Paint always in front.
transparent Paint object transparent.
shader Reference to phong shader.
mvp_matrix_location holds value of shader.uniforms["uMvpMatrix"]
model_matrix_location holds value of shader.uniforms["uModelMatrix"]
normal_matrix_location holds value of shader.uniforms["uNormalMatrix"]

Methods:

nameparametersreturnsdescription
setPosition posNone Setter for position.
setScale scaleNone Setter for scale.
setRotation rotNone Setter for rotation matrix.
delete NoneNone Deletes the glBuffers of the object.
draw proj_view_matrixNone The main draw function. Creates the geometry and then binds the buffers to the shaders, sets model matrix to idendity and translates, rotates and scales object. Then the model view matrix and normal_matrix ist calculated. Diffuse and AO-Texture are used. Object is either created in front or (disable depth test) or normal. Transparency is handled. glDrawElements is called with indices. Then all shaders are resetted.