istereo2

changeset 24:9d53a4938ce8

port to android mostly complete, ads not done, and needs some polishing
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 04 Oct 2015 08:15:24 +0300
parents 7d795dade0bc
children a9f2d30f7e8e
files .hgignore Makefile android/Makefile android/manifest.xml.in src/android/MainActivity.java src/android/amain.c src/android/assman.c src/android/logger.c src/istereo.c src/respath.c src/sdr.c src/sdr.h src/tex.c
diffstat 13 files changed, 293 insertions(+), 117 deletions(-) [+]
line diff
     1.1 --- a/.hgignore	Sat Oct 03 06:10:30 2015 +0300
     1.2 +++ b/.hgignore	Sun Oct 04 08:15:24 2015 +0300
     1.3 @@ -16,6 +16,7 @@
     1.4  ^android/res/
     1.5  ^android/src/
     1.6  ^android/assets/
     1.7 +^android/gen/
     1.8  \.xml$
     1.9  \.properties$
    1.10  proguard-project\.txt$
     2.1 --- a/Makefile	Sat Oct 03 06:10:30 2015 +0300
     2.2 +++ b/Makefile	Sun Oct 04 08:15:24 2015 +0300
     2.3 @@ -1,3 +1,4 @@
     2.4 +root = .
     2.5  src = $(wildcard src/*.c) $(wildcard src/glut/*.c)
     2.6  ccsrc = $(wildcard src/*.cc)
     2.7  
     3.1 --- a/android/Makefile	Sat Oct 03 06:10:30 2015 +0300
     3.2 +++ b/android/Makefile	Sun Oct 04 08:15:24 2015 +0300
     3.3 @@ -12,6 +12,7 @@
     3.4  # ------------------------
     3.5  
     3.6  src += $(wildcard $(root)/src/android/*.c)
     3.7 +jsrc = $(wildcard $(root)/src/android/*.java)
     3.8  
     3.9  obj = $(src:.c=.o) $(ccsrc:.cc=.o)
    3.10  lib = libs/armeabi/lib$(name).so
    3.11 @@ -19,7 +20,7 @@
    3.12  apk-debug = bin/$(name)-debug.apk
    3.13  
    3.14  pkg = $(pkgprefix).$(name)
    3.15 -act = android.app.NativeActivity
    3.16 +act = $(pkg).MainActivity
    3.17  
    3.18  CC = arm-linux-androideabi-gcc
    3.19  CXX = arm-linux-androideabi-g++
    3.20 @@ -95,7 +96,7 @@
    3.21  AndroidManifest.xml: manifest.xml.in
    3.22  	android create project -p . -t $(android_platform) -k $(pkg) -a NativeActivity -n $(name)
    3.23  	cat manifest.xml.in | sed 's/$$APPNAME/$(name)/g' | sed 's/$$APPTITLE/$(title)/g' >$@
    3.24 -#	cd src && rm -f *.java && ln -s ../../src/android/*.java .
    3.25 +	cd src && rm -f *.java && ln -s ../../src/android/*.java .
    3.26  
    3.27  .PHONY: update-project
    3.28  update-project: build.xml
     4.1 --- a/android/manifest.xml.in	Sat Oct 03 06:10:30 2015 +0300
     4.2 +++ b/android/manifest.xml.in	Sun Oct 04 08:15:24 2015 +0300
     4.3 @@ -4,14 +4,14 @@
     4.4  	android:versionCode="1"
     4.5  	android:versionName="1.0">
     4.6  
     4.7 -	<uses-sdk android:minSdkVersion="9"/>
     4.8 +	<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>
     4.9 +	<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
    4.10  
    4.11 -	<application android:label="$APPNAME"
    4.12 -			android:hasCode="false"
    4.13 -			android:debuggable="true">
    4.14 -			<!-- android:icon="@drawable/ic_launcher" -->
    4.15 +	<application android:label="$APPNAME" android:debuggable="true">
    4.16 +		<!-- android:icon="@drawable/ic_launcher" -->
    4.17  
    4.18 -		<activity android:name="android.app.NativeActivity"
    4.19 +		<activity android:name="MainActivity"
    4.20 +			android:configChanges="orientation"
    4.21  			android:label="$APPTITLE">
    4.22  
    4.23  			<meta-data android:name="android.app.lib_name" android:value="$APPNAME"/>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/android/MainActivity.java	Sun Oct 04 08:15:24 2015 +0300
     5.3 @@ -0,0 +1,56 @@
     5.4 +package com.mutantstargoat.stereotunnel;
     5.5 +
     5.6 +import android.os.Bundle;
     5.7 +import android.app.NativeActivity;
     5.8 +import android.view.*;
     5.9 +import android.view.WindowManager.LayoutParams;
    5.10 +//import android.util.Log;
    5.11 +
    5.12 +public class MainActivity extends NativeActivity
    5.13 +{
    5.14 +	//public static String tag = "stereotunnel";
    5.15 +
    5.16 +	@Override
    5.17 +	protected void onCreate(Bundle saved_inst)
    5.18 +	{
    5.19 +		super.onCreate(saved_inst);
    5.20 +
    5.21 +		// go fullscreen
    5.22 +		int winflags = LayoutParams.FLAG_FULLSCREEN |
    5.23 +			LayoutParams.FLAG_LAYOUT_NO_LIMITS | LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    5.24 +		Window win = getWindow();
    5.25 +		win.setFlags(winflags, winflags);
    5.26 +	}
    5.27 +
    5.28 +	@Override
    5.29 +	public void onWindowFocusChanged(boolean focus)
    5.30 +	{
    5.31 +		super.onWindowFocusChanged(focus);
    5.32 +		if(focus) {
    5.33 +			set_fullscreen();
    5.34 +		}
    5.35 +	}
    5.36 +
    5.37 +	protected void onResume()
    5.38 +	{
    5.39 +		super.onResume();
    5.40 +		set_fullscreen();
    5.41 +	}
    5.42 +
    5.43 +	public void set_fullscreen()
    5.44 +	{
    5.45 +		int uiflags = View.SYSTEM_UI_FLAG_FULLSCREEN |
    5.46 +			View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
    5.47 +			View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
    5.48 +			View.SYSTEM_UI_FLAG_LOW_PROFILE;
    5.49 +
    5.50 +		if(android.os.Build.VERSION.SDK_INT >= 19) {
    5.51 +			uiflags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
    5.52 +				View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
    5.53 +				View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    5.54 +		}
    5.55 +
    5.56 +		View decor = getWindow().getDecorView();
    5.57 +		decor.setSystemUiVisibility(uiflags);
    5.58 +	}
    5.59 +}
     6.1 --- a/src/android/amain.c	Sat Oct 03 06:10:30 2015 +0300
     6.2 +++ b/src/android/amain.c	Sun Oct 04 08:15:24 2015 +0300
     6.3 @@ -2,8 +2,8 @@
     6.4  #include <stdlib.h>
     6.5  #include <assert.h>
     6.6  #include <EGL/egl.h>
     6.7 -#include <jni.h>
     6.8  #include "android_native_app_glue.h"
     6.9 +#include <android/window.h>
    6.10  #include <android/sensor.h>
    6.11  #include "logger.h"
    6.12  #include "istereo.h"
    6.13 @@ -33,6 +33,8 @@
    6.14  	app->onAppCmd = handle_command;
    6.15  	app->onInputEvent = handle_input;
    6.16  
    6.17 +	//ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0);
    6.18 +
    6.19  	start_logger();
    6.20  
    6.21  	for(;;) {
    6.22 @@ -81,6 +83,7 @@
    6.23  		break;
    6.24  
    6.25  	case APP_CMD_INIT_WINDOW:
    6.26 +		printf("APP_CMD_INIT_WINDOW\n");
    6.27  		if(init_gl() == -1) {
    6.28  			exit(1);
    6.29  		}
    6.30 @@ -88,21 +91,25 @@
    6.31  		if(init() == -1) {
    6.32  			exit(1);	/* initialization failed, quit */
    6.33  		}
    6.34 +		reshape(width, height);
    6.35  		init_done = 1;
    6.36  		break;
    6.37  
    6.38  	case APP_CMD_TERM_WINDOW:
    6.39  		/* cleanup */
    6.40 +		printf("APP_CMD_TERM_WINDOW\n");
    6.41  		init_done = 0;
    6.42  		cleanup();
    6.43  		destroy_gl();
    6.44  		break;
    6.45  
    6.46  	case APP_CMD_GAINED_FOCUS:
    6.47 +		printf("APP_CMD_GAINED_FOCUS\n");
    6.48  		/* app focused */
    6.49  		break;
    6.50  
    6.51  	case APP_CMD_LOST_FOCUS:
    6.52 +		printf("APP_CMD_LOST_FOCUS\n");
    6.53  		/* app lost focus */
    6.54  		break;
    6.55  
    6.56 @@ -112,6 +119,7 @@
    6.57  			int nx = ANativeWindow_getWidth(app->window);
    6.58  			int ny = ANativeWindow_getHeight(app->window);
    6.59  			if(nx != width || ny != height) {
    6.60 +				printf("reshape(%d, %d)\n", nx, ny);
    6.61  				reshape(nx, ny);
    6.62  				width = nx;
    6.63  				height = ny;
    6.64 @@ -250,6 +258,7 @@
    6.65  
    6.66  	eglQuerySurface(dpy, surf, EGL_WIDTH, &width);
    6.67  	eglQuerySurface(dpy, surf, EGL_HEIGHT, &height);
    6.68 +	printf("initial reshape call: %dx%d\n", width, height);
    6.69  	reshape(width, height);
    6.70  
    6.71  	return 0;
     7.1 --- a/src/android/assman.c	Sat Oct 03 06:10:30 2015 +0300
     7.2 +++ b/src/android/assman.c	Sun Oct 04 08:15:24 2015 +0300
     7.3 @@ -1,3 +1,4 @@
     7.4 +#include <assert.h>
     7.5  #include <fcntl.h>
     7.6  #include <android/asset_manager.h>
     7.7  #include "assman.h"
     7.8 @@ -37,6 +38,9 @@
     7.9  		prev = *mode++;
    7.10  	}
    7.11  
    7.12 +	assert(app);
    7.13 +	assert(app->activity);
    7.14 +	assert(app->activity->assetManager);
    7.15  	if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) {
    7.16  		return 0;
    7.17  	}
     8.1 --- a/src/android/logger.c	Sat Oct 03 06:10:30 2015 +0300
     8.2 +++ b/src/android/logger.c	Sun Oct 04 08:15:24 2015 +0300
     8.3 @@ -5,6 +5,10 @@
     8.4  #include <android/log.h>
     8.5  #include "logger.h"
     8.6  
     8.7 +#ifndef APP_NAME
     8.8 +#define APP_NAME	"stereotunnel"
     8.9 +#endif
    8.10 +
    8.11  static void *thread_func(void *arg);
    8.12  
    8.13  static int pfd[2];
     9.1 --- a/src/istereo.c	Sat Oct 03 06:10:30 2015 +0300
     9.2 +++ b/src/istereo.c	Sun Oct 04 08:15:24 2015 +0300
     9.3 @@ -410,7 +410,7 @@
     9.4  	glViewport(0, 0, x, y);
     9.5  
     9.6  	float aspect = (float)x / (float)y;
     9.7 -	float maxfov = 40.0;
     9.8 +	float maxfov = 42.0;
     9.9  	float vfov = aspect > 1.0 ? maxfov / aspect : maxfov;
    9.10  
    9.11  	cam_fov(vfov);
    9.12 @@ -466,14 +466,14 @@
    9.13  {
    9.14  	unsigned int prog, vs, ps;
    9.15  
    9.16 -	if(!(vs = get_vertex_shader(find_resource(vfile, 0, 0)))) {
    9.17 +	if(!(vs = load_vertex_shader(find_resource(vfile, 0, 0)))) {
    9.18  		return 0;
    9.19  	}
    9.20 -	if(!(ps = get_pixel_shader(find_resource(pfile, 0, 0)))) {
    9.21 +	if(!(ps = load_pixel_shader(find_resource(pfile, 0, 0)))) {
    9.22  		return 0;
    9.23  	}
    9.24  
    9.25 -	if(!(prog = create_program_link(vs, ps))) {
    9.26 +	if(!(prog = create_program_link(vs, ps, 0))) {
    9.27  		return 0;
    9.28  	}
    9.29  	return prog;
    10.1 --- a/src/respath.c	Sat Oct 03 06:10:30 2015 +0300
    10.2 +++ b/src/respath.c	Sun Oct 04 08:15:24 2015 +0300
    10.3 @@ -24,6 +24,7 @@
    10.4  #include <unistd.h>
    10.5  #include "respath.h"
    10.6  #include "config.h"
    10.7 +#include "assman.h"
    10.8  
    10.9  #ifdef IPHONE
   10.10  #include <CoreFoundation/CoreFoundation.h>
   10.11 @@ -64,8 +65,11 @@
   10.12  
   10.13  	node = pathlist;
   10.14  	while(node) {
   10.15 +		ass_file *fp;
   10.16 +
   10.17  		snprintf(path, sz, "%s/%s", node->path, fname);
   10.18 -		if(access(path, F_OK) != -1) {
   10.19 +		if((fp = ass_fopen(path, "r"))) {
   10.20 +			ass_fclose(fp);
   10.21  			return path;
   10.22  		}
   10.23  		node = node->next;
    11.1 --- a/src/sdr.c	Sat Oct 03 06:10:30 2015 +0300
    11.2 +++ b/src/sdr.c	Sun Oct 04 08:15:24 2015 +0300
    11.3 @@ -1,27 +1,11 @@
    11.4 -/*
    11.5 -Stereoscopic tunnel for iOS.
    11.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
    11.7 -
    11.8 -This program is free software: you can redistribute it and/or modify
    11.9 -it under the terms of the GNU General Public License as published by
   11.10 -the Free Software Foundation, either version 3 of the License, or
   11.11 -(at your option) any later version.
   11.12 -
   11.13 -This program is distributed in the hope that it will be useful,
   11.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.16 -GNU General Public License for more details.
   11.17 -
   11.18 -You should have received a copy of the GNU General Public License
   11.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   11.20 -*/
   11.21 -
   11.22  #include <stdio.h>
   11.23  #include <stdlib.h>
   11.24  #include <string.h>
   11.25  #include <errno.h>
   11.26 +#include <stdarg.h>
   11.27  #include <assert.h>
   11.28  #include "opengl.h"
   11.29 +#include "assman.h"
   11.30  
   11.31  #if defined(unix) || defined(__unix__)
   11.32  #include <unistd.h>
   11.33 @@ -30,6 +14,7 @@
   11.34  
   11.35  #include "sdr.h"
   11.36  
   11.37 +static const char *sdrtypestr(unsigned int sdrtype);
   11.38  
   11.39  unsigned int create_vertex_shader(const char *src)
   11.40  {
   11.41 @@ -41,6 +26,33 @@
   11.42  	return create_shader(src, GL_FRAGMENT_SHADER);
   11.43  }
   11.44  
   11.45 +unsigned int create_tessctl_shader(const char *src)
   11.46 +{
   11.47 +#ifdef GL_TESS_CONTROL_SHADER
   11.48 +	return create_shader(src, GL_TESS_CONTROL_SHADER);
   11.49 +#else
   11.50 +	return 0;
   11.51 +#endif
   11.52 +}
   11.53 +
   11.54 +unsigned int create_tesseval_shader(const char *src)
   11.55 +{
   11.56 +#ifdef GL_TESS_EVALUATION_SHADER
   11.57 +	return create_shader(src, GL_TESS_EVALUATION_SHADER);
   11.58 +#else
   11.59 +	return 0;
   11.60 +#endif
   11.61 +}
   11.62 +
   11.63 +unsigned int create_geometry_shader(const char *src)
   11.64 +{
   11.65 +#ifdef GL_GEOMETRY_SHADER
   11.66 +	return create_shader(src, GL_GEOMETRY_SHADER);
   11.67 +#else
   11.68 +	return 0;
   11.69 +#endif
   11.70 +}
   11.71 +
   11.72  unsigned int create_shader(const char *src, unsigned int sdr_type)
   11.73  {
   11.74  	unsigned int sdr;
   11.75 @@ -65,6 +77,7 @@
   11.76  		if((info_str = malloc(info_len + 1))) {
   11.77  			glGetShaderInfoLog(sdr, info_len, 0, info_str);
   11.78  			assert(glGetError() == GL_NO_ERROR);
   11.79 +			info_str[info_len] = 0;
   11.80  		}
   11.81  	}
   11.82  
   11.83 @@ -95,39 +108,58 @@
   11.84  	return load_shader(fname, GL_FRAGMENT_SHADER);
   11.85  }
   11.86  
   11.87 +unsigned int load_tessctl_shader(const char *fname)
   11.88 +{
   11.89 +#ifdef GL_TESS_CONTROL_SHADER
   11.90 +	return load_shader(fname, GL_TESS_CONTROL_SHADER);
   11.91 +#else
   11.92 +	return 0;
   11.93 +#endif
   11.94 +}
   11.95 +
   11.96 +unsigned int load_tesseval_shader(const char *fname)
   11.97 +{
   11.98 +#ifdef GL_TESS_EVALUATION_SHADER
   11.99 +	return load_shader(fname, GL_TESS_EVALUATION_SHADER);
  11.100 +#else
  11.101 +	return 0;
  11.102 +#endif
  11.103 +}
  11.104 +
  11.105 +unsigned int load_geometry_shader(const char *fname)
  11.106 +{
  11.107 +#ifdef GL_GEOMETRY_SHADER
  11.108 +	return load_shader(fname, GL_GEOMETRY_SHADER);
  11.109 +#else
  11.110 +	return 0;
  11.111 +#endif
  11.112 +}
  11.113 +
  11.114  unsigned int load_shader(const char *fname, unsigned int sdr_type)
  11.115  {
  11.116 -#if defined(unix) || defined(__unix__)
  11.117 -	struct stat st;
  11.118 -#endif
  11.119  	unsigned int sdr;
  11.120  	size_t filesize;
  11.121 -	FILE *fp;
  11.122 +	ass_file *fp;
  11.123  	char *src;
  11.124  
  11.125 -	if(!(fp = fopen(fname, "r"))) {
  11.126 +	if(!(fp = ass_fopen(fname, "rb"))) {
  11.127  		fprintf(stderr, "failed to open shader %s: %s\n", fname, strerror(errno));
  11.128  		return 0;
  11.129  	}
  11.130  
  11.131 -#if defined(unix) || defined(__unix__)
  11.132 -	fstat(fileno(fp), &st);
  11.133 -	filesize = st.st_size;
  11.134 -#else
  11.135 -	fseek(fp, 0, SEEK_END);
  11.136 -	filesize = ftell(fp);
  11.137 -	fseek(fp, 0, SEEK_SET);
  11.138 -#endif	/* unix */
  11.139 +	filesize = ass_fseek(fp, 0, SEEK_END);
  11.140 +	/*filesize = ass_ftell(fp);*/
  11.141 +	ass_fseek(fp, 0, SEEK_SET);
  11.142  
  11.143  	if(!(src = malloc(filesize + 1))) {
  11.144 -		fclose(fp);
  11.145 +		ass_fclose(fp);
  11.146  		return 0;
  11.147  	}
  11.148 -	fread(src, 1, filesize, fp);
  11.149 +	ass_fread(src, 1, filesize, fp);
  11.150  	src[filesize] = 0;
  11.151 -	fclose(fp);
  11.152 +	ass_fclose(fp);
  11.153  
  11.154 -	fprintf(stderr, "compiling %s shader: %s... ", (sdr_type == GL_VERTEX_SHADER ? "vertex" : "pixel"), fname);
  11.155 +	fprintf(stderr, "compiling %s shader: %s... ", sdrtypestr(sdr_type), fname);
  11.156  	sdr = create_shader(src, sdr_type);
  11.157  
  11.158  	free(src);
  11.159 @@ -135,27 +167,6 @@
  11.160  }
  11.161  
  11.162  
  11.163 -unsigned int get_vertex_shader(const char *fname)
  11.164 -{
  11.165 -	return get_shader(fname, GL_VERTEX_SHADER);
  11.166 -}
  11.167 -
  11.168 -unsigned int get_pixel_shader(const char *fname)
  11.169 -{
  11.170 -	return get_shader(fname, GL_FRAGMENT_SHADER);
  11.171 -}
  11.172 -
  11.173 -unsigned int get_shader(const char *fname, unsigned int sdr_type)
  11.174 -{
  11.175 -	unsigned int sdr;
  11.176 -
  11.177 -	if(!fname || !(sdr = load_shader(fname, sdr_type))) {
  11.178 -		return 0;
  11.179 -	}
  11.180 -	return sdr;
  11.181 -}
  11.182 -
  11.183 -
  11.184  /* ---- gpu programs ---- */
  11.185  
  11.186  unsigned int create_program(void)
  11.187 @@ -165,18 +176,28 @@
  11.188  	return prog;
  11.189  }
  11.190  
  11.191 -unsigned int create_program_link(unsigned int vs, unsigned int ps)
  11.192 +unsigned int create_program_link(unsigned int sdr0, ...)
  11.193  {
  11.194 -	unsigned int prog;
  11.195 +	unsigned int prog, sdr;
  11.196 +	va_list ap;
  11.197  
  11.198  	if(!(prog = create_program())) {
  11.199  		return 0;
  11.200  	}
  11.201  
  11.202 -	attach_shader(prog, vs);
  11.203 -	assert(glGetError() == GL_NO_ERROR);
  11.204 -	attach_shader(prog, ps);
  11.205 -	assert(glGetError() == GL_NO_ERROR);
  11.206 +	attach_shader(prog, sdr0);
  11.207 +	if(glGetError()) {
  11.208 +		return 0;
  11.209 +	}
  11.210 +
  11.211 +	va_start(ap, sdr0);
  11.212 +	while((sdr = va_arg(ap, unsigned int))) {
  11.213 +		attach_shader(prog, sdr);
  11.214 +		if(glGetError()) {
  11.215 +			return 0;
  11.216 +		}
  11.217 +	}
  11.218 +	va_end(ap);
  11.219  
  11.220  	if(link_program(prog) == -1) {
  11.221  		free_program(prog);
  11.222 @@ -187,12 +208,15 @@
  11.223  
  11.224  unsigned int create_program_load(const char *vfile, const char *pfile)
  11.225  {
  11.226 -	unsigned int vs, ps;
  11.227 +	unsigned int vs = 0, ps = 0;
  11.228  
  11.229 -	if(!(vs = get_vertex_shader(vfile)) || !(ps = get_pixel_shader(pfile))) {
  11.230 +	if(vfile && *vfile && !(vs = load_vertex_shader(vfile))) {
  11.231  		return 0;
  11.232  	}
  11.233 -	return create_program_link(vs, ps);
  11.234 +	if(pfile && *pfile && !(ps = load_pixel_shader(pfile))) {
  11.235 +		return 0;
  11.236 +	}
  11.237 +	return create_program_link(vs, ps, 0);
  11.238  }
  11.239  
  11.240  void free_program(unsigned int sdr)
  11.241 @@ -202,8 +226,16 @@
  11.242  
  11.243  void attach_shader(unsigned int prog, unsigned int sdr)
  11.244  {
  11.245 -	glAttachShader(prog, sdr);
  11.246 -	assert(glGetError() == GL_NO_ERROR);
  11.247 +	int err;
  11.248 +
  11.249 +	if(prog && sdr) {
  11.250 +		assert(glGetError() == GL_NO_ERROR);
  11.251 +		glAttachShader(prog, sdr);
  11.252 +		if((err = glGetError()) != GL_NO_ERROR) {
  11.253 +			fprintf(stderr, "failed to attach shader %u to program %u (err: 0x%x)\n", sdr, prog, err);
  11.254 +			abort();
  11.255 +		}
  11.256 +	}
  11.257  }
  11.258  
  11.259  int link_program(unsigned int prog)
  11.260 @@ -222,6 +254,7 @@
  11.261  		if((info_str = malloc(info_len + 1))) {
  11.262  			glGetProgramInfoLog(prog, info_len, 0, info_str);
  11.263  			assert(glGetError() == GL_NO_ERROR);
  11.264 +			info_str[info_len] = 0;
  11.265  		}
  11.266  	}
  11.267  
  11.268 @@ -259,13 +292,13 @@
  11.269  #define BEGIN_UNIFORM_CODE \
  11.270  	int loc, curr_prog; \
  11.271  	glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog); \
  11.272 -	if(curr_prog != prog && bind_program(prog) == -1) { \
  11.273 +	if((unsigned int)curr_prog != prog && bind_program(prog) == -1) { \
  11.274  		return -1; \
  11.275  	} \
  11.276  	if((loc = glGetUniformLocation(prog, name)) != -1)
  11.277  
  11.278  #define END_UNIFORM_CODE \
  11.279 -	if(curr_prog != prog) { \
  11.280 +	if((unsigned int)curr_prog != prog) { \
  11.281  		bind_program(curr_prog); \
  11.282  	} \
  11.283  	return loc == -1 ? -1 : 0
  11.284 @@ -286,6 +319,14 @@
  11.285  	END_UNIFORM_CODE;
  11.286  }
  11.287  
  11.288 +int set_uniform_float2(unsigned int prog, const char *name, float x, float y)
  11.289 +{
  11.290 +	BEGIN_UNIFORM_CODE {
  11.291 +		glUniform2f(loc, x, y);
  11.292 +	}
  11.293 +	END_UNIFORM_CODE;
  11.294 +}
  11.295 +
  11.296  int set_uniform_float3(unsigned int prog, const char *name, float x, float y, float z)
  11.297  {
  11.298  	BEGIN_UNIFORM_CODE {
  11.299 @@ -323,13 +364,13 @@
  11.300  	int loc, curr_prog;
  11.301  
  11.302  	glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog);
  11.303 -	if(curr_prog != prog && bind_program(prog) == -1) {
  11.304 +	if((unsigned int)curr_prog != prog && bind_program(prog) == -1) {
  11.305  		return -1;
  11.306  	}
  11.307  
  11.308  	loc = glGetAttribLocation(prog, (char*)name);
  11.309  
  11.310 -	if(curr_prog != prog) {
  11.311 +	if((unsigned int)curr_prog != prog) {
  11.312  		bind_program(curr_prog);
  11.313  	}
  11.314  	return loc;
  11.315 @@ -339,3 +380,29 @@
  11.316  {
  11.317  	glVertexAttrib3f(attr_loc, x, y, z);
  11.318  }
  11.319 +
  11.320 +static const char *sdrtypestr(unsigned int sdrtype)
  11.321 +{
  11.322 +	switch(sdrtype) {
  11.323 +	case GL_VERTEX_SHADER:
  11.324 +		return "vertex";
  11.325 +	case GL_FRAGMENT_SHADER:
  11.326 +		return "pixel";
  11.327 +#ifdef GL_TESS_CONTROL_SHADER
  11.328 +	case GL_TESS_CONTROL_SHADER:
  11.329 +		return "tessellation control";
  11.330 +#endif
  11.331 +#ifdef GL_TESS_EVALUATION_SHADER
  11.332 +	case GL_TESS_EVALUATION_SHADER:
  11.333 +		return "tessellation evaluation";
  11.334 +#endif
  11.335 +#ifdef GL_GEOMETRY_SHADER
  11.336 +	case GL_GEOMETRY_SHADER:
  11.337 +		return "geometry";
  11.338 +#endif
  11.339 +
  11.340 +	default:
  11.341 +		break;
  11.342 +	}
  11.343 +	return "<unknown>";
  11.344 +}
    12.1 --- a/src/sdr.h	Sat Oct 03 06:10:30 2015 +0300
    12.2 +++ b/src/sdr.h	Sun Oct 04 08:15:24 2015 +0300
    12.3 @@ -1,21 +1,3 @@
    12.4 -/*
    12.5 -Stereoscopic tunnel for iOS.
    12.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
    12.7 -
    12.8 -This program is free software: you can redistribute it and/or modify
    12.9 -it under the terms of the GNU General Public License as published by
   12.10 -the Free Software Foundation, either version 3 of the License, or
   12.11 -(at your option) any later version.
   12.12 -
   12.13 -This program is distributed in the hope that it will be useful,
   12.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.16 -GNU General Public License for more details.
   12.17 -
   12.18 -You should have received a copy of the GNU General Public License
   12.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   12.20 -*/
   12.21 -
   12.22  #ifndef SDR_H_
   12.23  #define SDR_H_
   12.24  
   12.25 @@ -26,23 +8,25 @@
   12.26  /* ---- shaders ---- */
   12.27  unsigned int create_vertex_shader(const char *src);
   12.28  unsigned int create_pixel_shader(const char *src);
   12.29 +unsigned int create_tessctl_shader(const char *src);
   12.30 +unsigned int create_tesseval_shader(const char *src);
   12.31 +unsigned int create_geometry_shader(const char *src);
   12.32  unsigned int create_shader(const char *src, unsigned int sdr_type);
   12.33  void free_shader(unsigned int sdr);
   12.34  
   12.35  unsigned int load_vertex_shader(const char *fname);
   12.36  unsigned int load_pixel_shader(const char *fname);
   12.37 +unsigned int load_tessctl_shader(const char *fname);
   12.38 +unsigned int load_tesseval_shader(const char *fname);
   12.39 +unsigned int load_geometry_shader(const char *fname);
   12.40  unsigned int load_shader(const char *src, unsigned int sdr_type);
   12.41  
   12.42 -unsigned int get_vertex_shader(const char *fname);
   12.43 -unsigned int get_pixel_shader(const char *fname);
   12.44 -unsigned int get_shader(const char *fname, unsigned int sdr_type);
   12.45 -
   12.46  int add_shader(const char *fname, unsigned int sdr);
   12.47  int remove_shader(const char *fname);
   12.48  
   12.49  /* ---- gpu programs ---- */
   12.50  unsigned int create_program(void);
   12.51 -unsigned int create_program_link(unsigned int vs, unsigned int ps);
   12.52 +unsigned int create_program_link(unsigned int sdr0, ...);
   12.53  unsigned int create_program_load(const char *vfile, const char *pfile);
   12.54  void free_program(unsigned int sdr);
   12.55  
   12.56 @@ -52,6 +36,7 @@
   12.57  
   12.58  int set_uniform_int(unsigned int prog, const char *name, int val);
   12.59  int set_uniform_float(unsigned int prog, const char *name, float val);
   12.60 +int set_uniform_float2(unsigned int prog, const char *name, float x, float y);
   12.61  int set_uniform_float3(unsigned int prog, const char *name, float x, float y, float z);
   12.62  int set_uniform_float4(unsigned int prog, const char *name, float x, float y, float z, float w);
   12.63  int set_uniform_matrix4(unsigned int prog, const char *name, float *mat);
    13.1 --- a/src/tex.c	Sat Oct 03 06:10:30 2015 +0300
    13.2 +++ b/src/tex.c	Sun Oct 04 08:15:24 2015 +0300
    13.3 @@ -1,6 +1,6 @@
    13.4  /*
    13.5  Stereoscopic tunnel for iOS.
    13.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
    13.7 +Copyright (C) 2011-2015 John Tsiombikas <nuclear@member.fsf.org>
    13.8  
    13.9  This program is free software: you can redistribute it and/or modify
   13.10  it under the terms of the GNU General Public License as published by
   13.11 @@ -24,29 +24,63 @@
   13.12  #include "tex.h"
   13.13  #include "config.h"
   13.14  #include "imago2.h"
   13.15 +#include "assman.h"
   13.16 +
   13.17 +static size_t ioread(void *buf, size_t bytes, void *uptr);
   13.18 +static long ioseek(long offs, int whence, void *uptr);
   13.19  
   13.20  unsigned int load_texture(const char *fname)
   13.21  {
   13.22 -	int xsz, ysz;
   13.23  	unsigned int tex;
   13.24 -	void *pixels;
   13.25 +	ass_file *fp;
   13.26 +	struct img_io io;
   13.27 +	struct img_pixmap img;
   13.28  
   13.29  	if(!fname) {
   13.30  		return 0;
   13.31  	}
   13.32 -	if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) {
   13.33 -		fprintf(stderr, "failed to load image: %s\n", fname);
   13.34 +	if(!(fp = ass_fopen(fname, "rb"))) {
   13.35 +		fprintf(stderr, "failed to open texture file: %s: %s\n", fname, strerror(errno));
   13.36  		return 0;
   13.37  	}
   13.38 +	io.uptr = fp;
   13.39 +	io.read = ioread;
   13.40 +	io.write = 0;
   13.41 +	io.seek = ioseek;
   13.42 +
   13.43 +	img_init(&img);
   13.44 +	if(img_read(&img, &io) == -1) {
   13.45 +		fprintf(stderr, "failed to load image: %s\n", fname);
   13.46 +		ass_fclose(fp);
   13.47 +		return 0;
   13.48 +	}
   13.49 +	ass_fclose(fp);
   13.50 +	img_convert(&img, IMG_FMT_RGBA32);
   13.51  
   13.52  	glGenTextures(1, &tex);
   13.53  	glBindTexture(GL_TEXTURE_2D, tex);
   13.54  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   13.55  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   13.56 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   13.57 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   13.58  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   13.59 -	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
   13.60 -	img_free_pixels(pixels);
   13.61 +
   13.62 +#ifdef __GLEW_H__
   13.63 +	if(GLEW_SGIS_generate_mipmap) {
   13.64 +		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
   13.65 +#endif
   13.66 +		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0,
   13.67 +				GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
   13.68 +#ifdef __GLEW_H__
   13.69 +	} else {
   13.70 +		gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, img.width, img.height,
   13.71 +				GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
   13.72 +	}
   13.73 +#endif
   13.74 +
   13.75 +#ifdef GL_ES_VERSION_2_0
   13.76 +	glGenerateMipmap(GL_TEXTURE_2D);
   13.77 +#endif
   13.78 +	img_destroy(&img);
   13.79  
   13.80  	return tex;
   13.81  }
   13.82 @@ -55,7 +89,7 @@
   13.83  {
   13.84  	glActiveTexture(GL_TEXTURE0 + unit);
   13.85  
   13.86 -#ifndef IPHONE
   13.87 +#ifndef GL_ES_VERSION_2_0
   13.88  	if(tex) {
   13.89  		glEnable(GL_TEXTURE_2D);
   13.90  	} else {
   13.91 @@ -65,3 +99,13 @@
   13.92  
   13.93  	glBindTexture(GL_TEXTURE_2D, tex);
   13.94  }
   13.95 +
   13.96 +static size_t ioread(void *buf, size_t bytes, void *uptr)
   13.97 +{
   13.98 +	return ass_fread(buf, 1, bytes, uptr);
   13.99 +}
  13.100 +
  13.101 +static long ioseek(long offs, int whence, void *uptr)
  13.102 +{
  13.103 +	return ass_fseek(uptr, offs, whence);
  13.104 +}