Unify GLES1 and GLES2 (libraries are compatible and can be co-linked)

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1687 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
beuc 2014-06-01 09:24:47 +00:00
parent 693b4b8de8
commit 25be478938
9 changed files with 79 additions and 129 deletions

3
.gitattributes vendored
View File

@ -15,9 +15,8 @@ freeglut/freeglut/README.mac -text
freeglut/freeglut/README.mingw_cross svn_keywords=Author+Date+Id+Revision freeglut/freeglut/README.mingw_cross svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/README.win32 svn_keywords=Author+Date+Id+Revision freeglut/freeglut/README.win32 svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/TODO svn_keywords=Author+Date+Id+Revision freeglut/freeglut/TODO svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/android/Android.mk -text
freeglut/freeglut/android/README -text freeglut/freeglut/android/README -text
freeglut/freeglut/android/gles1/Android.mk -text
freeglut/freeglut/android/gles2/Android.mk -text
freeglut/freeglut/android_toolchain.cmake -text freeglut/freeglut/android_toolchain.cmake -text
freeglut/freeglut/config.h.in svn_keywords=Author+Date+Id+Revision freeglut/freeglut/config.h.in svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/doc/download.html svn_keywords=Author+Date+Id+Revision freeglut/freeglut/doc/download.html svn_keywords=Author+Date+Id+Revision

View File

