mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-30 23:29:08 +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;
|
using namespace Outputs::CRT;
|
||||||
|
|
||||||
static const GLint internalFormatForDepth(size_t depth) {
|
namespace {
|
||||||
|
|
||||||
|
const GLint internalFormatForDepth(size_t depth) {
|
||||||
switch(depth) {
|
switch(depth) {
|
||||||
default: return GL_FALSE;
|
default: return GL_FALSE;
|
||||||
case 1: return GL_R8UI;
|
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) {
|
switch(depth) {
|
||||||
default: return GL_FALSE;
|
default: return GL_FALSE;
|
||||||
case 1: return GL_RED_INTEGER;
|
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) :
|
TextureBuilder::TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit) :
|
||||||
bytes_per_pixel_(bytes_per_pixel),
|
bytes_per_pixel_(bytes_per_pixel),
|
||||||
write_areas_start_x_(0),
|
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_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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);
|
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() {
|
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
|
// TODO: allow somebody else to specify the rule for generating a left-padding value and
|
||||||
// a right-padding value.
|
// a right-padding value.
|
||||||
uint8_t *start_pointer = pointer_to_location(write_area_.x, write_area_.y) - bytes_per_pixel_;
|
uint8_t *start_pointer = pointer_to_location(write_area_.x, write_area_.y) - bytes_per_pixel_;
|
||||||
memcpy( start_pointer,
|
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_]);
|
||||||
&start_pointer[bytes_per_pixel_],
|
}
|
||||||
bytes_per_pixel_);
|
|
||||||
|
|
||||||
memcpy( &start_pointer[(actual_length + 1) * bytes_per_pixel_],
|
void TextureBuilder::set_bookender(std::unique_ptr<TextureBuilder::Bookender> bookender) {
|
||||||
&start_pointer[actual_length * bytes_per_pixel_],
|
bookender_ = std::move(bookender);
|
||||||
bytes_per_pixel_);
|
if(!bookender_) {
|
||||||
|
bookender_.reset(new DefaultBookender(bytes_per_pixel_));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureBuilder::retain_latest() {
|
bool TextureBuilder::retain_latest() {
|
||||||
|
@ -107,11 +107,12 @@ class TextureBuilder {
|
|||||||
struct Bookender {
|
struct Bookender {
|
||||||
/// Writes to left_bookend the sample that should appear as a continuation before the left_value;
|
/// 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.
|
/// 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.
|
/// Sets the current bookender. The bookender be called synchronously within the builder-writing thread.
|
||||||
void set_bookender(Bookender *bookender);
|
/// Supply nullptr to engage the default bookender.
|
||||||
|
void set_bookender(std::unique_ptr<Bookender> bookender);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// the buffer size
|
// the buffer size
|
||||||
@ -135,6 +136,8 @@ class TextureBuilder {
|
|||||||
// Caveat: reset to the origin upon a submit. So used in comparison by flush to
|
// 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.
|
// determine whether the current batch of write areas needs to be relocated.
|
||||||
uint16_t write_areas_start_x_, write_areas_start_y_;
|
uint16_t write_areas_start_x_, write_areas_start_y_;
|
||||||
|
|
||||||
|
std::unique_ptr<Bookender> bookender_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user