mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Corrects definition of Bookender
and provides the default implementation.
This commit is contained in:
parent
1157bde453
commit
513903890e
@ -13,7 +13,9 @@
|
||||
|
||||
using namespace Outputs::CRT;
|
||||
|
||||
static const GLint internalFormatForDepth(size_t depth) {
|
||||
namespace {
|
||||
|
||||
const GLint internalFormatForDepth(size_t depth) {
|
||||
switch(depth) {
|
||||
default: return GL_FALSE;
|
||||
case 1: return GL_R8UI;
|
||||
@ -23,7 +25,7 @@ static const GLint internalFormatForDepth(size_t depth) {
|
||||
}
|
||||
}
|
||||
|
||||
static const GLenum formatForDepth(size_t depth) {
|
||||
const GLenum formatForDepth(size_t depth) {
|
||||
switch(depth) {
|
||||
default: return GL_FALSE;
|
||||
case 1: return GL_RED_INTEGER;
|
||||
@ -33,6 +35,21 @@ static const GLenum formatForDepth(size_t depth) {
|
||||
}
|
||||
}
|
||||
|
||||
struct DefaultBookender: public TextureBuilder::Bookender {
|
||||
public:
|
||||
DefaultBookender(size_t bytes_per_pixel) : bytes_per_pixel_(bytes_per_pixel) {}
|
||||
|
||||
void add_bookends(uint8_t *const left_value, uint8_t *const right_value, uint8_t *left_bookend, uint8_t *right_bookend) {
|
||||
memcpy(left_bookend, left_value, bytes_per_pixel_);
|
||||
memcpy(right_bookend, right_value, bytes_per_pixel_);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t bytes_per_pixel_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TextureBuilder::TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit) :
|
||||
bytes_per_pixel_(bytes_per_pixel),
|
||||
write_areas_start_x_(0),
|
||||
@ -50,6 +67,8 @@ TextureBuilder::TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit) :
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormatForDepth(bytes_per_pixel), InputBufferBuilderWidth, InputBufferBuilderHeight, 0, formatForDepth(bytes_per_pixel), GL_UNSIGNED_BYTE, nullptr);
|
||||
|
||||
set_bookender(nullptr);
|
||||
}
|
||||
|
||||
TextureBuilder::~TextureBuilder() {
|
||||
@ -103,13 +122,14 @@ void TextureBuilder::reduce_previous_allocation_to(size_t actual_length) {
|
||||
// TODO: allow somebody else to specify the rule for generating a left-padding value and
|
||||
// a right-padding value.
|
||||
uint8_t *start_pointer = pointer_to_location(write_area_.x, write_area_.y) - bytes_per_pixel_;
|
||||
memcpy( start_pointer,
|
||||
&start_pointer[bytes_per_pixel_],
|
||||
bytes_per_pixel_);
|
||||
bookender_->add_bookends(&start_pointer[bytes_per_pixel_], &start_pointer[actual_length * bytes_per_pixel_], start_pointer, &start_pointer[(actual_length + 1) * bytes_per_pixel_]);
|
||||
}
|
||||
|
||||
memcpy( &start_pointer[(actual_length + 1) * bytes_per_pixel_],
|
||||
&start_pointer[actual_length * bytes_per_pixel_],
|
||||
bytes_per_pixel_);
|
||||
void TextureBuilder::set_bookender(std::unique_ptr<TextureBuilder::Bookender> bookender) {
|
||||
bookender_ = std::move(bookender);
|
||||
if(!bookender_) {
|
||||
bookender_.reset(new DefaultBookender(bytes_per_pixel_));
|
||||
}
|
||||
}
|
||||
|
||||
bool TextureBuilder::retain_latest() {
|
||||
|
@ -107,11 +107,12 @@ class TextureBuilder {
|
||||
struct Bookender {
|
||||
/// Writes to left_bookend the sample that should appear as a continuation before the left_value;
|
||||
/// writes to right_bookend the sample that should appear as a continuation after right_value.
|
||||
void add_bookends(uint8_t *const left_value, uint8_t *const right_value, uint8_t *left_bookend, uint8_t *right_bookend);
|
||||
virtual void add_bookends(uint8_t *const left_value, uint8_t *const right_value, uint8_t *left_bookend, uint8_t *right_bookend) = 0;
|
||||
};
|
||||
|
||||
/// Sets the current bookender. Will be called synchronously within the builder-writing thread.
|
||||
void set_bookender(Bookender *bookender);
|
||||
/// Sets the current bookender. The bookender be called synchronously within the builder-writing thread.
|
||||
/// Supply nullptr to engage the default bookender.
|
||||
void set_bookender(std::unique_ptr<Bookender> bookender);
|
||||
|
||||
private:
|
||||
// the buffer size
|
||||
@ -135,6 +136,8 @@ class TextureBuilder {
|
||||
// Caveat: reset to the origin upon a submit. So used in comparison by flush to
|
||||
// determine whether the current batch of write areas needs to be relocated.
|
||||
uint16_t write_areas_start_x_, write_areas_start_y_;
|
||||
|
||||
std::unique_ptr<Bookender> bookender_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user