Changeset 8965:17698370cf8b in orange


Ignore:
Timestamp:
09/14/11 13:12:49 (3 years ago)
Author:
matejd <matejd@…>
Branch:
default
Convert:
c4879dd93e9b75f915264497de62db0d8cb7fbab
Message:

Vertex Buffer documentation

Location:
orange/OrangeWidgets/plot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owopenglrenderer.py

    r8928 r8965  
     1''' 
     2 
     3################# 
     4OpenGL Renderer (``owopenglrenderer``) 
     5################# 
     6 
     7.. autoclass:: OrangeWidgets.plot.OWOpenGLRenderer 
     8 
     9''' 
     10 
    111from ctypes import c_void_p 
    212 
     
    1626 
    1727class VertexBuffer: 
     28    ''' 
     29    An abstraction simplifying the usage of Vertex Buffer Objects (VBO). Warning: understanding what this class does 
     30    requires basic knowledge of OpenGL. 
     31 
     32    VBOs are necessary in OpenGL 2+ world, since immediate mode (glBegin/glVertex/glEnd paradigm) has been deprecated 
     33    and is slow (even more so using it through PyOpenGL). Vertex Array Objects (VAO) were introduced in OpenGL version 3.0; they 
     34    reduce the amount of function calls that need to be made by storing the set of bindings between vertex attributes 
     35    and vertex data. VAOs are used only if the underlying hardware supports them. This class provides a simple usage pattern 
     36    which is suitable for many applications:: 
     37 
     38        data = numpy.array([1.3, 5.1, 42.,   0., 
     39                            3.3, 4.3, 5.1,   1.], dtype=numpy.float32) 
     40        buffer = VertexBuffer(data, [(3, GL_FLOAT), (1, GL_FLOAT)]) 
     41        # ... Later when drawing: 
     42        buffer.draw(GL_LINES) 
     43        # Possible setup in a vertex shader: 
     44        #  
     45        # attribute vec3 position; 
     46        # attribute float index; 
     47        # ... 
     48 
     49    What the example above does depends on the rest of the vertex shader (left to your imagination). VertexBuffer constructor 
     50    takes data and data format description as its parameters. Format specifies mapping between data values and vertex attributes. 
     51    See the constructor for more info. 
     52    ''' 
     53 
    1854    def __init__(self, data, format_description, usage=GL_STATIC_DRAW): 
    1955        ''' 
    20         Sample usage: geometry = VertexBuffer(data, size, [(3, GL_FLOAT), (4, GL_FLOAT)], GL_STATIC_DRAW) 
    21  
    22         Currently available attribute types: GL_FLOAT # TODO 
    23  
    24         Uses Vertex Arrays Object (OpenGL 3.0) if possible. Vertex Buffer Objects were introduced in 1.5 (2003). 
    25         ''' 
     56        Constructs VBO and prepares vertex attribute bindings. 
     57 
     58        :param data: Data array (vertices) to be sent to the GPU. 
     59        :type numpy.array 
     60 
     61        :param format_description: Describes vertex attribute bindings. This parameter must be an iterable 
     62            of tuples. Each tuple specifies a generic vertex attribute (the order is important!) by specifying 
     63            the number of components (must be 1,2,3 or 4) and data type (e.g. GL_FLOAT, GL_INT). See the example 
     64            above. Normalization for fixed-point values is turned off. 
     65        :type an iterable of tuples 
     66 
     67        :param usage: Specifies the expected usage pattern. The symbolic constant must be GL_STREAM_DRAW, 
     68            GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, 
     69            GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY. Default is GL_STATIC_DRAW. 
     70        :type GLenum  
     71        ''' 
     72 
    2673        self._format_description = format_description 
    2774 
     
    3481            glBufferData(GL_ARRAY_BUFFER, data, usage) 
    3582 
    36             vertex_size = sum(attribute[0]*4 for attribute in format_description) 
     83            vertex_size = sum(attribute[0]*4 for attribute in format_description) # TODO: sizeof(type) 
    3784            self._num_vertices = len(data) / (vertex_size / 4) 
    3885            current_size = 0 
     
    5299 
    53100    def draw(self, primitives=GL_TRIANGLES, first=0, count=-1): 
    54         '''glDrawArrays''' 
     101        ''' 
     102        Renders primitives from data array. By default it renders triangles using all the data. Consult 
     103        OpenGL documentation (specifically ``glDrawArrays``) for detail info. 
     104 
     105        :param primitives: What kind of primitives to render. Symbolic constants GL_POINTS, GL_LINE_STRIP, 
     106            GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, 
     107            GL_QUADS, and GL_POLYGON are accepted. 
     108        :type GLenum 
     109 
     110        :param first: Specifies the starting index into data. 
     111        :type int 
     112 
     113        :param count: The number of indices to be rendered. 
     114        :type int 
     115        ''' 
    55116        if hasattr(self, '_vao'): 
    56117            glBindVertexArray(self._vao) 
  • orange/OrangeWidgets/plot/owplot3d.py

    r8962 r8965  
    315315        glDepthFunc(GL_LESS) 
    316316        glEnable(GL_DEPTH_TEST) 
    317         glEnable(GL_LINE_SMOOTH) 
     317        glEnable(GL_LINE_SMOOTH) # TODO 
    318318        glDisable(GL_CULL_FACE) 
    319319        glEnable(GL_MULTISAMPLE) 
Note: See TracChangeset for help on using the changeset viewer.