當前位置: 首頁>>代碼示例>>Python>>正文


Python GL.glGetUniformLocation方法代碼示例

本文整理匯總了Python中OpenGL.GL.glGetUniformLocation方法的典型用法代碼示例。如果您正苦於以下問題:Python GL.glGetUniformLocation方法的具體用法?Python GL.glGetUniformLocation怎麽用?Python GL.glGetUniformLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenGL.GL的用法示例。


在下文中一共展示了GL.glGetUniformLocation方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _init_shaders

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def _init_shaders(self):
    """Initializes the shaders used to render the textures fullscreen quad."""
    vs = shaders.compileShader(_VERTEX_SHADER, GL.GL_VERTEX_SHADER)
    fs = shaders.compileShader(_FRAGMENT_SHADER, GL.GL_FRAGMENT_SHADER)
    self._shader = shaders.compileProgram(vs, fs)

    stride = _FLOATS_PER_VERTEX * _SIZE_OF_FLOAT
    var_position = GL.glGetAttribLocation(self._shader, _VAR_POSITION)
    GL.glVertexAttribPointer(
        var_position, 2, GL.GL_FLOAT, GL.GL_FALSE, stride, None)
    GL.glEnableVertexAttribArray(var_position)

    var_uv = GL.glGetAttribLocation(self._shader, _VAR_UV)
    uv_offset = ctypes.c_void_p(_FLOATS_PER_XY * _SIZE_OF_FLOAT)
    GL.glVertexAttribPointer(
        var_uv, 2, GL.GL_FLOAT, GL.GL_FALSE, stride, uv_offset)
    GL.glEnableVertexAttribArray(var_uv)

    self._var_texture_sampler = GL.glGetUniformLocation(
        self._shader, _VAR_TEXTURE_SAMPLER) 
開發者ID:deepmind,項目名稱:dm_control,代碼行數:22,代碼來源:fullscreen_quad.py

示例2: uniformf

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def uniformf(self, name, *values):
        {1 : gl.glUniform1f,
         2 : gl.glUniform2f,
         3 : gl.glUniform3f,
         4 : gl.glUniform4f
        }[len(values)](gl.glGetUniformLocation(self.handle, name), *values) 
開發者ID:bitsawer,項目名稱:renpy-shader,代碼行數:8,代碼來源:shaderprogram.py

示例3: uniformi

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def uniformi(self, name, *values):
        {1 : gl.glUniform1i,
         2 : gl.glUniform2i,
         3 : gl.glUniform3i,
         4 : gl.glUniform4i
        }[len(values)](gl.glGetUniformLocation(self.handle, name), *values) 
開發者ID:bitsawer,項目名稱:renpy-shader,代碼行數:8,代碼來源:shaderprogram.py

示例4: uniformMatrix4f

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def uniformMatrix4f(self, name, matrix):
        loc = gl.glGetUniformLocation(self.handle, name)
        gl.glUniformMatrix4fv(loc, 1, False, (ctypes.c_float * 16)(*matrix)) 
開發者ID:bitsawer,項目名稱:renpy-shader,代碼行數:5,代碼來源:shaderprogram.py

示例5: uniformMatrix4fArray

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def uniformMatrix4fArray(self, name, values):
        loc = gl.glGetUniformLocation(self.handle, name)
        count = len(values) / 16
        gl.glUniformMatrix4fv(loc, count, False, (ctypes.c_float * len(values))(*values)) 
開發者ID:bitsawer,項目名稱:renpy-shader,代碼行數:6,代碼來源:shaderprogram.py

示例6: init_shader

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def init_shader(self, program):
        self.loc_char_size = gl.glGetUniformLocation(program.program, 'char_size')
        self.loc_block_size = gl.glGetUniformLocation(program.program, 'block_size') 
開發者ID:TUDelft-CNS-ATM,項目名稱:bluesky,代碼行數:5,代碼來源:glhelpers.py

示例7: get_uniform_location

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def get_uniform_location(self, name):
        return gl.glGetUniformLocation(self.program, name) 
