ios/mac shader - shared glsl source

Posts: 86
Joined: 2008.04
Post: #1
I would like to use the same shader in my mac app as in my iOS app - the only difference is the presence of the precision qualifiers.

Is there an easy approach to #define the precision qualifiers so that I can share the same shader source for both mac and iOS?

(OSC mentioned how to do this before, but I can't remember the details)

Thanks in advance for any help
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
glShaderSource takes an array of strings that are concatenated together, so, on iOS, set string 0 to

#version 100

and on desktop, to

#version 110
#define highp
#define mediump
#define lowp

... and put your own source in string 1.

Where you need to declare global precision, you can use the GL_ES predefined macro to conditionalize:

#if defined(GL_ES)
precision highp float;
Quote this message in a reply
Posts: 86
Joined: 2008.04
Post: #3
Thanks OSC - That worked perfectly!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  passing values from vertex to fragment shader Sumaleth 5 17,299 Feb 18, 2011 01:54 AM
Last Post: Holmes
  Changing Uniform Variables for a Single Shader reapz 3 9,182 Jul 15, 2010 01:29 AM
Last Post: dazza
  Vertex shader particle billboarding question TomorrowPlusX 3 8,169 Sep 15, 2008 06:46 AM
Last Post: TomorrowPlusX
  GLSL Shader getting corrupted Weebull 4 7,523 Jun 23, 2008 03:43 PM
Last Post: Weebull
  Per-pixel shader? kelvin 15 14,613 Mar 9, 2008 07:42 PM
Last Post: kelvin