@ -40,9 +40,7 @@ ELSE()
ENDIF() ENDIF()
# OpenGL ES support # OpenGL ES support
OPTION(FREEGLUT_GLES1 "Use OpenGL ES 1.x (requires EGL)" OFF) OPTION(FREEGLUT_GLES "Use OpenGL ES (requires EGL)" OFF)
OPTION(FREEGLUT_GLES2 "Use OpenGL ES 2.x (requires EGL) (overrides BUILD_GLES1)" OFF)
SET(FREEGLUT_HEADERS SET(FREEGLUT_HEADERS
@ -81,7 +79,7 @@ SET(FREEGLUT_SRCS
src/fg_window.c src/fg_window.c
) )
# TODO: OpenGL ES requires a compatible version of these files: # TODO: OpenGL ES requires a compatible version of these files:
IF(NOT FREEGLUT_GLES2 AND NOT FREEGLUT_GLES1) IF(NOT FREEGLUT_GLES)
LIST(APPEND FREEGLUT_SRCS LIST(APPEND FREEGLUT_SRCS
src/fg_font.c src/fg_font.c
src/fg_menu.c src/fg_menu.c
@ -172,7 +170,7 @@ ELSE()
src/x11/fg_window_x11.c src/x11/fg_window_x11.c
src/x11/fg_xinput_x11.c src/x11/fg_xinput_x11.c
) )
IF(NOT(FREEGLUT_GLES2 OR FREEGLUT_GLES1)) IF(NOT(FREEGLUT_GLES))
LIST(APPEND FREEGLUT_SRCS LIST(APPEND FREEGLUT_SRCS
src/x11/fg_internal_x11_glx.h src/x11/fg_internal_x11_glx.h
src/x11/fg_display_x11_glx.c src/x11/fg_display_x11_glx.c
@ -183,7 +181,7 @@ ELSE()
) )
ENDIF() ENDIF()
ENDIF() ENDIF()
IF(FREEGLUT_GLES2 OR FREEGLUT_GLES1) IF(FREEGLUT_GLES)
LIST(APPEND FREEGLUT_SRCS LIST(APPEND FREEGLUT_SRCS
src/egl/fg_internal_egl.h src/egl/fg_internal_egl.h
src/egl/fg_display_egl.c src/egl/fg_display_egl.c
@ -199,18 +197,14 @@ IF(FREEGLUT_GLES2 OR FREEGLUT_GLES1)
) )
ENDIF() ENDIF()
# For OpenGL ES (GLES): # For OpenGL ES (GLES): compile with -DFREEGLUT_GLES to cleanly
# - compile with -DFREEGLUT_GLES1 and -DFREEGLUT_GLES2 to cleanly # bootstrap headers inclusion in freeglut_std.h; this constant also
# bootstrap headers inclusion in freeglut_std.h; these constants # need to be defined in client applications (e.g. through pkg-config),
# also need to be defined in client applications (e.g. through # but do use GLES constants directly for all other needs
# pkg-config), but use GLES constants directly for all other needs # GLES1 and GLES2 libraries are compatible and can be co-linked.
# - define GLES version-specific library IF(FREEGLUT_GLES)
IF(FREEGLUT_GLES2) ADD_DEFINITIONS(-DFREEGLUT_GLES)
ADD_DEFINITIONS(-DFREEGLUT_GLES2) LIST(APPEND LIBS GLESv2 GLESv1_CM EGL)
LIST(APPEND LIBS GLESv2 EGL)
ELSEIF(FREEGLUT_GLES1)
ADD_DEFINITIONS(-DFREEGLUT_GLES1)
LIST(APPEND LIBS GLESv1_CM EGL)
ELSE() ELSE()
FIND_PACKAGE(OpenGL REQUIRED) FIND_PACKAGE(OpenGL REQUIRED)
LIST(APPEND LIBS ${OPENGL_gl_LIBRARY}) LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
@ -369,10 +363,8 @@ ELSE()
# - the shared library should link to the dependency libraries so that the user # - the shared library should link to the dependency libraries so that the user
# won't have to link them explicitly (they shouldn't have to know that we depend # won't have to link them explicitly (they shouldn't have to know that we depend
# on Xrandr or Xxf86vm) # on Xrandr or Xxf86vm)
IF(FREEGLUT_GLES2) IF(FREEGLUT_GLES)
SET(LIBNAME freeglut-gles2) SET(LIBNAME freeglut-gles)
ELSEIF(FREEGLUT_GLES1)
SET(LIBNAME freeglut-gles1)
ELSE() ELSE()
SET(LIBNAME glut) SET(LIBNAME glut)
ENDIF() ENDIF()
@ -489,29 +481,17 @@ ADD_DEMO(timer progs/demos/timer/timer.c)
# Define static build dependencies # Define static build dependencies
IF(WIN32) IF(WIN32)
SET(PC_LIBS_PRIVATE "-lopengl32 -lwinmm -lgdi32 -lm") SET(PC_LIBS_PRIVATE "-lopengl32 -lwinmm -lgdi32 -lm")
ELSEIF(FREEGLUT_GLES2) ELSEIF(FREEGLUT_GLES)
IF(ANDROID) IF(ANDROID)
SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm") SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lGLESv1_CM -lEGL -lm")
ELSEIF(BLACKBERRY) ELSEIF(BLACKBERRY)
IF(PLAYBOOK) IF(PLAYBOOK)
SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv2 -lEGL -lm") SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
ELSE() ELSE()
SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lEGL -lm") SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
ENDIF() ENDIF()
ELSE() ELSE()
SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lEGL -lm") SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lGLESv1_CM -lEGL -lm")
ENDIF()
ELSEIF(FREEGLUT_GLES1)
IF(ANDROID)
SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv1_CM -lEGL -lm")
ELSEIF(BLACKBERRY)
IF(PLAYBOOK)
SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv1_CM -lEGL -lm")
ELSE()
SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv1_CM -lEGL -lm")
ENDIF()
ELSE()
SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv1_CM -lEGL -lm")
ENDIF() ENDIF()
ELSE() ELSE()
SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm") SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
@ -520,16 +500,12 @@ ENDIF()
# bootstrap headers inclusion in freeglut_std.h: # bootstrap headers inclusion in freeglut_std.h:
SET(PC_LIBNAME "glut") SET(PC_LIBNAME "glut")
SET(PC_FILENAME "freeglut.pc") SET(PC_FILENAME "freeglut.pc")
IF(FREEGLUT_GLES2) IF(FREEGLUT_GLES)
SET(PC_CFLAGS "-DFREEGLUT_GLES2") SET(PC_CFLAGS "-DFREEGLUT_GLES")
SET(PC_LIBNAME "freeglut-gles2") SET(PC_LIBNAME "freeglut-gles")
SET(PC_FILENAME "freeglut-gles2.pc") SET(PC_FILENAME "freeglut-gles.pc")
ELSEIF(FREEGLUT_GLES1)
SET(PC_CFLAGS "-DFREEGLUT_GLES1")
SET(PC_LIBNAME "freeglut-gles1")
SET(PC_FILENAME "freeglut-gles1.pc")
ENDIF() ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY)
INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION share/pkgconfig/ RENAME ${PC_FILENAME}) INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION share/pkgconfig/ RENAME ${PC_FILENAME})
# TODO: change the library and .pc name when building for GLES, # TODO: change the library and .pc name when building for GLES,
# e.g. -lglut-GLES2 # e.g. -lglut-GLES

