Notes on Porting RealityEngine Applications to OpenGL



	Notes on Porting RealityEngine Applications to OpenGL
			April 20, 1995


The first step in porting a RealityEngine IrisGL application to OpenGL
is to consult the OpenGL Porting Guide.  It covers all the core IrisGL
and OpenGL functionality, window/event-handling, and OpenGL extensions
up to and including those in Irix 5.3.

This note discusses porting RealityEngine IrisGL applications to
OpenGL, using the OpenGL extensions in Irix 5.3 and Irix 5.3 patch
154.  In order to make it as short and comprehensible as possible, I
won't repeat any of the information in the Porting Guide except some of
the comments relevant to special RealityEngine features.

In addition to the Porting Guide and this note, developers will
require copies of the OpenGL specification and the OpenGL extension
specifications.  Man pages exist for the extensions in 5.3 and
patch154; they are easier to understand than the specs, but less
complete in some respects.

The functionality restrictions mentioned in this note apply to the
patch154 implementation of OpenGL on RealityEngine.  Future machines
will not necessarily have these restrictions.

IMPORTANT:  Everyone should be aware that patch154 is a special porting
tool for OpenGL developers using RealityEngine to write applications
for next-generation machines.  End-users should not depend on patch154
for production work on RealityEngine.


RealityEngine-specific IrisGL functionality and OpenGL equivalents:

	backbuffer, frontbuffer
	(simultaneous rendering into multiple color buffers)

		The frame buffer update semantics for rendering into
		multiple color buffers are different in IrisGL and
		OpenGL.  RE OpenGL actually implements the IrisGL
		semantics (computing one color value and writing it to
		all buffers) rather than the correct OpenGL semantics
		(computing a separate color value for each buffer).
		This can cause unexpected results if blending is used.

	blendcolor

		Supported.  See glBlendColorEXT.

	blendfunction

		The RE-specific IrisGL features are supported, as well
		as some new ones like image subtraction.  See
		glBlendFunc, glBlendEquationEXT.

	convolve

		Both general and separable 2D convolution are
		available.  Convolution is supported for glDrawPixels
		(the equivalent of lrectwrite) and glCopyPixels (the
		equivalent of rectcopy).

		There are several special cases in which convolution
		is not supported.  For example, convolution is not
		available when fragment processing is enabled or when
		either of the pixel zoom factors has a value other
		than 1.0 or -1.0.  See the man pages for more
		information.

		See pixelmap below.

	displacepolygon

		The OpenGL equivalent, glPolygonOffsetEXT, is more
		general than displacepolygon.  Developers might need to
		tweak the parameter values they use to get the proper
		results.

	dither

		OpenGL provides no control over video dithering.  (This
		is also the case for IrisGL in Irix5.3, unless
		overridden by an environment variable.)

	fbsubtexload

		A subset of fbsubtexload functionality is supported in
		patch154.  (See glCopyTexSubImage2DEXT).  The main
		restrictions are that the dimensions of the subimage
		must be multiples of 32 for copying from the frame
		buffer, and the width of the subimage must be 768 when
		copying from Sirius video.

	gamma

		OpenGL has no support for loading the gamma table.  If
		this functionality is required, you can use an IrisGL
		program as a workaround.

	glcompat GLC_SET_VSYNC, GLC_GET_VSYNC, GLC_VSYNC_SLEEP

		For GLC_GET_VSYNC, use glXGetVideoSyncSGI.
		For GLC_VSYNC_SLEEP, use glXWaitVideoSyncSGI.

		GLC_SET_VSYNC has no equivalent in OpenGL.  To replace
		it, maintain a sync counter offset in a static
		variable.

	glcompat SIR_VEN_INTERFACE, SIR_VEN_VIDEOCOPY
	(copy Sirius video to frame buffer)

		Supported, with some constraints.  Use
		glXCreateGLXVideoSourceSGIX to create a video source
		context, glXMakeCurrentReadSGI to set up the video
		source for a data transfer, and glCopyPixels to copy
		the video data to the frame buffer.

	hgram, gethgram
	(histogram)

		Supported for glDrawPixels (lrectwrite), glCopyPixels
		(rectcopy), and glReadPixels (lrectread).

		See glGetHistogramEXT and glHistogramEXT.

	ilbuffer, ildraw, readsource(SRC_ILBUFFER)
	(accelerated drawing to offscreen frame buffer memory)

		Currently there is no replacement for ilbuffers.  The
		pbuffer extension is the leading candidate, but it
		could not be implemented in time for patch154.

		Pixmaps cannot be used as substitutes for ilbuffers,
		because pixmap rendering is not accelerated and because
		most of the RE-specific rendering operations cannot be
		used with pixmaps.

		In the meantime, the two best approaches for providing
		frame buffer storage for intermediate results are:  (1)
		use the back buffer or left/right stereo back buffers;
		(2) use non-overlapping windows.  glXMakeCurrentRead()
		can be used with option (2) to prototype an
		implementation that will be nearly identical to a
		pbuffer-based implementation.

	istexloaded
	(texture memory management)

		Supported.  See glAreTexturesResidentEXT.

	leftbuffer, rightbuffer
	(stereo-in-a-window)

		Supported.  See glXChooseVisual and glDrawBuffer.

		For old-style stereo, see XSGISetStereoMode.

	libsphere - sphdraw, sphgnpolys, sphfree, sphmode, sphobj,
	sphrotmatrix, sphbgnbitmap, sphendbitmap, sphcolor

		gluSphere provides polygonal spheres.  Only bilinear
		tessellation is supported; octahedral, icosahedral,
		barycentric, and cubic tessellations are not
		supported.

		There is no support for the canonical orientation
		capability (sphrotmatrix), hemispheres (SPH_HEMI), or
		bitmap spheres.

	linesmooth
	(antialiased lines)

		Supported, with one caveat:  it is not possible to draw
		blended antialiased lines in a multisampled window,
		even when multisampling is disabled.  See glHint and
		glEnable(GL_LINE_SMOOTH).

	luminance visuals

		There are no luminance-only X11 Visuals on
		RealityEngine, so there is no OpenGL support for
		luminance-only data in the frame buffer.  Luminance can
		be converted to RGBA automatically in many cases,
		though.  The color matrix (glMatrixMode(GL_COLOR))
		is invaluable for unpacking luminance data stored as
		separate channels in RGBA images.

	minmax, getminmax
	(minimum and maximum pixel values)

		Supported for glDrawPixels (lrectwrite), glCopyPixels
		(rectcopy), and glReadPixels (lrectread).

		See glGetMinmaxEXT and glMinmaxEXT.

	mswapbuffers

		Not supported.

		Swapping multiple windows (e.g.  main and overlay
		buffers, or windows on genlocked pipes) from multiple
		threads can be accomplished fairly reliably with
		semaphored calls to glXSwapBuffers.  The following
		code fragment outlines the approach:

			/* Create some semaphores: */
				usptr_t* arena = usinit("/usr/tmp/our_arena");
				usema_t* pipe0ready = usnewsema(arena, 0);
				usema_t* pipe1ready = usnewsema(arena, 0);

			/* After the process for pipe 0 finishes its
			   frame, it signals its completion and waits for
			   pipe1.  When pipe1 is also ready, pipe0 swaps: */
				usvsema(pipe0ready);
				uspsema(pipe1ready);
				glXSwapBuffers(dpy, drawable);

			/* The process for pipe 1 does the converse: */
				usvsema(pipe1ready);
				uspsema(pipe0ready);
				glXSwapBuffers(dpy, drawable);

	multisample, getmultisample, msalpha, msmask, mspattern, mssize
	(multisample antialiasing)

		Supported.

		For msalpha, see glEnable with arguments
		GL_SAMPLE_ALPHA_TO_MASK_SGIS and
		GL_SAMPLE_ALPHA_TO_ONE_SGIS.

		For msmask, see glSampleMaskSGIS.

		For mspattern, see glSamplePatternSGIS.

		For mssize, see glXChooseVisual.

		For ``light points'', use
		glHint(GL_POINT_SMOOTH_HINT,GL_NICEST) with
		multisampling.  The maximum point diameter is 3 (the
		same as IrisGL).

		For fast tag clear, see glTagSampleBufferSGIX.

	pixelmap

		Differs from IrisGL.  The OpenGL function glPixelMap
		specifies a lookup table for pixel transfer operations,
		just as pixelmap does in IrisGL.  However, the location
		of the lookup table in the pixel processing pipeline is
		different.  The IrisGL lookup table appears immediately
		after convolution, while the OpenGL lookup table
		appears almost at the beginning of the pipeline
		(immediately after the first scale and bias).  The two
		pipelines are equivalent only when convolution is
		disabled.

		Pixel mapping is supported for glDrawPixels
		(lrectwrite), glCopyPixels (rectcopy), glReadPixels
		(lrectread), and glTexImage (texdef), but not for
		glTexSubImage (subtexload).

	pixmode

		Most of the functions of pixmode are supported, albeit
		in very different ways.  Here is a brief summary:

		PM_SHIFT, PM_ADD24:  Use the OpenGL color matrix
		extension to swizzle color components or to scale and
		bias pixel values.  See glPixelTransfer.

		PM_EXPAND, PM_C0, PM_C1:  Use the standard OpenGL color
		lookup table to convert bitmap data to RGBA.  See
		glPixelTransfer and glPixelMap.

		PM_TTOB, PM_RTOL:  Use glPixelZoom with negative zoom
		factors to reflect images when drawing or copying.
		Reflection during reading is not supported.

		PM_INPUT_FORMAT, PM_OUTPUT_FORMAT, PM_INPUT_TYPE,
		PM_OUTPUT_TYPE, PM_ZDATA:  Use the glReadPixels,
		glDrawPixels, and glCopyPixels type and format
		parameters.

		PM_OFFSET, PM_STRIDE, PM_SIZE:  Use glPixelStore.

	pntsize

		Supported.  See comments under multisample.

	polymode

		OpenGL doesn't support PYM_HOLLOW.  The closest
		approximation is glPolygonMode(GL_LINE).  See also
		glPolygonOffsetEXT.

	polysmooth

		OpenGL doesn't support PYM_SHRINK.

	popup planes

		OpenGL doesn't support drawing in the popup planes.

	readcomponent

		Use the color matrix extension (see glPixelTransfer) to
		extract one or more color channels for image
		processing.  The implementation is optimized for the
		case in which all channels but one are multiplied by
		zero, and all frame buffer channels but one are
		write-masked (see glColorMask).

		The color matrix is supported for glDrawPixels
		(lrectwrite) and glCopyPixels (rectcopy) but not
		for glReadPixels (lrectread) or glTexImage.

	RGBwritemask

		OpenGL supports masking an entire RGBA color channel,
		but not arbitrary sets of bits within an RGBA color
		channel.

	setvideo, setmonitor

		OpenGL has no support for these routines.

		Video output format should be changed with the setmon
		command (this is now recommended for IrisGL as well as
		OpenGL).

		OpenGL supports stereo-in-a-window; see glXChooseVisual
		and glDrawBuffer.  For old-style stereo, see
		XSGISetStereoMode.

		Use the Video Library (VL) for other video device
		control tasks.

	spline fog

		Not supported.

	statistics gathering

		Not supported.

	subtexload

		Partially supported.  glTexSubImage2DEXT is the analog
		of subtexload.

		glTexSubImage2DEXT supports only the following texel
		type and format combinations:

			UNSIGNED_BYTE LUMINANCE
			UNSIGNED_SHORT LUMINANCE
			UNSIGNED_BYTE LUMINANCE_ALPHA
			UNSIGNED_SHORT LUMINANCE_ALPHA
			UNSIGNED_BYTE RGB
			UNSIGNED_BYTE RGBA

		Scale/bias and the other pixmode-style operations are not
		supported.

		The ``flags'' argument to subtexload is not supported,
		so the special fast-path cases are not available in
		OpenGL.  (However, note that the fast-path cases for
		IrisGL are still the fastest cases for OpenGL.)

		The special flags SIR_VEN_16BIT_TEXEL and
		SIR_VEN_32BIT_TEXEL, used to copy Sirius video to
		texture memory, are supported in a different way in
		OpenGL.  Use glXCreateGLXVideoSourceSGIX to declare
		Sirius as a pixel source, and glXMakeCurrentReadSGI to
		connect it to an OpenGL rendering context.  Then you
		can use the glCopyTexSubImage2DEXT command (roughly
		analogous to fbsubtexload) to copy the pixels from
		Sirius to texture memory.  See the man pages for
		information about additional constraints.

	tevdef, tevbind

		TV_COMPONENT_SELECT (the ability to pack multiple
		shallow textures together, then unpack and select one
		of them during drawing) is not supported.

	texbind

		Texture definition and binding are combined into a
		single operation in standard OpenGL.  However, the
		texture_object extension makes them separate again
		(albeit in a manner that differs from IrisGL).  See
		glBindTextureEXT.

		Detail texturing (TX_TEXTURE_DETAIL) is supported.  See
		glDetailTexFuncSGIS.

		Simple texture memory management (TX_TEXTURE_IDLE) is
		supported.  See glPrioritizeTexturesEXT.

	texdef

		1D, 2D, and 3D textures are supported.  See glTexImage1D,
		glTexImage2D, and glTexImage3DEXT.

		TX_FAST_DEFINE is not supported.  A copy of each
		texture is always placed in kernel memory for graphics
		context switching.  (OpenGL semantics require the
		graphics library to read the texture exactly once; it
		cannot re-read the texture later to refresh texture
		memory after a graphics context switch.)  Subtexloading
		is still possible, however; see glTexSubImage2DEXT.

		The TX_BILINEAR_LEQUAL and TX_BILINEAR_GEQUAL filtering
		options, which are used to implement shadows, are not
		supported.

		The TX_BICUBIC filter option, which is used for bicubic
		filtering and as a workaround for the lack of point
		sampling, is also not supported.

		The TX_MINFILTER options for mipmapping are supported
		for 1D and 2D textures, but not for 3D textures.  3D
		textures must use GL_POINT (TX_POINT) or GL_LINEAR
		(TX_BILINEAR) filtering modes.

		OpenGL differs from IrisGL in that filtered versions of
		the texture image (when required by the current
		minification filter) are not generated automatically;
		the application must load them explicitly.  Thus the
		TX_MIPMAP_FILTER_KERNEL token is not supported.

		Separate magnification filters for color and alpha
		(TX_MAGFILTER_COLOR and TX_MAGFILTER_ALPHA) are not
		supported in the general case.  However, it is possible
		to specify separate alpha and color magnification
		filters for detail and sharp texturing.  See
		glTexParameter.

		Sharp texture filtering (TX_SHARPEN) is supported.  See
		glTexParameter for setting the filtering mode, and
		glSharpenTexFuncSGIS for setting the scaling function
		(TX_CONTROL_POINT, TX_CONTROL_CLAMP).

		Detail texture (TX_ADD_DETAIL and TX_MODULATE_DETAIL)
		is supported for 2D.  The parameters are specified
		differently from those in IrisGL.  See glTexParameter
		for setting the filtering mode, and glDetailTexFuncSGIS
		for setting the scaling function (TX_CONTROL_POINT,
		TX_CONTROL_CLAMP).

		The TX_WRAP mode TX_SELECT is not supported.  OpenGL
		provides GL_CLAMP (TX_CLAMP) and GL_REPEAT (TX_REPEAT).

		TX_INTERNAL_FORMAT and all IrisGL texel internal
		formats are supported.  See the ``components''
		parameter of glTexImage2D for a list of the OpenGL
		internal formats.

		TX_TILE (multipass rendering for high-resolution
		textures) is not supported directly.  OpenGL border
		clamping can emulate tiling if you use the edges of
		neighboring tiles as the borders for the current tile.

	tlutbind

		In OpenGL, tlut definition and binding are combined
		into a single operation, and tluts apply to all
		texturing (rather than being bound to a particular
		texture target).  See the comments under tlutdef.

	tlutdef

		See glTexColorTableParameterSGI for a description of
		the OpenGL texture color lookup process, and
		glColorTableSGI for information about loading the
		lookup table.

		The OpenGL lookup table semantics differ from
		IrisGL's.  The following case described in the tlutdef
		man page cannot be emulated in OpenGL.  (``nc'' stands
		for ``number of components''; ``I'' for intensity;
		``A'' for alpha; ``R'' for red; ``G'' for green; ``B''
		for blue.)

			tlut nc	texture nc	action
			-------	----------	-----------------------
			    4	    3		R,G,B,B looks up R,G,B,A

		The following cases are supported directly, or can be
		supported with a judicious choice of table values and
		enables:

			tlut nc	texture nc	action
			-------	----------	-----------------------
			    2	    1		I looks up I,A
			    	    2		I,A looks up I,A
			    	    3		R,G,B pass unchanged
			    	    4		R,G,B,A pass unchanged
			    3	    1		I looks up R,G,B
			    	    2		I,A pass unchanged
			    	    3		R,G,B looks up R,G,B
			    	    4		R,G,B,A pass unchanged
			    4	    1		I looks up R,G,B,A
			    	    2		I looks up RGB; A looks up A
			    	    4		R,G,B,A looks up R,G,B,A

		OpenGL supports cases that are not available under
		IrisGL.  See glTexColorTableParameterSGI for more
		information.

	underlays

		There are no X11 Visuals for the underlay planes, so
		OpenGL rendering to underlays is not supported.