Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bgl replacement (and other 3.5 / 4.0 curiosities) #4983

Merged
merged 45 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b5aadd3
remove unused imports
zeffii Aug 15, 2023
54851df
mini-license
zeffii Aug 15, 2023
cd576b1
finish solid_viewer.py
zeffii Aug 15, 2023
381ef82
prelim buffer tests
zeffii Aug 15, 2023
20ab90b
vd_matrix done
zeffii Aug 15, 2023
a3aaa49
fixup consolenode
zeffii Aug 15, 2023
d8a6e84
fix viewer2d
zeffii Aug 15, 2023
ab40041
update viewer_draw_curve
zeffii Aug 15, 2023
828e6f8
freeup vdmk4
zeffii Aug 15, 2023
0feb325
vd_surface
zeffii Aug 15, 2023
dfd1905
fix up viewer_texture
zeffii Aug 15, 2023
16685f0
fixup tviewer lite
zeffii Aug 15, 2023
d0e32e3
rm unused import
zeffii Aug 15, 2023
bcd9cad
add back linewidth and pointsize
zeffii Aug 15, 2023
cc6d72d
good luck with parity
zeffii Aug 15, 2023
ed5754d
using classes instead of lambda
zeffii Aug 16, 2023
13cb438
update module docstring
zeffii Aug 16, 2023
1246bc4
restructure sv_texture_utils.py
zeffii Aug 16, 2023
c9d9a09
use dict for remap
zeffii Aug 16, 2023
68ff29f
resolve texture utils.py
zeffii Aug 18, 2023
8e84f13
remove bgl from texture_utils
zeffii Aug 18, 2023
82fef74
remove all traces of bgl from current node set and util files
zeffii Aug 18, 2023
a374a10
implement drawing.blf_size
zeffii Aug 18, 2023
cb860a1
whitespace
zeffii Aug 18, 2023
a70da89
testing 1..2..3...
zeffii Aug 18, 2023
70cf685
testing gpu.state
zeffii Aug 18, 2023
69b4b71
better format handler for init_image_from_texture
zeffii Aug 18, 2023
9614f28
test
zeffii Aug 18, 2023
8c9f8bd
saul goodman
zeffii Aug 18, 2023
76095ff
better names
zeffii Aug 19, 2023
abb0084
add some contents
zeffii Aug 19, 2023
04915ce
fix typo
zeffii Aug 20, 2023
9893056
solid_viewer using shading_3d constant
zeffii Aug 20, 2023
e22319a
replace currently used versions of smooth/uniform to shader_3d/2d ver…
zeffii Aug 20, 2023
709330e
missed import reference
zeffii Aug 20, 2023
d699e59
test 2FA
zeffii Aug 28, 2023
21d7901
experiment with geomcode
zeffii Sep 4, 2023
b81a8a9
testing passthrough
zeffii Sep 17, 2023
e3279a4
this pushes polygons back... by offset = vec4(small_normal, 0.0)
zeffii Sep 18, 2023
65ae489
remove some dead glsl
zeffii Sep 18, 2023
aa3531c
vec4 to 3
zeffii Sep 18, 2023
7015210
layout not needed
zeffii Sep 18, 2023
0cd3c3a
finally fragment shader in perspective mode shows normals
zeffii Sep 19, 2023
8a06038
remove dud glsl code
zeffii Sep 20, 2023
90f9205
remove last bit of unused default shader code
zeffii Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions nodes/number/easing.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE


from mathutils import Vector
import bpy
from bpy.props import FloatProperty, EnumProperty, StringProperty, BoolProperty

import blf
import bgl
import gpu
from gpu_extras.batch import batch_for_shader

Expand Down
35 changes: 16 additions & 19 deletions nodes/solid/solid_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from math import pi
import numpy as np

import bgl
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
Expand All @@ -23,6 +22,7 @@
from sverchok.utils.sv_shader_sources import dashed_vertex_shader, dashed_fragment_shader
from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata
from sverchok.utils.modules.geom_utils import obtain_normal3 as normal
from sverchok.utils.modules.drawing_abstractions import drawing, shading_3d

from sverchok.dependencies import FreeCAD
if FreeCAD is not None:
Expand Down Expand Up @@ -83,9 +83,9 @@ def generate_normals_data(verts, faces):

def draw_uniform(GL_KIND, coords, indices, color, width=1, dashed_data=None):
if GL_KIND == 'LINES':
bgl.glLineWidth(width)
drawing.set_line_width(width)
elif GL_KIND == 'POINTS':
bgl.glPointSize(width)
drawing.set_point_size(width)

