-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmyapp.cpp
63 lines (54 loc) · 2.01 KB
/
myapp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "precomp.h"
#include "myapp.h"
TheApp* CreateApp() { return new MyApp(); }
// -----------------------------------------------------------
// Initialize the application
// -----------------------------------------------------------
void MyApp::Init()
{
// anything that happens only once at application start goes here
}
// -----------------------------------------------------------
// Main application tick function - Executed once per frame
// -----------------------------------------------------------
void MyApp::Tick( float deltaTime )
{
// NOTE: clear this function before actual use; code is only for
// demonstration purposes. See _ getting started.pdf for details.
// clear the screen to black
screen->Clear( 0 );
// print something to the console window
printf( "hello world!\n" );
// plot some colors
for (int red = 0; red < 256; red++) for (int green = 0; green < 256; green++)
{
int x = red, y = green;
screen->Plot( x + 200, y + 100, (red << 16) + (green << 8) );
}
// plot a white pixel in the bottom right corner
screen->Plot( SCRWIDTH - 2, SCRHEIGHT - 2, 0xffffff );
#if 0
static Kernel* kernel = 0; // statics should be members of MyApp of course.
static Surface bitmap( 512, 512 ); // having them here allows us to disable the OpenCL
static Buffer* clBuffer = 0; // demonstration using a single #if 0.
static int offset = 0;
if (!kernel)
{
// prepare for OpenCL work
Kernel::InitCL();
// compile and load kernel "render" from file "kernels.cl"
kernel = new Kernel( "cl/kernels.cl", "render" );
// create an OpenCL buffer over using bitmap.pixels
clBuffer = new Buffer( 512 * 512, Buffer::DEFAULT, bitmap.pixels );
}
// pass arguments to the OpenCL kernel
kernel->SetArgument( 0, clBuffer );
kernel->SetArgument( 1, offset++ );
// run the kernel; use 512 * 512 threads
kernel->Run( 512 * 512 );
// get the results back from GPU to CPU (and thus: into bitmap.pixels)
clBuffer->CopyFromDevice();
// show the result on screen
bitmap.CopyTo( screen, 500, 200 );
#endif
}