+# GPU and viewport drawing
+# ------------------------------------------------------------------------------
+
+# Handlers
+cxr_view_draw_handler = None
+cxr_ui_draw_handler = None
+
+# Batches
+cxr_view_lines = None
+cxr_view_mesh = None
+cxr_jobs_batch = None
+cxr_jobs_inf = []
+
+# Shaders
+cxr_view_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
+cxr_ui_shader = gpu.types.GPUShader("""
+uniform mat4 ModelViewProjectionMatrix;
+uniform float scale;
+
+in vec2 aPos;
+in vec4 aColour;
+
+out vec4 colour;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(aPos.x*scale,aPos.y, 0.0, 1.0);
+ colour = aColour;
+}
+""","""
+in vec4 colour;
+out vec4 FragColor;
+
+void main()
+{
+ FragColor = colour;
+}
+""")
+
+# Render functions
+#
+def cxr_ui(_,context):
+ global cxr_jobs_batch, cxr_ui_shader, cxr_jobs_inf
+
+ w = gpu.state.viewport_get()[2]
+ cxr_ui_shader.bind()
+ cxr_ui_shader.uniform_float( "scale", w )
+
+ if cxr_jobs_batch != None:
+ gpu.state.blend_set('ALPHA')
+ cxr_jobs_batch.draw(cxr_ui_shader)
+
+ blf.position(0,2,50,0)
+ blf.size(0,50,48)
+ blf.color(0,1.0,1.0,1.0,1.0)
+ blf.draw(0,"Compiling")
+
+ for ji in cxr_jobs_inf:
+ blf.position(0,ji[0]*w,35,0)
+ blf.size(0,50,20)
+ blf.draw(0,ji[1])
+
+ if CXR_PREVIEW_OPERATOR.LASTERR != None:
+ blf.position(0,2,80,0)
+ blf.size(0,50,48)
+ blf.color(0,1.0,0.2,0.2,0.9)
+ blf.draw(0,"This is a stoopid error\nWIthiuawdnaw")
+
+ # Something is off with TIMER,
+ # this forces the viewport to redraw before we can continue with our
+ # compilation stuff.
+
+ CXR_COMPILER_CHAIN.WAIT_REDRAW = False
+
+def cxr_draw():
+ global cxr_view_shader, cxr_view_mesh, cxr_view_lines
+
+ cxr_view_shader.bind()
+
+ gpu.state.depth_mask_set(False)
+ gpu.state.line_width_set(1.5)
+ gpu.state.face_culling_set('BACK')
+ gpu.state.depth_test_set('NONE')
+ gpu.state.blend_set('ALPHA')
+
+ if cxr_view_lines != None:
+ cxr_view_lines.draw( cxr_view_shader )
+
+ gpu.state.depth_test_set('LESS_EQUAL')
+ gpu.state.blend_set('ADDITIVE')
+ if cxr_view_mesh != None:
+ cxr_view_mesh.draw( cxr_view_shader )
+
+def cxr_jobs_update_graph(jobs):
+ global cxr_jobs_batch, cxr_ui_shader, cxr_jobs_inf
+
+ cxr_jobs_inf = []
+
+ total_width = 0
+ verts = []
+ colours = []
+ indices = []
+
+ for sys in jobs:
+ total_width += sys['w']
+
+ sf = 1.0/total_width
+ cur = 0.0
+ ci = 0
+
+ for sys in jobs:
+ w = sys['w']
+ h = 30.0
+ colour = sys['colour']
+ colourwait = (colour[0],colour[1],colour[2],0.4)
+ colourrun = (colour[0]*1.5,colour[1]*1.5,colour[2]*1.5,0.5)
+ colourdone = (colour[0],colour[1],colour[2],1.0)
+
+ jobs = sys['jobs']
+ sfsub = (1.0/(len(jobs)))*w
+ i = 0
+
+ for j in jobs:
+ if j == None: colour = colourdone
+ else: colour = colourwait
+
+ px = (cur + (i)*sfsub) * sf
+ px1 = (cur + (i+1.0)*sfsub) * sf - 0.003
+ i += 1
+
+ verts += [(px,0), (px, h), (px1, 0.0), (px1,h)]
+ colours += [colour,colour,colour,colour]
+ indices += [(ci+0,ci+2,ci+3),(ci+0,ci+3,ci+1)]
+ ci += 4
+
+ cxr_jobs_inf += [((sf*cur), sys['title'])]
+ cur += w
+
+ cxr_jobs_batch = batch_for_shader(
+ cxr_ui_shader, 'TRIS',
+ { "aPos": verts, "aColour": colours },
+ indices = indices
+ )
+
+# view_layer.update() doesnt seem to work,
+# tag_redraw() seems to have broken
+# therefore, change a property
+def scene_redraw():
+ ob = bpy.context.scene.objects[0]
+ ob.hide_render = ob.hide_render
+
+ # the 'real' way to refresh the scene
+ for area in bpy.context.window.screen.areas:
+ if area.type == 'view_3d':
+ area.tag_redraw()