Files
test/source/blender/gpu/opengl/gl_query.cc
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00

65 lines
1.4 KiB
C++

/* SPDX-FileCopyrightText: 2020 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#include "gl_query.hh"
namespace blender::gpu {
#define QUERY_CHUNCK_LEN 256
GLQueryPool::~GLQueryPool()
{
glDeleteQueries(query_ids_.size(), query_ids_.data());
}
void GLQueryPool::init(GPUQueryType type)
{
BLI_assert(initialized_ == false);
initialized_ = true;
type_ = type;
gl_type_ = to_gl(type);
query_issued_ = 0;
}
#if 0 /* TODO: to avoid realloc of permanent query pool. */
void GLQueryPool::reset(GPUQueryType type)
{
initialized_ = false;
}
#endif
void GLQueryPool::begin_query()
{
/* TODO: add assert about expected usage. */
while (query_issued_ >= query_ids_.size()) {
int64_t prev_size = query_ids_.size();
int64_t chunk_size = prev_size == 0 ? query_ids_.capacity() : QUERY_CHUNCK_LEN;
query_ids_.resize(prev_size + chunk_size);
glGenQueries(chunk_size, &query_ids_[prev_size]);
}
glBeginQuery(gl_type_, query_ids_[query_issued_++]);
}
void GLQueryPool::end_query()
{
/* TODO: add assert about expected usage. */
glEndQuery(gl_type_);
}
void GLQueryPool::get_occlusion_result(MutableSpan<uint32_t> r_values)
{
BLI_assert(r_values.size() == query_issued_);
for (int i = 0; i < query_issued_; i++) {
/* NOTE: This is a sync point. */
glGetQueryObjectuiv(query_ids_[i], GL_QUERY_RESULT, &r_values[i]);
}
}
} // namespace blender::gpu