本文整理汇总了Python中OpenGL.GL.glBufferData方法的典型用法代码示例。如果您正苦于以下问题:Python GL.glBufferData方法的具体用法?Python GL.glBufferData怎么用?Python GL.glBufferData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL.GL
的用法示例。
在下文中一共展示了GL.glBufferData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assign
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def assign(self, array):
gl.glBindBuffer(self.target_, self.id_)
gl.glBufferData(self.target_, array, self.usage_)
gl.glBindBuffer(self.target_, 0)
示例2: create_empty_buffer
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def create_empty_buffer(size, target=gl.GL_ARRAY_BUFFER, usage=gl.GL_STATIC_DRAW):
buf_id = gl.glGenBuffers(1)
gl.glBindBuffer(target, buf_id)
gl.glBufferData(target, size, None, usage)
return buf_id
示例3: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def __init__(self, data):
self.data = data
self.nbytes = sizeof(data)
self.ubo = gl.glGenBuffers(1)
self.binding = self.max_binding
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, self.ubo)
gl.glBufferData(gl.GL_UNIFORM_BUFFER, self.nbytes, pointer(self.data), gl.GL_STREAM_DRAW)
gl.glBindBufferBase(gl.GL_UNIFORM_BUFFER, self.binding, self.ubo)
UniformBuffer.max_binding += 1
示例4: bind_attrib
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def bind_attrib(self, attrib_id, size, data, storagetype=gl.GL_STATIC_DRAW, instance_divisor=0, datatype=gl.GL_FLOAT, stride=0, offset=None, normalize=False):
if RenderObject.bound_vao is not self.vao_id:
gl.glBindVertexArray(self.vao_id)
RenderObject.bound_vao = self.vao_id
# Keep track of max instance divisor
self.max_instance_divisor = max(instance_divisor, self.max_instance_divisor)
# If the input is an array create a new GL buffer, otherwise assume the buffer already exists and a buffer ID is passed
if type(data) is np.ndarray:
# Get an index to one new buffer in GPU mem, bind it, and copy the array data to it
buf_id = gl.glGenBuffers(1)
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buf_id)
gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, storagetype)
else:
# Assume that a GLuint is passed which means that the buffer is already in GPU memory
buf_id = data
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buf_id)
# Assign this buffer to one of the attributes in the shader
gl.glEnableVertexAttribArray(attrib_id)
gl.glVertexAttribPointer(attrib_id, size, datatype, normalize, stride, offset)
# For instanced data, indicate per how many instances we move a step in the buffer (1=per instance)
if instance_divisor > 0:
gl.glVertexAttribDivisor(attrib_id, instance_divisor)
# Clean up
gl.glDisableVertexAttribArray(attrib_id)
self.enabled_attributes[attrib_id] = [size, buf_id, instance_divisor, datatype]
return buf_id
示例5: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def __init__(self, data):
if isinstance(data, np.ndarray):
self.pdata = data
self.nbytes = data.nbytes
else:
self.pdata = pointer(data)
self.nbytes = sizeof(data)
self.ubo = gl.glGenBuffers(1)
self.binding = self.max_binding
gl.glBindBuffer(gl.GL_UNIFORM_BUFFER, self.ubo)
gl.glBufferData(gl.GL_UNIFORM_BUFFER, self.nbytes, self.pdata, gl.GL_STREAM_DRAW)
gl.glBindBufferBase(gl.GL_UNIFORM_BUFFER, self.binding, self.ubo)
UniformBuffer.max_binding += 1
示例6: _init_geometry
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def _init_geometry(self):
"""Initializes the fullscreen quad geometry."""
vertex_buffer = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vertex_buffer)
GL.glBufferData(
GL.GL_ARRAY_BUFFER,
_FULLSCREEN_QUAD_VERTEX_POSITONS_AND_TEXTURE_COORDS.nbytes,
_FULLSCREEN_QUAD_VERTEX_POSITONS_AND_TEXTURE_COORDS, GL.GL_STATIC_DRAW)
示例7: set_up_scene
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def set_up_scene(self):
self.vertex_data = []
v = self.scene_volume_init
s = self.scale_spacing
scale = 0.3
mat_scale = numpy.diag(numpy.array([scale, scale, scale, 1], dtype=numpy.float32))
t = -0.5 * v * s
mat_translate = translate(t, t, t)
mat = mat_translate @ mat_scale
for z in range(v):
for y in range(v):
for x in range(v):
self.add_cube_to_scene(mat)
mat = translate(s, 0, 0) @ mat
mat = translate(-v * s, s, 0) @ mat
mat = translate(0, -v * s, s) @ mat
vertex_data = numpy.array(self.vertex_data, dtype=numpy.float32).flatten()
self.vert_count = len(vertex_data) / 5
self.scene_vao = GL.glGenVertexArrays(1)
GL.glBindVertexArray(self.scene_vao)
self.scene_vert_buffer = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.scene_vert_buffer)
GL.glBufferData(GL.GL_ARRAY_BUFFER, vertex_data, GL.GL_STATIC_DRAW)
f_size = sizeof(c_float)
stride = 5 * f_size
GL.glEnableVertexAttribArray(0)
GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, False, stride, cast(0 * f_size, c_void_p))
GL.glEnableVertexAttribArray(1)
GL.glVertexAttribPointer(1, 2, GL.GL_FLOAT, False, stride, cast(3 * f_size, c_void_p))
GL.glBindVertexArray(0)
GL.glDisableVertexAttribArray(0)
GL.glDisableVertexAttribArray(1)
示例8: set_up_companion_window
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def set_up_companion_window(self):
if not self.hmd:
return
verts = list()
# left eye verts
verts.append(((-1, -1), (0, 0)))
verts.append(((0, -1), (1, 0)))
verts.append(((-1, 1), (0, 1)))
verts.append(((0, 1), (1, 1)))
# right eye verts
verts.append(((0, -1), (0, 0)))
verts.append(((1, -1), (1, 0)))
verts.append(((0, 1), (0, 1)))
verts.append(((1, 1), (1, 1)))
vIndices = numpy.array([0, 1, 3, 0, 3, 2, 4, 5, 7, 4, 7, 6], dtype=numpy.uint16)
self.companion_window_index_size = len(vIndices)
self.companion_window_vao = GL.glGenVertexArrays(1)
GL.glBindVertexArray(self.companion_window_vao)
#
self.companion_window_id_vert_buffer = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.companion_window_id_vert_buffer)
vVerts = numpy.array(verts, dtype=numpy.float32).flatten()
GL.glBufferData(GL.GL_ARRAY_BUFFER, vVerts, GL.GL_STATIC_DRAW)
#
self.companion_window_id_index_buffer = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, self.companion_window_id_index_buffer)
GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, vIndices, GL.GL_STATIC_DRAW)
#
f_size = sizeof(c_float)
GL.glEnableVertexAttribArray(0)
GL.glVertexAttribPointer(0, 2, GL.GL_FLOAT, False, 4 * f_size, cast(0 * f_size, c_void_p))
#
GL.glEnableVertexAttribArray(1)
GL.glVertexAttribPointer(1, 2, GL.GL_FLOAT, False, 4 * f_size, cast(2 * f_size, c_void_p))
#
GL.glBindVertexArray(0)
GL.glDisableVertexAttribArray(0)
GL.glDisableVertexAttribArray(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0)
示例9: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glBufferData [as 别名]
def __init__(self, name, vr_model, vr_diffuse_texture):
self.name = name
# create and bind a VAO to hold state for this model
self.vertex_array = GL.glGenVertexArrays(1)
GL.glBindVertexArray(self.vertex_array)
# Populate a vertex buffer
self.vertex_buffer = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vertex_buffer)
GL.glBufferData(GL.GL_ARRAY_BUFFER,
sizeof(openvr.RenderModel_Vertex_t) * vr_model.unVertexCount,
vr_model.rVertexData, GL.GL_STATIC_DRAW)
# Identify the components in the vertex buffer
GL.glEnableVertexAttribArray(0)
hv3sz = sizeof(openvr.HmdVector3_t)
GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, False, sizeof(openvr.RenderModel_Vertex_t),
cast(0 * hv3sz, c_void_p))
GL.glEnableVertexAttribArray(1)
GL.glVertexAttribPointer(1, 3, GL.GL_FLOAT, False, sizeof(openvr.RenderModel_Vertex_t),
cast(1 * hv3sz, c_void_p))
GL.glEnableVertexAttribArray(2)
GL.glVertexAttribPointer(2, 2, GL.GL_FLOAT, False, sizeof(openvr.RenderModel_Vertex_t),
cast(2 * hv3sz, c_void_p))
# Create and populate the index buffer
self.index_buffer = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, self.index_buffer)
GL.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER,
sizeof(c_uint16) * vr_model.unTriangleCount * 3,
vr_model.rIndexData, GL.GL_STATIC_DRAW)
GL.glBindVertexArray(0)
# create and populate the texture
self.texture = GL.glGenTextures(1)
GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, vr_diffuse_texture.unWidth, vr_diffuse_texture.unHeight,
0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, vr_diffuse_texture.rubTextureMapData)
# If this renders black ask McJohn what's wrong.
GL.glGenerateMipmap(GL.GL_TEXTURE_2D)
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE)
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE)
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR)
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR)
f_largest = GL.glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)
GL.glTexParameterf(GL.GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, f_largest)
GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
self.vertex_count = vr_model.unTriangleCount * 3