Giter Site home page Giter Site logo

Comments (3)

Quasimondo avatar Quasimondo commented on July 19, 2024 1

Thanks - I am happy if this motivates you to improve this library since it is really great for standalone work on affordable hardware! But yeah this definitely needs to be generalized more and the socket stuff also needs some more error handling and recovery from disconnect.

from kms-glsl.

astefanutti avatar astefanutti commented on July 19, 2024

Thanks a lot! This really gives a good idea of what a socket based approach would look like.

I still need to review the solution space, and probably the problem space a little bit :). I'd really like to come up with a solution that's be generic and versatile.

Anyhow, your proposition is a very good candidate, and gives us a good baseline to start with.

I'll keep you posted here ASAP.

from kms-glsl.

astefanutti avatar astefanutti commented on July 19, 2024

@Quasimondo I've been able to iterate on this, and finally landed on another approach that provides a Python wrapper around the native library.

I've just merged #21 that contains the bulk of the work. You'll be able to find some examples on how to bring your own inputs in the glsl.py file here:

kms-glsl/glsl.py

Lines 19 to 126 in f853855

'''
"""
Example #1:
- Given the following uniform is declared in the shader:
uniform int variable;
- Extend the Input class, and set the value of the uniform
in the render method.
- Create an instance with the uniform variable name.
"""
class Variable(Input):
value = 0
def init(self, program, width, height):
"""
This method is called once after the program has been set up,
before the rendering starts. It can be used to further initialise
the input, using the `glsl` variable, that exposes OpenGL ES APIs.
Args:
program:
The handle to the current program object.
width:
The width of the viewport.
height:
The height of the viewport.
"""
super().init(program, width, height)
def render(self, frame, time):
"""
This method is called for every frame. It can be used to update
the rendering state, using the `glsl` variable, that exposes OpenGL ES APIs.
Args:
frame:
The current frame index, or frames since start time.
time:
The elapsed time since start time, in seconds.
"""
self.value += 1
glsl.glUniform1ui(self.loc, self.value)
Variable('variable')
'''
'''
"""
Example #2:
- Given the following uniforms are declared in the shader:
uniform int iAux0;
uniform vec4 iAux1;
- Declare an init callback function to retrieve the location
of the uniform variables.
- Declare a render callback function to set the uniform values
before each frame is rendered.
- Register the two callback functions.
"""
iAux0 = iAux1 = None
vAux0 = 0
vAux1 = [0] * 4
@CFUNCTYPE(None, c_uint, c_uint, c_uint)
def init(program, width, height):
"""
This function is called once after the program has been set up,
before the rendering starts. It can be used to further initialise
the program, using the `glsl` variable, that exposes OpenGL ES APIs.
Args:
program:
The handle to the current program object.
width:
The width of the viewport.
height:
The height of the viewport.
"""
global iAux0, iAux1
iAux0 = glsl.glGetUniformLocation(program, b'iAux0')
iAux1 = glsl.glGetUniformLocation(program, b'iAux1')
@CFUNCTYPE(None, c_uint64, c_float)
def render(frame, time):
"""
This function is called for every frame. It can be used to update
the rendering state, using the `glsl` variable, that exposes OpenGL ES APIs.
Args:
frame:
The current frame index, or frames since start time.
time:
The elapsed time since start time, in seconds.
"""
global vAux0, vAux1
vAux0 += 1
glsl.glUniform1ui(iAux0, vAux0)
vAux1 = [vAux0] * 4
glsl.glUniform4f(iAux1, vAux1[0], vAux1[1], vAux1[2], vAux1[3])
glsl.onInit(init)
glsl.onRender(render)
'''

Do not hesitate to share any feedback or ideas you might have 🙏🏼.

from kms-glsl.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.