ios/mac shader - shared glsl source

Member
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
Luminary
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

Code:
#version 100

and on desktop, to

Code:
#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:

Code:
#if defined(GL_ES)
precision highp float;
#endif
Quote this message in a reply
Member
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 6 11,403 Feb 18, 2011 01:54 AM
Last Post: Holmes
  Changing Uniform Variables for a Single Shader reapz 3 5,720 Jul 15, 2010 01:29 AM
Last Post: dazza
  Vertex shader particle billboarding question TomorrowPlusX 3 5,865 Sep 15, 2008 06:46 AM
Last Post: TomorrowPlusX
  GLSL Shader getting corrupted Weebull 4 4,781 Jun 23, 2008 03:43 PM
Last Post: Weebull
  Per-pixel shader? kelvin 15 8,875 Mar 9, 2008 07:42 PM
Last Post: kelvin