def set_uniform(location, value)
      raise ShaderUniformError, "Shader uniform #{location.inspect} could not be set, since shader is not current" unless current?

      return if location == INVALID_LOCATION # Not for end-users :)

      case value
        when true, Gl::GL_TRUE
          Gl.glUniform1i location, 1

        when false, Gl::GL_FALSE
          Gl.glUniform1i location, 0

        when Float
          begin
            Gl.glUniform1f location, value
          rescue
            Gl.glUniform1i location, value.to_i
          end

        when Integer
          begin
            Gl.glUniform1i location, value
          rescue
            Gl.glUniform1f location, value.to_f
          end

        when Gosu::Color
          Gl.glUniform4f location, *value.to_opengl

        when Array
          size = value.size

          raise ArgumentError, "Empty array not supported for uniform data" if size.zero?
          # raise ArgumentError, "Only support uniforms up to 4 elements" if size > 4

          case value[0]
            when Float
              begin
                Gl.send "glUniform#{size}f", location, *value.map(&:to_f)
              rescue
                Gl.send "glUniform#{size}i", location, *value.map(&:to_i)
              end

            when Integer
              begin
                Gl.send "glUniform#{size}i", location, *value.map(&:to_i)
              rescue
                Gl.send "glUniform#{size}f", location, *value.map(&:to_f)
              end

            when Gosu::Color
              GL.send "glUniform4fv", location, value.map(&:to_opengl).flatten

            else
              raise ArgumentError, "Uniform data type not supported for element of type: #{value[0].class}"
          end

        else
          raise ArgumentError, "Uniform data type not supported for type: #{value.class}"
      end

      value
    end
def set_uniform(location, value)
      raise ShaderUniformError, "Shader uniform #{location.inspect} could not be set, since shader is not current" unless current?

      return if location == INVALID_LOCATION # Not for end-users :)

      case value
        when true, Gl::GL_TRUE
          Gl.glUniform1i location, 1

        when false, Gl::GL_FALSE
          Gl.glUniform1i location, 0

        when Float
          begin
            Gl.glUniform1f location, value
          rescue
            Gl.glUniform1i location, value.to_i
          end

        when Integer
          begin
            Gl.glUniform1i location, value
          rescue
            Gl.glUniform1f location, value.to_f
          end

        when Gosu::Color
          Gl.glUniform4f location, *value.to_opengl

        when Array
          size = value.size

          raise ArgumentError, "Empty array not supported for uniform data" if size.zero?
          # raise ArgumentError, "Only support uniforms up to 4 elements" if size > 4

          case value[0]
            when Float
              begin
                Gl.send "glUniform#{size}f", location, *value.map(&:to_f)
              rescue
                Gl.send "glUniform#{size}i", location, *value.map(&:to_i)
              end

            when Integer
              begin
                Gl.send "glUniform#{size}i", location, *value.map(&:to_i)
              rescue
                Gl.send "glUniform#{size}f", location, *value.map(&:to_f)
              end

            when Gosu::Color
              GL.send "glUniform4fv", location, value.map(&:to_opengl).flatten

            else
              raise ArgumentError, "Uniform data type not supported for element of type: #{value[0].class}"
          end

        else
          raise ArgumentError, "Uniform data type not supported for type: #{value.class}"
      end

      value
    end
Set uniform without trying to force use of the program.