Permalink
Browse files

Improved REGAL_STATIC_EGL support.

Merged git://github.com/greggman/regal.git ifdef-stuff branch.
Add src/regal/RegalSystem.h to match REGAL_SYS_FOO for Regal.h.
  • Loading branch information...
1 parent b568bfb commit 227bf34aa403554772f71c38e4d741566b28b3eb @nigels-com nigels-com committed Aug 26, 2012
@@ -1,20 +1,31 @@
/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// OpenGL ES 2.0 code
+
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+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 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.
+
+For more information, please refer to <http://unlicense.org/>
+
+*/
#include <jni.h>
#include <android/log.h>
@@ -27,171 +38,35 @@
#include <cstdio>
#include <cstdlib>
-#define LOG_TAG "libgl2jni"
+#define LOG_TAG "dreamtorus"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
-static void printGLString(const char *name, GLenum s) {
- const char *v = (const char *) glGetString(s);
- LOGI("GL %s = %s\n", name, v);
-}
-
-static void checkGlError(const char* op) {
- for (GLint error = glGetError(); error; error
- = glGetError()) {
- LOGI("after %s() glError (0x%x)\n", op, error);
- }
-}
-
-static const char gVertexShader[] =
- "attribute vec4 vPosition;\n"
- "void main() {\n"
- " gl_Position = vPosition;\n"
- "}\n";
-
-static const char gFragmentShader[] =
- "precision mediump float;\n"
- "void main() {\n"
- " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
- "}\n";
-
-GLuint loadShader(GLenum shaderType, const char* pSource) {
- GLuint shader = glCreateShader(shaderType);
- if (shader) {
- glShaderSource(shader, 1, &pSource, NULL);
- glCompileShader(shader);
- GLint compiled = 0;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if (!compiled) {
- GLint infoLen = 0;
- glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
- if (infoLen) {
- char* buf = (char*) malloc(infoLen);
- if (buf) {
- glGetShaderInfoLog(shader, infoLen, NULL, buf);
- LOGE("Could not compile shader %d:\n%s\n",
- shaderType, buf);
- free(buf);
- }
- glDeleteShader(shader);
- shader = 0;
- }
- }
- }
- return shader;
-}
-
-GLuint createProgram(const char* pVertexSource, const char* pFragmentSource) {
- GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource);
- if (!vertexShader) {
- return 0;
- }
-
- GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource);
- if (!pixelShader) {
- return 0;
- }
-
- GLuint program = glCreateProgram();
- if (program) {
- glAttachShader(program, vertexShader);
- checkGlError("glAttachShader");
- glAttachShader(program, pixelShader);
- checkGlError("glAttachShader");
- glLinkProgram(program);
- GLint linkStatus = GL_FALSE;
- glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
- if (linkStatus != GL_TRUE) {
- GLint bufLength = 0;
- glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
- if (bufLength) {
- char* buf = (char*) malloc(bufLength);
- if (buf) {
- glGetProgramInfoLog(program, bufLength, NULL, buf);
- LOGE("Could not link program:\n%s\n", buf);
- free(buf);
- }
- }
- glDeleteProgram(program);
- program = 0;
- }
- }
- return program;
-}
-
-GLuint gProgram;
-GLuint gvPositionHandle;
-
static bool initialized = false;
-void initialize() {
- if( initialized ) {
- return;
- }
- initialized = true;
- RegalMakeCurrent( eglGetCurrentContext() );
-}
-bool setupGraphics(int w, int h) {
- initialize();
- printGLString("Version", GL_VERSION);
- printGLString("Vendor", GL_VENDOR);
- printGLString("Renderer", GL_RENDERER);
- printGLString("Extensions", GL_EXTENSIONS);
-
- LOGI("setupGraphics(%d, %d)", w, h);
- gProgram = createProgram(gVertexShader, gFragmentShader);
- if (!gProgram) {
- LOGE("Could not create program.");
- return false;
- }
- gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
- checkGlError("glGetAttribLocation");
- LOGI("glGetAttribLocation(\"vPosition\") = %d\n",
- gvPositionHandle);
-
- reshape( w, h );
- checkGlError("glViewport");
- return true;
-}
-
-const GLfloat gTriangleVertices[] = { 0.0f, 0.5f, -0.5f, -0.5f,
- 0.5f, -0.5f };
-
-void renderFrame() {
- static float grey;
- grey += 0.01f;
- if (grey > 1.0f) {
- grey = 0.0f;
- }
- glClearColor(grey, grey, grey, 1.0f);
- checkGlError("glClearColor");
- glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- checkGlError("glClear");
-
- glUseProgram(gProgram);
- checkGlError("glUseProgram");
-
- glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
- checkGlError("glVertexAttribPointer");
- glEnableVertexAttribArray(gvPositionHandle);
- checkGlError("glEnableVertexAttribArray");
- glDrawArrays(GL_TRIANGLES, 0, 3);
- checkGlError("glDrawArrays");
-
- display( false );
+void initialize()
+{
+ if (!initialized)
+ {
+ initialized = true;
+ RegalMakeCurrent( eglGetCurrentContext() );
+ }
}
-extern "C" {
- JNIEXPORT void JNICALL Java_com_nvidia_minimalAndroid_MinimalAndroidLib_init(JNIEnv * env, jobject obj, jint width, jint height);
- JNIEXPORT void JNICALL Java_com_nvidia_minimalAndroid_MinimalAndroidLib_step(JNIEnv * env, jobject obj);
+extern "C"
+{
+ JNIEXPORT void JNICALL Java_com_nvidia_minimalAndroid_MinimalAndroidLib_init(JNIEnv * env, jobject obj, jint width, jint height);
+ JNIEXPORT void JNICALL Java_com_nvidia_minimalAndroid_MinimalAndroidLib_step(JNIEnv * env, jobject obj);
};
JNIEXPORT void JNICALL Java_com_nvidia_minimalAndroid_MinimalAndroidLib_init(JNIEnv * env, jobject obj, jint width, jint height)
{
- setupGraphics(width, height);
+ initialize();
+ dreamTorusReshape(width, height);
}
JNIEXPORT void JNICALL Java_com_nvidia_minimalAndroid_MinimalAndroidLib_step(JNIEnv * env, jobject obj)
{
- renderFrame();
+ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
+ dreamTorusDisplay( false );
}
View
@@ -43,20 +43,32 @@
#define REGAL_DECLARATIONS_H
#if _WIN32
-# define REGAL_SYS_WGL 1
+# ifndef REGAL_SYS_WGL
+# define REGAL_SYS_WGL 1
+# endif
#elif __APPLE__
# include <TargetConditionals.h>
# if TARGET_OS_IPHONE
-# define REGAL_SYS_IOS 1
+# ifndef REGAL_SYS_IOS
+# define REGAL_SYS_IOS 1
+# endif
# else
-# define REGAL_SYS_OSX 1
+# ifndef REGAL_SYS_OSX
+# define REGAL_SYS_OSX 1
+# endif
# endif
#elif defined(__native_client__)
+# ifndef REGAL_SYS_NACL
# define REGAL_SYS_NACL 1
+# endif
#elif defined(__ANDROID__)
+# ifndef REGAL_SYS_ANDROID
# define REGAL_SYS_ANDROID 1
+# endif
#elif !defined(_WIN32) && !defined(__APPLE__) && !defined(__native_client__)
-# define REGAL_SYS_GLX 1
+# ifndef REGAL_SYS_GLX
+# define REGAL_SYS_GLX 1
+# endif
#endif
#if REGAL_SYS_WGL
@@ -228,7 +240,7 @@ typedef void * CGSWindowID;
typedef void * CGSSurfaceID;
#endif // REGAL_SYS_OSX
-#if REGAL_SYS_ANDROID | REGAL_STATIC_EGL
+#if REGAL_SYS_ANDROID
typedef struct ANativeWindow* EGLNativeWindowType;
typedef struct egl_native_pixmap_t* EGLNativePixmapType;
typedef void* EGLNativeDisplayType;
@@ -244,7 +256,7 @@ typedef void * EGLDisplay;
typedef void * EGLSurface;
typedef void * EGLClientBuffer;
typedef void (*__eglMustCastToProperFunctionPointerType)(void);
-#endif // REGAL_SYS_ANDROID | REGAL_STATIC_EGL
+#endif // REGAL_SYS_ANDROID
// TODO: make this automatic?
typedef void (*GLDEBUGPROCAMD)(GLuint id, GLenum category, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam);
@@ -30538,7 +30550,7 @@ REGAL_DECL CGLShareGroupObj REGAL_CALL CGLGetShareGroup(CGLContextObj ctx);
#endif /* REGAL_SYS_OSX */
-#if REGAL_SYS_ANDROID | REGAL_STATIC_EGL
+#if REGAL_SYS_ANDROID
#define EGL_NO_CONTEXT ((EGLContext)0)
#define EGL_NO_DISPLAY ((EGLDisplay)0)
#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
@@ -30868,7 +30880,7 @@ REGAL_DECL EGLSurface REGAL_CALL eglCreatePbufferFromClientBuffer(EGLDisplay dpy
REGAL_DECL EGLenum REGAL_CALL eglQueryAPI(void);
#endif
-#endif /* REGAL_SYS_ANDROID | REGAL_STATIC_EGL */
+#endif /* REGAL_SYS_ANDROID */
#ifdef __cplusplus
}
Oops, something went wrong.

0 comments on commit 227bf34

Please sign in to comment.