diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles.bb b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles.bb index 392b93682..0fcf08a47 100644 --- a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles.bb +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles.bb @@ -5,7 +5,7 @@ SECTION = "examples" LICENSE = "GPL-2.0" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" -DEPENDS = "virtual/egl virtual/libgles1 virtual/libgles2 virtual/kernel" +DEPENDS = "virtual/egl virtual/libgles1 virtual/libgles2" PR = "${DISTRO}.r0" @@ -13,21 +13,19 @@ SRC_URI = "file://opengles" S = "${WORKDIR}/opengles" -do_compile() { - ${CC} -O2 -Wall -Ilib/include es20_example.c lib/fslutil/fslutil.c -lm -lEGL -lGLESv2 -o es20_example - ${CC} -O2 -Wall -Ilib/include es11_example.c lib/fslutil/fslutil.c lib/glu3/glu3.c -lm -lEGL -lGLESv1_CM -o es11_example +EXTRA_OEMAKE = "" +EXTRA_OEMAKE_mx6 = "EGL_FLAVOUR=${@base_conditional('HAVE_GUI', '1' , 'x11', 'fb', d)}" + +do_install () { + oe_runmake DEST_DIR="${D}" install } -do_install() { - install -d ${D}${bindir} ${D}/usr/share/wallpapers - install -m 0755 es20_example es11_example ${D}${bindir} - install -m 0644 texture.bmp ${D}/usr/share/wallpapers -} +FILES_${PN} = "/opt/${PN}" +FILES_${PN}-dbg += "/opt/${PN}/.debug" -FILES_${PN} += "/usr/share/wallpapers/texture.bmp" - -RDEPENDS_${PN} = "lib2dz160-mx51 lib2dz430-mx51" +RDEPENDS_${PN}_mx5 = "lib2dz160-mx51 lib2dz430-mx51" +RDEPENDS_${PN}_mx6 = "libopenvg-mx6" PACKAGE_ARCH = "${MACHINE_ARCH}" -COMPATIBLE_MACHINE = "(ccimx51js|ccimx53js)" +COMPATIBLE_MACHINE = "(ccimx51js|ccimx53js|ccimx6adpt|ccimx6sbc)" diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/Makefile b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/Makefile new file mode 100644 index 000000000..47c86d7c5 --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/Makefile @@ -0,0 +1,16 @@ +CFLAGS += -O2 -Ilib/include +VPATH = lib/fslutil lib/glu3 +BINARIES = es20_example es11_example + +all: $(BINARIES) + +es11_example: fslutil.o glu3.o + $(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv1_CM $@.c -o $@ + +es20_example: fslutil.o + $(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv2 $@.c -o $@ + +install: $(BINARIES) + -mkdir -p $(DEST_DIR)/opt/dey-examples-opengles + install -m 0755 $^ $(DEST_DIR)/opt/dey-examples-opengles + install -m 0644 texture.bmp $(DEST_DIR)/opt/dey-examples-opengles diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/es11_example.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/es11_example.c similarity index 99% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/es11_example.c rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/es11_example.c index 5f239ecc7..6408c17b5 100644 --- a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/es11_example.c +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/es11_example.c @@ -51,7 +51,7 @@ int LoadGLTextures() } /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */ - if (ImageLoad("/usr/share/wallpapers/texture.bmp", image1)) { + if (ImageLoad("texture.bmp", image1)) { /* Create The Texture */ glGenTextures(1, texture); /* Typical Texture Generation Using Data From The Bitmap */ diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/es20_example.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/es20_example.c similarity index 99% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/es20_example.c rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/es20_example.c index e0f46c500..1f4325e71 100644 --- a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/es20_example.c +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/es20_example.c @@ -231,7 +231,7 @@ int LoadGLTextures() } /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */ - if (ImageLoad("/usr/share/wallpapers/texture.bmp", image1)) { + if (ImageLoad("texture.bmp", image1)) { /* Create The Texture */ glGenTextures(1, texture); /* Typical Texture Generation Using Data From The Bitmap */ diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/fslutil/fslutil.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/fslutil/fslutil.c similarity index 100% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/fslutil/fslutil.c rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/fslutil/fslutil.c diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/glu3/glu3.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/glu3/glu3.c similarity index 100% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/glu3/glu3.c rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/glu3/glu3.c diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/include/FSL/c2d_api.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/include/FSL/c2d_api.h similarity index 100% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/include/FSL/c2d_api.h rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/include/FSL/c2d_api.h diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/include/FSL/fslutil.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/include/FSL/fslutil.h similarity index 100% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/include/FSL/fslutil.h rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/include/FSL/fslutil.h diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/include/GLU3/glu3.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/include/GLU3/glu3.h similarity index 100% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/lib/include/GLU3/glu3.h rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/lib/include/GLU3/glu3.h diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/opengles/texture.bmp b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/texture.bmp similarity index 100% rename from meta-digi-dey/recipes-digi/dey-examples/files/opengles/texture.bmp rename to meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx5/opengles/texture.bmp diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/Makefile b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/Makefile new file mode 100644 index 000000000..ea8c73bbc --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/Makefile @@ -0,0 +1,27 @@ +CFLAGS += -O2 -Icommon/inc -DLINUX +VPATH = common/src +BINARIES = es20_example es11_example + +ifeq ($(EGL_FLAVOUR),fb) +$(info BUILDING FOR FB) +CFLAGS += -DEGL_API_FB +else ifeq ($(EGL_FLAVOUR),x11) +$(info BUILDING FOR X11) +CFLAGS += -DEGL_USE_X11 +X11LIBS = -lX11 +else +$(error Platform not recognized) +endif + +all: $(BINARIES) + +es11_example: fsl_egl.o fslutil.o glu3.o + $(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv1_CM $(X11LIBS) $@.c -o $@ + +es20_example: fsl_egl.o fslutil.o + $(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv2 $(X11LIBS) $@.c -o $@ + +install: $(BINARIES) + -mkdir -p $(DEST_DIR)/opt/dey-examples-opengles + install -m 0755 $^ $(DEST_DIR)/opt/dey-examples-opengles + install -m 0644 texture.bmp $(DEST_DIR)/opt/dey-examples-opengles diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/FSL/fsl_egl.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/FSL/fsl_egl.h new file mode 100644 index 000000000..06f9144aa --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/FSL/fsl_egl.h @@ -0,0 +1,50 @@ +/**************************************************************************** +* Copyright (c) 2012 Freescale Semiconductor, Inc. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* * Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* * Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* * Neither the name of the Freescale Semiconductor, Inc. nor the names of +* its contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Labels parameters + +*****************************************************************************/ + +#ifndef _FSL_EGL_H_ +#define _FSL_EGL_H_ +#ifdef __cplusplus +extern "C" { +#endif +#include + + EGLNativeDisplayType fsl_getNativeDisplay(); + EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType); + void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType,EGLNativeDisplayType eglNativeDisplayType); + + +#ifdef __cplusplus +} +#endif +#endif //_FSL_EGL_H_ + diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/FSL/fslutil.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/FSL/fslutil.h new file mode 100644 index 000000000..bac2327bc --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/FSL/fslutil.h @@ -0,0 +1,224 @@ +/**************************************************************************** +* Copyright (c) 2012 Freescale Semiconductor, Inc. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* * Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* * Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* * Neither the name of the Freescale Semiconductor, Inc. nor the names of +* its contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Labels parameters + +*****************************************************************************/ +#ifndef _FSLUTIL_H_ +#define _FSLUTIL_H_ +#ifdef __cplusplus +extern "C" { +#endif + +// Values for reading in ATC compressed texture files +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_AMD 0x8C93 +#define ATC_SIGNATURE 0xCCC40002 +#define ATI1N_SIGNATURE 0x31495441 +#define ATI2N_SIGNATURE 0x32495441 +#define ETC_SIGNATURE 0xEC000001 +#define ATC_RGB 0x00000001 +#define ATC_RGBA 0x00000002 +#define ATC_TILED 0X00000004 +#define ATC_ALPHA_INTERPOLATED 0X00000010 + +#define PI_OVER_360 0.00872664f + +#ifndef fslBool +#define fslBool int +#define FSL_FALSE 0 +#define FSL_TRUE !FSL_FALSE +#endif + +#define FSL_POINTER_MAX 10000 + + +/* Image type - contains height, width, and data */ +typedef struct Image_s { + unsigned long sizeX; + unsigned long sizeY; + char *data; + int Format; +} Image; + + +typedef enum fslStatus_e +{ + FSL_STATUS_DEVICE_ERROR = -5, //could not open a hardware device driver + FSL_STATUS_NO_CONTEXT = -4, //something has caused a device to fail and loose context + FSL_STATUS_BAD_PARAMETER = -3, + FSL_STATUS_ALLOCATION_ISSUE = -2, + FSL_STATUS_UNSUPPORTED_FEATURE = -1, + FSL_STATUS_GENERAL_ERROR = 0, + FSL_STATUS_SUCCESS = 1, + FSL_FSLSTATUS_END = 0xFFFFFFFF, //This forces the data type for binary lib compatipility +} fslStatus; + +typedef enum fslAxis_e +{ + FSL_X_AXIS, FSL_Y_AXIS, FSL_Z_AXIS +} fslAxis; + +typedef enum fslInputType_e +{ + FSL_INPUT_KEYPRESS =1000, + FSL_INPUT_KEYRELEASE =1500, + FSL_INPUT_POINTERDOWN =2000, + FSL_INPUT_POINTERUP =3000, + FSL_INPUT_POINTERMOVE =4000, + FSL_INPUT_STOP =5000, + FSL_INPUT_PLAY =5001, + FSL_INPUT_PAUSE =5002, + FSL_INPUT_REW =5003, + FSL_INPUT_FFWD =5004, + FSL_INPUT_SEEK =5005, + FSL_INPUT_CLOSEWINDOW =6000, + FSL_INPUTTYPE_END =0xFFFFFFFF, +} fslInputType; + +typedef struct fslInputEventType_s +{ + fslInputType input; + unsigned int signalA; //X, keystroke 1 Coordinates range from 0 to FSL_POINTER_MAX; 0,0 lower left corner + unsigned int signalB; //Y, keystroke 2 + unsigned int signalC; //undefined, could be pointer enumerator for multi-touch / secondary input + long time; //in microseconds +} fslInputEventType; + +typedef enum fslInputDevice_e +{ + FSL_INPUTDEVICE_TOUCHSCREEN =1000, + FSL_INPUTDEVICETYPE_END =0xFFFFFFFF, +} fslInputDevice; + +typedef void* fslDeviceHandle; + +#define FSL_UTIL_MAX_FILE_NAME_LENGTH 1024 // This is arbitrary +#define FSL_INPUT_MAX_EVENTS 64 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef FSL_EGL_USE_X11 +#include +#include +#include +#include +#include +#include +#endif + + +//-------------------------------------------------------------------------------------- +// Name: fslLoadCTES +// Desc: Helper function to load an compressed image file (ATC, ETC, etc.) from the compressenator +//-------------------------------------------------------------------------------------- +char* fslLoadCTES( char* strFileName, unsigned int* pWidth, unsigned int* pHeight, unsigned int* nFormat, unsigned int* nSize ); + +//fslLoadBMP +fslBool fslInit2DBMPTextureGL(char *,unsigned int *pTextureHandle); + +//fslLoadTGA +fslBool fslInit2DTGATextureGL(char* strFileName, unsigned int *pTextureHandle); + +//-------------------------------------------------------------------------------------- +// Name: fslEGLCheck +// Desc: Helper function to print EGL errors and exits application +//-------------------------------------------------------------------------------------- +fslBool fslEGLCheck( fslBool bExitOnFailure ); + +//-------------------------------------------------------------------------------------- +// Name: fslInit2DCTESTextureGL +// Desc: Helper function to load a CTES texture file and bind it to a given GL texture handle +//-------------------------------------------------------------------------------------- +fslBool fslInit2DCTESTextureGL( char* strFileName, unsigned int *pTextureHandle ); + +#ifdef FSL_EGL_USE_X11 +//-------------------------------------------------------------------------------------- +// Name: fslLoadFontX +// Desc: Helper function to load a X11 font into given struct +//-------------------------------------------------------------------------------------- +void fslLoadFontX( Display *display, XFontStruct **font_info ); + +//-------------------------------------------------------------------------------------- +// Name: fslErrorHandlerX +// Desc: Helper function to print incoming X11 server errors +//-------------------------------------------------------------------------------------- +int fslErrorHandlerX( Display *display, XErrorEvent *error ); +#endif + +//-------------------------------------------------------------------------------------- +// Name: fslGetTickCount +// Desc: Helper function to get current time +//-------------------------------------------------------------------------------------- +unsigned int fslGetTickCount(); + +//-------------------------------------------------------------------------------------- +// Name: fslMulMatrix4x4 +// Desc: 4x4 Matix Muliply DEPRECATED for GLU +//-------------------------------------------------------------------------------------- +void fslMultMatrix4x4( float *matC, float *matA, float *matB); + +fslBool fslInvertMatrix4x4( float *matA, float *matC); + +void fslPerspectiveMatrix4x4 ( float *m, float fov, float aspect, float zNear, float zFar); + +void fslMultMatrix4x4Vec4x1 ( float *matA, float *vecA, float *vecB ); + +void fslRotateMatrix4x4 (float *m, float angle, fslAxis axis); + +void fslTranslateMatrix4x4 (float *m, float transX, float transY, float transZ); + +void fslScaleMatrix4x4 (float *m, float scaleX, float scaleY, float scaleZ); +void fslNormalize(float *v); +void fslLoadIdentityMatrix4x4 (float *m); +void fslPrintMatrix4x4(float *m); +fslBool fslUnProject(float winx,float winy, float winz, float modelMatrix[16], float projMatrix[16], int viewport[4], float *objx, float *objy, float *objz); +void fslCrossProduct(float *result, float *b, float* c); +void fslDirectionVector(float *result, float *endPoint, float *startPoint); +float fslInnerProduct( float *v, float *q); +int fslRayIntersectsTriangle(float *p, float *d,float *v0, float *v1, float *v2); +int LoadBMP(char *filename, Image *image); +int LoadTGA(const char *textureFileName, Image *image); +void fslCalculateNormals(float *triArray, int size, float *normArray); + +#ifdef __cplusplus +} +#endif +#endif //_FSLUTIL_H_ + diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/GLU3/glu3.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/GLU3/glu3.h new file mode 100644 index 000000000..1a897ba1d --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/GLU3/glu3.h @@ -0,0 +1,1365 @@ +/* + * Copyright © 2009 Ian D. Romanick + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __glu3_h__ +#define __glu3_h__ + +/** + * \file glu3.h + * Interface definitions for GLU3 library. + */ + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#include +#include +#ifdef USE_GL20 +#include +#include +#elif USE_MX31 +#include +#else +#include +#include +#endif + +#ifdef HAVE_STDBOOL_H +# include +#else +# ifndef HAVE__BOOL +# ifdef __cplusplus +typedef bool _Bool; +# else +# define _Bool signed char +# endif +# endif +# define bool _Bool +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 +#endif + +#define GLU3_VERSION_0_1 +#define GLU3_VERSION_0_9 + +#ifndef GLchar +#define GLchar GLubyte +#endif + +#ifndef GLdouble +#define GLdouble GLfloat +#endif + +struct GLUmat4; + +/** + * Basic four-component vector type. + */ +struct GLUvec4 { + /** Data values of the vector. */ + GLfloat values[4]; + +#ifdef __cplusplus + /** Default constructor. Data values are uninitialized. */ + inline GLUvec4(void) + { + } + + /** Initialize vector from one float value. */ + inline GLUvec4(GLfloat v) + { + values[0] = v; + values[1] = v; + values[2] = v; + values[3] = v; + } + + /** Initialize vector from four float values. */ + inline GLUvec4(GLfloat x , GLfloat y, GLfloat z, GLfloat w) + { + values[0] = x; + values[1] = y; + values[2] = z; + values[3] = w; + } + + /** Initialize vector from another vector. */ + inline GLUvec4(const GLUvec4 &v) + { + values[0] = v.values[0]; + values[1] = v.values[1]; + values[2] = v.values[2]; + values[3] = v.values[3]; + } + + /** + * Multiply a vector with a matrix. + * + * Multiply a row-vector with a 4x4 matrix resulting in a + * row-vector. + */ + GLUvec4 operator *(const GLUmat4 &) const; + + /** + * Component-wise multiplication with a vec4. + * + * \sa gluMult4v_4v + */ + GLUvec4 operator *(const GLUvec4 &) const; + + /** + * Multiply with a scalar. + * + * \sa gluMult4v_f + */ + GLUvec4 operator *(GLfloat) const; + + /** Component-wise addition with a vec4. */ + GLUvec4 operator +(const GLUvec4 &) const; + + /** Component-wise subtraction with a vec4. */ + GLUvec4 operator -(const GLUvec4 &) const; +#endif /* __cplusplus */ +}; + + +#ifdef __cplusplus +inline GLUvec4 operator *(GLfloat f, const GLUvec4 &v) +{ + return v * f; +} + +inline GLUvec4 &operator +=(GLUvec4 &l, const GLUvec4 &r) +{ + l = l + r; + return l; +} + +inline GLUvec4 &operator -=(GLUvec4 &l, const GLUvec4 &r) +{ + l = l - r; + return l; +} + +inline GLUvec4 &operator *=(GLUvec4 &l, const GLUvec4 &r) +{ + l = l * r; + return l; +} + +inline GLUvec4 &operator *=(GLUvec4 &l, GLfloat r) +{ + l = l * r; + return l; +} +#endif /* __cplusplus */ + + +/** + * Basic 4x4 matrix type. + */ +struct GLUmat4 { + /** Columns of the matrix. */ + struct GLUvec4 col[4]; + +#ifdef __cplusplus + /** Default constructor. Columns are uninitialized. */ + inline GLUmat4(void) + { + } + + /** Initialize a matrix from four vec4 inputs. + * Each vec4 is a column in the resulting matrix. + */ + inline GLUmat4(const GLUvec4 & c0, const GLUvec4 & c1, + const GLUvec4 & c2, const GLUvec4 & c3) + { + col[0] = c0; + col[1] = c1; + col[2] = c2; + col[3] = c3; + } + + /** Initialize a matrix from another matrix. */ + inline GLUmat4(const GLUmat4 &m) + { + col[0] = m.col[0]; + col[1] = m.col[1]; + col[2] = m.col[2]; + col[3] = m.col[3]; + } + + + /** + * Multiply a vector with a matrix. + * + * Multiply as a column-vector with a 4x4 matrix resulting in a + * column-vector. + * + * \sa gluMult4m_4v + */ + GLUvec4 operator *(const GLUvec4 &) const; + + /** + * Matrix multiply with a 4x4 matrix. + * + * \sa gluMult4m_4m + */ + GLUmat4 operator *(const GLUmat4 &) const; + + /** Multiply with a scalar. */ + GLUmat4 operator *(GLfloat) const; + + /** Component-wise addition with a mat4. */ + GLUmat4 operator +(const GLUmat4 &) const; + + /** Component-wise subtraction with a mat4. */ + GLUmat4 operator -(const GLUmat4 &) const; +#endif /* __cplusplus */ +}; + +#define GLU_MAX_STACK_DEPTH 32 + +struct GLUmat4Stack { + struct GLUmat4 stack[GLU_MAX_STACK_DEPTH]; + unsigned top; + +#ifdef __cplusplus + GLUmat4Stack() : top(0) + { + /* empty */ + } +#endif /* __cplusplus */ +}; + + +struct GLUarcball { + /** + * Base location of the viewport. + */ + /*@{*/ + unsigned viewport_x; + unsigned viewport_y; + /*@}*/ + + /** + * Dimensions of the viewport. + */ + /*@{*/ + unsigned viewport_width; + unsigned viewport_height; + /*@}*/ + + /** + * Screen X/Y location of initial mouse click. + */ + /*@{*/ + unsigned click_x; + unsigned click_y; + /*@}*/ + + +#ifdef __cplusplus + void viewport(unsigned x, unsigned y, unsigned width, unsigned height) + { + viewport_x = x; + viewport_y = y; + viewport_width = width; + viewport_height = height; + } + + void click(unsigned x, unsigned y) + { + click_x = x; + click_y = y; + } + + GLUmat4 drag(unsigned end_x, unsigned end_y); +#endif /* __cplusplus */ +}; + + +#if 0 +/** + * Consumer for shape data generated by a GLUshapeProducer object + * + * Objects of this class and its descenents are used to consume data generated + * by \c GLUshapeProducer. The \c GLUshapeProducer object is responsible for + * the format of the data generate, and the \c GLUshapeConsumer object is + * repsonsible for storing that data. + * + * This splits the functionality of the classic GLU's \c GLUquadric structure. + * + * \sa GLUshapeProducer + */ +class GLUshapeConsumer { +public: + /** + * Emit an individual vertex + * + * \param position Object-space position of the vertex. + * \param normal Object-space normal of the vertex. + * \param tangent Object-space tangent of the vertex. + * \param uv Parameter-space position of the vertex. The + * per-vertex values will range from (0,0,0,0) to + * (1, 1, 0, 0). + */ + virtual void vertex(const GLUvec4 &position, + const GLUvec4 &normal, + const GLUvec4 &tangent, + const GLUvec4 &uv) = 0; + + /** + * Start a new indexed primitive. + * + * \param mode GL primitive drawing mode used for this primitive + */ + virtual void begin_primitive(GLenum mode) = 0; + + /** + * Emit an element index for drawing + */ + virtual void index(unsigned idx) = 0; + + /** + * End an index primitive previously started with begin_primitive + */ + virtual void end_primitive(void) = 0; +}; + + +/** + * Base class of a shape generators. + * + * Base class defines the interface for all shape generators. Each concrete + * subclass is responsible for providing the pure virtual query and data + * generation methods. Data produced by a shape generator is pushed to a + * \c GLUshapeConsumer as it is generated. + * + * \sa GLUshapeConsumer + */ +class GLUshapeProducer { +public: + virtual ~GLUshapeProducer() + { + } + + /** + * Select the orientation of generated normals + * + * \param outside Set to true if normals should point towards the + * outside of the object. + */ + void orientation(bool outside); + + /** + * Get the number of vertices in the shape + * + * This can be used in the constructor for derived classes, for + * example, to determine how much storage to allocate for vertex data. + */ + virtual unsigned vertex_count(void) const = 0; + + /** + * Get the number of elements used to draw primitives for the shape + * + * This can be used in the constructor for derived classes, for + * example, to determine how much storage to allocate for element data. + */ + virtual unsigned element_count(void) const = 0; + + /** + * Get the number of primitves used to draw the shape + * + * This can be used in the constructor for derived classes, for + * example, to determine the primitive count for a call to + * \c glMultiDrawElements or to determine how much padding to allocate + * for restart values used with primitive restart. + */ + virtual unsigned primitive_count(void) const = 0; + + /** + * Generate the primitive + * + * Causes the data for the primitive to be generated. This will result + * in the \c vertex, \c begin_primitive, \c index, and \c end_primitive + * methods of \c consumer being invoked with the data as it is + * generated. + */ + virtual void generate(GLUshapeConsumer *consumer) const = 0; + +protected: + GLUshapeProducer(void) : + normals_point_out(true) + { + } + + bool normals_point_out; +}; + + +/** + * Shape generator that generates a sphere. + */ +class GLUsphereProducer : public GLUshapeProducer { +public: + /** + * Construct a new sphere shape generator + * + * \param radius Specifies the radius of the sphere. + * \param slices Specifies the number of subdivisions around the + * z-axis. These subdivisions are analogous to the + * slices of an orange. These also match longitude + * lines on the globe. + * \param stacks Specifies the number of subdivisions along the + * z-axis. These match the latitude lines on the globe. + */ + GLUsphereProducer(GLdouble radius, GLint slices, GLint stacks); + virtual unsigned vertex_count(void) const; + virtual unsigned element_count(void) const; + virtual unsigned primitive_count(void) const; + virtual void generate(GLUshapeConsumer *consumer) const; + +private: + double radius; + unsigned slices; + unsigned stacks; +}; + + +/** + * Shape generator that generates a cube. + */ +class GLUcubeProducer : public GLUshapeProducer { +public: + /** + * Construct a new cube shape generator + * + * \param radius Distance from the center of the cube to the center + * of one of the axis-aligned faces. + */ + GLUcubeProducer(GLdouble radius); + virtual unsigned vertex_count(void) const; + virtual unsigned element_count(void) const; + virtual unsigned primitive_count(void) const; + virtual void generate(GLUshapeConsumer *consumer) const; + +private: + double radius; +}; +#endif + +#ifndef __cplusplus +typedef struct GLUvec4 GLUvec4; +typedef struct GLUmat4 GLUmat4; +typedef struct GLUmat4Stack GLUmat4Stack; +typedef struct GLUarcball GLUarcball; +#endif /* __cplusplus */ + + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * Four component dot product from vec4 sources. + * + * \sa gluDot4 (C++) + */ +GLfloat gluDot4_4v(const GLUvec4 *, const GLUvec4 *); + +/** + * Three component dot product from vec4 sources. + * + * \sa gluDot3 (C++) + */ +GLfloat gluDot3_4v(const GLUvec4 *, const GLUvec4 *); + +/** + * Two component dot product from vec4 sources. + * + * \sa gluDot2 (C++) + */ +GLfloat gluDot2_4v(const GLUvec4 *, const GLUvec4 *); + +/** + * Cross product from vec4 sources + * + * The 3-dimensional cross product of \c u and \c v is calculated. The result + * is stored in the first three components of \c result. The fourth component + * is set to 0.0. + * + * \sa gluCross (C++) + */ +void gluCross4v(GLUvec4 *result, const GLUvec4 *u, const GLUvec4 *v); + +/** + * Normalize a vec4 + * + * The 4-dimensional normalization of \c u is stored in \c result. + * + * \sa gluNormalize (C++) + */ +void gluNormalize4v(GLUvec4 *result, const GLUvec4 *u); + +/** + * Calculate the length of a vec4 + * + * The length (magnitude) the 4-dimensional vector \c u is returned. + * + * \sa gluLength (C++) + */ +GLfloat gluLength4v(const GLUvec4 *u); + +/** + * Calculate the squared length of a vec4 + * + * The squared length (magnitude) the 4-dimensional vector \c u is returned. + * + * \sa gluLengthSqr (C++) + */ +GLfloat gluLengthSqr4v(const GLUvec4 *); + +/** + * Calculate the four dimensional outer product of two vec4 sources + * + * Assuing \c u and \c v are column vectors, the outer product is: + * + * \f$\left( \begin{tabular}{cccc} + * $u_x v_x$ & $u_x v_y$ & $u_x v_y$ & $u_x v_w$ \\ + * $u_y v_x$ & $u_y v_y$ & $u_y v_y$ & $u_y v_w$ \\ + * $u_z v_x$ & $u_z v_y$ & $u_z v_y$ & $u_z v_w$ \\ + * $u_w v_x$ & $u_w v_y$ & $u_w v_y$ & $u_w v_w$ \\ + * \end{tabular} \right)\f$ + */ +void gluOuter4v(GLUmat4 *result, const GLUvec4 *u, const GLUvec4 *v); + + +/** + * Component-wise multiply two vec4s + * + * \sa GLUvec4::operator* + */ +void gluMult4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *); + +/** + * Component-wise divide two vec4s + */ +void gluDiv4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *); + +/** + * Component-wise add two vec4s + * + * \sa GLUvec4::operator+ + */ +void gluAdd4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *); + +/** + * Component-wise subtract two vec4s + * + * \sa GLUvec4::operator- + */ +void gluSub4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *); + +/** + * Multiply with a scalar. + * + * \sa GLUvec4::operator* + */ +void gluMult4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat); + +/** Divide components of a vector by a scalar. */ +void gluDiv4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat); + +/** Add a scalar to each of the components of a vector. */ +void gluAdd4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat); + +/** Subtract a scalar from each of the components of a vector. */ +void gluSub4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat); + +/** + * Matrix multiply with a 4x4 matrix. + * + * \sa GLUmat4::operator* + */ +void gluMult4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *); + +/** + * Component-wise addition with a mat4. + * + * \sa GLUmat4::operator+ + */ +void gluAdd4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *); + +/** + * Component-wise subtraction with a mat4. + * + * \sa GLUmat4::operator- + */ +void gluSub4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *); + +/** + * Multiply a vector with a matrix. + * + * Multiply as a column-vector with a 4x4 matrix resulting in a + * column-vector. + * + * \sa GLUmat4::operator* + */ +void gluMult4m_4v(GLUvec4 *result, const GLUmat4 *m, const GLUvec4 *v); + +/** + * Multiply each component of a matrix with a scalar + * + * \sa GLUmat4::operator* + */ +void gluMult4m_f(GLUmat4 *result, const GLUmat4 *, GLfloat); + +/** + * Calculate a scaling transformation matrix from a vector + * + * A scaling transformation matrix is created using the x, y, and z + * components of \c u. Specifically, the matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $u_x$ & $0$ & $0$ & $0$ \\ + * $0$ & $u_y$ & $0$ & $0$ \\ + * $0$ & $0$ & $u_z$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluScale (C++) + */ +void gluScale4v(GLUmat4 *result, const GLUvec4 *u); + +/** \name Translation matrix + */ +/*@{*/ +/** + * Calculate a translation matrix using x, y, and z offsets + * + * The matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $x$ \\ + * $0$ & $1$ & $0$ & $y$ \\ + * $0$ & $0$ & $1$ & $z$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluTranslate (C++) + */ +void gluTranslate3f(GLUmat4 *result, GLfloat x, GLfloat y, GLfloat z); + +/** + * Calculate a translation matrix using components of a vector + * + * The matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $v_x$ \\ + * $0$ & $1$ & $0$ & $v_y$ \\ + * $0$ & $0$ & $1$ & $v_z$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluTranslate (C++) + */ +void gluTranslate4v(GLUmat4 *result, const GLUvec4 *v); +/*@}*/ + +/** + * Calculate a rotation matrix around an arbitrary axis + * + * \param axis Axis, based at the origin, around which to rotate + * \param angle Angle of rotation in radians + * + * If the specificed axis is not unit length, the vector will be normalized. + * + * \sa gluRotate (C++) + */ +void gluRotate4v(GLUmat4 *result, const GLUvec4 *axis, GLfloat angle); + +/** + * Calculate a viewing transformation + * + * \param eye Position, in 3-dimensional space, of the eye point. + * \param center Position, in 3-dimensional space, that the eye is looking at. + * \param up Direction of the up vector. + * \param result Storage for the resulting matrix. + * + * Calculates a transformation matrix that maps the eye point to the origin + * and the \c center to the negative Z axis. The direction defined by \c up + * is projected onto the X/Y plane an is mapped to the positive Y axis. + * + * The calculated matrix is: + * + * \f{eqnarray*}{ + * f &=& c - e \\ + * f' &=& f \over |f| \\ + * u' &=& u \over |u| \\ + * s &=& f \times u \\ + * u'' &=& s \times f \\ + * M &=& + * \left( \begin{tabular}{cccc} + * $s_x$ & $s_y$ & $s_z$ & $0$ \\ + * $u''_x$ & $u''_y$ & $u''_z$ & $0$ \\ + * $-f'_x$ & $-f'_y$ & $-f'_z$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) + * \times + * \left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $-e_x$ \\ + * $0$ & $1$ & $0$ & $-e_y$ \\ + * $0$ & $0$ & $1$ & $-e_z$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) \\ + * \f} + * + * \sa gluLookAt (C++) + */ +void gluLookAt4v(GLUmat4 *result, const GLUvec4 *eye, const GLUvec4 *center, + const GLUvec4 *up); + +/** + * \name Projection matrix + * + * Functions that generate various common projection matrixes. + */ +/*@{*/ +/** + * Generate a perspective projection matrix + * + * \param result Location to store the calculated matrix + * \param left Coordinate for the left clipping plane + * \param right Coordinate for the right clipping plane + * \param top Coordinate for the top clipping plane + * \param bottom Coordinate for the bottom clipping plane + * \param near Distance to the near plane + * \param far Distance to the far plane + * + * The matrix calculated is: + * + * \f{eqnarray*}{ + * M &=& + * \left( \begin{tabular}{cccc} + * ${2 * near} \over {right - left}$ & $0$ & $ {{right + left} \over {right - left}}$ & $0$\\ + * $0$ & ${2 * near} \over {top - bottom}$ & $ {{top + bottom} \over {top - bottom}}$ & $0$ \\ + * $0$ & $0$ & $-{{far + near} \over {far - near}}$ & $-{{2 * far * near} \over {far - near}}$ \\ + * $0$ & $0$ & $-1$ & $0$ \\ + * \end{tabular} \right) \\ + * \f} + * + * If \c left = \c right, \c top = \c bottom, or \c near = \c far, the function + * returns without writing any value to \c result. + * + * If either\c near or \c far are negative, the function returns without + * writing any value to \c result. + */ +void gluFrustum6f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom, + GLfloat top, GLfloat near, GLfloat far); + +/** + * Calculate a perspective projection matrix + * + * \param result Storage for the resulting matrix. + * \param fovy Field-of-view in the Y direction, measured in radians + * \param aspect The ratio of the size in the X direction to the size in the + * Y direction. This is used to calculate the field-of-view in + * the X direction. + * \param near Distance to the near plane + * \param far Distance to the far plane + * + * The matrix calculated is: + * + * \f{eqnarray*}{ + * f &=& cotangent {\left({fovy \over 2} \right)} \\ + * M &=& + * \left( \begin{tabular}{cccc} + * $f \over aspect$ & $0$ & $0$ & $0$ \\ + * $0$ & $f$ & $0$ & $0$ \\ + * $0$ & $0$ & ${far + near} \over {near - far}$ & ${2 \times far \times near} \over {near - far}$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) \\ + * \f} + */ +void gluPerspective4f(GLUmat4 *result, GLfloat fovy, GLfloat aspect, + GLfloat near, GLfloat far); + +/** + * Generate an orthographic projection matrix + * + * \param result Location to store the calculated matrix + * \param left Coordinate for the left clipping plane + * \param right Coordinate for the right clipping plane + * \param top Coordinate for the top clipping plane + * \param bottom Coordinate for the bottom clipping plane + * + * The matrix calculated is: + * + * \f{eqnarray*}{ + * M &=& + * \left( \begin{tabular}{cccc} + * $2 \over {right - left}$ & $0$ & $0$ & $-{{right + left} \over {right - left}}$ \\ + * $0$ & $2 \over {top - bottom}$ & $0$ & $-{{top + bottom} \over {top - bottom}}$ \\ + * $0$ & $0$ & $-1$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) \\ + * \f} + * + * If \c left = \c right or \c top = \c bottom the function returns without + * writing any value to \c result. + * + * This function is identical to calling \c gluOrtho6f with \c near = -1 and + * \c far = 1. + * + * \sa gluOrtho6f + */ +void gluOrtho4f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom, + GLfloat top); + +/** + * Generate an orthographic projection matrix + * + * \param result Location to store the calculated matrix + * \param left Coordinate for the left clipping plane + * \param right Coordinate for the right clipping plane + * \param top Coordinate for the top clipping plane + * \param bottom Coordinate for the bottom clipping plane + * \param near Distance to the near plane + * \param far Distance to the far plane + * + * The matrix calculated is: + * + * \f{eqnarray*}{ + * M &=& + * \left( \begin{tabular}{cccc} + * $2 \over {right - left}$ & $0$ & $0$ & $-{{right + left} \over {right - left}}$ \\ + * $0$ & $2 \over {top - bottom}$ & $0$ & $-{{top + bottom} \over {top - bottom}}$ \\ + * $0$ & $0$ & $-2 \over {far - near}$ & $-{{far + near} \over {far - near}}$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) \\ + * \f} + * + * If \c left = \c right, \c top = \c bottom, or \c near = \c far, the function + * returns without writing any value to \c result. + * + * \s gluOrtho4f + */ +void gluOrtho6f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom, + GLfloat top, GLfloat near, GLfloat far); +/*@}*/ + +/** + * Calculate the transpose of a matrix. + */ +void gluTranspose4m(GLUmat4 *result, const GLUmat4 *m); + +/** + * Calculate the determinant of a matrix. + * + * \sa gluDeterminant4 (C++) + */ +GLfloat gluDeterminant4_4m(const GLUmat4 *m); + +/** + * Calculate the inverse of a matrix. + * + * Inverts the matrix \c m and stores the result in \c result. If \c m is + * not invertable, \c result is not modified + * + * \return + * If the matrix is invertable (i.e., the determinant is not zero), \c GL_TRUE + * is returned. Otherwise GL_FALSE is returned. + * + * \sa gluInverse4 (C++) + */ +GLboolean gluInverse4_4m(GLUmat4 *result, const GLUmat4 *m); + + +/** + * Identity matrix + * + * Global constant containing the matrix: + * + * \f$\left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $0$ \\ + * $0$ & $1$ & $0$ & $0$ \\ + * $0$ & $0$ & $1$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + */ +extern const GLUmat4 gluIdentityMatrix; + +/** + * Load a text file from disk + * + * \param file_name Name of the file to be loaded + * + * Loads data from a named text file and returns a pointer to that data to the + * caller. This may be useful, for example, for loading shader code from flies + * on disk. + * + * The pointer returned by this function should later be released by calling + * \c gluUnloadTextFile. + * + * \note + * The data pointed to by the return value if this function really is + * constant. On some systems this function may be implemented by creating a + * read-only mapping of the file. Writes to such data will result in program + * termination. + * + * \sa gluUnloadTextFile + */ +extern const GLchar *gluLoadTextFile(const char *file_name); + +/** + * Release data previously loaded with gluLoadTextFile. + * + * \sa gluLoadTextFile + */ +extern void gluUnloadTextFile(const GLchar *text); + +extern void gluArcballViewport(GLUarcball *ball, unsigned x, unsigned y, + unsigned width, unsigned height); + +extern void gluArcballClick(GLUarcball *ball, unsigned start_x, + unsigned start_y); + +extern void gluArcballDrag(GLUarcball *ball, GLUmat4 *transformation, + unsigned end_x, unsigned end_y); + +#ifdef __cplusplus +}; +#endif + +#ifdef __cplusplus +/** + * Four component dot product from vec4 sources. + * + * \sa gluDot4_4v + */ +GLfloat gluDot4(const GLUvec4 &, const GLUvec4 &); + +/** + * Three component dot product from vec4 sources. + * + * \sa gluDot3_4v + */ +GLfloat gluDot3(const GLUvec4 &, const GLUvec4 &); + +/** + * Two component dot product from vec4 sources. + * + * \sa gluDot2_4v + */ +GLfloat gluDot2(const GLUvec4 &, const GLUvec4 &); + +/** + * Cross product from vec4 sources + * + * The 3-dimensional cross product of \c u and \c v is calculated. The result + * is stored in the first three components of \c result. The fourth component + * is set to 0.0. + * + * \sa gluCross4v + */ +inline GLUvec4 gluCross(const GLUvec4 &u, const GLUvec4 &v) +{ + GLUvec4 t; + + gluCross4v(& t, & u, & v); + return t; +} + +/** + * Normalize a vec4 + * + * The 4-dimensional normalization of \c u is stored in \c result. + * + * \sa gluNormalize4v + */ +inline GLUvec4 gluNormalize(const GLUvec4 &v) +{ + GLUvec4 t; + + gluNormalize4v(& t, & v); + return t; +} + +/** + * Calculate the length of a vec4 + * + * The length (magnitude) the 4-dimensional vector \c u is returned. + * + * \sa gluLength4v + */ +inline GLfloat gluLength(const GLUvec4 &u) +{ + return gluLength4v(& u); +} + +/** + * Calculate the squared length of a vec4 + * + * The squared length (magnitude) the 4-dimensional vector \c u is returned. + * + * \sa gluLengthSqr4v + */ +inline GLfloat gluLengthSqr(const GLUvec4 &u) +{ + return gluLengthSqr4v(& u); +} + +/** + * Calculate a scaling transformation matrix from a vector + * + * A scaling transformation matrix is created using the x, y, and z + * components of \c u. Specifically, the matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $u_x$ & $0$ & $0$ & $0$ \\ + * $0$ & $u_y$ & $0$ & $0$ \\ + * $0$ & $0$ & $u_z$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluScale4v + */ +inline GLUmat4 gluScale(const GLUvec4 &u) +{ + GLUmat4 result; + + gluScale4v(& result, & u); + return result; +} + +/** + * Calculate a scaling transformation matrix from a vector + * + * A scaling transformation matrix is created using the x, y, and z + * components of \c u. Specifically, the matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $x$ & $0$ & $0$ & $0$ \\ + * $0$ & $y$ & $0$ & $0$ \\ + * $0$ & $0$ & $z$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluScale4v + */ +inline GLUmat4 gluScale(GLfloat x, GLfloat y, GLfloat z) +{ + GLUvec4 u(x, y, z, 1.0); + GLUmat4 result; + + gluScale4v(& result, & u); + return result; +} + +/** \name Translation matrix + */ +/*@{*/ +/** + * Calculate a translation matrix using x, y, and z offsets + * + * The matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $x$ \\ + * $0$ & $1$ & $0$ & $y$ \\ + * $0$ & $0$ & $1$ & $z$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluTranslate3f + */ +inline GLUmat4 gluTranslate(GLfloat x, GLfloat y, GLfloat z) +{ + GLUmat4 result; + + gluTranslate3f(& result, x, y, z); + return result; +} + +/** + * Calculate a translation matrix using components of a vector + * + * The matrix generated is: + * + * \f$\left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $v_x$ \\ + * $0$ & $1$ & $0$ & $v_y$ \\ + * $0$ & $0$ & $1$ & $v_z$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right)\f$ + * + * \sa gluTranslate4v + */ +inline GLUmat4 gluTranslate(const GLUvec4 &v) +{ + GLUmat4 result; + + gluTranslate4v(& result, & v); + return result; +} +/*@}*/ + +/** + * Calculate a rotation matrix around an arbitrary axis + * + * \param axis Axis, based at the origin, around which to rotate + * \param angle Angle of rotation in radians + * + * If the specificed axis is not unit length, the vector will be normalized. + * + * \sa gluRotate4v + */ +inline GLUmat4 gluRotate(const GLUvec4 &axis, GLfloat angle) +{ + GLUmat4 result; + + gluRotate4v(& result, & axis, angle); + return result; +} + +/** + * Calculate a viewing transformation + * + * \param eye Position, in 3-dimensional space, of the eye point. + * \param center Position, in 3-dimensional space, that the eye is looking at. + * \param up Direction of the up vector. + * \param result Storage for the resulting matrix. + * + * Calculates a transformation matrix that maps the eye point to the origin + * and the \c center to the negative Z axis. The direction defined by \c up + * is projected onto the X/Y plane an is mapped to the positive Y axis. + * + * The calculated matrix is: + * + * \f{eqnarray*}{ + * f &=& c - e \\ + * f' &=& f \over |f| \\ + * u' &=& u \over |u| \\ + * s &=& f \times u \\ + * u'' &=& s \times f \\ + * M &=& + * \left( \begin{tabular}{cccc} + * $s_x$ & $s_y$ & $s_z$ & $0$ \\ + * $u''_x$ & $u''_y$ & $u''_z$ & $0$ \\ + * $-f'_x$ & $-f'_y$ & $-f'_z$ & $0$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) + * \times + * \left( \begin{tabular}{cccc} + * $1$ & $0$ & $0$ & $-e_x$ \\ + * $0$ & $1$ & $0$ & $-e_y$ \\ + * $0$ & $0$ & $1$ & $-e_z$ \\ + * $0$ & $0$ & $0$ & $1$ \\ + * \end{tabular} \right) \\ + * \f} + * + * \sa gluLookAt4v + */ +inline GLUmat4 gluLookAt(const GLUvec4 &eye, const GLUvec4 ¢er, + const GLUvec4 &up) +{ + GLUmat4 result; + + gluLookAt4v(& result, & eye, & center, & up); + return result; +} + +/** + * Calculate the determinant of a matrix. + * + * \sa gluDeterminant4_4m + */ +inline GLfloat gluDeterminant4(const GLUmat4 &m) +{ + return gluDeterminant4_4m(& m); +} + +/** + * Calculate the inverse of a matrix. + * + * Inverts the matrix \c m and stores the result in \c result. If \c m is + * not invertable, \c result is not modified + * + * \return + * If the matrix is invertable (i.e., the determinant is not zero), \c GL_TRUE + * is returned. Otherwise GL_FALSE is returned. + * + * \sa gluInverse4_4m + */ +inline GLboolean gluInverse4(GLUmat4 &result, const GLUmat4 &m) +{ + return gluInverse4_4m(& result, & m); +} + +/** + * Calculate the inverse of a matrix. + * + * \return + * The inverse of the matrix \c m. If \c m is not invertable, the return + * result is undefined. + * + * \warning + * This function is really only safe when the input matrix is known to be + * invertable. Nearly all well behaved transformation matrices fall into this + * category. + * + * \sa gluInverse4_4m + */ +inline GLUmat4 gluInverse4(const GLUmat4 &m) +{ + GLUmat4 result; + + gluInverse4_4m(& result, & m); + return result; +} + + +inline GLUmat4 GLUarcball::drag(unsigned end_x, unsigned end_y) +{ + GLUmat4 result; + + gluArcballDrag(this, & result, end_x, end_y); + return result; +} +#endif /* __cplusplus */ + +#if defined(__cplusplus) +extern "C" { +#endif +/** + * \name Shading language helper functions + */ +/*@{*/ +/** + * Initialize the GLSL compiler infrastructure + * + * This function \b must be called before any of the GLU3 GLSL helper functions + * can be used. On Windows, this function must be called each time a context + * with a different color depth is made current. + * + * It is the responsibility of the caller to verify that the required version + * of GLSL and the required shader targets (e.g., geometry) are supported. + * + * \return + * If GLSL is available, \c true is returned. Otherwise \c false is returned. + */ +extern bool gluInitializeCompiler(void); + +/** + * Compile a shader + * + * Creates a new shader object for the specified target and compiles the + * supplied code into that shader object. If \c log_ptr is not \c NULL, a + * buffer will be allocated and filled with diagnostic messages from the + * shading language compiler. A pointer to this buffer will stored in + * \c log_ptr. + * + * The pointer stored in \c log_ptr must be later released with + * \c gluReleaseInfoLog. + * + * \param target Shader execution unit (e.g., \c GL_VERTEX_SHADER) + * \param code Shader source code + * \param log_ptr Location to store a pointer to the compiler generate info log + * + * \return + * If compilation was successful, the shader object is returned. On failure + * zero is returned. + * + * \sa gluReleaseInfoLog + */ +extern GLint gluCompileShader(GLenum target, const char *code, char **log_ptr); + +/** + * Link a shader program + * + * Links the specified shader program. If \c log_ptr is not \c NULL, a buffer + * will be allocated and filled with diagnostic messages from the shading + * language linker. A pointer to this buffer will stored in \c log_ptr. + * + * The pointer stored in \c log_ptr must be later released with + * \c gluReleaseInfoLog. + * + * \param prog Shading language program to be linked + * \param log_ptr Location to store a pointer to the compiler generate info log + * + * \return + * If linking was successful, \c true is returned. Otherwise \c false is + * returned. + * + * \sa gluReleaseInfoLog + */ +extern bool gluLinkProgram(GLuint prog, char **log_ptr); + +/** + * Attach a list of shader objects to a program + * + * Attaches a zero-terminated list of shader objects to a program object. + * + * \param prog Shading language program to which shaders will be attached + * \param shader First shader to be attached to the program + */ +extern void gluAttachShaders(GLuint prog, GLuint shader, ...); + +/** + * Bind a set of shader program attributes to locations + * + * Bind the locations of a set of attributes. The list of attributes is + * terminate by a \c NULL \c name pointer. + * + * \param prog Shading language program whose attribute locations will + * be set + * \param name Name of the first attribute to set + * \param location Location of the first attribute + */ +extern void gluBindAttributes(GLuint prog, const char *name, unsigned location, + ...); + +/** + * Release an info log + * + * Release an info log generated by a call to \c gluLinkProgram or + * \c gluCompileShader. + * + * \param log Info log buffer to be released + * + * \sa gluCompileShader, gluLinkProgram + */ +extern void gluReleaseInfoLog(char *log); +/*@}*/ +#if defined(__cplusplus) +}; +#endif + +#include "glu3_scalar.h" + +#endif /* __glu3_h__ */ diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/GLU3/glu3_scalar.h b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/GLU3/glu3_scalar.h new file mode 100644 index 000000000..d4fc03422 --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/inc/GLU3/glu3_scalar.h @@ -0,0 +1,396 @@ +/* + * Copyright © 2009 Ian D. Romanick + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#ifdef _MSC_VER +# define INLINE __forceinline +#elif defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__) +# define INLINE inline __attribute__((gnu_inline)) +#else +# define INLINE inline +#endif + +extern INLINE void gluMult4v_4v(GLUvec4 *result, + const GLUvec4 *v1, const GLUvec4 *v2) +{ + result->values[0] = v1->values[0] * v2->values[0]; + result->values[1] = v1->values[1] * v2->values[1]; + result->values[2] = v1->values[2] * v2->values[2]; + result->values[3] = v1->values[3] * v2->values[3]; +} + + +extern INLINE void gluDiv4v_4v(GLUvec4 *result, + const GLUvec4 *v1, const GLUvec4 *v2) +{ + result->values[0] = v1->values[0] / v2->values[0]; + result->values[1] = v1->values[1] / v2->values[1]; + result->values[2] = v1->values[2] / v2->values[2]; + result->values[3] = v1->values[3] / v2->values[3]; +} + + +extern INLINE void gluAdd4v_4v(GLUvec4 *result, + const GLUvec4 *v1, const GLUvec4 *v2) +{ + result->values[0] = v1->values[0] + v2->values[0]; + result->values[1] = v1->values[1] + v2->values[1]; + result->values[2] = v1->values[2] + v2->values[2]; + result->values[3] = v1->values[3] + v2->values[3]; +} + + +extern INLINE void gluSub4v_4v(GLUvec4 *result, + const GLUvec4 *v1, const GLUvec4 *v2) +{ + result->values[0] = v1->values[0] - v2->values[0]; + result->values[1] = v1->values[1] - v2->values[1]; + result->values[2] = v1->values[2] - v2->values[2]; + result->values[3] = v1->values[3] - v2->values[3]; +} + + +extern INLINE void gluMult4v_f(GLUvec4 *result, + const GLUvec4 *v1, GLfloat f) +{ + result->values[0] = v1->values[0] * f; + result->values[1] = v1->values[1] * f; + result->values[2] = v1->values[2] * f; + result->values[3] = v1->values[3] * f; +} + + +extern INLINE void gluDiv4v_f(GLUvec4 *result, + const GLUvec4 *v1, GLfloat f) +{ + result->values[0] = v1->values[0] / f; + result->values[1] = v1->values[1] / f; + result->values[2] = v1->values[2] / f; + result->values[3] = v1->values[3] / f; +} + + +extern INLINE void gluAdd4v_f(GLUvec4 *result, + const GLUvec4 *v1, GLfloat f) +{ + result->values[0] = v1->values[0] + f; + result->values[1] = v1->values[1] + f; + result->values[2] = v1->values[2] + f; + result->values[3] = v1->values[3] + f; +} + + +extern INLINE void gluSub4v_f(GLUvec4 *result, + const GLUvec4 *v1, GLfloat f) +{ + result->values[0] = v1->values[0] - f; + result->values[1] = v1->values[1] - f; + result->values[2] = v1->values[2] - f; + result->values[3] = v1->values[3] - f; +} + + +extern INLINE void gluMult4m_f(GLUmat4 *result, + const GLUmat4 *m, GLfloat f) +{ + GLUmat4 temp; + + gluMult4v_f(& temp.col[0], & m->col[0], f); + gluMult4v_f(& temp.col[1], & m->col[1], f); + gluMult4v_f(& temp.col[2], & m->col[2], f); + gluMult4v_f(& temp.col[3], & m->col[3], f); + *result = temp; +} + + +extern INLINE void gluMult4m_4v(GLUvec4 *result, + const GLUmat4 *m, const GLUvec4 *v) +{ + GLUvec4 temp[6]; + unsigned i; + + for (i = 0; i < 4; i++) { + gluMult4v_f(& temp[i], & m->col[i], v->values[i]); + } + + gluAdd4v_4v(& temp[4], & temp[0], & temp[1]); + gluAdd4v_4v(& temp[5], & temp[2], & temp[3]); + gluAdd4v_4v(result, & temp[4], & temp[5]); +} + + +extern INLINE void gluAdd4m_4m(GLUmat4 *result, + const GLUmat4 *m1, const GLUmat4 *m2) +{ + GLUmat4 temp; + + gluAdd4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]); + gluAdd4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]); + gluAdd4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]); + gluAdd4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]); + *result = temp; +} + +extern INLINE void gluSub4m_4m(GLUmat4 *result, + const GLUmat4 *m1, const GLUmat4 *m2) +{ + GLUmat4 temp; + + gluSub4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]); + gluSub4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]); + gluSub4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]); + gluSub4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]); + *result = temp; +} + +extern INLINE GLfloat gluDot4_4v(const GLUvec4 *v1, const GLUvec4 *v2) +{ + return v1->values[0] * v2->values[0] + + v1->values[1] * v2->values[1] + + v1->values[2] * v2->values[2] + + v1->values[3] * v2->values[3]; +} + + +extern INLINE GLfloat gluDot3_4v(const GLUvec4 *v1, const GLUvec4 *v2) +{ + return v1->values[0] * v2->values[0] + + v1->values[1] * v2->values[1] + + v1->values[2] * v2->values[2]; +} + + +extern INLINE GLfloat gluDot2_4v(const GLUvec4 *v1, const GLUvec4 *v2) +{ + return v1->values[0] * v2->values[0] + + v1->values[1] * v2->values[1]; +} + + +extern INLINE void gluCross4v(GLUvec4 *result, + const GLUvec4 *v1, const GLUvec4 *v2) +{ + GLUvec4 temp; + + temp.values[0] = (v1->values[1] * v2->values[2]) + - (v1->values[2] * v2->values[1]); + temp.values[1] = (v1->values[2] * v2->values[0]) + - (v1->values[0] * v2->values[2]); + temp.values[2] = (v1->values[0] * v2->values[1]) + - (v1->values[1] * v2->values[0]); + temp.values[3] = 0.0; + *result = temp; +} + + +extern INLINE void gluOuter4v(GLUmat4 *result, + const GLUvec4 *v1, const GLUvec4 *v2) +{ + GLUmat4 temp; + + gluMult4v_f(& temp.col[0], v1, v2->values[0]); + gluMult4v_f(& temp.col[1], v1, v2->values[1]); + gluMult4v_f(& temp.col[2], v1, v2->values[2]); + gluMult4v_f(& temp.col[3], v1, v2->values[3]); + *result = temp; +} + + +extern INLINE GLfloat gluLengthSqr4v(const GLUvec4 *v) +{ + return gluDot4_4v(v, v); +} + + +extern INLINE GLfloat gluLength4v(const GLUvec4 *v) +{ + return (GLfloat) sqrt(gluLengthSqr4v(v)); +} + + +extern INLINE void gluNormalize4v(GLUvec4 *result, const GLUvec4 *v) +{ + gluDiv4v_f(result, v, gluLength4v(v)); +} + + + +extern INLINE void gluTranspose4m(GLUmat4 *result, const GLUmat4 *m) +{ + unsigned i; + unsigned j; + GLUmat4 temp; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp.col[i].values[j] = m->col[j].values[i]; + } + } + + *result = temp; +} + + +extern INLINE void gluMult4m_4m(GLUmat4 *result, + const GLUmat4 *m1, const GLUmat4 *m2) +{ + GLUmat4 temp; + unsigned i; + + for (i = 0; i < 4; i++) { + gluMult4m_4v(& temp.col[i], m1, & m2->col[i]); + } + + *result = temp; +} + + + +extern INLINE void gluTranslate3f(GLUmat4 *result, + GLfloat x, GLfloat y, GLfloat z) +{ + memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix)); + result->col[3].values[0] = x; + result->col[3].values[1] = y; + result->col[3].values[2] = z; +} + + +#ifdef __cplusplus +extern INLINE GLfloat gluDot4(const GLUvec4 &v1, const GLUvec4 &v2) +{ + return v1.values[0] * v2.values[0] + + v1.values[1] * v2.values[1] + + v1.values[2] * v2.values[2] + + v1.values[3] * v2.values[3]; +} + + +extern INLINE GLfloat gluDot3(const GLUvec4 &v1, const GLUvec4 &v2) +{ + return v1.values[0] * v2.values[0] + + v1.values[1] * v2.values[1] + + v1.values[2] * v2.values[2]; +} + + +extern INLINE GLfloat gluDot2(const GLUvec4 &v1, const GLUvec4 &v2) +{ + return v1.values[0] * v2.values[0] + + v1.values[1] * v2.values[1]; +} + + +INLINE GLUvec4 GLUvec4::operator+(const GLUvec4 &v) const +{ + return GLUvec4(values[0] + v.values[0], + values[1] + v.values[1], + values[2] + v.values[2], + values[3] + v.values[3]); +} + + +INLINE GLUvec4 GLUvec4::operator-(const GLUvec4 &v) const +{ + return GLUvec4(values[0] - v.values[0], + values[1] - v.values[1], + values[2] - v.values[2], + values[3] - v.values[3]); +} + + +INLINE GLUvec4 GLUvec4::operator*(const GLUvec4 &v) const +{ + return GLUvec4(values[0] * v.values[0], + values[1] * v.values[1], + values[2] * v.values[2], + values[3] * v.values[3]); +} + + +INLINE GLUvec4 GLUvec4::operator*(GLfloat f) const +{ + return GLUvec4(values[0] * f, + values[1] * f, + values[2] * f, + values[3] * f); +} + + +INLINE GLUvec4 GLUvec4::operator*(const GLUmat4 &m) const +{ + return GLUvec4(gluDot4(*this, m.col[0]), + gluDot4(*this, m.col[1]), + gluDot4(*this, m.col[2]), + gluDot4(*this, m.col[3])); +} + + +INLINE GLUmat4 GLUmat4::operator+(const GLUmat4 &m) const +{ + GLUmat4 temp; + + gluAdd4m_4m(& temp, this, &m); + return temp; +} + + +INLINE GLUmat4 GLUmat4::operator-(const GLUmat4 &m) const +{ + return GLUmat4(col[0] - m.col[0], + col[1] - m.col[1], + col[2] - m.col[2], + col[3] - m.col[3]); +} + + +INLINE GLUmat4 GLUmat4::operator*(GLfloat f) const +{ + GLUmat4 temp; + + gluMult4m_f(& temp, this, f); + return temp; +} + + +INLINE GLUvec4 GLUmat4::operator*(const GLUvec4 &v) const +{ + return (col[0] * v.values[0]) + + (col[1] * v.values[1]) + + (col[2] * v.values[2]) + + (col[3] * v.values[3]); +} + + +INLINE GLUmat4 GLUmat4::operator*(const GLUmat4 &m) const +{ + GLUmat4 temp; + + gluMult4m_4m(& temp, this, &m); + return temp; +} + + +#endif /* __cplusplus */ diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/fsl_egl.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/fsl_egl.c new file mode 100644 index 000000000..f8ac3d7db --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/fsl_egl.c @@ -0,0 +1,475 @@ +/**************************************************************************** +* Copyright (c) 2012 Freescale Semiconductor, Inc. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* * Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* * Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* * Neither the name of the Freescale Semiconductor, Inc. nor the names of +* its contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Labels parameters + +*****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#ifdef EGL_USE_X11 +#include +#include +#elif EGL_API_WL +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct geometry { + int width; + int height; +}; + +struct display; + +struct window { + struct display *display; + struct wl_egl_window *native; + struct geometry geometry, window_size; + struct wl_surface *surface; + struct wl_shell_surface *shell_surface; + EGLSurface egl_surface; + struct wl_callback *callback; + int fullscreen, configured, opaque; +}; + +struct display { + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_shell *shell; + struct wl_seat *seat; + struct wl_pointer *pointer; + struct wl_keyboard *keyboard; + struct wl_shm *shm; + struct wl_cursor_theme *cursor_theme; + struct wl_cursor *default_cursor; + struct wl_surface *cursor_surface; + struct window *window; +}; + +struct display sdisplay = { 0 }; +struct window swindow = { 0 }; + +static void +create_wl_surface(VOID_ARGUMENT) +{ + struct display * display = &sdisplay; + struct window * window = &swindow; + + window->surface = wl_compositor_create_surface(display->compositor); + window->shell_surface = wl_shell_get_shell_surface(display->shell, + window->surface); + + window->native = + wl_egl_window_create(window->surface, + window->window_size.width, + window->window_size.height); + + wl_shell_surface_set_title(window->shell_surface, "3DMark for GLES2.0"); + + wl_shell_surface_set_fullscreen(window->shell_surface, + WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, + 0, NULL); +} + +static void +configure_callback(void *data, struct wl_callback *callback, uint32_t time) +{ + struct window *window = (struct window *)data; + + wl_callback_destroy(callback); + + window->configured = 1; +} + +static struct wl_callback_listener configure_callback_listener = { + configure_callback, +}; + +static void +handle_ping(void *data, struct wl_shell_surface *shell_surface, + uint32_t serial) +{ + wl_shell_surface_pong(shell_surface, serial); +} + +static void +handle_configure(void *data, struct wl_shell_surface *shell_surface, + uint32_t edges, int32_t width, int32_t height) +{ + struct window *window = (struct window *)data; + + if (window->native) + wl_egl_window_resize(window->native, width, height, 0, 0); + + window->geometry.width = width; + window->geometry.height = height; + + if (!window->fullscreen) + window->window_size = window->geometry; +} + +static void +handle_popup_done(void *data, struct wl_shell_surface *shell_surface) +{ +} + +static const struct wl_shell_surface_listener shell_surface_listener = { + handle_ping, + handle_configure, + handle_popup_done +}; + + +static void +toggle_fullscreen(struct window *window, int fullscreen) +{ + struct wl_callback *callback; + + window->fullscreen = fullscreen; + window->configured = 0; + + if (fullscreen) { + wl_shell_surface_set_fullscreen(window->shell_surface, + WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, + 0, NULL); + } else { + wl_shell_surface_set_toplevel(window->shell_surface); + handle_configure(window, window->shell_surface, 0, + window->window_size.width, + window->window_size.height); + } + + callback = wl_display_sync(window->display->display); + wl_callback_add_listener(callback, &configure_callback_listener, + window); +} + + +static void +pointer_handle_enter(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface, + wl_fixed_t sx, wl_fixed_t sy) +{ + struct display *display = (struct display *)data; + struct wl_buffer *buffer; + struct wl_cursor *cursor = display->default_cursor; + struct wl_cursor_image *image; + + if (display->window->fullscreen) + wl_pointer_set_cursor(pointer, serial, NULL, 0, 0); + else if (cursor) { + image = display->default_cursor->images[0]; + buffer = wl_cursor_image_get_buffer(image); + wl_pointer_set_cursor(pointer, serial, + display->cursor_surface, + image->hotspot_x, + image->hotspot_y); + wl_surface_attach(display->cursor_surface, buffer, 0, 0); + wl_surface_damage(display->cursor_surface, 0, 0, + image->width, image->height); + wl_surface_commit(display->cursor_surface); + } +} + +static void +pointer_handle_leave(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface) +{ +} + +static void +pointer_handle_motion(void *data, struct wl_pointer *pointer, + uint32_t time, wl_fixed_t sx, wl_fixed_t sy) +{ +} + +static void +pointer_handle_button(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, uint32_t time, uint32_t button, + uint32_t state) +{ + struct display *display = (struct display *)data; + + if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + wl_shell_surface_move(display->window->shell_surface, + display->seat, serial); +} + +static void +pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis, wl_fixed_t value) +{ +} + +static const struct wl_pointer_listener pointer_listener = { + pointer_handle_enter, + pointer_handle_leave, + pointer_handle_motion, + pointer_handle_button, + pointer_handle_axis, +}; + +static void +keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, + uint32_t format, int fd, uint32_t size) +{ +} + +static void +keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, + uint32_t serial, struct wl_surface *surface, + struct wl_array *keys) +{ +} + +static void +keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, + uint32_t serial, struct wl_surface *surface) +{ +} + +static void +keyboard_handle_key(void *data, struct wl_keyboard *keyboard, + uint32_t serial, uint32_t time, uint32_t key, + uint32_t state) +{ + struct display *d = (struct display *)data; + + if (key == KEY_F11 && state) + toggle_fullscreen(d->window, d->window->fullscreen ^ 1); +} + +static void +keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, + uint32_t serial, uint32_t mods_depressed, + uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) +{ +} + +static const struct wl_keyboard_listener keyboard_listener = { + keyboard_handle_keymap, + keyboard_handle_enter, + keyboard_handle_leave, + keyboard_handle_key, + keyboard_handle_modifiers, +}; + + +static void +seat_handle_capabilities(void *data, struct wl_seat *seat, + uint32_t caps) +{ + struct display *d = (struct display *)data; + + if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) { + d->pointer = wl_seat_get_pointer(seat); + wl_pointer_add_listener(d->pointer, &pointer_listener, d); + } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) { + wl_pointer_destroy(d->pointer); + d->pointer = NULL; + } + + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) { + d->keyboard = wl_seat_get_keyboard(seat); + wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d); + } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) { + wl_keyboard_destroy(d->keyboard); + d->keyboard = NULL; + } +} + +static const struct wl_seat_listener seat_listener = { + seat_handle_capabilities, +}; + + +static void +registry_handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + struct display *d = (struct display *)data; + + if (strcmp(interface, "wl_compositor") == 0) { + d->compositor = + (struct wl_compositor*)wl_registry_bind(registry, name,&wl_compositor_interface, 1); + } else if (strcmp(interface, "wl_shell") == 0) { + d->shell = (struct wl_shell *)wl_registry_bind(registry, name, + &wl_shell_interface, 1); + } else if (strcmp(interface, "wl_seat") == 0) { + d->seat = (struct wl_seat *)wl_registry_bind(registry, name, + &wl_seat_interface, 1); + wl_seat_add_listener(d->seat, &seat_listener, d); + } else if (strcmp(interface, "wl_shm") == 0) { + d->shm = (struct wl_shm *)wl_registry_bind(registry, name, + &wl_shm_interface, 1); + d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm); + d->default_cursor = + wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); + } +} + +static const struct wl_registry_listener registry_listener = { + registry_handle_global +}; +#endif + +EGLNativeDisplayType fsl_getNativeDisplay() +{ + EGLNativeDisplayType eglNativeDisplayType = NULL; +#if (defined EGL_USE_X11) + eglNativeDisplayType = XOpenDisplay(NULL); + assert(eglNativeDisplayType != NULL); +#elif EGL_API_WL + sdisplay.display = wl_display_connect(NULL); + sdisplay.registry = wl_display_get_registry(sdisplay.display); + wl_registry_add_listener(sdisplay.registry, + ®istry_listener, &sdisplay); + wl_display_dispatch(sdisplay.display); + + return sdisplay.display; +#elif (defined EGL_API_FB) + eglNativeDisplayType = fbGetDisplayByIndex(0); //Pass the argument as required to show the framebuffer +#else + display = EGL_DEFAULT_DISPLAY; +#endif + return eglNativeDisplayType; +} + +EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType) +{ + EGLNativeWindowType native_window = (EGLNativeWindowType)0; + +#if (defined EGL_USE_X11) + Window window, rootwindow; + int screen = DefaultScreen(eglNativeDisplayType); + rootwindow = RootWindow(eglNativeDisplayType,screen); + window = XCreateSimpleWindow(eglNativeDisplayType, rootwindow, 0, 0, 400, 533, 0, 0, WhitePixel (eglNativeDisplayType, screen)); + XMapWindow(eglNativeDisplayType, window); + native_window = window; +#elif EGL_API_WL + swindow.window_size.width = 800; + swindow.window_size.height = 480; + + swindow.display = &sdisplay; + sdisplay.window = &swindow; + + sdisplay.registry = wl_display_get_registry(sdisplay.display); + wl_registry_add_listener(sdisplay.registry, + ®istry_listener, &sdisplay); + wl_display_dispatch(sdisplay.display); + create_wl_surface(); + + native_window = swindow.native; + + sdisplay.cursor_surface = + wl_compositor_create_surface(sdisplay.compositor); + +#else + const char *vendor = eglQueryString(egldisplay, EGL_VENDOR); + if (strstr(vendor, "Imagination Technologies")) + native_window = (EGLNativeWindowType)0; + else if (strstr(vendor, "AMD")) + native_window = (EGLNativeWindowType) open("/dev/fb0", O_RDWR); + else if (strstr(vendor, "Vivante")) //NEEDS FIX - functs don't exist on other platforms + { +#if (defined EGL_API_FB) + native_window = fbCreateWindow(eglNativeDisplayType, 0, 0, 0, 0); +#endif + } + else + { + printf("Unknown vendor [%s]\n", vendor); + return 0; + } +#endif + return native_window; + +} + + +void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType, EGLNativeDisplayType eglNativeDisplayType) +{ + (void) eglNativeWindowType; +#if (defined EGL_USE_X11) + //close x display + XCloseDisplay(eglNativeDisplayType); +#elif EGL_API_WL + struct display * display = &sdisplay; + struct window * window = &swindow; + + if(eglNativeWindowType) + { + wl_egl_window_destroy(window->native); + wl_shell_surface_destroy(window->shell_surface); + wl_surface_destroy(window->surface); + if (window->callback) + wl_callback_destroy(window->callback); + } + + wl_surface_destroy(display->cursor_surface); + + if (display->cursor_theme) + wl_cursor_theme_destroy(display->cursor_theme); + + if (display->shell) + wl_shell_destroy(display->shell); + + if (display->compositor) + wl_compositor_destroy(display->compositor); + + wl_display_flush(display->display); + wl_display_disconnect(display->display); + +#endif +} diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/fslutil.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/fslutil.c new file mode 100644 index 000000000..c98508d2a --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/fslutil.c @@ -0,0 +1,935 @@ +/**************************************************************************** +* Copyright (c) 2012 Freescale Semiconductor, Inc. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* * Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* * Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* * Neither the name of the Freescale Semiconductor, Inc. nor the names of +* its contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Labels parameters + +*****************************************************************************/ + +#define GL_FUNCS 1 + + +#include +#include + +#include +#include +#include + +int LoadBMP(char *filename, Image *image) +{ + FILE *file; + unsigned long size; // size of the image in bytes. + unsigned long i; // standard counter. + unsigned short int planes; // number of planes in image (must be 1) + unsigned short int bpp; // number of bits per pixel (must be 24) + char temp; // temporary color storage for bgr-rgb conversion. + + // make sure the file is there. + if ((file = fopen(filename, "rb"))==NULL) + { + printf("File Not Found : %s\n",filename); + return 0; + } + + // seek through the bmp header, up to the width/height: + fseek(file, 18, SEEK_CUR); + + // read the width + if ((i = fread(&image->sizeX, 4, 1, file)) != 1) + { + printf("Error reading width from %s.\n", filename); + return 0; + } + + + // read the height + if ((i = fread(&image->sizeY, 4, 1, file)) != 1) + { + printf("Error reading height from %s.\n", filename); + return 0; + } + + // calculate the size (assuming 24 bits or 3 bytes per pixel). + size = image->sizeX * image->sizeY * 3; + //printf("size is %lu\n",size); + + // read the planes + if ((fread(&planes, 2, 1, file)) != 1) + { + printf("Error reading planes from %s.\n", filename); + return 0; + } + if (planes != 1) + { + printf("Planes from %s is not 1: %u\n", filename, planes); + return 0; + } + + // read the bpp + if ((i = fread(&bpp, 2, 1, file)) != 1) + { + printf("Error reading bpp from %s.\n", filename); + return 0; + } + if (bpp != 24) + { + printf("Bpp from %s is not 24: %u\n", filename, bpp); + return 0; + } + + // seek past the rest of the bitmap header. + fseek(file, 24, SEEK_CUR); + + // read the data. + image->data = (char *) malloc(size); + if (image->data == NULL) + { + printf("Error allocating memory for color-corrected image data"); + return 0; + } + + if ((i = fread(image->data, size, 1, file)) != 1) + { + printf("Error reading image data from %s.\n", filename); + return 0; + } + + for (i=0;i rgb) + temp = image->data[i]; + image->data[i] = image->data[i+2]; + image->data[i+2] = temp; + } + + + // we're done. + return 1; +} + + +int LoadTGA(const char *textureFileName, Image *image) +{ + FILE *f = fopen(textureFileName, "rb"); +#ifdef UNDER_CE + if (f == NULL) + { + wchar_t moduleName[MAX_PATH]; + char path[MAX_PATH], * p; + GetModuleFileName(NULL, moduleName, MAX_PATH); + wcstombs(path, moduleName, MAX_PATH); + p = strrchr(path, '\\'); + strcpy(p + 1, textureFileName); + f = fopen(path, "rb"); + } +#endif + if(!f) return 0; + + unsigned short width, height; + unsigned char widthLow, widthHigh, heightLow, heightHigh; + unsigned char headerLength = 0; + unsigned char imageType = 0; + unsigned char bits = 0; + int format= 0; + int lineWidth = 0; + + fread(&headerLength, sizeof(unsigned char), 1, f); + fseek(f,1,SEEK_CUR); + fread(&imageType, sizeof(unsigned char), 1, f); + fseek(f, 9, SEEK_CUR); + fread(&widthLow, sizeof(unsigned char), 1, f); + fread(&widthHigh, sizeof(unsigned char), 1, f); + width = (widthHigh << 16) + widthLow; + fread(&heightLow, sizeof(unsigned char), 1, f); + fread(&heightHigh, sizeof(unsigned char), 1, f); + height = (heightHigh << 16) + heightLow; + fread(&bits, sizeof(unsigned char), 1, f); + + image->sizeX = width; + image->sizeY = height; + + printf("width=%d height=%d\n", width, height); + + /* Check pixel depth. */ + switch (bits) + { + case 16: + /* 16-bpp RGB. */ + image->Format = GL_UNSIGNED_SHORT_5_6_5; + break; + + case 24: + /* 24-bpp RGB. */ + image->Format = GL_RGB; + break; + + case 32: + /* 32-bpp RGB. */ + image->Format = GL_RGBA; + break; + + default: + /* Invalid pixel depth. */ + return 0; + } + fseek(f, headerLength + 1, SEEK_CUR); + char *buffer = NULL; + if(imageType != 10) + { + int y; + int i; + printf("bits=%d\n", bits); + if((bits == 24)||(bits == 32)) //added to support for LUMINANCE and RGBA textures + { + format = bits >> 3; + lineWidth = format * width; + buffer = malloc( (bits / 8) * lineWidth * height); + + for(y = 0; y < height; y++) + { + GLubyte *line = &buffer[lineWidth * y]; + fread(line, lineWidth, 1, f); + + if(format!= 1) + { + for(i=0;idata = buffer; + return 0; + } + } + fclose(f); + + image->data = buffer; + + return 1; +} + +//-------------------------------------------------------------------------------------- +// Name: fslLoadCTES +// Desc: Helper function to load an compressed image file (ATC, ETC, etc.) from the compressenator +// At exit nFormat contains the GL +//-------------------------------------------------------------------------------------- +char* fslLoadCTES( char* strFileName, unsigned int* pWidth, unsigned int* pHeight, + unsigned int* nFormat, unsigned int* nSize ) +{ + unsigned int nTotalBlocks, nBytesPerBlock, nHasAlpha; + char* pBits8; + + struct CTES_HEADER + { + unsigned int signature; + unsigned int width; + unsigned int height; + unsigned int flags; + unsigned int dataOffset; // From start of header/file + } header; + + // Read the file + FILE* file = fopen( strFileName, "rb" ); + if( NULL == file ) + { + printf("Error loading file: %s \n",strFileName); + return NULL; + } + + + if (fread( &header, sizeof(header), 1, file ) != 1) + { + printf("Error loading file : %s \n",strFileName); + fclose( file ); + return NULL; + } + + nTotalBlocks = ((header.width + 3) >> 2) * ((header.height + 3) >> 2); + nHasAlpha = header.flags & ATC_RGBA; + nBytesPerBlock = (nHasAlpha) ? 16 : 8; + + (*nSize) = nTotalBlocks * nBytesPerBlock; + (*pWidth) = header.width; + (*pHeight) = header.height; + + switch (header.signature) + { + case ATC_SIGNATURE: + if(nHasAlpha && (header.flags & ATC_ALPHA_INTERPOLATED)) + (*nFormat) = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; + else if(nHasAlpha) + (*nFormat) = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD; + else + (*nFormat) = GL_ATC_RGB_AMD; + break; + case ATI1N_SIGNATURE: + (*nFormat) = GL_3DC_X_AMD; + break; + case ATI2N_SIGNATURE: + (*nFormat) = GL_3DC_XY_AMD; + break; + case ETC_SIGNATURE: + if(nHasAlpha) + { + printf("Unsupported texture format\n"); + return NULL; + } + (*nFormat) = GL_ETC1_RGB8_OES; + break; + + default: + printf("Unsupported texture format\n"); + return NULL; + break; + } + pBits8 = (char*)malloc(sizeof(char) * (*nSize)); + + // Read the encoded image + fseek(file, header.dataOffset, SEEK_SET); + if (fread(pBits8, *nSize, 1, file) != 1) { + printf("Error loading file : %s \n",strFileName); + fclose( file ); + free( pBits8 ); + return NULL; + } + + fclose( file ); + + return pBits8; +} + +fslBool fslUnProject(float winx,float winy, float winz, float modelMatrix[16], float projMatrix[16], int viewport[4], float *objx, float *objy, float *objz) +{ + float finalMatrix[16]; + float finalMatrixTmp[16]; + float in[4]; + float out[4]; + + fslMultMatrix4x4(finalMatrixTmp,modelMatrix,projMatrix); + + if(!fslInvertMatrix4x4( finalMatrixTmp, finalMatrix)) + { + printf("error inverting matrix \n"); + return FSL_FALSE; + } + + in[0]=winx; + in[1]=winy; + in[2]=winz; + in[3]=1.0; + //map x and y from coordinates + in[0]=(in[0]-viewport[0])/ viewport[2]; + in[1]=(in[1]-viewport[1])/ viewport[3]; + + //map range to -1 to 1 + in[0]= in[0]*2-1; + in[1]= in[1]*2-1; + in[2]= in[2]*2-1; + //printf("in: %f %f %f \n",in[0],in[1],in[2]); + fslMultMatrix4x4Vec4x1 ( finalMatrix, in, out ); + + + if(out[3]== 0.0) + return FSL_FALSE; + + + out[0] /=out[3]; + out[1] /=out[3]; + out[2] /=out[3]; + + + *objx = out[0]; + *objy = out[1]; + *objz = out[2]; + + return FSL_TRUE; + + +} + + +//-------------------------------------------------------------------------------------- +// Name: fslEGLCheck +// Desc: Helper function to print EGL errors and exits application +//-------------------------------------------------------------------------------------- +fslBool fslEGLCheck( fslBool bExitOnFailure) +{ + EGLint eglerr = eglGetError(); + + if(eglerr != EGL_SUCCESS) + { + switch(eglerr){ + case EGL_NOT_INITIALIZED: + fprintf(stdout, "EGL Fail = EGL_NOT_INITIALIZED (0x%x) \n", eglerr); + break; + case EGL_BAD_ACCESS: + fprintf(stdout, "EGL Fail = EGL_BAD_ACCESS (0x%x) \n", eglerr); + break; + case EGL_BAD_ALLOC: + fprintf(stdout, "EGL Fail = EGL_BAD_ALLOC (0x%x) \n", eglerr); + break; + case EGL_BAD_ATTRIBUTE: + fprintf(stdout, "EGL Fail = EGL_BAD_ATTRIBUTE(0x%x) \n", eglerr); + break; + case EGL_BAD_CONFIG: + fprintf(stdout, "EGL Fail = EGL_BAD_CONFIG (0x%x) \n", eglerr); + break; + case EGL_BAD_CONTEXT: + fprintf(stdout, "EGL Fail = EGL_BAD_CONTEXT (0x%x) \n", eglerr); + break; + case EGL_BAD_CURRENT_SURFACE: + fprintf(stdout, "EGL Fail = EGL_BAD_CURRENT_SURFACE (0x%x) \n", eglerr); + break; + case EGL_BAD_DISPLAY: + fprintf(stdout, "EGL Fail = EGL_BAD_DISPLAY (0x%x) \n", eglerr); + break; + case EGL_BAD_MATCH: + fprintf(stdout, "EGL Fail = EGL_BAD_MATCH (0x%x) \n", eglerr); + break; + case EGL_BAD_NATIVE_PIXMAP: + fprintf(stdout, "EGL Fail = EGL_BAD_NATIVE_PIXMAP (0x%x) \n", eglerr); + break; + case EGL_BAD_NATIVE_WINDOW: + fprintf(stdout, "EGL Fail = EGL_BAD_NATIVE_WINDOW (0x%x) \n", eglerr); + break; + case EGL_BAD_PARAMETER: + fprintf(stdout, "EGL Fail = EGL_BAD_PARAMETER (0x%x) \n", eglerr); + break; + case EGL_BAD_SURFACE: + fprintf(stdout, "EGL Fail = EGL_BAD_SURFACE (0x%x) \n", eglerr); + break; + case EGL_CONTEXT_LOST: + fprintf(stdout, "EGL Fail = EGL_CONTEXT_LOST (0x%x) \n", eglerr); + break; + default: + fprintf(stdout, "EGL Fail = 0x%x \n", eglerr); + } + + if (bExitOnFailure) + exit(EXIT_FAILURE); + else + return FSL_FALSE; + } + + return FSL_TRUE; +} + +#ifdef GL_FUNCS +fslBool fslInit2DBMPTextureGL(char* strFileName, GLuint *pTextureHandle){ + + Image *image1; + + // allocate space for texture we will use + image1 = (Image *) malloc(sizeof(Image)); + if (image1 == NULL) { + printf("Error allocating space for image"); + exit(0); + } + + if (!LoadBMP(strFileName, image1)) { + exit(1); + } + + glGenTextures( 1, pTextureHandle ); + glBindTexture( GL_TEXTURE_2D, *pTextureHandle ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,image1->sizeX,image1->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,image1->data); + free(image1); + return FSL_TRUE; + +} + + +fslBool fslInit2DTGATextureGL(char* strFileName, unsigned int *pTextureHandle){ + + Image *image1; + + // allocate space for texture we will use + image1 = (Image *) malloc(sizeof(Image)); + if (image1 == NULL) { + printf("Error allocating space for image"); + exit(0); + } + + if (!LoadTGA(strFileName, image1)) { + printf("Error loading TGA\n"); + exit(1); + } + + glGenTextures( 1, pTextureHandle ); + glBindTexture( GL_TEXTURE_2D, *pTextureHandle ); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + /* Set unpack alignment. */ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D,0 , image1->Format, image1->sizeX,image1->sizeY,0,image1->Format,GL_UNSIGNED_BYTE,image1->data); + free(image1->data); + free(image1); + return FSL_TRUE; + +} + +//-------------------------------------------------------------------------------------- +// Name: fslInit2DCTESTextureGL +// Desc: Helper function to load a CTES texture file and bind it to a given GL texture handle +//-------------------------------------------------------------------------------------- +fslBool fslInit2DCTESTextureGL( char* strFileName, GLuint *pTextureHandle ) +{ + unsigned int nWidth, nHeight, nFormat, nSize; + char* pImageData = fslLoadCTES( strFileName, &nWidth, &nHeight, &nFormat, &nSize ); + + if( NULL == pImageData ) + { + printf("Error loading texture! \n"); + return FSL_FALSE; + } + else + { + printf("Texture [%s] succesully read (%d x %d , %d) \n",strFileName,nWidth,nHeight,nSize); + } + + glGenTextures( 1, pTextureHandle ); + glBindTexture( GL_TEXTURE_2D, *pTextureHandle ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glCompressedTexImage2D( GL_TEXTURE_2D, 0, nFormat, nWidth, nHeight, 0, nSize, pImageData ); + free(pImageData); + + return FSL_TRUE; +} +#endif + +#ifdef FSL_EGL_USE_X11 +//-------------------------------------------------------------------------------------- +// Name: fslLoadFontX +// Desc: Helper function to load a X11 font into given struct +//-------------------------------------------------------------------------------------- +void fslLoadFontX(Display *display, XFontStruct **font_info) +{ + char *fontname = "9x15"; + + if ((*font_info=XLoadQueryFont(display,fontname)) == NULL) + { + printf("stderr, basicwin: cannot open 9x15 font\n"); + exit(EXIT_FAILURE); + } +} + +//-------------------------------------------------------------------------------------- +// Name: fslErrorHandlerX +// Desc: Helper function to print incoming X11 server errors +//-------------------------------------------------------------------------------------- +int fslErrorHandlerX( Display *display, XErrorEvent *error ) +{ + char errorText[1024]; + XGetErrorText( display, error->error_code, errorText, sizeof(errorText) ); + printf( "\t --- X Error: %s ---\n", errorText ); + return 0; +} +#endif + +//-------------------------------------------------------------------------------------- +// Name: fslGetTickCount +// Desc: Helper function to get current time +//-------------------------------------------------------------------------------------- +unsigned int fslGetTickCount() +{ + struct timeval tv; + if(gettimeofday(&tv, NULL) != 0) + { + return 0; + } + + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +//-------------------------------------------------------------------------------------- +// Name: fslMulMatrix4x4 +// Desc: 4x4 Matix Muliply +//-------------------------------------------------------------------------------------- +void fslMultMatrix4x4( float *matC, float *matA, float *matB) +{ + matC[ 0] = matA[ 0] * matB[ 0] + matA[ 1] * matB[ 4] + matA[ 2] * matB[ 8] + matA[ 3] * matB[12]; + matC[ 1] = matA[ 0] * matB[ 1] + matA[ 1] * matB[ 5] + matA[ 2] * matB[ 9] + matA[ 3] * matB[13]; + matC[ 2] = matA[ 0] * matB[ 2] + matA[ 1] * matB[ 6] + matA[ 2] * matB[10] + matA[ 3] * matB[14]; + matC[ 3] = matA[ 0] * matB[ 3] + matA[ 1] * matB[ 7] + matA[ 2] * matB[11] + matA[ 3] * matB[15]; + matC[ 4] = matA[ 4] * matB[ 0] + matA[ 5] * matB[ 4] + matA[ 6] * matB[ 8] + matA[ 7] * matB[12]; + matC[ 5] = matA[ 4] * matB[ 1] + matA[ 5] * matB[ 5] + matA[ 6] * matB[ 9] + matA[ 7] * matB[13]; + matC[ 6] = matA[ 4] * matB[ 2] + matA[ 5] * matB[ 6] + matA[ 6] * matB[10] + matA[ 7] * matB[14]; + matC[ 7] = matA[ 4] * matB[ 3] + matA[ 5] * matB[ 7] + matA[ 6] * matB[11] + matA[ 7] * matB[15]; + matC[ 8] = matA[ 8] * matB[ 0] + matA[ 9] * matB[ 4] + matA[10] * matB[ 8] + matA[11] * matB[12]; + matC[ 9] = matA[ 8] * matB[ 1] + matA[ 9] * matB[ 5] + matA[10] * matB[ 9] + matA[11] * matB[13]; + matC[10] = matA[ 8] * matB[ 2] + matA[ 9] * matB[ 6] + matA[10] * matB[10] + matA[11] * matB[14]; + matC[11] = matA[ 8] * matB[ 3] + matA[ 9] * matB[ 7] + matA[10] * matB[11] + matA[11] * matB[15]; + matC[12] = matA[12] * matB[ 0] + matA[13] * matB[ 4] + matA[14] * matB[ 8] + matA[15] * matB[12]; + matC[13] = matA[12] * matB[ 1] + matA[13] * matB[ 5] + matA[14] * matB[ 9] + matA[15] * matB[13]; + matC[14] = matA[12] * matB[ 2] + matA[13] * matB[ 6] + matA[14] * matB[10] + matA[15] * matB[14]; + matC[15] = matA[12] * matB[ 3] + matA[13] * matB[ 7] + matA[14] * matB[11] + matA[15] * matB[15]; +} + +fslBool fslInvertMatrix4x4( float *src, float *inverse) +{ + int i, j, k, swap; + double t; + double temp[4][4]; + + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + temp[i][j] = src[i*4+j]; + } + } + + inverse[ 0] = 1.0f; + inverse[ 1] = 0.0f; + inverse[ 2] = 0.0f; + inverse[ 3] = 0.0f; + inverse[ 4] = 0.0f; + inverse[ 5] = 1.0f; + inverse[ 6] = 0.0f; + inverse[ 7] = 0.0f; + inverse[ 8] = 0.0f; + inverse[ 9] = 0.0f; + inverse[10] = 1.0f; + inverse[11] = 0.0f; + inverse[12] = 0.0f; + inverse[13] = 0.0f; + inverse[14] = 0.0f; + inverse[15] = 1.0f; + + + for (i = 0; i < 4; i++) { + /* + ** Look for largest element in column + */ + swap = i; + for (j = i + 1; j < 4; j++) { + if (fabs(temp[j][i]) > fabs(temp[i][i])) { + swap = j; + } + } + + if (swap != i) { + /* + ** Swap rows. + */ + for (k = 0; k < 4; k++) { + t = temp[i][k]; + temp[i][k] = temp[swap][k]; + temp[swap][k] = t; + + t = inverse[i*4+k]; + inverse[i*4+k] = inverse[swap*4+k]; + inverse[swap*4+k] = t; + } + } + + if (temp[i][i] == 0) { + /* + ** No non-zero pivot. The matrix is singular, which shouldn't + ** happen. This means the user gave us a bad matrix. + */ + return FSL_FALSE; + } + + t = temp[i][i]; + for (k = 0; k < 4; k++) { + temp[i][k] /= t; + inverse[i*4+k] /= t; + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp[j][i]; + for (k = 0; k < 4; k++) { + temp[j][k] -= temp[i][k]*t; + inverse[j*4+k] -= inverse[i*4+k]*t; + } + } + } + } + return FSL_TRUE; +} + +void fslPerspectiveMatrix4x4 ( float *m, float fov, float aspect, float zNear, float zFar) +{ + const float h = 1.0f/tan(fov*PI_OVER_360); + float neg_depth = zNear-zFar; + + m[0] = h / aspect; + m[1] = 0; + m[2] = 0; + m[3] = 0; + + m[4] = 0; + m[5] = h; + m[6] = 0; + m[7] = 0; + + m[8] = 0; + m[9] = 0; + m[10] = (zFar + zNear)/neg_depth; + m[11] = -1; + + m[12] = 0; + m[13] = 0; + m[14] = 2.0f*(zNear*zFar)/neg_depth; + m[15] = 0; + +} + +void fslMultMatrix4x4Vec4x1 ( float *matA, float *vecA, float *vecB ) +{ + int i; + + for ( i = 0; i < 4; i++ ) + { + vecB[i] = vecA[0] * matA[0*4+i] + vecA[1] * matA[1*4+i] + vecA[2] * matA[2*4+i] + vecA[3] * matA[3*4+i]; + } +} + +void fslRotateMatrix4x4 (float *m, float angle, fslAxis axis) +{ + float radians = PI_OVER_360*2*angle; + float rotate[16] = {0}; + + fslLoadIdentityMatrix4x4(rotate); + + switch (axis) + { + case FSL_X_AXIS: + rotate[5] = cos(radians); + rotate[6] = sin(radians); + rotate[9] = -sin(radians); + rotate[10] = cos(radians); + fslMultMatrix4x4(m, rotate, m); + break; + case FSL_Y_AXIS: + rotate[0] = cos(radians); + rotate[2] = -sin(radians); + rotate[8] = sin(radians); + rotate[10] = cos(radians); + fslMultMatrix4x4(m, rotate, m); + break; + case FSL_Z_AXIS: + rotate[0] = cos(radians); + rotate[1] = sin(radians); + rotate[4] = -sin(radians); + rotate[5] = cos(radians); + fslMultMatrix4x4(m, rotate, m); + break; + default: + printf("invalid axis \n"); + break; + + } + + +} + +void fslTranslateMatrix4x4 (float *m, float transX, float transY, float transZ) +{ + float trans[16] = {0}; + fslLoadIdentityMatrix4x4(trans); + + trans[12]=transX; + trans[13]=transY; + trans[14]=transZ; + + fslMultMatrix4x4(m, trans, m); +} + +void fslScaleMatrix4x4 (float *m, float scaleX, float scaleY, float scaleZ) +{ + float scale[16] = {0}; + fslLoadIdentityMatrix4x4(scale); + + scale[0]=scaleX; + scale[5]=scaleY; + scale[10]=scaleZ; + + fslMultMatrix4x4(m, scale, m); +} + +void fslLoadIdentityMatrix4x4 (float *m) +{ + m[0] = 1; + m[1] = 0; + m[2] = 0; + m[3] = 0; + + m[4] = 0; + m[5] = 1; + m[6] = 0; + m[7] = 0; + + m[8] = 0; + m[9] = 0; + m[10] = 1; + m[11] = 0; + + m[12] = 0; + m[13] = 0; + m[14] = 0; + m[15] = 1; +} + +float fslInnerProduct( float *v, float *q) +{ + return v[0]*q[0]+v[1]*q[1]+v[2]*q[2]; +} +//result = endpoint-startPoint +void fslDirectionVector(float *result, float *endPoint, float *startPoint) +{ + result[0]= endPoint[0]-startPoint[0]; + result[1]= endPoint[1]-startPoint[1]; + result[2]= endPoint[2]-startPoint[2]; +} +//a = crossProduct(b,c) +void fslCrossProduct(float *result, float *b, float* c) +{ + result[0]= b[1]*c[2]-c[1]*b[2]; + result[1]= b[2]*c[0]-c[2]*b[0]; + result[2]= b[0]*c[1]-c[0]*b[1]; +} +//p is the startpoint, d is the direction vector, v0,v1,v2 represent the triangle +int fslRayIntersectsTriangle(float *p, float *d,float *v0, float *v1, float *v2) +{ + float e1[3]={0.0, 0.0, 0.0}; + float e2[3]={0.0, 0.0, 0.0}; + float h[3] = {0.0, 0.0, 0.0}; + float s[3] = {0.0, 0.0, 0.0}; + float q[3] = {0.0, 0.0, 0.0}; + float a,f,u,v,t; + fslDirectionVector(e1,v1,v0); + fslDirectionVector(e2,v2,v0); + fslCrossProduct(h,d,e2); + //get the inner product + a=fslInnerProduct(e1,h); + if(a>-0.00001&& a<0.00001) + return 0; + f= 1/a; + fslDirectionVector(s,p,v0); + u=f*(fslInnerProduct(s,h)); + + if(u<0.0 || u>1.0) + return 0; + + fslCrossProduct(q,s,e1); + v = f*fslInnerProduct(d,q); + if(v< 0.0 || u+v > 1.0) + return 0; + //we can compute t to find out where the intersection point is on the line + t= f*fslInnerProduct(e2,q); + if(t > 0.00001) //ray intersection + return 1; + else + return 0; + + +} +void fslNormalize(float *v) +{ + float mag =v[0]*v[0]+v[1]*v[1]+v[2]*v[2]; + sqrt(mag); + v[0]=v[0]/mag; + v[1]=v[1]/mag; + v[2]=v[2]/mag; + //printf("vector Normalized is %f,%f,%f\n",v[0],v[1],v[2]); +} +void fslPrintMatrix4x4(float *m){ + + printf(" %f %f %f %f \n", m[0], m[1], m[2], m[3]); + printf(" %f %f %f %f \n", m[4], m[5], m[6], m[7]); + printf(" %f %f %f %f \n", m[8], m[9], m[10], m[11]); + printf(" %f %f %f %f \n", m[12], m[13], m[14], m[15]); + +} +void fslCalculateNormals(float *triangleArray, int size, float *normalArray) +{ + printf("enter fslCalculateNormals \n"); + + + int index =0; + + int i=0; + for(i=0; i< size/3; i++){ + + float v1[3]={0.0f}; + float v2[3]={0.0f}; + float v3[3]={0.0f}; + //float v4[3]={0.0f}; + + float A[3]={0.0f}; + float B[3]={0.0f}; + /*float C[3]={0.0f}; + float D[3]={0.0f};*/ + + v1[0]=triangleArray[9*i];//9 is for 9 values (3 vertices) used per loop + v1[1]=triangleArray[9*i+1]; + v1[2]=triangleArray[12*i+2]; + + v2[0]=triangleArray[9*i+3]; + v2[1]=triangleArray[9*i+4]; + v2[2]=triangleArray[9*i+5]; + + v3[0]=triangleArray[9*i+6]; + v3[1]=triangleArray[9*i+7]; + v3[2]=triangleArray[9*i+8]; + + + A[0]=v1[0]-v2[0]; + A[1]=v1[1]-v2[1]; + A[2]=v1[2]-v2[2]; + + B[0]=v2[0]-v3[0]; + B[1]=v2[1]-v3[1]; + B[2]=v2[2]-v3[2]; + float result[3]={0.0f}; + + printf("adding normal %i\n",index); + fslCrossProduct(result, A, B); + fslNormalize(result); + normalArray[3*i]=result[0]; + normalArray[3*i+1]=result[1]; + normalArray[3*i+2]=result[2]; + + printf("adding normal: %f %f %f \n",result[0],result[1],result[2]); + index++; + } +} + + + diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/glu3.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/glu3.c new file mode 100644 index 000000000..77d0762bd --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/common/src/glu3.c @@ -0,0 +1,334 @@ +/* + * Copyright © 2009 Ian D. Romanick + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define DEG2RAD(d) ((d) * M_PI / 180.0) + +#ifdef __cplusplus +const GLUmat4 gluIdentityMatrix ( { 1.0f, 0.0f, 0.0f, 0.0f } , { 0.0f, 1.0f, 0.0f, 0.0f } , { 0.0f, 0.0f, 1.0f, 0.0f } , { 0.0f, 0.0f, 0.0f, 1.0f } ); +#else +const GLUmat4 gluIdentityMatrix = { + { + { { 1.0f, 0.0f, 0.0f, 0.0f } }, + { { 0.0f, 1.0f, 0.0f, 0.0f } }, + { { 0.0f, 0.0f, 1.0f, 0.0f } }, + { { 0.0f, 0.0f, 0.0f, 1.0f } } + } +}; +#endif + +void gluTranslate4v(GLUmat4 *result, const GLUvec4 *t) +{ + memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix)); + result->col[3] = *t; + result->col[3].values[3] = 1.0f; +} + + +void gluScale4v(GLUmat4 *result, const GLUvec4 *t) +{ + memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix)); + result->col[0].values[0] = t->values[0]; + result->col[1].values[1] = t->values[1]; + result->col[2].values[2] = t->values[2]; +} + +void gluLookAt4v(GLUmat4 *result, const GLUvec4 *_eye, const GLUvec4 *_center, const GLUvec4 *_up) +{ +#ifdef __cplusplus + static const GLUvec4 col3( 0.0f, 0.0f, 0.0f, 1.0f ); + const GLUvec4 e( -_eye->values[0], -_eye->values[1], -_eye->values[2], 0.0f ); +#else + static const GLUvec4 col3 = { { 0.0f, 0.0f, 0.0f, 1.0f } }; + const GLUvec4 e = { + { -_eye->values[0], -_eye->values[1], -_eye->values[2], 0.0f } + }; + +#endif + GLUmat4 translate; + GLUmat4 rotate; + GLUmat4 rotateT; + GLUvec4 f; + GLUvec4 s; + GLUvec4 u; + GLUvec4 center, up; + + center = *_center; + center.values[3] = 0; + up = *_up; + up.values[3] = 0; + + gluAdd4v_4v(& f, ¢er, &e); + gluNormalize4v(& f, & f); + + gluNormalize4v(& u, &up); + + gluCross4v(& s, & f, & u); + gluCross4v(& u, & s, & f); + + rotate.col[0] = s; + rotate.col[1] = u; + rotate.col[2].values[0] = -f.values[0]; + rotate.col[2].values[1] = -f.values[1]; + rotate.col[2].values[2] = -f.values[2]; + rotate.col[2].values[3] = 0.0f; + rotate.col[3] = col3; + gluTranspose4m(& rotateT, & rotate); + + gluTranslate4v(& translate, & e); + gluMult4m_4m(result, & rotateT, & translate); +} + +void gluRotate4v(GLUmat4 *result, const GLUvec4 *_axis, GLfloat angle) +{ + GLUvec4 axis; + const float c = cos(angle); + const float s = sin(angle); + const float one_c = 1.0 - c; + + float xx; + float yy; + float zz; + + float xs; + float ys; + float zs; + + float xy; + float xz; + float yz; + + + gluNormalize4v(& axis, _axis); + + xx = axis.values[0] * axis.values[0]; + yy = axis.values[1] * axis.values[1]; + zz = axis.values[2] * axis.values[2]; + + xs = axis.values[0] * s; + ys = axis.values[1] * s; + zs = axis.values[2] * s; + + xy = axis.values[0] * axis.values[1]; + xz = axis.values[0] * axis.values[2]; + yz = axis.values[1] * axis.values[2]; + + + result->col[0].values[0] = (one_c * xx) + c; + result->col[0].values[1] = (one_c * xy) + zs; + result->col[0].values[2] = (one_c * xz) - ys; + result->col[0].values[3] = 0.0; + + result->col[1].values[0] = (one_c * xy) - zs; + result->col[1].values[1] = (one_c * yy) + c; + result->col[1].values[2] = (one_c * yz) + xs; + result->col[1].values[3] = 0.0; + + + result->col[2].values[0] = (one_c * xz) + ys; + result->col[2].values[1] = (one_c * yz) - xs; + result->col[2].values[2] = (one_c * zz) + c; + result->col[2].values[3] = 0.0; + + result->col[3].values[0] = 0.0; + result->col[3].values[1] = 0.0; + result->col[3].values[2] = 0.0; + result->col[3].values[3] = 1.0; +} + +void gluFrustum6f(GLUmat4 *result, + GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, + GLfloat n, GLfloat f) +{ + if ((right == left) || (top == bottom) || (n == f) + || (n < 0.0) || (f < 0.0)) + return; + + + memcpy(result, &gluIdentityMatrix, sizeof(gluIdentityMatrix)); + + result->col[0].values[0] = (2.0 * n) / (right - left); + result->col[1].values[1] = (2.0 * n) / (top - bottom); + + result->col[2].values[0] = (right + left) / (right - left); + result->col[2].values[1] = (top + bottom) / (top - bottom); + result->col[2].values[2] = -(f + n) / (f - n); + result->col[2].values[3] = -1.0; + + result->col[3].values[2] = -(2.0 * f * n) / (f - n); + result->col[3].values[3] = 0.0; +} + +void gluPerspective4f(GLUmat4 *result, + GLfloat fovy, GLfloat aspect, GLfloat n, GLfloat f) +{ + const double sine = sin(DEG2RAD(fovy / 2.0)); + const double cosine = cos(DEG2RAD(fovy / 2.0)); + const double sine_aspect = sine * aspect; + const double dz = f - n; + + + memcpy(result, &gluIdentityMatrix, sizeof(gluIdentityMatrix)); + if ((sine == 0.0) || (dz == 0.0) || (sine_aspect == 0.0)) { + return; + } + + result->col[0].values[0] = cosine / sine_aspect; + result->col[1].values[1] = cosine / sine; + result->col[2].values[2] = -(f + n) / dz; + result->col[2].values[3] = -1.0; + result->col[3].values[2] = -2.0 * n * f / dz; + result->col[3].values[3] = 0.0; +} + +void gluOrtho6f(GLUmat4 *result, + GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, + GLfloat n, GLfloat f) +{ + if ((right == left) || (top == bottom) || (n == f)) + return; + + (void) memcpy(result, & gluIdentityMatrix, sizeof(*result)); + result->col[0].values[0] = 2.0 / (right - left); + result->col[1].values[1] = 2.0 / (top - bottom); + result->col[2].values[2] = -2.0 / (f - n); + + result->col[3].values[0] = -(right + left) / (right - left); + result->col[3].values[1] = -(top + bottom) / (top - bottom); + result->col[3].values[2] = -(f + n) / (f - n); +} + +void gluOrtho4f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom, + GLfloat top) +{ + gluOrtho6f(result, left, right, bottom, top, -1.0, 1.0); +} + + +static double det3(const GLUmat4 *m, unsigned i, unsigned j) +{ + unsigned r; + unsigned c; + double det = 0.0; + GLUvec4 col[6]; + + + /* Generate a 3x3 matrix from the original matrix with the ith column + * and the jth row removed. The columns of the matrix are duplicated + * to make the 'c - r' column addressing, below, work out easier. + */ + for (c = 0; c < 4; c++) { + if (c < i) { + col[c + 0] = m->col[c]; + col[c + 3] = m->col[c]; + } else if (c > i) { + col[c - 1] = m->col[c]; + col[c + 2] = m->col[c]; + } + } + + for (r = j; r < 3; r++) { + col[0].values[r] = col[0].values[r + 1]; + col[1].values[r] = col[1].values[r + 1]; + col[2].values[r] = col[2].values[r + 1]; + col[3].values[r] = col[3].values[r + 1]; + col[4].values[r] = col[4].values[r + 1]; + col[5].values[r] = col[5].values[r + 1]; + } + + + /* Calculate the determinant of the resulting 3x3 matrix. + */ + for (c = 0; c < 3; c++) { + double diag1 = col[c].values[0]; + double diag2 = col[c].values[0]; + + for (r = 1; r < 3; r++) { + diag1 *= col[(0 + c) + r].values[r]; + diag2 *= col[(3 + c) - r].values[r]; + } + + det += (diag1 - diag2); + } + + return det; +} + +GLfloat gluDeterminant4_4m(const GLUmat4 *m) +{ + double det = 0.0; + unsigned c; + + for (c = 0; c < 4; c++) { + if (m->col[c].values[3] != 0.0) { + /* The usual equation is -1**(i+j) where i and j are + * the row and column of the matrix on the range + * [1, rows] and [1, cols]. Note that r and c are on + * the range [0, rows - 1] and [0, cols - 1]. + */ + const double sign = ((c ^ 3) & 1) ? -1.0 : 1.0; + const double d = det3(m, c, 3); + + det += sign * m->col[c].values[3] * d; + } + } + + return det; +} + + +GLboolean gluInverse4_4m(GLUmat4 *result, const GLUmat4 *m) +{ + const double det = gluDeterminant4_4m(m); + double inv_det; + unsigned c; + unsigned r; + + + if (det == 0.0) + return GL_FALSE; + + inv_det = 1.0 / det; + for (c = 0; c < 4; c++) { + for (r = 0; r < 4; r++) { + /* The usual equation is -1**(i+j) where i and j are + * the row and column of the matrix on the range + * [1, rows] and [1, cols]. Note that r and c are on + * the range [0, rows - 1] and [0, cols - 1]. + */ + const double sign = ((c ^ r) & 1) ? -1.0 : 1.0; + const double d = det3(m, c, r); + + result->col[r].values[c] = sign * inv_det * d; + } + } + + return GL_TRUE; +} + + + diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/es11_example.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/es11_example.c new file mode 100644 index 000000000..38c1600d5 --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/es11_example.c @@ -0,0 +1,419 @@ +/* + * es11_example.c + * + * This code was created by Jeff Molofee '99 + * (ported to Linux by Ti Leggett '01) + * (ported to i.mx51, i.mx31 and x11 by Freescale '10) + * If you've found this code useful, please let him know. + * + * Visit Jeff at http://nehe.gamedev.net/ + * + * Description: Rotating textured 3D object (using OpenGL ES 1.1) + * + */ + +#include +#include +#include +#include +#include +#include + +#include "GLU3/glu3.h" +#include "GLES/gl.h" + +#include "EGL/egl.h" + +#include "FSL/fsl_egl.h" +#include "FSL/fslutil.h" + +EGLDisplay egldisplay; +EGLConfig eglconfig; +EGLSurface eglsurface; +EGLContext eglcontext; +EGLNativeWindowType eglNativeWindow; +EGLNativeDisplayType eglNativeDisplayType; +volatile sig_atomic_t quit = 0; + +GLfloat xrot; /* X Rotation ( NEW ) */ +GLfloat yrot; /* Y Rotation ( NEW ) */ +GLfloat zrot; /* Z Rotation ( NEW ) */ + +GLuint texture[1]; /* Storage For One Texture ( NEW ) */ + +/* function to load in bitmap as a GL texture */ +int LoadGLTextures() +{ + Image *image1; + + // allocate space for texture we will use + image1 = (Image *) malloc(sizeof(Image)); + if (image1 == NULL) { + printf("Error allocating space for image\n"); + return 0; + } + + /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */ + if (LoadBMP("texture.bmp", image1)) { + /* Create The Texture */ + glGenTextures(1, texture); + /* Typical Texture Generation Using Data From The Bitmap */ + glBindTexture(GL_TEXTURE_2D, *texture); + /* Generate The Texture */ + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image1->sizeX, image1->sizeY, 0, GL_RGB, + GL_UNSIGNED_BYTE, image1->data); + /* Linear Filtering */ + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + return 0; + } + + /* Free up any memory we may have used */ + if (image1 != NULL) { + free(image1); + } + + return 1; +} + +/* Here goes our drawing code */ +void render() +{ + /* These are to calculate our fps */ + GLfloat texcoords[4][2]; + GLfloat vertices[4][3]; + GLubyte indices[4] = { 0, 1, 3, 2 }; /* QUAD to TRIANGLE_STRIP conversion; */ + + /* Clear The Screen And The Depth Buffer */ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* Move Into The Screen 5 Units */ + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -5.0f); + + glRotatef(xrot, 1.0f, 0.0f, 0.0f); /* Rotate On The X Axis */ + glRotatef(yrot, 0.0f, 1.0f, 0.0f); /* Rotate On The Y Axis */ + glRotatef(zrot, 0.0f, 0.0f, 1.0f); /* Rotate On The Z Axis */ + + /* Select Our Texture */ + glBindTexture(GL_TEXTURE_2D, texture[0]); + + /* Set pointers to vertices and texcoords */ + glVertexPointer(3, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texcoords); + + /* Enable vertices and texcoords arrays */ + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + /* Front Face */ + texcoords[0][0] = 0.0f; + texcoords[0][1] = 0.0f; + vertices[0][0] = -1.0f; + vertices[0][1] = -1.0f; + vertices[0][2] = 1.0f; + texcoords[1][0] = 1.0f; + texcoords[1][1] = 0.0f; + vertices[1][0] = 1.0f; + vertices[1][1] = -1.0f; + vertices[1][2] = 1.0f; + texcoords[2][0] = 1.0f; + texcoords[2][1] = 1.0f; + vertices[2][0] = 1.0f; + vertices[2][1] = 1.0f; + vertices[2][2] = 1.0f; + texcoords[3][0] = 0.0f; + texcoords[3][1] = 1.0f; + vertices[3][0] = -1.0f; + vertices[3][1] = 1.0f; + vertices[3][2] = 1.0f; + + /* Draw one textured plane using two stripped triangles */ + glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); + + /* Back Face */ + /* Normal Pointing Away From Viewer */ + texcoords[0][0] = 0.0f; + texcoords[0][1] = 1.0f; + vertices[0][0] = -1.0f; + vertices[0][1] = -1.0f; + vertices[0][2] = -1.0f; + texcoords[1][0] = 0.0f; + texcoords[1][1] = 0.0f; + vertices[1][0] = -1.0f; + vertices[1][1] = 1.0f; + vertices[1][2] = -1.0f; + texcoords[2][0] = 1.0f; + texcoords[2][1] = 0.0f; + vertices[2][0] = 1.0f; + vertices[2][1] = 1.0f; + vertices[2][2] = -1.0f; + texcoords[3][0] = 1.0f; + texcoords[3][1] = 1.0f; + vertices[3][0] = 1.0f; + vertices[3][1] = -1.0f; + vertices[3][2] = -1.0f; + + /* Draw one textured plane using two stripped triangles */ + glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); + + /* Top Face */ + texcoords[0][0] = 1.0f; + texcoords[0][1] = 0.0f; + vertices[0][0] = -1.0f; + vertices[0][1] = 1.0f; + vertices[0][2] = -1.0f; + texcoords[1][0] = 1.0f; + texcoords[1][1] = 1.0f; + vertices[1][0] = -1.0f; + vertices[1][1] = 1.0f; + vertices[1][2] = 1.0f; + texcoords[2][0] = 0.0f; + texcoords[2][1] = 1.0f; + vertices[2][0] = 1.0f; + vertices[2][1] = 1.0f; + vertices[2][2] = 1.0f; + texcoords[3][0] = 0.0f; + texcoords[3][1] = 0.0f; + vertices[3][0] = 1.0f; + vertices[3][1] = 1.0f; + vertices[3][2] = -1.0f; + + /* Draw one textured plane using two stripped triangles */ + glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); + + /* Bottom Face */ + texcoords[0][0] = 1.0f; + texcoords[0][1] = 1.0f; + vertices[0][0] = -1.0f; + vertices[0][1] = -1.0f; + vertices[0][2] = -1.0f; + texcoords[1][0] = 0.0f; + texcoords[1][1] = 1.0f; + vertices[1][0] = 1.0f; + vertices[1][1] = -1.0f; + vertices[1][2] = -1.0f; + texcoords[2][0] = 0.0f; + texcoords[2][1] = 0.0f; + vertices[2][0] = 1.0f; + vertices[2][1] = -1.0f; + vertices[2][2] = 1.0f; + texcoords[3][0] = 1.0f; + texcoords[3][1] = 0.0f; + vertices[3][0] = -1.0f; + vertices[3][1] = -1.0f; + vertices[3][2] = 1.0f; + + /* Draw one textured plane using two stripped triangles */ + glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); + + /* Right face */ + texcoords[0][0] = 0.0f; + texcoords[0][1] = 1.0f; + vertices[0][0] = 1.0f; + vertices[0][1] = -1.0f; + vertices[0][2] = -1.0f; + texcoords[1][0] = 0.0f; + texcoords[1][1] = 0.0f; + vertices[1][0] = 1.0f; + vertices[1][1] = 1.0f; + vertices[1][2] = -1.0f; + texcoords[2][0] = 1.0f; + texcoords[2][1] = 0.0f; + vertices[2][0] = 1.0f; + vertices[2][1] = 1.0f; + vertices[2][2] = 1.0f; + texcoords[3][0] = 1.0f; + texcoords[3][1] = 1.0f; + vertices[3][0] = 1.0f; + vertices[3][1] = -1.0f; + vertices[3][2] = 1.0f; + + /* Draw one textured plane using two stripped triangles */ + glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); + + /* Left Face */ + texcoords[0][0] = 0.0f; + texcoords[0][1] = 0.0f; + vertices[0][0] = -1.0f; + vertices[0][1] = -1.0f; + vertices[0][2] = -1.0f; + texcoords[1][0] = 1.0f; + texcoords[1][1] = 0.0f; + vertices[1][0] = -1.0f; + vertices[1][1] = -1.0f; + vertices[1][2] = 1.0f; + texcoords[2][0] = 1.0f; + texcoords[2][1] = 1.0f; + vertices[2][0] = -1.0f; + vertices[2][1] = 1.0f; + vertices[2][2] = 1.0f; + texcoords[3][0] = 0.0f; + texcoords[3][1] = 1.0f; + vertices[3][0] = -1.0f; + vertices[3][1] = 1.0f; + vertices[3][2] = -1.0f; + + /* Draw one textured plane using two stripped triangles */ + glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); + + /* Disable texcoords and vertices arrays */ + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + /* Flush all drawings */ + glFinish(); + + xrot += 0.3f; /* X Axis Rotation */ + yrot += 0.2f; /* Y Axis Rotation */ + zrot += 0.4f; /* Z Axis Rotation */ +} + +void resize(int w, int h) +{ + /*change to projection matrix */ + glMatrixMode(GL_PROJECTION); + /*reset the projection matrix */ + glLoadIdentity(); + /*set the viewport */ + glViewport(0, 0, w, h); + + GLUmat4 perspective; + /*use glu to set perspective */ + gluPerspective4f(&perspective, 45.0f, ((GLfloat) w / (GLfloat) h), 1.0f, 100.0f); + glMultMatrixf(&perspective.col[0].values[0]); + + /*get back to model view matrix */ + glMatrixMode(GL_MODELVIEW); + /*reset modevl view matrix */ + glLoadIdentity(); +} + +int init(void) +{ + int w = 640; + int h = 480; + + static const EGLint s_configAttribs[] = { + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 6, + EGL_BLUE_SIZE, 5, + EGL_ALPHA_SIZE, 0, + EGL_SAMPLES, 0, + EGL_NONE + }; + + EGLint numconfigs; + + //get egl display + eglNativeDisplayType = fsl_getNativeDisplay(); + egldisplay = eglGetDisplay(eglNativeDisplayType); + //Initialize egl + eglInitialize(egldisplay, NULL, NULL); + assert(eglGetError() == EGL_SUCCESS); + //tell the driver we are using OpenGL ES + eglBindAPI(EGL_OPENGL_ES_API); + + //pass our egl configuration to egl + eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs); + printf("chooseconfig, \n"); + assert(eglGetError() == EGL_SUCCESS); + assert(numconfigs == 1); + /* Enable smooth shading */ + glShadeModel(GL_SMOOTH); + + eglNativeWindow = fsl_createwindow(egldisplay, eglNativeDisplayType); + assert(eglNativeWindow); + + eglsurface = + eglCreateWindowSurface(egldisplay, eglconfig, (EGLNativeWindowType) eglNativeWindow, + NULL); + + printf("createwindow, \n"); + assert(eglGetError() == EGL_SUCCESS); + + //create the egl graphics context + eglcontext = eglCreateContext(egldisplay, eglconfig, NULL, NULL); + printf("creatcontext, \n"); + assert(eglGetError() == EGL_SUCCESS); + + //make the context current + eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext); + printf("makecurrent, \n"); + assert(eglGetError() == EGL_SUCCESS); + + /* Load in the texture */ + if (LoadGLTextures() == 0) { + return 0; + } + + /* Enable Texture Mapping ( NEW ) */ + glEnable(GL_TEXTURE_2D); + + /* Enable smooth shading */ + glShadeModel(GL_SMOOTH); + + /* Set the background black */ + glClearColor(0.0f, 0.0f, 0.0f, 0.5f); + + /* Depth buffer setup */ + glClearDepthf(1.0f); + + /* Enables Depth Testing */ + glEnable(GL_DEPTH_TEST); + + /* The Type Of Depth Test To Do */ + glDepthFunc(GL_LEQUAL); + + /*enable cullface */ + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + /* Really Nice Perspective Calculations */ + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + + /*get width and height from egl */ + eglQuerySurface(egldisplay, eglsurface, EGL_WIDTH, &w); + eglQuerySurface(egldisplay, eglsurface, EGL_HEIGHT, &h); + + /* Scale the content to the window */ + resize(w, h); + + return 1; +} + +void deinit(void) +{ + printf("Cleaning up...\n"); + eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + assert(eglGetError() == EGL_SUCCESS); + eglDestroyContext(egldisplay, eglcontext); + eglDestroySurface(egldisplay, eglsurface); + fsl_destroywindow(eglNativeWindow, eglNativeDisplayType); + eglTerminate(egldisplay); + assert(eglGetError() == EGL_SUCCESS); + eglReleaseThread(); +} + +void sighandler(int signal) +{ + printf("Caught signal %d, setting flaq to quit.\n", signal); + quit = 1; +} + +int main(void) +{ + signal(SIGINT, sighandler); + signal(SIGTERM, sighandler); + + assert(init()); + while (!quit) { + render(); + eglSwapBuffers(egldisplay, eglsurface); + } + deinit(); + + return 1; +} diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/es20_example.c b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/es20_example.c new file mode 100644 index 000000000..a3dbb93a3 --- /dev/null +++ b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/es20_example.c @@ -0,0 +1,488 @@ +/* + * This code was created by Jeff Molofee '99 + * (ported to Linux by Ti Leggett '01) + * (ported to i.mx51, i.mx31 and x11 by Freescale '10) + * If you've found this code useful, please let him know. + * + * Visit Jeff at http://nehe.gamedev.net/ + * + */ + +#include +#include +#include +#include +#include +#include + +#include "GLES2/gl2.h" +#include "GLES2/gl2ext.h" + +#include "EGL/egl.h" + +#include "FSL/fsl_egl.h" +#include "FSL/fslutil.h" + + +#define TRUE 1 +#define FALSE !TRUE +EGLDisplay egldisplay; +EGLConfig eglconfig; +EGLSurface eglsurface; +EGLContext eglcontext; +EGLNativeWindowType eglNativeWindow; +EGLNativeDisplayType eglNativeDisplayType; +volatile sig_atomic_t quit = 0; + +GLuint g_hShaderProgram = 0; +GLuint g_hModelViewMatrixLoc = 0; +GLuint g_hProjMatrixLoc = 0; +GLuint g_hVertexLoc = 0; +GLuint g_hVertexTexLoc = 2; +GLuint g_hColorLoc = 1; + + +//-------------------------------------------------------------------------------------- +// Name: g_strVertexShader / g_strFragmentShader +// Desc: The vertex and fragment shader programs +//-------------------------------------------------------------------------------------- +const char* g_strVertexShader = +"uniform mat4 g_matModelView; \n" +"uniform mat4 g_matProj; \n" +" \n" +"attribute vec4 g_vPosition; \n" +"attribute vec3 g_vColor; \n" +"attribute vec2 g_vTexCoord; \n" +" \n" +"varying vec3 g_vVSColor; \n" +"varying vec2 g_vVSTexCoord; \n" +" \n" +"void main() \n" +"{ \n" +" vec4 vPositionES = g_matModelView * g_vPosition; \n" +" gl_Position = g_matProj * vPositionES; \n" +" g_vVSColor = g_vColor; \n" +" g_vVSTexCoord = g_vTexCoord; \n" +"} \n"; + + +const char* g_strFragmentShader = +"#ifdef GL_FRAGMENT_PRECISION_HIGH \n" +" precision highp float; \n" +"#else \n" +" precision mediump float; \n" +"#endif \n" +" \n" +"uniform sampler2D s_texture; \n" +"varying vec3 g_vVSColor; \n" +"varying vec2 g_vVSTexCoord; \n" +" \n" +"void main() \n" +"{ \n" +" gl_FragColor = texture2D(s_texture,g_vVSTexCoord); \n" +"} \n"; + +float VertexPositions[] = { + /* Draw A Quad */ + /* Top Right Of The Quad (Top) */ + 1.0f, 1.0f, -1.0f, + /* Top Left Of The Quad (Top) */ + -1.0f, 1.0f, -1.0f, + /* Bottom Right Of The Quad (Top) */ + 1.0f, 1.0f, 1.0f, + /* Bottom Left Of The Quad (Top) */ + -1.0f, 1.0f, 1.0f, + /* Top Right Of The Quad (Bottom) */ + 1.0f, -1.0f, 1.0f, + /* Top Left Of The Quad (Bottom) */ + -1.0f, -1.0f, 1.0f, + /* Bottom Right Of The Quad (Bottom) */ + 1.0f, -1.0f, -1.0f, + /* Bottom Left Of The Quad (Bottom) */ + -1.0f, -1.0f, -1.0f, + /* Top Right Of The Quad (Front) */ + 1.0f, 1.0f, 1.0f, + /* Top Left Of The Quad (Front) */ + -1.0f, 1.0f, 1.0f, + /* Bottom Right Of The Quad (Front) */ + 1.0f, -1.0f, 1.0f, + /* Bottom Left Of The Quad (Front) */ + -1.0f, -1.0f, 1.0f, + /* Top Right Of The Quad (Back) */ + 1.0f, -1.0f, -1.0f, + /* Top Left Of The Quad (Back) */ + -1.0f, -1.0f, -1.0f, + /* Bottom Right Of The Quad (Back) */ + 1.0f, 1.0f, -1.0f, + /* Bottom Left Of The Quad (Back) */ + -1.0f, 1.0f, -1.0f, + /* Top Right Of The Quad (Left) */ + -1.0f, 1.0f, 1.0f, + /* Top Left Of The Quad (Left) */ + -1.0f, 1.0f, -1.0f, + /* Bottom Right Of The Quad (Left) */ + -1.0f, -1.0f, 1.0f, + /* Bottom Left Of The Quad (Left) */ + -1.0f, -1.0f, -1.0f, + /* Top Right Of The Quad (Right) */ + 1.0f, 1.0f, -1.0f, + /* Top Left Of The Quad (Right) */ + 1.0f, 1.0f, 1.0f, + /* Bottom Right Of The Quad (Right) */ + 1.0f, -1.0f, -1.0f, + /* Bottom Left Of The Quad (Right) */ + 1.0f, -1.0f, 1.0f +}; + +float VertexTexCoords[] = { + /* Top Face */ + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + /* Bottom Face */ + 1.0f, 1.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + /* Front Face */ + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + /* Back Face */ + 1.0f, 1.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f, + /*left face */ + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + /* Right face */ + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, +}; + +float VertexColors[] = { + /* Red */ + 1.0f, 0.0f, 0.0f, 1.0f, + /* Red */ + 1.0f, 0.0f, 0.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Red */ + 1.0f, 0.0, 0.0f, 1.0f, + /* Red */ + 1.0f, 0.0, 0.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Red */ + 1.0f, 0.0f, 0.0f, 1.0f, + /* Red */ + 1.0f, 0.0f, 0.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Red */ + 1.0f, 0.0f, 0.0f, 1.0f, + /* Red */ + 1.0f, 0.0f, 0.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f, + /* Blue */ + 0.0f, 0.0f, 1.0f, 1.0f, + /* Green */ + 0.0f, 1.0f, 0.0f, 1.0f +}; + +GLuint texture[1]; /* Storage For One Texture ( NEW ) */ + +/* function to load in bitmap as a GL texture */ +int LoadGLTextures() +{ + + Image *image1; + + // allocate space for texture we will use + image1 = (Image *) malloc(sizeof(Image)); + if (image1 == NULL) { + printf("Error allocating space for image"); + return 0; + } + + /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */ + if (LoadBMP("texture.bmp", image1)) { + /* Create The Texture */ + glGenTextures(1, texture); + /* Typical Texture Generation Using Data From The Bitmap */ + glBindTexture(GL_TEXTURE_2D, *texture); + /* Generate The Texture */ + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image1->sizeX, image1->sizeY, 0, GL_RGB, + GL_UNSIGNED_BYTE, image1->data); + /* Linear Filtering */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + printf("texture loaded and created successfully"); + + } else + return 0; + + /* Free up any memory we may have used */ + if (image1 != NULL) { + free(image1); + } + + return 1; +} + +void render(float w, float h) +{ + static float fAngle = 0.0f; + fAngle += 0.01f; + + // Rotate and translate the model view matrix + float matModelView[16] = { 0 }; + matModelView[0] = +cosf(fAngle); + matModelView[2] = +sinf(fAngle); + matModelView[5] = 1.0f; + matModelView[8] = -sinf(fAngle); + matModelView[10] = +cosf(fAngle); + matModelView[12] = 0.0f; //X + matModelView[14] = -6.0f; //z + matModelView[15] = 1.0f; + + // Build a perspective projection matrix + float matProj[16] = { 0 }; + matProj[0] = cosf(0.5f) / sinf(0.5f); + matProj[5] = matProj[0] * (w / h); + matProj[10] = -(10.0f) / (9.0f); + matProj[11] = -1.0f; + matProj[14] = -(10.0f) / (9.0f); + + // Clear the colorbuffer and depth-buffer + glClearColor(0.0f, 0.0f, 0.5f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Set some state + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + // Set the shader program + glUseProgram(g_hShaderProgram); + glUniformMatrix4fv(g_hModelViewMatrixLoc, 1, 0, matModelView); + glUniformMatrix4fv(g_hProjMatrixLoc, 1, 0, matProj); + + // Bind the vertex attributes + glVertexAttribPointer(g_hVertexLoc, 3, GL_FLOAT, 0, 0, VertexPositions); + glEnableVertexAttribArray(g_hVertexLoc); + + glVertexAttribPointer(g_hColorLoc, 4, GL_FLOAT, 0, 0, VertexColors); + glEnableVertexAttribArray(g_hColorLoc); + + glVertexAttribPointer(g_hVertexTexLoc, 2, GL_FLOAT, 0, 0, VertexTexCoords); + glEnableVertexAttribArray(g_hVertexTexLoc); + + /* Select Our Texture */ + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, texture[0]); + + /* Drawing Using Triangle strips, draw triangle strips using 4 vertices */ + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 8, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); + + // Cleanup + glDisableVertexAttribArray(g_hVertexLoc); + glDisableVertexAttribArray(g_hColorLoc); + glDisableVertexAttribArray(g_hVertexTexLoc); +} + + +int init(void) +{ + + /*static const EGLint gl_context_attribs[] = + { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; */ + + static const EGLint s_configAttribs[] = { + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 6, + EGL_BLUE_SIZE, 5, + EGL_ALPHA_SIZE, 0, + EGL_SAMPLES, 0, + EGL_NONE + }; + + EGLint numconfigs; + + eglNativeDisplayType = fsl_getNativeDisplay(); + egldisplay = eglGetDisplay(eglNativeDisplayType); + eglInitialize(egldisplay, NULL, NULL); + assert(eglGetError() == EGL_SUCCESS); + eglBindAPI(EGL_OPENGL_ES_API); + + eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs); + assert(eglGetError() == EGL_SUCCESS); + assert(numconfigs == 1); + + eglNativeWindow = fsl_createwindow(egldisplay, eglNativeDisplayType); + assert(eglNativeWindow); + + eglsurface = eglCreateWindowSurface(egldisplay, eglconfig, eglNativeWindow, NULL); + + assert(eglGetError() == EGL_SUCCESS); + EGLint ContextAttribList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + + eglcontext = eglCreateContext(egldisplay, eglconfig, EGL_NO_CONTEXT, ContextAttribList); + assert(eglGetError() == EGL_SUCCESS); + eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext); + assert(eglGetError() == EGL_SUCCESS); + + { + // Compile the shaders + GLuint hVertexShader = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(hVertexShader, 1, &g_strVertexShader, NULL); + glCompileShader(hVertexShader); + + // Check for compile success + GLint nCompileResult = 0; + glGetShaderiv(hVertexShader, GL_COMPILE_STATUS, &nCompileResult); + if (0 == nCompileResult) { + char strLog[1024]; + GLint nLength; + glGetShaderInfoLog(hVertexShader, 1024, &nLength, strLog); + return FALSE; + } + + GLuint hFragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(hFragmentShader, 1, &g_strFragmentShader, NULL); + glCompileShader(hFragmentShader); + + // Check for compile success + glGetShaderiv(hFragmentShader, GL_COMPILE_STATUS, &nCompileResult); + if (0 == nCompileResult) { + char strLog[1024]; + GLint nLength; + glGetShaderInfoLog(hFragmentShader, 1024, &nLength, strLog); + return FALSE; + } + // Attach the individual shaders to the common shader program + g_hShaderProgram = glCreateProgram(); + glAttachShader(g_hShaderProgram, hVertexShader); + glAttachShader(g_hShaderProgram, hFragmentShader); + + // Init attributes BEFORE linking + glBindAttribLocation(g_hShaderProgram, g_hVertexLoc, "g_vPosition"); + glBindAttribLocation(g_hShaderProgram, g_hColorLoc, "g_vColor"); + + printf("about to link shader..."); + glBindAttribLocation(g_hShaderProgram, g_hVertexTexLoc, "g_vTexCoord"); + + // Link the vertex shader and fragment shader together + glLinkProgram(g_hShaderProgram); + + // Check for link success + GLint nLinkResult = 0; + glGetProgramiv(g_hShaderProgram, GL_LINK_STATUS, &nLinkResult); + if (0 == nLinkResult) { + char strLog[1024]; + GLint nLength; + glGetProgramInfoLog(g_hShaderProgram, 1024, &nLength, strLog); + printf("error linking shader"); + return FALSE; + } + // Get uniform locations + g_hModelViewMatrixLoc = + glGetUniformLocation(g_hShaderProgram, "g_matModelView"); + g_hProjMatrixLoc = glGetUniformLocation(g_hShaderProgram, "g_matProj"); + + glDeleteShader(hVertexShader); + glDeleteShader(hFragmentShader); + + //gen textures + /* Load in the texture */ + if (LoadGLTextures() == 0) { + printf("error loading texture"); + return 0; + } + + /* Enable Texture Mapping ( NEW ) */ + glEnable(GL_TEXTURE_2D); + + } + + return 1; +} + +void Cleanup() +{ + +} + +void deinit(void) +{ + printf("Cleaning up...\n"); + Cleanup(); + eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + assert(eglGetError() == EGL_SUCCESS); + eglDestroyContext(egldisplay, eglcontext); + eglDestroySurface(egldisplay, eglsurface); + fsl_destroywindow(eglNativeWindow, eglNativeDisplayType); + eglTerminate(egldisplay); + assert(eglGetError() == EGL_SUCCESS); + eglReleaseThread(); +} + +void sighandler(int signal) +{ + printf("Caught signal %d, setting flaq to quit.\n", signal); + quit = 1; +} + +int main(void) +{ + signal(SIGINT, sighandler); + signal(SIGTERM, sighandler); + assert(init()); + + while (!quit) { + EGLint width = 0; + EGLint height = 0; + eglQuerySurface(egldisplay, eglsurface, EGL_WIDTH, &width); + eglQuerySurface(egldisplay, eglsurface, EGL_HEIGHT, &height); + render(width, height); + eglSwapBuffers(egldisplay, eglsurface); + } + deinit(); + return 0; +} diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/texture.bmp b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/texture.bmp new file mode 100644 index 000000000..d36bd345e Binary files /dev/null and b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-opengles/mx6/opengles/texture.bmp differ diff --git a/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb b/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb index 69af7f51d..f6639b437 100644 --- a/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb +++ b/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb @@ -46,6 +46,7 @@ RDEPENDS_${PN}_append_ccimx53js = "\ RDEPENDS_${PN}_append_mx6 = "\ dey-examples-can \ + ${@base_contains("MACHINE_FEATURES", "accel-graphics", "dey-examples-opengles", "", d)} \ dey-examples-v4l2 \ "