Testing out pthread support in android. Appears to work.
authorPaul Hunkin
Fri, 18 Jun 2010 00:02:13 +1200
changeset 470612c9d4532b49
parent 4705 190f043af37d
child 4707 8b109f0dcd2f
Testing out pthread support in android. Appears to work.
android/testproject/jni/app-android.c
android/testproject/libs/armeabi/libsanangeles.so
     1.1 --- a/android/testproject/jni/app-android.c	Thu Jun 17 23:04:16 2010 +1200
     1.2 +++ b/android/testproject/jni/app-android.c	Fri Jun 18 00:02:13 2010 +1200
     1.3 @@ -11,6 +11,8 @@
     1.4  #include <stdlib.h>
     1.5  #include <math.h>
     1.6  
     1.7 +#include <pthread.h>
     1.8 +
     1.9  #include "importgl.h"
    1.10  
    1.11  /*******************************************************************************
    1.12 @@ -28,106 +30,18 @@
    1.13  	return (long)(now.tv_sec*1000 + now.tv_usec/1000);
    1.14  }
    1.15  
    1.16 -/**************************************
    1.17 -	gluperspective implementation
    1.18 -**************************************/
    1.19 -void gluPerspective(double fovy, double aspect, double zNear, double zFar){
    1.20 -	glMatrixMode(GL_PROJECTION);
    1.21 -	glLoadIdentity();
    1.22 -	double xmin, xmax, ymin, ymax;
    1.23 -	ymax = zNear * tan(fovy * M_PI / 360.0);
    1.24 -	ymin = -ymax;
    1.25 -	xmin = ymin * aspect;
    1.26 -	xmax = ymax * aspect;
    1.27 -	glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
    1.28 -}
    1.29  
    1.30  
    1.31 -/**************************************
    1.32 -	  glulookat implementation
    1.33 -**************************************/
    1.34 -void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
    1.35 -          GLfloat centerx, GLfloat centery, GLfloat centerz,
    1.36 -          GLfloat upx, GLfloat upy, GLfloat upz)
    1.37 -{
    1.38 -    GLfloat m[16];
    1.39 -    GLfloat x[3], y[3], z[3];
    1.40 -    GLfloat mag;
    1.41 -    
    1.42 -    /* Make rotation matrix */
    1.43 -    
    1.44 -    /* Z vector */
    1.45 -    z[0] = eyex - centerx;
    1.46 -    z[1] = eyey - centery;
    1.47 -    z[2] = eyez - centerz;
    1.48 -    mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
    1.49 -    if (mag) {          /* mpichler, 19950515 */
    1.50 -        z[0] /= mag;
    1.51 -        z[1] /= mag;
    1.52 -        z[2] /= mag;
    1.53 -    }
    1.54 -    
    1.55 -    /* Y vector */
    1.56 -    y[0] = upx;
    1.57 -    y[1] = upy;
    1.58 -    y[2] = upz;
    1.59 -    
    1.60 -    /* X vector = Y cross Z */
    1.61 -    x[0] = y[1] * z[2] - y[2] * z[1];
    1.62 -    x[1] = -y[0] * z[2] + y[2] * z[0];
    1.63 -    x[2] = y[0] * z[1] - y[1] * z[0];
    1.64 -    
    1.65 -    /* Recompute Y = Z cross X */
    1.66 -    y[0] = z[1] * x[2] - z[2] * x[1];
    1.67 -    y[1] = -z[0] * x[2] + z[2] * x[0];
    1.68 -    y[2] = z[0] * x[1] - z[1] * x[0];
    1.69 -    
    1.70 -    /* mpichler, 19950515 */
    1.71 -    /* cross product gives area of parallelogram, which is < 1.0 for
    1.72 -     * non-perpendicular unit-length vectors; so normalize x, y here
    1.73 -     */
    1.74 -    
    1.75 -    mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
    1.76 -    if (mag) {
    1.77 -        x[0] /= mag;
    1.78 -        x[1] /= mag;
    1.79 -        x[2] /= mag;
    1.80 -    }
    1.81 -    
    1.82 -    mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
    1.83 -    if (mag) {
    1.84 -        y[0] /= mag;
    1.85 -        y[1] /= mag;
    1.86 -        y[2] /= mag;
    1.87 -    }
    1.88 -    
    1.89 -#define M(row,col)  m[col*4+row]
    1.90 -    M(0, 0) = x[0];
    1.91 -    M(0, 1) = x[1];
    1.92 -    M(0, 2) = x[2];
    1.93 -    M(0, 3) = 0.0;
    1.94 -    M(1, 0) = y[0];
    1.95 -    M(1, 1) = y[1];
    1.96 -    M(1, 2) = y[2];
    1.97 -    M(1, 3) = 0.0;
    1.98 -    M(2, 0) = z[0];
    1.99 -    M(2, 1) = z[1];
   1.100 -    M(2, 2) = z[2];
   1.101 -    M(2, 3) = 0.0;
   1.102 -    M(3, 0) = 0.0;
   1.103 -    M(3, 1) = 0.0;
   1.104 -    M(3, 2) = 0.0;
   1.105 -    M(3, 3) = 1.0;
   1.106 -#undef M
   1.107 -    glMultMatrixf(m);
   1.108 -    
   1.109 -    /* Translate Eye to Origin */
   1.110 -    glTranslatef(-eyex, -eyey, -eyez);
   1.111 -    
   1.112 +/*******************************************************************************
   1.113 +                      SDL thread
   1.114 +*******************************************************************************/
   1.115 +pthread_t mSDLThread = 0;
   1.116 +
   1.117 +void* sdlThreadProc(void* args){
   1.118 +	__android_log_print(ANDROID_LOG_INFO, "SDL", "Thread Entry");
   1.119 +	return 0;
   1.120  }
   1.121 -
   1.122 -
   1.123 -
   1.124 +   
   1.125  /*******************************************************************************
   1.126                        Initialize the graphics state
   1.127  *******************************************************************************/
   1.128 @@ -140,25 +54,14 @@
   1.129  
   1.130  	__android_log_print(ANDROID_LOG_INFO, "SDL", "Entry point");
   1.131  
   1.132 -
   1.133 -	 /* Enable smooth shading */
   1.134 -    glShadeModel( GL_SMOOTH );
   1.135 -
   1.136 -    /* Set the background black */
   1.137 -    glClearColor( 1.0f, 0.0f, 0.0f, 0.0f );
   1.138 -
   1.139 -    /* Depth buffer setup */
   1.140 -    //glClearDepth( 1.0f );
   1.141 +	//Spin up the SDL thread
   1.142 +	int r = pthread_create(&mSDLThread, NULL, sdlThreadProc, NULL);
   1.143  
   1.144 -    /* Enables Depth Testing */
   1.145 -    glEnable( GL_DEPTH_TEST );
   1.146 -
   1.147 -    /* The Type Of Depth Test To Do */
   1.148 -    glDepthFunc( GL_LEQUAL );
   1.149 -
   1.150 -    /* Really Nice Perspective Calculations */
   1.151 -    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
   1.152 -
   1.153 +	if(r != 0){
   1.154 +		__android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't spawn thread: %d", r);
   1.155 +	}else{		
   1.156 +		__android_log_print(ANDROID_LOG_INFO, "SDL", "Started SDL thread");
   1.157 +	}
   1.158  
   1.159  }
   1.160  
   1.161 @@ -174,34 +77,6 @@
   1.162  	sWindowHeight = h;
   1.163  	__android_log_print(ANDROID_LOG_INFO, "SDL", "resize w=%d h=%d", w, h);
   1.164  
   1.165 -
   1.166 -
   1.167 -	 /* Height / width ration */
   1.168 -    GLfloat ratio;
   1.169 - 
   1.170 -    /* Protect against a divide by zero */
   1.171 -   if ( h == 0 )
   1.172 -	h = 1;
   1.173 -
   1.174 -    ratio = ( GLfloat )w / ( GLfloat )h;
   1.175 -
   1.176 -    /* Setup our viewport. */
   1.177 -    glViewport( 0, 0, ( GLsizei )w, ( GLsizei )h );
   1.178 -
   1.179 -    /* change to the projection matrix and set our viewing volume. */
   1.180 -    glMatrixMode( GL_PROJECTION );
   1.181 -    glLoadIdentity( );
   1.182 -
   1.183 -    /* Set our perspective */
   1.184 -    gluPerspective( 45.0f, ratio, 0.1f, 100.0f );
   1.185 -
   1.186 -    /* Make sure we're chaning the model view and not the projection */
   1.187 -    glMatrixMode( GL_MODELVIEW );
   1.188 -
   1.189 -    /* Reset The View */
   1.190 -    glLoadIdentity( );
   1.191 -
   1.192 -
   1.193  }
   1.194  
   1.195  /*******************************************************************************
   1.196 @@ -236,118 +111,8 @@
   1.197                       Render the next frame
   1.198  *******************************************************************************/
   1.199  
   1.200 -const GLbyte vertex []=
   1.201 -{
   1.202 -	0,1,0,
   1.203 -	-1,0,0,
   1.204 -	1,0,0
   1.205 -};
   1.206 -
   1.207 -const GLubyte color []=
   1.208 -{
   1.209 -	255,0,0,
   1.210 -	0,255,0,
   1.211 -	0,0,255
   1.212 -};
   1.213 -
   1.214 -int iRot = 0;
   1.215 -int Frames = 0;
   1.216 -
   1.217 -
   1.218 -static void prepareFrame(int width, int height)
   1.219 -{
   1.220 -    glViewport(0, 0, width, height);
   1.221 -
   1.222 -    glClearColorx(0,0,0,255);
   1.223 -    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
   1.224 -
   1.225 -    glMatrixMode(GL_PROJECTION);
   1.226 -    glLoadIdentity();
   1.227 -    gluPerspective(45, (float)width / height, 0.5f, 150);
   1.228 -
   1.229 -    glMatrixMode(GL_MODELVIEW);
   1.230 -
   1.231 -    glLoadIdentity();
   1.232 -}
   1.233 -
   1.234  void Java_org_libsdl_android_TestRenderer_nativeRender( JNIEnv*  env )
   1.235  {    
   1.236  	//TODO: Render here
   1.237  
   1.238 -	prepareFrame(sWindowWidth, sWindowHeight);
   1.239 -	
   1.240 -	//Camera
   1.241 -	gluLookAt(0,0,5, 0,0,0, 0,1,0);
   1.242 -			
   1.243 -	//Draw a triangle
   1.244 -	//glRotatef(iRot, 0, 1, 0);
   1.245 -
   1.246 -	glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f );
   1.247 -
   1.248 -
   1.249 -	glEnableClientState (GL_VERTEX_ARRAY);
   1.250 -	glEnableClientState (GL_COLOR_ARRAY);
   1.251 -	
   1.252 -	/* Rotate The Triangle On The Y axis ( NEW ) */
   1.253 -    glRotatef( Frames % 360, 0.0f, 1.0f, 0.0f );
   1.254 -
   1.255 -    /* GLES variant of drawing a triangle */
   1.256 -    const GLfloat triVertices[][9] = {
   1.257 -      {     /* Front Triangle */
   1.258 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
   1.259 -	-1.0f, -1.0f,  1.0f,               /* Left Of Triangle              */
   1.260 -	 1.0f, -1.0f,  1.0f                /* Right Of Triangle             */
   1.261 -      }, {  /* Right Triangle */
   1.262 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
   1.263 -	 1.0f, -1.0f,  1.0f,               /* Left Of Triangle              */
   1.264 -	 1.0f, -1.0f, -1.0f                /* Right Of Triangle             */
   1.265 -      }, {  /* Back Triangle */
   1.266 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
   1.267 -	 1.0f, -1.0f, -1.0f,               /* Left Of Triangle              */
   1.268 -	-1.0f, -1.0f, -1.0f                /* Right Of Triangle             */
   1.269 -      }, {  /* Left Triangle */
   1.270 -	 0.0f,  1.0f,  0.0f,               /* Top Of Triangle               */
   1.271 -	-1.0f, -1.0f, -1.0f,               /* Left Of Triangle              */
   1.272 -	-1.0f, -1.0f,  1.0f                /* Right Of Triangle             */
   1.273 -      }
   1.274 -    };
   1.275 -
   1.276 -    /* unlike GL, GLES does not support RGB. We have to use RGBA instead */
   1.277 -    const GLfloat triColors[][12] = {
   1.278 -      {     /* Front triangle */
   1.279 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
   1.280 -	0.0f, 1.0f, 0.0f, 1.0f,            /* Green                         */
   1.281 -	0.0f, 0.0f, 1.0f, 1.0f             /* Blue                          */
   1.282 -      }, {  /* Right triangle */
   1.283 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
   1.284 -	0.0f, 0.0f, 1.0f, 1.0f,            /* Blue                          */
   1.285 -	0.0f, 1.0f, 0.0f, 1.0f             /* Green                         */
   1.286 -      }, {  /* Back triangle */
   1.287 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
   1.288 -	0.0f, 1.0f, 0.0f, 1.0f,            /* Green                         */
   1.289 -	0.0f, 0.0f, 1.0f, 1.0f             /* Blue                          */
   1.290 -      }, {  /* Left triangle */
   1.291 -        1.0f, 0.0f, 0.0f, 1.0f,            /* Red                           */
   1.292 -	0.0f, 0.0f, 1.0f, 1.0f,            /* Blue                          */
   1.293 -	0.0f, 1.0f, 0.0f, 1.0f             /* Green                         */
   1.294 -      }
   1.295 -    };
   1.296 -
   1.297 -    glEnableClientState(GL_COLOR_ARRAY);
   1.298 -
   1.299 -    int tri=0;
   1.300 -
   1.301 -    /* Loop through all Triangles */
   1.302 -    for(tri=0;tri<sizeof(triVertices)/(9*sizeof(GLfloat));tri++) 
   1.303 -    {
   1.304 -      glVertexPointer(3, GL_FLOAT, 0, triVertices[tri]);
   1.305 -      glColorPointer(4, GL_FLOAT, 0, triColors[tri]);
   1.306 -      
   1.307 -      glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
   1.308 -    }
   1.309 -		
   1.310 -    //__android_log_print(ANDROID_LOG_INFO, "SDL", "render %d", Frames++);
   1.311 -
   1.312 -    Frames++;
   1.313 -
   1.314  }
     2.1 Binary file android/testproject/libs/armeabi/libsanangeles.so has changed