]> git.tdb.fi Git - libs/gl.git/blob - source/core/commands.cpp
Fix a logic error in Sequence
[libs/gl.git] / source / core / commands.cpp
1 #include <algorithm>
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 "batch.h"
7 #include "commands.h"
8 #include "gl.h"
9 #include "pipelinestate.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GL {
15
16 Commands::Commands():
17         pipeline_state(0)
18 { }
19
20 void Commands::use_pipeline(const PipelineState &ps)
21 {
22         pipeline_state = &ps;
23 }
24
25 void Commands::clear(BufferBits buffers)
26 {
27         pipeline_state->apply();
28         glClear(buffers);
29 }
30
31 void Commands::draw(const Batch &batch)
32 {
33         pipeline_state->apply();
34         void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
35         glDrawElements(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr);
36 }
37
38 void Commands::draw_instanced(const Batch &batch, unsigned count)
39 {
40         static Require req(ARB_draw_instanced);
41
42         pipeline_state->apply();
43         void *data_ptr = reinterpret_cast<void *>(batch.get_offset());
44         glDrawElementsInstanced(batch.get_gl_primitive_type(), batch.size(), batch.get_gl_index_type(), data_ptr, count);
45 }
46
47 void Commands::resolve_multisample(Framebuffer &target, BufferBits buffers)
48 {
49         const Framebuffer *source = pipeline_state->get_framebuffer();
50
51         unsigned width = min(source->get_width(), target.get_width());
52         unsigned height = min(source->get_height(), target.get_height());
53
54         if(ARB_direct_state_access)
55                 glBlitNamedFramebuffer(source->get_id(), target.get_id(), 0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
56         else
57         {
58                 glBindFramebuffer(GL_READ_FRAMEBUFFER, source->get_id());
59                 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target.get_id());
60
61                 target.refresh();
62
63                 glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, buffers, GL_NEAREST);
64
65                 glBindFramebuffer(GL_FRAMEBUFFER, source->get_id());
66         }
67 }
68
69 } // namespace GL
70 } // namespace Msp