Mondschein Engine  0.3.0
visual.cpp
1 /* Mondschein Engine is a fast, powerful, and easy-to-use 3D realtime rendering engine.
2  *
3  * Copyright (C) 2009-2013 by Andreas Amereller
4  * E-Mail: andreas.amereller.dev@googlemail.com
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "wxwidgets/visual.h"
22 
23 using namespace mondschein;
24 using namespace display;
25 
26 wx_Visual::wx_Visual() : Visual::Visual(), renderer::Context(), visual(), wxcontext()
27 {
28  return;
29 }
30 
31 wx_Visual::wx_Visual(const visual_attribs_t &_dsp,const renderer::context_attribs_t &_c,renderer::Renderer_p _r) :
32  Visual(_dsp,renderer::Context_p()), renderer::Context(_c,_r), visual(), wxcontext()
33 {
34  return;
35 }
36 
37 wx_Visual::~wx_Visual()
38 {
39  if (visual!=nullptr) delete visual;
40  if (wxcontext!=nullptr) delete wxcontext;
41  return;
42 }
43 
45 {
47  renderer::context_attribs_t cxt=renderer::Context::get_data();
48  std::array<int32,27> attriblist;
49  attriblist.at(0)=WX_GL_RGBA; attriblist.at(1)=1;
50  attriblist.at(2)=WX_GL_LEVEL; attriblist.at(3)=0;
51  attriblist.at(4)=WX_GL_DOUBLEBUFFER; attriblist.at(5)=cxt.doublebuffer;
52  attriblist.at(6)=WX_GL_MIN_RED; attriblist.at(7)=cxt.color_depth(0);
53  attriblist.at(8)=WX_GL_MIN_GREEN; attriblist.at(9)=cxt.color_depth(1);
54  attriblist.at(10)=WX_GL_MIN_BLUE; attriblist.at(11)=cxt.color_depth(2);
55  attriblist.at(12)=WX_GL_MIN_ALPHA; attriblist.at(13)=cxt.color_depth(3);
56  attriblist.at(14)=WX_GL_DEPTH_SIZE; attriblist.at(15)=cxt.depth_buffer_size;
57  attriblist.at(16)=WX_GL_STENCIL_SIZE; attriblist.at(17)=cxt.stencil_buffer_size;
58  attriblist.at(18)=WX_GL_MIN_ACCUM_RED; attriblist.at(19)=cxt.accum_depth(0);
59  attriblist.at(20)=WX_GL_MIN_ACCUM_GREEN; attriblist.at(21)=cxt.accum_depth(1);
60  attriblist.at(22)=WX_GL_MIN_ACCUM_BLUE; attriblist.at(23)=cxt.accum_depth(2);
61  attriblist.at(24)=WX_GL_MIN_ACCUM_ALPHA; attriblist.at(25)=cxt.accum_depth(3);
62  attriblist.at(26)=0;
63  visual=new wxGLCanvas(0,wxID_ANY,attriblist.data(),wxDefaultPosition,wxSize(dsp.width,dsp.height));
64  wxcontext=new wxGLContext(visual);
65  visual->SetCurrent(*wxcontext);
66  return;
67 }
68 
70 {
71  if (visual!=nullptr) delete visual;
72  init();
73  return;
74 }
75 
77 {
78  visual->SwapBuffers();
79 }