Skip to content

Commit

Permalink
closes #4915
Browse files Browse the repository at this point in the history
  • Loading branch information
Durman committed Jul 25, 2023
1 parent f27c936 commit 9418e39
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def screen_v3dBGL(context, args):

points = args[0]
colors = args[1] # expects 4-tuple r g b a
shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
shader = gpu.shader.from_builtin(shader_name)
batch = batch_for_shader(shader, 'POINTS', {"pos": points, "color": colors})
batch.draw(shader)

Expand Down
6 changes: 4 additions & 2 deletions nodes/solid/solid_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def draw_uniform(GL_KIND, coords, indices, color, width=1, dashed_data=None):

else:
# print(GL_KIND,coords)
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
shader = gpu.shader.from_builtin(shader_name)
batch = batch_for_shader(shader, GL_KIND, {"pos" : coords}, **params)
shader.bind()
shader.uniform_float("color", color)
Expand All @@ -117,7 +118,8 @@ def draw_uniform(GL_KIND, coords, indices, color, width=1, dashed_data=None):


def draw_smooth(coords, vcols, indices=None):
shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
shader = gpu.shader.from_builtin(shader_name)
params = dict(indices=indices) if indices else {}
batch = batch_for_shader(shader, 'TRIS', {"pos" : coords, "color": vcols}, **params)
batch.draw(shader)
Expand Down
3 changes: 2 additions & 1 deletion nodes/viz/vd_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from sverchok.node_tree import SverchCustomTreeNode

if not bpy.app.background:
smooth_2d_shader = gpu.shader.from_builtin('2D_SMOOTH_COLOR')
shader_name = f'{"2D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
smooth_2d_shader = gpu.shader.from_builtin(shader_name)
else:
smooth_2d_shader = None

Expand Down
10 changes: 6 additions & 4 deletions nodes/viz/viewer_draw_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,14 @@ def sv_init(self, context):
self.inputs.new('SvStringsSocket', 'Resolution').prop_name = 'resolution'

def draw_all(self, draw_inputs):

v_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
v_shader = gpu.shader.from_builtin(shader_name)
if self.draw_curvature:
e_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
e_shader = gpu.shader.from_builtin(shader_name)
else:
e_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
e_shader = gpu.shader.from_builtin(shader_name)

draw_data = {
'tree_name': self.id_data.name[:],
Expand Down
18 changes: 12 additions & 6 deletions nodes/viz/viewer_draw_mk4.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,28 +455,34 @@ def generate_mesh_geom(config, vecs_in):

if config.draw_verts:
if config.uniform_verts:
config.v_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
config.v_shader = gpu.shader.from_builtin(shader_name)
else:
config.v_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
config.v_shader = gpu.shader.from_builtin(shader_name)
geom.v_vertices, geom.points_color = v_vertices, points_color

if config.draw_edges:
if config.edges_use_vertex_color and e_vertices:
e_vertex_colors = points_color
if config.uniform_edges:
config.e_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
config.e_shader = gpu.shader.from_builtin(shader_name)
else:
config.e_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
config.e_shader = gpu.shader.from_builtin(shader_name)
geom.e_vertices, geom.e_vertex_colors, geom.e_indices = e_vertices, e_vertex_colors, e_indices


if config.draw_polys and config.shade_mode != 'fragment':
if config.uniform_pols:
config.p_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
config.p_shader = gpu.shader.from_builtin(shader_name)
else:
if config.polygon_use_vertex_color and config.shade_mode not in ['facet', 'smooth']:
p_vertex_colors = points_color
config.p_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
config.p_shader = gpu.shader.from_builtin(shader_name)
geom.p_vertices, geom.p_vertex_colors, geom.p_indices = p_vertices, p_vertex_colors, p_indices

elif config.shade_mode == 'fragment' and config.draw_polys:
Expand Down
10 changes: 6 additions & 4 deletions nodes/viz/viewer_draw_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ def draw_buttons_ext(self, context, layout):
self.draw_buttons(context, layout)

def draw_all(self, draw_inputs):

v_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
e_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
p_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
v_shader = gpu.shader.from_builtin(shader_name)
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
e_shader = gpu.shader.from_builtin(shader_name)
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
p_shader = gpu.shader.from_builtin(shader_name)

draw_data = {
'tree_name': self.id_data.name[:],
Expand Down
7 changes: 4 additions & 3 deletions old_nodes/vd_draw_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def draw_uniform(GL_KIND, coords, indices, color, width=1, dashed_data=None):
batch.draw(shader)

else:

shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
shader = gpu.shader.from_builtin(shader_name)
batch = batch_for_shader(shader, GL_KIND, {"pos" : coords}, **params)
shader.bind()
shader.uniform_float("color", color)
Expand All @@ -170,7 +170,8 @@ def draw_uniform(GL_KIND, coords, indices, color, width=1, dashed_data=None):


def draw_smooth(coords, vcols, indices=None):
shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
shader = gpu.shader.from_builtin(shader_name)
params = dict(indices=indices) if indices else {}
batch = batch_for_shader(shader, 'TRIS', {"pos" : coords, "color": vcols}, **params)
batch.draw(shader)
Expand Down
3 changes: 2 additions & 1 deletion utils/nodeview_time_graph_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def start_time_graph(ng):
ng.update_gl_scale_info(origin=f"configure_time_graph, tree: {ng.name}")

named_tree = ng.name
shader = gpu.shader.from_builtin('2D_SMOOTH_COLOR')
shader_name = f'{"2D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
shader = gpu.shader.from_builtin(shader_name)
data_overlay = (None, shader, named_tree)

config_graph_overlay = {
Expand Down
7 changes: 4 additions & 3 deletions utils/sv_batch_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def draw_matrix(self, *args, **kwargs):
sv_logger.info("draw_matrix: do nothing in background mode")

else:

uniform_shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
smooth_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
uniform_shader = gpu.shader.from_builtin(shader_name)
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
smooth_shader = gpu.shader.from_builtin(shader_name)


class MatrixDraw28(object):
Expand Down
3 changes: 2 additions & 1 deletion utils/sv_idx_viewer28_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ def draw_all_text_at_once(final_draw_data):
add_vcol((col,) * 6)

# draw background
shader = gpu.shader.from_builtin('2D_SMOOTH_COLOR')
shader_name = f'{"2D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
shader = gpu.shader.from_builtin(shader_name)
batch = batch_for_shader(shader, 'TRIS', {"pos": full_bg_Verts, "color": full_bg_colors})
batch.draw(shader)

Expand Down

0 comments on commit 9418e39

Please sign in to comment.