From abbdbe64d12af732983bc11aac772d3d32682bb5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 20 Jan 2020 22:40:44 +0100 Subject: Extract OpenCL setup into Renderer --- bluedot.py | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) (limited to 'bluedot.py') diff --git a/bluedot.py b/bluedot.py index 42bb9bc..975b106 100644 --- a/bluedot.py +++ b/bluedot.py @@ -1,13 +1,8 @@ import numpy import matplotlib.pyplot as plt -from string import Template -import pyopencl as cl -from pyopencl.cltypes import make_double3 - -mf = cl.mem_flags - -from planets import earth +from firmament import Renderer +from firmament.planets import earth config = { 'size_x': 1000, @@ -25,29 +20,12 @@ config = { sun_range = (0, 360, 10) -cl_platform = cl.get_platforms()[0] -cl_context = cl.Context(properties=[(cl.context_properties.PLATFORM, cl_platform)]) -cl_queue = cl.CommandQueue(cl_context) - -cl_picture = cl.Buffer(cl_context, mf.WRITE_ONLY, size=config['size_x']*config['size_y']*3*numpy.float64(0).nbytes) -program = None - -with open('raymarch.cl') as f: - program = cl.Program(cl_context, Template(f.read()).substitute( - {**config, **earth} - )).build() +renderer = Renderer(config, earth) for i in numpy.arange(*sun_range): - sun = make_double3(numpy.cos(i*2*numpy.pi/360),numpy.sin(i*2*numpy.pi/360),0) + sun = (numpy.cos(i*2*numpy.pi/360), numpy.sin(i*2*numpy.pi/360), 0) print(sun) - program.render_pinhole( - cl_queue, (config['size_x'], config['size_y']), None, cl_picture, - make_double3(*(config['eye_pos'] * earth['earth_radius'])), - make_double3(*(config['eye_dir'] * earth['earth_radius'])), - sun) - - np_picture = numpy.ndarray(shape=(config['size_y'], config['size_x'], 3), dtype=numpy.float64) - cl.enqueue_copy(cl_queue, np_picture, cl_picture).wait(); + np_picture = renderer.render_pinhole(sun) plt.imsave("bluedot_%05.1f.png" % i, np_picture, origin='lower') -- cgit v1.2.3