mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-09 17:31:18 +00:00
Added a testing hook, but as of yet no tests.
This commit is contained in:
parent
aca1fa0577
commit
f59537bce9
@ -11,8 +11,13 @@
|
|||||||
using namespace Outputs::CRT;
|
using namespace Outputs::CRT;
|
||||||
|
|
||||||
ArrayBuilder::ArrayBuilder(size_t input_size, size_t output_size) :
|
ArrayBuilder::ArrayBuilder(size_t input_size, size_t output_size) :
|
||||||
output_(output_size),
|
output_(output_size, nullptr),
|
||||||
input_(input_size)
|
input_(input_size, nullptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
ArrayBuilder::ArrayBuilder(size_t input_size, size_t output_size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function) :
|
||||||
|
output_(output_size, submission_function),
|
||||||
|
input_(input_size, submission_function)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool ArrayBuilder::is_full()
|
bool ArrayBuilder::is_full()
|
||||||
@ -70,8 +75,8 @@ ArrayBuilder::Submission ArrayBuilder::submit()
|
|||||||
ArrayBuilder::Submission submission;
|
ArrayBuilder::Submission submission;
|
||||||
|
|
||||||
buffer_mutex_.lock();
|
buffer_mutex_.lock();
|
||||||
submission.input_size = input_.submit();
|
submission.input_size = input_.submit(true);
|
||||||
submission.output_size = output_.submit();
|
submission.output_size = output_.submit(false);
|
||||||
if(is_full_)
|
if(is_full_)
|
||||||
{
|
{
|
||||||
is_full_ = false;
|
is_full_ = false;
|
||||||
@ -83,18 +88,22 @@ ArrayBuilder::Submission ArrayBuilder::submit()
|
|||||||
return submission;
|
return submission;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayBuilder::Buffer::Buffer(size_t size) :
|
ArrayBuilder::Buffer::Buffer(size_t size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function) :
|
||||||
allocated_data(0), flushed_data(0), submitted_data(0), is_full(false)
|
allocated_data(0), flushed_data(0), submitted_data(0), is_full(false), submission_function_(submission_function)
|
||||||
{
|
{
|
||||||
glGenBuffers(1, &buffer);
|
if(!submission_function_)
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
{
|
||||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, NULL, GL_STREAM_DRAW);
|
glGenBuffers(1, &buffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, NULL, GL_STREAM_DRAW);
|
||||||
|
}
|
||||||
data.resize(size);
|
data.resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayBuilder::Buffer::~Buffer()
|
ArrayBuilder::Buffer::~Buffer()
|
||||||
{
|
{
|
||||||
glDeleteBuffers(1, &buffer);
|
if(!submission_function_)
|
||||||
|
glDeleteBuffers(1, &buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *ArrayBuilder::get_storage(size_t size, Buffer &buffer)
|
uint8_t *ArrayBuilder::get_storage(size_t size, Buffer &buffer)
|
||||||
@ -151,16 +160,19 @@ void ArrayBuilder::Buffer::flush()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ArrayBuilder::Buffer::submit()
|
size_t ArrayBuilder::Buffer::submit(bool is_input)
|
||||||
{
|
{
|
||||||
size_t length = flushed_data;
|
size_t length = flushed_data;
|
||||||
|
if(submission_function_)
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
submission_function_(is_input, data.data(), length);
|
||||||
uint8_t *destination = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
else
|
||||||
memcpy(destination, data.data(), length);
|
{
|
||||||
glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length);
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
uint8_t *destination = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||||
|
memcpy(destination, data.data(), length);
|
||||||
|
glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, (GLsizeiptr)length);
|
||||||
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||||
|
}
|
||||||
submitted_data = flushed_data;
|
submitted_data = flushed_data;
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,11 @@ class ArrayBuilder {
|
|||||||
/// @c input_size bytes of storage for the input buffer.
|
/// @c input_size bytes of storage for the input buffer.
|
||||||
ArrayBuilder(size_t input_size, size_t output_size);
|
ArrayBuilder(size_t input_size, size_t output_size);
|
||||||
|
|
||||||
|
/// Creates an instance of ArrayBuilder with @c output_size bytes of storage for the output buffer and
|
||||||
|
/// @c input_size bytes of storage for the input buffer that, rather than using OpenGL, will submit data
|
||||||
|
/// to the @c submission_function. [Teleological: this is provided as a testing hook.]
|
||||||
|
ArrayBuilder(size_t input_size, size_t output_size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function);
|
||||||
|
|
||||||
/// Attempts to add @c size bytes
|
/// Attempts to add @c size bytes
|
||||||
uint8_t *get_input_storage(size_t size);
|
uint8_t *get_input_storage(size_t size);
|
||||||
uint8_t *reget_input_storage(size_t &size);
|
uint8_t *reget_input_storage(size_t &size);
|
||||||
@ -52,7 +57,7 @@ class ArrayBuilder {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
Buffer(size_t size);
|
Buffer(size_t size, std::function<void(bool is_input, uint8_t *, size_t)> submission_function);
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
@ -66,14 +71,16 @@ class ArrayBuilder {
|
|||||||
uint8_t *reget_storage(size_t &size);
|
uint8_t *reget_storage(size_t &size);
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
size_t submit();
|
size_t submit(bool is_input);
|
||||||
void bind();
|
void bind();
|
||||||
void reset();
|
void reset();
|
||||||
|
std::function<void(bool is_input, uint8_t *, size_t)> submission_function_;
|
||||||
} output_, input_;
|
} output_, input_;
|
||||||
uint8_t *get_storage(size_t size, Buffer &buffer);
|
uint8_t *get_storage(size_t size, Buffer &buffer);
|
||||||
|
|
||||||
std::mutex buffer_mutex_;
|
std::mutex buffer_mutex_;
|
||||||
bool is_full_;
|
bool is_full_;
|
||||||
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user