add point occlusion query tester

main
Dominik Madarász 2024-08-26 19:18:11 +02:00
parent cbd52d177a
commit bc73c8ebb6
8 changed files with 191 additions and 0 deletions

View File

@ -1102,6 +1102,7 @@ typedef struct colormap_t {
texture_t *texture; texture_t *texture;
} colormap_t; } colormap_t;
bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb );
unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size);
void fullscreen_quad_rgb( texture_t texture_rgb ); void fullscreen_quad_rgb( texture_t texture_rgb );
void fullscreen_quad_rgb_flipped( texture_t texture ); void fullscreen_quad_rgb_flipped( texture_t texture );
void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3] ); void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3] );

View File

@ -0,0 +1,5 @@
out vec4 fragcolor;
void main() {
fragcolor = vec4(1.0);
}

View File

@ -0,0 +1,5 @@
uniform mat4 u_mvp;
void main() {
gl_Position = u_mvp * vec4(0.0, 0.0, 0.0, 1.0);
}

View File

@ -17190,6 +17190,11 @@ typedef struct colormap_t {
API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb );
// -----------------------------------------------------------------------------
// Occlusion queries
API unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fullscreen quads // fullscreen quads
@ -383214,6 +383219,61 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
ortho44(shm_proj, left, right, bottom, top, znear, zfar); ortho44(shm_proj, left, right, bottom, top, znear, zfar);
} }
// -----------------------------------------------------------------------------
// Occlusion queries
static renderstate_t query_test_rs;
static inline
void query_test_rs_init() {
do_once {
query_test_rs = renderstate();
query_test_rs.depth_test_enabled = true;
query_test_rs.depth_write_enabled = false;
query_test_rs.depth_func = GL_LESS;
query_test_rs.point_size_enabled = 1;
query_test_rs.point_size = 1.0f;
memset(query_test_rs.color_mask, 0, sizeof(query_test_rs.color_mask));
}
}
unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size) {
static int program = -1, vao = -1, u_mvp = -1, query = -1;
if( program < 0 ) {
const char* vs = vfs_read("shaders/query_point_vs.glsl");
const char* fs = vfs_read("shaders/query_point_fs.glsl");
program = shader(vs, fs, "", "fragcolor" , NULL);
u_mvp = glGetUniformLocation(program, "u_mvp");
glGenVertexArrays( 1, (GLuint*)&vao );
glGenQueries(1, (GLuint*)&query);
query_test_rs_init();
}
query_test_rs.point_size = size;
renderstate_apply(&query_test_rs);
int oldprog = last_shader;
glUseProgram( program );
mat44 M; translation44(M, pos.x, pos.y, pos.z);
mat44 MVP; multiply44x3(MVP, proj, view, M);
glUniformMatrix4fv(u_mvp, 1, GL_FALSE, MVP);
glBindVertexArray( vao );
glBeginQuery(GL_SAMPLES_PASSED, query);
glDrawArrays( GL_POINTS, 0, 1 );
glEndQuery(GL_SAMPLES_PASSED);
GLuint samples_passed = 0;
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &samples_passed);
glBindVertexArray( 0 );
glUseProgram( oldprog );
return samples_passed;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fullscreen quads // fullscreen quads

View File

@ -1547,6 +1547,61 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
ortho44(shm_proj, left, right, bottom, top, znear, zfar); ortho44(shm_proj, left, right, bottom, top, znear, zfar);
} }
// -----------------------------------------------------------------------------
// Occlusion queries
static renderstate_t query_test_rs;
static inline
void query_test_rs_init() {
do_once {
query_test_rs = renderstate();
query_test_rs.depth_test_enabled = true;
query_test_rs.depth_write_enabled = false;
query_test_rs.depth_func = GL_LESS;
query_test_rs.point_size_enabled = 1;
query_test_rs.point_size = 1.0f;
memset(query_test_rs.color_mask, 0, sizeof(query_test_rs.color_mask));
}
}
unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size) {
static int program = -1, vao = -1, u_mvp = -1, query = -1;
if( program < 0 ) {
const char* vs = vfs_read("shaders/query_point_vs.glsl");
const char* fs = vfs_read("shaders/query_point_fs.glsl");
program = shader(vs, fs, "", "fragcolor" , NULL);
u_mvp = glGetUniformLocation(program, "u_mvp");
glGenVertexArrays( 1, (GLuint*)&vao );
glGenQueries(1, (GLuint*)&query);
query_test_rs_init();
}
query_test_rs.point_size = size;
renderstate_apply(&query_test_rs);
int oldprog = last_shader;
glUseProgram( program );
mat44 M; translation44(M, pos.x, pos.y, pos.z);
mat44 MVP; multiply44x3(MVP, proj, view, M);
glUniformMatrix4fv(u_mvp, 1, GL_FALSE, MVP);
glBindVertexArray( vao );
glBeginQuery(GL_SAMPLES_PASSED, query);
glDrawArrays( GL_POINTS, 0, 1 );
glEndQuery(GL_SAMPLES_PASSED);
GLuint samples_passed = 0;
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &samples_passed);
glBindVertexArray( 0 );
glUseProgram( oldprog );
return samples_passed;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fullscreen quads // fullscreen quads

View File

@ -222,6 +222,11 @@ typedef struct colormap_t {
API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb );
// -----------------------------------------------------------------------------
// Occlusion queries
API unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fullscreen quads // fullscreen quads

View File

@ -18346,6 +18346,61 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
ortho44(shm_proj, left, right, bottom, top, znear, zfar); ortho44(shm_proj, left, right, bottom, top, znear, zfar);
} }
// -----------------------------------------------------------------------------
// Occlusion queries
static renderstate_t query_test_rs;
static inline
void query_test_rs_init() {
do_once {
query_test_rs = renderstate();
query_test_rs.depth_test_enabled = true;
query_test_rs.depth_write_enabled = false;
query_test_rs.depth_func = GL_LESS;
query_test_rs.point_size_enabled = 1;
query_test_rs.point_size = 1.0f;
memset(query_test_rs.color_mask, 0, sizeof(query_test_rs.color_mask));
}
}
unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size) {
static int program = -1, vao = -1, u_mvp = -1, query = -1;
if( program < 0 ) {
const char* vs = vfs_read("shaders/query_point_vs.glsl");
const char* fs = vfs_read("shaders/query_point_fs.glsl");
program = shader(vs, fs, "", "fragcolor" , NULL);
u_mvp = glGetUniformLocation(program, "u_mvp");
glGenVertexArrays( 1, (GLuint*)&vao );
glGenQueries(1, (GLuint*)&query);
query_test_rs_init();
}
query_test_rs.point_size = size;
renderstate_apply(&query_test_rs);
int oldprog = last_shader;
glUseProgram( program );
mat44 M; translation44(M, pos.x, pos.y, pos.z);
mat44 MVP; multiply44x3(MVP, proj, view, M);
glUniformMatrix4fv(u_mvp, 1, GL_FALSE, MVP);
glBindVertexArray( vao );
glBeginQuery(GL_SAMPLES_PASSED, query);
glDrawArrays( GL_POINTS, 0, 1 );
glEndQuery(GL_SAMPLES_PASSED);
GLuint samples_passed = 0;
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &samples_passed);
glBindVertexArray( 0 );
glUseProgram( oldprog );
return samples_passed;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fullscreen quads // fullscreen quads

View File

@ -3257,6 +3257,11 @@ typedef struct colormap_t {
API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb );
// -----------------------------------------------------------------------------
// Occlusion queries
API unsigned query_test_point(mat44 proj, mat44 view, vec3 pos, float size);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fullscreen quads // fullscreen quads