Difference between revisions of "Platform specifics: Linux"
Line 152: | Line 152: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
/* | /* | ||
+ | MIT License | ||
+ | Copyright (c) 2015 Alex Cham | ||
+ | |||
+ | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
+ | this software and associated documentation files (the "Software"), to deal in | ||
+ | the Software without restriction, including without limitation the rights to | ||
+ | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
+ | of the Software, and to permit persons to whom the Software is furnished to do | ||
+ | so, subject to the following conditions: | ||
+ | |||
+ | The above copyright notice and this permission notice shall be included in all | ||
+ | copies or substantial portions of the Software. | ||
+ | |||
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
+ | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
+ | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
+ | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
+ | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
+ | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
+ | SOFTWARE. | ||
+ | |||
+ | |||
Very Dirty Code! Test Purposes Only! | Very Dirty Code! Test Purposes Only! | ||
Revision as of 21:02, 24 July 2015
This Section explains how to install Drivers to make OpenGL Programs run under Linux and how to use different Libraries/Toolkits to create Opengl Programs.
The standard OpenGL implementation used on Linux systems is Mesa3D. As of this writing, it provides implementations of OpenGL (up to version 3.0), as well as OpenGL ES, both versions 1.1 and 2.0. It includes a software-only implementation of the entire GL stack, but can also use hardware-specific drivers.
Mesa3D & DRI
Direct Rendering Infrastructure, also known as the DRI, is a framework for allowing direct access to graphics hardware under the X Window System in a safe and efficient manner. It includes changes to the X server, to several client libraries, and to the kernel (DRM, Direct Rendering Manager). The most important use for the DRI is to create fast OpenGL implementations providing hardware acceleration for Mesa. Several 3D accelerated drivers have been written to the DRI specification
http://dri.freedesktop.org/wiki/
DRIconf is a configuration applet for the Direct Rendering Infrastructure. It allows customizing performance and visual quality settings of OpenGL drivers on a per-driver, per-screen and/or per-application level. The settings are stored in system wide and per-user XML configuration files
http://dri.freedesktop.org/wiki/DriConf/ https://packages.debian.org/sid/all/driconf/filelist
- DRI libgl1-mesa-dri
- /etc/drirc
- /usr/lib/x86_64-linux-gnu/dri/i915_dri.so
- /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
- /usr/lib/x86_64-linux-gnu/dri/kms_swrast_dri.so
- /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so
- /usr/lib/x86_64-linux-gnu/dri/nouveau_vieux_dri.so
- /usr/lib/x86_64-linux-gnu/dri/r200_dri.so
- /usr/lib/x86_64-linux-gnu/dri/r300_dri.so
- /usr/lib/x86_64-linux-gnu/dri/r600_dri.so
- /usr/lib/x86_64-linux-gnu/dri/radeon_dri.so
- /usr/lib/x86_64-linux-gnu/dri/radeonsi_dri.so
- /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
- /usr/lib/x86_64-linux-gnu/dri/vmwgfx_dri.so
- /usr/share/bug/libgl1-mesa-dri/control
- /usr/share/bug/libgl1-mesa-dri/script
- /usr/share/doc/libgl1-mesa-dri/changelog.Debian.gz
- /usr/share/doc/libgl1-mesa-dri/copyright
- /usr/share/lintian/overrides/libgl1-mesa-dri
https://packages.debian.org/sid/amd64/libgl1-mesa-dri/filelist
Mesa3D & GLX
- OpenGL application on X Windows must use GLX, a standardized API, to set up a rendering context;
- GLX API is closely coupled with Xlib;
- OpenGL library also provides the GLX API implementation;
- GLX system has two roles, it communicates with the X server and initializes client-side and hardware state. The GLX client-server communication takes place using a standardized GLX wire protocol, which is an extension to the X network protocol;
- GLX library abstracts all client-side and hardware initialization and the internals of the process are hidden in the OpenGL implementation library;
- GLX API is specified in terms of Xlib, the glX functions use Xlib Displays, Windows, Visuals, etc. The GLX implementations are also built using Xlib;
http://xcb.freedesktop.org/opengl/
glxinfo is a command-line tool that can help you diagnose problems with your 3D acceleration setup
http://dri.freedesktop.org/wiki/glxinfo/ https://packages.debian.org/sid/amd64/mesa-utils/filelist
- GLX libgl1-mesa-glx
- /usr/lib/x86_64-linux-gnu/libGL.so.1
- /usr/lib/x86_64-linux-gnu/libGL.so.1.2.0
- /usr/share/bug/libgl1-mesa-glx/control
- /usr/share/bug/libgl1-mesa-glx/script
- /usr/share/doc/libgl1-mesa-glx/changelog.Debian.gz
- /usr/share/doc/libgl1-mesa-glx/copyright
- /usr/share/lintian/overrides/libgl1-mesa-glx
https://packages.debian.org/sid/amd64/libgl1-mesa-glx/filelist
OpenGL ABI (Headers, Datatypes, Libraries)
- ABI (Application Binary Interface) and runtime environment for applications using OpenGL under X11 on Linux enable applications using the OpenGL API for rendering to run on a variety of underlying implementations transparently. The intent is to address all of open source, commercial closed binary, OpenGL SI-based, and Mesa-based implementations.
- SDK for developing apps using OpenGL. This includes header file locations, conventions for use of extensions, etc.
https://www.opengl.org/registry/ABI/
Some Linux distributions may include support for hardware acceleration. Also, some GPUs have Open Source drivers developed by the community even though a closed source driver may be available from the manufacturer.
EGL, XCB, GL* & Forget About Xlib
Prerequisites
/usr/lib/x86_64-linux-gnu/libEGL.so.1 /usr/lib/x86_64-linux-gnu/libEGL.so.1.0.0 /usr/share/bug/libegl1-mesa/control /usr/share/bug/libegl1-mesa/script /usr/share/doc/libegl1-mesa/changelog.Debian.gz /usr/share/doc/libegl1-mesa/copyright /usr/share/lintian/overrides/libegl1-mesa
https://packages.debian.org/sid/amd64/libegl1-mesa/filelist
/usr/include/EGL/egl.h /usr/include/EGL/eglext.h /usr/include/EGL/eglextchromium.h /usr/include/EGL/eglmesaext.h /usr/include/EGL/eglplatform.h /usr/include/KHR/khrplatform.h /usr/lib/x86_64-linux-gnu/libEGL.so /usr/lib/x86_64-linux-gnu/libwayland-egl.so /usr/lib/x86_64-linux-gnu/pkgconfig/egl.pc /usr/lib/x86_64-linux-gnu/pkgconfig/wayland-egl.pc /usr/share/bug/libegl1-mesa-dev/control /usr/share/bug/libegl1-mesa-dev/script /usr/share/doc/libegl1-mesa-dev/changelog.Debian.gz /usr/share/doc/libegl1-mesa-dev/copyright
https://packages.debian.org/sid/amd64/libegl1-mesa-dev/filelist
/usr/lib/x86_64-linux-gnu/libGLESv2.so.2 /usr/lib/x86_64-linux-gnu/libGLESv2.so.2.0.0 /usr/share/bug/libgles2-mesa/control /usr/share/bug/libgles2-mesa/script /usr/share/doc/libgles2-mesa/changelog.Debian.gz /usr/share/doc/libgles2-mesa/copyright /usr/share/lintian/overrides/libgles2-mesa
https://packages.debian.org/sid/amd64/libgles2-mesa/filelist
/usr/include/GLES2/gl2.h /usr/include/GLES2/gl2ext.h /usr/include/GLES2/gl2platform.h /usr/include/GLES3/gl3.h /usr/include/GLES3/gl31.h /usr/include/GLES3/gl3ext.h /usr/include/GLES3/gl3platform.h /usr/lib/x86_64-linux-gnu/libGLESv2.so /usr/lib/x86_64-linux-gnu/pkgconfig/glesv2.pc /usr/share/bug/libgles2-mesa-dev/control /usr/share/bug/libgles2-mesa-dev/script /usr/share/doc/libgles2-mesa-dev/changelog.Debian.gz /usr/share/doc/libgles2-mesa-dev/copyright
https://packages.debian.org/sid/amd64/libgles2-mesa-dev/filelist
Source Code
/*
MIT License
Copyright (c) 2015 Alex Cham
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Very Dirty Code! Test Purposes Only!
Why XCB?
X protocol C-language Binding (XCB) is a replacement for Xlib
http://xcb.freedesktop.org/
Basic Graphics Programming With The XCB Library
http://www.x.org/releases/X11R7.6/doc/libxcb/tutorial/index.html
Introduction to managing client API rendering through the EGL API.
https://www.khronos.org/registry/egl/sdk/docs/man/html/eglIntro.xhtml
Linking
Invoking: GCC C++ Linker
g++ -o "EGL14XCBGLES20MakeCurrentContext" ./src/EGL14XCBGLES20MakeCurrentContext.o -lxcb -lEGL -lGLESv2
See Also:
Documentation for the X Window System
http://www.x.org/releases/X11R7.6/doc/
*/
#include <stdlib.h>
//
#include <EGL/egl.h>
#include <GLES2/gl2.h>
//
#include <xcb/xcb.h>
xcb_window_t makeXcbWindow(uint16_t width, uint16_t height,
xcb_visualid_t eglConfAttrVisualID) {
xcb_connection_t *c;
xcb_screen_t *screen;
xcb_window_t win;
/* Open the connection to the X server */
c = xcb_connect(NULL, NULL);
/* Get the first screen */
screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
/* Ask for our window's Id */
win = xcb_generate_id(c);
/* Create the window */
xcb_create_window(c,
XCB_COPY_FROM_PARENT, win, screen->root, 0, 0, width, height, 10,
XCB_WINDOW_CLASS_INPUT_OUTPUT, eglConfAttrVisualID, 0,
NULL);
/* Map the window on the screen */
xcb_map_window(c, win);
/* Make sure commands are sent before we pause, so window is shown */
xcb_flush(c);
return win;
}
int main(int argc, char ** argv) {
//@FIXME Black screen & cursor problems sometimes...
/* get an EGL display connection */
EGLDisplay display;
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
/* initialize the EGL display connection */
eglInitialize(display, NULL, NULL);
/* get an appropriate EGL frame buffer configuration */
/*
All attributes in attrib_list, including boolean attributes, are immediately
followed by the corresponding desired value. The list is terminated with EGL_NONE
https://www.khronos.org/registry/egl/sdk/docs/man/html/eglChooseConfig.xhtml
*/
static EGLint const attribute_list[] = {
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_NONE };
EGLConfig config;
EGLint num_config;
eglChooseConfig(display, attribute_list, &config, 1, &num_config);
/* create an EGL rendering context */
/*
#define EGL_OPENGL_ES_API 0x30A0
#define EGL_OPENVG_API 0x30A1
#define EGL_OPENGL_API 0x30A2
*/
eglBindAPI(EGL_OPENGL_ES_API);
/*
eglCreateContext — create a new EGL rendering context
attrib_list specifies a list of attributes for the context.
The list has the same structure as described for eglChooseConfig
https://www.khronos.org/registry/egl/sdk/docs/man/html/eglCreateContext.xhtml
*/
static const EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE };
EGLContext context;
context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attribs);
//Request eglVisualID for native window
EGLint eglConfAttrVisualID;
if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID,
&eglConfAttrVisualID)) {
//printf("Error: eglGetConfigAttrib() failed\n");
exit(1);
}
///////////////////////////////////////////////////////////////////////////////
/* create a native window */
//native_window = createNativeWindow();
uint16_t width = 640;
uint16_t height = 480;
NativeWindowType nativeWindow;
nativeWindow = makeXcbWindow(width, height,
(xcb_visualid_t) eglConfAttrVisualID);
///////////////////////////////////////////////////////////////////////////////
/* create an EGL window surface */
EGLSurface surface;
surface = eglCreateWindowSurface(display, config, nativeWindow, NULL);
/* connect the context to the surface */
eglMakeCurrent(display, surface, surface, context);
/* clear the color buffer */
while (1) {
glViewport(0, 0, (GLsizei) width, (GLsizei) height);
glClearColor(0., 0., 1., 0.);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
eglSwapBuffers(display, surface);
}
return EXIT_SUCCESS;
}