37 glGenTextures(1, &handle);
39 glTexStorage3D(
GL_TEXTURE_3D, 1, GL_R32F, width, height, depth);
40 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
41 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
42 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
43 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
44 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
60 glGenTextures(1, &handle);
62 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
63 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
64 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
65 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
66 glTexParameteri(
GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
67 glTexStorage3D(
GL_TEXTURE_3D, 1, GL_RGBA8, width, height, depth);
87 glGenBuffers(1, &result);
88 glBindBuffer(GL_ARRAY_BUFFER, result);
89 glBufferData(GL_ARRAY_BUFFER,
sizeof(v), v, GL_STATIC_DRAW);
95 std::vector<int>
v(
N*
N*
N*3);
98 std::vector<unsigned int> I(N*N*N);
99 for (
int z = 0; z <
N; z++)
100 for (
int y = 0;
y <
N;
y++)
101 for (
int x = 0;
x <
N;
x++)
110 glGenBuffers(1, vbo);
111 glBindBuffer(GL_ARRAY_BUFFER, *vbo);
112 glBufferData(GL_ARRAY_BUFFER,
sizeof(v[0]) * v.size(), v.data(), GL_STATIC_DRAW);
113 glGenBuffers(1, ibo);
114 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *ibo);
115 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(I[0]) * I.size(), I.data(), GL_STATIC_DRAW);
125 GLuint reservedMustBeZero;
126 } DrawElementsIndirectCommand;
128 DrawElementsIndirectCommand cmd = {};
129 cmd.instanceCount = 1;
131 glBufferData(GL_ATOMIC_COUNTER_BUFFER,
sizeof(cmd), &cmd, GL_STREAM_DRAW);
136 int local_size_x = 4;
137 int local_size_y = 4;
138 int local_size_z = 4;
144 int work_groups_x = 1 + (app->
tex_surface.
x - 1) / local_size_x;
145 int work_groups_y = 1 + (app->
tex_surface.
y - 1) / local_size_y;
146 int work_groups_z = 1 + (app->
tex_surface.
z - 1) / local_size_z;
153 glBindImageTexture(0, app->
tex_surface.
tex, 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_R32F);
154 glDispatchCompute(work_groups_x, work_groups_y, work_groups_z);
158 glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
163 int local_size_x = 4;
164 int local_size_y = 4;
165 int local_size_z = 4;
174 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, app->
index_buffer);
178 glBindImageTexture(0, app->
tex_surface.
tex, 0, GL_TRUE, 0, GL_READ_ONLY, GL_R32F);
179 glBindImageTexture(1, app->
tex_centroid.
tex, 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_RGBA8);
180 glDispatchCompute(work_groups_x, work_groups_y, work_groups_z);
184 glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
188 glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
189 glMemoryBarrier(GL_ELEMENT_ARRAY_BARRIER_BIT);
207 vec3 ro = (R * camera_pos).xyz();
208 vec3 rd =
normalize(-forward * (1.0
f / tan(app->
fov / 2.0f)) + right * u + up * v);
211 float t = -ro.y / rd.
y;
225 float center_tz = -4.0f;
229 float center_rx = -0.50f;
230 float center_ry = -0.25f;
233 float target_ry = 0.1f * pan;
234 float target_rx = -0.1f * pan * pan;
235 float target_tz = 1.2f * pan * pan;
236 float translate_x = -0.5f * app->
rotate_y;
250 glGenVertexArrays(1, &app->
vao);
251 glBindVertexArray(app->
vao);
259 app->
fov =
PI / 7.0f;
290 glBindBuffer(GL_SHADER_STORAGE_BUFFER, app->
index_buffer);
291 glBufferData(GL_SHADER_STORAGE_BUFFER,
N*
N*
N*
sizeof(
GLuint), 0, GL_STREAM_DRAW);
307 glEnable(GL_DEPTH_TEST);
308 glDepthFunc(GL_LEQUAL);
309 glDepthMask(GL_TRUE);
310 glDepthRangef(0.0, 1.0);
313 glClearColor(0.16
f, 0.16
f, 0.16
f, 1.0
f);
314 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
319 glDepthMask(GL_FALSE);
321 glBindBuffer(GL_ARRAY_BUFFER, app->
vbo_quad);
323 glDrawArrays(GL_TRIANGLES, 0, 6);
328 glDepthMask(GL_TRUE);
329 glActiveTexture(GL_TEXTURE0);
331 glActiveTexture(GL_TEXTURE1);
333 glActiveTexture(GL_TEXTURE2);
343 glBindBuffer(GL_ARRAY_BUFFER, app->
vbo_points);
344 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, app->
index_buffer);
347 glDrawElementsIndirect(GL_POINTS, GL_UNSIGNED_INT, 0);
void app_update_and_render(App *app)
#define get_attrib_location(prog, name)
uniform float sphere_radius
void app_initialize(App *app)
#define attribfv(prog, name, n, offset)
GLint GLsizei GLsizei height
#define get_uniform_location(prog, name)
Volume make_surface_volume()
static mat4 rotateY(float rad)
GLenum GLenum GLsizei count
mat4 animate_view(App *app)
Volume make_centroid_volume()
static vec3 normalize(const vec3 &v)
GLint GLenum GLsizei GLsizei GLsizei depth
#define uniform3fv(prog, name, value)
static mat4 rotateX(float rad)
void update_centroid(App *app)
#define uniformm4(prog, name, value)
void update_sphere(App *app, mat4 mat_view)
GLint GLint GLint GLint GLint x
void clear_indirect_buffer(App *app)
#define uniform1i(prog, name, value)
void make_points(GLuint *vbo, GLuint *ibo)
#define attribiv(prog, name, n, offset)
#define uniform1f(prog, name, value)
static float aspect_ratio
GLint GLsizei GLboolean transpose
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
static mat4 translate(float x, float y, float z)
void update_surface(App *app)