View File

@ -2,8 +2,8 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := freeglut-gles1 LOCAL_MODULE := freeglut-gles
LOCAL_SRC_FILES := lib/libfreeglut-gles1.a LOCAL_SRC_FILES := lib/libfreeglut-gles.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY) include $(PREBUILT_STATIC_LIBRARY)

View File

@ -1,9 +0,0 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := freeglut-gles2
LOCAL_SRC_FILES := lib/libfreeglut-gles2.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)

View File

@ -129,15 +129,13 @@
/* /*
* Always include OpenGL and GLU headers * Always include OpenGL and GLU headers
*/ */
/* Note: FREEGLUT_GLES1 and FREEGLUT_GLES2 are only used to cleanly /* Note: FREEGLUT_GLES is only used to cleanly bootstrap headers
bootstrap headers inclusion here; use GLES constants directly inclusion here; use GLES constants directly
(e.g. GL_ES_VERSION_2_0) for all other needs */ (e.g. GL_ES_VERSION_2_0) for all other needs */
#ifdef FREEGLUT_GLES2 #ifdef FREEGLUT_GLES
# include <EGL/egl.h>
# include <GLES2/gl2.h>
#elif FREEGLUT_GLES1
# include <EGL/egl.h> # include <EGL/egl.h>
# include <GLES/gl.h> # include <GLES/gl.h>
# include <GLES2/gl2.h>
#elif __APPLE__ #elif __APPLE__
# include <OpenGL/gl.h> # include <OpenGL/gl.h>
# include <OpenGL/glu.h> # include <OpenGL/glu.h>

View File

@ -11,7 +11,7 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC)
# FreeGLUT # FreeGLUT
include(FindPkgConfig) include(FindPkgConfig)
pkg_check_modules(freeglut REQUIRED freeglut-gles1>=3.0.0) pkg_check_modules(freeglut REQUIRED freeglut-gles>=3.0.0)
if(freeglut_FOUND) if(freeglut_FOUND)
include_directories(${freeglut_STATIC_INCLUDE_DIRS}) include_directories(${freeglut_STATIC_INCLUDE_DIRS})
link_directories(${freeglut_STATIC_LIBRARY_DIRS}) link_directories(${freeglut_STATIC_LIBRARY_DIRS})

View File

