Fix blenderplayer command line option parsing.

Fix stereo rendering in vertex array mode.  Added sidebyside & anaglyph stereo modes.
This commit is contained in:
Kester Maddock 2004-08-10 11:34:12 +00:00
parent 7c9b4e6f9a
commit 47c5b8ff26
8 changed files with 158 additions and 123 deletions

@ -121,7 +121,6 @@ void GPC_Canvas::ClearBuffer(
ogltype |= GL_DEPTH_BUFFER_BIT;
::glClear(ogltype);
}

@ -352,8 +352,8 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
// SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
// SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);
//bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
//bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
bool useVertexArrays = SYS_GetCommandLineInt(syshandle,"vertexarrays",1) != 0;
// create the canvas, rasterizer and rendertools
@ -370,7 +370,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
m_rasterizer = new RAS_VAOpenGLRasterizer(m_canvas);
else
m_rasterizer = new RAS_OpenGLRasterizer(m_canvas);
m_rasterizer->SetStereoMode(stereoMode);
m_rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) stereoMode);
if (!m_rasterizer)
goto initFailed;
@ -415,7 +415,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
m_ketsjiengine->SetTimingDisplay(frameRate, false, false);
m_ketsjiengine->SetUseFixedTime(false);
//m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
m_engineInitialized = true;
}

