void G2DTestSystemDriver::DrawLinePerf () { SetFont (fontItalic); WriteCentered (0,-16*4, white, -1, "LINE SLOPE AND PERFORMANCE TEST"); int w2 = myG2D->GetWidth () / 2; int colors [4] = { red, green, blue, yellow }; int a; for (a = 0; a < 360; a += 5) { float angle = (a * TWO_PI) / 360.0; float x = w2 + 80 * cos (angle); float y = 100 + 80 * sin (angle); myG2D->DrawLine (w2, 100, x, y, colors [a & 3]); } // Compute the size for the random lines box int sx = 0; int sw = myG2D->GetWidth (); int sy = myG2D->GetHeight () / 2; int sh = sy; myG2D->DrawBox (sx, sy + 16, sw, sh - 16, dsteel); SetFont (fontLarge); WriteCentered (0,-16*2, gray, -1, "Above this text you should see a uniformly hashed circle,"); WriteCentered (0,-16*1, gray, -1, "while below you should see some random lines, and the"); WriteCentered (0, 16*0, gray, -1, "measured line drawing performance in pixels per second."); // Test line drawing performance for 1/4 seconds sx += 20; sw -= 40; sy += 30; sh -= 40; csRandomGen rng (csGetTicks ()); csTicks start_time = csGetTicks (), delta_time; float pix_count = 0; do { for (a = 0; a < 5000; a++) { float x1 = sx + rng.Get () * sw; float y1 = sy + rng.Get () * sh; float x2 = sx + rng.Get () * sw; float y2 = sy + rng.Get () * sh; myG2D->DrawLine (x1, y1, x2, y2, colors [rng.Get (4)]); x2 = csQint (x2 - x1); y2 = csQint (y2 - y1); pix_count += csQsqrt (x2 * x2 + y2 * y2); } myG2D->PerformExtension ("flush"); delta_time = csGetTicks () - start_time; } while (delta_time < 500); pix_count = pix_count * (1000.0 / delta_time); WriteCentered (0, 16*1, green, black, " Performance: %20.1f pixels/second ", pix_count); }
bool WalkTestViews::UnsplitView () { if (split != -1) { csBox2 bbox1, bbox2; BoundingBoxForView(views[0], &bbox1); BoundingBoxForView(views[1], &bbox2); int width = csQint(bbox2.MaxX() - bbox1.MinX()); int height = csQint(bbox1.MaxY() - bbox1.MinY()); view->GetCamera()->SetViewportSize (width, height); view->SetRectangle((int)bbox1.MinX(), (int)bbox1.MinY(), width, height); split = -1; walktest->Report(CS_REPORTER_SEVERITY_NOTIFY, "Unsplitting view"); return true; } return false; }
bool WalkTestViews::SplitView () { if (split == -1) { csBox2 bbox; BoundingBoxForView (view, &bbox); int width = csQint(bbox.MaxX() - bbox.MinX()); int height = csQint(bbox.MaxY() - bbox.MinY()); views[0]->SetRectangle((int)bbox.MinX(), (int)bbox.MinY(), width / 2, height); views[0]->GetCamera()->SetViewportSize (width, height); views[1]->GetCamera()->SetViewportSize (width, height); views[1]->SetRectangle((int)bbox.MinX() + (width / 2), (int)bbox.MinY(), width / 2, height); split = (view == views[0]) ? 0 : 1; walktest->Report(CS_REPORTER_SEVERITY_NOTIFY, "Splitting to 2 views"); return true; } return false; }
bool csNullGraphics3D::Open () { csRef<iPluginManager> plugin_mgr = csQueryRegistry<iPluginManager> (object_reg); if (!plugin_mgr) return false; if (!G2D->Open ()) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.graphics3d.null", "Error opening Graphics2D context"); w = h = -1; return false; } SetDimensions (G2D->GetWidth (), G2D->GetHeight()); SetPerspectiveAspect (G2D->GetHeight ()); SetPerspectiveCenter (G2D->GetWidth ()/2, G2D->GetHeight ()/2); shadermgr = csQueryRegistryOrLoad<iShaderManager> (object_reg, "crystalspace.graphics3d.shadermanager"); if (!shadermgr) return false; string_vertices = strings->Request ("vertices"); string_texture_coordinates = strings->Request ("texture coordinates"); string_normals = strings->Request ("normals"); string_colors = strings->Request ("colors"); string_indices = strings->Request ("indices"); // @@@ These shouldn't be here, I guess. #define CS_FOGTABLE_SIZE 64 // Each texel in the fog table holds the fog alpha value at a certain // (distance*density). The median distance parameter determines the // (distance*density) value represented by the texel at the center of // the fog table. The fog calculation is: // alpha = 1.0 - exp( -(density*distance) / CS_FOGTABLE_MEDIANDISTANCE) #define CS_FOGTABLE_MEDIANDISTANCE 10.0f #define CS_FOGTABLE_MAXDISTANCE (CS_FOGTABLE_MEDIANDISTANCE * 2.0f) #define CS_FOGTABLE_DISTANCESCALE (1.0f / CS_FOGTABLE_MAXDISTANCE) unsigned char *transientfogdata = new unsigned char[CS_FOGTABLE_SIZE * 4]; for (unsigned int fogindex = 0; fogindex < CS_FOGTABLE_SIZE; fogindex++) { transientfogdata[fogindex * 4 + 0] = (unsigned char) 255; transientfogdata[fogindex * 4 + 1] = (unsigned char) 255; transientfogdata[fogindex * 4 + 2] = (unsigned char) 255; double fogalpha = (256 * (1.0 - exp (-float (fogindex) * CS_FOGTABLE_MAXDISTANCE / CS_FOGTABLE_SIZE))); transientfogdata[fogindex * 4 + 3] = (unsigned char) fogalpha; } transientfogdata[(CS_FOGTABLE_SIZE - 1) * 4 + 3] = 0; csRef<iImage> img = csPtr<iImage> (new csImageMemory ( CS_FOGTABLE_SIZE, 1, transientfogdata, true, CS_IMGFMT_TRUECOLOR | CS_IMGFMT_ALPHA)); csRef<iTextureHandle> fogtex = txtmgr->RegisterTexture ( img, CS_TEXTURE_3D | CS_TEXTURE_CLAMP | CS_TEXTURE_NOMIPMAPS); csRef<csShaderVariable> fogvar = csPtr<csShaderVariable>( new csShaderVariable( strings->Request ("standardtex fog"))); fogvar->SetValue (fogtex); if (shadermgr) shadermgr->AddVariable(fogvar); { const int normalizeCubeSize = config->GetInt ( "Video.Null3d.NormalizeCubeSize", 128); csRef<csShaderVariable> normvar = csPtr<csShaderVariable> (new csShaderVariable ( strings->Request ("standardtex normalization map"))); csRef<iShaderVariableAccessor> normCube; normCube.AttachNew (new csNormalizationCubeAccessor (txtmgr, normalizeCubeSize)); normvar->SetAccessor (normCube); shadermgr->AddVariable(normvar); } #define CS_ATTTABLE_SIZE 128 #define CS_HALF_ATTTABLE_SIZE ((float)CS_ATTTABLE_SIZE/2.0f) csRGBpixel *attenuationdata = new csRGBpixel[CS_ATTTABLE_SIZE * CS_ATTTABLE_SIZE * 4]; csRGBpixel* data = attenuationdata; for (int y=0; y < CS_ATTTABLE_SIZE; y++) { for (int x=0; x < CS_ATTTABLE_SIZE; x++) { float yv = 3.0f * ((y + 0.5f)/CS_HALF_ATTTABLE_SIZE - 1.0f); float xv = 3.0f * ((x + 0.5f)/CS_HALF_ATTTABLE_SIZE - 1.0f); float i = exp (-0.7 * (xv*xv + yv*yv)); unsigned char v = i>1.0f ? 255 : csQint (i*255.99f); (data++)->Set (v, v, v, v); } } img = csPtr<iImage> (new csImageMemory ( CS_ATTTABLE_SIZE, CS_ATTTABLE_SIZE, attenuationdata, true, CS_IMGFMT_TRUECOLOR | CS_IMGFMT_ALPHA)); csRef<iTextureHandle> atttex = txtmgr->RegisterTexture ( img, CS_TEXTURE_3D | CS_TEXTURE_CLAMP | CS_TEXTURE_NOMIPMAPS); csRef<csShaderVariable> attvar = csPtr<csShaderVariable>( new csShaderVariable( strings->Request ("standardtex attenuation"))); attvar->SetValue (atttex); if (shadermgr) shadermgr->AddVariable(attvar); return true; }