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


Python ArrayDatatype.arrayByteCount方法代码示例

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


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

示例1: __setitem__

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
        def __setitem__( self, slice, array):
            """Set slice of data on the array and vbo (if copied already)

            slice -- the Python slice object determining how the data should
                be copied into the vbo/array
            array -- something array-compatible that will be used as the
                source of the data, note that the data-format will have to
                be the same as the internal data-array to work properly, if
                not, the amount of data copied will be wrong.

            This is a reasonably complex operation, it has to have all sorts
            of state-aware changes to correctly map the source into the low-level
            OpenGL view of the buffer (which is just bytes as far as the GL
            is concerned).
            """
            if slice.step and not slice.step == 1:
                raise NotImplemented( """Don't know how to map stepped arrays yet""" )
            # TODO: handle e.g. mapping character data into an integer data-set
            data = ArrayDatatype.asArray( array )
            data_length = ArrayDatatype.arrayByteCount( array )
            start = (slice.start or 0)
            stop = (slice.stop or len(self.data))
            if start < 0:
                start += len(self.data)
                start = max((start,0))
            if stop < 0:
                stop += len(self.data)
                stop = max((stop,0))
            self.data[ slice ] = data
            if self.copied and self.buffers:
                if start-stop == len(self.data):
                    # re-copy the whole data-set
                    self.copied = False
                elif len(data):
                    # now the fun part, we need to make the array match the
                    # structure of the array we're going to copy into and make
                    # the "size" parameter match the value we're going to copy in,
                    # note that a 2D array (rather than a 1D array) may require
                    # multiple mappings to copy into the memory area...

                    # find the step size from the dimensions and base size...
                    size = ArrayDatatype.arrayByteCount( self.data[0] )
                    #baseSize = ArrayDatatype.unitSize( data )
                    # now create the start and distance values...
                    start *= size
                    stop *= size
                    # wait until the last moment (bind) to copy the data...
                    self._copy_segments.append(
                        (start,(stop-start), data)
                    )
开发者ID:EdwardBetts,项目名称:fs-uae-launcher,代码行数:52,代码来源:vbo.py

示例2: copy_data

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
 def copy_data( self ):
     """Copy our data into the buffer on the GL side (if required)
     
     Ensures that the GL's version of the data in the VBO matches our 
     internal view of the data, either by copying the entire data-set 
     over with glBufferData or by updating the already-transferred 
     data with glBufferSubData.
     """
     assert self.buffers, """Should do create_buffers before copy_data"""
     if self.copied:
         if self._copy_segments:
             while self._copy_segments:
                 start,size,data  = self._copy_segments.pop(0)
                 dataptr = ArrayDatatype.voidDataPointer( data )
                 self.implementation.glBufferSubData(self.target, start, size, dataptr)
     else:
         if self.data is not None and self.size is None:
             self.size = ArrayDatatype.arrayByteCount( self.data )
         self.implementation.glBufferData(
             self.target,
             self.size,
             self.data,
             self.usage,
         )
         self.copied = True
开发者ID:Tcll5850,项目名称:UMC3.0a,代码行数:27,代码来源:vbo.py

示例3: set_array

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
 def set_array( self, data, size=None ):
     """Update our entire array with new data"""
     self.data = data 
     self.copied = False
     if size is not None:
         self.size = size
     elif self.data is not None:
         self.size = ArrayDatatype.arrayByteCount( self.data )
开发者ID:AJMartel,项目名称:3DPrinter,代码行数:10,代码来源:vbo.py

示例4: set_array

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
 def set_array( self, data, size=None ):
     """Update our entire array with new data
     
     data -- PyOpenGL-compatible array-data structure, numpy arrays, ctypes arrays, etc.
     size -- if not provided, will use arrayByteCount to determine the size of the data-array,
         thus this value (number of bytes) is required when using opaque data-structures,
         (such as ctypes pointers) as the array data-source.
     """
     self.data = data
     self.copied = False
     if size is not None:
         self.size = size
     elif self.data is not None:
         self.size = ArrayDatatype.arrayByteCount( self.data )
开发者ID:Tcll5850,项目名称:UMC3.0a,代码行数:16,代码来源:vbo.py

