在PyOpenGL中使用glGetUniformIndices

2024-10-03 06:26:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个像这样的统一块:

layout(shared) uniform ProjectionMatrices {
  mat4 model_camera_xform;
  mat4 camera_clip_xform;
};

我想查询一下这个街区制服的尺寸和偏移量。为此,我首先需要使用glGetUniformIndices函数获取其成员的索引,但我不知道如何使用它。你知道吗

以下是我的尝试:

import ctypes as c
from OpenGL import GL
import numpy

name_array = c.c_char_p * len(uniform_names)
c_uniform_names = name_array(*[c.c_char_p(name.encode()) for name in uniform_names])
c_uniform_names = c.cast(c_uniform_names, c.POINTER(c.POINTER(c.c_char)))
uniform_indices = numpy.zeros(len(uniform_names), dtype='int32')
uniform_indices += 42
r = GL.glGetUniformIndices(program, len(uniform_names), c_uniform_names, uniform_indices)
err = GL.glGetError()

然而,其结果是:

>>> print(uniform_names) # looks good.
['ProjectionMatrices.model_camera_xform', 'ProjectionMatrices.camera_clip_xform']
>>> print(err == GL.GL_NO_ERROR) # No error occurred
True
>>> print(r) # GL.GL_INVALID_INDEX, not sure what this refers to
4294967295
>>> print(uniform_indices) # Nothing has been set
[42 42]

Tags: nameimportclipmodellennamesuniformcamera
1条回答
网友
1楼 · 发布于 2024-10-03 06:26:37

要解决uniform_indices未设置的问题,它们必须是uint32,这可以通过以下几种方式完成:

uniform_indices = numpy.zeros(len(uniform_names), dtype='uint32')
uniform_indices = numpy.zeros(len(uniform_names), dtype=OpenGL.constants.GLuint)
uniform_indices = (OpenGL.constants.GLuint * len(uniform_names))()

在此之后,uniform_indices被设置为GL_INVALID_INDEX。通过将uniform_names更改为使用非限定名称来解决此问题:

uniform_names = ['model_camera_xform', 'camera_clip_xform']

OpenGL 4.4规范的相关部分是4.3.9接口块:

Outside the shading language (i.e., in the API), members are similarly identified except the block name is always used in place of the instance name (API accesses are to shader interfaces, not to shaders). If there is no instance name, then the API does not use the block name to access a member, just the member name.

相关问题 更多 >