【问题标题】:Using glGetUniformIndices in PyOpenGL在 PyOpenGL 中使用 glGetUniformIndices
【发布时间】:2014-07-27 19:17:05
【问题描述】:

我有一个这样的统一块:

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]

【问题讨论】:

  • uniform_indicesdtype 更改为'uint32' 有帮助,但uniform_names 也必须更改(以排除块名称)。当我完全解决这个问题时会发布答案。

标签: python opengl pyopengl


【解决方案1】:

要解决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 Interface Blocks

在着色语言之外(即在 API 中),成员也类似 除了块名总是用来代替 实例名称(API 访问的是着色器接口,而不是着色器)。 如果没有实例名称,则 API 不使用块名称 要访问成员,只需成员名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 2019-03-14
    • 1970-01-01
    • 2013-06-09
    • 2012-10-26
    • 1970-01-01
    • 2015-07-01
    相关资源
    最近更新 更多