1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-24 02:30:54 +00:00

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.

This commit is contained in:
Thomas Harte 2015-08-05 21:12:33 -04:00
parent 5644b3a1cc
commit 67e82c713f
4 changed files with 29 additions and 23 deletions

View File

@ -130,7 +130,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
if(crtFrame) if(crtFrame)
{ {
[self.openGLContext makeCurrentContext]; [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); glBindTexture(GL_TEXTURE_2D, _textureName);
@ -239,10 +239,10 @@ const char *fragmentShader =
glEnableVertexAttribArray(_textureCoordinatesAttribute); glEnableVertexAttribArray(_textureCoordinatesAttribute);
glEnableVertexAttribArray(_lateralAttribute); glEnableVertexAttribArray(_lateralAttribute);
const GLsizei vertexStride = kCRTSizeOfVertex * sizeof(GLushort); const GLsizei vertexStride = kCRTSizeOfVertex;
glVertexAttribPointer(_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)(kCRTVertexOffsetOfPosition * sizeof(GLushort))); glVertexAttribPointer(_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)kCRTVertexOffsetOfPosition);
glVertexAttribPointer(_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)(kCRTVertexOffsetOfTexCoord * sizeof(GLushort))); glVertexAttribPointer(_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfTexCoord);
glVertexAttribPointer(_lateralAttribute, 1, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)(kCRTVertexOffsetOfLateral * sizeof(GLushort))); glVertexAttribPointer(_lateralAttribute, 1, GL_UNSIGNED_BYTE, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfLateral);
glGenTextures(1, &_textureName); glGenTextures(1, &_textureName);
glBindTexture(GL_TEXTURE_2D, _textureName); glBindTexture(GL_TEXTURE_2D, _textureName);

View File

@ -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) // 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); int next_run_length = std::min(time_until_vertical_sync_event, time_until_horizontal_sync_event);
// if(next_run_length) { hsync_requested = false;
hsync_requested = false; vsync_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); int lengthMask = (_is_in_hsync ? kRetraceXMask : 0) | (_is_in_vsync ? kRetraceXMask : 0);
#define position_x(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 0] #define position_x(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 0])
#define position_y(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 1] #define position_y(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfPosition + 2])
#define tex_x(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 0] #define tex_x(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 0])
#define tex_y(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 1] #define tex_y(v) (*(uint16_t *)&next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfTexCoord + 2])
#define lateral(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfLateral] #define lateral(v) next_run[kCRTSizeOfVertex*v + kCRTVertexOffsetOfLateral]
if(next_run) if(next_run)
@ -417,7 +415,7 @@ void CRTFrameBuilder::complete()
frame.runs = &_all_runs[0]; 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 vertices_per_run = 6;
const size_t size_of_run = kCRTSizeOfVertex * vertices_per_run; 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); _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++; frame.number_of_runs++;
return next_run; return next_run;

View File

@ -26,12 +26,12 @@ struct CRTFrameBuilder {
~CRTFrameBuilder(); ~CRTFrameBuilder();
private: private:
std::vector<uint16_t> _all_runs; std::vector<uint8_t> _all_runs;
void reset(); void reset();
void complete(); void complete();
uint16_t *get_next_run(); uint8_t *get_next_run();
friend CRT; friend CRT;
void allocate_write_area(int required_length); void allocate_write_area(int required_length);

View File

@ -29,16 +29,24 @@ typedef struct {
CRTBuffer *buffers; CRTBuffer *buffers;
int number_of_runs; int number_of_runs;
uint16_t *runs; uint8_t *runs;
} CRTFrame; } CRTFrame;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
static const int kCRTSizeOfVertex = 5;
static const int kCRTVertexOffsetOfPosition = 0; typedef uint16_t kCRTPositionType;
static const int kCRTVertexOffsetOfTexCoord = 2; typedef uint16_t kCRTTexCoordType;
static const int kCRTVertexOffsetOfLateral = 4; 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 */ #endif /* CRTFrame_h */