1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 18:30:21 +00:00

Started making first moves towards stripping CSCathodeRayView of its responsibilities. If that can be merely an OpenGL view that presents things, things will be a lot more portable.

This commit is contained in:
Thomas Harte 2016-01-20 08:21:33 -05:00
parent 280a2292ff
commit f727582911
3 changed files with 47 additions and 18 deletions

View File

@ -228,7 +228,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
BOOL hadFrame = _crtFrame ? YES : NO;
_crtFrame = crtFrame;
glBufferData(GL_ARRAY_BUFFER, _crtFrame->number_of_runs * kCRTSizeOfVertex * 6, _crtFrame->runs, GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(_crtFrame->number_of_vertices * _crtFrame->size_per_vertex), _crtFrame->vertices, GL_DYNAMIC_DRAW);
glBindTexture(GL_TEXTURE_2D, _textureName);
if(_textureSize.width != _crtFrame->size.width || _textureSize.height != _crtFrame->size.height)
@ -512,7 +512,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
if (_crtFrame)
{
if(_textureSizeUniform >= 0) glUniform2f(_textureSizeUniform, _crtFrame->size.width, _crtFrame->size.height);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)(_crtFrame->number_of_runs*6));
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)_crtFrame->number_of_vertices);
}
CGLFlushDrawable([[self openGLContext] CGLContextObj]);

View File

@ -15,6 +15,18 @@ using namespace Outputs;
static const uint32_t kCRTFixedPointRange = 0xf7ffffff;
static const uint32_t kCRTFixedPointOffset = 0x04000000;
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;
#define kRetraceXMask 0x01
#define kRetraceYMask 0x02
@ -394,6 +406,8 @@ CRTFrameBuilder::CRTFrameBuilder(uint16_t width, uint16_t height, unsigned int n
frame.size.height = height;
frame.number_of_buffers = number_of_buffers;
frame.buffers = new CRTBuffer[number_of_buffers];
frame.size_per_vertex = kCRTSizeOfVertex;
frame.geometry_mode = CRTGeometryModeTriangles;
for(int buffer = 0; buffer < number_of_buffers; buffer++)
{
@ -413,7 +427,7 @@ CRTFrameBuilder::~CRTFrameBuilder()
void CRTFrameBuilder::reset()
{
frame.number_of_runs = 0;
frame.number_of_vertices = 0;
_next_write_x_position = _next_write_y_position = 0;
frame.dirty_size.width = 0;
frame.dirty_size.height = 1;
@ -421,22 +435,21 @@ void CRTFrameBuilder::reset()
void CRTFrameBuilder::complete()
{
frame.runs = &_all_runs[0];
frame.vertices = &_all_runs[0];
}
uint8_t *CRTFrameBuilder::get_next_run()
{
const size_t vertices_per_run = 6;
const size_t size_of_run = kCRTSizeOfVertex * vertices_per_run;
// get a run from the allocated list, allocating more if we're about to overrun
if(frame.number_of_runs * size_of_run >= _all_runs.size())
if((frame.number_of_vertices + vertices_per_run) * frame.size_per_vertex >= _all_runs.size())
{
_all_runs.resize(_all_runs.size() + size_of_run * 200);
_all_runs.resize(_all_runs.size() + frame.size_per_vertex * vertices_per_run * 100);
}
uint8_t *next_run = &_all_runs[frame.number_of_runs * size_of_run];
frame.number_of_runs++;
uint8_t *next_run = &_all_runs[frame.number_of_vertices * frame.size_per_vertex];
frame.number_of_vertices += vertices_per_run;
return next_run;
}

View File

@ -22,21 +22,37 @@ typedef struct {
uint16_t width, height;
} CRTSize;
typedef struct {
CRTSize size, dirty_size;
typedef enum {
CRTGeometryModeTriangles
} CRTGeometryMode;
typedef struct {
/** The total size, in pixels, of the pixel buffer storage. Guaranteed to be a power of two. */
CRTSize size;
/** The portion of the pixel buffer that has been changed since the last time this set of buffers was provided. */
CRTSize dirty_size;
/** The number of individual buffers that adds up to the complete pixel buffer. */
unsigned int number_of_buffers;
/** A C array of those buffers. */
CRTBuffer *buffers;
unsigned int number_of_runs;
uint8_t *runs;
/** The number of vertices that constitute the output. */
unsigned int number_of_vertices;
/** The type of output. */
CRTGeometryMode geometry_mode;
/** The size of each vertex in bytes. */
size_t size_per_vertex;
/** The vertex data. */
uint8_t *vertices;
} CRTFrame;
typedef uint16_t kCRTPositionType;
typedef uint16_t kCRTTexCoordType;
typedef uint8_t kCRTLateralType;
typedef uint8_t kCRTPhaseType;
// TODO: these should be private to whomever builds the shaders
static const size_t kCRTVertexOffsetOfPosition = 0;
static const size_t kCRTVertexOffsetOfTexCoord = 4;
static const size_t kCRTVertexOffsetOfLateral = 8;