Skip to content

Commit f44692f

Browse files
committed
aobench: hide internal fns using static
1 parent 16f422c commit f44692f

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

samples/aobench/ao.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define FUNCTION
77
#endif
88

9-
FUNCTION unsigned int FNVHash(char* str, unsigned int length) {
9+
FUNCTION static unsigned int FNVHash(char* str, unsigned int length) {
1010
const unsigned int fnv_prime = 0x811C9DC5;
1111
unsigned int hash = 0;
1212
unsigned int i = 0;
@@ -20,13 +20,13 @@ FUNCTION unsigned int FNVHash(char* str, unsigned int length) {
2020
return hash;
2121
}
2222

23-
FUNCTION unsigned int nrand(unsigned int* rng) {
23+
FUNCTION static unsigned int nrand(unsigned int* rng) {
2424
unsigned int orand = *rng;
2525
*rng = FNVHash((char*) &orand, 4);
2626
return *rng;
2727
}
2828

29-
FUNCTION Scalar drand48(Ctx* ctx) {
29+
FUNCTION static Scalar drand48(Ctx* ctx) {
3030
Scalar n = (nrand(&ctx->rng) / 65536.0f);
3131
n = n - floorf(n);
3232
return n;
@@ -193,7 +193,7 @@ FUNCTION static void ambient_occlusion(Ctx* ctx, vec *col, const Isect *isect)
193193
col->z = occlusion;
194194
}
195195

196-
FUNCTION unsigned char aobench_clamp(Scalar f)
196+
FUNCTION static unsigned char aobench_clamp(Scalar f)
197197
{
198198
Scalar s = (f * 255.5f);
199199

@@ -203,7 +203,13 @@ FUNCTION unsigned char aobench_clamp(Scalar f)
203203
return (unsigned char) s;
204204
}
205205

206-
FUNCTION void render_pixel(Ctx* ctx, int x, int y, int w, int h, int nsubsamples, unsigned char* img) {
206+
FUNCTION EXTERNAL_FN Ctx get_init_context() {
207+
return (Ctx) {
208+
.rng = 0xFEEFDEED,
209+
};
210+
}
211+
212+
FUNCTION EXTERNAL_FN void render_pixel(Ctx* ctx, int x, int y, int w, int h, int nsubsamples, unsigned char* img) {
207213
Scalar pixel[3] = { 0, 0, 0 };
208214

209215
ctx->rng = x * w + y;
@@ -263,7 +269,7 @@ FUNCTION void render_pixel(Ctx* ctx, int x, int y, int w, int h, int nsubsamples
263269
img[3 * (y * w + x) + 2] = aobench_clamp(pixel[2]);
264270
}
265271

266-
FUNCTION void init_scene(Ctx* ctx)
272+
FUNCTION EXTERNAL_FN void init_scene(Ctx* ctx)
267273
{
268274
ctx->spheres[0].center.x = -2.0f;
269275
ctx->spheres[0].center.y = 0.0f;
@@ -288,10 +294,4 @@ FUNCTION void init_scene(Ctx* ctx)
288294
ctx->plane.n.y = 1.0f;
289295
ctx->plane.n.z = 0.0f;
290296

291-
}
292-
293-
FUNCTION Ctx get_init_context() {
294-
return (Ctx) {
295-
.rng = 0xFEEFDEED,
296-
};
297297
}

samples/aobench/ao.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ typedef struct {
6464
unsigned int rng;
6565
} Ctx;
6666

67-
Ctx get_init_context();
68-
void init_scene(Ctx*);
69-
void render_pixel(Ctx*, int x, int y, int w, int h, int nsubsamples, unsigned char* img);
67+
#ifndef EXTERNAL_FN
68+
#define EXTERNAL_FN static
69+
#endif
70+
71+
EXTERNAL_FN Ctx get_init_context();
72+
EXTERNAL_FN void init_scene(Ctx*);
73+
EXTERNAL_FN void render_pixel(Ctx*, int x, int y, int w, int h, int nsubsamples, unsigned char* img);

samples/aobench/ao_host.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define private
2-
2+
#define EXTERNAL_FN /* not static */
33
#include "ao.c"

samples/aobench/ao_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define EXTERNAL_FN /* not static */
12
#include "ao.h"
23
#include "../runtime/runtime_app_common.h"
34

0 commit comments

Comments
 (0)