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)
26 PipelineState::clear();
29 void Commands::clear(const ClearValue *values)
31 const Framebuffer *target = pipeline_state->get_framebuffer();
33 throw invalid_operation("OpenGLCommands::clear");
35 if(!ARB_direct_state_access)
37 static Require _req(MSP_clear_buffer);
38 pipeline_state->apply();
42 for(FrameAttachment a: target->get_format())
44 if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT))
46 if(ARB_direct_state_access)
47 glClearNamedFramebufferfv(target->id, GL_DEPTH, 0, &values->depth_stencil.depth);
49 glClearBufferfv(GL_DEPTH, 0, &values->depth_stencil.depth);
51 else if(get_attach_point(a)==get_attach_point(STENCIL_ATTACHMENT))
53 if(ARB_direct_state_access)
54 glClearNamedFramebufferiv(target->id, GL_STENCIL, 0, &values->depth_stencil.stencil);
56 glClearBufferiv(GL_STENCIL, 0, &values->depth_stencil.stencil);
60 if(ARB_direct_state_access)
61 glClearNamedFramebufferfv(target->id, GL_COLOR, i++, &values->color.r);
63 glClearBufferfv(GL_COLOR, i++, &values->color.r);
69 void Commands::draw(const Batch &batch)
71 pipeline_state->apply();
72 void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
73 glDrawElements(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr);
76 void Commands::draw_instanced(const Batch &batch, unsigned count)
78 static Require req(ARB_draw_instanced);
80 pipeline_state->apply();
81 void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
82 glDrawElementsInstanced(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr, count);
85 void Commands::resolve_multisample(Framebuffer &target)
87 static Require _req(EXT_framebuffer_blit);
89 const Framebuffer *source = pipeline_state->get_framebuffer();
91 unsigned width = min(source->get_width(), target.get_width());
92 unsigned height = min(source->get_height(), target.get_height());
93 unsigned buffers = get_gl_buffer_bits(source->get_format())&get_gl_buffer_bits(target.get_format());
95 if(ARB_direct_state_access)
96 glBlitNamedFramebuffer(source->id, target.id, 0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
99 glBindFramebuffer(GL_READ_FRAMEBUFFER, source->id);
100 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target.id);
104 glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
106 glBindFramebuffer(GL_FRAMEBUFFER, source->id);