Comments (6)
Update: The data I'm interested in can be retrieved in OpenGL 3 using glGetProgramiv(program_glo, gl.GL_ACTIVE_UNIFORMS)
glGetUniformLocation
, glGetActiveUniformName
, and glGetActiveUniformsiv
. For reference, the docs for these functions and explanation for what attributes can be retrieved by glGetActiveUniformsiv
can be found here: https://www.khronos.org/opengl/wiki/Program_Introspection
from moderngl.
I just came across this issue, having to create arays of nested structures passed to a compute shader - and it was super painful. Having the proposed ability to generate the structure definitions on the fly, would have saved me a lot of pain.
from moderngl.
This will be implemented as a standalone module. It will most likely use the program interface query (seems to be available all the time but actually it is part of OpenGL 4.3+)
I have some local code for it. I just realized I did not push anything yet to https://github.com/szabolcsdombi/ubo
from moderngl.
I have some local code for it. I just realized I did not push anything yet to https://github.com/szabolcsdombi/ubo
I just came across this issue again. Could you kindly consider pushing your prototype code? Thay would be a real help in getting such complicated ctype definitions right.
from moderngl.
Here is a minimum working code for getting all the information needed to construct the layout:
import ctypes
from OpenGL import GL
program = zengl.inspect(pipeline)['program']
num_blocks = GL.glGetProgramiv(program, GL.GL_ACTIVE_UNIFORM_BLOCKS)
uniform_blocks = {}
for i in range(num_blocks):
name = (ctypes.c_byte * 100)()
length = ctypes.c_long()
GL.glGetActiveUniformBlockName(program, i, 100, ctypes.byref(length), ctypes.byref(name))
size = ctypes.c_long()
GL.glGetActiveUniformBlockiv(program, i, GL.GL_UNIFORM_BLOCK_DATA_SIZE, ctypes.byref(size))
name = bytes(name)[:length.value].decode()
uniform_blocks[i] = {'name': name, 'size': size.value, 'members': {}}
num_uniforms = GL.glGetProgramiv(program, GL.GL_ACTIVE_UNIFORMS)
uniforms = {}
for i in range(num_uniforms):
name = (ctypes.c_byte * 100)()
length = ctypes.c_long()
GL.glGetActiveUniformName(program, i, 100, ctypes.byref(length), ctypes.byref(name))
name = bytes(name)[:length.value].decode()
uniforms[i] = {'name': name}
uniform_indices = (ctypes.c_long * num_uniforms)()
for i in range(num_uniforms):
uniform_indices[i] = i
info = [
('gltype', GL.GL_UNIFORM_TYPE),
('block', GL.GL_UNIFORM_BLOCK_INDEX),
('offset', GL.GL_UNIFORM_OFFSET),
('array_size', GL.GL_UNIFORM_SIZE),
('array_stride', GL.GL_UNIFORM_ARRAY_STRIDE),
('matrix_stride', GL.GL_UNIFORM_MATRIX_STRIDE),
('row_major', GL.GL_UNIFORM_IS_ROW_MAJOR),
]
for key, pname in info:
params = (ctypes.c_long * num_uniforms)()
GL.glGetActiveUniformsiv(program, num_uniforms, ctypes.byref(uniform_indices), pname, ctypes.byref(params))
for i in range(num_uniforms):
uniforms[i][key] = params[i]
for i in range(num_uniforms):
if uniforms[i]['block'] != -1:
uniform_blocks[uniforms[i]['block']]['members'][uniforms[i]['name']] = uniforms[i]
print(uniform_blocks)
I did not continue work on this after I found out it takes a tremendous amount of effort to actually parse the output for arrays.
Please see Program_Introspection#Arrays.
struct Aggregate
{
vec2 main;
vec2 sec[3];
};
uniform Aggregate unifArray[5];
There is no uniform named unifArray. However, there is a uniform named unifArray[0].main. There is one named unifArray[2].sec[0], which is an array of basic types. There are five of each of these. As before, the bottom-level array can be clipped off: unifArray[2].sec is equivalent to unifArray[2].sec[0].
These rules are applied recursively up the hierarchy.
PS: replace program = zengl.inspect(pipeline)['program']
with program = my_moderngl_program.glo
from moderngl.
This should be a separate module so I am closing this here.
from moderngl.
Related Issues (20)
- How to use Moderngl.ext.obj.Obj HOT 1
- Feature request: Multiple shader sources per shader stage HOT 4
- Subroutine uniforms do not appear in `Program` members HOT 1
- ModernGL can't find OpenGL on my computer or shows error with the mode. HOT 5
- How to use glDepthMask() function with moderngl? HOT 1
- How to write value to a GLSL uniform array? HOT 2
- Local docs build is different from the online one HOT 6
- Allow accessing context from the module object HOT 1
- Create Compute Shaders with ctx.program() HOT 1
- Add an optimization hint/flag to ctx.texture() to support texture render targets without sampling HOT 1
- Implement texture.use, texture.repeat_x and similar with an internal sampler object
- look into not hasattr(self, 'ctx')
- The library code is almost entire black formatted, adjust tests for code quality HOT 1
- Support Enable GL_CLIP_DISTANCE<n> HOT 4
- Exception: (standalone) glXChooseVisual: cannot choose visual HOT 3
- How to use Freetype with ModernGL to render text? HOT 7
- Can't create shader program from a python thread HOT 3
- does not install with build tools 143 on win11 HOT 6
- Vertex Array 'skip_errors' option is no longer valid HOT 3
- Disable depth_texture().compare_func by default HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moderngl.