summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2008-06-18 14:07:38 -0700
committerEric Anholt <eric@anholt.net>2008-06-18 14:07:38 -0700
commit654258a4fe5e7114022c6e02f2844fc469fcc6f3 (patch)
tree89d285becb87659ab61ee0ceeb35c76726ae93d2 /src
parent64adeb163d7da6d75b5664cd2ee3783cadaf63d8 (diff)
parentcf29ab3ba075905cca786b52617d7dc993f58033 (diff)
Merge commit 'origin/master' into drm-gem
Diffstat (limited to 'src')
-rw-r--r--src/glu/sgi/libutil/quad.c4
-rw-r--r--src/glut/os2/WarpWin.cpp838
-rw-r--r--src/glut/os2/glut_cindex.cpp516
-rw-r--r--src/glut/os2/glut_gamemode.cpp1358
-rw-r--r--src/glut/os2/glut_win.cpp2440
-rw-r--r--src/glut/os2/glut_winmisc.cpp252
-rw-r--r--src/glut/os2/os2_glx.cpp290
-rw-r--r--src/glut/os2/os2_menu.cpp1064
-rw-r--r--src/glut/os2/os2_winproc.cpp2592
-rw-r--r--src/glx/x11/Makefile2
-rw-r--r--src/glx/x11/dri2_glx.c98
-rw-r--r--src/glx/x11/dri_common.c399
-rw-r--r--src/glx/x11/dri_common.h60
-rw-r--r--src/glx/x11/dri_glx.c746
-rw-r--r--src/glx/x11/drisw_glx.c441
-rw-r--r--src/glx/x11/glcontextmodes.c5
-rw-r--r--src/glx/x11/glx_pbuffer.c2
-rw-r--r--src/glx/x11/glxclient.h3
-rw-r--r--src/glx/x11/glxext.c14
-rw-r--r--src/mesa/Makefile176
-rw-r--r--src/mesa/drivers/Makefile29
-rw-r--r--src/mesa/drivers/beos/Makefile2
-rw-r--r--src/mesa/drivers/directfb/Makefile15
-rw-r--r--src/mesa/drivers/dri/Makefile.template1
-rw-r--r--src/mesa/drivers/dri/common/dri_util.c43
-rw-r--r--src/mesa/drivers/dri/i915/i915_texstate.c7
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm_fp.c9
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm_glsl.c2
-rw-r--r--src/mesa/drivers/dri/intel/intel_blit.c5
-rw-r--r--src/mesa/drivers/dri/intel/intel_chipset.h12
-rw-r--r--src/mesa/drivers/dri/intel/intel_context.c7
-rw-r--r--src/mesa/drivers/dri/intel/intel_screen.c11
-rw-r--r--src/mesa/drivers/dri/r300/Makefile5
-rw-r--r--src/mesa/drivers/dri/r300/r300_context.c2
-rw-r--r--src/mesa/drivers/dri/r300/r300_context.h185
-rw-r--r--src/mesa/drivers/dri/r300/r300_fragprog.c2367
-rw-r--r--src/mesa/drivers/dri/r300/r300_fragprog.h46
-rw-r--r--src/mesa/drivers/dri/r300/r300_fragprog_emit.c2058
-rw-r--r--src/mesa/drivers/dri/r300/r300_ioctl.c17
-rw-r--r--src/mesa/drivers/dri/r300/r300_reg.h46
-rw-r--r--src/mesa/drivers/dri/r300/r300_render.c1
-rw-r--r--src/mesa/drivers/dri/r300/r300_shader.c1
-rw-r--r--src/mesa/drivers/dri/r300/r300_state.c178
-rw-r--r--src/mesa/drivers/dri/r300/r300_tex.c216
-rw-r--r--src/mesa/drivers/dri/r300/r300_texmem.c6
-rw-r--r--src/mesa/drivers/dri/r300/r300_texstate.c239
-rw-r--r--src/mesa/drivers/dri/r300/r500_fragprog.c1672
-rw-r--r--src/mesa/drivers/dri/r300/r500_fragprog.h13
-rw-r--r--src/mesa/drivers/dri/r300/r500_fragprog_emit.c1533
-rw-r--r--src/mesa/drivers/dri/r300/radeon_context.h10
-rw-r--r--src/mesa/drivers/dri/r300/radeon_program.c281
-rw-r--r--src/mesa/drivers/dri/r300/radeon_program.h164
-rw-r--r--src/mesa/drivers/dri/r300/radeon_program_alu.c284
-rw-r--r--src/mesa/drivers/dri/r300/radeon_program_alu.h38
-rw-r--r--src/mesa/drivers/dri/r300/radeon_span.c24
-rw-r--r--src/mesa/drivers/dri/swrast/swrast.c107
-rw-r--r--src/mesa/drivers/fbdev/Makefile36
-rw-r--r--src/mesa/drivers/osmesa/Makefile74
-rw-r--r--src/mesa/drivers/osmesa/osmesa.c14
-rw-r--r--src/mesa/drivers/x11/Makefile79
-rw-r--r--src/mesa/drivers/x11/glxapi.c4
-rw-r--r--src/mesa/drivers/x11/xm_api.c16
-rw-r--r--src/mesa/drivers/x11/xm_glide.c3
-rw-r--r--src/mesa/main/image.c2
-rw-r--r--src/mesa/main/mm.c8
-rw-r--r--src/mesa/main/mm.h5
-rw-r--r--src/mesa/main/texenvprogram.c8
-rw-r--r--src/mesa/main/texstore.c4
-rw-r--r--src/mesa/shader/arbprogparse.c2
-rw-r--r--src/mesa/shader/prog_execute.c3
-rw-r--r--src/mesa/shader/prog_parameter.c24
-rw-r--r--src/mesa/shader/prog_print.c17
-rw-r--r--src/mesa/shader/programopt.c12
-rw-r--r--src/mesa/shader/programopt.h2
-rw-r--r--src/mesa/shader/slang/slang_compile.c31
-rw-r--r--src/mesa/shader/slang/slang_emit.c16
-rw-r--r--src/mesa/shader/slang/slang_ir.h1
-rw-r--r--src/mesa/shader/slang/slang_link.c3
-rw-r--r--src/mesa/sources65
-rw-r--r--src/mesa/swrast/s_context.c2
-rw-r--r--src/mesa/swrast/s_context.h1
-rw-r--r--src/mesa/swrast/s_zoom.c27
-rw-r--r--src/mesa/tnl/t_context.c14
-rw-r--r--src/mesa/tnl/t_pipeline.c2
-rw-r--r--src/mesa/tnl/t_vb_fog.c6
-rw-r--r--src/mesa/vbo/vbo_save_loopback.c3
86 files changed, 11737 insertions, 9683 deletions
diff --git a/src/glu/sgi/libutil/quad.c b/src/glu/sgi/libutil/quad.c
index e604539c82..1ae7442c80 100644
--- a/src/glu/sgi/libutil/quad.c
+++ b/src/glu/sgi/libutil/quad.c
@@ -713,8 +713,8 @@ gluSphere(GLUquadric *qobj, GLdouble radius, GLint slices, GLint stacks)
GLfloat cosCache3b[CACHE_SIZE];
GLfloat angle;
GLfloat zLow, zHigh;
- GLfloat sintemp1, sintemp2, sintemp3 = 0.0, sintemp4 = 0.0;
- GLfloat costemp1, costemp2 = 0.0, costemp3 = 0.0, costemp4 = 0.0;
+ GLfloat sintemp1 = 0.0, sintemp2 = 0.0, sintemp3 = 0.0, sintemp4 = 0.0;
+ GLfloat costemp1 = 0.0, costemp2 = 0.0, costemp3 = 0.0, costemp4 = 0.0;
GLboolean needCache2, needCache3;
GLint start, finish;
diff --git a/src/glut/os2/WarpWin.cpp b/src/glut/os2/WarpWin.cpp
index ee746ecc76..bd5a6e80c7 100644
--- a/src/glut/os2/WarpWin.cpp
+++ b/src/glut/os2/WarpWin.cpp
@@ -1,420 +1,420 @@
-/* WarpWin.c */
-/* glut for Warp */
-#include <stdio.h>
-#include <string.h>
-
-#include "WarpWin.h"
-#include "WarpGL.h"
-
-#define POKA 0
-
-/* global variables that must be set for some functions to operate
- correctly. */
-HDC XHDC;
-HWND XHWND;
-
-
-void
-XStoreColor(Display* display, Colormap colormap, XColor* color)
-{
- /* KLUDGE: set XHDC to 0 if the palette should NOT be realized after
- setting the color. set XHDC to the correct HDC if it should. */
-
- LONG pe;
- ULONG cclr;
- int r,g,b;
- /* X11 stores color from 0-65535, Win32 expects them to be 0-256, so
- twiddle the bits ( / 256). */
- r = color->red / 256;
- g = color->green / 256;
- b = color->blue / 256;
- pe = LONGFromRGB(r,g,b);
- /* make sure we use this flag, otherwise the colors might get mapped
- to another place in the colormap, and when we glIndex() that
- color, it may have moved (argh!!) */
- pe |= (PC_NOCOLLAPSE<<24);
-/* This function changes the entries in a palette. */
-#if POKA
-OS2:
- rc = GpiSetPaletteEntries(colormap,LCOLF_CONSECRGB, color->pixel, 1, &pe);
- GpiSelectPalette(hps,colormap);
- WinRealizePalette(hwnd,hps,&cclr);
-source Win:
- if (XHDC) {
- UnrealizeObject(colormap);
- SelectPalette(XHDC, colormap, FALSE);
- RealizePalette(XHDC);
-
- }
-#endif
-}
-
-void
-XSetWindowColormap(Display* display, Window window, Colormap colormap)
-{
-#if POKA
- HDC hdc = GetDC(window);
-
- /* if the third parameter is FALSE, the logical colormap is copied
- into the device palette when the application is in the
- foreground, if it is TRUE, the colors are mapped into the current
- palette in the best possible way. */
- SelectPalette(hdc, colormap, FALSE);
- RealizePalette(hdc);
-
- /* note that we don't have to release the DC, since our window class
- uses the WC_OWNDC flag! */
-#endif
-}
-
-
-/* display, root and visual - don't used at all */
-Colormap
-XCreateColormap(Display* display, Window root, Visual* visual, int alloc)
-{
- /* KLUDGE: this function needs XHDC to be set to the HDC currently
- being operated on before it is invoked! */
-
- HPAL palette;
- int n;
-#if POKA
- PIXELFORMATDESCRIPTOR pfd;
- LOGPALETTE *logical;
-
- /* grab the pixel format */
- memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
- DescribePixelFormat(XHDC, GetPixelFormat(XHDC),
- sizeof(PIXELFORMATDESCRIPTOR), &pfd);
-
- if (!(pfd.dwFlags & PFD_NEED_PALETTE ||
- pfd.iPixelType == PFD_TYPE_COLORINDEX))
- {
- return 0;
- }
-
- n = 1 << pfd.cColorBits;
-
- /* allocate a bunch of memory for the logical palette (assume 256
- colors in a Win32 palette */
- logical = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +
- sizeof(PALETTEENTRY) * n);
- memset(logical, 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * n);
-
- /* set the entries in the logical palette */
- logical->palVersion = 0x300;
- logical->palNumEntries = n;
-
- /* start with a copy of the current system palette */
- GetSystemPaletteEntries(XHDC, 0, 256, &logical->palPalEntry[0]);
-
- if (pfd.iPixelType == PFD_TYPE_RGBA) {
- int redMask = (1 << pfd.cRedBits) - 1;
- int greenMask = (1 << pfd.cGreenBits) - 1;
- int blueMask = (1 << pfd.cBlueBits) - 1;
- int i;
-
- /* fill in an RGBA color palette */
- for (i = 0; i < n; ++i) {
- logical->palPalEntry[i].peRed =
- (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
- logical->palPalEntry[i].peGreen =
- (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
- logical->palPalEntry[i].peBlue =
- (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
- logical->palPalEntry[i].peFlags = 0;
- }
- }
-
- palette = CreatePalette(logical);
- free(logical);
-
- SelectPalette(XHDC, palette, FALSE);
- RealizePalette(XHDC);
-#endif /* POKA */
-
- return palette;
-}
-
-
-
-int GetSystemMetrics( int mode)
-{ RECTL rect;
-
- switch(mode)
- { case SM_CXSCREEN:
- WinQueryWindowRect(HWND_DESKTOP,&rect);
- return (rect.xRight-rect.xLeft);
- break;
- case SM_CYSCREEN:
- WinQueryWindowRect(HWND_DESKTOP,&rect);
- return (rect.yTop-rect.yBottom);
- break;
- default: ;
- }
- return 0;
-}
-/*
- * XParseGeometry parses strings of the form
- * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
- * width, height, xoffset, and yoffset are unsigned integers.
- * Example: "=80x24+300-49"
- * The equal sign is optional.
- * It returns a bitmask that indicates which of the four values
- * were actually found in the string. For each value found,
- * the corresponding argument is updated; for each value
- * not found, the corresponding argument is left unchanged.
- */
-
-static int
-ReadInteger(char *string, char **NextString)
-{
- register int Result = 0;
- int Sign = 1;
-
- if (*string == '+')
- string++;
- else if (*string == '-')
- {
- string++;
- Sign = -1;
- }
- for (; (*string >= '0') && (*string <= '9'); string++)
- {
- Result = (Result * 10) + (*string - '0');
- }
- *NextString = string;
- if (Sign >= 0)
- return (Result);
- else
- return (-Result);
-}
-
-int XParseGeometry(char *string, int *x, int *y, unsigned int *width, unsigned int *height)
-{
- int mask = NoValue;
- register char *strind;
- unsigned int tempWidth, tempHeight;
- int tempX, tempY;
- char *nextCharacter;
-
- if ( (string == NULL) || (*string == '\0')) return(mask);
- if (*string == '=')
- string++; /* ignore possible '=' at beg of geometry spec */
-
- strind = (char *)string;
- if (*strind != '+' && *strind != '-' && *strind != 'x') {
- tempWidth = ReadInteger(strind, &nextCharacter);
- if (strind == nextCharacter)
- return (0);
- strind = nextCharacter;
- mask |= WidthValue;
- }
-
- if (*strind == 'x' || *strind == 'X') {
- strind++;
- tempHeight = ReadInteger(strind, &nextCharacter);
- if (strind == nextCharacter)
- return (0);
- strind = nextCharacter;
- mask |= HeightValue;
- }
-
- if ((*strind == '+') || (*strind == '-')) {
- if (*strind == '-') {
- strind++;
- tempX = -ReadInteger(strind, &nextCharacter);
- if (strind == nextCharacter)
- return (0);
- strind = nextCharacter;
- mask |= XNegative;
-
- }
- else
- { strind++;
- tempX = ReadInteger(strind, &nextCharacter);
- if (strind == nextCharacter)
- return(0);
- strind = nextCharacter;
- }
- mask |= XValue;
- if ((*strind == '+') || (*strind == '-')) {
- if (*strind == '-') {
- strind++;
- tempY = -ReadInteger(strind, &nextCharacter);
- if (strind == nextCharacter)
- return(0);
- strind = nextCharacter;
- mask |= YNegative;
-
- }
- else
- {
- strind++;
- tempY = ReadInteger(strind, &nextCharacter);
- if (strind == nextCharacter)
- return(0);
- strind = nextCharacter;
- }
- mask |= YValue;
- }
- }
-
- /* If strind isn't at the end of the string the it's an invalid
- geometry specification. */
-
- if (*strind != '\0') return (0);
-
- if (mask & XValue)
- *x = tempX;
- if (mask & YValue)
- *y = tempY;
- if (mask & WidthValue)
- *width = tempWidth;
- if (mask & HeightValue)
- *height = tempHeight;
- return (mask);
-}
-
-int gettimeofday(struct timeval* tp, void* tzp)
-{
- DATETIME DateTime;
- APIRET ulrc; /* Return Code. */
-
- ulrc = DosGetDateTime(&DateTime);
- tp->tv_sec = 60 * (60*DateTime.hours + DateTime.minutes) + DateTime.seconds;
- tp->tv_usec = DateTime.hundredths * 10000;
- return 0;
-}
-
-
-int
-XPending(Display* display)
-{
- /* similar functionality...I don't think that it is exact, but this
- will have to do. */
- QMSG msg;
- extern HAB hab; /* PM anchor block handle */
-
-//?? WinPeekMsg(hab
- return WinPeekMsg(hab, &msg, NULLHANDLE, 0, 0, PM_NOREMOVE);
-}
-
-void
-__glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
-{
- RECTL rect;
-
- /* adjust the window rectangle because Win32 thinks that the x, y,
- width & height are the WHOLE window (including decorations),
- whereas GLUT treats the x, y, width & height as only the CLIENT
- area of the window. */
- rect.xLeft = *x; rect.yTop = *y;
- rect.xRight = *x + *width; rect.yBottom = *y + *height;
-
- /* must adjust the coordinates according to the correct style
- because depending on the style, there may or may not be
- borders. */
-//?? AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
-//?? (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
-//?? FALSE);
- /* FALSE in the third parameter = window has no menu bar */
-
- /* readjust if the x and y are offscreen */
- if(rect.xLeft < 0) {
- *x = 0;
- } else {
- *x = rect.xLeft;
- }
-
- if(rect.yTop < 0) {
- *y = 0;
- } else {
- *y = rect.yTop;
- }
-
- *width = rect.xRight - rect.xLeft; /* adjusted width */
- *height = -(rect.yBottom - rect.yTop); /* adjusted height */
-}
-
-
-int
-__glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
-{
- /* the transparent pixel on Win32 is always index number 0. So if
- we put this routine in this file, we can avoid compiling the
- whole of layerutil.c which is where this routine normally comes
- from. */
- return 0;
-}
-
-/* Translate point coordinates src_x and src_y from src to dst */
-
-Bool
-XTranslateCoordinates(Display *display, Window src, Window dst,
- int src_x, int src_y,
- int* dest_x_return, int* dest_y_return,
- Window* child_return)
-{
- SWP swp_src,swp_dst;
-
- WinQueryWindowPos(src,&swp_src);
- WinQueryWindowPos(dst,&swp_dst);
-
- *dest_x_return = src_x + swp_src.x - swp_dst.x;
- *dest_y_return = src_y + swp_src.y - swp_dst.y;
-
- /* just to make compilers happy...we don't use the return value. */
- return True;
-}
-
-Status
-XGetGeometry(Display* display, Window window, Window* root_return,
- int* x_return, int* y_return,
- unsigned int* width_return, unsigned int* height_return,
- unsigned int *border_width_return, unsigned int* depth_return)
-{
- /* KLUDGE: doesn't return the border_width or depth or root, x & y
- are in screen coordinates. */
- SWP swp_src;
- WinQueryWindowPos(window,&swp_src);
-
- *x_return = swp_src.x;
- *y_return = swp_src.y;
- *width_return = swp_src.cx;
- *height_return = swp_src.cy;
-
- /* just to make compilers happy...we don't use the return value. */
- return 1;
-}
-
-/* Get Display Width in millimeters */
-int
-DisplayWidthMM(Display* display, int screen)
-{
- int width;
- LONG *pVC_Caps;
- pVC_Caps = GetVideoConfig(NULLHANDLE);
- width = (int)( 0.001 * pVC_Caps[CAPS_WIDTH] / pVC_Caps[CAPS_HORIZONTAL_RESOLUTION]);/* mm */
- return width;
-}
-
-/* Get Display Height in millimeters */
-int
-DisplayHeightMM(Display* display, int screen)
-{
- int height;
- LONG *pVC_Caps;
- pVC_Caps = GetVideoConfig(NULLHANDLE);
- height = (int)( 0.001 * pVC_Caps[CAPS_HEIGHT] / pVC_Caps[CAPS_VERTICAL_RESOLUTION]); /* mm */
- return height;
-}
-
-void ScreenToClient( HWND hwnd, POINTL *point)
-{
- SWP swp_src;
- WinQueryWindowPos(hwnd,&swp_src);
- point->x -= swp_src.x;
- point->y -= swp_src.y;
-}
-
+/* WarpWin.c */
+/* glut for Warp */
+#include <stdio.h>
+#include <string.h>
+
+#include "WarpWin.h"
+#include "WarpGL.h"
+
+#define POKA 0
+
+/* global variables that must be set for some functions to operate
+ correctly. */
+HDC XHDC;
+HWND XHWND;
+
+
+void
+XStoreColor(Display* display, Colormap colormap, XColor* color)
+{
+ /* KLUDGE: set XHDC to 0 if the palette should NOT be realized after
+ setting the color. set XHDC to the correct HDC if it should. */
+
+ LONG pe;
+ ULONG cclr;
+ int r,g,b;
+ /* X11 stores color from 0-65535, Win32 expects them to be 0-256, so
+ twiddle the bits ( / 256). */
+ r = color->red / 256;
+ g = color->green / 256;
+ b = color->blue / 256;
+ pe = LONGFromRGB(r,g,b);
+ /* make sure we use this flag, otherwise the colors might get mapped
+ to another place in the colormap, and when we glIndex() that
+ color, it may have moved (argh!!) */
+ pe |= (PC_NOCOLLAPSE<<24);
+/* This function changes the entries in a palette. */
+#if POKA
+OS2:
+ rc = GpiSetPaletteEntries(colormap,LCOLF_CONSECRGB, color->pixel, 1, &pe);
+ GpiSelectPalette(hps,colormap);
+ WinRealizePalette(hwnd,hps,&cclr);
+source Win:
+ if (XHDC) {
+ UnrealizeObject(colormap);
+ SelectPalette(XHDC, colormap, FALSE);
+ RealizePalette(XHDC);
+
+ }
+#endif
+}
+
+void
+XSetWindowColormap(Display* display, Window window, Colormap colormap)
+{
+#if POKA
+ HDC hdc = GetDC(window);
+
+ /* if the third parameter is FALSE, the logical colormap is copied
+ into the device palette when the application is in the
+ foreground, if it is TRUE, the colors are mapped into the current
+ palette in the best possible way. */
+ SelectPalette(hdc, colormap, FALSE);
+ RealizePalette(hdc);
+
+ /* note that we don't have to release the DC, since our window class
+ uses the WC_OWNDC flag! */
+#endif
+}
+
+
+/* display, root and visual - don't used at all */
+Colormap
+XCreateColormap(Display* display, Window root, Visual* visual, int alloc)
+{
+ /* KLUDGE: this function needs XHDC to be set to the HDC currently
+ being operated on before it is invoked! */
+
+ HPAL palette;
+ int n;
+#if POKA
+ PIXELFORMATDESCRIPTOR pfd;
+ LOGPALETTE *logical;
+
+ /* grab the pixel format */
+ memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
+ DescribePixelFormat(XHDC, GetPixelFormat(XHDC),
+ sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+
+ if (!(pfd.dwFlags & PFD_NEED_PALETTE ||
+ pfd.iPixelType == PFD_TYPE_COLORINDEX))
+ {
+ return 0;
+ }
+
+ n = 1 << pfd.cColorBits;
+
+ /* allocate a bunch of memory for the logical palette (assume 256
+ colors in a Win32 palette */
+ logical = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +
+ sizeof(PALETTEENTRY) * n);
+ memset(logical, 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * n);
+
+ /* set the entries in the logical palette */
+ logical->palVersion = 0x300;
+ logical->palNumEntries = n;
+
+ /* start with a copy of the current system palette */
+ GetSystemPaletteEntries(XHDC, 0, 256, &logical->palPalEntry[0]);
+
+ if (pfd.iPixelType == PFD_TYPE_RGBA) {
+ int redMask = (1 << pfd.cRedBits) - 1;
+ int greenMask = (1 << pfd.cGreenBits) - 1;
+ int blueMask = (1 << pfd.cBlueBits) - 1;
+ int i;
+
+ /* fill in an RGBA color palette */
+ for (i = 0; i < n; ++i) {
+ logical->palPalEntry[i].peRed =
+ (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
+ logical->palPalEntry[i].peGreen =
+ (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
+ logical->palPalEntry[i].peBlue =
+ (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
+ logical->palPalEntry[i].peFlags = 0;
+ }
+ }
+
+ palette = CreatePalette(logical);
+ free(logical);
+
+ SelectPalette(XHDC, palette, FALSE);
+ RealizePalette(XHDC);
+#endif /* POKA */
+
+ return palette;
+}
+
+
+
+int GetSystemMetrics( int mode)
+{ RECTL rect;
+
+ switch(mode)
+ { case SM_CXSCREEN:
+ WinQueryWindowRect(HWND_DESKTOP,&rect);
+ return (rect.xRight-rect.xLeft);
+ break;
+ case SM_CYSCREEN:
+ WinQueryWindowRect(HWND_DESKTOP,&rect);
+ return (rect.yTop-rect.yBottom);
+ break;
+ default: ;
+ }
+ return 0;
+}
+/*
+ * XParseGeometry parses strings of the form
+ * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
+ * width, height, xoffset, and yoffset are unsigned integers.
+ * Example: "=80x24+300-49"
+ * The equal sign is optional.
+ * It returns a bitmask that indicates which of the four values
+ * were actually found in the string. For each value found,
+ * the corresponding argument is updated; for each value
+ * not found, the corresponding argument is left unchanged.
+ */
+
+static int
+ReadInteger(char *string, char **NextString)
+{
+ register int Result = 0;
+ int Sign = 1;
+
+ if (*string == '+')
+ string++;
+ else if (*string == '-')
+ {
+ string++;
+ Sign = -1;
+ }
+ for (; (*string >= '0') && (*string <= '9'); string++)
+ {
+ Result = (Result * 10) + (*string - '0');
+ }
+ *NextString = string;
+ if (Sign >= 0)
+ return (Result);
+ else
+ return (-Result);
+}
+
+int XParseGeometry(char *string, int *x, int *y, unsigned int *width, unsigned int *height)
+{
+ int mask = NoValue;
+ register char *strind;
+ unsigned int tempWidth, tempHeight;
+ int tempX, tempY;
+ char *nextCharacter;
+
+ if ( (string == NULL) || (*string == '\0')) return(mask);
+ if (*string == '=')
+ string++; /* ignore possible '=' at beg of geometry spec */
+
+ strind = (char *)string;
+ if (*strind != '+' && *strind != '-' && *strind != 'x') {
+ tempWidth = ReadInteger(strind, &nextCharacter);
+ if (strind == nextCharacter)
+ return (0);
+ strind = nextCharacter;
+ mask |= WidthValue;
+ }
+
+ if (*strind == 'x' || *strind == 'X') {
+ strind++;
+ tempHeight = ReadInteger(strind, &nextCharacter);
+ if (strind == nextCharacter)
+ return (0);
+ strind = nextCharacter;
+ mask |= HeightValue;
+ }
+
+ if ((*strind == '+') || (*strind == '-')) {
+ if (*strind == '-') {
+ strind++;
+ tempX = -ReadInteger(strind, &nextCharacter);
+ if (strind == nextCharacter)
+ return (0);
+ strind = nextCharacter;
+ mask |= XNegative;
+
+ }
+ else
+ { strind++;
+ tempX = ReadInteger(strind, &nextCharacter);
+ if (strind == nextCharacter)
+ return(0);
+ strind = nextCharacter;
+ }
+ mask |= XValue;
+ if ((*strind == '+') || (*strind == '-')) {
+ if (*strind == '-') {
+ strind++;
+ tempY = -ReadInteger(strind, &nextCharacter);
+ if (strind == nextCharacter)
+ return(0);
+ strind = nextCharacter;
+ mask |= YNegative;
+
+ }
+ else
+ {
+ strind++;
+ tempY = ReadInteger(strind, &nextCharacter);
+ if (strind == nextCharacter)
+ return(0);
+ strind = nextCharacter;
+ }
+ mask |= YValue;
+ }
+ }
+
+ /* If strind isn't at the end of the string the it's an invalid
+ geometry specification. */
+
+ if (*strind != '\0') return (0);
+
+ if (mask & XValue)
+ *x = tempX;
+ if (mask & YValue)
+ *y = tempY;
+ if (mask & WidthValue)
+ *width = tempWidth;
+ if (mask & HeightValue)
+ *height = tempHeight;
+ return (mask);
+}
+
+int gettimeofday(struct timeval* tp, void* tzp)
+{
+ DATETIME DateTime;
+ APIRET ulrc; /* Return Code. */
+
+ ulrc = DosGetDateTime(&DateTime);
+ tp->tv_sec = 60 * (60*DateTime.hours + DateTime.minutes) + DateTime.seconds;
+ tp->tv_usec = DateTime.hundredths * 10000;
+ return 0;
+}
+
+
+int
+XPending(Display* display)
+{
+ /* similar functionality...I don't think that it is exact, but this
+ will have to do. */
+ QMSG msg;
+ extern HAB hab; /* PM anchor block handle */
+
+//?? WinPeekMsg(hab
+ return WinPeekMsg(hab, &msg, NULLHANDLE, 0, 0, PM_NOREMOVE);
+}
+
+void
+__glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
+{
+ RECTL rect;
+
+ /* adjust the window rectangle because Win32 thinks that the x, y,
+ width & height are the WHOLE window (including decorations),
+ whereas GLUT treats the x, y, width & height as only the CLIENT
+ area of the window. */
+ rect.xLeft = *x; rect.yTop = *y;
+ rect.xRight = *x + *width; rect.yBottom = *y + *height;
+
+ /* must adjust the coordinates according to the correct style
+ because depending on the style, there may or may not be
+ borders. */
+//?? AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
+//?? (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
+//?? FALSE);
+ /* FALSE in the third parameter = window has no menu bar */
+
+ /* readjust if the x and y are offscreen */
+ if(rect.xLeft < 0) {
+ *x = 0;
+ } else {
+ *x = rect.xLeft;
+ }
+
+ if(rect.yTop < 0) {
+ *y = 0;
+ } else {
+ *y = rect.yTop;
+ }
+
+ *width = rect.xRight - rect.xLeft; /* adjusted width */
+ *height = -(rect.yBottom - rect.yTop); /* adjusted height */
+}
+
+
+int
+__glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
+{
+ /* the transparent pixel on Win32 is always index number 0. So if
+ we put this routine in this file, we can avoid compiling the
+ whole of layerutil.c which is where this routine normally comes
+ from. */
+ return 0;
+}
+
+/* Translate point coordinates src_x and src_y from src to dst */
+
+Bool
+XTranslateCoordinates(Display *display, Window src, Window dst,
+ int src_x, int src_y,
+ int* dest_x_return, int* dest_y_return,
+ Window* child_return)
+{
+ SWP swp_src,swp_dst;
+
+ WinQueryWindowPos(src,&swp_src);
+ WinQueryWindowPos(dst,&swp_dst);
+
+ *dest_x_return = src_x + swp_src.x - swp_dst.x;
+ *dest_y_return = src_y + swp_src.y - swp_dst.y;
+
+ /* just to make compilers happy...we don't use the return value. */
+ return True;
+}
+
+Status
+XGetGeometry(Display* display, Window window, Window* root_return,
+ int* x_return, int* y_return,
+ unsigned int* width_return, unsigned int* height_return,
+ unsigned int *border_width_return, unsigned int* depth_return)
+{
+ /* KLUDGE: doesn't return the border_width or depth or root, x & y
+ are in screen coordinates. */
+ SWP swp_src;
+ WinQueryWindowPos(window,&swp_src);
+
+ *x_return = swp_src.x;
+ *y_return = swp_src.y;
+ *width_return = swp_src.cx;
+ *height_return = swp_src.cy;
+
+ /* just to make compilers happy...we don't use the return value. */
+ return 1;
+}
+
+/* Get Display Width in millimeters */
+int
+DisplayWidthMM(Display* display, int screen)
+{
+ int width;
+ LONG *pVC_Caps;
+ pVC_Caps = GetVideoConfig(NULLHANDLE);
+ width = (int)( 0.001 * pVC_Caps[CAPS_WIDTH] / pVC_Caps[CAPS_HORIZONTAL_RESOLUTION]);/* mm */
+ return width;
+}
+
+/* Get Display Height in millimeters */
+int
+DisplayHeightMM(Display* display, int screen)
+{
+ int height;
+ LONG *pVC_Caps;
+ pVC_Caps = GetVideoConfig(NULLHANDLE);
+ height = (int)( 0.001 * pVC_Caps[CAPS_HEIGHT] / pVC_Caps[CAPS_VERTICAL_RESOLUTION]); /* mm */
+ return height;
+}
+
+void ScreenToClient( HWND hwnd, POINTL *point)
+{
+ SWP swp_src;
+ WinQueryWindowPos(hwnd,&swp_src);
+ point->x -= swp_src.x;
+ point->y -= swp_src.y;
+}
+
 \ No newline at end of file
diff --git a/src/glut/os2/glut_cindex.cpp b/src/glut/os2/glut_cindex.cpp
index 0897a3cf85..3484185051 100644
--- a/src/glut/os2/glut_cindex.cpp
+++ b/src/glut/os2/glut_cindex.cpp
@@ -1,259 +1,259 @@
-
-/* Copyright (c) Mark J. Kilgard, 1994, 1996, 1997. */
-
-/* This program is freely distributable without licensing fees
- and is provided without guarantee or warrantee expressed or
- implied. This program is -not- in the public domain. */
-
-#include <stdlib.h>
-#include "glutint.h"
-
-#if defined(__OS2PM__)
- #define IsWindowVisible WinIsWindowVisible
-#endif
-
-#define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
-
-/* CENTRY */
-void GLUTAPIENTRY
-glutSetColor(int ndx, GLfloat red, GLfloat green, GLfloat blue)
-{
- GLUTcolormap *cmap, *newcmap;
- XVisualInfo *vis;
- XColor color;
- int i;
-
- if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
- cmap = __glutCurrentWindow->colormap;
- vis = __glutCurrentWindow->vis;
- } else {
- cmap = __glutCurrentWindow->overlay->colormap;
- vis = __glutCurrentWindow->overlay->vis;
- if (ndx == __glutCurrentWindow->overlay->transparentPixel) {
- __glutWarning(
- "glutSetColor: cannot set color of overlay transparent index %d\n",
- ndx);
- return;
- }
- }
-
- if (!cmap) {
- __glutWarning("glutSetColor: current window is RGBA");
- return;
- }
-#if defined(_WIN32) || defined(__OS2PM__)
- if (ndx >= 256 || /* always assume 256 colors on Win32 */
-#else
- if (ndx >= vis->visual->map_entries ||
-#endif
- ndx < 0) {
- __glutWarning("glutSetColor: index %d out of range", ndx);
- return;
- }
- if (cmap->refcnt > 1) {
- newcmap = __glutAssociateNewColormap(vis);
- cmap->refcnt--;
- /* Wouldn't it be nice if XCopyColormapAndFree could be
- told not to free the old colormap's entries! */
- for (i = cmap->size - 1; i >= 0; i--) {
- if (i == ndx) {
- /* We are going to set this cell shortly! */
- continue;
- }
- if (cmap->cells[i].component[GLUT_RED] >= 0.0) {
- color.pixel = i;
- newcmap->cells[i].component[GLUT_RED] =
- cmap->cells[i].component[GLUT_RED];
- color.red = (GLfloat) 0xffff *
- cmap->cells[i].component[GLUT_RED];
- newcmap->cells[i].component[GLUT_GREEN] =
- cmap->cells[i].component[GLUT_GREEN];
- color.green = (GLfloat) 0xffff *
- cmap->cells[i].component[GLUT_GREEN];
- newcmap->cells[i].component[GLUT_BLUE] =
- cmap->cells[i].component[GLUT_BLUE];
- color.blue = (GLfloat) 0xffff *
- cmap->cells[i].component[GLUT_BLUE];
- color.flags = DoRed | DoGreen | DoBlue;
-#if defined(_WIN32) || defined(__OS2PM__)
- if (IsWindowVisible(__glutCurrentWindow->win)) {
- XHDC = __glutCurrentWindow->hdc;
- } else {
- XHDC = 0;
- }
-#endif
- XStoreColor(__glutDisplay, newcmap->cmap, &color);
- } else {
- /* Leave unallocated entries unallocated. */
- }
- }
- cmap = newcmap;
- if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
- __glutCurrentWindow->colormap = cmap;
- __glutCurrentWindow->cmap = cmap->cmap;
- } else {
- __glutCurrentWindow->overlay->colormap = cmap;
- __glutCurrentWindow->overlay->cmap = cmap->cmap;
- }
- XSetWindowColormap(__glutDisplay,
- __glutCurrentWindow->renderWin, cmap->cmap);
-
-#if !defined(_WIN32) && !defined(__OS2PM__)
- {
- GLUTwindow *toplevel;
-
- toplevel = __glutToplevelOf(__glutCurrentWindow);
- if (toplevel->cmap != cmap->cmap) {
- __glutPutOnWorkList(toplevel, GLUT_COLORMAP_WORK);
- }
- }
-#endif
- }
- color.pixel = ndx;
- red = CLAMP(red);
- cmap->cells[ndx].component[GLUT_RED] = red;
- color.red = (GLfloat) 0xffff *red;
- green = CLAMP(green);
- cmap->cells[ndx].component[GLUT_GREEN] = green;
- color.green = (GLfloat) 0xffff *green;
- blue = CLAMP(blue);
- cmap->cells[ndx].component[GLUT_BLUE] = blue;
- color.blue = (GLfloat) 0xffff *blue;
- color.flags = DoRed | DoGreen | DoBlue;
-#if defined(_WIN32) || defined(__OS2PM__)
- if (IsWindowVisible(__glutCurrentWindow->win)) {
- XHDC = __glutCurrentWindow->hdc;
- } else {
- XHDC = 0;
- }
-#endif
- XStoreColor(__glutDisplay, cmap->cmap, &color);
-}
-
-GLfloat GLUTAPIENTRY
-glutGetColor(int ndx, int comp)
-{
- GLUTcolormap *colormap;
- XVisualInfo *vis;
-
- if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
- colormap = __glutCurrentWindow->colormap;
- vis = __glutCurrentWindow->vis;
- } else {
- colormap = __glutCurrentWindow->overlay->colormap;
- vis = __glutCurrentWindow->overlay->vis;
- if (ndx == __glutCurrentWindow->overlay->transparentPixel) {
- __glutWarning("glutGetColor: requesting overlay transparent index %d\n",
- ndx);
- return -1.0;
- }
- }
-
- if (!colormap) {
- __glutWarning("glutGetColor: current window is RGBA");
- return -1.0;
- }
-#if defined(_WIN32) || defined(__OS2PM__)
-#define OUT_OF_RANGE_NDX(ndx) (ndx >= 256 || ndx < 0)
-#else
-#define OUT_OF_RANGE_NDX(ndx) (ndx >= vis->visual->map_entries || ndx < 0)
-#endif
- if (OUT_OF_RANGE_NDX(ndx)) {
- __glutWarning("glutGetColor: index %d out of range", ndx);
- return -1.0;
- }
- return colormap->cells[ndx].component[comp];
-}
-
-void GLUTAPIENTRY
-glutCopyColormap(int winnum)
-{
- GLUTwindow *window = __glutWindowList[winnum - 1];
- GLUTcolormap *oldcmap, *newcmap;
- XVisualInfo *dstvis;
-
- if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
- oldcmap = __glutCurrentWindow->colormap;
- dstvis = __glutCurrentWindow->vis;
- newcmap = window->colormap;
- } else {
- oldcmap = __glutCurrentWindow->overlay->colormap;
- dstvis = __glutCurrentWindow->overlay->vis;
- if (!window->overlay) {
- __glutWarning("glutCopyColormap: window %d has no overlay", winnum);
- return;
- }
- newcmap = window->overlay->colormap;
- }
-
- if (!oldcmap) {
- __glutWarning("glutCopyColormap: destination colormap must be color index");
- return;
- }
- if (!newcmap) {
- __glutWarning(
- "glutCopyColormap: source colormap of window %d must be color index",
- winnum);
- return;
- }
- if (newcmap == oldcmap) {
- /* Source and destination are the same; now copy needed. */
- return;
- }
-#if !defined(_WIN32) && !defined(__OS2PM__)
- /* Play safe: compare visual IDs, not Visual*'s. */
- if (newcmap->visual->visualid == oldcmap->visual->visualid) {
-#endif
- /* Visuals match! "Copy" by reference... */
- __glutFreeColormap(oldcmap);
- newcmap->refcnt++;
- if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
- __glutCurrentWindow->colormap = newcmap;
- __glutCurrentWindow->cmap = newcmap->cmap;
- } else {
- __glutCurrentWindow->overlay->colormap = newcmap;
- __glutCurrentWindow->overlay->cmap = newcmap->cmap;
- }
- XSetWindowColormap(__glutDisplay, __glutCurrentWindow->renderWin,
- newcmap->cmap);
-#if !defined(_WIN32) && !defined(__OS2PM__)
- __glutPutOnWorkList(__glutToplevelOf(window), GLUT_COLORMAP_WORK);
-bla bla bla
-
- } else {
- GLUTcolormap *copycmap;
- XColor color;
- int i, last;
-
- /* Visuals different - need a distinct X colormap! */
- copycmap = __glutAssociateNewColormap(dstvis);
- /* Wouldn't it be nice if XCopyColormapAndFree could be
- told not to free the old colormap's entries! */
- last = newcmap->size;
- if (last > copycmap->size) {
- last = copycmap->size;
- }
- for (i = last - 1; i >= 0; i--) {
- if (newcmap->cells[i].component[GLUT_RED] >= 0.0) {
- color.pixel = i;
- copycmap->cells[i].component[GLUT_RED] =
- newcmap->cells[i].component[GLUT_RED];
- color.red = (GLfloat) 0xffff *
- newcmap->cells[i].component[GLUT_RED];
- copycmap->cells[i].component[GLUT_GREEN] =
- newcmap->cells[i].component[GLUT_GREEN];
- color.green = (GLfloat) 0xffff *
- newcmap->cells[i].component[GLUT_GREEN];
- copycmap->cells[i].component[GLUT_BLUE] =
- newcmap->cells[i].component[GLUT_BLUE];
- color.blue = (GLfloat) 0xffff *
- newcmap->cells[i].component[GLUT_BLUE];
- color.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(__glutDisplay, copycmap->cmap, &color);
- }
- }
- }
-#endif
-}
-/* ENDCENTRY */
+
+/* Copyright (c) Mark J. Kilgard, 1994, 1996, 1997. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+#include <stdlib.h>
+#include "glutint.h"
+
+#if defined(__OS2PM__)
+ #define IsWindowVisible WinIsWindowVisible
+#endif
+
+#define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
+
+/* CENTRY */
+void GLUTAPIENTRY
+glutSetColor(int ndx, GLfloat red, GLfloat green, GLfloat blue)
+{
+ GLUTcolormap *cmap, *newcmap;
+ XVisualInfo *vis;
+ XColor color;
+ int i;
+
+ if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
+ cmap = __glutCurrentWindow->colormap;
+ vis = __glutCurrentWindow->vis;
+ } else {
+ cmap = __glutCurrentWindow->overlay->colormap;
+ vis = __glutCurrentWindow->overlay->vis;
+ if (ndx == __glutCurrentWindow->overlay->transparentPixel) {
+ __glutWarning(
+ "glutSetColor: cannot set color of overlay transparent index %d\n",
+ ndx);
+ return;
+ }
+ }
+
+ if (!cmap) {
+ __glutWarning("glutSetColor: current window is RGBA");
+ return;
+ }
+#if defined(_WIN32) || defined(__OS2PM__)
+ if (ndx >= 256 || /* always assume 256 colors on Win32 */
+#else
+ if (ndx >= vis->visual->map_entries ||
+#endif
+ ndx < 0) {
+ __glutWarning("glutSetColor: index %d out of range", ndx);
+ return;
+ }
+ if (cmap->refcnt > 1) {
+ newcmap = __glutAssociateNewColormap(vis);
+ cmap->refcnt--;
+ /* Wouldn't it be nice if XCopyColormapAndFree could be
+ told not to free the old colormap's entries! */
+ for (i = cmap->size - 1; i >= 0; i--) {
+ if (i == ndx) {
+ /* We are going to set this cell shortly! */
+ continue;
+ }
+ if (cmap->cells[i].component[GLUT_RED] >= 0.0) {
+ color.pixel = i;
+ newcmap->cells[i].component[GLUT_RED] =
+ cmap->cells[i].component[GLUT_RED];
+ color.red = (GLfloat) 0xffff *
+ cmap->cells[i].component[GLUT_RED];
+ newcmap->cells[i].component[GLUT_GREEN] =
+ cmap->cells[i].component[GLUT_GREEN];
+ color.green = (GLfloat) 0xffff *
+ cmap->cells[i].component[GLUT_GREEN];
+ newcmap->cells[i].component[GLUT_BLUE] =
+ cmap->cells[i].component[GLUT_BLUE];
+ color.blue = (GLfloat) 0xffff *
+ cmap->cells[i].component[GLUT_BLUE];
+ color.flags = DoRed | DoGreen | DoBlue;
+#if defined(_WIN32) || defined(__OS2PM__)
+ if (IsWindowVisible(__glutCurrentWindow->win)) {
+ XHDC = __glutCurrentWindow->hdc;
+ } else {
+ XHDC = 0;
+ }
+#endif
+ XStoreColor(__glutDisplay, newcmap->cmap, &color);
+ } else {
+ /* Leave unallocated entries unallocated. */
+ }
+ }
+ cmap = newcmap;
+ if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
+ __glutCurrentWindow->colormap = cmap;
+ __glutCurrentWindow->cmap = cmap->cmap;
+ } else {
+ __glutCurrentWindow->overlay->colormap = cmap;
+ __glutCurrentWindow->overlay->cmap = cmap->cmap;
+ }
+ XSetWindowColormap(__glutDisplay,
+ __glutCurrentWindow->renderWin, cmap->cmap);
+
+#if !defined(_WIN32) && !defined(__OS2PM__)
+ {
+ GLUTwindow *toplevel;
+
+ toplevel = __glutToplevelOf(__glutCurrentWindow);
+ if (toplevel->cmap != cmap->cmap) {
+ __glutPutOnWorkList(toplevel, GLUT_COLORMAP_WORK);
+ }
+ }
+#endif
+ }
+ color.pixel = ndx;
+ red = CLAMP(red);
+ cmap->cells[ndx].component[GLUT_RED] = red;
+ color.red = (GLfloat) 0xffff *red;
+ green = CLAMP(green);
+ cmap->cells[ndx].component[GLUT_GREEN] = green;
+ color.green = (GLfloat) 0xffff *green;
+ blue = CLAMP(blue);
+ cmap->cells[ndx].component[GLUT_BLUE] = blue;
+ color.blue = (GLfloat) 0xffff *blue;
+ color.flags = DoRed | DoGreen | DoBlue;
+#if defined(_WIN32) || defined(__OS2PM__)
+ if (IsWindowVisible(__glutCurrentWindow->win)) {
+ XHDC = __glutCurrentWindow->hdc;
+ } else {
+ XHDC = 0;
+ }
+#endif
+ XStoreColor(__glutDisplay, cmap->cmap, &color);
+}
+
+GLfloat GLUTAPIENTRY
+glutGetColor(int ndx, int comp)
+{
+ GLUTcolormap *colormap;
+ XVisualInfo *vis;
+
+ if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
+ colormap = __glutCurrentWindow->colormap;
+ vis = __glutCurrentWindow->vis;
+ } else {
+ colormap = __glutCurrentWindow->overlay->colormap;
+ vis = __glutCurrentWindow->overlay->vis;
+ if (ndx == __glutCurrentWindow->overlay->transparentPixel) {
+ __glutWarning("glutGetColor: requesting overlay transparent index %d\n",
+ ndx);
+ return -1.0;
+ }
+ }
+
+ if (!colormap) {
+ __glutWarning("glutGetColor: current window is RGBA");
+ return -1.0;
+ }
+#if defined(_WIN32) || defined(__OS2PM__)
+#define OUT_OF_RANGE_NDX(ndx) (ndx >= 256 || ndx < 0)
+#else
+#define OUT_OF_RANGE_NDX(ndx) (ndx >= vis->visual->map_entries || ndx < 0)
+#endif
+ if (OUT_OF_RANGE_NDX(ndx)) {
+ __glutWarning("glutGetColor: index %d out of range", ndx);
+ return -1.0;
+ }
+ return colormap->cells[ndx].component[comp];
+}
+
+void GLUTAPIENTRY
+glutCopyColormap(int winnum)
+{
+ GLUTwindow *window = __glutWindowList[winnum - 1];
+ GLUTcolormap *oldcmap, *newcmap;
+ XVisualInfo *dstvis;
+
+ if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
+ oldcmap = __glutCurrentWindow->colormap;
+ dstvis = __glutCurrentWindow->vis;
+ newcmap = window->colormap;
+ } else {
+ oldcmap = __glutCurrentWindow->overlay->colormap;
+ dstvis = __glutCurrentWindow->overlay->vis;
+ if (!window->overlay) {
+ __glutWarning("glutCopyColormap: window %d has no overlay", winnum);
+ return;
+ }
+ newcmap = window->overlay->colormap;
+ }
+
+ if (!oldcmap) {
+ __glutWarning("glutCopyColormap: destination colormap must be color index");
+ return;
+ }
+ if (!newcmap) {
+ __glutWarning(
+ "glutCopyColormap: source colormap of window %d must be color index",
+ winnum);
+ return;
+ }
+ if (newcmap == oldcmap) {
+ /* Source and destination are the same; now copy needed. */
+ return;
+ }
+#if !defined(_WIN32) && !defined(__OS2PM__)
+ /* Play safe: compare visual IDs, not Visual*'s. */
+ if (newcmap->visual->visualid == oldcmap->visual->visualid) {
+#endif
+ /* Visuals match! "Copy" by reference... */
+ __glutFreeColormap(oldcmap);
+ newcmap->refcnt++;
+ if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
+ __glutCurrentWindow->colormap = newcmap;
+ __glutCurrentWindow->cmap = newcmap->cmap;
+ } else {
+ __glutCurrentWindow->overlay->colormap = newcmap;
+ __glutCurrentWindow->overlay->cmap = newcmap->cmap;
+ }
+ XSetWindowColormap(__glutDisplay, __glutCurrentWindow->renderWin,
+ newcmap->cmap);
+#if !defined(_WIN32) && !defined(__OS2PM__)
+ __glutPutOnWorkList(__glutToplevelOf(window), GLUT_COLORMAP_WORK);
+bla bla bla
+
+ } else {
+ GLUTcolormap *copycmap;
+ XColor color;
+ int i, last;
+
+ /* Visuals different - need a distinct X colormap! */
+ copycmap = __glutAssociateNewColormap(dstvis);
+ /* Wouldn't it be nice if XCopyColormapAndFree could be
+ told not to free the old colormap's entries! */
+ last = newcmap->size;
+ if (last > copycmap->size) {
+ last = copycmap->size;
+ }
+ for (i = last - 1; i >= 0; i--) {
+ if (newcmap->cells[i].component[GLUT_RED] >= 0.0) {
+ color.pixel = i;
+ copycmap->cells[i].component[GLUT_RED] =
+ newcmap->cells[i].component[GLUT_RED];
+ color.red = (GLfloat) 0xffff *
+ newcmap->cells[i].component[GLUT_RED];
+ copycmap->cells[i].component[GLUT_GREEN] =
+ newcmap->cells[i].component[GLUT_GREEN];
+ color.green = (GLfloat) 0xffff *
+ newcmap->cells[i].component[GLUT_GREEN];
+ copycmap->cells[i].component[GLUT_BLUE] =
+ newcmap->cells[i].component[GLUT_BLUE];
+ color.blue = (GLfloat) 0xffff *
+ newcmap->cells[i].component[GLUT_BLUE];
+ color.flags = DoRed | DoGreen | DoBlue;
+ XStoreColor(__glutDisplay, copycmap->cmap, &color);
+ }
+ }
+ }
+#endif
+}
+/* ENDCENTRY */
 \ No newline at end of file
diff --git a/src/glut/os2/glut_gamemode.cpp b/src/glut/os2/glut_gamemode.cpp
index 50185d7b9d..39918fdf39 100644
--- a/src/glut/os2/glut_gamemode.cpp
+++ b/src/glut/os2/glut_gamemode.cpp
@@ -1,680 +1,680 @@
-
-/* Copyright (c) Mark J. Kilgard, 1998. */
-
-/* This program is freely distributable without licensing fees
- and is provided without guarantee or warrantee expressed or
- implied. This program is -not- in the public domain. */
-
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "glutint.h"
-
-#if !defined(_WIN32) && !defined(__OS2__)
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-
-/* SGI optimization introduced in IRIX 6.3 to avoid X server
- round trips for interning common X atoms. */
-#if defined(_SGI_EXTRA_PREDEFINES) && !defined(NO_FAST_ATOMS)
-#include <X11/SGIFastAtom.h>
-#else
-#define XSGIFastInternAtom(dpy,string,fast_name,how) XInternAtom(dpy,string,how)
-#endif
-#endif /* not _WIN32 */
-
-int __glutDisplaySettingsChanged = 0;
-static DisplayMode *dmodes, *currentDm = NULL;
-static int ndmodes = -1;
-GLUTwindow *__glutGameModeWindow = NULL;
-
-#ifdef TEST
-static char *compstr[] =
-{
- "none", "=", "!=", "<=", ">=", ">", "<", "~"
-};
-static char *capstr[] =
-{
- "width", "height", "bpp", "hertz", "num"
-};
-#endif
-
-#if defined(__OS2__)
-void
-#else
-void __cdecl
-#endif
-__glutCloseDownGameMode(void)
-{
- if (__glutDisplaySettingsChanged) {
-#ifdef _WIN32
- /* Assumes that display settings have been changed, that
- is __glutDisplaySettingsChanged is true. */
- ChangeDisplaySettings(NULL, 0);
-#endif
- __glutDisplaySettingsChanged = 0;
- }
- __glutGameModeWindow = NULL;
-}
-
-void GLUTAPIENTRY
-glutLeaveGameMode(void)
-{
- if (__glutGameModeWindow == NULL) {
- __glutWarning("not in game mode so cannot leave game mode");
- return;
- }
- __glutDestroyWindow(__glutGameModeWindow,
- __glutGameModeWindow);
- XFlush(__glutDisplay);
- __glutGameModeWindow = NULL;
-}
-
-#ifdef _WIN32
-
-/* Same values as from MSDN's SetDisp.c example. */
-#define MIN_WIDTH 400
-#define MIN_FREQUENCY 60
-
-static void
-initGameModeSupport(void)
-{
- DEVMODE dm;
- DWORD mode;
- int i;
-
- if (ndmodes >= 0) {
- /* ndmodes is initially -1 to indicate no
- dmodes allocated yet. */
- return;
- }
-
- /* Determine how many display modes there are. */
- ndmodes = 0;
- mode = 0;
- while (EnumDisplaySettings(NULL, mode, &dm)) {
- if (dm.dmPelsWidth >= MIN_WIDTH &&
- (dm.dmDisplayFrequency == 0 ||
- dm.dmDisplayFrequency >= MIN_FREQUENCY)) {
- ndmodes++;
- }
- mode++;
- }
-
- /* Allocate memory for a list of all the display modes. */
- dmodes = (DisplayMode*)
- malloc(ndmodes * sizeof(DisplayMode));
-
- /* Now that we know how many display modes to expect,
- enumerate them again and save the information in
- the list we allocated above. */
- i = 0;
- mode = 0;
- while (EnumDisplaySettings(NULL, mode, &dm)) {
- /* Try to reject any display settings that seem unplausible. */
- if (dm.dmPelsWidth >= MIN_WIDTH &&
- (dm.dmDisplayFrequency == 0 ||
- dm.dmDisplayFrequency >= MIN_FREQUENCY)) {
- dmodes[i].devmode = dm;
- dmodes[i].valid = 1; /* XXX Not used for now. */
- dmodes[i].cap[DM_WIDTH] = dm.dmPelsWidth;
- dmodes[i].cap[DM_HEIGHT] = dm.dmPelsHeight;
- dmodes[i].cap[DM_PIXEL_DEPTH] = dm.dmBitsPerPel;
- if (dm.dmDisplayFrequency == 0) {
- /* Guess a reasonable guess. */
- /* Lame Windows 95 version of EnumDisplaySettings. */
- dmodes[i].cap[DM_HERTZ] = 60;
- } else {
- dmodes[i].cap[DM_HERTZ] = dm.dmDisplayFrequency;
- }
- i++;
- }
- mode++;
- }
-
- assert(i == ndmodes);
-}
-
-#else
-
-/* X Windows version of initGameModeSupport. */
-static void
-initGameModeSupport(void)
-{
- if (ndmodes >= 0) {
- /* ndmodes is initially -1 to indicate no
- dmodes allocated yet. */
- return;
- }
-
- /* Determine how many display modes there are. */
- ndmodes = 0;
-}
-
-#endif
-
-/* This routine is based on similiar code in glut_dstr.c */
-static DisplayMode *
-findMatch(DisplayMode * dmodes, int ndmodes,
- Criterion * criteria, int ncriteria)
-{
- DisplayMode *found;
- int *bestScore, *thisScore;
- int i, j, numok, result = 0, worse, better;
-
- found = NULL;
- numok = 1; /* "num" capability is indexed from 1,
- not 0. */
-
- /* XXX alloca canidate. */
- bestScore = (int *) malloc(ncriteria * sizeof(int));
- if (!bestScore) {
- __glutFatalError("out of memory.");
- }
- for (j = 0; j < ncriteria; j++) {
- /* Very negative number. */
- bestScore[j] = -32768;
- }
-
- /* XXX alloca canidate. */
- thisScore = (int *) malloc(ncriteria * sizeof(int));
- if (!thisScore) {
- __glutFatalError("out of memory.");
- }
-
- for (i = 0; i < ndmodes; i++) {
- if (dmodes[i].valid) {
- worse = 0;
- better = 0;
-
- for (j = 0; j < ncriteria; j++) {
- int cap, cvalue, dvalue;
-
- cap = criteria[j].capability;
- cvalue = criteria[j].value;
- if (cap == NUM) {
- dvalue = numok;
- } else {
- dvalue = dmodes[i].cap[cap];
- }
-#ifdef TEST
- if (verbose)
- printf(" %s %s %d to %d\n",
- capstr[cap], compstr[criteria[j].comparison], cvalue, dvalue);
-#endif
- switch (criteria[j].comparison) {
- case EQ:
- result = cvalue == dvalue;
- thisScore[j] = 1;
- break;
- case NEQ:
- result = cvalue != dvalue;
- thisScore[j] = 1;
- break;
- case LT:
- result = dvalue < cvalue;
- thisScore[j] = dvalue - cvalue;
- break;
- case GT:
- result = dvalue > cvalue;
- thisScore[j] = dvalue - cvalue;
- break;
- case LTE:
- result = dvalue <= cvalue;
- thisScore[j] = dvalue - cvalue;
- break;
- case GTE:
- result = (dvalue >= cvalue);
- thisScore[j] = dvalue - cvalue;
- break;
- case MIN:
- result = dvalue >= cvalue;
- thisScore[j] = cvalue - dvalue;
- break;
- }
-
-#ifdef TEST
- if (verbose)
- printf(" result=%d score=%d bestScore=%d\n", result, thisScore[j], bestScore[j]);
-#endif
-
- if (result) {
- if (better || thisScore[j] > bestScore[j]) {
- better = 1;
- } else if (thisScore[j] == bestScore[j]) {
- /* Keep looking. */
- } else {
- goto nextDM;
- }
- } else {
- if (cap == NUM) {
- worse = 1;
- } else {
- goto nextDM;
- }
- }
-
- }
-
- if (better && !worse) {
- found = &dmodes[i];
- for (j = 0; j < ncriteria; j++) {
- bestScore[j] = thisScore[j];
- }
- }
- numok++;
-
- nextDM:;
-
- }
- }
- free(bestScore);
- free(thisScore);
- return found;
-}
-
-/**
- * Parses strings in the form of:
- * 800x600
- * 800x600:16
- * 800x600@60
- * 800x600:16@60
- * @60
- * :16
- * :16@60
- * NOTE that @ before : is not parsed.
- */
-static int
-specialCaseParse(char *word, Criterion * criterion, int mask)
-{
- char *xstr, *response;
- int got;
- int width, height, bpp, hertz;
-
- switch(word[0]) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- /* The WWWxHHH case. */
- if (mask & (1 << DM_WIDTH)) {
- return -1;
- }
- xstr = strpbrk(&word[1], "x");
- if (xstr) {
- width = (int) strtol(word, &response, 0);
- if (response == word || response[0] != 'x') {
- /* Not a valid number OR needs to be followed by 'x'. */
- return -1;
- }
- height = (int) strtol(&xstr[1], &response, 0);
- if (response == &xstr[1]) {
- /* Not a valid number. */
- return -1;
- }
- criterion[0].capability = DM_WIDTH;
- criterion[0].comparison = EQ;
- criterion[0].value = width;
- criterion[1].capability = DM_HEIGHT;
- criterion[1].comparison = EQ;
- criterion[1].value = height;
- got = specialCaseParse(response,
- &criterion[2], 1 << DM_WIDTH);
- if (got >= 0) {
- return got + 2;
- } else {
- return -1;
- }
- }
- return -1;
- case ':':
- /* The :BPP case. */
- if (mask & (1 << DM_PIXEL_DEPTH)) {
- return -1;
- }
- bpp = (int) strtol(&word[1], &response, 0);
- if (response == &word[1]) {
- /* Not a valid number. */
- return -1;
- }
- criterion[0].capability = DM_PIXEL_DEPTH;
- criterion[0].comparison = EQ;
- criterion[0].value = bpp;
- got = specialCaseParse(response,
- &criterion[1], (1 << DM_WIDTH) | (1 << DM_PIXEL_DEPTH));
- if (got >= 0) {
- return got + 1;
- } else {
- return -1;
- }
- case '@':
- /* The @HZ case. */
- if (mask & (1 << DM_HERTZ)) {
- return -1;
- }
- hertz = (int) strtol(&word[1], &response, 0);
- if (response == &word[1]) {
- /* Not a valid number. */
- return -1;
- }
- criterion[0].capability = DM_HERTZ;
- criterion[0].comparison = EQ;
- criterion[0].value = hertz;
- got = specialCaseParse(response,
- &criterion[1], ~DM_HERTZ);
- if (got >= 0) {
- return got + 1;
- } else {
- return -1;
- }
- case '\0':
- return 0;
- }
- return -1;
-}
-
-/* This routine is based on similiar code in glut_dstr.c */
-static int
-parseCriteria(char *word, Criterion * criterion)
-{
- char *cstr, *vstr, *response;
- int comparator, value = 0;
-
- cstr = strpbrk(word, "=><!~");
- if (cstr) {
- switch (cstr[0]) {
- case '=':
- comparator = EQ;
- vstr = &cstr[1];
- break;
- case '~':
- comparator = MIN;
- vstr = &cstr[1];
- break;
- case '>':
- if (cstr[1] == '=') {
- comparator = GTE;
- vstr = &cstr[2];
- } else {
- comparator = GT;
- vstr = &cstr[1];
- }
- break;
- case '<':
- if (cstr[1] == '=') {
- comparator = LTE;
- vstr = &cstr[2];
- } else {
- comparator = LT;
- vstr = &cstr[1];
- }
- break;
- case '!':
- if (cstr[1] == '=') {
- comparator = NEQ;
- vstr = &cstr[2];
- } else {
- return -1;
- }
- break;
- default:
- return -1;
- }
- value = (int) strtol(vstr, &response, 0);
- if (response == vstr) {
- /* Not a valid number. */
- return -1;
- }
- *cstr = '\0';
- } else {
- comparator = NONE;
- }
- switch (word[0]) {
- case 'b':
- if (!strcmp(word, "bpp")) {
- criterion[0].capability = DM_PIXEL_DEPTH;
- if (comparator == NONE) {
- return -1;
- } else {
- criterion[0].comparison = comparator;
- criterion[0].value = value;
- return 1;
- }
- }
- return -1;
- case 'h':
- if (!strcmp(word, "height")) {
- criterion[0].capability = DM_HEIGHT;
- if (comparator == NONE) {
- return -1;
- } else {
- criterion[0].comparison = comparator;
- criterion[0].value = value;
- return 1;
- }
- }
- if (!strcmp(word, "hertz")) {
- criterion[0].capability = DM_HERTZ;
- if (comparator == NONE) {
- return -1;
- } else {
- criterion[0].comparison = comparator;
- criterion[0].value = value;
- return 1;
- }
- }
- return -1;
- case 'n':
- if (!strcmp(word, "num")) {
- criterion[0].capability = DM_NUM;
- if (comparator == NONE) {
- return -1;
- } else {
- criterion[0].comparison = comparator;
- criterion[0].value = value;
- return 1;
- }
- }
- return -1;
- case 'w':
- if (!strcmp(word, "width")) {
- criterion[0].capability = DM_WIDTH;
- if (comparator == NONE) {
- return -1;
- } else {
- criterion[0].comparison = comparator;
- criterion[0].value = value;
- return 1;
- }
- }
- return -1;
- }
- if (comparator == NONE) {
- return specialCaseParse(word, criterion, 0);
- }
- return -1;
-}
-
-/* This routine is based on similiar code in glut_dstr.c */
-static Criterion *
-parseDisplayString(const char *display, int *ncriteria)
-{
- Criterion *criteria = NULL;
- int n, parsed;
- char *copy, *word;
-
- copy = __glutStrdup(display);
- /* Attempt to estimate how many criteria entries should be
- needed. */
- n = 0;
- word = strtok(copy, " \t");
- while (word) {
- n++;
- word = strtok(NULL, " \t");
- }
- /* Allocate number of words of criteria. A word
- could contain as many as four criteria in the
- worst case. Example: 800x600:16@60 */
- criteria = (Criterion *) malloc(4 * n * sizeof(Criterion));
- if (!criteria) {
- __glutFatalError("out of memory.");
- }
-
- /* Re-copy the copy of the display string. */
- strcpy(copy, display);
-
- n = 0;
- word = strtok(copy, " \t");
- while (word) {
- parsed = parseCriteria(word, &criteria[n]);
- if (parsed >= 0) {
- n += parsed;
- } else {
- __glutWarning("Unrecognized game mode string word: %s (ignoring)\n", word);
- }
- word = strtok(NULL, " \t");
- }
-
- free(copy);
- *ncriteria = n;
- return criteria;
-}
-
-void GLUTAPIENTRY
-glutGameModeString(const char *string)
-{
- Criterion *criteria;
- int ncriteria;
-
- initGameModeSupport();
- criteria = parseDisplayString(string, &ncriteria);
- currentDm = findMatch(dmodes, ndmodes, criteria, ncriteria);
- free(criteria);
-}
-
-int GLUTAPIENTRY
-glutEnterGameMode(void)
-{
- GLUTwindow *window;
- int width, height;
- Window win;
-
- if (__glutMappedMenu) {
- __glutFatalUsage("entering game mode not allowed while menus in use");
- }
- if (__glutGameModeWindow) {
- /* Already in game mode, so blow away game mode
- window so apps can change resolutions. */
- window = __glutGameModeWindow;
- /* Setting the game mode window to NULL tricks
- the window destroy code into not undoing the
- screen display change since we plan on immediately
- doing another mode change. */
- __glutGameModeWindow = NULL;
- __glutDestroyWindow(window, window);
- }
-
- /* Assume default screen size until we find out if we
- can actually change the display settings. */
- width = __glutScreenWidth;
- height = __glutScreenHeight;
-
- if (currentDm) {
-#ifdef _WIN32
- LONG status;
- static int registered = 0;
-
- status = ChangeDisplaySettings(&currentDm->devmode,
- CDS_FULLSCREEN);
- if (status == DISP_CHANGE_SUCCESSFUL) {
- __glutDisplaySettingsChanged = 1;
- width = currentDm->cap[DM_WIDTH];
- height = currentDm->cap[DM_HEIGHT];
- if (!registered) {
- atexit(__glutCloseDownGameMode);
- registered = 1;
- }
- } else {
- /* Switch back to default resolution. */
- ChangeDisplaySettings(NULL, 0);
- }
-#endif
- }
-
- window = __glutCreateWindow(NULL, 0, 0,
- width, height, /* game mode */ 1);
- win = window->win;
-
-#if !defined(_WIN32) && !defined(__OS2__)
- if (__glutMotifHints == None) {
- __glutMotifHints = XSGIFastInternAtom(__glutDisplay, "_MOTIF_WM_HINTS",
- SGI_XA__MOTIF_WM_HINTS, 0);
- if (__glutMotifHints == None) {
- __glutWarning("Could not intern X atom for _MOTIF_WM_HINTS.");
- }
- }
-
- /* Game mode window is a toplevel window. */
- XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
-#endif
-
- /* Schedule the fullscreen property to be added and to
- make sure the window is configured right. Win32
- doesn't need this. */
- window->desiredX = 0;
- window->desiredY = 0;
- window->desiredWidth = width;
- window->desiredHeight = height;
- window->desiredConfMask |= CWX | CWY | CWWidth | CWHeight;
-#ifdef _WIN32
- /* Win32 does not want to use GLUT_FULL_SCREEN_WORK
- for game mode because we need to be maximizing
- the window in game mode, not just sizing it to
- take up the full screen. The Win32-ness of game
- mode happens when you pass 1 in the gameMode parameter
- to __glutCreateWindow above. A gameMode of creates
- a WS_POPUP window, not a standard WS_OVERLAPPEDWINDOW
- window. WS_POPUP ensures the taskbar is hidden. */
- __glutPutOnWorkList(window,
- GLUT_CONFIGURE_WORK);
-#else
- __glutPutOnWorkList(window,
- GLUT_CONFIGURE_WORK | GLUT_FULL_SCREEN_WORK);
-#endif
-
- __glutGameModeWindow = window;
- return window->num + 1;
-}
-
-int GLUTAPIENTRY
-glutGameModeGet(GLenum mode)
-{
- switch (mode) {
- case GLUT_GAME_MODE_ACTIVE:
- return __glutGameModeWindow != NULL;
- case GLUT_GAME_MODE_POSSIBLE:
- return currentDm != NULL;
- case GLUT_GAME_MODE_WIDTH:
- return currentDm ? currentDm->cap[DM_WIDTH] : -1;
- case GLUT_GAME_MODE_HEIGHT:
- return currentDm ? currentDm->cap[DM_HEIGHT] : -1;
- case GLUT_GAME_MODE_PIXEL_DEPTH:
- return currentDm ? currentDm->cap[DM_PIXEL_DEPTH] : -1;
- case GLUT_GAME_MODE_REFRESH_RATE:
- return currentDm ? currentDm->cap[DM_HERTZ] : -1;
- case GLUT_GAME_MODE_DISPLAY_CHANGED:
- return __glutDisplaySettingsChanged;
- default:
- return -1;
- }
-}
+
+/* Copyright (c) Mark J. Kilgard, 1998. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "glutint.h"
+
+#if !defined(_WIN32) && !defined(__OS2__)
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+/* SGI optimization introduced in IRIX 6.3 to avoid X server
+ round trips for interning common X atoms. */
+#if defined(_SGI_EXTRA_PREDEFINES) && !defined(NO_FAST_ATOMS)
+#include <X11/SGIFastAtom.h>
+#else
+#define XSGIFastInternAtom(dpy,string,fast_name,how) XInternAtom(dpy,string,how)
+#endif
+#endif /* not _WIN32 */
+
+int __glutDisplaySettingsChanged = 0;
+static DisplayMode *dmodes, *currentDm = NULL;
+static int ndmodes = -1;
+GLUTwindow *__glutGameModeWindow = NULL;
+
+#ifdef TEST
+static char *compstr[] =
+{
+ "none", "=", "!=", "<=", ">=", ">", "<", "~"
+};
+static char *capstr[] =
+{
+ "width", "height", "bpp", "hertz", "num"
+};
+#endif
+
+#if defined(__OS2__)
+void
+#else
+void __cdecl
+#endif
+__glutCloseDownGameMode(void)
+{
+ if (__glutDisplaySettingsChanged) {
+#ifdef _WIN32
+ /* Assumes that display settings have been changed, that
+ is __glutDisplaySettingsChanged is true. */
+ ChangeDisplaySettings(NULL, 0);
+#endif
+ __glutDisplaySettingsChanged = 0;
+ }
+ __glutGameModeWindow = NULL;
+}
+
+void GLUTAPIENTRY
+glutLeaveGameMode(void)
+{
+ if (__glutGameModeWindow == NULL) {
+ __glutWarning("not in game mode so cannot leave game mode");
+ return;
+ }
+ __glutDestroyWindow(__glutGameModeWindow,
+ __glutGameModeWindow);
+ XFlush(__glutDisplay);
+ __glutGameModeWindow = NULL;
+}
+
+#ifdef _WIN32
+
+/* Same values as from MSDN's SetDisp.c example. */
+#define MIN_WIDTH 400
+#define MIN_FREQUENCY 60
+
+static void
+initGameModeSupport(void)
+{
+ DEVMODE dm;
+ DWORD mode;
+ int i;
+
+ if (ndmodes >= 0) {
+ /* ndmodes is initially -1 to indicate no
+ dmodes allocated yet. */
+ return;
+ }
+
+ /* Determine how many display modes there are. */
+ ndmodes = 0;
+ mode = 0;
+ while (EnumDisplaySettings(NULL, mode, &dm)) {
+ if (dm.dmPelsWidth >= MIN_WIDTH &&
+ (dm.dmDisplayFrequency == 0 ||
+ dm.dmDisplayFrequency >= MIN_FREQUENCY)) {
+ ndmodes++;
+ }
+ mode++;
+ }
+
+ /* Allocate memory for a list of all the display modes. */
+ dmodes = (DisplayMode*)
+ malloc(ndmodes * sizeof(DisplayMode));
+
+ /* Now that we know how many display modes to expect,
+ enumerate them again and save the information in
+ the list we allocated above. */
+ i = 0;
+ mode = 0;
+ while (EnumDisplaySettings(NULL, mode, &dm)) {
+ /* Try to reject any display settings that seem unplausible. */
+ if (dm.dmPelsWidth >= MIN_WIDTH &&
+ (dm.dmDisplayFrequency == 0 ||
+ dm.dmDisplayFrequency >= MIN_FREQUENCY)) {
+ dmodes[i].devmode = dm;
+ dmodes[i].valid = 1; /* XXX Not used for now. */
+ dmodes[i].cap[DM_WIDTH] = dm.dmPelsWidth;
+ dmodes[i].cap[DM_HEIGHT] = dm.dmPelsHeight;
+ dmodes[i].cap[DM_PIXEL_DEPTH] = dm.dmBitsPerPel;
+ if (dm.dmDisplayFrequency == 0) {
+ /* Guess a reasonable guess. */
+ /* Lame Windows 95 version of EnumDisplaySettings. */
+ dmodes[i].cap[DM_HERTZ] = 60;
+ } else {
+ dmodes[i].cap[DM_HERTZ] = dm.dmDisplayFrequency;
+ }
+ i++;
+ }
+ mode++;
+ }
+
+ assert(i == ndmodes);
+}
+
+#else
+
+/* X Windows version of initGameModeSupport. */
+static void
+initGameModeSupport(void)
+{
+ if (ndmodes >= 0) {
+ /* ndmodes is initially -1 to indicate no
+ dmodes allocated yet. */
+ return;
+ }
+
+ /* Determine how many display modes there are. */
+ ndmodes = 0;
+}
+
+#endif
+
+/* This routine is based on similiar code in glut_dstr.c */
+static DisplayMode *
+findMatch(DisplayMode * dmodes, int ndmodes,
+ Criterion * criteria, int ncriteria)
+{
+ DisplayMode *found;
+ int *bestScore, *thisScore;
+ int i, j, numok, result = 0, worse, better;
+
+ found = NULL;
+ numok = 1; /* "num" capability is indexed from 1,
+ not 0. */
+
+ /* XXX alloca canidate. */
+ bestScore = (int *) malloc(ncriteria * sizeof(int));
+ if (!bestScore) {
+ __glutFatalError("out of memory.");
+ }
+ for (j = 0; j < ncriteria; j++) {
+ /* Very negative number. */
+ bestScore[j] = -32768;
+ }
+
+ /* XXX alloca canidate. */
+ thisScore = (int *) malloc(ncriteria * sizeof(int));
+ if (!thisScore) {
+ __glutFatalError("out of memory.");
+ }
+
+ for (i = 0; i < ndmodes; i++) {
+ if (dmodes[i].valid) {
+ worse = 0;
+ better = 0;
+
+ for (j = 0; j < ncriteria; j++) {
+ int cap, cvalue, dvalue;
+
+ cap = criteria[j].capability;
+ cvalue = criteria[j].value;
+ if (cap == NUM) {
+ dvalue = numok;
+ } else {
+ dvalue = dmodes[i].cap[cap];
+ }
+#ifdef TEST
+ if (verbose)
+ printf(" %s %s %d to %d\n",
+ capstr[cap], compstr[criteria[j].comparison], cvalue, dvalue);
+#endif
+ switch (criteria[j].comparison) {
+ case EQ:
+ result = cvalue == dvalue;
+ thisScore[j] = 1;
+ break;
+ case NEQ:
+ result = cvalue != dvalue;
+ thisScore[j] = 1;
+ break;
+ case LT:
+ result = dvalue < cvalue;
+ thisScore[j] = dvalue - cvalue;
+ break;
+ case GT:
+ result = dvalue > cvalue;
+ thisScore[j] = dvalue - cvalue;
+ break;
+ case LTE:
+ result = dvalue <= cvalue;
+ thisScore[j] = dvalue - cvalue;
+ break;
+ case GTE:
+ result = (dvalue >= cvalue);
+ thisScore[j] = dvalue - cvalue;
+ break;
+ case MIN:
+ result = dvalue >= cvalue;
+ thisScore[j] = cvalue - dvalue;
+ break;
+ }
+
+#ifdef TEST
+ if (verbose)
+ printf(" result=%d score=%d bestScore=%d\n", result, thisScore[j], bestScore[j]);
+#endif
+
+ if (result) {
+ if (better || thisScore[j] > bestScore[j]) {
+ better = 1;
+ } else if (thisScore[j] == bestScore[j]) {
+ /* Keep looking. */
+ } else {
+ goto nextDM;
+ }
+ } else {
+ if (cap == NUM) {
+ worse = 1;
+ } else {
+ goto nextDM;
+ }
+ }
+
+ }
+
+ if (better && !worse) {
+ found = &dmodes[i];
+ for (j = 0; j < ncriteria; j++) {
+ bestScore[j] = thisScore[j];
+ }
+ }
+ numok++;
+
+ nextDM:;
+
+ }
+ }
+ free(bestScore);
+ free(thisScore);
+ return found;
+}
+
+/**
+ * Parses strings in the form of:
+ * 800x600
+ * 800x600:16
+ * 800x600@60
+ * 800x600:16@60
+ * @60
+ * :16
+ * :16@60
+ * NOTE that @ before : is not parsed.
+ */
+static int
+specialCaseParse(char *word, Criterion * criterion, int mask)
+{
+ char *xstr, *response;
+ int got;
+ int width, height, bpp, hertz;
+
+ switch(word[0]) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ /* The WWWxHHH case. */
+ if (mask & (1 << DM_WIDTH)) {
+ return -1;
+ }
+ xstr = strpbrk(&word[1], "x");
+ if (xstr) {
+ width = (int) strtol(word, &response, 0);
+ if (response == word || response[0] != 'x') {
+ /* Not a valid number OR needs to be followed by 'x'. */
+ return -1;
+ }
+ height = (int) strtol(&xstr[1], &response, 0);
+ if (response == &xstr[1]) {
+ /* Not a valid number. */
+ return -1;
+ }
+ criterion[0].capability = DM_WIDTH;
+ criterion[0].comparison = EQ;
+ criterion[0].value = width;
+ criterion[1].capability = DM_HEIGHT;
+ criterion[1].comparison = EQ;
+ criterion[1].value = height;
+ got = specialCaseParse(response,
+ &criterion[2], 1 << DM_WIDTH);
+ if (got >= 0) {
+ return got + 2;
+ } else {
+ return -1;
+ }
+ }
+ return -1;
+ case ':':
+ /* The :BPP case. */
+ if (mask & (1 << DM_PIXEL_DEPTH)) {
+ return -1;
+ }
+ bpp = (int) strtol(&word[1], &response, 0);
+ if (response == &word[1]) {
+ /* Not a valid number. */
+ return -1;
+ }
+ criterion[0].capability = DM_PIXEL_DEPTH;
+ criterion[0].comparison = EQ;
+ criterion[0].value = bpp;
+ got = specialCaseParse(response,
+ &criterion[1], (1 << DM_WIDTH) | (1 << DM_PIXEL_DEPTH));
+ if (got >= 0) {
+ return got + 1;
+ } else {
+ return -1;
+ }
+ case '@':
+ /* The @HZ case. */
+ if (mask & (1 << DM_HERTZ)) {
+ return -1;
+ }
+ hertz = (int) strtol(&word[1], &response, 0);
+ if (response == &word[1]) {
+ /* Not a valid number. */
+ return -1;
+ }
+ criterion[0].capability = DM_HERTZ;
+ criterion[0].comparison = EQ;
+ criterion[0].value = hertz;
+ got = specialCaseParse(response,
+ &criterion[1], ~DM_HERTZ);
+ if (got >= 0) {
+ return got + 1;
+ } else {
+ return -1;
+ }
+ case '\0':
+ return 0;
+ }
+ return -1;
+}
+
+/* This routine is based on similiar code in glut_dstr.c */
+static int
+parseCriteria(char *word, Criterion * criterion)
+{
+ char *cstr, *vstr, *response;
+ int comparator, value = 0;
+
+ cstr = strpbrk(word, "=><!~");
+ if (cstr) {
+ switch (cstr[0]) {
+ case '=':
+ comparator = EQ;
+ vstr = &cstr[1];
+ break;
+ case '~':
+ comparator = MIN;
+ vstr = &cstr[1];
+ break;
+ case '>':
+ if (cstr[1] == '=') {
+ comparator = GTE;
+ vstr = &cstr[2];
+ } else {
+ comparator = GT;
+ vstr = &cstr[1];
+ }
+ break;
+ case '<':
+ if (cstr[1] == '=') {
+ comparator = LTE;
+ vstr = &cstr[2];
+ } else {
+ comparator = LT;
+ vstr = &cstr[1];
+ }
+ break;
+ case '!':
+ if (cstr[1] == '=') {
+ comparator = NEQ;
+ vstr = &cstr[2];
+ } else {
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ }
+ value = (int) strtol(vstr, &response, 0);
+ if (response == vstr) {
+ /* Not a valid number. */
+ return -1;
+ }
+ *cstr = '\0';
+ } else {
+ comparator = NONE;
+ }
+ switch (word[0]) {
+ case 'b':
+ if (!strcmp(word, "bpp")) {
+ criterion[0].capability = DM_PIXEL_DEPTH;
+ if (comparator == NONE) {
+ return -1;
+ } else {
+ criterion[0].comparison = comparator;
+ criterion[0].value = value;
+ return 1;
+ }
+ }
+ return -1;
+ case 'h':
+ if (!strcmp(word, "height")) {
+ criterion[0].capability = DM_HEIGHT;
+ if (comparator == NONE) {
+ return -1;
+ } else {
+ criterion[0].comparison = comparator;
+ criterion[0].value = value;
+ return 1;
+ }
+ }
+ if (!strcmp(word, "hertz")) {
+ criterion[0].capability = DM_HERTZ;
+ if (comparator == NONE) {
+ return -1;
+ } else {
+ criterion[0].comparison = comparator;
+ criterion[0].value = value;
+ return 1;
+ }
+ }
+ return -1;
+ case 'n':
+ if (!strcmp(word, "num")) {
+ criterion[0].capability = DM_NUM;
+ if (comparator == NONE) {
+ return -1;
+ } else {
+ criterion[0].comparison = comparator;
+ criterion[0].value = value;
+ return 1;
+ }
+ }
+ return -1;
+ case 'w':
+ if (!strcmp(word, "width")) {
+ criterion[0].capability = DM_WIDTH;
+ if (comparator == NONE) {
+ return -1;
+ } else {
+ criterion[0].comparison = comparator;
+ criterion[0].value = value;
+ return 1;
+ }
+ }
+ return -1;
+ }
+ if (comparator == NONE) {
+ return specialCaseParse(word, criterion, 0);
+ }
+ return -1;
+}
+
+/* This routine is based on similiar code in glut_dstr.c */
+static Criterion *
+parseDisplayString(const char *display, int *ncriteria)
+{
+ Criterion *criteria = NULL;
+ int n, parsed;
+ char *copy, *word;
+
+ copy = __glutStrdup(display);
+ /* Attempt to estimate how many criteria entries should be
+ needed. */
+ n = 0;
+ word = strtok(copy, " \t");
+ while (word) {
+ n++;
+ word = strtok(NULL, " \t");
+ }
+ /* Allocate number of words of criteria. A word
+ could contain as many as four criteria in the
+ worst case. Example: 800x600:16@60 */
+ criteria = (Criterion *) malloc(4 * n * sizeof(Criterion));
+ if (!criteria) {
+ __glutFatalError("out of memory.");
+ }
+
+ /* Re-copy the copy of the display string. */
+ strcpy(copy, display);
+
+ n = 0;
+ word = strtok(copy, " \t");
+ while (word) {
+ parsed = parseCriteria(word, &criteria[n]);
+ if (parsed >= 0) {
+ n += parsed;
+ } else {
+ __glutWarning("Unrecognized game mode string word: %s (ignoring)\n", word);
+ }
+ word = strtok(NULL, " \t");
+ }
+
+ free(copy);
+ *ncriteria = n;
+ return criteria;
+}
+
+void GLUTAPIENTRY
+glutGameModeString(const char *string)
+{
+ Criterion *criteria;
+ int ncriteria;
+
+ initGameModeSupport();
+ criteria = parseDisplayString(string, &ncriteria);
+ currentDm = findMatch(dmodes, ndmodes, criteria, ncriteria);
+ free(criteria);
+}
+
+int GLUTAPIENTRY
+glutEnterGameMode(void)
+{
+ GLUTwindow *window;
+ int width, height;
+ Window win;
+
+ if (__glutMappedMenu) {
+ __glutFatalUsage("entering game mode not allowed while menus in use");
+ }
+ if (__glutGameModeWindow) {
+ /* Already in game mode, so blow away game mode
+ window so apps can change resolutions. */
+ window = __glutGameModeWindow;
+ /* Setting the game mode window to NULL tricks
+ the window destroy code into not undoing the
+ screen display change since we plan on immediately
+ doing another mode change. */
+ __glutGameModeWindow = NULL;
+ __glutDestroyWindow(window, window);
+ }
+
+ /* Assume default screen size until we find out if we
+ can actually change the display settings. */
+ width = __glutScreenWidth;
+ height = __glutScreenHeight;
+
+ if (currentDm) {
+#ifdef _WIN32
+ LONG status;
+ static int registered = 0;
+
+ status = ChangeDisplaySettings(&currentDm->devmode,
+ CDS_FULLSCREEN);
+ if (status == DISP_CHANGE_SUCCESSFUL) {
+ __glutDisplaySettingsChanged = 1;
+ width = currentDm->cap[DM_WIDTH];
+ height = currentDm->cap[DM_HEIGHT];
+ if (!registered) {
+ atexit(__glutCloseDownGameMode);
+ registered = 1;
+ }
+ } else {
+ /* Switch back to default resolution. */
+ ChangeDisplaySettings(NULL, 0);
+ }
+#endif
+ }
+
+ window = __glutCreateWindow(NULL, 0, 0,
+ width, height, /* game mode */ 1);
+ win = window->win;
+
+#if !defined(_WIN32) && !defined(__OS2__)
+ if (__glutMotifHints == None) {
+ __glutMotifHints = XSGIFastInternAtom(__glutDisplay, "_MOTIF_WM_HINTS",
+ SGI_XA__MOTIF_WM_HINTS, 0);
+ if (__glutMotifHints == None) {
+ __glutWarning("Could not intern X atom for _MOTIF_WM_HINTS.");
+ }
+ }
+
+ /* Game mode window is a toplevel window. */
+ XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
+#endif
+
+ /* Schedule the fullscreen property to be added and to
+ make sure the window is configured right. Win32
+ doesn't need this. */
+ window->desiredX = 0;
+ window->desiredY = 0;
+ window->desiredWidth = width;
+ window->desiredHeight = height;
+ window->desiredConfMask |= CWX | CWY | CWWidth | CWHeight;
+#ifdef _WIN32
+ /* Win32 does not want to use GLUT_FULL_SCREEN_WORK
+ for game mode because we need to be maximizing
+ the window in game mode, not just sizing it to
+ take up the full screen. The Win32-ness of game
+ mode happens when you pass 1 in the gameMode parameter
+ to __glutCreateWindow above. A gameMode of creates
+ a WS_POPUP window, not a standard WS_OVERLAPPEDWINDOW
+ window. WS_POPUP ensures the taskbar is hidden. */
+ __glutPutOnWorkList(window,
+ GLUT_CONFIGURE_WORK);
+#else
+ __glutPutOnWorkList(window,
+ GLUT_CONFIGURE_WORK | GLUT_FULL_SCREEN_WORK);
+#endif
+
+ __glutGameModeWindow = window;
+ return window->num + 1;
+}
+
+int GLUTAPIENTRY
+glutGameModeGet(GLenum mode)
+{
+ switch (mode) {
+ case GLUT_GAME_MODE_ACTIVE:
+ return __glutGameModeWindow != NULL;
+ case GLUT_GAME_MODE_POSSIBLE:
+ return currentDm != NULL;
+ case GLUT_GAME_MODE_WIDTH:
+ return currentDm ? currentDm->cap[DM_WIDTH] : -1;
+ case GLUT_GAME_MODE_HEIGHT:
+ return currentDm ? currentDm->cap[DM_HEIGHT] : -1;
+ case GLUT_GAME_MODE_PIXEL_DEPTH:
+ return currentDm ? currentDm->cap[DM_PIXEL_DEPTH] : -1;
+ case GLUT_GAME_MODE_REFRESH_RATE:
+ return currentDm ? currentDm->cap[DM_HERTZ] : -1;
+ case GLUT_GAME_MODE_DISPLAY_CHANGED:
+ return __glutDisplaySettingsChanged;
+ default:
+ return -1;
+ }
+}
 \ No newline at end of file
diff --git a/src/glut/os2/glut_win.cpp b/src/glut/os2/glut_win.cpp
index 82abba87e4..53ff5d5d95 100644
--- a/src/glut/os2/glut_win.cpp
+++ b/src/glut/os2/glut_win.cpp
@@ -1,1221 +1,1221 @@
-
-/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
-
-/* This program is freely distributable without licensing fees
- and is provided without guarantee or warrantee expressed or
- implied. This program is -not- in the public domain. */
-
-#ifdef __VMS
-#include <GL/vms_x_fix.h>
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#if defined(__OS2__)
-#define POKA 0
- #include "WarpGL.h"
- #include "glutos2.h"
- #include "glutint.h"
-
- #include "gl\os2mesa.h"
-
-//
-//define for resource id for main GLUT window, in samples it is defined in GL_TEST.h
- #define ID_WINDOW 256
-
- int evglSetPixelFormat(int iPixelFormat);
- HPS hpsCurrent;
-
-#elif !defined(_WIN32)
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#endif
-
-#include "glutint.h"
-
-GLUTwindow *__glutCurrentWindow = NULL;
-GLUTwindow **__glutWindowList = NULL;
-int __glutWindowListSize = 0;
-#if !defined(_WIN32) && !defined(__OS2__)
-GLUTstale *__glutStaleWindowList = NULL;
-#endif
-GLUTwindow *__glutMenuWindow = NULL;
-
-void (*__glutFreeOverlayFunc) (GLUToverlay *);
-XVisualInfo *(*__glutDetermineVisualFromString) (char *string, Bool * treatAsSingle,
- Criterion * requiredCriteria, int nRequired, int requiredMask, void** fbc) = NULL;
-
-static Criterion requiredWindowCriteria[] =
-{
- {LEVEL, EQ, 0},
- {TRANSPARENT, EQ, 0}
-};
-static int numRequiredWindowCriteria = sizeof(requiredWindowCriteria) / sizeof(Criterion);
-static int requiredWindowCriteriaMask = (1 << LEVEL) | (1 << TRANSPARENT);
-
-static void
-cleanWindowWorkList(GLUTwindow * window)
-{
- GLUTwindow **pEntry = &__glutWindowWorkList;
- GLUTwindow *entry = __glutWindowWorkList;
-
- /* Tranverse singly-linked window work list look for the
- window. */
- while (entry) {
- if (entry == window) {
- /* Found it; delete it. */
- *pEntry = entry->prevWorkWin;
- return;
- } else {
- pEntry = &entry->prevWorkWin;
- entry = *pEntry;
- }
- }
-}
-
-#if !defined(_WIN32) && !defined(__OS2PM__)
-
-static void
-cleanStaleWindowList(GLUTwindow * window)
-{
- GLUTstale **pEntry = &__glutStaleWindowList;
- GLUTstale *entry = __glutStaleWindowList;
-
- /* Tranverse singly-linked stale window list look for the
- window ID. */
- while (entry) {
- if (entry->window == window) {
- /* Found it; delete it. */
- *pEntry = entry->next;
- free(entry);
- return;
- } else {
- pEntry = &entry->next;
- entry = *pEntry;
- }
- }
-}
-
-#endif
-
-static GLUTwindow *__glutWindowCache = NULL;
-
-GLUTwindow *
-__glutGetWindow(Window win)
-{
- int i;
-
- /* Does win belong to the last window ID looked up? */
- if (__glutWindowCache && (win == __glutWindowCache->win ||
- (__glutWindowCache->overlay && win ==
- __glutWindowCache->overlay->win))) {
- return
- __glutWindowCache;
- }
- /* Otherwise scan the window list looking for the window ID. */
- for (i = 0; i < __glutWindowListSize; i++) {
- if (__glutWindowList[i]) {
- if (win == __glutWindowList[i]->win) {
- __glutWindowCache = __glutWindowList[i];
- return __glutWindowCache;
- }
- if (__glutWindowList[i]->overlay) {
- if (win == __glutWindowList[i]->overlay->win) {
- __glutWindowCache = __glutWindowList[i];
- return __glutWindowCache;
- }
- }
- }
- }
-#if !defined(_WIN32) && !defined(__OS2PM__)
- {
- GLUTstale *entry;
-
- /* Scan through destroyed overlay window IDs for which no
- DestroyNotify has yet been received. */
- for (entry = __glutStaleWindowList; entry; entry = entry->next) {
- if (entry->win == win)
- return entry->window;
- }
- }
-#endif
- return NULL;
-}
-
-/* CENTRY */
-int GLUTAPIENTRY
-glutGetWindow(void)
-{
- if (__glutCurrentWindow) {
- return __glutCurrentWindow->num + 1;
- } else {
- return 0;
- }
-}
-/* ENDCENTRY */
-
-void
-__glutSetWindow(GLUTwindow * window)
-{
- /* It is tempting to try to short-circuit the call to
- glXMakeCurrent if we "know" we are going to make current
- to a window we are already current to. In fact, this
- assumption breaks when GLUT is expected to integrated with
- other OpenGL windowing APIs that also make current to
- OpenGL contexts. Since glXMakeCurrent short-circuits the
- "already bound" case, GLUT avoids the temptation to do so
- too. */
- __glutCurrentWindow = window;
-
- MAKE_CURRENT_LAYER(__glutCurrentWindow);
-
-#if !defined(_WIN32) && !defined(__OS2__)
- /* We should be careful to force a finish between each
- iteration through the GLUT main loop if indirect OpenGL
- contexts are in use; indirect contexts tend to have much
- longer latency because lots of OpenGL extension requests
- can queue up in the X protocol stream. We accomplish this
- by posting GLUT_FINISH_WORK to be done. */
- if (!__glutCurrentWindow->isDirect)
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_FINISH_WORK);
-#endif
-
- /* If debugging is enabled, we'll want to check this window
- for any OpenGL errors every iteration through the GLUT
- main loop. To accomplish this, we post the
- GLUT_DEBUG_WORK to be done on this window. */
- if (__glutDebug) {
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_DEBUG_WORK);
- }
-}
-
-/* CENTRY */
-void GLUTAPIENTRY
-glutSetWindow(int win)
-{
- GLUTwindow *window;
-
- if (win < 1 || win > __glutWindowListSize) {
- __glutWarning("glutSetWindow attempted on bogus window.");
- return;
- }
- window = __glutWindowList[win - 1];
- if (!window) {
- __glutWarning("glutSetWindow attempted on bogus window.");
- return;
- }
- __glutSetWindow(window);
-}
-/* ENDCENTRY */
-
-static int
-getUnusedWindowSlot(void)
-{
- int i;
-
- /* Look for allocated, unused slot. */
- for (i = 0; i < __glutWindowListSize; i++) {
- if (!__glutWindowList[i]) {
- return i;
- }
- }
- /* Allocate a new slot. */
- __glutWindowListSize++;
- if (__glutWindowList) {
- __glutWindowList = (GLUTwindow **)
- realloc(__glutWindowList,
- __glutWindowListSize * sizeof(GLUTwindow *));
- } else {
- /* XXX Some realloc's do not correctly perform a malloc
- when asked to perform a realloc on a NULL pointer,
- though the ANSI C library spec requires this. */
- __glutWindowList = (GLUTwindow **)
- malloc(sizeof(GLUTwindow *));
- }
- if (!__glutWindowList)
- __glutFatalError("out of memory.");
- __glutWindowList[__glutWindowListSize - 1] = NULL;
- return __glutWindowListSize - 1;
-}
-
-static XVisualInfo *
-getVisualInfoCI(unsigned int mode)
-{
-#if POKA
- static int bufSizeList[] =
- {16, 12, 8, 4, 2, 1, 0};
- XVisualInfo *vi;
- int list[32];
- int i, n = 0;
-
- /* Should not be looking at display mode mask if
- __glutDisplayString is non-NULL. */
- assert(!__glutDisplayString);
-
- list[n++] = GLX_BUFFER_SIZE;
- list[n++] = 1;
- if (GLUT_WIND_IS_DOUBLE(mode)) {
- list[n++] = GLX_DOUBLEBUFFER;
- }
- if (GLUT_WIND_IS_STEREO(mode)) {
- list[n++] = GLX_STEREO;
- }
- if (GLUT_WIND_HAS_DEPTH(mode)) {
- list[n++] = GLX_DEPTH_SIZE;
- list[n++] = 1;
- }
- if (GLUT_WIND_HAS_STENCIL(mode)) {
- list[n++] = GLX_STENCIL_SIZE;
- list[n++] = 1;
- }
- list[n] = (int) None; /* terminate list */
-
- /* glXChooseVisual specify GLX_BUFFER_SIZE prefers the
- "smallest index buffer of at least the specified size".
- This would be reasonable if GLUT allowed the user to
- specify the required buffe size, but GLUT's display mode
- is too simplistic (easy to use?). GLUT should try to find
- the "largest". So start with a large buffer size and
- shrink until we find a matching one that exists. */
-
- for (i = 0; bufSizeList[i]; i++) {
- /* XXX Assumes list[1] is where GLX_BUFFER_SIZE parameter
- is. */
- list[1] = bufSizeList[i];
- vi = glXChooseVisual(__glutDisplay,
- __glutScreen, list);
- if (vi)
- return vi;
- }
- return NULL;
-#else
- return
- glXChooseVisual(mode);
-
-#endif
-}
-
-static XVisualInfo *
-getVisualInfoRGB(unsigned int mode)
-{
-#if POKA
- int list[32];
- int n = 0;
-
- /* Should not be looking at display mode mask if
- __glutDisplayString is non-NULL. */
- assert(!__glutDisplayString);
-
- /* XXX Would a caching mechanism to minize the calls to
- glXChooseVisual? You'd have to reference count
- XVisualInfo* pointers. Would also have to properly
- interact with glutInitDisplayString. */
-
- list[n++] = GLX_RGBA;
- list[n++] = GLX_RED_SIZE;
- list[n++] = 1;
- list[n++] = GLX_GREEN_SIZE;
- list[n++] = 1;
- list[n++] = GLX_BLUE_SIZE;
- list[n++] = 1;
- if (GLUT_WIND_HAS_ALPHA(mode)) {
- list[n++] = GLX_ALPHA_SIZE;
- list[n++] = 1;
- }
- if (GLUT_WIND_IS_DOUBLE(mode)) {
- list[n++] = GLX_DOUBLEBUFFER;
- }
- if (GLUT_WIND_IS_STEREO(mode)) {
- list[n++] = GLX_STEREO;
- }
- if (GLUT_WIND_HAS_DEPTH(mode)) {
- list[n++] = GLX_DEPTH_SIZE;
- list[n++] = 1;
- }
- if (GLUT_WIND_HAS_STENCIL(mode)) {
- list[n++] = GLX_STENCIL_SIZE;
- list[n++] = 1;
- }
- if (GLUT_WIND_HAS_ACCUM(mode)) {
- list[n++] = GLX_ACCUM_RED_SIZE;
- list[n++] = 1;
- list[n++] = GLX_ACCUM_GREEN_SIZE;
- list[n++] = 1;
- list[n++] = GLX_ACCUM_BLUE_SIZE;
- list[n++] = 1;
- if (GLUT_WIND_HAS_ALPHA(mode)) {
- list[n++] = GLX_ACCUM_ALPHA_SIZE;
- list[n++] = 1;
- }
- }
-#if defined(GLX_VERSION_1_1) && (defined(GLX_SGIS_multisample) || defined(GLX_ARB_multisample))
- if (GLUT_WIND_IS_MULTISAMPLE(mode)) {
- if (!__glutIsSupportedByGLX("GLX_SGIS_multisample") &&
- !__glutIsSupportedByGLX("GLX_ARB_multisample"))
- return NULL;
-#if defined(GLX_ARB_multisample)
- list[n++] = GLX_SAMPLES_ARB;
-#elif defined(GLX_SGIS_multisample)
- list[n++] = GLX_SAMPLES_SGIS;
-#endif
- /* XXX Is 4 a reasonable minimum acceptable number of
- samples? */
- list[n++] = 4;
- }
-#endif
- list[n] = (int) None; /* terminate list */
-
- return glXChooseVisual(__glutDisplay,
- __glutScreen, list);
-#else /* POKA */
-
- return
- glXChooseVisual(mode);
-
-#endif
-}
-
-XVisualInfo *
-__glutGetVisualInfo(unsigned int mode)
-{
- /* XXX GLUT_LUMINANCE not implemented for GLUT 3.0. */
- if (GLUT_WIND_IS_LUMINANCE(mode))
- return NULL;
-
- if (GLUT_WIND_IS_RGB(mode))
- return getVisualInfoRGB(mode);
- else
- return getVisualInfoCI(mode);
-}
-
-XVisualInfo *
-__glutDetermineVisual(
- unsigned int displayMode,
- Bool * treatAsSingle,
- XVisualInfo * (getVisualInfo) (unsigned int))
-{
- XVisualInfo *vis;
-
- /* Should not be looking at display mode mask if
- __glutDisplayString is non-NULL. */
- assert(!__glutDisplayString);
-
- *treatAsSingle = GLUT_WIND_IS_SINGLE(displayMode);
- vis = getVisualInfo(displayMode);
- if (!vis) {
- /* Fallback cases when can't get exactly what was asked
- for... */
- if (GLUT_WIND_IS_SINGLE(displayMode)) {
- /* If we can't find a single buffered visual, try looking
- for a double buffered visual. We can treat a double
- buffered visual as a single buffer visual by changing
- the draw buffer to GL_FRONT and treating any swap
- buffers as no-ops. */
- displayMode |= GLUT_DOUBLE;
- vis = getVisualInfo(displayMode);
- *treatAsSingle = True;
- }
- if (!vis && GLUT_WIND_IS_MULTISAMPLE(displayMode)) {
- /* If we can't seem to get multisampling (ie, not Reality
- Engine class graphics!), go without multisampling. It
- is up to the application to query how many multisamples
- were allocated (0 equals no multisampling) if the
- application is going to use multisampling for more than
- just antialiasing. */
- displayMode &= ~GLUT_MULTISAMPLE;
- vis = getVisualInfo(displayMode);
- }
- }
- return vis;
-}
-
-static void GLUTCALLBACK
-__glutDefaultDisplay(void)
-{
- /* XXX Remove the warning after GLUT 3.0. */
- __glutWarning("The following is a new check for GLUT 3.0; update your code.");
- __glutFatalError(
- "redisplay needed for window %d, but no display callback.",
- __glutCurrentWindow->num + 1);
-}
-
-void GLUTCALLBACK
-__glutDefaultReshape(int width, int height)
-{
- GLUToverlay *overlay;
-
- /* Adjust the viewport of the window (and overlay if one
- exists). */
- MAKE_CURRENT_WINDOW(__glutCurrentWindow);
- glViewport(0, 0, (GLsizei) width, (GLsizei) height);
- overlay = __glutCurrentWindow->overlay;
- if (overlay) {
- MAKE_CURRENT_OVERLAY(overlay);
- glViewport(0, 0, (GLsizei) width, (GLsizei) height);
- }
- /* Make sure we are current to the current layer (application
- should be able to count on the current layer not changing
- unless the application explicitly calls glutUseLayer). */
- MAKE_CURRENT_LAYER(__glutCurrentWindow);
-}
-
-XVisualInfo *
-__glutDetermineWindowVisual(Bool * treatAsSingle, Bool * visAlloced, void **fbc)
-{
- if (__glutDisplayString) {
-
- /* __glutDisplayString should be NULL except if
- glutInitDisplayString has been called to register a
- different display string. Calling glutInitDisplayString
- means using a string instead of an integer mask determine
- the visual to use. Using the function pointer variable
- __glutDetermineVisualFromString below avoids linking in
- the code for implementing glutInitDisplayString (ie,
- glut_dstr.o) unless glutInitDisplayString gets called by
- the application. */
-
- assert(__glutDetermineVisualFromString);
- *visAlloced = False;
- *fbc = NULL;
- return __glutDetermineVisualFromString(__glutDisplayString, treatAsSingle,
- requiredWindowCriteria, numRequiredWindowCriteria, requiredWindowCriteriaMask, fbc);
- } else {
- *visAlloced = True;
- *fbc = NULL;
- return __glutDetermineVisual(__glutDisplayMode,
- treatAsSingle, __glutGetVisualInfo);
- }
-}
-
-/* ARGSUSED5 */ /* Only Win32 uses gameMode parameter. */
-GLUTwindow *
-__glutCreateWindow(GLUTwindow * parent,
- int x, int y, int width, int height, int gameMode)
-{
- GLUTwindow *window;
- XSetWindowAttributes wa;
- unsigned long attribMask;
- int winnum;
- int i;
-#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
- GLXFBConfigSGIX fbc;
-#else
- void *fbc;
-#endif
-
-#if defined(__OS2PM__)
- {
- extern HAB hab; /* PM anchor block handle */
- CLASSINFO classinfo;
-
- if(!WinQueryClassInfo(hab,"GLUT", &classinfo) )
- __glutOpenOS2Connection(NULL);
- }
-#elif defined(_WIN32)
- WNDCLASS wc;
- int style;
-
- if (!GetClassInfo(GetModuleHandle(NULL), "GLUT", &wc)) {
- __glutOpenWin32Connection(NULL);
- }
-#else
- if (!__glutDisplay) {
- __glutOpenXConnection(NULL);
- }
-#endif
-
-#ifndef __OS2PM__
- if (__glutGameModeWindow) {
- __glutFatalError("cannot create windows in game mode.");
- }
-#endif
-
- winnum = getUnusedWindowSlot();
- window = (GLUTwindow *) malloc(sizeof(GLUTwindow));
- if (!window) {
- __glutFatalError("out of memory.");
- }
- window->num = winnum;
-
-#if defined(__OS2PM__)
- /* Add this new window to the window list. */
- __glutWindowList[winnum] = window;
- window->shownState = -1;
-#endif
-
-#if !defined(_WIN32) && !defined(__OS2PM__)
- window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
- &window->visAlloced, (void**) &fbc);
- if (!window->vis) {
- __glutFatalError(
- "visual with necessary capabilities not found.");
- }
- __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
-#endif
- window->eventMask = StructureNotifyMask | ExposureMask;
-
- attribMask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
- wa.background_pixmap = None;
- wa.border_pixel = 0;
- wa.colormap = window->cmap;
- wa.event_mask = window->eventMask;
- if (parent) {
- if (parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
- wa.event_mask |= GLUT_HACK_STOP_PROPAGATE_MASK;
- attribMask |= CWDontPropagate;
- wa.do_not_propagate_mask = parent->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
- } else {
- wa.do_not_propagate_mask = 0;
- }
-
- /* Stash width and height before Win32's __glutAdjustCoords
- possibly overwrites the values. */
- window->width = width;
- window->height = height;
- window->forceReshape = True;
- window->ignoreKeyRepeat = False;
-
-#if defined(__OS2PM__)
-
- { ULONG flStyle=0;
- int ii;
- ERRORID erridErrorCode;/* last error id code */
- extern HAB hab; /* PM anchor block handle */
-
- if (parent) {
- flStyle = WS_CLIPCHILDREN|WS_VISIBLE;
- } else {
- if (gameMode) {
- /* Game mode window should be a WS_POPUP window to
- ensure that the taskbar is hidden by it. A standard
- WS_OVERLAPPEDWINDOW does not hide the task bar. */
- flStyle = FCF_STANDARD | WS_MAXIMIZED;
- } else {
- /* A standard toplevel window with borders and such. */
- flStyle = FCF_STANDARD | WS_CLIPCHILDREN;
-// flStyle = WS_OVERLAPPEDWINDOW;
- }
- }
-{
- HWND hwnd; /* Window */
- ULONG ListBoxId; /* Window id */
- /* (supplied by application) */
-
-
- HWND hwndClient; /* handle to the client */
- HWND hwndFrame; /* handle to the frame */
- PFNWP GenericWndProc;
- FRAMECDATA fcd;
- RECTL rect; /* Boundary rectangle */
-
-
-
-/************************************************/
-// flCreate = (FCF_STANDARD) & ~FCF_TASKLIST;
-/**********************************/
- if (parent)
- { window->frame = NULL;
-
- hwnd = WinCreateWindow(parent->win, /* Parent window */
- "GLUTCHILD", /* Class name */
- "", /* Window text */
- flStyle, /* Window style */
- x, y, /* Position (x,y) */
- width, height, /* Size (width,height) */
- parent->win, /* Owner window */
- HWND_TOP, /* Sibling window */
- 0, /* Window id */
- NULL, /* Control data */
- NULL); /* Pres parameters */
-
- erridErrorCode = WinGetLastError(hab);
- window->win = hwnd;
-
- window->hdc = WinOpenWindowDC(window->win);
- window->hpsBuffer = hpsCurrent;
-
-
- rect.xLeft = x;
- rect.xRight = x+width;
- rect.yBottom = y;
- rect.yTop = y + height;
-
-/***** else parent *****************************/
- } else {
- hwnd = WinCreateStdWindow(HWND_DESKTOP,
- 0, /* WS_VISIBLE frame-window style */
- &flStyle, /* window style */
- "GLUT", /* class name */
- "GLUT",/* window title */
- 0L, /* default client style */
- NULLHANDLE, /* resource in executable file */
- ID_WINDOW, /* resource id */
- &hwndClient); /* receives client window handle */
-
- erridErrorCode = WinGetLastError(hab);
- window->win = hwndClient;
- window->frame = hwnd;
- window->hdc = WinOpenWindowDC(window->win);
-
- window->hpsBuffer = hpsCurrent;
-
-
-/* converts a client window's boundaries into an equivalent frame rectangle */
- rect.xLeft = x;
- rect.xRight = x+width;
- rect.yBottom = y;
- rect.yTop = y + height;
-
- /* calculate equivalent frame boundary from boundary data */
- WinCalcFrameRect(window->frame, &rect, FALSE);
- }
-/***** endof if(parent) *****************************/
-
- /* Must set the XHDC for fake glXChooseVisual & fake
- glXCreateContext & fake XAllocColorCells. */
- XHDC = window->hdc;
- XHWND = window->win;
- window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
- &window->visAlloced, &fbc);
- if (!window->vis)
- { __glutFatalError(
- "pixel format with necessary capabilities not found.");
- }
- { int rc;
- rc = wglChoosePixelFormat(window->hdc, window->vis),
-
-// evglSetPixelFormat(2); /* int iPixelFormat 1 - doublebuffer/2 - single buffer ??*/
- wglSetPixelFormat(window->hdc,rc,window->vis);
- }
- __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
-
- window->ctx = glXCreateContext(window->hpsBuffer, window->vis,
- None, __glutTryDirect);
-
- WinSetWindowPos(hwnd,
- HWND_TOP,rect.xLeft,rect.yBottom,
- rect.xRight-rect.xLeft, rect.yTop-rect.yBottom,
- SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW|SWP_ZORDER); /* flags*/
-
- /* Make sure subwindows get a windowStatus callback. */
- if (parent)
- WinPostMsg(parent->win, WM_ACTIVATE, 0, 0);
-
- }
-}
-
-#elif defined(_WIN32)
-
- __glutAdjustCoords(parent ? parent->win : NULL,
- &x, &y, &width, &height);
- if (parent) {
- style = WS_CHILD;
- } else {
- if (gameMode) {
- /* Game mode window should be a WS_POPUP window to
- ensure that the taskbar is hidden by it. A standard
- WS_OVERLAPPEDWINDOW does not hide the task bar. */
- style = WS_POPUP | WS_MAXIMIZE;
- } else {
- /* A standard toplevel window with borders and such. */
- style = WS_OVERLAPPEDWINDOW;
- }
- }
- window->win = CreateWindow("GLUT", "GLUT",
- WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
- x, y, width, height, parent ? parent->win : __glutRoot,
- NULL, GetModuleHandle(NULL), 0);
- window->hdc = GetDC(window->win);
- /* Must set the XHDC for fake glXChooseVisual & fake
- glXCreateContext & fake XAllocColorCells. */
- XHDC = window->hdc;
- window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
- &window->visAlloced, &fbc);
- if (!window->vis) {
- __glutFatalError(
- "pixel format with necessary capabilities not found.");
- }
- if (!SetPixelFormat(window->hdc,
- ChoosePixelFormat(window->hdc, window->vis),
- window->vis)) {
- __glutFatalError("SetPixelFormat failed during window create.");
- }
- __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
- /* Make sure subwindows get a windowStatus callback. */
- if (parent) {
- PostMessage(parent->win, WM_ACTIVATE, 0, 0);
- }
- window->renderDc = window->hdc;
-#else
- window->win = XCreateWindow(__glutDisplay,
- parent == NULL ? __glutRoot : parent->win,
- x, y, width, height, 0,
- window->vis->depth, InputOutput, window->vis->visual,
- attribMask, &wa);
-#endif
- window->renderWin = window->win;
-#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
- if (fbc) {
- window->ctx = __glut_glXCreateContextWithConfigSGIX(__glutDisplay, fbc,
- GLX_RGBA_TYPE_SGIX, None, __glutTryDirect);
- } else
-#endif
-#if defined(__OS2PM__)
-// window->ctx = glXCreateContext(window->hpsBuffer, window->vis,
-// None, __glutTryDirect);
-#else
- window->ctx = glXCreateContext(__glutDisplay, window->vis,
- None, __glutTryDirect);
-#endif
- if (!window->ctx) {
- __glutFatalError(
- "failed to create OpenGL rendering context.");
- }
- window->renderCtx = window->ctx;
-#if !defined(_WIN32) && !defined(__OS2PM__)
- window->isDirect = glXIsDirect(__glutDisplay, window->ctx);
- if (__glutForceDirect) {
- if (!window->isDirect)
- __glutFatalError("direct rendering not possible.");
- }
-#endif
-
- window->parent = parent;
- if (parent) {
- window->siblings = parent->children;
- parent->children = window;
- } else {
- window->siblings = NULL;
- }
- window->overlay = NULL;
- window->children = NULL;
- window->display = __glutDefaultDisplay;
- window->reshape = __glutDefaultReshape;
- window->mouse = NULL;
- window->motion = NULL;
- window->passive = NULL;
- window->entry = NULL;
- window->keyboard = NULL;
- window->keyboardUp = NULL;
- window->windowStatus = NULL;
- window->visibility = NULL;
- window->special = NULL;
- window->specialUp = NULL;
- window->buttonBox = NULL;
- window->dials = NULL;
- window->spaceMotion = NULL;
- window->spaceRotate = NULL;
- window->spaceButton = NULL;
- window->tabletMotion = NULL;
- window->tabletButton = NULL;
-#ifdef _WIN32
- window->joystick = NULL;
- window->joyPollInterval = 0;
-#endif
-
-#if defined(__OS2PM__)
- window->wm_command = NULL;
-#endif
-
- window->tabletPos[0] = -1;
- window->tabletPos[1] = -1;
-#if defined(__OS2PM__)
- if(window->shownState == -1)
- window->shownState = 0;
- window->visState = window->shownState;
-#else
- window->shownState = 0;
- window->visState = -1; /* not VisibilityUnobscured,
- VisibilityPartiallyObscured, or
- VisibilityFullyObscured */
-#endif
- window->entryState = -1; /* not EnterNotify or LeaveNotify */
-
- window->desiredConfMask = 0;
- window->buttonUses = 0;
- window->cursor = GLUT_CURSOR_INHERIT;
-
- /* Setup window to be mapped when glutMainLoop starts. */
- window->workMask = GLUT_MAP_WORK;
-#ifdef _WIN32
- if (gameMode) {
- /* When mapping a game mode window, just show
- the window. We have already created the game
- mode window with a maximize flag at creation
- time. Doing a ShowWindow(window->win, SW_SHOWNORMAL)
- would be wrong for a game mode window since it
- would unmaximize the window. */
- window->desiredMapState = GameModeState;
- } else {
- window->desiredMapState = NormalState;
- }
-#else
- window->desiredMapState = NormalState;
-#endif
- window->prevWorkWin = __glutWindowWorkList;
- __glutWindowWorkList = window;
-
- /* Initially, no menus attached. */
- for (i = 0; i < GLUT_MAX_MENUS; i++) {
- window->menu[i] = 0;
- }
-
- /* Add this new window to the window list. */
- __glutWindowList[winnum] = window;
-
- /* Make the new window the current window. */
- __glutSetWindow(window);
-
- __glutDetermineMesaSwapHackSupport();
-
- if (window->treatAsSingle) {
- /* We do this because either the window really is single
- buffered (in which case this is redundant, but harmless,
- because this is the initial single-buffered context
- state); or we are treating a double buffered window as a
- single-buffered window because the system does not appear
- to export any suitable single- buffered visuals (in which
- the following are necessary). */
- glDrawBuffer(GL_FRONT);
- glReadBuffer(GL_FRONT);
- }
- return window;
-}
-
-/* CENTRY */
-int GLUTAPIENTRY
-glutCreateWindow(const char *title)
-{
- static int firstWindow = 1;
- GLUTwindow *window;
-#if !defined(_WIN32) && !defined(__OS2__)
- XWMHints *wmHints;
-#endif
- Window win;
- XTextProperty textprop;
-
- if (__glutGameModeWindow) {
- __glutFatalError("cannot create windows in game mode.");
- }
- window = __glutCreateWindow(NULL,
- __glutSizeHints.x, __glutSizeHints.y,
- __glutInitWidth, __glutInitHeight,
- /* not game mode */ 0);
- win = window->win;
- /* Setup ICCCM properties. */
- textprop.value = (unsigned char *) title;
- textprop.encoding = XA_STRING;
- textprop.format = 8;
- textprop.nitems = strlen(title);
-#if defined(__OS2__)
- WinSetWindowText(window->frame, (PCSZ)title);
- if (__glutIconic) {
- window->desiredMapState = IconicState;
- }
-#elif defined(_WIN32)
- SetWindowText(win, title);
- if (__glutIconic) {
- window->desiredMapState = IconicState;
- }
-#else
- wmHints = XAllocWMHints();
- wmHints->initial_state =
- __glutIconic ? IconicState : NormalState;
- wmHints->flags = StateHint;
- XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
- /* Only put WM_COMMAND property on first window. */
- firstWindow ? __glutArgv : NULL,
- firstWindow ? __glutArgc : 0,
- &__glutSizeHints, wmHints, NULL);
- XFree(wmHints);
- XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
-#endif
- firstWindow = 0;
- return window->num + 1;
-}
-
-#ifdef _WIN32
-int GLUTAPIENTRY
-__glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int))
-{
- __glutExitFunc = exitfunc;
- return glutCreateWindow(title);
-}
-#endif
-
-int GLUTAPIENTRY
-glutCreateSubWindow(int win, int x, int y, int width, int height)
-{
- GLUTwindow *window;
-
- window = __glutCreateWindow(__glutWindowList[win - 1],
- x, y, width, height, /* not game mode */ 0);
-#if !defined(_WIN32) && !defined(__OS2__)
- {
- GLUTwindow *toplevel;
-
- toplevel = __glutToplevelOf(window);
- if (toplevel->cmap != window->cmap) {
- __glutPutOnWorkList(toplevel, GLUT_COLORMAP_WORK);
- }
- }
-#endif
- return window->num + 1;
-}
-/* ENDCENTRY */
-
-void
-__glutDestroyWindow(GLUTwindow * window,
- GLUTwindow * initialWindow)
-{
- GLUTwindow **prev, *cur, *parent, *siblings;
-
- /* Recursively destroy any children. */
- cur = window->children;
- while (cur) {
- siblings = cur->siblings;
- __glutDestroyWindow(cur, initialWindow);
- cur = siblings;
- }
- /* Remove from parent's children list (only necessary for
- non-initial windows and subwindows!). */
- parent = window->parent;
- if (parent && parent == initialWindow->parent) {
- prev = &parent->children;
- cur = parent->children;
- while (cur) {
- if (cur == window) {
- *prev = cur->siblings;
- break;
- }
- prev = &(cur->siblings);
- cur = cur->siblings;
- }
- }
- /* Unbind if bound to this window. */
- if (window == __glutCurrentWindow) {
- UNMAKE_CURRENT();
- __glutCurrentWindow = NULL;
- }
- /* Begin tearing down window itself. */
- if (window->overlay) {
- __glutFreeOverlayFunc(window->overlay);
- }
- XDestroyWindow(__glutDisplay, window->win);
- glXDestroyContext(__glutDisplay, window->ctx);
- if (window->colormap) {
- /* Only color index windows have colormap data structure. */
- __glutFreeColormap(window->colormap);
- }
- /* NULLing the __glutWindowList helps detect is a window
- instance has been destroyed, given a window number. */
- __glutWindowList[window->num] = NULL;
-
- /* Cleanup data structures that might contain window. */
- cleanWindowWorkList(window);
-#if !defined(_WIN32) && !defined(__OS2__)
- cleanStaleWindowList(window);
-#endif
- /* Remove window from the "get window cache" if it is there. */
- if (__glutWindowCache == window)
- __glutWindowCache = NULL;
-
- if (window->visAlloced) {
- /* Only free XVisualInfo* gotten from glXChooseVisual. */
- XFree(window->vis);
- }
-
- if (window == __glutGameModeWindow) {
- /* Destroying the game mode window should implicitly
- have GLUT leave game mode. */
- __glutCloseDownGameMode();
- }
-
- free(window);
-}
-
-/* CENTRY */
-void GLUTAPIENTRY
-glutDestroyWindow(int win)
-{
- GLUTwindow *window = __glutWindowList[win - 1];
-
- if (__glutMappedMenu && __glutMenuWindow == window) {
- __glutFatalUsage("destroying menu window not allowed while menus in use");
- }
-#if !defined(_WIN32) && !defined(__OS2__)
- /* If not a toplevel window... */
- if (window->parent) {
- /* Destroying subwindows may change colormap requirements;
- recalculate toplevel window's WM_COLORMAP_WINDOWS
- property. */
- __glutPutOnWorkList(__glutToplevelOf(window->parent),
- GLUT_COLORMAP_WORK);
- }
-#endif
- __glutDestroyWindow(window, window);
- XFlush(__glutDisplay);
-}
-/* ENDCENTRY */
-
-void
-__glutChangeWindowEventMask(long eventMask, Bool add)
-{
- if (add) {
- /* Add eventMask to window's event mask. */
- if ((__glutCurrentWindow->eventMask & eventMask) !=
- eventMask) {
- __glutCurrentWindow->eventMask |= eventMask;
- __glutPutOnWorkList(__glutCurrentWindow,
- GLUT_EVENT_MASK_WORK);
- }
- } else {
- /* Remove eventMask from window's event mask. */
- if (__glutCurrentWindow->eventMask & eventMask) {
- __glutCurrentWindow->eventMask &= ~eventMask;
- __glutPutOnWorkList(__glutCurrentWindow,
- GLUT_EVENT_MASK_WORK);
- }
- }
-}
-
-void GLUTAPIENTRY
-glutDisplayFunc(GLUTdisplayCB displayFunc)
-{
- /* XXX Remove the warning after GLUT 3.0. */
- if (!displayFunc)
- __glutFatalError("NULL display callback not allowed in GLUT 3.0; update your code.");
- __glutCurrentWindow->display = displayFunc;
-}
-
-void GLUTAPIENTRY
-glutMouseFunc(GLUTmouseCB mouseFunc)
-{
- if (__glutCurrentWindow->mouse) {
- if (!mouseFunc) {
- /* Previous mouseFunc being disabled. */
- __glutCurrentWindow->buttonUses--;
- __glutChangeWindowEventMask(
- ButtonPressMask | ButtonReleaseMask,
- __glutCurrentWindow->buttonUses > 0);
- }
- } else {
- if (mouseFunc) {
- /* Previously no mouseFunc, new one being installed. */
- __glutCurrentWindow->buttonUses++;
- __glutChangeWindowEventMask(
- ButtonPressMask | ButtonReleaseMask, True);
- }
- }
- __glutCurrentWindow->mouse = mouseFunc;
-}
-
-void GLUTAPIENTRY
-glutMotionFunc(GLUTmotionCB motionFunc)
-{
- /* Hack. Some window managers (4Dwm by default) will mask
- motion events if the client is not selecting for button
- press and release events. So we select for press and
- release events too (being careful to use reference
- counting). */
- if (__glutCurrentWindow->motion) {
- if (!motionFunc) {
- /* previous mouseFunc being disabled */
- __glutCurrentWindow->buttonUses--;
- __glutChangeWindowEventMask(
- ButtonPressMask | ButtonReleaseMask,
- __glutCurrentWindow->buttonUses > 0);
- }
- } else {
- if (motionFunc) {
- /* Previously no mouseFunc, new one being installed. */
- __glutCurrentWindow->buttonUses++;
- __glutChangeWindowEventMask(
- ButtonPressMask | ButtonReleaseMask, True);
- }
- }
- /* Real work of selecting for passive mouse motion. */
- __glutChangeWindowEventMask(
- Button1MotionMask | Button2MotionMask | Button3MotionMask,
- motionFunc != NULL);
- __glutCurrentWindow->motion = motionFunc;
-}
-
-void GLUTAPIENTRY
-glutPassiveMotionFunc(GLUTpassiveCB passiveMotionFunc)
-{
- __glutChangeWindowEventMask(PointerMotionMask,
- passiveMotionFunc != NULL);
-
- /* Passive motion also requires watching enters and leaves so
- that a fake passive motion event can be generated on an
- enter. */
- __glutChangeWindowEventMask(EnterWindowMask | LeaveWindowMask,
- __glutCurrentWindow->entry != NULL || passiveMotionFunc != NULL);
-
- __glutCurrentWindow->passive = passiveMotionFunc;
-}
-
-void GLUTAPIENTRY
-glutEntryFunc(GLUTentryCB entryFunc)
-{
- __glutChangeWindowEventMask(EnterWindowMask | LeaveWindowMask,
- entryFunc != NULL || __glutCurrentWindow->passive);
- __glutCurrentWindow->entry = entryFunc;
- if (!entryFunc) {
- __glutCurrentWindow->entryState = -1;
- }
-}
-
-void GLUTAPIENTRY
-glutWindowStatusFunc(GLUTwindowStatusCB windowStatusFunc)
-{
- __glutChangeWindowEventMask(VisibilityChangeMask,
- windowStatusFunc != NULL);
- __glutCurrentWindow->windowStatus = windowStatusFunc;
- if (!windowStatusFunc) {
- /* Make state invalid. */
- __glutCurrentWindow->visState = -1;
- }
-}
-
-static void GLUTCALLBACK
-visibilityHelper(int status)
-{
- if (status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED)
- __glutCurrentWindow->visibility(GLUT_NOT_VISIBLE);
- else
- __glutCurrentWindow->visibility(GLUT_VISIBLE);
-}
-
-
-void GLUTAPIENTRY
-glutVisibilityFunc(GLUTvisibilityCB visibilityFunc)
-{
- __glutCurrentWindow->visibility = visibilityFunc;
-
- if (visibilityFunc)
- { glutWindowStatusFunc(visibilityHelper);
-#if defined(__OS2PM__)
- if(__glutCurrentWindow->shownState >= 0)
- { visibilityHelper(__glutCurrentWindow->shownState);
- }
-#endif
- }
- else
- glutWindowStatusFunc(NULL);
-}
-
-void GLUTAPIENTRY
-glutReshapeFunc(GLUTreshapeCB reshapeFunc)
-{
- if (reshapeFunc) {
- __glutCurrentWindow->reshape = reshapeFunc;
- } else {
- __glutCurrentWindow->reshape = __glutDefaultReshape;
- }
-}
+
+/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+#ifdef __VMS
+#include <GL/vms_x_fix.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#if defined(__OS2__)
+#define POKA 0
+ #include "WarpGL.h"
+ #include "glutos2.h"
+ #include "glutint.h"
+
+ #include "gl\os2mesa.h"
+
+//
+//define for resource id for main GLUT window, in samples it is defined in GL_TEST.h
+ #define ID_WINDOW 256
+
+ int evglSetPixelFormat(int iPixelFormat);
+ HPS hpsCurrent;
+
+#elif !defined(_WIN32)
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#endif
+
+#include "glutint.h"
+
+GLUTwindow *__glutCurrentWindow = NULL;
+GLUTwindow **__glutWindowList = NULL;
+int __glutWindowListSize = 0;
+#if !defined(_WIN32) && !defined(__OS2__)
+GLUTstale *__glutStaleWindowList = NULL;
+#endif
+GLUTwindow *__glutMenuWindow = NULL;
+
+void (*__glutFreeOverlayFunc) (GLUToverlay *);
+XVisualInfo *(*__glutDetermineVisualFromString) (char *string, Bool * treatAsSingle,
+ Criterion * requiredCriteria, int nRequired, int requiredMask, void** fbc) = NULL;
+
+static Criterion requiredWindowCriteria[] =
+{
+ {LEVEL, EQ, 0},
+ {TRANSPARENT, EQ, 0}
+};
+static int numRequiredWindowCriteria = sizeof(requiredWindowCriteria) / sizeof(Criterion);
+static int requiredWindowCriteriaMask = (1 << LEVEL) | (1 << TRANSPARENT);
+
+static void
+cleanWindowWorkList(GLUTwindow * window)
+{
+ GLUTwindow **pEntry = &__glutWindowWorkList;
+ GLUTwindow *entry = __glutWindowWorkList;
+
+ /* Tranverse singly-linked window work list look for the
+ window. */
+ while (entry) {
+ if (entry == window) {
+ /* Found it; delete it. */
+ *pEntry = entry->prevWorkWin;
+ return;
+ } else {
+ pEntry = &entry->prevWorkWin;
+ entry = *pEntry;
+ }
+ }
+}
+
+#if !defined(_WIN32) && !defined(__OS2PM__)
+
+static void
+cleanStaleWindowList(GLUTwindow * window)
+{
+ GLUTstale **pEntry = &__glutStaleWindowList;
+ GLUTstale *entry = __glutStaleWindowList;
+
+ /* Tranverse singly-linked stale window list look for the
+ window ID. */
+ while (entry) {
+ if (entry->window == window) {
+ /* Found it; delete it. */
+ *pEntry = entry->next;
+ free(entry);
+ return;
+ } else {
+ pEntry = &entry->next;
+ entry = *pEntry;
+ }
+ }
+}
+
+#endif
+
+static GLUTwindow *__glutWindowCache = NULL;
+
+GLUTwindow *
+__glutGetWindow(Window win)
+{
+ int i;
+
+ /* Does win belong to the last window ID looked up? */
+ if (__glutWindowCache && (win == __glutWindowCache->win ||
+ (__glutWindowCache->overlay && win ==
+ __glutWindowCache->overlay->win))) {
+ return
+ __glutWindowCache;
+ }
+ /* Otherwise scan the window list looking for the window ID. */
+ for (i = 0; i < __glutWindowListSize; i++) {
+ if (__glutWindowList[i]) {
+ if (win == __glutWindowList[i]->win) {
+ __glutWindowCache = __glutWindowList[i];
+ return __glutWindowCache;
+ }
+ if (__glutWindowList[i]->overlay) {
+ if (win == __glutWindowList[i]->overlay->win) {
+ __glutWindowCache = __glutWindowList[i];
+ return __glutWindowCache;
+ }
+ }
+ }
+ }
+#if !defined(_WIN32) && !defined(__OS2PM__)
+ {
+ GLUTstale *entry;
+
+ /* Scan through destroyed overlay window IDs for which no
+ DestroyNotify has yet been received. */
+ for (entry = __glutStaleWindowList; entry; entry = entry->next) {
+ if (entry->win == win)
+ return entry->window;
+ }
+ }
+#endif
+ return NULL;
+}
+
+/* CENTRY */
+int GLUTAPIENTRY
+glutGetWindow(void)
+{
+ if (__glutCurrentWindow) {
+ return __glutCurrentWindow->num + 1;
+ } else {
+ return 0;
+ }
+}
+/* ENDCENTRY */
+
+void
+__glutSetWindow(GLUTwindow * window)
+{
+ /* It is tempting to try to short-circuit the call to
+ glXMakeCurrent if we "know" we are going to make current
+ to a window we are already current to. In fact, this
+ assumption breaks when GLUT is expected to integrated with
+ other OpenGL windowing APIs that also make current to
+ OpenGL contexts. Since glXMakeCurrent short-circuits the
+ "already bound" case, GLUT avoids the temptation to do so
+ too. */
+ __glutCurrentWindow = window;
+
+ MAKE_CURRENT_LAYER(__glutCurrentWindow);
+
+#if !defined(_WIN32) && !defined(__OS2__)
+ /* We should be careful to force a finish between each
+ iteration through the GLUT main loop if indirect OpenGL
+ contexts are in use; indirect contexts tend to have much
+ longer latency because lots of OpenGL extension requests
+ can queue up in the X protocol stream. We accomplish this
+ by posting GLUT_FINISH_WORK to be done. */
+ if (!__glutCurrentWindow->isDirect)
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_FINISH_WORK);
+#endif
+
+ /* If debugging is enabled, we'll want to check this window
+ for any OpenGL errors every iteration through the GLUT
+ main loop. To accomplish this, we post the
+ GLUT_DEBUG_WORK to be done on this window. */
+ if (__glutDebug) {
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_DEBUG_WORK);
+ }
+}
+
+/* CENTRY */
+void GLUTAPIENTRY
+glutSetWindow(int win)
+{
+ GLUTwindow *window;
+
+ if (win < 1 || win > __glutWindowListSize) {
+ __glutWarning("glutSetWindow attempted on bogus window.");
+ return;
+ }
+ window = __glutWindowList[win - 1];
+ if (!window) {
+ __glutWarning("glutSetWindow attempted on bogus window.");
+ return;
+ }
+ __glutSetWindow(window);
+}
+/* ENDCENTRY */
+
+static int
+getUnusedWindowSlot(void)
+{
+ int i;
+
+ /* Look for allocated, unused slot. */
+ for (i = 0; i < __glutWindowListSize; i++) {
+ if (!__glutWindowList[i]) {
+ return i;
+ }
+ }
+ /* Allocate a new slot. */
+ __glutWindowListSize++;
+ if (__glutWindowList) {
+ __glutWindowList = (GLUTwindow **)
+ realloc(__glutWindowList,
+ __glutWindowListSize * sizeof(GLUTwindow *));
+ } else {
+ /* XXX Some realloc's do not correctly perform a malloc
+ when asked to perform a realloc on a NULL pointer,
+ though the ANSI C library spec requires this. */
+ __glutWindowList = (GLUTwindow **)
+ malloc(sizeof(GLUTwindow *));
+ }
+ if (!__glutWindowList)
+ __glutFatalError("out of memory.");
+ __glutWindowList[__glutWindowListSize - 1] = NULL;
+ return __glutWindowListSize - 1;
+}
+
+static XVisualInfo *
+getVisualInfoCI(unsigned int mode)
+{
+#if POKA
+ static int bufSizeList[] =
+ {16, 12, 8, 4, 2, 1, 0};
+ XVisualInfo *vi;
+ int list[32];
+ int i, n = 0;
+
+ /* Should not be looking at display mode mask if
+ __glutDisplayString is non-NULL. */
+ assert(!__glutDisplayString);
+
+ list[n++] = GLX_BUFFER_SIZE;
+ list[n++] = 1;
+ if (GLUT_WIND_IS_DOUBLE(mode)) {
+ list[n++] = GLX_DOUBLEBUFFER;
+ }
+ if (GLUT_WIND_IS_STEREO(mode)) {
+ list[n++] = GLX_STEREO;
+ }
+ if (GLUT_WIND_HAS_DEPTH(mode)) {
+ list[n++] = GLX_DEPTH_SIZE;
+ list[n++] = 1;
+ }
+ if (GLUT_WIND_HAS_STENCIL(mode)) {
+ list[n++] = GLX_STENCIL_SIZE;
+ list[n++] = 1;
+ }
+ list[n] = (int) None; /* terminate list */
+
+ /* glXChooseVisual specify GLX_BUFFER_SIZE prefers the
+ "smallest index buffer of at least the specified size".
+ This would be reasonable if GLUT allowed the user to
+ specify the required buffe size, but GLUT's display mode
+ is too simplistic (easy to use?). GLUT should try to find
+ the "largest". So start with a large buffer size and
+ shrink until we find a matching one that exists. */
+
+ for (i = 0; bufSizeList[i]; i++) {
+ /* XXX Assumes list[1] is where GLX_BUFFER_SIZE parameter
+ is. */
+ list[1] = bufSizeList[i];
+ vi = glXChooseVisual(__glutDisplay,
+ __glutScreen, list);
+ if (vi)
+ return vi;
+ }
+ return NULL;
+#else
+ return
+ glXChooseVisual(mode);
+
+#endif
+}
+
+static XVisualInfo *
+getVisualInfoRGB(unsigned int mode)
+{
+#if POKA
+ int list[32];
+ int n = 0;
+
+ /* Should not be looking at display mode mask if
+ __glutDisplayString is non-NULL. */
+ assert(!__glutDisplayString);
+
+ /* XXX Would a caching mechanism to minize the calls to
+ glXChooseVisual? You'd have to reference count
+ XVisualInfo* pointers. Would also have to properly
+ interact with glutInitDisplayString. */
+
+ list[n++] = GLX_RGBA;
+ list[n++] = GLX_RED_SIZE;
+ list[n++] = 1;
+ list[n++] = GLX_GREEN_SIZE;
+ list[n++] = 1;
+ list[n++] = GLX_BLUE_SIZE;
+ list[n++] = 1;
+ if (GLUT_WIND_HAS_ALPHA(mode)) {
+ list[n++] = GLX_ALPHA_SIZE;
+ list[n++] = 1;
+ }
+ if (GLUT_WIND_IS_DOUBLE(mode)) {
+ list[n++] = GLX_DOUBLEBUFFER;
+ }
+ if (GLUT_WIND_IS_STEREO(mode)) {
+ list[n++] = GLX_STEREO;
+ }
+ if (GLUT_WIND_HAS_DEPTH(mode)) {
+ list[n++] = GLX_DEPTH_SIZE;
+ list[n++] = 1;
+ }
+ if (GLUT_WIND_HAS_STENCIL(mode)) {
+ list[n++] = GLX_STENCIL_SIZE;
+ list[n++] = 1;
+ }
+ if (GLUT_WIND_HAS_ACCUM(mode)) {
+ list[n++] = GLX_ACCUM_RED_SIZE;
+ list[n++] = 1;
+ list[n++] = GLX_ACCUM_GREEN_SIZE;
+ list[n++] = 1;
+ list[n++] = GLX_ACCUM_BLUE_SIZE;
+ list[n++] = 1;
+ if (GLUT_WIND_HAS_ALPHA(mode)) {
+ list[n++] = GLX_ACCUM_ALPHA_SIZE;
+ list[n++] = 1;
+ }
+ }
+#if defined(GLX_VERSION_1_1) && (defined(GLX_SGIS_multisample) || defined(GLX_ARB_multisample))
+ if (GLUT_WIND_IS_MULTISAMPLE(mode)) {
+ if (!__glutIsSupportedByGLX("GLX_SGIS_multisample") &&
+ !__glutIsSupportedByGLX("GLX_ARB_multisample"))
+ return NULL;
+#if defined(GLX_ARB_multisample)
+ list[n++] = GLX_SAMPLES_ARB;
+#elif defined(GLX_SGIS_multisample)
+ list[n++] = GLX_SAMPLES_SGIS;
+#endif
+ /* XXX Is 4 a reasonable minimum acceptable number of
+ samples? */
+ list[n++] = 4;
+ }
+#endif
+ list[n] = (int) None; /* terminate list */
+
+ return glXChooseVisual(__glutDisplay,
+ __glutScreen, list);
+#else /* POKA */
+
+ return
+ glXChooseVisual(mode);
+
+#endif
+}
+
+XVisualInfo *
+__glutGetVisualInfo(unsigned int mode)
+{
+ /* XXX GLUT_LUMINANCE not implemented for GLUT 3.0. */
+ if (GLUT_WIND_IS_LUMINANCE(mode))
+ return NULL;
+
+ if (GLUT_WIND_IS_RGB(mode))
+ return getVisualInfoRGB(mode);
+ else
+ return getVisualInfoCI(mode);
+}
+
+XVisualInfo *
+__glutDetermineVisual(
+ unsigned int displayMode,
+ Bool * treatAsSingle,
+ XVisualInfo * (getVisualInfo) (unsigned int))
+{
+ XVisualInfo *vis;
+
+ /* Should not be looking at display mode mask if
+ __glutDisplayString is non-NULL. */
+ assert(!__glutDisplayString);
+
+ *treatAsSingle = GLUT_WIND_IS_SINGLE(displayMode);
+ vis = getVisualInfo(displayMode);
+ if (!vis) {
+ /* Fallback cases when can't get exactly what was asked
+ for... */
+ if (GLUT_WIND_IS_SINGLE(displayMode)) {
+ /* If we can't find a single buffered visual, try looking
+ for a double buffered visual. We can treat a double
+ buffered visual as a single buffer visual by changing
+ the draw buffer to GL_FRONT and treating any swap
+ buffers as no-ops. */
+ displayMode |= GLUT_DOUBLE;
+ vis = getVisualInfo(displayMode);
+ *treatAsSingle = True;
+ }
+ if (!vis && GLUT_WIND_IS_MULTISAMPLE(displayMode)) {
+ /* If we can't seem to get multisampling (ie, not Reality
+ Engine class graphics!), go without multisampling. It
+ is up to the application to query how many multisamples
+ were allocated (0 equals no multisampling) if the
+ application is going to use multisampling for more than
+ just antialiasing. */
+ displayMode &= ~GLUT_MULTISAMPLE;
+ vis = getVisualInfo(displayMode);
+ }
+ }
+ return vis;
+}
+
+static void GLUTCALLBACK
+__glutDefaultDisplay(void)
+{
+ /* XXX Remove the warning after GLUT 3.0. */
+ __glutWarning("The following is a new check for GLUT 3.0; update your code.");
+ __glutFatalError(
+ "redisplay needed for window %d, but no display callback.",
+ __glutCurrentWindow->num + 1);
+}
+
+void GLUTCALLBACK
+__glutDefaultReshape(int width, int height)
+{
+ GLUToverlay *overlay;
+
+ /* Adjust the viewport of the window (and overlay if one
+ exists). */
+ MAKE_CURRENT_WINDOW(__glutCurrentWindow);
+ glViewport(0, 0, (GLsizei) width, (GLsizei) height);
+ overlay = __glutCurrentWindow->overlay;
+ if (overlay) {
+ MAKE_CURRENT_OVERLAY(overlay);
+ glViewport(0, 0, (GLsizei) width, (GLsizei) height);
+ }
+ /* Make sure we are current to the current layer (application
+ should be able to count on the current layer not changing
+ unless the application explicitly calls glutUseLayer). */
+ MAKE_CURRENT_LAYER(__glutCurrentWindow);
+}
+
+XVisualInfo *
+__glutDetermineWindowVisual(Bool * treatAsSingle, Bool * visAlloced, void **fbc)
+{
+ if (__glutDisplayString) {
+
+ /* __glutDisplayString should be NULL except if
+ glutInitDisplayString has been called to register a
+ different display string. Calling glutInitDisplayString
+ means using a string instead of an integer mask determine
+ the visual to use. Using the function pointer variable
+ __glutDetermineVisualFromString below avoids linking in
+ the code for implementing glutInitDisplayString (ie,
+ glut_dstr.o) unless glutInitDisplayString gets called by
+ the application. */
+
+ assert(__glutDetermineVisualFromString);
+ *visAlloced = False;
+ *fbc = NULL;
+ return __glutDetermineVisualFromString(__glutDisplayString, treatAsSingle,
+ requiredWindowCriteria, numRequiredWindowCriteria, requiredWindowCriteriaMask, fbc);
+ } else {
+ *visAlloced = True;
+ *fbc = NULL;
+ return __glutDetermineVisual(__glutDisplayMode,
+ treatAsSingle, __glutGetVisualInfo);
+ }
+}
+
+/* ARGSUSED5 */ /* Only Win32 uses gameMode parameter. */
+GLUTwindow *
+__glutCreateWindow(GLUTwindow * parent,
+ int x, int y, int width, int height, int gameMode)
+{
+ GLUTwindow *window;
+ XSetWindowAttributes wa;
+ unsigned long attribMask;
+ int winnum;
+ int i;
+#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
+ GLXFBConfigSGIX fbc;
+#else
+ void *fbc;
+#endif
+
+#if defined(__OS2PM__)
+ {
+ extern HAB hab; /* PM anchor block handle */
+ CLASSINFO classinfo;
+
+ if(!WinQueryClassInfo(hab,"GLUT", &classinfo) )
+ __glutOpenOS2Connection(NULL);
+ }
+#elif defined(_WIN32)
+ WNDCLASS wc;
+ int style;
+
+ if (!GetClassInfo(GetModuleHandle(NULL), "GLUT", &wc)) {
+ __glutOpenWin32Connection(NULL);
+ }
+#else
+ if (!__glutDisplay) {
+ __glutOpenXConnection(NULL);
+ }
+#endif
+
+#ifndef __OS2PM__
+ if (__glutGameModeWindow) {
+ __glutFatalError("cannot create windows in game mode.");
+ }
+#endif
+
+ winnum = getUnusedWindowSlot();
+ window = (GLUTwindow *) malloc(sizeof(GLUTwindow));
+ if (!window) {
+ __glutFatalError("out of memory.");
+ }
+ window->num = winnum;
+
+#if defined(__OS2PM__)
+ /* Add this new window to the window list. */
+ __glutWindowList[winnum] = window;
+ window->shownState = -1;
+#endif
+
+#if !defined(_WIN32) && !defined(__OS2PM__)
+ window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
+ &window->visAlloced, (void**) &fbc);
+ if (!window->vis) {
+ __glutFatalError(
+ "visual with necessary capabilities not found.");
+ }
+ __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
+#endif
+ window->eventMask = StructureNotifyMask | ExposureMask;
+
+ attribMask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
+ wa.background_pixmap = None;
+ wa.border_pixel = 0;
+ wa.colormap = window->cmap;
+ wa.event_mask = window->eventMask;
+ if (parent) {
+ if (parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
+ wa.event_mask |= GLUT_HACK_STOP_PROPAGATE_MASK;
+ attribMask |= CWDontPropagate;
+ wa.do_not_propagate_mask = parent->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
+ } else {
+ wa.do_not_propagate_mask = 0;
+ }
+
+ /* Stash width and height before Win32's __glutAdjustCoords
+ possibly overwrites the values. */
+ window->width = width;
+ window->height = height;
+ window->forceReshape = True;
+ window->ignoreKeyRepeat = False;
+
+#if defined(__OS2PM__)
+
+ { ULONG flStyle=0;
+ int ii;
+ ERRORID erridErrorCode;/* last error id code */
+ extern HAB hab; /* PM anchor block handle */
+
+ if (parent) {
+ flStyle = WS_CLIPCHILDREN|WS_VISIBLE;
+ } else {
+ if (gameMode) {
+ /* Game mode window should be a WS_POPUP window to
+ ensure that the taskbar is hidden by it. A standard
+ WS_OVERLAPPEDWINDOW does not hide the task bar. */
+ flStyle = FCF_STANDARD | WS_MAXIMIZED;
+ } else {
+ /* A standard toplevel window with borders and such. */
+ flStyle = FCF_STANDARD | WS_CLIPCHILDREN;
+// flStyle = WS_OVERLAPPEDWINDOW;
+ }
+ }
+{
+ HWND hwnd; /* Window */
+ ULONG ListBoxId; /* Window id */
+ /* (supplied by application) */
+
+
+ HWND hwndClient; /* handle to the client */
+ HWND hwndFrame; /* handle to the frame */
+ PFNWP GenericWndProc;
+ FRAMECDATA fcd;
+ RECTL rect; /* Boundary rectangle */
+
+
+
+/************************************************/
+// flCreate = (FCF_STANDARD) & ~FCF_TASKLIST;
+/**********************************/
+ if (parent)
+ { window->frame = NULL;
+
+ hwnd = WinCreateWindow(parent->win, /* Parent window */
+ "GLUTCHILD", /* Class name */
+ "", /* Window text */
+ flStyle, /* Window style */
+ x, y, /* Position (x,y) */
+ width, height, /* Size (width,height) */
+ parent->win, /* Owner window */
+ HWND_TOP, /* Sibling window */
+ 0, /* Window id */
+ NULL, /* Control data */
+ NULL); /* Pres parameters */
+
+ erridErrorCode = WinGetLastError(hab);
+ window->win = hwnd;
+
+ window->hdc = WinOpenWindowDC(window->win);
+ window->hpsBuffer = hpsCurrent;
+
+
+ rect.xLeft = x;
+ rect.xRight = x+width;
+ rect.yBottom = y;
+ rect.yTop = y + height;
+
+/***** else parent *****************************/
+ } else {
+ hwnd = WinCreateStdWindow(HWND_DESKTOP,
+ 0, /* WS_VISIBLE frame-window style */
+ &flStyle, /* window style */
+ "GLUT", /* class name */
+ "GLUT",/* window title */
+ 0L, /* default client style */
+ NULLHANDLE, /* resource in executable file */
+ ID_WINDOW, /* resource id */
+ &hwndClient); /* receives client window handle */
+
+ erridErrorCode = WinGetLastError(hab);
+ window->win = hwndClient;
+ window->frame = hwnd;
+ window->hdc = WinOpenWindowDC(window->win);
+
+ window->hpsBuffer = hpsCurrent;
+
+
+/* converts a client window's boundaries into an equivalent frame rectangle */
+ rect.xLeft = x;
+ rect.xRight = x+width;
+ rect.yBottom = y;
+ rect.yTop = y + height;
+
+ /* calculate equivalent frame boundary from boundary data */
+ WinCalcFrameRect(window->frame, &rect, FALSE);
+ }
+/***** endof if(parent) *****************************/
+
+ /* Must set the XHDC for fake glXChooseVisual & fake
+ glXCreateContext & fake XAllocColorCells. */
+ XHDC = window->hdc;
+ XHWND = window->win;
+ window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
+ &window->visAlloced, &fbc);
+ if (!window->vis)
+ { __glutFatalError(
+ "pixel format with necessary capabilities not found.");
+ }
+ { int rc;
+ rc = wglChoosePixelFormat(window->hdc, window->vis),
+
+// evglSetPixelFormat(2); /* int iPixelFormat 1 - doublebuffer/2 - single buffer ??*/
+ wglSetPixelFormat(window->hdc,rc,window->vis);
+ }
+ __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
+
+ window->ctx = glXCreateContext(window->hpsBuffer, window->vis,
+ None, __glutTryDirect);
+
+ WinSetWindowPos(hwnd,
+ HWND_TOP,rect.xLeft,rect.yBottom,
+ rect.xRight-rect.xLeft, rect.yTop-rect.yBottom,
+ SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW|SWP_ZORDER); /* flags*/
+
+ /* Make sure subwindows get a windowStatus callback. */
+ if (parent)
+ WinPostMsg(parent->win, WM_ACTIVATE, 0, 0);
+
+ }
+}
+
+#elif defined(_WIN32)
+
+ __glutAdjustCoords(parent ? parent->win : NULL,
+ &x, &y, &width, &height);
+ if (parent) {
+ style = WS_CHILD;
+ } else {
+ if (gameMode) {
+ /* Game mode window should be a WS_POPUP window to
+ ensure that the taskbar is hidden by it. A standard
+ WS_OVERLAPPEDWINDOW does not hide the task bar. */
+ style = WS_POPUP | WS_MAXIMIZE;
+ } else {
+ /* A standard toplevel window with borders and such. */
+ style = WS_OVERLAPPEDWINDOW;
+ }
+ }
+ window->win = CreateWindow("GLUT", "GLUT",
+ WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
+ x, y, width, height, parent ? parent->win : __glutRoot,
+ NULL, GetModuleHandle(NULL), 0);
+ window->hdc = GetDC(window->win);
+ /* Must set the XHDC for fake glXChooseVisual & fake
+ glXCreateContext & fake XAllocColorCells. */
+ XHDC = window->hdc;
+ window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
+ &window->visAlloced, &fbc);
+ if (!window->vis) {
+ __glutFatalError(
+ "pixel format with necessary capabilities not found.");
+ }
+ if (!SetPixelFormat(window->hdc,
+ ChoosePixelFormat(window->hdc, window->vis),
+ window->vis)) {
+ __glutFatalError("SetPixelFormat failed during window create.");
+ }
+ __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
+ /* Make sure subwindows get a windowStatus callback. */
+ if (parent) {
+ PostMessage(parent->win, WM_ACTIVATE, 0, 0);
+ }
+ window->renderDc = window->hdc;
+#else
+ window->win = XCreateWindow(__glutDisplay,
+ parent == NULL ? __glutRoot : parent->win,
+ x, y, width, height, 0,
+ window->vis->depth, InputOutput, window->vis->visual,
+ attribMask, &wa);
+#endif
+ window->renderWin = window->win;
+#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
+ if (fbc) {
+ window->ctx = __glut_glXCreateContextWithConfigSGIX(__glutDisplay, fbc,
+ GLX_RGBA_TYPE_SGIX, None, __glutTryDirect);
+ } else
+#endif
+#if defined(__OS2PM__)
+// window->ctx = glXCreateContext(window->hpsBuffer, window->vis,
+// None, __glutTryDirect);
+#else
+ window->ctx = glXCreateContext(__glutDisplay, window->vis,
+ None, __glutTryDirect);
+#endif
+ if (!window->ctx) {
+ __glutFatalError(
+ "failed to create OpenGL rendering context.");
+ }
+ window->renderCtx = window->ctx;
+#if !defined(_WIN32) && !defined(__OS2PM__)
+ window->isDirect = glXIsDirect(__glutDisplay, window->ctx);
+ if (__glutForceDirect) {
+ if (!window->isDirect)
+ __glutFatalError("direct rendering not possible.");
+ }
+#endif
+
+ window->parent = parent;
+ if (parent) {
+ window->siblings = parent->children;
+ parent->children = window;
+ } else {
+ window->siblings = NULL;
+ }
+ window->overlay = NULL;
+ window->children = NULL;
+ window->display = __glutDefaultDisplay;
+ window->reshape = __glutDefaultReshape;
+ window->mouse = NULL;
+ window->motion = NULL;
+ window->passive = NULL;
+ window->entry = NULL;
+ window->keyboard = NULL;
+ window->keyboardUp = NULL;
+ window->windowStatus = NULL;
+ window->visibility = NULL;
+ window->special = NULL;
+ window->specialUp = NULL;
+ window->buttonBox = NULL;
+ window->dials = NULL;
+ window->spaceMotion = NULL;
+ window->spaceRotate = NULL;
+ window->spaceButton = NULL;
+ window->tabletMotion = NULL;
+ window->tabletButton = NULL;
+#ifdef _WIN32
+ window->joystick = NULL;
+ window->joyPollInterval = 0;
+#endif
+
+#if defined(__OS2PM__)
+ window->wm_command = NULL;
+#endif
+
+ window->tabletPos[0] = -1;
+ window->tabletPos[1] = -1;
+#if defined(__OS2PM__)
+ if(window->shownState == -1)
+ window->shownState = 0;
+ window->visState = window->shownState;
+#else
+ window->shownState = 0;
+ window->visState = -1; /* not VisibilityUnobscured,
+ VisibilityPartiallyObscured, or
+ VisibilityFullyObscured */
+#endif
+ window->entryState = -1; /* not EnterNotify or LeaveNotify */
+
+ window->desiredConfMask = 0;
+ window->buttonUses = 0;
+ window->cursor = GLUT_CURSOR_INHERIT;
+
+ /* Setup window to be mapped when glutMainLoop starts. */
+ window->workMask = GLUT_MAP_WORK;
+#ifdef _WIN32
+ if (gameMode) {
+ /* When mapping a game mode window, just show
+ the window. We have already created the game
+ mode window with a maximize flag at creation
+ time. Doing a ShowWindow(window->win, SW_SHOWNORMAL)
+ would be wrong for a game mode window since it
+ would unmaximize the window. */
+ window->desiredMapState = GameModeState;
+ } else {
+ window->desiredMapState = NormalState;
+ }
+#else
+ window->desiredMapState = NormalState;
+#endif
+ window->prevWorkWin = __glutWindowWorkList;
+ __glutWindowWorkList = window;
+
+ /* Initially, no menus attached. */
+ for (i = 0; i < GLUT_MAX_MENUS; i++) {
+ window->menu[i] = 0;
+ }
+
+ /* Add this new window to the window list. */
+ __glutWindowList[winnum] = window;
+
+ /* Make the new window the current window. */
+ __glutSetWindow(window);
+
+ __glutDetermineMesaSwapHackSupport();
+
+ if (window->treatAsSingle) {
+ /* We do this because either the window really is single
+ buffered (in which case this is redundant, but harmless,
+ because this is the initial single-buffered context
+ state); or we are treating a double buffered window as a
+ single-buffered window because the system does not appear
+ to export any suitable single- buffered visuals (in which
+ the following are necessary). */
+ glDrawBuffer(GL_FRONT);
+ glReadBuffer(GL_FRONT);
+ }
+ return window;
+}
+
+/* CENTRY */
+int GLUTAPIENTRY
+glutCreateWindow(const char *title)
+{
+ static int firstWindow = 1;
+ GLUTwindow *window;
+#if !defined(_WIN32) && !defined(__OS2__)
+ XWMHints *wmHints;
+#endif
+ Window win;
+ XTextProperty textprop;
+
+ if (__glutGameModeWindow) {
+ __glutFatalError("cannot create windows in game mode.");
+ }
+ window = __glutCreateWindow(NULL,
+ __glutSizeHints.x, __glutSizeHints.y,
+ __glutInitWidth, __glutInitHeight,
+ /* not game mode */ 0);
+ win = window->win;
+ /* Setup ICCCM properties. */
+ textprop.value = (unsigned char *) title;
+ textprop.encoding = XA_STRING;
+ textprop.format = 8;
+ textprop.nitems = strlen(title);
+#if defined(__OS2__)
+ WinSetWindowText(window->frame, (PCSZ)title);
+ if (__glutIconic) {
+ window->desiredMapState = IconicState;
+ }
+#elif defined(_WIN32)
+ SetWindowText(win, title);
+ if (__glutIconic) {
+ window->desiredMapState = IconicState;
+ }
+#else
+ wmHints = XAllocWMHints();
+ wmHints->initial_state =
+ __glutIconic ? IconicState : NormalState;
+ wmHints->flags = StateHint;
+ XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
+ /* Only put WM_COMMAND property on first window. */
+ firstWindow ? __glutArgv : NULL,
+ firstWindow ? __glutArgc : 0,
+ &__glutSizeHints, wmHints, NULL);
+ XFree(wmHints);
+ XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
+#endif
+ firstWindow = 0;
+ return window->num + 1;
+}
+
+#ifdef _WIN32
+int GLUTAPIENTRY
+__glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int))
+{
+ __glutExitFunc = exitfunc;
+ return glutCreateWindow(title);
+}
+#endif
+
+int GLUTAPIENTRY
+glutCreateSubWindow(int win, int x, int y, int width, int height)
+{
+ GLUTwindow *window;
+
+ window = __glutCreateWindow(__glutWindowList[win - 1],
+ x, y, width, height, /* not game mode */ 0);
+#if !defined(_WIN32) && !defined(__OS2__)
+ {
+ GLUTwindow *toplevel;
+
+ toplevel = __glutToplevelOf(window);
+ if (toplevel->cmap != window->cmap) {
+ __glutPutOnWorkList(toplevel, GLUT_COLORMAP_WORK);
+ }
+ }
+#endif
+ return window->num + 1;
+}
+/* ENDCENTRY */
+
+void
+__glutDestroyWindow(GLUTwindow * window,
+ GLUTwindow * initialWindow)
+{
+ GLUTwindow **prev, *cur, *parent, *siblings;
+
+ /* Recursively destroy any children. */
+ cur = window->children;
+ while (cur) {
+ siblings = cur->siblings;
+ __glutDestroyWindow(cur, initialWindow);
+ cur = siblings;
+ }
+ /* Remove from parent's children list (only necessary for
+ non-initial windows and subwindows!). */
+ parent = window->parent;
+ if (parent && parent == initialWindow->parent) {
+ prev = &parent->children;
+ cur = parent->children;
+ while (cur) {
+ if (cur == window) {
+ *prev = cur->siblings;
+ break;
+ }
+ prev = &(cur->siblings);
+ cur = cur->siblings;
+ }
+ }
+ /* Unbind if bound to this window. */
+ if (window == __glutCurrentWindow) {
+ UNMAKE_CURRENT();
+ __glutCurrentWindow = NULL;
+ }
+ /* Begin tearing down window itself. */
+ if (window->overlay) {
+ __glutFreeOverlayFunc(window->overlay);
+ }
+ XDestroyWindow(__glutDisplay, window->win);
+ glXDestroyContext(__glutDisplay, window->ctx);
+ if (window->colormap) {
+ /* Only color index windows have colormap data structure. */
+ __glutFreeColormap(window->colormap);
+ }
+ /* NULLing the __glutWindowList helps detect is a window
+ instance has been destroyed, given a window number. */
+ __glutWindowList[window->num] = NULL;
+
+ /* Cleanup data structures that might contain window. */
+ cleanWindowWorkList(window);
+#if !defined(_WIN32) && !defined(__OS2__)
+ cleanStaleWindowList(window);
+#endif
+ /* Remove window from the "get window cache" if it is there. */
+ if (__glutWindowCache == window)
+ __glutWindowCache = NULL;
+
+ if (window->visAlloced) {
+ /* Only free XVisualInfo* gotten from glXChooseVisual. */
+ XFree(window->vis);
+ }
+
+ if (window == __glutGameModeWindow) {
+ /* Destroying the game mode window should implicitly
+ have GLUT leave game mode. */
+ __glutCloseDownGameMode();
+ }
+
+ free(window);
+}
+
+/* CENTRY */
+void GLUTAPIENTRY
+glutDestroyWindow(int win)
+{
+ GLUTwindow *window = __glutWindowList[win - 1];
+
+ if (__glutMappedMenu && __glutMenuWindow == window) {
+ __glutFatalUsage("destroying menu window not allowed while menus in use");
+ }
+#if !defined(_WIN32) && !defined(__OS2__)
+ /* If not a toplevel window... */
+ if (window->parent) {
+ /* Destroying subwindows may change colormap requirements;
+ recalculate toplevel window's WM_COLORMAP_WINDOWS
+ property. */
+ __glutPutOnWorkList(__glutToplevelOf(window->parent),
+ GLUT_COLORMAP_WORK);
+ }
+#endif
+ __glutDestroyWindow(window, window);
+ XFlush(__glutDisplay);
+}
+/* ENDCENTRY */
+
+void
+__glutChangeWindowEventMask(long eventMask, Bool add)
+{
+ if (add) {
+ /* Add eventMask to window's event mask. */
+ if ((__glutCurrentWindow->eventMask & eventMask) !=
+ eventMask) {
+ __glutCurrentWindow->eventMask |= eventMask;
+ __glutPutOnWorkList(__glutCurrentWindow,
+ GLUT_EVENT_MASK_WORK);
+ }
+ } else {
+ /* Remove eventMask from window's event mask. */
+ if (__glutCurrentWindow->eventMask & eventMask) {
+ __glutCurrentWindow->eventMask &= ~eventMask;
+ __glutPutOnWorkList(__glutCurrentWindow,
+ GLUT_EVENT_MASK_WORK);
+ }
+ }
+}
+
+void GLUTAPIENTRY
+glutDisplayFunc(GLUTdisplayCB displayFunc)
+{
+ /* XXX Remove the warning after GLUT 3.0. */
+ if (!displayFunc)
+ __glutFatalError("NULL display callback not allowed in GLUT 3.0; update your code.");
+ __glutCurrentWindow->display = displayFunc;
+}
+
+void GLUTAPIENTRY
+glutMouseFunc(GLUTmouseCB mouseFunc)
+{
+ if (__glutCurrentWindow->mouse) {
+ if (!mouseFunc) {
+ /* Previous mouseFunc being disabled. */
+ __glutCurrentWindow->buttonUses--;
+ __glutChangeWindowEventMask(
+ ButtonPressMask | ButtonReleaseMask,
+ __glutCurrentWindow->buttonUses > 0);
+ }
+ } else {
+ if (mouseFunc) {
+ /* Previously no mouseFunc, new one being installed. */
+ __glutCurrentWindow->buttonUses++;
+ __glutChangeWindowEventMask(
+ ButtonPressMask | ButtonReleaseMask, True);
+ }
+ }
+ __glutCurrentWindow->mouse = mouseFunc;
+}
+
+void GLUTAPIENTRY
+glutMotionFunc(GLUTmotionCB motionFunc)
+{
+ /* Hack. Some window managers (4Dwm by default) will mask
+ motion events if the client is not selecting for button
+ press and release events. So we select for press and
+ release events too (being careful to use reference
+ counting). */
+ if (__glutCurrentWindow->motion) {
+ if (!motionFunc) {
+ /* previous mouseFunc being disabled */
+ __glutCurrentWindow->buttonUses--;
+ __glutChangeWindowEventMask(
+ ButtonPressMask | ButtonReleaseMask,
+ __glutCurrentWindow->buttonUses > 0);
+ }
+ } else {
+ if (motionFunc) {
+ /* Previously no mouseFunc, new one being installed. */
+ __glutCurrentWindow->buttonUses++;
+ __glutChangeWindowEventMask(
+ ButtonPressMask | ButtonReleaseMask, True);
+ }
+ }
+ /* Real work of selecting for passive mouse motion. */
+ __glutChangeWindowEventMask(
+ Button1MotionMask | Button2MotionMask | Button3MotionMask,
+ motionFunc != NULL);
+ __glutCurrentWindow->motion = motionFunc;
+}
+
+void GLUTAPIENTRY
+glutPassiveMotionFunc(GLUTpassiveCB passiveMotionFunc)
+{
+ __glutChangeWindowEventMask(PointerMotionMask,
+ passiveMotionFunc != NULL);
+
+ /* Passive motion also requires watching enters and leaves so
+ that a fake passive motion event can be generated on an
+ enter. */
+ __glutChangeWindowEventMask(EnterWindowMask | LeaveWindowMask,
+ __glutCurrentWindow->entry != NULL || passiveMotionFunc != NULL);
+
+ __glutCurrentWindow->passive = passiveMotionFunc;
+}
+
+void GLUTAPIENTRY
+glutEntryFunc(GLUTentryCB entryFunc)
+{
+ __glutChangeWindowEventMask(EnterWindowMask | LeaveWindowMask,
+ entryFunc != NULL || __glutCurrentWindow->passive);
+ __glutCurrentWindow->entry = entryFunc;
+ if (!entryFunc) {
+ __glutCurrentWindow->entryState = -1;
+ }
+}
+
+void GLUTAPIENTRY
+glutWindowStatusFunc(GLUTwindowStatusCB windowStatusFunc)
+{
+ __glutChangeWindowEventMask(VisibilityChangeMask,
+ windowStatusFunc != NULL);
+ __glutCurrentWindow->windowStatus = windowStatusFunc;
+ if (!windowStatusFunc) {
+ /* Make state invalid. */
+ __glutCurrentWindow->visState = -1;
+ }
+}
+
+static void GLUTCALLBACK
+visibilityHelper(int status)
+{
+ if (status == GLUT_HIDDEN || status == GLUT_FULLY_COVERED)
+ __glutCurrentWindow->visibility(GLUT_NOT_VISIBLE);
+ else
+ __glutCurrentWindow->visibility(GLUT_VISIBLE);
+}
+
+
+void GLUTAPIENTRY
+glutVisibilityFunc(GLUTvisibilityCB visibilityFunc)
+{
+ __glutCurrentWindow->visibility = visibilityFunc;
+
+ if (visibilityFunc)
+ { glutWindowStatusFunc(visibilityHelper);
+#if defined(__OS2PM__)
+ if(__glutCurrentWindow->shownState >= 0)
+ { visibilityHelper(__glutCurrentWindow->shownState);
+ }
+#endif
+ }
+ else
+ glutWindowStatusFunc(NULL);
+}
+
+void GLUTAPIENTRY
+glutReshapeFunc(GLUTreshapeCB reshapeFunc)
+{
+ if (reshapeFunc) {
+ __glutCurrentWindow->reshape = reshapeFunc;
+ } else {
+ __glutCurrentWindow->reshape = __glutDefaultReshape;
+ }
+}
 \ No newline at end of file
diff --git a/src/glut/os2/glut_winmisc.cpp b/src/glut/os2/glut_winmisc.cpp
index ffa31c021c..456d19a8c1 100644
--- a/src/glut/os2/glut_winmisc.cpp
+++ b/src/glut/os2/glut_winmisc.cpp
@@ -1,127 +1,127 @@
-
-/* Copyright (c) Mark J. Kilgard, 1994. */
-
-/* This program is freely distributable without licensing fees
- and is provided without guarantee or warrantee expressed or
- implied. This program is -not- in the public domain. */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-
-#include "glutint.h"
-
-/* CENTRY */
-void GLUTAPIENTRY
-glutSetWindowTitle(const char *title)
-{
-#if defined(__OS2PM__)
- __glutSetWindowText(__glutCurrentWindow->win, (char *)title);
-
-#else
- XTextProperty textprop;
-
- assert(!__glutCurrentWindow->parent);
- IGNORE_IN_GAME_MODE();
- textprop.value = (unsigned char *) title;
- textprop.encoding = XA_STRING;
- textprop.format = 8;
- textprop.nitems = strlen(title);
- XSetWMName(__glutDisplay,
- __glutCurrentWindow->win, &textprop);
- XFlush(__glutDisplay);
-#endif
-}
-
-void GLUTAPIENTRY
-glutSetIconTitle(const char *title)
-{
-#if defined(__OS2PM__)
-//todo ?
-#else
-
- XTextProperty textprop;
-
- assert(!__glutCurrentWindow->parent);
- IGNORE_IN_GAME_MODE();
- textprop.value = (unsigned char *) title;
- textprop.encoding = XA_STRING;
- textprop.format = 8;
- textprop.nitems = strlen(title);
- XSetWMIconName(__glutDisplay,
- __glutCurrentWindow->win, &textprop);
- XFlush(__glutDisplay);
-#endif
-}
-
-void GLUTAPIENTRY
-glutPositionWindow(int x, int y)
-{
- IGNORE_IN_GAME_MODE();
- __glutCurrentWindow->desiredX = x;
- __glutCurrentWindow->desiredY = y;
- __glutCurrentWindow->desiredConfMask |= CWX | CWY;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
-}
-
-void GLUTAPIENTRY
-glutReshapeWindow(int w, int h)
-{
- IGNORE_IN_GAME_MODE();
- if (w <= 0 || h <= 0)
- __glutWarning("glutReshapeWindow: non-positive width or height not allowed");
-
- __glutCurrentWindow->desiredWidth = w;
- __glutCurrentWindow->desiredHeight = h;
- __glutCurrentWindow->desiredConfMask |= CWWidth | CWHeight;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
-}
-
-void GLUTAPIENTRY
-glutPopWindow(void)
-{
- IGNORE_IN_GAME_MODE();
- __glutCurrentWindow->desiredStack = Above;
- __glutCurrentWindow->desiredConfMask |= CWStackMode;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
-}
-
-void GLUTAPIENTRY
-glutPushWindow(void)
-{
- IGNORE_IN_GAME_MODE();
- __glutCurrentWindow->desiredStack = Below;
- __glutCurrentWindow->desiredConfMask |= CWStackMode;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
-}
-
-void GLUTAPIENTRY
-glutIconifyWindow(void)
-{
- IGNORE_IN_GAME_MODE();
- assert(!__glutCurrentWindow->parent);
- __glutCurrentWindow->desiredMapState = IconicState;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_MAP_WORK);
-}
-
-void GLUTAPIENTRY
-glutShowWindow(void)
-{
- IGNORE_IN_GAME_MODE();
- __glutCurrentWindow->desiredMapState = NormalState;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_MAP_WORK);
-}
-
-void GLUTAPIENTRY
-glutHideWindow(void)
-{
- IGNORE_IN_GAME_MODE();
- __glutCurrentWindow->desiredMapState = WithdrawnState;
- __glutPutOnWorkList(__glutCurrentWindow, GLUT_MAP_WORK);
-}
-
-/* ENDCENTRY */
+
+/* Copyright (c) Mark J. Kilgard, 1994. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+
+#include "glutint.h"
+
+/* CENTRY */
+void GLUTAPIENTRY
+glutSetWindowTitle(const char *title)
+{
+#if defined(__OS2PM__)
+ __glutSetWindowText(__glutCurrentWindow->win, (char *)title);
+
+#else
+ XTextProperty textprop;
+
+ assert(!__glutCurrentWindow->parent);
+ IGNORE_IN_GAME_MODE();
+ textprop.value = (unsigned char *) title;
+ textprop.encoding = XA_STRING;
+ textprop.format = 8;
+ textprop.nitems = strlen(title);
+ XSetWMName(__glutDisplay,
+ __glutCurrentWindow->win, &textprop);
+ XFlush(__glutDisplay);
+#endif
+}
+
+void GLUTAPIENTRY
+glutSetIconTitle(const char *title)
+{
+#if defined(__OS2PM__)
+//todo ?
+#else
+
+ XTextProperty textprop;
+
+ assert(!__glutCurrentWindow->parent);
+ IGNORE_IN_GAME_MODE();
+ textprop.value = (unsigned char *) title;
+ textprop.encoding = XA_STRING;
+ textprop.format = 8;
+ textprop.nitems = strlen(title);
+ XSetWMIconName(__glutDisplay,
+ __glutCurrentWindow->win, &textprop);
+ XFlush(__glutDisplay);
+#endif
+}
+
+void GLUTAPIENTRY
+glutPositionWindow(int x, int y)
+{
+ IGNORE_IN_GAME_MODE();
+ __glutCurrentWindow->desiredX = x;
+ __glutCurrentWindow->desiredY = y;
+ __glutCurrentWindow->desiredConfMask |= CWX | CWY;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
+}
+
+void GLUTAPIENTRY
+glutReshapeWindow(int w, int h)
+{
+ IGNORE_IN_GAME_MODE();
+ if (w <= 0 || h <= 0)
+ __glutWarning("glutReshapeWindow: non-positive width or height not allowed");
+
+ __glutCurrentWindow->desiredWidth = w;
+ __glutCurrentWindow->desiredHeight = h;
+ __glutCurrentWindow->desiredConfMask |= CWWidth | CWHeight;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
+}
+
+void GLUTAPIENTRY
+glutPopWindow(void)
+{
+ IGNORE_IN_GAME_MODE();
+ __glutCurrentWindow->desiredStack = Above;
+ __glutCurrentWindow->desiredConfMask |= CWStackMode;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
+}
+
+void GLUTAPIENTRY
+glutPushWindow(void)
+{
+ IGNORE_IN_GAME_MODE();
+ __glutCurrentWindow->desiredStack = Below;
+ __glutCurrentWindow->desiredConfMask |= CWStackMode;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_CONFIGURE_WORK);
+}
+
+void GLUTAPIENTRY
+glutIconifyWindow(void)
+{
+ IGNORE_IN_GAME_MODE();
+ assert(!__glutCurrentWindow->parent);
+ __glutCurrentWindow->desiredMapState = IconicState;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_MAP_WORK);
+}
+
+void GLUTAPIENTRY
+glutShowWindow(void)
+{
+ IGNORE_IN_GAME_MODE();
+ __glutCurrentWindow->desiredMapState = NormalState;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_MAP_WORK);
+}
+
+void GLUTAPIENTRY
+glutHideWindow(void)
+{
+ IGNORE_IN_GAME_MODE();
+ __glutCurrentWindow->desiredMapState = WithdrawnState;
+ __glutPutOnWorkList(__glutCurrentWindow, GLUT_MAP_WORK);
+}
+
+/* ENDCENTRY */
 \ No newline at end of file
diff --git a/src/glut/os2/os2_glx.cpp b/src/glut/os2/os2_glx.cpp
index ca345ea05b..5e135bc17e 100644
--- a/src/glut/os2/os2_glx.cpp
+++ b/src/glut/os2/os2_glx.cpp
@@ -1,146 +1,146 @@
-/* os2_glx.c */
-
-#include <stdio.h>
-#include <string.h>
-#include <malloc.h>
-#include "gl/gl.h"
-#include "WarpGL.h"
-#include "GL/os2mesa.h"
-
-#define POKA 0
-/* global current HDC */
-
-XVisualInfo *wglDescribePixelFormat(int iPixelFormat);
-
-extern HDC XHDC;
-extern HWND XHWND;
-//extern HPS hpsCurrent;
-extern HAB hab; /* PM anchor block handle */
-
-GLXContext
-glXCreateContext(HPS hps, XVisualInfo * visinfo,
- GLXContext share, Bool direct)
-{
- /* KLUDGE: GLX really expects a display pointer to be passed
- in as the first parameter, but Win32 needs an HDC instead,
- so BE SURE that the global XHDC is set before calling this
- routine. */
- HGLRC context;
-
- context = wglCreateContext(XHDC,hps,hab);
-
-
- /* Since direct rendering is implicit, the direct flag is
- ignored. */
-
- return context;
-}
-
-
-int
-glXGetConfig(XVisualInfo * visual, int attrib, int *value)
-{
- if (!visual)
- return GLX_BAD_VISUAL;
-
- switch (attrib) {
- case GLX_USE_GL:
- if (visual->dwFlags & (PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW)) {
- /* XXX Brad's Matrix Millenium II has problems creating
- color index windows in 24-bit mode (lead to GDI crash)
- and 32-bit mode (lead to black window). The cColorBits
- filed of the PIXELFORMATDESCRIPTOR returned claims to
- have 24 and 32 bits respectively of color indices. 2^24
- and 2^32 are ridiculously huge writable colormaps.
- Assume that if we get back a color index
- PIXELFORMATDESCRIPTOR with 24 or more bits, the
- PIXELFORMATDESCRIPTOR doesn't really work and skip it.
- -mjk */
- if (visual->iPixelType == PFD_TYPE_COLORINDEX
- && visual->cColorBits >= 24) {
- *value = 0;
- } else {
- *value = 1;
- }
- } else {
- *value = 0;
- }
- break;
- case GLX_BUFFER_SIZE:
- /* KLUDGE: if we're RGBA, return the number of bits/pixel,
- otherwise, return 8 (we guessed at 256 colors in CI
- mode). */
- if (visual->iPixelType == PFD_TYPE_RGBA)
- *value = visual->cColorBits;
- else
- *value = 8;
- break;
- case GLX_LEVEL:
- /* The bReserved flag of the pfd contains the
- overlay/underlay info. */
- *value = visual->bReserved;
- break;
- case GLX_RGBA:
- *value = visual->iPixelType == PFD_TYPE_RGBA;
- break;
- case GLX_DOUBLEBUFFER:
- *value = visual->dwFlags & PFD_DOUBLEBUFFER;
- break;
- case GLX_STEREO:
- *value = visual->dwFlags & PFD_STEREO;
- break;
- case GLX_AUX_BUFFERS:
- *value = visual->cAuxBuffers;
- break;
- case GLX_RED_SIZE:
- *value = visual->cRedBits;
- break;
- case GLX_GREEN_SIZE:
- *value = visual->cGreenBits;
- break;
- case GLX_BLUE_SIZE:
- *value = visual->cBlueBits;
- break;
- case GLX_ALPHA_SIZE:
- *value = visual->cAlphaBits;
- break;
- case GLX_DEPTH_SIZE:
- *value = visual->cDepthBits;
- break;
- case GLX_STENCIL_SIZE:
- *value = visual->cStencilBits;
- break;
- case GLX_ACCUM_RED_SIZE:
- *value = visual->cAccumRedBits;
- break;
- case GLX_ACCUM_GREEN_SIZE:
- *value = visual->cAccumGreenBits;
- break;
- case GLX_ACCUM_BLUE_SIZE:
- *value = visual->cAccumBlueBits;
- break;
- case GLX_ACCUM_ALPHA_SIZE:
- *value = visual->cAccumAlphaBits;
- break;
-#if POKA == 100
-#endif /* POKA == 100 */
- default:
- return GLX_BAD_ATTRIB;
- }
- return 0;
-}
-
-
-XVisualInfo * glXChooseVisual(int mode)
-{ int imode = 2;
- if(mode & GLUT_DOUBLE)
- imode = 1;
- return
- wglDescribePixelFormat(imode);
-}
-
-
-#if POKA
-#endif /* POKA */
-
+/* os2_glx.c */
+
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include "gl/gl.h"
+#include "WarpGL.h"
+#include "GL/os2mesa.h"
+
+#define POKA 0
+/* global current HDC */
+
+XVisualInfo *wglDescribePixelFormat(int iPixelFormat);
+
+extern HDC XHDC;
+extern HWND XHWND;
+//extern HPS hpsCurrent;
+extern HAB hab; /* PM anchor block handle */
+
+GLXContext
+glXCreateContext(HPS hps, XVisualInfo * visinfo,
+ GLXContext share, Bool direct)
+{
+ /* KLUDGE: GLX really expects a display pointer to be passed
+ in as the first parameter, but Win32 needs an HDC instead,
+ so BE SURE that the global XHDC is set before calling this
+ routine. */
+ HGLRC context;
+
+ context = wglCreateContext(XHDC,hps,hab);
+
+
+ /* Since direct rendering is implicit, the direct flag is
+ ignored. */
+
+ return context;
+}
+
+
+int
+glXGetConfig(XVisualInfo * visual, int attrib, int *value)
+{
+ if (!visual)
+ return GLX_BAD_VISUAL;
+
+ switch (attrib) {
+ case GLX_USE_GL:
+ if (visual->dwFlags & (PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW)) {
+ /* XXX Brad's Matrix Millenium II has problems creating
+ color index windows in 24-bit mode (lead to GDI crash)
+ and 32-bit mode (lead to black window). The cColorBits
+ filed of the PIXELFORMATDESCRIPTOR returned claims to
+ have 24 and 32 bits respectively of color indices. 2^24
+ and 2^32 are ridiculously huge writable colormaps.
+ Assume that if we get back a color index
+ PIXELFORMATDESCRIPTOR with 24 or more bits, the
+ PIXELFORMATDESCRIPTOR doesn't really work and skip it.
+ -mjk */
+ if (visual->iPixelType == PFD_TYPE_COLORINDEX
+ && visual->cColorBits >= 24) {
+ *value = 0;
+ } else {
+ *value = 1;
+ }
+ } else {
+ *value = 0;
+ }
+ break;
+ case GLX_BUFFER_SIZE:
+ /* KLUDGE: if we're RGBA, return the number of bits/pixel,
+ otherwise, return 8 (we guessed at 256 colors in CI
+ mode). */
+ if (visual->iPixelType == PFD_TYPE_RGBA)
+ *value = visual->cColorBits;
+ else
+ *value = 8;
+ break;
+ case GLX_LEVEL:
+ /* The bReserved flag of the pfd contains the
+ overlay/underlay info. */
+ *value = visual->bReserved;
+ break;
+ case GLX_RGBA:
+ *value = visual->iPixelType == PFD_TYPE_RGBA;
+ break;
+ case GLX_DOUBLEBUFFER:
+ *value = visual->dwFlags & PFD_DOUBLEBUFFER;
+ break;
+ case GLX_STEREO:
+ *value = visual->dwFlags & PFD_STEREO;
+ break;
+ case GLX_AUX_BUFFERS:
+ *value = visual->cAuxBuffers;
+ break;
+ case GLX_RED_SIZE:
+ *value = visual->cRedBits;
+ break;
+ case GLX_GREEN_SIZE:
+ *value = visual->cGreenBits;
+ break;
+ case GLX_BLUE_SIZE:
+ *value = visual->cBlueBits;
+ break;
+ case GLX_ALPHA_SIZE:
+ *value = visual->cAlphaBits;
+ break;
+ case GLX_DEPTH_SIZE:
+ *value = visual->cDepthBits;
+ break;
+ case GLX_STENCIL_SIZE:
+ *value = visual->cStencilBits;
+ break;
+ case GLX_ACCUM_RED_SIZE:
+ *value = visual->cAccumRedBits;
+ break;
+ case GLX_ACCUM_GREEN_SIZE:
+ *value = visual->cAccumGreenBits;
+ break;
+ case GLX_ACCUM_BLUE_SIZE:
+ *value = visual->cAccumBlueBits;
+ break;
+ case GLX_ACCUM_ALPHA_SIZE:
+ *value = visual->cAccumAlphaBits;
+ break;
+#if POKA == 100
+#endif /* POKA == 100 */
+ default:
+ return GLX_BAD_ATTRIB;
+ }
+ return 0;
+}
+
+
+XVisualInfo * glXChooseVisual(int mode)
+{ int imode = 2;
+ if(mode & GLUT_DOUBLE)
+ imode = 1;
+ return
+ wglDescribePixelFormat(imode);
+}
+
+
+#if POKA
+#endif /* POKA */
+
 \ No newline at end of file
diff --git a/src/glut/os2/os2_menu.cpp b/src/glut/os2/os2_menu.cpp
index 4eef308e5a..56f2cdef8b 100644
--- a/src/glut/os2/os2_menu.cpp
+++ b/src/glut/os2/os2_menu.cpp
@@ -1,533 +1,533 @@
-
-/* Copyright (c) Mark J. Kilgard, 1994, 1997, 1998. */
-/* Copyright (c) Nate Robins, 1997. */
-
-/* This program is freely distributable without licensing fees
- and is provided without guarantee or warrantee expressed or
- implied. This program is -not- in the public domain. */
-
-/* This file completely re-implements glut_menu.c and glut_menu2.c
- for Win32. Note that neither glut_menu.c nor glut_menu2.c are
- compiled into Win32 GLUT. */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <assert.h>
-
-#include "glutint.h"
-
-void (GLUTCALLBACK *__glutMenuStatusFunc) (int, int, int);
-//GLUTmenu *__glutMappedMenu;
-//GLUTwindow *__glutMenuWindow;
-GLUTmenuItem *__glutItemSelected;
-unsigned __glutMenuButton;
-
-static GLUTmenu **menuList = NULL;
-static int menuListSize = 0;
-static UINT uniqueMenuHandler = 1;
-
-/* DEPRICATED, use glutMenuStatusFunc instead. */
-void GLUTAPIENTRY
-glutMenuStateFunc(GLUTmenuStateCB menuStateFunc)
-{
- __glutMenuStatusFunc = (GLUTmenuStatusCB) menuStateFunc;
-}
-
-void GLUTAPIENTRY
-glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc)
-{
- __glutMenuStatusFunc = menuStatusFunc;
-}
-
-void
-__glutSetMenu(GLUTmenu * menu)
-{
- __glutCurrentMenu = menu;
-}
-
-static void
-unmapMenu(GLUTmenu * menu)
-{
- if (menu->cascade) {
- unmapMenu(menu->cascade);
- menu->cascade = NULL;
- }
- menu->anchor = NULL;
- menu->highlighted = NULL;
-}
-
-void
-__glutFinishMenu(Window win, int x, int y)
-{
-
- unmapMenu(__glutMappedMenu);
-
- /* XXX Put in a GdiFlush just in case. Probably unnecessary. -mjk */
-// GdiFlush();
-
- if (__glutMenuStatusFunc) {
- __glutSetWindow(__glutMenuWindow);
- __glutSetMenu(__glutMappedMenu);
-
- /* Setting __glutMappedMenu to NULL permits operations that
- change menus or destroy the menu window again. */
- __glutMappedMenu = NULL;
-
- __glutMenuStatusFunc(GLUT_MENU_NOT_IN_USE, x, y);
- }
- /* Setting __glutMappedMenu to NULL permits operations that
- change menus or destroy the menu window again. */
- __glutMappedMenu = NULL;
-
- /* If an item is selected and it is not a submenu trigger,
- generate menu callback. */
- if (__glutItemSelected && !__glutItemSelected->isTrigger) {
- __glutSetWindow(__glutMenuWindow);
- /* When menu callback is triggered, current menu should be
- set to the callback menu. */
- __glutSetMenu(__glutItemSelected->menu);
- __glutItemSelected->menu->select(__glutItemSelected->value);
- }
- __glutMenuWindow = NULL;
-}
-
-static void
-mapMenu(GLUTmenu * menu, int x, int y)
-{
-//todo
-// TrackPopupMenu((HMENU) menu->win, TPM_LEFTALIGN |
-// (__glutMenuButton == TPM_RIGHTBUTTON) ? TPM_RIGHTBUTTON : TPM_LEFTBUTTON,
-// x, y, 0, __glutCurrentWindow->win, NULL);
-}
-
-void
-__glutStartMenu(GLUTmenu * menu, GLUTwindow * window,
- int x, int y, int x_win, int y_win)
-{
- assert(__glutMappedMenu == NULL);
- __glutMappedMenu = menu;
- __glutMenuWindow = window;
- __glutItemSelected = NULL;
- if (__glutMenuStatusFunc) {
- __glutSetMenu(menu);
- __glutSetWindow(window);
- __glutMenuStatusFunc(GLUT_MENU_IN_USE, x_win, y_win);
- }
- mapMenu(menu, x, y);
-}
-
-GLUTmenuItem *
-__glutGetUniqueMenuItem(GLUTmenu * menu, UINT unique)
-{
- GLUTmenuItem *item;
- int i;
-
- i = menu->num;
- item = menu->list;
- while (item) {
- if (item->unique == unique) {
- return item;
- }
- if (item->isTrigger) {
- GLUTmenuItem *subitem;
- subitem = __glutGetUniqueMenuItem(menuList[item->value], unique);
- if (subitem) {
- return subitem;
- }
- }
- i--;
- item = item->next;
- }
- return NULL;
-}
-
-GLUTmenuItem *
-__glutGetMenuItem(GLUTmenu * menu, Window win, int *which)
-{
- GLUTmenuItem *item;
- int i;
-
- i = menu->num;
- item = menu->list;
- while (item) {
- if (item->win == win) {
- *which = i;
- return item;
- }
- if (item->isTrigger) {
- GLUTmenuItem *subitem;
-
- subitem = __glutGetMenuItem(menuList[item->value],
- win, which);
- if (subitem) {
- return subitem;
- }
- }
- i--;
- item = item->next;
- }
- return NULL;
-}
-
-GLUTmenu *
-__glutGetMenu(Window win)
-{
- GLUTmenu *menu;
-
- menu = __glutMappedMenu;
- while (menu) {
- if (win == menu->win) {
- return menu;
- }
- menu = menu->cascade;
- }
- return NULL;
-}
-
-GLUTmenu *
-__glutGetMenuByNum(int menunum)
-{
- if (menunum < 1 || menunum > menuListSize) {
- return NULL;
- }
- return menuList[menunum - 1];
-}
-
-static int
-getUnusedMenuSlot(void)
-{
- int i;
-
- /* Look for allocated, unused slot. */
- for (i = 0; i < menuListSize; i++) {
- if (!menuList[i]) {
- return i;
- }
- }
- /* Allocate a new slot. */
- menuListSize++;
- if (menuList) {
- menuList = (GLUTmenu **)
- realloc(menuList, menuListSize * sizeof(GLUTmenu *));
- } else {
- /* XXX Some realloc's do not correctly perform a malloc
- when asked to perform a realloc on a NULL pointer,
- though the ANSI C library spec requires this. */
- menuList = (GLUTmenu **) malloc(sizeof(GLUTmenu *));
- }
- if (!menuList) {
- __glutFatalError("out of memory.");
- }
- menuList[menuListSize - 1] = NULL;
- return menuListSize - 1;
-}
-
-static void
-menuModificationError(void)
-{
- /* XXX Remove the warning after GLUT 3.0. */
- __glutWarning("The following is a new check for GLUT 3.0; update your code.");
- __glutFatalError("menu manipulation not allowed while menus in use.");
-}
-
-int GLUTAPIENTRY
-glutCreateMenu(GLUTselectCB selectFunc)
-{
- GLUTmenu *menu;
- int menuid;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- menuid = getUnusedMenuSlot();
- menu = (GLUTmenu *) malloc(sizeof(GLUTmenu));
- if (!menu) {
- __glutFatalError("out of memory.");
- }
- menu->id = menuid;
- menu->num = 0;
- menu->submenus = 0;
- menu->select = selectFunc;
- menu->list = NULL;
- menu->cascade = NULL;
- menu->highlighted = NULL;
- menu->anchor = NULL;
-//todo
-// menu->win = (HWND) CreatePopupMenu();
- menuList[menuid] = menu;
- __glutSetMenu(menu);
- return menuid + 1;
-}
-
-
-void GLUTAPIENTRY
-glutDestroyMenu(int menunum)
-{
- GLUTmenu *menu = __glutGetMenuByNum(menunum);
- GLUTmenuItem *item, *next;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- assert(menu->id == menunum - 1);
-//todo DestroyMenu( (HMENU) menu->win);
- menuList[menunum - 1] = NULL;
- /* free all menu entries */
- item = menu->list;
- while (item) {
- assert(item->menu == menu);
- next = item->next;
- free(item->label);
- free(item);
- item = next;
- }
- if (__glutCurrentMenu == menu) {
- __glutCurrentMenu = NULL;
- }
- free(menu);
-}
-
-int GLUTAPIENTRY
-glutGetMenu(void)
-{
- if (__glutCurrentMenu) {
- return __glutCurrentMenu->id + 1;
- } else {
- return 0;
- }
-}
-
-void GLUTAPIENTRY
-glutSetMenu(int menuid)
-{
- GLUTmenu *menu;
-
- if (menuid < 1 || menuid > menuListSize) {
- __glutWarning("glutSetMenu attempted on bogus menu.");
- return;
- }
- menu = menuList[menuid - 1];
- if (!menu) {
- __glutWarning("glutSetMenu attempted on bogus menu.");
- return;
- }
- __glutSetMenu(menu);
-}
-
-static void
-setMenuItem(GLUTmenuItem * item, const char *label,
- int value, Bool isTrigger)
-{
- GLUTmenu *menu;
-
- menu = item->menu;
- item->label = __glutStrdup(label);
- if (!item->label) {
- __glutFatalError("out of memory.");
- }
- item->isTrigger = isTrigger;
- item->len = (int) strlen(label);
- item->value = value;
- item->unique = uniqueMenuHandler++;
-//todo
-// if (isTrigger) {
-// AppendMenu((HMENU) menu->win, MF_POPUP, (UINT)item->win, label);
-// } else {
-// AppendMenu((HMENU) menu->win, MF_STRING, item->unique, label);
-// }
-}
-
-void GLUTAPIENTRY
-glutAddMenuEntry(const char *label, int value)
-{
- GLUTmenuItem *entry;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- entry = (GLUTmenuItem *) malloc(sizeof(GLUTmenuItem));
- if (!entry) {
- __glutFatalError("out of memory.");
- }
- entry->menu = __glutCurrentMenu;
- setMenuItem(entry, label, value, FALSE);
- __glutCurrentMenu->num++;
- entry->next = __glutCurrentMenu->list;
- __glutCurrentMenu->list = entry;
-}
-
-void GLUTAPIENTRY
-glutAddSubMenu(const char *label, int menu)
-{
- GLUTmenuItem *submenu;
- GLUTmenu *popupmenu;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- submenu = (GLUTmenuItem *) malloc(sizeof(GLUTmenuItem));
- if (!submenu) {
- __glutFatalError("out of memory.");
- }
- __glutCurrentMenu->submenus++;
- submenu->menu = __glutCurrentMenu;
- popupmenu = __glutGetMenuByNum(menu);
- if (popupmenu) {
- submenu->win = popupmenu->win;
- }
- setMenuItem(submenu, label, /* base 0 */ menu - 1, TRUE);
- __glutCurrentMenu->num++;
- submenu->next = __glutCurrentMenu->list;
- __glutCurrentMenu->list = submenu;
-}
-
-void GLUTAPIENTRY
-glutChangeToMenuEntry(int num, const char *label, int value)
-{
- GLUTmenuItem *item;
- int i;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- i = __glutCurrentMenu->num;
- item = __glutCurrentMenu->list;
- while (item) {
- if (i == num) {
- if (item->isTrigger) {
- /* If changing a submenu trigger to a menu entry, we
- need to account for submenus. */
- item->menu->submenus--;
- /* Nuke the Win32 menu. */
-//todo
-// DestroyMenu((HMENU) item->win);
- }
- free(item->label);
-
- item->label = strdup(label);
- if (!item->label)
- __glutFatalError("out of memory");
- item->isTrigger = FALSE;
- item->len = (int) strlen(label);
- item->value = value;
- item->unique = uniqueMenuHandler++;
-//todo
-// ModifyMenu((HMENU) __glutCurrentMenu->win, (UINT) i - 1,
-// MF_BYPOSITION | MFT_STRING, item->unique, label);
-
- return;
- }
- i--;
- item = item->next;
- }
- __glutWarning("Current menu has no %d item.", num);
-}
-
-void GLUTAPIENTRY
-glutChangeToSubMenu(int num, const char *label, int menu)
-{
- GLUTmenu *popupmenu;
- GLUTmenuItem *item;
- int i;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- i = __glutCurrentMenu->num;
- item = __glutCurrentMenu->list;
- while (item) {
- if (i == num) {
- if (!item->isTrigger) {
- /* If changing a menu entry to as submenu trigger, we
- need to account for submenus. */
- item->menu->submenus++;
-//todo
-// item->win = (HWND) CreatePopupMenu();
- }
- free(item->label);
-
- item->label = strdup(label);
- if (!item->label)
- __glutFatalError("out of memory");
- item->isTrigger = TRUE;
- item->len = (int) strlen(label);
- item->value = menu - 1;
- item->unique = uniqueMenuHandler++;
- popupmenu = __glutGetMenuByNum(menu);
- if (popupmenu)
- item->win = popupmenu->win;
-//todo
-// ModifyMenu((HMENU) __glutCurrentMenu->win, (UINT) i - 1,
-// MF_BYPOSITION | MF_POPUP, (UINT) item->win, label);
- return;
- }
- i--;
- item = item->next;
- }
- __glutWarning("Current menu has no %d item.", num);
-}
-
-void GLUTAPIENTRY
-glutRemoveMenuItem(int num)
-{
- GLUTmenuItem *item, **prev;
- int i;
-
- if (__glutMappedMenu) {
- menuModificationError();
- }
- i = __glutCurrentMenu->num;
- prev = &__glutCurrentMenu->list;
- item = __glutCurrentMenu->list;
- while (item) {
- if (i == num) {
- /* Found the menu item in list to remove. */
- __glutCurrentMenu->num--;
-
- /* Patch up menu's item list. */
- *prev = item->next;
-//todo
-// RemoveMenu((HMENU) __glutCurrentMenu->win, (UINT) i - 1, MF_BYPOSITION);
-
- free(item->label);
- free(item);
- return;
- }
- i--;
- prev = &item->next;
- item = item->next;
- }
- __glutWarning("Current menu has no %d item.", num);
-}
-
-void GLUTAPIENTRY
-glutAttachMenu(int button)
-{
- if (__glutCurrentWindow == __glutGameModeWindow) {
- __glutWarning("cannot attach menus in game mode.");
- return;
- }
- if (__glutMappedMenu) {
- menuModificationError();
- }
- if (__glutCurrentWindow->menu[button] < 1) {
- __glutCurrentWindow->buttonUses++;
- }
- __glutCurrentWindow->menu[button] = __glutCurrentMenu->id + 1;
-}
-
-void GLUTAPIENTRY
-glutDetachMenu(int button)
-{
- if (__glutMappedMenu) {
- menuModificationError();
- }
- if (__glutCurrentWindow->menu[button] > 0) {
- __glutCurrentWindow->buttonUses--;
- __glutCurrentWindow->menu[button] = 0;
- }
-}
-
+
+/* Copyright (c) Mark J. Kilgard, 1994, 1997, 1998. */
+/* Copyright (c) Nate Robins, 1997. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+/* This file completely re-implements glut_menu.c and glut_menu2.c
+ for Win32. Note that neither glut_menu.c nor glut_menu2.c are
+ compiled into Win32 GLUT. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "glutint.h"
+
+void (GLUTCALLBACK *__glutMenuStatusFunc) (int, int, int);
+//GLUTmenu *__glutMappedMenu;
+//GLUTwindow *__glutMenuWindow;
+GLUTmenuItem *__glutItemSelected;
+unsigned __glutMenuButton;
+
+static GLUTmenu **menuList = NULL;
+static int menuListSize = 0;
+static UINT uniqueMenuHandler = 1;
+
+/* DEPRICATED, use glutMenuStatusFunc instead. */
+void GLUTAPIENTRY
+glutMenuStateFunc(GLUTmenuStateCB menuStateFunc)
+{
+ __glutMenuStatusFunc = (GLUTmenuStatusCB) menuStateFunc;
+}
+
+void GLUTAPIENTRY
+glutMenuStatusFunc(GLUTmenuStatusCB menuStatusFunc)
+{
+ __glutMenuStatusFunc = menuStatusFunc;
+}
+
+void
+__glutSetMenu(GLUTmenu * menu)
+{
+ __glutCurrentMenu = menu;
+}
+
+static void
+unmapMenu(GLUTmenu * menu)
+{
+ if (menu->cascade) {
+ unmapMenu(menu->cascade);
+ menu->cascade = NULL;
+ }
+ menu->anchor = NULL;
+ menu->highlighted = NULL;
+}
+
+void
+__glutFinishMenu(Window win, int x, int y)
+{
+
+ unmapMenu(__glutMappedMenu);
+
+ /* XXX Put in a GdiFlush just in case. Probably unnecessary. -mjk */
+// GdiFlush();
+
+ if (__glutMenuStatusFunc) {
+ __glutSetWindow(__glutMenuWindow);
+ __glutSetMenu(__glutMappedMenu);
+
+ /* Setting __glutMappedMenu to NULL permits operations that
+ change menus or destroy the menu window again. */
+ __glutMappedMenu = NULL;
+
+ __glutMenuStatusFunc(GLUT_MENU_NOT_IN_USE, x, y);
+ }
+ /* Setting __glutMappedMenu to NULL permits operations that
+ change menus or destroy the menu window again. */
+ __glutMappedMenu = NULL;
+
+ /* If an item is selected and it is not a submenu trigger,
+ generate menu callback. */
+ if (__glutItemSelected && !__glutItemSelected->isTrigger) {
+ __glutSetWindow(__glutMenuWindow);
+ /* When menu callback is triggered, current menu should be
+ set to the callback menu. */
+ __glutSetMenu(__glutItemSelected->menu);
+ __glutItemSelected->menu->select(__glutItemSelected->value);
+ }
+ __glutMenuWindow = NULL;
+}
+
+static void
+mapMenu(GLUTmenu * menu, int x, int y)
+{
+//todo
+// TrackPopupMenu((HMENU) menu->win, TPM_LEFTALIGN |
+// (__glutMenuButton == TPM_RIGHTBUTTON) ? TPM_RIGHTBUTTON : TPM_LEFTBUTTON,
+// x, y, 0, __glutCurrentWindow->win, NULL);
+}
+
+void
+__glutStartMenu(GLUTmenu * menu, GLUTwindow * window,
+ int x, int y, int x_win, int y_win)
+{
+ assert(__glutMappedMenu == NULL);
+ __glutMappedMenu = menu;
+ __glutMenuWindow = window;
+ __glutItemSelected = NULL;
+ if (__glutMenuStatusFunc) {
+ __glutSetMenu(menu);
+ __glutSetWindow(window);
+ __glutMenuStatusFunc(GLUT_MENU_IN_USE, x_win, y_win);
+ }
+ mapMenu(menu, x, y);
+}
+
+GLUTmenuItem *
+__glutGetUniqueMenuItem(GLUTmenu * menu, UINT unique)
+{
+ GLUTmenuItem *item;
+ int i;
+
+ i = menu->num;
+ item = menu->list;
+ while (item) {
+ if (item->unique == unique) {
+ return item;
+ }
+ if (item->isTrigger) {
+ GLUTmenuItem *subitem;
+ subitem = __glutGetUniqueMenuItem(menuList[item->value], unique);
+ if (subitem) {
+ return subitem;
+ }
+ }
+ i--;
+ item = item->next;
+ }
+ return NULL;
+}
+
+GLUTmenuItem *
+__glutGetMenuItem(GLUTmenu * menu, Window win, int *which)
+{
+ GLUTmenuItem *item;
+ int i;
+
+ i = menu->num;
+ item = menu->list;
+ while (item) {
+ if (item->win == win) {
+ *which = i;
+ return item;
+ }
+ if (item->isTrigger) {
+ GLUTmenuItem *subitem;
+
+ subitem = __glutGetMenuItem(menuList[item->value],
+ win, which);
+ if (subitem) {
+ return subitem;
+ }
+ }
+ i--;
+ item = item->next;
+ }
+ return NULL;
+}
+
+GLUTmenu *
+__glutGetMenu(Window win)
+{
+ GLUTmenu *menu;
+
+ menu = __glutMappedMenu;
+ while (menu) {
+ if (win == menu->win) {
+ return menu;
+ }
+ menu = menu->cascade;
+ }
+ return NULL;
+}
+
+GLUTmenu *
+__glutGetMenuByNum(int menunum)
+{
+ if (menunum < 1 || menunum > menuListSize) {
+ return NULL;
+ }
+ return menuList[menunum - 1];
+}
+
+static int
+getUnusedMenuSlot(void)
+{
+ int i;
+
+ /* Look for allocated, unused slot. */
+ for (i = 0; i < menuListSize; i++) {
+ if (!menuList[i]) {
+ return i;
+ }
+ }
+ /* Allocate a new slot. */
+ menuListSize++;
+ if (menuList) {
+ menuList = (GLUTmenu **)
+ realloc(menuList, menuListSize * sizeof(GLUTmenu *));
+ } else {
+ /* XXX Some realloc's do not correctly perform a malloc
+ when asked to perform a realloc on a NULL pointer,
+ though the ANSI C library spec requires this. */
+ menuList = (GLUTmenu **) malloc(sizeof(GLUTmenu *));
+ }
+ if (!menuList) {
+ __glutFatalError("out of memory.");
+ }
+ menuList[menuListSize - 1] = NULL;
+ return menuListSize - 1;
+}
+
+static void
+menuModificationError(void)
+{
+ /* XXX Remove the warning after GLUT 3.0. */
+ __glutWarning("The following is a new check for GLUT 3.0; update your code.");
+ __glutFatalError("menu manipulation not allowed while menus in use.");
+}
+
+int GLUTAPIENTRY
+glutCreateMenu(GLUTselectCB selectFunc)
+{
+ GLUTmenu *menu;
+ int menuid;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ menuid = getUnusedMenuSlot();
+ menu = (GLUTmenu *) malloc(sizeof(GLUTmenu));
+ if (!menu) {
+ __glutFatalError("out of memory.");
+ }
+ menu->id = menuid;
+ menu->num = 0;
+ menu->submenus = 0;
+ menu->select = selectFunc;
+ menu->list = NULL;
+ menu->cascade = NULL;
+ menu->highlighted = NULL;
+ menu->anchor = NULL;
+//todo
+// menu->win = (HWND) CreatePopupMenu();
+ menuList[menuid] = menu;
+ __glutSetMenu(menu);
+ return menuid + 1;
+}
+
+
+void GLUTAPIENTRY
+glutDestroyMenu(int menunum)
+{
+ GLUTmenu *menu = __glutGetMenuByNum(menunum);
+ GLUTmenuItem *item, *next;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ assert(menu->id == menunum - 1);
+//todo DestroyMenu( (HMENU) menu->win);
+ menuList[menunum - 1] = NULL;
+ /* free all menu entries */
+ item = menu->list;
+ while (item) {
+ assert(item->menu == menu);
+ next = item->next;
+ free(item->label);
+ free(item);
+ item = next;
+ }
+ if (__glutCurrentMenu == menu) {
+ __glutCurrentMenu = NULL;
+ }
+ free(menu);
+}
+
+int GLUTAPIENTRY
+glutGetMenu(void)
+{
+ if (__glutCurrentMenu) {
+ return __glutCurrentMenu->id + 1;
+ } else {
+ return 0;
+ }
+}
+
+void GLUTAPIENTRY
+glutSetMenu(int menuid)
+{
+ GLUTmenu *menu;
+
+ if (menuid < 1 || menuid > menuListSize) {
+ __glutWarning("glutSetMenu attempted on bogus menu.");
+ return;
+ }
+ menu = menuList[menuid - 1];
+ if (!menu) {
+ __glutWarning("glutSetMenu attempted on bogus menu.");
+ return;
+ }
+ __glutSetMenu(menu);
+}
+
+static void
+setMenuItem(GLUTmenuItem * item, const char *label,
+ int value, Bool isTrigger)
+{
+ GLUTmenu *menu;
+
+ menu = item->menu;
+ item->label = __glutStrdup(label);
+ if (!item->label) {
+ __glutFatalError("out of memory.");
+ }
+ item->isTrigger = isTrigger;
+ item->len = (int) strlen(label);
+ item->value = value;
+ item->unique = uniqueMenuHandler++;
+//todo
+// if (isTrigger) {
+// AppendMenu((HMENU) menu->win, MF_POPUP, (UINT)item->win, label);
+// } else {
+// AppendMenu((HMENU) menu->win, MF_STRING, item->unique, label);
+// }
+}
+
+void GLUTAPIENTRY
+glutAddMenuEntry(const char *label, int value)
+{
+ GLUTmenuItem *entry;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ entry = (GLUTmenuItem *) malloc(sizeof(GLUTmenuItem));
+ if (!entry) {
+ __glutFatalError("out of memory.");
+ }
+ entry->menu = __glutCurrentMenu;
+ setMenuItem(entry, label, value, FALSE);
+ __glutCurrentMenu->num++;
+ entry->next = __glutCurrentMenu->list;
+ __glutCurrentMenu->list = entry;
+}
+
+void GLUTAPIENTRY
+glutAddSubMenu(const char *label, int menu)
+{
+ GLUTmenuItem *submenu;
+ GLUTmenu *popupmenu;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ submenu = (GLUTmenuItem *) malloc(sizeof(GLUTmenuItem));
+ if (!submenu) {
+ __glutFatalError("out of memory.");
+ }
+ __glutCurrentMenu->submenus++;
+ submenu->menu = __glutCurrentMenu;
+ popupmenu = __glutGetMenuByNum(menu);
+ if (popupmenu) {
+ submenu->win = popupmenu->win;
+ }
+ setMenuItem(submenu, label, /* base 0 */ menu - 1, TRUE);
+ __glutCurrentMenu->num++;
+ submenu->next = __glutCurrentMenu->list;
+ __glutCurrentMenu->list = submenu;
+}
+
+void GLUTAPIENTRY
+glutChangeToMenuEntry(int num, const char *label, int value)
+{
+ GLUTmenuItem *item;
+ int i;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ i = __glutCurrentMenu->num;
+ item = __glutCurrentMenu->list;
+ while (item) {
+ if (i == num) {
+ if (item->isTrigger) {
+ /* If changing a submenu trigger to a menu entry, we
+ need to account for submenus. */
+ item->menu->submenus--;
+ /* Nuke the Win32 menu. */
+//todo
+// DestroyMenu((HMENU) item->win);
+ }
+ free(item->label);
+
+ item->label = strdup(label);
+ if (!item->label)
+ __glutFatalError("out of memory");
+ item->isTrigger = FALSE;
+ item->len = (int) strlen(label);
+ item->value = value;
+ item->unique = uniqueMenuHandler++;
+//todo
+// ModifyMenu((HMENU) __glutCurrentMenu->win, (UINT) i - 1,
+// MF_BYPOSITION | MFT_STRING, item->unique, label);
+
+ return;
+ }
+ i--;
+ item = item->next;
+ }
+ __glutWarning("Current menu has no %d item.", num);
+}
+
+void GLUTAPIENTRY
+glutChangeToSubMenu(int num, const char *label, int menu)
+{
+ GLUTmenu *popupmenu;
+ GLUTmenuItem *item;
+ int i;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ i = __glutCurrentMenu->num;
+ item = __glutCurrentMenu->list;
+ while (item) {
+ if (i == num) {
+ if (!item->isTrigger) {
+ /* If changing a menu entry to as submenu trigger, we
+ need to account for submenus. */
+ item->menu->submenus++;
+//todo
+// item->win = (HWND) CreatePopupMenu();
+ }
+ free(item->label);
+
+ item->label = strdup(label);
+ if (!item->label)
+ __glutFatalError("out of memory");
+ item->isTrigger = TRUE;
+ item->len = (int) strlen(label);
+ item->value = menu - 1;
+ item->unique = uniqueMenuHandler++;
+ popupmenu = __glutGetMenuByNum(menu);
+ if (popupmenu)
+ item->win = popupmenu->win;
+//todo
+// ModifyMenu((HMENU) __glutCurrentMenu->win, (UINT) i - 1,
+// MF_BYPOSITION | MF_POPUP, (UINT) item->win, label);
+ return;
+ }
+ i--;
+ item = item->next;
+ }
+ __glutWarning("Current menu has no %d item.", num);
+}
+
+void GLUTAPIENTRY
+glutRemoveMenuItem(int num)
+{
+ GLUTmenuItem *item, **prev;
+ int i;
+
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ i = __glutCurrentMenu->num;
+ prev = &__glutCurrentMenu->list;
+ item = __glutCurrentMenu->list;
+ while (item) {
+ if (i == num) {
+ /* Found the menu item in list to remove. */
+ __glutCurrentMenu->num--;
+
+ /* Patch up menu's item list. */
+ *prev = item->next;
+//todo
+// RemoveMenu((HMENU) __glutCurrentMenu->win, (UINT) i - 1, MF_BYPOSITION);
+
+ free(item->label);
+ free(item);
+ return;
+ }
+ i--;
+ prev = &item->next;
+ item = item->next;
+ }
+ __glutWarning("Current menu has no %d item.", num);
+}
+
+void GLUTAPIENTRY
+glutAttachMenu(int button)
+{
+ if (__glutCurrentWindow == __glutGameModeWindow) {
+ __glutWarning("cannot attach menus in game mode.");
+ return;
+ }
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ if (__glutCurrentWindow->menu[button] < 1) {
+ __glutCurrentWindow->buttonUses++;
+ }
+ __glutCurrentWindow->menu[button] = __glutCurrentMenu->id + 1;
+}
+
+void GLUTAPIENTRY
+glutDetachMenu(int button)
+{
+ if (__glutMappedMenu) {
+ menuModificationError();
+ }
+ if (__glutCurrentWindow->menu[button] > 0) {
+ __glutCurrentWindow->buttonUses--;
+ __glutCurrentWindow->menu[button] = 0;
+ }
+}
+
 \ No newline at end of file
diff --git a/src/glut/os2/os2_winproc.cpp b/src/glut/os2/os2_winproc.cpp
index e2d4ba9d55..6ffe0d4624 100644
--- a/src/glut/os2/os2_winproc.cpp
+++ b/src/glut/os2/os2_winproc.cpp
@@ -1,1297 +1,1297 @@
-/* os2_winproc.c */
-
-
-#define INCL_DEV
-#include "WarpGL.h"
-#include "GL/os2mesa.h"
-
-
-#define _MEERROR_H_
-#include <mmioos2.h> /* It is from MMPM toolkit */
-#include <dive.h>
-#include <fourcc.h>
-
-
-#include "os2mesadef.h"
-#include "glutint.h"
-
-
-#define POKA 0
-
-#if POKA
-
-extern unsigned __glutMenuButton;
-extern GLUTidleCB __glutIdleFunc;
-extern GLUTtimer *__glutTimerList;
-extern void handleTimeouts(void);
-extern GLUTmenuItem *__glutGetUniqueMenuItem(GLUTmenu * menu, int unique);
-static HMENU __glutHMenu;
-
-#endif
-
-extern void _mesa_ResizeBuffersMESA( void );
-
-
-MRESULT EXPENTRY GlutWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
-MRESULT EXPENTRY GlutWindowChildProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
-void updateWindowState(GLUTwindow *window, int visState);
-
-volatile extern HAB hab; /* PM anchor block handle */
-volatile extern HPS hpsCurrent;
-
-RECTL rCtls[52];
-ULONG ulNumRcls;
-
-MRESULT EXPENTRY GlutWindowChildProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
-{ MRESULT rc;
- rc = GlutWindowProc(hwnd, msg, mp1, mp2 );
- return rc;
-}
-
-MRESULT EXPENTRY GlutWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
-{
- HPS hps = NULLHANDLE; /* presentation space handle */
- GLUTwindow* window; /* GLUT window associated with message. */
- GLUTmenu* menu; /* GLUT menu associated with message. */
- RECTL rclClient;
- POINTL point;
- int button = -1,rc,key;
-
-
-/* Process the message. */
-
- switch( msg )
- {
- case WM_CREATE:
- {
- SIZEL sizl = { 0L, 0L };
- LONG *alCaps;
- HDC hdc;
-
- /*+-----------------------------------------------------------------+*/
- /*| The client window is being created. Create the semaphore to |*/
- /*| control access to the presentation space. Then create the |*/
- /*| thread that will draw the lines. |*/
- /*+-----------------------------------------------------------------+*/
- // DosCreateMutexSem( (PSZ)NULL, &hmtxPS, 0UL, FALSE );
-
- hdc = WinOpenWindowDC(hwnd);
-
- /*+-----------------------------------------------------------------+*/
- /*| Create a non-cached presentation space. We will not release |*/
- /*| this PS, as we will be Selecting a Palette to this PS and then |*/
- /*| animating the palette. Upon releasing a PS the palette is no |*/
- /*| longer selected for obvious reasons. |*/
- /*+-----------------------------------------------------------------+*/
- hpsCurrent = GpiCreatePS( hab,
- hdc,
- &sizl,
- PU_PELS | GPIF_DEFAULT |
- GPIT_MICRO | GPIA_ASSOC );
-// DevQueryCaps( hdc, lStart, lCount, alCaps );
-// fPaletteCaps = alCaps[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER;
-// PaletteInit(3);
- /* ¯¥p¥¢®¤ hpsBuffer ¢ p¥¦¨¬ RGB color table */
-
- GpiCreateLogColorTable(hpsCurrent,0 ,LCOLF_RGB,0,0,NULL);
- GpiSetPattern(hpsCurrent,PATSYM_SOLID);
- GpiSetPatternSet(hpsCurrent,LCID_DEFAULT);
-
- }
- break;
-
- return 0;
- case WM_CLOSE:
- WinPostMsg( hwnd, WM_QUIT, NULL, NULL );
-
- return 0;
-
- case WM_PAINT:
- window = __glutGetWindow(hwnd);
- if (window)
- {
- PWMC ctx;
-// hps = WinBeginPaint(hwnd,NULLHANDLE,&rclClient);
- hps = WinBeginPaint(hwnd,NULLHANDLE,&rclClient);
- // blit Dive buffer to screen.
-
- {
- SWP swp; // Window position
- POINTL pointl; // Point to offset from Desktop
-
- // Convert the point to offset from desktop lower left.
- pointl.x = 0;
- pointl.y = 0;
- WinMapWindowPoints ( hwnd, HWND_DESKTOP, &pointl, 1 );
-
-
-// ctx = window->ctx;
-// ctx->xDiveScr = pointl.x;
-// ctx->yDiveScr = pointl.y;
- }
-// rc = DiveBlitImage (ctx->hDive,
-// ctx->ulDiveBufferNumber,
-// DIVE_BUFFER_SCREEN );
-//
-
- if (window->win == hwnd) {
- __glutPostRedisplay(window, GLUT_REPAIR_WORK);
- } else if (window->overlay && window->overlay->win == hwnd) {
- __glutPostRedisplay(window, GLUT_OVERLAY_REPAIR_WORK);
- }
- WinEndPaint(hps);
- } else {
-
- hps = WinBeginPaint(hwnd,NULLHANDLE,&rclClient);
- WinFillRect(hps, &rclClient, CLR_WHITE);
- WinEndPaint(hps);
- }
- break;
-
- case WM_VRNDISABLED:
-
-// pwinData->fDataInProcess = TRUE;
-// DiveSetupBlitter ( pwinData->hDive, 0 );
-// pwinData->fVrnDisabled = TRUE;
- break;
-
- case WM_VRNENABLED:
- { HRGN hrgn; /* Region handle */
- RGNRECT rgnCtl; /* Processing control structure */
-// RECTL rCtls[52];
-// ULONG ulNumRcls;
-
-// pwinData->fDataInProcess = TRUE;
- hps = WinGetPS ( hwnd );
- if ( !hps )
- break;
- hrgn = GpiCreateRegion ( hps, 0L, NULL );
- if ( hrgn )
- { /* NOTE: If mp1 is zero, then this was just a move message.
- ** Illustrate the visible region on a WM_VRNENABLE.
- */
- WinQueryVisibleRegion ( hwnd, hrgn );
- rgnCtl.ircStart = 0;
- rgnCtl.crc = 50;
- rgnCtl.ulDirection = 1;
-
- /* Get the all ORed rectangles */
- if ( GpiQueryRegionRects ( hps, hrgn, NULL,
- &rgnCtl, rCtls) )
- {
- ulNumRcls = rgnCtl.crcReturned;
-
- /* Now find the window position and size, relative to parent.
- */
-// WinQueryWindowPos ( pwinData->hwndClient, &pwinData->swp );
-
-// rcl.xLeft = 0;
-// rcl.yBottom = 0;
-
- /* Convert the point to offset from desktop lower left.
- */
-// pointl.x = pwinData->swp.x;
-// pointl.y = pwinData->swp.y;
-
-// WinMapWindowPoints ( pwinData->hwndFrame,
-// HWND_DESKTOP, &pointl, 1 );
-
-// pwinData->cxWindowPos = pointl.x;
-// pwinData->cyWindowPos = pointl.y;
-
- }
- GpiDestroyRegion( hps, hrgn );
- }
- WinReleasePS( hps );
-
- }
- break;
-
- case WM_SIZE:
- window = __glutGetWindow(hwnd);
- if (window)
- { int width,height;
- width = SHORT1FROMMP(mp2);
- height = SHORT2FROMMP(mp2);
- if (width != window->width || height != window->height) {
-#if 0 /* Win32 GLUT does not support overlays for now. */
- if (window->overlay) {
- XResizeWindow(__glutDisplay, window->overlay->win, width, height);
- }
-#endif
- window->width = width;
- window->height = height;
- __glutSetWindow(window);
- if(width <= 0 || height <= 0)
- break;
- _mesa_ResizeBuffersMESA();
-
- /* Do not execute OpenGL out of sequence with respect
- to the SetWindowPos request! */
- window->reshape(width, height);
- window->forceReshape = FALSE;
- /* A reshape should be considered like posting a
- repair request. */
- __glutPostRedisplay(window, GLUT_REPAIR_WORK);
- }
- }
- return 0;
- case WM_SHOW:
- window = __glutGetWindow(hwnd);
- if (window) {
- int visState;
- visState = SHORT1FROMMP( mp1 );
- updateWindowState(window, visState);
- }
- return 0;
-
- case WM_ACTIVATE:
- window = __glutGetWindow(hwnd);
-// /* Make sure we re-select the correct palette if needed. */
-// if (LOWORD(wParam)) {
-// PostMessage(hwnd, WM_PALETTECHANGED, 0, 0);
-// }
- if (window) {
- int visState;
- visState = SHORT1FROMMP( mp1 );
- updateWindowState(window, visState);
- }
- return 0;
-
- case WM_CHAR:
- { USHORT fsflags;
- window = __glutGetWindow(hwnd);
- if (!window) {
- break;
- }
- fsflags = SHORT1FROMMP(mp1);
-/* ?? */
- if((fsflags & KC_KEYUP) ) /* ¨£­®p¨p㥬 ®â¦ â¨¥ ª­®¯ª¨, p¥ £¨p㥬 ⮫쪮 ­  ­ ¦ â¨¥ */
- break;
-///////////////////////////////////////////////////
- if(!(fsflags & KC_CHAR) )
- {
- if (!(fsflags & KC_VIRTUALKEY))
- break;
- key = 0;
- /* Get the virtual key from mp2. */
- switch (SHORT2FROMMP(mp2))
- {
-/* directional keys */
- case VK_LEFT: key = GLUT_KEY_LEFT; break;
- case VK_UP: key = GLUT_KEY_UP; break;
- case VK_RIGHT: key = GLUT_KEY_RIGHT; break;
- case VK_DOWN: key = GLUT_KEY_DOWN; break;
-
- case VK_PAGEUP: key = GLUT_KEY_PAGE_UP; break;
- case VK_PAGEDOWN:key = GLUT_KEY_PAGE_DOWN; break;
- case VK_HOME: key = GLUT_KEY_HOME;break;
- case VK_END: key = GLUT_KEY_END; break;
- case VK_INSERT: key = GLUT_KEY_INSERT; break;
-
-/* function keys */
- case VK_F1 : key = GLUT_KEY_F1; break;
- case VK_F2 : key = GLUT_KEY_F2; break;
- case VK_F3 : key = GLUT_KEY_F3; break;
- case VK_F4 : key = GLUT_KEY_F4; break;
- case VK_F5 : key = GLUT_KEY_F5; break;
- case VK_F6 : key = GLUT_KEY_F6; break;
- case VK_F7 : key = GLUT_KEY_F7; break;
- case VK_F8 : key = GLUT_KEY_F8; break;
- case VK_F9 : key = GLUT_KEY_F9; break;
- case VK_F10: key = GLUT_KEY_F10;break;
- case VK_F11: key = GLUT_KEY_F11; break;
- case VK_F12: key = GLUT_KEY_F12; break;
- case VK_ESC: key = -1; break; /* Character codes */
- case VK_SPACE: key = -1; break;
- case VK_TAB: key = -1; break;
- }
- if(!key)
- { break; /* Key Not implemented */
- }
- if(key > 0)
- { if (!window->special) /* ­¥ ãáâ ­®¢«¥­® ®¡à ¡®â稪  */
- break;
-
- WinQueryPointerPos(HWND_DESKTOP,&point);
- ScreenToClient(window->win, &point);
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if(WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* high order bit is on */
- __glutModifierMask |= ShiftMask;
- if(WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
- __glutModifierMask |= ControlMask;
- if(WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
- __glutModifierMask |= Mod1Mask;
- window->special(key, point.x, point.y);
- __glutModifierMask = (unsigned int) ~0;
- return 0;
- }
-
- }
-/////////////////////////////////////////////////////
- /* If we are ignoring auto repeated key strokes for the window, bail. */
- if (window->ignoreKeyRepeat && (CHAR3FROMMP(mp1)) )
- break;
- if(!((unsigned char)SHORT1FROMMP(mp2)) ) /* ¨£­®p¨p㥬 ­¥á¨¬¢®«ì­ë¥ ª®¤ë */
- break;
- if (window->keyboard) {
- WinQueryPointerPos(HWND_DESKTOP,&point);
-
- ScreenToClient(window->win, &point);
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if(WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* high order bit is on */
- __glutModifierMask |= ShiftMask;
- if(WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
- __glutModifierMask |= ControlMask;
- if(WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
- __glutModifierMask |= Mod1Mask;
- window->keyboard((unsigned char)SHORT1FROMMP(mp2), point.x, point.y);
- __glutModifierMask = (unsigned int) ~0;
- }
- return 0;
- } /* endof case WM_CHAR: */
-////////////////////////////////////////////////
- case WM_BUTTON1DOWN:
- button = GLUT_LEFT_BUTTON;
- case WM_BUTTON3DOWN:
- if (button < 0)
- button = GLUT_MIDDLE_BUTTON;
- case WM_BUTTON2DOWN:
- if (button < 0)
- button = GLUT_RIGHT_BUTTON;
- { POINTS psh;
- psh = *((POINTS *)&mp1);
- point.x = psh.x;
- point.y = psh.y;
- }
- /* finish the menu if we get a button down message (user must have
- cancelled the menu). */
- if (__glutMappedMenu) {
- /* TODO: take this out once the menu on middle mouse stuff works
- properly. */
- if (button == GLUT_MIDDLE_BUTTON)
- return 0;
- /* get current mouse pointer position */
-// WinQueryPointerPos(HWND_DESKTOP,&point);
- /* map from desktop to client window */
-// WinMapWindowPoints(HWND_DESKTOP, hwnd, &point, 1);
- __glutItemSelected = NULL;
- __glutFinishMenu(hwnd, point.x, point.y);
- return 0;
- }
- window = __glutGetWindow(hwnd);
- if (window) {
- window->buttonDownState = button+1;
- menu = __glutGetMenuByNum(window->menu[button]);
- if (menu) {
-//todo
-// __glutMenuButton = button == GLUT_RIGHT_BUTTON ? TPM_RIGHTBUTTON :
-// button == GLUT_LEFT_BUTTON ? TPM_LEFTBUTTON :
-// 0x0001;
-// __glutStartMenu(menu, window, point.x, point.y, x, y);
- } else if (window->mouse) {
-
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* < 0 = high order bit is on. */
- __glutModifierMask |= ShiftMask;
- if (WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
- __glutModifierMask |= ControlMask;
- if (WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
- __glutModifierMask |= Mod1Mask;
- window->mouse(button, GLUT_DOWN, point.x, point.y);
- __glutModifierMask = (unsigned int)~0;
- } else {
- /* Stray mouse events. Ignore. */
- }
- }
- return 0;
-
- break;
-/********************************************/
- case WM_BUTTON1UP:
- button = GLUT_LEFT_BUTTON;
- case WM_BUTTON3UP:
- if (button < 0)
- button = GLUT_MIDDLE_BUTTON;
- case WM_BUTTON2UP:
- if (button < 0)
- button = GLUT_RIGHT_BUTTON;
- { POINTS psh;
- psh = *((POINTS *)&mp1);
- point.x = psh.x;
- point.y = psh.y;
- }
- /* Bail out if we're processing a menu. */
- /* Bail out = ¢ë¡à®á¨âìáï á ¯ à èã⮬ */
- if (__glutMappedMenu) {
- WinQueryPointerPos(HWND_DESKTOP,&point);
- WinMapWindowPoints(HWND_DESKTOP, hwnd, &point, 1);
- /* if we're getting the middle button up signal, then something
- on the menu was selected. */
- if (button == GLUT_MIDDLE_BUTTON) {
- return 0;
- /* For some reason, the code below always returns -1 even
- though the point IS IN THE ITEM! Therefore, just bail out if
- we get a middle mouse up. The user must select using the
- left mouse button. Stupid Win32. */
-#if 0
- int item = MenuItemFromPoint(hwnd, __glutHMenu, point);
- if (item != -1)
- __glutItemSelected = (GLUTmenuItem*)GetMenuItemID(__glutHMenu, item);
- else
- __glutItemSelected = NULL;
- __glutFinishMenu(hwnd, point.x, point.y);
-#endif
- } else {
- __glutItemSelected = NULL;
- __glutFinishMenu(hwnd, point.x, point.y);
- }
- return 0;
- }
-
- window = __glutGetWindow(hwnd);
- if(window)
- window->buttonDownState = 0;
-
- if (window && window->mouse) {
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* < 0 = high order bit is on */
- __glutModifierMask |= ShiftMask;
- if (WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
- __glutModifierMask |= ControlMask;
- if (WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
- __glutModifierMask |= Mod1Mask;
- window->mouse(button, GLUT_UP, point.x, point.y);
-
- __glutModifierMask = (unsigned int)~0;
- } else {
- /* Window might have been destroyed and all the
- events for the window may not yet be received. */
- }
- return 0;
-
-
- break;
-//////////////////////////////////////////////////
- case WM_COMMAND:
- window = __glutGetWindow(hwnd);
- if (window)
- { if (window->wm_command)
- window->wm_command(hwnd,mp1,mp2);
- }
- break;
-
- case WM_MOUSEMOVE:
- if (!__glutMappedMenu) {
- window = __glutGetWindow(hwnd);
- if (window) {
- /* If motion function registered _and_ buttons held *
- down, call motion function... */
- { POINTS psh;
- psh = *((POINTS *)&mp1);
- point.x = psh.x;
- point.y = psh.y;
- }
-
- if (window->motion && window->buttonDownState) {
- __glutSetWindow(window);
- window->motion(point.x, point.y);
- }
- /* If passive motion function registered _and_
- buttons not held down, call passive motion
- function... */
- else if (window->passive && !window->buttonDownState) {
- __glutSetWindow(window);
- window->passive(point.x, point.y);
- }
- }
- } else {
- /* Motion events are thrown away when a pop up menu is
- active. */
- }
- return 0;
-
-
- default:
- /* For all other messages, let the default window procedure process them. */
- return ( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
-
- } //endof switch( msg )
- return ( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
-// return NULL;
-}
-
-void APIENTRY glutCommandFunc(GLUTcommandCB Func)
-{
-extern GLUTwindow *__glutCurrentWindow;
- __glutCurrentWindow->wm_command = Func;
-}
-
-
-
-
-void
-updateWindowState(GLUTwindow *window, int visState)
-{
- GLUTwindow* child;
-
- /* XXX shownState and visState are the same in Win32. */
- window->shownState = visState;
- if (visState != window->visState) {
- if (window->windowStatus) {
- window->visState = visState;
- __glutSetWindow(window);
- window->windowStatus(visState);
- }
- }
- /* Since Win32 only sends an activate for the toplevel window,
- update the visibility for all the child windows. */
- child = window->children;
- while (child) {
- updateWindowState(child, visState);
- child = child->siblings;
- }
-}
-
-#if POKA
-
-LONG WINAPI
-__glutWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- POINT point; /* Point structure. */
- PAINTSTRUCT ps; /* Paint structure. */
- LPMINMAXINFO minmax; /* Minimum/maximum info structure. */
- GLUTwindow* window; /* GLUT window associated with message. */
- GLUTmenu* menu; /* GLUT menu associated with message. */
- int x, y, width, height, key;
- int button = -1;
-
- switch(msg) {
- case WM_CREATE:
- return 0;
- case WM_CLOSE:
- PostQuitMessage(0);
- return 0;
-#if 0
- case WM_DESTROY:
- /* XXX NVidia's NT OpenGL can have problems closing down
- its OpenGL internal data structures if we just allow
- the process to terminate without unbinding and deleting
- the windows context. Apparently, DirectDraw unloads
- before OPENGL32.DLL in the close down sequence, but
- NVidia's NT OpenGL needs DirectDraw to close down its
- data structures. */
- window = __glutGetWindow(hwnd);
- if (window) {
- if (window->ctx) {
- wglMakeCurrent(NULL, NULL);
- wglDeleteContext(window->ctx);
- }
- }
- return 0;
-#endif
-
- case WM_SYSKEYUP:
- case WM_KEYUP:
- window = __glutGetWindow(hwnd);
- if (!window) {
- break;
- }
- /* Win32 is dumb and sends these messages only to the parent
- window. Therefore, find out if we're in a child window and
- call the child windows keyboard callback if we are. */
- if (window->parent) {
- GetCursorPos(&point);
- ScreenToClient(hwnd, &point);
- hwnd = ChildWindowFromPoint(hwnd, point);
- window = __glutGetWindow(hwnd);
- }
- if (window->specialUp || window->keyboardUp) {
- GetCursorPos(&point);
- ScreenToClient(window->win, &point);
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
- __glutModifierMask |= ShiftMask;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
- __glutModifierMask |= ControlMask;
- if (GetKeyState(VK_MENU) < 0)
- __glutModifierMask |= Mod1Mask;
- switch (wParam) {
- /* *INDENT-OFF* */
- case VK_F1: key = GLUT_KEY_F1; break;
- case VK_F2: key = GLUT_KEY_F2; break;
- case VK_F3: key = GLUT_KEY_F3; break;
- case VK_F4: key = GLUT_KEY_F4; break;
- case VK_F5: key = GLUT_KEY_F5; break;
- case VK_F6: key = GLUT_KEY_F6; break;
- case VK_F7: key = GLUT_KEY_F7; break;
- case VK_F8: key = GLUT_KEY_F8; break;
- case VK_F9: key = GLUT_KEY_F9; break;
- case VK_F10: key = GLUT_KEY_F10; break;
- case VK_F11: key = GLUT_KEY_F11; break;
- case VK_F12: key = GLUT_KEY_F12; break;
- case VK_LEFT: key = GLUT_KEY_LEFT; break;
- case VK_UP: key = GLUT_KEY_UP; break;
- case VK_RIGHT: key = GLUT_KEY_RIGHT; break;
- case VK_DOWN: key = GLUT_KEY_DOWN; break;
- case VK_PRIOR: key = GLUT_KEY_PAGE_UP; break;
- case VK_NEXT: key = GLUT_KEY_PAGE_DOWN; break;
- case VK_HOME: key = GLUT_KEY_HOME; break;
- case VK_END: key = GLUT_KEY_END; break;
- case VK_INSERT: key = GLUT_KEY_INSERT; break;
- case VK_DELETE:
- /* Delete is an ASCII character. */
- if (window->keyboardUp) {
- window->keyboardUp((unsigned char) 127, point.x, point.y);
- }
- return 0;
- /* *INDENT-ON* */
- default:
- if (window->keyboardUp) {
- key = MapVirtualKey(wParam, 2); /* Map to ASCII. */
- if (isascii(key) && (key != 0)) {
-
- /* XXX Attempt to determine modified ASCII character
- is quite incomplete. Digits, symbols, CapsLock,
- Ctrl, and numeric keypad are all ignored. Fix this. */
-
- if (!(__glutModifierMask & ShiftMask))
- key = tolower(key);
- window->keyboardUp((unsigned char) key, point.x, point.y);
- }
- }
- __glutModifierMask = (unsigned int) ~0;
- return 0;
- }
- if (window->specialUp) {
- window->specialUp(key, point.x, point.y);
- }
- __glutModifierMask = (unsigned int) ~0;
- }
- return 0;
-
- case WM_SYSCHAR:
- case WM_CHAR:
- window = __glutGetWindow(hwnd);
- if (!window) {
- break;
- }
-
- /* Bit 30 of lParam is set if key already held down. If
- we are ignoring auto repeated key strokes for the window, bail. */
- if (window->ignoreKeyRepeat && (lParam & (1 << 30)) ) {
- break;
- }
-
- /* Win32 is dumb and sends these messages only to the parent
- window. Therefore, find out if we're in a child window and
- call the child windows keyboard callback if we are. */
- if (window->parent) {
- GetCursorPos(&point);
- ScreenToClient(hwnd, &point);
- hwnd = ChildWindowFromPoint(hwnd, point);
- window = __glutGetWindow(hwnd);
- }
- if (window->keyboard) {
- GetCursorPos(&point);
- ScreenToClient(window->win, &point);
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
- __glutModifierMask |= ShiftMask;
- if (GetKeyState(VK_CONTROL) < 0)
- __glutModifierMask |= ControlMask;
- if (GetKeyState(VK_MENU) < 0)
- __glutModifierMask |= Mod1Mask;
- window->keyboard((unsigned char)wParam, point.x, point.y);
- __glutModifierMask = (unsigned int) ~0;
- }
- return 0;
-
- case WM_SYSKEYDOWN:
- case WM_KEYDOWN:
- window = __glutGetWindow(hwnd);
- if (!window) {
- break;
- }
-
- /* Bit 30 of lParam is set if key already held down. If
- we are ignoring auto repeated key strokes for the window, bail. */
- if (window->ignoreKeyRepeat && (lParam & (1 << 30)) ) {
- break;
- }
-
- /* Win32 is dumb and sends these messages only to the parent
- window. Therefore, find out if we're in a child window and
- call the child windows keyboard callback if we are. */
- if (window->parent) {
- GetCursorPos(&point);
- ScreenToClient(hwnd, &point);
- hwnd = ChildWindowFromPoint(hwnd, point);
- window = __glutGetWindow(hwnd);
- }
- if (window->special) {
- switch (wParam) {
- /* *INDENT-OFF* */
- /* function keys */
- case VK_F1: key = GLUT_KEY_F1; break;
- case VK_F2: key = GLUT_KEY_F2; break;
- case VK_F3: key = GLUT_KEY_F3; break;
- case VK_F4: key = GLUT_KEY_F4; break;
- case VK_F5: key = GLUT_KEY_F5; break;
- case VK_F6: key = GLUT_KEY_F6; break;
- case VK_F7: key = GLUT_KEY_F7; break;
- case VK_F8: key = GLUT_KEY_F8; break;
- case VK_F9: key = GLUT_KEY_F9; break;
- case VK_F10: key = GLUT_KEY_F10; break;
- case VK_F11: key = GLUT_KEY_F11; break;
- case VK_F12: key = GLUT_KEY_F12; break;
- /* directional keys */
- case VK_LEFT: key = GLUT_KEY_LEFT; break;
- case VK_UP: key = GLUT_KEY_UP; break;
- case VK_RIGHT: key = GLUT_KEY_RIGHT; break;
- case VK_DOWN: key = GLUT_KEY_DOWN; break;
- /* *INDENT-ON* */
-
- case VK_PRIOR:
- /* VK_PRIOR is Win32's Page Up */
- key = GLUT_KEY_PAGE_UP;
- break;
- case VK_NEXT:
- /* VK_NEXT is Win32's Page Down */
- key = GLUT_KEY_PAGE_DOWN;
- break;
- case VK_HOME:
- key = GLUT_KEY_HOME;
- break;
- case VK_END:
- key = GLUT_KEY_END;
- break;
- case VK_INSERT:
- key = GLUT_KEY_INSERT;
- break;
- case VK_DELETE:
- goto handleDelete;
- default:
- goto defproc;
- }
- GetCursorPos(&point);
- ScreenToClient(window->win, &point);
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
- __glutModifierMask |= ShiftMask;
- if (GetKeyState(VK_CONTROL) < 0)
- __glutModifierMask |= ControlMask;
- if (GetKeyState(VK_MENU) < 0)
- __glutModifierMask |= Mod1Mask;
- window->special(key, point.x, point.y);
- __glutModifierMask = (unsigned int) ~0;
- } else if (window->keyboard) {
- /* Specially handle any keys that match ASCII values but
- do not generate Windows WM_SYSCHAR or WM_CHAR messages. */
- switch (wParam) {
- case VK_DELETE:
- handleDelete:
- /* Delete is an ASCII character. */
- GetCursorPos(&point);
- ScreenToClient(window->win, &point);
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
- __glutModifierMask |= ShiftMask;
- if (GetKeyState(VK_CONTROL) < 0)
- __glutModifierMask |= ControlMask;
- if (GetKeyState(VK_MENU) < 0)
- __glutModifierMask |= Mod1Mask;
- window->keyboard((unsigned char) 127, point.x, point.y);
- __glutModifierMask = (unsigned int) ~0;
- return 0;
- default:
- /* Let the following WM_SYSCHAR or WM_CHAR message generate
- the keyboard callback. */
- break;
- }
- }
- return 0;
-
- case WM_LBUTTONDOWN:
- button = GLUT_LEFT_BUTTON;
- case WM_MBUTTONDOWN:
- if (button < 0)
- button = GLUT_MIDDLE_BUTTON;
- case WM_RBUTTONDOWN:
- if (button < 0)
- button = GLUT_RIGHT_BUTTON;
-
- /* finish the menu if we get a button down message (user must have
- cancelled the menu). */
- if (__glutMappedMenu) {
- /* TODO: take this out once the menu on middle mouse stuff works
- properly. */
- if (button == GLUT_MIDDLE_BUTTON)
- return 0;
- GetCursorPos(&point);
- ScreenToClient(hwnd, &point);
- __glutItemSelected = NULL;
- __glutFinishMenu(hwnd, point.x, point.y);
- return 0;
- }
-
- /* set the capture so we can get mouse events outside the window */
- SetCapture(hwnd);
-
- /* Win32 doesn't return the same numbers as X does when the mouse
- goes beyond the upper or left side of the window. roll the
- Win32's 0..2^16 pointer co-ord range to 0 +/- 2^15. */
- x = LOWORD(lParam);
- y = HIWORD(lParam);
- if(x & 1 << 15) x -= (1 << 16);
- if(y & 1 << 15) y -= (1 << 16);
-
- window = __glutGetWindow(hwnd);
- if (window) {
- menu = __glutGetMenuByNum(window->menu[button]);
- if (menu) {
- point.x = LOWORD(lParam); point.y = HIWORD(lParam);
- ClientToScreen(window->win, &point);
- __glutMenuButton = button == GLUT_RIGHT_BUTTON ? TPM_RIGHTBUTTON :
- button == GLUT_LEFT_BUTTON ? TPM_LEFTBUTTON :
- 0x0001;
- __glutStartMenu(menu, window, point.x, point.y, x, y);
- } else if (window->mouse) {
-
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on. */
- __glutModifierMask |= ShiftMask;
- if (GetKeyState(VK_CONTROL) < 0)
- __glutModifierMask |= ControlMask;
- if (GetKeyState(VK_MENU) < 0)
- __glutModifierMask |= Mod1Mask;
- window->mouse(button, GLUT_DOWN, x, y);
- __glutModifierMask = (unsigned int)~0;
- } else {
- /* Stray mouse events. Ignore. */
- }
- }
- return 0;
-
- case WM_LBUTTONUP:
- button = GLUT_LEFT_BUTTON;
- case WM_MBUTTONUP:
- if (button < 0)
- button = GLUT_MIDDLE_BUTTON;
- case WM_RBUTTONUP:
- if (button < 0)
- button = GLUT_RIGHT_BUTTON;
-
- /* Bail out if we're processing a menu. */
- if (__glutMappedMenu) {
- GetCursorPos(&point);
- ScreenToClient(hwnd, &point);
- /* if we're getting the middle button up signal, then something
- on the menu was selected. */
- if (button == GLUT_MIDDLE_BUTTON) {
- return 0;
- /* For some reason, the code below always returns -1 even
- though the point IS IN THE ITEM! Therefore, just bail out if
- we get a middle mouse up. The user must select using the
- left mouse button. Stupid Win32. */
-#if 0
- int item = MenuItemFromPoint(hwnd, __glutHMenu, point);
- if (item != -1)
- __glutItemSelected = (GLUTmenuItem*)GetMenuItemID(__glutHMenu, item);
- else
- __glutItemSelected = NULL;
- __glutFinishMenu(hwnd, point.x, point.y);
-#endif
- } else {
- __glutItemSelected = NULL;
- __glutFinishMenu(hwnd, point.x, point.y);
- }
- return 0;
- }
-
- /* Release the mouse capture. */
- ReleaseCapture();
-
- window = __glutGetWindow(hwnd);
- if (window && window->mouse) {
- /* Win32 doesn't return the same numbers as X does when the
- mouse goes beyond the upper or left side of the window. roll
- the Win32's 0..2^16 pointer co-ord range to 0 +/- 2^15. */
- x = LOWORD(lParam);
- y = HIWORD(lParam);
- if(x & 1 << 15) x -= (1 << 16);
- if(y & 1 << 15) y -= (1 << 16);
-
- __glutSetWindow(window);
- __glutModifierMask = 0;
- if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
- __glutModifierMask |= ShiftMask;
- if (GetKeyState(VK_CONTROL) < 0)
- __glutModifierMask |= ControlMask;
- if (GetKeyState(VK_MENU) < 0)
- __glutModifierMask |= Mod1Mask;
- window->mouse(button, GLUT_UP, x, y);
- __glutModifierMask = (unsigned int)~0;
- } else {
- /* Window might have been destroyed and all the
- events for the window may not yet be received. */
- }
- return 0;
-
- case WM_ENTERMENULOOP:
- /* KLUDGE: create a timer that fires every 100 ms when we start a
- menu so that we can still process the idle & timer events (that
- way, the timers will fire during a menu pick and so will the
- idle func. */
- SetTimer(hwnd, 1, 1, NULL);
- return 0;
-
- case WM_TIMER:
-#if 0
- /* If the timer id is 2, then this is the timer that is set up in
- the main glut message processing loop, and we don't want to do
- anything but acknowledge that we got it. It is used to prevent
- CPU spiking when an idle function is installed. */
- if (wParam == 2)
- return 0;
-#endif
-
- /* only worry about the idle function and the timeouts, since
- these are the only events we expect to process during
- processing of a menu. */
- /* we no longer process the idle functions (as outlined in the
- README), since drawing can't be done until the menu has
- finished...it's pretty lame when the animation goes on, but
- doesn't update, so you get this weird jerkiness. */
-#if 0
- if (__glutIdleFunc)
- __glutIdleFunc();
-#endif
- if (__glutTimerList)
- handleTimeouts();
- return 0;
-
- case WM_EXITMENULOOP:
- /* nuke the above created timer...we don't need it anymore, since
- the menu is gone now. */
- KillTimer(hwnd, 1);
- return 0;
-
- case WM_MENUSELECT:
- if (lParam != 0)
- __glutHMenu = (HMENU)lParam;
- return 0;
-
- case WM_COMMAND:
- if (__glutMappedMenu) {
- if (GetSubMenu(__glutHMenu, LOWORD(wParam)))
- __glutItemSelected = NULL;
- else
- __glutItemSelected =
- __glutGetUniqueMenuItem(__glutMappedMenu, LOWORD(wParam));
- GetCursorPos(&point);
- ScreenToClient(hwnd, &point);
- __glutFinishMenu(hwnd, point.x, point.y);
- }
- return 0;
-
- case WM_MOUSEMOVE:
- if (!__glutMappedMenu) {
- window = __glutGetWindow(hwnd);
- if (window) {
- /* If motion function registered _and_ buttons held *
- down, call motion function... */
- x = LOWORD(lParam);
- y = HIWORD(lParam);
-
- /* Win32 doesn't return the same numbers as X does when the
- mouse goes beyond the upper or left side of the window.
- roll the Win32's 0..2^16 pointer co-ord range to 0..+/-2^15. */
- if(x & 1 << 15) x -= (1 << 16);
- if(y & 1 << 15) y -= (1 << 16);
-
- if (window->motion && wParam &
- (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) {
- __glutSetWindow(window);
- window->motion(x, y);
- }
- /* If passive motion function registered _and_
- buttons not held down, call passive motion
- function... */
- else if (window->passive &&
- ((wParam &
- (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) ==
- 0)) {
- __glutSetWindow(window);
- window->passive(x, y);
- }
- }
- } else {
- /* Motion events are thrown away when a pop up menu is
- active. */
- }
- return 0;
-
- case WM_GETMINMAXINFO:
- /* this voodoo is brought to you by Win32 (again). It allows the
- window to be bigger than the screen, and smaller than 100x100
- (although it doesn't seem to help the y minimum). */
- minmax = (LPMINMAXINFO)lParam;
- minmax->ptMaxSize.x = __glutScreenWidth;
- minmax->ptMaxSize.y = __glutScreenHeight;
- minmax->ptMinTrackSize.x = 0;
- minmax->ptMinTrackSize.y = 0;
- minmax->ptMaxTrackSize.x = __glutScreenWidth +
- GetSystemMetrics(SM_CXSIZE) * 2;
- minmax->ptMaxTrackSize.y = __glutScreenHeight +
- GetSystemMetrics(SM_CXSIZE) * 2 + GetSystemMetrics(SM_CYCAPTION);
- return 0;
-
- case WM_SIZE:
- window = __glutGetWindow(hwnd);
- if (window) {
- width = LOWORD(lParam);
- height = HIWORD(lParam);
- if (width != window->width || height != window->height) {
-#if 0 /* Win32 GLUT does not support overlays for now. */
- if (window->overlay) {
- XResizeWindow(__glutDisplay, window->overlay->win, width, height);
- }
-#endif
- window->width = width;
- window->height = height;
- __glutSetWindow(window);
- /* Do not execute OpenGL out of sequence with respect
- to the SetWindowPos request! */
- GdiFlush();
- window->reshape(width, height);
- window->forceReshape = FALSE;
- /* A reshape should be considered like posting a
- repair request. */
- __glutPostRedisplay(window, GLUT_REPAIR_WORK);
- }
- }
- return 0;
-
- case WM_SETCURSOR:
- /* If the cursor is not in the client area, then we want to send
- this message to the default window procedure ('cause its
- probably in the border or title, and we don't handle that
- cursor. otherwise, set our cursor. Win32 makes us set the
- cursor every time the mouse moves (DUMB!). */
- if(LOWORD(lParam) != HTCLIENT) {
- goto defproc;
- }
- window = __glutGetWindow(hwnd);
- if (window) {
- __glutSetCursor(window);
- }
- /* TODO: check out the info in DevStudio on WM_SETCURSOR in the
- DefaultAction section. */
- return 1;
-
- case WM_SETFOCUS:
- window = __glutGetWindow(hwnd);
- if (window) {
- window->entryState = WM_SETFOCUS;
- if (window->entry) {
- __glutSetWindow(window);
- window->entry(GLUT_ENTERED);
- /* XXX Generation of fake passive notify? See how much
- work the X11 code does to support fake passive notify
- callbacks. */
- }
- if (window->joystick && __glutCurrentWindow) {
- if (__glutCurrentWindow->joyPollInterval > 0) {
- MMRESULT result;
-
- /* Because Win32 will only let one window capture the
- joystick at a time, we must capture it when we get the
- focus and release it when we lose the focus. */
- result = joySetCapture(__glutCurrentWindow->win,
- JOYSTICKID1, 0, TRUE);
- if (result != JOYERR_NOERROR) {
- return 0;
- }
- (void) joySetThreshold(JOYSTICKID1,
- __glutCurrentWindow->joyPollInterval);
- }
- }
- }
- return 0;
-
- case WM_KILLFOCUS:
- window = __glutGetWindow(hwnd);
- if (window) {
- window->entryState = WM_KILLFOCUS;
- if (window->entry) {
- __glutSetWindow(window);
- window->entry(GLUT_LEFT);
- }
- if (window->joystick && __glutCurrentWindow) {
- if (__glutCurrentWindow->joyPollInterval > 0) {
- /* Because Win32 will only let one window capture the
- joystick at a time, we must capture it when we get the
- focus and release it when we lose the focus. */
- (void) joyReleaseCapture(JOYSTICKID1);
- }
- }
- }
- return 0;
- case WM_ACTIVATE:
- window = __glutGetWindow(hwnd);
- /* Make sure we re-select the correct palette if needed. */
- if (LOWORD(wParam)) {
- PostMessage(hwnd, WM_PALETTECHANGED, 0, 0);
- }
- if (window) {
- int visState;
-
- /* HIWORD(wParam) is the minimized flag. */
- visState = !HIWORD(wParam);
- updateWindowState(window, visState);
- }
- return 0;
-
- /* Colour Palette Management */
- case WM_PALETTECHANGED:
- if (hwnd == (HWND)wParam) {
- /* Don't respond to the message that we sent! */
- break;
- }
- /* fall through to WM_QUERYNEWPALETTE */
-
- case WM_QUERYNEWPALETTE:
- window = __glutGetWindow(hwnd);
- if (window && window->colormap) {
- UnrealizeObject(window->colormap->cmap);
- SelectPalette(window->hdc, window->colormap->cmap, FALSE);
- RealizePalette(window->hdc);
- return TRUE;
- }
- return FALSE;
-
- case MM_JOY1MOVE:
- case MM_JOY1ZMOVE:
- window = __glutGetWindow(hwnd);
- if (window->joystick) {
- JOYINFOEX jix;
- int x, y, z;
-
- /* Because WIN32 only supports messages for X, Y, and Z
- translations, we must poll for the rest */
- jix.dwSize = sizeof(jix);
- jix.dwFlags = JOY_RETURNALL;
- joyGetPosEx(JOYSTICKID1,&jix);
-
-#define SCALE(v) ((int) ((v - 32767)/32.768))
-
- /* Convert to integer for scaling. */
- x = jix.dwXpos;
- y = jix.dwYpos;
- z = jix.dwZpos;
- window->joystick(jix.dwButtons, SCALE(x), SCALE(y), SCALE(z));
-
- return TRUE;
- }
- return FALSE;
- case MM_JOY1BUTTONDOWN:
- case MM_JOY1BUTTONUP:
- window = __glutGetWindow(hwnd);
- if (window->joystick) {
- JOYINFOEX jix;
-
- /* Because WIN32 only supports messages for X, Y, and Z
- translations, we must poll for the rest */
- jix.dwSize = sizeof(jix);
- jix.dwFlags = JOY_RETURNALL;
- joyGetPosEx(JOYSTICKID1,&jix);
-
- return TRUE;
- }
- return FALSE;
-
-#if 0
- /* Miscellaneous messages (don't really need to enumerate them,
- but it's good to know what you're not getting sometimes). */
- case WM_DISPLAYCHANGE:
- break;
- case WM_NCHITTEST:
- /* This event is generated by every mouse move event. */
- goto defproc;
- case WM_NCMOUSEMOVE:
- goto defproc;
- case WM_NCACTIVATE:
- goto defproc;
- case WM_NCPAINT:
- goto defproc;
- case WM_NCCALCSIZE:
- goto defproc;
- case WM_NCCREATE:
- goto defproc;
- case WM_NCDESTROY:
- goto defproc;
- case WM_NCLBUTTONDOWN:
- goto defproc;
- case WM_SETTEXT:
- goto defproc;
- case WM_GETTEXT:
- goto defproc;
- case WM_ACTIVATEAPP:
- goto defproc;
- case WM_GETICON:
- goto defproc;
- case WM_ERASEBKGND:
- goto defproc;
- case WM_WINDOWPOSCHANGING:
- goto defproc;
- case WM_WINDOWPOSCHANGED:
- goto defproc;
- case WM_MOUSEACTIVATE:
- goto defproc;
- case WM_SHOWWINDOW:
- goto defproc;
- case WM_MOVING:
- goto defproc;
- case WM_MOVE:
- goto defproc;
- case WM_KEYUP:
- goto defproc;
- case WM_CAPTURECHANGED:
- goto defproc;
- case WM_SYSCOMMAND:
- goto defproc;
- case WM_ENTERSIZEMOVE:
- goto defproc;
- case WM_ENTERIDLE:
- goto defproc;
-#endif
-
- default:
- goto defproc;
- }
-
-defproc:
- return DefWindowProc(hwnd, msg, wParam, lParam);
-}
-
-#endif
-
-#if defined(__OS2PM__)
-Bool __glutSetWindowText(Window window, char *text)
-{
- return WinSetWindowText(window, (PCSZ)text);
-
-}
-
-#endif
+/* os2_winproc.c */
+
+
+#define INCL_DEV
+#include "WarpGL.h"
+#include "GL/os2mesa.h"
+
+
+#define _MEERROR_H_
+#include <mmioos2.h> /* It is from MMPM toolkit */
+#include <dive.h>
+#include <fourcc.h>
+
+
+#include "os2mesadef.h"
+#include "glutint.h"
+
+
+#define POKA 0
+
+#if POKA
+
+extern unsigned __glutMenuButton;
+extern GLUTidleCB __glutIdleFunc;
+extern GLUTtimer *__glutTimerList;
+extern void handleTimeouts(void);
+extern GLUTmenuItem *__glutGetUniqueMenuItem(GLUTmenu * menu, int unique);
+static HMENU __glutHMenu;
+
+#endif
+
+extern void _mesa_ResizeBuffersMESA( void );
+
+
+MRESULT EXPENTRY GlutWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
+MRESULT EXPENTRY GlutWindowChildProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
+void updateWindowState(GLUTwindow *window, int visState);
+
+volatile extern HAB hab; /* PM anchor block handle */
+volatile extern HPS hpsCurrent;
+
+RECTL rCtls[52];
+ULONG ulNumRcls;
+
+MRESULT EXPENTRY GlutWindowChildProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
+{ MRESULT rc;
+ rc = GlutWindowProc(hwnd, msg, mp1, mp2 );
+ return rc;
+}
+
+MRESULT EXPENTRY GlutWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
+{
+ HPS hps = NULLHANDLE; /* presentation space handle */
+ GLUTwindow* window; /* GLUT window associated with message. */
+ GLUTmenu* menu; /* GLUT menu associated with message. */
+ RECTL rclClient;
+ POINTL point;
+ int button = -1,rc,key;
+
+
+/* Process the message. */
+
+ switch( msg )
+ {
+ case WM_CREATE:
+ {
+ SIZEL sizl = { 0L, 0L };
+ LONG *alCaps;
+ HDC hdc;
+
+ /*+-----------------------------------------------------------------+*/
+ /*| The client window is being created. Create the semaphore to |*/
+ /*| control access to the presentation space. Then create the |*/
+ /*| thread that will draw the lines. |*/
+ /*+-----------------------------------------------------------------+*/
+ // DosCreateMutexSem( (PSZ)NULL, &hmtxPS, 0UL, FALSE );
+
+ hdc = WinOpenWindowDC(hwnd);
+
+ /*+-----------------------------------------------------------------+*/
+ /*| Create a non-cached presentation space. We will not release |*/
+ /*| this PS, as we will be Selecting a Palette to this PS and then |*/
+ /*| animating the palette. Upon releasing a PS the palette is no |*/
+ /*| longer selected for obvious reasons. |*/
+ /*+-----------------------------------------------------------------+*/
+ hpsCurrent = GpiCreatePS( hab,
+ hdc,
+ &sizl,
+ PU_PELS | GPIF_DEFAULT |
+ GPIT_MICRO | GPIA_ASSOC );
+// DevQueryCaps( hdc, lStart, lCount, alCaps );
+// fPaletteCaps = alCaps[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER;
+// PaletteInit(3);
+ /* ¯¥p¥¢®¤ hpsBuffer ¢ p¥¦¨¬ RGB color table */
+
+ GpiCreateLogColorTable(hpsCurrent,0 ,LCOLF_RGB,0,0,NULL);
+ GpiSetPattern(hpsCurrent,PATSYM_SOLID);
+ GpiSetPatternSet(hpsCurrent,LCID_DEFAULT);
+
+ }
+ break;
+
+ return 0;
+ case WM_CLOSE:
+ WinPostMsg( hwnd, WM_QUIT, NULL, NULL );
+
+ return 0;
+
+ case WM_PAINT:
+ window = __glutGetWindow(hwnd);
+ if (window)
+ {
+ PWMC ctx;
+// hps = WinBeginPaint(hwnd,NULLHANDLE,&rclClient);
+ hps = WinBeginPaint(hwnd,NULLHANDLE,&rclClient);
+ // blit Dive buffer to screen.
+
+ {
+ SWP swp; // Window position
+ POINTL pointl; // Point to offset from Desktop
+
+ // Convert the point to offset from desktop lower left.
+ pointl.x = 0;
+ pointl.y = 0;
+ WinMapWindowPoints ( hwnd, HWND_DESKTOP, &pointl, 1 );
+
+
+// ctx = window->ctx;
+// ctx->xDiveScr = pointl.x;
+// ctx->yDiveScr = pointl.y;
+ }
+// rc = DiveBlitImage (ctx->hDive,
+// ctx->ulDiveBufferNumber,
+// DIVE_BUFFER_SCREEN );
+//
+
+ if (window->win == hwnd) {
+ __glutPostRedisplay(window, GLUT_REPAIR_WORK);
+ } else if (window->overlay && window->overlay->win == hwnd) {
+ __glutPostRedisplay(window, GLUT_OVERLAY_REPAIR_WORK);
+ }
+ WinEndPaint(hps);
+ } else {
+
+ hps = WinBeginPaint(hwnd,NULLHANDLE,&rclClient);
+ WinFillRect(hps, &rclClient, CLR_WHITE);
+ WinEndPaint(hps);
+ }
+ break;
+
+ case WM_VRNDISABLED:
+
+// pwinData->fDataInProcess = TRUE;
+// DiveSetupBlitter ( pwinData->hDive, 0 );
+// pwinData->fVrnDisabled = TRUE;
+ break;
+
+ case WM_VRNENABLED:
+ { HRGN hrgn; /* Region handle */
+ RGNRECT rgnCtl; /* Processing control structure */
+// RECTL rCtls[52];
+// ULONG ulNumRcls;
+
+// pwinData->fDataInProcess = TRUE;
+ hps = WinGetPS ( hwnd );
+ if ( !hps )
+ break;
+ hrgn = GpiCreateRegion ( hps, 0L, NULL );
+ if ( hrgn )
+ { /* NOTE: If mp1 is zero, then this was just a move message.
+ ** Illustrate the visible region on a WM_VRNENABLE.
+ */
+ WinQueryVisibleRegion ( hwnd, hrgn );
+ rgnCtl.ircStart = 0;
+ rgnCtl.crc = 50;
+ rgnCtl.ulDirection = 1;
+
+ /* Get the all ORed rectangles */
+ if ( GpiQueryRegionRects ( hps, hrgn, NULL,
+ &rgnCtl, rCtls) )
+ {
+ ulNumRcls = rgnCtl.crcReturned;
+
+ /* Now find the window position and size, relative to parent.
+ */
+// WinQueryWindowPos ( pwinData->hwndClient, &pwinData->swp );
+
+// rcl.xLeft = 0;
+// rcl.yBottom = 0;
+
+ /* Convert the point to offset from desktop lower left.
+ */
+// pointl.x = pwinData->swp.x;
+// pointl.y = pwinData->swp.y;
+
+// WinMapWindowPoints ( pwinData->hwndFrame,
+// HWND_DESKTOP, &pointl, 1 );
+
+// pwinData->cxWindowPos = pointl.x;
+// pwinData->cyWindowPos = pointl.y;
+
+ }
+ GpiDestroyRegion( hps, hrgn );
+ }
+ WinReleasePS( hps );
+
+ }
+ break;
+
+ case WM_SIZE:
+ window = __glutGetWindow(hwnd);
+ if (window)
+ { int width,height;
+ width = SHORT1FROMMP(mp2);
+ height = SHORT2FROMMP(mp2);
+ if (width != window->width || height != window->height) {
+#if 0 /* Win32 GLUT does not support overlays for now. */
+ if (window->overlay) {
+ XResizeWindow(__glutDisplay, window->overlay->win, width, height);
+ }
+#endif
+ window->width = width;
+ window->height = height;
+ __glutSetWindow(window);
+ if(width <= 0 || height <= 0)
+ break;
+ _mesa_ResizeBuffersMESA();
+
+ /* Do not execute OpenGL out of sequence with respect
+ to the SetWindowPos request! */
+ window->reshape(width, height);
+ window->forceReshape = FALSE;
+ /* A reshape should be considered like posting a
+ repair request. */
+ __glutPostRedisplay(window, GLUT_REPAIR_WORK);
+ }
+ }
+ return 0;
+ case WM_SHOW:
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ int visState;
+ visState = SHORT1FROMMP( mp1 );
+ updateWindowState(window, visState);
+ }
+ return 0;
+
+ case WM_ACTIVATE:
+ window = __glutGetWindow(hwnd);
+// /* Make sure we re-select the correct palette if needed. */
+// if (LOWORD(wParam)) {
+// PostMessage(hwnd, WM_PALETTECHANGED, 0, 0);
+// }
+ if (window) {
+ int visState;
+ visState = SHORT1FROMMP( mp1 );
+ updateWindowState(window, visState);
+ }
+ return 0;
+
+ case WM_CHAR:
+ { USHORT fsflags;
+ window = __glutGetWindow(hwnd);
+ if (!window) {
+ break;
+ }
+ fsflags = SHORT1FROMMP(mp1);
+/* ?? */
+ if((fsflags & KC_KEYUP) ) /* ¨£­®p¨p㥬 ®â¦ â¨¥ ª­®¯ª¨, p¥ £¨p㥬 ⮫쪮 ­  ­ ¦ â¨¥ */
+ break;
+///////////////////////////////////////////////////
+ if(!(fsflags & KC_CHAR) )
+ {
+ if (!(fsflags & KC_VIRTUALKEY))
+ break;
+ key = 0;
+ /* Get the virtual key from mp2. */
+ switch (SHORT2FROMMP(mp2))
+ {
+/* directional keys */
+ case VK_LEFT: key = GLUT_KEY_LEFT; break;
+ case VK_UP: key = GLUT_KEY_UP; break;
+ case VK_RIGHT: key = GLUT_KEY_RIGHT; break;
+ case VK_DOWN: key = GLUT_KEY_DOWN; break;
+
+ case VK_PAGEUP: key = GLUT_KEY_PAGE_UP; break;
+ case VK_PAGEDOWN:key = GLUT_KEY_PAGE_DOWN; break;
+ case VK_HOME: key = GLUT_KEY_HOME;break;
+ case VK_END: key = GLUT_KEY_END; break;
+ case VK_INSERT: key = GLUT_KEY_INSERT; break;
+
+/* function keys */
+ case VK_F1 : key = GLUT_KEY_F1; break;
+ case VK_F2 : key = GLUT_KEY_F2; break;
+ case VK_F3 : key = GLUT_KEY_F3; break;
+ case VK_F4 : key = GLUT_KEY_F4; break;
+ case VK_F5 : key = GLUT_KEY_F5; break;
+ case VK_F6 : key = GLUT_KEY_F6; break;
+ case VK_F7 : key = GLUT_KEY_F7; break;
+ case VK_F8 : key = GLUT_KEY_F8; break;
+ case VK_F9 : key = GLUT_KEY_F9; break;
+ case VK_F10: key = GLUT_KEY_F10;break;
+ case VK_F11: key = GLUT_KEY_F11; break;
+ case VK_F12: key = GLUT_KEY_F12; break;
+ case VK_ESC: key = -1; break; /* Character codes */
+ case VK_SPACE: key = -1; break;
+ case VK_TAB: key = -1; break;
+ }
+ if(!key)
+ { break; /* Key Not implemented */
+ }
+ if(key > 0)
+ { if (!window->special) /* ­¥ ãáâ ­®¢«¥­® ®¡à ¡®â稪  */
+ break;
+
+ WinQueryPointerPos(HWND_DESKTOP,&point);
+ ScreenToClient(window->win, &point);
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if(WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if(WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
+ __glutModifierMask |= ControlMask;
+ if(WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
+ __glutModifierMask |= Mod1Mask;
+ window->special(key, point.x, point.y);
+ __glutModifierMask = (unsigned int) ~0;
+ return 0;
+ }
+
+ }
+/////////////////////////////////////////////////////
+ /* If we are ignoring auto repeated key strokes for the window, bail. */
+ if (window->ignoreKeyRepeat && (CHAR3FROMMP(mp1)) )
+ break;
+ if(!((unsigned char)SHORT1FROMMP(mp2)) ) /* ¨£­®p¨p㥬 ­¥á¨¬¢®«ì­ë¥ ª®¤ë */
+ break;
+ if (window->keyboard) {
+ WinQueryPointerPos(HWND_DESKTOP,&point);
+
+ ScreenToClient(window->win, &point);
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if(WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if(WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
+ __glutModifierMask |= ControlMask;
+ if(WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
+ __glutModifierMask |= Mod1Mask;
+ window->keyboard((unsigned char)SHORT1FROMMP(mp2), point.x, point.y);
+ __glutModifierMask = (unsigned int) ~0;
+ }
+ return 0;
+ } /* endof case WM_CHAR: */
+////////////////////////////////////////////////
+ case WM_BUTTON1DOWN:
+ button = GLUT_LEFT_BUTTON;
+ case WM_BUTTON3DOWN:
+ if (button < 0)
+ button = GLUT_MIDDLE_BUTTON;
+ case WM_BUTTON2DOWN:
+ if (button < 0)
+ button = GLUT_RIGHT_BUTTON;
+ { POINTS psh;
+ psh = *((POINTS *)&mp1);
+ point.x = psh.x;
+ point.y = psh.y;
+ }
+ /* finish the menu if we get a button down message (user must have
+ cancelled the menu). */
+ if (__glutMappedMenu) {
+ /* TODO: take this out once the menu on middle mouse stuff works
+ properly. */
+ if (button == GLUT_MIDDLE_BUTTON)
+ return 0;
+ /* get current mouse pointer position */
+// WinQueryPointerPos(HWND_DESKTOP,&point);
+ /* map from desktop to client window */
+// WinMapWindowPoints(HWND_DESKTOP, hwnd, &point, 1);
+ __glutItemSelected = NULL;
+ __glutFinishMenu(hwnd, point.x, point.y);
+ return 0;
+ }
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ window->buttonDownState = button+1;
+ menu = __glutGetMenuByNum(window->menu[button]);
+ if (menu) {
+//todo
+// __glutMenuButton = button == GLUT_RIGHT_BUTTON ? TPM_RIGHTBUTTON :
+// button == GLUT_LEFT_BUTTON ? TPM_LEFTBUTTON :
+// 0x0001;
+// __glutStartMenu(menu, window, point.x, point.y, x, y);
+ } else if (window->mouse) {
+
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* < 0 = high order bit is on. */
+ __glutModifierMask |= ShiftMask;
+ if (WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
+ __glutModifierMask |= ControlMask;
+ if (WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
+ __glutModifierMask |= Mod1Mask;
+ window->mouse(button, GLUT_DOWN, point.x, point.y);
+ __glutModifierMask = (unsigned int)~0;
+ } else {
+ /* Stray mouse events. Ignore. */
+ }
+ }
+ return 0;
+
+ break;
+/********************************************/
+ case WM_BUTTON1UP:
+ button = GLUT_LEFT_BUTTON;
+ case WM_BUTTON3UP:
+ if (button < 0)
+ button = GLUT_MIDDLE_BUTTON;
+ case WM_BUTTON2UP:
+ if (button < 0)
+ button = GLUT_RIGHT_BUTTON;
+ { POINTS psh;
+ psh = *((POINTS *)&mp1);
+ point.x = psh.x;
+ point.y = psh.y;
+ }
+ /* Bail out if we're processing a menu. */
+ /* Bail out = ¢ë¡à®á¨âìáï á ¯ à èã⮬ */
+ if (__glutMappedMenu) {
+ WinQueryPointerPos(HWND_DESKTOP,&point);
+ WinMapWindowPoints(HWND_DESKTOP, hwnd, &point, 1);
+ /* if we're getting the middle button up signal, then something
+ on the menu was selected. */
+ if (button == GLUT_MIDDLE_BUTTON) {
+ return 0;
+ /* For some reason, the code below always returns -1 even
+ though the point IS IN THE ITEM! Therefore, just bail out if
+ we get a middle mouse up. The user must select using the
+ left mouse button. Stupid Win32. */
+#if 0
+ int item = MenuItemFromPoint(hwnd, __glutHMenu, point);
+ if (item != -1)
+ __glutItemSelected = (GLUTmenuItem*)GetMenuItemID(__glutHMenu, item);
+ else
+ __glutItemSelected = NULL;
+ __glutFinishMenu(hwnd, point.x, point.y);
+#endif
+ } else {
+ __glutItemSelected = NULL;
+ __glutFinishMenu(hwnd, point.x, point.y);
+ }
+ return 0;
+ }
+
+ window = __glutGetWindow(hwnd);
+ if(window)
+ window->buttonDownState = 0;
+
+ if (window && window->mouse) {
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) /* < 0 = high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if (WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000)
+ __glutModifierMask |= ControlMask;
+ if (WinGetKeyState(HWND_DESKTOP,VK_MENU) & 0x8000)
+ __glutModifierMask |= Mod1Mask;
+ window->mouse(button, GLUT_UP, point.x, point.y);
+
+ __glutModifierMask = (unsigned int)~0;
+ } else {
+ /* Window might have been destroyed and all the
+ events for the window may not yet be received. */
+ }
+ return 0;
+
+
+ break;
+//////////////////////////////////////////////////
+ case WM_COMMAND:
+ window = __glutGetWindow(hwnd);
+ if (window)
+ { if (window->wm_command)
+ window->wm_command(hwnd,mp1,mp2);
+ }
+ break;
+
+ case WM_MOUSEMOVE:
+ if (!__glutMappedMenu) {
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ /* If motion function registered _and_ buttons held *
+ down, call motion function... */
+ { POINTS psh;
+ psh = *((POINTS *)&mp1);
+ point.x = psh.x;
+ point.y = psh.y;
+ }
+
+ if (window->motion && window->buttonDownState) {
+ __glutSetWindow(window);
+ window->motion(point.x, point.y);
+ }
+ /* If passive motion function registered _and_
+ buttons not held down, call passive motion
+ function... */
+ else if (window->passive && !window->buttonDownState) {
+ __glutSetWindow(window);
+ window->passive(point.x, point.y);
+ }
+ }
+ } else {
+ /* Motion events are thrown away when a pop up menu is
+ active. */
+ }
+ return 0;
+
+
+ default:
+ /* For all other messages, let the default window procedure process them. */
+ return ( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
+
+ } //endof switch( msg )
+ return ( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
+// return NULL;
+}
+
+void APIENTRY glutCommandFunc(GLUTcommandCB Func)
+{
+extern GLUTwindow *__glutCurrentWindow;
+ __glutCurrentWindow->wm_command = Func;
+}
+
+
+
+
+void
+updateWindowState(GLUTwindow *window, int visState)
+{
+ GLUTwindow* child;
+
+ /* XXX shownState and visState are the same in Win32. */
+ window->shownState = visState;
+ if (visState != window->visState) {
+ if (window->windowStatus) {
+ window->visState = visState;
+ __glutSetWindow(window);
+ window->windowStatus(visState);
+ }
+ }
+ /* Since Win32 only sends an activate for the toplevel window,
+ update the visibility for all the child windows. */
+ child = window->children;
+ while (child) {
+ updateWindowState(child, visState);
+ child = child->siblings;
+ }
+}
+
+#if POKA
+
+LONG WINAPI
+__glutWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ POINT point; /* Point structure. */
+ PAINTSTRUCT ps; /* Paint structure. */
+ LPMINMAXINFO minmax; /* Minimum/maximum info structure. */
+ GLUTwindow* window; /* GLUT window associated with message. */
+ GLUTmenu* menu; /* GLUT menu associated with message. */
+ int x, y, width, height, key;
+ int button = -1;
+
+ switch(msg) {
+ case WM_CREATE:
+ return 0;
+ case WM_CLOSE:
+ PostQuitMessage(0);
+ return 0;
+#if 0
+ case WM_DESTROY:
+ /* XXX NVidia's NT OpenGL can have problems closing down
+ its OpenGL internal data structures if we just allow
+ the process to terminate without unbinding and deleting
+ the windows context. Apparently, DirectDraw unloads
+ before OPENGL32.DLL in the close down sequence, but
+ NVidia's NT OpenGL needs DirectDraw to close down its
+ data structures. */
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ if (window->ctx) {
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(window->ctx);
+ }
+ }
+ return 0;
+#endif
+
+ case WM_SYSKEYUP:
+ case WM_KEYUP:
+ window = __glutGetWindow(hwnd);
+ if (!window) {
+ break;
+ }
+ /* Win32 is dumb and sends these messages only to the parent
+ window. Therefore, find out if we're in a child window and
+ call the child windows keyboard callback if we are. */
+ if (window->parent) {
+ GetCursorPos(&point);
+ ScreenToClient(hwnd, &point);
+ hwnd = ChildWindowFromPoint(hwnd, point);
+ window = __glutGetWindow(hwnd);
+ }
+ if (window->specialUp || window->keyboardUp) {
+ GetCursorPos(&point);
+ ScreenToClient(window->win, &point);
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
+ __glutModifierMask |= ControlMask;
+ if (GetKeyState(VK_MENU) < 0)
+ __glutModifierMask |= Mod1Mask;
+ switch (wParam) {
+ /* *INDENT-OFF* */
+ case VK_F1: key = GLUT_KEY_F1; break;
+ case VK_F2: key = GLUT_KEY_F2; break;
+ case VK_F3: key = GLUT_KEY_F3; break;
+ case VK_F4: key = GLUT_KEY_F4; break;
+ case VK_F5: key = GLUT_KEY_F5; break;
+ case VK_F6: key = GLUT_KEY_F6; break;
+ case VK_F7: key = GLUT_KEY_F7; break;
+ case VK_F8: key = GLUT_KEY_F8; break;
+ case VK_F9: key = GLUT_KEY_F9; break;
+ case VK_F10: key = GLUT_KEY_F10; break;
+ case VK_F11: key = GLUT_KEY_F11; break;
+ case VK_F12: key = GLUT_KEY_F12; break;
+ case VK_LEFT: key = GLUT_KEY_LEFT; break;
+ case VK_UP: key = GLUT_KEY_UP; break;
+ case VK_RIGHT: key = GLUT_KEY_RIGHT; break;
+ case VK_DOWN: key = GLUT_KEY_DOWN; break;
+ case VK_PRIOR: key = GLUT_KEY_PAGE_UP; break;
+ case VK_NEXT: key = GLUT_KEY_PAGE_DOWN; break;
+ case VK_HOME: key = GLUT_KEY_HOME; break;
+ case VK_END: key = GLUT_KEY_END; break;
+ case VK_INSERT: key = GLUT_KEY_INSERT; break;
+ case VK_DELETE:
+ /* Delete is an ASCII character. */
+ if (window->keyboardUp) {
+ window->keyboardUp((unsigned char) 127, point.x, point.y);
+ }
+ return 0;
+ /* *INDENT-ON* */
+ default:
+ if (window->keyboardUp) {
+ key = MapVirtualKey(wParam, 2); /* Map to ASCII. */
+ if (isascii(key) && (key != 0)) {
+
+ /* XXX Attempt to determine modified ASCII character
+ is quite incomplete. Digits, symbols, CapsLock,
+ Ctrl, and numeric keypad are all ignored. Fix this. */
+
+ if (!(__glutModifierMask & ShiftMask))
+ key = tolower(key);
+ window->keyboardUp((unsigned char) key, point.x, point.y);
+ }
+ }
+ __glutModifierMask = (unsigned int) ~0;
+ return 0;
+ }
+ if (window->specialUp) {
+ window->specialUp(key, point.x, point.y);
+ }
+ __glutModifierMask = (unsigned int) ~0;
+ }
+ return 0;
+
+ case WM_SYSCHAR:
+ case WM_CHAR:
+ window = __glutGetWindow(hwnd);
+ if (!window) {
+ break;
+ }
+
+ /* Bit 30 of lParam is set if key already held down. If
+ we are ignoring auto repeated key strokes for the window, bail. */
+ if (window->ignoreKeyRepeat && (lParam & (1 << 30)) ) {
+ break;
+ }
+
+ /* Win32 is dumb and sends these messages only to the parent
+ window. Therefore, find out if we're in a child window and
+ call the child windows keyboard callback if we are. */
+ if (window->parent) {
+ GetCursorPos(&point);
+ ScreenToClient(hwnd, &point);
+ hwnd = ChildWindowFromPoint(hwnd, point);
+ window = __glutGetWindow(hwnd);
+ }
+ if (window->keyboard) {
+ GetCursorPos(&point);
+ ScreenToClient(window->win, &point);
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if (GetKeyState(VK_CONTROL) < 0)
+ __glutModifierMask |= ControlMask;
+ if (GetKeyState(VK_MENU) < 0)
+ __glutModifierMask |= Mod1Mask;
+ window->keyboard((unsigned char)wParam, point.x, point.y);
+ __glutModifierMask = (unsigned int) ~0;
+ }
+ return 0;
+
+ case WM_SYSKEYDOWN:
+ case WM_KEYDOWN:
+ window = __glutGetWindow(hwnd);
+ if (!window) {
+ break;
+ }
+
+ /* Bit 30 of lParam is set if key already held down. If
+ we are ignoring auto repeated key strokes for the window, bail. */
+ if (window->ignoreKeyRepeat && (lParam & (1 << 30)) ) {
+ break;
+ }
+
+ /* Win32 is dumb and sends these messages only to the parent
+ window. Therefore, find out if we're in a child window and
+ call the child windows keyboard callback if we are. */
+ if (window->parent) {
+ GetCursorPos(&point);
+ ScreenToClient(hwnd, &point);
+ hwnd = ChildWindowFromPoint(hwnd, point);
+ window = __glutGetWindow(hwnd);
+ }
+ if (window->special) {
+ switch (wParam) {
+ /* *INDENT-OFF* */
+ /* function keys */
+ case VK_F1: key = GLUT_KEY_F1; break;
+ case VK_F2: key = GLUT_KEY_F2; break;
+ case VK_F3: key = GLUT_KEY_F3; break;
+ case VK_F4: key = GLUT_KEY_F4; break;
+ case VK_F5: key = GLUT_KEY_F5; break;
+ case VK_F6: key = GLUT_KEY_F6; break;
+ case VK_F7: key = GLUT_KEY_F7; break;
+ case VK_F8: key = GLUT_KEY_F8; break;
+ case VK_F9: key = GLUT_KEY_F9; break;
+ case VK_F10: key = GLUT_KEY_F10; break;
+ case VK_F11: key = GLUT_KEY_F11; break;
+ case VK_F12: key = GLUT_KEY_F12; break;
+ /* directional keys */
+ case VK_LEFT: key = GLUT_KEY_LEFT; break;
+ case VK_UP: key = GLUT_KEY_UP; break;
+ case VK_RIGHT: key = GLUT_KEY_RIGHT; break;
+ case VK_DOWN: key = GLUT_KEY_DOWN; break;
+ /* *INDENT-ON* */
+
+ case VK_PRIOR:
+ /* VK_PRIOR is Win32's Page Up */
+ key = GLUT_KEY_PAGE_UP;
+ break;
+ case VK_NEXT:
+ /* VK_NEXT is Win32's Page Down */
+ key = GLUT_KEY_PAGE_DOWN;
+ break;
+ case VK_HOME:
+ key = GLUT_KEY_HOME;
+ break;
+ case VK_END:
+ key = GLUT_KEY_END;
+ break;
+ case VK_INSERT:
+ key = GLUT_KEY_INSERT;
+ break;
+ case VK_DELETE:
+ goto handleDelete;
+ default:
+ goto defproc;
+ }
+ GetCursorPos(&point);
+ ScreenToClient(window->win, &point);
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if (GetKeyState(VK_CONTROL) < 0)
+ __glutModifierMask |= ControlMask;
+ if (GetKeyState(VK_MENU) < 0)
+ __glutModifierMask |= Mod1Mask;
+ window->special(key, point.x, point.y);
+ __glutModifierMask = (unsigned int) ~0;
+ } else if (window->keyboard) {
+ /* Specially handle any keys that match ASCII values but
+ do not generate Windows WM_SYSCHAR or WM_CHAR messages. */
+ switch (wParam) {
+ case VK_DELETE:
+ handleDelete:
+ /* Delete is an ASCII character. */
+ GetCursorPos(&point);
+ ScreenToClient(window->win, &point);
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if (GetKeyState(VK_CONTROL) < 0)
+ __glutModifierMask |= ControlMask;
+ if (GetKeyState(VK_MENU) < 0)
+ __glutModifierMask |= Mod1Mask;
+ window->keyboard((unsigned char) 127, point.x, point.y);
+ __glutModifierMask = (unsigned int) ~0;
+ return 0;
+ default:
+ /* Let the following WM_SYSCHAR or WM_CHAR message generate
+ the keyboard callback. */
+ break;
+ }
+ }
+ return 0;
+
+ case WM_LBUTTONDOWN:
+ button = GLUT_LEFT_BUTTON;
+ case WM_MBUTTONDOWN:
+ if (button < 0)
+ button = GLUT_MIDDLE_BUTTON;
+ case WM_RBUTTONDOWN:
+ if (button < 0)
+ button = GLUT_RIGHT_BUTTON;
+
+ /* finish the menu if we get a button down message (user must have
+ cancelled the menu). */
+ if (__glutMappedMenu) {
+ /* TODO: take this out once the menu on middle mouse stuff works
+ properly. */
+ if (button == GLUT_MIDDLE_BUTTON)
+ return 0;
+ GetCursorPos(&point);
+ ScreenToClient(hwnd, &point);
+ __glutItemSelected = NULL;
+ __glutFinishMenu(hwnd, point.x, point.y);
+ return 0;
+ }
+
+ /* set the capture so we can get mouse events outside the window */
+ SetCapture(hwnd);
+
+ /* Win32 doesn't return the same numbers as X does when the mouse
+ goes beyond the upper or left side of the window. roll the
+ Win32's 0..2^16 pointer co-ord range to 0 +/- 2^15. */
+ x = LOWORD(lParam);
+ y = HIWORD(lParam);
+ if(x & 1 << 15) x -= (1 << 16);
+ if(y & 1 << 15) y -= (1 << 16);
+
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ menu = __glutGetMenuByNum(window->menu[button]);
+ if (menu) {
+ point.x = LOWORD(lParam); point.y = HIWORD(lParam);
+ ClientToScreen(window->win, &point);
+ __glutMenuButton = button == GLUT_RIGHT_BUTTON ? TPM_RIGHTBUTTON :
+ button == GLUT_LEFT_BUTTON ? TPM_LEFTBUTTON :
+ 0x0001;
+ __glutStartMenu(menu, window, point.x, point.y, x, y);
+ } else if (window->mouse) {
+
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on. */
+ __glutModifierMask |= ShiftMask;
+ if (GetKeyState(VK_CONTROL) < 0)
+ __glutModifierMask |= ControlMask;
+ if (GetKeyState(VK_MENU) < 0)
+ __glutModifierMask |= Mod1Mask;
+ window->mouse(button, GLUT_DOWN, x, y);
+ __glutModifierMask = (unsigned int)~0;
+ } else {
+ /* Stray mouse events. Ignore. */
+ }
+ }
+ return 0;
+
+ case WM_LBUTTONUP:
+ button = GLUT_LEFT_BUTTON;
+ case WM_MBUTTONUP:
+ if (button < 0)
+ button = GLUT_MIDDLE_BUTTON;
+ case WM_RBUTTONUP:
+ if (button < 0)
+ button = GLUT_RIGHT_BUTTON;
+
+ /* Bail out if we're processing a menu. */
+ if (__glutMappedMenu) {
+ GetCursorPos(&point);
+ ScreenToClient(hwnd, &point);
+ /* if we're getting the middle button up signal, then something
+ on the menu was selected. */
+ if (button == GLUT_MIDDLE_BUTTON) {
+ return 0;
+ /* For some reason, the code below always returns -1 even
+ though the point IS IN THE ITEM! Therefore, just bail out if
+ we get a middle mouse up. The user must select using the
+ left mouse button. Stupid Win32. */
+#if 0
+ int item = MenuItemFromPoint(hwnd, __glutHMenu, point);
+ if (item != -1)
+ __glutItemSelected = (GLUTmenuItem*)GetMenuItemID(__glutHMenu, item);
+ else
+ __glutItemSelected = NULL;
+ __glutFinishMenu(hwnd, point.x, point.y);
+#endif
+ } else {
+ __glutItemSelected = NULL;
+ __glutFinishMenu(hwnd, point.x, point.y);
+ }
+ return 0;
+ }
+
+ /* Release the mouse capture. */
+ ReleaseCapture();
+
+ window = __glutGetWindow(hwnd);
+ if (window && window->mouse) {
+ /* Win32 doesn't return the same numbers as X does when the
+ mouse goes beyond the upper or left side of the window. roll
+ the Win32's 0..2^16 pointer co-ord range to 0 +/- 2^15. */
+ x = LOWORD(lParam);
+ y = HIWORD(lParam);
+ if(x & 1 << 15) x -= (1 << 16);
+ if(y & 1 << 15) y -= (1 << 16);
+
+ __glutSetWindow(window);
+ __glutModifierMask = 0;
+ if (GetKeyState(VK_SHIFT) < 0) /* < 0 = high order bit is on */
+ __glutModifierMask |= ShiftMask;
+ if (GetKeyState(VK_CONTROL) < 0)
+ __glutModifierMask |= ControlMask;
+ if (GetKeyState(VK_MENU) < 0)
+ __glutModifierMask |= Mod1Mask;
+ window->mouse(button, GLUT_UP, x, y);
+ __glutModifierMask = (unsigned int)~0;
+ } else {
+ /* Window might have been destroyed and all the
+ events for the window may not yet be received. */
+ }
+ return 0;
+
+ case WM_ENTERMENULOOP:
+ /* KLUDGE: create a timer that fires every 100 ms when we start a
+ menu so that we can still process the idle & timer events (that
+ way, the timers will fire during a menu pick and so will the
+ idle func. */
+ SetTimer(hwnd, 1, 1, NULL);
+ return 0;
+
+ case WM_TIMER:
+#if 0
+ /* If the timer id is 2, then this is the timer that is set up in
+ the main glut message processing loop, and we don't want to do
+ anything but acknowledge that we got it. It is used to prevent
+ CPU spiking when an idle function is installed. */
+ if (wParam == 2)
+ return 0;
+#endif
+
+ /* only worry about the idle function and the timeouts, since
+ these are the only events we expect to process during
+ processing of a menu. */
+ /* we no longer process the idle functions (as outlined in the
+ README), since drawing can't be done until the menu has
+ finished...it's pretty lame when the animation goes on, but
+ doesn't update, so you get this weird jerkiness. */
+#if 0
+ if (__glutIdleFunc)
+ __glutIdleFunc();
+#endif
+ if (__glutTimerList)
+ handleTimeouts();
+ return 0;
+
+ case WM_EXITMENULOOP:
+ /* nuke the above created timer...we don't need it anymore, since
+ the menu is gone now. */
+ KillTimer(hwnd, 1);
+ return 0;
+
+ case WM_MENUSELECT:
+ if (lParam != 0)
+ __glutHMenu = (HMENU)lParam;
+ return 0;
+
+ case WM_COMMAND:
+ if (__glutMappedMenu) {
+ if (GetSubMenu(__glutHMenu, LOWORD(wParam)))
+ __glutItemSelected = NULL;
+ else
+ __glutItemSelected =
+ __glutGetUniqueMenuItem(__glutMappedMenu, LOWORD(wParam));
+ GetCursorPos(&point);
+ ScreenToClient(hwnd, &point);
+ __glutFinishMenu(hwnd, point.x, point.y);
+ }
+ return 0;
+
+ case WM_MOUSEMOVE:
+ if (!__glutMappedMenu) {
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ /* If motion function registered _and_ buttons held *
+ down, call motion function... */
+ x = LOWORD(lParam);
+ y = HIWORD(lParam);
+
+ /* Win32 doesn't return the same numbers as X does when the
+ mouse goes beyond the upper or left side of the window.
+ roll the Win32's 0..2^16 pointer co-ord range to 0..+/-2^15. */
+ if(x & 1 << 15) x -= (1 << 16);
+ if(y & 1 << 15) y -= (1 << 16);
+
+ if (window->motion && wParam &
+ (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) {
+ __glutSetWindow(window);
+ window->motion(x, y);
+ }
+ /* If passive motion function registered _and_
+ buttons not held down, call passive motion
+ function... */
+ else if (window->passive &&
+ ((wParam &
+ (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) ==
+ 0)) {
+ __glutSetWindow(window);
+ window->passive(x, y);
+ }
+ }
+ } else {
+ /* Motion events are thrown away when a pop up menu is
+ active. */
+ }
+ return 0;
+
+ case WM_GETMINMAXINFO:
+ /* this voodoo is brought to you by Win32 (again). It allows the
+ window to be bigger than the screen, and smaller than 100x100
+ (although it doesn't seem to help the y minimum). */
+ minmax = (LPMINMAXINFO)lParam;
+ minmax->ptMaxSize.x = __glutScreenWidth;
+ minmax->ptMaxSize.y = __glutScreenHeight;
+ minmax->ptMinTrackSize.x = 0;
+ minmax->ptMinTrackSize.y = 0;
+ minmax->ptMaxTrackSize.x = __glutScreenWidth +
+ GetSystemMetrics(SM_CXSIZE) * 2;
+ minmax->ptMaxTrackSize.y = __glutScreenHeight +
+ GetSystemMetrics(SM_CXSIZE) * 2 + GetSystemMetrics(SM_CYCAPTION);
+ return 0;
+
+ case WM_SIZE:
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ width = LOWORD(lParam);
+ height = HIWORD(lParam);
+ if (width != window->width || height != window->height) {
+#if 0 /* Win32 GLUT does not support overlays for now. */
+ if (window->overlay) {
+ XResizeWindow(__glutDisplay, window->overlay->win, width, height);
+ }
+#endif
+ window->width = width;
+ window->height = height;
+ __glutSetWindow(window);
+ /* Do not execute OpenGL out of sequence with respect
+ to the SetWindowPos request! */
+ GdiFlush();
+ window->reshape(width, height);
+ window->forceReshape = FALSE;
+ /* A reshape should be considered like posting a
+ repair request. */
+ __glutPostRedisplay(window, GLUT_REPAIR_WORK);
+ }
+ }
+ return 0;
+
+ case WM_SETCURSOR:
+ /* If the cursor is not in the client area, then we want to send
+ this message to the default window procedure ('cause its
+ probably in the border or title, and we don't handle that
+ cursor. otherwise, set our cursor. Win32 makes us set the
+ cursor every time the mouse moves (DUMB!). */
+ if(LOWORD(lParam) != HTCLIENT) {
+ goto defproc;
+ }
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ __glutSetCursor(window);
+ }
+ /* TODO: check out the info in DevStudio on WM_SETCURSOR in the
+ DefaultAction section. */
+ return 1;
+
+ case WM_SETFOCUS:
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ window->entryState = WM_SETFOCUS;
+ if (window->entry) {
+ __glutSetWindow(window);
+ window->entry(GLUT_ENTERED);
+ /* XXX Generation of fake passive notify? See how much
+ work the X11 code does to support fake passive notify
+ callbacks. */
+ }
+ if (window->joystick && __glutCurrentWindow) {
+ if (__glutCurrentWindow->joyPollInterval > 0) {
+ MMRESULT result;
+
+ /* Because Win32 will only let one window capture the
+ joystick at a time, we must capture it when we get the
+ focus and release it when we lose the focus. */
+ result = joySetCapture(__glutCurrentWindow->win,
+ JOYSTICKID1, 0, TRUE);
+ if (result != JOYERR_NOERROR) {
+ return 0;
+ }
+ (void) joySetThreshold(JOYSTICKID1,
+ __glutCurrentWindow->joyPollInterval);
+ }
+ }
+ }
+ return 0;
+
+ case WM_KILLFOCUS:
+ window = __glutGetWindow(hwnd);
+ if (window) {
+ window->entryState = WM_KILLFOCUS;
+ if (window->entry) {
+ __glutSetWindow(window);
+ window->entry(GLUT_LEFT);
+ }
+ if (window->joystick && __glutCurrentWindow) {
+ if (__glutCurrentWindow->joyPollInterval > 0) {
+ /* Because Win32 will only let one window capture the
+ joystick at a time, we must capture it when we get the
+ focus and release it when we lose the focus. */
+ (void) joyReleaseCapture(JOYSTICKID1);
+ }
+ }
+ }
+ return 0;
+ case WM_ACTIVATE:
+ window = __glutGetWindow(hwnd);
+ /* Make sure we re-select the correct palette if needed. */
+ if (LOWORD(wParam)) {
+ PostMessage(hwnd, WM_PALETTECHANGED, 0, 0);
+ }
+ if (window) {
+ int visState;
+
+ /* HIWORD(wParam) is the minimized flag. */
+ visState = !HIWORD(wParam);
+ updateWindowState(window, visState);
+ }
+ return 0;
+
+ /* Colour Palette Management */
+ case WM_PALETTECHANGED:
+ if (hwnd == (HWND)wParam) {
+ /* Don't respond to the message that we sent! */
+ break;
+ }
+ /* fall through to WM_QUERYNEWPALETTE */
+
+ case WM_QUERYNEWPALETTE:
+ window = __glutGetWindow(hwnd);
+ if (window && window->colormap) {
+ UnrealizeObject(window->colormap->cmap);
+ SelectPalette(window->hdc, window->colormap->cmap, FALSE);
+ RealizePalette(window->hdc);
+ return TRUE;
+ }
+ return FALSE;
+
+ case MM_JOY1MOVE:
+ case MM_JOY1ZMOVE:
+ window = __glutGetWindow(hwnd);
+ if (window->joystick) {
+ JOYINFOEX jix;
+ int x, y, z;
+
+ /* Because WIN32 only supports messages for X, Y, and Z
+ translations, we must poll for the rest */
+ jix.dwSize = sizeof(jix);
+ jix.dwFlags = JOY_RETURNALL;
+ joyGetPosEx(JOYSTICKID1,&jix);
+
+#define SCALE(v) ((int) ((v - 32767)/32.768))
+
+ /* Convert to integer for scaling. */
+ x = jix.dwXpos;
+ y = jix.dwYpos;
+ z = jix.dwZpos;
+ window->joystick(jix.dwButtons, SCALE(x), SCALE(y), SCALE(z));
+
+ return TRUE;
+ }
+ return FALSE;
+ case MM_JOY1BUTTONDOWN:
+ case MM_JOY1BUTTONUP:
+ window = __glutGetWindow(hwnd);
+ if (window->joystick) {
+ JOYINFOEX jix;
+
+ /* Because WIN32 only supports messages for X, Y, and Z
+ translations, we must poll for the rest */
+ jix.dwSize = sizeof(jix);
+ jix.dwFlags = JOY_RETURNALL;
+ joyGetPosEx(JOYSTICKID1,&jix);
+
+ return TRUE;
+ }
+ return FALSE;
+
+#if 0
+ /* Miscellaneous messages (don't really need to enumerate them,
+ but it's good to know what you're not getting sometimes). */
+ case WM_DISPLAYCHANGE:
+ break;
+ case WM_NCHITTEST:
+ /* This event is generated by every mouse move event. */
+ goto defproc;
+ case WM_NCMOUSEMOVE:
+ goto defproc;
+ case WM_NCACTIVATE:
+ goto defproc;
+ case WM_NCPAINT:
+ goto defproc;
+ case WM_NCCALCSIZE:
+ goto defproc;
+ case WM_NCCREATE:
+ goto defproc;
+ case WM_NCDESTROY:
+ goto defproc;
+ case WM_NCLBUTTONDOWN:
+ goto defproc;
+ case WM_SETTEXT:
+ goto defproc;
+ case WM_GETTEXT:
+ goto defproc;
+ case WM_ACTIVATEAPP:
+ goto defproc;
+ case WM_GETICON:
+ goto defproc;
+ case WM_ERASEBKGND:
+ goto defproc;
+ case WM_WINDOWPOSCHANGING:
+ goto defproc;
+ case WM_WINDOWPOSCHANGED:
+ goto defproc;
+ case WM_MOUSEACTIVATE:
+ goto defproc;
+ case WM_SHOWWINDOW:
+ goto defproc;
+ case WM_MOVING:
+ goto defproc;
+ case WM_MOVE:
+ goto defproc;
+ case WM_KEYUP:
+ goto defproc;
+ case WM_CAPTURECHANGED:
+ goto defproc;
+ case WM_SYSCOMMAND:
+ goto defproc;
+ case WM_ENTERSIZEMOVE:
+ goto defproc;
+ case WM_ENTERIDLE:
+ goto defproc;
+#endif
+
+ default:
+ goto defproc;
+ }
+
+defproc:
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+}
+
+#endif
+
+#if defined(__OS2PM__)
+Bool __glutSetWindowText(Window window, char *text)
+{
+ return WinSetWindowText(window, (PCSZ)text);
+
+}
+
+#endif
 \ No newline at end of file
diff --git a/src/glx/x11/Makefile b/src/glx/x11/Makefile
index 894c3cf159..c45c7de6d6 100644
--- a/src/glx/x11/Makefile
+++ b/src/glx/x11/Makefile
@@ -31,6 +31,8 @@ SOURCES = \
xfont.c \
glx_pbuffer.c \
glx_query.c \
+ drisw_glx.c \
+ dri_common.c \
dri_glx.c \
XF86dri.c \
glxhash.c \
diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c
index f24492672b..b679c72c10 100644
--- a/src/glx/x11/dri2_glx.c
+++ b/src/glx/x11/dri2_glx.c
@@ -32,7 +32,6 @@
#ifdef GLX_DIRECT_RENDERING
-#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xdamage.h>
@@ -46,18 +45,10 @@
#include <sys/mman.h>
#include "xf86drm.h"
#include "dri2.h"
-
-
-#ifndef RTLD_NOW
-#define RTLD_NOW 0
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
+#include "dri_common.h"
typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;
typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;
-typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate;
struct __GLXDRIdisplayPrivateRec {
__GLXDRIdisplay base;
@@ -76,11 +67,6 @@ struct __GLXDRIcontextPrivateRec {
__GLXscreenConfigs *psc;
};
-struct __GLXDRIconfigPrivateRec {
- __GLcontextModes modes;
- const __DRIconfig *driConfig;
-};
-
static void dri2DestroyContext(__GLXDRIcontext *context,
__GLXscreenConfigs *psc, Display *dpy)
{
@@ -253,94 +239,12 @@ static const __DRIloaderExtension dri2LoaderExtension = {
dri2PostDamage
};
-_X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension;
-
static const __DRIextension *loader_extensions[] = {
&dri2LoaderExtension.base,
&systemTimeExtension.base,
NULL
};
-/* We need a dri_common.h type-of-thing. */
-
-extern void ErrorMessageF(const char *f, ...);
-
-extern void *driOpenDriver(const char *driverName);
-
-extern __GLcontextModes *
-driConvertConfigs(const __DRIcoreExtension *core,
- __GLcontextModes *modes, const __DRIconfig **configs);
-
-extern void driBindExtensions(__GLXscreenConfigs *psc);
-
-void
-driBindExtensions(__GLXscreenConfigs *psc)
-{
- const __DRIextension **extensions;
- int i;
-
- extensions = psc->core->getExtensions(psc->__driScreen);
-
- for (i = 0; extensions[i]; i++) {
-#ifdef __DRI_COPY_SUB_BUFFER
- if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
- psc->copySubBuffer = (__DRIcopySubBufferExtension *) extensions[i];
- __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer_bit");
- }
-#endif
-
-#ifdef __DRI_SWAP_CONTROL
- if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) {
- psc->swapControl = (__DRIswapControlExtension *) extensions[i];
- __glXEnableDirectExtension(psc, "GLX_SGI_swap_control");
- __glXEnableDirectExtension(psc, "GLX_MESA_swap_control");
- }
-#endif
-
-#ifdef __DRI_ALLOCATE
- if (strcmp(extensions[i]->name, __DRI_ALLOCATE) == 0) {
- psc->allocate = (__DRIallocateExtension *) extensions[i];
- __glXEnableDirectExtension(psc, "GLX_MESA_allocate_memory");
- }
-#endif
-
-#ifdef __DRI_FRAME_TRACKING
- if (strcmp(extensions[i]->name, __DRI_FRAME_TRACKING) == 0) {
- psc->frameTracking = (__DRIframeTrackingExtension *) extensions[i];
- __glXEnableDirectExtension(psc, "GLX_MESA_swap_frame_usage");
- }
-#endif
-
-#ifdef __DRI_MEDIA_STREAM_COUNTER
- if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) {
- psc->msc = (__DRImediaStreamCounterExtension *) extensions[i];
- __glXEnableDirectExtension(psc, "GLX_SGI_video_sync");
- }
-#endif
-
-#ifdef __DRI_SWAP_BUFFER_COUNTER
- /* No driver supports this at this time and the extension is
- * not defined in dri_interface.h. Will enable
- * GLX_OML_sync_control if implemented. */
-#endif
-
-#ifdef __DRI_READ_DRAWABLE
- if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) {
- __glXEnableDirectExtension(psc, "GLX_SGI_make_current_read");
- }
-#endif
-
-#ifdef __DRI_TEX_BUFFER
- if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
- psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
- __glXEnableDirectExtension(psc, "GLX_EXT_texture_from_pixmap");
- }
-#endif
-
- /* Ignore unknown extensions */
- }
-}
-
static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
__GLXdisplayPrivate *priv)
{
diff --git a/src/glx/x11/dri_common.c b/src/glx/x11/dri_common.c
new file mode 100644
index 0000000000..b159d193a5
--- /dev/null
+++ b/src/glx/x11/dri_common.c
@@ -0,0 +1,399 @@
+/*
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Soft-
+ * ware"), to deal in the Software without restriction, including without
+ * limitation the rights to use, copy, modify, merge, publish, distribute,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, provided that the above copyright
+ * notice(s) and this permission notice appear in all copies of the Soft-
+ * ware and that both the above copyright notice(s) and this permission
+ * notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+ * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
+ * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
+ * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
+ * MANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization of
+ * the copyright holder.
+ *
+ * Authors:
+ * Kevin E. Martin <kevin@precisioninsight.com>
+ * Brian Paul <brian@precisioninsight.com>
+ * Kristian Høgsberg (krh@redhat.com)
+ */
+
+#ifdef GLX_DIRECT_RENDERING
+
+#include <unistd.h>
+#include <dlfcn.h>
+#include "glheader.h"
+#include "glxclient.h"
+#include "glcontextmodes.h"
+#include "dri_common.h"
+
+#ifndef RTLD_NOW
+#define RTLD_NOW 0
+#endif
+#ifndef RTLD_GLOBAL
+#define RTLD_GLOBAL 0
+#endif
+
+_X_HIDDEN void InfoMessageF(const char *f, ...)
+{
+ va_list args;
+ const char *env;
+
+ if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) {
+ fprintf(stderr, "libGL: ");
+ va_start(args, f);
+ vfprintf(stderr, f, args);
+ va_end(args);
+ }
+}
+
+/**
+ * Print error to stderr, unless LIBGL_DEBUG=="quiet".
+ */
+_X_HIDDEN void ErrorMessageF(const char *f, ...)
+{
+ va_list args;
+ const char *env;
+
+ if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) {
+ fprintf(stderr, "libGL error: ");
+ va_start(args, f);
+ vfprintf(stderr, f, args);
+ va_end(args);
+ }
+}
+
+#ifndef DEFAULT_DRIVER_DIR
+/* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */
+#define DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
+#endif
+
+/**
+ * Try to \c dlopen the named driver.
+ *
+ * This function adds the "_dri.so" suffix to the driver name and searches the
+ * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
+ * order to find the driver.
+ *
+ * \param driverName - a name like "tdfx", "i810", "mga", etc.
+ *
+ * \returns
+ * A handle from \c dlopen, or \c NULL if driver file not found.
+ */
+_X_HIDDEN void *driOpenDriver(const char *driverName)
+{
+ void *glhandle, *handle;
+ const char *libPaths, *p, *next;
+ char realDriverName[200];
+ int len;
+
+ /* Attempt to make sure libGL symbols will be visible to the driver */
+ glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
+
+ libPaths = NULL;
+ if (geteuid() == getuid()) {
+ /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
+ libPaths = getenv("LIBGL_DRIVERS_PATH");
+ if (!libPaths)
+ libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
+ }
+ if (libPaths == NULL)
+ libPaths = DEFAULT_DRIVER_DIR;
+
+ handle = NULL;
+ for (p = libPaths; *p; p = next) {
+ next = strchr(p, ':');
+ if (next == NULL) {
+ len = strlen(p);
+ next = p + len;
+ } else {
+ len = next - p;
+ next++;
+ }
+
+#ifdef GLX_USE_TLS
+ snprintf(realDriverName, sizeof realDriverName,
+ "%.*s/tls/%s_dri.so", len, p, driverName);
+ InfoMessageF("OpenDriver: trying %s\n", realDriverName);
+ handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
+#endif
+
+ if ( handle == NULL ) {
+ snprintf(realDriverName, sizeof realDriverName,
+ "%.*s/%s_dri.so", len, p, driverName);
+ InfoMessageF("OpenDriver: trying %s\n", realDriverName);
+ handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
+ }
+
+ if ( handle != NULL )
+ break;
+ else
+ ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
+ }
+
+ if (!handle)
+ ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
+
+ if (glhandle)
+ dlclose(glhandle);
+
+ return handle;
+}
+
+_X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = {
+ { __DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION },
+ __glXGetUST,
+ __driGetMscRateOML
+};
+
+#define __ATTRIB(attrib, field) \
+ { attrib, offsetof(__GLcontextModes, field) }
+
+static const struct { unsigned int attrib, offset; } attribMap[] = {
+ __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
+ __ATTRIB(__DRI_ATTRIB_LEVEL, level),
+ __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
+ __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
+ __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
+ __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
+ __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
+ __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
+ __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
+ __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
+ __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
+ __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
+ __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
+ __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
+ __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
+ __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
+ __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
+#if 0
+ __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
+ __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex),
+ __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
+ __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
+ __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
+ __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
+ __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
+ __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
+ __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
+ __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
+#endif
+ __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
+ __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
+ __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
+ __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
+ __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
+#if 0
+ __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
+#endif
+ __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
+ __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
+ __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture),
+ __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
+};
+
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
+static int
+scalarEqual(__GLcontextModes *mode, unsigned int attrib, unsigned int value)
+{
+ unsigned int glxValue;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(attribMap); i++)
+ if (attribMap[i].attrib == attrib) {
+ glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset);
+ return glxValue == GLX_DONT_CARE || glxValue == value;
+ }
+
+ return GL_TRUE; /* Is a non-existing attribute equal to value? */
+}
+
+static int
+driConfigEqual(const __DRIcoreExtension *core,
+ __GLcontextModes *modes, const __DRIconfig *driConfig)
+{
+ unsigned int attrib, value, glxValue;
+ int i;
+
+ i = 0;
+ while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) {
+ switch (attrib) {
+ case __DRI_ATTRIB_RENDER_TYPE:
+ glxValue = 0;
+ if (value & __DRI_ATTRIB_RGBA_BIT) {
+ glxValue |= GLX_RGBA_BIT;
+ } else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) {
+ glxValue |= GLX_COLOR_INDEX_BIT;
+ }
+ if (glxValue != modes->renderType)
+ return GL_FALSE;
+ break;
+
+ case __DRI_ATTRIB_CONFIG_CAVEAT:
+ if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
+ glxValue = GLX_NON_CONFORMANT_CONFIG;
+ else if (value & __DRI_ATTRIB_SLOW_BIT)
+ glxValue = GLX_SLOW_CONFIG;
+ else
+ glxValue = GLX_NONE;
+ if (glxValue != modes->visualRating)
+ return GL_FALSE;
+ break;
+
+ case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS:
+ glxValue = 0;
+ if (value & __DRI_ATTRIB_TEXTURE_1D_BIT)
+ glxValue |= GLX_TEXTURE_1D_BIT_EXT;
+ if (value & __DRI_ATTRIB_TEXTURE_2D_BIT)
+ glxValue |= GLX_TEXTURE_2D_BIT_EXT;
+ if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT)
+ glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
+ if (modes->bindToTextureTargets != GLX_DONT_CARE &&
+ glxValue != modes->bindToTextureTargets)
+ return GL_FALSE;
+ break;
+
+ default:
+ if (!scalarEqual(modes, attrib, value))
+ return GL_FALSE;
+ }
+ }
+
+ return GL_TRUE;
+}
+
+static __GLcontextModes *
+createDriMode(const __DRIcoreExtension *core,
+ __GLcontextModes *modes, const __DRIconfig **driConfigs)
+{
+ __GLXDRIconfigPrivate *config;
+ int i;
+
+ for (i = 0; driConfigs[i]; i++) {
+ if (driConfigEqual(core, modes, driConfigs[i]))
+ break;
+ }
+
+ if (driConfigs[i] == NULL)
+ return NULL;
+
+ config = Xmalloc(sizeof *config);
+ if (config == NULL)
+ return NULL;
+
+ config->modes = *modes;
+ config->driConfig = driConfigs[i];
+
+ return &config->modes;
+}
+
+_X_HIDDEN __GLcontextModes *
+driConvertConfigs(const __DRIcoreExtension *core,
+ __GLcontextModes *modes, const __DRIconfig **configs)
+{
+ __GLcontextModes head, *tail, *m;
+
+ tail = &head;
+ head.next = NULL;
+ for (m = modes; m; m = m->next) {
+ tail->next = createDriMode(core, m, configs);
+ if (tail->next == NULL) {
+ /* no matching dri config for m */
+ continue;
+ }
+
+
+ tail = tail->next;
+ }
+
+ _gl_context_modes_destroy(modes);
+
+ return head.next;
+}
+
+_X_HIDDEN void
+driBindExtensions(__GLXscreenConfigs *psc)
+{
+ const __DRIextension **extensions;
+ int i;
+
+ extensions = psc->core->getExtensions(psc->__driScreen);
+
+ for (i = 0; extensions[i]; i++) {
+#ifdef __DRI_COPY_SUB_BUFFER
+ if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
+ psc->copySubBuffer = (__DRIcopySubBufferExtension *) extensions[i];
+ __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer_bit");
+ }
+#endif
+
+#ifdef __DRI_SWAP_CONTROL
+ if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) {
+ psc->swapControl = (__DRIswapControlExtension *) extensions[i];
+ __glXEnableDirectExtension(psc, "GLX_SGI_swap_control");
+ __glXEnableDirectExtension(psc, "GLX_MESA_swap_control");
+ }
+#endif
+
+#ifdef __DRI_ALLOCATE
+ if (strcmp(extensions[i]->name, __DRI_ALLOCATE) == 0) {
+ psc->allocate = (__DRIallocateExtension *) extensions[i];
+ __glXEnableDirectExtension(psc, "GLX_MESA_allocate_memory");
+ }
+#endif
+
+#ifdef __DRI_FRAME_TRACKING
+ if (strcmp(extensions[i]->name, __DRI_FRAME_TRACKING) == 0) {
+ psc->frameTracking = (__DRIframeTrackingExtension *) extensions[i];
+ __glXEnableDirectExtension(psc, "GLX_MESA_swap_frame_usage");
+ }
+#endif
+
+#ifdef __DRI_MEDIA_STREAM_COUNTER
+ if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) {
+ psc->msc = (__DRImediaStreamCounterExtension *) extensions[i];
+ __glXEnableDirectExtension(psc, "GLX_SGI_video_sync");
+ }
+#endif
+
+#ifdef __DRI_SWAP_BUFFER_COUNTER
+ /* No driver supports this at this time and the extension is
+ * not defined in dri_interface.h. Will enable
+ * GLX_OML_sync_control if implemented. */
+#endif
+
+#ifdef __DRI_READ_DRAWABLE
+ if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) {
+ __glXEnableDirectExtension(psc, "GLX_SGI_make_current_read");
+ }
+#endif
+
+#ifdef __DRI_TEX_BUFFER
+ if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
+ psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
+ __glXEnableDirectExtension(psc, "GLX_EXT_texture_from_pixmap");
+ }
+#endif
+
+ /* Ignore unknown extensions */
+ }
+}
+
+#endif /* GLX_DIRECT_RENDERING */
diff --git a/src/glx/x11/dri_common.h b/src/glx/x11/dri_common.h
new file mode 100644
index 0000000000..3556510335
--- /dev/null
+++ b/src/glx/x11/dri_common.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Soft-
+ * ware"), to deal in the Software without restriction, including without
+ * limitation the rights to use, copy, modify, merge, publish, distribute,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, provided that the above copyright
+ * notice(s) and this permission notice appear in all copies of the Soft-
+ * ware and that both the above copyright notice(s) and this permission
+ * notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+ * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
+ * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
+ * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
+ * MANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization of
+ * the copyright holder.
+ *
+ * Authors:
+ * Kevin E. Martin <kevin@precisioninsight.com>
+ * Brian Paul <brian@precisioninsight.com>
+ * Kristian Høgsberg (krh@redhat.com)
+ */
+
+#ifndef _DRI_COMMON_H
+#define _DRI_COMMON_H
+
+typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate;
+
+struct __GLXDRIconfigPrivateRec {
+ __GLcontextModes modes;
+ const __DRIconfig *driConfig;
+};
+
+extern __GLcontextModes *
+driConvertConfigs(const __DRIcoreExtension *core,
+ __GLcontextModes *modes, const __DRIconfig **configs);
+
+extern const __DRIsystemTimeExtension systemTimeExtension;
+
+extern void InfoMessageF(const char *f, ...);
+
+extern void ErrorMessageF(const char *f, ...);
+
+extern void *driOpenDriver(const char *driverName);
+
+extern void driBindExtensions(__GLXscreenConfigs *psc);
+
+#endif /* _DRI_COMMON_H */
diff --git a/src/glx/x11/dri_glx.c b/src/glx/x11/dri_glx.c
index da4824f172..d53f2d9854 100644
--- a/src/glx/x11/dri_glx.c
+++ b/src/glx/x11/dri_glx.c
@@ -34,7 +34,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef GLX_DIRECT_RENDERING
-#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xdamage.h>
@@ -47,17 +46,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/types.h>
#include <sys/mman.h>
#include "xf86drm.h"
-
-#ifndef RTLD_NOW
-#define RTLD_NOW 0
-#endif
-#ifndef RTLD_GLOBAL
-#define RTLD_GLOBAL 0
-#endif
+#include "dri_common.h"
typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;
typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;
-typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate;
struct __GLXDRIdisplayPrivateRec {
__GLXDRIdisplay base;
@@ -77,128 +69,12 @@ struct __GLXDRIcontextPrivateRec {
__GLXscreenConfigs *psc;
};
-struct __GLXDRIconfigPrivateRec {
- __GLcontextModes modes;
- const __DRIconfig *driConfig;
-};
-
-#ifndef DEFAULT_DRIVER_DIR
-/* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */
-#define DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
-#endif
-
-static void InfoMessageF(const char *f, ...)
-{
- va_list args;
- const char *env;
-
- if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) {
- fprintf(stderr, "libGL: ");
- va_start(args, f);
- vfprintf(stderr, f, args);
- va_end(args);
- }
-}
-
-extern void ErrorMessageF(const char *f, ...);
-
-/**
- * Print error to stderr, unless LIBGL_DEBUG=="quiet".
- */
-_X_HIDDEN void ErrorMessageF(const char *f, ...)
-{
- va_list args;
- const char *env;
-
- if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) {
- fprintf(stderr, "libGL error: ");
- va_start(args, f);
- vfprintf(stderr, f, args);
- va_end(args);
- }
-}
-
-extern void *driOpenDriver(const char *driverName);
-
-/**
- * Try to \c dlopen the named driver.
- *
- * This function adds the "_dri.so" suffix to the driver name and searches the
- * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
- * order to find the driver.
- *
- * \param driverName - a name like "tdfx", "i810", "mga", etc.
- *
- * \returns
- * A handle from \c dlopen, or \c NULL if driver file not found.
- */
-_X_HIDDEN void *driOpenDriver(const char *driverName)
-{
- void *glhandle, *handle;
- const char *libPaths, *p, *next;
- char realDriverName[200];
- int len;
-
- /* Attempt to make sure libGL symbols will be visible to the driver */
- glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
-
- libPaths = NULL;
- if (geteuid() == getuid()) {
- /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
- libPaths = getenv("LIBGL_DRIVERS_PATH");
- if (!libPaths)
- libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
- }
- if (libPaths == NULL)
- libPaths = DEFAULT_DRIVER_DIR;
-
- handle = NULL;
- for (p = libPaths; *p; p = next) {
- next = strchr(p, ':');
- if (next == NULL) {
- len = strlen(p);
- next = p + len;
- } else {
- len = next - p;
- next++;
- }
-
-#ifdef GLX_USE_TLS
- snprintf(realDriverName, sizeof realDriverName,
- "%.*s/tls/%s_dri.so", len, p, driverName);
- InfoMessageF("OpenDriver: trying %s\n", realDriverName);
- handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
-#endif
-
- if ( handle == NULL ) {
- snprintf(realDriverName, sizeof realDriverName,
- "%.*s/%s_dri.so", len, p, driverName);
- InfoMessageF("OpenDriver: trying %s\n", realDriverName);
- handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
- }
-
- if ( handle != NULL )
- break;
- else
- ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
- }
-
- if (!handle)
- ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
-
- if (glhandle)
- dlclose(glhandle);
-
- return handle;
-}
-
-
/*
* Given a display pointer and screen number, determine the name of
* the DRI driver for the screen. (I.e. "r128", "tdfx", etc).
* Return True for success, False for failure.
*/
-static Bool GetDriverName(Display *dpy, int scrNum, char **driverName)
+static Bool driGetDriverName(Display *dpy, int scrNum, char **driverName)
{
int directCapable;
Bool b;
@@ -228,25 +104,6 @@ static Bool GetDriverName(Display *dpy, int scrNum, char **driverName)
return True;
}
-
-/*
- * Given a display pointer and screen number, return a __DRIdriver handle.
- * Return NULL if anything goes wrong.
- */
-static void *driGetDriver(Display *dpy, int scrNum)
-{
- char *driverName;
- void *ret;
-
- if (GetDriverName(dpy, scrNum, &driverName)) {
- ret = driOpenDriver(driverName);
- if (driverName)
- Xfree(driverName);
- return ret;
- }
- return NULL;
-}
-
/*
* Exported function for querying the DRI driver for a given screen.
*
@@ -256,7 +113,7 @@ static void *driGetDriver(Display *dpy, int scrNum)
PUBLIC const char *glXGetScreenDriver (Display *dpy, int scrNum) {
static char ret[32];
char *driverName;
- if (GetDriverName(dpy, scrNum, &driverName)) {
+ if (driGetDriverName(dpy, scrNum, &driverName)) {
int len;
if (!driverName)
return NULL;
@@ -270,7 +127,6 @@ PUBLIC const char *glXGetScreenDriver (Display *dpy, int scrNum) {
return NULL;
}
-
/*
* Exported function for obtaining a driver's option list (UTF-8 encoded XML).
*
@@ -291,63 +147,6 @@ PUBLIC const char *glXGetDriverConfig (const char *driverName)
return NULL;
}
-extern void
-driFilterModes(__GLcontextModes ** server_modes,
- const __GLcontextModes * driver_modes);
-
-_X_HIDDEN void
-driFilterModes(__GLcontextModes ** server_modes,
- const __GLcontextModes * driver_modes)
-{
- __GLcontextModes * m;
- __GLcontextModes ** prev_next;
- const __GLcontextModes * check;
-
- if (driver_modes == NULL) {
- fprintf(stderr, "libGL warning: 3D driver returned no fbconfigs.\n");
- return;
- }
-
- /* For each mode in server_modes, check to see if a matching mode exists
- * in driver_modes. If not, then the mode is not available.
- */
-
- prev_next = server_modes;
- for ( m = *prev_next ; m != NULL ; m = *prev_next ) {
- GLboolean do_delete = GL_TRUE;
-
- for ( check = driver_modes ; check != NULL ; check = check->next ) {
- if ( _gl_context_modes_are_same( m, check ) ) {
- do_delete = GL_FALSE;
- break;
- }
- }
-
- /* The 3D has to support all the modes that match the GLX visuals
- * sent from the X server.
- */
- if ( do_delete && (m->visualID != 0) ) {
- do_delete = GL_FALSE;
-
- /* don't warn for this visual (Novell #247471 / X.Org #6689) */
- if (m->visualRating != GLX_NON_CONFORMANT_CONFIG) {
- fprintf(stderr, "libGL warning: 3D driver claims to not "
- "support visual 0x%02x\n", m->visualID);
- }
- }
-
- if ( do_delete ) {
- *prev_next = m->next;
-
- m->next = NULL;
- _gl_context_modes_destroy( m );
- }
- else {
- prev_next = & m->next;
- }
- }
-}
-
#ifdef XDAMAGE_1_1_INTERFACE
static GLboolean has_damage_post(Display *dpy)
@@ -442,12 +241,6 @@ __glXDRIGetDrawableInfo(__DRIdrawable *drawable,
numBackClipRects, pBackClipRects);
}
-_X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = {
- { __DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION },
- __glXGetUST,
- __driGetMscRateOML,
-};
-
static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = {
{ __DRI_GET_DRAWABLE_INFO, __DRI_GET_DRAWABLE_INFO_VERSION },
__glXDRIGetDrawableInfo
@@ -456,184 +249,13 @@ static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = {
static const __DRIextension *loader_extensions[] = {
&systemTimeExtension.base,
&getDrawableInfoExtension.base,
-
#ifdef XDAMAGE_1_1_INTERFACE
&damageExtension.base,
#endif
-
NULL
};
-#define __ATTRIB(attrib, field) \
- { attrib, offsetof(__GLcontextModes, field) }
-
-static const struct { unsigned int attrib, offset; } attribMap[] = {
- __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
- __ATTRIB(__DRI_ATTRIB_LEVEL, level),
- __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
- __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
- __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
- __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
- __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
- __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
- __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
- __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
- __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
- __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
- __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
- __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
- __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
- __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
- __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
-#if 0
- __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
- __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex),
- __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
- __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
- __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
- __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
- __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
- __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
- __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
- __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
-#endif
- __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
- __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
- __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
- __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
- __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
-#if 0
- __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
-#endif
- __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
- __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
- __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture),
- __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
-};
-
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
-static int
-scalarEqual(__GLcontextModes *mode, unsigned int attrib, unsigned int value)
-{
- unsigned int glxValue;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(attribMap); i++)
- if (attribMap[i].attrib == attrib) {
- glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset);
- return glxValue == GLX_DONT_CARE || glxValue == value;
- }
-
- return GL_TRUE; /* Is a non-existing attribute equal to value? */
-}
-
-static int
-driConfigEqual(const __DRIcoreExtension *core,
- __GLcontextModes *modes, const __DRIconfig *driConfig)
-{
- unsigned int attrib, value, glxValue;
- int i;
-
- i = 0;
- while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) {
- switch (attrib) {
- case __DRI_ATTRIB_RENDER_TYPE:
- glxValue = 0;
- if (value & __DRI_ATTRIB_RGBA_BIT) {
- glxValue |= GLX_RGBA_BIT;
- } else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) {
- glxValue |= GLX_COLOR_INDEX_BIT;
- }
- if (glxValue != modes->renderType)
- return GL_FALSE;
- break;
-
- case __DRI_ATTRIB_CONFIG_CAVEAT:
- if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
- glxValue = GLX_NON_CONFORMANT_CONFIG;
- else if (value & __DRI_ATTRIB_SLOW_BIT)
- glxValue = GLX_SLOW_CONFIG;
- else
- glxValue = GLX_NONE;
- if (glxValue != modes->visualRating)
- return GL_FALSE;
- break;
-
- case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS:
- glxValue = 0;
- if (value & __DRI_ATTRIB_TEXTURE_1D_BIT)
- glxValue |= GLX_TEXTURE_1D_BIT_EXT;
- if (value & __DRI_ATTRIB_TEXTURE_2D_BIT)
- glxValue |= GLX_TEXTURE_2D_BIT_EXT;
- if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT)
- glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
- if (modes->bindToTextureTargets != GLX_DONT_CARE &&
- glxValue != modes->bindToTextureTargets)
- return GL_FALSE;
- break;
-
- default:
- if (!scalarEqual(modes, attrib, value))
- return GL_FALSE;
- }
- }
-
- return GL_TRUE;
-}
-
-static __GLcontextModes *
-createDriMode(const __DRIcoreExtension *core,
- __GLcontextModes *modes, const __DRIconfig **driConfigs)
-{
- __GLXDRIconfigPrivate *config;
- int i;
-
- for (i = 0; driConfigs[i]; i++) {
- if (driConfigEqual(core, modes, driConfigs[i]))
- break;
- }
-
- if (driConfigs[i] == NULL)
- return NULL;
-
- config = Xmalloc(sizeof *config);
- if (config == NULL)
- return NULL;
-
- config->modes = *modes;
- config->driConfig = driConfigs[i];
-
- return &config->modes;
-}
-
-extern __GLcontextModes *
-driConvertConfigs(const __DRIcoreExtension *core,
- __GLcontextModes *modes, const __DRIconfig **configs);
-
-_X_HIDDEN __GLcontextModes *
-driConvertConfigs(const __DRIcoreExtension *core,
- __GLcontextModes *modes, const __DRIconfig **configs)
-{
- __GLcontextModes head, *tail, *m;
-
- tail = &head;
- head.next = NULL;
- for (m = modes; m; m = m->next) {
- tail->next = createDriMode(core, m, configs);
- if (tail->next == NULL) {
- /* no matching dri config for m */
- continue;
- }
-
-
- tail = tail->next;
- }
-
- _gl_context_modes_destroy(modes);
-
- return head.next;
-}
+#ifndef GLX_USE_APPLEGL
/**
* Perform the required libGL-side initialization and call the client-side
@@ -647,17 +269,12 @@ driConvertConfigs(const __DRIcoreExtension *core,
* \c __driCreateNewScreen function.
* \returns A pointer to the \c __DRIscreenPrivate structure returned by
* the client-side driver on success, or \c NULL on failure.
- *
- * \todo This function needs to be modified to remove context-modes from the
- * list stored in the \c __GLXscreenConfigsRec to match the list
- * returned by the client-side driver.
*/
static void *
CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc,
__GLXDRIdisplayPrivate * driDpy)
{
void *psp = NULL;
-#ifndef GLX_USE_APPLEGL
drm_handle_t hSAREA;
drmAddress pSAREA = MAP_FAILED;
char *BusID;
@@ -667,175 +284,159 @@ CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc,
__DRIframebuffer framebuffer;
int fd = -1;
int status;
- const char * err_msg;
- const char * err_extra;
+
+ drm_magic_t magic;
+ drmVersionPtr version;
+ int newlyopened;
+ char *driverName;
+ drm_handle_t hFB;
+ int junk;
const __DRIconfig **driver_configs;
+ /* DRI protocol version. */
dri_version.major = driDpy->driMajor;
dri_version.minor = driDpy->driMinor;
dri_version.patch = driDpy->driPatch;
- err_msg = "XF86DRIOpenConnection";
- err_extra = NULL;
-
framebuffer.base = MAP_FAILED;
framebuffer.dev_priv = NULL;
- if (XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) {
- int newlyopened;
- fd = drmOpenOnce(NULL,BusID, &newlyopened);
- Xfree(BusID); /* No longer needed */
-
- err_msg = "open DRM";
- err_extra = strerror( -fd );
-
- if (fd >= 0) {
- drm_magic_t magic;
-
- err_msg = "drmGetMagic";
- err_extra = NULL;
-
- if (!drmGetMagic(fd, &magic)) {
- drmVersionPtr version = drmGetVersion(fd);
- if (version) {
- drm_version.major = version->version_major;
- drm_version.minor = version->version_minor;
- drm_version.patch = version->version_patchlevel;
- drmFreeVersion(version);
- }
- else {
- drm_version.major = -1;
- drm_version.minor = -1;
- drm_version.patch = -1;
- }
-
- err_msg = "XF86DRIAuthConnection";
- if (!newlyopened || XF86DRIAuthConnection(dpy, scrn, magic)) {
- char *driverName;
-
- /*
- * Get device name (like "tdfx") and the ddx version
- * numbers. We'll check the version in each DRI driver's
- * "createNewScreen" function.
- */
- err_msg = "XF86DRIGetClientDriverName";
- if (XF86DRIGetClientDriverName(dpy, scrn,
- &ddx_version.major,
- &ddx_version.minor,
- &ddx_version.patch,
- &driverName)) {
- drm_handle_t hFB;
- int junk;
-
- /* No longer needed. */
- Xfree( driverName );
-
-
- /*
- * Get device-specific info. pDevPriv will point to a struct
- * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
- * that has information about the screen size, depth, pitch,
- * ancilliary buffers, DRM mmap handles, etc.
- */
- err_msg = "XF86DRIGetDeviceInfo";
- if (XF86DRIGetDeviceInfo(dpy, scrn,
- &hFB,
- &junk,
- &framebuffer.size,
- &framebuffer.stride,
- &framebuffer.dev_priv_size,
- &framebuffer.dev_priv)) {
- framebuffer.width = DisplayWidth(dpy, scrn);
- framebuffer.height = DisplayHeight(dpy, scrn);
-
- /*
- * Map the framebuffer region.
- */
- status = drmMap(fd, hFB, framebuffer.size,
- (drmAddressPtr)&framebuffer.base);
-
- err_msg = "drmMap of framebuffer";
- err_extra = strerror( -status );
-
- if ( status == 0 ) {
- /*
- * Map the SAREA region. Further mmap regions
- * may be setup in each DRI driver's
- * "createNewScreen" function.
- */
- status = drmMap(fd, hSAREA, SAREA_MAX,
- &pSAREA);
-
- err_msg = "drmMap of sarea";
- err_extra = strerror( -status );
-
- if ( status == 0 ) {
- err_msg = "InitDriver";
- err_extra = NULL;
- psp = (*psc->legacy->createNewScreen)(scrn,
- & ddx_version,
- & dri_version,
- & drm_version,
- & framebuffer,
- pSAREA,
- fd,
- loader_extensions,
- & driver_configs,
- psc);
-
- if (psp) {
- psc->configs =
- driConvertConfigs(psc->core,
- psc->configs,
- driver_configs);
- psc->visuals =
- driConvertConfigs(psc->core,
- psc->visuals,
- driver_configs);
- }
- }
- }
- }
- }
- }
- }
- }
+ if (!XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) {
+ ErrorMessageF("XF86DRIOpenConnection failed\n");
+ goto handle_error;
}
- if ( psp == NULL ) {
- if ( pSAREA != MAP_FAILED ) {
- (void)drmUnmap(pSAREA, SAREA_MAX);
- }
+ fd = drmOpenOnce(NULL, BusID, &newlyopened);
- if ( framebuffer.base != MAP_FAILED ) {
- (void)drmUnmap((drmAddress)framebuffer.base, framebuffer.size);
- }
+ Xfree(BusID); /* No longer needed */
- if ( framebuffer.dev_priv != NULL ) {
- Xfree(framebuffer.dev_priv);
- }
+ if (fd < 0) {
+ ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd));
+ goto handle_error;
+ }
- if ( fd >= 0 ) {
- (void)drmCloseOnce(fd);
- }
+ if (drmGetMagic(fd, &magic)) {
+ ErrorMessageF("drmGetMagic failed\n");
+ goto handle_error;
+ }
- (void)XF86DRICloseConnection(dpy, scrn);
+ version = drmGetVersion(fd);
+ if (version) {
+ drm_version.major = version->version_major;
+ drm_version.minor = version->version_minor;
+ drm_version.patch = version->version_patchlevel;
+ drmFreeVersion(version);
+ }
+ else {
+ drm_version.major = -1;
+ drm_version.minor = -1;
+ drm_version.patch = -1;
+ }
- if ( err_extra != NULL ) {
- fprintf(stderr, "libGL error: %s failed (%s)\n", err_msg,
- err_extra);
- }
- else {
- fprintf(stderr, "libGL error: %s failed\n", err_msg );
- }
+ if (newlyopened && !XF86DRIAuthConnection(dpy, scrn, magic)) {
+ ErrorMessageF("XF86DRIAuthConnection failed\n");
+ goto handle_error;
+ }
- fprintf(stderr, "libGL error: reverting to (slow) indirect rendering\n");
+ /* Get device name (like "tdfx") and the ddx version numbers.
+ * We'll check the version in each DRI driver's "createNewScreen"
+ * function. */
+ if (!XF86DRIGetClientDriverName(dpy, scrn,
+ &ddx_version.major,
+ &ddx_version.minor,
+ &ddx_version.patch,
+ &driverName)) {
+ ErrorMessageF("XF86DRIGetClientDriverName failed\n");
+ goto handle_error;
+ }
+
+ Xfree(driverName); /* No longer needed. */
+
+ /*
+ * Get device-specific info. pDevPriv will point to a struct
+ * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) that
+ * has information about the screen size, depth, pitch, ancilliary
+ * buffers, DRM mmap handles, etc.
+ */
+ if (!XF86DRIGetDeviceInfo(dpy, scrn, &hFB, &junk,
+ &framebuffer.size, &framebuffer.stride,
+ &framebuffer.dev_priv_size, &framebuffer.dev_priv)) {
+ ErrorMessageF("XF86DRIGetDeviceInfo failed");
+ goto handle_error;
}
-#endif /* !GLX_USE_APPLEGL */
+
+ framebuffer.width = DisplayWidth(dpy, scrn);
+ framebuffer.height = DisplayHeight(dpy, scrn);
+
+ /* Map the framebuffer region. */
+ status = drmMap(fd, hFB, framebuffer.size,
+ (drmAddressPtr)&framebuffer.base);
+ if (status != 0) {
+ ErrorMessageF("drmMap of framebuffer failed (%s)", strerror(-status));
+ goto handle_error;
+ }
+
+ /* Map the SAREA region. Further mmap regions may be setup in
+ * each DRI driver's "createNewScreen" function.
+ */
+ status = drmMap(fd, hSAREA, SAREA_MAX, &pSAREA);
+ if (status != 0) {
+ ErrorMessageF("drmMap of SAREA failed (%s)", strerror(-status));
+ goto handle_error;
+ }
+
+ psp = (*psc->legacy->createNewScreen)(scrn,
+ &ddx_version,
+ &dri_version,
+ &drm_version,
+ &framebuffer,
+ pSAREA,
+ fd,
+ loader_extensions,
+ &driver_configs,
+ psc);
+
+ if (psp == NULL) {
+ ErrorMessageF("Calling driver entry point failed");
+ goto handle_error;
+ }
+
+ psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
+ psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
return psp;
+
+ handle_error:
+ if (pSAREA != MAP_FAILED)
+ drmUnmap(pSAREA, SAREA_MAX);
+
+ if (framebuffer.base != MAP_FAILED)
+ drmUnmap((drmAddress)framebuffer.base, framebuffer.size);
+
+ if (framebuffer.dev_priv != NULL)
+ Xfree(framebuffer.dev_priv);
+
+ if (fd >= 0)
+ drmCloseOnce(fd);
+
+ XF86DRICloseConnection(dpy, scrn);
+
+ ErrorMessageF("reverting to software direct rendering\n");
+
+ return NULL;
+}
+
+#else /* !GLX_USE_APPLEGL */
+
+static void *
+CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc,
+ __GLXDRIdisplayPrivate * driDpy)
+{
+ return NULL;
}
+#endif /* !GLX_USE_APPLEGL */
+
static void driDestroyContext(__GLXDRIcontext *context,
__GLXscreenConfigs *psc, Display *dpy)
{
@@ -875,45 +476,44 @@ static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc,
__DRIcontext *shared = NULL;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
- if (psc && psc->driScreen) {
- if (shareList) {
- pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext;
- shared = pcp_shared->driContext;
- }
-
- pcp = Xmalloc(sizeof *pcp);
- if (pcp == NULL)
- return NULL;
+ if (!psc || !psc->driScreen)
+ return NULL;
- pcp->psc = psc;
- if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr,
- mode->visualID,
- &pcp->hwContextID, &hwContext)) {
- Xfree(pcp);
- return NULL;
- }
+ if (shareList) {
+ pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext;
+ shared = pcp_shared->driContext;
+ }
- pcp->driContext =
- (*psc->legacy->createNewContext)(psc->__driScreen,
- config->driConfig,
- renderType,
- shared,
- hwContext,
- pcp);
- if (pcp->driContext == NULL) {
- XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID);
- Xfree(pcp);
- return NULL;
- }
+ pcp = Xmalloc(sizeof *pcp);
+ if (pcp == NULL)
+ return NULL;
- pcp->base.destroyContext = driDestroyContext;
- pcp->base.bindContext = driBindContext;
- pcp->base.unbindContext = driUnbindContext;
+ pcp->psc = psc;
+ if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr,
+ mode->visualID,
+ &pcp->hwContextID, &hwContext)) {
+ Xfree(pcp);
+ return NULL;
+ }
- return &pcp->base;
+ pcp->driContext =
+ (*psc->legacy->createNewContext)(psc->__driScreen,
+ config->driConfig,
+ renderType,
+ shared,
+ hwContext,
+ pcp);
+ if (pcp->driContext == NULL) {
+ XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID);
+ Xfree(pcp);
+ return NULL;
}
- return NULL;
+ pcp->base.destroyContext = driDestroyContext;
+ pcp->base.bindContext = driBindContext;
+ pcp->base.unbindContext = driUnbindContext;
+
+ return &pcp->base;
}
static void driDestroyDrawable(__GLXDRIdrawable *pdraw)
@@ -979,15 +579,13 @@ static void driDestroyScreen(__GLXscreenConfigs *psc)
dlclose(psc->driver);
}
-void
-driBindExtensions(__GLXscreenConfigs *psc);
-
static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen,
__GLXdisplayPrivate *priv)
{
__GLXDRIdisplayPrivate *pdp;
__GLXDRIscreen *psp;
const __DRIextension **extensions;
+ char *driverName;
int i;
psp = Xmalloc(sizeof *psp);
@@ -997,7 +595,13 @@ static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen,
/* Initialize per screen dynamic client GLX extensions */
psc->ext_list_first_time = GL_TRUE;
- psc->driver = driGetDriver(priv->dpy, screen);
+ if (!driGetDriverName(priv->dpy, screen, &driverName)) {
+ Xfree(psp);
+ return NULL;
+ }
+
+ psc->driver = driOpenDriver(driverName);
+ Xfree(driverName);
if (psc->driver == NULL) {
Xfree(psp);
return NULL;
diff --git a/src/glx/x11/drisw_glx.c b/src/glx/x11/drisw_glx.c
new file mode 100644
index 0000000000..f7ff001121
--- /dev/null
+++ b/src/glx/x11/drisw_glx.c
@@ -0,0 +1,441 @@
+/*
+ * Copyright 2008 George Sapountzis
+ *
+ * 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 (including the next
+ * paragraph) 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.
+ */
+
+#ifdef GLX_DIRECT_RENDERING
+
+#include <X11/Xlib.h>
+#include "glheader.h"
+#include "glxclient.h"
+#include "glcontextmodes.h"
+#include <dlfcn.h>
+#include "dri_common.h"
+
+typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;
+typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;
+typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate;
+
+struct __GLXDRIdisplayPrivateRec {
+ __GLXDRIdisplay base;
+};
+
+struct __GLXDRIcontextPrivateRec {
+ __GLXDRIcontext base;
+ __DRIcontext *driContext;
+ __GLXscreenConfigs *psc;
+};
+
+struct __GLXDRIdrawablePrivateRec {
+ __GLXDRIdrawable base;
+
+ GC gc;
+ GC swapgc;
+
+ XVisualInfo *visinfo;
+ XImage *ximage;
+ int bpp;
+};
+
+/**
+ * swrast loader functions
+ */
+
+static Bool XCreateDrawable(__GLXDRIdrawablePrivate *pdp,
+ Display *dpy, XID drawable, int visualid)
+{
+ XGCValues gcvalues;
+ long visMask;
+ XVisualInfo visTemp;
+ int num_visuals;
+
+ /* create GC's */
+ pdp->gc = XCreateGC(dpy, drawable, 0, NULL);
+ pdp->swapgc = XCreateGC(dpy, drawable, 0, NULL);
+
+ gcvalues.function = GXcopy;
+ gcvalues.graphics_exposures = False;
+ XChangeGC(dpy, pdp->gc, GCFunction, &gcvalues);
+ XChangeGC(dpy, pdp->swapgc, GCFunction, &gcvalues);
+ XChangeGC(dpy, pdp->swapgc, GCGraphicsExposures, &gcvalues);
+
+ /* create XImage */
+ visTemp.screen = DefaultScreen(dpy);
+ visTemp.visualid = visualid;
+ visMask = (VisualScreenMask | VisualIDMask);
+ pdp->visinfo = XGetVisualInfo(dpy, visMask, &visTemp, &num_visuals);
+
+ pdp->ximage = XCreateImage(dpy,
+ pdp->visinfo->visual,
+ pdp->visinfo->depth,
+ ZPixmap, 0, /* format, offset */
+ NULL, /* data */
+ 0, 0, /* size */
+ 32, /* bitmap_pad */
+ 0); /* bytes_per_line */
+
+ /* get the true number of bits per pixel */
+ pdp->bpp = pdp->ximage->bits_per_pixel;
+
+ return True;
+}
+
+static void XDestroyDrawable(__GLXDRIdrawablePrivate *pdp,
+ Display *dpy, XID drawable)
+{
+ XDestroyImage(pdp->ximage);
+ XFree(pdp->visinfo);
+
+ XFreeGC(dpy, pdp->gc);
+ XFreeGC(dpy, pdp->swapgc);
+}
+
+static void
+swrastGetDrawableInfo(__DRIdrawable *draw,
+ int *x, int *y, int *w, int *h,
+ void *loaderPrivate)
+{
+ __GLXDRIdrawablePrivate *pdp = loaderPrivate;
+ __GLXDRIdrawable *pdraw = &(pdp->base);;
+ Display *dpy = pdraw->psc->dpy;
+ Drawable drawable;
+
+ Window root;
+ Status stat;
+ unsigned int bw, depth;
+
+ drawable = pdraw->xDrawable;
+
+ stat = XGetGeometry(dpy, drawable, &root,
+ x, y, (unsigned int *)w, (unsigned int *)h,
+ &bw, &depth);
+}
+
+static inline int
+bytes_per_line(int w, int bpp, unsigned mul)
+{
+ unsigned mask = mul - 1;
+
+ return ((w * bpp + mask) & ~mask) / 8;
+}
+
+static void
+swrastPutImage(__DRIdrawable *draw, int op,
+ int x, int y, int w, int h, char *data,
+ void *loaderPrivate)
+{
+ __GLXDRIdrawablePrivate *pdp = loaderPrivate;
+ __GLXDRIdrawable *pdraw = &(pdp->base);;
+ Display *dpy = pdraw->psc->dpy;
+ Drawable drawable;
+ XImage *ximage;
+ GC gc;
+
+ switch (op) {
+ case __DRI_SWRAST_IMAGE_OP_DRAW:
+ gc = pdp->gc;
+ break;
+ case __DRI_SWRAST_IMAGE_OP_SWAP:
+ gc = pdp->swapgc;
+ break;
+ default:
+ return;
+ }
+
+ drawable = pdraw->xDrawable;
+
+ ximage = pdp->ximage;
+ ximage->data = data;
+ ximage->width = w;
+ ximage->height = h;
+ ximage->bytes_per_line = bytes_per_line(w, pdp->bpp, 32);
+
+ XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h);
+
+ ximage->data = NULL;
+}
+
+static void
+swrastGetImage(__DRIdrawable *draw,
+ int x, int y, int w, int h, char *data,
+ void *loaderPrivate)
+{
+ __GLXDRIdrawablePrivate *pdp = loaderPrivate;
+ __GLXDRIdrawable *pdraw = &(pdp->base);;
+ Display *dpy = pdraw->psc->dpy;
+ Drawable drawable;
+ XImage *ximage;
+
+ drawable = pdraw->xDrawable;
+
+ ximage = pdp->ximage;
+ ximage->data = data;
+ ximage->width = w;
+ ximage->height = h;
+ ximage->bytes_per_line = bytes_per_line(w, pdp->bpp, 32);
+
+ XGetSubImage(dpy, drawable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0);
+
+ ximage->data = NULL;
+}
+
+static const __DRIswrastLoaderExtension swrastLoaderExtension = {
+ { __DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION },
+ swrastGetDrawableInfo,
+ swrastPutImage,
+ swrastGetImage
+};
+
+static const __DRIextension *loader_extensions[] = {
+ &systemTimeExtension.base,
+ &swrastLoaderExtension.base,
+ NULL
+};
+
+/**
+ * GLXDRI functions
+ */
+
+static void driDestroyContext(__GLXDRIcontext *context,
+ __GLXscreenConfigs *psc, Display *dpy)
+{
+ __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
+ const __DRIcoreExtension *core = pcp->psc->core;
+
+ (*core->destroyContext)(pcp->driContext);
+
+ Xfree(pcp);
+}
+
+static Bool driBindContext(__GLXDRIcontext *context,
+ __GLXDRIdrawable *draw, __GLXDRIdrawable *read)
+{
+ __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
+ const __DRIcoreExtension *core = pcp->psc->core;
+
+ return (*core->bindContext)(pcp->driContext,
+ draw->driDrawable,
+ read->driDrawable);
+}
+
+static void driUnbindContext(__GLXDRIcontext *context)
+{
+ __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
+ const __DRIcoreExtension *core = pcp->psc->core;
+
+ (*core->unbindContext)(pcp->driContext);
+}
+
+static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc,
+ const __GLcontextModes *mode,
+ GLXContext gc,
+ GLXContext shareList, int renderType)
+{
+ __GLXDRIcontextPrivate *pcp, *pcp_shared;
+ __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
+ const __DRIcoreExtension *core = psc->core;
+ __DRIcontext *shared = NULL;
+
+ if (!psc || !psc->driScreen)
+ return NULL;
+
+ if (shareList) {
+ pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext;
+ shared = pcp_shared->driContext;
+ }
+
+ pcp = Xmalloc(sizeof *pcp);
+ if (pcp == NULL)
+ return NULL;
+
+ pcp->psc = psc;
+ pcp->driContext =
+ (*core->createNewContext)(psc->__driScreen,
+ config->driConfig, shared, pcp);
+ if (pcp->driContext == NULL) {
+ Xfree(pcp);
+ return NULL;
+ }
+
+ pcp->base.destroyContext = driDestroyContext;
+ pcp->base.bindContext = driBindContext;
+ pcp->base.unbindContext = driUnbindContext;
+
+ return &pcp->base;
+}
+
+static void driDestroyDrawable(__GLXDRIdrawable *pdraw)
+{
+ __GLXDRIdrawablePrivate *pdp = (__GLXDRIdrawablePrivate *) pdraw;
+ const __DRIcoreExtension *core = pdraw->psc->core;
+
+ (*core->destroyDrawable)(pdraw->driDrawable);
+
+ XDestroyDrawable(pdp, pdraw->psc->dpy, pdraw->drawable);
+ Xfree(pdp);
+}
+
+static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc,
+ XID xDrawable,
+ GLXDrawable drawable,
+ const __GLcontextModes *modes)
+{
+ __GLXDRIdrawable *pdraw;
+ __GLXDRIdrawablePrivate *pdp;
+ __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
+ const __DRIswrastExtension *swrast = psc->swrast;
+
+ /* Old dri can't handle GLX 1.3+ drawable constructors. */
+ if (xDrawable != drawable)
+ return NULL;
+
+ pdp = Xmalloc(sizeof(*pdp));
+ if (!pdp)
+ return NULL;
+
+ pdraw = &(pdp->base);
+ pdraw->xDrawable = xDrawable;
+ pdraw->drawable = drawable;
+ pdraw->psc = psc;
+
+ XCreateDrawable(pdp, psc->dpy, xDrawable, modes->visualID);
+
+ /* Create a new drawable */
+ pdraw->driDrawable =
+ (*swrast->createNewDrawable)(psc->__driScreen,
+ config->driConfig,
+ pdp);
+
+ if (!pdraw->driDrawable) {
+ XDestroyDrawable(pdp, psc->dpy, xDrawable);
+ Xfree(pdp);
+ return NULL;
+ }
+
+ pdraw->destroyDrawable = driDestroyDrawable;
+
+ return pdraw;
+}
+
+static void driDestroyScreen(__GLXscreenConfigs *psc)
+{
+ /* Free the direct rendering per screen data */
+ (*psc->core->destroyScreen)(psc->__driScreen);
+ psc->__driScreen = NULL;
+ if (psc->driver)
+ dlclose(psc->driver);
+}
+
+static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen,
+ __GLXdisplayPrivate *priv)
+{
+ __GLXDRIscreen *psp;
+ const __DRIconfig **driver_configs;
+ const __DRIextension **extensions;
+ const char *driverName = "swrast";
+ int i;
+
+ psp = Xmalloc(sizeof *psp);
+ if (psp == NULL)
+ return NULL;
+
+ /* Initialize per screen dynamic client GLX extensions */
+ psc->ext_list_first_time = GL_TRUE;
+
+ psc->driver = driOpenDriver(driverName);
+ if (psc->driver == NULL)
+ goto handle_error;
+
+ extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
+ if (extensions == NULL) {
+ ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
+ goto handle_error;
+ }
+
+ for (i = 0; extensions[i]; i++) {
+ if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
+ psc->core = (__DRIcoreExtension *) extensions[i];
+ if (strcmp(extensions[i]->name, __DRI_SWRAST) == 0)
+ psc->swrast = (__DRIswrastExtension *) extensions[i];
+ }
+
+ if (psc->core == NULL || psc->swrast == NULL) {
+ ErrorMessageF("core dri extension not found\n");
+ goto handle_error;
+ }
+
+ psc->__driScreen =
+ psc->swrast->createNewScreen(screen,
+ loader_extensions, &driver_configs, psc);
+ if (psc->__driScreen == NULL) {
+ ErrorMessageF("failed to create dri screen\n");
+ goto handle_error;
+ }
+
+ driBindExtensions(psc);
+
+ psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
+ psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
+
+ psp->destroyScreen = driDestroyScreen;
+ psp->createContext = driCreateContext;
+ psp->createDrawable = driCreateDrawable;
+
+ return psp;
+
+ handle_error:
+ Xfree(psp);
+
+ if (psc->driver)
+ dlclose(psc->driver);
+
+ ErrorMessageF("reverting to indirect rendering\n");
+
+ return NULL;
+}
+
+/* Called from __glXFreeDisplayPrivate.
+ */
+static void driDestroyDisplay(__GLXDRIdisplay *dpy)
+{
+ Xfree(dpy);
+}
+
+/*
+ * Allocate, initialize and return a __DRIdisplayPrivate object.
+ * This is called from __glXInitialize() when we are given a new
+ * display pointer.
+ */
+_X_HIDDEN __GLXDRIdisplay *driswCreateDisplay(Display *dpy)
+{
+ __GLXDRIdisplayPrivate *pdpyp;
+
+ pdpyp = Xmalloc(sizeof *pdpyp);
+ if (pdpyp == NULL)
+ return NULL;
+
+ pdpyp->base.destroyDisplay = driDestroyDisplay;
+ pdpyp->base.createScreen = driCreateScreen;
+
+ return &pdpyp->base;
+}
+
+#endif /* GLX_DIRECT_RENDERING */
diff --git a/src/glx/x11/glcontextmodes.c b/src/glx/x11/glcontextmodes.c
index 2a8e48d00d..326c8b2357 100644
--- a/src/glx/x11/glcontextmodes.c
+++ b/src/glx/x11/glcontextmodes.c
@@ -118,7 +118,7 @@ _gl_convert_to_x_visual_type( int visualType )
* of the fields in \c config are copied to \c mode. Additional fields in
* \c mode that can be derrived from the fields of \c config (i.e.,
* \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
- * that cannot be derrived are set to default values.
+ * that cannot be derived are set to default values.
*
* \param mode Destination GL context mode.
* \param config Source GLX visual config.
@@ -184,6 +184,9 @@ _gl_copy_visual_to_context_mode( __GLcontextModes * mode,
mode->transparentBlue = config->transparentBlue;
mode->transparentAlpha = config->transparentAlpha;
mode->transparentIndex = config->transparentIndex;
+ mode->samples = config->multiSampleSize;
+ mode->sampleBuffers = config->nMultiSampleBuffers;
+ /* mode->visualSelectGroup = config->visualSelectGroup; ? */
mode->swapMethod = GLX_SWAP_UNDEFINED_OML;
diff --git a/src/glx/x11/glx_pbuffer.c b/src/glx/x11/glx_pbuffer.c
index 08743e560f..0f878f223f 100644
--- a/src/glx/x11/glx_pbuffer.c
+++ b/src/glx/x11/glx_pbuffer.c
@@ -293,7 +293,7 @@ GetDrawableAttribute( Display *dpy, GLXDrawable drawable,
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
if (pdraw != NULL && !pdraw->textureTarget)
- pdraw->textureTarget = determineTextureTarget(data,
+ pdraw->textureTarget = determineTextureTarget((const int *)data,
num_attributes);
}
#endif
diff --git a/src/glx/x11/glxclient.h b/src/glx/x11/glxclient.h
index d19cc04d07..b0a5d1315a 100644
--- a/src/glx/x11/glxclient.h
+++ b/src/glx/x11/glxclient.h
@@ -147,6 +147,7 @@ struct __GLXDRIdrawableRec {
** Function to create and DRI display data and initialize the display
** dependent methods.
*/
+extern __GLXDRIdisplay *driswCreateDisplay(Display *dpy);
extern __GLXDRIdisplay *driCreateDisplay(Display *dpy);
extern __GLXDRIdisplay *dri2CreateDisplay(Display *dpy);
@@ -465,6 +466,7 @@ struct __GLXscreenConfigsRec {
__DRIscreen *__driScreen;
const __DRIcoreExtension *core;
const __DRIlegacyExtension *legacy;
+ const __DRIswrastExtension *swrast;
__glxHashTable *drawHash;
Display *dpy;
int scr, fd;
@@ -564,6 +566,7 @@ struct __GLXdisplayPrivateRec {
/**
* Per display direct rendering interface functions and data.
*/
+ __GLXDRIdisplay *driswDisplay;
__GLXDRIdisplay *driDisplay;
__GLXDRIdisplay *dri2Display;
#endif
diff --git a/src/glx/x11/glxext.c b/src/glx/x11/glxext.c
index 75b7374a3f..777828569f 100644
--- a/src/glx/x11/glxext.c
+++ b/src/glx/x11/glxext.c
@@ -194,9 +194,14 @@ static int __glXFreeDisplayPrivate(XExtData *extension)
#ifdef GLX_DIRECT_RENDERING
/* Free the direct rendering per display data */
+ if (priv->driswDisplay)
+ (*priv->driswDisplay->destroyDisplay)(priv->driswDisplay);
+ priv->driswDisplay = NULL;
+
if (priv->driDisplay)
(*priv->driDisplay->destroyDisplay)(priv->driDisplay);
priv->driDisplay = NULL;
+
if (priv->dri2Display)
(*priv->dri2Display->destroyDisplay)(priv->dri2Display);
priv->dri2Display = NULL;
@@ -596,10 +601,16 @@ static Bool AllocAndFetchScreenConfigs(Display *dpy, __GLXdisplayPrivate *priv)
psc->drawHash = __glxHashCreate();
if (psc->drawHash == NULL)
continue;
+
if (priv->dri2Display)
psc->driScreen = (*priv->dri2Display->createScreen)(psc, i, priv);
+
if (psc->driScreen == NULL && priv->driDisplay)
psc->driScreen = (*priv->driDisplay->createScreen)(psc, i, priv);
+
+ if (psc->driScreen == NULL && priv->driswDisplay)
+ psc->driScreen = (*priv->driswDisplay->createScreen)(psc, i, priv);
+
if (psc->driScreen == NULL) {
__glxHashDestroy(psc->drawHash);
psc->drawHash = NULL;
@@ -693,8 +704,9 @@ _X_HIDDEN __GLXdisplayPrivate *__glXInitialize(Display* dpy)
** (e.g., those called in AllocAndFetchScreenConfigs).
*/
if (getenv("LIBGL_ALWAYS_INDIRECT") == NULL) {
- dpyPriv->dri2Display = dri2CreateDisplay(dpy);
+ dpyPriv->dri2Display = dri2CreateDisplay(dpy);
dpyPriv->driDisplay = driCreateDisplay(dpy);
+ dpyPriv->driswDisplay = driswCreateDisplay(dpy);
}
#endif
diff --git a/src/mesa/Makefile b/src/mesa/Makefile
index 08d723553e..27eb186abe 100644
--- a/src/mesa/Makefile
+++ b/src/mesa/Makefile
@@ -6,11 +6,6 @@ include $(TOP)/configs/current
include sources
-GL_MAJOR = 1
-GL_MINOR = 5
-GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY)
-
-
.SUFFIXES : .cpp
.c.o:
@@ -23,131 +18,45 @@ GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY)
$(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-# Figure out what to make here
-default: depend
- @for driver in $(DRIVER_DIRS) ; do \
- case "$$driver" in \
- x11) $(MAKE) stand-alone || exit 1 ;; \
- dri) $(MAKE) linux-solo || exit 1 ;; \
- osmesa) $(MAKE) osmesa-only || exit 1 ;; \
- beos) $(MAKE) beos || exit 1 ;; \
- directfb) $(MAKE) directfb || exit 1 ;; \
- fbdev) $(MAKE) fbdev || exit 1 ;; \
- *) echo "$$driver is invalid in DRIVER_DIRS" >&2; exit 1;; \
- esac ; \
- done
-
-install: default
- @for driver in $(DRIVER_DIRS) ; do \
- case "$$driver" in \
- osmesa) if [ "$(DRIVER_DIRS)" = osmesa ]; then \
- $(MAKE) install-headers install-osmesa || exit 1 ; \
- else \
- $(MAKE) install-osmesa || exit 1 ; \
- fi ;; \
- dri) $(MAKE) install-libgl install-dri || exit 1 ;; \
- *) $(MAKE) install-libgl || exit 1 ;; \
- esac ; \
- done
-
-######################################################################
-# BeOS driver target
+# Default: build dependencies, then asm_subdirs, then convenience
+# libs (.a) and finally the device drivers:
+default: depend asm_subdirs libmesa.a libglapi.a driver_subdirs
-beos: depend subdirs libmesa.a
- cd drivers/beos && $(MAKE)
######################################################################
-# Linux DRI drivers
-
-# Make archive of core object files
-libmesa.a: $(SOLO_OBJECTS)
- @ $(TOP)/bin/mklib -o mesa -static $(SOLO_OBJECTS);
- @if [ "${CONFIG_NAME}" = "beos" ] ; then \
- mimeset -f "$@" ; \
- fi
+# Helper libraries used by many drivers:
-linux-solo: depend subdirs libmesa.a
- cd drivers/dri && $(MAKE)
+# Make archive of core mesa object files
+libmesa.a: $(MESA_OBJECTS) asm_subdirs
+ @ $(TOP)/bin/mklib -o mesa -static $(MESA_OBJECTS)
+# Make archive of gl* API dispatcher functions only
+libglapi.a: $(GLAPI_OBJECTS) asm_subdirs
+ @ $(TOP)/bin/mklib -o glapi -static $(GLAPI_OBJECTS)
-#####################################################################
-# Stand-alone Mesa libGL, no built-in drivers (DirectFB)
-libgl-core: $(CORE_OBJECTS)
- @ $(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
- -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \
- -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) $(CORE_OBJECTS) \
- $(GL_LIB_DEPS)
-
-directfb: depend subdirs libgl-core
- cd drivers/directfb && $(MAKE)
-
-
-#####################################################################
-# fbdev Mesa driver (libGL.so)
-
-fbdev: $(CORE_OBJECTS) $(FBDEV_DRIVER_OBJECTS) $(COMMON_DRIVER_OBJECTS)
- @ $(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
- -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \
- -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
- $(CORE_OBJECTS) $(FBDEV_DRIVER_OBJECTS) \
- $(COMMON_DRIVER_OBJECTS) $(GL_LIB_DEPS)
+######################################################################
+# Device drivers
+driver_subdirs: libmesa.a libglapi.a
+ (cd drivers && $(MAKE))
######################################################################
-# Stand-alone Mesa libGL and libOSMesa
-STAND_ALONE_DRIVER_SOURCES = \
- $(COMMON_DRIVER_SOURCES) \
- $(X11_DRIVER_SOURCES)
-
-STAND_ALONE_DRIVER_OBJECTS = $(STAND_ALONE_DRIVER_SOURCES:.c=.o)
-
-STAND_ALONE_OBJECTS = \
- $(CORE_OBJECTS) \
- $(STAND_ALONE_DRIVER_OBJECTS)
-
-# For libOSMesa16 or libOSMesa32 we link _all_ the objects into the library,
-# not just the osmesa.o object (i.e. we don't have a libGL).
-OSMESA16_OBJECTS = \
- $(CORE_OBJECTS) \
- $(COMMON_DRIVER_OBJECTS) \
- $(OSMESA_DRIVER_OBJECTS)
-
-
-stand-alone: depend subdirs libmesa.a \
- $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
-
-osmesa-only: depend subdirs \
- $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME)
-
-# Make the GL library
-$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(STAND_ALONE_OBJECTS)
- @ $(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
- -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \
- -install $(TOP)/$(LIB_DIR) \
- $(MKLIB_OPTIONS) $(GL_LIB_DEPS) $(STAND_ALONE_OBJECTS)
-
-# Make the OSMesa library
-$(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME): $(OSMESA_DRIVER_OBJECTS) $(OSMESA16_OBJECTS)
- @ if [ "${DRIVER_DIRS}" = "osmesa" ] ; then \
- $(TOP)/bin/mklib -o $(OSMESA_LIB) -linker '$(CC)' \
- -ldflags '$(LDFLAGS)' -major $(MESA_MAJOR) \
- -minor $(MESA_MINOR) -patch $(MESA_TINY) \
- -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
- $(OSMESA_LIB_DEPS) $(OSMESA16_OBJECTS) ; \
- else \
- $(TOP)/bin/mklib -o $(OSMESA_LIB) -linker '$(CC)' \
- -ldflags '$(LDFLAGS)' -major $(MESA_MAJOR) \
- -minor $(MESA_MINOR) -patch $(GL_TINY) \
- -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
- $(OSMESA_LIB_DEPS) $(OSMESA_DRIVER_OBJECTS) ; \
+# Assembly subdirs
+asm_subdirs:
+ @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_ASM ; then \
+ (cd x86 && $(MAKE)) || exit 1 ; \
+ fi
+ @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_64_ASM ; then \
+ (cd x86 && $(MAKE)) || exit 1 ; \
+ (cd x86-64 && $(MAKE)) || exit 1 ; \
fi
######################################################################
-# Generic stuff
+# Dependency generation
depend: $(ALL_SOURCES)
@ echo "running $(MKDEP)"
@@ -156,14 +65,28 @@ depend: $(ALL_SOURCES)
> /dev/null 2>/dev/null
-subdirs:
- @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_ASM ; then \
- (cd x86 && $(MAKE)) || exit 1 ; \
- fi
- @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_64_ASM ; then \
- (cd x86 && $(MAKE)) || exit 1 ; \
- (cd x86-64 && $(MAKE)) || exit 1 ; \
- fi
+######################################################################
+# Installation rules
+
+# this isn't fleshed out yet but is probably the way to go in the future
+new_install:
+ (cd drivers && $(MAKE) install)
+
+
+# XXX replace this with new_install above someday
+install: default
+ @for driver in $(DRIVER_DIRS) ; do \
+ case "$$driver" in \
+ osmesa) if [ "$(DRIVER_DIRS)" = osmesa ]; then \
+ $(MAKE) install-headers install-osmesa || exit 1 ; \
+ else \
+ $(MAKE) install-osmesa || exit 1 ; \
+ fi ;; \
+ dri) $(MAKE) install-libgl install-dri || exit 1 ;; \
+ *) $(MAKE) install-libgl || exit 1 ;; \
+ esac ; \
+ done
+
pcedit = sed \
-e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \
@@ -193,22 +116,21 @@ install-osmesa: default
install-dri:
cd drivers/dri && $(MAKE) install
-## NOT INSTALLED YET:
-## $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/include/GLES
-## $(INSTALL) -m 644 include/GLES/*.h $(DESTDIR)$(INSTALL_DIR)/include/GLES
# Emacs tags
tags:
etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h
+
clean:
-rm -f */*.o
-rm -f */*/*.o
- -rm -f depend depend.bak libmesa.a
+ -rm -f depend depend.bak libmesa.a libglapi.a
-rm -f drivers/*/*.o
-@cd drivers/dri && $(MAKE) clean
- -@cd drivers/xorg && $(MAKE) clean
+ -@cd drivers/x11 && $(MAKE) clean
+ -@cd drivers/osmesa && $(MAKE) clean
-@cd x86 && $(MAKE) clean
-@cd x86-64 && $(MAKE) clean
diff --git a/src/mesa/drivers/Makefile b/src/mesa/drivers/Makefile
new file mode 100644
index 0000000000..c5998413e8
--- /dev/null
+++ b/src/mesa/drivers/Makefile
@@ -0,0 +1,29 @@
+# src/mesa/drivers/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+default:
+ @for dir in $(DRIVER_DIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE)) || exit 1; \
+ fi \
+ done
+
+
+clean:
+ @for dir in $(DRIVER_DIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE) clean) || exit 1; \
+ fi \
+ done
+
+
+install:
+ @for dir in $(DRIVER_DIRS) ; do \
+ if [ -d $$dir ] ; then \
+ (cd $$dir && $(MAKE) install) || exit 1; \
+ fi \
+ done
+
diff --git a/src/mesa/drivers/beos/Makefile b/src/mesa/drivers/beos/Makefile
index 0448650a8c..342d7ce024 100644
--- a/src/mesa/drivers/beos/Makefile
+++ b/src/mesa/drivers/beos/Makefile
@@ -169,8 +169,10 @@ OBJECTS := $(DRIVER_OBJECTS:.cpp=.o)
default: depend $(TOP)/$(LIB_DIR) $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
+# XXX FIXME: mesa.a might be libmesa.a now
$(MESA_MODULES):
cd $(TOP)/src/mesa && $(MAKE) mesa.a ;
+ mimeset -f "$@"
$(GLU_MODULES):
cd $(GLU_DIR) && $(MAKE) $(subst $(GLU_DIR)/,,$(GLU_MODULES)) ;
diff --git a/src/mesa/drivers/directfb/Makefile b/src/mesa/drivers/directfb/Makefile
index dc71b385ca..ece0457cff 100644
--- a/src/mesa/drivers/directfb/Makefile
+++ b/src/mesa/drivers/directfb/Makefile
@@ -25,11 +25,24 @@ DIRECTFBGL_MESA_OBJECTS = $(DIRECTFBGL_MESA_SOURCES:.c=.o)
DIRECTFBGL_MESA = libidirectfbgl_mesa.so
+LIBS = $(TOP)/src/mesa/libmesa.a $(TOP)/src/mesa/libglapi.a
+
+
.c.o:
$(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(DFB_CFLAGS) $< -o $@
-default: directfbgl_mesa
+default: directfb-libgl directfbgl_mesa
+
+
+# XXX this used to be in src/mesa/Makefile and is probably broken now
+directfb-libgl: $(LIBS)
+ @ $(TOP)/bin/mklib -o $(GL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+ -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \
+ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) $(LIBS) \
+ $(GL_LIB_DEPS)
+
+
# Mesa DirectFBGL module
directfbgl_mesa: $(DIRECTFBGL_MESA_OBJECTS)
diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template
index 864c6234c8..7dcb077dca 100644
--- a/src/mesa/drivers/dri/Makefile.template
+++ b/src/mesa/drivers/dri/Makefile.template
@@ -3,7 +3,6 @@
MESA_MODULES = $(TOP)/src/mesa/libmesa.a
COMMON_SOURCES = \
- ../../common/driverfuncs.c \
../common/utils.c \
../common/texmem.c \
../common/vblank.c \
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 6efdf4312a..10d2e801dc 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -277,9 +277,9 @@ __driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp)
pdp->pStamp = &(psp->pSAREA->drawableTable[pdp->index].stamp);
DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
-
}
+
int
__driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp)
{
@@ -471,6 +471,7 @@ static int driDrawableGetMSC( __DRIscreen *sPriv, __DRIdrawable *dPriv,
return sPriv->DriverAPI.GetDrawableMSC(sPriv, dPriv, msc);
}
+
static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc,
int64_t divisor, int64_t remainder,
int64_t * msc, int64_t * sbc)
@@ -478,7 +479,6 @@ static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc,
__DRIswapInfo sInfo;
int status;
-
status = dPriv->driScreenPriv->DriverAPI.WaitForMSC( dPriv, target_msc,
divisor, remainder,
msc );
@@ -496,12 +496,14 @@ static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc,
return status;
}
+
const __DRImediaStreamCounterExtension driMediaStreamCounterExtension = {
{ __DRI_MEDIA_STREAM_COUNTER, __DRI_MEDIA_STREAM_COUNTER_VERSION },
driWaitForMSC,
driDrawableGetMSC,
};
+
static void driCopySubBuffer(__DRIdrawable *dPriv,
int x, int y, int w, int h)
{
@@ -595,6 +597,7 @@ driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config,
return pdp;
}
+
static __DRIdrawable *
dri2CreateNewDrawable(__DRIscreen *screen, const __DRIconfig *config,
unsigned int drawable_id, unsigned int head, void *data)
@@ -602,6 +605,8 @@ dri2CreateNewDrawable(__DRIscreen *screen, const __DRIconfig *config,
__DRIdrawable *pdraw;
pdraw = driCreateNewDrawable(screen, config, 0, 0, NULL, data);
+ if (!pdraw)
+ return NULL;
pdraw->dri2.drawable_id = drawable_id;
pdraw->dri2.tail = head;
@@ -642,8 +647,6 @@ driDestroyDrawable(__DRIdrawable *pdp)
/**
* Destroy the per-context private information.
*
- * \param contextPrivate opaque pointer to the per-drawable private info.
- *
* \internal
* This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls
* drmDestroyContext(), and finally frees \p contextPrivate.
@@ -661,13 +664,9 @@ driDestroyContext(__DRIcontext *pcp)
/**
* Create the per-drawable private driver information.
*
- * \param dpy The display handle.
- * \param modes Mode used to create the new context.
* \param render_type Type of rendering target. \c GLX_RGBA is the only
* type likely to ever be supported for direct-rendering.
- * \param shared The shared context dependent methods or \c NULL if
- * non-existent.
- * \param pctx DRI context to receive the context dependent methods.
+ * \param shared Context with which to share textures, etc. or NULL
*
* \returns An opaque pointer to the per-context private information on
* success, or \c NULL on failure.
@@ -716,6 +715,7 @@ driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
return pcp;
}
+
static __DRIcontext *
dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
__DRIcontext *shared, void *data)
@@ -734,6 +734,7 @@ dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
return driCreateNewContext(screen, config, 0, shared, hwContext, data);
}
+
static int
driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
{
@@ -751,10 +752,6 @@ driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
/**
* Destroy the per-screen private information.
*
- * \param dpy the display handle.
- * \param scrn the screen number.
- * \param screenPrivate opaque pointer to the per-screen private information.
- *
* \internal
* This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
* drmClose(), and finally frees \p screenPrivate.
@@ -809,15 +806,10 @@ setupLoaderExtensions(__DRIscreen *psp,
* This routine also fills in the linked list pointed to by \c driver_modes
* with the \c __GLcontextModes that the driver can support for windows or
* pbuffers.
+ *
+ * For legacy DRI.
*
* \param scrn Index of the screen
- * \param psc DRI screen data (not driver private)
- * \param modes Linked list of known display modes. This list is, at a
- * minimum, a list of modes based on the current display mode.
- * These roughly match the set of available X11 visuals, but it
- * need not be limited to X11! The calling libGL should create
- * a list that will inform the driver of the current display
- * mode (i.e., color buffer depth, depth buffer depth, etc.).
* \param ddx_version Version of the 2D DDX. This may not be meaningful for
* all drivers.
* \param dri_version Version of the "server-side" DRI.
@@ -826,9 +818,9 @@ setupLoaderExtensions(__DRIscreen *psp,
* framebuffer.
* \param pSAREA Pointer the the SAREA.
* \param fd Device handle for the DRM.
- * \param internal_api_version Version of the internal interface between the
- * driver and libGL.
- * \param driverAPI Driver API functions used by other routines in dri_util.c.
+ * \param extensions ??
+ * \param driver_modes Returns modes suppoted by the driver
+ * \param loaderPrivate ??
*
* \note There is no need to check the minimum API version in this
* function. Since the name of this function is versioned, it is
@@ -901,6 +893,9 @@ driCreateNewScreen(int scrn,
}
+/**
+ * DRI2
+ */
static __DRIscreen *
dri2CreateNewScreen(int scrn, int fd, unsigned int sarea_handle,
const __DRIextension **extensions,
@@ -984,6 +979,7 @@ static const __DRIextension **driGetExtensions(__DRIscreen *psp)
return psp->extensions;
}
+/** Legacy DRI interface */
const __DRIlegacyExtension driLegacyExtension = {
{ __DRI_LEGACY, __DRI_LEGACY_VERSION },
driCreateNewScreen,
@@ -991,6 +987,7 @@ const __DRIlegacyExtension driLegacyExtension = {
driCreateNewContext
};
+/** DRI2 interface */
const __DRIcoreExtension driCoreExtension = {
{ __DRI_CORE, __DRI_CORE_VERSION },
dri2CreateNewScreen,
diff --git a/src/mesa/drivers/dri/i915/i915_texstate.c b/src/mesa/drivers/dri/i915/i915_texstate.c
index 987c6c0454..af7166e681 100644
--- a/src/mesa/drivers/dri/i915/i915_texstate.c
+++ b/src/mesa/drivers/dri/i915/i915_texstate.c
@@ -65,7 +65,12 @@ translate_texture_format(GLuint mesa_format, GLenum DepthMode)
case MESA_FORMAT_RGBA_FXT1:
return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
case MESA_FORMAT_Z16:
- return (MAPSURF_16BIT | (DepthMode==GL_ALPHA?MT_16BIT_A16:MT_16BIT_L16));
+ if (DepthMode == GL_ALPHA)
+ return (MAPSURF_16BIT | MT_16BIT_A16);
+ else if (DepthMode == GL_INTENSITY)
+ return (MAPSURF_16BIT | MT_16BIT_I16);
+ else
+ return (MAPSURF_16BIT | MT_16BIT_L16);
case MESA_FORMAT_RGBA_DXT1:
case MESA_FORMAT_RGB_DXT1:
return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
diff --git a/src/mesa/drivers/dri/i965/brw_wm_fp.c b/src/mesa/drivers/dri/i965/brw_wm_fp.c
index 7e80724130..ef90260e2a 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_fp.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_fp.c
@@ -737,7 +737,8 @@ static void precalc_tex( struct brw_wm_compile *c,
release_temp(c, tmp);
}
- if (inst->TexSrcTarget == GL_TEXTURE_RECTANGLE_NV)
+ if ((inst->TexSrcTarget == TEXTURE_RECT_INDEX) ||
+ (inst->TexSrcTarget == TEXTURE_CUBE_INDEX))
release_temp(c, tmpcoord);
}
@@ -1019,7 +1020,11 @@ void brw_wm_pass_fp( struct brw_wm_compile *c )
case OPCODE_LIT:
precalc_lit(c, inst);
break;
-
+
+ case OPCODE_TEX:
+ precalc_tex(c, inst);
+ break;
+
case OPCODE_TXP:
precalc_txp(c, inst);
break;
diff --git a/src/mesa/drivers/dri/i965/brw_wm_glsl.c b/src/mesa/drivers/dri/i965/brw_wm_glsl.c
index b2ffc82ed2..faa2837fa0 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_glsl.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_glsl.c
@@ -978,7 +978,7 @@ static void emit_wpos_xy(struct brw_wm_compile *c,
brw_ADD(p,
dst[0],
retype(src0[0], BRW_REGISTER_TYPE_W),
- brw_imm_d(- c->key.origin_x));
+ brw_imm_d(0 - c->key.origin_x));
}
if (mask & WRITEMASK_Y) {
diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c
index 174f5ecab0..f1f21e7dfe 100644
--- a/src/mesa/drivers/dri/intel/intel_blit.c
+++ b/src/mesa/drivers/dri/intel/intel_blit.c
@@ -327,9 +327,6 @@ intelEmitCopyBlit(struct intel_context *intel,
return;
}
- dst_pitch &= 0xffff;
- src_pitch &= 0xffff;
-
/* Initial y values don't seem to work with negative pitches. If
* we adjust the offsets manually (below), it seems to work fine.
*
@@ -362,7 +359,7 @@ intelEmitCopyBlit(struct intel_context *intel,
BEGIN_BATCH(8, NO_LOOP_CLIPRECTS);
OUT_BATCH(CMD);
- OUT_BATCH(BR13 | dst_pitch);
+ OUT_BATCH(BR13 | ((uint16_t)dst_pitch));
OUT_BATCH((0 << 16) | dst_x);
OUT_BATCH((h << 16) | dst_x2);
OUT_RELOC(dst_buffer,
diff --git a/src/mesa/drivers/dri/intel/intel_chipset.h b/src/mesa/drivers/dri/intel/intel_chipset.h
index 3c8fd2384e..4a5166263a 100644
--- a/src/mesa/drivers/dri/intel/intel_chipset.h
+++ b/src/mesa/drivers/dri/intel/intel_chipset.h
@@ -53,7 +53,11 @@
#define PCI_CHIP_I965_GM 0x2A02
#define PCI_CHIP_I965_GME 0x2A12
-#define PCI_CHIP_IGD_GM 0x2A42
+#define PCI_CHIP_IGD_GM 0x2A42
+
+#define PCI_CHIP_IGD_E_G 0x2E02
+#define PCI_CHIP_Q45_G 0x2E12
+#define PCI_CHIP_G45_G 0x2E22
#define IS_MOBILE(devid) (devid == PCI_CHIP_I855_GM || \
devid == PCI_CHIP_I915_GM || \
@@ -63,7 +67,11 @@
devid == PCI_CHIP_I965_GME || \
devid == PCI_CHIP_IGD_GM)
-#define IS_IGD(devid) (devid == PCI_CHIP_IGD_GM)
+#define IS_IGD_GM(devid) (devid == PCI_CHIP_IGD_GM)
+#define IS_G4X(devid) (devid == PCI_CHIP_IGD_E_G || \
+ devid == PCI_CHIP_Q45_G || \
+ devid == PCI_CHIP_G45_G)
+#define IS_IGD(devid) (IS_IGD_GM(devid) || IS_G4X(devid))
#define IS_915(devid) (devid == PCI_CHIP_I915_G || \
devid == PCI_CHIP_E7221_G || \
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index e668b7326a..b9e1eae982 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -167,8 +167,15 @@ intelGetString(GLcontext * ctx, GLenum name)
chipset = "Intel(R) 965GME/GLE";
break;
case PCI_CHIP_IGD_GM:
+ case PCI_CHIP_IGD_E_G:
chipset = "Intel(R) Integrated Graphics Device";
break;
+ case PCI_CHIP_G45_G:
+ chipset = "Intel(R) G45/G43";
+ break;
+ case PCI_CHIP_Q45_G:
+ chipset = "Intel(R) Q45/Q43";
+ break;
default:
chipset = "Unknown Intel Chipset";
break;
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 09a30e80a5..8fd503ee8b 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -291,6 +291,10 @@ intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
intelPrintSAREA(sarea);
}
+
+/**
+ * DRI2 entrypoint
+ */
static void
intelHandleDrawableConfig(__DRIdrawablePrivate *dPriv,
__DRIcontextPrivate *pcp,
@@ -332,6 +336,9 @@ intelHandleDrawableConfig(__DRIdrawablePrivate *dPriv,
#define BUFFER_FLAG_TILED 0x0100
+/**
+ * DRI2 entrypoint
+ */
static void
intelHandleBufferAttach(__DRIdrawablePrivate *dPriv,
__DRIcontextPrivate *pcp,
@@ -734,6 +741,7 @@ intelFillInModes(__DRIscreenPrivate *psp,
/**
* This is the driver specific part of the createNewScreen entry point.
+ * Called when using legacy DRI.
*
* \todo maybe fold this into intelInitDriver
*
@@ -797,7 +805,8 @@ struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
/**
* This is the driver specific part of the createNewScreen entry point.
- *
+ * Called when using DRI2.
+ *
* \return the __GLcontextModes supported by this driver
*/
static const
diff --git a/src/mesa/drivers/dri/r300/Makefile b/src/mesa/drivers/dri/r300/Makefile
index 5b2bd0bc2b..d52b2b4c36 100644
--- a/src/mesa/drivers/dri/r300/Makefile
+++ b/src/mesa/drivers/dri/r300/Makefile
@@ -28,7 +28,6 @@ DRIVER_SOURCES = \
radeon_span.c \
radeon_state.c \
r300_mem.c \
- \
r300_context.c \
r300_ioctl.c \
r300_cmdbuf.c \
@@ -37,9 +36,13 @@ DRIVER_SOURCES = \
r300_texmem.c \
r300_tex.c \
r300_texstate.c \
+ radeon_program.c \
+ radeon_program_alu.c \
r300_vertprog.c \
r300_fragprog.c \
+ r300_fragprog_emit.c \
r500_fragprog.c \
+ r500_fragprog_emit.c \
r300_shader.c \
r300_emit.c \
r300_swtcl.c \
diff --git a/src/mesa/drivers/dri/r300/r300_context.c b/src/mesa/drivers/dri/r300/r300_context.c
index 31cc00a081..063d4e575e 100644
--- a/src/mesa/drivers/dri/r300/r300_context.c
+++ b/src/mesa/drivers/dri/r300/r300_context.c
@@ -98,6 +98,7 @@ const struct dri_extension card_extensions[] = {
{"GL_ARB_fragment_program", NULL},
{"GL_ARB_multisample", GL_ARB_multisample_functions},
{"GL_ARB_multitexture", NULL},
+ {"GL_ARB_shadow", NULL},
{"GL_ARB_texture_border_clamp", NULL},
{"GL_ARB_texture_compression", GL_ARB_texture_compression_functions},
{"GL_ARB_texture_cube_map", NULL},
@@ -116,6 +117,7 @@ const struct dri_extension card_extensions[] = {
{"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
{"GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions},
{"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
+ {"GL_EXT_shadow_funcs", NULL},
{"GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions},
{"GL_EXT_stencil_wrap", NULL},
{"GL_EXT_texture_edge_clamp", NULL},
diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h
index a5ec5ee46e..6279a67ab1 100644
--- a/src/mesa/drivers/dri/r300/r300_context.h
+++ b/src/mesa/drivers/dri/r300/r300_context.h
@@ -73,7 +73,6 @@ typedef struct r300_context *r300ContextPtr;
}
#include "r300_vertprog.h"
-#include "r300_fragprog.h"
#include "r500_fragprog.h"
/**
@@ -179,13 +178,6 @@ struct r300_tex_obj {
GLuint bufAddr; /* Offset to start of locally
shared texture block */
- GLuint dirty_state; /* Flags (1 per texunit) for
- whether or not this texobj
- has dirty hardware state
- (pp_*) that needs to be
- brought into the
- texunit. */
-
drm_radeon_tex_image_t image[6][RADEON_MAX_TEXTURE_LEVELS];
/* Six, for the cube faces */
@@ -581,9 +573,7 @@ struct r300_depthbuffer_state {
};
struct r300_stencilbuffer_state {
- GLuint clear;
GLboolean hw_stencil;
-
};
/* Vertex shader state */
@@ -663,96 +653,40 @@ struct r300_vertex_program_cont {
#define PFS_NUM_TEMP_REGS 32
#define PFS_NUM_CONST_REGS 16
-/* Mapping Mesa registers to R300 temporaries */
-struct reg_acc {
- int reg; /* Assigned hw temp */
- unsigned int refcount; /* Number of uses by mesa program */
-};
+struct r300_pfs_compile_state;
-/**
- * Describe the current lifetime information for an R300 temporary
- */
-struct reg_lifetime {
- /* Index of the first slot where this register is free in the sense
- that it can be used as a new destination register.
- This is -1 if the register has been assigned to a Mesa register
- and the last access to the register has not yet been emitted */
- int free;
-
- /* Index of the first slot where this register is currently reserved.
- This is used to stop e.g. a scalar operation from being moved
- before the allocation time of a register that was first allocated
- for a vector operation. */
- int reserved;
-
- /* Index of the first slot in which the register can be used as a
- source without losing the value that is written by the last
- emitted instruction that writes to the register */
- int vector_valid;
- int scalar_valid;
-
- /* Index to the slot where the register was last read.
- This is also the first slot in which the register may be written again */
- int vector_lastread;
- int scalar_lastread;
-};
/**
- * Store usage information about an ALU instruction slot during the
- * compilation of a fragment program.
+ * Stores state that influences the compilation of a fragment program.
*/
-#define SLOT_SRC_VECTOR (1<<0)
-#define SLOT_SRC_SCALAR (1<<3)
-#define SLOT_SRC_BOTH (SLOT_SRC_VECTOR | SLOT_SRC_SCALAR)
-#define SLOT_OP_VECTOR (1<<16)
-#define SLOT_OP_SCALAR (1<<17)
-#define SLOT_OP_BOTH (SLOT_OP_VECTOR | SLOT_OP_SCALAR)
-
-struct r300_pfs_compile_slot {
- /* Bitmask indicating which parts of the slot are used, using SLOT_ constants
- defined above */
- unsigned int used;
-
- /* Selected sources */
- int vsrc[3];
- int ssrc[3];
+struct r300_fragment_program_external_state {
+ struct {
+ /**
+ * If the sampler is used as a shadow sampler,
+ * this field is:
+ * 0 - GL_LUMINANCE
+ * 1 - GL_INTENSITY
+ * 2 - GL_ALPHA
+ * depending on the depth texture mode.
+ */
+ GLuint depth_texture_mode : 2;
+
+ /**
+ * If the sampler is used as a shadow sampler,
+ * this field is (texture_compare_func - GL_NEVER).
+ * [e.g. if compare function is GL_LEQUAL, this field is 3]
+ *
+ * Otherwise, this field is 0.
+ */
+ GLuint texture_compare_func : 3;
+ } unit[16];
};
-/**
- * Store information during compilation of fragment programs.
- */
-struct r300_pfs_compile_state {
- int nrslots; /* number of ALU slots used so far */
-
- /* Track which (parts of) slots are already filled with instructions */
- struct r300_pfs_compile_slot slot[PFS_MAX_ALU_INST];
-
- /* Track the validity of R300 temporaries */
- struct reg_lifetime hwtemps[PFS_NUM_TEMP_REGS];
-
- /* Used to map Mesa's inputs/temps onto hardware temps */
- int temp_in_use;
- struct reg_acc temps[PFS_NUM_TEMP_REGS];
- struct reg_acc inputs[32]; /* don't actually need 32... */
-
- /* Track usage of hardware temps, for register allocation,
- * indirection detection, etc. */
- GLuint used_in_node;
- GLuint dest_in_node;
-};
/**
- * Store everything about a fragment program that is needed
- * to render with that program.
+ * Stores an R300 fragment program in its compiled-to-hardware form.
*/
-struct r300_fragment_program {
- struct gl_fragment_program mesa_program;
-
- GLcontext *ctx;
- GLboolean translated;
- GLboolean error;
- struct r300_pfs_compile_state *cs;
-
+struct r300_fragment_program_code {
struct {
int length;
GLuint inst[PFS_MAX_TEX_INST];
@@ -793,19 +727,51 @@ struct r300_fragment_program {
int const_nr;
int max_temp_idx;
-
- GLboolean WritesDepth;
- GLuint optimization;
};
-struct r500_fragment_program {
+/**
+ * Store everything about a fragment program that is needed
+ * to render with that program.
+ */
+struct r300_fragment_program {
struct gl_fragment_program mesa_program;
- GLcontext *ctx;
GLboolean translated;
GLboolean error;
- struct r300_pfs_compile_state *cs;
+ struct r300_fragment_program_external_state state;
+ struct r300_fragment_program_code code;
+
+ GLboolean WritesDepth;
+ GLuint optimization;
+};
+
+struct r500_pfs_compile_state;
+
+struct r500_fragment_program_external_state {
+ struct {
+ /**
+ * If the sampler is used as a shadow sampler,
+ * this field is:
+ * 0 - GL_LUMINANCE
+ * 1 - GL_INTENSITY
+ * 2 - GL_ALPHA
+ * depending on the depth texture mode.
+ */
+ GLuint depth_texture_mode : 2;
+
+ /**
+ * If the sampler is used as a shadow sampler,
+ * this field is (texture_compare_func - GL_NEVER).
+ * [e.g. if compare function is GL_LEQUAL, this field is 3]
+ *
+ * Otherwise, this field is 0.
+ */
+ GLuint texture_compare_func : 3;
+ } unit[16];
+};
+
+struct r500_fragment_program_code {
struct {
GLuint inst0;
GLuint inst1;
@@ -822,17 +788,28 @@ struct r500_fragment_program {
int inst_end;
/* Hardware constants.
- * Contains a pointer to the value. The destination of the pointer
- * is supposed to be updated when GL state changes.
- * Typically, this is either a pointer into
- * gl_program_parameter_list::ParameterValues, or a pointer to a
- * global constant (e.g. for sin/cos-approximation)
- */
+ * Contains a pointer to the value. The destination of the pointer
+ * is supposed to be updated when GL state changes.
+ * Typically, this is either a pointer into
+ * gl_program_parameter_list::ParameterValues, or a pointer to a
+ * global constant (e.g. for sin/cos-approximation)
+ */
const GLfloat *constant[PFS_NUM_CONST_REGS];
int const_nr;
int max_temp_idx;
+};
+struct r500_fragment_program {
+ struct gl_fragment_program mesa_program;
+
+ GLcontext *ctx;
+ GLboolean translated;
+ GLboolean error;
+
+ struct r500_fragment_program_external_state state;
+ struct r500_fragment_program_code code;
+
GLboolean writes_depth;
GLuint optimization;
@@ -849,7 +826,6 @@ struct r300_state {
struct r300_texture_state texture;
int sw_tcl_inputs[VERT_ATTRIB_MAX];
struct r300_vertex_shader_state vertex_shader;
- struct r300_pfs_compile_state pfs_compile;
struct r300_dma_region aos[R300_MAX_AOS_ARRAYS];
int aos_count;
@@ -949,6 +925,7 @@ struct r300_context {
driTextureObject swapped;
int texture_depth;
float initialMaxAnisotropy;
+ float LODBias;
/* Clientdata textures;
*/
diff --git a/src/mesa/drivers/dri/r300/r300_fragprog.c b/src/mesa/drivers/dri/r300/r300_fragprog.c
index 54b80d20a1..6d24d266fe 100644
--- a/src/mesa/drivers/dri/r300/r300_fragprog.c
+++ b/src/mesa/drivers/dri/r300/r300_fragprog.c
@@ -28,16 +28,14 @@
/**
* \file
*
- * \author Ben Skeggs <darktama@iinet.net.au>
+ * Fragment program compiler. Perform transformations on the intermediate
+ * \ref radeon_program representation (which is essentially the Mesa
+ * program representation plus the notion of clauses) until the program
+ * is in a form where we can translate it more or less directly into
+ * machine-readable form.
*
+ * \author Ben Skeggs <darktama@iinet.net.au>
* \author Jerome Glisse <j.glisse@gmail.com>
- *
- * \todo Depth write, WPOS/FOGC inputs
- *
- * \todo FogOption
- *
- * \todo Verify results of opcodes for accuracy, I've only checked them in
- * specific cases.
*/
#include "glheader.h"
@@ -49,1967 +47,225 @@
#include "r300_context.h"
#include "r300_fragprog.h"
-#include "r300_reg.h"
#include "r300_state.h"
-/*
- * Usefull macros and values
- */
-#define ERROR(fmt, args...) do { \
- fprintf(stderr, "%s::%s(): " fmt "\n", \
- __FILE__, __FUNCTION__, ##args); \
- fp->error = GL_TRUE; \
- } while(0)
-
-#define PFS_INVAL 0xFFFFFFFF
-#define COMPILE_STATE struct r300_pfs_compile_state *cs = fp->cs
-
-#define SWIZZLE_XYZ 0
-#define SWIZZLE_XXX 1
-#define SWIZZLE_YYY 2
-#define SWIZZLE_ZZZ 3
-#define SWIZZLE_WWW 4
-#define SWIZZLE_YZX 5
-#define SWIZZLE_ZXY 6
-#define SWIZZLE_WZY 7
-#define SWIZZLE_111 8
-#define SWIZZLE_000 9
-#define SWIZZLE_HHH 10
-
-#define swizzle(r, x, y, z, w) do_swizzle(fp, r, \
- ((SWIZZLE_##x<<0)| \
- (SWIZZLE_##y<<3)| \
- (SWIZZLE_##z<<6)| \
- (SWIZZLE_##w<<9)), \
- 0)
-
-#define REG_TYPE_INPUT 0
-#define REG_TYPE_OUTPUT 1
-#define REG_TYPE_TEMP 2
-#define REG_TYPE_CONST 3
-
-#define REG_TYPE_SHIFT 0
-#define REG_INDEX_SHIFT 2
-#define REG_VSWZ_SHIFT 8
-#define REG_SSWZ_SHIFT 13
-#define REG_NEGV_SHIFT 18
-#define REG_NEGS_SHIFT 19
-#define REG_ABS_SHIFT 20
-#define REG_NO_USE_SHIFT 21 // Hack for refcounting
-#define REG_VALID_SHIFT 22 // Does the register contain a defined value?
-#define REG_BUILTIN_SHIFT 23 // Is it a builtin (like all zero/all one)?
-
-#define REG_TYPE_MASK (0x03 << REG_TYPE_SHIFT)
-#define REG_INDEX_MASK (0x3F << REG_INDEX_SHIFT)
-#define REG_VSWZ_MASK (0x1F << REG_VSWZ_SHIFT)
-#define REG_SSWZ_MASK (0x1F << REG_SSWZ_SHIFT)
-#define REG_NEGV_MASK (0x01 << REG_NEGV_SHIFT)
-#define REG_NEGS_MASK (0x01 << REG_NEGS_SHIFT)
-#define REG_ABS_MASK (0x01 << REG_ABS_SHIFT)
-#define REG_NO_USE_MASK (0x01 << REG_NO_USE_SHIFT)
-#define REG_VALID_MASK (0x01 << REG_VALID_SHIFT)
-#define REG_BUILTIN_MASK (0x01 << REG_BUILTIN_SHIFT)
-
-#define REG(type, index, vswz, sswz, nouse, valid, builtin) \
- (((type << REG_TYPE_SHIFT) & REG_TYPE_MASK) | \
- ((index << REG_INDEX_SHIFT) & REG_INDEX_MASK) | \
- ((nouse << REG_NO_USE_SHIFT) & REG_NO_USE_MASK) | \
- ((valid << REG_VALID_SHIFT) & REG_VALID_MASK) | \
- ((builtin << REG_BUILTIN_SHIFT) & REG_BUILTIN_MASK) | \
- ((vswz << REG_VSWZ_SHIFT) & REG_VSWZ_MASK) | \
- ((sswz << REG_SSWZ_SHIFT) & REG_SSWZ_MASK))
-#define REG_GET_TYPE(reg) \
- ((reg & REG_TYPE_MASK) >> REG_TYPE_SHIFT)
-#define REG_GET_INDEX(reg) \
- ((reg & REG_INDEX_MASK) >> REG_INDEX_SHIFT)
-#define REG_GET_VSWZ(reg) \
- ((reg & REG_VSWZ_MASK) >> REG_VSWZ_SHIFT)
-#define REG_GET_SSWZ(reg) \
- ((reg & REG_SSWZ_MASK) >> REG_SSWZ_SHIFT)
-#define REG_GET_NO_USE(reg) \
- ((reg & REG_NO_USE_MASK) >> REG_NO_USE_SHIFT)
-#define REG_GET_VALID(reg) \
- ((reg & REG_VALID_MASK) >> REG_VALID_SHIFT)
-#define REG_GET_BUILTIN(reg) \
- ((reg & REG_BUILTIN_MASK) >> REG_BUILTIN_SHIFT)
-#define REG_SET_TYPE(reg, type) \
- reg = ((reg & ~REG_TYPE_MASK) | \
- ((type << REG_TYPE_SHIFT) & REG_TYPE_MASK))
-#define REG_SET_INDEX(reg, index) \
- reg = ((reg & ~REG_INDEX_MASK) | \
- ((index << REG_INDEX_SHIFT) & REG_INDEX_MASK))
-#define REG_SET_VSWZ(reg, vswz) \
- reg = ((reg & ~REG_VSWZ_MASK) | \
- ((vswz << REG_VSWZ_SHIFT) & REG_VSWZ_MASK))
-#define REG_SET_SSWZ(reg, sswz) \
- reg = ((reg & ~REG_SSWZ_MASK) | \
- ((sswz << REG_SSWZ_SHIFT) & REG_SSWZ_MASK))
-#define REG_SET_NO_USE(reg, nouse) \
- reg = ((reg & ~REG_NO_USE_MASK) | \
- ((nouse << REG_NO_USE_SHIFT) & REG_NO_USE_MASK))
-#define REG_SET_VALID(reg, valid) \
- reg = ((reg & ~REG_VALID_MASK) | \
- ((valid << REG_VALID_SHIFT) & REG_VALID_MASK))
-#define REG_SET_BUILTIN(reg, builtin) \
- reg = ((reg & ~REG_BUILTIN_MASK) | \
- ((builtin << REG_BUILTIN_SHIFT) & REG_BUILTIN_MASK))
-#define REG_ABS(reg) \
- reg = (reg | REG_ABS_MASK)
-#define REG_NEGV(reg) \
- reg = (reg | REG_NEGV_MASK)
-#define REG_NEGS(reg) \
- reg = (reg | REG_NEGS_MASK)
-
-/*
- * Datas structures for fragment program generation
- */
-
-/* description of r300 native hw instructions */
-static const struct {
- const char *name;
- int argc;
- int v_op;
- int s_op;
-} r300_fpop[] = {
- /* *INDENT-OFF* */
- {"MAD", 3, R300_ALU_OUTC_MAD, R300_ALU_OUTA_MAD},
- {"DP3", 2, R300_ALU_OUTC_DP3, R300_ALU_OUTA_DP4},
- {"DP4", 2, R300_ALU_OUTC_DP4, R300_ALU_OUTA_DP4},
- {"MIN", 2, R300_ALU_OUTC_MIN, R300_ALU_OUTA_MIN},
- {"MAX", 2, R300_ALU_OUTC_MAX, R300_ALU_OUTA_MAX},
- {"CMP", 3, R300_ALU_OUTC_CMP, R300_ALU_OUTA_CMP},
- {"FRC", 1, R300_ALU_OUTC_FRC, R300_ALU_OUTA_FRC},
- {"EX2", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_EX2},
- {"LG2", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_LG2},
- {"RCP", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_RCP},
- {"RSQ", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_RSQ},
- {"REPL_ALPHA", 1, R300_ALU_OUTC_REPL_ALPHA, PFS_INVAL},
- {"CMPH", 3, R300_ALU_OUTC_CMPH, PFS_INVAL},
- /* *INDENT-ON* */
-};
-
-/* vector swizzles r300 can support natively, with a couple of
- * cases we handle specially
- *
- * REG_VSWZ/REG_SSWZ is an index into this table
- */
-
-/* mapping from SWIZZLE_* to r300 native values for scalar insns */
-#define SWIZZLE_HALF 6
-
-#define MAKE_SWZ3(x, y, z) (MAKE_SWIZZLE4(SWIZZLE_##x, \
- SWIZZLE_##y, \
- SWIZZLE_##z, \
- SWIZZLE_ZERO))
-/* native swizzles */
-static const struct r300_pfs_swizzle {
- GLuint hash; /* swizzle value this matches */
- GLuint base; /* base value for hw swizzle */
- GLuint stride; /* difference in base between arg0/1/2 */
- GLuint flags;
-} v_swiz[] = {
- /* *INDENT-OFF* */
- {MAKE_SWZ3(X, Y, Z), R300_ALU_ARGC_SRC0C_XYZ, 4, SLOT_SRC_VECTOR},
- {MAKE_SWZ3(X, X, X), R300_ALU_ARGC_SRC0C_XXX, 4, SLOT_SRC_VECTOR},
- {MAKE_SWZ3(Y, Y, Y), R300_ALU_ARGC_SRC0C_YYY, 4, SLOT_SRC_VECTOR},
- {MAKE_SWZ3(Z, Z, Z), R300_ALU_ARGC_SRC0C_ZZZ, 4, SLOT_SRC_VECTOR},
- {MAKE_SWZ3(W, W, W), R300_ALU_ARGC_SRC0A, 1, SLOT_SRC_SCALAR},
- {MAKE_SWZ3(Y, Z, X), R300_ALU_ARGC_SRC0C_YZX, 1, SLOT_SRC_VECTOR},
- {MAKE_SWZ3(Z, X, Y), R300_ALU_ARGC_SRC0C_ZXY, 1, SLOT_SRC_VECTOR},
- {MAKE_SWZ3(W, Z, Y), R300_ALU_ARGC_SRC0CA_WZY, 1, SLOT_SRC_BOTH},
- {MAKE_SWZ3(ONE, ONE, ONE), R300_ALU_ARGC_ONE, 0, 0},
- {MAKE_SWZ3(ZERO, ZERO, ZERO), R300_ALU_ARGC_ZERO, 0, 0},
- {MAKE_SWZ3(HALF, HALF, HALF), R300_ALU_ARGC_HALF, 0, 0},
- {PFS_INVAL, 0, 0, 0},
- /* *INDENT-ON* */
-};
-
-/* used during matching of non-native swizzles */
-#define SWZ_X_MASK (7 << 0)
-#define SWZ_Y_MASK (7 << 3)
-#define SWZ_Z_MASK (7 << 6)
-#define SWZ_W_MASK (7 << 9)
-static const struct {
- GLuint hash; /* used to mask matching swizzle components */
- int mask; /* actual outmask */
- int count; /* count of components matched */
-} s_mask[] = {
- /* *INDENT-OFF* */
- {SWZ_X_MASK | SWZ_Y_MASK | SWZ_Z_MASK, 1 | 2 | 4, 3},
- {SWZ_X_MASK | SWZ_Y_MASK, 1 | 2, 2},
- {SWZ_X_MASK | SWZ_Z_MASK, 1 | 4, 2},
- {SWZ_Y_MASK | SWZ_Z_MASK, 2 | 4, 2},
- {SWZ_X_MASK, 1, 1},
- {SWZ_Y_MASK, 2, 1},
- {SWZ_Z_MASK, 4, 1},
- {PFS_INVAL, PFS_INVAL, PFS_INVAL}
- /* *INDENT-ON* */
-};
-
-static const struct {
- int base; /* hw value of swizzle */
- int stride; /* difference between SRC0/1/2 */
- GLuint flags;
-} s_swiz[] = {
- /* *INDENT-OFF* */
- {R300_ALU_ARGA_SRC0C_X, 3, SLOT_SRC_VECTOR},
- {R300_ALU_ARGA_SRC0C_Y, 3, SLOT_SRC_VECTOR},
- {R300_ALU_ARGA_SRC0C_Z, 3, SLOT_SRC_VECTOR},
- {R300_ALU_ARGA_SRC0A, 1, SLOT_SRC_SCALAR},
- {R300_ALU_ARGA_ZERO, 0, 0},
- {R300_ALU_ARGA_ONE, 0, 0},
- {R300_ALU_ARGA_HALF, 0, 0}
- /* *INDENT-ON* */
-};
-
-/* boiler-plate reg, for convenience */
-static const GLuint undef = REG(REG_TYPE_TEMP,
- 0,
- SWIZZLE_XYZ,
- SWIZZLE_W,
- GL_FALSE,
- GL_FALSE,
- GL_FALSE);
-
-/* constant one source */
-static const GLuint pfs_one = REG(REG_TYPE_CONST,
- 0,
- SWIZZLE_111,
- SWIZZLE_ONE,
- GL_FALSE,
- GL_TRUE,
- GL_TRUE);
-
-/* constant half source */
-static const GLuint pfs_half = REG(REG_TYPE_CONST,
- 0,
- SWIZZLE_HHH,
- SWIZZLE_HALF,
- GL_FALSE,
- GL_TRUE,
- GL_TRUE);
-
-/* constant zero source */
-static const GLuint pfs_zero = REG(REG_TYPE_CONST,
- 0,
- SWIZZLE_000,
- SWIZZLE_ZERO,
- GL_FALSE,
- GL_TRUE,
- GL_TRUE);
+#include "radeon_program_alu.h"
-/*
- * Common functions prototypes
- */
-static void dump_program(struct r300_fragment_program *fp);
-static void emit_arith(struct r300_fragment_program *fp, int op,
- GLuint dest, int mask,
- GLuint src0, GLuint src1, GLuint src2, int flags);
-/**
- * Get an R300 temporary that can be written to in the given slot.
- */
-static int get_hw_temp(struct r300_fragment_program *fp, int slot)
+static void reset_srcreg(struct prog_src_register* reg)
{
- COMPILE_STATE;
- int r;
-
- for (r = 0; r < PFS_NUM_TEMP_REGS; ++r) {
- if (cs->hwtemps[r].free >= 0 && cs->hwtemps[r].free <= slot)
- break;
- }
-
- if (r >= PFS_NUM_TEMP_REGS) {
- ERROR("Out of hardware temps\n");
- return 0;
- }
- // Reserved is used to avoid the following scenario:
- // R300 temporary X is first assigned to Mesa temporary Y during vector ops
- // R300 temporary X is then assigned to Mesa temporary Z for further vector ops
- // Then scalar ops on Mesa temporary Z are emitted and move back in time
- // to overwrite the value of temporary Y.
- // End scenario.
- cs->hwtemps[r].reserved = cs->hwtemps[r].free;
- cs->hwtemps[r].free = -1;
-
- // Reset to some value that won't mess things up when the user
- // tries to read from a temporary that hasn't been assigned a value yet.
- // In the normal case, vector_valid and scalar_valid should be set to
- // a sane value by the first emit that writes to this temporary.
- cs->hwtemps[r].vector_valid = 0;
- cs->hwtemps[r].scalar_valid = 0;
-
- if (r > fp->max_temp_idx)
- fp->max_temp_idx = r;
-
- return r;
+ _mesa_bzero(reg, sizeof(*reg));
+ reg->Swizzle = SWIZZLE_NOOP;
}
/**
- * Get an R300 temporary that will act as a TEX destination register.
- */
-static int get_hw_temp_tex(struct r300_fragment_program *fp)
-{
- COMPILE_STATE;
- int r;
-
- for (r = 0; r < PFS_NUM_TEMP_REGS; ++r) {
- if (cs->used_in_node & (1 << r))
- continue;
-
- // Note: Be very careful here
- if (cs->hwtemps[r].free >= 0 && cs->hwtemps[r].free <= 0)
- break;
- }
-
- if (r >= PFS_NUM_TEMP_REGS)
- return get_hw_temp(fp, 0); /* Will cause an indirection */
-
- cs->hwtemps[r].reserved = cs->hwtemps[r].free;
- cs->hwtemps[r].free = -1;
-
- // Reset to some value that won't mess things up when the user
- // tries to read from a temporary that hasn't been assigned a value yet.
- // In the normal case, vector_valid and scalar_valid should be set to
- // a sane value by the first emit that writes to this temporary.
- cs->hwtemps[r].vector_valid = cs->nrslots;
- cs->hwtemps[r].scalar_valid = cs->nrslots;
-
- if (r > fp->max_temp_idx)
- fp->max_temp_idx = r;
-
- return r;
-}
-
-/**
- * Mark the given hardware register as free.
- */
-static void free_hw_temp(struct r300_fragment_program *fp, int idx)
-{
- COMPILE_STATE;
-
- // Be very careful here. Consider sequences like
- // MAD r0, r1,r2,r3
- // TEX r4, ...
- // The TEX instruction may be moved in front of the MAD instruction
- // due to the way nodes work. We don't want to alias r1 and r4 in
- // this case.
- // I'm certain the register allocation could be further sanitized,
- // but it's tricky because of stuff that can happen inside emit_tex
- // and emit_arith.
- cs->hwtemps[idx].free = cs->nrslots + 1;
-}
-
-/**
- * Create a new Mesa temporary register.
- */
-static GLuint get_temp_reg(struct r300_fragment_program *fp)
-{
- COMPILE_STATE;
- GLuint r = undef;
- GLuint index;
-
- index = ffs(~cs->temp_in_use);
- if (!index) {
- ERROR("Out of program temps\n");
- return r;
- }
-
- cs->temp_in_use |= (1 << --index);
- cs->temps[index].refcount = 0xFFFFFFFF;
- cs->temps[index].reg = -1;
-
- REG_SET_TYPE(r, REG_TYPE_TEMP);
- REG_SET_INDEX(r, index);
- REG_SET_VALID(r, GL_TRUE);
- return r;
-}
-
-/**
- * Create a new Mesa temporary register that will act as the destination
- * register for a texture read.
- */
-static GLuint get_temp_reg_tex(struct r300_fragment_program *fp)
-{
- COMPILE_STATE;
- GLuint r = undef;
- GLuint index;
-
- index = ffs(~cs->temp_in_use);
- if (!index) {
- ERROR("Out of program temps\n");
- return r;
- }
-
- cs->temp_in_use |= (1 << --index);
- cs->temps[index].refcount = 0xFFFFFFFF;
- cs->temps[index].reg = get_hw_temp_tex(fp);
-
- REG_SET_TYPE(r, REG_TYPE_TEMP);
- REG_SET_INDEX(r, index);
- REG_SET_VALID(r, GL_TRUE);
- return r;
-}
-
-/**
- * Free a Mesa temporary and the associated R300 temporary.
- */
-static void free_temp(struct r300_fragment_program *fp, GLuint r)
-{
- COMPILE_STATE;
- GLuint index = REG_GET_INDEX(r);
-
- if (!(cs->temp_in_use & (1 << index)))
- return;
-
- if (REG_GET_TYPE(r) == REG_TYPE_TEMP) {
- free_hw_temp(fp, cs->temps[index].reg);
- cs->temps[index].reg = -1;
- cs->temp_in_use &= ~(1 << index);
- } else if (REG_GET_TYPE(r) == REG_TYPE_INPUT) {
- free_hw_temp(fp, cs->inputs[index].reg);
- cs->inputs[index].reg = -1;
- }
-}
-
-/**
- * Emit a hardware constant/parameter.
+ * Transform TEX, TXP, TXB, and KIL instructions in the following way:
+ * - premultiply texture coordinates for RECT
+ * - extract operand swizzles
+ * - introduce a temporary register when write masks are needed
*
- * \p cp Stable pointer to an array of 4 floats.
- * The pointer must be stable in the sense that it remains to be valid
- * and hold the contents of the constant/parameter throughout the lifetime
- * of the fragment program (actually, up until the next time the fragment
- * program is translated).
+ * \todo If/when r5xx uses the radeon_program architecture, this can probably
+ * be reused.
*/
-static GLuint emit_const4fv(struct r300_fragment_program *fp,
- const GLfloat * cp)
-{
- GLuint reg = undef;
- int index;
-
- for (index = 0; index < fp->const_nr; ++index) {
- if (fp->constant[index] == cp)
- break;
- }
-
- if (index >= fp->const_nr) {
- if (index >= PFS_NUM_CONST_REGS) {
- ERROR("Out of hw constants!\n");
- return reg;
- }
-
- fp->const_nr++;
- fp->constant[index] = cp;
- }
-
- REG_SET_TYPE(reg, REG_TYPE_CONST);
- REG_SET_INDEX(reg, index);
- REG_SET_VALID(reg, GL_TRUE);
- return reg;
-}
-
-static inline GLuint negate(GLuint r)
-{
- REG_NEGS(r);
- REG_NEGV(r);
- return r;
-}
-
-/* Hack, to prevent clobbering sources used multiple times when
- * emulating non-native instructions
- */
-static inline GLuint keep(GLuint r)
-{
- REG_SET_NO_USE(r, GL_TRUE);
- return r;
-}
-
-static inline GLuint absolute(GLuint r)
-{
- REG_ABS(r);
- return r;
-}
-
-static int swz_native(struct r300_fragment_program *fp,
- GLuint src, GLuint * r, GLuint arbneg)
+static GLboolean transform_TEX(
+ struct radeon_program_transform_context* context,
+ struct prog_instruction* orig_inst, void* data)
{
- /* Native swizzle, handle negation */
- src = (src & ~REG_NEGS_MASK) | (((arbneg >> 3) & 1) << REG_NEGS_SHIFT);
-
- if ((arbneg & 0x7) == 0x0) {
- src = src & ~REG_NEGV_MASK;
- *r = src;
- } else if ((arbneg & 0x7) == 0x7) {
- src |= REG_NEGV_MASK;
- *r = src;
- } else {
- if (!REG_GET_VALID(*r))
- *r = get_temp_reg(fp);
- src |= REG_NEGV_MASK;
- emit_arith(fp,
- PFS_OP_MAD,
- *r, arbneg & 0x7, keep(src), pfs_one, pfs_zero, 0);
- src = src & ~REG_NEGV_MASK;
- emit_arith(fp,
- PFS_OP_MAD,
- *r,
- (arbneg ^ 0x7) | WRITEMASK_W,
- src, pfs_one, pfs_zero, 0);
- }
-
- return 3;
-}
-
-static int swz_emit_partial(struct r300_fragment_program *fp,
- GLuint src,
- GLuint * r, int mask, int mc, GLuint arbneg)
-{
- GLuint tmp;
- GLuint wmask = 0;
-
- if (!REG_GET_VALID(*r))
- *r = get_temp_reg(fp);
-
- /* A partial match, VSWZ/mask define what parts of the
- * desired swizzle we match
- */
- if (mc + s_mask[mask].count == 3) {
- wmask = WRITEMASK_W;
- src |= ((arbneg >> 3) & 1) << REG_NEGS_SHIFT;
- }
-
- tmp = arbneg & s_mask[mask].mask;
- if (tmp) {
- tmp = tmp ^ s_mask[mask].mask;
- if (tmp) {
- emit_arith(fp,
- PFS_OP_MAD,
- *r,
- arbneg & s_mask[mask].mask,
- keep(src) | REG_NEGV_MASK,
- pfs_one, pfs_zero, 0);
- if (!wmask) {
- REG_SET_NO_USE(src, GL_TRUE);
- } else {
- REG_SET_NO_USE(src, GL_FALSE);
- }
- emit_arith(fp,
- PFS_OP_MAD,
- *r, tmp | wmask, src, pfs_one, pfs_zero, 0);
- } else {
- if (!wmask) {
- REG_SET_NO_USE(src, GL_TRUE);
- } else {
- REG_SET_NO_USE(src, GL_FALSE);
- }
- emit_arith(fp,
- PFS_OP_MAD,
- *r,
- (arbneg & s_mask[mask].mask) | wmask,
- src | REG_NEGV_MASK, pfs_one, pfs_zero, 0);
- }
- } else {
- if (!wmask) {
- REG_SET_NO_USE(src, GL_TRUE);
- } else {
- REG_SET_NO_USE(src, GL_FALSE);
- }
- emit_arith(fp, PFS_OP_MAD,
- *r,
- s_mask[mask].mask | wmask,
- src, pfs_one, pfs_zero, 0);
- }
-
- return s_mask[mask].count;
-}
-
-static GLuint do_swizzle(struct r300_fragment_program *fp,
- GLuint src, GLuint arbswz, GLuint arbneg)
-{
- GLuint r = undef;
- GLuint vswz;
- int c_mask = 0;
- int v_match = 0;
-
- /* If swizzling from something without an XYZW native swizzle,
- * emit result to a temp, and do new swizzle from the temp.
- */
-#if 0
- if (REG_GET_VSWZ(src) != SWIZZLE_XYZ || REG_GET_SSWZ(src) != SWIZZLE_W) {
- GLuint temp = get_temp_reg(fp);
- emit_arith(fp,
- PFS_OP_MAD,
- temp, WRITEMASK_XYZW, src, pfs_one, pfs_zero, 0);
- src = temp;
- }
-#endif
-
- if (REG_GET_VSWZ(src) != SWIZZLE_XYZ || REG_GET_SSWZ(src) != SWIZZLE_W) {
- GLuint vsrcswz =
- (v_swiz[REG_GET_VSWZ(src)].
- hash & (SWZ_X_MASK | SWZ_Y_MASK | SWZ_Z_MASK)) |
- REG_GET_SSWZ(src) << 9;
- GLint i;
-
- GLuint newswz = 0;
- GLuint offset;
- for (i = 0; i < 4; ++i) {
- offset = GET_SWZ(arbswz, i);
-
- newswz |=
- (offset <= 3) ? GET_SWZ(vsrcswz,
- offset) << i *
- 3 : offset << i * 3;
- }
-
- arbswz = newswz & (SWZ_X_MASK | SWZ_Y_MASK | SWZ_Z_MASK);
- REG_SET_SSWZ(src, GET_SWZ(newswz, 3));
- } else {
- /* set scalar swizzling */
- REG_SET_SSWZ(src, GET_SWZ(arbswz, 3));
-
- }
- do {
- vswz = REG_GET_VSWZ(src);
- do {
- int chash;
-
- REG_SET_VSWZ(src, vswz);
- chash = v_swiz[REG_GET_VSWZ(src)].hash &
- s_mask[c_mask].hash;
-
- if (chash == (arbswz & s_mask[c_mask].hash)) {
- if (s_mask[c_mask].count == 3) {
- v_match += swz_native(fp,
- src, &r, arbneg);
- } else {
- v_match += swz_emit_partial(fp,
- src,
- &r,
- c_mask,
- v_match,
- arbneg);
- }
-
- if (v_match == 3)
- return r;
-
- /* Fill with something invalid.. all 0's was
- * wrong before, matched SWIZZLE_X. So all
- * 1's will be okay for now
- */
- arbswz |= (PFS_INVAL & s_mask[c_mask].hash);
- }
- } while (v_swiz[++vswz].hash != PFS_INVAL);
- REG_SET_VSWZ(src, SWIZZLE_XYZ);
- } while (s_mask[++c_mask].hash != PFS_INVAL);
-
- ERROR("should NEVER get here\n");
- return r;
-}
-
-static GLuint t_src(struct r300_fragment_program *fp,
- struct prog_src_register fpsrc)
-{
- GLuint r = undef;
-
- switch (fpsrc.File) {
- case PROGRAM_TEMPORARY:
- REG_SET_INDEX(r, fpsrc.Index);
- REG_SET_VALID(r, GL_TRUE);
- REG_SET_TYPE(r, REG_TYPE_TEMP);
- break;
- case PROGRAM_INPUT:
- REG_SET_INDEX(r, fpsrc.Index);
- REG_SET_VALID(r, GL_TRUE);
- REG_SET_TYPE(r, REG_TYPE_INPUT);
- break;
- case PROGRAM_LOCAL_PARAM:
- r = emit_const4fv(fp,
- fp->mesa_program.Base.LocalParams[fpsrc.
- Index]);
- break;
- case PROGRAM_ENV_PARAM:
- r = emit_const4fv(fp,
- fp->ctx->FragmentProgram.Parameters[fpsrc.
- Index]);
- break;
- case PROGRAM_STATE_VAR:
- case PROGRAM_NAMED_PARAM:
- case PROGRAM_CONSTANT:
- r = emit_const4fv(fp,
- fp->mesa_program.Base.Parameters->
- ParameterValues[fpsrc.Index]);
- break;
- default:
- ERROR("unknown SrcReg->File %x\n", fpsrc.File);
- return r;
- }
-
- /* no point swizzling ONE/ZERO/HALF constants... */
- if (REG_GET_VSWZ(r) < SWIZZLE_111 || REG_GET_SSWZ(r) < SWIZZLE_ZERO)
- r = do_swizzle(fp, r, fpsrc.Swizzle, fpsrc.NegateBase);
- return r;
-}
-
-static GLuint t_scalar_src(struct r300_fragment_program *fp,
- struct prog_src_register fpsrc)
-{
- struct prog_src_register src = fpsrc;
- int sc = GET_SWZ(fpsrc.Swizzle, 0); /* X */
-
- src.Swizzle = ((sc << 0) | (sc << 3) | (sc << 6) | (sc << 9));
-
- return t_src(fp, src);
-}
-
-static GLuint t_dst(struct r300_fragment_program *fp,
- struct prog_dst_register dest)
-{
- GLuint r = undef;
-
- switch (dest.File) {
- case PROGRAM_TEMPORARY:
- REG_SET_INDEX(r, dest.Index);
- REG_SET_VALID(r, GL_TRUE);
- REG_SET_TYPE(r, REG_TYPE_TEMP);
- return r;
- case PROGRAM_OUTPUT:
- REG_SET_TYPE(r, REG_TYPE_OUTPUT);
- switch (dest.Index) {
- case FRAG_RESULT_COLR:
- case FRAG_RESULT_DEPR:
- REG_SET_INDEX(r, dest.Index);
- REG_SET_VALID(r, GL_TRUE);
- return r;
- default:
- ERROR("Bad DstReg->Index 0x%x\n", dest.Index);
- return r;
- }
- default:
- ERROR("Bad DstReg->File 0x%x\n", dest.File);
- return r;
- }
-}
-
-static int t_hw_src(struct r300_fragment_program *fp, GLuint src, GLboolean tex)
-{
- COMPILE_STATE;
- int idx;
- int index = REG_GET_INDEX(src);
-
- switch (REG_GET_TYPE(src)) {
- case REG_TYPE_TEMP:
- /* NOTE: if reg==-1 here, a source is being read that
- * hasn't been written to. Undefined results.
- */
- if (cs->temps[index].reg == -1)
- cs->temps[index].reg = get_hw_temp(fp, cs->nrslots);
-
- idx = cs->temps[index].reg;
-
- if (!REG_GET_NO_USE(src) && (--cs->temps[index].refcount == 0))
- free_temp(fp, src);
- break;
- case REG_TYPE_INPUT:
- idx = cs->inputs[index].reg;
-
- if (!REG_GET_NO_USE(src) && (--cs->inputs[index].refcount == 0))
- free_hw_temp(fp, cs->inputs[index].reg);
- break;
- case REG_TYPE_CONST:
- return (index | SRC_CONST);
- default:
- ERROR("Invalid type for source reg\n");
- return (0 | SRC_CONST);
- }
+ struct r300_fragment_program_compiler *compiler =
+ (struct r300_fragment_program_compiler*)data;
+ struct prog_instruction inst = *orig_inst;
+ struct prog_instruction* tgt;
+ GLboolean destredirect = GL_FALSE;
+
+ if (inst.Opcode != OPCODE_TEX &&
+ inst.Opcode != OPCODE_TXB &&
+ inst.Opcode != OPCODE_TXP &&
+ inst.Opcode != OPCODE_KIL)
+ return GL_FALSE;
- if (!tex)
- cs->used_in_node |= (1 << idx);
+ if (inst.Opcode != OPCODE_KIL &&
+ compiler->fp->mesa_program.Base.ShadowSamplers & (1 << inst.TexSrcUnit)) {
+ GLuint comparefunc = GL_NEVER + compiler->fp->state.unit[inst.TexSrcUnit].texture_compare_func;
- return idx;
-}
+ if (comparefunc == GL_NEVER || comparefunc == GL_ALWAYS) {
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
-static int t_hw_dst(struct r300_fragment_program *fp,
- GLuint dest, GLboolean tex, int slot)
-{
- COMPILE_STATE;
- int idx;
- GLuint index = REG_GET_INDEX(dest);
- assert(REG_GET_VALID(dest));
-
- switch (REG_GET_TYPE(dest)) {
- case REG_TYPE_TEMP:
- if (cs->temps[REG_GET_INDEX(dest)].reg == -1) {
- if (!tex) {
- cs->temps[index].reg = get_hw_temp(fp, slot);
- } else {
- cs->temps[index].reg = get_hw_temp_tex(fp);
- }
- }
- idx = cs->temps[index].reg;
-
- if (!REG_GET_NO_USE(dest) && (--cs->temps[index].refcount == 0))
- free_temp(fp, dest);
-
- cs->dest_in_node |= (1 << idx);
- cs->used_in_node |= (1 << idx);
- break;
- case REG_TYPE_OUTPUT:
- switch (index) {
- case FRAG_RESULT_COLR:
- fp->node[fp->cur_node].flags |=
- R300_RGBA_OUT;
- break;
- case FRAG_RESULT_DEPR:
- fp->WritesDepth = GL_TRUE;
- fp->node[fp->cur_node].flags |=
- R300_W_OUT;
- break;
+ tgt->Opcode = OPCODE_MOV;
+ tgt->DstReg = inst.DstReg;
+ tgt->SrcReg[0].File = PROGRAM_BUILTIN;
+ tgt->SrcReg[0].Swizzle = comparefunc == GL_ALWAYS ? SWIZZLE_1111 : SWIZZLE_0000;
+ return GL_TRUE;
}
- return index;
- break;
- default:
- ERROR("invalid dest reg type %d\n", REG_GET_TYPE(dest));
- return 0;
- }
-
- return idx;
-}
-
-static void emit_nop(struct r300_fragment_program *fp)
-{
- COMPILE_STATE;
- if (cs->nrslots >= PFS_MAX_ALU_INST) {
- ERROR("Out of ALU instruction slots\n");
- return;
+ inst.DstReg.File = PROGRAM_TEMPORARY;
+ inst.DstReg.Index = radeonCompilerAllocateTemporary(context->compiler);
+ inst.DstReg.WriteMask = WRITEMASK_XYZW;
}
- fp->alu.inst[cs->nrslots].inst0 = NOP_INST0;
- fp->alu.inst[cs->nrslots].inst1 = NOP_INST1;
- fp->alu.inst[cs->nrslots].inst2 = NOP_INST2;
- fp->alu.inst[cs->nrslots].inst3 = NOP_INST3;
- cs->nrslots++;
-}
-static void emit_tex(struct r300_fragment_program *fp,
- struct prog_instruction *fpi, int opcode)
-{
- COMPILE_STATE;
- GLuint coord = t_src(fp, fpi->SrcReg[0]);
- GLuint dest = undef, rdest = undef;
- GLuint din, uin;
- int unit = fpi->TexSrcUnit;
- int hwsrc, hwdest;
- GLuint tempreg = 0;
-
- /**
- * Hardware uses [0..1]x[0..1] range for rectangle textures
+ /* Hardware uses [0..1]x[0..1] range for rectangle textures
* instead of [0..Width]x[0..Height].
* Add a scaling instruction.
- *
- * \todo Refactor this once we have proper rewriting/optimization
- * support for programs.
*/
- if (opcode != R300_TEX_OP_KIL && fpi->TexSrcTarget == TEXTURE_RECT_INDEX) {
+ if (inst.Opcode != OPCODE_KIL && inst.TexSrcTarget == TEXTURE_RECT_INDEX) {
gl_state_index tokens[STATE_LENGTH] = {
STATE_INTERNAL, STATE_R300_TEXRECT_FACTOR, 0, 0,
0
};
+
+ int tempreg = radeonCompilerAllocateTemporary(context->compiler);
int factor_index;
- GLuint factorreg;
- tokens[2] = unit;
+ tokens[2] = inst.TexSrcUnit;
factor_index =
- _mesa_add_state_reference(fp->mesa_program.Base.
- Parameters, tokens);
- factorreg =
- emit_const4fv(fp,
- fp->mesa_program.Base.Parameters->
- ParameterValues[factor_index]);
- tempreg = keep(get_temp_reg(fp));
-
- emit_arith(fp, PFS_OP_MAD, tempreg, WRITEMASK_XYZW,
- coord, factorreg, pfs_zero, 0);
-
- coord = tempreg;
- }
+ _mesa_add_state_reference(
+ compiler->fp->mesa_program.Base.Parameters, tokens);
- /* Texture operations do not support swizzles etc. in hardware,
- * so emit an additional arithmetic operation if necessary.
- */
- if (REG_GET_VSWZ(coord) != SWIZZLE_XYZ ||
- REG_GET_SSWZ(coord) != SWIZZLE_W ||
- coord & (REG_NEGV_MASK | REG_NEGS_MASK | REG_ABS_MASK)) {
- assert(tempreg == 0);
- tempreg = keep(get_temp_reg(fp));
- emit_arith(fp, PFS_OP_MAD, tempreg, WRITEMASK_XYZW,
- coord, pfs_one, pfs_zero, 0);
- coord = tempreg;
- }
-
- /* Ensure correct node indirection */
- uin = cs->used_in_node;
- din = cs->dest_in_node;
-
- /* Resolve source/dest to hardware registers */
- hwsrc = t_hw_src(fp, coord, GL_TRUE);
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
- if (opcode != R300_TEX_OP_KIL) {
- dest = t_dst(fp, fpi->DstReg);
+ tgt->Opcode = OPCODE_MUL;
+ tgt->DstReg.File = PROGRAM_TEMPORARY;
+ tgt->DstReg.Index = tempreg;
+ tgt->SrcReg[0] = inst.SrcReg[0];
+ tgt->SrcReg[1].File = PROGRAM_STATE_VAR;
+ tgt->SrcReg[1].Index = factor_index;
- /* r300 doesn't seem to be able to do TEX->output reg */
- if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
- rdest = dest;
- dest = get_temp_reg_tex(fp);
- } else if (fpi->DstReg.WriteMask != WRITEMASK_XYZW) {
- /* in case write mask isn't XYZW */
- rdest = dest;
- dest = get_temp_reg_tex(fp);
- }
- hwdest =
- t_hw_dst(fp, dest, GL_TRUE,
- fp->node[fp->cur_node].alu_offset);
-
- /* Use a temp that hasn't been used in this node, rather
- * than causing an indirection
- */
- if (uin & (1 << hwdest)) {
- free_hw_temp(fp, hwdest);
- hwdest = get_hw_temp_tex(fp);
- cs->temps[REG_GET_INDEX(dest)].reg = hwdest;
- }
- } else {
- hwdest = 0;
- unit = 0;
+ reset_srcreg(&inst.SrcReg[0]);
+ inst.SrcReg[0].File = PROGRAM_TEMPORARY;
+ inst.SrcReg[0].Index = tempreg;
}
- /* Indirection if source has been written in this node, or if the
- * dest has been read/written in this node
+ /* Texture operations do not support swizzles etc. in hardware,
+ * so emit an additional arithmetic operation if necessary.
*/
- if ((REG_GET_TYPE(coord) != REG_TYPE_CONST &&
- (din & (1 << hwsrc))) || (uin & (1 << hwdest))) {
-
- /* Finish off current node */
- if (fp->node[fp->cur_node].alu_offset == cs->nrslots)
- emit_nop(fp);
-
- fp->node[fp->cur_node].alu_end =
- cs->nrslots - fp->node[fp->cur_node].alu_offset - 1;
- assert(fp->node[fp->cur_node].alu_end >= 0);
-
- if (++fp->cur_node >= PFS_MAX_TEX_INDIRECT) {
- ERROR("too many levels of texture indirection\n");
- return;
- }
-
- /* Start new node */
- fp->node[fp->cur_node].tex_offset = fp->tex.length;
- fp->node[fp->cur_node].alu_offset = cs->nrslots;
- fp->node[fp->cur_node].tex_end = -1;
- fp->node[fp->cur_node].alu_end = -1;
- fp->node[fp->cur_node].flags = 0;
- cs->used_in_node = 0;
- cs->dest_in_node = 0;
- }
-
- if (fp->cur_node == 0)
- fp->first_node_has_tex = 1;
-
- fp->tex.inst[fp->tex.length++] = 0 | (hwsrc << R300_SRC_ADDR_SHIFT)
- | (hwdest << R300_DST_ADDR_SHIFT)
- | (unit << R300_TEX_ID_SHIFT)
- | (opcode << R300_TEX_INST_SHIFT);
-
- cs->dest_in_node |= (1 << hwdest);
- if (REG_GET_TYPE(coord) != REG_TYPE_CONST)
- cs->used_in_node |= (1 << hwsrc);
+ if (inst.SrcReg[0].Swizzle != SWIZZLE_NOOP ||
+ inst.SrcReg[0].Abs || inst.SrcReg[0].NegateBase || inst.SrcReg[0].NegateAbs) {
+ int tempreg = radeonCompilerAllocateTemporary(context->compiler);
- fp->node[fp->cur_node].tex_end++;
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
- /* Copy from temp to output if needed */
- if (REG_GET_VALID(rdest)) {
- emit_arith(fp, PFS_OP_MAD, rdest, fpi->DstReg.WriteMask, dest,
- pfs_one, pfs_zero, 0);
- free_temp(fp, dest);
- }
-
- /* Free temp register */
- if (tempreg != 0)
- free_temp(fp, tempreg);
-}
-
-/**
- * Returns the first slot where we could possibly allow writing to dest,
- * according to register allocation.
- */
-static int get_earliest_allowed_write(struct r300_fragment_program *fp,
- GLuint dest, int mask)
-{
- COMPILE_STATE;
- int idx;
- int pos;
- GLuint index = REG_GET_INDEX(dest);
- assert(REG_GET_VALID(dest));
-
- switch (REG_GET_TYPE(dest)) {
- case REG_TYPE_TEMP:
- if (cs->temps[index].reg == -1)
- return 0;
-
- idx = cs->temps[index].reg;
- break;
- case REG_TYPE_OUTPUT:
- return 0;
- default:
- ERROR("invalid dest reg type %d\n", REG_GET_TYPE(dest));
- return 0;
- }
+ tgt->Opcode = OPCODE_MOV;
+ tgt->DstReg.File = PROGRAM_TEMPORARY;
+ tgt->DstReg.Index = tempreg;
+ tgt->SrcReg[0] = inst.SrcReg[0];
- pos = cs->hwtemps[idx].reserved;
- if (mask & WRITEMASK_XYZ) {
- if (pos < cs->hwtemps[idx].vector_lastread)
- pos = cs->hwtemps[idx].vector_lastread;
- }
- if (mask & WRITEMASK_W) {
- if (pos < cs->hwtemps[idx].scalar_lastread)
- pos = cs->hwtemps[idx].scalar_lastread;
+ reset_srcreg(&inst.SrcReg[0]);
+ inst.SrcReg[0].File = PROGRAM_TEMPORARY;
+ inst.SrcReg[0].Index = tempreg;
}
- return pos;
-}
+ if (inst.Opcode != OPCODE_KIL) {
+ if (inst.DstReg.File != PROGRAM_TEMPORARY ||
+ inst.DstReg.WriteMask != WRITEMASK_XYZW) {
+ int tempreg = radeonCompilerAllocateTemporary(context->compiler);
-/**
- * Allocates a slot for an ALU instruction that can consist of
- * a vertex part or a scalar part or both.
- *
- * Sources from src (src[0] to src[argc-1]) are added to the slot in the
- * appropriate position (vector and/or scalar), and their positions are
- * recorded in the srcpos array.
- *
- * This function emits instruction code for the source fetch and the
- * argument selection. It does not emit instruction code for the
- * opcode or the destination selection.
- *
- * @return the index of the slot
- */
-static int find_and_prepare_slot(struct r300_fragment_program *fp,
- GLboolean emit_vop,
- GLboolean emit_sop,
- int argc, GLuint * src, GLuint dest, int mask)
-{
- COMPILE_STATE;
- int hwsrc[3];
- int srcpos[3];
- unsigned int used;
- int tempused;
- int tempvsrc[3];
- int tempssrc[3];
- int pos;
- int regnr;
- int i, j;
-
- // Determine instruction slots, whether sources are required on
- // vector or scalar side, and the smallest slot number where
- // all source registers are available
- used = 0;
- if (emit_vop)
- used |= SLOT_OP_VECTOR;
- if (emit_sop)
- used |= SLOT_OP_SCALAR;
-
- pos = get_earliest_allowed_write(fp, dest, mask);
-
- if (fp->node[fp->cur_node].alu_offset > pos)
- pos = fp->node[fp->cur_node].alu_offset;
- for (i = 0; i < argc; ++i) {
- if (!REG_GET_BUILTIN(src[i])) {
- if (emit_vop)
- used |= v_swiz[REG_GET_VSWZ(src[i])].flags << i;
- if (emit_sop)
- used |= s_swiz[REG_GET_SSWZ(src[i])].flags << i;
- }
-
- hwsrc[i] = t_hw_src(fp, src[i], GL_FALSE); /* Note: sideeffects wrt refcounting! */
- regnr = hwsrc[i] & 31;
-
- if (REG_GET_TYPE(src[i]) == REG_TYPE_TEMP) {
- if (used & (SLOT_SRC_VECTOR << i)) {
- if (cs->hwtemps[regnr].vector_valid > pos)
- pos = cs->hwtemps[regnr].vector_valid;
- }
- if (used & (SLOT_SRC_SCALAR << i)) {
- if (cs->hwtemps[regnr].scalar_valid > pos)
- pos = cs->hwtemps[regnr].scalar_valid;
- }
+ inst.DstReg.File = PROGRAM_TEMPORARY;
+ inst.DstReg.Index = tempreg;
+ inst.DstReg.WriteMask = WRITEMASK_XYZW;
+ destredirect = GL_TRUE;
}
}
- // Find a slot that fits
- for (;; ++pos) {
- if (cs->slot[pos].used & used & SLOT_OP_BOTH)
- continue;
-
- if (pos >= cs->nrslots) {
- if (cs->nrslots >= PFS_MAX_ALU_INST) {
- ERROR("Out of ALU instruction slots\n");
- return -1;
- }
-
- fp->alu.inst[pos].inst0 = NOP_INST0;
- fp->alu.inst[pos].inst1 = NOP_INST1;
- fp->alu.inst[pos].inst2 = NOP_INST2;
- fp->alu.inst[pos].inst3 = NOP_INST3;
-
- cs->nrslots++;
- }
- // Note: When we need both parts (vector and scalar) of a source,
- // we always try to put them into the same position. This makes the
- // code easier to read, and it is optimal (i.e. one doesn't gain
- // anything by splitting the parts).
- // It also avoids headaches with swizzles that access both parts (i.e WXY)
- tempused = cs->slot[pos].used;
- for (i = 0; i < 3; ++i) {
- tempvsrc[i] = cs->slot[pos].vsrc[i];
- tempssrc[i] = cs->slot[pos].ssrc[i];
- }
-
- for (i = 0; i < argc; ++i) {
- int flags = (used >> i) & SLOT_SRC_BOTH;
-
- if (!flags) {
- srcpos[i] = 0;
- continue;
- }
-
- for (j = 0; j < 3; ++j) {
- if ((tempused >> j) & flags & SLOT_SRC_VECTOR) {
- if (tempvsrc[j] != hwsrc[i])
- continue;
- }
-
- if ((tempused >> j) & flags & SLOT_SRC_SCALAR) {
- if (tempssrc[j] != hwsrc[i])
- continue;
- }
-
- break;
- }
-
- if (j == 3)
- break;
-
- srcpos[i] = j;
- tempused |= flags << j;
- if (flags & SLOT_SRC_VECTOR)
- tempvsrc[j] = hwsrc[i];
- if (flags & SLOT_SRC_SCALAR)
- tempssrc[j] = hwsrc[i];
- }
-
- if (i == argc)
- break;
- }
-
- // Found a slot, reserve it
- cs->slot[pos].used = tempused | (used & SLOT_OP_BOTH);
- for (i = 0; i < 3; ++i) {
- cs->slot[pos].vsrc[i] = tempvsrc[i];
- cs->slot[pos].ssrc[i] = tempssrc[i];
- }
-
- for (i = 0; i < argc; ++i) {
- if (REG_GET_TYPE(src[i]) == REG_TYPE_TEMP) {
- int regnr = hwsrc[i] & 31;
-
- if (used & (SLOT_SRC_VECTOR << i)) {
- if (cs->hwtemps[regnr].vector_lastread < pos)
- cs->hwtemps[regnr].vector_lastread =
- pos;
- }
- if (used & (SLOT_SRC_SCALAR << i)) {
- if (cs->hwtemps[regnr].scalar_lastread < pos)
- cs->hwtemps[regnr].scalar_lastread =
- pos;
- }
- }
- }
-
- // Emit the source fetch code
- fp->alu.inst[pos].inst1 &= ~R300_ALU_SRC_MASK;
- fp->alu.inst[pos].inst1 |=
- ((cs->slot[pos].vsrc[0] << R300_ALU_SRC0C_SHIFT) |
- (cs->slot[pos].vsrc[1] << R300_ALU_SRC1C_SHIFT) |
- (cs->slot[pos].vsrc[2] << R300_ALU_SRC2C_SHIFT));
-
- fp->alu.inst[pos].inst3 &= ~R300_ALU_SRC_MASK;
- fp->alu.inst[pos].inst3 |=
- ((cs->slot[pos].ssrc[0] << R300_ALU_SRC0A_SHIFT) |
- (cs->slot[pos].ssrc[1] << R300_ALU_SRC1A_SHIFT) |
- (cs->slot[pos].ssrc[2] << R300_ALU_SRC2A_SHIFT));
-
- // Emit the argument selection code
- if (emit_vop) {
- int swz[3];
-
- for (i = 0; i < 3; ++i) {
- if (i < argc) {
- swz[i] = (v_swiz[REG_GET_VSWZ(src[i])].base +
- (srcpos[i] *
- v_swiz[REG_GET_VSWZ(src[i])].
- stride)) | ((src[i] & REG_NEGV_MASK)
- ? ARG_NEG : 0) | ((src[i]
- &
- REG_ABS_MASK)
- ?
- ARG_ABS
- : 0);
- } else {
- swz[i] = R300_ALU_ARGC_ZERO;
- }
- }
-
- fp->alu.inst[pos].inst0 &=
- ~(R300_ALU_ARG0C_MASK | R300_ALU_ARG1C_MASK |
- R300_ALU_ARG2C_MASK);
- fp->alu.inst[pos].inst0 |=
- (swz[0] << R300_ALU_ARG0C_SHIFT) | (swz[1] <<
- R300_ALU_ARG1C_SHIFT)
- | (swz[2] << R300_ALU_ARG2C_SHIFT);
- }
-
- if (emit_sop) {
- int swz[3];
-
- for (i = 0; i < 3; ++i) {
- if (i < argc) {
- swz[i] = (s_swiz[REG_GET_SSWZ(src[i])].base +
- (srcpos[i] *
- s_swiz[REG_GET_SSWZ(src[i])].
- stride)) | ((src[i] & REG_NEGV_MASK)
- ? ARG_NEG : 0) | ((src[i]
- &
- REG_ABS_MASK)
- ?
- ARG_ABS
- : 0);
- } else {
- swz[i] = R300_ALU_ARGA_ZERO;
- }
- }
-
- fp->alu.inst[pos].inst2 &=
- ~(R300_ALU_ARG0A_MASK | R300_ALU_ARG1A_MASK |
- R300_ALU_ARG2A_MASK);
- fp->alu.inst[pos].inst2 |=
- (swz[0] << R300_ALU_ARG0A_SHIFT) | (swz[1] <<
- R300_ALU_ARG1A_SHIFT)
- | (swz[2] << R300_ALU_ARG2A_SHIFT);
- }
-
- return pos;
-}
-
-/**
- * Append an ALU instruction to the instruction list.
- */
-static void emit_arith(struct r300_fragment_program *fp,
- int op,
- GLuint dest,
- int mask,
- GLuint src0, GLuint src1, GLuint src2, int flags)
-{
- COMPILE_STATE;
- GLuint src[3] = { src0, src1, src2 };
- int hwdest;
- GLboolean emit_vop, emit_sop;
- int vop, sop, argc;
- int pos;
-
- vop = r300_fpop[op].v_op;
- sop = r300_fpop[op].s_op;
- argc = r300_fpop[op].argc;
-
- if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT &&
- REG_GET_INDEX(dest) == FRAG_RESULT_DEPR) {
- if (mask & WRITEMASK_Z) {
- mask = WRITEMASK_W;
- } else {
- return;
- }
- }
-
- emit_vop = GL_FALSE;
- emit_sop = GL_FALSE;
- if ((mask & WRITEMASK_XYZ) || vop == R300_ALU_OUTC_DP3)
- emit_vop = GL_TRUE;
- if ((mask & WRITEMASK_W) || vop == R300_ALU_OUTC_REPL_ALPHA)
- emit_sop = GL_TRUE;
-
- pos =
- find_and_prepare_slot(fp, emit_vop, emit_sop, argc, src, dest,
- mask);
- if (pos < 0)
- return;
-
- hwdest = t_hw_dst(fp, dest, GL_FALSE, pos); /* Note: Side effects wrt register allocation */
-
- if (flags & PFS_FLAG_SAT) {
- vop |= R300_ALU_OUTC_CLAMP;
- sop |= R300_ALU_OUTA_CLAMP;
- }
-
- /* Throw the pieces together and get ALU/1 */
- if (emit_vop) {
- fp->alu.inst[pos].inst0 |= vop;
-
- fp->alu.inst[pos].inst1 |= hwdest << R300_ALU_DSTC_SHIFT;
-
- if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
- if (REG_GET_INDEX(dest) == FRAG_RESULT_COLR) {
- fp->alu.inst[pos].inst1 |=
- (mask & WRITEMASK_XYZ) <<
- R300_ALU_DSTC_OUTPUT_MASK_SHIFT;
- } else
- assert(0);
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
+ _mesa_copy_instructions(tgt, &inst, 1);
+
+ if (inst.Opcode != OPCODE_KIL &&
+ compiler->fp->mesa_program.Base.ShadowSamplers & (1 << inst.TexSrcUnit)) {
+ GLuint comparefunc = GL_NEVER + compiler->fp->state.unit[inst.TexSrcUnit].texture_compare_func;
+ GLuint depthmode = compiler->fp->state.unit[inst.TexSrcUnit].depth_texture_mode;
+
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 2);
+
+ tgt[0].Opcode = OPCODE_ADD;
+ tgt[0].DstReg = inst.DstReg;
+ tgt[0].DstReg.WriteMask = orig_inst->DstReg.WriteMask;
+ tgt[0].SrcReg[0].File = PROGRAM_TEMPORARY;
+ tgt[0].SrcReg[0].Index = inst.DstReg.Index;
+ if (depthmode == 0) /* GL_LUMINANCE */
+ tgt[0].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z);
+ else if (depthmode == 2) /* GL_ALPHA */
+ tgt[0].SrcReg[0].Swizzle = SWIZZLE_WWWW;
+ tgt[0].SrcReg[1] = inst.SrcReg[0];
+ tgt[0].SrcReg[1].Swizzle = SWIZZLE_ZZZZ;
+
+ /* Recall that SrcReg[0] is tex, SrcReg[2] is r and:
+ * r < tex <=> -tex+r < 0
+ * r >= tex <=> not (-tex+r < 0 */
+ if (comparefunc == GL_LESS || comparefunc == GL_GEQUAL)
+ tgt[0].SrcReg[0].NegateBase = tgt[0].SrcReg[0].NegateBase ^ NEGATE_XYZW;
+ else
+ tgt[0].SrcReg[1].NegateBase = tgt[0].SrcReg[1].NegateBase ^ NEGATE_XYZW;
+
+ tgt[1].Opcode = OPCODE_CMP;
+ tgt[1].DstReg = orig_inst->DstReg;
+ tgt[1].SrcReg[0].File = PROGRAM_TEMPORARY;
+ tgt[1].SrcReg[0].Index = tgt[0].DstReg.Index;
+ tgt[1].SrcReg[1].File = PROGRAM_BUILTIN;
+ tgt[1].SrcReg[2].File = PROGRAM_BUILTIN;
+
+ if (comparefunc == GL_LESS || comparefunc == GL_GREATER) {
+ tgt[1].SrcReg[1].Swizzle = SWIZZLE_1111;
+ tgt[1].SrcReg[2].Swizzle = SWIZZLE_0000;
} else {
- fp->alu.inst[pos].inst1 |=
- (mask & WRITEMASK_XYZ) <<
- R300_ALU_DSTC_REG_MASK_SHIFT;
-
- cs->hwtemps[hwdest].vector_valid = pos + 1;
+ tgt[1].SrcReg[1].Swizzle = SWIZZLE_0000;
+ tgt[1].SrcReg[2].Swizzle = SWIZZLE_1111;
}
- }
+ } else if (destredirect) {
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
- /* And now ALU/3 */
- if (emit_sop) {
- fp->alu.inst[pos].inst2 |= sop;
-
- if (mask & WRITEMASK_W) {
- if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
- if (REG_GET_INDEX(dest) == FRAG_RESULT_COLR) {
- fp->alu.inst[pos].inst3 |=
- (hwdest << R300_ALU_DSTA_SHIFT) |
- R300_ALU_DSTA_OUTPUT;
- } else if (REG_GET_INDEX(dest) ==
- FRAG_RESULT_DEPR) {
- fp->alu.inst[pos].inst3 |=
- R300_ALU_DSTA_DEPTH;
- } else
- assert(0);
- } else {
- fp->alu.inst[pos].inst3 |=
- (hwdest << R300_ALU_DSTA_SHIFT) |
- R300_ALU_DSTA_REG;
-
- cs->hwtemps[hwdest].scalar_valid = pos + 1;
- }
- }
+ tgt->Opcode = OPCODE_MOV;
+ tgt->DstReg = orig_inst->DstReg;
+ tgt->SrcReg[0].File = PROGRAM_TEMPORARY;
+ tgt->SrcReg[0].Index = inst.DstReg.Index;
}
- return;
+ return GL_TRUE;
}
-#if 0
-static GLuint get_attrib(struct r300_fragment_program *fp, GLuint attr)
+
+static void update_params(r300ContextPtr r300, struct r300_fragment_program *fp)
{
struct gl_fragment_program *mp = &fp->mesa_program;
- GLuint r = undef;
- if (!(mp->Base.InputsRead & (1 << attr))) {
- ERROR("Attribute %d was not provided!\n", attr);
- return undef;
- }
-
- REG_SET_TYPE(r, REG_TYPE_INPUT);
- REG_SET_INDEX(r, attr);
- REG_SET_VALID(r, GL_TRUE);
- return r;
+ /* Ask Mesa nicely to fill in ParameterValues for us */
+ if (mp->Base.Parameters)
+ _mesa_load_state_parameters(r300->radeon.glCtx, mp->Base.Parameters);
}
-#endif
-
-static GLfloat SinCosConsts[2][4] = {
- {
- 1.273239545, // 4/PI
- -0.405284735, // -4/(PI*PI)
- 3.141592654, // PI
- 0.2225 // weight
- },
- {
- 0.75,
- 0.0,
- 0.159154943, // 1/(2*PI)
- 6.283185307 // 2*PI
- }
-};
+
/**
- * Emit a LIT instruction.
- * \p flags may be PFS_FLAG_SAT
+ * Transform the program to support fragment.position.
*
- * Definition of LIT (from ARB_fragment_program):
- * tmp = VectorLoad(op0);
- * if (tmp.x < 0) tmp.x = 0;
- * if (tmp.y < 0) tmp.y = 0;
- * if (tmp.w < -(128.0-epsilon)) tmp.w = -(128.0-epsilon);
- * else if (tmp.w > 128-epsilon) tmp.w = 128-epsilon;
- * result.x = 1.0;
- * result.y = tmp.x;
- * result.z = (tmp.x > 0) ? RoughApproxPower(tmp.y, tmp.w) : 0.0;
- * result.w = 1.0;
+ * Introduce a small fragment at the start of the program that will be
+ * the only code that directly reads the FRAG_ATTRIB_WPOS input.
+ * All other code pieces that reference that input will be rewritten
+ * to read from a newly allocated temporary.
*
- * The longest path of computation is the one leading to result.z,
- * consisting of 5 operations. This implementation of LIT takes
- * 5 slots. So unless there's some special undocumented opcode,
- * this implementation is potentially optimal. Unfortunately,
- * emit_arith is a bit too conservative because it doesn't understand
- * partial writes to the vector component.
+ * \todo if/when r5xx supports the radeon_program architecture, this is a
+ * likely candidate for code sharing.
*/
-static const GLfloat LitConst[4] =
- { 127.999999, 127.999999, 127.999999, -127.999999 };
-
-static void emit_lit(struct r300_fragment_program *fp,
- GLuint dest, int mask, GLuint src, int flags)
+static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler)
{
- COMPILE_STATE;
- GLuint cnst;
- int needTemporary;
- GLuint temp;
-
- cnst = emit_const4fv(fp, LitConst);
-
- needTemporary = 0;
- if ((mask & WRITEMASK_XYZW) != WRITEMASK_XYZW) {
- needTemporary = 1;
- } else if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
- // LIT is typically followed by DP3/DP4, so there's no point
- // in creating special code for this case
- needTemporary = 1;
- }
-
- if (needTemporary) {
- temp = keep(get_temp_reg(fp));
- } else {
- temp = keep(dest);
- }
-
- // Note: The order of emit_arith inside the slots is relevant,
- // because emit_arith only looks at scalar vs. vector when resolving
- // dependencies, and it does not consider individual vector components,
- // so swizzling between the two parts can create fake dependencies.
-
- // First slot
- emit_arith(fp, PFS_OP_MAX, temp, WRITEMASK_XY,
- keep(src), pfs_zero, undef, 0);
- emit_arith(fp, PFS_OP_MAX, temp, WRITEMASK_W, src, cnst, undef, 0);
-
- // Second slot
- emit_arith(fp, PFS_OP_MIN, temp, WRITEMASK_Z,
- swizzle(temp, W, W, W, W), cnst, undef, 0);
- emit_arith(fp, PFS_OP_LG2, temp, WRITEMASK_W,
- swizzle(temp, Y, Y, Y, Y), undef, undef, 0);
-
- // Third slot
- // If desired, we saturate the y result here.
- // This does not affect the use as a condition variable in the CMP later
- emit_arith(fp, PFS_OP_MAD, temp, WRITEMASK_W,
- temp, swizzle(temp, Z, Z, Z, Z), pfs_zero, 0);
- emit_arith(fp, PFS_OP_MAD, temp, WRITEMASK_Y,
- swizzle(temp, X, X, X, X), pfs_one, pfs_zero, flags);
-
- // Fourth slot
- emit_arith(fp, PFS_OP_MAD, temp, WRITEMASK_X,
- pfs_one, pfs_one, pfs_zero, 0);
- emit_arith(fp, PFS_OP_EX2, temp, WRITEMASK_W, temp, undef, undef, 0);
-
- // Fifth slot
- emit_arith(fp, PFS_OP_CMP, temp, WRITEMASK_Z,
- pfs_zero, swizzle(temp, W, W, W, W),
- negate(swizzle(temp, Y, Y, Y, Y)), flags);
- emit_arith(fp, PFS_OP_MAD, temp, WRITEMASK_W, pfs_one, pfs_one,
- pfs_zero, 0);
-
- if (needTemporary) {
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- temp, pfs_one, pfs_zero, flags);
- free_temp(fp, temp);
- } else {
- // Decrease refcount of the destination
- t_hw_dst(fp, dest, GL_FALSE, cs->nrslots);
- }
-}
-
-static GLboolean parse_program(struct r300_fragment_program *fp)
-{
- struct gl_fragment_program *mp = &fp->mesa_program;
- const struct prog_instruction *inst = mp->Base.Instructions;
- struct prog_instruction *fpi;
- GLuint src[3], dest, temp[2];
- int flags, mask = 0;
- int const_sin[2];
+ GLuint InputsRead = compiler->fp->mesa_program.Base.InputsRead;
- if (!inst || inst[0].Opcode == OPCODE_END) {
- ERROR("empty program?\n");
- return GL_FALSE;
- }
-
- for (fpi = mp->Base.Instructions; fpi->Opcode != OPCODE_END; fpi++) {
- if (fpi->SaturateMode == SATURATE_ZERO_ONE)
- flags = PFS_FLAG_SAT;
- else
- flags = 0;
-
- if (fpi->Opcode != OPCODE_KIL) {
- dest = t_dst(fp, fpi->DstReg);
- mask = fpi->DstReg.WriteMask;
- }
-
- switch (fpi->Opcode) {
- case OPCODE_ABS:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- absolute(src[0]), pfs_one, pfs_zero, flags);
- break;
- case OPCODE_ADD:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], pfs_one, src[1], flags);
- break;
- case OPCODE_CMP:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- src[2] = t_src(fp, fpi->SrcReg[2]);
- /* ARB_f_p - if src0.c < 0.0 ? src1.c : src2.c
- * r300 - if src2.c < 0.0 ? src1.c : src0.c
- */
- emit_arith(fp, PFS_OP_CMP, dest, mask,
- src[2], src[1], src[0], flags);
- break;
- case OPCODE_COS:
- /*
- * cos using a parabola (see SIN):
- * cos(x):
- * x = (x/(2*PI))+0.75
- * x = frac(x)
- * x = (x*2*PI)-PI
- * result = sin(x)
- */
- temp[0] = get_temp_reg(fp);
- const_sin[0] = emit_const4fv(fp, SinCosConsts[0]);
- const_sin[1] = emit_const4fv(fp, SinCosConsts[1]);
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
-
- /* add 0.5*PI and do range reduction */
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_X,
- swizzle(src[0], X, X, X, X),
- swizzle(const_sin[1], Z, Z, Z, Z),
- swizzle(const_sin[1], X, X, X, X), 0);
-
- emit_arith(fp, PFS_OP_FRC, temp[0], WRITEMASK_X,
- swizzle(temp[0], X, X, X, X),
- undef, undef, 0);
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_Z, swizzle(temp[0], X, X, X, X), swizzle(const_sin[1], W, W, W, W), //2*PI
- negate(swizzle(const_sin[0], Z, Z, Z, Z)), //-PI
- 0);
-
- /* SIN */
-
- emit_arith(fp, PFS_OP_MAD, temp[0],
- WRITEMASK_X | WRITEMASK_Y, swizzle(temp[0],
- Z, Z, Z,
- Z),
- const_sin[0], pfs_zero, 0);
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_X,
- swizzle(temp[0], Y, Y, Y, Y),
- absolute(swizzle(temp[0], Z, Z, Z, Z)),
- swizzle(temp[0], X, X, X, X), 0);
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_Y,
- swizzle(temp[0], X, X, X, X),
- absolute(swizzle(temp[0], X, X, X, X)),
- negate(swizzle(temp[0], X, X, X, X)), 0);
-
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- swizzle(temp[0], Y, Y, Y, Y),
- swizzle(const_sin[0], W, W, W, W),
- swizzle(temp[0], X, X, X, X), flags);
-
- free_temp(fp, temp[0]);
- break;
- case OPCODE_DP3:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_DP3, dest, mask,
- src[0], src[1], undef, flags);
- break;
- case OPCODE_DP4:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_DP4, dest, mask,
- src[0], src[1], undef, flags);
- break;
- case OPCODE_DPH:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- /* src0.xyz1 -> temp
- * DP4 dest, temp, src1
- */
-#if 0
- temp[0] = get_temp_reg(fp);
- src[0].s_swz = SWIZZLE_ONE;
- emit_arith(fp, PFS_OP_MAD, temp[0], mask,
- src[0], pfs_one, pfs_zero, 0);
- emit_arith(fp, PFS_OP_DP4, dest, mask,
- temp[0], src[1], undef, flags);
- free_temp(fp, temp[0]);
-#else
- emit_arith(fp, PFS_OP_DP4, dest, mask,
- swizzle(src[0], X, Y, Z, ONE), src[1],
- undef, flags);
-#endif
- break;
- case OPCODE_DST:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- /* dest.y = src0.y * src1.y */
- if (mask & WRITEMASK_Y)
- emit_arith(fp, PFS_OP_MAD, dest, WRITEMASK_Y,
- keep(src[0]), keep(src[1]),
- pfs_zero, flags);
- /* dest.z = src0.z */
- if (mask & WRITEMASK_Z)
- emit_arith(fp, PFS_OP_MAD, dest, WRITEMASK_Z,
- src[0], pfs_one, pfs_zero, flags);
- /* result.x = 1.0
- * result.w = src1.w */
- if (mask & WRITEMASK_XW) {
- REG_SET_VSWZ(src[1], SWIZZLE_111); /*Cheat */
- emit_arith(fp, PFS_OP_MAD, dest,
- mask & WRITEMASK_XW,
- src[1], pfs_one, pfs_zero, flags);
- }
- break;
- case OPCODE_EX2:
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_EX2, dest, mask,
- src[0], undef, undef, flags);
- break;
- case OPCODE_FLR:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- temp[0] = get_temp_reg(fp);
- /* FRC temp, src0
- * MAD dest, src0, 1.0, -temp
- */
- emit_arith(fp, PFS_OP_FRC, temp[0], mask,
- keep(src[0]), undef, undef, 0);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], pfs_one, negate(temp[0]), flags);
- free_temp(fp, temp[0]);
- break;
- case OPCODE_FRC:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_FRC, dest, mask,
- src[0], undef, undef, flags);
- break;
- case OPCODE_KIL:
- emit_tex(fp, fpi, R300_TEX_OP_KIL);
- break;
- case OPCODE_LG2:
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_LG2, dest, mask,
- src[0], undef, undef, flags);
- break;
- case OPCODE_LIT:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- emit_lit(fp, dest, mask, src[0], flags);
- break;
- case OPCODE_LRP:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- src[2] = t_src(fp, fpi->SrcReg[2]);
- /* result = tmp0tmp1 + (1 - tmp0)tmp2
- * = tmp0tmp1 + tmp2 + (-tmp0)tmp2
- * MAD temp, -tmp0, tmp2, tmp2
- * MAD result, tmp0, tmp1, temp
- */
- temp[0] = get_temp_reg(fp);
- emit_arith(fp, PFS_OP_MAD, temp[0], mask,
- negate(keep(src[0])), keep(src[2]), src[2],
- 0);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], src[1], temp[0], flags);
- free_temp(fp, temp[0]);
- break;
- case OPCODE_MAD:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- src[2] = t_src(fp, fpi->SrcReg[2]);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], src[1], src[2], flags);
- break;
- case OPCODE_MAX:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_MAX, dest, mask,
- src[0], src[1], undef, flags);
- break;
- case OPCODE_MIN:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_MIN, dest, mask,
- src[0], src[1], undef, flags);
- break;
- case OPCODE_MOV:
- case OPCODE_SWZ:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], pfs_one, pfs_zero, flags);
- break;
- case OPCODE_MUL:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], src[1], pfs_zero, flags);
- break;
- case OPCODE_POW:
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
- src[1] = t_scalar_src(fp, fpi->SrcReg[1]);
- temp[0] = get_temp_reg(fp);
- emit_arith(fp, PFS_OP_LG2, temp[0], WRITEMASK_W,
- src[0], undef, undef, 0);
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_W,
- temp[0], src[1], pfs_zero, 0);
- emit_arith(fp, PFS_OP_EX2, dest, fpi->DstReg.WriteMask,
- temp[0], undef, undef, 0);
- free_temp(fp, temp[0]);
- break;
- case OPCODE_RCP:
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_RCP, dest, mask,
- src[0], undef, undef, flags);
- break;
- case OPCODE_RSQ:
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
- emit_arith(fp, PFS_OP_RSQ, dest, mask,
- absolute(src[0]), pfs_zero, pfs_zero, flags);
- break;
- case OPCODE_SCS:
- /*
- * scs using a parabola :
- * scs(x):
- * result.x = sin(-abs(x)+0.5*PI) (cos)
- * result.y = sin(x) (sin)
- *
- */
- temp[0] = get_temp_reg(fp);
- temp[1] = get_temp_reg(fp);
- const_sin[0] = emit_const4fv(fp, SinCosConsts[0]);
- const_sin[1] = emit_const4fv(fp, SinCosConsts[1]);
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
-
- /* x = -abs(x)+0.5*PI */
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_Z, swizzle(const_sin[0], Z, Z, Z, Z), //PI
- pfs_half,
- negate(abs
- (swizzle(keep(src[0]), X, X, X, X))),
- 0);
-
- /* C*x (sin) */
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_W,
- swizzle(const_sin[0], Y, Y, Y, Y),
- swizzle(keep(src[0]), X, X, X, X),
- pfs_zero, 0);
-
- /* B*x, C*x (cos) */
- emit_arith(fp, PFS_OP_MAD, temp[0],
- WRITEMASK_X | WRITEMASK_Y, swizzle(temp[0],
- Z, Z, Z,
- Z),
- const_sin[0], pfs_zero, 0);
-
- /* B*x (sin) */
- emit_arith(fp, PFS_OP_MAD, temp[1], WRITEMASK_W,
- swizzle(const_sin[0], X, X, X, X),
- keep(src[0]), pfs_zero, 0);
-
- /* y = B*x + C*x*abs(x) (sin) */
- emit_arith(fp, PFS_OP_MAD, temp[1], WRITEMASK_Z,
- absolute(src[0]),
- swizzle(temp[0], W, W, W, W),
- swizzle(temp[1], W, W, W, W), 0);
-
- /* y = B*x + C*x*abs(x) (cos) */
- emit_arith(fp, PFS_OP_MAD, temp[1], WRITEMASK_W,
- swizzle(temp[0], Y, Y, Y, Y),
- absolute(swizzle(temp[0], Z, Z, Z, Z)),
- swizzle(temp[0], X, X, X, X), 0);
-
- /* y*abs(y) - y (cos), y*abs(y) - y (sin) */
- emit_arith(fp, PFS_OP_MAD, temp[0],
- WRITEMASK_X | WRITEMASK_Y, swizzle(temp[1],
- W, Z, Y,
- X),
- absolute(swizzle(temp[1], W, Z, Y, X)),
- negate(swizzle(temp[1], W, Z, Y, X)), 0);
-
- /* dest.xy = mad(temp.xy, P, temp2.wz) */
- emit_arith(fp, PFS_OP_MAD, dest,
- mask & (WRITEMASK_X | WRITEMASK_Y), temp[0],
- swizzle(const_sin[0], W, W, W, W),
- swizzle(temp[1], W, Z, Y, X), flags);
-
- free_temp(fp, temp[0]);
- free_temp(fp, temp[1]);
- break;
- case OPCODE_SGE:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- temp[0] = get_temp_reg(fp);
- /* temp = src0 - src1
- * dest.c = (temp.c < 0.0) ? 0 : 1
- */
- emit_arith(fp, PFS_OP_MAD, temp[0], mask,
- src[0], pfs_one, negate(src[1]), 0);
- emit_arith(fp, PFS_OP_CMP, dest, mask,
- pfs_one, pfs_zero, temp[0], 0);
- free_temp(fp, temp[0]);
- break;
- case OPCODE_SIN:
- /*
- * using a parabola:
- * sin(x) = 4/pi * x + -4/(pi*pi) * x * abs(x)
- * extra precision is obtained by weighting against
- * itself squared.
- */
-
- temp[0] = get_temp_reg(fp);
- const_sin[0] = emit_const4fv(fp, SinCosConsts[0]);
- const_sin[1] = emit_const4fv(fp, SinCosConsts[1]);
- src[0] = t_scalar_src(fp, fpi->SrcReg[0]);
-
- /* do range reduction */
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_X,
- swizzle(keep(src[0]), X, X, X, X),
- swizzle(const_sin[1], Z, Z, Z, Z),
- pfs_half, 0);
-
- emit_arith(fp, PFS_OP_FRC, temp[0], WRITEMASK_X,
- swizzle(temp[0], X, X, X, X),
- undef, undef, 0);
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_Z, swizzle(temp[0], X, X, X, X), swizzle(const_sin[1], W, W, W, W), //2*PI
- negate(swizzle(const_sin[0], Z, Z, Z, Z)), //PI
- 0);
-
- /* SIN */
-
- emit_arith(fp, PFS_OP_MAD, temp[0],
- WRITEMASK_X | WRITEMASK_Y, swizzle(temp[0],
- Z, Z, Z,
- Z),
- const_sin[0], pfs_zero, 0);
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_X,
- swizzle(temp[0], Y, Y, Y, Y),
- absolute(swizzle(temp[0], Z, Z, Z, Z)),
- swizzle(temp[0], X, X, X, X), 0);
-
- emit_arith(fp, PFS_OP_MAD, temp[0], WRITEMASK_Y,
- swizzle(temp[0], X, X, X, X),
- absolute(swizzle(temp[0], X, X, X, X)),
- negate(swizzle(temp[0], X, X, X, X)), 0);
-
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- swizzle(temp[0], Y, Y, Y, Y),
- swizzle(const_sin[0], W, W, W, W),
- swizzle(temp[0], X, X, X, X), flags);
-
- free_temp(fp, temp[0]);
- break;
- case OPCODE_SLT:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- temp[0] = get_temp_reg(fp);
- /* temp = src0 - src1
- * dest.c = (temp.c < 0.0) ? 1 : 0
- */
- emit_arith(fp, PFS_OP_MAD, temp[0], mask,
- src[0], pfs_one, negate(src[1]), 0);
- emit_arith(fp, PFS_OP_CMP, dest, mask,
- pfs_zero, pfs_one, temp[0], 0);
- free_temp(fp, temp[0]);
- break;
- case OPCODE_SUB:
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- emit_arith(fp, PFS_OP_MAD, dest, mask,
- src[0], pfs_one, negate(src[1]), flags);
- break;
- case OPCODE_TEX:
- emit_tex(fp, fpi, R300_TEX_OP_LD);
- break;
- case OPCODE_TXB:
- emit_tex(fp, fpi, R300_TEX_OP_TXB);
- break;
- case OPCODE_TXP:
- emit_tex(fp, fpi, R300_TEX_OP_TXP);
- break;
- case OPCODE_XPD:{
- src[0] = t_src(fp, fpi->SrcReg[0]);
- src[1] = t_src(fp, fpi->SrcReg[1]);
- temp[0] = get_temp_reg(fp);
- /* temp = src0.zxy * src1.yzx */
- emit_arith(fp, PFS_OP_MAD, temp[0],
- WRITEMASK_XYZ, swizzle(keep(src[0]),
- Z, X, Y, W),
- swizzle(keep(src[1]), Y, Z, X, W),
- pfs_zero, 0);
- /* dest.xyz = src0.yzx * src1.zxy - temp
- * dest.w = undefined
- * */
- emit_arith(fp, PFS_OP_MAD, dest,
- mask & WRITEMASK_XYZ, swizzle(src[0],
- Y, Z,
- X, W),
- swizzle(src[1], Z, X, Y, W),
- negate(temp[0]), flags);
- /* cleanup */
- free_temp(fp, temp[0]);
- break;
- }
- default:
- ERROR("unknown fpi->Opcode %d\n", fpi->Opcode);
- break;
- }
-
- if (fp->error)
- return GL_FALSE;
-
- }
-
- return GL_TRUE;
-}
+ if (!(InputsRead & FRAG_BIT_WPOS))
+ return;
-static void insert_wpos(struct gl_program *prog)
-{
static gl_state_index tokens[STATE_LENGTH] = {
STATE_INTERNAL, STATE_R300_WINDOW_DIMENSION, 0, 0, 0
};
struct prog_instruction *fpi;
GLuint window_index;
int i = 0;
- GLuint tempregi = prog->NumTemporaries;
- /* should do something else if no temps left... */
- prog->NumTemporaries++;
+ GLuint tempregi = radeonCompilerAllocateTemporary(&compiler->compiler);
- fpi = _mesa_alloc_instructions(prog->NumInstructions + 3);
- _mesa_init_instructions(fpi, prog->NumInstructions + 3);
+ fpi = radeonClauseInsertInstructions(&compiler->compiler, &compiler->compiler.Clauses[0], 0, 3);
/* perspective divide */
fpi[i].Opcode = OPCODE_RCP;
@@ -2041,7 +297,7 @@ static void insert_wpos(struct gl_program *prog)
i++;
/* viewport transformation */
- window_index = _mesa_add_state_reference(prog->Parameters, tokens);
+ window_index = _mesa_add_state_reference(compiler->fp->mesa_program.Base.Parameters, tokens);
fpi[i].Opcode = OPCODE_MAD;
@@ -2066,203 +322,114 @@ static void insert_wpos(struct gl_program *prog)
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
i++;
- _mesa_copy_instructions(&fpi[i], prog->Instructions,
- prog->NumInstructions);
-
- free(prog->Instructions);
-
- prog->Instructions = fpi;
-
- prog->NumInstructions += i;
- fpi = &prog->Instructions[prog->NumInstructions - 1];
-
- assert(fpi->Opcode == OPCODE_END);
-
- for (fpi = &prog->Instructions[3]; fpi->Opcode != OPCODE_END; fpi++) {
- for (i = 0; i < 3; i++)
- if (fpi->SrcReg[i].File == PROGRAM_INPUT &&
- fpi->SrcReg[i].Index == FRAG_ATTRIB_WPOS) {
- fpi->SrcReg[i].File = PROGRAM_TEMPORARY;
- fpi->SrcReg[i].Index = tempregi;
+ for (; i < compiler->compiler.Clauses[0].NumInstructions; ++i) {
+ int reg;
+ for (reg = 0; reg < 3; reg++) {
+ if (fpi[i].SrcReg[reg].File == PROGRAM_INPUT &&
+ fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_WPOS) {
+ fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY;
+ fpi[i].SrcReg[reg].Index = tempregi;
}
- }
-}
-
-/* - Init structures
- * - Determine what hwregs each input corresponds to
- */
-static void init_program(r300ContextPtr r300, struct r300_fragment_program *fp)
-{
- struct r300_pfs_compile_state *cs = NULL;
- struct gl_fragment_program *mp = &fp->mesa_program;
- struct prog_instruction *fpi;
- GLuint InputsRead = mp->Base.InputsRead;
- GLuint temps_used = 0; /* for fp->temps[] */
- int i, j;
-
- /* New compile, reset tracking data */
- fp->optimization =
- driQueryOptioni(&r300->radeon.optionCache, "fp_optimization");
- fp->translated = GL_FALSE;
- fp->error = GL_FALSE;
- fp->cs = cs = &(R300_CONTEXT(fp->ctx)->state.pfs_compile);
- fp->WritesDepth = GL_FALSE;
- fp->tex.length = 0;
- fp->cur_node = 0;
- fp->first_node_has_tex = 0;
- fp->const_nr = 0;
- fp->max_temp_idx = 0;
- fp->node[0].alu_end = -1;
- fp->node[0].tex_end = -1;
-
- _mesa_memset(cs, 0, sizeof(*fp->cs));
- for (i = 0; i < PFS_MAX_ALU_INST; i++) {
- for (j = 0; j < 3; j++) {
- cs->slot[i].vsrc[j] = SRC_CONST;
- cs->slot[i].ssrc[j] = SRC_CONST;
}
}
+}
- /* Work out what temps the Mesa inputs correspond to, this must match
- * what setup_rs_unit does, which shouldn't be a problem as rs_unit
- * configures itself based on the fragprog's InputsRead
- *
- * NOTE: this depends on get_hw_temp() allocating registers in order,
- * starting from register 0.
- */
- /* Texcoords come first */
- for (i = 0; i < fp->ctx->Const.MaxTextureUnits; i++) {
- if (InputsRead & (FRAG_BIT_TEX0 << i)) {
- cs->inputs[FRAG_ATTRIB_TEX0 + i].refcount = 0;
- cs->inputs[FRAG_ATTRIB_TEX0 + i].reg =
- get_hw_temp(fp, 0);
- }
+static GLuint build_dtm(GLuint depthmode)
+{
+ switch(depthmode) {
+ default:
+ case GL_LUMINANCE: return 0;
+ case GL_INTENSITY: return 1;
+ case GL_ALPHA: return 2;
}
- InputsRead &= ~FRAG_BITS_TEX_ANY;
+}
- /* fragment position treated as a texcoord */
- if (InputsRead & FRAG_BIT_WPOS) {
- cs->inputs[FRAG_ATTRIB_WPOS].refcount = 0;
- cs->inputs[FRAG_ATTRIB_WPOS].reg = get_hw_temp(fp, 0);
- insert_wpos(&mp->Base);
- }
- InputsRead &= ~FRAG_BIT_WPOS;
+static GLuint build_func(GLuint comparefunc)
+{
+ return comparefunc - GL_NEVER;
+}
- /* Then primary colour */
- if (InputsRead & FRAG_BIT_COL0) {
- cs->inputs[FRAG_ATTRIB_COL0].refcount = 0;
- cs->inputs[FRAG_ATTRIB_COL0].reg = get_hw_temp(fp, 0);
- }
- InputsRead &= ~FRAG_BIT_COL0;
- /* Secondary color */
- if (InputsRead & FRAG_BIT_COL1) {
- cs->inputs[FRAG_ATTRIB_COL1].refcount = 0;
- cs->inputs[FRAG_ATTRIB_COL1].reg = get_hw_temp(fp, 0);
- }
- InputsRead &= ~FRAG_BIT_COL1;
-
- /* Anything else */
- if (InputsRead) {
- WARN_ONCE("Don't know how to handle inputs 0x%x\n", InputsRead);
- /* force read from hwreg 0 for now */
- for (i = 0; i < 32; i++)
- if (InputsRead & (1 << i))
- cs->inputs[i].reg = 0;
- }
+/**
+ * Collect all external state that is relevant for compiling the given
+ * fragment program.
+ */
+static void build_state(
+ r300ContextPtr r300,
+ struct r300_fragment_program *fp,
+ struct r300_fragment_program_external_state *state)
+{
+ int unit;
- /* Pre-parse the mesa program, grabbing refcounts on input/temp regs.
- * That way, we can free up the reg when it's no longer needed
- */
- if (!mp->Base.Instructions) {
- ERROR("No instructions found in program\n");
- return;
- }
+ _mesa_bzero(state, sizeof(*state));
- for (fpi = mp->Base.Instructions; fpi->Opcode != OPCODE_END; fpi++) {
- int idx;
-
- for (i = 0; i < 3; i++) {
- idx = fpi->SrcReg[i].Index;
- switch (fpi->SrcReg[i].File) {
- case PROGRAM_TEMPORARY:
- if (!(temps_used & (1 << idx))) {
- cs->temps[idx].reg = -1;
- cs->temps[idx].refcount = 1;
- temps_used |= (1 << idx);
- } else
- cs->temps[idx].refcount++;
- break;
- case PROGRAM_INPUT:
- cs->inputs[idx].refcount++;
- break;
- default:
- break;
- }
- }
+ for(unit = 0; unit < 16; ++unit) {
+ if (fp->mesa_program.Base.ShadowSamplers & (1 << unit)) {
+ struct gl_texture_object* tex = r300->radeon.glCtx->Texture.Unit[unit]._Current;
- idx = fpi->DstReg.Index;
- if (fpi->DstReg.File == PROGRAM_TEMPORARY) {
- if (!(temps_used & (1 << idx))) {
- cs->temps[idx].reg = -1;
- cs->temps[idx].refcount = 1;
- temps_used |= (1 << idx);
- } else
- cs->temps[idx].refcount++;
+ state->unit[unit].depth_texture_mode = build_dtm(tex->DepthMode);
+ state->unit[unit].texture_compare_func = build_func(tex->CompareFunc);
}
}
- cs->temp_in_use = temps_used;
}
-static void update_params(struct r300_fragment_program *fp)
-{
- struct gl_fragment_program *mp = &fp->mesa_program;
-
- /* Ask Mesa nicely to fill in ParameterValues for us */
- if (mp->Base.Parameters)
- _mesa_load_state_parameters(fp->ctx, mp->Base.Parameters);
-}
void r300TranslateFragmentShader(r300ContextPtr r300,
struct r300_fragment_program *fp)
{
+ struct r300_fragment_program_external_state state;
- struct r300_pfs_compile_state *cs = NULL;
+ build_state(r300, fp, &state);
+ if (_mesa_memcmp(&fp->state, &state, sizeof(state))) {
+ /* TODO: cache compiled programs */
+ fp->translated = GL_FALSE;
+ _mesa_memcpy(&fp->state, &state, sizeof(state));
+ }
if (!fp->translated) {
+ struct r300_fragment_program_compiler compiler;
+
+ compiler.r300 = r300;
+ compiler.fp = fp;
+ compiler.code = &fp->code;
- init_program(r300, fp);
- cs = fp->cs;
+ radeonCompilerInit(&compiler.compiler, r300->radeon.glCtx, &fp->mesa_program.Base);
- if (parse_program(fp) == GL_FALSE) {
- dump_program(fp);
- return;
+ insert_WPOS_trailer(&compiler);
+
+ struct radeon_program_transformation transformations[] = {
+ { &transform_TEX, &compiler },
+ { &radeonTransformALU, 0 }
+ };
+ radeonClauseLocalTransform(&compiler.compiler,
+ &compiler.compiler.Clauses[0],
+ 2, transformations);
+
+ if (RADEON_DEBUG & DEBUG_PIXEL) {
+ _mesa_printf("Compiler state after transformations:\n");
+ radeonCompilerDump(&compiler.compiler);
}
- /* Finish off */
- fp->node[fp->cur_node].alu_end =
- cs->nrslots - fp->node[fp->cur_node].alu_offset - 1;
- if (fp->node[fp->cur_node].tex_end < 0)
- fp->node[fp->cur_node].tex_end = 0;
- fp->alu_offset = 0;
- fp->alu_end = cs->nrslots - 1;
- fp->tex_offset = 0;
- fp->tex_end = fp->tex.length ? fp->tex.length - 1 : 0;
- assert(fp->node[fp->cur_node].alu_end >= 0);
- assert(fp->alu_end >= 0);
-
- fp->translated = GL_TRUE;
- if (RADEON_DEBUG & DEBUG_PIXEL)
- dump_program(fp);
- r300UpdateStateParameters(fp->ctx, _NEW_PROGRAM);
+ if (!r300FragmentProgramEmit(&compiler))
+ fp->error = GL_TRUE;
+
+ radeonCompilerCleanup(&compiler.compiler);
+
+ if (!fp->error)
+ fp->translated = GL_TRUE;
+ if (fp->error || (RADEON_DEBUG & DEBUG_PIXEL))
+ r300FragmentProgramDump(fp, &fp->code);
+ r300UpdateStateParameters(r300->radeon.glCtx, _NEW_PROGRAM);
}
- update_params(fp);
+ update_params(r300, fp);
}
/* just some random things... */
-static void dump_program(struct r300_fragment_program *fp)
+void r300FragmentProgramDump(
+ struct r300_fragment_program *fp,
+ struct r300_fragment_program_code *code)
{
int n, i, j;
static int pc = 0;
@@ -2277,21 +444,21 @@ static void dump_program(struct r300_fragment_program *fp)
fprintf(stderr, "Hardware program\n");
fprintf(stderr, "----------------\n");
- for (n = 0; n < (fp->cur_node + 1); n++) {
+ for (n = 0; n < (code->cur_node + 1); n++) {
fprintf(stderr, "NODE %d: alu_offset: %d, tex_offset: %d, "
"alu_end: %d, tex_end: %d\n", n,
- fp->node[n].alu_offset,
- fp->node[n].tex_offset,
- fp->node[n].alu_end, fp->node[n].tex_end);
+ code->node[n].alu_offset,
+ code->node[n].tex_offset,
+ code->node[n].alu_end, code->node[n].tex_end);
- if (fp->tex.length) {
+ if (code->tex.length) {
fprintf(stderr, " TEX:\n");
- for (i = fp->node[n].tex_offset;
- i <= fp->node[n].tex_offset + fp->node[n].tex_end;
+ for (i = code->node[n].tex_offset;
+ i <= code->node[n].tex_offset + code->node[n].tex_end;
++i) {
const char *instr;
- switch ((fp->tex.
+ switch ((code->tex.
inst[i] >> R300_TEX_INST_SHIFT) &
15) {
case R300_TEX_OP_LD:
@@ -2313,20 +480,20 @@ static void dump_program(struct r300_fragment_program *fp)
fprintf(stderr,
" %s t%i, %c%i, texture[%i] (%08x)\n",
instr,
- (fp->tex.
+ (code->tex.
inst[i] >> R300_DST_ADDR_SHIFT) & 31,
't',
- (fp->tex.
+ (code->tex.
inst[i] >> R300_SRC_ADDR_SHIFT) & 31,
- (fp->tex.
+ (code->tex.
inst[i] & R300_TEX_ID_MASK) >>
R300_TEX_ID_SHIFT,
- fp->tex.inst[i]);
+ code->tex.inst[i]);
}
}
- for (i = fp->node[n].alu_offset;
- i <= fp->node[n].alu_offset + fp->node[n].alu_end; ++i) {
+ for (i = code->node[n].alu_offset;
+ i <= code->node[n].alu_offset + code->node[n].alu_end; ++i) {
char srcc[3][10], dstc[20];
char srca[3][10], dsta[20];
char argc[3][20];
@@ -2334,8 +501,8 @@ static void dump_program(struct r300_fragment_program *fp)
char flags[5], tmp[10];
for (j = 0; j < 3; ++j) {
- int regc = fp->alu.inst[i].inst1 >> (j * 6);
- int rega = fp->alu.inst[i].inst3 >> (j * 6);
+ int regc = code->alu.inst[i].inst1 >> (j * 6);
+ int rega = code->alu.inst[i].inst3 >> (j * 6);
sprintf(srcc[j], "%c%i",
(regc & 32) ? 'c' : 't', regc & 31);
@@ -2345,46 +512,46 @@ static void dump_program(struct r300_fragment_program *fp)
dstc[0] = 0;
sprintf(flags, "%s%s%s",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 & R300_ALU_DSTC_REG_X) ? "x" : "",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 & R300_ALU_DSTC_REG_Y) ? "y" : "",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 & R300_ALU_DSTC_REG_Z) ? "z" : "");
if (flags[0] != 0) {
sprintf(dstc, "t%i.%s ",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 >> R300_ALU_DSTC_SHIFT) & 31,
flags);
}
sprintf(flags, "%s%s%s",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 & R300_ALU_DSTC_OUTPUT_X) ? "x" : "",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 & R300_ALU_DSTC_OUTPUT_Y) ? "y" : "",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 & R300_ALU_DSTC_OUTPUT_Z) ? "z" : "");
if (flags[0] != 0) {
sprintf(tmp, "o%i.%s",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst1 >> R300_ALU_DSTC_SHIFT) & 31,
flags);
strcat(dstc, tmp);
}
dsta[0] = 0;
- if (fp->alu.inst[i].inst3 & R300_ALU_DSTA_REG) {
+ if (code->alu.inst[i].inst3 & R300_ALU_DSTA_REG) {
sprintf(dsta, "t%i.w ",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst3 >> R300_ALU_DSTA_SHIFT) & 31);
}
- if (fp->alu.inst[i].inst3 & R300_ALU_DSTA_OUTPUT) {
+ if (code->alu.inst[i].inst3 & R300_ALU_DSTA_OUTPUT) {
sprintf(tmp, "o%i.w ",
- (fp->alu.inst[i].
+ (code->alu.inst[i].
inst3 >> R300_ALU_DSTA_SHIFT) & 31);
strcat(dsta, tmp);
}
- if (fp->alu.inst[i].inst3 & R300_ALU_DSTA_DEPTH) {
+ if (code->alu.inst[i].inst3 & R300_ALU_DSTA_DEPTH) {
strcat(dsta, "Z");
}
@@ -2392,12 +559,12 @@ static void dump_program(struct r300_fragment_program *fp)
"%3i: xyz: %3s %3s %3s -> %-20s (%08x)\n"
" w: %3s %3s %3s -> %-20s (%08x)\n", i,
srcc[0], srcc[1], srcc[2], dstc,
- fp->alu.inst[i].inst1, srca[0], srca[1],
- srca[2], dsta, fp->alu.inst[i].inst3);
+ code->alu.inst[i].inst1, srca[0], srca[1],
+ srca[2], dsta, code->alu.inst[i].inst3);
for (j = 0; j < 3; ++j) {
- int regc = fp->alu.inst[i].inst0 >> (j * 7);
- int rega = fp->alu.inst[i].inst2 >> (j * 7);
+ int regc = code->alu.inst[i].inst0 >> (j * 7);
+ int rega = code->alu.inst[i].inst2 >> (j * 7);
int d;
char buf[20];
@@ -2479,8 +646,8 @@ static void dump_program(struct r300_fragment_program *fp)
fprintf(stderr, " xyz: %8s %8s %8s op: %08x\n"
" w: %8s %8s %8s op: %08x\n",
argc[0], argc[1], argc[2],
- fp->alu.inst[i].inst0, arga[0], arga[1],
- arga[2], fp->alu.inst[i].inst2);
+ code->alu.inst[i].inst0, arga[0], arga[1],
+ arga[2], code->alu.inst[i].inst2);
}
}
}
diff --git a/src/mesa/drivers/dri/r300/r300_fragprog.h b/src/mesa/drivers/dri/r300/r300_fragprog.h
index 573aacf19a..7c1e210b04 100644
--- a/src/mesa/drivers/dri/r300/r300_fragprog.h
+++ b/src/mesa/drivers/dri/r300/r300_fragprog.h
@@ -40,12 +40,7 @@
#include "shader/prog_instruction.h"
#include "r300_context.h"
-
-typedef struct r300_fragment_program_swizzle {
- GLuint length;
- GLuint src[4];
- GLuint inst[8];
-} r300_fragment_program_swizzle_t;
+#include "radeon_program.h"
/* supported hw opcodes */
#define PFS_OP_MAD 0
@@ -74,25 +69,6 @@ typedef struct r300_fragment_program_swizzle {
#define SRC_MASK (63 << 0)
#define SRC_STRIDE 6
-#define NOP_INST0 ( \
- (R300_ALU_OUTC_MAD) | \
- (R300_ALU_ARGC_ZERO << R300_ALU_ARG0C_SHIFT) | \
- (R300_ALU_ARGC_ZERO << R300_ALU_ARG1C_SHIFT) | \
- (R300_ALU_ARGC_ZERO << R300_ALU_ARG2C_SHIFT))
-#define NOP_INST1 ( \
- ((0 | SRC_CONST) << R300_ALU_SRC0C_SHIFT) | \
- ((0 | SRC_CONST) << R300_ALU_SRC1C_SHIFT) | \
- ((0 | SRC_CONST) << R300_ALU_SRC2C_SHIFT))
-#define NOP_INST2 ( \
- (R300_ALU_OUTA_MAD) | \
- (R300_ALU_ARGA_ZERO << R300_ALU_ARG0A_SHIFT) | \
- (R300_ALU_ARGA_ZERO << R300_ALU_ARG1A_SHIFT) | \
- (R300_ALU_ARGA_ZERO << R300_ALU_ARG2A_SHIFT))
-#define NOP_INST3 ( \
- ((0 | SRC_CONST) << R300_ALU_SRC0A_SHIFT) | \
- ((0 | SRC_CONST) << R300_ALU_SRC1A_SHIFT) | \
- ((0 | SRC_CONST) << R300_ALU_SRC2A_SHIFT))
-
#define DRI_CONF_FP_OPTIMIZATION_SPEED 0
#define DRI_CONF_FP_OPTIMIZATION_QUALITY 1
@@ -161,4 +137,24 @@ struct r300_fragment_program;
extern void r300TranslateFragmentShader(r300ContextPtr r300,
struct r300_fragment_program *fp);
+
+/**
+ * Used internally by the r300 fragment program code to store compile-time
+ * only data.
+ */
+struct r300_fragment_program_compiler {
+ r300ContextPtr r300;
+ struct r300_fragment_program *fp;
+ struct r300_fragment_program_code *code;
+ struct radeon_compiler compiler;
+};
+
+extern void r300FPTransformTextures(struct r300_fragment_program_compiler *compiler);
+extern GLboolean r300FragmentProgramEmit(struct r300_fragment_program_compiler *compiler);
+
+
+extern void r300FragmentProgramDump(
+ struct r300_fragment_program *fp,
+ struct r300_fragment_program_code *code);
+
#endif
diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_emit.c b/src/mesa/drivers/dri/r300/r300_fragprog_emit.c
new file mode 100644
index 0000000000..9ba29feb40
--- /dev/null
+++ b/src/mesa/drivers/dri/r300/r300_fragprog_emit.c
@@ -0,0 +1,2058 @@
+/*
+ * Copyright (C) 2005 Ben Skeggs.
+ *
+ * All Rights Reserved.
+ *
+ * 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 (including the
+ * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+ *
+ */
+
+/**
+ * \file
+ *
+ * Emit the r300_fragment_program_code that can be understood by the hardware.
+ * Input is a pre-transformed radeon_program.
+ *
+ * \author Ben Skeggs <darktama@iinet.net.au>
+ *
+ * \author Jerome Glisse <j.glisse@gmail.com>
+ *
+ * \todo FogOption
+ *
+ * \todo Verify results of opcodes for accuracy, I've only checked them in
+ * specific cases.
+ */
+
+#include "glheader.h"
+#include "macros.h"
+#include "enums.h"
+#include "shader/prog_instruction.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_print.h"
+
+#include "r300_context.h"
+#include "r300_fragprog.h"
+#include "r300_reg.h"
+#include "r300_state.h"
+
+/* Mapping Mesa registers to R300 temporaries */
+struct reg_acc {
+ int reg; /* Assigned hw temp */
+ unsigned int refcount; /* Number of uses by mesa program */
+};
+
+/**
+ * Describe the current lifetime information for an R300 temporary
+ */
+struct reg_lifetime {
+ /* Index of the first slot where this register is free in the sense
+ that it can be used as a new destination register.
+ This is -1 if the register has been assigned to a Mesa register
+ and the last access to the register has not yet been emitted */
+ int free;
+
+ /* Index of the first slot where this register is currently reserved.
+ This is used to stop e.g. a scalar operation from being moved
+ before the allocation time of a register that was first allocated
+ for a vector operation. */
+ int reserved;
+
+ /* Index of the first slot in which the register can be used as a
+ source without losing the value that is written by the last
+ emitted instruction that writes to the register */
+ int vector_valid;
+ int scalar_valid;
+
+ /* Index to the slot where the register was last read.
+ This is also the first slot in which the register may be written again */
+ int vector_lastread;
+ int scalar_lastread;
+};
+
+/**
+ * Store usage information about an ALU instruction slot during the
+ * compilation of a fragment program.
+ */
+#define SLOT_SRC_VECTOR (1<<0)
+#define SLOT_SRC_SCALAR (1<<3)
+#define SLOT_SRC_BOTH (SLOT_SRC_VECTOR | SLOT_SRC_SCALAR)
+#define SLOT_OP_VECTOR (1<<16)
+#define SLOT_OP_SCALAR (1<<17)
+#define SLOT_OP_BOTH (SLOT_OP_VECTOR | SLOT_OP_SCALAR)
+
+struct r300_pfs_compile_slot {
+ /* Bitmask indicating which parts of the slot are used, using SLOT_ constants
+ defined above */
+ unsigned int used;
+
+ /* Selected sources */
+ int vsrc[3];
+ int ssrc[3];
+};
+
+/**
+ * Store information during compilation of fragment programs.
+ */
+struct r300_pfs_compile_state {
+ struct r300_fragment_program_compiler *compiler;
+
+ int nrslots; /* number of ALU slots used so far */
+
+ /* Track which (parts of) slots are already filled with instructions */
+ struct r300_pfs_compile_slot slot[PFS_MAX_ALU_INST];
+
+ /* Track the validity of R300 temporaries */
+ struct reg_lifetime hwtemps[PFS_NUM_TEMP_REGS];
+
+ /* Used to map Mesa's inputs/temps onto hardware temps */
+ int temp_in_use;
+ struct reg_acc temps[PFS_NUM_TEMP_REGS];
+ struct reg_acc inputs[32]; /* don't actually need 32... */
+
+ /* Track usage of hardware temps, for register allocation,
+ * indirection detection, etc. */
+ GLuint used_in_node;
+ GLuint dest_in_node;
+};
+
+
+/*
+ * Usefull macros and values
+ */
+#define ERROR(fmt, args...) do { \
+ fprintf(stderr, "%s::%s(): " fmt "\n", \
+ __FILE__, __FUNCTION__, ##args); \
+ fp->error = GL_TRUE; \
+ } while(0)
+
+#define PFS_INVAL 0xFFFFFFFF
+#define COMPILE_STATE \
+ struct r300_fragment_program *fp = cs->compiler->fp; \
+ struct r300_fragment_program_code *code = cs->compiler->code; \
+ (void)code; (void)fp
+
+#define SWIZZLE_XYZ 0
+#define SWIZZLE_XXX 1
+#define SWIZZLE_YYY 2
+#define SWIZZLE_ZZZ 3
+#define SWIZZLE_WWW 4
+#define SWIZZLE_YZX 5
+#define SWIZZLE_ZXY 6
+#define SWIZZLE_WZY 7
+#define SWIZZLE_111 8
+#define SWIZZLE_000 9
+#define SWIZZLE_HHH 10
+
+#define swizzle(r, x, y, z, w) do_swizzle(cs, r, \
+ ((SWIZZLE_##x<<0)| \
+ (SWIZZLE_##y<<3)| \
+ (SWIZZLE_##z<<6)| \
+ (SWIZZLE_##w<<9)), \
+ 0)
+
+#define REG_TYPE_INPUT 0
+#define REG_TYPE_OUTPUT 1
+#define REG_TYPE_TEMP 2
+#define REG_TYPE_CONST 3
+
+#define REG_TYPE_SHIFT 0
+#define REG_INDEX_SHIFT 2
+#define REG_VSWZ_SHIFT 8
+#define REG_SSWZ_SHIFT 13
+#define REG_NEGV_SHIFT 18
+#define REG_NEGS_SHIFT 19
+#define REG_ABS_SHIFT 20
+#define REG_NO_USE_SHIFT 21 // Hack for refcounting
+#define REG_VALID_SHIFT 22 // Does the register contain a defined value?
+#define REG_BUILTIN_SHIFT 23 // Is it a builtin (like all zero/all one)?
+
+#define REG_TYPE_MASK (0x03 << REG_TYPE_SHIFT)
+#define REG_INDEX_MASK (0x3F << REG_INDEX_SHIFT)
+#define REG_VSWZ_MASK (0x1F << REG_VSWZ_SHIFT)
+#define REG_SSWZ_MASK (0x1F << REG_SSWZ_SHIFT)
+#define REG_NEGV_MASK (0x01 << REG_NEGV_SHIFT)
+#define REG_NEGS_MASK (0x01 << REG_NEGS_SHIFT)
+#define REG_ABS_MASK (0x01 << REG_ABS_SHIFT)
+#define REG_NO_USE_MASK (0x01 << REG_NO_USE_SHIFT)
+#define REG_VALID_MASK (0x01 << REG_VALID_SHIFT)
+#define REG_BUILTIN_MASK (0x01 << REG_BUILTIN_SHIFT)
+
+#define REG(type, index, vswz, sswz, nouse, valid, builtin) \
+ (((type << REG_TYPE_SHIFT) & REG_TYPE_MASK) | \
+ ((index << REG_INDEX_SHIFT) & REG_INDEX_MASK) | \
+ ((nouse << REG_NO_USE_SHIFT) & REG_NO_USE_MASK) | \
+ ((valid << REG_VALID_SHIFT) & REG_VALID_MASK) | \
+ ((builtin << REG_BUILTIN_SHIFT) & REG_BUILTIN_MASK) | \
+ ((vswz << REG_VSWZ_SHIFT) & REG_VSWZ_MASK) | \
+ ((sswz << REG_SSWZ_SHIFT) & REG_SSWZ_MASK))
+#define REG_GET_TYPE(reg) \
+ ((reg & REG_TYPE_MASK) >> REG_TYPE_SHIFT)
+#define REG_GET_INDEX(reg) \
+ ((reg & REG_INDEX_MASK) >> REG_INDEX_SHIFT)
+#define REG_GET_VSWZ(reg) \
+ ((reg & REG_VSWZ_MASK) >> REG_VSWZ_SHIFT)
+#define REG_GET_SSWZ(reg) \
+ ((reg & REG_SSWZ_MASK) >> REG_SSWZ_SHIFT)
+#define REG_GET_NO_USE(reg) \
+ ((reg & REG_NO_USE_MASK) >> REG_NO_USE_SHIFT)
+#define REG_GET_VALID(reg) \
+ ((reg & REG_VALID_MASK) >> REG_VALID_SHIFT)
+#define REG_GET_BUILTIN(reg) \
+ ((reg & REG_BUILTIN_MASK) >> REG_BUILTIN_SHIFT)
+#define REG_SET_TYPE(reg, type) \
+ reg = ((reg & ~REG_TYPE_MASK) | \
+ ((type << REG_TYPE_SHIFT) & REG_TYPE_MASK))
+#define REG_SET_INDEX(reg, index) \
+ reg = ((reg & ~REG_INDEX_MASK) | \
+ ((index << REG_INDEX_SHIFT) & REG_INDEX_MASK))
+#define REG_SET_VSWZ(reg, vswz) \
+ reg = ((reg & ~REG_VSWZ_MASK) | \
+ ((vswz << REG_VSWZ_SHIFT) & REG_VSWZ_MASK))
+#define REG_SET_SSWZ(reg, sswz) \
+ reg = ((reg & ~REG_SSWZ_MASK) | \
+ ((sswz << REG_SSWZ_SHIFT) & REG_SSWZ_MASK))
+#define REG_SET_NO_USE(reg, nouse) \
+ reg = ((reg & ~REG_NO_USE_MASK) | \
+ ((nouse << REG_NO_USE_SHIFT) & REG_NO_USE_MASK))
+#define REG_SET_VALID(reg, valid) \
+ reg = ((reg & ~REG_VALID_MASK) | \
+ ((valid << REG_VALID_SHIFT) & REG_VALID_MASK))
+#define REG_SET_BUILTIN(reg, builtin) \
+ reg = ((reg & ~REG_BUILTIN_MASK) | \
+ ((builtin << REG_BUILTIN_SHIFT) & REG_BUILTIN_MASK))
+#define REG_ABS(reg) \
+ reg = (reg | REG_ABS_MASK)
+#define REG_NEGV(reg) \
+ reg = (reg | REG_NEGV_MASK)
+#define REG_NEGS(reg) \
+ reg = (reg | REG_NEGS_MASK)
+
+#define NOP_INST0 ( \
+ (R300_ALU_OUTC_MAD) | \
+ (R300_ALU_ARGC_ZERO << R300_ALU_ARG0C_SHIFT) | \
+ (R300_ALU_ARGC_ZERO << R300_ALU_ARG1C_SHIFT) | \
+ (R300_ALU_ARGC_ZERO << R300_ALU_ARG2C_SHIFT))
+#define NOP_INST1 ( \
+ ((0 | SRC_CONST) << R300_ALU_SRC0C_SHIFT) | \
+ ((0 | SRC_CONST) << R300_ALU_SRC1C_SHIFT) | \
+ ((0 | SRC_CONST) << R300_ALU_SRC2C_SHIFT))
+#define NOP_INST2 ( \
+ (R300_ALU_OUTA_MAD) | \
+ (R300_ALU_ARGA_ZERO << R300_ALU_ARG0A_SHIFT) | \
+ (R300_ALU_ARGA_ZERO << R300_ALU_ARG1A_SHIFT) | \
+ (R300_ALU_ARGA_ZERO << R300_ALU_ARG2A_SHIFT))
+#define NOP_INST3 ( \
+ ((0 | SRC_CONST) << R300_ALU_SRC0A_SHIFT) | \
+ ((0 | SRC_CONST) << R300_ALU_SRC1A_SHIFT) | \
+ ((0 | SRC_CONST) << R300_ALU_SRC2A_SHIFT))
+
+
+/*
+ * Datas structures for fragment program generation
+ */
+
+/* description of r300 native hw instructions */
+static const struct {
+ const char *name;
+ int argc;
+ int v_op;
+ int s_op;
+} r300_fpop[] = {
+ /* *INDENT-OFF* */
+ {"MAD", 3, R300_ALU_OUTC_MAD, R300_ALU_OUTA_MAD},
+ {"DP3", 2, R300_ALU_OUTC_DP3, R300_ALU_OUTA_DP4},
+ {"DP4", 2, R300_ALU_OUTC_DP4, R300_ALU_OUTA_DP4},
+ {"MIN", 2, R300_ALU_OUTC_MIN, R300_ALU_OUTA_MIN},
+ {"MAX", 2, R300_ALU_OUTC_MAX, R300_ALU_OUTA_MAX},
+ {"CMP", 3, R300_ALU_OUTC_CMP, R300_ALU_OUTA_CMP},
+ {"FRC", 1, R300_ALU_OUTC_FRC, R300_ALU_OUTA_FRC},
+ {"EX2", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_EX2},
+ {"LG2", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_LG2},
+ {"RCP", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_RCP},
+ {"RSQ", 1, R300_ALU_OUTC_REPL_ALPHA, R300_ALU_OUTA_RSQ},
+ {"REPL_ALPHA", 1, R300_ALU_OUTC_REPL_ALPHA, PFS_INVAL},
+ {"CMPH", 3, R300_ALU_OUTC_CMPH, PFS_INVAL},
+ /* *INDENT-ON* */
+};
+
+/* vector swizzles r300 can support natively, with a couple of
+ * cases we handle specially
+ *
+ * REG_VSWZ/REG_SSWZ is an index into this table
+ */
+
+/* mapping from SWIZZLE_* to r300 native values for scalar insns */
+#define SWIZZLE_HALF 6
+
+#define MAKE_SWZ3(x, y, z) (MAKE_SWIZZLE4(SWIZZLE_##x, \
+ SWIZZLE_##y, \
+ SWIZZLE_##z, \
+ SWIZZLE_ZERO))
+/* native swizzles */
+static const struct r300_pfs_swizzle {
+ GLuint hash; /* swizzle value this matches */
+ GLuint base; /* base value for hw swizzle */
+ GLuint stride; /* difference in base between arg0/1/2 */
+ GLuint flags;
+} v_swiz[] = {
+ /* *INDENT-OFF* */
+ {MAKE_SWZ3(X, Y, Z), R300_ALU_ARGC_SRC0C_XYZ, 4, SLOT_SRC_VECTOR},
+ {MAKE_SWZ3(X, X, X), R300_ALU_ARGC_SRC0C_XXX, 4, SLOT_SRC_VECTOR},
+ {MAKE_SWZ3(Y, Y, Y), R300_ALU_ARGC_SRC0C_YYY, 4, SLOT_SRC_VECTOR},
+ {MAKE_SWZ3(Z, Z, Z), R300_ALU_ARGC_SRC0C_ZZZ, 4, SLOT_SRC_VECTOR},
+ {MAKE_SWZ3(W, W, W), R300_ALU_ARGC_SRC0A, 1, SLOT_SRC_SCALAR},
+ {MAKE_SWZ3(Y, Z, X), R300_ALU_ARGC_SRC0C_YZX, 1, SLOT_SRC_VECTOR},
+ {MAKE_SWZ3(Z, X, Y), R300_ALU_ARGC_SRC0C_ZXY, 1, SLOT_SRC_VECTOR},
+ {MAKE_SWZ3(W, Z, Y), R300_ALU_ARGC_SRC0CA_WZY, 1, SLOT_SRC_BOTH},
+ {MAKE_SWZ3(ONE, ONE, ONE), R300_ALU_ARGC_ONE, 0, 0},
+ {MAKE_SWZ3(ZERO, ZERO, ZERO), R300_ALU_ARGC_ZERO, 0, 0},
+ {MAKE_SWZ3(HALF, HALF, HALF), R300_ALU_ARGC_HALF, 0, 0},
+ {PFS_INVAL, 0, 0, 0},
+ /* *INDENT-ON* */
+};
+
+/* used during matching of non-native swizzles */
+#define SWZ_X_MASK (7 << 0)
+#define SWZ_Y_MASK (7 << 3)
+#define SWZ_Z_MASK (7 << 6)
+#define SWZ_W_MASK (7 << 9)
+static const struct {
+ GLuint hash; /* used to mask matching swizzle components */
+ int mask; /* actual outmask */
+ int count; /* count of components matched */
+} s_mask[] = {
+ /* *INDENT-OFF* */
+ {SWZ_X_MASK | SWZ_Y_MASK | SWZ_Z_MASK, 1 | 2 | 4, 3},
+ {SWZ_X_MASK | SWZ_Y_MASK, 1 | 2, 2},
+ {SWZ_X_MASK | SWZ_Z_MASK, 1 | 4, 2},
+ {SWZ_Y_MASK | SWZ_Z_MASK, 2 | 4, 2},
+ {SWZ_X_MASK, 1, 1},
+ {SWZ_Y_MASK, 2, 1},
+ {SWZ_Z_MASK, 4, 1},
+ {PFS_INVAL, PFS_INVAL, PFS_INVAL}
+ /* *INDENT-ON* */
+};
+
+static const struct {
+ int base; /* hw value of swizzle */
+ int stride; /* difference between SRC0/1/2 */
+ GLuint flags;
+} s_swiz[] = {
+ /* *INDENT-OFF* */
+ {R300_ALU_ARGA_SRC0C_X, 3, SLOT_SRC_VECTOR},
+ {R300_ALU_ARGA_SRC0C_Y, 3, SLOT_SRC_VECTOR},
+ {R300_ALU_ARGA_SRC0C_Z, 3, SLOT_SRC_VECTOR},
+ {R300_ALU_ARGA_SRC0A, 1, SLOT_SRC_SCALAR},
+ {R300_ALU_ARGA_ZERO, 0, 0},
+ {R300_ALU_ARGA_ONE, 0, 0},
+ {R300_ALU_ARGA_HALF, 0, 0}
+ /* *INDENT-ON* */
+};
+
+/* boiler-plate reg, for convenience */
+static const GLuint undef = REG(REG_TYPE_TEMP,
+ 0,
+ SWIZZLE_XYZ,
+ SWIZZLE_W,
+ GL_FALSE,
+ GL_FALSE,
+ GL_FALSE);
+
+/* constant one source */
+static const GLuint pfs_one = REG(REG_TYPE_CONST,
+ 0,
+ SWIZZLE_111,
+ SWIZZLE_ONE,
+ GL_FALSE,
+ GL_TRUE,
+ GL_TRUE);
+
+/* constant half source */
+static const GLuint pfs_half = REG(REG_TYPE_CONST,
+ 0,
+ SWIZZLE_HHH,
+ SWIZZLE_HALF,
+ GL_FALSE,
+ GL_TRUE,
+ GL_TRUE);
+
+/* constant zero source */
+static const GLuint pfs_zero = REG(REG_TYPE_CONST,
+ 0,
+ SWIZZLE_000,
+ SWIZZLE_ZERO,
+ GL_FALSE,
+ GL_TRUE,
+ GL_TRUE);
+
+/*
+ * Common functions prototypes
+ */
+static void emit_arith(struct r300_pfs_compile_state *cs, int op,
+ GLuint dest, int mask,
+ GLuint src0, GLuint src1, GLuint src2, int flags);
+
+/**
+ * Get an R300 temporary that can be written to in the given slot.
+ */
+static int get_hw_temp(struct r300_pfs_compile_state *cs, int slot)
+{
+ COMPILE_STATE;
+ int r;
+
+ for (r = 0; r < PFS_NUM_TEMP_REGS; ++r) {
+ if (cs->hwtemps[r].free >= 0 && cs->hwtemps[r].free <= slot)
+ break;
+ }
+
+ if (r >= PFS_NUM_TEMP_REGS) {
+ ERROR("Out of hardware temps\n");
+ return 0;
+ }
+ // Reserved is used to avoid the following scenario:
+ // R300 temporary X is first assigned to Mesa temporary Y during vector ops
+ // R300 temporary X is then assigned to Mesa temporary Z for further vector ops
+ // Then scalar ops on Mesa temporary Z are emitted and move back in time
+ // to overwrite the value of temporary Y.
+ // End scenario.
+ cs->hwtemps[r].reserved = cs->hwtemps[r].free;
+ cs->hwtemps[r].free = -1;
+
+ // Reset to some value that won't mess things up when the user
+ // tries to read from a temporary that hasn't been assigned a value yet.
+ // In the normal case, vector_valid and scalar_valid should be set to
+ // a sane value by the first emit that writes to this temporary.
+ cs->hwtemps[r].vector_valid = 0;
+ cs->hwtemps[r].scalar_valid = 0;
+
+ if (r > code->max_temp_idx)
+ code->max_temp_idx = r;
+
+ return r;
+}
+
+/**
+ * Get an R300 temporary that will act as a TEX destination register.
+ */
+static int get_hw_temp_tex(struct r300_pfs_compile_state *cs)
+{
+ COMPILE_STATE;
+ int r;
+
+ for (r = 0; r < PFS_NUM_TEMP_REGS; ++r) {
+ if (cs->used_in_node & (1 << r))
+ continue;
+
+ // Note: Be very careful here
+ if (cs->hwtemps[r].free >= 0 && cs->hwtemps[r].free <= 0)
+ break;
+ }
+
+ if (r >= PFS_NUM_TEMP_REGS)
+ return get_hw_temp(cs, 0); /* Will cause an indirection */
+
+ cs->hwtemps[r].reserved = cs->hwtemps[r].free;
+ cs->hwtemps[r].free = -1;
+
+ // Reset to some value that won't mess things up when the user
+ // tries to read from a temporary that hasn't been assigned a value yet.
+ // In the normal case, vector_valid and scalar_valid should be set to
+ // a sane value by the first emit that writes to this temporary.
+ cs->hwtemps[r].vector_valid = cs->nrslots;
+ cs->hwtemps[r].scalar_valid = cs->nrslots;
+
+ if (r > code->max_temp_idx)
+ code->max_temp_idx = r;
+
+ return r;
+}
+
+/**
+ * Mark the given hardware register as free.
+ */
+static void free_hw_temp(struct r300_pfs_compile_state *cs, int idx)
+{
+ // Be very careful here. Consider sequences like
+ // MAD r0, r1,r2,r3
+ // TEX r4, ...
+ // The TEX instruction may be moved in front of the MAD instruction
+ // due to the way nodes work. We don't want to alias r1 and r4 in
+ // this case.
+ // I'm certain the register allocation could be further sanitized,
+ // but it's tricky because of stuff that can happen inside emit_tex
+ // and emit_arith.
+ cs->hwtemps[idx].free = cs->nrslots + 1;
+}
+
+/**
+ * Create a new Mesa temporary register.
+ */
+static GLuint get_temp_reg(struct r300_pfs_compile_state *cs)
+{
+ COMPILE_STATE;
+ GLuint r = undef;
+ GLuint index;
+
+ index = ffs(~cs->temp_in_use);
+ if (!index) {
+ ERROR("Out of program temps\n");
+ return r;
+ }
+
+ cs->temp_in_use |= (1 << --index);
+ cs->temps[index].refcount = 0xFFFFFFFF;
+ cs->temps[index].reg = -1;
+
+ REG_SET_TYPE(r, REG_TYPE_TEMP);
+ REG_SET_INDEX(r, index);
+ REG_SET_VALID(r, GL_TRUE);
+ return r;
+}
+
+/**
+ * Free a Mesa temporary and the associated R300 temporary.
+ */
+static void free_temp(struct r300_pfs_compile_state *cs, GLuint r)
+{
+ GLuint index = REG_GET_INDEX(r);
+
+ if (!(cs->temp_in_use & (1 << index)))
+ return;
+
+ if (REG_GET_TYPE(r) == REG_TYPE_TEMP) {
+ free_hw_temp(cs, cs->temps[index].reg);
+ cs->temps[index].reg = -1;
+ cs->temp_in_use &= ~(1 << index);
+ } else if (REG_GET_TYPE(r) == REG_TYPE_INPUT) {
+ free_hw_temp(cs, cs->inputs[index].reg);
+ cs->inputs[index].reg = -1;
+ }
+}
+
+/**
+ * Emit a hardware constant/parameter.
+ *
+ * \p cp Stable pointer to an array of 4 floats.
+ * The pointer must be stable in the sense that it remains to be valid
+ * and hold the contents of the constant/parameter throughout the lifetime
+ * of the fragment program (actually, up until the next time the fragment
+ * program is translated).
+ */
+static GLuint emit_const4fv(struct r300_pfs_compile_state *cs,
+ const GLfloat * cp)
+{
+ COMPILE_STATE;
+ GLuint reg = undef;
+ int index;
+
+ for (index = 0; index < code->const_nr; ++index) {
+ if (code->constant[index] == cp)
+ break;
+ }
+
+ if (index >= code->const_nr) {
+ if (index >= PFS_NUM_CONST_REGS) {
+ ERROR("Out of hw constants!\n");
+ return reg;
+ }
+
+ code->const_nr++;
+ code->constant[index] = cp;
+ }
+
+ REG_SET_TYPE(reg, REG_TYPE_CONST);
+ REG_SET_INDEX(reg, index);
+ REG_SET_VALID(reg, GL_TRUE);
+ return reg;
+}
+
+static inline GLuint negate(GLuint r)
+{
+ REG_NEGS(r);
+ REG_NEGV(r);
+ return r;
+}
+
+/* Hack, to prevent clobbering sources used multiple times when
+ * emulating non-native instructions
+ */
+static inline GLuint keep(GLuint r)
+{
+ REG_SET_NO_USE(r, GL_TRUE);
+ return r;
+}
+
+static inline GLuint absolute(GLuint r)
+{
+ REG_ABS(r);
+ return r;
+}
+
+static int swz_native(struct r300_pfs_compile_state *cs,
+ GLuint src, GLuint * r, GLuint arbneg)
+{
+ COMPILE_STATE;
+
+ /* Native swizzle, handle negation */
+ src = (src & ~REG_NEGS_MASK) | (((arbneg >> 3) & 1) << REG_NEGS_SHIFT);
+
+ if ((arbneg & 0x7) == 0x0) {
+ src = src & ~REG_NEGV_MASK;
+ *r = src;
+ } else if ((arbneg & 0x7) == 0x7) {
+ src |= REG_NEGV_MASK;
+ *r = src;
+ } else {
+ if (!REG_GET_VALID(*r))
+ *r = get_temp_reg(cs);
+ src |= REG_NEGV_MASK;
+ emit_arith(cs,
+ PFS_OP_MAD,
+ *r, arbneg & 0x7, keep(src), pfs_one, pfs_zero, 0);
+ src = src & ~REG_NEGV_MASK;
+ emit_arith(cs,
+ PFS_OP_MAD,
+ *r,
+ (arbneg ^ 0x7) | WRITEMASK_W,
+ src, pfs_one, pfs_zero, 0);
+ }
+
+ return 3;
+}
+
+static int swz_emit_partial(struct r300_pfs_compile_state *cs,
+ GLuint src,
+ GLuint * r, int mask, int mc, GLuint arbneg)
+{
+ COMPILE_STATE;
+ GLuint tmp;
+ GLuint wmask = 0;
+
+ if (!REG_GET_VALID(*r))
+ *r = get_temp_reg(cs);
+
+ /* A partial match, VSWZ/mask define what parts of the
+ * desired swizzle we match
+ */
+ if (mc + s_mask[mask].count == 3) {
+ wmask = WRITEMASK_W;
+ src |= ((arbneg >> 3) & 1) << REG_NEGS_SHIFT;
+ }
+
+ tmp = arbneg & s_mask[mask].mask;
+ if (tmp) {
+ tmp = tmp ^ s_mask[mask].mask;
+ if (tmp) {
+ emit_arith(cs,
+ PFS_OP_MAD,
+ *r,
+ arbneg & s_mask[mask].mask,
+ keep(src) | REG_NEGV_MASK,
+ pfs_one, pfs_zero, 0);
+ if (!wmask) {
+ REG_SET_NO_USE(src, GL_TRUE);
+ } else {
+ REG_SET_NO_USE(src, GL_FALSE);
+ }
+ emit_arith(cs,
+ PFS_OP_MAD,
+ *r, tmp | wmask, src, pfs_one, pfs_zero, 0);
+ } else {
+ if (!wmask) {
+ REG_SET_NO_USE(src, GL_TRUE);
+ } else {
+ REG_SET_NO_USE(src, GL_FALSE);
+ }
+ emit_arith(cs,
+ PFS_OP_MAD,
+ *r,
+ (arbneg & s_mask[mask].mask) | wmask,
+ src | REG_NEGV_MASK, pfs_one, pfs_zero, 0);
+ }
+ } else {
+ if (!wmask) {
+ REG_SET_NO_USE(src, GL_TRUE);
+ } else {
+ REG_SET_NO_USE(src, GL_FALSE);
+ }
+ emit_arith(cs, PFS_OP_MAD,
+ *r,
+ s_mask[mask].mask | wmask,
+ src, pfs_one, pfs_zero, 0);
+ }
+
+ return s_mask[mask].count;
+}
+
+static GLuint do_swizzle(struct r300_pfs_compile_state *cs,
+ GLuint src, GLuint arbswz, GLuint arbneg)
+{
+ COMPILE_STATE;
+ GLuint r = undef;
+ GLuint vswz;
+ int c_mask = 0;
+ int v_match = 0;
+
+ /* If swizzling from something without an XYZW native swizzle,
+ * emit result to a temp, and do new swizzle from the temp.
+ */
+#if 0
+ if (REG_GET_VSWZ(src) != SWIZZLE_XYZ || REG_GET_SSWZ(src) != SWIZZLE_W) {
+ GLuint temp = get_temp_reg(fp);
+ emit_arith(fp,
+ PFS_OP_MAD,
+ temp, WRITEMASK_XYZW, src, pfs_one, pfs_zero, 0);
+ src = temp;
+ }
+#endif
+
+ if (REG_GET_VSWZ(src) != SWIZZLE_XYZ || REG_GET_SSWZ(src) != SWIZZLE_W) {
+ GLuint vsrcswz =
+ (v_swiz[REG_GET_VSWZ(src)].
+ hash & (SWZ_X_MASK | SWZ_Y_MASK | SWZ_Z_MASK)) |
+ REG_GET_SSWZ(src) << 9;
+ GLint i;
+
+ GLuint newswz = 0;
+ GLuint offset;
+ for (i = 0; i < 4; ++i) {
+ offset = GET_SWZ(arbswz, i);
+
+ newswz |=
+ (offset <= 3) ? GET_SWZ(vsrcswz,
+ offset) << i *
+ 3 : offset << i * 3;
+ }
+
+ arbswz = newswz & (SWZ_X_MASK | SWZ_Y_MASK | SWZ_Z_MASK);
+ REG_SET_SSWZ(src, GET_SWZ(newswz, 3));
+ } else {
+ /* set scalar swizzling */
+ REG_SET_SSWZ(src, GET_SWZ(arbswz, 3));
+
+ }
+ do {
+ vswz = REG_GET_VSWZ(src);
+ do {
+ int chash;
+
+ REG_SET_VSWZ(src, vswz);
+ chash = v_swiz[REG_GET_VSWZ(src)].hash &
+ s_mask[c_mask].hash;
+
+ if (chash == (arbswz & s_mask[c_mask].hash)) {
+ if (s_mask[c_mask].count == 3) {
+ v_match += swz_native(cs,
+ src, &r, arbneg);
+ } else {
+ v_match += swz_emit_partial(cs,
+ src,
+ &r,
+ c_mask,
+ v_match,
+ arbneg);
+ }
+
+ if (v_match == 3)
+ return r;
+
+ /* Fill with something invalid.. all 0's was
+ * wrong before, matched SWIZZLE_X. So all
+ * 1's will be okay for now
+ */
+ arbswz |= (PFS_INVAL & s_mask[c_mask].hash);
+ }
+ } while (v_swiz[++vswz].hash != PFS_INVAL);
+ REG_SET_VSWZ(src, SWIZZLE_XYZ);
+ } while (s_mask[++c_mask].hash != PFS_INVAL);
+
+ ERROR("should NEVER get here\n");
+ return r;
+}
+
+static GLuint t_src(struct r300_pfs_compile_state *cs,
+ struct prog_src_register fpsrc)
+{
+ COMPILE_STATE;
+ GLuint r = undef;
+
+ switch (fpsrc.File) {
+ case PROGRAM_TEMPORARY:
+ REG_SET_INDEX(r, fpsrc.Index);
+ REG_SET_VALID(r, GL_TRUE);
+ REG_SET_TYPE(r, REG_TYPE_TEMP);
+ break;
+ case PROGRAM_INPUT:
+ REG_SET_INDEX(r, fpsrc.Index);
+ REG_SET_VALID(r, GL_TRUE);
+ REG_SET_TYPE(r, REG_TYPE_INPUT);
+ break;
+ case PROGRAM_LOCAL_PARAM:
+ r = emit_const4fv(cs,
+ fp->mesa_program.Base.LocalParams[fpsrc.
+ Index]);
+ break;
+ case PROGRAM_ENV_PARAM:
+ r = emit_const4fv(cs,
+ cs->compiler->r300->radeon.glCtx->FragmentProgram.Parameters[fpsrc.Index]);
+ break;
+ case PROGRAM_STATE_VAR:
+ case PROGRAM_NAMED_PARAM:
+ case PROGRAM_CONSTANT:
+ r = emit_const4fv(cs,
+ fp->mesa_program.Base.Parameters->
+ ParameterValues[fpsrc.Index]);
+ break;
+ case PROGRAM_BUILTIN:
+ switch(fpsrc.Swizzle) {
+ case SWIZZLE_1111: r = pfs_one; break;
+ case SWIZZLE_0000: r = pfs_zero; break;
+ default:
+ ERROR("bad PROGRAM_BUILTIN swizzle %u\n", fpsrc.Swizzle);
+ break;
+ }
+ break;
+ default:
+ ERROR("unknown SrcReg->File %x\n", fpsrc.File);
+ return r;
+ }
+
+ /* no point swizzling ONE/ZERO/HALF constants... */
+ if (REG_GET_VSWZ(r) < SWIZZLE_111 || REG_GET_SSWZ(r) < SWIZZLE_ZERO)
+ r = do_swizzle(cs, r, fpsrc.Swizzle, fpsrc.NegateBase);
+ if (fpsrc.Abs)
+ r = absolute(r);
+ if (fpsrc.NegateAbs)
+ r = negate(r);
+ return r;
+}
+
+static GLuint t_scalar_src(struct r300_pfs_compile_state *cs,
+ struct prog_src_register fpsrc)
+{
+ struct prog_src_register src = fpsrc;
+ int sc = GET_SWZ(fpsrc.Swizzle, 0); /* X */
+
+ src.Swizzle = ((sc << 0) | (sc << 3) | (sc << 6) | (sc << 9));
+
+ return t_src(cs, src);
+}
+
+static GLuint t_dst(struct r300_pfs_compile_state *cs,
+ struct prog_dst_register dest)
+{
+ COMPILE_STATE;
+ GLuint r = undef;
+
+ switch (dest.File) {
+ case PROGRAM_TEMPORARY:
+ REG_SET_INDEX(r, dest.Index);
+ REG_SET_VALID(r, GL_TRUE);
+ REG_SET_TYPE(r, REG_TYPE_TEMP);
+ return r;
+ case PROGRAM_OUTPUT:
+ REG_SET_TYPE(r, REG_TYPE_OUTPUT);
+ switch (dest.Index) {
+ case FRAG_RESULT_COLR:
+ case FRAG_RESULT_DEPR:
+ REG_SET_INDEX(r, dest.Index);
+ REG_SET_VALID(r, GL_TRUE);
+ return r;
+ default:
+ ERROR("Bad DstReg->Index 0x%x\n", dest.Index);
+ return r;
+ }
+ default:
+ ERROR("Bad DstReg->File 0x%x\n", dest.File);
+ return r;
+ }
+}
+
+static int t_hw_src(struct r300_pfs_compile_state *cs, GLuint src, GLboolean tex)
+{
+ COMPILE_STATE;
+ int idx;
+ int index = REG_GET_INDEX(src);
+
+ switch (REG_GET_TYPE(src)) {
+ case REG_TYPE_TEMP:
+ /* NOTE: if reg==-1 here, a source is being read that
+ * hasn't been written to. Undefined results.
+ */
+ if (cs->temps[index].reg == -1)
+ cs->temps[index].reg = get_hw_temp(cs, cs->nrslots);
+
+ idx = cs->temps[index].reg;
+
+ if (!REG_GET_NO_USE(src) && (--cs->temps[index].refcount == 0))
+ free_temp(cs, src);
+ break;
+ case REG_TYPE_INPUT:
+ idx = cs->inputs[index].reg;
+
+ if (!REG_GET_NO_USE(src) && (--cs->inputs[index].refcount == 0))
+ free_hw_temp(cs, cs->inputs[index].reg);
+ break;
+ case REG_TYPE_CONST:
+ return (index | SRC_CONST);
+ default:
+ ERROR("Invalid type for source reg\n");
+ return (0 | SRC_CONST);
+ }
+
+ if (!tex)
+ cs->used_in_node |= (1 << idx);
+
+ return idx;
+}
+
+static int t_hw_dst(struct r300_pfs_compile_state *cs,
+ GLuint dest, GLboolean tex, int slot)
+{
+ COMPILE_STATE;
+ int idx;
+ GLuint index = REG_GET_INDEX(dest);
+ assert(REG_GET_VALID(dest));
+
+ switch (REG_GET_TYPE(dest)) {
+ case REG_TYPE_TEMP:
+ if (cs->temps[REG_GET_INDEX(dest)].reg == -1) {
+ if (!tex) {
+ cs->temps[index].reg = get_hw_temp(cs, slot);
+ } else {
+ cs->temps[index].reg = get_hw_temp_tex(cs);
+ }
+ }
+ idx = cs->temps[index].reg;
+
+ if (!REG_GET_NO_USE(dest) && (--cs->temps[index].refcount == 0))
+ free_temp(cs, dest);
+
+ cs->dest_in_node |= (1 << idx);
+ cs->used_in_node |= (1 << idx);
+ break;
+ case REG_TYPE_OUTPUT:
+ switch (index) {
+ case FRAG_RESULT_COLR:
+ code->node[code->cur_node].flags |= R300_RGBA_OUT;
+ break;
+ case FRAG_RESULT_DEPR:
+ fp->WritesDepth = GL_TRUE;
+ code->node[code->cur_node].flags |= R300_W_OUT;
+ break;
+ }
+ return index;
+ break;
+ default:
+ ERROR("invalid dest reg type %d\n", REG_GET_TYPE(dest));
+ return 0;
+ }
+
+ return idx;
+}
+
+static void emit_nop(struct r300_pfs_compile_state *cs)
+{
+ COMPILE_STATE;
+
+ if (cs->nrslots >= PFS_MAX_ALU_INST) {
+ ERROR("Out of ALU instruction slots\n");
+ return;
+ }
+
+ code->alu.inst[cs->nrslots].inst0 = NOP_INST0;
+ code->alu.inst[cs->nrslots].inst1 = NOP_INST1;
+ code->alu.inst[cs->nrslots].inst2 = NOP_INST2;
+ code->alu.inst[cs->nrslots].inst3 = NOP_INST3;
+ cs->nrslots++;
+}
+
+static void emit_tex(struct r300_pfs_compile_state *cs,
+ struct prog_instruction *fpi, int opcode)
+{
+ COMPILE_STATE;
+ GLuint coord = t_src(cs, fpi->SrcReg[0]);
+ GLuint dest = undef;
+ GLuint din, uin;
+ int unit = fpi->TexSrcUnit;
+ int hwsrc, hwdest;
+
+ /* Ensure correct node indirection */
+ uin = cs->used_in_node;
+ din = cs->dest_in_node;
+
+ /* Resolve source/dest to hardware registers */
+ hwsrc = t_hw_src(cs, coord, GL_TRUE);
+
+ if (opcode != R300_TEX_OP_KIL) {
+ dest = t_dst(cs, fpi->DstReg);
+
+ hwdest =
+ t_hw_dst(cs, dest, GL_TRUE,
+ code->node[code->cur_node].alu_offset);
+
+ /* Use a temp that hasn't been used in this node, rather
+ * than causing an indirection
+ */
+ if (uin & (1 << hwdest)) {
+ free_hw_temp(cs, hwdest);
+ hwdest = get_hw_temp_tex(cs);
+ cs->temps[REG_GET_INDEX(dest)].reg = hwdest;
+ }
+ } else {
+ hwdest = 0;
+ unit = 0;
+ }
+
+ /* Indirection if source has been written in this node, or if the
+ * dest has been read/written in this node
+ */
+ if ((REG_GET_TYPE(coord) != REG_TYPE_CONST &&
+ (din & (1 << hwsrc))) || (uin & (1 << hwdest))) {
+
+ /* Finish off current node */
+ if (code->node[code->cur_node].alu_offset == cs->nrslots)
+ emit_nop(cs);
+
+ code->node[code->cur_node].alu_end =
+ cs->nrslots - code->node[code->cur_node].alu_offset - 1;
+ assert(code->node[code->cur_node].alu_end >= 0);
+
+ if (++code->cur_node >= PFS_MAX_TEX_INDIRECT) {
+ ERROR("too many levels of texture indirection\n");
+ return;
+ }
+
+ /* Start new node */
+ code->node[code->cur_node].tex_offset = code->tex.length;
+ code->node[code->cur_node].alu_offset = cs->nrslots;
+ code->node[code->cur_node].tex_end = -1;
+ code->node[code->cur_node].alu_end = -1;
+ code->node[code->cur_node].flags = 0;
+ cs->used_in_node = 0;
+ cs->dest_in_node = 0;
+ }
+
+ if (code->cur_node == 0)
+ code->first_node_has_tex = 1;
+
+ code->tex.inst[code->tex.length++] = 0 | (hwsrc << R300_SRC_ADDR_SHIFT)
+ | (hwdest << R300_DST_ADDR_SHIFT)
+ | (unit << R300_TEX_ID_SHIFT)
+ | (opcode << R300_TEX_INST_SHIFT);
+
+ cs->dest_in_node |= (1 << hwdest);
+ if (REG_GET_TYPE(coord) != REG_TYPE_CONST)
+ cs->used_in_node |= (1 << hwsrc);
+
+ code->node[code->cur_node].tex_end++;
+}
+
+/**
+ * Returns the first slot where we could possibly allow writing to dest,
+ * according to register allocation.
+ */
+static int get_earliest_allowed_write(struct r300_pfs_compile_state *cs,
+ GLuint dest, int mask)
+{
+ COMPILE_STATE;
+ int idx;
+ int pos;
+ GLuint index = REG_GET_INDEX(dest);
+ assert(REG_GET_VALID(dest));
+
+ switch (REG_GET_TYPE(dest)) {
+ case REG_TYPE_TEMP:
+ if (cs->temps[index].reg == -1)
+ return 0;
+
+ idx = cs->temps[index].reg;
+ break;
+ case REG_TYPE_OUTPUT:
+ return 0;
+ default:
+ ERROR("invalid dest reg type %d\n", REG_GET_TYPE(dest));
+ return 0;
+ }
+
+ pos = cs->hwtemps[idx].reserved;
+ if (mask & WRITEMASK_XYZ) {
+ if (pos < cs->hwtemps[idx].vector_lastread)
+ pos = cs->hwtemps[idx].vector_lastread;
+ }
+ if (mask & WRITEMASK_W) {
+ if (pos < cs->hwtemps[idx].scalar_lastread)
+ pos = cs->hwtemps[idx].scalar_lastread;
+ }
+
+ return pos;
+}
+
+/**
+ * Allocates a slot for an ALU instruction that can consist of
+ * a vertex part or a scalar part or both.
+ *
+ * Sources from src (src[0] to src[argc-1]) are added to the slot in the
+ * appropriate position (vector and/or scalar), and their positions are
+ * recorded in the srcpos array.
+ *
+ * This function emits instruction code for the source fetch and the
+ * argument selection. It does not emit instruction code for the
+ * opcode or the destination selection.
+ *
+ * @return the index of the slot
+ */
+static int find_and_prepare_slot(struct r300_pfs_compile_state *cs,
+ GLboolean emit_vop,
+ GLboolean emit_sop,
+ int argc, GLuint * src, GLuint dest, int mask)
+{
+ COMPILE_STATE;
+ int hwsrc[3];
+ int srcpos[3];
+ unsigned int used;
+ int tempused;
+ int tempvsrc[3];
+ int tempssrc[3];
+ int pos;
+ int regnr;
+ int i, j;
+
+ // Determine instruction slots, whether sources are required on
+ // vector or scalar side, and the smallest slot number where
+ // all source registers are available
+ used = 0;
+ if (emit_vop)
+ used |= SLOT_OP_VECTOR;
+ if (emit_sop)
+ used |= SLOT_OP_SCALAR;
+
+ pos = get_earliest_allowed_write(cs, dest, mask);
+
+ if (code->node[code->cur_node].alu_offset > pos)
+ pos = code->node[code->cur_node].alu_offset;
+ for (i = 0; i < argc; ++i) {
+ if (!REG_GET_BUILTIN(src[i])) {
+ if (emit_vop)
+ used |= v_swiz[REG_GET_VSWZ(src[i])].flags << i;
+ if (emit_sop)
+ used |= s_swiz[REG_GET_SSWZ(src[i])].flags << i;
+ }
+
+ hwsrc[i] = t_hw_src(cs, src[i], GL_FALSE); /* Note: sideeffects wrt refcounting! */
+ regnr = hwsrc[i] & 31;
+
+ if (REG_GET_TYPE(src[i]) == REG_TYPE_TEMP) {
+ if (used & (SLOT_SRC_VECTOR << i)) {
+ if (cs->hwtemps[regnr].vector_valid > pos)
+ pos = cs->hwtemps[regnr].vector_valid;
+ }
+ if (used & (SLOT_SRC_SCALAR << i)) {
+ if (cs->hwtemps[regnr].scalar_valid > pos)
+ pos = cs->hwtemps[regnr].scalar_valid;
+ }
+ }
+ }
+
+ // Find a slot that fits
+ for (;; ++pos) {
+ if (cs->slot[pos].used & used & SLOT_OP_BOTH)
+ continue;
+
+ if (pos >= cs->nrslots) {
+ if (cs->nrslots >= PFS_MAX_ALU_INST) {
+ ERROR("Out of ALU instruction slots\n");
+ return -1;
+ }
+
+ code->alu.inst[pos].inst0 = NOP_INST0;
+ code->alu.inst[pos].inst1 = NOP_INST1;
+ code->alu.inst[pos].inst2 = NOP_INST2;
+ code->alu.inst[pos].inst3 = NOP_INST3;
+
+ cs->nrslots++;
+ }
+ // Note: When we need both parts (vector and scalar) of a source,
+ // we always try to put them into the same position. This makes the
+ // code easier to read, and it is optimal (i.e. one doesn't gain
+ // anything by splitting the parts).
+ // It also avoids headaches with swizzles that access both parts (i.e WXY)
+ tempused = cs->slot[pos].used;
+ for (i = 0; i < 3; ++i) {
+ tempvsrc[i] = cs->slot[pos].vsrc[i];
+ tempssrc[i] = cs->slot[pos].ssrc[i];
+ }
+
+ for (i = 0; i < argc; ++i) {
+ int flags = (used >> i) & SLOT_SRC_BOTH;
+
+ if (!flags) {
+ srcpos[i] = 0;
+ continue;
+ }
+
+ for (j = 0; j < 3; ++j) {
+ if ((tempused >> j) & flags & SLOT_SRC_VECTOR) {
+ if (tempvsrc[j] != hwsrc[i])
+ continue;
+ }
+
+ if ((tempused >> j) & flags & SLOT_SRC_SCALAR) {
+ if (tempssrc[j] != hwsrc[i])
+ continue;
+ }
+
+ break;
+ }
+
+ if (j == 3)
+ break;
+
+ srcpos[i] = j;
+ tempused |= flags << j;
+ if (flags & SLOT_SRC_VECTOR)
+ tempvsrc[j] = hwsrc[i];
+ if (flags & SLOT_SRC_SCALAR)
+ tempssrc[j] = hwsrc[i];
+ }
+
+ if (i == argc)
+ break;
+ }
+
+ // Found a slot, reserve it
+ cs->slot[pos].used = tempused | (used & SLOT_OP_BOTH);
+ for (i = 0; i < 3; ++i) {
+ cs->slot[pos].vsrc[i] = tempvsrc[i];
+ cs->slot[pos].ssrc[i] = tempssrc[i];
+ }
+
+ for (i = 0; i < argc; ++i) {
+ if (REG_GET_TYPE(src[i]) == REG_TYPE_TEMP) {
+ int regnr = hwsrc[i] & 31;
+
+ if (used & (SLOT_SRC_VECTOR << i)) {
+ if (cs->hwtemps[regnr].vector_lastread < pos)
+ cs->hwtemps[regnr].vector_lastread =
+ pos;
+ }
+ if (used & (SLOT_SRC_SCALAR << i)) {
+ if (cs->hwtemps[regnr].scalar_lastread < pos)
+ cs->hwtemps[regnr].scalar_lastread =
+ pos;
+ }
+ }
+ }
+
+ // Emit the source fetch code
+ code->alu.inst[pos].inst1 &= ~R300_ALU_SRC_MASK;
+ code->alu.inst[pos].inst1 |=
+ ((cs->slot[pos].vsrc[0] << R300_ALU_SRC0C_SHIFT) |
+ (cs->slot[pos].vsrc[1] << R300_ALU_SRC1C_SHIFT) |
+ (cs->slot[pos].vsrc[2] << R300_ALU_SRC2C_SHIFT));
+
+ code->alu.inst[pos].inst3 &= ~R300_ALU_SRC_MASK;
+ code->alu.inst[pos].inst3 |=
+ ((cs->slot[pos].ssrc[0] << R300_ALU_SRC0A_SHIFT) |
+ (cs->slot[pos].ssrc[1] << R300_ALU_SRC1A_SHIFT) |
+ (cs->slot[pos].ssrc[2] << R300_ALU_SRC2A_SHIFT));
+
+ // Emit the argument selection code
+ if (emit_vop) {
+ int swz[3];
+
+ for (i = 0; i < 3; ++i) {
+ if (i < argc) {
+ swz[i] = (v_swiz[REG_GET_VSWZ(src[i])].base +
+ (srcpos[i] *
+ v_swiz[REG_GET_VSWZ(src[i])].
+ stride)) | ((src[i] & REG_NEGV_MASK)
+ ? ARG_NEG : 0) | ((src[i]
+ &
+ REG_ABS_MASK)
+ ?
+ ARG_ABS
+ : 0);
+ } else {
+ swz[i] = R300_ALU_ARGC_ZERO;
+ }
+ }
+
+ code->alu.inst[pos].inst0 &=
+ ~(R300_ALU_ARG0C_MASK | R300_ALU_ARG1C_MASK |
+ R300_ALU_ARG2C_MASK);
+ code->alu.inst[pos].inst0 |=
+ (swz[0] << R300_ALU_ARG0C_SHIFT) | (swz[1] <<
+ R300_ALU_ARG1C_SHIFT)
+ | (swz[2] << R300_ALU_ARG2C_SHIFT);
+ }
+
+ if (emit_sop) {
+ int swz[3];
+
+ for (i = 0; i < 3; ++i) {
+ if (i < argc) {
+ swz[i] = (s_swiz[REG_GET_SSWZ(src[i])].base +
+ (srcpos[i] *
+ s_swiz[REG_GET_SSWZ(src[i])].
+ stride)) | ((src[i] & REG_NEGS_MASK)
+ ? ARG_NEG : 0) | ((src[i]
+ &
+ REG_ABS_MASK)
+ ?
+ ARG_ABS
+ : 0);
+ } else {
+ swz[i] = R300_ALU_ARGA_ZERO;
+ }
+ }
+
+ code->alu.inst[pos].inst2 &=
+ ~(R300_ALU_ARG0A_MASK | R300_ALU_ARG1A_MASK |
+ R300_ALU_ARG2A_MASK);
+ code->alu.inst[pos].inst2 |=
+ (swz[0] << R300_ALU_ARG0A_SHIFT) | (swz[1] <<
+ R300_ALU_ARG1A_SHIFT)
+ | (swz[2] << R300_ALU_ARG2A_SHIFT);
+ }
+
+ return pos;
+}
+
+/**
+ * Append an ALU instruction to the instruction list.
+ */
+static void emit_arith(struct r300_pfs_compile_state *cs,
+ int op,
+ GLuint dest,
+ int mask,
+ GLuint src0, GLuint src1, GLuint src2, int flags)
+{
+ COMPILE_STATE;
+ GLuint src[3] = { src0, src1, src2 };
+ int hwdest;
+ GLboolean emit_vop, emit_sop;
+ int vop, sop, argc;
+ int pos;
+
+ vop = r300_fpop[op].v_op;
+ sop = r300_fpop[op].s_op;
+ argc = r300_fpop[op].argc;
+
+ if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT &&
+ REG_GET_INDEX(dest) == FRAG_RESULT_DEPR) {
+ if (mask & WRITEMASK_Z) {
+ mask = WRITEMASK_W;
+ } else {
+ return;
+ }
+ }
+
+ emit_vop = GL_FALSE;
+ emit_sop = GL_FALSE;
+ if ((mask & WRITEMASK_XYZ) || vop == R300_ALU_OUTC_DP3)
+ emit_vop = GL_TRUE;
+ if ((mask & WRITEMASK_W) || vop == R300_ALU_OUTC_REPL_ALPHA)
+ emit_sop = GL_TRUE;
+
+ pos =
+ find_and_prepare_slot(cs, emit_vop, emit_sop, argc, src, dest,
+ mask);
+ if (pos < 0)
+ return;
+
+ hwdest = t_hw_dst(cs, dest, GL_FALSE, pos); /* Note: Side effects wrt register allocation */
+
+ if (flags & PFS_FLAG_SAT) {
+ vop |= R300_ALU_OUTC_CLAMP;
+ sop |= R300_ALU_OUTA_CLAMP;
+ }
+
+ /* Throw the pieces together and get ALU/1 */
+ if (emit_vop) {
+ code->alu.inst[pos].inst0 |= vop;
+
+ code->alu.inst[pos].inst1 |= hwdest << R300_ALU_DSTC_SHIFT;
+
+ if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
+ if (REG_GET_INDEX(dest) == FRAG_RESULT_COLR) {
+ code->alu.inst[pos].inst1 |=
+ (mask & WRITEMASK_XYZ) <<
+ R300_ALU_DSTC_OUTPUT_MASK_SHIFT;
+ } else
+ assert(0);
+ } else {
+ code->alu.inst[pos].inst1 |=
+ (mask & WRITEMASK_XYZ) <<
+ R300_ALU_DSTC_REG_MASK_SHIFT;
+
+ cs->hwtemps[hwdest].vector_valid = pos + 1;
+ }
+ }
+
+ /* And now ALU/3 */
+ if (emit_sop) {
+ code->alu.inst[pos].inst2 |= sop;
+
+ if (mask & WRITEMASK_W) {
+ if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
+ if (REG_GET_INDEX(dest) == FRAG_RESULT_COLR) {
+ code->alu.inst[pos].inst3 |=
+ (hwdest << R300_ALU_DSTA_SHIFT) |
+ R300_ALU_DSTA_OUTPUT;
+ } else if (REG_GET_INDEX(dest) ==
+ FRAG_RESULT_DEPR) {
+ code->alu.inst[pos].inst3 |=
+ R300_ALU_DSTA_DEPTH;
+ } else
+ assert(0);
+ } else {
+ code->alu.inst[pos].inst3 |=
+ (hwdest << R300_ALU_DSTA_SHIFT) |
+ R300_ALU_DSTA_REG;
+
+ cs->hwtemps[hwdest].scalar_valid = pos + 1;
+ }
+ }
+ }
+
+ return;
+}
+
+static GLfloat SinCosConsts[2][4] = {
+ {
+ 1.273239545, // 4/PI
+ -0.405284735, // -4/(PI*PI)
+ 3.141592654, // PI
+ 0.2225 // weight
+ },
+ {
+ 0.75,
+ 0.0,
+ 0.159154943, // 1/(2*PI)
+ 6.283185307 // 2*PI
+ }
+};
+
+/**
+ * Emit a LIT instruction.
+ * \p flags may be PFS_FLAG_SAT
+ *
+ * Definition of LIT (from ARB_fragment_program):
+ * tmp = VectorLoad(op0);
+ * if (tmp.x < 0) tmp.x = 0;
+ * if (tmp.y < 0) tmp.y = 0;
+ * if (tmp.w < -(128.0-epsilon)) tmp.w = -(128.0-epsilon);
+ * else if (tmp.w > 128-epsilon) tmp.w = 128-epsilon;
+ * result.x = 1.0;
+ * result.y = tmp.x;
+ * result.z = (tmp.x > 0) ? RoughApproxPower(tmp.y, tmp.w) : 0.0;
+ * result.w = 1.0;
+ *
+ * The longest path of computation is the one leading to result.z,
+ * consisting of 5 operations. This implementation of LIT takes
+ * 5 slots. So unless there's some special undocumented opcode,
+ * this implementation is potentially optimal. Unfortunately,
+ * emit_arith is a bit too conservative because it doesn't understand
+ * partial writes to the vector component.
+ */
+static const GLfloat LitConst[4] =
+ { 127.999999, 127.999999, 127.999999, -127.999999 };
+
+static void emit_lit(struct r300_pfs_compile_state *cs,
+ GLuint dest, int mask, GLuint src, int flags)
+{
+ COMPILE_STATE;
+ GLuint cnst;
+ int needTemporary;
+ GLuint temp;
+
+ cnst = emit_const4fv(cs, LitConst);
+
+ needTemporary = 0;
+ if ((mask & WRITEMASK_XYZW) != WRITEMASK_XYZW) {
+ needTemporary = 1;
+ } else if (REG_GET_TYPE(dest) == REG_TYPE_OUTPUT) {
+ // LIT is typically followed by DP3/DP4, so there's no point
+ // in creating special code for this case
+ needTemporary = 1;
+ }
+
+ if (needTemporary) {
+ temp = keep(get_temp_reg(cs));
+ } else {
+ temp = keep(dest);
+ }
+
+ // Note: The order of emit_arith inside the slots is relevant,
+ // because emit_arith only looks at scalar vs. vector when resolving
+ // dependencies, and it does not consider individual vector components,
+ // so swizzling between the two parts can create fake dependencies.
+
+ // First slot
+ emit_arith(cs, PFS_OP_MAX, temp, WRITEMASK_XY,
+ keep(src), pfs_zero, undef, 0);
+ emit_arith(cs, PFS_OP_MAX, temp, WRITEMASK_W, src, cnst, undef, 0);
+
+ // Second slot
+ emit_arith(cs, PFS_OP_MIN, temp, WRITEMASK_Z,
+ swizzle(temp, W, W, W, W), cnst, undef, 0);
+ emit_arith(cs, PFS_OP_LG2, temp, WRITEMASK_W,
+ swizzle(temp, Y, Y, Y, Y), undef, undef, 0);
+
+ // Third slot
+ // If desired, we saturate the y result here.
+ // This does not affect the use as a condition variable in the CMP later
+ emit_arith(cs, PFS_OP_MAD, temp, WRITEMASK_W,
+ temp, swizzle(temp, Z, Z, Z, Z), pfs_zero, 0);
+ emit_arith(cs, PFS_OP_MAD, temp, WRITEMASK_Y,
+ swizzle(temp, X, X, X, X), pfs_one, pfs_zero, flags);
+
+ // Fourth slot
+ emit_arith(cs, PFS_OP_MAD, temp, WRITEMASK_X,
+ pfs_one, pfs_one, pfs_zero, 0);
+ emit_arith(cs, PFS_OP_EX2, temp, WRITEMASK_W, temp, undef, undef, 0);
+
+ // Fifth slot
+ emit_arith(cs, PFS_OP_CMP, temp, WRITEMASK_Z,
+ pfs_zero, swizzle(temp, W, W, W, W),
+ negate(swizzle(temp, Y, Y, Y, Y)), flags);
+ emit_arith(cs, PFS_OP_MAD, temp, WRITEMASK_W, pfs_one, pfs_one,
+ pfs_zero, 0);
+
+ if (needTemporary) {
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ temp, pfs_one, pfs_zero, flags);
+ free_temp(cs, temp);
+ } else {
+ // Decrease refcount of the destination
+ t_hw_dst(cs, dest, GL_FALSE, cs->nrslots);
+ }
+}
+
+static void emit_instruction(struct r300_pfs_compile_state *cs, struct prog_instruction *fpi)
+{
+ COMPILE_STATE;
+ GLuint src[3], dest, temp[2];
+ int flags, mask = 0;
+ int const_sin[2];
+
+ if (fpi->SaturateMode == SATURATE_ZERO_ONE)
+ flags = PFS_FLAG_SAT;
+ else
+ flags = 0;
+
+ if (fpi->Opcode != OPCODE_KIL) {
+ dest = t_dst(cs, fpi->DstReg);
+ mask = fpi->DstReg.WriteMask;
+ }
+
+ switch (fpi->Opcode) {
+ case OPCODE_ADD:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ src[0], pfs_one, src[1], flags);
+ break;
+ case OPCODE_CMP:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ src[2] = t_src(cs, fpi->SrcReg[2]);
+ /* ARB_f_p - if src0.c < 0.0 ? src1.c : src2.c
+ * r300 - if src2.c < 0.0 ? src1.c : src0.c
+ */
+ emit_arith(cs, PFS_OP_CMP, dest, mask,
+ src[2], src[1], src[0], flags);
+ break;
+ case OPCODE_COS:
+ /*
+ * cos using a parabola (see SIN):
+ * cos(x):
+ * x = (x/(2*PI))+0.75
+ * x = frac(x)
+ * x = (x*2*PI)-PI
+ * result = sin(x)
+ */
+ temp[0] = get_temp_reg(cs);
+ const_sin[0] = emit_const4fv(cs, SinCosConsts[0]);
+ const_sin[1] = emit_const4fv(cs, SinCosConsts[1]);
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+
+ /* add 0.5*PI and do range reduction */
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_X,
+ swizzle(src[0], X, X, X, X),
+ swizzle(const_sin[1], Z, Z, Z, Z),
+ swizzle(const_sin[1], X, X, X, X), 0);
+
+ emit_arith(cs, PFS_OP_FRC, temp[0], WRITEMASK_X,
+ swizzle(temp[0], X, X, X, X),
+ undef, undef, 0);
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_Z, swizzle(temp[0], X, X, X, X), swizzle(const_sin[1], W, W, W, W), //2*PI
+ negate(swizzle(const_sin[0], Z, Z, Z, Z)), //-PI
+ 0);
+
+ /* SIN */
+
+ emit_arith(cs, PFS_OP_MAD, temp[0],
+ WRITEMASK_X | WRITEMASK_Y, swizzle(temp[0],
+ Z, Z, Z,
+ Z),
+ const_sin[0], pfs_zero, 0);
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_X,
+ swizzle(temp[0], Y, Y, Y, Y),
+ absolute(swizzle(temp[0], Z, Z, Z, Z)),
+ swizzle(temp[0], X, X, X, X), 0);
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_Y,
+ swizzle(temp[0], X, X, X, X),
+ absolute(swizzle(temp[0], X, X, X, X)),
+ negate(swizzle(temp[0], X, X, X, X)), 0);
+
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ swizzle(temp[0], Y, Y, Y, Y),
+ swizzle(const_sin[0], W, W, W, W),
+ swizzle(temp[0], X, X, X, X), flags);
+
+ free_temp(cs, temp[0]);
+ break;
+ case OPCODE_DP3:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ emit_arith(cs, PFS_OP_DP3, dest, mask,
+ src[0], src[1], undef, flags);
+ break;
+ case OPCODE_DP4:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ emit_arith(cs, PFS_OP_DP4, dest, mask,
+ src[0], src[1], undef, flags);
+ break;
+ case OPCODE_DST:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ /* dest.y = src0.y * src1.y */
+ if (mask & WRITEMASK_Y)
+ emit_arith(cs, PFS_OP_MAD, dest, WRITEMASK_Y,
+ keep(src[0]), keep(src[1]),
+ pfs_zero, flags);
+ /* dest.z = src0.z */
+ if (mask & WRITEMASK_Z)
+ emit_arith(cs, PFS_OP_MAD, dest, WRITEMASK_Z,
+ src[0], pfs_one, pfs_zero, flags);
+ /* result.x = 1.0
+ * result.w = src1.w */
+ if (mask & WRITEMASK_XW) {
+ REG_SET_VSWZ(src[1], SWIZZLE_111); /*Cheat */
+ emit_arith(cs, PFS_OP_MAD, dest,
+ mask & WRITEMASK_XW,
+ src[1], pfs_one, pfs_zero, flags);
+ }
+ break;
+ case OPCODE_EX2:
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+ emit_arith(cs, PFS_OP_EX2, dest, mask,
+ src[0], undef, undef, flags);
+ break;
+ case OPCODE_FRC:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ emit_arith(cs, PFS_OP_FRC, dest, mask,
+ src[0], undef, undef, flags);
+ break;
+ case OPCODE_KIL:
+ emit_tex(cs, fpi, R300_TEX_OP_KIL);
+ break;
+ case OPCODE_LG2:
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+ emit_arith(cs, PFS_OP_LG2, dest, mask,
+ src[0], undef, undef, flags);
+ break;
+ case OPCODE_LIT:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ emit_lit(cs, dest, mask, src[0], flags);
+ break;
+ case OPCODE_LRP:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ src[2] = t_src(cs, fpi->SrcReg[2]);
+ /* result = tmp0tmp1 + (1 - tmp0)tmp2
+ * = tmp0tmp1 + tmp2 + (-tmp0)tmp2
+ * MAD temp, -tmp0, tmp2, tmp2
+ * MAD result, tmp0, tmp1, temp
+ */
+ temp[0] = get_temp_reg(cs);
+ emit_arith(cs, PFS_OP_MAD, temp[0], mask,
+ negate(keep(src[0])), keep(src[2]), src[2],
+ 0);
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ src[0], src[1], temp[0], flags);
+ free_temp(cs, temp[0]);
+ break;
+ case OPCODE_MAD:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ src[2] = t_src(cs, fpi->SrcReg[2]);
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ src[0], src[1], src[2], flags);
+ break;
+ case OPCODE_MAX:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ emit_arith(cs, PFS_OP_MAX, dest, mask,
+ src[0], src[1], undef, flags);
+ break;
+ case OPCODE_MIN:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ emit_arith(cs, PFS_OP_MIN, dest, mask,
+ src[0], src[1], undef, flags);
+ break;
+ case OPCODE_MOV:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ src[0], pfs_one, pfs_zero, flags);
+ break;
+ case OPCODE_MUL:
+ src[0] = t_src(cs, fpi->SrcReg[0]);
+ src[1] = t_src(cs, fpi->SrcReg[1]);
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ src[0], src[1], pfs_zero, flags);
+ break;
+ case OPCODE_RCP:
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+ emit_arith(cs, PFS_OP_RCP, dest, mask,
+ src[0], undef, undef, flags);
+ break;
+ case OPCODE_RSQ:
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+ emit_arith(cs, PFS_OP_RSQ, dest, mask,
+ absolute(src[0]), pfs_zero, pfs_zero, flags);
+ break;
+ case OPCODE_SCS:
+ /*
+ * scs using a parabola :
+ * scs(x):
+ * result.x = sin(-abs(x)+0.5*PI) (cos)
+ * result.y = sin(x) (sin)
+ *
+ */
+ temp[0] = get_temp_reg(cs);
+ temp[1] = get_temp_reg(cs);
+ const_sin[0] = emit_const4fv(cs, SinCosConsts[0]);
+ const_sin[1] = emit_const4fv(cs, SinCosConsts[1]);
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+
+ /* x = -abs(x)+0.5*PI */
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_Z, swizzle(const_sin[0], Z, Z, Z, Z), //PI
+ pfs_half,
+ negate(abs
+ (swizzle(keep(src[0]), X, X, X, X))),
+ 0);
+
+ /* C*x (sin) */
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_W,
+ swizzle(const_sin[0], Y, Y, Y, Y),
+ swizzle(keep(src[0]), X, X, X, X),
+ pfs_zero, 0);
+
+ /* B*x, C*x (cos) */
+ emit_arith(cs, PFS_OP_MAD, temp[0],
+ WRITEMASK_X | WRITEMASK_Y, swizzle(temp[0],
+ Z, Z, Z,
+ Z),
+ const_sin[0], pfs_zero, 0);
+
+ /* B*x (sin) */
+ emit_arith(cs, PFS_OP_MAD, temp[1], WRITEMASK_W,
+ swizzle(const_sin[0], X, X, X, X),
+ keep(src[0]), pfs_zero, 0);
+
+ /* y = B*x + C*x*abs(x) (sin) */
+ emit_arith(cs, PFS_OP_MAD, temp[1], WRITEMASK_Z,
+ absolute(src[0]),
+ swizzle(temp[0], W, W, W, W),
+ swizzle(temp[1], W, W, W, W), 0);
+
+ /* y = B*x + C*x*abs(x) (cos) */
+ emit_arith(cs, PFS_OP_MAD, temp[1], WRITEMASK_W,
+ swizzle(temp[0], Y, Y, Y, Y),
+ absolute(swizzle(temp[0], Z, Z, Z, Z)),
+ swizzle(temp[0], X, X, X, X), 0);
+
+ /* y*abs(y) - y (cos), y*abs(y) - y (sin) */
+ emit_arith(cs, PFS_OP_MAD, temp[0],
+ WRITEMASK_X | WRITEMASK_Y, swizzle(temp[1],
+ W, Z, Y,
+ X),
+ absolute(swizzle(temp[1], W, Z, Y, X)),
+ negate(swizzle(temp[1], W, Z, Y, X)), 0);
+
+ /* dest.xy = mad(temp.xy, P, temp2.wz) */
+ emit_arith(cs, PFS_OP_MAD, dest,
+ mask & (WRITEMASK_X | WRITEMASK_Y), temp[0],
+ swizzle(const_sin[0], W, W, W, W),
+ swizzle(temp[1], W, Z, Y, X), flags);
+
+ free_temp(cs, temp[0]);
+ free_temp(cs, temp[1]);
+ break;
+ case OPCODE_SIN:
+ /*
+ * using a parabola:
+ * sin(x) = 4/pi * x + -4/(pi*pi) * x * abs(x)
+ * extra precision is obtained by weighting against
+ * itself squared.
+ */
+
+ temp[0] = get_temp_reg(cs);
+ const_sin[0] = emit_const4fv(cs, SinCosConsts[0]);
+ const_sin[1] = emit_const4fv(cs, SinCosConsts[1]);
+ src[0] = t_scalar_src(cs, fpi->SrcReg[0]);
+
+ /* do range reduction */
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_X,
+ swizzle(keep(src[0]), X, X, X, X),
+ swizzle(const_sin[1], Z, Z, Z, Z),
+ pfs_half, 0);
+
+ emit_arith(cs, PFS_OP_FRC, temp[0], WRITEMASK_X,
+ swizzle(temp[0], X, X, X, X),
+ undef, undef, 0);
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_Z, swizzle(temp[0], X, X, X, X), swizzle(const_sin[1], W, W, W, W), //2*PI
+ negate(swizzle(const_sin[0], Z, Z, Z, Z)), //PI
+ 0);
+
+ /* SIN */
+
+ emit_arith(cs, PFS_OP_MAD, temp[0],
+ WRITEMASK_X | WRITEMASK_Y, swizzle(temp[0],
+ Z, Z, Z,
+ Z),
+ const_sin[0], pfs_zero, 0);
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_X,
+ swizzle(temp[0], Y, Y, Y, Y),
+ absolute(swizzle(temp[0], Z, Z, Z, Z)),
+ swizzle(temp[0], X, X, X, X), 0);
+
+ emit_arith(cs, PFS_OP_MAD, temp[0], WRITEMASK_Y,
+ swizzle(temp[0], X, X, X, X),
+ absolute(swizzle(temp[0], X, X, X, X)),
+ negate(swizzle(temp[0], X, X, X, X)), 0);
+
+ emit_arith(cs, PFS_OP_MAD, dest, mask,
+ swizzle(temp[0], Y, Y, Y, Y),
+ swizzle(const_sin[0], W, W, W, W),
+ swizzle(temp[0], X, X, X, X), flags);
+
+ free_temp(cs, temp[0]);
+ break;
+ case OPCODE_TEX:
+ emit_tex(cs, fpi, R300_TEX_OP_LD);
+ break;
+ case OPCODE_TXB:
+ emit_tex(cs, fpi, R300_TEX_OP_TXB);
+ break;
+ case OPCODE_TXP:
+ emit_tex(cs, fpi, R300_TEX_OP_TXP);
+ break;
+ default:
+ ERROR("unknown fpi->Opcode %d\n", fpi->Opcode);
+ break;
+ }
+}
+
+static GLboolean parse_program(struct r300_pfs_compile_state *cs)
+{
+ COMPILE_STATE;
+ int clauseidx;
+
+ for (clauseidx = 0; clauseidx < cs->compiler->compiler.NumClauses; ++clauseidx) {
+ struct radeon_clause* clause = &cs->compiler->compiler.Clauses[clauseidx];
+ int ip;
+
+ for(ip = 0; ip < clause->NumInstructions; ++ip) {
+ emit_instruction(cs, clause->Instructions + ip);
+
+ if (fp->error)
+ return GL_FALSE;
+ }
+ }
+
+ return GL_TRUE;
+}
+
+
+/* - Init structures
+ * - Determine what hwregs each input corresponds to
+ */
+static void init_program(struct r300_pfs_compile_state *cs)
+{
+ COMPILE_STATE;
+ struct gl_fragment_program *mp = &fp->mesa_program;
+ GLuint InputsRead = mp->Base.InputsRead;
+ GLuint temps_used = 0; /* for fp->temps[] */
+ int i, j;
+
+ /* New compile, reset tracking data */
+ fp->optimization =
+ driQueryOptioni(&cs->compiler->r300->radeon.optionCache, "fp_optimization");
+ fp->translated = GL_FALSE;
+ fp->error = GL_FALSE;
+ fp->WritesDepth = GL_FALSE;
+ code->tex.length = 0;
+ code->cur_node = 0;
+ code->first_node_has_tex = 0;
+ code->const_nr = 0;
+ code->max_temp_idx = 0;
+ code->node[0].alu_end = -1;
+ code->node[0].tex_end = -1;
+
+ for (i = 0; i < PFS_MAX_ALU_INST; i++) {
+ for (j = 0; j < 3; j++) {
+ cs->slot[i].vsrc[j] = SRC_CONST;
+ cs->slot[i].ssrc[j] = SRC_CONST;
+ }
+ }
+
+ /* Work out what temps the Mesa inputs correspond to, this must match
+ * what setup_rs_unit does, which shouldn't be a problem as rs_unit
+ * configures itself based on the fragprog's InputsRead
+ *
+ * NOTE: this depends on get_hw_temp() allocating registers in order,
+ * starting from register 0.
+ */
+
+ /* Texcoords come first */
+ for (i = 0; i < cs->compiler->r300->radeon.glCtx->Const.MaxTextureUnits; i++) {
+ if (InputsRead & (FRAG_BIT_TEX0 << i)) {
+ cs->inputs[FRAG_ATTRIB_TEX0 + i].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_TEX0 + i].reg =
+ get_hw_temp(cs, 0);
+ }
+ }
+ InputsRead &= ~FRAG_BITS_TEX_ANY;
+
+ /* fragment position treated as a texcoord */
+ if (InputsRead & FRAG_BIT_WPOS) {
+ cs->inputs[FRAG_ATTRIB_WPOS].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_WPOS].reg = get_hw_temp(cs, 0);
+ }
+ InputsRead &= ~FRAG_BIT_WPOS;
+
+ /* Then primary colour */
+ if (InputsRead & FRAG_BIT_COL0) {
+ cs->inputs[FRAG_ATTRIB_COL0].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_COL0].reg = get_hw_temp(cs, 0);
+ }
+ InputsRead &= ~FRAG_BIT_COL0;
+
+ /* Secondary color */
+ if (InputsRead & FRAG_BIT_COL1) {
+ cs->inputs[FRAG_ATTRIB_COL1].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_COL1].reg = get_hw_temp(cs, 0);
+ }
+ InputsRead &= ~FRAG_BIT_COL1;
+
+ /* Anything else */
+ if (InputsRead) {
+ WARN_ONCE("Don't know how to handle inputs 0x%x\n", InputsRead);
+ /* force read from hwreg 0 for now */
+ for (i = 0; i < 32; i++)
+ if (InputsRead & (1 << i))
+ cs->inputs[i].reg = 0;
+ }
+
+ /* Pre-parse the program, grabbing refcounts on input/temp regs.
+ * That way, we can free up the reg when it's no longer needed
+ */
+ for (i = 0; i < cs->compiler->compiler.Clauses[0].NumInstructions; ++i) {
+ struct prog_instruction *fpi = cs->compiler->compiler.Clauses[0].Instructions + i;
+ int idx;
+
+ for (j = 0; j < 3; j++) {
+ idx = fpi->SrcReg[j].Index;
+ switch (fpi->SrcReg[j].File) {
+ case PROGRAM_TEMPORARY:
+ if (!(temps_used & (1 << idx))) {
+ cs->temps[idx].reg = -1;
+ cs->temps[idx].refcount = 1;
+ temps_used |= (1 << idx);
+ } else
+ cs->temps[idx].refcount++;
+ break;
+ case PROGRAM_INPUT:
+ cs->inputs[idx].refcount++;
+ break;
+ default:
+ break;
+ }
+ }
+
+ idx = fpi->DstReg.Index;
+ if (fpi->DstReg.File == PROGRAM_TEMPORARY) {
+ if (!(temps_used & (1 << idx))) {
+ cs->temps[idx].reg = -1;
+ cs->temps[idx].refcount = 1;
+ temps_used |= (1 << idx);
+ } else
+ cs->temps[idx].refcount++;
+ }
+ }
+ cs->temp_in_use = temps_used;
+}
+
+
+/**
+ * Final compilation step: Turn the intermediate radeon_program into
+ * machine-readable instructions.
+ */
+GLboolean r300FragmentProgramEmit(struct r300_fragment_program_compiler *compiler)
+{
+ struct r300_pfs_compile_state cs;
+ struct r300_fragment_program_code *code = compiler->code;
+
+ _mesa_memset(&cs, 0, sizeof(cs));
+ cs.compiler = compiler;
+ init_program(&cs);
+
+ if (!parse_program(&cs))
+ return GL_FALSE;
+
+ /* Finish off */
+ code->node[code->cur_node].alu_end =
+ cs.nrslots - code->node[code->cur_node].alu_offset - 1;
+ if (code->node[code->cur_node].tex_end < 0)
+ code->node[code->cur_node].tex_end = 0;
+ code->alu_offset = 0;
+ code->alu_end = cs.nrslots - 1;
+ code->tex_offset = 0;
+ code->tex_end = code->tex.length ? code->tex.length - 1 : 0;
+ assert(code->node[code->cur_node].alu_end >= 0);
+ assert(code->alu_end >= 0);
+
+ return GL_TRUE;
+}
+
diff --git a/src/mesa/drivers/dri/r300/r300_ioctl.c b/src/mesa/drivers/dri/r300/r300_ioctl.c
index b0225453d3..71821a01ea 100644
--- a/src/mesa/drivers/dri/r300/r300_ioctl.c
+++ b/src/mesa/drivers/dri/r300/r300_ioctl.c
@@ -54,6 +54,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r300_vertprog.h"
#include "radeon_reg.h"
#include "r300_emit.h"
+#include "r300_fragprog.h"
#include "vblank.h"
@@ -130,8 +131,6 @@ static void r300ClearBuffer(r300ContextPtr r300, int flags, int buffer)
t1 |= R300_Z_ENABLE | R300_Z_WRITE_ENABLE;
t2 |=
(R300_ZS_ALWAYS << R300_Z_FUNC_SHIFT);
- } else { //XXX
- t1 |= R300_STENCIL_FRONT_BACK; // disable
}
if (flags & CLEARBUFFER_STENCIL) {
@@ -144,20 +143,13 @@ static void r300ClearBuffer(r300ContextPtr r300, int flags, int buffer)
(R300_ZS_REPLACE <<
R300_S_FRONT_ZPASS_OP_SHIFT) |
(R300_ZS_REPLACE <<
- R300_S_FRONT_ZFAIL_OP_SHIFT) |
- (R300_ZS_ALWAYS <<
- R300_S_BACK_FUNC_SHIFT) |
- (R300_ZS_REPLACE <<
- R300_S_BACK_SFAIL_OP_SHIFT) |
- (R300_ZS_REPLACE <<
- R300_S_BACK_ZPASS_OP_SHIFT) |
- (R300_ZS_REPLACE <<
- R300_S_BACK_ZFAIL_OP_SHIFT);
+ R300_S_FRONT_ZFAIL_OP_SHIFT);
}
e32(t1);
e32(t2);
- e32(r300->state.stencil.clear);
+ e32(((ctx->Stencil.WriteMask[0] & R300_STENCILREF_MASK) << R300_STENCILWRITEMASK_SHIFT) |
+ (ctx->Stencil.Clear & R300_STENCILREF_MASK));
}
cmd2 = (drm_r300_cmd_header_t *) r300AllocCmdBuf(r300, 9, __FUNCTION__);
@@ -307,7 +299,6 @@ static void r300EmitClearState(GLcontext * ctx)
reg_start(R300_RS_INST_0, 0);
e32(R300_RS_INST_COL_CN_WRITE);
} else {
-
R300_STATECHANGE(r300, ri);
reg_start(R500_RS_IP_0, 7);
for (i = 0; i < 8; ++i) {
diff --git a/src/mesa/drivers/dri/r300/r300_reg.h b/src/mesa/drivers/dri/r300/r300_reg.h
index 21e1dc29de..8b00f9958c 100644
--- a/src/mesa/drivers/dri/r300/r300_reg.h
+++ b/src/mesa/drivers/dri/r300/r300_reg.h
@@ -1371,29 +1371,22 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
# define R300_TX_MAG_FILTER_4 (0 << 9)
# define R300_TX_MAG_FILTER_NEAREST (1 << 9)
# define R300_TX_MAG_FILTER_LINEAR (2 << 9)
+# define R300_TX_MAG_FILTER_ANISO (3 << 9)
# define R300_TX_MAG_FILTER_MASK (3 << 9)
# define R300_TX_MIN_FILTER_NEAREST (1 << 11)
# define R300_TX_MIN_FILTER_LINEAR (2 << 11)
-# define R300_TX_MIN_FILTER_NEAREST_MIP_NEAREST (5 << 11) /* TODO: use spec */
-# define R300_TX_MIN_FILTER_NEAREST_MIP_LINEAR (9 << 11) /* TODO: use spec */
-# define R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST (6 << 11) /* TODO: use spec */
-# define R300_TX_MIN_FILTER_LINEAR_MIP_LINEAR (10 << 11) /* TODO: use spec */
-
-/* NOTE: NEAREST doesnt seem to exist.
- * Im not seting MAG_FILTER_MASK and (3 << 11) on for all
- * anisotropy modes because that would void selected mag filter
- */
-# define R300_TX_MIN_FILTER_ANISO_NEAREST (0 << 13)
-# define R300_TX_MIN_FILTER_ANISO_LINEAR (0 << 13)
-# define R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST (1 << 13)
-# define R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR (2 << 13)
-# define R300_TX_MIN_FILTER_MASK ( (15 << 11) | (3 << 13) )
-# define R300_TX_MAX_ANISO_1_TO_1 (0 << 21)
-# define R300_TX_MAX_ANISO_2_TO_1 (2 << 21)
-# define R300_TX_MAX_ANISO_4_TO_1 (4 << 21)
-# define R300_TX_MAX_ANISO_8_TO_1 (6 << 21)
-# define R300_TX_MAX_ANISO_16_TO_1 (8 << 21)
-# define R300_TX_MAX_ANISO_MASK (14 << 21)
+# define R300_TX_MIN_FILTER_ANISO (3 << 11)
+# define R300_TX_MIN_FILTER_MASK (3 << 11)
+# define R300_TX_MIN_FILTER_MIP_NONE (0 << 13)
+# define R300_TX_MIN_FILTER_MIP_NEAREST (1 << 13)
+# define R300_TX_MIN_FILTER_MIP_LINEAR (2 << 13)
+# define R300_TX_MIN_FILTER_MIP_MASK (3 << 13)
+# define R300_TX_MAX_ANISO_1_TO_1 (0 << 21)
+# define R300_TX_MAX_ANISO_2_TO_1 (1 << 21)
+# define R300_TX_MAX_ANISO_4_TO_1 (2 << 21)
+# define R300_TX_MAX_ANISO_8_TO_1 (3 << 21)
+# define R300_TX_MAX_ANISO_16_TO_1 (4 << 21)
+# define R300_TX_MAX_ANISO_MASK (7 << 21)
#define R300_TX_FILTER1_0 0x4440
# define R300_CHROMA_KEY_MODE_DISABLE 0
@@ -1401,7 +1394,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
# define R300_CHROMA_KEY_BLEND 2
# define R300_MC_ROUND_NORMAL (0<<2)
# define R300_MC_ROUND_MPEG4 (1<<2)
-# define R300_LOD_BIAS_MASK 0x1fff
+# define R300_LOD_BIAS_SHIFT 3
+# define R300_LOD_BIAS_MASK 0x1ff8
# define R300_EDGE_ANISO_EDGE_DIAG (0<<13)
# define R300_EDGE_ANISO_EDGE_ONLY (1<<13)
# define R300_MC_COORD_TRUNCATE_DISABLE (0<<14)
@@ -1432,9 +1426,9 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
They are given meanings as R, G, B and Alpha by the swizzle
specification */
# define R300_TX_FORMAT_X8 0x0
-# define R500_TX_FORMAT_X1 0x0 // bit set in format 2
+# define R500_TX_FORMAT_X1 0x0 // bit set in format 2
# define R300_TX_FORMAT_X16 0x1
-# define R500_TX_FORMAT_X1_REV 0x0 // bit set in format 2
+# define R500_TX_FORMAT_X1_REV 0x0 // bit set in format 2
# define R300_TX_FORMAT_Y4X4 0x2
# define R300_TX_FORMAT_Y8X8 0x3
# define R300_TX_FORMAT_Y16X16 0x4
@@ -2238,7 +2232,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_GAMMA_22 (1 << 1)
# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_SAMPLE0 (0 << 2)
# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE (1 << 2)
-
+
/* Discard src pixels less than or equal to threshold. */
#define R500_RB3D_DISCARD_SRC_PIXEL_LTE_THRESHOLD 0x4ea0
@@ -3179,7 +3173,7 @@ enum {
* 2 to end: Up to 16380 dwords of vertex data.
*/
#define R300_PACKET3_3D_DRAW_INDX 0x00002A00
-
+
/* Specify the full set of vertex arrays as (address, stride).
* The first parameter is the number of vertex arrays specified.
@@ -3209,7 +3203,7 @@ enum {
/* Same as R300_PACKET3_3D_DRAW_INDX but without VAP_VTX_FMT */
#define R300_PACKET3_3D_DRAW_INDX_2 0x00003600
-/* Clears a portion of hierachical Z RAM
+/* Clears a portion of hierachical Z RAM
* 3 dword parameters
* 0. START
* 1. COUNT: 13:0 (max is 0x3FFF)
diff --git a/src/mesa/drivers/dri/r300/r300_render.c b/src/mesa/drivers/dri/r300/r300_render.c
index fc07105c56..8f74f9d785 100644
--- a/src/mesa/drivers/dri/r300/r300_render.c
+++ b/src/mesa/drivers/dri/r300/r300_render.c
@@ -74,6 +74,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r300_reg.h"
#include "r300_tex.h"
#include "r300_emit.h"
+#include "r300_fragprog.h"
extern int future_hw_tcl_on;
/**
diff --git a/src/mesa/drivers/dri/r300/r300_shader.c b/src/mesa/drivers/dri/r300/r300_shader.c
index 5c8fd8a5e5..f30fd986e0 100644
--- a/src/mesa/drivers/dri/r300/r300_shader.c
+++ b/src/mesa/drivers/dri/r300/r300_shader.c
@@ -28,7 +28,6 @@ static struct gl_program *r300NewProgram(GLcontext * ctx, GLenum target,
target, id);
} else {
r300_fp = CALLOC_STRUCT(r300_fragment_program);
- r300_fp->ctx = ctx;
return _mesa_init_fragment_program(ctx, &r300_fp->mesa_program,
target, id);
}
diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c
index 550f710854..55d3d55e90 100644
--- a/src/mesa/drivers/dri/r300/r300_state.c
+++ b/src/mesa/drivers/dri/r300/r300_state.c
@@ -60,6 +60,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r300_state.h"
#include "r300_reg.h"
#include "r300_emit.h"
+#include "r300_fragprog.h"
#include "r300_tex.h"
#include "drirenderbuffer.h"
@@ -525,24 +526,15 @@ static void r300SetDepthState(GLcontext * ctx)
r300ContextPtr r300 = R300_CONTEXT(ctx);
R300_STATECHANGE(r300, zs);
- r300->hw.zs.cmd[R300_ZS_CNTL_0] &= R300_STENCIL_ENABLE; // XXX
- r300->hw.zs.cmd[R300_ZS_CNTL_1] &=
- ~(R300_ZS_MASK << R300_Z_FUNC_SHIFT);
+ r300->hw.zs.cmd[R300_ZS_CNTL_0] &= R300_STENCIL_ENABLE|R300_STENCIL_FRONT_BACK;
+ r300->hw.zs.cmd[R300_ZS_CNTL_1] &= ~(R300_ZS_MASK << R300_Z_FUNC_SHIFT);
- if (ctx->Depth.Test && ctx->Depth.Func != GL_NEVER) {
+ if (ctx->Depth.Test) {
+ r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_Z_ENABLE;
if (ctx->Depth.Mask)
- r300->hw.zs.cmd[R300_ZS_CNTL_0] |=
- R300_Z_ENABLE | R300_Z_WRITE_ENABLE | R300_STENCIL_FRONT_BACK; // XXX
- else
- r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_Z_ENABLE | R300_STENCIL_FRONT_BACK; // XXX
-
- r300->hw.zs.cmd[R300_ZS_CNTL_1] |=
- translate_func(ctx->Depth.
- Func) << R300_Z_FUNC_SHIFT;
- } else {
- r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_STENCIL_FRONT_BACK; // XXX
+ r300->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_Z_WRITE_ENABLE;
r300->hw.zs.cmd[R300_ZS_CNTL_1] |=
- translate_func(GL_NEVER) << R300_Z_FUNC_SHIFT;
+ translate_func(ctx->Depth.Func) << R300_Z_FUNC_SHIFT;
}
r300SetEarlyZState(ctx);
@@ -925,7 +917,7 @@ static void r300StencilFuncSeparate(GLcontext * ctx, GLenum face,
GLuint flag;
R300_STATECHANGE(rmesa, zs);
-
+ rmesa->hw.zs.cmd[R300_ZS_CNTL_0] |= R300_STENCIL_FRONT_BACK;
rmesa->hw.zs.cmd[R300_ZS_CNTL_1] &= ~((R300_ZS_MASK <<
R300_S_FRONT_FUNC_SHIFT)
| (R300_ZS_MASK <<
@@ -1000,17 +992,6 @@ static void r300StencilOpSeparate(GLcontext * ctx, GLenum face,
}
}
-static void r300ClearStencil(GLcontext * ctx, GLint s)
-{
- r300ContextPtr rmesa = R300_CONTEXT(ctx);
-
- rmesa->state.stencil.clear =
- ((GLuint) (ctx->Stencil.Clear & R300_STENCILREF_MASK) |
- (R300_STENCILREF_MASK << R300_STENCILMASK_SHIFT) |
- ((ctx->Stencil.WriteMask[0] & R300_STENCILREF_MASK) <<
- R300_STENCILMASK_SHIFT));
-}
-
/* =============================================================
* Window position and viewport transformation
*/
@@ -1284,7 +1265,7 @@ static unsigned long gen_fixed_filter(unsigned long f)
return f;
mag = f & R300_TX_MAG_FILTER_MASK;
- min = f & R300_TX_MIN_FILTER_MASK;
+ min = f & (R300_TX_MIN_FILTER_MASK|R300_TX_MIN_FILTER_MIP_MASK);
/* TODO: Check for anisto filters too */
if ((mag != R300_TX_MAG_FILTER_NEAREST)
@@ -1328,18 +1309,19 @@ static void r300SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
int i;
struct r300_fragment_program *fp = (struct r300_fragment_program *)
(char *)ctx->FragmentProgram._Current;
+ struct r300_fragment_program_code *code = &fp->code;
R300_STATECHANGE(r300, fpt);
- for (i = 0; i < fp->tex.length; i++) {
+ for (i = 0; i < code->tex.length; i++) {
int unit;
int opcode;
unsigned long val;
- unit = fp->tex.inst[i] >> R300_TEX_ID_SHIFT;
+ unit = code->tex.inst[i] >> R300_TEX_ID_SHIFT;
unit &= 15;
- val = fp->tex.inst[i];
+ val = code->tex.inst[i];
val &= ~R300_TEX_ID_MASK;
opcode =
@@ -1361,7 +1343,7 @@ static void r300SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
}
r300->hw.fpt.cmd[R300_FPT_CMD_0] =
- cmdpacket0(R300_US_TEX_INST_0, fp->tex.length);
+ cmdpacket0(R300_US_TEX_INST_0, code->tex.length);
}
static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
@@ -1369,14 +1351,15 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
int i;
struct r500_fragment_program *fp = (struct r500_fragment_program *)
(char *)ctx->FragmentProgram._Current;
+ struct r500_fragment_program_code *code = &fp->code;
/* find all the texture instructions and relocate the texture units */
- for (i = 0; i < fp->inst_end + 1; i++) {
- if ((fp->inst[i].inst0 & 0x3) == R500_INST_TYPE_TEX) {
+ for (i = 0; i < code->inst_end + 1; i++) {
+ if ((code->inst[i].inst0 & 0x3) == R500_INST_TYPE_TEX) {
uint32_t val;
int unit, opcode, new_unit;
- val = fp->inst[i].inst1;
+ val = code->inst[i].inst1;
unit = (val >> 16) & 0xf;
@@ -1393,11 +1376,23 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
}
}
val |= R500_TEX_ID(new_unit);
- fp->inst[i].inst1 = val;
+ code->inst[i].inst1 = val;
}
}
}
+static GLuint r300CalculateTexLodBias(GLfloat bias)
+{
+ GLuint b;
+ b = (unsigned int)fabsf(ceilf(bias*31));
+ if (signbit(bias)) {
+ b ^= 0x3ff; /* 10 bits */
+ }
+ b <<= 3;
+ b &= R300_LOD_BIAS_MASK;
+ return b;
+}
+
static void r300SetupTextures(GLcontext * ctx)
{
int i, mtu;
@@ -1461,8 +1456,8 @@ static void r300SetupTextures(GLcontext * ctx)
r300->hw.tex.filter.cmd[R300_TEX_VALUE_0 +
hw_tmu] =
gen_fixed_filter(t->filter) | (hw_tmu << 28);
- /* Currently disabled! */
- r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = 0x0; //0x20501f80;
+ r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->filter_1
+ | r300CalculateTexLodBias(r300->LODBias);
r300->hw.tex.size.cmd[R300_TEX_VALUE_0 + hw_tmu] =
t->size;
r300->hw.tex.format.cmd[R300_TEX_VALUE_0 +
@@ -2426,6 +2421,7 @@ static void r300SetupPixelShader(r300ContextPtr rmesa)
GLcontext *ctx = rmesa->radeon.glCtx;
struct r300_fragment_program *fp = (struct r300_fragment_program *)
(char *)ctx->FragmentProgram._Current;
+ struct r300_fragment_program_code *code;
int i, k;
if (!fp) /* should only happenen once, just after context is created */
@@ -2437,62 +2433,63 @@ static void r300SetupPixelShader(r300ContextPtr rmesa)
__FUNCTION__);
return;
}
+ code = &fp->code;
r300SetupTextures(ctx);
R300_STATECHANGE(rmesa, fpi[0]);
- rmesa->hw.fpi[0].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_INST_0, fp->alu_end + 1);
- for (i = 0; i <= fp->alu_end; i++) {
- rmesa->hw.fpi[0].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst0;
+ rmesa->hw.fpi[0].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_INST_0, code->alu_end + 1);
+ for (i = 0; i <= code->alu_end; i++) {
+ rmesa->hw.fpi[0].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst0;
}
R300_STATECHANGE(rmesa, fpi[1]);
- rmesa->hw.fpi[1].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_ADDR_0, fp->alu_end + 1);
- for (i = 0; i <= fp->alu_end; i++) {
- rmesa->hw.fpi[1].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst1;
+ rmesa->hw.fpi[1].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_ADDR_0, code->alu_end + 1);
+ for (i = 0; i <= code->alu_end; i++) {
+ rmesa->hw.fpi[1].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst1;
}
R300_STATECHANGE(rmesa, fpi[2]);
- rmesa->hw.fpi[2].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_INST_0, fp->alu_end + 1);
- for (i = 0; i <= fp->alu_end; i++) {
- rmesa->hw.fpi[2].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst2;
+ rmesa->hw.fpi[2].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_INST_0, code->alu_end + 1);
+ for (i = 0; i <= code->alu_end; i++) {
+ rmesa->hw.fpi[2].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst2;
}
R300_STATECHANGE(rmesa, fpi[3]);
- rmesa->hw.fpi[3].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_ADDR_0, fp->alu_end + 1);
- for (i = 0; i <= fp->alu_end; i++) {
- rmesa->hw.fpi[3].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst3;
+ rmesa->hw.fpi[3].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_ADDR_0, code->alu_end + 1);
+ for (i = 0; i <= code->alu_end; i++) {
+ rmesa->hw.fpi[3].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst3;
}
R300_STATECHANGE(rmesa, fp);
- rmesa->hw.fp.cmd[R300_FP_CNTL0] = fp->cur_node | (fp->first_node_has_tex << 3);
- rmesa->hw.fp.cmd[R300_FP_CNTL1] = fp->max_temp_idx;
+ rmesa->hw.fp.cmd[R300_FP_CNTL0] = code->cur_node | (code->first_node_has_tex << 3);
+ rmesa->hw.fp.cmd[R300_FP_CNTL1] = code->max_temp_idx;
rmesa->hw.fp.cmd[R300_FP_CNTL2] =
- (fp->alu_offset << R300_PFS_CNTL_ALU_OFFSET_SHIFT) |
- (fp->alu_end << R300_PFS_CNTL_ALU_END_SHIFT) |
- (fp->tex_offset << R300_PFS_CNTL_TEX_OFFSET_SHIFT) |
- (fp->tex_end << R300_PFS_CNTL_TEX_END_SHIFT);
+ (code->alu_offset << R300_PFS_CNTL_ALU_OFFSET_SHIFT) |
+ (code->alu_end << R300_PFS_CNTL_ALU_END_SHIFT) |
+ (code->tex_offset << R300_PFS_CNTL_TEX_OFFSET_SHIFT) |
+ (code->tex_end << R300_PFS_CNTL_TEX_END_SHIFT);
/* I just want to say, the way these nodes are stored.. weird.. */
- for (i = 0, k = (4 - (fp->cur_node + 1)); i < 4; i++, k++) {
- if (i < (fp->cur_node + 1)) {
+ for (i = 0, k = (4 - (code->cur_node + 1)); i < 4; i++, k++) {
+ if (i < (code->cur_node + 1)) {
rmesa->hw.fp.cmd[R300_FP_NODE0 + k] =
- (fp->node[i].alu_offset << R300_ALU_START_SHIFT) |
- (fp->node[i].alu_end << R300_ALU_SIZE_SHIFT) |
- (fp->node[i].tex_offset << R300_TEX_START_SHIFT) |
- (fp->node[i].tex_end << R300_TEX_SIZE_SHIFT) |
- fp->node[i].flags;
+ (code->node[i].alu_offset << R300_ALU_START_SHIFT) |
+ (code->node[i].alu_end << R300_ALU_SIZE_SHIFT) |
+ (code->node[i].tex_offset << R300_TEX_START_SHIFT) |
+ (code->node[i].tex_end << R300_TEX_SIZE_SHIFT) |
+ code->node[i].flags;
} else {
rmesa->hw.fp.cmd[R300_FP_NODE0 + (3 - i)] = 0;
}
}
R300_STATECHANGE(rmesa, fpp);
- rmesa->hw.fpp.cmd[R300_FPP_CMD_0] = cmdpacket0(R300_PFS_PARAM_0_X, fp->const_nr * 4);
- for (i = 0; i < fp->const_nr; i++) {
- rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat24(fp->constant[i][0]);
- rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat24(fp->constant[i][1]);
- rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat24(fp->constant[i][2]);
- rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat24(fp->constant[i][3]);
+ rmesa->hw.fpp.cmd[R300_FPP_CMD_0] = cmdpacket0(R300_PFS_PARAM_0_X, code->const_nr * 4);
+ for (i = 0; i < code->const_nr; i++) {
+ rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat24(code->constant[i][0]);
+ rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat24(code->constant[i][1]);
+ rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat24(code->constant[i][2]);
+ rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat24(code->constant[i][3]);
}
}
@@ -2516,6 +2513,7 @@ static void r500SetupPixelShader(r300ContextPtr rmesa)
struct r500_fragment_program *fp = (struct r500_fragment_program *)
(char *)ctx->FragmentProgram._Current;
int i;
+ struct r500_fragment_program_code *code;
if (!fp) /* should only happenen once, just after context is created */
return;
@@ -2529,42 +2527,43 @@ static void r500SetupPixelShader(r300ContextPtr rmesa)
__FUNCTION__);
return;
}
+ code = &fp->code;
r300SetupTextures(ctx);
R300_STATECHANGE(rmesa, fp);
- rmesa->hw.fp.cmd[R500_FP_PIXSIZE] = fp->max_temp_idx;
+ rmesa->hw.fp.cmd[R500_FP_PIXSIZE] = code->max_temp_idx;
rmesa->hw.fp.cmd[R500_FP_CODE_ADDR] =
- R500_US_CODE_START_ADDR(fp->inst_offset) |
- R500_US_CODE_END_ADDR(fp->inst_end);
+ R500_US_CODE_START_ADDR(code->inst_offset) |
+ R500_US_CODE_END_ADDR(code->inst_end);
rmesa->hw.fp.cmd[R500_FP_CODE_RANGE] =
- R500_US_CODE_RANGE_ADDR(fp->inst_offset) |
- R500_US_CODE_RANGE_SIZE(fp->inst_end);
+ R500_US_CODE_RANGE_ADDR(code->inst_offset) |
+ R500_US_CODE_RANGE_SIZE(code->inst_end);
rmesa->hw.fp.cmd[R500_FP_CODE_OFFSET] =
R500_US_CODE_OFFSET_ADDR(0); /* FIXME when we add flow control */
R300_STATECHANGE(rmesa, r500fp);
/* Emit our shader... */
- for (i = 0; i < fp->inst_end+1; i++) {
- rmesa->hw.r500fp.cmd[i*6+1] = fp->inst[i].inst0;
- rmesa->hw.r500fp.cmd[i*6+2] = fp->inst[i].inst1;
- rmesa->hw.r500fp.cmd[i*6+3] = fp->inst[i].inst2;
- rmesa->hw.r500fp.cmd[i*6+4] = fp->inst[i].inst3;
- rmesa->hw.r500fp.cmd[i*6+5] = fp->inst[i].inst4;
- rmesa->hw.r500fp.cmd[i*6+6] = fp->inst[i].inst5;
+ for (i = 0; i < code->inst_end+1; i++) {
+ rmesa->hw.r500fp.cmd[i*6+1] = code->inst[i].inst0;
+ rmesa->hw.r500fp.cmd[i*6+2] = code->inst[i].inst1;
+ rmesa->hw.r500fp.cmd[i*6+3] = code->inst[i].inst2;
+ rmesa->hw.r500fp.cmd[i*6+4] = code->inst[i].inst3;
+ rmesa->hw.r500fp.cmd[i*6+5] = code->inst[i].inst4;
+ rmesa->hw.r500fp.cmd[i*6+6] = code->inst[i].inst5;
}
- bump_r500fp_count(rmesa->hw.r500fp.cmd, (fp->inst_end + 1) * 6);
+ bump_r500fp_count(rmesa->hw.r500fp.cmd, (code->inst_end + 1) * 6);
R300_STATECHANGE(rmesa, r500fp_const);
- for (i = 0; i < fp->const_nr; i++) {
- rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat32(fp->constant[i][0]);
- rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat32(fp->constant[i][1]);
- rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat32(fp->constant[i][2]);
- rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat32(fp->constant[i][3]);
+ for (i = 0; i < code->const_nr; i++) {
+ rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat32(code->constant[i][0]);
+ rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat32(code->constant[i][1]);
+ rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat32(code->constant[i][2]);
+ rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat32(code->constant[i][3]);
}
- bump_r500fp_const_count(rmesa->hw.r500fp_const.cmd, fp->const_nr * 4);
+ bump_r500fp_const_count(rmesa->hw.r500fp_const.cmd, code->const_nr * 4);
}
@@ -2637,12 +2636,10 @@ void r300InitState(r300ContextPtr r300)
case 16:
r300->state.depth.scale = 1.0 / (GLfloat) 0xffff;
depth_fmt = R300_DEPTHFORMAT_16BIT_INT_Z;
- r300->state.stencil.clear = 0x00000000;
break;
case 24:
r300->state.depth.scale = 1.0 / (GLfloat) 0xffffff;
depth_fmt = R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL;
- r300->state.stencil.clear = 0x00ff0000;
break;
default:
fprintf(stderr, "Error: Unsupported depth %d... exiting\n",
@@ -2706,7 +2703,6 @@ void r300InitStateFuncs(struct dd_function_table *functions)
functions->ShadeModel = r300ShadeModel;
/* Stencil related */
- functions->ClearStencil = r300ClearStencil;
functions->StencilFuncSeparate = r300StencilFuncSeparate;
functions->StencilMaskSeparate = r300StencilMaskSeparate;
functions->StencilOpSeparate = r300StencilOpSeparate;
diff --git a/src/mesa/drivers/dri/r300/r300_tex.c b/src/mesa/drivers/dri/r300/r300_tex.c
index 0b4acec044..5f54bcad9a 100644
--- a/src/mesa/drivers/dri/r300/r300_tex.c
+++ b/src/mesa/drivers/dri/r300/r300_tex.c
@@ -160,21 +160,18 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
t->filter |= hw_qwrap << R300_TX_WRAP_Q_SHIFT;
}
-static void r300SetTexMaxAnisotropy(r300TexObjPtr t, GLfloat max)
+static GLuint aniso_filter(GLfloat anisotropy)
{
-
- t->filter &= ~R300_TX_MAX_ANISO_MASK;
-
- if (max <= 1.0) {
- t->filter |= R300_TX_MAX_ANISO_1_TO_1;
- } else if (max <= 2.0) {
- t->filter |= R300_TX_MAX_ANISO_2_TO_1;
- } else if (max <= 4.0) {
- t->filter |= R300_TX_MAX_ANISO_4_TO_1;
- } else if (max <= 8.0) {
- t->filter |= R300_TX_MAX_ANISO_8_TO_1;
+ if (anisotropy >= 16.0) {
+ return R300_TX_MAX_ANISO_16_TO_1;
+ } else if (anisotropy >= 8.0) {
+ return R300_TX_MAX_ANISO_8_TO_1;
+ } else if (anisotropy >= 4.0) {
+ return R300_TX_MAX_ANISO_4_TO_1;
+ } else if (anisotropy >= 2.0) {
+ return R300_TX_MAX_ANISO_2_TO_1;
} else {
- t->filter |= R300_TX_MAX_ANISO_16_TO_1;
+ return R300_TX_MAX_ANISO_1_TO_1;
}
}
@@ -184,54 +181,47 @@ static void r300SetTexMaxAnisotropy(r300TexObjPtr t, GLfloat max)
* \param t Texture whose filter modes are to be set
* \param minf Texture minification mode
* \param magf Texture magnification mode
+ * \param anisotropy Maximum anisotropy level
*/
-
-static void r300SetTexFilter(r300TexObjPtr t, GLenum minf, GLenum magf)
+static void r300SetTexFilter(r300TexObjPtr t, GLenum minf, GLenum magf, GLfloat anisotropy)
{
- GLuint anisotropy = (t->filter & R300_TX_MAX_ANISO_MASK);
+ t->filter &= ~(R300_TX_MIN_FILTER_MASK | R300_TX_MIN_FILTER_MIP_MASK | R300_TX_MAG_FILTER_MASK | R300_TX_MAX_ANISO_MASK);
+ t->filter_1 &= ~R300_EDGE_ANISO_EDGE_ONLY;
- t->filter &= ~(R300_TX_MIN_FILTER_MASK | R300_TX_MAG_FILTER_MASK);
+ /* Note that EXT_texture_filter_anisotropic is extremely vague about
+ * how anisotropic filtering interacts with the "normal" filter modes.
+ * When anisotropic filtering is enabled, we override min and mag
+ * filter settings completely. This includes driconf's settings.
+ */
+ if (anisotropy >= 2.0 && (minf != GL_NEAREST) && (magf != GL_NEAREST)) {
+ t->filter |= R300_TX_MAG_FILTER_ANISO
+ | R300_TX_MIN_FILTER_ANISO
+ | R300_TX_MIN_FILTER_MIP_LINEAR
+ | aniso_filter(anisotropy);
+ if (RADEON_DEBUG & DEBUG_TEXTURE)
+ fprintf(stderr, "Using maximum anisotropy of %f\n", anisotropy);
+ return;
+ }
- if (anisotropy == R300_TX_MAX_ANISO_1_TO_1) {
- switch (minf) {
- case GL_NEAREST:
- t->filter |= R300_TX_MIN_FILTER_NEAREST;
- break;
- case GL_LINEAR:
- t->filter |= R300_TX_MIN_FILTER_LINEAR;
- break;
- case GL_NEAREST_MIPMAP_NEAREST:
- t->filter |= R300_TX_MIN_FILTER_NEAREST_MIP_NEAREST;
- break;
- case GL_NEAREST_MIPMAP_LINEAR:
- t->filter |= R300_TX_MIN_FILTER_NEAREST_MIP_LINEAR;
- break;
- case GL_LINEAR_MIPMAP_NEAREST:
- t->filter |= R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST;
- break;
- case GL_LINEAR_MIPMAP_LINEAR:
- t->filter |= R300_TX_MIN_FILTER_LINEAR_MIP_LINEAR;
- break;
- }
- } else {
- switch (minf) {
- case GL_NEAREST:
- t->filter |= R300_TX_MIN_FILTER_ANISO_NEAREST;
- break;
- case GL_LINEAR:
- t->filter |= R300_TX_MIN_FILTER_ANISO_LINEAR;
- break;
- case GL_NEAREST_MIPMAP_NEAREST:
- case GL_LINEAR_MIPMAP_NEAREST:
- t->filter |=
- R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST;
- break;
- case GL_NEAREST_MIPMAP_LINEAR:
- case GL_LINEAR_MIPMAP_LINEAR:
- t->filter |=
- R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR;
- break;
- }
+ switch (minf) {
+ case GL_NEAREST:
+ t->filter |= R300_TX_MIN_FILTER_NEAREST;
+ break;
+ case GL_LINEAR:
+ t->filter |= R300_TX_MIN_FILTER_LINEAR;
+ break;
+ case GL_NEAREST_MIPMAP_NEAREST:
+ t->filter |= R300_TX_MIN_FILTER_NEAREST|R300_TX_MIN_FILTER_MIP_NEAREST;
+ break;
+ case GL_NEAREST_MIPMAP_LINEAR:
+ t->filter |= R300_TX_MIN_FILTER_NEAREST|R300_TX_MIN_FILTER_MIP_LINEAR;
+ break;
+ case GL_LINEAR_MIPMAP_NEAREST:
+ t->filter |= R300_TX_MIN_FILTER_LINEAR|R300_TX_MIN_FILTER_MIP_NEAREST;
+ break;
+ case GL_LINEAR_MIPMAP_LINEAR:
+ t->filter |= R300_TX_MIN_FILTER_LINEAR|R300_TX_MIN_FILTER_MIP_LINEAR;
+ break;
}
/* Note we don't have 3D mipmaps so only use the mag filter setting
@@ -252,6 +242,20 @@ static void r300SetTexBorderColor(r300TexObjPtr t, GLubyte c[4])
t->pp_border_color = PACK_COLOR_8888(c[3], c[0], c[1], c[2]);
}
+static void r300SetTexLodBias(r300TexObjPtr t, GLfloat bias)
+{
+ GLuint b;
+ b = (unsigned int)fabsf(ceilf(bias*31));
+ if (signbit(bias)) {
+ b ^= 0x3ff; /* 10 bits */
+ }
+ b <<= 3;
+ b &= R300_LOD_BIAS_MASK;
+
+ t->filter_1 &= ~R300_LOD_BIAS_MASK;
+ t->filter_1 |= b;
+}
+
/**
* Allocate space for and load the mesa images into the texture memory block.
* This will happen before drawing with a new texture, or drawing with a
@@ -278,8 +282,7 @@ static r300TexObjPtr r300AllocTexObj(struct gl_texture_object *texObj)
make_empty_list(&t->base);
r300SetTexWrap(t, texObj->WrapS, texObj->WrapT, texObj->WrapR);
- r300SetTexMaxAnisotropy(t, texObj->MaxAnisotropy);
- r300SetTexFilter(t, texObj->MinFilter, texObj->MagFilter);
+ r300SetTexFilter(t, texObj->MinFilter, texObj->MagFilter, texObj->MaxAnisotropy);
r300SetTexBorderColor(t, texObj->_BorderChan);
}
@@ -976,9 +979,38 @@ r300TexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
t->dirty_images[0] |= (1 << level);
}
+/* This feels like a prime target for code reuse, so I'm putting it here
+ * instead of inlining it in TexEnv. */
+static GLenum r300TexUnitTarget(struct gl_texture_unit *unit) {
+ if (unit->_ReallyEnabled & (TEXTURE_RECT_BIT)) {
+ return GL_TEXTURE_RECTANGLE_NV;
+ } else if (unit->_ReallyEnabled & (TEXTURE_1D_BIT)) {
+ return GL_TEXTURE_1D;
+ } else if (unit->_ReallyEnabled & (TEXTURE_2D_BIT)) {
+ return GL_TEXTURE_2D;
+ } else if (unit->_ReallyEnabled & (TEXTURE_3D_BIT)) {
+ return GL_TEXTURE_3D;
+ } else if (unit->_ReallyEnabled & (TEXTURE_CUBE_BIT)) {
+ return GL_TEXTURE_CUBE_MAP;
+ }
+ if (unit->Enabled & (TEXTURE_RECT_BIT)) {
+ return GL_TEXTURE_RECTANGLE_NV;
+ } else if (unit->Enabled & (TEXTURE_1D_BIT)) {
+ return GL_TEXTURE_1D;
+ } else if (unit->Enabled & (TEXTURE_2D_BIT)) {
+ return GL_TEXTURE_2D;
+ } else if (unit->Enabled & (TEXTURE_3D_BIT)) {
+ return GL_TEXTURE_3D;
+ } else if (unit->Enabled & (TEXTURE_CUBE_BIT)) {
+ return GL_TEXTURE_CUBE_MAP;
+ }
+ return 0;
+}
+
static void r300TexEnv(GLcontext * ctx, GLenum target,
GLenum pname, const GLfloat * param)
{
+ r300ContextPtr rmesa = R300_CONTEXT(ctx);
if (RADEON_DEBUG & DEBUG_STATE) {
fprintf(stderr, "%s( %s )\n",
__FUNCTION__, _mesa_lookup_enum_by_nr(pname));
@@ -989,41 +1021,24 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
* between them according to _ReallyEnabled.
*/
switch (pname) {
- case GL_TEXTURE_LOD_BIAS_EXT:{
-#if 0 /* Needs to be relocated in order to make sure we got the right tmu */
- GLfloat bias, min;
- GLuint b;
-
- /* The R300's LOD bias is a signed 2's complement value with a
- * range of -16.0 <= bias < 16.0.
- *
- * NOTE: Add a small bias to the bias for conform mipsel.c test.
- */
- bias = *param + .01;
- min =
- driQueryOptionb(&rmesa->radeon.optionCache,
- "no_neg_lod_bias") ? 0.0 : -16.0;
- bias = CLAMP(bias, min, 16.0);
-
- /* 0.0 - 16.0 == 0x0 - 0x1000 */
- /* 0.0 - -16.0 == 0x1001 - 0x1fff */
- b = 0x1000 / 16.0 * bias;
- b &= R300_LOD_BIAS_MASK;
-
- if (b !=
- (rmesa->hw.tex.unknown1.
- cmd[R300_TEX_VALUE_0 +
- unit] & R300_LOD_BIAS_MASK)) {
- R300_STATECHANGE(rmesa, tex.unknown1);
- rmesa->hw.tex.unknown1.cmd[R300_TEX_VALUE_0 +
- unit] &=
- ~R300_LOD_BIAS_MASK;
- rmesa->hw.tex.unknown1.cmd[R300_TEX_VALUE_0 +
- unit] |= b;
- }
-#endif
- break;
- }
+ case GL_TEXTURE_LOD_BIAS_EXT: {
+ /* Needs to be relocated in order to make sure we got the right tmu */
+ GLfloat bias, min;
+
+ /* The R300's LOD bias is a signed 2's complement value with a
+ * range of -16.0 <= bias < 16.0.
+ *
+ * NOTE: Add a small bias to the bias for conform mipsel.c test.
+ */
+ bias = *param + .01;
+ min = driQueryOptionb(&rmesa->radeon.optionCache,
+ "no_neg_lod_bias") ? 0.0 : -16.0;
+ bias = CLAMP(bias, min, 16.0);
+
+ rmesa->LODBias = bias;
+
+ break;
+ }
default:
return;
@@ -1050,8 +1065,7 @@ static void r300TexParameter(GLcontext * ctx, GLenum target,
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- r300SetTexMaxAnisotropy(t, texObj->MaxAnisotropy);
- r300SetTexFilter(t, texObj->MinFilter, texObj->MagFilter);
+ r300SetTexFilter(t, texObj->MinFilter, texObj->MagFilter, texObj->MaxAnisotropy);
break;
case GL_TEXTURE_WRAP_S:
@@ -1077,7 +1091,7 @@ static void r300TexParameter(GLcontext * ctx, GLenum target,
break;
case GL_DEPTH_TEXTURE_MODE:
- if (texObj->Image[0][texObj->BaseLevel]->TexFormat->BaseFormat
+ if (texObj->Image[0][texObj->BaseLevel]->TexFormat->BaseFormat
== GL_DEPTH_COMPONENT) {
r300SetDepthTexMode(texObj);
break;
@@ -1092,10 +1106,6 @@ static void r300TexParameter(GLcontext * ctx, GLenum target,
default:
return;
}
-
- /* Mark this texobj as dirty (one bit per tex unit)
- */
- t->dirty_state = TEX_ALL;
}
static void r300BindTexture(GLcontext * ctx, GLenum target,
@@ -1157,6 +1167,10 @@ static struct gl_texture_object *r300NewTextureObject(GLcontext * ctx,
return NULL;
obj->MaxAnisotropy = rmesa->initialMaxAnisotropy;
+ /* Attempt to fill LOD bias, if previously set.
+ * Should start at 0.0, which won't affect the HW. */
+ obj->LodBias = rmesa->LODBias;
+
r300AllocTexObj(obj);
return obj;
}
diff --git a/src/mesa/drivers/dri/r300/r300_texmem.c b/src/mesa/drivers/dri/r300/r300_texmem.c
index 723601ac4a..69847a4022 100644
--- a/src/mesa/drivers/dri/r300/r300_texmem.c
+++ b/src/mesa/drivers/dri/r300/r300_texmem.c
@@ -349,7 +349,7 @@ static void r300UploadSubImage(r300ContextPtr rmesa, r300TexObjPtr t,
imageWidth = texImage->Width;
imageHeight = texImage->Height;
- offset = t->bufAddr + t->base.totalSize / 6 * face;
+ offset = t->bufAddr;
if (RADEON_DEBUG & (DEBUG_TEXTURE | DEBUG_IOCTL)) {
GLint imageX = 0;
@@ -534,10 +534,6 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face)
/* hope it's safe to add that here... */
t->offset |= t->tile_bits;
}
-
- /* Mark this texobj as dirty on all units:
- */
- t->dirty_state = TEX_ALL;
}
/* Let the world know we've used this memory recently.
diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c
index 78fa75228e..bdd20b18e4 100644
--- a/src/mesa/drivers/dri/r300/r300_texstate.c
+++ b/src/mesa/drivers/dri/r300/r300_texstate.c
@@ -127,18 +127,18 @@ void r300SetDepthTexMode(struct gl_texture_object *tObj)
{
static const GLuint formats[3][3] = {
{
- R300_EASY_TX_FORMAT(X, X, X, X, X16),
R300_EASY_TX_FORMAT(X, X, X, ONE, X16),
+ R300_EASY_TX_FORMAT(X, X, X, X, X16),
R300_EASY_TX_FORMAT(ZERO, ZERO, ZERO, X, X16),
},
{
- R300_EASY_TX_FORMAT(X, X, X, X, X24_Y8),
R300_EASY_TX_FORMAT(X, X, X, ONE, X24_Y8),
+ R300_EASY_TX_FORMAT(X, X, X, X, X24_Y8),
R300_EASY_TX_FORMAT(ZERO, ZERO, ZERO, X, X24_Y8),
},
{
- R300_EASY_TX_FORMAT(X, X, X, X, X32),
R300_EASY_TX_FORMAT(X, X, X, ONE, X32),
+ R300_EASY_TX_FORMAT(X, X, X, X, X32),
R300_EASY_TX_FORMAT(ZERO, ZERO, ZERO, X, X32),
},
};
@@ -190,6 +190,112 @@ void r300SetDepthTexMode(struct gl_texture_object *tObj)
/**
+ * Compute sizes and fill in offset and blit information for the given
+ * image (determined by \p face and \p level).
+ *
+ * \param curOffset points to the offset at which the image is to be stored
+ * and is updated by this function according to the size of the image.
+ */
+static void compute_tex_image_offset(
+ struct gl_texture_object *tObj,
+ GLuint face,
+ GLint level,
+ GLint* curOffset)
+{
+ r300TexObjPtr t = (r300TexObjPtr) tObj->DriverData;
+ const struct gl_texture_image* texImage;
+ GLuint blitWidth = R300_BLIT_WIDTH_BYTES;
+ GLuint texelBytes;
+ GLuint size;
+
+ texImage = tObj->Image[0][level + t->base.firstLevel];
+ if (!texImage)
+ return;
+
+ texelBytes = texImage->TexFormat->TexelBytes;
+
+ /* find image size in bytes */
+ if (texImage->IsCompressed) {
+ if ((t->format & R300_TX_FORMAT_DXT1) ==
+ R300_TX_FORMAT_DXT1) {
+ // fprintf(stderr,"DXT 1 %d %08X\n", texImage->Width, t->format);
+ if ((texImage->Width + 3) < 8) /* width one block */
+ size = texImage->CompressedSize * 4;
+ else if ((texImage->Width + 3) < 16)
+ size = texImage->CompressedSize * 2;
+ else
+ size = texImage->CompressedSize;
+ } else {
+ /* DXT3/5, 16 bytes per block */
+ WARN_ONCE
+ ("DXT 3/5 suffers from multitexturing problems!\n");
+ // fprintf(stderr,"DXT 3/5 %d\n", texImage->Width);
+ if ((texImage->Width + 3) < 8)
+ size = texImage->CompressedSize * 2;
+ else
+ size = texImage->CompressedSize;
+ }
+ } else if (tObj->Target == GL_TEXTURE_RECTANGLE_NV) {
+ size =
+ ((texImage->Width * texelBytes +
+ 63) & ~63) * texImage->Height;
+ blitWidth = 64 / texelBytes;
+ } else if (t->tile_bits & R300_TXO_MICRO_TILE) {
+ /* tile pattern is 16 bytes x2. mipmaps stay 32 byte aligned,
+ though the actual offset may be different (if texture is less than
+ 32 bytes width) to the untiled case */
+ int w = (texImage->Width * texelBytes * 2 + 31) & ~31;
+ size =
+ (w * ((texImage->Height + 1) / 2)) *
+ texImage->Depth;
+ blitWidth = MAX2(texImage->Width, 64 / texelBytes);
+ } else {
+ int w = (texImage->Width * texelBytes + 31) & ~31;
+ size = w * texImage->Height * texImage->Depth;
+ blitWidth = MAX2(texImage->Width, 64 / texelBytes);
+ }
+ assert(size > 0);
+
+ if (RADEON_DEBUG & DEBUG_TEXTURE)
+ fprintf(stderr, "w=%d h=%d d=%d tb=%d intFormat=%d\n",
+ texImage->Width, texImage->Height,
+ texImage->Depth,
+ texImage->TexFormat->TexelBytes,
+ texImage->InternalFormat);
+
+ /* All images are aligned to a 32-byte offset */
+ *curOffset = (*curOffset + 0x1f) & ~0x1f;
+
+ if (texelBytes) {
+ /* fix x and y coords up later together with offset */
+ t->image[face][level].x = *curOffset;
+ t->image[face][level].y = 0;
+ t->image[face][level].width =
+ MIN2(size / texelBytes, blitWidth);
+ t->image[face][level].height =
+ (size / texelBytes) / t->image[face][level].width;
+ } else {
+ t->image[face][level].x = *curOffset % R300_BLIT_WIDTH_BYTES;
+ t->image[face][level].y = *curOffset / R300_BLIT_WIDTH_BYTES;
+ t->image[face][level].width =
+ MIN2(size, R300_BLIT_WIDTH_BYTES);
+ t->image[face][level].height = size / t->image[face][level].width;
+ }
+
+ if (RADEON_DEBUG & DEBUG_TEXTURE)
+ fprintf(stderr,
+ "level %d, face %d: %dx%d x=%d y=%d w=%d h=%d size=%d at %d\n",
+ level, face, texImage->Width, texImage->Height,
+ t->image[face][level].x, t->image[face][level].y,
+ t->image[face][level].width, t->image[face][level].height,
+ size, *curOffset);
+
+ *curOffset += size;
+}
+
+
+
+/**
* This function computes the number of bytes of storage needed for
* the given texture object (all mipmap levels, all cube faces).
* The \c image[face][level].x/y/width/height parameters for upload/blitting
@@ -206,7 +312,7 @@ static void r300SetTexImages(r300ContextPtr rmesa,
r300TexObjPtr t = (r300TexObjPtr) tObj->DriverData;
const struct gl_texture_image *baseImage =
tObj->Image[0][tObj->BaseLevel];
- GLint curOffset, blitWidth;
+ GLint curOffset;
GLint i, texelBytes;
GLint numLevels;
GLint log2Width, log2Height, log2Depth;
@@ -245,8 +351,6 @@ static void r300SetTexImages(r300ContextPtr rmesa,
* The idea is that we lay out the mipmap levels within a block of
* memory organized as a rectangle of width BLIT_WIDTH_BYTES.
*/
- curOffset = 0;
- blitWidth = R300_BLIT_WIDTH_BYTES;
t->tile_bits = 0;
/* figure out if this texture is suitable for tiling. */
@@ -276,94 +380,20 @@ static void r300SetTexImages(r300ContextPtr rmesa,
}
#endif
- for (i = 0; i < numLevels; i++) {
- const struct gl_texture_image *texImage;
- GLuint size;
-
- texImage = tObj->Image[0][i + t->base.firstLevel];
- if (!texImage)
- break;
-
- /* find image size in bytes */
- if (texImage->IsCompressed) {
- if ((t->format & R300_TX_FORMAT_DXT1) ==
- R300_TX_FORMAT_DXT1) {
- // fprintf(stderr,"DXT 1 %d %08X\n", texImage->Width, t->format);
- if ((texImage->Width + 3) < 8) /* width one block */
- size = texImage->CompressedSize * 4;
- else if ((texImage->Width + 3) < 16)
- size = texImage->CompressedSize * 2;
- else
- size = texImage->CompressedSize;
- } else {
- /* DXT3/5, 16 bytes per block */
- WARN_ONCE
- ("DXT 3/5 suffers from multitexturing problems!\n");
- // fprintf(stderr,"DXT 3/5 %d\n", texImage->Width);
- if ((texImage->Width + 3) < 8)
- size = texImage->CompressedSize * 2;
- else
- size = texImage->CompressedSize;
- }
- } else if (tObj->Target == GL_TEXTURE_RECTANGLE_NV) {
- size =
- ((texImage->Width * texelBytes +
- 63) & ~63) * texImage->Height;
- blitWidth = 64 / texelBytes;
- } else if (t->tile_bits & R300_TXO_MICRO_TILE) {
- /* tile pattern is 16 bytes x2. mipmaps stay 32 byte aligned,
- though the actual offset may be different (if texture is less than
- 32 bytes width) to the untiled case */
- int w = (texImage->Width * texelBytes * 2 + 31) & ~31;
- size =
- (w * ((texImage->Height + 1) / 2)) *
- texImage->Depth;
- blitWidth = MAX2(texImage->Width, 64 / texelBytes);
- } else {
- int w = (texImage->Width * texelBytes + 31) & ~31;
- size = w * texImage->Height * texImage->Depth;
- blitWidth = MAX2(texImage->Width, 64 / texelBytes);
- }
- assert(size > 0);
-
- if (RADEON_DEBUG & DEBUG_TEXTURE)
- fprintf(stderr, "w=%d h=%d d=%d tb=%d intFormat=%d\n",
- texImage->Width, texImage->Height,
- texImage->Depth,
- texImage->TexFormat->TexelBytes,
- texImage->InternalFormat);
-
- /* Align to 32-byte offset. It is faster to do this unconditionally
- * (no branch penalty).
- */
+ curOffset = 0;
- curOffset = (curOffset + 0x1f) & ~0x1f;
+ if (tObj->Target == GL_TEXTURE_CUBE_MAP) {
+ ASSERT(log2Width == log2Height);
+ t->format |= R300_TX_FORMAT_CUBIC_MAP;
- if (texelBytes) {
- /* fix x and y coords up later together with offset */
- t->image[0][i].x = curOffset;
- t->image[0][i].y = 0;
- t->image[0][i].width =
- MIN2(size / texelBytes, blitWidth);
- t->image[0][i].height =
- (size / texelBytes) / t->image[0][i].width;
- } else {
- t->image[0][i].x = curOffset % R300_BLIT_WIDTH_BYTES;
- t->image[0][i].y = curOffset / R300_BLIT_WIDTH_BYTES;
- t->image[0][i].width =
- MIN2(size, R300_BLIT_WIDTH_BYTES);
- t->image[0][i].height = size / t->image[0][i].width;
+ for(i = 0; i < numLevels; i++) {
+ GLuint face;
+ for(face = 0; face < 6; face++)
+ compute_tex_image_offset(tObj, face, i, &curOffset);
}
-
- if (RADEON_DEBUG & DEBUG_TEXTURE)
- fprintf(stderr,
- "level %d: %dx%d x=%d y=%d w=%d h=%d size=%d at %d\n",
- i, texImage->Width, texImage->Height,
- t->image[0][i].x, t->image[0][i].y,
- t->image[0][i].width, t->image[0][i].height,
- size, curOffset);
-
- curOffset += size;
+ } else {
+ for (i = 0; i < numLevels; i++)
+ compute_tex_image_offset(tObj, 0, i, &curOffset);
}
/* Align the total size of texture memory block.
@@ -371,26 +401,6 @@ static void r300SetTexImages(r300ContextPtr rmesa,
t->base.totalSize =
(curOffset + RADEON_OFFSET_MASK) & ~RADEON_OFFSET_MASK;
- /* Setup remaining cube face blits, if needed */
- if (tObj->Target == GL_TEXTURE_CUBE_MAP) {
- GLuint face;
- for (face = 1; face < 6; face++) {
- for (i = 0; i < numLevels; i++) {
- t->image[face][i].x = t->image[0][i].x;
- t->image[face][i].y = t->image[0][i].y;
- t->image[face][i].width = t->image[0][i].width;
- t->image[face][i].height =
- t->image[0][i].height;
- }
- }
- t->base.totalSize *= 6; /* total texmem needed */
- }
-
- if (tObj->Target == GL_TEXTURE_CUBE_MAP) {
- ASSERT(log2Width == log2Height);
- t->format |= R300_TX_FORMAT_CUBIC_MAP;
- }
-
t->size =
(((tObj->Image[0][t->base.firstLevel]->Width -
1) << R300_TX_WIDTHMASK_SHIFT)
@@ -408,7 +418,7 @@ static void r300SetTexImages(r300ContextPtr rmesa,
t->pitch |=
(tObj->Image[0][t->base.firstLevel]->Width + 63) & ~(63);
} else if (tObj->Target == GL_TEXTURE_RECTANGLE_NV) {
- unsigned int align = blitWidth - 1;
+ unsigned int align = (64 / texelBytes) - 1;
t->pitch |= ((tObj->Image[0][t->base.firstLevel]->Width *
texelBytes) + 63) & ~(63);
t->size |= R300_TX_SIZE_TXPITCH_EN;
@@ -428,10 +438,6 @@ static void r300SetTexImages(r300ContextPtr rmesa,
if (tObj->Image[0][t->base.firstLevel]->Height > 2048)
t->pitch_reg |= R500_TXHEIGHT_BIT11;
}
-
- t->dirty_state = TEX_ALL;
-
- /* FYI: r300UploadTexImages( rmesa, t ) used to be called here */
}
/* ================================================================
@@ -568,7 +574,6 @@ static GLboolean r300UpdateTexture(GLcontext * ctx, int unit)
rmesa->state.texture.unit[unit].texobj = t;
t->base.bound |= (1 << unit);
- t->dirty_state |= 1 << unit;
driUpdateTextureLRU((driTextureObject *) t); /* XXX: should be locked! */
}
diff --git a/src/mesa/drivers/dri/r300/r500_fragprog.c b/src/mesa/drivers/dri/r300/r500_fragprog.c
index b967aa2d73..5d72ec2784 100644
--- a/src/mesa/drivers/dri/r300/r500_fragprog.c
+++ b/src/mesa/drivers/dri/r300/r500_fragprog.c
@@ -1,8 +1,5 @@
/*
- * Copyright (C) 2005 Ben Skeggs.
- *
* Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
- * Adaptation and modification for ATI/AMD Radeon R500 GPU chipsets.
*
* All Rights Reserved.
*
@@ -28,1439 +25,326 @@
*
*/
+#include "r500_fragprog.h"
+
+static void reset_srcreg(struct prog_src_register* reg)
+{
+ _mesa_bzero(reg, sizeof(*reg));
+ reg->Swizzle = SWIZZLE_NOOP;
+}
+
/**
- * \file
- *
- * \author Ben Skeggs <darktama@iinet.net.au>
- *
- * \author Jerome Glisse <j.glisse@gmail.com>
- *
- * \author Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Transform TEX, TXP, TXB, and KIL instructions in the following way:
+ * - premultiply texture coordinates for RECT
+ * - extract operand swizzles
+ * - introduce a temporary register when write masks are needed
*
- * \todo Depth write, WPOS/FOGC inputs
- *
- * \todo FogOption
- *
- * \todo Verify results of opcodes for accuracy, I've only checked them in
- * specific cases.
*/
+static GLboolean transform_TEX(
+ struct radeon_program_transform_context* context,
+ struct prog_instruction* orig_inst, void* data)
+{
+ struct r500_fragment_program_compiler *compiler =
+ (struct r500_fragment_program_compiler*)data;
+ struct prog_instruction inst = *orig_inst;
+ struct prog_instruction* tgt;
+ GLboolean destredirect = GL_FALSE;
+
+ if (inst.Opcode != OPCODE_TEX &&
+ inst.Opcode != OPCODE_TXB &&
+ inst.Opcode != OPCODE_TXP &&
+ inst.Opcode != OPCODE_KIL)
+ return GL_FALSE;
-#include "glheader.h"
-#include "macros.h"
-#include "enums.h"
-#include "shader/prog_instruction.h"
-#include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
-
-#include "r300_context.h"
-#include "r500_fragprog.h"
-#include "r300_reg.h"
-#include "r300_state.h"
+ /* ARB_shadow & EXT_shadow_funcs */
+ if (inst.Opcode != OPCODE_KIL &&
+ compiler->fp->mesa_program.Base.ShadowSamplers & (1 << inst.TexSrcUnit)) {
+ GLuint comparefunc = GL_NEVER + compiler->fp->state.unit[inst.TexSrcUnit].texture_compare_func;
+
+ if (comparefunc == GL_NEVER || comparefunc == GL_ALWAYS) {
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
+
+ tgt->Opcode = OPCODE_MOV;
+ tgt->DstReg.File = inst.DstReg.File;
+ tgt->DstReg.Index = inst.DstReg.Index;
+ tgt->DstReg.WriteMask = inst.DstReg.WriteMask;
+ tgt->SrcReg[0].File = PROGRAM_BUILTIN;
+ tgt->SrcReg[0].Swizzle = comparefunc == GL_ALWAYS ? SWIZZLE_1111 : SWIZZLE_0000;
+ return GL_TRUE;
+ }
-/*
- * Useful macros and values
- */
-#define ERROR(fmt, args...) do { \
- fprintf(stderr, "%s::%s(): " fmt "\n", \
- __FILE__, __FUNCTION__, ##args); \
- fp->error = GL_TRUE; \
- } while(0)
-
-#define COMPILE_STATE struct r300_pfs_compile_state *cs = fp->cs
-
-#define R500_US_NUM_TEMP_REGS 128
-#define R500_US_NUM_CONST_REGS 256
-
-/* "Register" flags */
-#define REG_CONSTANT (1 << 8)
-#define REG_SRC_REL (1 << 9)
-#define REG_DEST_REL (1 << 7)
-
-/* Swizzle tools */
-#define R500_SWIZZLE_ZERO 4
-#define R500_SWIZZLE_HALF 5
-#define R500_SWIZZLE_ONE 6
-#define R500_SWIZ_RGB_ZERO ((4 << 0) | (4 << 3) | (4 << 6))
-#define R500_SWIZ_RGB_ONE ((6 << 0) | (6 << 3) | (6 << 6))
-#define R500_SWIZ_RGB_RGB ((0 << 0) | (1 << 3) | (2 << 6))
-#define R500_SWIZ_MOD_NEG 1
-#define R500_SWIZ_MOD_ABS 2
-#define R500_SWIZ_MOD_NEG_ABS 3
-/* Swizzles for inst2 */
-#define MAKE_SWIZ_TEX_STRQ(x) (x << 8)
-#define MAKE_SWIZ_TEX_RGBA(x) (x << 24)
-/* Swizzles for inst3 */
-#define MAKE_SWIZ_RGB_A(x) (x << 2)
-#define MAKE_SWIZ_RGB_B(x) (x << 15)
-/* Swizzles for inst4 */
-#define MAKE_SWIZ_ALPHA_A(x) (x << 14)
-#define MAKE_SWIZ_ALPHA_B(x) (x << 21)
-/* Swizzle for inst5 */
-#define MAKE_SWIZ_RGBA_C(x) (x << 14)
-#define MAKE_SWIZ_ALPHA_C(x) (x << 27)
-
-/* Writemasks */
-#define R500_WRITEMASK_G 0x2
-#define R500_WRITEMASK_B 0x4
-#define R500_WRITEMASK_RGB 0x7
-#define R500_WRITEMASK_A 0x8
-#define R500_WRITEMASK_AR 0x9
-#define R500_WRITEMASK_AG 0xA
-#define R500_WRITEMASK_ARG 0xB
-#define R500_WRITEMASK_AB 0xC
-#define R500_WRITEMASK_ARGB 0xF
-
-/* 1/(2pi), needed for quick modulus in trig insts
- * Thanks to glisse for pointing out how to do it! */
-static const GLfloat RCP_2PI[] = {0.15915494309189535,
- 0.15915494309189535,
- 0.15915494309189535,
- 0.15915494309189535};
-
-static const GLfloat LIT[] = {127.999999,
- 127.999999,
- 127.999999,
- -127.999999};
-
-static void dump_program(struct r500_fragment_program *fp);
-
-static inline GLuint make_rgb_swizzle(struct prog_src_register src) {
- GLuint swiz = 0x0;
- GLuint temp;
- /* This could be optimized, but it should be plenty fast already. */
- int i;
- for (i = 0; i < 3; i++) {
- temp = GET_SWZ(src.Swizzle, i);
- /* Fix SWIZZLE_ONE */
- if (temp == 5) temp++;
- swiz |= temp << i*3;
+ inst.DstReg.File = PROGRAM_TEMPORARY;
+ inst.DstReg.Index = radeonCompilerAllocateTemporary(context->compiler);
+ inst.DstReg.WriteMask = WRITEMASK_XYZW;
}
- if (src.NegateBase)
- swiz |= (R500_SWIZ_MOD_NEG << 9);
- return swiz;
-}
-static inline GLuint make_rgba_swizzle(GLuint src) {
- GLuint swiz = 0x0;
- GLuint temp;
- int i;
- for (i = 0; i < 4; i++) {
- temp = GET_SWZ(src, i);
- /* Fix SWIZZLE_ONE */
- if (temp == 5) temp++;
- swiz |= temp << i*3;
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
+ _mesa_copy_instructions(tgt, &inst, 1);
+
+ if (inst.Opcode != OPCODE_KIL &&
+ compiler->fp->mesa_program.Base.ShadowSamplers & (1 << inst.TexSrcUnit)) {
+ GLuint comparefunc = GL_NEVER + compiler->fp->state.unit[inst.TexSrcUnit].texture_compare_func;
+ GLuint depthmode = compiler->fp->state.unit[inst.TexSrcUnit].depth_texture_mode;
+
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 2);
+
+ tgt[0].Opcode = OPCODE_MAD;
+ tgt[0].DstReg = inst.DstReg;
+ tgt[0].DstReg.WriteMask = orig_inst->DstReg.WriteMask;
+ tgt[0].SrcReg[0].File = PROGRAM_TEMPORARY;
+ tgt[0].SrcReg[0].Index = inst.DstReg.Index;
+ if (depthmode == 0) /* GL_LUMINANCE */
+ tgt[0].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z);
+ else if (depthmode == 2) /* GL_ALPHA */
+ tgt[0].SrcReg[0].Swizzle = SWIZZLE_WWWW;
+ tgt[0].SrcReg[1].File = PROGRAM_BUILTIN;
+ tgt[0].SrcReg[1].Swizzle = SWIZZLE_1111;
+ tgt[0].SrcReg[2] = inst.SrcReg[0];
+ tgt[0].SrcReg[2].Swizzle = SWIZZLE_ZZZZ;
+
+ /* Recall that SrcReg[0] is tex, SrcReg[2] is r and:
+ * r < tex <=> -tex+r < 0
+ * r >= tex <=> not (-tex+r < 0 */
+ if (comparefunc == GL_LESS || comparefunc == GL_GEQUAL)
+ tgt[0].SrcReg[0].NegateBase = tgt[0].SrcReg[0].NegateBase ^ NEGATE_XYZW;
+ else
+ tgt[0].SrcReg[2].NegateBase = tgt[0].SrcReg[2].NegateBase ^ NEGATE_XYZW;
+
+ tgt[1].Opcode = OPCODE_CMP;
+ tgt[1].DstReg = orig_inst->DstReg;
+ tgt[1].SrcReg[0].File = PROGRAM_TEMPORARY;
+ tgt[1].SrcReg[0].Index = tgt[0].DstReg.Index;
+ tgt[1].SrcReg[1].File = PROGRAM_BUILTIN;
+ tgt[1].SrcReg[2].File = PROGRAM_BUILTIN;
+
+ if (comparefunc == GL_LESS || comparefunc == GL_GREATER) {
+ tgt[1].SrcReg[1].Swizzle = SWIZZLE_1111;
+ tgt[1].SrcReg[2].Swizzle = SWIZZLE_0000;
+ } else {
+ tgt[1].SrcReg[1].Swizzle = SWIZZLE_0000;
+ tgt[1].SrcReg[2].Swizzle = SWIZZLE_1111;
+ }
+ } else if (destredirect) {
+ tgt = radeonClauseInsertInstructions(context->compiler, context->dest,
+ context->dest->NumInstructions, 1);
+
+ tgt->Opcode = OPCODE_MAD;
+ tgt->DstReg = orig_inst->DstReg;
+ tgt->SrcReg[0].File = PROGRAM_TEMPORARY;
+ tgt->SrcReg[0].Index = inst.DstReg.Index;
+ tgt->SrcReg[1].File = PROGRAM_BUILTIN;
+ tgt->SrcReg[1].Swizzle = SWIZZLE_1111;
+ tgt->SrcReg[2].File = PROGRAM_BUILTIN;
+ tgt->SrcReg[2].Swizzle = SWIZZLE_0000;
}
- return swiz;
-}
-static inline GLuint make_alpha_swizzle(struct prog_src_register src) {
- GLuint swiz = GET_SWZ(src.Swizzle, 3);
-
- if (swiz == 5) swiz++;
-
- if (src.NegateBase)
- swiz |= (R500_SWIZ_MOD_NEG << 3);
-
- return swiz;
+ return GL_TRUE;
}
-static inline GLuint make_sop_swizzle(struct prog_src_register src) {
- GLuint swiz = GET_SWZ(src.Swizzle, 0);
- if (swiz == 5) swiz++;
- return swiz;
-}
+static void update_params(r300ContextPtr r300, struct r500_fragment_program *fp)
+{
+ struct gl_fragment_program *mp = &fp->mesa_program;
-static inline GLuint make_strq_swizzle(struct prog_src_register src) {
- GLuint swiz = 0x0, temp = 0x0;
- int i;
- for (i = 0; i < 4; i++) {
- temp = GET_SWZ(src.Swizzle, i) & 0x3;
- swiz |= temp << i*2;
- }
- return swiz;
+ /* Ask Mesa nicely to fill in ParameterValues for us */
+ if (mp->Base.Parameters)
+ _mesa_load_state_parameters(r300->radeon.glCtx, mp->Base.Parameters);
}
-static int get_temp(struct r500_fragment_program *fp, int slot) {
-
- COMPILE_STATE;
-
- int r = fp->temp_reg_offset + cs->temp_in_use + slot;
- if (r > R500_US_NUM_TEMP_REGS) {
- ERROR("Too many temporary registers requested, can't compile!\n");
- }
-
- return r;
-}
-
-/* Borrowed verbatim from r300_fragprog since it hasn't changed. */
-static GLuint emit_const4fv(struct r500_fragment_program *fp,
- const GLfloat * cp)
+/**
+ * Transform the program to support fragment.position.
+ *
+ * Introduce a small fragment at the start of the program that will be
+ * the only code that directly reads the FRAG_ATTRIB_WPOS input.
+ * All other code pieces that reference that input will be rewritten
+ * to read from a newly allocated temporary.
+ *
+ * \todo if/when r5xx supports the radeon_program architecture, this is a
+ * likely candidate for code sharing.
+ */
+static void insert_WPOS_trailer(struct r500_fragment_program_compiler *compiler)
{
- GLuint reg = 0x0;
- int index;
+ GLuint InputsRead = compiler->fp->mesa_program.Base.InputsRead;
- for (index = 0; index < fp->const_nr; ++index) {
- if (fp->constant[index] == cp)
- break;
- }
+ if (!(InputsRead & FRAG_BIT_WPOS))
+ return;
- if (index >= fp->const_nr) {
- if (index >= R500_US_NUM_CONST_REGS) {
- ERROR("Out of hw constants!\n");
- return reg;
+ static gl_state_index tokens[STATE_LENGTH] = {
+ STATE_INTERNAL, STATE_R300_WINDOW_DIMENSION, 0, 0, 0
+ };
+ struct prog_instruction *fpi;
+ GLuint window_index;
+ int i = 0;
+ GLuint tempregi = radeonCompilerAllocateTemporary(&compiler->compiler);
+
+ fpi = radeonClauseInsertInstructions(&compiler->compiler, &compiler->compiler.Clauses[0], 0, 3);
+
+ /* perspective divide */
+ fpi[i].Opcode = OPCODE_RCP;
+
+ fpi[i].DstReg.File = PROGRAM_TEMPORARY;
+ fpi[i].DstReg.Index = tempregi;
+ fpi[i].DstReg.WriteMask = WRITEMASK_W;
+ fpi[i].DstReg.CondMask = COND_TR;
+
+ fpi[i].SrcReg[0].File = PROGRAM_INPUT;
+ fpi[i].SrcReg[0].Index = FRAG_ATTRIB_WPOS;
+ fpi[i].SrcReg[0].Swizzle = SWIZZLE_WWWW;
+ i++;
+
+ fpi[i].Opcode = OPCODE_MUL;
+
+ fpi[i].DstReg.File = PROGRAM_TEMPORARY;
+ fpi[i].DstReg.Index = tempregi;
+ fpi[i].DstReg.WriteMask = WRITEMASK_XYZ;
+ fpi[i].DstReg.CondMask = COND_TR;
+
+ fpi[i].SrcReg[0].File = PROGRAM_INPUT;
+ fpi[i].SrcReg[0].Index = FRAG_ATTRIB_WPOS;
+ fpi[i].SrcReg[0].Swizzle = SWIZZLE_XYZW;
+
+ fpi[i].SrcReg[1].File = PROGRAM_TEMPORARY;
+ fpi[i].SrcReg[1].Index = tempregi;
+ fpi[i].SrcReg[1].Swizzle = SWIZZLE_WWWW;
+ i++;
+
+ /* viewport transformation */
+ window_index = _mesa_add_state_reference(compiler->fp->mesa_program.Base.Parameters, tokens);
+
+ fpi[i].Opcode = OPCODE_MAD;
+
+ fpi[i].DstReg.File = PROGRAM_TEMPORARY;
+ fpi[i].DstReg.Index = tempregi;
+ fpi[i].DstReg.WriteMask = WRITEMASK_XYZ;
+ fpi[i].DstReg.CondMask = COND_TR;
+
+ fpi[i].SrcReg[0].File = PROGRAM_TEMPORARY;
+ fpi[i].SrcReg[0].Index = tempregi;
+ fpi[i].SrcReg[0].Swizzle =
+ MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
+
+ fpi[i].SrcReg[1].File = PROGRAM_STATE_VAR;
+ fpi[i].SrcReg[1].Index = window_index;
+ fpi[i].SrcReg[1].Swizzle =
+ MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
+
+ fpi[i].SrcReg[2].File = PROGRAM_STATE_VAR;
+ fpi[i].SrcReg[2].Index = window_index;
+ fpi[i].SrcReg[2].Swizzle =
+ MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
+ i++;
+
+ for (; i < compiler->compiler.Clauses[0].NumInstructions; ++i) {
+ int reg;
+ for (reg = 0; reg < 3; reg++) {
+ if (fpi[i].SrcReg[reg].File == PROGRAM_INPUT &&
+ fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_WPOS) {
+ fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY;
+ fpi[i].SrcReg[reg].Index = tempregi;
+ }
}
-
- fp->const_nr++;
- fp->constant[index] = cp;
- }
-
- reg = index | REG_CONSTANT;
- return reg;
-}
-
-static GLuint make_src(struct r500_fragment_program *fp, struct prog_src_register src) {
- COMPILE_STATE;
- GLuint reg;
- switch (src.File) {
- case PROGRAM_TEMPORARY:
- reg = src.Index + fp->temp_reg_offset;
- break;
- case PROGRAM_INPUT:
- reg = cs->inputs[src.Index].reg;
- break;
- case PROGRAM_LOCAL_PARAM:
- reg = emit_const4fv(fp,
- fp->mesa_program.Base.LocalParams[src.
- Index]);
- break;
- case PROGRAM_ENV_PARAM:
- reg = emit_const4fv(fp,
- fp->ctx->FragmentProgram.Parameters[src.
- Index]);
- break;
- case PROGRAM_STATE_VAR:
- case PROGRAM_NAMED_PARAM:
- case PROGRAM_CONSTANT:
- reg = emit_const4fv(fp, fp->mesa_program.Base.Parameters->
- ParameterValues[src.Index]);
- break;
- default:
- ERROR("Can't handle src.File %x\n", src.File);
- reg = 0x0;
- break;
}
- return reg;
}
-static GLuint make_dest(struct r500_fragment_program *fp, struct prog_dst_register dest) {
- GLuint reg;
- switch (dest.File) {
- case PROGRAM_TEMPORARY:
- reg = dest.Index + fp->temp_reg_offset;
- break;
- case PROGRAM_OUTPUT:
- /* Eventually we may need to handle multiple
- * rendering targets... */
- reg = dest.Index;
- break;
- default:
- ERROR("Can't handle dest.File %x\n", dest.File);
- reg = 0x0;
- break;
- }
- return reg;
-}
-static void emit_tex(struct r500_fragment_program *fp,
- struct prog_instruction *fpi, int dest, int counter)
+static GLuint build_dtm(GLuint depthmode)
{
- int hwsrc, hwdest;
- GLuint mask;
-
- mask = fpi->DstReg.WriteMask << 11;
- hwsrc = make_src(fp, fpi->SrcReg[0]);
-
- if (fpi->DstReg.File == PROGRAM_OUTPUT) {
- hwdest = get_temp(fp, 0);
- } else {
- hwdest = dest;
- }
-
- fp->inst[counter].inst0 = R500_INST_TYPE_TEX | mask
- | R500_INST_TEX_SEM_WAIT;
-
- fp->inst[counter].inst1 = R500_TEX_ID(fpi->TexSrcUnit)
- | R500_TEX_SEM_ACQUIRE | R500_TEX_IGNORE_UNCOVERED;
-
- if (fpi->TexSrcTarget == TEXTURE_RECT_INDEX)
- fp->inst[counter].inst1 |= R500_TEX_UNSCALED;
-
- switch (fpi->Opcode) {
- case OPCODE_KIL:
- fp->inst[counter].inst1 |= R500_TEX_INST_TEXKILL;
- break;
- case OPCODE_TEX:
- fp->inst[counter].inst1 |= R500_TEX_INST_LD;
- break;
- case OPCODE_TXB:
- fp->inst[counter].inst1 |= R500_TEX_INST_LODBIAS;
- break;
- case OPCODE_TXP:
- fp->inst[counter].inst1 |= R500_TEX_INST_PROJ;
- break;
+ switch(depthmode) {
default:
- ERROR("emit_tex can't handle opcode %x\n", fpi->Opcode);
+ case GL_LUMINANCE: return 0;
+ case GL_INTENSITY: return 1;
+ case GL_ALPHA: return 2;
}
-
- fp->inst[counter].inst2 = R500_TEX_SRC_ADDR(hwsrc)
- | MAKE_SWIZ_TEX_STRQ(make_strq_swizzle(fpi->SrcReg[0]))
- /* | R500_TEX_SRC_S_SWIZ_R | R500_TEX_SRC_T_SWIZ_G
- | R500_TEX_SRC_R_SWIZ_B | R500_TEX_SRC_Q_SWIZ_A */
- | R500_TEX_DST_ADDR(hwdest)
- | R500_TEX_DST_R_SWIZ_R | R500_TEX_DST_G_SWIZ_G
- | R500_TEX_DST_B_SWIZ_B | R500_TEX_DST_A_SWIZ_A;
-
- fp->inst[counter].inst3 = 0x0;
- fp->inst[counter].inst4 = 0x0;
- fp->inst[counter].inst5 = 0x0;
-
- if (fpi->DstReg.File == PROGRAM_OUTPUT) {
- counter++;
- fp->inst[counter].inst0 = R500_INST_TYPE_OUT
- | R500_INST_TEX_SEM_WAIT | (mask << 4);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGB_SEL_B_SRC0
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGB_OMOD_DISABLE;
- fp->inst[counter].inst4 = R500_ALPHA_OP_CMP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_ALPHA_SWIZ_A_A)
- | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(R500_ALPHA_SWIZ_A_A)
- | R500_ALPHA_OMOD_DISABLE;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
- | R500_ALU_RGBA_ADDRD(dest)
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- }
-}
-
-static void emit_alu(struct r500_fragment_program *fp, int counter, struct prog_instruction *fpi) {
- /* Ideally, we shouldn't have to explicitly clear memory here! */
- fp->inst[counter].inst0 = 0x0;
- fp->inst[counter].inst1 = 0x0;
- fp->inst[counter].inst2 = 0x0;
- fp->inst[counter].inst3 = 0x0;
- fp->inst[counter].inst4 = 0x0;
- fp->inst[counter].inst5 = 0x0;
-
- if (fpi->DstReg.File == PROGRAM_OUTPUT) {
- fp->inst[counter].inst0 = R500_INST_TYPE_OUT;
-
- if (fpi->DstReg.Index == FRAG_RESULT_COLR)
- fp->inst[counter].inst0 |= (fpi->DstReg.WriteMask << 15);
-
- if (fpi->DstReg.Index == FRAG_RESULT_DEPR) {
- fp->inst[counter].inst4 |= R500_ALPHA_W_OMASK;
- /* Notify the state emission! */
- fp->writes_depth = GL_TRUE;
- }
- } else {
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU
- /* pixel_mask */
- | (fpi->DstReg.WriteMask << 11);
- }
-
- fp->inst[counter].inst0 |= R500_INST_TEX_SEM_WAIT;
}
-static void emit_mov(struct r500_fragment_program *fp, int counter, struct prog_instruction *fpi, GLuint src_reg, GLuint swizzle, GLuint dest) {
- /* The r3xx shader uses MAD to implement MOV. We are using CMP, since
- * it is technically more accurate and recommended by ATI/AMD. */
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src_reg);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src_reg);
- /* (De)mangle the swizzle from Mesa to R500. */
- swizzle = make_rgba_swizzle(swizzle);
- /* 0x1FF is 9 bits, size of an RGB swizzle. */
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A((swizzle & 0x1ff))
- | R500_ALU_RGB_SEL_B_SRC0
- | MAKE_SWIZ_RGB_B((swizzle & 0x1ff))
- | R500_ALU_RGB_OMOD_DISABLE;
- fp->inst[counter].inst4 |= R500_ALPHA_OP_CMP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(GET_SWZ(swizzle, 3))
- | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(GET_SWZ(swizzle, 3))
- | R500_ALPHA_OMOD_DISABLE;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
- | R500_ALU_RGBA_ADDRD(dest)
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
-}
-
-static void emit_mad(struct r500_fragment_program *fp, int counter, struct prog_instruction *fpi, int one, int two, int three) {
- /* Note: This code was all Corbin's. Corbin is a rather hackish coder.
- * If you can make it pretty or fast, please do so! */
- emit_alu(fp, counter, fpi);
- /* Common MAD stuff */
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(make_dest(fp, fpi->DstReg));
- fp->inst[counter].inst5 |= R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(make_dest(fp, fpi->DstReg));
- switch (one) {
- case 0:
- case 1:
- case 2:
- fp->inst[counter].inst1 |= R500_RGB_ADDR0(make_src(fp, fpi->SrcReg[one]));
- fp->inst[counter].inst2 |= R500_ALPHA_ADDR0(make_src(fp, fpi->SrcReg[one]));
- fp->inst[counter].inst3 |= R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[one]));
- fp->inst[counter].inst4 |= R500_ALPHA_SEL_A_SRC0
- | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[one]));
- break;
- case R500_SWIZZLE_ZERO:
- fp->inst[counter].inst3 |= MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ZERO);
- fp->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ZERO);
- break;
- case R500_SWIZZLE_ONE:
- fp->inst[counter].inst3 |= MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE);
- fp->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE);
- break;
- default:
- ERROR("Bad src index in emit_mad: %d\n", one);
- break;
- }
- switch (two) {
- case 0:
- case 1:
- case 2:
- fp->inst[counter].inst1 |= R500_RGB_ADDR1(make_src(fp, fpi->SrcReg[two]));
- fp->inst[counter].inst2 |= R500_ALPHA_ADDR1(make_src(fp, fpi->SrcReg[two]));
- fp->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
- | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[two]));
- fp->inst[counter].inst4 |= R500_ALPHA_SEL_B_SRC1
- | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[two]));
- break;
- case R500_SWIZZLE_ZERO:
- fp->inst[counter].inst3 |= MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ZERO);
- fp->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ZERO);
- break;
- case R500_SWIZZLE_ONE:
- fp->inst[counter].inst3 |= MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
- fp->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ONE);
- break;
- default:
- ERROR("Bad src index in emit_mad: %d\n", two);
- break;
- }
- switch (three) {
- case 0:
- case 1:
- case 2:
- fp->inst[counter].inst1 |= R500_RGB_ADDR2(make_src(fp, fpi->SrcReg[three]));
- fp->inst[counter].inst2 |= R500_ALPHA_ADDR2(make_src(fp, fpi->SrcReg[three]));
- fp->inst[counter].inst5 |= R500_ALU_RGBA_SEL_C_SRC2
- | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[three]))
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
- | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[three]));
- break;
- case R500_SWIZZLE_ZERO:
- fp->inst[counter].inst5 |= MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- break;
- case R500_SWIZZLE_ONE:
- fp->inst[counter].inst5 |= MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ONE)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ONE);
- break;
- default:
- ERROR("Bad src index in emit_mad: %d\n", three);
- break;
- }
+static GLuint build_func(GLuint comparefunc)
+{
+ return comparefunc - GL_NEVER;
}
-static void emit_sop(struct r500_fragment_program *fp, int counter, struct prog_instruction *fpi, int opcode, GLuint src, GLuint swiz, GLuint dest) {
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src);
- fp->inst[counter].inst4 |= R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(swiz);
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_SOP
- | R500_ALU_RGBA_ADDRD(dest);
- switch (opcode) {
- case OPCODE_COS:
- fp->inst[counter].inst4 |= R500_ALPHA_OP_COS;
- break;
- case OPCODE_EX2:
- fp->inst[counter].inst4 |= R500_ALPHA_OP_EX2;
- break;
- case OPCODE_LG2:
- fp->inst[counter].inst4 |= R500_ALPHA_OP_LN2;
- break;
- case OPCODE_RCP:
- fp->inst[counter].inst4 |= R500_ALPHA_OP_RCP;
- break;
- case OPCODE_RSQ:
- fp->inst[counter].inst4 |= R500_ALPHA_OP_RSQ;
- break;
- case OPCODE_SIN:
- fp->inst[counter].inst4 |= R500_ALPHA_OP_SIN;
- break;
- default:
- ERROR("Bad opcode in emit_sop: %d\n", opcode);
- break;
- }
-}
-static GLboolean parse_program(struct r500_fragment_program *fp)
+/**
+ * Collect all external state that is relevant for compiling the given
+ * fragment program.
+ */
+static void build_state(
+ r300ContextPtr r300,
+ struct r500_fragment_program *fp,
+ struct r500_fragment_program_external_state *state)
{
- struct gl_fragment_program *mp = &fp->mesa_program;
- const struct prog_instruction *inst = mp->Base.Instructions;
- struct prog_instruction *fpi;
- GLuint src[3], dest = 0;
- int temp_swiz, counter = 0;
-
- if (!inst || inst[0].Opcode == OPCODE_END) {
- ERROR("The program is empty!\n");
- return GL_FALSE;
- }
+ int unit;
- for (fpi = mp->Base.Instructions; fpi->Opcode != OPCODE_END; fpi++) {
-
- if (fpi->Opcode != OPCODE_KIL) {
- dest = make_dest(fp, fpi->DstReg);
- }
+ _mesa_bzero(state, sizeof(*state));
- switch (fpi->Opcode) {
- case OPCODE_ABS:
- emit_mov(fp, counter, fpi, make_src(fp, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
- fp->inst[counter].inst3 |= R500_ALU_RGB_MOD_A_ABS
- | R500_ALU_RGB_MOD_B_ABS;
- fp->inst[counter].inst4 |= R500_ALPHA_MOD_A_ABS
- | R500_ALPHA_MOD_B_ABS;
- break;
- case OPCODE_ADD:
- /* Variation on MAD: 1*src0+src1 */
- emit_mad(fp, counter, fpi, R500_SWIZZLE_ONE, 0, 1);
- break;
- case OPCODE_CMP:
- /* This inst's selects need to be swapped as follows:
- * 0 -> C ; 1 -> B ; 2 -> A */
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- src[2] = make_src(fp, fpi->SrcReg[2]);
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[2])
- | R500_RGB_ADDR1(src[1]) | R500_RGB_ADDR2(src[0]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[2])
- | R500_ALPHA_ADDR1(src[1]) | R500_ALPHA_ADDR2(src[0]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[2]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_CMP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[2]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
- | R500_ALU_RGBA_ADDRD(dest)
- | R500_ALU_RGBA_SEL_C_SRC2
- | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
- | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[0]));
- break;
- case OPCODE_COS:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = emit_const4fv(fp, RCP_2PI);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
- | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_FRC
- | R500_ALPHA_ADDRD(get_temp(fp, 1))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 1));
- counter++;
- emit_sop(fp, counter, fpi, OPCODE_COS, get_temp(fp, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_DP3:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_DP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_DP3
- | R500_ALU_RGBA_ADDRD(dest);
- break;
- case OPCODE_DP4:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- /* Based on DP3 */
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_DP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_DP4
- | R500_ALU_RGBA_ADDRD(dest);
- break;
- case OPCODE_DPH:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- /* Based on DP3 */
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_DP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_DP4
- | R500_ALU_RGBA_ADDRD(dest);
- break;
- case OPCODE_DST:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- /* [1, src0.y*src1.y, src0.z, src1.w]
- * So basically MUL with lotsa swizzling. */
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | R500_ALU_RGB_SEL_B_SRC1;
- /* Select [1, y, z, 1] */
- temp_swiz = (make_rgb_swizzle(fpi->SrcReg[0]) & ~0x7) | R500_SWIZZLE_ONE;
- fp->inst[counter].inst3 |= MAKE_SWIZ_RGB_A(temp_swiz);
- /* Select [1, y, 1, w] */
- temp_swiz = (make_rgb_swizzle(fpi->SrcReg[0]) & ~0x1c7) | R500_SWIZZLE_ONE | (R500_SWIZZLE_ONE << 6);
- fp->inst[counter].inst3 |= MAKE_SWIZ_RGB_B(temp_swiz);
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(dest)
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- break;
- case OPCODE_EX2:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- emit_sop(fp, counter, fpi, OPCODE_EX2, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_FLR:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_FRC
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0));
- counter++;
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(get_temp(fp, 0));
- fp->inst[counter].inst3 = MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
- | R500_ALU_RGB_SEL_B_SRC0 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SWIZ_A_A
- | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(dest)
- | R500_ALU_RGBA_SEL_C_SRC1
- | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC1
- | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGBA_MOD_C_NEG;
- break;
- case OPCODE_FRC:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_FRC
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
- | R500_ALU_RGBA_ADDRD(dest);
- break;
- case OPCODE_LG2:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- emit_sop(fp, counter, fpi, OPCODE_LG2, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_LIT:
- /* To be honest, I have no idea how I came up with the following.
- * All I know is that it's based on the r3xx stuff, and was
- * concieved with the help of NyQuil. Mmm, MyQuil. */
-
- /* First instruction */
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = emit_const4fv(fp, LIT);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_ARG << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0]) | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]) | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ZERO);
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAX
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAX
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0));
- counter++;
- /* Second instruction */
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_AB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0)) | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- /* Select [w, w, w, y] */
- temp_swiz = 3 | (3 << 3) | (3 << 6);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(temp_swiz)
- | R500_ALU_RGB_SEL_B_SRC1
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_LN2
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_G;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MIN
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0));
- counter++;
- /* Third instruction */
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_AG << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- /* Select [x, x, x, z] */
- temp_swiz = 0;
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(temp_swiz)
- | R500_ALU_RGB_SEL_B_SRC0
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 1))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
- | R500_ALPHA_SEL_B_SRC0 | R500_ALPHA_SWIZ_B_B;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 1))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | R500_ALU_RGBA_A_SWIZ_0;
- counter++;
- /* Fourth instruction */
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_AR << 11);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
- fp->inst[counter].inst4 = R500_ALPHA_OP_EX2
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- /* Fifth instruction */
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_AB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- /* Select [w, w, w] */
- temp_swiz = 3 | (3 << 3) | (3 << 6);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ZERO)
- | R500_ALU_RGB_SEL_B_SRC0
- | MAKE_SWIZ_RGB_B(temp_swiz);
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SWIZ_A_1
- | R500_ALPHA_SWIZ_B_1;
- /* Select [-y, -y, -y] */
- temp_swiz = 1 | (1 << 3) | (1 << 6);
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(temp_swiz)
- | R500_ALU_RGBA_MOD_C_NEG
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- /* Final instruction */
- emit_mov(fp, counter, fpi, get_temp(fp, 0), SWIZZLE_NOOP, dest);
- break;
- case OPCODE_LRP:
- /* src0 * src1 + INV(src0) * src2
- * 1) MUL src0, src1, temp
- * 2) PRE 1-src0; MAD srcp, src2, temp */
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- src[2] = make_src(fp, fpi->SrcReg[2]);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | R500_INST_NOP | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[2])
- | R500_RGB_ADDR2(get_temp(fp, 0))
- | R500_RGB_SRCP_OP_1_MINUS_RGB0;
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[2])
- | R500_ALPHA_ADDR2(get_temp(fp, 0))
- | R500_ALPHA_SRCP_OP_1_MINUS_A0;
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRCP
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRCP | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(dest)
- | R500_ALU_RGBA_SEL_C_SRC2 | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[2]))
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
- | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[2]));
- break;
- case OPCODE_MAD:
- emit_mad(fp, counter, fpi, 0, 1, 2);
- break;
- case OPCODE_MAX:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0]) | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]) | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1
- | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MAX
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAX
- | R500_ALU_RGBA_ADDRD(dest);
- break;
- case OPCODE_MIN:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0]) | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]) | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1
- | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MIN
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MIN
- | R500_ALU_RGBA_ADDRD(dest);
- break;
- case OPCODE_MOV:
- emit_mov(fp, counter, fpi, make_src(fp, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
- break;
- case OPCODE_MUL:
- /* Variation on MAD: src0*src1+0 */
- emit_mad(fp, counter, fpi, 0, 1, R500_SWIZZLE_ZERO);
- break;
- case OPCODE_POW:
- /* POW(a,b) = EX2(LN2(a)*b) */
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- emit_sop(fp, counter, fpi, OPCODE_LG2, src[0], make_sop_swizzle(fpi->SrcReg[0]), get_temp(fp, 0));
- fp->inst[counter].inst0 |= (R500_WRITEMASK_ARGB << 11);
- counter++;
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0))
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0))
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 1))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 1))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- emit_sop(fp, counter, fpi, OPCODE_EX2, get_temp(fp, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_RCP:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- emit_sop(fp, counter, fpi, OPCODE_RCP, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_RSQ:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- emit_sop(fp, counter, fpi, OPCODE_RSQ, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_SCS:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = emit_const4fv(fp, RCP_2PI);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
- | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_FRC
- | R500_ALPHA_ADDRD(get_temp(fp, 1))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 1));
- counter++;
- /* Do a cosine, then a sine, masking out the channels we want to protect. */
- /* Cosine only goes in R (x) channel. */
- fpi->DstReg.WriteMask = 0x1;
- emit_sop(fp, counter, fpi, OPCODE_COS, get_temp(fp, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
- counter++;
- /* Sine only goes in G (y) channel. */
- fpi->DstReg.WriteMask = 0x2;
- emit_sop(fp, counter, fpi, OPCODE_SIN, get_temp(fp, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_SGE:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR1(src[0])
- | R500_RGB_ADDR2(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR1(src[0])
- | R500_ALPHA_ADDR2(src[1]);
- fp->inst[counter].inst3 = /* 1 */
- MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | R500_ALU_RGBA_SEL_C_SRC2
- | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[1]))
- | R500_ALU_RGBA_MOD_C_NEG
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
- | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[1]))
- | R500_ALU_RGBA_ALPHA_MOD_C_NEG;
- counter++;
- /* This inst's selects need to be swapped as follows:
- * 0 -> C ; 1 -> B ; 2 -> A */
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
- | R500_ALU_RGB_SEL_B_SRC0
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ZERO);
- fp->inst[counter].inst4 |= R500_ALPHA_OP_CMP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
- | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ZERO);
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
- | R500_ALU_RGBA_ADDRD(dest)
- | R500_ALU_RGBA_SEL_C_SRC0
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC0
- | R500_ALU_RGBA_A_SWIZ_A;
- break;
- case OPCODE_SIN:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = emit_const4fv(fp, RCP_2PI);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
- | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB);
- fp->inst[counter].inst4 = R500_ALPHA_OP_FRC
- | R500_ALPHA_ADDRD(get_temp(fp, 1))
- | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 1));
- counter++;
- emit_sop(fp, counter, fpi, OPCODE_SIN, get_temp(fp, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
- break;
- case OPCODE_SLT:
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_ARGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR1(src[0])
- | R500_RGB_ADDR2(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR1(src[0])
- | R500_ALPHA_ADDR2(src[1]);
- fp->inst[counter].inst3 = /* 1 */
- MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
- | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[0]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | R500_ALU_RGBA_SEL_C_SRC2
- | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[1]))
- | R500_ALU_RGBA_MOD_C_NEG
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
- | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[1]))
- | R500_ALU_RGBA_ALPHA_MOD_C_NEG;
- counter++;
- /* This inst's selects need to be swapped as follows:
- * 0 -> C ; 1 -> B ; 2 -> A */
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ZERO)
- | R500_ALU_RGB_SEL_B_SRC0
- | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
- fp->inst[counter].inst4 |= R500_ALPHA_OP_CMP
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ZERO)
- | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ONE);
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
- | R500_ALU_RGBA_ADDRD(dest)
- | R500_ALU_RGBA_SEL_C_SRC0
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGBA_ALPHA_SEL_C_SRC0
- | R500_ALU_RGBA_A_SWIZ_A;
- break;
- case OPCODE_SUB:
- /* Variation on MAD: 1*src0-src1 */
- fpi->SrcReg[1].NegateBase = 0xF; /* NEG_XYZW */
- emit_mad(fp, counter, fpi, R500_SWIZZLE_ONE, 0, 1);
- break;
- case OPCODE_SWZ:
- /* TODO: The rarer negation masks! */
- emit_mov(fp, counter, fpi, make_src(fp, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
- break;
- case OPCODE_XPD:
- /* src0 * src1 - src1 * src0
- * 1) MUL temp.xyz, src0.yzx, src1.zxy
- * 2) MAD src0.zxy, src1.yzx, -temp.xyz */
- src[0] = make_src(fp, fpi->SrcReg[0]);
- src[1] = make_src(fp, fpi->SrcReg[1]);
- fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
- | (R500_WRITEMASK_RGB << 11);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1]);
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1]);
- /* Select [y, z, x] */
- temp_swiz = make_rgb_swizzle(fpi->SrcReg[0]);
- temp_swiz = (GET_SWZ(temp_swiz, 1) << 0) | (GET_SWZ(temp_swiz, 2) << 3) | (GET_SWZ(temp_swiz, 0) << 6);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(temp_swiz);
- /* Select [z, x, y] */
- temp_swiz = make_rgb_swizzle(fpi->SrcReg[1]);
- temp_swiz = (GET_SWZ(temp_swiz, 2) << 0) | (GET_SWZ(temp_swiz, 0) << 3) | (GET_SWZ(temp_swiz, 1) << 6);
- fp->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
- | MAKE_SWIZ_RGB_B(temp_swiz);
- fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(get_temp(fp, 0))
- | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
- | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
- | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
- counter++;
- emit_alu(fp, counter, fpi);
- fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
- | R500_RGB_ADDR1(src[1])
- | R500_RGB_ADDR2(get_temp(fp, 0));
- fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
- | R500_ALPHA_ADDR1(src[1])
- | R500_ALPHA_ADDR2(get_temp(fp, 0));
- /* Select [z, x, y] */
- temp_swiz = make_rgb_swizzle(fpi->SrcReg[0]);
- temp_swiz = (GET_SWZ(temp_swiz, 2) << 0) | (GET_SWZ(temp_swiz, 0) << 3) | (GET_SWZ(temp_swiz, 1) << 6);
- fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
- | MAKE_SWIZ_RGB_A(temp_swiz);
- /* Select [y, z, x] */
- temp_swiz = make_rgb_swizzle(fpi->SrcReg[1]);
- temp_swiz = (GET_SWZ(temp_swiz, 1) << 0) | (GET_SWZ(temp_swiz, 2) << 3) | (GET_SWZ(temp_swiz, 0) << 6);
- fp->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
- | MAKE_SWIZ_RGB_B(temp_swiz);
- fp->inst[counter].inst4 |= R500_ALPHA_OP_MAD
- | R500_ALPHA_ADDRD(dest)
- | R500_ALPHA_SWIZ_A_1
- | R500_ALPHA_SWIZ_B_1;
- fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
- | R500_ALU_RGBA_ADDRD(dest)
- | R500_ALU_RGBA_SEL_C_SRC2
- | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
- | R500_ALU_RGBA_MOD_C_NEG
- | R500_ALU_RGBA_A_SWIZ_0;
- break;
- case OPCODE_KIL:
- case OPCODE_TEX:
- case OPCODE_TXB:
- case OPCODE_TXP:
- emit_tex(fp, fpi, dest, counter);
- if (fpi->DstReg.File == PROGRAM_OUTPUT)
- counter++;
- break;
- default:
- ERROR("unknown fpi->Opcode %s\n", _mesa_opcode_string(fpi->Opcode));
- break;
- }
+ for(unit = 0; unit < 16; ++unit) {
+ if (fp->mesa_program.Base.ShadowSamplers & (1 << unit)) {
+ struct gl_texture_object* tex = r300->radeon.glCtx->Texture.Unit[unit]._Current;
- /* Finishing touches */
- if (fpi->SaturateMode == SATURATE_ZERO_ONE) {
- fp->inst[counter].inst0 |= R500_INST_RGB_CLAMP | R500_INST_ALPHA_CLAMP;
+ state->unit[unit].depth_texture_mode = build_dtm(tex->DepthMode);
+ state->unit[unit].texture_compare_func = build_func(tex->CompareFunc);
}
-
- counter++;
-
- if (fp->error)
- return GL_FALSE;
-
}
-
- /* Finish him! (If it's an ALU/OUT instruction...) */
- if ((fp->inst[counter-1].inst0 & 0x3) == 1) {
- fp->inst[counter-1].inst0 |= R500_INST_LAST;
- } else {
- /* We still need to put an output inst, right? */
- WARN_ONCE("Final FP instruction is not an OUT.\n");
- }
-
- fp->cs->nrslots = counter;
-
- fp->max_temp_idx++;
-
- return GL_TRUE;
}
-static void init_program(r300ContextPtr r300, struct r500_fragment_program *fp)
-{
- struct r300_pfs_compile_state *cs = NULL;
- struct gl_fragment_program *mp = &fp->mesa_program;
- struct prog_instruction *fpi;
- GLuint InputsRead = mp->Base.InputsRead;
- GLuint temps_used = 0;
- int i, j;
-
- /* New compile, reset tracking data */
- fp->optimization =
- driQueryOptioni(&r300->radeon.optionCache, "fp_optimization");
- fp->translated = GL_FALSE;
- fp->error = GL_FALSE;
- fp->cs = cs = &(R300_CONTEXT(fp->ctx)->state.pfs_compile);
- fp->const_nr = 0;
- /* Size of pixel stack, plus 1. */
- fp->max_temp_idx = 1;
- /* Temp register offset. */
- fp->temp_reg_offset = 0;
- /* Whether or not we perform any depth writing. */
- fp->writes_depth = GL_FALSE;
-
- _mesa_memset(cs, 0, sizeof(*fp->cs));
- for (i = 0; i < PFS_MAX_ALU_INST; i++) {
- for (j = 0; j < 3; j++) {
- cs->slot[i].vsrc[j] = SRC_CONST;
- cs->slot[i].ssrc[j] = SRC_CONST;
- }
- }
-
- /* Work out what temps the Mesa inputs correspond to, this must match
- * what setup_rs_unit does, which shouldn't be a problem as rs_unit
- * configures itself based on the fragprog's InputsRead
- *
- * NOTE: this depends on get_hw_temp() allocating registers in order,
- * starting from register 0, so we're just going to do that instead.
- */
-
- /* Texcoords come first */
- for (i = 0; i < fp->ctx->Const.MaxTextureUnits; i++) {
- if (InputsRead & (FRAG_BIT_TEX0 << i)) {
- cs->inputs[FRAG_ATTRIB_TEX0 + i].refcount = 0;
- cs->inputs[FRAG_ATTRIB_TEX0 + i].reg =
- fp->temp_reg_offset;
- fp->temp_reg_offset++;
- }
- }
- InputsRead &= ~FRAG_BITS_TEX_ANY;
-
- /* fragment position treated as a texcoord */
- if (InputsRead & FRAG_BIT_WPOS) {
- cs->inputs[FRAG_ATTRIB_WPOS].refcount = 0;
- cs->inputs[FRAG_ATTRIB_WPOS].reg =
- fp->temp_reg_offset;
- fp->temp_reg_offset++;
- }
- InputsRead &= ~FRAG_BIT_WPOS;
-
- /* Then primary colour */
- if (InputsRead & FRAG_BIT_COL0) {
- cs->inputs[FRAG_ATTRIB_COL0].refcount = 0;
- cs->inputs[FRAG_ATTRIB_COL0].reg =
- fp->temp_reg_offset;
- fp->temp_reg_offset++;
- }
- InputsRead &= ~FRAG_BIT_COL0;
-
- /* Secondary color */
- if (InputsRead & FRAG_BIT_COL1) {
- cs->inputs[FRAG_ATTRIB_COL1].refcount = 0;
- cs->inputs[FRAG_ATTRIB_COL1].reg =
- fp->temp_reg_offset;
- fp->temp_reg_offset++;
- }
- InputsRead &= ~FRAG_BIT_COL1;
-
- /* Anything else */
- if (InputsRead) {
- WARN_ONCE("Don't know how to handle inputs 0x%x\n", InputsRead);
- /* force read from hwreg 0 for now */
- for (i = 0; i < 32; i++)
- if (InputsRead & (1 << i))
- cs->inputs[i].reg = 0;
- }
+static void dump_program(struct r500_fragment_program_code *code);
- if (!mp->Base.Instructions) {
- ERROR("No instructions found in program, going to go die now.\n");
- return;
- }
+void r500TranslateFragmentShader(r300ContextPtr r300,
+ struct r500_fragment_program *fp)
+{
+ struct r500_fragment_program_external_state state;
- for (fpi = mp->Base.Instructions; fpi->Opcode != OPCODE_END; fpi++) {
- for (i = 0; i < 3; i++) {
- if (fpi->SrcReg[i].File == PROGRAM_TEMPORARY) {
- if (fpi->SrcReg[i].Index >= temps_used)
- temps_used = fpi->SrcReg[i].Index + 1;
- }
- }
+ build_state(r300, fp, &state);
+ if (_mesa_memcmp(&fp->state, &state, sizeof(state))) {
+ /* TODO: cache compiled programs */
+ fp->translated = GL_FALSE;
+ _mesa_memcpy(&fp->state, &state, sizeof(state));
}
- cs->temp_in_use = temps_used + 1;
-
- fp->max_temp_idx = fp->temp_reg_offset + cs->temp_in_use;
-
- if (RADEON_DEBUG & DEBUG_PIXEL)
- fprintf(stderr, "FP temp indices: fp->max_temp_idx: %d cs->temp_in_use: %d\n", fp->max_temp_idx, cs->temp_in_use);
-}
+ if (!fp->translated) {
+ struct r500_fragment_program_compiler compiler;
-static void update_params(struct r500_fragment_program *fp)
-{
- struct gl_fragment_program *mp = &fp->mesa_program;
+ compiler.r300 = r300;
+ compiler.fp = fp;
+ compiler.code = &fp->code;
- /* Ask Mesa nicely to fill in ParameterValues for us */
- if (mp->Base.Parameters)
- _mesa_load_state_parameters(fp->ctx, mp->Base.Parameters);
-}
+ radeonCompilerInit(&compiler.compiler, r300->radeon.glCtx, &fp->mesa_program.Base);
-static void dumb_shader(struct r500_fragment_program *fp)
-{
- fp->inst[0].inst0 = R500_INST_TYPE_TEX
- | R500_INST_TEX_SEM_WAIT
- | R500_INST_RGB_WMASK_R
- | R500_INST_RGB_WMASK_G
- | R500_INST_RGB_WMASK_B
- | R500_INST_ALPHA_WMASK
- | R500_INST_RGB_CLAMP
- | R500_INST_ALPHA_CLAMP;
- fp->inst[0].inst1 = R500_TEX_ID(0)
- | R500_TEX_INST_LD
- | R500_TEX_SEM_ACQUIRE
- | R500_TEX_IGNORE_UNCOVERED;
- fp->inst[0].inst2 = R500_TEX_SRC_ADDR(0)
- | R500_TEX_SRC_S_SWIZ_R
- | R500_TEX_SRC_T_SWIZ_G
- | R500_TEX_DST_ADDR(0)
- | R500_TEX_DST_R_SWIZ_R
- | R500_TEX_DST_G_SWIZ_G
- | R500_TEX_DST_B_SWIZ_B
- | R500_TEX_DST_A_SWIZ_A;
- fp->inst[0].inst3 = R500_DX_ADDR(0)
- | R500_DX_S_SWIZ_R
- | R500_DX_T_SWIZ_R
- | R500_DX_R_SWIZ_R
- | R500_DX_Q_SWIZ_R
- | R500_DY_ADDR(0)
- | R500_DY_S_SWIZ_R
- | R500_DY_T_SWIZ_R
- | R500_DY_R_SWIZ_R
- | R500_DY_Q_SWIZ_R;
- fp->inst[0].inst4 = 0x0;
- fp->inst[0].inst5 = 0x0;
-
- fp->inst[1].inst0 = R500_INST_TYPE_OUT |
- R500_INST_TEX_SEM_WAIT |
- R500_INST_LAST |
- R500_INST_RGB_OMASK_R |
- R500_INST_RGB_OMASK_G |
- R500_INST_RGB_OMASK_B |
- R500_INST_ALPHA_OMASK;
- fp->inst[1].inst1 = R500_RGB_ADDR0(0) |
- R500_RGB_ADDR1(0) |
- R500_RGB_ADDR1_CONST |
- R500_RGB_ADDR2(0) |
- R500_RGB_ADDR2_CONST |
- R500_RGB_SRCP_OP_1_MINUS_2RGB0;
- fp->inst[1].inst2 = R500_ALPHA_ADDR0(0) |
- R500_ALPHA_ADDR1(0) |
- R500_ALPHA_ADDR1_CONST |
- R500_ALPHA_ADDR2(0) |
- R500_ALPHA_ADDR2_CONST |
- R500_ALPHA_SRCP_OP_1_MINUS_2A0;
- fp->inst[1].inst3 = R500_ALU_RGB_SEL_A_SRC0 |
- R500_ALU_RGB_R_SWIZ_A_R |
- R500_ALU_RGB_G_SWIZ_A_G |
- R500_ALU_RGB_B_SWIZ_A_B |
- R500_ALU_RGB_SEL_B_SRC0 |
- R500_ALU_RGB_R_SWIZ_B_1 |
- R500_ALU_RGB_B_SWIZ_B_1 |
- R500_ALU_RGB_G_SWIZ_B_1;
- fp->inst[1].inst4 = R500_ALPHA_OP_MAD |
- R500_ALPHA_SWIZ_A_A |
- R500_ALPHA_SWIZ_B_1;
- fp->inst[1].inst5 = R500_ALU_RGBA_OP_MAD |
- R500_ALU_RGBA_R_SWIZ_0 |
- R500_ALU_RGBA_G_SWIZ_0 |
- R500_ALU_RGBA_B_SWIZ_0 |
- R500_ALU_RGBA_A_SWIZ_0;
-
- fp->cs->nrslots = 2;
- fp->translated = GL_TRUE;
-}
+ insert_WPOS_trailer(&compiler);
-void r500TranslateFragmentShader(r300ContextPtr r300,
- struct r500_fragment_program *fp)
-{
+ struct radeon_program_transformation transformations[1] = {
+ { &transform_TEX, &compiler }
+ };
+ radeonClauseLocalTransform(&compiler.compiler,
+ &compiler.compiler.Clauses[0],
+ 1, transformations);
- struct r300_pfs_compile_state *cs = NULL;
+ if (RADEON_DEBUG & DEBUG_PIXEL) {
+ _mesa_printf("Compiler state after transformations:\n");
+ radeonCompilerDump(&compiler.compiler);
+ }
- if (!fp->translated) {
+ fp->translated = r500FragmentProgramEmit(&compiler);
- init_program(r300, fp);
- cs = fp->cs;
+ radeonCompilerCleanup(&compiler.compiler);
- if (parse_program(fp) == GL_FALSE) {
- ERROR("Huh. Couldn't parse program. There should be additional errors explaining why.\nUsing dumb shader...\n");
- dumb_shader(fp);
- fp->inst_offset = 0;
- fp->inst_end = cs->nrslots - 1;
- return;
- }
- fp->inst_offset = 0;
- fp->inst_end = cs->nrslots - 1;
+ r300UpdateStateParameters(r300->radeon.glCtx, _NEW_PROGRAM);
- fp->translated = GL_TRUE;
if (RADEON_DEBUG & DEBUG_PIXEL) {
fprintf(stderr, "Mesa program:\n");
fprintf(stderr, "-------------\n");
_mesa_print_program(&fp->mesa_program.Base);
fflush(stdout);
- dump_program(fp);
+ if (fp->translated)
+ dump_program(&fp->code);
}
-
- r300UpdateStateParameters(fp->ctx, _NEW_PROGRAM);
}
- update_params(fp);
+ update_params(r300, fp);
}
@@ -1561,7 +445,7 @@ static char *to_texop(int val)
return NULL;
}
-static void dump_program(struct r500_fragment_program *fp)
+static void dump_program(struct r500_fragment_program_code *code)
{
fprintf(stderr, "R500 Fragment Program:\n--------\n");
@@ -1571,18 +455,18 @@ static void dump_program(struct r500_fragment_program *fp)
uint32_t inst0;
char *str = NULL;
- if (fp->const_nr) {
+ if (code->const_nr) {
fprintf(stderr, "--------\nConstants:\n");
- for (n = 0; n < fp->const_nr; n++) {
+ for (n = 0; n < code->const_nr; n++) {
fprintf(stderr, "Constant %d: %f %f\n\t %f %f\n", n,
- fp->constant[n][0], fp->constant[n][1], fp->constant[n][2],
- fp->constant[n][3]);
+ code->constant[n][0], code->constant[n][1], code->constant[n][2],
+ code->constant[n][3]);
}
fprintf(stderr, "--------\n");
}
- for (n = 0; n < fp->inst_end+1; n++) {
- inst0 = inst = fp->inst[n].inst0;
+ for (n = 0; n < code->inst_end+1; n++) {
+ inst0 = inst = code->inst[n].inst0;
fprintf(stderr,"%d\t0:CMN_INST 0x%08x:", n, inst);
switch(inst & 0x3) {
case R500_INST_TYPE_ALU: str = "ALU"; break;
@@ -1601,8 +485,8 @@ static void dump_program(struct r500_fragment_program *fp)
switch(inst0 & 0x3) {
case 0:
case 1:
- fprintf(stderr,"\t1:RGB_ADDR 0x%08x:", fp->inst[n].inst1);
- inst = fp->inst[n].inst1;
+ fprintf(stderr,"\t1:RGB_ADDR 0x%08x:", code->inst[n].inst1);
+ inst = code->inst[n].inst1;
fprintf(stderr,"Addr0: %d%c, Addr1: %d%c, Addr2: %d%c, srcp:%d\n",
inst & 0xff, (inst & (1<<8)) ? 'c' : 't',
@@ -1610,15 +494,15 @@ static void dump_program(struct r500_fragment_program *fp)
(inst >> 20) & 0xff, (inst & (1<<28)) ? 'c' : 't',
(inst >> 30));
- fprintf(stderr,"\t2:ALPHA_ADDR 0x%08x:", fp->inst[n].inst2);
- inst = fp->inst[n].inst2;
+ fprintf(stderr,"\t2:ALPHA_ADDR 0x%08x:", code->inst[n].inst2);
+ inst = code->inst[n].inst2;
fprintf(stderr,"Addr0: %d%c, Addr1: %d%c, Addr2: %d%c, srcp:%d\n",
inst & 0xff, (inst & (1<<8)) ? 'c' : 't',
(inst >> 10) & 0xff, (inst & (1<<18)) ? 'c' : 't',
(inst >> 20) & 0xff, (inst & (1<<28)) ? 'c' : 't',
(inst >> 30));
- fprintf(stderr,"\t3 RGB_INST: 0x%08x:", fp->inst[n].inst3);
- inst = fp->inst[n].inst3;
+ fprintf(stderr,"\t3 RGB_INST: 0x%08x:", code->inst[n].inst3);
+ inst = code->inst[n].inst3;
fprintf(stderr,"rgb_A_src:%d %s/%s/%s %d rgb_B_src:%d %s/%s/%s %d\n",
(inst) & 0x3, toswiz((inst >> 2) & 0x7), toswiz((inst >> 5) & 0x7), toswiz((inst >> 8) & 0x7),
(inst >> 11) & 0x3,
@@ -1626,16 +510,16 @@ static void dump_program(struct r500_fragment_program *fp)
(inst >> 24) & 0x3);
- fprintf(stderr,"\t4 ALPHA_INST:0x%08x:", fp->inst[n].inst4);
- inst = fp->inst[n].inst4;
+ fprintf(stderr,"\t4 ALPHA_INST:0x%08x:", code->inst[n].inst4);
+ inst = code->inst[n].inst4;
fprintf(stderr,"%s dest:%d%s alp_A_src:%d %s %d alp_B_src:%d %s %d w:%d\n", to_alpha_op(inst & 0xf),
(inst >> 4) & 0x7f, inst & (1<<11) ? "(rel)":"",
(inst >> 12) & 0x3, toswiz((inst >> 14) & 0x7), (inst >> 17) & 0x3,
(inst >> 19) & 0x3, toswiz((inst >> 21) & 0x7), (inst >> 24) & 0x3,
(inst >> 31) & 0x1);
- fprintf(stderr,"\t5 RGBA_INST: 0x%08x:", fp->inst[n].inst5);
- inst = fp->inst[n].inst5;
+ fprintf(stderr,"\t5 RGBA_INST: 0x%08x:", code->inst[n].inst5);
+ inst = code->inst[n].inst5;
fprintf(stderr,"%s dest:%d%s rgb_C_src:%d %s/%s/%s %d alp_C_src:%d %s %d\n", toop(inst & 0xf),
(inst >> 4) & 0x7f, inst & (1<<11) ? "(rel)":"",
(inst >> 12) & 0x3, toswiz((inst >> 14) & 0x7), toswiz((inst >> 17) & 0x7), toswiz((inst >> 20) & 0x7),
@@ -1645,11 +529,11 @@ static void dump_program(struct r500_fragment_program *fp)
case 2:
break;
case 3:
- inst = fp->inst[n].inst1;
+ inst = code->inst[n].inst1;
fprintf(stderr,"\t1:TEX_INST: 0x%08x: id: %d op:%s, %s, %s %s\n", inst, (inst >> 16) & 0xf,
to_texop((inst >> 22) & 0x7), (inst & (1<<25)) ? "ACQ" : "",
(inst & (1<<26)) ? "IGNUNC" : "", (inst & (1<<27)) ? "UNSCALED" : "SCALED");
- inst = fp->inst[n].inst2;
+ inst = code->inst[n].inst2;
fprintf(stderr,"\t2:TEX_ADDR: 0x%08x: src: %d%s %s/%s/%s/%s dst: %d%s %s/%s/%s/%s\n", inst,
inst & 127, inst & (1<<7) ? "(rel)" : "",
toswiz((inst >> 8) & 0x3), toswiz((inst >> 10) & 0x3),
@@ -1658,7 +542,7 @@ static void dump_program(struct r500_fragment_program *fp)
toswiz((inst >> 24) & 0x3), toswiz((inst >> 26) & 0x3),
toswiz((inst >> 28) & 0x3), toswiz((inst >> 30) & 0x3));
- fprintf(stderr,"\t3:TEX_DXDY: 0x%08x\n", fp->inst[n].inst3);
+ fprintf(stderr,"\t3:TEX_DXDY: 0x%08x\n", code->inst[n].inst3);
break;
}
fprintf(stderr,"\n");
diff --git a/src/mesa/drivers/dri/r300/r500_fragprog.h b/src/mesa/drivers/dri/r300/r500_fragprog.h
index 5dd2def1c4..ff6a9002c1 100644
--- a/src/mesa/drivers/dri/r300/r500_fragprog.h
+++ b/src/mesa/drivers/dri/r300/r500_fragprog.h
@@ -36,10 +36,14 @@
#include "glheader.h"
#include "macros.h"
#include "enums.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_print.h"
#include "shader/program.h"
#include "shader/prog_instruction.h"
#include "r300_context.h"
+#include "r300_state.h"
+#include "radeon_program.h"
/* supported hw opcodes */
#define PFS_OP_MAD 0
@@ -76,4 +80,13 @@ struct r500_fragment_program;
extern void r500TranslateFragmentShader(r300ContextPtr r300,
struct r500_fragment_program *fp);
+struct r500_fragment_program_compiler {
+ r300ContextPtr r300;
+ struct r500_fragment_program *fp;
+ struct r500_fragment_program_code *code;
+ struct radeon_compiler compiler;
+};
+
+extern GLboolean r500FragmentProgramEmit(struct r500_fragment_program_compiler *compiler);
+
#endif
diff --git a/src/mesa/drivers/dri/r300/r500_fragprog_emit.c b/src/mesa/drivers/dri/r300/r500_fragprog_emit.c
new file mode 100644
index 0000000000..e1ad342690
--- /dev/null
+++ b/src/mesa/drivers/dri/r300/r500_fragprog_emit.c
@@ -0,0 +1,1533 @@
+/*
+ * Copyright (C) 2005 Ben Skeggs.
+ *
+ * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Adaptation and modification for ATI/AMD Radeon R500 GPU chipsets.
+ *
+ * All Rights Reserved.
+ *
+ * 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 (including the
+ * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+ *
+ */
+
+/**
+ * \file
+ *
+ * \author Ben Skeggs <darktama@iinet.net.au>
+ *
+ * \author Jerome Glisse <j.glisse@gmail.com>
+ *
+ * \author Corbin Simpson <MostAwesomeDude@gmail.com>
+ *
+ * \todo Depth write, WPOS/FOGC inputs
+ *
+ * \todo FogOption
+ *
+ */
+
+#include "glheader.h"
+#include "macros.h"
+#include "enums.h"
+#include "shader/prog_instruction.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_print.h"
+
+#include "r300_context.h"
+#include "r500_fragprog.h"
+#include "r300_reg.h"
+#include "r300_state.h"
+
+/* Mapping Mesa registers to R500 temporaries */
+struct reg_acc {
+ int reg; /* Assigned hw temp */
+ unsigned int refcount; /* Number of uses by mesa program */
+};
+
+/**
+ * Describe the current lifetime information for an R300 temporary
+ */
+struct reg_lifetime {
+ /* Index of the first slot where this register is free in the sense
+ that it can be used as a new destination register.
+ This is -1 if the register has been assigned to a Mesa register
+ and the last access to the register has not yet been emitted */
+ int free;
+
+ /* Index of the first slot where this register is currently reserved.
+ This is used to stop e.g. a scalar operation from being moved
+ before the allocation time of a register that was first allocated
+ for a vector operation. */
+ int reserved;
+
+ /* Index of the first slot in which the register can be used as a
+ source without losing the value that is written by the last
+ emitted instruction that writes to the register */
+ int vector_valid;
+ int scalar_valid;
+
+ /* Index to the slot where the register was last read.
+ This is also the first slot in which the register may be written again */
+ int vector_lastread;
+ int scalar_lastread;
+};
+
+/**
+ * Store usage information about an ALU instruction slot during the
+ * compilation of a fragment program.
+ */
+#define SLOT_SRC_VECTOR (1<<0)
+#define SLOT_SRC_SCALAR (1<<3)
+#define SLOT_SRC_BOTH (SLOT_SRC_VECTOR | SLOT_SRC_SCALAR)
+#define SLOT_OP_VECTOR (1<<16)
+#define SLOT_OP_SCALAR (1<<17)
+#define SLOT_OP_BOTH (SLOT_OP_VECTOR | SLOT_OP_SCALAR)
+
+struct r500_pfs_compile_slot {
+ /* Bitmask indicating which parts of the slot are used, using SLOT_ constants
+ defined above */
+ unsigned int used;
+
+ /* Selected sources */
+ int vsrc[3];
+ int ssrc[3];
+};
+
+/**
+ * Store information during compilation of fragment programs.
+ */
+struct r500_pfs_compile_state {
+ struct r500_fragment_program_compiler *compiler;
+
+ /* number of ALU slots used so far */
+ int nrslots;
+
+ /* Track which (parts of) slots are already filled with instructions */
+ struct r500_pfs_compile_slot slot[PFS_MAX_ALU_INST];
+
+ /* Track the validity of R300 temporaries */
+ struct reg_lifetime hwtemps[PFS_NUM_TEMP_REGS];
+
+ /* Used to map Mesa's inputs/temps onto hardware temps */
+ int temp_in_use;
+ struct reg_acc temps[PFS_NUM_TEMP_REGS];
+ struct reg_acc inputs[32]; /* don't actually need 32... */
+
+ /* Track usage of hardware temps, for register allocation,
+ * indirection detection, etc. */
+ GLuint used_in_node;
+ GLuint dest_in_node;
+};
+
+/*
+ * Useful macros and values
+ */
+#define ERROR(fmt, args...) do { \
+ fprintf(stderr, "%s::%s(): " fmt "\n", \
+ __FILE__, __FUNCTION__, ##args); \
+ cs->compiler->fp->error = GL_TRUE; \
+ } while(0)
+
+#define PROG_CODE struct r500_fragment_program_code *code = cs->compiler->code
+
+#define R500_US_NUM_TEMP_REGS 128
+#define R500_US_NUM_CONST_REGS 256
+
+/* "Register" flags */
+#define REG_CONSTANT (1 << 8)
+#define REG_SRC_REL (1 << 9)
+#define REG_DEST_REL (1 << 7)
+
+/* Swizzle tools */
+#define R500_SWIZZLE_ZERO 4
+#define R500_SWIZZLE_HALF 5
+#define R500_SWIZZLE_ONE 6
+#define R500_SWIZ_RGB_ZERO ((4 << 0) | (4 << 3) | (4 << 6))
+#define R500_SWIZ_RGB_ONE ((6 << 0) | (6 << 3) | (6 << 6))
+#define R500_SWIZ_RGB_RGB ((0 << 0) | (1 << 3) | (2 << 6))
+#define R500_SWIZ_MOD_NEG 1
+#define R500_SWIZ_MOD_ABS 2
+#define R500_SWIZ_MOD_NEG_ABS 3
+/* Swizzles for inst2 */
+#define MAKE_SWIZ_TEX_STRQ(x) (x << 8)
+#define MAKE_SWIZ_TEX_RGBA(x) (x << 24)
+/* Swizzles for inst3 */
+#define MAKE_SWIZ_RGB_A(x) (x << 2)
+#define MAKE_SWIZ_RGB_B(x) (x << 15)
+/* Swizzles for inst4 */
+#define MAKE_SWIZ_ALPHA_A(x) (x << 14)
+#define MAKE_SWIZ_ALPHA_B(x) (x << 21)
+/* Swizzle for inst5 */
+#define MAKE_SWIZ_RGBA_C(x) (x << 14)
+#define MAKE_SWIZ_ALPHA_C(x) (x << 27)
+
+/* Writemasks */
+#define R500_WRITEMASK_G 0x2
+#define R500_WRITEMASK_B 0x4
+#define R500_WRITEMASK_RGB 0x7
+#define R500_WRITEMASK_A 0x8
+#define R500_WRITEMASK_AR 0x9
+#define R500_WRITEMASK_AG 0xA
+#define R500_WRITEMASK_ARG 0xB
+#define R500_WRITEMASK_AB 0xC
+#define R500_WRITEMASK_ARGB 0xF
+
+/* 1/(2pi), needed for quick modulus in trig insts
+ * Thanks to glisse for pointing out how to do it! */
+static const GLfloat RCP_2PI[] = {0.15915494309189535,
+ 0.15915494309189535,
+ 0.15915494309189535,
+ 0.15915494309189535};
+
+static const GLfloat LIT[] = {127.999999,
+ 127.999999,
+ 127.999999,
+ -127.999999};
+
+static inline GLuint make_rgb_swizzle(struct prog_src_register src) {
+ GLuint swiz = 0x0;
+ GLuint temp;
+ /* This could be optimized, but it should be plenty fast already. */
+ int i;
+ for (i = 0; i < 3; i++) {
+ temp = GET_SWZ(src.Swizzle, i);
+ /* Fix SWIZZLE_ONE */
+ if (temp == 5) temp++;
+ swiz |= temp << i*3;
+ }
+ if (src.NegateBase)
+ swiz |= (R500_SWIZ_MOD_NEG << 9);
+ return swiz;
+}
+
+static inline GLuint make_rgba_swizzle(GLuint src) {
+ GLuint swiz = 0x0;
+ GLuint temp;
+ int i;
+ for (i = 0; i < 4; i++) {
+ temp = GET_SWZ(src, i);
+ /* Fix SWIZZLE_ONE */
+ if (temp == 5) temp++;
+ swiz |= temp << i*3;
+ }
+ return swiz;
+}
+
+static inline GLuint make_alpha_swizzle(struct prog_src_register src) {
+ GLuint swiz = GET_SWZ(src.Swizzle, 3);
+
+ if (swiz == 5) swiz++;
+
+ if (src.NegateBase)
+ swiz |= (R500_SWIZ_MOD_NEG << 3);
+
+ return swiz;
+}
+
+static inline GLuint make_sop_swizzle(struct prog_src_register src) {
+ GLuint swiz = GET_SWZ(src.Swizzle, 0);
+
+ if (swiz == 5) swiz++;
+ return swiz;
+}
+
+static inline GLuint make_strq_swizzle(struct prog_src_register src) {
+ GLuint swiz = 0x0, temp = 0x0;
+ int i;
+ for (i = 0; i < 4; i++) {
+ temp = GET_SWZ(src.Swizzle, i) & 0x3;
+ swiz |= temp << i*2;
+ }
+ return swiz;
+}
+
+static int get_temp(struct r500_pfs_compile_state *cs, int slot) {
+
+ PROG_CODE;
+
+ int r = code->temp_reg_offset + cs->temp_in_use + slot;
+
+ if (r > R500_US_NUM_TEMP_REGS) {
+ ERROR("Too many temporary registers requested, can't compile!\n");
+ }
+
+ return r;
+}
+
+/* Borrowed verbatim from r300_fragprog since it hasn't changed. */
+static GLuint emit_const4fv(struct r500_pfs_compile_state *cs,
+ const GLfloat * cp)
+{
+ PROG_CODE;
+
+ GLuint reg = 0x0;
+ int index;
+
+ for (index = 0; index < code->const_nr; ++index) {
+ if (code->constant[index] == cp)
+ break;
+ }
+
+ if (index >= code->const_nr) {
+ if (index >= R500_US_NUM_CONST_REGS) {
+ ERROR("Out of hw constants!\n");
+ return reg;
+ }
+
+ code->const_nr++;
+ code->constant[index] = cp;
+ }
+
+ reg = index | REG_CONSTANT;
+ return reg;
+}
+
+static GLuint make_src(struct r500_pfs_compile_state *cs, struct prog_src_register src) {
+ PROG_CODE;
+ GLuint reg;
+ switch (src.File) {
+ case PROGRAM_TEMPORARY:
+ reg = src.Index + code->temp_reg_offset;
+ break;
+ case PROGRAM_INPUT:
+ reg = cs->inputs[src.Index].reg;
+ break;
+ case PROGRAM_LOCAL_PARAM:
+ reg = emit_const4fv(cs,
+ cs->compiler->fp->mesa_program.Base.LocalParams[src.Index]);
+ break;
+ case PROGRAM_ENV_PARAM:
+ reg = emit_const4fv(cs,
+ cs->compiler->compiler.Ctx->FragmentProgram.Parameters[src.Index]);
+ break;
+ case PROGRAM_STATE_VAR:
+ case PROGRAM_NAMED_PARAM:
+ case PROGRAM_CONSTANT:
+ reg = emit_const4fv(cs,
+ cs->compiler->fp->mesa_program.Base.Parameters->ParameterValues[src.Index]);
+ break;
+ case PROGRAM_BUILTIN:
+ reg = 0x0;
+ break;
+ default:
+ ERROR("Can't handle src.File %x\n", src.File);
+ reg = 0x0;
+ break;
+ }
+ return reg;
+}
+
+static GLuint make_dest(struct r500_pfs_compile_state *cs, struct prog_dst_register dest) {
+ PROG_CODE;
+ GLuint reg;
+ switch (dest.File) {
+ case PROGRAM_TEMPORARY:
+ reg = dest.Index + code->temp_reg_offset;
+ break;
+ case PROGRAM_OUTPUT:
+ /* Eventually we may need to handle multiple
+ * rendering targets... */
+ reg = dest.Index;
+ break;
+ case PROGRAM_BUILTIN:
+ reg = 0x0;
+ break;
+ default:
+ ERROR("Can't handle dest.File %x\n", dest.File);
+ reg = 0x0;
+ break;
+ }
+ return reg;
+}
+
+static void emit_tex(struct r500_pfs_compile_state *cs,
+ struct prog_instruction *fpi, int dest, int counter)
+{
+ PROG_CODE;
+ int hwsrc, hwdest;
+ GLuint mask;
+
+ mask = fpi->DstReg.WriteMask << 11;
+ hwsrc = make_src(cs, fpi->SrcReg[0]);
+
+ if (fpi->DstReg.File == PROGRAM_OUTPUT) {
+ hwdest = get_temp(cs, 0);
+ } else {
+ hwdest = dest;
+ }
+
+ code->inst[counter].inst0 = R500_INST_TYPE_TEX | mask
+ | R500_INST_TEX_SEM_WAIT;
+
+ code->inst[counter].inst1 = R500_TEX_ID(fpi->TexSrcUnit)
+ | R500_TEX_SEM_ACQUIRE | R500_TEX_IGNORE_UNCOVERED;
+
+ if (fpi->TexSrcTarget == TEXTURE_RECT_INDEX)
+ code->inst[counter].inst1 |= R500_TEX_UNSCALED;
+
+ switch (fpi->Opcode) {
+ case OPCODE_KIL:
+ code->inst[counter].inst1 |= R500_TEX_INST_TEXKILL;
+ break;
+ case OPCODE_TEX:
+ code->inst[counter].inst1 |= R500_TEX_INST_LD;
+ break;
+ case OPCODE_TXB:
+ code->inst[counter].inst1 |= R500_TEX_INST_LODBIAS;
+ break;
+ case OPCODE_TXP:
+ code->inst[counter].inst1 |= R500_TEX_INST_PROJ;
+ break;
+ default:
+ ERROR("emit_tex can't handle opcode %x\n", fpi->Opcode);
+ }
+
+ code->inst[counter].inst2 = R500_TEX_SRC_ADDR(hwsrc)
+ | MAKE_SWIZ_TEX_STRQ(make_strq_swizzle(fpi->SrcReg[0]))
+ /* | R500_TEX_SRC_S_SWIZ_R | R500_TEX_SRC_T_SWIZ_G
+ | R500_TEX_SRC_R_SWIZ_B | R500_TEX_SRC_Q_SWIZ_A */
+ | R500_TEX_DST_ADDR(hwdest)
+ | R500_TEX_DST_R_SWIZ_R | R500_TEX_DST_G_SWIZ_G
+ | R500_TEX_DST_B_SWIZ_B | R500_TEX_DST_A_SWIZ_A;
+
+ code->inst[counter].inst3 = 0x0;
+ code->inst[counter].inst4 = 0x0;
+ code->inst[counter].inst5 = 0x0;
+
+ if (fpi->DstReg.File == PROGRAM_OUTPUT) {
+ counter++;
+ code->inst[counter].inst0 = R500_INST_TYPE_OUT
+ | R500_INST_TEX_SEM_WAIT | (mask << 4);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGB_SEL_B_SRC0
+ | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGB_OMOD_DISABLE;
+ code->inst[counter].inst4 = R500_ALPHA_OP_CMP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_ALPHA_SWIZ_A_A)
+ | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(R500_ALPHA_SWIZ_A_A)
+ | R500_ALPHA_OMOD_DISABLE;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
+ | R500_ALU_RGBA_ADDRD(dest)
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ }
+}
+
+static void emit_alu(struct r500_pfs_compile_state *cs, int counter, struct prog_instruction *fpi) {
+ PROG_CODE;
+ /* Ideally, we shouldn't have to explicitly clear memory here! */
+ code->inst[counter].inst0 = 0x0;
+ code->inst[counter].inst1 = 0x0;
+ code->inst[counter].inst2 = 0x0;
+ code->inst[counter].inst3 = 0x0;
+ code->inst[counter].inst4 = 0x0;
+ code->inst[counter].inst5 = 0x0;
+
+ if (fpi->DstReg.File == PROGRAM_OUTPUT) {
+ code->inst[counter].inst0 = R500_INST_TYPE_OUT;
+
+ if (fpi->DstReg.Index == FRAG_RESULT_COLR)
+ code->inst[counter].inst0 |= (fpi->DstReg.WriteMask << 15);
+
+ if (fpi->DstReg.Index == FRAG_RESULT_DEPR) {
+ code->inst[counter].inst4 |= R500_ALPHA_W_OMASK;
+ /* Notify the state emission! */
+ cs->compiler->fp->writes_depth = GL_TRUE;
+ }
+ } else {
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU
+ /* pixel_mask */
+ | (fpi->DstReg.WriteMask << 11);
+ }
+
+ code->inst[counter].inst0 |= R500_INST_TEX_SEM_WAIT;
+}
+
+static void emit_mov(struct r500_pfs_compile_state *cs, int counter, struct prog_instruction *fpi, GLuint src_reg, GLuint swizzle, GLuint dest) {
+ PROG_CODE;
+ /* The r3xx shader uses MAD to implement MOV. We are using CMP, since
+ * it is technically more accurate and recommended by ATI/AMD. */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src_reg);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src_reg);
+ /* (De)mangle the swizzle from Mesa to R500. */
+ swizzle = make_rgba_swizzle(swizzle);
+ /* 0x1FF is 9 bits, size of an RGB swizzle. */
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A((swizzle & 0x1ff))
+ | R500_ALU_RGB_SEL_B_SRC0
+ | MAKE_SWIZ_RGB_B((swizzle & 0x1ff))
+ | R500_ALU_RGB_OMOD_DISABLE;
+ code->inst[counter].inst4 |= R500_ALPHA_OP_CMP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(GET_SWZ(swizzle, 3))
+ | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(GET_SWZ(swizzle, 3))
+ | R500_ALPHA_OMOD_DISABLE;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
+ | R500_ALU_RGBA_ADDRD(dest)
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+}
+
+static void emit_mad(struct r500_pfs_compile_state *cs, int counter, struct prog_instruction *fpi, int one, int two, int three) {
+ PROG_CODE;
+ /* Note: This code was all Corbin's. Corbin is a rather hackish coder.
+ * If you can make it pretty or fast, please do so! */
+ emit_alu(cs, counter, fpi);
+ /* Common MAD stuff */
+ code->inst[counter].inst4 |= R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(make_dest(cs, fpi->DstReg));
+ code->inst[counter].inst5 |= R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(make_dest(cs, fpi->DstReg));
+ switch (one) {
+ case 0:
+ case 1:
+ case 2:
+ code->inst[counter].inst1 |= R500_RGB_ADDR0(make_src(cs, fpi->SrcReg[one]));
+ code->inst[counter].inst2 |= R500_ALPHA_ADDR0(make_src(cs, fpi->SrcReg[one]));
+ code->inst[counter].inst3 |= R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[one]));
+ code->inst[counter].inst4 |= R500_ALPHA_SEL_A_SRC0
+ | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[one]));
+ break;
+ case R500_SWIZZLE_ZERO:
+ code->inst[counter].inst3 |= MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ZERO);
+ code->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ZERO);
+ break;
+ case R500_SWIZZLE_ONE:
+ code->inst[counter].inst3 |= MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE);
+ code->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE);
+ break;
+ default:
+ ERROR("Bad src index in emit_mad: %d\n", one);
+ break;
+ }
+ switch (two) {
+ case 0:
+ case 1:
+ case 2:
+ code->inst[counter].inst1 |= R500_RGB_ADDR1(make_src(cs, fpi->SrcReg[two]));
+ code->inst[counter].inst2 |= R500_ALPHA_ADDR1(make_src(cs, fpi->SrcReg[two]));
+ code->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
+ | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[two]));
+ code->inst[counter].inst4 |= R500_ALPHA_SEL_B_SRC1
+ | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[two]));
+ break;
+ case R500_SWIZZLE_ZERO:
+ code->inst[counter].inst3 |= MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ZERO);
+ code->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ZERO);
+ break;
+ case R500_SWIZZLE_ONE:
+ code->inst[counter].inst3 |= MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
+ code->inst[counter].inst4 |= MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ONE);
+ break;
+ default:
+ ERROR("Bad src index in emit_mad: %d\n", two);
+ break;
+ }
+ switch (three) {
+ case 0:
+ case 1:
+ case 2:
+ code->inst[counter].inst1 |= R500_RGB_ADDR2(make_src(cs, fpi->SrcReg[three]));
+ code->inst[counter].inst2 |= R500_ALPHA_ADDR2(make_src(cs, fpi->SrcReg[three]));
+ code->inst[counter].inst5 |= R500_ALU_RGBA_SEL_C_SRC2
+ | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[three]))
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
+ | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[three]));
+ break;
+ case R500_SWIZZLE_ZERO:
+ code->inst[counter].inst5 |= MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ break;
+ case R500_SWIZZLE_ONE:
+ code->inst[counter].inst5 |= MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ONE)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ONE);
+ break;
+ default:
+ ERROR("Bad src index in emit_mad: %d\n", three);
+ break;
+ }
+}
+
+static void emit_sop(struct r500_pfs_compile_state *cs, int counter, struct prog_instruction *fpi, int opcode, GLuint src, GLuint swiz, GLuint dest) {
+ PROG_CODE;
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src);
+ code->inst[counter].inst4 |= R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(swiz);
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_SOP
+ | R500_ALU_RGBA_ADDRD(dest);
+ switch (opcode) {
+ case OPCODE_COS:
+ code->inst[counter].inst4 |= R500_ALPHA_OP_COS;
+ break;
+ case OPCODE_EX2:
+ code->inst[counter].inst4 |= R500_ALPHA_OP_EX2;
+ break;
+ case OPCODE_LG2:
+ code->inst[counter].inst4 |= R500_ALPHA_OP_LN2;
+ break;
+ case OPCODE_RCP:
+ code->inst[counter].inst4 |= R500_ALPHA_OP_RCP;
+ break;
+ case OPCODE_RSQ:
+ code->inst[counter].inst4 |= R500_ALPHA_OP_RSQ;
+ break;
+ case OPCODE_SIN:
+ code->inst[counter].inst4 |= R500_ALPHA_OP_SIN;
+ break;
+ default:
+ ERROR("Bad opcode in emit_sop: %d\n", opcode);
+ break;
+ }
+}
+
+static int do_inst(struct r500_pfs_compile_state *cs, struct prog_instruction *fpi, int counter) {
+ PROG_CODE;
+ GLuint src[3], dest = 0;
+ int temp_swiz = 0;
+
+ if (fpi->Opcode != OPCODE_KIL) {
+ dest = make_dest(cs, fpi->DstReg);
+ }
+
+ switch (fpi->Opcode) {
+ case OPCODE_ABS:
+ emit_mov(cs, counter, fpi, make_src(cs, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
+ code->inst[counter].inst3 |= R500_ALU_RGB_MOD_A_ABS
+ | R500_ALU_RGB_MOD_B_ABS;
+ code->inst[counter].inst4 |= R500_ALPHA_MOD_A_ABS
+ | R500_ALPHA_MOD_B_ABS;
+ break;
+ case OPCODE_ADD:
+ /* Variation on MAD: 1*src0+src1 */
+ emit_mad(cs, counter, fpi, R500_SWIZZLE_ONE, 0, 1);
+ break;
+ case OPCODE_CMP:
+ /* This inst's selects need to be swapped as follows:
+ * 0 -> C ; 1 -> B ; 2 -> A */
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ src[2] = make_src(cs, fpi->SrcReg[2]);
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[2])
+ | R500_RGB_ADDR1(src[1]) | R500_RGB_ADDR2(src[0]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[2])
+ | R500_ALPHA_ADDR1(src[1]) | R500_ALPHA_ADDR2(src[0]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[2]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_CMP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[2]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC2
+ | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
+ | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[0]));
+ break;
+ case OPCODE_COS:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = emit_const4fv(cs, RCP_2PI);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_FRC
+ | R500_ALPHA_ADDRD(get_temp(cs, 1))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 1));
+ counter++;
+ emit_sop(cs, counter, fpi, OPCODE_COS, get_temp(cs, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_DP3:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_DP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_DP3
+ | R500_ALU_RGBA_ADDRD(dest);
+ break;
+ case OPCODE_DP4:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ /* Based on DP3 */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_DP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_DP4
+ | R500_ALU_RGBA_ADDRD(dest);
+ break;
+ case OPCODE_DPH:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ /* Based on DP3 */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_DP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_DP4
+ | R500_ALU_RGBA_ADDRD(dest);
+ break;
+ case OPCODE_DST:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ /* [1, src0.y*src1.y, src0.z, src1.w]
+ * So basically MUL with lotsa swizzling. */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | R500_ALU_RGB_SEL_B_SRC1;
+ /* Select [1, y, z, 1] */
+ temp_swiz = (make_rgb_swizzle(fpi->SrcReg[0]) & ~0x7) | R500_SWIZZLE_ONE;
+ code->inst[counter].inst3 |= MAKE_SWIZ_RGB_A(temp_swiz);
+ /* Select [1, y, 1, w] */
+ temp_swiz = (make_rgb_swizzle(fpi->SrcReg[0]) & ~0x1c7) | R500_SWIZZLE_ONE | (R500_SWIZZLE_ONE << 6);
+ code->inst[counter].inst3 |= MAKE_SWIZ_RGB_B(temp_swiz);
+ code->inst[counter].inst4 |= R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(dest)
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ break;
+ case OPCODE_EX2:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ emit_sop(cs, counter, fpi, OPCODE_EX2, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_FLR:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_FRC
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0));
+ counter++;
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(get_temp(cs, 0));
+ code->inst[counter].inst3 = MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
+ | R500_ALU_RGB_SEL_B_SRC0 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SWIZ_A_A
+ | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC1
+ | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC1
+ | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGBA_MOD_C_NEG;
+ break;
+ case OPCODE_FRC:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_FRC
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
+ | R500_ALU_RGBA_ADDRD(dest);
+ break;
+ case OPCODE_LG2:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ emit_sop(cs, counter, fpi, OPCODE_LG2, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_LIT:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = emit_const4fv(cs, LIT);
+ /* First inst: MAX temp, input, [0, 0, 0, -128]
+ * Write: RG, A */
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_ARG << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0]) | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]) | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ZERO);
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAX
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAX
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0));
+ counter++;
+ /* Second inst: MIN temp, temp, [x, x, x, 128]
+ * Write: A */
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_A << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0)) | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0)) | R500_ALPHA_ADDR1(src[1]);
+ /* code->inst[counter].inst3; */
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAX
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAX
+ | R500_ALU_RGBA_ADDRD(dest);
+ counter++;
+ /* Third-fifth insts: POW temp, temp.y, temp.w
+ * Write: B */
+ emit_sop(cs, counter, fpi, OPCODE_LG2, get_temp(cs, 0), SWIZZLE_Y, get_temp(cs, 1));
+ code->inst[counter].inst0 |= (R500_WRITEMASK_ARGB << 11);
+ counter++;
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 1))
+ | R500_RGB_ADDR1(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 1))
+ | R500_ALPHA_ADDR1(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 1))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 1))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ emit_sop(cs, counter, fpi, OPCODE_EX2, get_temp(cs, 1), SWIZZLE_W, get_temp(cs, 0));
+ code->inst[counter].inst0 |= (R500_WRITEMASK_B << 11);
+ counter++;
+ /* Sixth inst: CMP dest, temp.xxxx, temp.[1, x, z, 1], temp.[1, x, 0, 1];
+ * Write: ARGB
+ * This inst's selects need to be swapped as follows:
+ * 0 -> C ; 1 -> B ; 2 -> A */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | R500_ALU_RGB_R_SWIZ_A_1
+ | R500_ALU_RGB_G_SWIZ_A_R
+ | R500_ALU_RGB_B_SWIZ_A_B
+ | R500_ALU_RGB_SEL_B_SRC0
+ | R500_ALU_RGB_R_SWIZ_B_1
+ | R500_ALU_RGB_G_SWIZ_B_R
+ | R500_ALU_RGB_B_SWIZ_B_0;
+ code->inst[counter].inst4 |= R500_ALPHA_OP_CMP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_1
+ | R500_ALPHA_SEL_B_SRC0 | R500_ALPHA_SWIZ_B_1;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC0
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC0
+ | R500_ALU_RGBA_R_SWIZ_R
+ | R500_ALU_RGBA_G_SWIZ_R
+ | R500_ALU_RGBA_B_SWIZ_R
+ | R500_ALU_RGBA_A_SWIZ_R;
+ break;
+ case OPCODE_LRP:
+ /* src0 * src1 + INV(src0) * src2
+ * 1) MUL src0, src1, temp
+ * 2) PRE 1-src0; MAD srcp, src2, temp */
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ src[2] = make_src(cs, fpi->SrcReg[2]);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | R500_INST_NOP | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[2])
+ | R500_RGB_ADDR2(get_temp(cs, 0))
+ | R500_RGB_SRCP_OP_1_MINUS_RGB0;
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[2])
+ | R500_ALPHA_ADDR2(get_temp(cs, 0))
+ | R500_ALPHA_SRCP_OP_1_MINUS_A0;
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRCP
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 |= R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRCP | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC2 | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[2]))
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
+ | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[2]));
+ break;
+ case OPCODE_MAD:
+ emit_mad(cs, counter, fpi, 0, 1, 2);
+ break;
+ case OPCODE_MAX:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0]) | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]) | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1
+ | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_MAX
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAX
+ | R500_ALU_RGBA_ADDRD(dest);
+ break;
+ case OPCODE_MIN:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0]) | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0]) | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1
+ | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 |= R500_ALPHA_OP_MIN
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MIN
+ | R500_ALU_RGBA_ADDRD(dest);
+ break;
+ case OPCODE_MOV:
+ emit_mov(cs, counter, fpi, make_src(cs, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
+ break;
+ case OPCODE_MUL:
+ /* Variation on MAD: src0*src1+0 */
+ emit_mad(cs, counter, fpi, 0, 1, R500_SWIZZLE_ZERO);
+ break;
+ case OPCODE_POW:
+ /* POW(a,b) = EX2(LN2(a)*b) */
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ emit_sop(cs, counter, fpi, OPCODE_LG2, src[0], make_sop_swizzle(fpi->SrcReg[0]), get_temp(cs, 0));
+ code->inst[counter].inst0 |= (R500_WRITEMASK_ARGB << 11);
+ counter++;
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0))
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0))
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(make_rgb_swizzle(fpi->SrcReg[0]))
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 1))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 1))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ emit_sop(cs, counter, fpi, OPCODE_EX2, get_temp(cs, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_RCP:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ emit_sop(cs, counter, fpi, OPCODE_RCP, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_RSQ:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ emit_sop(cs, counter, fpi, OPCODE_RSQ, src[0], make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_SCS:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = emit_const4fv(cs, RCP_2PI);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_FRC
+ | R500_ALPHA_ADDRD(get_temp(cs, 1))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 1));
+ counter++;
+ /* Do a cosine, then a sine, masking out the channels we want to protect. */
+ /* Cosine only goes in R (x) channel. */
+ fpi->DstReg.WriteMask = 0x1;
+ emit_sop(cs, counter, fpi, OPCODE_COS, get_temp(cs, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
+ counter++;
+ /* Sine only goes in G (y) channel. */
+ fpi->DstReg.WriteMask = 0x2;
+ emit_sop(cs, counter, fpi, OPCODE_SIN, get_temp(cs, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_SGE:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR1(src[0])
+ | R500_RGB_ADDR2(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR1(src[0])
+ | R500_ALPHA_ADDR2(src[1]);
+ code->inst[counter].inst3 = /* 1 */
+ MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | R500_ALU_RGBA_SEL_C_SRC2
+ | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[1]))
+ | R500_ALU_RGBA_MOD_C_NEG
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
+ | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[1]))
+ | R500_ALU_RGBA_ALPHA_MOD_C_NEG;
+ counter++;
+ /* This inst's selects need to be swapped as follows:
+ * 0 -> C ; 1 -> B ; 2 -> A */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
+ | R500_ALU_RGB_SEL_B_SRC0
+ | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ZERO);
+ code->inst[counter].inst4 |= R500_ALPHA_OP_CMP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
+ | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ZERO);
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC0
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC0
+ | R500_ALU_RGBA_A_SWIZ_A;
+ break;
+ case OPCODE_SIN:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = emit_const4fv(cs, RCP_2PI);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
+ | R500_ALPHA_SEL_B_SRC1 | R500_ALPHA_SWIZ_B_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_RGB);
+ code->inst[counter].inst4 = R500_ALPHA_OP_FRC
+ | R500_ALPHA_ADDRD(get_temp(cs, 1))
+ | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_FRC
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 1));
+ counter++;
+ emit_sop(cs, counter, fpi, OPCODE_SIN, get_temp(cs, 1), make_sop_swizzle(fpi->SrcReg[0]), dest);
+ break;
+ case OPCODE_SLT:
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_ARGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR1(src[0])
+ | R500_RGB_ADDR2(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR1(src[0])
+ | R500_ALPHA_ADDR2(src[1]);
+ code->inst[counter].inst3 = /* 1 */
+ MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ONE)
+ | R500_ALU_RGB_SEL_B_SRC1 | MAKE_SWIZ_RGB_B(make_rgb_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ONE)
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[0]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | R500_ALU_RGBA_SEL_C_SRC2
+ | MAKE_SWIZ_RGBA_C(make_rgb_swizzle(fpi->SrcReg[1]))
+ | R500_ALU_RGBA_MOD_C_NEG
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC2
+ | MAKE_SWIZ_ALPHA_C(make_alpha_swizzle(fpi->SrcReg[1]))
+ | R500_ALU_RGBA_ALPHA_MOD_C_NEG;
+ counter++;
+ /* This inst's selects need to be swapped as follows:
+ * 0 -> C ; 1 -> B ; 2 -> A */
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(cs, 0));
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(R500_SWIZ_RGB_ZERO)
+ | R500_ALU_RGB_SEL_B_SRC0
+ | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
+ code->inst[counter].inst4 |= R500_ALPHA_OP_CMP
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(R500_SWIZZLE_ZERO)
+ | R500_ALPHA_SEL_B_SRC0 | MAKE_SWIZ_ALPHA_B(R500_SWIZZLE_ONE);
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_CMP
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC0
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGBA_ALPHA_SEL_C_SRC0
+ | R500_ALU_RGBA_A_SWIZ_A;
+ break;
+ case OPCODE_SUB:
+ /* Variation on MAD: 1*src0-src1 */
+ fpi->SrcReg[1].NegateBase = 0xF; /* NEG_XYZW */
+ emit_mad(cs, counter, fpi, R500_SWIZZLE_ONE, 0, 1);
+ break;
+ case OPCODE_SWZ:
+ /* TODO: The rarer negation masks! */
+ emit_mov(cs, counter, fpi, make_src(cs, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
+ break;
+ case OPCODE_XPD:
+ /* src0 * src1 - src1 * src0
+ * 1) MUL temp.xyz, src0.yzx, src1.zxy
+ * 2) MAD src0.zxy, src1.yzx, -temp.xyz */
+ src[0] = make_src(cs, fpi->SrcReg[0]);
+ src[1] = make_src(cs, fpi->SrcReg[1]);
+ code->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+ | (R500_WRITEMASK_RGB << 11);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1]);
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1]);
+ /* Select [y, z, x] */
+ temp_swiz = make_rgb_swizzle(fpi->SrcReg[0]);
+ temp_swiz = (GET_SWZ(temp_swiz, 1) << 0) | (GET_SWZ(temp_swiz, 2) << 3) | (GET_SWZ(temp_swiz, 0) << 6);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(temp_swiz);
+ /* Select [z, x, y] */
+ temp_swiz = make_rgb_swizzle(fpi->SrcReg[1]);
+ temp_swiz = (GET_SWZ(temp_swiz, 2) << 0) | (GET_SWZ(temp_swiz, 0) << 3) | (GET_SWZ(temp_swiz, 1) << 6);
+ code->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
+ | MAKE_SWIZ_RGB_B(temp_swiz);
+ code->inst[counter].inst4 = R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(get_temp(cs, 0))
+ | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+ | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(get_temp(cs, 0))
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+ | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+ counter++;
+ emit_alu(cs, counter, fpi);
+ code->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+ | R500_RGB_ADDR1(src[1])
+ | R500_RGB_ADDR2(get_temp(cs, 0));
+ code->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+ | R500_ALPHA_ADDR1(src[1])
+ | R500_ALPHA_ADDR2(get_temp(cs, 0));
+ /* Select [z, x, y] */
+ temp_swiz = make_rgb_swizzle(fpi->SrcReg[0]);
+ temp_swiz = (GET_SWZ(temp_swiz, 2) << 0) | (GET_SWZ(temp_swiz, 0) << 3) | (GET_SWZ(temp_swiz, 1) << 6);
+ code->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+ | MAKE_SWIZ_RGB_A(temp_swiz);
+ /* Select [y, z, x] */
+ temp_swiz = make_rgb_swizzle(fpi->SrcReg[1]);
+ temp_swiz = (GET_SWZ(temp_swiz, 1) << 0) | (GET_SWZ(temp_swiz, 2) << 3) | (GET_SWZ(temp_swiz, 0) << 6);
+ code->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
+ | MAKE_SWIZ_RGB_B(temp_swiz);
+ code->inst[counter].inst4 |= R500_ALPHA_OP_MAD
+ | R500_ALPHA_ADDRD(dest)
+ | R500_ALPHA_SWIZ_A_1
+ | R500_ALPHA_SWIZ_B_1;
+ code->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+ | R500_ALU_RGBA_ADDRD(dest)
+ | R500_ALU_RGBA_SEL_C_SRC2
+ | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
+ | R500_ALU_RGBA_MOD_C_NEG
+ | R500_ALU_RGBA_A_SWIZ_0;
+ break;
+ case OPCODE_KIL:
+ case OPCODE_TEX:
+ case OPCODE_TXB:
+ case OPCODE_TXP:
+ emit_tex(cs, fpi, dest, counter);
+ if (fpi->DstReg.File == PROGRAM_OUTPUT)
+ counter++;
+ break;
+ default:
+ ERROR("unknown fpi->Opcode %s\n", _mesa_opcode_string(fpi->Opcode));
+ break;
+ }
+
+ /* Finishing touches */
+ if (fpi->SaturateMode == SATURATE_ZERO_ONE) {
+ code->inst[counter].inst0 |= R500_INST_RGB_CLAMP | R500_INST_ALPHA_CLAMP;
+ }
+
+ counter++;
+
+ return counter;
+}
+
+static GLboolean parse_program(struct r500_pfs_compile_state *cs)
+{
+ PROG_CODE;
+ int clauseidx, counter = 0;
+
+ for (clauseidx = 0; clauseidx < cs->compiler->compiler.NumClauses; clauseidx++) {
+ struct radeon_clause* clause = &cs->compiler->compiler.Clauses[clauseidx];
+ struct prog_instruction* fpi;
+
+ int ip;
+
+ for (ip = 0; ip < clause->NumInstructions; ip++) {
+ fpi = clause->Instructions + ip;
+ counter = do_inst(cs, fpi, counter);
+
+ if (cs->compiler->fp->error)
+ return GL_FALSE;
+ }
+ }
+
+ /* Finish him! (If it's an ALU/OUT instruction...) */
+ if ((code->inst[counter-1].inst0 & 0x3) == 1) {
+ code->inst[counter-1].inst0 |= R500_INST_LAST;
+ } else {
+ /* We still need to put an output inst, right? */
+ WARN_ONCE("Final FP instruction is not an OUT.\n");
+ }
+
+ cs->nrslots = counter;
+
+ code->max_temp_idx++;
+
+ return GL_TRUE;
+}
+
+static void init_program(struct r500_pfs_compile_state *cs)
+{
+ PROG_CODE;
+ struct gl_fragment_program *mp = &cs->compiler->fp->mesa_program;
+ struct prog_instruction *fpi;
+ GLuint InputsRead = mp->Base.InputsRead;
+ GLuint temps_used = 0;
+ int i, j;
+
+ /* New compile, reset tracking data */
+ cs->compiler->fp->optimization =
+ driQueryOptioni(&cs->compiler->r300->radeon.optionCache, "fp_optimization");
+ cs->compiler->fp->translated = GL_FALSE;
+ cs->compiler->fp->error = GL_FALSE;
+ code->const_nr = 0;
+ /* Size of pixel stack, plus 1. */
+ code->max_temp_idx = 1;
+ /* Temp register offset. */
+ code->temp_reg_offset = 0;
+ /* Whether or not we perform any depth writing. */
+ cs->compiler->fp->writes_depth = GL_FALSE;
+
+ for (i = 0; i < PFS_MAX_ALU_INST; i++) {
+ for (j = 0; j < 3; j++) {
+ cs->slot[i].vsrc[j] = SRC_CONST;
+ cs->slot[i].ssrc[j] = SRC_CONST;
+ }
+ }
+
+ /* Work out what temps the Mesa inputs correspond to, this must match
+ * what setup_rs_unit does, which shouldn't be a problem as rs_unit
+ * configures itself based on the fragprog's InputsRead
+ *
+ * NOTE: this depends on get_hw_temp() allocating registers in order,
+ * starting from register 0, so we're just going to do that instead.
+ */
+
+ /* Texcoords come first */
+ for (i = 0; i < cs->compiler->fp->ctx->Const.MaxTextureUnits; i++) {
+ if (InputsRead & (FRAG_BIT_TEX0 << i)) {
+ cs->inputs[FRAG_ATTRIB_TEX0 + i].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_TEX0 + i].reg =
+ code->temp_reg_offset;
+ code->temp_reg_offset++;
+ }
+ }
+ InputsRead &= ~FRAG_BITS_TEX_ANY;
+
+ /* fragment position treated as a texcoord */
+ if (InputsRead & FRAG_BIT_WPOS) {
+ cs->inputs[FRAG_ATTRIB_WPOS].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_WPOS].reg =
+ code->temp_reg_offset;
+ code->temp_reg_offset++;
+ }
+ InputsRead &= ~FRAG_BIT_WPOS;
+
+ /* Then primary colour */
+ if (InputsRead & FRAG_BIT_COL0) {
+ cs->inputs[FRAG_ATTRIB_COL0].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_COL0].reg =
+ code->temp_reg_offset;
+ code->temp_reg_offset++;
+ }
+ InputsRead &= ~FRAG_BIT_COL0;
+
+ /* Secondary color */
+ if (InputsRead & FRAG_BIT_COL1) {
+ cs->inputs[FRAG_ATTRIB_COL1].refcount = 0;
+ cs->inputs[FRAG_ATTRIB_COL1].reg =
+ code->temp_reg_offset;
+ code->temp_reg_offset++;
+ }
+ InputsRead &= ~FRAG_BIT_COL1;
+
+ /* Anything else */
+ if (InputsRead) {
+ WARN_ONCE("Don't know how to handle inputs 0x%x\n", InputsRead);
+ /* force read from hwreg 0 for now */
+ for (i = 0; i < 32; i++)
+ if (InputsRead & (1 << i))
+ cs->inputs[i].reg = 0;
+ }
+
+ int clauseidx;
+
+ for (clauseidx = 0; clauseidx < cs->compiler->compiler.NumClauses; ++clauseidx) {
+ struct radeon_clause* clause = &cs->compiler->compiler.Clauses[clauseidx];
+ int ip;
+
+ for (ip = 0; ip < clause->NumInstructions; ip++) {
+ fpi = clause->Instructions + ip;
+ for (i = 0; i < 3; i++) {
+ if (fpi->SrcReg[i].File == PROGRAM_TEMPORARY) {
+ if (fpi->SrcReg[i].Index >= temps_used)
+ temps_used = fpi->SrcReg[i].Index + 1;
+ }
+ }
+ }
+ }
+
+
+ cs->temp_in_use = temps_used + 1;
+
+ code->max_temp_idx = code->temp_reg_offset + cs->temp_in_use;
+
+ if (RADEON_DEBUG & DEBUG_PIXEL)
+ fprintf(stderr, "FP temp indices: code->max_temp_idx: %d cs->temp_in_use: %d\n", code->max_temp_idx, cs->temp_in_use);
+}
+
+static void dumb_shader(struct r500_pfs_compile_state *cs)
+{
+ PROG_CODE;
+ code->inst[0].inst0 = R500_INST_TYPE_TEX
+ | R500_INST_TEX_SEM_WAIT
+ | R500_INST_RGB_WMASK_R
+ | R500_INST_RGB_WMASK_G
+ | R500_INST_RGB_WMASK_B
+ | R500_INST_ALPHA_WMASK
+ | R500_INST_RGB_CLAMP
+ | R500_INST_ALPHA_CLAMP;
+ code->inst[0].inst1 = R500_TEX_ID(0)
+ | R500_TEX_INST_LD
+ | R500_TEX_SEM_ACQUIRE
+ | R500_TEX_IGNORE_UNCOVERED;
+ code->inst[0].inst2 = R500_TEX_SRC_ADDR(0)
+ | R500_TEX_SRC_S_SWIZ_R
+ | R500_TEX_SRC_T_SWIZ_G
+ | R500_TEX_DST_ADDR(0)
+ | R500_TEX_DST_R_SWIZ_R
+ | R500_TEX_DST_G_SWIZ_G
+ | R500_TEX_DST_B_SWIZ_B
+ | R500_TEX_DST_A_SWIZ_A;
+ code->inst[0].inst3 = R500_DX_ADDR(0)
+ | R500_DX_S_SWIZ_R
+ | R500_DX_T_SWIZ_R
+ | R500_DX_R_SWIZ_R
+ | R500_DX_Q_SWIZ_R
+ | R500_DY_ADDR(0)
+ | R500_DY_S_SWIZ_R
+ | R500_DY_T_SWIZ_R
+ | R500_DY_R_SWIZ_R
+ | R500_DY_Q_SWIZ_R;
+ code->inst[0].inst4 = 0x0;
+ code->inst[0].inst5 = 0x0;
+
+ code->inst[1].inst0 = R500_INST_TYPE_OUT |
+ R500_INST_TEX_SEM_WAIT |
+ R500_INST_LAST |
+ R500_INST_RGB_OMASK_R |
+ R500_INST_RGB_OMASK_G |
+ R500_INST_RGB_OMASK_B |
+ R500_INST_ALPHA_OMASK;
+ code->inst[1].inst1 = R500_RGB_ADDR0(0) |
+ R500_RGB_ADDR1(0) |
+ R500_RGB_ADDR1_CONST |
+ R500_RGB_ADDR2(0) |
+ R500_RGB_ADDR2_CONST |
+ R500_RGB_SRCP_OP_1_MINUS_2RGB0;
+ code->inst[1].inst2 = R500_ALPHA_ADDR0(0) |
+ R500_ALPHA_ADDR1(0) |
+ R500_ALPHA_ADDR1_CONST |
+ R500_ALPHA_ADDR2(0) |
+ R500_ALPHA_ADDR2_CONST |
+ R500_ALPHA_SRCP_OP_1_MINUS_2A0;
+ code->inst[1].inst3 = R500_ALU_RGB_SEL_A_SRC0 |
+ R500_ALU_RGB_R_SWIZ_A_R |
+ R500_ALU_RGB_G_SWIZ_A_G |
+ R500_ALU_RGB_B_SWIZ_A_B |
+ R500_ALU_RGB_SEL_B_SRC0 |
+ R500_ALU_RGB_R_SWIZ_B_1 |
+ R500_ALU_RGB_B_SWIZ_B_1 |
+ R500_ALU_RGB_G_SWIZ_B_1;
+ code->inst[1].inst4 = R500_ALPHA_OP_MAD |
+ R500_ALPHA_SWIZ_A_A |
+ R500_ALPHA_SWIZ_B_1;
+ code->inst[1].inst5 = R500_ALU_RGBA_OP_MAD |
+ R500_ALU_RGBA_R_SWIZ_0 |
+ R500_ALU_RGBA_G_SWIZ_0 |
+ R500_ALU_RGBA_B_SWIZ_0 |
+ R500_ALU_RGBA_A_SWIZ_0;
+
+ cs->nrslots = 2;
+}
+
+GLboolean r500FragmentProgramEmit(struct r500_fragment_program_compiler *compiler)
+{
+ struct r500_pfs_compile_state cs;
+ struct r500_fragment_program_code *code = compiler->code;
+
+ _mesa_memset(&cs, 0, sizeof(cs));
+ cs.compiler = compiler;
+ init_program(&cs);
+
+ if (!parse_program(&cs)) {
+#if 0
+ ERROR("Huh. Couldn't parse program. There should be additional errors explaining why.\nUsing dumb shader...\n");
+ dumb_shader(fp);
+ code->inst_offset = 0;
+ code->inst_end = cs.nrslots - 1;
+#endif
+ return GL_FALSE;
+ }
+
+ code->inst_offset = 0;
+ code->inst_end = cs.nrslots - 1;
+
+ return GL_TRUE;
+}
diff --git a/src/mesa/drivers/dri/r300/radeon_context.h b/src/mesa/drivers/dri/r300/radeon_context.h
index 38d8930601..7458d63723 100644
--- a/src/mesa/drivers/dri/r300/radeon_context.h
+++ b/src/mesa/drivers/dri/r300/radeon_context.h
@@ -53,16 +53,6 @@ struct radeon_context;
typedef struct radeon_context radeonContextRec;
typedef struct radeon_context *radeonContextPtr;
-#define TEX_0 0x1
-#define TEX_1 0x2
-#define TEX_2 0x4
-#define TEX_3 0x8
-#define TEX_4 0x10
-#define TEX_5 0x20
-#define TEX_6 0x40
-#define TEX_7 0x80
-#define TEX_ALL 0xff
-
/* Rasterizing fallbacks */
/* See correponding strings in r200_swtcl.c */
#define RADEON_FALLBACK_TEXTURE 0x0001
diff --git a/src/mesa/drivers/dri/r300/radeon_program.c b/src/mesa/drivers/dri/r300/radeon_program.c
new file mode 100644
index 0000000000..c8f40e8189
--- /dev/null
+++ b/src/mesa/drivers/dri/r300/radeon_program.c
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2008 Nicolai Haehnle.
+ *
+ * All Rights Reserved.
+ *
+ * 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 (including the
+ * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+ *
+ */
+
+#include "radeon_program.h"
+
+#include "shader/prog_print.h"
+
+/**
+ * Initialize a compiler structure with a single mixed clause
+ * containing all instructions from the source program.
+ */
+void radeonCompilerInit(
+ struct radeon_compiler *compiler,
+ GLcontext *ctx,
+ struct gl_program *source)
+{
+ struct radeon_clause* clause;
+
+ _mesa_memset(compiler, 0, sizeof(*compiler));
+ compiler->Source = source;
+ compiler->Ctx = ctx;
+
+ compiler->NumTemporaries = source->NumTemporaries;
+
+ clause = radeonCompilerInsertClause(compiler, 0, CLAUSE_MIXED);
+ clause->NumInstructions = 0;
+ while(source->Instructions[clause->NumInstructions].Opcode != OPCODE_END)
+ clause->NumInstructions++;
+ clause->ReservedInstructions = clause->NumInstructions;
+ clause->Instructions = _mesa_alloc_instructions(clause->NumInstructions);
+ _mesa_copy_instructions(clause->Instructions, source->Instructions, clause->NumInstructions);
+}
+
+
+/**
+ * Free all data that is referenced by the compiler structure.
+ * However, the compiler structure itself is not freed.
+ */
+void radeonCompilerCleanup(struct radeon_compiler *compiler)
+{
+ radeonCompilerEraseClauses(compiler, 0, compiler->NumClauses);
+}
+
+
+/**
+ * Allocate and return a unique temporary register.
+ */
+int radeonCompilerAllocateTemporary(struct radeon_compiler *compiler)
+{
+ if (compiler->NumTemporaries >= 256) {
+ _mesa_problem(compiler->Ctx, "radeonCompiler: Too many temporaries");
+ return 0;
+ }
+
+ return compiler->NumTemporaries++;
+}
+
+
+static const char* clausename(int type)
+{
+ switch(type) {
+ case CLAUSE_MIXED: return "CLAUSE_MIXED";
+ case CLAUSE_ALU: return "CLAUSE_ALU";
+ case CLAUSE_TEX: return "CLAUSE_TEX";
+ default: return "CLAUSE_UNKNOWN";
+ }
+}
+
+
+/**
+ * Dump the current compiler state to the console for debugging.
+ */
+void radeonCompilerDump(struct radeon_compiler *compiler)
+{
+ int i;
+ for(i = 0; i < compiler->NumClauses; ++i) {
+ struct radeon_clause *clause = &compiler->Clauses[i];
+ int j;
+
+ _mesa_printf("%2i: %s\n", i+1, clausename(clause->Type));
+
+ for(j = 0; j < clause->NumInstructions; ++j) {
+ _mesa_printf("%4i: ", j+1);
+ _mesa_print_instruction(&clause->Instructions[j]);
+ }
+ }
+}
+
+
+/**
+ * \p position index of the new clause; later clauses are moved
+ * \p type of the new clause; one of CLAUSE_XXX
+ * \return a pointer to the new clause
+ */
+struct radeon_clause* radeonCompilerInsertClause(
+ struct radeon_compiler *compiler,
+ int position, int type)
+{
+ struct radeon_clause* oldClauses = compiler->Clauses;
+ struct radeon_clause* clause;
+
+ assert(position >= 0 && position <= compiler->NumClauses);
+
+ compiler->Clauses = (struct radeon_clause *)
+ _mesa_malloc((compiler->NumClauses+1) * sizeof(struct radeon_clause));
+ if (oldClauses) {
+ _mesa_memcpy(compiler->Clauses, oldClauses,
+ position*sizeof(struct radeon_clause));
+ _mesa_memcpy(compiler->Clauses+position+1, oldClauses+position,
+ (compiler->NumClauses - position) * sizeof(struct radeon_clause));
+ _mesa_free(oldClauses);
+ }
+ compiler->NumClauses++;
+
+ clause = compiler->Clauses + position;
+ _mesa_memset(clause, 0, sizeof(*clause));
+ clause->Type = type;
+
+ return clause;
+}
+
+
+/**
+ * Remove clauses in the range [start, end)
+ */
+void radeonCompilerEraseClauses(
+ struct radeon_compiler *compiler,
+ int start, int end)
+{
+ struct radeon_clause* oldClauses = compiler->Clauses;
+ int i;
+
+ assert(0 <= start);
+ assert(start <= end);
+ assert(end <= compiler->NumClauses);
+
+ if (end == start)
+ return;
+
+ for(i = start; i < end; ++i) {
+ struct radeon_clause* clause = oldClauses + i;
+ _mesa_free_instructions(clause->Instructions, clause->NumInstructions);
+ }
+
+ if (start > 0 || end < compiler->NumClauses) {
+ compiler->Clauses = (struct radeon_clause*)
+ _mesa_malloc((compiler->NumClauses+start-end) * sizeof(struct radeon_clause));
+ _mesa_memcpy(compiler->Clauses, oldClauses,
+ start * sizeof(struct radeon_clause));
+ _mesa_memcpy(compiler->Clauses + start, oldClauses + end,
+ (compiler->NumClauses - end) * sizeof(struct radeon_clause));
+ compiler->NumClauses -= end - start;
+ } else {
+ compiler->Clauses = 0;
+ compiler->NumClauses = 0;
+ }
+
+ _mesa_free(oldClauses);
+}
+
+
+/**
+ * Insert new instructions at the given position, initialize them as NOPs
+ * and return a pointer to the first new instruction.
+ */
+struct prog_instruction* radeonClauseInsertInstructions(
+ struct radeon_compiler *compiler,
+ struct radeon_clause *clause,
+ int position, int count)
+{
+ int newNumInstructions = clause->NumInstructions + count;
+
+ assert(position >= 0 && position <= clause->NumInstructions);
+
+ if (newNumInstructions <= clause->ReservedInstructions) {
+ memmove(clause->Instructions + position + count, clause->Instructions + position,
+ (clause->NumInstructions - position) * sizeof(struct prog_instruction));
+ } else {
+ struct prog_instruction *oldInstructions = clause->Instructions;
+
+ clause->ReservedInstructions *= 2;
+ if (newNumInstructions > clause->ReservedInstructions)
+ clause->ReservedInstructions = newNumInstructions;
+
+ clause->Instructions = (struct prog_instruction*)
+ _mesa_malloc(clause->ReservedInstructions * sizeof(struct prog_instruction));
+
+ if (oldInstructions) {
+ _mesa_memcpy(clause->Instructions, oldInstructions,
+ position * sizeof(struct prog_instruction));
+ _mesa_memcpy(clause->Instructions + position + count, oldInstructions + position,
+ (clause->NumInstructions - position) * sizeof(struct prog_instruction));
+
+ _mesa_free(oldInstructions);
+ }
+ }
+
+ clause->NumInstructions = newNumInstructions;
+ _mesa_init_instructions(clause->Instructions + position, count);
+ return clause->Instructions + position;
+}
+
+
+/**
+ * Transform the given clause in the following way:
+ * 1. Replace it with an empty clause
+ * 2. For every instruction in the original clause, try the given
+ * transformations in order.
+ * 3. If one of the transformations returns GL_TRUE, assume that it
+ * has emitted the appropriate instruction(s) into the new clause;
+ * otherwise, copy the instruction verbatim.
+ *
+ * \note The transformation is currently not recursive; in other words,
+ * instructions emitted by transformations are not transformed.
+ *
+ * \note The transform is called 'local' because it can only look at
+ * one instruction at a time.
+ */
+void radeonClauseLocalTransform(
+ struct radeon_compiler *compiler,
+ struct radeon_clause *clause,
+ int num_transformations,
+ struct radeon_program_transformation* transformations)
+{
+ struct radeon_program_transform_context context;
+ struct radeon_clause source;
+ int ip;
+
+ source = *clause;
+ clause->Instructions = 0;
+ clause->NumInstructions = 0;
+ clause->ReservedInstructions = 0;
+
+ context.compiler = compiler;
+ context.dest = clause;
+ context.src = &source;
+
+ for(ip = 0; ip < source.NumInstructions; ++ip) {
+ struct prog_instruction *instr = source.Instructions + ip;
+ int i;
+
+ for(i = 0; i < num_transformations; ++i) {
+ struct radeon_program_transformation* t = transformations + i;
+
+ if (t->function(&context, instr, t->userData))
+ break;
+ }
+
+ if (i >= num_transformations) {
+ struct prog_instruction *tgt =
+ radeonClauseInsertInstructions(compiler, clause, clause->NumInstructions, 1);
+ _mesa_copy_instructions(tgt, instr, 1);
+ }
+ }
+
+ _mesa_free_instructions(source.Instructions, source.NumInstructions);
+}
diff --git a/src/mesa/drivers/dri/r300/radeon_program.h b/src/mesa/drivers/dri/r300/radeon_program.h
new file mode 100644
index 0000000000..25e70505b1
--- /dev/null
+++ b/src/mesa/drivers/dri/r300/radeon_program.h
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2008 Nicolai Haehnle.
+ *
+ * All Rights Reserved.
+ *
+ * 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 (including the
+ * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+ *
+ */
+
+#ifndef __RADEON_PROGRAM_H_
+#define __RADEON_PROGRAM_H_
+
+#include "glheader.h"
+#include "macros.h"
+#include "enums.h"
+#include "shader/program.h"
+#include "shader/prog_instruction.h"
+
+
+enum {
+ CLAUSE_MIXED = 0,
+ CLAUSE_ALU,
+ CLAUSE_TEX
+};
+
+enum {
+ PROGRAM_BUILTIN = PROGRAM_FILE_MAX /**< not a real register, but a special swizzle constant */
+};
+
+#define SWIZZLE_0000 MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO)
+#define SWIZZLE_1111 MAKE_SWIZZLE4(SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE)
+
+/**
+ * A clause is simply a sequence of instructions that are executed
+ * in order.
+ */
+struct radeon_clause {
+ /**
+ * Type of this clause, one of CLAUSE_XXX.
+ */
+ int Type : 2;
+
+ /**
+ * Pointer to an array of instructions.
+ * The array is terminated by an OPCODE_END instruction.
+ */
+ struct prog_instruction *Instructions;
+
+ /**
+ * Number of instructions in this clause.
+ */
+ int NumInstructions;
+
+ /**
+ * Space reserved for instructions in this clause.
+ */
+ int ReservedInstructions;
+};
+
+/**
+ * A compile object, holding the current intermediate state during compilation.
+ */
+struct radeon_compiler {
+ struct gl_program *Source;
+ GLcontext* Ctx;
+
+ /**
+ * Number of clauses in this program.
+ */
+ int NumClauses;
+
+ /**
+ * Pointer to an array of NumClauses clauses.
+ */
+ struct radeon_clause *Clauses;
+
+ /**
+ * Number of registers in the PROGRAM_TEMPORARIES file.
+ */
+ int NumTemporaries;
+};
+
+void radeonCompilerInit(
+ struct radeon_compiler *compiler,
+ GLcontext *ctx,
+ struct gl_program *source);
+void radeonCompilerCleanup(struct radeon_compiler *compiler);
+int radeonCompilerAllocateTemporary(struct radeon_compiler *compiler);
+void radeonCompilerDump(struct radeon_compiler *compiler);
+
+struct radeon_clause *radeonCompilerInsertClause(
+ struct radeon_compiler *compiler,
+ int position,
+ int type);
+void radeonCompilerEraseClauses(
+ struct radeon_compiler *compiler,
+ int start,
+ int end);
+
+struct prog_instruction* radeonClauseInsertInstructions(
+ struct radeon_compiler *compiler,
+ struct radeon_clause *clause,
+ int position, int count);
+
+/**
+ *
+ */
+struct radeon_program_transform_context {
+ struct radeon_compiler *compiler;
+
+ /**
+ * Destination clause where new instructions must be written.
+ */
+ struct radeon_clause *dest;
+
+ /**
+ * Original clause that is currently being transformed.
+ */
+ struct radeon_clause *src;
+};
+
+/**
+ * A transformation that can be passed to \ref radeonClauseLinearTransform.
+ *
+ * The function will be called once for each instruction.
+ * It has to either emit the appropriate transformed code for the instruction
+ * and return GL_TRUE, or return GL_FALSE if it doesn't understand the
+ * instruction.
+ *
+ * The function gets passed the userData as last parameter.
+ */
+struct radeon_program_transformation {
+ GLboolean (*function)(
+ struct radeon_program_transform_context*,
+ struct prog_instruction*,
+ void*);
+ void *userData;
+};
+
+void radeonClauseLocalTransform(
+ struct radeon_compiler *compiler,
+ struct radeon_clause *clause,
+ int num_transformations,
+ struct radeon_program_transformation* transformations);
+
+#endif
diff --git a/src/mesa/drivers/dri/r300/radeon_program_alu.c b/src/mesa/drivers/dri/r300/radeon_program_alu.c
new file mode 100644
index 0000000000..7fe940a7d7
--- /dev/null
+++ b/src/mesa/drivers/dri/r300/radeon_program_alu.c
@@ -0,0 +1,284 @@
+/*
+ * Copyright (C) 2008 Nicolai Haehnle.
+ *
+ * All Rights Reserved.
+ *
+ * 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 (including the
+ * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+ *
+ */
+
+/**
+ * @file
+ *
+ * Shareable transformations that transform "special" ALU instructions
+ * into ALU instructions that are supported by hardware.
+ *
+ */
+
+#include "radeon_program_alu.h"
+
+
+static struct prog_instruction *emit1(struct radeon_program_transform_context* ctx,
+ gl_inst_opcode Opcode, struct prog_dst_register DstReg,
+ struct prog_src_register SrcReg)
+{
+ struct prog_instruction *fpi =
+ radeonClauseInsertInstructions(ctx->compiler, ctx->dest,
+ ctx->dest->NumInstructions, 1);
+
+ fpi->Opcode = Opcode;
+ fpi->DstReg = DstReg;
+ fpi->SrcReg[0] = SrcReg;
+ return fpi;
+}
+
+static struct prog_instruction *emit2(struct radeon_program_transform_context* ctx,
+ gl_inst_opcode Opcode, struct prog_dst_register DstReg,
+ struct prog_src_register SrcReg0, struct prog_src_register SrcReg1)
+{
+ struct prog_instruction *fpi =
+ radeonClauseInsertInstructions(ctx->compiler, ctx->dest,
+ ctx->dest->NumInstructions, 1);
+
+ fpi->Opcode = Opcode;
+ fpi->DstReg = DstReg;
+ fpi->SrcReg[0] = SrcReg0;
+ fpi->SrcReg[1] = SrcReg1;
+ return fpi;
+}
+
+static struct prog_instruction *emit3(struct radeon_program_transform_context* ctx,
+ gl_inst_opcode Opcode, struct prog_dst_register DstReg,
+ struct prog_src_register SrcReg0, struct prog_src_register SrcReg1,
+ struct prog_src_register SrcReg2)
+{
+ struct prog_instruction *fpi =
+ radeonClauseInsertInstructions(ctx->compiler, ctx->dest,
+ ctx->dest->NumInstructions, 1);
+
+ fpi->Opcode = Opcode;
+ fpi->DstReg = DstReg;
+ fpi->SrcReg[0] = SrcReg0;
+ fpi->SrcReg[1] = SrcReg1;
+ fpi->SrcReg[2] = SrcReg2;
+ return fpi;
+}
+
+static void set_swizzle(struct prog_src_register *SrcReg, int coordinate, int swz)
+{
+ SrcReg->Swizzle &= ~(7 << (3*coordinate));
+ SrcReg->Swizzle |= swz << (3*coordinate);
+}
+
+static void set_negate_base(struct prog_src_register *SrcReg, int coordinate, int negate)
+{
+ SrcReg->NegateBase &= ~(1 << coordinate);
+ SrcReg->NegateBase |= (negate << coordinate);
+}
+
+static struct prog_dst_register dstreg(int file, int index)
+{
+ struct prog_dst_register dst;
+ dst.File = file;
+ dst.Index = index;
+ dst.WriteMask = WRITEMASK_XYZW;
+ dst.CondMask = COND_TR;
+ dst.CondSwizzle = SWIZZLE_NOOP;
+ dst.CondSrc = 0;
+ dst.pad = 0;
+ return dst;
+}
+
+static const struct prog_src_register builtin_zero = {
+ .File = PROGRAM_BUILTIN,
+ .Index = 0,
+ .Swizzle = SWIZZLE_0000
+};
+static const struct prog_src_register builtin_one = {
+ .File = PROGRAM_BUILTIN,
+ .Index = 0,
+ .Swizzle = SWIZZLE_1111
+};
+static const struct prog_src_register srcreg_undefined = {
+ .File = PROGRAM_UNDEFINED,
+ .Index = 0,
+ .Swizzle = SWIZZLE_NOOP
+};
+
+static struct prog_src_register srcreg(int file, int index)
+{
+ struct prog_src_register src = srcreg_undefined;
+ src.File = file;
+ src.Index = index;
+ return src;
+}
+
+static struct prog_src_register negate(struct prog_src_register reg)
+{
+ struct prog_src_register newreg = reg;
+ newreg.NegateAbs = !newreg.NegateAbs;
+ return newreg;
+}
+
+static struct prog_src_register swizzle(struct prog_src_register reg, GLuint x, GLuint y, GLuint z, GLuint w)
+{
+ struct prog_src_register swizzled = reg;
+ swizzled.Swizzle = MAKE_SWIZZLE4(
+ GET_SWZ(reg.Swizzle, x),
+ GET_SWZ(reg.Swizzle, y),
+ GET_SWZ(reg.Swizzle, z),
+ GET_SWZ(reg.Swizzle, w));
+ return swizzled;
+}
+
+static struct prog_src_register scalar(struct prog_src_register reg)
+{
+ return swizzle(reg, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X);
+}
+
+static void transform_ABS(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ struct prog_src_register src = inst->SrcReg[0];
+ src.Abs = 1;
+ src.NegateBase = 0;
+ src.NegateAbs = 0;
+ emit1(ctx, OPCODE_MOV, inst->DstReg, src);
+}
+
+static void transform_DPH(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ struct prog_src_register src0 = inst->SrcReg[0];
+ if (src0.NegateAbs) {
+ if (src0.Abs) {
+ int tempreg = radeonCompilerAllocateTemporary(ctx->compiler);
+ emit1(ctx, OPCODE_MOV, dstreg(PROGRAM_TEMPORARY, tempreg), src0);
+ src0 = srcreg(src0.File, src0.Index);
+ } else {
+ src0.NegateAbs = 0;
+ src0.NegateBase ^= NEGATE_XYZW;
+ }
+ }
+ set_swizzle(&src0, 3, SWIZZLE_ONE);
+ set_negate_base(&src0, 3, 0);
+ emit2(ctx, OPCODE_DP4, inst->DstReg, src0, inst->SrcReg[1]);
+}
+
+static void transform_FLR(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ int tempreg = radeonCompilerAllocateTemporary(ctx->compiler);
+ emit1(ctx, OPCODE_FRC, dstreg(PROGRAM_TEMPORARY, tempreg), inst->SrcReg[0]);
+ emit2(ctx, OPCODE_ADD, inst->DstReg, inst->SrcReg[0], negate(srcreg(PROGRAM_TEMPORARY, tempreg)));
+}
+
+static void transform_POW(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ int tempreg = radeonCompilerAllocateTemporary(ctx->compiler);
+ struct prog_dst_register tempdst = dstreg(PROGRAM_TEMPORARY, tempreg);
+ struct prog_src_register tempsrc = srcreg(PROGRAM_TEMPORARY, tempreg);
+ tempdst.WriteMask = WRITEMASK_W;
+ tempsrc.Swizzle = SWIZZLE_WWWW;
+
+ emit1(ctx, OPCODE_LG2, tempdst, scalar(inst->SrcReg[0]));
+ emit2(ctx, OPCODE_MUL, tempdst, tempsrc, scalar(inst->SrcReg[1]));
+ emit1(ctx, OPCODE_EX2, inst->DstReg, tempsrc);
+}
+
+static void transform_SGE(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ int tempreg = radeonCompilerAllocateTemporary(ctx->compiler);
+
+ emit2(ctx, OPCODE_ADD, dstreg(PROGRAM_TEMPORARY, tempreg), inst->SrcReg[0], negate(inst->SrcReg[1]));
+ emit3(ctx, OPCODE_CMP, inst->DstReg, srcreg(PROGRAM_TEMPORARY, tempreg), builtin_zero, builtin_one);
+}
+
+static void transform_SLT(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ int tempreg = radeonCompilerAllocateTemporary(ctx->compiler);
+
+ emit2(ctx, OPCODE_ADD, dstreg(PROGRAM_TEMPORARY, tempreg), inst->SrcReg[0], negate(inst->SrcReg[1]));
+ emit3(ctx, OPCODE_CMP, inst->DstReg, srcreg(PROGRAM_TEMPORARY, tempreg), builtin_one, builtin_zero);
+}
+
+static void transform_SUB(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ emit2(ctx, OPCODE_ADD, inst->DstReg, inst->SrcReg[0], negate(inst->SrcReg[1]));
+}
+
+static void transform_SWZ(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ emit1(ctx, OPCODE_MOV, inst->DstReg, inst->SrcReg[0]);
+}
+
+static void transform_XPD(struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst)
+{
+ int tempreg = radeonCompilerAllocateTemporary(ctx->compiler);
+
+ emit2(ctx, OPCODE_MUL, dstreg(PROGRAM_TEMPORARY, tempreg),
+ swizzle(inst->SrcReg[0], SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, SWIZZLE_W),
+ swizzle(inst->SrcReg[1], SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, SWIZZLE_W));
+ emit3(ctx, OPCODE_MAD, inst->DstReg,
+ swizzle(inst->SrcReg[0], SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, SWIZZLE_W),
+ swizzle(inst->SrcReg[1], SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, SWIZZLE_W),
+ negate(srcreg(PROGRAM_TEMPORARY, tempreg)));
+}
+
+
+/**
+ * Can be used as a transformation for @ref radeonClauseLocalTransform,
+ * no userData necessary.
+ *
+ * Eliminates the following ALU instructions:
+ * ABS, DPH, FLR, POW, SGE, SLT, SUB, SWZ, XPD
+ * using:
+ * MOV, ADD, MUL, MAD, FRC, DP3, LG2, EX2, CMP
+ *
+ * @note should be applicable to R300 and R500 fragment programs.
+ *
+ * @todo add LIT here as well?
+ */
+GLboolean radeonTransformALU(
+ struct radeon_program_transform_context* ctx,
+ struct prog_instruction* inst,
+ void* unused)
+{
+ switch(inst->Opcode) {
+ case OPCODE_ABS: transform_ABS(ctx, inst); return GL_TRUE;
+ case OPCODE_DPH: transform_DPH(ctx, inst); return GL_TRUE;
+ case OPCODE_FLR: transform_FLR(ctx, inst); return GL_TRUE;
+ case OPCODE_POW: transform_POW(ctx, inst); return GL_TRUE;
+ case OPCODE_SGE: transform_SGE(ctx, inst); return GL_TRUE;
+ case OPCODE_SLT: transform_SLT(ctx, inst); return GL_TRUE;
+ case OPCODE_SUB: transform_SUB(ctx, inst); return GL_TRUE;
+ case OPCODE_SWZ: transform_SWZ(ctx, inst); return GL_TRUE;
+ case OPCODE_XPD: transform_XPD(ctx, inst); return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
diff --git a/src/mesa/drivers/dri/r300/radeon_program_alu.h b/src/mesa/drivers/dri/r300/radeon_program_alu.h
new file mode 100644
index 0000000000..940459624f
--- /dev/null
+++ b/src/mesa/drivers/dri/r300/radeon_program_alu.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2008 Nicolai Haehnle.
+ *
+ * All Rights Reserved.
+ *
+ * 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 (including the
+ * next paragraph) 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+ *
+ */
+
+#ifndef __RADEON_PROGRAM_ALU_H_
+#define __RADEON_PROGRAM_ALU_H_
+
+#include "radeon_program.h"
+
+GLboolean radeonTransformALU(
+ struct radeon_program_transform_context*,
+ struct prog_instruction*,
+ void*);
+
+#endif /* __RADEON_PROGRAM_ALU_H_ */
diff --git a/src/mesa/drivers/dri/r300/radeon_span.c b/src/mesa/drivers/dri/r300/radeon_span.c
index eae09d6b35..f1bc56ea6a 100644
--- a/src/mesa/drivers/dri/r300/radeon_span.c
+++ b/src/mesa/drivers/dri/r300/radeon_span.c
@@ -282,6 +282,30 @@ static void radeonSpanRenderStart(GLcontext * ctx)
#endif
LOCK_HARDWARE(rmesa);
radeonWaitForIdleLocked(rmesa);
+
+ /* Read the first pixel in the frame buffer. This should
+ * be a noop, right? In fact without this conform fails as reading
+ * from the framebuffer sometimes produces old results -- the
+ * on-card read cache gets mixed up and doesn't notice that the
+ * framebuffer has been updated.
+ *
+ * Note that we should probably be reading some otherwise unused
+ * region of VRAM, otherwise we might get incorrect results when
+ * reading pixels from the top left of the screen.
+ *
+ * I found this problem on an R420 with glean's texCube test.
+ * Note that the R200 span code also *writes* the first pixel in the
+ * framebuffer, but I've found this to be unnecessary.
+ * -- Nicolai Hähnle, June 2008
+ */
+ {
+ int p;
+ driRenderbuffer *drb =
+ (driRenderbuffer *) ctx->WinSysDrawBuffer->_ColorDrawBuffers[0];
+ volatile int *buf =
+ (volatile int *)(rmesa->dri.screen->pFB + drb->offset);
+ p = *buf;
+ }
}
static void radeonSpanRenderFinish(GLcontext * ctx)
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index c4dba59198..304d07729e 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -43,6 +43,7 @@
#include "tnl/t_pipeline.h"
#include "vbo/vbo.h"
#include "drivers/common/driverfuncs.h"
+#include "utils.h"
#include "swrast_priv.h"
@@ -51,6 +52,7 @@
#define need_GL_VERSION_1_4
#define need_GL_VERSION_1_5
#define need_GL_VERSION_2_0
+#define need_GL_VERSION_2_1
/* sw extensions for imaging */
#define need_GL_EXT_blend_color
@@ -75,7 +77,6 @@
#define need_GL_NV_fragment_program
#include "extension_helper.h"
-#include "utils.h"
const struct dri_extension card_extensions[] =
{
@@ -83,6 +84,7 @@ const struct dri_extension card_extensions[] =
{ "GL_VERSION_1_4", GL_VERSION_1_4_functions },
{ "GL_VERSION_1_5", GL_VERSION_1_5_functions },
{ "GL_VERSION_2_0", GL_VERSION_2_0_functions },
+ { "GL_VERSION_2_1", GL_VERSION_2_1_functions },
{ "GL_EXT_blend_color", GL_EXT_blend_color_functions },
{ "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
@@ -326,7 +328,7 @@ swrast_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
_mesa_free(rb->Data);
- (void) swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
+ swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
rb->Data = _mesa_malloc(height * xrb->pitch);
@@ -341,59 +343,61 @@ swrast_new_renderbuffer(const GLvisual *visual, GLboolean front)
TRACE;
- if (xrb) {
- _mesa_init_renderbuffer(&xrb->Base, 0);
+ if (!xrb)
+ return NULL;
- pixel_format = choose_pixel_format(visual);
+ _mesa_init_renderbuffer(&xrb->Base, 0);
- xrb->Base.Delete = swrast_delete_renderbuffer;
- if (front) {
- xrb->Base.AllocStorage = swrast_alloc_front_storage;
- swrast_set_span_funcs_front(xrb, pixel_format);
- }
- else {
- xrb->Base.AllocStorage = swrast_alloc_back_storage;
- swrast_set_span_funcs_back(xrb, pixel_format);
- }
+ pixel_format = choose_pixel_format(visual);
- switch (pixel_format) {
- case PF_A8R8G8B8:
- xrb->Base.InternalFormat = GL_RGBA;
- xrb->Base._BaseFormat = GL_RGBA;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->Base.RedBits = 8 * sizeof(GLubyte);
- xrb->Base.GreenBits = 8 * sizeof(GLubyte);
- xrb->Base.BlueBits = 8 * sizeof(GLubyte);
- xrb->Base.AlphaBits = 8 * sizeof(GLubyte);
- break;
- case PF_R5G6B5:
- xrb->Base.InternalFormat = GL_RGB;
- xrb->Base._BaseFormat = GL_RGB;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->Base.RedBits = 5 * sizeof(GLubyte);
- xrb->Base.GreenBits = 6 * sizeof(GLubyte);
- xrb->Base.BlueBits = 5 * sizeof(GLubyte);
- xrb->Base.AlphaBits = 0;
- break;
- case PF_R3G3B2:
- xrb->Base.InternalFormat = GL_RGB;
- xrb->Base._BaseFormat = GL_RGB;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->Base.RedBits = 3 * sizeof(GLubyte);
- xrb->Base.GreenBits = 3 * sizeof(GLubyte);
- xrb->Base.BlueBits = 2 * sizeof(GLubyte);
- xrb->Base.AlphaBits = 0;
- break;
- case PF_CI8:
- xrb->Base.InternalFormat = GL_COLOR_INDEX8_EXT;
- xrb->Base._BaseFormat = GL_COLOR_INDEX;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->Base.IndexBits = 8 * sizeof(GLubyte);
- break;
- default:
- return NULL;
- }
+ xrb->Base.Delete = swrast_delete_renderbuffer;
+ if (front) {
+ xrb->Base.AllocStorage = swrast_alloc_front_storage;
+ swrast_set_span_funcs_front(xrb, pixel_format);
+ }
+ else {
+ xrb->Base.AllocStorage = swrast_alloc_back_storage;
+ swrast_set_span_funcs_back(xrb, pixel_format);
}
+
+ switch (pixel_format) {
+ case PF_A8R8G8B8:
+ xrb->Base.InternalFormat = GL_RGBA;
+ xrb->Base._BaseFormat = GL_RGBA;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->Base.RedBits = 8 * sizeof(GLubyte);
+ xrb->Base.GreenBits = 8 * sizeof(GLubyte);
+ xrb->Base.BlueBits = 8 * sizeof(GLubyte);
+ xrb->Base.AlphaBits = 8 * sizeof(GLubyte);
+ break;
+ case PF_R5G6B5:
+ xrb->Base.InternalFormat = GL_RGB;
+ xrb->Base._BaseFormat = GL_RGB;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->Base.RedBits = 5 * sizeof(GLubyte);
+ xrb->Base.GreenBits = 6 * sizeof(GLubyte);
+ xrb->Base.BlueBits = 5 * sizeof(GLubyte);
+ xrb->Base.AlphaBits = 0;
+ break;
+ case PF_R3G3B2:
+ xrb->Base.InternalFormat = GL_RGB;
+ xrb->Base._BaseFormat = GL_RGB;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->Base.RedBits = 3 * sizeof(GLubyte);
+ xrb->Base.GreenBits = 3 * sizeof(GLubyte);
+ xrb->Base.BlueBits = 2 * sizeof(GLubyte);
+ xrb->Base.AlphaBits = 0;
+ break;
+ case PF_CI8:
+ xrb->Base.InternalFormat = GL_COLOR_INDEX8_EXT;
+ xrb->Base._BaseFormat = GL_COLOR_INDEX;
+ xrb->Base.DataType = GL_UNSIGNED_BYTE;
+ xrb->Base.IndexBits = 8 * sizeof(GLubyte);
+ break;
+ default:
+ return NULL;
+ }
+
return xrb;
}
@@ -691,7 +695,6 @@ static int driUnbindContext(__DRIcontext *ctx)
{
TRACE;
(void) ctx;
- _mesa_make_current(NULL, NULL, NULL);
return GL_TRUE;
}
diff --git a/src/mesa/drivers/fbdev/Makefile b/src/mesa/drivers/fbdev/Makefile
new file mode 100644
index 0000000000..c0ef54f604
--- /dev/null
+++ b/src/mesa/drivers/fbdev/Makefile
@@ -0,0 +1,36 @@
+# src/mesa/drivers/fbdev/Makefile for libGL.so
+
+TOP = ../../../..
+
+include $(TOP)/configs/current
+
+
+SOURCES = glfbdev.c
+
+OBJECTS = $(SOURCES:.c=.o)
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/mesa \
+ -I$(TOP)/src/mesa/main
+
+CORE_MESA = $(TOP)/src/mesa/libmesa.a $(TOP)/src/mesa/libglapi.a
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+
+
+default: $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
+
+
+$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(CORE_MESA) $(OBJECTS)
+ @ $(TOP)/bin/mklib -o $(GL_LIB) \
+ -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+ -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \
+ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
+ $(CORE_MESA) $(OBJECTS) $(GL_LIB_DEPS)
+
+
+clean:
+ -rm -f $(OBJECTS)
diff --git a/src/mesa/drivers/osmesa/Makefile b/src/mesa/drivers/osmesa/Makefile
new file mode 100644
index 0000000000..fa8dffcb3e
--- /dev/null
+++ b/src/mesa/drivers/osmesa/Makefile
@@ -0,0 +1,74 @@
+# src/mesa/drivers/osmesa/Makefile for libOSMesa.so
+
+# Note that we may generate libOSMesa.so or libOSMesa16.so or libOSMesa32.so
+# with this Makefile
+
+
+TOP = ../../../..
+
+include $(TOP)/configs/current
+
+
+
+SOURCES = osmesa.c
+
+OBJECTS = $(SOURCES:.c=.o)
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/mesa \
+ -I$(TOP)/src/mesa/main
+
+CORE_MESA = $(TOP)/src/mesa/libmesa.a $(TOP)/src/mesa/libglapi.a
+
+
+.PHONY: osmesa8
+.PHONY: osmesa16
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+
+
+default:
+# $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME)
+ @ if [ "${DRIVER_DIRS}" = "osmesa" ] ; then \
+ $(MAKE) osmesa16 ; \
+ else \
+ $(MAKE) osmesa8 ; \
+ fi
+
+
+
+
+# The normal libOSMesa is used in conjuction with libGL
+osmesa8: $(TOP)/lib/$(OSMESA_LIB_NAME)
+
+$(TOP)/lib/$(OSMESA_LIB_NAME): $(OBJECTS)
+ $(TOP)/bin/mklib -o $(OSMESA_LIB) \
+ -linker "$(CC)" \
+ -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \
+ -install $(TOP)/$(LIB_DIR) \
+ $(MKLIB_OPTIONS) \
+ $(OSMESA_LIB_DEPS) $(OBJECTS)
+
+
+
+
+# The libOSMesa16/libOSMesa32 libraries do not use libGL but rather are built
+# with all the other Mesa sources (compiled with -DCHAN_BITS=16/32
+osmesa16: $(OBJECTS) $(CORE_MESA)
+ $(TOP)/bin/mklib -o $(OSMESA_LIB) \
+ -linker "$(CC)" \
+ -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \
+ -install $(TOP)/$(LIB_DIR) \
+ $(MKLIB_OPTIONS) \
+ $(OSMESA_LIB_DEPS) $(OBJECTS) $(CORE_MESA)
+
+
+
+clean:
+ -rm -f *.o *~
+
+
+# XXX todo install rule?
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 29a6c1f4aa..f2367bbbb7 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -33,14 +33,14 @@
*/
-#include "glheader.h"
+#include "main/glheader.h"
#include "GL/osmesa.h"
-#include "context.h"
-#include "extensions.h"
-#include "framebuffer.h"
-#include "imports.h"
-#include "mtypes.h"
-#include "renderbuffer.h"
+#include "main/context.h"
+#include "main/extensions.h"
+#include "main/framebuffer.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
+#include "main/renderbuffer.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "swrast/s_context.h"
diff --git a/src/mesa/drivers/x11/Makefile b/src/mesa/drivers/x11/Makefile
new file mode 100644
index 0000000000..51226eeae1
--- /dev/null
+++ b/src/mesa/drivers/x11/Makefile
@@ -0,0 +1,79 @@
+# src/mesa/drivers/x11/Makefile for libGL.so
+
+# This builds "stand-alone" Mesa, a version of libGL that does not need the
+# GLX extension. All rendering is converted to Xlib calls. No hardware
+# acceleration.
+
+
+TOP = ../../../..
+
+include $(TOP)/configs/current
+
+
+GL_MAJOR = 1
+GL_MINOR = 5
+GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY)
+
+
+HEADERS = \
+ glxapi.h \
+ glxheader.h \
+ xfonts.h \
+ xmesaP.h \
+ xm_glide.h \
+ xm_image.h
+
+SOURCES = \
+ fakeglx.c \
+ glxapi.c \
+ xfonts.c \
+ xm_api.c \
+ xm_buffer.c \
+ xm_dd.c \
+ xm_glide.c \
+ xm_image.c \
+ xm_line.c \
+ xm_span.c \
+ xm_tri.c
+
+OBJECTS = $(SOURCES:.c=.o)
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+ -I$(TOP)/src/mesa \
+ -I$(TOP)/src/mesa/main
+
+CORE_MESA = $(TOP)/src/mesa/libmesa.a $(TOP)/src/mesa/libglapi.a
+
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+
+
+default: $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
+
+
+$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(OBJECTS) $(CORE_MESA)
+ @ $(TOP)/bin/mklib -o $(GL_LIB) \
+ -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+ -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \
+ -install $(TOP)/$(LIB_DIR) \
+ $(MKLIB_OPTIONS) $(GL_LIB_DEPS) $(OBJECTS) $(CORE_MESA)
+
+
+
+clean:
+ -rm -f *.o *~
+ -rm -f depend depend.bak
+
+
+
+depend: $(SOURCES) $(HEADERS)
+ @ echo "running $(MKDEP)"
+ @ touch depend
+ @$(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(SOURCES) $(HEADERS) \
+ > /dev/null 2>/dev/null
+
+
+-include depend
diff --git a/src/mesa/drivers/x11/glxapi.c b/src/mesa/drivers/x11/glxapi.c
index 309a0008d7..c2ccce6f52 100644
--- a/src/mesa/drivers/x11/glxapi.c
+++ b/src/mesa/drivers/x11/glxapi.c
@@ -34,8 +34,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "glheader.h"
-#include "glapi.h"
+#include "main/glheader.h"
+#include "glapi/glapi.h"
#include "glxapi.h"
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index 8941817531..5bae69a472 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -65,14 +65,14 @@
#include "glxheader.h"
#include "GL/xmesa.h"
#include "xmesaP.h"
-#include "context.h"
-#include "extensions.h"
-#include "framebuffer.h"
-#include "glthread.h"
-#include "imports.h"
-#include "macros.h"
-#include "renderbuffer.h"
-#include "teximage.h"
+#include "main/context.h"
+#include "main/extensions.h"
+#include "main/framebuffer.h"
+#include "glapi/glthread.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/renderbuffer.h"
+#include "main/teximage.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "vbo/vbo.h"
diff --git a/src/mesa/drivers/x11/xm_glide.c b/src/mesa/drivers/x11/xm_glide.c
index ae4f4282db..cbd69b011a 100644
--- a/src/mesa/drivers/x11/xm_glide.c
+++ b/src/mesa/drivers/x11/xm_glide.c
@@ -64,7 +64,8 @@ FXcreateContext(XMesaVisual v, XMesaWindow w, XMesaContext c, XMesaBuffer b)
attribs[numAttribs++] = FXMESA_NONE;
/* [dBorca] we should take an envvar for `fxMesaSelectCurrentBoard'!!! */
- hw = fxMesaSelectCurrentBoard(0);
+/* hw = fxMesaSelectCurrentBoard(0); */
+ hw = GR_SSTTYPE_Voodoo2;
/* if these fail, there's a new bug somewhere */
ASSERT(b->mesa_buffer.Width > 0);
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index 347cec66ef..8034daecae 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -3963,7 +3963,7 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
DEPTH_VALUES(GLuint, UINT_TO_FLOAT);
break;
case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
- if (dstType == GL_UNSIGNED_INT &&
+ if (dstType == GL_UNSIGNED_INT_24_8_EXT &&
depthMax == 0xffffff &&
ctx->Pixel.DepthScale == 1.0 &&
ctx->Pixel.DepthBias == 0.0) {
diff --git a/src/mesa/main/mm.c b/src/mesa/main/mm.c
index 846c329c70..fb7809ed22 100644
--- a/src/mesa/main/mm.c
+++ b/src/mesa/main/mm.c
@@ -53,7 +53,7 @@ mmDumpMemInfo(const struct mem_block *heap)
}
struct mem_block *
-mmInit(int ofs, int size)
+mmInit(unsigned int ofs, int size)
{
struct mem_block *heap, *block;
@@ -91,7 +91,7 @@ mmInit(int ofs, int size)
static struct mem_block *
SliceBlock(struct mem_block *p,
- int startofs, int size,
+ unsigned int startofs, int size,
int reserved, int alignment)
{
struct mem_block *newblock;
@@ -164,8 +164,8 @@ mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch)
{
struct mem_block *p;
const int mask = (1 << align2)-1;
- int startofs = 0;
- int endofs;
+ unsigned int startofs = 0;
+ unsigned int endofs;
if (!heap || align2 < 0 || size <= 0)
return NULL;
diff --git a/src/mesa/main/mm.h b/src/mesa/main/mm.h
index 26d59fff13..5ad3ffd6d1 100644
--- a/src/mesa/main/mm.h
+++ b/src/mesa/main/mm.h
@@ -39,7 +39,8 @@ struct mem_block {
struct mem_block *next, *prev;
struct mem_block *next_free, *prev_free;
struct mem_block *heap;
- int ofs,size;
+ unsigned int ofs;
+ int size;
unsigned int free:1;
unsigned int reserved:1;
};
@@ -50,7 +51,7 @@ struct mem_block {
* input: total size in bytes
* return: a heap pointer if OK, NULL if error
*/
-extern struct mem_block *mmInit(int ofs, int size);
+extern struct mem_block *mmInit(unsigned int ofs, int size);
/**
* Allocate 'size' bytes with 2^align2 bytes alignment,
diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c
index af19a38c42..512d52704d 100644
--- a/src/mesa/main/texenvprogram.c
+++ b/src/mesa/main/texenvprogram.c
@@ -68,6 +68,7 @@ struct state_key {
struct {
GLuint enabled:1;
GLuint source_index:3; /* one of TEXTURE_1D/2D/3D/CUBE/RECT_INDEX */
+ GLuint shadow:1;
GLuint ScaleShiftRGB:2;
GLuint ScaleShiftA:2;
@@ -219,6 +220,7 @@ static void make_state_key( GLcontext *ctx, struct state_key *key )
key->unit[i].source_index =
translate_tex_src_bit(texUnit->_ReallyEnabled);
+ key->unit[i].shadow = texUnit->_Current->CompareMode == GL_COMPARE_R_TO_TEXTURE;
key->unit[i].NumArgsRGB = texUnit->_CurrentCombine->_NumArgsRGB;
key->unit[i].NumArgsA = texUnit->_CurrentCombine->_NumArgsA;
@@ -945,11 +947,13 @@ static void load_texture( struct texenv_fragment_program *p, GLuint unit )
/* TODO: Use D0_MASK_XY where possible.
*/
- if (p->state->unit[unit].enabled)
+ if (p->state->unit[unit].enabled) {
p->src_texture[unit] = emit_texld( p, OPCODE_TXP,
tmp, WRITEMASK_XYZW,
unit, dim, texcoord );
- else
+ if (p->state->unit[unit].shadow)
+ p->program->Base.ShadowSamplers |= 1 << unit;
+ } else
p->src_texture[unit] = get_zero(p);
}
}
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 5363e9e080..89774291f2 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -2322,7 +2322,7 @@ _mesa_texstore_ycbcr(TEXSTORE_PARAMS)
GLboolean
_mesa_texstore_z24_s8(TEXSTORE_PARAMS)
{
- const GLuint depthScale = 0xffffff;
+ const GLfloat depthScale = (GLfloat) 0xffffff;
ASSERT(dstFormat == &_mesa_texformat_z24_s8);
ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT);
@@ -2360,7 +2360,7 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
GLint i;
/* the 24 depth bits will be in the high position: */
_mesa_unpack_depth_span(ctx, srcWidth,
- GL_UNSIGNED_INT, /* dst type */
+ GL_UNSIGNED_INT_24_8_EXT, /* dst type */
dstRow, /* dst addr */
depthScale,
srcType, src, srcPacking);
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c
index 60aaabe679..97bda9c6b3 100644
--- a/src/mesa/shader/arbprogparse.c
+++ b/src/mesa/shader/arbprogparse.c
@@ -3869,7 +3869,7 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target,
program->Base.Parameters = ap.Base.Parameters;
#if DEBUG_FP
- _mesa_printf("____________Fragment program %u ________\n", program->Base.ID);
+ _mesa_printf("____________Fragment program %u ________\n", program->Base.Id);
_mesa_print_program(&program->Base);
#endif
}
diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 8ce2ca3964..4575a069ea 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -90,7 +90,8 @@ get_register_pointer(const struct prog_src_register *source,
const struct gl_program_parameter_list *params;
ASSERT(source->File == PROGRAM_LOCAL_PARAM ||
source->File == PROGRAM_CONSTANT ||
- source->File == PROGRAM_STATE_VAR);
+ source->File == PROGRAM_STATE_VAR ||
+ source->File == PROGRAM_UNIFORM);
params = machine->CurProgram->Parameters;
if (reg < 0 || reg >= params->NumParameters)
return ZeroVec;
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index 152bd79f69..afdd7e5489 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -62,6 +62,28 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList)
}
+static GLint
+_mesa_fit_type_in_vec4(GLenum type)
+{
+ switch (type) {
+ case GL_FLOAT:
+ case GL_INT:
+ return 4;
+ break;
+ case GL_FLOAT_VEC2:
+ case GL_INT_VEC2:
+ return 2;
+ break;
+ case GL_FLOAT_VEC3:
+ case GL_INT_VEC3:
+ return 1;
+ break;
+ case GL_FLOAT_VEC4:
+ case GL_INT_VEC4:
+ default:
+ return 1;
+ }
+}
/**
* Add a new parameter to a parameter list.
@@ -272,7 +294,7 @@ _mesa_add_uniform(struct gl_program_parameter_list *paramList,
}
else {
i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name,
- size, datatype, NULL, NULL);
+ size * _mesa_fit_type_in_vec4(datatype), datatype, NULL, NULL);
return i;
}
}
diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c
index 1c35ce3fec..2c5e03acc2 100644
--- a/src/mesa/shader/prog_print.c
+++ b/src/mesa/shader/prog_print.c
@@ -206,7 +206,7 @@ arb_output_attrib_string(GLint index, GLenum progType)
*/
static const char *
reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
- const struct gl_program *prog)
+ GLboolean relAddr, const struct gl_program *prog)
{
static char str[100];
@@ -214,7 +214,10 @@ reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
switch (mode) {
case PROG_PRINT_DEBUG:
- sprintf(str, "%s[%d]", file_string(f, mode), index);
+ if (relAddr)
+ sprintf(str, "%s[ADDR%s%d]", file_string(f, mode), (index > 0) ? "+" : "", index);
+ else
+ sprintf(str, "%s[%d]", file_string(f, mode), index);
break;
case PROG_PRINT_ARB:
@@ -401,7 +404,7 @@ print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
{
_mesa_printf("%s%s",
reg_string((enum register_file) dstReg->File,
- dstReg->Index, mode, prog),
+ dstReg->Index, mode, GL_FALSE, prog),
writemask_string(dstReg->WriteMask));
if (dstReg->CondMask != COND_TR) {
@@ -424,9 +427,9 @@ print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode,
{
_mesa_printf("%s%s",
reg_string((enum register_file) srcReg->File,
- srcReg->Index, mode, prog),
+ srcReg->Index, mode, srcReg->RelAddr, prog),
_mesa_swizzle_string(srcReg->Swizzle,
- srcReg->NegateBase, GL_FALSE));
+ srcReg->NegateBase, GL_FALSE));
#if 0
_mesa_printf("%s[%d]%s",
file_string((enum register_file) srcReg->File, mode),
@@ -590,7 +593,9 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
break;
case OPCODE_ARL:
- _mesa_printf("ARL addr.x, ");
+ _mesa_printf("ARL ");
+ print_dst_reg(&inst->DstReg, mode, prog);
+ _mesa_printf(", ");
print_src_reg(&inst->SrcReg[0], mode, prog);
print_comment(inst);
break;
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index 7d560c74a5..f3511ba00e 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -367,20 +367,22 @@ _mesa_count_texture_instructions(struct gl_program *prog)
/**
- * Scan/rewrite program to remove reads of varying (output) registers.
+ * Scan/rewrite program to remove reads of custom (output) registers.
+ * The passed type has to be either PROGRAM_VARYING or PROGRAM_OUTPUT.
* In GLSL vertex shaders, varying vars can be read and written.
* Normally, vertex varying vars are implemented as output registers.
* On some hardware, trying to read an output register causes trouble.
* So, rewrite the program to use a temporary register in this case.
*/
void
-_mesa_remove_varying_reads(struct gl_program *prog)
+_mesa_remove_output_reads(struct gl_program *prog, enum register_file type)
{
GLuint i;
GLint outputMap[VERT_RESULT_MAX];
GLuint numVaryingReads = 0;
assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
+ assert(type == PROGRAM_VARYING || type == PROGRAM_OUTPUT);
for (i = 0; i < VERT_RESULT_MAX; i++)
outputMap[i] = -1;
@@ -391,7 +393,7 @@ _mesa_remove_varying_reads(struct gl_program *prog)
const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
GLuint j;
for (j = 0; j < numSrc; j++) {
- if (inst->SrcReg[j].File == PROGRAM_VARYING) {
+ if (inst->SrcReg[j].File == type) {
/* replace the read with a temp reg */
const GLuint var = inst->SrcReg[j].Index;
if (outputMap[var] == -1) {
@@ -414,7 +416,7 @@ _mesa_remove_varying_reads(struct gl_program *prog)
const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
GLuint j;
for (j = 0; j < numSrc; j++) {
- if (inst->DstReg.File == PROGRAM_VARYING &&
+ if (inst->DstReg.File == type &&
outputMap[inst->DstReg.Index] >= 0) {
/* change inst to write to the temp reg, instead of the varying */
inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -447,7 +449,7 @@ _mesa_remove_varying_reads(struct gl_program *prog)
if (outputMap[var] >= 0) {
/* MOV VAR[var], TEMP[tmp]; */
inst->Opcode = OPCODE_MOV;
- inst->DstReg.File = PROGRAM_VARYING;
+ inst->DstReg.File = type;
inst->DstReg.Index = var;
inst->SrcReg[0].File = PROGRAM_TEMPORARY;
inst->SrcReg[0].Index = outputMap[var];
diff --git a/src/mesa/shader/programopt.h b/src/mesa/shader/programopt.h
index 47ff2f0c7b..11572e64f5 100644
--- a/src/mesa/shader/programopt.h
+++ b/src/mesa/shader/programopt.h
@@ -40,6 +40,6 @@ extern void
_mesa_count_texture_instructions(struct gl_program *prog);
extern void
-_mesa_remove_varying_reads(struct gl_program *prog);
+_mesa_remove_output_reads(struct gl_program *prog, enum register_file type);
#endif /* PROGRAMOPT_H */
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index 46b5c54bbe..cdea1c5128 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -258,9 +258,33 @@ parse_array_len(slang_parse_ctx * C, slang_output_ctx * O, GLuint * len)
/* evaluate compile-time expression which is array size */
_slang_simplify(&array_size, &space, C->atoms);
- result = (array_size.type == SLANG_OPER_LITERAL_INT);
- *len = (GLint) array_size.literal[0];
+ if (array_size.type == SLANG_OPER_LITERAL_INT) {
+ result = GL_TRUE;
+ *len = (GLint) array_size.literal[0];
+ } else if (array_size.type == SLANG_OPER_IDENTIFIER) {
+ slang_variable *var = _slang_locate_variable(array_size.locals, array_size.a_id, GL_TRUE);
+ if (!var) {
+ slang_info_log_error(C->L, "undefined variable '%s'",
+ (char *) array_size.a_id);
+ result = GL_FALSE;
+ } else if (var->type.qualifier == SLANG_QUAL_CONST &&
+ var->type.specifier.type == SLANG_SPEC_INT) {
+ if (var->initializer &&
+ var->initializer->type == SLANG_OPER_LITERAL_INT) {
+ *len = (GLint) var->initializer->literal[0];
+ result = GL_TRUE;
+ } else {
+ slang_info_log_error(C->L, "unable to parse array size declaration");
+ result = GL_FALSE;
+ }
+ } else {
+ slang_info_log_error(C->L, "unable to parse array size declaration");
+ result = GL_FALSE;
+ }
+ } else {
+ result = GL_FALSE;
+ }
slang_operation_destruct(&array_size);
return result;
@@ -2188,7 +2212,8 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader)
printf("Pre-remove output reads:\n");
_mesa_print_program(shader->Programs[0]);
#endif
- _mesa_remove_varying_reads(shader->Programs[0]);
+ _mesa_remove_output_reads(shader->Programs[0], PROGRAM_VARYING);
+ _mesa_remove_output_reads(shader->Programs[0], PROGRAM_OUTPUT);
#if 0
printf("Post-remove output reads:\n");
_mesa_print_program(shader->Programs[0]);
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index ff63e05dd2..93256f8647 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -223,6 +223,7 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st)
assert(st->Size <= 4);
src->File = st->File;
src->Index = st->Index;
+ src->RelAddr = st->RelAddr;
if (st->Swizzle != SWIZZLE_NOOP)
src->Swizzle = st->Swizzle;
else
@@ -1488,11 +1489,16 @@ emit_array_element(slang_emit_info *emitInfo, slang_ir_node *n)
n->Store->Index = arrayAddr + index;
}
else {
- /* Variable index - PROBLEM */
- const GLint arrayAddr = n->Children[0]->Store->Index;
- const GLint index = 0;
- _mesa_problem(NULL, "variable array indexes not supported yet!");
- n->Store->Index = arrayAddr + index;
+ /* Variable index*/
+ struct prog_instruction *inst;
+ inst = new_instruction(emitInfo, OPCODE_ARL);
+ storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[1]->Store);
+ inst->DstReg.File = PROGRAM_ADDRESS;
+ inst->Comment = _mesa_strdup("ARL ADDR");
+ n->Store->RelAddr = GL_TRUE;
+ n->Store->Index = inst->DstReg.Index;/*index of the array*/
+ inst->DstReg.Index = 0; /*addr index is always 0*/
}
return NULL; /* no instruction */
}
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index c7c0ddbf9a..ba0735d64d 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -146,6 +146,7 @@ struct _slang_ir_storage
GLint Size; /**< number of floats */
GLuint Swizzle;
GLint RefCount; /**< Used during IR tree delete */
+ GLboolean RelAddr;
};
typedef struct _slang_ir_storage slang_ir_storage;
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 80cd4b6df6..dd4990ba02 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -262,6 +262,9 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
return GL_FALSE;
}
_mesa_add_attribute(shProg->Attributes, name, size, attr);
+
+ /* set the attribute as used */
+ usedAttributes |= 1<<attr;
}
inst->SrcReg[j].Index = VERT_ATTRIB_GENERIC0 + attr;
diff --git a/src/mesa/sources b/src/mesa/sources
index 054f667a25..2db1843239 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -241,57 +241,11 @@ SPARC_API = \
COMMON_DRIVER_SOURCES = \
drivers/common/driverfuncs.c
-X11_DRIVER_SOURCES = \
- drivers/x11/glxapi.c \
- drivers/x11/fakeglx.c \
- drivers/x11/xfonts.c \
- drivers/x11/xm_api.c \
- drivers/x11/xm_buffer.c \
- drivers/x11/xm_dd.c \
- drivers/x11/xm_glide.c \
- drivers/x11/xm_line.c \
- drivers/x11/xm_span.c \
- drivers/x11/xm_tri.c
-
-OSMESA_DRIVER_SOURCES = \
- drivers/osmesa/osmesa.c
-
-GLIDE_DRIVER_SOURCES = \
- drivers/glide/fxapi.c \
- drivers/glide/fxdd.c \
- drivers/glide/fxddspan.c \
- drivers/glide/fxddtex.c \
- drivers/glide/fxsetup.c \
- drivers/glide/fxtexman.c \
- drivers/glide/fxtris.c \
- drivers/glide/fxvb.c \
- drivers/glide/fxglidew.c \
- drivers/glide/fxg.c
-
-SVGA_DRIVER_SOURCES = \
- drivers/svga/svgamesa.c \
- drivers/svga/svgamesa8.c \
- drivers/svga/svgamesa15.c \
- drivers/svga/svgamesa16.c \
- drivers/svga/svgamesa24.c \
- drivers/svga/svgamesa32.c
-
-FBDEV_DRIVER_SOURCES = \
- drivers/fbdev/glfbdev.c
### All the core C sources
-ALL_SOURCES = \
- $(GLAPI_SOURCES) \
- $(SOLO_SOURCES) \
- $(ASM_SOURCES) \
- $(COMMON_DRIVER_SOURCES)\
- $(X11_DRIVER_SOURCES) \
- $(FBDEV_DRIVER_SOURCES) \
- $(OSMESA_DRIVER_SOURCES)
-
-SOLO_SOURCES = \
+MESA_SOURCES = \
$(MAIN_SOURCES) \
$(MATH_SOURCES) \
$(VBO_SOURCES) \
@@ -299,32 +253,31 @@ SOLO_SOURCES = \
$(SHADER_SOURCES) \
$(SWRAST_SOURCES) \
$(SWRAST_SETUP_SOURCES) \
+ $(COMMON_DRIVER_SOURCES) \
$(ASM_C_SOURCES) \
$(SLANG_SOURCES)
-CORE_SOURCES = \
+ALL_SOURCES = \
+ $(MESA_SOURCES) \
$(GLAPI_SOURCES) \
- $(SOLO_SOURCES)
+ $(ASM_SOURCES) \
+ $(COMMON_DRIVER_SOURCES)
+
### Object files
-SOLO_OBJECTS = \
- $(SOLO_SOURCES:.c=.o) \
+MESA_OBJECTS = \
+ $(MESA_SOURCES:.c=.o) \
$(ASM_SOURCES:.S=.o)
GLAPI_OBJECTS = \
$(GLAPI_SOURCES:.c=.o) \
$(ASM_API:.S=.o)
-CORE_OBJECTS = $(SOLO_OBJECTS) $(GLAPI_OBJECTS)
-
-OSMESA_DRIVER_OBJECTS = $(OSMESA_DRIVER_SOURCES:.c=.o)
COMMON_DRIVER_OBJECTS = $(COMMON_DRIVER_SOURCES:.c=.o)
-FBDEV_DRIVER_OBJECTS = $(FBDEV_DRIVER_SOURCES:.c=.o)
-
### Include directories
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 8e6b28bb4c..eab9ff3a9e 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -832,6 +832,8 @@ _swrast_DestroyContext( GLcontext *ctx )
}
FREE( swrast->SpanArrays );
+ if (swrast->ZoomedArrays)
+ FREE( swrast->ZoomedArrays );
FREE( swrast->TexelBuffer );
FREE( swrast );
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 3dcc3ed16e..a511d1c9a1 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -206,6 +206,7 @@ typedef struct
* on some systems.
*/
SWspanarrays *SpanArrays;
+ SWspanarrays *ZoomedArrays; /**< For pixel zooming */
/**
* Used to buffer N GL_POINTS, instead of rendering one by one.
diff --git a/src/mesa/swrast/s_zoom.c b/src/mesa/swrast/s_zoom.c
index 9f1a4c6f0a..4473078b78 100644
--- a/src/mesa/swrast/s_zoom.c
+++ b/src/mesa/swrast/s_zoom.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.2
+ * Version: 7.1
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -130,8 +130,8 @@ static void
zoom_span( GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span,
const GLvoid *src, GLenum format )
{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
SWspan zoomed;
- SWspanarrays zoomed_arrays; /* this is big! */
GLint x0, x1, y0, y1;
GLint zoomedWidth;
@@ -140,6 +140,13 @@ zoom_span( GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span,
return; /* totally clipped */
}
+ if (!swrast->ZoomedArrays) {
+ /* allocate on demand */
+ swrast->ZoomedArrays = (SWspanarrays *) CALLOC(sizeof(SWspanarrays));
+ if (!swrast->ZoomedArrays)
+ return;
+ }
+
zoomedWidth = x1 - x0;
ASSERT(zoomedWidth > 0);
ASSERT(zoomedWidth <= MAX_WIDTH);
@@ -151,14 +158,14 @@ zoom_span( GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span,
INIT_SPAN(zoomed, GL_BITMAP);
zoomed.x = x0;
zoomed.end = zoomedWidth;
- zoomed.array = &zoomed_arrays;
- zoomed_arrays.ChanType = span->array->ChanType;
- if (zoomed_arrays.ChanType == GL_UNSIGNED_BYTE)
- zoomed_arrays.rgba = (GLchan (*)[4]) zoomed_arrays.rgba8;
- else if (zoomed_arrays.ChanType == GL_UNSIGNED_SHORT)
- zoomed_arrays.rgba = (GLchan (*)[4]) zoomed_arrays.rgba16;
+ zoomed.array = swrast->ZoomedArrays;
+ zoomed.array->ChanType = span->array->ChanType;
+ if (zoomed.array->ChanType == GL_UNSIGNED_BYTE)
+ zoomed.array->rgba = (GLchan (*)[4]) zoomed.array->rgba8;
+ else if (zoomed.array->ChanType == GL_UNSIGNED_SHORT)
+ zoomed.array->rgba = (GLchan (*)[4]) zoomed.array->rgba16;
else
- zoomed_arrays.rgba = (GLchan (*)[4]) zoomed_arrays.attribs[FRAG_ATTRIB_COL0];
+ zoomed.array->rgba = (GLchan (*)[4]) zoomed.array->attribs[FRAG_ATTRIB_COL0];
COPY_4V(zoomed.attrStart[FRAG_ATTRIB_WPOS], span->attrStart[FRAG_ATTRIB_WPOS]);
COPY_4V(zoomed.attrStepX[FRAG_ATTRIB_WPOS], span->attrStepX[FRAG_ATTRIB_WPOS]);
diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
index 3b8dd18bbb..e772a06eda 100644
--- a/src/mesa/tnl/t_context.c
+++ b/src/mesa/tnl/t_context.c
@@ -105,10 +105,10 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
const struct gl_vertex_program *vp = ctx->VertexProgram._Current;
const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
- if (new_state & (_NEW_HINT)) {
+ if (new_state & (_NEW_HINT | _NEW_PROGRAM)) {
ASSERT(tnl->AllowVertexFog || tnl->AllowPixelFog);
- tnl->_DoVertexFog = (tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
- || !tnl->AllowPixelFog;
+ tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
+ || !tnl->AllowPixelFog) && !fp;
}
tnl->pipeline.new_state |= new_state;
@@ -202,8 +202,8 @@ _tnl_allow_vertex_fog( GLcontext *ctx, GLboolean value )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
tnl->AllowVertexFog = value;
- tnl->_DoVertexFog = (tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
- || !tnl->AllowPixelFog;
+ tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
+ || !tnl->AllowPixelFog) && !ctx->FragmentProgram._Current;
}
@@ -212,7 +212,7 @@ _tnl_allow_pixel_fog( GLcontext *ctx, GLboolean value )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
tnl->AllowPixelFog = value;
- tnl->_DoVertexFog = (tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
- || !tnl->AllowPixelFog;
+ tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
+ || !tnl->AllowPixelFog) && !ctx->FragmentProgram._Current;
}
diff --git a/src/mesa/tnl/t_pipeline.c b/src/mesa/tnl/t_pipeline.c
index 2a0ed8852a..357ef1e24b 100644
--- a/src/mesa/tnl/t_pipeline.c
+++ b/src/mesa/tnl/t_pipeline.c
@@ -199,11 +199,11 @@ const struct tnl_pipeline_stage *_tnl_default_pipeline[] = {
&_tnl_vertex_transform_stage,
&_tnl_normal_transform_stage,
&_tnl_lighting_stage,
- &_tnl_fog_coordinate_stage,
&_tnl_texgen_stage,
&_tnl_texture_transform_stage,
&_tnl_point_attenuation_stage,
&_tnl_vertex_program_stage,
+ &_tnl_fog_coordinate_stage,
&_tnl_render_stage,
NULL
};
diff --git a/src/mesa/tnl/t_vb_fog.c b/src/mesa/tnl/t_vb_fog.c
index d8bca3820b..99e5a09c75 100644
--- a/src/mesa/tnl/t_vb_fog.c
+++ b/src/mesa/tnl/t_vb_fog.c
@@ -148,11 +148,11 @@ run_fog_stage(GLcontext *ctx, struct tnl_pipeline_stage *stage)
struct fog_stage_data *store = FOG_STAGE_DATA(stage);
GLvector4f *input;
- if (!ctx->Fog.Enabled || ctx->VertexProgram._Current)
- return GL_TRUE;
+ if (!ctx->Fog.Enabled)
+ return GL_TRUE;
- if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) {
+ if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT && !ctx->VertexProgram._Current) {
GLuint i;
GLfloat *coord;
/* Fog is computed from vertex or fragment Z values */
diff --git a/src/mesa/vbo/vbo_save_loopback.c b/src/mesa/vbo/vbo_save_loopback.c
index f2cef698fb..92ca4ea95d 100644
--- a/src/mesa/vbo/vbo_save_loopback.c
+++ b/src/mesa/vbo/vbo_save_loopback.c
@@ -25,9 +25,6 @@
*
**************************************************************************/
-#include "swrast_setup/swrast_setup.h"
-#include "swrast/swrast.h"
-#include "tnl/tnl.h"
#include "main/context.h"
#include "main/glheader.h"
#include "main/enums.h"