import glnext import glwindow from glnext_compiler import glsl instance = glnext.instance(surface=True) task = instance.task() framebuffer = task.framebuffer((512, 512)) pipeline = framebuffer.render( vertex_shader=glsl(''' #version 450 #pragma shader_stage(vertex) layout (location = 0) out vec4 out_color; vec2 positions[3] = vec2[]( vec2(-0.5, -0.5), vec2(0.5, -0.5), vec2(0.0, 0.5) ); vec4 colors[3] = vec4[]( vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0) ); void main() { gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); out_color = colors[gl_VertexIndex];
import glnext import numpy as np from glnext_compiler import glsl from matplotlib import pyplot as plt from objloader import Obj instance = glnext.instance() task = instance.task() framebuffer = task.framebuffer((512, 512), '1f', samples=1) vertex_size = 12 mesh = Obj.open('examples/monkey.obj').pack('vx vy vz') vertex_count = len(mesh) // vertex_size pipeline = framebuffer.render( vertex_shader=glsl(''' #version 450 #pragma shader_stage(vertex) layout (binding = 0) uniform Buffer { mat4 mvp; }; layout (location = 0) in vec3 in_vert; layout (location = 0) out float out_depth; void main() { vec4 vert = mvp * vec4(in_vert, 1.0); gl_Position = vert;
def instance(): instance = glnext.instance( application_name='glnext_tests', debug=True, ) yield instance
import glnext import imageio import mymodule windows = mymodule.init() instance = glnext.instance(surface='VK_KHR_win32_surface') image = instance.image((640, 360), mode='output') buffer = instance.staging_buffer([[image]]) for wnd in windows: instance.surface(wnd, image) reader = imageio.get_reader('assets/bunny.mp4') for im in reader: buffer.write(glnext.rgba(im, 'rgb')) instance.run()
} ''') def create_pipeline(instance): task = instance.task() framebuffer = task.framebuffer((512, 512)) framebuffer.render( vertex_shader=vertex_shader, fragment_shader=fragment_shader, vertex_count=3, ) cache = b'' instance1 = glnext.instance(cache=cache) a = time.perf_counter_ns() create_pipeline(instance1) b = time.perf_counter_ns() cache = instance1.cache() instance2 = glnext.instance(cache=cache) c = time.perf_counter_ns() create_pipeline(instance2) d = time.perf_counter_ns() print('cache size:', len(cache)) print('without cache:', (b - a) / 1e6) print('with cache:', (d - c) / 1e6)