Mercurial > hg > Members > kono > Cerium
diff TaskManager/Test/simple_render/viewer.cpp @ 48:70a0ac46133e
*** empty log message ***
author | gongo |
---|---|
date | Fri, 15 Feb 2008 16:09:42 +0900 |
parents | aa11038dbdc1 |
children | 64ef030deb22 |
line wrap: on
line diff
--- a/TaskManager/Test/simple_render/viewer.cpp Fri Feb 15 13:09:58 2008 +0900 +++ b/TaskManager/Test/simple_render/viewer.cpp Fri Feb 15 16:09:42 2008 +0900 @@ -2,6 +2,7 @@ #include <SDL.h> #include <SDL_opengl.h> #include <math.h> +#include <unistd.h> #include "polygon.h" //#include "demonstration.h" //#include "scene.h" @@ -14,9 +15,9 @@ #define blueMask 0x000000ff #define alphaMask 0 -extern int create_sgp(SceneGraphPack *sgp, Polygon *sg); +extern int create_sgp(Polygon *sg, SceneGraphPack *sgp); extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp); -extern int create_pp(PolygonPack *pp, SceneGraphPack *sgp); +extern int create_pp(SceneGraphPack *sgp, PolygonPack *pp); Viewer::Viewer(int b, int w, int h) { @@ -34,93 +35,9 @@ exit( 1 ); } screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE ); - - //manager = new TaskManager(1); - //manager->init(); } -void Viewer::init() -{ - if(SDL_Init( SDL_INIT_VIDEO ) < 0) - { - cout << "Couldn't initialize SDL:" << SDL_GetError() << endl; - exit(1); - } - - /* See if we should detect the display depth */ - if(bpp == 0) - { - if (SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8) - { - bpp = 8; - } - else - { - bpp = 16; /* More doesn't seem to work */ - } - } - - //video_flags = SDL_OPENGL; - video_flags = SDL_HWSURFACE; - - /* Initialize the display */ - switch (bpp) - { - case 8: - rgb_size[0] = 3; - rgb_size[1] = 3; - rgb_size[2] = 2; - break; - case 15: - case 16: - rgb_size[0] = 5; - rgb_size[1] = 5; - rgb_size[2] = 5; - break; - default: - rgb_size[0] = 8; - rgb_size[1] = 8; - rgb_size[2] = 8; - break; - } - - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0); - - screen = SDL_SetVideoMode(width, height, bpp, video_flags); - - if(screen == NULL) - { - cout << "Couldn't set GL mode: " << SDL_GetError() << endl; - SDL_Quit(); - exit(1); - } - - SDL_WM_SetCaption("SDL GL test", "testgl"); - - glViewport(0, 0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(-width/10, width/10, -height/10, height/10, -40.0, 400.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glEnable(GL_DEPTH_TEST); - - glDepthFunc(GL_LESS); - - glShadeModel(GL_SMOOTH); -} - int Viewer::get_ticks() { int time; @@ -328,14 +245,17 @@ PolygonPack *pp; }; -#if 0 +struct run_arg_t *arg; + void Viewer::run_init() { - struct run_arg_t *arg = new run_arg_t; + arg = new run_arg_t; HTaskPtr task; int fd; + fprintf(stderr, " ** %s **\n", __FUNCTION__); + arg->start_time = get_ticks(); arg->pf = screen->format; arg->background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); @@ -343,7 +263,7 @@ arg->p->set_data("cube.xml"); arg->p->viewer = this; arg->sgp = new SceneGraphPack; - create_sgp(arg->sgp, arg->p); + create_sgp(arg->p, arg->sgp); arg->pp = new PolygonPack; pixels = new Uint32[width*height]; @@ -355,14 +275,12 @@ blueMask, alphaMask); fd = manager->open("ViewerRunLoop"); - task = manager->create_task(fd, sizeof(struct run_arg_t), - (unsigned int)arg, 0, NULL); - manager->spawn_task(task_create_pp); - //manager->run(); + task = manager->create_task(fd, 0, 0, 0, NULL); + manager->spawn_task(task); } void -Viewer::run_loop(struct run_arg_t *arg) +Viewer::run_loop(void) { HTaskPtr task_update_sgp = NULL; HTaskPtr task_create_pp = NULL; @@ -371,53 +289,77 @@ int fd_create_pp; int fd_finish; + HTaskPtr task; + int fd; + + fprintf(stderr, " ** %s **\n", __FUNCTION__); + + if (quit_check()) { arg->this_time = get_ticks(); fd_finish = manager->open("ViewerRunFinish"); - task_finish = manager->create(fd_finish, sizeof(struct run_arg_t), - (unsigned int)arg, 0, NULL); + task_finish = manager->create_task(fd_finish, 0, 0, 0, NULL); manager->spawn_task(task_finish); return; } clean_pixels(); - this->zRow_init(); + zRow_init(); graph_line(); fd_update_sgp = manager->open("UpdateSGP"); fd_create_pp = manager->open("CreatePP"); - task_update_sgp = - manager->create_task(fd_update_sgp, - sizeof(SceneGraphPack), - (unsigned int)arg->sgp, - (unsigned int)arg->sgp, - NULL); - task_create_pp = - manager->create_task(fd_create_pp, - sizeof(SceneGraphPack), - (unsigned int)arg->sgp, - (unsigned int)arg->pp, - NULL); + fd = manager->open("ViewerRunDraw"); + task_update_sgp = manager->create_task(fd_update_sgp, + sizeof(SceneGraphPack), + (unsigned int)arg->sgp, + (unsigned int)arg->sgp, + NULL); + task_create_pp = manager->create_task(fd_create_pp, + sizeof(SceneGraphPack), + (unsigned int)arg->sgp, + (unsigned int)arg->pp, + NULL); + task = manager->create_task(fd, 0, 0, 0, NULL); + + manager->set_task_depend(task_update_sgp, task); + manager->set_task_depend(task_create_pp, task); manager->spawn_task(task_update_sgp); manager->spawn_task(task_create_pp); - manager->run(); + manager->spawn_task(task); +} - arg->p->draw(pp); // test draw of PolygonPack +void +Viewer::run_draw(void) +{ + HTaskPtr task; + int fd; + + + fprintf(stderr, " ** %s **\n", __FUNCTION__); + + arg->p->draw(arg->pp); // test draw of PolygonPack SDL_BlitSurface(arg->bitmap, NULL, screen, NULL); - SDL_UpdateRect(screen, 0, 0, 0, 0); + SDL_UpdateRect(screen, 0, 0, 0, 0); //swap_buffers(); arg->frames++; + + fd = manager->open("ViewerRunLoop"); + task = manager->create_task(fd, 0, 0, 0, NULL); + manager->spawn_task(task); } void -Viewer::run_finish(struct run_arg_t *arg) +Viewer::run_finish(void) { + fprintf(stderr, " ** %s **\n", __FUNCTION__); + if (arg->this_time != arg->start_time) { - cout<< ((float)arg->frames/(this_time-start_time))*1000.0 << " FPS\n"; + cout<< ((float)arg->frames/(arg->this_time-arg->start_time))*1000.0 << " FPS\n"; } SDL_FreeSurface(arg->bitmap); @@ -430,8 +372,8 @@ delete arg; } -#endif +#if 0 void Viewer::run() { int frames = 0; @@ -463,7 +405,7 @@ //p->screen = screen; SceneGraphPack *sgp = new SceneGraphPack; - create_sgp(sgp,p); + create_sgp(p, sgp); PolygonPack *pp = new PolygonPack; @@ -567,6 +509,9 @@ ++frames; } } +#else +void Viewer::run() {} +#endif void Viewer::zRow_init()