@ -113,18 +113,32 @@ void usage(char* program)
printf(" t = window top coordinate\n");
printf(" w = window width\n");
printf(" h = window height\n");
/* printf(" -f: start game in full screen mode\n");
printf(" -f: start game in full screen mode\n");
printf(" fw = full screen mode pixel width\n");
printf(" fh = full screen mode pixel height\n");
printf(" fb = full screen mode bits per pixel\n");
printf(" ff = full screen mode frequency\n"); */
printf(" ff = full screen mode frequency\n");
printf(" -s: start player in stereo\n");
printf(" stereomode = hwpageflip or syncdoubling depending on the type of stereo you want\n");
printf(" stereomode: hwpageflip (Quad buffered shutter glasses)\n");
printf(" syncdoubling (Above Below)\n");
printf(" sidebyside (Left Right)\n");
printf(" anaglyph (Red-Blue glasses)\n");
printf(" depending on the type of stereo you want\n");
#ifdef _WIN32
printf(" -c: keep console window open\n");
#endif
printf(" -g: game engine options:\n");
printf(" Name Default Description\n");
printf(" ----------------------------------------\n");
printf(" fixedtime 0 Do the same timestep each frame \"Enable all frames\"\n");
printf(" nomipmap 0 Disable mipmaps\n");
printf(" show_framerate 0 Show the frame rate\n");
printf(" show_properties 0 Show debug properties\n");
printf(" show_profile 0 Show profiling information\n");
printf(" vertexarrays 1 Enable vertex arrays\n");
printf("\n");
printf("example: %s -p 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program);
printf("example: %s -g vertexarrays = 0 c:\\loadtest.blend\n", program);
}
char *get_filename(int argc, char **argv) {
@ -216,7 +230,7 @@ int main(int argc, char** argv)
bool fullScreenParFound = false;
bool windowParFound = false;
bool closeConsole = true;
int stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
bool stereoWindow = false;
bool stereoParFound = false;
int windowLeft = 100;
@ -225,7 +239,7 @@ int main(int argc, char** argv)
int windowHeight = 480;
GHOST_TUns32 fullScreenWidth = 0;
GHOST_TUns32 fullScreenHeight= 0;
int fullScreenBpp = 16;
int fullScreenBpp = 32;
int fullScreenFrequency = 60;
#ifdef __linux__
@ -263,12 +277,11 @@ int main(int argc, char** argv)
#ifndef NDEBUG
printf("argv[0] = '%s'\n", argv[0]);
#endif
for (i = 1; (i < argc) && !error; i++)
for (i = 1; (i < argc) && !error;)
{
#ifndef NDEBUG
printf("argv[%d] = '%s'\n", i, argv[i]);
#endif
if (argv[i][0] == '-')
{
switch (argv[i][1])
@ -288,7 +301,13 @@ int main(int argc, char** argv)
{
i++;
// Assignment
SYS_WriteCommandLineInt(syshandle, paramname, atoi(argv[i]));
SYS_WriteCommandLineFloat(syshandle, paramname, atof(argv[i]));
SYS_WriteCommandLineString(syshandle, paramname, argv[i]);
#ifndef NDEBUG
printf("%s = '%s'\n", paramname, argv[i]);
#endif
i++;
}
else
{
@ -298,7 +317,7 @@ int main(int argc, char** argv)
}
else
{
SYS_WriteCommandLineInt(syshandle, argv[i], 1);
SYS_WriteCommandLineInt(syshandle, argv[i++], 1);
}
}
}
@ -313,7 +332,7 @@ int main(int argc, char** argv)
windowLeft = atoi(argv[i++]);
windowTop = atoi(argv[i++]);
windowWidth = atoi(argv[i++]);
windowHeight = atoi(argv[i]);
windowHeight = atoi(argv[i++]);
windowParFound = true;
}
else
@ -323,12 +342,27 @@ int main(int argc, char** argv)
}
}
break;
case 'f':
i++;
fullScreen = true;
fullScreenParFound = true;
if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-')
{
fullScreenWidth = atoi(argv[i++]);
fullScreenHeight = atoi(argv[i++]);
if ((i + 1) < argc && argv[i][0] != '-')
{
fullScreenBpp = atoi(argv[i++]);
if ((i + 1) < argc && argv[i][0] != '-')
fullScreenFrequency = atoi(argv[i++]);
}
}
break;
case 'w':
// Parse window position and size options
{
fullScreen = false;
fullScreenParFound = true;
fullScreenParFound = true;
i++;
}
break;
@ -350,6 +384,12 @@ int main(int argc, char** argv)
}
if(!strcmp(argv[i], "syncdoubling"))
stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
if(!strcmp(argv[i], "anaglyph"))
stereomode = RAS_IRasterizer::RAS_STEREO_ANAGLYPH;
if(!strcmp(argv[i], "sidebyside"))
stereomode = RAS_IRasterizer::RAS_STEREO_SIDEBYSIDE;
#if 0
// future stuff
if(strcmp(argv[i], "stencil")
@ -365,10 +405,14 @@ int main(int argc, char** argv)
printf("error: too few options for stereo argument.\n");
}
break;
default:
printf("Unkown argument: %s\n", argv[i++]);
break;
}
}
else
{
i++;
}
}
@ -400,7 +444,8 @@ int main(int argc, char** argv)
GHOST_ISystem* system = GHOST_ISystem::getSystem();
assertd(system);
system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight);
if (!fullScreenWidth || !fullScreenHeight)
system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight);
// process first batch of events. If the user
// drops a file on top off the blenderplayer icon, we
// recieve an event with the filename
@ -488,21 +533,9 @@ int main(int argc, char** argv)
// Check whether the game should be displayed in stereo
if (!stereoParFound)
{
if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_NOSTEREO) // ok, redundant but clear
stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
// only the hardware pageflip method needs a stereo window
if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED) {
stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
stereomode = (RAS_IRasterizer::StereoMode) scene->r.stereomode;
if (stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
stereoWindow = true;
}
if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_ABOVEBELOW)
stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
#if 0
// future stuff
if(scene->r.stereomode == RAS_IRasterizer::RAS_STEREO_STENCIL)
stereomode = RAS_STEREO_STENCIL;
#endif
}
// GPG_Application app (system, maggie, startscenename);

