@@ -90,7 +90,7 @@ def make_index_buffer(data, dynamic=False):
9090 return vbo
9191
9292
93- def update_vertex_buffer (data , buffer ):
93+ def update_vertex_buffer (data , buffer , offset = 0 ):
9494 """Update a vertex buffer with new data.
9595
9696 Parameters
@@ -99,12 +99,14 @@ def update_vertex_buffer(data, buffer):
9999 A flat list of floats.
100100 buffer : int
101101 The ID of the buffer.
102+ offset : int
103+ Byte offset into the buffer where the update should start.
102104 """
103105 n = len (data )
104106 size = n * ct .sizeof (ct .c_float )
105107 data = (ct .c_float * n )(* data )
106108 GL .glBindBuffer (GL .GL_ARRAY_BUFFER , buffer )
107- GL .glBufferSubData (GL .GL_ARRAY_BUFFER , 0 , size , data )
109+ GL .glBufferSubData (GL .GL_ARRAY_BUFFER , offset , size , data )
108110 GL .glBindBuffer (GL .GL_ARRAY_BUFFER , 0 )
109111
110112
@@ -124,3 +126,51 @@ def update_index_buffer(data, buffer):
124126 GL .glBindBuffer (GL .GL_ELEMENT_ARRAY_BUFFER , buffer )
125127 GL .glBufferSubData (GL .GL_ELEMENT_ARRAY_BUFFER , 0 , size , data )
126128 GL .glBindBuffer (GL .GL_ELEMENT_ARRAY_BUFFER , 0 )
129+
130+
131+ def make_texture_buffer (data , internal_format = GL .GL_RGBA32F ):
132+ """Make a texture buffer from the given data.
133+
134+ Parameters
135+ ----------
136+ data : numpy.ndarray
137+ A numpy array of floats.
138+ internal_format : GLenum, optional
139+ The internal format for the texture buffer. Default is GL.GL_RGBA32F.
140+
141+ Returns
142+ -------
143+ int
144+ The texture ID.
145+ """
146+ # Create buffer
147+ buffer = GL .glGenBuffers (1 )
148+ GL .glBindBuffer (GL .GL_TEXTURE_BUFFER , buffer )
149+
150+ GL .glBufferData (GL .GL_TEXTURE_BUFFER , data .nbytes , data , GL .GL_STATIC_DRAW )
151+
152+ # Create texture
153+ texture = GL .glGenTextures (1 )
154+ GL .glBindTexture (GL .GL_TEXTURE_BUFFER , texture )
155+ GL .glTexBuffer (GL .GL_TEXTURE_BUFFER , internal_format , buffer )
156+
157+ return texture
158+
159+
160+ def update_texture_buffer (data , texture , offset = 0 ):
161+ """Update a texture buffer with new data.
162+
163+ Parameters
164+ ----------
165+ data : numpy.ndarray
166+ A numpy array of floats.
167+ texture : int
168+ The texture ID.
169+ offset : int
170+ Byte offset into the buffer where the update should start.
171+ """
172+ GL .glBindTexture (GL .GL_TEXTURE_BUFFER , texture )
173+ buffer = GL .glGetTexLevelParameteriv (GL .GL_TEXTURE_BUFFER , 0 , GL .GL_TEXTURE_BUFFER_DATA_STORE_BINDING )
174+ GL .glBindBuffer (GL .GL_TEXTURE_BUFFER , buffer )
175+ GL .glBufferSubData (GL .GL_TEXTURE_BUFFER , offset , data .nbytes , data )
176+ GL .glBindBuffer (GL .GL_TEXTURE_BUFFER , 0 )
0 commit comments