From 67e82c713f3b994af0694cabc51dc97a60234ed5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 5 Aug 2015 21:12:33 -0400 Subject: [PATCH] Broke assumption that every item in a vertex description is a short, specifically turning lateral into a byte. Which buys me a byte for phase, if that's sufficient. --- .../Mac/Clock Signal/CSCathodeRayView.m | 10 +++++----- Outputs/CRT.cpp | 20 +++++++++---------- Outputs/CRT.hpp | 4 ++-- Outputs/CRTFrame.h | 18 ++++++++++++----- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m index 9e8274efc..ce6fc300c 100644 --- a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m +++ b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m @@ -130,7 +130,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt if(crtFrame) { [self.openGLContext makeCurrentContext]; - glBufferData(GL_ARRAY_BUFFER, _crtFrame->number_of_runs * sizeof(GLushort) * kCRTSizeOfVertex * 6, _crtFrame->runs, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, _crtFrame->number_of_runs * kCRTSizeOfVertex * 6, _crtFrame->runs, GL_DYNAMIC_DRAW); glBindTexture(GL_TEXTURE_2D, _textureName); @@ -239,10 +239,10 @@ const char *fragmentShader = glEnableVertexAttribArray(_textureCoordinatesAttribute); glEnableVertexAttribArray(_lateralAttribute); - const GLsizei vertexStride = kCRTSizeOfVertex * sizeof(GLushort); - glVertexAttribPointer(_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)(kCRTVertexOffsetOfPosition * sizeof(GLushort))); - glVertexAttribPointer(_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)(kCRTVertexOffsetOfTexCoord * sizeof(GLushort))); - glVertexAttribPointer(_lateralAttribute, 1, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)(kCRTVertexOffsetOfLateral * sizeof(GLushort))); + const GLsizei vertexStride = kCRTSizeOfVertex; + glVertexAttribPointer(_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)kCRTVertexOffsetOfPosition); + glVertexAttribPointer(_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfTexCoord); + glVertexAttribPointer(_lateralAttribute, 1, GL_UNSIGNED_BYTE, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfLateral); glGenTextures(1, &_textureName); glBindTexture(GL_TEXTURE_2D, _textureName); diff --git a/Outputs/CRT.cpp b/Outputs/CRT.cpp index dfbcec031..30597b926 100644 --- a/Outputs/CRT.cpp +++ b/Outputs/CRT.cpp @@ -185,18 +185,16 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, bool vsync_ // set it to false for the next run through this loop (if any) int next_run_length = std::min(time_until_vertical_sync_event, time_until_horizontal_sync_event); -// if(next_run_length) { - hsync_requested = false; - vsync_requested = false; -// } + hsync_requested = false; + vsync_requested = false; - uint16_t *next_run = (is_output_run && _current_frame_builder && next_run_length) ? _current_frame_builder->get_next_run() : nullptr; + uint8_t *next_run = (is_output_run && _current_frame_builder && next_run_length) ? _current_frame_builder->get_next_run() : nullptr; int lengthMask = (_is_in_hsync ? kRetraceXMask : 0) | (_is_in_vsync ? kRetraceXMask : 0); -#define position_x(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 0] -#define position_y(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 1] -#define tex_x(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 0] -#define tex_y(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 1] +#define position_x(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 0]) +#define position_y(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 2]) +#define tex_x(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 0]) +#define tex_y(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 2]) #define lateral(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfLateral] if(next_run) @@ -417,7 +415,7 @@ void CRTFrameBuilder::complete() frame.runs = &_all_runs[0]; } -uint16_t *CRTFrameBuilder::get_next_run() +uint8_t *CRTFrameBuilder::get_next_run() { const size_t vertices_per_run = 6; const size_t size_of_run = kCRTSizeOfVertex * vertices_per_run; @@ -428,7 +426,7 @@ uint16_t *CRTFrameBuilder::get_next_run() _all_runs.resize(_all_runs.size() + size_of_run * 200); } - uint16_t *next_run = &_all_runs[frame.number_of_runs * size_of_run]; + uint8_t *next_run = &_all_runs[frame.number_of_runs * size_of_run]; frame.number_of_runs++; return next_run; diff --git a/Outputs/CRT.hpp b/Outputs/CRT.hpp index a44036cbd..6ed15e136 100644 --- a/Outputs/CRT.hpp +++ b/Outputs/CRT.hpp @@ -26,12 +26,12 @@ struct CRTFrameBuilder { ~CRTFrameBuilder(); private: - std::vector _all_runs; + std::vector _all_runs; void reset(); void complete(); - uint16_t *get_next_run(); + uint8_t *get_next_run(); friend CRT; void allocate_write_area(int required_length); diff --git a/Outputs/CRTFrame.h b/Outputs/CRTFrame.h index e4938ac83..ebb14ba4a 100644 --- a/Outputs/CRTFrame.h +++ b/Outputs/CRTFrame.h @@ -29,16 +29,24 @@ typedef struct { CRTBuffer *buffers; int number_of_runs; - uint16_t *runs; + uint8_t *runs; } CRTFrame; #ifdef __cplusplus } #endif -static const int kCRTSizeOfVertex = 5; -static const int kCRTVertexOffsetOfPosition = 0; -static const int kCRTVertexOffsetOfTexCoord = 2; -static const int kCRTVertexOffsetOfLateral = 4; + +typedef uint16_t kCRTPositionType; +typedef uint16_t kCRTTexCoordType; +typedef uint8_t kCRTLateralType; +typedef uint8_t kCRTPhaseType; + +static const size_t kCRTVertexOffsetOfPosition = 0; +static const size_t kCRTVertexOffsetOfTexCoord = 4; +static const size_t kCRTVertexOffsetOfLateral = 8; +static const size_t kCRTVertexOffsetOfPhase = 9; + +static const int kCRTSizeOfVertex = 10; #endif /* CRTFrame_h */