mirror of
https://github.com/TomHarte/CLK.git
synced 2024-10-07 21:57:46 +00:00
Some cleaning.
This commit is contained in:
parent
0d27d3bb7f
commit
c8ecfb89d8
@ -91,8 +91,8 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
|||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer);
|
||||||
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, buffer_size, NULL, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, InputVertexBufferDataSize, NULL, GL_STREAM_DRAW);
|
||||||
_output_buffer_data = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, buffer_size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
_output_buffer_data = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, InputVertexBufferDataSize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||||
_output_buffer_data_pointer = 0;
|
_output_buffer_data_pointer = 0;
|
||||||
glBindVertexArray(output_vertex_array);
|
glBindVertexArray(output_vertex_array);
|
||||||
prepare_output_vertex_array();
|
prepare_output_vertex_array();
|
||||||
@ -111,10 +111,6 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
|||||||
filteredTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight));
|
filteredTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
// glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *)&_openGL_state->defaultFramebuffer);
|
|
||||||
//
|
|
||||||
// printf("%d", glIsFramebuffer(_openGL_state->defaultFramebuffer));
|
|
||||||
|
|
||||||
// lock down any further work on the current frame
|
// lock down any further work on the current frame
|
||||||
_output_mutex->lock();
|
_output_mutex->lock();
|
||||||
|
|
||||||
@ -159,81 +155,50 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
|||||||
// glBindTexture(GL_TEXTURE_2D, _openGL_state->textureName);
|
// glBindTexture(GL_TEXTURE_2D, _openGL_state->textureName);
|
||||||
// glGetIntegerv(GL_VIEWPORT, results);
|
// glGetIntegerv(GL_VIEWPORT, results);
|
||||||
|
|
||||||
// ensure array buffer is up to date
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer);
|
|
||||||
// size_t max_number_of_vertices = 0;
|
|
||||||
// for(int c = 0; c < NumberOfFields; c++)
|
|
||||||
// {
|
|
||||||
// max_number_of_vertices = std::max(max_number_of_vertices, _run_builders[c]->number_of_vertices);
|
|
||||||
// }
|
|
||||||
// if(output_vertices_per_slice < max_number_of_vertices)
|
|
||||||
// {
|
|
||||||
// output_vertices_per_slice = max_number_of_vertices;
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(max_number_of_vertices * OutputVertexSize * OutputVertexSize), NULL, GL_STREAM_DRAW);
|
|
||||||
//
|
|
||||||
// for(unsigned int c = 0; c < NumberOfFields; c++)
|
|
||||||
// {
|
|
||||||
// uint8_t *data = &_run_builders[c]->_runs[0];
|
|
||||||
// glBufferSubData(GL_ARRAY_BUFFER, (GLsizeiptr)(c * output_vertices_per_slice * OutputVertexSize), (GLsizeiptr)(_run_builders[c]->number_of_vertices * OutputVertexSize), data);
|
|
||||||
// _run_builders[c]->uploaded_vertices = _run_builders[c]->number_of_vertices;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// switch to the output shader
|
// switch to the output shader
|
||||||
if(rgb_shader_program)
|
if(rgb_shader_program)
|
||||||
{
|
{
|
||||||
rgb_shader_program->bind();
|
rgb_shader_program->bind();
|
||||||
|
|
||||||
// update uniforms
|
// update uniforms
|
||||||
push_size_uniforms(output_width, output_height);
|
push_size_uniforms(output_width, output_height);
|
||||||
|
|
||||||
// Ensure we're back on the output framebuffer
|
// Ensure we're back on the output framebuffer
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
||||||
|
|
||||||
// clear the buffer
|
// clear the buffer
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// draw all sitting frames
|
// draw all sitting frames
|
||||||
unsigned int run = (unsigned int)_run_write_pointer;
|
unsigned int run = (unsigned int)_run_write_pointer;
|
||||||
// printf("%d: %zu v %zu\n", run, _run_builders[run]->uploaded_vertices, _run_builders[run]->number_of_vertices);
|
// printf("%d: %zu v %zu\n", run, _run_builders[run]->uploaded_vertices, _run_builders[run]->number_of_vertices);
|
||||||
GLint total_age = 0;
|
GLint total_age = 0;
|
||||||
for(int c = 0; c < NumberOfFields; c++)
|
for(int c = 0; c < NumberOfFields; c++)
|
||||||
{
|
|
||||||
// update the total age at the start of this set of runs
|
|
||||||
total_age += _run_builders[run]->duration;
|
|
||||||
|
|
||||||
if(_run_builders[run]->number_of_vertices > 0)
|
|
||||||
{
|
{
|
||||||
glUniform1f(timestampBaseUniform, (GLfloat)total_age);
|
// update the total age at the start of this set of runs
|
||||||
|
total_age += _run_builders[run]->duration;
|
||||||
|
|
||||||
// if(_run_builders[run]->uploaded_vertices != _run_builders[run]->number_of_vertices)
|
if(_run_builders[run]->number_of_vertices > 0)
|
||||||
// {
|
|
||||||
// uint8_t *data = &_run_builders[run]->_runs[_run_builders[run]->uploaded_vertices * OutputVertexSize];
|
|
||||||
// glBufferSubData(GL_ARRAY_BUFFER,
|
|
||||||
// (GLsizeiptr)(((run * output_vertices_per_slice) + _run_builders[run]->uploaded_vertices) * OutputVertexSize),
|
|
||||||
// (GLsizeiptr)((_run_builders[run]->number_of_vertices - _run_builders[run]->uploaded_vertices) * OutputVertexSize), data);
|
|
||||||
// _run_builders[run]->uploaded_vertices = _run_builders[run]->number_of_vertices;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// draw this frame
|
|
||||||
// glDrawArrays(GL_TRIANGLE_STRIP, (GLint)(run * output_vertices_per_slice), (GLsizei)_run_builders[run]->number_of_vertices);
|
|
||||||
|
|
||||||
GLsizei count = (GLsizei)_run_builders[run]->number_of_vertices;
|
|
||||||
GLsizei max_count = (GLsizei)((buffer_size - _run_builders[run]->start) / InputVertexSize);
|
|
||||||
if(count < max_count)
|
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, (GLint)(_run_builders[run]->start / InputVertexSize), count);
|
glUniform1f(timestampBaseUniform, (GLfloat)total_age);
|
||||||
}
|
|
||||||
else
|
// draw this frame
|
||||||
{
|
GLsizei count = (GLsizei)_run_builders[run]->number_of_vertices;
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, (GLint)(_run_builders[run]->start / InputVertexSize), max_count);
|
GLsizei max_count = (GLsizei)((InputVertexBufferDataSize - _run_builders[run]->start) / InputVertexSize);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, count - max_count);
|
if(count < max_count)
|
||||||
|
{
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, (GLint)(_run_builders[run]->start / InputVertexSize), count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, (GLint)(_run_builders[run]->start / InputVertexSize), max_count);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, count - max_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// advance back in time
|
||||||
|
run = (run - 1 + NumberOfFields) % NumberOfFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance back in time
|
|
||||||
run = (run - 1 + NumberOfFields) % NumberOfFields;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_output_mutex->unlock();
|
_output_mutex->unlock();
|
||||||
|
@ -47,7 +47,8 @@ const int InputBufferBuilderHeight = 1024;
|
|||||||
const int IntermediateBufferWidth = 2048;
|
const int IntermediateBufferWidth = 2048;
|
||||||
const int IntermediateBufferHeight = 2048;
|
const int IntermediateBufferHeight = 2048;
|
||||||
|
|
||||||
const GLsizeiptr buffer_size = (GLsizeiptr)(312 * 6 * 6 * OutputVertexSize);
|
// Some internal
|
||||||
|
const GLsizeiptr InputVertexBufferDataSize = 256 * 1024;
|
||||||
|
|
||||||
|
|
||||||
// Runs are divided discretely by vertical syncs in order to put a usable bounds on the uniform used to track
|
// Runs are divided discretely by vertical syncs in order to put a usable bounds on the uniform used to track
|
||||||
@ -139,7 +140,7 @@ class OpenGLOutputBuilder {
|
|||||||
|
|
||||||
inline uint8_t *get_next_input_run()
|
inline uint8_t *get_next_input_run()
|
||||||
{
|
{
|
||||||
if (_output_buffer_data_pointer + 6 * InputVertexSize > buffer_size) _output_buffer_data_pointer = 0;
|
if (_output_buffer_data_pointer + 6 * InputVertexSize > InputVertexBufferDataSize) _output_buffer_data_pointer = 0;
|
||||||
uint8_t *pointer = &_output_buffer_data[_output_buffer_data_pointer];
|
uint8_t *pointer = &_output_buffer_data[_output_buffer_data_pointer];
|
||||||
_output_buffer_data_pointer += 6 * InputVertexSize;
|
_output_buffer_data_pointer += 6 * InputVertexSize;
|
||||||
return pointer;
|
return pointer;
|
||||||
|
Loading…
Reference in New Issue
Block a user