Merge remote-tracking branch 'svn/trunk' into git_master

This commit is contained in:
Diederick Niehorster 2014-06-01 23:31:57 +08:00
commit 8647b9a01e
5 changed files with 64 additions and 72 deletions

View File

@ -88,6 +88,9 @@ int fghPlatformGlutGetEGL ( GLenum eWhat )
return 0;
return fgPlatformGetConfig( EGL_NATIVE_VISUAL_ID );
case GLUT_WINDOW_DOUBLEBUFFER:
return 1; /* EGL is always double-buffered */
default:
fgWarning( "glutGet(): missing enum handle %d", eWhat );
break;

View File

@ -3,7 +3,7 @@
*
* Window management methods for EGL
*
* Copyright (C) 2012 Sylvain Beucler
* Copyright (C) 2012, 2014 Sylvain Beucler
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -27,21 +27,18 @@
#include "fg_internal.h"
int fghChooseConfig(EGLConfig* config) {
EGLint attribs[32];
int i = 0;
attribs[i++] = EGL_SURFACE_TYPE;
attribs[i++] = EGL_WINDOW_BIT;
EGLint attributes[32];
int where = 0;
ATTRIB_VAL(EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
if (fgState.MajorVersion >= 2) {
/*
* Khronos does not specify a EGL_OPENGL_ES3_BIT outside of the OpenGL extension "EGL_KHR_create_context". There are numerous references on the internet that
* say to use EGL_OPENGL_ES3_BIT, followed by many saying they can't find it in any headers. In fact, the offical updated specification for EGL does not have
* any references to OpenGL ES 3.0. Tests have shown that EGL_OPENGL_ES2_BIT will work with ES 3.0.
*/
attribs[i++] = EGL_RENDERABLE_TYPE;
attribs[i++] = EGL_OPENGL_ES2_BIT;
ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT);
} else {
attribs[i++] = EGL_RENDERABLE_TYPE;
attribs[i++] = EGL_OPENGL_ES_BIT;
ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT);
}
/* Technically it's possible to request a standard OpenGL (non-ES)
context, but currently our build system assumes EGL => GLES */
@ -51,29 +48,24 @@ int fghChooseConfig(EGLConfig* config) {
/* Only 888 and 565 seem to work. Based on
http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp and
https://twitter.com/BlackBerryDev/status/380720927475912706 */
attribs[i++] = EGL_BLUE_SIZE; attribs[i++] = 8;
attribs[i++] = EGL_GREEN_SIZE; attribs[i++] = 8;
attribs[i++] = EGL_RED_SIZE; attribs[i++] = 8;
ATTRIB_VAL(EGL_BLUE_SIZE, 8);
ATTRIB_VAL(EGL_GREEN_SIZE, 8);
ATTRIB_VAL(EGL_RED_SIZE, 8);
#else
attribs[i++] = EGL_BLUE_SIZE; attribs[i++] = 1;
attribs[i++] = EGL_GREEN_SIZE; attribs[i++] = 1;
attribs[i++] = EGL_RED_SIZE; attribs[i++] = 1;
ATTRIB_VAL(EGL_BLUE_SIZE, 1);
ATTRIB_VAL(EGL_GREEN_SIZE, 1);
ATTRIB_VAL(EGL_RED_SIZE, 1);
#endif
attribs[i++] = EGL_ALPHA_SIZE;
attribs[i++] = (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0;
attribs[i++] = EGL_DEPTH_SIZE;
attribs[i++] = (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0;
attribs[i++] = EGL_STENCIL_SIZE;
attribs[i++] = (fgState.DisplayMode & GLUT_STENCIL) ? 1 : 0;
attribs[i++] = EGL_SAMPLE_BUFFERS;
attribs[i++] = (fgState.DisplayMode & GLUT_MULTISAMPLE) ? 1 : 0;
attribs[i++] = EGL_SAMPLES;
attribs[i++] = (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0;
attribs[i++] = EGL_NONE;
ATTRIB_VAL(EGL_ALPHA_SIZE, (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0);
ATTRIB_VAL(EGL_DEPTH_SIZE, (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0);
ATTRIB_VAL(EGL_STENCIL_SIZE, (fgState.DisplayMode & GLUT_STENCIL) ? 1 : 0);
ATTRIB_VAL(EGL_SAMPLE_BUFFERS, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? 1 : 0);
ATTRIB_VAL(EGL_SAMPLES, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0);
ATTRIB(EGL_NONE);
EGLint num_config;
if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display,
attribs, config, 1, &num_config)) {
attributes, config, 1, &num_config)) {
fgWarning("eglChooseConfig: error %x\n", eglGetError());
return 0;
}
@ -92,13 +84,12 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) {
EGLConfig eglConfig = window->Window.pContext.egl.Config;
/* On GLES, user specifies the target version with glutInitContextVersion */
EGLint ctx_attribs[32];
int i = 0;
ctx_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
ctx_attribs[i++] = fgState.MajorVersion;
ctx_attribs[i++] = EGL_NONE;
EGLint attributes[32];
int where = 0;
ATTRIB_VAL(EGL_CONTEXT_CLIENT_VERSION, fgState.MajorVersion);
ATTRIB(EGL_NONE);
context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, ctx_attribs);
context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, attributes);
if (context == EGL_NO_CONTEXT) {
fgWarning("Cannot initialize EGL context, err=%x\n", eglGetError());
fghContextCreationError();

View File

@ -127,15 +127,19 @@ void fgOpenWindow( SFG_Window* window, const char* title,
fgSetWindow( window );
#ifndef EGL_VERSION_1_0
window->Window.DoubleBuffered =
( fgState.DisplayMode & GLUT_DOUBLE ) ? 1 : 0;
#ifndef EGL_VERSION_1_0 /* No glDrawBuffer/glReadBuffer in GLES */
if ( ! window->Window.DoubleBuffered )
{
glDrawBuffer ( GL_FRONT );
glReadBuffer ( GL_FRONT );
}
#else
/* - EGL is always double-buffered */
/* - No glDrawBuffer/glReadBuffer in GLES */
window->Window.DoubleBuffered = 1;
#endif
window->Window.attribute_v_coord = -1;
window->Window.attribute_v_normal = -1;

View File

@ -32,6 +32,9 @@ generateHeader($_SERVER['PHP_SELF']);
<a name="compiling"></a>
<h1>Compiling</h1>
<p>Note: a pre-built archive can be found here:
<a href="http://www.beuc.net/tmp/freeglut3-android-modules.tar.gz">freeglut3-android-modules.tar.gz</a> (2014-06-01 / SVN revision 1686).</p>
<ul>
<li>

View File

@ -23,67 +23,58 @@ generateHeader($_SERVER['PHP_SELF']);
<li>BlackBerry 10/BlackBerry PlayBook</li>
<li>Unix X11 with Mesa EGL</li>
<li>TODO: Raspberry PI: Mesa EGL doesn't work due to X11's fbdev limitation (no GL);
it needs to use <a href="https://github.com/raspberrypi/userland/tree/master/host_applications/linux/libs/bcm_host">bcm_host</a>
from <tt>libraspeberrypi-dev</tt> which will shortcut X11 - see <a href="http://sourceforge.net/p/freeglut/feature-requests/71/">[#71]</a></li>
it needs to use libraries from <tt>libraspeberrypi-dev</tt> which will shortcut X11
[<a href="https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/app/ofAppEGLWindow.cpp">1</a>]
[<a href="http://sourceforge.net/p/freeglut/feature-requests/71/">2</a>]
[<a href="https://github.com/raspberrypi/userland/">3</a>]
</li>
</ul>
<p>FreeGLUT ES is provided as a separate library, because OpenGL ES has a distinct,
incompatible library for each version (e.g. -lGLESv1_CM and -lGLESv2).<br />
TODO: it seems it's possible to link both without incompatibility, so we need to remove
double-compilation.</p>
<p>FreeGLUT ES is provided as a separate library, because OpenGL ES
has a distinct library from plain OpenGL (<tt>-lGLESv1_CM
-lGLESv2</tt> instead of <tt>-lGL</tt>, and different headers too).
We could consider dynamically loading the OpenGL symbols we need,
like <a href="http://libsdl.org/">libSDL</a>.</p>
<p>When compiled for OpenGL ES 2.0, it is possible to use OpenGL ES 3.0 and higher if the device or
driver supports it by calling <code>glutInitContextVersion(3.0, 0.0)</code> before creating a window.</p>
<p>The following explains how to use FreeGLUT ES under Mesa EGL.</p>
<p>It is possible to select OpenGL ES 1, 2 or 3 (if the device and
driver supports it) by calling
e.g. <code>glutInitContextVersion(3,0)</code> before creating a
window.</p>
<a name="compiling"></a>
<h1>Compiling</h1>
<p>Here's how to compile FreeGLUT for GLES2:</p>
<p>The following explains how to use FreeGLUT ES for Mesa EGL.<br />
See also the <a href="android.php">Android page</a>.</p>
<p>First, check <tt>README.cmake</tt> to install the dependencies for your system.</p>
<pre>
aptitude install libgles2-mesa-dev
cd /usr/src/freeglut-3.0.0/
mkdir native-gles2/ && cd native-gles2/
cmake \
-DCMAKE_INSTALL_PREFIX=/tmp/freeglut-native-gles2 \
-D CMAKE_BUILD_TYPE=Debug \
-DFREEGLUT_GLES2=ON \
-DFREEGLUT_BUILD_DEMOS=NO \
..
make
make install
</pre>
<p>For GLES1:</p>
<p>Then:</p>
<pre>
aptitude install libgles1-mesa-dev
apt-get install libgles1-mesa-dev libgles2-mesa-dev
cd /usr/src/freeglut-3.0.0/
mkdir native-gles1/ && cd native-gles1/
mkdir native-gles/ && cd native-gles/
cmake \
-DCMAKE_INSTALL_PREFIX=/tmp/freeglut-native-gles1 \
-DCMAKE_INSTALL_PREFIX=/tmp/freeglut-native-gles \
-D CMAKE_BUILD_TYPE=Debug \
-DFREEGLUT_GLES1=ON \
-DFREEGLUT_GLES=ON \
-DFREEGLUT_BUILD_DEMOS=NO \
..
make
make -j4
make install
</pre>
<a name="using"></a>
<h1>Using in your projects</h1>
<p>Get the 'freeglut-gles2' module through pkg-config.</p>
<p>Get the 'freeglut-gles' module through pkg-config.</p>
<p>If you use CMake, you can do that with:</p>
<pre>
include(FindPkgConfig)
pkg_check_modules(freeglut REQUIRED freeglut-gles2>=3.0.0)
pkg_check_modules(freeglut REQUIRED freeglut-gles>=3.0.0)
if(freeglut_FOUND)
include_directories(${freeglut_STATIC_INCLUDE_DIRS})
link_directories(${freeglut_STATIC_LIBRARY_DIRS})
@ -94,17 +85,17 @@ endif()
<pre>
cd your_project/
mkdir native-gles2/ && cd native-gles2/
PKG_CONFIG_PATH=/tmp/freeglut-native-gles2/share/pkgconfig/ cmake ..
mkdir native-gles/ && cd native-gles/
PKG_CONFIG_PATH=/tmp/freeglut-native-gles/share/pkgconfig/ cmake ..
</pre>
<p>See for instance:</p>
<p>Examples:</p>
<ul>
<li>OpenGL Wikibook's
<a href="https://gitorious.org/wikibooks-opengl/modern-tutorials/source/HEAD:tut04_transform-gles2"><tt>tut04_transform-gles2</tt>
example</a>: it uses a basic Makefile targetting <tt>freeglut-gles2</tt></li>
example</a>: it uses a basic Makefile targetting <tt>freeglut-gles</tt></li>
<li><tt>progs/test-shapes-gles1/</tt> in the source distribution:
it is a standalone CMake app that uses FreeGLUT GLES1.</li>
it is a standalone CMake app that uses FreeGLUT GLES (v1).</li>
</ul>
<?php generateFooter(); ?>