params = dict(indices=indices) if indices else {}

Expand All @@ -102,24 +102,21 @@ def draw_uniform(GL_KIND, coords, indices, color, width=1, dashed_data=None):
batch.draw(shader)

else:
# print(GL_KIND,coords)
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}UNIFORM_COLOR'
shader = gpu.shader.from_builtin(shader_name)
shader = gpu.shader.from_builtin(shading_3d.UNIFORM_COLOR)
batch = batch_for_shader(shader, GL_KIND, {"pos" : coords}, **params)
shader.bind()
shader.uniform_float("color", color)

batch.draw(shader)

if GL_KIND == 'LINES':
bgl.glLineWidth(1)
drawing.reset_line_width()
elif GL_KIND == 'POINTS':
bgl.glPointSize(1)
drawing.reset_point_size()


def draw_smooth(coords, vcols, indices=None):
shader_name = f'{"3D_" if bpy.app.version < (3, 4) else ""}SMOOTH_COLOR'
shader = gpu.shader.from_builtin(shader_name)
shader = gpu.shader.from_builtin(shading_3d.SMOOTH_COLOR)
params = dict(indices=indices) if indices else {}
batch = batch_for_shader(shader, 'TRIS', {"pos" : coords, "color": vcols}, **params)
batch.draw(shader)
Expand Down Expand Up @@ -181,13 +178,12 @@ def face_geom(geom, config):

def draw_faces_uniform(context, args):
geom, config = args
# print(geom.f_faces, config.shade)
if config.draw_gl_wireframe:
bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_LINE)
drawing.set_polygonmode_line()

if config.draw_gl_polygonoffset:
bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
bgl.glPolygonOffset(1.0, 1.0)
drawing.enable_polygon_offset_fill()
drawing.set_polygon_offset_amounts()

if config.shade == "flat":
draw_uniform('TRIS', geom.f_verts, geom.f_faces, config.face4f)
Expand All @@ -199,7 +195,8 @@ def draw_faces_uniform(context, args):
draw_smooth(geom.f_verts, geom.smooth_vnorms, indices=geom.f_faces)

if config.draw_gl_wireframe:
bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
# this is to reset the state of drawing to fill
drawing.set_polygonmode_fill()


def edges_geom(geom, config):
Expand Down Expand Up @@ -231,10 +228,10 @@ def edges_geom(geom, config):
def draw_complex(context, args):
geom, config = args
if config.draw_gl_polygonoffset:
bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)
drawing.disable_polygon_offset_fill()

if config.shade != 'normals':
bgl.glEnable(bgl.GL_BLEND)
drawing.enable_blendmode()

if config.display_edges:
draw_lines_uniform(context, config, geom.e_vertices, geom.e_edges, config.line4f, config.line_width)
Expand All @@ -243,10 +240,10 @@ def draw_complex(context, args):
if config.display_verts:
draw_uniform('POINTS', geom.verts, None, config.vcol, config.point_size)
if config.shade != 'normals':
bgl.glDisable(bgl.GL_BLEND)
drawing.disable_blendmode()
if config.draw_gl_polygonoffset:
# or restore to the state found when entering this function. TODO!
bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)
drawing.disable_polygon_offset_fill()


class SvSolidViewerNode(SverchCustomTreeNode, bpy.types.Node):
Expand Down
29 changes: 9 additions & 20 deletions nodes/viz/console_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import itertools

import bpy
import bgl
import gpu
from gpu_extras.batch import batch_for_shader

Expand All @@ -23,6 +22,7 @@
from sverchok.utils.sv_update_utils import sv_get_local_path
from sverchok.utils.sv_font_xml_parser import get_lookup_dict, letters_to_uv
from sverchok.utils.sv_nodeview_draw_helper import SvNodeViewDrawMixin, get_console_grid
from sverchok.utils.modules.drawing_abstractions import drawing
#from sverchok.utils.decorators_compilation import njit

def get_desired_xy(node):
Expand Down Expand Up @@ -391,8 +391,8 @@ def terminal_text_to_uv(lines):

def simple_console_xy(context, args, loc):
texture, config = args
act_tex = bgl.Buffer(bgl.GL_INT, 1)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture.texture_dict['texture'])
act_tex = drawing.new_buffer_texture()
drawing.bind_texture_2d(texture.texture_dict['texture'])
config.shader.bind()

