- Setup Contexts to pull more info from the GPU
- Started outlining OpenGL implementation
This commit is contained in:
@@ -16,11 +16,14 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/fproc/filesystem/file.h>
|
||||
#include <fennec/lang/startup.h>
|
||||
#include <fennec/platform/interface/display.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
#include <fennec/platform/opengl/egl/context.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
@@ -39,22 +42,15 @@ STATIC_CONSTRUCTOR(_egl_init) {
|
||||
eglcontext::eglcontext(display* display)
|
||||
: gfxcontext(display, "EGL", this) {
|
||||
|
||||
// Get the display format
|
||||
const display::pixel_format& fmt = _display->get_color_format();
|
||||
|
||||
// Currently empty
|
||||
EGLint context_attrs[] = {
|
||||
#if FENNEC_GRAPHICS_OPENGL
|
||||
EGL_CONTEXT_MAJOR_VERSION, 4,
|
||||
EGL_CONTEXT_MINOR_VERSION, 3,
|
||||
#elif FENNEC_GRAPHICS_GLES3
|
||||
EGL_CONTEXT_MAJOR_VERSION, 3,
|
||||
EGL_CONTEXT_MINOR_VERSION, 2,
|
||||
#elif FENNEC_GRAPHICS_GLES2
|
||||
EGL_CONTEXT_MAJOR_VERSION, 2,
|
||||
EGL_CONTEXT_MINOR_VERSION, 0,
|
||||
#endif
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
// Configure the depth and rgb bit-depth
|
||||
EGLint config_attrs[] = {
|
||||
EGL_SURFACE_TYPE,
|
||||
EGL_WINDOW_BIT,
|
||||
@@ -62,50 +58,59 @@ eglcontext::eglcontext(display* display)
|
||||
EGL_RED_SIZE, fmt.r,
|
||||
EGL_RED_SIZE, fmt.g,
|
||||
EGL_RED_SIZE, fmt.b,
|
||||
EGL_RENDERABLE_TYPE,
|
||||
|
||||
#if FENNEC_GRAPHICS_OPENGL
|
||||
EGL_OPENGL_BIT,
|
||||
#elif FENNEC_GRAPHICS_GLES3
|
||||
EGL_OPENGL_ES3_BIT,
|
||||
#elif FENNEC_GRAPHICS_GLES2
|
||||
EGL_OPENGL_ES2_BIT,
|
||||
#endif
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_BIT, // 7
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
|
||||
// Attempt to retrieve an egl display from the native display
|
||||
_egldisplay = eglGetDisplay(_display->get_native_handle());
|
||||
if (_egldisplay == nullptr) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
if (not eglInitialize(_egldisplay, &_eglvmajor, &_eglvminor)) {
|
||||
// Attempt to initialize egl
|
||||
if (not eglInitialize(_egldisplay, nullptr, nullptr)) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
#if FENNEC_GRAPHICS_OPENGL
|
||||
// Attempt to bind to Core OpenGL, otherwise OpenGL ES
|
||||
if (not eglBindAPI(EGL_OPENGL_API)) {
|
||||
#elif FENNEC_GRAPHICS_GLES3 or FENNEC_GRAPHICS_GLES2
|
||||
if (not eglBindAPI(EGL_OPENGL_ES_API)) {
|
||||
#endif
|
||||
cleanup();
|
||||
return;
|
||||
if (not eglBindAPI(EGL_OPENGL_ES_API)) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
config_attrs[7] = EGL_OPENGL_ES_BIT; // Change the support bit to OpenGL ES
|
||||
}
|
||||
|
||||
// Select a configuration
|
||||
EGLint n;
|
||||
if (not eglChooseConfig(_egldisplay, config_attrs, &_eglconfig, 1, &n)) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the context
|
||||
_eglcontext = eglCreateContext(_egldisplay, _eglconfig, EGL_NO_CONTEXT, context_attrs);
|
||||
if (_eglcontext == nullptr) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// make this the current context so we can retrieve the information below
|
||||
eglMakeCurrent(_egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, _eglcontext);
|
||||
|
||||
// Query available extensions
|
||||
const char* ptr = eglQueryString(_egldisplay, EGL_EXTENSIONS);
|
||||
_extensions = { ptr, strlen(ptr) + 1 };
|
||||
|
||||
// Query the context and version
|
||||
eglQueryContext(_egldisplay, _eglcontext, EGL_CONTEXT_CLIENT_TYPE, &_eglctype);
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &_eglvmajor);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &_eglvminor);
|
||||
}
|
||||
|
||||
eglcontext::~eglcontext() {
|
||||
@@ -116,6 +121,22 @@ bool eglcontext::connected() {
|
||||
return _eglcontext != nullptr;
|
||||
}
|
||||
|
||||
const cstring& eglcontext::get_context_name() {
|
||||
static constexpr cstring opengl = "OpenGL";
|
||||
static constexpr cstring gles = "GLES";
|
||||
static constexpr cstring openvg = "OpenVG"; // this should never be used
|
||||
switch (_eglctype) {
|
||||
default:
|
||||
case EGL_OPENGL_API: return opengl;
|
||||
case EGL_OPENGL_ES_API: return gles;
|
||||
case EGL_OPENVG_API: return openvg;
|
||||
}
|
||||
}
|
||||
|
||||
bool eglcontext::check_extension(const cstring& ext) {
|
||||
return _extensions.find(ext) != _extensions.size();
|
||||
}
|
||||
|
||||
void eglcontext::make_current(gfxsurface*) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user