Do you know guys, that index used by glGetActiveUniform() is not equal to the location used by glUniform...()? Please, fix lib/shader.py to get rid of this embarrassment.
To exact (it's short and simple):
- Code: Select all
diff -r 04eb677d1568 makehuman/lib/shader.py
--- a/makehuman/lib/shader.py Wed Mar 07 20:26:47 2018 +0100
+++ b/makehuman/lib/shader.py Sun Nov 03 13:39:09 2019 -0800
@@ -45,8 +45,9 @@
from core import G
class Uniform(object):
- def __init__(self, index, name, pytype, dims):
+ def __init__(self, index, location, name, pytype, dims):
self.index = index
+ self.location = location
self.name = name
self.pytype = pytype
self.dims = dims
@@ -111,9 +112,9 @@
cls.uniformTypes2.clear()
return type in cls.uniformTypes
- def __init__(self, index, name, type):
+ def __init__(self, index, location, name, type):
dims, dtype, pytype, glfunc, glquery = self.uniformTypes[type]
- super(VectorUniform, self).__init__(index, name, pytype, dims)
+ super(VectorUniform, self).__init__(index, location, name, pytype, dims)
self.type = type
self.dtype = dtype
self.glfunc = glfunc
@@ -125,13 +126,19 @@
return
values = np.asarray(data, dtype=self.dtype).reshape(self.dims)
if len(self.dims) > 1:
- self.glfunc(self.index, 1, GL_TRUE, values)
+ self.glfunc(self.location, 1, GL_TRUE, values)
else:
- self.glfunc(self.index, len(values)/self.dims[0], values)
+ try:
+ self.glfunc(self.location, len(values)/self.dims[0], values)
+ except GLerror as err:
+ log.error("%s", err.description)
def update(self, pgm):
values = np.zeros(self.dims, dtype=self.dtype)
- self.glquery(pgm, self.index, values)
+ try:
+ self.glquery(pgm, self.location, values)
+ except GLerror as err:
+ log.error("%s", err.description)
if len(self.dims) > 1:
values = values.T
self.values = values
@@ -223,9 +230,9 @@
cls.textureTargets2.clear()
return type in cls.textureTargets
- def __init__(self, index, name, type):
+ def __init__(self, index, location, name, type):
target = self.textureTargets[type]
- super(SamplerUniform, self).__init__(index, name, str, (1,))
+ super(SamplerUniform, self).__init__(index, location, name, str, (1,))
self.target = target
def set(self, data):
@@ -243,7 +250,10 @@
glBindTexture(self.target, 0)
else:
glBindTexture(self.target, tex.textureId)
- glUniform1i(self.index, cls.currentSampler)
+ try:
+ glUniform1i(self.location, cls.currentSampler)
+ except GLerror as err:
+ log.error("%s", err.description)
cls.currentSampler += 1
@classmethod
@@ -438,14 +448,17 @@
self.uniforms = []
for index in xrange(parameterCount):
name, size, type = glGetActiveUniform(self.shaderId, index)
+# log.debug("%s %d %s", name, size, type)
+ location = glGetUniformLocation(self.shaderId, name)
+# log.debug("%d == %d", index, location)
if name.startswith('gl_'):
log.debug("Shader: adding built-in uniform %s", name)
self.glUniforms.append(name)
continue
if VectorUniform.check(type):
- uniform = VectorUniform(index, name, type)
+ uniform = VectorUniform(index, location, name, type)
elif SamplerUniform.check(type):
- uniform = SamplerUniform(index, name, type)
+ uniform = SamplerUniform(index, location, name, type)
uniform.update(self.shaderId)
self.uniforms.append(uniform)