mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-25 16:31:42 +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:
parent
5644b3a1cc
commit
67e82c713f
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -26,12 +26,12 @@ struct CRTFrameBuilder {
|
||||
~CRTFrameBuilder();
|
||||
|
||||
private:
|
||||
std::vector<uint16_t> _all_runs;
|
||||
std::vector<uint8_t> _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);
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user