2 #include <msp/gl/extensions/arb_direct_state_access.h>
3 #include <msp/gl/extensions/arb_draw_instanced.h>
4 #include <msp/gl/extensions/arb_occlusion_query.h>
5 #include <msp/gl/extensions/ext_framebuffer_blit.h>
6 #include <msp/gl/extensions/ext_framebuffer_object.h>
7 #include <msp/gl/extensions/msp_clear_buffer.h>
12 #include "pipelinestate.h"
24 void Commands::use_pipeline(const PipelineState *ps)
28 PipelineState::clear();
31 void Commands::clear(const ClearValue *values)
33 const Framebuffer *target = pipeline_state->get_framebuffer();
35 throw invalid_operation("OpenGLCommands::clear");
37 if(!ARB_direct_state_access)
39 static Require _req(MSP_clear_buffer);
40 pipeline_state->apply();
44 for(FrameAttachment a: target->get_format())
46 if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT))
48 if(ARB_direct_state_access)
49 glClearNamedFramebufferfv(target->id, GL_DEPTH, 0, &values->depth_stencil.depth);
51 glClearBufferfv(GL_DEPTH, 0, &values->depth_stencil.depth);
53 else if(get_attach_point(a)==get_attach_point(STENCIL_ATTACHMENT))
55 if(ARB_direct_state_access)
56 glClearNamedFramebufferiv(target->id, GL_STENCIL, 0, &values->depth_stencil.stencil);
58 glClearBufferiv(GL_STENCIL, 0, &values->depth_stencil.stencil);
62 if(ARB_direct_state_access)
63 glClearNamedFramebufferfv(target->id, GL_COLOR, i++, &values->color.r);
65 glClearBufferfv(GL_COLOR, i++, &values->color.r);
71 void Commands::draw(const Batch &batch)
73 pipeline_state->apply();
74 void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
75 glDrawElements(batch.gl_prim_type, batch.size(), batch.gl_index_type, data_ptr);
78 void Commands::draw_instanced(const Batch &batch, unsigned count)
80 static Require req(ARB_draw_instanced);
82 pipeline_state->apply();
83 void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
84 glDrawElementsInstanced(batch.gl_prim_type, batch.size(), batch.gl_index_type, data_ptr, count);
87 void Commands::resolve_multisample(Framebuffer &target)
89 static Require _req(EXT_framebuffer_blit);
91 const Framebuffer *source = pipeline_state->get_framebuffer();
93 unsigned width = min(source->get_width(), target.get_width());
94 unsigned height = min(source->get_height(), target.get_height());
95 unsigned buffers = get_gl_buffer_bits(source->get_format())&get_gl_buffer_bits(target.get_format());
97 if(ARB_direct_state_access)
98 glBlitNamedFramebuffer(source->id, target.id, 0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
101 glBindFramebuffer(GL_READ_FRAMEBUFFER, source->id);
102 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target.id);
106 glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
108 glBindFramebuffer(GL_FRAMEBUFFER, source->id);
112 void Commands::begin_query(const QueryPool &pool, unsigned index)
114 if(index>=pool.queries.size())
115 throw out_of_range("OpenGLCommands::begin_query");
116 glBeginQuery(pool.gl_type, pool.queries[index]);
119 void Commands::end_query(const QueryPool &pool, unsigned)
121 glEndQuery(pool.gl_type);