# if not config.syntax_mode == "None":
Expand Down Expand Up @@ -513,13 +513,13 @@ def get_font_texture(self):
dsize = data.size
data = data.repeat(3).reshape(-1, 3)
data = np.concatenate((data, np.ones(dsize)[:,None]),axis=1).flatten()
name = bgl.Buffer(bgl.GL_INT, 1)
bgl.glGenTextures(1, name)
name = drawing.new_buffer_texture()
drawing.generate_textures(name)

self.texture_dict['texture'] = name[0]
self.texture_dict['texture_data'] = data # bgl.Buffer(bgl.GL_FLOAT, data.size, data.tolist())
self.texture_dict['texture_data'] = data

# return self.texture_dict.get('texture')


def sv_init(self, context):
self.inputs.new("SvStringsSocket", "text")
self.id_data.update_gl_scale_info()
Expand All @@ -543,23 +543,12 @@ def draw_buttons_ext(self, context, layout):
for color_name in lexed_colors:
row = col.row()
row.prop(self, color_name)


def init_texture(self, width, height):
clr = bgl.GL_RGBA
texname = self.texture_dict['texture']
data = self.texture_dict['texture_data']
drawing.init_complex_texture(width, height, texname, data, 'RGBA')

texture = bgl.Buffer(bgl.GL_FLOAT, data.size, data.tolist())
bgl.glPixelStorei(bgl.GL_UNPACK_ALIGNMENT, 1)
bgl.glEnable(bgl.GL_TEXTURE_2D)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, texname)
bgl.glActiveTexture(bgl.GL_TEXTURE0)
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_S, bgl.GL_CLAMP_TO_EDGE)
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_T, bgl.GL_CLAMP_TO_EDGE)
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, clr, width, height, 0, clr, bgl.GL_FLOAT, texture)

def set_node_props(self, socket_data):
multiline, (chars_x, chars_y) = text_decompose('\n'.join(socket_data), self.last_n_lines)
Expand Down
37 changes: 13 additions & 24 deletions nodes/viz/vd_matrix.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####


import bgl
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE



import bpy
import gpu
from gpu_extras.batch import batch_for_shader
Expand All @@ -29,10 +18,10 @@
from sverchok.utils.sv_batch_primitives import MatrixDraw28
from sverchok.data_structure import node_id, updateNode
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.utils.modules.drawing_abstractions import drawing, shading_2d

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

Expand Down Expand Up @@ -77,9 +66,9 @@ def screen_v3d_batch_matrix_overlay(context, args):
indices=indices_shifted)

# smooth_2d_shader.bind()
bgl.glEnable( bgl.GL_BLEND )
drawing.enable_blendmode()
batch.draw(smooth_2d_shader)
bgl.glDisable( bgl.GL_BLEND )
drawing.disable_blendmode()


def match_color_to_matrix(node):
Expand Down
10 changes: 5 additions & 5 deletions nodes/viz/viewer_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import bpy
from bpy.props import FloatProperty, IntProperty, EnumProperty, BoolProperty, FloatVectorProperty, IntVectorProperty

import bgl
import gpu
from gpu_extras.batch import batch_for_shader

from sverchok.utils.modules.drawing_abstractions import drawing
from sverchok.data_structure import updateNode, node_id
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.ui import bgl_callback_nodeview as nvBGL
Expand Down Expand Up @@ -186,24 +186,24 @@ def view_2d_geom(x, y, args):
config.p_batch.draw(config.p_shader)

if config.draw_edges:
bgl.glLineWidth(config.edge_width)
drawing.set_line_width(config.edge_width)
config.e_batch = batch_for_shader(config.e_shader, 'LINES', {"pos": geom.e_vertices, "color": geom.e_vertex_colors}, indices=geom.e_indices)
config.e_shader.bind()
config.e_shader.uniform_float("x_offset", x)
config.e_shader.uniform_float("y_offset", y)
config.e_shader.uniform_float("viewProjectionMatrix", matrix)
config.e_batch.draw(config.e_shader)
bgl.glLineWidth(1)
drawing.reset_line_width()

if config.draw_verts:
bgl.glPointSize(config.point_size)
drawing.set_point_size(config.point_size)
config.v_batch = batch_for_shader(config.v_shader, 'POINTS', {"pos": geom.v_vertices, "color": geom.points_color})
config.v_shader.bind()
config.v_shader.uniform_float("x_offset", x)
config.v_shader.uniform_float("y_offset", y)
config.v_shader.uniform_float("viewProjectionMatrix", matrix)
config.v_batch.draw(config.v_shader)
bgl.glPointSize(1)
drawing.reset_point_size()


def path_from_nums(nums, x, y, num_width, num_height, maxmin, sys_scale):
Expand Down
Loading