posts/OpenGL ES 2.0 using Android NDKBeuc's Bloghttps://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/Beuc's Blogikiwiki2020-02-04T15:26:58Zcomment 1https://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/comment_1_6635a6b3ed82a086b8a35712e0f7a969/Anonymous2020-02-04T15:26:58Z2012-01-24T22:33:03Z
See the GLSL ES specification (http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf) section "Default Precision Qualifiers". If you don't want to change the defaults, you only have to define a default for floats in fragment shaders.
Default precisionhttps://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/comment_2_6f204795c15c5aa3a2eecdd4127c11fb/beuc2020-02-04T15:26:58Z2012-01-25T09:02:09Z
<p>Thanks for the input.</p>
<p>I saw you can do:</p>
<pre><code>#ifdef GLES2
precision mediump float;
#endif
</code></pre>
<p>though I was looking for a way to do without the pre-processing.</p>
<p>Also AFAICS you need to define precision for uniforms in the vertex shader as well.</p>
Perhaps simplerhttps://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/comment_3_8a4d522ab21272836399d5cf7d953731/Anonymous2020-02-04T15:26:58Z2012-01-25T21:52:00Z
<pre><code>#ifndef GLES2
#define lowp
#endif
</code></pre>
Nice trickhttps://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/comment_4_8ada2ae7a337f0009a8ec404dc346d6f/beuc2020-02-04T15:26:58Z2012-01-26T09:53:21Z
<p>Nice trick!
I gotta test it when I get back home tonight.</p>
GL_ES predefined preprocessor macrohttps://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/comment_5_2719a35917f8ad7eb880d575cc14fdbf/Anonymous2020-02-04T15:26:58Z2012-01-26T10:25:08Z
[[!comment <span class="error">Error: cannot import docutils.core: ModuleNotFoundError: No module named 'docutils'</span>]]
Great!https://blog.beuc.net/posts/OpenGL_ES_2.0_using_Android_NDK/comment_6_733fa4349e0536f525150871235c0cef/beuc2020-02-04T15:26:58Z2012-01-27T00:07:01Z
<p>Thanks for these tips <img src="https://blog.beuc.net/smileys/smile.png" alt=":)" />
They work great!</p>
<p>Here's the shader loading code now :</p>
<pre><code> GLuint res = glCreateShader(type);
const GLchar* sources[3] = {
// Define GLSL version
#ifdef GL_ES_VERSION_2_0
"#version 100\n"
#else
"#version 120\n"
#endif
,
// GLES2 precision specifiers
#ifdef GL_ES_VERSION_2_0
// Define default float precision for fragment shaders:
(type == GL_FRAGMENT_SHADER) ?
"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
"precision highp float; \n"
"#else \n"
"precision mediump float; \n"
"#endif \n"
: ""
// Note: OpenGL ES automatically defines this:
// #define GL_ES
#else
// Ignore GLES 2 precision specifiers:
"#define lowp \n"
"#define mediump\n"
"#define highp \n"
#endif
,
source };
glShaderSource(res, 3, sources, NULL);
</code></pre>
<p>Unlike what I wrote there's no need to define precision in the vertex shader, it's implicit according to the specs <img src="https://blog.beuc.net/smileys/smile.png" alt=":)" /></p>