開發者ID:TUDelft-CNS-ATM,項目名稱:bluesky,代碼行數:4,代碼來源:glhelpers.py

示例8: _create_device_objects

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def _create_device_objects(self):
        # save state
        last_texture = gl.glGetIntegerv(gl.GL_TEXTURE_BINDING_2D)
        last_array_buffer = gl.glGetIntegerv(gl.GL_ARRAY_BUFFER_BINDING)

        last_vertex_array = gl.glGetIntegerv(gl.GL_VERTEX_ARRAY_BINDING)

        self._shader_handle = gl.glCreateProgram()
        # note: no need to store shader parts handles after linking
        vertex_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
        fragment_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)

        gl.glShaderSource(vertex_shader, self.VERTEX_SHADER_SRC)
        gl.glShaderSource(fragment_shader, self.FRAGMENT_SHADER_SRC)
        gl.glCompileShader(vertex_shader)
        gl.glCompileShader(fragment_shader)

        gl.glAttachShader(self._shader_handle, vertex_shader)
        gl.glAttachShader(self._shader_handle, fragment_shader)

        gl.glLinkProgram(self._shader_handle)

        # note: after linking shaders can be removed
        gl.glDeleteShader(vertex_shader)
        gl.glDeleteShader(fragment_shader)

        self._attrib_location_tex = gl.glGetUniformLocation(self._shader_handle, "Texture")
        self._attrib_proj_mtx = gl.glGetUniformLocation(self._shader_handle, "ProjMtx")
        self._attrib_location_position = gl.glGetAttribLocation(self._shader_handle, "Position")
        self._attrib_location_uv = gl.glGetAttribLocation(self._shader_handle, "UV")
        self._attrib_location_color = gl.glGetAttribLocation(self._shader_handle, "Color")

        self._vbo_handle = gl.glGenBuffers(1)
        self._elements_handle = gl.glGenBuffers(1)

        self._vao_handle = gl.glGenVertexArrays(1)
        gl.glBindVertexArray(self._vao_handle)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo_handle)

        gl.glEnableVertexAttribArray(self._attrib_location_position)
        gl.glEnableVertexAttribArray(self._attrib_location_uv)
        gl.glEnableVertexAttribArray(self._attrib_location_color)

        gl.glVertexAttribPointer(self._attrib_location_position, 2, gl.GL_FLOAT, gl.GL_FALSE, imgui.VERTEX_SIZE, ctypes.c_void_p(imgui.VERTEX_BUFFER_POS_OFFSET))
        gl.glVertexAttribPointer(self._attrib_location_uv, 2, gl.GL_FLOAT, gl.GL_FALSE, imgui.VERTEX_SIZE, ctypes.c_void_p(imgui.VERTEX_BUFFER_UV_OFFSET))
        gl.glVertexAttribPointer(self._attrib_location_color, 4, gl.GL_UNSIGNED_BYTE, gl.GL_TRUE, imgui.VERTEX_SIZE, ctypes.c_void_p(imgui.VERTEX_BUFFER_COL_OFFSET))

        # restore state
        gl.glBindTexture(gl.GL_TEXTURE_2D, last_texture)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, last_array_buffer)
        gl.glBindVertexArray(last_vertex_array) 
開發者ID:swistakm,項目名稱:pyimgui,代碼行數:53,代碼來源:opengl.py

