当前位置: 首页>>代码示例>>Python>>正文


Python bgl.Buffer方法代码示例

本文整理汇总了Python中bgl.Buffer方法的典型用法代码示例。如果您正苦于以下问题:Python bgl.Buffer方法的具体用法?Python bgl.Buffer怎么用?Python bgl.Buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bgl的用法示例。


在下文中一共展示了bgl.Buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def __init__(self, image_data, margin=0, async_load=True, width=None, height=None):
        super().__init__()
        self.defer_recalc = True
        self.image_data = image_data
        self.image_width,self.image_height = 16,16
        self.width = width or 16
        self.height = height or 16
        self.size_set = (width is not None) or (height is not None)
        self.loaded = False
        self.buffered = False
        self.deleted = False
        self.margin = margin

        self.texbuffer = bgl.Buffer(bgl.GL_INT, [1])
        bgl.glGenTextures(1, self.texbuffer)
        self.texture_id = self.texbuffer[0]

        if async_load: self.executor.submit(self.load_image)
        else: self.load_image()
        self.defer_recalc = False 
开发者ID:CGCookie,项目名称:addon_common,代码行数:22,代码来源:ui.py

示例2: shader_compile

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def shader_compile(name, shader):
        '''
        logging and error-checking not quite working :(
        '''

        bufLen = bgl.Buffer(bgl.GL_BYTE, 4)
        bufLog = bgl.Buffer(bgl.GL_BYTE, 2000)

        bgl.glCompileShader(shader)

        # XXX: this test is a hack to determine whether the shader was compiled successfully
        # TODO: rewrite to use a more correct test (glIsShader?)
        bgl.glGetShaderInfoLog(shader, 2000, bufLen, bufLog)
        log = ''.join(chr(v) for v in bufLog.to_list() if v)
        assert not log and 'was successfully compiled' not in log, 'ERROR WHILE COMPILING SHADER %s: %s' % (name,log)
        return log 
开发者ID:CGCookie,项目名称:addon_common,代码行数:18,代码来源:shaders.py

示例3: enable

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def enable(self):
        try:
            if DEBUG_PRINT:
                print('enabling shader <==================')
                if self.checkErrors:
                    self.drawing.glCheckError('something broke before enabling shader program (%s, %d)' % (self.name,self.shaderProg))
            bgl.glUseProgram(self.shaderProg)
            if self.checkErrors:
                self.drawing.glCheckError('something broke after enabling shader program (%s,%d)' % (self.name,self.shaderProg))

            # special uniforms
            # - uMVPMatrix works around deprecated gl_ModelViewProjectionMatrix
            if 'uMVPMatrix' in self.shaderVars:
                mvpmatrix = bpy.context.region_data.perspective_matrix
                mvpmatrix_buffer = bgl.Buffer(bgl.GL_FLOAT, [4,4], mvpmatrix)
                self.assign('uMVPMatrix', mvpmatrix_buffer)

            if self.funcStart: self.funcStart(self)
        except Exception as e:
            print('Error with using shader: ' + str(e))
            bgl.glUseProgram(0) 
开发者ID:CGCookie,项目名称:addon_common,代码行数:23,代码来源:shaders.py

示例4: __init__

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def __init__(self, gltype):
        self.count = 0
        self.gltype = gltype
        self.gltype_name, self.gl_count, self.options_prefix = {
            bgl.GL_POINTS:   ('points',    1, 'point'),
            bgl.GL_LINES:    ('lines',     2, 'line'),
            bgl.GL_TRIANGLES: ('triangles', 3, 'poly'),
        }[self.gltype]

        # self.vao = bgl.Buffer(bgl.GL_INT, 1)
        # bgl.glGenVertexArrays(1, self.vao)
        # bgl.glBindVertexArray(self.vao[0])

        self.vbos = bgl.Buffer(bgl.GL_INT, 4)
        bgl.glGenBuffers(4, self.vbos)
        self.vbo_pos = self.vbos[0]
        self.vbo_norm = self.vbos[1]
        self.vbo_sel = self.vbos[2]
        self.vbo_idx = self.vbos[3]

        self.render_indices = False 
开发者ID:CGCookie,项目名称:addon_common,代码行数:23,代码来源:bmesh_render.py

