def _guess_uniform_func(self, value): # We make a best-effort guess. # This does NOT work with arrays of uniforms. # First look at the dtype kind. Fortunately, this falls into either # 'f' or 'i', which matches nicely with OpenGL. # Note that in some implementations, it seems there is also a 'd' type, # but we will not be using that here. if isinstance(value, int): return GL.glUniform1i elif isinstance(value, (YTQuantity, float)): return GL.glUniform1f else: kind = value.dtype.kind if kind not in 'if': raise YTUnknownUniformKind(kind) if len(value.shape) == 1: if value.size > 4: raise YTUnknownUniformSize(value.size) func = self._set_scalar_uniform(kind, value.size) elif len(value.shape) == 2: if value.shape[0] != value.shape[1]: raise YTUnknownUniformSize(value.shape) func = self._set_matrix_uniform(kind, value.shape) else: raise YTUnknownUniformSize(value.shape) return func
def _guess_uniform_func(self, value): # We make a best-effort guess. # This does NOT work with arrays of uniforms. # First look at the dtype kind. Fortunately, this falls into either # 'f' or 'i', which matches nicely with OpenGL. # Note that in some implementations, it seems there is also a 'd' type, # but we will not be using that here. if isinstance(value, int): return GL.glUniform1i elif isinstance(value, (YTQuantity, float)): return GL.glUniform1f else: kind = value.dtype.kind if kind not in "if": raise YTUnknownUniformKind(kind) if value.ndim == 0: return {"f": GL.glUniform1f, "i": GL.glUniform1i}[kind] elif value.ndim == 1: # This is not precisely the breakdown, but it lets us # pass in arrays that are greater than 4 long as arrays if value.size > 4: func = self._set_array_uniform(kind, value.size) else: func = self._set_scalar_uniform(kind, value.size) elif value.ndim == 2: if value.shape[0] != value.shape[1]: raise YTUnknownUniformSize(value.shape) func = self._set_matrix_uniform(kind, value.shape) else: raise YTUnknownUniformSize(value.shape) return func