2014-10-27 21:22:29 -04:00
|
|
|
#include "PrimaryGLContext.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CubicSDR.h"
|
2014-10-30 22:51:33 -04:00
|
|
|
#include "CubicSDRDefs.h"
|
2014-11-04 19:52:11 -05:00
|
|
|
#include "AppFrame.h"
|
2014-10-30 22:51:33 -04:00
|
|
|
#include <algorithm>
|
2014-11-09 04:38:33 -05:00
|
|
|
|
2014-12-08 02:16:06 -05:00
|
|
|
GLFont *PrimaryGLContext::font = NULL;
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
wxString PrimaryGLContext::glGetwxString(GLenum name) {
|
2014-10-27 21:22:29 -04:00
|
|
|
const GLubyte *v = glGetString(name);
|
|
|
|
if (v == 0) {
|
|
|
|
// The error is not important. It is GL_INVALID_ENUM.
|
|
|
|
// We just want to clear the error stack.
|
|
|
|
glGetError();
|
|
|
|
|
|
|
|
return wxString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxString((const char*) v);
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
void PrimaryGLContext::CheckGLError() {
|
2014-10-27 21:22:29 -04:00
|
|
|
GLenum errLast = GL_NO_ERROR;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
GLenum err = glGetError();
|
|
|
|
if (err == GL_NO_ERROR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (err == errLast) {
|
|
|
|
wxLogError
|
|
|
|
(wxT("OpenGL error state couldn't be reset."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errLast = err;
|
|
|
|
|
|
|
|
wxLogError
|
|
|
|
(wxT("OpenGL error %d"), err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext) :
|
|
|
|
wxGLContext(canvas, sharedContext) {
|
2014-10-27 21:22:29 -04:00
|
|
|
SetCurrent(*canvas);
|
|
|
|
|
|
|
|
CheckGLError();
|
|
|
|
}
|
|
|
|
|
2014-12-08 02:16:06 -05:00
|
|
|
GLFont *PrimaryGLContext::getFont() {
|
|
|
|
if (font == NULL) {
|
|
|
|
font = new GLFont();
|
|
|
|
font->loadFont("vera_sans_mono.fnt");
|
|
|
|
}
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|