1'''OpenGL extension ARB.vertex_shader
2
3This module customises the behaviour of the
4OpenGL.raw.GL.ARB.vertex_shader to provide a more
5Python-friendly API
6
7Overview (from the spec)
8
9	This extension adds programmable vertex level processing to OpenGL. The
10	application can write vertex shaders in a high level language as defined
11	in the OpenGL Shading Language specification. The language itself is not
12	discussed here. A vertex shader replaces the transformation, texture
13	coordinate generation and lighting parts of OpenGL, and it also adds
14	texture access at the vertex level. Furthermore, management of vertex
15	shader objects and loading generic attributes are discussed. A vertex
16	shader object, attached to a program object, can be compiled and linked
17	to produce an executable that runs on the vertex processor in OpenGL.
18	This extension also defines how such an executable interacts with the
19	fixed functionality vertex processing of OpenGL 1.4.
20
21The official definition of this extension is available here:
22http://www.opengl.org/registry/specs/ARB/vertex_shader.txt
23'''
24from OpenGL import platform, constant, arrays
25from OpenGL import extensions, wrapper
26import ctypes
27from OpenGL.raw.GL import _types, _glgets
28from OpenGL.raw.GL.ARB.vertex_shader import *
29from OpenGL.raw.GL.ARB.vertex_shader import _EXTENSION_NAME
30
31def glInitVertexShaderARB():
32    '''Return boolean indicating whether this extension is available'''
33    from OpenGL import extensions
34    return extensions.hasGLExtension( _EXTENSION_NAME )
35
36glVertexAttrib1fvARB=wrapper.wrapper(glVertexAttrib1fvARB).setInputArraySize(
37    'v', 1
38)
39glVertexAttrib1svARB=wrapper.wrapper(glVertexAttrib1svARB).setInputArraySize(
40    'v', 1
41)
42glVertexAttrib1dvARB=wrapper.wrapper(glVertexAttrib1dvARB).setInputArraySize(
43    'v', 1
44)
45glVertexAttrib2fvARB=wrapper.wrapper(glVertexAttrib2fvARB).setInputArraySize(
46    'v', 2
47)
48glVertexAttrib2svARB=wrapper.wrapper(glVertexAttrib2svARB).setInputArraySize(
49    'v', 2
50)
51glVertexAttrib2dvARB=wrapper.wrapper(glVertexAttrib2dvARB).setInputArraySize(
52    'v', 2
53)
54glVertexAttrib3fvARB=wrapper.wrapper(glVertexAttrib3fvARB).setInputArraySize(
55    'v', 3
56)
57glVertexAttrib3svARB=wrapper.wrapper(glVertexAttrib3svARB).setInputArraySize(
58    'v', 3
59)
60glVertexAttrib3dvARB=wrapper.wrapper(glVertexAttrib3dvARB).setInputArraySize(
61    'v', 3
62)
63glVertexAttrib4fvARB=wrapper.wrapper(glVertexAttrib4fvARB).setInputArraySize(
64    'v', 4
65)
66glVertexAttrib4svARB=wrapper.wrapper(glVertexAttrib4svARB).setInputArraySize(
67    'v', 4
68)
69glVertexAttrib4dvARB=wrapper.wrapper(glVertexAttrib4dvARB).setInputArraySize(
70    'v', 4
71)
72glVertexAttrib4ivARB=wrapper.wrapper(glVertexAttrib4ivARB).setInputArraySize(
73    'v', 4
74)
75glVertexAttrib4bvARB=wrapper.wrapper(glVertexAttrib4bvARB).setInputArraySize(
76    'v', 4
77)
78glVertexAttrib4ubvARB=wrapper.wrapper(glVertexAttrib4ubvARB).setInputArraySize(
79    'v', 4
80)
81glVertexAttrib4usvARB=wrapper.wrapper(glVertexAttrib4usvARB).setInputArraySize(
82    'v', 4
83)
84glVertexAttrib4uivARB=wrapper.wrapper(glVertexAttrib4uivARB).setInputArraySize(
85    'v', 4
86)
87glVertexAttrib4NbvARB=wrapper.wrapper(glVertexAttrib4NbvARB).setInputArraySize(
88    'v', 4
89)
90glVertexAttrib4NsvARB=wrapper.wrapper(glVertexAttrib4NsvARB).setInputArraySize(
91    'v', 4
92)
93glVertexAttrib4NivARB=wrapper.wrapper(glVertexAttrib4NivARB).setInputArraySize(
94    'v', 4
95)
96glVertexAttrib4NubvARB=wrapper.wrapper(glVertexAttrib4NubvARB).setInputArraySize(
97    'v', 4
98)
99glVertexAttrib4NusvARB=wrapper.wrapper(glVertexAttrib4NusvARB).setInputArraySize(
100    'v', 4
101)
102glVertexAttrib4NuivARB=wrapper.wrapper(glVertexAttrib4NuivARB).setInputArraySize(
103    'v', 4
104)
105# INPUT glVertexAttribPointerARB.pointer size not checked against 'size,type,stride'
106glVertexAttribPointerARB=wrapper.wrapper(glVertexAttribPointerARB).setInputArraySize(
107    'pointer', None
108)
109glGetActiveAttribARB=wrapper.wrapper(glGetActiveAttribARB).setOutput(
110    'length',size=(1,),orPassIn=True
111).setOutput(
112    'name',size=lambda x:(x,),pnameArg='maxLength',orPassIn=True
113).setOutput(
114    'size',size=(1,),orPassIn=True
115).setOutput(
116    'type',size=(1,),orPassIn=True
117)
118glGetVertexAttribdvARB=wrapper.wrapper(glGetVertexAttribdvARB).setOutput(
119    'params',size=(4,),orPassIn=True
120)
121glGetVertexAttribfvARB=wrapper.wrapper(glGetVertexAttribfvARB).setOutput(
122    'params',size=(4,),orPassIn=True
123)
124glGetVertexAttribivARB=wrapper.wrapper(glGetVertexAttribivARB).setOutput(
125    'params',size=(4,),orPassIn=True
126)
127glGetVertexAttribPointervARB=wrapper.wrapper(glGetVertexAttribPointervARB).setOutput(
128    'pointer',size=(1,),orPassIn=True
129)
130### END AUTOGENERATED SECTION
131from OpenGL._bytes import bytes, _NULL_8_BYTE, as_8_bit
132from OpenGL.lazywrapper import lazy as _lazy
133from OpenGL.GL.ARB.shader_objects import glGetObjectParameterivARB
134
135@_lazy( glGetActiveAttribARB )
136def glGetActiveAttribARB(baseOperation, program, index):
137    """Retrieve the name, size and type of the uniform of the index in the program"""
138    max_index = int(glGetObjectParameterivARB( program, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB ))
139    length = int(glGetObjectParameterivARB( program, GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB))
140    if index < max_index and index >= 0 and length > 0:
141        length,name,size,type = baseOperation( program, index )
142        if hasattr(name,'tostring'):
143            name = name.tostring().rstrip(b'\000')
144        elif hasattr(name,'value'):
145            name = name.value
146        return name,size,type
147    raise IndexError('index out of range from zero to %i' % (max_index - 1, ))
148
149@_lazy( glGetAttribLocationARB )
150def glGetAttribLocationARB( baseOperation, program, name ):
151    """Check that name is a string with a null byte at the end of it"""
152    if not name:
153        raise ValueError( """Non-null name required""" )
154    name = as_8_bit( name )
155    if name[-1] != _NULL_8_BYTE:
156        name = name + _NULL_8_BYTE
157    return baseOperation( program, name )
158