goat3dgfx

changeset 25:6236080aaea4

LIBOVR conditional compilation fix
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 27 Feb 2014 01:40:12 +0200
parents 0ac499409edd
children 940e5b1e2f92
files examples/viewscn/src/main.cc goat3dgfx.sln goat3dgfx.vcproj src/vr/vr.cc src/vr/vr_impl.h
diffstat 5 files changed, 175 insertions(+), 100 deletions(-) [+]
line diff
     1.1 --- a/examples/viewscn/src/main.cc	Tue Feb 25 23:47:48 2014 +0200
     1.2 +++ b/examples/viewscn/src/main.cc	Thu Feb 27 01:40:12 2014 +0200
     1.3 @@ -87,9 +87,9 @@
     1.4  
     1.5  	//setup_gl_matrices();
     1.6  
     1.7 -	bind_shader(sdr);
     1.8 +	goatgfx::bind_shader(sdr);
     1.9  	scn->draw();
    1.10 -	bind_shader(0);
    1.11 +	goatgfx::bind_shader(0);
    1.12  
    1.13  	/*glBegin(GL_QUADS);
    1.14  	glColor3f(1, 1, 1);
     2.1 --- a/goat3dgfx.sln	Tue Feb 25 23:47:48 2014 +0200
     2.2 +++ b/goat3dgfx.sln	Thu Feb 27 01:40:12 2014 +0200
     2.3 @@ -9,6 +9,9 @@
     2.4  	EndProjectSection
     2.5  EndProject
     2.6  Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "viewscn", "examples\viewscn\viewscn.vcproj", "{7240C31B-8746-4816-AE13-BF0F75228411}"
     2.7 +	ProjectSection(ProjectDependencies) = postProject
     2.8 +		{251F8AFF-5A37-4F10-A519-C55C40E127AF} = {251F8AFF-5A37-4F10-A519-C55C40E127AF}
     2.9 +	EndProjectSection
    2.10  EndProject
    2.11  Global
    2.12  	GlobalSection(SolutionConfigurationPlatforms) = preSolution
     3.1 --- a/goat3dgfx.vcproj	Tue Feb 25 23:47:48 2014 +0200
     3.2 +++ b/goat3dgfx.vcproj	Thu Feb 27 01:40:12 2014 +0200
     3.3 @@ -25,6 +25,7 @@
     3.4  			>
     3.5  			<Tool
     3.6  				Name="VCPreBuildEventTool"
     3.7 +				CommandLine="echo #ifndef GOAT3DGFX_CONFIG_H_&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #define GOAT3DGFX_CONFIG_H_&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #define USE_VR&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #define USE_LIBOVR&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #endif&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;"
     3.8  			/>
     3.9  			<Tool
    3.10  				Name="VCCustomBuildTool"
    3.11 @@ -41,6 +42,7 @@
    3.12  			<Tool
    3.13  				Name="VCCLCompilerTool"
    3.14  				Optimization="0"
    3.15 +				AdditionalIncludeDirectories="$(SolutionDir)\src"
    3.16  				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GOAT3DGFX_EXPORTS"
    3.17  				MinimalRebuild="true"
    3.18  				BasicRuntimeChecks="3"
    3.19 @@ -61,6 +63,7 @@
    3.20  			/>
    3.21  			<Tool
    3.22  				Name="VCLibrarianTool"
    3.23 +				AdditionalDependencies="libovrd.lib"
    3.24  				OutputFile="$(OutDir)\$(ProjectName)-dbg.lib"
    3.25  			/>
    3.26  			<Tool
    3.27 @@ -77,7 +80,7 @@
    3.28  			/>
    3.29  			<Tool
    3.30  				Name="VCPostBuildEventTool"
    3.31 -				CommandLine="mkdir usr\include\goat3dgfx&#x0D;&#x0A;mkdir usr\lib&#x0D;&#x0A;copy /Y src\*.h usr\include\goat3dgfx\&#x0D;&#x0A;copy /Y src\*.inl usr\include\goat3dgfx\&#x0D;&#x0A;copy /Y $(TargetPath) usr\lib\"
    3.32 +				CommandLine="mkdir usr\include\goat3dgfx&#x0D;&#x0A;mkdir usr\lib&#x0D;&#x0A;copy /Y src\*.h usr\include\goat3dgfx\&#x0D;&#x0A;copy /Y src\*.inl usr\include\goat3dgfx\&#x0D;&#x0A;copy /Y $(TargetPath) usr\lib\&#x0D;&#x0A;"
    3.33  			/>
    3.34  		</Configuration>
    3.35  		<Configuration
    3.36 @@ -90,6 +93,7 @@
    3.37  			>
    3.38  			<Tool
    3.39  				Name="VCPreBuildEventTool"
    3.40 +				CommandLine="echo #ifndef GOAT3DGFX_CONFIG_H_&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #define GOAT3DGFX_CONFIG_H_&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #define USE_VR&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #define USE_LIBOVR&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;echo #endif&gt;&gt;$(ProjectDir)\src\config.h&#x0D;&#x0A;"
    3.41  			/>
    3.42  			<Tool
    3.43  				Name="VCCustomBuildTool"
    3.44 @@ -107,6 +111,7 @@
    3.45  				Name="VCCLCompilerTool"
    3.46  				Optimization="2"
    3.47  				EnableIntrinsicFunctions="true"
    3.48 +				AdditionalIncludeDirectories="$(SolutionDir)\src"
    3.49  				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GOAT3DGFX_EXPORTS"
    3.50  				RuntimeLibrary="2"
    3.51  				EnableFunctionLevelLinking="true"
    3.52 @@ -126,6 +131,7 @@
    3.53  			/>
    3.54  			<Tool
    3.55  				Name="VCLibrarianTool"
    3.56 +				AdditionalDependencies="libovr.lib"
    3.57  			/>
    3.58  			<Tool
    3.59  				Name="VCALinkTool"
    3.60 @@ -149,7 +155,7 @@
    3.61  	<Files>
    3.62  		<Filter
    3.63  			Name="src"
    3.64 -			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
    3.65 +			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;inl"
    3.66  			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
    3.67  			>
    3.68  			<File
    3.69 @@ -161,113 +167,35 @@
    3.70  				>
    3.71  			</File>
    3.72  			<File
    3.73 +				RelativePath=".\src\assload.h"
    3.74 +				>
    3.75 +			</File>
    3.76 +			<File
    3.77 +				RelativePath=".\src\camera.cc"
    3.78 +				>
    3.79 +			</File>
    3.80 +			<File
    3.81 +				RelativePath=".\src\camera.h"
    3.82 +				>
    3.83 +			</File>
    3.84 +			<File
    3.85  				RelativePath=".\src\curve.cc"
    3.86  				>
    3.87  			</File>
    3.88  			<File
    3.89 +				RelativePath=".\src\curve.h"
    3.90 +				>
    3.91 +			</File>
    3.92 +			<File
    3.93  				RelativePath=".\src\curveload.cc"
    3.94  				>
    3.95  			</File>
    3.96  			<File
    3.97 -				RelativePath=".\src\datapath.cc"
    3.98 +				RelativePath=".\src\curveload.h"
    3.99  				>
   3.100  			</File>
   3.101  			<File
   3.102 -				RelativePath=".\src\geom.cc"
   3.103 -				>
   3.104 -			</File>
   3.105 -			<File
   3.106 -				RelativePath=".\src\gfxutil.cc"
   3.107 -				>
   3.108 -			</File>
   3.109 -			<File
   3.110 -				RelativePath=".\src\image.cc"
   3.111 -				>
   3.112 -			</File>
   3.113 -			<File
   3.114 -				RelativePath=".\src\logger.cc"
   3.115 -				>
   3.116 -			</File>
   3.117 -			<File
   3.118 -				RelativePath=".\src\material.cc"
   3.119 -				>
   3.120 -			</File>
   3.121 -			<File
   3.122 -				RelativePath=".\src\mesh.cc"
   3.123 -				>
   3.124 -			</File>
   3.125 -			<File
   3.126 -				RelativePath=".\src\meshgen.cc"
   3.127 -				>
   3.128 -			</File>
   3.129 -			<File
   3.130 -				RelativePath=".\src\object.cc"
   3.131 -				>
   3.132 -			</File>
   3.133 -			<File
   3.134 -				RelativePath=".\src\opengl.cc"
   3.135 -				>
   3.136 -			</File>
   3.137 -			<File
   3.138 -				RelativePath=".\src\psyspp.cc"
   3.139 -				>
   3.140 -			</File>
   3.141 -			<File
   3.142 -				RelativePath=".\src\rtarg.cc"
   3.143 -				>
   3.144 -			</File>
   3.145 -			<File
   3.146 -				RelativePath=".\src\scene.cc"
   3.147 -				>
   3.148 -			</File>
   3.149 -			<File
   3.150 -				RelativePath=".\src\sdrman.cc"
   3.151 -				>
   3.152 -			</File>
   3.153 -			<File
   3.154 -				RelativePath=".\src\shader.cc"
   3.155 -				>
   3.156 -			</File>
   3.157 -			<File
   3.158 -				RelativePath=".\src\texgen.cc"
   3.159 -				>
   3.160 -			</File>
   3.161 -			<File
   3.162 -				RelativePath=".\src\texman.cc"
   3.163 -				>
   3.164 -			</File>
   3.165 -			<File
   3.166 -				RelativePath=".\src\texture.cc"
   3.167 -				>
   3.168 -			</File>
   3.169 -			<File
   3.170 -				RelativePath=".\src\timer.cc"
   3.171 -				>
   3.172 -			</File>
   3.173 -			<File
   3.174 -				RelativePath=".\src\unistate.cc"
   3.175 -				>
   3.176 -			</File>
   3.177 -			<File
   3.178 -				RelativePath=".\src\xform_node.cc"
   3.179 -				>
   3.180 -			</File>
   3.181 -		</Filter>
   3.182 -		<Filter
   3.183 -			Name="include"
   3.184 -			Filter="h;hpp;hxx;hm;inl;inc;xsd"
   3.185 -			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
   3.186 -			>
   3.187 -			<File
   3.188 -				RelativePath=".\src\assload.h"
   3.189 -				>
   3.190 -			</File>
   3.191 -			<File
   3.192 -				RelativePath=".\src\curve.h"
   3.193 -				>
   3.194 -			</File>
   3.195 -			<File
   3.196 -				RelativePath=".\src\curveload.h"
   3.197 +				RelativePath=".\src\datapath.cc"
   3.198  				>
   3.199  			</File>
   3.200  			<File
   3.201 @@ -283,85 +211,193 @@
   3.202  				>
   3.203  			</File>
   3.204  			<File
   3.205 +				RelativePath=".\src\geom.cc"
   3.206 +				>
   3.207 +			</File>
   3.208 +			<File
   3.209  				RelativePath=".\src\geom.h"
   3.210  				>
   3.211  			</File>
   3.212  			<File
   3.213 +				RelativePath=".\src\gfxutil.cc"
   3.214 +				>
   3.215 +			</File>
   3.216 +			<File
   3.217  				RelativePath=".\src\gfxutil.h"
   3.218  				>
   3.219  			</File>
   3.220  			<File
   3.221 +				RelativePath=".\src\goat3dgfx.cc"
   3.222 +				>
   3.223 +			</File>
   3.224 +			<File
   3.225 +				RelativePath=".\src\goat3dgfx.h"
   3.226 +				>
   3.227 +			</File>
   3.228 +			<File
   3.229 +				RelativePath=".\src\image.cc"
   3.230 +				>
   3.231 +			</File>
   3.232 +			<File
   3.233  				RelativePath=".\src\image.h"
   3.234  				>
   3.235  			</File>
   3.236  			<File
   3.237 +				RelativePath=".\src\logger.cc"
   3.238 +				>
   3.239 +			</File>
   3.240 +			<File
   3.241  				RelativePath=".\src\logger.h"
   3.242  				>
   3.243  			</File>
   3.244  			<File
   3.245 +				RelativePath=".\src\material.cc"
   3.246 +				>
   3.247 +			</File>
   3.248 +			<File
   3.249  				RelativePath=".\src\material.h"
   3.250  				>
   3.251  			</File>
   3.252  			<File
   3.253 +				RelativePath=".\src\mesh.cc"
   3.254 +				>
   3.255 +			</File>
   3.256 +			<File
   3.257  				RelativePath=".\src\mesh.h"
   3.258  				>
   3.259  			</File>
   3.260  			<File
   3.261 +				RelativePath=".\src\meshgen.cc"
   3.262 +				>
   3.263 +			</File>
   3.264 +			<File
   3.265  				RelativePath=".\src\meshgen.h"
   3.266  				>
   3.267  			</File>
   3.268  			<File
   3.269 +				RelativePath=".\src\object.cc"
   3.270 +				>
   3.271 +			</File>
   3.272 +			<File
   3.273  				RelativePath=".\src\object.h"
   3.274  				>
   3.275  			</File>
   3.276  			<File
   3.277 +				RelativePath=".\src\opengl.cc"
   3.278 +				>
   3.279 +			</File>
   3.280 +			<File
   3.281  				RelativePath=".\src\opengl.h"
   3.282  				>
   3.283  			</File>
   3.284  			<File
   3.285 +				RelativePath=".\src\psyspp.cc"
   3.286 +				>
   3.287 +			</File>
   3.288 +			<File
   3.289  				RelativePath=".\src\psyspp.h"
   3.290  				>
   3.291  			</File>
   3.292  			<File
   3.293 +				RelativePath=".\src\rtarg.cc"
   3.294 +				>
   3.295 +			</File>
   3.296 +			<File
   3.297  				RelativePath=".\src\rtarg.h"
   3.298  				>
   3.299  			</File>
   3.300  			<File
   3.301 +				RelativePath=".\src\scene.cc"
   3.302 +				>
   3.303 +			</File>
   3.304 +			<File
   3.305  				RelativePath=".\src\scene.h"
   3.306  				>
   3.307  			</File>
   3.308  			<File
   3.309 +				RelativePath=".\src\sdrman.cc"
   3.310 +				>
   3.311 +			</File>
   3.312 +			<File
   3.313  				RelativePath=".\src\sdrman.h"
   3.314  				>
   3.315  			</File>
   3.316  			<File
   3.317 +				RelativePath=".\src\shader.cc"
   3.318 +				>
   3.319 +			</File>
   3.320 +			<File
   3.321  				RelativePath=".\src\shader.h"
   3.322  				>
   3.323  			</File>
   3.324  			<File
   3.325 +				RelativePath=".\src\texgen.cc"
   3.326 +				>
   3.327 +			</File>
   3.328 +			<File
   3.329  				RelativePath=".\src\texgen.h"
   3.330  				>
   3.331  			</File>
   3.332  			<File
   3.333 +				RelativePath=".\src\texman.cc"
   3.334 +				>
   3.335 +			</File>
   3.336 +			<File
   3.337  				RelativePath=".\src\texman.h"
   3.338  				>
   3.339  			</File>
   3.340  			<File
   3.341 +				RelativePath=".\src\texture.cc"
   3.342 +				>
   3.343 +			</File>
   3.344 +			<File
   3.345  				RelativePath=".\src\texture.h"
   3.346  				>
   3.347  			</File>
   3.348  			<File
   3.349 +				RelativePath=".\src\timer.cc"
   3.350 +				>
   3.351 +			</File>
   3.352 +			<File
   3.353  				RelativePath=".\src\timer.h"
   3.354  				>
   3.355  			</File>
   3.356  			<File
   3.357 +				RelativePath=".\src\unistate.cc"
   3.358 +				>
   3.359 +			</File>
   3.360 +			<File
   3.361  				RelativePath=".\src\unistate.h"
   3.362  				>
   3.363  			</File>
   3.364  			<File
   3.365 +				RelativePath=".\src\vr.h"
   3.366 +				>
   3.367 +			</File>
   3.368 +			<File
   3.369 +				RelativePath=".\src\xform_node.cc"
   3.370 +				>
   3.371 +			</File>
   3.372 +			<File
   3.373  				RelativePath=".\src\xform_node.h"
   3.374  				>
   3.375  			</File>
   3.376 +			<Filter
   3.377 +				Name="vr"
   3.378 +				>
   3.379 +				<File
   3.380 +					RelativePath=".\src\vr\vr.cc"
   3.381 +					>
   3.382 +				</File>
   3.383 +				<File
   3.384 +					RelativePath=".\src\vr\vr_impl.h"
   3.385 +					>
   3.386 +				</File>
   3.387 +				<File
   3.388 +					RelativePath=".\src\vr\vr_sdr.h"
   3.389 +					>
   3.390 +				</File>
   3.391 +			</Filter>
   3.392  		</Filter>
   3.393  	</Files>
   3.394  	<Globals>
     4.1 --- a/src/vr/vr.cc	Tue Feb 25 23:47:48 2014 +0200
     4.2 +++ b/src/vr/vr.cc	Thu Feb 27 01:40:12 2014 +0200
     4.3 @@ -1,5 +1,11 @@
     4.4 +#include "config.h"
     4.5 +
     4.6  #include <stdio.h>
     4.7 +#include <string.h>
     4.8 +#define _USE_MATH_DEFINES
     4.9 +#include <math.h>
    4.10  #include <GL/glew.h>
    4.11 +#include "vmath/vmath.h"
    4.12  #include "vr.h"
    4.13  #include "vr_impl.h"
    4.14  #include "vr_sdr.h"
    4.15 @@ -35,8 +41,10 @@
    4.16  extern "C" void vr_shutdown(void)
    4.17  {
    4.18  	delete [] vr_ctx.info.display;
    4.19 +#ifdef USE_LIBOVR
    4.20  	delete vr_ctx.ovr_sfusion;
    4.21  	//System::Destroy();
    4.22 +#endif
    4.23  
    4.24  	memset(&vr_ctx, 0, sizeof vr_ctx);
    4.25  }
    4.26 @@ -53,6 +61,7 @@
    4.27  
    4.28  static bool init_ovr()
    4.29  {
    4.30 +#ifdef USE_LIBOVR
    4.31  	LogMaskConstants log_level = LogMask_All;
    4.32  	// initialize Oculus SDK
    4.33  	const char *logenv = getenv("VR_LOGLEVEL");
    4.34 @@ -150,6 +159,7 @@
    4.35  		vr_ctx.ovr_sfusion = new SensorFusion;
    4.36  		vr_ctx.ovr_sfusion->AttachToSensor(vr_ctx.ovr_sensor_dev);
    4.37  	}
    4.38 +#endif	// USE_LIBOVR
    4.39  	return true;
    4.40  }
    4.41  
    4.42 @@ -289,12 +299,16 @@
    4.43  
    4.44  extern "C" void vr_set_prediction_sec(float dt)
    4.45  {
    4.46 +#ifdef USE_LIBOVR
    4.47  	vr_ctx.ovr_sfusion->SetPrediction(dt);
    4.48 +#endif
    4.49  }
    4.50  
    4.51  extern "C" float vr_get_prediction_sec(void)
    4.52  {
    4.53 +#ifdef USE_LIBOVR
    4.54  	return vr_ctx.ovr_sfusion->GetPredictionDelta();
    4.55 +#endif
    4.56  }
    4.57  
    4.58  extern "C" void vr_get_view_matrix(float *res, int eye)
    4.59 @@ -304,12 +318,19 @@
    4.60  
    4.61  extern "C" void vr_get_proj_matrix(float *res, int eye)
    4.62  {
    4.63 +#ifdef USE_LIBOVR
    4.64  	static float eye_scale[] = {0.0, 1.0, -1.0};
    4.65  
    4.66  	Matrix4f proj = Matrix4f::PerspectiveRH(vr_ctx.info.fov, vr_ctx.info.aspect / 2.0, 0.3, 1000.0);
    4.67  	proj = Matrix4f::Translation(vr_ctx.info.proj_center_offset * eye_scale[eye], 0, 0) * proj;
    4.68  
    4.69  	memcpy(res, proj.M[0], 16 * sizeof(float));
    4.70 +#else
    4.71 +	Matrix4x4 proj;
    4.72 +	proj.set_perspective(vr_ctx.info.fov, vr_ctx.info.aspect, 0.3, 1000.0);
    4.73 +	proj.transpose();
    4.74 +	memcpy(res, proj[0], 16 * sizeof(float));
    4.75 +#endif
    4.76  }
    4.77  
    4.78  extern "C" void vr_get_translation(float *offs)
    4.79 @@ -320,17 +341,26 @@
    4.80  
    4.81  extern "C" void vr_get_rotation(float *quat)
    4.82  {
    4.83 +#ifdef USE_LIBOVR
    4.84  	Quatf oq = vr_ctx.ovr_sfusion->GetPredictedOrientation();
    4.85  	quat[0] = oq.x;
    4.86  	quat[1] = oq.y;
    4.87  	quat[2] = oq.z;
    4.88  	quat[3] = oq.w;
    4.89 +#else
    4.90 +	quat[0] = quat[1] = quat[2] = 0.0;
    4.91 +	quat[3] = 1.0;
    4.92 +#endif
    4.93  }
    4.94  
    4.95  extern "C" void vr_get_rotation_euler(float *euler)
    4.96  {
    4.97 +#ifdef USE_LIBOVR
    4.98  	Quatf oq = vr_ctx.ovr_sfusion->GetPredictedOrientation();
    4.99  	oq.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(euler + 1, euler, euler + 2);
   4.100 +#else
   4.101 +	euler[0] = euler[1] = euler[2] = 0.0;
   4.102 +#endif
   4.103  }
   4.104  
   4.105  extern "C" void vr_draw_eye(int eye, unsigned int tex, float tex_scale_x, float tex_scale_y)
     5.1 --- a/src/vr/vr_impl.h	Tue Feb 25 23:47:48 2014 +0200
     5.2 +++ b/src/vr/vr_impl.h	Thu Feb 27 01:40:12 2014 +0200
     5.3 @@ -1,15 +1,21 @@
     5.4  #ifndef VR_IMPL_H_
     5.5  #define VR_IMPL_H_
     5.6  
     5.7 +#include "config.h"
     5.8 +
     5.9 +#ifdef USE_LIBOVR
    5.10  #include <OVR.h>
    5.11  
    5.12  using namespace OVR;
    5.13 +#endif
    5.14  
    5.15  struct VRContext {
    5.16 +#ifdef USE_LIBOVR
    5.17  	DeviceManager *ovr_devman;
    5.18  	HMDDevice *ovr_hmd_dev;
    5.19  	SensorDevice *ovr_sensor_dev;
    5.20  	SensorFusion *ovr_sfusion;
    5.21 +#endif
    5.22  
    5.23  	struct {
    5.24  		char *display;