~matobet/pyopengl/Python3

« back to all changes in this revision

Viewing changes to GL/VERSION/GL_1_5.py

  • Committer: matobet at gmail
  • Date: 2010-06-26 14:11:04 UTC
  • Revision ID: matobet@gmail.com-20100626141104-k011ofmltgiiu60g
Initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''OpenGL extension VERSION.GL_1_5
 
2
 
 
3
This module customises the behaviour of the 
 
4
OpenGL.raw.GL.VERSION.GL_1_5 to provide a more 
 
5
Python-friendly API
 
6
 
 
7
The official definition of this extension is available here:
 
8
http://www.opengl.org/registry/specs/VERSION/GL_1_5.txt
 
9
'''
 
10
from OpenGL import platform, constants, constant, arrays
 
11
from OpenGL import extensions, wrapper
 
12
from OpenGL.GL import glget
 
13
import ctypes
 
14
from OpenGL.raw.GL.VERSION.GL_1_5 import *
 
15
### END AUTOGENERATED SECTION
 
16
from OpenGL.lazywrapper import lazy
 
17
from OpenGL.arrays import ArrayDatatype
 
18
 
 
19
glDeleteBuffers = arrays.setInputArraySizeType(
 
20
    glDeleteBuffers,
 
21
    None,
 
22
    arrays.GLuintArray,
 
23
    'buffers',
 
24
)
 
25
 
 
26
glGenBuffers = wrapper.wrapper( glGenBuffers ).setOutput(
 
27
    'buffers', lambda n: (n,), 'n',
 
28
)
 
29
 
 
30
def _sizeOfArrayInput( pyArgs, index, wrapper ):
 
31
    return (
 
32
        arrays.ArrayDatatype.arrayByteCount( pyArgs[index] )
 
33
    )
 
34
 
 
35
@lazy( glBufferData )
 
36
def glBufferData( baseOperation, target, size, data=None, usage=None ):
 
37
    """Copy given data into the currently bound vertex-buffer-data object
 
38
    
 
39
    target -- the symbolic constant indicating which buffer type is intended
 
40
    size -- if provided, the count-in-bytes of the array
 
41
    data -- data-pointer to be used, may be None to initialize without 
 
42
        copying over a data-set 
 
43
    usage -- hint to the driver as to how to set up access to the buffer 
 
44
    
 
45
    Note: parameter "size" can be omitted, which makes the signature
 
46
        glBufferData( target, data, usage )
 
47
    instead of:
 
48
        glBufferData( target, size, data, usage )
 
49
    """
 
50
    if usage is None:
 
51
        usage = data 
 
52
        data = size 
 
53
        size = None 
 
54
    data = ArrayDatatype.asArray( data )
 
55
    if size is None:
 
56
        size = ArrayDatatype.arrayByteCount( data )
 
57
    return baseOperation( target, size, data, usage )
 
58
 
 
59
@lazy( glBufferSubData )
 
60
def glBufferSubData( baseOperation, target, offset, size, data=None ):
 
61
    """Copy subset of data into the currently bound vertex-buffer-data object
 
62
    
 
63
    target -- the symbolic constant indicating which buffer type is intended
 
64
    offset -- offset from beginning of buffer at which to copy bytes
 
65
    size -- the count-in-bytes of the array (if an int/long), if None,
 
66
        calculate size from data, if an array and data is None, use as 
 
67
        data (i.e. the parameter can be omitted and calculated)
 
68
    data -- data-pointer to be used, may be None to initialize without 
 
69
        copying over a data-set 
 
70
    
 
71
    Note that if size is not an int/long it is considered to be data
 
72
    """
 
73
    try:
 
74
        if size is not None:
 
75
            size = int( size )
 
76
    except TypeError as err:
 
77
        if data is not None:
 
78
            raise TypeError(
 
79
                """Expect an integer size *or* a data-array, not both"""
 
80
            )
 
81
        data = size 
 
82
        size = None 
 
83
    data = ArrayDatatype.asArray( data )
 
84
    if size is None:
 
85
        size = ArrayDatatype.arrayByteCount( data )
 
86
    return baseOperation( target, offset, size, data )
 
87
 
 
88
glGetBufferParameteriv = wrapper.wrapper(glGetBufferParameteriv).setOutput(
 
89
    "params",(1,),
 
90
)
 
91
@lazy( glGetBufferPointerv )
 
92
def glGetBufferPointerv( baseOperation, target, pname, params=None ):
 
93
    """Retrieve a ctypes pointer to buffer's data"""
 
94
    if params is None:
 
95
        size = glGetBufferParameteriv( target, GL_BUFFER_SIZE )
 
96
        data = arrays.ArrayDatatype.zeros( (size,), GL_UNSIGNED_BYTE )
 
97
        result = baseOperation( target, pname, ctypes.byref( data ) )
 
98
        return data
 
99
    else:
 
100
        return baseOperation( target, pname, params )
 
101
 
 
102
@lazy( glDeleteQueries )
 
103
def glDeleteQueries( baseOperation, n, ids=None ):
 
104
    if ids is None:
 
105
        ids = arrays.GLuintArray.asArray( ids )
 
106
        n = arrays.GLuintArray.arraySize( ids )
 
107
    else:
 
108
        ids = arrays.GLuintArray.asArray( ids )
 
109
    return baseOperation( n,ids )
 
110
@lazy( glGenQueries )
 
111
def glGenQueries( baseOperation, n, ids=None ):
 
112
    """Generate n queries, if ids is None, is allocated
 
113
    
 
114
    returns array of ids
 
115
    """
 
116
    if ids is None:
 
117
        ids = arrays.GLuintArray.zeros( (n,))
 
118
    else:
 
119
        ids = arrays.GLuintArray.asArray( ids )
 
120
    baseOperation( n, ids )
 
121
    return ids
 
122
 
 
123
for func in (
 
124
    'glGetQueryiv','glGetQueryObjectiv','glGetQueryObjectuiv',
 
125
):
 
126
    globals()[func] = wrapper.wrapper(globals()[func]).setOutput(
 
127
        "params", (1,)
 
128
    )
 
129
del func, glget