diff options
Deprecate MomentsVertexBuffer
Not necessary and failed on some systems for some unknown reason.
-rw-r--r-- | channel_2d_streamlines_gl_interop.py | 1 | ||||
-rw-r--r-- | channel_3d_gl_interop.py | 6 | ||||
-rw-r--r-- | template/opengl.mako | 42 | ||||
-rw-r--r-- | trugfeuer_2d_gl_interop.py | 48 | ||||
-rw-r--r-- | utility/opengl.py | 54 |
5 files changed, 3 insertions, 148 deletions
diff --git a/channel_2d_streamlines_gl_interop.py b/channel_2d_streamlines_gl_interop.py index 7c370a2..544d40a 100644 --- a/channel_2d_streamlines_gl_interop.py +++ b/channel_2d_streamlines_gl_interop.py @@ -2,7 +2,6 @@ import numpy from string import Template from simulation import Lattice, Geometry -from utility.opengl import MomentsVertexBuffer from utility.streamline import Streamlines from symbolic.generator import LBM diff --git a/channel_3d_gl_interop.py b/channel_3d_gl_interop.py index 535d595..376276c 100644 --- a/channel_3d_gl_interop.py +++ b/channel_3d_gl_interop.py @@ -17,7 +17,6 @@ from geometry.box import Box from geometry.cylinder import Cylinder from utility.projection import Projection, Rotation -from utility.opengl import MomentsVertexBuffer from utility.mouse import MouseDragMonitor, MouseScrollMonitor lattice_x = 256 @@ -211,11 +210,8 @@ primitives = list(map(lambda material: material[0], filter(lambda material: no lattice.apply_material_map(material_map) lattice.sync_material() -moments_vbo = MomentsVertexBuffer(lattice) - particles = Particles( lattice, - moments_vbo, numpy.mgrid[ 2*lattice.geometry.size_x//100:4*lattice.geometry.size_x//100:particle_count/10000j, lattice.geometry.size_y//16:15*lattice.geometry.size_y//16:100j, @@ -231,7 +227,7 @@ def on_display(): for i in range(0,updates_per_frame): lattice.evolve() - moments_vbo.collect() + lattice.update_moments() for i in range(0,updates_per_frame): particles.update(aging = True) diff --git a/template/opengl.mako b/template/opengl.mako index 6958db8..daf5f66 100644 --- a/template/opengl.mako +++ b/template/opengl.mako @@ -13,49 +13,7 @@ def moments_cell(): 2: '(int2)(get_global_id(0), get_global_id(1))', 3: '(int4)(get_global_id(0), get_global_id(1), get_global_id(2), 0)' }.get(descriptor.d) -%> - -__kernel void collect_gl_moments(__global ${float_type}* f, - __global int* material, - __global float4* moments) -{ - const unsigned int gid = ${gid()}; - - __global ${float_type}* preshifted_f = f + gid; - -% for i in range(0,descriptor.q): - const ${float_type} f_curr_${i} = preshifted_f[${pop_offset(i)}]; -% endfor - -% for i, expr in enumerate(moments_subexpr): - const ${float_type} ${expr[0]} = ${ccode(expr[1])}; -% endfor - - float4 data; - - if (material[gid] == 1) { -% if descriptor.d == 2: - data.x = ${ccode(moments_assignment[0].rhs)}; - data.y = ${ccode(moments_assignment[1].rhs)}; - data.z = ${ccode(moments_assignment[2].rhs)}; - data.w = sqrt(data.y*data.y + data.z*data.z); -% elif descriptor.d == 3: - data.x = ${ccode(moments_assignment[0].rhs)}; - data.y = ${ccode(moments_assignment[1].rhs)}; - data.z = ${ccode(moments_assignment[2].rhs)}; - data.w = ${ccode(moments_assignment[3].rhs)}; -% endif - } else { - data.x = 0.0; - data.y = 0.0; - data.z = 0.0; - data.w = -material[gid]; - } - - moments[gid] = data; -} -<% def neighbor_offset(c_i): return { 2: lambda: c_i[1]*memory.size_x + c_i[0], diff --git a/trugfeuer_2d_gl_interop.py b/trugfeuer_2d_gl_interop.py index 969fe4f..b2ec534 100644 --- a/trugfeuer_2d_gl_interop.py +++ b/trugfeuer_2d_gl_interop.py @@ -2,7 +2,6 @@ import numpy from string import Template from simulation import Lattice, Geometry -from utility.opengl import MomentsVertexBuffer from utility.particles import Particles from symbolic.generator import LBM @@ -86,38 +85,6 @@ lbm = LBM(D2Q9) window = glut_window(fullscreen = False) -vertex_shader = shaders.compileShader(Template(""" -#version 430 - -layout (location=0) in vec4 CellMoments; - -out vec3 color; - -uniform mat4 projection; - -vec2 fluidVertexAtIndex(uint i) { - const float y = floor(float(i) / $size_x); - return vec2( - i - $size_x*y, - y - ); -} - -void main() { - const vec2 idx = fluidVertexAtIndex(gl_VertexID); - - gl_Position = projection * vec4(idx.x, idx.y, 0., 1.); - - if (CellMoments[3] > 0.0) { - color = vec3(0.0,0.0,0.0); - } else { - color = vec3(0.4,0.4,0.4); - } -}""").substitute({ - 'size_x': lattice_x, - 'size_y': lattice_y -}), GL_VERTEX_SHADER) - fragment_shader = shaders.compileShader(""" #version 430 @@ -158,9 +125,8 @@ void main() { 'size_y': lattice_y }), GL_VERTEX_SHADER) -moment_program = shaders.compileProgram(vertex_shader, fragment_shader) particle_program = shaders.compileProgram(particle_shader, fragment_shader) -projection_id = shaders.glGetUniformLocation(moment_program, 'projection') +projection_id = shaders.glGetUniformLocation(particle_program, 'projection') lattice = Lattice( descriptor = D2Q9, @@ -175,11 +141,8 @@ lattice.apply_material_map( get_channel_material_map(lattice.geometry)) lattice.sync_material() -moments_vbo = MomentsVertexBuffer(lattice) - particles = Particles( lattice, - moments_vbo, numpy.mgrid[ 4*lattice.geometry.size_x//9:5*lattice.geometry.size_x//9:particle_count/100j, lattice.geometry.size_y//20:2*lattice.geometry.size_y//20:100j, @@ -189,7 +152,7 @@ def on_display(): for i in range(0,updates_per_frame): lattice.evolve() - moments_vbo.collect() + lattice.update_moments() for i in range(0,updates_per_frame): particles.update(aging = True) @@ -198,13 +161,6 @@ def on_display(): glClear(GL_COLOR_BUFFER_BIT) - shaders.glUseProgram(moment_program) - glUniformMatrix4fv(projection_id, 1, False, numpy.ascontiguousarray(projection)) - moments_vbo.bind() - glPointSize(point_size) - glDisable(GL_POINT_SMOOTH) - glDrawArrays(GL_POINTS, 0, lattice.geometry.volume) - shaders.glUseProgram(particle_program) glUniformMatrix4fv(projection_id, 1, False, numpy.ascontiguousarray(projection)) particles.bind() diff --git a/utility/opengl.py b/utility/opengl.py index f305eae..456259b 100644 --- a/utility/opengl.py +++ b/utility/opengl.py @@ -8,60 +8,6 @@ from mako.template import Template from pathlib import Path from OpenGL.GL import * -from OpenGL.arrays import vbo - -class MomentsVertexBuffer: - def __init__(self, lattice): - self.lattice = lattice - - self.np_moments = numpy.ndarray(shape=(self.lattice.memory.volume, 4), dtype=self.lattice.memory.float_type) - self.gl_moments = vbo.VBO(data=self.np_moments, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) - self.gl_moments.bind() - self.cl_gl_moments = cl.GLBuffer(self.lattice.context, mf.READ_WRITE, int(self.gl_moments)) - - self.build_kernel() - - def build_kernel(self): - program_src = Template(filename = str(Path(__file__).parent/'../template/opengl.mako')).render( - descriptor = self.lattice.descriptor, - geometry = self.lattice.geometry, - memory = self.lattice.memory, - - moments_subexpr = self.lattice.moments[0], - moments_assignment = self.lattice.moments[1], - collide_subexpr = self.lattice.collide[0], - collide_assignment = self.lattice.collide[1], - - float_type = self.lattice.float_type[1], - - ccode = sympy.ccode - ) - self.program = cl.Program(self.lattice.context, program_src).build(self.lattice.compiler_args) - - def bind(self): - self.gl_moments.bind() - glEnableClientState(GL_VERTEX_ARRAY) - glVertexPointer(4, GL_FLOAT, 0, self.gl_moments) - - def collect(self): - cl.enqueue_acquire_gl_objects(self.lattice.queue, [self.cl_gl_moments]) - - if self.lattice.tick: - self.program.collect_gl_moments( - self.lattice.queue, - self.lattice.grid.size(), - self.lattice.layout, - self.lattice.memory.cl_pop_b, - self.lattice.memory.cl_material, - self.cl_gl_moments) - else: - self.program.collect_gl_moments( - self.lattice.queue, - self.lattice.grid.size(), - self.lattice.layout, - self.lattice.memory.cl_pop_a, - self.lattice.memory.cl_material, - self.cl_gl_moments) class MomentsTexture: |