summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-11-13 10:58:05 -0500
committerSam Anthony <sam@samanthony.xyz>2024-11-13 10:58:05 -0500
commit2e442c894d50c42aea748d21a6f08add123e9a70 (patch)
tree18787923b5fd63c1cb519141b97165aa5afd885f
parent8f13501beaad34d4d58178ab7a41747c28cf6faa (diff)
downloadballs-2e442c894d50c42aea748d21a6f08add123e9a70.zip
rearrange functions
-rw-r--r--balls.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/balls.c b/balls.c
index 7fb3b3c..67eb0b2 100644
--- a/balls.c
+++ b/balls.c
@@ -74,14 +74,14 @@ void setColors(void);
void configSharedData(void);
void setKernelArgs(void);
void animate(int v);
-void display(void);
-void reshape(int w, int h);
-void keyboard(unsigned char key, int x, int y);
void move(void);
void collideBalls(void);
cl_event collideWalls(void);
-void copyPositionsToGpu(cl_event cpuEvent);
void genVertices(void);
+void display(void);
+void copyPositionsToGpu(cl_event cpuEvent);
+void reshape(int w, int h);
+void keyboard(unsigned char key, int x, int y);
void freeCL(void);
void freeGL(void);
void initShaders(void);
@@ -559,33 +559,6 @@ animate(int v) {
}
void
-display(void) {
- int i;
-
- glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
-
- glBindVertexArray(vertexVAO);
- for (i = 0; i < nBalls; i++)
- glDrawArrays(GL_TRIANGLE_FAN, i*CIRCLE_POINTS, CIRCLE_POINTS);
- glBindVertexArray(0);
-
- frameCount();
-
- glutSwapBuffers();
-}
-
-void
-reshape(int w, int h) {
- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
-}
-
-void
-keyboard(unsigned char key, int x, int y) {
- if (key == KEY_QUIT)
- glutDestroyWindow(glutGetWindow());
-}
-
-void
move(void) {
size_t size;
int err;
@@ -623,20 +596,6 @@ collideWalls(void) {
return event;
}
-/* Wait for the CPU to finish computing the new positions and then copy them to the GPU. */
-void
-copyPositionsToGpu(cl_event cpuEvent) {
- int err;
-
- err = clWaitForEvents(1, &cpuEvent);
- if (err < 0)
- sysfatal("Error waiting for CPU kernel to finish.\n");
- clReleaseEvent(cpuEvent);
- err = clEnqueueWriteBuffer(gpuQueue, positionsGpuBuf, CL_TRUE, 0, nBalls*2*sizeof(float), positionsHostBuf, 0, NULL, NULL);
- if (err < 0)
- sysfatal("Failed to copy positions from host to GPU.\n");
-}
-
void
genVertices(void) {
int err;
@@ -665,6 +624,47 @@ genVertices(void) {
}
void
+display(void) {
+ int i;
+
+ glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
+
+ glBindVertexArray(vertexVAO);
+ for (i = 0; i < nBalls; i++)
+ glDrawArrays(GL_TRIANGLE_FAN, i*CIRCLE_POINTS, CIRCLE_POINTS);
+ glBindVertexArray(0);
+
+ frameCount();
+
+ glutSwapBuffers();
+}
+
+/* Wait for the CPU to finish computing the new positions and then copy them to the GPU. */
+void
+copyPositionsToGpu(cl_event cpuEvent) {
+ int err;
+
+ err = clWaitForEvents(1, &cpuEvent);
+ if (err < 0)
+ sysfatal("Error waiting for CPU kernel to finish.\n");
+ clReleaseEvent(cpuEvent);
+ err = clEnqueueWriteBuffer(gpuQueue, positionsGpuBuf, CL_TRUE, 0, nBalls*2*sizeof(float), positionsHostBuf, 0, NULL, NULL);
+ if (err < 0)
+ sysfatal("Failed to copy positions from host to GPU.\n");
+}
+
+void
+reshape(int w, int h) {
+ glViewport(0, 0, (GLsizei) w, (GLsizei) h);
+}
+
+void
+keyboard(unsigned char key, int x, int y) {
+ if (key == KEY_QUIT)
+ glutDestroyWindow(glutGetWindow());
+}
+
+void
freeCL(void) {
size_t i;