@ -61,7 +61,7 @@ public:
/**
* Drawing types
*/
enum {
enum DrawType {
KX_BOUNDINGBOX = 1,
KX_WIREFRAME,
KX_SOLID,
@ -72,7 +72,7 @@ public:
/**
* Valid SetDepthMask parameters
*/
enum {
enum DepthMask {
KX_DEPTHMASK_ENABLED =1,
KX_DEPTHMASK_DISABLED
};
@ -87,16 +87,18 @@ public:
/**
* Stereo mode types
*/
enum {
enum StereoMode {
RAS_STEREO_NOSTEREO = 1,
RAS_STEREO_QUADBUFFERED,
RAS_STEREO_ABOVEBELOW,
RAS_STEREO_INTERLACED
RAS_STEREO_INTERLACED,
RAS_STEREO_ANAGLYPH,
RAS_STEREO_SIDEBYSIDE
};
/**
* Render pass identifiers for stereo.
*/
enum {
enum StereoEye {
RAS_STEREO_LEFTEYE = 1,
RAS_STEREO_RIGHTEYE
};
@ -105,7 +107,7 @@ public:
* SetDepthMask enables or disables writing a fragment's depth value
* to the Z buffer.
*/
virtual void SetDepthMask(int depthmask)=0;
virtual void SetDepthMask(DepthMask depthmask)=0;
/**
* SetMaterial sets the material settings for subsequent primitives
* to be rendered with.
@ -145,7 +147,7 @@ public:
/**
* SetStereoMode will set the stereo mode
*/
virtual void SetStereoMode(const int stereomode)=0;
virtual void SetStereoMode(const StereoMode stereomode)=0;
/**
* Stereo can be used to query if the rasterizer is in stereo mode.
* @return true if stereo mode is enabled.
@ -154,7 +156,7 @@ public:
/**
* Sets which eye buffer subsequent primitives will be rendered to.
*/
virtual void SetEye(const int eye)=0;
virtual void SetEye(const StereoEye eye)=0;
/**
*/
virtual void SetEyeSeparation(const float eyeseparation)=0;

@ -55,11 +55,13 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
:RAS_IRasterizer(canvas),
m_2DCanvas(canvas),
m_fogenabled(false),
m_time(0.0),
m_stereomode(RAS_STEREO_NOSTEREO),
m_curreye(RAS_STEREO_LEFTEYE),
m_noOfScanlines(32),
m_materialCachingInfo(0)
{
m_viewmatrix.Identity();
m_stereomode = RAS_STEREO_NOSTEREO;
}
@ -128,7 +130,6 @@ static void Myinit_gl_stuff(void)
}
glPolygonStipple(patc);
}
@ -144,6 +145,7 @@ bool RAS_OpenGLRasterizer::Init()
m_alphaback = 0.0;
glClearColor(m_redback,m_greenback,m_blueback,m_alphaback);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
@ -257,6 +259,7 @@ void RAS_OpenGLRasterizer::Exit()
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(m_redback, m_greenback, m_blueback, m_alphaback);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthMask (GL_TRUE);
@ -339,29 +342,9 @@ int RAS_OpenGLRasterizer::GetDrawingMode()
void RAS_OpenGLRasterizer::SetDepthMask(int depthmask)
void RAS_OpenGLRasterizer::SetDepthMask(DepthMask depthmask)
{
switch (depthmask)
{
case KX_DEPTHMASK_ENABLED:
{
glDepthMask(GL_TRUE);
//glDisable ( GL_ALPHA_TEST );
break;
};
case KX_DEPTHMASK_DISABLED:
{
glDepthMask(GL_FALSE);
//glAlphaFunc ( GL_GREATER, 0.0 ) ;
//glEnable ( GL_ALPHA_TEST ) ;
break;
};
default:
{
//printf("someone made a mistake, RAS_OpenGLRasterizer::SetDepthMask(int depthmask)\n");
exit(0);
}
}
glDepthMask(depthmask == KX_DEPTHMASK_DISABLED ? GL_FALSE : GL_TRUE);
}
@ -380,47 +363,67 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void)
void RAS_OpenGLRasterizer::EndFrame()
{
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
m_2DCanvas->EndFrame();
}
void RAS_OpenGLRasterizer::SetRenderArea()
{
// only above/below stereo method needs viewport adjustment
if(m_stereomode == RAS_STEREO_ABOVEBELOW)
switch (m_stereomode)
{
switch(m_curreye)
{
case RAS_STEREO_LEFTEYE:
// upper half of window
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(m_2DCanvas->GetHeight() -
int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
break;
case RAS_STEREO_RIGHTEYE:
// lower half of window
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(0);
m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
break;
}
}
else
{
// every available pixel
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(0);
m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
case RAS_STEREO_ABOVEBELOW:
switch(m_curreye)
{
case RAS_STEREO_LEFTEYE:
// upper half of window
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(m_2DCanvas->GetHeight() -
int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
break;
case RAS_STEREO_RIGHTEYE:
// lower half of window
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(0);
m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
break;
}
break;
case RAS_STEREO_SIDEBYSIDE:
switch (m_curreye)
{
case RAS_STEREO_LEFTEYE:
// Left half of window
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(0);
m_2DCanvas->GetDisplayArea().SetRight(m_2DCanvas->GetWidth()/2);
m_2DCanvas->GetDisplayArea().SetTop(m_2DCanvas->GetHeight());
break;
case RAS_STEREO_RIGHTEYE:
// Right half of window
m_2DCanvas->GetDisplayArea().SetLeft(m_2DCanvas->GetWidth()/2);
m_2DCanvas->GetDisplayArea().SetBottom(0);
m_2DCanvas->GetDisplayArea().SetRight(m_2DCanvas->GetWidth());
m_2DCanvas->GetDisplayArea().SetTop(m_2DCanvas->GetHeight());
break;
}
break;
default:
// every available pixel
m_2DCanvas->GetDisplayArea().SetLeft(0);
m_2DCanvas->GetDisplayArea().SetBottom(0);
m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
break;
}
}
void RAS_OpenGLRasterizer::SetStereoMode(const int stereomode)
void RAS_OpenGLRasterizer::SetStereoMode(const StereoMode stereomode)
{
m_stereomode = stereomode;
}
@ -436,14 +439,28 @@ bool RAS_OpenGLRasterizer::Stereo()
}
void RAS_OpenGLRasterizer::SetEye(int eye)
void RAS_OpenGLRasterizer::SetEye(StereoEye eye)
{
m_curreye = eye;
if(m_stereomode == RAS_STEREO_QUADBUFFERED) {
if(m_curreye == RAS_STEREO_LEFTEYE)
glDrawBuffer(GL_BACK_LEFT);
else
glDrawBuffer(GL_BACK_RIGHT);
switch (m_stereomode)
{
case RAS_STEREO_QUADBUFFERED:
glDrawBuffer(m_curreye == RAS_STEREO_LEFTEYE ? GL_BACK_LEFT : GL_BACK_RIGHT);
break;
case RAS_STEREO_ANAGLYPH:
if (m_curreye == RAS_STEREO_LEFTEYE)
{
glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE);
m_2DCanvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER);
glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
} else {
glAccum(GL_LOAD, 1.0);
glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
ClearDepthBuffer();
}
break;
default:
break;
}
}

@ -65,14 +65,12 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
float m_blueback;
float m_alphaback;
bool m_bEXT_compiled_vertex_array;
double m_time;
MT_CmMatrix4x4 m_viewmatrix;
MT_Point3 m_campos;
int m_stereomode;
int m_curreye;
StereoMode m_stereomode;
StereoEye m_curreye;
float m_eyeseparation;
float m_focallength;
int m_noOfScanlines;
@ -87,9 +85,7 @@ public:
RAS_OpenGLRasterizer(RAS_ICanvas* canv);
virtual ~RAS_OpenGLRasterizer();
enum
/*enum DrawType
{
KX_BOUNDINGBOX = 1,
KX_WIREFRAME,
@ -98,12 +94,12 @@ public:
KX_TEXTURED
};
enum
enum DepthMask
{
KX_DEPTHMASK_ENABLED =1,
KX_DEPTHMASK_DISABLED,
};
virtual void SetDepthMask(int depthmask);
};*/
virtual void SetDepthMask(DepthMask depthmask);
virtual void SetMaterial(const RAS_IPolyMaterial& mat);
virtual bool Init();
@ -114,9 +110,9 @@ public:
virtual void EndFrame();
virtual void SetRenderArea();
virtual void SetStereoMode(const int stereomode);
virtual void SetStereoMode(const StereoMode stereomode);
virtual bool Stereo();
virtual void SetEye(const int eye);
virtual void SetEye(const StereoEye eye);
virtual void SetEyeSeparation(const float eyeseparation);
virtual void SetFocalLength(const float focallength);

@ -212,14 +212,3 @@ void RAS_VAOpenGLRasterizer::EnableTextures(bool enable)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
bool RAS_VAOpenGLRasterizer::Stereo()
{
/*
if(m_stereomode == RAS_STEREO_NOSTEREO)
return false;
else
return true;
*/
return false;
}

@ -43,7 +43,6 @@ public:
virtual bool Init();
virtual void Exit();
virtual bool Stereo();
virtual void SetDrawingMode(int drawingmode);
virtual void IndexPrimitives( const vecVertexArray& vertexarrays,