Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2017-10-17 11:41:43 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-10-17 11:41:43 +0300
commitdd2126b0988e6efa6a29b47cfefb659ec7952b68 (patch)
tree9b4b55a27d46cd69198e8c206ae7cd657349cc56
parent3b601c6ec881b6309a286d7279b5df69a36fb97a (diff)
Snap utilities: Avoid any OpenGL resources allocations for class members
OpenGL is not available in background mode, which was making unit tests to fail. Additionally, it will cause some unwanted noise when someone renders his project from command line, or performs any other command-line operation with Blender.
-rw-r--r--modules/snap_context/mesh_drawing.py50
1 files changed, 31 insertions, 19 deletions
diff --git a/modules/snap_context/mesh_drawing.py b/modules/snap_context/mesh_drawing.py
index 82d87937..c85da506 100644
--- a/modules/snap_context/mesh_drawing.py
+++ b/modules/snap_context/mesh_drawing.py
@@ -156,33 +156,43 @@ class _Mesh_Arrays():
class GPU_Indices_Mesh():
- shader = Shader(
- load_shader('3D_vert.glsl'),
- None,
- load_shader('primitive_id_frag.glsl'),
- )
+ shader = None
- unif_use_clip_planes = bgl.glGetUniformLocation(shader.program, 'use_clip_planes')
- unif_clip_plane = bgl.glGetUniformLocation(shader.program, 'clip_plane')
+ @classmethod
+ def init_opengl(cls):
+ # OpenGL was already initialized, nothing to do here.
+ if cls.shader is not None:
+ return
+
+ cls.shader = Shader(
+ load_shader('3D_vert.glsl'),
+ None,
+ load_shader('primitive_id_frag.glsl'),
+ )
- unif_MVP = bgl.glGetUniformLocation(shader.program, 'MVP')
- unif_MV = bgl.glGetUniformLocation(shader.program, 'MV')
- unif_offset = bgl.glGetUniformLocation(shader.program, 'offset')
+ cls.unif_use_clip_planes = bgl.glGetUniformLocation(cls.shader.program, 'use_clip_planes')
+ cls.unif_clip_plane = bgl.glGetUniformLocation(cls.shader.program, 'clip_plane')
- attr_pos = bgl.glGetAttribLocation(shader.program, 'pos')
- attr_primitive_id = bgl.glGetAttribLocation(shader.program, 'primitive_id')
+ cls.unif_MVP = bgl.glGetUniformLocation(cls.shader.program, 'MVP')
+ cls.unif_MV = bgl.glGetUniformLocation(cls.shader.program, 'MV')
+ cls.unif_offset = bgl.glGetUniformLocation(cls.shader.program, 'offset')
- P = bgl.Buffer(bgl.GL_FLOAT, (4, 4))
- MV = bgl.Buffer(bgl.GL_FLOAT, (4, 4))
+ cls.attr_pos = bgl.glGetAttribLocation(cls.shader.program, 'pos')
+ cls.attr_primitive_id = bgl.glGetAttribLocation(cls.shader.program, 'primitive_id')
- # returns of public API #
- vert_index = bgl.Buffer(bgl.GL_INT, 1)
+ cls.P = bgl.Buffer(bgl.GL_FLOAT, (4, 4))
+ cls.MV = bgl.Buffer(bgl.GL_FLOAT, (4, 4))
- tri_co = bgl.Buffer(bgl.GL_FLOAT, (3, 3))
- edge_co = bgl.Buffer(bgl.GL_FLOAT, (2, 3))
- vert_co = bgl.Buffer(bgl.GL_FLOAT, 3)
+ # returns of public API #
+ cls.vert_index = bgl.Buffer(bgl.GL_INT, 1)
+
+ cls.tri_co = bgl.Buffer(bgl.GL_FLOAT, (3, 3))
+ cls.edge_co = bgl.Buffer(bgl.GL_FLOAT, (2, 3))
+ cls.vert_co = bgl.Buffer(bgl.GL_FLOAT, 3)
def __init__(self, obj, draw_tris, draw_edges, draw_verts):
+ GPU_Indices_Mesh.init_opengl()
+
self._NULL = gl_buffer_void_as_long(0)
self.MVP = bgl.Buffer(bgl.GL_FLOAT, (4, 4))
@@ -463,6 +473,7 @@ def _restore_shader_state(cls):
def gpu_Indices_enable_state():
_store_current_shader_state(PreviousGLState)
+ GPU_Indices_Mesh.init_opengl()
bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
#bgl.glBindVertexArray(GPU_Indices_Mesh.vao[0])
@@ -477,6 +488,7 @@ def gpu_Indices_use_clip_planes(rv3d, value):
planes = bgl.Buffer(bgl.GL_FLOAT, (6, 4), rv3d.clip_planes)
_store_current_shader_state(PreviousGLState)
+ GPU_Indices_Mesh.init_opengl()
bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
bgl.glUniform1i(GPU_Indices_Mesh.unif_use_clip_planes, value)