本文整理汇总了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
示例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
示例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)
示例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
示例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
示例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
示例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())
示例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)
示例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()
示例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])
示例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 ===== #
示例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
示例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)
示例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())
示例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())