From 56e9efa15de5fdc952e56f04276285870214b24d Mon Sep 17 00:00:00 2001
From: Brian Paul Copyright © 2002-2003 by Tungsten Graphics, Inc., Cedar Park,
+Texas. All Rights Reserved. The Mini GLX interface facilitates OpenGL rendering on embedded
+devices. The interface is a subset of the GLX interface, plus a minimal
+set of Xlib-like functions. Programs written to the Mini GLX specification should run unchanged
+on systems with the X Window System and the GLX extension. The intention
+is to allow flexibility for prototyping and testing. This document serves as both the reference guide and programming
+guide for Mini GLX. The OpenGL specification does not describe how OpenGL rendering
+contexts and drawing surfaces (i.e. the frame buffer) are created and
+managed. Rather, this is handled by an OpenGL window system interface,
+such as Mini GLX. There are three main datatypes or resources managed by Mini GLX. The
+resources and their corresponding GLX or Xlib data types are: Pixel formats or X Visuals describe the per-pixel attributes of the
+frame buffer. For example, bits per color component, Z buffer size,
+stencil size, TrueColor vs PseudoColor, etc. Drawing surfaces or X Windows typically describe a spatial
+allocation of the frame buffer (i.e. the position and size of a
+rectangular region of pixels). Since MiniGLX doesn't really support a
+window system, the window is effectively the entire frame buffer. A rendering context represents the current OpenGL state such as
+current drawing color, line width, blending mode, texture parameters,
+etc. Several rendering contexts can be created but only one can be in
+use at any given time. The Mini GLX interface provides all the functions needed for
+choosing pixel formats, create drawing surfaces, creating rendering
+contexts and binding rendering contexts to drawing surfaces. To use the Mini GLX interface in your application, include the
+GL/miniglx.h header file at compile time: The XOpenDisplay function is used to initialize the graphics system: The If XOpenDisplay is able to initialize the graphics system a pointer
+to a Display will be returned. Otherwise, NULL will be returned. A visual (i.e. pixel format) must be chosen before a drawing surface
+or rendering context can be created. This is done with the
+glXChooseVisual function: glXChooseVisual will return a pointer to an XVisualInfo object which
+most closely matches the requirements of the attribute list. If there
+is no visual which matches the request, NULL will be returned. Note that visuals with accumulation buffers and depth buffers are
+not available. Drawing surfaces are created as X windows. For Mini GLX,
+windows are full-screen; they cover the entire frame buffer.
+ Also, Mini GLX imposes a limit of one window. A second window
+cannot be created until the first one is destroyed. The XCreateWindow function is used to create a drawing surface: The parameters are as follows: To display the window the XMapWindow function must be called: This function does nothing in Mini GLX but is required for Xlib/GLX
+compatibility Xlib requires specification of a colormap when creating a window.
+ For purposes of interoperability, Mini GLX requires this as well,
+though the colormap is not actually used. The XCreateColormap
+function is used to create a colormap: The parameters are as follows: An OpenGL rendering context is created with the The parameters are as follows: The final step before beginning OpenGL rendering is to bind (i.e.
+activate) a rendering context and drawing surface with the
+glXMakeCurrent function: The parameters are as follows: If glXMakeCurrent succeeds True is returned. Otherwise False is
+returned to indicate an invalid display, window or context parameter. After the rendering context has been bound to the drawing surface
+OpenGL rendering can begin. The current rendering context may be unbound by calling
+glXMakeCurrent with the window and context parameters set to zero. An application may create any number of rendering contexts and bind
+them as needed. Note that binding a rendering context is generally not a
+light-weight operation. Most simple OpenGL applications create
+only one rendering context. A double buffered window has two color buffers: a front buffer and a
+back buffer. Normally, rendering is directed to the back buffer while
+the front buffer is displayed. When rendering of a frame is finished
+the front and back buffers are swapped to provide the illusion of
+instanteous screen updates. The color buffers for a particular window (i.e. drawable) may be
+swapped with the glXSwapBuffers command: A rendering context may be destroyed by calling glXDestroyContext: A window may be destroyed by calling XDestroyWindow: An XVisualInfo object may be freed by calling XFree: A colormap may be freed by calling XFreeColormap: When the application is about to exit, the resources associated with
+the graphics system can be released by calling XCloseDisplay: The display handle becomes invalid at this point. The GLX attributes of an X visual may be queried with the
+glXGetConfig function: The parameters are as follows: The return value will be zero if no error occurs. The following attributes may be queried: The current rendering context can be queried with
+glXGetCurrentContext: Zero will be returned if no context is currently bound. The current drawable (i.e. window or drawing surface) can be queried
+with glXGetCurrentDrawable: Zero will be returned if no drawable is currently bound. The glXGetProcAddress function will return the address of any
+available OpenGL or Mini GLX function: If The purpose of glXGetProcAddress is to facilitate using future
+extensions to OpenGL or Mini GLX. If a future version of the library
+adds new extension functions they'll be accessible via
+glXGetProcAddress. The alternative is to hard-code calls to the new
+functions in the application but doing so will prevent linking the
+application with older versions of the library. At compile time, the Mini GLX interface version can be tested with
+the MINI_GLX_VERSION_1_x preprocessor tokens. For example, if
+version 1.0 of Mini GLX is supported, then At the time of writing the current Mini GLX version is 1.0. This section shows an example program which uses the Mini GLX
+interface. The program simply draws several frames of a rotating square. The program may be compiled for use with Xlib/GLX or Mini GLX by
+setting the
+The fbdev/DRI sub-project within Mesa brings hardware accelerated OpenGL
+rendering to the Linux fbdev environment.
+The X Window System / XFree86 is not needed.
+
+Basically, the DRI drivers for hardware
+accelerated OpenGL for XFree86 have been ported to fbdev so that X is
+not needed.
+This means fbdev/DRI works in full-screen mode only.
+
+DRI driver writers may find this simplified environment easier to work in,
+compared to the full XFree86/DRI environment.
+
+Much of the work for this project has been done by Jon Smirl and
+Keith Whitwell.
+
+To use fbdev/DRI, you'll need a Linux 2.4 or 2.6 kernel.
+
+The fbdev/DRI Mesa code is in the Mesa CVS trunk (to be released as Mesa
+5.1 in the future).
+
+Assuming you're starting with a fresh Mesa CVS checkout, do the following:
+
+When this is finished, check the
+If XFree86 is currently running, exit/stop the X server so you're
+working from the console.
+
+You'll need to load kernel modules specific to your graphics hardware.
+The following kernel modules should be included with your kernel.
+
+If you have ATI Radeon/R200 hardware, run as root:
+
+If you have ATI Rage 128 hardware, run as root:
+
+If you have Matrox G200/G400 hardware, run as root:
+
+Then run
+The
+Edit
+Make sure your LD_LIBRARY_PATH environment variable is set to the
+
+Change to the
+Then try running the
+You should see a rotating quadrilateral which changes color as it rotates.
+It will exit automatically after a bit.
+
+If you run other tests in the miniglx/ directory, you may want to run
+them from a remote shell so that you can stop them with ctrl-C.
+
+If you try to run miniglxtest and get the following:
+
+It means that the sample_server process is not running.
+
+The full OpenGL API is available with fbdev/DRI.
+
+OpenGL/Mesa is interfaced to fbdev via the MiniGLX
+interface.
+MiniGLX is a subset of Xlib and GLX API functions which provides just
+enough functionality to setup OpenGL rendering and respond to simple
+input events.
+
+Since MiniGLX is a subset of the usual Xlib and GLX APIs, programs written
+to the MiniGLX API can also be run on full Xlib/GLX implementations.
+This allows some degree of flexibility for software development and testing.
+
+
+
+
+
+
+January 20, 2003
+
+
+
+Permission is granted to make and distribute verbatim copies of this
+document provided the copyright notice and this permission notice are
+preserved on all copies.
+
+1. Introduction
+
+
+2. Mini GLX Concepts
+
+
+
+
+
+ Resource
+ Data type
+
+
+ pixel formats
+ X Visual and XVisualInfo
+
+
+ drawing surfaces
+ X Window or GLXDrawable
+
+
+
+rendering contexts
+ GLXContext
+
+
+3. Using Mini GLX
+
+ #include <GL/miniglx.h>
+ Applications should link with libGL.so (i.e. gcc
+myprogram.o -lGL -o myprogram). libGL.so implements the
+MiniGLX API functions and, in turn, loads a hardware-specific device
+driver (such as radeon_dri.so) at runtime. The
+environment variable LIBGL_DRIVERS_PATH should name the
+directory where these modules are located.
+
+Prior to running a MiniGXL application, the following kernel modules
+must be installed:
+
+
+radeonfb.o (assuming Radeon hardware)
+radeon.o (assuming Radeon hardware)
+
+Finally, MiniGLX reads a configuration file (by default,
+/etc/miniglx.conf) to determine basic configuration information.
+ The configuration file may also be located in the directory
+specified by the MINIGLX_CONF environment variable).
+
+The remainder of this section describes the MiniGLX API functions.
+
+3.1 Initialization
+
+
+Display *XOpenDisplay(const char *displayname)
+displayName parameter is currently ignored in Mini
+GLX. It is recommended that NULL be passed as thedisplayName
+parameter.3.2 Choosing a Visual
+
+
+XVisualInfo *glXChooseVisual(Display *dpy, int screen, const int *attribList)
+dpy is a pointer to the display returned by
+XOpenDisplay. screen is currently ignored by Mini GLX and should be
+zero. attribList is a list of GLX attributes which describe
+the desired pixel format. It is terminated by the token None.
+The attributes are as follows:
+
+
+
+GLX_USE_GLGLX_RGBAGLX_DOUBLEBUFFERGLX_RED_SIZE nGLX_GREEN_SIZE nGLX_BLUE_SIZE nGLX_ALPHA_SIZE nGLX_STENCIL_SIZE nNone
+
+3.3 Creating a Drawing Surface
+3.3.1 Window Creation
+
+
+Window XCreateWindow( Display *display,
+
Window parent,
int x, int y,
unsigned int width, unsigned int height,
unsigned int borderWidth,
int depth,
unsigned int class,
Visual *visual,
unsigned long valuemask,
XSetWindowAttributes *attributes )
+
+
+
+displayparentRootWindow(dpy, 0).x, ywidth, heightborderWidthdepthglxChooseVisual.classInputOutput.visualvisual field of the XVisualInfo
+object returned by glxChooseVisual.valuemaskXSetWindowAttributes
+are to be used. For Mini GLX this is typically the bitmaskCWBackPixel
+| CWBorderPixel | CWColormap.attributesXSetWindowAttributes
+structure, thebackground_pixel, border_pixel
+and colormap fields should be set. See the discussion
+below regarding colormaps.XCreateWindow will return a window handle if it succeeds
+or zero if it fails.3.3.2 Window Mapping
+
+
+void XMapWindow(Display *dpy, Window w)
+3.3.3 Colormaps
+
+
+Colormap XCreateColormap(Display *dpy, Window window,
+Visual *visual, int alloc)
+
+
+
+
+
+dpywindowRootWindow(dpy, 0) macro.
+ visualallocAllocNone.
+3.4 Creating a Rendering Context
+glXCreateContext
+function:
+
+GLXContext glXCreateContext(Display *dpy, XVisualInfo *visInfo, GLXContext shareList, Bool direct)
+
+
+
+
+dpyvisInfoshareListdirectTrue.glXCreateContext will return a GLXContext handle if it
+succeeds or zero if it fails due to invalid parameter or insufficient
+resources.
+
+3.5 Binding a Rendering Context
+
+
+Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
+
+
+
+
+dpydrawablectx
+
+3.6 Color Buffer Swapping
+
+
+Any pending rendering commands will be completed before the buffer swap
+takes place.void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
+
+
+Calling glXSwapBuffers on a window which is single-buffered has no
+effect.
+
+3.7 Releasing Resources
+3.7.1 Releasing Rendering Contexts
+
+
+void glXDestroyContext(Display *dpy, GLXContext ctx)
+3.7.2 Releasing Windows
+
+
+void XDestroyWindow(Display *dpy, Window window)
+3.7.3 Releasing Visuals
+
+
+void XFree(void *data)
+3.7.4 Releasing Colormaps
+
+
+void XFreeColormap(Display *dpy, Colormap colormap)
+3.7.4 Releasing Display Resources
+
+
+void XCloseDisplay(Display *dpy)
+
+
+3.8 Query Functions
+3.8.1 Querying Available Visuals
+A list of all available visuals can be obtained with the XGetVisualInfo
+function:
+
+XVisualInfo
+*XGetVisualInfo(Display *dpy, long vinfo_mask, XVisualInfo
+*vinfo_template, int *nitems_return)
+
+The parameters are as follows:
+
+
+The return value is the address of an array of all available visuals.
+
+dpyvinfo_maskvinfo_templatenitems_return
+
+An example of using XGetVisualInfo to get all available visuals follows:
+
+XVisualInfo visTemplate, *results;
+int numVisuals;
+Display *dpy = XOpenDisplay(NULL);
+visTemplate.screen = 0;
+results = XGetVisualInfo(dpy, VisualScreenMask, &visTemplate,
+&numVisuals);
+
+3.8.2 Querying Visual Attributes
+
+
+int glXGetConfig(Display *dpy, XVisualInfo *vis, int attribute, int *value)
+
+
+
+
+dpyvisattributevalue
+ GLX_INVALID_ATTRIBUTE will be returned if the attribute
+parameter is invalid. GLX_BAD_VISUAL will be returned
+if the XVisualInfo parameter is invalid.
+
+
+
+GLX_USE_GLTrue or False to
+indicate if OpenGL rendering is supported with the visual. Mini GLX
+always return True.GLX_RGBATrue for RGBA visuals or False
+for color index visuals.GLX_DOUBLEBUFFERTrue if the visual has two
+color buffers or False if the visual has one color buffer.GLX_RED_SIZEGLX_GREEN_SIZEGLX_BLUE_SIZEGLX_ALPHA_SIZEGLX_DEPTH_SIZEGLX_STENCIL_SIZE
+
+ 3.8.3 Querying the Current Rendering Context
+
+
+GLXContext glXGetCurrentContext(void)
+
+
+3.8.4 Querying the Current Drawable
+
+
+GLXDrawable glXGetCurrentDrawable(void)
+
+
+3.8.5 Function Address Queries
+
+
+void *glXGetProcAddress(const GLubyte *procName)
+procName is a valid function name, a pointer to that
+function will be returned. Otherwise, NULL will be returned.
+
+3.9 Versioning
+The Mini GLX version can be queried at run time with glXQueryVersion:
+
+
+Bool glXQueryVersion(Display *dpy, int *major, int *minor)
+major will be set to the major version number andminor
+will be set to the minor version number.True will be
+returned if the function succeeds. False will be returned
+if the function fails due to invalid parameters. The dpy
+argument is currently ignored, but should be the value returned by
+XOpenDisplay. MINI_GLX_VERSION_1_0
+will be defined. If version 1.1 of Mini GLX is supported, then
+MINI_GLX_VERSION_1_1 will be defined.
+
+4.0 Interoperability with GLX and Xlib
+While Mini GLX strives to be compatible with GLX and Xlib there are
+some unavoidable differences which must be taken into consideration.
+4.1 Public vs Private Structures
+The structure of many X data types is public. For example, the Display
+data type is defined as a structure in /usr/include/X11/Xlib.h and
+programmers may access any fields of that structure at will. Mini
+GLX also defines a Display data type but its fields are hidden and not
+visiblein miniglx.h. Duplicating the Xlib
+declaration for the Display data type in minigl.h would
+require defining a large number of other superfluous Xlib datatypes.
+
+Mini GLX users are discouraged from directly accessing the fields of
+Xlib data types to maximize portability - though this is unavoidable to
+some extent. For example, the XVisualInfo and XSetWindowAtttributes
+data types must be completely public.
+4.2 Macros
+In some cases, Xlib defines macros which are meant to be used instead
+of direct structure accesses. For example, the RootWindow(dpy,
+screen) macro returns the root window for a given screen on a
+given display. Unfortunately, macros do nothing to aid in ABI
+compatibility since they are resolved at compile time instead of at
+link/run time.
+
+Mini GLX also defines a RootWindow macro since it's
+essential for creating windows. But the implementation of this
+macro by Xlib and Mini GLX is completely different.
+4.3 Summary
+Because Xlib and Mini GLX define data types and macros differently,
+Mini GLX applications must be recompiled when retargeting Mini GLX or
+native Xlib/GLX. That is, applications can't simply be re-linked
+because of ABI incompatibilities.
+
+Nevertheless, the fact that Mini GLX programs can be recompiled for
+Xlib and GLX increases portability and flexibility for testing and
+prototyping.
+
+5.0 Example Program
+
+USE_MINIGLX token to 0 or 1, respectively.
+ Note that the only difference is the header files which are
+included.
+
+#define USE_MINIGLX 1 /* 1 = use Mini GLX, 0 = use Xlib/GLX */
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#if USE_MINIGLX
#include <GL/miniglx.h>
#else
#include <GL/glx.h>
#include <X11/Xlib.h>
#endif/*
* Create a simple double-buffered RGBA window.
*/
static Window
MakeWindow(Display * dpy, unsigned int width, unsigned int height)
{
int visAttributes[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None
};
XSetWindowAttributes attr;
unsigned long attrMask;
Window root;
Window win;
GLXContext ctx;
XVisualInfo *visinfo;
root = RootWindow(dpy, 0);
/* Choose GLX visual / pixel format */
visinfo = glXChooseVisual(dpy, 0, visAttributes);
if (!visinfo) {
printf("Error: couldn't get an RGB, Double-buffered visual\n");
exit(1);
}
/* Create the window */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attrMask = CWBackPixel | CWBorderPixel | CWColormap;
win = XCreateWindow(dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, attrMask, &attr);
if (!win) {
printf("Error: XCreateWindow failed\n");
exit(1);
}
/* Display the window */
XMapWindow(dpy, win);
/* Create GLX rendering context */
ctx = glXCreateContext(dpy, visinfo, NULL, True);
if (!ctx) {
printf("Error: glXCreateContext failed\n");
exit(1);
}
/* Bind the rendering context and window */
glXMakeCurrent(dpy, win, ctx);
return win;
}
/*
* Draw a few frames of a rotating square.
*/
static void
DrawFrames(Display * dpy, Window win)
{
int angle;
glShadeModel(GL_FLAT);
glClearColor(0.5, 0.5, 0.5, 1.0);
for (angle = 0; angle < 360; angle += 10) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glPushMatrix();
glRotatef(angle, 0, 0, 1);
glRectf(-0.8, -0.8, 0.8, 0.8);
glPopMatrix();
glXSwapBuffers(dpy, win);
}
}
int
main(int argc, char *argv[])
{
Display *dpy;
Window win;
dpy = XOpenDisplay(NULL);
if (!dpy) {
printf("Error: XOpenDisplay failed\n");
return 1;
}
win = MakeWindow(dpy, 300, 300);
DrawFrames(dpy, win);
return 0;
}
+
+
diff --git a/docs/contents.html b/docs/contents.html
index 20fd949f844..6ad259a9224 100644
--- a/docs/contents.html
+++ b/docs/contents.html
@@ -54,6 +54,7 @@
Mesa fbdev/DRI Drivers
1. Introduction
+
+2. Compilation
+
+
+ cd Mesa-newtree
+ cp Makefile.X11 Makefile # or use a symlink
+ make linux-solo
+
+
+Mesa-newtree/lib directory
+to verify that the following files were made:
+
+
+
+
+libGL.so.1.2 - the client-side OpenGL library
+ (and a few symlinks to it).
+libGLU.so.1.1 - the GLU library (and a few symlinks to it).
+libglut.so.3.7 - the GLUT library (and a few symlinks to it).
+mga_dri.so - DRI driver for Matrox G200/G400 cards.
+r128_dri.so - DRI driver for ATI Rage 128 cards.
+r200_dri.so - DRI driver for ATI R200 Radeon cards.
+radeon_dri.so - DRI driver for original ATI Radeon cards.
+fb_dri.so - software-only fbdev driver.
+miniglx.conf - configuration file for the MiniGLX interface
+3. Using fbdev/DRI
+
+3.1 Kernel Modules
+
+
+ modprobe agpgart # the AGP GART module
+ modprobe radeonfb # the Radeon fbdev driver
+ modprobe radeon # the Radeon DRI kernel module
+
+
+
+ modprobe agpgart # the AGP GART module
+ modprobe aty128fb # the Rage 128 fbdev driver
+ modprobe r128 # the Rage 128 DRI kernel module
+
+
+
+ modprobe agpgart # the AGP GART module
+ modprobe mgafb # the Matrox fbdev driver
+ modprobe mga # the Matrox DRI kernel module
+
+
+lsmod to be sure the modules are loaded.
+For a Radeon card, you should see something like this:
+
+Module Size Used by Not tainted
+radeon 110308 0 (unused)
+radeonfb 21900 0 (unused)
+agpgart 43072 1
+
+
+
+3.2 Configuration File
+
+Mesa-newtree/lib/miniglx.conf file should be installed
+in /etc/.
+/etc/miniglx.conf to be sure it's set up correctly
+for your hardware.
+Comments in the file explain the options.
+3.3 Running fbdev/DRI Programs
+
+Mesa-newtree/lib/ directory.
+Mesa-newtree/progs/miniglx/ directory and
+start the sample_server program in the background:
+
+ ./sample_server &
+
+
+miniglxtest program:
+
+ ./miniglxtest
+
+4.0 Troubleshooting
+
+
+ [miniglx] failed to probe chipset
+ connect: Connection refused
+ server connection lost
+
+5.0 Programming Information
+
+
+The MiniGLX specification describes the +interface between fbdev and Mesa. +
+More info to come...
-- 2.30.2