示例5: copy_data

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
 def copy_data( self ):
     """Copy our data into the buffer on the GL side"""
     assert self.buffers, """Should do create_buffers before copy_data"""
     if self.copied:
         if self._copy_segments:
             while self._copy_segments:
                 start,size,data  = self._copy_segments.pop(0)
                 dataptr = ArrayDatatype.voidDataPointer( data )
                 self.implementation.glBufferSubData(self.target, start, size, dataptr)
     else:
         if self.data is not None and self.size is None:
             self.size = ArrayDatatype.arrayByteCount( self.data )
         self.implementation.glBufferData(
             self.target, 
             self.size,
             self.data,
             self.usage,
         )
         self.copied = True
开发者ID:AJMartel,项目名称:3DPrinter,代码行数:21,代码来源:vbo.py

示例6: arrayByteCount

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
 def arrayByteCount( self, value ):
     return ArrayDatatype.arrayByteCount( value.data )
开发者ID:Tcll5850,项目名称:UMC3.0a,代码行数:4,代码来源:vbo.py

示例7: initializeGL

# 需要导入模块: from OpenGL.arrays.arraydatatype import ArrayDatatype [as 别名]
# 或者: from OpenGL.arrays.arraydatatype.ArrayDatatype import arrayByteCount [as 别名]
    def initializeGL(self):
        self.initGeometry()

        self.vertex_code = """
            #version 120
            //attribute vec4 color;
            attribute float x_position;
            attribute float y_position;
            //varying vec4 v_color;
            void main()
            {
                gl_Position = vec4(x_position, y_position, 0.0, 1.0);
                //v_color = color;
            } """

        self.fragment_code = """
            #version 120
            //varying vec4 v_color;
            void main()
            {
                //gl_FragColor = v_color;
                gl_FragColor = vec4(1,1,1,1);
            } """

        ## Build and activate program
        # Request program and shader slots from GPU
        self.program = GL.glCreateProgram()
        self.vertex = GL.glCreateShader(GL.GL_VERTEX_SHADER)
        self.fragment = GL.glCreateShader(GL.GL_FRAGMENT_SHADER)

        # Set shaders source
        GL.glShaderSource(self.vertex, self.vertex_code)
        GL.glShaderSource(self.fragment, self.fragment_code)

        # Compile shaders
        GL.glCompileShader(self.vertex)
        GL.glCompileShader(self.fragment)

        # Attach shader objects to the program
        GL.glAttachShader(self.program, self.vertex)
        GL.glAttachShader(self.program, self.fragment)
        
        #GL.glBindAttribLocation(self.program, 0, "x_position1".encode('utf-8'))
        #GL.glBindAttribLocation(self.program, 1, "y_position1".encode('utf-8'))
        
        # Build program
        GL.glLinkProgram(self.program)

        # Get rid of shaders (not needed anymore)
        GL.glDetachShader(self.program, self.vertex)
        GL.glDetachShader(self.program, self.fragment)

        # Make program the default program
        GL.glUseProgram(self.program)

        # Create array object
        self.vao = GL.glGenVertexArrays(1)
        GL.glBindVertexArray(self.vao)

        # Request buffer slot from GPU
        self.x_data_buffer = GL.glGenBuffers(1)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.x_data_buffer)
        GL.glBufferData(GL.GL_ARRAY_BUFFER, ArrayDatatype.arrayByteCount(self.x), self.x, GL.GL_DYNAMIC_DRAW)
        
        self.y_data_buffer = GL.glGenBuffers(1)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.y_data_buffer)
        GL.glBufferData(GL.GL_ARRAY_BUFFER, ArrayDatatype.arrayByteCount(self.y), self.y, GL.GL_DYNAMIC_DRAW)
        
        
        

        ## Bind attributes
        #self.stride = self.x.strides[0]
        #self.offset = ctypes.c_void_p(0)
        self.loc = GL.glGetAttribLocation(self.program, "x_position".encode('utf-8'))
        print(self.loc)
        GL.glEnableVertexAttribArray(self.loc)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.x_data_buffer)
        GL.glVertexAttribPointer(self.loc, 1, GL.GL_FLOAT, GL.GL_FALSE, 0, 0)
        
        #self.stride = self.y.strides[0]
        #self.offset = ctypes.c_void_p(0)
        self.loc = GL.glGetAttribLocation(self.program, "y_position".encode('utf-8'))
        print(self.loc)
        GL.glEnableVertexAttribArray(self.loc)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.y_data_buffer)
        GL.glVertexAttribPointer(self.loc, 1, GL.GL_FLOAT, GL.GL_FALSE, 0, 0)
开发者ID:hobenkr88,项目名称:OxySensor,代码行数:89,代码来源:main.py


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