// This function called by both OpenGL (GLUT) and DirectX void mouse_drag_func ( int x, int y ) { if ( guiMouseDrag ( x, y ) ) return; // event handling for nv2D GUIs int dx = x - last_x; int dy = y - last_y; float deltx = window_width / cam.getToPos().z; float delty = window_height / cam.getToPos().z; // Camera interaction int mode = 0; switch ( mode ) { case 0: if ( dragging == DRAG_LEFT ) { glide += Vector3DF( dx / cam.getToPos().z, 0, 0); cam.moveToPos ( 0, dy, 0 ); } else if ( dragging == DRAG_RIGHT ) { cam.moveToPos ( 0, 0, -dy*0.001 ); if ( cam.to_pos.z < 0.001 ) cam.to_pos.z = 0.001; } break; } last_x = x; last_y = y; }
// This function called by both OpenGL (GLUT) and DirectX void mouse_move_func ( int x, int y ) { mSelectID = (((x-window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10; if ( mSelectID < 0 ) mSelectID = 0; if ( mSelectID > mEvents.size()-1 ) mSelectID = mEvents.size() -1; mSelectBin = ((y-window_height/2.0) - cam.getToPos().y) / 25; if ( mSelectBin < 0 ) mSelectBin = 0; if ( mSelectBin >= NUM_BIN ) mSelectBin = NUM_BIN-1; }
void AppWindow::motion ( int x, int y ) { int dx = last_x - x; int dy = y - last_y; // Handle GUI interaction in nvGui by calling guiMouseDrag if ( guiMouseDrag ( x, y ) ) return; // Camera interaction Camera3D* cam = scene.getCamera (); switch ( cam_mode ) { case MODE_CAMERA: if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) { Vector4DF angs = cam->getAng(); angs.x += dx*.1; angs.y += dy*.1; cam->setOrbit ( angs, cam->getToPos(), cam->getOrbitDist(), cam->getOrbitDist() ); //cam->moveOrbit ( dx*.1, dy*.1, 0, 0 ); } else if ( dragging == NVPWindow::MOUSE_BUTTON_MIDDLE ) { cam->moveRelative ( dx*.1, dy*.1, 0 ); } else if ( dragging == NVPWindow::MOUSE_BUTTON_RIGHT ) { float orb = cam->getOrbitDist() + dy*0.1; cam->setOrbit ( cam->getAng(), cam->getToPos(), orb, orb); } break; case MODE_FOV: if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) { cam->setFov ( cam->getFov() + dy*.1 ); } break; case MODE_LIGHT: Light* light = scene.getLight(); if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) { light->moveOrbit ( dx*0.1, dy*0.1, 0, 0 ); } else if ( dragging == NVPWindow::MOUSE_BUTTON_RIGHT ) { light->moveOrbit ( 0, 0, dy*0.1, 0 ); } break; } last_x = x; last_y = y; }
// This function called by both OpenGL (GLUT) and DirectX void mouse_click_func ( int button, int state, int x, int y ) { cangs = cam.getAng(); ctp = cam.getToPos(); cdist = cam.getOrbitDist(); if ( state==GLUT_DOWN && guiMouseDown ( x, y ) ) return; // event handling for nv2D GUIs if( state == GLUT_DOWN ) { if ( button == GLUT_LEFT_BUTTON ) dragging = DRAG_LEFT; else if ( button == GLUT_RIGHT_BUTTON ) dragging = DRAG_RIGHT; last_x = x; last_y = y; } else if ( state==GLUT_UP ) { dragging = DRAG_OFF; } }
void AppWindow::mouse ( NVPWindow::MouseButton button, ButtonAction action, int mods, int x, int y ) { Vector3DF cangs, ctp; float cdist; Camera3D* cam = scene.getCamera (); cangs = cam->getAng(); ctp = cam->getToPos(); cdist = cam->getOrbitDist(); if ( action==NVPWindow::BUTTON_PRESS && guiMouseDown ( x, y ) ) return; if( action==NVPWindow::BUTTON_PRESS ) { dragging = (int) button; last_x = x; last_y = y; } else if ( action==NVPWindow::BUTTON_RELEASE ) { dragging = -1; } }
void drawOverlay () { Vector4DF clr; Matrix4F proj, view, model; proj.Scale ( 2.0/window_width, -2.0/window_height, 1 ); model.Translate ( cam.getToPos().x, cam.getToPos().y, 1 ); view.Scale ( cam.getToPos().z, 1, 1 ); view *= model; model.Identity (); //----- 2D Drawing (visualizer space) setview2D ( model.GetDataF(), view.GetDataF(), proj.GetDataF() ); setorder2D ( false, 1 ); updatestatic2D ( 0 ); // update model/view/proj matrices of each static draw layer updatestatic2D ( 1 ); updatestatic2D ( 2 ); updatestatic2D ( 3 ); // Selector Bar start2D (); drawRect ( mSelectID*10, 0, mSelectID*10+10, NUM_BIN*25, 1,1,1,1 ); // Same-State Highlights (yellow) int minE = (((0-window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10; int maxE = (((window_width - window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10; minE = ( minE < 0 ) ? 0 : minE; maxE = ( maxE >= mEvents.size() ) ? mEvents.size() : maxE; for (int n=0; n < mEvents.size(); n++ ) { if ( mEvents[n].bin_id[mSelectBin] == mEvents[mSelectID].bin_id[mSelectBin] && n > minE && n < maxE ) { drawRect ( n*10, mSelectBin*25, n*10+10, mSelectBin*25+24, 1,1,0,1 ); drawRect ( n*10+1, mSelectBin*25+1, n*10+9, mSelectBin*25+23, 1,1,0,1 ); } } end2D (); //----- 2D Drawing (screen space) setview2D ( window_width, window_height ); // change to screen space setorder2D ( true, -0.00001 ); start2D (); // dynamic draw int panel_width = 200; float xoff = window_width - panel_width; float yoff = cam.getToPos().y + (window_height/2); // Left panel - Bin Text char name[128]; char msg[1024]; int frame = mEvents[mSelectID].frame; frame = (frame < 0 || frame >= mFrames.size() ) ? 0 : frame; Frame& f = mFrames[ frame ]; drawFill ( 0, yoff, +panel_width, yoff + NUM_BIN*25+250, 0.15,0.15,0.2,0.75 ); drawText ( 10, yoff-85, "Frame #:", 1,1,1,1 ); drawText ( 10, yoff-70, "Frame Draws:", 1,1,1,1 ); drawText ( 10, yoff-55, "Frame Prims:", 1,1,1,1 ); drawText ( 10, yoff-40, "Frame Transfer:", 1,1,1,1 ); drawText ( 10, yoff-20, "Frame States:", 1,1,1,1 ); sprintf ( msg, "%d", frame ); drawText ( 100, yoff - 85, msg, 1,1,1,1 ); sprintf ( msg, "%d", f.totalDraw ); drawText ( 100, yoff - 70, msg, 1,1,1,1 ); sprintf ( msg, "%d", f.totalPrim ); drawText ( 100, yoff - 55, msg, 1,1,1,1 ); sprintf ( msg, "%d bytes", f.totalTransfer ); drawText ( 100, yoff - 40, msg, 1,1,1,1 ); setText ( 0.8, 0 ); drawText ( 100, yoff - 20, "Modify", 1,0,0,1 ); drawText ( 125, yoff - 10, "Switch", 1,0.5,0,1 ); drawText ( 150, yoff - 20, "Reuse", 0,1,0,1 ); drawText ( 175, yoff - 10, "Unique", 1,1,1,1 ); drawTri ( 100, yoff-10, 100+10, yoff-10, 100, yoff, 1, 0,0, 1); drawTri ( 125, yoff-10, 125+10, yoff-10, 125, yoff, 1,.5,0, 1); drawTri ( 150, yoff-10, 150+10, yoff-10, 150, yoff, 0, 1,0, 1); setText ( 1.0, -0.5 ); for (int b=0; b < NUM_BIN; b++ ) { strncpy ( name, binNames[b].c_str(), 128 ); drawText ( 8, yoff + b*25+12, name, 1,1,1,1 ); clr.x = float(f.binChange[b]) / f.totalDraw; if ( clr.x > 1 ) clr.x = 1; sprintf ( msg, "%d", f.binChange[b] ); drawText ( 100, yoff + b*25+12-2, msg, clr.x*0.7+0.3, 0,0,1 ); clr.x = float(f.binSwitch[b]) / f.totalDraw; if ( clr.x > 1 ) clr.x= 1; sprintf ( msg, "%d", f.binSwitch[b] ); drawText ( 125, yoff + b*25+12+2, msg, clr.x*0.7+0.3,clr.x*.4+0.2,0,1 ); clr.x = float(f.binReuse[b]) / f.totalDraw; if ( clr.x > 1 ) clr.x= 1; sprintf ( msg, "%d", f.binReuse[b] ); drawText ( 150, yoff + b*25+12-2, msg, 0, clr.x*0.7+0.3, 0,1 ); sprintf ( msg, "%d", f.binUnique[b] ); drawText ( 175, yoff + b*25+12+2, msg, .7, .7, .7,1 ); } int ys = NUM_BIN*25; float ypos; sprintf ( msg, "%d", mMaxPrim/4 ); drawLine ( 0, yoff + ys+25, 200, yoff+ys+25, .6, .6, .6, 1); drawText ( 10, yoff+ys+25+15, msg, .8,.8,.8,1 ); drawText ( 10, yoff + ys+80, "# Prims", 1, 1, 1, 1 ); drawText ( 10, yoff+ys+125, "0", .8,.8,.8,1 ); drawLine ( 0, yoff + ys+125, 200, yoff+ys+125, .6, .6, .6, 1); ypos = mEvents[ mSelectID ].bin_id[ BIN_DRAW ] * 400 / mMaxPrim; // prim count clr = getClr ( mEvents[ mSelectID ].bin_id[9] + 9*16384 ); if ( ypos > 100 ) ypos = 100; sprintf ( msg, "%d", mEvents[ mSelectID ].bin_id[BIN_DRAW] ); drawLine ( 150, yoff+ys+(125-ypos), 200, yoff+ys+(125-ypos), clr.x,clr.y,clr.z,1 ); drawText ( 150, yoff+ys+(125-ypos), msg, clr.x,clr.y,clr.z,1 ); sprintf ( msg, "%d", mMaxSize ); drawLine ( 0, yoff + ys+150, 200, yoff+ys+150, .6, .6, .6, 1); drawText ( 10, yoff+ys+150+15, msg, .8,.8,.8,1 ); drawText ( 10, yoff + ys+200, "Transfer (bytes)" , 1, 1, 1, 1); drawText ( 10, yoff+ys+250, "0", .8,.8,.8,1 ); drawLine ( 0, yoff + ys+250, 200, yoff+ys+250, .6, .6, .6, 1); ypos = mEvents[ mSelectID ].bin_size [ BIN_SIZE ] * 100 / mMaxSize; // prim count if ( ypos > 100 ) ypos = 100; sprintf ( msg, "%d", mEvents[ mSelectID ].bin_size [BIN_SIZE] ); drawLine ( 150, yoff+ys+(250-ypos), 200, yoff+ys+(250-ypos), 1,1,1,1 ); drawText ( 150, yoff+ys+(250-ypos), msg, 1,1,1,1 ); // Right panel - Call Text drawFill ( xoff, yoff, xoff + panel_width, yoff + NUM_BIN*25+250, 0.15,0.15,0.2,0.75 ); int cid; glColor3f ( 1, 1, 1); for (int c = 0; c < mEvents[ mSelectID ].call_num; c++ ) { cid = mEvents[ mSelectID ].call_start + c; clr = getClr ( mCalls[cid].val_id + mCalls[cid].bin_id*16384 ); clr.w = 1; drawFill ( xoff+100, yoff + c*15, xoff+125, yoff+c*15+13, clr.x, clr.y, clr.z, clr.w ); sprintf ( msg, "%s", mCalls[cid].name.c_str() ); drawText ( xoff+5, yoff + c*15+15, msg, 1,1,1,1 ); sprintf ( msg, "%02d %d %d", mCalls[cid].bin_id, mCalls[cid].size, mCalls[cid].val_id ); drawText ( xoff+130, yoff + c*15+15, msg, 1,1,1,1 ); } end2D (); #ifdef USE_DX g_pContext->OMSetDepthStencilState( g_pDepthStencilState, 1 ); #endif }
void drawMatrix () { Vector3DF id_clr; float ypos, yposl; int b, num = (int) mEvents.size(); Matrix4F proj, view, model; proj.Scale ( 2.0/window_width, -2.0/window_height, 1 ); model.Translate ( cam.getToPos().x, cam.getToPos().y, 1 ); view.Scale ( cam.getToPos().z, 1, 1 ); view *= model; model.Identity (); //----- 2D Drawing (visualizer space) setview2D ( model.GetDataF(), view.GetDataF(), proj.GetDataF() ); setorder2D ( false, 1 ); // Event ID bars static2D (); int fl = -1; char msg[100]; for (int n=0; n < num; n++ ) { if ( mEvents[n].frame != fl ) { sprintf ( msg, "frame %d", mEvents[n].frame ); drawText ( n*10, -2, msg, 1,1,1,1 ); } for (b=0; b < NUM_BIN; b++) { if ( mEvents[n].bin_id[b] == -1 ) { id_clr.Set ( 1, 1, 1 ); } else if ( mEvents[n].bin_change[b] == 0 ) { id_clr.Set ( .2, .2, .2 ); } else { id_clr = getClr ( mEvents[n].bin_id[b] + b*16384 ); } drawFill ( n*10.0, b*25, n*10+10.0, b*25+24, id_clr.x, id_clr.y, id_clr.z, 1 ); } fl = mEvents[n].frame; } end2D (); // Change State bars static2D (); for (int n=0; n < num; n++ ) { for (b=0; b < NUM_BIN; b++) { if ( mEvents[n].bin_id[b] != -1 ) { switch ( mEvents[n].bin_change[b] ) { case BIN_NOTUSED: id_clr.Set ( .2, .2, .2 ); break; case BIN_CREATE: id_clr.Set ( 1, 0, 0 ); break; case BIN_CHANGE: id_clr.Set ( 1, 0, 0 ); break; case BIN_SWITCH: id_clr.Set ( 1, .5, 0 ); break; case BIN_REUSE: id_clr.Set ( 0, 1, 0 ); break; }; drawTri ( n*10, b*25, n*10+10, b*25, n*10, b*25+10, id_clr.x, id_clr.y, id_clr.z, 1 ); } } } end2D (); int ys = NUM_BIN*25; // Prim count bars static2D(); b = BIN_DRAW; for (int n=0; n < num; n++ ) { id_clr = getClr ( mEvents[n].bin_id[9] + 9*16384 ); ypos = mEvents[n].bin_id[ b ] * 400 / mMaxPrim; // prim count if ( ypos > 100 ) ypos = 100; drawFill ( n*10, ys+(125-ypos), n*10+10, ys+125, id_clr.x, id_clr.y, id_clr.z, 1 ); } end2D (); // Mem transfer line static2D(); yposl = 0; b = BIN_SIZE; for (int n=0; n < num; n++ ) { id_clr.Set(1,1,1); ypos = mEvents[n].bin_size[ b ] * 100 / mMaxSize; // size (bytes) if ( ypos > 100 ) ypos = 100; drawLine ( n*10+5, ys+(250-ypos), n*10-5, ys+(250-yposl), 1, 1, 1, 1 ); yposl = ypos; } drawLine ( 5, ys+250, num*10-5, ys+250, .5, .5, .5, 1 ); end2D (); }