Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/testbed/indirect.cxx

Go to the documentation of this file.
00001 // Filename: indirect.cxx
00002 // Created by:  cary (25Mar99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include <eventHandler.h>
00020 #include <texture.h>
00021 #include <graphicsWindow.h>
00022 #include <graphicsStateGuardian.h>
00023 #include <pixelBuffer.h>
00024 #include <dconfig.h>
00025 #include <chancfg.h>
00026 #include <string>
00027 
00028 Configure(indirect);
00029 
00030 extern GraphicsWindow* win;
00031 extern std::string chan_config;
00032 
00033 extern int framework_main(int argc, char *argv[]);
00034 extern void (*extra_display_func)();
00035 extern void (*define_keys)(EventHandler&);
00036 extern void (*first_init)();
00037 
00038 Texture* t = (Texture*)0L;
00039 PixelBuffer* pb = (PixelBuffer *)0L;
00040 DisplayRegion* dr1 = (DisplayRegion*)0L;
00041 DisplayRegion* dr2 = (DisplayRegion*)0L;
00042 
00043 bool use_canned_texture = indirect.GetBool("canned-texture", false);
00044 bool use_texture = indirect.GetBool("use-texture", true);
00045 bool full_region = indirect.GetBool("full-region", true);
00046 bool side_by_side = indirect.GetBool("side-by-side", true);
00047 bool right_to_left = indirect.GetBool("right-to-left", true);
00048 
00049 int logs[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 0 };
00050 
00051 int binary_log_cap(int x) {
00052   int i = 0;
00053   for (; (x > logs[i])&&(logs[i] != 0); ++i);
00054   if (logs[i] == 0)
00055     return 4096;
00056   return logs[i];
00057 }
00058 
00059 void indirect_display_func( void ) {
00060   GraphicsStateGuardian* g = win->get_gsg();
00061   const RenderBuffer& rf = g->get_render_buffer(RenderBuffer::T_front);
00062   const RenderBuffer& rb = g->get_render_buffer(RenderBuffer::T_back);
00063 
00064   if (use_texture) {
00065     if (t == (Texture*)0L) {
00066       t = new Texture;
00067       if (use_canned_texture)
00068         t->read( "smiley.rgba" );
00069       else if (full_region) {
00070         int a, b, w, h;
00071         dr1->get_region_pixels(a, b, w, h);
00072         t->_pbuffer->set_xsize(binary_log_cap(w));
00073         t->_pbuffer->set_ysize(binary_log_cap(h));
00074       } else {
00075         t->_pbuffer->set_xsize( 512 );
00076         t->_pbuffer->set_ysize( 512 );
00077       }
00078     }
00079     if (side_by_side) {
00080       if (right_to_left)
00081         g->prepare_display_region(dr2);
00082       else
00083         g->prepare_display_region(dr1);
00084     }
00085     if (!use_canned_texture) {
00086       if (full_region) {
00087         if (side_by_side) {
00088           if (right_to_left)
00089             t->copy_from( rb, dr2 );
00090           else
00091             t->copy_from( rb, dr1 );
00092         } else
00093           t->copy_from( rb, dr1 );
00094       } else
00095         t->copy_from( rb );
00096     }
00097     if (side_by_side) {
00098       if (right_to_left)
00099         g->prepare_display_region(dr1);
00100       else
00101         g->prepare_display_region(dr2);
00102     }
00103     if (full_region) {
00104       if (side_by_side) {
00105         if (right_to_left)
00106           t->draw_to( rf, dr1 );
00107         else
00108           t->draw_to( rf, dr2 );
00109       } else
00110         t->draw_to( rf, dr1 );
00111     } else
00112       t->draw_to( rf );
00113   } else {
00114     if (pb == (PixelBuffer*)0L) {
00115       pb = new PixelBuffer;
00116       if (use_canned_texture)
00117         pb->read( "smiley.rgba" );
00118       else if (full_region) {
00119         int a, b, w, h;
00120         dr1->get_region_pixels(a, b, w, h);
00121         w = binary_log_cap(w);
00122         h = binary_log_cap(h);
00123         pb->set_xsize(w);
00124         pb->set_ysize(h);
00125         pb->_image = PTA_uchar(w * h * 3);
00126       } else {
00127         pb->set_xsize(512);
00128         pb->set_ysize(512);
00129         pb->_image = PTA_uchar(512 * 512 * 3);
00130       }
00131     }
00132     if (side_by_side) {
00133       if (right_to_left)
00134         g->prepare_display_region(dr2);
00135       else
00136         g->prepare_display_region(dr1);
00137     }
00138     if (!use_canned_texture)
00139       pb->copy_from( rf );
00140     if (side_by_side) {
00141       if (right_to_left)
00142         g->prepare_display_region(dr1);
00143       else
00144         g->prepare_display_region(dr2);
00145     }
00146     pb->draw_to( rf );
00147   }
00148 }
00149 
00150 void indirect_init(void) {
00151   if (side_by_side)
00152     chan_config = "two-frame";
00153 }
00154 
00155 void indirect_keys(EventHandler&) {
00156   DRList::iterator i = win->getDRBegin();
00157   dr1 = *i;
00158   if (side_by_side) {
00159     ++i;
00160     dr2 = *i;
00161     if (right_to_left)
00162       dr1->set_active(false);
00163     else
00164       dr2->set_active(false);
00165   }
00166 }
00167 
00168 int main(int argc, char *argv[]) {
00169   define_keys = &indirect_keys;
00170   extra_display_func = &indirect_display_func;
00171   first_init = &indirect_init;
00172   return framework_main(argc, argv);
00173 }

Generated on Fri May 2 00:44:08 2003 for Panda by doxygen1.3