Subversion Repositories eduke32

Compare Revisions

Ignore whitespace Rev 4988 → Rev 4989

/polymer/eduke32/Android.mk
14,36 → 14,33
#
LOCAL_PATH := $(call my-dir)
 
 
 
include $(CLEAR_VARS)
 
 
LOCAL_MODULE := duke
 
# -O2 -fvisibility=hidden
 
LOCAL_CFLAGS := -fvisibility=hidden -fPIC -Wimplicit -O2 -funswitch-loops -fomit-frame-pointer -DNDEBUG -DUSING_LTO -flto -fno-stack-protector -W -Werror-implicit-function-declaration -Wpointer-arith -Wextra -funsigned-char -fno-strict-aliasing -D_FORTIFY_SOURCE=0 -fjump-tables -Wno-unused-result -Wno-char-subscripts -pthread -DHAVE_INTTYPES -D_GNU_SOURCE=1 -D_REENTRANT -DRENDERTYPESDL=1 -Wno-strict-overflow -DUSE_OPENGL -Wno-attributes
LOCAL_CFLAGS := -x c++ -std=gnu++03 -fvisibility=hidden -fPIC -O2 -funswitch-loops -fomit-frame-pointer -DNDEBUG -DUSING_LTO -flto -fno-stack-protector -funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=0 -fjump-tables -pthread -DHAVE_INTTYPES -D_GNU_SOURCE=1 -D_REENTRANT
LOCAL_CFLAGS += -W -Werror-implicit-function-declaration -Wpointer-arith -Wextra -Wno-unused-result -Wno-char-subscripts -Wno-strict-overflow -Wno-attributes -Wno-write-strings
LOCAL_CPPFLAGS := -std=gnu++03
 
#-DUSE_LIBPNG
 
LOCAL_CFLAGS += -DHAVE_SDL -DHAVE_VORBIS -DDROIDMENU
LOCAL_CFLAGS += -DHAVE_SDL -DHAVE_VORBIS -DHAVE_JWZGLES -DHAVE_ANDROID -DRENDERTYPESDL=1 -DUSE_OPENGL -DNETCODE_DISABLE
 
#LOCAL_CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1
 
LOCAL_LDFLAGS := -fuse-ld=bfd
LOCAL_ARM_NEON = true
 
LOCAL_LDLIBS += -lGLESv1_CM -lEGL
 
LOCAL_LDLIBS += -llog
 
LOCAL_C_INCLUDES := $(LOCAL_PATH)/source $(LOCAL_PATH)/source/jmact $(LOCAL_PATH)/source/jaudiolib/include $(LOCAL_PATH)/source/enet/include $(LOCAL_PATH)/build/include
LOCAL_C_INCLUDES += $(TOP_DIR)/ $(TOP_DIR)/Libraries/liboggvorbis/include $(TOP_DIR)/Libraries/ $(TOP_DIR)/Libraries/SDL2/include $(TOP_DIR)/Libraries/SDL2_mixer/include $(TOP_DIR)/Libraries/libpng/include $(TOP_DIR)/Libraries/TinyXML/include $(TOP_DIR)/TouchControls
 
LOCAL_C_INCLUDES += $(TOP_DIR)/ $(TOP_DIR)/Libraries/liboggvorbis/include $(TOP_DIR)/Libraries/ $(TOP_DIR)/Libraries/SDL2/include $(TOP_DIR)/Libraries/SDL2_mixer/include $(TOP_DIR)/Libraries/libpng/include $(TOP_DIR)/Libraries/TinyXML/include $(TOP_DIR)/TouchControls
 
ANDROID_SRC = \
source/android/android-jni.cpp \
source/android/in_android.c
source/android/in_android.c \
build/src/glbuild_android.c \
build/src/jwzgles.c
 
BUILD_SRC = \
build/src/a-c.c \
54,6 → 51,7
build/src/defs.c \
build/src/engine.c \
build/src/polymost.c \
build/src/mdsprite.c \
build/src/texcache.c \
build/src/dxtfilter.c \
build/src/hightile.c \
62,22 → 60,16
build/src/kplib.c \
build/src/lz4.c \
build/src/osd.c \
build/src/md4.c \
build/src/pragmas.c \
build/src/scriptfile.c \
build/src/mutex.c \
build/src/xxhash.c \
build/src/mmulti_null.c \
build/src/voxmodel.c \
build/src/common.c \
build/src/xxhash.c \
build/src/mmulti_null.c \
build/src/voxmodel.c \
build/src/common.c \
build/src/sdlayer.c
 
GL_SRC = \
build/src/mdsprite.c \
build/src/glbuild_android.c \
 
SDL_SRC = \
build/src/sdlayer.c \
 
JMACT_SRC=source/jmact/file_lib.c \
source/jmact//control.c \
source/jmact//keyboard.c \
90,6 → 82,7
GAME_SRC=source/game.c \
source/actors.c \
source/anim.c \
source/animsounds.c \
source/common.c \
source/config.c \
source/demo.c \
137,13 → 130,13
source/enet/src/compress.c \
source/enet/src/unix.c
LOCAL_SRC_FILES = $(ANDROID_SRC) $(ENET_SRC) $(JAUDIO_SRC) $(JMACT_SRC) $(GAME_SRC) $(BUILD_SRC) $(GL_SRC) $(SDL_SRC)
LOCAL_SRC_FILES = $(ANDROID_SRC) $(JAUDIO_SRC) $(JMACT_SRC) $(GAME_SRC) $(BUILD_SRC)
 
LOCAL_LDLIBS := -lGLESv1_CM -lEGL -ldl -llog -lOpenSLES -lz -L$(TOP_DIR)/openssl/libs/
LOCAL_STATIC_LIBRARIES := libpng crypto
LOCAL_SHARED_LIBRARIES := touchcontrols ogg vorbis SDL2 SDL2_mixer
# SDL2_image
 
LOCAL_LDLIBS := -lGLESv1_CM -lEGL -ldl -llog -lOpenSLES -lz -L$(TOP_DIR)/openssl/libs/ -lcrypto
LOCAL_STATIC_LIBRARIES := nanogl SDL2_net libjpeg libpng
LOCAL_SHARED_LIBRARIES := touchcontrols openal ogg vorbis SDL2 SDL2_mixer SDL2_image
 
ifeq ($(GP_LIC),1)
LOCAL_STATIC_LIBRARIES += s-setup
LOCAL_CFLAGS += -DGP_LIC
/polymer/eduke32/build/include/compat.h
93,6 → 93,7
 
#if defined __ANDROID__ || defined EDUKE32_IOS
# define EDUKE32_TOUCH_DEVICES
# define EDUKE32_GLES
#endif
 
// This gives us access to 'intptr_t' and 'uintptr_t', which are
192,8 → 193,8
#endif
 
#if defined(__arm__)
# define Bsqrt __sqrt
# define Bsqrtf __sqrtf
# define Bsqrt __builtin_sqrt
# define Bsqrtf __builtin_sqrtf
#else
# define Bsqrt sqrt
# define Bsqrtf sqrtf
/polymer/eduke32/build/include/jwzgles.h
0,0 → 1,517
/* xscreensaver, Copyright (c) 2012 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
 
/* A compatibility shim to allow OpenGL 1.3 source code to work in an
OpenGLES environment, where almost every OpenGL 1.3 function has
been "deprecated". See jwzgles.c for details.
*/
 
#ifndef __JWZGLES_H__
#define __JWZGLES_H__
 
#ifndef HAVE_JWZGLES
# error: do not include this without HAVE_JWZGLES
#endif
 
 
#include "jwzglesI.h"
 
 
/* These are the OpenGL 1.3 functions that are not present in OpenGLES 1.
As you can see from the length of this list, OpenGL and OpenGLES have
almost nothing to do with each other. To claim that GLES is a dialect
of OpenGL is absurd -- English and Latin have more in common!
*/
 
#define glAccum jwzgles_glAccum
#define glAntialiasing jwzgles_glAntialiasing
#define glAreTexturesResident jwzgles_glAreTexturesResident
#define glArrayElement jwzgles_glArrayElement
#define glBegin jwzgles_glBegin
#define glBitmap jwzgles_glBitmap
#define glBlendColor jwzgles_glBlendColor
#define glBlendEquation jwzgles_glBlendEquation
#define glCallList jwzgles_glCallList
#define glCallLists jwzgles_glCallLists
#define glClearAccum jwzgles_glClearAccum
#define glClearDepth jwzgles_glClearDepth
#define glClearIndex jwzgles_glClearIndex
#define glClipPlane jwzgles_glClipPlane
#define glColor3b jwzgles_glColor3b
#define glColor3bv jwzgles_glColor3bv
#define glColor3d jwzgles_glColor3f
#define glColor3dv jwzgles_glColor3dv
#define glColor3f jwzgles_glColor3f
#define glColor3fv jwzgles_glColor3fv
#define glColor3i jwzgles_glColor3i
#define glColor3iv jwzgles_glColor3iv
#define glColor3s jwzgles_glColor3s
#define glColor3sv jwzgles_glColor3sv
#define glColor3ub jwzgles_glColor3ub
#define glColor3ubv jwzgles_glColor3ubv
#define glColor3ui jwzgles_glColor3ui
#define glColor3uiv jwzgles_glColor3uiv
#define glColor3us jwzgles_glColor3us
#define glColor3usv jwzgles_glColor3usv
#define glColor4b jwzgles_glColor4b
#define glColor4bv jwzgles_glColor4bv
#define glColor4d jwzgles_glColor4d
#define glColor4dv jwzgles_glColor4dv
#define glColor4fv jwzgles_glColor4fv
#define glColor4i jwzgles_glColor4i
#define glColor4iv jwzgles_glColor4iv
#define glColor4s jwzgles_glColor4s
#define glColor4sv jwzgles_glColor4sv
#define glColor4ub jwzgles_glColor4ub
#define glColor4ubv jwzgles_glColor4ubv
#define glColor4ui jwzgles_glColor4ui
#define glColor4uiv jwzgles_glColor4uiv
#define glColor4us jwzgles_glColor4us
#define glColor4usv jwzgles_glColor4usv
#define glColorMaterial jwzgles_glColorMaterial
#define glColorSubTable jwzgles_glColorSubTable
#define glColorTable jwzgles_glColorTable
#define glColorTableParameter jwzgles_glColorTableParameter
#define glColorTableParameterfv jwzgles_glColorTableParameterfv
#define glColorub jwzgles_glColorub
#define glColorui jwzgles_glColorui
#define glColorus jwzgles_glColorus
#define glCompressedTexImage jwzgles_glCompressedTexImage
#define glCompressedTexImage1D jwzgles_glCompressedTexImage1D
#define glCompressedTexImage3D jwzgles_glCompressedTexImage3D
#define glCompressedTexSubImage1D jwzgles_glCompressedTexSubImage1D
#define glCompressedTexSubImage3D jwzgles_glCompressedTexSubImage3D
#define glConvolutionFilter1D jwzgles_glConvolutionFilter1D
#define glConvolutionFilter2D jwzgles_glConvolutionFilter2D
#define glConvolutionParameter jwzgles_glConvolutionParameter
#define glConvolutionParameterfv jwzgles_glConvolutionParameterfv
#define glConvolutionParameteriv jwzgles_glConvolutionParameteriv
#define glCopyColorSubTable jwzgles_glCopyColorSubTable
#define glCopyColorTable jwzgles_glCopyColorTable
#define glCopyConvolutionFilter1D jwzgles_glCopyConvolutionFilter1D
#define glCopyConvolutionFilter2D jwzgles_glCopyConvolutionFilter2D
#define glCopyPixels jwzgles_glCopyPixels
#define glCopyTexImage1D jwzgles_glCopyTexImage1D
#define glCopyTexImage3D jwzgles_glCopyTexImage3D
#define glCopyTexSubImage1D jwzgles_glCopyTexSubImage1D
#define glCopyTexSubImage3D jwzgles_glCopyTexSubImage3D
#define glDeleteLists jwzgles_glDeleteLists
#define glDrawBuffer jwzgles_glDrawBuffer
#define glDrawPixels jwzgles_glDrawPixels
#define glDrawRangeElements jwzgles_glDrawRangeElements
#define glEdgeFlag jwzgles_glEdgeFlag
#define glEdgeFlagPointer jwzgles_glEdgeFlagPointer
#define glEdgeFlagv jwzgles_glEdgeFlagv
#define glEnd jwzgles_glEnd
#define glEndList jwzgles_glEndList
#define glEvalCoord1d jwzgles_glEvalCoord1d
#define glEvalCoord1dv jwzgles_glEvalCoord1dv
#define glEvalCoord1f jwzgles_glEvalCoord1f
#define glEvalCoord1fv jwzgles_glEvalCoord1fv
#define glEvalCoord2d jwzgles_glEvalCoord2d
#define glEvalCoord2dv jwzgles_glEvalCoord2dv
#define glEvalCoord2f jwzgles_glEvalCoord2f
#define glEvalCoord2fv jwzgles_glEvalCoord2fv
#define glEvalMesh1 jwzgles_glEvalMesh1
#define glEvalMesh2 jwzgles_glEvalMesh2
#define glEvalPoint1 jwzgles_glEvalPoint1
#define glEvalPoint2 jwzgles_glEvalPoint2
#define glFeedbackBuffer jwzgles_glFeedbackBuffer
#define glFogi jwzgles_glFogi
#define glFogiv jwzgles_glFogiv
#define glFrustum jwzgles_glFrustum
#define glGenLists jwzgles_glGenLists
#define glGet jwzgles_glGet
#define glGetBooleanv jwzgles_glGetBooleanv
#define glGetClipPlane jwzgles_glGetClipPlane
#define glGetColorTable jwzgles_glGetColorTable
#define glGetColorTableParameter jwzgles_glGetColorTableParameter
#define glGetCompressedTexImage jwzgles_glGetCompressedTexImage
#define glGetConvolutionFilter jwzgles_glGetConvolutionFilter
#define glGetConvolutionParameter jwzgles_glGetConvolutionParameter
#define glGetConvolutionParameteriv jwzgles_glGetConvolutionParameteriv
#define glGetDoublev jwzgles_glGetDoublev
#define glGetFloatv jwzgles_glGetFloatv
#define glGetHistogram jwzgles_glGetHistogram
#define glGetHistogramParameter jwzgles_glGetHistogramParameter
#define glGetLightfv jwzgles_glGetLightfv
#define glGetLightiv jwzgles_glGetLightiv
#define glGetMapdv jwzgles_glGetMapdv
#define glGetMapfv jwzgles_glGetMapfv
#define glGetMapiv jwzgles_glGetMapiv
#define glGetMaterialfv jwzgles_glGetMaterialfv
#define glGetMaterialiv jwzgles_glGetMaterialiv
#define glGetPixelMapfv jwzgles_glGetPixelMapfv
#define glGetPixelMapuiv jwzgles_glGetPixelMapuiv
#define glGetPixelMapusv jwzgles_glGetPixelMapusv
#define glGetPointerv jwzgles_glGetPointerv
#define glGetPolygonStipple jwzgles_glGetPolygonStipple
#define glGetSeparableFilter jwzgles_glGetSeparableFilter
#define glGetTexEnvfv jwzgles_glGetTexEnvfv
#define glGetTexEnviv jwzgles_glGetTexEnviv
#define glGetTexGendv jwzgles_glGetTexGendv
#define glGetTexGenfv jwzgles_glGetTexGenfv
#define glGetTexGeniv jwzgles_glGetTexGeniv
#define glGetTexImage jwzgles_glGetTexImage
#define glGetTexImage1D jwzgles_glGetTexImage1D
#define glGetTexImage2D jwzgles_glGetTexImage2D
#define glGetTexImage3D jwzgles_glGetTexImage3D
#define glGetTexLevelParameterfv jwzgles_glGetTexLevelParameterfv
//#define glGetTexLevelParameteriv jwzgles_glGetTexLevelParameteriv
#define glGetTexParameterfv jwzgles_glGetTexParameterfv
//#define glGetTexParameteriv jwzgles_glGetTexParameteriv
#define glHistogram jwzgles_glHistogram
#define glIndex jwzgles_glIndex
#define glIndexMask jwzgles_glIndexMask
#define glIndexPointer jwzgles_glIndexPointer
#define glIndexd jwzgles_glIndexd
#define glIndexdv jwzgles_glIndexdv
#define glIndexf jwzgles_glIndexf
#define glIndexfv jwzgles_glIndexfv
/*#define glIndexi jwzgles_glIndexi*/
#define glIndexiv jwzgles_glIndexiv
#define glIndexs jwzgles_glIndexs
#define glIndexsv jwzgles_glIndexsv
#define glIndexub jwzgles_glIndexub
#define glIndexubv jwzgles_glIndexubv
#define glInitNames jwzgles_glInitNames
#define glInterleavedArrays jwzgles_glInterleavedArrays
#define glIsEnabled jwzgles_glIsEnabled
#define glIsList jwzgles_glIsList
#define glIsTexture jwzgles_glIsTexture
#define glLightModeli jwzgles_glLightModeli
#define glLightModeliv jwzgles_glLightModeliv
#define glLighti jwzgles_glLighti
#define glLightiv jwzgles_glLightiv
#define glLightf jwzgles_glLightf
#define glLightfv jwzgles_glLightfv
#define glLineStipple jwzgles_glLineStipple
#define glListBase jwzgles_glListBase
#define glLoadMatrix jwzgles_glLoadMatrix
#define glLoadName jwzgles_glLoadName
#define glLoadTransposeMatrix jwzgles_glLoadTransposeMatrix
#define glLoadTransposeMatrixf jwzgles_glLoadTransposeMatrixf
#define glMap1d jwzgles_glMap1d
#define glMap1f jwzgles_glMap1f
#define glMap2d jwzgles_glMap2d
#define glMap2f jwzgles_glMap2f
#define glMapGrid1d jwzgles_glMapGrid1d
#define glMapGrid1f jwzgles_glMapGrid1f
#define glMapGrid2d jwzgles_glMapGrid2d
#define glMapGrid2f jwzgles_glMapGrid2f
#define glMateriali jwzgles_glMateriali
#define glMaterialiv jwzgles_glMaterialiv
#define glMultTransposeMatrix jwzgles_glMultTransposeMatrix
#define glMultTransposeMatrixf jwzgles_glMultTransposeMatrixf
#define glNewList jwzgles_glNewList
#define glNormal3b jwzgles_glNormal3b
#define glNormal3bv jwzgles_glNormal3bv
#define glNormal3d jwzgles_glNormal3f
#define glNormal3dv jwzgles_glNormal3dv
#define glNormal3fv jwzgles_glNormal3fv
#define glNormal3i jwzgles_glNormal3i
#define glNormal3iv jwzgles_glNormal3iv
#define glNormal3s jwzgles_glNormal3s
#define glNormal3sv jwzgles_glNormal3sv
#define glOrtho jwzgles_glOrtho
#define glPassThrough jwzgles_glPassThrough
#define glPixelMapfv jwzgles_glPixelMapfv
#define glPixelMapuiv jwzgles_glPixelMapuiv
#define glPixelMapusv jwzgles_glPixelMapusv
#define glPixelStoref jwzgles_glPixelStoref
#define glPixelTransferf jwzgles_glPixelTransferf
#define glPixelTransferi jwzgles_glPixelTransferi
#define glPixelZoom jwzgles_glPixelZoom
#define glPolygonMode jwzgles_glPolygonMode
#define glPolygonStipple jwzgles_glPolygonStipple
#define glPopAttrib jwzgles_glPopAttrib
#define glPopClientAttrib jwzgles_glPopClientAttrib
#define glPopName jwzgles_glPopName
#define glPrioritizeTextures jwzgles_glPrioritizeTextures
#define glPushAttrib jwzgles_glPushAttrib
#define glPushClientAttrib jwzgles_glPushClientAttrib
#define glPushName jwzgles_glPushName
#define glRasterPos2d jwzgles_glRasterPos2d
#define glRasterPos2dv jwzgles_glRasterPos2dv
#define glRasterPos2f jwzgles_glRasterPos2f
#define glRasterPos2fv jwzgles_glRasterPos2fv
#define glRasterPos2i jwzgles_glRasterPos2i
#define glRasterPos2iv jwzgles_glRasterPos2iv
#define glRasterPos2s jwzgles_glRasterPos2s
#define glRasterPos2sv jwzgles_glRasterPos2sv
#define glRasterPos3d jwzgles_glRasterPos3d
#define glRasterPos3dv jwzgles_glRasterPos3dv
#define glRasterPos3f jwzgles_glRasterPos3f
#define glRasterPos3fv jwzgles_glRasterPos3fv
#define glRasterPos3i jwzgles_glRasterPos3i
#define glRasterPos3iv jwzgles_glRasterPos3iv
#define glRasterPos3s jwzgles_glRasterPos3s
#define glRasterPos3sv jwzgles_glRasterPos3sv
#define glRasterPos4d jwzgles_glRasterPos4d
#define glRasterPos4dv jwzgles_glRasterPos4dv
#define glRasterPos4f jwzgles_glRasterPos4f
#define glRasterPos4fv jwzgles_glRasterPos4fv
//#define glRasterPos4i jwzgles_glRasterPos4i
#define glRasterPos4iv jwzgles_glRasterPos4iv
#define glRasterPos4s jwzgles_glRasterPos4s
#define glRasterPos4sv jwzgles_glRasterPos4sv
#define glReadBuffer jwzgles_glReadBuffer
#define glRectd jwzgles_glRectf
#define glRectdv jwzgles_glRectdv
#define glRectf jwzgles_glRectf
#define glRectfv jwzgles_glRectfv
#define glRecti jwzgles_glRecti
#define glRectiv jwzgles_glRectiv
#define glRects jwzgles_glRects
#define glRectsv jwzgles_glRectsv
#define glRenderMode jwzgles_glRenderMode
#define glResetHistogram jwzgles_glResetHistogram
#define glResetMinmax jwzgles_glResetMinmax
#define glRotated jwzgles_glRotated
#define glScaled jwzgles_glScalef
#define glSelectBuffer jwzgles_glSelectBuffer
#define glSeparableFilter2D jwzgles_glSeparableFilter2D
#define glTexCoord1d jwzgles_glTexCoord1d
#define glTexCoord1dv jwzgles_glTexCoord1dv
#define glTexCoord1f jwzgles_glTexCoord1f
#define glTexCoord1fv jwzgles_glTexCoord1fv
#define glTexCoord1i jwzgles_glTexCoord1i
#define glTexCoord1iv jwzgles_glTexCoord1iv
#define glTexCoord1s jwzgles_glTexCoord1s
#define glTexCoord1sv jwzgles_glTexCoord1sv
#define glTexCoord2d jwzgles_glTexCoord2f
#define glTexCoord2dv jwzgles_glTexCoord2dv
#define glTexCoord2f jwzgles_glTexCoord2f
#define glTexCoord2fv jwzgles_glTexCoord2fv
#define glTexCoord2i jwzgles_glTexCoord2i
#define glTexCoord2iv jwzgles_glTexCoord2iv
#define glTexCoord2s jwzgles_glTexCoord2s
#define glTexCoord2sv jwzgles_glTexCoord2sv
#define glTexCoord3d jwzgles_glTexCoord3d
#define glTexCoord3dv jwzgles_glTexCoord3dv
#define glTexCoord3f jwzgles_glTexCoord3f
#define glTexCoord3fv jwzgles_glTexCoord3fv
#define glTexCoord3i jwzgles_glTexCoord3i
#define glTexCoord3iv jwzgles_glTexCoord3iv
#define glTexCoord3s jwzgles_glTexCoord3s
#define glTexCoord3sv jwzgles_glTexCoord3sv
#define glTexCoord4d jwzgles_glTexCoord4d
#define glTexCoord4dv jwzgles_glTexCoord4dv
#define glTexCoord4f jwzgles_glTexCoord4f
#define glTexCoord4fv jwzgles_glTexCoord4fv
#define glTexCoord4i jwzgles_glTexCoord4i
#define glTexCoord4iv jwzgles_glTexCoord4iv
#define glTexCoord4s jwzgles_glTexCoord4s
#define glTexCoord4sv jwzgles_glTexCoord4sv
#define glTexEnvi jwzgles_glTexEnvi
#define glTexEnviv jwzgles_glTexEnviv
#define glTexGend jwzgles_glTexGend
#define glTexGendv jwzgles_glTexGendv
#define glTexGenf jwzgles_glTexGenf
#define glTexGenfv jwzgles_glTexGenfv
#define glTexGeni jwzgles_glTexGeni
#define glTexGeniv jwzgles_glTexGeniv
#define glTexImage1D jwzgles_glTexImage1D
#define glTexImage3D jwzgles_glTexImage3D
#define glTexParameterfv jwzgles_glTexParameterfv
#define glTexParameteri jwzgles_glTexParameteri
#define glTexParameteriv jwzgles_glTexParameteriv
#define glTexSubImage1D jwzgles_glTexSubImage1D
#define glTexSubImage3D jwzgles_glTexSubImage3D
#define glTranslated jwzgles_glTranslatef
#define glVertex2d jwzgles_glVertex2d
#define glVertex2dv jwzgles_glVertex2dv
#define glVertex2f jwzgles_glVertex2f
#define glVertex2fv jwzgles_glVertex2fv
#define glVertex2i jwzgles_glVertex2i
#define glVertex2iv jwzgles_glVertex2iv
#define glVertex2s jwzgles_glVertex2s
#define glVertex2sv jwzgles_glVertex2sv
#define glVertex3d jwzgles_glVertex3f
#define glVertex3dv jwzgles_glVertex3dv
#define glVertex3f jwzgles_glVertex3f
#define glVertex3fv jwzgles_glVertex3fv
#define glVertex3i jwzgles_glVertex3i
#define glVertex3iv jwzgles_glVertex3iv
#define glVertex3s jwzgles_glVertex3s
#define glVertex3sv jwzgles_glVertex3sv
#define glVertex4d jwzgles_glVertex4d
#define glVertex4dv jwzgles_glVertex4dv
#define glVertex4f jwzgles_glVertex4f
#define glVertex4fv jwzgles_glVertex4fv
#define glVertex4i jwzgles_glVertex4i
#define glVertex4iv jwzgles_glVertex4iv
#define glVertex4s jwzgles_glVertex4s
#define glVertex4sv jwzgles_glVertex4sv
 
#define gluOrtho2D(L,R,B,T) glOrtho(L,R,B,T,-1,1)
#define gluPerspective jwzgles_gluPerspective
 
#define glXChooseVisual jwzgles_glXChooseVisual
#define glXCopyContext jwzgles_glXCopyContext
/*#define glXCreateContext jwzgles_glXCreateContext*/
#define glXCreateGLXPixmap jwzgles_glXCreateGLXPixmap
#define glXDestroyContext jwzgles_glXDestroyContext
#define glXDestroyGLXPixmap jwzgles_glXDestroyGLXPixmap
#define glXFreeContextEXT jwzgles_glXFreeContextEXT
#define glXGetClientString jwzgles_glXGetClientString
#define glXGetConfig jwzgles_glXGetConfig
#define glXGetContextIDEXT jwzgles_glXGetContextIDEXT
#define glXGetCurrentContext jwzgles_glXGetCurrentContext
#define glXGetCurrentDisplay jwzgles_glXGetCurrentDisplay
#define glXGetCurrentDrawable jwzgles_glXGetCurrentDrawable
#define glXImportContextEXT jwzgles_glXImportContextEXT
#define glXIntro jwzgles_glXIntro
#define glXIsDirect jwzgles_glXIsDirect
/*#define glXMakeCurrent jwzgles_glXMakeCurrent*/
#define glXQueryContextInfoEXT jwzgles_glXQueryContextInfoEXT
#define glXQueryExtension jwzgles_glXQueryExtension
#define glXQueryExtensionsString jwzgles_glXQueryExtensionsString
#define glXQueryServerString jwzgles_glXQueryServerString
#define glXQueryVersion jwzgles_glXQueryVersion
/*#define glXSwapBuffers jwzgles_glXSwapBuffers*/
#define glXUseXFont jwzgles_glXUseXFont
#define glXWaitGL jwzgles_glXWaitGL
#define glXWaitX jwzgles_glXWaitX
 
#define gluBeginCurve jwzgles_gluBeginCurve
#define gluBeginPolygon jwzgles_gluBeginPolygon
#define gluBeginSurface jwzgles_gluBeginSurface
#define gluBeginTrim jwzgles_gluBeginTrim
#define gluBuild1DMipmaps jwzgles_gluBuild1DMipmaps
#define gluBuild2DMipmaps jwzgles_gluBuild2DMipmaps
#define gluCylinder jwzgles_gluCylinder
#define gluDeleteNurbsRenderer jwzgles_gluDeleteNurbsRenderer
#define gluDeleteQuadric jwzgles_gluDeleteQuadric
#define gluDeleteTess jwzgles_gluDeleteTess
#define gluDisk jwzgles_gluDisk
#define gluEndCurve jwzgles_gluEndCurve
#define gluEndPolygon jwzgles_gluEndPolygon
#define gluEndSurface jwzgles_gluEndSurface
#define gluEndTrim jwzgles_gluEndTrim
#define gluErrorString jwzgles_gluErrorString
#define gluGetNurbsProperty jwzgles_gluGetNurbsProperty
#define gluGetString jwzgles_gluGetString
#define gluGetTessProperty jwzgles_gluGetTessProperty
#define gluLoadSamplingMatrices jwzgles_gluLoadSamplingMatrices
#define gluLookAt jwzgles_gluLookAt
#define gluNewNurbsRenderer jwzgles_gluNewNurbsRenderer
#define gluNewQuadric jwzgles_gluNewQuadric
#define gluNewTess jwzgles_gluNewTess
#define gluNextContour jwzgles_gluNextContour
#define gluNurbsCallback jwzgles_gluNurbsCallback
#define gluNurbsCurve jwzgles_gluNurbsCurve
#define gluNurbsProperty jwzgles_gluNurbsProperty
#define gluNurbsSurface jwzgles_gluNurbsSurface
#define gluPartialDisk jwzgles_gluPartialDisk
#define gluPickMatrix jwzgles_gluPickMatrix
#define gluProject jwzgles_gluProject
#define gluPwlCurve jwzgles_gluPwlCurve
#define gluQuadricCallback jwzgles_gluQuadricCallback
#define gluQuadricDrawStyle jwzgles_gluQuadricDrawStyle
#define gluQuadricNormals jwzgles_gluQuadricNormals
#define gluQuadricOrientation jwzgles_gluQuadricOrientation
#define gluQuadricTexture jwzgles_gluQuadricTexture
#define gluScaleImage jwzgles_gluScaleImage
#define gluSphere jwzgles_gluSphere
#define gluTessBeginContour jwzgles_gluTessBeginContour
#define gluTessBeginPolygon jwzgles_gluTessBeginPolygon
#define gluTessCallback jwzgles_gluTessCallback
#define gluTessEndPolygon jwzgles_gluTessEndPolygon
#define gluTessEndContour jwzgles_gluTessEndContour
#define gluTessNormal jwzgles_gluTessNormal
#define gluTessProperty jwzgles_gluTessProperty
#define gluTessVertex jwzgles_gluTessVertex
#define gluUnProject jwzgles_gluUnProject
 
 
/* These functions are present in both OpenGL 1.1 and in OpenGLES 1,
but are allowed within glNewList/glEndList, so we must wrap them
to allow them to be recorded.
*/
#define glActiveTexture jwzgles_glActiveTexture
#define glAlphaFunc jwzgles_glAlphaFunc
#define glBindTexture jwzgles_glBindTexture
#define glBlendFunc jwzgles_glBlendFunc
#define glClear jwzgles_glClear
#define glClearColor jwzgles_glClearColor
#define glClearStencil jwzgles_glClearStencil
#define glColor4f jwzgles_glColor4f
#define glColorMask jwzgles_glColorMask
#define glColorPointer jwzgles_glColorPointer
#define glCompressedTexImage2D jwzgles_glCompressedTexImage2D
#define glCompressedTexSubImage2D jwzgles_glCompressedTexSubImage2D
#define glCopyTexImage2D jwzgles_glCopyTexImage2D
#define glCopyTexSubImage2D jwzgles_glCopyTexSubImage2D
#define glCullFace jwzgles_glCullFace
#define glDeleteTextures jwzgles_glDeleteTextures
#define glDepthFunc jwzgles_glDepthFunc
#define glDepthMask jwzgles_glDepthMask
#define glDisable jwzgles_glDisable
#define glDrawArrays jwzgles_glDrawArrays
#define glDrawElements jwzgles_glDrawElements
#define glEnable jwzgles_glEnable
#define glFinish jwzgles_glFinish
#define glFlush jwzgles_glFlush
#define glFogf jwzgles_glFogf
#define glFogfv jwzgles_glFogfv
#define glFrontFace jwzgles_glFrontFace
#define glGenTextures jwzgles_glGenTextures
#define glGetIntegerv jwzgles_glGetIntegerv
#define glHint jwzgles_glHint
#define glLightModelf jwzgles_glLightModelf
#define glLightModelfv jwzgles_glLightModelfv
#define glLightf jwzgles_glLightf
#define glLightfv jwzgles_glLightfv
#define glLineWidth jwzgles_glLineWidth
#define glLoadIdentity jwzgles_glLoadIdentity
#define glLoadMatrixf jwzgles_glLoadMatrixf
#define glLogicOp jwzgles_glLogicOp
#define glMaterialf jwzgles_glMaterialf
#define glMateriali jwzgles_glMateriali
#define glMaterialfv jwzgles_glMaterialfv
#define glMaterialiv jwzgles_glMaterialiv
#define glMatrixMode jwzgles_glMatrixMode
#define glMultMatrixf jwzgles_glMultMatrixf
#define glNormal3f jwzgles_glNormal3f
#define glNormalPointer jwzgles_glNormalPointer
#define glPixelStorei jwzgles_glPixelStorei
#define glPointSize jwzgles_glPointSize
#define glPolygonOffset jwzgles_glPolygonOffset
#define glPopMatrix jwzgles_glPopMatrix
#define glPushMatrix jwzgles_glPushMatrix
#define glReadPixels jwzgles_glReadPixels
#define glRotatef jwzgles_glRotatef
#define glScalef jwzgles_glScalef
#define glSampleCoverage jwzgles_glSampleCoverage
#define glScissor jwzgles_glScissor
#define glShadeModel jwzgles_glShadeModel
#define glStencilFunc jwzgles_glStencilFunc
#define glStencilMask jwzgles_glStencilMask
#define glStencilOp jwzgles_glStencilOp
#define glTexCoordPointer jwzgles_glTexCoordPointer
#define glTexEnvf jwzgles_glTexEnvf
#define glTexEnvfv jwzgles_glTexEnvfv
#define glTexImage2D jwzgles_glTexImage2D
#define glTexParameterf jwzgles_glTexParameterf
#define glTexSubImage2D jwzgles_glTexSubImage2D
#define glTranslatef jwzgles_glTranslatef
#define glVertexPointer jwzgles_glVertexPointer
#define glViewport jwzgles_glViewport
#define glEnableClientState jwzgles_glEnableClientState
#define glDisableClientState jwzgles_glDisableClientState
#define glClipPlane jwzgles_glClipPlane
 
 
#define glGetError jwzgles_glGetError
#define glGetString jwzgles_glGetString
 
#endif /* __JWZGLES_H__ */
/polymer/eduke32/build/include/jwzglesI.h
0,0 → 1,353
/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
 
/* A compatibility shim to allow OpenGL 1.3 source code to work in an
OpenGLES environment, where almost every OpenGL 1.3 function has
been "deprecated". See jwzgles.c for details.
*/
 
#ifndef __JWZGLES_I_H__
#define __JWZGLES_I_H__
 
#ifdef GL_VERSION_ES_CM_1_0 /* compiling against OpenGLES 1.x */
 
/* These OpenGL 1.3 constants are not present in OpenGLES 1.
Fortunately, it looks like they didn't re-use any of the numbers,
so we can just keep using the OpenGL 1.3 values. I'm actually
kind of shocked that the GLES folks passed up that opportunity
for further clusterfuckery.
*/
# define GLdouble double
 
# define GL_ACCUM_BUFFER_BIT 0x00000200
# define GL_ALL_ATTRIB_BITS 0x000FFFFF
# define GL_AUTO_NORMAL 0x0D80
# define GL_BLEND_SRC_ALPHA 0x80CB
# define GL_C3F_V3F 0x2A24
# define GL_C4F_N3F_V3F 0x2A26
# define GL_C4UB_V2F 0x2A22
# define GL_C4UB_V3F 0x2A23
# define GL_CLAMP 0x2900
# define GL_COLOR_BUFFER_BIT 0x00004000
# define GL_COLOR_MATERIAL_FACE 0x0B55
# define GL_COLOR_MATERIAL_PARAMETER 0x0B56
# define GL_COMPILE 0x1300
# define GL_CURRENT_BIT 0x00000001
# define GL_DEPTH_BUFFER_BIT 0x00000100
# define GL_DOUBLEBUFFER 0x0C32
# define GL_ENABLE_BIT 0x00002000
# define GL_EVAL_BIT 0x00010000
# define GL_EYE_LINEAR 0x2400
# define GL_EYE_PLANE 0x2502
# define GL_FEEDBACK 0x1C01
# define GL_FILL 0x1B02
# define GL_FOG_BIT 0x00000080
# define GL_HINT_BIT 0x00008000
# define GL_INTENSITY 0x8049
# define GL_LIGHTING_BIT 0x00000040
# define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
# define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
# define GL_LINE 0x1B01
# define GL_LINE_BIT 0x00000004
# define GL_LIST_BIT 0x00020000
# define GL_N3F_V3F 0x2A25
# define GL_OBJECT_LINEAR 0x2401
# define GL_OBJECT_PLANE 0x2501
# define GL_PIXEL_MODE_BIT 0x00000020
# define GL_POINT_BIT 0x00000002
# define GL_POLYGON 0x0009
# define GL_POLYGON_BIT 0x00000008
# define GL_POLYGON_MODE 0x0B40
# define GL_POLYGON_SMOOTH 0x0B41
# define GL_POLYGON_STIPPLE 0x0B42
# define GL_POLYGON_STIPPLE_BIT 0x00000010
# define GL_Q 0x2003
# define GL_QUADS 0x0007
# define GL_QUAD_STRIP 0x0008
# define GL_R 0x2002
# define GL_RENDER 0x1C00
# define GL_RGBA_MODE 0x0C31
# define GL_S 0x2000
# define GL_SCISSOR_BIT 0x00080000
# define GL_SELECT 0x1C02
# define GL_SEPARATE_SPECULAR_COLOR 0x81FA
# define GL_SINGLE_COLOR 0x81F9
# define GL_SPHERE_MAP 0x2402
# define GL_STENCIL_BUFFER_BIT 0x00000400
# define GL_T 0x2001
# define GL_T2F_C3F_V3F 0x2A2A
# define GL_T2F_C4F_N3F_V3F 0x2A2C
# define GL_T2F_C4UB_V3F 0x2A29
# define GL_T2F_N3F_V3F 0x2A2B
# define GL_T2F_V3F 0x2A27
# define GL_T4F_C4F_N3F_V4F 0x2A2D
# define GL_T4F_V4F 0x2A28
# define GL_TEXTURE_1D 0x0DE0
# define GL_TEXTURE_ALPHA_SIZE 0x805F
# define GL_TEXTURE_BIT 0x00040000
# define GL_TEXTURE_BLUE_SIZE 0x805E
# define GL_TEXTURE_BORDER 0x1005
# define GL_TEXTURE_BORDER_COLOR 0x1004
# define GL_TEXTURE_COMPONENTS 0x1003
# define GL_TEXTURE_GEN_MODE 0x2500
# define GL_TEXTURE_GEN_Q 0x0C63
# define GL_TEXTURE_GEN_R 0x0C62
# define GL_TEXTURE_GEN_S 0x0C60
# define GL_TEXTURE_GEN_T 0x0C61
# define GL_TEXTURE_GREEN_SIZE 0x805D
# define GL_TEXTURE_HEIGHT 0x1001
# define GL_TEXTURE_INTENSITY_SIZE 0x8061
# define GL_TEXTURE_LUMINANCE_SIZE 0x8060
# define GL_TEXTURE_RED_SIZE 0x805C
# define GL_TEXTURE_WIDTH 0x1000
# define GL_TRANSFORM_BIT 0x00001000
# define GL_UNPACK_ROW_LENGTH 0x0CF2
# define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
# define GL_V2F 0x2A20
# define GL_V3F 0x2A21
# define GL_VIEWPORT_BIT 0x00000800
# define GL_INT 0x1404
# define GL_DOUBLE 0x140A
 
#endif
 
 
extern void jwzgles_reset (void);
 
 
/* Prototypes for the things re-implemented in jwzgles.c
*/
 
extern int jwzgles_glGenLists (int n);
extern void jwzgles_glNewList (int id, int mode);
extern void jwzgles_glEndList (void);
extern void jwzgles_glDeleteLists (int list, int range);
extern void jwzgles_glBegin (int mode);
extern void jwzgles_glNormal3fv (const GLfloat *);
extern void jwzgles_glNormal3f (GLfloat x, GLfloat y, GLfloat z);
extern void jwzgles_glTexCoord1f (GLfloat s);
extern void jwzgles_glTexCoord2fv (const GLfloat *);
extern void jwzgles_glTexCoord2f (GLfloat s, GLfloat t);
extern void jwzgles_glTexCoord2i (GLint s, GLint t);
extern void jwzgles_glTexCoord3fv (const GLfloat *);
extern void jwzgles_glTexCoord3f (GLfloat s, GLfloat t, GLfloat r);
extern void jwzgles_glTexCoord4fv (const GLfloat *);
extern void jwzgles_glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q);
extern void jwzgles_glVertex2f (GLfloat x, GLfloat y);
extern void jwzgles_glVertex2fv (const GLfloat *);
extern void jwzgles_glVertex2i (GLint x, GLint y);
extern void jwzgles_glVertex3f (GLfloat x, GLfloat y, GLfloat z);
extern void jwzgles_glVertex3dv (const GLdouble *);
extern void jwzgles_glVertex3fv (const GLfloat *);
extern void jwzgles_glVertex3i (GLint x, GLint y, GLint z);
extern void jwzgles_glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
extern void jwzgles_glVertex4fv (const GLfloat *);
extern void jwzgles_glVertex4i (GLint x, GLint y, GLint z, GLint w);
extern void jwzgles_glEnd (void);
extern void jwzgles_glCallList (int id);
extern void jwzgles_glClearIndex(GLfloat c);
extern void jwzgles_glBitmap (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat,
GLfloat, const GLubyte *);
extern void jwzgles_glPushAttrib(int);
extern void jwzgles_glPopAttrib(void);
 
 
/* These functions are present in both OpenGL 1.3 and in OpenGLES 1,
but are allowed within glNewList/glEndList, so we must wrap them
to allow them to be recorded.
*/
extern void jwzgles_glActiveTexture (GLuint);
extern void jwzgles_glBindTexture (GLuint, GLuint);
extern void jwzgles_glBlendFunc (GLuint, GLuint);
extern void jwzgles_glClear (GLuint);
extern void jwzgles_glClearColor (GLclampf, GLclampf, GLclampf, GLclampf);
extern void jwzgles_glClearStencil (GLuint);
extern void jwzgles_glColorMask (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glCullFace (GLuint);
extern void jwzgles_glDepthFunc (GLuint);
extern void jwzgles_glDepthMask (GLuint);
extern void jwzgles_glDisable (GLuint);
extern void jwzgles_glDrawArrays (GLuint, GLuint, GLuint);
extern GLboolean jwzgles_glIsEnabled (GLuint);
extern void jwzgles_glEnable (GLuint);
extern void jwzgles_glFrontFace (GLuint);
extern void jwzgles_glHint (GLuint, GLuint);
extern void jwzgles_glLineWidth (GLfloat);
extern void jwzgles_glLoadIdentity (void);
extern void jwzgles_glLogicOp (GLuint);
extern void jwzgles_glMatrixMode (GLuint);
extern void jwzgles_glMultMatrixf (const GLfloat *);
extern void jwzgles_glLoadMatrixf (const GLfloat *);
extern void jwzgles_glPointSize (GLfloat);
extern void jwzgles_glPolygonOffset (GLfloat, GLfloat);
extern void jwzgles_glPopMatrix (void);
extern void jwzgles_glPushMatrix (void);
extern void jwzgles_glScissor (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glShadeModel (GLuint);
extern void jwzgles_glStencilFunc (GLuint, GLuint, GLuint);
extern void jwzgles_glStencilMask (GLuint);
extern void jwzgles_glStencilOp (GLuint, GLuint, GLuint);
extern void jwzgles_glViewport (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glTranslatef (GLfloat, GLfloat, GLfloat);
extern void jwzgles_glRotatef (GLfloat, GLfloat, GLfloat, GLfloat);
extern void jwzgles_glRotated (GLdouble, GLdouble x, GLdouble y, GLdouble z);
extern void jwzgles_glScalef (GLfloat, GLfloat, GLfloat);
extern void jwzgles_glColor3f (GLfloat, GLfloat, GLfloat);
extern void jwzgles_glColor4f (GLfloat, GLfloat, GLfloat, GLfloat);
extern void jwzgles_glColor3fv (const GLfloat *);
extern void jwzgles_glColor4fv (const GLfloat *);
extern void jwzgles_glColor3s (GLshort, GLshort, GLshort);
extern void jwzgles_glColor4s (GLshort, GLshort, GLshort, GLshort);
extern void jwzgles_glColor3sv (const GLshort *);
extern void jwzgles_glColor4sv (const GLshort *);
extern void jwzgles_glColor3us (GLushort, GLushort, GLushort);
extern void jwzgles_glColor4us (GLushort, GLushort, GLushort, GLushort);
extern void jwzgles_glColor3usv (const GLushort *);
extern void jwzgles_glColor4usv (const GLushort *);
extern void jwzgles_glColor3d (GLdouble, GLdouble, GLdouble);
extern void jwzgles_glColor4d (GLdouble, GLdouble, GLdouble, GLdouble);
extern void jwzgles_glColor3dv (const GLdouble *);
extern void jwzgles_glColor4dv (const GLdouble *);
extern void jwzgles_glColor4i (GLint, GLint, GLint, GLint);
extern void jwzgles_glColor3i (GLint, GLint, GLint);
extern void jwzgles_glColor3iv (const GLint *);
extern void jwzgles_glColor4iv (const GLint *);
extern void jwzgles_glColor4ui (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glColor3ui (GLuint, GLuint, GLuint);
extern void jwzgles_glColor3uiv (const GLuint *);
extern void jwzgles_glColor4uiv (const GLuint *);
extern void jwzgles_glColor4b (GLbyte, GLbyte, GLbyte, GLbyte);
extern void jwzgles_glColor3b (GLbyte, GLbyte, GLbyte);
extern void jwzgles_glColor4bv (const GLbyte *);
extern void jwzgles_glColor3bv (const GLbyte *);
extern void jwzgles_glColor4ub (GLubyte, GLubyte, GLubyte, GLubyte);
extern void jwzgles_glColor3ub (GLubyte, GLubyte, GLubyte);
extern void jwzgles_glColor4ubv (const GLubyte *);
extern void jwzgles_glColor3ubv (const GLubyte *);
extern void jwzgles_glMaterialf (GLuint, GLuint, GLfloat);
extern void jwzgles_glMateriali (GLuint, GLuint, GLuint);
extern void jwzgles_glMaterialfv (GLuint, GLuint, const GLfloat *);
extern void jwzgles_glMaterialiv (GLuint, GLuint, const GLint *);
extern void jwzgles_glFinish (void);
extern void jwzgles_glFlush (void);
extern void jwzgles_glPixelStorei (GLuint, GLuint);
extern void jwzgles_glEnableClientState (GLuint);
extern void jwzgles_glDisableClientState (GLuint);
 
extern void jwzgles_glInitNames (void);
extern void jwzgles_glPushName (GLuint);
extern GLuint jwzgles_glPopName (void);
extern GLuint jwzgles_glRenderMode (GLuint);
extern void jwzgles_glSelectBuffer (GLsizei, GLuint *);
extern void jwzgles_glLightf (GLenum, GLenum, GLfloat);
extern void jwzgles_glLighti (GLenum, GLenum, GLint);
extern void jwzgles_glLightfv (GLenum, GLenum, const GLfloat *);
extern void jwzgles_glLightiv (GLenum, GLenum, const GLint *);
extern void jwzgles_glLightModelf (GLenum, GLfloat);
extern void jwzgles_glLightModeli (GLenum, GLint);
extern void jwzgles_glLightModelfv (GLenum, const GLfloat *);
extern void jwzgles_glLightModeliv (GLenum, const GLint *);
extern void jwzgles_glGenTextures (GLuint, GLuint *);
extern void jwzgles_glFrustum (GLfloat, GLfloat, GLfloat, GLfloat,
GLfloat, GLfloat);
extern void jwzgles_glOrtho (GLfloat, GLfloat, GLfloat, GLfloat,
GLfloat, GLfloat);
extern void jwzgles_glTexImage1D (GLenum target, GLint level,
GLint internalFormat,
GLsizei width, GLint border,
GLenum format, GLenum type,
const GLvoid *pixels);
extern void jwzgles_glTexImage2D (GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *data);
extern void jwzgles_glTexSubImage2D (GLenum target, GLint level,
GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height,
GLenum format, GLenum type,
const GLvoid *pixels);
extern void jwzgles_glCopyTexImage2D (GLenum target, GLint level,
GLenum internalformat,
GLint x, GLint y,
GLsizei width, GLsizei height,
GLint border);
extern void jwzgles_glInterleavedArrays (GLenum, GLsizei, const GLvoid *);
extern void jwzgles_glTexEnvf (GLuint, GLuint, GLfloat);
extern void jwzgles_glTexEnvi (GLuint, GLuint, GLuint);
extern void jwzgles_glTexParameterf (GLuint, GLuint, GLfloat);
extern void jwzgles_glTexParameteri (GLuint, GLuint, GLuint);
extern void jwzgles_glTexGeni (GLenum, GLenum, GLint);
extern void jwzgles_glTexGenfv (GLenum, GLenum, const GLfloat *);
extern void jwzgles_glGetTexGenfv (GLenum, GLenum, GLfloat *);
extern void jwzgles_glRectf (GLfloat, GLfloat, GLfloat, GLfloat);
extern void jwzgles_glRecti (GLint, GLint, GLint, GLint);
extern void jwzgles_glLightModelfv (GLenum, const GLfloat *);
extern void jwzgles_glClearDepth (GLfloat);
extern GLboolean jwzgles_glIsList (GLuint);
extern void jwzgles_glColorMaterial (GLenum, GLenum);
extern void jwzgles_glPolygonMode (GLenum, GLenum);
extern void jwzgles_glFogf (GLenum, GLfloat);
extern void jwzgles_glFogi (GLenum, GLint);
extern void jwzgles_glFogfv (GLenum, const GLfloat *);
extern void jwzgles_glFogiv (GLenum, const GLint *);
extern void jwzgles_glAlphaFunc (GLenum, GLfloat);
extern void jwzgles_glClipPlane (GLenum, const GLdouble *);
extern void jwzgles_glDrawBuffer (GLenum);
extern void jwzgles_glDeleteTextures (GLuint, const GLuint *);
 
extern void jwzgles_gluPerspective (GLdouble fovy, GLdouble aspect,
GLdouble near, GLdouble far);
extern void jwzgles_gluLookAt (GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery,
GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz);
extern GLint jwzgles_gluProject (GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx, GLdouble *winy,
GLdouble *winz);
extern int jwzgles_gluBuild2DMipmaps (GLenum target,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const GLvoid *data);
extern void jwzgles_glGetFloatv (GLenum pname, GLfloat *params);
extern void jwzgles_glGetPointerv (GLenum pname, GLvoid *params);
extern void jwzgles_glGetDoublev (GLenum pname, GLdouble *params);
extern void jwzgles_glGetIntegerv (GLenum pname, GLint *params);
extern void jwzgles_glGetBooleanv (GLenum pname, GLboolean *params);
extern void jwzgles_glVertexPointer (GLuint, GLuint, GLuint, const void *);
extern void jwzgles_glNormalPointer (GLenum, GLuint, const void *);
extern void jwzgles_glColorPointer (GLuint, GLuint, GLuint, const void *);
extern void jwzgles_glTexCoordPointer (GLuint, GLuint, GLuint, const void *);
extern void jwzgles_glBindBuffer (GLuint, GLuint);
extern void jwzgles_glBufferData (GLenum, GLsizeiptr, const void *, GLenum);
extern const char *jwzgles_gluErrorString (GLenum error);
 
extern GLenum jwzgles_glGetError();
extern const GLubyte * jwzgles_glGetString(GLenum name);
 
 
typedef float GLclampd;
 
extern void jwzgles_glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
extern void jwzgles_glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
extern void jwzgles_glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices );
 
#endif /* __JWZGLES_I_H__ */
/polymer/eduke32/build/src/glbuild_android.c
0,0 → 1,1047
#include "compat.h"
#include "glbuild.h"
#include "baselayer.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
 
#include "jwzgles.h"
 
#ifdef RENDERTYPESDL
#include "sdl_inc.h"
#endif
 
bglClearColorProcPtr bglClearColor;
bglClearProcPtr bglClear;
bglColorMaskProcPtr bglColorMask;
bglAlphaFuncProcPtr bglAlphaFunc;
bglBlendFuncProcPtr bglBlendFunc;
bglBlendEquationProcPtr bglBlendEquation;
bglCullFaceProcPtr bglCullFace;
bglFrontFaceProcPtr bglFrontFace;
bglPolygonOffsetProcPtr bglPolygonOffset;
bglPolygonModeProcPtr bglPolygonMode;
bglEnableProcPtr bglEnable;
bglDisableProcPtr bglDisable;
bglGetDoublevProcPtr bglGetDoublev;
bglGetFloatvProcPtr bglGetFloatv;
bglGetIntegervProcPtr bglGetIntegerv;
/*
bglPushAttribProcPtr bglPushAttrib;
bglPopAttribProcPtr bglPopAttrib;
*/
bglGetErrorProcPtr bglGetError;
bglGetStringProcPtr bglGetString;
bglHintProcPtr bglHint;
bglDrawBufferProcPtr bglDrawBuffer;
bglReadBufferProcPtr bglReadBuffer;
bglScissorProcPtr bglScissor;
//bglClipPlaneProcPtr bglClipPlane;
 
// Depth
bglDepthFuncProcPtr bglDepthFunc;
bglDepthMaskProcPtr bglDepthMask;
//bglDepthRangeProcPtr bglDepthRange;
 
// Matrix
bglMatrixModeProcPtr bglMatrixMode;
bglOrthoProcPtr bglOrtho;
bglFrustumProcPtr bglFrustum;
bglViewportProcPtr bglViewport;
bglPushMatrixProcPtr bglPushMatrix;
bglPopMatrixProcPtr bglPopMatrix;
bglLoadIdentityProcPtr bglLoadIdentity;
bglLoadMatrixfProcPtr bglLoadMatrixf;
bglMultMatrixfProcPtr bglMultMatrixf;
bglRotatefProcPtr bglRotatef;
bglScalefProcPtr bglScalef;
bglTranslatefProcPtr bglTranslatef;
 
// Drawing
bglBeginProcPtr bglBegin;
bglEndProcPtr bglEnd;
bglVertex2fProcPtr bglVertex2f;
bglVertex2iProcPtr bglVertex2i;
bglVertex3fProcPtr bglVertex3f;
bglVertex3dProcPtr bglVertex3d;
bglVertex3fvProcPtr bglVertex3fv;
bglVertex3dvProcPtr bglVertex3dv;
bglRectiProcPtr bglRecti;
bglColor3fProcPtr bglColor3f;
bglColor4fProcPtr bglColor4f;
bglColor4ubProcPtr bglColor4ub;
bglTexCoord2dProcPtr bglTexCoord2d;
bglTexCoord2fProcPtr bglTexCoord2f;
bglTexCoord2iProcPtr bglTexCoord2i;
bglNormal3fProcPtr bglNormal3f;
 
// Lighting
bglShadeModelProcPtr bglShadeModel;
bglLightfvProcPtr bglLightfv;
 
// Raster funcs
bglReadPixelsProcPtr bglReadPixels;
bglRasterPos4iProcPtr bglRasterPos4i;
bglDrawPixelsProcPtr bglDrawPixels;
bglPixelStoreiProcPtr bglPixelStorei;
 
// Texture mapping
bglTexEnvfProcPtr bglTexEnvf;
bglGenTexturesProcPtr bglGenTextures;
bglDeleteTexturesProcPtr bglDeleteTextures;
bglBindTextureProcPtr bglBindTexture;
bglTexImage2DProcPtr bglTexImage2D;
bglTexImage3DProcPtr bglTexImage3D;
bglCopyTexImage2DProcPtr bglCopyTexImage2D;
bglCopyTexSubImage2DProcPtr bglCopyTexSubImage2D;
bglTexSubImage2DProcPtr bglTexSubImage2D;
bglTexParameterfProcPtr bglTexParameterf;
bglTexParameteriProcPtr bglTexParameteri;
bglGetTexParameterivProcPtr bglGetTexParameteriv;
bglGetTexLevelParameterivProcPtr bglGetTexLevelParameteriv;
bglCompressedTexImage2DARBProcPtr bglCompressedTexImage2DARB;
bglGetCompressedTexImageARBProcPtr bglGetCompressedTexImageARB;
bglTexGenfvProcPtr bglTexGenfv;
 
// Fog
bglFogfProcPtr bglFogf;
bglFogiProcPtr bglFogi;
bglFogfvProcPtr bglFogfv;
 
// Display Lists
bglNewListProcPtr bglNewList;
bglEndListProcPtr bglEndList;
bglCallListProcPtr bglCallList;
bglDeleteListsProcPtr bglDeleteLists;
 
// Vertex Arrays
bglEnableClientStateProcPtr bglEnableClientState;
bglDisableClientStateProcPtr bglDisableClientState;
bglVertexPointerProcPtr bglVertexPointer;
bglNormalPointerProcPtr bglNormalPointer;
bglTexCoordPointerProcPtr bglTexCoordPointer;
bglDrawArraysProcPtr bglDrawArrays;
bglDrawElementsProcPtr bglDrawElements;
 
// Stencil Buffer
bglClearStencilProcPtr bglClearStencil;
bglStencilOpProcPtr bglStencilOp;
bglStencilFuncProcPtr bglStencilFunc;
 
// GPU Programs
bglGenProgramsARBProcPtr bglGenProgramsARB;
bglBindProgramARBProcPtr bglBindProgramARB;
bglProgramStringARBProcPtr bglProgramStringARB;
bglDeleteProgramsARBProcPtr bglDeleteProgramsARB;
 
// Multitexturing
bglActiveTextureARBProcPtr bglActiveTextureARB;
bglClientActiveTextureARBProcPtr bglClientActiveTextureARB;
bglMultiTexCoord2dARBProcPtr bglMultiTexCoord2dARB;
bglMultiTexCoord2fARBProcPtr bglMultiTexCoord2fARB;
 
// Frame Buffer Objects
bglGenFramebuffersEXTProcPtr bglGenFramebuffersEXT;
bglBindFramebufferEXTProcPtr bglBindFramebufferEXT;
bglFramebufferTexture2DEXTProcPtr bglFramebufferTexture2DEXT;
bglCheckFramebufferStatusEXTProcPtr bglCheckFramebufferStatusEXT;
bglDeleteFramebuffersEXTProcPtr bglDeleteFramebuffersEXT;
 
// Vertex Buffer Objects
bglGenBuffersARBProcPtr bglGenBuffersARB;
bglBindBufferARBProcPtr bglBindBufferARB;
bglDeleteBuffersARBProcPtr bglDeleteBuffersARB;
bglBufferDataARBProcPtr bglBufferDataARB;
bglBufferSubDataARBProcPtr bglBufferSubDataARB;
bglMapBufferARBProcPtr bglMapBufferARB;
bglUnmapBufferARBProcPtr bglUnmapBufferARB;
 
// Occlusion queries
bglGenQueriesARBProcPtr bglGenQueriesARB;
bglDeleteQueriesARBProcPtr bglDeleteQueriesARB;
bglIsQueryARBProcPtr bglIsQueryARB;
bglBeginQueryARBProcPtr bglBeginQueryARB;
bglEndQueryARBProcPtr bglEndQueryARB;
bglGetQueryivARBProcPtr bglGetQueryivARB;
bglGetQueryObjectivARBProcPtr bglGetQueryObjectivARB;
bglGetQueryObjectuivARBProcPtr bglGetQueryObjectuivARB;
 
// Shader Objects
bglDeleteObjectARBProcPtr bglDeleteObjectARB;
bglGetHandleARBProcPtr bglGetHandleARB;
bglDetachObjectARBProcPtr bglDetachObjectARB;
bglCreateShaderObjectARBProcPtr bglCreateShaderObjectARB;
bglShaderSourceARBProcPtr bglShaderSourceARB;
bglCompileShaderARBProcPtr bglCompileShaderARB;
bglCreateProgramObjectARBProcPtr bglCreateProgramObjectARB;
bglAttachObjectARBProcPtr bglAttachObjectARB;
bglLinkProgramARBProcPtr bglLinkProgramARB;
bglUseProgramObjectARBProcPtr bglUseProgramObjectARB;
bglValidateProgramARBProcPtr bglValidateProgramARB;
bglUniform1fARBProcPtr bglUniform1fARB;
bglUniform2fARBProcPtr bglUniform2fARB;
bglUniform3fARBProcPtr bglUniform3fARB;
bglUniform4fARBProcPtr bglUniform4fARB;
bglUniform1iARBProcPtr bglUniform1iARB;
bglUniform2iARBProcPtr bglUniform2iARB;
bglUniform3iARBProcPtr bglUniform3iARB;
bglUniform4iARBProcPtr bglUniform4iARB;
bglUniform1fvARBProcPtr bglUniform1fvARB;
bglUniform2fvARBProcPtr bglUniform2fvARB;
bglUniform3fvARBProcPtr bglUniform3fvARB;
bglUniform4fvARBProcPtr bglUniform4fvARB;
bglUniform1ivARBProcPtr bglUniform1ivARB;
bglUniform2ivARBProcPtr bglUniform2ivARB;
bglUniform3ivARBProcPtr bglUniform3ivARB;
bglUniform4ivARBProcPtr bglUniform4ivARB;
bglUniformMatrix2fvARBProcPtr bglUniformMatrix2fvARB;
bglUniformMatrix3fvARBProcPtr bglUniformMatrix3fvARB;
bglUniformMatrix4fvARBProcPtr bglUniformMatrix4fvARB;
bglGetObjectParameterfvARBProcPtr bglGetObjectParameterfvARB;
bglGetObjectParameterivARBProcPtr bglGetObjectParameterivARB;
bglGetInfoLogARBProcPtr bglGetInfoLogARB;
bglGetAttachedObjectsARBProcPtr bglGetAttachedObjectsARB;
bglGetUniformLocationARBProcPtr bglGetUniformLocationARB;
bglGetActiveUniformARBProcPtr bglGetActiveUniformARB;
bglGetUniformfvARBProcPtr bglGetUniformfvARB;
bglGetUniformivARBProcPtr bglGetUniformivARB;
bglGetShaderSourceARBProcPtr bglGetShaderSourceARB;
 
// Vertex Shaders
bglVertexAttrib1dARBProcPtr bglVertexAttrib1dARB;
bglVertexAttrib1dvARBProcPtr bglVertexAttrib1dvARB;
bglVertexAttrib1fARBProcPtr bglVertexAttrib1fARB;
bglVertexAttrib1fvARBProcPtr bglVertexAttrib1fvARB;
bglVertexAttrib1sARBProcPtr bglVertexAttrib1sARB;
bglVertexAttrib1svARBProcPtr bglVertexAttrib1svARB;
bglVertexAttrib2dARBProcPtr bglVertexAttrib2dARB;
bglVertexAttrib2dvARBProcPtr bglVertexAttrib2dvARB;
bglVertexAttrib2fARBProcPtr bglVertexAttrib2fARB;
bglVertexAttrib2fvARBProcPtr bglVertexAttrib2fvARB;
bglVertexAttrib2sARBProcPtr bglVertexAttrib2sARB;
bglVertexAttrib2svARBProcPtr bglVertexAttrib2svARB;
bglVertexAttrib3dARBProcPtr bglVertexAttrib3dARB;
bglVertexAttrib3dvARBProcPtr bglVertexAttrib3dvARB;
bglVertexAttrib3fARBProcPtr bglVertexAttrib3fARB;
bglVertexAttrib3fvARBProcPtr bglVertexAttrib3fvARB;
bglVertexAttrib3sARBProcPtr bglVertexAttrib3sARB;
bglVertexAttrib3svARBProcPtr bglVertexAttrib3svARB;
bglVertexAttrib4NbvARBProcPtr bglVertexAttrib4NbvARB;
bglVertexAttrib4NivARBProcPtr bglVertexAttrib4NivARB;
bglVertexAttrib4NsvARBProcPtr bglVertexAttrib4NsvARB;
bglVertexAttrib4NubARBProcPtr bglVertexAttrib4NubARB;
bglVertexAttrib4NubvARBProcPtr bglVertexAttrib4NubvARB;
bglVertexAttrib4NuivARBProcPtr bglVertexAttrib4NuivARB;
bglVertexAttrib4NusvARBProcPtr bglVertexAttrib4NusvARB;
bglVertexAttrib4bvARBProcPtr bglVertexAttrib4bvARB;
bglVertexAttrib4dARBProcPtr bglVertexAttrib4dARB;
bglVertexAttrib4dvARBProcPtr bglVertexAttrib4dvARB;
bglVertexAttrib4fARBProcPtr bglVertexAttrib4fARB;
bglVertexAttrib4fvARBProcPtr bglVertexAttrib4fvARB;
bglVertexAttrib4ivARBProcPtr bglVertexAttrib4ivARB;
bglVertexAttrib4sARBProcPtr bglVertexAttrib4sARB;
bglVertexAttrib4svARBProcPtr bglVertexAttrib4svARB;
bglVertexAttrib4ubvARBProcPtr bglVertexAttrib4ubvARB;
bglVertexAttrib4uivARBProcPtr bglVertexAttrib4uivARB;
bglVertexAttrib4usvARBProcPtr bglVertexAttrib4usvARB;
bglVertexAttribPointerARBProcPtr bglVertexAttribPointerARB;
bglEnableVertexAttribArrayARBProcPtr bglEnableVertexAttribArrayARB;
bglDisableVertexAttribArrayARBProcPtr bglDisableVertexAttribArrayARB;
bglGetVertexAttribdvARBProcPtr bglGetVertexAttribdvARB;
bglGetVertexAttribfvARBProcPtr bglGetVertexAttribfvARB;
bglGetVertexAttribivARBProcPtr bglGetVertexAttribivARB;
bglGetVertexAttribPointervARBProcPtr bglGetVertexAttribPointervARB;
bglBindAttribLocationARBProcPtr bglBindAttribLocationARB;
bglGetActiveAttribARBProcPtr bglGetActiveAttribARB;
bglGetAttribLocationARBProcPtr bglGetAttribLocationARB;
 
// Debug Output
#ifndef __APPLE__
bglDebugMessageControlARBProcPtr bglDebugMessageControlARB;
bglDebugMessageCallbackARBProcPtr bglDebugMessageCallbackARB;
#endif
 
// GLU
bgluTessBeginContourProcPtr bgluTessBeginContour;
bgluTessBeginPolygonProcPtr bgluTessBeginPolygon;
bgluTessCallbackProcPtr bgluTessCallback;
bgluTessEndContourProcPtr bgluTessEndContour;
bgluTessEndPolygonProcPtr bgluTessEndPolygon;
bgluTessNormalProcPtr bgluTessNormal;
bgluTessPropertyProcPtr bgluTessProperty;
bgluTessVertexProcPtr bgluTessVertex;
bgluNewTessProcPtr bgluNewTess;
bgluDeleteTessProcPtr bgluDeleteTess;
 
bgluPerspectiveProcPtr bgluPerspective;
 
bgluErrorStringProcPtr bgluErrorString;
 
bgluProjectProcPtr bgluProject;
bgluUnProjectProcPtr bgluUnProject;
 
 
#ifdef _WIN32
// Windows
bwglCreateContextProcPtr bwglCreateContext;
bwglDeleteContextProcPtr bwglDeleteContext;
bwglGetProcAddressProcPtr bwglGetProcAddress;
bwglMakeCurrentProcPtr bwglMakeCurrent;
 
bwglSwapBuffersProcPtr bwglSwapBuffers;
bwglChoosePixelFormatProcPtr bwglChoosePixelFormat;
bwglDescribePixelFormatProcPtr bwglDescribePixelFormat;
bwglGetPixelFormatProcPtr bwglGetPixelFormat;
bwglSetPixelFormatProcPtr bwglSetPixelFormat;
bwglSwapIntervalEXTProcPtr bwglSwapIntervalEXT;
bwglCreateContextAttribsARBProcPtr bwglCreateContextAttribsARB;
 
static HMODULE hGLDLL, hGLUDLL;
#else
#include <dlfcn.h>
 
static void *gluhandle = NULL;
#endif
 
char *gldriver = NULL, *glulibrary = NULL;
 
static void *getproc_(const char *s, int32_t *err, int32_t fatal, int32_t extension)
{
void *t;
#if defined RENDERTYPESDL
UNREFERENCED_PARAMETER(extension);
t = (void *)SDL_GL_GetProcAddress(s);
#elif defined _WIN32
if (extension) t = (void *)bwglGetProcAddress(s);
else t = (void *)GetProcAddress(hGLDLL,s);
#else
#error Need a dynamic loader for this platform...
#endif
if (!t && fatal)
{
initprintf("Failed to find %s in %s\n", s, gldriver);
*err = 1;
}
return t;
}
#define GETPROC(s) getproc_(s,&err,1,0)
#define GETPROCSOFT(s) getproc_(s,&err,0,0)
#define GETPROCEXT(s) getproc_(s,&err,1,1)
#define GETPROCEXTSOFT(s) getproc_(s,&err,0,1)
 
int32_t loadgldriver(const char *driver)
{
int32_t err=0;
 
 
// gldriver = Bstrdup(driver);
 
// QGL_Init( 0 );
jwzgles_reset();
 
bglClearColor = (bglClearColorProcPtr) glClearColor;
bglClear = (bglClearProcPtr) glClear;
bglColorMask = (bglColorMaskProcPtr) glColorMask;
bglAlphaFunc = (bglAlphaFuncProcPtr) glAlphaFunc;
bglBlendFunc = (bglBlendFuncProcPtr) glBlendFunc;
bglCullFace = (bglCullFaceProcPtr) glCullFace;
bglFrontFace = (bglFrontFaceProcPtr) glFrontFace;
bglPolygonOffset = (bglPolygonOffsetProcPtr) glPolygonOffset;
bglPolygonMode = (bglPolygonModeProcPtr) glPolygonMode;
bglEnable = (bglEnableProcPtr) glEnable;
bglDisable = (bglDisableProcPtr) glDisable;
bglGetDoublev = (bglGetDoublevProcPtr) glGetDoublev;
bglGetFloatv = (bglGetFloatvProcPtr) glGetFloatv;
bglGetIntegerv = (bglGetIntegervProcPtr) glGetIntegerv;
/*
bglPushAttrib = (bglPushAttribProcPtr) glPushAttrib;
bglPopAttrib = (bglPopAttribProcPtr) glPopAttrib;
*/
bglGetError = (bglGetErrorProcPtr) glGetError;
bglGetString = (bglGetStringProcPtr) glGetString;
bglHint = (bglHintProcPtr) glHint;
bglDrawBuffer = (bglDrawBufferProcPtr) glDrawBuffer;
bglReadBuffer = (bglReadBufferProcPtr) glDrawBuffer;
bglScissor = (bglScissorProcPtr) glScissor;
// bglClipPlane = (bglClipPlaneProcPtr) glClipPlane;
 
// Depth
bglDepthFunc = (bglDepthFuncProcPtr) glDepthFunc;
bglDepthMask = (bglDepthMaskProcPtr) glDepthMask;
// bglDepthRange = (bglDepthRangeProcPtr) glDepthRange;
 
// Matrix
bglMatrixMode = (bglMatrixModeProcPtr) glMatrixMode;
bglOrtho = (bglOrthoProcPtr) glOrtho;
bglFrustum = (bglFrustumProcPtr) glFrustum;
bglViewport = (bglViewportProcPtr) glViewport;
bglPushMatrix = (bglPushMatrixProcPtr) glPushMatrix;
bglPopMatrix = (bglPopMatrixProcPtr) glPopMatrix;
bglLoadIdentity = (bglLoadIdentityProcPtr) glLoadIdentity;
bglLoadMatrixf = (bglLoadMatrixfProcPtr) glLoadMatrixf;
bglMultMatrixf = (bglMultMatrixfProcPtr) glMultMatrixf;
bglRotatef = (bglRotatefProcPtr) glRotatef;
bglScalef = (bglScalefProcPtr) glScalef;
bglTranslatef = (bglTranslatefProcPtr) glTranslatef;
 
// Drawing
bglBegin = (bglBeginProcPtr) glBegin;
bglEnd = (bglEndProcPtr) glEnd;
bglVertex2f = (bglVertex2fProcPtr) glVertex2f;
bglVertex2i = (bglVertex2iProcPtr) glVertex2i;
bglVertex3f = (bglVertex3fProcPtr) glVertex3f;
bglVertex3d = (bglVertex3dProcPtr) glVertex3d;
bglVertex3fv = (bglVertex3fvProcPtr) glVertex3fv;
bglVertex3dv = (bglVertex3dvProcPtr) glVertex3dv;
bglRecti = (bglRectiProcPtr) glRectd;
bglColor4f = (bglColor4fProcPtr) glColor4f;
bglColor3f = (bglColor3fProcPtr) glColor3f;
bglColor4ub = (bglColor4ubProcPtr) glColor4ub;
bglTexCoord2d = (bglTexCoord2dProcPtr) glTexCoord2d;
bglTexCoord2f = (bglTexCoord2fProcPtr) glTexCoord2f;
bglTexCoord2i = (bglTexCoord2iProcPtr) glTexCoord2i;
bglNormal3f = (bglNormal3fProcPtr) glNormal3f;
 
// Lighting
bglShadeModel = (bglShadeModelProcPtr) glShadeModel;
bglLightfv = (bglLightfvProcPtr) glLightfv;
 
// Raster funcs
bglReadPixels = (bglReadPixelsProcPtr) glReadPixels;
// bglRasterPos4i = (bglRasterPos4iProcPtr) glRasterPos4i;
// bglDrawPixels = (bglDrawPixelsProcPtr) glDrawPixels;
bglPixelStorei = (bglPixelStoreiProcPtr) glPixelStorei;
 
// Texture mapping
bglTexEnvf = (bglTexEnvfProcPtr) glTexEnvf;
bglGenTextures = (bglGenTexturesProcPtr) glGenTextures;
bglDeleteTextures = (bglDeleteTexturesProcPtr) glDeleteTextures;
bglBindTexture = (bglBindTextureProcPtr) glBindTexture;
bglTexImage2D = (bglTexImage2DProcPtr) glTexImage2D;
bglCopyTexImage2D = (bglCopyTexImage2DProcPtr) glCopyTexImage2D;
bglCopyTexSubImage2D = (bglCopyTexSubImage2DProcPtr) glCopyTexSubImage2D;
bglTexSubImage2D = (bglTexSubImage2DProcPtr) glTexSubImage2D;
bglTexParameterf = (bglTexParameterfProcPtr) glTexParameterf;
bglTexParameteri = (bglTexParameteriProcPtr) glTexParameteri;
// bglGetTexParameteriv = (bglGetTexParameterivProcPtr) glGetTexParameteriv;
// bglGetTexLevelParameteriv = (bglGetTexLevelParameterivProcPtr) glGetTexLevelParameteriv;
bglTexGenfv = (bglTexGenfvProcPtr) glTexGenfv;
 
// Fog
bglFogf = (bglFogfProcPtr) glFogf;
bglFogi = (bglFogiProcPtr) glFogi;
bglFogfv = (bglFogfvProcPtr) glFogfv;
 
// Display Lists
bglNewList = (bglNewListProcPtr) glNewList;
bglEndList = (bglEndListProcPtr) glEndList;
bglCallList = (bglCallListProcPtr) glCallList;
bglDeleteLists = (bglDeleteListsProcPtr) glDeleteLists;
 
// Vertex Arrays
bglEnableClientState = (bglEnableClientStateProcPtr) glEnableClientState;
bglDisableClientState = (bglDisableClientStateProcPtr) glDisableClientState;
bglVertexPointer = (bglVertexPointerProcPtr) glVertexPointer;
bglNormalPointer = (bglNormalPointerProcPtr) glNormalPointer;
bglTexCoordPointer = (bglTexCoordPointerProcPtr) glTexCoordPointer;
bglDrawArrays = (bglDrawArraysProcPtr) glDrawArrays;
bglDrawElements = (bglDrawElementsProcPtr) glDrawElements;
 
// Stencil Buffer
bglClearStencil = (bglClearStencilProcPtr) glClearStencil;
bglStencilOp = (bglStencilOpProcPtr) glStencilOp;
bglStencilFunc = (bglStencilFuncProcPtr) glStencilFunc;
 
//ALSO NEEDED FOR POLYMOST!!
bglActiveTextureARB = (bglActiveTextureARBProcPtr)glActiveTexture;
 
// loadglextensions();
// loadglulibrary(getenv("BUILD_GLULIB"));
 
 
 
return 0;
}
 
int32_t loadglextensions(void)
{
int32_t err = 0;
#ifdef _WIN32
if (!hGLDLL) return 0;
#endif
 
bglBlendEquation = (bglBlendEquationProcPtr) GETPROCEXTSOFT("glBlendEquation");
 
bglTexImage3D = (bglTexImage3DProcPtr) GETPROCEXTSOFT("glTexImage3D");
bglCompressedTexImage2DARB = (bglCompressedTexImage2DARBProcPtr) GETPROCEXTSOFT("glCompressedTexImage2DARB");
bglGetCompressedTexImageARB = (bglGetCompressedTexImageARBProcPtr) GETPROCEXTSOFT("glGetCompressedTexImageARB");
 
// GPU Programs
bglGenProgramsARB = (bglGenProgramsARBProcPtr) GETPROCEXTSOFT("glGenProgramsARB");
bglBindProgramARB = (bglBindProgramARBProcPtr) GETPROCEXTSOFT("glBindProgramARB");
bglProgramStringARB = (bglProgramStringARBProcPtr) GETPROCEXTSOFT("glProgramStringARB");
bglDeleteProgramsARB = (bglDeleteProgramsARBProcPtr) GETPROCEXTSOFT("glDeleteProgramsARB");
 
// Multitexturing
bglActiveTextureARB = (bglActiveTextureARBProcPtr) GETPROCEXTSOFT("glActiveTextureARB");
bglClientActiveTextureARB = (bglClientActiveTextureARBProcPtr) GETPROCEXTSOFT("glClientActiveTextureARB");
bglMultiTexCoord2dARB = (bglMultiTexCoord2dARBProcPtr) GETPROCEXTSOFT("glMultiTexCoord2dARB");
bglMultiTexCoord2fARB = (bglMultiTexCoord2fARBProcPtr) GETPROCEXTSOFT("glMultiTexCoord2fARB");
 
// Frame Buffer Objects
bglGenFramebuffersEXT = (bglGenFramebuffersEXTProcPtr) GETPROCEXTSOFT("glGenFramebuffersEXT");
bglBindFramebufferEXT = (bglBindFramebufferEXTProcPtr) GETPROCEXTSOFT("glBindFramebufferEXT");
bglFramebufferTexture2DEXT = (bglFramebufferTexture2DEXTProcPtr) GETPROCEXTSOFT("glFramebufferTexture2DEXT");
bglCheckFramebufferStatusEXT = (bglCheckFramebufferStatusEXTProcPtr) GETPROCEXTSOFT("glCheckFramebufferStatusEXT");
bglDeleteFramebuffersEXT = (bglDeleteFramebuffersEXTProcPtr) GETPROCEXTSOFT("glDeleteFramebuffersEXT");
 
// Vertex Buffer Objects
bglGenBuffersARB = (bglGenBuffersARBProcPtr) GETPROCEXTSOFT("glGenBuffersARB");
bglBindBufferARB = (bglBindBufferARBProcPtr) GETPROCEXTSOFT("glBindBufferARB");
bglDeleteBuffersARB = (bglDeleteBuffersARBProcPtr) GETPROCEXTSOFT("glDeleteBuffersARB");
bglBufferDataARB = (bglBufferDataARBProcPtr) GETPROCEXTSOFT("glBufferDataARB");
bglBufferSubDataARB = (bglBufferSubDataARBProcPtr) GETPROCEXTSOFT("glBufferSubDataARB");
bglMapBufferARB = (bglMapBufferARBProcPtr) GETPROCEXTSOFT("glMapBufferARB");
bglUnmapBufferARB = (bglUnmapBufferARBProcPtr) GETPROCEXTSOFT("glUnmapBufferARB");
 
// Occlusion queries
bglGenQueriesARB = (bglGenQueriesARBProcPtr) GETPROCEXTSOFT("glGenQueriesARB");
bglDeleteQueriesARB = (bglDeleteQueriesARBProcPtr) GETPROCEXTSOFT("glDeleteQueriesARB");
bglIsQueryARB = (bglIsQueryARBProcPtr) GETPROCEXTSOFT("glIsQueryARB");
bglBeginQueryARB = (bglBeginQueryARBProcPtr) GETPROCEXTSOFT("glBeginQueryARB");
bglEndQueryARB = (bglEndQueryARBProcPtr) GETPROCEXTSOFT("glEndQueryARB");
bglGetQueryivARB = (bglGetQueryivARBProcPtr) GETPROCEXTSOFT("glGetQueryivARB");
bglGetQueryObjectivARB = (bglGetQueryObjectivARBProcPtr) GETPROCEXTSOFT("glGetQueryObjectivARB");
bglGetQueryObjectuivARB = (bglGetQueryObjectuivARBProcPtr) GETPROCEXTSOFT("glGetQueryObjectuivARB");
 
// Shader Objects
bglDeleteObjectARB = (bglDeleteObjectARBProcPtr) GETPROCEXTSOFT("glDeleteObjectARB");
bglGetHandleARB = (bglGetHandleARBProcPtr) GETPROCEXTSOFT("glGetHandleARB");
bglDetachObjectARB = (bglDetachObjectARBProcPtr) GETPROCEXTSOFT("glDetachObjectARB");
bglCreateShaderObjectARB = (bglCreateShaderObjectARBProcPtr) GETPROCEXTSOFT("glCreateShaderObjectARB");
bglShaderSourceARB = (bglShaderSourceARBProcPtr) GETPROCEXTSOFT("glShaderSourceARB");
bglCompileShaderARB = (bglCompileShaderARBProcPtr) GETPROCEXTSOFT("glCompileShaderARB");
bglCreateProgramObjectARB = (bglCreateProgramObjectARBProcPtr) GETPROCEXTSOFT("glCreateProgramObjectARB");
bglAttachObjectARB = (bglAttachObjectARBProcPtr) GETPROCEXTSOFT("glAttachObjectARB");
bglLinkProgramARB = (bglLinkProgramARBProcPtr) GETPROCEXTSOFT("glLinkProgramARB");
bglUseProgramObjectARB = (bglUseProgramObjectARBProcPtr) GETPROCEXTSOFT("glUseProgramObjectARB");
bglValidateProgramARB = (bglValidateProgramARBProcPtr) GETPROCEXTSOFT("glValidateProgramARB");
bglUniform1fARB = (bglUniform1fARBProcPtr) GETPROCEXTSOFT("glUniform1fARB");
bglUniform2fARB = (bglUniform2fARBProcPtr) GETPROCEXTSOFT("glUniform2fARB");
bglUniform3fARB = (bglUniform3fARBProcPtr) GETPROCEXTSOFT("glUniform3fARB");
bglUniform4fARB = (bglUniform4fARBProcPtr) GETPROCEXTSOFT("glUniform4fARB");
bglUniform1iARB = (bglUniform1iARBProcPtr) GETPROCEXTSOFT("glUniform1iARB");
bglUniform2iARB = (bglUniform2iARBProcPtr) GETPROCEXTSOFT("glUniform2iARB");
bglUniform3iARB = (bglUniform3iARBProcPtr) GETPROCEXTSOFT("glUniform3iARB");
bglUniform4iARB = (bglUniform4iARBProcPtr) GETPROCEXTSOFT("glUniform4iARB");
bglUniform1fvARB = (bglUniform1fvARBProcPtr) GETPROCEXTSOFT("glUniform1fvARB");
bglUniform2fvARB = (bglUniform2fvARBProcPtr) GETPROCEXTSOFT("glUniform2fvARB");
bglUniform3fvARB = (bglUniform3fvARBProcPtr) GETPROCEXTSOFT("glUniform3fvARB");
bglUniform4fvARB = (bglUniform4fvARBProcPtr) GETPROCEXTSOFT("glUniform4fvARB");
bglUniform1ivARB = (bglUniform1ivARBProcPtr) GETPROCEXTSOFT("glUniform1ivARB");
bglUniform2ivARB = (bglUniform2ivARBProcPtr) GETPROCEXTSOFT("glUniform2ivARB");
bglUniform3ivARB = (bglUniform3ivARBProcPtr) GETPROCEXTSOFT("glUniform3ivARB");
bglUniform4ivARB = (bglUniform4ivARBProcPtr) GETPROCEXTSOFT("glUniform4ivARB");
bglUniformMatrix2fvARB = (bglUniformMatrix2fvARBProcPtr) GETPROCEXTSOFT("glUniformMatrix2fvARB");
bglUniformMatrix3fvARB = (bglUniformMatrix3fvARBProcPtr) GETPROCEXTSOFT("glUniformMatrix3fvARB");
bglUniformMatrix4fvARB = (bglUniformMatrix4fvARBProcPtr) GETPROCEXTSOFT("glUniformMatrix4fvARB");
bglGetObjectParameterfvARB = (bglGetObjectParameterfvARBProcPtr) GETPROCEXTSOFT("glGetObjectParameterfvARB");
bglGetObjectParameterivARB = (bglGetObjectParameterivARBProcPtr) GETPROCEXTSOFT("glGetObjectParameterivARB");
bglGetInfoLogARB = (bglGetInfoLogARBProcPtr) GETPROCEXTSOFT("glGetInfoLogARB");
bglGetAttachedObjectsARB = (bglGetAttachedObjectsARBProcPtr) GETPROCEXTSOFT("glGetAttachedObjectsARB");
bglGetUniformLocationARB = (bglGetUniformLocationARBProcPtr) GETPROCEXTSOFT("glGetUniformLocationARB");
bglGetActiveUniformARB = (bglGetActiveUniformARBProcPtr) GETPROCEXTSOFT("glGetActiveUniformARB");
bglGetUniformfvARB = (bglGetUniformfvARBProcPtr) GETPROCEXTSOFT("glGetUniformfvARB");
bglGetUniformivARB = (bglGetUniformivARBProcPtr) GETPROCEXTSOFT("glGetUniformivARB");
bglGetShaderSourceARB = (bglGetShaderSourceARBProcPtr) GETPROCEXTSOFT("glGetShaderSourceARB");
 
// Vertex Shaders
bglVertexAttrib1dARB = (bglVertexAttrib1dARBProcPtr) GETPROCEXTSOFT("glVertexAttrib1dARB");
bglVertexAttrib1dvARB = (bglVertexAttrib1dvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib1dvARB");
bglVertexAttrib1fARB = (bglVertexAttrib1fARBProcPtr) GETPROCEXTSOFT("glVertexAttrib1fARB");
bglVertexAttrib1fvARB = (bglVertexAttrib1fvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib1fvARB");
bglVertexAttrib1sARB = (bglVertexAttrib1sARBProcPtr) GETPROCEXTSOFT("glVertexAttrib1sARB");
bglVertexAttrib1svARB = (bglVertexAttrib1svARBProcPtr) GETPROCEXTSOFT("glVertexAttrib1svARB");
bglVertexAttrib2dARB = (bglVertexAttrib2dARBProcPtr) GETPROCEXTSOFT("glVertexAttrib2dARB");
bglVertexAttrib2dvARB = (bglVertexAttrib2dvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib2dvARB");
bglVertexAttrib2fARB = (bglVertexAttrib2fARBProcPtr) GETPROCEXTSOFT("glVertexAttrib2fARB");
bglVertexAttrib2fvARB = (bglVertexAttrib2fvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib2fvARB");
bglVertexAttrib2sARB = (bglVertexAttrib2sARBProcPtr) GETPROCEXTSOFT("glVertexAttrib2sARB");
bglVertexAttrib2svARB = (bglVertexAttrib2svARBProcPtr) GETPROCEXTSOFT("glVertexAttrib2svARB");
bglVertexAttrib3dARB = (bglVertexAttrib3dARBProcPtr) GETPROCEXTSOFT("glVertexAttrib3dARB");
bglVertexAttrib3dvARB = (bglVertexAttrib3dvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib3dvARB");
bglVertexAttrib3fARB = (bglVertexAttrib3fARBProcPtr) GETPROCEXTSOFT("glVertexAttrib3fARB");
bglVertexAttrib3fvARB = (bglVertexAttrib3fvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib3fvARB");
bglVertexAttrib3sARB = (bglVertexAttrib3sARBProcPtr) GETPROCEXTSOFT("glVertexAttrib3sARB");
bglVertexAttrib3svARB = (bglVertexAttrib3svARBProcPtr) GETPROCEXTSOFT("glVertexAttrib3svARB");
bglVertexAttrib4NbvARB = (bglVertexAttrib4NbvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NbvARB");
bglVertexAttrib4NivARB = (bglVertexAttrib4NivARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NivARB");
bglVertexAttrib4NsvARB = (bglVertexAttrib4NsvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NsvARB");
bglVertexAttrib4NubARB = (bglVertexAttrib4NubARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NubARB");
bglVertexAttrib4NubvARB = (bglVertexAttrib4NubvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NubvARB");
bglVertexAttrib4NuivARB = (bglVertexAttrib4NuivARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NuivARB");
bglVertexAttrib4NusvARB = (bglVertexAttrib4NusvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4NusvARB");
bglVertexAttrib4bvARB = (bglVertexAttrib4bvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4bvARB");
bglVertexAttrib4dARB = (bglVertexAttrib4dARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4dARB");
bglVertexAttrib4dvARB = (bglVertexAttrib4dvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4dvARB");
bglVertexAttrib4fARB = (bglVertexAttrib4fARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4fARB");
bglVertexAttrib4fvARB = (bglVertexAttrib4fvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4fvARB");
bglVertexAttrib4ivARB = (bglVertexAttrib4ivARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4ivARB");
bglVertexAttrib4sARB = (bglVertexAttrib4sARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4sARB");
bglVertexAttrib4svARB = (bglVertexAttrib4svARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4svARB");
bglVertexAttrib4ubvARB = (bglVertexAttrib4ubvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4ubvARB");
bglVertexAttrib4uivARB = (bglVertexAttrib4uivARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4uivARB");
bglVertexAttrib4usvARB = (bglVertexAttrib4usvARBProcPtr) GETPROCEXTSOFT("glVertexAttrib4usvARB");
bglVertexAttribPointerARB = (bglVertexAttribPointerARBProcPtr) GETPROCEXTSOFT("glVertexAttribPointerARB");
bglEnableVertexAttribArrayARB = (bglEnableVertexAttribArrayARBProcPtr) GETPROCEXTSOFT("glEnableVertexAttribArrayARB");
bglDisableVertexAttribArrayARB = (bglDisableVertexAttribArrayARBProcPtr) GETPROCEXTSOFT("glDisableVertexAttribArrayARB");
bglGetVertexAttribdvARB = (bglGetVertexAttribdvARBProcPtr) GETPROCEXTSOFT("glGetVertexAttribdvARB");
bglGetVertexAttribfvARB = (bglGetVertexAttribfvARBProcPtr) GETPROCEXTSOFT("glGetVertexAttribfvARB");
bglGetVertexAttribivARB = (bglGetVertexAttribivARBProcPtr) GETPROCEXTSOFT("glGetVertexAttribivARB");
bglGetVertexAttribPointervARB = (bglGetVertexAttribPointervARBProcPtr) GETPROCEXTSOFT("glGetVertexAttribPointervARB");
bglBindAttribLocationARB = (bglBindAttribLocationARBProcPtr) GETPROCEXTSOFT("glBindAttribLocationARB");
bglGetActiveAttribARB = (bglGetActiveAttribARBProcPtr) GETPROCEXTSOFT("glGetActiveAttribARB");
bglGetAttribLocationARB = (bglGetAttribLocationARBProcPtr) GETPROCEXTSOFT("glGetAttribLocationARB");
 
// Debug Output
#ifndef __APPLE__
bglDebugMessageControlARB = (bglDebugMessageControlARBProcPtr) GETPROCEXTSOFT("glDebugMessageControlARB");
bglDebugMessageCallbackARB = (bglDebugMessageCallbackARBProcPtr) GETPROCEXTSOFT("glDebugMessageCallbackARB");
#endif
 
#ifdef _WIN32
bwglSwapIntervalEXT = (bwglSwapIntervalEXTProcPtr) GETPROCEXTSOFT("wglSwapIntervalEXT");
bwglCreateContextAttribsARB = (bwglCreateContextAttribsARBProcPtr) GETPROCEXTSOFT("wglCreateContextAttribsARB");
#endif
return err;
}
 
int32_t unloadgldriver(void)
{
unloadglulibrary();
 
#ifdef _WIN32
if (!hGLDLL) return 0;
#endif
 
Bfree(gldriver);
gldriver = NULL;
 
#ifdef _WIN32
FreeLibrary(hGLDLL);
hGLDLL = NULL;
#endif
 
bglClearColor = (bglClearColorProcPtr) NULL;
bglClear = (bglClearProcPtr) NULL;
bglColorMask = (bglColorMaskProcPtr) NULL;
bglAlphaFunc = (bglAlphaFuncProcPtr) NULL;
bglBlendFunc = (bglBlendFuncProcPtr) NULL;
bglBlendEquation = (bglBlendEquationProcPtr) NULL;
bglCullFace = (bglCullFaceProcPtr) NULL;
bglFrontFace = (bglFrontFaceProcPtr) NULL;
bglPolygonOffset = (bglPolygonOffsetProcPtr) NULL;
bglPolygonMode = (bglPolygonModeProcPtr) NULL;
bglEnable = (bglEnableProcPtr) NULL;
bglDisable = (bglDisableProcPtr) NULL;
bglGetDoublev = (bglGetDoublevProcPtr) NULL;
bglGetFloatv = (bglGetFloatvProcPtr) NULL;
bglGetIntegerv = (bglGetIntegervProcPtr) NULL;
/*
bglPushAttrib = (bglPushAttribProcPtr) NULL;
bglPopAttrib = (bglPopAttribProcPtr) NULL;
*/
bglGetError = (bglGetErrorProcPtr) NULL;
bglGetString = (bglGetStringProcPtr) NULL;
bglHint = (bglHintProcPtr) NULL;
bglDrawBuffer = (bglDrawBufferProcPtr) NULL;
bglReadBuffer = (bglReadBufferProcPtr) NULL;
bglScissor = (bglScissorProcPtr) NULL;
// bglClipPlane = (bglClipPlaneProcPtr) NULL;
 
// Depth
bglDepthFunc = (bglDepthFuncProcPtr) NULL;
bglDepthMask = (bglDepthMaskProcPtr) NULL;
// bglDepthRange = (bglDepthRangeProcPtr) NULL;
 
// Matrix
bglMatrixMode = (bglMatrixModeProcPtr) NULL;
bglOrtho = (bglOrthoProcPtr) NULL;
bglFrustum = (bglFrustumProcPtr) NULL;
bglViewport = (bglViewportProcPtr) NULL;
bglPushMatrix = (bglPushMatrixProcPtr) NULL;
bglPopMatrix = (bglPopMatrixProcPtr) NULL;
bglLoadIdentity = (bglLoadIdentityProcPtr) NULL;
bglLoadMatrixf = (bglLoadMatrixfProcPtr) NULL;
bglMultMatrixf = (bglMultMatrixfProcPtr) NULL;
bglRotatef = (bglRotatefProcPtr) NULL;
bglScalef = (bglScalefProcPtr) NULL;
bglTranslatef = (bglTranslatefProcPtr) NULL;
 
// Drawing
bglBegin = (bglBeginProcPtr) NULL;
bglEnd = (bglEndProcPtr) NULL;
bglVertex2f = (bglVertex2fProcPtr) NULL;
bglVertex2i = (bglVertex2iProcPtr) NULL;
bglVertex3f = (bglVertex3fProcPtr) NULL;
bglVertex3d = (bglVertex3dProcPtr) NULL;
bglVertex3fv = (bglVertex3fvProcPtr) NULL;
bglColor4f = (bglColor4fProcPtr) NULL;
bglColor4ub = (bglColor4ubProcPtr) NULL;
bglTexCoord2d = (bglTexCoord2dProcPtr) NULL;
bglTexCoord2f = (bglTexCoord2fProcPtr) NULL;
bglTexCoord2i = (bglTexCoord2iProcPtr) NULL;
bglNormal3f = (bglNormal3fProcPtr) NULL;
 
// Lighting
bglShadeModel = (bglShadeModelProcPtr) NULL;
bglLightfv = (bglLightfvProcPtr) NULL;
 
// Raster funcs
bglReadPixels = (bglReadPixelsProcPtr) NULL;
bglRasterPos4i = (bglRasterPos4iProcPtr) NULL;
bglDrawPixels = (bglDrawPixelsProcPtr) NULL;
bglPixelStorei = (bglPixelStoreiProcPtr) NULL;
 
// Texture mapping
bglTexEnvf = (bglTexEnvfProcPtr) NULL;
bglGenTextures = (bglGenTexturesProcPtr) NULL;
bglDeleteTextures = (bglDeleteTexturesProcPtr) NULL;
bglBindTexture = (bglBindTextureProcPtr) NULL;
bglTexImage2D = (bglTexImage2DProcPtr) NULL;
bglTexImage3D = (bglTexImage3DProcPtr) NULL;
bglCopyTexImage2D = (bglCopyTexImage2DProcPtr) NULL;
bglCopyTexSubImage2D= NULL;
bglTexSubImage2D = (bglTexSubImage2DProcPtr) NULL;
bglTexParameterf = (bglTexParameterfProcPtr) NULL;
bglTexParameteri = (bglTexParameteriProcPtr) NULL;
bglGetTexParameteriv = (bglGetTexParameterivProcPtr) NULL;
bglGetTexLevelParameteriv = (bglGetTexLevelParameterivProcPtr) NULL;
bglCompressedTexImage2DARB = (bglCompressedTexImage2DARBProcPtr) NULL;
bglGetCompressedTexImageARB = (bglGetCompressedTexImageARBProcPtr) NULL;
 
// Fog
bglFogf = (bglFogfProcPtr) NULL;
bglFogi = (bglFogiProcPtr) NULL;
bglFogfv = (bglFogfvProcPtr) NULL;
 
// Display Lists
bglNewList = (bglNewListProcPtr) NULL;
bglEndList = (bglEndListProcPtr) NULL;
bglCallList = (bglCallListProcPtr) NULL;
bglDeleteLists = (bglDeleteListsProcPtr) NULL;
 
// Vertex Arrays
bglEnableClientState = (bglEnableClientStateProcPtr) NULL;
bglDisableClientState = (bglDisableClientStateProcPtr) NULL;
bglVertexPointer = (bglVertexPointerProcPtr) NULL;
bglNormalPointer = (bglNormalPointerProcPtr) NULL;
bglTexCoordPointer = (bglTexCoordPointerProcPtr) NULL;
bglDrawElements = (bglDrawElementsProcPtr) NULL;
 
// Stencil Buffer
bglClearStencil = (bglClearStencilProcPtr) NULL;
bglStencilOp = (bglStencilOpProcPtr) NULL;
bglStencilFunc = (bglStencilFuncProcPtr) NULL;
 
// GPU Programs
bglGenProgramsARB = (bglGenProgramsARBProcPtr) NULL;
bglBindProgramARB = (bglBindProgramARBProcPtr) NULL;
bglProgramStringARB = (bglProgramStringARBProcPtr) NULL;
bglDeleteProgramsARB= NULL;
 
// Multitexturing
bglActiveTextureARB = (bglActiveTextureARBProcPtr) NULL;
bglClientActiveTextureARB = (bglClientActiveTextureARBProcPtr) NULL;
bglMultiTexCoord2dARB = (bglMultiTexCoord2dARBProcPtr) NULL;
bglMultiTexCoord2fARB = (bglMultiTexCoord2fARBProcPtr) NULL;
 
// Frame Buffer Objects
bglGenFramebuffersEXT = (bglGenFramebuffersEXTProcPtr) NULL;
bglBindFramebufferEXT = (bglBindFramebufferEXTProcPtr) NULL;
bglFramebufferTexture2DEXT = (bglFramebufferTexture2DEXTProcPtr) NULL;
bglCheckFramebufferStatusEXT = (bglCheckFramebufferStatusEXTProcPtr) NULL;
bglDeleteFramebuffersEXT = (bglDeleteFramebuffersEXTProcPtr) NULL;
 
// Vertex Buffer Objects
bglGenBuffersARB = (bglGenBuffersARBProcPtr) NULL;
bglBindBufferARB = (bglBindBufferARBProcPtr) NULL;
bglDeleteBuffersARB = (bglDeleteBuffersARBProcPtr) NULL;
bglBufferDataARB = (bglBufferDataARBProcPtr) NULL;
bglBufferSubDataARB = (bglBufferSubDataARBProcPtr) NULL;
bglMapBufferARB = (bglMapBufferARBProcPtr) NULL;
bglUnmapBufferARB = (bglUnmapBufferARBProcPtr) NULL;
 
// Occlusion queries
bglGenQueriesARB = (bglGenQueriesARBProcPtr) NULL;
bglDeleteQueriesARB = (bglDeleteQueriesARBProcPtr) NULL;
bglIsQueryARB = (bglIsQueryARBProcPtr) NULL;
bglBeginQueryARB = (bglBeginQueryARBProcPtr) NULL;
bglEndQueryARB = (bglEndQueryARBProcPtr) NULL;
bglGetQueryivARB = (bglGetQueryivARBProcPtr) NULL;
bglGetQueryObjectivARB = (bglGetQueryObjectivARBProcPtr) NULL;
bglGetQueryObjectuivARB = (bglGetQueryObjectuivARBProcPtr) NULL;
 
// Shader Objects
bglDeleteObjectARB = (bglDeleteObjectARBProcPtr) NULL;
bglGetHandleARB = (bglGetHandleARBProcPtr) NULL;
bglDetachObjectARB = (bglDetachObjectARBProcPtr) NULL;
bglCreateShaderObjectARB = (bglCreateShaderObjectARBProcPtr) NULL;
bglShaderSourceARB = (bglShaderSourceARBProcPtr) NULL;
bglCompileShaderARB = (bglCompileShaderARBProcPtr) NULL;
bglCreateProgramObjectARB = (bglCreateProgramObjectARBProcPtr) NULL;
bglAttachObjectARB = (bglAttachObjectARBProcPtr) NULL;
bglLinkProgramARB = (bglLinkProgramARBProcPtr) NULL;
bglUseProgramObjectARB = (bglUseProgramObjectARBProcPtr) NULL;
bglValidateProgramARB = (bglValidateProgramARBProcPtr) NULL;
bglUniform1fARB = (bglUniform1fARBProcPtr) NULL;
bglUniform2fARB = (bglUniform2fARBProcPtr) NULL;
bglUniform3fARB = (bglUniform3fARBProcPtr) NULL;
bglUniform4fARB = (bglUniform4fARBProcPtr) NULL;
bglUniform1iARB = (bglUniform1iARBProcPtr) NULL;
bglUniform2iARB = (bglUniform2iARBProcPtr) NULL;
bglUniform3iARB = (bglUniform3iARBProcPtr) NULL;
bglUniform4iARB = (bglUniform4iARBProcPtr) NULL;
bglUniform1fvARB = (bglUniform1fvARBProcPtr) NULL;
bglUniform2fvARB = (bglUniform2fvARBProcPtr) NULL;
bglUniform3fvARB = (bglUniform3fvARBProcPtr) NULL;
bglUniform4fvARB = (bglUniform4fvARBProcPtr) NULL;
bglUniform1ivARB = (bglUniform1ivARBProcPtr) NULL;
bglUniform2ivARB = (bglUniform2ivARBProcPtr) NULL;
bglUniform3ivARB = (bglUniform3ivARBProcPtr) NULL;
bglUniform4ivARB = (bglUniform4ivARBProcPtr) NULL;
bglUniformMatrix2fvARB = (bglUniformMatrix2fvARBProcPtr) NULL;
bglUniformMatrix3fvARB = (bglUniformMatrix3fvARBProcPtr) NULL;
bglUniformMatrix4fvARB = (bglUniformMatrix4fvARBProcPtr) NULL;
bglGetObjectParameterfvARB = (bglGetObjectParameterfvARBProcPtr) NULL;
bglGetObjectParameterivARB = (bglGetObjectParameterivARBProcPtr) NULL;
bglGetInfoLogARB = (bglGetInfoLogARBProcPtr) NULL;
bglGetAttachedObjectsARB = (bglGetAttachedObjectsARBProcPtr) NULL;
bglGetUniformLocationARB = (bglGetUniformLocationARBProcPtr) NULL;
bglGetActiveUniformARB = (bglGetActiveUniformARBProcPtr) NULL;
bglGetUniformfvARB = (bglGetUniformfvARBProcPtr) NULL;
bglGetUniformivARB = (bglGetUniformivARBProcPtr) NULL;
bglGetShaderSourceARB = (bglGetShaderSourceARBProcPtr) NULL;
 
// Vertex Shaders
bglVertexAttrib1dARB = (bglVertexAttrib1dARBProcPtr) NULL;
bglVertexAttrib1dvARB = (bglVertexAttrib1dvARBProcPtr) NULL;
bglVertexAttrib1fARB = (bglVertexAttrib1fARBProcPtr) NULL;
bglVertexAttrib1fvARB = (bglVertexAttrib1fvARBProcPtr) NULL;
bglVertexAttrib1sARB = (bglVertexAttrib1sARBProcPtr) NULL;
bglVertexAttrib1svARB = (bglVertexAttrib1svARBProcPtr) NULL;
bglVertexAttrib2dARB = (bglVertexAttrib2dARBProcPtr) NULL;
bglVertexAttrib2dvARB = (bglVertexAttrib2dvARBProcPtr) NULL;
bglVertexAttrib2fARB = (bglVertexAttrib2fARBProcPtr) NULL;
bglVertexAttrib2fvARB = (bglVertexAttrib2fvARBProcPtr) NULL;
bglVertexAttrib2sARB = (bglVertexAttrib2sARBProcPtr) NULL;
bglVertexAttrib2svARB = (bglVertexAttrib2svARBProcPtr) NULL;
bglVertexAttrib3dARB = (bglVertexAttrib3dARBProcPtr) NULL;
bglVertexAttrib3dvARB = (bglVertexAttrib3dvARBProcPtr) NULL;
bglVertexAttrib3fARB = (bglVertexAttrib3fARBProcPtr) NULL;
bglVertexAttrib3fvARB = (bglVertexAttrib3fvARBProcPtr) NULL;
bglVertexAttrib3sARB = (bglVertexAttrib3sARBProcPtr) NULL;
bglVertexAttrib3svARB = (bglVertexAttrib3svARBProcPtr) NULL;
bglVertexAttrib4NbvARB = (bglVertexAttrib4NbvARBProcPtr) NULL;
bglVertexAttrib4NivARB = (bglVertexAttrib4NivARBProcPtr) NULL;
bglVertexAttrib4NsvARB = (bglVertexAttrib4NsvARBProcPtr) NULL;
bglVertexAttrib4NubARB = (bglVertexAttrib4NubARBProcPtr) NULL;
bglVertexAttrib4NubvARB = (bglVertexAttrib4NubvARBProcPtr) NULL;
bglVertexAttrib4NuivARB = (bglVertexAttrib4NuivARBProcPtr) NULL;
bglVertexAttrib4NusvARB = (bglVertexAttrib4NusvARBProcPtr) NULL;
bglVertexAttrib4bvARB = (bglVertexAttrib4bvARBProcPtr) NULL;
bglVertexAttrib4dARB = (bglVertexAttrib4dARBProcPtr) NULL;
bglVertexAttrib4dvARB = (bglVertexAttrib4dvARBProcPtr) NULL;
bglVertexAttrib4fARB = (bglVertexAttrib4fARBProcPtr) NULL;
bglVertexAttrib4fvARB = (bglVertexAttrib4fvARBProcPtr) NULL;
bglVertexAttrib4ivARB = (bglVertexAttrib4ivARBProcPtr) NULL;
bglVertexAttrib4sARB = (bglVertexAttrib4sARBProcPtr) NULL;
bglVertexAttrib4svARB = (bglVertexAttrib4svARBProcPtr) NULL;
bglVertexAttrib4ubvARB = (bglVertexAttrib4ubvARBProcPtr) NULL;
bglVertexAttrib4uivARB = (bglVertexAttrib4uivARBProcPtr) NULL;
bglVertexAttrib4usvARB = (bglVertexAttrib4usvARBProcPtr) NULL;
bglVertexAttribPointerARB = (bglVertexAttribPointerARBProcPtr) NULL;
bglEnableVertexAttribArrayARB = (bglEnableVertexAttribArrayARBProcPtr) NULL;
bglDisableVertexAttribArrayARB = (bglDisableVertexAttribArrayARBProcPtr) NULL;
bglGetVertexAttribdvARB = (bglGetVertexAttribdvARBProcPtr) NULL;
bglGetVertexAttribfvARB = (bglGetVertexAttribfvARBProcPtr) NULL;
bglGetVertexAttribivARB = (bglGetVertexAttribivARBProcPtr) NULL;
bglGetVertexAttribPointervARB = (bglGetVertexAttribPointervARBProcPtr) NULL;
bglBindAttribLocationARB = (bglBindAttribLocationARBProcPtr) NULL;
bglGetActiveAttribARB = (bglGetActiveAttribARBProcPtr) NULL;
bglGetAttribLocationARB = (bglGetAttribLocationARBProcPtr) NULL;
 
#ifdef _WIN32
bwglCreateContext = (bwglCreateContextProcPtr) NULL;
bwglDeleteContext = (bwglDeleteContextProcPtr) NULL;
bwglGetProcAddress = (bwglGetProcAddressProcPtr) NULL;
bwglMakeCurrent = (bwglMakeCurrentProcPtr) NULL;
 
bwglSwapBuffers = (bwglSwapBuffersProcPtr) NULL;
bwglChoosePixelFormat = (bwglChoosePixelFormatProcPtr) NULL;
bwglDescribePixelFormat = (bwglDescribePixelFormatProcPtr) NULL;
bwglGetPixelFormat = (bwglGetPixelFormatProcPtr) NULL;
bwglSetPixelFormat = (bwglSetPixelFormatProcPtr) NULL;
bwglSwapIntervalEXT = (bwglSwapIntervalEXTProcPtr) NULL;
#endif
 
return 0;
}
 
static void *glugetproc_(const char *s, int32_t *err, int32_t fatal)
{
void *t;
#if defined _WIN32
t = (void *)GetProcAddress(hGLUDLL,s);
#else
t = (void *)dlsym(gluhandle,s);
#endif
if (!t && fatal)
{
initprintf("Failed to find %s in %s\n", s, glulibrary);
*err = 1;
}
return t;
}
#define GLUGETPROC(s) glugetproc_(s,&err,1)
#define GLUGETPROCSOFT(s) glugetproc_(s,&err,0)
 
int32_t loadglulibrary(const char *driver)
{
return 0;
}
 
int32_t unloadglulibrary(void)
{
#ifdef _WIN32
if (!hGLUDLL) return 0;
#endif
 
Bfree(glulibrary);
glulibrary = NULL;
 
#ifdef _WIN32
FreeLibrary(hGLUDLL);
hGLUDLL = NULL;
#else
if (gluhandle) dlclose(gluhandle);
gluhandle = NULL;
#endif
 
bgluTessBeginContour = (bgluTessBeginContourProcPtr) NULL;
bgluTessBeginPolygon = (bgluTessBeginPolygonProcPtr) NULL;
bgluTessCallback = (bgluTessCallbackProcPtr) NULL;
bgluTessEndContour = (bgluTessEndContourProcPtr) NULL;
bgluTessEndPolygon = (bgluTessEndPolygonProcPtr) NULL;
bgluTessNormal = (bgluTessNormalProcPtr) NULL;
bgluTessProperty = (bgluTessPropertyProcPtr) NULL;
bgluTessVertex = (bgluTessVertexProcPtr) NULL;
bgluNewTess = (bgluNewTessProcPtr) NULL;
bgluDeleteTess = (bgluDeleteTessProcPtr) NULL;
 
bgluPerspective = (bgluPerspectiveProcPtr) NULL;
 
bgluErrorString = (bgluErrorStringProcPtr) NULL;
 
bgluProject = (bgluProjectProcPtr) NULL;
bgluUnProject = (bgluUnProjectProcPtr) NULL;
 
return 0;
}
 
 
//////// glGenTextures/glDeleteTextures debugging ////////
# if defined DEBUGGINGAIDS && defined DEBUG_TEXTURE_NAMES
static uint8_t *texnameused; // bitmap
static uint32_t *texnamefromwhere; // hash of __FILE__
static uint32_t texnameallocsize;
 
// djb3 algorithm
static inline uint32_t texdbg_getcode(const char *s)
{
uint32_t h = 5381;
int32_t ch;
 
while ((ch = *s++) != '\0')
h = ((h << 5) + h) ^ ch;
 
return h;
}
 
static void texdbg_realloc(uint32_t maxtexname)
{
uint32_t newsize = texnameallocsize ? texnameallocsize : 64;
 
if (maxtexname < texnameallocsize)
return;
 
while (maxtexname >= newsize)
newsize <<= 1;
// initprintf("texdebug: new size %u\n", newsize);
 
texnameused = Brealloc(texnameused, newsize>>3);
texnamefromwhere = Brealloc(texnamefromwhere, newsize*sizeof(uint32_t));
 
Bmemset(texnameused + (texnameallocsize>>3), 0, (newsize-texnameallocsize)>>3);
Bmemset(texnamefromwhere + texnameallocsize, 0, (newsize-texnameallocsize)*sizeof(uint32_t));
 
texnameallocsize = newsize;
}
 
#undef bglGenTextures
void texdbg_bglGenTextures(GLsizei n, GLuint *textures, const char *srcfn)
{
int32_t i;
uint32_t hash = srcfn ? texdbg_getcode(srcfn) : 0;
 
for (i=0; i<n; i++)
if (textures[i] < texnameallocsize && (texnameused[textures[i]>>3]&(1<<(textures[i]&7))))
initprintf("texdebug %x Gen: overwriting used tex name %u from %x\n", hash, textures[i], texnamefromwhere[textures[i]]);
 
bglGenTextures(n, textures);
 
{
GLuint maxtexname = 0;
 
for (i=0; i<n; i++)
maxtexname = max(maxtexname, textures[i]);
 
texdbg_realloc(maxtexname);
 
for (i=0; i<n; i++)
{
texnameused[textures[i]>>3] |= (1<<(textures[i]&7));
texnamefromwhere[textures[i]] = hash;
}
}
}
 
#undef bglDeleteTextures
void texdbg_bglDeleteTextures(GLsizei n, const GLuint *textures, const char *srcfn)
{
int32_t i;
uint32_t hash = srcfn ? texdbg_getcode(srcfn) : 0;
 
for (i=0; i<n; i++)
if (textures[i] < texnameallocsize)
{
if ((texnameused[textures[i]>>3]&(1<<(textures[i]&7)))==0)
initprintf("texdebug %x Del: deleting unused tex name %u\n", hash, textures[i]);
else if ((texnameused[textures[i]>>3]&(1<<(textures[i]&7))) &&
texnamefromwhere[textures[i]] != hash)
initprintf("texdebug %x Del: deleting foreign tex name %u from %x\n", hash,
textures[i], texnamefromwhere[textures[i]]);
}
 
bglDeleteTextures(n, textures);
 
if (texnameallocsize)
for (i=0; i<n; i++)
{
texnameused[textures[i]>>3] &= ~(1<<(textures[i]&7));
texnamefromwhere[textures[i]] = 0;
}
}
# endif // defined DEBUGGINGAIDS
 
 
/polymer/eduke32/build/src/jwzgles.c
0,0 → 1,4152
/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
 
/* A compatibility shim to allow OpenGL 1.3 source code to work in an
OpenGLES environment, where almost every OpenGL 1.3 function has
been "deprecated".
 
There are two major operations going on here:
 
- Converting calls to glBegin + glVertex3f + glEnd to glDrawArrays
- Implementing display lists.
 
So this code shadows all of the functions that are allowed within
glBegin, builds up an array, and calls glDrawArrays at the end.
 
Likewise, it shadows all of the functions that are allowed within
glNewList and records those calls for later playback.
 
 
This code only handles OpenGLES 1.x, not 2.x.
 
 
Some things that are missing:
 
- glTexGeni, meaning no spherical environment-mapping textures.
 
- gluNewTess, meaning no tesselation of complex objects.
 
- glMap2f mesh evaluators, meaning no Utah Teapot.
 
- glPolygonMode with GL_LINE or GL_POINT, meaning no wireframe modes
that do hidden-surface removal.
 
- glSelectBuffer, meaning no mouse-hit detection on rendered objects.
 
- gluNewQuadric, gluCylinder, etc: rewrite your code to use tube.c, etc.
 
- Putting verts in a display list without a wrapping glBegin.
I didn't realize that even worked! Lockward used to do that,
before I fixed it to not.
 
- Not every function is implemented; just the ones that I needed for
xscreensaver. However, the trivial ones are trivial to enable
as they come up. Harder ones will be harder.
*/
 
 
#undef DEBUG
// #define DEBUG 1
 
 
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
 
#ifdef HAVE_JWZGLES /* whole file */
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
 
#if defined(USE_IPHONE)
# include <OpenGLES/ES1/gl.h>
# include <OpenGLES/ES1/glext.h>
#elif defined(HAVE_COCOA)
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
#elif defined(HAVE_ANDROID)
# include <GLES/gl.h>
#else /* real X11 */
# ifndef GL_GLEXT_PROTOTYPES
# define GL_GLEXT_PROTOTYPES /* for glBindBuffer */
# endif
# include <GL/glx.h>
# include <GL/glu.h>
#endif
 
#include "jwzglesI.h"
 
#define STRINGIFY(X) #X
 
#undef countof
#define countof(x) (signed)((signed)sizeof((x))/(signed)sizeof((*x)))
 
#include <android/log.h>
#define LOG_TAG "JWZGLES"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
 
#undef Assert
 
#ifdef HAVE_COCOA
extern void jwxyz_abort (const char *fmt, ...) __dead2;
# define Assert(C,S) do { if (!(C)) { jwxyz_abort ("%s",S); }} while(0)
#else
# define Assert(C,S) do { \
if (!(C)) { \
LOGE ( "ASSERT jwzgles: %s\n", S); \
}} while(0)
#endif
 
 
typedef struct { GLfloat x, y, z; } XYZ;
typedef struct { GLfloat x, y, z, w; } XYZW;
typedef struct { GLfloat s, t, r, q; } STRQ;
typedef struct { GLfloat r, g, b, a; } RGBA;
 
 
/* Used to record all calls to glVertex3f, glNormal3f, etc.
while inside glBegin / glEnd so that we can convert that
to a single call to glDrawArrays.
*/
typedef struct {
int mode;
int count, size; /* size of each array */
 
XYZW *verts; /* Arrays being built */
XYZ *norms;
STRQ *tex;
RGBA *color;
 
int ncount; /* How many normals, tex coords and colors were */
int tcount; /* used. We optimize based on "0, 1, or many". */
int ccount;
int materialistic; /* Whether glMaterial was called inside glBegin */
 
XYZ cnorm; /* Prevailing normal/texture/color while building */
STRQ ctex;
RGBA ccolor;
 
} vert_set;
 
 
typedef void (*list_fn_cb) (void);
 
 
/* We need this nonsense because you can't cast a double to a void*
or vice versa. They tend to be passed in different registers,
and you need to know about that because it's still 1972 here.
*/
typedef union {
const void *v; GLfloat f; GLuint i; GLshort s; GLdouble d;
} void_int;
 
typedef struct { /* saved args for glDrawArrays */
int binding, size, type, stride, bytes;
void *data;
} draw_array;
 
typedef enum { /* shorthand describing arglist signature */
PROTO_VOID, /* no args */
PROTO_I, /* 1 int arg */
PROTO_F, /* 1 float arg */
PROTO_II, /* int, int */
PROTO_FF, /* float, float */
PROTO_IF, /* int, float */
PROTO_III, /* int, int, int */
PROTO_FFF, /* float, float, float */
PROTO_IIF, /* int, int, float */
PROTO_IIII, /* int, int, int, int */
PROTO_FFFF, /* float, float, float, float */
PROTO_IIV, /* int, int[4] */
PROTO_IFV, /* int, float[4] */
PROTO_IIIV, /* int, int, int[4] */
PROTO_IIFV, /* int, int, float[4] */
PROTO_FV16, /* float[16] */
PROTO_ARRAYS /* glDrawArrays */
} fn_proto;
 
typedef struct { /* A single element of a display list */
const char *name;
list_fn_cb fn; /* saved function pointer */
fn_proto proto; /* arglist prototype */
draw_array *arrays; /* args for glDrawArrays */
void_int argv[16]; /* args for everything else */
} list_fn;
 
 
typedef struct { /* a display list: saved activity within glNewList */
int id;
int size, count;
list_fn *fns;
 
/* Named buffer that should be freed when this display list is deleted. */
GLuint buffer;
 
} list;
 
 
typedef struct { /* All display lists */
list *lists;
int count, size;
} list_set;
 
 
#define ISENABLED_TEXTURE_2D (1<<0)
#define ISENABLED_TEXTURE_GEN_S (1<<1)
#define ISENABLED_TEXTURE_GEN_T (1<<2)
#define ISENABLED_TEXTURE_GEN_R (1<<3)
#define ISENABLED_TEXTURE_GEN_Q (1<<4)
#define ISENABLED_LIGHTING (1<<5)
#define ISENABLED_BLEND (1<<6)
#define ISENABLED_DEPTH_TEST (1<<7)
#define ISENABLED_CULL_FACE (1<<8)
#define ISENABLED_NORMALIZE (1<<9)
#define ISENABLED_FOG (1<<10)
#define ISENABLED_COLMAT (1<<11)
#define ISENABLED_VERT_ARRAY (1<<12)
#define ISENABLED_NORM_ARRAY (1<<13)
#define ISENABLED_TEX_ARRAY (1<<14)
#define ISENABLED_COLOR_ARRAY (1<<15)
#define ISENABLED_ALPHA_TEST (1<<16)
 
 
typedef struct {
GLuint mode;
GLfloat obj[4], eye[4];
} texgen_state;
 
 
typedef struct { /* global state */
 
vert_set set; /* set being built */
 
int compiling_list; /* list id if inside glNewList; 0 means immediate */
int replaying_list; /* depth of call stack to glCallList */
int compiling_verts; /* inside glBegin */
 
list_set lists; /* saved lists */
 
unsigned long enabled; /* enabled flags, immediate mode */
unsigned long list_enabled; /* and for the list-in-progress */
 
texgen_state s, t, r, q;
 
} jwzgles_state;
 
 
static jwzgles_state *state = 0;
 
#ifdef DEBUG
# define LOG(A) LOGE("jwzgles: " A "\n")
# define LOG1(A,B) LOGE("jwzgles: " A "\n",B)
# define LOG2(A,B,C) LOGE("jwzgles: " A "\n",B,C)
# define LOG3(A,B,C,D) LOGE("jwzgles: " A "\n",B,C,D)
# define LOG4(A,B,C,D,E) LOGE("jwzgles: " A "\n",B,C,D,E)
# define LOG5(A,B,C,D,E,F) LOGE("jwzgles: " A "\n",B,C,D,E,F)
# define LOG6(A,B,C,D,E,F,G) LOGE("jwzgles: " A "\n",B,C,D,E,F,G)
# define LOG7(A,B,C,D,E,F,G,H) LOGE("jwzgles: " A "\n",B,C,D,E,F,G,H)
# define LOG8(A,B,C,D,E,F,G,H,I)\
LOGE("jwzgles: "A "\n",B,C,D,E,F,G,H,I)
# define LOG9(A,B,C,D,E,F,G,H,I,J)\
LOGE("jwzgles: "A "\n",B,C,D,E,F,G,H,I,J)
# define LOG10(A,B,C,D,E,F,G,H,I,J,K)\
LOGE("jwzgles: "A "\n",B,C,D,E,F,G,H,I,J,K)
# define LOG17(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R)\
LOGE("jwzgles: "A "\n",B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R)
# define CHECK(S) check_gl_error(S)
#else
// "" defeats -Wempty-body
# define LOG(A) ""
# define LOG1(A,B) ""
# define LOG2(A,B,C) ""
# define LOG3(A,B,C,D) ""
# define LOG4(A,B,C,D,E) ""
# define LOG5(A,B,C,D,E,F) ""
# define LOG6(A,B,C,D,E,F,G) ""
# define LOG7(A,B,C,D,E,F,G,H) ""
# define LOG8(A,B,C,D,E,F,G,H,I) ""
# define LOG9(A,B,C,D,E,F,G,H,I,J) ""
# define LOG10(A,B,C,D,E,F,G,H,I,J,K) ""
# define LOG17(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R) ""
# define CHECK(S) ""
#endif
 
#ifdef DEBUG
static const char *
mode_desc (int mode) /* for debugging messages */
{
switch (mode) {
# define SS(X) case GL_##X: return STRINGIFY(X);
SS(ALPHA)
SS(ALPHA_TEST)
SS(AMBIENT)
SS(AMBIENT_AND_DIFFUSE)
SS(ARRAY_BUFFER)
SS(AUTO_NORMAL)
SS(BACK)
SS(BLEND)
SS(BLEND_DST)
SS(BLEND_SRC)
SS(BLEND_SRC_ALPHA)
SS(BYTE)
SS(C3F_V3F)
SS(C4F_N3F_V3F)
SS(C4UB_V2F)
SS(C4UB_V3F)
SS(CCW)
SS(CLAMP)
SS(COLOR_ARRAY)
SS(COLOR_ARRAY_BUFFER_BINDING);
SS(COLOR_MATERIAL)
SS(COLOR_MATERIAL_FACE)
SS(COLOR_MATERIAL_PARAMETER)
SS(COMPILE)
SS(CULL_FACE)
SS(CW)
SS(DECAL)
SS(DEPTH_BUFFER_BIT)
SS(DEPTH_TEST)
SS(DIFFUSE)
SS(DOUBLEBUFFER)
SS(DST_ALPHA)
SS(DST_COLOR)
SS(DYNAMIC_DRAW)
SS(ELEMENT_ARRAY_BUFFER)
SS(EYE_LINEAR)
SS(EYE_PLANE)
SS(FEEDBACK)
SS(FILL)
SS(FLAT)
SS(FLOAT)
SS(FOG)
SS(FRONT)
SS(FRONT_AND_BACK)
SS(GREATER)
SS(INTENSITY)
SS(INVALID_ENUM)
SS(INVALID_OPERATION)
SS(INVALID_VALUE)
SS(LESS)
SS(LIGHT0)
SS(LIGHT1)
SS(LIGHT2)
SS(LIGHT3)
SS(LIGHTING)
SS(LIGHT_MODEL_AMBIENT)
SS(LIGHT_MODEL_COLOR_CONTROL)
SS(LIGHT_MODEL_LOCAL_VIEWER)
SS(LIGHT_MODEL_TWO_SIDE)
SS(LINE)
SS(LINEAR)
SS(LINEAR_MIPMAP_LINEAR)
SS(LINEAR_MIPMAP_NEAREST)
SS(LINES)
SS(LINE_LOOP)
SS(LINE_STRIP)
SS(LUMINANCE)
SS(LUMINANCE_ALPHA)
SS(MATRIX_MODE)
SS(MODELVIEW)
SS(MODULATE)
SS(N3F_V3F)
SS(NEAREST)
SS(NEAREST_MIPMAP_LINEAR)
SS(NEAREST_MIPMAP_NEAREST)
SS(NORMALIZE)
SS(NORMAL_ARRAY)
SS(NORMAL_ARRAY_BUFFER_BINDING);
SS(OBJECT_LINEAR)
SS(OBJECT_PLANE)
SS(ONE_MINUS_DST_ALPHA)
SS(ONE_MINUS_DST_COLOR)
SS(ONE_MINUS_SRC_ALPHA)
SS(ONE_MINUS_SRC_COLOR)
SS(OUT_OF_MEMORY)
SS(PACK_ALIGNMENT)
SS(POINTS)
SS(POLYGON)
SS(POLYGON_OFFSET_FILL)
SS(POLYGON_SMOOTH)
SS(POLYGON_STIPPLE)
SS(POSITION)
SS(PROJECTION)
SS(Q)
SS(QUADS)
SS(QUAD_STRIP)
SS(R)
SS(RENDER)
SS(REPEAT)
SS(RGB)
SS(RGBA)
SS(RGBA_MODE)
SS(S)
SS(SELECT)
SS(SEPARATE_SPECULAR_COLOR)
SS(SHADE_MODEL)
SS(SHININESS)
SS(SHORT)
SS(SINGLE_COLOR)
SS(SMOOTH)
SS(SPECULAR)
SS(SPHERE_MAP)
SS(SRC_ALPHA)
SS(SRC_ALPHA_SATURATE)
SS(SRC_COLOR)
SS(STACK_OVERFLOW)
SS(STACK_UNDERFLOW)
SS(STATIC_DRAW)
SS(STENCIL_BUFFER_BIT)
SS(T)
SS(T2F_C3F_V3F)
SS(T2F_C4F_N3F_V3F)
SS(T2F_C4UB_V3F)
SS(T2F_N3F_V3F)
SS(T2F_V3F)
SS(T4F_C4F_N3F_V4F)
SS(T4F_V4F)
SS(TEXTURE)
SS(TEXTURE_1D)
SS(TEXTURE_2D)
SS(TEXTURE_ALPHA_SIZE)
SS(TEXTURE_BINDING_2D)
SS(TEXTURE_BLUE_SIZE)
SS(TEXTURE_BORDER)
SS(TEXTURE_BORDER_COLOR)
SS(TEXTURE_COMPONENTS)
SS(TEXTURE_COORD_ARRAY)
SS(TEXTURE_COORD_ARRAY_BUFFER_BINDING);
SS(TEXTURE_ENV)
SS(TEXTURE_ENV_COLOR)
SS(TEXTURE_ENV_MODE)
SS(TEXTURE_GEN_MODE)
SS(TEXTURE_GEN_Q)
SS(TEXTURE_GEN_R)
SS(TEXTURE_GEN_S)
SS(TEXTURE_GEN_T)
SS(TEXTURE_GREEN_SIZE)
SS(TEXTURE_HEIGHT)
SS(TEXTURE_INTENSITY_SIZE)
SS(TEXTURE_LUMINANCE_SIZE)
SS(TEXTURE_MAG_FILTER)
SS(TEXTURE_MIN_FILTER)
SS(TEXTURE_RED_SIZE)
SS(TEXTURE_WRAP_S)
SS(TEXTURE_WRAP_T)
SS(TRIANGLES)
SS(TRIANGLE_FAN)
SS(TRIANGLE_STRIP)
SS(UNPACK_ALIGNMENT)
SS(UNPACK_ROW_LENGTH)
SS(UNSIGNED_BYTE)
SS(UNSIGNED_INT_8_8_8_8_REV)
SS(UNSIGNED_SHORT)
SS(V2F)
SS(V3F)
SS(VERTEX_ARRAY)
SS(VERTEX_ARRAY_BUFFER_BINDING);
/*SS(COLOR_BUFFER_BIT) -- same value as GL_LIGHT0 */
# undef SS
case (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT):
return "DEPTH_BUFFER_BIT | COLOR_BUFFER_BIT";
/* Oops, same as INVALID_ENUM.
case (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT):
return "DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT";
*/
case (GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT):
return "COLOR_BUFFER_BIT | STENCIL_BUFFER_BIT";
case (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT):
return "DEPTH_BUFFER_BIT | COLOR_BUFFER_BIT | STENCIL_BUFFER_BIT";
default:
{
static char buf[255];
sprintf (buf, "0x%04X", mode);
return buf;
}
}
}
 
static void
check_gl_error (const char *s)
{
GLenum i = glGetError();
if (i == GL_NO_ERROR) return;
fprintf (stderr, "jwzgles: GL ERROR: %s: %s\n", s, mode_desc(i));
}
 
#endif /* DEBUG */
 
 
static void
make_room (const char *name, void **array, int span, int *count, int *size)
{
if (*count + 1 >= *size)
{
int new_size = (*count + 20) * 1.2; /* mildly exponential */
*array = realloc (*array, new_size * span);
Assert (*array, "out of memory");
/* LOG3("%s: grew %d -> %d", name, *size, new_size); */
*size = new_size;
}
}
 
 
void
jwzgles_reset (void)
{
if (! state)
state = (jwzgles_state *) calloc (1, sizeof (*state));
 
if (state->lists.lists)
{
state->compiling_list = 0;
if (state->lists.count)
jwzgles_glDeleteLists (1, state->lists.count);
free (state->lists.lists);
}
 
if (state->set.verts) free (state->set.verts);
if (state->set.norms) free (state->set.norms);
if (state->set.tex) free (state->set.tex);
if (state->set.color) free (state->set.color);
 
memset (state, 0, sizeof(*state));
 
state->s.mode = state->t.mode = state->r.mode = state->q.mode =
GL_EYE_LINEAR;
state->s.obj[0] = state->s.eye[0] = 1; /* s = 1 0 0 0 */
state->t.obj[1] = state->t.eye[1] = 1; /* t = 0 1 0 0 */
}
 
 
int
jwzgles_glGenLists (int n)
{
int i;
int ret = 0;
 
Assert (!state->compiling_verts, "glGenLists not allowed inside glBegin");
 
/* Ensure space in state->lists, clear the one at the end, and tick counter
Note that lists are never really deleted, and we can never re-use elements
of this array. glDeleteLists zeroes out the contents of the list, but
the list ID is still valid for use with glNewList forever.
#### So maybe this should be a linked list instead of an array.
*/
for (i = 0; i < n; i++)
{
list *L;
int id = 0;
make_room ("glGenLists",
(void **) &state->lists.lists,
sizeof (*state->lists.lists),
&state->lists.count, &state->lists.size);
state->lists.count++;
id = state->lists.count;
L = &state->lists.lists[id-1];
 
memset (L, 0, sizeof (*L));
L->id = id;
if (ret == 0) ret = id;
LOG1("glGenLists -> %d", L->id);
}
 
/* Return the ID of the first list allocated */
 
return ret;
}
 
 
void
jwzgles_glNewList (int id, int mode)
{
list *L;
Assert (id > 0 && id <= state->lists.count, "glNewList: bogus ID");
Assert (mode == GL_COMPILE, "glNewList: bad mode");
Assert (!state->compiling_verts, "glNewList not allowed inside glBegin");
Assert (!state->compiling_list, "nested glNewList");
Assert (state->set.count == 0, "missing glEnd");
 
L = &state->lists.lists[id-1];
Assert (L->id == id, "glNewList corrupted");
 
if (L->count != 0) jwzgles_glDeleteLists (L->id, 1); /* Overwriting */
Assert (L->count == 0, "glNewList corrupted");
state->compiling_list = id;
 
state->list_enabled = state->enabled;
 
LOG1("glNewList -> %d", id);
}
 
 
static void save_arrays (list_fn *, int);
static void restore_arrays (list_fn *, int);
static void copy_array_data (draw_array *, int, const char *);
static void optimize_arrays (void);
static void generate_texture_coords (GLuint, GLuint);
 
 
void
jwzgles_glEndList (void)
{
Assert (state->compiling_list, "extra glEndList");
Assert (state->set.count == 0, "missing glEnd");
Assert (!state->compiling_verts, "glEndList not allowed inside glBegin");
LOG1("glEndList %d", state->compiling_list);
optimize_arrays();
state->compiling_list = 0;
state->list_enabled = state->enabled;
}
 
 
static void
list_push (const char * const name,
list_fn_cb fn, fn_proto proto, void_int *av)
{
list *L;
list_fn *F;
int i;
 
Assert (state->compiling_list > 0, "not inside glNewList");
Assert (state->compiling_list <= state->lists.count, "glNewList corrupted");
 
L = &state->lists.lists[state->compiling_list-1];
Assert (L, "glNewList: no list");
 
make_room ("glNewLists",
(void **) &L->fns, sizeof (*L->fns),
&L->count, &L->size);
memset (&L->fns[L->count], 0, sizeof (*L->fns));
F = L->fns + L->count;
 
F->name = name;
F->fn = fn;
F->proto = proto;
if (proto != PROTO_VOID)
for (i = 0; i < countof(F->argv); i++)
F->argv[i] = av[i];
 
# ifdef DEBUG
switch (proto) {
case PROTO_VOID:
LOG1 (" push %-12s", name);
break;
case PROTO_I:
if (fn == (list_fn_cb) &jwzgles_glBegin ||
fn == (list_fn_cb) &jwzgles_glFrontFace ||
fn == (list_fn_cb) &jwzgles_glEnable ||
fn == (list_fn_cb) &jwzgles_glDisable ||
fn == (list_fn_cb) &jwzgles_glEnableClientState ||
fn == (list_fn_cb) &jwzgles_glDisableClientState ||
fn == (list_fn_cb) &jwzgles_glShadeModel ||
fn == (list_fn_cb) &jwzgles_glMatrixMode)
LOG2 (" push %-12s %s", name, mode_desc (av[0].i));
else
LOG2 (" push %-12s %d", name, av[0].i);
break;
case PROTO_F:
LOG2 (" push %-12s %7.3f", name, av[0].f);
break;
case PROTO_II:
if (fn == (list_fn_cb) &jwzgles_glBindTexture ||
fn == (list_fn_cb) &jwzgles_glBindBuffer)
LOG3 (" push %-12s %s %d", name, mode_desc (av[0].i), av[1].i);
else
LOG3 (" push %-12s %d %d", name, av[0].i, av[1].i);
break;
case PROTO_FF:
LOG3 (" push %-12s %7.3f %7.3f", name, av[0].f, av[1].f);
break;
case PROTO_IF:
LOG3 (" push %-12s %s %7.3f", name, mode_desc (av[0].i), av[1].f);
break;
case PROTO_III:
case PROTO_ARRAYS:
if (fn == (list_fn_cb) &jwzgles_glDrawArrays ||
fn == (list_fn_cb) &jwzgles_glTexParameteri)
LOG4 (" push %-12s %s %d %d", name, mode_desc (av[0].i),
av[1].i, av[2].i);
else
LOG4 (" push %-12s %d %d %d", name, av[0].i, av[1].i, av[2].i);
break;
case PROTO_FFF:
LOG4 (" push %-12s %7.3f %7.3f %7.3f", name, av[0].f, av[1].f, av[2].f);
break;
case PROTO_IIF:
LOG4 (" push %-12s %s %s %7.3f", name,
mode_desc(av[0].i), mode_desc(av[1].i), av[2].f);
break;
case PROTO_IIII:
LOG5 (" push %-12s %d %d %d %d", name,
av[0].i, av[1].i, av[2].i, av[3].i);
break;
case PROTO_FFFF:
LOG5 (" push %-12s %7.3f %7.3f %7.3f %7.3f", name,
av[0].f, av[1].f, av[2].f, av[3].f);
break;
case PROTO_IFV:
LOG6 (" push %-12s %s %3.1f %3.1f %3.1f %3.1f", name, mode_desc (av[0].i),
av[1].f, av[2].f, av[3].f, av[4].f);
break;
case PROTO_IIV:
LOG6 (" push %-12s %s %d %d %d %d", name, mode_desc (av[0].i),
av[1].i, av[2].i, av[3].i, av[4].i);
break;
case PROTO_IIFV:
LOG7 (" push %-12s %s %-8s %3.1f %3.1f %3.1f %3.1f", name,
mode_desc (av[0].i), mode_desc (av[1].i),
av[2].f, av[3].f, av[4].f, av[5].f);
break;
case PROTO_IIIV:
LOG7 (" push %-12s %s %-8s %3d %3d %3d %3d", name,
mode_desc (av[0].i), mode_desc (av[1].i),
av[2].i, av[3].i, av[4].i, av[5].i);
break;
case PROTO_FV16:
LOG17 (" push %-12s ["
"%8.3f %8.3f %8.3f %8.3f " "\n\t\t\t "
"%8.3f %8.3f %8.3f %8.3f " "\n\t\t\t "
"%8.3f %8.3f %8.3f %8.3f " "\n\t\t\t "
"%8.3f %8.3f %8.3f %8.3f ]",
name,
av[0].f, av[1].f, av[2].f, av[3].f,
av[4].f, av[5].f, av[6].f, av[7].f,
av[8].f, av[9].f, av[10].f, av[11].f,
av[12].f, av[13].f, av[14].f, av[15].f);
break;
default:
Assert (0, "bogus prototype");
break;
}
# endif /* DEBUG */
 
if (proto == PROTO_ARRAYS) /* glDrawArrays */
save_arrays (F, av[1].i + av[2].i);
 
L->count++;
}
 
 
void
jwzgles_glBegin (int mode)
{
Assert (!state->compiling_verts, "nested glBegin");
state->compiling_verts++;
 
/* Only these commands are allowed inside glBegin:
 
glVertex -- not allowed outside
glColor
glSecondaryColor
glIndex
glNormal
glFogCoord
glTexCoord
glMultiTexCoord
glVertexAttrib
glEvalCoord
glEvalPoint
glArrayElement -- not allowed outside
glMaterial
glEdgeFlag
glCallList
glCallLists
*/
 
if (!state->replaying_list)
LOG2 ("%sglBegin %s",
(state->compiling_list || state->replaying_list ? " " : ""),
mode_desc (mode));
 
Assert (state->set.count == 0, "glBegin corrupted");
state->set.mode = mode;
state->set.count = 0;
state->set.ncount = 0;
state->set.tcount = 0;
state->set.ccount = 0;
}
 
 
void
jwzgles_glDeleteLists (int id0, int range)
{
Assert (!state->compiling_verts, "glDeleteLists not allowed inside glBegin");
 
if (state->compiling_list)
{
void_int vv[2];
vv[0].i = id0;
vv[1].i = range;
list_push ("glDeleteLists", (list_fn_cb) &jwzgles_glDeleteLists,
PROTO_II, vv);
}
else
{
int id;
 
if (!state->replaying_list)
LOG2 ("glDeleteLists %d %d", id0, range);
 
for (id = id0 + range - 1; id >= id0; id--)
{
int i;
list *L;
if (id == 0) continue; /* People do this stupid thing */
if (id > state->lists.count) break; /* this too */
Assert (id > 0 && id <= state->lists.count,
"glDeleteLists: bogus ID");
L = &state->lists.lists[id-1];
Assert (L->id == id, "glDeleteLists corrupted");
 
for (i = 0; i < L->count; i++)
{
list_fn *lf = &L->fns[i];
if (lf->arrays)
{
int j;
for (j = 0; j < 4; j++)
/* If there's a binding, 'data' is an index, not a ptr. */
if (!lf->arrays[j].binding &&
lf->arrays[j].data)
free (lf->arrays[j].data);
free (lf->arrays);
}
}
if (L->fns)
free (L->fns);
if (L->buffer)
glDeleteBuffers (1, &L->buffer);
 
memset (L, 0, sizeof (*L));
L->id = id;
}
}
}
 
 
extern GLboolean
jwzgles_glIsList (GLuint id)
{
return (id > 0 && id < (unsigned)state->lists.count);
}
 
 
 
void
jwzgles_glNormal3fv (const GLfloat *v)
{
if (state->compiling_list && !state->compiling_verts)
{
void_int vv[3];
vv[0].f = v[0];
vv[1].f = v[1];
vv[2].f = v[2];
list_push ("glNormal3f", (list_fn_cb) &jwzgles_glNormal3f,
PROTO_FFF, vv);
}
else
{
if (!state->replaying_list)
LOG5 ("%s%sglNormal3f %7.3f %7.3f %7.3f",
(state->compiling_list || state->replaying_list ? " " : ""),
(state->compiling_verts ? " rec " : ""),
v[0], v[1], v[2]);
 
if (state->compiling_verts) /* inside glBegin */
{
state->set.cnorm.x = v[0];
state->set.cnorm.y = v[1];
state->set.cnorm.z = v[2];
state->set.ncount++;
if (state->set.count > 0 && state->set.ncount == 1) /* not first! */
state->set.ncount++;
}
else /* outside glBegin */
{
glNormal3f (v[0], v[1], v[2]);
CHECK("glNormal3f");
}
}
}
 
 
void
jwzgles_glNormal3f (GLfloat x, GLfloat y, GLfloat z)
{
GLfloat v[3];
v[0] = x;
v[1] = y;
v[2] = z;
jwzgles_glNormal3fv (v);
}
 
 
void
jwzgles_glTexCoord4fv (const GLfloat *v)
{
if (state->compiling_list && !state->compiling_verts)
{
void_int vv[4];
vv[0].f = v[0];
vv[1].f = v[1];
vv[2].f = v[2];
vv[3].f = v[3];
list_push ("glTexCoord4f", (list_fn_cb) &jwzgles_glTexCoord4f,
PROTO_FFFF, vv);
}
else
{
if (!state->replaying_list)
LOG6 ("%s%sglTexCoord4f %7.3f %7.3f %7.3f %7.3f",
(state->compiling_list || state->replaying_list ? " " : ""),
(state->compiling_verts ? " rec " : ""),
v[0], v[1], v[2], v[3]);
 
Assert (state->compiling_verts, "glTexCoord4fv outside glBegin");
 
if (state->compiling_verts) /* inside glBegin */
{
state->set.ctex.s = v[0];
state->set.ctex.t = v[1];
state->set.ctex.r = v[2];
state->set.ctex.q = v[3];
state->set.tcount++;
if (state->set.count > 0 && state->set.tcount == 1) /* not first! */
state->set.tcount++;
}
}
}
 
 
void
jwzgles_glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q)
{
GLfloat v[4];
v[0] = s;
v[1] = t;
v[2] = r;
v[3] = q;
jwzgles_glTexCoord4fv (v);
}
 
 
void
jwzgles_glTexCoord3fv (const GLfloat *v)
{
GLfloat vv[4];
vv[0] = v[0];
vv[1] = v[1];
vv[2] = v[2];
vv[3] = 1;
jwzgles_glTexCoord4fv (vv);
}
 
 
void
jwzgles_glTexCoord2fv (const GLfloat *v)
{
GLfloat vv[4];
vv[0] = v[0];
vv[1] = v[1];
vv[2] = 0;
vv[3] = 1;
jwzgles_glTexCoord4fv (vv);
}
 
 
void
jwzgles_glTexCoord3f (GLfloat s, GLfloat t, GLfloat r)
{
jwzgles_glTexCoord4f (s, t, r, 1);
}
 
 
void
jwzgles_glTexCoord2f (GLfloat s, GLfloat t)
{
jwzgles_glTexCoord4f (s, t, 0, 1);
}
 
void
jwzgles_glTexCoord2i (GLint s, GLint t)
{
jwzgles_glTexCoord4f (s, t, 0, 1);
}
 
void
jwzgles_glTexCoord1f (GLfloat s)
{
jwzgles_glTexCoord4f (s, 0, 0, 1);
}
 
 
/* glColor: GLfloat */
 
void
jwzgles_glColor4fv (const GLfloat *v)
{
if (state->compiling_list && !state->compiling_verts)
{
void_int vv[4];
vv[0].f = v[0];
vv[1].f = v[1];
vv[2].f = v[2];
vv[3].f = v[3];
list_push ("glColor4f", (list_fn_cb) &jwzgles_glColor4f,
PROTO_FFFF, vv);
}
else
{
if (!state->replaying_list)
LOG6 ("%s%sglColor4f %7.3f %7.3f %7.3f %7.3f",
(state->compiling_list || state->replaying_list ? " " : ""),
(state->compiling_verts ? " rec " : ""),
v[0], v[1], v[2], v[3]);
 
if (state->compiling_verts) /* inside glBegin */
{
state->set.ccolor.r = v[0];
state->set.ccolor.g = v[1];
state->set.ccolor.b = v[2];
state->set.ccolor.a = v[3];
state->set.ccount++;
if (state->set.count > 0 && state->set.ccount == 1) /* not first! */
state->set.ccount++;
}
else /* outside glBegin */
{
glColor4f (v[0], v[1], v[2], v[3]);
CHECK("glColor4");
}
}
}
 
 
void
jwzgles_glColor4f (GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
GLfloat v[4];
v[0] = r;
v[1] = g;
v[2] = b;
v[3] = a;
jwzgles_glColor4fv (v);
}
 
void
jwzgles_glColor3f (GLfloat r, GLfloat g, GLfloat b)
{
jwzgles_glColor4f (r, g, b, 1);
}
 
void
jwzgles_glColor3fv (const GLfloat *v)
{
jwzgles_glColor3f (v[0], v[1], v[2]);
}
 
 
/* glColor: GLdouble */
 
void
jwzgles_glColor4d (GLdouble r, GLdouble g, GLdouble b, GLdouble a)
{
jwzgles_glColor4f (r, g, b, a);
}
 
void
jwzgles_glColor4dv (const GLdouble *v)
{
jwzgles_glColor4d (v[0], v[1], v[2], v[3]);
}
 
void
jwzgles_glColor3d (GLdouble r, GLdouble g, GLdouble b)
{
jwzgles_glColor4d (r, g, b, 1.0);
}
 
void
jwzgles_glColor3dv (const GLdouble *v)
{
jwzgles_glColor3d (v[0], v[1], v[2]);
}
 
 
/* glColor: GLint (INT_MIN - INT_MAX) */
 
void
jwzgles_glColor4i (GLint r, GLint g, GLint b, GLint a)
{
/* -0x8000000 - 0x7FFFFFFF => 0.0 - 1.0 */
jwzgles_glColor4f (0.5 + (GLfloat) r / 0xFFFFFFFF,
0.5 + (GLfloat) g / 0xFFFFFFFF,
0.5 + (GLfloat) b / 0xFFFFFFFF,
0.5 + (GLfloat) a / 0xFFFFFFFF);
}
 
void
jwzgles_glColor4iv (const GLint *v)
{
jwzgles_glColor4i (v[0], v[1], v[2], v[3]);
}
 
 
void
jwzgles_glColor3i (GLint r, GLint g, GLint b)
{
jwzgles_glColor4i (r, g, b, 0x7FFFFFFF);
}
 
void
jwzgles_glColor3iv (const GLint *v)
{
jwzgles_glColor3i (v[0], v[1], v[2]);
}
 
 
/* glColor: GLuint (0 - UINT_MAX) */
 
void
jwzgles_glColor4ui (GLuint r, GLuint g, GLuint b, GLuint a)
{
/* 0 - 0xFFFFFFFF => 0.0 - 1.0 */
jwzgles_glColor4f ((GLfloat) r / 0xFFFFFFFF,
(GLfloat) g / 0xFFFFFFFF,
(GLfloat) b / 0xFFFFFFFF,
(GLfloat) a / 0xFFFFFFFF);
}
 
void
jwzgles_glColor4uiv (const GLuint *v)
{
jwzgles_glColor4ui (v[0], v[1], v[2], v[3]);
}
 
void
jwzgles_glColor3ui (GLuint r, GLuint g, GLuint b)
{
jwzgles_glColor4ui (r, g, b, 0xFFFFFFFF);
}
 
void
jwzgles_glColor3uiv (const GLuint *v)
{
jwzgles_glColor3ui (v[0], v[1], v[2]);
}
 
 
/* glColor: GLshort (SHRT_MIN - SHRT_MAX) */
 
void
jwzgles_glColor4s (GLshort r, GLshort g, GLshort b, GLshort a)
{
/* -0x8000 - 0x7FFF => 0.0 - 1.0 */
jwzgles_glColor4f (0.5 + (GLfloat) r / 0xFFFF,
0.5 + (GLfloat) g / 0xFFFF,
0.5 + (GLfloat) b / 0xFFFF,
0.5 + (GLfloat) a / 0xFFFF);
}
 
void
jwzgles_glColor4sv (const GLshort *v)
{
jwzgles_glColor4s (v[0], v[1], v[2], v[3]);
}
 
void
jwzgles_glColor3s (GLshort r, GLshort g, GLshort b)
{
jwzgles_glColor4s (r, g, b, 0x7FFF);
}
 
void
jwzgles_glColor3sv (const GLshort *v)
{
jwzgles_glColor3s (v[0], v[1], v[2]);
}
 
 
/* glColor: GLushort (0 - USHRT_MAX) */
 
void
jwzgles_glColor4us (GLushort r, GLushort g, GLushort b, GLushort a)
{
/* 0 - 0xFFFF => 0.0 - 1.0 */
jwzgles_glColor4f ((GLfloat) r / 0xFFFF,
(GLfloat) g / 0xFFFF,
(GLfloat) b / 0xFFFF,
(GLfloat) a / 0xFFFF);
}
 
void
jwzgles_glColor4usv (const GLushort *v)
{
jwzgles_glColor4us (v[0], v[1], v[2], v[3]);
}
 
void
jwzgles_glColor3us (GLushort r, GLushort g, GLushort b)
{
jwzgles_glColor4us (r, g, b, 0xFFFF);
}
 
void
jwzgles_glColor3usv (const GLushort *v)
{
jwzgles_glColor3us (v[0], v[1], v[2]);
}
 
 
/* glColor: GLbyte (-128 - 127) */
 
void
jwzgles_glColor4b (GLbyte r, GLbyte g, GLbyte b, GLbyte a)
{
/* -128 - 127 => 0.0 - 1.0 */
jwzgles_glColor4f (0.5 + (GLfloat) r / 255,
0.5 + (GLfloat) g / 255,
0.5 + (GLfloat) b / 255,
0.5 + (GLfloat) a / 255);
}
 
void
jwzgles_glColor4bv (const GLbyte *v)
{
jwzgles_glColor4b (v[0], v[1], v[2], v[3]);
}
 
void
jwzgles_glColor3b (GLbyte r, GLbyte g, GLbyte b)
{
jwzgles_glColor4b (r, g, b, 127);
}
 
void
jwzgles_glColor3bv (const GLbyte *v)
{
jwzgles_glColor3b (v[0], v[1], v[2]);
}
 
 
/* glColor: GLubyte (0 - 255) */
 
void
jwzgles_glColor4ub (GLubyte r, GLubyte g, GLubyte b, GLubyte a)
{
/* 0 - 255 => 0.0 - 1.0 */
jwzgles_glColor4f (r / 255.0, g / 255.0, b / 255.0, a / 255.0);
}
 
void
jwzgles_glColor4ubv (const GLubyte *v)
{
jwzgles_glColor4ub (v[0], v[1], v[2], v[3]);
}
 
void
jwzgles_glColor3ub (GLubyte r, GLubyte g, GLubyte b)
{
jwzgles_glColor4ub (r, g, b, 255);
}
 
void
jwzgles_glColor3ubv (const GLubyte *v)
{
jwzgles_glColor3ub (v[0], v[1], v[2]);
}
 
 
 
void
jwzgles_glMaterialfv (GLenum face, GLenum pname, const GLfloat *color)
{
/* If this is called inside glBegin/glEnd with a front ambient color,
then treat it the same as glColor: set the color of the upcoming
vertex.
 
Other faces or lighting types within glBegin are ignored.
*/
 
if (state->compiling_verts)
{
if ((face == GL_FRONT ||
face == GL_FRONT_AND_BACK) &&
(pname == GL_AMBIENT ||
pname == GL_DIFFUSE ||
pname == GL_AMBIENT_AND_DIFFUSE))
{
jwzgles_glColor4f (color[0], color[1], color[2], color[3]);
state->set.materialistic++;
}
else
LOG2 (" IGNORING glMaterialfv %s %s",
mode_desc(face), mode_desc(pname));
}
else if (state->compiling_list)
{
void_int vv[6];
vv[0].i = face;
vv[1].i = pname;
vv[2].f = color[0];
vv[3].f = color[1];
vv[4].f = color[2];
vv[5].f = color[3];
list_push ("glMaterialfv", (list_fn_cb) &jwzgles_glMaterialfv,
PROTO_IIFV, vv);
}
else
{
/* If this is called outside of glBegin/glEnd with a front
ambient color, then the intent is presumably for that color
to apply to the upcoming vertexes (which may be played back
from a list that does not have vertex colors in it). In that
case, the only way to make the colors show up is to call
glColor() with GL_COLOR_MATERIAL enabled.
 
I'm not sure if this will have other inappropriate side effects...
*/
if ((face == GL_FRONT ||
face == GL_FRONT_AND_BACK) &&
(pname == GL_AMBIENT ||
pname == GL_DIFFUSE ||
pname == GL_AMBIENT_AND_DIFFUSE))
{
jwzgles_glEnable (GL_COLOR_MATERIAL);
jwzgles_glColor4f (color[0], color[1], color[2], color[3]);
}
 
/* OpenGLES seems to throw "invalid enum" for GL_FRONT -- but it
goes ahead and sets the material anyway! No error if we just
always use GL_FRONT_AND_BACK.
*/
if (face == GL_FRONT)
face = GL_FRONT_AND_BACK;
if (! state->replaying_list)
LOG7 ("direct %-12s %s %s %7.3f %7.3f %7.3f %7.3f", "glMaterialfv",
mode_desc(face), mode_desc(pname),
color[0], color[1], color[2], color[3]);
glMaterialfv (face, pname, color); /* the real one */
CHECK("glMaterialfv");
}
}
 
 
void
jwzgles_glMaterialiv (GLenum face, GLenum pname, const GLint *v)
{
GLfloat vv[4];
vv[0] = v[0];
vv[1] = v[1];
vv[2] = v[2];
vv[3] = 1;
jwzgles_glMaterialfv (face, pname, vv);
}
 
void
jwzgles_glMaterialf (GLenum face, GLenum pname, const GLfloat c)
{
GLfloat vv[4];
vv[0] = c;
vv[1] = c;
vv[2] = c;
vv[3] = 1;
jwzgles_glMaterialfv (face, pname, vv);
}
 
 
void
jwzgles_glMateriali (GLenum face, GLenum pname, const GLuint c)
{
jwzgles_glMaterialf (face, pname, c);
}
 
 
void
jwzgles_glColorMaterial (GLenum face, GLenum mode)
{
Assert (!state->compiling_verts,
"glColorMaterial not allowed inside glBegin");
#if 0
if (state->compiling_list)
{
void_int vv[2];
vv[0].i = face;
vv[1].i = mode;
list_push ("glColorMaterial", (list_fn_cb) &jwzgles_glColorMaterial,
PROTO_II, vv);
}
else
{
/* No real analog to this distinction in OpenGLES, since color
arrays don't distinguish between "color" and "material", */
Assert (0, "glColorMaterial: unimplemented mode");
}
#endif
}
 
 
 
 
void
jwzgles_glVertex4fv (const GLfloat *v)
{
vert_set *s = &state->set;
int count = s->count;
 
Assert (state->compiling_verts, "glVertex4fv not inside glBegin");
 
LOG5("%s rec glVertex4f %7.3f %7.3f %7.3f %7.3f",
(state->compiling_list || state->replaying_list ? " " : ""),
v[0], v[1], v[2], v[3]);
 
if (count >= s->size - 1)
{
int new_size = 20 + (s->size * 1.2);
 
/* 4 arrays, different element sizes...
We allocate all 4 arrays just in case we need them,
but we might not end up using them all at the end.
*/
 
s->verts = (XYZW *) realloc (s->verts, new_size * sizeof (*s->verts));
Assert (s->verts, "out of memory");
 
s->norms = (XYZ *) realloc (s->norms, new_size * sizeof (*s->norms));
Assert (s->norms, "out of memory");
 
s->tex = (STRQ *) realloc (s->tex, new_size * sizeof (*s->tex));
Assert (s->tex, "out of memory");
 
s->color = (RGBA *) realloc (s->color, new_size * sizeof (*s->color));
Assert (s->color, "out of memory");
 
s->size = new_size;
}
 
s->verts [count].x = v[0];
s->verts [count].y = v[1];
s->verts [count].z = v[2];
s->verts [count].w = v[3];
s->norms [count] = s->cnorm;
s->tex [count] = s->ctex;
s->color [count] = s->ccolor;
s->count++;
}
 
 
void
jwzgles_glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
GLfloat v[4];
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = w;
jwzgles_glVertex4fv (v);
}
 
void
jwzgles_glVertex4i (GLint x, GLint y, GLint z, GLint w)
{
jwzgles_glVertex4f (x, y, z, w);
}
 
void
jwzgles_glVertex3f (GLfloat x, GLfloat y, GLfloat z)
{
GLfloat v[4];
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = 1;
jwzgles_glVertex4fv (v);
}
 
void
jwzgles_glVertex3i (GLint x, GLint y, GLint z)
{
jwzgles_glVertex3f (x, y, z);
}
 
void
jwzgles_glVertex3fv (const GLfloat *v)
{
jwzgles_glVertex3f (v[0], v[1], v[2]);
}
 
void
jwzgles_glVertex3dv (const GLdouble *v)
{
jwzgles_glVertex3f (v[0], v[1], v[2]);
}
 
 
void
jwzgles_glVertex2f (GLfloat x, GLfloat y)
{
GLfloat v[3];
v[0] = x;
v[1] = y;
v[2] = 0;
jwzgles_glVertex3fv (v);
}
 
void
jwzgles_glVertex2fv (const GLfloat *v)
{
jwzgles_glVertex2f (v[0], v[1]);
}
 
void
jwzgles_glVertex2i (GLint x, GLint y)
{
jwzgles_glVertex2f (x, y);
}
 
 
void
jwzgles_glLightiv (GLenum light, GLenum pname, const GLint *params)
{
GLfloat v[4];
v[0] = params[0];
v[1] = params[1];
v[2] = params[2];
v[3] = params[3];
jwzgles_glLightfv (light, pname, v);
}
 
void
jwzgles_glLightModeliv (GLenum pname, const GLint *params)
{
GLfloat v[4];
v[0] = params[0];
v[1] = params[1];
v[2] = params[2];
v[3] = params[3];
jwzgles_glLightModelfv (pname, v);
}
 
void
jwzgles_glFogiv (GLenum pname, const GLint *params)
{
GLfloat v[4];
v[0] = params[0];
v[1] = params[1];
v[2] = params[2];
v[3] = params[3];
jwzgles_glFogfv (pname, v);
}
 
void
jwzgles_glLighti (GLenum light, GLenum pname, GLint param)
{
jwzgles_glLightf (light, pname, param);
}
 
void
jwzgles_glLightModeli (GLenum pname, GLint param)
{
jwzgles_glLightModelf (pname, param);
}
 
void
jwzgles_glFogi (GLenum pname, GLint param)
{
jwzgles_glFogf (pname, param);
}
 
 
void
jwzgles_glRotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
{
jwzgles_glRotatef (angle, x, y, z);
}
 
 
/*
void
jwzgles_glClipPlane (GLenum plane, const GLdouble *equation)
{
Assert (state->compiling_verts, "glClipPlane not inside glBegin");
Assert (0, "glClipPlane unimplemented"); / * no GLES equivalent... * /
}
*/
 
 
void
jwzgles_glPolygonMode (GLenum face, GLenum mode)
{
Assert (!state->compiling_verts, "not inside glBegin");
if (state->compiling_list)
{
void_int vv[2];
vv[0].i = face;
vv[1].i = mode;
list_push ("glPolygonMode", (list_fn_cb) &jwzgles_glPolygonMode,
PROTO_II, vv);
}
else
{
/* POINT and LINE don't exist in GLES */
Assert (mode == GL_FILL, "glPolygonMode: unimplemented mode");
}
}
 
 
void
jwzgles_glDrawBuffer (GLenum buf)
{
Assert (!state->compiling_verts, "not inside glBegin");
if (state->compiling_list)
{
void_int vv[1];
vv[0].i = buf;
list_push ("glDrawBuffer", (list_fn_cb) &jwzgles_glDrawBuffer,
PROTO_I, vv);
}
else
{
/* Assert (buf == GL_BACK, "glDrawBuffer: back buffer only"); */
# ifndef GL_VERSION_ES_CM_1_0 /* not compiling against OpenGLES 1.x */
if (! state->replaying_list)
LOG1 ("direct %-12s", "glDrawBuffer");
glDrawBuffer (buf); /* the real one */
CHECK("glDrawBuffer");
# endif
}
}
 
 
/* Given an array of sets of 4 elements of arbitrary size, convert it
to an array of sets of 6 elements instead: ABCD becomes ABC BCD.
*/
static int
cq2t (unsigned char **arrayP, int stride, int count)
{
int count2 = count * 6 / 4;
int size = stride * count;
int size2 = stride * count2;
const unsigned char *oarray, *in;
unsigned char *array2, *oarray2, *out;
int i;
 
oarray = *arrayP;
if (!oarray || count == 0)
return count2;
 
array2 = (unsigned char *) malloc (size2);
Assert (array2, "out of memory");
oarray2 = array2;
 
in = oarray;
out = oarray2;
for (i = 0; i < count / 4; i++)
{
const unsigned char *a, *b, *c, *d; /* the 4 corners */
a = in; in += stride;
b = in; in += stride;
c = in; in += stride;
d = in; in += stride;
 
# define PUSH(IN) do { \
const unsigned char *ii = IN; \
int j; \
for (j = 0; j < stride; j++) { \
*out++ = *ii++; \
}} while(0)
 
PUSH (a); PUSH (b); PUSH (d); /* the 2 triangles */
PUSH (b); PUSH (c); PUSH (d);
# undef PUSH
}
 
Assert (in == oarray + size, "convert_quads corrupted");
Assert (out == oarray2 + size2, "convert_quads corrupted");
 
free (*arrayP);
*arrayP = oarray2;
return count2;
}
 
/* Convert all coordinates in a GL_QUADS vert_set to GL_TRIANGLES.
*/
static void
convert_quads_to_triangles (vert_set *s)
{
int count2;
Assert (s->mode == GL_QUADS, "convert_quads bad mode");
count2 =
cq2t ((unsigned char **) &s->verts, sizeof(*s->verts), s->count);
cq2t ((unsigned char **) &s->norms, sizeof(*s->norms), s->count);
cq2t ((unsigned char **) &s->tex, sizeof(*s->tex), s->count);
cq2t ((unsigned char **) &s->color, sizeof(*s->color), s->count);
s->count = count2;
s->size = count2;
s->mode = GL_TRIANGLES;
}
 
 
void
jwzgles_glEnd (void)
{
vert_set *s = &state->set;
int was_norm, was_tex, was_color, was_mat;
int is_norm, is_tex, is_color, is_mat;
 
Assert (state->compiling_verts == 1, "missing glBegin");
state->compiling_verts--;
 
Assert (!state->replaying_list, "how did glEnd get into a display list?");
 
if (!state->replaying_list)
{
LOG5 ("%s [V = %d, N = %d, T = %d, C = %d]",
(state->compiling_list || state->replaying_list ? " " : ""),
s->count, s->ncount, s->tcount, s->ccount);
LOG1 ("%sglEnd",
(state->compiling_list || state->replaying_list ? " " : ""));
}
 
if (s->count == 0) return;
 
if (s->mode == GL_QUADS)
convert_quads_to_triangles (s);
else if (s->mode == GL_QUAD_STRIP)
s->mode = GL_TRIANGLE_STRIP; /* They do the same thing! */
else if (s->mode == GL_POLYGON)
s->mode = GL_TRIANGLE_FAN; /* They do the same thing! */
 
jwzgles_glColorPointer (4,GL_FLOAT, sizeof(*s->color),s->color); /* RGBA */
jwzgles_glNormalPointer ( GL_FLOAT, sizeof(*s->norms),s->norms); /* XYZ */
jwzgles_glTexCoordPointer(4,GL_FLOAT, sizeof(*s->tex), s->tex); /* STRQ */
jwzgles_glVertexPointer (4,GL_FLOAT, sizeof(*s->verts),s->verts); /* XYZW */
/* glVertexPointer must come after glTexCoordPointer */
 
/* If there were no calls to glNormal3f inside of glBegin/glEnd,
don't bother enabling the normals array.
 
If there was exactly *one* call to glNormal3f inside of glBegin/glEnd,
and it was before the first glVertex3f, then also don't enable the
normals array, but do emit that call to glNormal3f before calling
glDrawArrays.
 
Likewise for texture coordinates and colors.
 
Be careful to leave the arrays' enabled/disabled state the same as
before, or a later caller might end up using one of our arrays by
mistake. (Remember that jwzgles_glIsEnabled() tracks the enablement
of the list-in-progress as well as the global state.)
*/
was_norm = jwzgles_glIsEnabled (GL_NORMAL_ARRAY);
was_tex = jwzgles_glIsEnabled (GL_TEXTURE_COORD_ARRAY);
was_color = jwzgles_glIsEnabled (GL_COLOR_ARRAY);
was_mat = jwzgles_glIsEnabled (GL_COLOR_MATERIAL);
 
/* If we're executing glEnd in immediate mode, not from inside a display
list (which is the only way it happens, because glEnd doesn't go into
display lists), make sure we're not stomping on a saved buffer list:
in immediate mode, vertexes are client-side only.
*/
if (! state->compiling_list)
jwzgles_glBindBuffer (GL_ARRAY_BUFFER, 0);
 
if (s->ncount > 1)
{
is_norm = 1;
jwzgles_glEnableClientState (GL_NORMAL_ARRAY);
}
else
{
is_norm = 0;
if (s->ncount == 1)
jwzgles_glNormal3f (s->cnorm.x, s->cnorm.y, s->cnorm.z);
jwzgles_glDisableClientState (GL_NORMAL_ARRAY);
}
 
if (s->tcount > 1 ||
((state->compiling_list ? state->list_enabled : state->enabled)
& (ISENABLED_TEXTURE_GEN_S | ISENABLED_TEXTURE_GEN_T |
ISENABLED_TEXTURE_GEN_R | ISENABLED_TEXTURE_GEN_Q)))
{
/* Enable texture coords if any were specified; or if generation
is on in immediate mode; or if this list turned on generation. */
is_tex = 1;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
}
else
{
is_tex = 0;
if (s->tcount == 1)
jwzgles_glTexCoord4f (s->ctex.s, s->ctex.t, s->ctex.r, s->ctex.q);
jwzgles_glDisableClientState (GL_TEXTURE_COORD_ARRAY);
}
 
if (s->ccount > 1)
{
is_color = 1;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
}
else
{
is_color = 0;
if (s->ccount == 1)
jwzgles_glColor4f (s->ccolor.r, s->ccolor.g, s->ccolor.b, s->ccolor.a);
jwzgles_glDisableClientState (GL_COLOR_ARRAY);
}
 
jwzgles_glEnableClientState (GL_VERTEX_ARRAY);
 
/* We translated the glMaterial calls to per-vertex colors, which are
of the glColor sort, not the glMaterial sort, so automatically
turn on material mapping. Maybe this is a bad idea.
*/
if (s->materialistic && !jwzgles_glIsEnabled (GL_COLOR_MATERIAL))
{
is_mat = 1;
jwzgles_glEnable (GL_COLOR_MATERIAL);
}
else
is_mat = 0;
 
glBindBuffer (GL_ARRAY_BUFFER, 0); /* This comes later. */
jwzgles_glDrawArrays (s->mode, 0, s->count);
glBindBuffer (GL_ARRAY_BUFFER, 0); /* Keep out of others' hands */
 
# define RESET(VAR,FN,ARG) do { \
if (is_##VAR != was_##VAR) { \
if (was_##VAR) jwzgles_glEnable##FN (ARG); \
else jwzgles_glDisable##FN (ARG); \
}} while(0)
RESET (norm, ClientState, GL_NORMAL_ARRAY);
RESET (tex, ClientState, GL_TEXTURE_COORD_ARRAY);
RESET (color, ClientState, GL_COLOR_ARRAY);
RESET (mat, , GL_COLOR_MATERIAL);
# undef RESET
 
s->count = 0;
s->ncount = 0;
s->tcount = 0;
s->ccount = 0;
s->materialistic = 0;
}
 
 
/* The display list is full of calls to glDrawArrays(), plus saved arrays
of the values we need to restore before calling it. "Restore" means
"ship them off to the GPU before each call".
 
So instead, this function walks through the display list and
combines all of those vertex, normal, texture and color values into
a single VBO array; ships those values off to the GPU *once* at the
time of glEndList; and when running the list with glCallList, the
values are already on the GPU and don't need to be sent over again.
 
The VBO persists in the GPU until the display list is deleted.
*/
static void
optimize_arrays (void)
{
list *L = &state->lists.lists[state->compiling_list-1];
int i, j;
GLfloat *combo = 0;
int combo_count = 0;
int combo_size = 0;
GLuint buf_name = 0;
 
Assert (state->compiling_list, "not compiling a list");
Assert (L, "no list");
Assert (!L->buffer, "list already has a buffer");
 
glGenBuffers (1, &buf_name);
CHECK("glGenBuffers");
if (! buf_name) return;
 
L->buffer = buf_name;
 
/* Go through the list and dump the contents of the various saved arrays
into one large array.
*/
for (i = 0; i < L->count; i++)
{
list_fn *F = &L->fns[i];
/* int count; */
if (! F->arrays)
continue;
/* count = F->argv[2].i;*/ /* 3rd arg to glDrawArrays */
 
for (j = 0; j < 4; j++)
{
draw_array *A = &F->arrays[j];
int ocount = combo_count;
 
/* If some caller is using arrays that don't have floats in them,
we just leave them as-is and ship them over at each call.
Doubt this ever really happens.
*/
if (A->type != GL_FLOAT)
continue;
 
if (! A->data) /* No array. */
continue;
 
Assert (A->bytes > 0, "no bytes in draw_array");
Assert (((unsigned long) A->data > 0xFFFF),
"buffer data not a pointer");
 
combo_count += A->bytes / sizeof(*combo);
make_room ("optimize_arrays",
(void **) &combo, sizeof(*combo),
&combo_count, &combo_size);
memcpy (combo + ocount, A->data, A->bytes);
A->binding = buf_name;
free (A->data);
/* 'data' is now the byte offset into the VBO. */
A->data = (void *) (ocount * sizeof(*combo));
/* LOG3(" loaded %lu floats to pos %d of buffer %d",
A->bytes / sizeof(*combo), ocount, buf_name); */
}
}
 
if (combo_count == 0) /* Nothing to do! */
{
if (combo) free (combo);
glDeleteBuffers (1, &buf_name);
L->buffer = 0;
return;
}
 
glBindBuffer (GL_ARRAY_BUFFER, buf_name);
glBufferData (GL_ARRAY_BUFFER,
combo_count * sizeof (*combo),
combo,
GL_STATIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER, 0); /* Keep out of others' hands */
 
LOG3(" loaded %d floats of list %d into VBO %d",
combo_count, state->compiling_list, buf_name);
 
# ifdef DEBUG
# if 0
for (i = 0; i < combo_count; i++)
{
if (i % 4 == 0)
fprintf (stderr, "\njwzgles: %4d: ", i);
fprintf (stderr, " %7.3f", combo[i]);
}
fprintf (stderr, "\n");
# endif
# endif /* DEBUG */
 
if (combo) free (combo);
}
 
 
void
jwzgles_glCallList (int id)
{
if (state->compiling_list)
{
/* Yes, you can call lists inside of lists.
Yes, recursion would be a mistake. */
void_int vv[1];
vv[0].i = id;
list_push ("glCallList", (list_fn_cb) &jwzgles_glCallList, PROTO_I, vv);
}
else
{
list *L;
int i;
 
state->replaying_list++;
 
# ifdef DEBUG
fprintf (stderr, "\n");
LOG1 ("glCallList %d", id);
# endif
 
Assert (id > 0 && id <= state->lists.count, "glCallList: bogus ID");
L = &state->lists.lists[id-1];
Assert (id == L->id, "glCallList corrupted");
 
for (i = 0; i < L->count; i++)
{
list_fn *F = &L->fns[i];
list_fn_cb fn = F->fn;
void_int *av = F->argv;
 
switch (F->proto) {
case PROTO_VOID:
LOG1 (" call %-12s", F->name);
((void (*) (void)) fn) ();
break;
 
case PROTO_I:
if (fn == (list_fn_cb) &jwzgles_glBegin ||
fn == (list_fn_cb) &jwzgles_glFrontFace ||
fn == (list_fn_cb) &jwzgles_glEnable ||
fn == (list_fn_cb) &jwzgles_glDisable ||
fn == (list_fn_cb) &jwzgles_glEnableClientState ||
fn == (list_fn_cb) &jwzgles_glDisableClientState ||
fn == (list_fn_cb) &jwzgles_glShadeModel ||
fn == (list_fn_cb) &jwzgles_glMatrixMode)
LOG2 (" call %-12s %s", F->name, mode_desc (av[0].i));
else
LOG2 (" call %-12s %d", F->name, av[0].i);
((void (*) (int)) fn) (av[0].i);
break;
 
case PROTO_F:
LOG2 (" call %-12s %7.3f", F->name, av[0].f);
((void (*) (GLfloat)) fn) (av[0].f);
break;
 
case PROTO_II:
if (fn == (list_fn_cb) &jwzgles_glBindTexture ||
fn == (list_fn_cb) &jwzgles_glBindBuffer)
LOG3 (" call %-12s %s %d", F->name,
mode_desc (av[0].i), av[1].i);
else
LOG3 (" call %-12s %d %d", F->name, av[0].i, av[1].i);
((void (*) (int, int)) fn) (av[0].i, av[1].i);
break;
 
case PROTO_FF:
LOG3 (" call %-12s %7.3f %7.3f", F->name, av[0].f, av[1].f);
((void (*) (GLfloat, GLfloat)) fn) (av[0].f, av[1].f);
break;
 
case PROTO_IF:
LOG3 (" call %-12s %s %7.3f", F->name,
mode_desc (av[0].f), av[1].f);
((void (*) (GLint, GLfloat)) fn) (av[0].i, av[1].f);
break;
 
case PROTO_III: III:
if (fn == (list_fn_cb) &jwzgles_glDrawArrays ||
fn == (list_fn_cb) &jwzgles_glTexParameteri)
LOG4 (" call %-12s %s %d %d", F->name,
mode_desc (av[0].i), av[1].i, av[2].i);
else
LOG4 (" call %-12s %d %d %d", F->name,
av[0].i, av[1].i, av[2].i);
((void (*) (int, int, int)) fn) (av[0].i, av[1].i, av[2].i);
break;
 
case PROTO_FFF:
LOG4 (" call %-12s %7.3f %7.3f %7.3f", F->name,
av[0].f, av[1].f, av[2].f);
((void (*) (GLfloat, GLfloat, GLfloat)) fn)
(av[0].f, av[1].f, av[2].f);
break;
 
case PROTO_IIF:
LOG4 (" call %-12s %s %s %7.3f", F->name,
mode_desc (av[0].i), mode_desc (av[1].i), av[2].f);
((void (*) (int, int, GLfloat)) fn) (av[0].i, av[1].i, av[2].f);
break;
 
case PROTO_IIII:
LOG5 (" call %-12s %d %d %d %d", F->name,
av[0].i, av[1].i, av[2].i, av[3].i);
((void (*) (int, int, int, int)) fn)
(av[0].i, av[1].i, av[2].i, av[3].i);
break;
 
case PROTO_FFFF:
LOG5 (" call %-12s %7.3f %7.3f %7.3f %7.3f", F->name,
av[0].f, av[1].f, av[2].f, av[3].f);
((void (*) (GLfloat, GLfloat, GLfloat, GLfloat)) fn)
(av[0].f, av[1].f, av[2].f, av[3].f);
break;
 
case PROTO_IFV:
{
GLfloat v[4];
v[0] = av[1].f;
v[1] = av[2].f;
v[2] = av[3].f;
v[3] = av[4].f;
LOG6 (" call %-12s %s %3.1f %3.1f %3.1f %3.1f", F->name,
mode_desc (av[0].i),
av[1].f, av[2].f, av[3].f, av[4].f);
((void (*) (int, const GLfloat *)) fn) (av[0].i, v);
}
break;
 
case PROTO_IIFV:
{
GLfloat v[4];
v[0] = av[2].f;
v[1] = av[3].f;
v[2] = av[4].f;
v[3] = av[5].f;
LOG7 (" call %-12s %s %-8s %3.1f %3.1f %3.1f %3.1f", F->name,
mode_desc (av[0].i), mode_desc (av[1].i),
av[2].f, av[3].f, av[4].f, av[5].f);
((void (*) (int, int, const GLfloat *)) fn)
(av[0].i, av[1].i, v);
}
break;
 
case PROTO_IIV:
{
int v[4];
v[0] = av[1].i;
v[1] = av[2].i;
v[2] = av[3].i;
v[3] = av[4].i;
LOG6 (" call %-12s %s %3d %3d %3d %3d", F->name,
mode_desc (av[0].i),
av[1].i, av[2].i, av[3].i, av[4].i);
((void (*) (int, const int *)) fn) (av[0].i, v);
}
break;
 
case PROTO_IIIV:
{
int v[4];
v[0] = av[2].i;
v[1] = av[3].i;
v[2] = av[4].i;
v[3] = av[5].i;
LOG7 (" call %-12s %s %-8s %3d %3d %3d %3d", F->name,
mode_desc (av[0].i), mode_desc (av[1].i),
av[2].i, av[3].i, av[4].i, av[5].i);
((void (*) (int, int, const int *)) fn)
(av[0].i, av[1].i, v);
}
break;
 
case PROTO_ARRAYS:
restore_arrays (F, av[1].i + av[2].i);
goto III;
break;
 
case PROTO_FV16:
{
GLfloat m[16];
int i;
for (i = 0; i < countof(m); i++)
m[i] = av[i].f;
LOG17 (" call %-12s ["
"%8.3f %8.3f %8.3f %8.3f " "\n\t\t\t "
"%8.3f %8.3f %8.3f %8.3f " "\n\t\t\t "
"%8.3f %8.3f %8.3f %8.3f " "\n\t\t\t "
"%8.3f %8.3f %8.3f %8.3f ]",
F->name,
m[0], m[1], m[2], m[3],
m[4], m[5], m[6], m[7],
m[8], m[9], m[10], m[11],
m[12], m[13], m[14], m[15]);
((void (*) (GLfloat *)) fn) (m);
}
break;
 
default:
Assert (0, "bogus prototype");
break;
}
}
 
LOG1 ("glCallList %d done\n", id);
 
state->replaying_list--;
Assert (state->replaying_list >= 0, "glCallList corrupted");
}
}
 
 
/* When we save a call to glDrawArrays into a display list, we also need to
save the prevailing copy of the arrays that it will use, and restore them
later.
*/
static void
save_arrays (list_fn *F, int count)
{
int i = 0;
draw_array *A = (draw_array *) calloc (4, sizeof (*A));
Assert (A, "out of memory");
 
/* if (state->set.count > 0) */
{
glGetIntegerv (GL_VERTEX_ARRAY_BUFFER_BINDING, &A[i].binding);
glGetIntegerv (GL_VERTEX_ARRAY_SIZE, &A[i].size);
glGetIntegerv (GL_VERTEX_ARRAY_TYPE, &A[i].type);
glGetIntegerv (GL_VERTEX_ARRAY_STRIDE, &A[i].stride);
glGetPointerv (GL_VERTEX_ARRAY_POINTER, &A[i].data);
CHECK("glGetPointerv");
copy_array_data (&A[i], count, "vert");
}
 
i++;
if (state->set.ncount > 1)
{
A[i].size = 3;
glGetIntegerv (GL_NORMAL_ARRAY_BUFFER_BINDING, &A[i].binding);
glGetIntegerv (GL_NORMAL_ARRAY_TYPE, &A[i].type);
glGetIntegerv (GL_NORMAL_ARRAY_STRIDE, &A[i].stride);
glGetPointerv (GL_NORMAL_ARRAY_POINTER, &A[i].data);
CHECK("glGetPointerv");
copy_array_data (&A[i], count, "norm");
}
 
i++;
if (state->set.tcount > 1)
{
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING, &A[i].binding);
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, &A[i].size);
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, &A[i].type);
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, &A[i].stride);
glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, &A[i].data);
CHECK("glGetPointerv");
copy_array_data (&A[i], count, "tex ");
}
 
i++;
if (state->set.ccount > 1)
{
glGetIntegerv (GL_COLOR_ARRAY_BUFFER_BINDING, &A[i].binding);
glGetIntegerv (GL_COLOR_ARRAY_SIZE, &A[i].size);
glGetIntegerv (GL_COLOR_ARRAY_TYPE, &A[i].type);
glGetIntegerv (GL_COLOR_ARRAY_STRIDE, &A[i].stride);
glGetPointerv (GL_COLOR_ARRAY_POINTER, &A[i].data);
CHECK("glGetPointerv");
copy_array_data (&A[i], count, "col ");
}
 
/* Freed by glDeleteLists. */
 
Assert (!F->arrays, "save_arrays corrupted");
F->arrays = A;
}
 
 
#ifdef DEBUG
 
static void
dump_array_data (draw_array *A, int count,
const char *action, const char *name, const void *old)
{
int bytes = count * A->stride;
 
if (A->binding)
{
fprintf (stderr,
"jwzgles: %s %s %d %s %2d, %4d = %5d bind %d @ %d\n",
action, name,
A->size, mode_desc(A->type), A->stride,
count, bytes, A->binding, (int) A->data);
}
else
{
Assert (bytes == A->bytes, "array data corrupted");
 
fprintf (stderr, "jwzgles: %s %s %d %s %2d, %4d = %5d @ %lX",
action, name,
A->size, mode_desc(A->type), A->stride,
count, bytes, (unsigned long) A->data);
if (old)
fprintf (stderr, " / %lX", (unsigned long) old);
fprintf (stderr, "\n");
}
 
if (A->binding)
{
Assert (((unsigned long) A->data < 0xFFFF),
"buffer binding should be a numeric index,"
" but looks like a pointer");
 
# if 0
/* glGetBufferSubData doesn't actually exist in OpenGLES, but this
was helpful for debugging on real OpenGL... */
GLfloat *d;
int i;
fprintf (stderr, "jwzgles: read back:\n");
d = (GLfloat *) malloc (A->bytes);
glGetBufferSubData (GL_ARRAY_BUFFER, (int) A->data,
count * A->stride, (void *) d);
CHECK("glGetBufferSubData");
for (i = 0; i < count * A->size; i++)
{
if (i % 4 == 0)
fprintf (stderr, "\njwzgles: %4d: ",
i + (int) A->data / sizeof(GLfloat));
fprintf (stderr, " %7.3f", d[i]);
}
fprintf (stderr, "\n");
free (d);
# endif
}
# if 0
else
{
unsigned char *b = (unsigned char *) A->data;
int i;
if ((unsigned long) A->data < 0xFFFF)
{
Assert (0, "buffer data not a pointer");
return;
}
for (i = 0; i < count; i++)
{
int j;
GLfloat *f = (GLfloat *) b;
int s = A->size;
if (s == 0) s = 3; /* normals */
fprintf (stderr, "jwzgles: ");
for (j = 0; j < s; j++)
fprintf (stderr, " %7.3f", f[j]);
fprintf (stderr, "\n");
b += A->stride;
}
}
# endif
}
 
static void
dump_direct_array_data (int count)
{
draw_array A = { 0, 0, 0, 0, 0, NULL};
 
if (jwzgles_glIsEnabled (GL_VERTEX_ARRAY))
{
glGetIntegerv (GL_VERTEX_ARRAY_BUFFER_BINDING, &A.binding);
glGetIntegerv (GL_VERTEX_ARRAY_SIZE, &A.size);
glGetIntegerv (GL_VERTEX_ARRAY_TYPE, &A.type);
glGetIntegerv (GL_VERTEX_ARRAY_STRIDE, &A.stride);
glGetPointerv (GL_VERTEX_ARRAY_POINTER, &A.data);
A.bytes = count * A.stride;
dump_array_data (&A, count, "direct", "vertex ", 0);
}
if (jwzgles_glIsEnabled (GL_NORMAL_ARRAY))
{
A.size = 0;
glGetIntegerv (GL_NORMAL_ARRAY_BUFFER_BINDING, &A.binding);
glGetIntegerv (GL_NORMAL_ARRAY_TYPE, &A.type);
glGetIntegerv (GL_NORMAL_ARRAY_STRIDE, &A.stride);
glGetPointerv (GL_NORMAL_ARRAY_POINTER, &A.data);
A.bytes = count * A.stride;
dump_array_data (&A, count, "direct", "normal ", 0);
}
if (jwzgles_glIsEnabled (GL_TEXTURE_COORD_ARRAY))
{
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING, &A.binding);
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, &A.size);
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, &A.type);
glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, &A.stride);
glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, &A.data);
A.bytes = count * A.stride;
dump_array_data (&A, count, "direct", "texture", 0);
}
if (jwzgles_glIsEnabled (GL_COLOR_ARRAY))
{
glGetIntegerv (GL_COLOR_ARRAY_BUFFER_BINDING, &A.binding);
glGetIntegerv (GL_COLOR_ARRAY_SIZE, &A.size);
glGetIntegerv (GL_COLOR_ARRAY_TYPE, &A.type);
glGetIntegerv (GL_COLOR_ARRAY_STRIDE, &A.stride);
glGetPointerv (GL_COLOR_ARRAY_POINTER, &A.data);
A.bytes = count * A.stride;
dump_array_data (&A, count, "direct", "color ", 0);
}
}
 
#endif /* DEBUG */
 
 
static void
copy_array_data (draw_array *A, int count, const char *name)
{
/* Instead of just memcopy'ing the whole array and obeying its previous
'stride' value, we make up a more compact array. This is because if
the same array data is being used with multiple component types,
e.g. with glInterleavedArrays, we don't want to copy all of the
data multiple times.
*/
int stride2 = 0, bytes, i, j;
void *data2;
const GLfloat *IF;
GLfloat *OF;
const unsigned char *IB;
unsigned char *OB;
 
if (((unsigned long) A->data) < 0xFFFF)
{
Assert (0, "buffer data not a pointer");
return;
}
 
Assert (A->size >= 2 && A->size <= 4, "bogus array size");
 
switch (A->type) {
case GL_FLOAT: stride2 = A->size * sizeof(GLfloat); break;
case GL_UNSIGNED_BYTE: stride2 = A->size; break;
default: Assert (0, "bogus array type"); break;
}
 
bytes = count * stride2;
Assert (bytes > 0, "bogus array count or stride");
Assert (A->data, "missing array data");
data2 = (void *) malloc (bytes);
Assert (data2, "out of memory");
 
IB = (const unsigned char *) A->data;
OB = (unsigned char *) data2;
IF = (const GLfloat *) A->data;
OF = (GLfloat *) data2;
 
switch (A->type) {
case GL_FLOAT:
for (i = 0; i < count; i++)
{
for (j = 0; j < A->size; j++)
*OF++ = IF[j];
IF = (const GLfloat *) (((const unsigned char *) IF) + A->stride);
}
break;
case GL_UNSIGNED_BYTE:
for (i = 0; i < count; i++)
{
for (j = 0; j < A->size; j++)
*OB++ = IB[j];
IB += A->stride;
}
break;
default:
Assert (0, "bogus array type");
break;
}
 
A->data = data2;
A->bytes = bytes;
A->stride = stride2;
 
# ifdef DEBUG
dump_array_data (A, count, "saved", name, 0);
# endif
}
 
 
static void
restore_arrays (list_fn *F, int count)
{
int i = 0;
draw_array *A = F->arrays;
Assert (A, "missing array");
 
for (i = 0; i < 4; i++)
{
const char *name = 0;
 
if (!A[i].size)
continue;
 
Assert ((A[i].binding || A[i].data),
"array has neither buffer binding nor data");
 
glBindBuffer (GL_ARRAY_BUFFER, A[i].binding);
CHECK("glBindBuffer");
 
switch (i) {
case 0: glVertexPointer (A[i].size, A[i].type, A[i].stride, A[i].data);
name = "vertex ";
CHECK("glVertexPointer");
break;
case 1: glNormalPointer ( A[i].type, A[i].stride, A[i].data);
name = "normal ";
CHECK("glNormalPointer");
break;
case 2: glTexCoordPointer(A[i].size, A[i].type, A[i].stride, A[i].data);
name = "texture";
CHECK("glTexCoordPointer");
break;
case 3: glColorPointer (A[i].size, A[i].type, A[i].stride, A[i].data);
name = "color ";
CHECK("glColorPointer");
break;
default: Assert (0, "wat"); break;
}
 
# ifdef DEBUG
dump_array_data (&A[i], count, "restored", name, 0);
# endif
}
 
glBindBuffer (GL_ARRAY_BUFFER, 0); /* Keep out of others' hands */
}
 
 
void
jwzgles_glDrawArrays (GLuint mode, GLuint first, GLuint count)
{
/* If we are auto-generating texture coordinates, do that now, after
the vertex array was installed, but before drawing, This happens
when recording into a list, or in direct mode. It must happen
before calling optimize_arrays() from glEndList().
*/
if (! state->replaying_list &&
((state->compiling_list ? state->list_enabled : state->enabled)
& (ISENABLED_TEXTURE_GEN_S | ISENABLED_TEXTURE_GEN_T |
ISENABLED_TEXTURE_GEN_R | ISENABLED_TEXTURE_GEN_Q)))
generate_texture_coords (first, count);
 
if (state->compiling_list)
{
void_int vv[3];
vv[0].i = mode;
vv[1].i = first;
vv[2].i = count;
list_push ("glDrawArrays", (list_fn_cb) &jwzgles_glDrawArrays,
PROTO_ARRAYS, vv);
}
else
{
# ifdef DEBUG
if (! state->replaying_list) {
LOG4("direct %-12s %d %d %d", "glDrawArrays", mode, first, count);
dump_direct_array_data (first + count);
}
# endif
glDrawArrays (mode, first, count); /* the real one */
CHECK("glDrawArrays");
}
}
 
 
void
jwzgles_glInterleavedArrays (GLenum format, GLsizei stride, const void *data)
{
/* We can implement this by calling the various *Pointer functions
with offsets into the same data, taking advantage of stride.
*/
const unsigned char *c = (const unsigned char *) data;
# define B 1
# define F sizeof(GLfloat)
 
Assert (!state->compiling_verts,
"glInterleavedArrays not allowed inside glBegin");
 
jwzgles_glEnableClientState (GL_VERTEX_ARRAY);
 
if (!state->replaying_list)
LOG4 ("%sglInterleavedArrays %s %d %lX",
(state->compiling_list || state->replaying_list ? " " : ""),
mode_desc (format), stride, (unsigned long) data);
 
switch (format) {
case GL_V2F:
glVertexPointer (2, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
if (!state->replaying_list)
LOG3 ("%s -> glVertexPointer 2 FLOAT %d %lX",
(state->compiling_list || state->replaying_list ? " " : ""),
stride, (unsigned long) c);
break;
case GL_V3F:
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
if (!state->replaying_list)
LOG3 ("%s -> glVertexPointer 3 FLOAT %d %lX",
(state->compiling_list || state->replaying_list ? " " : ""),
stride, (unsigned long) c);
break;
case GL_C4UB_V2F:
if (stride == 0)
stride = 4*B + 2*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (4, GL_UNSIGNED_BYTE, stride, c);
CHECK("glColorPointer");
c += 4*B; /* #### might be incorrect float-aligned address */
glVertexPointer (2, GL_FLOAT, stride, c);
break;
case GL_C4UB_V3F:
if (stride == 0)
stride = 4*B + 3*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (4, GL_UNSIGNED_BYTE, stride, c);
CHECK("glColorPointer");
c += 4*B;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_C3F_V3F:
if (stride == 0)
stride = 3*F + 3*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (3, GL_FLOAT, stride, c);
CHECK("glColorPointer");
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_N3F_V3F:
if (stride == 0)
stride = 3*F + 3*F;
jwzgles_glEnableClientState (GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, stride, c);
CHECK("glNormalPointer");
if (!state->replaying_list)
LOG3 ("%s -> glNormalPointer FLOAT %d %lX",
(state->compiling_list || state->replaying_list ? " " : ""),
stride, (unsigned long) c);
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
if (!state->replaying_list)
LOG3 ("%s -> glVertexPointer 3 FLOAT %d %lX",
(state->compiling_list || state->replaying_list ? " " : ""),
stride, (unsigned long) c);
break;
case GL_C4F_N3F_V3F:
if (stride == 0)
stride = 4*F + 3*F + 3*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (4, GL_FLOAT, stride, c);
CHECK("glColorPointer");
c += 4*F;
jwzgles_glEnableClientState (GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, stride, c);
CHECK("glNormalPointer");
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T2F_V3F:
if (stride == 0)
stride = 2*F + 3*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (2, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 2*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T4F_V4F:
if (stride == 0)
stride = 4*F + 4*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (4, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 4*F;
glVertexPointer (4, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T2F_C4UB_V3F:
if (stride == 0)
stride = 2*F + 4*B + 3*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (2, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 2*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (4, GL_UNSIGNED_BYTE, stride, c);
CHECK("glColorPointer");
c += 4*B;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T2F_C3F_V3F:
if (stride == 0)
stride = 2*F + 3*F + 3*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (2, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 2*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (3, GL_FLOAT, stride, c);
CHECK("glColorPointer");
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T2F_N3F_V3F:
if (stride == 0)
stride = 2*F + 3*F + 3*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (2, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 2*F;
jwzgles_glEnableClientState (GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, stride, c);
CHECK("glNormalPointer");
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T2F_C4F_N3F_V3F:
if (stride == 0)
stride = 2*F + 4*F + 3*F + 3*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (2, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 2*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (3, GL_FLOAT, stride, c);
CHECK("glColorPointer");
c += 3*F;
jwzgles_glEnableClientState (GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, stride, c);
CHECK("glNormalPointer");
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
case GL_T4F_C4F_N3F_V4F:
if (stride == 0)
stride = 4*F + 4*F + 3*F + 4*F;
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (4, GL_FLOAT, stride, c);
CHECK("glTexCoordPointer");
c += 4*F;
jwzgles_glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (4, GL_FLOAT, stride, c);
CHECK("glColorPointer");
c += 4*F;
jwzgles_glEnableClientState (GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, stride, c);
CHECK("glNormalPointer");
c += 3*F;
glVertexPointer (3, GL_FLOAT, stride, c);
CHECK("glVertexPointer");
break;
default:
Assert (0, "glInterleavedArrays: bogus format");
break;
}
 
# undef B
# undef F
}
 
 
 
void
jwzgles_glMultMatrixf (const GLfloat *m)
{
Assert (!state->compiling_verts,
"glMultMatrixf not allowed inside glBegin");
if (state->compiling_list)
{
void_int vv[16];
int i;
for (i = 0; i < countof(vv); i++)
vv[i].f = m[i];
list_push ("glMultMatrixf", (list_fn_cb) &jwzgles_glMultMatrixf,
PROTO_FV16, vv);
}
else
{
if (! state->replaying_list)
LOG1 ("direct %-12s", "glMultMatrixf");
glMultMatrixf (m); /* the real one */
CHECK("glMultMatrixf");
}
}
 
void
jwzgles_glLoadMatrixf (const GLfloat * m)
{
glLoadMatrixf(m);
}
 
void
jwzgles_glLoadMatrixd (const GLdouble * m)
{
int n;
GLfloat matrix[16];
for (n=0;n<16;n++)
{
matrix[n] = (GLfloat)m[n];
}
jwzgles_glLoadMatrixf(matrix);
}
 
 
/*
void
jwzgles_glClearIndex(GLfloat c)
{
/ * Does GLES even do indexed color? * /
Assert (0, "glClearIndex unimplemented");
}
*/
 
 
/*
void
jwzgles_glBitmap (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig,
GLfloat xmove, GLfloat ymove, const GLubyte *bitmap)
{
Assert (0, "glBitmap unimplemented");
}
*/
 
/*
void
jwzgles_glPushAttrib(int flags)
{
//Assert (0, "glPushAttrib unimplemented");
}
 
void
jwzgles_glPopAttrib(void)
{
// Assert (0, "glPopAttrib unimplemented");
}
*/
 
 
/* These are needed for object hit detection in pinion.
Might need to rewrite that code entirely. Punt for now.
*/
/*
void
jwzgles_glInitNames (void)
{
/ * Assert (0, "glInitNames unimplemented");* /
}
*/
 
/*
void
jwzgles_glPushName (GLuint name)
{
/ * Assert (0, "glPushName unimplemented");* /
}
 
GLuint
jwzgles_glPopName (void)
{
/ * Assert (0, "glPopName unimplemented");* /
return 0;
}
*/
 
/*
GLuint
jwzgles_glRenderMode (GLuint mode)
{
/ * Assert (0, "glRenderMode unimplemented");* /
return 0;
}
 
void
jwzgles_glSelectBuffer (GLsizei size, GLuint *buf)
{
/ * Assert (0, "glSelectBuffer unimplemented");* /
}
*/
 
 
void
jwzgles_glGenTextures (GLuint n, GLuint *ret)
{
Assert (!state->compiling_verts,
"glGenTextures not allowed inside glBegin");
/* technically legal, but stupid! */
Assert (!state->compiling_list,
"glGenTextures not allowed inside glNewList");
if (! state->replaying_list)
LOG1 ("direct %-12s", "glGenTextures");
glGenTextures (n, ret); /* the real one */
CHECK("glGenTextures");
}
 
 
/* return the next larger power of 2. */
static int
to_pow2 (int value)
{
int i = 1;
while (i < value) i <<= 1;
return i;
}
 
void
jwzgles_glTexImage1D (GLenum target, GLint level,
GLint internalFormat,
GLsizei width, GLint border,
GLenum format, GLenum type,
const GLvoid *data)
{
Assert (!state->compiling_verts, "glTexImage1D not allowed inside glBegin");
/* technically legal, but stupid! */
Assert (!state->compiling_list, "glTexImage1D inside glNewList");
Assert (width == to_pow2(width), "width must be a power of 2");
 
if (target == GL_TEXTURE_1D) target = GL_TEXTURE_2D;
jwzgles_glTexImage2D (target, level, internalFormat, width, 1,
border, format, type, data);
}
 
void
jwzgles_glTexImage2D (GLenum target,
GLint level,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *data)
{
GLvoid *d2 = (GLvoid *) data;
Assert (!state->compiling_verts, "glTexImage2D not allowed inside glBegin");
Assert (!state->compiling_list, /* technically legal, but stupid! */
"glTexImage2D not allowed inside glNewList");
 
// Assert (width == to_pow2(width), "width must be a power of 2");
// Assert (height == to_pow2(height), "height must be a power of 2");
 
/* OpenGLES no longer supports "4" as a synonym for "RGBA". */
switch (internalFormat) {
case 1: internalFormat = GL_LUMINANCE; break;
case 2: internalFormat = GL_LUMINANCE_ALPHA; break;
case 3: internalFormat = GL_RGB; break;
case 4: internalFormat = GL_RGBA; break;
}
 
/* GLES does not let us omit the data pointer to create a blank texture. */
if (! data)
{
d2 = (GLvoid *) calloc (1, width * height * sizeof(GLfloat) * 4);
Assert (d2, "out of memory");
}
 
if (internalFormat == GL_RGB && format == GL_RGBA)
internalFormat = GL_RGBA; /* WTF */
if (type == GL_UNSIGNED_INT_8_8_8_8_REV)
type = GL_UNSIGNED_BYTE;
 
if (! state->replaying_list)
LOG10 ("direct %-12s %s %d %s %d %d %d %s %s 0x%lX", "glTexImage2D",
mode_desc(target), level, mode_desc(internalFormat),
width, height, border, mode_desc(format), mode_desc(type),
(unsigned long) d2);
glTexImage2D (target, level, internalFormat, width, height, border,
format, type, d2); /* the real one */
CHECK("glTexImage2D");
 
if (d2 != data) free (d2);
}
 
void
jwzgles_glTexSubImage2D (GLenum target, GLint level,
GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height,
GLenum format, GLenum type,
const GLvoid *pixels)
{
Assert (!state->compiling_verts,
"glTexSubImage2D not allowed inside glBegin");
Assert (!state->compiling_list, /* technically legal, but stupid! */
"glTexSubImage2D not allowed inside glNewList");
 
if (! state->replaying_list)
LOG10 ("direct %-12s %s %d %d %d %d %d %s %s 0x%lX", "glTexSubImage2D",
mode_desc(target), level, xoffset, yoffset, width, height,
mode_desc (format), mode_desc (type), (unsigned long) pixels);
glTexSubImage2D (target, level, xoffset, yoffset, width, height,
format, type, pixels); /* the real one */
CHECK("glTexSubImage2D");
}
 
void
jwzgles_glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat,
GLint x, GLint y, GLsizei width, GLsizei height,
GLint border)
{
Assert (!state->compiling_verts,
"glCopyTexImage2D not allowed inside glBegin");
Assert (!state->compiling_list, /* technically legal, but stupid! */
"glCopyTexImage2D not allowed inside glNewList");
if (! state->replaying_list)
LOG9 ("direct %-12s %s %d %s %d %d %d %d %d", "glCopyTexImage2D",
mode_desc(target), level, mode_desc(internalformat),
x, y, width, height, border);
glCopyTexImage2D (target, level, internalformat, x, y, width, height,
border); /* the real one */
CHECK("glCopyTexImage2D");
}
 
 
/* OpenGLES doesn't have auto texture-generation at all!
"Oh, just rewrite that code to use GPU shaders", they say.
How fucking convenient.
*/
void
jwzgles_glTexGenfv (GLenum coord, GLenum pname, const GLfloat *params)
{
texgen_state *s = NULL;
 
if (pname == GL_TEXTURE_GEN_MODE)
LOG5 ("%sdirect %-12s %s %s %s",
(state->compiling_list || state->replaying_list ? " " : ""),
"glTexGenfv",
mode_desc(coord), mode_desc(pname), mode_desc(params[0]));
else
LOG8 ("%sdirect %-12s %s %s %3.1f %3.1f %3.1f %3.1f",
(state->compiling_list || state->replaying_list ? " " : ""),
"glTexGenfv",
mode_desc(coord), mode_desc(pname),
params[0], params[1], params[2], params[3]);
 
switch (coord) {
case GL_S: s = &state->s; break;
case GL_T: s = &state->t; break;
case GL_R: s = &state->r; break;
case GL_Q: s = &state->q; break;
default: Assert (0, "glGetTexGenfv: unknown coord"); break;
}
 
switch (pname) {
case GL_TEXTURE_GEN_MODE: s->mode = params[0]; break;
case GL_OBJECT_PLANE: memcpy (s->obj, params, sizeof(s->obj)); break;
case GL_EYE_PLANE: memcpy (s->eye, params, sizeof(s->eye)); break;
default: Assert (0, "glTexGenfv: unknown pname"); break;
}
}
 
void
jwzgles_glTexGeni (GLenum coord, GLenum pname, GLint param)
{
GLfloat v = param;
jwzgles_glTexGenfv (coord, pname, &v);
}
 
void
jwzgles_glGetTexGenfv (GLenum coord, GLenum pname, GLfloat *params)
{
texgen_state *s = NULL;
 
switch (coord) {
case GL_S: s = &state->s; break;
case GL_T: s = &state->t; break;
case GL_R: s = &state->r; break;
case GL_Q: s = &state->q; break;
default: Assert (0, "glGetTexGenfv: unknown coord"); break;
}
 
switch (pname) {
case GL_TEXTURE_GEN_MODE: params[0] = s->mode; break;
case GL_OBJECT_PLANE: memcpy (params, s->obj, sizeof(s->obj)); break;
case GL_EYE_PLANE: memcpy (params, s->eye, sizeof(s->eye)); break;
default: Assert (0, "glGetTexGenfv: unknown pname"); break;
}
 
if (pname == GL_TEXTURE_GEN_MODE)
LOG5 ("%sdirect %-12s %s %s -> %s",
(state->compiling_list || state->replaying_list ? " " : ""),
"glGetTexGenfv",
mode_desc(coord), mode_desc(pname), mode_desc(params[0]));
else
LOG8 ("%sdirect %-12s %s %s -> %3.1f %3.1f %3.1f %3.1f",
(state->compiling_list || state->replaying_list ? " " : ""),
"glGetTexGenfv",
mode_desc(coord), mode_desc(pname),
params[0], params[1], params[2], params[3]);
}
 
 
static GLfloat
dot_product (int rank, GLfloat *a, GLfloat *b)
{
/* A dot B => (A[1] * B[1]) + ... + (A[n] * B[n]) */
GLfloat ret = 0;
int i;
for (i = 0; i < rank; i++)
ret += a[i] * b[i];
return ret;
}
 
 
 
/* Compute the texture coordinates of the prevailing list of verts as per
http://www.opengl.org/wiki/Mathematics_of_glTexGen
*/
static void
generate_texture_coords (GLuint first, GLuint count)
{
GLfloat *tex_out, *tex_array;
GLsizei tex_stride;
GLuint i;
draw_array A = { 0, 0, 0, 0, 0, NULL};
char *verts_in;
 
struct { GLuint which, flag, mode; GLfloat plane[4]; } tg[4] = {
{ GL_S, ISENABLED_TEXTURE_GEN_S, 0, { 0, } },
{ GL_T, ISENABLED_TEXTURE_GEN_T, 0, { 0, } },
{ GL_R, ISENABLED_TEXTURE_GEN_R, 0, { 0, } },
{ GL_Q, ISENABLED_TEXTURE_GEN_Q, 0, { 0, }}};
int tcoords = 0;
 
/* Read the texture plane configs that were stored with glTexGen.
*/
for (i = 0; i < countof(tg); i++)
{
GLfloat mode = 0;
if (! ((state->compiling_list ? state->list_enabled : state->enabled)
& tg[i].flag))
continue;
jwzgles_glGetTexGenfv (tg[i].which, GL_TEXTURE_GEN_MODE, &mode);
jwzgles_glGetTexGenfv (tg[i].which, GL_OBJECT_PLANE, tg[i].plane);
tg[i].mode = mode;
tcoords++;
}
 
if (tcoords == 0) return; /* Nothing to do! */
 
 
/* Make the array to store our texture coords in. */
 
tex_stride = tcoords * sizeof(GLfloat);
tex_array = (GLfloat *) calloc (first + count, tex_stride);
tex_out = tex_array;
 
 
/* Read the prevailing vertex array, that was stored with
glVertexPointer or glInterleavedArrays.
*/
glGetIntegerv (GL_VERTEX_ARRAY_BUFFER_BINDING, &A.binding);
glGetIntegerv (GL_VERTEX_ARRAY_SIZE, &A.size);
glGetIntegerv (GL_VERTEX_ARRAY_TYPE, &A.type);
glGetIntegerv (GL_VERTEX_ARRAY_STRIDE, &A.stride);
glGetPointerv (GL_VERTEX_ARRAY_POINTER, &A.data);
A.bytes = count * A.stride;
 
verts_in = (char *) A.data;
 
/* Iterate over each vertex we're drawing.
We just skip the ones < start, but the tex array has
left room for zeroes there anyway.
*/
for (i = first; i < first + count; i++)
{
GLfloat vert[4] = { 0, };
int j, k;
 
/* Extract this vertex into `vert' as a float, whatever its type was. */
for (j = 0; j < A.size; j++)
{
switch (A.type) {
case GL_SHORT: vert[j] = ((GLshort *) verts_in)[j]; break;
case GL_INT: vert[j] = ((GLint *) verts_in)[j]; break;
case GL_FLOAT: vert[j] = ((GLfloat *) verts_in)[j]; break;
case GL_DOUBLE: vert[j] = ((GLdouble *) verts_in)[j]; break;
default: Assert (0, "unknown vertex type"); break;
}
}
 
/* Compute the texture coordinate for this vertex.
For GL_OBJECT_LINEAR, these coordinates are static, and can go
into the display list. But for GL_EYE_LINEAR, GL_SPHERE_MAP and
GL_REFLECTION_MAP, they depend on the prevailing ModelView matrix,
and so need to be computed afresh each time glDrawArrays is called.
Unfortunately, our verts and norms are gone by then, dumped down
into the VBO and discarded from CPU RAM. Bleh.
*/
for (j = 0, k = 0; j < countof(tg); j++)
{
if (! ((state->compiling_list ? state->list_enabled : state->enabled)
& tg[j].flag))
continue;
switch (tg[j].mode) {
case GL_OBJECT_LINEAR:
tex_out[k] = dot_product (4, vert, tg[j].plane);
break;
default:
Assert (0, "unimplemented texture mode");
break;
}
k++;
}
 
/* fprintf (stderr, "%4d: V %-5.1f %-5.1f %-5.1f T %-5.1f %-5.1f\n",
i, vert[0], vert[1], vert[2], tex_out[0], tex_out[1]); */
 
/* Move verts_in and tex_out forward to the next vertex by stride. */
verts_in += A.stride;
tex_out = (GLfloat *) (((char *) tex_out) + tex_stride);
}
 
jwzgles_glEnableClientState (GL_TEXTURE_COORD_ARRAY);
jwzgles_glTexCoordPointer (tcoords, GL_FLOAT, tex_stride,
(GLvoid *) tex_array);
free (tex_array);
}
 
 
int
jwzgles_gluBuild2DMipmaps (GLenum target,
GLint internalFormat,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const GLvoid *data)
{
/* Not really bothering with mipmapping; only making one level.
Note that this required a corresponding hack in glTexParameterf().
*/
 
int w2 = to_pow2(width);
int h2 = to_pow2(height);
 
void *d2 = (void *) data;
 
/* OpenGLES no longer supports "4" as a synonym for "RGBA". */
switch (internalFormat) {
case 1: internalFormat = GL_LUMINANCE; break;
case 2: internalFormat = GL_LUMINANCE_ALPHA; break;
case 3: internalFormat = GL_RGB; break;
case 4: internalFormat = GL_RGBA; break;
}
 
/* if (w2 < h2) w2 = h2;
if (h2 < w2) h2 = w2;*/
 
if (w2 != width || h2 != height)
{
/* Scale up the image bits to fit the power-of-2 texture.
We have to do this because the mipmap API assumes that
the texture bits go to texture coordinates 1.0 x 1.0.
This could be more efficient, but it doesn't happen often.
*/
int istride = (format == GL_RGBA ? 4 : 3);
int ostride = 4;
int ibpl = istride * width;
int obpl = ostride * w2;
int oy;
const unsigned char *in = (unsigned char *) data;
unsigned char *out = (unsigned char *) malloc (h2 * obpl);
Assert (out, "out of memory");
d2 = out;
 
for (oy = 0; oy < h2; oy++)
{
int iy = oy * height / h2;
const unsigned char *iline = in + (iy * ibpl);
unsigned char *oline = out + (oy * obpl);
int ox;
for (ox = 0; ox < w2; ox++)
{
int ix = ox * width / w2;
const unsigned char *i = iline + (ix * istride);
unsigned char *o = oline + (ox * ostride);
*o++ = *i++; /* R */
*o++ = *i++; /* G */
*o++ = *i++; /* B */
*o++ = (istride == 4 ? *i : 0xFF); /* A */
}
}
width = w2;
height = h2;
internalFormat = GL_RGBA;
format = GL_RGBA;
}
 
jwzgles_glTexImage2D (target, 0, internalFormat, w2, h2, 0,
format, type, d2);
if (d2 != data) free (d2);
 
return 0;
}
 
 
void
jwzgles_glRectf (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
{
jwzgles_glBegin (GL_POLYGON);
jwzgles_glVertex2f (x1, y1);
jwzgles_glVertex2f (x2, y1);
jwzgles_glVertex2f (x2, y2);
jwzgles_glVertex2f (x1, y2);
jwzgles_glEnd ();
}
 
void
jwzgles_glRecti (GLint x1, GLint y1, GLint x2, GLint y2)
{
jwzgles_glRectf (x1, y1, x2, y2);
}
 
/*
void
jwzgles_glClearDepth (GLfloat d)
{
/ * Not sure what to do here * /
Assert (d == 1.0, "glClearDepth unimplemented");
}
*/
 
 
/* When in immediate mode, we store a bit into state->enabled, and also
call the real glEnable() / glDisable().
 
When recording a list, we store a bit into state->list_enabled instead,
so that we can see what the prevailing enablement state will be when
the list is run.
 
set: 1 = set, -1 = clear, 0 = query.
*/
static int
enable_disable (GLuint bit, int set)
{
int result = (set > 0);
int omitp = 0;
int csp = 0;
unsigned long flag = 0;
 
switch (bit) {
case GL_TEXTURE_1D: /* We implement 1D textures as 2D textures. */
case GL_TEXTURE_2D: flag = ISENABLED_TEXTURE_2D; break;
case GL_TEXTURE_GEN_S: flag = ISENABLED_TEXTURE_GEN_S; omitp = 1; break;
case GL_TEXTURE_GEN_T: flag = ISENABLED_TEXTURE_GEN_T; omitp = 1; break;
case GL_TEXTURE_GEN_R: flag = ISENABLED_TEXTURE_GEN_R; omitp = 1; break;
case GL_TEXTURE_GEN_Q: flag = ISENABLED_TEXTURE_GEN_Q; omitp = 1; break;
case GL_LIGHTING: flag = ISENABLED_LIGHTING; break;
case GL_BLEND: flag = ISENABLED_BLEND; break;
case GL_DEPTH_TEST: flag = ISENABLED_DEPTH_TEST; break;
case GL_ALPHA_TEST: flag = ISENABLED_ALPHA_TEST; break;
case GL_CULL_FACE: flag = ISENABLED_CULL_FACE; break;
case GL_NORMALIZE: flag = ISENABLED_NORMALIZE; break;
case GL_FOG: flag = ISENABLED_FOG; break;
case GL_COLOR_MATERIAL: flag = ISENABLED_COLMAT; break;
 
/* Maybe technically these only work with glEnableClientState,
but we treat that as synonymous with glEnable. */
case GL_VERTEX_ARRAY: flag = ISENABLED_VERT_ARRAY; csp = 1; break;
case GL_NORMAL_ARRAY: flag = ISENABLED_NORM_ARRAY; csp = 1; break;
case GL_COLOR_ARRAY: flag = ISENABLED_COLOR_ARRAY; csp = 1; break;
case GL_TEXTURE_COORD_ARRAY: flag = ISENABLED_TEX_ARRAY; csp = 1; break;
 
default:
Assert (set != 0, "glIsEnabled unimplemented bit");
break;
}
 
if (set) /* setting or unsetting, not querying */
{
const char *fns[4] = { "glEnable", "glDisable",
"glEnableClientState", "glDisableClientState" };
list_fn_cb fs[4] = { (list_fn_cb) &jwzgles_glEnable,
(list_fn_cb) &jwzgles_glDisable,
(list_fn_cb) &jwzgles_glEnableClientState,
(list_fn_cb) &jwzgles_glDisableClientState };
const char *fn = fns[(csp ? 2 : 0) + (set < 0 ? 1 : 0)];
list_fn_cb f = fs[(csp ? 2 : 0) + (set < 0 ? 1 : 0)];
 
Assert (!state->compiling_verts,
"glEnable/glDisable not allowed inside glBegin");
 
if (state->compiling_list)
{
void_int vv[1];
vv[0].i = bit;
list_push (fn, f,PROTO_I, vv);
}
 
if (! state->replaying_list &&
! state->compiling_list)
LOG2 ("direct %-12s %s", fn, mode_desc(bit));
 
if (csp && !state->compiling_verts)
{
if (set > 0)
switch (bit) {
case GL_NORMAL_ARRAY: state->set.ncount += 2; break;
case GL_TEXTURE_COORD_ARRAY: state->set.tcount += 2; break;
case GL_COLOR_ARRAY: state->set.ccount += 2; break;
default: break;
}
else
switch (bit) {
case GL_NORMAL_ARRAY: state->set.ncount = 0; break;
case GL_TEXTURE_COORD_ARRAY: state->set.tcount = 0; break;
case GL_COLOR_ARRAY: state->set.ccount = 0; break;
default: break;
}
}
 
if (omitp || state->compiling_list)
;
else if (set > 0 && csp)
glEnableClientState (bit); /* the real one */
else if (set < 0 && csp)
glDisableClientState (bit); /* the real one */
else if (set > 0)
glEnable (bit); /* the real one */
else
glDisable (bit); /* the real one */
 
CHECK(fn);
}
 
/* Store the bit in our state as well, or query it.
*/
if (flag)
{
unsigned long *enabled = (state->compiling_list
? &state->list_enabled
: &state->enabled);
if (set > 0)
*enabled |= flag;
else if (set < 0)
*enabled &= ~flag;
else
result = !!(*enabled & flag);
}
 
return result;
}
 
 
void
jwzgles_glEnable (GLuint bit)
{
enable_disable (bit, 1);
}
 
void
jwzgles_glDisable (GLuint bit)
{
enable_disable (bit, -1);
}
 
GLboolean
jwzgles_glIsEnabled (GLuint bit)
{
return enable_disable (bit, 0);
}
 
void
jwzgles_glEnableClientState (GLuint cap)
{
enable_disable (cap, 1);
}
 
void
jwzgles_glDisableClientState (GLuint cap)
{
enable_disable (cap, -1);
}
 
 
 
/* The spec says that OpenGLES 1.x doesn't implement glGetFloatv.
Were this true, it would suck, for it would mean that there was no
way to retrieve the prevailing matrixes. To implement this, we'd
have to keep track of them all on the client side by combining in
all the actions of glMultMatrixf, glRotatef, etc.
 
However, Apple's iOS OpenGLES *does* provide glGetFloatv!
*/
void
jwzgles_glGetFloatv (GLenum pname, GLfloat *params)
{
if (! state->replaying_list)
LOG2 ("direct %-12s %s", "glGetFloatv", mode_desc(pname));
glGetFloatv (pname, params); /* the real one */
CHECK("glGetFloatv");
}
 
 
/* Likewise: not supposed to be there, but it is. */
void
jwzgles_glGetPointerv (GLenum pname, GLvoid *params)
{
if (! state->replaying_list)
LOG2 ("direct %-12s %s", "glGetPointerv", mode_desc(pname));
glGetPointerv (pname, (GLvoid **)params); /* the real one */
CHECK("glGetPointerv");
}
 
 
void jwzgles_glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
{
glReadPixels(x,y,width,height,format,type,pixels);
}
 
 
 
 
void jwzgles_glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
{
glCopyTexSubImage2D (target,level,xoffset,yoffset,x,y,width,height);
}
 
void jwzgles_glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
{
glDrawElements(mode, count, type, indices);
}
 
 
GLenum jwzgles_glGetError()
{
return glGetError();
}
const GLubyte * jwzgles_glGetString(GLenum name)
{
return glGetString(name);
}
 
 
 
 
 
/* How many cells are written into the *params array.
We need to know this to avoid smashing the caller's stack
if they asked for a single-value parameter.
*/
static int
glGet_ret_count (GLenum pname)
{
switch (pname) {
/*case GL_COLOR_MATRIX: */
case GL_MODELVIEW_MATRIX:
case GL_PROJECTION_MATRIX:
case GL_TEXTURE_MATRIX:
/*case GL_TRANSPOSE_COLOR_MATRIX: */
/*case GL_TRANSPOSE_MODELVIEW_MATRIX: */
/*case GL_TRANSPOSE_PROJECTION_MATRIX: */
/*case GL_TRANSPOSE_TEXTURE_MATRIX: */
return 16;
/*case GL_ACCUM_CLEAR_VALUE: */
/*case GL_BLEND_COLOR: */
case GL_COLOR_CLEAR_VALUE:
case GL_COLOR_WRITEMASK:
case GL_CURRENT_COLOR:
/*case GL_CURRENT_RASTER_COLOR: */
/*case GL_CURRENT_RASTER_POSITION: */
/*case GL_CURRENT_RASTER_SECONDARY_COLOR: */
/*case GL_CURRENT_RASTER_TEXTURE_COORDS: */
/*case GL_CURRENT_SECONDARY_COLOR: */
case GL_CURRENT_TEXTURE_COORDS:
case GL_FOG_COLOR:
case GL_LIGHT_MODEL_AMBIENT:
/*case GL_MAP2_GRID_DOMAIN: */
case GL_SCISSOR_BOX:
case GL_VIEWPORT:
return 4;
case GL_CURRENT_NORMAL:
case GL_POINT_DISTANCE_ATTENUATION:
return 3;
case GL_ALIASED_LINE_WIDTH_RANGE:
case GL_ALIASED_POINT_SIZE_RANGE:
case GL_DEPTH_RANGE:
/*case GL_LINE_WIDTH_RANGE: */
/*case GL_MAP1_GRID_DOMAIN: */
/*case GL_MAP2_GRID_SEGMENTS: */
case GL_MAX_VIEWPORT_DIMS:
/*case GL_POINT_SIZE_RANGE: */
case GL_POLYGON_MODE:
case GL_SMOOTH_LINE_WIDTH_RANGE:
case GL_SMOOTH_POINT_SIZE_RANGE:
return 2;
default:
return 1;
}
}
 
 
void
jwzgles_glGetDoublev (GLenum pname, GLdouble *params)
{
GLfloat m[16];
int i, j = glGet_ret_count (pname);
jwzgles_glGetFloatv (pname, m);
for (i = 0; i < j; i++)
params[i] = m[i];
}
 
 
void
jwzgles_glGetIntegerv (GLenum pname, GLint *params)
{
GLfloat m[16];
int i, j = glGet_ret_count (pname);
jwzgles_glGetFloatv (pname, m);
for (i = 0; i < j; i++)
params[i] = m[i];
}
 
 
void
jwzgles_glGetBooleanv (GLenum pname, GLboolean *params)
{
GLfloat m[16];
int i, j = glGet_ret_count (pname);
jwzgles_glGetFloatv (pname, m);
for (i = 0; i < j; i++)
params[i] = (m[i] != 0.0);
}
 
 
const char *
jwzgles_gluErrorString (GLenum error)
{
static char s[20];
sprintf (s, "0x%lX", (unsigned long) error);
return s;
}
 
 
/* These four *Pointer calls (plus glBindBuffer and glBufferData) can
be included inside glNewList, but they actually execute immediately
anyway, because their data is recorded in the list by the
subsequently-recorded call to glDrawArrays. This is a little weird.
*/
void
jwzgles_glVertexPointer (GLuint size, GLuint type, GLuint stride,
const GLvoid *ptr)
{
if (! state->replaying_list)
LOG5 ("direct %-12s %d %s %d 0x%lX", "glVertexPointer",
size, mode_desc(type), stride, (unsigned long) ptr);
glVertexPointer (size, type, stride, ptr); /* the real one */
CHECK("glVertexPointer");
}
 
 
void
jwzgles_glNormalPointer (GLuint type, GLuint stride, const GLvoid *ptr)
{
if (! state->replaying_list)
LOG4 ("direct %-12s %s %d 0x%lX", "glNormalPointer",
mode_desc(type), stride, (unsigned long) ptr);
glNormalPointer (type, stride, ptr); /* the real one */
CHECK("glNormalPointer");
}
 
void
jwzgles_glColorPointer (GLuint size, GLuint type, GLuint stride,
const GLvoid *ptr)
{
if (! state->replaying_list)
LOG5 ("direct %-12s %d %s %d 0x%lX", "glColorPointer",
size, mode_desc(type), stride, (unsigned long) ptr);
glColorPointer (size, type, stride, ptr); /* the real one */
CHECK("glColorPointer");
}
 
void
jwzgles_glTexCoordPointer (GLuint size, GLuint type, GLuint stride,
const GLvoid *ptr)
{
if (! state->replaying_list)
LOG5 ("direct %-12s %d %s %d 0x%lX", "glTexCoordPointer",
size, mode_desc(type), stride, (unsigned long) ptr);
glTexCoordPointer (size, type, stride, ptr); /* the real one */
CHECK("glTexCoordPointer");
}
 
void
jwzgles_glBindBuffer (GLuint target, GLuint buffer)
{
if (! state->replaying_list)
LOG3 ("direct %-12s %s %d", "glBindBuffer", mode_desc(target), buffer);
glBindBuffer (target, buffer); /* the real one */
CHECK("glBindBuffer");
}
 
void
jwzgles_glBufferData (GLenum target, GLsizeiptr size, const void *data,
GLenum usage)
{
if (! state->replaying_list)
LOG5 ("direct %-12s %s %ld 0x%lX %s", "glBufferData",
mode_desc(target), size, (unsigned long) data, mode_desc(usage));
glBufferData (target, size, data, usage); /* the real one */
CHECK("glBufferData");
}
 
 
void
jwzgles_glTexParameterf (GLuint target, GLuint pname, GLfloat param)
{
Assert (!state->compiling_verts,
"glTexParameterf not allowed inside glBegin");
 
/* We don't *really* implement mipmaps, so just turn this off. */
if (param == GL_LINEAR_MIPMAP_LINEAR) param = GL_LINEAR;
if (param == GL_NEAREST_MIPMAP_LINEAR) param = GL_LINEAR;
if (param == GL_LINEAR_MIPMAP_NEAREST) param = GL_NEAREST;
if (param == GL_NEAREST_MIPMAP_NEAREST) param = GL_NEAREST;
 
/* We implement 1D textures as 2D textures. */
if (target == GL_TEXTURE_1D) target = GL_TEXTURE_2D;
 
/* Apparently this is another invalid enum. Just ignore it. */
if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) &&
param == GL_CLAMP)
return;
 
if (state->compiling_list)
{
void_int vv[3];
vv[0].i = target;
vv[1].i = pname;
vv[2].f = param;
list_push ("glTexParameterf", (list_fn_cb) &jwzgles_glTexParameterf,
PROTO_IIF, vv);
}
else
{
if (! state->replaying_list)
LOG4 ("direct %-12s %s %s %7.3f", "glTexParameterf",
mode_desc(target), mode_desc(pname), param);
glTexParameterf (target, pname, param); /* the real one */
CHECK("glTexParameterf");
}
}
 
void
jwzgles_glTexParameteri (GLuint target, GLuint pname, GLuint param)
{
jwzgles_glTexParameterf (target, pname, param);
}
 
 
void
jwzgles_glBindTexture (GLuint target, GLuint texture)
{
Assert (!state->compiling_verts,
"glBindTexture not allowed inside glBegin");
 
/* We implement 1D textures as 2D textures. */
if (target == GL_TEXTURE_1D) target = GL_TEXTURE_2D;
 
if (state->compiling_list)
{
void_int vv[2];
vv[0].i = target;
vv[1].i = texture;
list_push ("glBindTexture", (list_fn_cb) &jwzgles_glBindTexture,
PROTO_II, vv);
}
 
/* Do it immediately as well, for generate_texture_coords */
/* else */
{
if (! state->replaying_list)
LOG3 ("direct %-12s %s %d", "glBindTexture",
mode_desc(target), texture);
glBindTexture (target, texture); /* the real one */
CHECK("glBindTexture");
}
}
 
 
 
/* Matrix functions, mostly cribbed from Mesa.
*/
 
void
jwzgles_glFrustum (GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat near, GLfloat far)
{
GLfloat const rlr = 1.f / (right - left);
GLfloat const tbr = 1.f / (top - bottom);
GLfloat const fnr = 1.f / (far - near);
 
GLfloat x = (2 * near) * rlr;
GLfloat a = (right + left) * rlr;
GLfloat y = (2 * near) * tbr;
GLfloat b = (top + bottom) * tbr;
GLfloat c = -(far + near) * fnr;
GLfloat d = -(2 * far * near) * fnr;
GLfloat m[16];
 
# define M(X,Y) m[Y * 4 + X]
M(0,0) = x; M(0,1) = 0; M(0,2) = a; M(0,3) = 0;
M(1,0) = 0; M(1,1) = y; M(1,2) = b; M(1,3) = 0;
M(2,0) = 0; M(2,1) = 0; M(2,2) = c; M(2,3) = d;
M(3,0) = 0; M(3,1) = 0; M(3,2) = -1; M(3,3) = 0;
# undef M
 
jwzgles_glMultMatrixf (m);
}
 
 
void
jwzgles_glOrtho (GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat near, GLfloat far)
{
GLfloat m[16];
GLfloat const rlr = 1.f/(right - left);
GLfloat a = 2 * rlr;
GLfloat b = -(right + left) * rlr;
GLfloat const tbr = 1.f/(top - bottom);
GLfloat c = 2 * tbr;
GLfloat d = -(top + bottom) * tbr;
GLfloat const fnr = 1.f/(far - near);
GLfloat e = -2 * fnr;
GLfloat f = -(far + near) * fnr;
 
# define M(X,Y) m[Y * 4 + X]
M(0,0) = a; M(0,1) = 0; M(0,2) = 0; M(0,3) = b;
M(1,0) = 0; M(1,1) = c; M(1,2) = 0; M(1,3) = d;
M(2,0) = 0; M(2,1) = 0; M(2,2) = e; M(2,3) = f;
M(3,0) = 0; M(3,1) = 0; M(3,2) = 0; M(3,3) = 1;
# undef M
 
jwzgles_glMultMatrixf (m);
}
 
 
void
jwzgles_gluPerspective (GLdouble fovy, GLdouble aspect,
GLdouble near, GLdouble far)
{
GLfloat m[16];
double si, co, dz;
double rad = fovy / 2 * M_PI / 180;
double a, b, c, d;
 
dz = far - near;
si = sin(rad);
if (dz == 0 || si == 0 || aspect == 0)
return;
co = cos(rad) / si;
 
a = co / aspect;
b = co;
c = -(far + near) / dz;
d = -2 * near * far / dz;
 
# define M(X,Y) m[Y * 4 + X]
M(0,0) = a; M(0,1) = 0; M(0,2) = 0; M(0,3) = 0;
M(1,0) = 0; M(1,1) = b; M(1,2) = 0; M(1,3) = 0;
M(2,0) = 0; M(2,1) = 0; M(2,2) = c; M(2,3) = d;
M(3,0) = 0; M(3,1) = 0; M(3,2) = -1; M(3,3) = 0;
# undef M
 
jwzgles_glMultMatrixf (m);
}
 
 
void
jwzgles_gluLookAt (GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz)
{
GLfloat m[16];
GLfloat x[3], y[3], z[3];
GLfloat mag;
/* Make rotation matrix */
/* Z vector */
z[0] = eyex - centerx;
z[1] = eyey - centery;
z[2] = eyez - centerz;
mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
if (mag) { /* mpichler, 19950515 */
z[0] /= mag;
z[1] /= mag;
z[2] /= mag;
}
/* Y vector */
y[0] = upx;
y[1] = upy;
y[2] = upz;
/* X vector = Y cross Z */
x[0] = y[1] * z[2] - y[2] * z[1];
x[1] = -y[0] * z[2] + y[2] * z[0];
x[2] = y[0] * z[1] - y[1] * z[0];
/* Recompute Y = Z cross X */
y[0] = z[1] * x[2] - z[2] * x[1];
y[1] = -z[0] * x[2] + z[2] * x[0];
y[2] = z[0] * x[1] - z[1] * x[0];
/* mpichler, 19950515 */
/* cross product gives area of parallelogram, which is < 1.0 for
* non-perpendicular unit-length vectors; so normalize x, y here
*/
mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
if (mag) {
x[0] /= mag;
x[1] /= mag;
x[2] /= mag;
}
mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
if (mag) {
y[0] /= mag;
y[1] /= mag;
y[2] /= mag;
}
#define M(row,col) m[col*4+row]
M(0, 0) = x[0]; M(0, 1) = x[1]; M(0, 2) = x[2]; M(0, 3) = 0.0;
M(1, 0) = y[0]; M(1, 1) = y[1]; M(1, 2) = y[2]; M(1, 3) = 0.0;
M(2, 0) = z[0]; M(2, 1) = z[1]; M(2, 2) = z[2]; M(2, 3) = 0.0;
M(3, 0) = 0.0; M(3, 1) = 0.0; M(3, 2) = 0.0; M(3, 3) = 1.0;
#undef M
 
jwzgles_glMultMatrixf(m);
/* Translate Eye to Origin */
jwzgles_glTranslatef(-eyex, -eyey, -eyez);
}
 
 
static void __gluMultMatrixVecd (const GLdouble matrix[16],
const GLdouble in[4],
GLdouble out[4])
{
int i;
 
for (i=0; i<4; i++) {
out[i] =
in[0] * matrix[0*4+i] +
in[1] * matrix[1*4+i] +
in[2] * matrix[2*4+i] +
in[3] * matrix[3*4+i];
}
}
 
GLint
jwzgles_gluProject (GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx, GLdouble *winy, GLdouble *winz)
{
GLdouble in[4];
GLdouble out[4];
 
/* #### I suspect this is not working right. I was seeing crazy values
in lament.c. Maybe there's some float-vs-double confusion going on?
*/
 
in[0]=objx;
in[1]=objy;
in[2]=objz;
in[3]=1.0;
__gluMultMatrixVecd(modelMatrix, in, out);
__gluMultMatrixVecd(projMatrix, out, in);
if (in[3] == 0.0) return(GL_FALSE);
in[0] /= in[3];
in[1] /= in[3];
in[2] /= in[3];
/* Map x, y and z to range 0-1 */
in[0] = in[0] * 0.5 + 0.5;
in[1] = in[1] * 0.5 + 0.5;
in[2] = in[2] * 0.5 + 0.5;
 
/* Map x,y to viewport */
in[0] = in[0] * viewport[2] + viewport[0];
in[1] = in[1] * viewport[3] + viewport[1];
 
*winx=in[0];
*winy=in[1];
*winz=in[2];
return(GL_TRUE);
}
 
 
void jwzgles_glViewport (GLuint x, GLuint y, GLuint w, GLuint h)
{
# if TARGET_IPHONE_SIMULATOR
/* fprintf (stderr, "glViewport %dx%d\n", w, h); */
# endif
glViewport (x, y, w, h); /* the real one */
}
 
 
/* The following functions are present in both OpenGL 1.1 and in OpenGLES 1,
but are allowed within glNewList/glEndList, so we must wrap them to allow
them to either be recorded in lists, or run directly.
 
All this CPP obscenity is me screaming in rage at all the ways that C is
not Lisp, as all I want to do here is DEFADVICE.
*/
 
#define PROTO_V PROTO_VOID
#define TYPE_V GLuint
#define ARGS_V void
#define VARS_V /* */
#define LOGS_V "\n"
#define FILL_V /* */
 
#define TYPE_I GLuint
#define TYPE_II TYPE_I
#define TYPE_III TYPE_I
#define TYPE_IIII TYPE_I
#define ARGS_I TYPE_I a
#define ARGS_II TYPE_I a, TYPE_I b
#define ARGS_III TYPE_I a, TYPE_I b, TYPE_I c
#define ARGS_IIII TYPE_I a, TYPE_I b, TYPE_I c, TYPE_I d
#define LOGS_I "%s\n", mode_desc(a)
#define LOGS_II "%s %d\n", mode_desc(a), b
#define LOGS_III "%s %s %s\n", mode_desc(a), mode_desc(b), mode_desc(c)
#define LOGS_IIII "%d %d %d %d\n", a, b, c, d
#define VARS_I a
#define VARS_II a, b
#define VARS_III a, b, c
#define VARS_IIII a, b, c, d
#define FILL_I vv[0].i = a;
#define FILL_II vv[0].i = a; vv[1].i = b;
#define FILL_III vv[0].i = a; vv[1].i = b; vv[2].i = c;
#define FILL_IIII vv[0].i = a; vv[1].i = b; vv[2].i = c; vv[3].i = d;
 
#define TYPE_F GLfloat
#define TYPE_FF TYPE_F
#define TYPE_FFF TYPE_F
#define TYPE_FFFF TYPE_F
#define ARGS_F TYPE_F a
#define ARGS_FF TYPE_F a, TYPE_F b
#define ARGS_FFF TYPE_F a, TYPE_F b, TYPE_F c
#define ARGS_FFFF TYPE_F a, TYPE_F b, TYPE_F c, TYPE_F d
#define LOGS_F "%7.3f\n", a
#define LOGS_FF "%7.3f %7.3f\n", a, b
#define LOGS_FFF "%7.3f %7.3f %7.3f\n", a, b, c
#define LOGS_FFFF "%7.3f %7.3f %7.3f %7.3f\n", a, b, c, d
#define VARS_F VARS_I
#define VARS_FF VARS_II
#define VARS_FFF VARS_III
#define VARS_FFFF VARS_IIII
#define FILL_F vv[0].f = a;
#define FILL_FF vv[0].f = a; vv[1].f = b;
#define FILL_FFF vv[0].f = a; vv[1].f = b; vv[2].f = c;
#define FILL_FFFF vv[0].f = a; vv[1].f = b; vv[2].f = c; vv[3].f = d;
 
#define ARGS_IF TYPE_I a, TYPE_F b
#define VARS_IF VARS_II
#define LOGS_IF "%s %7.3f\n", mode_desc(a), b
#define FILL_IF vv[0].i = a; vv[1].f = b;
 
#define ARGS_IIF TYPE_I a, TYPE_I b, TYPE_F c
#define VARS_IIF VARS_III
#define LOGS_IIF "%s %s %7.3f\n", mode_desc(a), mode_desc(b), c
#define FILL_IIF vv[0].i = a; vv[1].i = b; vv[2].f = c;
 
#define TYPE_IV GLint
#define ARGS_IIV TYPE_I a, const TYPE_IV *b
#define VARS_IIV VARS_II
#define LOGS_IIV "%s %d %d %d %d\n", mode_desc(a), b[0], b[1], b[2], b[3]
#define FILL_IIV vv[0].i = a; \
vv[1].i = b[0]; vv[2].i = b[1]; \
vv[3].i = b[2]; vv[4].i = b[3];
 
#define ARGS_IFV TYPE_I a, const TYPE_F *b
#define VARS_IFV VARS_II
#define LOGS_IFV "%s %7.3f %7.3f %7.3f %7.3f\n", mode_desc(a), \
b[0], b[1], b[2], b[3]
#define FILL_IFV vv[0].i = a; \
vv[1].f = b[0]; vv[2].f = b[1]; \
vv[3].f = b[2]; vv[4].f = b[3];
 
#define ARGS_IIIV TYPE_I a, TYPE_I b, const TYPE_IV *c
#define VARS_IIIV VARS_III
#define LOGS_IIIV "%s %-8s %3d %3d %3d %3d\n", mode_desc(a), mode_desc(b), \
c[0], c[1], c[2], c[3]
#define FILL_IIIV vv[0].i = a; vv[1].i = b; \
vv[2].i = c[0]; vv[3].i = c[1]; \
vv[4].i = c[2]; vv[5].i = c[3];
 
#define ARGS_IIFV TYPE_I a, TYPE_I b, const TYPE_F *c
#define VARS_IIFV VARS_III
#define LOGS_IIFV "%s %-8s %7.3f %7.3f %7.3f %7.3f\n", \
mode_desc(a), mode_desc(b), \
c[0], c[1], c[2], c[3]
#define FILL_IIFV vv[0].i = a; vv[1].i = b; \
vv[2].f = c[0]; vv[3].f = c[1]; \
vv[4].f = c[2]; vv[5].f = c[3];
 
#ifdef DEBUG
# define WLOG(NAME,ARGS) \
fprintf (stderr, "jwzgles: direct %-12s ", NAME); \
fprintf (stderr, ARGS)
#else
# define WLOG(NAME,ARGS) /* */
#endif
 
#define WRAP(NAME,SIG) \
void jwzgles_##NAME (ARGS_##SIG) \
{ \
Assert (!state->compiling_verts, \
STRINGIFY(NAME) " not allowed inside glBegin"); \
if (state->compiling_list) { \
void_int vv[10]; \
FILL_##SIG \
list_push (STRINGIFY(NAME), (list_fn_cb) &jwzgles_##NAME, \
PROTO_##SIG, vv); \
} else { \
if (! state->replaying_list) { \
WLOG (STRINGIFY(NAME), LOGS_##SIG); \
} \
NAME (VARS_##SIG); \
CHECK(STRINGIFY(NAME)); \
} \
}
 
WRAP (glActiveTexture, I)
WRAP (glAlphaFunc, IF)
WRAP (glBlendFunc, II)
WRAP (glClear, I)
WRAP (glClearColor, FFFF)
WRAP (glClearStencil, I)
WRAP (glColorMask, IIII)
WRAP (glCullFace, I)
WRAP (glDepthFunc, I)
WRAP (glDepthMask, I)
WRAP (glFinish, V)
WRAP (glFlush, V)
WRAP (glFogf, IF)
WRAP (glFogfv, IFV)
WRAP (glFrontFace, I)
WRAP (glHint, II)
WRAP (glLightModelf, IF)
WRAP (glLightModelfv, IFV)
WRAP (glLightf, IIF)
WRAP (glLightfv, IIFV)
WRAP (glLineWidth, F)
WRAP (glLoadIdentity, V)
WRAP (glLogicOp, I)
WRAP (glMatrixMode, I)
WRAP(glPixelStorei, II)
WRAP (glPointSize, F)
WRAP (glPolygonOffset, FF)
WRAP (glPopMatrix, V)
WRAP (glPushMatrix, V)
WRAP (glRotatef, FFFF)
WRAP (glScalef, FFF)
WRAP (glScissor, IIII)
WRAP (glShadeModel, I)
WRAP (glStencilFunc, III)
WRAP (glStencilMask, I)
WRAP (glStencilOp, III)
WRAP (glTexEnvf, IIF)
WRAP (glTexEnvi, III)
WRAP (glTranslatef, FFF)
#undef TYPE_IV
#define TYPE_IV GLuint
WRAP (glDeleteTextures, IIV)
 
 
#endif /* HAVE_JWZGLES - whole file */
/polymer/eduke32/source/android/android-jni.cpp
20,52 → 20,60
#include "s-setup/s-setup.h"
#endif
 
extern "C"
{
 
extern "C" {
#define DEFAULT_FADE_FRAMES 10
 
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
//This is a new function I put into SDL2, file SDL_androidgl.c
extern void SDL_Android_Init(JNIEnv *env, jclass cls);
// This is a new function I put into SDL2, file SDL_androidgl.c
extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void));
 
extern char const *G_GetStringFromSavegame(const char *filename, int type);
extern int32_t G_GetScreenshotFromSavegame(const char *filename, char *pal, char *data);
 
#include "in_android.h"
#include "../function.h"
 
#include "../GL/gl.h"
#include "../GL/nano_gl.h"
 
//Copied from build.h, which didnt include here
enum rendmode_t {
// Copied from build.h, which didnt include here
enum rendmode_t
{
REND_CLASSIC,
REND_POLYMOST = 3,
REND_POLYMER
};
 
enum dukeinv_t
{
GET_STEROIDS, // 0
GET_SHIELD,
GET_SCUBA,
GET_HOLODUKE,
GET_JETPACK,
GET_DUMMY1, // 5
GET_ACCESS,
GET_HEATS,
GET_DUMMY2,
GET_FIRSTAID,
GET_BOOTS, // 10
GET_MAX
};
 
 
#ifndef LOGI
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "DUKE", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "DUKE", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,"DUKE", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "DUKE", __VA_ARGS__))
#endif
 
#define REND_SOFT 0
#define REND_GL 1
#define REND_SOFT 0
#define REND_GL 1
 
droidsysinfo_t droidinfo;
 
static int curRenderer;
 
float gameControlsAlpha = 0.5;
 
static bool invertLook = false;
static bool precisionShoot = false;
static bool showSticks = true;
static bool hideTouchControls = true;
char toggleCrouch = true;
static bool selectLastWeap = true;
 
static bool shooting = false;
 
static int weaponWheelVisible = false;
 
 
72,21 → 80,23
static int controlsCreated = 0;
touchcontrols::TouchControlsContainer controlsContainer;
 
touchcontrols::TouchControls *tcBlankTap=0;
touchcontrols::TouchControls *tcYesNo=0;
touchcontrols::TouchControls *tcMenuMain=0;
touchcontrols::TouchControls *tcGameMain=0;
touchcontrols::TouchControls *tcGameWeapons=0;
//touchcontrols::TouchControls *tcInventory=0;
touchcontrols::TouchControls *tcAutomap=0;
touchcontrols::TouchControls *tcBlankTap = 0;
touchcontrols::TouchControls *tcYesNo = 0;
touchcontrols::TouchControls *tcMenuMain = 0;
touchcontrols::TouchControls *tcGameMain = 0;
touchcontrols::TouchControls *tcGameWeapons = 0;
// touchcontrols::TouchControls *tcInventory=0;
touchcontrols::TouchControls *tcAutomap = 0;
 
 
touchcontrols::TouchJoy *touchJoyLeft;
touchcontrols::WheelSelect *weaponWheel;
 
extern JNIEnv* env_;
JavaVM* jvm_;
extern JNIEnv *env_;
JavaVM *jvm_;
 
touchcontrols::Button *inv_buttons[GET_MAX];
 
void openGLStart()
{
if (curRenderer == REND_GL)
95,22 → 105,22
 
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof (0, droidinfo.screen_width, droidinfo.screen_height, 0, 0, 1);
glOrthof(0, droidinfo.screen_width, droidinfo.screen_height, 0, 0, 1);
 
//glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
//glClear(GL_COLOR_BUFFER_BIT);
//LOGI("openGLStart");
// glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT);
// LOGI("openGLStart");
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glEnable(GL_TEXTURE_2D);
glEnable (GL_BLEND);
glEnable(GL_BLEND);
 
glColor4f(1,1,1,1);
glColor4f(1, 1, 1, 1);
 
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY );
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
120,21 → 130,23
 
glMatrixMode(GL_MODELVIEW);
 
nanoPushState();
// nanoPushState();
}
else //software mode
/*
else // software mode
{
glDisable(GL_ALPHA_TEST);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY );
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable (GL_BLEND);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
}
*/
}
 
void openGLEnd()
141,15 → 153,17
{
if (curRenderer == REND_GL)
{
//glPopMatrix();
nanoPopState();
// glPopMatrix();
// nanoPopState();
glPopMatrix();
}
else// Software mode
/*
else // Software mode
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glMatrixMode(GL_MODELVIEW);
}
*/
}
 
void gameSettingsButton(int state)
160,8 → 174,9
}
}
 
//Because there is no Frame(), we need to check back to java each frame to see if the app hase paused
// Because there is no Frame(), we need to check back to java each frame to see if the app hase paused
 
/*
static jclass NativeLibClass = 0;
static jmethodID checkPauseMethod = 0;
 
169,32 → 184,34
{
if (NativeLibClass == 0)
{
NativeLibClass = env_->FindClass("com/beloko/duke/engine/NativeLib");
NativeLibClass = env_->FindClass("com/voidpoint/duke3d/engine/NativeLib");
checkPauseMethod = env_->GetStaticMethodID(NativeLibClass, "swapBuffers", "()V");
}
env_->CallStaticVoidMethod(NativeLibClass, checkPauseMethod);
}
*/
 
//This is a bit of a hack, if the weapon wheel was selected, then an inv chosen instead, we need to cancel the weapon selection
//NOT needed actually, weapon wheel disabled before is get finger up anyway
//static bool invWasSelected = false;
// This is a bit of a hack, if the weapon wheel was selected, then an inv chosen instead, we need to cancel the weapon
// selection
// NOT needed actually, weapon wheel disabled before is get finger up anyway
// static bool invWasSelected = false;
 
void showWeaponsInventory(bool show)
{
if (show)
{
for (int n=0; n<10; n++)
for (int n = 0; n < 10; n++)
{
weaponWheel->setSegmentEnabled(n, (PortableRead(READ_WEAPONS) >> n) & 0x1);
}
 
//Show inventory buttons
// Show inventory buttons
tcGameWeapons->setAllButtonsEnable(true);
 
tcGameWeapons->fade(touchcontrols::FADE_IN, 5); //fade in
tcGameWeapons->fade(touchcontrols::FADE_IN, 5); // fade in
weaponWheelVisible = true;
}
else //hide
else // hide
{
tcGameWeapons->setAllButtonsEnable(false);
weaponWheel->setTapMode(false);
206,75 → 223,80
{
switch (code)
{
case gamefunc_Fire:
shooting = state;
PortableAction(state, code);
break;
case gamefunc_Fire:
if (state && PortableRead(READ_SOMETHINGONPLAYER))
{
PortableAction(1, gamefunc_Quick_Kick);
PortableAction(0, gamefunc_Quick_Kick);
}
else PortableAction(state, code);
break;
 
case KEY_SHOW_KBRD:
if (state)
toggleKeyboard();
case KEY_SHOW_KBRD:
if (state)
toggleKeyboard();
 
PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0);
break;
PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0);
break;
 
case KEY_QUICK_CMD:
if (state == 1)
showCustomCommands();
break;
case KEY_QUICK_CMD:
if (state == 1)
showCustomCommands();
break;
 
case KEY_SHOW_INVEN:
if (state)
{
if (!weaponWheelVisible)
case KEY_SHOW_INVEN:
if (state)
{
weaponWheel->setTapMode(true);
showWeaponsInventory(true);
if (!weaponWheelVisible)
{
weaponWheel->setTapMode(true);
showWeaponsInventory(true);
}
else
showWeaponsInventory(false);
}
else
showWeaponsInventory(false);
}
break;
break;
 
case KEY_QUICK_SAVE:
LOGI("QUICK SAVE");
PortableKeyEvent(state, SDL_SCANCODE_F6, 0);
break;
case KEY_QUICK_SAVE:
LOGI("QUICK SAVE");
PortableKeyEvent(state, SDL_SCANCODE_F6, 0);
break;
 
case KEY_QUICK_LOAD:
LOGI("QUICK LOAD");
PortableKeyEvent(state, SDL_SCANCODE_F9, 0);
break;
case KEY_QUICK_LOAD:
LOGI("QUICK LOAD");
PortableKeyEvent(state, SDL_SCANCODE_F9, 0);
break;
 
default:
PortableAction(state, code);
break;
default: PortableAction(state, code); break;
}
}
 
void automapButton(int state,int code)
{
PortableAction(state,code);
}
void automapButton(int state, int code) { PortableAction(state, code); }
 
void inventoryButton(int state,int code)
void inventoryButton(int state, int code)
{
PortableAction(state,code);
PortableAction(state, code);
if (state == 0)
{
//Inventory chosen, hide them and wheel
// Inventory chosen, hide them and wheel
showWeaponsInventory(false);
}
}
 
void menuButton(int state,int code)
void menuButton(int state, int code) { PortableKeyEvent(state, code, code); }
 
void menuMouse(int action, float x, float y, float dx, float dy)
{
PortableKeyEvent(state, code,code);
// PortableMouse(dx,dy);
PortableMouseMenu(x * droidinfo.screen_width, y * droidinfo.screen_height);
 
if (action == MULTITOUCHMOUSE_DOWN || action == MULTITOUCHMOUSE_UP)
PortableMouseMenuButton(action == MULTITOUCHMOUSE_DOWN, 0);
}
 
void blankTapButton(int state,int code)
void blankTapButton(int state, int code)
{
if (PortableRead(READ_IS_DEAD)) //if the player is dead we need to send a 'open' button
if (PortableRead(READ_IS_DEAD)) // if the player is dead we need to send a 'open' button
{
if (state)
{
282,48 → 304,25
PortableAction(0, gamefunc_Open);
}
}
else //everything else send a return key
{
PortableKeyEvent(state, SDL_SCANCODE_RETURN,0);
}
 
else // everything else send a return key
PortableKeyEvent(state, SDL_SCANCODE_RETURN, 0);
}
 
void weaponWheelSelected(int enabled)
{
if (enabled)
{
showWeaponsInventory(true);
}
else
{
showWeaponsInventory(false);
}
}
void weaponWheelSelected(int enabled) { showWeaponsInventory(enabled ? true : false); }
 
void weaponWheelChosen(int segment)
{
// LOGI("weaponWheel %d",segment);
if (segment == -1 && droidinput.quickSelectWeapon)
segment = PortableRead(READ_LASTWEAPON);
 
//LOGI("weaponWheel %d",segment);
if (segment == -1) //Nothing was selected
{
if (selectLastWeap)
{
int32_t lw = PortableRead(READ_LASTWEAPON);
 
if (lw != -1)
PortableAction(2, gamefunc_Weapon_1 + lw);
}
}
else
{
if (segment != -1)
PortableAction(2, gamefunc_Weapon_1 + segment);
}
}
 
void left_double_tap(int state)
{
//LOGI("L double %d, droidinput.left_double_action = %d",state,droidinput.left_double_action);
// LOGI("L double %d, droidinput.left_double_action = %d",state,droidinput.left_double_action);
if (droidinput.left_double_action != -1)
PortableAction(state, droidinput.left_double_action);
}
330,7 → 329,7
 
void right_double_tap(int state)
{
//LOGTOUCH("R double %d",state);
// LOGTOUCH("R double %d",state);
if (droidinput.right_double_action != -1)
PortableAction(state, droidinput.right_double_action);
}
337,49 → 336,40
 
void mouseMove(int action, float x, float y, float dx, float dy)
{
//LOGI(" mouse dx = %f, dy = %f",dx,dy);
// LOGI(" mouse dx = %f, dy = %f",dx,dy);
if (weaponWheelVisible)
return;
 
double scale = (shooting && precisionShoot) ? PRECISIONSHOOTFACTOR : 1.f;
float const scale = .1f;
 
PortableLook(dx * droidinput.yaw_sens * scale,
-dy * droidinput.pitch_sens * scale * (invertLook ? -1.f : 1.f));
PortableLook(dx * droidinput.yaw_sens * scale, -dy * droidinput.pitch_sens * scale * (droidinput.invertLook ? -1.f : 1.f));
}
 
void automap_multitouch_mouse_move(int action,float x, float y,float dx, float dy)
void automap_multitouch_mouse_move(int action, float x, float y, float dx, float dy)
{
 
if (action == MULTITOUCHMOUSE_MOVE)
{
PortableAutomapControl(0,dx,dy);
}
PortableAutomapControl(0, dx, dy);
else if (action == MULTITOUCHMOUSE_ZOOM)
{
PortableAutomapControl(x,0,0);
}
PortableAutomapControl(x, 0, 0);
}
 
void left_stick(float joy_x, float joy_y, float mouse_x, float mouse_y)
{
//LOGI("left_stick joy_x = %f, joy_y = %f",joy_x,joy_y);
joy_x *=10;
float strafe = joy_x*joy_x;
//float strafe = joy_x;
if (joy_x < 0)
strafe *= -1;
 
PortableMove(joy_y * 15 * droidinput.forward_sens, -strafe * droidinput.strafe_sens);
// LOGI("left_stick joy_x = %f, joy_y = %f",joy_x,joy_y);
PortableMove(joy_y * droidinput.forward_sens, -joy_x * droidinput.strafe_sens);
}
 
/*
void right_stick(float joy_x, float joy_y, float mouse_x, float mouse_y)
{
mouseMove(0, joy_x, joy_y, mouse_x, mouse_y);
}
*/
 
void setHideSticks(bool v)
{
if (touchJoyLeft) touchJoyLeft->setHideGraphics(v);
if (touchJoyLeft)
touchJoyLeft->setHideGraphics(v);
}
 
void touchSettingsButton(int state)
395,12 → 385,12
*/
}
 
void initControls(int width, int height, const char * graphics_path, const char *settings_file)
void initControls(int width, int height, const char *graphics_path, const char *settings_file)
{
touchcontrols::GLScaleWidth = (float)width;
touchcontrols::GLScaleHeight = (float)height;
 
LOGI("initControls %d x %d,x path = %s, settings = %s",width,height,graphics_path,settings_file);
LOGI("initControls %d x %d,x path = %s, settings = %s", width, height, graphics_path, settings_file);
 
if (!controlsCreated)
{
408,156 → 398,173
 
touchcontrols::setGraphicsBasePath(graphics_path);
 
controlsContainer.openGL_start.connect( sigc::ptr_fun(&openGLStart));
controlsContainer.openGL_end.connect( sigc::ptr_fun(&openGLEnd));
controlsContainer.signal_settings.connect( sigc::ptr_fun(&touchSettingsButton));
controlsContainer.openGL_start.connect(sigc::ptr_fun(&openGLStart));
controlsContainer.openGL_end.connect(sigc::ptr_fun(&openGLEnd));
controlsContainer.signal_settings.connect(sigc::ptr_fun(&touchSettingsButton));
 
tcBlankTap = new touchcontrols::TouchControls("blank_tap", false, false);
tcYesNo = new touchcontrols::TouchControls("yes_no", false, false);
tcMenuMain = new touchcontrols::TouchControls("menu", false, false);
tcGameMain = new touchcontrols::TouchControls("game", false,true,1,true);
tcGameWeapons = new touchcontrols::TouchControls("weapons", false,true,1,false);
tcAutomap = new touchcontrols::TouchControls("automap", false,false);
tcBlankTap = new touchcontrols::TouchControls("blank_tap", false, false);
tcYesNo = new touchcontrols::TouchControls("yes_no", false, false);
tcMenuMain = new touchcontrols::TouchControls("menu", false, false);
tcGameMain = new touchcontrols::TouchControls("game", false, true, 1, true);
tcGameWeapons = new touchcontrols::TouchControls("weapons", false, true, 1, false);
tcAutomap = new touchcontrols::TouchControls("automap", false, false);
// tcInventory = new touchcontrols::TouchControls("inventory", false,true,1,false);
 
///////////////////////// BLANK TAP SCREEN //////////////////////
 
//One button on whole screen with no graphic, send a return key
tcBlankTap->addControl(new touchcontrols::Button("whole_screen", touchcontrols::RectF(0,0,26,16), std::string("test"), SDL_SCANCODE_RETURN));
tcBlankTap->signal_button.connect( sigc::ptr_fun(&blankTapButton) ); //Just reuse the menuButton function
// One button on whole screen with no graphic, send a return key
tcBlankTap->addControl(new touchcontrols::Button("whole_screen", touchcontrols::RectF(0, 0, 26, 16),
"" /*std::string("test")*/, SDL_SCANCODE_RETURN));
tcBlankTap->signal_button.connect(sigc::ptr_fun(&blankTapButton)); // Just reuse the menuButton function
 
 
 
///////////////////////// YES NO SCREEN /////////////////////
 
tcYesNo->addControl(new touchcontrols::Button("enter", touchcontrols::RectF(8,10,11,13), "yes", SDL_SCANCODE_RETURN));
tcYesNo->addControl(new touchcontrols::Button("esc", touchcontrols::RectF(14,10,17,13), "no", SDL_SCANCODE_ESCAPE));
tcYesNo->signal_button.connect( sigc::ptr_fun(&menuButton) ); //Just reuse the menuButton function
tcYesNo->addControl(
new touchcontrols::Button("enter", touchcontrols::RectF(16, 8, 19, 11), "yes", SDL_SCANCODE_RETURN));
tcYesNo->addControl(
new touchcontrols::Button("esc", touchcontrols::RectF(7, 8, 10, 11), "no", SDL_SCANCODE_ESCAPE));
tcYesNo->signal_button.connect(sigc::ptr_fun(&menuButton)); // Just reuse the menuButton function
 
 
 
///////////////////////// MAIN MENU SCREEN /////////////////////
 
//Menu
/* 3x3
tcMenuMain->addControl(new touchcontrols::Button("down_arrow", touchcontrols::RectF(20,13,23,16), "arrow_down", SDL_SCANCODE_DOWN, true)); //Repeating buttons
tcMenuMain->addControl(new touchcontrols::Button("up_arrow", touchcontrols::RectF(20,10,23,13), "arrow_up", SDL_SCANCODE_UP, true));
tcMenuMain->addControl(new touchcontrols::Button("left_arrow", touchcontrols::RectF(17,13,20,16), "arrow_left", SDL_SCANCODE_LEFT, true));
tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(23,13,26,16), "arrow_right", SDL_SCANCODE_RIGHT, true));
tcMenuMain->addControl(new touchcontrols::Button("enter", touchcontrols::RectF(0,13,3,16), "enter", SDL_SCANCODE_RETURN));
tcMenuMain->addControl(new touchcontrols::Button("esc", touchcontrols::RectF(0,10,3,13), "esc", SDL_SCANCODE_ESCAPE));
/*
tcMenuMain->addControl(new touchcontrols::Button("down_arrow", touchcontrols::RectF(22,14,24,16),
"arrow_down", SDL_SCANCODE_DOWN, true)); //Repeating buttons
tcMenuMain->addControl(new touchcontrols::Button("up_arrow", touchcontrols::RectF(22,12,24,14), "arrow_up",
SDL_SCANCODE_UP, true));
tcMenuMain->addControl(new touchcontrols::Button("left_arrow", touchcontrols::RectF(20,14,22,16),
"arrow_left", SDL_SCANCODE_LEFT, true));
tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(24,14,26,16),
"arrow_right", SDL_SCANCODE_RIGHT, true));
tcMenuMain->addControl(new touchcontrols::Button("enter", touchcontrols::RectF(0,14,2,16), "enter",
SDL_SCANCODE_RETURN));
tcMenuMain->addControl(new touchcontrols::Button("esc", touchcontrols::RectF(0,12,2,14), "esc",
SDL_SCANCODE_ESCAPE));
tcMenuMain->signal_button.connect( sigc::ptr_fun(&menuButton) );
tcMenuMain->setAlpha(1);
*/
 
tcMenuMain->addControl(new touchcontrols::Button("down_arrow", touchcontrols::RectF(22,14,24,16), "arrow_down", SDL_SCANCODE_DOWN, true)); //Repeating buttons
tcMenuMain->addControl(new touchcontrols::Button("up_arrow", touchcontrols::RectF(22,12,24,14), "arrow_up", SDL_SCANCODE_UP, true));
tcMenuMain->addControl(new touchcontrols::Button("left_arrow", touchcontrols::RectF(20,14,22,16), "arrow_left", SDL_SCANCODE_LEFT, true));
tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(24,14,26,16), "arrow_right", SDL_SCANCODE_RIGHT, true));
tcMenuMain->addControl(new touchcontrols::Button("enter", touchcontrols::RectF(0,14,2,16), "enter", SDL_SCANCODE_RETURN));
tcMenuMain->addControl(new touchcontrols::Button("esc", touchcontrols::RectF(0,12,2,14), "esc", SDL_SCANCODE_ESCAPE));
touchcontrols::MultitouchMouse *mouseMenu =
new touchcontrols::MultitouchMouse("mouse", touchcontrols::RectF(0, 0, 26, 16), "");
mouseMenu->setHideGraphics(true);
tcMenuMain->addControl(mouseMenu);
mouseMenu->signal_action.connect(sigc::ptr_fun(&menuMouse));
 
touchcontrols::Button *console_button = new touchcontrols::Button(
"keyboard", "Development console", touchcontrols::RectF(8, 0, 10, 2), "keyboard", KEY_SHOW_KBRD, false, true);
 
tcMenuMain->addControl(console_button);
 
tcMenuMain->signal_button.connect( sigc::ptr_fun(&menuButton) );
tcMenuMain->setAlpha(1);
 
 
 
//////////////////////////// GAME SCREEN /////////////////////
tcGameMain->setAlpha(gameControlsAlpha);
controlsContainer.editButtonAlpha = gameControlsAlpha;
tcGameMain->addControl(new touchcontrols::Button("use", touchcontrols::RectF(23,3,26,6), "use", gamefunc_Open));
tcGameMain->addControl(new touchcontrols::Button("attack", touchcontrols::RectF(20,7,23,10), "fire2", gamefunc_Fire));
tcGameMain->addControl(new touchcontrols::Button("jump", touchcontrols::RectF(23,6,26,9), "jump", gamefunc_Jump));
tcGameMain->addControl(new touchcontrols::Button("crouch", touchcontrols::RectF(24,12,26,14), "crouch", gamefunc_Crouch));
tcGameMain->addControl(new touchcontrols::Button("kick","Mighty Foot", touchcontrols::RectF(20,4,23,7), "boot", gamefunc_Quick_Kick,false,true));
tcGameMain->setAlpha(droidinput.gameControlsAlpha);
controlsContainer.editButtonAlpha = droidinput.gameControlsAlpha;
tcGameMain->addControl(
new touchcontrols::Button("use", touchcontrols::RectF(20, 4, 23, 7), "use", gamefunc_Open));
tcGameMain->addControl(
new touchcontrols::Button("attack", touchcontrols::RectF(20, 7, 23, 10), "fire2", gamefunc_Fire));
tcGameMain->addControl(
new touchcontrols::Button("jump", touchcontrols::RectF(23, 6, 26, 9), "jump", gamefunc_Jump));
tcGameMain->addControl(
new touchcontrols::Button("crouch", touchcontrols::RectF(24, 12, 26, 14), "crouch", gamefunc_Crouch));
tcGameMain->addControl(new touchcontrols::Button("kick", "Mighty Foot", touchcontrols::RectF(23, 3, 26, 6),
"boot", gamefunc_Quick_Kick, false, true));
 
tcGameMain->addControl(new touchcontrols::Button("quick_save","Quick Save", touchcontrols::RectF(22,0,24,2), "save", KEY_QUICK_SAVE,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_load","Quick Load", touchcontrols::RectF(20,0,22,2), "load", KEY_QUICK_LOAD,false,true));
touchcontrols::Button *map_button = new touchcontrols::Button("map","Autotmap", touchcontrols::RectF(6,0,8,2), "map", gamefunc_Map, false,true);
touchcontrols::Button *map_button = new touchcontrols::Button(
"map", "Overhead map", touchcontrols::RectF(6, 0, 8, 2), "map", gamefunc_Map, false, true);
tcGameMain->addControl(map_button);
tcGameMain->addControl(new touchcontrols::Button("keyboard","Show Console", touchcontrols::RectF(8,0,10,2), "keyboard", KEY_SHOW_KBRD, false,true));
tcGameMain->addControl(new touchcontrols::Button("show_inventory", "Inventory",
touchcontrols::RectF(24, 0, 26, 2), "inv", KEY_SHOW_INVEN));
tcGameMain->addControl(new touchcontrols::Button("next_weapon", "Next weapon", touchcontrols::RectF(0, 3, 3, 5),
"next_weap", gamefunc_Next_Weapon, false, true));
tcGameMain->addControl(new touchcontrols::Button("prev_weapon", "Previous weapon",
touchcontrols::RectF(0, 5, 3, 7), "prev_weap",
gamefunc_Previous_Weapon, false, true));
tcGameMain->addControl(new touchcontrols::Button("quick_save", "Save game", touchcontrols::RectF(22, 0, 24, 2),
"save", KEY_QUICK_SAVE, false, true));
tcGameMain->addControl(new touchcontrols::Button("quick_load", "Load game", touchcontrols::RectF(20, 0, 22, 2),
"load", KEY_QUICK_LOAD, false, true));
 
tcGameMain->addControl(new touchcontrols::Button("show_inventory","Show Inventory",touchcontrols::RectF(24,0,26,2), "inv", KEY_SHOW_INVEN));
 
tcGameMain->addControl(new touchcontrols::Button("next_weapon","Next Weapon", touchcontrols::RectF(0,3,3,5), "next_weap",gamefunc_Next_Weapon,false,true));
tcGameMain->addControl(new touchcontrols::Button("prev_weapon","Previous Weapon", touchcontrols::RectF(0,5,3,7), "prev_weap",gamefunc_Previous_Weapon,false,true));
tcGameMain->addControl(console_button);
/*
//quick actions binds
tcGameMain->addControl(new touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_4",touchcontrols::RectF(10,3,12,5),"quick_key_4",KEY_QUICK_KEY4,false,true));
//quick actions binds
tcGameMain->addControl(new
touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true));
tcGameMain->addControl(new
touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,false,true));
tcGameMain->addControl(new
touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,false,true));
tcGameMain->addControl(new
touchcontrols::Button("quick_key_4",touchcontrols::RectF(10,3,12,5),"quick_key_4",KEY_QUICK_KEY4,false,true));
*/
//Left stick
touchJoyLeft = new touchcontrols::TouchJoy("stick",touchcontrols::RectF(0,7,8,16),"strafe_arrow");
// Left stick
touchJoyLeft = new touchcontrols::TouchJoy("stick", touchcontrols::RectF(0, 7, 8, 16), "strafe_arrow");
tcGameMain->addControl(touchJoyLeft);
touchJoyLeft->signal_move.connect(sigc::ptr_fun(&left_stick) );
touchJoyLeft->signal_double_tap.connect(sigc::ptr_fun(&left_double_tap) );
touchJoyLeft->signal_move.connect(sigc::ptr_fun(&left_stick));
touchJoyLeft->signal_double_tap.connect(sigc::ptr_fun(&left_double_tap));
 
//Right stick (not used)
//touchJoyRight = new touchcontrols::TouchJoy("touch",touchcontrols::RectF(17,7,26,16),"look_arrow");
//tcGameMain->addControl(touchJoyRight);
//touchJoyRight->signal_move.connect(sigc::ptr_fun(&right_stick) );
//touchJoyRight->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) );
//touchJoyRight->setEnabled(false);
// Right stick (not used)
// touchJoyRight = new touchcontrols::TouchJoy("touch",touchcontrols::RectF(17,7,26,16),"look_arrow");
// tcGameMain->addControl(touchJoyRight);
// touchJoyRight->signal_move.connect(sigc::ptr_fun(&right_stick) );
// touchJoyRight->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) );
// touchJoyRight->setEnabled(false);
 
 
//Mouse look for whole screen
touchcontrols::Mouse *mouse = new touchcontrols::Mouse("mouse",touchcontrols::RectF(3,0,26,16),"");
// Mouse look for whole screen
touchcontrols::Mouse *mouse = new touchcontrols::Mouse("mouse", touchcontrols::RectF(3, 0, 26, 16), "");
mouse->signal_action.connect(sigc::ptr_fun(&mouseMove));
mouse->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) );
mouse->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap));
 
mouse->setHideGraphics(true);
tcGameMain->addControl(mouse);
 
tcGameMain->signal_button.connect( sigc::ptr_fun(&gameButton) );
tcGameMain->signal_settingsButton.connect( sigc::ptr_fun(&gameSettingsButton) );
tcGameMain->signal_button.connect(sigc::ptr_fun(&gameButton));
tcGameMain->signal_settingsButton.connect(sigc::ptr_fun(&gameSettingsButton));
 
///////////////////////// AUTO MAP SCREEN ///////////////////////
 
 
//Automap
touchcontrols::MultitouchMouse *multimouse = new touchcontrols::MultitouchMouse("gamemouse",touchcontrols::RectF(0,0,26,16),"");
// Automap
touchcontrols::MultitouchMouse *multimouse =
new touchcontrols::MultitouchMouse("gamemouse", touchcontrols::RectF(0, 0, 26, 16), "");
multimouse->setHideGraphics(true);
tcAutomap->addControl(multimouse);
multimouse->signal_action.connect(sigc::ptr_fun(&automap_multitouch_mouse_move) );
multimouse->signal_action.connect(sigc::ptr_fun(&automap_multitouch_mouse_move));
tcAutomap->addControl(map_button);
tcAutomap->signal_button.connect( sigc::ptr_fun(&gameButton) );
tcAutomap->signal_button.connect(sigc::ptr_fun(&gameButton));
tcAutomap->setAlpha(0.5);
 
// Now inventory in the weapons control group!
 
inv_buttons[GET_JETPACK] = new touchcontrols::Button("jetpack", touchcontrols::RectF(0, 3, 2, 5), "jetpack",
gamefunc_Jetpack, false, false, true);
inv_buttons[GET_FIRSTAID] = new touchcontrols::Button("medkit", touchcontrols::RectF(0, 5, 2, 7), "medkit",
gamefunc_MedKit, false, false, true);
inv_buttons[GET_HEATS] = new touchcontrols::Button("nightv", touchcontrols::RectF(0, 7, 2, 9), "nightvision",
gamefunc_NightVision, false, false, true);
inv_buttons[GET_HOLODUKE] = new touchcontrols::Button("holoduke", touchcontrols::RectF(0, 9, 2, 11), "holoduke",
gamefunc_Holo_Duke, false, false, true);
inv_buttons[GET_STEROIDS] = new touchcontrols::Button("steroids", touchcontrols::RectF(0, 11, 2, 13),
"steroids", gamefunc_Steroids, false, false, true);
 
tcGameWeapons->addControl(inv_buttons[GET_JETPACK]);
tcGameWeapons->addControl(inv_buttons[GET_FIRSTAID]);
tcGameWeapons->addControl(inv_buttons[GET_HEATS]);
tcGameWeapons->addControl(inv_buttons[GET_HOLODUKE]);
tcGameWeapons->addControl(inv_buttons[GET_STEROIDS]);
// Inventory are the only buttons so safe to do this
tcGameWeapons->signal_button.connect(sigc::ptr_fun(&inventoryButton));
 
 
//Now inventory in the weapons control group!
tcGameWeapons->addControl(new touchcontrols::Button("jetpack", touchcontrols::RectF(0,3,2,5),"jetpack",gamefunc_Jetpack,false,false,true));
tcGameWeapons->addControl(new touchcontrols::Button("medkit", touchcontrols::RectF(0,5,2,7),"medkit",gamefunc_MedKit,false,false,true));
tcGameWeapons->addControl(new touchcontrols::Button("nightv", touchcontrols::RectF(0,7,2,9),"nightvision",gamefunc_NightVision,false,false,true));
tcGameWeapons->addControl(new touchcontrols::Button("holoduke",touchcontrols::RectF(0,9,2,11),"holoduke",gamefunc_Holo_Duke,false,false,true));
tcGameWeapons->addControl(new touchcontrols::Button("steroids",touchcontrols::RectF(0,11,2,13),"steroids",gamefunc_Steroids,false,false,true));
//Inventory are the only buttons so safe to do this
tcGameWeapons->signal_button.connect( sigc::ptr_fun(&inventoryButton) );
 
 
//Weapons
weaponWheel = new touchcontrols::WheelSelect("weapon_wheel",touchcontrols::RectF(7,2,19,14),"weapon_wheel_orange_blank",10);
weaponWheel->signal_selected.connect(sigc::ptr_fun(&weaponWheelChosen) );
// Weapons
weaponWheel = new touchcontrols::WheelSelect("weapon_wheel", touchcontrols::RectF(7, 2, 19, 14),
"weapon_wheel_orange_blank", 10);
weaponWheel->signal_selected.connect(sigc::ptr_fun(&weaponWheelChosen));
weaponWheel->signal_enabled.connect(sigc::ptr_fun(&weaponWheelSelected));
tcGameWeapons->addControl(weaponWheel);
tcGameWeapons->setAlpha(0.9);
 
/*
tcInventory->addControl(new touchcontrols::Button("jetpack", touchcontrols::RectF(0,3,2,5),"jetpack",gamefunc_Jetpack));
tcInventory->addControl(new touchcontrols::Button("medkit", touchcontrols::RectF(0,5,2,7),"medkit",gamefunc_MedKit));
tcInventory->addControl(new touchcontrols::Button("nightv", touchcontrols::RectF(0,7,2,9),"nightvision",gamefunc_NightVision));
tcInventory->addControl(new touchcontrols::Button("holoduke",touchcontrols::RectF(0,9,2,11),"holoduke",gamefunc_Holo_Duke));
tcInventory->addControl(new touchcontrols::Button("steroids",touchcontrols::RectF(0,11,2,13),"steroids",gamefunc_Steroids));
tcInventory->setAlpha(1);
 
tcInventory->signal_button.connect( sigc::ptr_fun(&inventoryButton));
*/
 
 
/////////////////////////////////////////////////////////////
 
 
570,15 → 577,15
controlsContainer.addControlGroup(tcBlankTap);
controlsCreated = 1;
 
tcGameMain->setAlpha(gameControlsAlpha);
controlsContainer.editButtonAlpha = gameControlsAlpha;
tcGameWeapons->setAlpha(gameControlsAlpha);
tcMenuMain->setAlpha(gameControlsAlpha);
tcGameMain->setAlpha(droidinput.gameControlsAlpha);
controlsContainer.editButtonAlpha = droidinput.gameControlsAlpha;
tcGameWeapons->setAlpha(droidinput.gameControlsAlpha);
tcMenuMain->setAlpha(droidinput.gameControlsAlpha);
 
 
tcGameMain->setXMLFile((std::string)graphics_path + "/game.xml");
tcGameWeapons->setXMLFile((std::string)graphics_path + "/weapons.xml");
tcAutomap->setXMLFile((std::string)graphics_path + "/automap.xml");
tcGameMain->setXMLFile((std::string)graphics_path + "/game.xml");
tcGameWeapons->setXMLFile((std::string)graphics_path + "/weapons.xml");
tcAutomap->setXMLFile((std::string)graphics_path + "/automap.xml");
// tcInventory->setXMLFile((std::string)graphics_path + "/inventory.xml");
 
setControlsContainer(&controlsContainer);
586,7 → 593,7
else
LOGI("NOT creating controls");
 
//controlsContainer.initGL();
// controlsContainer.initGL();
}
 
void updateTouchScreenMode(touchscreemode_t mode)
593,80 → 600,77
{
// LOGI("updateTouchScreenModeA %d",mode);
 
static touchscreemode_t lastMode = TOUCH_SCREEN_BLANK;
static touchscreemode_t lastMode = TOUCH_SCREEN_BLANK;
 
if (mode != lastMode)
{
// first disable the last screen and fade out is necessary
switch (lastMode)
{
case TOUCH_SCREEN_BLANK: // Does not exist yet break;
case TOUCH_SCREEN_BLANK_TAP:
tcBlankTap->resetOutput();
tcBlankTap->setEnabled(false); // Dont fade out as no graphics
break;
case TOUCH_SCREEN_YES_NO:
tcYesNo->resetOutput();
tcYesNo->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_MENU:
tcMenuMain->resetOutput();
tcMenuMain->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_GAME:
tcGameMain->resetOutput();
 
if (mode != lastMode){
 
//first disable the last screen and fade out is necessary
switch(lastMode){
case TOUCH_SCREEN_BLANK:
//Does not exist yet
break;
case TOUCH_SCREEN_BLANK_TAP:
tcBlankTap->resetOutput();
tcBlankTap->setEnabled(false); //Dont fade out as no graphics
break;
case TOUCH_SCREEN_YES_NO:
tcYesNo->resetOutput();
tcYesNo->fade(touchcontrols::FADE_OUT,DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_MENU:
tcMenuMain->resetOutput();
tcMenuMain->fade(touchcontrols::FADE_OUT,DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_GAME:
tcGameMain->resetOutput();
 
tcGameMain->fade(touchcontrols::FADE_OUT,DEFAULT_FADE_FRAMES);
tcGameWeapons->setEnabled(false);
 
break;
case TOUCH_SCREEN_AUTOMAP:
tcAutomap->resetOutput();
tcAutomap->fade(touchcontrols::FADE_OUT,DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_CONSOLE:
break;
tcGameMain->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES);
tcGameWeapons->setEnabled(false);
break;
case TOUCH_SCREEN_AUTOMAP:
tcAutomap->resetOutput();
tcAutomap->fade(touchcontrols::FADE_OUT, DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_CONSOLE: break;
}
 
//Enable the current new screen
switch(mode){
case TOUCH_SCREEN_BLANK:
//Does not exist yet
break;
case TOUCH_SCREEN_BLANK_TAP:
tcBlankTap->setEnabled(true);
break;
case TOUCH_SCREEN_YES_NO:
tcYesNo->setEnabled(true);
tcYesNo->fade(touchcontrols::FADE_IN,DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_MENU:
tcMenuMain->setEnabled(true);
tcMenuMain->fade(touchcontrols::FADE_IN,DEFAULT_FADE_FRAMES);
// Enable the current new screen
switch (mode)
{
case TOUCH_SCREEN_BLANK: // Does not exist yet break;
case TOUCH_SCREEN_BLANK_TAP: tcBlankTap->setEnabled(true); break;
case TOUCH_SCREEN_YES_NO:
tcYesNo->setEnabled(true);
tcYesNo->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_MENU:
tcMenuMain->setEnabled(true);
tcMenuMain->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES);
 
//This is a bit of a hack, we need to enable the inventory buttons so they can be edited, they will not be seen anyway
showWeaponsInventory(true);
break;
case TOUCH_SCREEN_GAME:
tcGameMain->setEnabled(true);
tcGameMain->fade(touchcontrols::FADE_IN,DEFAULT_FADE_FRAMES);
tcGameWeapons->setEnabled(true);
showWeaponsInventory(false);
break;
case TOUCH_SCREEN_AUTOMAP:
tcAutomap->setEnabled(true);
tcAutomap->fade(touchcontrols::FADE_IN,DEFAULT_FADE_FRAMES);
 
break;
case TOUCH_SCREEN_CONSOLE:
break;
// This is a bit of a hack, we need to enable the inventory buttons so they can be edited, they will not
// be seen anyway
showWeaponsInventory(true);
break;
case TOUCH_SCREEN_GAME:
tcGameMain->setEnabled(true);
tcGameMain->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES);
tcGameWeapons->setEnabled(true);
showWeaponsInventory(false);
break;
case TOUCH_SCREEN_AUTOMAP:
tcAutomap->setEnabled(true);
tcAutomap->fade(touchcontrols::FADE_IN, DEFAULT_FADE_FRAMES);
break;
case TOUCH_SCREEN_CONSOLE: break;
}
 
lastMode = mode;
}
 
int inv = PortableRead(READ_INVENTORY);
 
for (int i = 0; i < GET_MAX; ++i)
if (inv_buttons[i])
inv_buttons[i]->setAlpha(tcGameWeapons->getFadedAlpha() * ((inv & (1 << i)) ? 1.f : 0.3f));
}
 
 
675,27 → 679,46
#include "s-setup/gp_lic_include.h"
#endif
 
extern char videomodereset;
extern int mobile_halted;
 
void frameControls()
{
if (mobile_halted) return;
 
static int loadedGLImages = 0;
 
LOGI("frameControls");
if (videomodereset)
{
loadedGLImages = -1;
return;
}
 
// We need to do this here now because duke loads a new gl context
 
//We need to do this here now because duke loads a new gl context
if (!loadedGLImages)
if (loadedGLImages <= 0)
{
controlsContainer.initGL();
controlsContainer.initGL(loadedGLImages == -1);
loadedGLImages = 1;
}
 
//LOGI("frameControls");
// LOGI("frameControls");
 
curRenderer = (PortableRead(READ_RENDERER) != REND_CLASSIC);
 
updateTouchScreenMode((touchscreemode_t)PortableRead(READ_SCREEN_MODE));
 
setHideSticks(droidinput.hideStick);
 
setHideSticks(!showSticks);
if (tcGameMain)
{
tcGameMain->setAlpha(droidinput.gameControlsAlpha);
controlsContainer.editButtonAlpha = droidinput.gameControlsAlpha;
tcGameWeapons->setAlpha(droidinput.gameControlsAlpha);
tcMenuMain->setAlpha(droidinput.gameControlsAlpha);
// tcInventory->setAlpha(droidinput.gameControlsAlpha);
}
 
controlsContainer.draw();
 
#ifdef GP_LIC
703,64 → 726,37
#define GP_LIC_INC 2
#include "s-setup/gp_lic_include.h"
#endif
 
}
 
void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other)
void setTouchSettings(int other)
{
 
gameControlsAlpha = MINCONTROLALPHA + (alpha * (1.0f - MINCONTROLALPHA));
 
if (tcGameMain)
{
tcGameMain->setAlpha(gameControlsAlpha);
controlsContainer.editButtonAlpha = gameControlsAlpha;
tcGameWeapons->setAlpha(gameControlsAlpha);
tcMenuMain->setAlpha(gameControlsAlpha);
// tcInventory->setAlpha(gameControlsAlpha);
}
 
// TODO: defined names for these values
selectLastWeap = other & 0x1 ? true : false;
toggleCrouch = other & 0x2 ? true : false;
invertLook = other & 0x4 ? true : false;
precisionShoot = other & 0x8 ? true : false;
showSticks = other & 0x1000 ? true : false;
 
hideTouchControls = other & 0x80000000 ? true : false;
 
int doubletap_options[6] = {0,gamefunc_Fire,gamefunc_Jump,gamefunc_Quick_Kick,gamefunc_MedKit,gamefunc_Jetpack};
// keep in sync with Duke3d/res/values/strings.xml
int doubletap_options[5] = { -1, gamefunc_Quick_Kick, gamefunc_AutoRun, gamefunc_MedKit, gamefunc_Jetpack };
 
droidinput.left_double_action = doubletap_options[((other>>4) & 0xF)];
droidinput.right_double_action = doubletap_options[((other>>8) & 0xF)];
droidinput.left_double_action = doubletap_options[((other >> 4) & 0xF)];
droidinput.right_double_action = doubletap_options[((other >> 8) & 0xF)];
 
 
droidinput.strafe_sens = strafe;
droidinput.forward_sens = fwd;
droidinput.pitch_sens = pitch;
droidinput.yaw_sens = yaw;
 
LOGI("setTouchSettings alpha = %f, left_double_action = %d",alpha,droidinput.left_double_action);
LOGI("setTouchSettings left_double_action = %d", droidinput.left_double_action);
}
 
#define EXPORT_ME __NDK_FPABI__ __attribute__ ((visibility("default")))
#define EXPORT_ME __NDK_FPABI__ __attribute__((visibility("default")))
 
JNIEnv* env_;
JNIEnv *env_;
 
int argc=1;
const char * argv[32];
int argc = 1;
const char *argv[32];
std::string graphicpath;
std::string doom_path;
std::string duke3d_path;
 
static const char * getGamePath()
{
return doom_path.c_str();
}
static inline const char *getGamePath() { return duke3d_path.c_str(); }
 
 
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
jobject thiz,jstring graphics_dir,jint audio_rate,jint audio_buffer_size,jobjectArray argsArray,jint renderer,jstring doom_path_ )
jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_init(JNIEnv *env, jobject thiz, jstring graphics_dir,
jint audio_rate, jint audio_buffer_size,
jobjectArray argsArray, jint renderer,
jstring jduke3d_path)
{
env_ = env;
 
771,53 → 767,38
droidinfo.audio_sample_rate = audio_rate;
droidinfo.audio_buffer_size = audio_buffer_size;
 
curRenderer = renderer;
//curRenderer = REND_SOFT;
// curRenderer = renderer;
curRenderer = REND_GL;
 
argv[0] = "eduke32";
int argCount = (env)->GetArrayLength( argsArray);
LOGI("argCount = %d",argCount);
for (int i=0; i<argCount; i++) {
jstring string = (jstring) (env)->GetObjectArrayElement( argsArray, i);
argv[argc] = (char *)(env)->GetStringUTFChars( string, 0);
LOGI("arg = %s",argv[argc]);
int argCount = (env)->GetArrayLength(argsArray);
LOGI("argCount = %d", argCount);
for (int i = 0; i < argCount; i++)
{
jstring string = (jstring)(env)->GetObjectArrayElement(argsArray, i);
argv[argc] = (char *)(env)->GetStringUTFChars(string, 0);
LOGI("arg = %s", argv[argc]);
argc++;
}
 
doom_path = (char *)(env)->GetStringUTFChars( doom_path_, 0);
duke3d_path = (char *)(env)->GetStringUTFChars(jduke3d_path, 0);
 
//Change working dir, save games etc
// Change working dir, save games etc
// FIXME: potentially conflicts with chdirs in -game_dir support
chdir(getGamePath());
char timidity_env[512];
 
sprintf(timidity_env,"TIMIDITY_CFG=%s/../timidity.cfg",getGamePath());
//putenv("TIMIDITY_CFG=../timidity.cfg");
sprintf(timidity_env, "TIMIDITY_CFG=%s/../timidity.cfg", getGamePath());
putenv(timidity_env);
 
LOGI("doom_path = %s",getGamePath());
LOGI("duke3d_path = %s", getGamePath());
 
const char * p = env->GetStringUTFChars(graphics_dir,NULL);
graphicpath = std::string(p);
const char *p = env->GetStringUTFChars(graphics_dir, NULL);
graphicpath = std::string(p);
 
initControls(droidinfo.screen_width, -droidinfo.screen_height,
graphicpath.c_str(),(graphicpath + "/touch_controls.xml").c_str());
initControls(droidinfo.screen_width, -droidinfo.screen_height, graphicpath.c_str(),
(graphicpath + "/touch_controls.xml").c_str());
 
/*
if (renderer != REND_SOFT)
SDL_SetSwapBufferCallBack(frameControls);
 
if (renderer == REND_SOFT)// In soft mode SDL calls swap buffer, disable so it does not flicker
SDL_SwapBufferPerformsSwap(false);
*/
 
 
SDL_SetSwapBufferCallBack(frameControls);
 
//Now doen in java to keep context etc
//SDL_SwapBufferPerformsSwap(false);
 
PortableInit(argc, argv);
 
return 0;
824,17 → 805,15
}
 
 
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_frame( JNIEnv* env,
jobject thiz )
jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_frame(JNIEnv *env, jobject thiz)
{
LOGI("Java_com_beloko_duke_engine_NativeLib_frame");
LOGI("Java_com_voidpoint_duke3d_engine_NativeLib_frame");
 
frameControls();
// frameControls();
return 0;
}
 
__attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM* vm, void* reserved)
__attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
LOGI("JNI_OnLoad");
setTCJNIEnv(vm);
844,36 → 823,33
 
 
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_keypress(JNIEnv *env, jobject obj,
jint down, jint keycode, jint unicode)
Java_com_voidpoint_duke3d_engine_NativeLib_keypress(JNIEnv *env, jobject obj, jint down, jint keycode, jint unicode)
{
LOGI("keypress %d",keycode);
LOGI("keypress %d", keycode);
if (controlsContainer.isEditing())
{
if (down && (keycode == SDL_SCANCODE_ESCAPE ))
if (down && (keycode == SDL_SCANCODE_ESCAPE))
controlsContainer.finishEditing();
return;
}
 
PortableKeyEvent(down,keycode,unicode);
PortableKeyEvent(down, keycode, unicode);
}
 
 
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj,
jint action, jint pid, jdouble x, jdouble y)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj, jint action, jint pid,
jfloat x, jfloat y)
{
//LOGI("TOUCHED");
controlsContainer.processPointer(action,pid,x,y);
// LOGI("TOUCHED");
controlsContainer.processPointer(action, pid, x, y);
}
 
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_doAction(JNIEnv *env, jobject obj,
jint state, jint action)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_doAction(JNIEnv *env, jobject obj, jint state, jint action)
{
LOGI("doAction %d %d",state,action);
LOGI("doAction %d %d", state, action);
 
//gamepadButtonPressed();
// gamepadButtonPressed();
if (hideTouchControls && tcGameMain)
{
if (tcGameMain->isEnabled())
883,64 → 859,58
tcGameWeapons->animateOut(30);
}
 
PortableAction(state,action);
PortableAction(state, action);
}
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj,
jfloat v)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj, jfloat v)
{
PortableMove(v, NAN);
}
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogSide(JNIEnv *env, jobject obj,
jfloat v)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogSide(JNIEnv *env, jobject obj, jfloat v)
{
PortableMove(NAN, v);
}
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj,
jint mode,jfloat v)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj, jint mode, jfloat v)
{
PortableLookJoystick(NAN, v);
}
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj,
jint mode,jfloat v)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj, jint mode, jfloat v)
{
PortableLookJoystick(v, NAN);
}
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj,
jfloat alpha,jfloat strafe,jfloat fwd,jfloat pitch,jfloat yaw,int other)
void EXPORT_ME
Java_com_voidpoint_duke3d_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj, int other)
{
setTouchSettings(alpha,strafe,fwd,pitch,yaw,other);
setTouchSettings(other);
}
 
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_resetTouchSettings(JNIEnv *env, jobject obj)
void EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_resetTouchSettings(JNIEnv *env, jobject obj)
{
controlsContainer.resetDefaults();
}
 
std::string quickCommandString;
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_quickCommand(JNIEnv *env, jobject obj,
jstring command)
 
jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_quickCommand(JNIEnv *env, jobject obj, jstring command)
{
const char * p = env->GetStringUTFChars(command,NULL);
quickCommandString = std::string(p) + "\n";
const char *p = env->GetStringUTFChars(command, NULL);
quickCommandString = std::string(p) + "\n";
env->ReleaseStringUTFChars(command, p);
PortableCommand(quickCommandString.c_str());
}
 
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_setScreenSize( JNIEnv* env,
jobject thiz, jint width, jint height)
Java_com_voidpoint_duke3d_engine_NativeLib_setScreenSize(JNIEnv *env, jobject thiz, jint width, jint height)
{
droidinfo.screen_width = width;
droidinfo.screen_height = height;
}
 
void EXPORT_ME Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls)
void EXPORT_ME Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv *env, jclass cls)
{
/* This interface could expand with ABI negotiation, calbacks, etc. */
SDL_Android_Init(env, cls);
948,6 → 918,31
// SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE);
}
 
jstring EXPORT_ME
Java_com_voidpoint_duke3d_engine_NativeLib_getSavetext(JNIEnv *env, jobject obj, jstring jfile, jint type)
{
const char *p = env->GetStringUTFChars(jfile, NULL);
 
jstring ret = env->NewStringUTF(G_GetStringFromSavegame(p, type));
env->ReleaseStringUTFChars(jfile, p);
 
return ret;
}
 
jint EXPORT_ME Java_com_voidpoint_duke3d_engine_NativeLib_getScreenshot(JNIEnv *env, jobject obj, jstring jfile,
jobject jpal, jobject jdataOut)
{
const char *p = env->GetStringUTFChars(jfile, NULL);
 
jbyte *bb = (jbyte *)env->GetDirectBufferAddress(jdataOut);
jbyte *pb = (jbyte *)env->GetDirectBufferAddress(jpal);
 
int ret = G_GetScreenshotFromSavegame(p, (char *)pb, (char *)bb);
 
env->ReleaseStringUTFChars(jfile, p);
return ret;
}
 
#ifdef GP_LIC
#undef GP_LIC_INC
#define GP_LIC_INC 3
/polymer/eduke32/source/android/in_android.c
1,3 → 1,4
#include "compat.h"
#include "sdl_inc.h"
#include "baselayer.h"
#include "keys.h"
7,16 → 8,30
#include "player.h"
#include "game.h"
#include "build.h"
#include "anim.h"
#include "player.h"
 
#include "jmact/keyboard.h"
#include "jmact/control.h"
#include "jmact/_control.h"
 
#include "menus.h"
 
#include "../src/video/android/SDL_androidkeyboard.h" // FIXME: include header locally if necessary
#ifdef __cplusplus
extern "C" {
#endif
// #include "../src/video/android/SDL_androidkeyboard.h" // FIXME: include header locally if necessary
//#include "../src/events/SDL_mouse_c.h"
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardText(const char *text);
extern int SDL_SendMouseMotion(SDL_Window * window, Uint32 mouseID, int relative, int x, int y);
extern int SDL_SendMouseButton(SDL_Window * window, Uint32 mouseID, Uint8 state, Uint8 button);
 
#ifdef __cplusplus
}
#endif
 
#include "in_android.h"
 
#include <android/log.h>
 
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
23,9 → 38,6
 
extern int32_t main(int32_t argc, char *argv []);
 
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardText(const char *text);
 
static char sdl_text[2];
 
droidinput_t droidinput;
32,9 → 44,9
 
int PortableKeyEvent(int state, int code,int unicode)
{
LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
LOGI("PortableKeyEvent %d %d %d",state,(SDL_Scancode)code,unicode);
 
SDL_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED, code);
SDL_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED, (SDL_Scancode)code);
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
 
// if (code == 42)
58,6 → 70,16
return 0;
}
 
void PortableMouseMenu(float x,float y)
{
SDL_SendMouseMotion(NULL,0,0,x,y);
}
 
void PortableMouseMenuButton(int state,int button)
{
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, state?SDL_PRESSED:SDL_RELEASED, SDL_BUTTON_LEFT);
}
 
void changeActionState(int state, int action)
{
if (state)
102,13 → 124,22
#endif
 
//Special toggle for crouch, NOT when using jetpack or in water
if (!g_player[myconnectindex].ps->jetpack_on &&
g_player[myconnectindex].ps->on_ground &&
(sector[g_player[myconnectindex].ps->cursectnum].lotag != ST_2_UNDERWATER))
if (droidinput.toggleCrouch)
{
if (toggleCrouch)
int lotag = sector[g_player[myconnectindex].ps->cursectnum].lotag;
 
if (droidinput.crouchToggleState && (lotag == ST_2_UNDERWATER || lotag == ST_1_ABOVE_WATER))
{
droidinput.crouchToggleState = 0;
if (action == gamefunc_Crouch)
state = 0;
else PortableAction(0, gamefunc_Crouch);
}
 
if (action == gamefunc_Crouch)
{
if (!g_player[myconnectindex].ps->jetpack_on && g_player[myconnectindex].ps->on_ground &&
lotag != ST_2_UNDERWATER && lotag != ST_1_ABOVE_WATER)
{
if (state)
droidinput.crouchToggleState = !droidinput.crouchToggleState;
116,19 → 147,25
state = droidinput.crouchToggleState;
}
}
 
}
 
//Check if jumping while crouched
if (action == gamefunc_Jump)
{
droidinput.crouchToggleState = 0;
changeActionState(0, gamefunc_Crouch);
if (droidinput.crouchToggleState)
{
droidinput.crouchToggleState = 0;
changeActionState(0, gamefunc_Crouch);
}
else
changeActionState(state, action);
}
else
changeActionState(state, action);
 
changeActionState(state, action);
 
if (state == 2)
PortableAction(0,action);
PortableAction(0, action);
 
// LOGI("PortableAction state = 0x%016llX", CONTROL_ButtonState);
}
137,6 → 174,12
//Need these NAN check as not cumulative.
void PortableMove(float fwd, float strafe)
{
if (!ud.auto_run)
{
fwd *= 0.5f;
strafe *= 0.5f;
}
 
if (!isnan(fwd))
droidinput.forwardmove = fclamp2(fwd, -1.f, 1.f);
 
164,13 → 207,10
{
OSD_Dispatch(cmd);
}
 
 
void PortableInit(int argc, const char ** argv)
{
//droidinput.left_double_action = -1;
//droidinput.right_double_action = -1;
 
main(argc, argv);
main(argc, ( char **)argv);
}
 
int consoleShown = 0;
179,62 → 219,63
consoleShown = onf;
}
 
extern int animation_playing;
extern int inExtraScreens; //In game.c
int32_t PortableRead(portableread_t r)
{
int32_t rv;
 
switch (r)
{
case READ_SCREEN_MODE:
 
if (animation_playing)
return TOUCH_SCREEN_BLANK_TAP;
else if (inExtraScreens)
return TOUCH_SCREEN_BLANK_TAP;
if (g_animPtr || inExtraScreens)
rv = TOUCH_SCREEN_BLANK_TAP;
else if (consoleShown)
return TOUCH_SCREEN_CONSOLE;
rv = TOUCH_SCREEN_CONSOLE;
else if ((g_player[myconnectindex].ps->gm & MODE_MENU) == MODE_MENU)
{
//Then check if Yes/No menu
if ((g_currentMenu == MENU_QUITTOTITLE) ||
(g_currentMenu == MENU_RESETPLAYER ) ||
((g_currentMenu == MENU_LOADVERIFY )) ||
(g_currentMenu == MENU_NEWVERIFY ) ||
((g_currentMenu == MENU_SAVEVERIFY )) ||
(g_currentMenu == MENU_QUIT ) ||
(g_currentMenu == MENU_QUITTOTITLE )
)
return TOUCH_SCREEN_YES_NO;
else
return TOUCH_SCREEN_MENU;
}
rv = (m_currentMenu->type == Verify) ? TOUCH_SCREEN_YES_NO : TOUCH_SCREEN_MENU;
else if (ud.overhead_on == 2)
return TOUCH_SCREEN_AUTOMAP;
rv = TOUCH_SCREEN_AUTOMAP;
else if ((g_player[myconnectindex].ps->gm & MODE_GAME))
if (PortableRead(READ_IS_DEAD))
return TOUCH_SCREEN_BLANK_TAP;
rv = TOUCH_SCREEN_BLANK_TAP;
else
return TOUCH_SCREEN_GAME;
rv = TOUCH_SCREEN_GAME;
else
return TOUCH_SCREEN_BLANK_TAP;
 
rv = TOUCH_SCREEN_BLANK_TAP;
break;
case READ_WEAPONS:
return g_player[myconnectindex].ps->gotweapon;
rv = g_player[myconnectindex].ps->gotweapon; break;
case READ_AUTOMAP:
return ud.overhead_on != 0; // ud.overhead_on ranges from 0-2
rv = ud.overhead_on != 0; break;// ud.overhead_on ranges from 0-2
case READ_MAPFOLLOWMODE:
return ud.scrollmode;
rv = ud.scrollmode; break;
case READ_RENDERER:
return getrendermode();
rv = getrendermode(); break;
case READ_LASTWEAPON:
return droidinput.lastWeapon;
rv = droidinput.lastWeapon;
if ((unsigned)rv < MAX_WEAPONS && !g_player[myconnectindex].ps->ammo_amount[rv])
rv = -1;
break;
case READ_PAUSED:
return ud.pause_on != 0;
rv = ud.pause_on != 0; break;
case READ_IS_DEAD:
return g_player[myconnectindex].ps->dead_flag;
rv = g_player[myconnectindex].ps->dead_flag; break;
case READ_INVENTORY:
rv = 0;
for (int i = 0; i < GET_MAX; i++)
{
if (g_player[myconnectindex].ps->inv_amount[i])
rv += (1 << i);
}
break;
case READ_SOMETHINGONPLAYER:
rv = g_player[myconnectindex].ps->somethingonplayer != -1;
break;
default:
return 0;
rv = 0; break;
}
 
return rv;
}
 
static float map_zoom,map_dx,map_dy = 0;
254,7 → 295,7
*x += ((int)(map_dx * -30000)*sintable[(512+2048-*angle)&2047])>>14;
*y += ((int)(map_dy * -30000)*sintable[(512+1024-512-*angle)&2047])>>14;
 
*zoom += map_zoom * 2000;
// *zoom += map_zoom * 2000;
//*angle = 0;
map_dx = map_dy = map_zoom = 0;
}
/polymer/eduke32/source/android/in_android.h
24,8 → 24,8
#define KEY_QUICK_KEY3 0x1013
#define KEY_QUICK_KEY4 0x1014
 
#define BUTTONSET(x,value) (CONTROL_ButtonState |= ((uint64_t)value<<((uint64_t)(x))))
#define BUTTONCLEAR(x) (CONTROL_ButtonState &= ~((uint64_t)1<<((uint64_t)(x))))
// #define BUTTONSET(x,value) (CONTROL_ButtonState |= ((uint64_t)value<<((uint64_t)(x))))
// #define BUTTONCLEAR(x) (CONTROL_ButtonState &= ~((uint64_t)1<<((uint64_t)(x))))
 
#define PRECISIONSHOOTFACTOR 0.3f
 
49,7 → 49,9
READ_RENDERER,
READ_LASTWEAPON,
READ_PAUSED,
READ_IS_DEAD
READ_IS_DEAD,
READ_INVENTORY,
READ_SOMETHINGONPLAYER
} portableread_t;
 
 
68,6 → 70,8
{
int32_t crouchToggleState;
int32_t lastWeapon;
int32_t toggleCrouch;
int32_t quickSelectWeapon;
 
uint64_t functionSticky; //To let at least one tick
uint64_t functionHeld;
75,6 → 79,8
int32_t left_double_action;
int32_t right_double_action;
 
int32_t invertLook, hideStick;
 
double pitch, yaw;
double pitch_joystick, yaw_joystick;
float forwardmove, sidemove;
82,6 → 88,8
// set by configuration UI
float strafe_sens, forward_sens;
float pitch_sens, yaw_sens;
 
float gameControlsAlpha;
} droidinput_t;
 
typedef struct
93,15 → 101,16
 
extern droidinput_t droidinput;
extern droidsysinfo_t droidinfo;
extern char toggleCrouch;
 
 
 
int PortableKeyEvent(int state, int code, int unicode);
int PortableRead(portableread_t r);
 
void PortableAction(int state, int action);
 
void PortableMouseMenu(float x,float y);
void PortableMouseMenuButton(int state,int button);
 
void PortableMove(float fwd, float strafe);
void PortableLook(double yaw, double pitch);
void PortableLookJoystick(double yaw, double pitch);
/polymer/eduke32/source/android.h
36,6 → 36,9
extern void CONTROL_Android_ClearButton(int32_t whichbutton);
extern void CONTROL_Android_PollDevices(ControlInfo *info);
extern void CONTROL_Android_SetLastWeapon(int w);
 
extern void CONTROL_Android_ScrollMap(int32_t *angle,int32_t *x, int32_t *y, uint16_t *zoom );
 
#endif
 
#endif
/polymer/eduke32/source/common.c
368,70 → 368,70
}
}
 
void G_ExtPreStartupWindow(void)
void G_ScanGroups(void)
{
ScanGroups();
 
// try and identify the 'defaultgamegrp' in the set of GRPs.
// if it is found, set up the environment accordingly for the game it represents.
// if it is not found, choose the first GRP from the list
struct grpfile *fg, *first = NULL;
 
for (fg = foundgrps; fg; fg=fg->next)
{
// try and identify the 'defaultgamegrp' in the set of GRPs.
// if it is found, set up the environment accordingly for the game it represents.
// if it is not found, choose the first GRP from the list
struct grpfile *fg, *first = NULL;
struct grpfile *grp;
for (grp = listgrps; grp; grp=grp->next)
if (fg->crcval == grp->crcval) break;
 
for (fg = foundgrps; fg; fg=fg->next)
if (grp == NULL)
continue;
 
fg->game = grp->game;
if (!first) first = fg;
if (!Bstrcasecmp(fg->name, G_DefaultGrpFile()))
{
struct grpfile *grp;
for (grp = listgrps; grp; grp=grp->next)
if (fg->crcval == grp->crcval) break;
 
if (grp == NULL)
continue;
 
fg->game = grp->game;
if (!first) first = fg;
if (!Bstrcasecmp(fg->name, G_DefaultGrpFile()))
{
g_gameType = grp->game;
g_gameNamePtr = grp->name;
break;
}
g_gameType = grp->game;
g_gameNamePtr = grp->name;
break;
}
if (!fg && first)
}
if (!fg && first)
{
if (g_grpNamePtr == NULL)
{
if (g_grpNamePtr == NULL)
{
clearGrpNamePtr();
g_grpNamePtr = dup_filename(first->name);
}
g_gameType = first->game;
g_gameNamePtr = listgrps->name;
clearGrpNamePtr();
g_grpNamePtr = dup_filename(first->name);
}
else if (!fg) g_gameNamePtr = NULL;
g_gameType = first->game;
g_gameNamePtr = listgrps->name;
}
else if (!fg) g_gameNamePtr = NULL;
}
 
void G_ExtPostStartupWindow(int32_t autoload)
void G_LoadGroups(int32_t autoload)
{
if (g_modDir[0] != '/')
{
char cwd[BMAX_PATH];
 
Bstrcat(g_rootDir,g_modDir);
Bstrcat(g_rootDir, g_modDir);
addsearchpath(g_rootDir);
// addsearchpath(mod_dir);
// addsearchpath(mod_dir);
 
if (getcwd(cwd,BMAX_PATH))
if (getcwd(cwd, BMAX_PATH))
{
Bsprintf(cwd,"%s/%s",cwd,g_modDir);
Bsprintf(cwd, "%s/%s", cwd, g_modDir);
if (!Bstrcmp(g_rootDir, cwd))
{
if (addsearchpath(cwd) == -2)
if (Bmkdir(cwd,S_IRWXU) == 0) addsearchpath(cwd);
if (Bmkdir(cwd, S_IRWXU) == 0)
addsearchpath(cwd);
}
}
 
#ifdef USE_OPENGL
Bsprintf(cwd,"%s/%s",g_modDir,TEXCACHEFILE);
Bstrcpy(TEXCACHEFILE,cwd);
Bsprintf(cwd, "%s/%s", g_modDir, TEXCACHEFILE);
Bstrcpy(TEXCACHEFILE, cwd);
#endif
}
 
438,34 → 438,32
if (g_usingAddon)
G_LoadAddon();
 
int32_t i;
const char *grpfile = G_GrpFile();
 
if (g_dependencyCRC)
{
int32_t i;
const char *grpfile = G_GrpFile();
 
if (g_dependencyCRC)
struct grpfile *grp = FindGroup(g_dependencyCRC);
if (grp)
{
struct grpfile * grp = FindGroup(g_dependencyCRC);
if (grp)
{
if ((i = initgroupfile(grp->name)) == -1)
initprintf("Warning: could not find main data file \"%s\"!\n",grp->name);
else
initprintf("Using \"%s\" as main game data file.\n", grp->name);
}
if ((i = initgroupfile(grp->name)) == -1)
initprintf("Warning: could not find main data file \"%s\"!\n", grp->name);
else
initprintf("Using \"%s\" as main game data file.\n", grp->name);
}
}
 
if ((i = initgroupfile(grpfile)) == -1)
initprintf("Warning: could not find main data file \"%s\"!\n",grpfile);
else
initprintf("Using \"%s\" as main game data file.\n", grpfile);
if ((i = initgroupfile(grpfile)) == -1)
initprintf("Warning: could not find main data file \"%s\"!\n", grpfile);
else
initprintf("Using \"%s\" as main game data file.\n", grpfile);
 
if (autoload)
{
G_LoadGroupsInDir("autoload");
if (autoload)
{
G_LoadGroupsInDir("autoload");
 
if (i != -1)
G_DoAutoload(grpfile);
}
if (i != -1)
G_DoAutoload(grpfile);
}
 
if (g_modDir[0] != '/')
484,32 → 482,30
 
loaddefinitions_game(G_DefFile(), TRUE);
 
struct strllist *s;
 
pathsearchmode = 1;
while (CommandGrps)
{
struct strllist *s;
int32_t j;
 
pathsearchmode = 1;
while (CommandGrps)
s = CommandGrps->next;
 
if ((j = initgroupfile(CommandGrps->str)) == -1)
initprintf("Could not find file \"%s\".\n", CommandGrps->str);
else
{
int32_t j;
g_groupFileHandle = j;
initprintf("Using file \"%s\" as game data.\n", CommandGrps->str);
if (autoload)
G_DoAutoload(CommandGrps->str);
}
 
s = CommandGrps->next;
 
if ((j = initgroupfile(CommandGrps->str)) == -1)
initprintf("Could not find file \"%s\".\n",CommandGrps->str);
else
{
g_groupFileHandle = j;
initprintf("Using file \"%s\" as game data.\n",CommandGrps->str);
if (autoload)
G_DoAutoload(CommandGrps->str);
}
 
Bfree(CommandGrps->str);
Bfree(CommandGrps);
CommandGrps = s;
}
pathsearchmode = 0;
Bfree(CommandGrps->str);
Bfree(CommandGrps);
CommandGrps = s;
}
pathsearchmode = 0;
}
 
#ifdef _WIN32
/polymer/eduke32/source/game.c
60,6 → 60,10
#include "input.h"
#include "compat.h"
 
#ifdef __ANDROID__
#include "android.h"
#endif
 
#ifdef LUNATIC
# include "lunatic_game.h"
#endif
2884,6 → 2888,10
int32_t g_logoFlags = 255;
#endif
 
#ifdef __ANDROID__
int inExtraScreens = 0;
#endif
 
static void G_DisplayExtraScreens(void)
{
int32_t flags = G_GetLogoFlags();
2893,6 → 2901,9
 
if (!DUKEBETA && (!VOLUMEALL || flags & LOGO_SHAREWARESCREENS))
{
#ifdef __ANDROID__
inExtraScreens = 1;
#endif
setview(0,0,xdim-1,ydim-1);
flushperms();
//g_player[myconnectindex].ps->palette = palette;
2910,10 → 2921,17
fadepaltile(0,0,0, 63,0,-7,3290);
while (!I_CheckAllInput())
G_HandleAsync();
 
#ifdef __ANDROID__
inExtraScreens = 0;
#endif
}
 
if (flags & LOGO_TENSCREEN)
{
#ifdef __ANDROID__
inExtraScreens = 1;
#endif
setview(0,0,xdim-1,ydim-1);
flushperms();
//g_player[myconnectindex].ps->palette = palette;
2928,6 → 2946,9
 
fadepaltile(0,0,0, 0,63,7, TENSCREEN);
I_ClearAllInput();
#ifdef __ANDROID__
inExtraScreens = 0;
#endif
}
}
 
2976,8 → 2997,6
}
}
 
uninitgroupfile();
 
Bfflush(NULL);
 
exit(0);
3666,6 → 3685,9
}
else
{
#ifdef __ANDROID__
CONTROL_Android_ScrollMap(&ud.fola,& ud.folx,&ud.foly,&pp->zoom);
#else
if (!ud.pause_on)
{
ud.fola += ud.folavel>>3;
3672,6 → 3694,7
ud.folx += (ud.folfvel*sintable[(512+2048-ud.fola)&2047])>>14;
ud.foly += (ud.folfvel*sintable[(512+1024-512-ud.fola)&2047])>>14;
}
#endif
cposx = ud.folx;
cposy = ud.foly;
cang = ud.fola;
4413,6 → 4436,11
 
if (pub > 0 || getrendermode() >= REND_POLYMOST) // JBF 20040101: redraw background always
{
#ifdef __ANDROID__
// HACK: this is needed or else we get leftover UI texture crap where we'd get HOM on PC
clearallviews(0L);
#endif
 
#ifndef EDUKE32_TOUCH_DEVICES
if (ud.screen_size >= 8)
#endif
7502,8 → 7530,11
#endif
 
t->picnum = TILE_VIEWSCR;
t->xrepeat = t->xrepeat & 1 ? (t->xrepeat>>2) + 1 : t->xrepeat>>2;
t->yrepeat = t->yrepeat & 1 ? (t->yrepeat>>2) + 1 : t->yrepeat>>2;
 
#if VIEWSCREENFACTOR > 0
t->xrepeat = (t->xrepeat>>VIEWSCREENFACTOR) + (t->xrepeat & 1);
t->yrepeat = (t->yrepeat>>VIEWSCREENFACTOR) + (t->yrepeat & 1);
#endif
}
 
break;
9164,6 → 9195,18
if (ud.overhead_on == 3) ud.overhead_on = 0;
ud.last_overhead = ud.overhead_on;
}
 
#ifdef __ANDROID__
if (ud.overhead_on == 1)
ud.scrollmode = 0;
else if (ud.overhead_on == 2)
{
ud.scrollmode = 1;
ud.folx = g_player[screenpeek].ps->opos.x;
ud.foly = g_player[screenpeek].ps->opos.y;
ud.fola = g_player[screenpeek].ps->oang;
}
#endif
g_restorePalette = 1;
G_UpdateScreenArea();
}
10735,6 → 10778,7
G_Cleanup();
FreeGroups();
OSD_Cleanup();
uninitgroupfile();
Bfflush(NULL);
}
 
11067,7 → 11111,10
G_GameExit("Failed loading art.");
}
Bchdir(cwd);
#ifndef __ANDROID__ //This crashes on *some* Android devices. Small onetime memory leak. TODO fix above function
Bfree(cwd);
#endif
 
}
else if (loadpics("tiles000.art",MAXCACHE1DSIZE) < 0)
G_GameExit("Failed loading art.");
11409,7 → 11456,7
if (Bstrcmp(setupfilename, SETUPFILENAME))
initprintf("Using config file \"%s\".\n",setupfilename);
 
G_ExtPreStartupWindow();
G_ScanGroups();
 
#ifdef STARTUP_SETUP_WINDOW
if (i < 0 || (!g_noSetup && (ud.configversion != BYTEVERSION_JF || ud.config.ForceSetup)) || g_commandSetup)
11429,7 → 11476,7
}
 
flushlogwindow = 0;
G_ExtPostStartupWindow(!g_noAutoLoad && !ud.config.NoAutoLoad);
G_LoadGroups(!g_noAutoLoad && !ud.config.NoAutoLoad);
// flushlogwindow = 1;
 
if (!usecwd)
/polymer/eduke32/source/game.h
42,6 → 42,14
#define MAXPWLOCKOUT 128
#define MAXRTSNAME 128
 
#if defined(GEKKO) || defined(__OPENDINGUX__)
# define VIEWSCREENFACTOR 0
#elif defined(__ANDROID__)
# define VIEWSCREENFACTOR 1
#else
# define VIEWSCREENFACTOR 2
#endif
 
enum GametypeFlags_t {
GAMETYPE_COOP = 0x00000001,
GAMETYPE_WEAPSTAY = 0x00000002,
/polymer/eduke32/source/sector.c
405,7 → 405,7
if (OW >= 0 && dist(&sprite[ps->i], &sprite[i]) < VIEWSCREEN_ACTIVE_DISTANCE)
{
if (waloff[TILE_VIEWSCR] == 0)
allocatepermanenttile(TILE_VIEWSCR, tilesiz[PN].x<<2, tilesiz[PN].y<<2);
allocatepermanenttile(TILE_VIEWSCR, tilesiz[PN].x<<VIEWSCREENFACTOR, tilesiz[PN].y<<VIEWSCREENFACTOR);
else
walock[TILE_VIEWSCR] = 255;