Re: Shader doesn't compile with Python 3
Gabriele Lanaro <[email protected]> Wed, 29 May 2013 11:49:05 -0700
| Newsgroups | gmane.comp.python.opengl.user |
|---|---|
| Message-ID | <CACFi4KcCEmznxWgvRRkrC7yUgRn6s3unGVFDcb0zctpK07pDEQ@mail.gmail.com> |
@Chris yes, that's basically the issue. The function glShaderSource in py3
wants an 'str' object instead of a 'bytes' one. If you pass a 'bytes' you
have to convert it to 'str'. And in the non-bzr version there is probably
some code that doesn't correctly handles bytes strings.
I was able to solve the problem by backporting the function compileshader.
In this way it works with both py2 and py3:
def compileShader( source, shaderType ):
"""Compile shader source of given type
source -- GLSL source-code for the shader
shaderType -- GLenum GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc,
returns GLuint compiled shader reference
raises RuntimeError when a compilation failure occurs
"""
if isinstance(source, str):
source = [source]
elif isinstance(source, bytes):
source = [source.decode('utf-8')]
shader = glCreateShader(shaderType)
glShaderSource(shader, source)
glCompileShader(shader)
result = glGetShaderiv(shader, GL_COMPILE_STATUS)
if not(result):
# TODO: this will be wrong if the user has
# disabled traditional unpacking array support.
raise RuntimeError(
"""Shader compile failure (%s): %s"""%(
result,
glGetShaderInfoLog( shader ),
),
source,
shaderType,
)
return shader
On Wed, May 29, 2013 at 9:23 AM, Chris Barker - NOAA Federal <
[email protected]> wrote:
> On Tue, May 28, 2013 at 10:53 PM, Gabriele Lanaro
> <[email protected]> wrote:
> > I'm having the same problem in python 3 (not being able to compile the
> > shaders because it gets an invalid literal). Did you find any actual
> > workaround for that?
>
> IIUC shaders have to be written in ASCII, perhaps with Py3, you are
> passing unicode in -- ty encoding it to ascii and passing the bytes
> object instead.
>
> Or maybe I totally mis-understand the issue!
>
> -Chris
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> [email protected]
>
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users