// Get the time elapsed since the Start()
u64 Timer::GetTimeElapsed()
{
// If we have not started yet, return 1 (because then I don't
// have to change the FPS calculation in CoreRerecording.cpp .
if (m_StartTime == 0) return 1;
// Return the final timer time if the timer is stopped
if (!m_Running) return (m_LastTime - m_StartTime);
return (GetTimeMs() - m_StartTime);
}
开发者ID:Ced2911,项目名称:ppsspp,代码行数:12,代码来源:Timer.cpp
示例6: IB_Animate_Sleep
static void
IB_Animate_Sleep(unsigned int t0, double a)
{
unsigned int t;
double dt;
t = GetTimeMs() - t0;
dt = 1e-3 * (t - a * IB_ANIM_TIME);
dt = 1e-3 * IB_ANIM_STEP - dt;
if (dt > 0)
usleep((unsigned long)(1e6 * dt));
}
// Get the formatted time elapsed since the Start()
std::string Timer::GetTimeElapsedFormatted() const
{
// If we have not started yet, return zero
if (m_StartTime == 0)
return "00:00:00:000";
// The number of milliseconds since the start.
// Use a different value if the timer is stopped.
u64 Milliseconds;
if (m_Running)
Milliseconds = GetTimeMs() - m_StartTime;
else
Milliseconds = m_LastTime - m_StartTime;
// Seconds
u32 Seconds = (u32)(Milliseconds / 1000);
// Minutes
u32 Minutes = Seconds / 60;
// Hours
u32 Hours = Minutes / 60;
std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i",
Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000);
return TmpStr;
}
//.........这里部分代码省略.........
glutCreateWindow("SRTP Middle Check");
glutCreateMenu(NULL);
glewInit();
initTextureList();
for (int i = 0; i < textpoint; i++){
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, textureObjects[i]);
}
glActiveTexture(GL_TEXTURE0);
sprintf(path, "%sCook-Torrorence", root);
programs[2] = setupShaders(path);
// Set GLUT callbacks
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
// Initialize AntTweakBar
TwInit(TW_OPENGL, NULL);
// Set GLUT event callbacks
// - Directly redirect GLUT mouse button events to AntTweakBar
glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
// - Directly redirect GLUT mouse motion events to AntTweakBar
glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
// - Directly redirect GLUT key events to AntTweakBar
glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
// - Directly redirect GLUT special key events to AntTweakBar
glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
// - Send 'glutGetModifers' function pointer to AntTweakBar;
// required because the GLUT key event functions do not report key modifiers states.
TwGLUTModifiersFunc(glutGetModifiers);
// Create some 3D objects (stored in display lists)
glNewList(SHAPE_TEAPOT, GL_COMPILE);
glutSolidTeapot(1.0);
glEndList();
glNewList(SHAPE_TORUS, GL_COMPILE);
//glutSolidTorus(0.3, 1.0, 16, 32);
glutSolidSphere(0.75f, 20, 20);
glEndList();
glNewList(SHAPE_DRAGON, GL_COMPILE);
drawBunny("dragon");
glEndList();
glNewList(SHAPE_SKULL, GL_COMPILE);
drawBunny("skull");
glEndList();
glNewList(SHAPE_GARGO, GL_COMPILE);
drawBunny("Gargoyle_ABF");
glEndList();
glNewList(DRAW_EN, GL_COMPILE);
drawEnv(30);
glEndList();
// Create a tweak bar
bar = TwNewBar("TweakBar");
TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
TwDefine(" TweakBar size='250 540' color='96 216 224' "); // change default tweak bar size and color
TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=7.5 step=0.01 ");
TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true ");
TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space ");
TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &lightDirection, " label='Light direction' opened=true ");
TwAddVarRW(bar, "LightDist", TW_TYPE_FLOAT, &lightDistance, " label='Light distance' ");
TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &lightAmbient, "");
TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &lightDiffuse, "");
TwAddVarRW(bar, "Rf", TW_TYPE_COLOR3F, &rf, "");
TwAddVarRW(bar, "Roughness", TW_TYPE_FLOAT, &roughness, " label='Roughness' min=0.01 max=1.99 step=0.01 keyIncr='+' keyDecr='-' ");
{
TwEnumVal shaders[NUM_SHADERS] = { { SHADER_PHONG, "Phong" }, { SHADER_COOKTORRORENCE, "CookTorrorence" } };
TwType shaderType = TwDefineEnum("ShaderType", shaders, NUM_SHADERS);
TwAddVarRW(bar, "Shader", shaderType, ¤tShader, "");
}
// Add the enum variable 'g_CurrentShape' to 'bar'
// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
{
// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
TwEnumVal shapeEV[NUM_SHAPES] = { { SHAPE_TEAPOT, "Teapot" }, { SHAPE_TORUS, "Sphere" }, { SHAPE_DRAGON, "Dragon" }, { SHAPE_SKULL, "Skull" }, { SHAPE_GARGO, "Gargo" } };
// Create a type for the enum shapeEV
TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, "");
}
// Store time
g_RotateTime = GetTimeMs();
// Init rotation
SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);
atexit(Terminate); // Called after glutMainLoop ends
// Call the GLUT main loop
glutMainLoop();
return 0;
}
开发者ID:Sylvanuszhy,项目名称:IBL,代码行数:101,代码来源:main.cpp
示例14: main
int main() {
// Create the variables for the time measure
int starttime, stoptime;
//Get initial time
starttime = GetTimeMs();
// This code executes on the OpenCL host
// Host data
float *A=NULL; // Input array
float *B=NULL; // Input array
float *C=NULL; // Output array
// Elements in each array
const int elements=2048;
// Compute the size of the data
size_t datasize=sizeof(int)*elements;
// Allocate space for input/output data
A=(float*)malloc(datasize);
B=(float*)malloc(datasize);
C=(float*)malloc(datasize);
// Initialize the input data
A[0]=2.2;
A[1]=1.3;
B[0]=3.7;
B[1]=5.4;
// Load the kernel source code into the array programSource
FILE *fp;
char *programSource;
size_t programSize;
fp = fopen("fplos_kernels.cl", "r");
if (!fp) {
fprintf(stderr, "Failed to load kernel.\n");
exit(1);
}
programSource = (char*)malloc(MAX_SOURCE_SIZE);
fclose( fp );
// Use this to check the output of each API call
cl_int status;
// Retrieve the number of platforms
cl_uint numPlatforms=0;
status=clGetPlatformIDs(0, NULL,&numPlatforms);
// Allocate enough space for each platform
cl_platform_id *platforms=NULL;
platforms=(cl_platform_id*)malloc(
numPlatforms*sizeof(cl_platform_id));
// Fill in the platforms
status = clGetPlatformIDs(numPlatforms, platforms, NULL);
// Retrieve the number of devices
cl_uint numDevices=0;
status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, 0,
NULL,&numDevices);
// Allocate enough space for each device
cl_device_id *devices;
devices = (cl_device_id*)malloc(
numDevices*sizeof(cl_device_id));
// Fill in the devices
status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL,
numDevices, devices, NULL);
// Create a context and associate it with the devices
cl_context context;
context = clCreateContext(NULL, numDevices, devices, NULL,
NULL, &status);
// Create a command queue and associate it with the device
cl_command_queue cmdQueue;
cmdQueue = clCreateCommandQueue(context, devices[0], 0,
&status);
// Create a buffer object that will contain the data
// from the host array A
cl_mem bufA;
bufA = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,
NULL, &status);
// Create a buffer object that will contain the data
// from the host array B
cl_mem bufB;
bufB = clCreateBuffer(context, CL_MEM_READ_ONLY, datasize,
NULL, &status);
// Create a buffer object that will hold the output data
cl_mem bufC;
bufC = clCreateBuffer(context, CL_MEM_WRITE_ONLY, datasize,
NULL, &status);
//.........这里部分代码省略.........
// Setup new sub-window
void SetupSubWindow(int subWinIdx)
{
float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
float angle = 0.8f;
SubWindowData *win;
win = &g_SubWindowData[subWinIdx];
win->ObjectShape = (subWinIdx == 0) ? SHAPE_TEAPOT : SHAPE_TORUS;
win->Zoom = 1;
win->AutoRotate = (subWinIdx == 0);
win->MatAmbient[0] = (subWinIdx == 1) ? 0.0f : 0.5f;; win->MatAmbient[1] = win->MatAmbient[2] = 0.2f; win->MatAmbient[3] = 1;
win->MatDiffuse[0] = (subWinIdx == 1) ? 0.0f : 1.0f; win->MatDiffuse[1] = 1; win->MatDiffuse[2] = 0; win->MatDiffuse[3] = 1;
win->LightMultiplier = 1;
win->LightDirection[0] = win->LightDirection[1] = win->LightDirection[2] = -0.57735f;
win->RotateTime = GetTimeMs();
SetQuaternionFromAxisAngle(axis, angle, win->Rotation);
SetQuaternionFromAxisAngle(axis, angle, win->RotateStart);
glutSetWindow(win->WinID);
// Set GLUT callbacks
glutDisplayFunc(DisplaySubWindow);
glutReshapeFunc(ReshapeSubWindow);
// Set GLUT event callbacks
// - Register mouse button events callback
glutMouseFunc((GLUTmousebuttonfun)MouseButtonCB);
// - Register mouse motion events callback
glutMotionFunc((GLUTmousemotionfun)MouseMotionCB);
// - Register mouse "passive" motion events (same as Motion)
glutPassiveMotionFunc((GLUTmousemotionfun)MouseMotionCB);
// - Register keyboard events callback
glutKeyboardFunc((GLUTkeyboardfun)KeyboardCB);
// - Register special key events callback
glutSpecialFunc((GLUTspecialfun)SpecialKeyCB);
// - Send 'glutGetModifers' function pointer to AntTweakBar;
// required because the GLUT key event functions do not report key modifiers states.
TwGLUTModifiersFunc(glutGetModifiers);
// Create some 3D objects (stored in display lists)
glNewList(SHAPE_TEAPOT, GL_COMPILE);
glutSolidTeapot(1.0);
glEndList();
glNewList(SHAPE_TORUS, GL_COMPILE);
glutSolidTorus(0.3, 1.0, 16, 32);
glEndList();
glNewList(SHAPE_CONE, GL_COMPILE);
glutSolidCone(1.0, 1.5, 64, 4);
glEndList();
// Declare this window as current for AntTweakBar.
// Here, this will create a new AntTweakBar context for this window,
// which will be identified by the number WinID.
TwSetCurrentWindow(win->WinID);
// Create a tweak bar
win->Bar = TwNewBar("TweakBar");
TwDefine(" GLOBAL help='This example shows how to use AntTweakBar with multiple windows.' "); // Message added to the help bar.
TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color
// Add 'win->Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
TwAddVarRW(win->Bar, "Zoom", TW_TYPE_FLOAT, &win->Zoom,
" min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");
// Add 'win->Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
TwAddVarRW(win->Bar, "ObjRotation", TW_TYPE_QUAT4F, &win->Rotation,
" label='Object rotation' open help='Change the object orientation.' ");
// Add callback to toggle auto-rotate mode (callback functions are defined above).
TwAddVarCB(win->Bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, win,
" label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");
// Add 'win->LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
TwAddVarRW(win->Bar, "Multiplier", TW_TYPE_FLOAT, &win->LightMultiplier,
" label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");
// Add 'win->LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
TwAddVarRW(win->Bar, "LightDir", TW_TYPE_DIR3F, &win->LightDirection,
" label='Light direction' open help='Change the light direction.' ");
// Add 'win->MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
// and is inserted into a group named 'Material'.
TwAddVarRW(win->Bar, "Ambient", TW_TYPE_COLOR3F, &win->MatAmbient, " group='Material' ");
// Add 'win->MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
// and is inserted into group 'Material'.
TwAddVarRW(win->Bar, "Diffuse", TW_TYPE_COLOR3F, &win->MatDiffuse, " group='Material' ");
// Add the enum variable 'win->ObjectShape' to 'bar'
// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
{
// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
// Create a type for the enum shapeEV
TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
// add 'win->CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
TwAddVarRW(win->Bar, "Shape", shapeType, &win->ObjectShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
}
}
// Main
int main(int argc, char *argv[])
{
TwBar *bar; // Pointer to the tweak bar
float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
float angle = 0.8f;
// Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("AntTweakBar simple example using GLUT");
glutCreateMenu(NULL);
// Set GLUT callbacks
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
atexit(Terminate); // Called after glutMainLoop ends
// Initialize AntTweakBar
TwInit(TW_OPENGL, NULL);
// Set GLUT event callbacks
// - Directly redirect GLUT mouse button events to AntTweakBar
glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
// - Directly redirect GLUT mouse motion events to AntTweakBar
glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
// - Directly redirect GLUT key events to AntTweakBar
glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
// - Directly redirect GLUT special key events to AntTweakBar
glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
// - Send 'glutGetModifers' function pointer to AntTweakBar;
// required because the GLUT key event functions do not report key modifiers states.
TwGLUTModifiersFunc(glutGetModifiers);
// Create some 3D objects (stored in display lists)
glNewList(SHAPE_TEAPOT, GL_COMPILE);
glutSolidTeapot(1.0);
glEndList();
glNewList(SHAPE_TORUS, GL_COMPILE);
glutSolidTorus(0.3, 1.0, 16, 32);
glEndList();
glNewList(SHAPE_CONE, GL_COMPILE);
glutSolidCone(1.0, 1.5, 64, 4);
glEndList();
// Create a tweak bar
bar = TwNewBar("TweakBar");
TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color
// Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom,
" min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");
// Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation,
" label='Object rotation' opened=true help='Change the object orientation.' ");
// Add callback to toggle auto-rotate mode (callback functions are defined above).
TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL,
" label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");
// Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier,
" label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");
// Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection,
" label='Light direction' opened=true help='Change the light direction.' ");
// Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
// and is inserted into a group named 'Material'.
TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");
// Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
// and is inserted into group 'Material'.
TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");
// Add the enum variable 'g_CurrentShape' to 'bar'
// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
{
// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
// Create a type for the enum shapeEV
TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
}
// Store time
g_RotateTime = GetTimeMs();
// Init rotation
SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);
// Call the GLUT main loop
glutMainLoop();
//.........这里部分代码省略.........
请发表评论