示例5: np_array_as_bgl_Buffer

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def np_array_as_bgl_Buffer(array):
    type = array.dtype
    if   type == np.int8:    type = bgl.GL_BYTE
    elif type == np.int16:   type = bgl.GL_SHORT
    elif type == np.int32:   type = bgl.GL_INT
    elif type == np.float32: type = bgl.GL_FLOAT
    elif type == np.float64: type = bgl.GL_DOUBLE
    else: raise

    _decref = ctypes.pythonapi.Py_DecRef
    _incref = ctypes.pythonapi.Py_IncRef

    _decref.argtypes = _incref.argtypes = [ctypes.py_object]
    _decref.restype = _incref.restype = None

    buf = bgl.Buffer(bgl.GL_BYTE, (1, *array.shape))[0]
    c_buf = C_Buffer.from_address(id(buf))

    _decref(c_buf.parent)
    _incref(array)

    c_buf.parent = array # Prevents MEM_freeN
    c_buf.type = type
    c_buf.buf = array.ctypes.data
    return buf 
开发者ID:CGCookie,项目名称:addon_common,代码行数:27,代码来源:bgl_ext.py

示例6: bgl_Buffer_reshape

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def bgl_Buffer_reshape(buf, shape):
    assert np.prod(buf.dimensions) == np.prod(shape)

    c_buf = C_Buffer.from_address(id(buf))
    c_buf.ndimensions = len(shape)

    tmp_buf = bgl.Buffer(c_buf.type, (1,) * len(shape))
    c_tmp_buf = C_Buffer.from_address(id(tmp_buf))
    for i, v in enumerate(shape):
        c_tmp_buf.dimensions[i] = v

    offset = C_Buffer.dimensions.offset
    a = ctypes.pointer(ctypes.c_void_p.from_address(id(tmp_buf) + offset))
    b = ctypes.pointer(ctypes.c_void_p.from_address(id(buf) + offset))

    a[0], b[0] = b[0], a[0]

    del c_buf
    del c_tmp_buf
    del tmp_buf 
开发者ID:CGCookie,项目名称:addon_common,代码行数:22,代码来源:bgl_ext.py

示例7: copy_buffer_to_pixel

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def copy_buffer_to_pixel(buffer, image):

    # According to 
    #   https://developer.blender.org/D2734
    #   https://docs.blender.org/api/current/gpu.html#copy-offscreen-rendering-result-back-to-ram
    # the buffer protocol is currently not implemented for 
    # bgl.Buffer and bpy.types.Image.pixels
    # (this makes the extraction very slow)
    
    # # from photogrammetry_importer.utils.stop_watch import StopWatch
    # Option 1 (faster)
    # sw = StopWatch()
    image.pixels = [v / 255 for v in buffer]
    # print('sw.get_elapsed_time()', sw.get_elapsed_time())

    # Option 2 (slower)
    # sw = StopWatch()
    # image.pixels = (np.asarray(buffer, dtype=np.uint8) / 255).tolist()
    # print('sw.get_elapsed_time()', sw.get_elapsed_time()) 
开发者ID:SBCV,项目名称:Blender-Addon-Photogrammetry-Importer,代码行数:21,代码来源:opengl_utils.py

示例8: __init__

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def __init__(self, context):
        rv3d = context.region_data
        persmat = rv3d.perspective_matrix
        flatten_persmat = [persmat[i][j] for i in range(4) for j in range(4)]
        self.persmat_buffer = bgl.Buffer(bgl.GL_FLOAT, 16, flatten_persmat)

        # GL_BLEND
        blend = bgl.Buffer(bgl.GL_BYTE, [1])
        bgl.glGetFloatv(bgl.GL_BLEND, blend)
        self.blend = blend[0]

        # GL_COLOR
        color = bgl.Buffer(bgl.GL_FLOAT, [4])
        bgl.glGetFloatv(bgl.GL_COLOR, color)
        self.color = color

        # GL_LINE_WIDTH
        line_width = bgl.Buffer(bgl.GL_FLOAT, [1])
        bgl.glGetFloatv(bgl.GL_LINE_WIDTH, line_width)
        self.line_width = line_width[0]

        # GL_Matrix_MODE
        matrix_mode = bgl.Buffer(bgl.GL_INT, [1])
        bgl.glGetIntegerv(bgl.GL_MATRIX_MODE, matrix_mode)
        self.matrix_mode = matrix_mode[0]

        # GL_PROJECTION_MATRIX
        projection_matrix = bgl.Buffer(bgl.GL_DOUBLE, [16])
        bgl.glGetFloatv(bgl.GL_PROJECTION_MATRIX, projection_matrix)
        self.projection_matrix = projection_matrix

        # blf: size, dpi
        self.size_dpi = (11, context.user_preferences.system.dpi) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:35,代码来源:gl.py

