2 #include <msp/gl/extensions/arb_direct_state_access.h>
3 #include <msp/gl/extensions/arb_draw_instanced.h>
4 #include <msp/gl/extensions/ext_framebuffer_blit.h>
5 #include <msp/gl/extensions/ext_framebuffer_object.h>
6 #include <msp/gl/extensions/msp_clear_buffer.h>
11 #include "pipelinestate.h"
22 void Commands::use_pipeline(const PipelineState &ps)
27 void Commands::clear(const ClearValue *values)
29 const Framebuffer *target = pipeline_state->get_framebuffer();
31 throw invalid_operation("OpenGLCommands::clear");
33 if(!ARB_direct_state_access)
35 static Require _req(MSP_clear_buffer);
36 pipeline_state->apply();
40 for(FrameAttachment a: target->get_format())
42 if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT))
44 if(ARB_direct_state_access)
45 glClearNamedFramebufferfv(target->id, GL_DEPTH, 0, &values->depth_stencil.depth);
47 glClearBufferfv(GL_DEPTH, 0, &values->depth_stencil.depth);
49 else if(get_attach_point(a)==get_attach_point(STENCIL_ATTACHMENT))
51 if(ARB_direct_state_access)
52 glClearNamedFramebufferiv(target->id, GL_STENCIL, 0, &values->depth_stencil.stencil);
54 glClearBufferiv(GL_STENCIL, 0, &values->depth_stencil.stencil);
58 if(ARB_direct_state_access)
59 glClearNamedFramebufferfv(target->id, GL_COLOR, i++, &values->color.r);
61 glClearBufferfv(GL_COLOR, i++, &values->color.r);
67 void Commands::draw(const Batch &batch)
69 pipeline_state->apply();
70 void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
71 glDrawElements(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr);
74 void Commands::draw_instanced(const Batch &batch, unsigned count)
76 static Require req(ARB_draw_instanced);
78 pipeline_state->apply();
79 void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
80 glDrawElementsInstanced(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr, count);
83 void Commands::resolve_multisample(Framebuffer &target, BufferBits buffers)
85 static Require _req(EXT_framebuffer_blit);
87 const Framebuffer *source = pipeline_state->get_framebuffer();
89 unsigned width = min(source->get_width(), target.get_width());
90 unsigned height = min(source->get_height(), target.get_height());
92 if(ARB_direct_state_access)
93 glBlitNamedFramebuffer(source->id, target.id, 0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
96 glBindFramebuffer(GL_READ_FRAMEBUFFER, source->id);
97 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target.id);
101 glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
103 glBindFramebuffer(GL_FRAMEBUFFER, source->id);