On Linux, OpenGL programs drew only with softgl. Now, when the system has an OpenGL driver whose renderer is hardware, the wgl functions make their contexts there, as an installable client driver does on Windows: - libEGL.so.1 is loaded when OpenGL is first used, so a program still needs no OpenGL library to start. The display is one of no window system (EGL_MESA_platform_surfaceless), else a device (EGL_EXT_platform_device), else the default one; the first with a hardware renderer is used. - Each context draws into a pbuffer of the window's (or bitmap's) size. Before the picture goes to the window, it is read back into the buffer that opengl.cpp copies with GDI, keeping the program's pack states, pixel transfer, read buffer, read framebuffer and pack buffer. So it works the same on X11, Wayland and with no display. - The program's gl functions are still softgl's, which call through the thread's dispatch table; a driver context points that table at the driver's functions. The makefile takes the table's order from port/softgl/src/dispatch.h (gl_names.inc), and a static_assert checks the size. - The pixel formats lose PFD_GENERIC_FORMAT and give the driver's depth and stencil bits. wglGetProcAddress gives NULL for a vendor's function whose extension is not there, as EGL gives a stub for any name. WINPORT_OPENGL=generic always uses softgl, and WINPORT_OPENGL=system uses the driver even when its renderer is software (llvmpipe). WINPORT_NO_EGL leaves it out. The README now says softgl gives OpenGL 1.5, not 1.1. gltest runs once more over the system's driver where there is EGL, and also checks a window that grows and the pixel states kept across the read-back. Signed-off-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRRw4kkFHrrHRhkcuLw
3.8 KiB
Software OpenGL (the generic implementation)
Some systems have no OpenGL of their own. On these systems, the wgl
functions use softgl, a software renderer. Windows has a renderer of
the same type: the "generic implementation" of opengl32.dll, which
GDI uses when there is no graphics driver for OpenGL.
softgl is a separate project: clang-retro/softgl. Its documentation tells the design, the functions, the speed on the 68000 and the limits: software-opengl.md.
The submodule
MFC has softgl as a git submodule in port/softgl. Clone MFC with
the submodule:
git clone --recurse-submodules https://github.com/clang-retro/mfc.git
For a clone that you have already, get the submodule:
git submodule update --init
If port/softgl is empty, the makefile stops and tells you to run
this command.
Where the renderer is used
| System | OpenGL under the wgl functions |
|---|---|
| Linux | The system's driver through EGL when its renderer is hardware (port/src/opengl_egl.cpp), else the generic implementation (port/softgl). |
| Classic Mac OS, 68k | The generic implementation (port/softgl). |
| Classic Mac OS, PowerPC | Apple OpenGL through AGL (port/src/opengl_agl.cpp). |
| Mac OS X and macOS | The OpenGL framework through CGL (port/src/opengl.cpp). |
The Apple renderers and the Linux drivers have the function of the
installable client driver (ICD) of Windows. The generic implementation
is used on all other portable targets, and on Linux when there is no
libEGL.so.1 or its renderer is software. WINPORT_OPENGL=generic
always uses the generic implementation; WINPORT_OPENGL=system uses
the driver even when its renderer is software. Compile with
-DWINPORT_NO_EGL to leave the drivers out.
On Linux the program's gl functions are still those of softgl: they
call through the thread's dispatch table, and a context of the driver
makes that table point at the driver's functions. The makefile takes
the order of the table from port/softgl/src/dispatch.h
(gl_names.inc).
To remove the generic implementation, compile with
-DWINPORT_NO_SOFTGL. Then ChoosePixelFormat fails with
ERROR_NOT_SUPPORTED.
How MFC builds the renderer
The makefile compiles the files of port/softgl/src and
port/softgl/glu (the NURBS of GLU, glu/libnurbs, are C++) with the
portable layer and puts the objects in
libwinport.a. A program links only with libwinport.a. Add
-Iport/softgl/include after -Iport/include, so that <GL/gl.h>
finds the headers. libglaux.a gives the aux functions of the
Windows SDK (GL/glaux.h) on these systems too.
The portable layer defines glFlush and glFinish itself: for a
single-buffered pixel format, they copy the picture to the window.
Thus the makefile compiles the renderer with -DSGL_LAYER_FLUSH,
which removes these two functions from softgl.
port/src/opengl_soft.cpp connects the wgl functions to the
interface of softgl (port/softgl/include/softgl.h). It gives a
color buffer to the context, and copies the buffer to the window after
SwapBuffers or glFlush.
Tests
tests/gltest.cppuses thewglfunctions. With the generic implementation, it also draws a triangle and examines its pixels.make checkruns it on Linux, then once more withWINPORT_OPENGL=systemover the system's driver where there islibEGL.so.1: the triangle, a window that grows, and the program's pixel states kept across the read of the picture.make check TARGET=m68k-apple-macosruns it in the 68000 and 68020 simulators of mac-sdk.tools/build-sdk-samples.pybuilds the OpenGL screen savers of the Win32 SDK for Linux and for the 68k Mac. See sdk-samples.md.- softgl has its own tests (
make checkinport/softgl).