@ -27,39 +27,49 @@
#include "fg_internal.h" #include "fg_internal.h"
int fghChooseConfig(EGLConfig* config) { int fghChooseConfig(EGLConfig* config) {
const EGLint attribs[] = { EGLint attribs[32];
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, int i = 0;
#ifdef GL_ES_VERSION_2_0 attribs[i++] = EGL_SURFACE_TYPE;
attribs[i++] = 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 * 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 * 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. * any references to OpenGL ES 3.0. Tests have shown that EGL_OPENGL_ES2_BIT will work with ES 3.0.
*/ */
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, attribs[i++] = EGL_RENDERABLE_TYPE;
#elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 attribs[i++] = EGL_OPENGL_ES2_BIT;
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, } else {
#else attribs[i++] = EGL_RENDERABLE_TYPE;
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, attribs[i++] = EGL_OPENGL_ES_BIT;
#endif }
/* Technically it's possible to request a standard OpenGL (non-ES)
context, but currently our build system assumes EGL => GLES */
/* attribs[i++] = EGL_RENDERABLE_TYPE; */
/* attribs[i++] = EGL_OPENGL_BIT; */
#ifdef TARGET_HOST_BLACKBERRY #ifdef TARGET_HOST_BLACKBERRY
/* Only 888 and 565 seem to work. Based on /* Only 888 and 565 seem to work. Based on
http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp and http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp and
https://twitter.com/BlackBerryDev/status/380720927475912706 */ https://twitter.com/BlackBerryDev/status/380720927475912706 */
EGL_BLUE_SIZE, 8, attribs[i++] = EGL_BLUE_SIZE; attribs[i++] = 8;
EGL_GREEN_SIZE, 8, attribs[i++] = EGL_GREEN_SIZE; attribs[i++] = 8;
EGL_RED_SIZE, 8, attribs[i++] = EGL_RED_SIZE; attribs[i++] = 8;
#else #else
EGL_BLUE_SIZE, 1, attribs[i++] = EGL_BLUE_SIZE; attribs[i++] = 1;
EGL_GREEN_SIZE, 1, attribs[i++] = EGL_GREEN_SIZE; attribs[i++] = 1;
EGL_RED_SIZE, 1, attribs[i++] = EGL_RED_SIZE; attribs[i++] = 1;
#endif #endif
EGL_ALPHA_SIZE, (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0, attribs[i++] = EGL_ALPHA_SIZE;
EGL_DEPTH_SIZE, (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0, attribs[i++] = (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0;
EGL_STENCIL_SIZE, (fgState.DisplayMode & GLUT_STENCIL) ? 1 : 0, attribs[i++] = EGL_DEPTH_SIZE;
EGL_SAMPLE_BUFFERS, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? 1 : 0, attribs[i++] = (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0;
EGL_SAMPLES, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0, attribs[i++] = EGL_STENCIL_SIZE;
EGL_NONE 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;
EGLint num_config; EGLint num_config;
if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display,
@ -76,39 +86,26 @@ int fghChooseConfig(EGLConfig* config) {
*/ */
EGLContext fghCreateNewContextEGL( SFG_Window* window ) { EGLContext fghCreateNewContextEGL( SFG_Window* window ) {
EGLContext context; EGLContext context;
EGLint ver = -1;
EGLDisplay eglDisplay = fgDisplay.pDisplay.egl.Display; EGLDisplay eglDisplay = fgDisplay.pDisplay.egl.Display;
EGLConfig eglConfig = window->Window.pContext.egl.Config; EGLConfig eglConfig = window->Window.pContext.egl.Config;
/* Ensure OpenGLES 2.0 context */ /* On GLES, user specifies the target version with glutInitContextVersion */
static EGLint ctx_attribs[] = { EGLint ctx_attribs[32];
#ifdef GL_ES_VERSION_2_0 int i = 0;
EGL_CONTEXT_CLIENT_VERSION, 2, ctx_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
#elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 ctx_attribs[i++] = fgState.MajorVersion;
EGL_CONTEXT_CLIENT_VERSION, 1, ctx_attribs[i++] = EGL_NONE;
#endif
EGL_NONE
};
#ifdef GL_ES_VERSION_2_0
/*
* As GLES 3.0 is backwards compatible with GLES 2.0, we set 2.0 as default unless the user states a different version.
* This updates the context attributes and lets us check that the correct version was set when we query it after creation.
*/
int gles2Ver = fgState.MajorVersion <= 2 ? 2 : fgState.MajorVersion;
ctx_attribs[1] = gles2Ver;
#endif
context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, ctx_attribs); context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, ctx_attribs);
if (context == EGL_NO_CONTEXT) { if (context == EGL_NO_CONTEXT) {
fgWarning("Cannot initialize EGL context, err=%x\n", eglGetError()); fgWarning("Cannot initialize EGL context, err=%x\n", eglGetError());
fghContextCreationError(); fghContextCreationError();
} }
EGLint ver = -1;
eglQueryContext(fgDisplay.pDisplay.egl.Display, context, EGL_CONTEXT_CLIENT_VERSION, &ver); eglQueryContext(fgDisplay.pDisplay.egl.Display, context, EGL_CONTEXT_CLIENT_VERSION, &ver);
#ifdef GL_ES_VERSION_2_0 if (ver != fgState.MajorVersion)
if (ver != gles2Ver)
#else
if (ver != 1)
#endif
fgError("Wrong GLES major version: %d\n", ver); fgError("Wrong GLES major version: %d\n", ver);
return context; return context;

View File

@ -44,14 +44,12 @@
/* declare for drawing using the different OpenGL versions here so we can /* declare for drawing using the different OpenGL versions here so we can
have a nice code order below */ have a nice code order below */
#ifndef GL_ES_VERSION_2_0
static void fghDrawGeometryWire11(GLfloat *vertices, GLfloat *normals, static void fghDrawGeometryWire11(GLfloat *vertices, GLfloat *normals,
GLushort *vertIdxs, GLsizei numParts, GLsizei numVertPerPart, GLenum vertexMode, GLushort *vertIdxs, GLsizei numParts, GLsizei numVertPerPart, GLenum vertexMode,
GLushort *vertIdxs2, GLsizei numParts2, GLsizei numVertPerPart2 GLushort *vertIdxs2, GLsizei numParts2, GLsizei numVertPerPart2
); );
static void fghDrawGeometrySolid11(GLfloat *vertices, GLfloat *normals, GLfloat *textcs, GLsizei numVertices, static void fghDrawGeometrySolid11(GLfloat *vertices, GLfloat *normals, GLfloat *textcs, GLsizei numVertices,
GLushort *vertIdxs, GLsizei numParts, GLsizei numVertIdxsPerPart); GLushort *vertIdxs, GLsizei numParts, GLsizei numVertIdxsPerPart);
#endif
static void fghDrawGeometryWire20(GLfloat *vertices, GLfloat *normals, GLsizei numVertices, static void fghDrawGeometryWire20(GLfloat *vertices, GLfloat *normals, GLsizei numVertices,
GLushort *vertIdxs, GLsizei numParts, GLsizei numVertPerPart, GLenum vertexMode, GLushort *vertIdxs, GLsizei numParts, GLsizei numVertPerPart, GLenum vertexMode,
GLushort *vertIdxs2, GLsizei numParts2, GLsizei numVertPerPart2, GLushort *vertIdxs2, GLsizei numParts2, GLsizei numVertPerPart2,
@ -62,9 +60,7 @@ static void fghDrawGeometrySolid20(GLfloat *vertices, GLfloat *normals, GLfloat
GLint attribute_v_coord, GLint attribute_v_normal, GLint attribute_v_texture); GLint attribute_v_coord, GLint attribute_v_normal, GLint attribute_v_texture);
/* declare function for generating visualization of normals */ /* declare function for generating visualization of normals */
static void fghGenerateNormalVisualization(GLfloat *vertices, GLfloat *normals, GLsizei numVertices); static void fghGenerateNormalVisualization(GLfloat *vertices, GLfloat *normals, GLsizei numVertices);
#ifndef GL_ES_VERSION_2_0
static void fghDrawNormalVisualization11(); static void fghDrawNormalVisualization11();
#endif
static void fghDrawNormalVisualization20(GLint attribute_v_coord); static void fghDrawNormalVisualization20(GLint attribute_v_coord);
/* Drawing geometry: /* Drawing geometry:
@ -147,12 +143,10 @@ void fghDrawGeometryWire(GLfloat *vertices, GLfloat *normals, GLsizei numVertice
vertIdxs, numParts, numVertPerPart, vertexMode, vertIdxs, numParts, numVertPerPart, vertexMode,
vertIdxs2, numParts2, numVertPerPart2, vertIdxs2, numParts2, numVertPerPart2,
attribute_v_coord, attribute_v_normal); attribute_v_coord, attribute_v_normal);
#ifndef GL_ES_VERSION_2_0
else else
fghDrawGeometryWire11(vertices, normals, fghDrawGeometryWire11(vertices, normals,
vertIdxs, numParts, numVertPerPart, vertexMode, vertIdxs, numParts, numVertPerPart, vertexMode,
vertIdxs2, numParts2, numVertPerPart2); vertIdxs2, numParts2, numVertPerPart2);
#endif
} }
/* Draw the geometric shape with filled triangles /* Draw the geometric shape with filled triangles
@ -203,7 +197,6 @@ void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLfloat *textcs,
/* draw normals for each vertex as well */ /* draw normals for each vertex as well */
fghDrawNormalVisualization20(attribute_v_coord); fghDrawNormalVisualization20(attribute_v_coord);
} }
#ifndef GL_ES_VERSION_2_0
else else
{ {
fghDrawGeometrySolid11(vertices, normals, textcs, numVertices, fghDrawGeometrySolid11(vertices, normals, textcs, numVertices,
@ -213,13 +206,11 @@ void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLfloat *textcs,
/* draw normals for each vertex as well */ /* draw normals for each vertex as well */
fghDrawNormalVisualization11(); fghDrawNormalVisualization11();
} }
#endif
} }
/* Version for OpenGL (ES) 1.1 */ /* Version for OpenGL (ES) 1.1 */
#ifndef GL_ES_VERSION_2_0
static void fghDrawGeometryWire11(GLfloat *vertices, GLfloat *normals, static void fghDrawGeometryWire11(GLfloat *vertices, GLfloat *normals,
GLushort *vertIdxs, GLsizei numParts, GLsizei numVertPerPart, GLenum vertexMode, GLushort *vertIdxs, GLsizei numParts, GLsizei numVertPerPart, GLenum vertexMode,
GLushort *vertIdxs2, GLsizei numParts2, GLsizei numVertPerPart2 GLushort *vertIdxs2, GLsizei numParts2, GLsizei numVertPerPart2
@ -282,7 +273,6 @@ static void fghDrawGeometrySolid11(GLfloat *vertices, GLfloat *normals, GLfloat
if (textcs) if (textcs)
glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} }
#endif
/* Version for OpenGL (ES) >= 2.0 */ /* Version for OpenGL (ES) >= 2.0 */
static void fghDrawGeometryWire20(GLfloat *vertices, GLfloat *normals, GLsizei numVertices, static void fghDrawGeometryWire20(GLfloat *vertices, GLfloat *normals, GLsizei numVertices,
@ -540,7 +530,6 @@ static void fghGenerateNormalVisualization(GLfloat *vertices, GLfloat *normals,
} }
/* Version for OpenGL (ES) 1.1 */ /* Version for OpenGL (ES) 1.1 */
#ifndef GL_ES_VERSION_2_0
static void fghDrawNormalVisualization11() static void fghDrawNormalVisualization11()
{ {
GLfloat currentColor[4]; GLfloat currentColor[4];
@ -559,7 +548,6 @@ static void fghDrawNormalVisualization11()
free(verticesForNormalVisualization); free(verticesForNormalVisualization);
glColor4f(currentColor[0],currentColor[1],currentColor[2],currentColor[3]); glColor4f(currentColor[0],currentColor[1],currentColor[2],currentColor[3]);
} }
#endif
/* Version for OpenGL (ES) >= 2.0 */ /* Version for OpenGL (ES) >= 2.0 */
static void fghDrawNormalVisualization20(GLint attribute_v_coord) static void fghDrawNormalVisualization20(GLint attribute_v_coord)

View File

@ -43,8 +43,9 @@ void FGAPIENTRY glutSetVertexAttribTexCoord2(GLint attrib) {
} }
void fgInitGL2() { void fgInitGL2() {
#ifndef GL_ES_VERSION_2_0 #ifdef GL_ES_VERSION_2_0
fgState.HasOpenGL20 = 0; fgState.HasOpenGL20 = (fgState.MajorVersion >= 2);
#else
/* TODO: Mesa returns a valid stub function, rather than NULL, /* TODO: Mesa returns a valid stub function, rather than NULL,
when we request a non-existent function */ when we request a non-existent function */
#define CHECK(func, a) if ((a) == NULL) { fgWarning("fgInitGL2: " func " is NULL"); return; } #define CHECK(func, a) if ((a) == NULL) { fgWarning("fgInitGL2: " func " is NULL"); return; }
@ -56,6 +57,6 @@ void fgInitGL2() {
CHECK("fghEnableVertexAttribArray", fghEnableVertexAttribArray = (FGH_PFNGLENABLEVERTEXATTRIBARRAYPROC)glutGetProcAddress("glEnableVertexAttribArray")); CHECK("fghEnableVertexAttribArray", fghEnableVertexAttribArray = (FGH_PFNGLENABLEVERTEXATTRIBARRAYPROC)glutGetProcAddress("glEnableVertexAttribArray"));
CHECK("fghDisableVertexAttribArray", fghDisableVertexAttribArray = (FGH_PFNGLDISABLEVERTEXATTRIBARRAYPROC)glutGetProcAddress("glDisableVertexAttribArray")); CHECK("fghDisableVertexAttribArray", fghDisableVertexAttribArray = (FGH_PFNGLDISABLEVERTEXATTRIBARRAYPROC)glutGetProcAddress("glDisableVertexAttribArray"));
#undef CHECK #undef CHECK
#endif
fgState.HasOpenGL20 = 1; fgState.HasOpenGL20 = 1;
#endif
} }