示例9: __setitem__

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def __setitem__(self, name, value):
    # quitely ignore
    if name not in self.uniform_types_:
      if WARN_INVALID_UNIFORMS: print("No uniform with name '{}' available.".format(name))
      return

    loc = gl.glGetUniformLocation(self.id_, name)
    T = self.uniform_types_[name]

    if T == "int":
      gl.glUniform1i(loc, np.int32(value))
    if T == "uint":
      gl.glUniform1ui(loc, np.uint32(value))
    elif T == "float":
      gl.glUniform1f(loc, np.float32(value))
    elif T == "bool":
      gl.glUniform1f(loc, value)
    elif T == "vec2":
      gl.glUniform2fv(loc, 1, value)
    elif T == "vec3":
      gl.glUniform3fv(loc, 1, value)
    elif T == "vec4":
      gl.glUniform4fv(loc, 1, value)
    elif T == "ivec2":
      gl.glUniform2iv(loc, 1, value)
    elif T == "ivec3":
      gl.glUniform3iv(loc, 1, value)
    elif T == "ivec4":
      gl.glUniform4iv(loc, 1, value)
    elif T == "uivec2":
      gl.glUniform2uiv(loc, 1, value)
    elif T == "uivec3":
      gl.glUniform3uiv(loc, 1, value)
    elif T == "uivec4":
      gl.glUniform4uiv(loc, 1, value)
    elif T == "mat4":
      #print("set matrix: ", value)
      gl.glUniformMatrix4fv(loc, 1, False, value.astype(np.float32))
    elif T == "sampler2D":
      gl.glUniform1i(loc, np.int32(value))
    elif T == "sampler2DRect":
      gl.glUniform1i(loc, np.int32(value))
    else:
      raise NotImplementedError("uniform type {} not implemented. :(".format(T)) 
開發者ID:PRBonn,項目名稱:semantic-kitti-api,代碼行數:46,代碼來源:glow.py

示例10: initializeGL

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import glGetUniformLocation [as 別名]
def initializeGL(self):
        """Initialize OpenGL, VBOs, upload data on the GPU, etc."""

        # First check for supported GL version
        gl_version = float(gl.glGetString(gl.GL_VERSION)[:3])
        if gl_version < 3.3:
            print(('OpenGL context created with GL version %.1f' % gl_version))
            qCritical("""Your system reports that it supports OpenGL up to version %.1f. The minimum requirement for BlueSky is OpenGL 3.3.
                Generally, AMD/ATI/nVidia cards from 2008 and newer support OpenGL 3.3, and Intel integrated graphics from the Haswell
                generation and newer. If you think your graphics system should be able to support GL>=3.3 please open an issue report
                on the BlueSky Github page (https://github.com/ProfHoekstra/bluesky/issues)""" % gl_version)
            return

        # background color
        gl.glClearColor(*(palette.background + (0,)))
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        self.globaldata = radarUBO()

        try:
            shpath = path.join(settings.gfx_path, 'shaders')
            # Compile shaders and link color shader program
            self.color_shader = BlueSkyProgram(path.join(shpath, 'radarwidget-normal.vert'), path.join(shpath, 'radarwidget-color.frag'))
            self.color_shader.bind_uniform_buffer('global_data', self.globaldata)

            # Compile shaders and link texture shader program
            self.texture_shader = BlueSkyProgram(path.join(shpath, 'radarwidget-normal.vert'), path.join(shpath, 'radarwidget-texture.frag'))
            self.texture_shader.bind_uniform_buffer('global_data', self.globaldata)

            # Compile shaders and link text shader program
            self.text_shader = BlueSkyProgram(path.join(shpath, 'radarwidget-text.vert'), path.join(shpath, 'radarwidget-text.frag'))
            self.text_shader.bind_uniform_buffer('global_data', self.globaldata)

            self.ssd_shader = BlueSkyProgram(path.join(shpath, 'ssd.vert'), path.join(shpath, 'ssd.frag'), path.join(shpath, 'ssd.geom'))
            self.ssd_shader.bind_uniform_buffer('global_data', self.globaldata)
            self.ssd_shader.loc_vlimits = gl.glGetUniformLocation(self.ssd_shader.program, 'Vlimits')
            self.ssd_shader.loc_nac = gl.glGetUniformLocation(self.ssd_shader.program, 'n_ac')

        except RuntimeError as e:
            print('Error compiling shaders in radarwidget: ' + e.args[0])
            qCritical('Error compiling shaders in radarwidget: ' + e.args[0])
            return

        # create all vertex array objects
        try:
            self.create_objects()
        except Exception as e:
            print('Error while creating RadarWidget objects: ' + e.args[0]) 
開發者ID:TUDelft-CNS-ATM,項目名稱:bluesky,代碼行數:51,代碼來源:radarwidget.py


注:本文中的OpenGL.GL.glGetUniformLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。