示例9: display_islands

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def display_islands(self, context):
    # TODO: save the vertex positions and don't recalculate them always?
    ob = context.active_object
    if not ob or ob.type != 'MESH':
        return
    mesh = ob.data
    if not mesh.paper_island_list or mesh.paper_island_index == -1:
        return

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    perspMatrix = context.space_data.region_3d.perspective_matrix
    perspBuff = bgl.Buffer(bgl.GL_FLOAT, (4, 4), perspMatrix.transposed())
    bgl.glLoadMatrixf(perspBuff)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    objectBuff = bgl.Buffer(bgl.GL_FLOAT, (4, 4), ob.matrix_world.transposed())
    bgl.glLoadMatrixf(objectBuff)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(0, -10)  # offset in Zbuffer to remove flicker
    bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
    bgl.glColor4f(1.0, 0.4, 0.0, self.islands_alpha)
    island = mesh.paper_island_list[mesh.paper_island_index]
    for lface in island.faces:
        face = mesh.polygons[lface.id]
        bgl.glBegin(bgl.GL_POLYGON)
        for vertex_id in face.vertices:
            vertex = mesh.vertices[vertex_id]
            bgl.glVertex4f(*vertex.co.to_4d())
        bgl.glEnd()
    bgl.glPolygonOffset(0.0, 0.0)
    bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glLoadIdentity() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:35,代码来源:io_export_paper_model.py

示例10: gl_get

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def gl_get(state_id):
    type, size = gl_state_info[state_id]
    buf = bgl.Buffer(type, [size])
    gl_type_getters[type](state_id, buf)
    return (buf if (len(buf) != 1) else buf[0]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:space_view3d_enhanced_3d_cursor.py

示例11: gl_matrix_to_buffer

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def gl_matrix_to_buffer(m):
    tempMat = [m[i][j] for i in range(4) for j in range(4)]
    return bgl.Buffer(bgl.GL_FLOAT, 16, tempMat)


# ===== DRAWING CALLBACKS ===== # 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:space_view3d_enhanced_3d_cursor.py

示例12: buffer_image

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def buffer_image(self):
        if not self.loaded: return
        if self.buffered: return
        if self.deleted: return
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture_id)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE)
        bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
        bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
        # texbuffer = bgl.Buffer(bgl.GL_BYTE, [self.width,self.height,self.depth], image_data)
        image_size = self.image_width*self.image_height*self.image_depth
        texbuffer = bgl.Buffer(bgl.GL_BYTE, [image_size], self.image_flat)
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, self.image_width, self.image_height, 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, texbuffer)
        del texbuffer
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
        self.buffered = True 
开发者ID:CGCookie,项目名称:addon_common,代码行数:17,代码来源:ui.py

示例13: to_bglMatrix

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def to_bglMatrix(mat):
        # return bgl.Buffer(
        #     bgl.GL_FLOAT, len(mat)**2, [v for r in mat for v in r]
        # )
        return bgl.Buffer(bgl.GL_FLOAT, [len(mat), len(mat)], mat) 
开发者ID:CGCookie,项目名称:addon_common,代码行数:7,代码来源:maths.py

示例14: get_pixel_matrix_buffer

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def get_pixel_matrix_buffer(self):
        if not self.r3d: return None
        return bgl.Buffer(bgl.GL_FLOAT, [4,4], self.get_pixel_matrix_list()) 
开发者ID:CGCookie,项目名称:addon_common,代码行数:5,代码来源:drawing.py

示例15: get_view_matrix_buffer

# 需要导入模块: import bgl [as 别名]
# 或者: from bgl import Buffer [as 别名]
def get_view_matrix_buffer(self):
        if not self.r3d: return None
        return bgl.Buffer(bgl.GL_FLOAT, [4,4], self.get_view_matrix_list()) 
开发者ID:CGCookie,项目名称:addon_common,代码行数:5,代码来源:drawing.py


注:本文中的bgl.Buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。