--- mesa-7.2.orig/autogen.sh +++ mesa-7.2/autogen.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +srcdir=`dirname "$0"` +test -z "$srcdir" && srcdir=. + +SRCDIR=`(cd "$srcdir" && pwd)` +ORIGDIR=`pwd` + +if test "x$SRCDIR" != "x$ORIGDIR"; then + echo "Mesa cannot be built when srcdir != builddir" 1>&2 + exit 1 +fi + +autoreconf -v --install || exit 1 + +"$srcdir"/configure "$@" --- mesa-7.2.orig/include/GL/miniglx.h +++ mesa-7.2/include/GL/miniglx.h @@ -0,0 +1,482 @@ +/* + * Mesa 3-D graphics library + * Version: 6.1 + * + * Copyright (C) 1999-2004 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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 miniglx.h + * \brief Mini GLX interface functions. + * \author Brian Paul + * + * See comments miniglx.c for more information. + */ + +#ifndef MINIGLX_H +#define MINIGLX_H + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * \name Replacement Xlib/GLX types + */ +/*@{*/ +/** + * \brief Boolean type. + * + * It can have the values #True or #False. + */ +#ifndef MINIGLX_NO_XTYPES +typedef int Bool; +#endif +typedef int MINI_Bool; + +/** + * \brief Color map. + * + * Alias for private ::MiniGLXColormapRec structure. + */ +typedef struct MiniGLXColormapRec *MINI_Colormap; +#ifndef MINIGLX_NO_XTYPES +typedef struct MiniGLXColormapRec *Colormap; +#endif + +/** + * \brief Window attributes. + */ +typedef struct MiniGLXSetWindowAttributesRec { + int background_pixel; /**< \brief background pixel */ + int border_pixel; /**< \brief border pixel value */ + MINI_Colormap colormap; /**< \brief color map to be associated with window */ + int event_mask; /**< \brief set of events that should be saved */ +} XSetWindowAttributes; + +/** + * \brief Visual. + * + * Alias for the private ::MiniGLXVisualRec structure. + * + * \sa \ref datatypes. + */ +typedef struct MiniGLXVisualRec Visual; + +/** + * \brief Visual information. + * + * \sa \ref datatypes. + */ +#ifndef MINIGLX_NO_XTYPES +typedef unsigned long VisualID; +#endif +typedef unsigned long MINI_VisualID; +typedef struct MiniGLXXVisualInfoRec { + Visual *visual; /**< \brief pointer to the GLX Visual */ + MINI_VisualID visualid; /**< \brief visual ID */ + int screen; /**< \brief screen number */ + int depth; /**< \brief bit depth */ +#if defined(__cplusplus) || defined(c_plusplus) + int c_class; /**< \brief class */ +#else + int class; /**< \brief class */ +#endif + int bits_per_rgb; /**< \brief total bits per pixel */ +} XVisualInfo; + +/** + * \brief GLX Frame Buffer Configuration (for pbuffers) + * \sa \ref datatypes. + */ +typedef struct MiniGLXFBConfigRec { + XVisualInfo *visInfo; +} GLXFBConfig; + + +/** + * \brief Display handle. + * + * Alias for the private ::MiniGLXDisplayRec structure. + * + * \sa \ref datatypes. + */ +#ifndef MINIGLX_NO_XTYPES +typedef struct MiniGLXDisplayRec Display; +#endif +typedef struct MiniGLXDisplayRec MINI_Display; + +/** + * \brief Window handle. + * + * Alias for the private ::MiniGLXWindowRec structure. + * + * \sa \ref datatypes. + */ +#ifndef MINIGLX_NO_XTYPES +typedef struct MiniGLXWindowRec *Window; +#endif +typedef struct MiniGLXWindowRec *MINI_Window; + +/** + * \brief Drawable. + * + * Alias for the private ::MiniGLXWindowRec structure. + * + * For Mini GLX only the full-screen window can be used as source and + * destination in graphics operations. + * + * \sa \ref datatypes. + */ +#ifndef MINIGLX_NO_XTYPES +typedef struct MiniGLXWindowRec *Drawable; +#endif +typedef struct MiniGLXWindowRec *MINI_Drawable; + +/** + * \brief GLX drawable. + * + * Alias for the private ::MiniGLXWindowRec structure. + * + * Same as #Drawable. + * + * \sa \ref datatypes. + */ +typedef struct MiniGLXWindowRec *GLXDrawable; + +/** + * \brief GLX pbuffer. + * + * Alias for the private ::MiniGLXWindowRec structure. + * + * Same as #Drawable. + * + * \sa \ref datatypes. + */ +typedef struct MiniGLXWindowRec *GLXPbuffer; + +/** + * \brief GLX context. + * + * Alias for the private ::MiniGLXContext structure. + * + * \sa \ref datatypes. + */ +typedef struct MiniGLXContextRec *GLXContext; +/*@}*/ + + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + MINI_Bool send_event; /* true if this came from a SendEvent request */ + MINI_Display *display; /* Display the event was read from */ + MINI_Window window; + int x, y; + int width, height; + int count; /* if non-zero, at least this many more */ +} XExposeEvent; + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + MINI_Bool send_event; /* true if this came from a SendEvent request */ + MINI_Display *display; /* Display the event was read from */ + MINI_Window parent; /* parent of the window */ + MINI_Window window; /* window id of window created */ + int x, y; /* window location */ + int width, height; /* size of window */ + int border_width; /* border width */ + MINI_Bool override_redirect; /* creation should be overridden */ +} XCreateWindowEvent; + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + MINI_Bool send_event; /* true if this came from a SendEvent request */ + MINI_Display *display; /* Display the event was read from */ + MINI_Window event; + MINI_Window window; +} XDestroyWindowEvent; + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + MINI_Bool send_event; /* true if this came from a SendEvent request */ + MINI_Display *display; /* Display the event was read from */ + MINI_Window event; + MINI_Window window; + MINI_Bool from_configure; +} XUnmapEvent; + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + MINI_Bool send_event; /* true if this came from a SendEvent request */ + MINI_Display *display; /* Display the event was read from */ + MINI_Window event; + MINI_Window window; + MINI_Bool override_redirect; /* boolean, is override set... */ +} XMapEvent; + + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + MINI_Bool send_event; /* true if this came from a SendEvent request */ + MINI_Display *display; /* Display the event was read from */ + MINI_Window parent; + MINI_Window window; +} XMapRequestEvent; + +typedef union _XEvent { + int type; /* must not be changed; first element */ + XExposeEvent xexpose; + XCreateWindowEvent xcreatewindow; + XDestroyWindowEvent xdestroywindow; + XUnmapEvent xunmap; + XMapEvent xmap; + XMapRequestEvent xmaprequest; + long pad[24]; +} XEvent; + + +/** + * \name Xlib constants + */ +/*@{*/ +#define False 0 +#define True 1 +#define None 0 +#define AllocNone 0 +#define InputOutput 1 +#define ExposureMask (1L<<15) +#define StructureNotifyMask (1L<<17) +#define CWBackPixel (1L<<1) +#define CWBorderPixel (1L<<3) +#define CWEventMask (1L<<11) +#define CWColormap (1L<<13) +#define PseudoColor 3 +#define TrueColor 4 +#define VisualIDMask 0x1 +#define VisualScreenMask 0x2 +#define Expose 12 +#define CreateNotify 16 +#define DestroyNotify 17 +#define UnmapNotify 18 +#define MapNotify 19 +#define MapRequest 20 + +/*@}*/ + +/** + * \name Standard GLX tokens + */ +/*@{*/ +#define GLX_USE_GL 1 +#define GLX_BUFFER_SIZE 2 +#define GLX_LEVEL 3 +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_STEREO 6 +#define GLX_AUX_BUFFERS 7 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 +#define GLX_ACCUM_RED_SIZE 14 +#define GLX_ACCUM_GREEN_SIZE 15 +#define GLX_ACCUM_BLUE_SIZE 16 +#define GLX_ACCUM_ALPHA_SIZE 17 +#define GLX_BAD_ATTRIBUTE 1 +#define GLX_BAD_VISUAL 4 +/*@}*/ + + +/** + * \name Unique to Mini GLX + * + * At compile time, the Mini GLX interface version can be tested with the + * MINI_GLX_VERSION_1_x preprocessor tokens. + * + * \sa glXQueryVersion() + */ +/*@{*/ +/** \brief Defined if version 1.0 of Mini GLX is supported. */ +#define MINI_GLX_VERSION_1_0 1 +/** \brief Defined if version 1.1 of Mini GLX is supported. */ +#define MINI_GLX_VERSION_1_1 1 +/*@}*/ + + +/** + * \name Server-specific functions + */ +extern MINI_Display * +__miniglx_StartServer( const char *display_name ); + +extern int +__miniglx_Select( MINI_Display *dpy, int maxfd, + fd_set *rfds, fd_set *wfds, fd_set *xfds, + struct timeval *tv ); + + +/** + * \name Simulated Xlib functions + */ +/*@{*/ +extern MINI_Display * +XOpenDisplay( const char *dpy_name ); + + +extern void +XCloseDisplay( MINI_Display *display ); + +extern MINI_Window +XCreateWindow( MINI_Display *display, MINI_Window parent, int x, int y, + unsigned int width, unsigned int height, + unsigned int border_width, int depth, unsigned int winclass, + Visual *visual, unsigned long valuemask, + XSetWindowAttributes *attributes ); + +extern int +XNextEvent(MINI_Display *display, XEvent *event_return); + +extern MINI_Bool +XCheckMaskEvent( MINI_Display *dpy, long event_mask, XEvent *event_return ); + +/** + * \brief Return the root window. + * + * \param display the display handle. It is ignored by Mini GLX, but should be + * the value returned by XOpenDisplay(). + * \param screen the screen number on the host server. It is ignored by Mini + * GLX but should be zero. + * + * \return the root window. Always zero on Mini GLX. + */ +#define RootWindow(display, screen) 0 +#define DefaultScreen(dpy) 0 + +extern void +XDestroyWindow( MINI_Display *display, MINI_Window w ); + +extern void +XMapWindow( MINI_Display *display, MINI_Window w ); + +/* Should clients have access to this? + */ +extern void +XUnmapWindow( MINI_Display *display, MINI_Window w ); + +extern MINI_Colormap +XCreateColormap( MINI_Display *display, MINI_Window w, Visual *visual, int alloc ); + +extern void +XFreeColormap( MINI_Display *display, MINI_Colormap cmap ); + +extern void +XFree( void *data ); + +extern XVisualInfo * +XGetVisualInfo( MINI_Display *display, long vinfo_mask, + XVisualInfo *vinfo_template, int *nitems_return ); +/*@}*/ + + + +/** + * \name GLX functions + */ +/*@{*/ +extern XVisualInfo* +glXChooseVisual( MINI_Display *dpy, int screen, int *attribList ); + +extern int +glXGetConfig( MINI_Display *dpy, XVisualInfo *vis, int attrib, int *value ); + +extern GLXContext +glXCreateContext( MINI_Display *dpy, XVisualInfo *vis, + GLXContext shareList, MINI_Bool direct ); + +extern void +glXDestroyContext( MINI_Display *dpy, GLXContext ctx ); + +extern MINI_Bool +glXMakeCurrent( MINI_Display *dpy, GLXDrawable drawable, GLXContext ctx); + +extern void +glXSwapBuffers( MINI_Display *dpy, GLXDrawable drawable ); + +extern GLXContext +glXGetCurrentContext( void ); + +extern GLXDrawable +glXGetCurrentDrawable( void ); + +extern void +(*glXGetProcAddress(const GLubyte *procname))( void ); + +extern MINI_Bool +glXQueryVersion( MINI_Display *dpy, int *major, int *minor ); + +/* Added in MiniGLX 1.1 */ +extern GLXPbuffer +glXCreatePbuffer( MINI_Display *dpy, GLXFBConfig config, const int *attribList ); + +extern void +glXDestroyPbuffer( MINI_Display *dpy, GLXPbuffer pbuf ); + +extern GLXFBConfig * +glXChooseFBConfig( MINI_Display *dpy, int screen, const int *attribList, + int *nitems ); + +extern XVisualInfo * +glXGetVisualFromFBConfig( MINI_Display *dpy, GLXFBConfig config ); + +extern void *glXAllocateMemoryMESA(Display *dpy, int scrn, + size_t size, float readFreq, + float writeFreq, float priority); + +extern void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer); + +extern GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, + const void *pointer ); +/*@}*/ + +extern void +__glXScrEnableExtension( void *, const char * name ); + +/*@}*/ + + +#ifdef __cplusplus +} +#endif + +#endif /* MINIGLX_H */ --- mesa-7.2.orig/include/GL/directfbgl.h +++ mesa-7.2/include/GL/directfbgl.h @@ -0,0 +1,89 @@ +/* + (c) Copyright 2001 convergence integrated media GmbH. + All rights reserved. + + Written by Denis Oliver Kropp and + Andreas Hundt . + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef __DIRECTFBGL_H__ +#define __DIRECTFBGL_H__ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + +typedef struct { + int buffer_size; + int depth_size; + int stencil_size; + int aux_buffers; + + int red_size; + int green_size; + int blue_size; + int alpha_size; + + int accum_red_size; + int accum_green_size; + int accum_blue_size; + int accum_alpha_size; + + DFBBoolean double_buffer; + DFBBoolean stereo; +} DFBGLAttributes; + + +DEFINE_INTERFACE( IDirectFBGL, + + /** Context handling **/ + + /* + * Acquire the hardware lock. + */ + DFBResult (*Lock) ( + IDirectFBGL *thiz + ); + + /* + * Release the lock. + */ + DFBResult (*Unlock) ( + IDirectFBGL *thiz + ); + + /* + * Query the OpenGL attributes. + */ + DFBResult (*GetAttributes) ( + IDirectFBGL *thiz, + DFBGLAttributes *attributes + ); +) + + +#ifdef __cplusplus +} +#endif + +#endif + --- mesa-7.2.orig/include/GL/Makefile.am +++ mesa-7.2/include/GL/Makefile.am @@ -0,0 +1,43 @@ +## Process this file with automake to produce Makefile.in + +GLincludedir = $(includedir)/GL + +INC_FX = fxmesa.h +INC_GGI = ggimesa.h +INC_OSMESA = osmesa.h +INC_SVGA = svgamesa.h +INC_X11 = glx.h glxext.h glx_mangle.h xmesa.h xmesa_x.h xmesa_xf86.h +INC_GLUT = glut.h glutf90.h + +if HAVE_FX +sel_inc_fx = $(INC_FX) +endif + +if HAVE_GGI +sel_inc_ggi = $(INC_GGI) +endif + +if HAVE_OSMESA +sel_inc_osmesa = $(INC_OSMESA) +endif + +if HAVE_SVGA +sel_inc_svga = $(INC_SVGA) +endif + +if HAVE_X11 +sel_inc_x11 = $(INC_X11) +endif + +if NEED_GLUT +sel_inc_glut = $(INC_GLUT) +endif + +EXTRA_HEADERS = amesa.h dosmesa.h foomesa.h glut_h.dja mesa_wgl.h mglmesa.h \ + vms_x_fix.h wmesa.h \ + $(INC_FX) $(INC_GGI) $(INC_OSMESA) $(INC_SVGA) $(INC_X11) $(INC_GLUT) + +GLinclude_HEADERS = gl.h glext.h gl_mangle.h glu.h glu_mangle.h \ + $(sel_inc_fx) $(sel_inc_ggi) $(sel_inc_osmesa) $(sel_inc_svga) \ + $(sel_inc_x11) $(sel_inc_glut) +include $(top_srcdir)/common_rules.make --- mesa-7.2.orig/include/GL/glut_h.dja +++ mesa-7.2/include/GL/glut_h.dja @@ -0,0 +1,340 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.1 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This header file is based on the REAL glut.h by Mark J. Kilgard. + * + * The DJGPP/ALLEGRO (DJA) GLUT implementation was written by + * Bernhard Tschirren (bernie-t@geocities.com) for the sole purpose + * of compiling all the sample programs (which use GLUT). Therefore, + * is NOT AT ALL a complete version of GLUT! + */ + + +#ifndef __AGLUT_H__ +#define __AGLUT_H__ + +#include +#include + +#define GLUTCALLBACK +#define APIENTRY +#define GLUTAPI extern + +#define GLUT_RGB 0 +#define GLUT_RGBA GLUT_RGB +#define GLUT_INDEX 1 +#define GLUT_SINGLE 0 +#define GLUT_DOUBLE 2 +#define GLUT_ACCUM 4 +#define GLUT_ALPHA 8 +#define GLUT_DEPTH 16 +#define GLUT_STENCIL 32 + +/* Mouse buttons. */ +#define GLUT_LEFT_BUTTON 0 +#define GLUT_MIDDLE_BUTTON 1 +#define GLUT_RIGHT_BUTTON 2 + +/* Mouse button state. */ +#define GLUT_DOWN 0 +#define GLUT_UP 1 + +/* function keys */ +#define GLUT_KEY_F1 1 +#define GLUT_KEY_F2 2 +#define GLUT_KEY_F3 3 +#define GLUT_KEY_F4 4 +#define GLUT_KEY_F5 5 +#define GLUT_KEY_F6 6 +#define GLUT_KEY_F7 7 +#define GLUT_KEY_F8 8 +#define GLUT_KEY_F9 9 +#define GLUT_KEY_F10 10 +#define GLUT_KEY_F11 11 +#define GLUT_KEY_F12 12 + +/* directional keys */ +#define GLUT_KEY_LEFT 100 +#define GLUT_KEY_UP 101 +#define GLUT_KEY_RIGHT 102 +#define GLUT_KEY_DOWN 103 +#define GLUT_KEY_PAGE_UP 104 +#define GLUT_KEY_PAGE_DOWN 105 +#define GLUT_KEY_HOME 106 +#define GLUT_KEY_END 107 +#define GLUT_KEY_INSERT 108 + +/* Entry/exit state. */ +#define GLUT_LEFT 0 +#define GLUT_ENTERED 1 + +/* Visibility state. */ +#define GLUT_NOT_VISIBLE 0 +#define GLUT_VISIBLE 1 + +/* Color index component selection values. */ +#define GLUT_RED 0 +#define GLUT_GREEN 1 +#define GLUT_BLUE 2 + +/* Layers for use. */ +#define GLUT_NORMAL 0 +#define GLUT_OVERLAY 1 + +/* Stroke font constants (use these in GLUT program). */ +#define GLUT_STROKE_ROMAN ((void*)0) +#define GLUT_STROKE_MONO_ROMAN ((void*)1) + +/* Bitmap font constants (use these in GLUT program). */ +#define GLUT_BITMAP_9_BY_15 ((void*)2) +#define GLUT_BITMAP_8_BY_13 ((void*)3) +#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4) +#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5) +#define GLUT_BITMAP_HELVETICA_10 ((void*)6) +#define GLUT_BITMAP_HELVETICA_12 ((void*)7) +#define GLUT_BITMAP_HELVETICA_18 ((void*)8) + +/* glutGet parameters. */ +#define GLUT_WINDOW_X 100 +#define GLUT_WINDOW_Y 101 +#define GLUT_WINDOW_WIDTH 102 +#define GLUT_WINDOW_HEIGHT 103 +#define GLUT_WINDOW_BUFFER_SIZE 104 +#define GLUT_WINDOW_STENCIL_SIZE 105 +#define GLUT_WINDOW_DEPTH_SIZE 106 +#define GLUT_WINDOW_RED_SIZE 107 +#define GLUT_WINDOW_GREEN_SIZE 108 +#define GLUT_WINDOW_BLUE_SIZE 109 +#define GLUT_WINDOW_ALPHA_SIZE 110 +#define GLUT_WINDOW_ACCUM_RED_SIZE 111 +#define GLUT_WINDOW_ACCUM_GREEN_SIZE 112 +#define GLUT_WINDOW_ACCUM_BLUE_SIZE 113 +#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 114 +#define GLUT_WINDOW_DOUBLEBUFFER 115 +#define GLUT_WINDOW_RGBA 116 +#define GLUT_WINDOW_PARENT 117 +#define GLUT_WINDOW_NUM_CHILDREN 118 +#define GLUT_WINDOW_COLORMAP_SIZE 119 +#define GLUT_WINDOW_NUM_SAMPLES 120 +#define GLUT_WINDOW_STEREO 121 +#define GLUT_WINDOW_CURSOR 122 +#define GLUT_SCREEN_WIDTH 200 +#define GLUT_SCREEN_HEIGHT 201 +#define GLUT_SCREEN_WIDTH_MM 202 +#define GLUT_SCREEN_HEIGHT_MM 203 +#define GLUT_MENU_NUM_ITEMS 300 +#define GLUT_DISPLAY_MODE_POSSIBLE 400 +#define GLUT_INIT_WINDOW_X 500 +#define GLUT_INIT_WINDOW_Y 501 +#define GLUT_INIT_WINDOW_WIDTH 502 +#define GLUT_INIT_WINDOW_HEIGHT 503 +#define GLUT_INIT_DISPLAY_MODE 504 +#define GLUT_ELAPSED_TIME 700 +#define GLUT_WINDOW_FORMAT_ID 123 + +/* glutDeviceGet parameters. */ +#define GLUT_HAS_KEYBOARD 600 +#define GLUT_HAS_MOUSE 601 +#define GLUT_HAS_SPACEBALL 602 +#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603 +#define GLUT_HAS_TABLET 604 +#define GLUT_NUM_MOUSE_BUTTONS 605 +#define GLUT_NUM_SPACEBALL_BUTTONS 606 +#define GLUT_NUM_BUTTON_BOX_BUTTONS 607 +#define GLUT_NUM_DIALS 608 +#define GLUT_NUM_TABLET_BUTTONS 609 +#define GLUT_DEVICE_IGNORE_KEY_REPEAT 610 +#define GLUT_DEVICE_KEY_REPEAT 611 +#define GLUT_HAS_JOYSTICK 612 +#define GLUT_OWNS_JOYSTICK 613 +#define GLUT_JOYSTICK_BUTTONS 614 +#define GLUT_JOYSTICK_AXES 615 +#define GLUT_JOYSTICK_POLL_RATE 616 + +/* glutLayerGet parameters. */ +#define GLUT_OVERLAY_POSSIBLE 800 +#define GLUT_LAYER_IN_USE 801 +#define GLUT_HAS_OVERLAY 802 +#define GLUT_TRANSPARENT_INDEX 803 +#define GLUT_NORMAL_DAMAGED 804 +#define GLUT_OVERLAY_DAMAGED 805 + +/* glutVideoResizeGet parameters. */ +#define GLUT_VIDEO_RESIZE_POSSIBLE 900 +#define GLUT_VIDEO_RESIZE_IN_USE 901 +#define GLUT_VIDEO_RESIZE_X_DELTA 902 +#define GLUT_VIDEO_RESIZE_Y_DELTA 903 +#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904 +#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905 +#define GLUT_VIDEO_RESIZE_X 906 +#define GLUT_VIDEO_RESIZE_Y 907 +#define GLUT_VIDEO_RESIZE_WIDTH 908 +#define GLUT_VIDEO_RESIZE_HEIGHT 909 + +/* glutUseLayer parameters. */ +#define GLUT_NORMAL 0 +#define GLUT_OVERLAY 1 + +/* glutGetModifiers return mask. */ +#define GLUT_ACTIVE_SHIFT 1 +#define GLUT_ACTIVE_CTRL 2 +#define GLUT_ACTIVE_ALT 4 + +/* glutSetCursor parameters. */ +/* Basic arrows. */ +#define GLUT_CURSOR_RIGHT_ARROW 0 +#define GLUT_CURSOR_LEFT_ARROW 1 +/* Symbolic cursor shapes. */ +#define GLUT_CURSOR_INFO 2 +#define GLUT_CURSOR_DESTROY 3 +#define GLUT_CURSOR_HELP 4 +#define GLUT_CURSOR_CYCLE 5 +#define GLUT_CURSOR_SPRAY 6 +#define GLUT_CURSOR_WAIT 7 +#define GLUT_CURSOR_TEXT 8 +#define GLUT_CURSOR_CROSSHAIR 9 +/* Directional cursors. */ +#define GLUT_CURSOR_UP_DOWN 10 +#define GLUT_CURSOR_LEFT_RIGHT 11 +/* Sizing cursors. */ +#define GLUT_CURSOR_TOP_SIDE 12 +#define GLUT_CURSOR_BOTTOM_SIDE 13 +#define GLUT_CURSOR_LEFT_SIDE 14 +#define GLUT_CURSOR_RIGHT_SIDE 15 +#define GLUT_CURSOR_TOP_LEFT_CORNER 16 +#define GLUT_CURSOR_TOP_RIGHT_CORNER 17 +#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18 +#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19 +/* Inherit from parent window. */ +#define GLUT_CURSOR_INHERIT 100 +/* Blank cursor. */ +#define GLUT_CURSOR_NONE 101 +/* Fullscreen crosshair (if available). */ +#define GLUT_CURSOR_FULL_CROSSHAIR 102 + +/* GLUT initialization sub-API. */ +GLUTAPI void APIENTRY glutInit(int *argcp, char **argv); +GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode); +GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y); +GLUTAPI void APIENTRY glutInitWindowSize(int width, int height); +GLUTAPI void APIENTRY glutMainLoop(void); + +/* GLUT window sub-API. */ +GLUTAPI int APIENTRY glutCreateWindow(const char *title); +GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height); +GLUTAPI void APIENTRY glutDestroyWindow(int win); +GLUTAPI void APIENTRY glutPostRedisplay(void); +GLUTAPI void APIENTRY glutSwapBuffers(void); +GLUTAPI int APIENTRY glutGetWindow(void); +GLUTAPI void APIENTRY glutSetWindow(int win); +GLUTAPI void APIENTRY glutSetWindowTitle(const char *title); +GLUTAPI void APIENTRY glutSetIconTitle(const char *title); +GLUTAPI void APIENTRY glutPositionWindow(int x, int y); +GLUTAPI void APIENTRY glutReshapeWindow(int width, int height); +GLUTAPI void APIENTRY glutPopWindow(void); +GLUTAPI void APIENTRY glutPushWindow(void); +GLUTAPI void APIENTRY glutIconifyWindow(void); +GLUTAPI void APIENTRY glutShowWindow(void); +GLUTAPI void APIENTRY glutHideWindow(void); + +/* GLUT overlay sub-API. */ +GLUTAPI void APIENTRY glutEstablishOverlay(void); +GLUTAPI void APIENTRY glutRemoveOverlay(void); +GLUTAPI void APIENTRY glutUseLayer(GLenum layer); +GLUTAPI void APIENTRY glutPostOverlayRedisplay(void); +GLUTAPI void APIENTRY glutShowOverlay(void); +GLUTAPI void APIENTRY glutHideOverlay(void); + +/* GLUT menu sub-API. */ +GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *)(int)); +GLUTAPI void APIENTRY glutDestroyMenu(int menu); +GLUTAPI int APIENTRY glutGetMenu(void); +GLUTAPI void APIENTRY glutSetMenu(int menu); +GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value); +GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu); +GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value); +GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu); +GLUTAPI void APIENTRY glutRemoveMenuItem(int item); +GLUTAPI void APIENTRY glutAttachMenu(int button); +GLUTAPI void APIENTRY glutDetachMenu(int button); + +/* GLUT window callback sub-API. */ +GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK * func)(void)); +GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK * func)(int width, int height)); +GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK * func)(unsigned char key, int x, int y)); +GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK * func)(int button, int state, int x, int y)); +GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK * func)(int x, int y)); +GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK * func)(int x, int y)); +GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK * func)(int state)); +GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK * func)(int state)); +GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK * func)(void)); +GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK * func)(int value), int value); +GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK * func)(int state)); +GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK * func)(int key, int x, int y)); +GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK * func)(int x, int y, int z)); +GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK * func)(int x, int y, int z)); +GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK * func)(int button, int state)); +GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK * func)(int button, int state)); +GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK * func)(int dial, int value)); +GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK * func)(int x, int y)); +GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK * func)(int button, int state, int x, int y)); +GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK * func)(int status, int x, int y)); +GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK * func)(void)); +GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK * func)(int state)); + +/* GLUT color index sub-API. */ +GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue); +GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component); +GLUTAPI void APIENTRY glutCopyColormap(int win); + +/* GLUT state retrieval sub-API. */ +GLUTAPI int APIENTRY glutGet(GLenum type); +GLUTAPI int APIENTRY glutDeviceGet(GLenum type); + +/* GLUT font sub-API */ +GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character); +GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character); +GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character); +GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character); + +/* GLUT pre-built models sub-API */ +GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); +GLUTAPI void APIENTRY glutWireCube(GLdouble size); +GLUTAPI void APIENTRY glutSolidCube(GLdouble size); +GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); +GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings); +GLUTAPI void APIENTRY glutWireDodecahedron(void); +GLUTAPI void APIENTRY glutSolidDodecahedron(void); +GLUTAPI void APIENTRY glutWireTeapot(GLdouble size); +GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size); +GLUTAPI void APIENTRY glutWireOctahedron(void); +GLUTAPI void APIENTRY glutSolidOctahedron(void); +GLUTAPI void APIENTRY glutWireTetrahedron(void); +GLUTAPI void APIENTRY glutSolidTetrahedron(void); +GLUTAPI void APIENTRY glutWireIcosahedron(void); +GLUTAPI void APIENTRY glutSolidIcosahedron(void); + +#endif /* __AGLUT_H__ */ --- mesa-7.2.orig/configs/debian-osmesa-static +++ mesa-7.2/configs/debian-osmesa-static @@ -0,0 +1,9 @@ +# Configuration for building only OSMesa (static version) on Debian. + +include $(TOP)/configs/linux-osmesa-static +include $(TOP)/configs/debian-osmesa-default + +CONFIG_NAME = debian-osmesa-static + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-sparc-ultrasparc +++ mesa-7.2/configs/debian-swx11+glu-sparc-ultrasparc @@ -0,0 +1,13 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on sparc (ultrasparc-optimized). + +include $(TOP)/configs/linux-ultrasparc +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-sparc-ultrasparc + +SRC_DIRS = mesa +LIB_DIR = lib/ultrasparc/cmov + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-powerpc-603 +++ mesa-7.2/configs/debian-swx11+glu-powerpc-603 @@ -0,0 +1,13 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on powerpc (603 optimized). + +include $(TOP)/configs/linux-ppc +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-powerpc-603 + +SRC_DIRS = mesa +LIB_DIR = lib/603/cmov + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-dri-default +++ mesa-7.2/configs/debian-dri-default @@ -0,0 +1,36 @@ +# Configuration defaults for building the DRI drivers and DRI/GLX-enabled +# libGL. + +include $(TOP)/configs/debian-default + +CONFIG_NAME = debian-dri-default + +SRC_DIRS = glx/x11 mesa progs +DRIVER_DIRS = dri +PROGRAM_DIRS = xdemos +PROGS = glxdemo \ + glxgears \ + glxheads \ + glxinfo + +LIB_DIR = lib/glx + +DRI_DRIVER_INSTALL_DIR = $(INSTALL_DIR)/lib/dri +DRI_DRIVER_SEARCH_DIR = /usr/lib/dri + +DRI_DIRS = mach64 mga r128 r200 r300 radeon s3v savage tdfx trident + +ARCH_X86 = i386 amd64 + +ifneq ($(findstring $(DEB_BUILD_ARCH), $(ARCH_X86)),) + DRI_DIRS += i810 i915 i915tex i965 sis unichrome +endif + +ifeq ($(DEB_BUILD_ARCH), sparc) + DRI_DIRS += ffb +endif + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-sparc +++ mesa-7.2/configs/debian-swx11+glu-sparc @@ -0,0 +1,10 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on sparc. + +include $(TOP)/configs/linux-sparc +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-sparc + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-any +++ mesa-7.2/configs/debian-swx11+glu-any @@ -0,0 +1,9 @@ +# Configuration for building Mesa (swx11 and GLU) on the build architecture. + +include $(TOP)/configs/linux +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-any + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-amd64 +++ mesa-7.2/configs/debian-swx11+glu-amd64 @@ -0,0 +1,10 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on amd64. + +include $(TOP)/configs/linux-x86-64 +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-amd64 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-osmesa16-static +++ mesa-7.2/configs/debian-osmesa16-static @@ -0,0 +1,10 @@ +# Configuration for building a static version of OSMesa with support for 16 +# bits per color channel. + +include $(TOP)/configs/linux-osmesa16-static +include $(TOP)/configs/debian-osmesa-default + +CONFIG_NAME = debian-osmesa16-static + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-i386-i686 +++ mesa-7.2/configs/debian-swx11+glu-i386-i686 @@ -0,0 +1,14 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on i386 (i686 optimized). + +include $(TOP)/configs/linux-x86 +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-i386-i686 + +ARCH_FLAGS += -march=i686 +SRC_DIRS = mesa +LIB_DIR = lib/i686/cmov + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-indirect-hurd-i386 +++ mesa-7.2/configs/debian-indirect-hurd-i386 @@ -0,0 +1,9 @@ +# Configuration for building the DRI drivers on the build architecture. + +include $(TOP)/configs/linux-indirect +include $(TOP)/configs/debian-indirect-default + +CONFIG_NAME = debian-indirect-hurd-i386 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-osmesa16 +++ mesa-7.2/configs/debian-osmesa16 @@ -0,0 +1,10 @@ +# Configuration for building OSMesa with support for 16 bits per color +# channel. + +include $(TOP)/configs/linux-osmesa16 +include $(TOP)/configs/debian-osmesa-default + +CONFIG_NAME = debian-osmesa16 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-default +++ mesa-7.2/configs/debian-default @@ -0,0 +1,17 @@ +# Define Debian-specific defaults. + +CONFIG_NAME = debian-default + +OPT_FLAGS = -O2 -g + +# override settings in configs/linux-x86-64 +LIB_DIR = lib +EXTRA_LIB_PATH = + +SRC_DIRS = mesa +PROGRAM_DIRS = + +INSTALL_DIR = /usr + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-dri-any +++ mesa-7.2/configs/debian-dri-any @@ -0,0 +1,9 @@ +# Configuration for building the DRI drivers on the build architecture. + +include $(TOP)/configs/linux-dri +include $(TOP)/configs/debian-dri-default + +CONFIG_NAME = debian-dri-any + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-dri-optimized-default +++ mesa-7.2/configs/debian-dri-optimized-default @@ -0,0 +1,13 @@ +# Configuration defaults for CPU-optimized builds of the DRI drivers and +# DRI/GLX-enabled libGL. + +include $(TOP)/configs/debian-dri-default + +CONFIG_NAME = debian-dri-optimized-default + +# override so that the utility programs are not rebuilt with CPU-specific +# optimizations +SRC_DIRS = glx/x11 mesa + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-osmesa32-static +++ mesa-7.2/configs/debian-osmesa32-static @@ -0,0 +1,10 @@ +# Configuration for building a static version of OSMesa with support for 32 +# bits per color channel. + +include $(TOP)/configs/linux-osmesa32-static +include $(TOP)/configs/debian-osmesa-default + +CONFIG_NAME = debian-osmesa32-static + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-indirect-default +++ mesa-7.2/configs/debian-indirect-default @@ -0,0 +1,7 @@ +# Configuration defaults for building GLX-enabled libGL. + +include $(TOP)/configs/debian-dri-default + +CONFIG_NAME = debian-indirect-default + +DRI_DIRS = --- mesa-7.2.orig/configs/debian-osmesa +++ mesa-7.2/configs/debian-osmesa @@ -0,0 +1,9 @@ +# Configuration for building only OSMesa on Debian. + +include $(TOP)/configs/linux-osmesa +include $(TOP)/configs/debian-osmesa-default + +CONFIG_NAME = debian-osmesa + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-static-amd64 +++ mesa-7.2/configs/debian-swx11+glu-static-amd64 @@ -0,0 +1,10 @@ +# Configuration for building static versions of the libraries (swx11 and GLU) +# on amd64. + +include $(TOP)/configs/linux-x86-64-static +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-static-amd64 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-dri-i386 +++ mesa-7.2/configs/debian-dri-i386 @@ -0,0 +1,9 @@ +# Configuration for building the DRI drivers on i386. + +include $(TOP)/configs/linux-dri-x86 +include $(TOP)/configs/debian-dri-default + +CONFIG_NAME = debian-dri-i386 + +# vim: ft=make + --- mesa-7.2.orig/configs/linux-osmesa32-static +++ mesa-7.2/configs/linux-osmesa32-static @@ -0,0 +1,13 @@ +# Configuration for 32 bits/channel OSMesa library on Linux + +include $(TOP)/configs/linux-osmesa32 + +CONFIG_NAME = linux-osmesa32-static + +# Compiler and flags +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Library names +OSMESA_LIB_NAME = lib$(OSMESA_LIB).a + --- mesa-7.2.orig/configs/default-bp +++ mesa-7.2/configs/default-bp @@ -0,0 +1,75 @@ +# Default/template configuration + +# This is included by other config files which may override some +# of these variables. + +CONFIG_NAME = default + +# Version info +MESA_MAJOR=6 +MESA_MINOR=3 +MESA_TINY=0 + +# external projects +#DRM_SOURCE_PATH=$(TOP)/../drm +DRM_SOURCE_PATH=/home/projects/DRI-freedesktop/drm + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -O +CXXFLAGS = -O +GLU_CFLAGS = + +# Misc tools and flags +MKLIB_OPTIONS = +MKDEP = makedepend +MKDEP_OPTIONS = -fdepend +MAKE = make + +# Library names (base name) +GL_LIB = GL +GLU_LIB = GLU +GLUT_LIB = glut +GLW_LIB = GLw +OSMESA_LIB = OSMesa + + +# Library names (actual file names) +GL_LIB_NAME = lib$(GL_LIB).so +GLU_LIB_NAME = lib$(GLU_LIB).so +GLUT_LIB_NAME = lib$(GLUT_LIB).so +GLW_LIB_NAME = lib$(GLW_LIB).so +OSMESA_LIB_NAME = lib$(OSMesa).so + + +# Optional assembly language optimization files for libGL +ASM_SOURCES = + +# GLw widget sources (Append "GLwMDrawA.c" here and add -lXm to GLW_LIB_DEPS in +# order to build the Motif widget too) +GLW_SOURCES = GLwDrawA.c + + +# Directories +LIB_DIR = $(TOP)/lib +INSTALL_PREFIX = /usr/local +SRC_DIRS = mesa glu glut/glx glw +GLU_DIRS = sgi +DRIVER_DIRS = x11 osmesa +# Which subdirs under $(TOP)/progs/ to enter: +PROGRAM_DIRS = demos redbook samples xdemos + + +# Library/program dependencies +GL_LIB_DEPS = -lX11 -lXext -lm -lpthread +OSMESA_LIB_DEPS = -L$(LIB_DIR) -l$(GL_LIB) +GLU_LIB_DEPS = -L$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXt -lXi -lm +GLW_LIB_DEPS = -L$(LIB_DIR) -l$(GL_LIB) -lXt -lX11 +APP_LIB_DEPS = -L$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm + + +# Shading language support (set to 0 or 1) +SHADING_LANGUAGE = 0 + --- mesa-7.2.orig/configs/debian-swx11+glu-default +++ mesa-7.2/configs/debian-swx11+glu-default @@ -0,0 +1,14 @@ +# Configuration defaults for building Mesa (swx11 and GLU). + +include $(TOP)/configs/debian-default + +CONFIG_NAME = debian-swx11+glu-default + +SRC_DIRS = mesa glu glw +DRIVER_DIRS = x11 + +GLW_SOURCES += GLwMDrawA.c +GLW_LIB_DEPS += -lXm + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-ppc64 +++ mesa-7.2/configs/debian-swx11+glu-ppc64 @@ -0,0 +1,11 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on ppc64. + +include $(TOP)/configs/debian-swx11+glu-any + +CONFIG_NAME = debian-swx11+glu-ppc64 + +LIB_DIR = lib64 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-static-any +++ mesa-7.2/configs/debian-swx11+glu-static-any @@ -0,0 +1,10 @@ +# Configuration for building static versions of the libraries (swx11 and GLU) +# on the build architecture. + +include $(TOP)/configs/linux-static +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-static-any + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-osmesa-default +++ mesa-7.2/configs/debian-osmesa-default @@ -0,0 +1,10 @@ +# Configuration defaults for building OSMesa. + +include $(TOP)/configs/debian-default + +CONFIG_NAME = debian-osmesa-default + +DRIVER_DIRS = osmesa + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-dri-amd64 +++ mesa-7.2/configs/debian-dri-amd64 @@ -0,0 +1,9 @@ +# Configuration for building the DRI drivers on i386. + +include $(TOP)/configs/linux-dri-x86-64 +include $(TOP)/configs/debian-dri-default + +CONFIG_NAME = debian-dri-amd64 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-i386 +++ mesa-7.2/configs/debian-swx11+glu-i386 @@ -0,0 +1,10 @@ +# Configuration for building Mesa (swx11 and GLU) with runtime-detected +# assembler optimizations on i386. + +include $(TOP)/configs/linux-x86 +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-i386 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-static-ppc64 +++ mesa-7.2/configs/debian-swx11+glu-static-ppc64 @@ -0,0 +1,11 @@ +# Configuration for building static versions of the libraries (swx11 and GLU) +# on ppc64. + +include $(TOP)/configs/debian-swx11+glu-static-any + +CONFIG_NAME = debian-swx11+glu-static-ppc64 + +LIB_DIR = lib64 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-osmesa32 +++ mesa-7.2/configs/debian-osmesa32 @@ -0,0 +1,10 @@ +# Configuration for building OSMesa with support for 32 bits per color +# channel. + +include $(TOP)/configs/linux-osmesa32 +include $(TOP)/configs/debian-osmesa-default + +CONFIG_NAME = debian-osmesa32 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-swx11+glu-alpha-ev5 +++ mesa-7.2/configs/debian-swx11+glu-alpha-ev5 @@ -0,0 +1,12 @@ +# Configuration for building Mesa (swx11 and GLU) on alpha (ev5 optimized). + +include $(TOP)/configs/linux-alpha +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-alpha-ev5 + +SRC_DIRS = mesa +LIB_DIR = lib/ev5/cmov + +# vim: ft=make + --- mesa-7.2.orig/configs/autoconf +++ mesa-7.2/configs/autoconf @@ -0,0 +1,107 @@ +# Autoconf configuration + +# Pull in the defaults +include $(TOP)/configs/default + +# This is generated by configure +CONFIG_NAME = autoconf + +# Compiler and flags +CC = gcc +CXX = g++ +OPT_FLAGS = +ARCH_FLAGS = +ASM_FLAGS = -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM +PIC_FLAGS = -fPIC +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -DPTHREADS -DHAVE_POSIX_MEMALIGN -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS -DGLX_DIRECT_RENDERING +CFLAGS = -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing \ + $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES) +CXXFLAGS = -g -O2 -Wall -fno-strict-aliasing \ + $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) +LDFLAGS = +EXTRA_LIB_PATH = + +# Assembler +ASM_SOURCES = $(X86_SOURCES) +ASM_API = $(X86_API) + +# Misc tools and flags +MAKE = make +SHELL = /bin/bash +MKLIB_OPTIONS = +MKDEP = /usr/bin/makedepend +MKDEP_OPTIONS = -fdepend -I/usr/lib/gcc/i486-linux-gnu/4.3.2/include + +# Python and flags (generally only needed by the developers) +PYTHON2 = python +PYTHON_FLAGS = -t -O -O + +# Library names (base name) +GL_LIB = GL +GLU_LIB = GLU +GLUT_LIB = glut +GLW_LIB = GLw +OSMESA_LIB = OSMesa + +# Library names (actual file names) +GL_LIB_NAME = lib$(GL_LIB).so +GLU_LIB_NAME = lib$(GLU_LIB).so +GLUT_LIB_NAME = lib$(GLUT_LIB).so +GLW_LIB_NAME = lib$(GLW_LIB).so +OSMESA_LIB_NAME = lib$(OSMESA_LIB).so + +# Directories to build +LIB_DIR = lib +SRC_DIRS = glx/x11 mesa glu glw glut/glx +GLU_DIRS = sgi +DRIVER_DIRS = dri +# Which subdirs under $(TOP)/progs/ to enter: +PROGRAM_DIRS = xdemos demos redbook samples glsl + +# Driver specific build vars +DRI_DIRS = i965 +WINDOW_SYSTEM = dri +USING_EGL = 0 + +# Dependencies +X11_INCLUDES = + +# GLw motif setup +GLW_SOURCES = GLwDrawA.c +MOTIF_CFLAGS = + +# Library/program dependencies +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes -ldrm -lm -lpthread -ldl +OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) \ + $(EXTRA_LIB_PATH) +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) \ + $(EXTRA_LIB_PATH) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) \ + $(EXTRA_LIB_PATH) -lX11 -lXmu -lXi -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) \ + $(EXTRA_LIB_PATH) -lXt -lX11 -lSM -lICE +APP_LIB_DEPS = $(EXTRA_LIB_PATH) -lm + +# DRI dependencies +DRI_LIB_DEPS = $(EXTRA_LIB_PATH) -ldrm -lexpat -lm -lpthread -ldl +LIBDRM_CFLAGS = -I/usr/include/drm +LIBDRM_LIB = -ldrm +DRI2PROTO_CFLAGS = +EXPAT_INCLUDES = + +# Autoconf directories +prefix = /usr/local +exec_prefix = ${prefix} +libdir = ${exec_prefix}/lib +includedir = ${prefix}/include + +# Installation directories (for make install) +INSTALL_DIR = $(prefix) +INSTALL_LIB_DIR = $(libdir) +INSTALL_INC_DIR = $(includedir) + +# DRI installation directories +DRI_DRIVER_INSTALL_DIR = ${libdir}/dri + +# Where libGL will look for DRI hardware drivers +DRI_DRIVER_SEARCH_DIR = $(DRI_DRIVER_INSTALL_DIR) --- mesa-7.2.orig/configs/debian-swx11+glu-static-i386 +++ mesa-7.2/configs/debian-swx11+glu-static-i386 @@ -0,0 +1,10 @@ +# Configuration for building static versions of the libraries (swx11 and GLU) +# on i386. + +include $(TOP)/configs/linux-x86-static +include $(TOP)/configs/debian-swx11+glu-default + +CONFIG_NAME = debian-swx11+glu-static-i386 + +# vim: ft=make + --- mesa-7.2.orig/configs/debian-dri-i386-i686 +++ mesa-7.2/configs/debian-dri-i386-i686 @@ -0,0 +1,14 @@ +# Configuration for building the DRI drivers on i386. + +include $(TOP)/configs/linux-dri-x86 +include $(TOP)/configs/debian-dri-optimized-default + +CONFIG_NAME = debian-dri-i386-i686 + +ARCH_FLAGS = -march=i686 +LIB_DIR = lib/glx/i686/cmov + +DRI_DRIVER_INSTALL_DIR = $(INSTALL_DIR)/lib/dri/i686/cmov + +# vim: ft=make + --- mesa-7.2.orig/configs/linux-osmesa-static +++ mesa-7.2/configs/linux-osmesa-static @@ -0,0 +1,15 @@ +# Configuration for building only libOSMesa on Linux, no Xlib driver +# This doesn't really have any Linux dependencies, so it should be usable +# on other (gcc-based) systems. + +include $(TOP)/configs/linux-osmesa + +CONFIG_NAME = linux-osmesa-static + +# Compiler and flags +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Library names +OSMESA_LIB_NAME = lib$(OSMESA_LIB).a + --- mesa-7.2.orig/.gitattributes +++ mesa-7.2/.gitattributes @@ -0,0 +1,4 @@ +*.dsp -crlf +*.dsw -crlf +*.sln -crlf +*.vcproj -crlf --- mesa-7.2.orig/bin/confdiff.sh +++ mesa-7.2/bin/confdiff.sh @@ -0,0 +1,48 @@ +#!/bin/bash -e + +usage() +{ + echo "Usage: $0 " + echo "Highlight differences between Mesa configs" + echo "Example:" + echo " $0 linux linux-x86" +} + +die() +{ + echo "$@" >&2 + return 1 +} + +case "$1" in +-h|--help) usage; exit 0;; +esac + +[ $# -lt 2 ] && die 2 targets needed. See $0 --help +target1=$1 +target2=$2 + +topdir=$(cd "`dirname $0`"/..; pwd) +cd "$topdir" + +[ -f "./configs/$target1" ] || die Missing configs/$target1 +[ -f "./configs/$target2" ] || die Missing configs/$target2 + +trap 'rm -f "$t1" "$t2"' 0 + +t1=$(mktemp) +t2=$(mktemp) + +make -f- -n -p < $t1 +TOP = . +include \$(TOP)/configs/$target1 +default: +EOF + +make -f- -n -p < $t2 +TOP = . +include \$(TOP)/configs/$target2 +default: +EOF + +diff -pu -I'^#' $t1 $t2 --- mesa-7.2.orig/bin/installmesa +++ mesa-7.2/bin/installmesa @@ -0,0 +1,74 @@ +#!/bin/sh + +# +# Simple shell script for installing Mesa's header and library files. +# If the copy commands below don't work on a particular system (i.e. the +# -f or -d flags), we may need to branch on `uname` to do the right thing. +# + + +TOP=. + +INCLUDE_DIR="/usr/local/include" +LIB_DIR="/usr/local/lib" + +if [ "x$#" = "x0" ] ; then +echo +echo "***** Mesa installation - You may need root privileges to do this *****" +echo +echo "Default directory for header files is:" ${INCLUDE_DIR} +echo "Enter new directory or press to accept this default." + +read INPUT +if [ "x${INPUT}" != "x" ] ; then + INCLUDE_DIR=${INPUT} +fi + +echo +echo "Default directory for library files is:" ${LIB_DIR} +echo "Enter new directory or press to accept this default." + +read INPUT +if [ "x${INPUT}" != "x" ] ; then + LIB_DIR=${INPUT} +fi + +echo +echo "About to install Mesa header files (GL/*.h) in: " ${INCLUDE_DIR}/GL +echo "and Mesa library files (libGL.*, etc) in: " ${LIB_DIR} +echo "Press to continue, or -C to abort." + +read INPUT + +else +INCLUDE_DIR=$1/include +LIB_DIR=$1/lib +fi + +# flags: +# -f = force +# -d = preserve symlinks (does not work on BSD) + +if [ `uname` = "FreeBSD" ] ; then + CP_FLAGS="-f" +elif [ `uname` = "Darwin" ] ; then + CP_FLAGS="-f" +elif [ `uname` = "AIX" ] ; then + CP_FLAGS="-fh" +else + CP_FLAGS="-fd" +fi + + +set -v + +mkdir -p ${INCLUDE_DIR} +mkdir -p ${INCLUDE_DIR}/GL +# NOT YET: mkdir -p ${INCLUDE_DIR}/GLES +mkdir -p ${LIB_DIR} +cp -f ${TOP}/include/GL/*.h ${INCLUDE_DIR}/GL +cp -f ${TOP}/src/glw/*.h ${INCLUDE_DIR}/GL +# NOT YET: cp -f ${TOP}/include/GLES/*.h ${INCLUDE_DIR}/GLES +cp ${CP_FLAGS} ${TOP}/lib*/lib* ${LIB_DIR} + +echo "Done." --- mesa-7.2.orig/src/egl/drivers/demo/Makefile +++ mesa-7.2/src/egl/drivers/demo/Makefile @@ -0,0 +1,32 @@ +# src/egl/drivers/demo/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + + +INCLUDE_DIRS = -I$(TOP)/include -I$(TOP)/src/egl/main + + +SOURCES = demo.c + +OBJECTS = $(SOURCES:.c=.o) + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: $(TOP)/$(LIB_DIR)/demodriver.so + + +$(TOP)/$(LIB_DIR)/demodriver.so: $(OBJECTS) + $(MKLIB) -o demodriver.so -noprefix -linker '$(CC)' \ + -ldflags '$(LDFLAGS)' -install $(TOP)/$(LIB_DIR) \ + $(OBJECTS) + + + +clean: + -rm -f *.o + -rm -f *.so --- mesa-7.2.orig/src/egl/drivers/demo/demo.c +++ mesa-7.2/src/egl/drivers/demo/demo.c @@ -0,0 +1,316 @@ +/* + * Sample driver: Demo + */ + +#include +#include +#include +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglglobals.h" +#include "eglmode.h" +#include "eglscreen.h" +#include "eglsurface.h" + + +/** + * Demo driver-specific driver class derived from _EGLDriver + */ +typedef struct demo_driver +{ + _EGLDriver Base; /* base class/object */ + GLuint DemoStuff; +} DemoDriver; + +#define DEMO_DRIVER(D) ((DemoDriver *) (D)) + + +/** + * Demo driver-specific surface class derived from _EGLSurface + */ +typedef struct demo_surface +{ + _EGLSurface Base; /* base class/object */ + GLuint DemoStuff; +} DemoSurface; + + +/** + * Demo driver-specific context class derived from _EGLContext + */ +typedef struct demo_context +{ + _EGLContext Base; /* base class/object */ + GLuint DemoStuff; +} DemoContext; + + + +static EGLBoolean +demoInitialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLScreen *scrn; + EGLint i; + + /* Create a screen */ + scrn = calloc(1, sizeof(*scrn)); + _eglAddScreen(disp, scrn); + + /* Create the screen's modes - silly example */ + _eglAddNewMode(scrn, 1600, 1200, 72 * 1000, "1600x1200-72"); + _eglAddNewMode(scrn, 1280, 1024, 72 * 1000, "1280x1024-70"); + _eglAddNewMode(scrn, 1280, 1024, 70 * 1000, "1280x1024-70"); + _eglAddNewMode(scrn, 1024, 768, 72 * 1000, "1024x768-72"); + + /* Create the display's visual configs - silly example */ + for (i = 0; i < 4; i++) { + _EGLConfig config; + _eglInitConfig(&config, i + 1); + _eglSetConfigAttrib(&config, EGL_RED_SIZE, 8); + _eglSetConfigAttrib(&config, EGL_GREEN_SIZE, 8); + _eglSetConfigAttrib(&config, EGL_BLUE_SIZE, 8); + _eglSetConfigAttrib(&config, EGL_ALPHA_SIZE, 8); + _eglSetConfigAttrib(&config, EGL_BUFFER_SIZE, 32); + if (i & 1) { + _eglSetConfigAttrib(&config, EGL_DEPTH_SIZE, 32); + } + if (i & 2) { + _eglSetConfigAttrib(&config, EGL_STENCIL_SIZE, 8); + } + _eglSetConfigAttrib(&config, EGL_SURFACE_TYPE, + (EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)); + _eglAddConfig(disp, &config); + } + + drv->Initialized = EGL_TRUE; + + *major = 1; + *minor = 0; + + return EGL_TRUE; +} + + +static EGLBoolean +demoTerminate(_EGLDriver *drv, EGLDisplay dpy) +{ + /*DemoDriver *demo = DEMO_DRIVER(dpy);*/ + free(drv); + return EGL_TRUE; +} + + +static DemoContext * +LookupDemoContext(EGLContext ctx) +{ + _EGLContext *c = _eglLookupContext(ctx); + return (DemoContext *) c; +} + + +static DemoSurface * +LookupDemoSurface(EGLSurface surf) +{ + _EGLSurface *s = _eglLookupSurface(surf); + return (DemoSurface *) s; +} + + + +static EGLContext +demoCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) +{ + _EGLConfig *conf; + DemoContext *c; + int i; + + conf = _eglLookupConfig(drv, dpy, config); + if (!conf) { + _eglError(EGL_BAD_CONFIG, "eglCreateContext"); + return EGL_NO_CONTEXT; + } + + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + /* no attribs defined for now */ + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext"); + return EGL_NO_CONTEXT; + } + } + + c = (DemoContext *) calloc(1, sizeof(DemoContext)); + if (!c) + return EGL_NO_CONTEXT; + + _eglInitContext(drv, dpy, &c->Base, config, attrib_list); + c->DemoStuff = 1; + printf("demoCreateContext\n"); + + /* generate handle and insert into hash table */ + _eglSaveContext(&c->Base); + assert(c->Base.Handle); + + return c->Base.Handle; +} + + +static EGLSurface +demoCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) +{ + int i; + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + /* no attribs at this time */ + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglCreateWindowSurface"); + return EGL_NO_SURFACE; + } + } + printf("eglCreateWindowSurface()\n"); + /* XXX unfinished */ + + return EGL_NO_SURFACE; +} + + +static EGLSurface +demoCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) +{ + _EGLConfig *conf; + EGLint i; + + conf = _eglLookupConfig(drv, dpy, config); + if (!conf) { + _eglError(EGL_BAD_CONFIG, "eglCreatePixmapSurface"); + return EGL_NO_SURFACE; + } + + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + /* no attribs at this time */ + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglCreatePixmapSurface"); + return EGL_NO_SURFACE; + } + } + + if (conf->Attrib[EGL_SURFACE_TYPE - FIRST_ATTRIB] == 0) { + _eglError(EGL_BAD_MATCH, "eglCreatePixmapSurface"); + return EGL_NO_SURFACE; + } + + printf("eglCreatePixmapSurface()\n"); + return EGL_NO_SURFACE; +} + + +static EGLSurface +demoCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) +{ + DemoSurface *surf = (DemoSurface *) calloc(1, sizeof(DemoSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, &surf->Base, EGL_PBUFFER_BIT, + config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + /* a real driver would allocate the pbuffer memory here */ + + return surf->Base.Handle; +} + + +static EGLBoolean +demoDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +{ + DemoSurface *fs = LookupDemoSurface(surface); + _eglRemoveSurface(&fs->Base); + if (fs->Base.IsBound) { + fs->Base.DeletePending = EGL_TRUE; + } + else { + free(fs); + } + return EGL_TRUE; +} + + +static EGLBoolean +demoDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) +{ + DemoContext *fc = LookupDemoContext(context); + _eglRemoveContext(&fc->Base); + if (fc->Base.IsBound) { + fc->Base.DeletePending = EGL_TRUE; + } + else { + free(fc); + } + return EGL_TRUE; +} + + +static EGLBoolean +demoMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context) +{ + /*DemoDriver *demo = DEMO_DRIVER(dpy);*/ + DemoSurface *readSurf = LookupDemoSurface(read); + DemoSurface *drawSurf = LookupDemoSurface(draw); + DemoContext *ctx = LookupDemoContext(context); + EGLBoolean b; + + b = _eglMakeCurrent(drv, dpy, draw, read, context); + if (!b) + return EGL_FALSE; + + /* XXX this is where we'd do the hardware context switch */ + (void) drawSurf; + (void) readSurf; + (void) ctx; + + printf("eglMakeCurrent()\n"); + return EGL_TRUE; +} + + +/** + * The bootstrap function. Return a new DemoDriver object and + * plug in API functions. + */ +_EGLDriver * +_eglMain(_EGLDisplay *dpy) +{ + DemoDriver *demo; + + demo = (DemoDriver *) calloc(1, sizeof(DemoDriver)); + if (!demo) { + return NULL; + } + + /* First fill in the dispatch table with defaults */ + _eglInitDriverFallbacks(&demo->Base); + /* then plug in our Demo-specific functions */ + demo->Base.API.Initialize = demoInitialize; + demo->Base.API.Terminate = demoTerminate; + demo->Base.API.CreateContext = demoCreateContext; + demo->Base.API.MakeCurrent = demoMakeCurrent; + demo->Base.API.CreateWindowSurface = demoCreateWindowSurface; + demo->Base.API.CreatePixmapSurface = demoCreatePixmapSurface; + demo->Base.API.CreatePbufferSurface = demoCreatePbufferSurface; + demo->Base.API.DestroySurface = demoDestroySurface; + demo->Base.API.DestroyContext = demoDestroyContext; + + /* enable supported extensions */ + demo->Base.Extensions.MESA_screen_surface = EGL_TRUE; + demo->Base.Extensions.MESA_copy_context = EGL_TRUE; + + return &demo->Base; +} --- mesa-7.2.orig/src/egl/drivers/dri/Makefile +++ mesa-7.2/src/egl/drivers/dri/Makefile @@ -0,0 +1,62 @@ +# src/egl/drivers/dri/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + + +### Include directories +INCLUDE_DIRS = \ + -I. \ + -I/usr/include \ + -I/usr/include/drm \ + -I$(TOP)/include \ + -I$(TOP)/include/GL/internal \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/mesa/glapi \ + -I$(TOP)/src/mesa/math \ + -I$(TOP)/src/mesa/transform \ + -I$(TOP)/src/mesa/shader \ + -I$(TOP)/src/mesa/swrast \ + -I$(TOP)/src/mesa/swrast_setup \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/src/mesa/drivers/dri/common + + +HEADERS = egldri.h + +SOURCES = egldri.c + +OBJECTS = $(SOURCES:.c=.o) + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: depend library Makefile + + +# EGLdri Library +library: $(TOP)/$(LIB_DIR)/libEGLdri.so + +$(TOP)/$(LIB_DIR)/libEGLdri.so: $(OBJECTS) + $(MKLIB) -o EGLdri -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major 1 -minor 0 \ + -install $(TOP)/$(LIB_DIR) -ldl $(OBJECTS) + + +clean: + -rm -f *.o + -rm -f *.so + +depend: $(SOURCES) $(HEADERS) + @ echo "running $(MKDEP)" + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \ + $(SOURCES) $(HEADERS) > /dev/null + +include depend +# DO NOT DELETE + --- mesa-7.2.orig/src/egl/drivers/dri/egldri.h +++ mesa-7.2/src/egl/drivers/dri/egldri.h @@ -0,0 +1,113 @@ +#ifndef EGLDRI_INCLUDED +#define EGLDRI_INCLUDED + +#include "egldisplay.h" +#include "eglscreen.h" +#include "eglsurface.h" +#include "eglcontext.h" +#include "mtypes.h" +#include "dri_util.h" +#include "drm_sarea.h" + +/** + * dri display-specific driver class derived from _EGLDisplay + */ +typedef struct dri_display +{ + _EGLDisplay Base; /* base class/object */ + void *pFB; + int drmFD; /**< \brief DRM device file descriptor */ + int minor; + unsigned long hFrameBuffer; + + int virtualWidth; + int virtualHeight; + int fbSize; + int bpp; + int cpp; + int card_type; + int SAREASize; + drm_sarea_t *pSAREA; + unsigned int serverContext; /**< \brief DRM context only active on server */ + unsigned long FBStart; /**< \brief physical address of the framebuffer */ + void *driverClientMsg; + int driverClientMsgSize; + int chipset; + void *driverPrivate; + drm_magic_t magic; + + __DRIscreen driScreen; + +} driDisplay; + + +/** + * dri driver-specific screen class derived from _EGLScreen + */ +typedef struct dri_screen +{ + _EGLScreen Base; + char fb[NAME_MAX]; /** the screen name, like "fb0" */ +} driScreen; + + +/** + * dri driver-specific surface class derived from _EGLSurface + */ +typedef struct dri_surface +{ + _EGLSurface Base; /* base class/object */ + __DRIdrawable drawable; +} driSurface; + + +/** + * dri driver-specific context class derived from _EGLContext + */ +typedef struct dri_context +{ + _EGLContext Base; /* base class/object */ + __DRIcontext driContext; /**< \brief context dependent methods */ +} driContext; + + + +static inline driDisplay * +Lookup_driDisplay(EGLDisplay dpy) +{ + _EGLDisplay *d = _eglLookupDisplay(dpy); + return (driDisplay *) d; +} + + +static inline driScreen * +Lookup_driScreen(EGLDisplay dpy, EGLScreenMESA screen) +{ + _EGLScreen *s = _eglLookupScreen(dpy, screen); + return (driScreen *) s; +} + + +static inline driContext * +Lookup_driContext(EGLContext ctx) +{ + _EGLContext *c = _eglLookupContext(ctx); + return (driContext *) c; +} + + +static inline driSurface * +Lookup_driSurface(EGLSurface surf) +{ + _EGLSurface *s = _eglLookupSurface(surf); + return (driSurface *) s; +} + +extern void _eglDRIInitDriverFallbacks(_EGLDriver *drv); +extern EGLBoolean _eglDRIShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface surface, EGLModeMESA m); +extern EGLBoolean _eglDRIInitialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor); +extern EGLBoolean _eglDRIGetDisplayInfo(driDisplay *dpy); +extern EGLBoolean _eglDRICreateDisplay(driDisplay *dpy, __DRIframebuffer *framebuffer); +extern EGLBoolean _eglDRICreateScreens(driDisplay *dpy); + +#endif /* EGLDRI_INCLUDED */ --- mesa-7.2.orig/src/egl/drivers/dri/egldri.c +++ mesa-7.2/src/egl/drivers/dri/egldri.c @@ -0,0 +1,1138 @@ +/** + * Generic EGL driver for DRI. + * + * This file contains all the code needed to interface DRI-based drivers + * with libEGL. + * + * There's a lot of dependencies on fbdev and the /sys/ filesystem. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "egldriver.h" +#include "egldisplay.h" +#include "eglcontext.h" +#include "eglconfig.h" +#include "eglsurface.h" +#include "eglscreen.h" +#include "eglglobals.h" +#include "egllog.h" +#include "eglmode.h" + +#include "egldri.h" + +const char *sysfs = "/sys/class"; +#define None 0 +static const int empty_attribute_list[1] = { None }; + + +/** + * The bootstrap function. + * Return a new driDriver object and plug in API functions. + * This function, in turn, loads a specific DRI driver (ex: r200_dri.so). + */ +_EGLDriver * +_eglMain(_EGLDisplay *dpy) +{ + int length; + char path[NAME_MAX]; + struct dirent *dirent; +#if 1 + FILE *file; +#endif + DIR *dir; + _EGLDriver *driver = NULL;; + + snprintf(path, sizeof(path), "%s/drm", sysfs); + if (!(dir = opendir(path))) { + _eglLog(_EGL_WARNING, "%s DRM devices not found.", path); + return EGL_FALSE; + } + while ((dirent = readdir(dir))) { + + if (strncmp(&dirent->d_name[0], "card", 4) != 0) + continue; + if (strcmp(&dirent->d_name[4], &dpy->Name[1]) != 0) + continue; + + snprintf(path, sizeof(path), "%s/drm/card%s/dri_library_name", sysfs, &dpy->Name[1]); + _eglLog(_EGL_INFO, "Opening %s", path); +#if 1 + file = fopen(path, "r"); + if (!file) { + _eglLog(_EGL_WARNING, "Failed to open %s", path); + return NULL; + } + fgets(path, sizeof(path), file); + fclose(file); +#else + strcpy(path, "r200\n"); +#endif + if ((length = strlen(path)) > 0) + path[length - 1] = '\0'; /* remove the trailing newline from sysfs */ + strncat(path, "_dri", sizeof(path)); + + driver = _eglOpenDriver(dpy, path); + + break; + } + closedir(dir); + + return driver; +} + + +/** + * Called by eglCreateContext via drv->API.CreateContext(). + */ +static EGLContext +_eglDRICreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + EGLContext share_list, const EGLint *attrib_list) +{ + driDisplay *disp = Lookup_driDisplay(dpy); + driContext *c, *share; + void *sharePriv; + _EGLConfig *conf; + __GLcontextModes visMode; + + c = (driContext *) calloc(1, sizeof(*c)); + if (!c) + return EGL_NO_CONTEXT; + + if (!_eglInitContext(drv, dpy, &c->Base, config, attrib_list)) { + free(c); + return EGL_NO_CONTEXT; + } + + if (share_list != EGL_NO_CONTEXT) { + _EGLContext *shareCtx = _eglLookupContext(share_list); + if (!shareCtx) { + _eglError(EGL_BAD_CONTEXT, "eglCreateContext(share_list)"); + return EGL_FALSE; + } + } + share = Lookup_driContext(share_list); + if (share) + sharePriv = share->driContext.private; + else + sharePriv = NULL; + + conf = _eglLookupConfig(drv, dpy, config); + assert(conf); + _eglConfigToContextModesRec(conf, &visMode); + + c->driContext.private = disp->driScreen.createNewContext(disp, &visMode, + GLX_WINDOW_BIT, sharePriv, &c->driContext); + if (!c->driContext.private) { + free(c); + return EGL_FALSE; + } + + /* generate handle and insert into hash table */ + _eglSaveContext(&c->Base); + + return c->Base.Handle; +} + + +static EGLBoolean +_eglDRIMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, + EGLSurface read, EGLContext context) +{ + driDisplay *disp = Lookup_driDisplay(dpy); + driContext *ctx = Lookup_driContext(context); + EGLBoolean b; + + b = _eglMakeCurrent(drv, dpy, draw, read, context); + if (!b) + return EGL_FALSE; + + if (ctx) { + ctx->driContext.bindContext(disp, 0, read, draw, &ctx->driContext); + } + else { + /* what's this??? */ + /* _mesa_make_current( NULL, NULL, NULL );*/ + } + return EGL_TRUE; +} + + +static EGLSurface +_eglDRICreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) +{ + driSurface *surf; + + surf = (driSurface *) calloc(1, sizeof(*surf)); + if (!surf) { + return EGL_NO_SURFACE; + } + + if (!_eglInitSurface(drv, dpy, &surf->Base, EGL_PBUFFER_BIT, + config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + /* create software-based pbuffer */ + { +#if 0 + GLcontext *ctx = NULL; /* this _should_ be OK */ +#endif + GLvisual visMode; + _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); + assert(conf); /* bad config should be caught earlier */ + _eglConfigToContextModesRec(conf, &visMode); + +#if 0 + surf->mesa_framebuffer = _mesa_create_framebuffer(&visMode); + _mesa_add_soft_renderbuffers(surf->mesa_framebuffer, + GL_TRUE, /* color bufs */ + visMode.haveDepthBuffer, + visMode.haveStencilBuffer, + visMode.haveAccumBuffer, + GL_FALSE, /* alpha */ + GL_FALSE /* aux */ ); + + /* set pbuffer/framebuffer size */ + _mesa_resize_framebuffer(ctx, surf->mesa_framebuffer, + surf->Base.Width, surf->Base.Height); +#endif + } + + _eglSaveSurface(&surf->Base); + + return surf->Base.Handle; +} + + +static EGLBoolean +_eglDRIDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +{ + driDisplay *disp = Lookup_driDisplay(dpy); + driSurface *fs = Lookup_driSurface(surface); + + _eglRemoveSurface(&fs->Base); + + fs->drawable.destroyDrawable(disp, fs->drawable.private); + + if (fs->Base.IsBound) { + fs->Base.DeletePending = EGL_TRUE; + } + else { + free(fs); + } + return EGL_TRUE; +} + + +static EGLBoolean +_eglDRIDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) +{ + driDisplay *disp = Lookup_driDisplay(dpy); + driContext *fc = Lookup_driContext(context); + + _eglRemoveContext(&fc->Base); + + fc->driContext.destroyContext(disp, 0, fc->driContext.private); + + if (fc->Base.IsBound) { + fc->Base.DeletePending = EGL_TRUE; + } + else { + free(fc); + } + return EGL_TRUE; +} + + +/** + * Create a drawing surface which can be directly displayed on a screen. + */ +static EGLSurface +_eglDRICreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg, + const EGLint *attrib_list) +{ + _EGLConfig *config = _eglLookupConfig(drv, dpy, cfg); + driDisplay *disp = Lookup_driDisplay(dpy); + driSurface *surface; + GLvisual visMode; + + surface = (driSurface *) calloc(1, sizeof(*surface)); + if (!surface) { + return EGL_NO_SURFACE; + } + + /* init base class, do error checking, etc. */ + if (!_eglInitSurface(drv, dpy, &surface->Base, EGL_SCREEN_BIT_MESA, + cfg, attrib_list)) { + free(surface); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(&surface->Base); + + + /* + * XXX this is where we should allocate video memory for the surface! + */ + + + /* convert EGLConfig to GLvisual */ + _eglConfigToContextModesRec(config, &visMode); + + /* Create a new DRI drawable */ + if (!disp->driScreen.createNewDrawable(disp, &visMode, surface->Base.Handle, + &surface->drawable, GLX_WINDOW_BIT, + empty_attribute_list)) { + _eglRemoveSurface(&surface->Base); + free(surface); + return EGL_NO_SURFACE; + } + + return surface->Base.Handle; +} + + +/** + * Set the fbdev colormap to a simple linear ramp. + */ +static void +_eglDRILoadColormap(driScreen *scrn) +{ + char path[ NAME_MAX ]; + char *buffer; + int i, fd; + + /* cmap attribute uses 256 lines of 16 bytes. + * Allocate one extra char for the \0 added by sprintf() + */ + if ( !( buffer = malloc( 256 * 16 + 1 ) ) ) { + _eglLog(_EGL_WARNING, "Out of memory in _eglDRILoadColormap"); + return; + } + + /* cmap attribute uses 256 lines of 16 bytes */ + for ( i = 0; i < 256; i++ ) { + int c = (i << 8) | i; /* expand to 16-bit value */ + sprintf(&buffer[i * 16], "%02x%c%04x%04x%04x\n", i, ' ', c, c, c); + } + + snprintf(path, sizeof(path), "%s/graphics/%s/color_map", sysfs, scrn->fb); + if ( !( fd = open( path, O_RDWR ) ) ) { + _eglLog(_EGL_WARNING, "Unable to open %s to set colormap", path); + return; + } + write( fd, buffer, 256 * 16 ); + close( fd ); + + free( buffer ); +} + + +/** + * Show the given surface on the named screen. + * If surface is EGL_NO_SURFACE, disable the screen's output. + * Called via eglShowSurfaceMESA(). + */ +EGLBoolean +_eglDRIShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, + EGLScreenMESA screen, + EGLSurface surface, EGLModeMESA m) +{ + driDisplay *display = Lookup_driDisplay(dpy); + driScreen *scrn = Lookup_driScreen(dpy, screen); + driSurface *surf = Lookup_driSurface(surface); + _EGLMode *mode = _eglLookupMode(dpy, m); + FILE *file; + char fname[NAME_MAX], buffer[1000]; + int temp; + + _eglLog(_EGL_DEBUG, "Enter _eglDRIShowScreenSurface"); + + /* This will check that surface, screen, and mode are valid. + * Also, it checks that the surface is large enough for the mode, etc. + */ + if (!_eglShowScreenSurfaceMESA(drv, dpy, screen, surface, m)) + return EGL_FALSE; + + assert(surface == EGL_NO_SURFACE || surf); + assert(m == EGL_NO_MODE_MESA || mode); + assert(scrn); + + /* + * Blank/unblank screen depending on if m == EGL_NO_MODE_MESA + */ + snprintf(fname, sizeof(fname), "%s/graphics/%s/blank", sysfs, scrn->fb); + file = fopen(fname, "r+"); + if (!file) { + _eglLog(_EGL_WARNING, "kernel patch?? chown all fb sysfs attrib to allow" + " write - %s\n", fname); + return EGL_FALSE; + } + snprintf(buffer, sizeof(buffer), "%d", + (m == EGL_NO_MODE_MESA ? VESA_POWERDOWN : VESA_VSYNC_SUSPEND)); + fputs(buffer, file); + fclose(file); + + if (m == EGL_NO_MODE_MESA) { + /* all done! */ + return EGL_TRUE; + } + + _eglLog(_EGL_INFO, "Setting display mode to %d x %d, %d bpp", + mode->Width, mode->Height, display->bpp); + + /* + * Set the display mode + */ + snprintf(fname, sizeof(fname), "%s/graphics/%s/mode", sysfs, scrn->fb); + file = fopen(fname, "r+"); + if (!file) { + _eglLog(_EGL_WARNING, "Failed to open %s to set mode", fname); + return EGL_FALSE; + } + /* note: nothing happens without the \n! */ + snprintf(buffer, sizeof(buffer), "%s\n", mode->Name); + fputs(buffer, file); + fclose(file); + _eglLog(_EGL_INFO, "Set mode to %s in %s", mode->Name, fname); + + /* + * Set display bpp + */ + snprintf(fname, sizeof(fname), "%s/graphics/%s/bits_per_pixel", + sysfs, scrn->fb); + file = fopen(fname, "r+"); + if (!file) { + _eglLog(_EGL_WARNING, "Failed to open %s to set bpp", fname); + return EGL_FALSE; + } + display->bpp = GET_CONFIG_ATTRIB(surf->Base.Config, EGL_BUFFER_SIZE); + display->cpp = display->bpp / 8; + snprintf(buffer, sizeof(buffer), "%d", display->bpp); + fputs(buffer, file); + fclose(file); + + /* + * Unblank display + */ + snprintf(fname, sizeof(fname), "%s/graphics/%s/blank", sysfs, scrn->fb); + file = fopen(fname, "r+"); + if (!file) { + _eglLog(_EGL_WARNING, "Failed to open %s", fname); + return EGL_FALSE; + } + snprintf(buffer, sizeof(buffer), "%d", VESA_NO_BLANKING); + fputs(buffer, file); + fclose(file); + + /* + * Set fbdev buffer virtual size to surface's size. + */ + snprintf(fname, sizeof(fname), "%s/graphics/%s/virtual_size", sysfs, scrn->fb); + file = fopen(fname, "r+"); + snprintf(buffer, sizeof(buffer), "%d,%d", surf->Base.Width, surf->Base.Height); + fputs(buffer, file); + rewind(file); + fgets(buffer, sizeof(buffer), file); + sscanf(buffer, "%d,%d", &display->virtualWidth, &display->virtualHeight); + fclose(file); + + /* + * round up pitch as needed + */ + temp = display->virtualWidth; + switch (display->bpp / 8) { + case 1: temp = (display->virtualWidth + 127) & ~127; break; + case 2: temp = (display->virtualWidth + 31) & ~31; break; + case 3: + case 4: temp = (display->virtualWidth + 15) & ~15; break; + default: + _eglLog(_EGL_WARNING, "Bad display->bpp = %d in _eglDRIShowScreenSurface"); + } + display->virtualWidth = temp; + + /* + * sanity check + */ + if (surf->Base.Width < display->virtualWidth || + surf->Base.Height < display->virtualHeight) { + /* this case _should_ have been caught at the top of this function */ + _eglLog(_EGL_WARNING, "too small of surface in _eglDRIShowScreenSurfaceMESA " + "%d x %d < %d x %d", + surf->Base.Width, + surf->Base.Height, + display->virtualWidth, + display->virtualHeight); + /* + return EGL_FALSE; + */ + } + + /* This used to be done in the _eglDRICreateScreens routine. */ + _eglDRILoadColormap(scrn); + + return EGL_TRUE; +} + + +/** + * Called by eglSwapBuffers via the drv->API.SwapBuffers() pointer. + * + * If the backbuffer is on a videocard, this is extraordinarily slow! + */ +static EGLBoolean +_eglDRISwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +{ + driSurface *drawable = Lookup_driSurface(draw); + + /* this does error checking */ + if (!_eglSwapBuffers(drv, dpy, draw)) + return EGL_FALSE; + + drawable->drawable.swapBuffers(NULL, drawable->drawable.private); + + return EGL_TRUE; +} + + +EGLBoolean +_eglDRIGetDisplayInfo(driDisplay *dpy) +{ + char path[ NAME_MAX ]; + FILE *file; + int i, rc; + drmSetVersion sv; + drm_magic_t magic; + + snprintf( path, sizeof( path ), "%s/graphics/fb%d/device/device", sysfs, dpy->minor ); + file = fopen( path, "r" ); + if (!file) { + _eglLog(_EGL_WARNING, "Unable to open %s", path); + return EGL_FALSE; + } + fgets( path, sizeof( path ), file ); + sscanf( path, "%x", &dpy->chipset ); + fclose( file ); + + sprintf(path, DRM_DEV_NAME, DRM_DIR_NAME, dpy->minor); + if ( ( dpy->drmFD = open(path, O_RDWR, 0) ) < 0 ) { + _eglLog(_EGL_WARNING, "drmOpen failed."); + return EGL_FALSE; + } + + /* Set the interface version, asking for 1.2 */ + sv.drm_di_major = 1; + sv.drm_di_minor = 2; + sv.drm_dd_major = -1; + if ((rc = drmSetInterfaceVersion(dpy->drmFD, &sv))) + return EGL_FALSE; + + /* self authorize */ + if (drmGetMagic(dpy->drmFD, &magic)) + return EGL_FALSE; + if (drmAuthMagic(dpy->drmFD, magic)) + return EGL_FALSE; + + /* Map framebuffer and SAREA */ + for (i = 0; ; i++) { + drm_handle_t handle, offset; + drmSize size; + drmMapType type; + drmMapFlags flags; + int mtrr; + + if (drmGetMap(dpy->drmFD, i, &offset, &size, &type, &flags, + &handle, &mtrr)) + break; + + if (type == DRM_FRAME_BUFFER) { + rc = drmMap( dpy->drmFD, offset, size, (drmAddressPtr) &dpy->pFB); + if (rc < 0) { + _eglLog(_EGL_WARNING, "drmMap DRM_FAME_BUFFER failed"); + return EGL_FALSE; + } + dpy->fbSize = size; + _eglLog(_EGL_INFO, "Found framebuffer size: %d", dpy->fbSize); + } + else if (type == DRM_SHM) { + rc = drmMap(dpy->drmFD, offset, size, (drmAddressPtr) &dpy->pSAREA); + if (rc < 0 ) { + _eglLog(_EGL_WARNING, "drmMap DRM_SHM failed."); + return EGL_FALSE; + } + dpy->SAREASize = SAREA_MAX; + _eglLog(_EGL_DEBUG, "mapped SAREA 0x%08lx to %p, size %d", + (unsigned long) offset, dpy->pSAREA, dpy->SAREASize ); + } + } + + if (!dpy->pFB) { + _eglLog(_EGL_WARNING, "failed to map framebuffer"); + return EGL_FALSE; + } + + if (!dpy->pSAREA) { + /* if this happens, make sure you're using the most recent DRM modules */ + _eglLog(_EGL_WARNING, "failed to map SAREA"); + return EGL_FALSE; + } + + memset( dpy->pSAREA, 0, dpy->SAREASize ); + + return EGL_TRUE; +} + + + /* Return the DRI per screen structure */ +static __DRIscreen * +__eglFindDRIScreen(__DRInativeDisplay *ndpy, int scrn) +{ + driDisplay *disp = (driDisplay *)ndpy; + return &disp->driScreen; +} + + +static GLboolean +__eglCreateContextWithConfig(__DRInativeDisplay* ndpy, int screen, + int configID, void* context, + drm_context_t * hHWContext) +{ + __DRIscreen *pDRIScreen; + __DRIscreenPrivate *psp; + + pDRIScreen = __eglFindDRIScreen(ndpy, screen); + if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) { + return GL_FALSE; + } + psp = (__DRIscreenPrivate *) pDRIScreen->private; + if (psp->fd) { + if (drmCreateContext(psp->fd, hHWContext)) { + _eglLog(_EGL_WARNING, "drmCreateContext failed."); + return GL_FALSE; + } + *(void**)context = (void*) *hHWContext; + } +#if 0 + __DRIscreen *pDRIScreen; + __DRIscreenPrivate *psp; + + pDRIScreen = __glXFindDRIScreen(dpy, screen); + if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) { + return GL_FALSE; + } + + psp = (__DRIscreenPrivate *) pDRIScreen->private; + + if (psp->fd) { + if (drmCreateContext(psp->fd, hHWContext)) { + _eglLog(_EGL_WARNING, "drmCreateContext failed."); + return GL_FALSE; + } + *(void**)contextID = (void*) *hHWContext; + } +#endif + return GL_TRUE; +} + + +static GLboolean +__eglDestroyContext( __DRInativeDisplay * ndpy, int screen, __DRIid context ) +{ + __DRIscreen *pDRIScreen; + __DRIscreenPrivate *psp; + + pDRIScreen = __eglFindDRIScreen(ndpy, screen); + if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) { + return GL_FALSE; + } + psp = (__DRIscreenPrivate *) pDRIScreen->private; + if (psp->fd) + drmDestroyContext(psp->fd, context); + + return GL_TRUE; +} + + +static GLboolean +__eglCreateDrawable(__DRInativeDisplay * ndpy, int screen, + __DRIid drawable, drm_drawable_t * hHWDrawable) +{ + __DRIscreen *pDRIScreen; + __DRIscreenPrivate *psp; + + pDRIScreen = __eglFindDRIScreen(ndpy, screen); + if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) { + return GL_FALSE; + } + psp = (__DRIscreenPrivate *) pDRIScreen->private; + if (psp->fd) { + if (drmCreateDrawable(psp->fd, hHWDrawable)) { + _eglLog(_EGL_WARNING, "drmCreateDrawable failed."); + return GL_FALSE; + } + } + return GL_TRUE; +} + + +static GLboolean +__eglDestroyDrawable( __DRInativeDisplay * ndpy, int screen, __DRIid drawable ) +{ + __DRIscreen *pDRIScreen; + __DRIscreenPrivate *psp; + + pDRIScreen = __eglFindDRIScreen(ndpy, screen); + if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) { + return GL_FALSE; + } + psp = (__DRIscreenPrivate *) pDRIScreen->private; + if (psp->fd) + drmDestroyDrawable(psp->fd, drawable); + + return GL_TRUE; +} + +static GLboolean +__eglGetDrawableInfo(__DRInativeDisplay * ndpy, int screen, __DRIid drawable, + unsigned int* index, unsigned int* stamp, + int* X, int* Y, int* W, int* H, + int* numClipRects, drm_clip_rect_t ** pClipRects, + int* backX, int* backY, + int* numBackClipRects, drm_clip_rect_t ** pBackClipRects ) +{ + __DRIscreen *pDRIScreen; + __DRIscreenPrivate *psp; + driSurface *surf = Lookup_driSurface(drawable); + + pDRIScreen = __eglFindDRIScreen(ndpy, screen); + + if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) { + return GL_FALSE; + } + psp = (__DRIscreenPrivate *) pDRIScreen->private; + *X = 0; + *Y = 0; + *W = surf->Base.Width; + *H = surf->Base.Height; + + *backX = 0; + *backY = 0; + *numBackClipRects = 0; + *pBackClipRects = NULL; + + *numClipRects = 1; + *pClipRects = malloc(sizeof(**pClipRects)); + **pClipRects = (drm_clip_rect_t){0, 0, surf->Base.Width, surf->Base.Height}; + + psp->pSAREA->drawableTable[0].stamp = 1; + *stamp = 1; +#if 0 + GLXDrawable drawable = (GLXDrawable) draw; + drm_clip_rect_t * cliprect; + Display* display = (Display*)dpy; + __DRIcontextPrivate *pcp = (__DRIcontextPrivate *)CurrentContext->driContext.private; + if (drawable == 0) { + return GL_FALSE; + } + + cliprect = (drm_clip_rect_t*) _mesa_malloc(sizeof(drm_clip_rect_t)); + cliprect->x1 = drawable->x; + cliprect->y1 = drawable->y; + cliprect->x2 = drawable->x + drawable->w; + cliprect->y2 = drawable->y + drawable->h; + + /* the drawable index is by client id */ + *index = display->clientID; + + *stamp = pcp->driScreenPriv->pSAREA->drawableTable[display->clientID].stamp; + *x = drawable->x; + *y = drawable->y; + *width = drawable->w; + *height = drawable->h; + *numClipRects = 1; + *pClipRects = cliprect; + + *backX = drawable->x; + *backY = drawable->y; + *numBackClipRects = 0; + *pBackClipRects = 0; +#endif + return GL_TRUE; +} + + +/** + * Implement \c __DRIinterfaceMethods::getProcAddress. + */ +static __DRIfuncPtr +get_proc_address(const char * proc_name) +{ + return NULL; +} + + +/** + * Destroy a linked list of \c __GLcontextModes structures created by + * \c _gl_context_modes_create. + * + * \param modes Linked list of structures to be destroyed. All structres + * in the list will be freed. + */ +static void +__egl_context_modes_destroy(__GLcontextModes *modes) +{ + while ( modes != NULL ) { + __GLcontextModes * const next = modes->next; + + free( modes ); + modes = next; + } +} + + +/** + * Allocate a linked list of \c __GLcontextModes structures. The fields of + * each structure will be initialized to "reasonable" default values. In + * most cases this is the default value defined by table 3.4 of the GLX + * 1.3 specification. This means that most values are either initialized to + * zero or \c GLX_DONT_CARE (which is -1). As support for additional + * extensions is added, the new values will be initialized to appropriate + * values from the extension specification. + * + * \param count Number of structures to allocate. + * \param minimum_size Minimum size of a structure to allocate. This allows + * for differences in the version of the + * \c __GLcontextModes stucture used in libGL and in a + * DRI-based driver. + * \returns A pointer to the first element in a linked list of \c count + * stuctures on success, or \c NULL on failure. + * + * \warning Use of \c minimum_size does \b not guarantee binary compatibility. + * The fundamental assumption is that if the \c minimum_size + * specified by the driver and the size of the \c __GLcontextModes + * structure in libGL is the same, then the meaning of each byte in + * the structure is the same in both places. \b Be \b careful! + * Basically this means that fields have to be added in libGL and + * then propagated to drivers. Drivers should \b never arbitrarilly + * extend the \c __GLcontextModes data-structure. + */ +static __GLcontextModes * +__egl_context_modes_create(unsigned count, size_t minimum_size) +{ + const size_t size = (minimum_size > sizeof( __GLcontextModes )) + ? minimum_size : sizeof( __GLcontextModes ); + __GLcontextModes * base = NULL; + __GLcontextModes ** next; + unsigned i; + + next = & base; + for ( i = 0 ; i < count ; i++ ) { + *next = (__GLcontextModes *) malloc( size ); + if ( *next == NULL ) { + __egl_context_modes_destroy( base ); + base = NULL; + break; + } + + (void) memset( *next, 0, size ); + (*next)->visualID = GLX_DONT_CARE; + (*next)->visualType = GLX_DONT_CARE; + (*next)->visualRating = GLX_NONE; + (*next)->transparentPixel = GLX_NONE; + (*next)->transparentRed = GLX_DONT_CARE; + (*next)->transparentGreen = GLX_DONT_CARE; + (*next)->transparentBlue = GLX_DONT_CARE; + (*next)->transparentAlpha = GLX_DONT_CARE; + (*next)->transparentIndex = GLX_DONT_CARE; + (*next)->xRenderable = GLX_DONT_CARE; + (*next)->fbconfigID = GLX_DONT_CARE; + (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML; + + next = & ((*next)->next); + } + + return base; +} + + +static GLboolean +__eglWindowExists(__DRInativeDisplay *dpy, __DRIid draw) +{ + return EGL_TRUE; +} + + +/** + * Get the unadjusted system time (UST). Currently, the UST is measured in + * microseconds since Epoc. The actual resolution of the UST may vary from + * system to system, and the units may vary from release to release. + * Drivers should not call this function directly. They should instead use + * \c glXGetProcAddress to obtain a pointer to the function. + * + * \param ust Location to store the 64-bit UST + * \returns Zero on success or a negative errno value on failure. + * + * \sa glXGetProcAddress, PFNGLXGETUSTPROC + * + * \since Internal API version 20030317. + */ +static int +__eglGetUST(int64_t *ust) +{ + struct timeval tv; + + if ( ust == NULL ) { + return -EFAULT; + } + + if ( gettimeofday( & tv, NULL ) == 0 ) { + ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; + return 0; + } + else { + return -errno; + } +} + +/** + * Determine the refresh rate of the specified drawable and display. + * + * \param dpy Display whose refresh rate is to be determined. + * \param drawable Drawable whose refresh rate is to be determined. + * \param numerator Numerator of the refresh rate. + * \param demoninator Denominator of the refresh rate. + * \return If the refresh rate for the specified display and drawable could + * be calculated, True is returned. Otherwise False is returned. + * + * \note This function is implemented entirely client-side. A lot of other + * functionality is required to export GLX_OML_sync_control, so on + * XFree86 this function can be called for direct-rendering contexts + * when GLX_OML_sync_control appears in the client extension string. + */ +static GLboolean +__eglGetMSCRate(__DRInativeDisplay * dpy, __DRIid drawable, + int32_t * numerator, int32_t * denominator) +{ + return EGL_TRUE; +} + + +/** + * Table of functions exported by the loader to the driver. + */ +static const __DRIinterfaceMethods interface_methods = { + get_proc_address, + + __egl_context_modes_create, + __egl_context_modes_destroy, + + __eglFindDRIScreen, + __eglWindowExists, + + __eglCreateContextWithConfig, + __eglDestroyContext, + + __eglCreateDrawable, + __eglDestroyDrawable, + __eglGetDrawableInfo, + + __eglGetUST, + __eglGetMSCRate, +}; + + +static int +__glXGetInternalVersion(void) +{ + return 20050725; +} + +static const char createNewScreenName[] = "__driCreateNewScreen_20050727"; + + +/** + * Do per-display initialization. + */ +EGLBoolean +_eglDRICreateDisplay(driDisplay *dpy, __DRIframebuffer *framebuffer) +{ + PFNCREATENEWSCREENFUNC createNewScreen; + int api_ver = __glXGetInternalVersion(); + __DRIversion ddx_version; + __DRIversion dri_version; + __DRIversion drm_version; + drmVersionPtr version; + + version = drmGetVersion( dpy->drmFD ); + 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; + } + + /* + * Get device name (like "tdfx") and the ddx version numbers. + * We'll check the version in each DRI driver's "createScreen" + * function. + */ + ddx_version.major = 4; + ddx_version.minor = 0; + ddx_version.patch = 0; + + /* + * Get the DRI X extension version. + */ + dri_version.major = 4; + dri_version.minor = 0; + dri_version.patch = 0; + + createNewScreen = ( PFNCREATENEWSCREENFUNC ) dlsym( dpy->Base.Driver->LibHandle, createNewScreenName ); + if ( !createNewScreen ) { + _eglLog(_EGL_WARNING, "Couldn't find %s function in the driver.", + createNewScreenName ); + return EGL_FALSE; + } + + dpy->driScreen.private = createNewScreen( dpy, 0, &dpy->driScreen, NULL, + &ddx_version, &dri_version, + &drm_version, framebuffer, + dpy->pSAREA, dpy->drmFD, + api_ver, + & interface_methods, + NULL); + if (!dpy->driScreen.private) + return EGL_FALSE; + + DRM_UNLOCK( dpy->drmFD, dpy->pSAREA, dpy->serverContext ); + + return EGL_TRUE; +} + + +/** + * Create all the EGL screens for the given display. + */ +EGLBoolean +_eglDRICreateScreens(driDisplay *dpy) +{ + const int numScreens = 1; /* XXX fix this someday */ + int i; + + for (i = 0; i < numScreens; i++) { + char path[ NAME_MAX ]; + FILE *file; + driScreen *s; + + /* Create a screen */ + if ( !( s = ( driScreen * ) calloc( 1, sizeof( *s ) ) ) ) + return EGL_FALSE; + + snprintf( s->fb, NAME_MAX, "fb%d", dpy->minor ); + _eglInitScreen( &s->Base ); + + _eglAddScreen( &dpy->Base, &s->Base ); + + /* Create the screen's mode list */ + snprintf( path, sizeof( path ), "%s/graphics/%s/modes", sysfs, s->fb ); + file = fopen( path, "r" ); + while ( fgets( path, sizeof( path ), file ) ) { + unsigned int x, y, r; + char c; + path[ strlen( path ) - 1 ] = '\0'; /* strip off \n from sysfs */ + sscanf( path, "%c:%ux%u-%u", &c, &x, &y, &r ); + _eglAddNewMode( &s->Base, x, y, r * 1000, path ); + } + fclose( file ); + + /* + * NOTE: we used to set the colormap here, but that didn't work reliably. + * Some entries near the start of the table would get corrupted by later + * mode changes. + */ + } + + return EGL_TRUE; +} + + +EGLBoolean +_eglDRIInitialize(_EGLDriver *drv, EGLDisplay dpy, + EGLint *major, EGLint *minor) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + driDisplay *display; + + assert(disp); + + /* Create new driDisplay object to replace the _EGLDisplay that was + * previously created. + */ + display = calloc(1, sizeof(*display)); + display->Base = *disp; + _eglHashInsert(_eglGlobal.Displays, disp->Handle, display); + free(disp); + + *major = 1; + *minor = 0; + + sscanf(&disp->Name[1], "%d", &display->minor); + + drv->Initialized = EGL_TRUE; + return EGL_TRUE; +} + + +static EGLBoolean +_eglDRITerminate(_EGLDriver *drv, EGLDisplay dpy) +{ + driDisplay *display = Lookup_driDisplay(dpy); + _eglCleanupDisplay(&display->Base);/*rename that function*/ + free(display); + free(drv); + return EGL_TRUE; +} + + +/** + * Plug in the DRI-specific functions into the driver's dispatch table. + * Also, enable some EGL extensions. + */ +void +_eglDRIInitDriverFallbacks(_EGLDriver *drv) +{ + _eglInitDriverFallbacks(drv); + + drv->API.Initialize = _eglDRIInitialize; + drv->API.Terminate = _eglDRITerminate; + drv->API.CreateContext = _eglDRICreateContext; + drv->API.MakeCurrent = _eglDRIMakeCurrent; + drv->API.CreatePbufferSurface = _eglDRICreatePbufferSurface; + drv->API.DestroySurface = _eglDRIDestroySurface; + drv->API.DestroyContext = _eglDRIDestroyContext; + drv->API.CreateScreenSurfaceMESA = _eglDRICreateScreenSurfaceMESA; + drv->API.ShowScreenSurfaceMESA = _eglDRIShowScreenSurfaceMESA; + drv->API.SwapBuffers = _eglDRISwapBuffers; + + /* enable supported extensions */ + drv->Extensions.MESA_screen_surface = EGL_TRUE; + drv->Extensions.MESA_copy_context = EGL_TRUE; +} --- mesa-7.2.orig/src/egl/Makefile +++ mesa-7.2/src/egl/Makefile @@ -0,0 +1,24 @@ +# src/egl/Makefile + +TOP = ../.. + +SUBDIRS = main drivers/demo drivers/dri + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + + +clean: + -@for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) clean) ; \ + fi \ + done --- mesa-7.2.orig/src/egl/docs/EGL_MESA_screen_surface +++ mesa-7.2/src/egl/docs/EGL_MESA_screen_surface @@ -0,0 +1,564 @@ +Name + + MESA_screen_surface + +Name Strings + + EGL_MESA_screen_surface + +Contact + + Brian Paul + + To discuss, join the dri-egl@lists.freedesktop.org list. + +Status + + Preliminary - totally subject to change. + +Version + + 11 (27 January 2006) + +Number + + TBD + +Dependencies + + EGL 1.0 or later. + +Overview + + EGL 1.1 supports three types of drawing surfaces: + * Window surfaces + * Pixmap surfaces + * Pbuffer surfaces + This extension defines a fourth type of drawing surface: + * Screen surface + + A screen surface is a surface for which the (front) color buffer can + be directly displayed (i.e. scanned out) on a monitor (such as a flat + panel or CRT). In particular the color buffer memory will be allocated + at a location in VRAM (and in a suitable format) which can be displayed + by the graphics hardware. + + Note that the width and height of the screen surface need not exactly + match the monitor's current resolution. For example, while the monitor + may be configured to to show 1024x768 pixels, the associated screen + surface may be larger, such as 1200x1000. The "screen origin" attribute + will specify which region of the screen surface which is visible on the + monitor. The screen surface can be scrolled by changing this origin. + + This extension also defines functions for controlling the monitor's + display mode (width, height, refresh rate, etc), and specifing which + screen surface is to be displayed on a monitor. + + The new EGLModeMESA type and related functions are very similar to the + EGLConfig type and related functions. The user may get a list of + supported modes for a screen and specify the mode to be used when + displaying a screen surface. + + +Issues + + 1. Should EGL_INTERLACE be a supported mode attribute? + + Arguments against: + + No, this should be provided by another extension which would + also provide the mechanisms needed to play back interlaced video + material correctly on hardware that supports it. + This extension should prefer non-interlaced modes. [M. Danzer] + + Arguments for: + + An interlaced display can be of use without considering video + material. Being able to query whether a screen is operating in + interlaced mode can be used by applications to control their + drawing. For example: avoid drawing 1-pixel-wide horizontal lines + if screen is interlaced. [B. Paul] + + Resolution: Defer for future extension? + + + 2. Should EGL_REFRESH_RATE be a supported mode attribute? + + Arguments for: + + Yes, it's been shown that applications and/or users need to select + modes by this. [M. Danzer] + + Many examples have been given in which it's desirable to let the + user choose from a variety of refresh rates without having to + restart/reconfigure. [B. Paul] + + Arguments against: + + TBD. + + Resolution: Yes. + + + 3. Exactly how should the list of modes returned by eglChooseConfigMESA + be sorted? + + Current method is described in the text below. Subject to change. + + Alternately, leave the sorting order undefined so that each + implementation can return the modes in order of "most desirable" + to "least desirable" which may depend on the display technology + (CRT vs LCD, etc) or other factors. + + + 4. How should screen blanking be supported? Note that a screen can be + disabled or turned off by calling eglShowSurface(dpy, scrn, + EGL_NO_SURFACE, EGL_NO_MODE_MESA). But what about power-save mode? + + I would defer this to other extensions that depend on this one. + I can imagine people wanting different semantics not just in + relation to the power management API being exposed (DPMS or whatever) + but also relating to what events can trigger EGL_CONTEXT_LOST. Also + I'm not sure whether power management commands are properly operations + on the Display or on a screen surface. [A. Jackson] + + + 5. Should the EGL_PHYSICAL_SIZE_EGL query be kept? The size information + isn't always reliable (consider video projectors) but can still be + used to determine the pixel aspect ratio. + + Resolution: Omit. The EGL 1.2 specification includes queries for + the display resolution and pixel aspect ratio. + + + 6. Should detailed mode timing information be exposed by this API? + + Probably not. Instead, offer that information in a layered extension. + + + 7. How should the notion of a screen's "native" mode be expressed? + For example, LCD panels have a native resolution and refresh rate + that looks best but other sub-optimal resolutions may be supported. + + The mode attribute EGL_OPTIMAL_MESA will be set for modes which + best match the screen. [M. Danzer] + + + 8. Should eglQueryModeStringMESA() be included? This function returns + a human-readable string which corresponds to an EGLMode. + + Arguments for: + + A mode name such as "HDTV-720P" might mean more to users than + "1280x720@60Hz" if the later were generated via code. + + Arguments against: + + There's no standard syntax for the strings. May cause more + trouble than it's worth. + + Postpone for future extension. [A. Jackson] + + Latest discussion leaning toward omitting this function. + + + 9. Should we use "Get" or "Query" for functions which return state? + The EGL 1.x specification doesn't seem to be totally consistent + in this regard, but "Query" is used more often. + + Use "Get" for mode-related queries (as for EGLConfigs) but "Query" + for everything else. + + + 10. What should be the default size for screen surfaces? + + For Pbuffer surfaces the default width and height are zero. + We'll do the same for screen surfaces. Since there's no function + to resize surfaces it's useless to have a 0x0 screen, but this isn't + a situation that'll normally be encountered. + + + 11. Should there be a function for resizing a screen surface? + + Suppose one wants to change the screen's size in the EGL application. + Also suppose there's a hardware restriction such that only one screen + surface can exist at a time (either for lack of memory or because of + memory layout restrictions). + + The basic idea is that the currently displayed screen surface must + be deallocated before a new one can be created. Perhaps a resize + function would work better? + + + 12. How should sub-pixel LCD color information be made available? + What about the display's gamma value? + + Perhaps expose as additional read-only mode attributes. + + Perhaps postpone for a layered extension. + + + 13. What happens if the user attempts to delete a screen surface that + is currently being shown? + + Spec currently says that's illegal and that an error (TBD) will be + generated. + + + 14. What if the physical screen size can't be determined? Should + a query of EGL_PHYSICAL_SIZE_MESA return [0,0]? + + Obsolete: EGL_PHYSICAL_SIZE_MESA not used. + + + 15. Suppose the device's number of RAMDACs is different from the + number of output ports. For example, a graphics card with + two RAMDACs but three ports (VGA, DVI, TV). + + Address this in a follow-on extension. [Matthias Hopf] + + + 16. How should we deal with on-the-fly device changes? For example, + the monitor being unplugged and replaced by another with different + characteristics? + + A HAL event could be received via DBUS in the application [J. Smirl, + A. Jackson]. + + Should there be an EGL mechanism for detecting this? Maybe an + EGL_SCREEN_LOST error (similar to EGL_CONTEXT_LOST) can be recorded + when there's a screen change. At least then the application can + poll to detect this situation. + + Maybe leave that to a future extension. + + See also the EGL_SCREEN_COUNT_MESA query. + + + 17. What if pixel-accurate panning is not supported (see + eglScreenPositionMESA)? [M. Danzer] + + Is this a common problem? Can we ignore it for now? + + + 18. Should eglShowSurfaceMESA be renamed to eglShowScreenSurfaceMESA? + + Probably. + + + +New Procedures and Functions + + EGLBoolean eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, + const EGLint *attrib_list, + EGLModeMESA *modes, EGLint modes_size, + EGLint *num_modes) + + EGLBoolean eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *modes, EGLint modes_size, + EGLint *num_modes) + + EGLBoolean eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, + EGLint attrib, EGLint *value) + + + EGLBoolean eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, + EGLint screens_size, EGLint *num_screens) + + EGLSurface eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) + + EGLBoolean eglShowSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLSurface surface, EGLModeMESA mode) + + EGLBoolean eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLint x, EGLint y) + + + EGLBoolean eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLint attrib, EGLint *value); + + EGLBoolean eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLSurface *surface) + + EGLBoolean eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *mode) + + const char *eglQueryModeStringMESA(EGLDisplay dpy, EGLMode mode); + + +New Types + + EGLModeMESA + EGLScreenMESA + +New Tokens + + New error codes: + + EGL_BAD_SCREEN_MESA + EGL_BAD_MODE_MESA + + Screen-related tokens: + + EGL_SCREEN_COUNT_MESA + EGL_SCREEN_POSITION_MESA + EGL_SCREEN_BIT_MESA + EGL_SCREEN_POSITION_GRANULARITY_MESA + + Mode-related tokens: + + EGL_MODE_ID_MESA + EGL_REFRESH_RATE_MESA + EGL_INTERLACED_MESA + EGL_OPTIMAL_MESA + EGL_NO_MODE_MESA + + +Additions to Chapter X of the EGL 1.1 Specification + + [XXX this all has to be rewritten to fit into the EGL specification + and match the conventions of an EGL extension. For now, just list + all the functions with brief descriptions.] + + + EGLBoolean eglChooseModeMESA(EGLDisplay dpy, const EGLScreenMESA screen, + EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes) + + Like eglChooseConfig, returns a list of EGLModes which match the given + attribute list. This does not set the screen's current display mode. + The attribute list is a list of token/value pairs terminated with + EGL_NONE. Supported attributes include: + + Name Description + --------------------- --------------------------------------------- + EGL_WIDTH Mode width (resolution) + EGL_HEIGHT Mode height (resolution) + EGL_REFRESH_RATE_MESA The mode's refresh rate, multiplied by 1000 + EGL_INTERLACED_MESA 1 indicates an interlaced mode, 0 otherwise + EGL_OPTIMAL_MESA Set if the most is especially optimal for the + screen (ex. for particular LCD resolutions) + + Any other token will generate the error EGL_BAD_ATTRIBUTE. + + The list of modes returned by eglChooseModeMESA will be sorted + according to the following criteria. See the discussion of table 3.3 + in the EGL specification for more information. + + Selection Sort Sort + Attribute Default Criteria Order Priority + -------------------- -------------- ----------- ------ -------- + EGL_OPTIMAL_MESA EGL_DONT_CARE Exact 1,0 1 + EGL_INTERLACED_MESA EGL_DONT_CARE Exact 0,1 2 + EGL_REFRESH_RATE EGL_DONT_CARE AtLeast Larger 3 + EGL_WIDTH EGL_DONT_CARE AtLeast Larger 4 + EGL_HEIGHT EGL_DONT_CARE AtLeast Larger 5 + EGL_MODE_ID_MESA EGL_DONT_CARE Exact Smaller 6 + + + EGLBoolean eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *modes, EGLint modes_size, + EGLint *num_modes) + + Like eglGetConfigs, returns a list of all modes supported by the + given screen. The returned modes will be sorted in the same manner + as for eglChooseModeMESA(). + + + + EGLBoolean eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, + EGLint attrib, EGLint *value) + + Used to query mode attributes. The following attributes are supported: + + Name Return value description + --------------------- ---------------------------------------------- + EGL_OPTIMAL_MESA 1 indicates an optimal mode, 0 otherwise + EGL_INTERLACED_MESA 1 indicates an interlaced mode, 0 otherwise + EGL_REFRESH_RATE_MESA The mode's refresh rate, multiplied by 1000 + EGL_WIDTH Mode width (resolution) + EGL_HEIGHT Mode height (resolution) + EGL_MODE_ID_MESA A unique small integer identifier for the mode + + Any other token will generate the error EGL_BAD_ATTRIBUTE. + + + + EGLBoolean eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, + EGLint screens_size, EGLint *num_screens) + + This function returns an array of all available screen handles. + is the maximum number of screens to return in the + array. will return the number of screen handles + placed in the array, even if is NULL. + + The number of screens and the availability of each may change over + time (hot-plugging). Screen handles will not be reused. When a + screen handle becomes invalid, function calls which reference an + invalid handle will generate EGL_BAD_SCREEN_MESA. + + The first screen handle returned will be considered to be the primary + one. + + + + EGLSurface eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) + + Create a surface that can be displayed on a screen. is + an array of token/value pairs terminated with EGL_NONE. Valid tokens + include: + + Name Description + ---------------- -------------------------------- + EGL_WIDTH desired surface width in pixels + EGL_HEIGHT desired surface height in pixels + + Any other token will generate the error EGL_BAD_ATTRIBUTE. + The default width and height are zero. + + + + EGLBoolean eglShowSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLSurface surface, EGLModeMESA mode) + + This function causes a screen to show the given surface (or more + precisely, the surface's front color buffer) with the given mode. + + If the surface is in any way incompatible with the mode, the error + EGL_BAD_MATCH will be generated, EGL_FALSE will be returned, and the + previous screen state will remain in effect. This might occur when + the bandwidth of the video-out subsystem is exceeded, or if the mode + specifies a width or height that's greater than the width or height + of the surface. + + To disable a screen, the values EGL_NO_SURFACE and EGL_NO_MODE_MESA + be passed as the and parameters. + + The values of EGL_SCREEN_POSITION_MESA are clamped to the new valid + range computed from the screen size and surface size. If the new + surface is EGL_NO_SURFACE, EGL_SCREEN_POSITION_MESA is set to [0, 0]. + + + Attempting to delete a screen surface which is currently being + displayed will result in the error EGL_BAD_ACCESS being generated. + + + + EGLBoolean eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLint x, EGLint y) + + Specifies the origin of the screen's view into the surface, if the + surface is larger than the screen. Valid values for x and y are + [0, surfaceWidth - screenWidth] and [0, surfaceHeight - screenHeight], + respectively. + + The x and y values are also constrained to be integer multiples of the + EGL_SCREEN_POSITION_GRANULARITY_MESA values. + + + + + EGLBoolean eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLint attrib, EGLint *value); + + Used to query screen attributes. may be one of the following: + + Name Return value description + ------------------------ --------------------------------------------- + EGL_SCREEN_POSITION_MESA x, y position of the screen's origin with + respect to the surface. If no surface is + attached to the screen, [0, 0] is returned. + EGL_SCREEN_POSITION_GRANULARITY_MESA + Returns the granularity, in pixels, for + which the screen position is constrained. + + Any other token will generate the error EGL_BAD_ATTRIBUTE. + + + + + EGLBoolean eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLSurface *surface) + + Returns the surface currently displayed on the given screen. + may be EGL_NO_SURFACE if the screen isn't currently showing any surface. + + + + + EGLBoolean eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *mode) + + Returns the given screen's current display mode. The mode may be + EGL_NO_MODE_MESA if the screen is currently disabled. + + + + const char *eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode); + + Returns a human-readable string for the given mode. The string is a + zero-terminated C string which the user should not attempt to free. + There is no standard syntax for mode strings. Applications should + not directly rely on mode strings. + + + +Version History + + 1. 15 March 2005 - BrianP + Initial version + + 2. 16 March 2005 - BrianP + Removed EGL_DEPTH_MESA + Added EGL_PHYSICAL_WIDTH_MESA, EGL_PHYSICAL_HEIGHT_MESA queries + Added EGL_OPTIMAL_MESA for width/height/refresh rate selection + Added possible eglQueryModeStringMESA() function + More details of the new functions explained. + + 3. 18 March 2005 - BrianP + Added screen_number to eglChooseModeMESA(). + Fix off by one mistake in value range for ORIGIN attributes + Added Issues section + + 4. 21 March 2005 - BrianP + Removed eglScreenAttribsMESA(). + Added eglScreenPositionMESA() to set screen origin. + Replaced EGL_SCREEN_X/Y_OFFSET_MESA with EGL_SCREEN_POSITION_MESA. + Replaced EGL_PHYSICAL_WIDTH/HEIGHT_MESA with EGL_PHYSICAL_SIZE_MESA. + Use EGL_OPTIMAL_MESA as a new mode attribute. (Michel Danzer) + Added a few more issues. + + 5. 6 April 2005 - BrianP + More language for eglGetModeStringMESA(). + Added issues 10, 11, 12, 13, 14. + Updated issue 3 discussion about mode sorting. + + 6. 22 April 2005 - BrianP + Fixed "LDC" typo. + Added issues 15, 16. + Changed dependency on EGL 1.1 to EGL 1.0 + s/EGL_NUM_SCREENS_MESA/EGL_SCREEN_COUNT_MESA/ + Added eglQueryDisplayMESA() to New Functions section. + Clarified language for the EGL_SCREEN_COUNT_MESA query. + + 7. 29 April 2005 - BrianP + Added EGLScreenMESA type and eglGetScreensMESA() function. [J. Smirl]. + Replaced EGLint screen_number parameters with EGLScreenMESA screen. + Added issue 17 (pixel-accurate panning) + + 8. 2 May 2005 - BrianP + Removed eglQueryDisplayMESA. + Fixed a few more EGLint -> EGLScreenMESA changes. + + 9. 20 May 2005 - BrianP + Fixed a few typos. + Updated some open issues text. + + 10. 10 August 2005 - BrianP + Added EGL_SCREEN_POSITION_GRANULARITY_MESA. + + 11. 27 January 2006 - BrianP + EGL_PHYSICAL_SIZE_MESA removed since EGL 1.2 has a similar feature. + --- mesa-7.2.orig/src/egl/main/eglglobals.h +++ mesa-7.2/src/egl/main/eglglobals.h @@ -0,0 +1,68 @@ +#ifndef EGLGLOBALS_INCLUDED +#define EGLGLOBALS_INCLUDED + +#include "egltypedefs.h" +#include "eglhash.h" + + +/** + * Per-thread info + */ +struct _egl_thread_info +{ + EGLint LastError; + _EGLContext *CurrentContext; + EGLenum CurrentAPI; +}; + + +/** + * Global library data + */ +struct _egl_global +{ + EGLBoolean Initialized; + + _EGLHashtable *Displays; + _EGLHashtable *Contexts; + _EGLHashtable *Surfaces; + + EGLScreenMESA FreeScreenHandle; + + /* XXX these may be temporary */ + EGLBoolean OpenGLESAPISupported; + EGLBoolean OpenVGAPISupported; + + /* XXX temporary - should be thread-specific data (TSD) */ + _EGLThreadInfo *ThreadInfo; +}; + + +extern struct _egl_global _eglGlobal; + + +extern void +_eglInitGlobals(void); + + +extern void +_eglDestroyGlobals(void); + + +extern _EGLThreadInfo * +_eglNewThreadInfo(void); + + +extern void +_eglDeleteThreadData(_EGLThreadInfo *t); + + +extern _EGLThreadInfo * +_eglGetCurrentThread(void); + + +extern void +_eglError(EGLint errCode, const char *msg); + + +#endif /* EGLGLOBALS_INCLUDED */ --- mesa-7.2.orig/src/egl/main/egldisplay.c +++ mesa-7.2/src/egl/main/egldisplay.c @@ -0,0 +1,71 @@ +#include +#include +#include "eglcontext.h" +#include "egldisplay.h" +#include "eglglobals.h" +#include "eglhash.h" + + +static char * +my_strdup(const char *s) +{ + int l = strlen(s); + char *s2 = malloc(l + 1); + strcpy(s2, s); + return s2; +} + + +/** + * We're assuming that the NativeDisplayType parameter is actually + * a string. + * Return a new _EGLDisplay object for the given displayName + */ +_EGLDisplay * +_eglNewDisplay(NativeDisplayType displayName) +{ + _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); + if (dpy) { + dpy->Handle = _eglHashGenKey(_eglGlobal.Displays); + _eglHashInsert(_eglGlobal.Displays, dpy->Handle, dpy); + if (displayName) + dpy->Name = my_strdup(displayName); + else + dpy->Name = NULL; + dpy->Driver = NULL; /* this gets set later */ + } + return dpy; +} + + +/** + * Return the _EGLDisplay object that corresponds to the given public/ + * opaque display handle. + */ +_EGLDisplay * +_eglLookupDisplay(EGLDisplay dpy) +{ + _EGLDisplay *d = (_EGLDisplay *) _eglHashLookup(_eglGlobal.Displays, dpy); + return d; +} + + +_EGLDisplay * +_eglGetCurrentDisplay(void) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + if (ctx) + return ctx->Display; + else + return NULL; +} + + +void +_eglCleanupDisplay(_EGLDisplay *disp) +{ + /* XXX incomplete */ + free(disp->Configs); + free(disp->Name); + /* driver deletes _EGLDisplay */ +} --- mesa-7.2.orig/src/egl/main/egllog.h +++ mesa-7.2/src/egl/main/egllog.h @@ -0,0 +1,16 @@ +#ifndef EGLLOG_INCLUDED +#define EGLLOG_INCLUDED + +#include "egltypedefs.h" + +#define _EGL_FATAL 0 /* unrecoverable error */ +#define _EGL_WARNING 1 /* recoverable error/problem */ +#define _EGL_INFO 2 /* just useful info */ +#define _EGL_DEBUG 3 /* useful info for debugging */ + + +extern void +_eglLog(EGLint level, const char *fmtStr, ...); + + +#endif /* EGLLOG_INCLUDED */ --- mesa-7.2.orig/src/egl/main/Makefile +++ mesa-7.2/src/egl/main/Makefile @@ -0,0 +1,67 @@ +# src/egl/main/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + + +INCLUDE_DIRS = -I$(TOP)/include -I$(TOP)/src/mesa/glapi + +HEADERS = \ + eglconfig.h \ + eglcontext.h \ + egldisplay.h \ + egldriver.h \ + eglglobals.h \ + egllog.h \ + eglhash.h \ + eglmode.h \ + eglscreen.h \ + eglsurface.h + +SOURCES = \ + eglapi.c \ + eglconfig.c \ + eglcontext.c \ + egldisplay.c \ + egldriver.c \ + eglglobals.c \ + egllog.c \ + eglhash.c \ + eglmode.c \ + eglscreen.c \ + eglsurface.c + +OBJECTS = $(SOURCES:.c=.o) + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: depend library + + +# EGL Library +library: $(TOP)/$(LIB_DIR)/libEGL.so + +$(TOP)/$(LIB_DIR)/libEGL.so: $(OBJECTS) + $(MKLIB) -o EGL -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major 1 -minor 0 \ + -install $(TOP)/$(LIB_DIR) -ldl $(OBJECTS) + + + +clean: + -rm -f *.o *.so* + -rm -f core.* + + +depend: $(SOURCES) $(HEADERS) + @ echo "running $(MKDEP)" + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \ + $(SOURCES) $(HEADERS) > /dev/null + +include depend +# DO NOT DELETE --- mesa-7.2.orig/src/egl/main/eglhash.h +++ mesa-7.2/src/egl/main/eglhash.h @@ -0,0 +1,39 @@ +/** + * \file eglhash.h + * Generic hash table. + */ + + +#ifndef EGLHASH_INCLUDED +#define EGLHASH_INCLUDED + + +/* XXX move this? */ +typedef unsigned int EGLuint; + + +typedef struct _egl_hashtable _EGLHashtable; + + +extern _EGLHashtable *_eglNewHashTable(void); + +extern void _eglDeleteHashTable(_EGLHashtable *table); + +extern void *_eglHashLookup(const _EGLHashtable *table, EGLuint key); + +extern void _eglHashInsert(_EGLHashtable *table, EGLuint key, void *data); + +extern void _eglHashRemove(_EGLHashtable *table, EGLuint key); + +extern EGLuint _eglHashFirstEntry(_EGLHashtable *table); + +extern EGLuint _eglHashNextEntry(const _EGLHashtable *table, EGLuint key); + +extern void _eglHashPrint(const _EGLHashtable *table); + +extern EGLuint _eglHashGenKey(_EGLHashtable *table); + +extern void _egltest_hash_functions(void); + + +#endif /* EGLHASH_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglmode.c +++ mesa-7.2/src/egl/main/eglmode.c @@ -0,0 +1,431 @@ +#include +#include +#include +#include + +#include "egldisplay.h" +#include "egldriver.h" +#include "eglmode.h" +#include "eglglobals.h" +#include "eglscreen.h" + + +#define MIN2(A, B) (((A) < (B)) ? (A) : (B)) + + +static char * +my_strdup(const char *s) +{ + if (s) { + int l = strlen(s); + char *s2 = malloc(l + 1); + if (s2) + strcpy(s2, s); + return s2; + } + else { + return NULL; + } +} + + +/** + * Given an EGLModeMESA handle, return the corresponding _EGLMode object + * or null if non-existant. + */ +_EGLMode * +_eglLookupMode(EGLDisplay dpy, EGLModeMESA mode) +{ + const _EGLDisplay *disp = _eglLookupDisplay(dpy); + EGLint scrnum; + + /* loop over all screens on the display */ + for (scrnum = 0; scrnum < disp->NumScreens; scrnum++) { + const _EGLScreen *scrn = disp->Screens[scrnum]; + EGLint i; + /* search list of modes for handle */ + for (i = 0; i < scrn->NumModes; i++) { + if (scrn->Modes[i].Handle == mode) { + return scrn->Modes + i; + } + } + } + + return NULL; +} + + +/** + * Add a new mode with the given attributes (width, height, depth, refreshRate) + * to the given screen. + * Assign a new mode ID/handle to the mode as well. + * \return pointer to the new _EGLMode + */ +_EGLMode * +_eglAddNewMode(_EGLScreen *screen, EGLint width, EGLint height, + EGLint refreshRate, const char *name) +{ + EGLint n; + _EGLMode *newModes; + + assert(screen); + assert(width > 0); + assert(height > 0); + assert(refreshRate > 0); + + n = screen->NumModes; + newModes = (_EGLMode *) realloc(screen->Modes, (n+1) * sizeof(_EGLMode)); + if (newModes) { + screen->Modes = newModes; + screen->Modes[n].Handle = n + 1; + screen->Modes[n].Width = width; + screen->Modes[n].Height = height; + screen->Modes[n].RefreshRate = refreshRate; + screen->Modes[n].Optimal = EGL_FALSE; + screen->Modes[n].Interlaced = EGL_FALSE; + screen->Modes[n].Name = my_strdup(name); + screen->NumModes++; + return screen->Modes + n; + } + else { + return NULL; + } +} + + + +/** + * Parse the attrib_list to fill in the fields of the given _eglMode + * Return EGL_FALSE if any errors, EGL_TRUE otherwise. + */ +static EGLBoolean +_eglParseModeAttribs(_EGLMode *mode, const EGLint *attrib_list) +{ + EGLint i; + + /* init all attribs to EGL_DONT_CARE */ + mode->Handle = EGL_DONT_CARE; + mode->Width = EGL_DONT_CARE; + mode->Height = EGL_DONT_CARE; + mode->RefreshRate = EGL_DONT_CARE; + mode->Optimal = EGL_DONT_CARE; + mode->Interlaced = EGL_DONT_CARE; + mode->Name = NULL; + + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + case EGL_MODE_ID_MESA: + mode->Handle = attrib_list[++i]; + if (mode->Handle <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(handle)"); + return EGL_FALSE; + } + break; + case EGL_WIDTH: + mode->Width = attrib_list[++i]; + if (mode->Width <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(width)"); + return EGL_FALSE; + } + break; + case EGL_HEIGHT: + mode->Height = attrib_list[++i]; + if (mode->Height <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(height)"); + return EGL_FALSE; + } + break; + case EGL_REFRESH_RATE_MESA: + mode->RefreshRate = attrib_list[++i]; + if (mode->RefreshRate <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(refresh rate)"); + return EGL_FALSE; + } + break; + case EGL_INTERLACED_MESA: + mode->Interlaced = attrib_list[++i]; + if (mode->Interlaced != EGL_TRUE && mode->Interlaced != EGL_FALSE) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(interlaced)"); + return EGL_FALSE; + } + break; + case EGL_OPTIMAL_MESA: + mode->Optimal = attrib_list[++i]; + if (mode->Optimal != EGL_TRUE && mode->Optimal != EGL_FALSE) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(optimal)"); + return EGL_FALSE; + } + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglChooseModeMESA"); + return EGL_FALSE; + } + } + return EGL_TRUE; +} + + +/** + * Determine if the candidate mode's attributes are at least as good + * as the minimal mode's. + * \return EGL_TRUE if qualifies, EGL_FALSE otherwise + */ +static EGLBoolean +_eglModeQualifies(const _EGLMode *c, const _EGLMode *min) +{ + if (min->Handle != EGL_DONT_CARE && c->Handle != min->Handle) + return EGL_FALSE; + if (min->Width != EGL_DONT_CARE && c->Width < min->Width) + return EGL_FALSE; + if (min->Height != EGL_DONT_CARE && c->Height < min->Height) + return EGL_FALSE; + if (min->RefreshRate != EGL_DONT_CARE && c->RefreshRate < min->RefreshRate) + return EGL_FALSE; + if (min->Optimal != EGL_DONT_CARE && c->Optimal != min->Optimal) + return EGL_FALSE; + if (min->Interlaced != EGL_DONT_CARE && c->Interlaced != min->Interlaced) + return EGL_FALSE; + + return EGL_TRUE; +} + + +/** + * Return value of given mode attribute, or -1 if bad attrib. + */ +static EGLint +getModeAttrib(const _EGLMode *m, EGLint attrib) +{ + switch (attrib) { + case EGL_MODE_ID_MESA: + return m->Handle; + case EGL_WIDTH: + return m->Width; + case EGL_HEIGHT: + return m->Height; + case EGL_REFRESH_RATE_MESA: + return m->RefreshRate; + case EGL_OPTIMAL_MESA: + return m->Optimal; + case EGL_INTERLACED_MESA: + return m->Interlaced; + default: + return -1; + } +} + + +#define SMALLER 1 +#define LARGER 2 + +struct sort_info { + EGLint Attrib; + EGLint Order; /* SMALLER or LARGER */ +}; + +/* the order of these entries is the priority */ +static struct sort_info SortInfo[] = { + { EGL_OPTIMAL_MESA, LARGER }, + { EGL_INTERLACED_MESA, SMALLER }, + { EGL_WIDTH, LARGER }, + { EGL_HEIGHT, LARGER }, + { EGL_REFRESH_RATE_MESA, LARGER }, + { EGL_MODE_ID_MESA, SMALLER }, + { 0, 0 } +}; + + +/** + * Compare modes 'a' and 'b' and return -1 if a belongs before b, or 1 if a + * belongs after b, or 0 if they're equal. + * Used by qsort(). + */ +static int +_eglCompareModes(const void *a, const void *b) +{ + const _EGLMode *aMode = *((const _EGLMode **) a); + const _EGLMode *bMode = *((const _EGLMode **) b); + EGLint i; + + for (i = 0; SortInfo[i].Attrib; i++) { + const EGLint aVal = getModeAttrib(aMode, SortInfo[i].Attrib); + const EGLint bVal = getModeAttrib(bMode, SortInfo[i].Attrib); + if (aVal == bVal) { + /* a tie */ + continue; + } + else if (SortInfo[i].Order == SMALLER) { + return (aVal < bVal) ? -1 : 1; + } + else if (SortInfo[i].Order == LARGER) { + return (aVal > bVal) ? -1 : 1; + } + } + + /* all attributes identical */ + return 0; +} + + +/** + * Search for EGLModes which match the given attribute list. + * Called via eglChooseModeMESA API function. + */ +EGLBoolean +_eglChooseModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + const EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes) +{ + const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + _EGLMode **modeList, min; + EGLint i, count; + + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, "eglChooseModeMESA"); + return EGL_FALSE; + } + + if (!_eglParseModeAttribs(&min, attrib_list)) { + /* error code will have been recorded */ + return EGL_FALSE; + } + + /* allocate array of mode pointers */ + modeList = (_EGLMode **) malloc(modes_size * sizeof(_EGLMode *)); + if (!modeList) { + _eglError(EGL_BAD_MODE_MESA, "eglChooseModeMESA(out of memory)"); + return EGL_FALSE; + } + + /* make array of pointers to qualifying modes */ + for (i = count = 0; i < scrn->NumModes && count < modes_size; i++) { + if (_eglModeQualifies(scrn->Modes + i, &min)) { + modeList[count++] = scrn->Modes + i; + } + } + + /* sort array of pointers */ + qsort(modeList, count, sizeof(_EGLMode *), _eglCompareModes); + + /* copy mode handles to output array */ + for (i = 0; i < count; i++) { + modes[i] = modeList[i]->Handle; + } + + free(modeList); + + *num_modes = count; + + return EGL_TRUE; +} + + + +/** + * Return all possible modes for the given screen. No sorting of results. + * Called via eglGetModesMESA() API function. + */ +EGLBoolean +_eglGetModesMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes) +{ + _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, "eglGetModesMESA"); + return EGL_FALSE; + } + + if (modes) { + EGLint i; + *num_modes = MIN2(scrn->NumModes, modes_size); + for (i = 0; i < *num_modes; i++) { + modes[i] = scrn->Modes[i].Handle; + } + } + else { + /* just return total number of supported modes */ + *num_modes = scrn->NumModes; + } + + return EGL_TRUE; +} + + +/** + * Query an attribute of a mode. + */ +EGLBoolean +_eglGetModeAttribMESA(_EGLDriver *drv, EGLDisplay dpy, + EGLModeMESA mode, EGLint attribute, EGLint *value) +{ + _EGLMode *m = _eglLookupMode(dpy, mode); + EGLint v; + + if (!m) { + _eglError(EGL_BAD_MODE_MESA, "eglGetModeAttribMESA"); + return EGL_FALSE; + } + + v = getModeAttrib(m, attribute); + if (v < 0) { + _eglError(EGL_BAD_ATTRIBUTE, "eglGetModeAttribMESA"); + return EGL_FALSE; + } + *value = v; + return EGL_TRUE; +} + + +/** + * Return human-readable string for given mode. + * This is the default function called by eglQueryModeStringMESA(). + */ +const char * +_eglQueryModeStringMESA(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode) +{ + _EGLMode *m = _eglLookupMode(dpy, mode); + if (!m) { + _eglError(EGL_BAD_MODE_MESA, "eglQueryModeStringMESA"); + return NULL; + } + return m->Name; +} + + +#if 0 +static int +_eglRand(int max) +{ + return rand() % max; +} + +void +_eglTestModeModule(void) +{ + EGLint count = 30; + _EGLMode *modes = (_EGLMode *) malloc(count * sizeof(_EGLMode)); + _EGLMode **modeList = (_EGLMode **) malloc(count * sizeof(_EGLMode*)); + EGLint i; + + for (i = 0; i < count; i++) { + modes[i].Handle = _eglRand(20); + modes[i].Width = 512 + 256 * _eglRand(2); + modes[i].Height = 512 + 256 * _eglRand(2); + modes[i].RefreshRate = 50 + 5 * _eglRand(3); + modes[i].Interlaced = _eglRand(2); + modes[i].Optimal = _eglRand(4) == 0; + modeList[i] = modes + i; + } + + /* sort array of pointers */ + qsort(modeList, count, sizeof(_EGLMode *), compareModes); + + for (i = 0; i < count; i++) { + _EGLMode *m = modeList[i]; + printf("%2d: %3d %4d x %4d @ %3d opt %d int %d\n", i, + m->Handle, m->Width, m->Height, m->RefreshRate, + m->Optimal, m->Interlaced); + } +} +#endif --- mesa-7.2.orig/src/egl/main/egldisplay.h +++ mesa-7.2/src/egl/main/egldisplay.h @@ -0,0 +1,44 @@ +#ifndef EGLDISPLAY_INCLUDED +#define EGLDISPLAY_INCLUDED + + +#include "egltypedefs.h" + + +struct _egl_display +{ + EGLDisplay Handle; + + char *Name; + _EGLDriver *Driver; + + EGLint NumScreens; + _EGLScreen **Screens; /* array [NumScreens] */ + + EGLint NumConfigs; + _EGLConfig *Configs; /* array [NumConfigs] */ +}; + + +extern _EGLDisplay * +_eglNewDisplay(NativeDisplayType displayName); + + +extern _EGLDisplay * +_eglLookupDisplay(EGLDisplay dpy); + + +extern _EGLDisplay * +_eglGetCurrentDisplay(void); + + +extern void +_eglCleanupDisplay(_EGLDisplay *disp); + + +extern EGLBoolean +_eglQueryDisplayMESA(_EGLDriver *drv, EGLDisplay dpy, EGLint attrib, EGLint *value); + + + +#endif /* EGLDISPLAY_INCLUDED */ --- mesa-7.2.orig/src/egl/main/egltypedefs.h +++ mesa-7.2/src/egl/main/egltypedefs.h @@ -0,0 +1,34 @@ +#ifndef EGLTYPEDEFS_INCLUDED +#define EGLTYPEDEFS_INCLUDED + + +#include + + +typedef struct _egl_api _EGLAPI; + +typedef struct _egl_config _EGLConfig; + +typedef struct _egl_context _EGLContext; + +typedef struct _egl_display _EGLDisplay; + +typedef struct _egl_driver _EGLDriver; + +typedef struct _egl_extensions _EGLExtensions; + +typedef struct _egl_mode _EGLMode; + +typedef struct _egl_screen _EGLScreen; + +typedef struct _egl_surface _EGLSurface; + +typedef struct _egl_thread_info _EGLThreadInfo; + + +typedef void (*_EGLProc)(); + +typedef _EGLDriver *(*_EGLMain_t)(_EGLDisplay *dpy); + + +#endif /* EGLTYPEDEFS_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglmode.h +++ mesa-7.2/src/egl/main/eglmode.h @@ -0,0 +1,54 @@ +#ifndef EGLMODE_INCLUDED +#define EGLMODE_INCLUDED + +#include "egltypedefs.h" + + +/** + * Data structure which corresponds to an EGLModeMESA. + */ +struct _egl_mode +{ + EGLModeMESA Handle; /* the public/opaque handle which names this mode */ + EGLint Width, Height; /* size in pixels */ + EGLint RefreshRate; /* rate * 1000.0 */ + EGLint Optimal; + EGLint Interlaced; + const char *Name; + + /* Other possible attributes */ + /* interlaced */ + /* external sync */ +}; + + +extern _EGLMode * +_eglLookupMode(EGLDisplay dpy, EGLModeMESA mode); + + +extern _EGLMode * +_eglAddNewMode(_EGLScreen *screen, EGLint width, EGLint height, + EGLint refreshRate, const char *name); + + +extern EGLBoolean +_eglChooseModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + const EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes); + + +extern EGLBoolean +_eglGetModesMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); + + +extern EGLBoolean +_eglGetModeAttribMESA(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode, + EGLint attribute, EGLint *value); + + +extern const char * +_eglQueryModeStringMESA(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode); + + +#endif /* EGLMODE_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglapi.c +++ mesa-7.2/src/egl/main/eglapi.c @@ -0,0 +1,586 @@ +/** + * Public EGL API entrypoints + * + * Generally, we use the EGLDisplay parameter as a key to lookup the + * appropriate device driver handle, then jump though the driver's + * dispatch table to handle the function. + * + * That allows us the option of supporting multiple, simultaneous, + * heterogeneous hardware devices in the future. + * + * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are + * opaque handles implemented with 32-bit unsigned integers. + * It's up to the driver function or fallback function to look up the + * handle and get an object. + * By using opaque handles, we leave open the possibility of having + * indirect rendering in the future, like GLX. + * + * + * Notes on naming conventions: + * + * eglFooBar - public EGL function + * EGL_FOO_BAR - public EGL token + * EGLDatatype - public EGL datatype + * + * _eglFooBar - private EGL function + * _EGLDatatype - private EGL datatype, typedef'd struct + * _egl_struct - private EGL struct, non-typedef'd + * + */ + + + +#include +#include +#include +#include "eglcontext.h" +#include "egldisplay.h" +#include "egltypedefs.h" +#include "eglglobals.h" +#include "egldriver.h" +#include "eglsurface.h" + + + +/** + * NOTE: displayName is treated as a string in _eglChooseDriver()!!! + * This will probably change! + * See _eglChooseDriver() for details! + */ +EGLDisplay APIENTRY +eglGetDisplay(NativeDisplayType displayName) +{ + _EGLDisplay *dpy; + _eglInitGlobals(); + dpy = _eglNewDisplay(displayName); + if (dpy) + return dpy->Handle; + else + return EGL_NO_DISPLAY; +} + + +EGLBoolean APIENTRY +eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + if (dpy) { + _EGLDriver *drv = _eglChooseDriver(dpy); + if (drv) + return drv->API.Initialize(drv, dpy, major, minor); + } + return EGL_FALSE; +} + + +EGLBoolean APIENTRY +eglTerminate(EGLDisplay dpy) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return _eglCloseDriver(drv, dpy); + else + return EGL_FALSE; +} + + +const char * APIENTRY +eglQueryString(EGLDisplay dpy, EGLint name) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return drv->API.QueryString(drv, dpy, name); + else + return NULL; +} + + +EGLBoolean APIENTRY +eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + /* XXX check drv for null in remaining functions */ + return drv->API.GetConfigs(drv, dpy, configs, config_size, num_config); +} + + +EGLBoolean APIENTRY +eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.ChooseConfig(drv, dpy, attrib_list, configs, config_size, num_config); +} + + +EGLBoolean APIENTRY +eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.GetConfigAttrib(drv, dpy, config, attribute, value); +} + + +EGLContext APIENTRY +eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CreateContext(drv, dpy, config, share_list, attrib_list); +} + + +EGLBoolean APIENTRY +eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.DestroyContext(drv, dpy, ctx); +} + + +EGLBoolean APIENTRY +eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.MakeCurrent(drv, dpy, draw, read, ctx); +} + + +EGLBoolean APIENTRY +eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.QueryContext(drv, dpy, ctx, attribute, value); +} + + +EGLSurface APIENTRY +eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CreateWindowSurface(drv, dpy, config, window, attrib_list); +} + + +EGLSurface APIENTRY +eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CreatePixmapSurface(drv, dpy, config, pixmap, attrib_list); +} + + +EGLSurface APIENTRY +eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CreatePbufferSurface(drv, dpy, config, attrib_list); +} + + +EGLBoolean APIENTRY +eglDestroySurface(EGLDisplay dpy, EGLSurface surface) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.DestroySurface(drv, dpy, surface); +} + + +EGLBoolean APIENTRY +eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.QuerySurface(drv, dpy, surface, attribute, value); +} + + +EGLBoolean APIENTRY +eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.SurfaceAttrib(drv, dpy, surface, attribute, value); +} + + +EGLBoolean APIENTRY +eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.BindTexImage(drv, dpy, surface, buffer); +} + + +EGLBoolean APIENTRY +eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.ReleaseTexImage(drv, dpy, surface, buffer); +} + + +EGLBoolean APIENTRY +eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.SwapInterval(drv, dpy, interval); +} + + +EGLBoolean APIENTRY +eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.SwapBuffers(drv, dpy, draw); +} + + +EGLBoolean APIENTRY +eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, NativePixmapType target) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CopyBuffers(drv, dpy, surface, target); +} + + +EGLBoolean APIENTRY +eglWaitGL(void) +{ + EGLDisplay dpy = eglGetCurrentDisplay(); + if (dpy != EGL_NO_DISPLAY) { + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.WaitGL(drv, dpy); + } + else + return EGL_FALSE; +} + + +EGLBoolean APIENTRY +eglWaitNative(EGLint engine) +{ + EGLDisplay dpy = eglGetCurrentDisplay(); + if (dpy != EGL_NO_DISPLAY) { + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.WaitNative(drv, dpy, engine); + } + else + return EGL_FALSE; +} + + +EGLDisplay APIENTRY +eglGetCurrentDisplay(void) +{ + _EGLDisplay *dpy = _eglGetCurrentDisplay(); + if (dpy) + return dpy->Handle; + else + return EGL_NO_DISPLAY; +} + + +EGLContext APIENTRY +eglGetCurrentContext(void) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + if (ctx) + return ctx->Handle; + else + return EGL_NO_CONTEXT; +} + + +EGLSurface APIENTRY +eglGetCurrentSurface(EGLint readdraw) +{ + _EGLSurface *s = _eglGetCurrentSurface(readdraw); + if (s) + return s->Handle; + else + return EGL_NO_SURFACE; +} + + +EGLint APIENTRY +eglGetError(void) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLint e = t->LastError; + t->LastError = EGL_SUCCESS; + return e; +} + + +void (* APIENTRY eglGetProcAddress(const char *procname))() +{ + typedef void (*genericFunc)(); + struct name_function { + const char *name; + _EGLProc function; + }; + static struct name_function egl_functions[] = { + /* alphabetical order */ + { "eglBindTexImage", (_EGLProc) eglBindTexImage }, + { "eglChooseConfig", (_EGLProc) eglChooseConfig }, + { "eglCopyBuffers", (_EGLProc) eglCopyBuffers }, + { "eglCreateContext", (_EGLProc) eglCreateContext }, + { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface }, + { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface }, + { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface }, + { "eglDestroyContext", (_EGLProc) eglDestroyContext }, + { "eglDestroySurface", (_EGLProc) eglDestroySurface }, + { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib }, + { "eglGetConfigs", (_EGLProc) eglGetConfigs }, + { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext }, + { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay }, + { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface }, + { "eglGetDisplay", (_EGLProc) eglGetDisplay }, + { "eglGetError", (_EGLProc) eglGetError }, + { "eglGetProcAddress", (_EGLProc) eglGetProcAddress }, + { "eglInitialize", (_EGLProc) eglInitialize }, + { "eglMakeCurrent", (_EGLProc) eglMakeCurrent }, + { "eglQueryContext", (_EGLProc) eglQueryContext }, + { "eglQueryString", (_EGLProc) eglQueryString }, + { "eglQuerySurface", (_EGLProc) eglQuerySurface }, + { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage }, + { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib }, + { "eglSwapBuffers", (_EGLProc) eglSwapBuffers }, + { "eglSwapInterval", (_EGLProc) eglSwapInterval }, + { "eglTerminate", (_EGLProc) eglTerminate }, + { "eglWaitGL", (_EGLProc) eglWaitGL }, + { "eglWaitNative", (_EGLProc) eglWaitNative }, + /* Extensions */ +#ifdef EGL_MESA_screen_surface + { "eglChooseModeMESA", (_EGLProc) eglChooseModeMESA }, + { "eglGetModesMESA", (_EGLProc) eglGetModesMESA }, + { "eglGetModeAttribMESA", (_EGLProc) eglGetModeAttribMESA }, + { "eglCopyContextMESA", (_EGLProc) eglCopyContextMESA }, + { "eglGetScreensMESA", (_EGLProc) eglGetScreensMESA }, + { "eglCreateScreenSurfaceMESA", (_EGLProc) eglCreateScreenSurfaceMESA }, + { "eglShowScreenSurfaceMESA", (_EGLProc) eglShowScreenSurfaceMESA }, + { "eglScreenPositionMESA", (_EGLProc) eglScreenPositionMESA }, + { "eglQueryScreenMESA", (_EGLProc) eglQueryScreenMESA }, + { "eglQueryScreenSurfaceMESA", (_EGLProc) eglQueryScreenSurfaceMESA }, + { "eglQueryScreenModeMESA", (_EGLProc) eglQueryScreenModeMESA }, + { "eglQueryModeStringMESA", (_EGLProc) eglQueryModeStringMESA }, +#endif /* EGL_MESA_screen_surface */ +#ifdef EGL_VERSION_1_2 + { "eglBindAPI", (_EGLProc) eglBindAPI }, + { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer }, + { "eglQueryAPI", (_EGLProc) eglQueryAPI }, + { "eglReleaseThread", (_EGLProc) eglReleaseThread }, + { "eglWaitClient", (_EGLProc) eglWaitClient }, +#endif /* EGL_VERSION_1_2 */ + { NULL, NULL } + }; + EGLint i; + for (i = 0; egl_functions[i].name; i++) { + if (strcmp(egl_functions[i].name, procname) == 0) { + return (genericFunc) egl_functions[i].function; + } + } +#if 0 + /* XXX enable this code someday */ + return (genericFunc) _glapi_get_proc_address(procname); +#else + return NULL; +#endif +} + + +/* + * EGL_MESA_screen extension + */ + +EGLBoolean APIENTRY +eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, + const EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return drv->API.ChooseModeMESA(drv, dpy, screen, attrib_list, modes, modes_size, num_modes); + else + return EGL_FALSE; +} + + +EGLBoolean APIENTRY +eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return drv->API.GetModesMESA(drv, dpy, screen, modes, mode_size, num_mode); + else + return EGL_FALSE; +} + + +EGLBoolean APIENTRY +eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return drv->API.GetModeAttribMESA(drv, dpy, mode, attribute, value); + else + return EGL_FALSE; +} + + +EGLBoolean APIENTRY +eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return drv->API.CopyContextMESA(drv, dpy, source, dest, mask); + else + return EGL_FALSE; +} + + +EGLBoolean +eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + if (drv) + return drv->API.GetScreensMESA(drv, dpy, screens, max_screens, num_screens); + else + return EGL_FALSE; +} + + +EGLSurface +eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CreateScreenSurfaceMESA(drv, dpy, config, attrib_list); +} + + +EGLBoolean +eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.ShowScreenSurfaceMESA(drv, dpy, screen, surface, mode); +} + + +EGLBoolean +eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.ScreenPositionMESA(drv, dpy, screen, x, y); +} + + +EGLBoolean +eglQueryScreenMESA( EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.QueryScreenMESA(drv, dpy, screen, attribute, value); +} + + +EGLBoolean +eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.QueryScreenSurfaceMESA(drv, dpy, screen, surface); +} + + +EGLBoolean +eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.QueryScreenModeMESA(drv, dpy, screen, mode); +} + + +const char * +eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.QueryModeStringMESA(drv, dpy, mode); +} + + +/** + ** EGL 1.2 + **/ + +#ifdef EGL_VERSION_1_2 + +EGLBoolean +eglBindAPI(EGLenum api) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + + switch (api) { + case EGL_OPENGL_ES_API: + if (_eglGlobal.OpenGLESAPISupported) { + t->CurrentAPI = api; + return EGL_TRUE; + } + _eglError(EGL_BAD_PARAMETER, "eglBindAPI"); + return EGL_FALSE; + case EGL_OPENVG_API: + if (_eglGlobal.OpenVGAPISupported) { + t->CurrentAPI = api; + return EGL_TRUE; + } + _eglError(EGL_BAD_PARAMETER, "eglBindAPI"); + return EGL_FALSE; + default: + return EGL_FALSE; + } + return EGL_TRUE; +} + + +EGLSurface +eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, + EGLClientBuffer buffer, EGLConfig config, + const EGLint *attrib_list) +{ + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.CreatePbufferFromClientBuffer(drv, dpy, buftype, buffer, + config, attrib_list); +} + + +EGLenum +eglQueryAPI(void) +{ + /* returns one of EGL_OPENGL_ES_API or EGL_OPENVG_API */ + _EGLThreadInfo *t = _eglGetCurrentThread(); + return t->CurrentAPI; +} + + +EGLBoolean +eglReleaseThread(void) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLDisplay dpy = eglGetCurrentDisplay(); + if (dpy) { + _EGLDriver *drv = _eglLookupDriver(dpy); + /* unbind context */ + (void) drv->API.MakeCurrent(drv, dpy, EGL_NO_SURFACE, + EGL_NO_SURFACE, EGL_NO_CONTEXT); + } + _eglDeleteThreadData(t); + return EGL_TRUE; +} + + +EGLBoolean +eglWaitClient(void) +{ + EGLDisplay dpy = eglGetCurrentDisplay(); + if (dpy != EGL_NO_DISPLAY) { + _EGLDriver *drv = _eglLookupDriver(dpy); + return drv->API.WaitClient(drv, dpy); + } + else + return EGL_FALSE; +} + +#endif /* EGL_VERSION_1_2 */ --- mesa-7.2.orig/src/egl/main/eglhash.c +++ mesa-7.2/src/egl/main/eglhash.c @@ -0,0 +1,347 @@ +/** + * \file hash.c + * Generic hash table. + * + * This code taken from Mesa and adapted. + */ + +#include +#include +#include +#include "eglhash.h" + + +#define TABLE_SIZE 1023 /**< Size of lookup table/array */ + +#define HASH_FUNC(K) ((K) % TABLE_SIZE) + + +/* + * Unfinished mutex stuff + */ + +typedef int _EGLMutex; + +static void +_eglInitMutex(_EGLMutex m) +{ +} + +static void +_eglDestroyMutex(_EGLMutex m) +{ +} + +static void +_eglLockMutex(_EGLMutex m) +{ +} + +static void +_eglUnlockMutex(_EGLMutex m) +{ +} + + + +typedef struct _egl_hashentry _EGLHashentry; + +struct _egl_hashentry +{ + EGLuint Key; /**< the entry's key */ + void *Data; /**< the entry's data */ + _EGLHashentry *Next; /**< pointer to next entry */ +}; + + +struct _egl_hashtable +{ + _EGLHashentry *Table[TABLE_SIZE]; /**< the lookup table */ + EGLuint MaxKey; /**< highest key inserted so far */ + _EGLMutex Mutex; /**< mutual exclusion lock */ +}; + + +/** + * Create a new hash table. + * + * \return pointer to a new, empty hash table. + */ +_EGLHashtable * +_eglNewHashTable(void) +{ + _EGLHashtable *table = (_EGLHashtable *) calloc(1, sizeof(_EGLHashtable)); + if (table) { + _eglInitMutex(table->Mutex); + table->MaxKey = 1; + } + return table; +} + + + +/** + * Delete a hash table. + * Frees each entry on the hash table and then the hash table structure itself. + * Note that the caller should have already traversed the table and deleted + * the objects in the table (i.e. We don't free the entries' data pointer). + * + * \param table the hash table to delete. + */ +void +_eglDeleteHashTable(_EGLHashtable *table) +{ + EGLuint i; + assert(table); + for (i = 0; i < TABLE_SIZE; i++) { + _EGLHashentry *entry = table->Table[i]; + while (entry) { + _EGLHashentry *next = entry->Next; + free(entry); + entry = next; + } + } + _eglDestroyMutex(table->Mutex); + free(table); +} + + + +/** + * Lookup an entry in the hash table. + * + * \param table the hash table. + * \param key the key. + * + * \return pointer to user's data or NULL if key not in table + */ +void * +_eglHashLookup(const _EGLHashtable *table, EGLuint key) +{ + EGLuint pos; + const _EGLHashentry *entry; + + assert(table); + + if (!key) + return NULL; + + pos = HASH_FUNC(key); + entry = table->Table[pos]; + while (entry) { + if (entry->Key == key) { + return entry->Data; + } + entry = entry->Next; + } + return NULL; +} + + + +/** + * Insert a key/pointer pair into the hash table. + * If an entry with this key already exists we'll replace the existing entry. + * + * \param table the hash table. + * \param key the key (not zero). + * \param data pointer to user data. + */ +void +_eglHashInsert(_EGLHashtable *table, EGLuint key, void *data) +{ + /* search for existing entry with this key */ + EGLuint pos; + _EGLHashentry *entry; + + assert(table); + assert(key); + + _eglLockMutex(table->Mutex); + + if (key > table->MaxKey) + table->MaxKey = key; + + pos = HASH_FUNC(key); + entry = table->Table[pos]; + while (entry) { + if (entry->Key == key) { + /* replace entry's data */ + entry->Data = data; + _eglUnlockMutex(table->Mutex); + return; + } + entry = entry->Next; + } + + /* alloc and insert new table entry */ + entry = (_EGLHashentry *) malloc(sizeof(_EGLHashentry)); + entry->Key = key; + entry->Data = data; + entry->Next = table->Table[pos]; + table->Table[pos] = entry; + + _eglUnlockMutex(table->Mutex); +} + + + +/** + * Remove an entry from the hash table. + * + * \param table the hash table. + * \param key key of entry to remove. + * + * While holding the hash table's lock, searches the entry with the matching + * key and unlinks it. + */ +void +_eglHashRemove(_EGLHashtable *table, EGLuint key) +{ + EGLuint pos; + _EGLHashentry *entry, *prev; + + assert(table); + assert(key); + + _eglLockMutex(table->Mutex); + + pos = HASH_FUNC(key); + prev = NULL; + entry = table->Table[pos]; + while (entry) { + if (entry->Key == key) { + /* found it! */ + if (prev) { + prev->Next = entry->Next; + } + else { + table->Table[pos] = entry->Next; + } + free(entry); + _eglUnlockMutex(table->Mutex); + return; + } + prev = entry; + entry = entry->Next; + } + + _eglUnlockMutex(table->Mutex); +} + + + +/** + * Get the key of the "first" entry in the hash table. + * + * This is used in the course of deleting all display lists when + * a context is destroyed. + * + * \param table the hash table + * + * \return key for the "first" entry in the hash table. + * + * While holding the lock, walks through all table positions until finding + * the first entry of the first non-empty one. + */ +EGLuint +_eglHashFirstEntry(_EGLHashtable *table) +{ + EGLuint pos; + assert(table); + _eglLockMutex(table->Mutex); + for (pos = 0; pos < TABLE_SIZE; pos++) { + if (table->Table[pos]) { + _eglUnlockMutex(table->Mutex); + return table->Table[pos]->Key; + } + } + _eglUnlockMutex(table->Mutex); + return 0; +} + + +/** + * Given a hash table key, return the next key. This is used to walk + * over all entries in the table. Note that the keys returned during + * walking won't be in any particular order. + * \return next hash key or 0 if end of table. + */ +EGLuint +_eglHashNextEntry(const _EGLHashtable *table, EGLuint key) +{ + const _EGLHashentry *entry; + EGLuint pos; + + assert(table); + assert(key); + + /* Find the entry with given key */ + pos = HASH_FUNC(key); + entry = table->Table[pos]; + while (entry) { + if (entry->Key == key) { + break; + } + entry = entry->Next; + } + + if (!entry) { + /* the key was not found, we can't find next entry */ + return 0; + } + + if (entry->Next) { + /* return next in linked list */ + return entry->Next->Key; + } + else { + /* look for next non-empty table slot */ + pos++; + while (pos < TABLE_SIZE) { + if (table->Table[pos]) { + return table->Table[pos]->Key; + } + pos++; + } + return 0; + } +} + + +/** + * Dump contents of hash table for debugging. + * + * \param table the hash table. + */ +void +_eglHashPrint(const _EGLHashtable *table) +{ + EGLuint i; + assert(table); + for (i = 0; i < TABLE_SIZE; i++) { + const _EGLHashentry *entry = table->Table[i]; + while (entry) { + printf("%u %p\n", entry->Key, entry->Data); + entry = entry->Next; + } + } +} + + + +/** + * Return a new, unused hash key. + */ +EGLuint +_eglHashGenKey(_EGLHashtable *table) +{ + EGLuint k; + + _eglLockMutex(table->Mutex); + k = table->MaxKey; + table->MaxKey++; + _eglUnlockMutex(table->Mutex); + return k; +} + --- mesa-7.2.orig/src/egl/main/eglconfig.h +++ mesa-7.2/src/egl/main/eglconfig.h @@ -0,0 +1,67 @@ +#ifndef EGLCONFIG_INCLUDED +#define EGLCONFIG_INCLUDED + + +#include "egltypedefs.h" +#include "GL/internal/glcore.h" + + +#define MAX_ATTRIBS 100 +#define FIRST_ATTRIB EGL_BUFFER_SIZE + + +struct _egl_config +{ + EGLConfig Handle; /* the public/opaque handle which names this config */ + EGLint Attrib[MAX_ATTRIBS]; +}; + + +#define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) ((CONF)->Attrib[(ATTR) - FIRST_ATTRIB] = VAL) +#define GET_CONFIG_ATTRIB(CONF, ATTR) ((CONF)->Attrib[(ATTR) - FIRST_ATTRIB]) + + +extern void +_eglInitConfig(_EGLConfig *config, EGLint id); + + +extern _EGLConfig * +_eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config); + + +extern _EGLConfig * +_eglAddConfig(_EGLDisplay *display, const _EGLConfig *config); + + +extern EGLBoolean +_eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list); + + +extern EGLBoolean +_eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); + + +extern EGLBoolean +_eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); + + +extern EGLBoolean +_eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); + + +extern void +_eglSetConfigAttrib(_EGLConfig *config, EGLint attr, EGLint val); + +extern GLboolean +_eglFillInConfigs( _EGLConfig *configs, + GLenum fb_format, GLenum fb_type, + const u_int8_t * depth_bits, const u_int8_t * stencil_bits, + unsigned num_depth_stencil_bits, + const GLenum * db_modes, unsigned num_db_modes, + int visType ); + +extern void +_eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode); + + +#endif /* EGLCONFIG_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglconfig.c +++ mesa-7.2/src/egl/main/eglconfig.c @@ -0,0 +1,638 @@ +/** + * EGL Configuration (pixel format) functions. + */ + + +#include +#include +#include +#include +#include "eglconfig.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglglobals.h" +#include "egllog.h" + + +#define MIN2(A, B) (((A) < (B)) ? (A) : (B)) + + +/** + * Convert an _EGLConfig to a __GLcontextModes object. + * NOTE: This routine may be incomplete - we're only making sure that + * the fields needed by Mesa (for _mesa_create_context/framebuffer) are + * set correctly. + */ +void +_eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode) +{ + memset(mode, 0, sizeof(*mode)); + + mode->rgbMode = GL_TRUE; /* no color index */ + mode->colorIndexMode = GL_FALSE; + mode->doubleBufferMode = GL_TRUE; /* always DB for now */ + mode->stereoMode = GL_FALSE; + + mode->redBits = GET_CONFIG_ATTRIB(config, EGL_RED_SIZE); + mode->greenBits = GET_CONFIG_ATTRIB(config, EGL_GREEN_SIZE); + mode->blueBits = GET_CONFIG_ATTRIB(config, EGL_BLUE_SIZE); + mode->alphaBits = GET_CONFIG_ATTRIB(config, EGL_ALPHA_SIZE); + mode->rgbBits = GET_CONFIG_ATTRIB(config, EGL_BUFFER_SIZE); + + /* no rgba masks - fix? */ + + mode->depthBits = GET_CONFIG_ATTRIB(config, EGL_DEPTH_SIZE); + mode->haveDepthBuffer = mode->depthBits > 0; + + mode->stencilBits = GET_CONFIG_ATTRIB(config, EGL_STENCIL_SIZE); + mode->haveStencilBuffer = mode->stencilBits > 0; + + /* no accum */ + + mode->level = GET_CONFIG_ATTRIB(config, EGL_LEVEL); + mode->samples = GET_CONFIG_ATTRIB(config, EGL_SAMPLES); + mode->sampleBuffers = GET_CONFIG_ATTRIB(config, EGL_SAMPLE_BUFFERS); + + /* surface type - not really needed */ + mode->visualType = GLX_TRUE_COLOR; + mode->renderType = GLX_RGBA_BIT; +} + + +void +_eglSetConfigAttrib(_EGLConfig *config, EGLint attr, EGLint val) +{ + assert(attr >= FIRST_ATTRIB); + assert(attr < FIRST_ATTRIB + MAX_ATTRIBS); + config->Attrib[attr - FIRST_ATTRIB] = val; +} + + +/** + * Init the given _EGLconfig to default values. + * \param id the configuration's ID. + */ +void +_eglInitConfig(_EGLConfig *config, EGLint id) +{ + memset(config, 0, sizeof(*config)); + config->Handle = id; + _eglSetConfigAttrib(config, EGL_CONFIG_ID, id); + _eglSetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_CONFIG_CAVEAT, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_NATIVE_RENDERABLE, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, + EGL_SCREEN_BIT_MESA | EGL_PBUFFER_BIT | + EGL_PIXMAP_BIT | EGL_WINDOW_BIT); + _eglSetConfigAttrib(config, EGL_TRANSPARENT_TYPE, EGL_NONE); + _eglSetConfigAttrib(config, EGL_TRANSPARENT_RED_VALUE, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_TRANSPARENT_GREEN_VALUE, EGL_DONT_CARE); + _eglSetConfigAttrib(config, EGL_TRANSPARENT_BLUE_VALUE, EGL_DONT_CARE); +#ifdef EGL_VERSION_1_2 + _eglSetConfigAttrib(config, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER); + _eglSetConfigAttrib(config, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT); +#endif /* EGL_VERSION_1_2 */ +} + + +/** + * Given an EGLConfig handle, return the corresponding _EGLConfig object. + */ +_EGLConfig * +_eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config) +{ + EGLint i; + _EGLDisplay *disp = _eglLookupDisplay(dpy); + for (i = 0; i < disp->NumConfigs; i++) { + if (disp->Configs[i].Handle == config) { + return disp->Configs + i; + } + } + return NULL; +} + + +/** + * Add the given _EGLConfig to the given display. + */ +_EGLConfig * +_eglAddConfig(_EGLDisplay *display, const _EGLConfig *config) +{ + _EGLConfig *newConfigs; + EGLint n; + + n = display->NumConfigs; + + newConfigs = (_EGLConfig *) realloc(display->Configs, + (n + 1) * sizeof(_EGLConfig)); + if (newConfigs) { + display->Configs = newConfigs; + display->Configs[n] = *config; /* copy struct */ + display->Configs[n].Handle = n; + display->NumConfigs++; + return display->Configs + n; + } + else { + return NULL; + } +} + + +/** + * Parse the attrib_list to fill in the fields of the given _eglConfig + * Return EGL_FALSE if any errors, EGL_TRUE otherwise. + */ +EGLBoolean +_eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list) +{ + EGLint i; + + /* set all config attribs to EGL_DONT_CARE */ + for (i = 0; i < MAX_ATTRIBS; i++) { + config->Attrib[i] = EGL_DONT_CARE; + } + + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + const EGLint attr = attrib_list[i]; + if (attr >= EGL_BUFFER_SIZE && + attr <= EGL_MAX_SWAP_INTERVAL) { + EGLint k = attr - FIRST_ATTRIB; + assert(k >= 0); + assert(k < MAX_ATTRIBS); + config->Attrib[k] = attrib_list[++i]; + } +#ifdef EGL_VERSION_1_2 + else if (attr == EGL_COLOR_BUFFER_TYPE) { + EGLint bufType = attrib_list[++i]; + if (bufType != EGL_RGB_BUFFER && bufType != EGL_LUMINANCE_BUFFER) { + _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); + return EGL_FALSE; + } + _eglSetConfigAttrib(config, EGL_COLOR_BUFFER_TYPE, bufType); + } + else if (attr == EGL_RENDERABLE_TYPE) { + EGLint renType = attrib_list[++i]; + if (renType & ~(EGL_OPENGL_ES_BIT | EGL_OPENVG_BIT)) { + _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); + return EGL_FALSE; + } + _eglSetConfigAttrib(config, EGL_RENDERABLE_TYPE, renType); + } + else if (attr == EGL_ALPHA_MASK_SIZE || + attr == EGL_LUMINANCE_SIZE) { + EGLint value = attrib_list[++i]; + _eglSetConfigAttrib(config, attr, value); + } +#endif /* EGL_VERSION_1_2 */ + else { + _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); + return EGL_FALSE; + } + } + return EGL_TRUE; +} + + +#define EXACT 1 +#define ATLEAST 2 +#define MASK 3 +#define SMALLER 4 +#define SPECIAL 5 +#define NONE 6 + +struct sort_info { + EGLint Attribute; + EGLint MatchCriteria; + EGLint SortOrder; +}; + +/* This encodes the info from Table 3.5 of the EGL spec, ordered by + * Sort Priority. + * + * XXX To do: EGL 1.2 attribs + */ +static struct sort_info SortInfo[] = { + { EGL_CONFIG_CAVEAT, EXACT, SPECIAL }, + { EGL_RED_SIZE, ATLEAST, SPECIAL }, + { EGL_GREEN_SIZE, ATLEAST, SPECIAL }, + { EGL_BLUE_SIZE, ATLEAST, SPECIAL }, + { EGL_ALPHA_SIZE, ATLEAST, SPECIAL }, + { EGL_BUFFER_SIZE, ATLEAST, SMALLER }, + { EGL_SAMPLE_BUFFERS, ATLEAST, SMALLER }, + { EGL_SAMPLES, ATLEAST, SMALLER }, + { EGL_DEPTH_SIZE, ATLEAST, SMALLER }, + { EGL_STENCIL_SIZE, ATLEAST, SMALLER }, + { EGL_NATIVE_VISUAL_TYPE, EXACT, SPECIAL }, + { EGL_CONFIG_ID, EXACT, SMALLER }, + { EGL_BIND_TO_TEXTURE_RGB, EXACT, NONE }, + { EGL_BIND_TO_TEXTURE_RGBA, EXACT, NONE }, + { EGL_LEVEL, EXACT, NONE }, + { EGL_NATIVE_RENDERABLE, EXACT, NONE }, + { EGL_MAX_SWAP_INTERVAL, EXACT, NONE }, + { EGL_MIN_SWAP_INTERVAL, EXACT, NONE }, + { EGL_SURFACE_TYPE, MASK, NONE }, + { EGL_TRANSPARENT_TYPE, EXACT, NONE }, + { EGL_TRANSPARENT_RED_VALUE, EXACT, NONE }, + { EGL_TRANSPARENT_GREEN_VALUE, EXACT, NONE }, + { EGL_TRANSPARENT_BLUE_VALUE, EXACT, NONE }, + { 0, 0, 0 } +}; + + +/** + * Return EGL_TRUE if the attributes of c meet or exceed the minimums + * specified by min. + */ +static EGLBoolean +_eglConfigQualifies(const _EGLConfig *c, const _EGLConfig *min) +{ + EGLint i; + for (i = 0; SortInfo[i].Attribute != 0; i++) { + const EGLint mv = GET_CONFIG_ATTRIB(min, SortInfo[i].Attribute); + if (mv != EGL_DONT_CARE) { + const EGLint cv = GET_CONFIG_ATTRIB(c, SortInfo[i].Attribute); + if (SortInfo[i].MatchCriteria == EXACT) { + if (cv != mv) { + return EGL_FALSE; + } + } + else if (SortInfo[i].MatchCriteria == ATLEAST) { + if (cv < mv) { + return EGL_FALSE; + } + } + else { + assert(SortInfo[i].MatchCriteria == MASK); + if ((mv & cv) != mv) { + return EGL_FALSE; + } + } + } + } + return EGL_TRUE; +} + + +/** + * Compare configs 'a' and 'b' and return -1 if a belongs before b, + * 1 if a belongs after b, or 0 if they're equal. + * Used by qsort(). + */ +static int +_eglCompareConfigs(const void *a, const void *b) +{ + const _EGLConfig *aConfig = (const _EGLConfig *) a; + const _EGLConfig *bConfig = (const _EGLConfig *) b; + EGLint i; + + for (i = 0; SortInfo[i].Attribute != 0; i++) { + const EGLint aVal = GET_CONFIG_ATTRIB(aConfig, SortInfo[i].Attribute); + const EGLint bVal = GET_CONFIG_ATTRIB(bConfig, SortInfo[i].Attribute); + if (SortInfo[i].SortOrder == SMALLER) { + if (aVal < bVal) + return -1; + else if (aVal > bVal) + return 1; + /* else, continue examining attribute values */ + } + else if (SortInfo[i].SortOrder == SPECIAL) { + if (SortInfo[i].Attribute == EGL_CONFIG_CAVEAT) { + /* values are EGL_NONE, SLOW_CONFIG, or NON_CONFORMANT_CONFIG */ + if (aVal < bVal) + return -1; + else if (aVal > bVal) + return 1; + } + else if (SortInfo[i].Attribute == EGL_RED_SIZE || + SortInfo[i].Attribute == EGL_GREEN_SIZE || + SortInfo[i].Attribute == EGL_BLUE_SIZE || + SortInfo[i].Attribute == EGL_ALPHA_SIZE) { + if (aVal > bVal) + return -1; + else if (aVal < bVal) + return 1; + } + else { + assert(SortInfo[i].Attribute == EGL_NATIVE_VISUAL_TYPE); + if (aVal < bVal) + return -1; + else if (aVal > bVal) + return 1; + } + } + else { + assert(SortInfo[i].SortOrder == NONE); + /* continue examining attribute values */ + } + } + + /* all attributes identical */ + return 0; +} + + +/** + * Typical fallback routine for eglChooseConfig + */ +EGLBoolean +_eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, EGLint *num_configs) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + _EGLConfig **configList, criteria; + EGLint i, count; + + /* parse the attrib_list to initialize criteria */ + if (!_eglParseConfigAttribs(&criteria, attrib_list)) { + return EGL_FALSE; + } + + /* allocate array of config pointers */ + configList = (_EGLConfig **) malloc(config_size * sizeof(_EGLConfig *)); + if (!configList) { + _eglError(EGL_BAD_CONFIG, "eglChooseConfig(out of memory)"); + return EGL_FALSE; + } + + /* make array of pointers to qualifying configs */ + for (i = count = 0; i < disp->NumConfigs && count < config_size; i++) { + if (_eglConfigQualifies(disp->Configs + i, &criteria)) { + configList[count++] = disp->Configs + i; + } + } + + /* sort array of pointers */ + qsort(configList, count, sizeof(_EGLConfig *), _eglCompareConfigs); + + /* copy config handles to output array */ + for (i = 0; i < count; i++) { + configs[i] = configList[i]->Handle; + } + + free(configList); + + *num_configs = count; + + return EGL_TRUE; +} + + +/** + * Fallback for eglGetConfigAttrib. + */ +EGLBoolean +_eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value) +{ + const _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); + const EGLint k = attribute - FIRST_ATTRIB; + if (k >= 0 && k < MAX_ATTRIBS) { + *value = conf->Attrib[k]; + return EGL_TRUE; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib"); + return EGL_FALSE; + } +} + + +/** + * Fallback for eglGetConfigs. + */ +EGLBoolean +_eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config) +{ + _EGLDisplay *disp = _eglLookupDisplay(dpy); + + if (!drv->Initialized) { + _eglError(EGL_NOT_INITIALIZED, "eglGetConfigs"); + return EGL_FALSE; + } + + if (configs) { + EGLint i; + *num_config = MIN2(disp->NumConfigs, config_size); + for (i = 0; i < *num_config; i++) { + configs[i] = disp->Configs[i].Handle; + } + } + else { + /* just return total number of supported configs */ + *num_config = disp->NumConfigs; + } + + return EGL_TRUE; +} + + +/** + * Creates a set of \c __GLcontextModes that a driver will expose. + * + * A set of \c __GLcontextModes will be created based on the supplied + * parameters. The number of modes processed will be 2 * + * \c num_depth_stencil_bits * \c num_db_modes. + * + * For the most part, data is just copied from \c depth_bits, \c stencil_bits, + * \c db_modes, and \c visType into each \c __GLcontextModes element. + * However, the meanings of \c fb_format and \c fb_type require further + * explanation. The \c fb_format specifies which color components are in + * each pixel and what the default order is. For example, \c GL_RGB specifies + * that red, green, blue are available and red is in the "most significant" + * position and blue is in the "least significant". The \c fb_type specifies + * the bit sizes of each component and the actual ordering. For example, if + * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11] + * are the blue value, bits [10:5] are the green value, and bits [4:0] are + * the red value. + * + * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either + * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the + * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or + * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as + * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8 + * still uses 32-bits. + * + * If in doubt, look at the tables used in the function. + * + * \param ptr_to_modes Pointer to a pointer to a linked list of + * \c __GLcontextModes. Upon completion, a pointer to + * the next element to be process will be stored here. + * If the function fails and returns \c GL_FALSE, this + * value will be unmodified, but some elements in the + * linked list may be modified. + * \param fb_format Format of the framebuffer. Currently only \c GL_RGB, + * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported. + * \param fb_type Type of the pixels in the framebuffer. Currently only + * \c GL_UNSIGNED_SHORT_5_6_5, + * \c GL_UNSIGNED_SHORT_5_6_5_REV, + * \c GL_UNSIGNED_INT_8_8_8_8, and + * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported. + * \param depth_bits Array of depth buffer sizes to be exposed. + * \param stencil_bits Array of stencil buffer sizes to be exposed. + * \param num_depth_stencil_bits Number of entries in both \c depth_bits and + * \c stencil_bits. + * \param db_modes Array of buffer swap modes. If an element has a + * value of \c GLX_NONE, then it represents a + * single-buffered mode. Other valid values are + * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and + * \c GLX_SWAP_UNDEFINED_OML. See the + * GLX_OML_swap_method extension spec for more details. + * \param num_db_modes Number of entries in \c db_modes. + * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or + * \c GLX_DIRECT_COLOR. + * + * \returns + * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only + * cause of failure is a bad parameter (i.e., unsupported \c fb_format or + * \c fb_type). + * + * \todo + * There is currently no way to support packed RGB modes (i.e., modes with + * exactly 3 bytes per pixel) or floating-point modes. This could probably + * be done by creating some new, private enums with clever names likes + * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, + * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it. + */ +GLboolean +_eglFillInConfigs(_EGLConfig * configs, + GLenum fb_format, GLenum fb_type, + const u_int8_t * depth_bits, const u_int8_t * stencil_bits, + unsigned num_depth_stencil_bits, + const GLenum * db_modes, unsigned num_db_modes, + int visType) +{ + static const u_int8_t bits_table[3][4] = { + /* R G B A */ + { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */ + { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */ + { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */ + }; + + /* The following arrays are all indexed by the fb_type masked with 0x07. + * Given the four supported fb_type values, this results in valid array + * indices of 3, 4, 5, and 7. + */ + static const u_int32_t masks_table_rgb[8][4] = { + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */ + {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */ + {0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000}, /* 8_8_8_8 */ + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000} /* 8_8_8_8_REV */ + }; + + static const u_int32_t masks_table_rgba[8][4] = { + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */ + {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */ + {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF}, /* 8_8_8_8 */ + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, /* 8_8_8_8_REV */ + }; + + static const u_int32_t masks_table_bgr[8][4] = { + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */ + {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */ + {0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000}, /* 8_8_8_8 */ + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000}, /* 8_8_8_8_REV */ + }; + + static const u_int32_t masks_table_bgra[8][4] = { + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */ + {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */ + {0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF}, /* 8_8_8_8 */ + {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, /* 8_8_8_8_REV */ + }; + + static const u_int8_t bytes_per_pixel[8] = { + 0, 0, 0, 2, 2, 4, 0, 4 + }; + + const u_int8_t * bits; + const u_int32_t * masks; + const int index = fb_type & 0x07; + _EGLConfig *config; + unsigned i; + unsigned j; + unsigned k; + + if ( bytes_per_pixel[index] == 0 ) { + _eglLog(_EGL_INFO, + "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.", + __FUNCTION__, __LINE__, fb_type); + return GL_FALSE; + } + + /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and + * the _REV versions. + * + * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA. + */ + switch ( fb_format ) { + case GL_RGB: + bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1]; + masks = masks_table_rgb[index]; + break; + + case GL_RGBA: + bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2]; + masks = masks_table_rgba[index]; + break; + + case GL_BGR: + bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1]; + masks = masks_table_bgr[index]; + break; + + case GL_BGRA: + bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2]; + masks = masks_table_bgra[index]; + break; + + default: + _eglLog(_EGL_WARNING, + "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.", + __FUNCTION__, __LINE__, fb_format); + return GL_FALSE; + } + + config = configs; + for (k = 0; k < num_depth_stencil_bits; k++) { + for (i = 0; i < num_db_modes; i++) { + for (j = 0; j < 2; j++) { + _eglSetConfigAttrib(config, EGL_RED_SIZE, bits[0]); + _eglSetConfigAttrib(config, EGL_GREEN_SIZE, bits[1]); + _eglSetConfigAttrib(config, EGL_BLUE_SIZE, bits[2]); + _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, bits[3]); + _eglSetConfigAttrib(config, EGL_BUFFER_SIZE, + bits[0] + bits[1] + bits[2] + bits[3]); + + _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, stencil_bits[k]); + _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, depth_bits[i]); + + _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_SCREEN_BIT_MESA | + EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT); + + config++; + } + } + } + return GL_TRUE; +} --- mesa-7.2.orig/src/egl/main/egldriver.h +++ mesa-7.2/src/egl/main/egldriver.h @@ -0,0 +1,81 @@ +#ifndef EGLDRIVER_INCLUDED +#define EGLDRIVER_INCLUDED + + +#include "egltypedefs.h" +#include "eglapi.h" + +/* should probably use a dynamic-length string, but this will do */ +#define MAX_EXTENSIONS_LEN 1000 + + +/** + * Optional EGL extensions info. + */ +struct _egl_extensions +{ + EGLBoolean MESA_screen_surface; + EGLBoolean MESA_copy_context; + + char String[MAX_EXTENSIONS_LEN]; +}; + + +/** + * Base class for device drivers. + */ +struct _egl_driver +{ + EGLBoolean Initialized; /* set by driver after initialized */ + + void *LibHandle; /* dlopen handle */ + + _EGLDisplay *Display; + + int ABIversion; + int APImajor, APIminor; /* returned through eglInitialize */ + const char *ClientAPIs; + + _EGLAPI API; + + _EGLExtensions Extensions; +}; + + +extern _EGLDriver *_eglMain(_EGLDisplay *dpy); + + +extern _EGLDriver * +_eglChooseDriver(EGLDisplay dpy); + + +extern _EGLDriver * +_eglOpenDriver(_EGLDisplay *dpy, const char *driverName); + + +extern EGLBoolean +_eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy); + + +extern _EGLDriver * +_eglLookupDriver(EGLDisplay d); + + +extern void +_eglInitDriverFallbacks(_EGLDriver *drv); + + +extern const char * +_eglQueryString(_EGLDriver *drv, EGLDisplay dpy, EGLint name); + + +extern EGLBoolean +_eglWaitGL(_EGLDriver *drv, EGLDisplay dpy); + + +extern EGLBoolean +_eglWaitNative(_EGLDriver *drv, EGLDisplay dpy, EGLint engine); + + + +#endif /* EGLDRIVER_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglglobals.c +++ mesa-7.2/src/egl/main/eglglobals.c @@ -0,0 +1,148 @@ +#include +#include +#include "eglglobals.h" + + +struct _egl_global _eglGlobal = { .Initialized = EGL_FALSE }; + + +/** + * Init the fields in the _eglGlobal struct + * May be safely called more than once. + */ +void +_eglInitGlobals(void) +{ + if (!_eglGlobal.Initialized) { + _eglGlobal.Displays = _eglNewHashTable(); + _eglGlobal.Contexts = _eglNewHashTable(); + _eglGlobal.Surfaces = _eglNewHashTable(); + _eglGlobal.FreeScreenHandle = 1; + _eglGlobal.Initialized = EGL_TRUE; + + _eglGlobal.OpenGLESAPISupported = EGL_TRUE; + _eglGlobal.OpenVGAPISupported = EGL_FALSE; + + /* XXX temporary */ + _eglGlobal.ThreadInfo = _eglNewThreadInfo(); + } +} + + +/** + * Should call this via an atexit handler. + */ +void +_eglDestroyGlobals(void) +{ + /* XXX TODO walk over table entries, deleting each */ + _eglDeleteHashTable(_eglGlobal.Displays); + _eglDeleteHashTable(_eglGlobal.Contexts); + _eglDeleteHashTable(_eglGlobal.Surfaces); +} + + +/** + * Allocate and init a new _EGLThreadInfo object. + */ +_EGLThreadInfo * +_eglNewThreadInfo(void) +{ + _EGLThreadInfo *t = (_EGLThreadInfo *) calloc(1, sizeof(_EGLThreadInfo)); + if (t) { + t->CurrentContext = EGL_NO_CONTEXT; + t->LastError = EGL_SUCCESS; + t->CurrentAPI = EGL_NONE; + } + return t; +} + + +/** + * Delete/free a _EGLThreadInfo object. + */ +void +_eglDeleteThreadData(_EGLThreadInfo *t) +{ + free(t); +} + + + +/** + * Return pointer to calling thread's _EGLThreadInfo object. + * Create a new one if needed. + * Should never return NULL. + */ +_EGLThreadInfo * +_eglGetCurrentThread(void) +{ + _eglInitGlobals(); + + /* XXX temporary */ + return _eglGlobal.ThreadInfo; +} + + +/** + * Record EGL error code. + */ +void +_eglError(EGLint errCode, const char *msg) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + const char *s; + + if (t->LastError == EGL_SUCCESS) { + t->LastError = errCode; + + switch (errCode) { + case EGL_BAD_ACCESS: + s = "EGL_BAD_ACCESS"; + break; + case EGL_BAD_ALLOC: + s = "EGL_BAD_ALLOC"; + break; + case EGL_BAD_ATTRIBUTE: + s = "EGL_BAD_ATTRIBUTE"; + break; + case EGL_BAD_CONFIG: + s = "EGL_BAD_CONFIG"; + break; + case EGL_BAD_CONTEXT: + s = "EGL_BAD_CONTEXT"; + break; + case EGL_BAD_CURRENT_SURFACE: + s = "EGL_BAD_CURRENT_SURFACE"; + break; + case EGL_BAD_DISPLAY: + s = "EGL_BAD_DISPLAY"; + break; + case EGL_BAD_MATCH: + s = "EGL_BAD_MATCH"; + break; + case EGL_BAD_NATIVE_PIXMAP: + s = "EGL_BAD_NATIVE_PIXMAP"; + break; + case EGL_BAD_NATIVE_WINDOW: + s = "EGL_BAD_NATIVE_WINDOW"; + break; + case EGL_BAD_PARAMETER: + s = "EGL_BAD_PARAMETER"; + break; + case EGL_BAD_SURFACE: + s = "EGL_BAD_SURFACE"; + break; + case EGL_BAD_SCREEN_MESA: + s = "EGL_BAD_SCREEN_MESA"; + break; + case EGL_BAD_MODE_MESA: + s = "EGL_BAD_MODE_MESA"; + break; + default: + s = "other"; + } + /* XXX temporary */ + fprintf(stderr, "EGL user error 0x%x (%s) in %s\n", errCode, s, msg); + } +} --- mesa-7.2.orig/src/egl/main/egllog.c +++ mesa-7.2/src/egl/main/egllog.c @@ -0,0 +1,94 @@ +/** + * Logging facility for debug/info messages. + */ + + +#include +#include +#include +#include +#include "egllog.h" + +#define MAXSTRING 1000 +#define FALLBACK_LOG_LEVEL _EGL_DEBUG +#define FALLBACK_LOG_LEVEL_STR "debug" + +static EGLint ReportingLevel = -1; + + +static void +log_level_initialize (void) +{ + char *log_env = getenv ("EGL_LOG_LEVEL"); + + if (log_env == NULL) { + ReportingLevel = FALLBACK_LOG_LEVEL; + } + else if (strcasecmp (log_env, "fatal") == 0) { + ReportingLevel = _EGL_FATAL; + } + else if (strcasecmp (log_env, "warning") == 0) { + ReportingLevel = _EGL_WARNING; + } + else if (strcasecmp (log_env, "info") == 0) { + ReportingLevel = _EGL_INFO; + } + else if (strcasecmp (log_env, "debug") == 0) { + ReportingLevel = _EGL_DEBUG; + } + else { + fprintf (stderr, "Unrecognized EGL_LOG_LEVEL environment variable value. " + "Expected one of \"fatal\", \"warning\", \"info\", \"debug\". " + "Got \"%s\". Falling back to \"%s\".\n", + log_env, FALLBACK_LOG_LEVEL_STR); + ReportingLevel = FALLBACK_LOG_LEVEL; + } +} + + +/** + * Log a message to stderr. + * \param level one of _EGL_FATAL, _EGL_WARNING, _EGL_INFO, _EGL_DEBUG. + */ +void +_eglLog(EGLint level, const char *fmtStr, ...) +{ + va_list args; + char msg[MAXSTRING]; + const char *levelStr; + static int log_level_initialized = 0; + + if (!log_level_initialized) { + log_level_initialize (); + log_level_initialized = 1; + } + + if (level <= ReportingLevel) { + switch (level) { + case _EGL_FATAL: + levelStr = "Fatal"; + break; + case _EGL_WARNING: + levelStr = "Warning"; + break; + case _EGL_INFO: + levelStr = "Info"; + break; + case _EGL_DEBUG: + levelStr = "Debug"; + break; + default: + levelStr = ""; + } + + va_start(args, fmtStr); + vsnprintf(msg, MAXSTRING, fmtStr, args); + va_end(args); + + fprintf(stderr, "EGL %s: %s\n", levelStr, msg); + + if (level == _EGL_FATAL) { + exit(1); /* or abort()? */ + } + } +} --- mesa-7.2.orig/src/egl/main/eglcontext.h +++ mesa-7.2/src/egl/main/eglcontext.h @@ -0,0 +1,71 @@ + +#ifndef EGLCONTEXT_INCLUDED +#define EGLCONTEXT_INCLUDED + + +#include "egltypedefs.h" + + +/** + * "Base" class for device driver contexts. + */ +struct _egl_context +{ + EGLContext Handle; /* The public/opaque handle which names this object */ + + _EGLDisplay *Display; /* who do I belong to? */ + + _EGLConfig *Config; + + _EGLSurface *DrawSurface; + _EGLSurface *ReadSurface; + + EGLBoolean IsBound; + EGLBoolean DeletePending; +#ifdef EGL_VERSION_1_2 + EGLint ClientAPI; /* Either EGL_OPENGL_ES_API or EGL_OPENVG_API */ +#endif /* EGL_VERSION_1_2 */ +}; + + +extern EGLBoolean +_eglInitContext(_EGLDriver *drv, EGLDisplay dpy, _EGLContext *ctx, + EGLConfig config, const EGLint *attrib_list); + + +extern void +_eglSaveContext(_EGLContext *ctx); + + +extern void +_eglRemoveContext(_EGLContext *ctx); + + +extern _EGLContext * +_eglLookupContext(EGLContext ctx); + + +extern _EGLContext * +_eglGetCurrentContext(void); + + +extern EGLContext +_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); + + +extern EGLBoolean +_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx); + + +extern EGLBoolean +_eglQueryContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value); + + +extern EGLBoolean +_eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); + + +extern EGLBoolean +_eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); + +#endif /* EGLCONTEXT_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglcontext.c +++ mesa-7.2/src/egl/main/eglcontext.c @@ -0,0 +1,276 @@ +#include +#include +#include +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglglobals.h" +#include "eglhash.h" +#include "eglsurface.h" + + +/** + * Initialize the given _EGLContext object to defaults. + */ +EGLBoolean +_eglInitContext(_EGLDriver *drv, EGLDisplay dpy, _EGLContext *ctx, + EGLConfig config, const EGLint *attrib_list) +{ + _EGLConfig *conf; + _EGLDisplay *display = _eglLookupDisplay(dpy); + EGLint i; + + conf = _eglLookupConfig(drv, dpy, config); + if (!conf) { + _eglError(EGL_BAD_CONFIG, "eglCreateContext"); + return EGL_FALSE; + } + + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + /* no attribs defined for now */ + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext"); + return EGL_NO_CONTEXT; + } + } + + memset(ctx, 0, sizeof(_EGLContext)); + ctx->Display = display; + ctx->Config = conf; + ctx->DrawSurface = EGL_NO_SURFACE; + ctx->ReadSurface = EGL_NO_SURFACE; + + return EGL_TRUE; +} + + +/* + * Assign an EGLContext handle to the _EGLContext object then put it into + * the hash table. + */ +void +_eglSaveContext(_EGLContext *ctx) +{ + assert(ctx); + ctx->Handle = _eglHashGenKey(_eglGlobal.Contexts); + _eglHashInsert(_eglGlobal.Contexts, ctx->Handle, ctx); +} + + +/** + * Remove the given _EGLContext object from the hash table. + */ +void +_eglRemoveContext(_EGLContext *ctx) +{ + _eglHashRemove(_eglGlobal.Contexts, ctx->Handle); +} + + +/** + * Return the _EGLContext object that corresponds to the given + * EGLContext handle. + */ +_EGLContext * +_eglLookupContext(EGLContext ctx) +{ + _EGLContext *c = (_EGLContext *) _eglHashLookup(_eglGlobal.Contexts, ctx); + return c; +} + + +/** + * Return the currently bound _EGLContext object, or NULL. + */ +_EGLContext * +_eglGetCurrentContext(void) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + return t->CurrentContext; +} + + +/** + * Just a placeholder/demo function. Real driver will never use this! + */ +EGLContext +_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + EGLContext share_list, const EGLint *attrib_list) +{ +#if 0 /* example code */ + _EGLContext *context; + + context = (_EGLContext *) calloc(1, sizeof(_EGLContext)); + if (!context) + return EGL_NO_CONTEXT; + + if (!_eglInitContext(drv, dpy, context, config, attrib_list)) { + free(context); + return EGL_NO_CONTEXT; + } + + _eglSaveContext(context); + return context->Handle; +#endif + return EGL_NO_CONTEXT; +} + + +/** + * Default fallback routine - drivers should usually override this. + */ +EGLBoolean +_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) +{ + _EGLContext *context = _eglLookupContext(ctx); + if (context) { + _eglHashRemove(_eglGlobal.Contexts, ctx); + if (context->IsBound) { + context->DeletePending = EGL_TRUE; + } + else { + free(context); + } + return EGL_TRUE; + } + else { + _eglError(EGL_BAD_CONTEXT, "eglDestroyContext"); + return EGL_TRUE; + } +} + + +EGLBoolean +_eglQueryContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value) +{ + _EGLContext *c = _eglLookupContext(ctx); + + (void) drv; + (void) dpy; + + if (!c) { + _eglError(EGL_BAD_CONTEXT, "eglQueryContext"); + return EGL_FALSE; + } + + switch (attribute) { + case EGL_CONFIG_ID: + *value = GET_CONFIG_ATTRIB(c->Config, EGL_CONFIG_ID); + return EGL_TRUE; +#ifdef EGL_VERSION_1_2 + case EGL_CONTEXT_CLIENT_TYPE: + *value = c->ClientAPI; + return EGL_FALSE; +#endif /* EGL_VERSION_1_2 */ + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext"); + return EGL_FALSE; + } +} + + +/** + * Drivers will typically call this to do the error checking and + * update the various IsBound and DeletePending flags. + * Then, the driver will do its device-dependent Make-Current stuff. + */ +EGLBoolean +_eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, + EGLSurface r, EGLContext context) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + _EGLContext *ctx = _eglLookupContext(context); + _EGLSurface *draw = _eglLookupSurface(d); + _EGLSurface *read = _eglLookupSurface(r); + + _EGLContext *oldContext = _eglGetCurrentContext(); + _EGLSurface *oldDrawSurface = _eglGetCurrentSurface(EGL_DRAW); + _EGLSurface *oldReadSurface = _eglGetCurrentSurface(EGL_READ); + + /* error checking */ + if (ctx) { + if (draw == NULL || read == NULL) { + _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + return EGL_FALSE; + } + if (draw->Config != ctx->Config) { + _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + return EGL_FALSE; + } + if (read->Config != ctx->Config) { + _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + return EGL_FALSE; + } + } + + /* + * check if the old context or surfaces need to be deleted + */ + if (oldDrawSurface != NULL) { + oldDrawSurface->IsBound = EGL_FALSE; + if (oldDrawSurface->DeletePending) { + /* make sure we don't try to rebind a deleted surface */ + if (draw == oldDrawSurface || draw == oldReadSurface) { + draw = NULL; + } + /* really delete surface now */ + drv->API.DestroySurface(drv, dpy, oldDrawSurface->Handle); + } + } + if (oldReadSurface != NULL && oldReadSurface != oldDrawSurface) { + oldReadSurface->IsBound = EGL_FALSE; + if (oldReadSurface->DeletePending) { + /* make sure we don't try to rebind a deleted surface */ + if (read == oldDrawSurface || read == oldReadSurface) { + read = NULL; + } + /* really delete surface now */ + drv->API.DestroySurface(drv, dpy, oldReadSurface->Handle); + } + } + if (oldContext != NULL) { + oldContext->IsBound = EGL_FALSE; + if (oldContext->DeletePending) { + /* make sure we don't try to rebind a deleted context */ + if (ctx == oldContext) { + ctx = NULL; + } + /* really delete context now */ + drv->API.DestroyContext(drv, dpy, oldContext->Handle); + } + } + + if (ctx) { + /* check read/draw again, in case we deleted them above */ + if (draw == NULL || read == NULL) { + _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + return EGL_FALSE; + } + ctx->DrawSurface = draw; + ctx->ReadSurface = read; + ctx->IsBound = EGL_TRUE; + draw->IsBound = EGL_TRUE; + read->IsBound = EGL_TRUE; + } + + t->CurrentContext = ctx; + + return EGL_TRUE; +} + + +/** + * This is defined by the EGL_MESA_copy_context extension. + */ +EGLBoolean +_eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, + EGLContext dest, EGLint mask) +{ + /* This function will always have to be overridden/implemented in the + * device driver. If the driver is based on Mesa, use _mesa_copy_context(). + */ + return EGL_FALSE; +} --- mesa-7.2.orig/src/egl/main/egldriver.c +++ mesa-7.2/src/egl/main/egldriver.c @@ -0,0 +1,272 @@ +#include +#include +#include +#include +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglglobals.h" +#include "egllog.h" +#include "eglmode.h" +#include "eglscreen.h" +#include "eglsurface.h" + + +const char *DefaultDriverName = "demodriver"; + + +/** + * Choose and open/init the hardware driver for the given EGLDisplay. + * Previously, the EGLDisplay was created with _eglNewDisplay() where + * we recorded the user's NativeDisplayType parameter. + * + * Now we'll use the NativeDisplayType value. + * + * Currently, the native display value is treated as a string. + * If the first character is ':' we interpret it as a screen or card index + * number (i.e. ":0" or ":1", etc) + * Else if the first character is '!' we interpret it as specific driver name + * (i.e. "!r200" or "!i830". + */ +_EGLDriver * +_eglChooseDriver(EGLDisplay display) +{ + _EGLDisplay *dpy = _eglLookupDisplay(display); + _EGLDriver *drv; + const char *driverName = DefaultDriverName; + const char *name; + + assert(dpy); + + name = dpy->Name; + if (!name) { + /* use default */ + } + else if (name[0] == ':' && (name[1] >= '0' && name[1] <= '9') && !name[2]) { + /* XXX probe hardware here to determine which driver to open */ + driverName = "libEGLdri"; + } + else if (name[0] == '!') { + /* use specified driver name */ + driverName = name + 1; + } + else { + /* Maybe display was returned by XOpenDisplay? */ + _eglLog(_EGL_FATAL, "eglChooseDriver() bad name"); + } + + _eglLog(_EGL_INFO, "eglChooseDriver() choosing %s", driverName); + + drv = _eglOpenDriver(dpy, driverName); + dpy->Driver = drv; + + return drv; +} + + +/** + * Open/load the named driver and call its bootstrap function: _eglMain(). + * \return new _EGLDriver object. + */ +_EGLDriver * +_eglOpenDriver(_EGLDisplay *dpy, const char *driverName) +{ + _EGLDriver *drv; + _EGLMain_t mainFunc; + void *lib; + char driverFilename[1000]; + + /* XXX also prepend a directory path??? */ + sprintf(driverFilename, "%s.so", driverName); + + _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename); + lib = dlopen(driverFilename, RTLD_NOW); + if (!lib) { + _eglLog(_EGL_WARNING, "Could not open %s (%s)", + driverFilename, dlerror()); + return NULL; + } + + mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain"); + if (!mainFunc) { + _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename); + dlclose(lib); + return NULL; + } + + drv = mainFunc(dpy); + if (!drv) { + dlclose(lib); + return NULL; + } + /* with a recurvise open you want the inner most handle */ + if (!drv->LibHandle) + drv->LibHandle = lib; + else + dlclose(lib); + + drv->Display = dpy; + return drv; +} + + +EGLBoolean +_eglCloseDriver(_EGLDriver *drv, EGLDisplay dpy) +{ + void *handle = drv->LibHandle; + EGLBoolean b; + + _eglLog(_EGL_INFO, "Closing driver"); + + /* + * XXX check for currently bound context/surfaces and delete them? + */ + + b = drv->API.Terminate(drv, dpy); + dlclose(handle); + return b; +} + + +/** + * Given a display handle, return the _EGLDriver for that display. + */ +_EGLDriver * +_eglLookupDriver(EGLDisplay dpy) +{ + _EGLDisplay *d = _eglLookupDisplay(dpy); + if (d) + return d->Driver; + else + return NULL; +} + + +/** + * Plug all the available fallback routines into the given driver's + * dispatch table. + */ +void +_eglInitDriverFallbacks(_EGLDriver *drv) +{ + /* If a pointer is set to NULL, then the device driver _really_ has + * to implement it. + */ + drv->API.Initialize = NULL; + drv->API.Terminate = NULL; + + drv->API.GetConfigs = _eglGetConfigs; + drv->API.ChooseConfig = _eglChooseConfig; + drv->API.GetConfigAttrib = _eglGetConfigAttrib; + + drv->API.CreateContext = _eglCreateContext; + drv->API.DestroyContext = _eglDestroyContext; + drv->API.MakeCurrent = _eglMakeCurrent; + drv->API.QueryContext = _eglQueryContext; + + drv->API.CreateWindowSurface = _eglCreateWindowSurface; + drv->API.CreatePixmapSurface = _eglCreatePixmapSurface; + drv->API.CreatePbufferSurface = _eglCreatePbufferSurface; + drv->API.DestroySurface = _eglDestroySurface; + drv->API.QuerySurface = _eglQuerySurface; + drv->API.SurfaceAttrib = _eglSurfaceAttrib; + drv->API.BindTexImage = _eglBindTexImage; + drv->API.ReleaseTexImage = _eglReleaseTexImage; + drv->API.SwapInterval = _eglSwapInterval; + drv->API.SwapBuffers = _eglSwapBuffers; + drv->API.CopyBuffers = _eglCopyBuffers; + + drv->API.QueryString = _eglQueryString; + drv->API.WaitGL = _eglWaitGL; + drv->API.WaitNative = _eglWaitNative; + +#ifdef EGL_MESA_screen_surface + drv->API.ChooseModeMESA = _eglChooseModeMESA; + drv->API.GetModesMESA = _eglGetModesMESA; + drv->API.GetModeAttribMESA = _eglGetModeAttribMESA; + drv->API.GetScreensMESA = _eglGetScreensMESA; + drv->API.CreateScreenSurfaceMESA = _eglCreateScreenSurfaceMESA; + drv->API.ShowScreenSurfaceMESA = _eglShowScreenSurfaceMESA; + drv->API.ScreenPositionMESA = _eglScreenPositionMESA; + drv->API.QueryScreenMESA = _eglQueryScreenMESA; + drv->API.QueryScreenSurfaceMESA = _eglQueryScreenSurfaceMESA; + drv->API.QueryScreenModeMESA = _eglQueryScreenModeMESA; + drv->API.QueryModeStringMESA = _eglQueryModeStringMESA; +#endif /* EGL_MESA_screen_surface */ + +#ifdef EGL_VERSION_1_2 + drv->API.CreatePbufferFromClientBuffer = _eglCreatePbufferFromClientBuffer; +#endif /* EGL_VERSION_1_2 */ +} + + +/** + * Examine the individual extension enable/disable flags and recompute + * the driver's Extensions string. + */ +static void +_eglUpdateExtensionsString(_EGLDriver *drv) +{ + drv->Extensions.String[0] = 0; + + if (drv->Extensions.MESA_screen_surface) + strcat(drv->Extensions.String, "EGL_MESA_screen_surface "); + if (drv->Extensions.MESA_copy_context) + strcat(drv->Extensions.String, "EGL_MESA_copy_context "); + assert(strlen(drv->Extensions.String) < MAX_EXTENSIONS_LEN); +} + + + +const char * +_eglQueryString(_EGLDriver *drv, EGLDisplay dpy, EGLint name) +{ + (void) drv; + (void) dpy; + switch (name) { + case EGL_VENDOR: + return "Mesa Project"; + case EGL_VERSION: + return "1.0"; + case EGL_EXTENSIONS: + _eglUpdateExtensionsString(drv); + return drv->Extensions.String; +#ifdef EGL_VERSION_1_2 + case EGL_CLIENT_APIS: + /* XXX need to initialize somewhere */ + return drv->ClientAPIs; +#endif + default: + _eglError(EGL_BAD_PARAMETER, "eglQueryString"); + return NULL; + } +} + + +EGLBoolean +_eglWaitGL(_EGLDriver *drv, EGLDisplay dpy) +{ + /* just a placeholder */ + (void) drv; + (void) dpy; + return EGL_TRUE; +} + + +EGLBoolean +_eglWaitNative(_EGLDriver *drv, EGLDisplay dpy, EGLint engine) +{ + /* just a placeholder */ + (void) drv; + (void) dpy; + switch (engine) { + case EGL_CORE_NATIVE_ENGINE: + break; + default: + _eglError(EGL_BAD_PARAMETER, "eglWaitNative(engine)"); + return EGL_FALSE; + } + + return EGL_TRUE; +} --- mesa-7.2.orig/src/egl/main/eglsurface.c +++ mesa-7.2/src/egl/main/eglsurface.c @@ -0,0 +1,530 @@ +/** + * Surface-related functions. + */ + + +#include +#include +#include +#include "eglcontext.h" +#include "eglconfig.h" +#include "eglglobals.h" +#include "eglhash.h" +#include "egllog.h" +#include "eglsurface.h" + + +/** + * Do error check on parameters and initialize the given _EGLSurface object. + * \return EGL_TRUE if no errors, EGL_FALSE otherwise. + */ +EGLBoolean +_eglInitSurface(_EGLDriver *drv, EGLDisplay dpy, + _EGLSurface *surf, EGLint type, EGLConfig config, + const EGLint *attrib_list) +{ + const char *func; + _EGLConfig *conf; + EGLint width = 0, height = 0, largest = 0; + EGLint texFormat = 0, texTarget = 0, mipmapTex = 0; + EGLint renderBuffer = EGL_BACK_BUFFER; +#ifdef EGL_VERSION_1_2 + EGLint colorspace = EGL_COLORSPACE_sRGB; + EGLint alphaFormat = EGL_ALPHA_FORMAT_NONPRE; +#endif + EGLint i; + + switch (type) { + case EGL_WINDOW_BIT: + func = "eglCreateWindowSurface"; + break; + case EGL_PIXMAP_BIT: + func = "eglCreatePixmapSurface"; + renderBuffer = EGL_SINGLE_BUFFER; + break; + case EGL_PBUFFER_BIT: + func = "eglCreatePBufferSurface"; + break; + case EGL_SCREEN_BIT_MESA: + func = "eglCreateScreenSurface"; + renderBuffer = EGL_SINGLE_BUFFER; /* XXX correct? */ + break; + default: + _eglLog(_EGL_WARNING, "Bad type in _eglInitSurface"); + return EGL_FALSE; + } + + conf = _eglLookupConfig(drv, dpy, config); + if (!conf) { + _eglError(EGL_BAD_CONFIG, func); + return EGL_FALSE; + } + + /* + * Parse attribute list. Different kinds of surfaces support different + * attributes. + */ + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + case EGL_WIDTH: + if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) { + width = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_HEIGHT: + if (type == EGL_PBUFFER_BIT || type == EGL_SCREEN_BIT_MESA) { + height = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_LARGEST_PBUFFER: + if (type == EGL_PBUFFER_BIT) { + largest = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_TEXTURE_FORMAT: + if (type == EGL_PBUFFER_BIT) { + texFormat = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_TEXTURE_TARGET: + if (type == EGL_PBUFFER_BIT) { + texTarget = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_MIPMAP_TEXTURE: + if (type == EGL_PBUFFER_BIT) { + mipmapTex = attrib_list[++i]; + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; +#ifdef EGL_VERSION_1_2 + case EGL_RENDER_BUFFER: + if (type == EGL_WINDOW_BIT) { + renderBuffer = attrib_list[++i]; + if (renderBuffer != EGL_BACK_BUFFER && + renderBuffer != EGL_SINGLE_BUFFER) { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_COLORSPACE: + if (type == EGL_WINDOW_BIT || + type == EGL_PBUFFER_BIT || + type == EGL_PIXMAP_BIT) { + colorspace = attrib_list[++i]; + if (colorspace != EGL_COLORSPACE_sRGB && + colorspace != EGL_COLORSPACE_LINEAR) { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + case EGL_ALPHA_FORMAT: + if (type == EGL_WINDOW_BIT || + type == EGL_PBUFFER_BIT || + type == EGL_PIXMAP_BIT) { + alphaFormat = attrib_list[++i]; + if (alphaFormat != EGL_ALPHA_FORMAT_NONPRE && + alphaFormat != EGL_ALPHA_FORMAT_PRE) { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + } + else { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + break; + +#endif /* EGL_VERSION_1_2 */ + default: + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + } + + if (width <= 0 || height <= 0) { + _eglError(EGL_BAD_ATTRIBUTE, func); + return EGL_FALSE; + } + + memset(surf, 0, sizeof(_EGLSurface)); + surf->Config = conf; + surf->Type = type; + surf->Width = width; + surf->Height = height; + surf->TextureFormat = texFormat; + surf->TextureTarget = texTarget; + surf->MipmapTexture = mipmapTex; + surf->MipmapLevel = 0; + surf->SwapInterval = 0; +#ifdef EGL_VERSION_1_2 + surf->SwapBehavior = EGL_BUFFER_DESTROYED; /* XXX ok? */ + surf->HorizontalResolution = EGL_UNKNOWN; /* set by caller */ + surf->VerticalResolution = EGL_UNKNOWN; /* set by caller */ + surf->AspectRatio = EGL_UNKNOWN; /* set by caller */ + surf->RenderBuffer = renderBuffer; + surf->AlphaFormat = alphaFormat; + surf->Colorspace = colorspace; +#endif + + return EGL_TRUE; +} + + +void +_eglSaveSurface(_EGLSurface *surf) +{ + assert(surf); + assert(!surf->Handle); + surf->Handle = _eglHashGenKey(_eglGlobal.Contexts); + assert(surf->Handle); + _eglHashInsert(_eglGlobal.Surfaces, surf->Handle, surf); +} + + +void +_eglRemoveSurface(_EGLSurface *surf) +{ + _eglHashRemove(_eglGlobal.Surfaces, surf->Handle); +} + + +_EGLSurface * +_eglLookupSurface(EGLSurface surf) +{ + _EGLSurface *c = (_EGLSurface *) _eglHashLookup(_eglGlobal.Surfaces, surf); + return c; +} + + +_EGLSurface * +_eglGetCurrentSurface(EGLint readdraw) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + if (ctx) { + switch (readdraw) { + case EGL_DRAW: + return ctx->DrawSurface; + case EGL_READ: + return ctx->ReadSurface; + default: + return NULL; + } + } + return NULL; +} + + +EGLBoolean +_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +{ + /* Basically just do error checking here. Drivers have to do the + * actual buffer swap. + */ + _EGLContext *context = _eglGetCurrentContext(); + _EGLSurface *surface = _eglLookupSurface(draw); + if (context && context->DrawSurface != surface) { + _eglError(EGL_BAD_SURFACE, "eglSwapBuffers"); + return EGL_FALSE; + } + if (surface == NULL) { + _eglError(EGL_BAD_SURFACE, "eglSwapBuffers"); + return EGL_FALSE; + } + return EGL_TRUE; +} + + +EGLBoolean +_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, + NativePixmapType target) +{ + /* copy surface to native pixmap */ + /* All implementation burdon for this is in the device driver */ + return EGL_FALSE; +} + + +EGLBoolean +_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, + EGLint attribute, EGLint *value) +{ + _EGLSurface *surface = _eglLookupSurface(surf); + if (surface == NULL) { + _eglError(EGL_BAD_SURFACE, "eglQuerySurface"); + return EGL_FALSE; + } + switch (attribute) { + case EGL_WIDTH: + *value = surface->Width; + return EGL_TRUE; + case EGL_HEIGHT: + *value = surface->Height; + return EGL_TRUE; + case EGL_CONFIG_ID: + *value = GET_CONFIG_ATTRIB(surface->Config, EGL_CONFIG_ID); + return EGL_TRUE; + /*XXX case EGL_LARGEST_PBUFFER:*/ + case EGL_SURFACE_TYPE: + *value = surface->Type; + return EGL_TRUE; +#ifdef EGL_VERSION_1_1 + case EGL_TEXTURE_FORMAT: + /* texture attributes: only for pbuffers, no error otherwise */ + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->TextureFormat; + return EGL_TRUE; + case EGL_TEXTURE_TARGET: + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->TextureTarget; + return EGL_TRUE; + case EGL_MIPMAP_TEXTURE: + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->MipmapTexture; + return EGL_TRUE; + case EGL_MIPMAP_LEVEL: + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->MipmapLevel; + return EGL_TRUE; +#endif /* EGL_VERSION_1_1 */ +#ifdef EGL_VERSION_1_2 + case EGL_SWAP_BEHAVIOR: + *value = surface->SwapBehavior; + return EGL_TRUE; + case EGL_RENDER_BUFFER: + *value = surface->RenderBuffer; + return EGL_TRUE; + case EGL_PIXEL_ASPECT_RATIO: + *value = surface->AspectRatio; + return EGL_TRUE; + case EGL_HORIZONTAL_RESOLUTION: + *value = surface->HorizontalResolution; + return EGL_TRUE; + case EGL_VERTICAL_RESOLUTION: + *value = surface->VerticalResolution; + return EGL_TRUE; + case EGL_ALPHA_FORMAT: + *value = surface->AlphaFormat; + return EGL_TRUE; + case EGL_COLORSPACE: + *value = surface->Colorspace; + return EGL_TRUE; +#endif /* EGL_VERSION_1_2 */ + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); + return EGL_FALSE; + } +} + + +/** + * Example function - drivers should do a proper implementation. + */ +EGLSurface +_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + NativeWindowType window, const EGLint *attrib_list) +{ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_WINDOW_BIT, config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif + return EGL_NO_SURFACE; +} + + +/** + * Example function - drivers should do a proper implementation. + */ +EGLSurface +_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + NativePixmapType pixmap, const EGLint *attrib_list) +{ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_PIXMAP_BIT, config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif + return EGL_NO_SURFACE; +} + + +/** + * Example function - drivers should do a proper implementation. + */ +EGLSurface +_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) +{ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_PBUFFER_BIT, config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif + return EGL_NO_SURFACE; +} + + +/** + * Default fallback routine - drivers should usually override this. + */ +EGLBoolean +_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) +{ + _EGLSurface *surf = _eglLookupSurface(surface); + if (surf) { + _eglHashRemove(_eglGlobal.Surfaces, surface); + if (surf->IsBound) { + surf->DeletePending = EGL_TRUE; + } + else { + free(surf); + } + return EGL_TRUE; + } + else { + _eglError(EGL_BAD_SURFACE, "eglDestroySurface"); + return EGL_FALSE; + } +} + + +/** + * Default fallback routine - drivers might override this. + */ +EGLBoolean +_eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surf, EGLint attribute, EGLint value) +{ + _EGLSurface *surface = _eglLookupSurface(surf); + + if (surface == NULL) { + _eglError(EGL_BAD_SURFACE, "eglSurfaceAttrib"); + return EGL_FALSE; + } + + switch (attribute) { + case EGL_MIPMAP_LEVEL: + surface->MipmapLevel = value; + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglSurfaceAttrib"); + return EGL_FALSE; + } + return EGL_TRUE; +} + + +EGLBoolean +_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + /* XXX unfinished */ + return EGL_FALSE; +} + + +EGLBoolean +_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + /* XXX unfinished */ + return EGL_FALSE; +} + + +EGLBoolean +_eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval) +{ + _EGLSurface *surf = _eglGetCurrentSurface(EGL_DRAW); + if (surf == NULL) { + _eglError(EGL_BAD_SURFACE, "eglSwapInterval"); + return EGL_FALSE; + } + surf->SwapInterval = interval; + return EGL_TRUE; +} + + +#ifdef EGL_VERSION_1_2 + +/** + * Example function - drivers should do a proper implementation. + */ +EGLSurface +_eglCreatePbufferFromClientBuffer(_EGLDriver *drv, EGLDisplay dpy, + EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list) +{ + if (buftype != EGL_OPENVG_IMAGE) { + _eglError(EGL_BAD_PARAMETER, "eglCreatePbufferFromClientBuffer"); + return EGL_NO_SURFACE; + } + + return EGL_NO_SURFACE; +} + +#endif /* EGL_VERSION_1_2 */ --- mesa-7.2.orig/src/egl/main/eglscreen.c +++ mesa-7.2/src/egl/main/eglscreen.c @@ -0,0 +1,328 @@ +/* + * Ideas for screen management extension to EGL. + * + * Each EGLDisplay has one or more screens (CRTs, Flat Panels, etc). + * The screens' handles can be obtained with eglGetScreensMESA(). + * + * A new kind of EGLSurface is possible- one which can be directly scanned + * out on a screen. Such a surface is created with eglCreateScreenSurface(). + * + * To actually display a screen surface on a screen, the eglShowSurface() + * function is called. + */ + +#include +#include +#include + +#include "egldisplay.h" +#include "eglglobals.h" +#include "eglmode.h" +#include "eglconfig.h" +#include "eglsurface.h" +#include "eglscreen.h" + + +/** + * Return a new screen handle/ID. + * NOTE: we never reuse these! + */ +EGLScreenMESA +_eglAllocScreenHandle(void) +{ + EGLScreenMESA s = _eglGlobal.FreeScreenHandle; + _eglGlobal.FreeScreenHandle++; + return s; +} + + +/** + * Initialize an _EGLScreen object to default values. + */ +void +_eglInitScreen(_EGLScreen *screen) +{ + memset(screen, 0, sizeof(_EGLScreen)); + screen->StepX = 1; + screen->StepY = 1; +} + + +/** + * Given a public screen handle, return the internal _EGLScreen object. + */ +_EGLScreen * +_eglLookupScreen(EGLDisplay dpy, EGLScreenMESA screen) +{ + EGLint i; + _EGLDisplay *display = _eglLookupDisplay(dpy); + + if (!display) + return NULL; + + for (i = 0; i < display->NumScreens; i++) { + if (display->Screens[i]->Handle == screen) + return display->Screens[i]; + } + return NULL; +} + + +/** + * Add the given _EGLScreen to the display's list of screens. + */ +void +_eglAddScreen(_EGLDisplay *display, _EGLScreen *screen) +{ + EGLint n; + + assert(display); + assert(screen); + + screen->Handle = _eglAllocScreenHandle(); + n = display->NumScreens; + display->Screens = realloc(display->Screens, (n+1) * sizeof(_EGLScreen *)); + display->Screens[n] = screen; + display->NumScreens++; +} + + + +EGLBoolean +_eglGetScreensMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, + EGLint max_screens, EGLint *num_screens) +{ + _EGLDisplay *display = _eglLookupDisplay(dpy); + EGLint n; + + if (!display) { + _eglError(EGL_BAD_DISPLAY, "eglGetScreensMESA"); + return EGL_FALSE; + } + + if (display->NumScreens > max_screens) { + n = max_screens; + } + else { + n = display->NumScreens; + } + + if (screens) { + EGLint i; + for (i = 0; i < n; i++) + screens[i] = display->Screens[i]->Handle; + } + if (num_screens) + *num_screens = n; + + return EGL_TRUE; +} + + +/** + * Example function - drivers should do a proper implementation. + */ +EGLSurface +_eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) +{ +#if 0 /* THIS IS JUST EXAMPLE CODE */ + _EGLSurface *surf; + + surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface)); + if (!surf) + return EGL_NO_SURFACE; + + if (!_eglInitSurface(drv, dpy, surf, EGL_SCREEN_BIT_MESA, + config, attrib_list)) { + free(surf); + return EGL_NO_SURFACE; + } + + _eglSaveSurface(surf); + + return surf->Handle; +#endif + return EGL_NO_SURFACE; +} + + +/** + * Show the given surface on the named screen. + * If surface is EGL_NO_SURFACE, disable the screen's output. + * + * This is just a placeholder function; drivers will always override + * this with code that _really_ shows the surface. + */ +EGLBoolean +_eglShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, + EGLScreenMESA screen, EGLSurface surface, + EGLModeMESA m) +{ + _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + _EGLMode *mode = _eglLookupMode(dpy, m); + + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, "eglShowSurfaceMESA"); + return EGL_FALSE; + } + if (!mode && (m != EGL_NO_MODE_MESA )) { + _eglError(EGL_BAD_MODE_MESA, "eglShowSurfaceMESA"); + return EGL_FALSE; + } + + if (surface == EGL_NO_SURFACE) { + scrn->CurrentSurface = NULL; + } + else { + _EGLSurface *surf = _eglLookupSurface(surface); + if (!surf || surf->Type != EGL_SCREEN_BIT_MESA) { + _eglError(EGL_BAD_SURFACE, "eglShowSurfaceMESA"); + return EGL_FALSE; + } + if (surf->Width < mode->Width || surf->Height < mode->Height) { + _eglError(EGL_BAD_SURFACE, + "eglShowSurfaceMESA(surface smaller than screen size)"); + return EGL_FALSE; + } + + scrn->CurrentSurface = surf; + scrn->CurrentMode = mode; + } + return EGL_TRUE; +} + + +/** + * Set a screen's current display mode. + * Note: mode = EGL_NO_MODE is valid (turns off the screen) + * + * This is just a placeholder function; drivers will always override + * this with code that _really_ sets the mode. + */ +EGLBoolean +_eglScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA mode) +{ + _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, "eglScreenModeMESA"); + return EGL_FALSE; + } + + scrn->CurrentMode = _eglLookupMode(dpy, mode); + + return EGL_TRUE; +} + + +/** + * Set a screen's surface origin. + */ +EGLBoolean +_eglScreenPositionMESA(_EGLDriver *drv, EGLDisplay dpy, + EGLScreenMESA screen, EGLint x, EGLint y) +{ + _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, "eglScreenPositionMESA"); + return EGL_FALSE; + } + + scrn->OriginX = x; + scrn->OriginY = y; + + return EGL_TRUE; +} + + +/** + * Query a screen's current surface. + */ +EGLBoolean +_eglQueryScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, + EGLScreenMESA screen, EGLSurface *surface) +{ + const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + if (scrn->CurrentSurface) + *surface = scrn->CurrentSurface->Handle; + else + *surface = EGL_NO_SURFACE; + return EGL_TRUE; +} + + +/** + * Query a screen's current mode. + */ +EGLBoolean +_eglQueryScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + EGLModeMESA *mode) +{ + const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + if (scrn->CurrentMode) + *mode = scrn->CurrentMode->Handle; + else + *mode = EGL_NO_MODE_MESA; + return EGL_TRUE; +} + + +EGLBoolean +_eglQueryScreenMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, + EGLint attribute, EGLint *value) +{ + const _EGLScreen *scrn = _eglLookupScreen(dpy, screen); + + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, "eglQueryScreenMESA"); + return EGL_FALSE; + } + + switch (attribute) { + case EGL_SCREEN_POSITION_MESA: + value[0] = scrn->OriginX; + value[1] = scrn->OriginY; + break; + case EGL_SCREEN_POSITION_GRANULARITY_MESA: + value[0] = scrn->StepX; + value[1] = scrn->StepY; + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglQueryScreenMESA"); + return EGL_FALSE; + } + + return EGL_TRUE; +} + + +/** + * Delete the modes associated with given screen. + */ +void +_eglDestroyScreenModes(_EGLScreen *scrn) +{ + EGLint i; + for (i = 0; i < scrn->NumModes; i++) { + if (scrn->Modes[i].Name) + free((char *) scrn->Modes[i].Name); /* cast away const */ + } + if (scrn->Modes) + free(scrn->Modes); + scrn->Modes = NULL; + scrn->NumModes = 0; +} + + +/** + * Default fallback routine - drivers should usually override this. + */ +void +_eglDestroyScreen(_EGLScreen *scrn) +{ + _eglDestroyScreenModes(scrn); + free(scrn); +} + --- mesa-7.2.orig/src/egl/main/eglscreen.h +++ mesa-7.2/src/egl/main/eglscreen.h @@ -0,0 +1,90 @@ +#ifndef EGLSCREEN_INCLUDED +#define EGLSCREEN_INCLUDED + + +/** + * Per-screen information. + * Note that an EGL screen doesn't have a size. A screen may be set to + * one of several display modes (width/height/scanrate). The screen + * then displays a drawing surface. The drawing surface must be at least + * as large as the display mode's resolution. If it's larger, the + * OriginX and OriginY fields control what part of the surface is visible + * on the screen. + */ +struct _egl_screen +{ + EGLScreenMESA Handle; /* The public/opaque handle which names this object */ + + _EGLMode *CurrentMode; + _EGLSurface *CurrentSurface; + + EGLint OriginX, OriginY; /**< Origin of scan-out region w.r.t. surface */ + EGLint StepX, StepY; /**< Screen position/origin granularity */ + + EGLint NumModes; + _EGLMode *Modes; /**< array [NumModes] */ +}; + + +extern EGLScreenMESA +_eglAllocScreenHandle(void); + + +extern void +_eglInitScreen(_EGLScreen *screen); + + +extern _EGLScreen * +_eglLookupScreen(EGLDisplay dpy, EGLScreenMESA screen); + + +extern void +_eglAddScreen(_EGLDisplay *display, _EGLScreen *screen); + + +extern EGLBoolean +_eglGetScreensMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); + + +extern EGLSurface +_eglCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); + + +extern EGLBoolean +_eglShowScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface surface, EGLModeMESA mode); + + +extern EGLBoolean +_eglScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA mode); + + +extern EGLBoolean +_eglScreenPositionMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y); + + +extern EGLBoolean +_eglQueryDisplayMESA(_EGLDriver *drv, EGLDisplay dpy, EGLint attribute, EGLint *value); + + +extern EGLBoolean +_eglQueryScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, + EGLScreenMESA screen, EGLSurface *surface); + + +extern EGLBoolean +_eglQueryScreenModeMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode); + + +extern EGLBoolean +_eglQueryScreenMESA(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value); + + +extern void +_eglDestroyScreenModes(_EGLScreen *scrn); + + +extern void +_eglDestroyScreen(_EGLScreen *scrn); + + +#endif /* EGLSCREEN_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglapi.h +++ mesa-7.2/src/egl/main/eglapi.h @@ -0,0 +1,119 @@ +#ifndef EGLAPI_INCLUDED +#define EGLAPI_INCLUDED + +/** + * Typedefs for all EGL API entrypoint functions. + */ + + +/* driver funcs */ +typedef EGLBoolean (*Initialize_t)(_EGLDriver *, EGLDisplay dpy, EGLint *major, EGLint *minor); +typedef EGLBoolean (*Terminate_t)(_EGLDriver *, EGLDisplay dpy); + +/* config funcs */ +typedef EGLBoolean (*GetConfigs_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); +typedef EGLBoolean (*ChooseConfig_t)(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); +typedef EGLBoolean (*GetConfigAttrib_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); + +/* context funcs */ +typedef EGLContext (*CreateContext_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list); +typedef EGLBoolean (*DestroyContext_t)(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx); +typedef EGLBoolean (*MakeCurrent_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); +typedef EGLBoolean (*QueryContext_t)(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value); + +/* surface funcs */ +typedef EGLSurface (*CreateWindowSurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list); +typedef EGLSurface (*CreatePixmapSurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list); +typedef EGLSurface (*CreatePbufferSurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); +typedef EGLBoolean (*DestroySurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface); +typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value); +typedef EGLBoolean (*SurfaceAttrib_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value); +typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); +typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); +typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, EGLDisplay dpy, EGLint interval); +typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); +typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target); + +/* misc funcs */ +typedef const char *(*QueryString_t)(_EGLDriver *drv, EGLDisplay dpy, EGLint name); +typedef EGLBoolean (*WaitGL_t)(_EGLDriver *drv, EGLDisplay dpy); +typedef EGLBoolean (*WaitNative_t)(_EGLDriver *drv, EGLDisplay dpy, EGLint engine); + + +#ifdef EGL_MESA_screen_surface +typedef EGLBoolean (*ChooseModeMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +typedef EGLBoolean (*GetModesMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode); +typedef EGLBoolean (*GetModeAttribMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value); +typedef EGLBoolean (*CopyContextMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); +typedef EGLBoolean (*GetScreensMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); +typedef EGLSurface (*CreateScreenSurfaceMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); +typedef EGLBoolean (*ShowScreenSurfaceMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface surface, EGLModeMESA mode); +typedef EGLBoolean (*ScreenPositionMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y); +typedef EGLBoolean (*QueryScreenMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value); +typedef EGLBoolean (*QueryScreenSurfaceMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface); +typedef EGLBoolean (*QueryScreenModeMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode); +typedef const char * (*QueryModeStringMESA_t)(_EGLDriver *drv, EGLDisplay dpy, EGLModeMESA mode); +#endif /* EGL_MESA_screen_surface */ + + +#ifdef EGL_VERSION_1_2 +typedef EGLBoolean (*WaitClient_t)(_EGLDriver *drv, EGLDisplay dpy); +typedef EGLSurface (*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list); +#endif /* EGL_VERSION_1_2 */ + + + +/** + * The API dispatcher jumps through these functions + */ +struct _egl_api +{ + Initialize_t Initialize; + Terminate_t Terminate; + + GetConfigs_t GetConfigs; + ChooseConfig_t ChooseConfig; + GetConfigAttrib_t GetConfigAttrib; + + CreateContext_t CreateContext; + DestroyContext_t DestroyContext; + MakeCurrent_t MakeCurrent; + QueryContext_t QueryContext; + + CreateWindowSurface_t CreateWindowSurface; + CreatePixmapSurface_t CreatePixmapSurface; + CreatePbufferSurface_t CreatePbufferSurface; + DestroySurface_t DestroySurface; + QuerySurface_t QuerySurface; + SurfaceAttrib_t SurfaceAttrib; + BindTexImage_t BindTexImage; + ReleaseTexImage_t ReleaseTexImage; + SwapInterval_t SwapInterval; + SwapBuffers_t SwapBuffers; + CopyBuffers_t CopyBuffers; + + QueryString_t QueryString; + WaitGL_t WaitGL; + WaitNative_t WaitNative; + + /* EGL_MESA_screen extension */ + ChooseModeMESA_t ChooseModeMESA; + GetModesMESA_t GetModesMESA; + GetModeAttribMESA_t GetModeAttribMESA; + CopyContextMESA_t CopyContextMESA; + GetScreensMESA_t GetScreensMESA; + CreateScreenSurfaceMESA_t CreateScreenSurfaceMESA; + ShowScreenSurfaceMESA_t ShowScreenSurfaceMESA; + ScreenPositionMESA_t ScreenPositionMESA; + QueryScreenMESA_t QueryScreenMESA; + QueryScreenSurfaceMESA_t QueryScreenSurfaceMESA; + QueryScreenModeMESA_t QueryScreenModeMESA; + QueryModeStringMESA_t QueryModeStringMESA; + +#ifdef EGL_VERSION_1_2 + WaitClient_t WaitClient; + CreatePbufferFromClientBuffer_t CreatePbufferFromClientBuffer; +#endif +}; + +#endif /* EGLAPI_INCLUDED */ --- mesa-7.2.orig/src/egl/main/eglsurface.h +++ mesa-7.2/src/egl/main/eglsurface.h @@ -0,0 +1,117 @@ +#ifndef EGLSURFACE_INCLUDED +#define EGLSURFACE_INCLUDED + + +#include "egltypedefs.h" + + +/** + * "Base" class for device driver surfaces. + */ +struct _egl_surface +{ + EGLSurface Handle; /* The public/opaque handle which names this object */ + _EGLConfig *Config; + + /* May need reference counting here */ + EGLBoolean IsBound; + EGLBoolean DeletePending; + + EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ + EGLint Width, Height; + EGLint TextureFormat, TextureTarget; + EGLint MipmapTexture, MipmapLevel; + EGLint SwapInterval; + + /* If type == EGL_SCREEN_BIT: */ + EGLint VisibleRefCount; /* number of screens I'm displayed on */ + +#ifdef EGL_VERSION_1_2 + EGLint SwapBehavior; /* one of EGL_BUFFER_PRESERVED/DESTROYED */ + EGLint HorizontalResolution, VerticalResolution; + EGLint AspectRatio; + EGLint RenderBuffer; /* EGL_BACK_BUFFER or EGL_SINGLE_BUFFER */ + EGLint AlphaFormat; /* EGL_ALPHA_FORMAT_NONPRE or EGL_ALPHA_FORMAT_PRE */ + EGLint Colorspace; /* EGL_COLORSPACE_sRGB or EGL_COLORSPACE_LINEAR */ +#endif /* EGL_VERSION_1_2 */ +}; + + +extern EGLBoolean +_eglInitSurface(_EGLDriver *drv, EGLDisplay dpy, + _EGLSurface *surf, EGLint type, EGLConfig config, + const EGLint *attrib_list); + + +extern void +_eglSaveSurface(_EGLSurface *surf); + + +extern void +_eglRemoveSurface(_EGLSurface *surf); + + +extern _EGLSurface * +_eglLookupSurface(EGLSurface surf); + + +extern _EGLSurface * +_eglGetCurrentSurface(EGLint readdraw); + + +extern EGLBoolean +_eglSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw); + + +extern EGLBoolean +_eglCopyBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, NativePixmapType target); + + +extern EGLBoolean +_eglQuerySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value); + + +extern EGLSurface +_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list); + + +extern EGLSurface +_eglCreatePixmapSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list); + + +extern EGLSurface +_eglCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); + + +extern EGLBoolean +_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface); + + +extern EGLBoolean +_eglSurfaceAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value); + + +extern EGLBoolean +_eglBindTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); + + +extern EGLBoolean +_eglReleaseTexImage(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface, EGLint buffer); + + +extern EGLBoolean +_eglSwapInterval(_EGLDriver *drv, EGLDisplay dpy, EGLint interval); + + +#ifdef EGL_VERSION_1_2 + +extern EGLSurface +_eglCreatePbufferFromClientBuffer(_EGLDriver *drv, EGLDisplay dpy, + EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list); + +#endif /* EGL_VERSION_1_2 */ + + + +#endif /* EGLSURFACE_INCLUDED */ --- mesa-7.2.orig/src/glu/mini/quadric.c +++ mesa-7.2/src/glu/mini/quadric.c @@ -0,0 +1,774 @@ +/* $Id: quadric.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1999-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* TODO: + * texture coordinate support + * flip normals according to orientation + * there's still some inside/outside orientation bugs in possibly all + * but the sphere function + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include "gluP.h" +#endif + + + +#ifndef M_PI +# define M_PI (3.1415926) +#endif + + +/* + * Convert degrees to radians: + */ +#define DEG_TO_RAD(A) ((A)*(M_PI/180.0)) + + +/* + * Sin and Cos for degree angles: + */ +#define SIND( A ) sin( (A)*(M_PI/180.0) ) +#define COSD( A) cos( (A)*(M_PI/180.0) ) + + +/* + * Texture coordinates if texture flag is set + */ +#define TXTR_COORD(x,y) if (qobj->TextureFlag) glTexCoord2f(x,y); + + + +struct GLUquadric +{ + GLenum DrawStyle; /* GLU_FILL, LINE, SILHOUETTE, or POINT */ + GLenum Orientation; /* GLU_INSIDE or GLU_OUTSIDE */ + GLboolean TextureFlag; /* Generate texture coords? */ + GLenum Normals; /* GLU_NONE, GLU_FLAT, or GLU_SMOOTH */ + void (GLCALLBACK * ErrorFunc) (GLenum err); /* Error handler callback function */ +}; + + + +/* + * Process a GLU error. + */ +static void +quadric_error(GLUquadricObj * qobj, GLenum error, const char *msg) +{ + /* Call the error call back function if any */ + if (qobj->ErrorFunc) { + (*qobj->ErrorFunc) (error); + } + /* Print a message to stdout if MESA_DEBUG variable is defined */ + if (getenv("MESA_DEBUG")) { + fprintf(stderr, "GLUError: %s: %s\n", (char *) gluErrorString(error), + msg); + } +} + + + + +GLUquadricObj *GLAPIENTRY +gluNewQuadric(void) +{ + GLUquadricObj *q; + + q = (GLUquadricObj *) malloc(sizeof(struct GLUquadric)); + if (q) { + q->DrawStyle = GLU_FILL; + q->Orientation = GLU_OUTSIDE; + q->TextureFlag = GL_FALSE; + q->Normals = GLU_SMOOTH; + q->ErrorFunc = NULL; + } + return q; +} + + + +void GLAPIENTRY +gluDeleteQuadric(GLUquadricObj * state) +{ + if (state) { + free((void *) state); + } +} + + + +/* + * Set the drawing style to be GLU_FILL, GLU_LINE, GLU_SILHOUETTE, + * or GLU_POINT. + */ +void GLAPIENTRY +gluQuadricDrawStyle(GLUquadricObj * quadObject, GLenum drawStyle) +{ + if (quadObject && (drawStyle == GLU_FILL || drawStyle == GLU_LINE + || drawStyle == GLU_SILHOUETTE + || drawStyle == GLU_POINT)) { + quadObject->DrawStyle = drawStyle; + } + else { + quadric_error(quadObject, GLU_INVALID_ENUM, "qluQuadricDrawStyle"); + } +} + + + +/* + * Set the orientation to GLU_INSIDE or GLU_OUTSIDE. + */ +void GLAPIENTRY +gluQuadricOrientation(GLUquadricObj * quadObject, GLenum orientation) +{ + if (quadObject + && (orientation == GLU_INSIDE || orientation == GLU_OUTSIDE)) { + quadObject->Orientation = orientation; + } + else { + quadric_error(quadObject, GLU_INVALID_ENUM, "qluQuadricOrientation"); + } +} + + + +/* + * Set the error handler callback function. + */ +void GLAPIENTRY +gluQuadricCallback(GLUquadricObj * qobj, + GLenum which, void (GLCALLBACK * fn) ()) +{ + /* + * UGH, this is a mess! I thought ANSI was a standard. + */ + if (qobj && which == GLU_ERROR) { +#ifdef __CYGWIN32__ + qobj->ErrorFunc = (void (GLCALLBACKPCAST) (GLenum)) fn; +#elif defined(OPENSTEP) + qobj->ErrorFunc = (void (*)(GLenum)) fn; +#elif defined(_WIN32) + qobj->ErrorFunc = (void (GLCALLBACK *) (int)) fn; +#elif defined(__STORM__) + qobj->ErrorFunc = (void (GLCALLBACK *) (GLenum)) fn; +#elif defined(__BEOS__) + qobj->ErrorFunc = (void (*)(GLenum)) fn; +#else + qobj->ErrorFunc = (void (GLCALLBACK *) ()) fn; +#endif + } +} + + +void GLAPIENTRY +gluQuadricNormals(GLUquadricObj * quadObject, GLenum normals) +{ + if (quadObject + && (normals == GLU_NONE || normals == GLU_FLAT + || normals == GLU_SMOOTH)) { + quadObject->Normals = normals; + } +} + + +void GLAPIENTRY +gluQuadricTexture(GLUquadricObj * quadObject, GLboolean textureCoords) +{ + if (quadObject) { + quadObject->TextureFlag = textureCoords; + } +} + + + + +/* + * Call glNormal3f after scaling normal to unit length. + */ +static void +normal3f(GLfloat x, GLfloat y, GLfloat z) +{ +} + + + +void GLAPIENTRY +gluCylinder(GLUquadricObj * qobj, + GLdouble baseRadius, GLdouble topRadius, + GLdouble height, GLint slices, GLint stacks) +{ + GLdouble da, r, dr, dz; + GLfloat x, y, z, nz, nsign; + GLint i, j; + + if (qobj->Orientation == GLU_INSIDE) { + nsign = -1.0; + } + else { + nsign = 1.0; + } + + da = 2.0 * M_PI / slices; + dr = (topRadius - baseRadius) / stacks; + dz = height / stacks; + nz = (baseRadius - topRadius) / height; /* Z component of normal vectors */ + + if (qobj->DrawStyle == GLU_POINT) { + glBegin(GL_POINTS); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + + z = 0.0; + r = baseRadius; + for (j = 0; j <= stacks; j++) { + glVertex3f(x * r, y * r, z); + z += dz; + r += dr; + } + } + glEnd(); + } + else if (qobj->DrawStyle == GLU_LINE || qobj->DrawStyle == GLU_SILHOUETTE) { + /* Draw rings */ + if (qobj->DrawStyle == GLU_LINE) { + z = 0.0; + r = baseRadius; + for (j = 0; j <= stacks; j++) { + glBegin(GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * r, y * r, z); + } + glEnd(); + z += dz; + r += dr; + } + } + else { + /* draw one ring at each end */ + if (baseRadius != 0.0) { + glBegin(GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * baseRadius, y * baseRadius, 0.0); + } + glEnd(); + glBegin(GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * topRadius, y * topRadius, height); + } + glEnd(); + } + } + /* draw length lines */ + glBegin(GL_LINES); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * baseRadius, y * baseRadius, 0.0); + glVertex3f(x * topRadius, y * topRadius, height); + } + glEnd(); + } + else if (qobj->DrawStyle == GLU_FILL) { + GLfloat ds = 1.0 / slices; + GLfloat dt = 1.0 / stacks; + GLfloat t = 0.0; + z = 0.0; + r = baseRadius; + for (j = 0; j < stacks; j++) { + GLfloat s = 0.0; + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + GLfloat x, y; + if (i == slices) { + x = sin(0.0); + y = cos(0.0); + } + else { + x = sin(i * da); + y = cos(i * da); + } + if (nsign == 1.0) { + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t); + glVertex3f(x * r, y * r, z); + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t + dt); + glVertex3f(x * (r + dr), y * (r + dr), z + dz); + } + else { + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t); + glVertex3f(x * r, y * r, z); + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t + dt); + glVertex3f(x * (r + dr), y * (r + dr), z + dz); + } + s += ds; + } /* for slices */ + glEnd(); + r += dr; + t += dt; + z += dz; + } /* for stacks */ + } +} + + + + + +void GLAPIENTRY +gluSphere(GLUquadricObj * qobj, GLdouble radius, GLint slices, GLint stacks) +{ + GLfloat rho, drho, theta, dtheta; + GLfloat x, y, z; + GLfloat s, t, ds, dt; + GLint i, j, imin, imax; + GLboolean normals; + GLfloat nsign; + + if (qobj->Normals == GLU_NONE) { + normals = GL_FALSE; + } + else { + normals = GL_TRUE; + } + if (qobj->Orientation == GLU_INSIDE) { + nsign = -1.0; + } + else { + nsign = 1.0; + } + + drho = M_PI / (GLfloat) stacks; + dtheta = 2.0 * M_PI / (GLfloat) slices; + + /* texturing: s goes from 0.0/0.25/0.5/0.75/1.0 at +y/+x/-y/-x/+y axis */ + /* t goes from -1.0/+1.0 at z = -radius/+radius (linear along longitudes) */ + /* cannot use triangle fan on texturing (s coord. at top/bottom tip varies) */ + + if (qobj->DrawStyle == GLU_FILL) { + if (!qobj->TextureFlag) { + /* draw +Z end as a triangle fan */ + glBegin(GL_TRIANGLE_FAN); +/* glNormal3f(0.0, 0.0, 1.0); */ + glVertex3f(0.0, 0.0, nsign * radius); + for (j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(drho); + y = cos(theta) * sin(drho); + z = nsign * cos(drho); + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + + ds = 1.0 / slices; + dt = 1.0 / stacks; + t = 1.0; /* because loop now runs from 0 */ + if (qobj->TextureFlag) { + imin = 0; + imax = stacks; + } + else { + imin = 1; + imax = stacks - 1; + } + + /* draw intermediate stacks as quad strips */ + for (i = imin; i < imax; i++) { + rho = i * drho; + glBegin(GL_QUAD_STRIP); + s = 0.0; + for (j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + TXTR_COORD(s, t); + glVertex3f(x * radius, y * radius, z * radius); + x = -sin(theta) * sin(rho + drho); + y = cos(theta) * sin(rho + drho); + z = nsign * cos(rho + drho); + TXTR_COORD(s, t - dt); + s += ds; + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + t -= dt; + } + + if (!qobj->TextureFlag) { + /* draw -Z end as a triangle fan */ + glBegin(GL_TRIANGLE_FAN); + glVertex3f(0.0, 0.0, -radius * nsign); + rho = M_PI - drho; + s = 1.0; + t = dt; + for (j = slices; j >= 0; j--) { + theta = (j == slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + s -= ds; + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + } + else if (qobj->DrawStyle == GLU_LINE || qobj->DrawStyle == GLU_SILHOUETTE) { + /* draw stack lines */ + for (i = 1; i < stacks; i++) { /* stack line at i==stacks-1 was missing here */ + rho = i * drho; + glBegin(GL_LINE_LOOP); + for (j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + /* draw slice lines */ + for (j = 0; j < slices; j++) { + theta = j * dtheta; + glBegin(GL_LINE_STRIP); + for (i = 0; i <= stacks; i++) { + rho = i * drho; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + } + else if (qobj->DrawStyle == GLU_POINT) { + /* top and bottom-most points */ + glBegin(GL_POINTS); + glVertex3f(0.0, 0.0, radius); + glVertex3f(0.0, 0.0, -radius); + + /* loop over stacks */ + for (i = 1; i < stacks - 1; i++) { + rho = i * drho; + for (j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + glVertex3f(x * radius, y * radius, z * radius); + } + } + glEnd(); + } + +} + + + +void GLAPIENTRY +gluDisk(GLUquadricObj * qobj, + GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops) +{ + GLfloat da, dr; +#if 0 + GLdouble a, da; + GLfloat r, dr; + GLfloat x, y; + GLfloat r1, r2, dtc; + GLint s, l; +#endif + + + da = 2.0 * M_PI / slices; + dr = (outerRadius - innerRadius) / (GLfloat) loops; + + switch (qobj->DrawStyle) { + case GLU_FILL: + { + /* texture of a gluDisk is a cut out of the texture unit square + * x, y in [-outerRadius, +outerRadius]; s, t in [0, 1] + * (linear mapping) + */ + GLfloat dtc = 2.0f * outerRadius; + GLfloat sa, ca; + GLfloat r1 = innerRadius; + GLint l; + for (l = 0; l < loops; l++) { + GLfloat r2 = r1 + dr; + if (qobj->Orientation == GLU_OUTSIDE) { + GLint s; + glBegin(GL_QUAD_STRIP); + for (s = 0; s <= slices; s++) { + GLfloat a; + if (s == slices) + a = 0.0; + else + a = s * da; + sa = sin(a); + ca = cos(a); + TXTR_COORD(0.5 + sa * r2 / dtc, 0.5 + ca * r2 / dtc); + glVertex2f(r2 * sa, r2 * ca); + TXTR_COORD(0.5 + sa * r1 / dtc, 0.5 + ca * r1 / dtc); + glVertex2f(r1 * sa, r1 * ca); + } + glEnd(); + } + else { + GLint s; + glBegin(GL_QUAD_STRIP); + for (s = slices; s >= 0; s--) { + GLfloat a; + if (s == slices) + a = 0.0; + else + a = s * da; + sa = sin(a); + ca = cos(a); + TXTR_COORD(0.5 - sa * r2 / dtc, 0.5 + ca * r2 / dtc); + glVertex2f(r2 * sa, r2 * ca); + TXTR_COORD(0.5 - sa * r1 / dtc, 0.5 + ca * r1 / dtc); + glVertex2f(r1 * sa, r1 * ca); + } + glEnd(); + } + r1 = r2; + } + break; + } + case GLU_LINE: + { + GLint l, s; + /* draw loops */ + for (l = 0; l <= loops; l++) { + GLfloat r = innerRadius + l * dr; + glBegin(GL_LINE_LOOP); + for (s = 0; s < slices; s++) { + GLfloat a = s * da; + glVertex2f(r * sin(a), r * cos(a)); + } + glEnd(); + } + /* draw spokes */ + for (s = 0; s < slices; s++) { + GLfloat a = s * da; + GLfloat x = sin(a); + GLfloat y = cos(a); + glBegin(GL_LINE_STRIP); + for (l = 0; l <= loops; l++) { + GLfloat r = innerRadius + l * dr; + glVertex2f(r * x, r * y); + } + glEnd(); + } + break; + } + case GLU_POINT: + { + GLint s; + glBegin(GL_POINTS); + for (s = 0; s < slices; s++) { + GLfloat a = s * da; + GLfloat x = sin(a); + GLfloat y = cos(a); + GLint l; + for (l = 0; l <= loops; l++) { + GLfloat r = innerRadius * l * dr; + glVertex2f(r * x, r * y); + } + } + glEnd(); + break; + } + case GLU_SILHOUETTE: + { + if (innerRadius != 0.0) { + GLfloat a; + glBegin(GL_LINE_LOOP); + for (a = 0.0; a < 2.0 * M_PI; a += da) { + GLfloat x = innerRadius * sin(a); + GLfloat y = innerRadius * cos(a); + glVertex2f(x, y); + } + glEnd(); + } + { + GLfloat a; + glBegin(GL_LINE_LOOP); + for (a = 0; a < 2.0 * M_PI; a += da) { + GLfloat x = outerRadius * sin(a); + GLfloat y = outerRadius * cos(a); + glVertex2f(x, y); + } + glEnd(); + } + break; + } + default: + abort(); + } +} + + + +void GLAPIENTRY +gluPartialDisk(GLUquadricObj * qobj, GLdouble innerRadius, + GLdouble outerRadius, GLint slices, GLint loops, + GLdouble startAngle, GLdouble sweepAngle) +{ + if (qobj->DrawStyle == GLU_POINT) { + GLint loop, slice; + GLdouble radius, delta_radius; + GLdouble angle, delta_angle; + delta_radius = (outerRadius - innerRadius) / (loops - 1); + delta_angle = DEG_TO_RAD((sweepAngle) / (slices - 1)); + glBegin(GL_POINTS); + radius = innerRadius; + for (loop = 0; loop < loops; loop++) { + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice < slices; slice++) { + glVertex2f(radius * sin(angle), radius * cos(angle)); + angle += delta_angle; + } + radius += delta_radius; + } + glEnd(); + } + else if (qobj->DrawStyle == GLU_LINE) { + GLint loop, slice; + GLdouble radius, delta_radius; + GLdouble angle, delta_angle; + delta_radius = (outerRadius - innerRadius) / loops; + delta_angle = DEG_TO_RAD(sweepAngle / slices); + /* draw rings */ + radius = innerRadius; + for (loop = 0; loop < loops; loop++) { + angle = DEG_TO_RAD(startAngle); + glBegin(GL_LINE_STRIP); + for (slice = 0; slice <= slices; slice++) { + glVertex2f(radius * sin(angle), radius * cos(angle)); + angle += delta_angle; + } + glEnd(); + radius += delta_radius; + } + /* draw spokes */ + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice <= slices; slice++) { + radius = innerRadius; + glBegin(GL_LINE_STRIP); + for (loop = 0; loop < loops; loop++) { + glVertex2f(radius * sin(angle), radius * cos(angle)); + radius += delta_radius; + } + glEnd(); + angle += delta_angle; + } + } + else if (qobj->DrawStyle == GLU_SILHOUETTE) { + GLint slice; + GLdouble angle, delta_angle; + delta_angle = DEG_TO_RAD(sweepAngle / slices); + /* draw outer ring */ + glBegin(GL_LINE_STRIP); + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice <= slices; slice++) { + glVertex2f(outerRadius * sin(angle), outerRadius * cos(angle)); + angle += delta_angle; + } + glEnd(); + /* draw inner ring */ + if (innerRadius > 0.0) { + glBegin(GL_LINE_STRIP); + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice < slices; slice++) { + glVertex2f(innerRadius * sin(angle), innerRadius * cos(angle)); + angle += delta_angle; + } + glEnd(); + } + /* draw spokes */ + if (sweepAngle < 360.0) { + GLdouble stopAngle = startAngle + sweepAngle; + glBegin(GL_LINES); + glVertex2f(innerRadius * SIND(startAngle), + innerRadius * COSD(startAngle)); + glVertex2f(outerRadius * SIND(startAngle), + outerRadius * COSD(startAngle)); + glVertex2f(innerRadius * SIND(stopAngle), + innerRadius * COSD(stopAngle)); + glVertex2f(outerRadius * SIND(stopAngle), + outerRadius * COSD(stopAngle)); + glEnd(); + } + } + else if (qobj->DrawStyle == GLU_FILL) { + GLint loop, slice; + GLdouble radius, delta_radius; + GLdouble angle, delta_angle; + delta_radius = (outerRadius - innerRadius) / loops; + delta_angle = DEG_TO_RAD(sweepAngle / slices); + radius = innerRadius; + for (loop = 0; loop < loops; loop++) { + glBegin(GL_QUAD_STRIP); + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice <= slices; slice++) { + if (qobj->Orientation == GLU_OUTSIDE) { + glVertex2f((radius + delta_radius) * sin(angle), + (radius + delta_radius) * cos(angle)); + glVertex2f(radius * sin(angle), radius * cos(angle)); + } + else { + glVertex2f(radius * sin(angle), radius * cos(angle)); + glVertex2f((radius + delta_radius) * sin(angle), + (radius + delta_radius) * cos(angle)); + } + angle += delta_angle; + } + glEnd(); + radius += delta_radius; + } + } +} --- mesa-7.2.orig/src/glu/mini/all.h +++ mesa-7.2/src/glu/mini/all.h @@ -0,0 +1,55 @@ +/* $Id: all.h,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file includes all .h files needed for the GLU source code for + * the purpose of precompiled headers. + * + * If the preprocessor symbol PCH is defined at compile time then each + * of the .c files will #include "all.h" only, instead of a bunch of + * individual .h files. + */ + + +#ifndef GLU_ALL_H +#define GLU_ALL_H + + +#ifndef PC_HEADER +This is an error. all.h should be included only if PCH is defined. +#endif + + +#include +#include +#include +#include +#include +#include "GL/gl.h" +#include "GL/glu.h" +#include "gluP.h" +#include "nurbs.h" +#include "tess.h" + + +#endif /*GLU_ALL_H */ --- mesa-7.2.orig/src/glu/mini/mipmap.c +++ mesa-7.2/src/glu/mini/mipmap.c @@ -0,0 +1,764 @@ +/* $Id: mipmap.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include +#include "gluP.h" +#endif + + +/* + * Compute ceiling of integer quotient of A divided by B: + */ +#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 ) + + + +#ifdef EPSILON +#undef EPSILON +#endif +#define EPSILON 0.001 + + +/* To work around optimizer bug in MSVC4.1 */ +#if defined(__WIN32__) && !defined(OPENSTEP) +void +dummy(GLuint j, GLuint k) +{ +} +#else +#define dummy(J, K) +#endif + + +GLint GLAPIENTRY +gluScaleImage(GLenum format, + GLsizei widthin, GLsizei heightin, + GLenum typein, const void *datain, + GLsizei widthout, GLsizei heightout, + GLenum typeout, void *dataout) +{ + GLint components, i, j, k; + GLfloat *tempin, *tempout, f; + GLfloat sx, sy; + GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels; + GLint packrowlength, packalignment, packskiprows, packskippixels; + GLint sizein, sizeout; + GLint rowstride, rowlen; + + + /* Determine number of components per pixel */ + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + components = 1; + break; + case GL_LUMINANCE_ALPHA: + components = 2; + break; + case GL_RGB: + case GL_BGR: + components = 3; + break; + case GL_RGBA: + case GL_BGRA: +#ifdef GL_EXT_abgr + case GL_ABGR_EXT: +#endif + components = 4; + break; + default: + return GLU_INVALID_ENUM; + } + + /* Determine bytes per input datum */ + switch (typein) { + case GL_UNSIGNED_BYTE: + sizein = sizeof(GLubyte); + break; + case GL_BYTE: + sizein = sizeof(GLbyte); + break; + case GL_UNSIGNED_SHORT: + sizein = sizeof(GLushort); + break; + case GL_SHORT: + sizein = sizeof(GLshort); + break; + case GL_UNSIGNED_INT: + sizein = sizeof(GLuint); + break; + case GL_INT: + sizein = sizeof(GLint); + break; + case GL_FLOAT: + sizein = sizeof(GLfloat); + break; + case GL_BITMAP: + /* not implemented yet */ + default: + return GL_INVALID_ENUM; + } + + /* Determine bytes per output datum */ + switch (typeout) { + case GL_UNSIGNED_BYTE: + sizeout = sizeof(GLubyte); + break; + case GL_BYTE: + sizeout = sizeof(GLbyte); + break; + case GL_UNSIGNED_SHORT: + sizeout = sizeof(GLushort); + break; + case GL_SHORT: + sizeout = sizeof(GLshort); + break; + case GL_UNSIGNED_INT: + sizeout = sizeof(GLuint); + break; + case GL_INT: + sizeout = sizeof(GLint); + break; + case GL_FLOAT: + sizeout = sizeof(GLfloat); + break; + case GL_BITMAP: + /* not implemented yet */ + default: + return GL_INVALID_ENUM; + } + + /* Get glPixelStore state */ + glGetFloatv(GL_UNPACK_ROW_LENGTH, &f); unpackrowlength = (int)f; + glGetFloatv(GL_UNPACK_ALIGNMENT, &f); unpackalignment = (int)f; + glGetFloatv(GL_UNPACK_SKIP_ROWS, &f); unpackskiprows = (int)f; + glGetFloatv(GL_UNPACK_SKIP_PIXELS, &f); unpackskippixels = (int)f; + glGetFloatv(GL_PACK_ROW_LENGTH, &f); packrowlength = (int)f; + glGetFloatv(GL_PACK_ALIGNMENT, &f); packalignment = (int)f; + glGetFloatv(GL_PACK_SKIP_ROWS, &f); packskiprows = (int)f; + glGetFloatv(GL_PACK_SKIP_PIXELS, &f); packskippixels = (int)f; + + /* Allocate storage for intermediate images */ + tempin = (GLfloat *) malloc(widthin * heightin + * components * sizeof(GLfloat)); + if (!tempin) { + return GLU_OUT_OF_MEMORY; + } + tempout = (GLfloat *) malloc(widthout * heightout + * components * sizeof(GLfloat)); + if (!tempout) { + free(tempin); + return GLU_OUT_OF_MEMORY; + } + + + /* + * Unpack the pixel data and convert to floating point + */ + + if (unpackrowlength > 0) { + rowlen = unpackrowlength; + } + else { + rowlen = widthin; + } + if (sizein >= unpackalignment) { + rowstride = components * rowlen; + } + else { + rowstride = unpackalignment / sizein + * CEILING(components * rowlen * sizein, unpackalignment); + } + + switch (typein) { + case GL_UNSIGNED_BYTE: + k = 0; + for (i = 0; i < heightin; i++) { + GLubyte *ubptr = (GLubyte *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * ubptr++; + } + } + break; + case GL_BYTE: + k = 0; + for (i = 0; i < heightin; i++) { + GLbyte *bptr = (GLbyte *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * bptr++; + } + } + break; + case GL_UNSIGNED_SHORT: + k = 0; + for (i = 0; i < heightin; i++) { + GLushort *usptr = (GLushort *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * usptr++; + } + } + break; + case GL_SHORT: + k = 0; + for (i = 0; i < heightin; i++) { + GLshort *sptr = (GLshort *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * sptr++; + } + } + break; + case GL_UNSIGNED_INT: + k = 0; + for (i = 0; i < heightin; i++) { + GLuint *uiptr = (GLuint *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * uiptr++; + } + } + break; + case GL_INT: + k = 0; + for (i = 0; i < heightin; i++) { + GLint *iptr = (GLint *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * iptr++; + } + } + break; + case GL_FLOAT: + k = 0; + for (i = 0; i < heightin; i++) { + GLfloat *fptr = (GLfloat *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = *fptr++; + } + } + break; + default: + return GLU_INVALID_ENUM; + } + + + /* + * Scale the image! + */ + + if (widthout > 1) + sx = (GLfloat) (widthin - 1) / (GLfloat) (widthout - 1); + else + sx = (GLfloat) (widthin - 1); + if (heightout > 1) + sy = (GLfloat) (heightin - 1) / (GLfloat) (heightout - 1); + else + sy = (GLfloat) (heightin - 1); + +/*#define POINT_SAMPLE*/ +#ifdef POINT_SAMPLE + for (i = 0; i < heightout; i++) { + GLint ii = i * sy; + for (j = 0; j < widthout; j++) { + GLint jj = j * sx; + + GLfloat *src = tempin + (ii * widthin + jj) * components; + GLfloat *dst = tempout + (i * widthout + j) * components; + + for (k = 0; k < components; k++) { + *dst++ = *src++; + } + } + } +#else + if (sx < 1.0 && sy < 1.0) { + /* magnify both width and height: use weighted sample of 4 pixels */ + GLint i0, i1, j0, j1; + GLfloat alpha, beta; + GLfloat *src00, *src01, *src10, *src11; + GLfloat s1, s2; + GLfloat *dst; + + for (i = 0; i < heightout; i++) { + i0 = i * sy; + i1 = i0 + 1; + if (i1 >= heightin) + i1 = heightin - 1; +/* i1 = (i+1) * sy - EPSILON;*/ + alpha = i * sy - i0; + for (j = 0; j < widthout; j++) { + j0 = j * sx; + j1 = j0 + 1; + if (j1 >= widthin) + j1 = widthin - 1; +/* j1 = (j+1) * sx - EPSILON; */ + beta = j * sx - j0; + + /* compute weighted average of pixels in rect (i0,j0)-(i1,j1) */ + src00 = tempin + (i0 * widthin + j0) * components; + src01 = tempin + (i0 * widthin + j1) * components; + src10 = tempin + (i1 * widthin + j0) * components; + src11 = tempin + (i1 * widthin + j1) * components; + + dst = tempout + (i * widthout + j) * components; + + for (k = 0; k < components; k++) { + s1 = *src00++ * (1.0 - beta) + *src01++ * beta; + s2 = *src10++ * (1.0 - beta) + *src11++ * beta; + *dst++ = s1 * (1.0 - alpha) + s2 * alpha; + } + } + } + } + else { + /* shrink width and/or height: use an unweighted box filter */ + GLint i0, i1; + GLint j0, j1; + GLint ii, jj; + GLfloat sum, *dst; + + for (i = 0; i < heightout; i++) { + i0 = i * sy; + i1 = i0 + 1; + if (i1 >= heightin) + i1 = heightin - 1; +/* i1 = (i+1) * sy - EPSILON; */ + for (j = 0; j < widthout; j++) { + j0 = j * sx; + j1 = j0 + 1; + if (j1 >= widthin) + j1 = widthin - 1; +/* j1 = (j+1) * sx - EPSILON; */ + + dst = tempout + (i * widthout + j) * components; + + /* compute average of pixels in the rectangle (i0,j0)-(i1,j1) */ + for (k = 0; k < components; k++) { + sum = 0.0; + for (ii = i0; ii <= i1; ii++) { + for (jj = j0; jj <= j1; jj++) { + sum += *(tempin + (ii * widthin + jj) * components + k); + } + } + sum /= (j1 - j0 + 1) * (i1 - i0 + 1); + *dst++ = sum; + } + } + } + } +#endif + + + /* + * Return output image + */ + + if (packrowlength > 0) { + rowlen = packrowlength; + } + else { + rowlen = widthout; + } + if (sizeout >= packalignment) { + rowstride = components * rowlen; + } + else { + rowstride = packalignment / sizeout + * CEILING(components * rowlen * sizeout, packalignment); + } + + switch (typeout) { + case GL_UNSIGNED_BYTE: + k = 0; + for (i = 0; i < heightout; i++) { + GLubyte *ubptr = (GLubyte *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *ubptr++ = (GLubyte) tempout[k++]; + } + } + break; + case GL_BYTE: + k = 0; + for (i = 0; i < heightout; i++) { + GLbyte *bptr = (GLbyte *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *bptr++ = (GLbyte) tempout[k++]; + } + } + break; + case GL_UNSIGNED_SHORT: + k = 0; + for (i = 0; i < heightout; i++) { + GLushort *usptr = (GLushort *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *usptr++ = (GLushort) tempout[k++]; + } + } + break; + case GL_SHORT: + k = 0; + for (i = 0; i < heightout; i++) { + GLshort *sptr = (GLshort *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *sptr++ = (GLshort) tempout[k++]; + } + } + break; + case GL_UNSIGNED_INT: + k = 0; + for (i = 0; i < heightout; i++) { + GLuint *uiptr = (GLuint *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *uiptr++ = (GLuint) tempout[k++]; + } + } + break; + case GL_INT: + k = 0; + for (i = 0; i < heightout; i++) { + GLint *iptr = (GLint *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *iptr++ = (GLint) tempout[k++]; + } + } + break; + case GL_FLOAT: + k = 0; + for (i = 0; i < heightout; i++) { + GLfloat *fptr = (GLfloat *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *fptr++ = tempout[k++]; + } + } + break; + default: + return GLU_INVALID_ENUM; + } + + + /* free temporary image storage */ + free(tempin); + free(tempout); + + return 0; +} + + + +/* + * Return the largest k such that 2^k <= n. + */ +static GLint +ilog2(GLint n) +{ + GLint k; + + if (n <= 0) + return 0; + for (k = 0; n >>= 1; k++); + return k; +} + + + +/* + * Find the value nearest to n which is also a power of two. + */ +static GLint +round2(GLint n) +{ + GLint m; + + for (m = 1; m < n; m *= 2); + + /* m>=n */ + if (m - n <= n - m / 2) { + return m; + } + else { + return m / 2; + } +} + + +/* + * Given an pixel format and data type, return the number of bytes to + * store one pixel. + */ +static GLint +bytes_per_pixel(GLenum format, GLenum type) +{ + GLint n, m; + + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + n = 1; + break; + case GL_LUMINANCE_ALPHA: + n = 2; + break; + case GL_RGB: + case GL_BGR: + n = 3; + break; + case GL_RGBA: + case GL_BGRA: +#ifdef GL_EXT_abgr + case GL_ABGR_EXT: +#endif + n = 4; + break; + default: + n = 0; + } + + switch (type) { + case GL_UNSIGNED_BYTE: + m = sizeof(GLubyte); + break; + case GL_BYTE: + m = sizeof(GLbyte); + break; + case GL_BITMAP: + m = 1; + break; + case GL_UNSIGNED_SHORT: + m = sizeof(GLushort); + break; + case GL_SHORT: + m = sizeof(GLshort); + break; + case GL_UNSIGNED_INT: + m = sizeof(GLuint); + break; + case GL_INT: + m = sizeof(GLint); + break; + case GL_FLOAT: + m = sizeof(GLfloat); + break; + default: + m = 0; + } + + return n * m; +} + + + +/* + * WARNING: This function isn't finished and has never been tested!!!! + */ +GLint GLAPIENTRY +gluBuild1DMipmaps(GLenum target, GLint components, + GLsizei width, GLenum format, GLenum type, const void *data) +{ + return 0; +} + + + +GLint GLAPIENTRY +gluBuild2DMipmaps(GLenum target, GLint components, + GLsizei width, GLsizei height, GLenum format, + GLenum type, const void *data) +{ + GLint w, h; + GLint maxsize; + void *image, *newimage; + GLint neww, newh, level, bpp; + int error; + GLboolean done; + GLint retval = 0; + GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels; + GLint packrowlength, packalignment, packskiprows, packskippixels; + GLfloat f; + + if (width < 1 || height < 1) + return GLU_INVALID_VALUE; + + glGetFloatv(GL_MAX_TEXTURE_SIZE, &f); maxsize = (int)f; + + w = round2(width); + if (w > maxsize) { + w = maxsize; + } + h = round2(height); + if (h > maxsize) { + h = maxsize; + } + + bpp = bytes_per_pixel(format, type); + if (bpp == 0) { + /* probably a bad format or type enum */ + return GLU_INVALID_ENUM; + } + + /* Get current glPixelStore values */ + glGetFloatv(GL_UNPACK_ROW_LENGTH, &f); unpackrowlength = (int)f; + glGetFloatv(GL_UNPACK_ALIGNMENT, &f); unpackalignment = (int)f; + glGetFloatv(GL_UNPACK_SKIP_ROWS, &f); unpackskiprows = (int)f; + glGetFloatv(GL_UNPACK_SKIP_PIXELS, &f); unpackskippixels = (int)f; + glGetFloatv(GL_PACK_ROW_LENGTH, &f); packrowlength = (int)f; + glGetFloatv(GL_PACK_ALIGNMENT, &f); packalignment = (int)f; + glGetFloatv(GL_PACK_SKIP_ROWS, &f); packskiprows = (int)f; + glGetFloatv(GL_PACK_SKIP_PIXELS, &f); packskippixels = (int)f; + + /* set pixel packing */ + glPixelStorei(GL_PACK_ROW_LENGTH, 0); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_SKIP_ROWS, 0); + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + + done = GL_FALSE; + + if (w != width || h != height) { + /* must rescale image to get "top" mipmap texture image */ + image = malloc((w + 4) * h * bpp); + if (!image) { + return GLU_OUT_OF_MEMORY; + } + error = gluScaleImage(format, width, height, type, data, + w, h, type, image); + if (error) { + retval = error; + done = GL_TRUE; + } + } + else { + image = (void *) data; + } + + level = 0; + while (!done) { + if (image != data) { + /* set pixel unpacking */ + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + } + + glTexImage2D(target, level, components, w, h, 0, format, type, image); + + if (w == 1 && h == 1) + break; + + neww = (w < 2) ? 1 : w / 2; + newh = (h < 2) ? 1 : h / 2; + newimage = malloc((neww + 4) * newh * bpp); + if (!newimage) { + return GLU_OUT_OF_MEMORY; + } + + error = gluScaleImage(format, w, h, type, image, + neww, newh, type, newimage); + if (error) { + retval = error; + done = GL_TRUE; + } + + if (image != data) { + free(image); + } + image = newimage; + + w = neww; + h = newh; + level++; + } + + if (image != data) { + free(image); + } + + /* Restore original glPixelStore state */ + glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackrowlength); + glPixelStorei(GL_UNPACK_ALIGNMENT, unpackalignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, unpackskiprows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackskippixels); + glPixelStorei(GL_PACK_ROW_LENGTH, packrowlength); + glPixelStorei(GL_PACK_ALIGNMENT, packalignment); + glPixelStorei(GL_PACK_SKIP_ROWS, packskiprows); + glPixelStorei(GL_PACK_SKIP_PIXELS, packskippixels); + + return retval; +} --- mesa-7.2.orig/src/glu/mini/project.c +++ mesa-7.2/src/glu/mini/project.c @@ -0,0 +1,404 @@ +/* $Id: project.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include "gluP.h" +#endif + + +/* + * This code was contributed by Marc Buffat (buffat@mecaflu.ec-lyon.fr). + * Thanks Marc!!! + */ + + + +/* implementation de gluProject et gluUnproject */ +/* M. Buffat 17/2/95 */ + + + +/* + * Transform a point (column vector) by a 4x4 matrix. I.e. out = m * in + * Input: m - the 4x4 matrix + * in - the 4x1 vector + * Output: out - the resulting 4x1 vector. + */ +static void +transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) +{ +#define M(row,col) m[col*4+row] + out[0] = + M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; + out[1] = + M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3]; + out[2] = + M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3]; + out[3] = + M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3]; +#undef M +} + + + + +/* + * Perform a 4x4 matrix multiplication (product = a x b). + * Input: a, b - matrices to multiply + * Output: product - product of a and b + */ +static void +matmul(GLdouble * product, const GLdouble * a, const GLdouble * b) +{ + /* This matmul was contributed by Thomas Malik */ + GLdouble temp[16]; + GLint i; + +#define A(row,col) a[(col<<2)+row] +#define B(row,col) b[(col<<2)+row] +#define T(row,col) temp[(col<<2)+row] + + /* i-te Zeile */ + for (i = 0; i < 4; i++) { + T(i, 0) = + A(i, 0) * B(0, 0) + A(i, 1) * B(1, 0) + A(i, 2) * B(2, 0) + A(i, + 3) * + B(3, 0); + T(i, 1) = + A(i, 0) * B(0, 1) + A(i, 1) * B(1, 1) + A(i, 2) * B(2, 1) + A(i, + 3) * + B(3, 1); + T(i, 2) = + A(i, 0) * B(0, 2) + A(i, 1) * B(1, 2) + A(i, 2) * B(2, 2) + A(i, + 3) * + B(3, 2); + T(i, 3) = + A(i, 0) * B(0, 3) + A(i, 1) * B(1, 3) + A(i, 2) * B(2, 3) + A(i, + 3) * + B(3, 3); + } + +#undef A +#undef B +#undef T + MEMCPY(product, temp, 16 * sizeof(GLdouble)); +} + + + +/* + * Compute inverse of 4x4 transformation matrix. + * Code contributed by Jacques Leroy jle@star.be + * Return GL_TRUE for success, GL_FALSE for failure (singular matrix) + */ +static GLboolean +invert_matrix(const GLdouble * m, GLdouble * out) +{ +/* NB. OpenGL Matrices are COLUMN major. */ +#define SWAP_ROWS(a, b) { GLdouble *_tmp = a; (a)=(b); (b)=_tmp; } +#define MAT(m,r,c) (m)[(c)*4+(r)] + + GLdouble wtmp[4][8]; + GLdouble m0, m1, m2, m3, s; + GLdouble *r0, *r1, *r2, *r3; + + r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3]; + + r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1), + r0[2] = MAT(m, 0, 2), r0[3] = MAT(m, 0, 3), + r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0, + r1[0] = MAT(m, 1, 0), r1[1] = MAT(m, 1, 1), + r1[2] = MAT(m, 1, 2), r1[3] = MAT(m, 1, 3), + r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0, + r2[0] = MAT(m, 2, 0), r2[1] = MAT(m, 2, 1), + r2[2] = MAT(m, 2, 2), r2[3] = MAT(m, 2, 3), + r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0, + r3[0] = MAT(m, 3, 0), r3[1] = MAT(m, 3, 1), + r3[2] = MAT(m, 3, 2), r3[3] = MAT(m, 3, 3), + r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0; + + /* choose pivot - or die */ + if (fabs(r3[0]) > fabs(r2[0])) + SWAP_ROWS(r3, r2); + if (fabs(r2[0]) > fabs(r1[0])) + SWAP_ROWS(r2, r1); + if (fabs(r1[0]) > fabs(r0[0])) + SWAP_ROWS(r1, r0); + if (0.0 == r0[0]) + return GL_FALSE; + + /* eliminate first variable */ + m1 = r1[0] / r0[0]; + m2 = r2[0] / r0[0]; + m3 = r3[0] / r0[0]; + s = r0[1]; + r1[1] -= m1 * s; + r2[1] -= m2 * s; + r3[1] -= m3 * s; + s = r0[2]; + r1[2] -= m1 * s; + r2[2] -= m2 * s; + r3[2] -= m3 * s; + s = r0[3]; + r1[3] -= m1 * s; + r2[3] -= m2 * s; + r3[3] -= m3 * s; + s = r0[4]; + if (s != 0.0) { + r1[4] -= m1 * s; + r2[4] -= m2 * s; + r3[4] -= m3 * s; + } + s = r0[5]; + if (s != 0.0) { + r1[5] -= m1 * s; + r2[5] -= m2 * s; + r3[5] -= m3 * s; + } + s = r0[6]; + if (s != 0.0) { + r1[6] -= m1 * s; + r2[6] -= m2 * s; + r3[6] -= m3 * s; + } + s = r0[7]; + if (s != 0.0) { + r1[7] -= m1 * s; + r2[7] -= m2 * s; + r3[7] -= m3 * s; + } + + /* choose pivot - or die */ + if (fabs(r3[1]) > fabs(r2[1])) + SWAP_ROWS(r3, r2); + if (fabs(r2[1]) > fabs(r1[1])) + SWAP_ROWS(r2, r1); + if (0.0 == r1[1]) + return GL_FALSE; + + /* eliminate second variable */ + m2 = r2[1] / r1[1]; + m3 = r3[1] / r1[1]; + r2[2] -= m2 * r1[2]; + r3[2] -= m3 * r1[2]; + r2[3] -= m2 * r1[3]; + r3[3] -= m3 * r1[3]; + s = r1[4]; + if (0.0 != s) { + r2[4] -= m2 * s; + r3[4] -= m3 * s; + } + s = r1[5]; + if (0.0 != s) { + r2[5] -= m2 * s; + r3[5] -= m3 * s; + } + s = r1[6]; + if (0.0 != s) { + r2[6] -= m2 * s; + r3[6] -= m3 * s; + } + s = r1[7]; + if (0.0 != s) { + r2[7] -= m2 * s; + r3[7] -= m3 * s; + } + + /* choose pivot - or die */ + if (fabs(r3[2]) > fabs(r2[2])) + SWAP_ROWS(r3, r2); + if (0.0 == r2[2]) + return GL_FALSE; + + /* eliminate third variable */ + m3 = r3[2] / r2[2]; + r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4], + r3[5] -= m3 * r2[5], r3[6] -= m3 * r2[6], r3[7] -= m3 * r2[7]; + + /* last check */ + if (0.0 == r3[3]) + return GL_FALSE; + + s = 1.0 / r3[3]; /* now back substitute row 3 */ + r3[4] *= s; + r3[5] *= s; + r3[6] *= s; + r3[7] *= s; + + m2 = r2[3]; /* now back substitute row 2 */ + s = 1.0 / r2[2]; + r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2), + r2[6] = s * (r2[6] - r3[6] * m2), r2[7] = s * (r2[7] - r3[7] * m2); + m1 = r1[3]; + r1[4] -= r3[4] * m1, r1[5] -= r3[5] * m1, + r1[6] -= r3[6] * m1, r1[7] -= r3[7] * m1; + m0 = r0[3]; + r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0, + r0[6] -= r3[6] * m0, r0[7] -= r3[7] * m0; + + m1 = r1[2]; /* now back substitute row 1 */ + s = 1.0 / r1[1]; + r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1), + r1[6] = s * (r1[6] - r2[6] * m1), r1[7] = s * (r1[7] - r2[7] * m1); + m0 = r0[2]; + r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0, + r0[6] -= r2[6] * m0, r0[7] -= r2[7] * m0; + + m0 = r0[1]; /* now back substitute row 0 */ + s = 1.0 / r0[0]; + r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0), + r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0); + + MAT(out, 0, 0) = r0[4]; + MAT(out, 0, 1) = r0[5], MAT(out, 0, 2) = r0[6]; + MAT(out, 0, 3) = r0[7], MAT(out, 1, 0) = r1[4]; + MAT(out, 1, 1) = r1[5], MAT(out, 1, 2) = r1[6]; + MAT(out, 1, 3) = r1[7], MAT(out, 2, 0) = r2[4]; + MAT(out, 2, 1) = r2[5], MAT(out, 2, 2) = r2[6]; + MAT(out, 2, 3) = r2[7], MAT(out, 3, 0) = r3[4]; + MAT(out, 3, 1) = r3[5], MAT(out, 3, 2) = r3[6]; + MAT(out, 3, 3) = r3[7]; + + return GL_TRUE; + +#undef MAT +#undef SWAP_ROWS +} + + + +/* projection du point (objx,objy,obz) sur l'ecran (winx,winy,winz) */ +GLint GLAPIENTRY +gluProject(GLdouble objx, GLdouble objy, GLdouble objz, + const GLdouble model[16], const GLdouble proj[16], + const GLint viewport[4], + GLdouble * winx, GLdouble * winy, GLdouble * winz) +{ + /* matrice de transformation */ + GLdouble in[4], out[4]; + + /* initilise la matrice et le vecteur a transformer */ + in[0] = objx; + in[1] = objy; + in[2] = objz; + in[3] = 1.0; + transform_point(out, model, in); + transform_point(in, proj, out); + + /* d'ou le resultat normalise entre -1 et 1 */ + if (in[3] == 0.0) + return GL_FALSE; + + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + + /* en coordonnees ecran */ + *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; + *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; + /* entre 0 et 1 suivant z */ + *winz = (1 + in[2]) / 2; + return GL_TRUE; +} + + + +/* transformation du point ecran (winx,winy,winz) en point objet */ +GLint GLAPIENTRY +gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz, + const GLdouble model[16], const GLdouble proj[16], + const GLint viewport[4], + GLdouble * objx, GLdouble * objy, GLdouble * objz) +{ + /* matrice de transformation */ + GLdouble m[16], A[16]; + GLdouble in[4], out[4]; + + /* transformation coordonnees normalisees entre -1 et 1 */ + in[0] = (winx - viewport[0]) * 2 / viewport[2] - 1.0; + in[1] = (winy - viewport[1]) * 2 / viewport[3] - 1.0; + in[2] = 2 * winz - 1.0; + in[3] = 1.0; + + /* calcul transformation inverse */ + matmul(A, proj, model); + if (!invert_matrix(A, m)) + return GL_FALSE; + + /* d'ou les coordonnees objets */ + transform_point(out, m, in); + if (out[3] == 0.0) + return GL_FALSE; + *objx = out[0] / out[3]; + *objy = out[1] / out[3]; + *objz = out[2] / out[3]; + return GL_TRUE; +} + + +/* + * New in GLU 1.3 + * This is like gluUnProject but also takes near and far DepthRange values. + */ +#ifdef GLU_VERSION_1_3 +GLint GLAPIENTRY +gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw, + const GLdouble modelMatrix[16], + const GLdouble projMatrix[16], + const GLint viewport[4], + GLclampd nearZ, GLclampd farZ, + GLdouble * objx, GLdouble * objy, GLdouble * objz, + GLdouble * objw) +{ + /* matrice de transformation */ + GLdouble m[16], A[16]; + GLdouble in[4], out[4]; + GLdouble z = nearZ + winz * (farZ - nearZ); + + /* transformation coordonnees normalisees entre -1 et 1 */ + in[0] = (winx - viewport[0]) * 2 / viewport[2] - 1.0; + in[1] = (winy - viewport[1]) * 2 / viewport[3] - 1.0; + in[2] = 2.0 * z - 1.0; + in[3] = clipw; + + /* calcul transformation inverse */ + matmul(A, projMatrix, modelMatrix); + if (!invert_matrix(A, m)) + return GL_FALSE; + + /* d'ou les coordonnees objets */ + transform_point(out, m, in); + if (out[3] == 0.0) + return GL_FALSE; + *objx = out[0] / out[3]; + *objy = out[1] / out[3]; + *objz = out[2] / out[3]; + *objw = out[3]; + return GL_TRUE; +} +#endif --- mesa-7.2.orig/src/glu/mini/tesselat.c +++ mesa-7.2/src/glu/mini/tesselat.c @@ -0,0 +1,407 @@ +/* $Id: tesselat.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "tess.h" +#endif + + + +static GLboolean edge_flag; + +static void emit_triangle(GLUtriangulatorObj *, tess_vertex *, + tess_vertex *, tess_vertex *); + +static void emit_triangle_with_edge_flag(GLUtriangulatorObj *, + tess_vertex *, GLboolean, + tess_vertex *, GLboolean, + tess_vertex *, GLboolean); + +static GLdouble +twice_the_triangle_area(tess_vertex * va, tess_vertex * vb, tess_vertex * vc) +{ + return (vb->x - va->x) * (vc->y - va->y) - (vb->y - va->y) * (vc->x - + va->x); +} + +static GLboolean +left(GLdouble A, GLdouble B, GLdouble C, GLdouble x, GLdouble y) +{ + if (A * x + B * y + C > -EPSILON) + return GL_TRUE; + else + return GL_FALSE; +} + +static GLboolean +right(GLdouble A, GLdouble B, GLdouble C, GLdouble x, GLdouble y) +{ + if (A * x + B * y + C < EPSILON) + return GL_TRUE; + else + return GL_FALSE; +} + +static GLint +convex_ccw(tess_vertex * va, + tess_vertex * vb, tess_vertex * vc, GLUtriangulatorObj * tobj) +{ + GLdouble d; + + d = twice_the_triangle_area(va, vb, vc); + + if (d > EPSILON) { + return 1; + } + else if (d < -EPSILON) { + return 0; + } + else { + return -1; + } +} + +static GLint +convex_cw(tess_vertex * va, + tess_vertex * vb, tess_vertex * vc, GLUtriangulatorObj * tobj) +{ + GLdouble d; + + d = twice_the_triangle_area(va, vb, vc); + + if (d < -EPSILON) { + return 1; + } + else if (d > EPSILON) { + return 0; + } + else { + return -1; + } +} + +static GLboolean +diagonal_ccw(tess_vertex * va, + tess_vertex * vb, + GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vc = va->next, *vertex, *shadow_vertex; + struct + { + GLdouble A, B, C; + } + ac, cb, ba; + GLdouble x, y; + + GLint res = convex_ccw(va, vc, vb, tobj); + if (res == 0) + return GL_FALSE; + if (res == -1) + return GL_TRUE; + + ba.A = vb->y - va->y; + ba.B = va->x - vb->x; + ba.C = -ba.A * va->x - ba.B * va->y; + ac.A = va->y - vc->y; + ac.B = vc->x - va->x; + ac.C = -ac.A * vc->x - ac.B * vc->y; + cb.A = vc->y - vb->y; + cb.B = vb->x - vc->x; + cb.C = -cb.A * vb->x - cb.B * vb->y; + for (vertex = vb->next; vertex != va; vertex = vertex->next) { + shadow_vertex = vertex->shadow_vertex; + if (shadow_vertex != NULL && + (shadow_vertex == va || shadow_vertex == vb || shadow_vertex == vc)) + continue; + x = vertex->x; + y = vertex->y; + if (left(ba.A, ba.B, ba.C, x, y) && + left(ac.A, ac.B, ac.C, x, y) && left(cb.A, cb.B, cb.C, x, y)) + return GL_FALSE; + } + return GL_TRUE; +} + +static GLboolean +diagonal_cw(tess_vertex * va, + tess_vertex * vb, + GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vc = va->next, *vertex, *shadow_vertex; + struct + { + GLdouble A, B, C; + } + ac, cb, ba; + GLdouble x, y; + + GLint res = convex_cw(va, vc, vb, tobj); + if (res == 0) + return GL_FALSE; + if (res == -1) + return GL_TRUE; + + ba.A = vb->y - va->y; + ba.B = va->x - vb->x; + ba.C = -ba.A * va->x - ba.B * va->y; + ac.A = va->y - vc->y; + ac.B = vc->x - va->x; + ac.C = -ac.A * vc->x - ac.B * vc->y; + cb.A = vc->y - vb->y; + cb.B = vb->x - vc->x; + cb.C = -cb.A * vb->x - cb.B * vb->y; + for (vertex = vb->next; vertex != va; vertex = vertex->next) { + shadow_vertex = vertex->shadow_vertex; + if (shadow_vertex != NULL && + (shadow_vertex == va || shadow_vertex == vb || shadow_vertex == vc)) + continue; + x = vertex->x; + y = vertex->y; + if (right(ba.A, ba.B, ba.C, x, y) && + right(ac.A, ac.B, ac.C, x, y) && right(cb.A, cb.B, cb.C, x, y)) + return GL_FALSE; + } + return GL_TRUE; +} + +static void +clip_ear(GLUtriangulatorObj * tobj, tess_vertex * v, tess_contour * contour) +{ + emit_triangle(tobj, v->previous, v, v->next); + /* the first in the list */ + if (contour->vertices == v) { + contour->vertices = v->next; + contour->last_vertex->next = v->next; + v->next->previous = contour->last_vertex; + } + else + /* the last ? */ + if (contour->last_vertex == v) { + contour->vertices->previous = v->previous; + v->previous->next = v->next; + contour->last_vertex = v->previous; + } + else { + v->next->previous = v->previous; + v->previous->next = v->next; + } + free(v); + --(contour->vertex_cnt); +} + +static void +clip_ear_with_edge_flag(GLUtriangulatorObj * tobj, + tess_vertex * v, tess_contour * contour) +{ + emit_triangle_with_edge_flag(tobj, v->previous, v->previous->edge_flag, + v, v->edge_flag, v->next, GL_FALSE); + v->previous->edge_flag = GL_FALSE; + /* the first in the list */ + if (contour->vertices == v) { + contour->vertices = v->next; + contour->last_vertex->next = v->next; + v->next->previous = contour->last_vertex; + } + else + /* the last ? */ + if (contour->last_vertex == v) { + contour->vertices->previous = v->previous; + v->previous->next = v->next; + contour->last_vertex = v->previous; + } + else { + v->next->previous = v->previous; + v->previous->next = v->next; + } + free(v); + --(contour->vertex_cnt); +} + +static void +triangulate_ccw(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_ccw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +static void +triangulate_cw(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_cw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +static void +triangulate_ccw_with_edge_flag(GLUtriangulatorObj * tobj, + tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_ccw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear_with_edge_flag(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +static void +triangulate_cw_with_edge_flag(GLUtriangulatorObj * tobj, + tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_cw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear_with_edge_flag(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +void +tess_tesselate(GLUtriangulatorObj * tobj) +{ + tess_contour *contour; + + for (contour = tobj->contours; contour != NULL; contour = contour->next) { + if (contour->orientation == GLU_CCW) { + triangulate_ccw(tobj, contour); + } + else { + triangulate_cw(tobj, contour); + } + if (tobj->error != GLU_NO_ERROR) + return; + + /* emit the last triangle */ + emit_triangle(tobj, contour->vertices, contour->vertices->next, + contour->vertices->next->next); + } +} + +void +tess_tesselate_with_edge_flag(GLUtriangulatorObj * tobj) +{ + tess_contour *contour; + + edge_flag = GL_TRUE; + /* first callback with edgeFlag set to GL_TRUE */ + (tobj->callbacks.edgeFlag) (GL_TRUE); + + for (contour = tobj->contours; contour != NULL; contour = contour->next) { + if (contour->orientation == GLU_CCW) + triangulate_ccw_with_edge_flag(tobj, contour); + else + triangulate_cw_with_edge_flag(tobj, contour); + if (tobj->error != GLU_NO_ERROR) + return; + /* emit the last triangle */ + emit_triangle_with_edge_flag(tobj, contour->vertices, + contour->vertices->edge_flag, + contour->vertices->next, + contour->vertices->next->edge_flag, + contour->vertices->next->next, + contour->vertices->next->next->edge_flag); + } +} + +static void +emit_triangle(GLUtriangulatorObj * tobj, + tess_vertex * v1, tess_vertex * v2, tess_vertex * v3) +{ + (tobj->callbacks.begin) (GL_TRIANGLES); + (tobj->callbacks.vertex) (v1->data); + (tobj->callbacks.vertex) (v2->data); + (tobj->callbacks.vertex) (v3->data); + (tobj->callbacks.end) (); +} + +static void +emit_triangle_with_edge_flag(GLUtriangulatorObj * tobj, + tess_vertex * v1, + GLboolean edge_flag1, + tess_vertex * v2, + GLboolean edge_flag2, + tess_vertex * v3, GLboolean edge_flag3) +{ + (tobj->callbacks.begin) (GL_TRIANGLES); + if (edge_flag1 != edge_flag) { + edge_flag = (edge_flag == GL_TRUE ? GL_FALSE : GL_TRUE); + (tobj->callbacks.edgeFlag) (edge_flag); + } + (tobj->callbacks.vertex) (v1->data); + if (edge_flag2 != edge_flag) { + edge_flag = (edge_flag == GL_TRUE ? GL_FALSE : GL_TRUE); + (tobj->callbacks.edgeFlag) (edge_flag); + } + (tobj->callbacks.vertex) (v2->data); + if (edge_flag3 != edge_flag) { + edge_flag = (edge_flag == GL_TRUE ? GL_FALSE : GL_TRUE); + (tobj->callbacks.edgeFlag) (edge_flag); + } + (tobj->callbacks.vertex) (v3->data); + (tobj->callbacks.end) (); +} --- mesa-7.2.orig/src/glu/mini/nurbscrv.c +++ mesa-7.2/src/glu/mini/nurbscrv.c @@ -0,0 +1,133 @@ +/* $Id: nurbscrv.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "gluP.h" +#include "nurbs.h" +#endif + + + +/* main NURBS curve procedure */ +void +do_nurbs_curve(GLUnurbsObj * nobj) +{ + GLint geom_order, color_order = 0, normal_order = 0, texture_order = 0; + GLenum geom_type; + GLint n_ctrl; + GLfloat *new_geom_ctrl, *new_color_ctrl, *new_normal_ctrl, + *new_texture_ctrl; + GLfloat *geom_ctrl = 0, *color_ctrl = 0, *normal_ctrl = 0, *texture_ctrl = 0; + GLint *factors; + GLint i, j; + GLint geom_dim, color_dim = 0, normal_dim = 0, texture_dim = 0; + + /* test the user supplied data */ + if (test_nurbs_curves(nobj) != GLU_NO_ERROR) + return; + + if (convert_curves(nobj, &new_geom_ctrl, &n_ctrl, &new_color_ctrl, + &new_normal_ctrl, &new_texture_ctrl) != GLU_NO_ERROR) + return; + + geom_order = nobj->curve.geom.order; + geom_type = nobj->curve.geom.type; + geom_dim = nobj->curve.geom.dim; + + if (glu_do_sampling_crv(nobj, new_geom_ctrl, n_ctrl, geom_order, geom_dim, + &factors) != GLU_NO_ERROR) { + free(new_geom_ctrl); + if (new_color_ctrl) + free(new_color_ctrl); + if (new_normal_ctrl) + free(new_normal_ctrl); + if (new_texture_ctrl) + free(new_texture_ctrl); + return; + } + glEnable(geom_type); + if (new_color_ctrl) { + glEnable(nobj->curve.color.type); + color_dim = nobj->curve.color.dim; + color_ctrl = new_color_ctrl; + color_order = nobj->curve.color.order; + } + if (new_normal_ctrl) { + glEnable(nobj->curve.normal.type); + normal_dim = nobj->curve.normal.dim; + normal_ctrl = new_normal_ctrl; + normal_order = nobj->curve.normal.order; + } + if (new_texture_ctrl) { + glEnable(nobj->curve.texture.type); + texture_dim = nobj->curve.texture.dim; + texture_ctrl = new_texture_ctrl; + texture_order = nobj->curve.texture.order; + } + for (i = 0, j = 0, geom_ctrl = new_geom_ctrl; + i < n_ctrl; i += geom_order, j++, geom_ctrl += geom_order * geom_dim) { + if (fine_culling_test_2D + (nobj, geom_ctrl, geom_order, geom_dim, geom_dim)) { + color_ctrl += color_order * color_dim; + normal_ctrl += normal_order * normal_dim; + texture_ctrl += texture_order * texture_dim; + continue; + } + glMap1f(geom_type, 0.0, 1.0, geom_dim, geom_order, geom_ctrl); + if (new_color_ctrl) { + glMap1f(nobj->curve.color.type, 0.0, 1.0, color_dim, + color_order, color_ctrl); + color_ctrl += color_order * color_dim; + } + if (new_normal_ctrl) { + glMap1f(nobj->curve.normal.type, 0.0, 1.0, normal_dim, + normal_order, normal_ctrl); + normal_ctrl += normal_order * normal_dim; + } + if (new_texture_ctrl) { + glMap1f(nobj->curve.texture.type, 0.0, 1.0, texture_dim, + texture_order, texture_ctrl); + texture_ctrl += texture_order * texture_dim; + } + glMapGrid1f(factors[j], 0.0, 1.0); + glEvalMesh1(GL_LINE, 0, factors[j]); + } + free(new_geom_ctrl); + free(factors); + if (new_color_ctrl) + free(new_color_ctrl); + if (new_normal_ctrl) + free(new_normal_ctrl); + if (new_texture_ctrl) + free(new_texture_ctrl); +} --- mesa-7.2.orig/src/glu/mini/polytest.c +++ mesa-7.2/src/glu/mini/polytest.c @@ -0,0 +1,938 @@ +/* $Id: polytest.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "gluP.h" +#include "tess.h" +#endif + + + +static GLenum store_polygon_as_contour(GLUtriangulatorObj *); +static void free_current_polygon(tess_polygon *); +static void prepare_projection_info(GLUtriangulatorObj *); +static GLdouble twice_the_polygon_area(tess_vertex *, tess_vertex *); +static GLenum verify_edge_vertex_intersections(GLUtriangulatorObj *); +void tess_find_contour_hierarchies(GLUtriangulatorObj *); +static GLenum test_for_overlapping_contours(GLUtriangulatorObj *); +static GLenum contours_overlap(tess_contour *, tess_polygon *); +static GLenum is_contour_contained_in(tess_contour *, tess_contour *); +static void add_new_exterior(GLUtriangulatorObj *, tess_contour *); +static void add_new_interior(GLUtriangulatorObj *, tess_contour *, + tess_contour *); +static void add_interior_with_hierarchy_check(GLUtriangulatorObj *, + tess_contour *, tess_contour *); +static void reverse_hierarchy_and_add_exterior(GLUtriangulatorObj *, + tess_contour *, + tess_contour *); +static GLboolean point_in_polygon(tess_contour *, GLdouble, GLdouble); +static void shift_interior_to_exterior(GLUtriangulatorObj *, tess_contour *); +static void add_exterior_with_check(GLUtriangulatorObj *, tess_contour *, + tess_contour *); +static GLenum cut_out_hole(GLUtriangulatorObj *, tess_contour *, + tess_contour *); +static GLenum merge_hole_with_contour(GLUtriangulatorObj *, + tess_contour *, tess_contour *, + tess_vertex *, tess_vertex *); + +static GLenum +find_normal(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *va, *vb, *vc; + GLdouble A, B, C; + GLdouble A0, A1, A2, B0, B1, B2; + + va = polygon->vertices; + vb = va->next; + A0 = vb->location[0] - va->location[0]; + A1 = vb->location[1] - va->location[1]; + A2 = vb->location[2] - va->location[2]; + for (vc = vb->next; vc != va; vc = vc->next) { + B0 = vc->location[0] - va->location[0]; + B1 = vc->location[1] - va->location[1]; + B2 = vc->location[2] - va->location[2]; + A = A1 * B2 - A2 * B1; + B = A2 * B0 - A0 * B2; + C = A0 * B1 - A1 * B0; + if (fabs(A) > EPSILON || fabs(B) > EPSILON || fabs(C) > EPSILON) { + polygon->A = A; + polygon->B = B; + polygon->C = C; + polygon->D = + -A * va->location[0] - B * va->location[1] - C * va->location[2]; + return GLU_NO_ERROR; + } + } + tess_call_user_error(tobj, GLU_TESS_ERROR7); + return GLU_ERROR; +} + +void +tess_test_polygon(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + + /* any vertices defined? */ + if (polygon->vertex_cnt < 3) { + free_current_polygon(polygon); + return; + } + /* wrap pointers */ + polygon->last_vertex->next = polygon->vertices; + polygon->vertices->previous = polygon->last_vertex; + /* determine the normal */ + if (find_normal(tobj) == GLU_ERROR) + return; + /* compare the normals of previously defined contours and this one */ + /* first contour define ? */ + if (tobj->contours == NULL) { + tobj->A = polygon->A; + tobj->B = polygon->B; + tobj->C = polygon->C; + tobj->D = polygon->D; + /* determine the best projection to use */ + if (fabs(polygon->A) > fabs(polygon->B)) + if (fabs(polygon->A) > fabs(polygon->C)) + tobj->projection = OYZ; + else + tobj->projection = OXY; + else if (fabs(polygon->B) > fabs(polygon->C)) + tobj->projection = OXZ; + else + tobj->projection = OXY; + } + else { + GLdouble a[3], b[3]; + tess_vertex *vertex = polygon->vertices; + + a[0] = tobj->A; + a[1] = tobj->B; + a[2] = tobj->C; + b[0] = polygon->A; + b[1] = polygon->B; + b[2] = polygon->C; + + /* compare the normals */ + if (fabs(a[1] * b[2] - a[2] * b[1]) > EPSILON || + fabs(a[2] * b[0] - a[0] * b[2]) > EPSILON || + fabs(a[0] * b[1] - a[1] * b[0]) > EPSILON) { + /* not coplanar */ + tess_call_user_error(tobj, GLU_TESS_ERROR9); + return; + } + /* the normals are parallel - test for plane equation */ + if (fabs(a[0] * vertex->location[0] + a[1] * vertex->location[1] + + a[2] * vertex->location[2] + tobj->D) > EPSILON) { + /* not the same plane */ + tess_call_user_error(tobj, GLU_TESS_ERROR9); + return; + } + } + prepare_projection_info(tobj); + if (verify_edge_vertex_intersections(tobj) == GLU_ERROR) + return; + if (test_for_overlapping_contours(tobj) == GLU_ERROR) + return; + if (store_polygon_as_contour(tobj) == GLU_ERROR) + return; +} + +static GLenum +test_for_overlapping_contours(GLUtriangulatorObj * tobj) +{ + tess_contour *contour; + tess_polygon *polygon; + + polygon = tobj->current_polygon; + for (contour = tobj->contours; contour != NULL; contour = contour->next) + if (contours_overlap(contour, polygon) != GLU_NO_ERROR) { + tess_call_user_error(tobj, GLU_TESS_ERROR5); + return GLU_ERROR; + } + return GLU_NO_ERROR; +} + +static GLenum +store_polygon_as_contour(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_contour *contour = tobj->contours; + + /* the first contour defined */ + if (contour == NULL) { + if ((contour = (tess_contour *) malloc(sizeof(tess_contour))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + free_current_polygon(polygon); + return GLU_ERROR; + } + tobj->contours = tobj->last_contour = contour; + contour->next = contour->previous = NULL; + } + else { + if ((contour = (tess_contour *) malloc(sizeof(tess_contour))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + free_current_polygon(polygon); + return GLU_ERROR; + } + contour->previous = tobj->last_contour; + tobj->last_contour->next = contour; + tobj->last_contour = contour; + contour->next = NULL; + } + /* mark all vertices in new contour as not special */ + /* and all are boundary edges */ + { + tess_vertex *vertex; + GLuint vertex_cnt, i; + + for (vertex = polygon->vertices, i = 0, vertex_cnt = + polygon->vertex_cnt; i < vertex_cnt; vertex = vertex->next, i++) { + vertex->shadow_vertex = NULL; + vertex->edge_flag = GL_TRUE; + } + } + contour->vertex_cnt = polygon->vertex_cnt; + contour->area = polygon->area; + contour->orientation = polygon->orientation; + contour->type = GLU_UNKNOWN; + contour->vertices = polygon->vertices; + contour->last_vertex = polygon->last_vertex; + polygon->vertices = polygon->last_vertex = NULL; + polygon->vertex_cnt = 0; + ++(tobj->contour_cnt); + return GLU_NO_ERROR; +} + +static void +free_current_polygon(tess_polygon * polygon) +{ + tess_vertex *vertex, *vertex_tmp; + GLuint i; + + /* free current_polygon structures */ + for (vertex = polygon->vertices, i = 0; i < polygon->vertex_cnt; i++) { + vertex_tmp = vertex->next; + free(vertex); + vertex = vertex_tmp; + } + polygon->vertices = polygon->last_vertex = NULL; + polygon->vertex_cnt = 0; +} + +static void +prepare_projection_info(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *vertex, *last_vertex_ptr; + GLdouble area; + + last_vertex_ptr = polygon->last_vertex; + switch (tobj->projection) { + case OXY: + for (vertex = polygon->vertices; vertex != last_vertex_ptr; + vertex = vertex->next) { + vertex->x = vertex->location[0]; + vertex->y = vertex->location[1]; + } + last_vertex_ptr->x = last_vertex_ptr->location[0]; + last_vertex_ptr->y = last_vertex_ptr->location[1]; + break; + case OXZ: + for (vertex = polygon->vertices; vertex != last_vertex_ptr; + vertex = vertex->next) { + vertex->x = vertex->location[0]; + vertex->y = vertex->location[2]; + } + last_vertex_ptr->x = last_vertex_ptr->location[0]; + last_vertex_ptr->y = last_vertex_ptr->location[2]; + break; + case OYZ: + for (vertex = polygon->vertices; vertex != last_vertex_ptr; + vertex = vertex->next) { + vertex->x = vertex->location[1]; + vertex->y = vertex->location[2]; + } + last_vertex_ptr->x = last_vertex_ptr->location[1]; + last_vertex_ptr->y = last_vertex_ptr->location[2]; + break; + } + area = twice_the_polygon_area(polygon->vertices, polygon->last_vertex); + if (area >= 0.0) { + polygon->orientation = GLU_CCW; + polygon->area = area; + } + else { + polygon->orientation = GLU_CW; + polygon->area = -area; + } +} + +static GLdouble +twice_the_polygon_area(tess_vertex * vertex, tess_vertex * last_vertex) +{ + tess_vertex *next; + GLdouble area, x, y; + + area = 0.0; + x = vertex->x; + y = vertex->y; + vertex = vertex->next; + for (; vertex != last_vertex; vertex = vertex->next) { + next = vertex->next; + area += + (vertex->x - x) * (next->y - y) - (vertex->y - y) * (next->x - x); + } + return area; +} + +/* test if edges ab and cd intersect */ +/* if not return GLU_NO_ERROR, else if cross return GLU_TESS_ERROR8, */ +/* else if adjacent return GLU_TESS_ERROR4 */ +static GLenum +edge_edge_intersect(tess_vertex * a, + tess_vertex * b, tess_vertex * c, tess_vertex * d) +{ + GLdouble denom, r, s; + GLdouble xba, ydc, yba, xdc, yac, xac; + + xba = b->x - a->x; + yba = b->y - a->y; + xdc = d->x - c->x; + ydc = d->y - c->y; + xac = a->x - c->x; + yac = a->y - c->y; + denom = xba * ydc - yba * xdc; + r = yac * xdc - xac * ydc; + /* parallel? */ + if (fabs(denom) < EPSILON) { + if (fabs(r) < EPSILON) { + /* colinear */ + if (fabs(xba) < EPSILON) { + /* compare the Y coordinate */ + if (yba > 0.0) { + if ( + (fabs(a->y - c->y) < EPSILON + && fabs(c->y - b->y) < EPSILON) + || (fabs(a->y - d->y) < EPSILON + && fabs(d->y - b->y) < + EPSILON)) return GLU_TESS_ERROR4; + + } + else { + if ( + (fabs(b->y - c->y) < EPSILON + && fabs(c->y - a->y) < EPSILON) + || (fabs(b->y - d->y) < EPSILON + && fabs(d->y - a->y) < + EPSILON)) return GLU_TESS_ERROR4; + } + } + else { + /* compare the X coordinate */ + if (xba > 0.0) { + if ( + (fabs(a->x - c->x) < EPSILON + && fabs(c->x - b->x) < EPSILON) + || (fabs(a->x - d->x) < EPSILON + && fabs(d->x - b->x) < + EPSILON)) return GLU_TESS_ERROR4; + } + else { + if ( + (fabs(b->x - c->x) < EPSILON + && fabs(c->x - a->x) < EPSILON) + || (fabs(b->x - d->x) < EPSILON + && fabs(d->x - a->x) < + EPSILON)) return GLU_TESS_ERROR4; + } + } + } + return GLU_NO_ERROR; + } + r /= denom; + s = (yac * xba - xac * yba) / denom; + /* test if one vertex lies on other edge */ + if (((fabs(r) < EPSILON || (r < 1.0 + EPSILON && r > 1.0 - EPSILON)) && + s > -EPSILON && s < 1.0 + EPSILON) || + ((fabs(s) < EPSILON || (s < 1.0 + EPSILON && s > 1.0 - EPSILON)) && + r > -EPSILON && r < 1.0 + EPSILON)) { + return GLU_TESS_ERROR4; + } + /* test for crossing */ + if (r > -EPSILON && r < 1.0 + EPSILON && s > -EPSILON && s < 1.0 + EPSILON) { + return GLU_TESS_ERROR8; + } + return GLU_NO_ERROR; +} + +static GLenum +verify_edge_vertex_intersections(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *vertex1, *last_vertex, *vertex2; + GLenum test; + + last_vertex = polygon->last_vertex; + vertex1 = last_vertex; + for (vertex2 = vertex1->next->next; + vertex2->next != last_vertex; vertex2 = vertex2->next) { + test = edge_edge_intersect(vertex1, vertex1->next, vertex2, + vertex2->next); + if (test != GLU_NO_ERROR) { + tess_call_user_error(tobj, test); + return GLU_ERROR; + } + } + for (vertex1 = polygon->vertices; + vertex1->next->next != last_vertex; vertex1 = vertex1->next) { + for (vertex2 = vertex1->next->next; + vertex2 != last_vertex; vertex2 = vertex2->next) { + test = edge_edge_intersect(vertex1, vertex1->next, vertex2, + vertex2->next); + if (test != GLU_NO_ERROR) { + tess_call_user_error(tobj, test); + return GLU_ERROR; + } + } + } + return GLU_NO_ERROR; +} + +static int +#ifdef WIN32 + __cdecl +#endif +area_compare(const void *a, const void *b) +{ + GLdouble area1, area2; + + area1 = (*((tess_contour **) a))->area; + area2 = (*((tess_contour **) b))->area; + if (area1 < area2) + return 1; + if (area1 > area2) + return -1; + return 0; +} + +void +tess_find_contour_hierarchies(GLUtriangulatorObj * tobj) +{ + tess_contour **contours; /* dinamic array of pointers */ + tess_contour *tmp_contour_ptr = tobj->contours; + GLuint cnt, i; + GLenum result; + GLboolean hierarchy_changed; + + /* any contours? */ + if (tobj->contour_cnt < 2) { + tobj->contours->type = GLU_EXTERIOR; + return; + } + if ((contours = (tess_contour **) + malloc(sizeof(tess_contour *) * (tobj->contour_cnt))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + for (tmp_contour_ptr = tobj->contours, cnt = 0; + tmp_contour_ptr != NULL; tmp_contour_ptr = tmp_contour_ptr->next) + contours[cnt++] = tmp_contour_ptr; + /* now sort the contours in decreasing area size order */ + qsort((void *) contours, (size_t) cnt, (size_t) sizeof(tess_contour *), + area_compare); + /* we leave just the first contour - remove others from list */ + tobj->contours = contours[0]; + tobj->contours->next = tobj->contours->previous = NULL; + tobj->last_contour = tobj->contours; + tobj->contour_cnt = 1; + /* first contour is the one with greatest area */ + /* must be EXTERIOR */ + tobj->contours->type = GLU_EXTERIOR; + tmp_contour_ptr = tobj->contours; + /* now we play! */ + for (i = 1; i < cnt; i++) { + hierarchy_changed = GL_FALSE; + for (tmp_contour_ptr = tobj->contours; + tmp_contour_ptr != NULL; tmp_contour_ptr = tmp_contour_ptr->next) { + if (tmp_contour_ptr->type == GLU_EXTERIOR) { + /* check if contour completely contained in EXTERIOR */ + result = is_contour_contained_in(tmp_contour_ptr, contours[i]); + switch (result) { + case GLU_INTERIOR: + /* now we have to check if contour is inside interiors */ + /* or not */ + /* any interiors? */ + if (tmp_contour_ptr->next != NULL && + tmp_contour_ptr->next->type == GLU_INTERIOR) { + /* for all interior, check if inside any of them */ + /* if not inside any of interiors, its another */ + /* interior */ + /* or it may contain some interiors, then change */ + /* the contained interiors to exterior ones */ + add_interior_with_hierarchy_check(tobj, + tmp_contour_ptr, + contours[i]); + } + else { + /* not in interior, add as new interior contour */ + add_new_interior(tobj, tmp_contour_ptr, contours[i]); + } + hierarchy_changed = GL_TRUE; + break; + case GLU_EXTERIOR: + /* ooops, the marked as EXTERIOR (contours[i]) is */ + /* actually an interior of tmp_contour_ptr */ + /* reverse the local hierarchy */ + reverse_hierarchy_and_add_exterior(tobj, tmp_contour_ptr, + contours[i]); + hierarchy_changed = GL_TRUE; + break; + case GLU_NO_ERROR: + break; + default: + abort(); + } + } + if (hierarchy_changed) + break; /* break from for loop */ + } + if (hierarchy_changed == GL_FALSE) { + /* disjoint with all contours, add to contour list */ + add_new_exterior(tobj, contours[i]); + } + } + free(contours); +} + +/* returns GLU_INTERIOR if inner is completey enclosed within outer */ +/* returns GLU_EXTERIOR if outer is completely enclosed within inner */ +/* returns GLU_NO_ERROR if contours are disjoint */ +static GLenum +is_contour_contained_in(tess_contour * outer, tess_contour * inner) +{ + GLenum relation_flag; + + /* set relation_flag to relation of containment of first inner vertex */ + /* regarding outer contour */ + if (point_in_polygon(outer, inner->vertices->x, inner->vertices->y)) + relation_flag = GLU_INTERIOR; + else + relation_flag = GLU_EXTERIOR; + if (relation_flag == GLU_INTERIOR) + return GLU_INTERIOR; + if (point_in_polygon(inner, outer->vertices->x, outer->vertices->y)) + return GLU_EXTERIOR; + return GLU_NO_ERROR; +} + +static GLboolean +point_in_polygon(tess_contour * contour, GLdouble x, GLdouble y) +{ + tess_vertex *v1, *v2; + GLuint i, vertex_cnt; + GLdouble xp1, yp1, xp2, yp2; + GLboolean tst; + + tst = GL_FALSE; + v1 = contour->vertices; + v2 = contour->vertices->previous; + for (i = 0, vertex_cnt = contour->vertex_cnt; i < vertex_cnt; i++) { + xp1 = v1->x; + yp1 = v1->y; + xp2 = v2->x; + yp2 = v2->y; + if ((((yp1 <= y) && (y < yp2)) || ((yp2 <= y) && (y < yp1))) && + (x < (xp2 - xp1) * (y - yp1) / (yp2 - yp1) + xp1)) + tst = (tst == GL_FALSE ? GL_TRUE : GL_FALSE); + v2 = v1; + v1 = v1->next; + } + return tst; +} + +static GLenum +contours_overlap(tess_contour * contour, tess_polygon * polygon) +{ + tess_vertex *vertex1, *vertex2; + GLuint vertex1_cnt, vertex2_cnt, i, j; + GLenum test; + + vertex1 = contour->vertices; + vertex2 = polygon->vertices; + vertex1_cnt = contour->vertex_cnt; + vertex2_cnt = polygon->vertex_cnt; + for (i = 0; i < vertex1_cnt; vertex1 = vertex1->next, i++) { + for (j = 0; j < vertex2_cnt; vertex2 = vertex2->next, j++) + if ((test = edge_edge_intersect(vertex1, vertex1->next, vertex2, + vertex2->next)) != GLU_NO_ERROR) + return test; + } + return GLU_NO_ERROR; +} + +static void +add_new_exterior(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + contour->type = GLU_EXTERIOR; + contour->next = NULL; + contour->previous = tobj->last_contour; + tobj->last_contour->next = contour; + tobj->last_contour = contour; +} + +static void +add_new_interior(GLUtriangulatorObj * tobj, + tess_contour * outer, tess_contour * contour) +{ + contour->type = GLU_INTERIOR; + contour->next = outer->next; + contour->previous = outer; + if (outer->next != NULL) + outer->next->previous = contour; + outer->next = contour; + if (tobj->last_contour == outer) + tobj->last_contour = contour; +} + +static void +add_interior_with_hierarchy_check(GLUtriangulatorObj * tobj, + tess_contour * outer, + tess_contour * contour) +{ + tess_contour *ptr; + + /* for all interiors of outer check if they are interior of contour */ + /* if so, change that interior to exterior and move it of of the */ + /* interior sequence */ + if (outer->next != NULL && outer->next->type == GLU_INTERIOR) { + GLenum test; + + for (ptr = outer->next; ptr != NULL && ptr->type == GLU_INTERIOR; + ptr = ptr->next) { + test = is_contour_contained_in(ptr, contour); + switch (test) { + case GLU_INTERIOR: + /* contour is contained in one of the interiors */ + /* check if possibly contained in other exteriors */ + /* move ptr to first EXTERIOR */ + for (; ptr != NULL && ptr->type == GLU_INTERIOR; ptr = ptr->next); + if (ptr == NULL) + /* another exterior */ + add_new_exterior(tobj, contour); + else + add_exterior_with_check(tobj, ptr, contour); + return; + case GLU_EXTERIOR: + /* one of the interiors is contained in the contour */ + /* change it to EXTERIOR, and shift it away from the */ + /* interior sequence */ + shift_interior_to_exterior(tobj, ptr); + break; + case GLU_NO_ERROR: + /* disjoint */ + break; + default: + abort(); + } + } + } + /* add contour to the interior sequence */ + add_new_interior(tobj, outer, contour); +} + +static void +reverse_hierarchy_and_add_exterior(GLUtriangulatorObj * tobj, + tess_contour * outer, + tess_contour * contour) +{ + tess_contour *ptr; + + /* reverse INTERIORS to EXTERIORS */ + /* any INTERIORS? */ + if (outer->next != NULL && outer->next->type == GLU_INTERIOR) + for (ptr = outer->next; ptr != NULL && ptr->type == GLU_INTERIOR; + ptr = ptr->next) ptr->type = GLU_EXTERIOR; + /* the outer now becomes inner */ + outer->type = GLU_INTERIOR; + /* contour is the EXTERIOR */ + contour->next = outer; + if (tobj->contours == outer) { + /* first contour beeing reversed */ + contour->previous = NULL; + tobj->contours = contour; + } + else { + outer->previous->next = contour; + contour->previous = outer->previous; + } + outer->previous = contour; +} + +static void +shift_interior_to_exterior(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + contour->previous->next = contour->next; + if (contour->next != NULL) + contour->next->previous = contour->previous; + else + tobj->last_contour = contour->previous; +} + +static void +add_exterior_with_check(GLUtriangulatorObj * tobj, + tess_contour * outer, tess_contour * contour) +{ + GLenum test; + + /* this contour might be interior to further exteriors - check */ + /* if not, just add as a new exterior */ + for (; outer != NULL && outer->type == GLU_EXTERIOR; outer = outer->next) { + test = is_contour_contained_in(outer, contour); + switch (test) { + case GLU_INTERIOR: + /* now we have to check if contour is inside interiors */ + /* or not */ + /* any interiors? */ + if (outer->next != NULL && outer->next->type == GLU_INTERIOR) { + /* for all interior, check if inside any of them */ + /* if not inside any of interiors, its another */ + /* interior */ + /* or it may contain some interiors, then change */ + /* the contained interiors to exterior ones */ + add_interior_with_hierarchy_check(tobj, outer, contour); + } + else { + /* not in interior, add as new interior contour */ + add_new_interior(tobj, outer, contour); + } + return; + case GLU_NO_ERROR: + /* disjoint */ + break; + default: + abort(); + } + } + /* add contour to the exterior sequence */ + add_new_exterior(tobj, contour); +} + +void +tess_handle_holes(GLUtriangulatorObj * tobj) +{ + tess_contour *contour, *hole; + GLenum exterior_orientation; + + /* verify hole orientation */ + for (contour = tobj->contours; contour != NULL;) { + exterior_orientation = contour->orientation; + for (contour = contour->next; + contour != NULL && contour->type == GLU_INTERIOR; + contour = contour->next) { + if (contour->orientation == exterior_orientation) { + tess_call_user_error(tobj, GLU_TESS_ERROR5); + return; + } + } + } + /* now cut-out holes */ + for (contour = tobj->contours; contour != NULL;) { + hole = contour->next; + while (hole != NULL && hole->type == GLU_INTERIOR) { + if (cut_out_hole(tobj, contour, hole) == GLU_ERROR) + return; + hole = contour->next; + } + contour = contour->next; + } +} + +static GLenum +cut_out_hole(GLUtriangulatorObj * tobj, + tess_contour * contour, tess_contour * hole) +{ + tess_contour *tmp_hole; + tess_vertex *v1, *v2, *tmp_vertex; + GLuint vertex1_cnt, vertex2_cnt, tmp_vertex_cnt; + GLuint i, j, k; + GLenum test = 0; + + /* find an edge connecting contour and hole not intersecting any other */ + /* edge belonging to either the contour or any of the other holes */ + for (v1 = contour->vertices, vertex1_cnt = contour->vertex_cnt, i = 0; + i < vertex1_cnt; i++, v1 = v1->next) { + for (v2 = hole->vertices, vertex2_cnt = hole->vertex_cnt, j = 0; + j < vertex2_cnt; j++, v2 = v2->next) { + /* does edge (v1,v2) intersect any edge of contour */ + for (tmp_vertex = contour->vertices, tmp_vertex_cnt = + contour->vertex_cnt, k = 0; k < tmp_vertex_cnt; + tmp_vertex = tmp_vertex->next, k++) { + /* skip edge tests for edges directly connected */ + if (v1 == tmp_vertex || v1 == tmp_vertex->next) + continue; + test = edge_edge_intersect(v1, v2, tmp_vertex, tmp_vertex->next); + if (test != GLU_NO_ERROR) + break; + } + if (test == GLU_NO_ERROR) { + /* does edge (v1,v2) intersect any edge of hole */ + for (tmp_vertex = hole->vertices, + tmp_vertex_cnt = hole->vertex_cnt, k = 0; + k < tmp_vertex_cnt; tmp_vertex = tmp_vertex->next, k++) { + /* skip edge tests for edges directly connected */ + if (v2 == tmp_vertex || v2 == tmp_vertex->next) + continue; + test = + edge_edge_intersect(v1, v2, tmp_vertex, tmp_vertex->next); + if (test != GLU_NO_ERROR) + break; + } + if (test == GLU_NO_ERROR) { + /* does edge (v1,v2) intersect any other hole? */ + for (tmp_hole = hole->next; + tmp_hole != NULL && tmp_hole->type == GLU_INTERIOR; + tmp_hole = tmp_hole->next) { + /* does edge (v1,v2) intersect any edge of hole */ + for (tmp_vertex = tmp_hole->vertices, + tmp_vertex_cnt = tmp_hole->vertex_cnt, k = 0; + k < tmp_vertex_cnt; tmp_vertex = tmp_vertex->next, k++) { + test = edge_edge_intersect(v1, v2, tmp_vertex, + tmp_vertex->next); + if (test != GLU_NO_ERROR) + break; + } + if (test != GLU_NO_ERROR) + break; + } + } + } + if (test == GLU_NO_ERROR) { + /* edge (v1,v2) is good for eliminating the hole */ + if (merge_hole_with_contour(tobj, contour, hole, v1, v2) + == GLU_NO_ERROR) + return GLU_NO_ERROR; + else + return GLU_ERROR; + } + } + } + /* other holes are blocking all possible connections of hole */ + /* with contour, we shift this hole as the last hole and retry */ + for (tmp_hole = hole; + tmp_hole != NULL && tmp_hole->type == GLU_INTERIOR; + tmp_hole = tmp_hole->next); + contour->next = hole->next; + hole->next->previous = contour; + if (tmp_hole == NULL) { + /* last EXTERIOR contour, shift hole as last contour */ + hole->next = NULL; + hole->previous = tobj->last_contour; + tobj->last_contour->next = hole; + tobj->last_contour = hole; + } + else { + tmp_hole->previous->next = hole; + hole->previous = tmp_hole->previous; + tmp_hole->previous = hole; + hole->next = tmp_hole; + } + hole = contour->next; + /* try once again - recurse */ + return cut_out_hole(tobj, contour, hole); +} + +static GLenum +merge_hole_with_contour(GLUtriangulatorObj * tobj, + tess_contour * contour, + tess_contour * hole, + tess_vertex * v1, tess_vertex * v2) +{ + tess_vertex *v1_new, *v2_new; + + /* make copies of v1 and v2, place them respectively after their originals */ + if ((v1_new = (tess_vertex *) malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + if ((v2_new = (tess_vertex *) malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + v1_new->edge_flag = GL_TRUE; + v1_new->data = v1->data; + v1_new->location[0] = v1->location[0]; + v1_new->location[1] = v1->location[1]; + v1_new->location[2] = v1->location[2]; + v1_new->x = v1->x; + v1_new->y = v1->y; + v1_new->shadow_vertex = v1; + v1->shadow_vertex = v1_new; + v1_new->next = v1->next; + v1_new->previous = v1; + v1->next->previous = v1_new; + v1->next = v1_new; + v2_new->edge_flag = GL_TRUE; + v2_new->data = v2->data; + v2_new->location[0] = v2->location[0]; + v2_new->location[1] = v2->location[1]; + v2_new->location[2] = v2->location[2]; + v2_new->x = v2->x; + v2_new->y = v2->y; + v2_new->shadow_vertex = v2; + v2->shadow_vertex = v2_new; + v2_new->next = v2->next; + v2_new->previous = v2; + v2->next->previous = v2_new; + v2->next = v2_new; + /* link together the two lists */ + v1->next = v2_new; + v2_new->previous = v1; + v2->next = v1_new; + v1_new->previous = v2; + /* update the vertex count of the contour */ + contour->vertex_cnt += hole->vertex_cnt + 2; + /* remove the INTERIOR contour */ + contour->next = hole->next; + if (hole->next != NULL) + hole->next->previous = contour; + free(hole); + /* update tobj structure */ + --(tobj->contour_cnt); + if (contour->last_vertex == v1) + contour->last_vertex = v1_new; + /* mark two vertices with edge_flag */ + v2->edge_flag = GL_FALSE; + v1->edge_flag = GL_FALSE; + return GLU_NO_ERROR; +} --- mesa-7.2.orig/src/glu/mini/gluP.h +++ mesa-7.2/src/glu/mini/gluP.h @@ -0,0 +1,142 @@ +/* $Id: gluP.h,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file allows the GLU code to be compiled either with the Mesa + * headers or with the real OpenGL headers. + */ + + +#ifndef GLUP_H +#define GLUP_H + + +#include +#include +#include + + +#if defined(_WIN32) && !defined(__WIN32__) +# define __WIN32__ +#endif + +#if !defined(OPENSTEP) && (defined(__WIN32__) || defined(__CYGWIN__)) +# pragma warning( disable : 4068 ) /* unknown pragma */ +# pragma warning( disable : 4710 ) /* function 'foo' not inlined */ +# pragma warning( disable : 4711 ) /* function 'foo' selected for automatic inline expansion */ +# pragma warning( disable : 4127 ) /* conditional expression is constant */ +# if defined(MESA_MINWARN) +# pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */ +# pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */ +# pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */ +# pragma warning( disable : 4550 ) /* 'function' undefined; assuming extern returning int */ +# pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */ +# endif +# if defined(_MSC_VER) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */ +# define GLAPI __declspec(dllexport) +# define WGLAPI __declspec(dllexport) +# elif defined(_MSC_VER) && defined(_DLL) /* tag specifying we're building for DLL runtime support */ +# define GLAPI __declspec(dllimport) +# define WGLAPI __declspec(dllimport) +# else /* for use with static link lib build of Win32 edition only */ +# define GLAPI extern +# define WGLAPI __declspec(dllimport) +# endif /* _STATIC_MESA support */ +# define GLAPIENTRY __stdcall +# define GLAPIENTRYP __stdcall * +# define GLCALLBACK __stdcall +# define GLCALLBACKP __stdcall * +# if defined(__CYGWIN__) +# define GLCALLBACKPCAST * +# else +# define GLCALLBACKPCAST __stdcall * +# endif +# define GLWINAPI __stdcall +# define GLWINAPIV __cdecl +#else +/* non-Windows compilation */ +# define GLAPI extern +# define GLAPIENTRY +# define GLAPIENTRYP * +# define GLCALLBACK +# define GLCALLBACKP * +# define GLCALLBACKPCAST * +# define GLWINAPI +# define GLWINAPIV +#endif /* WIN32 / CYGWIN bracket */ + +/* compatibility guard so we don't need to change client code */ + +#if defined(_WIN32) && !defined(_WINDEF_) && !defined(_GNU_H_WINDOWS32_BASE) && !defined(OPENSTEP) +# define CALLBACK GLCALLBACK +typedef int (GLAPIENTRY *PROC)(); +typedef void *HGLRC; +typedef void *HDC; +typedef unsigned long COLORREF; +#endif + +#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) +# define WGL_FONT_LINES 0 +# define WGL_FONT_POLYGONS 1 +#ifndef _GNU_H_WINDOWS32_FUNCTIONS +# ifdef UNICODE +# define wglUseFontBitmaps wglUseFontBitmapsW +# define wglUseFontOutlines wglUseFontOutlinesW +# else +# define wglUseFontBitmaps wglUseFontBitmapsA +# define wglUseFontOutlines wglUseFontOutlinesA +# endif /* !UNICODE */ +#endif /* _GNU_H_WINDOWS32_FUNCTIONS */ +typedef struct tagLAYERPLANEDESCRIPTOR LAYERPLANEDESCRIPTOR, *PLAYERPLANEDESCRIPTOR, *LPLAYERPLANEDESCRIPTOR; +typedef struct _GLYPHMETRICSFLOAT GLYPHMETRICSFLOAT, *PGLYPHMETRICSFLOAT, *LPGLYPHMETRICSFLOAT; +typedef struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESCRIPTOR, *LPPIXELFORMATDESCRIPTOR; +#include +#endif + + + +#ifndef GLU_TESS_ERROR9 + /* If we're using the real OpenGL header files... */ +# define GLU_TESS_ERROR9 100159 +#endif + + +#define GLU_NO_ERROR GL_NO_ERROR + + +/* for Sun: */ +#ifdef SUNOS4 +#define MEMCPY( DST, SRC, BYTES) \ + memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) ) +#else +#define MEMCPY( DST, SRC, BYTES) \ + memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) ) +#endif + + +#ifndef NULL +# define NULL 0 +#endif + + +#endif --- mesa-7.2.orig/src/glu/mini/nurbs.c +++ mesa-7.2/src/glu/mini/nurbs.c @@ -0,0 +1,158 @@ +/* $Id: nurbs.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "gluP.h" +#include "nurbs.h" +#endif + + +void +call_user_error(GLUnurbsObj * nobj, GLenum error) +{ + nobj->error = error; + if (nobj->error_callback != NULL) { + (*(nobj->error_callback)) (error); + } + else { + printf("NURBS error %d %s\n", error, (char *) gluErrorString(error)); + } +} + + + +GLUnurbsObj *GLAPIENTRY +gluNewNurbsRenderer(void) +{ + GLUnurbsObj *n; + GLfloat tmp_viewport[4]; + GLint i, j; + + n = (GLUnurbsObj *) malloc(sizeof(GLUnurbsObj)); + return n; +} + + + +void GLAPIENTRY +gluDeleteNurbsRenderer(GLUnurbsObj * nobj) +{ + if (nobj) { + free(nobj); + } +} + + + +void GLAPIENTRY +gluLoadSamplingMatrices(GLUnurbsObj * nobj, + const GLfloat modelMatrix[16], + const GLfloat projMatrix[16], const GLint viewport[4]) +{ +} + + +void GLAPIENTRY +gluNurbsProperty(GLUnurbsObj * nobj, GLenum property, GLfloat value) +{ +} + + +void GLAPIENTRY +gluGetNurbsProperty(GLUnurbsObj * nobj, GLenum property, GLfloat * value) +{ +} + + + +void GLAPIENTRY +gluBeginCurve(GLUnurbsObj * nobj) +{ +} + + +void GLAPIENTRY +gluEndCurve(GLUnurbsObj * nobj) +{ +} + + +void GLAPIENTRY +gluNurbsCurve(GLUnurbsObj * nobj, GLint nknots, GLfloat * knot, + GLint stride, GLfloat * ctlarray, GLint order, GLenum type) +{ +} + + +void GLAPIENTRY +gluBeginSurface(GLUnurbsObj * nobj) +{ +} + + +void GLAPIENTRY +gluEndSurface(GLUnurbsObj * nobj) +{ +} + + +void GLAPIENTRY +gluNurbsSurface(GLUnurbsObj * nobj, + GLint sknot_count, GLfloat * sknot, + GLint tknot_count, GLfloat * tknot, + GLint s_stride, GLint t_stride, + GLfloat * ctrlarray, GLint sorder, GLint torder, GLenum type) +{ +} + + +void GLAPIENTRY +gluNurbsCallback(GLUnurbsObj * nobj, GLenum which, void (GLCALLBACK * fn) ()) +{ +} + +void GLAPIENTRY +gluBeginTrim(GLUnurbsObj * nobj) +{ +} + +void GLAPIENTRY +gluPwlCurve(GLUnurbsObj * nobj, GLint count, GLfloat * array, GLint stride, + GLenum type) +{ +} + +void GLAPIENTRY +gluEndTrim(GLUnurbsObj * nobj) +{ +} --- mesa-7.2.orig/src/glu/mini/nurbs.h +++ mesa-7.2/src/glu/mini/nurbs.h @@ -0,0 +1,253 @@ +/* $Id: nurbs.h,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifndef NURBS_H +#define NURBS_H + + +#define EPSILON 1e-06 /* epsilon for double precision compares */ + +typedef enum +{ + GLU_NURBS_CURVE, GLU_NURBS_SURFACE, GLU_NURBS_TRIM, GLU_NURBS_NO_TRIM, + GLU_NURBS_TRIM_DONE, GLU_NURBS_NONE +} +GLU_nurbs_enum; + +typedef enum +{ + GLU_TRIM_NURBS, GLU_TRIM_PWL +} +GLU_trim_enum; + +typedef struct +{ + GLint sknot_count; + GLfloat *sknot; + GLint tknot_count; + GLfloat *tknot; + GLint s_stride; + GLint t_stride; + GLfloat *ctrlarray; + GLint sorder; + GLint torder; + GLint dim; + GLenum type; +} +surface_attribs; + +typedef struct +{ + surface_attribs geom; + surface_attribs color; + surface_attribs texture; + surface_attribs normal; +} +nurbs_surface; + +typedef struct +{ + GLint knot_count; + GLfloat *knot; + GLint stride; + GLfloat *ctrlarray; + GLint order; + GLint dim; + GLenum type; +} +curve_attribs; + +typedef struct +{ + GLint pt_count; + GLfloat *ctrlarray; + GLint stride; + GLint dim; + GLenum type; +} +pwl_curve_attribs; + +typedef struct +{ + curve_attribs geom; + curve_attribs color; + curve_attribs texture; + curve_attribs normal; +} +nurbs_curve; + +typedef struct trim_list_str +{ + GLU_trim_enum trim_type; + union + { + pwl_curve_attribs pwl_curve; + curve_attribs nurbs_curve; + } + curve; + struct trim_list_str *next; +} +trim_list; + +typedef struct seg_trim_str +{ + GLfloat *points; + GLint pt_cnt, seg_array_len; + struct seg_trim_str *next; +} +trim_segments; + +typedef struct nurbs_trim_str +{ + trim_list *trim_loop; + trim_segments *segments; + struct nurbs_trim_str *next; +} +nurbs_trim; + +typedef struct +{ + GLfloat model[16], proj[16], viewport[4]; +} +culling_and_sampling_str; + +struct GLUnurbs +{ + GLboolean culling; + GLenum error; + void (GLCALLBACK * error_callback) (GLenum err); + GLenum display_mode; + GLU_nurbs_enum nurbs_type; + GLboolean auto_load_matrix; + culling_and_sampling_str sampling_matrices; + GLenum sampling_method; + GLfloat sampling_tolerance; + GLfloat parametric_tolerance; + GLint u_step, v_step; + nurbs_surface surface; + nurbs_curve curve; + nurbs_trim *trim; +}; + +typedef struct +{ + GLfloat *knot; + GLint nknots; + GLfloat *unified_knot; + GLint unified_nknots; + GLint order; + GLint t_min, t_max; + GLint delta_nknots; + GLboolean open_at_begin, open_at_end; + GLfloat *new_knot; + GLfloat *alpha; +} +knot_str_type; + +typedef struct +{ + GLfloat *geom_ctrl; + GLint geom_s_stride, geom_t_stride; + GLfloat **geom_offsets; + GLint geom_s_pt_cnt, geom_t_pt_cnt; + GLfloat *color_ctrl; + GLint color_s_stride, color_t_stride; + GLfloat **color_offsets; + GLint color_s_pt_cnt, color_t_pt_cnt; + GLfloat *normal_ctrl; + GLint normal_s_stride, normal_t_stride; + GLfloat **normal_offsets; + GLint normal_s_pt_cnt, normal_t_pt_cnt; + GLfloat *texture_ctrl; + GLint texture_s_stride, texture_t_stride; + GLfloat **texture_offsets; + GLint texture_s_pt_cnt, texture_t_pt_cnt; + GLint s_bezier_cnt, t_bezier_cnt; +} +new_ctrl_type; + +extern void call_user_error(GLUnurbsObj * nobj, GLenum error); + +extern GLenum test_knot(GLint nknots, GLfloat * knot, GLint order); + +extern GLenum explode_knot(knot_str_type * the_knot); + +extern GLenum calc_alphas(knot_str_type * the_knot); + +extern GLenum calc_new_ctrl_pts(GLfloat * ctrl, GLint stride, + knot_str_type * the_knot, GLint dim, + GLfloat ** new_ctrl, GLint * ncontrol); + +extern GLenum glu_do_sampling_crv(GLUnurbsObj * nobj, GLfloat * new_ctrl, + GLint n_ctrl, GLint order, GLint dim, + GLint ** factors); + +extern GLenum glu_do_sampling_3D(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + int **sfactors, GLint ** tfactors); + +extern GLenum glu_do_sampling_uv(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + int **sfactors, GLint ** tfactors); + +extern GLenum glu_do_sampling_param_3D(GLUnurbsObj * nobj, + new_ctrl_type * new_ctrl, + int **sfactors, GLint ** tfactors); + +extern GLboolean fine_culling_test_2D(GLUnurbsObj * nobj, GLfloat * ctrl, + GLint n_ctrl, GLint stride, GLint dim); + +extern GLboolean fine_culling_test_3D(GLUnurbsObj * nobj, GLfloat * ctrl, + GLint s_n_ctrl, GLint t_n_ctrl, + GLint s_stride, GLint t_stride, + GLint dim); + +extern void do_nurbs_curve(GLUnurbsObj * nobj); + +extern void do_nurbs_surface(GLUnurbsObj * nobj); + +extern GLenum patch_trimming(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + GLint * sfactors, GLint * tfactors); + +extern void collect_unified_knot(knot_str_type * dest, knot_str_type * src, + GLfloat maximal_min_knot, + GLfloat minimal_max_knot); + +extern GLenum select_knot_working_range(GLUnurbsObj * nobj, + knot_str_type * geom_knot, + knot_str_type * color_knot, + knot_str_type * normal_knot, + knot_str_type * texture_knot); + +extern void free_unified_knots(knot_str_type * geom_knot, + knot_str_type * color_knot, + knot_str_type * normal_knot, + knot_str_type * texture_knot); + + + +#endif --- mesa-7.2.orig/src/glu/mini/glu.c +++ mesa-7.2/src/glu/mini/glu.c @@ -0,0 +1,417 @@ +/* $Id: glu.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * Copyright (C) 1995-2001 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include +#include +#include "gluP.h" +#endif + + +/* + * Miscellaneous utility functions + */ + + +#ifndef M_PI +#define M_PI 3.1415926536 +#endif +#define EPS 0.00001 + +#ifndef GLU_INCOMPATIBLE_GL_VERSION +#define GLU_INCOMPATIBLE_GL_VERSION 100903 +#endif + + +void GLAPIENTRY +gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, + GLdouble centerx, GLdouble centery, GLdouble centerz, + GLdouble upx, GLdouble upy, GLdouble upz) +{ + GLfloat m[16]; + GLfloat x[3], y[3], z[3]; + GLfloat mag; + + /* Make rotation matrix */ + + /* Z vector */ + z[0] = eyex - centerx; + z[1] = eyey - centery; + z[2] = eyez - centerz; + mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]); + if (mag) { /* mpichler, 19950515 */ + z[0] /= mag; + z[1] /= mag; + z[2] /= mag; + } + + /* Y vector */ + y[0] = upx; + y[1] = upy; + y[2] = upz; + + /* X vector = Y cross Z */ + x[0] = y[1] * z[2] - y[2] * z[1]; + x[1] = -y[0] * z[2] + y[2] * z[0]; + x[2] = y[0] * z[1] - y[1] * z[0]; + + /* Recompute Y = Z cross X */ + y[0] = z[1] * x[2] - z[2] * x[1]; + y[1] = -z[0] * x[2] + z[2] * x[0]; + y[2] = z[0] * x[1] - z[1] * x[0]; + + /* mpichler, 19950515 */ + /* cross product gives area of parallelogram, which is < 1.0 for + * non-perpendicular unit-length vectors; so normalize x, y here + */ + + mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); + if (mag) { + x[0] /= mag; + x[1] /= mag; + x[2] /= mag; + } + + mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]); + if (mag) { + y[0] /= mag; + y[1] /= mag; + y[2] /= mag; + } + +#define M(row,col) m[col*4+row] + M(0, 0) = x[0]; + M(0, 1) = x[1]; + M(0, 2) = x[2]; + M(0, 3) = 0.0; + M(1, 0) = y[0]; + M(1, 1) = y[1]; + M(1, 2) = y[2]; + M(1, 3) = 0.0; + M(2, 0) = z[0]; + M(2, 1) = z[1]; + M(2, 2) = z[2]; + M(2, 3) = 0.0; + M(3, 0) = 0.0; + M(3, 1) = 0.0; + M(3, 2) = 0.0; + M(3, 3) = 1.0; +#undef M + glMultMatrixf(m); + + /* Translate Eye to Origin */ + glTranslatef(-eyex, -eyey, -eyez); + +} + + + +void GLAPIENTRY +gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) +{ + glOrtho(left, right, bottom, top, -1.0, 1.0); +} + + + +static void +frustum(GLfloat left, GLfloat right, + GLfloat bottom, GLfloat top, + GLfloat nearval, GLfloat farval) +{ + GLfloat x, y, a, b, c, d; + GLfloat m[16]; + + x = (2.0 * nearval) / (right - left); + y = (2.0 * nearval) / (top - bottom); + a = (right + left) / (right - left); + b = (top + bottom) / (top - bottom); + c = -(farval + nearval) / ( farval - nearval); + d = -(2.0 * farval * nearval) / (farval - nearval); + +#define M(row,col) m[col*4+row] + M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F; + M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F; + M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d; + M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F; +#undef M + + glMultMatrixf(m); +} + + +void GLAPIENTRY +gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) +{ + GLfloat xmin, xmax, ymin, ymax; + + ymax = zNear * tan(fovy * M_PI / 360.0); + ymin = -ymax; + xmin = ymin * aspect; + xmax = ymax * aspect; + + /* don't call glFrustum() because of error semantics (covglu) */ + frustum(xmin, xmax, ymin, ymax, zNear, zFar); +} + + + +void GLAPIENTRY +gluPickMatrix(GLdouble x, GLdouble y, + GLdouble width, GLdouble height, GLint viewport[4]) +{ + GLfloat m[16]; + GLfloat sx, sy; + GLfloat tx, ty; + + sx = viewport[2] / width; + sy = viewport[3] / height; + tx = (viewport[2] + 2.0 * (viewport[0] - x)) / width; + ty = (viewport[3] + 2.0 * (viewport[1] - y)) / height; + +#define M(row,col) m[col*4+row] + M(0, 0) = sx; + M(0, 1) = 0.0; + M(0, 2) = 0.0; + M(0, 3) = tx; + M(1, 0) = 0.0; + M(1, 1) = sy; + M(1, 2) = 0.0; + M(1, 3) = ty; + M(2, 0) = 0.0; + M(2, 1) = 0.0; + M(2, 2) = 1.0; + M(2, 3) = 0.0; + M(3, 0) = 0.0; + M(3, 1) = 0.0; + M(3, 2) = 0.0; + M(3, 3) = 1.0; +#undef M + + glMultMatrixf(m); +} + + + +const GLubyte *GLAPIENTRY +gluErrorString(GLenum errorCode) +{ + static char *tess_error[] = { + "missing gluBeginPolygon", + "missing gluBeginContour", + "missing gluEndPolygon", + "missing gluEndContour", + "misoriented or self-intersecting loops", + "coincident vertices", + "colinear vertices", + "FIST recovery process fatal error" + }; + static char *nurbs_error[] = { + "spline order un-supported", + "too few knots", + "valid knot range is empty", + "decreasing knot sequence knot", + "knot multiplicity greater than order of spline", + "endcurve() must follow bgncurve()", + "bgncurve() must precede endcurve()", + "missing or extra geometric data", + "can't draw pwlcurves", + "missing bgncurve()", + "missing bgnsurface()", + "endtrim() must precede endsurface()", + "bgnsurface() must precede endsurface()", + "curve of improper type passed as trim curve", + "bgnsurface() must precede bgntrim()", + "endtrim() must follow bgntrim()", + "bgntrim() must precede endtrim()", + "invalid or missing trim curve", + "bgntrim() must precede pwlcurve()", + "pwlcurve referenced twice", + "pwlcurve and nurbscurve mixed", + "improper usage of trim data type", + "nurbscurve referenced twice", + "nurbscurve and pwlcurve mixed", + "nurbssurface referenced twice", + "invalid property", + "endsurface() must follow bgnsurface()", + "misoriented trim curves", + "intersecting trim curves", + "UNUSED", + "unconnected trim curves", + "unknown knot error", + "negative vertex count encountered", + "negative byte-stride encountered", + "unknown type descriptor", + "null control array or knot vector", + "duplicate point on pwlcurve" + }; + + /* GL Errors */ + if (errorCode == GL_NO_ERROR) { + return (GLubyte *) "no error"; + } + else if (errorCode == GL_INVALID_VALUE) { + return (GLubyte *) "invalid value"; + } + else if (errorCode == GL_INVALID_ENUM) { + return (GLubyte *) "invalid enum"; + } + else if (errorCode == GL_INVALID_OPERATION) { + return (GLubyte *) "invalid operation"; + } + else if (errorCode == GL_STACK_OVERFLOW) { + return (GLubyte *) "stack overflow"; + } + else if (errorCode == GL_STACK_UNDERFLOW) { + return (GLubyte *) "stack underflow"; + } + else if (errorCode == GL_OUT_OF_MEMORY) { + return (GLubyte *) "out of memory"; + } + /* GLU Errors */ + else if (errorCode == GLU_NO_ERROR) { + return (GLubyte *) "no error"; + } + else if (errorCode == GLU_INVALID_ENUM) { + return (GLubyte *) "invalid enum"; + } + else if (errorCode == GLU_INVALID_VALUE) { + return (GLubyte *) "invalid value"; + } + else if (errorCode == GLU_OUT_OF_MEMORY) { + return (GLubyte *) "out of memory"; + } + else if (errorCode == GLU_INCOMPATIBLE_GL_VERSION) { + return (GLubyte *) "incompatible GL version"; + } + else if (errorCode >= GLU_TESS_ERROR1 && errorCode <= GLU_TESS_ERROR8) { + return (GLubyte *) tess_error[errorCode - GLU_TESS_ERROR1]; + } + else if (errorCode >= GLU_NURBS_ERROR1 && errorCode <= GLU_NURBS_ERROR37) { + return (GLubyte *) nurbs_error[errorCode - GLU_NURBS_ERROR1]; + } + else { + return NULL; + } +} + + + +/* + * New in GLU 1.1 + */ + +const GLubyte *GLAPIENTRY +gluGetString(GLenum name) +{ + static char *extensions = "GL_EXT_abgr"; + static char *version = "1.1 Mesa 3.5"; + + switch (name) { + case GLU_EXTENSIONS: + return (GLubyte *) extensions; + case GLU_VERSION: + return (GLubyte *) version; + default: + return NULL; + } +} + + + +#if 0 /* gluGetProcAddressEXT not finalized yet! */ + +#ifdef __cplusplus + /* for BeOS R4.5 */ +void GLAPIENTRY(*gluGetProcAddressEXT(const GLubyte * procName)) (...) +#else +void (GLAPIENTRY * gluGetProcAddressEXT(const GLubyte * procName)) () +#endif +{ + struct proc + { + const char *name; + void *address; + }; + static struct proc procTable[] = { + {"gluGetProcAddressEXT", (void *) gluGetProcAddressEXT}, /* me! */ + + /* new 1.1 functions */ + {"gluGetString", (void *) gluGetString}, + + /* new 1.2 functions */ + {"gluTessBeginPolygon", (void *) gluTessBeginPolygon}, + {"gluTessBeginContour", (void *) gluTessBeginContour}, + {"gluTessEndContour", (void *) gluTessEndContour}, + {"gluTessEndPolygon", (void *) gluTessEndPolygon}, + {"gluGetTessProperty", (void *) gluGetTessProperty}, + + /* new 1.3 functions */ + + {NULL, NULL} + }; + GLuint i; + + for (i = 0; procTable[i].address; i++) { + if (strcmp((const char *) procName, procTable[i].name) == 0) + return (void (GLAPIENTRY *) ()) procTable[i].address; + } + + return NULL; +} + +#endif + + + +/* + * New in GLU 1.3 + */ +#ifdef GLU_VERSION_1_3 +GLboolean GLAPIENTRY +gluCheckExtension(const GLubyte *extName, const GLubyte * extString) +{ + assert(extName); + assert(extString); + { + const int len = strlen((const char *) extName); + const char *start = (const char *) extString; + + while (1) { + const char *c = strstr(start, (const char *) extName); + if (!c) + return GL_FALSE; + + if ((c == start || c[-1] == ' ') && (c[len] == ' ' || c[len] == 0)) + return GL_TRUE; + + start = c + len; + } + } +} +#endif --- mesa-7.2.orig/src/glu/mini/tess.c +++ mesa-7.2/src/glu/mini/tess.c @@ -0,0 +1,328 @@ +/* $Id: tess.c,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "tess.h" +#endif + + +/* + * This is ugly, but seems the easiest way to do things to make the + * code work under YellowBox for Windows + */ +#if defined(OPENSTEP) && defined(CALLBACK) +#undef CALLBACK +#define CALLBACK +#endif + + +static void delete_contours(GLUtriangulatorObj *); + +#ifdef __CYGWIN32__ +#define _CALLBACK +#else +#define _CALLBACK GLCALLBACK +#endif + + +static void +init_callbacks(tess_callbacks * callbacks) +{ + callbacks->begin = (void (_CALLBACK *) (GLenum)) 0; + callbacks->edgeFlag = (void (_CALLBACK *) (GLboolean)) 0; + callbacks->vertex = (void (_CALLBACK *) (void *)) 0; + callbacks->end = (void (_CALLBACK *) (void)) 0; + callbacks->error = (void (_CALLBACK *) (GLenum)) 0; +} + +void +tess_call_user_error(GLUtriangulatorObj * tobj, GLenum gluerr) +{ + if (tobj->error == GLU_NO_ERROR) + tobj->error = gluerr; + if (tobj->callbacks.error != NULL) + (tobj->callbacks.error) (gluerr); +} + +GLUtriangulatorObj *GLAPIENTRY +gluNewTess(void) +{ + GLUtriangulatorObj *tobj; + + if ((tobj = (GLUtriangulatorObj *) + malloc(sizeof(struct GLUtesselator))) == NULL) + return NULL; + tobj->contours = tobj->last_contour = NULL; + init_callbacks(&tobj->callbacks); + tobj->error = GLU_NO_ERROR; + tobj->current_polygon = NULL; + tobj->contour_cnt = 0; + return tobj; +} + + +void GLAPIENTRY +gluTessCallback(GLUtriangulatorObj * tobj, GLenum which, + void (GLCALLBACK * fn) ()) +{ + switch (which) { + case GLU_BEGIN: + tobj->callbacks.begin = (void (_CALLBACK *) (GLenum)) fn; + break; + case GLU_EDGE_FLAG: + tobj->callbacks.edgeFlag = (void (_CALLBACK *) (GLboolean)) fn; + break; + case GLU_VERTEX: + tobj->callbacks.vertex = (void (_CALLBACK *) (void *)) fn; + break; + case GLU_END: + tobj->callbacks.end = (void (_CALLBACK *) (void)) fn; + break; + case GLU_ERROR: + tobj->callbacks.error = (void (_CALLBACK *) (GLenum)) fn; + break; + default: + tobj->error = GLU_INVALID_ENUM; + break; + } +} + + + +void GLAPIENTRY +gluDeleteTess(GLUtriangulatorObj * tobj) +{ + if (tobj->error == GLU_NO_ERROR && tobj->contour_cnt) + /* was gluEndPolygon called? */ + tess_call_user_error(tobj, GLU_TESS_ERROR1); + /* delete all internal structures */ + delete_contours(tobj); + free(tobj); +} + + +void GLAPIENTRY +gluBeginPolygon(GLUtriangulatorObj * tobj) +{ +/* + if(tobj->error!=GLU_NO_ERROR) + return; +*/ + tobj->error = GLU_NO_ERROR; + if (tobj->current_polygon != NULL) { + /* gluEndPolygon was not called */ + tess_call_user_error(tobj, GLU_TESS_ERROR1); + /* delete all internal structures */ + delete_contours(tobj); + } + else { + if ((tobj->current_polygon = + (tess_polygon *) malloc(sizeof(tess_polygon))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + tobj->current_polygon->vertex_cnt = 0; + tobj->current_polygon->vertices = + tobj->current_polygon->last_vertex = NULL; + } +} + + +void GLAPIENTRY +gluEndPolygon(GLUtriangulatorObj * tobj) +{ + /*tess_contour *contour_ptr; */ + + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + /* check if gluBeginPolygon was called */ + if (tobj->current_polygon == NULL) { + tess_call_user_error(tobj, GLU_TESS_ERROR2); + return; + } + tess_test_polygon(tobj); + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + /* any real contours? */ + if (tobj->contour_cnt == 0) { + /* delete all internal structures */ + delete_contours(tobj); + return; + } + tess_find_contour_hierarchies(tobj); + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + tess_handle_holes(tobj); + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + /* if no callbacks, nothing to do */ + if (tobj->callbacks.begin != NULL && tobj->callbacks.vertex != NULL && + tobj->callbacks.end != NULL) { + if (tobj->callbacks.edgeFlag == NULL) + tess_tesselate(tobj); + else + tess_tesselate_with_edge_flag(tobj); + } + + end: + /* delete all internal structures */ + delete_contours(tobj); +} + + +void GLAPIENTRY +gluNextContour(GLUtriangulatorObj * tobj, GLenum type) +{ + if (tobj->error != GLU_NO_ERROR) + return; + if (tobj->current_polygon == NULL) { + tess_call_user_error(tobj, GLU_TESS_ERROR2); + return; + } + /* first contour? */ + if (tobj->current_polygon->vertex_cnt) + tess_test_polygon(tobj); +} + + +void GLAPIENTRY +gluTessVertex(GLUtriangulatorObj * tobj, GLdouble v[3], void *data) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *last_vertex_ptr; + + if (tobj->error != GLU_NO_ERROR) + return; + if (polygon == NULL) { + tess_call_user_error(tobj, GLU_TESS_ERROR2); + return; + } + last_vertex_ptr = polygon->last_vertex; + if (last_vertex_ptr == NULL) { + if ((last_vertex_ptr = (tess_vertex *) + malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + polygon->vertices = last_vertex_ptr; + polygon->last_vertex = last_vertex_ptr; + last_vertex_ptr->data = data; + last_vertex_ptr->location[0] = v[0]; + last_vertex_ptr->location[1] = v[1]; + last_vertex_ptr->location[2] = v[2]; + last_vertex_ptr->next = NULL; + last_vertex_ptr->previous = NULL; + ++(polygon->vertex_cnt); + } + else { + tess_vertex *vertex_ptr; + + /* same point twice? */ + if (fabs(last_vertex_ptr->location[0] - v[0]) < EPSILON && + fabs(last_vertex_ptr->location[1] - v[1]) < EPSILON && + fabs(last_vertex_ptr->location[2] - v[2]) < EPSILON) { + tess_call_user_error(tobj, GLU_TESS_ERROR6); + return; + } + if ((vertex_ptr = (tess_vertex *) + malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + vertex_ptr->data = data; + vertex_ptr->location[0] = v[0]; + vertex_ptr->location[1] = v[1]; + vertex_ptr->location[2] = v[2]; + vertex_ptr->next = NULL; + vertex_ptr->previous = last_vertex_ptr; + ++(polygon->vertex_cnt); + last_vertex_ptr->next = vertex_ptr; + polygon->last_vertex = vertex_ptr; + } +} + + +static void +delete_contours(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_contour *contour, *contour_tmp; + tess_vertex *vertex, *vertex_tmp; + + /* remove current_polygon list - if exists due to detected error */ + if (polygon != NULL) { + if (polygon->vertices) { + for (vertex = polygon->vertices; vertex != polygon->last_vertex;) { + vertex_tmp = vertex->next; + free(vertex); + vertex = vertex_tmp; + } + free(vertex); + } + free(polygon); + tobj->current_polygon = NULL; + } + /* remove all contour data */ + for (contour = tobj->contours; contour != NULL;) { + for (vertex = contour->vertices; vertex != contour->last_vertex;) { + vertex_tmp = vertex->next; + free(vertex); + vertex = vertex_tmp; + } + free(vertex); + contour_tmp = contour->next; + free(contour); + contour = contour_tmp; + } + tobj->contours = tobj->last_contour = NULL; + tobj->contour_cnt = 0; +} + + +void GLAPIENTRY +gluTessNormal(GLUtesselator *tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ) +{ + /* dummy function */ + (void) tess; + (void) valueX; + (void) valueY; + (void) valueZ; +} --- mesa-7.2.orig/src/glu/mini/tess.h +++ mesa-7.2/src/glu/mini/tess.h @@ -0,0 +1,108 @@ +/* $Id: tess.h,v 1.2 2003/08/22 20:11:43 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifndef TESS_H +#define TESS_H + + +#include "gluP.h" + +#define EPSILON 1e-06 /* epsilon for double precision compares */ + +typedef enum +{ + OXY, + OYZ, + OXZ +} +projection_type; + +typedef struct callbacks_str +{ + void (GLCALLBACK * begin) (GLenum mode); + void (GLCALLBACK * edgeFlag) (GLboolean flag); + void (GLCALLBACK * vertex) (GLvoid * v); + void (GLCALLBACK * end) (void); + void (GLCALLBACK * error) (GLenum err); +} +tess_callbacks; + +typedef struct vertex_str +{ + void *data; + GLdouble location[3]; + GLdouble x, y; + GLboolean edge_flag; + struct vertex_str *shadow_vertex; + struct vertex_str *next, *previous; +} +tess_vertex; + +typedef struct contour_str +{ + GLenum type; + GLuint vertex_cnt; + GLdouble area; + GLenum orientation; + struct vertex_str *vertices, *last_vertex; + struct contour_str *next, *previous; +} +tess_contour; + +typedef struct polygon_str +{ + GLuint vertex_cnt; + GLdouble A, B, C, D; + GLdouble area; + GLenum orientation; + struct vertex_str *vertices, *last_vertex; +} +tess_polygon; + +struct GLUtesselator +{ + tess_contour *contours, *last_contour; + GLuint contour_cnt; + tess_callbacks callbacks; + tess_polygon *current_polygon; + GLenum error; + GLdouble A, B, C, D; + projection_type projection; +}; + + +extern void tess_call_user_error(GLUtriangulatorObj *, GLenum); +extern void tess_test_polygon(GLUtriangulatorObj *); +extern void tess_find_contour_hierarchies(GLUtriangulatorObj *); +extern void tess_handle_holes(GLUtriangulatorObj *); +extern void tess_tesselate(GLUtriangulatorObj *); +extern void tess_tesselate_with_edge_flag(GLUtriangulatorObj *); + + +#endif --- mesa-7.2.orig/src/glu/mesa/MesaGLU.def +++ mesa-7.2/src/glu/mesa/MesaGLU.def @@ -0,0 +1,62 @@ +LIBRARY GLU32 +DESCRIPTION 'GLU for Windows Mesa' +EXETYPE WINDOWS +CODE MOVEABLE DISCARDABLE +DATA MOVEABLE SINGLE +HEAPSIZE 256000 + +STACKSIZE 4096 + +EXPORTS + gluLookAt + gluOrtho2D + gluPerspective + gluPickMatrix + gluProject + gluUnProject + gluErrorString + gluScaleImage + gluBuild1DMipmaps + gluBuild2DMipmaps + gluNewQuadric + gluDeleteQuadric + gluQuadricDrawStyle + gluQuadricOrientation + gluQuadricNormals + gluQuadricTexture + gluQuadricCallback + gluCylinder + gluSphere + gluDisk + gluPartialDisk + gluNewNurbsRenderer + gluDeleteNurbsRenderer + gluLoadSamplingMatrices + gluNurbsProperty + gluGetNurbsProperty + gluBeginCurve + gluEndCurve + gluNurbsCurve + gluBeginSurface + gluEndSurface + gluNurbsSurface + gluBeginTrim + gluEndTrim + gluPwlCurve + gluNurbsCallback + gluNewTess + gluDeleteTess +; gluTessBeginPolygon +; gluTessBeginContour + gluTessVertex +; gluTessEndContour +; gluTessEndPolygon +; gluTessProperty +; gluTessNormal + gluTessCallback +; gluGetTessProperty + gluBeginPolygon + gluNextContour + gluEndPolygon + gluGetString + --- mesa-7.2.orig/src/glu/mesa/Makefile +++ mesa-7.2/src/glu/mesa/Makefile @@ -0,0 +1,56 @@ +# src/glu/mesa/Makefile + +TOP = ../../.. + +include $(TOP)/configs/current + +GLU_MAJOR = 1 +GLU_MINOR = 1 +GLU_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) + +C_SOURCES = \ + glu.c \ + mipmap.c \ + nurbs.c \ + nurbscrv.c \ + nurbssrf.c \ + nurbsutl.c \ + polytest.c \ + project.c \ + quadric.c \ + tess.c \ + tesselat.c + +OBJECTS = $(C_SOURCES:.c=.o) + +INCLUDES = -I. -I$(TOP)/include + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $< -o $@ + +##### TARGETS ##### + +default: + @if [ "${CONFIG_NAME}" = "beos" ] ; then \ + echo "$(GLU_LIB_NAME) not build under BeOS, but integrated into ${GL_LIB_NAME}." ; \ + exit 0 ; \ + else \ + $(MAKE) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) || exit 1 ; \ + fi + +$(TOP)/$(LIB_DIR): + -mkdir $(TOP)/$(LIB_DIR) + +# Make the library: +$(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME): $(OBJECTS) + @ $(MKLIB) -o $(GLU_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major $(GLU_MAJOR) -minor $(GLU_MINOR) -patch $(GLU_TINY) \ + $(MKLIB_OPTIONS) -install $(TOP)/$(LIB_DIR) \ + $(GLU_LIB_DEPS) $(OBJECTS) + +clean: + -rm -f *.o */*.o */*/*.o + -rm -f *.lo */*.lo */*/*.lo + -rm -f *.la */*.la */*/*.la --- mesa-7.2.orig/src/glu/mesa/mms_depend +++ mesa-7.2/src/glu/mesa/mms_depend @@ -0,0 +1,15 @@ +# DO NOT DELETE THIS LINE -- make depend depends on it. + +glu.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h +mipmap.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h +nurbs.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h nurbs.h +nurbscrv.obj : nurbs.h gluP.h [-.include.gl]gl.h [-.include.gl]glu.h +nurbssrf.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h nurbs.h +nurbsutl.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h nurbs.h +project.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h +quadric.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h +tess.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h tess.h +tess_fist.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h tess.h +tess_hash.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h tess.h +tess_heap.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h tess.h +tess_clip.obj : gluP.h [-.include.gl]gl.h [-.include.gl]glu.h tess.h --- mesa-7.2.orig/src/glu/mesa/quadric.c +++ mesa-7.2/src/glu/mesa/quadric.c @@ -0,0 +1,819 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1999-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* TODO: + * texture coordinate support + * flip normals according to orientation + * there's still some inside/outside orientation bugs in possibly all + * but the sphere function + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include "gluP.h" +#endif + + + +#ifndef M_PI +# define M_PI (3.1415926) +#endif + + +/* + * Convert degrees to radians: + */ +#define DEG_TO_RAD(A) ((A)*(M_PI/180.0)) + + +/* + * Sin and Cos for degree angles: + */ +#define SIND( A ) sin( (A)*(M_PI/180.0) ) +#define COSD( A) cos( (A)*(M_PI/180.0) ) + + +/* + * Texture coordinates if texture flag is set + */ +#define TXTR_COORD(x,y) if (qobj->TextureFlag) glTexCoord2f(x,y); + + + +struct GLUquadric +{ + GLenum DrawStyle; /* GLU_FILL, LINE, SILHOUETTE, or POINT */ + GLenum Orientation; /* GLU_INSIDE or GLU_OUTSIDE */ + GLboolean TextureFlag; /* Generate texture coords? */ + GLenum Normals; /* GLU_NONE, GLU_FLAT, or GLU_SMOOTH */ + void (GLCALLBACK * ErrorFunc) (GLenum err); /* Error handler callback function */ +}; + + + +/* + * Process a GLU error. + */ +static void +quadric_error(GLUquadricObj * qobj, GLenum error, const char *msg) +{ + /* Call the error call back function if any */ + if (qobj->ErrorFunc) { + (*qobj->ErrorFunc) (error); + } + /* Print a message to stdout if MESA_DEBUG variable is defined */ + if (getenv("MESA_DEBUG")) { + fprintf(stderr, "GLUError: %s: %s\n", (char *) gluErrorString(error), + msg); + } +} + + + + +GLUquadricObj *GLAPIENTRY +gluNewQuadric(void) +{ + GLUquadricObj *q; + + q = (GLUquadricObj *) malloc(sizeof(struct GLUquadric)); + if (q) { + q->DrawStyle = GLU_FILL; + q->Orientation = GLU_OUTSIDE; + q->TextureFlag = GL_FALSE; + q->Normals = GLU_SMOOTH; + q->ErrorFunc = NULL; + } + return q; +} + + + +void GLAPIENTRY +gluDeleteQuadric(GLUquadricObj * state) +{ + if (state) { + free((void *) state); + } +} + + + +/* + * Set the drawing style to be GLU_FILL, GLU_LINE, GLU_SILHOUETTE, + * or GLU_POINT. + */ +void GLAPIENTRY +gluQuadricDrawStyle(GLUquadricObj * quadObject, GLenum drawStyle) +{ + if (quadObject && (drawStyle == GLU_FILL || drawStyle == GLU_LINE + || drawStyle == GLU_SILHOUETTE + || drawStyle == GLU_POINT)) { + quadObject->DrawStyle = drawStyle; + } + else { + quadric_error(quadObject, GLU_INVALID_ENUM, "qluQuadricDrawStyle"); + } +} + + + +/* + * Set the orientation to GLU_INSIDE or GLU_OUTSIDE. + */ +void GLAPIENTRY +gluQuadricOrientation(GLUquadricObj * quadObject, GLenum orientation) +{ + if (quadObject + && (orientation == GLU_INSIDE || orientation == GLU_OUTSIDE)) { + quadObject->Orientation = orientation; + } + else { + quadric_error(quadObject, GLU_INVALID_ENUM, "qluQuadricOrientation"); + } +} + + + +/* + * Set the error handler callback function. + */ +void GLAPIENTRY +gluQuadricCallback(GLUquadricObj * qobj, + GLenum which, void (GLCALLBACK * fn) ()) +{ + /* + * UGH, this is a mess! I thought ANSI was a standard. + */ + if (qobj && which == GLU_ERROR) { +#ifdef __CYGWIN32__ + qobj->ErrorFunc = (void (GLCALLBACKPCAST) (GLenum)) fn; +#elif defined(OPENSTEP) + qobj->ErrorFunc = (void (*)(GLenum)) fn; +#elif defined(_WIN32) + qobj->ErrorFunc = (void (GLCALLBACK *) (int)) fn; +#elif defined(__STORM__) + qobj->ErrorFunc = (void (GLCALLBACK *) (GLenum)) fn; +#elif defined(__BEOS__) + qobj->ErrorFunc = (void (*)(GLenum)) fn; +#else + qobj->ErrorFunc = (void (GLCALLBACK *) ()) fn; +#endif + } +} + + +void GLAPIENTRY +gluQuadricNormals(GLUquadricObj * quadObject, GLenum normals) +{ + if (quadObject + && (normals == GLU_NONE || normals == GLU_FLAT + || normals == GLU_SMOOTH)) { + quadObject->Normals = normals; + } +} + + +void GLAPIENTRY +gluQuadricTexture(GLUquadricObj * quadObject, GLboolean textureCoords) +{ + if (quadObject) { + quadObject->TextureFlag = textureCoords; + } +} + + + + +/* + * Call glNormal3f after scaling normal to unit length. + */ +static void +normal3f(GLfloat x, GLfloat y, GLfloat z) +{ + GLdouble mag; + + mag = sqrt(x * x + y * y + z * z); + if (mag > 0.00001F) { + x /= mag; + y /= mag; + z /= mag; + } + glNormal3f(x, y, z); +} + + + +void GLAPIENTRY +gluCylinder(GLUquadricObj * qobj, + GLdouble baseRadius, GLdouble topRadius, + GLdouble height, GLint slices, GLint stacks) +{ + GLdouble da, r, dr, dz; + GLfloat x, y, z, nz, nsign; + GLint i, j; + + if (qobj->Orientation == GLU_INSIDE) { + nsign = -1.0; + } + else { + nsign = 1.0; + } + + da = 2.0 * M_PI / slices; + dr = (topRadius - baseRadius) / stacks; + dz = height / stacks; + nz = (baseRadius - topRadius) / height; /* Z component of normal vectors */ + + if (qobj->DrawStyle == GLU_POINT) { + glBegin(GL_POINTS); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + + z = 0.0; + r = baseRadius; + for (j = 0; j <= stacks; j++) { + glVertex3f(x * r, y * r, z); + z += dz; + r += dr; + } + } + glEnd(); + } + else if (qobj->DrawStyle == GLU_LINE || qobj->DrawStyle == GLU_SILHOUETTE) { + /* Draw rings */ + if (qobj->DrawStyle == GLU_LINE) { + z = 0.0; + r = baseRadius; + for (j = 0; j <= stacks; j++) { + glBegin(GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * r, y * r, z); + } + glEnd(); + z += dz; + r += dr; + } + } + else { + /* draw one ring at each end */ + if (baseRadius != 0.0) { + glBegin(GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * baseRadius, y * baseRadius, 0.0); + } + glEnd(); + glBegin(GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * topRadius, y * topRadius, height); + } + glEnd(); + } + } + /* draw length lines */ + glBegin(GL_LINES); + for (i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + normal3f(x * nsign, y * nsign, nz * nsign); + glVertex3f(x * baseRadius, y * baseRadius, 0.0); + glVertex3f(x * topRadius, y * topRadius, height); + } + glEnd(); + } + else if (qobj->DrawStyle == GLU_FILL) { + GLfloat ds = 1.0 / slices; + GLfloat dt = 1.0 / stacks; + GLfloat t = 0.0; + z = 0.0; + r = baseRadius; + for (j = 0; j < stacks; j++) { + GLfloat s = 0.0; + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + GLfloat x, y; + if (i == slices) { + x = sin(0.0); + y = cos(0.0); + } + else { + x = sin(i * da); + y = cos(i * da); + } + if (nsign == 1.0) { + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t); + glVertex3f(x * r, y * r, z); + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t + dt); + glVertex3f(x * (r + dr), y * (r + dr), z + dz); + } + else { + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t); + glVertex3f(x * r, y * r, z); + normal3f(x * nsign, y * nsign, nz * nsign); + TXTR_COORD(s, t + dt); + glVertex3f(x * (r + dr), y * (r + dr), z + dz); + } + s += ds; + } /* for slices */ + glEnd(); + r += dr; + t += dt; + z += dz; + } /* for stacks */ + } +} + + + + + +void GLAPIENTRY +gluSphere(GLUquadricObj * qobj, GLdouble radius, GLint slices, GLint stacks) +{ + GLfloat rho, drho, theta, dtheta; + GLfloat x, y, z; + GLfloat s, t, ds, dt; + GLint i, j, imin, imax; + GLboolean normals; + GLfloat nsign; + + if (qobj->Normals == GLU_NONE) { + normals = GL_FALSE; + } + else { + normals = GL_TRUE; + } + if (qobj->Orientation == GLU_INSIDE) { + nsign = -1.0; + } + else { + nsign = 1.0; + } + + drho = M_PI / (GLfloat) stacks; + dtheta = 2.0 * M_PI / (GLfloat) slices; + + /* texturing: s goes from 0.0/0.25/0.5/0.75/1.0 at +y/+x/-y/-x/+y axis */ + /* t goes from -1.0/+1.0 at z = -radius/+radius (linear along longitudes) */ + /* cannot use triangle fan on texturing (s coord. at top/bottom tip varies) */ + + if (qobj->DrawStyle == GLU_FILL) { + if (!qobj->TextureFlag) { + /* draw +Z end as a triangle fan */ + glBegin(GL_TRIANGLE_FAN); + glNormal3f(0.0, 0.0, 1.0); + glVertex3f(0.0, 0.0, nsign * radius); + for (j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(drho); + y = cos(theta) * sin(drho); + z = nsign * cos(drho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + + ds = 1.0 / slices; + dt = 1.0 / stacks; + t = 1.0; /* because loop now runs from 0 */ + if (qobj->TextureFlag) { + imin = 0; + imax = stacks; + } + else { + imin = 1; + imax = stacks - 1; + } + + /* draw intermediate stacks as quad strips */ + for (i = imin; i < imax; i++) { + rho = i * drho; + glBegin(GL_QUAD_STRIP); + s = 0.0; + for (j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + TXTR_COORD(s, t); + glVertex3f(x * radius, y * radius, z * radius); + x = -sin(theta) * sin(rho + drho); + y = cos(theta) * sin(rho + drho); + z = nsign * cos(rho + drho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + TXTR_COORD(s, t - dt); + s += ds; + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + t -= dt; + } + + if (!qobj->TextureFlag) { + /* draw -Z end as a triangle fan */ + glBegin(GL_TRIANGLE_FAN); + glNormal3f(0.0, 0.0, -1.0); + glVertex3f(0.0, 0.0, -radius * nsign); + rho = M_PI - drho; + s = 1.0; + t = dt; + for (j = slices; j >= 0; j--) { + theta = (j == slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + s -= ds; + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + } + else if (qobj->DrawStyle == GLU_LINE || qobj->DrawStyle == GLU_SILHOUETTE) { + /* draw stack lines */ + for (i = 1; i < stacks; i++) { /* stack line at i==stacks-1 was missing here */ + rho = i * drho; + glBegin(GL_LINE_LOOP); + for (j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + /* draw slice lines */ + for (j = 0; j < slices; j++) { + theta = j * dtheta; + glBegin(GL_LINE_STRIP); + for (i = 0; i <= stacks; i++) { + rho = i * drho; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + glVertex3f(x * radius, y * radius, z * radius); + } + glEnd(); + } + } + else if (qobj->DrawStyle == GLU_POINT) { + /* top and bottom-most points */ + glBegin(GL_POINTS); + if (normals) + glNormal3f(0.0, 0.0, nsign); + glVertex3d(0.0, 0.0, radius); + if (normals) + glNormal3f(0.0, 0.0, -nsign); + glVertex3d(0.0, 0.0, -radius); + + /* loop over stacks */ + for (i = 1; i < stacks - 1; i++) { + rho = i * drho; + for (j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) + glNormal3f(x * nsign, y * nsign, z * nsign); + glVertex3f(x * radius, y * radius, z * radius); + } + } + glEnd(); + } + +} + + + +void GLAPIENTRY +gluDisk(GLUquadricObj * qobj, + GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops) +{ + GLfloat da, dr; +#if 0 + GLdouble a, da; + GLfloat r, dr; + GLfloat x, y; + GLfloat r1, r2, dtc; + GLint s, l; +#endif + + /* Normal vectors */ + if (qobj->Normals != GLU_NONE) { + if (qobj->Orientation == GLU_OUTSIDE) { + glNormal3f(0.0, 0.0, +1.0); + } + else { + glNormal3f(0.0, 0.0, -1.0); + } + } + + da = 2.0 * M_PI / slices; + dr = (outerRadius - innerRadius) / (GLfloat) loops; + + switch (qobj->DrawStyle) { + case GLU_FILL: + { + /* texture of a gluDisk is a cut out of the texture unit square + * x, y in [-outerRadius, +outerRadius]; s, t in [0, 1] + * (linear mapping) + */ + GLfloat dtc = 2.0f * outerRadius; + GLfloat sa, ca; + GLfloat r1 = innerRadius; + GLint l; + for (l = 0; l < loops; l++) { + GLfloat r2 = r1 + dr; + if (qobj->Orientation == GLU_OUTSIDE) { + GLint s; + glBegin(GL_QUAD_STRIP); + for (s = 0; s <= slices; s++) { + GLfloat a; + if (s == slices) + a = 0.0; + else + a = s * da; + sa = sin(a); + ca = cos(a); + TXTR_COORD(0.5 + sa * r2 / dtc, 0.5 + ca * r2 / dtc); + glVertex2f(r2 * sa, r2 * ca); + TXTR_COORD(0.5 + sa * r1 / dtc, 0.5 + ca * r1 / dtc); + glVertex2f(r1 * sa, r1 * ca); + } + glEnd(); + } + else { + GLint s; + glBegin(GL_QUAD_STRIP); + for (s = slices; s >= 0; s--) { + GLfloat a; + if (s == slices) + a = 0.0; + else + a = s * da; + sa = sin(a); + ca = cos(a); + TXTR_COORD(0.5 - sa * r2 / dtc, 0.5 + ca * r2 / dtc); + glVertex2f(r2 * sa, r2 * ca); + TXTR_COORD(0.5 - sa * r1 / dtc, 0.5 + ca * r1 / dtc); + glVertex2f(r1 * sa, r1 * ca); + } + glEnd(); + } + r1 = r2; + } + break; + } + case GLU_LINE: + { + GLint l, s; + /* draw loops */ + for (l = 0; l <= loops; l++) { + GLfloat r = innerRadius + l * dr; + glBegin(GL_LINE_LOOP); + for (s = 0; s < slices; s++) { + GLfloat a = s * da; + glVertex2f(r * sin(a), r * cos(a)); + } + glEnd(); + } + /* draw spokes */ + for (s = 0; s < slices; s++) { + GLfloat a = s * da; + GLfloat x = sin(a); + GLfloat y = cos(a); + glBegin(GL_LINE_STRIP); + for (l = 0; l <= loops; l++) { + GLfloat r = innerRadius + l * dr; + glVertex2f(r * x, r * y); + } + glEnd(); + } + break; + } + case GLU_POINT: + { + GLint s; + glBegin(GL_POINTS); + for (s = 0; s < slices; s++) { + GLfloat a = s * da; + GLfloat x = sin(a); + GLfloat y = cos(a); + GLint l; + for (l = 0; l <= loops; l++) { + GLfloat r = innerRadius * l * dr; + glVertex2f(r * x, r * y); + } + } + glEnd(); + break; + } + case GLU_SILHOUETTE: + { + if (innerRadius != 0.0) { + GLfloat a; + glBegin(GL_LINE_LOOP); + for (a = 0.0; a < 2.0 * M_PI; a += da) { + GLfloat x = innerRadius * sin(a); + GLfloat y = innerRadius * cos(a); + glVertex2f(x, y); + } + glEnd(); + } + { + GLfloat a; + glBegin(GL_LINE_LOOP); + for (a = 0; a < 2.0 * M_PI; a += da) { + GLfloat x = outerRadius * sin(a); + GLfloat y = outerRadius * cos(a); + glVertex2f(x, y); + } + glEnd(); + } + break; + } + default: + abort(); + } +} + + + +void GLAPIENTRY +gluPartialDisk(GLUquadricObj * qobj, GLdouble innerRadius, + GLdouble outerRadius, GLint slices, GLint loops, + GLdouble startAngle, GLdouble sweepAngle) +{ + if (qobj->Normals != GLU_NONE) { + if (qobj->Orientation == GLU_OUTSIDE) { + glNormal3f(0.0, 0.0, +1.0); + } + else { + glNormal3f(0.0, 0.0, -1.0); + } + } + + if (qobj->DrawStyle == GLU_POINT) { + GLint loop, slice; + GLdouble radius, delta_radius; + GLdouble angle, delta_angle; + delta_radius = (outerRadius - innerRadius) / (loops - 1); + delta_angle = DEG_TO_RAD((sweepAngle) / (slices - 1)); + glBegin(GL_POINTS); + radius = innerRadius; + for (loop = 0; loop < loops; loop++) { + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice < slices; slice++) { + glVertex2d(radius * sin(angle), radius * cos(angle)); + angle += delta_angle; + } + radius += delta_radius; + } + glEnd(); + } + else if (qobj->DrawStyle == GLU_LINE) { + GLint loop, slice; + GLdouble radius, delta_radius; + GLdouble angle, delta_angle; + delta_radius = (outerRadius - innerRadius) / loops; + delta_angle = DEG_TO_RAD(sweepAngle / slices); + /* draw rings */ + radius = innerRadius; + for (loop = 0; loop < loops; loop++) { + angle = DEG_TO_RAD(startAngle); + glBegin(GL_LINE_STRIP); + for (slice = 0; slice <= slices; slice++) { + glVertex2d(radius * sin(angle), radius * cos(angle)); + angle += delta_angle; + } + glEnd(); + radius += delta_radius; + } + /* draw spokes */ + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice <= slices; slice++) { + radius = innerRadius; + glBegin(GL_LINE_STRIP); + for (loop = 0; loop < loops; loop++) { + glVertex2d(radius * sin(angle), radius * cos(angle)); + radius += delta_radius; + } + glEnd(); + angle += delta_angle; + } + } + else if (qobj->DrawStyle == GLU_SILHOUETTE) { + GLint slice; + GLdouble angle, delta_angle; + delta_angle = DEG_TO_RAD(sweepAngle / slices); + /* draw outer ring */ + glBegin(GL_LINE_STRIP); + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice <= slices; slice++) { + glVertex2d(outerRadius * sin(angle), outerRadius * cos(angle)); + angle += delta_angle; + } + glEnd(); + /* draw inner ring */ + if (innerRadius > 0.0) { + glBegin(GL_LINE_STRIP); + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice < slices; slice++) { + glVertex2d(innerRadius * sin(angle), innerRadius * cos(angle)); + angle += delta_angle; + } + glEnd(); + } + /* draw spokes */ + if (sweepAngle < 360.0) { + GLdouble stopAngle = startAngle + sweepAngle; + glBegin(GL_LINES); + glVertex2d(innerRadius * SIND(startAngle), + innerRadius * COSD(startAngle)); + glVertex2d(outerRadius * SIND(startAngle), + outerRadius * COSD(startAngle)); + glVertex2d(innerRadius * SIND(stopAngle), + innerRadius * COSD(stopAngle)); + glVertex2d(outerRadius * SIND(stopAngle), + outerRadius * COSD(stopAngle)); + glEnd(); + } + } + else if (qobj->DrawStyle == GLU_FILL) { + GLint loop, slice; + GLdouble radius, delta_radius; + GLdouble angle, delta_angle; + delta_radius = (outerRadius - innerRadius) / loops; + delta_angle = DEG_TO_RAD(sweepAngle / slices); + radius = innerRadius; + for (loop = 0; loop < loops; loop++) { + glBegin(GL_QUAD_STRIP); + angle = DEG_TO_RAD(startAngle); + for (slice = 0; slice <= slices; slice++) { + if (qobj->Orientation == GLU_OUTSIDE) { + glVertex2d((radius + delta_radius) * sin(angle), + (radius + delta_radius) * cos(angle)); + glVertex2d(radius * sin(angle), radius * cos(angle)); + } + else { + glVertex2d(radius * sin(angle), radius * cos(angle)); + glVertex2d((radius + delta_radius) * sin(angle), + (radius + delta_radius) * cos(angle)); + } + angle += delta_angle; + } + glEnd(); + radius += delta_radius; + } + } +} --- mesa-7.2.orig/src/glu/mesa/all.h +++ mesa-7.2/src/glu/mesa/all.h @@ -0,0 +1,54 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file includes all .h files needed for the GLU source code for + * the purpose of precompiled headers. + * + * If the preprocessor symbol PCH is defined at compile time then each + * of the .c files will #include "all.h" only, instead of a bunch of + * individual .h files. + */ + + +#ifndef GLU_ALL_H +#define GLU_ALL_H + + +#ifndef PC_HEADER +This is an error. all.h should be included only if PCH is defined. +#endif + + +#include +#include +#include +#include +#include +#include "GL/gl.h" +#include "GL/glu.h" +#include "gluP.h" +#include "nurbs.h" +#include "tess.h" + + +#endif /*GLU_ALL_H */ --- mesa-7.2.orig/src/glu/mesa/mipmap.c +++ mesa-7.2/src/glu/mesa/mipmap.c @@ -0,0 +1,824 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include +#include "gluP.h" +#endif + + +/* + * Compute ceiling of integer quotient of A divided by B: + */ +#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 ) + + + +#ifdef EPSILON +#undef EPSILON +#endif +#define EPSILON 0.001 + + +/* To work around optimizer bug in MSVC4.1 */ +#if defined(__WIN32__) && !defined(OPENSTEP) +void +dummy(GLuint j, GLuint k) +{ +} +#else +#define dummy(J, K) +#endif + + +GLint GLAPIENTRY +gluScaleImage(GLenum format, + GLsizei widthin, GLsizei heightin, + GLenum typein, const void *datain, + GLsizei widthout, GLsizei heightout, + GLenum typeout, void *dataout) +{ + GLint components, i, j, k; + GLfloat *tempin, *tempout; + GLfloat sx, sy; + GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels; + GLint packrowlength, packalignment, packskiprows, packskippixels; + GLint sizein, sizeout; + GLint rowstride, rowlen; + + + /* Determine number of components per pixel */ + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + components = 1; + break; + case GL_LUMINANCE_ALPHA: + components = 2; + break; + case GL_RGB: + case GL_BGR: + components = 3; + break; + case GL_RGBA: + case GL_BGRA: +#ifdef GL_EXT_abgr + case GL_ABGR_EXT: +#endif + components = 4; + break; + default: + return GLU_INVALID_ENUM; + } + + /* Determine bytes per input datum */ + switch (typein) { + case GL_UNSIGNED_BYTE: + sizein = sizeof(GLubyte); + break; + case GL_BYTE: + sizein = sizeof(GLbyte); + break; + case GL_UNSIGNED_SHORT: + sizein = sizeof(GLushort); + break; + case GL_SHORT: + sizein = sizeof(GLshort); + break; + case GL_UNSIGNED_INT: + sizein = sizeof(GLuint); + break; + case GL_INT: + sizein = sizeof(GLint); + break; + case GL_FLOAT: + sizein = sizeof(GLfloat); + break; + case GL_BITMAP: + /* not implemented yet */ + default: + return GL_INVALID_ENUM; + } + + /* Determine bytes per output datum */ + switch (typeout) { + case GL_UNSIGNED_BYTE: + sizeout = sizeof(GLubyte); + break; + case GL_BYTE: + sizeout = sizeof(GLbyte); + break; + case GL_UNSIGNED_SHORT: + sizeout = sizeof(GLushort); + break; + case GL_SHORT: + sizeout = sizeof(GLshort); + break; + case GL_UNSIGNED_INT: + sizeout = sizeof(GLuint); + break; + case GL_INT: + sizeout = sizeof(GLint); + break; + case GL_FLOAT: + sizeout = sizeof(GLfloat); + break; + case GL_BITMAP: + /* not implemented yet */ + default: + return GL_INVALID_ENUM; + } + + /* Get glPixelStore state */ + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpackrowlength); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpackalignment); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &unpackskiprows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &unpackskippixels); + glGetIntegerv(GL_PACK_ROW_LENGTH, &packrowlength); + glGetIntegerv(GL_PACK_ALIGNMENT, &packalignment); + glGetIntegerv(GL_PACK_SKIP_ROWS, &packskiprows); + glGetIntegerv(GL_PACK_SKIP_PIXELS, &packskippixels); + + /* Allocate storage for intermediate images */ + tempin = (GLfloat *) malloc(widthin * heightin + * components * sizeof(GLfloat)); + if (!tempin) { + return GLU_OUT_OF_MEMORY; + } + tempout = (GLfloat *) malloc(widthout * heightout + * components * sizeof(GLfloat)); + if (!tempout) { + free(tempin); + return GLU_OUT_OF_MEMORY; + } + + + /* + * Unpack the pixel data and convert to floating point + */ + + if (unpackrowlength > 0) { + rowlen = unpackrowlength; + } + else { + rowlen = widthin; + } + if (sizein >= unpackalignment) { + rowstride = components * rowlen; + } + else { + rowstride = unpackalignment / sizein + * CEILING(components * rowlen * sizein, unpackalignment); + } + + switch (typein) { + case GL_UNSIGNED_BYTE: + k = 0; + for (i = 0; i < heightin; i++) { + GLubyte *ubptr = (GLubyte *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * ubptr++; + } + } + break; + case GL_BYTE: + k = 0; + for (i = 0; i < heightin; i++) { + GLbyte *bptr = (GLbyte *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * bptr++; + } + } + break; + case GL_UNSIGNED_SHORT: + k = 0; + for (i = 0; i < heightin; i++) { + GLushort *usptr = (GLushort *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * usptr++; + } + } + break; + case GL_SHORT: + k = 0; + for (i = 0; i < heightin; i++) { + GLshort *sptr = (GLshort *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * sptr++; + } + } + break; + case GL_UNSIGNED_INT: + k = 0; + for (i = 0; i < heightin; i++) { + GLuint *uiptr = (GLuint *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * uiptr++; + } + } + break; + case GL_INT: + k = 0; + for (i = 0; i < heightin; i++) { + GLint *iptr = (GLint *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = (GLfloat) * iptr++; + } + } + break; + case GL_FLOAT: + k = 0; + for (i = 0; i < heightin; i++) { + GLfloat *fptr = (GLfloat *) datain + + i * rowstride + + unpackskiprows * rowstride + unpackskippixels * components; + for (j = 0; j < widthin * components; j++) { + dummy(j, k); + tempin[k++] = *fptr++; + } + } + break; + default: + return GLU_INVALID_ENUM; + } + + + /* + * Scale the image! + */ + + if (widthout > 1) + sx = (GLfloat) (widthin - 1) / (GLfloat) (widthout - 1); + else + sx = (GLfloat) (widthin - 1); + if (heightout > 1) + sy = (GLfloat) (heightin - 1) / (GLfloat) (heightout - 1); + else + sy = (GLfloat) (heightin - 1); + +/*#define POINT_SAMPLE*/ +#ifdef POINT_SAMPLE + for (i = 0; i < heightout; i++) { + GLint ii = i * sy; + for (j = 0; j < widthout; j++) { + GLint jj = j * sx; + + GLfloat *src = tempin + (ii * widthin + jj) * components; + GLfloat *dst = tempout + (i * widthout + j) * components; + + for (k = 0; k < components; k++) { + *dst++ = *src++; + } + } + } +#else + if (sx < 1.0 && sy < 1.0) { + /* magnify both width and height: use weighted sample of 4 pixels */ + GLint i0, i1, j0, j1; + GLfloat alpha, beta; + GLfloat *src00, *src01, *src10, *src11; + GLfloat s1, s2; + GLfloat *dst; + + for (i = 0; i < heightout; i++) { + i0 = i * sy; + i1 = i0 + 1; + if (i1 >= heightin) + i1 = heightin - 1; +/* i1 = (i+1) * sy - EPSILON;*/ + alpha = i * sy - i0; + for (j = 0; j < widthout; j++) { + j0 = j * sx; + j1 = j0 + 1; + if (j1 >= widthin) + j1 = widthin - 1; +/* j1 = (j+1) * sx - EPSILON; */ + beta = j * sx - j0; + + /* compute weighted average of pixels in rect (i0,j0)-(i1,j1) */ + src00 = tempin + (i0 * widthin + j0) * components; + src01 = tempin + (i0 * widthin + j1) * components; + src10 = tempin + (i1 * widthin + j0) * components; + src11 = tempin + (i1 * widthin + j1) * components; + + dst = tempout + (i * widthout + j) * components; + + for (k = 0; k < components; k++) { + s1 = *src00++ * (1.0 - beta) + *src01++ * beta; + s2 = *src10++ * (1.0 - beta) + *src11++ * beta; + *dst++ = s1 * (1.0 - alpha) + s2 * alpha; + } + } + } + } + else { + /* shrink width and/or height: use an unweighted box filter */ + GLint i0, i1; + GLint j0, j1; + GLint ii, jj; + GLfloat sum, *dst; + + for (i = 0; i < heightout; i++) { + i0 = i * sy; + i1 = i0 + 1; + if (i1 >= heightin) + i1 = heightin - 1; +/* i1 = (i+1) * sy - EPSILON; */ + for (j = 0; j < widthout; j++) { + j0 = j * sx; + j1 = j0 + 1; + if (j1 >= widthin) + j1 = widthin - 1; +/* j1 = (j+1) * sx - EPSILON; */ + + dst = tempout + (i * widthout + j) * components; + + /* compute average of pixels in the rectangle (i0,j0)-(i1,j1) */ + for (k = 0; k < components; k++) { + sum = 0.0; + for (ii = i0; ii <= i1; ii++) { + for (jj = j0; jj <= j1; jj++) { + sum += *(tempin + (ii * widthin + jj) * components + k); + } + } + sum /= (j1 - j0 + 1) * (i1 - i0 + 1); + *dst++ = sum; + } + } + } + } +#endif + + + /* + * Return output image + */ + + if (packrowlength > 0) { + rowlen = packrowlength; + } + else { + rowlen = widthout; + } + if (sizeout >= packalignment) { + rowstride = components * rowlen; + } + else { + rowstride = packalignment / sizeout + * CEILING(components * rowlen * sizeout, packalignment); + } + + switch (typeout) { + case GL_UNSIGNED_BYTE: + k = 0; + for (i = 0; i < heightout; i++) { + GLubyte *ubptr = (GLubyte *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *ubptr++ = (GLubyte) tempout[k++]; + } + } + break; + case GL_BYTE: + k = 0; + for (i = 0; i < heightout; i++) { + GLbyte *bptr = (GLbyte *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *bptr++ = (GLbyte) tempout[k++]; + } + } + break; + case GL_UNSIGNED_SHORT: + k = 0; + for (i = 0; i < heightout; i++) { + GLushort *usptr = (GLushort *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *usptr++ = (GLushort) tempout[k++]; + } + } + break; + case GL_SHORT: + k = 0; + for (i = 0; i < heightout; i++) { + GLshort *sptr = (GLshort *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *sptr++ = (GLshort) tempout[k++]; + } + } + break; + case GL_UNSIGNED_INT: + k = 0; + for (i = 0; i < heightout; i++) { + GLuint *uiptr = (GLuint *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *uiptr++ = (GLuint) tempout[k++]; + } + } + break; + case GL_INT: + k = 0; + for (i = 0; i < heightout; i++) { + GLint *iptr = (GLint *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *iptr++ = (GLint) tempout[k++]; + } + } + break; + case GL_FLOAT: + k = 0; + for (i = 0; i < heightout; i++) { + GLfloat *fptr = (GLfloat *) dataout + + i * rowstride + + packskiprows * rowstride + packskippixels * components; + for (j = 0; j < widthout * components; j++) { + dummy(j, k + i); + *fptr++ = tempout[k++]; + } + } + break; + default: + return GLU_INVALID_ENUM; + } + + + /* free temporary image storage */ + free(tempin); + free(tempout); + + return 0; +} + + + +/* + * Return the largest k such that 2^k <= n. + */ +static GLint +ilog2(GLint n) +{ + GLint k; + + if (n <= 0) + return 0; + for (k = 0; n >>= 1; k++); + return k; +} + + + +/* + * Find the value nearest to n which is also a power of two. + */ +static GLint +round2(GLint n) +{ + GLint m; + + for (m = 1; m < n; m *= 2); + + /* m>=n */ + if (m - n <= n - m / 2) { + return m; + } + else { + return m / 2; + } +} + + +/* + * Given an pixel format and datatype, return the number of bytes to + * store one pixel. + */ +static GLint +bytes_per_pixel(GLenum format, GLenum type) +{ + GLint n, m; + + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + n = 1; + break; + case GL_LUMINANCE_ALPHA: + n = 2; + break; + case GL_RGB: + case GL_BGR: + n = 3; + break; + case GL_RGBA: + case GL_BGRA: +#ifdef GL_EXT_abgr + case GL_ABGR_EXT: +#endif + n = 4; + break; + default: + n = 0; + } + + switch (type) { + case GL_UNSIGNED_BYTE: + m = sizeof(GLubyte); + break; + case GL_BYTE: + m = sizeof(GLbyte); + break; + case GL_BITMAP: + m = 1; + break; + case GL_UNSIGNED_SHORT: + m = sizeof(GLushort); + break; + case GL_SHORT: + m = sizeof(GLshort); + break; + case GL_UNSIGNED_INT: + m = sizeof(GLuint); + break; + case GL_INT: + m = sizeof(GLint); + break; + case GL_FLOAT: + m = sizeof(GLfloat); + break; + default: + m = 0; + } + + return n * m; +} + + + +/* + * WARNING: This function isn't finished and has never been tested!!!! + */ +GLint GLAPIENTRY +gluBuild1DMipmaps(GLenum target, GLint components, + GLsizei width, GLenum format, GLenum type, const void *data) +{ + GLubyte *texture; + GLint levels, max_levels; + GLint new_width, max_width; + GLint i, j, k, l; + + if (width < 1) + return GLU_INVALID_VALUE; + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_width); + max_levels = ilog2(max_width) + 1; + + /* Compute how many mipmap images to make */ + levels = ilog2(width) + 1; + if (levels > max_levels) { + levels = max_levels; + } + + new_width = 1 << (levels - 1); + + texture = (GLubyte *) malloc(new_width * components); + if (!texture) { + return GLU_OUT_OF_MEMORY; + } + + if (width != new_width) { + /* initial rescaling */ + switch (type) { + case GL_UNSIGNED_BYTE: + { + GLubyte *ub_data = (GLubyte *) data; + for (i = 0; i < new_width; i++) { + j = i * width / new_width; + for (k = 0; k < components; k++) { + texture[i * components + k] = ub_data[j * components + k]; + } + } + } + break; + default: + /* Not implemented */ + return GLU_ERROR; + } + } + + /* generate and load mipmap images */ + for (l = 0; l < levels; l++) { + glTexImage1D(GL_TEXTURE_1D, l, components, new_width, 0, + format, GL_UNSIGNED_BYTE, texture); + + /* Scale image down to 1/2 size */ + new_width = new_width / 2; + for (i = 0; i < new_width; i++) { + for (k = 0; k < components; k++) { + GLint sample1, sample2; + sample1 = (GLint) texture[i * 2 * components + k]; + sample2 = (GLint) texture[(i * 2 + 1) * components + k]; + texture[i * components + k] = (GLubyte) ((sample1 + sample2) / 2); + } + } + } + + free(texture); + + return 0; +} + + + +GLint GLAPIENTRY +gluBuild2DMipmaps(GLenum target, GLint components, + GLsizei width, GLsizei height, GLenum format, + GLenum type, const void *data) +{ + GLint w, h, maxsize; + void *image, *newimage; + GLint neww, newh, level, bpp; + int error; + GLboolean done; + GLint retval = 0; + GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels; + GLint packrowlength, packalignment, packskiprows, packskippixels; + + if (width < 1 || height < 1) + return GLU_INVALID_VALUE; + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); + + w = round2(width); + if (w > maxsize) { + w = maxsize; + } + h = round2(height); + if (h > maxsize) { + h = maxsize; + } + + bpp = bytes_per_pixel(format, type); + if (bpp == 0) { + /* probably a bad format or type enum */ + return GLU_INVALID_ENUM; + } + + /* Get current glPixelStore values */ + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpackrowlength); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpackalignment); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &unpackskiprows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &unpackskippixels); + glGetIntegerv(GL_PACK_ROW_LENGTH, &packrowlength); + glGetIntegerv(GL_PACK_ALIGNMENT, &packalignment); + glGetIntegerv(GL_PACK_SKIP_ROWS, &packskiprows); + glGetIntegerv(GL_PACK_SKIP_PIXELS, &packskippixels); + + /* set pixel packing */ + glPixelStorei(GL_PACK_ROW_LENGTH, 0); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_SKIP_ROWS, 0); + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + + done = GL_FALSE; + + if (w != width || h != height) { + /* must rescale image to get "top" mipmap texture image */ + image = malloc((w + 4) * h * bpp); + if (!image) { + return GLU_OUT_OF_MEMORY; + } + error = gluScaleImage(format, width, height, type, data, + w, h, type, image); + if (error) { + retval = error; + done = GL_TRUE; + } + } + else { + image = (void *) data; + } + + level = 0; + while (!done) { + if (image != data) { + /* set pixel unpacking */ + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + } + + glTexImage2D(target, level, components, w, h, 0, format, type, image); + + if (w == 1 && h == 1) + break; + + neww = (w < 2) ? 1 : w / 2; + newh = (h < 2) ? 1 : h / 2; + newimage = malloc((neww + 4) * newh * bpp); + if (!newimage) { + return GLU_OUT_OF_MEMORY; + } + + error = gluScaleImage(format, w, h, type, image, + neww, newh, type, newimage); + if (error) { + retval = error; + done = GL_TRUE; + } + + if (image != data) { + free(image); + } + image = newimage; + + w = neww; + h = newh; + level++; + } + + if (image != data) { + free(image); + } + + /* Restore original glPixelStore state */ + glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackrowlength); + glPixelStorei(GL_UNPACK_ALIGNMENT, unpackalignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, unpackskiprows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackskippixels); + glPixelStorei(GL_PACK_ROW_LENGTH, packrowlength); + glPixelStorei(GL_PACK_ALIGNMENT, packalignment); + glPixelStorei(GL_PACK_SKIP_ROWS, packskiprows); + glPixelStorei(GL_PACK_SKIP_PIXELS, packskippixels); + + return retval; +} --- mesa-7.2.orig/src/glu/mesa/project.c +++ mesa-7.2/src/glu/mesa/project.c @@ -0,0 +1,403 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include "gluP.h" +#endif + + +/* + * This code was contributed by Marc Buffat (buffat@mecaflu.ec-lyon.fr). + * Thanks Marc!!! + */ + + + +/* implementation de gluProject et gluUnproject */ +/* M. Buffat 17/2/95 */ + + + +/* + * Transform a point (column vector) by a 4x4 matrix. I.e. out = m * in + * Input: m - the 4x4 matrix + * in - the 4x1 vector + * Output: out - the resulting 4x1 vector. + */ +static void +transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) +{ +#define M(row,col) m[col*4+row] + out[0] = + M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; + out[1] = + M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3]; + out[2] = + M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3]; + out[3] = + M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3]; +#undef M +} + + + + +/* + * Perform a 4x4 matrix multiplication (product = a x b). + * Input: a, b - matrices to multiply + * Output: product - product of a and b + */ +static void +matmul(GLdouble * product, const GLdouble * a, const GLdouble * b) +{ + /* This matmul was contributed by Thomas Malik */ + GLdouble temp[16]; + GLint i; + +#define A(row,col) a[(col<<2)+row] +#define B(row,col) b[(col<<2)+row] +#define T(row,col) temp[(col<<2)+row] + + /* i-te Zeile */ + for (i = 0; i < 4; i++) { + T(i, 0) = + A(i, 0) * B(0, 0) + A(i, 1) * B(1, 0) + A(i, 2) * B(2, 0) + A(i, + 3) * + B(3, 0); + T(i, 1) = + A(i, 0) * B(0, 1) + A(i, 1) * B(1, 1) + A(i, 2) * B(2, 1) + A(i, + 3) * + B(3, 1); + T(i, 2) = + A(i, 0) * B(0, 2) + A(i, 1) * B(1, 2) + A(i, 2) * B(2, 2) + A(i, + 3) * + B(3, 2); + T(i, 3) = + A(i, 0) * B(0, 3) + A(i, 1) * B(1, 3) + A(i, 2) * B(2, 3) + A(i, + 3) * + B(3, 3); + } + +#undef A +#undef B +#undef T + MEMCPY(product, temp, 16 * sizeof(GLdouble)); +} + + + +/* + * Compute inverse of 4x4 transformation matrix. + * Code contributed by Jacques Leroy jle@star.be + * Return GL_TRUE for success, GL_FALSE for failure (singular matrix) + */ +static GLboolean +invert_matrix(const GLdouble * m, GLdouble * out) +{ +/* NB. OpenGL Matrices are COLUMN major. */ +#define SWAP_ROWS(a, b) { GLdouble *_tmp = a; (a)=(b); (b)=_tmp; } +#define MAT(m,r,c) (m)[(c)*4+(r)] + + GLdouble wtmp[4][8]; + GLdouble m0, m1, m2, m3, s; + GLdouble *r0, *r1, *r2, *r3; + + r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3]; + + r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1), + r0[2] = MAT(m, 0, 2), r0[3] = MAT(m, 0, 3), + r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0, + r1[0] = MAT(m, 1, 0), r1[1] = MAT(m, 1, 1), + r1[2] = MAT(m, 1, 2), r1[3] = MAT(m, 1, 3), + r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0, + r2[0] = MAT(m, 2, 0), r2[1] = MAT(m, 2, 1), + r2[2] = MAT(m, 2, 2), r2[3] = MAT(m, 2, 3), + r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0, + r3[0] = MAT(m, 3, 0), r3[1] = MAT(m, 3, 1), + r3[2] = MAT(m, 3, 2), r3[3] = MAT(m, 3, 3), + r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0; + + /* choose pivot - or die */ + if (fabs(r3[0]) > fabs(r2[0])) + SWAP_ROWS(r3, r2); + if (fabs(r2[0]) > fabs(r1[0])) + SWAP_ROWS(r2, r1); + if (fabs(r1[0]) > fabs(r0[0])) + SWAP_ROWS(r1, r0); + if (0.0 == r0[0]) + return GL_FALSE; + + /* eliminate first variable */ + m1 = r1[0] / r0[0]; + m2 = r2[0] / r0[0]; + m3 = r3[0] / r0[0]; + s = r0[1]; + r1[1] -= m1 * s; + r2[1] -= m2 * s; + r3[1] -= m3 * s; + s = r0[2]; + r1[2] -= m1 * s; + r2[2] -= m2 * s; + r3[2] -= m3 * s; + s = r0[3]; + r1[3] -= m1 * s; + r2[3] -= m2 * s; + r3[3] -= m3 * s; + s = r0[4]; + if (s != 0.0) { + r1[4] -= m1 * s; + r2[4] -= m2 * s; + r3[4] -= m3 * s; + } + s = r0[5]; + if (s != 0.0) { + r1[5] -= m1 * s; + r2[5] -= m2 * s; + r3[5] -= m3 * s; + } + s = r0[6]; + if (s != 0.0) { + r1[6] -= m1 * s; + r2[6] -= m2 * s; + r3[6] -= m3 * s; + } + s = r0[7]; + if (s != 0.0) { + r1[7] -= m1 * s; + r2[7] -= m2 * s; + r3[7] -= m3 * s; + } + + /* choose pivot - or die */ + if (fabs(r3[1]) > fabs(r2[1])) + SWAP_ROWS(r3, r2); + if (fabs(r2[1]) > fabs(r1[1])) + SWAP_ROWS(r2, r1); + if (0.0 == r1[1]) + return GL_FALSE; + + /* eliminate second variable */ + m2 = r2[1] / r1[1]; + m3 = r3[1] / r1[1]; + r2[2] -= m2 * r1[2]; + r3[2] -= m3 * r1[2]; + r2[3] -= m2 * r1[3]; + r3[3] -= m3 * r1[3]; + s = r1[4]; + if (0.0 != s) { + r2[4] -= m2 * s; + r3[4] -= m3 * s; + } + s = r1[5]; + if (0.0 != s) { + r2[5] -= m2 * s; + r3[5] -= m3 * s; + } + s = r1[6]; + if (0.0 != s) { + r2[6] -= m2 * s; + r3[6] -= m3 * s; + } + s = r1[7]; + if (0.0 != s) { + r2[7] -= m2 * s; + r3[7] -= m3 * s; + } + + /* choose pivot - or die */ + if (fabs(r3[2]) > fabs(r2[2])) + SWAP_ROWS(r3, r2); + if (0.0 == r2[2]) + return GL_FALSE; + + /* eliminate third variable */ + m3 = r3[2] / r2[2]; + r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4], + r3[5] -= m3 * r2[5], r3[6] -= m3 * r2[6], r3[7] -= m3 * r2[7]; + + /* last check */ + if (0.0 == r3[3]) + return GL_FALSE; + + s = 1.0 / r3[3]; /* now back substitute row 3 */ + r3[4] *= s; + r3[5] *= s; + r3[6] *= s; + r3[7] *= s; + + m2 = r2[3]; /* now back substitute row 2 */ + s = 1.0 / r2[2]; + r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2), + r2[6] = s * (r2[6] - r3[6] * m2), r2[7] = s * (r2[7] - r3[7] * m2); + m1 = r1[3]; + r1[4] -= r3[4] * m1, r1[5] -= r3[5] * m1, + r1[6] -= r3[6] * m1, r1[7] -= r3[7] * m1; + m0 = r0[3]; + r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0, + r0[6] -= r3[6] * m0, r0[7] -= r3[7] * m0; + + m1 = r1[2]; /* now back substitute row 1 */ + s = 1.0 / r1[1]; + r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1), + r1[6] = s * (r1[6] - r2[6] * m1), r1[7] = s * (r1[7] - r2[7] * m1); + m0 = r0[2]; + r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0, + r0[6] -= r2[6] * m0, r0[7] -= r2[7] * m0; + + m0 = r0[1]; /* now back substitute row 0 */ + s = 1.0 / r0[0]; + r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0), + r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0); + + MAT(out, 0, 0) = r0[4]; + MAT(out, 0, 1) = r0[5], MAT(out, 0, 2) = r0[6]; + MAT(out, 0, 3) = r0[7], MAT(out, 1, 0) = r1[4]; + MAT(out, 1, 1) = r1[5], MAT(out, 1, 2) = r1[6]; + MAT(out, 1, 3) = r1[7], MAT(out, 2, 0) = r2[4]; + MAT(out, 2, 1) = r2[5], MAT(out, 2, 2) = r2[6]; + MAT(out, 2, 3) = r2[7], MAT(out, 3, 0) = r3[4]; + MAT(out, 3, 1) = r3[5], MAT(out, 3, 2) = r3[6]; + MAT(out, 3, 3) = r3[7]; + + return GL_TRUE; + +#undef MAT +#undef SWAP_ROWS +} + + + +/* projection du point (objx,objy,obz) sur l'ecran (winx,winy,winz) */ +GLint GLAPIENTRY +gluProject(GLdouble objx, GLdouble objy, GLdouble objz, + const GLdouble model[16], const GLdouble proj[16], + const GLint viewport[4], + GLdouble * winx, GLdouble * winy, GLdouble * winz) +{ + /* matrice de transformation */ + GLdouble in[4], out[4]; + + /* initilise la matrice et le vecteur a transformer */ + in[0] = objx; + in[1] = objy; + in[2] = objz; + in[3] = 1.0; + transform_point(out, model, in); + transform_point(in, proj, out); + + /* d'ou le resultat normalise entre -1 et 1 */ + if (in[3] == 0.0) + return GL_FALSE; + + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + + /* en coordonnees ecran */ + *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; + *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; + /* entre 0 et 1 suivant z */ + *winz = (1 + in[2]) / 2; + return GL_TRUE; +} + + + +/* transformation du point ecran (winx,winy,winz) en point objet */ +GLint GLAPIENTRY +gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz, + const GLdouble model[16], const GLdouble proj[16], + const GLint viewport[4], + GLdouble * objx, GLdouble * objy, GLdouble * objz) +{ + /* matrice de transformation */ + GLdouble m[16], A[16]; + GLdouble in[4], out[4]; + + /* transformation coordonnees normalisees entre -1 et 1 */ + in[0] = (winx - viewport[0]) * 2 / viewport[2] - 1.0; + in[1] = (winy - viewport[1]) * 2 / viewport[3] - 1.0; + in[2] = 2 * winz - 1.0; + in[3] = 1.0; + + /* calcul transformation inverse */ + matmul(A, proj, model); + if (!invert_matrix(A, m)) + return GL_FALSE; + + /* d'ou les coordonnees objets */ + transform_point(out, m, in); + if (out[3] == 0.0) + return GL_FALSE; + *objx = out[0] / out[3]; + *objy = out[1] / out[3]; + *objz = out[2] / out[3]; + return GL_TRUE; +} + + +/* + * New in GLU 1.3 + * This is like gluUnProject but also takes near and far DepthRange values. + */ +#ifdef GLU_VERSION_1_3 +GLint GLAPIENTRY +gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw, + const GLdouble modelMatrix[16], + const GLdouble projMatrix[16], + const GLint viewport[4], + GLclampd nearZ, GLclampd farZ, + GLdouble * objx, GLdouble * objy, GLdouble * objz, + GLdouble * objw) +{ + /* matrice de transformation */ + GLdouble m[16], A[16]; + GLdouble in[4], out[4]; + GLdouble z = nearZ + winz * (farZ - nearZ); + + /* transformation coordonnees normalisees entre -1 et 1 */ + in[0] = (winx - viewport[0]) * 2 / viewport[2] - 1.0; + in[1] = (winy - viewport[1]) * 2 / viewport[3] - 1.0; + in[2] = 2.0 * z - 1.0; + in[3] = clipw; + + /* calcul transformation inverse */ + matmul(A, projMatrix, modelMatrix); + if (!invert_matrix(A, m)) + return GL_FALSE; + + /* d'ou les coordonnees objets */ + transform_point(out, m, in); + if (out[3] == 0.0) + return GL_FALSE; + *objx = out[0] / out[3]; + *objy = out[1] / out[3]; + *objz = out[2] / out[3]; + *objw = out[3]; + return GL_TRUE; +} +#endif --- mesa-7.2.orig/src/glu/mesa/README1 +++ mesa-7.2/src/glu/mesa/README1 @@ -0,0 +1,195 @@ + +Notes on the GLU polygon tesselation facility implemented by Bogdan Sikorski... + + + +The tesselation module is provided under the same terms as the Mesa +package. + +This is the first release of polygon tesselation code for Mesa. +It was written during my very little free time, so lets name it: +"its not perfect". If someone hates pointers, don't look at the code. +I preffer dynamic allocation versus static. But _all_ ideas, suggestions, +bug reports and fixes are welcome (if You want, also flames). I am aware +that many things could have been written using better techniques, but time +that I could devote to this library was very limited. It is not well commented, +excuse me. Also I am thinking of continuing working on this code to improve, +fix and polish it. And make it as compliant as possible to the OpenGL, so +software ports from OpenGL to Mesa will work correctly. If You know of any +differences in behaviour, expected input/output between Mesa tesselation library +and OpenGL, please send me a note. I explain later on why I am not +confident with this code. + +I tried to be fully compliant with the OpenGL routines. By "tried" I mean that +up to my knowledge it behaves as OpenGL tesselation routines. Just recently +I began to experiment with OpenGL (actually only Mesa), and also have +no access to any machine providing official implementation of OpenGL, +nor access to books (particulary Addison-Wesley publications). Thus my +knowledge on how the original tesselation code works, what kind of data +it expects etc. is based _only_ on the publicly available documentation +provided by SGI. Namely: + +* "The OpenGL Graphics System Utility Library" by K.P.Smith + (Silicon Graphics, 1992) +* "The OpenGL Graphics Interface" by M.Segal and K.Akeley + (Silicon Graphics, 19??) +* "OpenGL and X, Part 1: Introduction" by M.J.Kilgard + (Silicon Graphics, 1994) +* "OpenGL and X, Part 2: Using OpenGL with Xlib" by M.J.Kilgard + (Silicon Graphics, 1994) +* "OpenGL Graphics with the X Window System" by P.Karlton + (Silicon Graphics, 1993) +* Online Docs - Appendix C of OpenGL Programming Guide, Polygon Tesselation + (partial text cut and sent by e-mail) + + +The tesselation routines use slightly different prototypes than the ones +specified in the mentioned above publications. The _only_ differences are +the enumeration types which are not GLenum, but are GLUenum. So the +implemented routines have following prototypes: + +GLUtringulatorObj *gluNewTess(void); + +void gluTessCallback(GLUtriangulatorObj *,GLUenum,void (*)()); + ^^^^^^^ +void gluBeginPolygon(GLUtriangulatorObj *); + +void gluTessVertex(GLUtriangulatorObj *,GLdouble [3],void *); + +void gluNextContour(GLUtriangulatorObj *,GLUenum); + ^^^^^^^ +void gluEndPolygon(GLUtriangulatorObj *); + +const GLubyte *gluErrorString(GLUenum); + ^^^^^^^ + prototypes for callback functions: + +void (GLUenum); + ^^^^^^^ +void (GLboolean); +void (void *); +void (void); +void (GLUenum); + ^^^^^^^ + +The begin callback will be called only with GLU_TRIANGLES. No support +for traingle fans or strips yet. + +In case of errors an internal error variable is set to the appropiate +error enum values (GLU_TESS_ERROR?). Initially it is set to GLU_NO_ERROR. +The OpenGL library provides 8 error conditions, the tesselation code +of Mesa provides 9. They are: + +GLU_TESS_ERROR1: missing gluEndPolygon /* same as OpenGL */ +GLU_TESS_ERROR2: missing gluBeginPolygon /* same as OpenGL */ +GLU_TESS_ERROR3: misoriented contour /* not used in Mesa + in OpenGL is bad orientation or intersecting edges */ +GLU_TESS_ERROR4: vertex/edge intersection /* same as OpenGL */ +GLU_TESS_ERROR5: misoriented or self-intersecting loops /* same as OpenGL */ +GLU_TESS_ERROR6: coincident vertices /* same as OpenGL */ +GLU_TESS_ERROR7: colinear vertices /* OpenGL's illegal data */ +GLU_TESS_ERROR8: intersecting edges /* same as OpenGL */ +GLU_TESS_ERROR9: not coplanar contours /* new for Mesa */ + +The Mesa tesselation code ignores all data and calls after detecting an error +codition. This means that a _new_ tesselation object must be used for further +triangulations. Maybe this is too restrictive, and will be lifted in +future versions. + +The tesselation code completely ignores the type parameter passed in +gluNextContour. It also doesn't check if the passed parameter is a legal +enum value - ignores silently (maybe at least this should be checked). +The reason I chose this behaviour is based on what I read in the +beforementioned documents. I cite: + +".... +void gluNextContour(GLUtriangulatorObj *tessobj, GLenum type); + +Marks the beginning of the next contour when multiple contours make up the +boundary of the polygon to be tessellated. type can be GLU_EXTERIOR, +GLU_INTERIOR, GLU_CCW, GLU_CW, or GLU_UNKNOWN. These serve only as +to the tessellation. If you get them right, the tessellation might +go faster. If you get them wrong, they're ignored, and the tesselation still +works. +....." + +I hope You agree with me that my decision was correct. Mesa tesselation +_always_ checks by itself the interrelations between contours. Just as if +all contours were specified with the type GLU_UNKNOWN. + +One of OpenGL's policy is not to check all error conditions - rely sometimes +that the user "got things right". This is justified, since exhausting +error checking is timeconsuming, and would significantly slow down +a correct application. The Mesa tesselation code assumes only _one_ condition +when triangulating - all vertices in a contour are planar. This is _not_ +checked for correctness. Trying to tesselate such objects will lead to +unpredictable output. + +And now we arrive to the moment where I would like to list the required +(but checked for) conditions for triangulation, as well as summarize the +library: + +* all contours in a single tesselation cycle _must_ be coplanar - if not + an error is raised (and if provided a call to the error callback + is made) +* the contours can be passed in _any_ order, exteriors and holes can be + intermixed within a tesselation cycle and the correct hierarchy + will be determined by the library; thus specifying first holes then + exteriors, then holes within holes form a valid input. +* a hole within a hole is consider to be a yet another exterior contour +* multiple exterior contours (polygons) can be tesselated in one cycle; + _but_ this significantly degrades performance since many tests will be + performed for every contour pair; if You want triangulation to be fast + tesselate a single polygon (with possible holes) one at a time. +* orientation of exterior contours is arbitray, but if it has holes, + all interior holes of this particular exterior contour _must_ have an + opposite orientation. +* the output triangles have the same orientation as the exterior contour + that forms them +* each triangle is "enclosed" within the begin and end callbacks; + this is not efficent, but was made on purpose; so if triangulation + results in 2 triangles the following callbacks will be made in such + order: + (GLU_TRAINGLES) + (...) /* 3 vertices of first triangle */ + (...) + (...) + () + (GLU_TRAINGLES) + (...) /* 3 vertices of second triangle */ + (...) + (...) + () + Of course only when begin, vertex, and end callback were provided, + otherwise no output is done (actually tesselation does not take place). +* You will notice that some output traingles are very "thin"; there + exist possible several ways to traingulate a polygon, but "smart" code + avoiding such cases would require time to write, and will impact on + execution speed. +* like OpenGL, no new vertices are introduced during triangulation +* if the edgeflag callback is provided it will be called whenever + the just-about-to be output vertex begins a different type of edge + than the previous vertices; always before the first output a call + is made with GL_TRUE, to allow synchronization. +* all intermediate computations are done using GLdouble type, and comparisons + are biased with a precision value (EPSILON defined in tess.h) +* the point_in_poly function is my adaptation of code from the + comp.graphics.alg newsgroup FAQ (originally written by Mr. Wm. Randolph + Franklin, modified by Scott Anguish). +* the edge_edge_intersect test is also an adopted code from comp.graphics.alg + newsgroup FAQ +* the general idea for traingulation used in this library is described in + the book "Computational Geometry in C" by Joseph O'Rourke. + + +Excuse my English, its not my mother tongue. I should be available for some +time uner the following e-mail address. But For how long I am not certain. +Once I am settled in my new place, I'll post on the Mesa mailing list +my new address. + +(PS: today is my last day of work here, I'm changing my job). + +Bogdan. ( bogdan@dia.unisa.it ) + +Apr 28, 1995. + --- mesa-7.2.orig/src/glu/mesa/tesselat.c +++ mesa-7.2/src/glu/mesa/tesselat.c @@ -0,0 +1,406 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "tess.h" +#endif + + + +static GLboolean edge_flag; + +static void emit_triangle(GLUtriangulatorObj *, tess_vertex *, + tess_vertex *, tess_vertex *); + +static void emit_triangle_with_edge_flag(GLUtriangulatorObj *, + tess_vertex *, GLboolean, + tess_vertex *, GLboolean, + tess_vertex *, GLboolean); + +static GLdouble +twice_the_triangle_area(tess_vertex * va, tess_vertex * vb, tess_vertex * vc) +{ + return (vb->x - va->x) * (vc->y - va->y) - (vb->y - va->y) * (vc->x - + va->x); +} + +static GLboolean +left(GLdouble A, GLdouble B, GLdouble C, GLdouble x, GLdouble y) +{ + if (A * x + B * y + C > -EPSILON) + return GL_TRUE; + else + return GL_FALSE; +} + +static GLboolean +right(GLdouble A, GLdouble B, GLdouble C, GLdouble x, GLdouble y) +{ + if (A * x + B * y + C < EPSILON) + return GL_TRUE; + else + return GL_FALSE; +} + +static GLint +convex_ccw(tess_vertex * va, + tess_vertex * vb, tess_vertex * vc, GLUtriangulatorObj * tobj) +{ + GLdouble d; + + d = twice_the_triangle_area(va, vb, vc); + + if (d > EPSILON) { + return 1; + } + else if (d < -EPSILON) { + return 0; + } + else { + return -1; + } +} + +static GLint +convex_cw(tess_vertex * va, + tess_vertex * vb, tess_vertex * vc, GLUtriangulatorObj * tobj) +{ + GLdouble d; + + d = twice_the_triangle_area(va, vb, vc); + + if (d < -EPSILON) { + return 1; + } + else if (d > EPSILON) { + return 0; + } + else { + return -1; + } +} + +static GLboolean +diagonal_ccw(tess_vertex * va, + tess_vertex * vb, + GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vc = va->next, *vertex, *shadow_vertex; + struct + { + GLdouble A, B, C; + } + ac, cb, ba; + GLdouble x, y; + + GLint res = convex_ccw(va, vc, vb, tobj); + if (res == 0) + return GL_FALSE; + if (res == -1) + return GL_TRUE; + + ba.A = vb->y - va->y; + ba.B = va->x - vb->x; + ba.C = -ba.A * va->x - ba.B * va->y; + ac.A = va->y - vc->y; + ac.B = vc->x - va->x; + ac.C = -ac.A * vc->x - ac.B * vc->y; + cb.A = vc->y - vb->y; + cb.B = vb->x - vc->x; + cb.C = -cb.A * vb->x - cb.B * vb->y; + for (vertex = vb->next; vertex != va; vertex = vertex->next) { + shadow_vertex = vertex->shadow_vertex; + if (shadow_vertex != NULL && + (shadow_vertex == va || shadow_vertex == vb || shadow_vertex == vc)) + continue; + x = vertex->x; + y = vertex->y; + if (left(ba.A, ba.B, ba.C, x, y) && + left(ac.A, ac.B, ac.C, x, y) && left(cb.A, cb.B, cb.C, x, y)) + return GL_FALSE; + } + return GL_TRUE; +} + +static GLboolean +diagonal_cw(tess_vertex * va, + tess_vertex * vb, + GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vc = va->next, *vertex, *shadow_vertex; + struct + { + GLdouble A, B, C; + } + ac, cb, ba; + GLdouble x, y; + + GLint res = convex_cw(va, vc, vb, tobj); + if (res == 0) + return GL_FALSE; + if (res == -1) + return GL_TRUE; + + ba.A = vb->y - va->y; + ba.B = va->x - vb->x; + ba.C = -ba.A * va->x - ba.B * va->y; + ac.A = va->y - vc->y; + ac.B = vc->x - va->x; + ac.C = -ac.A * vc->x - ac.B * vc->y; + cb.A = vc->y - vb->y; + cb.B = vb->x - vc->x; + cb.C = -cb.A * vb->x - cb.B * vb->y; + for (vertex = vb->next; vertex != va; vertex = vertex->next) { + shadow_vertex = vertex->shadow_vertex; + if (shadow_vertex != NULL && + (shadow_vertex == va || shadow_vertex == vb || shadow_vertex == vc)) + continue; + x = vertex->x; + y = vertex->y; + if (right(ba.A, ba.B, ba.C, x, y) && + right(ac.A, ac.B, ac.C, x, y) && right(cb.A, cb.B, cb.C, x, y)) + return GL_FALSE; + } + return GL_TRUE; +} + +static void +clip_ear(GLUtriangulatorObj * tobj, tess_vertex * v, tess_contour * contour) +{ + emit_triangle(tobj, v->previous, v, v->next); + /* the first in the list */ + if (contour->vertices == v) { + contour->vertices = v->next; + contour->last_vertex->next = v->next; + v->next->previous = contour->last_vertex; + } + else + /* the last ? */ + if (contour->last_vertex == v) { + contour->vertices->previous = v->previous; + v->previous->next = v->next; + contour->last_vertex = v->previous; + } + else { + v->next->previous = v->previous; + v->previous->next = v->next; + } + free(v); + --(contour->vertex_cnt); +} + +static void +clip_ear_with_edge_flag(GLUtriangulatorObj * tobj, + tess_vertex * v, tess_contour * contour) +{ + emit_triangle_with_edge_flag(tobj, v->previous, v->previous->edge_flag, + v, v->edge_flag, v->next, GL_FALSE); + v->previous->edge_flag = GL_FALSE; + /* the first in the list */ + if (contour->vertices == v) { + contour->vertices = v->next; + contour->last_vertex->next = v->next; + v->next->previous = contour->last_vertex; + } + else + /* the last ? */ + if (contour->last_vertex == v) { + contour->vertices->previous = v->previous; + v->previous->next = v->next; + contour->last_vertex = v->previous; + } + else { + v->next->previous = v->previous; + v->previous->next = v->next; + } + free(v); + --(contour->vertex_cnt); +} + +static void +triangulate_ccw(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_ccw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +static void +triangulate_cw(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_cw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +static void +triangulate_ccw_with_edge_flag(GLUtriangulatorObj * tobj, + tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_ccw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear_with_edge_flag(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +static void +triangulate_cw_with_edge_flag(GLUtriangulatorObj * tobj, + tess_contour * contour) +{ + tess_vertex *vertex; + GLuint vertex_cnt = contour->vertex_cnt; + + while (vertex_cnt > 3) { + vertex = contour->vertices; + while (diagonal_cw(vertex, vertex->next->next, tobj, contour) == + GL_FALSE && tobj->error == GLU_NO_ERROR) + vertex = vertex->next; + if (tobj->error != GLU_NO_ERROR) + return; + clip_ear_with_edge_flag(tobj, vertex->next, contour); + --vertex_cnt; + } +} + +void +tess_tesselate(GLUtriangulatorObj * tobj) +{ + tess_contour *contour; + + for (contour = tobj->contours; contour != NULL; contour = contour->next) { + if (contour->orientation == GLU_CCW) { + triangulate_ccw(tobj, contour); + } + else { + triangulate_cw(tobj, contour); + } + if (tobj->error != GLU_NO_ERROR) + return; + + /* emit the last triangle */ + emit_triangle(tobj, contour->vertices, contour->vertices->next, + contour->vertices->next->next); + } +} + +void +tess_tesselate_with_edge_flag(GLUtriangulatorObj * tobj) +{ + tess_contour *contour; + + edge_flag = GL_TRUE; + /* first callback with edgeFlag set to GL_TRUE */ + (tobj->callbacks.edgeFlag) (GL_TRUE); + + for (contour = tobj->contours; contour != NULL; contour = contour->next) { + if (contour->orientation == GLU_CCW) + triangulate_ccw_with_edge_flag(tobj, contour); + else + triangulate_cw_with_edge_flag(tobj, contour); + if (tobj->error != GLU_NO_ERROR) + return; + /* emit the last triangle */ + emit_triangle_with_edge_flag(tobj, contour->vertices, + contour->vertices->edge_flag, + contour->vertices->next, + contour->vertices->next->edge_flag, + contour->vertices->next->next, + contour->vertices->next->next->edge_flag); + } +} + +static void +emit_triangle(GLUtriangulatorObj * tobj, + tess_vertex * v1, tess_vertex * v2, tess_vertex * v3) +{ + (tobj->callbacks.begin) (GL_TRIANGLES); + (tobj->callbacks.vertex) (v1->data); + (tobj->callbacks.vertex) (v2->data); + (tobj->callbacks.vertex) (v3->data); + (tobj->callbacks.end) (); +} + +static void +emit_triangle_with_edge_flag(GLUtriangulatorObj * tobj, + tess_vertex * v1, + GLboolean edge_flag1, + tess_vertex * v2, + GLboolean edge_flag2, + tess_vertex * v3, GLboolean edge_flag3) +{ + (tobj->callbacks.begin) (GL_TRIANGLES); + if (edge_flag1 != edge_flag) { + edge_flag = (edge_flag == GL_TRUE ? GL_FALSE : GL_TRUE); + (tobj->callbacks.edgeFlag) (edge_flag); + } + (tobj->callbacks.vertex) (v1->data); + if (edge_flag2 != edge_flag) { + edge_flag = (edge_flag == GL_TRUE ? GL_FALSE : GL_TRUE); + (tobj->callbacks.edgeFlag) (edge_flag); + } + (tobj->callbacks.vertex) (v2->data); + if (edge_flag3 != edge_flag) { + edge_flag = (edge_flag == GL_TRUE ? GL_FALSE : GL_TRUE); + (tobj->callbacks.edgeFlag) (edge_flag); + } + (tobj->callbacks.vertex) (v3->data); + (tobj->callbacks.end) (); +} --- mesa-7.2.orig/src/glu/mesa/Makefile.DJ +++ mesa-7.2/src/glu/mesa/Makefile.DJ @@ -0,0 +1,100 @@ +# Mesa 3-D graphics library +# Version: 4.0 +# +# Copyright (C) 1999 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"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# BRIAN PAUL 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. + +# DOS/DJGPP glu makefile v1.5 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : dborca@users.sourceforge.net +# Web : http://www.geocities.com/dborca + + +# +# Available options: +# +# Environment variables: +# CFLAGS +# +# Targets: +# all: build GLU +# clean: remove object files +# + + + +.PHONY: all clean + +TOP = ../../.. +LIBDIR = $(TOP)/lib +GLU_LIB = libglu.a +GLU_DXE = glu.dxe +GLU_IMP = libiglu.a + +export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH);$(LIBDIR);$(GLIDE)/lib + +CC = gcc +CFLAGS += -I$(TOP)/include + +AR = ar +ARFLAGS = crus + +HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe) + +ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) +UNLINK = del $(subst /,\,$(1)) +else +UNLINK = $(RM) $(1) +endif + +CORE_SOURCES = \ + glu.c \ + mipmap.c \ + nurbs.c \ + nurbscrv.c \ + nurbssrf.c \ + nurbsutl.c \ + polytest.c \ + project.c \ + quadric.c \ + tess.c \ + tesselat.c + +SOURCES = $(CORE_SOURCES) + +OBJECTS = $(SOURCES:.c=.o) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< + +all: $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP) + +$(LIBDIR)/$(GLU_LIB): $(OBJECTS) + $(AR) $(ARFLAGS) $@ $^ + +$(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP): $(OBJECTS) +ifeq ($(HAVEDXE3),) + $(warning Missing DXE3 package... Skipping $(GLU_DXE)) +else + -dxe3gen -o $(LIBDIR)/$(GLU_DXE) -Y $(LIBDIR)/$(GLU_IMP) -D "MesaGLU DJGPP" -E _glu -P gl.dxe -U $^ +endif + +clean: + -$(call UNLINK,*.o) --- mesa-7.2.orig/src/glu/mesa/nurbsutl.c +++ mesa-7.2/src/glu/mesa/nurbsutl.c @@ -0,0 +1,1309 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "gluP.h" +#include "nurbs.h" +#endif + + +GLenum test_knot(GLint nknots, GLfloat * knot, GLint order) +{ + GLsizei i; + GLint knot_mult; + GLfloat tmp_knot; + + tmp_knot = knot[0]; + knot_mult = 1; + for (i = 1; i < nknots; i++) { + if (knot[i] < tmp_knot) + return GLU_NURBS_ERROR4; + if (fabs(tmp_knot - knot[i]) > EPSILON) { + if (knot_mult > order) + return GLU_NURBS_ERROR5; + knot_mult = 1; + tmp_knot = knot[i]; + } + else + ++knot_mult; + } + return GLU_NO_ERROR; +} + +static int +/* qsort function */ +#if defined(WIN32) && !defined(OPENSTEP) + __cdecl +#endif +knot_sort(const void *a, const void *b) +{ + GLfloat x, y; + + x = *((GLfloat *) a); + y = *((GLfloat *) b); + if (fabs(x - y) < EPSILON) + return 0; + if (x > y) + return 1; + return -1; +} + +/* insert into dest knot all values within the valid range from src knot */ +/* that do not appear in dest */ +void +collect_unified_knot(knot_str_type * dest, knot_str_type * src, + GLfloat maximal_min_knot, GLfloat minimal_max_knot) +{ + GLfloat *src_knot, *dest_knot; + GLint src_t_min, src_t_max, dest_t_min, dest_t_max; + GLint src_nknots, dest_nknots; + GLint i, j, k, new_cnt; + GLboolean not_found_flag; + + src_knot = src->unified_knot; + dest_knot = dest->unified_knot; + src_t_min = src->t_min; + src_t_max = src->t_max; + dest_t_min = dest->t_min; + dest_t_max = dest->t_max; + src_nknots = src->unified_nknots; + dest_nknots = dest->unified_nknots; + + k = new_cnt = dest_nknots; + for (i = src_t_min; i <= src_t_max; i++) + if (src_knot[i] - maximal_min_knot > -EPSILON && + src_knot[i] - minimal_max_knot < EPSILON) { + not_found_flag = GL_TRUE; + for (j = dest_t_min; j <= dest_t_max; j++) + if (fabs(dest_knot[j] - src_knot[i]) < EPSILON) { + not_found_flag = GL_FALSE; + break; + } + if (not_found_flag) { + /* knot from src is not in dest - add this knot to dest */ + dest_knot[k++] = src_knot[i]; + ++new_cnt; + ++(dest->t_max); /* the valid range widens */ + ++(dest->delta_nknots); /* increment the extra knot value counter */ + } + } + dest->unified_nknots = new_cnt; + qsort((void *) dest_knot, (size_t) new_cnt, (size_t) sizeof(GLfloat), + &knot_sort); +} + +/* basing on the new common knot range for all attributes set */ +/* t_min and t_max values for each knot - they will be used later on */ +/* by explode_knot() and calc_new_ctrl_pts */ +static void +set_new_t_min_t_max(knot_str_type * geom_knot, knot_str_type * color_knot, + knot_str_type * normal_knot, knot_str_type * texture_knot, + GLfloat maximal_min_knot, GLfloat minimal_max_knot) +{ + GLuint t_min = 0, t_max = 0, cnt = 0; + + if (minimal_max_knot - maximal_min_knot < EPSILON) { + /* knot common range empty */ + geom_knot->t_min = geom_knot->t_max = 0; + color_knot->t_min = color_knot->t_max = 0; + normal_knot->t_min = normal_knot->t_max = 0; + texture_knot->t_min = texture_knot->t_max = 0; + } + else { + if (geom_knot->unified_knot != NULL) { + cnt = geom_knot->unified_nknots; + for (t_min = 0; t_min < cnt; t_min++) + if (fabs((geom_knot->unified_knot)[t_min] - maximal_min_knot) < + EPSILON) break; + for (t_max = cnt - 1; t_max; t_max--) + if (fabs((geom_knot->unified_knot)[t_max] - minimal_max_knot) < + EPSILON) break; + } + else if (geom_knot->nknots) { + cnt = geom_knot->nknots; + for (t_min = 0; t_min < cnt; t_min++) + if (fabs((geom_knot->knot)[t_min] - maximal_min_knot) < EPSILON) + break; + for (t_max = cnt - 1; t_max; t_max--) + if (fabs((geom_knot->knot)[t_max] - minimal_max_knot) < EPSILON) + break; + } + geom_knot->t_min = t_min; + geom_knot->t_max = t_max; + if (color_knot->unified_knot != NULL) { + cnt = color_knot->unified_nknots; + for (t_min = 0; t_min < cnt; t_min++) + if (fabs((color_knot->unified_knot)[t_min] - maximal_min_knot) < + EPSILON) break; + for (t_max = cnt - 1; t_max; t_max--) + if (fabs((color_knot->unified_knot)[t_max] - minimal_max_knot) < + EPSILON) break; + color_knot->t_min = t_min; + color_knot->t_max = t_max; + } + if (normal_knot->unified_knot != NULL) { + cnt = normal_knot->unified_nknots; + for (t_min = 0; t_min < cnt; t_min++) + if (fabs((normal_knot->unified_knot)[t_min] - maximal_min_knot) < + EPSILON) break; + for (t_max = cnt - 1; t_max; t_max--) + if (fabs((normal_knot->unified_knot)[t_max] - minimal_max_knot) < + EPSILON) break; + normal_knot->t_min = t_min; + normal_knot->t_max = t_max; + } + if (texture_knot->unified_knot != NULL) { + cnt = texture_knot->unified_nknots; + for (t_min = 0; t_min < cnt; t_min++) + if (fabs((texture_knot->unified_knot)[t_min] - maximal_min_knot) + < EPSILON) + break; + for (t_max = cnt - 1; t_max; t_max--) + if (fabs((texture_knot->unified_knot)[t_max] - minimal_max_knot) + < EPSILON) + break; + texture_knot->t_min = t_min; + texture_knot->t_max = t_max; + } + } +} + +/* modify all knot valid ranges in such a way that all have the same */ +/* range, common to all knots */ +/* do this by knot insertion */ +GLenum +select_knot_working_range(GLUnurbsObj * nobj, knot_str_type * geom_knot, + knot_str_type * color_knot, + knot_str_type * normal_knot, + knot_str_type * texture_knot) +{ + GLint max_nknots; + GLfloat maximal_min_knot, minimal_max_knot; + GLint i; + + /* find the maximum modified knot length */ + max_nknots = geom_knot->nknots; + if (color_knot->unified_knot) + max_nknots += color_knot->nknots; + if (normal_knot->unified_knot) + max_nknots += normal_knot->nknots; + if (texture_knot->unified_knot) + max_nknots += texture_knot->nknots; + maximal_min_knot = (geom_knot->knot)[geom_knot->t_min]; + minimal_max_knot = (geom_knot->knot)[geom_knot->t_max]; + /* any attirb data ? */ + if (max_nknots != geom_knot->nknots) { + /* allocate space for the unified knots */ + if ((geom_knot->unified_knot = + (GLfloat *) malloc(sizeof(GLfloat) * max_nknots)) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + /* copy the original knot to the unified one */ + geom_knot->unified_nknots = geom_knot->nknots; + for (i = 0; i < geom_knot->nknots; i++) + (geom_knot->unified_knot)[i] = (geom_knot->knot)[i]; + if (color_knot->unified_knot) { + if ((color_knot->knot)[color_knot->t_min] - maximal_min_knot > + EPSILON) + maximal_min_knot = (color_knot->knot)[color_knot->t_min]; + if (minimal_max_knot - (color_knot->knot)[color_knot->t_max] > + EPSILON) + minimal_max_knot = (color_knot->knot)[color_knot->t_max]; + if ((color_knot->unified_knot = + (GLfloat *) malloc(sizeof(GLfloat) * max_nknots)) == NULL) { + free(geom_knot->unified_knot); + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + /* copy the original knot to the unified one */ + color_knot->unified_nknots = color_knot->nknots; + for (i = 0; i < color_knot->nknots; i++) + (color_knot->unified_knot)[i] = (color_knot->knot)[i]; + } + if (normal_knot->unified_knot) { + if ((normal_knot->knot)[normal_knot->t_min] - maximal_min_knot > + EPSILON) + maximal_min_knot = (normal_knot->knot)[normal_knot->t_min]; + if (minimal_max_knot - (normal_knot->knot)[normal_knot->t_max] > + EPSILON) + minimal_max_knot = (normal_knot->knot)[normal_knot->t_max]; + if ((normal_knot->unified_knot = + (GLfloat *) malloc(sizeof(GLfloat) * max_nknots)) == NULL) { + free(geom_knot->unified_knot); + free(color_knot->unified_knot); + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + /* copy the original knot to the unified one */ + normal_knot->unified_nknots = normal_knot->nknots; + for (i = 0; i < normal_knot->nknots; i++) + (normal_knot->unified_knot)[i] = (normal_knot->knot)[i]; + } + if (texture_knot->unified_knot) { + if ((texture_knot->knot)[texture_knot->t_min] - maximal_min_knot > + EPSILON) + maximal_min_knot = (texture_knot->knot)[texture_knot->t_min]; + if (minimal_max_knot - (texture_knot->knot)[texture_knot->t_max] > + EPSILON) + minimal_max_knot = (texture_knot->knot)[texture_knot->t_max]; + if ((texture_knot->unified_knot = + (GLfloat *) malloc(sizeof(GLfloat) * max_nknots)) == NULL) { + free(geom_knot->unified_knot); + free(color_knot->unified_knot); + free(normal_knot->unified_knot); + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + /* copy the original knot to the unified one */ + texture_knot->unified_nknots = texture_knot->nknots; + for (i = 0; i < texture_knot->nknots; i++) + (texture_knot->unified_knot)[i] = (texture_knot->knot)[i]; + } + /* work on the geometry knot with all additional knot values */ + /* appearing in attirbutive knots */ + if (minimal_max_knot - maximal_min_knot < EPSILON) { + /* empty working range */ + geom_knot->unified_nknots = 0; + color_knot->unified_nknots = 0; + normal_knot->unified_nknots = 0; + texture_knot->unified_nknots = 0; + } + else { + if (color_knot->unified_knot) + collect_unified_knot(geom_knot, color_knot, maximal_min_knot, + minimal_max_knot); + if (normal_knot->unified_knot) + collect_unified_knot(geom_knot, normal_knot, maximal_min_knot, + minimal_max_knot); + if (texture_knot->unified_knot) + collect_unified_knot(geom_knot, texture_knot, maximal_min_knot, + minimal_max_knot); + /* since we have now built the "unified" geometry knot */ + /* add same knot values to all attributive knots */ + if (color_knot->unified_knot) + collect_unified_knot(color_knot, geom_knot, maximal_min_knot, + minimal_max_knot); + if (normal_knot->unified_knot) + collect_unified_knot(normal_knot, geom_knot, maximal_min_knot, + minimal_max_knot); + if (texture_knot->unified_knot) + collect_unified_knot(texture_knot, geom_knot, maximal_min_knot, + minimal_max_knot); + } + } + set_new_t_min_t_max(geom_knot, color_knot, normal_knot, texture_knot, + maximal_min_knot, minimal_max_knot); + return GLU_NO_ERROR; +} + +void +free_unified_knots(knot_str_type * geom_knot, knot_str_type * color_knot, + knot_str_type * normal_knot, knot_str_type * texture_knot) +{ + if (geom_knot->unified_knot) + free(geom_knot->unified_knot); + if (color_knot->unified_knot) + free(color_knot->unified_knot); + if (normal_knot->unified_knot) + free(normal_knot->unified_knot); + if (texture_knot->unified_knot) + free(texture_knot->unified_knot); +} + +GLenum explode_knot(knot_str_type * the_knot) +{ + GLfloat *knot, *new_knot; + GLint nknots, n_new_knots = 0; + GLint t_min, t_max; + GLint ord; + GLsizei i, j, k; + GLfloat tmp_float; + + if (the_knot->unified_knot) { + knot = the_knot->unified_knot; + nknots = the_knot->unified_nknots; + } + else { + knot = the_knot->knot; + nknots = the_knot->nknots; + } + ord = the_knot->order; + t_min = the_knot->t_min; + t_max = the_knot->t_max; + + for (i = t_min; i <= t_max;) { + tmp_float = knot[i]; + for (j = 0; j < ord && (i + j) <= t_max; j++) + if (fabs(tmp_float - knot[i + j]) > EPSILON) + break; + n_new_knots += ord - j; + i += j; + } + /* alloc space for new_knot */ + if ( + (new_knot = + (GLfloat *) malloc(sizeof(GLfloat) * (nknots + n_new_knots + 1))) == NULL) { + return GLU_OUT_OF_MEMORY; + } + /* fill in new knot */ + for (j = 0; j < t_min; j++) + new_knot[j] = knot[j]; + for (i = j; i <= t_max; i++) { + tmp_float = knot[i]; + for (k = 0; k < ord; k++) { + new_knot[j++] = knot[i]; + if (tmp_float == knot[i + 1]) + i++; + } + } + for (i = t_max + 1; i < (int) nknots; i++) + new_knot[j++] = knot[i]; + /* fill in the knot structure */ + the_knot->new_knot = new_knot; + the_knot->delta_nknots += n_new_knots; + the_knot->t_max += n_new_knots; + return GLU_NO_ERROR; +} + +GLenum calc_alphas(knot_str_type * the_knot) +{ + GLfloat tmp_float; + int i, j, k, m, n; + int order; + GLfloat *alpha, *alpha_new, *tmp_alpha; + GLfloat denom; + GLfloat *knot, *new_knot; + + + knot = the_knot->knot; + order = the_knot->order; + new_knot = the_knot->new_knot; + n = the_knot->nknots - the_knot->order; + m = n + the_knot->delta_nknots; + if ((alpha = (GLfloat *) malloc(sizeof(GLfloat) * n * m)) == NULL) { + return GLU_OUT_OF_MEMORY; + } + if ((alpha_new = (GLfloat *) malloc(sizeof(GLfloat) * n * m)) == NULL) { + free(alpha); + return GLU_OUT_OF_MEMORY; + } + for (j = 0; j < m; j++) { + for (i = 0; i < n; i++) { + if ((knot[i] <= new_knot[j]) && (new_knot[j] < knot[i + 1])) + tmp_float = 1.0; + else + tmp_float = 0.0; + alpha[i + j * n] = tmp_float; + } + } + for (k = 1; k < order; k++) { + for (j = 0; j < m; j++) + for (i = 0; i < n; i++) { + denom = knot[i + k] - knot[i]; + if (fabs(denom) < EPSILON) + tmp_float = 0.0; + else + tmp_float = (new_knot[j + k] - knot[i]) / denom * + alpha[i + j * n]; + denom = knot[i + k + 1] - knot[i + 1]; + if (fabs(denom) > EPSILON) + tmp_float += (knot[i + k + 1] - new_knot[j + k]) / denom * + alpha[(i + 1) + j * n]; + alpha_new[i + j * n] = tmp_float; + } + tmp_alpha = alpha_new; + alpha_new = alpha; + alpha = tmp_alpha; + } + the_knot->alpha = alpha; + free(alpha_new); + return GLU_NO_ERROR; +} + +GLenum +calc_new_ctrl_pts(GLfloat * ctrl, GLint stride, knot_str_type * the_knot, + GLint dim, GLfloat ** new_ctrl, GLint * ncontrol) +{ + GLsizei i, j, k, l, m, n; + GLsizei index1, index2; + GLfloat *alpha; + GLfloat *new_knot; + + new_knot = the_knot->new_knot; + n = the_knot->nknots - the_knot->order; + alpha = the_knot->alpha; + + m = the_knot->t_max + 1 - the_knot->t_min - the_knot->order; + k = the_knot->t_min; + /* allocate space for new control points */ + if ((*new_ctrl = (GLfloat *) malloc(sizeof(GLfloat) * dim * m)) == NULL) { + return GLU_OUT_OF_MEMORY; + } + for (j = 0; j < m; j++) { + for (l = 0; l < dim; l++) + (*new_ctrl)[j * dim + l] = 0.0; + for (i = 0; i < n; i++) { + index1 = i + (j + k) * n; + index2 = i * stride; + for (l = 0; l < dim; l++) + (*new_ctrl)[j * dim + l] += alpha[index1] * ctrl[index2 + l]; + } + } + *ncontrol = (GLint) m; + return GLU_NO_ERROR; +} + +static GLint +calc_factor(GLfloat * pts, GLint order, GLint indx, GLint stride, + GLfloat tolerance, GLint dim) +{ + GLdouble model[16], proj[16]; + GLint viewport[4]; + GLdouble x, y, z, w, winx1, winy1, winz, winx2, winy2; + GLint i; + GLdouble len, dx, dy; + + glGetDoublev(GL_MODELVIEW_MATRIX, model); + glGetDoublev(GL_PROJECTION_MATRIX, proj); + glGetIntegerv(GL_VIEWPORT, viewport); + if (dim == 4) { + w = (GLdouble) pts[indx + 3]; + x = (GLdouble) pts[indx] / w; + y = (GLdouble) pts[indx + 1] / w; + z = (GLdouble) pts[indx + 2] / w; + gluProject(x, y, z, model, proj, viewport, &winx1, &winy1, &winz); + len = 0.0; + for (i = 1; i < order; i++) { + w = (GLdouble) pts[indx + i * stride + 3]; + x = (GLdouble) pts[indx + i * stride] / w; + y = (GLdouble) pts[indx + i * stride + 1] / w; + z = (GLdouble) pts[indx + i * stride + 2] / w; + if (gluProject + (x, y, z, model, proj, viewport, &winx2, &winy2, &winz)) { + dx = winx2 - winx1; + dy = winy2 - winy1; + len += sqrt(dx * dx + dy * dy); + } + winx1 = winx2; + winy1 = winy2; + } + } + else { + x = (GLdouble) pts[indx]; + y = (GLdouble) pts[indx + 1]; + if (dim == 2) + z = 0.0; + else + z = (GLdouble) pts[indx + 2]; + gluProject(x, y, z, model, proj, viewport, &winx1, &winy1, &winz); + len = 0.0; + for (i = 1; i < order; i++) { + x = (GLdouble) pts[indx + i * stride]; + y = (GLdouble) pts[indx + i * stride + 1]; + if (dim == 2) + z = 0.0; + else + z = (GLdouble) pts[indx + i * stride + 2]; + if (gluProject + (x, y, z, model, proj, viewport, &winx2, &winy2, &winz)) { + dx = winx2 - winx1; + dy = winy2 - winy1; + len += sqrt(dx * dx + dy * dy); + } + winx1 = winx2; + winy1 = winy2; + } + } + len /= tolerance; + return ((GLint) len + 1); +} + +/* we can't use the Mesa evaluators - no way to get the point coords */ +/* so we use our own Bezier point calculus routines */ +/* because I'm lazy, I reuse the ones from eval.c */ + +static void +bezier_curve(GLfloat * cp, GLfloat * out, GLfloat t, + GLuint dim, GLuint order, GLint offset) +{ + GLfloat s, powert; + GLuint i, k, bincoeff; + + if (order >= 2) { + bincoeff = order - 1; + s = 1.0 - t; + + for (k = 0; k < dim; k++) + out[k] = s * cp[k] + bincoeff * t * cp[offset + k]; + + for (i = 2, cp += 2 * offset, powert = t * t; i < order; + i++, powert *= t, cp += offset) { + bincoeff *= order - i; + bincoeff /= i; + + for (k = 0; k < dim; k++) + out[k] = s * out[k] + bincoeff * powert * cp[k]; + } + } + else { /* order=1 -> constant curve */ + + for (k = 0; k < dim; k++) + out[k] = cp[k]; + } +} + +static GLint +calc_parametric_factor(GLfloat * pts, GLint order, GLint indx, GLint stride, + GLfloat tolerance, GLint dim) +{ + GLdouble model[16], proj[16]; + GLint viewport[4]; + GLdouble x, y, z, w, x1, y1, z1, x2, y2, z2, x3, y3, z3; + GLint i; + GLint P; + GLfloat bez_pt[4]; + GLdouble len = 0.0, tmp, z_med; + + P = 2 * (order + 2); + glGetDoublev(GL_MODELVIEW_MATRIX, model); + glGetDoublev(GL_PROJECTION_MATRIX, proj); + glGetIntegerv(GL_VIEWPORT, viewport); + z_med = (viewport[2] + viewport[3]) * 0.5; + switch (dim) { + case 4: + for (i = 1; i < P; i++) { + bezier_curve(pts + indx, bez_pt, (GLfloat) i / (GLfloat) P, 4, + order, stride); + w = (GLdouble) bez_pt[3]; + x = (GLdouble) bez_pt[0] / w; + y = (GLdouble) bez_pt[1] / w; + z = (GLdouble) bez_pt[2] / w; + gluProject(x, y, z, model, proj, viewport, &x3, &y3, &z3); + z3 *= z_med; + bezier_curve(pts + indx, bez_pt, (GLfloat) (i - 1) / (GLfloat) P, 4, + order, stride); + w = (GLdouble) bez_pt[3]; + x = (GLdouble) bez_pt[0] / w; + y = (GLdouble) bez_pt[1] / w; + z = (GLdouble) bez_pt[2] / w; + gluProject(x, y, z, model, proj, viewport, &x1, &y1, &z1); + z1 *= z_med; + bezier_curve(pts + indx, bez_pt, (GLfloat) (i + 1) / (GLfloat) P, 4, + order, stride); + w = (GLdouble) bez_pt[3]; + x = (GLdouble) bez_pt[0] / w; + y = (GLdouble) bez_pt[1] / w; + z = (GLdouble) bez_pt[2] / w; + gluProject(x, y, z, model, proj, viewport, &x2, &y2, &z2); + z2 *= z_med; + /* calc distance between point (x3,y3,z3) and line segment */ + /* */ + x = x2 - x1; + y = y2 - y1; + z = z2 - z1; + tmp = sqrt(x * x + y * y + z * z); + x /= tmp; + y /= tmp; + z /= tmp; + tmp = x3 * x + y3 * y + z3 * z - x1 * x - y1 * y - z1 * z; + x = x1 + x * tmp - x3; + y = y1 + y * tmp - y3; + z = z1 + z * tmp - z3; + tmp = sqrt(x * x + y * y + z * z); + if (tmp > len) + len = tmp; + } + break; + case 3: + for (i = 1; i < P; i++) { + bezier_curve(pts + indx, bez_pt, (GLfloat) i / (GLfloat) P, 3, + order, stride); + x = (GLdouble) bez_pt[0]; + y = (GLdouble) bez_pt[1]; + z = (GLdouble) bez_pt[2]; + gluProject(x, y, z, model, proj, viewport, &x3, &y3, &z3); + z3 *= z_med; + bezier_curve(pts + indx, bez_pt, (GLfloat) (i - 1) / (GLfloat) P, 3, + order, stride); + x = (GLdouble) bez_pt[0]; + y = (GLdouble) bez_pt[1]; + z = (GLdouble) bez_pt[2]; + gluProject(x, y, z, model, proj, viewport, &x1, &y1, &z1); + z1 *= z_med; + bezier_curve(pts + indx, bez_pt, (GLfloat) (i + 1) / (GLfloat) P, 3, + order, stride); + x = (GLdouble) bez_pt[0]; + y = (GLdouble) bez_pt[1]; + z = (GLdouble) bez_pt[2]; + gluProject(x, y, z, model, proj, viewport, &x2, &y2, &z2); + z2 *= z_med; + /* calc distance between point (x3,y3,z3) and line segment */ + /* */ + x = x2 - x1; + y = y2 - y1; + z = z2 - z1; + tmp = sqrt(x * x + y * y + z * z); + x /= tmp; + y /= tmp; + z /= tmp; + tmp = x3 * x + y3 * y + z3 * z - x1 * x - y1 * y - z1 * z; + x = x1 + x * tmp - x3; + y = y1 + y * tmp - y3; + z = z1 + z * tmp - z3; + tmp = sqrt(x * x + y * y + z * z); + if (tmp > len) + len = tmp; + } + break; + case 2: + for (i = 1; i < P; i++) { + bezier_curve(pts + indx, bez_pt, (GLfloat) i / (GLfloat) P, 2, + order, stride); + x = (GLdouble) bez_pt[0]; + y = (GLdouble) bez_pt[1]; + z = 0.0; + gluProject(x, y, z, model, proj, viewport, &x3, &y3, &z3); + z3 *= z_med; + bezier_curve(pts + indx, bez_pt, (GLfloat) (i - 1) / (GLfloat) P, 2, + order, stride); + x = (GLdouble) bez_pt[0]; + y = (GLdouble) bez_pt[1]; + z = 0.0; + gluProject(x, y, z, model, proj, viewport, &x1, &y1, &z1); + z1 *= z_med; + bezier_curve(pts + indx, bez_pt, (GLfloat) (i + 1) / (GLfloat) P, 2, + order, stride); + x = (GLdouble) bez_pt[0]; + y = (GLdouble) bez_pt[1]; + z = 0.0; + gluProject(x, y, z, model, proj, viewport, &x2, &y2, &z2); + z2 *= z_med; + /* calc distance between point (x3,y3,z3) and line segment */ + /* */ + x = x2 - x1; + y = y2 - y1; + z = z2 - z1; + tmp = sqrt(x * x + y * y + z * z); + x /= tmp; + y /= tmp; + z /= tmp; + tmp = x3 * x + y3 * y + z3 * z - x1 * x - y1 * y - z1 * z; + x = x1 + x * tmp - x3; + y = y1 + y * tmp - y3; + z = z1 + z * tmp - z3; + tmp = sqrt(x * x + y * y + z * z); + if (tmp > len) + len = tmp; + } + break; + + } + if (len < tolerance) + return (order); + else + return (GLint) (sqrt(len / tolerance) * (order + 2) + 1); +} + +static GLenum +calc_sampling_3D(new_ctrl_type * new_ctrl, GLfloat tolerance, GLint dim, + GLint uorder, GLint vorder, GLint ** ufactors, + GLint ** vfactors) +{ + GLfloat *ctrl; + GLint tmp_factor1, tmp_factor2; + GLint ufactor_cnt, vfactor_cnt; + GLint offset1, offset2, offset3; + GLint i, j; + + ufactor_cnt = new_ctrl->s_bezier_cnt; + vfactor_cnt = new_ctrl->t_bezier_cnt; + if ((*ufactors = (GLint *) malloc(sizeof(GLint) * ufactor_cnt * 3)) + == NULL) { + return GLU_OUT_OF_MEMORY; + } + if ((*vfactors = (GLint *) malloc(sizeof(GLint) * vfactor_cnt * 3)) + == NULL) { + free(*ufactors); + return GLU_OUT_OF_MEMORY; + } + ctrl = new_ctrl->geom_ctrl; + offset1 = new_ctrl->geom_t_stride * vorder; + offset2 = new_ctrl->geom_s_stride * uorder; + for (j = 0; j < vfactor_cnt; j++) { + *(*vfactors + j * 3 + 1) = tmp_factor1 = calc_factor(ctrl, vorder, + j * offset1, dim, + tolerance, dim); + /* loop ufactor_cnt-1 times */ + for (i = 1; i < ufactor_cnt; i++) { + tmp_factor2 = calc_factor(ctrl, vorder, + j * offset1 + i * offset2, dim, tolerance, + dim); + if (tmp_factor2 > tmp_factor1) + tmp_factor1 = tmp_factor2; + } + /* last time for the opposite edge */ + *(*vfactors + j * 3 + 2) = tmp_factor2 = calc_factor(ctrl, vorder, + j * offset1 + + i * offset2 - + new_ctrl-> + geom_s_stride, dim, + tolerance, dim); + if (tmp_factor2 > tmp_factor1) + *(*vfactors + j * 3) = tmp_factor2; + else + *(*vfactors + j * 3) = tmp_factor1; + } + offset3 = new_ctrl->geom_s_stride; + offset2 = new_ctrl->geom_s_stride * uorder; + for (j = 0; j < ufactor_cnt; j++) { + *(*ufactors + j * 3 + 1) = tmp_factor1 = calc_factor(ctrl, uorder, + j * offset2, + offset3, tolerance, + dim); + /* loop vfactor_cnt-1 times */ + for (i = 1; i < vfactor_cnt; i++) { + tmp_factor2 = calc_factor(ctrl, uorder, + j * offset2 + i * offset1, offset3, + tolerance, dim); + if (tmp_factor2 > tmp_factor1) + tmp_factor1 = tmp_factor2; + } + /* last time for the opposite edge */ + *(*ufactors + j * 3 + 2) = tmp_factor2 = calc_factor(ctrl, uorder, + j * offset2 + + i * offset1 - + new_ctrl-> + geom_t_stride, + offset3, tolerance, + dim); + if (tmp_factor2 > tmp_factor1) + *(*ufactors + j * 3) = tmp_factor2; + else + *(*ufactors + j * 3) = tmp_factor1; + } + return GL_NO_ERROR; +} + +static GLenum +calc_sampling_param_3D(new_ctrl_type * new_ctrl, GLfloat tolerance, GLint dim, + GLint uorder, GLint vorder, GLint ** ufactors, + GLint ** vfactors) +{ + GLfloat *ctrl; + GLint tmp_factor1, tmp_factor2; + GLint ufactor_cnt, vfactor_cnt; + GLint offset1, offset2, offset3; + GLint i, j; + + ufactor_cnt = new_ctrl->s_bezier_cnt; + vfactor_cnt = new_ctrl->t_bezier_cnt; + if ((*ufactors = (GLint *) malloc(sizeof(GLint) * ufactor_cnt * 3)) + == NULL) { + return GLU_OUT_OF_MEMORY; + } + if ((*vfactors = (GLint *) malloc(sizeof(GLint) * vfactor_cnt * 3)) + == NULL) { + free(*ufactors); + return GLU_OUT_OF_MEMORY; + } + ctrl = new_ctrl->geom_ctrl; + offset1 = new_ctrl->geom_t_stride * vorder; + offset2 = new_ctrl->geom_s_stride * uorder; + for (j = 0; j < vfactor_cnt; j++) { + *(*vfactors + j * 3 + 1) = tmp_factor1 = + calc_parametric_factor(ctrl, vorder, j * offset1, dim, tolerance, + dim); + /* loop ufactor_cnt-1 times */ + for (i = 1; i < ufactor_cnt; i++) { + tmp_factor2 = calc_parametric_factor(ctrl, vorder, + j * offset1 + i * offset2, dim, + tolerance, dim); + if (tmp_factor2 > tmp_factor1) + tmp_factor1 = tmp_factor2; + } + /* last time for the opposite edge */ + *(*vfactors + j * 3 + 2) = tmp_factor2 = + calc_parametric_factor(ctrl, vorder, + j * offset1 + i * offset2 - + new_ctrl->geom_s_stride, dim, tolerance, dim); + if (tmp_factor2 > tmp_factor1) + *(*vfactors + j * 3) = tmp_factor2; + else + *(*vfactors + j * 3) = tmp_factor1; + } + offset3 = new_ctrl->geom_s_stride; + offset2 = new_ctrl->geom_s_stride * uorder; + for (j = 0; j < ufactor_cnt; j++) { + *(*ufactors + j * 3 + 1) = tmp_factor1 = + calc_parametric_factor(ctrl, uorder, j * offset2, offset3, tolerance, + dim); + /* loop vfactor_cnt-1 times */ + for (i = 1; i < vfactor_cnt; i++) { + tmp_factor2 = calc_parametric_factor(ctrl, uorder, + j * offset2 + i * offset1, + offset3, tolerance, dim); + if (tmp_factor2 > tmp_factor1) + tmp_factor1 = tmp_factor2; + } + /* last time for the opposite edge */ + *(*ufactors + j * 3 + 2) = tmp_factor2 = + calc_parametric_factor(ctrl, uorder, + j * offset2 + i * offset1 - + new_ctrl->geom_t_stride, offset3, tolerance, + dim); + if (tmp_factor2 > tmp_factor1) + *(*ufactors + j * 3) = tmp_factor2; + else + *(*ufactors + j * 3) = tmp_factor1; + } + return GL_NO_ERROR; +} + +static GLenum +calc_sampling_2D(GLfloat * ctrl, GLint cnt, GLint order, + GLfloat tolerance, GLint dim, GLint ** factors) +{ + GLint factor_cnt; + GLint tmp_factor; + GLint offset; + GLint i; + + factor_cnt = cnt / order; + if ((*factors = (GLint *) malloc(sizeof(GLint) * factor_cnt)) == NULL) { + return GLU_OUT_OF_MEMORY; + } + offset = order * dim; + for (i = 0; i < factor_cnt; i++) { + tmp_factor = calc_factor(ctrl, order, i * offset, dim, tolerance, dim); + if (tmp_factor == 0) + (*factors)[i] = 1; + else + (*factors)[i] = tmp_factor; + } + return GL_NO_ERROR; +} + +static void +set_sampling_and_culling(GLUnurbsObj * nobj) +{ + if (nobj->auto_load_matrix == GL_FALSE) { + GLint i; + GLfloat m[4]; + + glPushAttrib((GLbitfield) (GL_VIEWPORT_BIT | GL_TRANSFORM_BIT)); + for (i = 0; i < 4; i++) + m[i] = nobj->sampling_matrices.viewport[i]; + glViewport(m[0], m[1], m[2], m[3]); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadMatrixf(nobj->sampling_matrices.proj); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadMatrixf(nobj->sampling_matrices.model); + } +} + +static void +revert_sampling_and_culling(GLUnurbsObj * nobj) +{ + if (nobj->auto_load_matrix == GL_FALSE) { + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + } +} + +GLenum +glu_do_sampling_3D(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + GLint ** sfactors, GLint ** tfactors) +{ + GLint dim; + GLenum err; + + *sfactors = NULL; + *tfactors = NULL; + dim = nobj->surface.geom.dim; + set_sampling_and_culling(nobj); + if ((err = calc_sampling_3D(new_ctrl, nobj->sampling_tolerance, dim, + nobj->surface.geom.sorder, + nobj->surface.geom.torder, sfactors, + tfactors)) == GLU_ERROR) { + revert_sampling_and_culling(nobj); + call_user_error(nobj, err); + return GLU_ERROR; + } + revert_sampling_and_culling(nobj); + return GLU_NO_ERROR; +} + +GLenum +glu_do_sampling_uv(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + GLint ** sfactors, GLint ** tfactors) +{ + GLint s_cnt, t_cnt, i; + GLint u_steps, v_steps; + + s_cnt = new_ctrl->s_bezier_cnt; + t_cnt = new_ctrl->t_bezier_cnt; + *sfactors = NULL; + *tfactors = NULL; + if ((*sfactors = (GLint *) malloc(sizeof(GLint) * s_cnt * 3)) + == NULL) { + return GLU_OUT_OF_MEMORY; + } + if ((*tfactors = (GLint *) malloc(sizeof(GLint) * t_cnt * 3)) + == NULL) { + free(*sfactors); + return GLU_OUT_OF_MEMORY; + } + u_steps = nobj->u_step; + v_steps = nobj->v_step; + for (i = 0; i < s_cnt; i++) { + *(*sfactors + i * 3) = u_steps; + *(*sfactors + i * 3 + 1) = u_steps; + *(*sfactors + i * 3 + 2) = u_steps; + } + for (i = 0; i < t_cnt; i++) { + *(*tfactors + i * 3) = v_steps; + *(*tfactors + i * 3 + 1) = v_steps; + *(*tfactors + i * 3 + 2) = v_steps; + } + return GLU_NO_ERROR; +} + + +GLenum +glu_do_sampling_param_3D(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + GLint ** sfactors, GLint ** tfactors) +{ + GLint dim; + GLenum err; + + *sfactors = NULL; + *tfactors = NULL; + dim = nobj->surface.geom.dim; + set_sampling_and_culling(nobj); + if ( + (err = + calc_sampling_param_3D(new_ctrl, nobj->parametric_tolerance, dim, + nobj->surface.geom.sorder, + nobj->surface.geom.torder, sfactors, + tfactors)) == GLU_ERROR) { + revert_sampling_and_culling(nobj); + call_user_error(nobj, err); + return GLU_ERROR; + } + revert_sampling_and_culling(nobj); + return GLU_NO_ERROR; +} + + +static GLenum +glu_do_sampling_2D(GLUnurbsObj * nobj, GLfloat * ctrl, GLint cnt, GLint order, + GLint dim, GLint ** factors) +{ + GLenum err; + + set_sampling_and_culling(nobj); + err = calc_sampling_2D(ctrl, cnt, order, nobj->sampling_tolerance, dim, + factors); + revert_sampling_and_culling(nobj); + return err; +} + + +static GLenum +glu_do_sampling_u(GLUnurbsObj * nobj, GLfloat * ctrl, GLint cnt, GLint order, + GLint dim, GLint ** factors) +{ + GLint i; + GLint u_steps; + + cnt /= order; + if ((*factors = (GLint *) malloc(sizeof(GLint) * cnt)) + == NULL) { + return GLU_OUT_OF_MEMORY; + } + u_steps = nobj->u_step; + for (i = 0; i < cnt; i++) + (*factors)[i] = u_steps; + return GLU_NO_ERROR; +} + + +static GLenum +glu_do_sampling_param_2D(GLUnurbsObj * nobj, GLfloat * ctrl, GLint cnt, + GLint order, GLint dim, GLint ** factors) +{ + GLint i; + GLint u_steps; + GLfloat tolerance; + + set_sampling_and_culling(nobj); + tolerance = nobj->parametric_tolerance; + cnt /= order; + if ((*factors = (GLint *) malloc(sizeof(GLint) * cnt)) + == NULL) { + revert_sampling_and_culling(nobj); + return GLU_OUT_OF_MEMORY; + } + u_steps = nobj->u_step; + for (i = 0; i < cnt; i++) { + (*factors)[i] = calc_parametric_factor(ctrl, order, 0, + dim, tolerance, dim); + + } + revert_sampling_and_culling(nobj); + return GLU_NO_ERROR; +} + +GLenum +glu_do_sampling_crv(GLUnurbsObj * nobj, GLfloat * ctrl, GLint cnt, + GLint order, GLint dim, GLint ** factors) +{ + GLenum err; + + *factors = NULL; + switch (nobj->sampling_method) { + case GLU_PATH_LENGTH: + if ((err = glu_do_sampling_2D(nobj, ctrl, cnt, order, dim, factors)) != + GLU_NO_ERROR) { + call_user_error(nobj, err); + return GLU_ERROR; + } + break; + case GLU_DOMAIN_DISTANCE: + if ((err = glu_do_sampling_u(nobj, ctrl, cnt, order, dim, factors)) != + GLU_NO_ERROR) { + call_user_error(nobj, err); + return GLU_ERROR; + } + break; + case GLU_PARAMETRIC_ERROR: + if ( + (err = + glu_do_sampling_param_2D(nobj, ctrl, cnt, order, dim, + factors)) != GLU_NO_ERROR) { + call_user_error(nobj, err); + return GLU_ERROR; + } + break; + default: + abort(); + } + + return GLU_NO_ERROR; +} + +/* TODO - i don't like this culling - this one just tests if at least one */ +/* ctrl point lies within the viewport . Also the point_in_viewport() */ +/* should be included in the fnctions for efficiency reasons */ + +static GLboolean +point_in_viewport(GLfloat * pt, GLint dim) +{ + GLdouble model[16], proj[16]; + GLint viewport[4]; + GLdouble x, y, z, w, winx, winy, winz; + + glGetDoublev(GL_MODELVIEW_MATRIX, model); + glGetDoublev(GL_PROJECTION_MATRIX, proj); + glGetIntegerv(GL_VIEWPORT, viewport); + if (dim == 3) { + x = (GLdouble) pt[0]; + y = (GLdouble) pt[1]; + z = (GLdouble) pt[2]; + gluProject(x, y, z, model, proj, viewport, &winx, &winy, &winz); + } + else { + w = (GLdouble) pt[3]; + x = (GLdouble) pt[0] / w; + y = (GLdouble) pt[1] / w; + z = (GLdouble) pt[2] / w; + gluProject(x, y, z, model, proj, viewport, &winx, &winy, &winz); + } + if ((GLint) winx >= viewport[0] && (GLint) winx < viewport[2] && + (GLint) winy >= viewport[1] && (GLint) winy < viewport[3]) + return GL_TRUE; + return GL_FALSE; +} + +GLboolean +fine_culling_test_3D(GLUnurbsObj * nobj, GLfloat * pts, GLint s_cnt, + GLint t_cnt, GLint s_stride, GLint t_stride, GLint dim) +{ + GLint i, j; + + if (nobj->culling == GL_FALSE) + return GL_FALSE; + set_sampling_and_culling(nobj); + + if (dim == 3) { + for (i = 0; i < s_cnt; i++) + for (j = 0; j < t_cnt; j++) + if (point_in_viewport(pts + i * s_stride + j * t_stride, dim)) { + revert_sampling_and_culling(nobj); + return GL_FALSE; + } + } + else { + for (i = 0; i < s_cnt; i++) + for (j = 0; j < t_cnt; j++) + if (point_in_viewport(pts + i * s_stride + j * t_stride, dim)) { + revert_sampling_and_culling(nobj); + return GL_FALSE; + } + } + revert_sampling_and_culling(nobj); + return GL_TRUE; +} + +/*GLboolean +fine_culling_test_3D(GLUnurbsObj *nobj,GLfloat *pts,GLint s_cnt,GLint t_cnt, + GLint s_stride,GLint t_stride, GLint dim) +{ + GLint visible_cnt; + GLfloat feedback_buffer[5]; + GLsizei buffer_size; + GLint i,j; + + if(nobj->culling==GL_FALSE) + return GL_FALSE; + buffer_size=5; + set_sampling_and_culling(nobj); + + glFeedbackBuffer(buffer_size,GL_2D,feedback_buffer); + glRenderMode(GL_FEEDBACK); + if(dim==3) + { + for(i=0;iculling == GL_FALSE) + return GL_FALSE; + set_sampling_and_culling(nobj); + + if (dim == 3) { + for (i = 0; i < cnt; i++) + if (point_in_viewport(pts + i * stride, dim)) { + revert_sampling_and_culling(nobj); + return GL_FALSE; + } + } + else { + for (i = 0; i < cnt; i++) + if (point_in_viewport(pts + i * stride, dim)) { + revert_sampling_and_culling(nobj); + return GL_FALSE; + } + } + revert_sampling_and_culling(nobj); + return GL_TRUE; +} + +/*GLboolean +fine_culling_test_2D(GLUnurbsObj *nobj,GLfloat *pts,GLint cnt, + GLint stride, GLint dim) +{ + GLint visible_cnt; + GLfloat feedback_buffer[5]; + GLsizei buffer_size; + GLint i; + + if(nobj->culling==GL_FALSE) + return GL_FALSE; + buffer_size=5; + set_sampling_and_culling(nobj); + + glFeedbackBuffer(buffer_size,GL_2D,feedback_buffer); + glRenderMode(GL_FEEDBACK); + glBegin(GL_LINE_LOOP); + if(dim==3) + { + for(i=0;i +#include +#include "gluP.h" +#include "nurbs.h" +#endif + + +static int +get_curve_dim(GLenum type) +{ + switch (type) { + case GL_MAP1_VERTEX_3: + return 3; + case GL_MAP1_VERTEX_4: + return 4; + case GL_MAP1_INDEX: + return 1; + case GL_MAP1_COLOR_4: + return 4; + case GL_MAP1_NORMAL: + return 3; + case GL_MAP1_TEXTURE_COORD_1: + return 1; + case GL_MAP1_TEXTURE_COORD_2: + return 2; + case GL_MAP1_TEXTURE_COORD_3: + return 3; + case GL_MAP1_TEXTURE_COORD_4: + return 4; + default: + abort(); /* TODO: is this OK? */ + } + return 0; /*never get here */ +} + +static GLenum +test_nurbs_curve(GLUnurbsObj * nobj, curve_attribs * attribs) +{ + GLenum err; + GLint tmp_int; + + if (attribs->order < 0) { + call_user_error(nobj, GLU_INVALID_VALUE); + return GLU_ERROR; + } + glGetIntegerv(GL_MAX_EVAL_ORDER, &tmp_int); + if (attribs->order > tmp_int || attribs->order < 2) { + call_user_error(nobj, GLU_NURBS_ERROR1); + return GLU_ERROR; + } + if (attribs->knot_count < attribs->order + 2) { + call_user_error(nobj, GLU_NURBS_ERROR2); + return GLU_ERROR; + } + if (attribs->stride < 0) { + call_user_error(nobj, GLU_NURBS_ERROR34); + return GLU_ERROR; + } + if (attribs->knot == NULL || attribs->ctrlarray == NULL) { + call_user_error(nobj, GLU_NURBS_ERROR36); + return GLU_ERROR; + } + if ((err = test_knot(attribs->knot_count, attribs->knot, attribs->order)) + != GLU_NO_ERROR) { + call_user_error(nobj, err); + return GLU_ERROR; + } + return GLU_NO_ERROR; +} + +static GLenum +test_nurbs_curves(GLUnurbsObj * nobj) +{ + /* test the geometric data */ + if (test_nurbs_curve(nobj, &(nobj->curve.geom)) != GLU_NO_ERROR) + return GLU_ERROR; + /* now test the attributive data */ + /* color */ + if (nobj->curve.color.type != GLU_INVALID_ENUM) + if (test_nurbs_curve(nobj, &(nobj->curve.color)) != GLU_NO_ERROR) + return GLU_ERROR; + /* normal */ + if (nobj->curve.normal.type != GLU_INVALID_ENUM) + if (test_nurbs_curve(nobj, &(nobj->curve.normal)) != GLU_NO_ERROR) + return GLU_ERROR; + /* texture */ + if (nobj->curve.texture.type != GLU_INVALID_ENUM) + if (test_nurbs_curve(nobj, &(nobj->curve.texture)) != GLU_NO_ERROR) + return GLU_ERROR; + return GLU_NO_ERROR; +} + +/* prepare the knot information structures */ +static GLenum +fill_knot_structures(GLUnurbsObj * nobj, knot_str_type * geom_knot, + knot_str_type * color_knot, knot_str_type * normal_knot, + knot_str_type * texture_knot) +{ + GLint order; + GLfloat *knot; + GLint nknots; + GLint t_min, t_max; + + geom_knot->unified_knot = NULL; + knot = geom_knot->knot = nobj->curve.geom.knot; + nknots = geom_knot->nknots = nobj->curve.geom.knot_count; + order = geom_knot->order = nobj->curve.geom.order; + geom_knot->delta_nknots = 0; + t_min = geom_knot->t_min = order - 1; + t_max = geom_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + geom_knot->open_at_begin = GL_TRUE; + } + else + geom_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + geom_knot->open_at_end = GL_TRUE; + } + else + geom_knot->open_at_end = GL_FALSE; + if (nobj->curve.color.type != GLU_INVALID_ENUM) { + color_knot->unified_knot = (GLfloat *) 1; + knot = color_knot->knot = nobj->curve.color.knot; + nknots = color_knot->nknots = nobj->curve.color.knot_count; + order = color_knot->order = nobj->curve.color.order; + color_knot->delta_nknots = 0; + t_min = color_knot->t_min = order - 1; + t_max = color_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + color_knot->open_at_begin = GL_TRUE; + } + else + color_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + color_knot->open_at_end = GL_TRUE; + } + else + color_knot->open_at_end = GL_FALSE; + } + else + color_knot->unified_knot = NULL; + if (nobj->curve.normal.type != GLU_INVALID_ENUM) { + normal_knot->unified_knot = (GLfloat *) 1; + knot = normal_knot->knot = nobj->curve.normal.knot; + nknots = normal_knot->nknots = nobj->curve.normal.knot_count; + order = normal_knot->order = nobj->curve.normal.order; + normal_knot->delta_nknots = 0; + t_min = normal_knot->t_min = order - 1; + t_max = normal_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + normal_knot->open_at_begin = GL_TRUE; + } + else + normal_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + normal_knot->open_at_end = GL_TRUE; + } + else + normal_knot->open_at_end = GL_FALSE; + } + else + normal_knot->unified_knot = NULL; + if (nobj->curve.texture.type != GLU_INVALID_ENUM) { + texture_knot->unified_knot = (GLfloat *) 1; + knot = texture_knot->knot = nobj->curve.texture.knot; + nknots = texture_knot->nknots = nobj->curve.texture.knot_count; + order = texture_knot->order = nobj->curve.texture.order; + texture_knot->delta_nknots = 0; + t_min = texture_knot->t_min = order - 1; + t_max = texture_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + texture_knot->open_at_begin = GL_TRUE; + } + else + texture_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + texture_knot->open_at_end = GL_TRUE; + } + else + texture_knot->open_at_end = GL_FALSE; + } + else + texture_knot->unified_knot = NULL; + return GLU_NO_ERROR; +} + +/* covert the NURBS curve into a series of adjacent Bezier curves */ +static GLenum +convert_curve(knot_str_type * the_knot, curve_attribs * attrib, + GLfloat ** new_ctrl, GLint * ncontrol) +{ + GLenum err; + + if ((err = explode_knot(the_knot)) != GLU_NO_ERROR) { + if (the_knot->unified_knot) { + free(the_knot->unified_knot); + the_knot->unified_knot = NULL; + } + return err; + } + if (the_knot->unified_knot) { + free(the_knot->unified_knot); + the_knot->unified_knot = NULL; + } + if ((err = calc_alphas(the_knot)) != GLU_NO_ERROR) { + free(the_knot->new_knot); + return err; + } + free(the_knot->new_knot); + if ((err = calc_new_ctrl_pts(attrib->ctrlarray, attrib->stride, the_knot, + attrib->dim, new_ctrl, ncontrol)) + != GLU_NO_ERROR) { + free(the_knot->alpha); + return err; + } + free(the_knot->alpha); + return GLU_NO_ERROR; +} + +/* covert curves - geometry and possible attribute ones into equivalent */ +/* sequence of adjacent Bezier curves */ +static GLenum +convert_curves(GLUnurbsObj * nobj, GLfloat ** new_geom_ctrl, + GLint * ncontrol, GLfloat ** new_color_ctrl, + GLfloat ** new_normal_ctrl, GLfloat ** new_texture_ctrl) +{ + knot_str_type geom_knot, color_knot, normal_knot, texture_knot; + GLint junk; + GLenum err; + + *new_color_ctrl = *new_normal_ctrl = *new_texture_ctrl = NULL; + + if (fill_knot_structures(nobj, &geom_knot, &color_knot, &normal_knot, + &texture_knot) != GLU_NO_ERROR) + return GLU_ERROR; + + /* unify knots - all knots should have the same number of working */ + /* ranges */ + if ( + (err = + select_knot_working_range(nobj, &geom_knot, &color_knot, &normal_knot, + &texture_knot)) != GLU_NO_ERROR) { + return err; + } + /* convert the geometry curve */ + nobj->curve.geom.dim = get_curve_dim(nobj->curve.geom.type); + if ((err = convert_curve(&geom_knot, &(nobj->curve.geom), new_geom_ctrl, + ncontrol)) != GLU_NO_ERROR) { + free_unified_knots(&geom_knot, &color_knot, &normal_knot, + &texture_knot); + call_user_error(nobj, err); + return err; + } + /* if additional attributive curves are given convert them as well */ + if (color_knot.unified_knot) { + nobj->curve.color.dim = get_curve_dim(nobj->curve.color.type); + if ((err = convert_curve(&color_knot, &(nobj->curve.color), + new_color_ctrl, &junk)) != GLU_NO_ERROR) { + free_unified_knots(&geom_knot, &color_knot, &normal_knot, + &texture_knot); + free(*new_geom_ctrl); + call_user_error(nobj, err); + return err; + } + } + if (normal_knot.unified_knot) { + nobj->curve.normal.dim = get_curve_dim(nobj->curve.normal.type); + if ((err = convert_curve(&normal_knot, &(nobj->curve.normal), + new_normal_ctrl, &junk)) != GLU_NO_ERROR) { + free_unified_knots(&geom_knot, &color_knot, &normal_knot, + &texture_knot); + free(*new_geom_ctrl); + if (*new_color_ctrl) + free(*new_color_ctrl); + call_user_error(nobj, err); + return err; + } + } + if (texture_knot.unified_knot) { + nobj->curve.texture.dim = get_curve_dim(nobj->curve.texture.type); + if ((err = convert_curve(&texture_knot, &(nobj->curve.texture), + new_texture_ctrl, &junk)) != GLU_NO_ERROR) { + free_unified_knots(&geom_knot, &color_knot, &normal_knot, + &texture_knot); + free(*new_geom_ctrl); + if (*new_color_ctrl) + free(*new_color_ctrl); + if (*new_normal_ctrl) + free(*new_normal_ctrl); + call_user_error(nobj, err); + return err; + } + } + return GLU_NO_ERROR; +} + +/* main NURBS curve procedure */ +void +do_nurbs_curve(GLUnurbsObj * nobj) +{ + GLint geom_order, color_order = 0, normal_order = 0, texture_order = 0; + GLenum geom_type; + GLint n_ctrl; + GLfloat *new_geom_ctrl, *new_color_ctrl, *new_normal_ctrl, + *new_texture_ctrl; + GLfloat *geom_ctrl = 0, *color_ctrl = 0, *normal_ctrl = 0, *texture_ctrl = 0; + GLint *factors; + GLint i, j; + GLint geom_dim, color_dim = 0, normal_dim = 0, texture_dim = 0; + + /* test the user supplied data */ + if (test_nurbs_curves(nobj) != GLU_NO_ERROR) + return; + + if (convert_curves(nobj, &new_geom_ctrl, &n_ctrl, &new_color_ctrl, + &new_normal_ctrl, &new_texture_ctrl) != GLU_NO_ERROR) + return; + + geom_order = nobj->curve.geom.order; + geom_type = nobj->curve.geom.type; + geom_dim = nobj->curve.geom.dim; + + if (glu_do_sampling_crv(nobj, new_geom_ctrl, n_ctrl, geom_order, geom_dim, + &factors) != GLU_NO_ERROR) { + free(new_geom_ctrl); + if (new_color_ctrl) + free(new_color_ctrl); + if (new_normal_ctrl) + free(new_normal_ctrl); + if (new_texture_ctrl) + free(new_texture_ctrl); + return; + } + glEnable(geom_type); + if (new_color_ctrl) { + glEnable(nobj->curve.color.type); + color_dim = nobj->curve.color.dim; + color_ctrl = new_color_ctrl; + color_order = nobj->curve.color.order; + } + if (new_normal_ctrl) { + glEnable(nobj->curve.normal.type); + normal_dim = nobj->curve.normal.dim; + normal_ctrl = new_normal_ctrl; + normal_order = nobj->curve.normal.order; + } + if (new_texture_ctrl) { + glEnable(nobj->curve.texture.type); + texture_dim = nobj->curve.texture.dim; + texture_ctrl = new_texture_ctrl; + texture_order = nobj->curve.texture.order; + } + for (i = 0, j = 0, geom_ctrl = new_geom_ctrl; + i < n_ctrl; i += geom_order, j++, geom_ctrl += geom_order * geom_dim) { + if (fine_culling_test_2D + (nobj, geom_ctrl, geom_order, geom_dim, geom_dim)) { + color_ctrl += color_order * color_dim; + normal_ctrl += normal_order * normal_dim; + texture_ctrl += texture_order * texture_dim; + continue; + } + glMap1f(geom_type, 0.0, 1.0, geom_dim, geom_order, geom_ctrl); + if (new_color_ctrl) { + glMap1f(nobj->curve.color.type, 0.0, 1.0, color_dim, + color_order, color_ctrl); + color_ctrl += color_order * color_dim; + } + if (new_normal_ctrl) { + glMap1f(nobj->curve.normal.type, 0.0, 1.0, normal_dim, + normal_order, normal_ctrl); + normal_ctrl += normal_order * normal_dim; + } + if (new_texture_ctrl) { + glMap1f(nobj->curve.texture.type, 0.0, 1.0, texture_dim, + texture_order, texture_ctrl); + texture_ctrl += texture_order * texture_dim; + } + glMapGrid1f(factors[j], 0.0, 1.0); + glEvalMesh1(GL_LINE, 0, factors[j]); + } + free(new_geom_ctrl); + free(factors); + if (new_color_ctrl) + free(new_color_ctrl); + if (new_normal_ctrl) + free(new_normal_ctrl); + if (new_texture_ctrl) + free(new_texture_ctrl); +} --- mesa-7.2.orig/src/glu/mesa/polytest.c +++ mesa-7.2/src/glu/mesa/polytest.c @@ -0,0 +1,937 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "gluP.h" +#include "tess.h" +#endif + + + +static GLenum store_polygon_as_contour(GLUtriangulatorObj *); +static void free_current_polygon(tess_polygon *); +static void prepare_projection_info(GLUtriangulatorObj *); +static GLdouble twice_the_polygon_area(tess_vertex *, tess_vertex *); +static GLenum verify_edge_vertex_intersections(GLUtriangulatorObj *); +void tess_find_contour_hierarchies(GLUtriangulatorObj *); +static GLenum test_for_overlapping_contours(GLUtriangulatorObj *); +static GLenum contours_overlap(tess_contour *, tess_polygon *); +static GLenum is_contour_contained_in(tess_contour *, tess_contour *); +static void add_new_exterior(GLUtriangulatorObj *, tess_contour *); +static void add_new_interior(GLUtriangulatorObj *, tess_contour *, + tess_contour *); +static void add_interior_with_hierarchy_check(GLUtriangulatorObj *, + tess_contour *, tess_contour *); +static void reverse_hierarchy_and_add_exterior(GLUtriangulatorObj *, + tess_contour *, + tess_contour *); +static GLboolean point_in_polygon(tess_contour *, GLdouble, GLdouble); +static void shift_interior_to_exterior(GLUtriangulatorObj *, tess_contour *); +static void add_exterior_with_check(GLUtriangulatorObj *, tess_contour *, + tess_contour *); +static GLenum cut_out_hole(GLUtriangulatorObj *, tess_contour *, + tess_contour *); +static GLenum merge_hole_with_contour(GLUtriangulatorObj *, + tess_contour *, tess_contour *, + tess_vertex *, tess_vertex *); + +static GLenum +find_normal(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *va, *vb, *vc; + GLdouble A, B, C; + GLdouble A0, A1, A2, B0, B1, B2; + + va = polygon->vertices; + vb = va->next; + A0 = vb->location[0] - va->location[0]; + A1 = vb->location[1] - va->location[1]; + A2 = vb->location[2] - va->location[2]; + for (vc = vb->next; vc != va; vc = vc->next) { + B0 = vc->location[0] - va->location[0]; + B1 = vc->location[1] - va->location[1]; + B2 = vc->location[2] - va->location[2]; + A = A1 * B2 - A2 * B1; + B = A2 * B0 - A0 * B2; + C = A0 * B1 - A1 * B0; + if (fabs(A) > EPSILON || fabs(B) > EPSILON || fabs(C) > EPSILON) { + polygon->A = A; + polygon->B = B; + polygon->C = C; + polygon->D = + -A * va->location[0] - B * va->location[1] - C * va->location[2]; + return GLU_NO_ERROR; + } + } + tess_call_user_error(tobj, GLU_TESS_ERROR7); + return GLU_ERROR; +} + +void +tess_test_polygon(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + + /* any vertices defined? */ + if (polygon->vertex_cnt < 3) { + free_current_polygon(polygon); + return; + } + /* wrap pointers */ + polygon->last_vertex->next = polygon->vertices; + polygon->vertices->previous = polygon->last_vertex; + /* determine the normal */ + if (find_normal(tobj) == GLU_ERROR) + return; + /* compare the normals of previously defined contours and this one */ + /* first contour define ? */ + if (tobj->contours == NULL) { + tobj->A = polygon->A; + tobj->B = polygon->B; + tobj->C = polygon->C; + tobj->D = polygon->D; + /* determine the best projection to use */ + if (fabs(polygon->A) > fabs(polygon->B)) + if (fabs(polygon->A) > fabs(polygon->C)) + tobj->projection = OYZ; + else + tobj->projection = OXY; + else if (fabs(polygon->B) > fabs(polygon->C)) + tobj->projection = OXZ; + else + tobj->projection = OXY; + } + else { + GLdouble a[3], b[3]; + tess_vertex *vertex = polygon->vertices; + + a[0] = tobj->A; + a[1] = tobj->B; + a[2] = tobj->C; + b[0] = polygon->A; + b[1] = polygon->B; + b[2] = polygon->C; + + /* compare the normals */ + if (fabs(a[1] * b[2] - a[2] * b[1]) > EPSILON || + fabs(a[2] * b[0] - a[0] * b[2]) > EPSILON || + fabs(a[0] * b[1] - a[1] * b[0]) > EPSILON) { + /* not coplanar */ + tess_call_user_error(tobj, GLU_TESS_ERROR9); + return; + } + /* the normals are parallel - test for plane equation */ + if (fabs(a[0] * vertex->location[0] + a[1] * vertex->location[1] + + a[2] * vertex->location[2] + tobj->D) > EPSILON) { + /* not the same plane */ + tess_call_user_error(tobj, GLU_TESS_ERROR9); + return; + } + } + prepare_projection_info(tobj); + if (verify_edge_vertex_intersections(tobj) == GLU_ERROR) + return; + if (test_for_overlapping_contours(tobj) == GLU_ERROR) + return; + if (store_polygon_as_contour(tobj) == GLU_ERROR) + return; +} + +static GLenum +test_for_overlapping_contours(GLUtriangulatorObj * tobj) +{ + tess_contour *contour; + tess_polygon *polygon; + + polygon = tobj->current_polygon; + for (contour = tobj->contours; contour != NULL; contour = contour->next) + if (contours_overlap(contour, polygon) != GLU_NO_ERROR) { + tess_call_user_error(tobj, GLU_TESS_ERROR5); + return GLU_ERROR; + } + return GLU_NO_ERROR; +} + +static GLenum +store_polygon_as_contour(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_contour *contour = tobj->contours; + + /* the first contour defined */ + if (contour == NULL) { + if ((contour = (tess_contour *) malloc(sizeof(tess_contour))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + free_current_polygon(polygon); + return GLU_ERROR; + } + tobj->contours = tobj->last_contour = contour; + contour->next = contour->previous = NULL; + } + else { + if ((contour = (tess_contour *) malloc(sizeof(tess_contour))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + free_current_polygon(polygon); + return GLU_ERROR; + } + contour->previous = tobj->last_contour; + tobj->last_contour->next = contour; + tobj->last_contour = contour; + contour->next = NULL; + } + /* mark all vertices in new contour as not special */ + /* and all are boundary edges */ + { + tess_vertex *vertex; + GLuint vertex_cnt, i; + + for (vertex = polygon->vertices, i = 0, vertex_cnt = + polygon->vertex_cnt; i < vertex_cnt; vertex = vertex->next, i++) { + vertex->shadow_vertex = NULL; + vertex->edge_flag = GL_TRUE; + } + } + contour->vertex_cnt = polygon->vertex_cnt; + contour->area = polygon->area; + contour->orientation = polygon->orientation; + contour->type = GLU_UNKNOWN; + contour->vertices = polygon->vertices; + contour->last_vertex = polygon->last_vertex; + polygon->vertices = polygon->last_vertex = NULL; + polygon->vertex_cnt = 0; + ++(tobj->contour_cnt); + return GLU_NO_ERROR; +} + +static void +free_current_polygon(tess_polygon * polygon) +{ + tess_vertex *vertex, *vertex_tmp; + GLuint i; + + /* free current_polygon structures */ + for (vertex = polygon->vertices, i = 0; i < polygon->vertex_cnt; i++) { + vertex_tmp = vertex->next; + free(vertex); + vertex = vertex_tmp; + } + polygon->vertices = polygon->last_vertex = NULL; + polygon->vertex_cnt = 0; +} + +static void +prepare_projection_info(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *vertex, *last_vertex_ptr; + GLdouble area; + + last_vertex_ptr = polygon->last_vertex; + switch (tobj->projection) { + case OXY: + for (vertex = polygon->vertices; vertex != last_vertex_ptr; + vertex = vertex->next) { + vertex->x = vertex->location[0]; + vertex->y = vertex->location[1]; + } + last_vertex_ptr->x = last_vertex_ptr->location[0]; + last_vertex_ptr->y = last_vertex_ptr->location[1]; + break; + case OXZ: + for (vertex = polygon->vertices; vertex != last_vertex_ptr; + vertex = vertex->next) { + vertex->x = vertex->location[0]; + vertex->y = vertex->location[2]; + } + last_vertex_ptr->x = last_vertex_ptr->location[0]; + last_vertex_ptr->y = last_vertex_ptr->location[2]; + break; + case OYZ: + for (vertex = polygon->vertices; vertex != last_vertex_ptr; + vertex = vertex->next) { + vertex->x = vertex->location[1]; + vertex->y = vertex->location[2]; + } + last_vertex_ptr->x = last_vertex_ptr->location[1]; + last_vertex_ptr->y = last_vertex_ptr->location[2]; + break; + } + area = twice_the_polygon_area(polygon->vertices, polygon->last_vertex); + if (area >= 0.0) { + polygon->orientation = GLU_CCW; + polygon->area = area; + } + else { + polygon->orientation = GLU_CW; + polygon->area = -area; + } +} + +static GLdouble +twice_the_polygon_area(tess_vertex * vertex, tess_vertex * last_vertex) +{ + tess_vertex *next; + GLdouble area, x, y; + + area = 0.0; + x = vertex->x; + y = vertex->y; + vertex = vertex->next; + for (; vertex != last_vertex; vertex = vertex->next) { + next = vertex->next; + area += + (vertex->x - x) * (next->y - y) - (vertex->y - y) * (next->x - x); + } + return area; +} + +/* test if edges ab and cd intersect */ +/* if not return GLU_NO_ERROR, else if cross return GLU_TESS_ERROR8, */ +/* else if adjacent return GLU_TESS_ERROR4 */ +static GLenum +edge_edge_intersect(tess_vertex * a, + tess_vertex * b, tess_vertex * c, tess_vertex * d) +{ + GLdouble denom, r, s; + GLdouble xba, ydc, yba, xdc, yac, xac; + + xba = b->x - a->x; + yba = b->y - a->y; + xdc = d->x - c->x; + ydc = d->y - c->y; + xac = a->x - c->x; + yac = a->y - c->y; + denom = xba * ydc - yba * xdc; + r = yac * xdc - xac * ydc; + /* parallel? */ + if (fabs(denom) < EPSILON) { + if (fabs(r) < EPSILON) { + /* colinear */ + if (fabs(xba) < EPSILON) { + /* compare the Y coordinate */ + if (yba > 0.0) { + if ( + (fabs(a->y - c->y) < EPSILON + && fabs(c->y - b->y) < EPSILON) + || (fabs(a->y - d->y) < EPSILON + && fabs(d->y - b->y) < + EPSILON)) return GLU_TESS_ERROR4; + + } + else { + if ( + (fabs(b->y - c->y) < EPSILON + && fabs(c->y - a->y) < EPSILON) + || (fabs(b->y - d->y) < EPSILON + && fabs(d->y - a->y) < + EPSILON)) return GLU_TESS_ERROR4; + } + } + else { + /* compare the X coordinate */ + if (xba > 0.0) { + if ( + (fabs(a->x - c->x) < EPSILON + && fabs(c->x - b->x) < EPSILON) + || (fabs(a->x - d->x) < EPSILON + && fabs(d->x - b->x) < + EPSILON)) return GLU_TESS_ERROR4; + } + else { + if ( + (fabs(b->x - c->x) < EPSILON + && fabs(c->x - a->x) < EPSILON) + || (fabs(b->x - d->x) < EPSILON + && fabs(d->x - a->x) < + EPSILON)) return GLU_TESS_ERROR4; + } + } + } + return GLU_NO_ERROR; + } + r /= denom; + s = (yac * xba - xac * yba) / denom; + /* test if one vertex lies on other edge */ + if (((fabs(r) < EPSILON || (r < 1.0 + EPSILON && r > 1.0 - EPSILON)) && + s > -EPSILON && s < 1.0 + EPSILON) || + ((fabs(s) < EPSILON || (s < 1.0 + EPSILON && s > 1.0 - EPSILON)) && + r > -EPSILON && r < 1.0 + EPSILON)) { + return GLU_TESS_ERROR4; + } + /* test for crossing */ + if (r > -EPSILON && r < 1.0 + EPSILON && s > -EPSILON && s < 1.0 + EPSILON) { + return GLU_TESS_ERROR8; + } + return GLU_NO_ERROR; +} + +static GLenum +verify_edge_vertex_intersections(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *vertex1, *last_vertex, *vertex2; + GLenum test; + + last_vertex = polygon->last_vertex; + vertex1 = last_vertex; + for (vertex2 = vertex1->next->next; + vertex2->next != last_vertex; vertex2 = vertex2->next) { + test = edge_edge_intersect(vertex1, vertex1->next, vertex2, + vertex2->next); + if (test != GLU_NO_ERROR) { + tess_call_user_error(tobj, test); + return GLU_ERROR; + } + } + for (vertex1 = polygon->vertices; + vertex1->next->next != last_vertex; vertex1 = vertex1->next) { + for (vertex2 = vertex1->next->next; + vertex2 != last_vertex; vertex2 = vertex2->next) { + test = edge_edge_intersect(vertex1, vertex1->next, vertex2, + vertex2->next); + if (test != GLU_NO_ERROR) { + tess_call_user_error(tobj, test); + return GLU_ERROR; + } + } + } + return GLU_NO_ERROR; +} + +static int +#ifdef WIN32 + __cdecl +#endif +area_compare(const void *a, const void *b) +{ + GLdouble area1, area2; + + area1 = (*((tess_contour **) a))->area; + area2 = (*((tess_contour **) b))->area; + if (area1 < area2) + return 1; + if (area1 > area2) + return -1; + return 0; +} + +void +tess_find_contour_hierarchies(GLUtriangulatorObj * tobj) +{ + tess_contour **contours; /* dinamic array of pointers */ + tess_contour *tmp_contour_ptr = tobj->contours; + GLuint cnt, i; + GLenum result; + GLboolean hierarchy_changed; + + /* any contours? */ + if (tobj->contour_cnt < 2) { + tobj->contours->type = GLU_EXTERIOR; + return; + } + if ((contours = (tess_contour **) + malloc(sizeof(tess_contour *) * (tobj->contour_cnt))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + for (tmp_contour_ptr = tobj->contours, cnt = 0; + tmp_contour_ptr != NULL; tmp_contour_ptr = tmp_contour_ptr->next) + contours[cnt++] = tmp_contour_ptr; + /* now sort the contours in decreasing area size order */ + qsort((void *) contours, (size_t) cnt, (size_t) sizeof(tess_contour *), + area_compare); + /* we leave just the first contour - remove others from list */ + tobj->contours = contours[0]; + tobj->contours->next = tobj->contours->previous = NULL; + tobj->last_contour = tobj->contours; + tobj->contour_cnt = 1; + /* first contour is the one with greatest area */ + /* must be EXTERIOR */ + tobj->contours->type = GLU_EXTERIOR; + tmp_contour_ptr = tobj->contours; + /* now we play! */ + for (i = 1; i < cnt; i++) { + hierarchy_changed = GL_FALSE; + for (tmp_contour_ptr = tobj->contours; + tmp_contour_ptr != NULL; tmp_contour_ptr = tmp_contour_ptr->next) { + if (tmp_contour_ptr->type == GLU_EXTERIOR) { + /* check if contour completely contained in EXTERIOR */ + result = is_contour_contained_in(tmp_contour_ptr, contours[i]); + switch (result) { + case GLU_INTERIOR: + /* now we have to check if contour is inside interiors */ + /* or not */ + /* any interiors? */ + if (tmp_contour_ptr->next != NULL && + tmp_contour_ptr->next->type == GLU_INTERIOR) { + /* for all interior, check if inside any of them */ + /* if not inside any of interiors, its another */ + /* interior */ + /* or it may contain some interiors, then change */ + /* the contained interiors to exterior ones */ + add_interior_with_hierarchy_check(tobj, + tmp_contour_ptr, + contours[i]); + } + else { + /* not in interior, add as new interior contour */ + add_new_interior(tobj, tmp_contour_ptr, contours[i]); + } + hierarchy_changed = GL_TRUE; + break; + case GLU_EXTERIOR: + /* ooops, the marked as EXTERIOR (contours[i]) is */ + /* actually an interior of tmp_contour_ptr */ + /* reverse the local hierarchy */ + reverse_hierarchy_and_add_exterior(tobj, tmp_contour_ptr, + contours[i]); + hierarchy_changed = GL_TRUE; + break; + case GLU_NO_ERROR: + break; + default: + abort(); + } + } + if (hierarchy_changed) + break; /* break from for loop */ + } + if (hierarchy_changed == GL_FALSE) { + /* disjoint with all contours, add to contour list */ + add_new_exterior(tobj, contours[i]); + } + } + free(contours); +} + +/* returns GLU_INTERIOR if inner is completey enclosed within outer */ +/* returns GLU_EXTERIOR if outer is completely enclosed within inner */ +/* returns GLU_NO_ERROR if contours are disjoint */ +static GLenum +is_contour_contained_in(tess_contour * outer, tess_contour * inner) +{ + GLenum relation_flag; + + /* set relation_flag to relation of containment of first inner vertex */ + /* regarding outer contour */ + if (point_in_polygon(outer, inner->vertices->x, inner->vertices->y)) + relation_flag = GLU_INTERIOR; + else + relation_flag = GLU_EXTERIOR; + if (relation_flag == GLU_INTERIOR) + return GLU_INTERIOR; + if (point_in_polygon(inner, outer->vertices->x, outer->vertices->y)) + return GLU_EXTERIOR; + return GLU_NO_ERROR; +} + +static GLboolean +point_in_polygon(tess_contour * contour, GLdouble x, GLdouble y) +{ + tess_vertex *v1, *v2; + GLuint i, vertex_cnt; + GLdouble xp1, yp1, xp2, yp2; + GLboolean tst; + + tst = GL_FALSE; + v1 = contour->vertices; + v2 = contour->vertices->previous; + for (i = 0, vertex_cnt = contour->vertex_cnt; i < vertex_cnt; i++) { + xp1 = v1->x; + yp1 = v1->y; + xp2 = v2->x; + yp2 = v2->y; + if ((((yp1 <= y) && (y < yp2)) || ((yp2 <= y) && (y < yp1))) && + (x < (xp2 - xp1) * (y - yp1) / (yp2 - yp1) + xp1)) + tst = (tst == GL_FALSE ? GL_TRUE : GL_FALSE); + v2 = v1; + v1 = v1->next; + } + return tst; +} + +static GLenum +contours_overlap(tess_contour * contour, tess_polygon * polygon) +{ + tess_vertex *vertex1, *vertex2; + GLuint vertex1_cnt, vertex2_cnt, i, j; + GLenum test; + + vertex1 = contour->vertices; + vertex2 = polygon->vertices; + vertex1_cnt = contour->vertex_cnt; + vertex2_cnt = polygon->vertex_cnt; + for (i = 0; i < vertex1_cnt; vertex1 = vertex1->next, i++) { + for (j = 0; j < vertex2_cnt; vertex2 = vertex2->next, j++) + if ((test = edge_edge_intersect(vertex1, vertex1->next, vertex2, + vertex2->next)) != GLU_NO_ERROR) + return test; + } + return GLU_NO_ERROR; +} + +static void +add_new_exterior(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + contour->type = GLU_EXTERIOR; + contour->next = NULL; + contour->previous = tobj->last_contour; + tobj->last_contour->next = contour; + tobj->last_contour = contour; +} + +static void +add_new_interior(GLUtriangulatorObj * tobj, + tess_contour * outer, tess_contour * contour) +{ + contour->type = GLU_INTERIOR; + contour->next = outer->next; + contour->previous = outer; + if (outer->next != NULL) + outer->next->previous = contour; + outer->next = contour; + if (tobj->last_contour == outer) + tobj->last_contour = contour; +} + +static void +add_interior_with_hierarchy_check(GLUtriangulatorObj * tobj, + tess_contour * outer, + tess_contour * contour) +{ + tess_contour *ptr; + + /* for all interiors of outer check if they are interior of contour */ + /* if so, change that interior to exterior and move it of of the */ + /* interior sequence */ + if (outer->next != NULL && outer->next->type == GLU_INTERIOR) { + GLenum test; + + for (ptr = outer->next; ptr != NULL && ptr->type == GLU_INTERIOR; + ptr = ptr->next) { + test = is_contour_contained_in(ptr, contour); + switch (test) { + case GLU_INTERIOR: + /* contour is contained in one of the interiors */ + /* check if possibly contained in other exteriors */ + /* move ptr to first EXTERIOR */ + for (; ptr != NULL && ptr->type == GLU_INTERIOR; ptr = ptr->next); + if (ptr == NULL) + /* another exterior */ + add_new_exterior(tobj, contour); + else + add_exterior_with_check(tobj, ptr, contour); + return; + case GLU_EXTERIOR: + /* one of the interiors is contained in the contour */ + /* change it to EXTERIOR, and shift it away from the */ + /* interior sequence */ + shift_interior_to_exterior(tobj, ptr); + break; + case GLU_NO_ERROR: + /* disjoint */ + break; + default: + abort(); + } + } + } + /* add contour to the interior sequence */ + add_new_interior(tobj, outer, contour); +} + +static void +reverse_hierarchy_and_add_exterior(GLUtriangulatorObj * tobj, + tess_contour * outer, + tess_contour * contour) +{ + tess_contour *ptr; + + /* reverse INTERIORS to EXTERIORS */ + /* any INTERIORS? */ + if (outer->next != NULL && outer->next->type == GLU_INTERIOR) + for (ptr = outer->next; ptr != NULL && ptr->type == GLU_INTERIOR; + ptr = ptr->next) ptr->type = GLU_EXTERIOR; + /* the outer now becomes inner */ + outer->type = GLU_INTERIOR; + /* contour is the EXTERIOR */ + contour->next = outer; + if (tobj->contours == outer) { + /* first contour beeing reversed */ + contour->previous = NULL; + tobj->contours = contour; + } + else { + outer->previous->next = contour; + contour->previous = outer->previous; + } + outer->previous = contour; +} + +static void +shift_interior_to_exterior(GLUtriangulatorObj * tobj, tess_contour * contour) +{ + contour->previous->next = contour->next; + if (contour->next != NULL) + contour->next->previous = contour->previous; + else + tobj->last_contour = contour->previous; +} + +static void +add_exterior_with_check(GLUtriangulatorObj * tobj, + tess_contour * outer, tess_contour * contour) +{ + GLenum test; + + /* this contour might be interior to further exteriors - check */ + /* if not, just add as a new exterior */ + for (; outer != NULL && outer->type == GLU_EXTERIOR; outer = outer->next) { + test = is_contour_contained_in(outer, contour); + switch (test) { + case GLU_INTERIOR: + /* now we have to check if contour is inside interiors */ + /* or not */ + /* any interiors? */ + if (outer->next != NULL && outer->next->type == GLU_INTERIOR) { + /* for all interior, check if inside any of them */ + /* if not inside any of interiors, its another */ + /* interior */ + /* or it may contain some interiors, then change */ + /* the contained interiors to exterior ones */ + add_interior_with_hierarchy_check(tobj, outer, contour); + } + else { + /* not in interior, add as new interior contour */ + add_new_interior(tobj, outer, contour); + } + return; + case GLU_NO_ERROR: + /* disjoint */ + break; + default: + abort(); + } + } + /* add contour to the exterior sequence */ + add_new_exterior(tobj, contour); +} + +void +tess_handle_holes(GLUtriangulatorObj * tobj) +{ + tess_contour *contour, *hole; + GLenum exterior_orientation; + + /* verify hole orientation */ + for (contour = tobj->contours; contour != NULL;) { + exterior_orientation = contour->orientation; + for (contour = contour->next; + contour != NULL && contour->type == GLU_INTERIOR; + contour = contour->next) { + if (contour->orientation == exterior_orientation) { + tess_call_user_error(tobj, GLU_TESS_ERROR5); + return; + } + } + } + /* now cut-out holes */ + for (contour = tobj->contours; contour != NULL;) { + hole = contour->next; + while (hole != NULL && hole->type == GLU_INTERIOR) { + if (cut_out_hole(tobj, contour, hole) == GLU_ERROR) + return; + hole = contour->next; + } + contour = contour->next; + } +} + +static GLenum +cut_out_hole(GLUtriangulatorObj * tobj, + tess_contour * contour, tess_contour * hole) +{ + tess_contour *tmp_hole; + tess_vertex *v1, *v2, *tmp_vertex; + GLuint vertex1_cnt, vertex2_cnt, tmp_vertex_cnt; + GLuint i, j, k; + GLenum test = 0; + + /* find an edge connecting contour and hole not intersecting any other */ + /* edge belonging to either the contour or any of the other holes */ + for (v1 = contour->vertices, vertex1_cnt = contour->vertex_cnt, i = 0; + i < vertex1_cnt; i++, v1 = v1->next) { + for (v2 = hole->vertices, vertex2_cnt = hole->vertex_cnt, j = 0; + j < vertex2_cnt; j++, v2 = v2->next) { + /* does edge (v1,v2) intersect any edge of contour */ + for (tmp_vertex = contour->vertices, tmp_vertex_cnt = + contour->vertex_cnt, k = 0; k < tmp_vertex_cnt; + tmp_vertex = tmp_vertex->next, k++) { + /* skip edge tests for edges directly connected */ + if (v1 == tmp_vertex || v1 == tmp_vertex->next) + continue; + test = edge_edge_intersect(v1, v2, tmp_vertex, tmp_vertex->next); + if (test != GLU_NO_ERROR) + break; + } + if (test == GLU_NO_ERROR) { + /* does edge (v1,v2) intersect any edge of hole */ + for (tmp_vertex = hole->vertices, + tmp_vertex_cnt = hole->vertex_cnt, k = 0; + k < tmp_vertex_cnt; tmp_vertex = tmp_vertex->next, k++) { + /* skip edge tests for edges directly connected */ + if (v2 == tmp_vertex || v2 == tmp_vertex->next) + continue; + test = + edge_edge_intersect(v1, v2, tmp_vertex, tmp_vertex->next); + if (test != GLU_NO_ERROR) + break; + } + if (test == GLU_NO_ERROR) { + /* does edge (v1,v2) intersect any other hole? */ + for (tmp_hole = hole->next; + tmp_hole != NULL && tmp_hole->type == GLU_INTERIOR; + tmp_hole = tmp_hole->next) { + /* does edge (v1,v2) intersect any edge of hole */ + for (tmp_vertex = tmp_hole->vertices, + tmp_vertex_cnt = tmp_hole->vertex_cnt, k = 0; + k < tmp_vertex_cnt; tmp_vertex = tmp_vertex->next, k++) { + test = edge_edge_intersect(v1, v2, tmp_vertex, + tmp_vertex->next); + if (test != GLU_NO_ERROR) + break; + } + if (test != GLU_NO_ERROR) + break; + } + } + } + if (test == GLU_NO_ERROR) { + /* edge (v1,v2) is good for eliminating the hole */ + if (merge_hole_with_contour(tobj, contour, hole, v1, v2) + == GLU_NO_ERROR) + return GLU_NO_ERROR; + else + return GLU_ERROR; + } + } + } + /* other holes are blocking all possible connections of hole */ + /* with contour, we shift this hole as the last hole and retry */ + for (tmp_hole = hole; + tmp_hole != NULL && tmp_hole->type == GLU_INTERIOR; + tmp_hole = tmp_hole->next); + contour->next = hole->next; + hole->next->previous = contour; + if (tmp_hole == NULL) { + /* last EXTERIOR contour, shift hole as last contour */ + hole->next = NULL; + hole->previous = tobj->last_contour; + tobj->last_contour->next = hole; + tobj->last_contour = hole; + } + else { + tmp_hole->previous->next = hole; + hole->previous = tmp_hole->previous; + tmp_hole->previous = hole; + hole->next = tmp_hole; + } + hole = contour->next; + /* try once again - recurse */ + return cut_out_hole(tobj, contour, hole); +} + +static GLenum +merge_hole_with_contour(GLUtriangulatorObj * tobj, + tess_contour * contour, + tess_contour * hole, + tess_vertex * v1, tess_vertex * v2) +{ + tess_vertex *v1_new, *v2_new; + + /* make copies of v1 and v2, place them respectively after their originals */ + if ((v1_new = (tess_vertex *) malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + if ((v2_new = (tess_vertex *) malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + v1_new->edge_flag = GL_TRUE; + v1_new->data = v1->data; + v1_new->location[0] = v1->location[0]; + v1_new->location[1] = v1->location[1]; + v1_new->location[2] = v1->location[2]; + v1_new->x = v1->x; + v1_new->y = v1->y; + v1_new->shadow_vertex = v1; + v1->shadow_vertex = v1_new; + v1_new->next = v1->next; + v1_new->previous = v1; + v1->next->previous = v1_new; + v1->next = v1_new; + v2_new->edge_flag = GL_TRUE; + v2_new->data = v2->data; + v2_new->location[0] = v2->location[0]; + v2_new->location[1] = v2->location[1]; + v2_new->location[2] = v2->location[2]; + v2_new->x = v2->x; + v2_new->y = v2->y; + v2_new->shadow_vertex = v2; + v2->shadow_vertex = v2_new; + v2_new->next = v2->next; + v2_new->previous = v2; + v2->next->previous = v2_new; + v2->next = v2_new; + /* link together the two lists */ + v1->next = v2_new; + v2_new->previous = v1; + v2->next = v1_new; + v1_new->previous = v2; + /* update the vertex count of the contour */ + contour->vertex_cnt += hole->vertex_cnt + 2; + /* remove the INTERIOR contour */ + contour->next = hole->next; + if (hole->next != NULL) + hole->next->previous = contour; + free(hole); + /* update tobj structure */ + --(tobj->contour_cnt); + if (contour->last_vertex == v1) + contour->last_vertex = v1_new; + /* mark two vertices with edge_flag */ + v2->edge_flag = GL_FALSE; + v1->edge_flag = GL_FALSE; + return GLU_NO_ERROR; +} --- mesa-7.2.orig/src/glu/mesa/README2 +++ mesa-7.2/src/glu/mesa/README2 @@ -0,0 +1,43 @@ +The current NURBS implementation has no trimming facilities yet. + +The code is not well commented. + +1) Normal calculus fails for special cases of NURBS (independent + of the NURBS modules) + Those cases arise when for u or v, some control points + for a fixed value of that parameter form the same point. + Imagine a Bezier patch degenerated into a "triangle". + + v ^ 0,1,2 order=3 + | * + | + | 3* 4* 5* + | + | 6* 7* 8* + | + | + +------------------------> u + + The calculus of du derivative at triple point (0,1 and 2) will fail. + As a result, the normal vector will be 0. + The eval2.c code has to be changed to handle the above situation. + +2) Adjacent NURBS surfaces ("sharing" the same control points along + the "joining" edge) will be sampled with the same factor. + This prevents the formation of "cracks". + When the control polygon of the "shared" edge is not the same, + cracks might appear. + +The sampling tolerance is sometimes not respected! +A NURBS object is broken into Bezier curves/surfaces. If one of such +Bezier objects has a local high curvature with other portions of it +relatively flat then the high curvature part will be sampled more dense that +its flatter regions. +The flat regions might be tesselated into quads having sides of length +greater than the current sampling tolernace setting. +I believe such behaviour is acceptable, though not along the concept of +sampling tolerance. + +February 20, 1996. + +Bogdan. --- mesa-7.2.orig/src/glu/mesa/Makefile.m32 +++ mesa-7.2/src/glu/mesa/Makefile.m32 @@ -0,0 +1,63 @@ +# Makefile for GLU for GCC-2.95.2/Mingw32 contributed by +# Paul Garceau + +# Mesa 3-D graphics library +# Version: 3.3 +# Copyright (C) 1995-1999 Brian Paul +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +MESA_MAJOR=3 +MESA_MINOR=3 +MESA_TINY=0 +VERSION=$(MESA_MAJOR).$(MESA_MINOR) + +CFLAGS = -I. -DWIN32 -D__WIN32__ -D_WINDOWS \ + -O2 -funroll-loops \ + -fexpensive-optimizations -fomit-frame-pointer -ffast-math \ + -malign-loops=2 -malign-jumps=2 -malign-functions=2 \ + -mwindows +CC = gcc +MAKELIB = ar ru +GLU_LIB = libGLU.a + + +##### MACROS ##### + +VPATH = RCS + +INCDIR = ../include +LIBDIR = ../lib + +SOURCES = glu.c mipmap.c nurbs.c nurbscrv.c nurbssrf.c nurbsutl.c \ + polytest.c project.c quadric.c tess.c tesselat.c + +OBJECTS = $(SOURCES:.c=.o) + + + +##### RULES ##### + +.c.o: + $(CC) -c -I$(INCDIR) $(CFLAGS) $< + + + +##### TARGETS ##### + +# Make the library: +$(LIBDIR)/$(GLU_LIB): $(OBJECTS) + $(MAKELIB) $(GLU_LIB) $(MAJOR) $(MINOR) $(TINY) $(OBJECTS) \ No newline at end of file --- mesa-7.2.orig/src/glu/mesa/gluP.h +++ mesa-7.2/src/glu/mesa/gluP.h @@ -0,0 +1,97 @@ +/* + * Mesa 3-D graphics library + * Version: 6.3 + * Copyright (C) 1995-2004 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file allows the GLU code to be compiled either with the Mesa + * headers or with the real OpenGL headers. + */ + + +#ifndef GLUP_H +#define GLUP_H + + +#include +#include +#include + + +#if defined(_WIN32) && !defined(__WIN32__) +# define __WIN32__ +#endif + +#if !defined(OPENSTEP) && (defined(__WIN32__) || defined(__CYGWIN__)) +# pragma warning( disable : 4068 ) /* unknown pragma */ +# pragma warning( disable : 4710 ) /* function 'foo' not inlined */ +# pragma warning( disable : 4711 ) /* function 'foo' selected for automatic inline expansion */ +# pragma warning( disable : 4127 ) /* conditional expression is constant */ +# if defined(MESA_MINWARN) +# pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */ +# pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */ +# pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */ +# pragma warning( disable : 4550 ) /* 'function' undefined; assuming extern returning int */ +# pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */ +# endif +# define GLCALLBACK __stdcall +# if defined(__CYGWIN__) +# define GLCALLBACKPCAST * +# else +# define GLCALLBACKPCAST __stdcall * +# endif +#else +/* non-Windows compilation */ +# define GLCALLBACK +# define GLCALLBACKPCAST * +#endif /* WIN32 / CYGWIN bracket */ + +/* compatability guard so we don't need to change client code */ + +#if defined(_WIN32) && !defined(_WINDEF_) && !defined(_GNU_H_WINDOWS32_BASE) && !defined(OPENSTEP) +# define CALLBACK GLCALLBACK +#endif + + + +#ifndef GLU_TESS_ERROR9 + /* If we're using the real OpenGL header files... */ +# define GLU_TESS_ERROR9 100159 +#endif + + +#define GLU_NO_ERROR GL_NO_ERROR + + +/* for Sun: */ +#ifdef SUNOS4 +#define MEMCPY( DST, SRC, BYTES) \ + memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) ) +#else +#define MEMCPY( DST, SRC, BYTES) \ + memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) ) +#endif + + +#ifndef NULL +# define NULL 0 +#endif + + +#endif --- mesa-7.2.orig/src/glu/mesa/Makefile.ugl +++ mesa-7.2/src/glu/mesa/Makefile.ugl @@ -0,0 +1,96 @@ +# Mesa 3-D graphics library +# Version: 3.5 +# +# Copyright (C) 2001 Wind River Systems, Inc + +# The MIT License +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# Makefile for GLU library + +##### MACROS ##### +GLU_MAJOR = 1 +GLU_MINOR = 3 +GLU_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) + +##### RULES ##### + +include ../rules.windml + +GLU_SOURCES = \ + glu.c \ + mipmap.c \ + nurbs.c \ + nurbscrv.c \ + nurbssrf.c \ + nurbsutl.c \ + polytest.c \ + project.c \ + quadric.c \ + tess.c \ + tesselat.c \ + ../src/windml/tornado/torMesaGLUInit.c + +GLU_OBJECTS = $(GLU_SOURCES:.c=.o) +GLU_OBJNAME = $(MESA_LIBDIR)/objMesaGLU.o + +SOURCES = $(GLU_SOURCES) + +##### TARGETS ##### + +all: depend.$(CPU)$(TOOL) $(GLU_OBJNAME) + +# Make the GLU library +$(GLU_OBJNAME): $(GLU_OBJECTS) +# $(LD) -r $(GLU_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(GLU_OBJECTS) -o $(GLU_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(GLU_OBJNAME) +# $(AR) rus $(VX_LIBNAME) $(GLU_OBJNAME) + +depend.$(CPU)$(TOOL): +ifeq ($(WIND_HOST_TYPE),x86-win32) + @ $(RM) $@ + @ $(ECHO) Creating depend.$(CPU)$(TOOL) +ifneq ($(SOURCES),) + @ for %f in ($(SOURCES)) do \ + $(CC) -MM $(CFLAGS) %f >>$@ +endif +else +Makefile + @ $(RM) $@ + @ $(ECHO) "Creating depend.$(CPU)$(TOOL)" +ifneq ($(SOURCES),) + @ for FILE in $(filter-out $(NODEPENDOBJS), $(SOURCES)); \ + do \ + $(CC) -MM $(CFLAGS) $$FILE \ + | $(TCL) $(BIN_DIR)/depend.tcl $(TGT_DIR) >>$@; \ + done +endif +endif + +.PHONY = clean + +clean: +# $(AR) d $(MESA_LIBNAME) $(GLU_OBJNAME) +# $(AR) d $(VX_LIBNAME) $(GLU_OBJNAME) + $(RM) $(GLU_OBJNAME) + $(RM) $(GLU_OBJECTS) + $(RM) depend.$(CPU)$(TOOL) + +include depend.$(CPU)$(TOOL) --- mesa-7.2.orig/src/glu/mesa/nurbs.c +++ mesa-7.2/src/glu/mesa/nurbs.c @@ -0,0 +1,628 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "gluP.h" +#include "nurbs.h" +#endif + + +void +call_user_error(GLUnurbsObj * nobj, GLenum error) +{ + nobj->error = error; + if (nobj->error_callback != NULL) { + (*(nobj->error_callback)) (error); + } + else { + printf("NURBS error %d %s\n", error, (char *) gluErrorString(error)); + } +} + + + +GLUnurbsObj *GLAPIENTRY +gluNewNurbsRenderer(void) +{ + GLUnurbsObj *n; + GLfloat tmp_viewport[4]; + GLint i, j; + + n = (GLUnurbsObj *) malloc(sizeof(GLUnurbsObj)); + if (n) { + /* init */ + n->culling = GL_FALSE; + n->nurbs_type = GLU_NURBS_NONE; + n->error = GLU_NO_ERROR; + n->error_callback = NULL; + n->auto_load_matrix = GL_TRUE; + n->sampling_tolerance = 50.0; + n->parametric_tolerance = 0.5; + n->u_step = n->v_step = 100; + n->sampling_method = GLU_PATH_LENGTH; + n->display_mode = GLU_FILL; + /* in case the user doesn't supply the sampling matrices */ + /* set projection and modelview to identity */ + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + if (i == j) { + n->sampling_matrices.model[i * 4 + j] = 1.0; + n->sampling_matrices.proj[i * 4 + j] = 1.0; + } + else { + n->sampling_matrices.model[i * 4 + j] = 0.0; + n->sampling_matrices.proj[i * 4 + j] = 0.0; + } + /* and set the viewport sampling matrix to current ciewport */ + glGetFloatv(GL_VIEWPORT, tmp_viewport); + for (i = 0; i < 4; i++) + n->sampling_matrices.viewport[i] = tmp_viewport[i]; + n->trim = NULL; + } + return n; +} + + + +void GLAPIENTRY +gluDeleteNurbsRenderer(GLUnurbsObj * nobj) +{ + if (nobj) { + free(nobj); + } +} + + + +void GLAPIENTRY +gluLoadSamplingMatrices(GLUnurbsObj * nobj, + const GLfloat modelMatrix[16], + const GLfloat projMatrix[16], const GLint viewport[4]) +{ + GLint i; + + for (i = 0; i < 16; i++) { + nobj->sampling_matrices.model[i] = modelMatrix[i]; + nobj->sampling_matrices.proj[i] = projMatrix[i]; + } + for (i = 0; i < 4; i++) + nobj->sampling_matrices.viewport[i] = viewport[i]; +} + + +void GLAPIENTRY +gluNurbsProperty(GLUnurbsObj * nobj, GLenum property, GLfloat value) +{ + GLenum val; + + switch (property) { + case GLU_SAMPLING_TOLERANCE: + if (value <= 0.0) { + call_user_error(nobj, GLU_INVALID_VALUE); + return; + } + nobj->sampling_tolerance = value; + break; + case GLU_PARAMETRIC_TOLERANCE: + if (value <= 0.0) { + call_user_error(nobj, GLU_INVALID_VALUE); + return; + } + nobj->parametric_tolerance = value; + break; + case GLU_U_STEP: + if (value <= 0.0) { + call_user_error(nobj, GLU_INVALID_VALUE); + return; + } + nobj->u_step = (GLint) value; + break; + case GLU_V_STEP: + if (value <= 0.0) { + call_user_error(nobj, GLU_INVALID_VALUE); + return; + } + nobj->v_step = (GLint) value; + break; + case GLU_SAMPLING_METHOD: + val = (GLenum) value; + if (val != GLU_PATH_LENGTH && val != GLU_PARAMETRIC_ERROR + && val != GLU_DOMAIN_DISTANCE) { + call_user_error(nobj, GLU_INVALID_ENUM); + return; + } + nobj->sampling_method = val; + break; + case GLU_DISPLAY_MODE: + val = (GLenum) value; + if (val != GLU_FILL && val != GLU_OUTLINE_POLYGON + && val != GLU_OUTLINE_PATCH) { + call_user_error(nobj, GLU_INVALID_ENUM); + return; + } + if (nobj->nurbs_type == GLU_NURBS_CURVE) { + call_user_error(nobj, GLU_NURBS_ERROR26); + return; + } + nobj->display_mode = val; + if (val == GLU_OUTLINE_PATCH) + fprintf(stderr, + "NURBS, for the moment, can display only in POLYGON mode\n"); + break; + case GLU_CULLING: + val = (GLenum) value; + if (val != GL_TRUE && val != GL_FALSE) { + call_user_error(nobj, GLU_INVALID_ENUM); + return; + } + nobj->culling = (GLboolean) value; + break; + case GLU_AUTO_LOAD_MATRIX: + val = (GLenum) value; + if (val != GL_TRUE && val != GL_FALSE) { + call_user_error(nobj, GLU_INVALID_ENUM); + return; + } + nobj->auto_load_matrix = (GLboolean) value; + break; + default: + call_user_error(nobj, GLU_NURBS_ERROR26); + } +} + + +void GLAPIENTRY +gluGetNurbsProperty(GLUnurbsObj * nobj, GLenum property, GLfloat * value) +{ + switch (property) { + case GLU_SAMPLING_TOLERANCE: + *value = nobj->sampling_tolerance; + break; + case GLU_DISPLAY_MODE: + *value = (GLfloat) (GLint) nobj->display_mode; + break; + case GLU_CULLING: + *value = nobj->culling ? 1.0 : 0.0; + break; + case GLU_AUTO_LOAD_MATRIX: + *value = nobj->auto_load_matrix ? 1.0 : 0.0; + break; + default: + call_user_error(nobj, GLU_INVALID_ENUM); + } +} + + + +void GLAPIENTRY +gluBeginCurve(GLUnurbsObj * nobj) +{ + if (nobj->nurbs_type == GLU_NURBS_CURVE) { + call_user_error(nobj, GLU_NURBS_ERROR6); + return; + } + nobj->nurbs_type = GLU_NURBS_CURVE; + nobj->curve.geom.type = GLU_INVALID_ENUM; + nobj->curve.color.type = GLU_INVALID_ENUM; + nobj->curve.texture.type = GLU_INVALID_ENUM; + nobj->curve.normal.type = GLU_INVALID_ENUM; +} + + +void GLAPIENTRY +gluEndCurve(GLUnurbsObj * nobj) +{ + if (nobj->nurbs_type == GLU_NURBS_NONE) { + call_user_error(nobj, GLU_NURBS_ERROR7); + return; + } + if (nobj->curve.geom.type == GLU_INVALID_ENUM) { + call_user_error(nobj, GLU_NURBS_ERROR8); + nobj->nurbs_type = GLU_NURBS_NONE; + return; + } + glPushAttrib((GLbitfield) (GL_EVAL_BIT | GL_ENABLE_BIT)); + glDisable(GL_MAP1_VERTEX_3); + glDisable(GL_MAP1_VERTEX_4); + glDisable(GL_MAP1_INDEX); + glDisable(GL_MAP1_COLOR_4); + glDisable(GL_MAP1_NORMAL); + glDisable(GL_MAP1_TEXTURE_COORD_1); + glDisable(GL_MAP1_TEXTURE_COORD_2); + glDisable(GL_MAP1_TEXTURE_COORD_3); + glDisable(GL_MAP1_TEXTURE_COORD_4); + glDisable(GL_MAP2_VERTEX_3); + glDisable(GL_MAP2_VERTEX_4); + glDisable(GL_MAP2_INDEX); + glDisable(GL_MAP2_COLOR_4); + glDisable(GL_MAP2_NORMAL); + glDisable(GL_MAP2_TEXTURE_COORD_1); + glDisable(GL_MAP2_TEXTURE_COORD_2); + glDisable(GL_MAP2_TEXTURE_COORD_3); + glDisable(GL_MAP2_TEXTURE_COORD_4); + do_nurbs_curve(nobj); + glPopAttrib(); + nobj->nurbs_type = GLU_NURBS_NONE; +} + + +void GLAPIENTRY +gluNurbsCurve(GLUnurbsObj * nobj, GLint nknots, GLfloat * knot, + GLint stride, GLfloat * ctlarray, GLint order, GLenum type) +{ + if (nobj->nurbs_type == GLU_NURBS_TRIM) { +#if 0 +/* TODO: NOT IMPLEMENTED YET */ + nurbs_trim *ptr1; + trim_list *ptr2; + + if (type != GLU_MAP1_TRIM_2 && type != GLU_MAP1_TRIM_3) { + call_user_error(nobj, GLU_NURBS_ERROR14); + return; + } + for (ptr1 = nobj->trim; ptr1->next; ptr1 = ptr1->next); + if (ptr1->trim_loop) { + for (ptr2 = ptr1->trim_loop; ptr2->next; ptr2 = ptr2->next); + if ((ptr2->next = (trim_list *) malloc(sizeof(trim_list))) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return; + } + ptr2 = ptr2->next; + } + else { + if ((ptr2 = (trim_list *) malloc(sizeof(trim_list))) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return; + } + ptr1->trim_loop = ptr2; + } + ptr2->trim_type = GLU_TRIM_NURBS; + ptr2->curve.nurbs_curve.knot_count = nknots; + ptr2->curve.nurbs_curve.knot = knot; + ptr2->curve.nurbs_curve.stride = stride; + ptr2->curve.nurbs_curve.ctrlarray = ctlarray; + ptr2->curve.nurbs_curve.order = order; + ptr2->curve.nurbs_curve.dim = (type == GLU_MAP1_TRIM_2 ? 2 : 3); + ptr2->curve.nurbs_curve.type = type; + ptr2->next = NULL; +#endif + } + else { + if (type == GLU_MAP1_TRIM_2 || type == GLU_MAP1_TRIM_3) { + call_user_error(nobj, GLU_NURBS_ERROR22); + return; + } + if (nobj->nurbs_type != GLU_NURBS_CURVE) { + call_user_error(nobj, GLU_NURBS_ERROR10); + return; + } + switch (type) { + case GL_MAP1_VERTEX_3: + case GL_MAP1_VERTEX_4: + if (nobj->curve.geom.type != GLU_INVALID_ENUM) { + call_user_error(nobj, GLU_NURBS_ERROR8); + return; + } + nobj->curve.geom.type = type; + nobj->curve.geom.knot_count = nknots; + nobj->curve.geom.knot = knot; + nobj->curve.geom.stride = stride; + nobj->curve.geom.ctrlarray = ctlarray; + nobj->curve.geom.order = order; + break; + case GL_MAP1_INDEX: + case GL_MAP1_COLOR_4: + nobj->curve.color.type = type; + nobj->curve.color.knot_count = nknots; + nobj->curve.color.knot = knot; + nobj->curve.color.stride = stride; + nobj->curve.color.ctrlarray = ctlarray; + nobj->curve.color.order = order; + break; + case GL_MAP1_NORMAL: + nobj->curve.normal.type = type; + nobj->curve.normal.knot_count = nknots; + nobj->curve.normal.knot = knot; + nobj->curve.normal.stride = stride; + nobj->curve.normal.ctrlarray = ctlarray; + nobj->curve.normal.order = order; + break; + case GL_MAP1_TEXTURE_COORD_1: + case GL_MAP1_TEXTURE_COORD_2: + case GL_MAP1_TEXTURE_COORD_3: + case GL_MAP1_TEXTURE_COORD_4: + nobj->curve.texture.type = type; + nobj->curve.texture.knot_count = nknots; + nobj->curve.texture.knot = knot; + nobj->curve.texture.stride = stride; + nobj->curve.texture.ctrlarray = ctlarray; + nobj->curve.texture.order = order; + break; + default: + call_user_error(nobj, GLU_INVALID_ENUM); + } + } +} + + +void GLAPIENTRY +gluBeginSurface(GLUnurbsObj * nobj) +{ + switch (nobj->nurbs_type) { + case GLU_NURBS_NONE: + nobj->nurbs_type = GLU_NURBS_SURFACE; + nobj->surface.geom.type = GLU_INVALID_ENUM; + nobj->surface.color.type = GLU_INVALID_ENUM; + nobj->surface.texture.type = GLU_INVALID_ENUM; + nobj->surface.normal.type = GLU_INVALID_ENUM; + break; + case GLU_NURBS_TRIM: + call_user_error(nobj, GLU_NURBS_ERROR16); + break; + case GLU_NURBS_SURFACE: + case GLU_NURBS_NO_TRIM: + case GLU_NURBS_TRIM_DONE: + call_user_error(nobj, GLU_NURBS_ERROR27); + break; + case GLU_NURBS_CURVE: + call_user_error(nobj, GLU_NURBS_ERROR6); + break; + } +} + + +void GLAPIENTRY +gluEndSurface(GLUnurbsObj * nobj) +{ + switch (nobj->nurbs_type) { + case GLU_NURBS_NONE: + call_user_error(nobj, GLU_NURBS_ERROR13); + break; + case GLU_NURBS_TRIM: + call_user_error(nobj, GLU_NURBS_ERROR12); + break; + case GLU_NURBS_TRIM_DONE: +/* if(nobj->trim->trim_loop==NULL) + { + call_user_error(nobj,GLU_NURBS_ERROR18); + return; + }*/ + /* no break - fallthrough */ + case GLU_NURBS_NO_TRIM: + glPushAttrib((GLbitfield) + (GL_EVAL_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT)); + glDisable(GL_MAP2_VERTEX_3); + glDisable(GL_MAP2_VERTEX_4); + glDisable(GL_MAP2_INDEX); + glDisable(GL_MAP2_COLOR_4); + glDisable(GL_MAP2_NORMAL); + glDisable(GL_MAP2_TEXTURE_COORD_1); + glDisable(GL_MAP2_TEXTURE_COORD_2); + glDisable(GL_MAP2_TEXTURE_COORD_3); + glDisable(GL_MAP2_TEXTURE_COORD_4); +/* glDisable(GL_MAP1_VERTEX_3); + glDisable(GL_MAP1_VERTEX_4); + glDisable(GL_MAP1_INDEX); + glDisable(GL_MAP1_COLOR_4); + glDisable(GL_MAP1_NORMAL); + glDisable(GL_MAP1_TEXTURE_COORD_1); + glDisable(GL_MAP1_TEXTURE_COORD_2); + glDisable(GL_MAP1_TEXTURE_COORD_3); + glDisable(GL_MAP1_TEXTURE_COORD_4);*/ + do_nurbs_surface(nobj); + glPopAttrib(); + break; + default: + call_user_error(nobj, GLU_NURBS_ERROR8); + } + nobj->nurbs_type = GLU_NURBS_NONE; +} + + +void GLAPIENTRY +gluNurbsSurface(GLUnurbsObj * nobj, + GLint sknot_count, GLfloat * sknot, + GLint tknot_count, GLfloat * tknot, + GLint s_stride, GLint t_stride, + GLfloat * ctrlarray, GLint sorder, GLint torder, GLenum type) +{ + if (nobj->nurbs_type == GLU_NURBS_NO_TRIM + || nobj->nurbs_type == GLU_NURBS_TRIM + || nobj->nurbs_type == GLU_NURBS_TRIM_DONE) { + if (type == GL_MAP2_VERTEX_3 || type == GL_MAP2_VERTEX_4) { + call_user_error(nobj, GLU_NURBS_ERROR8); + return; + } + } + else if (nobj->nurbs_type != GLU_NURBS_SURFACE) { + call_user_error(nobj, GLU_NURBS_ERROR11); + return; + } + switch (type) { + case GL_MAP2_VERTEX_3: + case GL_MAP2_VERTEX_4: + nobj->surface.geom.sknot_count = sknot_count; + nobj->surface.geom.sknot = sknot; + nobj->surface.geom.tknot_count = tknot_count; + nobj->surface.geom.tknot = tknot; + nobj->surface.geom.s_stride = s_stride; + nobj->surface.geom.t_stride = t_stride; + nobj->surface.geom.ctrlarray = ctrlarray; + nobj->surface.geom.sorder = sorder; + nobj->surface.geom.torder = torder; + nobj->surface.geom.type = type; + nobj->nurbs_type = GLU_NURBS_NO_TRIM; + break; + case GL_MAP2_INDEX: + case GL_MAP2_COLOR_4: + nobj->surface.color.sknot_count = sknot_count; + nobj->surface.color.sknot = sknot; + nobj->surface.color.tknot_count = tknot_count; + nobj->surface.color.tknot = tknot; + nobj->surface.color.s_stride = s_stride; + nobj->surface.color.t_stride = t_stride; + nobj->surface.color.ctrlarray = ctrlarray; + nobj->surface.color.sorder = sorder; + nobj->surface.color.torder = torder; + nobj->surface.color.type = type; + break; + case GL_MAP2_NORMAL: + nobj->surface.normal.sknot_count = sknot_count; + nobj->surface.normal.sknot = sknot; + nobj->surface.normal.tknot_count = tknot_count; + nobj->surface.normal.tknot = tknot; + nobj->surface.normal.s_stride = s_stride; + nobj->surface.normal.t_stride = t_stride; + nobj->surface.normal.ctrlarray = ctrlarray; + nobj->surface.normal.sorder = sorder; + nobj->surface.normal.torder = torder; + nobj->surface.normal.type = type; + break; + case GL_MAP2_TEXTURE_COORD_1: + case GL_MAP2_TEXTURE_COORD_2: + case GL_MAP2_TEXTURE_COORD_3: + case GL_MAP2_TEXTURE_COORD_4: + nobj->surface.texture.sknot_count = sknot_count; + nobj->surface.texture.sknot = sknot; + nobj->surface.texture.tknot_count = tknot_count; + nobj->surface.texture.tknot = tknot; + nobj->surface.texture.s_stride = s_stride; + nobj->surface.texture.t_stride = t_stride; + nobj->surface.texture.ctrlarray = ctrlarray; + nobj->surface.texture.sorder = sorder; + nobj->surface.texture.torder = torder; + nobj->surface.texture.type = type; + break; + default: + call_user_error(nobj, GLU_INVALID_ENUM); + } +} + + +void GLAPIENTRY +gluNurbsCallback(GLUnurbsObj * nobj, GLenum which, void (GLCALLBACK * fn) ()) +{ + nobj->error_callback = (void (GLCALLBACKPCAST) (GLenum)) fn; + + if (which != GLU_ERROR) + call_user_error(nobj, GLU_INVALID_ENUM); +} + +void GLAPIENTRY +gluBeginTrim(GLUnurbsObj * nobj) +{ +#if 0 + nurbs_trim *ptr; +#endif + + if (nobj->nurbs_type != GLU_NURBS_TRIM_DONE) + if (nobj->nurbs_type != GLU_NURBS_NO_TRIM) { + call_user_error(nobj, GLU_NURBS_ERROR15); + return; + } + nobj->nurbs_type = GLU_NURBS_TRIM; + fprintf(stderr, "NURBS - trimming not supported yet\n"); +#if 0 + if ((ptr = (nurbs_trim *) malloc(sizeof(nurbs_trim))) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return; + } + if (nobj->trim) { + nurbs_trim *tmp_ptr; + + for (tmp_ptr = nobj->trim; tmp_ptr->next; tmp_ptr = tmp_ptr->next); + tmp_ptr->next = ptr; + } + else + nobj->trim = ptr; + ptr->trim_loop = NULL; + ptr->segments = NULL; + ptr->next = NULL; +#endif +} + +void GLAPIENTRY +gluPwlCurve(GLUnurbsObj * nobj, GLint count, GLfloat * array, GLint stride, + GLenum type) +{ +#if 0 + nurbs_trim *ptr1; + trim_list *ptr2; +#endif + if (nobj->nurbs_type == GLU_NURBS_CURVE) { + call_user_error(nobj, GLU_NURBS_ERROR9); + return; + } + if (nobj->nurbs_type == GLU_NURBS_NONE) { + call_user_error(nobj, GLU_NURBS_ERROR19); + return; + } + if (type != GLU_MAP1_TRIM_2 && type != GLU_MAP1_TRIM_3) { + call_user_error(nobj, GLU_NURBS_ERROR14); + return; + } +#if 0 + for (ptr1 = nobj->trim; ptr1->next; ptr1 = ptr1->next); + if (ptr1->trim_loop) { + for (ptr2 = ptr1->trim_loop; ptr2->next; ptr2 = ptr2->next); + if ((ptr2->next = (trim_list *) malloc(sizeof(trim_list))) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return; + } + ptr2 = ptr2->next; + } + else { + if ((ptr2 = (trim_list *) malloc(sizeof(trim_list))) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return; + } + ptr1->trim_loop = ptr2; + } + ptr2->trim_type = GLU_TRIM_PWL; + ptr2->curve.pwl_curve.pt_count = count; + ptr2->curve.pwl_curve.ctrlarray = array; + ptr2->curve.pwl_curve.stride = stride; + ptr2->curve.pwl_curve.dim = (type == GLU_MAP1_TRIM_2 ? 2 : 3); + ptr2->curve.pwl_curve.type = type; + ptr2->next = NULL; +#endif +} + +void GLAPIENTRY +gluEndTrim(GLUnurbsObj * nobj) +{ + if (nobj->nurbs_type != GLU_NURBS_TRIM) { + call_user_error(nobj, GLU_NURBS_ERROR17); + return; + } + nobj->nurbs_type = GLU_NURBS_TRIM_DONE; +} --- mesa-7.2.orig/src/glu/mesa/nurbs.h +++ mesa-7.2/src/glu/mesa/nurbs.h @@ -0,0 +1,252 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifndef NURBS_H +#define NURBS_H + + +#define EPSILON 1e-06 /* epsilon for double precision compares */ + +typedef enum +{ + GLU_NURBS_CURVE, GLU_NURBS_SURFACE, GLU_NURBS_TRIM, GLU_NURBS_NO_TRIM, + GLU_NURBS_TRIM_DONE, GLU_NURBS_NONE +} +GLU_nurbs_enum; + +typedef enum +{ + GLU_TRIM_NURBS, GLU_TRIM_PWL +} +GLU_trim_enum; + +typedef struct +{ + GLint sknot_count; + GLfloat *sknot; + GLint tknot_count; + GLfloat *tknot; + GLint s_stride; + GLint t_stride; + GLfloat *ctrlarray; + GLint sorder; + GLint torder; + GLint dim; + GLenum type; +} +surface_attribs; + +typedef struct +{ + surface_attribs geom; + surface_attribs color; + surface_attribs texture; + surface_attribs normal; +} +nurbs_surface; + +typedef struct +{ + GLint knot_count; + GLfloat *knot; + GLint stride; + GLfloat *ctrlarray; + GLint order; + GLint dim; + GLenum type; +} +curve_attribs; + +typedef struct +{ + GLint pt_count; + GLfloat *ctrlarray; + GLint stride; + GLint dim; + GLenum type; +} +pwl_curve_attribs; + +typedef struct +{ + curve_attribs geom; + curve_attribs color; + curve_attribs texture; + curve_attribs normal; +} +nurbs_curve; + +typedef struct trim_list_str +{ + GLU_trim_enum trim_type; + union + { + pwl_curve_attribs pwl_curve; + curve_attribs nurbs_curve; + } + curve; + struct trim_list_str *next; +} +trim_list; + +typedef struct seg_trim_str +{ + GLfloat *points; + GLint pt_cnt, seg_array_len; + struct seg_trim_str *next; +} +trim_segments; + +typedef struct nurbs_trim_str +{ + trim_list *trim_loop; + trim_segments *segments; + struct nurbs_trim_str *next; +} +nurbs_trim; + +typedef struct +{ + GLfloat model[16], proj[16], viewport[4]; +} +culling_and_sampling_str; + +struct GLUnurbs +{ + GLboolean culling; + GLenum error; + void (GLCALLBACK * error_callback) (GLenum err); + GLenum display_mode; + GLU_nurbs_enum nurbs_type; + GLboolean auto_load_matrix; + culling_and_sampling_str sampling_matrices; + GLenum sampling_method; + GLfloat sampling_tolerance; + GLfloat parametric_tolerance; + GLint u_step, v_step; + nurbs_surface surface; + nurbs_curve curve; + nurbs_trim *trim; +}; + +typedef struct +{ + GLfloat *knot; + GLint nknots; + GLfloat *unified_knot; + GLint unified_nknots; + GLint order; + GLint t_min, t_max; + GLint delta_nknots; + GLboolean open_at_begin, open_at_end; + GLfloat *new_knot; + GLfloat *alpha; +} +knot_str_type; + +typedef struct +{ + GLfloat *geom_ctrl; + GLint geom_s_stride, geom_t_stride; + GLfloat **geom_offsets; + GLint geom_s_pt_cnt, geom_t_pt_cnt; + GLfloat *color_ctrl; + GLint color_s_stride, color_t_stride; + GLfloat **color_offsets; + GLint color_s_pt_cnt, color_t_pt_cnt; + GLfloat *normal_ctrl; + GLint normal_s_stride, normal_t_stride; + GLfloat **normal_offsets; + GLint normal_s_pt_cnt, normal_t_pt_cnt; + GLfloat *texture_ctrl; + GLint texture_s_stride, texture_t_stride; + GLfloat **texture_offsets; + GLint texture_s_pt_cnt, texture_t_pt_cnt; + GLint s_bezier_cnt, t_bezier_cnt; +} +new_ctrl_type; + +extern void call_user_error(GLUnurbsObj * nobj, GLenum error); + +extern GLenum test_knot(GLint nknots, GLfloat * knot, GLint order); + +extern GLenum explode_knot(knot_str_type * the_knot); + +extern GLenum calc_alphas(knot_str_type * the_knot); + +extern GLenum calc_new_ctrl_pts(GLfloat * ctrl, GLint stride, + knot_str_type * the_knot, GLint dim, + GLfloat ** new_ctrl, GLint * ncontrol); + +extern GLenum glu_do_sampling_crv(GLUnurbsObj * nobj, GLfloat * new_ctrl, + GLint n_ctrl, GLint order, GLint dim, + GLint ** factors); + +extern GLenum glu_do_sampling_3D(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + int **sfactors, GLint ** tfactors); + +extern GLenum glu_do_sampling_uv(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + int **sfactors, GLint ** tfactors); + +extern GLenum glu_do_sampling_param_3D(GLUnurbsObj * nobj, + new_ctrl_type * new_ctrl, + int **sfactors, GLint ** tfactors); + +extern GLboolean fine_culling_test_2D(GLUnurbsObj * nobj, GLfloat * ctrl, + GLint n_ctrl, GLint stride, GLint dim); + +extern GLboolean fine_culling_test_3D(GLUnurbsObj * nobj, GLfloat * ctrl, + GLint s_n_ctrl, GLint t_n_ctrl, + GLint s_stride, GLint t_stride, + GLint dim); + +extern void do_nurbs_curve(GLUnurbsObj * nobj); + +extern void do_nurbs_surface(GLUnurbsObj * nobj); + +extern GLenum patch_trimming(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl, + GLint * sfactors, GLint * tfactors); + +extern void collect_unified_knot(knot_str_type * dest, knot_str_type * src, + GLfloat maximal_min_knot, + GLfloat minimal_max_knot); + +extern GLenum select_knot_working_range(GLUnurbsObj * nobj, + knot_str_type * geom_knot, + knot_str_type * color_knot, + knot_str_type * normal_knot, + knot_str_type * texture_knot); + +extern void free_unified_knots(knot_str_type * geom_knot, + knot_str_type * color_knot, + knot_str_type * normal_knot, + knot_str_type * texture_knot); + + + +#endif --- mesa-7.2.orig/src/glu/mesa/nurbssrf.c +++ mesa-7.2/src/glu/mesa/nurbssrf.c @@ -0,0 +1,1317 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it) + * See README2 for more info. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include "gluP.h" +#include "nurbs.h" +#endif + + +static int +get_surface_dim(GLenum type) +{ + switch (type) { + case GL_MAP2_VERTEX_3: + return 3; + case GL_MAP2_VERTEX_4: + return 4; + case GL_MAP2_INDEX: + return 1; + case GL_MAP2_COLOR_4: + return 4; + case GL_MAP2_NORMAL: + return 3; + case GL_MAP2_TEXTURE_COORD_1: + return 1; + case GL_MAP2_TEXTURE_COORD_2: + return 2; + case GL_MAP2_TEXTURE_COORD_3: + return 3; + case GL_MAP2_TEXTURE_COORD_4: + return 4; + default: + abort(); /* TODO: is this OK? */ + } + return 0; /*never get here */ +} + +static GLenum +test_nurbs_surface(GLUnurbsObj * nobj, surface_attribs * attrib) +{ + GLenum err; + GLint tmp_int; + + if (attrib->sorder < 0 || attrib->torder < 0) { + call_user_error(nobj, GLU_INVALID_VALUE); + return GLU_ERROR; + } + glGetIntegerv(GL_MAX_EVAL_ORDER, &tmp_int); + if (attrib->sorder > tmp_int || attrib->sorder < 2) { + call_user_error(nobj, GLU_NURBS_ERROR1); + return GLU_ERROR; + } + if (attrib->torder > tmp_int || attrib->torder < 2) { + call_user_error(nobj, GLU_NURBS_ERROR1); + return GLU_ERROR; + } + if (attrib->sknot_count < attrib->sorder + 2) { + call_user_error(nobj, GLU_NURBS_ERROR2); + return GLU_ERROR; + } + if (attrib->tknot_count < attrib->torder + 2) { + call_user_error(nobj, GLU_NURBS_ERROR2); + return GLU_ERROR; + } + if (attrib->s_stride < 0 || attrib->t_stride < 0) { + call_user_error(nobj, GLU_NURBS_ERROR34); + return GLU_ERROR; + } + if (attrib->sknot == NULL || attrib->tknot == NULL + || attrib->ctrlarray == NULL) { + call_user_error(nobj, GLU_NURBS_ERROR36); + return GLU_ERROR; + } + if ((err = test_knot(attrib->tknot_count, attrib->tknot, attrib->torder)) + != GLU_NO_ERROR) { + call_user_error(nobj, err); + return GLU_ERROR; + } + if ((err = test_knot(attrib->sknot_count, attrib->sknot, attrib->sorder)) + != GLU_NO_ERROR) { + call_user_error(nobj, err); + return GLU_ERROR; + } + return GLU_NO_ERROR; +} + +static GLenum +test_nurbs_surfaces(GLUnurbsObj * nobj) +{ + /* test the geometric data */ + if (test_nurbs_surface(nobj, &(nobj->surface.geom)) != GLU_NO_ERROR) + return GLU_ERROR; + /* now test the attributive data */ + /* color */ + if (nobj->surface.color.type != GLU_INVALID_ENUM) + if (test_nurbs_surface(nobj, &(nobj->surface.color)) != GLU_NO_ERROR) + return GLU_ERROR; + /* normal */ + if (nobj->surface.normal.type != GLU_INVALID_ENUM) + if (test_nurbs_surface(nobj, &(nobj->surface.normal)) != GLU_NO_ERROR) + return GLU_ERROR; + /* texture */ + if (nobj->surface.texture.type != GLU_INVALID_ENUM) + if (test_nurbs_surface(nobj, &(nobj->surface.texture)) != GLU_NO_ERROR) + return GLU_ERROR; + return GLU_NO_ERROR; +} + +static GLenum +convert_surf(knot_str_type * s_knot, knot_str_type * t_knot, + surface_attribs * attrib, GLfloat ** new_ctrl, + GLint * s_n_ctrl, GLint * t_n_ctrl) +{ + GLfloat **tmp_ctrl; + GLfloat *ctrl_offset; + GLint tmp_n_control; + GLint i, j, t_cnt, s_cnt; + GLint tmp_stride; + GLint dim; + GLenum err; + + /* valid range is empty? */ + if ((s_knot->unified_knot != NULL && s_knot->unified_nknots == 0) || + (t_knot->unified_knot != NULL && t_knot->unified_nknots == 0)) { + if (s_knot->unified_knot) { + free(s_knot->unified_knot); + s_knot->unified_knot = NULL; + } + if (t_knot->unified_knot) { + free(t_knot->unified_knot); + t_knot->unified_knot = NULL; + } + *s_n_ctrl = 0; + *t_n_ctrl = 0; + return GLU_NO_ERROR; + } + t_cnt = attrib->tknot_count - attrib->torder; + s_cnt = attrib->sknot_count - attrib->sorder; + if ((tmp_ctrl = (GLfloat **) malloc(sizeof(GLfloat *) * t_cnt)) == NULL) + return GLU_OUT_OF_MEMORY; + if ((err = explode_knot(s_knot)) != GLU_NO_ERROR) { + free(tmp_ctrl); + if (s_knot->unified_knot) { + free(s_knot->unified_knot); + s_knot->unified_knot = NULL; + } + return err; + } + if (s_knot->unified_knot) { + free(s_knot->unified_knot); + s_knot->unified_knot = NULL; + } + if ((err = calc_alphas(s_knot)) != GLU_NO_ERROR) { + free(tmp_ctrl); + free(s_knot->new_knot); + return err; + } + free(s_knot->new_knot); + ctrl_offset = attrib->ctrlarray; + dim = attrib->dim; + for (i = 0; i < t_cnt; i++) { + if ((err = calc_new_ctrl_pts(ctrl_offset, attrib->s_stride, s_knot, + dim, &(tmp_ctrl[i]), + &tmp_n_control)) != GLU_NO_ERROR) { + for (--i; i <= 0; i--) + free(tmp_ctrl[i]); + free(tmp_ctrl); + free(s_knot->alpha); + return err; + } + ctrl_offset += attrib->t_stride; + } + free(s_knot->alpha); + tmp_stride = dim * tmp_n_control; + if ((*new_ctrl = (GLfloat *) malloc(sizeof(GLfloat) * tmp_stride * t_cnt)) + == NULL) { + for (i = 0; i < t_cnt; i++) + free(tmp_ctrl[i]); + free(tmp_ctrl); + return GLU_OUT_OF_MEMORY; + } + for (i = 0; i < tmp_n_control; i++) + for (j = 0; j < t_cnt; j++) + MEMCPY(*new_ctrl + j * dim + i * dim * t_cnt, tmp_ctrl[j] + dim * i, + sizeof(GLfloat) * dim); + for (i = 0; i < t_cnt; i++) + free(tmp_ctrl[i]); + free(tmp_ctrl); + *s_n_ctrl = tmp_n_control; + + if ((tmp_ctrl = (GLfloat **) malloc(sizeof(GLfloat *) * (*s_n_ctrl))) == + NULL) { + return GLU_OUT_OF_MEMORY; + } + if ((err = explode_knot(t_knot)) != GLU_NO_ERROR) { + free(tmp_ctrl); + if (t_knot->unified_knot) { + free(t_knot->unified_knot); + t_knot->unified_knot = NULL; + } + return err; + } + if (t_knot->unified_knot) { + free(t_knot->unified_knot); + t_knot->unified_knot = NULL; + } + if ((err = calc_alphas(t_knot)) != GLU_NO_ERROR) { + free(tmp_ctrl); + free(t_knot->new_knot); + return err; + } + free(t_knot->new_knot); + ctrl_offset = *new_ctrl; + for (i = 0; i < (*s_n_ctrl); i++) { + if ((err = calc_new_ctrl_pts(ctrl_offset, dim, t_knot, + dim, &(tmp_ctrl[i]), + &tmp_n_control)) != GLU_NO_ERROR) { + for (--i; i <= 0; i--) + free(tmp_ctrl[i]); + free(tmp_ctrl); + free(t_knot->alpha); + return err; + } + ctrl_offset += dim * t_cnt; + } + free(t_knot->alpha); + free(*new_ctrl); + tmp_stride = dim * tmp_n_control; + if ( + (*new_ctrl = + (GLfloat *) malloc(sizeof(GLfloat) * tmp_stride * (*s_n_ctrl))) == + NULL) { + for (i = 0; i < (*s_n_ctrl); i++) + free(tmp_ctrl[i]); + free(tmp_ctrl); + return GLU_OUT_OF_MEMORY; + } + for (i = 0; i < (*s_n_ctrl); i++) { + MEMCPY(*new_ctrl + i * tmp_stride, tmp_ctrl[i], + sizeof(GLfloat) * tmp_stride); + free(tmp_ctrl[i]); + } + free(tmp_ctrl); + *t_n_ctrl = tmp_n_control; + return GLU_NO_ERROR; +} + +/* prepare the knot information structures */ +static GLenum +fill_knot_structures(GLUnurbsObj * nobj, + knot_str_type * geom_s_knot, knot_str_type * geom_t_knot, + knot_str_type * color_s_knot, + knot_str_type * color_t_knot, + knot_str_type * normal_s_knot, + knot_str_type * normal_t_knot, + knot_str_type * texture_s_knot, + knot_str_type * texture_t_knot) +{ + GLint order; + GLfloat *knot; + GLint nknots; + GLint t_min, t_max; + + geom_s_knot->unified_knot = NULL; + knot = geom_s_knot->knot = nobj->surface.geom.sknot; + nknots = geom_s_knot->nknots = nobj->surface.geom.sknot_count; + order = geom_s_knot->order = nobj->surface.geom.sorder; + geom_s_knot->delta_nknots = 0; + t_min = geom_s_knot->t_min = order - 1; + t_max = geom_s_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + geom_s_knot->open_at_begin = GL_TRUE; + } + else + geom_s_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + geom_s_knot->open_at_end = GL_TRUE; + } + else + geom_s_knot->open_at_end = GL_FALSE; + geom_t_knot->unified_knot = NULL; + knot = geom_t_knot->knot = nobj->surface.geom.tknot; + nknots = geom_t_knot->nknots = nobj->surface.geom.tknot_count; + order = geom_t_knot->order = nobj->surface.geom.torder; + geom_t_knot->delta_nknots = 0; + t_min = geom_t_knot->t_min = order - 1; + t_max = geom_t_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + geom_t_knot->open_at_begin = GL_TRUE; + } + else + geom_t_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + geom_t_knot->open_at_end = GL_TRUE; + } + else + geom_t_knot->open_at_end = GL_FALSE; + + if (nobj->surface.color.type != GLU_INVALID_ENUM) { + color_s_knot->unified_knot = (GLfloat *) 1; + knot = color_s_knot->knot = nobj->surface.color.sknot; + nknots = color_s_knot->nknots = nobj->surface.color.sknot_count; + order = color_s_knot->order = nobj->surface.color.sorder; + color_s_knot->delta_nknots = 0; + t_min = color_s_knot->t_min = order - 1; + t_max = color_s_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + color_s_knot->open_at_begin = GL_TRUE; + } + else + color_s_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + color_s_knot->open_at_end = GL_TRUE; + } + else + color_s_knot->open_at_end = GL_FALSE; + color_t_knot->unified_knot = (GLfloat *) 1; + knot = color_t_knot->knot = nobj->surface.color.tknot; + nknots = color_t_knot->nknots = nobj->surface.color.tknot_count; + order = color_t_knot->order = nobj->surface.color.torder; + color_t_knot->delta_nknots = 0; + t_min = color_t_knot->t_min = order - 1; + t_max = color_t_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + color_t_knot->open_at_begin = GL_TRUE; + } + else + color_t_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + color_t_knot->open_at_end = GL_TRUE; + } + else + color_t_knot->open_at_end = GL_FALSE; + } + else { + color_s_knot->unified_knot = NULL; + color_t_knot->unified_knot = NULL; + } + + if (nobj->surface.normal.type != GLU_INVALID_ENUM) { + normal_s_knot->unified_knot = (GLfloat *) 1; + knot = normal_s_knot->knot = nobj->surface.normal.sknot; + nknots = normal_s_knot->nknots = nobj->surface.normal.sknot_count; + order = normal_s_knot->order = nobj->surface.normal.sorder; + normal_s_knot->delta_nknots = 0; + t_min = normal_s_knot->t_min = order - 1; + t_max = normal_s_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + normal_s_knot->open_at_begin = GL_TRUE; + } + else + normal_s_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + normal_s_knot->open_at_end = GL_TRUE; + } + else + normal_s_knot->open_at_end = GL_FALSE; + normal_t_knot->unified_knot = (GLfloat *) 1; + knot = normal_t_knot->knot = nobj->surface.normal.tknot; + nknots = normal_t_knot->nknots = nobj->surface.normal.tknot_count; + order = normal_t_knot->order = nobj->surface.normal.torder; + normal_t_knot->delta_nknots = 0; + t_min = normal_t_knot->t_min = order - 1; + t_max = normal_t_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + normal_t_knot->open_at_begin = GL_TRUE; + } + else + normal_t_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + normal_t_knot->open_at_end = GL_TRUE; + } + else + normal_t_knot->open_at_end = GL_FALSE; + } + else { + normal_s_knot->unified_knot = NULL; + normal_t_knot->unified_knot = NULL; + } + + if (nobj->surface.texture.type != GLU_INVALID_ENUM) { + texture_s_knot->unified_knot = (GLfloat *) 1; + knot = texture_s_knot->knot = nobj->surface.texture.sknot; + nknots = texture_s_knot->nknots = nobj->surface.texture.sknot_count; + order = texture_s_knot->order = nobj->surface.texture.sorder; + texture_s_knot->delta_nknots = 0; + t_min = texture_s_knot->t_min = order - 1; + t_max = texture_s_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + texture_s_knot->open_at_begin = GL_TRUE; + } + else + texture_s_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + texture_s_knot->open_at_end = GL_TRUE; + } + else + texture_s_knot->open_at_end = GL_FALSE; + texture_t_knot->unified_knot = (GLfloat *) 1; + knot = texture_t_knot->knot = nobj->surface.texture.tknot; + nknots = texture_t_knot->nknots = nobj->surface.texture.tknot_count; + order = texture_t_knot->order = nobj->surface.texture.torder; + texture_t_knot->delta_nknots = 0; + t_min = texture_t_knot->t_min = order - 1; + t_max = texture_t_knot->t_max = nknots - order; + if (fabs(knot[t_min] - knot[t_max]) < EPSILON) { + call_user_error(nobj, GLU_NURBS_ERROR3); + return GLU_ERROR; + } + if (fabs(knot[0] - knot[t_min]) < EPSILON) { + /* knot open at beggining */ + texture_t_knot->open_at_begin = GL_TRUE; + } + else + texture_t_knot->open_at_begin = GL_FALSE; + if (fabs(knot[t_max] - knot[nknots - 1]) < EPSILON) { + /* knot open at end */ + texture_t_knot->open_at_end = GL_TRUE; + } + else + texture_t_knot->open_at_end = GL_FALSE; + } + else { + texture_s_knot->unified_knot = NULL; + texture_t_knot->unified_knot = NULL; + } + return GLU_NO_ERROR; +} + + +static void +free_new_ctrl(new_ctrl_type * p) +{ + if (p->geom_ctrl) + free(p->geom_ctrl); + if (p->geom_offsets) + free(p->geom_offsets); + if (p->color_ctrl) { + free(p->color_ctrl); + if (p->color_offsets) + free(p->color_offsets); + } + if (p->normal_ctrl) { + free(p->normal_ctrl); + if (p->normal_offsets) + free(p->normal_offsets); + } + if (p->texture_ctrl) { + free(p->texture_ctrl); + if (p->texture_offsets) + free(p->texture_offsets); + } +} + +/* convert surfaces - geometry and possible attribute ones into equivalent */ +/* sequence of adjacent Bezier patches */ +static GLenum +convert_surfs(GLUnurbsObj * nobj, new_ctrl_type * new_ctrl) +{ + knot_str_type geom_s_knot, color_s_knot, normal_s_knot, texture_s_knot; + knot_str_type geom_t_knot, color_t_knot, normal_t_knot, texture_t_knot; + GLenum err; + + if ((err = fill_knot_structures(nobj, &geom_s_knot, &geom_t_knot, + &color_s_knot, &color_t_knot, + &normal_s_knot, &normal_t_knot, + &texture_s_knot, + &texture_t_knot)) != GLU_NO_ERROR) { + return err; + } + /* unify knots - all knots should have the same working range */ + if ((err = select_knot_working_range(nobj, &geom_s_knot, &color_s_knot, + &normal_s_knot, + &texture_s_knot)) != GLU_NO_ERROR) { + call_user_error(nobj, err); + return err; + } + if ((err = select_knot_working_range(nobj, &geom_t_knot, &color_t_knot, + &normal_t_knot, + &texture_t_knot)) != GLU_NO_ERROR) { + free_unified_knots(&geom_s_knot, &color_s_knot, &normal_s_knot, + &texture_s_knot); + call_user_error(nobj, err); + return err; + } + + /* convert the geometry surface */ + nobj->surface.geom.dim = get_surface_dim(nobj->surface.geom.type); + if ((err = convert_surf(&geom_s_knot, &geom_t_knot, &(nobj->surface.geom), + &(new_ctrl->geom_ctrl), &(new_ctrl->geom_s_pt_cnt), + &(new_ctrl->geom_t_pt_cnt))) != GLU_NO_ERROR) { + free_unified_knots(&geom_s_knot, &color_s_knot, &normal_s_knot, + &texture_s_knot); + free_unified_knots(&geom_t_knot, &color_t_knot, &normal_t_knot, + &texture_t_knot); + call_user_error(nobj, err); + return err; + } + /* if additional attributive surfaces are given convert them as well */ + if (color_s_knot.unified_knot) { + nobj->surface.color.dim = get_surface_dim(nobj->surface.color.type); + if ( + (err = + convert_surf(&color_s_knot, &color_t_knot, &(nobj->surface.color), + &(new_ctrl->color_ctrl), &(new_ctrl->color_s_pt_cnt), + &(new_ctrl->color_t_pt_cnt))) != GLU_NO_ERROR) { + free_unified_knots(&color_s_knot, &color_s_knot, &normal_s_knot, + &texture_s_knot); + free_unified_knots(&color_t_knot, &color_t_knot, &normal_t_knot, + &texture_t_knot); + free_new_ctrl(new_ctrl); + call_user_error(nobj, err); + return err; + } + } + if (normal_s_knot.unified_knot) { + nobj->surface.normal.dim = get_surface_dim(nobj->surface.normal.type); + if ((err = convert_surf(&normal_s_knot, &normal_t_knot, + &(nobj->surface.normal), + &(new_ctrl->normal_ctrl), + &(new_ctrl->normal_s_pt_cnt), + &(new_ctrl->normal_t_pt_cnt))) != + GLU_NO_ERROR) { + free_unified_knots(&normal_s_knot, &normal_s_knot, &normal_s_knot, + &texture_s_knot); + free_unified_knots(&normal_t_knot, &normal_t_knot, &normal_t_knot, + &texture_t_knot); + free_new_ctrl(new_ctrl); + call_user_error(nobj, err); + return err; + } + } + if (texture_s_knot.unified_knot) { + nobj->surface.texture.dim = get_surface_dim(nobj->surface.texture.type); + if ((err = convert_surf(&texture_s_knot, &texture_t_knot, + &(nobj->surface.texture), + &(new_ctrl->texture_ctrl), + &(new_ctrl->texture_s_pt_cnt), + &(new_ctrl->texture_t_pt_cnt))) != + GLU_NO_ERROR) { + free_unified_knots(&texture_s_knot, &texture_s_knot, &texture_s_knot, + &texture_s_knot); + free_unified_knots(&texture_t_knot, &texture_t_knot, &texture_t_knot, + &texture_t_knot); + free_new_ctrl(new_ctrl); + call_user_error(nobj, err); + return err; + } + } + return GLU_NO_ERROR; +} + +/* tesselate the "boundary" Bezier edge strips */ +static void +tesselate_strip_t_line(GLint top_start, GLint top_end, GLint top_z, + GLint bottom_start, GLint bottom_end, GLint bottom_z, + GLint bottom_domain) +{ + GLint top_cnt, bottom_cnt, tri_cnt, k; + GLint direction; + + top_cnt = top_end - top_start; + direction = (top_cnt >= 0 ? 1 : -1); + bottom_cnt = bottom_end - bottom_start; + glBegin(GL_LINES); + while (top_cnt) { + if (bottom_cnt) + tri_cnt = top_cnt / bottom_cnt; + else + tri_cnt = abs(top_cnt); + for (k = 0; k <= tri_cnt; k++, top_start += direction) { + glEvalCoord2f((GLfloat) bottom_z / bottom_domain, + (GLfloat) bottom_start / bottom_domain); + glEvalPoint2(top_z, top_start); + } + if (bottom_cnt) { + glEvalCoord2f((GLfloat) bottom_z / bottom_domain, + (GLfloat) bottom_start / bottom_domain); + bottom_start += direction; + top_start -= direction; + glEvalCoord2f((GLfloat) bottom_z / bottom_domain, + (GLfloat) bottom_start / bottom_domain); + glEvalCoord2f((GLfloat) bottom_z / bottom_domain, + (GLfloat) bottom_start / bottom_domain); + glEvalPoint2(top_z, top_start); + } + top_cnt -= direction * tri_cnt; + bottom_cnt -= direction; + } + glEnd(); +} + + +static void +tesselate_strip_t_fill(GLint top_start, GLint top_end, GLint top_z, + GLint bottom_start, GLint bottom_end, GLint bottom_z, + GLint bottom_domain) +{ + GLint top_cnt, bottom_cnt, tri_cnt, k; + GLint direction; + + top_cnt = top_end - top_start; + direction = (top_cnt >= 0 ? 1 : -1); + bottom_cnt = bottom_end - bottom_start; + while (top_cnt) { + if (bottom_cnt) + tri_cnt = top_cnt / bottom_cnt; + else + tri_cnt = abs(top_cnt); + glBegin(GL_TRIANGLE_FAN); + glEvalCoord2f((GLfloat) bottom_z / bottom_domain, + (GLfloat) bottom_start / bottom_domain); + for (k = 0; k <= tri_cnt; k++, top_start += direction) + glEvalPoint2(top_z, top_start); + if (bottom_cnt) { + bottom_start += direction; + top_start -= direction; + glEvalCoord2f((GLfloat) bottom_z / bottom_domain, + (GLfloat) bottom_start / bottom_domain); + } + glEnd(); + top_cnt -= direction * tri_cnt; + bottom_cnt -= direction; + } +} + + +static void +tesselate_strip_t(GLenum display_mode, GLint top_start, GLint top_end, + GLint top_z, GLint bottom_start, GLint bottom_end, + GLint bottom_z, GLint bottom_domain) +{ + if (display_mode == GL_FILL) + tesselate_strip_t_fill(top_start, top_end, top_z, bottom_start, + bottom_end, bottom_z, bottom_domain); + else + tesselate_strip_t_line(top_start, top_end, top_z, bottom_start, + bottom_end, bottom_z, bottom_domain); +} + + +static void +tesselate_strip_s_fill(GLint top_start, GLint top_end, GLint top_z, + GLint bottom_start, GLint bottom_end, GLint bottom_z, + GLfloat bottom_domain) +{ + GLint top_cnt, bottom_cnt, tri_cnt, k; + GLint direction; + + top_cnt = top_end - top_start; + direction = (top_cnt >= 0 ? 1 : -1); + bottom_cnt = bottom_end - bottom_start; + while (top_cnt) { + if (bottom_cnt) + tri_cnt = top_cnt / bottom_cnt; + else + tri_cnt = abs(top_cnt); + glBegin(GL_TRIANGLE_FAN); + glEvalCoord2f((GLfloat) bottom_start / bottom_domain, + (GLfloat) bottom_z / bottom_domain); + for (k = 0; k <= tri_cnt; k++, top_start += direction) + glEvalPoint2(top_start, top_z); + if (bottom_cnt) { + bottom_start += direction; + top_start -= direction; + glEvalCoord2f((GLfloat) bottom_start / bottom_domain, + (GLfloat) bottom_z / bottom_domain); + } + glEnd(); + top_cnt -= direction * tri_cnt; + bottom_cnt -= direction; + } +} + + +static void +tesselate_strip_s_line(GLint top_start, GLint top_end, GLint top_z, + GLint bottom_start, GLint bottom_end, GLint bottom_z, + GLfloat bottom_domain) +{ + GLint top_cnt, bottom_cnt, tri_cnt, k; + GLint direction; + + top_cnt = top_end - top_start; + direction = (top_cnt >= 0 ? 1 : -1); + bottom_cnt = bottom_end - bottom_start; + glBegin(GL_LINES); + while (top_cnt) { + if (bottom_cnt) + tri_cnt = top_cnt / bottom_cnt; + else + tri_cnt = abs(top_cnt); + for (k = 0; k <= tri_cnt; k++, top_start += direction) { + glEvalCoord2f((GLfloat) bottom_start / bottom_domain, + (GLfloat) bottom_z / bottom_domain); + glEvalPoint2(top_start, top_z); + } + if (bottom_cnt) { + glEvalCoord2f((GLfloat) bottom_start / bottom_domain, + (GLfloat) bottom_z / bottom_domain); + bottom_start += direction; + top_start -= direction; + glEvalCoord2f((GLfloat) bottom_start / bottom_domain, + (GLfloat) bottom_z / bottom_domain); + glEvalPoint2(top_start, top_z); + glEvalCoord2f((GLfloat) bottom_start / bottom_domain, + (GLfloat) bottom_z / bottom_domain); + } + top_cnt -= direction * tri_cnt; + bottom_cnt -= direction; + } + glEnd(); +} + + +static void +tesselate_strip_s(GLenum display_mode, GLint top_start, GLint top_end, + GLint top_z, GLint bottom_start, GLint bottom_end, + GLint bottom_z, GLfloat bottom_domain) +{ + if (display_mode == GL_FILL) + tesselate_strip_s_fill(top_start, top_end, top_z, bottom_start, + bottom_end, bottom_z, bottom_domain); + else + tesselate_strip_s_line(top_start, top_end, top_z, bottom_start, + bottom_end, bottom_z, bottom_domain); +} + +static void +tesselate_bottom_left_corner(GLenum display_mode, GLfloat s_1, GLfloat t_1) +{ + if (display_mode == GL_FILL) { + glBegin(GL_TRIANGLE_FAN); + glEvalPoint2(1, 1); + glEvalCoord2f(s_1, 0.0); + glEvalCoord2f(0.0, 0.0); + glEvalCoord2f(0.0, t_1); + } + else { + glBegin(GL_LINES); + glEvalCoord2f(0.0, 0.0); + glEvalCoord2f(0.0, t_1); + glEvalCoord2f(0.0, 0.0); + glEvalPoint2(1, 1); + glEvalCoord2f(0.0, 0.0); + glEvalCoord2f(s_1, 0.0); + } + glEnd(); +} + +static void +tesselate_bottom_right_corner(GLenum display_mode, GLint v_top, + GLint v_bottom, GLfloat s_1, GLfloat t_1) +{ + if (display_mode == GL_FILL) { + glBegin(GL_TRIANGLE_FAN); + glEvalPoint2(1, v_top); + glEvalCoord2f(0.0, v_bottom * t_1); + glEvalCoord2f(0.0, (v_bottom + 1) * t_1); + glEvalCoord2f(s_1, (v_bottom + 1) * t_1); + } + else { + glBegin(GL_LINES); + glEvalCoord2f(0.0, (v_bottom + 1) * t_1); + glEvalPoint2(1, v_top); + glEvalCoord2f(0.0, (v_bottom + 1) * t_1); + glEvalCoord2f(0.0, v_bottom * t_1); + glEvalCoord2f(0.0, (v_bottom + 1) * t_1); + glEvalCoord2f(s_1, (v_bottom + 1) * t_1); + } + glEnd(); +} + +static void +tesselate_top_left_corner(GLenum display_mode, GLint u_right, GLint u_left, + GLfloat s_1, GLfloat t_1) +{ + if (display_mode == GL_FILL) { + glBegin(GL_TRIANGLE_FAN); + glEvalPoint2(u_right, 1); + glEvalCoord2f((u_left + 1) * s_1, t_1); + glEvalCoord2f((u_left + 1) * s_1, 0.0); + glEvalCoord2f(u_left * s_1, 0.0); + } + else { + glBegin(GL_LINES); + glEvalCoord2f((u_left + 1) * s_1, 0.0); + glEvalPoint2(u_right, 1); + glEvalCoord2f((u_left + 1) * s_1, 0.0); + glEvalCoord2f(u_left * s_1, 0.0); + glEvalCoord2f((u_left + 1) * s_1, 0.0); + glEvalCoord2f((u_left + 1) * s_1, t_1); + } + glEnd(); +} + +static void +tesselate_top_right_corner(GLenum display_mode, GLint u_left, GLint v_bottom, + GLint u_right, GLint v_top, GLfloat s_1, + GLfloat t_1) +{ + if (display_mode == GL_FILL) { + glBegin(GL_TRIANGLE_FAN); + glEvalPoint2(u_left, v_bottom); + glEvalCoord2f((u_right - 1) * s_1, v_top * t_1); + glEvalCoord2f(u_right * s_1, v_top * t_1); + glEvalCoord2f(u_right * s_1, (v_top - 1) * t_1); + } + else { + glBegin(GL_LINES); + glEvalCoord2f(u_right * s_1, v_top * t_1); + glEvalPoint2(u_left, v_bottom); + glEvalCoord2f(u_right * s_1, v_top * t_1); + glEvalCoord2f(u_right * s_1, (v_top - 1) * t_1); + glEvalCoord2f(u_right * s_1, v_top * t_1); + glEvalCoord2f((u_right - 1) * s_1, v_top * t_1); + } + glEnd(); +} + +/* do mesh mapping of Bezier */ +static void +nurbs_map_bezier(GLenum display_mode, GLint * sfactors, GLint * tfactors, + GLint s_bezier_cnt, GLint t_bezier_cnt, GLint s, GLint t) +{ + GLint top, bottom, right, left; + + + if (s == 0) { + top = *(tfactors + t * 3); + bottom = *(tfactors + t * 3 + 1); + } + else if (s == s_bezier_cnt - 1) { + top = *(tfactors + t * 3 + 2); + bottom = *(tfactors + t * 3); + } + else { + top = bottom = *(tfactors + t * 3); + } + if (t == 0) { + left = *(sfactors + s * 3 + 1); + right = *(sfactors + s * 3); + } + else if (t == t_bezier_cnt - 1) { + left = *(sfactors + s * 3); + right = *(sfactors + s * 3 + 2); + } + else { + left = right = *(sfactors + s * 3); + } + + if (top > bottom) { + if (left < right) { + glMapGrid2f(right, 0.0, 1.0, top, 0.0, 1.0); + glEvalMesh2(display_mode, 1, right, 1, top); + tesselate_strip_s(display_mode, 1, right, 1, 1, left, 0, + (GLfloat) left); + tesselate_bottom_left_corner(display_mode, (GLfloat) (1.0 / left), + (GLfloat) (1.0 / bottom)); +/* tesselate_strip_t(display_mode,1,top,1,1,bottom,0,(GLfloat)bottom);*/ + tesselate_strip_t(display_mode, top, 1, 1, bottom, 1, 0, + (GLfloat) bottom); + } + else if (left == right) { + glMapGrid2f(right, 0.0, 1.0, top, 0.0, 1.0); + glEvalMesh2(display_mode, 1, right, 0, top); +/* tesselate_strip_t(display_mode,0,top,1,0,bottom,0,(GLfloat)bottom);*/ + tesselate_strip_t(display_mode, top, 0, 1, bottom, 0, 0, + (GLfloat) bottom); + } + else { + glMapGrid2f(left, 0.0, 1.0, top, 0.0, 1.0); + glEvalMesh2(display_mode, 1, left, 0, top - 1); +/* tesselate_strip_t(display_mode,0,top-1,1,0,bottom-1,0, + (GLfloat)bottom);*/ + tesselate_strip_t(display_mode, top - 1, 0, 1, bottom - 1, 0, 0, + (GLfloat) bottom); + tesselate_bottom_right_corner(display_mode, top - 1, bottom - 1, + (GLfloat) (1.0 / right), + (GLfloat) (1.0 / bottom)); +/* tesselate_strip_s(display_mode,1,left,top-1,1,right,right, + (GLfloat)right);*/ + tesselate_strip_s(display_mode, left, 1, top - 1, right, 1, right, + (GLfloat) right); + } + } + else if (top == bottom) { + if (left < right) { + glMapGrid2f(right, 0.0, 1.0, top, 0.0, 1.0); + glEvalMesh2(display_mode, 0, right, 1, top); + tesselate_strip_s(display_mode, 0, right, 1, 0, left, 0, + (GLfloat) left); + } + else if (left == right) { + glMapGrid2f(right, 0.0, 1.0, top, 0.0, 1.0); + glEvalMesh2(display_mode, 0, right, 0, top); + } + else { + glMapGrid2f(left, 0.0, 1.0, top, 0.0, 1.0); + glEvalMesh2(display_mode, 0, left, 0, top - 1); +/* tesselate_strip_s(display_mode,0,left,top-1,0,right,right, + (GLfloat)right);*/ + tesselate_strip_s(display_mode, left, 0, top - 1, right, 0, right, + (GLfloat) right); + } + } + else { + if (left < right) { + glMapGrid2f(right, 0.0, 1.0, bottom, 0.0, 1.0); + glEvalMesh2(display_mode, 0, right - 1, 1, bottom); + tesselate_strip_s(display_mode, 0, right - 1, 1, 0, left - 1, 0, + (GLfloat) left); + tesselate_top_left_corner(display_mode, right - 1, left - 1, + (GLfloat) (1.0 / left), + (GLfloat) (1.0 / top)); + tesselate_strip_t(display_mode, 1, bottom, right - 1, 1, top, top, + (GLfloat) top); + } + else if (left == right) { + glMapGrid2f(right, 0.0, 1.0, bottom, 0.0, 1.0); + glEvalMesh2(display_mode, 0, right - 1, 0, bottom); + tesselate_strip_t(display_mode, 0, bottom, right - 1, 0, top, top, + (GLfloat) top); + } + else { + glMapGrid2f(left, 0.0, 1.0, bottom, 0.0, 1.0); + glEvalMesh2(display_mode, 0, left - 1, 0, bottom - 1); + tesselate_strip_t(display_mode, 0, bottom - 1, left - 1, 0, top - 1, + top, (GLfloat) top); + tesselate_top_right_corner(display_mode, left - 1, bottom - 1, right, + top, (GLfloat) (1.0 / right), + (GLfloat) (1.0 / top)); +/* tesselate_strip_s(display_mode,0,left-1,bottom-1,0,right-1,right, + (GLfloat)right);*/ + tesselate_strip_s(display_mode, left - 1, 0, bottom - 1, right - 1, + 0, right, (GLfloat) right); + } + } +} + +/* draw NURBS surface in OUTLINE POLYGON mode */ +static void +draw_polygon_mode(GLenum display_mode, GLUnurbsObj * nobj, + new_ctrl_type * new_ctrl, GLint * sfactors, + GLint * tfactors) +{ + GLsizei offset; + GLint t_bezier_cnt, s_bezier_cnt; + GLboolean do_color, do_normal, do_texture; + GLint i, j; + + t_bezier_cnt = new_ctrl->t_bezier_cnt; + s_bezier_cnt = new_ctrl->s_bezier_cnt; + glEnable(nobj->surface.geom.type); + if (new_ctrl->color_ctrl) { + glEnable(nobj->surface.color.type); + do_color = GL_TRUE; + } + else + do_color = GL_FALSE; + if (new_ctrl->normal_ctrl) { + glEnable(nobj->surface.normal.type); + do_normal = GL_TRUE; + } + else + do_normal = GL_FALSE; + if (new_ctrl->texture_ctrl) { + glEnable(nobj->surface.texture.type); + do_texture = GL_TRUE; + } + else + do_texture = GL_FALSE; + for (j = 0; j < s_bezier_cnt; j++) { + for (i = 0; i < t_bezier_cnt; i++) { + offset = j * t_bezier_cnt + i; + if (fine_culling_test_3D(nobj, *(new_ctrl->geom_offsets + offset), + nobj->surface.geom.sorder, + nobj->surface.geom.torder, + new_ctrl->geom_s_stride, + new_ctrl->geom_t_stride, + nobj->surface.geom.dim)) continue; + glMap2f(nobj->surface.geom.type, 0.0, 1.0, new_ctrl->geom_s_stride, + nobj->surface.geom.sorder, 0.0, 1.0, new_ctrl->geom_t_stride, + nobj->surface.geom.torder, + *(new_ctrl->geom_offsets + offset)); + if (do_color) { + glMap2f(nobj->surface.color.type, 0.0, 1.0, + new_ctrl->color_s_stride, nobj->surface.color.sorder, + 0.0, 1.0, new_ctrl->color_t_stride, + nobj->surface.color.torder, + *(new_ctrl->color_offsets + offset)); + } + if (do_normal) { + glMap2f(nobj->surface.normal.type, 0.0, 1.0, + new_ctrl->normal_s_stride, nobj->surface.normal.sorder, + 0.0, 1.0, new_ctrl->normal_t_stride, + nobj->surface.normal.torder, + *(new_ctrl->normal_offsets + offset)); + } + if (do_texture) { + glMap2f(nobj->surface.texture.type, 0.0, 1.0, + new_ctrl->texture_s_stride, nobj->surface.texture.sorder, + 0.0, 1.0, new_ctrl->texture_t_stride, + nobj->surface.texture.torder, + *(new_ctrl->texture_offsets + offset)); + } +/* glMapGrid2f(sfactors[j*3+0],0.0,1.0,tfactors[i*3+0],0.0,1.0); + glEvalMesh2(display_mode,0,sfactors[j*3+0],0,tfactors[i*3+0]);*/ + nurbs_map_bezier(display_mode, sfactors, tfactors, s_bezier_cnt, + t_bezier_cnt, j, i); + } + } +} + + + +/* draw NURBS surface in OUTLINE POLYGON mode */ +#if 0 +static void +draw_patch_mode(GLenum display_mode, GLUnurbsObj * nobj, + new_ctrl_type * new_ctrl, GLint * sfactors, GLint * tfactors) +{ + GLsizei offset; + GLint t_bezier_cnt, s_bezier_cnt; + GLboolean do_color, do_normal, do_texture; + GLint i, j; + + t_bezier_cnt = new_ctrl->t_bezier_cnt; + s_bezier_cnt = new_ctrl->s_bezier_cnt; + glEnable(nobj->surface.geom.type); + if (new_ctrl->color_ctrl) { + glEnable(nobj->surface.color.type); + do_color = GL_TRUE; + } + else + do_color = GL_FALSE; + if (new_ctrl->normal_ctrl) { + glEnable(nobj->surface.normal.type); + do_normal = GL_TRUE; + } + else + do_normal = GL_FALSE; + if (new_ctrl->texture_ctrl) { + glEnable(nobj->surface.texture.type); + do_texture = GL_TRUE; + } + else + do_texture = GL_FALSE; + for (j = 0; j < s_bezier_cnt; j++) { + for (i = 0; i < t_bezier_cnt; i++) { + offset = j * t_bezier_cnt + i; + if (fine_culling_test_3D(nobj, *(new_ctrl->geom_offsets + offset), + nobj->surface.geom.sorder, + nobj->surface.geom.torder, + new_ctrl->geom_s_stride, + new_ctrl->geom_t_stride, + nobj->surface.geom.dim)) continue; + glMap2f(nobj->surface.geom.type, 0.0, 1.0, new_ctrl->geom_s_stride, + nobj->surface.geom.sorder, 0.0, 1.0, new_ctrl->geom_t_stride, + nobj->surface.geom.torder, + *(new_ctrl->geom_offsets + offset)); + if (do_color) { + glMap2f(nobj->surface.color.type, 0.0, 1.0, + new_ctrl->color_s_stride, nobj->surface.color.sorder, + 0.0, 1.0, new_ctrl->color_t_stride, + nobj->surface.color.torder, + *(new_ctrl->color_offsets + offset)); + } + if (do_normal) { + glMap2f(nobj->surface.normal.type, 0.0, 1.0, + new_ctrl->normal_s_stride, nobj->surface.normal.sorder, + 0.0, 1.0, new_ctrl->normal_t_stride, + nobj->surface.normal.torder, + *(new_ctrl->normal_offsets + offset)); + } + if (do_texture) { + glMap2f(nobj->surface.texture.type, 0.0, 1.0, + new_ctrl->texture_s_stride, nobj->surface.texture.sorder, + 0.0, 1.0, new_ctrl->texture_t_stride, + nobj->surface.texture.torder, + *(new_ctrl->texture_offsets + offset)); + } + nurbs_map_bezier(display_mode, sfactors, tfactors, s_bezier_cnt, + t_bezier_cnt, i, j); +/* glMapGrid2f(sfactors[j],0.0,1.0,tfactors[i],0.0,1.0); + glEvalMesh2(display_mode,0,sfactors[j],0,tfactors[i]);*/ + } + } +} +#endif + + + +static void +init_new_ctrl(new_ctrl_type * p) +{ + p->geom_ctrl = p->color_ctrl = p->normal_ctrl = p->texture_ctrl = NULL; + p->geom_offsets = p->color_offsets = p->normal_offsets = + p->texture_offsets = NULL; + p->s_bezier_cnt = p->t_bezier_cnt = 0; +} + + +static GLenum +augment_new_ctrl(GLUnurbsObj * nobj, new_ctrl_type * p) +{ + GLsizei offset_size; + GLint i, j; + + p->s_bezier_cnt = (p->geom_s_pt_cnt) / (nobj->surface.geom.sorder); + p->t_bezier_cnt = (p->geom_t_pt_cnt) / (nobj->surface.geom.torder); + offset_size = (p->s_bezier_cnt) * (p->t_bezier_cnt); + p->geom_t_stride = nobj->surface.geom.dim; + p->geom_s_stride = (p->geom_t_pt_cnt) * (nobj->surface.geom.dim); + p->color_t_stride = nobj->surface.color.dim; + p->color_s_stride = (p->color_t_pt_cnt) * (nobj->surface.color.dim); + p->normal_t_stride = nobj->surface.normal.dim; + p->normal_s_stride = (p->normal_t_pt_cnt) * (nobj->surface.normal.dim); + p->texture_t_stride = nobj->surface.texture.dim; + p->texture_s_stride = (p->texture_t_pt_cnt) * (nobj->surface.texture.dim); + if ( + (p->geom_offsets = + (GLfloat **) malloc(sizeof(GLfloat *) * offset_size)) == NULL) { + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + if (p->color_ctrl) + if ( + (p->color_offsets = + (GLfloat **) malloc(sizeof(GLfloat *) * offset_size)) == NULL) { + free_new_ctrl(p); + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + if (p->normal_ctrl) + if ( + (p->normal_offsets = + (GLfloat **) malloc(sizeof(GLfloat *) * offset_size)) == NULL) { + free_new_ctrl(p); + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + if (p->texture_ctrl) + if ( + (p->texture_offsets = + (GLfloat **) malloc(sizeof(GLfloat *) * offset_size)) == NULL) { + free_new_ctrl(p); + call_user_error(nobj, GLU_OUT_OF_MEMORY); + return GLU_ERROR; + } + for (i = 0; i < p->s_bezier_cnt; i++) + for (j = 0; j < p->t_bezier_cnt; j++) + *(p->geom_offsets + i * (p->t_bezier_cnt) + j) = + p->geom_ctrl + i * (nobj->surface.geom.sorder) * + (nobj->surface.geom.dim) * (p->geom_t_pt_cnt) + + j * (nobj->surface.geom.dim) * (nobj->surface.geom.torder); + if (p->color_ctrl) + for (i = 0; i < p->s_bezier_cnt; i++) + for (j = 0; j < p->t_bezier_cnt; j++) + *(p->color_offsets + i * (p->t_bezier_cnt) + j) = + p->color_ctrl + i * (nobj->surface.color.sorder) * + (nobj->surface.color.dim) * (p->color_t_pt_cnt) + + j * (nobj->surface.color.dim) * (nobj->surface.color.torder); + if (p->normal_ctrl) + for (i = 0; i < p->s_bezier_cnt; i++) + for (j = 0; j < p->t_bezier_cnt; j++) + *(p->normal_offsets + i * (p->t_bezier_cnt) + j) = + p->normal_ctrl + i * (nobj->surface.normal.sorder) * + (nobj->surface.normal.dim) * (p->normal_t_pt_cnt) + + j * (nobj->surface.normal.dim) * (nobj->surface.normal.torder); + if (p->texture_ctrl) + for (i = 0; i < p->s_bezier_cnt; i++) + for (j = 0; j < p->t_bezier_cnt; j++) + *(p->texture_offsets + i * (p->t_bezier_cnt) + j) = + p->texture_ctrl + i * (nobj->surface.texture.sorder) * + (nobj->surface.texture.dim) * (p->texture_t_pt_cnt) + + j * (nobj->surface.texture.dim) * + (nobj->surface.texture.torder); + return GLU_NO_ERROR; +} + +/* main NURBS surface procedure */ +void +do_nurbs_surface(GLUnurbsObj * nobj) +{ + GLint *sfactors, *tfactors; + new_ctrl_type new_ctrl; + + /* test user supplied data */ + if (test_nurbs_surfaces(nobj) != GLU_NO_ERROR) + return; + + init_new_ctrl(&new_ctrl); + + if (convert_surfs(nobj, &new_ctrl) != GLU_NO_ERROR) + return; + if (augment_new_ctrl(nobj, &new_ctrl) != GLU_NO_ERROR) + return; + switch (nobj->sampling_method) { + case GLU_PATH_LENGTH: + if (glu_do_sampling_3D(nobj, &new_ctrl, &sfactors, &tfactors) != + GLU_NO_ERROR) { + free_new_ctrl(&new_ctrl); + return; + } + break; + case GLU_DOMAIN_DISTANCE: + if (glu_do_sampling_uv(nobj, &new_ctrl, &sfactors, &tfactors) != + GLU_NO_ERROR) { + free_new_ctrl(&new_ctrl); + return; + } + break; + case GLU_PARAMETRIC_ERROR: + if (glu_do_sampling_param_3D(nobj, &new_ctrl, &sfactors, &tfactors) != + GLU_NO_ERROR) { + free_new_ctrl(&new_ctrl); + return; + } + break; + default: + abort(); + } + glFrontFace(GL_CW); + switch (nobj->display_mode) { + case GLU_FILL: +/* if(polygon_trimming(nobj,&new_ctrl,sfactors,tfactors)==GLU_NO_ERROR)*/ + draw_polygon_mode(GL_FILL, nobj, &new_ctrl, sfactors, tfactors); + break; + case GLU_OUTLINE_POLYGON: + /* TODO - missing trimming handeling */ +/* just for now - no OUTLINE_PATCH mode + draw_patch_mode(GL_LINE,nobj,&new_ctrl,sfactors,tfactors); + break; */ + case GLU_OUTLINE_PATCH: +/* if(polygon_trimming(nobj,&new_ctrl,sfactors,tfactors)==GLU_NO_ERROR)*/ + draw_polygon_mode(GL_LINE, nobj, &new_ctrl, sfactors, tfactors); + break; + default: + abort(); /* TODO: is this OK? */ + } + free(sfactors); + free(tfactors); + free_new_ctrl(&new_ctrl); +} --- mesa-7.2.orig/src/glu/mesa/glu.c +++ mesa-7.2/src/glu/mesa/glu.c @@ -0,0 +1,416 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * Copyright (C) 1995-2001 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include +#include +#include +#include "gluP.h" +#endif + + +/* + * Miscellaneous utility functions + */ + + +#ifndef M_PI +#define M_PI 3.1415926536 +#endif +#define EPS 0.00001 + +#ifndef GLU_INCOMPATIBLE_GL_VERSION +#define GLU_INCOMPATIBLE_GL_VERSION 100903 +#endif + + +void GLAPIENTRY +gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, + GLdouble centerx, GLdouble centery, GLdouble centerz, + GLdouble upx, GLdouble upy, GLdouble upz) +{ + GLdouble m[16]; + GLdouble x[3], y[3], z[3]; + GLdouble mag; + + /* Make rotation matrix */ + + /* Z vector */ + z[0] = eyex - centerx; + z[1] = eyey - centery; + z[2] = eyez - centerz; + mag = sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]); + if (mag) { /* mpichler, 19950515 */ + z[0] /= mag; + z[1] /= mag; + z[2] /= mag; + } + + /* Y vector */ + y[0] = upx; + y[1] = upy; + y[2] = upz; + + /* X vector = Y cross Z */ + x[0] = y[1] * z[2] - y[2] * z[1]; + x[1] = -y[0] * z[2] + y[2] * z[0]; + x[2] = y[0] * z[1] - y[1] * z[0]; + + /* Recompute Y = Z cross X */ + y[0] = z[1] * x[2] - z[2] * x[1]; + y[1] = -z[0] * x[2] + z[2] * x[0]; + y[2] = z[0] * x[1] - z[1] * x[0]; + + /* mpichler, 19950515 */ + /* cross product gives area of parallelogram, which is < 1.0 for + * non-perpendicular unit-length vectors; so normalize x, y here + */ + + mag = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); + if (mag) { + x[0] /= mag; + x[1] /= mag; + x[2] /= mag; + } + + mag = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]); + if (mag) { + y[0] /= mag; + y[1] /= mag; + y[2] /= mag; + } + +#define M(row,col) m[col*4+row] + M(0, 0) = x[0]; + M(0, 1) = x[1]; + M(0, 2) = x[2]; + M(0, 3) = 0.0; + M(1, 0) = y[0]; + M(1, 1) = y[1]; + M(1, 2) = y[2]; + M(1, 3) = 0.0; + M(2, 0) = z[0]; + M(2, 1) = z[1]; + M(2, 2) = z[2]; + M(2, 3) = 0.0; + M(3, 0) = 0.0; + M(3, 1) = 0.0; + M(3, 2) = 0.0; + M(3, 3) = 1.0; +#undef M + glMultMatrixd(m); + + /* Translate Eye to Origin */ + glTranslated(-eyex, -eyey, -eyez); + +} + + + +void GLAPIENTRY +gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) +{ + glOrtho(left, right, bottom, top, -1.0, 1.0); +} + + + +static void +frustum(GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble nearval, GLdouble farval) +{ + GLdouble x, y, a, b, c, d; + GLdouble m[16]; + + x = (2.0 * nearval) / (right - left); + y = (2.0 * nearval) / (top - bottom); + a = (right + left) / (right - left); + b = (top + bottom) / (top - bottom); + c = -(farval + nearval) / ( farval - nearval); + d = -(2.0 * farval * nearval) / (farval - nearval); + +#define M(row,col) m[col*4+row] + M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F; + M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F; + M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d; + M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F; +#undef M + + glMultMatrixd(m); +} + + +void GLAPIENTRY +gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) +{ + GLdouble xmin, xmax, ymin, ymax; + + ymax = zNear * tan(fovy * M_PI / 360.0); + ymin = -ymax; + xmin = ymin * aspect; + xmax = ymax * aspect; + + /* don't call glFrustum() because of error semantics (covglu) */ + frustum(xmin, xmax, ymin, ymax, zNear, zFar); +} + + + +void GLAPIENTRY +gluPickMatrix(GLdouble x, GLdouble y, + GLdouble width, GLdouble height, GLint viewport[4]) +{ + GLfloat m[16]; + GLfloat sx, sy; + GLfloat tx, ty; + + sx = viewport[2] / width; + sy = viewport[3] / height; + tx = (viewport[2] + 2.0 * (viewport[0] - x)) / width; + ty = (viewport[3] + 2.0 * (viewport[1] - y)) / height; + +#define M(row,col) m[col*4+row] + M(0, 0) = sx; + M(0, 1) = 0.0; + M(0, 2) = 0.0; + M(0, 3) = tx; + M(1, 0) = 0.0; + M(1, 1) = sy; + M(1, 2) = 0.0; + M(1, 3) = ty; + M(2, 0) = 0.0; + M(2, 1) = 0.0; + M(2, 2) = 1.0; + M(2, 3) = 0.0; + M(3, 0) = 0.0; + M(3, 1) = 0.0; + M(3, 2) = 0.0; + M(3, 3) = 1.0; +#undef M + + glMultMatrixf(m); +} + + + +const GLubyte *GLAPIENTRY +gluErrorString(GLenum errorCode) +{ + static char *tess_error[] = { + "missing gluBeginPolygon", + "missing gluBeginContour", + "missing gluEndPolygon", + "missing gluEndContour", + "misoriented or self-intersecting loops", + "coincident vertices", + "colinear vertices", + "FIST recovery process fatal error" + }; + static char *nurbs_error[] = { + "spline order un-supported", + "too few knots", + "valid knot range is empty", + "decreasing knot sequence knot", + "knot multiplicity greater than order of spline", + "endcurve() must follow bgncurve()", + "bgncurve() must precede endcurve()", + "missing or extra geometric data", + "can't draw pwlcurves", + "missing bgncurve()", + "missing bgnsurface()", + "endtrim() must precede endsurface()", + "bgnsurface() must precede endsurface()", + "curve of improper type passed as trim curve", + "bgnsurface() must precede bgntrim()", + "endtrim() must follow bgntrim()", + "bgntrim() must precede endtrim()", + "invalid or missing trim curve", + "bgntrim() must precede pwlcurve()", + "pwlcurve referenced twice", + "pwlcurve and nurbscurve mixed", + "improper usage of trim data type", + "nurbscurve referenced twice", + "nurbscurve and pwlcurve mixed", + "nurbssurface referenced twice", + "invalid property", + "endsurface() must follow bgnsurface()", + "misoriented trim curves", + "intersecting trim curves", + "UNUSED", + "unconnected trim curves", + "unknown knot error", + "negative vertex count encountered", + "negative byte-stride encountered", + "unknown type descriptor", + "null control array or knot vector", + "duplicate point on pwlcurve" + }; + + /* GL Errors */ + if (errorCode == GL_NO_ERROR) { + return (GLubyte *) "no error"; + } + else if (errorCode == GL_INVALID_VALUE) { + return (GLubyte *) "invalid value"; + } + else if (errorCode == GL_INVALID_ENUM) { + return (GLubyte *) "invalid enum"; + } + else if (errorCode == GL_INVALID_OPERATION) { + return (GLubyte *) "invalid operation"; + } + else if (errorCode == GL_STACK_OVERFLOW) { + return (GLubyte *) "stack overflow"; + } + else if (errorCode == GL_STACK_UNDERFLOW) { + return (GLubyte *) "stack underflow"; + } + else if (errorCode == GL_OUT_OF_MEMORY) { + return (GLubyte *) "out of memory"; + } + /* GLU Errors */ + else if (errorCode == GLU_NO_ERROR) { + return (GLubyte *) "no error"; + } + else if (errorCode == GLU_INVALID_ENUM) { + return (GLubyte *) "invalid enum"; + } + else if (errorCode == GLU_INVALID_VALUE) { + return (GLubyte *) "invalid value"; + } + else if (errorCode == GLU_OUT_OF_MEMORY) { + return (GLubyte *) "out of memory"; + } + else if (errorCode == GLU_INCOMPATIBLE_GL_VERSION) { + return (GLubyte *) "incompatible GL version"; + } + else if (errorCode >= GLU_TESS_ERROR1 && errorCode <= GLU_TESS_ERROR8) { + return (GLubyte *) tess_error[errorCode - GLU_TESS_ERROR1]; + } + else if (errorCode >= GLU_NURBS_ERROR1 && errorCode <= GLU_NURBS_ERROR37) { + return (GLubyte *) nurbs_error[errorCode - GLU_NURBS_ERROR1]; + } + else { + return NULL; + } +} + + + +/* + * New in GLU 1.1 + */ + +const GLubyte *GLAPIENTRY +gluGetString(GLenum name) +{ + static char *extensions = "GL_EXT_abgr"; + static char *version = "1.1 Mesa 3.5"; + + switch (name) { + case GLU_EXTENSIONS: + return (GLubyte *) extensions; + case GLU_VERSION: + return (GLubyte *) version; + default: + return NULL; + } +} + + + +#if 0 /* gluGetProcAddressEXT not finalized yet! */ + +#ifdef __cplusplus + /* for BeOS R4.5 */ +void GLAPIENTRY(*gluGetProcAddressEXT(const GLubyte * procName)) (...) +#else +void (GLAPIENTRY * gluGetProcAddressEXT(const GLubyte * procName)) () +#endif +{ + struct proc + { + const char *name; + void *address; + }; + static struct proc procTable[] = { + {"gluGetProcAddressEXT", (void *) gluGetProcAddressEXT}, /* me! */ + + /* new 1.1 functions */ + {"gluGetString", (void *) gluGetString}, + + /* new 1.2 functions */ + {"gluTessBeginPolygon", (void *) gluTessBeginPolygon}, + {"gluTessBeginContour", (void *) gluTessBeginContour}, + {"gluTessEndContour", (void *) gluTessEndContour}, + {"gluTessEndPolygon", (void *) gluTessEndPolygon}, + {"gluGetTessProperty", (void *) gluGetTessProperty}, + + /* new 1.3 functions */ + + {NULL, NULL} + }; + GLuint i; + + for (i = 0; procTable[i].address; i++) { + if (strcmp((const char *) procName, procTable[i].name) == 0) + return (void (GLAPIENTRY *) ()) procTable[i].address; + } + + return NULL; +} + +#endif + + + +/* + * New in GLU 1.3 + */ +#ifdef GLU_VERSION_1_3 +GLboolean GLAPIENTRY +gluCheckExtension(const GLubyte *extName, const GLubyte * extString) +{ + assert(extName); + assert(extString); + { + const int len = strlen((const char *) extName); + const char *start = (const char *) extString; + + while (1) { + const char *c = strstr(start, (const char *) extName); + if (!c) + return GL_FALSE; + + if ((c == start || c[-1] == ' ') && (c[len] == ' ' || c[len] == 0)) + return GL_TRUE; + + start = c + len; + } + } +} +#endif --- mesa-7.2.orig/src/glu/mesa/tess.c +++ mesa-7.2/src/glu/mesa/tess.c @@ -0,0 +1,327 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifdef PC_HEADER +#include "all.h" +#else +#include +#include +#include "tess.h" +#endif + + +/* + * This is ugly, but seems the easiest way to do things to make the + * code work under YellowBox for Windows + */ +#if defined(OPENSTEP) && defined(CALLBACK) +#undef CALLBACK +#define CALLBACK +#endif + + +static void delete_contours(GLUtriangulatorObj *); + +#ifdef __CYGWIN32__ +#define _CALLBACK +#else +#define _CALLBACK GLCALLBACK +#endif + + +static void +init_callbacks(tess_callbacks * callbacks) +{ + callbacks->begin = (void (_CALLBACK *) (GLenum)) 0; + callbacks->edgeFlag = (void (_CALLBACK *) (GLboolean)) 0; + callbacks->vertex = (void (_CALLBACK *) (void *)) 0; + callbacks->end = (void (_CALLBACK *) (void)) 0; + callbacks->error = (void (_CALLBACK *) (GLenum)) 0; +} + +void +tess_call_user_error(GLUtriangulatorObj * tobj, GLenum gluerr) +{ + if (tobj->error == GLU_NO_ERROR) + tobj->error = gluerr; + if (tobj->callbacks.error != NULL) + (tobj->callbacks.error) (gluerr); +} + +GLUtriangulatorObj *GLAPIENTRY +gluNewTess(void) +{ + GLUtriangulatorObj *tobj; + + if ((tobj = (GLUtriangulatorObj *) + malloc(sizeof(struct GLUtesselator))) == NULL) + return NULL; + tobj->contours = tobj->last_contour = NULL; + init_callbacks(&tobj->callbacks); + tobj->error = GLU_NO_ERROR; + tobj->current_polygon = NULL; + tobj->contour_cnt = 0; + return tobj; +} + + +void GLAPIENTRY +gluTessCallback(GLUtriangulatorObj * tobj, GLenum which, + void (GLCALLBACK * fn) ()) +{ + switch (which) { + case GLU_BEGIN: + tobj->callbacks.begin = (void (_CALLBACK *) (GLenum)) fn; + break; + case GLU_EDGE_FLAG: + tobj->callbacks.edgeFlag = (void (_CALLBACK *) (GLboolean)) fn; + break; + case GLU_VERTEX: + tobj->callbacks.vertex = (void (_CALLBACK *) (void *)) fn; + break; + case GLU_END: + tobj->callbacks.end = (void (_CALLBACK *) (void)) fn; + break; + case GLU_ERROR: + tobj->callbacks.error = (void (_CALLBACK *) (GLenum)) fn; + break; + default: + tobj->error = GLU_INVALID_ENUM; + break; + } +} + + + +void GLAPIENTRY +gluDeleteTess(GLUtriangulatorObj * tobj) +{ + if (tobj->error == GLU_NO_ERROR && tobj->contour_cnt) + /* was gluEndPolygon called? */ + tess_call_user_error(tobj, GLU_TESS_ERROR1); + /* delete all internal structures */ + delete_contours(tobj); + free(tobj); +} + + +void GLAPIENTRY +gluBeginPolygon(GLUtriangulatorObj * tobj) +{ +/* + if(tobj->error!=GLU_NO_ERROR) + return; +*/ + tobj->error = GLU_NO_ERROR; + if (tobj->current_polygon != NULL) { + /* gluEndPolygon was not called */ + tess_call_user_error(tobj, GLU_TESS_ERROR1); + /* delete all internal structures */ + delete_contours(tobj); + } + else { + if ((tobj->current_polygon = + (tess_polygon *) malloc(sizeof(tess_polygon))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + tobj->current_polygon->vertex_cnt = 0; + tobj->current_polygon->vertices = + tobj->current_polygon->last_vertex = NULL; + } +} + + +void GLAPIENTRY +gluEndPolygon(GLUtriangulatorObj * tobj) +{ + /*tess_contour *contour_ptr; */ + + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + /* check if gluBeginPolygon was called */ + if (tobj->current_polygon == NULL) { + tess_call_user_error(tobj, GLU_TESS_ERROR2); + return; + } + tess_test_polygon(tobj); + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + /* any real contours? */ + if (tobj->contour_cnt == 0) { + /* delete all internal structures */ + delete_contours(tobj); + return; + } + tess_find_contour_hierarchies(tobj); + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + tess_handle_holes(tobj); + /* there was an error */ + if (tobj->error != GLU_NO_ERROR) + goto end; + + /* if no callbacks, nothing to do */ + if (tobj->callbacks.begin != NULL && tobj->callbacks.vertex != NULL && + tobj->callbacks.end != NULL) { + if (tobj->callbacks.edgeFlag == NULL) + tess_tesselate(tobj); + else + tess_tesselate_with_edge_flag(tobj); + } + + end: + /* delete all internal structures */ + delete_contours(tobj); +} + + +void GLAPIENTRY +gluNextContour(GLUtriangulatorObj * tobj, GLenum type) +{ + if (tobj->error != GLU_NO_ERROR) + return; + if (tobj->current_polygon == NULL) { + tess_call_user_error(tobj, GLU_TESS_ERROR2); + return; + } + /* first contour? */ + if (tobj->current_polygon->vertex_cnt) + tess_test_polygon(tobj); +} + + +void GLAPIENTRY +gluTessVertex(GLUtriangulatorObj * tobj, GLdouble v[3], void *data) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_vertex *last_vertex_ptr; + + if (tobj->error != GLU_NO_ERROR) + return; + if (polygon == NULL) { + tess_call_user_error(tobj, GLU_TESS_ERROR2); + return; + } + last_vertex_ptr = polygon->last_vertex; + if (last_vertex_ptr == NULL) { + if ((last_vertex_ptr = (tess_vertex *) + malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + polygon->vertices = last_vertex_ptr; + polygon->last_vertex = last_vertex_ptr; + last_vertex_ptr->data = data; + last_vertex_ptr->location[0] = v[0]; + last_vertex_ptr->location[1] = v[1]; + last_vertex_ptr->location[2] = v[2]; + last_vertex_ptr->next = NULL; + last_vertex_ptr->previous = NULL; + ++(polygon->vertex_cnt); + } + else { + tess_vertex *vertex_ptr; + + /* same point twice? */ + if (fabs(last_vertex_ptr->location[0] - v[0]) < EPSILON && + fabs(last_vertex_ptr->location[1] - v[1]) < EPSILON && + fabs(last_vertex_ptr->location[2] - v[2]) < EPSILON) { + tess_call_user_error(tobj, GLU_TESS_ERROR6); + return; + } + if ((vertex_ptr = (tess_vertex *) + malloc(sizeof(tess_vertex))) == NULL) { + tess_call_user_error(tobj, GLU_OUT_OF_MEMORY); + return; + } + vertex_ptr->data = data; + vertex_ptr->location[0] = v[0]; + vertex_ptr->location[1] = v[1]; + vertex_ptr->location[2] = v[2]; + vertex_ptr->next = NULL; + vertex_ptr->previous = last_vertex_ptr; + ++(polygon->vertex_cnt); + last_vertex_ptr->next = vertex_ptr; + polygon->last_vertex = vertex_ptr; + } +} + + +static void +delete_contours(GLUtriangulatorObj * tobj) +{ + tess_polygon *polygon = tobj->current_polygon; + tess_contour *contour, *contour_tmp; + tess_vertex *vertex, *vertex_tmp; + + /* remove current_polygon list - if exists due to detected error */ + if (polygon != NULL) { + if (polygon->vertices) { + for (vertex = polygon->vertices; vertex != polygon->last_vertex;) { + vertex_tmp = vertex->next; + free(vertex); + vertex = vertex_tmp; + } + free(vertex); + } + free(polygon); + tobj->current_polygon = NULL; + } + /* remove all contour data */ + for (contour = tobj->contours; contour != NULL;) { + for (vertex = contour->vertices; vertex != contour->last_vertex;) { + vertex_tmp = vertex->next; + free(vertex); + vertex = vertex_tmp; + } + free(vertex); + contour_tmp = contour->next; + free(contour); + contour = contour_tmp; + } + tobj->contours = tobj->last_contour = NULL; + tobj->contour_cnt = 0; +} + + +void GLAPIENTRY +gluTessNormal(GLUtesselator *tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ) +{ + /* dummy function */ + (void) tess; + (void) valueX; + (void) valueY; + (void) valueZ; +} --- mesa-7.2.orig/src/glu/mesa/tess.h +++ mesa-7.2/src/glu/mesa/tess.h @@ -0,0 +1,107 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.3 + * Copyright (C) 1995-2000 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * This file is part of the polygon tesselation code contributed by + * Bogdan Sikorski + */ + + +#ifndef TESS_H +#define TESS_H + + +#include "gluP.h" + +#define EPSILON 1e-06 /* epsilon for double precision compares */ + +typedef enum +{ + OXY, + OYZ, + OXZ +} +projection_type; + +typedef struct callbacks_str +{ + void (GLCALLBACK * begin) (GLenum mode); + void (GLCALLBACK * edgeFlag) (GLboolean flag); + void (GLCALLBACK * vertex) (GLvoid * v); + void (GLCALLBACK * end) (void); + void (GLCALLBACK * error) (GLenum err); +} +tess_callbacks; + +typedef struct vertex_str +{ + void *data; + GLdouble location[3]; + GLdouble x, y; + GLboolean edge_flag; + struct vertex_str *shadow_vertex; + struct vertex_str *next, *previous; +} +tess_vertex; + +typedef struct contour_str +{ + GLenum type; + GLuint vertex_cnt; + GLdouble area; + GLenum orientation; + struct vertex_str *vertices, *last_vertex; + struct contour_str *next, *previous; +} +tess_contour; + +typedef struct polygon_str +{ + GLuint vertex_cnt; + GLdouble A, B, C, D; + GLdouble area; + GLenum orientation; + struct vertex_str *vertices, *last_vertex; +} +tess_polygon; + +struct GLUtesselator +{ + tess_contour *contours, *last_contour; + GLuint contour_cnt; + tess_callbacks callbacks; + tess_polygon *current_polygon; + GLenum error; + GLdouble A, B, C, D; + projection_type projection; +}; + + +extern void tess_call_user_error(GLUtriangulatorObj *, GLenum); +extern void tess_test_polygon(GLUtriangulatorObj *); +extern void tess_find_contour_hierarchies(GLUtriangulatorObj *); +extern void tess_handle_holes(GLUtriangulatorObj *); +extern void tess_tesselate(GLUtriangulatorObj *); +extern void tess_tesselate_with_edge_flag(GLUtriangulatorObj *); + + +#endif --- mesa-7.2.orig/src/glu/mesa/descrip.mms +++ mesa-7.2/src/glu/mesa/descrip.mms @@ -0,0 +1,61 @@ +# Makefile for GLU for VMS +# contributed by Jouk Jansen joukj@hrem.stm.tudelft.nl + +.first + define gl [-.include.gl] + +.include [-]mms-config. + +##### MACROS ##### + +VPATH = RCS + +INCDIR = $disk2:[-.include] +LIBDIR = [-.lib] +CFLAGS = /include=$(INCDIR)/define=(FBIND=1)/name=(as_is,short)/float=ieee/ieee=denorm + +SOURCES = glu.c mipmap.c nurbs.c nurbscrv.c nurbssrf.c nurbsutl.c \ + polytest.c project.c quadric.c tess.c tesselat.c + +OBJECTS =glu.obj,mipmap.obj,nurbs.obj,nurbscrv.obj,nurbssrf.obj,nurbsutl.obj,\ + polytest.obj,project.obj,quadric.obj,tess.obj,tesselat.obj + + +##### RULES ##### + +VERSION=MesaGlu V3.2 + +##### TARGETS ##### + +# Make the library: +$(LIBDIR)$(GLU_LIB) : $(OBJECTS) +.ifdef SHARE + @ WRITE_ SYS$OUTPUT " generating mesagl1.opt" + @ OPEN_/WRITE FILE mesagl1.opt + @ WRITE_ FILE "!" + @ WRITE_ FILE "! mesagl1.opt generated by DESCRIP.$(MMS_EXT)" + @ WRITE_ FILE "!" + @ WRITE_ FILE "IDENTIFICATION=""$(VERSION)""" + @ WRITE_ FILE "GSMATCH=LEQUAL,3,2 + @ WRITE_ FILE "$(OBJECTS)" + @ WRITE_ FILE "[-.lib]libmesagl.exe/SHARE" + @ WRITE_ FILE "SYS$SHARE:DECW$XEXTLIBSHR/SHARE" + @ WRITE_ FILE "SYS$SHARE:DECW$XLIBSHR/SHARE" + @ CLOSE_ FILE + @ WRITE_ SYS$OUTPUT " generating mesagl.map ..." + @ LINK_/NODEB/NOSHARE/NOEXE/MAP=mesagl.map/FULL mesagl1.opt/OPT + @ WRITE_ SYS$OUTPUT " analyzing mesagl.map ..." + @ @[-.vms]ANALYZE_MAP.COM mesagl.map mesagl.opt + @ WRITE_ SYS$OUTPUT " linking $(GLU_LIB) ..." + @ LINK_/noinform/NODEB/SHARE=$(GLU_LIB)/MAP=mesagl.map/FULL mesagl1.opt/opt,mesagl.opt/opt +.else + @ $(MAKELIB) $(GLU_LIB) $(OBJECTS) +.endif + @ rename $(GLU_LIB)* $(LIBDIR) + +clean : + delete *.obj;* + purge + +include mms_depend. + --- mesa-7.2.orig/src/mesa/x86-64/calling_convention.txt +++ mesa-7.2/src/mesa/x86-64/calling_convention.txt @@ -0,0 +1,50 @@ +Register Usage +rax temporary register; with variable arguments passes information + about the number of SSE registers used; 1st return register + +rbx* callee-saved register; optionally used as base pointer + +rcx used to pass 4th integer argument to functions + +rdx used to pass 3rd argument to functions 2nd return register + +rsp* stack pointer + +rbp* callee-saved register; optionally used as frame pointer + +rsi used to pass 2nd argument to functions + +rdi used to pass 1st argument to functions + +r8 used to pass 5th argument to functions + +r9 used to pass 6th argument to functions + +r10 temporary register, used for passing a function's static chain pointer + +r11 temporary register + +r12-15* callee-saved registers + +xmm0­1 used to pass and return floating point arguments + +xmm2­7 used to pass floating point arguments + +xmm8­15 temporary registers + +mmx0­7 temporary registers + +st0 temporary register; used to return long double arguments + +st1 temporary registers; used to return long double arguments + +st2­7 temporary registers + +fs Reserved for system use (as thread specific data register) + + + +*) must be preserved across function calls + +Integer arguments from list: rdi,rsi,rdx,rcx,r8,r9,stack +Floating point arguments from list: xmm0-xmm7 \ No newline at end of file --- mesa-7.2.orig/src/mesa/drivers/ggi/default/genkgi.h +++ mesa-7.2/src/mesa/drivers/ggi/default/genkgi.h @@ -0,0 +1,76 @@ +/* $Id: genkgi.h,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ +****************************************************************************** + + GGIMesa - KGIcon specific overrides for fbcon-mesa + API header + + Copyright (C) 1999 Jon Taylor [taylorj@ggi-project.org] + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHOR(S) 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 _GENKGI_MESA_H +#define _GENKGI_MESA_H + +#undef KGI_USE_PPBUFS + +#include +#include + +#include +#include +#include + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +/* FIXME: LibGGI needs to export its genkgi.h */ +struct genkgi_priv +{ + ggi_gc *mapped_gc; + unsigned int gc_size; + ggifunc_drawline *drawline; + ggifunc_drawbox *drawbox; + ggifunc_fillscreen *fillscreen; + int fd_gc; + int close_gc; + int fd_kgicommand; + uint8 *mapped_kgicommand; + uint8 *kgicommand_ptr; + unsigned int kgicommand_buffersize; +}; + +#define GENKGI_PRIV(vis) ((struct genkgi_priv *)FBDEV_PRIV(vis)->accelpriv) + +extern ggifunc_getapi GGIMesa_genkgi_getapi; +extern ggifunc_flush GGIMesa_genkgi_flush; + +struct genkgi_priv_mesa +{ + char accel[100]; + int have_accel; + void *accelpriv; /* Private data of subdrivers */ + struct genkgi_priv *oldpriv; /* LibGGI's private data */ +}; + +#define GENKGI_PRIV_MESA(vis) ((struct genkgi_priv_mesa *)FBDEV_PRIV_MESA(vis)->accelpriv) + +#endif /* _GENKHI_MESA_H */ --- mesa-7.2.orig/src/mesa/drivers/glslcompiler/Makefile +++ mesa-7.2/src/mesa/drivers/glslcompiler/Makefile @@ -0,0 +1,44 @@ +# Makefile for stand-alone GL-SL compiler + +TOP = ../../../.. + +include $(TOP)/configs/current + + +PROGRAM = glslcompiler + +OBJECTS = \ + glslcompiler.o \ + ../../glapi/glapi.o \ + ../../glapi/glthread.o \ + ../../main/dispatch.o \ + ../common/driverfuncs.o \ + ../../libmesa.a + +INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/include/GL/internal \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/mesa/glapi \ + -I$(TOP)/src/mesa/math \ + -I$(TOP)/src/mesa/transform \ + -I$(TOP)/src/mesa/shader \ + -I$(TOP)/src/mesa/swrast \ + -I$(TOP)/src/mesa/swrast_setup \ + + +default: $(PROGRAM) + $(INSTALL) $(PROGRAM) $(TOP)/bin + + +glslcompiler: $(OBJECTS) + $(CC) $(OBJECTS) -lm -lpthread -o $@ + + +glslcompiler.o: glslcompiler.c + $(CC) -c $(CFLAGS) $(INCLUDES) glslcompiler.c -o $@ + + +clean: + -rm -f *.o *~ $(PROGRAM) --- mesa-7.2.orig/src/mesa/drivers/glslcompiler/glslcompiler.c +++ mesa-7.2/src/mesa/drivers/glslcompiler/glslcompiler.c @@ -0,0 +1,358 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5.3 + * + * Copyright (C) 1999-2007 Brian Paul, Tungsten Graphics, Inc. + * 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 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 + * BRIAN PAUL 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. + */ + +/** + * \mainpage + * + * Stand-alone Shading Language compiler. + * Basically, a command-line program which accepts GLSL shaders and emits + * vertex/fragment programs (GPU instructions). + * + * This file is basically just a Mesa device driver but instead of building + * a shared library we build an executable. + * + * We can emit programs in three different formats: + * 1. ARB-style (GL_ARB_vertex/fragment_program) + * 2. NV-style (GL_NV_vertex/fragment_program) + * 3. debug-style (a slightly more sophisticated, internal format) + * + * Note that the ARB and NV program languages can't express all the + * features that might be used by a fragment program (examples being + * uniform and varying vars). So, the ARB/NV programs that are + * emitted aren't always legal programs in those languages. + */ + + +#include "imports.h" +#include "context.h" +#include "extensions.h" +#include "framebuffer.h" +#include "shaders.h" +#include "shader/shader_api.h" +#include "shader/prog_print.h" +#include "drivers/common/driverfuncs.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" +#include "swrast/swrast.h" +#include "swrast/s_context.h" +#include "swrast/s_triangle.h" +#include "swrast_setup/swrast_setup.h" +#include "vbo/vbo.h" + + +static const char *Prog = "glslcompiler"; + + +struct options { + GLboolean LineNumbers; + gl_prog_print_mode Mode; + const char *VertFile; + const char *FragFile; + const char *OutputFile; +}; + +static struct options Options; + + +/** + * GLSL compiler driver context. (kind of an artificial thing for now) + */ +struct compiler_context +{ + GLcontext MesaContext; + int foo; +}; + +typedef struct compiler_context CompilerContext; + + + +static void +UpdateState(GLcontext *ctx, GLuint new_state) +{ + /* easy - just propogate */ + _swrast_InvalidateState( ctx, new_state ); + _swsetup_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + _vbo_InvalidateState( ctx, new_state ); +} + + + +static GLboolean +CreateContext(void) +{ + struct dd_function_table ddFuncs; + GLvisual *vis; + GLframebuffer *buf; + GLcontext *ctx; + CompilerContext *cc; + + vis = _mesa_create_visual(GL_TRUE, GL_FALSE, GL_FALSE, /* RGB */ + 8, 8, 8, 8, /* color */ + 0, 0, 0, /* z, stencil */ + 0, 0, 0, 0, 1); /* accum */ + buf = _mesa_create_framebuffer(vis); + + cc = _mesa_calloc(sizeof(*cc)); + if (!vis || !buf || !cc) { + if (vis) + _mesa_destroy_visual(vis); + if (buf) + _mesa_destroy_framebuffer(buf); + return GL_FALSE; + } + + _mesa_init_driver_functions(&ddFuncs); + ddFuncs.GetString = NULL;/*get_string;*/ + ddFuncs.UpdateState = UpdateState; + ddFuncs.GetBufferSize = NULL; + + ctx = &cc->MesaContext; + _mesa_initialize_context(ctx, vis, NULL, &ddFuncs, cc); + _mesa_enable_sw_extensions(ctx); + + if (!_swrast_CreateContext( ctx ) || + !_vbo_CreateContext( ctx ) || + !_tnl_CreateContext( ctx ) || + !_swsetup_CreateContext( ctx )) { + _mesa_destroy_visual(vis); + _mesa_free_context_data(ctx); + _mesa_free(cc); + return GL_FALSE; + } + TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline; + _swsetup_Wakeup( ctx ); + + _mesa_make_current(ctx, buf, buf); + + return GL_TRUE; +} + + +static void +LoadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + _mesa_ShaderSourceARB(shader, 1, (const GLchar **) &text, NULL); + _mesa_CompileShaderARB(shader); + _mesa_GetShaderiv(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + _mesa_GetShaderInfoLog(shader, 1000, &len, log); + fprintf(stderr, "%s: problem compiling shader: %s\n", Prog, log); + exit(1); + } + else { + printf("Shader compiled OK\n"); + } +} + + +/** + * Read a shader from a file. + */ +static void +ReadShader(GLuint shader, const char *filename) +{ + const int max = 100*1000; + int n; + char *buffer = (char*) malloc(max); + FILE *f = fopen(filename, "r"); + if (!f) { + fprintf(stderr, "%s: Unable to open shader file %s\n", Prog, filename); + exit(1); + } + + n = fread(buffer, 1, max, f); + /* + printf("%s: read %d bytes from shader file %s\n", Prog, n, filename); + */ + if (n > 0) { + buffer[n] = 0; + LoadAndCompileShader(shader, buffer); + } + + fclose(f); + free(buffer); +} + + +#if 0 +static void +CheckLink(GLuint prog) +{ + GLint stat; + _mesa_GetProgramiv(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + _mesa_GetProgramInfoLog(prog, 1000, &len, log); + fprintf(stderr, "%s: Linker error:\n%s\n", Prog, log); + } + else { + fprintf(stderr, "%s: Link success!\n", Prog); + } +} +#endif + + +static void +PrintShaderInstructions(GLuint shader, FILE *f) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); + GLuint i; + + for (i = 0; i < sh->NumPrograms; i++) { + struct gl_program *prog = sh->Programs[i]; + _mesa_print_program_opt(prog, Options.Mode, Options.LineNumbers); + } +} + + +static GLuint +CompileShader(const char *filename, GLenum type) +{ + GLuint shader; + + assert(type == GL_FRAGMENT_SHADER || + type == GL_VERTEX_SHADER); + + shader = _mesa_CreateShader(type); + ReadShader(shader, filename); + + return shader; +} + + +static void +Usage(void) +{ + printf("Mesa GLSL stand-alone compiler\n"); + printf("Usage:\n"); + printf(" --vs FILE vertex shader input filename\n"); + printf(" --fs FILE fragment shader input filename\n"); + printf(" --arb emit ARB-style instructions (the default)\n"); + printf(" --nv emit NV-style instructions\n"); + printf(" --debug emit debug-style instructions\n"); + printf(" --number, -n emit line numbers\n"); + printf(" --output, -o FILE output filename\n"); + printf(" --help display this information\n"); +} + + +static void +ParseOptions(int argc, char *argv[]) +{ + int i; + + Options.LineNumbers = GL_FALSE; + Options.Mode = PROG_PRINT_ARB; + Options.VertFile = NULL; + Options.FragFile = NULL; + Options.OutputFile = NULL; + + if (argc == 1) { + Usage(); + exit(0); + } + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "--vs") == 0) { + Options.VertFile = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "--fs") == 0) { + Options.FragFile = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "--arb") == 0) { + Options.Mode = PROG_PRINT_ARB; + } + else if (strcmp(argv[i], "--nv") == 0) { + Options.Mode = PROG_PRINT_NV; + } + else if (strcmp(argv[i], "--debug") == 0) { + Options.Mode = PROG_PRINT_DEBUG; + } + else if (strcmp(argv[i], "--number") == 0 || + strcmp(argv[i], "-n") == 0) { + Options.LineNumbers = GL_TRUE; + } + else if (strcmp(argv[i], "--output") == 0 || + strcmp(argv[i], "-o") == 0) { + Options.OutputFile = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "--help") == 0) { + Usage(); + exit(0); + } + else { + printf("Unknown option: %s\n", argv[i]); + Usage(); + exit(1); + } + } +} + + +int +main(int argc, char *argv[]) +{ + GLuint shader = 0; + + if (!CreateContext()) { + fprintf(stderr, "%s: Failed to create compiler context\n", Prog); + exit(1); + } + + ParseOptions(argc, argv); + + if (Options.VertFile) { + shader = CompileShader(Options.VertFile, GL_VERTEX_SHADER); + } + else if (Options.FragFile) { + shader = CompileShader(Options.FragFile, GL_FRAGMENT_SHADER); + } + + if (shader) { + if (Options.OutputFile) { + fclose(stdout); + /*stdout =*/ freopen(Options.OutputFile, "w", stdout); + } + if (stdout) { + PrintShaderInstructions(shader, stdout); + } + if (Options.OutputFile) { + fclose(stdout); + } + } + + return 0; +} --- mesa-7.2.orig/src/mesa/drivers/allegro/amesa.c +++ mesa-7.2/src/mesa/drivers/allegro/amesa.c @@ -0,0 +1,414 @@ +/* + * Mesa 3-D graphics library + * Version: 3.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include "buffers.h" +#include "context.h" +#include "imports.h" +#include "matrix.h" +#include "mtypes.h" +#include "GL/amesa.h" + + +struct amesa_visual + { + GLvisual *GLVisual; /* inherit from GLvisual */ + GLboolean DBFlag; /* double buffered? */ + GLuint Depth; /* bits per pixel ( >= 15 ) */ + }; + + +struct amesa_buffer + { + GLframebuffer *GLBuffer; /* inherit from GLframebuffer */ + GLuint Width, Height; + BITMAP *Screen; + BITMAP *Background; + BITMAP *Active; + }; + + +struct amesa_context + { + GLcontext *GLContext; /* inherit from GLcontext */ + AMesaVisual Visual; + AMesaBuffer Buffer; + GLuint ClearColor; + GLuint CurrentColor; + }; + + +static void setup_dd_pointers(GLcontext *ctx); + + +/**********************************************************************/ +/***** drawing functions *****/ +/**********************************************************************/ + +#define FLIP(context, y) (context->Buffer->Height - (y) - 1) + +#include "allegro/generic.h" +#include "allegro/direct.h" + + +/**********************************************************************/ +/***** 15-bit accelerated drawing funcs *****/ +/**********************************************************************/ + +IMPLEMENT_WRITE_RGBA_SPAN(15, unsigned short) +IMPLEMENT_WRITE_RGB_SPAN(15, unsigned short) +IMPLEMENT_WRITE_MONO_RGBA_SPAN(15, unsigned short) +IMPLEMENT_READ_RGBA_SPAN(15, unsigned short) +IMPLEMENT_WRITE_RGBA_PIXELS(15, unsigned short) +IMPLEMENT_WRITE_MONO_RGBA_PIXELS(15, unsigned short) +IMPLEMENT_READ_RGBA_PIXELS(15, unsigned short) + + +/**********************************************************************/ +/***** 16-bit accelerated drawing funcs *****/ +/**********************************************************************/ + +IMPLEMENT_WRITE_RGBA_SPAN(16, unsigned short) +IMPLEMENT_WRITE_RGB_SPAN(16, unsigned short) +IMPLEMENT_WRITE_MONO_RGBA_SPAN(16, unsigned short) +IMPLEMENT_READ_RGBA_SPAN(16, unsigned short) +IMPLEMENT_WRITE_RGBA_PIXELS(16, unsigned short) +IMPLEMENT_WRITE_MONO_RGBA_PIXELS(16, unsigned short) +IMPLEMENT_READ_RGBA_PIXELS(16, unsigned short) + + +/**********************************************************************/ +/***** 32-bit accelerated drawing funcs *****/ +/**********************************************************************/ + +IMPLEMENT_WRITE_RGBA_SPAN(32, unsigned long) +IMPLEMENT_WRITE_RGB_SPAN(32, unsigned long) +IMPLEMENT_WRITE_MONO_RGBA_SPAN(32, unsigned long) +IMPLEMENT_READ_RGBA_SPAN(32, unsigned long) +IMPLEMENT_WRITE_RGBA_PIXELS(32, unsigned long) +IMPLEMENT_WRITE_MONO_RGBA_PIXELS(32, unsigned long) +IMPLEMENT_READ_RGBA_PIXELS(32, unsigned long) + + +/**********************************************************************/ +/***** Miscellaneous device driver funcs *****/ +/**********************************************************************/ + +static GLboolean set_buffer(GLcontext *ctx, GLframebuffer *buffer, GLuint bit) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + GLboolean ok = GL_TRUE; + + if (bit == DD_FRONT_LEFT_BIT) + context->Buffer->Active = context->Buffer->Screen; + + else if (bit == DD_BACK_LEFT) + { + if (context->Buffer->Background) + context->Buffer->Active = context->Buffer->Background; + else + ok = GL_FALSE; + } + + else + ok = GL_FALSE; + + return ok; + } + + +static void get_buffer_size(GLcontext *ctx, GLuint *width, GLuint *height) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + + *width = context->Buffer->Width; + *height = context->Buffer->Height; + } + + +/** + * We only implement this function as a mechanism to check if the + * framebuffer size has changed (and update corresponding state). + */ +static void viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) +{ + /* poll for window size change and realloc software Z/stencil/etc if needed */ + GLuint newWidth, newHeight; + GLframebuffer *buffer = ctx->WinSysDrawBuffer; + get_buffer_size( &newWidth, &newHeight ); + if (buffer->Width != newWidth || buffer->Height != newHeight) { + _mesa_resize_framebuffer(ctx, buffer, newWidth, newHeight ); + } + +} + + +/**********************************************************************/ +/**********************************************************************/ + +static void setup_dd_pointers(GLcontext *ctx) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + + /* Initialize all the pointers in the driver struct. Do this whenever */ + /* a new context is made current or we change buffers via set_buffer! */ + + ctx->Driver.UpdateState = setup_dd_pointers; + ctx->Driver.SetBuffer = set_buffer; + ctx->Driver.GetBufferSize = get_buffer_size; + ctx->Driver.Viewport = viewport; + + ctx->Driver.Color = set_color_generic; + ctx->Driver.ClearColor = clear_color_generic; + ctx->Driver.Clear = clear_generic; + ctx->Driver.WriteRGBASpan = write_rgba_span_generic; + ctx->Driver.WriteRGBSpan = write_rgb_span_generic; + ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_generic; + ctx->Driver.WriteRGBAPixels = write_rgba_pixels_generic; + ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_generic; + ctx->Driver.ReadRGBASpan = read_rgba_span_generic; + ctx->Driver.ReadRGBAPixels = read_rgba_pixels_generic; + + if (context->Buffer->Active != screen) + { + switch (context->Visual->Depth) + { + case 15: + ctx->Driver.WriteRGBASpan = write_rgba_span_15; + ctx->Driver.WriteRGBSpan = write_rgb_span_15; + ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_15; + ctx->Driver.WriteRGBAPixels = write_rgba_pixels_15; + ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_15; + ctx->Driver.ReadRGBASpan = read_rgba_span_15; + ctx->Driver.ReadRGBAPixels = read_rgba_pixels_15; + break; + + case 16: + ctx->Driver.WriteRGBASpan = write_rgba_span_16; + ctx->Driver.WriteRGBSpan = write_rgb_span_16; + ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_16; + ctx->Driver.WriteRGBAPixels = write_rgba_pixels_16; + ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_16; + ctx->Driver.ReadRGBASpan = read_rgba_span_16; + ctx->Driver.ReadRGBAPixels = read_rgba_pixels_16; + break; + + case 32: + ctx->Driver.WriteRGBASpan = write_rgba_span_32; + ctx->Driver.WriteRGBSpan = write_rgb_span_32; + ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span_32; + ctx->Driver.WriteRGBAPixels = write_rgba_pixels_32; + ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels_32; + ctx->Driver.ReadRGBASpan = read_rgba_span_32; + ctx->Driver.ReadRGBAPixels = read_rgba_pixels_32; + break; + } + } + } + + +/**********************************************************************/ +/***** AMesa Public API Functions *****/ +/**********************************************************************/ + + +AMesaVisual AMesaCreateVisual(GLboolean dbFlag, GLint depth, + GLint depthSize, GLint stencilSize, GLint accumSize) + { + AMesaVisual visual; + GLbyte redBits, greenBits, blueBits; + + visual = (AMesaVisual)calloc(1, sizeof(struct amesa_visual)); + if (!visual) + return NULL; + + switch (depth) + { + case 15: + redBits = 5; + greenBits = 5; + blueBits = 5; + break; + + case 16: + redBits = 5; + greenBits = 6; + blueBits = 5; + break; + + case 24: case 32: + redBits = 8; + greenBits = 8; + blueBits = 8; + break; + + default: + free(visual); + return NULL; + } + + visual->DBFlag = dbFlag; + visual->Depth = depth; + visual->GLVisual = _mesa_create_visual(GL_TRUE, /* rgb mode */ + dbFlag, /* db_flag */ + GL_FALSE, /* stereo */ + redBits, greenBits, blueBits, 8, + 0, /* index bits */ + depthSize, /* depth bits */ + stencilSize,/* stencil bits */ + accumSize, /* accum bits */ + accumSize, /* accum bits */ + accumSize, /* accum bits */ + accumSize, /* accum bits */ + 1 ); + if (!visual->GLVisual) + { + free(visual); + return NULL; + } + + return visual; + } + + +void AMesaDestroyVisual(AMesaVisual visual) + { + _mesa_destroy_visual(visual->GLVisual); + free(visual); + } + + +AMesaBuffer AMesaCreateBuffer(AMesaVisual visual, + GLint width, GLint height) + { + AMesaBuffer buffer; + + buffer = (AMesaBuffer)calloc(1, sizeof(struct amesa_buffer)); + if (!buffer) + return NULL; + + buffer->Screen = NULL; + buffer->Background = NULL; + buffer->Active = NULL; + buffer->Width = width; + buffer->Height = height; + + if (visual->DBFlag) + { + buffer->Background = create_bitmap_ex(visual->Depth, width, height); + if (!buffer->Background) + { + free(buffer); + return NULL; + } + } + + buffer->GLBuffer = _mesa_create_framebuffer(visual->GLVisual); + if (!buffer->GLBuffer) + { + if (buffer->Background) destroy_bitmap(buffer->Background); + free(buffer); + return NULL; + } + + return buffer; + } + + +void AMesaDestroyBuffer(AMesaBuffer buffer) +{ + if (buffer->Screen) destroy_bitmap(buffer->Screen); + if (buffer->Background) destroy_bitmap(buffer->Background); + _mesa_unreference_framebuffer(&buffer->GLBuffer); + free(buffer); +} + + +AMesaContext AMesaCreateContext(AMesaVisual visual, + AMesaContext share) +{ + AMesaContext context; + GLboolean direct = GL_FALSE; + + context = (AMesaContext)calloc(1, sizeof(struct amesa_context)); + if (!context) + return NULL; + + context->Visual = visual; + context->Buffer = NULL; + context->ClearColor = 0; + context->CurrentColor = 0; + context->GLContext = _mesa_create_context(visual->GLVisual, + share ? share->GLContext : NULL, + (void *) context, GL_FALSE ); + if (!context->GLContext) + { + free(context); + return NULL; + } + + return context; +} + + +void AMesaDestroyContext(AMesaContext context) +{ + _mesa_destroy_context(context->GLContext); + free(context); +} + + +GLboolean AMesaMakeCurrent(AMesaContext context, AMesaBuffer buffer) +{ + if (context && buffer) { + set_color_depth(context->Visual->Depth); + if (set_gfx_mode(GFX_AUTODETECT, buffer->Width, buffer->Height, 0, 0) != 0) + return GL_FALSE; + + context->Buffer = buffer; + buffer->Screen = screen; + buffer->Active = buffer->Background ? buffer->Background : screen; + + setup_dd_pointers(context->GLContext); + _mesa_make_current(context->GLContext, buffer->GLBuffer); + } + else { + /* XXX I don't think you want to destroy anything here! */ + destroy_bitmap(context->Buffer->Screen); + context->Buffer->Screen = NULL; + context->Buffer->Active = NULL; + context->Buffer = NULL; + _mesa_make_current(NULL, NULL); + } + + return GL_TRUE; +} + + +void AMesaSwapBuffers(AMesaBuffer buffer) +{ + if (buffer->Background) { + blit(buffer->Background, buffer->Screen, + 0, 0, 0, 0, + buffer->Width, buffer->Height); + } +} --- mesa-7.2.orig/src/mesa/drivers/allegro/direct.h +++ mesa-7.2/src/mesa/drivers/allegro/direct.h @@ -0,0 +1,189 @@ +/* + * Mesa 3-D graphics library + * Version: 3.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#define DESTINATION(BMP, X, Y, TYPE) \ + ({ \ + BITMAP *_bmp = BMP; \ + \ + (TYPE*)(_bmp->line[_bmp->h - (Y) - 1]) + (X); \ + }) + + +#define IMPLEMENT_WRITE_RGBA_SPAN(DEPTH, TYPE) \ +static void write_rgba_span_##DEPTH (const GLcontext *ctx, \ + GLuint n, GLint x, GLint y, \ + const GLubyte rgba[][4], \ + const GLubyte mask[]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + TYPE *d = DESTINATION(context->Buffer->Active, x, y, TYPE); \ + \ + if (mask) \ + { \ + while (n--) \ + { \ + if (mask[0]) d[0] = makecol##DEPTH(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]); \ + d++; rgba++; mask++; \ + } \ + } \ + else \ + { \ + while (n--) \ + { \ + d[0] = makecol##DEPTH(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]); \ + d++; rgba++; \ + } \ + } \ + } + + +#define IMPLEMENT_WRITE_RGB_SPAN(DEPTH, TYPE) \ +static void write_rgb_span_##DEPTH (const GLcontext *ctx, \ + GLuint n, GLint x, GLint y, \ + const GLubyte rgb[][3], \ + const GLubyte mask[]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + TYPE *d = DESTINATION(context->Buffer->Active, x, y, TYPE); \ + \ + if (mask) \ + { \ + while (n--) \ + { \ + if (mask[0]) d[0] = makecol##DEPTH(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP]); \ + d++; rgb++; mask++; \ + } \ + } \ + else \ + { \ + while (n--) \ + { \ + d[0] = makecol##DEPTH(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP]); \ + d++; rgb++; \ + } \ + } \ + } + + +#define IMPLEMENT_WRITE_MONO_RGBA_SPAN(DEPTH, TYPE) \ +static void write_mono_rgba_span_##DEPTH (const GLcontext *ctx, \ + GLuint n, GLint x, GLint y, \ + const GLubyte mask[]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + TYPE color = context->CurrentColor; \ + TYPE *d = DESTINATION(context->Buffer->Active, x, y, TYPE); \ + \ + while (n--) \ + { \ + if (mask[0]) d[0] = color; \ + d++; mask++; \ + } \ + } + + +#define IMPLEMENT_READ_RGBA_SPAN(DEPTH, TYPE) \ +static void read_rgba_span_##DEPTH (const GLcontext *ctx, \ + GLuint n, GLint x, GLint y, \ + GLubyte rgba[][4]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + BITMAP *bmp = context->Buffer->Active; \ + TYPE *d = DESTINATION(bmp, x, y, TYPE); \ + \ + while (n--) \ + { \ + rgba[0][RCOMP] = getr##DEPTH(d[0]); \ + rgba[0][GCOMP] = getg##DEPTH(d[0]); \ + rgba[0][BCOMP] = getb##DEPTH(d[0]); \ + rgba[0][ACOMP] = 255; \ + \ + d++; rgba++; \ + } \ + } + + +#define IMPLEMENT_WRITE_RGBA_PIXELS(DEPTH, TYPE) \ +static void write_rgba_pixels_##DEPTH (const GLcontext *ctx, \ + GLuint n, \ + const GLint x[], \ + const GLint y[], \ + const GLubyte rgba[][4], \ + const GLubyte mask[]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + BITMAP *bmp = context->Buffer->Active; \ + \ + while (n--) \ + { \ + if (mask[0]) *DESTINATION(bmp, x[0], y[0], TYPE) = makecol##DEPTH(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]); \ + rgba++; x++; y++; mask++; \ + } \ + } + + + +#define IMPLEMENT_WRITE_MONO_RGBA_PIXELS(DEPTH, TYPE) \ +static void write_mono_rgba_pixels_##DEPTH (const GLcontext *ctx, \ + GLuint n, \ + const GLint x[], \ + const GLint y[], \ + const GLubyte mask[]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + TYPE color = context->CurrentColor; \ + BITMAP *bmp = context->Buffer->Active; \ + \ + while (n--) \ + { \ + if (mask[0]) *DESTINATION(bmp, x[0], y[0], TYPE) = color; \ + x++; y++; mask++; \ + } \ + } + + +#define IMPLEMENT_READ_RGBA_PIXELS(DEPTH, TYPE) \ +static void read_rgba_pixels_##DEPTH (const GLcontext *ctx, \ + GLuint n, \ + const GLint x[], \ + const GLint y[], \ + GLubyte rgba[][4], \ + const GLubyte mask[]) \ + { \ + AMesaContext context = (AMesaContext)(ctx->DriverCtx); \ + BITMAP *bmp = context->Buffer->Active; \ + \ + while (n--) \ + { \ + if (mask[0]) \ + { \ + int color = *DESTINATION(bmp, x[0], y[0], TYPE); \ + \ + rgba[0][RCOMP] = getr##DEPTH(color); \ + rgba[0][GCOMP] = getg##DEPTH(color); \ + rgba[0][BCOMP] = getb##DEPTH(color); \ + rgba[0][ACOMP] = 255; \ + } \ + \ + x++; y++; rgba++; mask++; \ + } \ + } + --- mesa-7.2.orig/src/mesa/drivers/allegro/generic.h +++ mesa-7.2/src/mesa/drivers/allegro/generic.h @@ -0,0 +1,234 @@ +/* + * Mesa 3-D graphics library + * Version: 3.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +static void clear_color_generic(GLcontext *ctx, const GLfloat color[4]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + GLubyte r, g, b; + CLAMPED_FLOAT_TO_UBYTE(r, color[0]); + CLAMPED_FLOAT_TO_UBYTE(g, color[1]); + CLAMPED_FLOAT_TO_UBYTE(b, color[2]); + context->ClearColor = makecol(r, g, b); + } + + +static void set_color_generic(GLcontext *ctx, + GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + + context->CurrentColor = makecol(red, green, blue); + } + + +static GLbitfield clear_generic(GLcontext *ctx, + GLbitfield mask, GLboolean all, + GLint x, GLint y, + GLint width, GLint height) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + + if (mask & GL_COLOR_BUFFER_BIT) + { + if (all) + clear_to_color(context->Buffer->Active, context->ClearColor); + else + rect(context->Buffer->Active, + x, y, x+width-1, y+height-1, + context->ClearColor); + } + + return mask & (~GL_COLOR_BUFFER_BIT); + } + + +static void write_rgba_span_generic(const GLcontext *ctx, + GLuint n, GLint x, GLint y, + const GLubyte rgba[][4], + const GLubyte mask[]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + + y = FLIP(context, y); + + if (mask) + { + while (n--) + { + if (mask[0]) putpixel(bmp, x, y, makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP])); + x++; mask++; rgba++; + } + } + else + { + while (n--) + { + putpixel(bmp, x, y, makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP])); + x++; rgba++; + } + } + } + + +static void write_rgb_span_generic(const GLcontext *ctx, + GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], + const GLubyte mask[]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + + y = FLIP(context, y); + + if (mask) + { + while(n--) + { + if (mask[0]) putpixel(bmp, x, y, makecol(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP])); + x++; mask++; rgb++; + } + } + else + { + while (n--) + { + putpixel(bmp, x, y, makecol(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP])); + x++; rgb++; + } + } + } + + +static void write_mono_rgba_span_generic(const GLcontext *ctx, + GLuint n, GLint x, GLint y, + const GLubyte mask[]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + int color = context->CurrentColor; + + y = FLIP(context, y); + + if (mask) + { + while(n--) + { + if (mask[0]) putpixel(bmp, x, y, color); + x++; mask++; + } + } + else + { + while(n--) + { + putpixel(bmp, x, y, color); + x++; + } + } + } + + +static void read_rgba_span_generic(const GLcontext *ctx, + GLuint n, GLint x, GLint y, + GLubyte rgba[][4]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + + y = FLIP(context, y); + + while (n--) + { + int color = getpixel(bmp, x, y); + + rgba[0][RCOMP] = getr(color); + rgba[0][GCOMP] = getg(color); + rgba[0][BCOMP] = getb(color); + rgba[0][ACOMP] = 255; + + x++; rgba++; + } + } + + +static void write_rgba_pixels_generic(const GLcontext *ctx, + GLuint n, + const GLint x[], + const GLint y[], + const GLubyte rgba[][4], + const GLubyte mask[]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + + while (n--) + { + if (mask[0]) putpixel(bmp, x[0], FLIP(context, y[0]), makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP])); + x++; y++; mask++; + } + } + + +static void write_mono_rgba_pixels_generic(const GLcontext *ctx, + GLuint n, + const GLint x[], + const GLint y[], + const GLubyte mask[]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + int color = context->CurrentColor; + + while (n--) + { + if (mask[0]) putpixel(bmp, x[0], FLIP(context, y[0]), color); + x++; y++; mask++; + } + } + + +static void read_rgba_pixels_generic(const GLcontext *ctx, + GLuint n, + const GLint x[], + const GLint y[], + GLubyte rgba[][4], + const GLubyte mask[]) + { + AMesaContext context = (AMesaContext)(ctx->DriverCtx); + BITMAP *bmp = context->Buffer->Active; + + while (n--) + { + if (mask[0]) + { + int color = getpixel(bmp, x[0], FLIP(context, y[0])); + + rgba[0][RCOMP] = getr(color); + rgba[0][GCOMP] = getg(color); + rgba[0][BCOMP] = getb(color); + rgba[0][ACOMP] = 255; + } + + x++; y++; mask++; rgba++; + } + } + --- mesa-7.2.orig/src/mesa/drivers/windows/gdi/InitCritSections.cpp +++ mesa-7.2/src/mesa/drivers/windows/gdi/InitCritSections.cpp @@ -0,0 +1,32 @@ +#include "glapi.h" +#include "glThread.h" + +#ifdef WIN32_THREADS +extern "C" _glthread_Mutex OneTimeLock; +extern "C" _glthread_Mutex GenTexturesLock; + +extern "C" void FreeAllTSD(void); + +class _CriticalSectionInit +{ +public: + static _CriticalSectionInit m_inst; + + _CriticalSectionInit() + { + _glthread_INIT_MUTEX(OneTimeLock); + _glthread_INIT_MUTEX(GenTexturesLock); + } + + ~_CriticalSectionInit() + { + _glthread_DESTROY_MUTEX(OneTimeLock); + _glthread_DESTROY_MUTEX(GenTexturesLock); + FreeAllTSD(); + } +}; + +_CriticalSectionInit _CriticalSectionInit::m_inst; + + +#endif --- mesa-7.2.orig/src/mesa/drivers/windows/fx/fx.rc +++ mesa-7.2/src/mesa/drivers/windows/fx/fx.rc @@ -0,0 +1,39 @@ +#include + +#define PRODNAME "Mesa 6.x" +#define CONTACTSTR "http://www.mesa3d.org" +#define HWSTR "3dfx Voodoo Graphics, Voodoo Rush, Voodoo^2, Voodoo Banshee, Velocity 100/200, Voodoo3, Voodoo4, Voodoo5" +#define COPYRIGHTSTR "Copyright \251 Brian E. Paul" + +#define VERSIONSTR "6.3.0.1" +#define MANVERSION 6 +#define MANREVISION 3 +#define BUILD_NUMBER 1 + +VS_VERSION_INFO VERSIONINFO + FILEVERSION MANVERSION, MANREVISION, 0, BUILD_NUMBER + PRODUCTVERSION MANVERSION, MANREVISION, 0, BUILD_NUMBER + FILEFLAGSMASK 0x0030003FL + + FILEOS VOS_DOS_WINDOWS32 + FILETYPE VFT_DRV + FILESUBTYPE VFT2_DRV_INSTALLABLE +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileDescription", PRODNAME + VALUE "FileVersion", VERSIONSTR + VALUE "LegalCopyright", COPYRIGHTSTR + VALUE "ProductName", PRODNAME + VALUE "Graphics Subsystem", HWSTR + VALUE "Contact", CONTACTSTR + END + END + BLOCK "VarFileInfo" + BEGIN + /* the following line should be extended for localized versions */ + VALUE "Translation", 0x409, 1252 + END +END --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_pipeline_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_pipeline_dx7.c @@ -0,0 +1,77 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Mesa transformation pipeline with GLDirect fastpath +* +****************************************************************************/ + +//#include "../GLDirect.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx7.h" + +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +//--------------------------------------------------------------------------- + +extern struct tnl_pipeline_stage _gld_d3d_render_stage; +extern struct tnl_pipeline_stage _gld_mesa_render_stage; + +static const struct tnl_pipeline_stage *gld_pipeline[] = { + &_gld_d3d_render_stage, // Direct3D TnL + &_tnl_vertex_transform_stage, + &_tnl_normal_transform_stage, + &_tnl_lighting_stage, + &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage. ??? */ + &_tnl_texgen_stage, + &_tnl_texture_transform_stage, + &_tnl_point_attenuation_stage, + &_gld_mesa_render_stage, // Mesa TnL, D3D rendering + 0, +}; + +//--------------------------------------------------------------------------- + +void gldInstallPipeline_DX7( + GLcontext *ctx) +{ + // Remove any existing pipeline stages, + // then install GLDirect pipeline stages. + + _tnl_destroy_pipeline(ctx); + _tnl_install_pipeline(ctx, gld_pipeline); +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_ext_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_ext_dx7.c @@ -0,0 +1,346 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GL extensions +* +****************************************************************************/ + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "../gld_settings.h" + +#include +#define GL_GLEXT_PROTOTYPES +#include +#include + +//#include "ddlog.h" +//#include "gld_dx8.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "dglcontext.h" +#include "extensions.h" + +// For some reason this is not defined in an above header... +extern void _mesa_enable_imaging_extensions(GLcontext *ctx); + +//--------------------------------------------------------------------------- +// Hack for the SGIS_multitexture extension that was removed from Mesa +// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel + + // NOTE: Quake2 ran *slower* with this enabled, so I've + // disabled it for now. + // To enable, uncomment: + // _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); + +//--------------------------------------------------------------------------- + +enum { + /* Quake2 GL_SGIS_multitexture */ + GL_SELECTED_TEXTURE_SGIS = 0x835B, + GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835C, + GL_MAX_TEXTURES_SGIS = 0x835D, + GL_TEXTURE0_SGIS = 0x835E, + GL_TEXTURE1_SGIS = 0x835F, + GL_TEXTURE2_SGIS = 0x8360, + GL_TEXTURE3_SGIS = 0x8361, + GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, +}; + +//--------------------------------------------------------------------------- + +void APIENTRY gldSelectTextureSGIS( + GLenum target) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glActiveTextureARB(ARB_target); +} + +//--------------------------------------------------------------------------- + +void APIENTRY gldMTexCoord2fSGIS( + GLenum target, + GLfloat s, + GLfloat t) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glMultiTexCoord2fARB(ARB_target, s, t); +} + +//--------------------------------------------------------------------------- + +void APIENTRY gldMTexCoord2fvSGIS( + GLenum target, + const GLfloat *v) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glMultiTexCoord2fvARB(ARB_target, v); +} + +//--------------------------------------------------------------------------- +// Extensions +//--------------------------------------------------------------------------- + +typedef struct { + PROC proc; + char *name; +} GLD_extension; + +GLD_extension GLD_extList[] = { +#ifdef GL_EXT_polygon_offset + { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, +#endif + { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, + { (PROC)glBlendColorEXT, "glBlendColorExt" }, + { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, + { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, + { (PROC)glColorPointerEXT, "glColorPointerEXT" }, + { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, + { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, + { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, + { (PROC)glGetPointervEXT, "glGetPointervEXT" }, + { (PROC)glArrayElementEXT, "glArrayElementEXT" }, + { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, + { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, + { (PROC)glBindTextureEXT, "glBindTextureEXT" }, + { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, + { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, + { (PROC)glIsTextureEXT, "glIsTextureEXT" }, + { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, + { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, + { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, + { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, + { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, + { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, + + { (PROC)glLockArraysEXT, "glLockArraysEXT" }, + { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, + { NULL, "\0" } +}; + +GLD_extension GLD_multitexList[] = { +/* + { (PROC)glMultiTexCoord1dSGIS, "glMTexCoord1dSGIS" }, + { (PROC)glMultiTexCoord1dvSGIS, "glMTexCoord1dvSGIS" }, + { (PROC)glMultiTexCoord1fSGIS, "glMTexCoord1fSGIS" }, + { (PROC)glMultiTexCoord1fvSGIS, "glMTexCoord1fvSGIS" }, + { (PROC)glMultiTexCoord1iSGIS, "glMTexCoord1iSGIS" }, + { (PROC)glMultiTexCoord1ivSGIS, "glMTexCoord1ivSGIS" }, + { (PROC)glMultiTexCoord1sSGIS, "glMTexCoord1sSGIS" }, + { (PROC)glMultiTexCoord1svSGIS, "glMTexCoord1svSGIS" }, + { (PROC)glMultiTexCoord2dSGIS, "glMTexCoord2dSGIS" }, + { (PROC)glMultiTexCoord2dvSGIS, "glMTexCoord2dvSGIS" }, + { (PROC)glMultiTexCoord2fSGIS, "glMTexCoord2fSGIS" }, + { (PROC)glMultiTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, + { (PROC)glMultiTexCoord2iSGIS, "glMTexCoord2iSGIS" }, + { (PROC)glMultiTexCoord2ivSGIS, "glMTexCoord2ivSGIS" }, + { (PROC)glMultiTexCoord2sSGIS, "glMTexCoord2sSGIS" }, + { (PROC)glMultiTexCoord2svSGIS, "glMTexCoord2svSGIS" }, + { (PROC)glMultiTexCoord3dSGIS, "glMTexCoord3dSGIS" }, + { (PROC)glMultiTexCoord3dvSGIS, "glMTexCoord3dvSGIS" }, + { (PROC)glMultiTexCoord3fSGIS, "glMTexCoord3fSGIS" }, + { (PROC)glMultiTexCoord3fvSGIS, "glMTexCoord3fvSGIS" }, + { (PROC)glMultiTexCoord3iSGIS, "glMTexCoord3iSGIS" }, + { (PROC)glMultiTexCoord3ivSGIS, "glMTexCoord3ivSGIS" }, + { (PROC)glMultiTexCoord3sSGIS, "glMTexCoord3sSGIS" }, + { (PROC)glMultiTexCoord3svSGIS, "glMTexCoord3svSGIS" }, + { (PROC)glMultiTexCoord4dSGIS, "glMTexCoord4dSGIS" }, + { (PROC)glMultiTexCoord4dvSGIS, "glMTexCoord4dvSGIS" }, + { (PROC)glMultiTexCoord4fSGIS, "glMTexCoord4fSGIS" }, + { (PROC)glMultiTexCoord4fvSGIS, "glMTexCoord4fvSGIS" }, + { (PROC)glMultiTexCoord4iSGIS, "glMTexCoord4iSGIS" }, + { (PROC)glMultiTexCoord4ivSGIS, "glMTexCoord4ivSGIS" }, + { (PROC)glMultiTexCoord4sSGIS, "glMTexCoord4sSGIS" }, + { (PROC)glMultiTexCoord4svSGIS, "glMTexCoord4svSGIS" }, + { (PROC)glMultiTexCoordPointerSGIS, "glMTexCoordPointerSGIS" }, + { (PROC)glSelectTextureSGIS, "glSelectTextureSGIS" }, + { (PROC)glSelectTextureCoordSetSGIS, "glSelectTextureCoordSetSGIS" }, +*/ + { (PROC)glActiveTextureARB, "glActiveTextureARB" }, + { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, + { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, + { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, + { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, + { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, + { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, + { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, + { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, + { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, + { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, + { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, + { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, + { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, + { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, + { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, + { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, + { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, + { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, + { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, + { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, + { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, + { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, + { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, + { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, + { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, + { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, + { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, + { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, + { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, + { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, + { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, + { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, + { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, + + // Descent3 doesn't use correct string, hence this hack + { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4f" }, + + // Quake2 SGIS multitexture + { (PROC)gldSelectTextureSGIS, "glSelectTextureSGIS" }, + { (PROC)gldMTexCoord2fSGIS, "glMTexCoord2fSGIS" }, + { (PROC)gldMTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, + + { NULL, "\0" } +}; + +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_DX( + LPCSTR a) +{ + int i; + PROC proc = NULL; + + for (i=0; GLD_extList[i].proc; i++) { + if (!strcmp(a, GLD_extList[i].name)) { + proc = GLD_extList[i].proc; + break; + } + } + + if (glb.bMultitexture) { + for (i=0; GLD_multitexList[i].proc; i++) { + if (!strcmp(a, GLD_multitexList[i].name)) { + proc = GLD_multitexList[i].proc; + break; + } + } + } + + gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); + + return proc; +} + +//--------------------------------------------------------------------------- + +void gldEnableExtensions_DX7( + GLcontext *ctx) +{ + GLuint i; + + // Mesa enables some extensions by default. + // This table decides which ones we want to switch off again. + + // NOTE: GL_EXT_compiled_vertex_array appears broken. + + const char *gld_disable_extensions[] = { +// "GL_ARB_transpose_matrix", +// "GL_EXT_compiled_vertex_array", +// "GL_EXT_polygon_offset", +// "GL_EXT_rescale_normal", + "GL_EXT_texture3D", +// "GL_NV_texgen_reflection", + "GL_EXT_abgr", + "GL_EXT_bgra", + NULL + }; + + const char *gld_multitex_extensions[] = { + "GL_ARB_multitexture", // Quake 3 + NULL + }; + + // Quake 2 engines + const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture"; + + const char *gld_enable_extensions[] = { + "GL_EXT_texture_env_add", // Quake 3 + "GL_ARB_texture_env_add", // Quake 3 + NULL + }; + + for (i=0; gld_disable_extensions[i]; i++) { + _mesa_disable_extension(ctx, gld_disable_extensions[i]); + } + + for (i=0; gld_enable_extensions[i]; i++) { + _mesa_enable_extension(ctx, gld_enable_extensions[i]); + } + + if (glb.bMultitexture) { + for (i=0; gld_multitex_extensions[i]; i++) { + _mesa_enable_extension(ctx, gld_multitex_extensions[i]); + } + + // GL_SGIS_multitexture + // NOTE: Quake2 ran *slower* with this enabled, so I've + // disabled it for now. + // Fair bit slower on GeForce256, + // Much slower on 3dfx Voodoo5 5500. +// _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); + + } + + _mesa_enable_imaging_extensions(ctx); + _mesa_enable_1_3_extensions(ctx); + _mesa_enable_1_4_extensions(ctx); +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_dx7.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_dx7.h @@ -0,0 +1,292 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect Direct3D 7.0a header file +* +****************************************************************************/ + +#ifndef _GLD_DX7_H +#define _GLD_DX7_H + +//--------------------------------------------------------------------------- +// Windows includes +//--------------------------------------------------------------------------- + +#define DIRECTDRAW_VERSION 0x0700 +#define DIRECT3D_VERSION 0x0700 +#include +#include + +// Typedef for obtaining function from d3d7.dll +//typedef IDirect3D7* (WINAPI *FNDIRECT3DCREATE7) (UINT); + + +//--------------------------------------------------------------------------- +// Defines +//--------------------------------------------------------------------------- + +#ifdef _DEBUG +// Debug build tests the return value of D3D calls +#define _GLD_TEST_HRESULT(h) \ +{ \ + HRESULT _hr = (h); \ + if (FAILED(_hr)) { \ + gldLogError(GLDLOG_ERROR, #h, _hr); \ + } \ +} +#define _GLD_DX7(func) _GLD_TEST_HRESULT(IDirect3D7_##func##) +#define _GLD_DX7_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice7_##func##) +#define _GLD_DX7_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer7_##func##) +#define _GLD_DX7_TEX(func) _GLD_TEST_HRESULT(IDirectDrawSurface7_##func##) +#else +#define _GLD_DX7(func) IDirect3D7_##func +#define _GLD_DX7_DEV(func) IDirect3DDevice7_##func +#define _GLD_DX7_VB(func) IDirect3DVertexBuffer7_##func +#define _GLD_DX7_TEX(func) IDirectDrawSurface7_##func +#endif + +#define SAFE_RELEASE(p) \ +{ \ + if (p) { \ + (p)->lpVtbl->Release(p); \ + (p) = NULL; \ + } \ +} + +#define SAFE_RELEASE_VB7(p) \ +{ \ + if (p) { \ + IDirect3DVertexBuffer7_Release((p)); \ + (p) = NULL; \ + } \ +} + +#define SAFE_RELEASE_SURFACE7(p) \ +{ \ + if (p) { \ + IDirectDrawSurface7_Release((p)); \ + (p) = NULL; \ + } \ +} + +// Emulate some DX8 defines +#define D3DCOLOR_ARGB(a,r,g,b) ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) +#define D3DCOLOR_RGBA(r,g,b,a) D3DCOLOR_ARGB(a,r,g,b) +#define D3DCOLOR_COLORVALUE(r,g,b,a) D3DCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f)) + + +// Setup index. +enum { + GLD_SI_FLAT = 0, + GLD_SI_SMOOTH = 1, + GLD_SI_FLAT_EXTRAS = 2, + GLD_SI_SMOOTH_EXTRAS = 3, +}; + +//--------------------------------------------------------------------------- +// Vertex definitions for Fixed-Function pipeline +//--------------------------------------------------------------------------- + +// +// NOTE: If the number of texture units is altered then most of +// the texture code will need to be revised. +// + +#define GLD_MAX_TEXTURE_UNITS_DX7 2 + +// +// 2D vertex transformed by Mesa +// +#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \ + D3DFVF_DIFFUSE | \ + D3DFVF_SPECULAR | \ + D3DFVF_TEX2) +typedef struct { + FLOAT x, y; // 2D raster coords + FLOAT sz; // Screen Z (depth) + FLOAT rhw; // Reciprocal homogenous W + DWORD diffuse; // Diffuse colour + DWORD specular; // For separate-specular support + FLOAT t0_u, t0_v; // 1st set of texture coords + FLOAT t1_u, t1_v; // 2nd set of texture coords +} GLD_2D_VERTEX; + + +// +// 3D vertex transformed by Direct3D +// +#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \ + D3DFVF_DIFFUSE | \ + D3DFVF_TEX2) + +typedef struct { + D3DXVECTOR3 Position; // XYZ Vector in object space + D3DCOLOR Diffuse; // Diffuse colour + D3DXVECTOR2 TexUnit0; // Texture unit 0 + D3DXVECTOR2 TexUnit1; // Texture unit 1 +} GLD_3D_VERTEX; + +//--------------------------------------------------------------------------- +// Structs +//--------------------------------------------------------------------------- + +// This keeps a count of how many times we choose each individual internal +// pathway. Useful for seeing if a certain pathway was ever used by an app, and +// how much each pathway is biased. +// Zero the members at context creation and dump stats at context deletion. +typedef struct { + // Note: DWORD is probably too small + ULARGE_INTEGER qwMesa; // Mesa TnL pipeline + ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline +} GLD_pipeline_usage; + +// GLDirect Primitive Buffer (points, lines, triangles and quads) +typedef struct { + // Data for IDirect3D7::CreateVertexBuffer() + DWORD dwStride; // Stride of vertex + DWORD dwCreateFlags; // Create flags + DWORD dwFVF; // Direct3D Flexible Vertex Format + + IDirect3DVertexBuffer7 *pVB; // Holds points, lines, tris and quads. + + // Point list is assumed to be at start of buffer + DWORD iFirstLine; // Index of start of line list + DWORD iFirstTriangle; // Index of start of triangle list + + BYTE *pPoints; // Pointer to next free point + BYTE *pLines; // Pointer to next free line + BYTE *pTriangles; // Pointer to next free triangle + + DWORD nPoints; // Number of points ready to render + DWORD nLines; // Number of lines ready to render + DWORD nTriangles; // Number of triangles ready to render +} GLD_pb_dx7; + +// GLDirect DX7 driver data +typedef struct { + // GLDirect vars + BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered) + BOOL bDepthStencil; // Depth buffer needed (stencil optional) + D3DX_SURFACEFORMAT RenderFormat; // Format of back/front buffer + D3DX_SURFACEFORMAT DepthFormat; // Format of depth/stencil + + // Direct3D vars + DDCAPS ddCaps; + D3DDEVICEDESC7 d3dCaps; + BOOL bHasHWTnL; // Device has Hardware Transform/Light? + ID3DXContext *pD3DXContext; // Base D3DX context + IDirectDraw7 *pDD; // DirectDraw7 interface + IDirect3D7 *pD3D; // Base Direct3D7 interface + IDirect3DDevice7 *pDev; // Direct3D7 Device interface + GLD_pb_dx7 PB2d; // Vertices transformed by Mesa + GLD_pb_dx7 PB3d; // Vertices transformed by Direct3D + D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type + D3DMATRIX matProjection; // Projection matrix for D3D TnL + D3DMATRIX matModelView; // Model/View matrix for D3D TnL + int iSetupFunc; // Which setup functions to use + BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL + + GLD_pipeline_usage PipelineUsage; +} GLD_driver_dx7; + +#define GLD_GET_DX7_DRIVER(c) (GLD_driver_dx7*)(c)->glPriv + +//--------------------------------------------------------------------------- +// Function prototypes +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_DX7(LPCSTR a); +void gldEnableExtensions_DX7(GLcontext *ctx); +void gldInstallPipeline_DX7(GLcontext *ctx); +void gldSetupDriverPointers_DX7(GLcontext *ctx); +void gldResizeBuffers_DX7(GLframebuffer *fb); + + +// Texture functions + +void gldCopyTexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); +void gldCopyTexImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +void gldCopyTexSubImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ); +void gldCopyTexSubImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); +void gldCopyTexSubImage3D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); + +void gld_NEW_TEXTURE_DX7(GLcontext *ctx); +void gld_DrawPixels_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels); +void gld_ReadPixels_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest); +void gld_CopyPixels_DX7(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type); +void gld_Bitmap_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap); +const struct gl_texture_format* gld_ChooseTextureFormat_DX7(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType); +void gld_TexImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage); +void gld_TexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); +void gld_TexSubImage2D_DX7( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); +void gld_TexSubImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage); +void gld_DeleteTexture_DX7(GLcontext *ctx, struct gl_texture_object *tObj); +void gld_ResetLineStipple_DX7(GLcontext *ctx); + +// 2D primitive functions + +void gld_Points2D_DX7(GLcontext *ctx, GLuint first, GLuint last); + +void gld_Line2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Line2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1); + +void gld_Triangle2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DFlatExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmoothExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); + +void gld_Quad2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DFlatExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmoothExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +// 3D primitive functions + +void gld_Points3D_DX7(GLcontext *ctx, GLuint first, GLuint last); +void gld_Line3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Line3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +// Primitive functions for Two-sided-lighting Vertex Shader + +void gld_Points2DTwoside_DX7(GLcontext *ctx, GLuint first, GLuint last); +void gld_Line2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Line2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +#endif --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_texture_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_texture_dx7.c @@ -0,0 +1,2196 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Texture / Bitmap functions +* +****************************************************************************/ + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx7.h" + +//#include + +#include "texformat.h" +#include "colormac.h" +#include "texstore.h" +#include "image.h" +// #include "mem.h" + +//--------------------------------------------------------------------------- + +#define GLD_FLIP_HEIGHT(y,h) (gldCtx->dwHeight - (y) - (h)) + +D3DX_SURFACEFORMAT _gldD3DXFormatFromSurface(IDirectDrawSurface7 *pSurface); + +//--------------------------------------------------------------------------- +// 1D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + ((GLchan *)(t)->Data + (i) * (sz)) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + (i) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + (i)) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + (i)) + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// 2D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + ((GLchan *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + ((t)->Width * (j) + (i))) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + ((t)->Width * (j) + (i))) + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// 3D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i)) * (sz) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i)) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i))) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i))) + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// Direct3D texture formats that have no Mesa equivalent +//--------------------------------------------------------------------------- + +const struct gl_texture_format _gld_texformat_X8R8G8B8 = { + MESA_FORMAT_ARGB8888, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 8, /* RedBits */ + 8, /* GreenBits */ + 8, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 4, /* TexelBytes */ + _mesa_texstore_argb8888, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X8R8G8B8, /* FetchTexel1D */ + gld_fetch_2d_texel_X8R8G8B8, /* FetchTexel2D */ + gld_fetch_3d_texel_X8R8G8B8, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X8R8G8B8, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X8R8G8B8, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X8R8G8B8, /* FetchTexel3Df */ +}; + +const struct gl_texture_format _gld_texformat_X1R5G5B5 = { + MESA_FORMAT_ARGB1555, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 5, /* RedBits */ + 5, /* GreenBits */ + 5, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 2, /* TexelBytes */ + _mesa_texstore_argb1555, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X1R5G5B5, /* FetchTexel1D */ + gld_fetch_2d_texel_X1R5G5B5, /* FetchTexel2D */ + gld_fetch_3d_texel_X1R5G5B5, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X1R5G5B5, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X1R5G5B5, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X1R5G5B5, /* FetchTexel3Df */ +}; + +const struct gl_texture_format _gld_texformat_X4R4G4B4 = { + MESA_FORMAT_ARGB4444, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4, /* RedBits */ + 4, /* GreenBits */ + 4, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 2, /* TexelBytes */ + _mesa_texstore_argb4444, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X4R4G4B4, /* FetchTexel1D */ + gld_fetch_2d_texel_X4R4G4B4, /* FetchTexel2D */ + gld_fetch_3d_texel_X4R4G4B4, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X4R4G4B4, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X4R4G4B4, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X4R4G4B4, /* FetchTexel3Df */ +}; + +//--------------------------------------------------------------------------- +// Texture unit constants +//--------------------------------------------------------------------------- + +// List of possible combinations of texture environments. +// Example: GLD_TEXENV_MODULATE_RGBA means +// GL_MODULATE, GL_RGBA base internal format. +#define GLD_TEXENV_DECAL_RGB 0 +#define GLD_TEXENV_DECAL_RGBA 1 +#define GLD_TEXENV_DECAL_ALPHA 2 +#define GLD_TEXENV_REPLACE_RGB 3 +#define GLD_TEXENV_REPLACE_RGBA 4 +#define GLD_TEXENV_REPLACE_ALPHA 5 +#define GLD_TEXENV_MODULATE_RGB 6 +#define GLD_TEXENV_MODULATE_RGBA 7 +#define GLD_TEXENV_MODULATE_ALPHA 8 +#define GLD_TEXENV_BLEND_RGB 9 +#define GLD_TEXENV_BLEND_RGBA 10 +#define GLD_TEXENV_BLEND_ALPHA 11 +#define GLD_TEXENV_ADD_RGB 12 +#define GLD_TEXENV_ADD_RGBA 13 +#define GLD_TEXENV_ADD_ALPHA 14 + +// Per-stage (i.e. per-unit) texture environment +typedef struct { + DWORD ColorArg1; // Colour argument 1 + D3DTEXTUREOP ColorOp; // Colour operation + DWORD ColorArg2; // Colour argument 2 + DWORD AlphaArg1; // Alpha argument 1 + D3DTEXTUREOP AlphaOp; // Alpha operation + DWORD AlphaArg2; // Alpha argument 2 +} GLD_texenv; + +// TODO: Do we really need to set ARG1 and ARG2 every time? +// They seem to always be TEXTURE and CURRENT respectively. + +// C = Colour out +// A = Alpha out +// Ct = Colour from Texture +// Cf = Colour from fragment (diffuse) +// At = Alpha from Texture +// Af = Alpha from fragment (diffuse) +// Cc = GL_TEXTURE_ENV_COLOUR (GL_BLEND) +const GLD_texenv gldTexEnv[] = { + // DECAL_RGB: C=Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // DECAL_RGBA: C=Cf(1-At)+CtAt, A=Af + {D3DTA_TEXTURE, D3DTOP_BLENDTEXTUREALPHA, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // DECAL_ALPHA: use DECAL_RGB + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + + // REPLACE_RGB: C=Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // REPLACE_RGBA: C=Ct, A=At + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, + // REPLACE_ALPHA: C=Cf, A=At + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, + + // MODULATE_RGB: C=CfCt, A=Af + {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // MODULATE_RGBA: C=CfCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // MODULATE_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + + // + // DX7 Does not support D3DTOP_LERP + // Emulate(?) via D3DTOP_ADDSMOOTH + // +#if 0 + // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af + {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, +#else + // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af + {D3DTA_TEXTURE, D3DTOP_ADDSMOOTH, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_ADDSMOOTH, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, +#endif + // BLEND_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + + // ADD_RGB: C=Cf+Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // ADD_RGBA: C=Cf+Ct, A=AfAt + {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // ADD_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, +}; + +//--------------------------------------------------------------------------- + +D3DTEXTUREADDRESS _gldConvertWrap( + GLenum wrap) +{ +// ASSERT(wrap==GL_CLAMP || wrap==GL_REPEAT); + return (wrap == GL_CLAMP) ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP; +} + +//--------------------------------------------------------------------------- + +D3DTEXTUREMAGFILTER _gldConvertMagFilter( + GLenum magfilter) +{ + ASSERT(magfilter==GL_LINEAR || magfilter==GL_NEAREST); + return (magfilter == GL_LINEAR) ? D3DTFG_LINEAR : D3DTFG_POINT; +} + +//--------------------------------------------------------------------------- + +void _gldConvertMinFilter( + GLenum minfilter, + D3DTEXTUREMINFILTER *min_filter, + D3DTEXTUREMIPFILTER *mip_filter) +{ + switch (minfilter) { + case GL_NEAREST: + *min_filter = D3DTFN_POINT; + *mip_filter = D3DTFP_NONE; + break; + case GL_LINEAR: + *min_filter = D3DTFN_LINEAR; + *mip_filter = D3DTFP_NONE; + break; + case GL_NEAREST_MIPMAP_NEAREST: + *min_filter = D3DTFN_POINT; + *mip_filter = D3DTFP_POINT; + break; + case GL_LINEAR_MIPMAP_NEAREST: + *min_filter = D3DTFN_LINEAR; + *mip_filter = D3DTFP_POINT; + break; + case GL_NEAREST_MIPMAP_LINEAR: + *min_filter = D3DTFN_POINT; + *mip_filter = D3DTFP_LINEAR; + break; + case GL_LINEAR_MIPMAP_LINEAR: + *min_filter = D3DTFN_LINEAR; + *mip_filter = D3DTFP_LINEAR; + break; + default: + ASSERT(0); + } +} + +//--------------------------------------------------------------------------- + +D3DX_SURFACEFORMAT _gldGLFormatToD3DFormat( + GLenum internalFormat) +{ + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + // LUNIMANCE != INTENSITY, but D3D doesn't have I8 textures + return D3DX_SF_L8; + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + return D3DX_SF_L8; + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + return D3DX_SF_A8; + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return D3DX_SF_X8R8G8B8; + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return D3DX_SF_A8L8; + case GL_R3_G3_B2: + // TODO: Mesa does not support RGB332 internally + return D3DX_SF_X4R4G4B4; //D3DFMT_R3G3B2; + case GL_RGB4: + return D3DX_SF_X4R4G4B4; + case GL_RGB5: + return D3DX_SF_R5G5B5; + case 3: + case GL_RGB: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return D3DX_SF_R8G8B8; + case GL_RGBA4: + return D3DX_SF_A4R4G4B4; + case 4: + case GL_RGBA: + case GL_RGBA2: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return D3DX_SF_A8R8G8B8; + case GL_RGB5_A1: + return D3DX_SF_A1R5G5B5; + } + + ASSERT(0); + + // Return an acceptable default + return D3DX_SF_A8R8G8B8; +} + +//--------------------------------------------------------------------------- + +GLenum _gldDecodeBaseFormat( + IDirectDrawSurface7 *pTex) +{ + // Examine Direct3D texture and return base OpenGL internal texture format + // NOTE: We can't use any base format info from Mesa because D3D might have + // used a different texture format when we used D3DXCreateTexture(). + + // Base internal format is one of (Red Book p355): + // GL_ALPHA, + // GL_LUMINANCE, + // GL_LUMINANCE_ALPHA, + // GL_INTENSITY, + // GL_RGB, + // GL_RGBA + + // NOTE: INTENSITY not used (not supported by Direct3D) + // LUMINANCE has same texture functions as RGB + // LUMINANCE_ALPHA has same texture functions as RGBA + + // TODO: cache format instead of using GetLevelDesc() +// D3DSURFACE_DESC desc; +// _GLD_DX7_TEX(GetLevelDesc(pTex, 0, &desc)); + + D3DX_SURFACEFORMAT sf; + + sf = _gldD3DXFormatFromSurface(pTex); + + switch (sf) { + case D3DX_SF_R8G8B8: + case D3DX_SF_X8R8G8B8: + case D3DX_SF_R5G6B5: + case D3DX_SF_R5G5B5: + case D3DX_SF_R3G3B2: + case D3DX_SF_X4R4G4B4: + case D3DX_SF_PALETTE8: + case D3DX_SF_L8: + return GL_RGB; + case D3DX_SF_A8R8G8B8: + case D3DX_SF_A1R5G5B5: + case D3DX_SF_A4R4G4B4: +// case D3DX_SF_A8R3G3B2: // Unsupported by DX7 +// case D3DX_SF_A8P8: // Unsupported by DX7 + case D3DX_SF_A8L8: +// case D3DX_SF_A4L4: // Unsupported by DX7 + return GL_RGBA; + case D3DX_SF_A8: + return GL_ALPHA; + // Compressed texture formats. Need to check these... + case D3DX_SF_DXT1: + return GL_RGBA; +// case D3DX_SF_DXT2: // Unsupported by DX7 + return GL_RGB; + case D3DX_SF_DXT3: + return GL_RGBA; +// case D3DX_SF_DXT4: // Unsupported by DX7 + return GL_RGB; + case D3DX_SF_DXT5: + return GL_RGBA; + } + + // Fell through. Return arbitary default. + ASSERT(0); // BANG! + return GL_RGBA; +} + +//--------------------------------------------------------------------------- + +const struct gl_texture_format* _gldMesaFormatForD3DFormat( + D3DX_SURFACEFORMAT d3dfmt) +{ + switch (d3dfmt) { + case D3DX_SF_A8R8G8B8: + return &_mesa_texformat_argb8888; + case D3DX_SF_R8G8B8: + return &_mesa_texformat_rgb888; + case D3DX_SF_R5G6B5: + return &_mesa_texformat_rgb565; + case D3DX_SF_A4R4G4B4: + return &_mesa_texformat_argb4444; + case D3DX_SF_A1R5G5B5: + return &_mesa_texformat_argb1555; + case D3DX_SF_A8L8: + return &_mesa_texformat_al88; + case D3DX_SF_R3G3B2: + return &_mesa_texformat_rgb332; + case D3DX_SF_A8: + return &_mesa_texformat_a8; + case D3DX_SF_L8: + return &_mesa_texformat_l8; + case D3DX_SF_X8R8G8B8: + return &_gld_texformat_X8R8G8B8; + case D3DX_SF_R5G5B5: + return &_gld_texformat_X1R5G5B5; + case D3DX_SF_X4R4G4B4: + return &_gld_texformat_X4R4G4B4; + } + + // If we reach here then we've made an error somewhere else + // by allowing a format that is not supported. + ASSERT(0); + + return NULL; // Shut up compiler warning +} + +//--------------------------------------------------------------------------- + +D3DX_SURFACEFORMAT _gldD3DXFormatFromSurface( + IDirectDrawSurface7 *pSurface) +{ + DDPIXELFORMAT ddpf; + + ddpf.dwSize = sizeof(ddpf); + + // Obtain pixel format of surface + _GLD_DX7_TEX(GetPixelFormat(pSurface, &ddpf)); + // Decode to D3DX surface format + return D3DXMakeSurfaceFormat(&ddpf); +} + +//--------------------------------------------------------------------------- + +void _gldClearSurface( + IDirectDrawSurface *pSurface, + D3DCOLOR dwColour) +{ + DDBLTFX bltFX; // Used for colour fill + + // Initialise struct + bltFX.dwSize = sizeof(bltFX); + // Set clear colour + bltFX.dwFillColor = dwColour; + // Clear surface. HW accelerated if available. + IDirectDrawSurface7_Blt(pSurface, NULL, NULL, NULL, DDBLT_COLORFILL, &bltFX); +} + +//--------------------------------------------------------------------------- +// Copy* functions +//--------------------------------------------------------------------------- + +void gldCopyTexImage1D_DX7( + GLcontext *ctx, + GLenum target, GLint level, + GLenum internalFormat, + GLint x, GLint y, + GLsizei width, GLint border ) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexImage2D_DX7( + GLcontext *ctx, + GLenum target, + GLint level, + GLenum internalFormat, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + GLint border) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage1D_DX7( + GLcontext *ctx, + GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, GLsizei width ) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage2D_DX7( + GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage3D_DX7( + GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height ) +{ + // TODO ? +} + +//--------------------------------------------------------------------------- +// Bitmap/Pixel functions +//--------------------------------------------------------------------------- + +#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) + +#define _GLD_FVF_IMAGE (D3DFVF_XYZRHW | D3DFVF_TEX1) + +typedef struct { + FLOAT x, y; // 2D raster coords + FLOAT z; // depth value + FLOAT rhw; // reciprocal homogenous W (always 1.0f) + FLOAT tu, tv; // texture coords +} _GLD_IMAGE_VERTEX; + +//--------------------------------------------------------------------------- + +HRESULT _gldDrawPixels( + GLcontext *ctx, + BOOL bChromakey, // Alpha test for glBitmap() images + GLint x, // GL x position + GLint y, // GL y position (needs flipping) + GLsizei width, // Width of input image + GLsizei height, // Height of input image + IDirectDrawSurface7 *pImage) +{ + // + // Draw input image as texture implementing PixelZoom and clipping. + // Any fragment operations currently enabled will be used. + // + + // NOTE: This DX7 version does not create a new texture in which + // to copy the input image, as the image is already a texture. + + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + DDSURFACEDESC2 ddsd; + _GLD_IMAGE_VERTEX v[4]; + + float ZoomWidth, ZoomHeight; + float ScaleWidth, ScaleHeight; + + // Fixup for rasterisation rules + const float cfEpsilon = 1.0f / (float)height; + + // + // Set up the quad like this (ascii-art ahead!) + // + // 3--2 + // | | + // 0--1 + // + // + + // Set depth + v[0].z = v[1].z = v[2].z = v[3].z = ctx->Current.RasterPos[2]; + // Set Reciprocal Homogenous W + v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.0f; + + // Set texcoords + // Examine texture size - if different to input width and height + // then we'll need to munge the texcoords to fit. + ddsd.dwSize = sizeof(DDSURFACEDESC2); + IDirectDrawSurface7_GetSurfaceDesc(pImage, &ddsd); + ScaleWidth = (float)width / (float)ddsd.dwWidth; + ScaleHeight = (float)height / (float)ddsd.dwHeight; + v[0].tu = 0.0f; v[0].tv = 0.0f; + v[1].tu = ScaleWidth; v[1].tv = 0.0f; + v[2].tu = ScaleWidth; v[2].tv = ScaleHeight; + v[3].tu = 0.0f; v[3].tv = ScaleHeight; + + // Set raster positions + ZoomWidth = (float)width * ctx->Pixel.ZoomX; + ZoomHeight = (float)height * ctx->Pixel.ZoomY; + + v[0].x = x; v[0].y = GLD_FLIP_Y(y+cfEpsilon); + v[1].x = x+ZoomWidth; v[1].y = GLD_FLIP_Y(y+cfEpsilon); + v[2].x = x+ZoomWidth; v[2].y = GLD_FLIP_Y(y+ZoomHeight+cfEpsilon); + v[3].x = x; v[3].y = GLD_FLIP_Y(y+ZoomHeight+cfEpsilon); + + // Draw image with full HW acceleration + // NOTE: Be nice to use a State Block for all this state... + IDirect3DDevice7_SetTexture(gld->pDev, 0, pImage); + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, TRUE); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_MINFILTER, D3DTFN_POINT); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_MIPFILTER, D3DTFP_POINT); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_MAGFILTER, D3DTFG_POINT); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + // Ensure texture unit 1 is disabled + IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + + // + // Emulate Chromakey with an Alpha Test. + // [Alpha Test is more widely supported anyway] + // + if (bChromakey) { + // Switch on alpha testing + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE); + // Fragment passes is alpha is greater than reference value + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAFUNC, D3DCMP_GREATER); + // Set alpha reference value between Bitmap alpha values of + // zero (transparent) and one (opaque). + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAREF, 0x7f); + } + + IDirect3DDevice7_DrawPrimitive(gld->pDev, D3DPT_TRIANGLEFAN, _GLD_FVF_IMAGE, &v, 4, 0); + + // Reset state to before we messed it up + FLUSH_VERTICES(ctx, _NEW_ALL); + + return S_OK; +} + +//--------------------------------------------------------------------------- + +void gld_DrawPixels_DX7( + GLcontext *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels ) +{ + GLD_context *gldCtx; + GLD_driver_dx7 *gld; + + IDirectDrawSurface7 *pImage; + HRESULT hr; + DDSURFACEDESC2 ddsd; + DWORD dwFlags; + D3DX_SURFACEFORMAT sf; + DWORD dwMipmaps; + + const struct gl_texture_format *MesaFormat; + + MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX7_DRIVER(gldCtx); + + dwFlags = D3DX_TEXTURE_NOMIPMAP; + sf = D3DX_SF_A8R8G8B8; + dwMipmaps = 1; + + hr = D3DXCreateTexture( + gld->pDev, + &dwFlags, + &width, &height, + &sf, // format + NULL, // palette + &pImage, // Output texture + &dwMipmaps); + if (FAILED(hr)) { + return; + } + + // D3DXCreateTexture() may not clear the texture is creates. + _gldClearSurface(pImage, 0); + + // + // Use Mesa to fill in image + // + + // Lock all of surface + ddsd.dwSize = sizeof(DDSURFACEDESC2); + dwFlags = DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT; + hr = IDirectDrawSurface7_Lock(pImage, NULL, &ddsd, dwFlags, NULL); + if (FAILED(hr)) { + SAFE_RELEASE_SURFACE7(pImage); + return; + } + + // unpack image, apply transfer ops and store directly in texture + MesaFormat->StoreImage( + ctx, + 2, + GL_RGBA, + &_mesa_texformat_argb8888, + ddsd.lpSurface, + width, height, 1, 0, 0, 0, + ddsd.lPitch, + 0, /* dstImageStride */ + format, type, pixels, unpack); + + IDirectDrawSurface7_Unlock(pImage, NULL); + + _gldDrawPixels(ctx, FALSE, x, y, width, height, pImage); + + SAFE_RELEASE_SURFACE7(pImage); +} + +//--------------------------------------------------------------------------- + +void gld_ReadPixels_DX7( + GLcontext *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest) +{ +// TODO +#if 0 + GLD_context *gldCtx; + GLD_driver_dx7 *gld; + + IDirect3DSurface8 *pBackbuffer = NULL; + IDirect3DSurface8 *pNativeImage = NULL; + IDirect3DSurface8 *pCanonicalImage = NULL; + + D3DSURFACE_DESC d3dsd; + RECT rcSrc; // Source rect + POINT ptDst; // Dest point + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + struct gl_pixelstore_attrib srcPacking; + int i; + GLint DstRowStride; + const struct gl_texture_format *MesaFormat; + + switch (format) { + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + return; + } + + MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); + DstRowStride = _mesa_image_row_stride(pack, width, format, type); + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX7_DRIVER(gldCtx); + + // Get backbuffer + hr = IDirect3DDevice8_GetBackBuffer( + gld->pDev, + 0, // First backbuffer + D3DBACKBUFFER_TYPE_MONO, + &pBackbuffer); + if (FAILED(hr)) + return; + + // Get backbuffer description + hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); + if (FAILED(hr)) { + goto gld_ReadPixels_DX7_return; + } + + // Create a surface compatible with backbuffer + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + d3dsd.Format, + &pNativeImage); + if (FAILED(hr)) { + goto gld_ReadPixels_DX7_return; + } + + // Compute source rect and dest point + SetRect(&rcSrc, 0, 0, width, height); + OffsetRect(&rcSrc, x, GLD_FLIP_HEIGHT(y, height)); + ptDst.x = ptDst.y = 0; + + // Get source pixels. + // + // This intermediate surface ensure that we can use CopyRects() + // instead of relying on D3DXLoadSurfaceFromSurface(), which may + // try and lock the backbuffer. This way seems safer. + // + hr = IDirect3DDevice8_CopyRects( + gld->pDev, + pBackbuffer, + &rcSrc, + 1, + pNativeImage, + &ptDst); + if (FAILED(hr)) { + goto gld_ReadPixels_DX7_return; + } + + // Create an RGBA8888 surface + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + &pCanonicalImage); + if (FAILED(hr)) { + goto gld_ReadPixels_DX7_return; + } + + // Convert to RGBA8888 + hr = D3DXLoadSurfaceFromSurface( + pCanonicalImage, // Dest surface + NULL, NULL, // Dest palette, RECT + pNativeImage, // Src surface + NULL, NULL, // Src palette, RECT + D3DX_FILTER_NONE, // Filter + 0); // Colourkey + if (FAILED(hr)) { + goto gld_ReadPixels_DX7_return; + } + + srcPacking.Alignment = 1; + srcPacking.ImageHeight = height; + srcPacking.LsbFirst = GL_FALSE; + srcPacking.RowLength = 0; + srcPacking.SkipImages = 0; + srcPacking.SkipPixels = 0; + srcPacking.SkipRows = 0; + srcPacking.SwapBytes = GL_FALSE; + + // Lock all of image + hr = IDirect3DSurface8_LockRect(pCanonicalImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + goto gld_ReadPixels_DX7_return; + } + + // We need to flip the data. Yuck. + // Perhaps Mesa has a span packer we can use in future... + for (i=0; iTexFormat->StoreImage( + ctx, + 2, + GL_RGBA, // base format + MesaFormat, // dst format + pDestRow, // dest addr + width, 1, 1, 0, 0, 0, // src x,y,z & dst offsets x,y,z + DstRowStride, // dst row stride + 0, // dstImageStride + GL_BGRA, // src format + GL_UNSIGNED_BYTE, // src type + pSrcRow, // src addr + &srcPacking); // packing params of source image + } + + IDirect3DSurface8_UnlockRect(pCanonicalImage); + +gld_ReadPixels_DX7_return: + SAFE_RELEASE_SURFACE8(pCanonicalImage); + SAFE_RELEASE_SURFACE8(pNativeImage); + SAFE_RELEASE_SURFACE8(pBackbuffer); +#endif +} + +//--------------------------------------------------------------------------- + +void gld_CopyPixels_DX7( + GLcontext *ctx, + GLint srcx, + GLint srcy, + GLsizei width, + GLsizei height, + GLint dstx, + GLint dsty, + GLenum type) +{ +// TODO +#if 0 + // + // NOTE: Not allowed to copy vidmem to vidmem! + // Therefore we use an intermediate image surface. + // + + GLD_context *gldCtx; + GLD_driver_dx7 *gld; + + IDirect3DSurface8 *pBackbuffer; + D3DSURFACE_DESC d3dsd; + IDirect3DSurface8 *pImage; + RECT rcSrc; // Source rect + POINT ptDst; // Dest point + HRESULT hr; + + // Only backbuffer + if (type != GL_COLOR) + return; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX7_DRIVER(gldCtx); + + // Get backbuffer + hr = IDirect3DDevice8_GetBackBuffer( + gld->pDev, + 0, // First backbuffer + D3DBACKBUFFER_TYPE_MONO, + &pBackbuffer); + if (FAILED(hr)) + return; + + // Get backbuffer description + hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pBackbuffer); + return; + } + + // Create a surface compatible with backbuffer + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + d3dsd.Format, + &pImage); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pBackbuffer); + return; + } + + // Compute source rect and dest point + SetRect(&rcSrc, 0, 0, width, height); + OffsetRect(&rcSrc, srcx, GLD_FLIP_HEIGHT(srcy, height)); + ptDst.x = ptDst.y = 0; + + // Get source pixels + hr = IDirect3DDevice8_CopyRects( + gld->pDev, + pBackbuffer, + &rcSrc, + 1, + pImage, + &ptDst); + IDirect3DSurface8_Release(pBackbuffer); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pImage); + return; + } + + _gldDrawPixels(ctx, FALSE, dstx, dsty, width, height, pImage); + + IDirect3DSurface8_Release(pImage); +#endif +} + +//--------------------------------------------------------------------------- + +void gld_Bitmap_DX7( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap) +{ + GLD_context *gldCtx; + GLD_driver_dx7 *gld; + + IDirectDrawSurface7 *pImage; // Bitmap texture + HRESULT hr; + BYTE *pTempBitmap; // Pointer to unpacked bitmap + D3DCOLOR clBitmapOne; // Opaque bitmap colour + D3DCOLOR clBitmapZero; // Transparent bitmap colour + D3DCOLOR *pBits; // Pointer to texture surface + const GLubyte *src; + int i, j, k; + + DDSURFACEDESC2 ddsd; // Surface desc returned by lock call + DWORD dwFlags; + D3DX_SURFACEFORMAT sf; + DWORD dwMipmaps; + + // Keep a copy of width/height as D3DXCreateTexture() call may alter input dimensions + GLsizei dwWidth = width; + GLsizei dwHeight = height; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX7_DRIVER(gldCtx); + + // Bail if no bitmap (only raster pos is updated) + if ((bitmap == NULL) && (width==0) && (height==0)) + return; + + // + // TODO: Detect conditions when created texture (pImage) is non-pow2. + // Texture coords may need to be adjusted to compensate. + // + + clBitmapZero = D3DCOLOR_RGBA(0,0,0,0); // NOTE: Alpha is Zero + clBitmapOne = D3DCOLOR_COLORVALUE( + ctx->Current.RasterColor[0], + ctx->Current.RasterColor[1], + ctx->Current.RasterColor[2], + 1.0f); // NOTE: Alpha is One + + // Use Mesa to unpack bitmap into a canonical format + pTempBitmap = _mesa_unpack_bitmap(width, height, bitmap, unpack); + if (pTempBitmap == NULL) + return; + + // Flags for texture creation + dwFlags = D3DX_TEXTURE_NOMIPMAP; + sf = D3DX_SF_A8R8G8B8; + dwMipmaps = 1; + + // Create a D3D texture to hold the bitmap + hr = D3DXCreateTexture( + gld->pDev, + &dwFlags, + &dwWidth, &dwHeight, + &sf, // format + NULL, // palette + &pImage, // Output texture + &dwMipmaps); + if (FAILED(hr)) { + FREE(pTempBitmap); + return; + } + + // D3DXCreateTexture may return a texture bigger than we asked for + // (i.e. padded to POW2) so let's clear the entire image bitmap. + // Additional: Looks like this is not strictly necessary. +// _gldClearSurface(pImage, clBitmapZero); + + ddsd.dwSize = sizeof(DDSURFACEDESC2); + dwFlags = DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT; + hr = IDirectDrawSurface7_Lock(pImage, NULL, &ddsd, dwFlags, NULL); + if (FAILED(hr)) { + FREE(pTempBitmap); + SAFE_RELEASE_SURFACE7(pImage); + return; + } + +#if 0 + // DEBUG CODE + if (!(width==ddsd.dwWidth && height==ddsd.dwHeight)) + ddlogPrintf(GLDLOG_WARN, "gld_Bitmap: In=%d,%d / Tex=%d,%d", width,height,ddsd.dwWidth,ddsd.dwHeight); +#endif + +#if 0 + // DEBUG CODE + ddlogPrintf(GLDLOG_SYSTEM, "gld_Bitmap: In=%d,%d / Tex=%d,%d", width,height,ddsd.dwWidth,ddsd.dwHeight); + ddlogPrintf(GLDLOG_SYSTEM, "gld_Bitmap: bpp=%d", ddsd.ddpfPixelFormat.dwRGBBitCount); +#endif + + // Cast texel pointer to texture surface. + // We can do this because we used D3DX_SF_A8R8G8B8 as the format + pBits = (D3DCOLOR*)ddsd.lpSurface; + + + // Copy from the input bitmap into the texture + for (i=0; iDefaultPacking, pTempBitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, + 0, i, 0); + for (j=0; j<(width>>3); j++) { + byte = *src++; + for (k=0; k<8; k++) { + *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; + byte <<= 1; + } + } + // Fill remaining bits from bitmap + if (width & 7) { + byte = *src; + for (k=0; k<(width & 7); k++) { + *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; + byte <<= 1; + } + } + } + + // We're done with the unpacked bitmap + FREE(pTempBitmap); + + // Finished with texture surface - unlock it + IDirectDrawSurface7_Unlock(pImage, NULL); + + // Use internal function to draw bitmap onto rendertarget + _gldDrawPixels(ctx, TRUE, x, y, width, height, pImage); + + // We're done with the bitmap texure - release it + IDirectDrawSurface7_Release(pImage); +} + +//--------------------------------------------------------------------------- +// Texture functions +//--------------------------------------------------------------------------- + +void _gldAllocateTexture( + GLcontext *ctx, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + HRESULT hr; + IDirectDrawSurface7 *pTex; + D3DX_SURFACEFORMAT d3dFormat; + DWORD dwFlags; + DWORD dwMipmaps; + DWORD dwWidth, dwHeight; + + if (!tObj || !texImage) + return; + + pTex = (IDirectDrawSurface7*)tObj->DriverData; + if (pTex) { + // Decide whether we can keep existing D3D texture + // by examining top-level surface. + DDSURFACEDESC2 ddsd; + ddsd.dwSize = sizeof(DDSURFACEDESC2); + _GLD_DX7_TEX(GetSurfaceDesc(pTex, &ddsd)); + // Release existing texture if not compatible + if ((ddsd.dwWidth == texImage->Width) || + (ddsd.dwHeight == texImage->Height)) + { + return; // Keep the existing texture + } + tObj->DriverData = NULL; + _GLD_DX7_TEX(Release(pTex)); + } + + dwFlags = (glb.bUseMipmaps) ? 0 : D3DX_TEXTURE_NOMIPMAP; + dwMipmaps = (glb.bUseMipmaps) ? D3DX_DEFAULT : 1; + dwWidth = texImage->Width; + dwHeight = texImage->Height; + + d3dFormat = _gldGLFormatToD3DFormat(texImage->IntFormat); + hr = D3DXCreateTexture( + gld->pDev, + &dwFlags, + &dwWidth, + &dwHeight, + &d3dFormat, + NULL, + &pTex, + &dwMipmaps); + if (FAILED(hr)) { + gldLogError(GLDLOG_ERROR, "AllocateTexture failed", hr); + } + tObj->DriverData = pTex; +} + +//--------------------------------------------------------------------------- + +const struct gl_texture_format* gld_ChooseTextureFormat_DX7( + GLcontext *ctx, + GLint internalFormat, + GLenum srcFormat, + GLenum srcType) +{ + // [Based on mesa_choose_tex_format()] + // + // We will choose only texture formats that are supported + // by Direct3D. If the hardware doesn't support a particular + // texture format, then the D3DX texture calls that we use + // will automatically use a HW supported format. + // + // The most critical aim is to reduce copying; if we can use + // texture-image data directly then it will be a big performance assist. + // + + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + return &_mesa_texformat_l8; // D3DFMT_L8 + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + return &_mesa_texformat_l8; // D3DFMT_L8 + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + return &_mesa_texformat_a8; // D3DFMT_A8 + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return &_mesa_texformat_rgb565; // D3DFMT_R5G6B5 + // Mesa will convert this for us later... + // return &_mesa_texformat_ci8; // D3DFMT_R5G6B5 + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return &_mesa_texformat_al88; // D3DFMT_A8L8 + case GL_R3_G3_B2: + return &_mesa_texformat_rgb332; // D3DFMT_R3G3B2 + case GL_RGB4: + case GL_RGBA4: + case GL_RGBA2: + return &_mesa_texformat_argb4444; // D3DFMT_A4R4G4B4 + case 3: + case GL_RGB: + case GL_RGB5: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return &_mesa_texformat_rgb565; + case 4: + case GL_RGBA: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return &_mesa_texformat_argb8888; + case GL_RGB5_A1: + return &_mesa_texformat_argb1555; + default: + _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat"); + return NULL; + } +} + +//--------------------------------------------------------------------------- + +/* +// Safer(?), slower version. +void gld_TexImage2D_DX7( + GLcontext *ctx, + GLenum target, + GLint level, + GLint internalFormat, + GLint width, + GLint height, + GLint border, + GLenum format, + GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + IDirect3DTexture8 *pTex; + IDirect3DSurface8 *pSurface; + RECT rcSrcRect; + HRESULT hr; + GLint texelBytes = 4; + GLvoid *tempImage; + + if (!tObj || !texImage) + return; + + if (level == 0) { + _gldAllocateTexture(ctx, tObj, texImage); + } + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture8_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + tempImage = MALLOC(width * height * texelBytes); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); + IDirect3DSurface8_Release(pSurface); + return; + } + // unpack image, apply transfer ops and store in tempImage + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + &_mesa_texformat_argb8888, // dest format + tempImage, + width, height, 1, 0, 0, 0, + width * texelBytes, + 0, // dstImageStride + format, type, pixels, packing); + + SetRect(&rcSrcRect, 0, 0, width, height); + D3DXLoadSurfaceFromMemory( + pSurface, + NULL, + NULL, + tempImage, + D3DFMT_A8R8G8B8, + width * texelBytes, + NULL, + &rcSrcRect, + D3DX_FILTER_NONE, + 0); + + FREE(tempImage); + IDirect3DSurface8_Release(pSurface); +} +*/ + +//--------------------------------------------------------------------------- + +// Faster, more efficient version. +// Copies subimage straight to dest texture +void gld_TexImage2D_DX7( + GLcontext *ctx, + GLenum target, + GLint level, + GLint internalFormat, + GLint width, + GLint height, + GLint border, + GLenum format, + GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + IDirectDrawSurface7 *pTex = NULL; + IDirectDrawSurface7 *pSurface = NULL; + HRESULT hr; + DDSURFACEDESC2 ddsd; + int i; + DDSCAPS2 ddsCaps; + + if (!tObj || !texImage) + return; + + // GLQUAKE FIX + // Test for input alpha data with non-alpha internalformat + if (((internalFormat==3) || (internalFormat==GL_RGB)) && (format==GL_RGBA)) { + // Input format has alpha, but a non-alpha format has been requested. + texImage->IntFormat = GL_RGBA; + internalFormat = GL_RGBA; + } + + if (level == 0) { + _gldAllocateTexture(ctx, tObj, texImage); + } + + pTex = (IDirectDrawSurface7*)tObj->DriverData; + if (!pTex) { + ASSERT(0); + return; // Texture has not been created + } + + pSurface = pTex; + if (level != 0) { + ddsd.dwSize = sizeof(ddsd); + _GLD_DX7_TEX(GetSurfaceDesc(pTex, &ddsd)); + if ((level > 0) && (level >= ddsd.dwMipMapCount)) + return; // Level does not exist + ZeroMemory(&ddsCaps, sizeof(ddsCaps)); + for (i=0; iTexFormat->StoreImage( + ctx, + 2, + texImage->Format, + //_gldMesaFormatForD3DFormat(d3dsd.Format), + _gldMesaFormatForD3DFormat(_gldD3DXFormatFromSurface(pSurface)), + ddsd.lpSurface, + width, height, 1, 0, 0, 0, + ddsd.lPitch, + 0, // dstImageStride + format, type, pixels, packing); + + IDirectDrawSurface7_Unlock(pSurface, NULL); +} + +//--------------------------------------------------------------------------- + +void gld_TexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint border, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + // A 1D texture is a 2D texture with a height of zero + gld_TexImage2D_DX7(ctx, target, level, internalFormat, width, 1, border, format, type, pixels, packing, texObj, texImage); +} + +//--------------------------------------------------------------------------- + +/* +void gld_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage ) +{ + GLD_GET_CONTEXT + IDirect3DTexture8 *pTex; + IDirect3DSurface8 *pSurface; + D3DFORMAT d3dFormat; + HRESULT hr; + GLint texelBytes = 4; + GLvoid *tempImage; + RECT rcSrcRect; + RECT rcDstRect; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= _GLD_DX8_TEX(GetLevelCount(pTex)) + return; // Level does not exist + hr = _GLD_DX8_TEX(GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + d3dFormat = _gldGLFormatToD3DFormat(texImage->Format); + tempImage = MALLOC(width * height * texelBytes); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); + IDirect3DSurface8_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store in tempImage + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + &_mesa_texformat_argb8888, // dest format + tempImage, + width, height, 1, 0, 0, 0, + width * texelBytes, + 0, // dstImageStride + format, type, pixels, packing); + + // Source rectangle is whole of input image + SetRect(&rcSrcRect, 0, 0, width, height); + + // Dest rectangle must be offset to dest image + SetRect(&rcDstRect, 0, 0, width, height); + OffsetRect(&rcDstRect, xoffset, yoffset); + + D3DXLoadSurfaceFromMemory( + pSurface, + NULL, + &rcDstRect, + tempImage, + D3DFMT_A8R8G8B8, + width * texelBytes, + NULL, + &rcSrcRect, + D3DX_FILTER_NONE, + 0); + + FREE(tempImage); + IDirect3DSurface8_Release(pSurface); +} +*/ + +//--------------------------------------------------------------------------- + +// Faster, more efficient version. +// Copies subimage straight to dest texture +void gld_TexSubImage2D_DX7( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + IDirectDrawSurface7 *pTex; + IDirectDrawSurface7 *pSurface; + HRESULT hr; + RECT rcDstRect; + DDSURFACEDESC2 ddsd; + int i; + DDSCAPS2 ddsCaps; + + if (!tObj || !texImage) + return; + + pTex = (IDirectDrawSurface7*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + + __try { + + ddsd.dwSize = sizeof(ddsd); + _GLD_DX7_TEX(GetSurfaceDesc(pTex, &ddsd)); + if ((level > 0) && (level >= ddsd.dwMipMapCount)) + return; // Level does not exist + + ZeroMemory(&ddsCaps, sizeof(ddsCaps)); + pSurface = pTex; + for (i=0; iTexFormat->StoreImage(ctx, 2, texImage->Format, + _gldMesaFormatForD3DFormat(_gldD3DXFormatFromSurface(pSurface)), + ddsd.lpSurface, + width, height, 1, + 0, 0, 0, // NOTE: d3dLockedRect.pBits is already offset!!! + ddsd.lPitch, + 0, // dstImageStride + format, type, pixels, packing); + + + IDirectDrawSurface7_Unlock(pSurface, &rcDstRect); + } + __except(EXCEPTION_EXECUTE_HANDLER) { + ; + } +} + +//--------------------------------------------------------------------------- + +void gld_TexSubImage1D_DX7( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLsizei width, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + gld_TexSubImage2D_DX7(ctx, target, level, xoffset, 0, width, 1, format, type, pixels, packing, texObj, texImage); +} + +//--------------------------------------------------------------------------- + +void gld_DeleteTexture_DX7( + GLcontext *ctx, + struct gl_texture_object *tObj) +{ + GLD_context *gld = (GLD_context*)(ctx->DriverCtx); + + __try { + + if (tObj) { + IDirectDrawSurface7 *pTex = (IDirectDrawSurface7*)tObj->DriverData; + if (pTex) { +/* // Make sure texture is not bound to a stage before releasing it + for (int i=0; iCurrentTexture[i] == pTex) { + gld->pDev->SetTexture(i, NULL); + gld->CurrentTexture[i] = NULL; + } + }*/ + _GLD_DX7_TEX(Release(pTex)); + tObj->DriverData = NULL; + } + } + + } + __except(EXCEPTION_EXECUTE_HANDLER) { + ; + } +} + +//--------------------------------------------------------------------------- + +__inline void _gldSetColorOps( + const GLD_driver_dx7 *gld, + GLuint unit, + DWORD ColorArg1, + D3DTEXTUREOP ColorOp, + DWORD ColorArg2) +{ + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG1, ColorArg1)); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLOROP, ColorOp)); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG2, ColorArg2)); +} + +//--------------------------------------------------------------------------- + +__inline void _gldSetAlphaOps( + const GLD_driver_dx7 *gld, + GLuint unit, + DWORD AlphaArg1, + D3DTEXTUREOP AlphaOp, + DWORD AlphaArg2) +{ + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG1, AlphaArg1)); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAOP, AlphaOp)); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG2, AlphaArg2)); +} + +//--------------------------------------------------------------------------- + +void gldUpdateTextureUnit( + GLcontext *ctx, + GLuint unit, + BOOL bPassThrough) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DTEXTUREMINFILTER minfilter; + D3DTEXTUREMIPFILTER mipfilter; + GLenum BaseFormat; + DWORD dwColorArg0; + int iTexEnv = 0; + GLD_texenv *pTexenv; + + // NOTE: If bPassThrough is FALSE then texture stage can be + // disabled otherwise it must pass-through it's current fragment. + + const struct gl_texture_unit *pUnit = &ctx->Texture.Unit[unit]; + const struct gl_texture_object *tObj = pUnit->_Current; + + IDirectDrawSurface7 *pTex = NULL; + if (tObj) { + pTex = (IDirectDrawSurface7*)tObj->DriverData; + } + + __try { + + // Enable texturing if unit is enabled and a valid D3D texture exists + // Mesa 5: TEXTUREn_x altered to TEXTURE_nD_BIT + //if (pTex && (pUnit->Enabled & (TEXTURE0_1D | TEXTURE0_2D))) { + if (pTex && (pUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT))) { + // Enable texturing + _GLD_DX7_DEV(SetTexture(gld->pDev, unit, pTex)); + } else { + // Disable texturing, then return + _GLD_DX7_DEV(SetTexture(gld->pDev, unit, NULL)); + if (bPassThrough) { + _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); + _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); + } else { + _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); + _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); + } + return; + } + + // Texture parameters + _gldConvertMinFilter(tObj->MinFilter, &minfilter, &mipfilter); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MINFILTER, minfilter)); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MIPFILTER, mipfilter)); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSU, _gldConvertWrap(tObj->WrapS))); + _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSV, _gldConvertWrap(tObj->WrapT))); + + // Texture priority + _GLD_DX7_TEX(SetPriority(pTex, (DWORD)(tObj->Priority*65535.0f))); + + // Texture environment + // TODO: Examine input texture for alpha and use specific alpha/non-alpha ops. + // See Page 355 of the Red Book. + BaseFormat = _gldDecodeBaseFormat(pTex); + + switch (BaseFormat) { + case GL_RGB: + iTexEnv = 0; + break; + case GL_RGBA: + iTexEnv = 1; + break; + case GL_ALPHA: + iTexEnv = 2; + break; + } + + switch (pUnit->EnvMode) { + case GL_DECAL: + iTexEnv += 0; + break; + case GL_REPLACE: + iTexEnv += 3; + break; + case GL_MODULATE: + iTexEnv += 6; + break; + case GL_BLEND: + // Set blend colour + // Unsupported by DX7 +// dwColorArg0 = D3DCOLOR_COLORVALUE(pUnit->EnvColor[0], pUnit->EnvColor[1], pUnit->EnvColor[2], pUnit->EnvColor[3]); +// _GLD_DX7_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG0, dwColorArg0)); +// gldLogMessage(GLDLOG_WARN, "GL_BLEND\n"); + iTexEnv += 9; + break; + case GL_ADD: + iTexEnv += 12; + break; + } + pTexenv = (GLD_texenv*)&gldTexEnv[iTexEnv]; + _gldSetColorOps(gld, unit, pTexenv->ColorArg1, pTexenv->ColorOp, pTexenv->ColorArg2); + _gldSetAlphaOps(gld, unit, pTexenv->AlphaArg1, pTexenv->AlphaOp, pTexenv->AlphaArg2); + + } + __except(EXCEPTION_EXECUTE_HANDLER) { + ; + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_TEXTURE_DX7( + GLcontext *ctx) +{ + // TODO: Support for three (ATI Radeon) or more (nVidia GeForce3) texture units + + BOOL bUnit0Enabled; + BOOL bUnit1Enabled; + + if (!ctx) + return; // Sanity check + + if (ctx->Const.MaxTextureUnits == 1) { + gldUpdateTextureUnit(ctx, 0, TRUE); + return; + } + + // + // NOTE: THE FOLLOWING RELATES TO TWO TEXTURE UNITS, AND TWO ONLY!! + // + + // Mesa 5: Texture Units altered + bUnit0Enabled = (ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; + bUnit1Enabled = (ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; + + // If Unit0 is disabled and Unit1 is enabled then we must pass-though + gldUpdateTextureUnit(ctx, 0, (!bUnit0Enabled && bUnit1Enabled) ? TRUE : FALSE); + // We can always disable the last texture unit + gldUpdateTextureUnit(ctx, 1, FALSE); + +#ifdef _DEBUG + { + // Find out whether device supports current renderstates + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + DWORD dwPasses; + _GLD_DX7_DEV(ValidateDevice(gld->pDev, &dwPasses)); +#if 0 + if (FAILED(hr)) { + gldLogError(GLDLOG_ERROR, "ValidateDevice failed", hr); + } +#endif + if (dwPasses != 1) { + gldLogMessage(GLDLOG_ERROR, "ValidateDevice: Can't do in one pass\n"); + } + } +#endif +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_vb_d3d_render_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_vb_d3d_render_dx7.c @@ -0,0 +1,257 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect fastpath pipeline stage +* +****************************************************************************/ + +//--------------------------------------------------------------------------- + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx7.h" + +//--------------------------------------------------------------------------- + +#include "glheader.h" +#include "context.h" +#include "macros.h" +// #include "mem.h" +#include "mtypes.h" +//#include "mmath.h" + +#include "math/m_matrix.h" +#include "math/m_xform.h" + +#include "tnl/t_pipeline.h" + +//--------------------------------------------------------------------------- +/* +__inline void _gldSetVertexShaderConstants( + GLcontext *ctx, + GLD_driver_dx8 *gld) +{ + D3DXMATRIX mat, matView, matProj; + GLfloat *pM; + + // Mesa 5: Altered to a Stack + //pM = ctx->ModelView.m; + pM = ctx->ModelviewMatrixStack.Top->m; + matView._11 = pM[0]; + matView._12 = pM[1]; + matView._13 = pM[2]; + matView._14 = pM[3]; + matView._21 = pM[4]; + matView._22 = pM[5]; + matView._23 = pM[6]; + matView._24 = pM[7]; + matView._31 = pM[8]; + matView._32 = pM[9]; + matView._33 = pM[10]; + matView._34 = pM[11]; + matView._41 = pM[12]; + matView._42 = pM[13]; + matView._43 = pM[14]; + matView._44 = pM[15]; + + // Mesa 5: Altered to a Stack + //pM = ctx->ProjectionMatrix.m; + pM = ctx->ProjectionMatrixStack.Top->m; + matProj._11 = pM[0]; + matProj._12 = pM[1]; + matProj._13 = pM[2]; + matProj._14 = pM[3]; + matProj._21 = pM[4]; + matProj._22 = pM[5]; + matProj._23 = pM[6]; + matProj._24 = pM[7]; + matProj._31 = pM[8]; + matProj._32 = pM[9]; + matProj._33 = pM[10]; + matProj._34 = pM[11]; + matProj._41 = pM[12]; + matProj._42 = pM[13]; + matProj._43 = pM[14]; + matProj._44 = pM[15]; + + D3DXMatrixMultiply( &mat, &matView, &matProj ); + D3DXMatrixTranspose( &mat, &mat ); + + _GLD_DX8_DEV(SetVertexShaderConstant(gld->pDev, 0, &mat, 4)); +} +*/ +//--------------------------------------------------------------------------- + +static GLboolean gld_d3d_render_stage_run( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + TNLcontext *tnl; + struct vertex_buffer *VB; + tnl_render_func *tab; + GLint pass; + GLD_pb_dx7 *gldPB = &gld->PB3d; + DWORD dwFlags; + +/* + static int count = 0; + count++; + if (count != 2) + return GL_FALSE; +*/ + // The "check" function should disable this stage, + // but we'll test gld->bUseMesaTnL anyway. + if (gld->bUseMesaTnL) { + // Do nothing in this stage, but continue pipeline + return GL_TRUE; + } + + tnl = TNL_CONTEXT(ctx); + VB = &tnl->vb; + pass = 0; + + tnl->Driver.Render.Start( ctx ); + +#if 0 + // For debugging: Useful to see if an app passes colour data in + // an unusual format. + switch (VB->ColorPtr[0]->Type) { + case GL_FLOAT: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_FLOAT\n"); + break; + case GL_UNSIGNED_BYTE: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_UNSIGNED_BYTE\n"); + break; + default: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: *?*\n"); + break; + } +#endif + + tnl->Driver.Render.Points = gld_Points3D_DX7; + if (ctx->_TriangleCaps & DD_FLATSHADE) { + tnl->Driver.Render.Line = gld_Line3DFlat_DX7; + tnl->Driver.Render.Triangle = gld_Triangle3DFlat_DX7; + tnl->Driver.Render.Quad = gld_Quad3DFlat_DX7; + } else { + tnl->Driver.Render.Line = gld_Line3DSmooth_DX7; + tnl->Driver.Render.Triangle = gld_Triangle3DSmooth_DX7; + tnl->Driver.Render.Quad = gld_Quad3DSmooth_DX7; + } + +// _GLD_DX7_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); + dwFlags = DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY; + _GLD_DX7_VB(Lock(gldPB->pVB, dwFlags, &gldPB->pPoints, NULL)); + gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; + // Allocate primitive pointers + // gldPB->pPoints is always first + gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); + gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); + + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); + + tab = (VB->Elts ? tnl->Driver.Render.PrimTabElts : tnl->Driver.Render.PrimTabVerts); + + do { + GLuint i, length, flags = 0; + for (i = 0 ; !(flags & PRIM_END) ; i += length) + { + flags = VB->Primitive[i].mode; + length= VB->Primitive[i].count; + ASSERT(length || (flags & PRIM_END)); + ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + if (length) + tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + } + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + + _GLD_DX7_VB(Unlock(gldPB->pVB)); + +// _GLD_DX7_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, gldPB->dwStride)); + + _GLD_DX7_DEV(SetTransform(gld->pDev, D3DTRANSFORMSTATE_PROJECTION, &gld->matProjection)); + _GLD_DX7_DEV(SetTransform(gld->pDev, D3DTRANSFORMSTATE_WORLD, &gld->matModelView)); + + if (gldPB->nPoints) { +// _GLD_DX7_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); + _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_POINTLIST, gldPB->pVB, 0, gldPB->nPoints, 0)); + gldPB->nPoints = 0; + } + + if (gldPB->nLines) { +// _GLD_DX7_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); + _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_LINELIST, gldPB->pVB, gldPB->iFirstLine, gldPB->nLines, 0)); + gldPB->nLines = 0; + } + + if (gldPB->nTriangles) { +// _GLD_DX7_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); + _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_TRIANGLELIST, gldPB->pVB, gldPB->iFirstTriangle, gldPB->nTriangles, 0)); + gldPB->nTriangles = 0; + } + + return GL_FALSE; /* finished the pipe */ +} + + +//--------------------------------------------------------------------------- + +const struct tnl_pipeline_stage _gld_d3d_render_stage = +{ + "gld_d3d_render_stage", + NULL, + NULL, + NULL, + NULL, + gld_d3d_render_stage_run /* run */ +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_wgl_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_wgl_dx7.c @@ -0,0 +1,1611 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect Direct3D 8.x WGL (WindowsGL) +* +****************************************************************************/ + +#include "dglcontext.h" +#include "gld_driver.h" +//#include "gld_dxerr8.h" +#include "gld_dx7.h" + +#include "tnl/tnl.h" +#include "tnl/t_context.h" + +// Copied from dglcontect.c +#define GLDERR_NONE 0 +#define GLDERR_MEM 1 +#define GLDERR_DDRAW 2 +#define GLDERR_D3D 3 +#define GLDERR_BPP 4 +#define GLDERR_DDS 5 +// This external var keeps track of any error +extern int nContextError; + +// Uncomment this for persistant resources +//#define _GLD_PERSISTANT + +#define DDLOG_CRITICAL_OR_WARN DDLOG_CRITICAL + +extern void _gld_mesa_warning(GLcontext *, char *); +extern void _gld_mesa_fatal(GLcontext *, char *); + +//--------------------------------------------------------------------------- + +static char szColorDepthWarning[] = +"GLDirect does not support the current desktop\n\ +color depth.\n\n\ +You may need to change the display resolution to\n\ +16 bits per pixel or higher color depth using\n\ +the Windows Display Settings control panel\n\ +before running this OpenGL application.\n"; + +// The only depth-stencil formats currently supported by Direct3D +// Surface Format Depth Stencil Total Bits +// D3DFMT_D32 32 - 32 +// D3DFMT_D15S1 15 1 16 +// D3DFMT_D24S8 24 8 32 +// D3DFMT_D16 16 - 16 +// D3DFMT_D24X8 24 - 32 +// D3DFMT_D24X4S4 24 4 32 + +// This pixel format will be used as a template when compiling the list +// of pixel formats supported by the hardware. Many fields will be +// filled in at runtime. +// PFD flag defaults are upgraded to match ChoosePixelFormat() -- DaveM +static DGL_pixelFormat pfTemplateHW = +{ + { + sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure + 1, // Structure version - should be 1 + // Flags: + PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. + PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) + PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) + PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. + PFD_DOUBLEBUFFER | // The buffer is double-buffered. + 0, // Placeholder for easy commenting of above flags + PFD_TYPE_RGBA, // Pixel type RGBA. + 16, // Total colour bitplanes (excluding alpha bitplanes) + 5, 0, // Red bits, shift + 5, 0, // Green bits, shift + 5, 0, // Blue bits, shift + 0, 0, // Alpha bits, shift (destination alpha) + 0, // Accumulator bits (total) + 0, 0, 0, 0, // Accumulator bits: Red, Green, Blue, Alpha + 0, // Depth bits + 0, // Stencil bits + 0, // Number of auxiliary buffers + 0, // Layer type + 0, // Specifies the number of overlay and underlay planes. + 0, // Layer mask + 0, // Specifies the transparent color or index of an underlay plane. + 0 // Damage mask + }, + D3DX_SF_UNKNOWN, // No depth/stencil buffer +}; + +//--------------------------------------------------------------------------- +// Vertex Shaders +//--------------------------------------------------------------------------- +/* +// Vertex Shader Declaration +static DWORD dwTwoSidedLightingDecl[] = +{ + D3DVSD_STREAM(0), + D3DVSD_REG(0, D3DVSDT_FLOAT3), // XYZ position + D3DVSD_REG(1, D3DVSDT_FLOAT3), // XYZ normal + D3DVSD_REG(2, D3DVSDT_D3DCOLOR), // Diffuse color + D3DVSD_REG(3, D3DVSDT_D3DCOLOR), // Specular color + D3DVSD_REG(4, D3DVSDT_FLOAT2), // 2D texture unit 0 + D3DVSD_REG(5, D3DVSDT_FLOAT2), // 2D texture unit 1 + D3DVSD_END() +}; + +// Vertex Shader for two-sided lighting +static char *szTwoSidedLightingVS = +// This is a test shader! +"vs.1.0\n" +"m4x4 oPos,v0,c0\n" +"mov oD0,v2\n" +"mov oD1,v3\n" +"mov oT0,v4\n" +"mov oT1,v5\n" +; +*/ +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +typedef struct { +// HINSTANCE hD3D8DLL; // Handle to d3d8.dll +// FNDIRECT3DCREATE7 fnDirect3DCreate7; // Direct3DCreate8 function prototype +// BOOL bDirect3D; // Persistant Direct3D7 exists +// BOOL bDirect3DDevice; // Persistant Direct3DDevice7 exists +// IDirect3D7 *pD3D; // Persistant Direct3D7 +// IDirect3DDevice7 *pDev; // Persistant Direct3DDevice7 + BOOL bD3DXStarted; +} GLD_dx7_globals; + +// These are "global" to all DX7 contexts. KeithH +static GLD_dx7_globals dx7Globals; + +// Added for correct clipping of multiple open windows. (DaveM) +LPDIRECTDRAWSURFACE7 lpDDSPrimary = NULL; +LPDIRECTDRAWCLIPPER lpDDClipper = NULL; + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +BOOL gldGetDXErrorString_DX( + HRESULT hr, + char *buf, + int nBufSize) +{ + // + // Return a string describing the input HRESULT error code + // + + D3DXGetErrorString(hr, nBufSize, buf); + return TRUE; +} + +//--------------------------------------------------------------------------- +// +// DX7 does not support multisample +/* +static D3DMULTISAMPLE_TYPE _gldGetDeviceMultiSampleType( + IDirect3D8 *pD3D8, + D3DFORMAT SurfaceFormat, + D3DDEVTYPE d3dDevType, + BOOL Windowed) +{ + int i; + HRESULT hr; + + if (glb.dwMultisample == GLDS_MULTISAMPLE_NONE) + return D3DMULTISAMPLE_NONE; + + if (glb.dwMultisample == GLDS_MULTISAMPLE_FASTEST) { + // Find fastest multisample + for (i=2; i<17; i++) { + hr = IDirect3D8_CheckDeviceMultiSampleType( + pD3D8, + glb.dwAdapter, + d3dDevType, + SurfaceFormat, + Windowed, + (D3DMULTISAMPLE_TYPE)i); + if (SUCCEEDED(hr)) { + return (D3DMULTISAMPLE_TYPE)i; + } + } + } else { + // Find nicest multisample + for (i=16; i>1; i--) { + hr = IDirect3D8_CheckDeviceMultiSampleType( + pD3D8, + glb.dwAdapter, + d3dDevType, + SurfaceFormat, + Windowed, + (D3DMULTISAMPLE_TYPE)i); + if (SUCCEEDED(hr)) { + return (D3DMULTISAMPLE_TYPE)i; + } + } + } + + // Nothing found - return default + return D3DMULTISAMPLE_NONE; +} +*/ +//--------------------------------------------------------------------------- + +void _gldDestroyPrimitiveBuffer( + GLD_pb_dx7 *gldVB) +{ + SAFE_RELEASE(gldVB->pVB); + + // Sanity check... + gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; +} + +//--------------------------------------------------------------------------- + +HRESULT _gldCreatePrimitiveBuffer( + GLcontext *ctx, + GLD_driver_dx7 *lpCtx, + GLD_pb_dx7 *gldVB) +{ + HRESULT hResult; + char *szCreateVertexBufferFailed = "CreateVertexBuffer failed"; + DWORD dwMaxVertices; // Max number of vertices in vertex buffer + DWORD dwVBSize; // Total size of vertex buffer + D3DVERTEXBUFFERDESC vbdesc; + + // If CVA (Compiled Vertex Array) is used by an OpenGL app, then we + // will need enough vertices to cater for Mesa::Const.MaxArrayLockSize. + // We'll use IMM_SIZE if it's larger (which it should not be). + dwMaxVertices = MAX_ARRAY_LOCK_SIZE; + + // Max vertex buffer size limited in DX7. (DaveM) + if (dwMaxVertices*9 > D3DMAXNUMVERTICES) + dwMaxVertices = D3DMAXNUMVERTICES/9; + + // Now calculate how many vertices to allow for in total + // 1 per point, 2 per line, 6 per quad = 9 + dwVBSize = dwMaxVertices * 9 * gldVB->dwStride; + + vbdesc.dwSize = sizeof(vbdesc); + vbdesc.dwCaps = gldVB->dwCreateFlags; + vbdesc.dwFVF = gldVB->dwFVF; + vbdesc.dwNumVertices = dwMaxVertices * 9; + +/* hResult = IDirect3DDevice8_CreateVertexBuffer( + lpCtx->pDev, + dwVBSize, +RAgldVB->dwUsage, + gldVB->dwFVF, + gldVB->dwPool, + &gldVB->pVB);*/ + hResult = IDirect3D7_CreateVertexBuffer( + lpCtx->pD3D, + &vbdesc, + &gldVB->pVB, + 0); + if (FAILED(hResult)) { + ddlogMessage(DDLOG_CRITICAL_OR_WARN, szCreateVertexBufferFailed); + return hResult; + } + + gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; + gldVB->pPoints = gldVB->pLines = gldVB->pTriangles = NULL; + gldVB->iFirstLine = dwMaxVertices; // Index of first line in VB + gldVB->iFirstTriangle = dwMaxVertices*3; // Index of first triangle in VB + + return S_OK; +} + +//--------------------------------------------------------------------------- +// Function: _gldCreateVertexShaders +// Create DX8 Vertex Shaders. +//--------------------------------------------------------------------------- +/* +void _gldCreateVertexShaders( + GLD_driver_dx8 *gld) +{ + DWORD dwFlags; + LPD3DXBUFFER pVSOpcodeBuffer; // Vertex Shader opcode buffer + HRESULT hr; + +#ifdef _DEBUG + dwFlags = D3DXASM_DEBUG; +#else + dwFlags = 0; // D3DXASM_SKIPVALIDATION; +#endif + + ddlogMessage(DDLOG_INFO, "Creating shaders...\n"); + + // Init the shader handle + gld->VStwosidelight.hShader = 0; + + if (gld->d3dCaps8.MaxStreams == 0) { + // Lame DX8 driver doesn't support streams + // Not fatal, as defaults will be used + ddlogMessage(DDLOG_WARN, "Driver doesn't support Vertex Shaders (MaxStreams==0)\n"); + return; + } + + // ** THIS DISABLES VERTEX SHADER SUPPORT ** +// return; + // ** THIS DISABLES VERTEX SHADER SUPPORT ** + + // + // Two-sided lighting + // + +#if 0 + // + // DEBUGGING: Load shader from a text file + // + { + LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer + hr = D3DXAssembleShaderFromFile( + "twoside.vsh", + dwFlags, + NULL, // No constants + &pVSOpcodeBuffer, + &pVSErrorBuffer); + if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) + ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); + SAFE_RELEASE(pVSErrorBuffer); + } +#else + { + LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer + // Assemble ascii shader text into shader opcodes + hr = D3DXAssembleShader( + szTwoSidedLightingVS, + strlen(szTwoSidedLightingVS), + dwFlags, + NULL, // No constants + &pVSOpcodeBuffer, + &pVSErrorBuffer); + if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) + ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); + SAFE_RELEASE(pVSErrorBuffer); + } +#endif + if (FAILED(hr)) { + ddlogError(DDLOG_WARN, "AssembleShader failed", hr); + SAFE_RELEASE(pVSOpcodeBuffer); + return; + } + +// This is for debugging. Remove to enable vertex shaders in HW +#define _GLD_FORCE_SW_VS 0 + + if (_GLD_FORCE_SW_VS) { + // _GLD_FORCE_SW_VS should be disabled for Final Release + ddlogMessage(DDLOG_SYSTEM, "[Forcing shaders in SW]\n"); + } + + // Try and create shader in hardware. + // NOTE: The D3D Ref device appears to succeed when trying to + // create the device in hardware, but later complains + // when trying to set it with SetVertexShader(). Go figure. + if (_GLD_FORCE_SW_VS || glb.dwDriver == GLDS_DRIVER_REF) { + // Don't try and create a hardware shader with the Ref device + hr = E_FAIL; // COM error/fail result + } else { + gld->VStwosidelight.bHardware = TRUE; + hr = IDirect3DDevice8_CreateVertexShader( + gld->pDev, + dwTwoSidedLightingDecl, + pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), + &gld->VStwosidelight.hShader, + 0); + } + if (FAILED(hr)) { + ddlogMessage(DDLOG_INFO, "... HW failed, trying SW...\n"); + // Failed. Try and create shader for software processing + hr = IDirect3DDevice8_CreateVertexShader( + gld->pDev, + dwTwoSidedLightingDecl, + pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), + &gld->VStwosidelight.hShader, + D3DUSAGE_SOFTWAREPROCESSING); + if (FAILED(hr)) { + gld->VStwosidelight.hShader = 0; // Sanity check + ddlogError(DDLOG_WARN, "CreateVertexShader failed", hr); + return; + } + // Succeeded, but for software processing + gld->VStwosidelight.bHardware = FALSE; + } + + SAFE_RELEASE(pVSOpcodeBuffer); + + ddlogMessage(DDLOG_INFO, "... OK\n"); +} + +//--------------------------------------------------------------------------- + +void _gldDestroyVertexShaders( + GLD_driver_dx8 *gld) +{ + if (gld->VStwosidelight.hShader) { + IDirect3DDevice8_DeleteVertexShader(gld->pDev, gld->VStwosidelight.hShader); + gld->VStwosidelight.hShader = 0; + } +} +*/ +//--------------------------------------------------------------------------- + +BOOL gldCreateDrawable_DX( + DGL_ctx *ctx, +// BOOL bDefaultDriver, + BOOL bDirectDrawPersistant, + BOOL bPersistantBuffers) +{ + // + // bDirectDrawPersistant: applies to IDirect3D8 + // bPersistantBuffers: applies to IDirect3DDevice8 + // + +// D3DDEVTYPE d3dDevType; +// D3DPRESENT_PARAMETERS d3dpp; +// D3DDISPLAYMODE d3ddm; +// DWORD dwBehaviourFlags; +// D3DADAPTER_IDENTIFIER8 d3dIdent; + + HRESULT hr; + GLD_driver_dx7 *lpCtx = NULL; + D3DX_VIDMODEDESC d3ddm; + + // Parameters for D3DXCreateContextEx + // These will be different for fullscreen and windowed + DWORD dwDeviceIndex; + DWORD dwFlags; + HWND hwnd; + HWND hwndFocus; + DWORD numColorBits; + DWORD numAlphaBits; + DWORD numDepthBits; + DWORD numStencilBits; + DWORD numBackBuffers; + DWORD dwWidth; + DWORD dwHeight; + DWORD refreshRate; + + // Error if context is NULL. + if (ctx == NULL) + return FALSE; + + if (ctx->glPriv) { + lpCtx = ctx->glPriv; + // Release any existing interfaces (in reverse order) + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + lpCtx->pD3DXContext->lpVtbl->Release(lpCtx->pD3DXContext); + lpCtx->pD3DXContext = NULL; + } else { + lpCtx = (GLD_driver_dx7*)malloc(sizeof(GLD_driver_dx7)); + ZeroMemory(lpCtx, sizeof(lpCtx)); + } + +// d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + // Use REF device if requested. Otherwise D3DX_DEFAULT will choose highest level + // of HW acceleration. + dwDeviceIndex = (glb.dwDriver == GLDS_DRIVER_REF) ? D3DX_HWLEVEL_REFERENCE : D3DX_DEFAULT; + + // TODO: Check this +// if (bDefaultDriver) +// d3dDevType = D3DDEVTYPE_REF; + +#ifdef _GLD_PERSISTANT + // Use persistant interface if needed + if (bDirectDrawPersistant && dx7Globals.bDirect3D) { + lpCtx->pD3D = dx7Globals.pD3D; + IDirect3D7_AddRef(lpCtx->pD3D); + goto SkipDirectDrawCreate; + } +#endif +/* + // Create Direct3D7 object + lpCtx->pD3D = dx7Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); + if (lpCtx->pD3D == NULL) { + MessageBox(NULL, "Unable to initialize Direct3D8", "GLDirect", MB_OK); + ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D8 interface"); + nContextError = GLDERR_D3D; + goto return_with_error; + } +*/ + +#ifdef _GLD_PERSISTANT + // Cache Direct3D interface for subsequent GLRCs + if (bDirectDrawPersistant && !dx8Globals.bDirect3D) { + dx7Globals.pD3D = lpCtx->pD3D; + IDirect3D7_AddRef(dx7Globals.pD3D); + dx7Globals.bDirect3D = TRUE; + } +SkipDirectDrawCreate: +#endif +/* + // Get the display mode so we can make a compatible backbuffer + hResult = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hResult)) { + nContextError = GLDERR_D3D; + goto return_with_error; + } +*/ + +#if 0 + // Get device caps + hResult = IDirect3D8_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps8); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_GetDeviceCaps failed", hResult); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Check for hardware transform & lighting + lpCtx->bHasHWTnL = lpCtx->d3dCaps8.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; + + // If this flag is present then we can't default to Mesa + // SW rendering between BeginScene() and EndScene(). + if (lpCtx->d3dCaps8.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { + ddlogMessage(DDLOG_WARN, + "Warning : No 2D allowed during 3D scene.\n"); + } +#endif + + // + // Create the Direct3D context + // + +#ifdef _GLD_PERSISTANT + // Re-use original IDirect3DDevice if persistant buffers exist. + // Note that we test for persistant IDirect3D8 as well + // bDirectDrawPersistant == persistant IDirect3D8 (DirectDraw8 does not exist) + if (bDirectDrawPersistant && bPersistantBuffers && dx7Globals.pD3D && dx7Globals.pDev) { + lpCtx->pDev = dx7Globals.pDev; + IDirect3DDevice7_AddRef(dx7Globals.pDev); + goto skip_direct3ddevice_create; + } +#endif +/* + // Clear the presentation parameters (sets all members to zero) + ZeroMemory(&d3dpp, sizeof(d3dpp)); + + // Recommended by MS; needed for MultiSample. + // Be careful if altering this for FullScreenBlit + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + + d3dpp.BackBufferFormat = d3ddm.Format; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); + d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; + d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; + + if (ctx->bFullscreen) { + ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen + d3dpp.Windowed = FALSE; + d3dpp.BackBufferWidth = d3ddm.Width; + d3dpp.BackBufferHeight = d3ddm.Height; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + + // Support for vertical retrace synchronisation. + // Set default presentation interval in case caps bits are missing + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + if (glb.bWaitForRetrace) { + if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; + } else { + if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + } else { + ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages + d3dpp.Windowed = TRUE; + d3dpp.BackBufferWidth = ctx->dwWidth; + d3dpp.BackBufferHeight = ctx->dwHeight; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = 0; + // FullScreen_PresentationInterval must be default for Windowed mode + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + } + + // Decide if we can use hardware TnL + dwBehaviourFlags = (lpCtx->bHasHWTnL) ? + D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; + // Add flag to tell D3D to be thread-safe + if (glb.bMultiThreaded) + dwBehaviourFlags |= D3DCREATE_MULTITHREADED; + hResult = IDirect3D8_CreateDevice(lpCtx->pD3D, + glb.dwAdapter, + d3dDevType, + ctx->hWnd, + dwBehaviourFlags, + &d3dpp, + &lpCtx->pDev); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_CreateDevice failed", hResult); + nContextError = GLDERR_D3D; + goto return_with_error; + } +*/ + + // Create D3DX context + if (ctx->bFullscreen) { + // + // FULLSCREEN + // + + // Get display mode + D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); + + // Fullscreen Parameters + dwFlags = D3DX_CONTEXT_FULLSCREEN; + hwnd = ctx->hWnd; + hwndFocus = ctx->hWnd; + numColorBits = ctx->lpPF->pfd.cColorBits; + numAlphaBits = ctx->lpPF->pfd.cAlphaBits; + numDepthBits = ctx->lpPF->pfd.cDepthBits + ctx->lpPF->pfd.cStencilBits; + numStencilBits = ctx->lpPF->pfd.cStencilBits; + numBackBuffers = D3DX_DEFAULT; // Default is 1 backbuffer + dwWidth = d3ddm.width; + dwHeight = d3ddm.height; + refreshRate = d3ddm.refreshRate; // D3DX_DEFAULT; + } else { + // + // WINDOWED + // + + // Windowed Parameters + dwFlags = 0; // No flags means "windowed" + hwnd = ctx->hWnd; + hwndFocus = (HWND)D3DX_DEFAULT; + numColorBits = D3DX_DEFAULT; // Use Desktop depth + numAlphaBits = ctx->lpPF->pfd.cAlphaBits; + numDepthBits = ctx->lpPF->pfd.cDepthBits + ctx->lpPF->pfd.cStencilBits; + numStencilBits = ctx->lpPF->pfd.cStencilBits; + numBackBuffers = D3DX_DEFAULT; // Default is 1 backbuffer + dwWidth = ctx->dwWidth; + dwHeight = ctx->dwHeight; + refreshRate = D3DX_DEFAULT; + } + hr = D3DXCreateContextEx(dwDeviceIndex, dwFlags, hwnd, hwndFocus, + numColorBits, numAlphaBits, numDepthBits, numStencilBits, + numBackBuffers, + dwWidth, dwHeight, refreshRate, + &lpCtx->pD3DXContext); + if (FAILED(hr)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "D3DXCreateContextEx failed", hr); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Obtain D3D7 interfaces from ID3DXContext +// lpCtx->pDD = ID3DXContext_GetDD(lpCtx->pD3DXContext); + lpCtx->pDD = lpCtx->pD3DXContext->lpVtbl->GetDD(lpCtx->pD3DXContext); + if (lpCtx->pDD == NULL) + goto return_with_error; + lpCtx->pD3D = lpCtx->pD3DXContext->lpVtbl->GetD3D(lpCtx->pD3DXContext); + if (lpCtx->pD3D == NULL) + goto return_with_error; + lpCtx->pDev = lpCtx->pD3DXContext->lpVtbl->GetD3DDevice(lpCtx->pD3DXContext); + if (lpCtx->pDev == NULL) + goto return_with_error; + + // Need to manage clipper manually for multiple windows + // since DX7 D3DX utility lib does not appear to do that. (DaveM) + if (!ctx->bFullscreen) { + // Get primary surface too + lpDDSPrimary = lpCtx->pD3DXContext->lpVtbl->GetPrimary(lpCtx->pD3DXContext); + if (lpDDSPrimary == NULL) { + ddlogPrintf(DDLOG_WARN, "GetPrimary"); + goto return_with_error; + } + // Create clipper for correct window updates + if (IDirectDraw7_CreateClipper(lpCtx->pDD, 0, &lpDDClipper, NULL) != DD_OK) { + ddlogPrintf(DDLOG_WARN, "CreateClipper"); + goto return_with_error; + } + // Set the window that the clipper belongs to + if (IDirectDrawClipper_SetHWnd(lpDDClipper, 0, hwnd) != DD_OK) { + ddlogPrintf(DDLOG_WARN, "SetHWnd"); + goto return_with_error; + } + // Attach the clipper to the primary surface + if (IDirectDrawSurface7_SetClipper(lpDDSPrimary, lpDDClipper) != DD_OK) { + ddlogPrintf(DDLOG_WARN, "SetClipper"); + goto return_with_error; + } + } + + // Get device caps + IDirect3DDevice7_GetCaps(lpCtx->pDev, &lpCtx->d3dCaps); + + // Determine HW TnL + lpCtx->bHasHWTnL = lpCtx->d3dCaps.dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; + +#ifdef _GLD_PERSISTANT + if (bDirectDrawPersistant && bPersistantBuffers && dx7Globals.pD3D) { + dx7Globals.pDev = lpCtx->pDev; + dx7Globals.bDirect3DDevice = TRUE; + } +#endif + +#if 0 + // Dump some useful stats + hResult = IDirect3D8_GetAdapterIdentifier( + lpCtx->pD3D, + glb.dwAdapter, + D3DENUM_NO_WHQL_LEVEL, // Avoids 1 to 2 second delay + &d3dIdent); + if (SUCCEEDED(hResult)) { + ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); + ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", + d3dIdent.Driver, + HIWORD(d3dIdent.DriverVersion.HighPart), + LOWORD(d3dIdent.DriverVersion.HighPart), + HIWORD(d3dIdent.DriverVersion.LowPart), + LOWORD(d3dIdent.DriverVersion.LowPart)); + ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", + d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); + } +#endif + + // Init projection matrix for D3D TnL + D3DXMatrixIdentity((D3DXMATRIX*)&lpCtx->matProjection); + lpCtx->matModelView = lpCtx->matProjection; +// gld->bUseMesaProjection = TRUE; + +skip_direct3ddevice_create: + + // Create buffers to hold primitives + lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; +// lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; + lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); + lpCtx->PB2d.dwCreateFlags = D3DVBCAPS_DONOTCLIP | + D3DVBCAPS_SYSTEMMEMORY | + D3DVBCAPS_WRITEONLY; + hr = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); + if (FAILED(hr)) + goto return_with_error; + + lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; +// lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; + lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); + lpCtx->PB3d.dwCreateFlags = D3DVBCAPS_WRITEONLY; + + hr = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); + if (FAILED(hr)) + goto return_with_error; + + // Zero the pipeline usage counters + lpCtx->PipelineUsage.qwMesa.QuadPart = +// lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = + lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; + + // Assign drawable to GL private + ctx->glPriv = lpCtx; + return TRUE; + +return_with_error: + // Clean up and bail + _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); + _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); + + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + //SAFE_RELEASE(lpCtx->pD3DXContext); + lpCtx->pD3DXContext->lpVtbl->Release(lpCtx->pD3DXContext); + return FALSE; +} + +//--------------------------------------------------------------------------- + +BOOL gldResizeDrawable_DX( + DGL_ctx *ctx, + BOOL bDefaultDriver, + BOOL bPersistantInterface, + BOOL bPersistantBuffers) +{ + GLD_driver_dx7 *gld = NULL; +// D3DDEVTYPE d3dDevType; +// D3DPRESENT_PARAMETERS d3dpp; +// D3DDISPLAYMODE d3ddm; + D3DX_VIDMODEDESC d3ddm; + HRESULT hr; + DWORD dwWidth, dwHeight; + + // Error if context is NULL. + if (ctx == NULL) + return FALSE; + + gld = ctx->glPriv; + if (gld == NULL) + return FALSE; + + if (ctx->bSceneStarted) { + IDirect3DDevice7_EndScene(gld->pDev); + ctx->bSceneStarted = FALSE; + } +/* + d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + if (!bDefaultDriver) + d3dDevType = D3DDEVTYPE_REF; // Force Direct3D Reference Rasterise (software) + + // Get the display mode so we can make a compatible backbuffer + hResult = IDirect3D8_GetAdapterDisplayMode(gld->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hResult)) { + nContextError = GLDERR_D3D; +// goto return_with_error; + return FALSE; + } +*/ + // Release objects before Reset() + _gldDestroyPrimitiveBuffer(&gld->PB3d); + _gldDestroyPrimitiveBuffer(&gld->PB2d); + +/* + // Clear the presentation parameters (sets all members to zero) + ZeroMemory(&d3dpp, sizeof(d3dpp)); + + // Recommended by MS; needed for MultiSample. + // Be careful if altering this for FullScreenBlit + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + + d3dpp.BackBufferFormat = d3ddm.Format; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(gld->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); + d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; + d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; + + // TODO: Sync to refresh + + if (ctx->bFullscreen) { + ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen + d3dpp.Windowed = FALSE; + d3dpp.BackBufferWidth = d3ddm.Width; + d3dpp.BackBufferHeight = d3ddm.Height; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + // Get better benchmark results? KeithH +// d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_UNLIMITED; + } else { + ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages + d3dpp.Windowed = TRUE; + d3dpp.BackBufferWidth = ctx->dwWidth; + d3dpp.BackBufferHeight = ctx->dwHeight; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = 0; + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + } + hResult = IDirect3DDevice8_Reset(gld->pDev, &d3dpp); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "dglResize: Reset failed", hResult); + return FALSE; + //goto cleanup_and_return_with_error; + } +*/ + // Obtain dimensions of 'window' + if (ctx->bFullscreen) { + D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); + dwWidth = d3ddm.width; + dwHeight = d3ddm.height; + } else { + dwWidth = ctx->dwWidth; + dwHeight = ctx->dwHeight; + } + + // Resize context + hr = gld->pD3DXContext->lpVtbl->Resize(gld->pD3DXContext, dwWidth, dwHeight); + if (FAILED(hr)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "gldResizeDrawable_DX: Resize failed", hr); + return FALSE; + } + + // Clear the resized surface (DaveM) + { + D3DVIEWPORT7 vp1, vp2; + IDirect3DDevice7_GetViewport(gld->pDev, &vp1); + IDirect3DDevice7_GetViewport(gld->pDev, &vp2); + vp2.dwX = 0; + vp2.dwY = 0; + vp2.dwWidth = dwWidth; + vp2.dwHeight = dwHeight; + IDirect3DDevice7_SetViewport(gld->pDev, &vp2); + hr = gld->pD3DXContext->lpVtbl->Clear(gld->pD3DXContext, D3DCLEAR_TARGET); + if (FAILED(hr)) + ddlogError(DDLOG_WARN, "gldResizeDrawable_DX: Clear failed", hr); + IDirect3DDevice7_SetViewport(gld->pDev, &vp1); + } + + // + // Recreate objects + // + _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); + _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB3d); + + // Signal a complete state update + ctx->glCtx->Driver.UpdateState(ctx->glCtx, _NEW_ALL); + + // Begin a new scene + IDirect3DDevice7_BeginScene(gld->pDev); + ctx->bSceneStarted = TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyDrawable_DX( + DGL_ctx *ctx) +{ + GLD_driver_dx7 *lpCtx = NULL; + + // Error if context is NULL. + if (!ctx) + return FALSE; + + // Error if the drawable does not exist. + if (!ctx->glPriv) + return FALSE; + + lpCtx = ctx->glPriv; + +#ifdef _DEBUG + // Dump out stats + ddlogPrintf(DDLOG_SYSTEM, "Usage: M:0x%X%X, D:0x%X%X", + lpCtx->PipelineUsage.qwMesa.HighPart, + lpCtx->PipelineUsage.qwMesa.LowPart, + lpCtx->PipelineUsage.qwD3DFVF.HighPart, + lpCtx->PipelineUsage.qwD3DFVF.LowPart); +#endif + + // Destroy Primtive Buffers + _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); + _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); + + // Release DX interfaces (in reverse order) + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + //SAFE_RELEASE(lpCtx->pD3DXContext); + lpCtx->pD3DXContext->lpVtbl->Release(lpCtx->pD3DXContext); + + // Free the private drawable data + free(ctx->glPriv); + ctx->glPriv = NULL; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldCreatePrivateGlobals_DX(void) +{ +/* + ZeroMemory(&dx7Globals, sizeof(dx7Globals)); + + // Load d3d8.dll + dx8Globals.hD3D8DLL = LoadLibrary("D3D8.DLL"); + if (dx8Globals.hD3D8DLL == NULL) + return FALSE; + + // Now try and obtain Direct3DCreate8 + dx8Globals.fnDirect3DCreate8 = (FNDIRECT3DCREATE8)GetProcAddress(dx8Globals.hD3D8DLL, "Direct3DCreate8"); + if (dx8Globals.fnDirect3DCreate8 == NULL) { + FreeLibrary(dx8Globals.hD3D8DLL); + return FALSE; + } +*/ + + // Initialise D3DX + return FAILED(D3DXInitialize()) ? FALSE : TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyPrivateGlobals_DX(void) +{ +/* + if (dx7Globals.bDirect3DDevice) { + SAFE_RELEASE(dx7Globals.pDev); + dx7Globals.bDirect3DDevice = FALSE; + } + if (dx7Globals.bDirect3D) { + SAFE_RELEASE(dx7Globals.pD3D); + dx7Globals.bDirect3D = FALSE; + } + + FreeLibrary(dx8Globals.hD3D8DLL); + dx8Globals.hD3D8DLL = NULL; + dx8Globals.fnDirect3DCreate8 = NULL; +*/ + return FAILED(D3DXUninitialize()) ? FALSE : TRUE; +} + +//--------------------------------------------------------------------------- + +static void _BitsFromDisplayFormat( + D3DX_SURFACEFORMAT fmt, + BYTE *cColorBits, + BYTE *cRedBits, + BYTE *cGreenBits, + BYTE *cBlueBits, + BYTE *cAlphaBits) +{ + switch (fmt) { +/* case D3DX_SF_X1R5G5B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 5; + *cBlueBits = 5; + *cAlphaBits = 0; + return;*/ + case D3DX_SF_R5G5B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 5; + *cBlueBits = 5; + *cAlphaBits = 0; + return; + case D3DX_SF_R5G6B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 6; + *cBlueBits = 5; + *cAlphaBits = 0; + return; + case D3DX_SF_X8R8G8B8: + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 0; + return; + case D3DX_SF_A8R8G8B8: + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 8; + return; + } + + // Should not get here! + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 0; +} + +//--------------------------------------------------------------------------- + +static void _BitsFromDepthStencilFormat( + D3DX_SURFACEFORMAT fmt, + BYTE *cDepthBits, + BYTE *cStencilBits) +{ + // NOTE: GL expects either 32 or 16 as depth bits. + switch (fmt) { + case D3DX_SF_Z16S0: + *cDepthBits = 16; + *cStencilBits = 0; + return; + case D3DX_SF_Z32S0: + *cDepthBits = 32; + *cStencilBits = 0; + return; + case D3DX_SF_Z15S1: + *cDepthBits = 15; + *cStencilBits = 1; + return; + case D3DX_SF_Z24S8: + *cDepthBits = 24; + *cStencilBits = 8; + return; + case D3DX_SF_S1Z15: + *cDepthBits = 15; + *cStencilBits = 1; + return; + case D3DX_SF_S8Z24: + *cDepthBits = 24; + *cStencilBits = 8; + return; + } +} + +//--------------------------------------------------------------------------- +/* +BOOL GLD_CheckDepthStencilMatch( + DWORD dwDeviceIndex, + D3DX_SURFACEFORMAT sfWant) +{ + // Emulate function built in to DX9 + D3DX_SURFACEFORMAT sfFound; + int i; + int nFormats = D3DXGetMaxSurfaceFormats(dwDeviceIndex, NULL, D3DX_SC_DEPTHBUFFER); + if (nFormats) { + for (i=0; ilpVtbl->GetZBuffer(pD3DXContext); + + // Get pixel format of depth buffer + ddpf.dwSize = sizeof(ddpf); + pZBuffer->lpVtbl->GetPixelFormat(pZBuffer, &ddpf); + // Done with surface - release it + pZBuffer->lpVtbl->Release(pZBuffer); + + // Done with D3DX context + pD3DXContext->lpVtbl->Release(pD3DXContext); + + // Convert and return + return D3DXMakeSurfaceFormat(&ddpf); +} + +//--------------------------------------------------------------------------- + +BOOL gldBuildPixelformatList_DX(void) +{ + D3DX_DEVICEDESC d3dxdd; + D3DX_VIDMODEDESC d3ddm; + D3DX_SURFACEFORMAT fmt[64]; // 64 should be enough... + DWORD dwDeviceIndex; + DWORD surfClassFlags; +// IDirect3D7 *pD3D = NULL; + HRESULT hr; + int nSupportedFormats = 0; // Total formats + int nDepthOnlyFormats = 0; + int nDepthStencilFormats = 0; + int i; + DGL_pixelFormat *pPF; + BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; +// char buf[128]; +// char cat[8]; + + // Direct3D (SW or HW) + // These are arranged so that 'best' pixelformat + // is higher in the list (for ChoosePixelFormat). +/* const D3DFORMAT DepthStencil[4] = { + D3DX_SF_Z16S0, //D3DX_SF_D16, + D3DX_SF_Z15S1, //D3DX_SF_D15S1, + D3DX_SF_Z32S0, //D3DX_SF_D32, + D3DX_SF_Z24S8, //D3DX_SF_D24S8, + //D3DX_SF_D24X8, + //D3DX_SF_D24X4S4, + };*/ + + // Dump DX version + ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 7.0\n"); + + // Release any existing pixelformat list + if (glb.lpPF) { + free(glb.lpPF); + } + + glb.nPixelFormatCount = 0; + glb.lpPF = NULL; + + // + // Pixelformats for Direct3D (SW or HW) rendering + // + + dwDeviceIndex = (glb.dwDriver == GLDS_DRIVER_REF) ? D3DX_HWLEVEL_REFERENCE : D3DX_DEFAULT; + + // Dump description + D3DXGetDeviceDescription(dwDeviceIndex, &d3dxdd); + ddlogPrintf(GLDLOG_SYSTEM, "Device: %s", d3dxdd.driverDesc); + + // Get display mode + D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); + +#if 0 + // Phooey - this don't work... +/* + // Since D3DXGetMaxSurfaceFormats() can lie to us, we'll need a workaround. + // Explicitly test for matching depth/stencil to display bpp. + if (d3ddm.bpp <= 16) { + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z16S0)) + fmt[nSupportedFormats++] = D3DX_SF_Z16S0; + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z15S1)) + fmt[nSupportedFormats++] = D3DX_SF_Z15S1; + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_S1Z15)) + fmt[nSupportedFormats++] = D3DX_SF_S1Z15; + // Didn't find anything? Try default + if (nSupportedFormats == 0) { + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z32S0)) + fmt[nSupportedFormats++] = D3DX_SF_Z32S0; + } + } else { + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z32S0)) + fmt[nSupportedFormats++] = D3DX_SF_Z32S0; + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z24S8)) + fmt[nSupportedFormats++] = D3DX_SF_Z24S8; + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_S8Z24)) + fmt[nSupportedFormats++] = D3DX_SF_S8Z24; + // Didn't find anything? Try default + if (nSupportedFormats == 0) { + if (GLD_CheckDepthStencilMatch(dwDeviceIndex, D3DX_SF_Z16S0)) + fmt[nSupportedFormats++] = D3DX_SF_Z16S0; + } + } +*/ + // Go the Whole Hog... + fmt[nSupportedFormats++] = _gldFindCompatibleDepthStencilFormat(dwDeviceIndex); +#else + // + // Depth buffer formats WITHOUT stencil + // + surfClassFlags = D3DX_SC_DEPTHBUFFER; + nDepthOnlyFormats = D3DXGetMaxSurfaceFormats(dwDeviceIndex, NULL, surfClassFlags); + // + // Depth buffer formats WITH stencil + // + surfClassFlags = D3DX_SC_DEPTHBUFFER | D3DX_SC_STENCILBUFFER; + nDepthStencilFormats = D3DXGetMaxSurfaceFormats(dwDeviceIndex, NULL, surfClassFlags); + + // Work out how many formats we have in total + if ((nDepthOnlyFormats + nDepthStencilFormats) == 0) + return FALSE; // Bail: no compliant pixelformats + + // Get depth buffer formats WITHOUT stencil + surfClassFlags = D3DX_SC_DEPTHBUFFER; + for (i=0; ipfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + pPF->pfd.cDepthBits = 0; + pPF->pfd.cStencilBits = 0; + pPF->dwDriverData = D3DX_SF_UNKNOWN; + pPF++;*/ + + for (i=0; ipfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); + pPF->dwDriverData = fmt[i]; + } + + // + // Add double-buffer formats + // + +/* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + pPF->pfd.cDepthBits = 0; + pPF->pfd.cStencilBits = 0; + pPF->dwDriverData = D3DX_SF_UNKNOWN; + pPF++;*/ + + for (i=0; ipfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); + pPF->dwDriverData = fmt[i]; + } + + // Popup warning message if non RGB color mode + { + // This is a hack. KeithH + HDC hdcDesktop = GetDC(NULL); + DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); + ReleaseDC(0, hdcDesktop); + if (dwDisplayBitDepth <= 8) { + ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); + MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); + } + } + + // Mark list as 'current' + glb.bPixelformatsDirty = FALSE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldInitialiseMesa_DX( + DGL_ctx *lpCtx) +{ + GLD_driver_dx7 *gld = NULL; + int MaxTextureSize, TextureLevels; + BOOL bSoftwareTnL; + + if (lpCtx == NULL) + return FALSE; + + gld = lpCtx->glPriv; + if (gld == NULL) + return FALSE; + + if (glb.bMultitexture) { + lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps.wMaxSimultaneousTextures; + // Only support MAX_TEXTURE_UNITS texture units. + // ** If this is altered then the FVF formats must be reviewed **. + if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX7) + lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX7; + } else { + // Multitexture override + lpCtx->glCtx->Const.MaxTextureUnits = 1; + } + + // max texture size +// MaxTextureSize = min(gld->d3dCaps8.MaxTextureHeight, gld->d3dCaps8.MaxTextureWidth); + MaxTextureSize = min(gld->d3dCaps.dwMaxTextureHeight, gld->d3dCaps.dwMaxTextureWidth); + if (MaxTextureSize == 0) + MaxTextureSize = 256; // Sanity check + + // + // HACK!! + if (MaxTextureSize > 1024) + MaxTextureSize = 1024; // HACK - CLAMP TO 1024 + // HACK!! + // + + // TODO: Check this again for Mesa 5 + // Got to set MAX_TEXTURE_SIZE as max levels. + // Who thought this stupid idea up? ;) + TextureLevels = 0; + // Calculate power-of-two. + while (MaxTextureSize) { + TextureLevels++; + MaxTextureSize >>= 1; + } + lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8; + + // Defaults + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_LIGHTING, FALSE); + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_DITHERENABLE, TRUE); + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD); + + // Set texture coord set to be used with each stage + IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_TEXCOORDINDEX, 0); + IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_TEXCOORDINDEX, 1); + + // Set up Depth buffer + IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ZENABLE, + (lpCtx->lpPF->dwDriverData!=D3DX_SF_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE); + + // Set the view matrix + { + D3DXMATRIX vm; +#if 1 + D3DXMatrixIdentity(&vm); +#else + D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f); + D3DXVECTOR3 At(0.0f, 0.0f, -1.0f); + D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); + D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up); + vm._31 = -vm._31; + vm._32 = -vm._32; + vm._33 = -vm._33; + vm._34 = -vm._34; +#endif + IDirect3DDevice7_SetTransform(gld->pDev, D3DTRANSFORMSTATE_VIEW, &vm); + } + +// DX7 does not support D3DRS_SOFTWAREVERTEXPROCESSING +/* + if (gld->bHasHWTnL) { + if (glb.dwTnL == GLDS_TNL_DEFAULT) + bSoftwareTnL = FALSE; // HW TnL + else { + bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE; + } + } else { + // No HW TnL, so no choice possible + bSoftwareTnL = TRUE; + } + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL); +*/ + +// Dump this in a Release build as well, now. +//#ifdef _DEBUG + ddlogPrintf(DDLOG_INFO, "HW TnL: %s", +// gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable"); + gld->bHasHWTnL ? "Enabled" : "Unavailable"); +//#endif + + // Set up interfaces to Mesa + gldEnableExtensions_DX7(lpCtx->glCtx); + gldInstallPipeline_DX7(lpCtx->glCtx); + gldSetupDriverPointers_DX7(lpCtx->glCtx); + + // Signal a complete state update + lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL); + + // Start a scene + IDirect3DDevice7_BeginScene(gld->pDev); + lpCtx->bSceneStarted = TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldSwapBuffers_DX( + DGL_ctx *ctx, + HDC hDC, + HWND hWnd) +{ + HRESULT hr; + GLD_driver_dx7 *gld = NULL; + DWORD dwFlags; + + if (ctx == NULL) + return FALSE; + + gld = ctx->glPriv; + if (gld == NULL) + return FALSE; + + + // End the scene if one is started + if (ctx->bSceneStarted) { + IDirect3DDevice7_EndScene(gld->pDev); + ctx->bSceneStarted = FALSE; + } + + // Needed by D3DX for MDI multi-window apps (DaveM) + if (lpDDClipper) + IDirectDrawClipper_SetHWnd(lpDDClipper, 0, hWnd); + + // Swap the buffers. hWnd may override the hWnd used for CreateDevice() +// hr = IDirect3DDevice8_Present(gld->pDev, NULL, NULL, hWnd, NULL); + + // Set refresh sync flag + dwFlags = glb.bWaitForRetrace ? 0 : D3DX_UPDATE_NOVSYNC; + // Render and show frame + hr = gld->pD3DXContext->lpVtbl->UpdateFrame(gld->pD3DXContext, dwFlags); + if (FAILED(hr)) + ddlogError(DDLOG_WARN, "gldSwapBuffers_DX: UpdateFrame", hr); + + if (hr == DDERR_SURFACELOST) { + hr = gld->pD3DXContext->lpVtbl->RestoreSurfaces(gld->pD3DXContext); + if (FAILED(hr)) + ddlogError(DDLOG_WARN, "gldSwapBuffers_DX: RestoreSurfaces", hr); + } + +exit_swap: + // Begin a new scene + IDirect3DDevice7_BeginScene(gld->pDev); + ctx->bSceneStarted = TRUE; + + return (FAILED(hr)) ? FALSE : TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldGetDisplayMode_DX( + DGL_ctx *ctx, + GLD_displayMode *glddm) +{ +// D3DDISPLAYMODE d3ddm; + D3DX_VIDMODEDESC d3ddm; + HRESULT hr; + GLD_driver_dx7 *lpCtx = NULL; + BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; + + if ((glddm == NULL) || (ctx == NULL)) + return FALSE; + + lpCtx = ctx->glPriv; + if (lpCtx == NULL) + return FALSE; + + if (lpCtx->pD3D == NULL) + return FALSE; + +// hr = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); + hr = D3DXGetCurrentVideoMode(D3DX_DEFAULT, &d3ddm); + if (FAILED(hr)) + return FALSE; + + // Get info from the display format +// _BitsFromDisplayFormat(d3ddm.Format, +// &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); + + glddm->Width = d3ddm.width; + glddm->Height = d3ddm.height; + glddm->BPP = d3ddm.bpp; + glddm->Refresh = d3ddm.refreshRate; + + return TRUE; +} + +//--------------------------------------------------------------------------- + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_dxerr7.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_dxerr7.h @@ -0,0 +1,77 @@ +/*==========================================================================; + * + * + * File: dxerr8.h + * Content: DirectX Error Library Include File + * + ****************************************************************************/ + +#ifndef _GLD_DXERR7_H_ +#define _GLD_DXERR7_H_ + + +#include + +// +// DXGetErrorString8 +// +// Desc: Converts an DirectX HRESULT to a string +// +// Args: HRESULT hr Can be any error code from +// DPLAY D3D8 D3DX8 DMUSIC DSOUND +// +// Return: Converted string +// +const char* __stdcall DXGetErrorString8A(HRESULT hr); +const WCHAR* __stdcall DXGetErrorString8W(HRESULT hr); + +#ifdef UNICODE + #define DXGetErrorString8 DXGetErrorString8W +#else + #define DXGetErrorString8 DXGetErrorString8A +#endif + + +// +// DXTrace +// +// Desc: Outputs a formatted error message to the debug stream +// +// Args: CHAR* strFile The current file, typically passed in using the +// __FILE__ macro. +// DWORD dwLine The current line number, typically passed in using the +// __LINE__ macro. +// HRESULT hr An HRESULT that will be traced to the debug stream. +// CHAR* strMsg A string that will be traced to the debug stream (may be NULL) +// BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. +// +// Return: The hr that was passed in. +// +//HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox = FALSE ); +//HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox = FALSE ); +HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox); +HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox); + +#ifdef UNICODE + #define DXTrace DXTraceW +#else + #define DXTrace DXTraceA +#endif + + +// +// Helper macros +// +#if defined(DEBUG) | defined(_DEBUG) + #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) + #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) + #define DXTRACE_ERR_NOMSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) +#else + #define DXTRACE_MSG(str) (0L) + #define DXTRACE_ERR(str,hr) (hr) + #define DXTRACE_ERR_NOMSGBOX(str,hr) (hr) +#endif + + +#endif + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_primitive_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_primitive_dx7.c @@ -0,0 +1,1448 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Primitive (points/lines/tris/quads) rendering +* +****************************************************************************/ + +//#include "../GLDirect.h" + +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx7.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "swrast/s_context.h" +#include "swrast/s_depth.h" +#include "swrast/s_lines.h" +#include "swrast/s_triangle.h" +#include "swrast/s_trispan.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +// Disable compiler complaints about unreferenced local variables +#pragma warning (disable:4101) + +//--------------------------------------------------------------------------- +// Helper defines for primitives +//--------------------------------------------------------------------------- + +//static const float ooZ = 1.0f / 65536.0f; // One over Z + +#define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3])) +#define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3])) +#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) + +//--------------------------------------------------------------------------- +// 2D vertex setup +//--------------------------------------------------------------------------- + +#define GLD_SETUP_2D_VARS_POINTS \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour + +#define GLD_SETUP_2D_VARS_LINES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour + +#define GLD_SETUP_2D_VARS_TRIANGLES \ + BOOL bFog = ctx->Fog.Enabled; \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour; \ + GLuint facing = 0; \ + struct vertex_buffer *VB; \ + GLchan (*vbcolor)[4]; \ + GLchan (*vbspec)[4] + +#define GLD_SETUP_GET_SWVERT(s) \ + swv = &ss->verts[##s] + +#define GLD_SETUP_2D_VERTEX \ + pV->x = swv->win[0]; \ + pV->y = GLD_FLIP_Y(swv->win[1]); \ + pV->rhw = swv->win[3] + +#define GLD_SETUP_SMOOTH_COLOUR \ + pV->diffuse = GLD_COLOUR + +#define GLD_SETUP_GET_FLAT_COLOUR \ + dwFlatColour = GLD_COLOUR +#define GLD_SETUP_GET_FLAT_FOG_COLOUR \ + dwFlatColour = _gldComputeFog(ctx, swv) + +#define GLD_SETUP_USE_FLAT_COLOUR \ + pV->diffuse = dwFlatColour + +#define GLD_SETUP_GET_FLAT_SPECULAR \ + dwSpecularColour= GLD_SPECULAR + +#define GLD_SETUP_USE_FLAT_SPECULAR \ + pV->specular = dwSpecularColour + +#define GLD_SETUP_DEPTH \ + pV->sz = swv->win[2] / ctx->DepthMaxF +// pV->z = swv->win[2] * ooZ; + +#define GLD_SETUP_SPECULAR \ + pV->specular = GLD_SPECULAR + +#define GLD_SETUP_FOG \ + pV->diffuse = _gldComputeFog(ctx, swv) + +#define GLD_SETUP_TEX0 \ + pV->t0_u = swv->texcoord[0][0]; \ + pV->t0_v = swv->texcoord[0][1] + +#define GLD_SETUP_TEX1 \ + pV->t1_u = swv->texcoord[1][0]; \ + pV->t1_v = swv->texcoord[1][1] + +#define GLD_SETUP_LIGHTING(v) \ + if (facing == 1) { \ + pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ + if (vbspec) { \ + pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ + } \ + } else { \ + if (bFog) \ + GLD_SETUP_FOG; \ + else \ + GLD_SETUP_SMOOTH_COLOUR; \ + GLD_SETUP_SPECULAR; \ + } + +#define GLD_SETUP_GET_FLAT_LIGHTING(v) \ + if (facing == 1) { \ + dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ + if (vbspec) { \ + dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ + } \ + } + +#define GLD_SETUP_TWOSIDED_LIGHTING \ + /* Two-sided lighting */ \ + if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \ + SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \ + SWvertex *v[3]; \ + GLfloat ex,ey,fx,fy,cc; \ + /* Get vars for later */ \ + VB = &TNL_CONTEXT(ctx)->vb; \ + vbcolor = (GLchan (*)[4])VB->ColorPtr[1]->data; \ + if (VB->SecondaryColorPtr[1]) { \ + vbspec = (GLchan (*)[4])VB->SecondaryColorPtr[1]->data; \ + } else { \ + vbspec = NULL; \ + } \ + v[0] = &verts[v0]; \ + v[1] = &verts[v1]; \ + v[2] = &verts[v2]; \ + ex = v[0]->win[0] - v[2]->win[0]; \ + ey = v[0]->win[1] - v[2]->win[1]; \ + fx = v[1]->win[0] - v[2]->win[0]; \ + fy = v[1]->win[1] - v[2]->win[1]; \ + cc = ex*fy - ey*fx; \ + facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \ + } + +//--------------------------------------------------------------------------- +// 3D vertex setup +//--------------------------------------------------------------------------- + +#define GLD_SETUP_3D_VARS_POINTS \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VARS_LINES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VARS_TRIANGLES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VERTEX(v) \ + p4f = VB->ObjPtr->data; \ + pV->Position.x = p4f[##v][0]; \ + pV->Position.y = p4f[##v][1]; \ + pV->Position.z = p4f[##v][2]; + +#define GLD_SETUP_SMOOTH_COLOUR_3D(v) \ + p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ + pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); + + +#define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \ + p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ + dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); + +#define GLD_SETUP_USE_FLAT_COLOUR_3D \ + pV->Diffuse = dwColor; + +#define GLD_SETUP_TEX0_3D(v) \ + if (VB->TexCoordPtr[0]) { \ + tc = VB->TexCoordPtr[0]->data; \ + pV->TexUnit0.x = tc[##v][0]; \ + pV->TexUnit0.y = tc[##v][1]; \ + } + +#define GLD_SETUP_TEX1_3D(v) \ + if (VB->TexCoordPtr[1]) { \ + tc = VB->TexCoordPtr[1]->data; \ + pV->TexUnit1.x = tc[##v][0]; \ + pV->TexUnit1.y = tc[##v][1]; \ + } + +//--------------------------------------------------------------------------- +// Helper functions +//--------------------------------------------------------------------------- + +__inline DWORD _gldComputeFog( + GLcontext *ctx, + SWvertex *swv) +{ + // Full fog calculation. + // Based on Mesa code. + + GLchan rFog, gFog, bFog; + GLchan fR, fG, fB; + const GLfloat f = swv->fog; + const GLfloat g = 1.0 - f; + + UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); + fR = f * swv->color[0] + g * rFog; + fG = f * swv->color[1] + g * gFog; + fB = f * swv->color[2] + g * bFog; + return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]); +} + +//--------------------------------------------------------------------------- + +void gld_ResetLineStipple_DX7( + GLcontext *ctx) +{ + // TODO: Fake stipple with a 32x32 texture. +} + +//--------------------------------------------------------------------------- +// 2D (post-transformed) primitives +//--------------------------------------------------------------------------- + +void gld_Points2D_DX7( + GLcontext *ctx, + GLuint first, + GLuint last) +{ + GLD_SETUP_2D_VARS_POINTS; + + unsigned i; + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + // _Size is already clamped to MaxPointSize and MinPointSize + // Not supported by DX7 +// IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); + + if (VB->Elts) { + for (i=first; iClipMask[VB->Elts[i]] == 0) { +// _swrast_Point( ctx, &verts[VB->Elts[i]] ); + GLD_SETUP_GET_SWVERT(VB->Elts[i]); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + } + } + } else { + GLD_SETUP_GET_SWVERT(first); + for (i=first; iClipMask[i] == 0) { +// _swrast_Point( ctx, &verts[i] ); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + } + } + } + + gld->PB2d.pPoints = (BYTE*)pV; + gld->PB2d.nPoints += (last-first); +} + +//--------------------------------------------------------------------------- + +void gld_Line2DFlat_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_2D_VARS_LINES; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pLines = (BYTE*)pV; + gld->PB2d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Line2DSmooth_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_2D_VARS_LINES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_SPECULAR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pLines = (BYTE*)pV; + gld->PB2d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlat_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + pV++;; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmooth_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlatExtras_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v2); + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + if (bFog) + GLD_SETUP_GET_FLAT_FOG_COLOUR; + else + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_GET_FLAT_LIGHTING(v2); + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmoothExtras_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v0); + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v1); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlat_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmooth_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlatExtras_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v3); + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + if (bFog) + GLD_SETUP_GET_FLAT_FOG_COLOUR; + else + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_GET_FLAT_LIGHTING(v3); + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmoothExtras_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v0); + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v1); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v3); + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- +// 3D (pre-transformed) primitives +//--------------------------------------------------------------------------- + +void gld_Points3D_DX7( + GLcontext *ctx, + GLuint first, + GLuint last) +{ + GLD_SETUP_3D_VARS_POINTS + + unsigned i; +// struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + // _Size is already clamped to MaxPointSize and MinPointSize + // Not supported by DX7 +// IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); + + if (VB->Elts) { + for (i=first; iClipMask[VB->Elts[i]] == 0) { +// _swrast_Point( ctx, &verts[VB->Elts[i]] ); +// GLD_SETUP_GET_SWVERT(VB->Elts[i]); + GLD_SETUP_3D_VERTEX(VB->Elts[i]) + GLD_SETUP_SMOOTH_COLOUR_3D(i) + GLD_SETUP_TEX0_3D(i) + GLD_SETUP_TEX1_3D(i) + } + } + } else { +// GLD_SETUP_GET_SWVERT(first); + for (i=first; iClipMask[i] == 0) { +// _swrast_Point( ctx, &verts[i] ); + GLD_SETUP_3D_VERTEX(i) + GLD_SETUP_SMOOTH_COLOUR_3D(i) + GLD_SETUP_TEX0_3D(i) + GLD_SETUP_TEX1_3D(i) + } + } + } +/* + for (i=first; iPB3d.pPoints = (BYTE*)pV; + gld->PB3d.nPoints += (last-first); +} + +//--------------------------------------------------------------------------- +// Line functions +//--------------------------------------------------------------------------- + +void gld_Line3DFlat_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_3D_VARS_LINES + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_GET_FLAT_COLOUR_3D(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pLines = (BYTE*)pV; + gld->PB3d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Line3DSmooth_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_3D_VARS_LINES + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pLines = (BYTE*)pV; + gld->PB3d.nLines++; +} + +//--------------------------------------------------------------------------- +// Triangle functions +//--------------------------------------------------------------------------- + +void gld_Triangle3DFlat_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + GLD_SETUP_GET_FLAT_COLOUR_3D(v2) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle3DSmooth_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles++; +} + +//--------------------------------------------------------------------------- +// Quad functions +//--------------------------------------------------------------------------- + +void gld_Quad3DFlat_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_GET_FLAT_COLOUR_3D(v3) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad3DSmooth_DX7( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_SMOOTH_COLOUR_3D(v3) + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- +// Vertex setup for two-sided-lighting vertex shader +//--------------------------------------------------------------------------- + +/* + +void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last) +{ + // NOTE: Two-sided lighting does not apply to Points +} + +//--------------------------------------------------------------------------- + +void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) +{ + // NOTE: Two-sided lighting does not apply to Lines +} + +//--------------------------------------------------------------------------- + +void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) +{ + // NOTE: Two-sided lighting does not apply to Lines +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) +{ +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 4th vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 5th vert + swv = &ss->verts[v3]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 6th vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 4th vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 5th vert + swv = &ss->verts[v3]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 6th vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +*/ --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_vb_mesa_render_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_vb_mesa_render_dx7.c @@ -0,0 +1,423 @@ +/* $Id: gld_vb_mesa_render_dx7.c,v 1.6 2005/08/27 13:56:08 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * Copyright (C) 1999-2001 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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. + * + * Authors: + * Keith Whitwell + */ + + +/* + * Render whole vertex buffers, including projection of vertices from + * clip space and clipping of primitives. + * + * This file makes calls to project vertices and to the point, line + * and triangle rasterizers via the function pointers: + * + * context->Driver.Render.* + * + */ + + +//--------------------------------------------------------------------------- + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx7.h" + +//--------------------------------------------------------------------------- + +#include "glheader.h" +#include "context.h" +#include "macros.h" +// #include "mem.h" +#include "mtypes.h" +//#include "mmath.h" + +#include "math/m_matrix.h" +#include "math/m_xform.h" + +#include "tnl/t_pipeline.h" + +/**********************************************************************/ +/* Clip single primitives */ +/**********************************************************************/ + + +#if defined(USE_IEEE) +#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) +//#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) +#else +#define NEGATIVE(x) (x < 0) +//#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) +/* Could just use (x*y<0) except for the flatshading requirements. + * Maybe there's a better way? + */ +#endif + + +#define W(i) coord[i][3] +#define Z(i) coord[i][2] +#define Y(i) coord[i][1] +#define X(i) coord[i][0] +#define SIZE 4 +#define TAG(x) x##_4 +#include "tnl/t_vb_cliptmp.h" + + + +/**********************************************************************/ +/* Clip and render whole begin/end objects */ +/**********************************************************************/ + +#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] +#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val + + +/* Vertices, with the possibility of clipping. + */ +#define RENDER_POINTS( start, count ) \ + tnl->Driver.Render.Points( ctx, start, count ) + +#define RENDER_LINE( v1, v2 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2]; \ + GLubyte ormask = c1|c2; \ + if (!ormask) \ + LineFunc( ctx, v1, v2 ); \ + else if (!(c1 & c2 & 0x3f)) \ + clip_line_4( ctx, v1, v2, ormask ); \ +} while (0) + +#define RENDER_TRI( v1, v2, v3 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ + GLubyte ormask = c1|c2|c3; \ + if (!ormask) \ + TriangleFunc( ctx, v1, v2, v3 ); \ + else if (!(c1 & c2 & c3 & 0x3f)) \ + clip_tri_4( ctx, v1, v2, v3, ormask ); \ +} while (0) + +#define RENDER_QUAD( v1, v2, v3, v4 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2]; \ + GLubyte c3 = mask[v3], c4 = mask[v4]; \ + GLubyte ormask = c1|c2|c3|c4; \ + if (!ormask) \ + QuadFunc( ctx, v1, v2, v3, v4 ); \ + else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ + clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ +} while (0) + + +#define LOCAL_VARS \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + const GLuint * const elt = VB->Elts; \ + const GLubyte *mask = VB->ClipMask; \ + const GLuint sz = VB->ClipPtr->size; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + const GLboolean stipple = ctx->Line.StippleFlag; \ + (void) (LineFunc && TriangleFunc && QuadFunc); \ + (void) elt; (void) mask; (void) sz; (void) stipple; + +#define TAG(x) clip_##x##_verts +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) +#define PRESERVE_VB_DEFS +#include "tnl/t_vb_rendertmp.h" + + + +/* Elts, with the possibility of clipping. + */ +#undef ELT +#undef TAG +#define ELT(x) elt[x] +#define TAG(x) clip_##x##_elts +#include "tnl/t_vb_rendertmp.h" + +/* TODO: do this for all primitives, verts and elts: + */ +static void clip_elt_triangles( GLcontext *ctx, + GLuint start, + GLuint count, + GLuint flags ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; + struct vertex_buffer *VB = &tnl->vb; + const GLuint * const elt = VB->Elts; + GLubyte *mask = VB->ClipMask; + GLuint last = count-2; + GLuint j; + (void) flags; + + tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); + + for (j=start; j < last; j+=3 ) { + GLubyte c1 = mask[elt[j]]; + GLubyte c2 = mask[elt[j+1]]; + GLubyte c3 = mask[elt[j+2]]; + GLubyte ormask = c1|c2|c3; + if (ormask) { + if (start < j) + render_tris( ctx, start, j, 0 ); + if (!(c1&c2&c3&0x3f)) + clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); + start = j+3; + } + } + + if (start < j) + render_tris( ctx, start, j, 0 ); +} + +/**********************************************************************/ +/* Render whole begin/end objects */ +/**********************************************************************/ + +#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] +#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val + + +/* Vertices, no clipping. + */ +#define RENDER_POINTS( start, count ) \ + tnl->Driver.Render.Points( ctx, start, count ) + +#define RENDER_LINE( v1, v2 ) \ + LineFunc( ctx, v1, v2 ) + +#define RENDER_TRI( v1, v2, v3 ) \ + TriangleFunc( ctx, v1, v2, v3 ) + +#define RENDER_QUAD( v1, v2, v3, v4 ) \ + QuadFunc( ctx, v1, v2, v3, v4 ) + +#define TAG(x) _gld_tnl_##x##_verts + +#define LOCAL_VARS \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + const GLuint * const elt = VB->Elts; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + (void) (LineFunc && TriangleFunc && QuadFunc); \ + (void) elt; + +#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx ) +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RENDER_TAB_QUALIFIER +#define PRESERVE_VB_DEFS +#include "tnl/t_vb_rendertmp.h" + + +/* Elts, no clipping. + */ +#undef ELT +#define TAG(x) _gld_tnl_##x##_elts +#define ELT(x) elt[x] +#include "tnl/t_vb_rendertmp.h" + + +/**********************************************************************/ +/* Helper functions for drivers */ +/**********************************************************************/ +/* +void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + GLuint *tmp = VB->Elts; + + VB->Elts = (GLuint *)elts; + tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); + VB->Elts = tmp; +} + +void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl->Driver.Render.Line( ctx, ii, jj ); +} +*/ + + +/**********************************************************************/ +/* Clip and render whole vertex buffers */ +/**********************************************************************/ + +tnl_points_func _gldSetupPoints[4] = { + gld_Points2D_DX7, + gld_Points2D_DX7, + gld_Points2D_DX7, + gld_Points2D_DX7 +}; +tnl_line_func _gldSetupLine[4] = { + gld_Line2DFlat_DX7, + gld_Line2DSmooth_DX7, + gld_Line2DFlat_DX7, + gld_Line2DSmooth_DX7, +}; +tnl_triangle_func _gldSetupTriangle[4] = { + gld_Triangle2DFlat_DX7, + gld_Triangle2DSmooth_DX7, + gld_Triangle2DFlatExtras_DX7, + gld_Triangle2DSmoothExtras_DX7 +}; +tnl_quad_func _gldSetupQuad[4] = { + gld_Quad2DFlat_DX7, + gld_Quad2DSmooth_DX7, + gld_Quad2DFlatExtras_DX7, + gld_Quad2DSmoothExtras_DX7 +}; + +//--------------------------------------------------------------------------- + +static GLboolean _gld_mesa_render_stage_run( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + tnl_render_func *tab; + GLint pass = 0; + GLD_pb_dx7 *gldPB; + DWORD dwFlags; + + /* Allow the drivers to lock before projected verts are built so + * that window coordinates are guarenteed not to change before + * rendering. + */ + ASSERT(tnl->Driver.Render.Start); + + tnl->Driver.Render.Start( ctx ); + + gldPB = &gld->PB2d; + tnl->Driver.Render.Points = _gldSetupPoints[gld->iSetupFunc]; + tnl->Driver.Render.Line = _gldSetupLine[gld->iSetupFunc]; + tnl->Driver.Render.Triangle = _gldSetupTriangle[gld->iSetupFunc]; + tnl->Driver.Render.Quad = _gldSetupQuad[gld->iSetupFunc]; + + dwFlags = DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY; + _GLD_DX7_VB(Lock(gldPB->pVB, dwFlags, &gldPB->pPoints, NULL)); + gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; + + // Allocate primitive pointers - gldPB->pPoints is always first + gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); + gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); + + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); + + tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); + + if (VB->ClipOrMask) { + tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; + clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; + } + else { + tab = (VB->Elts ? + tnl->Driver.Render.PrimTabElts : + tnl->Driver.Render.PrimTabVerts); + } + + do { + GLuint i, length, flags = 0; + for (i = 0 ; !(flags & PRIM_END) ; i += length) { + flags = VB->Primitive[i].mode; + length= VB->Primitive[i].count; + ASSERT(length || (flags & PRIM_END)); + ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + if (length) + tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + } + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + + +// tnl->Driver.Render.Finish( ctx ); + + _GLD_DX7_VB(Unlock(gldPB->pVB)); + + if (gldPB->nPoints) { + _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_POINTLIST, gldPB->pVB, 0, gldPB->nPoints, 0)); + gldPB->nPoints = 0; + } + + if (gldPB->nLines) { + _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_LINELIST, gldPB->pVB, gldPB->iFirstLine, gldPB->nLines*2, 0)); + gldPB->nLines = 0; + } + + if (gldPB->nTriangles) { + _GLD_DX7_DEV(DrawPrimitiveVB(gld->pDev, D3DPT_TRIANGLELIST, gldPB->pVB, gldPB->iFirstTriangle, gldPB->nTriangles*3, 0)); + gldPB->nTriangles = 0; + } + + return GL_FALSE; /* finished the pipe */ +} + + +/**********************************************************************/ +/* Render pipeline stage */ +/**********************************************************************/ + + + +const struct tnl_pipeline_stage _gld_mesa_render_stage = +{ + "gld_mesa_render_stage", + NULL, + NULL, + NULL, + NULL, + _gld_mesa_render_stage_run /* run */ +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx7/gld_driver_dx7.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx7/gld_driver_dx7.c @@ -0,0 +1,1196 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Driver interface code to Mesa +* +****************************************************************************/ + +//#include +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx7.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "teximage.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +extern BOOL dglSwapBuffers(HDC hDC); + +// HACK: Hack the _33 member of the OpenGL perspective projection matrix +const float _fPersp_33 = 1.6f; + +//--------------------------------------------------------------------------- +// Internal functions +//--------------------------------------------------------------------------- + +void _gld_mesa_warning( + __GLcontext *gc, + char *str) +{ + // Intercept Mesa's internal warning mechanism + gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str); +} + +//--------------------------------------------------------------------------- + +void _gld_mesa_fatal( + __GLcontext *gc, + char *str) +{ + // Intercept Mesa's internal fatal-message mechanism + gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str); + + // Mesa calls abort(0) here. + ddlogClose(); + exit(0); +} + +//--------------------------------------------------------------------------- + +D3DSTENCILOP _gldConvertStencilOp( + GLenum StencilOp) +{ + // Used by Stencil: pass, fail and zfail + + switch (StencilOp) { + case GL_KEEP: + return D3DSTENCILOP_KEEP; + case GL_ZERO: + return D3DSTENCILOP_ZERO; + case GL_REPLACE: + return D3DSTENCILOP_REPLACE; + case GL_INCR: + return D3DSTENCILOP_INCRSAT; + case GL_DECR: + return D3DSTENCILOP_DECRSAT; + case GL_INVERT: + return D3DSTENCILOP_INVERT; + case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap + return D3DSTENCILOP_INCR; + case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap + return D3DSTENCILOP_DECR; + } + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n"); +#endif + + return D3DSTENCILOP_KEEP; +} + +//--------------------------------------------------------------------------- + +D3DCMPFUNC _gldConvertCompareFunc( + GLenum CmpFunc) +{ + // Used for Alpha func, depth func and stencil func. + + switch (CmpFunc) { + case GL_NEVER: + return D3DCMP_NEVER; + case GL_LESS: + return D3DCMP_LESS; + case GL_EQUAL: + return D3DCMP_EQUAL; + case GL_LEQUAL: + return D3DCMP_LESSEQUAL; + case GL_GREATER: + return D3DCMP_GREATER; + case GL_NOTEQUAL: + return D3DCMP_NOTEQUAL; + case GL_GEQUAL: + return D3DCMP_GREATEREQUAL; + case GL_ALWAYS: + return D3DCMP_ALWAYS; + }; + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n"); +#endif + + return D3DCMP_ALWAYS; +} + +//--------------------------------------------------------------------------- + +D3DBLEND _gldConvertBlendFunc( + GLenum blend, + GLenum DefaultBlend) +{ + switch (blend) { + case GL_ZERO: + return D3DBLEND_ZERO; + case GL_ONE: + return D3DBLEND_ONE; + case GL_DST_COLOR: + return D3DBLEND_DESTCOLOR; + case GL_SRC_COLOR: + return D3DBLEND_SRCCOLOR; + case GL_ONE_MINUS_DST_COLOR: + return D3DBLEND_INVDESTCOLOR; + case GL_ONE_MINUS_SRC_COLOR: + return D3DBLEND_INVSRCCOLOR; + case GL_SRC_ALPHA: + return D3DBLEND_SRCALPHA; + case GL_ONE_MINUS_SRC_ALPHA: + return D3DBLEND_INVSRCALPHA; + case GL_DST_ALPHA: + return D3DBLEND_DESTALPHA; + case GL_ONE_MINUS_DST_ALPHA: + return D3DBLEND_INVDESTALPHA; + case GL_SRC_ALPHA_SATURATE: + return D3DBLEND_SRCALPHASAT; + } + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n"); +#endif + + return DefaultBlend; +} + +//--------------------------------------------------------------------------- +// Misc. functions +//--------------------------------------------------------------------------- + +void gld_Noop_DX7( + GLcontext *ctx) +{ +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n"); +#endif +} + +//--------------------------------------------------------------------------- + +void gld_Error_DX7( + GLcontext *ctx) +{ +#ifdef _DEBUG + // Quite useless. +// gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n"); +#endif +} + +//--------------------------------------------------------------------------- +// Required Mesa functions +//--------------------------------------------------------------------------- + +static GLboolean gld_set_draw_buffer_DX7( + GLcontext *ctx, + GLenum mode) +{ + (void) ctx; + if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) { + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + +//--------------------------------------------------------------------------- + +static void gld_set_read_buffer_DX7( + GLcontext *ctx, + GLframebuffer *buffer, + GLenum mode) +{ + /* separate read buffer not supported */ +/* + ASSERT(buffer == ctx->DrawBuffer); + ASSERT(mode == GL_FRONT_LEFT); +*/ +} + +//--------------------------------------------------------------------------- + +void gld_Clear_DX7( + GLcontext *ctx, + GLbitfield mask, + GLboolean all, + GLint x, + GLint y, + GLint width, + GLint height) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + DWORD dwFlags = 0; + D3DCOLOR Color = 0; + float Z = 0.0f; + DWORD Stencil = 0; + D3DRECT d3dClearRect; + + // TODO: Colourmask + const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; + + if (!gld->pDev) + return; + + if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { + GLubyte col[4]; + CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]); + CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]); + CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]); + CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]); + dwFlags |= D3DCLEAR_TARGET; + Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]); +// ctx->Color.ClearColor[1], +// ctx->Color.ClearColor[2], +// ctx->Color.ClearColor[3]); + } + + if (mask & DD_DEPTH_BIT) { + // D3D7 will fail the Clear call if we try and clear a + // depth buffer and we haven't created one. + // Also, some apps try and clear a depth buffer, + // when a depth buffer hasn't been requested by the app. + if (ctx->Visual.depthBits == 0) { + mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask + } else { + dwFlags |= D3DCLEAR_ZBUFFER; + Z = ctx->Depth.Clear; + } + } + + if (mask & DD_STENCIL_BIT) { + if (ctx->Visual.stencilBits == 0) { + // No stencil bits in depth buffer + mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask + } else { + dwFlags |= D3DCLEAR_STENCIL; + Stencil = ctx->Stencil.Clear; + } + } + + // Some apps do really weird things with the rect, such as Quake3. + if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) { + all = GL_TRUE; + } + + if (!all) { + // Calculate clear subrect + d3dClearRect.x1 = x; + d3dClearRect.y1 = gldCtx->dwHeight - (y + height); + d3dClearRect.x2 = x + width; + d3dClearRect.y2 = d3dClearRect.y1 + height; + } + + // dwFlags will be zero if there's nothing to clear + if (dwFlags) { + _GLD_DX7_DEV(Clear( + gld->pDev, + all ? 0 : 1, + all ? NULL : &d3dClearRect, + dwFlags, + Color, Z, Stencil)); + } + + if (mask & DD_ACCUM_BIT) { + // Clear accumulation buffer + } +} + +//--------------------------------------------------------------------------- + +// Mesa 5: Parameter change +static void gld_buffer_size_DX7( +// GLcontext *ctx, + GLframebuffer *fb, + GLuint *width, + GLuint *height) +{ +// GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + + *width = fb->Width; // gldCtx->dwWidth; + *height = fb->Height; // gldCtx->dwHeight; +} + +//--------------------------------------------------------------------------- + +static void gld_Finish_DX7( + GLcontext *ctx) +{ +} + +//--------------------------------------------------------------------------- + +static void gld_Flush_DX7( + GLcontext *ctx) +{ + GLD_context *gld = GLD_GET_CONTEXT(ctx); + + // TODO: Detect apps that glFlush() then SwapBuffers() ? + + if (gld->EmulateSingle) { + // Emulating a single-buffered context. + // [Direct3D doesn't allow rendering to front buffer] + dglSwapBuffers(gld->hDC); + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_STENCIL( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + // Two-sided stencil. New for Mesa 5 + const GLuint uiFace = 0UL; + + struct gl_stencil_attrib *pStencil = &ctx->Stencil; + + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE)); + if (pStencil->Enabled) { + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace]))); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILREF, pStencil->Ref[uiFace])); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILMASK, pStencil->ValueMask[uiFace])); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILWRITEMASK, pStencil->WriteMask[uiFace])); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace]))); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace]))); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace]))); + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_COLOR( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + DWORD dwFlags = 0; + D3DBLEND src; + D3DBLEND dest; + + // Alpha func + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc))); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAREF, (DWORD)ctx->Color.AlphaRef)); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHATESTENABLE, ctx->Color.AlphaEnabled)); + + // Blend func + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHABLENDENABLE, ctx->Color.BlendEnabled)); + src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE); + dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SRCBLEND, src)); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_DESTBLEND, dest)); + +/* + // Color mask - unsupported by DX7 + if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED; + if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN; + if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE; + if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA; + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_COLORWRITEENABLE, dwFlags)); +*/ +} + +//--------------------------------------------------------------------------- + +void gld_NEW_DEPTH( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE)); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func))); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_POLYGON( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DFILLMODE d3dFillMode = D3DFILL_SOLID; + D3DCULL d3dCullMode = D3DCULL_NONE; + int iOffset = 0; + + // Fillmode + switch (ctx->Polygon.FrontMode) { + case GL_POINT: + d3dFillMode = D3DFILL_POINT; + break; + case GL_LINE: + d3dFillMode = D3DFILL_WIREFRAME; + break; + case GL_FILL: + d3dFillMode = D3DFILL_SOLID; + break; + } + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FILLMODE, d3dFillMode)); + + if (ctx->Polygon.CullFlag) { + switch (ctx->Polygon.CullFaceMode) { + case GL_BACK: + if (ctx->Polygon.FrontFace == GL_CCW) + d3dCullMode = D3DCULL_CW; + else + d3dCullMode = D3DCULL_CCW; + break; + case GL_FRONT: + if (ctx->Polygon.FrontFace == GL_CCW) + d3dCullMode = D3DCULL_CCW; + else + d3dCullMode = D3DCULL_CW; + break; + case GL_FRONT_AND_BACK: + d3dCullMode = D3DCULL_NONE; + break; + default: + break; + } + } else { + d3dCullMode = D3DCULL_NONE; + } +// d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, d3dCullMode)); + + // Polygon offset + // ZBIAS ranges from 0 to 16 and can only move towards the viewer + // Mesa5: ctx->Polygon._OffsetAny removed + if (ctx->Polygon.OffsetFill) { + iOffset = (int)ctx->Polygon.OffsetUnits; + if (iOffset < 0) + iOffset = -iOffset; + else + iOffset = 0; // D3D can't push away + } + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZBIAS, iOffset)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_FOG( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DCOLOR d3dFogColour; + D3DFOGMODE d3dFogMode = D3DFOG_LINEAR; + + // TODO: Fog is calculated seperately in the Mesa pipeline + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGENABLE, FALSE)); + return; + + // Fog enable + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGENABLE, ctx->Fog.Enabled)); + if (!ctx->Fog.Enabled) { + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE)); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE)); + return; // If disabled, don't bother setting any fog state + } + + // Fog colour + d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0], + ctx->Fog.Color[1], + ctx->Fog.Color[2], + ctx->Fog.Color[3]); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGCOLOR, d3dFogColour)); + + // Fog density + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density)))); + + // Fog start + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGSTART, *((DWORD*) (&ctx->Fog.Start)))); + + // Fog end + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGEND, *((DWORD*) (&ctx->Fog.End)))); + + // Fog mode + switch (ctx->Fog.Mode) { + case GL_LINEAR: + d3dFogMode = D3DFOG_LINEAR; + break; + case GL_EXP: + d3dFogMode = D3DFOG_EXP; + break; + case GL_EXP2: + d3dFogMode = D3DFOG_EXP2; + break; + } + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGTABLEMODE, d3dFogMode)); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_LIGHT( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + DWORD dwSpecularEnable; + + // Shademode + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT)); + + // Separate specular colour + if (ctx->Light.Enabled) + dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE; + else + dwSpecularEnable = FALSE; + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SPECULARENABLE, dwSpecularEnable)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_MODELVIEW( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DMATRIX m; + //GLfloat *pM = ctx->ModelView.m; + // Mesa5: Model-view is now a stack + GLfloat *pM = ctx->ModelviewMatrixStack.Top->m; + m._11 = pM[0]; + m._12 = pM[1]; + m._13 = pM[2]; + m._14 = pM[3]; + m._21 = pM[4]; + m._22 = pM[5]; + m._23 = pM[6]; + m._24 = pM[7]; + m._31 = pM[8]; + m._32 = pM[9]; + m._33 = pM[10]; + m._34 = pM[11]; + m._41 = pM[12]; + m._42 = pM[13]; + m._43 = pM[14]; + m._44 = pM[15]; +/* m[0][0] = pM[0]; + m[0][1] = pM[1]; + m[0][2] = pM[2]; + m[0][3] = pM[3]; + m[1][0] = pM[4]; + m[1][1] = pM[5]; + m[1][2] = pM[6]; + m[1][3] = pM[7]; + m[2][0] = pM[8]; + m[2][1] = pM[9]; + m[2][2] = pM[10]; + m[2][3] = pM[11]; + m[3][0] = pM[12]; + m[3][1] = pM[13]; + m[3][2] = pM[14]; + m[3][3] = pM[15];*/ + + gld->matModelView = m; +} + +//--------------------------------------------------------------------------- + +void gld_NEW_PROJECTION( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DMATRIX m; + //GLfloat *pM = ctx->ProjectionMatrix.m; + // Mesa 5: Now a stack + GLfloat *pM = ctx->ProjectionMatrixStack.Top->m; + m._11 = pM[0]; + m._12 = pM[1]; + m._13 = pM[2]; + m._14 = pM[3]; + + m._21 = pM[4]; + m._22 = pM[5]; + m._23 = pM[6]; + m._24 = pM[7]; + + m._31 = pM[8]; + m._32 = pM[9]; + m._33 = pM[10] / _fPersp_33; // / 1.6f; + m._34 = pM[11]; + + m._41 = pM[12]; + m._42 = pM[13]; + m._43 = pM[14] / 2.0f; + m._44 = pM[15]; + + gld->matProjection = m; +} + +//--------------------------------------------------------------------------- +/* +void gldFrustumHook_DX7( + GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearval, + GLdouble farval) +{ + GET_CURRENT_CONTEXT(ctx); + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + // Pass values on to Mesa first (in case we mess with them) + _mesa_Frustum(left, right, bottom, top, nearval, farval); + + _fPersp_33 = farval / (nearval - farval); + +// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval); +} + +//--------------------------------------------------------------------------- + +void gldOrthoHook_DX7( + GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearval, + GLdouble farval) +{ + GET_CURRENT_CONTEXT(ctx); + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + // Pass values on to Mesa first (in case we mess with them) + _mesa_Ortho(left, right, bottom, top, nearval, farval); + + _fPersp_33 = 1.6f; + +// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval); +} +*/ +//--------------------------------------------------------------------------- + +void gld_NEW_VIEWPORT( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DVIEWPORT7 d3dvp; +// GLint x, y; +// GLsizei w, h; + + // Set depth range + _GLD_DX7_DEV(GetViewport(gld->pDev, &d3dvp)); + // D3D can't do Quake1/Quake2 z-trick + if (ctx->Viewport.Near <= ctx->Viewport.Far) { + d3dvp.dvMinZ = ctx->Viewport.Near; + d3dvp.dvMaxZ = ctx->Viewport.Far; + } else { + d3dvp.dvMinZ = ctx->Viewport.Far; + d3dvp.dvMaxZ = ctx->Viewport.Near; + } +/* x = ctx->Viewport.X; + y = ctx->Viewport.Y; + w = ctx->Viewport.Width; + h = ctx->Viewport.Height; + if (x < 0) x = 0; + if (y < 0) y = 0; + if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; + if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; + // Ditto for D3D viewport dimensions + if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; + if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; + d3dvp.X = x; + d3dvp.Y = gldCtx->dwHeight - (y + h); + d3dvp.Width = w; + d3dvp.Height = h;*/ + _GLD_DX7_DEV(SetViewport(gld->pDev, &d3dvp)); + +// gld->fFlipWindowY = (float)gldCtx->dwHeight; +} + +//--------------------------------------------------------------------------- + +__inline BOOL _gldAnyEvalEnabled( + GLcontext *ctx) +{ + struct gl_eval_attrib *eval = &ctx->Eval; + + if ((eval->AutoNormal) || + (eval->Map1Color4) || + (eval->Map1Index) || + (eval->Map1Normal) || + (eval->Map1TextureCoord1) || + (eval->Map1TextureCoord2) || + (eval->Map1TextureCoord3) || + (eval->Map1TextureCoord4) || + (eval->Map1Vertex3) || + (eval->Map1Vertex4) || + (eval->Map2Color4) || + (eval->Map2Index) || + (eval->Map2Normal) || + (eval->Map2TextureCoord1) || + (eval->Map2TextureCoord2) || + (eval->Map2TextureCoord3) || + (eval->Map2TextureCoord4) || + (eval->Map2Vertex3) || + (eval->Map2Vertex4) + ) + return TRUE; + + return FALSE; +} + +//--------------------------------------------------------------------------- + +BOOL _gldChooseInternalPipeline( + GLcontext *ctx, + GLD_driver_dx7 *gld) +{ +// return TRUE; // DEBUGGING: ALWAYS USE MESA +// return FALSE; // DEBUGGING: ALWAYS USE D3D + + if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE)) + { + gld->PipelineUsage.qwMesa.QuadPart++; + return TRUE; // Force Mesa TnL + } + + if ((ctx->Light.Enabled) || + (1) || + (ctx->Texture._TexGenEnabled) || + (ctx->Texture._TexMatEnabled) || +// (ctx->Transform._AnyClip) || + (ctx->Scissor.Enabled) || + _gldAnyEvalEnabled(ctx) // Put this last so we can early-out + ) + { + gld->PipelineUsage.qwMesa.QuadPart++; + return TRUE; + } + + gld->PipelineUsage.qwD3DFVF.QuadPart++; + return FALSE; + +/* // Force Mesa pipeline? + if (glb.dwTnL == GLDS_TNL_MESA) { + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + + // Test for functionality not exposed in the D3D pathways + if ((ctx->Texture._GenFlags)) { + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + + // Now decide if vertex shader can be used. + // If two sided lighting is enabled then we must either + // use Mesa TnL or the vertex shader + if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { + if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) { + // Use Vertex Shader + gld->PipelineUsage.dwD3D2SVS.QuadPart++; + return GLD_PIPELINE_D3D_VS_TWOSIDE; + } else { + // Use Mesa TnL + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + } + + // Must be D3D fixed-function pipeline + gld->PipelineUsage.dwD3DFVF.QuadPart++; + return GLD_PIPELINE_D3D_FVF; +*/ +} + +//--------------------------------------------------------------------------- + +void gld_update_state_DX7( + GLcontext *ctx, + GLuint new_state) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + TNLcontext *tnl = TNL_CONTEXT(ctx); + GLD_pb_dx7 *gldPB; + + if (!gld || !gld->pDev) + return; + + _swsetup_InvalidateState( ctx, new_state ); + _vbo_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + + // SetupIndex will be used in the pipelines for choosing setup function + if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) || + (ctx->Fog.Enabled)) + { + if (ctx->_TriangleCaps & DD_FLATSHADE) + gld->iSetupFunc = GLD_SI_FLAT_EXTRAS; + else + gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS; + } else { + if (ctx->_TriangleCaps & DD_FLATSHADE) + gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture + else + gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture + } + + gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld); + if (gld->bUseMesaTnL) { + gldPB = &gld->PB2d; + // DX7 Does not implement D3DRS_SOFTWAREVERTEXPROCESSING +// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, TRUE)); + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, FALSE)); +// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); + } else { + gldPB = &gld->PB3d; + _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, TRUE)); +// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) { +// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware)); +// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); +// } else { + // DX7 Does not implement D3DRS_SOFTWAREVERTEXPROCESSING +// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL)); +// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); +// } + } + +#define _GLD_TEST_STATE(a) \ + if (new_state & (a)) { \ + gld##a(ctx); \ + new_state &= ~(a); \ + } + +#define _GLD_TEST_STATE_DX7(a) \ + if (new_state & (a)) { \ + gld##a##_DX7(ctx); \ + new_state &= ~(a); \ + } + +#define _GLD_IGNORE_STATE(a) new_state &= ~(a); + +// if (!gld->bUseMesaTnL) { + // Not required if Mesa is doing the TnL. + // Problem: If gld->bUseMesaTnL is TRUE when these are signaled, + // then we'll miss updating the D3D TnL pipeline. + // Therefore, don't test for gld->bUseMesaTnL + _GLD_TEST_STATE(_NEW_MODELVIEW); + _GLD_TEST_STATE(_NEW_PROJECTION); +// } + + _GLD_TEST_STATE_DX7(_NEW_TEXTURE); // extern, so guard with _DX7 + _GLD_TEST_STATE(_NEW_COLOR); + _GLD_TEST_STATE(_NEW_DEPTH); + _GLD_TEST_STATE(_NEW_POLYGON); + _GLD_TEST_STATE(_NEW_STENCIL); + _GLD_TEST_STATE(_NEW_FOG); + _GLD_TEST_STATE(_NEW_LIGHT); + _GLD_TEST_STATE(_NEW_VIEWPORT); + + _GLD_IGNORE_STATE(_NEW_TRANSFORM); + + +// Stubs for future use. +/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX); + _GLD_TEST_STATE(_NEW_COLOR_MATRIX); + _GLD_TEST_STATE(_NEW_ACCUM); + _GLD_TEST_STATE(_NEW_EVAL); + _GLD_TEST_STATE(_NEW_HINT); + _GLD_TEST_STATE(_NEW_LINE); + _GLD_TEST_STATE(_NEW_PIXEL); + _GLD_TEST_STATE(_NEW_POINT); + _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE); + _GLD_TEST_STATE(_NEW_SCISSOR); + _GLD_TEST_STATE(_NEW_PACKUNPACK); + _GLD_TEST_STATE(_NEW_ARRAY); + _GLD_TEST_STATE(_NEW_RENDERMODE); + _GLD_TEST_STATE(_NEW_BUFFERS); + _GLD_TEST_STATE(_NEW_MULTISAMPLE); +*/ + +// For debugging. +#if 0 +#define _GLD_TEST_UNHANDLED_STATE(a) \ + if (new_state & (a)) { \ + gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \ + } + _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX); + _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX); + _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM); + _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL); + _GLD_TEST_UNHANDLED_STATE(_NEW_HINT); + _GLD_TEST_UNHANDLED_STATE(_NEW_LINE); + _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL); + _GLD_TEST_UNHANDLED_STATE(_NEW_POINT); + _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE); + _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR); + _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK); + _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY); + _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE); + _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS); + _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE); +#undef _GLD_UNHANDLED_STATE +#endif + +#undef _GLD_TEST_STATE +} + +//--------------------------------------------------------------------------- +// Viewport +//--------------------------------------------------------------------------- + +void gld_Viewport_DX7( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei w, + GLsizei h) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + D3DVIEWPORT7 d3dvp; + + if (!gld || !gld->pDev) + return; + + // This is a hack. When the app is minimized, Mesa passes + // w=1 and h=1 for viewport dimensions. Without this test + // we get a GPF in gld_wgl_resize_buffers(). + if ((w==1) && (h==1)) + return; + + // Call ResizeBuffersMESA. This function will early-out + // if no resize is needed. + //ctx->Driver.ResizeBuffersMESA(ctx); + // Mesa 5: Changed parameters + ctx->Driver.ResizeBuffers(gldCtx->glBuffer); + +#if 0 + ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h); +#endif + + // ** D3D viewport must not be outside the render target surface ** + // Sanity check the GL viewport dimensions + if (x < 0) x = 0; + if (y < 0) y = 0; + if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; + if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; + // Ditto for D3D viewport dimensions + if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; + if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; + + d3dvp.dwX = x; + d3dvp.dwY = gldCtx->dwHeight - (y + h); + d3dvp.dwWidth = w; + d3dvp.dwHeight = h; + if (ctx->Viewport.Near <= ctx->Viewport.Far) { + d3dvp.dvMinZ = ctx->Viewport.Near; + d3dvp.dvMaxZ = ctx->Viewport.Far; + } else { + d3dvp.dvMinZ = ctx->Viewport.Far; + d3dvp.dvMaxZ = ctx->Viewport.Near; + } + + // TODO: DEBUGGING +// d3dvp.MinZ = 0.0f; +// d3dvp.MaxZ = 1.0f; + + _GLD_DX7_DEV(SetViewport(gld->pDev, &d3dvp)); + +} + +//--------------------------------------------------------------------------- + +extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver); + +// Mesa 5: Parameter change +void gldResizeBuffers_DX7( +// GLcontext *ctx) + GLframebuffer *fb) +{ + GET_CURRENT_CONTEXT(ctx); + dglWglResizeBuffers(ctx, TRUE); +} + +//--------------------------------------------------------------------------- +#ifdef _DEBUG +// This is only for debugging. +// To use, plug into ctx->Driver.Enable pointer below. +void gld_Enable( + GLcontext *ctx, + GLenum e, + GLboolean b) +{ + char buf[1024]; + sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE"); + ddlogMessage(DDLOG_SYSTEM, buf); +} +#endif +//--------------------------------------------------------------------------- +// Driver pointer setup +//--------------------------------------------------------------------------- + +extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum); + +void gldSetupDriverPointers_DX7( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx); + + TNLcontext *tnl = TNL_CONTEXT(ctx); + + // Mandatory functions + ctx->Driver.GetString = _gldGetStringGeneric; + ctx->Driver.UpdateState = gld_update_state_DX7; + ctx->Driver.Clear = gld_Clear_DX7; + ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX7; + ctx->Driver.GetBufferSize = gld_buffer_size_DX7; + ctx->Driver.Finish = gld_Finish_DX7; + ctx->Driver.Flush = gld_Flush_DX7; + ctx->Driver.Error = gld_Error_DX7; + + // Hardware accumulation buffer + ctx->Driver.Accum = NULL; // TODO: gld_Accum; + + // Bitmap functions + ctx->Driver.CopyPixels = gld_CopyPixels_DX7; + ctx->Driver.DrawPixels = gld_DrawPixels_DX7; + ctx->Driver.ReadPixels = gld_ReadPixels_DX7; + ctx->Driver.Bitmap = gld_Bitmap_DX7; + + // Buffer resize + ctx->Driver.ResizeBuffers = gldResizeBuffers_DX7; + + // Texture image functions + ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX7; + ctx->Driver.TexImage1D = gld_TexImage1D_DX7; + ctx->Driver.TexImage2D = gld_TexImage2D_DX7; + ctx->Driver.TexImage3D = _mesa_store_teximage3d; + ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX7; + ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX7; + ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + + ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX7; //NULL; + ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX7; //NULL; + ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX7; //NULL; + ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX7; //NULL; + ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX7; + ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; + + // Texture object functions + ctx->Driver.BindTexture = NULL; + ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!; + ctx->Driver.DeleteTexture = gld_DeleteTexture_DX7; + ctx->Driver.PrioritizeTexture = NULL; + + // Imaging functionality + ctx->Driver.CopyColorTable = NULL; + ctx->Driver.CopyColorSubTable = NULL; + ctx->Driver.CopyConvolutionFilter1D = NULL; + ctx->Driver.CopyConvolutionFilter2D = NULL; + + // State changing functions + ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc; + ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc; + ctx->Driver.ClearColor = NULL; //gld_ClearColor; + ctx->Driver.ClearDepth = NULL; //gld_ClearDepth; + ctx->Driver.ClearStencil = NULL; //gld_ClearStencil; + ctx->Driver.ColorMask = NULL; //gld_ColorMask; + ctx->Driver.CullFace = NULL; //gld_CullFace; + ctx->Driver.ClipPlane = NULL; //gld_ClipPlane; + ctx->Driver.FrontFace = NULL; //gld_FrontFace; + ctx->Driver.DepthFunc = NULL; //gld_DepthFunc; + ctx->Driver.DepthMask = NULL; //gld_DepthMask; + ctx->Driver.DepthRange = NULL; + ctx->Driver.Enable = NULL; //gld_Enable; + ctx->Driver.Fogfv = NULL; //gld_Fogfv; + ctx->Driver.Hint = NULL; //gld_Hint; + ctx->Driver.Lightfv = NULL; //gld_Lightfv; + ctx->Driver.LightModelfv = NULL; //gld_LightModelfv; + ctx->Driver.LineStipple = NULL; //gld_LineStipple; + ctx->Driver.LineWidth = NULL; //gld_LineWidth; + ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode; + ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv; + ctx->Driver.PointSize = NULL; //gld_PointSize; + ctx->Driver.PolygonMode = NULL; //gld_PolygonMode; + ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset; + ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple; + ctx->Driver.RenderMode = NULL; //gld_RenderMode; + ctx->Driver.Scissor = NULL; //gld_Scissor; + ctx->Driver.ShadeModel = NULL; //gld_ShadeModel; + ctx->Driver.StencilFunc = NULL; //gld_StencilFunc; + ctx->Driver.StencilMask = NULL; //gld_StencilMask; + ctx->Driver.StencilOp = NULL; //gld_StencilOp; + ctx->Driver.TexGen = NULL; //gld_TexGen; + ctx->Driver.TexEnv = NULL; + ctx->Driver.TexParameter = NULL; + ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix; + ctx->Driver.Viewport = gld_Viewport_DX7; + + _swsetup_Wakeup(ctx); + + tnl->Driver.RunPipeline = _tnl_run_pipeline; + tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX7; + tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; + tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; + + // Hook into glFrustum() and glOrtho() +// ctx->Exec->Frustum = gldFrustumHook_DX7; +// ctx->Exec->Ortho = gldOrthoHook_DX7; + +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_ext_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_ext_dx9.c @@ -0,0 +1,344 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GL extensions +* +****************************************************************************/ + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "../gld_settings.h" + +#include +#define GL_GLEXT_PROTOTYPES +#include +#include + +//#include "ddlog.h" +//#include "gld_dx8.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "dglcontext.h" +#include "extensions.h" + +// For some reason this is not defined in an above header... +extern void _mesa_enable_imaging_extensions(GLcontext *ctx); + +//--------------------------------------------------------------------------- +// Hack for the SGIS_multitexture extension that was removed from Mesa +// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel + + // NOTE: Quake2 ran *slower* with this enabled, so I've + // disabled it for now. + // To enable, uncomment: + // _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); + +//--------------------------------------------------------------------------- + +enum { + /* Quake2 GL_SGIS_multitexture */ + GL_SELECTED_TEXTURE_SGIS = 0x835B, + GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835C, + GL_MAX_TEXTURES_SGIS = 0x835D, + GL_TEXTURE0_SGIS = 0x835E, + GL_TEXTURE1_SGIS = 0x835F, + GL_TEXTURE2_SGIS = 0x8360, + GL_TEXTURE3_SGIS = 0x8361, + GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, +}; + +//--------------------------------------------------------------------------- + +void APIENTRY gldSelectTextureSGIS( + GLenum target) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glActiveTextureARB(ARB_target); +} + +//--------------------------------------------------------------------------- + +void APIENTRY gldMTexCoord2fSGIS( + GLenum target, + GLfloat s, + GLfloat t) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glMultiTexCoord2fARB(ARB_target, s, t); +} + +//--------------------------------------------------------------------------- + +void APIENTRY gldMTexCoord2fvSGIS( + GLenum target, + const GLfloat *v) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glMultiTexCoord2fvARB(ARB_target, v); +} + +//--------------------------------------------------------------------------- +// Extensions +//--------------------------------------------------------------------------- + +typedef struct { + PROC proc; + char *name; +} GLD_extension; + +GLD_extension GLD_extList[] = { +#ifdef GL_EXT_polygon_offset + { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, +#endif + { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, + { (PROC)glBlendColorEXT, "glBlendColorExt" }, + { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, + { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, + { (PROC)glColorPointerEXT, "glColorPointerEXT" }, + { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, + { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, + { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, + { (PROC)glGetPointervEXT, "glGetPointervEXT" }, + { (PROC)glArrayElementEXT, "glArrayElementEXT" }, + { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, + { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, + { (PROC)glBindTextureEXT, "glBindTextureEXT" }, + { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, + { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, + { (PROC)glIsTextureEXT, "glIsTextureEXT" }, + { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, + { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, + { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, + { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, + { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, + { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, + + { (PROC)glLockArraysEXT, "glLockArraysEXT" }, + { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, + { NULL, "\0" } +}; + +GLD_extension GLD_multitexList[] = { +/* + { (PROC)glMultiTexCoord1dSGIS, "glMTexCoord1dSGIS" }, + { (PROC)glMultiTexCoord1dvSGIS, "glMTexCoord1dvSGIS" }, + { (PROC)glMultiTexCoord1fSGIS, "glMTexCoord1fSGIS" }, + { (PROC)glMultiTexCoord1fvSGIS, "glMTexCoord1fvSGIS" }, + { (PROC)glMultiTexCoord1iSGIS, "glMTexCoord1iSGIS" }, + { (PROC)glMultiTexCoord1ivSGIS, "glMTexCoord1ivSGIS" }, + { (PROC)glMultiTexCoord1sSGIS, "glMTexCoord1sSGIS" }, + { (PROC)glMultiTexCoord1svSGIS, "glMTexCoord1svSGIS" }, + { (PROC)glMultiTexCoord2dSGIS, "glMTexCoord2dSGIS" }, + { (PROC)glMultiTexCoord2dvSGIS, "glMTexCoord2dvSGIS" }, + { (PROC)glMultiTexCoord2fSGIS, "glMTexCoord2fSGIS" }, + { (PROC)glMultiTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, + { (PROC)glMultiTexCoord2iSGIS, "glMTexCoord2iSGIS" }, + { (PROC)glMultiTexCoord2ivSGIS, "glMTexCoord2ivSGIS" }, + { (PROC)glMultiTexCoord2sSGIS, "glMTexCoord2sSGIS" }, + { (PROC)glMultiTexCoord2svSGIS, "glMTexCoord2svSGIS" }, + { (PROC)glMultiTexCoord3dSGIS, "glMTexCoord3dSGIS" }, + { (PROC)glMultiTexCoord3dvSGIS, "glMTexCoord3dvSGIS" }, + { (PROC)glMultiTexCoord3fSGIS, "glMTexCoord3fSGIS" }, + { (PROC)glMultiTexCoord3fvSGIS, "glMTexCoord3fvSGIS" }, + { (PROC)glMultiTexCoord3iSGIS, "glMTexCoord3iSGIS" }, + { (PROC)glMultiTexCoord3ivSGIS, "glMTexCoord3ivSGIS" }, + { (PROC)glMultiTexCoord3sSGIS, "glMTexCoord3sSGIS" }, + { (PROC)glMultiTexCoord3svSGIS, "glMTexCoord3svSGIS" }, + { (PROC)glMultiTexCoord4dSGIS, "glMTexCoord4dSGIS" }, + { (PROC)glMultiTexCoord4dvSGIS, "glMTexCoord4dvSGIS" }, + { (PROC)glMultiTexCoord4fSGIS, "glMTexCoord4fSGIS" }, + { (PROC)glMultiTexCoord4fvSGIS, "glMTexCoord4fvSGIS" }, + { (PROC)glMultiTexCoord4iSGIS, "glMTexCoord4iSGIS" }, + { (PROC)glMultiTexCoord4ivSGIS, "glMTexCoord4ivSGIS" }, + { (PROC)glMultiTexCoord4sSGIS, "glMTexCoord4sSGIS" }, + { (PROC)glMultiTexCoord4svSGIS, "glMTexCoord4svSGIS" }, + { (PROC)glMultiTexCoordPointerSGIS, "glMTexCoordPointerSGIS" }, + { (PROC)glSelectTextureSGIS, "glSelectTextureSGIS" }, + { (PROC)glSelectTextureCoordSetSGIS, "glSelectTextureCoordSetSGIS" }, +*/ + { (PROC)glActiveTextureARB, "glActiveTextureARB" }, + { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, + { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, + { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, + { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, + { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, + { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, + { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, + { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, + { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, + { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, + { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, + { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, + { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, + { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, + { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, + { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, + { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, + { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, + { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, + { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, + { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, + { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, + { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, + { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, + { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, + { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, + { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, + { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, + { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, + { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, + { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, + { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, + { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, + + // Descent3 doesn't use correct string, hence this hack + { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4f" }, + + // Quake2 SGIS multitexture + { (PROC)gldSelectTextureSGIS, "glSelectTextureSGIS" }, + { (PROC)gldMTexCoord2fSGIS, "glMTexCoord2fSGIS" }, + { (PROC)gldMTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, + + { NULL, "\0" } +}; + +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_DX( + LPCSTR a) +{ + int i; + PROC proc = NULL; + + for (i=0; GLD_extList[i].proc; i++) { + if (!strcmp(a, GLD_extList[i].name)) { + proc = GLD_extList[i].proc; + break; + } + } + + if (glb.bMultitexture) { + for (i=0; GLD_multitexList[i].proc; i++) { + if (!strcmp(a, GLD_multitexList[i].name)) { + proc = GLD_multitexList[i].proc; + break; + } + } + } + + gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); + + return proc; +} + +//--------------------------------------------------------------------------- + +void gldEnableExtensions_DX9( + GLcontext *ctx) +{ + GLuint i; + + // Mesa enables some extensions by default. + // This table decides which ones we want to switch off again. + + // NOTE: GL_EXT_compiled_vertex_array appears broken. + + const char *gld_disable_extensions[] = { +// "GL_ARB_transpose_matrix", +// "GL_EXT_compiled_vertex_array", +// "GL_EXT_polygon_offset", +// "GL_EXT_rescale_normal", + "GL_EXT_texture3D", +// "GL_NV_texgen_reflection", + NULL + }; + + const char *gld_multitex_extensions[] = { + "GL_ARB_multitexture", // Quake 3 + NULL + }; + + // Quake 2 engines + const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture"; + + const char *gld_enable_extensions[] = { + "GL_EXT_texture_env_add", // Quake 3 + "GL_ARB_texture_env_add", // Quake 3 + NULL + }; + + for (i=0; gld_disable_extensions[i]; i++) { + _mesa_disable_extension(ctx, gld_disable_extensions[i]); + } + + for (i=0; gld_enable_extensions[i]; i++) { + _mesa_enable_extension(ctx, gld_enable_extensions[i]); + } + + if (glb.bMultitexture) { + for (i=0; gld_multitex_extensions[i]; i++) { + _mesa_enable_extension(ctx, gld_multitex_extensions[i]); + } + + // GL_SGIS_multitexture + // NOTE: Quake2 ran *slower* with this enabled, so I've + // disabled it for now. + // Fair bit slower on GeForce256, + // Much slower on 3dfx Voodoo5 5500. +// _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); + + } + + _mesa_enable_imaging_extensions(ctx); + _mesa_enable_1_3_extensions(ctx); + _mesa_enable_1_4_extensions(ctx); +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_pipeline_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_pipeline_dx9.c @@ -0,0 +1,77 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Mesa transformation pipeline with GLDirect fastpath +* +****************************************************************************/ + +//#include "../GLDirect.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx9.h" + +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +//--------------------------------------------------------------------------- + +extern struct tnl_pipeline_stage _gld_d3d_render_stage; +extern struct tnl_pipeline_stage _gld_mesa_render_stage; + +static const struct tnl_pipeline_stage *gld_pipeline[] = { + &_gld_d3d_render_stage, // Direct3D TnL + &_tnl_vertex_transform_stage, + &_tnl_normal_transform_stage, + &_tnl_lighting_stage, + &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage. ??? */ + &_tnl_texgen_stage, + &_tnl_texture_transform_stage, + &_tnl_point_attenuation_stage, + &_gld_mesa_render_stage, // Mesa TnL, D3D rendering + 0, +}; + +//--------------------------------------------------------------------------- + +void gldInstallPipeline_DX9( + GLcontext *ctx) +{ + // Remove any existing pipeline stages, + // then install GLDirect pipeline stages. + + _tnl_destroy_pipeline(ctx); + _tnl_install_pipeline(ctx, gld_pipeline); +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_dxerr9.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_dxerr9.h @@ -0,0 +1,77 @@ +/*==========================================================================; + * + * + * File: dxerr9.h + * Content: DirectX Error Library Include File + * + ****************************************************************************/ + +#ifndef _GLD_DXERR9_H_ +#define _GLD_DXERR9_H_ + + +#include + +// +// DXGetErrorString9 +// +// Desc: Converts an DirectX HRESULT to a string +// +// Args: HRESULT hr Can be any error code from +// DPLAY D3D8 D3DX8 DMUSIC DSOUND +// +// Return: Converted string +// +const char* __stdcall DXGetErrorString9A(HRESULT hr); +const WCHAR* __stdcall DXGetErrorString9W(HRESULT hr); + +#ifdef UNICODE + #define DXGetErrorString9 DXGetErrorString9W +#else + #define DXGetErrorString9 DXGetErrorString9A +#endif + + +// +// DXTrace +// +// Desc: Outputs a formatted error message to the debug stream +// +// Args: CHAR* strFile The current file, typically passed in using the +// __FILE__ macro. +// DWORD dwLine The current line number, typically passed in using the +// __LINE__ macro. +// HRESULT hr An HRESULT that will be traced to the debug stream. +// CHAR* strMsg A string that will be traced to the debug stream (may be NULL) +// BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. +// +// Return: The hr that was passed in. +// +//HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox = FALSE ); +//HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox = FALSE ); +HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox); +HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox); + +#ifdef UNICODE + #define DXTrace DXTraceW +#else + #define DXTrace DXTraceA +#endif + + +// +// Helper macros +// +#if defined(DEBUG) | defined(_DEBUG) + #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) + #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) + #define DXTRACE_ERR_NOMSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) +#else + #define DXTRACE_MSG(str) (0L) + #define DXTRACE_ERR(str,hr) (hr) + #define DXTRACE_ERR_NOMSGBOX(str,hr) (hr) +#endif + + +#endif + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_texture_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_texture_dx9.c @@ -0,0 +1,2104 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Texture / Bitmap functions +* +****************************************************************************/ + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx9.h" + +#include + +#include "texformat.h" +#include "colormac.h" +#include "texstore.h" +#include "image.h" +// #include "mem.h" + +//--------------------------------------------------------------------------- + +#define GLD_FLIP_HEIGHT(y,h) (gldCtx->dwHeight - (y) - (h)) + +//--------------------------------------------------------------------------- +// 1D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + ((GLchan *)(t)->Data + (i) * (sz)) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + (i) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + (i)) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + (i)) + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// 2D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + ((GLchan *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + ((t)->Width * (j) + (i))) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + ((t)->Width * (j) + (i))) + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// 3D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i)) * (sz) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i)) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i))) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i))) + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// Direct3D texture formats that have no Mesa equivalent +//--------------------------------------------------------------------------- + +const struct gl_texture_format _gld_texformat_X8R8G8B8 = { + MESA_FORMAT_ARGB8888, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 8, /* RedBits */ + 8, /* GreenBits */ + 8, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 4, /* TexelBytes */ + _mesa_texstore_argb8888, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X8R8G8B8, /* FetchTexel1D */ + gld_fetch_2d_texel_X8R8G8B8, /* FetchTexel2D */ + gld_fetch_3d_texel_X8R8G8B8, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X8R8G8B8, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X8R8G8B8, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X8R8G8B8, /* FetchTexel3Df */ +}; + +const struct gl_texture_format _gld_texformat_X1R5G5B5 = { + MESA_FORMAT_ARGB1555, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 5, /* RedBits */ + 5, /* GreenBits */ + 5, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 2, /* TexelBytes */ + _mesa_texstore_argb1555, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X1R5G5B5, /* FetchTexel1D */ + gld_fetch_2d_texel_X1R5G5B5, /* FetchTexel2D */ + gld_fetch_3d_texel_X1R5G5B5, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X1R5G5B5, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X1R5G5B5, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X1R5G5B5, /* FetchTexel3Df */ +}; + +const struct gl_texture_format _gld_texformat_X4R4G4B4 = { + MESA_FORMAT_ARGB4444, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4, /* RedBits */ + 4, /* GreenBits */ + 4, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 2, /* TexelBytes */ + _mesa_texstore_argb4444, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X4R4G4B4, /* FetchTexel1D */ + gld_fetch_2d_texel_X4R4G4B4, /* FetchTexel2D */ + gld_fetch_3d_texel_X4R4G4B4, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X4R4G4B4, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X4R4G4B4, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X4R4G4B4, /* FetchTexel3Df */ +}; + +//--------------------------------------------------------------------------- +// Texture unit constants +//--------------------------------------------------------------------------- + +// List of possible combinations of texture environments. +// Example: GLD_TEXENV_MODULATE_RGBA means +// GL_MODULATE, GL_RGBA base internal format. +#define GLD_TEXENV_DECAL_RGB 0 +#define GLD_TEXENV_DECAL_RGBA 1 +#define GLD_TEXENV_DECAL_ALPHA 2 +#define GLD_TEXENV_REPLACE_RGB 3 +#define GLD_TEXENV_REPLACE_RGBA 4 +#define GLD_TEXENV_REPLACE_ALPHA 5 +#define GLD_TEXENV_MODULATE_RGB 6 +#define GLD_TEXENV_MODULATE_RGBA 7 +#define GLD_TEXENV_MODULATE_ALPHA 8 +#define GLD_TEXENV_BLEND_RGB 9 +#define GLD_TEXENV_BLEND_RGBA 10 +#define GLD_TEXENV_BLEND_ALPHA 11 +#define GLD_TEXENV_ADD_RGB 12 +#define GLD_TEXENV_ADD_RGBA 13 +#define GLD_TEXENV_ADD_ALPHA 14 + +// Per-stage (i.e. per-unit) texture environment +typedef struct { + DWORD ColorArg1; // Colour argument 1 + D3DTEXTUREOP ColorOp; // Colour operation + DWORD ColorArg2; // Colour argument 2 + DWORD AlphaArg1; // Alpha argument 1 + D3DTEXTUREOP AlphaOp; // Alpha operation + DWORD AlphaArg2; // Alpha argument 2 +} GLD_texenv; + +// TODO: Do we really need to set ARG1 and ARG2 every time? +// They seem to always be TEXTURE and CURRENT respectively. + +// C = Colour out +// A = Alpha out +// Ct = Colour from Texture +// Cf = Colour from fragment (diffuse) +// At = Alpha from Texture +// Af = Alpha from fragment (diffuse) +// Cc = GL_TEXTURE_ENV_COLOUR (GL_BLEND) +const GLD_texenv gldTexEnv[] = { + // DECAL_RGB: C=Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // DECAL_RGBA: C=Cf(1-At)+CtAt, A=Af + {D3DTA_TEXTURE, D3DTOP_BLENDTEXTUREALPHA, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // DECAL_ALPHA: use DECAL_RGB + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + + // REPLACE_RGB: C=Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // REPLACE_RGBA: C=Ct, A=At + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, + // REPLACE_ALPHA: C=Cf, A=At + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, + + // MODULATE_RGB: C=CfCt, A=Af + {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // MODULATE_RGBA: C=CfCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // MODULATE_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + + // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af + {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // BLEND_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + + // ADD_RGB: C=Cf+Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // ADD_RGBA: C=Cf+Ct, A=AfAt + {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // ADD_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, +}; + +//--------------------------------------------------------------------------- + +D3DTEXTUREADDRESS _gldConvertWrap( + GLenum wrap) +{ + return (wrap == GL_CLAMP) ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP; +} + +//--------------------------------------------------------------------------- + +D3DTEXTUREFILTERTYPE _gldConvertMagFilter( + GLenum magfilter) +{ + return (magfilter == GL_LINEAR) ? D3DTEXF_LINEAR : D3DTEXF_POINT; +} + +//--------------------------------------------------------------------------- + +void _gldConvertMinFilter( + GLenum minfilter, + D3DTEXTUREFILTERTYPE *min_filter, + D3DTEXTUREFILTERTYPE *mip_filter) +{ + switch (minfilter) { + case GL_NEAREST: + *min_filter = D3DTEXF_POINT; + *mip_filter = D3DTEXF_NONE; + break; + case GL_LINEAR: + *min_filter = D3DTEXF_LINEAR; + *mip_filter = D3DTEXF_NONE; + break; + case GL_NEAREST_MIPMAP_NEAREST: + *min_filter = D3DTEXF_POINT; + *mip_filter = D3DTEXF_POINT; + break; + case GL_LINEAR_MIPMAP_NEAREST: + *min_filter = D3DTEXF_LINEAR; + *mip_filter = D3DTEXF_POINT; + break; + case GL_NEAREST_MIPMAP_LINEAR: + *min_filter = D3DTEXF_POINT; + *mip_filter = D3DTEXF_LINEAR; + break; + case GL_LINEAR_MIPMAP_LINEAR: + *min_filter = D3DTEXF_LINEAR; + *mip_filter = D3DTEXF_LINEAR; + break; + } +} + +//--------------------------------------------------------------------------- + +D3DFORMAT _gldGLFormatToD3DFormat( + GLenum internalFormat) +{ + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + // LUNIMANCE != INTENSITY, but D3D doesn't have I8 textures + return D3DFMT_L8; + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + return D3DFMT_L8; + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + return D3DFMT_A8; + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return D3DFMT_X8R8G8B8; + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return D3DFMT_A8L8; + case GL_R3_G3_B2: + // TODO: Mesa does not support RGB332 internally + return D3DFMT_X4R4G4B4; //D3DFMT_R3G3B2; + case GL_RGB4: + return D3DFMT_X4R4G4B4; + case GL_RGB5: + return D3DFMT_X1R5G5B5; + case 3: + case GL_RGB: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return D3DFMT_R8G8B8; + case GL_RGBA4: + return D3DFMT_A4R4G4B4; + case 4: + case GL_RGBA: + case GL_RGBA2: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return D3DFMT_A8R8G8B8; + case GL_RGB5_A1: + return D3DFMT_A1R5G5B5; + } + + // Return an acceptable default + return D3DFMT_A8R8G8B8; +} + +//--------------------------------------------------------------------------- + +GLenum _gldDecodeBaseFormat( + IDirect3DTexture9 *pTex) +{ + // Examine Direct3D texture and return base OpenGL internal texture format + // NOTE: We can't use any base format info from Mesa because D3D might have + // used a different texture format when we used D3DXCreateTexture(). + + // Base internal format is one of (Red Book p355): + // GL_ALPHA, + // GL_LUMINANCE, + // GL_LUMINANCE_ALPHA, + // GL_INTENSITY, + // GL_RGB, + // GL_RGBA + + // NOTE: INTENSITY not used (not supported by Direct3D) + // LUMINANCE has same texture functions as RGB + // LUMINANCE_ALPHA has same texture functions as RGBA + + // TODO: cache format instead of using GetLevelDesc() + D3DSURFACE_DESC desc; + _GLD_DX9_TEX(GetLevelDesc(pTex, 0, &desc)); + + switch (desc.Format) { + case D3DFMT_R8G8B8: + case D3DFMT_X8R8G8B8: + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_R3G3B2: + case D3DFMT_X4R4G4B4: + case D3DFMT_P8: + case D3DFMT_L8: + return GL_RGB; + case D3DFMT_A8R8G8B8: + case D3DFMT_A1R5G5B5: + case D3DFMT_A4R4G4B4: + case D3DFMT_A8R3G3B2: + case D3DFMT_A8P8: + case D3DFMT_A8L8: + case D3DFMT_A4L4: + return GL_RGBA; + case D3DFMT_A8: + return GL_ALPHA; + // Compressed texture formats. Need to check these... + case D3DFMT_DXT1: + return GL_RGBA; + case D3DFMT_DXT2: + return GL_RGB; + case D3DFMT_DXT3: + return GL_RGBA; + case D3DFMT_DXT4: + return GL_RGB; + case D3DFMT_DXT5: + return GL_RGBA; + } + + // Fell through. Return arbitary default. + return GL_RGBA; +} + +//--------------------------------------------------------------------------- + +const struct gl_texture_format* _gldMesaFormatForD3DFormat( + D3DFORMAT d3dfmt) +{ + switch (d3dfmt) { + case D3DFMT_A8R8G8B8: + return &_mesa_texformat_argb8888; + case D3DFMT_R8G8B8: + return &_mesa_texformat_rgb888; + case D3DFMT_R5G6B5: + return &_mesa_texformat_rgb565; + case D3DFMT_A4R4G4B4: + return &_mesa_texformat_argb4444; + case D3DFMT_A1R5G5B5: + return &_mesa_texformat_argb1555; + case D3DFMT_A8L8: + return &_mesa_texformat_al88; + case D3DFMT_R3G3B2: + return &_mesa_texformat_rgb332; + case D3DFMT_A8: + return &_mesa_texformat_a8; + case D3DFMT_L8: + return &_mesa_texformat_l8; + case D3DFMT_X8R8G8B8: + return &_gld_texformat_X8R8G8B8; + case D3DFMT_X1R5G5B5: + return &_gld_texformat_X1R5G5B5; + case D3DFMT_X4R4G4B4: + return &_gld_texformat_X4R4G4B4; + } + + // If we reach here then we've made an error somewhere else + // by allowing a format that is not supported. + assert(0); + + return NULL; // Shut up compiler warning +} + +//--------------------------------------------------------------------------- +// Copy* functions +//--------------------------------------------------------------------------- + +void gldCopyTexImage1D_DX9( + GLcontext *ctx, + GLenum target, GLint level, + GLenum internalFormat, + GLint x, GLint y, + GLsizei width, GLint border ) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexImage2D_DX9( + GLcontext *ctx, + GLenum target, + GLint level, + GLenum internalFormat, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + GLint border) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage1D_DX9( + GLcontext *ctx, + GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, GLsizei width ) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage2D_DX9( + GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage3D_DX9( + GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height ) +{ + // TODO ? +} + +//--------------------------------------------------------------------------- +// Bitmap/Pixel functions +//--------------------------------------------------------------------------- + +#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) + +#define _GLD_FVF_IMAGE (D3DFVF_XYZRHW | D3DFVF_TEX1) + +typedef struct { + FLOAT x, y; // 2D raster coords + FLOAT z; // depth value + FLOAT rhw; // reciprocal homogenous W (always 1.0f) + FLOAT tu, tv; // texture coords +} _GLD_IMAGE_VERTEX; + +//--------------------------------------------------------------------------- + +HRESULT _gldDrawPixels( + GLcontext *ctx, + BOOL bChromakey, // Alpha test for glBitmap() images + GLint x, // GL x position + GLint y, // GL y position (needs flipping) + GLsizei width, // Width of input image + GLsizei height, // Height of input image + IDirect3DSurface9 *pImage) +{ + // + // Draw input image as texture implementing PixelZoom and clipping. + // Any fragment operations currently enabled will be used. + // + + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + IDirect3DTexture9 *pTexture; + D3DSURFACE_DESC d3dsd; + IDirect3DSurface9 *pSurface; + _GLD_IMAGE_VERTEX v[4]; + HRESULT hr; + + float ZoomWidth, ZoomHeight; + float ScaleWidth, ScaleHeight; + + // Create a texture to hold image + hr = D3DXCreateTexture( + gld->pDev, + width, height, + 1, // miplevels + 0, // usage + D3DFMT_A8R8G8B8, // format + D3DPOOL_MANAGED, // pool + &pTexture); + if (FAILED(hr)) + return hr; + + hr = IDirect3DTexture9_GetSurfaceLevel(pTexture, 0, &pSurface); + if (FAILED(hr)) { + IDirect3DTexture9_Release(pTexture); + return hr; + } + + // Copy image into texture + hr = D3DXLoadSurfaceFromSurface( + pSurface, NULL, NULL, // Dest surface + pImage, NULL, NULL, // Src surface + D3DX_FILTER_NONE, + 0); + IDirect3DSurface9_Release(pSurface); + if (FAILED(hr)) { + IDirect3DTexture9_Release(pTexture); + return hr; + } + + // + // Set up the quad like this (ascii-art ahead!) + // + // 3--2 + // | | + // 0--1 + // + // + + // Set depth + v[0].z = v[1].z = v[2].z = v[3].z = ctx->Current.RasterPos[2]; + // Set Reciprocal Homogenous W + v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.0f; + + // Set texcoords + // Examine texture size - if different to input width and height + // then we'll need to munge the texcoords to fit. + IDirect3DTexture9_GetLevelDesc(pTexture, 0, &d3dsd); + ScaleWidth = (float)width / (float)d3dsd.Width; + ScaleHeight = (float)height / (float)d3dsd.Height; + v[0].tu = 0.0f; v[0].tv = 0.0f; + v[1].tu = ScaleWidth; v[1].tv = 0.0f; + v[2].tu = ScaleWidth; v[2].tv = ScaleHeight; + v[3].tu = 0.0f; v[3].tv = ScaleHeight; + + // Set raster positions + ZoomWidth = (float)width * ctx->Pixel.ZoomX; + ZoomHeight = (float)height * ctx->Pixel.ZoomY; + + v[0].x = x; v[0].y = GLD_FLIP_Y(y); + v[1].x = x+ZoomWidth; v[1].y = GLD_FLIP_Y(y); + v[2].x = x+ZoomWidth; v[2].y = GLD_FLIP_Y(y+ZoomHeight); + v[3].x = x; v[3].y = GLD_FLIP_Y(y+ZoomHeight); + + // Draw image with full HW acceleration + // NOTE: Be nice to use a State Block for all this state... + IDirect3DDevice9_SetTexture(gld->pDev, 0, pTexture); + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE); + +// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_MINFILTER, D3DTEXF_POINT); +// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT); +// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT); +// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); +// IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + IDirect3DDevice9_SetSamplerState(gld->pDev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + + IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); + IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + IDirect3DDevice9_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + IDirect3DDevice9_SetTextureStageState(gld->pDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); + IDirect3DDevice9_SetTextureStageState(gld->pDev, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + + IDirect3DDevice9_SetVertexShader(gld->pDev, NULL); + IDirect3DDevice9_SetFVF(gld->pDev, _GLD_FVF_IMAGE); + + // + // Emulate Chromakey with an Alpha Test. + // [Alpha Test is more widely supported anyway] + // + if (bChromakey) { + // Switch on alpha testing + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, TRUE); + // Fragment passes is alpha is greater than reference value + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, D3DCMP_GREATER); + // Set alpha reference value between Bitmap alpha values of + // zero (transparent) and one (opaque). + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ALPHAREF, 0x7f); + } + + IDirect3DDevice9_DrawPrimitiveUP(gld->pDev, D3DPT_TRIANGLEFAN, 2, &v, sizeof(_GLD_IMAGE_VERTEX)); + + // Release texture + IDirect3DDevice9_SetTexture(gld->pDev, 0, NULL); + IDirect3DTexture9_Release(pTexture); + + // Reset state to before we messed it up + FLUSH_VERTICES(ctx, _NEW_ALL); + + return S_OK; +} + +//--------------------------------------------------------------------------- + +void gld_DrawPixels_DX9( + GLcontext *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels ) +{ + GLD_context *gldCtx; + GLD_driver_dx9 *gld; + + IDirect3DSurface9 *pImage; + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + + const struct gl_texture_format *MesaFormat; + + MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); + + // Mesa does not currently handle this format. + if (format == GL_BGR) + return; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX9_DRIVER(gldCtx); + + hr = IDirect3DDevice9_CreateOffscreenPlainSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + D3DPOOL_SCRATCH, + &pImage, + NULL); + if (FAILED(hr)) { + return; + } + + // + // Use Mesa to fill in image + // + + // Lock all of surface + hr = IDirect3DSurface9_LockRect(pImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pImage); + return; + } + + // unpack image, apply transfer ops and store directly in texture + MesaFormat->StoreImage( + ctx, + 2, + GL_RGBA, + &_mesa_texformat_argb8888, + d3dLockedRect.pBits, + width, height, 1, 0, 0, 0, + d3dLockedRect.Pitch, + 0, /* dstImageStride */ + format, type, pixels, unpack); + + IDirect3DSurface9_UnlockRect(pImage); + + _gldDrawPixels(ctx, FALSE, x, y, width, height, pImage); + + IDirect3DSurface9_Release(pImage); +} + +//--------------------------------------------------------------------------- + +void gld_ReadPixels_DX9( + GLcontext *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest) +{ + + GLD_context *gldCtx; + GLD_driver_dx9 *gld; + + IDirect3DSurface9 *pBackbuffer = NULL; + IDirect3DSurface9 *pNativeImage = NULL; + IDirect3DSurface9 *pCanonicalImage = NULL; + + D3DSURFACE_DESC d3dsd; + RECT rcSrc; // Source rect + POINT ptDst; // Dest point + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + struct gl_pixelstore_attrib srcPacking; + int i; + GLint DstRowStride; + const struct gl_texture_format *MesaFormat; + + switch (format) { + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + return; + } + + MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); + DstRowStride = _mesa_image_row_stride(pack, width, format, type); + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX9_DRIVER(gldCtx); + + // Get backbuffer + hr = IDirect3DDevice9_GetBackBuffer( + gld->pDev, + 0, // First swapchain + 0, // First backbuffer + D3DBACKBUFFER_TYPE_MONO, + &pBackbuffer); + if (FAILED(hr)) + return; + + // Get backbuffer description + hr = IDirect3DSurface9_GetDesc(pBackbuffer, &d3dsd); + if (FAILED(hr)) { + goto gld_ReadPixels_DX9_return; + } + + // Create a surface compatible with backbuffer + hr = IDirect3DDevice9_CreateOffscreenPlainSurface( + gld->pDev, + width, + height, + d3dsd.Format, + D3DPOOL_SCRATCH, + &pNativeImage, + NULL); + if (FAILED(hr)) { + goto gld_ReadPixels_DX9_return; + } + + // Compute source rect and dest point + SetRect(&rcSrc, 0, 0, width, height); + OffsetRect(&rcSrc, x, GLD_FLIP_HEIGHT(y, height)); + ptDst.x = ptDst.y = 0; + + // Get source pixels. + // + // This intermediate surface ensure that we can use CopyRects() + // instead of relying on D3DXLoadSurfaceFromSurface(), which may + // try and lock the backbuffer. This way seems safer. + // + // CopyRects has been removed for DX9. + // +/* hr = IDirect3DDevice9_CopyRects( + gld->pDev, + pBackbuffer, + &rcSrc, + 1, + pNativeImage, + &ptDst);*/ + hr = D3DXLoadSurfaceFromSurface( + pNativeImage, // Dest surface + NULL, // Dest palette + &rcSrc, // Dest rect + pBackbuffer, // Src surface + NULL, // Src palette + &rcSrc, // Src rect + D3DX_FILTER_NONE, // Filter + 0 // Colorkey (0=no colorkey) + ); + if (FAILED(hr)) { + goto gld_ReadPixels_DX9_return; + } + + // Create an RGBA8888 surface + hr = IDirect3DDevice9_CreateOffscreenPlainSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + D3DPOOL_SCRATCH, + &pCanonicalImage, + NULL); + if (FAILED(hr)) { + goto gld_ReadPixels_DX9_return; + } + + // Convert to RGBA8888 + hr = D3DXLoadSurfaceFromSurface( + pCanonicalImage, // Dest surface + NULL, NULL, // Dest palette, RECT + pNativeImage, // Src surface + NULL, NULL, // Src palette, RECT + D3DX_FILTER_NONE, // Filter + 0); // Colourkey + if (FAILED(hr)) { + goto gld_ReadPixels_DX9_return; + } + + srcPacking.Alignment = 1; + srcPacking.ImageHeight = height; + srcPacking.LsbFirst = GL_FALSE; + srcPacking.RowLength = 0; + srcPacking.SkipImages = 0; + srcPacking.SkipPixels = 0; + srcPacking.SkipRows = 0; + srcPacking.SwapBytes = GL_FALSE; + + // Lock all of image + hr = IDirect3DSurface9_LockRect(pCanonicalImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + goto gld_ReadPixels_DX9_return; + } + + // We need to flip the data. Yuck. + // Perhaps Mesa has a span packer we can use in future... + for (i=0; iStoreImage( + ctx, + 2, + GL_RGBA, // base format + MesaFormat, // dst format + pDestRow, // dest addr + width, 1, 1, 0, 0, 0, // src x,y,z & dst offsets x,y,z + DstRowStride, // dst row stride + 0, // dstImageStride + GL_BGRA, // src format + GL_UNSIGNED_BYTE, // src type + pSrcRow, // src addr + &srcPacking); // packing params of source image + } + + IDirect3DSurface9_UnlockRect(pCanonicalImage); + +gld_ReadPixels_DX9_return: + SAFE_RELEASE_SURFACE9(pCanonicalImage); + SAFE_RELEASE_SURFACE9(pNativeImage); + SAFE_RELEASE_SURFACE9(pBackbuffer); +} + +//--------------------------------------------------------------------------- + +void gld_CopyPixels_DX9( + GLcontext *ctx, + GLint srcx, + GLint srcy, + GLsizei width, + GLsizei height, + GLint dstx, + GLint dsty, + GLenum type) +{ + // + // NOTE: Not allowed to copy vidmem to vidmem! + // Therefore we use an intermediate image surface. + // + + GLD_context *gldCtx; + GLD_driver_dx9 *gld; + + IDirect3DSurface9 *pBackbuffer; + D3DSURFACE_DESC d3dsd; + IDirect3DSurface9 *pImage; + RECT rcSrc; // Source rect + POINT ptDst; // Dest point + HRESULT hr; + + // Only backbuffer + if (type != GL_COLOR) + return; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX9_DRIVER(gldCtx); + + // Get backbuffer + hr = IDirect3DDevice9_GetBackBuffer( + gld->pDev, + 0, // First swapchain + 0, // First backbuffer + D3DBACKBUFFER_TYPE_MONO, + &pBackbuffer); + if (FAILED(hr)) + return; + + // Get backbuffer description + hr = IDirect3DSurface9_GetDesc(pBackbuffer, &d3dsd); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pBackbuffer); + return; + } + + // Create a surface compatible with backbuffer + hr = IDirect3DDevice9_CreateOffscreenPlainSurface( + gld->pDev, + width, + height, + d3dsd.Format, + D3DPOOL_SCRATCH, + &pImage, + NULL); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pBackbuffer); + return; + } + + // Compute source rect and dest point + SetRect(&rcSrc, 0, 0, width, height); + OffsetRect(&rcSrc, srcx, GLD_FLIP_HEIGHT(srcy, height)); + ptDst.x = ptDst.y = 0; + + // Get source pixels +/* hr = IDirect3DDevice8_CopyRects( + gld->pDev, + pBackbuffer, + &rcSrc, + 1, + pImage, + &ptDst);*/ + hr = D3DXLoadSurfaceFromSurface( + pImage, // Dest surface + NULL, // Dest palette + &rcSrc, // Dest rect + pBackbuffer, // Src surface + NULL, // Src palette + &rcSrc, // Src rect + D3DX_FILTER_NONE, // Filter + 0 // Colorkey (0=no colorkey) + ); + IDirect3DSurface9_Release(pBackbuffer); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pImage); + return; + } + + _gldDrawPixels(ctx, FALSE, dstx, dsty, width, height, pImage); + + IDirect3DSurface9_Release(pImage); +} + +//--------------------------------------------------------------------------- + +void gld_Bitmap_DX9( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap) +{ + GLD_context *gldCtx; + GLD_driver_dx9 *gld; + + IDirect3DSurface9 *pImage; + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + BYTE *pTempBitmap; + D3DCOLOR clBitmapOne, clBitmapZero; + D3DCOLOR *pBits; + const GLubyte *src; + int i, j, k; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX9_DRIVER(gldCtx); + + // A NULL bitmap is valid, but merely advances the raster position + if ((bitmap == NULL) || (width == 0) || (height == 0)) + return; + + clBitmapZero = D3DCOLOR_RGBA(0,0,0,0); // NOTE: Alpha is Zero + clBitmapOne = D3DCOLOR_COLORVALUE( + ctx->Current.RasterColor[0], + ctx->Current.RasterColor[1], + ctx->Current.RasterColor[2], + 1.0f); // NOTE: Alpha is One + + hr = IDirect3DDevice9_CreateOffscreenPlainSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + D3DPOOL_SCRATCH, + &pImage, + NULL); + if (FAILED(hr)) { + return; + } + + // Lock all of surface + hr = IDirect3DSurface9_LockRect(pImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pImage); + return; + } + + pTempBitmap = _mesa_unpack_bitmap(width, height, bitmap, unpack); + if (pTempBitmap == NULL) { + IDirect3DSurface9_Release(pImage); + return; + } + + pBits = (D3DCOLOR*)d3dLockedRect.pBits; + + for (i=0; iDefaultPacking, pTempBitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, + 0, i, 0); + for (j=0; j<(width>>3); j++) { + byte = *src++; + for (k=0; k<8; k++) { + *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; + byte <<= 1; + } + } + // Fill remaining bits from bitmap + if (width & 7) { + byte = *src; + for (k=0; k<(width & 7); k++) { + *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; + byte <<= 1; + } + } + } + + FREE(pTempBitmap); + +/* + // unpack image, apply transfer ops and store directly in texture + texImage->TexFormat->StoreImage( + ctx, + 2, + GL_BITMAP, + &_mesa_texformat_argb8888, + d3dLockedRect.pBits, + width, height, 1, 0, 0, 0, + d3dLockedRect.Pitch, + 0, // dstImageStride + GL_BITMAP, GL_COLOR_INDEX, bitmap, unpack); +*/ + IDirect3DSurface9_UnlockRect(pImage); + + _gldDrawPixels(ctx, TRUE, x, y, width, height, pImage); + + IDirect3DSurface9_Release(pImage); +} + +//--------------------------------------------------------------------------- +// Texture functions +//--------------------------------------------------------------------------- + +void _gldAllocateTexture( + GLcontext *ctx, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + IDirect3DTexture9 *pTex; + D3DFORMAT d3dFormat; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture9*)tObj->DriverData; + if (pTex) { + // Decide whether we can keep existing D3D texture + // by examining top-level surface. + D3DSURFACE_DESC d3dsd; + _GLD_DX9_TEX(GetLevelDesc(pTex, 0, &d3dsd)); + // Release existing texture if not compatible + if ((d3dsd.Width == texImage->Width) || + (d3dsd.Height == texImage->Height)) + { + return; // Keep the existing texture + } + tObj->DriverData = NULL; + _GLD_DX9_TEX(Release(pTex)); + } + + d3dFormat = _gldGLFormatToD3DFormat(texImage->IntFormat); + D3DXCreateTexture( + gld->pDev, + texImage->Width, + texImage->Height, + // TODO: Re-evaluate mipmapping + (glb.bUseMipmaps) ? D3DX_DEFAULT : 1, + 0, // Usage + d3dFormat, + D3DPOOL_MANAGED, + &pTex); + tObj->DriverData = pTex; +} + +//--------------------------------------------------------------------------- + +const struct gl_texture_format* gld_ChooseTextureFormat_DX9( + GLcontext *ctx, + GLint internalFormat, + GLenum srcFormat, + GLenum srcType) +{ + // [Based on mesa_choose_tex_format()] + // + // We will choose only texture formats that are supported + // by Direct3D. If the hardware doesn't support a particular + // texture format, then the D3DX texture calls that we use + // will automatically use a HW supported format. + // + // The most critical aim is to reduce copying; if we can use + // texture-image data directly then it will be a big performance assist. + // + + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + return &_mesa_texformat_l8; // D3DFMT_L8 + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + return &_mesa_texformat_l8; // D3DFMT_L8 + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + return &_mesa_texformat_a8; // D3DFMT_A8 + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return &_mesa_texformat_rgb565; // D3DFMT_R5G6B5 + // Mesa will convert this for us later... + // return &_mesa_texformat_ci8; // D3DFMT_R5G6B5 + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return &_mesa_texformat_al88; // D3DFMT_A8L8 + case GL_R3_G3_B2: + return &_mesa_texformat_rgb332; // D3DFMT_R3G3B2 + case GL_RGB4: + case GL_RGBA4: + case GL_RGBA2: + return &_mesa_texformat_argb4444; // D3DFMT_A4R4G4B4 + case 3: + case GL_RGB: + case GL_RGB5: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return &_mesa_texformat_rgb565; + case 4: + case GL_RGBA: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return &_mesa_texformat_argb8888; + case GL_RGB5_A1: + return &_mesa_texformat_argb1555; + default: + _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat"); + return NULL; + } +} + +//--------------------------------------------------------------------------- + +/* +// Safer(?), slower version. +void gld_TexImage2D_DX9( + GLcontext *ctx, + GLenum target, + GLint level, + GLint internalFormat, + GLint width, + GLint height, + GLint border, + GLenum format, + GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + IDirect3DTexture9 *pTex; + IDirect3DSurface9 *pSurface; + RECT rcSrcRect; + HRESULT hr; + GLint texelBytes = 4; + GLvoid *tempImage; + + if (!tObj || !texImage) + return; + + if (level == 0) { + _gldAllocateTexture(ctx, tObj, texImage); + } + + pTex = (IDirect3DTexture9*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture9_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture9_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + tempImage = MALLOC(width * height * texelBytes); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); + IDirect3DSurface9_Release(pSurface); + return; + } + // unpack image, apply transfer ops and store in tempImage + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + &_mesa_texformat_argb8888, // dest format + tempImage, + width, height, 1, 0, 0, 0, + width * texelBytes, + 0, // dstImageStride + format, type, pixels, packing); + + SetRect(&rcSrcRect, 0, 0, width, height); + D3DXLoadSurfaceFromMemory( + pSurface, + NULL, + NULL, + tempImage, + D3DFMT_A8R8G8B8, + width * texelBytes, + NULL, + &rcSrcRect, + D3DX_FILTER_NONE, + 0); + + FREE(tempImage); + IDirect3DSurface9_Release(pSurface); +} +*/ + +//--------------------------------------------------------------------------- + +// Faster, more efficient version. +// Copies subimage straight to dest texture +void gld_TexImage2D_DX9( + GLcontext *ctx, + GLenum target, + GLint level, + GLint internalFormat, + GLint width, + GLint height, + GLint border, + GLenum format, + GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + IDirect3DTexture9 *pTex; + IDirect3DSurface9 *pSurface; + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + D3DSURFACE_DESC d3dsd; + + if (!tObj || !texImage) + return; + + // GLQUAKE FIX + // Test for input alpha data with non-alpha internalformat + if (((internalFormat==3) || (internalFormat==GL_RGB)) && (format==GL_RGBA)) { + // Input format has alpha, but a non-alpha format has been requested. + texImage->IntFormat = GL_RGBA; + internalFormat = GL_RGBA; + } + + if (level == 0) { + _gldAllocateTexture(ctx, tObj, texImage); + } + + pTex = (IDirect3DTexture9*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture9_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture9_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + IDirect3DSurface9_GetDesc(pSurface, &d3dsd); + + // Lock all of surface + hr = IDirect3DSurface9_LockRect(pSurface, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store directly in texture + texImage->TexFormat->StoreImage( + ctx, + 2, + texImage->Format, + _gldMesaFormatForD3DFormat(d3dsd.Format), + d3dLockedRect.pBits, + width, height, 1, 0, 0, 0, + d3dLockedRect.Pitch, + 0, // dstImageStride + format, type, pixels, packing); + + IDirect3DSurface9_UnlockRect(pSurface); + IDirect3DSurface9_Release(pSurface); +} + +//--------------------------------------------------------------------------- + +void gld_TexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint border, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + // A 1D texture is a 2D texture with a height of zero + gld_TexImage2D_DX9(ctx, target, level, internalFormat, width, 1, border, format, type, pixels, packing, texObj, texImage); +} + +//--------------------------------------------------------------------------- + +/* +void gld_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage ) +{ + GLD_GET_CONTEXT + IDirect3DTexture9 *pTex; + IDirect3DSurface9 *pSurface; + D3DFORMAT d3dFormat; + HRESULT hr; + GLint texelBytes = 4; + GLvoid *tempImage; + RECT rcSrcRect; + RECT rcDstRect; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture9*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= _GLD_DX9_TEX(GetLevelCount(pTex)) + return; // Level does not exist + hr = _GLD_DX9_TEX(GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + d3dFormat = _gldGLFormatToD3DFormat(texImage->Format); + tempImage = MALLOC(width * height * texelBytes); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); + IDirect3DSurface9_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store in tempImage + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + &_mesa_texformat_argb8888, // dest format + tempImage, + width, height, 1, 0, 0, 0, + width * texelBytes, + 0, // dstImageStride + format, type, pixels, packing); + + // Source rectangle is whole of input image + SetRect(&rcSrcRect, 0, 0, width, height); + + // Dest rectangle must be offset to dest image + SetRect(&rcDstRect, 0, 0, width, height); + OffsetRect(&rcDstRect, xoffset, yoffset); + + D3DXLoadSurfaceFromMemory( + pSurface, + NULL, + &rcDstRect, + tempImage, + D3DFMT_A8R8G8B8, + width * texelBytes, + NULL, + &rcSrcRect, + D3DX_FILTER_NONE, + 0); + + FREE(tempImage); + IDirect3DSurface9_Release(pSurface); +} +*/ + +//--------------------------------------------------------------------------- + +// Faster, more efficient version. +// Copies subimage straight to dest texture +void gld_TexSubImage2D_DX9( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + IDirect3DTexture9 *pTex; + IDirect3DSurface9 *pSurface; + HRESULT hr; + RECT rcDstRect; + D3DLOCKED_RECT d3dLockedRect; + D3DSURFACE_DESC d3dsd; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture9*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture9_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture9_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + IDirect3DSurface9_GetDesc(pSurface, &d3dsd); + + // Dest rectangle must be offset to dest image + SetRect(&rcDstRect, 0, 0, width, height); + OffsetRect(&rcDstRect, xoffset, yoffset); + + // Lock sub-rect of surface + hr = IDirect3DSurface9_LockRect(pSurface, &d3dLockedRect, &rcDstRect, 0); + if (FAILED(hr)) { + IDirect3DSurface9_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store directly in texture + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + _gldMesaFormatForD3DFormat(d3dsd.Format), + d3dLockedRect.pBits, + width, height, 1, + 0, 0, 0, // NOTE: d3dLockedRect.pBits is already offset!!! + d3dLockedRect.Pitch, + 0, // dstImageStride + format, type, pixels, packing); + + + IDirect3DSurface9_UnlockRect(pSurface); + IDirect3DSurface9_Release(pSurface); +} + +//--------------------------------------------------------------------------- + +void gld_TexSubImage1D_DX9( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLsizei width, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + gld_TexSubImage2D_DX9(ctx, target, level, xoffset, 0, width, 1, format, type, pixels, packing, texObj, texImage); +} + +//--------------------------------------------------------------------------- + +void gld_DeleteTexture_DX9( + GLcontext *ctx, + struct gl_texture_object *tObj) +{ + GLD_context *gld = (GLD_context*)(ctx->DriverCtx); + + if (tObj) { + IDirect3DTexture9 *pTex = (IDirect3DTexture9*)tObj->DriverData; + if (pTex) { +/* // Make sure texture is not bound to a stage before releasing it + for (int i=0; iCurrentTexture[i] == pTex) { + gld->pDev->SetTexture(i, NULL); + gld->CurrentTexture[i] = NULL; + } + }*/ + _GLD_DX9_TEX(Release(pTex)); + tObj->DriverData = NULL; + } + } +} + +//--------------------------------------------------------------------------- + +__inline void _gldSetColorOps( + const GLD_driver_dx9 *gld, + GLuint unit, + DWORD ColorArg1, + D3DTEXTUREOP ColorOp, + DWORD ColorArg2) +{ + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG1, ColorArg1)); + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLOROP, ColorOp)); + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG2, ColorArg2)); +} + +//--------------------------------------------------------------------------- + +__inline void _gldSetAlphaOps( + const GLD_driver_dx9 *gld, + GLuint unit, + DWORD AlphaArg1, + D3DTEXTUREOP AlphaOp, + DWORD AlphaArg2) +{ + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG1, AlphaArg1)); + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAOP, AlphaOp)); + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG2, AlphaArg2)); +} + +//--------------------------------------------------------------------------- + +void gldUpdateTextureUnit( + GLcontext *ctx, + GLuint unit, + BOOL bPassThrough) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DTEXTUREFILTERTYPE minfilter; + D3DTEXTUREFILTERTYPE mipfilter; + GLenum BaseFormat; + DWORD dwColorArg0; + int iTexEnv = 0; + GLD_texenv *pTexenv; + + // NOTE: If bPassThrough is FALSE then texture stage can be + // disabled otherwise it must pass-through it's current fragment. + + const struct gl_texture_unit *pUnit = &ctx->Texture.Unit[unit]; + const struct gl_texture_object *tObj = pUnit->_Current; + + IDirect3DTexture9 *pTex = NULL; + if (tObj) { + pTex = (IDirect3DTexture9*)tObj->DriverData; + } + + // Enable texturing if unit is enabled and a valid D3D texture exists + // Mesa 5: TEXTUREn_x altered to TEXTURE_nD_BIT + //if (pTex && (pUnit->Enabled & (TEXTURE0_1D | TEXTURE0_2D))) { + if (pTex && (pUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT))) { + // Enable texturing + _GLD_DX9_DEV(SetTexture(gld->pDev, unit, pTex)); + } else { + // Disable texturing, then return + _GLD_DX9_DEV(SetTexture(gld->pDev, unit, NULL)); + if (bPassThrough) { + _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); + _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); + } else { + _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); + _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); + } + return; + } + + // Texture parameters + _gldConvertMinFilter(tObj->MinFilter, &minfilter, &mipfilter); +// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MINFILTER, minfilter)); +// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MIPFILTER, mipfilter)); +// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); +// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSU, _gldConvertWrap(tObj->WrapS))); +// _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSV, _gldConvertWrap(tObj->WrapT))); + _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_MINFILTER, minfilter)); + _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_MIPFILTER, mipfilter)); + _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); + _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_ADDRESSU, _gldConvertWrap(tObj->WrapS))); + _GLD_DX9_DEV(SetSamplerState(gld->pDev, unit, D3DSAMP_ADDRESSV, _gldConvertWrap(tObj->WrapT))); + + // Texture priority + _GLD_DX9_TEX(SetPriority(pTex, (DWORD)(tObj->Priority*65535.0f))); + + // Texture environment + // TODO: Examine input texture for alpha and use specific alpha/non-alpha ops. + // See Page 355 of the Red Book. + BaseFormat = _gldDecodeBaseFormat(pTex); + + switch (BaseFormat) { + case GL_RGB: + iTexEnv = 0; + break; + case GL_RGBA: + iTexEnv = 1; + break; + case GL_ALPHA: + iTexEnv = 2; + break; + } + + switch (pUnit->EnvMode) { + case GL_DECAL: + iTexEnv += 0; + break; + case GL_REPLACE: + iTexEnv += 3; + break; + case GL_MODULATE: + iTexEnv += 6; + break; + case GL_BLEND: + // Set blend colour + dwColorArg0 = D3DCOLOR_COLORVALUE(pUnit->EnvColor[0], pUnit->EnvColor[1], pUnit->EnvColor[2], pUnit->EnvColor[3]); + _GLD_DX9_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG0, dwColorArg0)); + iTexEnv += 9; + break; + case GL_ADD: + iTexEnv += 12; + break; + } + pTexenv = (GLD_texenv*)&gldTexEnv[iTexEnv]; + _gldSetColorOps(gld, unit, pTexenv->ColorArg1, pTexenv->ColorOp, pTexenv->ColorArg2); + _gldSetAlphaOps(gld, unit, pTexenv->AlphaArg1, pTexenv->AlphaOp, pTexenv->AlphaArg2); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_TEXTURE_DX9( + GLcontext *ctx) +{ + // TODO: Support for three (ATI Radeon) or more (nVidia GeForce3) texture units + + BOOL bUnit0Enabled; + BOOL bUnit1Enabled; + + if (!ctx) + return; // Sanity check + + if (ctx->Const.MaxTextureUnits == 1) { + gldUpdateTextureUnit(ctx, 0, TRUE); + return; + } + + // + // NOTE: THE FOLLOWING RELATES TO TWO TEXTURE UNITS, AND TWO ONLY!! + // + + // Mesa 5: Texture Units altered + //bUnit0Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE0_1D | TEXTURE0_2D)) ? TRUE : FALSE; + //bUnit1Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE1_1D | TEXTURE1_2D)) ? TRUE : FALSE; + bUnit0Enabled = (ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; + bUnit1Enabled = (ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; + + // If Unit0 is disabled and Unit1 is enabled then we must pass-though + gldUpdateTextureUnit(ctx, 0, (!bUnit0Enabled && bUnit1Enabled) ? TRUE : FALSE); + // We can always disable the last texture unit + gldUpdateTextureUnit(ctx, 1, FALSE); + +#ifdef _DEBUG +#if 0 + { + // Find out whether device supports current renderstates + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); +// GLD_context *gld = GLD_GET_CONTEXT(ctx); + + DWORD dwPasses; + _GLD_DX9_DEV(ValidateDevice(gld->pDev, &dwPasses)); +// if (FAILED(hr)) { +// gldLogError(GLDLOG_ERROR, "ValidateDevice failed", hr); +// } + if (dwPasses != 1) { + gldLogMessage(GLDLOG_ERROR, "ValidateDevice: Can't do in one pass\n"); + } + } +#endif +#endif +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_dx9.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_dx9.h @@ -0,0 +1,327 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect Direct3D 9.0 header file +* +****************************************************************************/ + +#ifndef _GLD_DX9_H +#define _GLD_DX9_H + +//--------------------------------------------------------------------------- +// Windows includes +//--------------------------------------------------------------------------- + +//#ifndef STRICT +//#define STRICT +//#endif + +//#define WIN32_LEAN_AND_MEAN +//#include +#include +#include + +// MS screwed up with the DX8.1 SDK - there's no compile-time +// method of compiling for 8.0 via the 8.1 SDK unless you +// "make sure you don't use any 8.1 interfaces". +// We CAN use 8.1 D3DX static functions, though - just not new 8.1 interfaces. +// +// D3D_SDK_VERSION is 120 for 8.0 (supported by Windows 95). +// D3D_SDK_VERSION is 220 for 8.1 (NOT supported by Windows 95). +// +//#define D3D_SDK_VERSION_DX9_SUPPORT_WIN95 120 +//#define D3D_SDK_VERSION_DX91 220 + +// Typedef for obtaining function from d3d8.dll +typedef IDirect3D9* (WINAPI *FNDIRECT3DCREATE9) (UINT); + + +//--------------------------------------------------------------------------- +// Defines +//--------------------------------------------------------------------------- + +#ifdef _DEBUG +#define _GLD_TEST_HRESULT(h) \ +{ \ + HRESULT _hr = (h); \ + if (FAILED(_hr)) { \ + gldLogError(GLDLOG_ERROR, #h, _hr); \ + } \ +} +#define _GLD_DX9(func) _GLD_TEST_HRESULT(IDirect3D9_##func##) +#define _GLD_DX9_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice9_##func##) +#define _GLD_DX9_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer9_##func##) +#define _GLD_DX9_TEX(func) _GLD_TEST_HRESULT(IDirect3DTexture9_##func##) +#else +#define _GLD_DX9(func) IDirect3D9_##func +#define _GLD_DX9_DEV(func) IDirect3DDevice9_##func +#define _GLD_DX9_VB(func) IDirect3DVertexBuffer9_##func +#define _GLD_DX9_TEX(func) IDirect3DTexture9_##func +#endif + +#define SAFE_RELEASE(p) \ +{ \ + if (p) { \ + (p)->lpVtbl->Release(p); \ + (p) = NULL; \ + } \ +} + +#define SAFE_RELEASE_VB9(p) \ +{ \ + if (p) { \ + IDirect3DVertexBuffer9_Release((p)); \ + (p) = NULL; \ + } \ +} + +#define SAFE_RELEASE_SURFACE9(p) \ +{ \ + if (p) { \ + IDirect3DSurface9_Release((p)); \ + (p) = NULL; \ + } \ +} + +// Setup index. +enum { + GLD_SI_FLAT = 0, + GLD_SI_SMOOTH = 1, + GLD_SI_FLAT_EXTRAS = 2, + GLD_SI_SMOOTH_EXTRAS = 3, +}; +/* +// Internal pipeline +typedef enum { + GLD_PIPELINE_MESA = 0, // Mesa pipeline + GLD_PIPELINE_D3D_FVF = 1, // Direct3D Fixed-function pipeline + GLD_PIPELINE_D3D_VS_TWOSIDE = 2 // Direct3D two-sided-lighting vertex shader +} GLD_tnl_pipeline; +*/ +//--------------------------------------------------------------------------- +// Vertex definitions for Fixed-Function pipeline +//--------------------------------------------------------------------------- + +// +// NOTE: If the number of texture units is altered then most of +// the texture code will need to be revised. +// + +#define GLD_MAX_TEXTURE_UNITS_DX9 2 + +// +// 2D vertex transformed by Mesa +// +#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \ + D3DFVF_DIFFUSE | \ + D3DFVF_SPECULAR | \ + D3DFVF_TEX2) +typedef struct { + FLOAT x, y; // 2D raster coords + FLOAT sz; // Screen Z (depth) + FLOAT rhw; // Reciprocal homogenous W + DWORD diffuse; // Diffuse colour + DWORD specular; // For separate-specular support + FLOAT t0_u, t0_v; // 1st set of texture coords + FLOAT t1_u, t1_v; // 2nd set of texture coords +} GLD_2D_VERTEX; + + +// +// 3D vertex transformed by Direct3D +// +#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \ + D3DFVF_DIFFUSE | \ + D3DFVF_TEX2) + +typedef struct { + D3DXVECTOR3 Position; // XYZ Vector in object space + D3DCOLOR Diffuse; // Diffuse colour + D3DXVECTOR2 TexUnit0; // Texture unit 0 + D3DXVECTOR2 TexUnit1; // Texture unit 1 +} GLD_3D_VERTEX; + +//--------------------------------------------------------------------------- +// Vertex Shaders +//--------------------------------------------------------------------------- +/* +// DX8 Vertex Shader +typedef struct { + DWORD hShader; // If NULL, shader is invalid and cannot be used + BOOL bHardware; // If TRUE then shader was created for hardware, + // otherwise shader was created for software. +} GLD_vertexShader; +*/ +//--------------------------------------------------------------------------- +// Structs +//--------------------------------------------------------------------------- + +// This keeps a count of how many times we choose each individual internal +// pathway. Useful for seeing if a certain pathway was ever used by an app, and +// how much each pathway is biased. +// Zero the members at context creation and dump stats at context deletion. +typedef struct { + // Note: DWORD is probably too small + ULARGE_INTEGER qwMesa; // Mesa TnL pipeline + ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline +// ULARGE_INTEGER dwD3D2SVS; // Direct3D Two-Sided Vertex Shader pipeline +} GLD_pipeline_usage; + +// GLDirect Primitive Buffer (points, lines, triangles and quads) +typedef struct { + // Data for IDirect3DDevice9::CreateVertexBuffer() + DWORD dwStride; // Stride of vertex + DWORD dwUsage; // Usage flags + DWORD dwFVF; // Direct3D Flexible Vertex Format + DWORD dwPool; // Pool flags + + IDirect3DVertexBuffer9 *pVB; // Holds points, lines, tris and quads. + + // Point list is assumed to be at start of buffer + DWORD iFirstLine; // Index of start of line list + DWORD iFirstTriangle; // Index of start of triangle list + + BYTE *pPoints; // Pointer to next free point + BYTE *pLines; // Pointer to next free line + BYTE *pTriangles; // Pointer to next free triangle + + DWORD nPoints; // Number of points ready to render + DWORD nLines; // Number of lines ready to render + DWORD nTriangles; // Number of triangles ready to render +} GLD_pb_dx9; + +// GLDirect DX9 driver data +typedef struct { + // GLDirect vars + BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered) + BOOL bDepthStencil; // Depth buffer needed (stencil optional) + D3DFORMAT RenderFormat; // Format of back/front buffer + D3DFORMAT DepthFormat; // Format of depth/stencil +// float fFlipWindowY; // Value for flipping viewport Y coord + + // Direct3D vars + D3DCAPS9 d3dCaps9; + BOOL bHasHWTnL; // Device has Hardware Transform/Light? + IDirect3D9 *pD3D; // Base Direct3D9 interface + IDirect3DDevice9 *pDev; // Direct3D9 Device interface + GLD_pb_dx9 PB2d; // Vertices transformed by Mesa + GLD_pb_dx9 PB3d; // Vertices transformed by Direct3D + D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type + D3DXMATRIX matProjection; // Projection matrix for D3D TnL + D3DXMATRIX matModelView; // Model/View matrix for D3D TnL + int iSetupFunc; // Which setup functions to use + BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL + + // Direct3D vars for two-sided lighting +// GLD_vertexShader VStwosidelight; // Vertex Shader for two-sided lighting +// D3DXMATRIX matWorldViewProj;// World/View/Projection matrix for shaders + + +// GLD_tnl_pipeline TnLPipeline; // Index of current internal pipeline + GLD_pipeline_usage PipelineUsage; + + BOOL bCanScissor; // Scissor test - new for DX9 +} GLD_driver_dx9; + +#define GLD_GET_DX9_DRIVER(c) (GLD_driver_dx9*)(c)->glPriv + +//--------------------------------------------------------------------------- +// Function prototypes +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_DX9(LPCSTR a); +void gldEnableExtensions_DX9(GLcontext *ctx); +void gldInstallPipeline_DX9(GLcontext *ctx); +void gldSetupDriverPointers_DX9(GLcontext *ctx); +//void gldResizeBuffers_DX9(GLcontext *ctx); +void gldResizeBuffers_DX9(GLframebuffer *fb); + + +// Texture functions + +void gldCopyTexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); +void gldCopyTexImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +void gldCopyTexSubImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ); +void gldCopyTexSubImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); +void gldCopyTexSubImage3D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); + +void gld_NEW_TEXTURE_DX9(GLcontext *ctx); +void gld_DrawPixels_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels); +void gld_ReadPixels_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest); +void gld_CopyPixels_DX9(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type); +void gld_Bitmap_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap); +const struct gl_texture_format* gld_ChooseTextureFormat_DX9(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType); +void gld_TexImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage); +void gld_TexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); +void gld_TexSubImage2D_DX9( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); +void gld_TexSubImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage); +void gld_DeleteTexture_DX9(GLcontext *ctx, struct gl_texture_object *tObj); +void gld_ResetLineStipple_DX9(GLcontext *ctx); + +// 2D primitive functions + +void gld_Points2D_DX9(GLcontext *ctx, GLuint first, GLuint last); + +void gld_Line2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Line2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1); + +void gld_Triangle2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DFlatExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmoothExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); + +void gld_Quad2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DFlatExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmoothExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +// 3D primitive functions + +void gld_Points3D_DX9(GLcontext *ctx, GLuint first, GLuint last); +void gld_Line3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Line3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +// Primitive functions for Two-sided-lighting Vertex Shader + +void gld_Points2DTwoside_DX9(GLcontext *ctx, GLuint first, GLuint last); +void gld_Line2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Line2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +#endif --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_vb_d3d_render_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_vb_d3d_render_dx9.c @@ -0,0 +1,263 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect fastpath pipeline stage +* +****************************************************************************/ + +//--------------------------------------------------------------------------- + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx9.h" + +//--------------------------------------------------------------------------- + +#include "glheader.h" +#include "context.h" +#include "macros.h" +// #include "mem.h" +#include "mtypes.h" +//#include "mmath.h" + +#include "math/m_matrix.h" +#include "math/m_xform.h" + +#include "tnl/t_pipeline.h" + +//--------------------------------------------------------------------------- + +__inline void _gldSetVertexShaderConstants( + GLcontext *ctx, + GLD_driver_dx9 *gld) +{ + D3DXMATRIX mat, matView, matProj; + GLfloat *pM; + + // Mesa 5: Altered to a Stack + //pM = ctx->ModelView.m; + pM = ctx->ModelviewMatrixStack.Top->m; + matView._11 = pM[0]; + matView._12 = pM[1]; + matView._13 = pM[2]; + matView._14 = pM[3]; + matView._21 = pM[4]; + matView._22 = pM[5]; + matView._23 = pM[6]; + matView._24 = pM[7]; + matView._31 = pM[8]; + matView._32 = pM[9]; + matView._33 = pM[10]; + matView._34 = pM[11]; + matView._41 = pM[12]; + matView._42 = pM[13]; + matView._43 = pM[14]; + matView._44 = pM[15]; + + // Mesa 5: Altered to a Stack + //pM = ctx->ProjectionMatrix.m; + pM = ctx->ProjectionMatrixStack.Top->m; + matProj._11 = pM[0]; + matProj._12 = pM[1]; + matProj._13 = pM[2]; + matProj._14 = pM[3]; + matProj._21 = pM[4]; + matProj._22 = pM[5]; + matProj._23 = pM[6]; + matProj._24 = pM[7]; + matProj._31 = pM[8]; + matProj._32 = pM[9]; + matProj._33 = pM[10]; + matProj._34 = pM[11]; + matProj._41 = pM[12]; + matProj._42 = pM[13]; + matProj._43 = pM[14]; + matProj._44 = pM[15]; + + D3DXMatrixMultiply( &mat, &matView, &matProj ); + D3DXMatrixTranspose( &mat, &mat ); + + _GLD_DX9_DEV(SetVertexShaderConstantF(gld->pDev, 0, (float*)&mat, 4)); +} + +//--------------------------------------------------------------------------- + +static GLboolean gld_d3d_render_stage_run( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + TNLcontext *tnl; + struct vertex_buffer *VB; + tnl_render_func *tab; + GLint pass; + GLD_pb_dx9 *gldPB = &gld->PB3d; +/* + static int count = 0; + count++; + if (count != 2) + return GL_FALSE; +*/ + // The "check" function should disable this stage, + // but we'll test gld->bUseMesaTnL anyway. + if (gld->bUseMesaTnL) { + // Do nothing in this stage, but continue pipeline + return GL_TRUE; + } + + tnl = TNL_CONTEXT(ctx); + VB = &tnl->vb; + pass = 0; + + tnl->Driver.Render.Start( ctx ); + +#if 0 + // For debugging: Useful to see if an app passes colour data in + // an unusual format. + switch (VB->ColorPtr[0]->Type) { + case GL_FLOAT: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_FLOAT\n"); + break; + case GL_UNSIGNED_BYTE: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_UNSIGNED_BYTE\n"); + break; + default: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: *?*\n"); + break; + } +#endif + + tnl->Driver.Render.Points = gld_Points3D_DX9; + if (ctx->_TriangleCaps & DD_FLATSHADE) { + tnl->Driver.Render.Line = gld_Line3DFlat_DX9; + tnl->Driver.Render.Triangle = gld_Triangle3DFlat_DX9; + tnl->Driver.Render.Quad = gld_Quad3DFlat_DX9; + } else { + tnl->Driver.Render.Line = gld_Line3DSmooth_DX9; + tnl->Driver.Render.Triangle = gld_Triangle3DSmooth_DX9; + tnl->Driver.Render.Quad = gld_Quad3DSmooth_DX9; + } + + _GLD_DX9_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); + gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; + // Allocate primitive pointers + // gldPB->pPoints is always first + gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); + gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); + + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); + + tab = (VB->Elts ? tnl->Driver.Render.PrimTabElts : tnl->Driver.Render.PrimTabVerts); + + do { + GLuint i, length, flags = 0; + for (i = 0 ; !(flags & PRIM_END) ; i += length) + { + flags = VB->Primitive[i].mode; + length= VB->Primitive[i].count; + ASSERT(length || (flags & PRIM_END)); + ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + if (length) + tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + } + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + + _GLD_DX9_VB(Unlock(gldPB->pVB)); + + _GLD_DX9_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, 0, gldPB->dwStride)); + + _GLD_DX9_DEV(SetTransform(gld->pDev, D3DTS_PROJECTION, &gld->matProjection)); + _GLD_DX9_DEV(SetTransform(gld->pDev, D3DTS_WORLD, &gld->matModelView)); + + if (gldPB->nPoints) { + _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); + gldPB->nPoints = 0; + } + + if (gldPB->nLines) { + _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); + gldPB->nLines = 0; + } + + if (gldPB->nTriangles) { + _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); + gldPB->nTriangles = 0; + } + + return GL_FALSE; /* finished the pipe */ +} + +//--------------------------------------------------------------------------- + +static void gld_d3d_render_stage_check( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + // Is this thread safe? + stage->active = (gld->bUseMesaTnL) ? GL_FALSE : GL_TRUE; + return; +} + + +//--------------------------------------------------------------------------- + +const struct tnl_pipeline_stage _gld_d3d_render_stage = +{ + "gld_d3d_render_stage", + NULL, + NULL, + NULL, + NULL, + gld_d3d_render_stage_run /* run */ +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_primitive_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_primitive_dx9.c @@ -0,0 +1,1446 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Primitive (points/lines/tris/quads) rendering +* +****************************************************************************/ + +//#include "../GLDirect.h" + +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx9.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "swrast/s_context.h" +#include "swrast/s_depth.h" +#include "swrast/s_lines.h" +#include "swrast/s_triangle.h" +#include "swrast/s_trispan.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +// Disable compiler complaints about unreferenced local variables +#pragma warning (disable:4101) + +//--------------------------------------------------------------------------- +// Helper defines for primitives +//--------------------------------------------------------------------------- + +//static const float ooZ = 1.0f / 65536.0f; // One over Z + +#define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3])) +#define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3])) +#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) + +//--------------------------------------------------------------------------- +// 2D vertex setup +//--------------------------------------------------------------------------- + +#define GLD_SETUP_2D_VARS_POINTS \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour + +#define GLD_SETUP_2D_VARS_LINES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour + +#define GLD_SETUP_2D_VARS_TRIANGLES \ + BOOL bFog = ctx->Fog.Enabled; \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour; \ + GLuint facing = 0; \ + struct vertex_buffer *VB; \ + GLchan (*vbcolor)[4]; \ + GLchan (*vbspec)[4] + +#define GLD_SETUP_GET_SWVERT(s) \ + swv = &ss->verts[##s] + +#define GLD_SETUP_2D_VERTEX \ + pV->x = swv->win[0]; \ + pV->y = GLD_FLIP_Y(swv->win[1]); \ + pV->rhw = swv->win[3] + +#define GLD_SETUP_SMOOTH_COLOUR \ + pV->diffuse = GLD_COLOUR + +#define GLD_SETUP_GET_FLAT_COLOUR \ + dwFlatColour = GLD_COLOUR +#define GLD_SETUP_GET_FLAT_FOG_COLOUR \ + dwFlatColour = _gldComputeFog(ctx, swv) + +#define GLD_SETUP_USE_FLAT_COLOUR \ + pV->diffuse = dwFlatColour + +#define GLD_SETUP_GET_FLAT_SPECULAR \ + dwSpecularColour= GLD_SPECULAR + +#define GLD_SETUP_USE_FLAT_SPECULAR \ + pV->specular = dwSpecularColour + +#define GLD_SETUP_DEPTH \ + pV->sz = swv->win[2] / ctx->DepthMaxF +// pV->z = swv->win[2] * ooZ; + +#define GLD_SETUP_SPECULAR \ + pV->specular = GLD_SPECULAR + +#define GLD_SETUP_FOG \ + pV->diffuse = _gldComputeFog(ctx, swv) + +#define GLD_SETUP_TEX0 \ + pV->t0_u = swv->texcoord[0][0]; \ + pV->t0_v = swv->texcoord[0][1] + +#define GLD_SETUP_TEX1 \ + pV->t1_u = swv->texcoord[1][0]; \ + pV->t1_v = swv->texcoord[1][1] + +#define GLD_SETUP_LIGHTING(v) \ + if (facing == 1) { \ + pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ + if (vbspec) { \ + pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ + } \ + } else { \ + if (bFog) \ + GLD_SETUP_FOG; \ + else \ + GLD_SETUP_SMOOTH_COLOUR; \ + GLD_SETUP_SPECULAR; \ + } + +#define GLD_SETUP_GET_FLAT_LIGHTING(v) \ + if (facing == 1) { \ + dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ + if (vbspec) { \ + dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ + } \ + } + +#define GLD_SETUP_TWOSIDED_LIGHTING \ + /* Two-sided lighting */ \ + if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \ + SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \ + SWvertex *v[3]; \ + GLfloat ex,ey,fx,fy,cc; \ + /* Get vars for later */ \ + VB = &TNL_CONTEXT(ctx)->vb; \ + vbcolor = (GLchan (*)[4])VB->ColorPtr[1]->data; \ + if (VB->SecondaryColorPtr[1]) { \ + vbspec = (GLchan (*)[4])VB->SecondaryColorPtr[1]->data; \ + } else { \ + vbspec = NULL; \ + } \ + v[0] = &verts[v0]; \ + v[1] = &verts[v1]; \ + v[2] = &verts[v2]; \ + ex = v[0]->win[0] - v[2]->win[0]; \ + ey = v[0]->win[1] - v[2]->win[1]; \ + fx = v[1]->win[0] - v[2]->win[0]; \ + fy = v[1]->win[1] - v[2]->win[1]; \ + cc = ex*fy - ey*fx; \ + facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \ + } + +//--------------------------------------------------------------------------- +// 3D vertex setup +//--------------------------------------------------------------------------- + +#define GLD_SETUP_3D_VARS_POINTS \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VARS_LINES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VARS_TRIANGLES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VERTEX(v) \ + p4f = VB->ObjPtr->data; \ + pV->Position.x = p4f[##v][0]; \ + pV->Position.y = p4f[##v][1]; \ + pV->Position.z = p4f[##v][2]; + +#define GLD_SETUP_SMOOTH_COLOUR_3D(v) \ + p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ + pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); + + +#define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \ + p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ + dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); + +#define GLD_SETUP_USE_FLAT_COLOUR_3D \ + pV->Diffuse = dwColor; + +#define GLD_SETUP_TEX0_3D(v) \ + if (VB->TexCoordPtr[0]) { \ + tc = VB->TexCoordPtr[0]->data; \ + pV->TexUnit0.x = tc[##v][0]; \ + pV->TexUnit0.y = tc[##v][1]; \ + } + +#define GLD_SETUP_TEX1_3D(v) \ + if (VB->TexCoordPtr[1]) { \ + tc = VB->TexCoordPtr[1]->data; \ + pV->TexUnit1.x = tc[##v][0]; \ + pV->TexUnit1.y = tc[##v][1]; \ + } + +//--------------------------------------------------------------------------- +// Helper functions +//--------------------------------------------------------------------------- + +__inline DWORD _gldComputeFog( + GLcontext *ctx, + SWvertex *swv) +{ + // Full fog calculation. + // Based on Mesa code. + + GLchan rFog, gFog, bFog; + GLchan fR, fG, fB; + const GLfloat f = swv->fog; + const GLfloat g = 1.0 - f; + + UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); + fR = f * swv->color[0] + g * rFog; + fG = f * swv->color[1] + g * gFog; + fB = f * swv->color[2] + g * bFog; + return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]); +} + +//--------------------------------------------------------------------------- + +void gld_ResetLineStipple_DX9( + GLcontext *ctx) +{ + // TODO: Fake stipple with a 32x32 texture. +} + +//--------------------------------------------------------------------------- +// 2D (post-transformed) primitives +//--------------------------------------------------------------------------- + +void gld_Points2D_DX9( + GLcontext *ctx, + GLuint first, + GLuint last) +{ + GLD_SETUP_2D_VARS_POINTS; + + unsigned i; + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + // _Size is already clamped to MaxPointSize and MinPointSize + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); + + if (VB->Elts) { + for (i=first; iClipMask[VB->Elts[i]] == 0) { +// _swrast_Point( ctx, &verts[VB->Elts[i]] ); + GLD_SETUP_GET_SWVERT(VB->Elts[i]); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + } + } + } else { + GLD_SETUP_GET_SWVERT(first); + for (i=first; iClipMask[i] == 0) { +// _swrast_Point( ctx, &verts[i] ); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + } + } + } + + gld->PB2d.pPoints = (BYTE*)pV; + gld->PB2d.nPoints += (last-first); +} + +//--------------------------------------------------------------------------- + +void gld_Line2DFlat_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_2D_VARS_LINES; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pLines = (BYTE*)pV; + gld->PB2d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Line2DSmooth_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_2D_VARS_LINES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_SPECULAR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pLines = (BYTE*)pV; + gld->PB2d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlat_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + pV++;; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmooth_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlatExtras_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v2); + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + if (bFog) + GLD_SETUP_GET_FLAT_FOG_COLOUR; + else + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_GET_FLAT_LIGHTING(v2); + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmoothExtras_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v0); + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v1); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlat_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmooth_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlatExtras_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v3); + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + if (bFog) + GLD_SETUP_GET_FLAT_FOG_COLOUR; + else + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_GET_FLAT_LIGHTING(v3); + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmoothExtras_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v0); + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v1); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v3); + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- +// 3D (pre-transformed) primitives +//--------------------------------------------------------------------------- + +void gld_Points3D_DX9( + GLcontext *ctx, + GLuint first, + GLuint last) +{ + GLD_SETUP_3D_VARS_POINTS + + unsigned i; +// struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + // _Size is already clamped to MaxPointSize and MinPointSize + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); + + if (VB->Elts) { + for (i=first; iClipMask[VB->Elts[i]] == 0) { +// _swrast_Point( ctx, &verts[VB->Elts[i]] ); +// GLD_SETUP_GET_SWVERT(VB->Elts[i]); + GLD_SETUP_3D_VERTEX(VB->Elts[i]) + GLD_SETUP_SMOOTH_COLOUR_3D(i) + GLD_SETUP_TEX0_3D(i) + GLD_SETUP_TEX1_3D(i) + } + } + } else { +// GLD_SETUP_GET_SWVERT(first); + for (i=first; iClipMask[i] == 0) { +// _swrast_Point( ctx, &verts[i] ); + GLD_SETUP_3D_VERTEX(i) + GLD_SETUP_SMOOTH_COLOUR_3D(i) + GLD_SETUP_TEX0_3D(i) + GLD_SETUP_TEX1_3D(i) + } + } + } +/* + for (i=first; iPB3d.pPoints = (BYTE*)pV; + gld->PB3d.nPoints += (last-first); +} + +//--------------------------------------------------------------------------- +// Line functions +//--------------------------------------------------------------------------- + +void gld_Line3DFlat_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_3D_VARS_LINES + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_GET_FLAT_COLOUR_3D(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pLines = (BYTE*)pV; + gld->PB3d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Line3DSmooth_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_3D_VARS_LINES + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pLines = (BYTE*)pV; + gld->PB3d.nLines++; +} + +//--------------------------------------------------------------------------- +// Triangle functions +//--------------------------------------------------------------------------- + +void gld_Triangle3DFlat_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + GLD_SETUP_GET_FLAT_COLOUR_3D(v2) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle3DSmooth_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles++; +} + +//--------------------------------------------------------------------------- +// Quad functions +//--------------------------------------------------------------------------- + +void gld_Quad3DFlat_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_GET_FLAT_COLOUR_3D(v3) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad3DSmooth_DX9( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_SMOOTH_COLOUR_3D(v3) + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- +// Vertex setup for two-sided-lighting vertex shader +//--------------------------------------------------------------------------- + +/* + +void gld_Points2DTwoside_DX9(GLcontext *ctx, GLuint first, GLuint last) +{ + // NOTE: Two-sided lighting does not apply to Points +} + +//--------------------------------------------------------------------------- + +void gld_Line2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1) +{ + // NOTE: Two-sided lighting does not apply to Lines +} + +//--------------------------------------------------------------------------- + +void gld_Line2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1) +{ + // NOTE: Two-sided lighting does not apply to Lines +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) +{ +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 4th vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 5th vert + swv = &ss->verts[v3]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 6th vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 4th vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 5th vert + swv = &ss->verts[v3]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 6th vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +*/ --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_vb_mesa_render_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_vb_mesa_render_dx9.c @@ -0,0 +1,444 @@ +/* $Id: gld_vb_mesa_render_dx9.c,v 1.6 2005/08/27 13:56:08 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * Copyright (C) 1999-2001 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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. + * + * Authors: + * Keith Whitwell + */ + + +/* + * Render whole vertex buffers, including projection of vertices from + * clip space and clipping of primitives. + * + * This file makes calls to project vertices and to the point, line + * and triangle rasterizers via the function pointers: + * + * context->Driver.Render.* + * + */ + + +//--------------------------------------------------------------------------- + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx9.h" + +//--------------------------------------------------------------------------- + +#include "glheader.h" +#include "context.h" +#include "macros.h" +#include "mtypes.h" +//#include "mmath.h" + +#include "math/m_matrix.h" +#include "math/m_xform.h" + +#include "tnl/t_pipeline.h" + +/**********************************************************************/ +/* Clip single primitives */ +/**********************************************************************/ + + +#if defined(USE_IEEE) +#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) +//#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) +#else +#define NEGATIVE(x) (x < 0) +//#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) +/* Could just use (x*y<0) except for the flatshading requirements. + * Maybe there's a better way? + */ +#endif + + +#define W(i) coord[i][3] +#define Z(i) coord[i][2] +#define Y(i) coord[i][1] +#define X(i) coord[i][0] +#define SIZE 4 +#define TAG(x) x##_4 +#include "tnl/t_vb_cliptmp.h" + + + +/**********************************************************************/ +/* Clip and render whole begin/end objects */ +/**********************************************************************/ + +#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] +#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val + + +/* Vertices, with the possibility of clipping. + */ +#define RENDER_POINTS( start, count ) \ + tnl->Driver.Render.Points( ctx, start, count ) + +#define RENDER_LINE( v1, v2 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2]; \ + GLubyte ormask = c1|c2; \ + if (!ormask) \ + LineFunc( ctx, v1, v2 ); \ + else if (!(c1 & c2 & 0x3f)) \ + clip_line_4( ctx, v1, v2, ormask ); \ +} while (0) + +#define RENDER_TRI( v1, v2, v3 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ + GLubyte ormask = c1|c2|c3; \ + if (!ormask) \ + TriangleFunc( ctx, v1, v2, v3 ); \ + else if (!(c1 & c2 & c3 & 0x3f)) \ + clip_tri_4( ctx, v1, v2, v3, ormask ); \ +} while (0) + +#define RENDER_QUAD( v1, v2, v3, v4 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2]; \ + GLubyte c3 = mask[v3], c4 = mask[v4]; \ + GLubyte ormask = c1|c2|c3|c4; \ + if (!ormask) \ + QuadFunc( ctx, v1, v2, v3, v4 ); \ + else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ + clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ +} while (0) + + +#define LOCAL_VARS \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + const GLuint * const elt = VB->Elts; \ + const GLubyte *mask = VB->ClipMask; \ + const GLuint sz = VB->ClipPtr->size; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + const GLboolean stipple = ctx->Line.StippleFlag; \ + (void) (LineFunc && TriangleFunc && QuadFunc); \ + (void) elt; (void) mask; (void) sz; (void) stipple; + +#define TAG(x) clip_##x##_verts +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) +#define PRESERVE_VB_DEFS +#include "tnl/t_vb_rendertmp.h" + + + +/* Elts, with the possibility of clipping. + */ +#undef ELT +#undef TAG +#define ELT(x) elt[x] +#define TAG(x) clip_##x##_elts +#include "tnl/t_vb_rendertmp.h" + +/* TODO: do this for all primitives, verts and elts: + */ +static void clip_elt_triangles( GLcontext *ctx, + GLuint start, + GLuint count, + GLuint flags ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; + struct vertex_buffer *VB = &tnl->vb; + const GLuint * const elt = VB->Elts; + GLubyte *mask = VB->ClipMask; + GLuint last = count-2; + GLuint j; + (void) flags; + + tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); + + for (j=start; j < last; j+=3 ) { + GLubyte c1 = mask[elt[j]]; + GLubyte c2 = mask[elt[j+1]]; + GLubyte c3 = mask[elt[j+2]]; + GLubyte ormask = c1|c2|c3; + if (ormask) { + if (start < j) + render_tris( ctx, start, j, 0 ); + if (!(c1&c2&c3&0x3f)) + clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); + start = j+3; + } + } + + if (start < j) + render_tris( ctx, start, j, 0 ); +} + +/**********************************************************************/ +/* Render whole begin/end objects */ +/**********************************************************************/ + +#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] +#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val + + +/* Vertices, no clipping. + */ +#define RENDER_POINTS( start, count ) \ + tnl->Driver.Render.Points( ctx, start, count ) + +#define RENDER_LINE( v1, v2 ) \ + LineFunc( ctx, v1, v2 ) + +#define RENDER_TRI( v1, v2, v3 ) \ + TriangleFunc( ctx, v1, v2, v3 ) + +#define RENDER_QUAD( v1, v2, v3, v4 ) \ + QuadFunc( ctx, v1, v2, v3, v4 ) + +#define TAG(x) _gld_tnl_##x##_verts + +#define LOCAL_VARS \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + const GLuint * const elt = VB->Elts; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + (void) (LineFunc && TriangleFunc && QuadFunc); \ + (void) elt; + +#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx ) +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RENDER_TAB_QUALIFIER +#define PRESERVE_VB_DEFS +#include "tnl/t_vb_rendertmp.h" + + +/* Elts, no clipping. + */ +#undef ELT +#define TAG(x) _gld_tnl_##x##_elts +#define ELT(x) elt[x] +#include "tnl/t_vb_rendertmp.h" + + +/**********************************************************************/ +/* Helper functions for drivers */ +/**********************************************************************/ +/* +void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + GLuint *tmp = VB->Elts; + + VB->Elts = (GLuint *)elts; + tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); + VB->Elts = tmp; +} + +void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl->Driver.Render.Line( ctx, ii, jj ); +} +*/ + + +/**********************************************************************/ +/* Clip and render whole vertex buffers */ +/**********************************************************************/ + +tnl_points_func _gldSetupPoints[4] = { + gld_Points2D_DX9, + gld_Points2D_DX9, + gld_Points2D_DX9, + gld_Points2D_DX9 +}; +tnl_line_func _gldSetupLine[4] = { + gld_Line2DFlat_DX9, + gld_Line2DSmooth_DX9, + gld_Line2DFlat_DX9, + gld_Line2DSmooth_DX9, +}; +tnl_triangle_func _gldSetupTriangle[4] = { + gld_Triangle2DFlat_DX9, + gld_Triangle2DSmooth_DX9, + gld_Triangle2DFlatExtras_DX9, + gld_Triangle2DSmoothExtras_DX9 +}; +tnl_quad_func _gldSetupQuad[4] = { + gld_Quad2DFlat_DX9, + gld_Quad2DSmooth_DX9, + gld_Quad2DFlatExtras_DX9, + gld_Quad2DSmoothExtras_DX9 +}; + +//--------------------------------------------------------------------------- + +static GLboolean _gld_mesa_render_stage_run( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + tnl_render_func *tab; + GLint pass = 0; + GLD_pb_dx9 *gldPB; + + /* Allow the drivers to lock before projected verts are built so + * that window coordinates are guarenteed not to change before + * rendering. + */ + ASSERT(tnl->Driver.Render.Start); + + tnl->Driver.Render.Start( ctx ); + + // NOTE: Setting D3DRS_SOFTWAREVERTEXPROCESSING for a mixed-mode device resets + // stream, indices and shader to default values of NULL or 0. +/* if ((ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) && + gld->VStwosidelight.hShader && + !ctx->Fog.Enabled) + { + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware); + _GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); + gldPB = &gld->PBtwosidelight; + tnl->Driver.Render.Points = gld_Points2DTwoside_DX9; + if (ctx->_TriangleCaps & DD_FLATSHADE) { + tnl->Driver.Render.Line = gld_Line2DFlatTwoside_DX9; + tnl->Driver.Render.Triangle = gld_Triangle2DFlatTwoside_DX9; + tnl->Driver.Render.Quad = gld_Quad2DFlatTwoside_DX9; + } else { + tnl->Driver.Render.Line = gld_Line2DSmoothTwoside_DX9; + tnl->Driver.Render.Triangle = gld_Triangle2DSmoothTwoside_DX9; + tnl->Driver.Render.Quad = gld_Quad2DSmoothTwoside_DX9; + } + } else {*/ +// IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE); + IDirect3DDevice9_SetSoftwareVertexProcessing(gld->pDev, TRUE); + gldPB = &gld->PB2d; + _GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL)); + _GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF)); + tnl->Driver.Render.Points = _gldSetupPoints[gld->iSetupFunc]; + tnl->Driver.Render.Line = _gldSetupLine[gld->iSetupFunc]; + tnl->Driver.Render.Triangle = _gldSetupTriangle[gld->iSetupFunc]; + tnl->Driver.Render.Quad = _gldSetupQuad[gld->iSetupFunc]; +// } + + _GLD_DX9_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); + gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; + // Allocate primitive pointers + // gldPB->pPoints is always first + gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); + gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); + + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); + + tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); + + if (VB->ClipOrMask) { + tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; + clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; + } + else { + tab = (VB->Elts ? + tnl->Driver.Render.PrimTabElts : + tnl->Driver.Render.PrimTabVerts); + } + + do { + GLuint i, length, flags = 0; + for (i = 0 ; !(flags & PRIM_END) ; i += length) { + flags = VB->Primitive[i].mode; + length= VB->Primitive[i].count; + ASSERT(length || (flags & PRIM_END)); + ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + if (length) + tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + } + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + + +// tnl->Driver.Render.Finish( ctx ); + + _GLD_DX9_VB(Unlock(gldPB->pVB)); + + _GLD_DX9_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, 0, gldPB->dwStride)); + + if (gldPB->nPoints) { + _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); + gldPB->nPoints = 0; + } + + if (gldPB->nLines) { + _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); + gldPB->nLines = 0; + } + + if (gldPB->nTriangles) { + _GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); + gldPB->nTriangles = 0; + } + + return GL_FALSE; /* finished the pipe */ +} + + +/**********************************************************************/ +/* Render pipeline stage */ +/**********************************************************************/ + + + + +const struct tnl_pipeline_stage _gld_mesa_render_stage = +{ + "gld_mesa_render_stage", + NULL, + NULL, + NULL, + NULL, + _gld_mesa_render_stage_run /* run */ +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_driver_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_driver_dx9.c @@ -0,0 +1,1206 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Driver interface code to Mesa +* +****************************************************************************/ + +//#include +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx9.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "teximage.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +extern BOOL dglSwapBuffers(HDC hDC); + +// HACK: Hack the _33 member of the OpenGL perspective projection matrix +const float _fPersp_33 = 1.6f; + +//--------------------------------------------------------------------------- +// Internal functions +//--------------------------------------------------------------------------- + +void _gld_mesa_warning( + __GLcontext *gc, + char *str) +{ + // Intercept Mesa's internal warning mechanism + gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str); +} + +//--------------------------------------------------------------------------- + +void _gld_mesa_fatal( + __GLcontext *gc, + char *str) +{ + // Intercept Mesa's internal fatal-message mechanism + gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str); + + // Mesa calls abort(0) here. + ddlogClose(); + exit(0); +} + +//--------------------------------------------------------------------------- + +D3DSTENCILOP _gldConvertStencilOp( + GLenum StencilOp) +{ + // Used by Stencil: pass, fail and zfail + + switch (StencilOp) { + case GL_KEEP: + return D3DSTENCILOP_KEEP; + case GL_ZERO: + return D3DSTENCILOP_ZERO; + case GL_REPLACE: + return D3DSTENCILOP_REPLACE; + case GL_INCR: + return D3DSTENCILOP_INCRSAT; + case GL_DECR: + return D3DSTENCILOP_DECRSAT; + case GL_INVERT: + return D3DSTENCILOP_INVERT; + case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap + return D3DSTENCILOP_INCR; + case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap + return D3DSTENCILOP_DECR; + } + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n"); +#endif + + return D3DSTENCILOP_KEEP; +} + +//--------------------------------------------------------------------------- + +D3DCMPFUNC _gldConvertCompareFunc( + GLenum CmpFunc) +{ + // Used for Alpha func, depth func and stencil func. + + switch (CmpFunc) { + case GL_NEVER: + return D3DCMP_NEVER; + case GL_LESS: + return D3DCMP_LESS; + case GL_EQUAL: + return D3DCMP_EQUAL; + case GL_LEQUAL: + return D3DCMP_LESSEQUAL; + case GL_GREATER: + return D3DCMP_GREATER; + case GL_NOTEQUAL: + return D3DCMP_NOTEQUAL; + case GL_GEQUAL: + return D3DCMP_GREATEREQUAL; + case GL_ALWAYS: + return D3DCMP_ALWAYS; + }; + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n"); +#endif + + return D3DCMP_ALWAYS; +} + +//--------------------------------------------------------------------------- + +D3DBLEND _gldConvertBlendFunc( + GLenum blend, + GLenum DefaultBlend) +{ + switch (blend) { + case GL_ZERO: + return D3DBLEND_ZERO; + case GL_ONE: + return D3DBLEND_ONE; + case GL_DST_COLOR: + return D3DBLEND_DESTCOLOR; + case GL_SRC_COLOR: + return D3DBLEND_SRCCOLOR; + case GL_ONE_MINUS_DST_COLOR: + return D3DBLEND_INVDESTCOLOR; + case GL_ONE_MINUS_SRC_COLOR: + return D3DBLEND_INVSRCCOLOR; + case GL_SRC_ALPHA: + return D3DBLEND_SRCALPHA; + case GL_ONE_MINUS_SRC_ALPHA: + return D3DBLEND_INVSRCALPHA; + case GL_DST_ALPHA: + return D3DBLEND_DESTALPHA; + case GL_ONE_MINUS_DST_ALPHA: + return D3DBLEND_INVDESTALPHA; + case GL_SRC_ALPHA_SATURATE: + return D3DBLEND_SRCALPHASAT; + } + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n"); +#endif + + return DefaultBlend; +} + +//--------------------------------------------------------------------------- +// Misc. functions +//--------------------------------------------------------------------------- + +void gld_Noop_DX9( + GLcontext *ctx) +{ +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n"); +#endif +} + +//--------------------------------------------------------------------------- + +void gld_Error_DX9( + GLcontext *ctx) +{ +#ifdef _DEBUG + // Quite useless. +// gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n"); +#endif +} + +//--------------------------------------------------------------------------- +// Required Mesa functions +//--------------------------------------------------------------------------- + +static GLboolean gld_set_draw_buffer_DX9( + GLcontext *ctx, + GLenum mode) +{ + (void) ctx; + if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) { + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + +//--------------------------------------------------------------------------- + +static void gld_set_read_buffer_DX9( + GLcontext *ctx, + GLframebuffer *buffer, + GLenum mode) +{ + /* separate read buffer not supported */ +/* + ASSERT(buffer == ctx->DrawBuffer); + ASSERT(mode == GL_FRONT_LEFT); +*/ +} + +//--------------------------------------------------------------------------- + +void gld_Clear_DX9( + GLcontext *ctx, + GLbitfield mask, + GLboolean all, + GLint x, + GLint y, + GLint width, + GLint height) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + DWORD dwFlags = 0; + D3DCOLOR Color = 0; + float Z = 0.0f; + DWORD Stencil = 0; + D3DRECT d3dClearRect; + + // TODO: Colourmask + const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; + + if (!gld->pDev) + return; + + if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { + GLubyte col[4]; + CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]); + CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]); + CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]); + CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]); + dwFlags |= D3DCLEAR_TARGET; + Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]); + } + + if (mask & DD_DEPTH_BIT) { + // D3D8 will fail the Clear call if we try and clear a + // depth buffer and we haven't created one. + // Also, some apps try and clear a depth buffer, + // when a depth buffer hasn't been requested by the app. + if (ctx->Visual.depthBits == 0) { + mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask + } else { + dwFlags |= D3DCLEAR_ZBUFFER; + Z = ctx->Depth.Clear; + } + } + + if (mask & DD_STENCIL_BIT) { + if (ctx->Visual.stencilBits == 0) { + // No stencil bits in depth buffer + mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask + } else { + dwFlags |= D3DCLEAR_STENCIL; + Stencil = ctx->Stencil.Clear; + } + } + + // Some apps do really weird things with the rect, such as Quake3. + if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) { + all = GL_TRUE; + } + + if (!all) { + // Calculate clear subrect + d3dClearRect.x1 = x; + d3dClearRect.y1 = gldCtx->dwHeight - (y + height); + d3dClearRect.x2 = x + width; + d3dClearRect.y2 = d3dClearRect.y1 + height; +// gldLogPrintf(GLDLOG_INFO, "Rect %d,%d %d,%d", x,y,width,height); + } + + // dwFlags will be zero if there's nothing to clear + if (dwFlags) { + _GLD_DX9_DEV(Clear( + gld->pDev, + all ? 0 : 1, + all ? NULL : &d3dClearRect, + dwFlags, + Color, Z, Stencil)); + } + + if (mask & DD_ACCUM_BIT) { + // Clear accumulation buffer + } +} + +//--------------------------------------------------------------------------- + +// Mesa 5: Parameter change +static void gld_buffer_size_DX9( +// GLcontext *ctx, + GLframebuffer *fb, + GLuint *width, + GLuint *height) +{ +// GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + + *width = fb->Width; // gldCtx->dwWidth; + *height = fb->Height; // gldCtx->dwHeight; +} + +//--------------------------------------------------------------------------- + +static void gld_Finish_DX9( + GLcontext *ctx) +{ +} + +//--------------------------------------------------------------------------- + +static void gld_Flush_DX9( + GLcontext *ctx) +{ + GLD_context *gld = GLD_GET_CONTEXT(ctx); + + // TODO: Detect apps that glFlush() then SwapBuffers() ? + + if (gld->EmulateSingle) { + // Emulating a single-buffered context. + // [Direct3D doesn't allow rendering to front buffer] + dglSwapBuffers(gld->hDC); + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_STENCIL( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + // Two-sided stencil. New for Mesa 5 + const GLuint uiFace = 0UL; + + struct gl_stencil_attrib *pStencil = &ctx->Stencil; + + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE)); + if (pStencil->Enabled) { + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace]))); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILREF, pStencil->Ref[uiFace])); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILMASK, pStencil->ValueMask[uiFace])); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILWRITEMASK, pStencil->WriteMask[uiFace])); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace]))); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace]))); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace]))); + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_COLOR( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + DWORD dwFlags = 0; + D3DBLEND src; + D3DBLEND dest; + + // Alpha func + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc))); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAREF, (DWORD)ctx->Color.AlphaRef)); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, ctx->Color.AlphaEnabled)); + + // Blend func + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ALPHABLENDENABLE, ctx->Color.BlendEnabled)); + src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE); + dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SRCBLEND, src)); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_DESTBLEND, dest)); + + // Color mask + if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED; + if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN; + if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE; + if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA; + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_COLORWRITEENABLE, dwFlags)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_DEPTH( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE)); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func))); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_POLYGON( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DFILLMODE d3dFillMode = D3DFILL_SOLID; + D3DCULL d3dCullMode = D3DCULL_NONE; + float fOffset = 0; // Changed from int to float for DX9 + + // Fillmode + switch (ctx->Polygon.FrontMode) { + case GL_POINT: + d3dFillMode = D3DFILL_POINT; + break; + case GL_LINE: + d3dFillMode = D3DFILL_WIREFRAME; + break; + case GL_FILL: + d3dFillMode = D3DFILL_SOLID; + break; + } + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FILLMODE, d3dFillMode)); + + if (ctx->Polygon.CullFlag) { + switch (ctx->Polygon.CullFaceMode) { + case GL_BACK: + if (ctx->Polygon.FrontFace == GL_CCW) + d3dCullMode = D3DCULL_CW; + else + d3dCullMode = D3DCULL_CCW; + break; + case GL_FRONT: + if (ctx->Polygon.FrontFace == GL_CCW) + d3dCullMode = D3DCULL_CCW; + else + d3dCullMode = D3DCULL_CW; + break; + case GL_FRONT_AND_BACK: + d3dCullMode = D3DCULL_NONE; + break; + default: + break; + } + } else { + d3dCullMode = D3DCULL_NONE; + } +// d3dCullMode = D3DCULL_NONE; // FOR DEBUGGING + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CULLMODE, d3dCullMode)); + + // Polygon offset + // ZBIAS ranges from 0 to 16 and can only move towards the viewer + // Mesa5: ctx->Polygon._OffsetAny removed + if (ctx->Polygon.OffsetFill) { + fOffset = ctx->Polygon.OffsetUnits; +// if (iOffset < 0.0f) +// iOffset = -iOffset; +// else +// iOffset = 0.0f; // D3D can't push away + } + // NOTE: SetRenderState() required a DWORD, so need to cast + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_DEPTHBIAS, *((DWORD*)&fOffset))); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_FOG( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DCOLOR d3dFogColour; + D3DFOGMODE d3dFogMode = D3DFOG_LINEAR; + + // TODO: Fog is calculated seperately in the Mesa pipeline + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, FALSE)); + return; + + // Fog enable + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, ctx->Fog.Enabled)); + if (!ctx->Fog.Enabled) { + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, D3DFOG_NONE)); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); + return; // If disabled, don't bother setting any fog state + } + + // Fog colour + d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0], + ctx->Fog.Color[1], + ctx->Fog.Color[2], + ctx->Fog.Color[3]); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGCOLOR, d3dFogColour)); + + // Fog density + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density)))); + + // Fog start + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGSTART, *((DWORD*) (&ctx->Fog.Start)))); + + // Fog end + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGEND, *((DWORD*) (&ctx->Fog.End)))); + + // Fog mode + switch (ctx->Fog.Mode) { + case GL_LINEAR: + d3dFogMode = D3DFOG_LINEAR; + break; + case GL_EXP: + d3dFogMode = D3DFOG_EXP; + break; + case GL_EXP2: + d3dFogMode = D3DFOG_EXP2; + break; + } + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, d3dFogMode)); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_LIGHT( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + DWORD dwSpecularEnable; + + // Shademode + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT)); + + // Separate specular colour + if (ctx->Light.Enabled) + dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE; + else + dwSpecularEnable = FALSE; + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SPECULARENABLE, dwSpecularEnable)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_MODELVIEW( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DMATRIX m; + //GLfloat *pM = ctx->ModelView.m; + // Mesa5: Model-view is now a stack + GLfloat *pM = ctx->ModelviewMatrixStack.Top->m; + m._11 = pM[0]; + m._12 = pM[1]; + m._13 = pM[2]; + m._14 = pM[3]; + m._21 = pM[4]; + m._22 = pM[5]; + m._23 = pM[6]; + m._24 = pM[7]; + m._31 = pM[8]; + m._32 = pM[9]; + m._33 = pM[10]; + m._34 = pM[11]; + m._41 = pM[12]; + m._42 = pM[13]; + m._43 = pM[14]; + m._44 = pM[15]; + + gld->matModelView = m; +} + +//--------------------------------------------------------------------------- + +void gld_NEW_PROJECTION( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DMATRIX m; + //GLfloat *pM = ctx->ProjectionMatrix.m; + // Mesa 5: Now a stack + GLfloat *pM = ctx->ProjectionMatrixStack.Top->m; + m._11 = pM[0]; + m._12 = pM[1]; + m._13 = pM[2]; + m._14 = pM[3]; + + m._21 = pM[4]; + m._22 = pM[5]; + m._23 = pM[6]; + m._24 = pM[7]; + + m._31 = pM[8]; + m._32 = pM[9]; + m._33 = pM[10] / _fPersp_33; // / 1.6f; + m._34 = pM[11]; + + m._41 = pM[12]; + m._42 = pM[13]; + m._43 = pM[14] / 2.0f; + m._44 = pM[15]; + + gld->matProjection = m; +} + +//--------------------------------------------------------------------------- +/* +void gldFrustumHook_DX9( + GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearval, + GLdouble farval) +{ + GET_CURRENT_CONTEXT(ctx); + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + // Pass values on to Mesa first (in case we mess with them) + _mesa_Frustum(left, right, bottom, top, nearval, farval); + + _fPersp_33 = farval / (nearval - farval); + +// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval); +} + +//--------------------------------------------------------------------------- + +void gldOrthoHook_DX9( + GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearval, + GLdouble farval) +{ + GET_CURRENT_CONTEXT(ctx); + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + // Pass values on to Mesa first (in case we mess with them) + _mesa_Ortho(left, right, bottom, top, nearval, farval); + + _fPersp_33 = 1.6f; + +// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval); +} +*/ +//--------------------------------------------------------------------------- + +void gld_NEW_VIEWPORT( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DVIEWPORT9 d3dvp; +// GLint x, y; +// GLsizei w, h; + + // Set depth range + _GLD_DX9_DEV(GetViewport(gld->pDev, &d3dvp)); + // D3D can't do Quake1/Quake2 z-trick + if (ctx->Viewport.Near <= ctx->Viewport.Far) { + d3dvp.MinZ = ctx->Viewport.Near; + d3dvp.MaxZ = ctx->Viewport.Far; + } else { + d3dvp.MinZ = ctx->Viewport.Far; + d3dvp.MaxZ = ctx->Viewport.Near; + } +/* x = ctx->Viewport.X; + y = ctx->Viewport.Y; + w = ctx->Viewport.Width; + h = ctx->Viewport.Height; + if (x < 0) x = 0; + if (y < 0) y = 0; + if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; + if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; + // Ditto for D3D viewport dimensions + if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; + if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; + d3dvp.X = x; + d3dvp.Y = gldCtx->dwHeight - (y + h); + d3dvp.Width = w; + d3dvp.Height = h;*/ + _GLD_DX9_DEV(SetViewport(gld->pDev, &d3dvp)); + +// gld->fFlipWindowY = (float)gldCtx->dwHeight; +} + +//--------------------------------------------------------------------------- + +void gld_NEW_SCISSOR( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + // Bail if IHV driver cannot scissor + if (!gld->bCanScissor) + return; + + // Set scissor rect + if (ctx->Scissor.Enabled) { + RECT rcRect; + // Keep in mind that RECT's need an extra row and column + rcRect.left = ctx->Scissor.X; + rcRect.right = ctx->Scissor.X + ctx->Scissor.Width; // + 1; + rcRect.top = gldCtx->dwHeight - (ctx->Scissor.Y + ctx->Scissor.Height); + rcRect.bottom = rcRect.top + ctx->Scissor.Height; + IDirect3DDevice9_SetScissorRect(gld->pDev, &rcRect); + } + + // Enable/disable scissor as required + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SCISSORTESTENABLE, ctx->Scissor.Enabled)); +} + +//--------------------------------------------------------------------------- + +__inline BOOL _gldAnyEvalEnabled( + GLcontext *ctx) +{ + struct gl_eval_attrib *eval = &ctx->Eval; + + if ((eval->AutoNormal) || + (eval->Map1Color4) || + (eval->Map1Index) || + (eval->Map1Normal) || + (eval->Map1TextureCoord1) || + (eval->Map1TextureCoord2) || + (eval->Map1TextureCoord3) || + (eval->Map1TextureCoord4) || + (eval->Map1Vertex3) || + (eval->Map1Vertex4) || + (eval->Map2Color4) || + (eval->Map2Index) || + (eval->Map2Normal) || + (eval->Map2TextureCoord1) || + (eval->Map2TextureCoord2) || + (eval->Map2TextureCoord3) || + (eval->Map2TextureCoord4) || + (eval->Map2Vertex3) || + (eval->Map2Vertex4) + ) + return TRUE; + + return FALSE; +} + +//--------------------------------------------------------------------------- + +BOOL _gldChooseInternalPipeline( + GLcontext *ctx, + GLD_driver_dx9 *gld) +{ +// return TRUE; // DEBUGGING: ALWAYS USE MESA +// return FALSE; // DEBUGGING: ALWAYS USE D3D + + if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE)) + { + gld->PipelineUsage.qwMesa.QuadPart++; + return TRUE; // Force Mesa TnL + } + + if ((ctx->Light.Enabled) || + (1) || + (ctx->Texture._TexGenEnabled) || + (ctx->Texture._TexMatEnabled) || +// (ctx->Transform._AnyClip) || + (ctx->Scissor.Enabled) || + _gldAnyEvalEnabled(ctx) // Put this last so we can early-out + ) + { + gld->PipelineUsage.qwMesa.QuadPart++; + return TRUE; + } + + gld->PipelineUsage.qwD3DFVF.QuadPart++; + return FALSE; + +/* // Force Mesa pipeline? + if (glb.dwTnL == GLDS_TNL_MESA) { + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + + // Test for functionality not exposed in the D3D pathways + if ((ctx->Texture._GenFlags)) { + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + + // Now decide if vertex shader can be used. + // If two sided lighting is enabled then we must either + // use Mesa TnL or the vertex shader + if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { + if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) { + // Use Vertex Shader + gld->PipelineUsage.dwD3D2SVS.QuadPart++; + return GLD_PIPELINE_D3D_VS_TWOSIDE; + } else { + // Use Mesa TnL + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + } + + // Must be D3D fixed-function pipeline + gld->PipelineUsage.dwD3DFVF.QuadPart++; + return GLD_PIPELINE_D3D_FVF; +*/ +} + +//--------------------------------------------------------------------------- + +void gld_update_state_DX9( + GLcontext *ctx, + GLuint new_state) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + TNLcontext *tnl = TNL_CONTEXT(ctx); + GLD_pb_dx9 *gldPB; + + if (!gld || !gld->pDev) + return; + + _swsetup_InvalidateState( ctx, new_state ); + _vbo_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + + // SetupIndex will be used in the pipelines for choosing setup function + if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) || + (ctx->Fog.Enabled)) + { + if (ctx->_TriangleCaps & DD_FLATSHADE) + gld->iSetupFunc = GLD_SI_FLAT_EXTRAS; + else + gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS; + } else { + if (ctx->_TriangleCaps & DD_FLATSHADE) + gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture + else + gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture + } + + gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld); + if (gld->bUseMesaTnL) { + gldPB = &gld->PB2d; + _GLD_DX9_DEV(SetSoftwareVertexProcessing(gld->pDev, TRUE)); + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, FALSE)); + _GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL)); + _GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF)); + } else { + gldPB = &gld->PB3d; + _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE)); +// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) { +// _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware)); +// _GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); +// } else { +// _GLD_DX9_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL)); + _GLD_DX9_DEV(SetSoftwareVertexProcessing(gld->pDev, !gld->bHasHWTnL)); + _GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL)); + _GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF)); +// } + } + +#define _GLD_TEST_STATE(a) \ + if (new_state & (a)) { \ + gld##a(ctx); \ + new_state &= ~(a); \ + } + +#define _GLD_TEST_STATE_DX9(a) \ + if (new_state & (a)) { \ + gld##a##_DX9(ctx); \ + new_state &= ~(a); \ + } + +#define _GLD_IGNORE_STATE(a) new_state &= ~(a); + +// if (!gld->bUseMesaTnL) { + // Not required if Mesa is doing the TnL. + // Problem: If gld->bUseMesaTnL is TRUE when these are signaled, + // then we'll miss updating the D3D TnL pipeline. + // Therefore, don't test for gld->bUseMesaTnL + _GLD_TEST_STATE(_NEW_MODELVIEW); + _GLD_TEST_STATE(_NEW_PROJECTION); +// } + + _GLD_TEST_STATE_DX9(_NEW_TEXTURE); // extern, so guard with _DX9 + _GLD_TEST_STATE(_NEW_COLOR); + _GLD_TEST_STATE(_NEW_DEPTH); + _GLD_TEST_STATE(_NEW_POLYGON); + _GLD_TEST_STATE(_NEW_STENCIL); + _GLD_TEST_STATE(_NEW_FOG); + _GLD_TEST_STATE(_NEW_LIGHT); + _GLD_TEST_STATE(_NEW_VIEWPORT); + + _GLD_IGNORE_STATE(_NEW_TRANSFORM); + + // Scissor Test: New for DX9 + _GLD_TEST_STATE(_NEW_SCISSOR); + +// Stubs for future use. +/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX); + _GLD_TEST_STATE(_NEW_COLOR_MATRIX); + _GLD_TEST_STATE(_NEW_ACCUM); + _GLD_TEST_STATE(_NEW_EVAL); + _GLD_TEST_STATE(_NEW_HINT); + _GLD_TEST_STATE(_NEW_LINE); + _GLD_TEST_STATE(_NEW_PIXEL); + _GLD_TEST_STATE(_NEW_POINT); + _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE); + _GLD_TEST_STATE(_NEW_PACKUNPACK); + _GLD_TEST_STATE(_NEW_ARRAY); + _GLD_TEST_STATE(_NEW_RENDERMODE); + _GLD_TEST_STATE(_NEW_BUFFERS); + _GLD_TEST_STATE(_NEW_MULTISAMPLE); +*/ + +// For debugging. +#if 0 +#define _GLD_TEST_UNHANDLED_STATE(a) \ + if (new_state & (a)) { \ + gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \ + } + _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX); + _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX); + _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM); + _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL); + _GLD_TEST_UNHANDLED_STATE(_NEW_HINT); + _GLD_TEST_UNHANDLED_STATE(_NEW_LINE); + _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL); + _GLD_TEST_UNHANDLED_STATE(_NEW_POINT); + _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE); +// _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR); + _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK); + _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY); + _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE); + _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS); + _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE); +#undef _GLD_UNHANDLED_STATE +#endif + +#undef _GLD_TEST_STATE +} + +//--------------------------------------------------------------------------- +// Viewport +//--------------------------------------------------------------------------- + +void gld_Viewport_DX9( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei w, + GLsizei h) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + D3DVIEWPORT9 d3dvp; + + if (!gld || !gld->pDev) + return; + + // This is a hack. When the app is minimized, Mesa passes + // w=1 and h=1 for viewport dimensions. Without this test + // we get a GPF in gld_wgl_resize_buffers(). + if ((w==1) && (h==1)) + return; + + // Call ResizeBuffersMESA. This function will early-out + // if no resize is needed. + //ctx->Driver.ResizeBuffersMESA(ctx); + // Mesa 5: Changed parameters + ctx->Driver.ResizeBuffers(gldCtx->glBuffer); + +#if 0 + ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h); +#endif + + // ** D3D viewport must not be outside the render target surface ** + // Sanity check the GL viewport dimensions + if (x < 0) x = 0; + if (y < 0) y = 0; + if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; + if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; + // Ditto for D3D viewport dimensions + if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; + if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; + + d3dvp.X = x; + d3dvp.Y = gldCtx->dwHeight - (y + h); + d3dvp.Width = w; + d3dvp.Height = h; + if (ctx->Viewport.Near <= ctx->Viewport.Far) { + d3dvp.MinZ = ctx->Viewport.Near; + d3dvp.MaxZ = ctx->Viewport.Far; + } else { + d3dvp.MinZ = ctx->Viewport.Far; + d3dvp.MaxZ = ctx->Viewport.Near; + } + + // TODO: DEBUGGING +// d3dvp.MinZ = 0.0f; +// d3dvp.MaxZ = 1.0f; + + _GLD_DX9_DEV(SetViewport(gld->pDev, &d3dvp)); + +} + +//--------------------------------------------------------------------------- + +extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver); + +// Mesa 5: Parameter change +void gldResizeBuffers_DX9( +// GLcontext *ctx) + GLframebuffer *fb) +{ + GET_CURRENT_CONTEXT(ctx); + dglWglResizeBuffers(ctx, TRUE); +} + +//--------------------------------------------------------------------------- +#ifdef _DEBUG +// This is only for debugging. +// To use, plug into ctx->Driver.Enable pointer below. +void gld_Enable( + GLcontext *ctx, + GLenum e, + GLboolean b) +{ + char buf[1024]; + sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE"); + ddlogMessage(DDLOG_SYSTEM, buf); +} +#endif +//--------------------------------------------------------------------------- +// Driver pointer setup +//--------------------------------------------------------------------------- + +extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum); + +void gldSetupDriverPointers_DX9( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); + + TNLcontext *tnl = TNL_CONTEXT(ctx); + + // Mandatory functions + ctx->Driver.GetString = _gldGetStringGeneric; + ctx->Driver.UpdateState = gld_update_state_DX9; + ctx->Driver.Clear = gld_Clear_DX9; + ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX9; + ctx->Driver.GetBufferSize = gld_buffer_size_DX9; + ctx->Driver.Finish = gld_Finish_DX9; + ctx->Driver.Flush = gld_Flush_DX9; + ctx->Driver.Error = gld_Error_DX9; + + // Hardware accumulation buffer + ctx->Driver.Accum = NULL; // TODO: gld_Accum; + + // Bitmap functions + ctx->Driver.CopyPixels = gld_CopyPixels_DX9; + ctx->Driver.DrawPixels = gld_DrawPixels_DX9; + ctx->Driver.ReadPixels = gld_ReadPixels_DX9; + ctx->Driver.Bitmap = gld_Bitmap_DX9; + + // Buffer resize + ctx->Driver.ResizeBuffers = gldResizeBuffers_DX9; + + // Texture image functions + ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX9; + ctx->Driver.TexImage1D = gld_TexImage1D_DX9; + ctx->Driver.TexImage2D = gld_TexImage2D_DX9; + ctx->Driver.TexImage3D = _mesa_store_teximage3d; + ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX9; + ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX9; + ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + + ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX9; //NULL; + ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX9; //NULL; + ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX9; //NULL; + ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX9; //NULL; + ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX9; + ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; + + // Texture object functions + ctx->Driver.BindTexture = NULL; + ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!; + ctx->Driver.DeleteTexture = gld_DeleteTexture_DX9; + ctx->Driver.PrioritizeTexture = NULL; + + // Imaging functionality + ctx->Driver.CopyColorTable = NULL; + ctx->Driver.CopyColorSubTable = NULL; + ctx->Driver.CopyConvolutionFilter1D = NULL; + ctx->Driver.CopyConvolutionFilter2D = NULL; + + // State changing functions + ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc; + ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc; + ctx->Driver.ClearColor = NULL; //gld_ClearColor; + ctx->Driver.ClearDepth = NULL; //gld_ClearDepth; + ctx->Driver.ClearStencil = NULL; //gld_ClearStencil; + ctx->Driver.ColorMask = NULL; //gld_ColorMask; + ctx->Driver.CullFace = NULL; //gld_CullFace; + ctx->Driver.ClipPlane = NULL; //gld_ClipPlane; + ctx->Driver.FrontFace = NULL; //gld_FrontFace; + ctx->Driver.DepthFunc = NULL; //gld_DepthFunc; + ctx->Driver.DepthMask = NULL; //gld_DepthMask; + ctx->Driver.DepthRange = NULL; + ctx->Driver.Enable = NULL; //gld_Enable; + ctx->Driver.Fogfv = NULL; //gld_Fogfv; + ctx->Driver.Hint = NULL; //gld_Hint; + ctx->Driver.Lightfv = NULL; //gld_Lightfv; + ctx->Driver.LightModelfv = NULL; //gld_LightModelfv; + ctx->Driver.LineStipple = NULL; //gld_LineStipple; + ctx->Driver.LineWidth = NULL; //gld_LineWidth; + ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode; + ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv; + ctx->Driver.PointSize = NULL; //gld_PointSize; + ctx->Driver.PolygonMode = NULL; //gld_PolygonMode; + ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset; + ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple; + ctx->Driver.RenderMode = NULL; //gld_RenderMode; + ctx->Driver.Scissor = NULL; //gld_Scissor; + ctx->Driver.ShadeModel = NULL; //gld_ShadeModel; + ctx->Driver.StencilFunc = NULL; //gld_StencilFunc; + ctx->Driver.StencilMask = NULL; //gld_StencilMask; + ctx->Driver.StencilOp = NULL; //gld_StencilOp; + ctx->Driver.TexGen = NULL; //gld_TexGen; + ctx->Driver.TexEnv = NULL; + ctx->Driver.TexParameter = NULL; + ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix; + ctx->Driver.Viewport = gld_Viewport_DX9; + + _swsetup_Wakeup(ctx); + + tnl->Driver.RunPipeline = _tnl_run_pipeline; + tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX9; + tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; + tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; + + // Hook into glFrustum() and glOrtho() +// ctx->Exec->Frustum = gldFrustumHook_DX9; +// ctx->Exec->Ortho = gldOrthoHook_DX9; + +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx9/gld_wgl_dx9.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx9/gld_wgl_dx9.c @@ -0,0 +1,1345 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect Direct3D 8.x WGL (WindowsGL) +* +****************************************************************************/ + +#include "dglcontext.h" +#include "gld_driver.h" +#include "gld_dxerr9.h" +#include "gld_dx9.h" + +#include "tnl/tnl.h" +#include "tnl/t_context.h" + +// Copied from dglcontect.c +#define GLDERR_NONE 0 +#define GLDERR_MEM 1 +#define GLDERR_DDRAW 2 +#define GLDERR_D3D 3 +#define GLDERR_BPP 4 +#define GLDERR_DDS 5 +// This external var keeps track of any error +extern int nContextError; + +#define DDLOG_CRITICAL_OR_WARN DDLOG_CRITICAL + +extern void _gld_mesa_warning(GLcontext *, char *); +extern void _gld_mesa_fatal(GLcontext *, char *); + +//--------------------------------------------------------------------------- + +static char szColorDepthWarning[] = +"GLDirect does not support the current desktop\n\ +color depth.\n\n\ +You may need to change the display resolution to\n\ +16 bits per pixel or higher color depth using\n\ +the Windows Display Settings control panel\n\ +before running this OpenGL application.\n"; + +// The only depth-stencil formats currently supported by Direct3D +// Surface Format Depth Stencil Total Bits +// D3DFMT_D32 32 - 32 +// D3DFMT_D15S1 15 1 16 +// D3DFMT_D24S8 24 8 32 +// D3DFMT_D16 16 - 16 +// D3DFMT_D24X8 24 - 32 +// D3DFMT_D24X4S4 24 4 32 + +// This pixel format will be used as a template when compiling the list +// of pixel formats supported by the hardware. Many fields will be +// filled in at runtime. +// PFD flag defaults are upgraded to match ChoosePixelFormat() -- DaveM +static DGL_pixelFormat pfTemplateHW = +{ + { + sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure + 1, // Structure version - should be 1 + // Flags: + PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. + PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) + PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) + PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. + PFD_DOUBLEBUFFER | // The buffer is double-buffered. + 0, // Placeholder for easy commenting of above flags + PFD_TYPE_RGBA, // Pixel type RGBA. + 16, // Total colour bitplanes (excluding alpha bitplanes) + 5, 0, // Red bits, shift + 5, 0, // Green bits, shift + 5, 0, // Blue bits, shift + 0, 0, // Alpha bits, shift (destination alpha) + 0, // Accumulator bits (total) + 0, 0, 0, 0, // Accumulator bits: Red, Green, Blue, Alpha + 0, // Depth bits + 0, // Stencil bits + 0, // Number of auxiliary buffers + 0, // Layer type + 0, // Specifies the number of overlay and underlay planes. + 0, // Layer mask + 0, // Specifies the transparent color or index of an underlay plane. + 0 // Damage mask + }, + D3DFMT_UNKNOWN, // No depth/stencil buffer +}; + +//--------------------------------------------------------------------------- +// Vertex Shaders +//--------------------------------------------------------------------------- +/* +// Vertex Shader Declaration +static DWORD dwTwoSidedLightingDecl[] = +{ + D3DVSD_STREAM(0), + D3DVSD_REG(0, D3DVSDT_FLOAT3), // XYZ position + D3DVSD_REG(1, D3DVSDT_FLOAT3), // XYZ normal + D3DVSD_REG(2, D3DVSDT_D3DCOLOR), // Diffuse color + D3DVSD_REG(3, D3DVSDT_D3DCOLOR), // Specular color + D3DVSD_REG(4, D3DVSDT_FLOAT2), // 2D texture unit 0 + D3DVSD_REG(5, D3DVSDT_FLOAT2), // 2D texture unit 1 + D3DVSD_END() +}; + +// Vertex Shader for two-sided lighting +static char *szTwoSidedLightingVS = +// This is a test shader! +"vs.1.0\n" +"m4x4 oPos,v0,c0\n" +"mov oD0,v2\n" +"mov oD1,v3\n" +"mov oT0,v4\n" +"mov oT1,v5\n" +; +*/ +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +typedef struct { + HINSTANCE hD3D9DLL; // Handle to d3d9.dll + FNDIRECT3DCREATE9 fnDirect3DCreate9; // Direct3DCreate9 function prototype + BOOL bDirect3D; // Persistant Direct3D9 exists + BOOL bDirect3DDevice; // Persistant Direct3DDevice9 exists + IDirect3D9 *pD3D; // Persistant Direct3D9 + IDirect3DDevice9 *pDev; // Persistant Direct3DDevice9 +} GLD_dx9_globals; + +// These are "global" to all DX9 contexts. KeithH +static GLD_dx9_globals dx9Globals; + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +BOOL gldGetDXErrorString_DX( + HRESULT hr, + char *buf, + int nBufSize) +{ + // + // Return a string describing the input HRESULT error code + // + + const char *pStr = DXGetErrorString9(hr); + + if (pStr == NULL) + return FALSE; + + if (strlen(pStr) > nBufSize) + strncpy(buf, pStr, nBufSize); + else + strcpy(buf, pStr); + +// D3DXGetErrorString(hr, buf, nBufSize); + + return TRUE; +} + +//--------------------------------------------------------------------------- + +static D3DMULTISAMPLE_TYPE _gldGetDeviceMultiSampleType( + IDirect3D9 *pD3D9, + D3DFORMAT SurfaceFormat, + D3DDEVTYPE d3dDevType, + BOOL Windowed) +{ + int i; + HRESULT hr; + + if (glb.dwMultisample == GLDS_MULTISAMPLE_NONE) + return D3DMULTISAMPLE_NONE; + + if (glb.dwMultisample == GLDS_MULTISAMPLE_FASTEST) { + // Find fastest multisample + for (i=2; i<17; i++) { + hr = IDirect3D9_CheckDeviceMultiSampleType( + pD3D9, + glb.dwAdapter, + d3dDevType, + SurfaceFormat, + Windowed, + (D3DMULTISAMPLE_TYPE)i, + NULL); + if (SUCCEEDED(hr)) { + return (D3DMULTISAMPLE_TYPE)i; + } + } + } else { + // Find nicest multisample + for (i=16; i>1; i--) { + hr = IDirect3D9_CheckDeviceMultiSampleType( + pD3D9, + glb.dwAdapter, + d3dDevType, + SurfaceFormat, + Windowed, + (D3DMULTISAMPLE_TYPE)i, + NULL); + if (SUCCEEDED(hr)) { + return (D3DMULTISAMPLE_TYPE)i; + } + } + } + + // Nothing found - return default + return D3DMULTISAMPLE_NONE; +} + +//--------------------------------------------------------------------------- + +void _gldDestroyPrimitiveBuffer( + GLD_pb_dx9 *gldVB) +{ + SAFE_RELEASE(gldVB->pVB); + + // Sanity check... + gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; +} + +//--------------------------------------------------------------------------- + +HRESULT _gldCreatePrimitiveBuffer( + GLcontext *ctx, + GLD_driver_dx9 *lpCtx, + GLD_pb_dx9 *gldVB) +{ + HRESULT hResult; + char *szCreateVertexBufferFailed = "CreateVertexBuffer failed"; + DWORD dwMaxVertices; // Max number of vertices in vertex buffer + DWORD dwVBSize; // Total size of vertex buffer + + // If CVA (Compiled Vertex Array) is used by an OpenGL app, then we + // will need enough vertices to cater for Mesa::Const.MaxArrayLockSize. + // We'll use IMM_SIZE if it's larger (which it should not be). + dwMaxVertices = MAX_ARRAY_LOCK_SIZE; + + // Now calculate how many vertices to allow for in total + // 1 per point, 2 per line, 6 per quad = 9 + dwVBSize = dwMaxVertices * 9 * gldVB->dwStride; + + hResult = IDirect3DDevice9_CreateVertexBuffer( + lpCtx->pDev, + dwVBSize, + gldVB->dwUsage, + gldVB->dwFVF, + gldVB->dwPool, + &gldVB->pVB, + NULL); + if (FAILED(hResult)) { + ddlogMessage(DDLOG_CRITICAL_OR_WARN, szCreateVertexBufferFailed); + return hResult; + } + + gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; + gldVB->pPoints = gldVB->pLines = gldVB->pTriangles = NULL; + gldVB->iFirstLine = dwMaxVertices; // Index of first line in VB + gldVB->iFirstTriangle = dwMaxVertices*3; // Index of first triangle in VB + + return S_OK; +} + +//--------------------------------------------------------------------------- +// Function: _gldCreateVertexShaders +// Create DX9 Vertex Shaders. +//--------------------------------------------------------------------------- +/* +void _gldCreateVertexShaders( + GLD_driver_dx9 *gld) +{ + DWORD dwFlags; + LPD3DXBUFFER pVSOpcodeBuffer; // Vertex Shader opcode buffer + HRESULT hr; + +#ifdef _DEBUG + dwFlags = D3DXASM_DEBUG; +#else + dwFlags = 0; // D3DXASM_SKIPVALIDATION; +#endif + + ddlogMessage(DDLOG_INFO, "Creating shaders...\n"); + + // Init the shader handle + gld->VStwosidelight.hShader = 0; + + if (gld->d3dCaps8.MaxStreams == 0) { + // Lame DX8 driver doesn't support streams + // Not fatal, as defaults will be used + ddlogMessage(DDLOG_WARN, "Driver doesn't support Vertex Shaders (MaxStreams==0)\n"); + return; + } + + // ** THIS DISABLES VERTEX SHADER SUPPORT ** +// return; + // ** THIS DISABLES VERTEX SHADER SUPPORT ** + + // + // Two-sided lighting + // + +#if 0 + // + // DEBUGGING: Load shader from a text file + // + { + LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer + hr = D3DXAssembleShaderFromFile( + "twoside.vsh", + dwFlags, + NULL, // No constants + &pVSOpcodeBuffer, + &pVSErrorBuffer); + if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) + ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); + SAFE_RELEASE(pVSErrorBuffer); + } +#else + { + LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer + // Assemble ascii shader text into shader opcodes + hr = D3DXAssembleShader( + szTwoSidedLightingVS, + strlen(szTwoSidedLightingVS), + dwFlags, + NULL, // No constants + &pVSOpcodeBuffer, + &pVSErrorBuffer); + if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) + ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); + SAFE_RELEASE(pVSErrorBuffer); + } +#endif + if (FAILED(hr)) { + ddlogError(DDLOG_WARN, "AssembleShader failed", hr); + SAFE_RELEASE(pVSOpcodeBuffer); + return; + } + +// This is for debugging. Remove to enable vertex shaders in HW +#define _GLD_FORCE_SW_VS 0 + + if (_GLD_FORCE_SW_VS) { + // _GLD_FORCE_SW_VS should be disabled for Final Release + ddlogMessage(DDLOG_SYSTEM, "[Forcing shaders in SW]\n"); + } + + // Try and create shader in hardware. + // NOTE: The D3D Ref device appears to succeed when trying to + // create the device in hardware, but later complains + // when trying to set it with SetVertexShader(). Go figure. + if (_GLD_FORCE_SW_VS || glb.dwDriver == GLDS_DRIVER_REF) { + // Don't try and create a hardware shader with the Ref device + hr = E_FAIL; // COM error/fail result + } else { + gld->VStwosidelight.bHardware = TRUE; + hr = IDirect3DDevice8_CreateVertexShader( + gld->pDev, + dwTwoSidedLightingDecl, + pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), + &gld->VStwosidelight.hShader, + 0); + } + if (FAILED(hr)) { + ddlogMessage(DDLOG_INFO, "... HW failed, trying SW...\n"); + // Failed. Try and create shader for software processing + hr = IDirect3DDevice8_CreateVertexShader( + gld->pDev, + dwTwoSidedLightingDecl, + pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), + &gld->VStwosidelight.hShader, + D3DUSAGE_SOFTWAREPROCESSING); + if (FAILED(hr)) { + gld->VStwosidelight.hShader = 0; // Sanity check + ddlogError(DDLOG_WARN, "CreateVertexShader failed", hr); + return; + } + // Succeeded, but for software processing + gld->VStwosidelight.bHardware = FALSE; + } + + SAFE_RELEASE(pVSOpcodeBuffer); + + ddlogMessage(DDLOG_INFO, "... OK\n"); +} + +//--------------------------------------------------------------------------- + +void _gldDestroyVertexShaders( + GLD_driver_dx9 *gld) +{ + if (gld->VStwosidelight.hShader) { + IDirect3DDevice8_DeleteVertexShader(gld->pDev, gld->VStwosidelight.hShader); + gld->VStwosidelight.hShader = 0; + } +} +*/ +//--------------------------------------------------------------------------- + +BOOL gldCreateDrawable_DX( + DGL_ctx *ctx, +// BOOL bDefaultDriver, + BOOL bDirectDrawPersistant, + BOOL bPersistantBuffers) +{ + // + // bDirectDrawPersistant: applies to IDirect3D9 + // bPersistantBuffers: applies to IDirect3DDevice9 + // + + HRESULT hResult; + GLD_driver_dx9 *lpCtx = NULL; + D3DDEVTYPE d3dDevType; + D3DPRESENT_PARAMETERS d3dpp; + D3DDISPLAYMODE d3ddm; + DWORD dwBehaviourFlags; + D3DADAPTER_IDENTIFIER9 d3dIdent; + + // Error if context is NULL. + if (ctx == NULL) + return FALSE; + + if (ctx->glPriv) { + lpCtx = ctx->glPriv; + // Release any existing interfaces + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + } else { + lpCtx = (GLD_driver_dx9*)malloc(sizeof(GLD_driver_dx9)); + ZeroMemory(lpCtx, sizeof(lpCtx)); + } + + d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + // TODO: Check this +// if (bDefaultDriver) +// d3dDevType = D3DDEVTYPE_REF; + + // Use persistant interface if needed + if (bDirectDrawPersistant && dx9Globals.bDirect3D) { + lpCtx->pD3D = dx9Globals.pD3D; + IDirect3D9_AddRef(lpCtx->pD3D); + goto SkipDirectDrawCreate; + } + + // Create Direct3D9 object + lpCtx->pD3D = dx9Globals.fnDirect3DCreate9(D3D_SDK_VERSION); + if (lpCtx->pD3D == NULL) { + MessageBox(NULL, "Unable to initialize Direct3D9", "GLDirect", MB_OK); + ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D9 interface"); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Cache Direct3D interface for subsequent GLRCs + if (bDirectDrawPersistant && !dx9Globals.bDirect3D) { + dx9Globals.pD3D = lpCtx->pD3D; + IDirect3D9_AddRef(dx9Globals.pD3D); + dx9Globals.bDirect3D = TRUE; + } +SkipDirectDrawCreate: + + // Get the display mode so we can make a compatible backbuffer + hResult = IDirect3D9_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hResult)) { + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Get device caps + hResult = IDirect3D9_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps9); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D9_GetDeviceCaps failed", hResult); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Check for hardware transform & lighting + lpCtx->bHasHWTnL = lpCtx->d3dCaps9.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; + +/* + // + // GONE FOR DX9? + // + // If this flag is present then we can't default to Mesa + // SW rendering between BeginScene() and EndScene(). + if (lpCtx->d3dCaps9.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { + ddlogMessage(DDLOG_WARN, + "Warning : No 2D allowed during 3D scene.\n"); + } +*/ + + // + // Create the Direct3D context + // + + // Re-use original IDirect3DDevice if persistant buffers exist. + // Note that we test for persistant IDirect3D9 as well + // bDirectDrawPersistant == persistant IDirect3D9 (DirectDraw9 does not exist) + if (bDirectDrawPersistant && bPersistantBuffers && dx9Globals.pD3D && dx9Globals.pDev) { + lpCtx->pDev = dx9Globals.pDev; + IDirect3DDevice9_AddRef(dx9Globals.pDev); + goto skip_direct3ddevice_create; + } + + // Clear the presentation parameters (sets all members to zero) + ZeroMemory(&d3dpp, sizeof(d3dpp)); + + // Recommended by MS; needed for MultiSample. + // Be careful if altering this for FullScreenBlit + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + + d3dpp.BackBufferFormat = d3ddm.Format; + d3dpp.BackBufferCount = 2; //1; + d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); + d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; + d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; + + if (ctx->bFullscreen) { + ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen + d3dpp.Windowed = FALSE; + d3dpp.BackBufferWidth = d3ddm.Width; + d3dpp.BackBufferHeight = d3ddm.Height; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + + // Support for vertical retrace synchronisation. + // Set default presentation interval in case caps bits are missing + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + if (glb.bWaitForRetrace) { + if (lpCtx->d3dCaps9.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + } else { + if (lpCtx->d3dCaps9.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + } else { + ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages + d3dpp.Windowed = TRUE; + d3dpp.BackBufferWidth = ctx->dwWidth; + d3dpp.BackBufferHeight = ctx->dwHeight; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = 0; + // PresentationInterval Windowed mode is optional now in DX9 (DaveM) + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + if (glb.bWaitForRetrace) { + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + } else { + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + } + + // Decide if we can use hardware TnL + dwBehaviourFlags = (lpCtx->bHasHWTnL) ? + D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; + // Add flag to tell D3D to be thread-safe + if (glb.bMultiThreaded) + dwBehaviourFlags |= D3DCREATE_MULTITHREADED; + // Add flag to tell D3D to be FPU-safe + if (!glb.bFastFPU) + dwBehaviourFlags |= D3DCREATE_FPU_PRESERVE; + hResult = IDirect3D9_CreateDevice(lpCtx->pD3D, + glb.dwAdapter, + d3dDevType, + ctx->hWnd, + dwBehaviourFlags, + &d3dpp, + &lpCtx->pDev); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D9_CreateDevice failed", hResult); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + if (bDirectDrawPersistant && bPersistantBuffers && dx9Globals.pD3D) { + dx9Globals.pDev = lpCtx->pDev; + dx9Globals.bDirect3DDevice = TRUE; + } + + // Dump some useful stats + hResult = IDirect3D9_GetAdapterIdentifier( + lpCtx->pD3D, + glb.dwAdapter, + 0, // No WHQL detection (avoid few seconds delay) + &d3dIdent); + if (SUCCEEDED(hResult)) { + ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); + ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", + d3dIdent.Driver, + HIWORD(d3dIdent.DriverVersion.HighPart), + LOWORD(d3dIdent.DriverVersion.HighPart), + HIWORD(d3dIdent.DriverVersion.LowPart), + LOWORD(d3dIdent.DriverVersion.LowPart)); + ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", + d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); + } + + // Test to see if IHV driver exposes Scissor Test (new for DX9) + lpCtx->bCanScissor = lpCtx->d3dCaps9.RasterCaps & D3DPRASTERCAPS_SCISSORTEST; + ddlogPrintf(DDLOG_INFO, "Can Scissor: %s", lpCtx->bCanScissor ? "Yes" : "No"); + + // Init projection matrix for D3D TnL + D3DXMatrixIdentity(&lpCtx->matProjection); + lpCtx->matModelView = lpCtx->matProjection; +// gld->bUseMesaProjection = TRUE; + +skip_direct3ddevice_create: + + // Create buffers to hold primitives + lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; + lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; + lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); + lpCtx->PB2d.dwUsage = D3DUSAGE_DONOTCLIP | + D3DUSAGE_DYNAMIC | + D3DUSAGE_SOFTWAREPROCESSING | + D3DUSAGE_WRITEONLY; + hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); + if (FAILED(hResult)) + goto return_with_error; + + lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; + lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; + lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); + lpCtx->PB3d.dwUsage = D3DUSAGE_DYNAMIC | +//DaveM D3DUSAGE_SOFTWAREPROCESSING | + D3DUSAGE_WRITEONLY; + hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); + if (FAILED(hResult)) + goto return_with_error; + +/* // NOTE: A FVF code of zero indicates a non-FVF vertex buffer (for vertex shaders) + lpCtx->PBtwosidelight.dwFVF = 0; //GLD_FVF_TWOSIDED_VERTEX; + lpCtx->PBtwosidelight.dwPool = D3DPOOL_DEFAULT; + lpCtx->PBtwosidelight.dwStride = sizeof(GLD_TWOSIDED_VERTEX); + lpCtx->PBtwosidelight.dwUsage = D3DUSAGE_DONOTCLIP | + D3DUSAGE_DYNAMIC | + D3DUSAGE_SOFTWAREPROCESSING | + D3DUSAGE_WRITEONLY; + hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PBtwosidelight); + if (FAILED(hResult)) + goto return_with_error;*/ + + // Now try and create the DX9 Vertex Shaders +// _gldCreateVertexShaders(lpCtx); + + // Zero the pipeline usage counters + lpCtx->PipelineUsage.qwMesa.QuadPart = +// lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = + lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; + + // Assign drawable to GL private + ctx->glPriv = lpCtx; + return TRUE; + +return_with_error: + // Clean up and bail + +// _gldDestroyVertexShaders(lpCtx); + +// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); + _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); + _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); + + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + return FALSE; +} + +//--------------------------------------------------------------------------- + +BOOL gldResizeDrawable_DX( + DGL_ctx *ctx, + BOOL bDefaultDriver, + BOOL bPersistantInterface, + BOOL bPersistantBuffers) +{ + GLD_driver_dx9 *gld = NULL; + D3DDEVTYPE d3dDevType; + D3DPRESENT_PARAMETERS d3dpp; + D3DDISPLAYMODE d3ddm; + HRESULT hResult; + + // Error if context is NULL. + if (ctx == NULL) + return FALSE; + + gld = ctx->glPriv; + if (gld == NULL) + return FALSE; + + if (ctx->bSceneStarted) { + IDirect3DDevice9_EndScene(gld->pDev); + ctx->bSceneStarted = FALSE; + } + + d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + if (!bDefaultDriver) + d3dDevType = D3DDEVTYPE_REF; // Force Direct3D Reference Rasterise (software) + + // Get the display mode so we can make a compatible backbuffer + hResult = IDirect3D9_GetAdapterDisplayMode(gld->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hResult)) { + nContextError = GLDERR_D3D; +// goto return_with_error; + return FALSE; + } + + // Destroy DX9 Vertex Shaders before Reset() +// _gldDestroyVertexShaders(gld); + + // Release POOL_DEFAULT objects before Reset() + if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) + _gldDestroyPrimitiveBuffer(&gld->PB2d); + if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) + _gldDestroyPrimitiveBuffer(&gld->PB3d); +// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) +// _gldDestroyPrimitiveBuffer(&gld->PBtwosidelight); + + // Clear the presentation parameters (sets all members to zero) + ZeroMemory(&d3dpp, sizeof(d3dpp)); + + // Recommended by MS; needed for MultiSample. + // Be careful if altering this for FullScreenBlit + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + + d3dpp.BackBufferFormat = d3ddm.Format; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(gld->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); + d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; + d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; + + // TODO: Sync to refresh + + if (ctx->bFullscreen) { + ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen + d3dpp.Windowed = FALSE; + d3dpp.BackBufferWidth = d3ddm.Width; + d3dpp.BackBufferHeight = d3ddm.Height; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + // Get better benchmark results? KeithH +// d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_UNLIMITED; + } else { + ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages + d3dpp.Windowed = TRUE; + d3dpp.BackBufferWidth = ctx->dwWidth; + d3dpp.BackBufferHeight = ctx->dwHeight; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = 0; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + } + hResult = IDirect3DDevice9_Reset(gld->pDev, &d3dpp); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "dglResize: Reset failed", hResult); + return FALSE; + //goto cleanup_and_return_with_error; + } + + // + // Recreate POOL_DEFAULT objects + // + if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) { + _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); + } + if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) { + _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB3d); + } +// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) { +// _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); +// } + + // Recreate DX9 Vertex Shaders +// _gldCreateVertexShaders(gld); + + // Signal a complete state update + ctx->glCtx->Driver.UpdateState(ctx->glCtx, _NEW_ALL); + + // Begin a new scene + IDirect3DDevice9_BeginScene(gld->pDev); + ctx->bSceneStarted = TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyDrawable_DX( + DGL_ctx *ctx) +{ + GLD_driver_dx9 *lpCtx = NULL; + + // Error if context is NULL. + if (!ctx) + return FALSE; + + // Error if the drawable does not exist. + if (!ctx->glPriv) + return FALSE; + + lpCtx = ctx->glPriv; + +#ifdef _DEBUG + // Dump out stats + ddlogPrintf(DDLOG_SYSTEM, "Usage: M:0x%X%X, D:0x%X%X", + lpCtx->PipelineUsage.qwMesa.HighPart, + lpCtx->PipelineUsage.qwMesa.LowPart, + lpCtx->PipelineUsage.qwD3DFVF.HighPart, + lpCtx->PipelineUsage.qwD3DFVF.LowPart); +#endif + +// _gldDestroyVertexShaders(lpCtx); + +// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); + _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); + _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); + + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + + // Free the private drawable data + free(ctx->glPriv); + ctx->glPriv = NULL; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldCreatePrivateGlobals_DX(void) +{ + ZeroMemory(&dx9Globals, sizeof(dx9Globals)); + + // Load d3d9.dll + dx9Globals.hD3D9DLL = LoadLibrary("D3D9.DLL"); + if (dx9Globals.hD3D9DLL == NULL) + return FALSE; + + // Now try and obtain Direct3DCreate9 + dx9Globals.fnDirect3DCreate9 = (FNDIRECT3DCREATE9)GetProcAddress(dx9Globals.hD3D9DLL, "Direct3DCreate9"); + if (dx9Globals.fnDirect3DCreate9 == NULL) { + FreeLibrary(dx9Globals.hD3D9DLL); + return FALSE; + } + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyPrivateGlobals_DX(void) +{ + if (dx9Globals.bDirect3DDevice) { + SAFE_RELEASE(dx9Globals.pDev); + dx9Globals.bDirect3DDevice = FALSE; + } + if (dx9Globals.bDirect3D) { + SAFE_RELEASE(dx9Globals.pD3D); + dx9Globals.bDirect3D = FALSE; + } + + FreeLibrary(dx9Globals.hD3D9DLL); + dx9Globals.hD3D9DLL = NULL; + dx9Globals.fnDirect3DCreate9 = NULL; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +static void _BitsFromDisplayFormat( + D3DFORMAT fmt, + BYTE *cColorBits, + BYTE *cRedBits, + BYTE *cGreenBits, + BYTE *cBlueBits, + BYTE *cAlphaBits) +{ + switch (fmt) { + case D3DFMT_X1R5G5B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 5; + *cBlueBits = 5; + *cAlphaBits = 0; + return; + case D3DFMT_R5G6B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 6; + *cBlueBits = 5; + *cAlphaBits = 0; + return; + case D3DFMT_X8R8G8B8: + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 0; + return; + case D3DFMT_A8R8G8B8: + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 8; + return; + } + + // Should not get here! + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 0; +} + +//--------------------------------------------------------------------------- + +static void _BitsFromDepthStencilFormat( + D3DFORMAT fmt, + BYTE *cDepthBits, + BYTE *cStencilBits) +{ + // NOTE: GL expects either 32 or 16 as depth bits. + switch (fmt) { + case D3DFMT_D32: + *cDepthBits = 32; + *cStencilBits = 0; + return; + case D3DFMT_D15S1: + *cDepthBits = 16; + *cStencilBits = 1; + return; + case D3DFMT_D24S8: + *cDepthBits = 32; + *cStencilBits = 8; + return; + case D3DFMT_D16: + *cDepthBits = 16; + *cStencilBits = 0; + return; + case D3DFMT_D24X8: + *cDepthBits = 32; + *cStencilBits = 0; + return; + case D3DFMT_D24X4S4: + *cDepthBits = 32; + *cStencilBits = 4; + return; + } +} + +//--------------------------------------------------------------------------- + +BOOL gldBuildPixelformatList_DX(void) +{ + D3DDISPLAYMODE d3ddm; + D3DFORMAT fmt[6]; + IDirect3D9 *pD3D = NULL; + HRESULT hr; + int nSupportedFormats = 0; + int i; + DGL_pixelFormat *pPF; + BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; +// char buf[128]; +// char cat[8]; + + // Direct3D (SW or HW) + // These are arranged so that 'best' pixelformat + // is higher in the list (for ChoosePixelFormat). + const D3DFORMAT DepthStencil[6] = { +// New order: increaing Z, then increasing stencil + D3DFMT_D15S1, + D3DFMT_D16, + D3DFMT_D24X4S4, + D3DFMT_D24X8, + D3DFMT_D24S8, + D3DFMT_D32, + }; + + // Dump DX version + ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 9.0\n"); + + // Release any existing pixelformat list + if (glb.lpPF) { + free(glb.lpPF); + } + + glb.nPixelFormatCount = 0; + glb.lpPF = NULL; + + // + // Pixelformats for Direct3D (SW or HW) rendering + // + + // Get a Direct3D 9.0 interface + pD3D = dx9Globals.fnDirect3DCreate9(D3D_SDK_VERSION); + if (!pD3D) { + return FALSE; + } + + // We will use the display mode format when finding compliant + // rendertarget/depth-stencil surfaces. + hr = IDirect3D9_GetAdapterDisplayMode(pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hr)) { + IDirect3D9_Release(pD3D); + return FALSE; + } + + // Run through the possible formats and detect supported formats + for (i=0; i<6; i++) { + hr = IDirect3D9_CheckDeviceFormat( + pD3D, + glb.dwAdapter, + glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, + d3ddm.Format, + D3DUSAGE_DEPTHSTENCIL, + D3DRTYPE_SURFACE, + DepthStencil[i]); + if (FAILED(hr)) + // A failure here is not fatal. + continue; + + // Verify that the depth format is compatible. + hr = IDirect3D9_CheckDepthStencilMatch( + pD3D, + glb.dwAdapter, + glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, + d3ddm.Format, + d3ddm.Format, + DepthStencil[i]); + if (FAILED(hr)) + // A failure here is not fatal, just means depth-stencil + // format is not compatible with this display mode. + continue; + + fmt[nSupportedFormats++] = DepthStencil[i]; + } + + IDirect3D9_Release(pD3D); + + if (nSupportedFormats == 0) + return FALSE; // Bail: no compliant pixelformats + + // Total count of pixelformats is: + // (nSupportedFormats+1)*2 + // UPDATED: nSupportedFormats*2 + glb.lpPF = (DGL_pixelFormat *)calloc(nSupportedFormats*2, sizeof(DGL_pixelFormat)); + glb.nPixelFormatCount = nSupportedFormats*2; + if (glb.lpPF == NULL) { + glb.nPixelFormatCount = 0; + return FALSE; + } + + // Get a copy of pointer that we can alter + pPF = glb.lpPF; + + // Cache colour bits from display format + _BitsFromDisplayFormat(d3ddm.Format, &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); + + // + // Add single-buffer formats + // +/* + // NOTE: No longer returning pixelformats that don't contain depth + // Single-buffer, no depth-stencil buffer + memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); + pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + pPF->pfd.cDepthBits = 0; + pPF->pfd.cStencilBits = 0; + pPF->dwDriverData = D3DFMT_UNKNOWN; + pPF++; +*/ + for (i=0; ipfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); + pPF->dwDriverData = fmt[i]; + } + + // + // Add double-buffer formats + // + + // NOTE: No longer returning pixelformats that don't contain depth +/* + memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + pPF->pfd.cDepthBits = 0; + pPF->pfd.cStencilBits = 0; + pPF->dwDriverData = D3DFMT_UNKNOWN; + pPF++; +*/ + for (i=0; ipfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); + pPF->dwDriverData = fmt[i]; + } + + // Popup warning message if non RGB color mode + { + // This is a hack. KeithH + HDC hdcDesktop = GetDC(NULL); + DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); + ReleaseDC(0, hdcDesktop); + if (dwDisplayBitDepth <= 8) { + ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); + MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); + } + } + + // Mark list as 'current' + glb.bPixelformatsDirty = FALSE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldInitialiseMesa_DX( + DGL_ctx *lpCtx) +{ + GLD_driver_dx9 *gld = NULL; + int MaxTextureSize, TextureLevels; + BOOL bSoftwareTnL; + + if (lpCtx == NULL) + return FALSE; + + gld = lpCtx->glPriv; + if (gld == NULL) + return FALSE; + + if (glb.bMultitexture) { + lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps9.MaxSimultaneousTextures; + // Only support MAX_TEXTURE_UNITS texture units. + // ** If this is altered then the FVF formats must be reviewed **. + if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX9) + lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX9; + } else { + // Multitexture override + lpCtx->glCtx->Const.MaxTextureUnits = 1; + } + + // max texture size + MaxTextureSize = min(gld->d3dCaps9.MaxTextureHeight, gld->d3dCaps9.MaxTextureWidth); + if (MaxTextureSize == 0) + MaxTextureSize = 256; // Sanity check + + // + // HACK!! + if (MaxTextureSize > 1024) + MaxTextureSize = 1024; // HACK - CLAMP TO 1024 + // HACK!! + // + + // Got to set MAX_TEXTURE_SIZE as max levels. + // Who thought this stupid idea up? ;) + TextureLevels = 0; + // Calculate power-of-two. + while (MaxTextureSize) { + TextureLevels++; + MaxTextureSize >>= 1; + } + lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8; + + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_LIGHTING, FALSE); + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_DITHERENABLE, TRUE); + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); + + IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_ZENABLE, + (lpCtx->lpPF->dwDriverData!=D3DFMT_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE); + + // Set the view matrix + { + D3DXMATRIX vm; +#if 1 + D3DXMatrixIdentity(&vm); +#else + D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f); + D3DXVECTOR3 At(0.0f, 0.0f, -1.0f); + D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); + D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up); + vm._31 = -vm._31; + vm._32 = -vm._32; + vm._33 = -vm._33; + vm._34 = -vm._34; +#endif + IDirect3DDevice9_SetTransform(gld->pDev, D3DTS_VIEW, &vm); + } + + if (gld->bHasHWTnL) { + if (glb.dwTnL == GLDS_TNL_DEFAULT) + bSoftwareTnL = FALSE; // HW TnL + else { + bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE; + } + } else { + // No HW TnL, so no choice possible + bSoftwareTnL = TRUE; + } +// IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL); + IDirect3DDevice9_SetSoftwareVertexProcessing(gld->pDev, bSoftwareTnL); + +// Dump this in a Release build as well, now. +//#ifdef _DEBUG + ddlogPrintf(DDLOG_INFO, "HW TnL: %s", + gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable"); +//#endif + + gldEnableExtensions_DX9(lpCtx->glCtx); + gldInstallPipeline_DX9(lpCtx->glCtx); + gldSetupDriverPointers_DX9(lpCtx->glCtx); + + // Signal a complete state update + lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL); + + // Start a scene + IDirect3DDevice9_BeginScene(gld->pDev); + lpCtx->bSceneStarted = TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldSwapBuffers_DX( + DGL_ctx *ctx, + HDC hDC, + HWND hWnd) +{ + HRESULT hr; + GLD_driver_dx9 *gld = NULL; + + if (ctx == NULL) + return FALSE; + + gld = ctx->glPriv; + if (gld == NULL) + return FALSE; + + if (ctx->bSceneStarted) { + IDirect3DDevice9_EndScene(gld->pDev); + ctx->bSceneStarted = FALSE; + } + + // Swap the buffers. hWnd may override the hWnd used for CreateDevice() + hr = IDirect3DDevice9_Present(gld->pDev, NULL, NULL, hWnd, NULL); + +exit_swap: + + IDirect3DDevice9_BeginScene(gld->pDev); + ctx->bSceneStarted = TRUE; + +// Debugging code +#ifdef _DEBUG +// ddlogMessage(GLDLOG_WARN, "SwapBuffers\n"); +#endif + + return (FAILED(hr)) ? FALSE : TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldGetDisplayMode_DX( + DGL_ctx *ctx, + GLD_displayMode *glddm) +{ + D3DDISPLAYMODE d3ddm; + HRESULT hr; + GLD_driver_dx9 *lpCtx = NULL; + BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; + + if ((glddm == NULL) || (ctx == NULL)) + return FALSE; + + lpCtx = ctx->glPriv; + if (lpCtx == NULL) + return FALSE; + + if (lpCtx->pD3D == NULL) + return FALSE; + + hr = IDirect3D9_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hr)) + return FALSE; + + // Get info from the display format + _BitsFromDisplayFormat(d3ddm.Format, + &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); + + glddm->Width = d3ddm.Width; + glddm->Height = d3ddm.Height; + glddm->BPP = cColorBits; + glddm->Refresh = d3ddm.RefreshRate; + + return TRUE; +} + +//--------------------------------------------------------------------------- + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/mesasw/colors.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/mesasw/colors.h @@ -0,0 +1,523 @@ +/* File name : colors.h + * Version : 2.3 + * + * Header file for display driver for Mesa 2.3 under + * Windows95 and WindowsNT + * This file defines macros and global variables needed + * for converting color format + * + * Copyright (C) 1996- Li Wei + * Address : Institute of Artificial Intelligence + * : & Robotics + * : Xi'an Jiaotong University + * Email : liwei@aiar.xjtu.edu.cn + * Web page : http://sun.aiar.xjtu.edu.cn + * + * This file and its associations are partially based on the + * Windows NT driver for Mesa, written by Mark Leaming + * (mark@rsinc.com). + */ + +/* $Log: ddcolors.h 1997/6/14 by Li Wei(liwei@aiar.xjtu.edu.cn) + * Macros for pixel format defined + */ + +/* + * $Log: colors.h,v $ + * Revision 1.1 2004/04/20 11:13:11 alanh + * add SciTech's GLDirect driver for Windows. + * + * This code is donated to Mesa which allows the usage of + * a Direct3D layer (DX7, DX8, DX9 or complete software fallback). + * + * No build system exists for this code yet, that will come..... + * + * Revision 1.1.1.1 1999/08/19 00:55:42 jtg + * Imported sources + * + * Revision 1.2 1999/01/03 03:08:57 brianp + * Ted Jump's changes + * + * Revision 1.1 1999/01/03 03:08:12 brianp + * Initial revision + * + * Revision 2.0.2 1997/4/30 15:58:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn) + * Add LUTs need for dithering + */ + +/* + * $Log: colors.h,v $ + * Revision 1.1 2004/04/20 11:13:11 alanh + * add SciTech's GLDirect driver for Windows. + * + * This code is donated to Mesa which allows the usage of + * a Direct3D layer (DX7, DX8, DX9 or complete software fallback). + * + * No build system exists for this code yet, that will come..... + * + * Revision 1.1.1.1 1999/08/19 00:55:42 jtg + * Imported sources + * + * Revision 1.2 1999/01/03 03:08:57 brianp + * Ted Jump's changes + * + * Revision 1.1 1999/01/03 03:08:12 brianp + * Initial revision + * + * Revision 2.0.1 1997/4/29 15:52:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn) + * Add BGR8 Macro + */ + +/* + * $Log: colors.h,v $ + * Revision 1.1 2004/04/20 11:13:11 alanh + * add SciTech's GLDirect driver for Windows. + * + * This code is donated to Mesa which allows the usage of + * a Direct3D layer (DX7, DX8, DX9 or complete software fallback). + * + * No build system exists for this code yet, that will come..... + * + * Revision 1.1.1.1 1999/08/19 00:55:42 jtg + * Imported sources + * + * Revision 1.2 1999/01/03 03:08:57 brianp + * Ted Jump's changes + * + * Revision 1.1 1999/01/03 03:08:12 brianp + * Initial revision + * + * Revision 2.0 1996/11/15 10:55:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn) + * Initial revision + */ +/* Values for wmesa->pixelformat: */ + +#define PF_8A8B8G8R 3 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */ +#define PF_8R8G8B 4 /* 32-bit TrueColor: 8-R, 8-G, 8-B */ +#define PF_5R6G5B 5 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */ +#define PF_DITHER8 6 /* Dithered RGB using a lookup table */ +#define PF_LOOKUP 7 /* Undithered RGB using a lookup table */ +#define PF_GRAYSCALE 10 /* Grayscale or StaticGray */ +#define PF_BADFORMAT 11 +#define PF_INDEX8 12 + +char ColorMap16[] = { +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, +0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, +0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04, +0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05, +0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06, +0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07, +0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08, +0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09, +0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A, +0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, +0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C, +0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D, +0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E, +0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, +0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, +0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, +0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, +0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13, +0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14, +0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, +0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, +0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17, +0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, +0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19, +0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A, +0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B, +0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C, +0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D, +0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, +0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; + +#define BGR8(r,g,b) (unsigned)(((BYTE)(b & 0xc0 | (g & 0xe0)>>2 | (r & 0xe0)>>5))) +#ifdef DDRAW +#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11))) +#else +#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10))) +#endif +#define BGR24(r,g,b) (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) << 8) +#define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) + + + +/* + * If pixelformat==PF_8A8B8G8R: + */ +#define PACK_8A8B8G8R( R, G, B, A ) \ + ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) ) + + +/* + * If pixelformat==PF_8R8G8B: + */ +#define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) ) + + +/* + * If pixelformat==PF_5R6G5B: + */ + + +#ifdef DDRAW +#define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11))) +#else +#define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(ColorMap16[G]) << 5)) | (((WORD)(BYTE)(ColorMap16[R])) << 10))) +#endif +/*---------------------------------------------------------------------------- + +Division lookup tables. These tables compute 0-255 divided by 51 and +modulo 51. These tables could approximate gamma correction. + +*/ + +char unsigned const aDividedBy51Rounded[256] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +}; + +char unsigned const aDividedBy51[256] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, +}; + +char unsigned const aModulo51[256] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, +}; + +/*---------------------------------------------------------------------------- + +Multiplication LUTs. These compute 0-5 times 6 and 36. + +*/ + +char unsigned const aTimes6[6] = +{ + 0, 6, 12, 18, 24, 30 +}; + +char unsigned const aTimes36[6] = +{ + 0, 36, 72, 108, 144, 180 +}; + + +/*---------------------------------------------------------------------------- + +Dither matrices for 8 bit to 2.6 bit halftones. + +*/ + +char unsigned const aHalftone16x16[256] = +{ + 0, 44, 9, 41, 3, 46, 12, 43, 1, 44, 10, 41, 3, 46, 12, 43, + 34, 16, 25, 19, 37, 18, 28, 21, 35, 16, 26, 19, 37, 18, 28, 21, + 38, 6, 47, 3, 40, 9, 50, 6, 38, 7, 47, 4, 40, 9, 49, 6, + 22, 28, 13, 31, 25, 31, 15, 34, 22, 29, 13, 32, 24, 31, 15, 34, + 2, 46, 12, 43, 1, 45, 10, 42, 2, 45, 11, 42, 1, 45, 11, 42, + 37, 18, 27, 21, 35, 17, 26, 20, 36, 17, 27, 20, 36, 17, 26, 20, + 40, 8, 49, 5, 38, 7, 48, 4, 39, 8, 48, 5, 39, 7, 48, 4, + 24, 30, 15, 33, 23, 29, 13, 32, 23, 30, 14, 33, 23, 29, 14, 32, + 2, 46, 12, 43, 0, 44, 10, 41, 3, 47, 12, 44, 0, 44, 10, 41, + 37, 18, 27, 21, 35, 16, 25, 19, 37, 19, 28, 22, 35, 16, 25, 19, + 40, 9, 49, 5, 38, 7, 47, 4, 40, 9, 50, 6, 38, 6, 47, 3, + 24, 30, 15, 34, 22, 29, 13, 32, 25, 31, 15, 34, 22, 28, 13, 31, + 1, 45, 11, 42, 2, 46, 11, 42, 1, 45, 10, 41, 2, 46, 11, 43, + 36, 17, 26, 20, 36, 17, 27, 21, 35, 16, 26, 20, 36, 18, 27, 21, + 39, 8, 48, 4, 39, 8, 49, 5, 38, 7, 48, 4, 39, 8, 49, 5, + 23, 29, 14, 33, 24, 30, 14, 33, 23, 29, 13, 32, 24, 30, 14, 33, +}; + +char unsigned const aHalftone8x8[64] = +{ + 0, 38, 9, 47, 2, 40, 11, 50, + 25, 12, 35, 22, 27, 15, 37, 24, + 6, 44, 3, 41, 8, 47, 5, 43, + 31, 19, 28, 15, 34, 21, 31, 18, + 1, 39, 11, 49, 0, 39, 10, 48, + 27, 14, 36, 23, 26, 13, 35, 23, + 7, 46, 4, 43, 7, 45, 3, 42, + 33, 20, 30, 17, 32, 19, 29, 16, +}; + +char unsigned const aHalftone4x4_1[16] = +{ + 0, 25, 6, 31, + 38, 12, 44, 19, + 9, 35, 3, 28, + 47, 22, 41, 15 +}; + +char unsigned const aHalftone4x4_2[16] = +{ + 41, 3, 9, 28, + 35, 15, 22, 47, + 6, 25, 38, 0, + 19, 44, 31, 12 +}; + +/*************************************************************************** + aWinGHalftoneTranslation + + Translates a 2.6 bit-per-pixel halftoned representation into the + slightly rearranged WinG Halftone Palette. +*/ + +char unsigned const aWinGHalftoneTranslation[216] = +{ + 0, + 29, + 30, + 31, + 32, + 249, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 250, + 250, + 57, + 58, + 59, + 251, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 250, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 227, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 151, + 120, + 121, + 122, + 123, + 124, + 228, + 125, + 126, + 229, + 133, + 162, + 135, + 131, + 132, + 137, + 166, + 134, + 140, + 130, + 136, + 143, + 138, + 139, + 174, + 141, + 142, + 177, + 129, + 144, + 145, + 146, + 147, + 148, + 149, + 150, + 157, + 152, + 153, + 154, + 155, + 156, + 192, + 158, + 159, + 160, + 161, + 196, + 163, + 164, + 165, + 127, + 199, + 167, + 168, + 169, + 170, + 171, + 172, + 173, + 207, + 175, + 176, + 210, + 178, + 179, + 180, + 181, + 182, + 183, + 184, + 185, + 186, + 187, + 188, + 189, + 190, + 191, + 224, + 193, + 194, + 195, + 252, + 252, + 197, + 198, + 128, + 253, + 252, + 200, + 201, + 202, + 203, + 204, + 205, + 206, + 230, + 208, + 209, + 231, + 211, + 212, + 213, + 214, + 215, + 216, + 217, + 218, + 219, + 220, + 221, + 222, + 254, + 223, + 232, + 225, + 226, + 255, +}; \ No newline at end of file --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c @@ -0,0 +1,1719 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Mesa Software WGL (WindowsGL) +* +****************************************************************************/ + +#include +#define GL_GLEXT_PROTOTYPES +#include +#include + +#include "glheader.h" +#include "colors.h" +#include "context.h" +#include "colormac.h" +#include "dd.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "teximage.h" +#include "vbo/vbo.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast/s_context.h" +#include "swrast/s_depth.h" +#include "swrast/s_lines.h" +#include "swrast/s_triangle.h" +#include "swrast/s_trispan.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "dglcontext.h" +#include "gld_driver.h" + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +DGL_pixelFormat pfTemplateMesaSW = +{ + { + sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure + 1, // Structure version - should be 1 + // Flags: + PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. + PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) + PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) + PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. + PFD_DOUBLEBUFFER | // The buffer is double-buffered. + 0, // Placeholder for easy commenting of above flags + PFD_TYPE_RGBA, // Pixel type RGBA. + 32, // Total colour bitplanes (excluding alpha bitplanes) + 8, 0, // Red bits, shift + 8, 8, // Green bits, shift + 8, 16, // Blue bits, shift + 8, 24, // Alpha bits, shift (destination alpha) + 64, // Accumulator bits (total) + 16, 16, 16, 16, // Accumulator bits: Red, Green, Blue, Alpha + 16, // Depth bits + 8, // Stencil bits + 0, // Number of auxiliary buffers + 0, // Layer type + 0, // Specifies the number of overlay and underlay planes. + 0, // Layer mask + 0, // Specifies the transparent color or index of an underlay plane. + 0 // Damage mask + }, + 0, // Unused +}; + +//--------------------------------------------------------------------------- +// Extensions +//--------------------------------------------------------------------------- + +typedef struct { + PROC proc; + char *name; +} GLD_extension; + +static GLD_extension GLD_extList[] = { +#ifdef GL_EXT_polygon_offset + { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, +#endif + { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, + { (PROC)glBlendColorEXT, "glBlendColorExt" }, + { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, + { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, + { (PROC)glColorPointerEXT, "glColorPointerEXT" }, + { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, + { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, + { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, + { (PROC)glGetPointervEXT, "glGetPointervEXT" }, + { (PROC)glArrayElementEXT, "glArrayElementEXT" }, + { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, + { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, + { (PROC)glBindTextureEXT, "glBindTextureEXT" }, + { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, + { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, + { (PROC)glIsTextureEXT, "glIsTextureEXT" }, + { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, + { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, + { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, + { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, + { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, + { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, + { (PROC)glLockArraysEXT, "glLockArraysEXT" }, + { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, + { NULL, "\0" } +}; + +//--------------------------------------------------------------------------- +// WMesa Internal Functions +//--------------------------------------------------------------------------- + +#define PAGE_FILE 0xffffffff + +#define REDBITS 0x03 +#define REDSHIFT 0x00 +#define GREENBITS 0x03 +#define GREENSHIFT 0x03 +#define BLUEBITS 0x02 +#define BLUESHIFT 0x06 + +typedef struct _dibSection { + HDC hDC; + HANDLE hFileMap; + BOOL fFlushed; + LPVOID base; +} WMDIBSECTION, *PWMDIBSECTION; + +typedef struct wmesa_context { + HWND Window; + HDC hDC; + HPALETTE hPalette; + HPALETTE hOldPalette; + HPEN hPen; + HPEN hOldPen; + HCURSOR hOldCursor; + COLORREF crColor; + // 3D projection stuff + RECT drawRect; + UINT uiDIBoffset; + // OpenGL stuff + HPALETTE hGLPalette; + GLuint width; + GLuint height; + GLuint ScanWidth; + GLboolean db_flag; //* double buffered? + GLboolean rgb_flag; //* RGB mode? + GLboolean dither_flag; //* use dither when 256 color mode for RGB? + GLuint depth; //* bits per pixel (1, 8, 24, etc) + ULONG pixel; // current color index or RGBA pixel value + ULONG clearpixel; //* pixel for clearing the color buffers + PBYTE ScreenMem; // WinG memory + BITMAPINFO *IndexFormat; + HPALETTE hPal; // Current Palette + HPALETTE hPalHalfTone; + + + WMDIBSECTION dib; + BITMAPINFO bmi; + HBITMAP hbmDIB; + HBITMAP hOldBitmap; + HBITMAP Old_Compat_BM; + HBITMAP Compat_BM; // Bitmap for double buffering + PBYTE pbPixels; + int nColors; + BYTE cColorBits; + int pixelformat; + + RECT rectOffScreen; + RECT rectSurface; +// HWND hwnd; + DWORD pitch; + PBYTE addrOffScreen; + + // We always double-buffer, for performance reasons, but + // we need to know which of SwapBuffers() or glFlush() to + // handle. If we're emulating, then we update on Flush(), + // otherwise we update on SwapBufers(). KeithH + BOOL bEmulateSingleBuffer; +} WMesaContext, *PWMC; + +#define GLD_GET_WMESA_DRIVER(c) (WMesaContext*)(c)->glPriv + +// TODO: +GLint stereo_flag = 0 ; + +/* If we are double-buffering, we want to get the DC for the + * off-screen DIB, otherwise the DC for the window. + */ +#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC ) +#define DD_RELEASEDC + +#define FLIP(Y) (Current->height-(Y)-1) + +struct DISPLAY_OPTIONS { + int stereo; + int fullScreen; + int mode; + int bpp; +}; + +struct DISPLAY_OPTIONS displayOptions; + +//--------------------------------------------------------------------------- + +static unsigned char threeto8[8] = { + 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377 +}; + +static unsigned char twoto8[4] = { + 0, 0x55, 0xaa, 0xff +}; + +static unsigned char oneto8[2] = { + 0, 255 +}; + +//--------------------------------------------------------------------------- + +BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline) +{ + char unsigned redtemp, greentemp, bluetemp, paletteindex; + + //*** now, look up each value in the halftone matrix + //*** using an 8x8 ordered dither. + redtemp = aDividedBy51[red] + + (aModulo51[red] > aHalftone8x8[(pixel%8)*8 + + scanline%8]); + greentemp = aDividedBy51[(char unsigned)green] + + (aModulo51[green] > aHalftone8x8[ + (pixel%8)*8 + scanline%8]); + bluetemp = aDividedBy51[(char unsigned)blue] + + (aModulo51[blue] > aHalftone8x8[ + (pixel%8)*8 +scanline%8]); + + //*** recombine the halftoned rgb values into a palette index + paletteindex = + redtemp + aTimes6[greentemp] + aTimes36[bluetemp]; + + //*** and translate through the wing halftone palette + //*** translation vector to give the correct value. + return aWinGHalftoneTranslation[paletteindex]; +} + +//--------------------------------------------------------------------------- + +static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift) +{ + unsigned char val; + + val = i >> shift; + switch (nbits) { + + case 1: + val &= 0x1; + return oneto8[val]; + + case 2: + val &= 0x3; + return twoto8[val]; + + case 3: + val &= 0x7; + return threeto8[val]; + + default: + return 0; + } +} + +//--------------------------------------------------------------------------- + + +void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b) +{ + WMesaContext *Current = pwc; + + // Test for invalid scanline parameter. KeithH + if ((iScanLine < 0) || (iScanLine >= pwc->height)) + return; + + if (Current->db_flag) { + LPBYTE lpb = pwc->pbPixels; + UINT nBypp = pwc->cColorBits >> 3; + UINT nOffset = iPixel % nBypp; + + lpb += pwc->ScanWidth * iScanLine; + lpb += iPixel * nBypp; + + if(nBypp == 1){ + if(pwc->dither_flag) + *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel); + else + *lpb = BGR8(r,g,b); + } + else if(nBypp == 2) + *((LPWORD)lpb) = BGR16(r,g,b); + else if (nBypp == 3) + *((LPDWORD)lpb) = BGR24(r,g,b); + else if (nBypp == 4) + *((LPDWORD)lpb) = BGR32(r,g,b); + } + else{ + SetPixel(Current->hDC, iPixel, iScanLine, RGB(r,g,b)); + } +} + +//--------------------------------------------------------------------------- + +void wmCreateDIBSection( + HDC hDC, + PWMC pwc, // handle of device context + CONST BITMAPINFO *pbmi, // bitmap size, format, and color data + UINT iUsage // color data type indicator: RGB values or palette indices + ) +{ + DWORD dwSize = 0; + DWORD dwScanWidth; + UINT nBypp = pwc->cColorBits / 8; + HDC hic; + + dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3); + + pwc->ScanWidth =pwc->pitch = dwScanWidth; + + if (stereo_flag) + pwc->ScanWidth = 2* pwc->pitch; + + dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height); + + pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE, + NULL, + PAGE_READWRITE | SEC_COMMIT, + 0, + dwSize, + NULL); + + if (!pwc->dib.hFileMap) + return; + + pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap, + FILE_MAP_ALL_ACCESS, + 0, + 0, + 0); + + if(!pwc->dib.base){ + CloseHandle(pwc->dib.hFileMap); + return; + } + + + CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO)); + + hic = CreateIC("display", NULL, NULL, NULL); + pwc->dib.hDC = CreateCompatibleDC(hic); + + + pwc->hbmDIB = CreateDIBSection(hic, + &(pwc->bmi), + (iUsage ? DIB_PAL_COLORS : DIB_RGB_COLORS), + &(pwc->pbPixels), + pwc->dib.hFileMap, + 0); + pwc->ScreenMem = pwc->addrOffScreen = pwc->pbPixels; + pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB); + + DeleteDC(hic); + + return; + +} + +//--------------------------------------------------------------------------- + +void wmCreatePalette( PWMC pwdc ) +{ + /* Create a compressed and re-expanded 3:3:2 palette */ + int i; + LOGPALETTE *pPal; + BYTE rb, rs, gb, gs, bb, bs; + + pwdc->nColors = 0x100; + + pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + + pwdc->nColors * sizeof(PALETTEENTRY)); + memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) ); + + pPal->palVersion = 0x300; + + rb = REDBITS; + rs = REDSHIFT; + gb = GREENBITS; + gs = GREENSHIFT; + bb = BLUEBITS; + bs = BLUESHIFT; + + if (pwdc->db_flag) { + + /* Need to make two palettes: one for the screen DC and one for the DIB. */ + pPal->palNumEntries = pwdc->nColors; + for (i = 0; i < pwdc->nColors; i++) { + pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs ); + pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs ); + pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs ); + pPal->palPalEntry[i].peFlags = 0; + } + pwdc->hGLPalette = CreatePalette( pPal ); + pwdc->hPalette = CreatePalette( pPal ); + } + + else { + pPal->palNumEntries = pwdc->nColors; + for (i = 0; i < pwdc->nColors; i++) { + pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs ); + pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs ); + pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs ); + pPal->palPalEntry[i].peFlags = 0; + } + pwdc->hGLPalette = CreatePalette( pPal ); + } + + free(pPal); + +} + +//--------------------------------------------------------------------------- + +/* This function sets the color table of a DIB section + * to match that of the destination DC + */ +BOOL wmSetDibColors(PWMC pwc) +{ + RGBQUAD *pColTab, *pRGB; + PALETTEENTRY *pPal, *pPE; + int i, nColors; + BOOL bRet=TRUE; + DWORD dwErr=0; + + /* Build a color table in the DIB that maps to the + * selected palette in the DC. + */ + nColors = 1 << pwc->cColorBits; + pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY)); + memset( pPal, 0, nColors * sizeof(PALETTEENTRY) ); + GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal ); + pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD)); + for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) { + pRGB->rgbRed = pPE->peRed; + pRGB->rgbGreen = pPE->peGreen; + pRGB->rgbBlue = pPE->peBlue; + } + if(pwc->db_flag) + bRet = SetDIBColorTable(pwc->dib.hDC, 0, nColors, pColTab ); + + if(!bRet) + dwErr = GetLastError(); + + free( pColTab ); + free( pPal ); + + return bRet; +} + +//--------------------------------------------------------------------------- + +static void wmSetPixelFormat( PWMC wc, HDC hDC) +{ + if(wc->rgb_flag) + wc->cColorBits = GetDeviceCaps(hDC, BITSPIXEL); + else + wc->cColorBits = 8; + switch(wc->cColorBits){ + case 8: + if(wc->dither_flag != GL_TRUE) + wc->pixelformat = PF_INDEX8; + else + wc->pixelformat = PF_DITHER8; + break; + case 16: + wc->pixelformat = PF_5R6G5B; + break; + case 32: + wc->pixelformat = PF_8R8G8B; + break; + default: + wc->pixelformat = PF_BADFORMAT; + } +} + +//--------------------------------------------------------------------------- + +/* + * This function creates the DIB section that is used for combined + * GL and GDI calls + */ +BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize) +{ + HDC hdc = pwc->hDC; + LPBITMAPINFO pbmi = &(pwc->bmi); + int iUsage; + + pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + pbmi->bmiHeader.biWidth = lxSize; + pbmi->bmiHeader.biHeight= -lySize; + pbmi->bmiHeader.biPlanes = 1; + if(pwc->rgb_flag) + pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL); + else + pbmi->bmiHeader.biBitCount = 8; + pbmi->bmiHeader.biCompression = BI_RGB; + pbmi->bmiHeader.biSizeImage = 0; + pbmi->bmiHeader.biXPelsPerMeter = 0; + pbmi->bmiHeader.biYPelsPerMeter = 0; + pbmi->bmiHeader.biClrUsed = 0; + pbmi->bmiHeader.biClrImportant = 0; + + iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS; + + pwc->cColorBits = pbmi->bmiHeader.biBitCount; + pwc->ScanWidth = pwc->pitch = lxSize; + pwc->width = lxSize; + pwc->height = lySize; + + wmCreateDIBSection(hdc, pwc, pbmi, iUsage); + + if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) { + wmCreatePalette( pwc ); + wmSetDibColors( pwc ); + } + wmSetPixelFormat(pwc, pwc->hDC); + return TRUE; +} + +//--------------------------------------------------------------------------- + +/* + * Free up the dib section that was created + */ +BOOL wmDeleteBackingStore(PWMC pwc) +{ + SelectObject(pwc->dib.hDC, pwc->hOldBitmap); + DeleteDC(pwc->dib.hDC); + DeleteObject(pwc->hbmDIB); + UnmapViewOfFile(pwc->dib.base); + CloseHandle(pwc->dib.hFileMap); + return TRUE; +} + +//--------------------------------------------------------------------------- + +/* + * Blit memory DC to screen DC + */ +BOOL wmFlush(PWMC pwc, HDC hDC) +{ + BOOL bRet = 0; + DWORD dwErr = 0; + +// Now using bEmulateSingleBuffer in the calling function. KeithH + +// if(pwc->db_flag){ + bRet = BitBlt(hDC, 0, 0, pwc->width, pwc->height, + pwc->dib.hDC, 0, 0, SRCCOPY); +// } + + return bRet; + +} + +//--------------------------------------------------------------------------- +// Support Functions +//--------------------------------------------------------------------------- + +static void flush(GLcontext* ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); +/* + if((Current->rgb_flag &&!(Current->db_flag)) + ||(!Current->rgb_flag)) + { + wmFlush(Current, Current->hDC); + } +*/ + // Only flush if we're not in double-buffer mode. KeithH + // The demo fractal.c calls glutSwapBuffers() then glFlush()! + if (Current->bEmulateSingleBuffer) { + wmFlush(Current, Current->hDC); + } +} + + +//--------------------------------------------------------------------------- + + +/* + * Set the color index used to clear the color buffer. + */ +static void clear_index(GLcontext* ctx, GLuint index) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + Current->clearpixel = index; +} + + + +//--------------------------------------------------------------------------- + +/* + * Set the color used to clear the color buffer. + */ +//static void clear_color( GLcontext* ctx, const GLchan color[4] ) +// Changed for Mesa 5.x. KeithH +static void clear_color( + GLcontext* ctx, + const GLfloat color[4]) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + GLubyte col[4]; + CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]); + CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]); + CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]); + Current->clearpixel = RGB(col[0], col[1], col[2]); +} + + +//--------------------------------------------------------------------------- + + +/* + * Clear the specified region of the color buffer using the clear color + * or index as specified by one of the two functions above. + * + * This procedure clears either the front and/or the back COLOR buffers. + * Only the "left" buffer is cleared since we are not stereo. + * Clearing of the other non-color buffers is left to the swrast. + * We also only clear the color buffers if the color masks are all 1's. + * Otherwise, we let swrast do it. + */ + +static clear(GLcontext* ctx, GLbitfield mask, + GLboolean all, GLint x, GLint y, GLint width, GLint height) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + DWORD dwColor; + WORD wColor; + BYTE bColor; + LPDWORD lpdw = (LPDWORD)Current->pbPixels; + LPWORD lpw = (LPWORD)Current->pbPixels; + LPBYTE lpb = Current->pbPixels; + int lines; + const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; + + if (all){ + x=y=0; + width=Current->width; + height=Current->height; + } + + + /* sanity check - can't have right(stereo) buffers */ + assert((mask & (DD_FRONT_RIGHT_BIT | DD_BACK_RIGHT_BIT)) == 0); + + /* clear alpha */ + if ((mask & (DD_FRONT_LEFT_BIT | DD_BACK_RIGHT_BIT)) && + ctx->DrawBuffer->UseSoftwareAlphaBuffers && + ctx->Color.ColorMask[ACOMP]) { + _swrast_clear_alpha_buffers( ctx ); + } + + if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) { + if (mask & DD_BACK_LEFT_BIT) { + /* Double-buffering - clear back buffer */ + UINT nBypp = Current->cColorBits / 8; + int i = 0; + int iSize = 0; + + assert(Current->db_flag==GL_TRUE); /* we'd better be double buffer */ + if(nBypp ==1 ){ + iSize = Current->width/4; + bColor = BGR8(GetRValue(Current->clearpixel), + GetGValue(Current->clearpixel), + GetBValue(Current->clearpixel)); + wColor = MAKEWORD(bColor,bColor); + dwColor = MAKELONG(wColor, wColor); + } + if(nBypp == 2){ + iSize = Current->width / 2; + wColor = BGR16(GetRValue(Current->clearpixel), + GetGValue(Current->clearpixel), + GetBValue(Current->clearpixel)); + dwColor = MAKELONG(wColor, wColor); + } + else if(nBypp == 4){ + iSize = Current->width; + dwColor = BGR32(GetRValue(Current->clearpixel), + GetGValue(Current->clearpixel), + GetBValue(Current->clearpixel)); + } + + /* clear a line */ + while(i < iSize){ + *lpdw = dwColor; + lpdw++; + i++; + } + + /* This is the 24bit case */ + if (nBypp == 3) { + iSize = Current->width *3/4; + dwColor = BGR24(GetRValue(Current->clearpixel), + GetGValue(Current->clearpixel), + GetBValue(Current->clearpixel)); + while(i < iSize){ + *lpdw = dwColor; + lpb += nBypp; + lpdw = (LPDWORD)lpb; + i++; + } + } + + i = 0; + if (stereo_flag) + lines = height /2; + else + lines = height; + /* copy cleared line to other lines in buffer */ + do { + memcpy(lpb, Current->pbPixels, iSize*4); + lpb += Current->ScanWidth; + i++; + } + while (iclearpixel); + HBRUSH Brush=CreateSolidBrush(Current->clearpixel); + HPEN Old_Pen=SelectObject(DC,Pen); + HBRUSH Old_Brush=SelectObject(DC,Brush); + Rectangle(DC,x,y,x+width,y+height); + SelectObject(DC,Old_Pen); + SelectObject(DC,Old_Brush); + DeleteObject(Pen); + DeleteObject(Brush); + DD_RELEASEDC; + mask &= ~DD_FRONT_LEFT_BIT; + } /* single-buffer */ + } /* if masks are all 1's */ + + /* Call swrast if there is anything left to clear (like DEPTH) */ + if (mask) + _swrast_Clear( ctx, mask, all, x, y, width, height ); +} + + +//--------------------------------------------------------------------------- + + +static void enable( GLcontext* ctx, GLenum pname, GLboolean enable ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + + if (!Current) + return; + + if (pname == GL_DITHER) { + if(enable == GL_FALSE){ + Current->dither_flag = GL_FALSE; + if(Current->cColorBits == 8) + Current->pixelformat = PF_INDEX8; + } + else{ + if (Current->rgb_flag && Current->cColorBits == 8){ + Current->pixelformat = PF_DITHER8; + Current->dither_flag = GL_TRUE; + } + else + Current->dither_flag = GL_FALSE; + } + } +} + +//--------------------------------------------------------------------------- + +static GLboolean set_draw_buffer( GLcontext* ctx, GLenum mode ) +{ + /* TODO: this could be better */ + if (mode==GL_FRONT_LEFT || mode==GL_BACK_LEFT) { + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + +//--------------------------------------------------------------------------- + + +static void set_read_buffer(GLcontext *ctx, GLframebuffer *colorBuffer, + GLenum buffer ) +{ + /* XXX todo */ + return; +} + + +//--------------------------------------------------------------------------- + + +/* Return characteristics of the output buffer. */ +//static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height ) +// Altered for Mesa 5.x. KeithH +static void buffer_size( + GLframebuffer *buffer, + GLuint *width, + GLuint *height) +{ + // For some reason the context is not passed into this function. + // Therefore we have to explicitly retrieve it. + GET_CURRENT_CONTEXT(ctx); + + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + int New_Size; + RECT CR; + + GetClientRect(Current->Window,&CR); + + *width=CR.right; + *height=CR.bottom; + + New_Size=((*width)!=Current->width) || ((*height)!=Current->height); + + if (New_Size){ + Current->width=*width; + Current->height=*height; + Current->ScanWidth=Current->width; + if ((Current->ScanWidth%sizeof(long))!=0) + Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long))); + + if (Current->db_flag){ + if (Current->rgb_flag==GL_TRUE && Current->dither_flag!=GL_TRUE){ + wmDeleteBackingStore(Current); + wmCreateBackingStore(Current, Current->width, Current->height); + } + } + + } +} + + + +/**********************************************************************/ +/***** Accelerated point, line, polygon rendering *****/ +/**********************************************************************/ + +/* Accelerated routines are not implemented in 4.0. See OSMesa for ideas. */ + +static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last ) +{ +} + +//--------------------------------------------------------------------------- + +/* Return pointer to accelerated points function */ +extern tnl_points_func choose_points_function( GLcontext* ctx ) +{ + return NULL; +} + +//--------------------------------------------------------------------------- + +static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, + GLuint v1, GLuint pv ) +{ +} + +//--------------------------------------------------------------------------- + +static tnl_line_func choose_line_function( GLcontext* ctx ) +{ +} + + +/**********************************************************************/ +/***** Span-based pixel drawing *****/ +/**********************************************************************/ + + +/* Write a horizontal span of 32-bit color-index pixels with a boolean mask. */ +static void write_ci32_span( const GLcontext* ctx, + GLuint n, GLint x, GLint y, + const GLuint index[], + const GLubyte mask[] ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + GLuint i; + PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x; + assert(Current->rgb_flag==GL_FALSE); + for (i=0; iScreenMem+FLIP(y)*Current->ScanWidth+x; + assert(Current->rgb_flag==GL_FALSE); + for (i=0; iScreenMem+FLIP(y)*Current->ScanWidth+x; + assert(Current->rgb_flag==GL_FALSE); + for (i=0; irgb_flag==GL_TRUE) + { + GLuint i; + HDC DC=DD_GETDC; + y=FLIP(y); + if (mask) { + for (i=0; iScreenMem+y*Current->ScanWidth+x; + y = FLIP(y); + if (mask) { + for (i=0; ihPal, + RGB(rgba[i][RCOMP], + rgba[i][GCOMP], + rgba[i][BCOMP])); + } + else { + for (i=0; ihPal, + RGB(rgba[i][RCOMP], + rgba[i][GCOMP], + rgba[i][BCOMP])); + } + } +} + +//--------------------------------------------------------------------------- + +/* Write a horizontal span of RGB color pixels with a boolean mask. */ +static void write_rgb_span( const GLcontext* ctx, + GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], const GLubyte mask[] ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + PWMC pwc = Current; + + if (pwc->rgb_flag==GL_TRUE) + { + GLuint i; + HDC DC=DD_GETDC; + y=FLIP(y); + if (mask) { + for (i=0; iScreenMem+y*Current->ScanWidth+x; + y = FLIP(y); + if (mask) { + for (i=0; ihPal, + RGB(rgb[i][RCOMP], + rgb[i][GCOMP], + rgb[i][BCOMP])); + } + else { + for (i=0; ihPal, + RGB(rgb[i][RCOMP], + rgb[i][GCOMP], + rgb[i][BCOMP])); + } + } +} + +//--------------------------------------------------------------------------- + +/* + * Write a horizontal span of pixels with a boolean mask. The current color + * is used for all pixels. + */ +static void write_mono_rgba_span( const GLcontext* ctx, + GLuint n, GLint x, GLint y, + const GLchan color[4], const GLubyte mask[]) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + ULONG pixel = RGB( color[RCOMP], color[GCOMP], color[BCOMP] ); + GLuint i; + HDC DC=DD_GETDC; + PWMC pwc = Current; + assert(Current->rgb_flag==GL_TRUE); + y=FLIP(y); + if(Current->rgb_flag==GL_TRUE){ + for (i=0; irgb_flag==GL_FALSE); + for (i=0; iScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]; + *Mem = index[i]; + } + } +} + + +//--------------------------------------------------------------------------- + + +/* + * Write an array of pixels with a boolean mask. The current color + * index is used for all pixels. + */ +static void write_mono_ci_pixels( const GLcontext* ctx, + GLuint n, + const GLint x[], const GLint y[], + GLuint colorIndex, const GLubyte mask[] ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + GLuint i; + assert(Current->rgb_flag==GL_FALSE); + for (i=0; iScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]; + *Mem = colorIndex; + } + } +} + + +//--------------------------------------------------------------------------- + + +/* Write an array of RGBA pixels with a boolean mask. */ +static void write_rgba_pixels( const GLcontext* ctx, + GLuint n, const GLint x[], const GLint y[], + const GLubyte rgba[][4], const GLubyte mask[] ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + GLuint i; + PWMC pwc = Current; + HDC DC=DD_GETDC; + assert(Current->rgb_flag==GL_TRUE); + for (i=0; irgb_flag==GL_TRUE); + for (i=0; iScreenMem+FLIP(y)*Current->ScanWidth+x; + assert(Current->rgb_flag==GL_FALSE); + for (i=0; irgb_flag==GL_FALSE); + for (i=0; iScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]); + } + } +} + +//--------------------------------------------------------------------------- + +/* Read a horizontal span of color pixels. */ +static void read_rgba_span( const GLcontext* ctx, + GLuint n, GLint x, GLint y, + GLubyte rgba[][4] ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx); + UINT i; + COLORREF Color; + HDC DC=DD_GETDC; + assert(Current->rgb_flag==GL_TRUE); + y = Current->height - y - 1; + for (i=0; irgb_flag==GL_TRUE); + for (i=0; iheight - y[i] - 1; + Color=GetPixel(DC,x[i],y2); + rgba[i][RCOMP] = GetRValue(Color); + rgba[i][GCOMP] = GetGValue(Color); + rgba[i][BCOMP] = GetBValue(Color); + rgba[i][ACOMP] = 255; + } + } + DD_RELEASEDC; +} + +//--------------------------------------------------------------------------- + +static void wmesa_update_state( + GLcontext *ctx, + GLuint new_state) +{ + _swrast_InvalidateState( ctx, new_state ); + _swsetup_InvalidateState( ctx, new_state ); + _vbo_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); +} + +//--------------------------------------------------------------------------- + +static void wmesa_viewport( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei w, + GLsizei h) +{ +// ctx->Driver.ResizeBuffersMESA(ctx); +} + +//--------------------------------------------------------------------------- + +static void wmesa_update_state_first_time( + GLcontext *ctx, + GLuint new_state) +{ + struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference( ctx ); + TNLcontext *tnl = TNL_CONTEXT(ctx); + + /* + * XXX these function pointers could be initialized just once during + * context creation since they don't depend on any state changes. + * kws - This is true - this function gets called a lot and it + * would be good to minimize setting all this when not needed. + */ + // Good idea, so I'll do it. KeithH. :-) + + ctx->Driver.GetString = _gldGetStringGeneric; + ctx->Driver.UpdateState = wmesa_update_state; + ctx->Driver.DrawBuffer = set_draw_buffer; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; + ctx->Driver.GetBufferSize = buffer_size; + + ctx->Driver.Viewport = wmesa_viewport; + + ctx->Driver.Accum = _swrast_Accum; + ctx->Driver.Bitmap = _swrast_Bitmap; + ctx->Driver.Clear = clear; + + ctx->Driver.Flush = flush; + ctx->Driver.ClearIndex = clear_index; + ctx->Driver.ClearColor = clear_color; + ctx->Driver.Enable = enable; + + ctx->Driver.CopyPixels = _swrast_CopyPixels; + ctx->Driver.DrawPixels = _swrast_DrawPixels; + ctx->Driver.ReadPixels = _swrast_ReadPixels; + + ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; + ctx->Driver.TexImage1D = _mesa_store_teximage1d; + ctx->Driver.TexImage2D = _mesa_store_teximage2d; + ctx->Driver.TexImage3D = _mesa_store_teximage3d; + ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; + ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; + ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; + + ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; + ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; + ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; + ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; + ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; + ctx->Driver.CopyColorTable = _swrast_CopyColorTable; + ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; + ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; + ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; + + // Does not apply for Mesa 5.x + //ctx->Driver.BaseCompressedTexFormat = _mesa_base_compressed_texformat; + //ctx->Driver.CompressedTextureSize = _mesa_compressed_texture_size; + //ctx->Driver.GetCompressedTexImage = _mesa_get_compressed_teximage; + + swdd->SetBuffer = set_read_buffer; + + + /* Pixel/span writing functions: */ + swdd->WriteRGBASpan = write_rgba_span; + swdd->WriteRGBSpan = write_rgb_span; + swdd->WriteMonoRGBASpan = write_mono_rgba_span; + swdd->WriteRGBAPixels = write_rgba_pixels; + swdd->WriteMonoRGBAPixels = write_mono_rgba_pixels; + swdd->WriteCI32Span = write_ci32_span; + swdd->WriteCI8Span = write_ci8_span; + swdd->WriteMonoCISpan = write_mono_ci_span; + swdd->WriteCI32Pixels = write_ci32_pixels; + swdd->WriteMonoCIPixels = write_mono_ci_pixels; + + swdd->ReadCI32Span = read_ci32_span; + swdd->ReadRGBASpan = read_rgba_span; + swdd->ReadCI32Pixels = read_ci32_pixels; + swdd->ReadRGBAPixels = read_rgba_pixels; + + + tnl->Driver.RunPipeline = _tnl_run_pipeline; + + wmesa_update_state(ctx, new_state); +} + +//--------------------------------------------------------------------------- +// Driver interface functions +//--------------------------------------------------------------------------- + +BOOL gldCreateDrawable_MesaSW( + DGL_ctx *pCtx, + BOOL bPersistantInterface, + BOOL bPersistantBuffers) +{ + WMesaContext *c; + GLboolean true_color_flag; + GLboolean rgb_flag = GL_TRUE; + GLboolean db_flag = GL_TRUE; + + if (pCtx == NULL) + return FALSE; + + c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context)); + if (!c) + return FALSE; + + pCtx->glPriv = c; + + c->hDC = pCtx->hDC; + c->Window = pCtx->hWnd; + + true_color_flag = GetDeviceCaps(pCtx->hDC, BITSPIXEL) > 8; + + +#ifdef DITHER + if ((true_color_flag==GL_FALSE) && (rgb_flag == GL_TRUE)){ + c->dither_flag = GL_TRUE; + c->hPalHalfTone = WinGCreateHalftonePalette(); + } + else + c->dither_flag = GL_FALSE; +#else + c->dither_flag = GL_FALSE; +#endif + + + if (rgb_flag==GL_FALSE) + { + c->rgb_flag = GL_FALSE; +#if 0 + /* Old WinG stuff???? */ + c->db_flag = db_flag =GL_TRUE; /* WinG requires double buffering */ + printf("Single buffer is not supported in color index mode, ", + "setting to double buffer.\n"); +#endif + } + else + { + c->rgb_flag = GL_TRUE; + } + +// db_flag = pCtx->lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER ? GL_TRUE : GL_FALSE; + db_flag = GL_TRUE; // Force double-buffer + if (db_flag) { + c->db_flag = 1; + /* Double buffered */ + { + wmCreateBackingStore(c, pCtx->dwWidth, pCtx->dwHeight); + + } + } else { + /* Single Buffered */ + if (c->rgb_flag) + c->db_flag = 0; + } + + c->bEmulateSingleBuffer = (pCtx->lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER) + ? FALSE : TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldResizeDrawable_MesaSW( + DGL_ctx *ctx, + BOOL bDefaultDriver, + BOOL bPersistantInterface, + BOOL bPersistantBuffers) +{ + WMesaContext *c; + + if (ctx == NULL) + return FALSE; + + c = ctx->glPriv; + if (c == NULL) + return FALSE; + + c->hDC = ctx->hDC; + c->Window = ctx->hWnd; +// c->width = ctx->dwWidth; +// c->height = ctx->dwHeight; + + if (c->db_flag) { + wmDeleteBackingStore(c); + wmCreateBackingStore(c, ctx->dwWidth, ctx->dwHeight); + } + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyDrawable_MesaSW( + DGL_ctx *ctx) +{ + WMesaContext *c; + + if (ctx == NULL) + return FALSE; + + c = ctx->glPriv; + if (c == NULL) + return FALSE; + + if (c->hPalHalfTone != NULL) + DeleteObject(c->hPalHalfTone); + + if (c->db_flag) + wmDeleteBackingStore(c); + + free(c); + + ctx->glPriv = NULL; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldCreatePrivateGlobals_MesaSW(void) +{ + // Mesa Software driver needs no private globals + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyPrivateGlobals_MesaSW(void) +{ + // Mesa Software driver needs no private globals + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldBuildPixelformatList_MesaSW(void) +{ + // Release any existing pixelformat list + if (glb.lpPF) { + free(glb.lpPF); + } + + glb.nPixelFormatCount = 0; + glb.lpPF = NULL; + + glb.lpPF = (DGL_pixelFormat *)calloc(2, sizeof(DGL_pixelFormat)); + if (glb.lpPF == NULL) + return FALSE; + // Single-buffered + memcpy(&glb.lpPF[0], &pfTemplateMesaSW, sizeof(DGL_pixelFormat)); + glb.lpPF[0].pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + // Double-buffered + memcpy(&glb.lpPF[1], &pfTemplateMesaSW, sizeof(DGL_pixelFormat)); + glb.nPixelFormatCount = 2; + + // Mark list as 'current' + glb.bPixelformatsDirty = FALSE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldInitialiseMesa_MesaSW( + DGL_ctx *gld) +{ + GLcontext *ctx; + + if (gld == NULL) + return FALSE; + + ctx = gld->glCtx; + + // Set max texture size to 256 + ctx->Const.MaxTextureLevels = 8; + + // Multitexture enable/disable + ctx->Const.MaxTextureUnits = (glb.bMultitexture) ? MAX_TEXTURE_UNITS : 1; + + /* Initialize the software rasterizer and helper modules.*/ + + // Added this to force max texture diminsion to 256. KeithH + ctx->Const.MaxTextureLevels = 8; + + _mesa_enable_sw_extensions(ctx); + _mesa_enable_imaging_extensions(ctx); + _mesa_enable_1_3_extensions(ctx); + +// _swrast_CreateContext( ctx ); +// _vbo_CreateContext( ctx ); +// _tnl_CreateContext( ctx ); +// _swsetup_CreateContext( ctx ); + + _swsetup_Wakeup( ctx ); + + wmesa_update_state_first_time(ctx, ~0); + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldSwapBuffers_MesaSW( + DGL_ctx *ctx, + HDC hDC, + HWND hWnd) +{ + WMesaContext *c; + + if (ctx == NULL) + return FALSE; + + c = ctx->glPriv; + if (c == NULL) + return FALSE; + + /* If we're swapping the buffer associated with the current context + * we have to flush any pending rendering commands first. + */ + + // Altered to respect bEmulateSingleBuffer. KeithH +// if (c->db_flag) + if (!c->bEmulateSingleBuffer) + wmFlush(c, hDC); + + return TRUE; +} + +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_MesaSW( + LPCSTR a) +{ + int i; + PROC proc = NULL; + + for (i=0; GLD_extList[i].proc; i++) { + if (!strcmp(a, GLD_extList[i].name)) { + proc = GLD_extList[i].proc; + break; + } + } + + gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); + + return proc; +} + +//--------------------------------------------------------------------------- + +BOOL gldGetDisplayMode_MesaSW( + DGL_ctx *ctx, + GLD_displayMode *glddm) +{ + HDC hdcDesktop; + + if (glddm == NULL) + return FALSE; + + // + // A bit hacky... KeithH + // + + hdcDesktop = GetDC(NULL); + glddm->Width = GetDeviceCaps(hdcDesktop, HORZRES); + glddm->Height = GetDeviceCaps(hdcDesktop, VERTRES); + glddm->BPP = GetDeviceCaps(hdcDesktop, BITSPIXEL); + glddm->Refresh = 0; + ReleaseDC(0, hdcDesktop); + + return TRUE; +} + +//--------------------------------------------------------------------------- + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/gldirect.rc +++ mesa-7.2/src/mesa/drivers/windows/gldirect/gldirect.rc @@ -0,0 +1,43 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: Windows Resource Compiler +* Environment: Windows 95 +* +****************************************************************************/ + +#ifndef WORKSHOP_INVOKED + #include +#endif + +#define FILE_DESCRIPTION "SciTech GLDirect" +#define ORIG_FILENAME "opengl32.dll" +#define FILE_TYPE VFT_DLL + +#include "gldirect/gldver.ver" --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_wgl_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_wgl_dx8.c @@ -0,0 +1,1335 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect Direct3D 8.x WGL (WindowsGL) +* +****************************************************************************/ + +#include "dglcontext.h" +#include "gld_driver.h" +#include "gld_dxerr8.h" +#include "gld_dx8.h" + +#include "tnl/tnl.h" +#include "tnl/t_context.h" + +// Copied from dglcontect.c +#define GLDERR_NONE 0 +#define GLDERR_MEM 1 +#define GLDERR_DDRAW 2 +#define GLDERR_D3D 3 +#define GLDERR_BPP 4 +#define GLDERR_DDS 5 +// This external var keeps track of any error +extern int nContextError; + +#define DDLOG_CRITICAL_OR_WARN DDLOG_CRITICAL + +extern void _gld_mesa_warning(GLcontext *, char *); +extern void _gld_mesa_fatal(GLcontext *, char *); + +//--------------------------------------------------------------------------- + +static char szColorDepthWarning[] = +"GLDirect does not support the current desktop\n\ +color depth.\n\n\ +You may need to change the display resolution to\n\ +16 bits per pixel or higher color depth using\n\ +the Windows Display Settings control panel\n\ +before running this OpenGL application.\n"; + +// The only depth-stencil formats currently supported by Direct3D +// Surface Format Depth Stencil Total Bits +// D3DFMT_D32 32 - 32 +// D3DFMT_D15S1 15 1 16 +// D3DFMT_D24S8 24 8 32 +// D3DFMT_D16 16 - 16 +// D3DFMT_D24X8 24 - 32 +// D3DFMT_D24X4S4 24 4 32 + +// This pixel format will be used as a template when compiling the list +// of pixel formats supported by the hardware. Many fields will be +// filled in at runtime. +// PFD flag defaults are upgraded to match ChoosePixelFormat() -- DaveM +static DGL_pixelFormat pfTemplateHW = +{ + { + sizeof(PIXELFORMATDESCRIPTOR), // Size of the data structure + 1, // Structure version - should be 1 + // Flags: + PFD_DRAW_TO_WINDOW | // The buffer can draw to a window or device surface. + PFD_DRAW_TO_BITMAP | // The buffer can draw to a bitmap. (DaveM) + PFD_SUPPORT_GDI | // The buffer supports GDI drawing. (DaveM) + PFD_SUPPORT_OPENGL | // The buffer supports OpenGL drawing. + PFD_DOUBLEBUFFER | // The buffer is double-buffered. + 0, // Placeholder for easy commenting of above flags + PFD_TYPE_RGBA, // Pixel type RGBA. + 16, // Total colour bitplanes (excluding alpha bitplanes) + 5, 0, // Red bits, shift + 5, 0, // Green bits, shift + 5, 0, // Blue bits, shift + 0, 0, // Alpha bits, shift (destination alpha) + 0, // Accumulator bits (total) + 0, 0, 0, 0, // Accumulator bits: Red, Green, Blue, Alpha + 0, // Depth bits + 0, // Stencil bits + 0, // Number of auxiliary buffers + 0, // Layer type + 0, // Specifies the number of overlay and underlay planes. + 0, // Layer mask + 0, // Specifies the transparent color or index of an underlay plane. + 0 // Damage mask + }, + D3DFMT_UNKNOWN, // No depth/stencil buffer +}; + +//--------------------------------------------------------------------------- +// Vertex Shaders +//--------------------------------------------------------------------------- + +// Vertex Shader Declaration +static DWORD dwTwoSidedLightingDecl[] = +{ + D3DVSD_STREAM(0), + D3DVSD_REG(0, D3DVSDT_FLOAT3), // XYZ position + D3DVSD_REG(1, D3DVSDT_FLOAT3), // XYZ normal + D3DVSD_REG(2, D3DVSDT_D3DCOLOR), // Diffuse color + D3DVSD_REG(3, D3DVSDT_D3DCOLOR), // Specular color + D3DVSD_REG(4, D3DVSDT_FLOAT2), // 2D texture unit 0 + D3DVSD_REG(5, D3DVSDT_FLOAT2), // 2D texture unit 1 + D3DVSD_END() +}; + +// Vertex Shader for two-sided lighting +static char *szTwoSidedLightingVS = +// This is a test shader! +"vs.1.0\n" +"m4x4 oPos,v0,c0\n" +"mov oD0,v2\n" +"mov oD1,v3\n" +"mov oT0,v4\n" +"mov oT1,v5\n" +; + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +typedef struct { + HINSTANCE hD3D8DLL; // Handle to d3d8.dll + FNDIRECT3DCREATE8 fnDirect3DCreate8; // Direct3DCreate8 function prototype + BOOL bDirect3D; // Persistant Direct3D8 exists + BOOL bDirect3DDevice; // Persistant Direct3DDevice8 exists + IDirect3D8 *pD3D; // Persistant Direct3D8 + IDirect3DDevice8 *pDev; // Persistant Direct3DDevice8 +} GLD_dx8_globals; + +// These are "global" to all DX8 contexts. KeithH +static GLD_dx8_globals dx8Globals; + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +BOOL gldGetDXErrorString_DX( + HRESULT hr, + char *buf, + int nBufSize) +{ + // + // Return a string describing the input HRESULT error code + // + + D3DXGetErrorString(hr, buf, nBufSize); + return TRUE; +} + +//--------------------------------------------------------------------------- + +static D3DMULTISAMPLE_TYPE _gldGetDeviceMultiSampleType( + IDirect3D8 *pD3D8, + D3DFORMAT SurfaceFormat, + D3DDEVTYPE d3dDevType, + BOOL Windowed) +{ + int i; + HRESULT hr; + + if (glb.dwMultisample == GLDS_MULTISAMPLE_NONE) + return D3DMULTISAMPLE_NONE; + + if (glb.dwMultisample == GLDS_MULTISAMPLE_FASTEST) { + // Find fastest multisample + for (i=2; i<17; i++) { + hr = IDirect3D8_CheckDeviceMultiSampleType( + pD3D8, + glb.dwAdapter, + d3dDevType, + SurfaceFormat, + Windowed, + (D3DMULTISAMPLE_TYPE)i); + if (SUCCEEDED(hr)) { + return (D3DMULTISAMPLE_TYPE)i; + } + } + } else { + // Find nicest multisample + for (i=16; i>1; i--) { + hr = IDirect3D8_CheckDeviceMultiSampleType( + pD3D8, + glb.dwAdapter, + d3dDevType, + SurfaceFormat, + Windowed, + (D3DMULTISAMPLE_TYPE)i); + if (SUCCEEDED(hr)) { + return (D3DMULTISAMPLE_TYPE)i; + } + } + } + + // Nothing found - return default + return D3DMULTISAMPLE_NONE; +} + +//--------------------------------------------------------------------------- + +void _gldDestroyPrimitiveBuffer( + GLD_pb_dx8 *gldVB) +{ + SAFE_RELEASE(gldVB->pVB); + + // Sanity check... + gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; +} + +//--------------------------------------------------------------------------- + +HRESULT _gldCreatePrimitiveBuffer( + GLcontext *ctx, + GLD_driver_dx8 *lpCtx, + GLD_pb_dx8 *gldVB) +{ + HRESULT hResult; + char *szCreateVertexBufferFailed = "CreateVertexBuffer failed"; + DWORD dwMaxVertices; // Max number of vertices in vertex buffer + DWORD dwVBSize; // Total size of vertex buffer + + // If CVA (Compiled Vertex Array) is used by an OpenGL app, then we + // will need enough vertices to cater for Mesa::Const.MaxArrayLockSize. + // We'll use IMM_SIZE if it's larger (which it should not be). + dwMaxVertices = MAX_ARRAY_LOCK_SIZE; + + // Now calculate how many vertices to allow for in total + // 1 per point, 2 per line, 6 per quad = 9 + dwVBSize = dwMaxVertices * 9 * gldVB->dwStride; + + hResult = IDirect3DDevice8_CreateVertexBuffer( + lpCtx->pDev, + dwVBSize, + gldVB->dwUsage, + gldVB->dwFVF, + gldVB->dwPool, + &gldVB->pVB); + if (FAILED(hResult)) { + ddlogMessage(DDLOG_CRITICAL_OR_WARN, szCreateVertexBufferFailed); + return hResult; + } + + gldVB->nLines = gldVB->nPoints = gldVB->nTriangles = 0; + gldVB->pPoints = gldVB->pLines = gldVB->pTriangles = NULL; + gldVB->iFirstLine = dwMaxVertices; // Index of first line in VB + gldVB->iFirstTriangle = dwMaxVertices*3; // Index of first triangle in VB + + return S_OK; +} + +//--------------------------------------------------------------------------- +// Function: _gldCreateVertexShaders +// Create DX8 Vertex Shaders. +//--------------------------------------------------------------------------- +/* +void _gldCreateVertexShaders( + GLD_driver_dx8 *gld) +{ + DWORD dwFlags; + LPD3DXBUFFER pVSOpcodeBuffer; // Vertex Shader opcode buffer + HRESULT hr; + +#ifdef _DEBUG + dwFlags = D3DXASM_DEBUG; +#else + dwFlags = 0; // D3DXASM_SKIPVALIDATION; +#endif + + ddlogMessage(DDLOG_INFO, "Creating shaders...\n"); + + // Init the shader handle + gld->VStwosidelight.hShader = 0; + + if (gld->d3dCaps8.MaxStreams == 0) { + // Lame DX8 driver doesn't support streams + // Not fatal, as defaults will be used + ddlogMessage(DDLOG_WARN, "Driver doesn't support Vertex Shaders (MaxStreams==0)\n"); + return; + } + + // ** THIS DISABLES VERTEX SHADER SUPPORT ** +// return; + // ** THIS DISABLES VERTEX SHADER SUPPORT ** + + // + // Two-sided lighting + // + +#if 0 + // + // DEBUGGING: Load shader from a text file + // + { + LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer + hr = D3DXAssembleShaderFromFile( + "twoside.vsh", + dwFlags, + NULL, // No constants + &pVSOpcodeBuffer, + &pVSErrorBuffer); + if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) + ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); + SAFE_RELEASE(pVSErrorBuffer); + } +#else + { + LPD3DXBUFFER pVSErrorBuffer; // Vertex Shader error buffer + // Assemble ascii shader text into shader opcodes + hr = D3DXAssembleShader( + szTwoSidedLightingVS, + strlen(szTwoSidedLightingVS), + dwFlags, + NULL, // No constants + &pVSOpcodeBuffer, + &pVSErrorBuffer); + if (pVSErrorBuffer && pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)) + ddlogMessage(DDLOG_INFO, pVSErrorBuffer->lpVtbl->GetBufferPointer(pVSErrorBuffer)); + SAFE_RELEASE(pVSErrorBuffer); + } +#endif + if (FAILED(hr)) { + ddlogError(DDLOG_WARN, "AssembleShader failed", hr); + SAFE_RELEASE(pVSOpcodeBuffer); + return; + } + +// This is for debugging. Remove to enable vertex shaders in HW +#define _GLD_FORCE_SW_VS 0 + + if (_GLD_FORCE_SW_VS) { + // _GLD_FORCE_SW_VS should be disabled for Final Release + ddlogMessage(DDLOG_SYSTEM, "[Forcing shaders in SW]\n"); + } + + // Try and create shader in hardware. + // NOTE: The D3D Ref device appears to succeed when trying to + // create the device in hardware, but later complains + // when trying to set it with SetVertexShader(). Go figure. + if (_GLD_FORCE_SW_VS || glb.dwDriver == GLDS_DRIVER_REF) { + // Don't try and create a hardware shader with the Ref device + hr = E_FAIL; // COM error/fail result + } else { + gld->VStwosidelight.bHardware = TRUE; + hr = IDirect3DDevice8_CreateVertexShader( + gld->pDev, + dwTwoSidedLightingDecl, + pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), + &gld->VStwosidelight.hShader, + 0); + } + if (FAILED(hr)) { + ddlogMessage(DDLOG_INFO, "... HW failed, trying SW...\n"); + // Failed. Try and create shader for software processing + hr = IDirect3DDevice8_CreateVertexShader( + gld->pDev, + dwTwoSidedLightingDecl, + pVSOpcodeBuffer->lpVtbl->GetBufferPointer(pVSOpcodeBuffer), + &gld->VStwosidelight.hShader, + D3DUSAGE_SOFTWAREPROCESSING); + if (FAILED(hr)) { + gld->VStwosidelight.hShader = 0; // Sanity check + ddlogError(DDLOG_WARN, "CreateVertexShader failed", hr); + return; + } + // Succeeded, but for software processing + gld->VStwosidelight.bHardware = FALSE; + } + + SAFE_RELEASE(pVSOpcodeBuffer); + + ddlogMessage(DDLOG_INFO, "... OK\n"); +} + +//--------------------------------------------------------------------------- + +void _gldDestroyVertexShaders( + GLD_driver_dx8 *gld) +{ + if (gld->VStwosidelight.hShader) { + IDirect3DDevice8_DeleteVertexShader(gld->pDev, gld->VStwosidelight.hShader); + gld->VStwosidelight.hShader = 0; + } +} +*/ +//--------------------------------------------------------------------------- + +LPVOID lpOpaque1 = NULL; +LPVOID lpOpaque2 = NULL; + +BOOL gldCreateDrawable_DX( + DGL_ctx *ctx, +// BOOL bDefaultDriver, + BOOL bDirectDrawPersistant, + BOOL bPersistantBuffers) +{ + // + // bDirectDrawPersistant: applies to IDirect3D8 + // bPersistantBuffers: applies to IDirect3DDevice8 + // + + HRESULT hResult; + GLD_driver_dx8 *lpCtx = NULL; + D3DDEVTYPE d3dDevType; + D3DPRESENT_PARAMETERS d3dpp; + D3DDISPLAYMODE d3ddm; + DWORD dwBehaviourFlags; + D3DADAPTER_IDENTIFIER8 d3dIdent; + + // Error if context is NULL. + if (ctx == NULL) + return FALSE; + + if (ctx->glPriv) { + lpCtx = ctx->glPriv; + // Release any existing interfaces + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + } else { + lpCtx = (GLD_driver_dx8*)malloc(sizeof(GLD_driver_dx8)); + ZeroMemory(lpCtx, sizeof(lpCtx)); + } + + d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + // TODO: Check this +// if (bDefaultDriver) +// d3dDevType = D3DDEVTYPE_REF; + + // Use persistant interface if needed + if (bDirectDrawPersistant && dx8Globals.bDirect3D) { + lpCtx->pD3D = dx8Globals.pD3D; + IDirect3D8_AddRef(lpCtx->pD3D); + goto SkipDirectDrawCreate; + } + + // Create Direct3D8 object + lpCtx->pD3D = dx8Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); + if (lpCtx->pD3D == NULL) { + MessageBox(NULL, "Unable to initialize Direct3D8", "GLDirect", MB_OK); + ddlogMessage(DDLOG_CRITICAL_OR_WARN, "Unable to create Direct3D8 interface"); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Cache Direct3D interface for subsequent GLRCs + if (bDirectDrawPersistant && !dx8Globals.bDirect3D) { + dx8Globals.pD3D = lpCtx->pD3D; + IDirect3D8_AddRef(dx8Globals.pD3D); + dx8Globals.bDirect3D = TRUE; + } +SkipDirectDrawCreate: + + // Get the display mode so we can make a compatible backbuffer + hResult = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hResult)) { + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Get device caps + hResult = IDirect3D8_GetDeviceCaps(lpCtx->pD3D, glb.dwAdapter, d3dDevType, &lpCtx->d3dCaps8); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_GetDeviceCaps failed", hResult); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + // Check for hardware transform & lighting + lpCtx->bHasHWTnL = lpCtx->d3dCaps8.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? TRUE : FALSE; + + // If this flag is present then we can't default to Mesa + // SW rendering between BeginScene() and EndScene(). + if (lpCtx->d3dCaps8.Caps2 & D3DCAPS2_NO2DDURING3DSCENE) { + ddlogMessage(DDLOG_WARN, + "Warning : No 2D allowed during 3D scene.\n"); + } + + // + // Create the Direct3D context + // + + // Re-use original IDirect3DDevice if persistant buffers exist. + // Note that we test for persistant IDirect3D8 as well + // bDirectDrawPersistant == persistant IDirect3D8 (DirectDraw8 does not exist) + if (bDirectDrawPersistant && bPersistantBuffers && dx8Globals.pD3D && dx8Globals.pDev) { + lpCtx->pDev = dx8Globals.pDev; + IDirect3DDevice8_AddRef(dx8Globals.pDev); + goto skip_direct3ddevice_create; + } + + // Clear the presentation parameters (sets all members to zero) + ZeroMemory(&d3dpp, sizeof(d3dpp)); + + // Recommended by MS; needed for MultiSample. + // Be careful if altering this for FullScreenBlit + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + + d3dpp.BackBufferFormat = d3ddm.Format; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(lpCtx->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); + d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; + d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; + + if (ctx->bFullscreen) { + ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen + d3dpp.Windowed = FALSE; + d3dpp.BackBufferWidth = d3ddm.Width; + d3dpp.BackBufferHeight = d3ddm.Height; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + + // Support for vertical retrace synchronisation. + // Set default presentation interval in case caps bits are missing + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + if (glb.bWaitForRetrace) { + if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; + } else { + if (lpCtx->d3dCaps8.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + } else { + ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages + d3dpp.Windowed = TRUE; + d3dpp.BackBufferWidth = ctx->dwWidth; + d3dpp.BackBufferHeight = ctx->dwHeight; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = 0; + // FullScreen_PresentationInterval must be default for Windowed mode + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + } + + // Decide if we can use hardware TnL + dwBehaviourFlags = (lpCtx->bHasHWTnL) ? + D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING; + // Add flag to tell D3D to be thread-safe + if (glb.bMultiThreaded) + dwBehaviourFlags |= D3DCREATE_MULTITHREADED; + // Add flag to tell D3D to be FPU-safe + if (!glb.bFastFPU) + dwBehaviourFlags |= D3DCREATE_FPU_PRESERVE; + hResult = IDirect3D8_CreateDevice(lpCtx->pD3D, + glb.dwAdapter, + d3dDevType, + ctx->hWnd, + dwBehaviourFlags, + &d3dpp, + &lpCtx->pDev); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "IDirect3D8_CreateDevice failed", hResult); + nContextError = GLDERR_D3D; + goto return_with_error; + } + + if (bDirectDrawPersistant && bPersistantBuffers && dx8Globals.pD3D) { + dx8Globals.pDev = lpCtx->pDev; + dx8Globals.bDirect3DDevice = TRUE; + } + +/* + // See if DDraw interfaces are available (DaveM) + hResult = IDirect3D8_QueryInterface(lpCtx->pDev, + &IID_IDirectDraw7, (LPVOID*)&lpOpaque1); + if (FAILED(hResult) || lpOpaque1 == NULL) { + ddlogMessage(DDLOG_INFO, "DirectDraw QueryInterface unavailable\n"); + } + + hResult = IDirect3DDevice8_QueryInterface(lpCtx->pDev, + &IID_IDirectDrawSurface7, (LPVOID*)&lpOpaque2); + if (FAILED(hResult) || lpOpaque2 == NULL) { + ddlogMessage(DDLOG_INFO, "DirectDrawSurface QueryInterface unavialable\n"); + } +*/ + // Dump some useful stats + hResult = IDirect3D8_GetAdapterIdentifier( + lpCtx->pD3D, + glb.dwAdapter, + D3DENUM_NO_WHQL_LEVEL, // Avoids 1 to 2 second delay + &d3dIdent); + if (SUCCEEDED(hResult)) { + ddlogPrintf(DDLOG_INFO, "[Driver Description: %s]", &d3dIdent.Description); + ddlogPrintf(DDLOG_INFO, "[Driver file: %s %d.%d.%02d.%d]", + d3dIdent.Driver, + HIWORD(d3dIdent.DriverVersion.HighPart), + LOWORD(d3dIdent.DriverVersion.HighPart), + HIWORD(d3dIdent.DriverVersion.LowPart), + LOWORD(d3dIdent.DriverVersion.LowPart)); + ddlogPrintf(DDLOG_INFO, "[VendorId: 0x%X, DeviceId: 0x%X, SubSysId: 0x%X, Revision: 0x%X]", + d3dIdent.VendorId, d3dIdent.DeviceId, d3dIdent.SubSysId, d3dIdent.Revision); + } + + // Init projection matrix for D3D TnL + D3DXMatrixIdentity(&lpCtx->matProjection); + lpCtx->matModelView = lpCtx->matProjection; +// gld->bUseMesaProjection = TRUE; + +skip_direct3ddevice_create: + + // Create buffers to hold primitives + lpCtx->PB2d.dwFVF = GLD_FVF_2D_VERTEX; + lpCtx->PB2d.dwPool = D3DPOOL_SYSTEMMEM; + lpCtx->PB2d.dwStride = sizeof(GLD_2D_VERTEX); + lpCtx->PB2d.dwUsage = D3DUSAGE_DONOTCLIP | + D3DUSAGE_DYNAMIC | + D3DUSAGE_SOFTWAREPROCESSING | + D3DUSAGE_WRITEONLY; + hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB2d); + if (FAILED(hResult)) + goto return_with_error; + + lpCtx->PB3d.dwFVF = GLD_FVF_3D_VERTEX; + lpCtx->PB3d.dwPool = D3DPOOL_DEFAULT; + lpCtx->PB3d.dwStride = sizeof(GLD_3D_VERTEX); + lpCtx->PB3d.dwUsage = D3DUSAGE_DYNAMIC | + D3DUSAGE_SOFTWAREPROCESSING | + D3DUSAGE_WRITEONLY; + hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PB3d); + if (FAILED(hResult)) + goto return_with_error; + +/* // NOTE: A FVF code of zero indicates a non-FVF vertex buffer (for vertex shaders) + lpCtx->PBtwosidelight.dwFVF = 0; //GLD_FVF_TWOSIDED_VERTEX; + lpCtx->PBtwosidelight.dwPool = D3DPOOL_DEFAULT; + lpCtx->PBtwosidelight.dwStride = sizeof(GLD_TWOSIDED_VERTEX); + lpCtx->PBtwosidelight.dwUsage = D3DUSAGE_DONOTCLIP | + D3DUSAGE_DYNAMIC | + D3DUSAGE_SOFTWAREPROCESSING | + D3DUSAGE_WRITEONLY; + hResult = _gldCreatePrimitiveBuffer(ctx->glCtx, lpCtx, &lpCtx->PBtwosidelight); + if (FAILED(hResult)) + goto return_with_error;*/ + + // Now try and create the DX8 Vertex Shaders +// _gldCreateVertexShaders(lpCtx); + + // Zero the pipeline usage counters + lpCtx->PipelineUsage.qwMesa.QuadPart = +// lpCtx->PipelineUsage.dwD3D2SVS.QuadPart = + lpCtx->PipelineUsage.qwD3DFVF.QuadPart = 0; + + // Assign drawable to GL private + ctx->glPriv = lpCtx; + return TRUE; + +return_with_error: + // Clean up and bail + +// _gldDestroyVertexShaders(lpCtx); + +// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); + _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); + _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); + + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + return FALSE; +} + +//--------------------------------------------------------------------------- + +BOOL gldResizeDrawable_DX( + DGL_ctx *ctx, + BOOL bDefaultDriver, + BOOL bPersistantInterface, + BOOL bPersistantBuffers) +{ + GLD_driver_dx8 *gld = NULL; + D3DDEVTYPE d3dDevType; + D3DPRESENT_PARAMETERS d3dpp; + D3DDISPLAYMODE d3ddm; + HRESULT hResult; + + // Error if context is NULL. + if (ctx == NULL) + return FALSE; + + gld = ctx->glPriv; + if (gld == NULL) + return FALSE; + + if (ctx->bSceneStarted) { + IDirect3DDevice8_EndScene(gld->pDev); + ctx->bSceneStarted = FALSE; + } + + d3dDevType = (glb.dwDriver == GLDS_DRIVER_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + if (!bDefaultDriver) + d3dDevType = D3DDEVTYPE_REF; // Force Direct3D Reference Rasterise (software) + + // Get the display mode so we can make a compatible backbuffer + hResult = IDirect3D8_GetAdapterDisplayMode(gld->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hResult)) { + nContextError = GLDERR_D3D; +// goto return_with_error; + return FALSE; + } + + // Destroy DX8 Vertex Shaders before Reset() +// _gldDestroyVertexShaders(gld); + + // Release POOL_DEFAULT objects before Reset() + if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) + _gldDestroyPrimitiveBuffer(&gld->PB2d); + if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) + _gldDestroyPrimitiveBuffer(&gld->PB3d); +// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) +// _gldDestroyPrimitiveBuffer(&gld->PBtwosidelight); + + // Clear the presentation parameters (sets all members to zero) + ZeroMemory(&d3dpp, sizeof(d3dpp)); + + // Recommended by MS; needed for MultiSample. + // Be careful if altering this for FullScreenBlit + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + + d3dpp.BackBufferFormat = d3ddm.Format; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = _gldGetDeviceMultiSampleType(gld->pD3D, d3ddm.Format, d3dDevType, !ctx->bFullscreen); + d3dpp.AutoDepthStencilFormat = ctx->lpPF->dwDriverData; + d3dpp.EnableAutoDepthStencil = (d3dpp.AutoDepthStencilFormat == D3DFMT_UNKNOWN) ? FALSE : TRUE; + + // TODO: Sync to refresh + + if (ctx->bFullscreen) { + ddlogWarnOption(FALSE); // Don't popup any messages in fullscreen + d3dpp.Windowed = FALSE; + d3dpp.BackBufferWidth = d3ddm.Width; + d3dpp.BackBufferHeight = d3ddm.Height; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + // Get better benchmark results? KeithH +// d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_UNLIMITED; + } else { + ddlogWarnOption(glb.bMessageBoxWarnings); // OK to popup messages + d3dpp.Windowed = TRUE; + d3dpp.BackBufferWidth = ctx->dwWidth; + d3dpp.BackBufferHeight = ctx->dwHeight; + d3dpp.hDeviceWindow = ctx->hWnd; + d3dpp.FullScreen_RefreshRateInHz = 0; + d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + } + hResult = IDirect3DDevice8_Reset(gld->pDev, &d3dpp); + if (FAILED(hResult)) { + ddlogError(DDLOG_CRITICAL_OR_WARN, "dglResize: Reset failed", hResult); + return FALSE; + //goto cleanup_and_return_with_error; + } + + // Explicitly Clear resized surfaces (DaveM) + { + D3DVIEWPORT8 d3dvp1, d3dvp2; + IDirect3DDevice8_GetViewport(gld->pDev, &d3dvp1); + IDirect3DDevice8_GetViewport(gld->pDev, &d3dvp2); + d3dvp1.X = 0; + d3dvp1.Y = 0; + d3dvp1.Width = ctx->dwWidth; + d3dvp1.Height = ctx->dwHeight; + IDirect3DDevice8_SetViewport(gld->pDev, &d3dvp1); + IDirect3DDevice8_Clear(gld->pDev,0,NULL,D3DCLEAR_TARGET,0,0,0); + IDirect3DDevice8_SetViewport(gld->pDev, &d3dvp2); + } + + // + // Recreate POOL_DEFAULT objects + // + if (gld->PB2d.dwPool == D3DPOOL_DEFAULT) { + _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); + } + if (gld->PB3d.dwPool == D3DPOOL_DEFAULT) { + _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB3d); + } +// if (gld->PBtwosidelight.dwPool == D3DPOOL_DEFAULT) { +// _gldCreatePrimitiveBuffer(ctx->glCtx, gld, &gld->PB2d); +// } + + // Recreate DX8 Vertex Shaders +// _gldCreateVertexShaders(gld); + + // Signal a complete state update + ctx->glCtx->Driver.UpdateState(ctx->glCtx, _NEW_ALL); + + // Begin a new scene + IDirect3DDevice8_BeginScene(gld->pDev); + ctx->bSceneStarted = TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyDrawable_DX( + DGL_ctx *ctx) +{ + GLD_driver_dx8 *lpCtx = NULL; + + // Error if context is NULL. + if (!ctx) + return FALSE; + + // Error if the drawable does not exist. + if (!ctx->glPriv) + return FALSE; + + lpCtx = ctx->glPriv; + +#ifdef _DEBUG + // Dump out stats + ddlogPrintf(DDLOG_SYSTEM, "Usage: M:0x%X%X, D:0x%X%X", + lpCtx->PipelineUsage.qwMesa.HighPart, + lpCtx->PipelineUsage.qwMesa.LowPart, + lpCtx->PipelineUsage.qwD3DFVF.HighPart, + lpCtx->PipelineUsage.qwD3DFVF.LowPart); +#endif + +// _gldDestroyVertexShaders(lpCtx); + +// _gldDestroyPrimitiveBuffer(&lpCtx->PBtwosidelight); + _gldDestroyPrimitiveBuffer(&lpCtx->PB3d); + _gldDestroyPrimitiveBuffer(&lpCtx->PB2d); + + SAFE_RELEASE(lpCtx->pDev); + SAFE_RELEASE(lpCtx->pD3D); + + // Free the private drawable data + free(ctx->glPriv); + ctx->glPriv = NULL; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldCreatePrivateGlobals_DX(void) +{ + ZeroMemory(&dx8Globals, sizeof(dx8Globals)); + + // Load d3d8.dll + dx8Globals.hD3D8DLL = LoadLibrary("D3D8.DLL"); + if (dx8Globals.hD3D8DLL == NULL) + return FALSE; + + // Now try and obtain Direct3DCreate8 + dx8Globals.fnDirect3DCreate8 = (FNDIRECT3DCREATE8)GetProcAddress(dx8Globals.hD3D8DLL, "Direct3DCreate8"); + if (dx8Globals.fnDirect3DCreate8 == NULL) { + FreeLibrary(dx8Globals.hD3D8DLL); + return FALSE; + } + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldDestroyPrivateGlobals_DX(void) +{ + if (dx8Globals.bDirect3DDevice) { + SAFE_RELEASE(dx8Globals.pDev); + dx8Globals.bDirect3DDevice = FALSE; + } + if (dx8Globals.bDirect3D) { + SAFE_RELEASE(dx8Globals.pD3D); + dx8Globals.bDirect3D = FALSE; + } + + FreeLibrary(dx8Globals.hD3D8DLL); + dx8Globals.hD3D8DLL = NULL; + dx8Globals.fnDirect3DCreate8 = NULL; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +static void _BitsFromDisplayFormat( + D3DFORMAT fmt, + BYTE *cColorBits, + BYTE *cRedBits, + BYTE *cGreenBits, + BYTE *cBlueBits, + BYTE *cAlphaBits) +{ + switch (fmt) { + case D3DFMT_X1R5G5B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 5; + *cBlueBits = 5; + *cAlphaBits = 0; + return; + case D3DFMT_R5G6B5: + *cColorBits = 16; + *cRedBits = 5; + *cGreenBits = 6; + *cBlueBits = 5; + *cAlphaBits = 0; + return; + case D3DFMT_X8R8G8B8: + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 0; + return; + case D3DFMT_A8R8G8B8: + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 8; + return; + } + + // Should not get here! + *cColorBits = 32; + *cRedBits = 8; + *cGreenBits = 8; + *cBlueBits = 8; + *cAlphaBits = 0; +} + +//--------------------------------------------------------------------------- + +static void _BitsFromDepthStencilFormat( + D3DFORMAT fmt, + BYTE *cDepthBits, + BYTE *cStencilBits) +{ + // NOTE: GL expects either 32 or 16 as depth bits. + switch (fmt) { + case D3DFMT_D32: + *cDepthBits = 32; + *cStencilBits = 0; + return; + case D3DFMT_D15S1: + *cDepthBits = 16; + *cStencilBits = 1; + return; + case D3DFMT_D24S8: + *cDepthBits = 32; + *cStencilBits = 8; + return; + case D3DFMT_D16: + *cDepthBits = 16; + *cStencilBits = 0; + return; + case D3DFMT_D24X8: + *cDepthBits = 32; + *cStencilBits = 0; + return; + case D3DFMT_D24X4S4: + *cDepthBits = 32; + *cStencilBits = 4; + return; + } +} + +//--------------------------------------------------------------------------- + +BOOL gldBuildPixelformatList_DX(void) +{ + D3DDISPLAYMODE d3ddm; + D3DFORMAT fmt[6]; + IDirect3D8 *pD3D = NULL; + HRESULT hr; + int nSupportedFormats = 0; + int i; + DGL_pixelFormat *pPF; + BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; +// char buf[128]; +// char cat[8]; + + // Direct3D (SW or HW) + // These are arranged so that 'best' pixelformat + // is higher in the list (for ChoosePixelFormat). + const D3DFORMAT DepthStencil[6] = { + D3DFMT_D15S1, + D3DFMT_D16, + D3DFMT_D24X8, + D3DFMT_D24X4S4, + D3DFMT_D24S8, + D3DFMT_D32, + }; + + // Dump DX version + ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 8.0\n"); + + // Release any existing pixelformat list + if (glb.lpPF) { + free(glb.lpPF); + } + + glb.nPixelFormatCount = 0; + glb.lpPF = NULL; + + // + // Pixelformats for Direct3D (SW or HW) rendering + // + + // Get a Direct3D 8.0 interface + pD3D = dx8Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); + if (!pD3D) { + return FALSE; + } + + // We will use the display mode format when finding compliant + // rendertarget/depth-stencil surfaces. + hr = IDirect3D8_GetAdapterDisplayMode(pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hr)) { + IDirect3D8_Release(pD3D); + return FALSE; + } + + // Run through the possible formats and detect supported formats + for (i=0; i<6; i++) { + hr = IDirect3D8_CheckDeviceFormat( + pD3D, + glb.dwAdapter, + glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, + d3ddm.Format, + D3DUSAGE_DEPTHSTENCIL, + D3DRTYPE_SURFACE, + DepthStencil[i]); + if (FAILED(hr)) + // A failure here is not fatal. + continue; + + // Verify that the depth format is compatible. + hr = IDirect3D8_CheckDepthStencilMatch( + pD3D, + glb.dwAdapter, + glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, + d3ddm.Format, + d3ddm.Format, + DepthStencil[i]); + if (FAILED(hr)) + // A failure here is not fatal, just means depth-stencil + // format is not compatible with this display mode. + continue; + + fmt[nSupportedFormats++] = DepthStencil[i]; + } + + IDirect3D8_Release(pD3D); + + if (nSupportedFormats == 0) + return FALSE; // Bail: no compliant pixelformats + + // Total count of pixelformats is: + // (nSupportedFormats+1)*2 + glb.lpPF = (DGL_pixelFormat *)calloc((nSupportedFormats)*2, sizeof(DGL_pixelFormat)); + glb.nPixelFormatCount = (nSupportedFormats)*2; + if (glb.lpPF == NULL) { + glb.nPixelFormatCount = 0; + return FALSE; + } + + // Get a copy of pointer that we can alter + pPF = glb.lpPF; + + // Cache colour bits from display format + _BitsFromDisplayFormat(d3ddm.Format, &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); + + // + // Add single-buffer formats + // + + // Single-buffer, no depth-stencil buffer +/* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); + pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + pPF->pfd.cDepthBits = 0; + pPF->pfd.cStencilBits = 0; + pPF->dwDriverData = D3DFMT_UNKNOWN; + pPF++;*/ + + for (i=0; ipfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); + pPF->dwDriverData = fmt[i]; + } + + // + // Add double-buffer formats + // + +/* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); + pPF->pfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + pPF->pfd.cDepthBits = 0; + pPF->pfd.cStencilBits = 0; + pPF->dwDriverData = D3DFMT_UNKNOWN; + pPF++;*/ + + for (i=0; ipfd.cColorBits = cColorBits; + pPF->pfd.cRedBits = cRedBits; + pPF->pfd.cGreenBits = cGreenBits; + pPF->pfd.cBlueBits = cBlueBits; + pPF->pfd.cAlphaBits = cAlphaBits; + _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); + pPF->dwDriverData = fmt[i]; + } + + // Popup warning message if non RGB color mode + { + // This is a hack. KeithH + HDC hdcDesktop = GetDC(NULL); + DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); + ReleaseDC(0, hdcDesktop); + if (dwDisplayBitDepth <= 8) { + ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); + MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); + } + } + + // Mark list as 'current' + glb.bPixelformatsDirty = FALSE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldInitialiseMesa_DX( + DGL_ctx *lpCtx) +{ + GLD_driver_dx8 *gld = NULL; + int MaxTextureSize, TextureLevels; + BOOL bSoftwareTnL; + + if (lpCtx == NULL) + return FALSE; + + gld = lpCtx->glPriv; + if (gld == NULL) + return FALSE; + + if (glb.bMultitexture) { + lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps8.MaxSimultaneousTextures; + // Only support MAX_TEXTURE_UNITS texture units. + // ** If this is altered then the FVF formats must be reviewed **. + if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX8) + lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX8; + } else { + // Multitexture override + lpCtx->glCtx->Const.MaxTextureUnits = 1; + } + + // max texture size + MaxTextureSize = min(gld->d3dCaps8.MaxTextureHeight, gld->d3dCaps8.MaxTextureWidth); + if (MaxTextureSize == 0) + MaxTextureSize = 256; // Sanity check + + // + // HACK!! + if (MaxTextureSize > 1024) + MaxTextureSize = 1024; // HACK - CLAMP TO 1024 + // HACK!! + // + + // Got to set MAX_TEXTURE_SIZE as max levels. + // Who thought this stupid idea up? ;) + TextureLevels = 0; + // Calculate power-of-two. + while (MaxTextureSize) { + TextureLevels++; + MaxTextureSize >>= 1; + } + lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8; + + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_LIGHTING, FALSE); + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_DITHERENABLE, TRUE); + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SHADEMODE, D3DSHADE_GOURAUD); + + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ZENABLE, + (lpCtx->lpPF->dwDriverData!=D3DFMT_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE); + + // Set the view matrix + { + D3DXMATRIX vm; +#if 1 + D3DXMatrixIdentity(&vm); +#else + D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f); + D3DXVECTOR3 At(0.0f, 0.0f, -1.0f); + D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); + D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up); + vm._31 = -vm._31; + vm._32 = -vm._32; + vm._33 = -vm._33; + vm._34 = -vm._34; +#endif + IDirect3DDevice8_SetTransform(gld->pDev, D3DTS_VIEW, &vm); + } + + if (gld->bHasHWTnL) { + if (glb.dwTnL == GLDS_TNL_DEFAULT) + bSoftwareTnL = FALSE; // HW TnL + else { + bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE; + } + } else { + // No HW TnL, so no choice possible + bSoftwareTnL = TRUE; + } + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL); + +// Dump this in a Release build as well, now. +//#ifdef _DEBUG + ddlogPrintf(DDLOG_INFO, "HW TnL: %s", + gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable"); +//#endif + + gldEnableExtensions_DX8(lpCtx->glCtx); + gldInstallPipeline_DX8(lpCtx->glCtx); + gldSetupDriverPointers_DX8(lpCtx->glCtx); + + // Signal a complete state update + lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL); + + // Start a scene + IDirect3DDevice8_BeginScene(gld->pDev); + lpCtx->bSceneStarted = TRUE; + + return TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldSwapBuffers_DX( + DGL_ctx *ctx, + HDC hDC, + HWND hWnd) +{ + HRESULT hr; + GLD_driver_dx8 *gld = NULL; + + if (ctx == NULL) + return FALSE; + + gld = ctx->glPriv; + if (gld == NULL) + return FALSE; + + if (ctx->bSceneStarted) { + IDirect3DDevice8_EndScene(gld->pDev); + ctx->bSceneStarted = FALSE; + } + + // Swap the buffers. hWnd may override the hWnd used for CreateDevice() + hr = IDirect3DDevice8_Present(gld->pDev, NULL, NULL, hWnd, NULL); + + IDirect3DDevice8_BeginScene(gld->pDev); + ctx->bSceneStarted = TRUE; + + return (FAILED(hr)) ? FALSE : TRUE; +} + +//--------------------------------------------------------------------------- + +BOOL gldGetDisplayMode_DX( + DGL_ctx *ctx, + GLD_displayMode *glddm) +{ + D3DDISPLAYMODE d3ddm; + HRESULT hr; + GLD_driver_dx8 *lpCtx = NULL; + BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; + + if ((glddm == NULL) || (ctx == NULL)) + return FALSE; + + lpCtx = ctx->glPriv; + if (lpCtx == NULL) + return FALSE; + + if (lpCtx->pD3D == NULL) + return FALSE; + + hr = IDirect3D8_GetAdapterDisplayMode(lpCtx->pD3D, glb.dwAdapter, &d3ddm); + if (FAILED(hr)) + return FALSE; + + // Get info from the display format + _BitsFromDisplayFormat(d3ddm.Format, + &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); + + glddm->Width = d3ddm.Width; + glddm->Height = d3ddm.Height; + glddm->BPP = cColorBits; + glddm->Refresh = d3ddm.RefreshRate; + + return TRUE; +} + +//--------------------------------------------------------------------------- + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_ext_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_ext_dx8.c @@ -0,0 +1,344 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GL extensions +* +****************************************************************************/ + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "../gld_settings.h" + +#include +#define GL_GLEXT_PROTOTYPES +#include +#include + +//#include "ddlog.h" +//#include "gld_dx8.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "dglcontext.h" +#include "extensions.h" + +// For some reason this is not defined in an above header... +extern void _mesa_enable_imaging_extensions(GLcontext *ctx); + +//--------------------------------------------------------------------------- +// Hack for the SGIS_multitexture extension that was removed from Mesa +// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel + + // NOTE: Quake2 ran *slower* with this enabled, so I've + // disabled it for now. + // To enable, uncomment: + // _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); + +//--------------------------------------------------------------------------- + +enum { + /* Quake2 GL_SGIS_multitexture */ + GL_SELECTED_TEXTURE_SGIS = 0x835B, + GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835C, + GL_MAX_TEXTURES_SGIS = 0x835D, + GL_TEXTURE0_SGIS = 0x835E, + GL_TEXTURE1_SGIS = 0x835F, + GL_TEXTURE2_SGIS = 0x8360, + GL_TEXTURE3_SGIS = 0x8361, + GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, +}; + +//--------------------------------------------------------------------------- + +void APIENTRY gldSelectTextureSGIS( + GLenum target) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glActiveTextureARB(ARB_target); +} + +//--------------------------------------------------------------------------- + +void APIENTRY gldMTexCoord2fSGIS( + GLenum target, + GLfloat s, + GLfloat t) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glMultiTexCoord2fARB(ARB_target, s, t); +} + +//--------------------------------------------------------------------------- + +void APIENTRY gldMTexCoord2fvSGIS( + GLenum target, + const GLfloat *v) +{ + GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS); + glMultiTexCoord2fvARB(ARB_target, v); +} + +//--------------------------------------------------------------------------- +// Extensions +//--------------------------------------------------------------------------- + +typedef struct { + PROC proc; + char *name; +} GLD_extension; + +GLD_extension GLD_extList[] = { +#ifdef GL_EXT_polygon_offset + { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, +#endif + { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, + { (PROC)glBlendColorEXT, "glBlendColorExt" }, + { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, + { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, + { (PROC)glColorPointerEXT, "glColorPointerEXT" }, + { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, + { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, + { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, + { (PROC)glGetPointervEXT, "glGetPointervEXT" }, + { (PROC)glArrayElementEXT, "glArrayElementEXT" }, + { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, + { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, + { (PROC)glBindTextureEXT, "glBindTextureEXT" }, + { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, + { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, + { (PROC)glIsTextureEXT, "glIsTextureEXT" }, + { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, + { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, + { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, + { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, + { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, + { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, + + { (PROC)glLockArraysEXT, "glLockArraysEXT" }, + { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }, + { NULL, "\0" } +}; + +GLD_extension GLD_multitexList[] = { +/* + { (PROC)glMultiTexCoord1dSGIS, "glMTexCoord1dSGIS" }, + { (PROC)glMultiTexCoord1dvSGIS, "glMTexCoord1dvSGIS" }, + { (PROC)glMultiTexCoord1fSGIS, "glMTexCoord1fSGIS" }, + { (PROC)glMultiTexCoord1fvSGIS, "glMTexCoord1fvSGIS" }, + { (PROC)glMultiTexCoord1iSGIS, "glMTexCoord1iSGIS" }, + { (PROC)glMultiTexCoord1ivSGIS, "glMTexCoord1ivSGIS" }, + { (PROC)glMultiTexCoord1sSGIS, "glMTexCoord1sSGIS" }, + { (PROC)glMultiTexCoord1svSGIS, "glMTexCoord1svSGIS" }, + { (PROC)glMultiTexCoord2dSGIS, "glMTexCoord2dSGIS" }, + { (PROC)glMultiTexCoord2dvSGIS, "glMTexCoord2dvSGIS" }, + { (PROC)glMultiTexCoord2fSGIS, "glMTexCoord2fSGIS" }, + { (PROC)glMultiTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, + { (PROC)glMultiTexCoord2iSGIS, "glMTexCoord2iSGIS" }, + { (PROC)glMultiTexCoord2ivSGIS, "glMTexCoord2ivSGIS" }, + { (PROC)glMultiTexCoord2sSGIS, "glMTexCoord2sSGIS" }, + { (PROC)glMultiTexCoord2svSGIS, "glMTexCoord2svSGIS" }, + { (PROC)glMultiTexCoord3dSGIS, "glMTexCoord3dSGIS" }, + { (PROC)glMultiTexCoord3dvSGIS, "glMTexCoord3dvSGIS" }, + { (PROC)glMultiTexCoord3fSGIS, "glMTexCoord3fSGIS" }, + { (PROC)glMultiTexCoord3fvSGIS, "glMTexCoord3fvSGIS" }, + { (PROC)glMultiTexCoord3iSGIS, "glMTexCoord3iSGIS" }, + { (PROC)glMultiTexCoord3ivSGIS, "glMTexCoord3ivSGIS" }, + { (PROC)glMultiTexCoord3sSGIS, "glMTexCoord3sSGIS" }, + { (PROC)glMultiTexCoord3svSGIS, "glMTexCoord3svSGIS" }, + { (PROC)glMultiTexCoord4dSGIS, "glMTexCoord4dSGIS" }, + { (PROC)glMultiTexCoord4dvSGIS, "glMTexCoord4dvSGIS" }, + { (PROC)glMultiTexCoord4fSGIS, "glMTexCoord4fSGIS" }, + { (PROC)glMultiTexCoord4fvSGIS, "glMTexCoord4fvSGIS" }, + { (PROC)glMultiTexCoord4iSGIS, "glMTexCoord4iSGIS" }, + { (PROC)glMultiTexCoord4ivSGIS, "glMTexCoord4ivSGIS" }, + { (PROC)glMultiTexCoord4sSGIS, "glMTexCoord4sSGIS" }, + { (PROC)glMultiTexCoord4svSGIS, "glMTexCoord4svSGIS" }, + { (PROC)glMultiTexCoordPointerSGIS, "glMTexCoordPointerSGIS" }, + { (PROC)glSelectTextureSGIS, "glSelectTextureSGIS" }, + { (PROC)glSelectTextureCoordSetSGIS, "glSelectTextureCoordSetSGIS" }, +*/ + { (PROC)glActiveTextureARB, "glActiveTextureARB" }, + { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, + { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, + { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, + { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, + { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, + { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, + { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, + { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, + { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, + { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, + { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, + { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, + { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, + { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, + { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, + { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, + { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, + { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, + { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, + { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, + { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, + { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, + { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, + { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, + { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, + { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, + { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, + { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, + { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, + { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, + { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, + { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, + { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, + + // Descent3 doesn't use correct string, hence this hack + { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4f" }, + + // Quake2 SGIS multitexture + { (PROC)gldSelectTextureSGIS, "glSelectTextureSGIS" }, + { (PROC)gldMTexCoord2fSGIS, "glMTexCoord2fSGIS" }, + { (PROC)gldMTexCoord2fvSGIS, "glMTexCoord2fvSGIS" }, + + { NULL, "\0" } +}; + +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_DX( + LPCSTR a) +{ + int i; + PROC proc = NULL; + + for (i=0; GLD_extList[i].proc; i++) { + if (!strcmp(a, GLD_extList[i].name)) { + proc = GLD_extList[i].proc; + break; + } + } + + if (glb.bMultitexture) { + for (i=0; GLD_multitexList[i].proc; i++) { + if (!strcmp(a, GLD_multitexList[i].name)) { + proc = GLD_multitexList[i].proc; + break; + } + } + } + + gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed"); + + return proc; +} + +//--------------------------------------------------------------------------- + +void gldEnableExtensions_DX8( + GLcontext *ctx) +{ + GLuint i; + + // Mesa enables some extensions by default. + // This table decides which ones we want to switch off again. + + // NOTE: GL_EXT_compiled_vertex_array appears broken. + + const char *gld_disable_extensions[] = { +// "GL_ARB_transpose_matrix", +// "GL_EXT_compiled_vertex_array", +// "GL_EXT_polygon_offset", +// "GL_EXT_rescale_normal", + "GL_EXT_texture3D", +// "GL_NV_texgen_reflection", + NULL + }; + + const char *gld_multitex_extensions[] = { + "GL_ARB_multitexture", // Quake 3 + NULL + }; + + // Quake 2 engines + const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture"; + + const char *gld_enable_extensions[] = { + "GL_EXT_texture_env_add", // Quake 3 + "GL_ARB_texture_env_add", // Quake 3 + NULL + }; + + for (i=0; gld_disable_extensions[i]; i++) { + _mesa_disable_extension(ctx, gld_disable_extensions[i]); + } + + for (i=0; gld_enable_extensions[i]; i++) { + _mesa_enable_extension(ctx, gld_enable_extensions[i]); + } + + if (glb.bMultitexture) { + for (i=0; gld_multitex_extensions[i]; i++) { + _mesa_enable_extension(ctx, gld_multitex_extensions[i]); + } + + // GL_SGIS_multitexture + // NOTE: Quake2 ran *slower* with this enabled, so I've + // disabled it for now. + // Fair bit slower on GeForce256, + // Much slower on 3dfx Voodoo5 5500. +// _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0); + + } + + _mesa_enable_imaging_extensions(ctx); + _mesa_enable_1_3_extensions(ctx); + _mesa_enable_1_4_extensions(ctx); +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_dx8.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_dx8.h @@ -0,0 +1,324 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect Direct3D 8.0 header file +* +****************************************************************************/ + +#ifndef _GLD_DX8_H +#define _GLD_DX8_H + +//--------------------------------------------------------------------------- +// Windows includes +//--------------------------------------------------------------------------- + +//#ifndef STRICT +//#define STRICT +//#endif + +//#define WIN32_LEAN_AND_MEAN +//#include +#include +#include + +// MS screwed up with the DX8.1 SDK - there's no compile-time +// method of compiling for 8.0 via the 8.1 SDK unless you +// "make sure you don't use any 8.1 interfaces". +// We CAN use 8.1 D3DX static functions, though - just not new 8.1 interfaces. +// +// D3D_SDK_VERSION is 120 for 8.0 (supported by Windows 95). +// D3D_SDK_VERSION is 220 for 8.1 (NOT supported by Windows 95). +// +#define D3D_SDK_VERSION_DX8_SUPPORT_WIN95 120 + +// Typedef for obtaining function from d3d8.dll +typedef IDirect3D8* (WINAPI *FNDIRECT3DCREATE8) (UINT); + + +//--------------------------------------------------------------------------- +// Defines +//--------------------------------------------------------------------------- + +#ifdef _DEBUG +#define _GLD_TEST_HRESULT(h) \ +{ \ + HRESULT _hr = (h); \ + if (FAILED(_hr)) { \ + gldLogError(GLDLOG_ERROR, #h, _hr); \ + } \ +} +#define _GLD_DX8(func) _GLD_TEST_HRESULT(IDirect3D8_##func##) +#define _GLD_DX8_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice8_##func##) +#define _GLD_DX8_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer8_##func##) +#define _GLD_DX8_TEX(func) _GLD_TEST_HRESULT(IDirect3DTexture8_##func##) +#else +#define _GLD_DX8(func) IDirect3D8_##func +#define _GLD_DX8_DEV(func) IDirect3DDevice8_##func +#define _GLD_DX8_VB(func) IDirect3DVertexBuffer8_##func +#define _GLD_DX8_TEX(func) IDirect3DTexture8_##func +#endif + +#define SAFE_RELEASE(p) \ +{ \ + if (p) { \ + (p)->lpVtbl->Release(p); \ + (p) = NULL; \ + } \ +} + +#define SAFE_RELEASE_VB8(p) \ +{ \ + if (p) { \ + IDirect3DVertexBuffer8_Release((p)); \ + (p) = NULL; \ + } \ +} + +#define SAFE_RELEASE_SURFACE8(p) \ +{ \ + if (p) { \ + IDirect3DSurface8_Release((p)); \ + (p) = NULL; \ + } \ +} + +// Setup index. +enum { + GLD_SI_FLAT = 0, + GLD_SI_SMOOTH = 1, + GLD_SI_FLAT_EXTRAS = 2, + GLD_SI_SMOOTH_EXTRAS = 3, +}; +/* +// Internal pipeline +typedef enum { + GLD_PIPELINE_MESA = 0, // Mesa pipeline + GLD_PIPELINE_D3D_FVF = 1, // Direct3D Fixed-function pipeline + GLD_PIPELINE_D3D_VS_TWOSIDE = 2 // Direct3D two-sided-lighting vertex shader +} GLD_tnl_pipeline; +*/ +//--------------------------------------------------------------------------- +// Vertex definitions for Fixed-Function pipeline +//--------------------------------------------------------------------------- + +// +// NOTE: If the number of texture units is altered then most of +// the texture code will need to be revised. +// + +#define GLD_MAX_TEXTURE_UNITS_DX8 2 + +// +// 2D vertex transformed by Mesa +// +#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \ + D3DFVF_DIFFUSE | \ + D3DFVF_SPECULAR | \ + D3DFVF_TEX2) +typedef struct { + FLOAT x, y; // 2D raster coords + FLOAT sz; // Screen Z (depth) + FLOAT rhw; // Reciprocal homogenous W + DWORD diffuse; // Diffuse colour + DWORD specular; // For separate-specular support + FLOAT t0_u, t0_v; // 1st set of texture coords + FLOAT t1_u, t1_v; // 2nd set of texture coords +} GLD_2D_VERTEX; + + +// +// 3D vertex transformed by Direct3D +// +#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \ + D3DFVF_DIFFUSE | \ + D3DFVF_TEX2) + +typedef struct { + D3DXVECTOR3 Position; // XYZ Vector in object space + D3DCOLOR Diffuse; // Diffuse colour + D3DXVECTOR2 TexUnit0; // Texture unit 0 + D3DXVECTOR2 TexUnit1; // Texture unit 1 +} GLD_3D_VERTEX; + +//--------------------------------------------------------------------------- +// Vertex Shaders +//--------------------------------------------------------------------------- +/* +// DX8 Vertex Shader +typedef struct { + DWORD hShader; // If NULL, shader is invalid and cannot be used + BOOL bHardware; // If TRUE then shader was created for hardware, + // otherwise shader was created for software. +} GLD_vertexShader; +*/ +//--------------------------------------------------------------------------- +// Structs +//--------------------------------------------------------------------------- + +// This keeps a count of how many times we choose each individual internal +// pathway. Useful for seeing if a certain pathway was ever used by an app, and +// how much each pathway is biased. +// Zero the members at context creation and dump stats at context deletion. +typedef struct { + // Note: DWORD is probably too small + ULARGE_INTEGER qwMesa; // Mesa TnL pipeline + ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline +// ULARGE_INTEGER dwD3D2SVS; // Direct3D Two-Sided Vertex Shader pipeline +} GLD_pipeline_usage; + +// GLDirect Primitive Buffer (points, lines, triangles and quads) +typedef struct { + // Data for IDirect3DDevice8::CreateVertexBuffer() + DWORD dwStride; // Stride of vertex + DWORD dwUsage; // Usage flags + DWORD dwFVF; // Direct3D Flexible Vertex Format + DWORD dwPool; // Pool flags + + IDirect3DVertexBuffer8 *pVB; // Holds points, lines, tris and quads. + + // Point list is assumed to be at start of buffer + DWORD iFirstLine; // Index of start of line list + DWORD iFirstTriangle; // Index of start of triangle list + + BYTE *pPoints; // Pointer to next free point + BYTE *pLines; // Pointer to next free line + BYTE *pTriangles; // Pointer to next free triangle + + DWORD nPoints; // Number of points ready to render + DWORD nLines; // Number of lines ready to render + DWORD nTriangles; // Number of triangles ready to render +} GLD_pb_dx8; + +// GLDirect DX8 driver data +typedef struct { + // GLDirect vars + BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered) + BOOL bDepthStencil; // Depth buffer needed (stencil optional) + D3DFORMAT RenderFormat; // Format of back/front buffer + D3DFORMAT DepthFormat; // Format of depth/stencil +// float fFlipWindowY; // Value for flipping viewport Y coord + + // Direct3D vars + D3DCAPS8 d3dCaps8; + BOOL bHasHWTnL; // Device has Hardware Transform/Light? + IDirect3D8 *pD3D; // Base Direct3D8 interface + IDirect3DDevice8 *pDev; // Direct3D8 Device interface + GLD_pb_dx8 PB2d; // Vertices transformed by Mesa + GLD_pb_dx8 PB3d; // Vertices transformed by Direct3D + D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type + D3DXMATRIX matProjection; // Projection matrix for D3D TnL + D3DXMATRIX matModelView; // Model/View matrix for D3D TnL + int iSetupFunc; // Which setup functions to use + BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL + + // Direct3D vars for two-sided lighting +// GLD_vertexShader VStwosidelight; // Vertex Shader for two-sided lighting +// D3DXMATRIX matWorldViewProj;// World/View/Projection matrix for shaders + + +// GLD_tnl_pipeline TnLPipeline; // Index of current internal pipeline + GLD_pipeline_usage PipelineUsage; +} GLD_driver_dx8; + +#define GLD_GET_DX8_DRIVER(c) (GLD_driver_dx8*)(c)->glPriv + +//--------------------------------------------------------------------------- +// Function prototypes +//--------------------------------------------------------------------------- + +PROC gldGetProcAddress_DX8(LPCSTR a); +void gldEnableExtensions_DX8(GLcontext *ctx); +void gldInstallPipeline_DX8(GLcontext *ctx); +void gldSetupDriverPointers_DX8(GLcontext *ctx); +//void gldResizeBuffers_DX8(GLcontext *ctx); +void gldResizeBuffers_DX8(GLframebuffer *fb); + + +// Texture functions + +void gldCopyTexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border); +void gldCopyTexImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +void gldCopyTexSubImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ); +void gldCopyTexSubImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); +void gldCopyTexSubImage3D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); + +void gld_NEW_TEXTURE_DX8(GLcontext *ctx); +void gld_DrawPixels_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels); +void gld_ReadPixels_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest); +void gld_CopyPixels_DX8(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type); +void gld_Bitmap_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap); +const struct gl_texture_format* gld_ChooseTextureFormat_DX8(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType); +void gld_TexImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage); +void gld_TexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); +void gld_TexSubImage2D_DX8( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage ); +void gld_TexSubImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage); +void gld_DeleteTexture_DX8(GLcontext *ctx, struct gl_texture_object *tObj); +void gld_ResetLineStipple_DX8(GLcontext *ctx); + +// 2D primitive functions + +void gld_Points2D_DX8(GLcontext *ctx, GLuint first, GLuint last); + +void gld_Line2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Line2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1); + +void gld_Triangle2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DFlatExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmoothExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); + +void gld_Quad2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DFlatExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmoothExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +// 3D primitive functions + +void gld_Points3D_DX8(GLcontext *ctx, GLuint first, GLuint last); +void gld_Line3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Line3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +// Primitive functions for Two-sided-lighting Vertex Shader + +void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last); +void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1); +void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2); +void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3); + +#endif --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_vb_d3d_render_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_vb_d3d_render_dx8.c @@ -0,0 +1,249 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: GLDirect fastpath pipeline stage +* +****************************************************************************/ + +//--------------------------------------------------------------------------- + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx8.h" + +//--------------------------------------------------------------------------- + +#include "glheader.h" +#include "context.h" +#include "macros.h" +// #include "mem.h" +#include "mtypes.h" +//#include "mmath.h" + +#include "math/m_matrix.h" +#include "math/m_xform.h" + +#include "tnl/t_pipeline.h" + +//--------------------------------------------------------------------------- + +__inline void _gldSetVertexShaderConstants( + GLcontext *ctx, + GLD_driver_dx8 *gld) +{ + D3DXMATRIX mat, matView, matProj; + GLfloat *pM; + + // Mesa 5: Altered to a Stack + //pM = ctx->ModelView.m; + pM = ctx->ModelviewMatrixStack.Top->m; + matView._11 = pM[0]; + matView._12 = pM[1]; + matView._13 = pM[2]; + matView._14 = pM[3]; + matView._21 = pM[4]; + matView._22 = pM[5]; + matView._23 = pM[6]; + matView._24 = pM[7]; + matView._31 = pM[8]; + matView._32 = pM[9]; + matView._33 = pM[10]; + matView._34 = pM[11]; + matView._41 = pM[12]; + matView._42 = pM[13]; + matView._43 = pM[14]; + matView._44 = pM[15]; + + // Mesa 5: Altered to a Stack + //pM = ctx->ProjectionMatrix.m; + pM = ctx->ProjectionMatrixStack.Top->m; + matProj._11 = pM[0]; + matProj._12 = pM[1]; + matProj._13 = pM[2]; + matProj._14 = pM[3]; + matProj._21 = pM[4]; + matProj._22 = pM[5]; + matProj._23 = pM[6]; + matProj._24 = pM[7]; + matProj._31 = pM[8]; + matProj._32 = pM[9]; + matProj._33 = pM[10]; + matProj._34 = pM[11]; + matProj._41 = pM[12]; + matProj._42 = pM[13]; + matProj._43 = pM[14]; + matProj._44 = pM[15]; + + D3DXMatrixMultiply( &mat, &matView, &matProj ); + D3DXMatrixTranspose( &mat, &mat ); + + _GLD_DX8_DEV(SetVertexShaderConstant(gld->pDev, 0, &mat, 4)); +} + +//--------------------------------------------------------------------------- + +static GLboolean gld_d3d_render_stage_run( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + TNLcontext *tnl; + struct vertex_buffer *VB; + tnl_render_func *tab; + GLint pass; + GLD_pb_dx8 *gldPB = &gld->PB3d; +/* + static int count = 0; + count++; + if (count != 2) + return GL_FALSE; +*/ + // The "check" function should disable this stage, + // but we'll test gld->bUseMesaTnL anyway. + if (gld->bUseMesaTnL) { + // Do nothing in this stage, but continue pipeline + return GL_TRUE; + } + + tnl = TNL_CONTEXT(ctx); + VB = &tnl->vb; + pass = 0; + + tnl->Driver.Render.Start( ctx ); + +#if 0 + // For debugging: Useful to see if an app passes colour data in + // an unusual format. + switch (VB->ColorPtr[0]->Type) { + case GL_FLOAT: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_FLOAT\n"); + break; + case GL_UNSIGNED_BYTE: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: GL_UNSIGNED_BYTE\n"); + break; + default: + ddlogMessage(GLDLOG_SYSTEM, "ColorPtr: *?*\n"); + break; + } +#endif + + tnl->Driver.Render.Points = gld_Points3D_DX8; + if (ctx->_TriangleCaps & DD_FLATSHADE) { + tnl->Driver.Render.Line = gld_Line3DFlat_DX8; + tnl->Driver.Render.Triangle = gld_Triangle3DFlat_DX8; + tnl->Driver.Render.Quad = gld_Quad3DFlat_DX8; + } else { + tnl->Driver.Render.Line = gld_Line3DSmooth_DX8; + tnl->Driver.Render.Triangle = gld_Triangle3DSmooth_DX8; + tnl->Driver.Render.Quad = gld_Quad3DSmooth_DX8; + } + + _GLD_DX8_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); + gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; + // Allocate primitive pointers + // gldPB->pPoints is always first + gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); + gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); + + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); + + tab = (VB->Elts ? tnl->Driver.Render.PrimTabElts : tnl->Driver.Render.PrimTabVerts); + + do { + GLuint i, length, flags = 0; + for (i = 0 ; !(flags & PRIM_END) ; i += length) + { + flags = VB->Primitive[i].mode; + length= VB->Primitive[i].count; + ASSERT(length || (flags & PRIM_END)); + ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + if (length) + tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + } + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + + _GLD_DX8_VB(Unlock(gldPB->pVB)); + + _GLD_DX8_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, gldPB->dwStride)); + + _GLD_DX8_DEV(SetTransform(gld->pDev, D3DTS_PROJECTION, &gld->matProjection)); + _GLD_DX8_DEV(SetTransform(gld->pDev, D3DTS_WORLD, &gld->matModelView)); + + if (gldPB->nPoints) { + _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); + gldPB->nPoints = 0; + } + + if (gldPB->nLines) { + _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); + gldPB->nLines = 0; + } + + if (gldPB->nTriangles) { + _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); + gldPB->nTriangles = 0; + } + + return GL_FALSE; /* finished the pipe */ +} + +//--------------------------------------------------------------------------- + +const struct tnl_pipeline_stage _gld_d3d_render_stage = +{ + "gld_d3d_render_stage", + NULL, + NULL, + NULL, + NULL, + gld_d3d_render_stage_run /* run */ +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_vb_mesa_render_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_vb_mesa_render_dx8.c @@ -0,0 +1,449 @@ +/* $Id: gld_vb_mesa_render_dx8.c,v 1.6 2005/08/27 13:56:08 brianp Exp $ */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * Copyright (C) 1999-2001 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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. + * + * Authors: + * Keith Whitwell + */ + + +/* + * Render whole vertex buffers, including projection of vertices from + * clip space and clipping of primitives. + * + * This file makes calls to project vertices and to the point, line + * and triangle rasterizers via the function pointers: + * + * context->Driver.Render.* + * + */ + + +//--------------------------------------------------------------------------- + +//#include "../GLDirect.h" +//#include "../gld_log.h" +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx8.h" + +//--------------------------------------------------------------------------- + +#include "glheader.h" +#include "context.h" +#include "macros.h" +// #include "mem.h" +#include "mtypes.h" +//#include "mmath.h" + +#include "math/m_matrix.h" +#include "math/m_xform.h" + +#include "tnl/t_pipeline.h" + +/**********************************************************************/ +/* Clip single primitives */ +/**********************************************************************/ + + +#if defined(USE_IEEE) +#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) +//#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) +#else +#define NEGATIVE(x) (x < 0) +//#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) +/* Could just use (x*y<0) except for the flatshading requirements. + * Maybe there's a better way? + */ +#endif + + +#define W(i) coord[i][3] +#define Z(i) coord[i][2] +#define Y(i) coord[i][1] +#define X(i) coord[i][0] +#define SIZE 4 +#define TAG(x) x##_4 +#include "tnl/t_vb_cliptmp.h" + + + +/**********************************************************************/ +/* Clip and render whole begin/end objects */ +/**********************************************************************/ + +#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] +#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val + + +/* Vertices, with the possibility of clipping. + */ +#define RENDER_POINTS( start, count ) \ + tnl->Driver.Render.Points( ctx, start, count ) + +#define RENDER_LINE( v1, v2 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2]; \ + GLubyte ormask = c1|c2; \ + if (!ormask) \ + LineFunc( ctx, v1, v2 ); \ + else if (!(c1 & c2 & 0x3f)) \ + clip_line_4( ctx, v1, v2, ormask ); \ +} while (0) + +#define RENDER_TRI( v1, v2, v3 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ + GLubyte ormask = c1|c2|c3; \ + if (!ormask) \ + TriangleFunc( ctx, v1, v2, v3 ); \ + else if (!(c1 & c2 & c3 & 0x3f)) \ + clip_tri_4( ctx, v1, v2, v3, ormask ); \ +} while (0) + +#define RENDER_QUAD( v1, v2, v3, v4 ) \ +do { \ + GLubyte c1 = mask[v1], c2 = mask[v2]; \ + GLubyte c3 = mask[v3], c4 = mask[v4]; \ + GLubyte ormask = c1|c2|c3|c4; \ + if (!ormask) \ + QuadFunc( ctx, v1, v2, v3, v4 ); \ + else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ + clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ +} while (0) + + +#define LOCAL_VARS \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + const GLuint * const elt = VB->Elts; \ + const GLubyte *mask = VB->ClipMask; \ + const GLuint sz = VB->ClipPtr->size; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + const GLboolean stipple = ctx->Line.StippleFlag; \ + (void) (LineFunc && TriangleFunc && QuadFunc); \ + (void) elt; (void) mask; (void) sz; (void) stipple; + +#define TAG(x) clip_##x##_verts +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) +#define PRESERVE_VB_DEFS +#include "tnl/t_vb_rendertmp.h" + + + +/* Elts, with the possibility of clipping. + */ +#undef ELT +#undef TAG +#define ELT(x) elt[x] +#define TAG(x) clip_##x##_elts +#include "tnl/t_vb_rendertmp.h" + +/* TODO: do this for all primitives, verts and elts: + */ +static void clip_elt_triangles( GLcontext *ctx, + GLuint start, + GLuint count, + GLuint flags ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; + struct vertex_buffer *VB = &tnl->vb; + const GLuint * const elt = VB->Elts; + GLubyte *mask = VB->ClipMask; + GLuint last = count-2; + GLuint j; + (void) flags; + + tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); + + for (j=start; j < last; j+=3 ) { + GLubyte c1 = mask[elt[j]]; + GLubyte c2 = mask[elt[j+1]]; + GLubyte c3 = mask[elt[j+2]]; + GLubyte ormask = c1|c2|c3; + if (ormask) { + if (start < j) + render_tris( ctx, start, j, 0 ); + if (!(c1&c2&c3&0x3f)) + clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); + start = j+3; + } + } + + if (start < j) + render_tris( ctx, start, j, 0 ); +} + +/**********************************************************************/ +/* Render whole begin/end objects */ +/**********************************************************************/ + +#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] +#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val + + +/* Vertices, no clipping. + */ +#define RENDER_POINTS( start, count ) \ + tnl->Driver.Render.Points( ctx, start, count ) + +#define RENDER_LINE( v1, v2 ) \ + LineFunc( ctx, v1, v2 ) + +#define RENDER_TRI( v1, v2, v3 ) \ + TriangleFunc( ctx, v1, v2, v3 ) + +#define RENDER_QUAD( v1, v2, v3, v4 ) \ + QuadFunc( ctx, v1, v2, v3, v4 ) + +#define TAG(x) _gld_tnl_##x##_verts + +#define LOCAL_VARS \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + const GLuint * const elt = VB->Elts; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + (void) (LineFunc && TriangleFunc && QuadFunc); \ + (void) elt; + +#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx ) +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RENDER_TAB_QUALIFIER +#define PRESERVE_VB_DEFS +#include "tnl/t_vb_rendertmp.h" + + +/* Elts, no clipping. + */ +#undef ELT +#define TAG(x) _gld_tnl_##x##_elts +#define ELT(x) elt[x] +#include "tnl/t_vb_rendertmp.h" + + +/**********************************************************************/ +/* Helper functions for drivers */ +/**********************************************************************/ +/* +void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + GLuint *tmp = VB->Elts; + + VB->Elts = (GLuint *)elts; + tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); + VB->Elts = tmp; +} + +void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl->Driver.Render.Line( ctx, ii, jj ); +} +*/ + + +/**********************************************************************/ +/* Clip and render whole vertex buffers */ +/**********************************************************************/ + +tnl_points_func _gldSetupPoints[4] = { + gld_Points2D_DX8, + gld_Points2D_DX8, + gld_Points2D_DX8, + gld_Points2D_DX8 +}; +tnl_line_func _gldSetupLine[4] = { + gld_Line2DFlat_DX8, + gld_Line2DSmooth_DX8, + gld_Line2DFlat_DX8, + gld_Line2DSmooth_DX8, +}; +tnl_triangle_func _gldSetupTriangle[4] = { + gld_Triangle2DFlat_DX8, + gld_Triangle2DSmooth_DX8, + gld_Triangle2DFlatExtras_DX8, + gld_Triangle2DSmoothExtras_DX8 +}; +tnl_quad_func _gldSetupQuad[4] = { + gld_Quad2DFlat_DX8, + gld_Quad2DSmooth_DX8, + gld_Quad2DFlatExtras_DX8, + gld_Quad2DSmoothExtras_DX8 +}; + +//--------------------------------------------------------------------------- + +static GLboolean _gld_mesa_render_stage_run( + GLcontext *ctx, + struct tnl_pipeline_stage *stage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + tnl_render_func *tab; + GLint pass = 0; + GLD_pb_dx8 *gldPB; + + /* Allow the drivers to lock before projected verts are built so + * that window coordinates are guarenteed not to change before + * rendering. + */ + ASSERT(tnl->Driver.Render.Start); + + tnl->Driver.Render.Start( ctx ); + + // NOTE: Setting D3DRS_SOFTWAREVERTEXPROCESSING for a mixed-mode device resets + // stream, indices and shader to default values of NULL or 0. +/* if ((ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) && + gld->VStwosidelight.hShader && + !ctx->Fog.Enabled) + { + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware); + _GLD_DX8_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); + gldPB = &gld->PBtwosidelight; + tnl->Driver.Render.Points = gld_Points2DTwoside_DX8; + if (ctx->_TriangleCaps & DD_FLATSHADE) { + tnl->Driver.Render.Line = gld_Line2DFlatTwoside_DX8; + tnl->Driver.Render.Triangle = gld_Triangle2DFlatTwoside_DX8; + tnl->Driver.Render.Quad = gld_Quad2DFlatTwoside_DX8; + } else { + tnl->Driver.Render.Line = gld_Line2DSmoothTwoside_DX8; + tnl->Driver.Render.Triangle = gld_Triangle2DSmoothTwoside_DX8; + tnl->Driver.Render.Quad = gld_Quad2DSmoothTwoside_DX8; + } + } else {*/ + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE); + gldPB = &gld->PB2d; + _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); + tnl->Driver.Render.Points = _gldSetupPoints[gld->iSetupFunc]; + tnl->Driver.Render.Line = _gldSetupLine[gld->iSetupFunc]; + tnl->Driver.Render.Triangle = _gldSetupTriangle[gld->iSetupFunc]; + tnl->Driver.Render.Quad = _gldSetupQuad[gld->iSetupFunc]; +// } + + _GLD_DX8_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD)); + gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0; + // Allocate primitive pointers + // gldPB->pPoints is always first + gldPB->pLines = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine); + gldPB->pTriangles = gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle); + + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); + + tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); + + if (VB->ClipOrMask) { + tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; + clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; + } + else { + tab = (VB->Elts ? + tnl->Driver.Render.PrimTabElts : + tnl->Driver.Render.PrimTabVerts); + } + + do { + GLuint i, length, flags = 0; + for (i = 0 ; !(flags & PRIM_END) ; i += length) { + flags = VB->Primitive[i].mode; + length= VB->Primitive[i].count; + ASSERT(length || (flags & PRIM_END)); + ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + if (length) + tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + } + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + + +// tnl->Driver.Render.Finish( ctx ); + + _GLD_DX8_VB(Unlock(gldPB->pVB)); + + _GLD_DX8_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, gldPB->dwStride)); + + if (gldPB->nPoints) { + _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints)); + gldPB->nPoints = 0; + } + + if (gldPB->nLines) { + _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines)); + gldPB->nLines = 0; + } + + if (gldPB->nTriangles) { + _GLD_DX8_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles)); + gldPB->nTriangles = 0; + } + + return GL_FALSE; /* finished the pipe */ +} + + +/**********************************************************************/ +/* Render pipeline stage */ +/**********************************************************************/ + + + + +//--------------------------------------------------------------------------- + +const struct tnl_pipeline_stage _gld_mesa_render_stage = +{ + "gld_mesa_render_stage", + NULL, + NULL, + NULL, + NULL, + _gld_mesa_render_stage_run /* run */ +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_primitive_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_primitive_dx8.c @@ -0,0 +1,1446 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Primitive (points/lines/tris/quads) rendering +* +****************************************************************************/ + +//#include "../GLDirect.h" + +//#include "gld_dx8.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx8.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "swrast/s_context.h" +#include "swrast/s_depth.h" +#include "swrast/s_lines.h" +#include "swrast/s_triangle.h" +#include "swrast/s_trispan.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +// Disable compiler complaints about unreferenced local variables +#pragma warning (disable:4101) + +//--------------------------------------------------------------------------- +// Helper defines for primitives +//--------------------------------------------------------------------------- + +//static const float ooZ = 1.0f / 65536.0f; // One over Z + +#define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3])) +#define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3])) +#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) + +//--------------------------------------------------------------------------- +// 2D vertex setup +//--------------------------------------------------------------------------- + +#define GLD_SETUP_2D_VARS_POINTS \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour + +#define GLD_SETUP_2D_VARS_LINES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour + +#define GLD_SETUP_2D_VARS_TRIANGLES \ + BOOL bFog = ctx->Fog.Enabled; \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ + GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \ + SScontext *ss = SWSETUP_CONTEXT(ctx); \ + SWvertex *swv; \ + DWORD dwSpecularColour; \ + DWORD dwFlatColour; \ + GLuint facing = 0; \ + struct vertex_buffer *VB; \ + GLchan (*vbcolor)[4]; \ + GLchan (*vbspec)[4] + +#define GLD_SETUP_GET_SWVERT(s) \ + swv = &ss->verts[##s] + +#define GLD_SETUP_2D_VERTEX \ + pV->x = swv->win[0]; \ + pV->y = GLD_FLIP_Y(swv->win[1]); \ + pV->rhw = swv->win[3] + +#define GLD_SETUP_SMOOTH_COLOUR \ + pV->diffuse = GLD_COLOUR + +#define GLD_SETUP_GET_FLAT_COLOUR \ + dwFlatColour = GLD_COLOUR +#define GLD_SETUP_GET_FLAT_FOG_COLOUR \ + dwFlatColour = _gldComputeFog(ctx, swv) + +#define GLD_SETUP_USE_FLAT_COLOUR \ + pV->diffuse = dwFlatColour + +#define GLD_SETUP_GET_FLAT_SPECULAR \ + dwSpecularColour= GLD_SPECULAR + +#define GLD_SETUP_USE_FLAT_SPECULAR \ + pV->specular = dwSpecularColour + +#define GLD_SETUP_DEPTH \ + pV->sz = swv->win[2] / ctx->DepthMaxF +// pV->z = swv->win[2] * ooZ; + +#define GLD_SETUP_SPECULAR \ + pV->specular = GLD_SPECULAR + +#define GLD_SETUP_FOG \ + pV->diffuse = _gldComputeFog(ctx, swv) + +#define GLD_SETUP_TEX0 \ + pV->t0_u = swv->texcoord[0][0]; \ + pV->t0_v = swv->texcoord[0][1] + +#define GLD_SETUP_TEX1 \ + pV->t1_u = swv->texcoord[1][0]; \ + pV->t1_v = swv->texcoord[1][1] + +#define GLD_SETUP_LIGHTING(v) \ + if (facing == 1) { \ + pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ + if (vbspec) { \ + pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ + } \ + } else { \ + if (bFog) \ + GLD_SETUP_FOG; \ + else \ + GLD_SETUP_SMOOTH_COLOUR; \ + GLD_SETUP_SPECULAR; \ + } + +#define GLD_SETUP_GET_FLAT_LIGHTING(v) \ + if (facing == 1) { \ + dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \ + if (vbspec) { \ + dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \ + } \ + } + +#define GLD_SETUP_TWOSIDED_LIGHTING \ + /* Two-sided lighting */ \ + if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \ + SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \ + SWvertex *v[3]; \ + GLfloat ex,ey,fx,fy,cc; \ + /* Get vars for later */ \ + VB = &TNL_CONTEXT(ctx)->vb; \ + vbcolor = (GLchan (*)[4])VB->ColorPtr[1]->data; \ + if (VB->SecondaryColorPtr[1]) { \ + vbspec = (GLchan (*)[4])VB->SecondaryColorPtr[1]->data; \ + } else { \ + vbspec = NULL; \ + } \ + v[0] = &verts[v0]; \ + v[1] = &verts[v1]; \ + v[2] = &verts[v2]; \ + ex = v[0]->win[0] - v[2]->win[0]; \ + ey = v[0]->win[1] - v[2]->win[1]; \ + fx = v[1]->win[0] - v[2]->win[0]; \ + fy = v[1]->win[1] - v[2]->win[1]; \ + cc = ex*fy - ey*fx; \ + facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \ + } + +//--------------------------------------------------------------------------- +// 3D vertex setup +//--------------------------------------------------------------------------- + +#define GLD_SETUP_3D_VARS_POINTS \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VARS_LINES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VARS_TRIANGLES \ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \ + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); \ + GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \ + TNLcontext *tnl = TNL_CONTEXT(ctx); \ + struct vertex_buffer *VB = &tnl->vb; \ + GLfloat (*p4f)[4]; \ + GLfloat (*tc)[4]; \ + DWORD dwColor; + +#define GLD_SETUP_3D_VERTEX(v) \ + p4f = VB->ObjPtr->data; \ + pV->Position.x = p4f[##v][0]; \ + pV->Position.y = p4f[##v][1]; \ + pV->Position.z = p4f[##v][2]; + +#define GLD_SETUP_SMOOTH_COLOUR_3D(v) \ + p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ + pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); + + +#define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \ + p4f = (GLfloat (*)[4])VB->ColorPtr[0]->data; \ + dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]); + +#define GLD_SETUP_USE_FLAT_COLOUR_3D \ + pV->Diffuse = dwColor; + +#define GLD_SETUP_TEX0_3D(v) \ + if (VB->TexCoordPtr[0]) { \ + tc = VB->TexCoordPtr[0]->data; \ + pV->TexUnit0.x = tc[##v][0]; \ + pV->TexUnit0.y = tc[##v][1]; \ + } + +#define GLD_SETUP_TEX1_3D(v) \ + if (VB->TexCoordPtr[1]) { \ + tc = VB->TexCoordPtr[1]->data; \ + pV->TexUnit1.x = tc[##v][0]; \ + pV->TexUnit1.y = tc[##v][1]; \ + } + +//--------------------------------------------------------------------------- +// Helper functions +//--------------------------------------------------------------------------- + +__inline DWORD _gldComputeFog( + GLcontext *ctx, + SWvertex *swv) +{ + // Full fog calculation. + // Based on Mesa code. + + GLchan rFog, gFog, bFog; + GLchan fR, fG, fB; + const GLfloat f = swv->fog; + const GLfloat g = 1.0f - f; + + UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); + fR = f * swv->color[0] + g * rFog; + fG = f * swv->color[1] + g * gFog; + fB = f * swv->color[2] + g * bFog; + return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]); +} + +//--------------------------------------------------------------------------- + +void gld_ResetLineStipple_DX8( + GLcontext *ctx) +{ + // TODO: Fake stipple with a 32x32 texture. +} + +//--------------------------------------------------------------------------- +// 2D (post-transformed) primitives +//--------------------------------------------------------------------------- + +void gld_Points2D_DX8( + GLcontext *ctx, + GLuint first, + GLuint last) +{ + GLD_SETUP_2D_VARS_POINTS; + + unsigned i; + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + // _Size is already clamped to MaxPointSize and MinPointSize + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); + + if (VB->Elts) { + for (i=first; iClipMask[VB->Elts[i]] == 0) { +// _swrast_Point( ctx, &verts[VB->Elts[i]] ); + GLD_SETUP_GET_SWVERT(VB->Elts[i]); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + } + } + } else { + GLD_SETUP_GET_SWVERT(first); + for (i=first; iClipMask[i] == 0) { +// _swrast_Point( ctx, &verts[i] ); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + } + } + } + + gld->PB2d.pPoints = (BYTE*)pV; + gld->PB2d.nPoints += (last-first); +} + +//--------------------------------------------------------------------------- + +void gld_Line2DFlat_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_2D_VARS_LINES; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pLines = (BYTE*)pV; + gld->PB2d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Line2DSmooth_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_2D_VARS_LINES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_SPECULAR; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_SPECULAR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pLines = (BYTE*)pV; + gld->PB2d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlat_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + pV++;; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmooth_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlatExtras_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v2); + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + if (bFog) + GLD_SETUP_GET_FLAT_FOG_COLOUR; + else + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_GET_FLAT_LIGHTING(v2); + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmoothExtras_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v0); + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v1); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlat_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmooth_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_SMOOTH_COLOUR; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlatExtras_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v3); + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + if (bFog) + GLD_SETUP_GET_FLAT_FOG_COLOUR; + else + GLD_SETUP_GET_FLAT_COLOUR; + GLD_SETUP_GET_FLAT_SPECULAR; + GLD_SETUP_GET_FLAT_LIGHTING(v3); + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_USE_FLAT_COLOUR; + GLD_SETUP_USE_FLAT_SPECULAR; + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmoothExtras_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_2D_VARS_TRIANGLES; + + GLD_SETUP_TWOSIDED_LIGHTING(v0); + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + GLD_SETUP_GET_SWVERT(v1); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v1); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + GLD_SETUP_GET_SWVERT(v2); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v2); + pV++; + + GLD_SETUP_GET_SWVERT(v3); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v3); + pV++; + + GLD_SETUP_GET_SWVERT(v0); + GLD_SETUP_2D_VERTEX; + GLD_SETUP_DEPTH; + GLD_SETUP_TEX0; + GLD_SETUP_TEX1; + GLD_SETUP_LIGHTING(v0); + pV++; + + gld->PB2d.pTriangles = (BYTE*)pV; + gld->PB2d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- +// 3D (pre-transformed) primitives +//--------------------------------------------------------------------------- + +void gld_Points3D_DX8( + GLcontext *ctx, + GLuint first, + GLuint last) +{ + GLD_SETUP_3D_VARS_POINTS + + unsigned i; +// struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + // _Size is already clamped to MaxPointSize and MinPointSize + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size)); + + if (VB->Elts) { + for (i=first; iClipMask[VB->Elts[i]] == 0) { +// _swrast_Point( ctx, &verts[VB->Elts[i]] ); +// GLD_SETUP_GET_SWVERT(VB->Elts[i]); + GLD_SETUP_3D_VERTEX(VB->Elts[i]) + GLD_SETUP_SMOOTH_COLOUR_3D(i) + GLD_SETUP_TEX0_3D(i) + GLD_SETUP_TEX1_3D(i) + } + } + } else { +// GLD_SETUP_GET_SWVERT(first); + for (i=first; iClipMask[i] == 0) { +// _swrast_Point( ctx, &verts[i] ); + GLD_SETUP_3D_VERTEX(i) + GLD_SETUP_SMOOTH_COLOUR_3D(i) + GLD_SETUP_TEX0_3D(i) + GLD_SETUP_TEX1_3D(i) + } + } + } +/* + for (i=first; iPB3d.pPoints = (BYTE*)pV; + gld->PB3d.nPoints += (last-first); +} + +//--------------------------------------------------------------------------- +// Line functions +//--------------------------------------------------------------------------- + +void gld_Line3DFlat_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_3D_VARS_LINES + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_GET_FLAT_COLOUR_3D(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pLines = (BYTE*)pV; + gld->PB3d.nLines++; +} + +//--------------------------------------------------------------------------- + +void gld_Line3DSmooth_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1) +{ + GLD_SETUP_3D_VARS_LINES + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pLines = (BYTE*)pV; + gld->PB3d.nLines++; +} + +//--------------------------------------------------------------------------- +// Triangle functions +//--------------------------------------------------------------------------- + +void gld_Triangle3DFlat_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + GLD_SETUP_GET_FLAT_COLOUR_3D(v2) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Triangle3DSmooth_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles++; +} + +//--------------------------------------------------------------------------- +// Quad functions +//--------------------------------------------------------------------------- + +void gld_Quad3DFlat_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_GET_FLAT_COLOUR_3D(v3) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_USE_FLAT_COLOUR_3D + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad3DSmooth_DX8( + GLcontext *ctx, + GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + GLD_SETUP_3D_VARS_TRIANGLES + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + GLD_SETUP_3D_VERTEX(v1) + GLD_SETUP_SMOOTH_COLOUR_3D(v1) + GLD_SETUP_TEX0_3D(v1) + GLD_SETUP_TEX1_3D(v1) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v2) + GLD_SETUP_SMOOTH_COLOUR_3D(v2) + GLD_SETUP_TEX0_3D(v2) + GLD_SETUP_TEX1_3D(v2) + pV++; + + GLD_SETUP_3D_VERTEX(v3) + GLD_SETUP_SMOOTH_COLOUR_3D(v3) + GLD_SETUP_TEX0_3D(v3) + GLD_SETUP_TEX1_3D(v3) + pV++; + + GLD_SETUP_3D_VERTEX(v0) + GLD_SETUP_SMOOTH_COLOUR_3D(v0) + GLD_SETUP_TEX0_3D(v0) + GLD_SETUP_TEX1_3D(v0) + pV++; + + gld->PB3d.pTriangles = (BYTE*)pV; + gld->PB3d.nTriangles += 2; +} + +//--------------------------------------------------------------------------- +// Vertex setup for two-sided-lighting vertex shader +//--------------------------------------------------------------------------- + +/* + +void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last) +{ + // NOTE: Two-sided lighting does not apply to Points +} + +//--------------------------------------------------------------------------- + +void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) +{ + // NOTE: Two-sided lighting does not apply to Lines +} + +//--------------------------------------------------------------------------- + +void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1) +{ + // NOTE: Two-sided lighting does not apply to Lines +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) +{ +} + +//--------------------------------------------------------------------------- + +void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles++; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 4th vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 5th vert + swv = &ss->verts[v3]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 6th vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles; + SScontext *ss = SWSETUP_CONTEXT(ctx); + SWvertex *swv; + DWORD dwSpecularColour; + DWORD dwFlatColour; + GLuint facing = 0; + struct vertex_buffer *VB; + GLchan (*vbcolor)[4]; + GLchan (*vbspec)[4]; + + // Reciprocal of DepthMax + const float ooDepthMax = 1.0f / ctx->DepthMaxF; + + // 1st vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 2nd vert + swv = &ss->verts[v1]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 3rd vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 4th vert + swv = &ss->verts[v2]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 5th vert + swv = &ss->verts[v3]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + // 6th vert + swv = &ss->verts[v0]; + pV->Position.x = swv->win[0]; + pV->Position.y = GLD_FLIP_Y(swv->win[1]); + pV->Position.z = swv->win[2] * ooDepthMax; + pV->Position.w = swv->win[3]; + pV->TexUnit0.x = swv->texcoord[0][0]; + pV->TexUnit0.y = swv->texcoord[0][1]; + pV->TexUnit1.x = swv->texcoord[1][0]; + pV->TexUnit1.y = swv->texcoord[1][1]; + pV->FrontDiffuse = GLD_COLOUR; + pV->FrontSpecular = GLD_SPECULAR; + pV++; + + gld->PBtwosidelight.pTriangles = (BYTE*)pV; + gld->PBtwosidelight.nTriangles += 2; +} + +//--------------------------------------------------------------------------- + +*/ --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_dxerr8.h +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_dxerr8.h @@ -0,0 +1,77 @@ +/*==========================================================================; + * + * + * File: dxerr8.h + * Content: DirectX Error Library Include File + * + ****************************************************************************/ + +#ifndef _GLD_DXERR8_H_ +#define _GLD_DXERR8_H_ + + +#include + +// +// DXGetErrorString8 +// +// Desc: Converts an DirectX HRESULT to a string +// +// Args: HRESULT hr Can be any error code from +// DPLAY D3D8 D3DX8 DMUSIC DSOUND +// +// Return: Converted string +// +const char* __stdcall DXGetErrorString8A(HRESULT hr); +const WCHAR* __stdcall DXGetErrorString8W(HRESULT hr); + +#ifdef UNICODE + #define DXGetErrorString8 DXGetErrorString8W +#else + #define DXGetErrorString8 DXGetErrorString8A +#endif + + +// +// DXTrace +// +// Desc: Outputs a formatted error message to the debug stream +// +// Args: CHAR* strFile The current file, typically passed in using the +// __FILE__ macro. +// DWORD dwLine The current line number, typically passed in using the +// __LINE__ macro. +// HRESULT hr An HRESULT that will be traced to the debug stream. +// CHAR* strMsg A string that will be traced to the debug stream (may be NULL) +// BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info. +// +// Return: The hr that was passed in. +// +//HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox = FALSE ); +//HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox = FALSE ); +HRESULT __stdcall DXTraceA( char* strFile, DWORD dwLine, HRESULT hr, char* strMsg, BOOL bPopMsgBox); +HRESULT __stdcall DXTraceW( char* strFile, DWORD dwLine, HRESULT hr, WCHAR* strMsg, BOOL bPopMsgBox); + +#ifdef UNICODE + #define DXTrace DXTraceW +#else + #define DXTrace DXTraceA +#endif + + +// +// Helper macros +// +#if defined(DEBUG) | defined(_DEBUG) + #define DXTRACE_MSG(str) DXTrace( __FILE__, (DWORD)__LINE__, 0, str, FALSE ) + #define DXTRACE_ERR(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, TRUE ) + #define DXTRACE_ERR_NOMSGBOX(str,hr) DXTrace( __FILE__, (DWORD)__LINE__, hr, str, FALSE ) +#else + #define DXTRACE_MSG(str) (0L) + #define DXTRACE_ERR(str,hr) (hr) + #define DXTRACE_ERR_NOMSGBOX(str,hr) (hr) +#endif + + +#endif + --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_texture_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_texture_dx8.c @@ -0,0 +1,2046 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Texture / Bitmap functions +* +****************************************************************************/ + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx8.h" + +#include + +#include "texformat.h" +#include "colormac.h" +#include "texstore.h" +#include "image.h" +// #include "mem.h" + +//--------------------------------------------------------------------------- + +#define GLD_FLIP_HEIGHT(y,h) (gldCtx->dwHeight - (y) - (h)) + +//--------------------------------------------------------------------------- +// 1D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + ((GLchan *)(t)->Data + (i) * (sz)) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + (i) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + (i)) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + (i)) + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_1d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// 2D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + ((GLchan *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + ((t)->Width * (j) + (i)) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + ((t)->Width * (j) + (i))) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + ((t)->Width * (j) + (i))) + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_2d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// 3D texture fetch +//--------------------------------------------------------------------------- + +#define CHAN_SRC( t, i, j, k, sz ) \ + (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i)) * (sz) +#define UBYTE_SRC( t, i, j, k, sz ) \ + ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i)) * (sz)) +#define USHORT_SRC( t, i, j, k ) \ + ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i))) +#define FLOAT_SRC( t, i, j, k ) \ + ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \ + (t)->Width + (i))) + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + GLchan *rgba = (GLchan *)texel; + rgba[RCOMP] = src[2]; + rgba[GCOMP] = src[1]; + rgba[BCOMP] = src[0]; + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X8R8G8B8( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 ); + texel[RCOMP] = CHAN_TO_FLOAT(src[0]); + texel[GCOMP] = CHAN_TO_FLOAT(src[1]); + texel[BCOMP] = CHAN_TO_FLOAT(src[2]); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf8) * 255 / 0xf8 ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X1R5G5B5( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0xf8) * 255 / 0xf8 ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0xf8) * 255 / 0xf8 ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf8) * 255 / 0xf8 ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLchan *rgba = (GLchan *) texel; GLushort s = *src; + rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf ); + rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf ); + rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf ); + rgba[ACOMP] = CHAN_MAX; +} + +//--------------------------------------------------------------------------- + +static void gld_fetch_3d_texel_f_X4R4G4B4( + const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLushort *src = USHORT_SRC( texImage, i, j, k ); + GLushort s = *src; + texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf ); + texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf ); + texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf ); + texel[ACOMP] = 1.f; +} + +//--------------------------------------------------------------------------- + +#undef CHAN_SRC +#undef UBYTE_SRC +#undef USHORT_SRC +#undef FLOAT_SRC + +//--------------------------------------------------------------------------- +// Direct3D texture formats that have no Mesa equivalent +//--------------------------------------------------------------------------- + +const struct gl_texture_format _gld_texformat_X8R8G8B8 = { + MESA_FORMAT_ARGB8888, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 8, /* RedBits */ + 8, /* GreenBits */ + 8, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 4, /* TexelBytes */ + _mesa_texstore_argb8888, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X8R8G8B8, /* FetchTexel1D */ + gld_fetch_2d_texel_X8R8G8B8, /* FetchTexel2D */ + gld_fetch_3d_texel_X8R8G8B8, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X8R8G8B8, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X8R8G8B8, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X8R8G8B8, /* FetchTexel3Df */ +}; + +const struct gl_texture_format _gld_texformat_X1R5G5B5 = { + MESA_FORMAT_ARGB1555, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 5, /* RedBits */ + 5, /* GreenBits */ + 5, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 2, /* TexelBytes */ + _mesa_texstore_argb1555, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X1R5G5B5, /* FetchTexel1D */ + gld_fetch_2d_texel_X1R5G5B5, /* FetchTexel2D */ + gld_fetch_3d_texel_X1R5G5B5, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X1R5G5B5, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X1R5G5B5, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X1R5G5B5, /* FetchTexel3Df */ +}; + +const struct gl_texture_format _gld_texformat_X4R4G4B4 = { + MESA_FORMAT_ARGB4444, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4, /* RedBits */ + 4, /* GreenBits */ + 4, /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 2, /* TexelBytes */ + _mesa_texstore_argb4444, /* StoreTexImageFunc */ + gld_fetch_1d_texel_X4R4G4B4, /* FetchTexel1D */ + gld_fetch_2d_texel_X4R4G4B4, /* FetchTexel2D */ + gld_fetch_3d_texel_X4R4G4B4, /* FetchTexel3D */ + gld_fetch_1d_texel_f_X4R4G4B4, /* FetchTexel1Df */ + gld_fetch_2d_texel_f_X4R4G4B4, /* FetchTexel2Df */ + gld_fetch_3d_texel_f_X4R4G4B4, /* FetchTexel3Df */ +}; + +//--------------------------------------------------------------------------- +// Texture unit constants +//--------------------------------------------------------------------------- + +// List of possible combinations of texture environments. +// Example: GLD_TEXENV_MODULATE_RGBA means +// GL_MODULATE, GL_RGBA base internal format. +#define GLD_TEXENV_DECAL_RGB 0 +#define GLD_TEXENV_DECAL_RGBA 1 +#define GLD_TEXENV_DECAL_ALPHA 2 +#define GLD_TEXENV_REPLACE_RGB 3 +#define GLD_TEXENV_REPLACE_RGBA 4 +#define GLD_TEXENV_REPLACE_ALPHA 5 +#define GLD_TEXENV_MODULATE_RGB 6 +#define GLD_TEXENV_MODULATE_RGBA 7 +#define GLD_TEXENV_MODULATE_ALPHA 8 +#define GLD_TEXENV_BLEND_RGB 9 +#define GLD_TEXENV_BLEND_RGBA 10 +#define GLD_TEXENV_BLEND_ALPHA 11 +#define GLD_TEXENV_ADD_RGB 12 +#define GLD_TEXENV_ADD_RGBA 13 +#define GLD_TEXENV_ADD_ALPHA 14 + +// Per-stage (i.e. per-unit) texture environment +typedef struct { + DWORD ColorArg1; // Colour argument 1 + D3DTEXTUREOP ColorOp; // Colour operation + DWORD ColorArg2; // Colour argument 2 + DWORD AlphaArg1; // Alpha argument 1 + D3DTEXTUREOP AlphaOp; // Alpha operation + DWORD AlphaArg2; // Alpha argument 2 +} GLD_texenv; + +// TODO: Do we really need to set ARG1 and ARG2 every time? +// They seem to always be TEXTURE and CURRENT respectively. + +// C = Colour out +// A = Alpha out +// Ct = Colour from Texture +// Cf = Colour from fragment (diffuse) +// At = Alpha from Texture +// Af = Alpha from fragment (diffuse) +// Cc = GL_TEXTURE_ENV_COLOUR (GL_BLEND) +const GLD_texenv gldTexEnv[] = { + // DECAL_RGB: C=Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // DECAL_RGBA: C=Cf(1-At)+CtAt, A=Af + {D3DTA_TEXTURE, D3DTOP_BLENDTEXTUREALPHA, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // DECAL_ALPHA: use DECAL_RGB + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + + // REPLACE_RGB: C=Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // REPLACE_RGBA: C=Ct, A=At + {D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, + // REPLACE_ALPHA: C=Cf, A=At + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT}, + + // MODULATE_RGB: C=CfCt, A=Af + {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // MODULATE_RGBA: C=CfCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // MODULATE_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + + // BLEND_RGB: C=Cf(1-Ct)+CcCt, A=Af + {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // BLEND_RGBA: C=Cf(1-Ct)+CcCt, A=AfAt + {D3DTA_TEXTURE, D3DTOP_LERP, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // BLEND_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + + // ADD_RGB: C=Cf+Ct, A=Af + {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT}, + // ADD_RGBA: C=Cf+Ct, A=AfAt + {D3DTA_TEXTURE, D3DTOP_ADD, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, + // ADD_ALPHA: C=Cf, A=AfAt + {D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT, + D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT}, +}; + +//--------------------------------------------------------------------------- + +D3DTEXTUREADDRESS _gldConvertWrap( + GLenum wrap) +{ + return (wrap == GL_CLAMP) ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP; +} + +//--------------------------------------------------------------------------- + +D3DTEXTUREFILTERTYPE _gldConvertMagFilter( + GLenum magfilter) +{ + return (magfilter == GL_LINEAR) ? D3DTEXF_LINEAR : D3DTEXF_POINT; +} + +//--------------------------------------------------------------------------- + +void _gldConvertMinFilter( + GLenum minfilter, + D3DTEXTUREFILTERTYPE *min_filter, + D3DTEXTUREFILTERTYPE *mip_filter) +{ + switch (minfilter) { + case GL_NEAREST: + *min_filter = D3DTEXF_POINT; + *mip_filter = D3DTEXF_NONE; + break; + case GL_LINEAR: + *min_filter = D3DTEXF_LINEAR; + *mip_filter = D3DTEXF_NONE; + break; + case GL_NEAREST_MIPMAP_NEAREST: + *min_filter = D3DTEXF_POINT; + *mip_filter = D3DTEXF_POINT; + break; + case GL_LINEAR_MIPMAP_NEAREST: + *min_filter = D3DTEXF_LINEAR; + *mip_filter = D3DTEXF_POINT; + break; + case GL_NEAREST_MIPMAP_LINEAR: + *min_filter = D3DTEXF_POINT; + *mip_filter = D3DTEXF_LINEAR; + break; + case GL_LINEAR_MIPMAP_LINEAR: + *min_filter = D3DTEXF_LINEAR; + *mip_filter = D3DTEXF_LINEAR; + break; + } +} + +//--------------------------------------------------------------------------- + +D3DFORMAT _gldGLFormatToD3DFormat( + GLenum internalFormat) +{ + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + // LUNIMANCE != INTENSITY, but D3D doesn't have I8 textures + return D3DFMT_L8; + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + return D3DFMT_L8; + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + return D3DFMT_A8; + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return D3DFMT_X8R8G8B8; + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return D3DFMT_A8L8; + case GL_R3_G3_B2: + // TODO: Mesa does not support RGB332 internally + return D3DFMT_X4R4G4B4; //D3DFMT_R3G3B2; + case GL_RGB4: + return D3DFMT_X4R4G4B4; + case GL_RGB5: + return D3DFMT_X1R5G5B5; + case 3: + case GL_RGB: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return D3DFMT_R8G8B8; + case GL_RGBA4: + return D3DFMT_A4R4G4B4; + case 4: + case GL_RGBA: + case GL_RGBA2: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return D3DFMT_A8R8G8B8; + case GL_RGB5_A1: + return D3DFMT_A1R5G5B5; + } + + // Return an acceptable default + return D3DFMT_A8R8G8B8; +} + +//--------------------------------------------------------------------------- + +GLenum _gldDecodeBaseFormat( + IDirect3DTexture8 *pTex) +{ + // Examine Direct3D texture and return base OpenGL internal texture format + // NOTE: We can't use any base format info from Mesa because D3D might have + // used a different texture format when we used D3DXCreateTexture(). + + // Base internal format is one of (Red Book p355): + // GL_ALPHA, + // GL_LUMINANCE, + // GL_LUMINANCE_ALPHA, + // GL_INTENSITY, + // GL_RGB, + // GL_RGBA + + // NOTE: INTENSITY not used (not supported by Direct3D) + // LUMINANCE has same texture functions as RGB + // LUMINANCE_ALPHA has same texture functions as RGBA + + // TODO: cache format instead of using GetLevelDesc() + D3DSURFACE_DESC desc; + _GLD_DX8_TEX(GetLevelDesc(pTex, 0, &desc)); + + switch (desc.Format) { + case D3DFMT_R8G8B8: + case D3DFMT_X8R8G8B8: + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_R3G3B2: + case D3DFMT_X4R4G4B4: + case D3DFMT_P8: + case D3DFMT_L8: + return GL_RGB; + case D3DFMT_A8R8G8B8: + case D3DFMT_A1R5G5B5: + case D3DFMT_A4R4G4B4: + case D3DFMT_A8R3G3B2: + case D3DFMT_A8P8: + case D3DFMT_A8L8: + case D3DFMT_A4L4: + return GL_RGBA; + case D3DFMT_A8: + return GL_ALPHA; + // Compressed texture formats. Need to check these... + case D3DFMT_DXT1: + return GL_RGBA; + case D3DFMT_DXT2: + return GL_RGB; + case D3DFMT_DXT3: + return GL_RGBA; + case D3DFMT_DXT4: + return GL_RGB; + case D3DFMT_DXT5: + return GL_RGBA; + } + + // Fell through. Return arbitary default. + return GL_RGBA; +} + +//--------------------------------------------------------------------------- + +const struct gl_texture_format* _gldMesaFormatForD3DFormat( + D3DFORMAT d3dfmt) +{ + switch (d3dfmt) { + case D3DFMT_A8R8G8B8: + return &_mesa_texformat_argb8888; + case D3DFMT_R8G8B8: + return &_mesa_texformat_rgb888; + case D3DFMT_R5G6B5: + return &_mesa_texformat_rgb565; + case D3DFMT_A4R4G4B4: + return &_mesa_texformat_argb4444; + case D3DFMT_A1R5G5B5: + return &_mesa_texformat_argb1555; + case D3DFMT_A8L8: + return &_mesa_texformat_al88; + case D3DFMT_R3G3B2: + return &_mesa_texformat_rgb332; + case D3DFMT_A8: + return &_mesa_texformat_a8; + case D3DFMT_L8: + return &_mesa_texformat_l8; + case D3DFMT_X8R8G8B8: + return &_gld_texformat_X8R8G8B8; + case D3DFMT_X1R5G5B5: + return &_gld_texformat_X1R5G5B5; + case D3DFMT_X4R4G4B4: + return &_gld_texformat_X4R4G4B4; + } + + // If we reach here then we've made an error somewhere else + // by allowing a format that is not supported. + assert(0); + + return NULL; // Shut up compiler warning +} + +//--------------------------------------------------------------------------- +// Copy* functions +//--------------------------------------------------------------------------- + +void gldCopyTexImage1D_DX8( + GLcontext *ctx, + GLenum target, GLint level, + GLenum internalFormat, + GLint x, GLint y, + GLsizei width, GLint border ) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexImage2D_DX8( + GLcontext *ctx, + GLenum target, + GLint level, + GLenum internalFormat, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + GLint border) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage1D_DX8( + GLcontext *ctx, + GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, GLsizei width ) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage2D_DX8( + GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + // TODO +} + +//--------------------------------------------------------------------------- + +void gldCopyTexSubImage3D_DX8( + GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height ) +{ + // TODO ? +} + +//--------------------------------------------------------------------------- +// Bitmap/Pixel functions +//--------------------------------------------------------------------------- + +#define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y)) + +#define _GLD_FVF_IMAGE (D3DFVF_XYZRHW | D3DFVF_TEX1) + +typedef struct { + FLOAT x, y; // 2D raster coords + FLOAT z; // depth value + FLOAT rhw; // reciprocal homogenous W (always 1.0f) + FLOAT tu, tv; // texture coords +} _GLD_IMAGE_VERTEX; + +//--------------------------------------------------------------------------- + +HRESULT _gldDrawPixels( + GLcontext *ctx, + BOOL bChromakey, // Alpha test for glBitmap() images + GLint x, // GL x position + GLint y, // GL y position (needs flipping) + GLsizei width, // Width of input image + GLsizei height, // Height of input image + IDirect3DSurface8 *pImage) +{ + // + // Draw input image as texture implementing PixelZoom and clipping. + // Any fragment operations currently enabled will be used. + // + + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + IDirect3DTexture8 *pTexture; + D3DSURFACE_DESC d3dsd; + IDirect3DSurface8 *pSurface; + _GLD_IMAGE_VERTEX v[4]; + HRESULT hr; + + float ZoomWidth, ZoomHeight; + float ScaleWidth, ScaleHeight; + + // Create a texture to hold image + hr = D3DXCreateTexture( + gld->pDev, + width, height, + 1, // miplevels + 0, // usage + D3DFMT_A8R8G8B8, // format + D3DPOOL_MANAGED, // pool + &pTexture); + if (FAILED(hr)) + return hr; + + hr = IDirect3DTexture8_GetSurfaceLevel(pTexture, 0, &pSurface); + if (FAILED(hr)) { + IDirect3DTexture8_Release(pTexture); + return hr; + } + + // Copy image into texture + hr = D3DXLoadSurfaceFromSurface( + pSurface, NULL, NULL, // Dest surface + pImage, NULL, NULL, // Src surface + D3DX_FILTER_NONE, + 0); + IDirect3DSurface8_Release(pSurface); + if (FAILED(hr)) { + IDirect3DTexture8_Release(pTexture); + return hr; + } + + // + // Set up the quad like this (ascii-art ahead!) + // + // 3--2 + // | | + // 0--1 + // + // + + // Set depth + v[0].z = v[1].z = v[2].z = v[3].z = ctx->Current.RasterPos[2]; + // Set Reciprocal Homogenous W + v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.0f; + + // Set texcoords + // Examine texture size - if different to input width and height + // then we'll need to munge the texcoords to fit. + IDirect3DTexture8_GetLevelDesc(pTexture, 0, &d3dsd); + ScaleWidth = (float)width / (float)d3dsd.Width; + ScaleHeight = (float)height / (float)d3dsd.Height; + v[0].tu = 0.0f; v[0].tv = 0.0f; + v[1].tu = ScaleWidth; v[1].tv = 0.0f; + v[2].tu = ScaleWidth; v[2].tv = ScaleHeight; + v[3].tu = 0.0f; v[3].tv = ScaleHeight; + + // Set raster positions + ZoomWidth = (float)width * ctx->Pixel.ZoomX; + ZoomHeight = (float)height * ctx->Pixel.ZoomY; + + v[0].x = x; v[0].y = GLD_FLIP_Y(y); + v[1].x = x+ZoomWidth; v[1].y = GLD_FLIP_Y(y); + v[2].x = x+ZoomWidth; v[2].y = GLD_FLIP_Y(y+ZoomHeight); + v[3].x = x; v[3].y = GLD_FLIP_Y(y+ZoomHeight); + + // Draw image with full HW acceleration + // NOTE: Be nice to use a State Block for all this state... + IDirect3DDevice8_SetTexture(gld->pDev, 0, pTexture); + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CULLMODE, D3DCULL_NONE); + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_MINFILTER, D3DTEXF_POINT); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); + IDirect3DDevice8_SetTextureStageState(gld->pDev, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + IDirect3DDevice8_SetVertexShader(gld->pDev, _GLD_FVF_IMAGE); + + // + // Emulate Chromakey with an Alpha Test. + // [Alpha Test is more widely supported anyway] + // + if (bChromakey) { + // Switch on alpha testing + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, TRUE); + // Fragment passes is alpha is greater than reference value + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, D3DCMP_GREATER); + // Set alpha reference value between Bitmap alpha values of + // zero (transparent) and one (opaque). + IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_ALPHAREF, 0x7f); + } + + IDirect3DDevice8_DrawPrimitiveUP(gld->pDev, D3DPT_TRIANGLEFAN, 2, &v, sizeof(_GLD_IMAGE_VERTEX)); + + // Release texture + IDirect3DDevice8_SetTexture(gld->pDev, 0, NULL); + IDirect3DTexture8_Release(pTexture); + + // Reset state to before we messed it up + FLUSH_VERTICES(ctx, _NEW_ALL); + + return S_OK; +} + +//--------------------------------------------------------------------------- + +void gld_DrawPixels_DX8( + GLcontext *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels ) +{ + GLD_context *gldCtx; + GLD_driver_dx8 *gld; + + IDirect3DSurface8 *pImage; + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + + const struct gl_texture_format *MesaFormat; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX8_DRIVER(gldCtx); + + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + &pImage); + if (FAILED(hr)) { + return; + } + + // + // Use Mesa to fill in image + // + + // Lock all of surface + hr = IDirect3DSurface8_LockRect(pImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pImage); + return; + } + + MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); + + // unpack image, apply transfer ops and store directly in texture + MesaFormat->StoreImage( + ctx, + 2, + GL_RGBA, + &_mesa_texformat_argb8888, + d3dLockedRect.pBits, + width, height, 1, 0, 0, 0, + d3dLockedRect.Pitch, + 0, /* dstImageStride */ + format, type, pixels, unpack); + + IDirect3DSurface8_UnlockRect(pImage); + + _gldDrawPixels(ctx, FALSE, x, y, width, height, pImage); + + IDirect3DSurface8_Release(pImage); +} + +//--------------------------------------------------------------------------- + +void gld_ReadPixels_DX8( + GLcontext *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest) +{ + + GLD_context *gldCtx; + GLD_driver_dx8 *gld; + + IDirect3DSurface8 *pBackbuffer = NULL; + IDirect3DSurface8 *pNativeImage = NULL; + IDirect3DSurface8 *pCanonicalImage = NULL; + + D3DSURFACE_DESC d3dsd; + RECT rcSrc; // Source rect + POINT ptDst; // Dest point + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + struct gl_pixelstore_attrib srcPacking; + int i; + GLint DstRowStride; + const struct gl_texture_format *MesaFormat; + + switch (format) { + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + return; + } + + MesaFormat = _mesa_choose_tex_format(ctx, format, format, type); + DstRowStride = _mesa_image_row_stride(pack, width, format, type); + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX8_DRIVER(gldCtx); + + // Get backbuffer + hr = IDirect3DDevice8_GetBackBuffer( + gld->pDev, + 0, // First backbuffer + D3DBACKBUFFER_TYPE_MONO, + &pBackbuffer); + if (FAILED(hr)) + return; + + // Get backbuffer description + hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); + if (FAILED(hr)) { + goto gld_ReadPixels_DX8_return; + } + + // Create a surface compatible with backbuffer + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + d3dsd.Format, + &pNativeImage); + if (FAILED(hr)) { + goto gld_ReadPixels_DX8_return; + } + + // Compute source rect and dest point + SetRect(&rcSrc, 0, 0, width, height); + OffsetRect(&rcSrc, x, GLD_FLIP_HEIGHT(y, height)); + ptDst.x = ptDst.y = 0; + + // Get source pixels. + // + // This intermediate surface ensure that we can use CopyRects() + // instead of relying on D3DXLoadSurfaceFromSurface(), which may + // try and lock the backbuffer. This way seems safer. + // + hr = IDirect3DDevice8_CopyRects( + gld->pDev, + pBackbuffer, + &rcSrc, + 1, + pNativeImage, + &ptDst); + if (FAILED(hr)) { + goto gld_ReadPixels_DX8_return; + } + + // Create an RGBA8888 surface + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + &pCanonicalImage); + if (FAILED(hr)) { + goto gld_ReadPixels_DX8_return; + } + + // Convert to RGBA8888 + hr = D3DXLoadSurfaceFromSurface( + pCanonicalImage, // Dest surface + NULL, NULL, // Dest palette, RECT + pNativeImage, // Src surface + NULL, NULL, // Src palette, RECT + D3DX_FILTER_NONE, // Filter + 0); // Colourkey + if (FAILED(hr)) { + goto gld_ReadPixels_DX8_return; + } + + srcPacking.Alignment = 1; + srcPacking.ImageHeight = height; + srcPacking.LsbFirst = GL_FALSE; + srcPacking.RowLength = 0; + srcPacking.SkipImages = 0; + srcPacking.SkipPixels = 0; + srcPacking.SkipRows = 0; + srcPacking.SwapBytes = GL_FALSE; + + // Lock all of image + hr = IDirect3DSurface8_LockRect(pCanonicalImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + goto gld_ReadPixels_DX8_return; + } + + // We need to flip the data. Yuck. + // Perhaps Mesa has a span packer we can use in future... + for (i=0; iStoreImage( + ctx, + 2, + GL_RGBA, // base format + MesaFormat, // dst format + pDestRow, // dest addr + width, 1, 1, 0, 0, 0, // src x,y,z & dst offsets x,y,z + DstRowStride, // dst row stride + 0, // dstImageStride + GL_BGRA, // src format + GL_UNSIGNED_BYTE, // src type + pSrcRow, // src addr + &srcPacking); // packing params of source image + } + + IDirect3DSurface8_UnlockRect(pCanonicalImage); + +gld_ReadPixels_DX8_return: + SAFE_RELEASE_SURFACE8(pCanonicalImage); + SAFE_RELEASE_SURFACE8(pNativeImage); + SAFE_RELEASE_SURFACE8(pBackbuffer); +} + +//--------------------------------------------------------------------------- + +void gld_CopyPixels_DX8( + GLcontext *ctx, + GLint srcx, + GLint srcy, + GLsizei width, + GLsizei height, + GLint dstx, + GLint dsty, + GLenum type) +{ + // + // NOTE: Not allowed to copy vidmem to vidmem! + // Therefore we use an intermediate image surface. + // + + GLD_context *gldCtx; + GLD_driver_dx8 *gld; + + IDirect3DSurface8 *pBackbuffer; + D3DSURFACE_DESC d3dsd; + IDirect3DSurface8 *pImage; + RECT rcSrc; // Source rect + POINT ptDst; // Dest point + HRESULT hr; + + // Only backbuffer + if (type != GL_COLOR) + return; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX8_DRIVER(gldCtx); + + // Get backbuffer + hr = IDirect3DDevice8_GetBackBuffer( + gld->pDev, + 0, // First backbuffer + D3DBACKBUFFER_TYPE_MONO, + &pBackbuffer); + if (FAILED(hr)) + return; + + // Get backbuffer description + hr = IDirect3DSurface8_GetDesc(pBackbuffer, &d3dsd); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pBackbuffer); + return; + } + + // Create a surface compatible with backbuffer + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + d3dsd.Format, + &pImage); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pBackbuffer); + return; + } + + // Compute source rect and dest point + SetRect(&rcSrc, 0, 0, width, height); + OffsetRect(&rcSrc, srcx, GLD_FLIP_HEIGHT(srcy, height)); + ptDst.x = ptDst.y = 0; + + // Get source pixels + hr = IDirect3DDevice8_CopyRects( + gld->pDev, + pBackbuffer, + &rcSrc, + 1, + pImage, + &ptDst); + IDirect3DSurface8_Release(pBackbuffer); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pImage); + return; + } + + _gldDrawPixels(ctx, FALSE, dstx, dsty, width, height, pImage); + + IDirect3DSurface8_Release(pImage); +} + +//--------------------------------------------------------------------------- + +void gld_Bitmap_DX8( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap) +{ + GLD_context *gldCtx; + GLD_driver_dx8 *gld; + + IDirect3DSurface8 *pImage; + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + BYTE *pTempBitmap; + D3DCOLOR clBitmapOne, clBitmapZero; + D3DCOLOR *pBits; + const GLubyte *src; + int i, j, k; + + gldCtx = GLD_GET_CONTEXT(ctx); + gld = GLD_GET_DX8_DRIVER(gldCtx); + + clBitmapZero = D3DCOLOR_RGBA(0,0,0,0); // NOTE: Alpha is Zero + clBitmapOne = D3DCOLOR_COLORVALUE( + ctx->Current.RasterColor[0], + ctx->Current.RasterColor[1], + ctx->Current.RasterColor[2], + 1.0f); // NOTE: Alpha is One + + hr = IDirect3DDevice8_CreateImageSurface( + gld->pDev, + width, + height, + D3DFMT_A8R8G8B8, + &pImage); + if (FAILED(hr)) { + return; + } + + // Lock all of surface + hr = IDirect3DSurface8_LockRect(pImage, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pImage); + return; + } + + pTempBitmap = _mesa_unpack_bitmap(width, height, bitmap, unpack); + if (pTempBitmap == NULL) { + IDirect3DSurface8_Release(pImage); + return; + } + + pBits = (D3DCOLOR*)d3dLockedRect.pBits; + + for (i=0; iDefaultPacking, pTempBitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, + 0, i, 0); + for (j=0; j<(width>>3); j++) { + byte = *src++; + for (k=0; k<8; k++) { + *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; + byte <<= 1; + } + } + // Fill remaining bits from bitmap + if (width & 7) { + byte = *src; + for (k=0; k<(width & 7); k++) { + *pBits++ = (byte & 128) ? clBitmapOne : clBitmapZero; + byte <<= 1; + } + } + } + + FREE(pTempBitmap); + +/* + // unpack image, apply transfer ops and store directly in texture + texImage->TexFormat->StoreImage( + ctx, + 2, + GL_BITMAP, + &_mesa_texformat_argb8888, + d3dLockedRect.pBits, + width, height, 1, 0, 0, 0, + d3dLockedRect.Pitch, + 0, // dstImageStride + GL_BITMAP, GL_COLOR_INDEX, bitmap, unpack); +*/ + IDirect3DSurface8_UnlockRect(pImage); + + _gldDrawPixels(ctx, TRUE, x, y, width, height, pImage); + + IDirect3DSurface8_Release(pImage); +} + +//--------------------------------------------------------------------------- +// Texture functions +//--------------------------------------------------------------------------- + +void _gldAllocateTexture( + GLcontext *ctx, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + IDirect3DTexture8 *pTex; + D3DFORMAT d3dFormat; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (pTex) { + // Decide whether we can keep existing D3D texture + // by examining top-level surface. + D3DSURFACE_DESC d3dsd; + _GLD_DX8_TEX(GetLevelDesc(pTex, 0, &d3dsd)); + // Release existing texture if not compatible + if ((d3dsd.Width == texImage->Width) || + (d3dsd.Height == texImage->Height)) + { + return; // Keep the existing texture + } + tObj->DriverData = NULL; + _GLD_DX8_TEX(Release(pTex)); + } + + d3dFormat = _gldGLFormatToD3DFormat(texImage->IntFormat); + D3DXCreateTexture( + gld->pDev, + texImage->Width, + texImage->Height, + // TODO: Re-evaluate mipmapping + (glb.bUseMipmaps) ? D3DX_DEFAULT : 1, + 0, // Usage + d3dFormat, + D3DPOOL_MANAGED, + &pTex); + tObj->DriverData = pTex; +} + +//--------------------------------------------------------------------------- + +const struct gl_texture_format* gld_ChooseTextureFormat_DX8( + GLcontext *ctx, + GLint internalFormat, + GLenum srcFormat, + GLenum srcType) +{ + // [Based on mesa_choose_tex_format()] + // + // We will choose only texture formats that are supported + // by Direct3D. If the hardware doesn't support a particular + // texture format, then the D3DX texture calls that we use + // will automatically use a HW supported format. + // + // The most critical aim is to reduce copying; if we can use + // texture-image data directly then it will be a big performance assist. + // + + switch (internalFormat) { + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + return &_mesa_texformat_l8; // D3DFMT_L8 + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + return &_mesa_texformat_l8; // D3DFMT_L8 + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + return &_mesa_texformat_a8; // D3DFMT_A8 + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return &_mesa_texformat_rgb565; // D3DFMT_R5G6B5 + // Mesa will convert this for us later... + // return &_mesa_texformat_ci8; // D3DFMT_R5G6B5 + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return &_mesa_texformat_al88; // D3DFMT_A8L8 + case GL_R3_G3_B2: + return &_mesa_texformat_rgb332; // D3DFMT_R3G3B2 + case GL_RGB4: + case GL_RGBA4: + case GL_RGBA2: + return &_mesa_texformat_argb4444; // D3DFMT_A4R4G4B4 + case 3: + case GL_RGB: + case GL_RGB5: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return &_mesa_texformat_rgb565; + case 4: + case GL_RGBA: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return &_mesa_texformat_argb8888; + case GL_RGB5_A1: + return &_mesa_texformat_argb1555; + default: + _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat"); + return NULL; + } +} + +//--------------------------------------------------------------------------- + +/* +// Safer(?), slower version. +void gld_TexImage2D_DX8( + GLcontext *ctx, + GLenum target, + GLint level, + GLint internalFormat, + GLint width, + GLint height, + GLint border, + GLenum format, + GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + IDirect3DTexture8 *pTex; + IDirect3DSurface8 *pSurface; + RECT rcSrcRect; + HRESULT hr; + GLint texelBytes = 4; + GLvoid *tempImage; + + if (!tObj || !texImage) + return; + + if (level == 0) { + _gldAllocateTexture(ctx, tObj, texImage); + } + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture8_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + tempImage = MALLOC(width * height * texelBytes); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); + IDirect3DSurface8_Release(pSurface); + return; + } + // unpack image, apply transfer ops and store in tempImage + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + &_mesa_texformat_argb8888, // dest format + tempImage, + width, height, 1, 0, 0, 0, + width * texelBytes, + 0, // dstImageStride + format, type, pixels, packing); + + SetRect(&rcSrcRect, 0, 0, width, height); + D3DXLoadSurfaceFromMemory( + pSurface, + NULL, + NULL, + tempImage, + D3DFMT_A8R8G8B8, + width * texelBytes, + NULL, + &rcSrcRect, + D3DX_FILTER_NONE, + 0); + + FREE(tempImage); + IDirect3DSurface8_Release(pSurface); +} +*/ + +//--------------------------------------------------------------------------- + +// Faster, more efficient version. +// Copies subimage straight to dest texture +void gld_TexImage2D_DX8( + GLcontext *ctx, + GLenum target, + GLint level, + GLint internalFormat, + GLint width, + GLint height, + GLint border, + GLenum format, + GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + IDirect3DTexture8 *pTex; + IDirect3DSurface8 *pSurface; + HRESULT hr; + D3DLOCKED_RECT d3dLockedRect; + D3DSURFACE_DESC d3dsd; + + if (!tObj || !texImage) + return; + + // GLQUAKE FIX + // Test for input alpha data with non-alpha internalformat + if (((internalFormat==3) || (internalFormat==GL_RGB)) && (format==GL_RGBA)) { + // Input format has alpha, but a non-alpha format has been requested. + texImage->IntFormat = GL_RGBA; + internalFormat = GL_RGBA; + } + + if (level == 0) { + _gldAllocateTexture(ctx, tObj, texImage); + } + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture8_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + IDirect3DSurface8_GetDesc(pSurface, &d3dsd); + + // Lock all of surface + hr = IDirect3DSurface8_LockRect(pSurface, &d3dLockedRect, NULL, 0); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store directly in texture + texImage->TexFormat->StoreImage( + ctx, + 2, + texImage->Format, + _gldMesaFormatForD3DFormat(d3dsd.Format), + d3dLockedRect.pBits, + width, height, 1, 0, 0, 0, + d3dLockedRect.Pitch, + 0, // dstImageStride + format, type, pixels, packing); + + IDirect3DSurface8_UnlockRect(pSurface); + IDirect3DSurface8_Release(pSurface); +} + +//--------------------------------------------------------------------------- + +void gld_TexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint border, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + // A 1D texture is a 2D texture with a height of zero + gld_TexImage2D_DX8(ctx, target, level, internalFormat, width, 1, border, format, type, pixels, packing, texObj, texImage); +} + +//--------------------------------------------------------------------------- + +/* +void gld_TexSubImage2D( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage ) +{ + GLD_GET_CONTEXT + IDirect3DTexture8 *pTex; + IDirect3DSurface8 *pSurface; + D3DFORMAT d3dFormat; + HRESULT hr; + GLint texelBytes = 4; + GLvoid *tempImage; + RECT rcSrcRect; + RECT rcDstRect; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= _GLD_DX8_TEX(GetLevelCount(pTex)) + return; // Level does not exist + hr = _GLD_DX8_TEX(GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + d3dFormat = _gldGLFormatToD3DFormat(texImage->Format); + tempImage = MALLOC(width * height * texelBytes); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); + IDirect3DSurface8_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store in tempImage + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + &_mesa_texformat_argb8888, // dest format + tempImage, + width, height, 1, 0, 0, 0, + width * texelBytes, + 0, // dstImageStride + format, type, pixels, packing); + + // Source rectangle is whole of input image + SetRect(&rcSrcRect, 0, 0, width, height); + + // Dest rectangle must be offset to dest image + SetRect(&rcDstRect, 0, 0, width, height); + OffsetRect(&rcDstRect, xoffset, yoffset); + + D3DXLoadSurfaceFromMemory( + pSurface, + NULL, + &rcDstRect, + tempImage, + D3DFMT_A8R8G8B8, + width * texelBytes, + NULL, + &rcSrcRect, + D3DX_FILTER_NONE, + 0); + + FREE(tempImage); + IDirect3DSurface8_Release(pSurface); +} +*/ + +//--------------------------------------------------------------------------- + +// Faster, more efficient version. +// Copies subimage straight to dest texture +void gld_TexSubImage2D_DX8( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *tObj, + struct gl_texture_image *texImage ) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + IDirect3DTexture8 *pTex; + IDirect3DSurface8 *pSurface; + HRESULT hr; + RECT rcDstRect; + D3DLOCKED_RECT d3dLockedRect; + D3DSURFACE_DESC d3dsd; + + if (!tObj || !texImage) + return; + + pTex = (IDirect3DTexture8*)tObj->DriverData; + if (!pTex) + return; // Texture has not been created + if (level >= IDirect3DTexture8_GetLevelCount(pTex)) + return; // Level does not exist + hr = IDirect3DTexture8_GetSurfaceLevel(pTex, level, &pSurface); + if (FAILED(hr)) + return; // Surface level doesn't exist (or just a plain error) + + IDirect3DSurface8_GetDesc(pSurface, &d3dsd); + + // Dest rectangle must be offset to dest image + SetRect(&rcDstRect, 0, 0, width, height); + OffsetRect(&rcDstRect, xoffset, yoffset); + + // Lock sub-rect of surface + hr = IDirect3DSurface8_LockRect(pSurface, &d3dLockedRect, &rcDstRect, 0); + if (FAILED(hr)) { + IDirect3DSurface8_Release(pSurface); + return; + } + + // unpack image, apply transfer ops and store directly in texture + texImage->TexFormat->StoreImage(ctx, 2, texImage->Format, + _gldMesaFormatForD3DFormat(d3dsd.Format), + d3dLockedRect.pBits, + width, height, 1, + 0, 0, 0, // NOTE: d3dLockedRect.pBits is already offset!!! + d3dLockedRect.Pitch, + 0, // dstImageStride + format, type, pixels, packing); + + + IDirect3DSurface8_UnlockRect(pSurface); + IDirect3DSurface8_Release(pSurface); +} + +//--------------------------------------------------------------------------- + +void gld_TexSubImage1D_DX8( GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLsizei width, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + gld_TexSubImage2D_DX8(ctx, target, level, xoffset, 0, width, 1, format, type, pixels, packing, texObj, texImage); +} + +//--------------------------------------------------------------------------- + +void gld_DeleteTexture_DX8( + GLcontext *ctx, + struct gl_texture_object *tObj) +{ + GLD_context *gld = (GLD_context*)(ctx->DriverCtx); + + if (tObj) { + IDirect3DTexture8 *pTex = (IDirect3DTexture8*)tObj->DriverData; + if (pTex) { +/* // Make sure texture is not bound to a stage before releasing it + for (int i=0; iCurrentTexture[i] == pTex) { + gld->pDev->SetTexture(i, NULL); + gld->CurrentTexture[i] = NULL; + } + }*/ + _GLD_DX8_TEX(Release(pTex)); + tObj->DriverData = NULL; + } + } +} + +//--------------------------------------------------------------------------- + +__inline void _gldSetColorOps( + const GLD_driver_dx8 *gld, + GLuint unit, + DWORD ColorArg1, + D3DTEXTUREOP ColorOp, + DWORD ColorArg2) +{ + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG1, ColorArg1)); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLOROP, ColorOp)); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG2, ColorArg2)); +} + +//--------------------------------------------------------------------------- + +__inline void _gldSetAlphaOps( + const GLD_driver_dx8 *gld, + GLuint unit, + DWORD AlphaArg1, + D3DTEXTUREOP AlphaOp, + DWORD AlphaArg2) +{ + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG1, AlphaArg1)); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAOP, AlphaOp)); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ALPHAARG2, AlphaArg2)); +} + +//--------------------------------------------------------------------------- + +void gldUpdateTextureUnit( + GLcontext *ctx, + GLuint unit, + BOOL bPassThrough) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DTEXTUREFILTERTYPE minfilter; + D3DTEXTUREFILTERTYPE mipfilter; + GLenum BaseFormat; + DWORD dwColorArg0; + int iTexEnv = 0; + GLD_texenv *pTexenv; + + // NOTE: If bPassThrough is FALSE then texture stage can be + // disabled otherwise it must pass-through it's current fragment. + + const struct gl_texture_unit *pUnit = &ctx->Texture.Unit[unit]; + const struct gl_texture_object *tObj = pUnit->_Current; + + IDirect3DTexture8 *pTex = NULL; + if (tObj) { + pTex = (IDirect3DTexture8*)tObj->DriverData; + } + + // Enable texturing if unit is enabled and a valid D3D texture exists + // Mesa 5: TEXTUREn_x altered to TEXTURE_nD_BIT + //if (pTex && (pUnit->Enabled & (TEXTURE0_1D | TEXTURE0_2D))) { + if (pTex && (pUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT))) { + // Enable texturing + _GLD_DX8_DEV(SetTexture(gld->pDev, unit, pTex)); + } else { + // Disable texturing, then return + _GLD_DX8_DEV(SetTexture(gld->pDev, unit, NULL)); + if (bPassThrough) { + _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); + _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_DIFFUSE); + } else { + _gldSetColorOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); + _gldSetAlphaOps(gld, unit, D3DTA_TEXTURE, D3DTOP_DISABLE, D3DTA_DIFFUSE); + } + return; + } + + // Texture parameters + _gldConvertMinFilter(tObj->MinFilter, &minfilter, &mipfilter); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MINFILTER, minfilter)); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MIPFILTER, mipfilter)); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_MAGFILTER, _gldConvertMagFilter(tObj->MagFilter))); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSU, _gldConvertWrap(tObj->WrapS))); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_ADDRESSV, _gldConvertWrap(tObj->WrapT))); + + // Texture priority + _GLD_DX8_TEX(SetPriority(pTex, (DWORD)(tObj->Priority*65535.0f))); + + // Texture environment + // TODO: Examine input texture for alpha and use specific alpha/non-alpha ops. + // See Page 355 of the Red Book. + BaseFormat = _gldDecodeBaseFormat(pTex); + + switch (BaseFormat) { + case GL_RGB: + iTexEnv = 0; + break; + case GL_RGBA: + iTexEnv = 1; + break; + case GL_ALPHA: + iTexEnv = 2; + break; + } + + switch (pUnit->EnvMode) { + case GL_DECAL: + iTexEnv += 0; + break; + case GL_REPLACE: + iTexEnv += 3; + break; + case GL_MODULATE: + iTexEnv += 6; + break; + case GL_BLEND: + // Set blend colour + dwColorArg0 = D3DCOLOR_COLORVALUE(pUnit->EnvColor[0], pUnit->EnvColor[1], pUnit->EnvColor[2], pUnit->EnvColor[3]); + _GLD_DX8_DEV(SetTextureStageState(gld->pDev, unit, D3DTSS_COLORARG0, dwColorArg0)); + iTexEnv += 9; + break; + case GL_ADD: + iTexEnv += 12; + break; + } + pTexenv = (GLD_texenv*)&gldTexEnv[iTexEnv]; + _gldSetColorOps(gld, unit, pTexenv->ColorArg1, pTexenv->ColorOp, pTexenv->ColorArg2); + _gldSetAlphaOps(gld, unit, pTexenv->AlphaArg1, pTexenv->AlphaOp, pTexenv->AlphaArg2); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_TEXTURE_DX8( + GLcontext *ctx) +{ + // TODO: Support for three (ATI Radeon) or more (nVidia GeForce3) texture units + + BOOL bUnit0Enabled; + BOOL bUnit1Enabled; + + if (!ctx) + return; // Sanity check + + if (ctx->Const.MaxTextureUnits == 1) { + gldUpdateTextureUnit(ctx, 0, TRUE); + return; + } + + // + // NOTE: THE FOLLOWING RELATES TO TWO TEXTURE UNITS, AND TWO ONLY!! + // + + // Mesa 5: Texture Units altered + //bUnit0Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE0_1D | TEXTURE0_2D)) ? TRUE : FALSE; + //bUnit1Enabled = (ctx->Texture._ReallyEnabled & (TEXTURE1_1D | TEXTURE1_2D)) ? TRUE : FALSE; + bUnit0Enabled = (ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; + bUnit1Enabled = (ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) ? TRUE : FALSE; + + // If Unit0 is disabled and Unit1 is enabled then we must pass-though + gldUpdateTextureUnit(ctx, 0, (!bUnit0Enabled && bUnit1Enabled) ? TRUE : FALSE); + // We can always disable the last texture unit + gldUpdateTextureUnit(ctx, 1, FALSE); + +#ifdef _DEBUG + { + // Find out whether device supports current renderstates + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); +// GLD_context *gld = GLD_GET_CONTEXT(ctx); + + DWORD dwPasses; + _GLD_DX8_DEV(ValidateDevice(gld->pDev, &dwPasses)); +// if (FAILED(hr)) { +// gldLogError(GLDLOG_ERROR, "ValidateDevice failed", hr); +// } + if (dwPasses != 1) { + gldLogMessage(GLDLOG_ERROR, "ValidateDevice: Can't do in one pass\n"); + } + } +#endif +}; + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_driver_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_driver_dx8.c @@ -0,0 +1,1176 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Driver interface code to Mesa +* +****************************************************************************/ + +//#include +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx8.h" + +#include "glheader.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +// #include "mem.h" +//#include "mmath.h" +#include "mtypes.h" +#include "texformat.h" +#include "teximage.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast_setup/ss_context.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +extern BOOL dglSwapBuffers(HDC hDC); + +// HACK: Hack the _33 member of the OpenGL perspective projection matrix +const float _fPersp_33 = 1.6f; + +//--------------------------------------------------------------------------- +// Internal functions +//--------------------------------------------------------------------------- + +void _gld_mesa_warning( + __GLcontext *gc, + char *str) +{ + // Intercept Mesa's internal warning mechanism + gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str); +} + +//--------------------------------------------------------------------------- + +void _gld_mesa_fatal( + __GLcontext *gc, + char *str) +{ + // Intercept Mesa's internal fatal-message mechanism + gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str); + + // Mesa calls abort(0) here. + ddlogClose(); + exit(0); +} + +//--------------------------------------------------------------------------- + +D3DSTENCILOP _gldConvertStencilOp( + GLenum StencilOp) +{ + // Used by Stencil: pass, fail and zfail + + switch (StencilOp) { + case GL_KEEP: + return D3DSTENCILOP_KEEP; + case GL_ZERO: + return D3DSTENCILOP_ZERO; + case GL_REPLACE: + return D3DSTENCILOP_REPLACE; + case GL_INCR: + return D3DSTENCILOP_INCRSAT; + case GL_DECR: + return D3DSTENCILOP_DECRSAT; + case GL_INVERT: + return D3DSTENCILOP_INVERT; + case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap + return D3DSTENCILOP_INCR; + case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap + return D3DSTENCILOP_DECR; + } + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n"); +#endif + + return D3DSTENCILOP_KEEP; +} + +//--------------------------------------------------------------------------- + +D3DCMPFUNC _gldConvertCompareFunc( + GLenum CmpFunc) +{ + // Used for Alpha func, depth func and stencil func. + + switch (CmpFunc) { + case GL_NEVER: + return D3DCMP_NEVER; + case GL_LESS: + return D3DCMP_LESS; + case GL_EQUAL: + return D3DCMP_EQUAL; + case GL_LEQUAL: + return D3DCMP_LESSEQUAL; + case GL_GREATER: + return D3DCMP_GREATER; + case GL_NOTEQUAL: + return D3DCMP_NOTEQUAL; + case GL_GEQUAL: + return D3DCMP_GREATEREQUAL; + case GL_ALWAYS: + return D3DCMP_ALWAYS; + }; + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n"); +#endif + + return D3DCMP_ALWAYS; +} + +//--------------------------------------------------------------------------- + +D3DBLEND _gldConvertBlendFunc( + GLenum blend, + GLenum DefaultBlend) +{ + switch (blend) { + case GL_ZERO: + return D3DBLEND_ZERO; + case GL_ONE: + return D3DBLEND_ONE; + case GL_DST_COLOR: + return D3DBLEND_DESTCOLOR; + case GL_SRC_COLOR: + return D3DBLEND_SRCCOLOR; + case GL_ONE_MINUS_DST_COLOR: + return D3DBLEND_INVDESTCOLOR; + case GL_ONE_MINUS_SRC_COLOR: + return D3DBLEND_INVSRCCOLOR; + case GL_SRC_ALPHA: + return D3DBLEND_SRCALPHA; + case GL_ONE_MINUS_SRC_ALPHA: + return D3DBLEND_INVSRCALPHA; + case GL_DST_ALPHA: + return D3DBLEND_DESTALPHA; + case GL_ONE_MINUS_DST_ALPHA: + return D3DBLEND_INVDESTALPHA; + case GL_SRC_ALPHA_SATURATE: + return D3DBLEND_SRCALPHASAT; + } + +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n"); +#endif + + return DefaultBlend; +} + +//--------------------------------------------------------------------------- +// Misc. functions +//--------------------------------------------------------------------------- + +void gld_Noop_DX8( + GLcontext *ctx) +{ +#ifdef _DEBUG + gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n"); +#endif +} + +//--------------------------------------------------------------------------- + +void gld_Error_DX8( + GLcontext *ctx) +{ +#ifdef _DEBUG + // Quite useless. +// gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n"); +#endif +} + +//--------------------------------------------------------------------------- +// Required Mesa functions +//--------------------------------------------------------------------------- + +static GLboolean gld_set_draw_buffer_DX8( + GLcontext *ctx, + GLenum mode) +{ + (void) ctx; + if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) { + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + +//--------------------------------------------------------------------------- + +static void gld_set_read_buffer_DX8( + GLcontext *ctx, + GLframebuffer *buffer, + GLenum mode) +{ + /* separate read buffer not supported */ +/* + ASSERT(buffer == ctx->DrawBuffer); + ASSERT(mode == GL_FRONT_LEFT); +*/ +} + +//--------------------------------------------------------------------------- + +void gld_Clear_DX8( + GLcontext *ctx, + GLbitfield mask, + GLboolean all, + GLint x, + GLint y, + GLint width, + GLint height) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + DWORD dwFlags = 0; + D3DCOLOR Color = 0; + float Z = 0.0f; + DWORD Stencil = 0; + D3DRECT d3dClearRect; + + // TODO: Colourmask + const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; + + if (!gld->pDev) + return; + + if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { + GLubyte col[4]; + CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]); + CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]); + CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]); + CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]); + dwFlags |= D3DCLEAR_TARGET; + Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]); +// ctx->Color.ClearColor[1], +// ctx->Color.ClearColor[2], +// ctx->Color.ClearColor[3]); + } + + if (mask & DD_DEPTH_BIT) { + // D3D8 will fail the Clear call if we try and clear a + // depth buffer and we haven't created one. + // Also, some apps try and clear a depth buffer, + // when a depth buffer hasn't been requested by the app. + if (ctx->Visual.depthBits == 0) { + mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask + } else { + dwFlags |= D3DCLEAR_ZBUFFER; + Z = ctx->Depth.Clear; + } + } + + if (mask & DD_STENCIL_BIT) { + if (ctx->Visual.stencilBits == 0) { + // No stencil bits in depth buffer + mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask + } else { + dwFlags |= D3DCLEAR_STENCIL; + Stencil = ctx->Stencil.Clear; + } + } + + // Some apps do really weird things with the rect, such as Quake3. + if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) { + all = GL_TRUE; + } + + if (!all) { + // Calculate clear subrect + d3dClearRect.x1 = x; + d3dClearRect.y1 = gldCtx->dwHeight - (y + height); + d3dClearRect.x2 = x + width; + d3dClearRect.y2 = d3dClearRect.y1 + height; + } + + // dwFlags will be zero if there's nothing to clear + if (dwFlags) { + _GLD_DX8_DEV(Clear( + gld->pDev, + all ? 0 : 1, + all ? NULL : &d3dClearRect, + dwFlags, + Color, Z, Stencil)); + } + + if (mask & DD_ACCUM_BIT) { + // Clear accumulation buffer + } +} + +//--------------------------------------------------------------------------- + +// Mesa 5: Parameter change +static void gld_buffer_size_DX8( +// GLcontext *ctx, + GLframebuffer *fb, + GLuint *width, + GLuint *height) +{ +// GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + + *width = fb->Width; // gldCtx->dwWidth; + *height = fb->Height; // gldCtx->dwHeight; +} + +//--------------------------------------------------------------------------- + +static void gld_Finish_DX8( + GLcontext *ctx) +{ +} + +//--------------------------------------------------------------------------- + +static void gld_Flush_DX8( + GLcontext *ctx) +{ + GLD_context *gld = GLD_GET_CONTEXT(ctx); + + // TODO: Detect apps that glFlush() then SwapBuffers() ? + + if (gld->EmulateSingle) { + // Emulating a single-buffered context. + // [Direct3D doesn't allow rendering to front buffer] + dglSwapBuffers(gld->hDC); + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_STENCIL( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + // Two-sided stencil. New for Mesa 5 + const GLuint uiFace = 0UL; + + struct gl_stencil_attrib *pStencil = &ctx->Stencil; + + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE)); + if (pStencil->Enabled) { + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace]))); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILREF, pStencil->Ref[uiFace])); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILMASK, pStencil->ValueMask[uiFace])); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILWRITEMASK, pStencil->WriteMask[uiFace])); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace]))); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace]))); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace]))); + } +} + +//--------------------------------------------------------------------------- + +void gld_NEW_COLOR( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + DWORD dwFlags = 0; + D3DBLEND src; + D3DBLEND dest; + + // Alpha func + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc))); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAREF, (DWORD)ctx->Color.AlphaRef)); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, ctx->Color.AlphaEnabled)); + + // Blend func + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHABLENDENABLE, ctx->Color.BlendEnabled)); + src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE); + dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SRCBLEND, src)); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_DESTBLEND, dest)); + + // Color mask + if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED; + if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN; + if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE; + if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA; + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_COLORWRITEENABLE, dwFlags)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_DEPTH( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE)); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func))); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_POLYGON( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DFILLMODE d3dFillMode = D3DFILL_SOLID; + D3DCULL d3dCullMode = D3DCULL_NONE; + int iOffset = 0; + + // Fillmode + switch (ctx->Polygon.FrontMode) { + case GL_POINT: + d3dFillMode = D3DFILL_POINT; + break; + case GL_LINE: + d3dFillMode = D3DFILL_WIREFRAME; + break; + case GL_FILL: + d3dFillMode = D3DFILL_SOLID; + break; + } + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FILLMODE, d3dFillMode)); + + if (ctx->Polygon.CullFlag) { + switch (ctx->Polygon.CullFaceMode) { + case GL_BACK: + if (ctx->Polygon.FrontFace == GL_CCW) + d3dCullMode = D3DCULL_CW; + else + d3dCullMode = D3DCULL_CCW; + break; + case GL_FRONT: + if (ctx->Polygon.FrontFace == GL_CCW) + d3dCullMode = D3DCULL_CCW; + else + d3dCullMode = D3DCULL_CW; + break; + case GL_FRONT_AND_BACK: + d3dCullMode = D3DCULL_NONE; + break; + default: + break; + } + } else { + d3dCullMode = D3DCULL_NONE; + } +// d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CULLMODE, d3dCullMode)); + + // Polygon offset + // ZBIAS ranges from 0 to 16 and can only move towards the viewer + // Mesa5: ctx->Polygon._OffsetAny removed + if (ctx->Polygon.OffsetFill) { + iOffset = (int)ctx->Polygon.OffsetUnits; + if (iOffset < 0) + iOffset = -iOffset; + else + iOffset = 0; // D3D can't push away + } + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZBIAS, iOffset)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_FOG( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DCOLOR d3dFogColour; + D3DFOGMODE d3dFogMode = D3DFOG_LINEAR; + + // TODO: Fog is calculated seperately in the Mesa pipeline + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, FALSE)); + return; + + // Fog enable + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, ctx->Fog.Enabled)); + if (!ctx->Fog.Enabled) { + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, D3DFOG_NONE)); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); + return; // If disabled, don't bother setting any fog state + } + + // Fog colour + d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0], + ctx->Fog.Color[1], + ctx->Fog.Color[2], + ctx->Fog.Color[3]); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGCOLOR, d3dFogColour)); + + // Fog density + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density)))); + + // Fog start + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGSTART, *((DWORD*) (&ctx->Fog.Start)))); + + // Fog end + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGEND, *((DWORD*) (&ctx->Fog.End)))); + + // Fog mode + switch (ctx->Fog.Mode) { + case GL_LINEAR: + d3dFogMode = D3DFOG_LINEAR; + break; + case GL_EXP: + d3dFogMode = D3DFOG_EXP; + break; + case GL_EXP2: + d3dFogMode = D3DFOG_EXP2; + break; + } + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, d3dFogMode)); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_LIGHT( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + DWORD dwSpecularEnable; + + // Shademode + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT)); + + // Separate specular colour + if (ctx->Light.Enabled) + dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE; + else + dwSpecularEnable = FALSE; + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SPECULARENABLE, dwSpecularEnable)); +} + +//--------------------------------------------------------------------------- + +void gld_NEW_MODELVIEW( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DMATRIX m; + //GLfloat *pM = ctx->ModelView.m; + // Mesa5: Model-view is now a stack + GLfloat *pM = ctx->ModelviewMatrixStack.Top->m; + m._11 = pM[0]; + m._12 = pM[1]; + m._13 = pM[2]; + m._14 = pM[3]; + m._21 = pM[4]; + m._22 = pM[5]; + m._23 = pM[6]; + m._24 = pM[7]; + m._31 = pM[8]; + m._32 = pM[9]; + m._33 = pM[10]; + m._34 = pM[11]; + m._41 = pM[12]; + m._42 = pM[13]; + m._43 = pM[14]; + m._44 = pM[15]; + + gld->matModelView = m; +} + +//--------------------------------------------------------------------------- + +void gld_NEW_PROJECTION( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DMATRIX m; + //GLfloat *pM = ctx->ProjectionMatrix.m; + // Mesa 5: Now a stack + GLfloat *pM = ctx->ProjectionMatrixStack.Top->m; + m._11 = pM[0]; + m._12 = pM[1]; + m._13 = pM[2]; + m._14 = pM[3]; + + m._21 = pM[4]; + m._22 = pM[5]; + m._23 = pM[6]; + m._24 = pM[7]; + + m._31 = pM[8]; + m._32 = pM[9]; + m._33 = pM[10] / _fPersp_33; // / 1.6f; + m._34 = pM[11]; + + m._41 = pM[12]; + m._42 = pM[13]; + m._43 = pM[14] / 2.0f; + m._44 = pM[15]; + + gld->matProjection = m; +} + +//--------------------------------------------------------------------------- +/* +void gldFrustumHook_DX8( + GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearval, + GLdouble farval) +{ + GET_CURRENT_CONTEXT(ctx); + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + // Pass values on to Mesa first (in case we mess with them) + _mesa_Frustum(left, right, bottom, top, nearval, farval); + + _fPersp_33 = farval / (nearval - farval); + +// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval); +} + +//--------------------------------------------------------------------------- + +void gldOrthoHook_DX8( + GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearval, + GLdouble farval) +{ + GET_CURRENT_CONTEXT(ctx); + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + // Pass values on to Mesa first (in case we mess with them) + _mesa_Ortho(left, right, bottom, top, nearval, farval); + + _fPersp_33 = 1.6f; + +// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval); +} +*/ +//--------------------------------------------------------------------------- + +void gld_NEW_VIEWPORT( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DVIEWPORT8 d3dvp; +// GLint x, y; +// GLsizei w, h; + + // Set depth range + _GLD_DX8_DEV(GetViewport(gld->pDev, &d3dvp)); + // D3D can't do Quake1/Quake2 z-trick + if (ctx->Viewport.Near <= ctx->Viewport.Far) { + d3dvp.MinZ = ctx->Viewport.Near; + d3dvp.MaxZ = ctx->Viewport.Far; + } else { + d3dvp.MinZ = ctx->Viewport.Far; + d3dvp.MaxZ = ctx->Viewport.Near; + } +/* x = ctx->Viewport.X; + y = ctx->Viewport.Y; + w = ctx->Viewport.Width; + h = ctx->Viewport.Height; + if (x < 0) x = 0; + if (y < 0) y = 0; + if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; + if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; + // Ditto for D3D viewport dimensions + if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; + if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; + d3dvp.X = x; + d3dvp.Y = gldCtx->dwHeight - (y + h); + d3dvp.Width = w; + d3dvp.Height = h;*/ + _GLD_DX8_DEV(SetViewport(gld->pDev, &d3dvp)); + +// gld->fFlipWindowY = (float)gldCtx->dwHeight; +} + +//--------------------------------------------------------------------------- + +__inline BOOL _gldAnyEvalEnabled( + GLcontext *ctx) +{ + struct gl_eval_attrib *eval = &ctx->Eval; + + if ((eval->AutoNormal) || + (eval->Map1Color4) || + (eval->Map1Index) || + (eval->Map1Normal) || + (eval->Map1TextureCoord1) || + (eval->Map1TextureCoord2) || + (eval->Map1TextureCoord3) || + (eval->Map1TextureCoord4) || + (eval->Map1Vertex3) || + (eval->Map1Vertex4) || + (eval->Map2Color4) || + (eval->Map2Index) || + (eval->Map2Normal) || + (eval->Map2TextureCoord1) || + (eval->Map2TextureCoord2) || + (eval->Map2TextureCoord3) || + (eval->Map2TextureCoord4) || + (eval->Map2Vertex3) || + (eval->Map2Vertex4) + ) + return TRUE; + + return FALSE; +} + +//--------------------------------------------------------------------------- + +BOOL _gldChooseInternalPipeline( + GLcontext *ctx, + GLD_driver_dx8 *gld) +{ +// return TRUE; // DEBUGGING: ALWAYS USE MESA +// return FALSE; // DEBUGGING: ALWAYS USE D3D + + if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE)) + { + gld->PipelineUsage.qwMesa.QuadPart++; + return TRUE; // Force Mesa TnL + } + + if ((ctx->Light.Enabled) || + (1) || + (ctx->Texture._TexGenEnabled) || + (ctx->Texture._TexMatEnabled) || +// (ctx->Transform._AnyClip) || + (ctx->Scissor.Enabled) || + _gldAnyEvalEnabled(ctx) // Put this last so we can early-out + ) + { + gld->PipelineUsage.qwMesa.QuadPart++; + return TRUE; + } + + gld->PipelineUsage.qwD3DFVF.QuadPart++; + return FALSE; + +/* // Force Mesa pipeline? + if (glb.dwTnL == GLDS_TNL_MESA) { + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + + // Test for functionality not exposed in the D3D pathways + if ((ctx->Texture._GenFlags)) { + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + + // Now decide if vertex shader can be used. + // If two sided lighting is enabled then we must either + // use Mesa TnL or the vertex shader + if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { + if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) { + // Use Vertex Shader + gld->PipelineUsage.dwD3D2SVS.QuadPart++; + return GLD_PIPELINE_D3D_VS_TWOSIDE; + } else { + // Use Mesa TnL + gld->PipelineUsage.dwMesa.QuadPart++; + return GLD_PIPELINE_MESA; + } + } + + // Must be D3D fixed-function pipeline + gld->PipelineUsage.dwD3DFVF.QuadPart++; + return GLD_PIPELINE_D3D_FVF; +*/ +} + +//--------------------------------------------------------------------------- + +void gld_update_state_DX8( + GLcontext *ctx, + GLuint new_state) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + TNLcontext *tnl = TNL_CONTEXT(ctx); + GLD_pb_dx8 *gldPB; + + if (!gld || !gld->pDev) + return; + + _swsetup_InvalidateState( ctx, new_state ); + _vbo_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + + // SetupIndex will be used in the pipelines for choosing setup function + if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) || + (ctx->Fog.Enabled)) + { + if (ctx->_TriangleCaps & DD_FLATSHADE) + gld->iSetupFunc = GLD_SI_FLAT_EXTRAS; + else + gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS; + } else { + if (ctx->_TriangleCaps & DD_FLATSHADE) + gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture + else + gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture + } + + gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld); + if (gld->bUseMesaTnL) { + gldPB = &gld->PB2d; + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE)); + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, FALSE)); + _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); + } else { + gldPB = &gld->PB3d; + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE)); +// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) { +// _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware)); +// _GLD_DX8_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader)); +// } else { + _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL)); + _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF)); +// } + } + +#define _GLD_TEST_STATE(a) \ + if (new_state & (a)) { \ + gld##a(ctx); \ + new_state &= ~(a); \ + } + +#define _GLD_TEST_STATE_DX8(a) \ + if (new_state & (a)) { \ + gld##a##_DX8(ctx); \ + new_state &= ~(a); \ + } + +#define _GLD_IGNORE_STATE(a) new_state &= ~(a); + +// if (!gld->bUseMesaTnL) { + // Not required if Mesa is doing the TnL. + // Problem: If gld->bUseMesaTnL is TRUE when these are signaled, + // then we'll miss updating the D3D TnL pipeline. + // Therefore, don't test for gld->bUseMesaTnL + _GLD_TEST_STATE(_NEW_MODELVIEW); + _GLD_TEST_STATE(_NEW_PROJECTION); +// } + + _GLD_TEST_STATE_DX8(_NEW_TEXTURE); // extern, so guard with _DX8 + _GLD_TEST_STATE(_NEW_COLOR); + _GLD_TEST_STATE(_NEW_DEPTH); + _GLD_TEST_STATE(_NEW_POLYGON); + _GLD_TEST_STATE(_NEW_STENCIL); + _GLD_TEST_STATE(_NEW_FOG); + _GLD_TEST_STATE(_NEW_LIGHT); + _GLD_TEST_STATE(_NEW_VIEWPORT); + + _GLD_IGNORE_STATE(_NEW_TRANSFORM); + + +// Stubs for future use. +/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX); + _GLD_TEST_STATE(_NEW_COLOR_MATRIX); + _GLD_TEST_STATE(_NEW_ACCUM); + _GLD_TEST_STATE(_NEW_EVAL); + _GLD_TEST_STATE(_NEW_HINT); + _GLD_TEST_STATE(_NEW_LINE); + _GLD_TEST_STATE(_NEW_PIXEL); + _GLD_TEST_STATE(_NEW_POINT); + _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE); + _GLD_TEST_STATE(_NEW_SCISSOR); + _GLD_TEST_STATE(_NEW_PACKUNPACK); + _GLD_TEST_STATE(_NEW_ARRAY); + _GLD_TEST_STATE(_NEW_RENDERMODE); + _GLD_TEST_STATE(_NEW_BUFFERS); + _GLD_TEST_STATE(_NEW_MULTISAMPLE); +*/ + +// For debugging. +#if 0 +#define _GLD_TEST_UNHANDLED_STATE(a) \ + if (new_state & (a)) { \ + gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \ + } + _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX); + _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX); + _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM); + _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL); + _GLD_TEST_UNHANDLED_STATE(_NEW_HINT); + _GLD_TEST_UNHANDLED_STATE(_NEW_LINE); + _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL); + _GLD_TEST_UNHANDLED_STATE(_NEW_POINT); + _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE); + _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR); + _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK); + _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY); + _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE); + _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS); + _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE); +#undef _GLD_UNHANDLED_STATE +#endif + +#undef _GLD_TEST_STATE +} + +//--------------------------------------------------------------------------- +// Viewport +//--------------------------------------------------------------------------- + +void gld_Viewport_DX8( + GLcontext *ctx, + GLint x, + GLint y, + GLsizei w, + GLsizei h) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + D3DVIEWPORT8 d3dvp; + + if (!gld || !gld->pDev) + return; + + // This is a hack. When the app is minimized, Mesa passes + // w=1 and h=1 for viewport dimensions. Without this test + // we get a GPF in gld_wgl_resize_buffers(). + if ((w==1) && (h==1)) + return; + + // Call ResizeBuffersMESA. This function will early-out + // if no resize is needed. + //ctx->Driver.ResizeBuffersMESA(ctx); + // Mesa 5: Changed parameters + ctx->Driver.ResizeBuffers(gldCtx->glBuffer); + +#if 0 + ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h); +#endif + + // ** D3D viewport must not be outside the render target surface ** + // Sanity check the GL viewport dimensions + if (x < 0) x = 0; + if (y < 0) y = 0; + if (w > gldCtx->dwWidth) w = gldCtx->dwWidth; + if (h > gldCtx->dwHeight) h = gldCtx->dwHeight; + // Ditto for D3D viewport dimensions + if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x; + if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y; + + d3dvp.X = x; + d3dvp.Y = gldCtx->dwHeight - (y + h); + d3dvp.Width = w; + d3dvp.Height = h; + if (ctx->Viewport.Near <= ctx->Viewport.Far) { + d3dvp.MinZ = ctx->Viewport.Near; + d3dvp.MaxZ = ctx->Viewport.Far; + } else { + d3dvp.MinZ = ctx->Viewport.Far; + d3dvp.MaxZ = ctx->Viewport.Near; + } + + // TODO: DEBUGGING +// d3dvp.MinZ = 0.0f; +// d3dvp.MaxZ = 1.0f; + + _GLD_DX8_DEV(SetViewport(gld->pDev, &d3dvp)); + +} + +//--------------------------------------------------------------------------- + +extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver); + +// Mesa 5: Parameter change +void gldResizeBuffers_DX8( +// GLcontext *ctx) + GLframebuffer *fb) +{ + GET_CURRENT_CONTEXT(ctx); + dglWglResizeBuffers(ctx, TRUE); +} + +//--------------------------------------------------------------------------- +#ifdef _DEBUG +// This is only for debugging. +// To use, plug into ctx->Driver.Enable pointer below. +void gld_Enable( + GLcontext *ctx, + GLenum e, + GLboolean b) +{ + char buf[1024]; + sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE"); + ddlogMessage(DDLOG_SYSTEM, buf); +} +#endif +//--------------------------------------------------------------------------- +// Driver pointer setup +//--------------------------------------------------------------------------- + +extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum); + +void gldSetupDriverPointers_DX8( + GLcontext *ctx) +{ + GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); + GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx); + + TNLcontext *tnl = TNL_CONTEXT(ctx); + + // Mandatory functions + ctx->Driver.GetString = _gldGetStringGeneric; + ctx->Driver.UpdateState = gld_update_state_DX8; + ctx->Driver.Clear = gld_Clear_DX8; + ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX8; + ctx->Driver.GetBufferSize = gld_buffer_size_DX8; + ctx->Driver.Finish = gld_Finish_DX8; + ctx->Driver.Flush = gld_Flush_DX8; + ctx->Driver.Error = gld_Error_DX8; + + // Hardware accumulation buffer + ctx->Driver.Accum = NULL; // TODO: gld_Accum; + + // Bitmap functions + ctx->Driver.CopyPixels = gld_CopyPixels_DX8; + ctx->Driver.DrawPixels = gld_DrawPixels_DX8; + ctx->Driver.ReadPixels = gld_ReadPixels_DX8; + ctx->Driver.Bitmap = gld_Bitmap_DX8; + + // Buffer resize + ctx->Driver.ResizeBuffers = gldResizeBuffers_DX8; + + // Texture image functions + ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX8; + ctx->Driver.TexImage1D = gld_TexImage1D_DX8; + ctx->Driver.TexImage2D = gld_TexImage2D_DX8; + ctx->Driver.TexImage3D = _mesa_store_teximage3d; + ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX8; + ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX8; + ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + + ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX8; //NULL; + ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX8; //NULL; + ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX8; //NULL; + ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX8; //NULL; + ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX8; + ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; + + // Texture object functions + ctx->Driver.BindTexture = NULL; + ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!; + ctx->Driver.DeleteTexture = gld_DeleteTexture_DX8; + ctx->Driver.PrioritizeTexture = NULL; + + // Imaging functionality + ctx->Driver.CopyColorTable = NULL; + ctx->Driver.CopyColorSubTable = NULL; + ctx->Driver.CopyConvolutionFilter1D = NULL; + ctx->Driver.CopyConvolutionFilter2D = NULL; + + // State changing functions + ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc; + ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc; + ctx->Driver.ClearColor = NULL; //gld_ClearColor; + ctx->Driver.ClearDepth = NULL; //gld_ClearDepth; + ctx->Driver.ClearStencil = NULL; //gld_ClearStencil; + ctx->Driver.ColorMask = NULL; //gld_ColorMask; + ctx->Driver.CullFace = NULL; //gld_CullFace; + ctx->Driver.ClipPlane = NULL; //gld_ClipPlane; + ctx->Driver.FrontFace = NULL; //gld_FrontFace; + ctx->Driver.DepthFunc = NULL; //gld_DepthFunc; + ctx->Driver.DepthMask = NULL; //gld_DepthMask; + ctx->Driver.DepthRange = NULL; + ctx->Driver.Enable = NULL; //gld_Enable; + ctx->Driver.Fogfv = NULL; //gld_Fogfv; + ctx->Driver.Hint = NULL; //gld_Hint; + ctx->Driver.Lightfv = NULL; //gld_Lightfv; + ctx->Driver.LightModelfv = NULL; //gld_LightModelfv; + ctx->Driver.LineStipple = NULL; //gld_LineStipple; + ctx->Driver.LineWidth = NULL; //gld_LineWidth; + ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode; + ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv; + ctx->Driver.PointSize = NULL; //gld_PointSize; + ctx->Driver.PolygonMode = NULL; //gld_PolygonMode; + ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset; + ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple; + ctx->Driver.RenderMode = NULL; //gld_RenderMode; + ctx->Driver.Scissor = NULL; //gld_Scissor; + ctx->Driver.ShadeModel = NULL; //gld_ShadeModel; + ctx->Driver.StencilFunc = NULL; //gld_StencilFunc; + ctx->Driver.StencilMask = NULL; //gld_StencilMask; + ctx->Driver.StencilOp = NULL; //gld_StencilOp; + ctx->Driver.TexGen = NULL; //gld_TexGen; + ctx->Driver.TexEnv = NULL; + ctx->Driver.TexParameter = NULL; + ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix; + ctx->Driver.Viewport = gld_Viewport_DX8; + + _swsetup_Wakeup(ctx); + + tnl->Driver.RunPipeline = _tnl_run_pipeline; + tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX8; + tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; + tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; + + // Hook into glFrustum() and glOrtho() +// ctx->Exec->Frustum = gldFrustumHook_DX8; +// ctx->Exec->Ortho = gldOrthoHook_DX8; + +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/dx8/gld_pipeline_dx8.c +++ mesa-7.2/src/mesa/drivers/windows/gldirect/dx8/gld_pipeline_dx8.c @@ -0,0 +1,77 @@ +/**************************************************************************** +* +* Mesa 3-D graphics library +* Direct3D Driver Interface +* +* ======================================================================== +* +* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +* SCITECH SOFTWARE INC 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. +* +* ====================================================================== +* +* Language: ANSI C +* Environment: Windows 9x/2000/XP/XBox (Win32) +* +* Description: Mesa transformation pipeline with GLDirect fastpath +* +****************************************************************************/ + +//#include "../GLDirect.h" + +#include "dglcontext.h" +#include "ddlog.h" +#include "gld_dx8.h" + +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +//--------------------------------------------------------------------------- + +extern struct tnl_pipeline_stage _gld_d3d_render_stage; +extern struct tnl_pipeline_stage _gld_mesa_render_stage; + +static const struct tnl_pipeline_stage *gld_pipeline[] = { + &_gld_d3d_render_stage, // Direct3D TnL + &_tnl_vertex_transform_stage, + &_tnl_normal_transform_stage, + &_tnl_lighting_stage, + &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage. ??? */ + &_tnl_texgen_stage, + &_tnl_texture_transform_stage, + &_tnl_point_attenuation_stage, + &_gld_mesa_render_stage, // Mesa TnL, D3D rendering + 0, +}; + +//--------------------------------------------------------------------------- + +void gldInstallPipeline_DX8( + GLcontext *ctx) +{ + // Remove any existing pipeline stages, + // then install GLDirect pipeline stages. + + _tnl_destroy_pipeline(ctx); + _tnl_install_pipeline(ctx, gld_pipeline); +} + +//--------------------------------------------------------------------------- --- mesa-7.2.orig/src/mesa/drivers/windows/gldirect/opengl32.ref +++ mesa-7.2/src/mesa/drivers/windows/gldirect/opengl32.ref @@ -0,0 +1,495 @@ +;**************************************************************************** +;* +;* Mesa 3-D graphics library +;* Direct3D Driver Interface +;* +;* ======================================================================== +;* +;* Copyright (C) 1991-2004 SciTech Software, Inc. 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 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 +;* SCITECH SOFTWARE INC 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. +;* +;* ====================================================================== +;* +;* Language: ANSI C +;* Environment: Windows 9x/2000/XP/XBox (Win32) +;* +;* Description: DLL Module definition file +;* +;****************************************************************************/ + +DESCRIPTION 'GLDirect' + +VERSION 3.0 + +EXPORTS + glAccum + glAlphaFunc + glAreTexturesResident + glArrayElement + glBegin + glBindTexture + glBitmap + glBlendFunc + glCallList + glCallLists + glClear + glClearAccum + glClearIndex + glClearColor + glClearDepth + glClearStencil + glClipPlane + glColor3b + glColor3d + glColor3f + glColor3i + glColor3s + glColor3ub + glColor3ui + glColor3us + glColor4b + glColor4d + glColor4f + glColor4i + glColor4s + glColor4ub + glColor4ui + glColor4us + glColor3bv + glColor3dv + glColor3fv + glColor3iv + glColor3sv + glColor3ubv + glColor3uiv + glColor3usv + glColor4bv + glColor4dv + glColor4fv + glColor4iv + glColor4sv + glColor4ubv + glColor4uiv + glColor4usv + glColorMask + glColorMaterial + glColorPointer + glColorTableEXT + glColorSubTableEXT + glCopyPixels + glCopyTexImage1D + glCopyTexImage2D + glCopyTexSubImage1D + glCopyTexSubImage2D + glCullFace + glDepthFunc + glDepthMask + glDepthRange + glDeleteLists + glDeleteTextures + glDisable + glDisableClientState + glDrawArrays + glDrawBuffer + glDrawElements + glDrawPixels + glEnable + glEnableClientState + glEnd + glEndList + glEvalCoord1d + glEvalCoord1f + glEvalCoord1dv + glEvalCoord1fv + glEvalCoord2d + glEvalCoord2f + glEvalCoord2dv + glEvalCoord2fv + glEvalPoint1 + glEvalPoint2 + glEvalMesh1 + glEdgeFlag + glEdgeFlagv + glEdgeFlagPointer + glEvalMesh2 + glFeedbackBuffer + glFinish + glFlush + glFogf + glFogi + glFogfv + glFogiv + glFrontFace + glFrustum + glGenLists + glGenTextures + glGetBooleanv + glGetClipPlane + glGetColorTableEXT + glGetColorTableParameterivEXT + glGetColorTableParameterfvEXT + glGetDoublev + glGetError + glGetFloatv + glGetIntegerv + glGetLightfv + glGetLightiv + glGetMapdv + glGetMapfv + glGetMapiv + glGetMaterialfv + glGetMaterialiv + glGetPixelMapfv + glGetPixelMapuiv + glGetPixelMapusv + glGetPointerv + glGetPolygonStipple + glGetString + glGetTexEnvfv + glGetTexEnviv + glGetTexGeniv + glGetTexGendv + glGetTexGenfv + glGetTexImage + glGetTexLevelParameterfv + glGetTexLevelParameteriv + glGetTexParameterfv + glGetTexParameteriv + glHint + glIndexd + glIndexf + glIndexi + glIndexs + glIndexub + glIndexdv + glIndexfv + glIndexiv + glIndexsv + glIndexubv + glIndexMask + glIndexPointer + glInterleavedArrays + glInitNames + glIsList + glIsTexture + glLightf + glLighti + glLightfv + glLightiv + glLightModelf + glLightModeli + glLightModelfv + glLightModeliv + glLineWidth + glLineStipple + glListBase + glLoadIdentity + glLoadMatrixd + glLoadMatrixf + glLoadName + glLogicOp + glMap1d + glMap1f + glMap2d + glMap2f + glMapGrid1d + glMapGrid1f + glMapGrid2d + glMapGrid2f + glMaterialf + glMateriali + glMaterialfv + glMaterialiv + glMatrixMode + glMultMatrixd + glMultMatrixf + glNewList + glNormal3b + glNormal3d + glNormal3f + glNormal3i + glNormal3s + glNormal3bv + glNormal3dv + glNormal3fv + glNormal3iv + glNormal3sv + glNormalPointer + glOrtho + glPassThrough + glPixelMapfv + glPixelMapuiv + glPixelMapusv + glPixelStoref + glPixelStorei + glPixelTransferf + glPixelTransferi + glPixelZoom + glPointSize + glPolygonMode + glPolygonOffset + glPolygonOffsetEXT + glPolygonStipple + glPopAttrib + glPopClientAttrib + glPopMatrix + glPopName + glPrioritizeTextures + glPushMatrix + glRasterPos2d + glRasterPos2f + glRasterPos2i + glRasterPos2s + glRasterPos3d + glRasterPos3f + glRasterPos3i + glRasterPos3s + glRasterPos4d + glRasterPos4f + glRasterPos4i + glRasterPos4s + glRasterPos2dv + glRasterPos2fv + glRasterPos2iv + glRasterPos2sv + glRasterPos3dv + glRasterPos3fv + glRasterPos3iv + glRasterPos3sv + glRasterPos4dv + glRasterPos4fv + glRasterPos4iv + glRasterPos4sv + glReadBuffer + glReadPixels + glRectd + glRectf + glRecti + glRects + glRectdv + glRectfv + glRectiv + glRectsv + glScissor + glIsEnabled + glPushAttrib + glPushClientAttrib + glPushName + glRenderMode + glRotated + glRotatef + glSelectBuffer + glScaled + glScalef + glShadeModel + glStencilFunc + glStencilMask + glStencilOp + glTexCoord1d + glTexCoord1f + glTexCoord1i + glTexCoord1s + glTexCoord2d + glTexCoord2f + glTexCoord2i + glTexCoord2s + glTexCoord3d + glTexCoord3f + glTexCoord3i + glTexCoord3s + glTexCoord4d + glTexCoord4f + glTexCoord4i + glTexCoord4s + glTexCoord1dv + glTexCoord1fv + glTexCoord1iv + glTexCoord1sv + glTexCoord2dv + glTexCoord2fv + glTexCoord2iv + glTexCoord2sv + glTexCoord3dv + glTexCoord3fv + glTexCoord3iv + glTexCoord3sv + glTexCoord4dv + glTexCoord4fv + glTexCoord4iv + glTexCoord4sv + glTexCoordPointer + glTexGend + glTexGenf + glTexGeni + glTexGendv + glTexGeniv + glTexGenfv + glTexEnvf + glTexEnvi + glTexEnvfv + glTexEnviv + glTexImage1D + glTexImage2D + glTexParameterf + glTexParameteri + glTexParameterfv + glTexParameteriv + glTexSubImage1D + glTexSubImage2D + glTranslated + glTranslatef + glVertex2d + glVertex2f + glVertex2i + glVertex2s + glVertex3d + glVertex3f + glVertex3i + glVertex3s + glVertex4d + glVertex4f + glVertex4i + glVertex4s + glVertex2dv + glVertex2fv + glVertex2iv + glVertex2sv + glVertex3dv + glVertex3fv + glVertex3iv + glVertex3sv + glVertex4dv + glVertex4fv + glVertex4iv + glVertex4sv + glVertexPointer + glViewport + + glBlendEquationEXT + glBlendColorEXT + glVertexPointerEXT + glNormalPointerEXT + glColorPointerEXT + glIndexPointerEXT + glTexCoordPointerEXT + glEdgeFlagPointerEXT + glGetPointervEXT + glArrayElementEXT + glDrawArraysEXT + glBindTextureEXT + glDeleteTexturesEXT + glGenTexturesEXT + glPrioritizeTexturesEXT + glCopyTexSubImage3DEXT + glTexImage3DEXT + glTexSubImage3DEXT + + glWindowPos4fMESA + glWindowPos2iMESA + glWindowPos2sMESA + glWindowPos2fMESA + glWindowPos2dMESA + glWindowPos2ivMESA + glWindowPos2svMESA + glWindowPos2fvMESA + glWindowPos2dvMESA + glWindowPos3iMESA + glWindowPos3sMESA + glWindowPos3fMESA + glWindowPos3dMESA + glWindowPos3ivMESA + glWindowPos3svMESA + glWindowPos3fvMESA + glWindowPos3dvMESA + glWindowPos4iMESA + glWindowPos4sMESA + glWindowPos4dMESA + glWindowPos4ivMESA + glWindowPos4svMESA + glWindowPos4fvMESA + glWindowPos4dvMESA + glResizeBuffersMESA + + wglCopyContext + wglCreateContext + wglCreateLayerContext + wglDeleteContext + wglDescribeLayerPlane + wglGetCurrentContext + wglGetCurrentDC + wglGetLayerPaletteEntries + wglGetProcAddress + wglMakeCurrent + wglRealizeLayerPalette + wglSetLayerPaletteEntries + wglShareLists + wglSwapLayerBuffers + wglUseFontBitmapsA + wglUseFontBitmapsW + wglUseFontOutlinesA + wglUseFontOutlinesW + +;These functions are identical and therefore share the same addresses + ChoosePixelFormat = wglChoosePixelFormat + DescribePixelFormat = wglDescribePixelFormat + GetPixelFormat = wglGetPixelFormat + SetPixelFormat = wglSetPixelFormat + SwapBuffers = wglSwapBuffers + + wglChoosePixelFormat + wglDescribePixelFormat + wglGetPixelFormat + wglSetPixelFormat + wglSwapBuffers + + glActiveTextureARB + glClientActiveTextureARB + glMultiTexCoord1dARB + glMultiTexCoord1dvARB + glMultiTexCoord1fARB + glMultiTexCoord1fvARB + glMultiTexCoord1iARB + glMultiTexCoord1ivARB + glMultiTexCoord1sARB + glMultiTexCoord1svARB + glMultiTexCoord2dARB + glMultiTexCoord2dvARB + glMultiTexCoord2fARB + glMultiTexCoord2fvARB + glMultiTexCoord2iARB + glMultiTexCoord2ivARB + glMultiTexCoord2sARB + glMultiTexCoord2svARB + glMultiTexCoord3dARB + glMultiTexCoord3dvARB + glMultiTexCoord3fARB + glMultiTexCoord3fvARB + glMultiTexCoord3iARB + glMultiTexCoord3ivARB + glMultiTexCoord3sARB + glMultiTexCoord3svARB + glMultiTexCoord4dARB + glMultiTexCoord4dvARB + glMultiTexCoord4fARB + glMultiTexCoord4fvARB + glMultiTexCoord4iARB + glMultiTexCoord4ivARB + glMultiTexCoord4sARB + glMultiTexCoord4svARB --- mesa-7.2.orig/src/mesa/drivers/dri/mga/README +++ mesa-7.2/src/mesa/drivers/dri/mga/README @@ -0,0 +1,26 @@ +MGA DRI driver ported from XF86DRI to FBDRI +by Denis Oliver Kropp + + +INFO + +This driver has been ported from the head branch of XFree86 to +the embedded-1-branch of Mesa. + + +STATUS + +Already working very well as far as I've tested it (16/32 bit). +glxgears runs at 935 fps (G550 32MB AGP 4x, Athlon 1.33) vs 744 fps with XFree. +Other demos (terrain, fire, etc.) have been successfully tested as well. + + +TODO + +- mgaEngineShutdown +- mgaEngineRestore +- SGRAM detection +- remove some unused bits from server/* +- subset driver support +- mgaWaitForVBlank +- deinitialization (from MGADRICloseScreen) a la radeonDestroyScreen --- mesa-7.2.orig/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fasttmp.h +++ mesa-7.2/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fasttmp.h @@ -0,0 +1,314 @@ +/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fasttmp.h,v 1.2 2000/09/26 15:56:51 tsi Exp $ */ + +#if !defined(NASM_ASSEMBLER) && !defined(MASM_ASSEMBLER) +#define TAGLLBL(a) TAG(.L##a) +#else +#define TAGLLBL(a) TAG(a) +#endif + +#if !GLIDE3 + +#define GR_VERTEX_X_OFFSET 0 +#define GR_VERTEX_Y_OFFSET 4 +#define GR_VERTEX_Z_OFFSET 8 +#define GR_VERTEX_R_OFFSET 12 +#define GR_VERTEX_G_OFFSET 16 +#define GR_VERTEX_B_OFFSET 20 +#define GR_VERTEX_OOZ_OFFSET 24 +#define GR_VERTEX_A_OFFSET 28 +#define GR_VERTEX_OOW_OFFSET 32 + +#else /* GLIDE3 */ + +#define GR_VERTEX_X_OFFSET 0 +#define GR_VERTEX_Y_OFFSET 4 +#define GR_VERTEX_OOZ_OFFSET 8 +#define GR_VERTEX_OOW_OFFSET 12 +#define GR_VERTEX_R_OFFSET 16 +#define GR_VERTEX_G_OFFSET 20 +#define GR_VERTEX_B_OFFSET 24 +#define GR_VERTEX_A_OFFSET 28 +#define GR_VERTEX_Z_OFFSET 32 + +#endif /* GLIDE3 */ + +#define GR_VERTEX_SOW_TMU0_OFFSET 36 +#define GR_VERTEX_TOW_TMU0_OFFSET 40 +#define GR_VERTEX_OOW_TMU0_OFFSET 44 +#define GR_VERTEX_SOW_TMU1_OFFSET 48 +#define GR_VERTEX_TOW_TMU1_OFFSET 52 +#define GR_VERTEX_OOW_TMU1_OFFSET 56 + + + + +/*#define MAT_SX 0 /* accessed by REGIND !! */ +#define MAT_SY 20 +#define MAT_SZ 40 +#define MAT_TX 48 +#define MAT_TY 52 +#define MAT_TZ 56 + + + + +/* Do viewport map, device scale and perspective projection. + * + * void project_verts( GLfloat *first, + * GLfloat *last, + * const GLfloat *m, + * GLuint stride ) + * + * + * Rearrange fxVertices to look like grVertices. + */ + +GLOBL GLNAME( TAG(fx_3dnow_project_vertices) ) +GLNAME( TAG(fx_3dnow_project_vertices) ): + + PUSH_L ( EBP ) + + MOV_L ( REGOFF(8, ESP), ECX ) /* first_vert */ + MOV_L ( REGOFF(12, ESP), EDX ) /* last_vert */ + + CMP_L ( ECX, EDX ) + JE ( TAGLLBL(FXPV_end) ) + + FEMMS + + PREFETCH ( REGIND(ECX) ) /* fetch the first vertex */ + + MOV_L ( REGOFF(16, ESP), EBP ) /* matrix */ + MOV_L ( REGOFF(20, ESP), EAX ) /* stride */ + + MOVD ( REGOFF(MAT_TX, EBP), MM6 ) /* | tx */ + PUNPCKLDQ ( REGOFF(MAT_TY, EBP), MM6 ) /* ty | tx */ + +#if !defined(FX_V2) + MOV_L ( CONST(0x49400000), REGOFF(-8, ESP) ) /* snapper */ + MOV_L ( CONST(0x49400000), REGOFF(-4, ESP) ) /* snapper */ +#endif + + MOVQ ( REGOFF(-8, ESP), MM4 ) /* snapper | snapper */ + PFADD ( MM4, MM6 ) /* ty+snapper | tx+snapper */ + + MOVD ( REGIND(EBP), MM5 ) + PUNPCKLDQ ( REGOFF(MAT_SY, EBP), MM5 ) /* vsy | vsx */ + + MOVD ( REGOFF(MAT_SZ, EBP), MM1 ) /* | vsz */ + + +ALIGNTEXT32 +TAGLLBL(FXPV_loop_start): + + PREFETCH ( REGOFF(64, ECX) ) /* fetch the next-ish vertex */ + + + MOVD ( REGOFF(12, ECX), MM0 ) /* | f[3] */ + PFRCP ( MM0, MM0 ) /* oow = 1/f[3] */ + + MOVD ( REGOFF(12, ECX), MM7 ) /* | f[3] */ + PFRCPIT1 ( MM0, MM7 ) + PFRCPIT2 ( MM0, MM7 ) /* oow | oow */ + + PUNPCKLDQ ( MM7, MM7 ) + + +#if (TYPE & SETUP_RGBA) + MOVD ( REGOFF(CLIP_R, ECX ), MM0 ) /* f[RCOORD] = f[CLIP_R]; */ + MOVD ( MM0, REGOFF(GR_VERTEX_R_OFFSET, ECX) ) +#endif + +#if (TYPE & SETUP_TMU1) + MOVQ ( REGOFF(CLIP_S1, ECX), MM0 ) /* f[S1COORD] = f[CLIP_S1] * oow */ + PFMUL ( MM7, MM0 ) /* f[T1COORD] = f[CLIP_T1] * oow */ + MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU1_OFFSET, ECX) ) +#endif + + +#if (TYPE & SETUP_TMU0) + MOVQ ( REGOFF(CLIP_S0, ECX), MM0 ) /* f[S0COORD] = f[CLIP_S0] * oow */ + PFMUL ( MM7, MM0 ) /* f[T0COORD] = f[CLIP_T0] * oow */ + MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU0_OFFSET, ECX) ) +#endif + + + + + +/* DO_SETUP_XYZ */ + + MOVQ ( REGIND(ECX), MM2 ) /* f[1] | f[0] */ + PFMUL ( MM7, MM2 ) /* f[1] * oow | f[0] * oow */ + + MOVD ( REGOFF(8, ECX), MM3 ) /* | f[2] */ + PFMUL ( MM7, MM3 ) /* | f[2] * oow */ + + MOVD ( REGOFF(MAT_TZ, EBP), MM0 ) /* | vtz */ + PFMUL ( MM1, MM3 ) /* | f[2] *= vsz */ + + PFADD ( MM0, MM3 ) /* | f[2] += vtz */ + PFMUL ( MM5, MM2 ) /* f[1] *= vsy | f[0] *= vsx */ + + PFADD ( MM6, MM2 ) /* f[1] += vty | f[0] += vtx */ + +#if !defined(FX_V2) + PFSUB ( MM4, MM2 ) /* f[0,1] -= snapper */ +#endif + + MOVQ ( MM2, REGOFF(GR_VERTEX_X_OFFSET, ECX) ) + MOVD ( MM3, REGOFF(GR_VERTEX_OOZ_OFFSET, ECX) ) + + +/* end of DO_SETUP_XYZ */ + + MOVD ( MM7, REGOFF(GR_VERTEX_OOW_OFFSET, ECX) ) /* f[OOWCOORD] = oow */ + ADD_L ( EAX, ECX ) /* f += stride */ + + CMP_L ( ECX, EDX ) /* stall??? */ + JA ( TAGLLBL(FXPV_loop_start) ) + +TAGLLBL(FXPV_end): + FEMMS + POP_L ( EBP ) + RET + + + + + + + +/* void project_verts( GLfloat *first, + * GLfloat *last, + * const GLfloat *m, + * GLuint stride, + * const GLubyte *mask ) + * + */ + +GLOBL GLNAME( TAG(fx_3dnow_project_clipped_vertices) ) +GLNAME( TAG(fx_3dnow_project_clipped_vertices) ): + + PUSH_L ( EBP ) + + MOV_L ( REGOFF(8, ESP), ECX ) /* first FXDRIVER(VB)->verts*/ + MOV_L ( REGOFF(12, ESP), EDX ) /* last FXDRIVER(VB)->last_vert */ + + FEMMS + + PUSH_L ( EDI ) + PUSH_L ( ESI ) + + PREFETCH ( REGIND(ECX) ) /* fetch the first vertex */ + + MOV_L ( REGOFF(24, ESP), EBP ) /* mat ctx->Viewport.WindowMap.M */ + MOV_L ( REGOFF(28, ESP), EAX ) /* stride */ + MOV_L ( REGOFF(32, ESP), ESI ) /* VB->ClipMask */ + + MOVD ( REGOFF(MAT_TX, EBP), MM6 ) /* | tx */ + PUNPCKLDQ ( REGOFF(MAT_TY, EBP), MM6 ) /* ty | tx */ + +#if !defined(FX_V2) + MOV_L ( CONST(0x49400000), REGOFF(-8, ESP) ) /* snapper */ + MOV_L ( CONST(0x49400000), REGOFF(-4, ESP) ) /* snapper */ +#endif + + MOVQ ( REGOFF(-8, ESP), MM4 ) /* snapper | snapper */ + PFADD ( MM4, MM6 ) /* ty+snapper | tx+snapper */ + + MOVD ( REGIND(EBP), MM5 ) + PUNPCKLDQ ( REGOFF(MAT_SY, EBP), MM5 ) /* vsy | vsx */ + + MOVD ( REGOFF(MAT_SZ, EBP), MM1 ) /* | vsz */ + + + +ALIGNTEXT32 +TAGLLBL(FXPCV_loop_start): + + PREFETCH ( REGOFF(64, ECX) ) /* fetch the next-ish vertex */ + + CMP_B ( CONST(0), REGIND(ESI) ) + JNE ( TAGLLBL(FXPCV_skip) ) + + MOVD ( REGOFF(12, ECX), MM0) /* | f[3] */ + PFRCP ( MM0, MM0 ) /* oow = 1/f[3] */ + + MOVD ( REGOFF(12, ECX), MM7) /* | f[3] */ + PFRCPIT1 ( MM0, MM7 ) + PFRCPIT2 ( MM0, MM7 ) /* oow | oow */ + + PUNPCKLDQ ( MM7, MM7 ) + + +#if (TYPE & SETUP_RGBA) + MOVD ( REGOFF(CLIP_R, ECX ), MM0 ) /* f[RCOORD] = f[CLIP_R]; */ + MOVD ( MM0, REGOFF(GR_VERTEX_R_OFFSET, ECX) ) +#endif + +#if (TYPE & SETUP_TMU1) + MOVQ ( REGOFF(CLIP_S1, ECX), MM0 ) /* f[S1COORD] = f[CLIP_S1] * oow */ + PFMUL ( MM7, MM0 ) /* f[T1COORD] = f[CLIP_T1] * oow */ + MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU1_OFFSET, ECX) ) +#endif + + +#if (TYPE & SETUP_TMU0) + MOVQ ( REGOFF(CLIP_S0, ECX), MM0 ) /* f[S0COORD] = f[CLIP_S0] * oow */ + PFMUL ( MM7, MM0 ) /* f[T0COORD] = f[CLIP_T0] * oow */ + MOVQ ( MM0, REGOFF(GR_VERTEX_SOW_TMU0_OFFSET, ECX) ) +#endif + + + + +/* DO_SETUP_XYZ */ + + MOVQ ( REGIND(ECX), MM2 ) /* f[1] | f[0] */ + PFMUL ( MM7, MM2 ) /* f[1] * oow | f[0] * oow */ + + MOVD ( REGOFF(8, ECX), MM3 ) /* | f[2] */ + PFMUL ( MM7, MM3 ) /* | f[2] * oow */ + + MOVD ( REGOFF(MAT_TZ, EBP), MM0 ) /* | vtz */ + PFMUL ( MM1, MM3 ) /* | f[2] *= vsz */ + + PFADD ( MM0, MM3 ) /* | f[2] += vtz */ + PFMUL ( MM5, MM2 ) /* f[1] *= vsy | f[0] *= vsx */ + + PFADD ( MM6, MM2 ) /* f[1] += vty | f[0] += vtx */ + +#if !defined(FX_V2) + PFSUB ( MM4, MM2 ) /* f[0,1] -= snapper */ +#endif + + MOVQ ( MM2, REGOFF(GR_VERTEX_X_OFFSET, ECX) ) + MOVD ( MM3, REGOFF(GR_VERTEX_OOZ_OFFSET, ECX) ) + + +/* end of DO_SETUP_XYZ */ + + MOVD ( MM7, REGOFF(GR_VERTEX_OOW_OFFSET, ECX) ) /* f[OOWCOORD] = oow */ + +TAGLLBL(FXPCV_skip): + ADD_L ( EAX, ECX ) /* f += stride */ + + INC_L ( ESI ) /* next ClipMask */ + CMP_L ( ECX, EDX ) + JA ( TAGLLBL(FXPCV_loop_start) ) + + POP_L ( ESI ) + POP_L ( EDI ) + +TAGLLBL(FXPCV_end): + FEMMS + POP_L ( EBP ) + RET + + + +#undef TYPE +#undef TAG +#undef SIZE + --- mesa-7.2.orig/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fastpath.S +++ mesa-7.2/src/mesa/drivers/dri/tdfx/X86/fx_3dnow_fastpath.S @@ -0,0 +1,84 @@ +/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fastpath.S,v 1.2 2000/09/26 15:56:51 tsi Exp $ */ + +#include "../../X86/assyntax.h" + +#define SETUP_RGBA 0x1 +#define SETUP_TMU0 0x2 +#define SETUP_TMU1 0x4 + + +/* Pack either rgba or texture into the remaining half of a 32 byte vertex. + */ +#define CLIP_R 24 +#define CLIP_G 16 +#define CLIP_B 20 +#define CLIP_A 28 /* defined inf fxdrv.h */ + +#define CLIP_S0 16 +#define CLIP_T0 20 +#define CLIP_S1 24 +#define CLIP_T1 28 + +#define SIZE 4 +#define TYPE (0) +#define TAG(x) x +#include "fx_3dnow_fasttmp.h" + +#define SIZE 8 +#define TYPE (SETUP_RGBA) +#define TAG(x) x##_RGBA +#include "fx_3dnow_fasttmp.h" + +#define SIZE 6 +#define TYPE (SETUP_TMU0) +#define TAG(x) x##_TMU0 +#include "fx_3dnow_fasttmp.h" + +#define SIZE 8 +#define TYPE (SETUP_TMU0|SETUP_TMU1) +#define TAG(x) x##_TMU0_TMU1 +#include "fx_3dnow_fasttmp.h" + +#undef CLIP_S1 +#undef CLIP_T1 +#define CLIP_S1 16 +#define CLIP_T1 20 + +#define SIZE 6 +#define TYPE (SETUP_TMU1) +#define TAG(x) x##_TMU1 +#include "fx_3dnow_fasttmp.h" + +/* These three need to use a full 64 byte clip-space vertex. + */ +#undef CLIP_S0 +#undef CLIP_T0 +#undef CLIP_S1 +#undef CLIP_T1 + +#define CLIP_S0 32 +#define CLIP_T0 36 +#define CLIP_S1 40 +#define CLIP_T1 44 + +#define SIZE 10 +#define TYPE (SETUP_RGBA|SETUP_TMU0) +#define TAG(x) x##_RGBA_TMU0 +#include "fx_3dnow_fasttmp.h" + +#define SIZE 12 +#define TYPE (SETUP_RGBA|SETUP_TMU0|SETUP_TMU1) +#define TAG(x) x##_RGBA_TMU0_TMU1 +#include "fx_3dnow_fasttmp.h" + +#undef CLIP_S1 +#undef CLIP_T1 +#define CLIP_S1 32 +#define CLIP_T1 36 + +#define SIZE 10 +#define TYPE (SETUP_RGBA|SETUP_TMU1) +#define TAG(x) x##_RGBA_TMU1 +#include "fx_3dnow_fasttmp.h" + + --- mesa-7.2.orig/src/mesa/drivers/dri/tdfx/BUGS +++ mesa-7.2/src/mesa/drivers/dri/tdfx/BUGS @@ -0,0 +1,64 @@ +REMOVE THIS FILE BEFORE MERGING WITH TRUNK +------------------------------------------ + +OUTSTANDING BUGS + +demos/reflect - reading back Z on Voodoo3, image offset to right + Fixed in latest Glide. + +Q3 - some polygons drawn as vertical strips, similar to bug that was + seen in demos/fire. Voodoo3 only. May be related to glDepthMask + or glColorMask. + +book/fog - not fogging + Fog in orthograph mode still not implemented. Checking with + 3dfx engineers for ideas. + +Q3 demo crashes after changing display settings + but the full Q3 game version seems OK. + + + +MORE OUTSTANDING BUGS + +private context was NULL! causing immediate failure of any glx prog. cant +reproduce after restarting the X server. putting it down as halluc. + +texture object image was NULL, causing segmentation failure. happens with +prboom. ive put a check in tdfx_texstate.c but this isn't a fix. + +prboom, wall textures near first chainsaw aren't bound properly. sideways +movements causes the wall textures to move with you. prboom busted? + +16bpp mode, quake3, windowed, q3dm1, floor under rocketlauncher bands. it +looks like multitexturing gone wrong. i'll disable a tmu and test. + +sof, polygons appear at wrong x,y,z positions, intermittent, have not yet +found reliable way of reproducing. culling? sometimes polys disappear. + +descent3 is all black in 16bpp mode - FIXED (palette problems) + +smeared pixels in quake3 - FIXED (texture memory overlapped FB) + + + +PERFORMANCE COMPARISON (Brian / Alan) + + V3/16 is Voodoo3 in 16bpp on a P3/500 + V5/16 is Voodoo5 in 16bpp on a P3/600 + V5/32 is Voodoo5 in 32bpp on a P3/600 + V5A/16 is Voodoo5 in 16bpp on an Alpha AXP/600 + V5A/32 is Voodoo5 in 32bpp on an Alpha AXP/600 + + tdfx-2-1-branch tdfx-3-0-0-branch +demo V3/16 V5/16 V5/32 V3/16 V5/16 V5/32 V5A/16 V5A/32 +------------------------------------------------------------------------ +gloss 257 183 174 320 308 177 313 167 +fire 42 39 52 41 +fire (no help) 98 80 50 106 113 73 124 80 +tunnel 61 50 70 58 +tunnel (no help) 167 142 57 138 152 113 171 122 +gears 663 554 540 881 1232 776 1484 830 +teapot 20 21 37 36 +teapot (no help) 22 14 14 24 30 30 43 42 + --- mesa-7.2.orig/src/mesa/drivers/dri/common/xmlpool/Makefile +++ mesa-7.2/src/mesa/drivers/dri/common/xmlpool/Makefile @@ -0,0 +1,96 @@ +# Convenient makefile for managing translations. + +# Prerequisites: +# - GNU gettext +# - Python + +# Adding new translations +# ----------------------- + +# To start working on a new translation edit the POS=... line +# below. If you want to add for example a french translation, add +# fr.po. + +# Then run "make po" to generate a fresh .po file from translatable +# strings in t_options.h. Now you can edit the new .po file (fr.po in +# the example above) to translate the strings. Please make sure that +# your editor encodes the file in UTF-8. + +# Updating existing translations +# ------------------------------ + +# Run "make po" to update .po files with new translatable strings from +# t_options.h. Now you can edit the .po files you're interested +# in. Please make sure that your editor encodes the file in UTF-8. + +# Updating options.h +# ------------------ + +# Finally run "make" to generate options.h from t_options.h with all +# translations. Now you can rebuild the drivers. Any common options +# used by the drivers will have option descriptions with the latest +# translations. + +# Publishing translations +# ----------------------- + +# To get your translation(s) into Mesa CVS, please send me your +# .po file. + +# More information: +# - info gettext + +# The set of supported languages. Add languages as needed. +POS=de.po es.po nl.po fr.po sv.po + +# +# Don't change anything below, unless you know what you're doing. +# +LANGS=$(POS:%.po=%) +MOS=$(POS:%.po=%/LC_MESSAGES/options.mo) +POT=xmlpool.pot + +.PHONY: all clean pot po mo + +all: options.h + +# Only intermediate files are cleaned up. options.h is not deleted because +# it's in CVS. +clean: + -rm -f $(POT) *~ + -rm -rf $(LANGS) + +# Default target options.h +options.h: t_options.h mo + python gen_xmlpool.py $(LANGS) > options.h + +# Update .mo files from the corresponding .po files. +mo: + @for mo in $(MOS); do \ + lang=$${mo%%/*}; \ + echo "Updating $$mo from $$lang.po."; \ + mkdir -p $${mo%/*}; \ + msgfmt -o $$mo $$lang.po; \ + done + +# Use this target to create or update .po files with new messages in +# driconf.py. +po: $(POS) + +pot: $(POT) + +# Extract message catalog from driconf.py. +$(POT): t_options.h + xgettext -L C --from-code utf-8 -o $(POT) t_options.h + +# Create or update a .po file for a specific language. +%.po: $(POT) + @if [ -f $@ ]; then \ + echo "Merging new strings from $(POT) into $@."; \ + mv $@ $@~; \ + msgmerge -o $@ $@~ $(POT); \ + else \ + echo "Initializing $@ from $(POT)."; \ + msginit -i $(POT) -o $@~ --locale=$*; \ + sed -e 's/charset=.*\\n/charset=UTF-8\\n/' $@~ > $@; \ + fi --- mesa-7.2.orig/src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py +++ mesa-7.2/src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py @@ -0,0 +1,191 @@ +#!/usr/bin/python + +import sys +import gettext +import re + +# List of supported languages +languages = sys.argv[1:] + +# Escape special characters in C strings +def escapeCString (s): + escapeSeqs = {'\a' : '\\a', '\b' : '\\b', '\f' : '\\f', '\n' : '\\n', + '\r' : '\\r', '\t' : '\\t', '\v' : '\\v', '\\' : '\\\\'} + # " -> '' is a hack. Quotes (") aren't possible in XML attributes. + # Better use Unicode characters for typographic quotes in option + # descriptions and translations. + i = 0 + r = '' + while i < len(s): + # Special case: escape double quote with \u201c or \u201d, depending + # on whether it's an open or close quote. This is needed because plain + # double quotes are not possible in XML attributes. + if s[i] == '"': + if i == len(s)-1 or s[i+1].isspace(): + # close quote + q = u'\u201c' + else: + # open quote + q = u'\u201d' + r = r + q + elif escapeSeqs.has_key(s[i]): + r = r + escapeSeqs[s[i]] + else: + r = r + s[i] + i = i + 1 + return r + +# Expand escape sequences in C strings (needed for gettext lookup) +def expandCString (s): + escapeSeqs = {'a' : '\a', 'b' : '\b', 'f' : '\f', 'n' : '\n', + 'r' : '\r', 't' : '\t', 'v' : '\v', + '"' : '"', '\\' : '\\'} + i = 0 + escape = False + hexa = False + octa = False + num = 0 + digits = 0 + r = '' + while i < len(s): + if not escape: + if s[i] == '\\': + escape = True + else: + r = r + s[i] + elif hexa: + if (s[i] >= '0' and s[i] <= '9') or \ + (s[i] >= 'a' and s[i] <= 'f') or \ + (s[i] >= 'A' and s[i] <= 'F'): + num = num * 16 + int(s[i],16) + digits = digits + 1 + else: + digits = 2 + if digits >= 2: + hexa = False + escape = False + r = r + chr(num) + elif octa: + if s[i] >= '0' and s[i] <= '7': + num = num * 8 + int(s[i],8) + digits = digits + 1 + else: + digits = 3 + if digits >= 3: + octa = False + escape = False + r = r + chr(num) + else: + if escapeSeqs.has_key(s[i]): + r = r + escapeSeqs[s[i]] + escape = False + elif s[i] >= '0' and s[i] <= '7': + octa = True + num = int(s[i],8) + if num <= 3: + digits = 1 + else: + digits = 2 + elif s[i] == 'x' or s[i] == 'X': + hexa = True + num = 0 + digits = 0 + else: + r = r + s[i] + escape = False + i = i + 1 + return r + +# Expand matches. The first match is always a DESC or DESC_BEGIN match. +# Subsequent matches are ENUM matches. +# +# DESC, DESC_BEGIN format: \1 \2= \3 \4=gettext(" \5= \6=") \7 +# ENUM format: \1 \2=gettext(" \3= \4=") \5 +def expandMatches (matches, translations, end=None): + assert len(matches) > 0 + nTranslations = len(translations) + i = 0 + # Expand the description+enums for all translations + for lang,trans in translations: + i = i + 1 + # Make sure that all but the last line of a simple description + # are extended with a backslash. + suffix = '' + if len(matches) == 1 and i < len(translations) and \ + not matches[0].expand (r'\7').endswith('\\'): + suffix = ' \\' + # Expand the description line. Need to use ugettext in order to allow + # non-ascii unicode chars in the original English descriptions. + text = escapeCString (trans.ugettext (unicode (expandCString ( + matches[0].expand (r'\5')), "utf-8"))).encode("utf-8") + print matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix + # Expand any subsequent enum lines + for match in matches[1:]: + text = escapeCString (trans.ugettext (unicode (expandCString ( + match.expand (r'\3')), "utf-8"))).encode("utf-8") + print match.expand (r'\1"' + text + r'"\5') + + # Expand description end + if end: + print end, + +# Compile a list of translation classes to all supported languages. +# The first translation is always a NullTranslations. +translations = [("en", gettext.NullTranslations())] +for lang in languages: + try: + trans = gettext.translation ("options", ".", [lang]) + except IOError: + sys.stderr.write ("Warning: language '%s' not found.\n" % lang) + continue + translations.append ((lang, trans)) + +# Regular expressions: +reLibintl_h = re.compile (r'#\s*include\s*') +reDESC = re.compile (r'(\s*DRI_CONF_DESC\s*\(\s*)([a-z]+)(\s*,\s*)(gettext\s*\(\s*")(.*)("\s*\))(\s*\)[ \t]*\\?)$') +reDESC_BEGIN = re.compile (r'(\s*DRI_CONF_DESC_BEGIN\s*\(\s*)([a-z]+)(\s*,\s*)(gettext\s*\(\s*")(.*)("\s*\))(\s*\)[ \t]*\\?)$') +reENUM = re.compile (r'(\s*DRI_CONF_ENUM\s*\([^,]+,\s*)(gettext\s*\(\s*")(.*)("\s*\))(\s*\)[ \t]*\\?)$') +reDESC_END = re.compile (r'\s*DRI_CONF_DESC_END') + +# Print a header +print \ +"/***********************************************************************\n" \ +" *** THIS FILE IS GENERATED AUTOMATICALLY. DON'T EDIT! ***\n" \ +" ***********************************************************************/" + +# Process the options template and generate options.h with all +# translations. +template = file ("t_options.h", "r") +descMatches = [] +for line in template: + if len(descMatches) > 0: + matchENUM = reENUM .match (line) + matchDESC_END = reDESC_END.match (line) + if matchENUM: + descMatches.append (matchENUM) + elif matchDESC_END: + expandMatches (descMatches, translations, line) + descMatches = [] + else: + sys.stderr.write ( + "Warning: unexpected line inside description dropped:\n%s\n" \ + % line) + continue + if reLibintl_h.search (line): + # Ignore (comment out) #include + print "/* %s * commented out by gen_xmlpool.py */" % line + continue + matchDESC = reDESC .match (line) + matchDESC_BEGIN = reDESC_BEGIN.match (line) + if matchDESC: + assert len(descMatches) == 0 + expandMatches ([matchDESC], translations) + elif matchDESC_BEGIN: + assert len(descMatches) == 0 + descMatches = [matchDESC_BEGIN] + else: + print line, + +if len(descMatches) > 0: + sys.stderr.write ("Warning: unterminated description at end of file.\n") + expandMatches (descMatches, translations) --- mesa-7.2.orig/src/mesa/drivers/dri/r300/Lindent +++ mesa-7.2/src/mesa/drivers/dri/r300/Lindent @@ -0,0 +1,2 @@ +#!/bin/sh +indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs "$@" --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DInit.cpp +++ mesa-7.2/src/mesa/drivers/d3d/D3DInit.cpp @@ -0,0 +1,891 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver Build 5 */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DHAL.h" +/*===========================================================================*/ +/* Local function prototypes. */ +/*===========================================================================*/ +static void DestroyAllSurfaces( PMESAD3DHAL pHAL ); +static void DestroyDevice( PMESAD3DHAL pHAL ); +static void DestroyInterfaces( PMESAD3DHAL pHAL ); + +HRESULT WINAPI EnumSurfacesHook( LPDIRECTDRAWSURFACE4 lpDDS, LPDDSURFACEDESC2 lpDDSDesc, LPVOID pVoid ); +HRESULT CALLBACK EnumZBufferHook( DDPIXELFORMAT* pddpf, VOID *pVoid ); +HRESULT CALLBACK EnumDeviceHook( GUID FAR* lpGuid, LPSTR lpDesc, LPSTR lpName, LPD3DDEVICEDESC lpD3DHWDesc, LPD3DDEVICEDESC lpD3DHELDesc, void *pVoid ); +/*===========================================================================*/ +/* Globals. */ +/*===========================================================================*/ +//char *errorMsg; +/*===========================================================================*/ +/* This function is responable for allocating the actual MESAD3DHAL struct. */ +/* Each Mesa context will have its own MESAD3DHAL struct so its like a mini */ +/* context to some extent. All one time allocations/operations get done here.*/ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +extern "C" PMESAD3DSHARED InitHAL( HWND hwnd ) +{ + PMESAD3DHAL pHAL; + ULONG rc; + + DPF(( DBG_FUNC, "InitHAL();" )); + DPF(( DBG_CNTX_INFO, "hwnd: %d", hwnd )); + + /* Allocate the structure and zero it out. */ + pHAL = (PMESAD3DHAL)ALLOC( sizeof(MESAD3DHAL) ); + if ( pHAL == NULL ) + { + RIP( pHAL, "InitHAL->", "Memory Allocation" ); + return (PMESAD3DSHARED)NULL; + } + memset( pHAL, 0, sizeof(MESAD3DHAL) ); + + /* Get the texture manager going. */ + rc = InitTMgrHAL( pHAL ); + if ( rc == FALSE ) + { + RIP( pHAL, "InitTMgrHAL->", "Failed" ); + return (PMESAD3DSHARED)NULL; + } + + /* Fill in the window parameters if we can. */ + pHAL->shared.hwnd = hwnd; + + /* Parse the user's enviroment variables to generate a debug mask. */ + ReadDBGEnv(); + + return (PMESAD3DSHARED)pHAL; +} +/*===========================================================================*/ +/* This function will unload all the resources that the MESAD3DHAL struct */ +/* has bound to it. The actual structure itself will be freed. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void TermHAL( PMESAD3DSHARED pShared ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + + DPF(( DBG_FUNC, "TermHAL();" )); + + /* Check for an empty wrapper structure. */ + if ( pHAL == NULL ) + return; + + /* Kill this texture manager. */ + TermTMgrHAL( pHAL ); + + /* Kill any DDraw stuff if exists. */ + DestroyDevice( pHAL ); + DestroyAllSurfaces( pHAL ); + DestroyInterfaces( pHAL ); + + FREE( pHAL ); +} +/*===========================================================================*/ +/* This function is used to init and resize the rendering surface as the two*/ +/* are almost the same. First the device and all the surfaces are destoryed */ +/* if they already exist. Next we create a OffScreen rendering surface and */ +/* save some pixelformat info to do color convertions. Next we start to take */ +/* care of getting the most out of the hardware. I use bHardware to determine*/ +/* the state of the device we found in the device enumeration. The enum proc*/ +/* will try for hardware first. I next use a bForceSW to make the enum proc */ +/* choose a software device. So I will try some combinations with HW first */ +/* until I feel I have to set the bForceSW and call this function again. If */ +/* this function is called with no width or height then use the internals. */ +/* NOTE: The worst case is that all will be in SW (RGBDevice) and really */ +/* I should forget the whole thing and fall back to a DDraw span type*/ +/* rendering but what is the point. This way I always know I have a */ +/* D3DDevice and that makes things easier. I do impliment the span */ +/* rendering function for stuff that I haven't done support for such */ +/* as points and lines. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE */ +/*===========================================================================*/ +extern "C" BOOL CreateHAL( PMESAD3DSHARED pShared ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + DDSURFACEDESC2 ddsd2; + D3DDEVICEDESC D3DSWDevDesc; + DDSCAPS2 ddscaps; + DWORD dwCoopFlags, + dwWidth, + dwHeight; + ULONG rc; + + DPF(( DBG_FUNC, "CreateHAL();" )); + +#define InitDDSD2(f) memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); \ + ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); \ + ddsd2.dwFlags = f; + + if ( pHAL == NULL ) + return FALSE; + + /* Use the internal rectangle struct. */ + dwWidth = pShared->rectW.right - pShared->rectW.left; + dwHeight = pShared->rectW.bottom - pShared->rectW.top; + + DPF(( DBG_CNTX_INFO, "Width: %d Height: %d", dwWidth, dwHeight )); + + /* The dimensions might still be the same so just leave. */ + if ( (dwWidth == pShared->dwWidth) && (dwHeight == pShared->dwHeight) ) + { + DPF(( DBG_CNTX_WARN, "Context size hasn't changed" )); + return TRUE; + } + + /* If one of the dimensions are zero then leave. WM_SIZE should get us back here. */ + if ( (dwWidth == 0) || (dwHeight == 0) ) + return TRUE; + + /* Save the renders dimensions. */ + pShared->dwWidth = dwWidth; + pShared->dwHeight = dwHeight; + + DPF(( DBG_CNTX_INFO, "Creating Context:\n cx:%d cy:%d", pShared->dwWidth, pShared->dwHeight )); + + /*=================================*/ + /* Create all required interfaces. */ + /*=================================*/ + + /* Kill any DDraw stuff if exists. */ + DestroyDevice( pHAL ); + DestroyAllSurfaces( pHAL ); + DestroyInterfaces( pHAL ); + + /* Create a instance of DDraw using the Primary display driver. */ + rc = DirectDrawCreate( NULL, &pHAL->lpDD, NULL ); + if( FAILED(rc) ) + { + RIP( pHAL, "DirectDrawCreate->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Get the DDraw4 interface. */ + rc = pHAL->lpDD->QueryInterface( IID_IDirectDraw4, (void **)&pHAL->lpDD4 ); + if( FAILED(rc) ) + { + RIP( pHAL, "QueryInterface (IID_IDirectDraw4) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Get the Direct3D3 interface. */ + rc = pHAL->lpDD4->QueryInterface( IID_IDirect3D3, (void **)&pHAL->lpD3D3 ); + if( FAILED(rc) ) + { + RIP( pHAL, "QueryInterface (IID_IDirect3D3) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Set the Cooperative level. NOTE: we need to know if we are FS at this point.*/ + dwCoopFlags = (pShared->bWindow == TRUE) ? DDSCL_NORMAL : (DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); + rc = pHAL->lpDD4->SetCooperativeLevel( pShared->hwnd, dwCoopFlags ); + if ( FAILED(rc) ) + { + RIP( pHAL, "SetCooperativeLevel->", ErrorStringD3D(rc) ); + return FALSE; + } + + /*==================================================================*/ + /* Get the best device we can and note whether its hardware or not. */ + /*==================================================================*/ + pShared->bForceSW = FALSE; + pHAL->lpD3D3->EnumDevices( EnumDeviceHook, (void *)pHAL ); + pShared->bHardware = IsEqualIID( pHAL->guid, IID_IDirect3DHALDevice ); + DPF(( DBG_CNTX_INFO, "bHardware: %s", (pShared->bHardware) ? "TRUE" : "FALSE" )); + DPF(( DBG_CNTX_INFO, "bWindowed: %s", (pShared->bWindow) ? "TRUE" : "FALSE" )); + + /*========================================================================*/ + /* HARDWARE was found. */ + /*========================================================================*/ + if ( pShared->bHardware == TRUE ) + { + /*===================================*/ + /* HARDWARE -> Z-BUFFER. */ + /*===================================*/ + + /* Get a Z-Buffer pixelformat. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); + rc = pHAL->lpD3D3->EnumZBufferFormats( pHAL->guid, EnumZBufferHook, (VOID*)&ddsd2.ddpfPixelFormat ); + if ( FAILED(rc) ) + { + RIP( pHAL, "EnumZBufferFormatsl->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Setup our request structure for the Z-buffer surface. */ + ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; + ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY; + ddsd2.dwWidth = dwWidth; + ddsd2.dwHeight = dwHeight; + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSZbuffer, NULL ); + if ( !FAILED(rc) ) + { + DPF(( DBG_CNTX_INFO, "HW ZBuffer" )); + + /*===================================*/ + /* HARDWARE -> Z-BUFFER -> FLIPABLE */ + /*===================================*/ + if ( pShared->bWindow == FALSE ) + { + InitDDSD2( DDSD_CAPS | DDSD_BACKBUFFERCOUNT ); + ddsd2.dwBackBufferCount = 1; + ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); + if ( FAILED(rc) ) + { + /* Make sure we try the next fall back. */ + DPF(( DBG_CNTX_WARN, "HW Flip/Complex not available" )); + pHAL->lpDDSPrimary = NULL; + } + else + { + /* Get the back buffer that was created. */ + ddscaps.dwCaps = DDSCAPS_BACKBUFFER; + rc = pHAL->lpDDSPrimary->GetAttachedSurface( &ddscaps, &pHAL->lpDDSRender ); + if ( FAILED(rc) ) + { + DPF(( DBG_CNTX_WARN, "GetAttachedSurface failed -> HW Flip/Complex" )); + + /* Make sure we try the next fall back. */ + pHAL->lpDDSPrimary->Release(); + pHAL->lpDDSPrimary = NULL; + } + else + { + /* I have had problems when a complex surface comes back */ + /* with the back buffer being created in SW. Not sure why */ + /* or how this is possable but I'm checking for it here. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); + DX_RESTORE( pHAL->lpDDSRender ); + rc = pHAL->lpDDSRender->GetSurfaceDesc( &ddsd2 ); + if ( FAILED(rc) ) + { + RIP( pHAL, "GetSurfaceDesc (RENDER) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* If the surface is in VID then we are happy with are Flipable. */ + if ( ddsd2.ddsCaps.dwCaps & DDSCAPS_LOCALVIDMEM ) + { + pShared->bFlipable = TRUE; + DPF(( DBG_CNTX_INFO, "HW Flip/Complex!" )); + } + else + { + /* Kill this setup. */ + pHAL->lpDDSPrimary->Release(); + pHAL->lpDDSPrimary = NULL; + } + } + } + } + + /*===================================*/ + /* HARDWARE -> Z-BUFFER -> BLT */ + /*===================================*/ + if ( pHAL->lpDDSPrimary == NULL ) + { + pShared->bFlipable = FALSE; + + /* Create the Primary (front buffer). */ + InitDDSD2( DDSD_CAPS ); + ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); + if ( FAILED(rc) ) + { + /* This is an error as we should be able to do this at minimum. */ + RIP( pHAL, "CreateSurface (PRIMARY) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Create the Render (back buffer). */ + InitDDSD2( DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ); + ddsd2.dwWidth = dwWidth; + ddsd2.dwHeight = dwHeight; + ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSRender, NULL ); + if ( FAILED(rc) ) + { + DPF(( DBG_CNTX_WARN, "Failed HW Offscreen surface" )); + + /* Make sure we try the next fall back. */ + pHAL->lpDDSPrimary->Release(); + pHAL->lpDDSPrimary = NULL; + } + else + { + /* Might as well check here too see if this surface is in */ + /* hardware. If nothing else just to be consistant. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); + DX_RESTORE( pHAL->lpDDSRender ); + rc = pHAL->lpDDSRender->GetSurfaceDesc( &ddsd2 ); + if ( FAILED(rc) ) + { + RIP( pHAL, "GetSurfaceDesc (RENDER) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* If the surface is in VID then we are happy. */ + if ( ddsd2.ddsCaps.dwCaps & DDSCAPS_LOCALVIDMEM ) + { + /* Create a clipper object so that DDraw will be able to blt windows that */ + /* have been clipped by the screen or other windows. */ + pHAL->lpDD4->CreateClipper( 0, &pHAL->lpClipper, NULL ); + pHAL->lpClipper->SetHWnd( 0, pShared->hwnd ); + pHAL->lpDDSPrimary->SetClipper( pHAL->lpClipper ); + pHAL->lpClipper->Release(); + DPF(( DBG_CNTX_INFO, "HW RENDER surface" )); + } + else + { + /* Kill this setup. */ + pHAL->lpDDSRender->Release(); + pHAL->lpDDSRender = NULL; + pHAL->lpDDSPrimary->Release(); + pHAL->lpDDSPrimary = NULL; + } + } + } + + /*===================================*/ + /* Create D3DDEVICE -> HARDWARE. */ + /*===================================*/ + if ( pHAL->lpDDSZbuffer && pHAL->lpDDSPrimary && pHAL->lpDDSRender ) + { + DX_RESTORE( pHAL->lpDDSRender ); + DX_RESTORE( pHAL->lpDDSZbuffer ); + + rc = pHAL->lpDDSRender->AddAttachedSurface( pHAL->lpDDSZbuffer ); + if ( FAILED(rc) ) + { + RIP( pHAL, "AddAttachedSurface (ZBUFFER) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + rc = pHAL->lpD3D3->CreateDevice( IID_IDirect3DHALDevice, pHAL->lpDDSRender, &pHAL->lpD3DDevice, NULL ); + if ( rc != D3D_OK ) + { + DPF(( DBG_CNTX_WARN, "Failed HW Device" )); + pHAL->lpD3DDevice = NULL; + } + else + { + DPF(( DBG_CNTX_INFO, "HW Device" )); + } + } + } + } + + /*========================================================================*/ + /* SOFTWARE fallback. */ + /*========================================================================*/ + if ( pHAL->lpD3DDevice == NULL ) + { + DPF(( DBG_CNTX_INFO, "SW fallback :(" )); + + /* Make sure we have no surfaces allocated. Just incase. */ + DestroyAllSurfaces( pHAL ); + + /* Get a software device. */ + pShared->bFlipable = FALSE; + pShared->bForceSW = TRUE; + pHAL->lpD3D3->EnumDevices( EnumDeviceHook, (void *)pHAL ); + pShared->bHardware = IsEqualIID( pHAL->guid, IID_IDirect3DHALDevice ); + + /*===================================*/ + /* SOFTWARE -> Z-BUFFER. */ + /*===================================*/ + + /*===================================*/ + /* SOFTWARE -> Z-BUFFER -> FLIPABLE */ + /*===================================*/ + if ( pShared->bWindow == FALSE ) + { + InitDDSD2( DDSD_CAPS | DDSD_BACKBUFFERCOUNT ); + ddsd2.dwBackBufferCount = 1; + ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; + ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); + ddsd2.ddpfPixelFormat.dwFlags = (DDPF_RGB | DDPF_ALPHAPIXELS); + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); + if ( FAILED(rc) ) + { + DPF(( DBG_CNTX_WARN, "Failed SW Flip/Complex" )); + + /* Make sure we try the next fall back. */ + pHAL->lpDDSPrimary = NULL; + } + else + { + ddscaps.dwCaps = DDSCAPS_BACKBUFFER; + rc = pHAL->lpDDSPrimary->GetAttachedSurface( &ddscaps, &pHAL->lpDDSRender ); + if ( FAILED(rc) ) + { + /* Make sure we try the next fall back. */ + DPF(( DBG_CNTX_WARN, "GetAttachedSurface failed -> SW Flip/Complex" )); + pHAL->lpDDSPrimary->Release(); + pHAL->lpDDSPrimary = NULL; + } + else + { + DPF(( DBG_CNTX_INFO, "SW Flip/Complex" )); + pShared->bFlipable = TRUE; + } + } + } + + /*===================================*/ + /* SOFTWARE -> Z-BUFFER -> BLT */ + /*===================================*/ + if ( pHAL->lpDDSPrimary == NULL ) + { + /* Create the Primary (front buffer). */ + InitDDSD2( DDSD_CAPS ); + ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSPrimary, NULL ); + if ( FAILED(rc) ) + { + /* This is an error as we should be able to do this at minimum. */ + RIP( pHAL, "CreateSurface (PRIMARY) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Create the Render (back buffer). */ + InitDDSD2( DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ); + ddsd2.dwWidth = dwWidth; + ddsd2.dwHeight = dwHeight; + ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; + ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); + ddsd2.ddpfPixelFormat.dwFlags = (DDPF_RGB | DDPF_ALPHAPIXELS); + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pHAL->lpDDSRender, NULL ); + if ( FAILED(rc) ) + { + /* That was our last hope. */ + RIP( pHAL, "CreateSurface (RENDER) ->", ErrorStringD3D(rc) ); + return FALSE; + } + else + { + DPF(( DBG_CNTX_INFO, "SW RENDER surface" )); + + /* Create a clipper object so that DDraw will be able to blt windows that */ + /* have been clipped by the screen or other windows. */ + pHAL->lpDD4->CreateClipper( 0, &pHAL->lpClipper, NULL ); + pHAL->lpClipper->SetHWnd( 0, pShared->hwnd ); + pHAL->lpDDSPrimary->SetClipper( pHAL->lpClipper ); + pHAL->lpClipper->Release(); + } + } + + /*===================================*/ + /* Create D3DDEVICE -> SOFTWARE. */ + /*===================================*/ + if ( pHAL->lpDDSPrimary && pHAL->lpDDSRender ) + { + DX_RESTORE( pHAL->lpDDSRender ); + rc = pHAL->lpD3D3->CreateDevice( IID_IDirect3DRGBDevice, pHAL->lpDDSRender, &pHAL->lpD3DDevice, NULL ); + if ( rc != D3D_OK ) + { + /* That was our last hope. */ + RIP( pHAL, "CreateDevice (IID_IDirect3DRGBDevice) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + DPF(( DBG_CNTX_INFO, "SW Device" )); + } + } + + /*==============================================================================*/ + /* Get a copy of the render pixelformat so that wgl.c can call GetPixelInfoD3D. */ + /*==============================================================================*/ + memset( &pHAL->ddpf, 0, sizeof(DDPIXELFORMAT) ); + pHAL->ddpf.dwSize = sizeof( DDPIXELFORMAT ); + rc = pHAL->lpDDSRender->GetPixelFormat( &pHAL->ddpf ); + if ( FAILED(rc) ) + { + RIP( pHAL, "GetPixelFormat ->", ErrorStringD3D(rc) ); + return FALSE; + } + DebugPixelFormat( "Using OFFSCREEN", &pHAL->ddpf ); + DebugPixelFormat( "Using ZBUFFER", &ddsd2.ddpfPixelFormat ); + + /* Get a copy of what the D3DDevice supports for later use. */ + memset( &D3DSWDevDesc, 0, sizeof(D3DDEVICEDESC) ); + memset( &pHAL->D3DHWDevDesc, 0, sizeof(D3DDEVICEDESC) ); + D3DSWDevDesc.dwSize = sizeof( D3DDEVICEDESC ); + pHAL->D3DHWDevDesc.dwSize = sizeof( D3DDEVICEDESC ); + rc = pHAL->lpD3DDevice->GetCaps( &pHAL->D3DHWDevDesc, &D3DSWDevDesc ); + if ( FAILED(rc) ) + { + RIP( pHAL, "GetCaps ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Get a copy of the pixel convertion stuff for direct buffer access. */ + Solve8BitChannelPixelFormat( &pHAL->ddpf, &pShared->pixel ); + AlphaBlendTableHAL( pHAL ); + + /* We must prime the Begin/End scene for SwapBuffers to work. */ + rc = pHAL->lpD3DDevice->BeginScene(); + if ( FAILED(rc) ) + { + RIP( pHAL, "BeginScene ->", ErrorStringD3D(rc) ); + return FALSE; + } + +#undef InitDDSD2 + + return TRUE; +} +/*===========================================================================*/ +/* This function will make sure a viewport is created and set for the device*/ +/* in the supplied structure. If a rect is supplied then it will be used for*/ +/* the viewport otherwise the current setting in the strucute will be used. */ +/* Note that the rect is relative to the window. So left/top must be 0,0 to */ +/* use the whole window else there is scissoring going down. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +extern "C" BOOL SetViewportHAL( PMESAD3DSHARED pShared, RECT *pRect, float minZ, float maxZ ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + D3DVIEWPORT2 vdData; + ULONG rc; + POINT pt; + + DPF(( DBG_FUNC, "SetViewportHAL();" )); + + /* Make sure we have enough info. */ + if ( !pHAL || !pHAL->lpDDSPrimary || !pHAL->lpD3DDevice ) + { + DPF(( DBG_CNTX_WARN, "SetViewport() -> NULL Pointer" )); + return FALSE; + } + + /* TODO: this is just a temp fix to stop redundant changes. */ + if ( pRect && + (pShared->rectV.left == pRect->left) && + (pShared->rectV.right == pRect->right) && + (pShared->rectV.top == pRect->top) && + (pShared->rectV.bottom == pRect->bottom) ) + { + DPF(( DBG_CNTX_WARN, "Redundant viewport" )); + return TRUE; + } + + DPF(( DBG_CNTX_INFO, "Current Viewport:" )); + DPF(( DBG_CNTX_INFO, "x: %d y: %d", pShared->rectV.left, pShared->rectV.top )); + DPF(( DBG_CNTX_INFO, "cx: %d cy: %d", (pShared->rectV.right-pShared->rectV.left), (pShared->rectV.bottom-pShared->rectV.top) )); + DPF(( DBG_CNTX_INFO, "New Viewport:" )); + DPF(( DBG_CNTX_INFO, "x: %d y: %d", pRect->left, pRect->top )); + DPF(( DBG_CNTX_INFO, "cx: %d cy: %d", (pRect->right-pRect->left), (pRect->bottom-pRect->top) )); + + /* Update the current viewport rect if one is supplied. */ + if ( pRect ) + memcpy( &pShared->rectV, pRect, sizeof(RECT) ); + + /* Build the request structure. */ + memset( &vdData, 0, sizeof(D3DVIEWPORT2) ); + vdData.dwSize = sizeof(D3DVIEWPORT2); + vdData.dwX = pShared->rectV.left; + vdData.dwY = pShared->rectV.top; + vdData.dwWidth = (pShared->rectV.right - pShared->rectV.left); + vdData.dwHeight = (pShared->rectV.bottom - pShared->rectV.top); + + if ( !vdData.dwWidth || !vdData.dwHeight ) + { + GetClientRect( pShared->hwnd, &pShared->rectW ); + pt.x = pt.y = 0; + ClientToScreen( pShared->hwnd, &pt ); + OffsetRect( &pShared->rectW, pt.x, pt.y); + vdData.dwX = pShared->rectW.left; + vdData.dwY = pShared->rectW.top; + vdData.dwWidth = (pShared->rectW.right - pShared->rectW.left); + vdData.dwHeight = (pShared->rectW.bottom - pShared->rectW.top); + memcpy( &pShared->rectV, &pShared->rectW, sizeof(RECT) ); + } + + // The dvClipX, dvClipY, dvClipWidth, dvClipHeight, dvMinZ, + // and dvMaxZ members define the non-normalized post-perspective + // 3-D view volume which is visible to the viewer. In most cases, + // dvClipX is set to -1.0 and dvClipY is set to the inverse of + // the viewport's aspect ratio on the target surface, which can be + // calculated by dividing the dwHeight member by dwWidth. Similarly, + // the dvClipWidth member is typically 2.0 and dvClipHeight is set + // to twice the aspect ratio set in dwClipY. The dvMinZ and dvMaxZ + // are usually set to 0.0 and 1.0. + vdData.dvClipX = -1.0f; + vdData.dvClipWidth = 2.0f; + vdData.dvClipY = 1.0f; + vdData.dvClipHeight = 2.0f; + vdData.dvMaxZ = maxZ; + vdData.dvMinZ = minZ; + + DPF(( DBG_CNTX_INFO, "zMin: %f zMax: %f", minZ, maxZ )); + + /* I'm going to destroy the viewport everytime as when we size we will */ + /* have a new D3DDevice. As this area doesn't need to be fast... */ + if ( pHAL->lpViewport ) + { + DPF(( DBG_CNTX_INFO, "DeleteViewport" )); + + pHAL->lpD3DDevice->DeleteViewport( pHAL->lpViewport ); + rc = pHAL->lpViewport->Release(); + pHAL->lpViewport = NULL; + } + + rc = pHAL->lpD3D3->CreateViewport( &pHAL->lpViewport, NULL ); + if ( rc != D3D_OK ) + { + DPF(( DBG_CNTX_ERROR, "CreateViewport Failed" )); + return FALSE; + } + + /* Update the device with the new viewport. */ + pHAL->lpD3DDevice->AddViewport( pHAL->lpViewport ); + pHAL->lpViewport->SetViewport2( &vdData ); + pHAL->lpD3DDevice->SetCurrentViewport( pHAL->lpViewport ); + + return TRUE; +} +/*===========================================================================*/ +/* */ +/* */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +HRESULT WINAPI EnumSurfacesHook( LPDIRECTDRAWSURFACE4 lpDDS, LPDDSURFACEDESC2 lpDDSDesc, LPVOID pVoid ) +{ + DDSURFACEDESC2 *pddsd2 = (DDSURFACEDESC2 *)pVoid; + + DPF(( DBG_FUNC, "EnumSurfacesHook();" )); + + if ( (lpDDSDesc->ddpfPixelFormat.dwFlags == pddsd2->ddpfPixelFormat.dwFlags) && (lpDDSDesc->ddsCaps.dwCaps == pddsd2->ddsCaps.dwCaps) ) + { + /* Save the pixelformat now so that we know we have one. */ + memcpy( pddsd2, lpDDSDesc, sizeof(DDSURFACEDESC2) ); + + return D3DENUMRET_CANCEL; + } + + return D3DENUMRET_OK; +} +/*===========================================================================*/ +/* This is the callback proc to get a Z-Buffer. Thats it. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +HRESULT CALLBACK EnumZBufferHook( DDPIXELFORMAT* pddpf, VOID *pVoid ) +{ + DDPIXELFORMAT *pddpfChoice = (DDPIXELFORMAT *)pVoid; + + DPF(( DBG_FUNC, "EnumZBufferHook();" )); + + /* If this is ANY type of depth-buffer, stop. */ + if( pddpf->dwFlags == DDPF_ZBUFFER ) + { + /* Save the pixelformat now so that we know we have one. */ + memcpy( pddpfChoice, pddpf, sizeof(DDPIXELFORMAT) ); + + /* I feel if the hardware supports this low then lets use it. Could get ugly. */ + if( pddpf->dwZBufferBitDepth >= 8 ) + { + return D3DENUMRET_CANCEL; + } + } + + return D3DENUMRET_OK; +} +/*===========================================================================*/ +/* This function handles the callback for the D3DDevice enumeration. Good */ +/* god who's idea was this? The D3D wrapper has two variable related to what*/ +/* kind of device we want and have. First we have a Bool that is set if we */ +/* have allocated a HW device. We always look for the HW device first. The */ +/* other variable is used to force SW. If we have run into a case that we */ +/* want to fallback to SW then we set this. We will fallback if we cannot */ +/* texture in video memory (among others). */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +HRESULT CALLBACK EnumDeviceHook( GUID FAR* lpGuid, LPSTR lpDesc, LPSTR lpName, LPD3DDEVICEDESC lpD3DHWDesc, LPD3DDEVICEDESC lpD3DHELDesc, void *pVoid ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pVoid; + LPD3DDEVICEDESC pChoice = lpD3DHWDesc; + + DPF(( DBG_FUNC, "EnumDeviceHook();" )); + + /* Determine if which device description is valid. */ + if ( pChoice->dcmColorModel == 0 ) + pChoice = lpD3DHELDesc; + + /* Make sure we always have a GUID. */ + memcpy( &pHAL->guid, lpGuid, sizeof(GUID) ); + + /* This controls whether we will except HW or not. */ + if ( pHAL->shared.bForceSW == TRUE ) + { + return (pChoice == lpD3DHELDesc) ? D3DENUMRET_CANCEL : D3DENUMRET_OK; + } + + /* Always try for hardware. */ + if ( pChoice == lpD3DHWDesc ) + { + return D3DENUMRET_CANCEL; + } + + return D3DENUMRET_OK; +} +/*===========================================================================*/ +/* This function will destroy any and all surfaces that this context has */ +/* allocated. If there is a clipper object then it will also be destoryed as*/ +/* it is part of the Primary Surface. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void DestroyAllSurfaces( PMESAD3DHAL pHAL ) +{ + LONG refCount; + + DPF(( DBG_FUNC, "DestroyAllSurfaces();" )); + + DX_RESTORE( pHAL->lpDDSPrimary ); + DX_RESTORE( pHAL->lpDDSRender ); + DX_RESTORE( pHAL->lpDDSZbuffer); + + if ( pHAL->lpDDSRender ) + { + pHAL->lpDDSRender->Unlock( NULL ); + + /* If this isn't a Flipable surface then we must clean up the render. */ + if ( pHAL->shared.bFlipable == FALSE) + { + if ( pHAL->lpDDSZbuffer ) + { + DPF(( DBG_CNTX_INFO, "Remove attached surfaces from RENDER" )); + pHAL->lpDDSRender->DeleteAttachedSurface( 0, NULL ); + } + + DPF(( DBG_CNTX_INFO, "Release RENDER" )); + refCount = pHAL->lpDDSRender->Release(); + pHAL->lpDDSRender = NULL; + } + } + + if ( pHAL->lpDDSZbuffer ) + { + DPF(( DBG_CNTX_INFO, "Release ZBuffer" )); + pHAL->lpDDSZbuffer->Unlock( NULL ); + refCount = pHAL->lpDDSZbuffer->Release(); + pHAL->lpDDSZbuffer = NULL; + } + + if ( pHAL->lpClipper ) + { + DPF(( DBG_CNTX_INFO, "Release Clipper" )); + refCount = pHAL->lpClipper->Release(); + pHAL->lpClipper = NULL; + } + + if ( pHAL->lpDDSPrimary ) + { + pHAL->lpDDSPrimary->Unlock( NULL ); + + DPF(( DBG_CNTX_INFO, "Release PRIMARY" )); + refCount = pHAL->lpDDSPrimary->Release(); + pHAL->lpDDSPrimary = NULL; + } +} +/*===========================================================================*/ +/* This function will destroy the current D3DDevice and any resources that */ +/* belong to it. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void DestroyDevice( PMESAD3DHAL pHAL ) +{ + LONG refCount; + + DPF(( DBG_FUNC, "DestroyDevice();" )); + + /* Kill the D3D stuff if exists. */ + if ( pHAL->lpViewport ) + { + DPF(( DBG_CNTX_INFO, "Delete Viewport" )); + pHAL->lpD3DDevice->DeleteViewport( pHAL->lpViewport ); + + DPF(( DBG_CNTX_INFO, "Release Viewport" )); + refCount = pHAL->lpViewport->Release(); + pHAL->lpViewport = NULL; + } + + if ( pHAL->lpD3DDevice != NULL ) + { + DPF(( DBG_CNTX_INFO, "Release D3DDevice" )); + refCount = pHAL->lpD3DDevice->EndScene(); + refCount = pHAL->lpD3DDevice->Release(); + pHAL->lpD3DDevice = NULL; + } +} +/*===========================================================================*/ +/* This function will destroy the current D3DDevice and any resources that */ +/* belong to it. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void DestroyInterfaces( PMESAD3DHAL pHAL ) +{ + LONG refCount; + + DPF(( DBG_FUNC, "DestroyInterfaces();" )); + + if ( pHAL->lpD3D3 != NULL ) + { + DPF(( DBG_CNTX_INFO, "Release Direct3D3" )); + refCount = pHAL->lpD3D3->Release(); + pHAL->lpD3D3 = NULL; + } + + if ( pHAL->lpDD4 != NULL ) + { + DPF(( DBG_CNTX_INFO, "Release DDraw4" )); + refCount = pHAL->lpDD4->Release(); + pHAL->lpDD4 = NULL; + } + + if ( pHAL->lpDD != NULL ) + { + DPF(( DBG_CNTX_INFO, "Release DDraw" )); + refCount = pHAL->lpDD->Release(); + pHAL->lpDD = NULL; + } +} +/*===========================================================================*/ +/* This function will first send (not post) a message to the client window */ +/* that this context is using. The client will respond by unbinding itself */ +/* and binding the 'default' context. This allows the API to be supported */ +/* until the window can be destroyed. Finally we post the quit message to */ +/* the client in hopes to end the application. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void FatalShutDown( PMESAD3DHAL pHAL ) +{ + /* Whip this baby in too try and support the API until we die... */ + if ( pHAL ) + SendMessage( pHAL->shared.hwnd, UM_FATALSHUTDOWN, 0L, 0L ); + + /* Close the client application down. */ + PostQuitMessage( 0 ); +} + --- mesa-7.2.orig/src/mesa/drivers/d3d/DbgEnv.bat +++ mesa-7.2/src/mesa/drivers/d3d/DbgEnv.bat @@ -0,0 +1,25 @@ +SET DBG_FUNC=FALSE + +SET DBG_CNTX_INFO=TRUE +SET DBG_CNTX_WARN=TRUE +SET DBG_CNTX_PROFILE=FALSE +SET DBG_CNTX_ERROR=TRUE +SET DBG_CNTX_ALL=TRUE + +SET DBG_PRIM_INFO=FALSE +SET DBG_PRIM_WARN=FALSE +SET DBG_PRIM_PROFILE=FALSE +SET DBG_PRIM_ERROR=TRUE +SET DBG_PRIM_ALL=FALSE + +SET DBG_TXT_INFO=FALSE +SET DBG_TXT_WARN=TRUE +SET DBG_TXT_PROFILE=FALSE +SET DBG_TXT_ERROR=TRUE +SET DBG_TXT_ALL=FALSE + +SET DBG_ALL_INFO=FALSE +SET DBG_ALL_WARN=TRUE +SET DBG_ALL_PROFILE=FALSE +SET DBG_ALL_ERROR=TRUE +SET DBG_ALL=FALSE --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DHAL.H +++ mesa-7.2/src/mesa/drivers/d3d/D3DHAL.H @@ -0,0 +1,68 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef _D3D_HAL_INC +#define _D3D_HAL_INC + +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include +#include +#include +#include +#include +#include "D3DShared.h" +#include "D3DTextureMgr.h" +#include "Debug.h" +/*===========================================================================*/ +/* Defines. */ +/*===========================================================================*/ +#define DX_RESTORE(ps) if ( (ps) && (ps)->IsLost() ) (ps)->Restore(); +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +typedef struct _d3d_hal_struct +{ + MESAD3DSHARED shared; + + GUID guid; + LPDIRECTDRAW lpDD; + LPDIRECTDRAW4 lpDD4; + LPDIRECT3D3 lpD3D3; + LPDIRECT3DDEVICE3 lpD3DDevice; + D3DDEVICEDESC D3DHWDevDesc; + LPDIRECTDRAWSURFACE4 lpDDSPrimary, + lpDDSRender, + lpDDSZbuffer; + LPDIRECT3DVIEWPORT3 lpViewport; + LPDIRECTDRAWCLIPPER lpClipper; + DDPIXELFORMAT ddpf, + ddpfZBuffer; + PTM_OBJECT pTMList; + +} MESAD3DHAL, *PMESAD3DHAL; +/*===========================================================================*/ +/* External function prototypes. */ +/*===========================================================================*/ +extern BOOL InitTMgrHAL( PMESAD3DHAL pHAL ); +extern void TermTMgrHAL( PMESAD3DHAL pHAL ); +extern void AlphaBlendTableHAL( PMESAD3DHAL pHAL ); + +extern void Solve8BitChannelPixelFormat( DDPIXELFORMAT *pddpf, PPIXELINFO pPixel ); +extern char *ErrorStringD3D( HRESULT hr ); +extern void FatalShutDown( PMESAD3DHAL pHAL ); +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ +extern char *errorMsg; + +#endif + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DTEXT.CPP +++ mesa-7.2/src/mesa/drivers/d3d/D3DTEXT.CPP @@ -0,0 +1,576 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "d3dText.h" + +/*============================================================================= + + 1 + ------ + | | + 6 | | 2 + | 7 | + ------ + | | + 5 | | 3 + | | + ------ + 4 + + TL_0 TR_0 +TLL TL_1 TR_1 TRR + +MLL_0 ML_0 MR_0 MRR_0 +MLL_1 ML_1 MR_1 MRR_1 + +BLL BL_0 BR_0 BRR + BL_1 BR_1 + +=============================================================================*/ + +#define TLL 0 +#define TRR 1 +#define TL_0 2 +#define TL_1 3 +#define TR_0 4 +#define TR_1 5 + +#define MLL_0 6 +#define MLL_1 7 +#define MRR_0 8 +#define MRR_1 9 + +#define ML_0 10 +#define ML_1 11 +#define MR_0 12 +#define MR_1 13 + +#define BL_0 14 +#define BL_1 15 +#define BR_0 16 +#define BR_1 17 +#define BLL 18 +#define BRR 19 + +#define BIT1 0x00000001 +#define BIT2 0x00000002 +#define BIT3 0x00000004 +#define BIT4 0x00000008 +#define BIT5 0x00000010 +#define BIT6 0x00000020 +#define BIT7 0x00000040 + +#define TOP BIT4 +#define MIDDLE BIT7 +#define BOTTOM BIT1 +#define TLEFT BIT5 +#define BLEFT BIT6 +#define LEFT (TLEFT|BLEFT) +#define TRIGHT BIT3 +#define BRIGHT BIT2 +#define RIGHT (TRIGHT|BRIGHT) +#define ALL 0xFFFFFFFF + +/*===========================================================================*/ +/* This is the static array that will map the ASCII value of the character */ +/* being draw to the bit mask that will be scan converted to the LED display.*/ +/*===========================================================================*/ +DWORD textBitMasks[] = +{ + 0xFFFFFFFF, // 000 + 0xFFFFFFFF, // 001 + 0xFFFFFFFF, // 002 + 0xFFFFFFFF, // 003 + 0xFFFFFFFF, // 004 + 0xFFFFFFFF, // 005 + 0xFFFFFFFF, // 006 + 0xFFFFFFFF, // 007 + 0xFFFFFFFF, // 008 + 0xFFFFFFFF, // 009 + 0xFFFFFFFF, // 010 + 0xFFFFFFFF, // 011 + 0xFFFFFFFF, // 012 + 0xFFFFFFFF, // 013 + 0xFFFFFFFF, // 014 + 0xFFFFFFFF, // 015 + 0xFFFFFFFF, // 016 + 0xFFFFFFFF, // 017 + 0xFFFFFFFF, // 018 + 0xFFFFFFFF, // 019 + 0xFFFFFFFF, // 020 + 0xFFFFFFFF, // 021 + 0xFFFFFFFF, // 022 + 0xFFFFFFFF, // 023 + 0xFFFFFFFF, // 024 + 0xFFFFFFFF, // 025 + 0xFFFFFFFF, // 026 + 0xFFFFFFFF, // 027 + 0xFFFFFFFF, // 028 + 0xFFFFFFFF, // 029 + 0xFFFFFFFF, // 030 + 0XFFFFFFFF, // 031 + 0x00000000, // 032 'SPC' + 0xFFFFFFFF, // 033 + 0xFFFFFFFF, // 034 + 0xFFFFFFFF, // 035 + 0xFFFFFFFF, // 036 + 0xFFFFFFFF, // 037 + 0xFFFFFFFF, // 038 + 0xFFFFFFFF, // 039 + 0xFFFFFFFF, // 040 + 0xFFFFFFFF, // 041 + 0xFFFFFFFF, // 042 + 0xFFFFFFFF, // 043 + 0xFFFFFFFF, // 044 + 0xFFFFFFFF, // 045 + 0xFFFFFFFF, // 046 + 0xFFFFFFFF, // 047 + (ALL &~ MIDDLE), // 048 '0' + (RIGHT), // 049 '1' + (ALL &~ TLEFT &~ BRIGHT), // 050 '2' + (ALL &~ LEFT), // 051 '3' + (TLEFT | MIDDLE | RIGHT), // 052 '4' + (ALL &~ TRIGHT &~ BLEFT), // 053 '5' + (ALL &~ TRIGHT), // 054 '6' + (TOP | RIGHT), // 055 '7' + (ALL), // 056 '8' + (ALL &~ BOTTOM &~ BLEFT), // 057 '9' + 0xFFFFFFFF, // 058 + 0xFFFFFFFF, // 059 + 0xFFFFFFFF, // 060 + 0XFFFFFFFF, // 061 + 0xFFFFFFFF, // 062 + 0xFFFFFFFF, // 063 + 0xFFFFFFFF, // 064 + (ALL &~ BOTTOM), // 065 'A' + (ALL), // 066 'B' + (TOP | LEFT | BOTTOM), // 067 'C' + (ALL &~ MIDDLE), // 068 'D' + (ALL &~ RIGHT), // 069 'E' + (LEFT | TOP | MIDDLE), // 070 'F' + 0x00000000, // 071 'G' + (ALL &~ TOP &~ BOTTOM), // 072 'H' + (RIGHT), // 073 'I' + (RIGHT | BOTTOM), // 074 'J' + 0x00000000, // 075 'K' + (LEFT | BOTTOM), // 076 'L' + 0x00000000, // 088 'M' + 0x00000000, // 089 'N' + (ALL &~ MIDDLE), // 090 'O' + (ALL &~ BRIGHT &~ BOTTOM),// 091 'P' + 0x00000000, // 092 'Q' + 0x00000000, // 093 'R' + (ALL &~ TRIGHT &~ BLEFT), // 094 'S' + 0X00000000, // 095 'T' + (LEFT | RIGHT | BOTTOM), // 096 'U' + 0x00000000, // 097 'V' + 0x00000000, // 098 'W' + 0x00000000, // 099 'X' + 0x00000000, // 1000 'Z' + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 100 + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 104 + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 108 + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 112 + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 116 + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, // 120 + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF // 124 +}; + +#define CT 1.0f +#define CX 7.0f +#define CY 13.0f +#define CM ((CY-(CT*3.0f))/2.0f) + +float lCoords[][2] = +{ + /* Top outsides. */ + { 0, (CY-CT) }, + { CX, (CY-CT) }, + + /* Top Line. */ + { CT, CY }, + { CT, (CY-CT) }, + { (CX-CT), CY }, + { (CX-CT), (CY-CT) }, + + /* Middle outsides. */ + { 0.0f, (CT+CM+CT) }, + { 0.0f, (CT+CM) }, + { CX, (CT+CM+CT) }, + { CX, (CT+CM) }, + + /* Middle Line. */ + { CT, (CT+CM+CT) }, + { CT, (CT+CM) }, + { (CX-CT), (CT+CM+CT) }, + { (CX-CT), (CT+CM) }, + + /* Bottom line. */ + { CT, CT }, + { CT, 0.0f }, + { (CX-CT), CT }, + { (CX-CT), 0.0f }, + + /* Bottom outsides. */ + { 0.0f, CT}, + { CX, CT } +}; + +static int ConvertCharacter( char *c, int cIndex, PD3DFONTMETRICS pfntMetrics ); + +D3DTLVERTEX TextVertices[MAX_VERTICES]; +/*===========================================================================*/ +/* When we attach I will zero out the whole D3D vertex buffer I'm using for */ +/* the text. This way I don't need to set all the redundant values. I also */ +/* set all the oow values to 1 as I will be doing direct rendering. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +extern "C" BOOL InitD3DText( void ) +{ + int index; + + /* Set the D3D Vertex Buffer up once so we don't do redundant changes. */ + memset( &TextVertices[0], 0, sizeof(TextVertices) ); + for( index = 0; index < MAX_VERTICES; index++ ) + TextVertices[index].rhw = D3DVAL( 1.0 ); + + return TRUE; +} +/*===========================================================================*/ +/* This function takes a single character and draw it using the supplied */ +/* fontmetrics structure. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void d3dTextDrawString( char *pszString, int x, int y, PD3DFONTMETRICS pfntMetrics ) +{ + int cIndex, + nIndex, + index; + float cWidth = CX, + cHeight = CY; + + /* Find the max width/height of a character and add the spacing so */ + /* that we can use this value to calculate the x,y of the character.*/ + cWidth = (cWidth * pfntMetrics->fntXScale) + pfntMetrics->fntXSpacing; + cHeight = (cHeight * pfntMetrics->fntYScale) + pfntMetrics->fntYSpacing; + + /* Walk the string. This must be NULL terminated. */ + for( cIndex = 0, nIndex = 0; *pszString; pszString++, cIndex = nIndex, x++ ) + { + /* Convert the character and get the index into the text vertex buffer. */ + nIndex = ConvertCharacter( &pszString[0], cIndex, pfntMetrics ); + if ( (nIndex - cIndex) > 2 ) + { + /* Modify the text vertex buffer based on the fntMetrics structure. */ + for( index = cIndex; index < nIndex; index++ ) + { + /* Scale the character. */ + TextVertices[index].sx *= pfntMetrics->fntXScale; + TextVertices[index].sy *= pfntMetrics->fntYScale; + + /* Move the character. */ + TextVertices[index].sx += (cWidth*x); + TextVertices[index].sy += (cHeight*y); + + /* Set the color. */ + TextVertices[index].color = pfntMetrics->dwColor; + } + } + } + + if ( nIndex < 3 ) + return; + + /* Set the states that slim things down. */ + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE , FALSE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); + + /* Blast them baby... */ + pfntMetrics->lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, + D3DFVF_TLVERTEX, + (LPVOID)&TextVertices[0], + nIndex, + (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); +} +/*===========================================================================*/ +/* This function takes a single character and draw it directly to the screen*/ +/* unsing the supplied fntMetrics structure. The character will be drawn at */ +/* the supplied x,y. The x,y position is relative to the top left and uses */ +/* the spacing in the fntMetrics structure. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void d3dTextDrawCharacter( char *c, int x, int y, PD3DFONTMETRICS pfntMetrics ) +{ + int cIndex = 0, + index; + float cWidth = CX, + cHeight = CY; + + /* Convert the character and get the index into the text vertex buffer. */ + cIndex = ConvertCharacter( c, 0, pfntMetrics ); + if ( cIndex < 3 ) + return; + + /* Find the max width/height of a character and add the spacing so */ + /* that we can use this value to calculate the x,y of the character.*/ + cWidth = (cWidth * pfntMetrics->fntXScale) + pfntMetrics->fntXSpacing; + cHeight = (cHeight * pfntMetrics->fntYScale) + pfntMetrics->fntYSpacing; + + /* Modify the text vertex buffer based on the fntMetrics structure. */ + for( index = 0; index < cIndex; index++ ) + { + /* Scale the character. */ + TextVertices[index].sx *= pfntMetrics->fntXScale; + TextVertices[index].sy *= pfntMetrics->fntYScale; + + /* Move the character. */ + TextVertices[index].sx += (cWidth*x); + TextVertices[index].sy += (cHeight*y); + + /* Set the color. */ + TextVertices[index].color = pfntMetrics->dwColor; + } + + + /* Set the states that slim things down. */ + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE , FALSE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); + pfntMetrics->lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); + + /* Blast them baby... */ + pfntMetrics->lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, + D3DFVF_TLVERTEX, + (LPVOID)&TextVertices[0], + cIndex, + (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); +} +/*===========================================================================*/ +/* This function takes a single character and draw it using the supplied */ +/* fontmetrics structure. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static int ConvertCharacter( char *c, int cIndex, PD3DFONTMETRICS pfntMetrics ) +{ + DWORD asciiChar = (int)(*c); + + /* Handle the TOP line. */ + if ( textBitMasks[asciiChar] & BIT1 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[TL_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TL_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_0][1] ); + } + + /* Handle the TOP/BOTTOM RIGHT lines. */ + // if ( textBitMasks[index] & (BIT2|BIT3) ) + if ( 1 == 0 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TRR][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TRR][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BRR][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BRR][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TR_1][1] ); + } + else + { + if ( textBitMasks[asciiChar] & BIT2 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[TR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TRR][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[TRR][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MR_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TR_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[TR_1][1] ); + } + if ( textBitMasks[asciiChar] & BIT3 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MRR_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MRR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[BRR][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BRR][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[BRR][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[BR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MR_1][1] ); + } + } + + /* Handle the TOP/BOTTOM LEFT lines. */ + // if ( textBitMasks[asciiChar] & (BIT5|BIT6) ) + if ( 1 == 0 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TLL][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TL_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BLL][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BLL][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[TLL][1] ); + } + else + { + if ( textBitMasks[asciiChar] & BIT5 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[ML_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[BL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[BL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BLL][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[BLL][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_1][1] ); + } + if ( textBitMasks[asciiChar] & BIT6 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[TLL][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TL_1][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[TL_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[ML_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MLL_0][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[MLL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[TLL][0] ); + TextVertices[cIndex++].sy = D3DVAL( lCoords[TLL][1] ); + } + } + + /* Handle the MIDDLE line. */ + if ( textBitMasks[asciiChar] & BIT7 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MR_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[MR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[MR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[ML_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[ML_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[ML_0][1] ); + } + + /* Handle the BOTTOM line. */ + if ( textBitMasks[asciiChar] & BIT4 ) + { + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BR_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_0][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BR_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BR_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_1][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_1][1] ); + TextVertices[cIndex].sx = D3DVAL( lCoords[BL_0][0] ); + TextVertices[cIndex++].sy= D3DVAL( lCoords[BL_0][1] ); + } + + return cIndex; +} + +#undef CM +#undef CY +#undef CX +#undef CT + +#undef TLL +#undef TRR +#undef TL_0 +#undef TL_1 +#undef TR_0 +#undef TR_1 + +#undef MLL_0 +#undef MLL_1 +#undef MRR_0 +#undef MRR_1 + +#undef ML_0 +#undef ML_1 +#undef MR_0 +#undef MR_1 + +#undef BL_0 +#undef BL_1 +#undef BR_0 +#undef BR_1 +#undef BLL +#undef BRR + +#undef BIT1 +#undef BIT2 +#undef BIT3 +#undef BIT4 +#undef BIT5 +#undef BIT6 +#undef BIT7 + +#undef TOP +#undef MIDDLE +#undef BOTTOM +#undef TLEFT +#undef BLEFT +#undef LEFT +#undef TRIGHT +#undef BRIGHT +#undef RIGHT +#undef ALL --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DRaster.cpp +++ mesa-7.2/src/mesa/drivers/d3d/D3DRaster.cpp @@ -0,0 +1,213 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DHAL.h" +/*===========================================================================*/ +/* This function clears the context bound to the supplied shared context. */ +/* The function takes the D3D flags D3DCLEAR_TARGET, D3DCLEAR_STENCIL and */ +/* D3DCLEAR_ZBUFFER. Set bAll to TRUE for a full clear else supply the coord*/ +/* of the rect to be cleared relative to the window. The color is always a */ +/* 32bit value (RGBA). Fill in the z-value and stencil if needed. */ +/* */ +/* TODO: this can be redone to be called by Mesa directly. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void ClearHAL( PMESAD3DSHARED pShared, DWORD dwFlags, BOOL bAll, int x, int y, int cx, int cy, DWORD dwColor, float zv, DWORD dwStencil ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + D3DRECT d3dRect; + +#ifdef D3D_DEBUG + HRESULT rc; + + DPF(( DBG_FUNC, "CleaHAL();" )); + + /* Make sure we have enough info. */ + if ( (pHAL == NULL) || (pHAL->lpViewport == NULL) ) + return; +#endif + + if ( bAll ) + { + /* I assume my viewport is valid. */ + d3dRect.lX1 = pShared->rectV.left; + d3dRect.lY1 = pShared->rectV.top; + d3dRect.lX2 = pShared->rectV.right; + d3dRect.lY2 = pShared->rectV.bottom; + } + else + { + d3dRect.lX1 = pShared->rectV.left + x; + d3dRect.lY1 = pShared->rectV.top + y; + d3dRect.lX2 = d3dRect.lX1 + cx; + d3dRect.lY2 = d3dRect.lY1 + cy; + } + +#ifdef D3D_DEBUG + rc = pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil ); + if ( FAILED(rc) ) + { + RIP( pHAL, "Clear2 ->", ErrorStringD3D(rc) ); + } +#else + pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil ); +#endif +} +/*===========================================================================*/ +/* Well this is the guts of it all. Here we rasterize the primitives that */ +/* are in their final form. OpenGL has done all the lighting, transfomations*/ +/* and clipping at this point. */ +/* */ +/* TODO: I'm not sure if I want to bother to check for errors on this call. */ +/* The overhead kills me... */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void DrawPrimitiveHAL( PMESAD3DSHARED pShared, D3DPRIMITIVETYPE dptPrimitiveType, D3DTLVERTEX *pVertices, DWORD dwCount ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + +#ifdef D3D_DEBUG + HRESULT rc; + + DPF(( DBG_FUNC, "DrawPrimitveHAL();" )); + + /* Make sure we have enough info. */ + if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) ) + return; + + DPF(( DBG_PRIM_INFO, "DP( %d )", dwCount )); + + rc = pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType, + D3DFVF_TLVERTEX, + (LPVOID)pVertices, + dwCount, + (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); + if ( FAILED(rc) ) + { + RIP( pHAL, "DrawPrimitive ->", ErrorStringD3D(rc) ); + } +#else + pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType, + D3DFVF_TLVERTEX, + (LPVOID)pVertices, + dwCount, + (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) ); +#endif +} +/*===========================================================================*/ +/* This call will handle the swapping of the buffers. Now I didn't bother */ +/* to support single buffered so this will be used for glFlush() as its all */ +/* the same. So first we do an EndScene as we are always considered to be in*/ +/* a BeginScene because when we leave we do a BeginScene. Now note that when*/ +/* the context is created in the first place we do a BeginScene also just to */ +/* get things going. The call will use either Flip/blt based on the type of */ +/* surface was created for rendering. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void SwapBuffersHAL( PMESAD3DSHARED pShared ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + +#ifdef D3D_DEBUG + HRESULT rc; + + DPF(( DBG_FUNC, "SwapBuffersHAL();" )); + DPF(( DBG_ALL_PROFILE, "=================SWAP===================" )); + + /* Make sure we have enough info. */ + if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) ) + return; + + /* Make sure we have enough info. */ + if ( pHAL->lpDDSPrimary != NULL ) + { + rc = pHAL->lpD3DDevice->EndScene(); + if ( FAILED(rc) ) + { + RIP( pHAL, "EndScene ->", ErrorStringD3D(rc) ); + } + + if ( pShared->bFlipable ) + { + DPF(( DBG_CNTX_PROFILE, "Swap->FLIP" )); + rc = pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ); + } + else + { + DPF(( DBG_CNTX_PROFILE, "Swap->Blt" )); + rc = pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL ); + } + if ( FAILED(rc) ) + { + RIP( pHAL, "Blt (RENDER/PRIMARY) ->", ErrorStringD3D(rc) ); + } + + rc = pHAL->lpD3DDevice->BeginScene(); + if ( FAILED(rc) ) + { + RIP( pHAL, "BeginScene ->", ErrorStringD3D(rc) ); + } + } +#else + pHAL->lpD3DDevice->EndScene(); + + if ( pShared->bFlipable ) + pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ); + else + pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL ); + + pHAL->lpD3DDevice->BeginScene(); + +#endif +} +/*===========================================================================*/ +/* This function is a very thin wrapper for the D3D call 'SetRenderState'. */ +/* Using this function requires all the types to be defined by including the */ +/* D3D header file. */ +/* */ +/* TODO: would be much better to get ride of all these calls per VBRender. */ +/* I feel I should get this call into SetRenderStates() the RenderVB. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void SetStateHAL( PMESAD3DSHARED pShared, DWORD dwType, DWORD dwState ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + +#ifdef D3D_DEBUG + HRESULT rc; + + DPF(( DBG_FUNC, "SetStateHAL();" )); + + /* Make sure we have enough info. */ + if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) ) + return; + + rc = pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState ); + if ( FAILED(rc) ) + { + RIP( pHAL, "SetRenderState ->", ErrorStringD3D(rc) ); + } + +#else + pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState ); +#endif +} + + + + + + + + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DShared.h +++ mesa-7.2/src/mesa/drivers/d3d/D3DShared.h @@ -0,0 +1,154 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef D3D_MESA_ALL_H +#define D3D_MESA_ALL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include +#include +/*===========================================================================*/ +/* Magic numbers. */ +/*===========================================================================*/ +#define TM_ACTION_LOAD 0x01 +#define TM_ACTION_BIND 0x02 +#define TM_ACTION_UPDATE 0x04 + +#define UM_FATALSHUTDOWN (WM_USER+42) +/*===========================================================================*/ +/* Macros defines. */ +/*===========================================================================*/ +#define ALLOC(cb) malloc( (cb) ) +#define FREE(p) { free( (p) ); (p) = NULL; } +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +typedef struct _pixel_convert +{ + int cb, /* Count in bytes of one pixel. */ + rShift, /* Shift count that postions each componet. */ + gShift, + bShift, + aShift; + float rScale, /* Value that scales a color that ranges 0.0 -> 1.0 */ + gScale, /* to this pixel format. */ + bScale, + aScale; + DWORD dwRMask, /* Color mask per component. */ + dwGMask, + dwBMask, + dwAMask; + +} PIXELINFO, *PPIXELINFO; + + +typedef struct _d3d_shared_info +{ + HWND hwnd; + BOOL bWindow, + bFlipable, + bForceSW, + bHardware; + RECT rectW, /* Window size and postion in screen space. */ + rectV; /* Viewport size and postion. */ + DWORD dwWidth, /* Current render size for quick checks. */ + dwHeight; + + PIXELINFO pixel; + DWORD dwSrcBlendCaps[14], /* See D3DCAPS.CPP */ + dwDestBlendCaps[14], + dwTexFunc[4]; + +} MESAD3DSHARED, *PMESAD3DSHARED; + +typedef struct _render_options +{ + BOOL bForceSoftware, /* TODO: Add user switches. */ + bStretchtoPrimary; + +} USER_CTRL, *PUSER_CRTL; + +enum { s_zero = 0, + s_one, + s_dst_color, + s_one_minus_dst_color, + s_src_alpha, + s_one_minus_src_alpha, + s_dst_alpha, + s_one_minus_dst_alpha, + s_src_alpha_saturate, + s_constant_color, + s_one_minus_constant_color, + s_constant_alpha, + s_one_minus_constant_alpha }; + +enum { d_zero = 0, + d_one, + d_src_color, + d_one_minus_src_color, + d_src_alpha, + d_one_minus_src_alpha, + d_dst_alpha, + d_one_minus_dst_alpha, + d_constant_color, + d_one_minus_constant_color, + d_constant_alpha, + d_one_minus_constant_alpha }; + +enum { d3dtblend_decal = 0, + d3dtblend_decalalpha, + d3dtblend_modulate, + d3dtblend_modulatealpha }; + +/*===========================================================================*/ +/* Function prototypes. */ +/*===========================================================================*/ +PMESAD3DSHARED InitHAL( HWND hwnd ); +void TermHAL( PMESAD3DSHARED pShared ); +BOOL CreateHAL( PMESAD3DSHARED pShared ); +BOOL SetViewportHAL( PMESAD3DSHARED pShared, RECT *pRect, float minZ, float maxZ ); + +void ClearHAL( PMESAD3DSHARED pShared, DWORD dwFlags, BOOL bAll, int x, int y, int cx, int cy, DWORD dwColor, float zv, DWORD dwStencil ); +void SetStateHAL( PMESAD3DSHARED pShared, DWORD dwType, DWORD dwState ); +void DrawPrimitiveHAL( PMESAD3DSHARED pShared, D3DPRIMITIVETYPE dptPrimitiveType, D3DTLVERTEX *pVertices, DWORD dwCount ); + +void SwapBuffersHAL( PMESAD3DSHARED pShared ); +DDSURFACEDESC2 *LockHAL( PMESAD3DSHARED pShared, BOOL bBack ); +void UnlockHAL( PMESAD3DSHARED pShared, BOOL bBack ); +void UpdateScreenPosHAL( PMESAD3DSHARED pShared ); +void GetPixelInfoHAL( PMESAD3DSHARED pShared, PPIXELINFO pPixel ); +BOOL CreateTMgrHAL( PMESAD3DSHARED pShared, DWORD dwName, int level, DWORD dwRequestFlags, RECT *rectDirty, DWORD dwWidth, DWORD dwHeight, DWORD dwAction, void *pPixels ); +void DisableTMgrHAL( PMESAD3DSHARED pShared ); + + +int SaveDIBitmap( char *filename, BITMAPINFO *info, void *bits ); +int ARGB_SaveBitmap( char *filename, int width, int height, unsigned char *pARGB ); +int BGRA_SaveBitmap( char *filename, int width, int height, unsigned char *pBGRA ); +int BGR_SaveBitmap( char *filename, int width, int height, unsigned char *pBGR ); +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ +extern float g_DepthScale, /* Mesa needs to scale Z in SW. The HAL */ + g_MaxDepth; /* doesn't but I wanted SW still to work.*/ + +#ifdef __cplusplus +} +#endif + +#endif + + + --- mesa-7.2.orig/src/mesa/drivers/d3d/d3dText.h +++ mesa-7.2/src/mesa/drivers/d3d/d3dText.h @@ -0,0 +1,53 @@ +#ifndef D3D_TEXT_H +#define D3D_TEXT_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include +#include +#include +/*===========================================================================*/ +/* Magic numbers. */ +/*===========================================================================*/ +#define D3DLTEXT_BITSUSED 0xFFFFFFFF +#define MAX_VERTICES 700 // (14*40) 14 per character, 40 characters +/*===========================================================================*/ +/* Macros defines. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +typedef struct _d3dText_metrics +{ + float fntYScale, + fntXScale; + + int fntXSpacing, + fntYSpacing; + + DWORD dwColor; + LPDIRECT3DDEVICE3 lpD3DDevice; + +} D3DFONTMETRICS, *PD3DFONTMETRICS; +/*===========================================================================*/ +/* Function prototypes. */ +/*===========================================================================*/ +extern BOOL InitD3DText( void ); +extern void d3dTextDrawCharacter( char *c, int x, int y, PD3DFONTMETRICS pfntMetrics ); +extern void d3dTextDrawString( char *pszString, int x, int y, PD3DFONTMETRICS pfntMetrics ); +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ + +#ifdef __cplusplus +} +#endif + + +#endif --- mesa-7.2.orig/src/mesa/drivers/d3d/NULLProcs.h +++ mesa-7.2/src/mesa/drivers/d3d/NULLProcs.h @@ -0,0 +1,49 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef NULL_MESA_PROCS_INC +#define NULL_MESA_PROCS_INC +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include "matrix.h" +#include "context.h" +#include "types.h" +#include "vb.h" +/*===========================================================================*/ +/* Macros. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Magic numbers. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +void NULLSetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); +void NULLClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); +GLboolean NULLSetBuffer( GLcontext *ctx, GLenum mode ); +void NULLGetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ); +GLbitfield NULLClearBuffers( GLcontext *ctx, GLbitfield m, GLboolean a, GLint x, GLint y, GLint w, GLint h ); +void NULLWrSpRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][3], const GLubyte m[] ); +void NULLWrSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][4], const GLubyte m[] ); +void NULLWrSpRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte m[] ); +void NULLWrPiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte r[][4], const GLubyte m[] ); +void NULLWrPiRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte m[] ); +void NULLReSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte r[][4] ); +void NULLRePiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte r[][4], const GLubyte m[] ); +/*===========================================================================*/ +/* Extern function prototypes. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ + +#endif + --- mesa-7.2.orig/src/mesa/drivers/d3d/WGL.C +++ mesa-7.2/src/mesa/drivers/d3d/WGL.C @@ -0,0 +1,1262 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 Makefile for DirectX 6 */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1998-1997 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DMesa.h" +/*===========================================================================*/ +/* Window managment. */ +/*===========================================================================*/ +static BOOL InitOpenGL( HINSTANCE hInst ); +static BOOL TermOpenGL( HINSTANCE hInst ); +static BOOL ResizeContext( GLcontext *ctx ); +static BOOL MakeCurrent( D3DMESACONTEXT *pContext ); +static void DestroyContext( D3DMESACONTEXT *pContext ); +static BOOL UnBindWindow( D3DMESACONTEXT *pContext ); +LONG APIENTRY wglMonitorProc( HWND hwnd, UINT message, UINT wParam, LONG lParam ); +/*===========================================================================*/ +/* Mesa hooks. */ +/*===========================================================================*/ +static void SetupDDPointers( GLcontext *ctx ); +static void SetupSWDDPointers( GLcontext *ctx ); +static void SetupHWDDPointers( GLcontext *ctx ); +static void SetupNULLDDPointers( GLcontext *ctx ); +static const char *RendererString( void ); + +/* State Management hooks. */ +static void SetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); +static void ClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); +static GLboolean SetBuffer( GLcontext *ctx, GLenum buffer ); + +/* Window Management hooks. */ +static void GetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ); +static void SetViewport( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ); +static void Flush( GLcontext *ctx ); + +/* Span rendering hooks. */ +void WSpanRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ); +void WSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ); +void WSpanRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] ); +void WPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ); +void WPixelsRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] ); +void RSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ); +void RPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ); +GLbitfield ClearBuffers( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ); + +/* Primitve rendering hooks. */ +GLboolean RenderVertexBuffer( GLcontext *ctx, GLboolean allDone ); +void RenderOneTriangle( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv ); +void RenderOneLine( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ); +GLbitfield ClearBuffersD3D( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ); + +/* Texture Management hooks. */ +static void TextureBind( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ); +static void TextureLoad( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint internalFormat, const struct gl_texture_image *image ); +static void TextureSubImage( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLint internalFormat, const struct gl_texture_image *image ); +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ +D3DMESACONTEXT *pD3DCurrent, + *pD3DDefault; /* Thin support context. */ + +struct __extensions__ ext[] = { + + { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, + { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, + { (PROC)glBlendColorEXT, "glBlendColorExt" }, + { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, + { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, + { (PROC)glColorPointerEXT, "glColorPointerEXT" }, + { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, + { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, + { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, + { (PROC)glGetPointervEXT, "glGetPointervEXT" }, + { (PROC)glArrayElementEXT, "glArrayElementEXT" }, + { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, + { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, + { (PROC)glBindTextureEXT, "glBindTextureEXT" }, + { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, + { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, + { (PROC)glIsTextureEXT, "glIsTextureEXT" }, + { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, + { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, + { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, + { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, +}; + +int qt_ext = sizeof(ext) / sizeof(ext[0]); +float g_DepthScale, + g_MaxDepth; +/*===========================================================================*/ +/* When a process loads this DLL we will setup the linked list for context */ +/* management and create a default context that will support the API until */ +/* the user creates and binds thier own. This THIN default context is useful*/ +/* to have around. */ +/* When the process terminates we will clean up all resources here. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY DllMain( HINSTANCE hInst, DWORD reason, LPVOID reserved ) +{ + switch( reason ) + { + case DLL_PROCESS_ATTACH: + return InitOpenGL( hInst ); + + case DLL_PROCESS_DETACH: + return TermOpenGL( hInst ); + } + + return TRUE; +} +/*===========================================================================*/ +/* The first thing we do when this dll is hit is connect to the dll that has*/ +/* handles all the DirectX 6 rendering. I decided to use another dll as DX6 */ +/* is all C++ and Mesa-3.0 is C (thats a good thing). This way I can write */ +/* the DX6 in C++ and Mesa-3.0 in C without having to worry about linkage. */ +/* I feel this is easy and better then using static wrappers as it is likely */ +/* faster and it allows me to just develope the one without compiling the */ +/* other. */ +/* NOTE that at this point we don't have much other than a very thin context*/ +/* that will support the API calls only to the point of not causing the app */ +/* to crash from the API table being empty. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +static BOOL InitOpenGL( HINSTANCE hInst ) +{ + /* Allocate and clear the default context. */ + pD3DDefault = (PD3DMESACONTEXT)ALLOC( sizeof(D3DMESACONTEXT) ); + if ( pD3DDefault == NULL ) + return FALSE; + memset( pD3DDefault, 0, sizeof(D3DMESACONTEXT) ); + + /* Clear the D3D vertex buffer so that values not used will be zero. This */ + /* save me from some redundant work. */ + memset( &D3DTLVertices, 0, sizeof(D3DTLVertices) ); + + /* Update the link. We uses a circular list so that it is easy to */ + /* add and search. This context will also be used for head and tail.*/ + pD3DDefault->next = pD3DDefault; + + /*========================================================================*/ + /* Do all core Mesa stuff. */ + /*========================================================================*/ + pD3DDefault->gl_visual = _mesa_create_visual( TRUE, + FALSE, /* db_flag */ + GL_FALSE, /* stereo */ + 8,8,8,8, /* r, g, b, a bits */ + 0, /* index bits */ + 16, /* depth_bits */ + 8, /* stencil_bits */ + 8,8,8,8, /* accum_bits */ + 1 ); + + if ( pD3DDefault->gl_visual == NULL) + { + FREE( pD3DDefault ); + return FALSE; + } + + /* Allocate a new Mesa context */ + pD3DDefault->gl_ctx = _mesa_create_context( pD3DDefault->gl_visual, NULL, pD3DDefault, GL_TRUE ); + if ( pD3DDefault->gl_ctx == NULL ) + { + _mesa_destroy_visual( pD3DDefault->gl_visual ); + FREE( pD3DDefault ); + return FALSE; + } + + /* Allocate a new Mesa frame buffer */ + pD3DDefault->gl_buffer = _mesa_create_framebuffer( pD3DDefault->gl_visual ); + if ( pD3DDefault->gl_buffer == NULL ) + { + _mesa_destroy_visual( pD3DDefault->gl_visual ); + _mesa_destroy_context( pD3DDefault->gl_ctx ); + FREE( pD3DDefault ); + return FALSE; + } + SetupDDPointers( pD3DDefault->gl_ctx ); + _mesa_make_current( pD3DDefault->gl_ctx, pD3DDefault->gl_buffer ); + + return TRUE; +} +/*===========================================================================*/ +/* This function will create a new D3D context but will not create the D3D */ +/* surfaces or even an instance of D3D (see at GetBufferSize). The only stuff*/ +/* done here is the internal Mesa stuff and some Win32 handles. */ +/*===========================================================================*/ +/* RETURN: casted pointer to the context, NULL. */ +/*===========================================================================*/ +HGLRC APIENTRY wglCreateContext( HDC hdc ) +{ + D3DMESACONTEXT *pNewContext; + DWORD dwCoopFlags = DDSCL_NORMAL; + RECT rectClient; + POINT pt; + + /* ALLOC and clear the new context. */ + pNewContext = (PD3DMESACONTEXT)ALLOC( sizeof(D3DMESACONTEXT) ); + if ( pNewContext == NULL ) + { + SetLastError( 0 ); + return (HGLRC)NULL; + } + memset( pNewContext, 0, sizeof(D3DMESACONTEXT) ); + + /*========================================================================*/ + /* Do all core Mesa stuff. */ + /*========================================================================*/ + + /* TODO: support more then one visual. */ + pNewContext->gl_visual = _mesa_create_visual( TRUE, + TRUE, /* db_flag */ + GL_FALSE, /* stereo */ + 8,8,8,8, /* r, g, b, a bits */ + 0, /* index bits */ + 16, /* depth_bits */ + 8, /* stencil_bits */ + 16,16,16,16,/* accum_bits */ + 1 ); + if ( pNewContext->gl_visual == NULL) + { + FREE( pNewContext ); + SetLastError( 0 ); + return (HGLRC)NULL; + } + + /* Allocate a new Mesa context */ + pNewContext->gl_ctx = _mesa_create_context( pNewContext->gl_visual, NULL, pNewContext, GL_TRUE ); + if ( pNewContext->gl_ctx == NULL ) + { + _mesa_destroy_visual( pNewContext->gl_visual ); + FREE( pNewContext ); + SetLastError( 0 ); + return (HGLRC)NULL; + } + + /* Allocate a new Mesa frame buffer */ + pNewContext->gl_buffer = _mesa_create_framebuffer( pNewContext->gl_visual ); + if ( pNewContext->gl_buffer == NULL ) + { + _mesa_destroy_visual( pNewContext->gl_visual ); + _mesa_destroy_context( pNewContext->gl_ctx ); + FREE( pNewContext ); + SetLastError( 0 ); + return (HGLRC)NULL; + } + + /*========================================================================*/ + /* Do all the driver stuff. */ + /*========================================================================*/ + pNewContext->hdc = hdc; + pNewContext->next = pD3DDefault->next; + pD3DDefault->next = pNewContext; /* Add to circular list. */ + + /* Create the HAL for the new context. */ + pNewContext->pShared = InitHAL( WindowFromDC(hdc) ); + + return (HGLRC)pNewContext; +} +/*===========================================================================*/ +/* This is a wrapper function that is supported by MakeCurrent. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglMakeCurrent( HDC hdc, HGLRC hglrc ) +{ + return MakeCurrent((D3DMESACONTEXT *)hglrc); +} +/*===========================================================================*/ +/* MakeCurrent will unbind whatever context is current (if any) & then bind */ +/* the supplied context. A context that is bound has it's window proc hooked*/ +/* with the wglMonitorProc and the context pointer is saved in pD3DCurrent. */ +/* Once the context is bound we update the Mesa-3.0 hooks (SetDDPointers) and*/ +/* the viewport (Mesa-.30 and DX6). */ +/* */ +/* TODO: this function can't fail. */ +/*===========================================================================*/ +/* RETURN: TRUE */ +/*===========================================================================*/ +static BOOL MakeCurrent( D3DMESACONTEXT *pContext ) +{ + D3DMESACONTEXT *pNext; + + /*====================================================================*/ + /* This is a special case that is a request to have no context bound. */ + /*====================================================================*/ + if ( pContext == NULL ) + { + /* Walk the whole list. We start and end at the Default context. */ + for( pNext = pD3DDefault->next; pNext != pD3DDefault; pNext = pNext->next ) + UnBindWindow( pNext ); + + return TRUE; + } + + /*=================================================*/ + /* Make for a fast redundant use of this function. */ + /*=================================================*/ + if ( pD3DCurrent == pContext ) + return TRUE; + + /*=============================*/ + /* Unbind the current context. */ + /*=============================*/ + UnBindWindow( pD3DCurrent ); + + /*=====================================*/ + /* Let Mesa-3.0 we have a new context. */ + /*=====================================*/ + SetupDDPointers( pContext->gl_ctx ); + _mesa_make_current( pContext->gl_ctx, pContext->gl_buffer ); + + /* We are done so set the internal current context. */ + if ( pContext != pD3DDefault ) + { + ResizeContext( pContext->gl_ctx ); + pContext->hOldProc = (WNDPROC)GetWindowLong( pContext->pShared->hwnd, GWL_WNDPROC ); + SetWindowLong( pContext->pShared->hwnd, GWL_WNDPROC, (LONG)wglMonitorProc ); + } + pD3DCurrent = pContext; + + return TRUE; +} +/*===========================================================================*/ +/* This function will only return the current window size. I have re-done */ +/* this function so that it doesn't check the current size and react to it as*/ +/* I should be able to have all the react code in the WM_SIZE message. The */ +/* old version would check the current window size and create/resize the HAL */ +/* surfaces if they have changed. I needed to delay the creation if the */ +/* surfaces because sometimes I wouldn't have a window size so this is where */ +/* I delayed it. If you are reading this then all went ok! */ +/* The default context will return a zero sized window and I'm not sure if */ +/* this is ok at this point (TODO). */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void GetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + /* Fall through for the default because that is one of the uses for it. */ + if ( pContext == pD3DDefault ) + { + *width = 0; + *height = 0; + } + else + { + *width = pContext->pShared->dwWidth; + *height = pContext->pShared->dwHeight; + } +} +/*===========================================================================*/ +/* */ +/* */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static BOOL ResizeContext( GLcontext *ctx ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx, + *pCurrentTemp; + RECT rectClient; + POINT pt; + DWORD dwWidth, + dwHeight; + static BOOL bDDrawLock = FALSE; + + /* Make sure we have some values. */ + if ( (pContext->hdc == NULL ) || + (pContext->pShared->hwnd != WindowFromDC(pContext->hdc)) || + (pContext == pD3DDefault) ) + return FALSE; + + /* Having problems with DDraw sending resize messages before I was done. */ + if( bDDrawLock == TRUE ) + return FALSE; + + // TODO: don't think I need this anymore. + pCurrentTemp = pD3DCurrent; + pD3DCurrent = pD3DDefault; + bDDrawLock = TRUE; + + /* Get the current window dimentions. */ + UpdateScreenPosHAL( pContext->pShared ); + dwWidth = pContext->pShared->rectW.right - pContext->pShared->rectW.left; + dwHeight = pContext->pShared->rectW.bottom - pContext->pShared->rectW.top; + + /* Is the size of the OffScreen Render different? */ + if ( (dwWidth != pContext->pShared->dwWidth) || (dwHeight != pContext->pShared->dwHeight) ) + { + /* Create all the D3D surfaces and device. */ + CreateHAL( pContext->pShared ); + + /* I did this so that software rendering would still work as */ + /* I don't need to scale the z values twice. */ + g_DepthScale = (pContext->pShared->bHardware) ? 1.0 : ((float)0x00FFFFFF); + g_MaxDepth = (pContext->pShared->bHardware) ? 1.0 : ((float)0x00FFFFFF); + gl_DepthRange( pContext->gl_ctx, ctx->Viewport.Near, ctx->Viewport.Far ); + + /* Make sure we have a viewport. */ + gl_Viewport( pContext->gl_ctx, 0, 0, dwWidth, dwHeight ); + + /* Update Mesa as we might have changed from SW <-> HW. */ + SetupDDPointers( pContext->gl_ctx ); + _mesa_make_current( pContext->gl_ctx, pContext->gl_buffer ); + + /* If we are in HW we need to load the current texture if there is one already. */ + // if ( (ctx->Texture.Set[ctx->Texture.CurrentSet].Current != NULL) && + // (pContext->pShared->bHardware == TRUE) ) + // { + // CreateTMgrHAL( pContext->pShared, + // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name, + // 0, + // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Format, + // (RECT *)NULL, + // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Width, + // ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Height, + // TM_ACTION_BIND, + // (void *)ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0]->Data ); + // } + } + + // TODO: don't think I need this anymore. + pD3DCurrent = pCurrentTemp; + bDDrawLock = FALSE; + + return TRUE; +} + +/*===========================================================================* +/* This function will Blt the render buffer to the PRIMARY surface. I repeat*/ +/* this code for the other SwapBuffer like functions and the flush (didn't */ +/* want the function calling overhead). Thsi could have been a macro... */ +/* */ +/* TODO: there are some problems with viewport/scissoring. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglSwapBuffers( HDC hdc ) +{ + /* Fall through for the default because that is one of the uses for it. */ + if ( pD3DCurrent == pD3DDefault ) + return FALSE; + + SwapBuffersHAL( pD3DCurrent->pShared ); + + return TRUE; +} +/*===========================================================================*/ +/* Same as wglSwapBuffers. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY SwapBuffers( HDC hdc ) +{ + /* Fall through for the default because that is one of the uses for it. */ + if ( pD3DCurrent == pD3DDefault ) + return FALSE; + + SwapBuffersHAL( pD3DCurrent->pShared ); + + return TRUE; +} +/*===========================================================================*/ +/* This should be ok as none of the SwapBuffers will cause a redundant Blt */ +/* as none of my Swap functions will call flush. This should also allow */ +/* sinlge buffered applications to work (not really worried though). Some */ +/* applications may flush then swap but then this is there fault IMHO. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void Flush( GLcontext *ctx ) +{ + /* Fall through for the default because that is one of the uses for it. */ + if ( pD3DCurrent == pD3DDefault ) + return; + + SwapBuffersHAL( pD3DCurrent->pShared ); +} +/*===========================================================================*/ +/* For now this function will ignore the supplied PF. If I'm going to allow */ +/* the user to choice the mode and device at startup I'm going to have to do */ +/* something different. */ +/* */ +/* TODO: use the linked list of modes to build a pixel format to be returned */ +/* to the caller. */ +/*===========================================================================*/ +/* RETURN: 1. */ +/*===========================================================================*/ +int APIENTRY wglChoosePixelFormat( HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd ) +{ + return 1; +} +/*===========================================================================*/ +/* See wglChoosePixelFormat. */ +/*===========================================================================*/ +/* RETURN: 1. */ +/*===========================================================================*/ +int APIENTRY ChoosePixelFormat( HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd ) +{ + return wglChoosePixelFormat(hdc,ppfd); +} +/*===========================================================================*/ +/* This function (for now) returns a static PF everytime. This is just to */ +/* allow things to continue. */ +/*===========================================================================*/ +/* RETURN: 1. */ +/*===========================================================================*/ +int APIENTRY wglDescribePixelFormat( HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd ) +{ + static PIXELFORMATDESCRIPTOR pfd = + { + sizeof(PIXELFORMATDESCRIPTOR), /* size */ + 1, /* version */ + PFD_SUPPORT_OPENGL | + PFD_DRAW_TO_WINDOW | + PFD_DOUBLEBUFFER, /* support double-buffering */ + PFD_TYPE_RGBA, /* color type */ + 16, /* prefered color depth */ + 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ + 0, /* no alpha buffer */ + 0, /* alpha bits (ignored) */ + 0, /* no accumulation buffer */ + 0, 0, 0, 0, /* accum bits (ignored) */ + 16, /* depth buffer */ + 0, /* no stencil buffer */ + 0, /* no auxiliary buffers */ + PFD_MAIN_PLANE, /* main layer */ + 0, /* reserved */ + 0, 0, 0, /* no layer, visible, damage masks */ + }; + + /* Return the address of this static PF if one was requested. */ + if ( ppfd != NULL ) + memcpy( ppfd, &pfd, sizeof(PIXELFORMATDESCRIPTOR) ); + + return 1; +} +/*===========================================================================*/ +/* See wglDescribePixelFormat. */ +/*===========================================================================*/ +/* RETURN: 1. */ +/*===========================================================================*/ +int APIENTRY DescribePixelFormat( HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd ) +{ + return wglDescribePixelFormat(hdc,iPixelFormat,nBytes,ppfd); +} +/*===========================================================================*/ +/* This function will always return 1 for now. Just to allow for support. */ +/*===========================================================================*/ +/* RETURN: 1. */ +/*===========================================================================*/ +int APIENTRY wglGetPixelFormat( HDC hdc ) +{ + return 1; +} +/*===========================================================================*/ +/* See wglGetPixelFormat. */ +/*===========================================================================*/ +/* RETURN: 1. */ +/*===========================================================================*/ +int APIENTRY GetPixelFormat( HDC hdc ) +{ + return wglGetPixelFormat(hdc); +} +/*===========================================================================*/ +/* This will aways work for now. */ +/*===========================================================================*/ +/* RETURN: TRUE. */ +/*===========================================================================*/ +BOOL APIENTRY wglSetPixelFormat( HDC hdc, int iPixelFormat, CONST PIXELFORMATDESCRIPTOR *ppfd ) +{ + return TRUE; +} +/*===========================================================================*/ +/* See wglSetPixelFormat. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY SetPixelFormat( HDC hdc, int iPixelFormat, CONST PIXELFORMATDESCRIPTOR *ppfd ) +{ + return wglSetPixelFormat(hdc,iPixelFormat,ppfd); +} +/*===========================================================================*/ +/* This is a wrapper function that is supported by my own internal function.*/ +/* that takes my own D3D Mesa context structure. This so I can reuse the */ +/* function (no need for speed). */ +/*===========================================================================*/ +/* RETURN: TRUE. */ +/*===========================================================================*/ +BOOL APIENTRY wglDeleteContext( HGLRC hglrc ) +{ + DestroyContext( (D3DMESACONTEXT *)hglrc ); + + return TRUE; +} +/*===========================================================================*/ +/* Simple getter function that uses a cast. */ +/*===========================================================================*/ +/* RETURN: casted pointer to the context, NULL. */ +/*===========================================================================*/ +HGLRC APIENTRY wglGetCurrentContext( VOID ) +{ + return (pD3DCurrent) ? (HGLRC)pD3DCurrent : (HGLRC)NULL; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglCopyContext( HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask ) +{ + SetLastError( 0 ); + return FALSE; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: NULL. */ +/*===========================================================================*/ +HGLRC APIENTRY wglCreateLayerContext( HDC hdc,int iLayerPlane ) +{ + SetLastError( 0 ); + return (HGLRC)NULL; +} +/*===========================================================================*/ +/* Simple getter function. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +HDC APIENTRY wglGetCurrentDC( VOID ) +{ + return (pD3DCurrent) ? pD3DCurrent->hdc : (HDC)NULL; +} +/*===========================================================================*/ +/* Simply call that searches the supported extensions for a match & returns */ +/* the pointer to the function that lends support. */ +/*===========================================================================*/ +/* RETURN: pointer to API call, NULL. */ +/*===========================================================================*/ +PROC APIENTRY wglGetProcAddress( LPCSTR lpszProc ) +{ + int index; + + for( index = 0; index < qt_ext; index++ ) + if( !strcmp(lpszProc,ext[index].name) ) + return ext[index].proc; + + SetLastError( 0 ); + return NULL; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglShareLists( HGLRC hglrc1, HGLRC hglrc2 ) +{ + SetLastError( 0 ); + return FALSE; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglUseFontBitmaps( HDC fontDevice, DWORD firstChar, DWORD numChars, DWORD listBase ) +{ + SetLastError( 0 ); + return FALSE; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglUseFontBitmapsW( HDC hdc,DWORD first,DWORD count,DWORD listBase ) +{ + SetLastError( 0 ); + return FALSE; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglUseFontOutlinesA( HDC hdc, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf ) +{ + SetLastError( 0 ); + return FALSE; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglUseFontOutlinesW( HDC hdc,DWORD first,DWORD count, DWORD listBase,FLOAT deviation, FLOAT extrusion,int format, LPGLYPHMETRICSFLOAT lpgmf ) +{ + SetLastError( 0 ); + return FALSE ; +} +/*===========================================================================*/ +/* No support. */ +/*===========================================================================*/ +/* RETURN: FALSE. */ +/*===========================================================================*/ +BOOL APIENTRY wglSwapLayerBuffers( HDC hdc, UINT fuPlanes ) +{ + SetLastError( 0 ); + return FALSE; +} +/*===========================================================================*/ +/* This function will be hooked into the window that has been bound. Right */ +/* now it is used to track the window size and position. Also the we clean */ +/* up the currrent context when the window is close/destroyed. */ +/* */ +/* TODO: there might be something wrong here as some games (Heretic II) don't*/ +/* track the window quit right. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +LONG APIENTRY wglMonitorProc( HWND hwnd, UINT message, UINT wParam, LONG lParam ) +{ + WNDPROC hOldProc; + GLint width, + height; + + switch( message ) + { +// case WM_PAINT: +// break; +// case WM_ACTIVATE: +// break; +// case WM_SHOWWINDOW: +// break; + + case UM_FATALSHUTDOWN: + /* Support the API until we die... */ + MakeCurrent( pD3DDefault ); + break; + + case WM_MOVE: + case WM_DISPLAYCHANGE: + case WM_SIZE: + ResizeContext( pD3DCurrent->gl_ctx ); + break; + + case WM_CLOSE: + case WM_DESTROY: + /* Support the API until we die... */ + hOldProc = pD3DCurrent->hOldProc; + DestroyContext( pD3DCurrent ); + return (hOldProc)(hwnd,message,wParam,lParam); + } + + return (pD3DCurrent->hOldProc)(hwnd,message,wParam,lParam); +} + +/**********************************************************************/ +/***** Miscellaneous device driver funcs *****/ +/**********************************************************************/ + +/*===========================================================================*/ +/* Not reacting to this as I'm only supporting drawing to the back buffer */ +/* right now. */ +/*===========================================================================*/ +/* RETURN: TRUE. */ +/*===========================================================================*/ +static GLboolean SetBuffer( GLcontext *ctx, GLenum buffer ) +{ + if (buffer == GL_BACK_LEFT) + return GL_TRUE; + else + return GL_FALSE; +} +/*===========================================================================*/ +/* This proc will be called by Mesa when the viewport has been set. So if */ +/* we have a context and it isn't the default then we should let D3D know of */ +/* the change. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void SetViewport( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + RECT rect; + + /* Make sure we can set a viewport. */ + if ( pContext->pShared && (pContext != pD3DDefault) ) + { + // TODO: might be needed. + UpdateScreenPosHAL( pContext->pShared ); + rect.left = x; + rect.right = x + w; + rect.top = y; + rect.bottom = y + h; + + // TODO: shared struct should make this call smaller + SetViewportHAL( pContext->pShared, &rect, 0.0F, 1.0F ); + } +} +/*===========================================================================*/ +/* This function could be better I guess but I decided just to grab the four*/ +/* components and store then seperately. Makes it easier to use IMHO. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void ClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + pContext->aClear = a; + pContext->bClear = b; + pContext->gClear = g; + pContext->rClear = r; +} +/*===========================================================================*/ +/* This function could be better I guess but I decided just to grab the four*/ +/* components and store then seperately. Makes it easier to use IMHO. */ +/* (is there an echo in here?) */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void SetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + pContext->aCurrent = a; + pContext->bCurrent = b; + pContext->gCurrent = g; + pContext->rCurrent = r; +} +/*===========================================================================*/ +/* */ +/* */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static const char *RendererString( void ) +{ + static char pszRender[64]; + + strcpy( pszRender, "altD3D " ); + + if ( pD3DCurrent->pShared->bHardware ) + strcat( pszRender, "(HW)"); + else + strcat( pszRender, "(SW)"); + + return (const char *)pszRender; +} +/*===========================================================================*/ +/* This function will choose which set of pointers Mesa will use based on */ +/* whether we hard using hardware or software. I have added another set of */ +/* pointers that will do nothing but stop the API from crashing. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void SetupDDPointers( GLcontext *ctx ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + // TODO: write a generic NULL support for the span render. + if ( pContext->pShared && pContext->pShared->bHardware ) + { + ctx->Driver.UpdateState = SetupHWDDPointers; + } + else if ( pContext == pD3DDefault ) + { + ctx->Driver.UpdateState = SetupNULLDDPointers; + } + else + { + ctx->Driver.UpdateState = SetupSWDDPointers; + } +} +/*===========================================================================*/ +/* This function will populate all the Mesa driver hooks. This version of */ +/* hooks will do nothing but support the API when we don't have a valid */ +/* context bound. This is mostly for applications that don't behave right */ +/* and also to help exit as clean as possable when we have a FatalError. */ +/*===========================================================================*/ +/* RETURN: pointer to the specific function. */ +/*===========================================================================*/ +static void SetupNULLDDPointers( GLcontext *ctx ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + /* Initialize all the pointers in the DD struct. Do this whenever */ + /* a new context is made current or we change buffers via set_buffer! */ + ctx->Driver.UpdateState = SetupNULLDDPointers; + + /* State management hooks. */ + ctx->Driver.Color = NULLSetColor; + ctx->Driver.ClearColor = NULLClearColor; + ctx->Driver.Clear = NULLClearBuffers; + ctx->Driver.SetBuffer = NULLSetBuffer; + + /* Window management hooks. */ + ctx->Driver.GetBufferSize = NULLGetBufferSize; + + /* Primitive rendering hooks. */ + ctx->Driver.TriangleFunc = NULL; + ctx->Driver.RenderVB = NULL; + + /* Pixel/span writing functions: */ + ctx->Driver.WriteRGBASpan = NULLWrSpRGBA; + ctx->Driver.WriteRGBSpan = NULLWrSpRGB; + ctx->Driver.WriteMonoRGBASpan = NULLWrSpRGBAMono; + ctx->Driver.WriteRGBAPixels = NULLWrPiRGBA; + ctx->Driver.WriteMonoRGBAPixels = NULLWrPiRGBAMono; + + /* Pixel/span reading functions: */ + ctx->Driver.ReadRGBASpan = NULLReSpRGBA; + ctx->Driver.ReadRGBAPixels = NULLRePiRGBA; + + /* Misc. hooks. */ + ctx->Driver.RendererString = RendererString; +} +/*===========================================================================*/ +/* This function will populate all the Mesa driver hooks. There are two of */ +/* these functions. One if we have hardware support and one is there is only*/ +/* software. These functions will be called by Mesa and by the wgl.c when we*/ +/* have resized (or created) the buffers. The thing is that if a window gets*/ +/* resized we may loose hardware support or gain it... */ +/*===========================================================================*/ +/* RETURN: pointer to the specific function. */ +/*===========================================================================*/ +static void SetupSWDDPointers( GLcontext *ctx ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + /* Initialize all the pointers in the DD struct. Do this whenever */ + /* a new context is made current or we change buffers via set_buffer! */ + ctx->Driver.UpdateState = SetupSWDDPointers; + + /* State management hooks. */ + ctx->Driver.Color = SetColor; + ctx->Driver.ClearColor = ClearColor; + ctx->Driver.Clear = ClearBuffers; + ctx->Driver.SetBuffer = SetBuffer; + + /* Window management hooks. */ + ctx->Driver.GetBufferSize = GetBufferSize; + ctx->Driver.Viewport = SetViewport; + + /* Primitive rendering hooks. */ + ctx->Driver.TriangleFunc = NULL; + ctx->Driver.RenderVB = NULL; + + /* Texture management hooks. */ + + /* Pixel/span writing functions: */ + ctx->Driver.WriteRGBASpan = WSpanRGBA; + ctx->Driver.WriteRGBSpan = WSpanRGB; + ctx->Driver.WriteMonoRGBASpan = WSpanRGBAMono; + ctx->Driver.WriteRGBAPixels = WPixelsRGBA; + ctx->Driver.WriteMonoRGBAPixels = WPixelsRGBAMono; + + /* Pixel/span reading functions: */ + ctx->Driver.ReadRGBASpan = RSpanRGBA; + ctx->Driver.ReadRGBAPixels = RPixelsRGBA; + + /* Misc. hooks. */ + ctx->Driver.Flush = Flush; + ctx->Driver.RendererString = RendererString; +} +/*===========================================================================*/ +/* This function will populate all the Mesa driver hooks. There are two of */ +/* these functions. One if we have hardware support and one is there is only*/ +/* software. These functions will be called by Mesa and by the wgl.c when we*/ +/* have resized (or created) the buffers. The thing is that if a window gets*/ +/* resized we may loose hardware support or gain it... */ +/*===========================================================================*/ +/* RETURN: pointer to the specific function. */ +/*===========================================================================*/ +static void SetupHWDDPointers( GLcontext *ctx ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + /* Initialize all the pointers in the DD struct. Do this whenever */ + /* a new context is made current or we change buffers via set_buffer! */ + ctx->Driver.UpdateState = SetupHWDDPointers; + + /* State management hooks. */ + ctx->Driver.Color = SetColor; + ctx->Driver.ClearColor = ClearColor; + ctx->Driver.Clear = ClearBuffersD3D; + ctx->Driver.SetBuffer = SetBuffer; + + /* Window management hooks. */ + ctx->Driver.GetBufferSize = GetBufferSize; + ctx->Driver.Viewport = SetViewport; + + /* Primitive rendering hooks. */ + ctx->Driver.TriangleFunc = RenderOneTriangle; + ctx->Driver.LineFunc = RenderOneLine; + ctx->Driver.RenderVB = RenderVertexBuffer; + + /* Pixel/span writing functions: */ + ctx->Driver.WriteRGBASpan = WSpanRGBA; + ctx->Driver.WriteRGBSpan = WSpanRGB; + ctx->Driver.WriteMonoRGBASpan = WSpanRGBAMono; + ctx->Driver.WriteRGBAPixels = WPixelsRGBA; + ctx->Driver.WriteMonoRGBAPixels = WPixelsRGBAMono; + + /* Pixel/span reading functions: */ + ctx->Driver.ReadRGBASpan = RSpanRGBA; + ctx->Driver.ReadRGBAPixels = RPixelsRGBA; + + /* Texture management hooks. */ + // ctx->Driver.BindTexture = TextureBind; + ctx->Driver.TexImage = TextureLoad; + ctx->Driver.TexSubImage = TextureSubImage; + + /* Misc. hooks. */ + ctx->Driver.Flush = Flush; + ctx->Driver.RendererString = RendererString; +} +/*===========================================================================*/ +/* This function will release all resources used by the DLL. Every context */ +/* will be clobbered by releaseing all driver desources and then freeing the */ +/* context memory. Most all the work is done in DestroyContext. */ +/*===========================================================================*/ +/* RETURN: TRUE. */ +/*===========================================================================*/ +static BOOL TermOpenGL( HINSTANCE hInst ) +{ + D3DMESACONTEXT *pTmp, + *pNext; + + /* Just incase we are still getting paint msg. */ + MakeCurrent( pD3DDefault ); + + /* Walk the list until we get back to the default context. */ + for( pTmp = pD3DDefault->next; pTmp != pD3DDefault; pTmp = pNext ) + { + pNext = pTmp->next; + DestroyContext( pTmp ); + } + DestroyContext( pD3DDefault ); + + return TRUE; +} +/*===========================================================================*/ +/* This function is an internal function that will clean up all the Mesa */ +/* context bound to this D3D context. Also any D3D stuff that this context */ +/* uses will be unloaded. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +static void DestroyContext( D3DMESACONTEXT *pContext ) +{ + D3DMESACONTEXT *pTmp; + + /* Walk the list until we find the context before this one. */ + for( pTmp = pD3DDefault; pTmp && (pTmp->next != pContext); pTmp = pTmp->next ) + if ( pTmp == pTmp->next ) + break; + + /* If we never found it it must already be deleted. */ + if ( pTmp->next != pContext ) + return; + + /* Make sure we are not using this context. */ + if ( pContext == pD3DCurrent ) + MakeCurrent( pD3DDefault ); + + /* Free the Mesa stuff. */ + if ( pContext->gl_visual ) + { + _mesa_destroy_visual( pContext->gl_visual ); + pContext->gl_visual = NULL; + } + if ( pContext->gl_buffer ) + { + _mesa_destroy_framebuffer( pContext->gl_buffer ); + pContext->gl_buffer = NULL; + } + if ( pContext->gl_ctx ) + { + _mesa_destroy_context( pContext->gl_ctx ); + pContext->gl_ctx = NULL; + } + + /* Now dump the D3D. */ + if ( pContext->pShared ) + TermHAL( pContext->pShared ); + + /* Update the previous context's link. */ + pTmp->next = pContext->next; + + /* Gonzo. */ + FREE( pContext ); +} +/*===========================================================================*/ +/* This function will pull the supplied context away from Win32. Basicly it*/ +/* will remove the hook from the window Proc. */ +/* */ +/* TODO: might want to serialize this stuff... */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +static BOOL UnBindWindow( D3DMESACONTEXT *pContext ) +{ + if ( pContext == NULL ) + return FALSE; + + if ( pContext == pD3DDefault ) + return TRUE; + + /* Make sure we always have a context bound. */ + if ( pContext == pD3DCurrent ) + pD3DCurrent = pD3DDefault; + + SetWindowLong( pContext->pShared->hwnd, GWL_WNDPROC, (LONG)pContext->hOldProc ); + pContext->hOldProc = NULL; + + return TRUE; +} +/*===========================================================================*/ +/* There are two cases that allow for a faster clear when we know that the */ +/* whole buffer is cleared and that there is no clipping. */ +/*===========================================================================*/ +/* RETURN: the original mask with the bits cleared that represents the buffer* +/* or buffers we just cleared. */ +/*===========================================================================*/ +GLbitfield ClearBuffersD3D( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DWORD dwFlags = 0; + + if ( mask & GL_COLOR_BUFFER_BIT ) + { + dwFlags |= D3DCLEAR_TARGET; + mask &= ~GL_COLOR_BUFFER_BIT; + } + if ( mask & GL_DEPTH_BUFFER_BIT ) + { + dwFlags |= D3DCLEAR_ZBUFFER; + mask &= ~GL_DEPTH_BUFFER_BIT; + } + if ( dwFlags == 0 ) + return mask; + + ClearHAL( pContext->pShared, + dwFlags, + all, + x, y, + width, height, + ((pContext->aClear<<24) | (pContext->rClear<<16) | (pContext->gClear<<8) | (pContext->bClear)), + ctx->Depth.Clear, + 0 ); + + return mask; +} + + + +/*===========================================================================*/ +/* TEXTURE MANAGER: ok here is how I did textures. Mesa-3.0 will keep track*/ +/* of all the textures for us. So this means that at anytime we can go to */ +/* the Mesa context and get the current texture. With this in mind this is */ +/* what I did. I really don't care about what textures get or are loaded */ +/* until I actually have to draw a tri that is textured. At this point I */ +/* must have the texture so I demand the texture by destorying all other */ +/* texture surfaces if need be and load the current one. This allows for the*/ +/* best preformance on low memory cards as time is not wasted loading and */ +/* unload textures. */ +/*===========================================================================*/ + + + + + +/*===========================================================================*/ +/* TextureLoad will try and create a D3D surface from the supplied texture */ +/* object if its level 0 (first). The surface will be fully filled with the */ +/* texture. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void TextureLoad( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint internalFormat, const struct gl_texture_image *image ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + /* TODO: only doing first LOD. */ + if ( (ctx->DriverCtx == NULL) || (level != 0) ) + return; + + CreateTMgrHAL( pContext->pShared, + tObj->Name, + level, + tObj->Image[level]->Format, + (RECT *)NULL, + tObj->Image[level]->Width, + tObj->Image[level]->Height, + TM_ACTION_LOAD, + (void *)tObj->Image[level]->Data ); +} +/*===========================================================================*/ +/* TextureBind make sure that the texture is on the card. Thats it. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void TextureBind( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + + /* TODO: only doing first LOD. */ + if ( (tObj->Image[0] == NULL) || (ctx->DriverCtx == NULL) ) + return; + + CreateTMgrHAL( pContext->pShared, + tObj->Name, + 0, + tObj->Image[0]->Format, + (RECT *)NULL, + tObj->Image[0]->Width, + tObj->Image[0]->Height, + TM_ACTION_BIND, + (void *)tObj->Image[0]->Data ); +} +/*===========================================================================*/ +/* TextureSubImage will make sure that the texture being updated is updated */ +/* if its on the card. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void TextureSubImage( GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLint internalFormat, const struct gl_texture_image *image ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + RECT rect; + + /* TODO: only doing first LOD. */ + if ( (ctx->DriverCtx == NULL) || (level > 0) ) + return; + + /* Create a dirty rectangle structure. */ + rect.left = xoffset; + rect.right = xoffset + width; + rect.top = yoffset; + rect.bottom = yoffset + height; + + CreateTMgrHAL( pContext->pShared, + tObj->Name, + 0, + tObj->Image[0]->Format, + &rect, + tObj->Image[0]->Width, + tObj->Image[0]->Height, + TM_ACTION_UPDATE, + (void *)tObj->Image[0]->Data ); +} + --- mesa-7.2.orig/src/mesa/drivers/d3d/DDrawPROCS.c +++ mesa-7.2/src/mesa/drivers/d3d/DDrawPROCS.c @@ -0,0 +1,399 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DMesa.h" +/*===========================================================================*/ +/* This call will clear the render surface using the pixel info built from */ +/* the surface at creation time. The call uses Lock/Unlock to access the */ +/* surface. The call also special cases a full clear or a dirty rectangle. */ +/* Finally the call returns the new clear mask that reflects that the color */ +/* buffer was cleared. */ +/*===========================================================================*/ +/* RETURN: the original mask with the bits cleared that represents the buffer*/ +/* or buffers we just cleared. */ +/*===========================================================================*/ +GLbitfield ClearBuffers( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer, + *pScanLine; + int index, + index2; + DWORD dwColor; + + if ( mask & GL_COLOR_BUFFER_BIT ) + { + /* Lock the surface to get the surface pointer. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + /* Solve the color once only. */ + dwColor = ( ((DWORD)((float)pContext->rClear * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)pContext->gClear * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)pContext->bClear * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + + if ( all ) + { + for( index = 0, pScanLine = (UCHAR *)pddsd2->lpSurface; index < pContext->pShared->dwHeight; index++, pScanLine += pddsd2->lPitch ) + for( pBuffer = pScanLine, index2 = 0; index2 < pContext->pShared->dwWidth; index2++, pBuffer += pContext->pShared->pixel.cb ) + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + else + { + pScanLine = ((UCHAR *)pddsd2->lpSurface) + + ( (FLIP( pContext->pShared->dwHeight, (y+height)) * pddsd2->lPitch) + (x * pContext->pShared->pixel.cb) ); + + for( index = 0; index < height; index++, pScanLine += pddsd2->lPitch ) + { + for( index2 = 0, pBuffer = pScanLine; index2 < width; index2++, pBuffer += pContext->pShared->pixel.cb ) + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + + UnlockHAL( pContext->pShared, TRUE ); + } + + return (mask & ~GL_COLOR_BUFFER_BIT); +} +/*===========================================================================*/ +/* This proc (as all others) has been written for the general case. I use */ +/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ +/* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void WSpanRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer; + int index; + DWORD dwColor; + + /* Get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + /* Find the start of the span. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb); + + if ( mask ) + { + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + { + if ( mask[index] ) + { + /* Pack the color components. */ + dwColor = ( ((DWORD)((float)rgb[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)rgb[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)rgb[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + } + else + { + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + { + /* Pack the color components. */ + dwColor = ( ((DWORD)((float)rgb[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)rgb[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)rgb[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} +/*===========================================================================*/ +/* This proc (as all others) has been written for the general case. I use */ +/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ +/* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void WSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer; + int index; + DWORD dwColor; + + /* Get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + /* Find the start of the span. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb); + + if ( mask ) + { + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + { + if ( mask[index] ) + { + /* Pack the color components. */ + dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + } + else + { + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + { + /* Pack the color components. */ + dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} +/*===========================================================================*/ +/* This proc (as all others) has been written for the general case. I use */ +/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ +/* Screen render surface uses. The color is solved once from the current */ +/* color components. The alpha is ignored as Mesa is doing it in SW. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void WSpanRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer; + int index; + DWORD dwColor; + + /* Lock the surface to get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + /* Solve the color once only. (no alpha) */ + dwColor = ( ((DWORD)((float)pContext->rCurrent * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)pContext->gCurrent * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)pContext->bCurrent * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + + /* Find the start of the span. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb); + + if ( mask ) + { + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + if ( mask[index] ) + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + else + { + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} +/*===========================================================================*/ +/* This proc (as all others) has been written for the general case. I use */ +/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ +/* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void WPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer; + int index; + DWORD dwColor; + + /* Get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + if ( mask ) + { + for( index = 0; index < n; index++ ) + { + if ( mask[index] ) + { + /* Pack the color components. */ + dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + + /* Find the pixel. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + } + else + { + for( index = 0; index < n; index++ ) + { + /* Pack the color components. */ + dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + + /* Find the pixel. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} +/*===========================================================================*/ +/* This proc (as all others) has been written for the general case. I use */ +/* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */ +/* Screen render surface uses. The color is solved once from the current */ +/* color components. The alpha is ignored as Mesa is doing it in SW. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void WPixelsRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer; + int index; + DWORD dwColor; + + /* Get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + /* Solve the color once only. I don't uses the alpha. */ + dwColor = ( ((DWORD)((float)pContext->rCurrent * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift ); + dwColor |= ( ((DWORD)((float)pContext->gCurrent * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift ); + dwColor |= ( ((DWORD)((float)pContext->bCurrent * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift ); + + if ( mask ) + { + /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ + for( index = 0; index < n; index++ ) + { + if ( mask[index] ) + { + /* Find the pixel. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + } + else + { + /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ + for( index = 0; index < n; index++ ) + { + /* Find the pixel. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb); + memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb ); + } + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} +/*===========================================================================*/ +/* This proc isn't written for speed rather its to handle the general case. */ +/* I grab each pixel from the surface and unpack the info using the PIXELINFO*/ +/* structure that was generated from the OffScreen surface pixelformat. The */ +/* function will not fill in the alpha value as Mesa I have Mesa allocate its*/ +/* own alpha channel when the context was created. I did this as I didn't */ +/* feel that it was worth the effort to try and get HW to work (bus bound). */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void RSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + UCHAR *pBuffer; + int index; + DWORD *pdwColor; + + /* Get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + /* Find the start of the span. Invert y for Windows. */ + pBuffer = (UCHAR *)pddsd2->lpSurface + + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + + (x*pContext->pShared->pixel.cb); + + /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ + for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb ) + { + pdwColor = (DWORD *)pBuffer; + rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale); + rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale); + rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale); + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} +/*===========================================================================*/ +/* This proc isn't written for speed rather its to handle the general case. */ +/* I grab each pixel from the surface and unpack the info using the PIXELINFO*/ +/* structure that was generated from the OffScreen surface pixelformat. The */ +/* function will not fill in the alpha value as Mesa I have Mesa allocate its*/ +/* own alpha channel when the context was created. I did this as I didn't */ +/* feel that it was worth the effort to try and get HW to work (bus bound). */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void RPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DDSURFACEDESC2 *pddsd2; + int index; + DWORD *pdwColor; + + /* Get the surface pointer and the pitch. */ + pddsd2 = LockHAL( pContext->pShared, TRUE ); + + if ( mask ) + { + /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ + for( index = 0; index < n; index++ ) + { + if ( mask[index] ) + { + /* Find the start of the pixel. Invert y for Windows. */ + pdwColor = (DWORD *)((UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb)); + rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale); + rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale); + rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale); + } + } + } + else + { + /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */ + for( index = 0; index < n; index++ ) + { + /* Find the start of the pixel. Invert y for Windows. */ + pdwColor = (DWORD *)((UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb)); + rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale); + rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale); + rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale); + } + } + + /* Giver back. */ + UnlockHAL( pContext->pShared, TRUE ); +} --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DMESA.H +++ mesa-7.2/src/mesa/drivers/d3d/D3DMESA.H @@ -0,0 +1,84 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef D3D_MESA_H +#define D3D_MESA_H +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include +#include +#include +#include "matrix.h" +#include "context.h" +#include "mtypes.h" +#include "vb.h" +#include "D3DShared.h" +#include "Debug.h" +#include "NULLProcs.h" +/*===========================================================================*/ +/* Macros. */ +/*===========================================================================*/ +#define FLIP(h,y) (h-y) +/*===========================================================================*/ +/* Magic numbers. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +struct __extensions__ +{ + PROC proc; + char *name; +}; + +typedef GLbitfield (*ClearPROC)( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height ); +typedef void (*WSpanRGBPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] ); +typedef void (*WSpanRGBAPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] ); +typedef void (*WSpanRGBAMonoPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] ); +typedef void (*WPixelsRGBAPROC)( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] ); +typedef void (*WPixelsRGBAMonoPROC)( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] ); +typedef void (*RSpanRGBAPROC)( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] ); +typedef void (*RPixelsRGBAPROC)( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ); + +typedef struct D3D_mesa_context +{ + PMESAD3DSHARED pShared; + + GLcontext *gl_ctx; /* The core GL/Mesa context */ + GLvisual *gl_visual; /* Describes the buffers */ + GLframebuffer *gl_buffer; /* Depth, stencil, accum, etc buffers */ + + HDC hdc; + WNDPROC hOldProc; + + UCHAR rClear, /* Current clear colors. */ + gClear, + bClear, + aClear, + rCurrent, /* Current rendering colors. */ + gCurrent, + bCurrent, + aCurrent; + + struct D3D_mesa_context *next; + +} D3DMESACONTEXT, *PD3DMESACONTEXT; +/*===========================================================================*/ +/* Extern function prototypes. */ +/*===========================================================================*/ +extern void gl_Viewport( GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height ); +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ +extern D3DTLVERTEX D3DTLVertices[(VB_MAX*6)]; + +#endif + --- mesa-7.2.orig/src/mesa/drivers/d3d/MAKEFILE +++ mesa-7.2/src/mesa/drivers/d3d/MAKEFILE @@ -0,0 +1,101 @@ +############################################################################## +# +# Mesa-3.0 Makefile for DirectX 6 Driver +# +# By Leigh McRae +# +# http://www.altsoftware.com/ +# +# Copyright (c) 1999-1998 alt.software inc. All Rights Reserved +############################################################################## +NAME= +TARGET= WGL Driver (D3DHAL) + +D3D_DIR=$(MAKEDIR)\D3D +TARGET_DIR=e:\WinNT\System32 +TEMP_DIR=c:\Temp + +SPACE=- +LINKER=link.exe + +INCLUDE=$(SDKROOT)\include;$(INCLUDE) +LIB=$(SDKROOT)\lib;$(LIB) +############################################################################## +CFLAGS = /c /nologo /W1 /G5 /I..\ /I..\..\Include \ + /D "_WIN32" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "MESAD3D" +CPPFLAGS= /c /nologo /W1 /G5 /I..\ /I..\..\Include \ + /D "_WIN32" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "MESAD3D" + +!IF "$(DEBUG)" == "1" + +CFLAGS = /MTd /Od /Z7 /Yd /D "_DEBUG" /D "D3D_DEBUG" $(CFLAGS) +CPPFLAGS = /MTd /Od /Z7 /Yd /D "_DEBUG" /D "D3D_DEBUG" $(CPPFLAGS) +BUILD_TYPE=debug + +!ELSE + +CFLAGS = /MT /Ox /D "NDEBUG" $(CFLAGS) +CPPFLAGS = /MT /Ox /D "NDEBUG" $(CPPFLAGS) +BUILD_TYPE=release + +!ENDIF +############################################################################## +SRCS_WGL = wgl.c D3Dvbrender.c DDrawPROCS.c NULLProcs.c Debug.c +SRCS_HAL = D3DInit.cpp D3DRaster.cpp D3DTextureMgr.cpp D3DUtils.cpp D3DCaps.cpp +OBJS_WGL = $(SRCS_WGL:.c=.obj) +OBJS_HAL = $(SRCS_HAL:.cpp=.obj) + +WINLIBS = kernel32.lib user32.lib gdi32.lib oldnames.lib +DXLIBS = +LIBS = $(WINLIBS) $(DXLIBS) +############################################################################### +# Primary Targets # +############################################################################### + +default: header WGL HAL footer + +all: default + +WGL : $(OBJS_WGL) + +HAL : $(OBJS_HAL) + +install : forceit + @echo $(SPACE) + @echo ======================================== + @echo Install files created. + @echo ======================================== + + +############################################################################### +# Secondary Targets # +############################################################################### + +clean: + @echo ======================================== + @echo Cleaning $(TARGET) + @del *.obj + @del *.dep + @del *.exp + @del *.ncb + @del *.plg + @del *.lib + @echo ======================================== + +header: + @echo ============================================================ + @echo Building $(TARGET) ($(BUILD_TYPE) version) + @echo ============================================================ + @echo $(SPACE) + +footer: + @echo $(SPACE) + @echo ============================================================ + @echo DONE building $(TARGET) ($(BUILD_TYPE) version) + @echo ============================================================ + +forceit: + + + + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DUTILS.CPP +++ mesa-7.2/src/mesa/drivers/d3d/D3DUTILS.CPP @@ -0,0 +1,638 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DHAL.h" +/*===========================================================================*/ +/* Local only functions. */ +/*===========================================================================*/ +static int CountTrailingZeros( DWORD dwMask ); +/*===========================================================================*/ +/* This function is used to get the pointer to the surface and the pitch for*/ +/* the scanline rendering functions. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" DDSURFACEDESC2 *LockHAL( PMESAD3DSHARED pShared, BOOL bBack ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + static DDSURFACEDESC2 ddsd2; + HRESULT rc; + + DPF(( DBG_FUNC, "LockHAL();" )); + + /* Set the request structure up first. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof(DDSURFACEDESC2); + + /* Make sure we have enough info. */ + if ( pHAL ) + { + rc = pHAL->lpDDSRender->Lock( NULL, &ddsd2, DDLOCK_WAIT, NULL ); + if ( FAILED(rc) ) + { + RIP( pHAL, "Lock (RENDER) ->", ErrorStringD3D(rc) ); + } + } + + return &ddsd2; +} +/*===========================================================================*/ +/* This is just a simple wrapper. I probably don't need to do any error */ +/* checking as the Lock must have worked inorder to get here... */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void UnlockHAL( PMESAD3DSHARED pShared, BOOL bBack ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + HRESULT rc; + + DPF(( DBG_FUNC, "UnlockHAL();" )); + + /* Make sure we have enough info. */ + if ( pHAL ) + { + rc = pHAL->lpDDSRender->Unlock( NULL ); + if ( FAILED(rc) ) + { + RIP( pHAL, "Unlock (RENDER) ->", ErrorStringD3D(rc) ); + } + } +} +/*===========================================================================*/ +/* This function will track the main/Primary window that will be used as the*/ +/* target for the Blt in SwapBuffers. As a side effect the call will check */ +/* to see if the primary surface is the same size and position as the screen.*/ +/* If they are the same size we will call it fullscreen... */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void UpdateScreenPosHAL( PMESAD3DSHARED pShared ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + POINT pt; + DWORD dwWidth, dwHeight; + + DPF(( DBG_FUNC, "UpdateScreenPosHAL();" )); + + /* Make sure we have enough info. */ + if ( pHAL != NULL ) + { + /* Update the windows screen position. */ + GetClientRect( pShared->hwnd, &pShared->rectW ); + pt.x = pt.y = 0; + ClientToScreen( pShared->hwnd, &pt ); + OffsetRect( &pShared->rectW, pt.x, pt.y); + + /* Compare the primary to the screen. */ + dwWidth = GetSystemMetrics( SM_CXSCREEN ); + dwHeight = GetSystemMetrics( SM_CYSCREEN ); + if ( (pShared->rectW.left > 0) || (pShared->rectW.top > 0) || + (pShared->rectW.right > dwWidth) || (pShared->rectW.bottom > dwHeight) ) + pShared->bWindow = TRUE; + else + pShared->bWindow = FALSE; + } +} +/*===========================================================================*/ +/* This function will fill in the pixel info structure defined in D3Dshared.*/ +/* Basicly it will take a DirectDraw pixelformat structure and make scaling */ +/* values that will convert from 8bit channels to whatever the supplied ddpf */ +/* uses. Also we will generate shift values that will be used to get move */ +/* each component of the pixel into place. */ +/* I have now added a special case for a 1bit alpha channel. If I find a 1b*/ +/* alpha then I will set the scale to -1.0 which should be unique. Later I */ +/* can check the alpha scale value too see if its -1.0 and thus handle it. I*/ +/* was finding that the case was not working tom my advantage so this is my */ +/* HACK for the day. As a TODO I should work on this... */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void Solve8BitChannelPixelFormat( DDPIXELFORMAT *pddpf, PPIXELINFO pPixel ) +{ + DPF(( DBG_FUNC, "Solve8BitChannelPixelFromat();" )); + + memset( pPixel, 0, sizeof(PPIXELINFO) ); + + /* Check too see if the color space is valid in the PF. */ + if ( pddpf->dwFlags & DDPF_RGB ) + { + /* Solve the red stuff. */ + pPixel->dwRMask = pddpf->dwRBitMask; + pPixel->rShift = CountTrailingZeros( pPixel->dwRMask ); + pPixel->rScale = (float)0.00392156 * (float)(pPixel->dwRMask >> pPixel->rShift); + + /* Solve the green thingy's. */ + pPixel->dwGMask = pddpf->dwGBitMask; + pPixel->gShift = CountTrailingZeros( pPixel->dwGMask ); + pPixel->gScale = (float)0.00392156 * (float)(pPixel->dwGMask >> pPixel->gShift); + + /* Solve the blues. */ + pPixel->dwBMask = pddpf->dwBBitMask; + pPixel->bShift = CountTrailingZeros( pddpf->dwBBitMask ); + pPixel->bScale = (float)0.00392156 * (float)(pddpf->dwBBitMask >> pPixel->bShift); + } + + /* Do the alpha channel if there is one. */ + if ( pddpf->dwFlags & DDPF_ALPHAPIXELS ) + { + pPixel->dwAMask = pddpf->dwRGBAlphaBitMask; + pPixel->aShift = CountTrailingZeros( pPixel->dwAMask ); + + /* Special case a 1bit alpha. */ + if ( (pPixel->dwAMask >> pPixel->aShift) == 1 ) + pPixel->aScale = -1.0; + else + pPixel->aScale = (float)0.00392156 * (float)(pPixel->dwAMask >> pPixel->aShift); + } + + /* Get the size of the pixel in bytes. Should work as dwRGBBitCount is in a union. */ + pPixel->cb = pddpf->dwRGBBitCount / 8; +} +/*===========================================================================*/ +/* See RETURN :) */ +/*===========================================================================*/ +/* RETURN: number of contiguous zeros starting from the right. */ +/*===========================================================================*/ +static int CountTrailingZeros( DWORD dwMask ) +{ + DWORD Mask; + + if ( dwMask == 0 ) + return 32; + + /* Can't take credit for this one! */ + Mask = dwMask & -(int)dwMask; + return ((Mask & 0xFFFF0000)!=0) << 4 + | ((Mask & 0xFF00FF00)!=0) << 3 + | ((Mask & 0xF0F0F0F0)!=0) << 2 + | ((Mask & 0xCCCCCCCC)!=0) << 1 + | ((Mask & 0xAAAAAAAA)!=0); +} +/*===========================================================================*/ +/* This function will convert the DDraw error code to its macro string. The*/ +/* returned pointer is static so you need not worry about memory managemnet */ +/* but the error message gets written over from call to call... */ +/*===========================================================================*/ +/* RETURN: pointer to the single static buffer that hold the error message. */ +/*===========================================================================*/ +char *ErrorStringD3D( HRESULT hr ) +{ + static char errorString[128]; + + switch( hr ) + { + case DDERR_ALREADYINITIALIZED: + strcpy( errorString, "DDERR_ALREADYINITIALIZED" ); + break; + + case DDERR_CANNOTATTACHSURFACE: + strcpy( errorString, "DDERR_CANNOTATTACHSURFACE" ); + break; + + case DDERR_CANNOTDETACHSURFACE: + strcpy( errorString, "DDERR_CANNOTDETACHSURFACE" ); + break; + + case DDERR_CURRENTLYNOTAVAIL: + strcpy( errorString, "DDERR_CURRENTLYNOTAVAIL" ); + break; + + case DDERR_EXCEPTION: + strcpy( errorString, "DDERR_EXCEPTION" ); + break; + + case DDERR_GENERIC: + strcpy( errorString, "DDERR_GENERIC" ); + break; + + case DDERR_HEIGHTALIGN: + strcpy( errorString, "DDERR_HEIGHTALIGN" ); + break; + + case DDERR_INCOMPATIBLEPRIMARY: + strcpy( errorString, "DDERR_INCOMPATIBLEPRIMARY" ); + break; + + case DDERR_INVALIDCAPS: + strcpy( errorString, "DDERR_INVALIDCAPS" ); + break; + + case DDERR_INVALIDCLIPLIST: + strcpy( errorString, "DDERR_INVALIDCLIPLIST" ); + break; + + case DDERR_INVALIDMODE: + strcpy( errorString, "DDERR_INVALIDMODE" ); + break; + + case DDERR_INVALIDOBJECT: + strcpy( errorString, "DDERR_INVALIDOBJECT" ); + break; + + case DDERR_INVALIDPARAMS: + strcpy( errorString, "DDERR_INVALIDPARAMS" ); + break; + + case DDERR_INVALIDPIXELFORMAT: + strcpy( errorString, "DDERR_INVALIDPIXELFORMAT" ); + break; + + case DDERR_INVALIDRECT: + strcpy( errorString, "DDERR_INVALIDRECT" ); + break; + + case DDERR_LOCKEDSURFACES: + strcpy( errorString, "DDERR_LOCKEDSURFACES" ); + break; + + case DDERR_NO3D: + strcpy( errorString, "DDERR_NO3D" ); + break; + + case DDERR_NOALPHAHW: + strcpy( errorString, "DDERR_NOALPHAHW" ); + break; + + case DDERR_NOCLIPLIST: + strcpy( errorString, "DDERR_NOCLIPLIST" ); + break; + + case DDERR_NOCOLORCONVHW: + strcpy( errorString, "DDERR_NOCOLORCONVHW" ); + break; + + case DDERR_NOCOOPERATIVELEVELSET: + strcpy( errorString, "DDERR_NOCOOPERATIVELEVELSET" ); + break; + + case DDERR_NOCOLORKEY: + strcpy( errorString, "DDERR_NOCOLORKEY" ); + break; + + case DDERR_NOCOLORKEYHW: + strcpy( errorString, "DDERR_NOCOLORKEYHW" ); + break; + + case DDERR_NODIRECTDRAWSUPPORT: + strcpy( errorString, "DDERR_NODIRECTDRAWSUPPORT" ); + break; + + case DDERR_NOEXCLUSIVEMODE: + strcpy( errorString, "DDERR_NOEXCLUSIVEMODE" ); + break; + + case DDERR_NOFLIPHW: + strcpy( errorString, "DDERR_NOFLIPHW" ); + break; + + case DDERR_NOGDI: + strcpy( errorString, "DDERR_NOGDI" ); + break; + + case DDERR_NOMIRRORHW: + strcpy( errorString, "DDERR_NOMIRRORHW" ); + break; + + case DDERR_NOTFOUND: + strcpy( errorString, "DDERR_NOTFOUND" ); + break; + + case DDERR_NOOVERLAYHW: + strcpy( errorString, "DDERR_NOOVERLAYHW" ); + break; + + case DDERR_OVERLAPPINGRECTS: + strcpy( errorString, "DDERR_OVERLAPPINGRECTS" ); + break; + + case DDERR_NORASTEROPHW: + strcpy( errorString, "DDERR_NORASTEROPHW" ); + break; + + case DDERR_NOROTATIONHW: + strcpy( errorString, "DDERR_NOROTATIONHW" ); + break; + + case DDERR_NOSTRETCHHW: + strcpy( errorString, "DDERR_NOSTRETCHHW" ); + break; + + case DDERR_NOT4BITCOLOR: + strcpy( errorString, "DDERR_NOT4BITCOLOR" ); + break; + + case DDERR_NOT4BITCOLORINDEX: + strcpy( errorString, "DDERR_NOT4BITCOLORINDEX" ); + break; + + case DDERR_NOT8BITCOLOR: + strcpy( errorString, "DDERR_NOT8BITCOLOR" ); + break; + + case DDERR_NOTEXTUREHW: + strcpy( errorString, "DDERR_NOTEXTUREHW" ); + break; + + case DDERR_NOVSYNCHW: + strcpy( errorString, "DDERR_NOVSYNCHW" ); + break; + + case DDERR_NOZBUFFERHW: + strcpy( errorString, "DDERR_NOZBUFFERHW" ); + break; + + case DDERR_NOZOVERLAYHW: + strcpy( errorString, "DDERR_NOZOVERLAYHW" ); + break; + + case DDERR_OUTOFCAPS: + strcpy( errorString, "DDERR_OUTOFCAPS" ); + break; + + case DDERR_OUTOFMEMORY: + strcpy( errorString, "DDERR_OUTOFMEMORY" ); + break; + + case DDERR_OUTOFVIDEOMEMORY: + strcpy( errorString, "DDERR_OUTOFVIDEOMEMORY" ); + break; + + case DDERR_OVERLAYCANTCLIP: + strcpy( errorString, "DDERR_OVERLAYCANTCLIP" ); + break; + + case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: + strcpy( errorString, "DDERR_OVERLAYCOLORKEYONLYONEACTIVE" ); + break; + + case DDERR_PALETTEBUSY: + strcpy( errorString, "DDERR_PALETTEBUSY" ); + break; + + case DDERR_COLORKEYNOTSET: + strcpy( errorString, "DDERR_COLORKEYNOTSET" ); + break; + + case DDERR_SURFACEALREADYATTACHED: + strcpy( errorString, "DDERR_SURFACEALREADYATTACHED" ); + break; + + case DDERR_SURFACEALREADYDEPENDENT: + strcpy( errorString, "DDERR_SURFACEALREADYDEPENDENT" ); + break; + + case DDERR_SURFACEBUSY: + strcpy( errorString, "DDERR_SURFACEBUSY" ); + break; + + case DDERR_CANTLOCKSURFACE: + strcpy( errorString, "DDERR_CANTLOCKSURFACE" ); + break; + + case DDERR_SURFACEISOBSCURED: + strcpy( errorString, "DDERR_SURFACEISOBSCURED" ); + break; + + case DDERR_SURFACELOST: + strcpy( errorString, "DDERR_SURFACELOST" ); + break; + + case DDERR_SURFACENOTATTACHED: + strcpy( errorString, "DDERR_SURFACENOTATTACHED" ); + break; + + case DDERR_TOOBIGHEIGHT: + strcpy( errorString, "DDERR_TOOBIGHEIGHT" ); + break; + + case DDERR_TOOBIGSIZE: + strcpy( errorString, "DDERR_TOOBIGSIZE" ); + break; + + case DDERR_TOOBIGWIDTH: + strcpy( errorString, "DDERR_TOOBIGWIDTH" ); + break; + + case DDERR_UNSUPPORTED: + strcpy( errorString, "DDERR_UNSUPPORTED" ); + break; + + case DDERR_UNSUPPORTEDFORMAT: + strcpy( errorString, "DDERR_UNSUPPORTEDFORMAT" ); + break; + + case DDERR_UNSUPPORTEDMASK: + strcpy( errorString, "DDERR_UNSUPPORTEDMASK" ); + break; + + case DDERR_INVALIDSTREAM: + strcpy( errorString, "DDERR_INVALIDSTREAM" ); + break; + + case DDERR_VERTICALBLANKINPROGRESS: + strcpy( errorString, "DDERR_VERTICALBLANKINPROGRESS" ); + break; + + case DDERR_WASSTILLDRAWING: + strcpy( errorString, "DDERR_WASSTILLDRAWING" ); + break; + + case DDERR_XALIGN: + strcpy( errorString, "DDERR_XALIGN" ); + break; + + case DDERR_INVALIDDIRECTDRAWGUID: + strcpy( errorString, "DDERR_INVALIDDIRECTDRAWGUID" ); + break; + + case DDERR_DIRECTDRAWALREADYCREATED: + strcpy( errorString, "DDERR_DIRECTDRAWALREADYCREATED" ); + break; + + case DDERR_NODIRECTDRAWHW: + strcpy( errorString, "DDERR_NODIRECTDRAWHW" ); + break; + + case DDERR_PRIMARYSURFACEALREADYEXISTS: + strcpy( errorString, "DDERR_PRIMARYSURFACEALREADYEXISTS" ); + break; + + case DDERR_NOEMULATION: + strcpy( errorString, "DDERR_NOEMULATION" ); + break; + + case DDERR_REGIONTOOSMALL: + strcpy( errorString, "DDERR_REGIONTOOSMALL" ); + break; + + case DDERR_CLIPPERISUSINGHWND: + strcpy( errorString, "DDERR_CLIPPERISUSINGHWND" ); + break; + + case DDERR_NOCLIPPERATTACHED: + strcpy( errorString, "DDERR_NOCLIPPERATTACHED" ); + break; + + case DDERR_NOHWND: + strcpy( errorString, "DDERR_NOHWND" ); + break; + + case DDERR_HWNDSUBCLASSED: + strcpy( errorString, "DDERR_HWNDSUBCLASSED" ); + break; + + case DDERR_HWNDALREADYSET: + strcpy( errorString, "DDERR_HWNDALREADYSET" ); + break; + + case DDERR_NOPALETTEATTACHED: + strcpy( errorString, "DDERR_NOPALETTEATTACHED" ); + break; + + case DDERR_NOPALETTEHW: + strcpy( errorString, "DDERR_NOPALETTEHW" ); + break; + + case DDERR_BLTFASTCANTCLIP: + strcpy( errorString, "DDERR_BLTFASTCANTCLIP" ); + break; + + case DDERR_NOBLTHW: + strcpy( errorString, "DDERR_NOBLTHW" ); + break; + + case DDERR_NODDROPSHW: + strcpy( errorString, "DDERR_NODDROPSHW" ); + break; + + case DDERR_OVERLAYNOTVISIBLE: + strcpy( errorString, "DDERR_OVERLAYNOTVISIBLE" ); + break; + + case DDERR_NOOVERLAYDEST: + strcpy( errorString, "DDERR_NOOVERLAYDEST" ); + break; + + case DDERR_INVALIDPOSITION: + strcpy( errorString, "DDERR_INVALIDPOSITION" ); + break; + + case DDERR_NOTAOVERLAYSURFACE: + strcpy( errorString, "DDERR_NOTAOVERLAYSURFACE" ); + break; + + case DDERR_EXCLUSIVEMODEALREADYSET: + strcpy( errorString, "DDERR_EXCLUSIVEMODEALREADYSET" ); + break; + + case DDERR_NOTFLIPPABLE: + strcpy( errorString, "DDERR_NOTFLIPPABLE" ); + break; + + case DDERR_CANTDUPLICATE: + strcpy( errorString, "DDERR_CANTDUPLICATE" ); + break; + + case DDERR_NOTLOCKED: + strcpy( errorString, "DDERR_NOTLOCKED" ); + break; + + case DDERR_CANTCREATEDC: + strcpy( errorString, "DDERR_CANTCREATEDC" ); + break; + + case DDERR_NODC: + strcpy( errorString, "DDERR_NODC" ); + break; + + case DDERR_WRONGMODE: + strcpy( errorString, "DDERR_WRONGMODE" ); + break; + + case DDERR_IMPLICITLYCREATED: + strcpy( errorString, "DDERR_IMPLICITLYCREATED" ); + break; + + case DDERR_NOTPALETTIZED: + strcpy( errorString, "DDERR_NOTPALETTIZED" ); + break; + + case DDERR_UNSUPPORTEDMODE: + strcpy( errorString, "DDERR_UNSUPPORTEDMODE" ); + break; + + case DDERR_NOMIPMAPHW: + strcpy( errorString, "DDERR_NOMIPMAPHW" ); + break; + + case DDERR_INVALIDSURFACETYPE: + strcpy( errorString, "DDERR_INVALIDSURFACETYPE" ); + break; + + case DDERR_NOOPTIMIZEHW: + strcpy( errorString, "DDERR_NOOPTIMIZEHW" ); + break; + + case DDERR_NOTLOADED: + strcpy( errorString, "DDERR_NOTLOADED" ); + break; + + case DDERR_NOFOCUSWINDOW: + strcpy( errorString, "DDERR_NOFOCUSWINDOW" ); + break; + + case DDERR_DCALREADYCREATED: + strcpy( errorString, "DDERR_DCALREADYCREATED" ); + break; + + case DDERR_NONONLOCALVIDMEM: + strcpy( errorString, "DDERR_NONONLOCALVIDMEM" ); + break; + + case DDERR_CANTPAGELOCK: + strcpy( errorString, "DDERR_CANTPAGELOCK" ); + break; + + case DDERR_CANTPAGEUNLOCK: + strcpy( errorString, "DDERR_CANTPAGEUNLOCK" ); + break; + + case DDERR_NOTPAGELOCKED: + strcpy( errorString, "DDERR_NOTPAGELOCKED" ); + break; + + case DDERR_MOREDATA: + strcpy( errorString, "DDERR_MOREDATA" ); + break; + + case DDERR_EXPIRED: + strcpy( errorString, "DDERR_EXPIRED" ); + break; + + case DDERR_VIDEONOTACTIVE: + strcpy( errorString, "DDERR_VIDEONOTACTIVE" ); + break; + + case DDERR_DEVICEDOESNTOWNSURFACE: + strcpy( errorString, "DDERR_DEVICEDOESNTOWNSURFACE" ); + break; + + case DDERR_NOTINITIALIZED: + strcpy( errorString, "DDERR_NOTINITIALIZED" ); + break; + + default: + strcpy( errorString, "" ); + break; + } + + return &errorString[0]; +} --- mesa-7.2.orig/src/mesa/drivers/d3d/NullProcs.c +++ mesa-7.2/src/mesa/drivers/d3d/NullProcs.c @@ -0,0 +1,49 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef NULL_MESA_PROCS_INC +#define NULL_MESA_PROCS_INC +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include "matrix.h" +#include "context.h" +#include "mtypes.h" +#include "vb.h" +/*===========================================================================*/ +/* Macros. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Magic numbers. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +void NULLSetColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); +void NULLClearColor( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a ); +GLboolean NULLSetBuffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bit ); +void NULLGetBufferSize( GLcontext *ctx, GLuint *width, GLuint *height ); +GLbitfield NULLClearBuffers( GLcontext *ctx, GLbitfield m, GLboolean a, GLint x, GLint y, GLint w, GLint h ); +void NULLWrSpRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][3], const GLubyte m[] ); +void NULLWrSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte r[][4], const GLubyte m[] ); +void NULLWrSpRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte m[] ); +void NULLWrPiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte r[][4], const GLubyte m[] ); +void NULLWrPiRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte m[] ); +void NULLReSpRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte r[][4] ); +void NULLRePiRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte r[][4], const GLubyte m[] ); +/*===========================================================================*/ +/* Extern function prototypes. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ + +#endif + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DCAPS.CPP +++ mesa-7.2/src/mesa/drivers/d3d/D3DCAPS.CPP @@ -0,0 +1,250 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver Build 5 */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DHAL.h" +/*===========================================================================*/ +/* Macros. */ +/*===========================================================================*/ +#define SRCBLEND_MAP(gl,d3d,fall) if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwSrcBlendCaps & d3d ) \ + { \ + sprintf( buffer, "SRC Blend: %s -> %s", # gl, # d3d ); \ + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ + pShared->dwSrcBlendCaps[index] = d3d; \ + } \ + else \ + { \ + sprintf( buffer, "SRC Blend: %s -> %s", # gl, # fall ); \ + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ + pShared->dwSrcBlendCaps[index] = fall; \ + } +#define DSTBLEND_MAP(gl,d3d,fall) if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwDestBlendCaps & d3d ) \ + { \ + sprintf( buffer, "DST Blend: %s -> %s", # gl, # d3d ); \ + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ + pShared->dwDestBlendCaps[index] = d3d; \ + } \ + else \ + { \ + sprintf( buffer, "DST Blend: %s -> %s", # gl, # fall ); \ + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \ + pShared->dwDestBlendCaps[index] = fall; \ + } + +/*===========================================================================*/ +/* I use this function to handle the fact that the D3D texture blending and */ +/* OpenGL texture blending functions don't map one to one. Also there is the*/ +/* problem with cards not supporting all the D3D functions. So I use the CAPS*/ +/* of the card to make a table of functions that will have defaults for the */ +/* unsupported functions. */ +/* So first I fill the table with the fallback function then I check to see */ +/* if the card supports the requested function. If it does I replace the */ +/* default thats already in the array. Now order does matter as I used an */ +/* enum type in D3DShared.h so that the mapping would be a little easier. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void AlphaBlendTableHAL( PMESAD3DHAL pHAL ) +{ + PMESAD3DSHARED pShared = &pHAL->shared; + int index; + char buffer[128]; + + DPF(( DBG_FUNC, "AlphaBlendTableHAL();" )); + + /* Make the fallback for the Source blend. */ + for( index = 0; index < 14; index++ ) + { + switch( index ) + { + case s_zero: + SRCBLEND_MAP( GL_ZERO, D3DBLEND_ZERO, D3DBLEND_ONE ); + break; + case s_one: + SRCBLEND_MAP( GL_ONE, D3DBLEND_ONE, D3DBLEND_ONE ); + break; + case s_dst_color: + SRCBLEND_MAP( GL_DST_COLOR, D3DBLEND_DESTCOLOR, D3DBLEND_ONE ); + break; + case s_one_minus_dst_color: + SRCBLEND_MAP( GL_ONE_MINUS_DST_COLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_ONE ); + break; + case s_src_alpha: + SRCBLEND_MAP( GL_SRC_ALPHA, D3DBLEND_SRCALPHA, D3DBLEND_ONE ); + break; + case s_one_minus_src_alpha: + SRCBLEND_MAP( GL_ONE_MINUS_SRC_ALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_ONE ); + break; + case s_dst_alpha: + SRCBLEND_MAP( GL_DST_ALPHA, D3DBLEND_DESTALPHA, D3DBLEND_ONE ); + break; + case s_one_minus_dst_alpha: + SRCBLEND_MAP( GL_ONE_MINUS_DST_ALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_ONE ); + break; + case s_src_alpha_saturate: + SRCBLEND_MAP( GL_SRC_ALPHA_SATURATE, D3DBLEND_SRCALPHASAT, D3DBLEND_ONE ); + break; + case s_constant_color: + SRCBLEND_MAP( GL_CONSTANT_COLOR, D3DBLEND_SRCCOLOR, D3DBLEND_ONE ); + break; + case s_one_minus_constant_color: + SRCBLEND_MAP( GL_ONE_MINUS_CONSTANT_COLOR, D3DBLEND_INVSRCCOLOR, D3DBLEND_ONE ); + break; + case s_constant_alpha: + SRCBLEND_MAP( GL_CONSTANT_ALPHA, D3DBLEND_BOTHSRCALPHA, D3DBLEND_ONE ); + break; + case s_one_minus_constant_alpha: + SRCBLEND_MAP( GL_ONE_MINUS_CONSTANT_ALPHA, D3DBLEND_BOTHINVSRCALPHA, D3DBLEND_ONE ); + break; + } + } + + /* Make the fallback for the Destination blend. */ + for( index = 0; index < 14; index++ ) + { + switch( index ) + { + case d_zero: + DSTBLEND_MAP( GL_ZERO, D3DBLEND_ZERO, D3DBLEND_ONE ); + break; + case d_one: + DSTBLEND_MAP( GL_ONE, D3DBLEND_ONE, D3DBLEND_ONE ); + break; + case d_src_color: + DSTBLEND_MAP( GL_SRC_COLOR, D3DBLEND_SRCCOLOR, D3DBLEND_ONE ); + break; + case d_one_minus_src_color: + DSTBLEND_MAP( GL_ONE_MINUS_SRC_COLOR, D3DBLEND_INVSRCCOLOR, D3DBLEND_ONE ); + break; + case d_src_alpha: + DSTBLEND_MAP( GL_SRC_ALPHA, D3DBLEND_SRCALPHA, D3DBLEND_ONE ); + break; + case d_one_minus_src_alpha: + DSTBLEND_MAP( GL_ONE_MINUS_SRC_ALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_ONE ); + break; + case d_dst_alpha: + DSTBLEND_MAP( GL_DST_ALPHA, D3DBLEND_DESTALPHA, D3DBLEND_ONE ); + break; + case d_one_minus_dst_alpha: + DSTBLEND_MAP( GL_ONE_MINUS_DST_ALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_ONE ); + break; + case d_constant_color: + DSTBLEND_MAP( GL_CONSTANT_COLOR, D3DBLEND_DESTCOLOR, D3DBLEND_ONE ); + break; + case d_one_minus_constant_color: + DSTBLEND_MAP( GL_ONE_MINUS_CONSTANT_COLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_ONE ); + break; + case d_constant_alpha: + DSTBLEND_MAP( GL_CONSTANT_ALPHAR, D3DBLEND_BOTHSRCALPHA, D3DBLEND_ONE ); + break; + case d_one_minus_constant_alpha: + DSTBLEND_MAP( GL_ONE_MINUS_CONSTANT_ALPHA, D3DBLEND_BOTHINVSRCALPHA, D3DBLEND_ONE ); + break; + } + } + + /* Make the fallbacks for the texture functions. */ + for( index = 0; index < 4; index++ ) + { + switch( index ) + { + case d3dtblend_decal: + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_DECAL" )); + pShared->dwTexFunc[index] = D3DTBLEND_DECAL; + } + else + { + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_MODULATE" )); + pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; + } + else + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_ADD" )); + pShared->dwTexFunc[index] = D3DTBLEND_ADD; + } + } + break; + case d3dtblend_decalalpha: + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECALALPHA ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPHA -> D3DTBLEND_DECALALPHA" )); + pShared->dwTexFunc[index] = D3DTBLEND_DECALALPHA; + } + else + { + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPA -> D3DTBLEND_DECAL" )); + pShared->dwTexFunc[index] = D3DTBLEND_DECAL; + } + else + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPHA -> D3DTBLEND_ADD" )); + pShared->dwTexFunc[index] = D3DTBLEND_ADD; + } + } + break; + case d3dtblend_modulate: + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_MODULATE" )); + pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; + } + else + { + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATEALPHA ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_MODULATEALPHA" )); + pShared->dwTexFunc[index] = D3DTBLEND_MODULATEALPHA; + } + else if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_DECAL" )); + pShared->dwTexFunc[index] = D3DTBLEND_DECAL; + } + else + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_ADD" )); + pShared->dwTexFunc[index] = D3DTBLEND_ADD; + } + } + break; + case d3dtblend_modulatealpha: + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATEALPHA ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_MODULATEALPHA" )); + pShared->dwTexFunc[index] = D3DTBLEND_MODULATEALPHA; + } + else + { + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_MODULATE" )); + pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; + } + else if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL ) + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_DECALE" )); + pShared->dwTexFunc[index] = D3DTBLEND_DECAL; + } + else + { + DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_ADD" )); + pShared->dwTexFunc[index] = D3DTBLEND_ADD; + } + } + break; + } + } +} + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DTextureMgr.h +++ mesa-7.2/src/mesa/drivers/d3d/D3DTextureMgr.h @@ -0,0 +1,62 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef _TEXTURE_MGR_INC +#define _TEXTURE_MGR_INC + +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include +#include +#include +#include +#include +#include "GL/gl.h" +/*========================================================================*/ +/* Defines. */ +/*========================================================================*/ +/*========================================================================*/ +/* Type defines. */ +/*========================================================================*/ +typedef struct _local_texture_object +{ + DWORD dwName, + dwPriority, + dwFlags, + dwSWidth, + dwSHeight, + dwVWidth, + dwVHeight; + BOOL bLock, + bDirty; /* I only update VID on SubImage calls so the system */ + /* texture can get invalid. */ + + LPDIRECT3DDEVICE3 lpD3DDevice; /* If the device changes we must get new handles... */ + LPDIRECTDRAWSURFACE4 lpDDS_System, + lpDDS_Video; + LPDIRECT3DTEXTURE2 lpD3DTexture2; + + PIXELINFO pixel; + + struct _local_texture_object *next; + struct _local_texture_object *prev; + +} TM_OBJECT, *PTM_OBJECT; +/*========================================================================*/ +/* Function prototypes. */ +/*========================================================================*/ +void APIENTRY InitTMD3D( void *pVoid ); +void APIENTRY TermTMD3D( void *pVoid ); +/*========================================================================*/ +/* Global variables declaration. */ +/*========================================================================*/ + +#endif --- mesa-7.2.orig/src/mesa/drivers/d3d/OPENGL32.DEF +++ mesa-7.2/src/mesa/drivers/d3d/OPENGL32.DEF @@ -0,0 +1,442 @@ +;=========================================================================== +; +; Mesa-3.0 DirectX 6 Driver +; +; By Leigh McRae +; +; http://www.altsoftware.com/ +; +; Copyright (c) 1999-1998 alt.software inc. All Rights Reserved +;=========================================================================== +NAME OpenGL32.DLL +DESCRIPTION "Mesa-3.0 DX6 Driver Version 0.5" + +EXPORTS + DllMain + glAccum + glAlphaFunc + glAreTexturesResident + glAreTexturesResidentEXT + glArrayElement + glArrayElementEXT + glBegin + glBindTexture + glBindTextureEXT + glBitmap + glBlendColorEXT + glBlendEquationEXT + glBlendFunc + glCallList + glCallLists + glClear + glClearAccum + glClearColor + glClearDepth + glClearIndex + glClearStencil + glClipPlane + glColor3b + glColor3bv + glColor3d + glColor3dv + glColor3f + glColor3fv + glColor3i + glColor3iv + glColor3s + glColor3sv + glColor3ub + glColor3ubv + glColor3ui + glColor3uiv + glColor3us + glColor3usv + glColor4b + glColor4bv + glColor4d + glColor4dv + glColor4f + glColor4fv + glColor4i + glColor4iv + glColor4s + glColor4sv + glColor4ub + glColor4ubv + glColor4ui + glColor4uiv + glColor4us + glColor4usv + glColorMask + glColorMaterial + glColorPointer + glColorPointerEXT + glColorSubTableEXT + glColorTableEXT + glCopyPixels + glCopyTexImage1D + glCopyTexImage2D + glCopyTexSubImage1D + glCopyTexSubImage2D + glCopyTexSubImage3DEXT + glCullFace + glDeleteLists + glDeleteTextures + glDeleteTexturesEXT + glDepthFunc + glDepthMask + glDepthRange + glDisable + glDisableClientState + glDrawArrays + glDrawArraysEXT + glDrawBuffer + glDrawElements + glDrawPixels + glEdgeFlag + glEdgeFlagPointer + glEdgeFlagPointerEXT + glEdgeFlagv + glEnable + glEnableClientState + glEnd + glEndList + glEvalCoord1d + glEvalCoord1dv + glEvalCoord1f + glEvalCoord1fv + glEvalCoord2d + glEvalCoord2dv + glEvalCoord2f + glEvalCoord2fv + glEvalMesh1 + glEvalMesh2 + glEvalPoint1 + glEvalPoint2 + glFeedbackBuffer + glFinish + glFlush + glFogf + glFogfv + glFogi + glFogiv + glFrontFace + glFrustum + glGenLists + glGenTextures + glGenTexturesEXT + glGetBooleanv + glGetClipPlane + glGetColorTableEXT + glGetColorTableParameterfvEXT + glGetColorTableParameterivEXT + glGetDoublev + glGetError + glGetFloatv + glGetIntegerv + glGetLightfv + glGetLightiv + glGetMapdv + glGetMapfv + glGetMapiv + glGetMaterialfv + glGetMaterialiv + glGetPixelMapfv + glGetPixelMapuiv + glGetPixelMapusv + glGetPointerv + glGetPointervEXT + glGetPolygonStipple + glGetString + glGetTexEnvfv + glGetTexEnviv + glGetTexGendv + glGetTexGenfv + glGetTexGeniv + glGetTexImage + glGetTexLevelParameterfv + glGetTexLevelParameteriv + glGetTexParameterfv + glGetTexParameteriv + glHint + glIndexd + glIndexdv + glIndexf + glIndexfv + glIndexi + glIndexiv + glIndexMask + glIndexPointer + glIndexPointerEXT + glIndexs + glIndexsv + glIndexub + glIndexubv + glInitNames + glInterleavedArrays + glIsEnabled + glIsList + glIsTexture + glIsTextureEXT + glLightf + glLightfv + glLighti + glLightiv + glLightModelf + glLightModelfv + glLightModeli + glLightModeliv + glLineStipple + glLineWidth + glListBase + glLoadIdentity + glLoadMatrixd + glLoadMatrixf + glLoadName + glLogicOp + glMap1d + glMap1f + glMap2d + glMap2f + glMapGrid1d + glMapGrid1f + glMapGrid2d + glMapGrid2f + glMaterialf + glMaterialfv + glMateriali + glMaterialiv + glMatrixMode + glMultMatrixd + glMultMatrixf + glNewList + glNormal3b + glNormal3bv + glNormal3d + glNormal3dv + glNormal3f + glNormal3fv + glNormal3i + glNormal3iv + glNormal3s + glNormal3sv + glNormalPointer + glNormalPointerEXT + glOrtho + glPassThrough + glPixelMapfv + glPixelMapuiv + glPixelMapusv + glPixelStoref + glPixelStorei + glPixelTransferf + glPixelTransferi + glPixelZoom + glPointParameterfEXT + glPointParameterfvEXT + glPointSize + glPolygonMode + glPolygonOffset + glPolygonOffsetEXT + glPolygonStipple + glPopAttrib + glPopClientAttrib + glPopMatrix + glPopName + glPrioritizeTextures + glPrioritizeTexturesEXT + glPushAttrib + glPushClientAttrib + glPushMatrix + glPushName + glRasterPos2d + glRasterPos2dv + glRasterPos2f + glRasterPos2fv + glRasterPos2i + glRasterPos2iv + glRasterPos2s + glRasterPos2sv + glRasterPos3d + glRasterPos3dv + glRasterPos3f + glRasterPos3fv + glRasterPos3i + glRasterPos3iv + glRasterPos3s + glRasterPos3sv + glRasterPos4d + glRasterPos4dv + glRasterPos4f + glRasterPos4fv + glRasterPos4i + glRasterPos4iv + glRasterPos4s + glRasterPos4sv + glReadBuffer + glReadPixels + glRectd + glRectdv + glRectf + glRectfv + glRecti + glRectiv + glRects + glRectsv + glRenderMode + glResizeBuffersMESA + glRotated + glRotatef + glScaled + glScalef + glScissor + glSelectBuffer + glShadeModel + glStencilFunc + glStencilMask + glStencilOp + glTexCoord1d + glTexCoord1dv + glTexCoord1f + glTexCoord1fv + glTexCoord1i + glTexCoord1iv + glTexCoord1s + glTexCoord1sv + glTexCoord2d + glTexCoord2dv + glTexCoord2f + glTexCoord2fv + glTexCoord2i + glTexCoord2iv + glTexCoord2s + glTexCoord2sv + glTexCoord3d + glTexCoord3dv + glTexCoord3f + glTexCoord3fv + glTexCoord3i + glTexCoord3iv + glTexCoord3s + glTexCoord3sv + glTexCoord4d + glTexCoord4dv + glTexCoord4f + glTexCoord4fv + glTexCoord4i + glTexCoord4iv + glTexCoord4s + glTexCoord4sv + glTexCoordPointer + glTexCoordPointerEXT + glTexEnvf + glTexEnvfv + glTexEnvi + glTexEnviv + glTexGend + glTexGendv + glTexGenf + glTexGenfv + glTexGeni + glTexGeniv + glTexImage1D + glTexImage2D + glTexImage3DEXT + glTexParameterf + glTexParameterfv + glTexParameteri + glTexParameteriv + glTexSubImage1D + glTexSubImage2D + glTexSubImage3DEXT + glTranslated + glTranslatef + glVertex2d + glVertex2dv + glVertex2f + glVertex2fv + glVertex2i + glVertex2iv + glVertex2s + glVertex2sv + glVertex3d + glVertex3dv + glVertex3f + glVertex3fv + glVertex3i + glVertex3iv + glVertex3s + glVertex3sv + glVertex4d + glVertex4dv + glVertex4f + glVertex4fv + glVertex4i + glVertex4iv + glVertex4s + glVertex4sv + glVertexPointer + glVertexPointerEXT + glViewport + glWindowPos2dMESA + glWindowPos2dvMESA + glWindowPos2fMESA + glWindowPos2fvMESA + glWindowPos2iMESA + glWindowPos2ivMESA + glWindowPos2sMESA + glWindowPos2svMESA + glWindowPos3dMESA + glWindowPos3dvMESA + glWindowPos3fMESA + glWindowPos3fvMESA + glWindowPos3iMESA + glWindowPos3ivMESA + glWindowPos3sMESA + glWindowPos3svMESA + glWindowPos4dMESA + glWindowPos4dvMESA + glWindowPos4fMESA + glWindowPos4fvMESA + glWindowPos4iMESA + glWindowPos4ivMESA + glWindowPos4sMESA + glWindowPos4svMESA +; WMesaCreateContext +; WMesaDestroyContext +; WMesaMakeCurrent +; WMesaPaletteChange +; WMesaSwapBuffers +; OSMesaCreateContext +; OSMesaDestroyContext +; OSMesaMakeCurrent +; OSMesaGetCurrentContext +; OSMesaPixelStore +; OSMesaGetIntegerv +; OSMesaGetDepthBuffer + wglCopyContext + wglCreateContext + wglCreateLayerContext + wglDeleteContext +; wglDescribeLayerPlane + wglGetCurrentContext + wglGetCurrentDC +; wglGetLayerPaletteEntries + wglGetProcAddress + wglMakeCurrent +; wglRealizeLayerPalette +; wglSetLayerPaletteEntries + wglShareLists + wglSwapLayerBuffers + wglUseFontBitmapsA + wglUseFontBitmapsW + wglUseFontOutlinesA + wglUseFontOutlinesW + wglChoosePixelFormat + wglDescribePixelFormat + wglGetPixelFormat + wglSetPixelFormat + wglSwapBuffers + + + --- mesa-7.2.orig/src/mesa/drivers/d3d/DEBUG.H +++ mesa-7.2/src/mesa/drivers/d3d/DEBUG.H @@ -0,0 +1,90 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#ifndef _DEBUG_H +#define _DEBUG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ +/* Includes. */ +/*===========================================================================*/ +#include +#include +#include +#include +#include "D3DShared.h" +/*===========================================================================*/ +/* Magic numbers. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Macros defines. */ +/*===========================================================================*/ +#define DBG_FUNC 0x00000001 +#define DBG_STATES 0x00000002 + +#define DBG_CNTX_INFO 0x00000010 +#define DBG_CNTX_WARN 0x00000020 +#define DBG_CNTX_PROFILE 0x00000040 +#define DBG_CNTX_ERROR 0x00000080 +#define DBG_CNTX_ALL 0x000000F0 + +#define DBG_PRIM_INFO 0x00000100 +#define DBG_PRIM_WARN 0x00000200 +#define DBG_PRIM_PROFILE 0x00000400 +#define DBG_PRIM_ERROR 0x00000800 +#define DBG_PRIM_ALL 0x00000F00 + +#define DBG_TXT_INFO 0x00001000 +#define DBG_TXT_WARN 0x00002000 +#define DBG_TXT_PROFILE 0x00004000 +#define DBG_TXT_ERROR 0x00008000 +#define DBG_TXT_ALL 0x0000F000 + +#define DBG_ALL_INFO 0x11111110 +#define DBG_ALL_WARN 0x22222220 +#define DBG_ALL_PROFILE 0x44444440 +#define DBG_ALL_ERROR 0x88888880 +#define DBG_ALL 0xFFFFFFFF + +#ifdef D3D_DEBUG +# define DPF(arg) DebugPrint arg +# define RIP(pH,msg,err) OutputDebugString(msg); \ + OutputDebugString(err); \ + OutputDebugString("\n"); \ + FatalShutDown(pH) +#else +# define DPF(arg) +# define RIP(pH,msg,err) FatalShutDown(pH) +#endif +/*===========================================================================*/ +/* Type defines. */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Function prototypes. */ +/*===========================================================================*/ +extern void ReadDBGEnv( void ); +extern void _cdecl DebugPrint( int mask, char *pszFormat, ... ); +extern void DebugPixelFormat( char *pszSurfaceName, DDPIXELFORMAT *pddpf ); +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ +extern DWORD g_DBGMask; + +#ifdef __cplusplus +} +#endif + +#endif + + + --- mesa-7.2.orig/src/mesa/drivers/d3d/DEBUG.C +++ mesa-7.2/src/mesa/drivers/d3d/DEBUG.C @@ -0,0 +1,143 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "Debug.h" +/*===========================================================================*/ +/* Global variables. */ +/*===========================================================================*/ +DWORD g_DBGMask = DBG_ALL_ERROR; +/*===========================================================================*/ +/* This is your basic DPF function with printf like support. The function */ +/* also works with a global debug mask variable. I have written support that*/ +/* allows for the user's enviroment variable space to be read and set the */ +/* masks. This is done when the dll starts and is only in the debug version.*/ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void _cdecl DebugPrint( int mask, char *pszFormat, ... ) +{ + char buffer[512]; + va_list args; + + /* A mask of 0 will always pass. Easy to remeber. */ + if ( (mask == 0) || (mask & g_DBGMask) ) + { + va_start( args, pszFormat ); + + if ( mask & DBG_ALL_ERROR ) + OutputDebugString( "MesaD3D: (ERROR)" ); + else + OutputDebugString( "MesaD3D: " ); + + vsprintf( buffer, pszFormat, args ); + strcat( buffer, "\n" ); + OutputDebugString( buffer ); + + va_end( args ); + } +} +/*===========================================================================*/ +/* This call reads the users enviroment variables and sets any debug mask */ +/* that they have set to TRUE. Now the value must be "TRUE". */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void ReadDBGEnv( void ) +{ + g_DBGMask = DBG_ALL_ERROR; + +#define IS_VAR_SET(v) if ( getenv( # v ) && !strcmp(getenv( # v ),"TRUE") ) g_DBGMask |= v; + + IS_VAR_SET( DBG_FUNC ); + IS_VAR_SET( DBG_STATES ); + + IS_VAR_SET( DBG_CNTX_INFO ); + IS_VAR_SET( DBG_CNTX_WARN ); + IS_VAR_SET( DBG_CNTX_PROFILE ); + IS_VAR_SET( DBG_CNTX_ERROR ); + IS_VAR_SET( DBG_CNTX_ALL ); + + IS_VAR_SET( DBG_PRIM_INFO ); + IS_VAR_SET( DBG_PRIM_WARN ); + IS_VAR_SET( DBG_PRIM_PROFILE ); + IS_VAR_SET( DBG_PRIM_ERROR ); + IS_VAR_SET( DBG_PRIM_ALL ); + + IS_VAR_SET( DBG_TXT_INFO ); + IS_VAR_SET( DBG_TXT_WARN ); + IS_VAR_SET( DBG_TXT_PROFILE ); + IS_VAR_SET( DBG_TXT_ERROR ); + IS_VAR_SET( DBG_TXT_ALL ); + + IS_VAR_SET( DBG_ALL_INFO ); + IS_VAR_SET( DBG_ALL_WARN ); + IS_VAR_SET( DBG_ALL_PROFILE ); + IS_VAR_SET( DBG_ALL_ERROR ); + IS_VAR_SET( DBG_ALL ); + +#undef IS_VAR_SET +} +/*===========================================================================*/ +/* This function will take a pointer to a DDSURFACEDESC2 structure & display*/ +/* the parsed information using a DPF call. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void DebugPixelFormat( char *pszSurfaceName, DDPIXELFORMAT *pddpf ) +{ + char buffer[256]; + + /* Parse the flag type and write the string equivalent. */ + if ( pddpf->dwFlags & DDPF_ALPHA ) + strcat( buffer, "DDPF_ALPHA " ); + if ( pddpf->dwFlags & DDPF_ALPHAPIXELS ) + strcat( buffer, "DDPF_ALPHAPIXELS " ); + if ( pddpf->dwFlags & DDPF_ALPHAPREMULT ) + strcat( buffer, "DDPF_ALPHAPREMULT " ); + if ( pddpf->dwFlags & DDPF_BUMPLUMINANCE ) + strcat( buffer, "DDPF_BUMPLUMINANCE " ); + if ( pddpf->dwFlags & DDPF_BUMPDUDV ) + strcat( buffer, "DDPF_BUMPDUDV " ); + if ( pddpf->dwFlags & DDPF_COMPRESSED ) + strcat( buffer, "DDPF_COMPRESSED " ); + if ( pddpf->dwFlags & DDPF_FOURCC ) + strcat( buffer, "DDPF_FOURCC " ); + if ( pddpf->dwFlags & DDPF_LUMINANCE ) + strcat( buffer, "DDPF_LUMINANCE " ); + if ( pddpf->dwFlags & DDPF_PALETTEINDEXED1 ) + strcat( buffer, "DDPF_PALETTEINDEXED1 " ); + if ( pddpf->dwFlags & DDPF_PALETTEINDEXED2 ) + strcat( buffer, "DDPF_PALETTEINDEXED2 " ); + if ( pddpf->dwFlags & DDPF_PALETTEINDEXED4 ) + strcat( buffer, "DDPF_PALETTEINDEXED4 " ); + if ( pddpf->dwFlags & DDPF_PALETTEINDEXED8 ) + strcat( buffer, "DDPF_PALETTEINDEXED8 " ); + if ( pddpf->dwFlags & DDPF_PALETTEINDEXEDTO8 ) + strcat( buffer, "DDPF_PALETTEINDEXEDTO8 " ); + if ( pddpf->dwFlags & DDPF_RGB ) + strcat( buffer, "DDPF_RGB " ); + if ( pddpf->dwFlags & DDPF_RGBTOYUV ) + strcat( buffer, "DDPF_RGBTOYUV " ); + if ( pddpf->dwFlags & DDPF_STENCILBUFFER ) + strcat( buffer, "DDPF_STENCILBUFFER " ); + if ( pddpf->dwFlags & DDPF_YUV ) + strcat( buffer, "DDPF_YUV " ); + if ( pddpf->dwFlags & DDPF_ZBUFFER ) + strcat( buffer, "DDPF_ZBUFFER " ); + if ( pddpf->dwFlags & DDPF_ZPIXELS ) + strcat( buffer, "DDPF_ZPIXELS " ); + + DPF(( (DBG_TXT_INFO|DBG_CNTX_INFO),"%s", buffer )); +} + + + + + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3DTextureMgr.cpp +++ mesa-7.2/src/mesa/drivers/d3d/D3DTextureMgr.cpp @@ -0,0 +1,947 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include "D3DHAL.h" +/*===========================================================================*/ +/* Local function prototypes. */ +/*===========================================================================*/ +static void UpdateTexture( PTM_OBJECT pTMObj, BOOL bVideo, RECT *pRect, UCHAR *pixels ); +static BOOL LoadTextureInVideo( PMESAD3DHAL pHAL, PTM_OBJECT pTMObj ); +static BOOL FreeTextureMemory( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ); +static BOOL DestroyTextureObject( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ); +HRESULT CALLBACK EnumPFHook( LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext ); +/*===========================================================================*/ +/* This function will simply set the top of stack to NULL. I only used it */ +/* just incase I want to add something later. */ +/*===========================================================================*/ +/* RETURN: TRUE. */ +/*===========================================================================*/ +BOOL InitTMgrHAL( PMESAD3DHAL pHAL ) +{ + DPF(( DBG_FUNC, "InitTMgrHAL();" )); + + /* Be clean my friend. */ + pHAL->pTMList = NULL; + + return TRUE; +} +/*===========================================================================*/ +/* This function will walk the Texture Managers linked list and destroy all */ +/* surfaces (SYSTEM/VIDEO). The texture objects themselves also will be */ +/* freed. */ +/* NOTE: this is per/context. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +void TermTMgrHAL( PMESAD3DHAL pHAL ) +{ + DPF(( DBG_FUNC, "TermTMgrHAL();" )); + + if ( pHAL && pHAL->pTMList ) + { + /* Destroy the surface and remove the TMO from the stack. */ + while( DestroyTextureObject(pHAL,NULL) ); + + /* Be clean my friend. */ + pHAL->pTMList = NULL; + } +} +/*===========================================================================*/ +/* This function is a HACK as I don't know how I can disable a texture with-*/ +/* out booting it out. Is there know state change? */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +extern "C" void DisableTMgrHAL( PMESAD3DSHARED pShared ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + + DPF(( DBG_FUNC, "DisableTMgrHAL();" )); + + /* Check too see that we have a valid context. */ + if ( (pHAL == NULL) && (pHAL->lpD3DDevice != NULL) ) + { + DPF(( DBG_TXT_WARN, "Null HAL/Direct3D Device!" )); + return; + } + + // TODO: This is a hack to shut off textures. + pHAL->lpD3DDevice->SetTexture( 0, NULL ); +} +/*===========================================================================*/ +/* This function is the only entry into the TextureManager that Mesa/wgl */ +/* will see. It uses a dwAction to specify what we are doing. I did this as*/ +/* depending on the cards resources the action taken can change. */ +/* When this function is called we will always search the Texture Managers */ +/* linked list (per context remember) and try and find a structure that has */ +/* the same dwName. If we have a match we pull it out of the list and put it*/ +/* at the top of the list (TOL). If we don't find one then we create a struc*/ +/* and put it a TOL. This TOL idea makes for some caching as we will always */ +/* destroy Texture Surfaces from the bottom up... */ +/* All texture objects at this point will create a texture surface in System*/ +/* memory (SMEM). Then we will copy the Mesa texture into the surface using */ +/* the 'pixel' struc to get the translation info. So now this means that all*/ +/* textures that Mesa gives me I will have a Surface with a copy. If Mesa */ +/* changes the texture the I update the surface in (SMEM). */ +/* Now we have a texture struc and a Texture Surface in SMEM. At this point*/ +/* we create another surface on the card (VMEM). Finally we blt from the */ +/* SMEM to the VMEM and set the texture as current. Why do I need two? First*/ +/* this solves square textures. If the cards CAPS is square textures only */ +/* then I change the dimensions of the VMEM surface and the blt solves it for*/ +/* me. Second it saves me from filling D3D textures over and over if the */ +/* card needs to be creating and destroying surfaces because of low memory. */ +/* The surface in SMEM is expected to work always. When a surface has to be*/ +/* created in VMEM then we put it in a loop that tries to create the surface.*/ +/* If we create the surface ok then we brake from the loop. If we fail then */ +/* we will call 'FreeTextureMemory' that will return TRUE/FALSE as to whether*/ +/* memory was freed. If memory was freed then we can try again. If no memory*/ +/* was freed then it just can't fit. */ +/* 'FreeTextureMemory' will find the end of the list and start freeing VMEM */ +/* (never SMEM) surfaces that are not locked. */ +/* BIND - when we bind and there is a texture struct with a texture surface */ +/* in VMEM then we just make it current. If we have a struct and a surface */ +/* in SMEM but no VMEM surface then we create the surface in VMEM and blt */ +/* from the SMEM surface. If we have nothing its just like a creation... */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +extern "C" BOOL CreateTMgrHAL( PMESAD3DSHARED pShared, DWORD dwName, int level, DWORD dwRequestFlags, + RECT *rectDirty, DWORD dwWidth, DWORD dwHeight, DWORD dwAction, void *pPixels ) +{ + PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared; + PTM_OBJECT pTMObj, + pTemp; + DDSURFACEDESC2 ddsd2; + HRESULT rc; + + + DPF(( DBG_FUNC, "CreateTMgrHAL();" )); + + DPF(( DBG_TXT_INFO, "Texture:" )); + DPF(( DBG_TXT_INFO, "cx: %d cy: %d", dwWidth, dwHeight )); + DPF(( DBG_TXT_INFO, "Rect:" )); + if ( rectDirty ) + { + DPF(( DBG_TXT_INFO, "x0: %d y0: %d", rectDirty->left, rectDirty->top )); + DPF(( DBG_TXT_INFO, "x1: %d y1: %d", rectDirty->right, rectDirty->bottom )); + } + + /* Check too see that we have a valid context. */ + if ( (pHAL == NULL) && (pHAL->lpD3DDevice != NULL) ) + { + DPF(( DBG_TXT_WARN, "Null HAL/Direct3D Device!" )); + return FALSE; + } + + /*=================================================*/ + /* See if we can find this texture object by name. */ + /*=================================================*/ + for( pTMObj = pHAL->pTMList; pTMObj && (pTMObj->dwName != dwName); pTMObj = pTMObj->next ); + + /*=========================================================*/ + /* Allocate a new object if we didn't get a matching name. */ + /*=========================================================*/ + if ( pTMObj == NULL ) + { + pTMObj = (PTM_OBJECT)ALLOC( sizeof(TM_OBJECT) ); + if ( pTMObj == NULL ) + return FALSE; + memset( pTMObj, 0, sizeof(TM_OBJECT) ); + + /* Put the object at the beginning of the list. */ + pTMObj->next = pHAL->pTMList; + if ( pTMObj->next ) + { + pTemp = pTMObj->next; + pTemp->prev = pTMObj; + } + pHAL->pTMList = pTMObj; + } + else + { + /*===============================================================*/ + /* Make some caching happen by pulling this object to the front. */ + /*===============================================================*/ + if ( pHAL->pTMList != pTMObj ) + { + /* Pull the object out of the list. */ + if ( pTMObj->prev ) + { + pTemp = pTMObj->prev; + pTemp->next = pTMObj->next; + } + if ( pTMObj->next ) + { + pTemp = pTMObj->next; + pTemp->prev = pTMObj->prev; + } + + pTMObj->prev = NULL; + pTMObj->next = NULL; + + /* Put the object at the front of the list. */ + pTMObj->next = pHAL->pTMList; + if ( pTMObj->next ) + { + pTemp = pTMObj->next; + pTemp->prev = pTMObj; + } + pHAL->pTMList = pTMObj; + } + } + + /*========================================================*/ + /* If we are doing BIND and the texture is in VID memory. */ + /*========================================================*/ + if ( (dwAction == TM_ACTION_BIND) && pTMObj->lpDDS_Video ) + { + DPF(( DBG_TXT_PROFILE, "Cache HIT (%d)", dwName )); + + /* Make this the current texture. */ + rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); + if ( FAILED(rc) ) + { + DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + return TRUE; + } + + /*=================================================================*/ + /* If we are doing BIND and the texture is at least in SYS memory. */ + /*=================================================================*/ + if ( (dwAction == TM_ACTION_BIND) && pTMObj->lpDDS_System ) + { + DPF(( DBG_TXT_PROFILE, "Cache MISS (%d)", dwName )); + + /* Create the texture on the card. */ + rc = LoadTextureInVideo( pHAL, pTMObj ); + if ( rc == FALSE ) + return FALSE; + + /* Make this the current texture. */ + rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); + if ( FAILED(rc) ) + { + DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + return TRUE; + } + + /*=========================================================*/ + /* If we are doing UPDATE then try in VID first for speed. */ + /*=========================================================*/ + if ( (dwAction == TM_ACTION_UPDATE) && pTMObj->lpDDS_Video && + !(pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY) ) + { + DPF(( DBG_TXT_INFO, "Fix the SubTexture update Leigh!" )); + + /* Update the texture on the card. */ + UpdateTexture( pTMObj, TRUE, rectDirty, (UCHAR *)pPixels ); + + /* We updated the texture in VID so kill the SYS so we know its dirty. */ + if ( pTMObj->lpDDS_System ) + { + DPF(( DBG_TXT_INFO, "Release texture (SYS)" )); + DX_RESTORE( pTMObj->lpDDS_System ); + pTMObj->lpDDS_System->Release(); + pTMObj->lpDDS_System = NULL; + } + + /* Make this the current texture. */ + rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); + if ( FAILED(rc) ) + { + DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + return TRUE; + } + + /*===========================================================*/ + /* If we are doing UPDATE then try in SYS still gives speed. */ + /*===========================================================*/ + if ( (dwAction == TM_ACTION_UPDATE) && pTMObj->lpDDS_System ) + { + DPF(( DBG_TXT_INFO, "Fix the SubTexture update Leigh!" )); + + /* Update the texture in SYS. */ + UpdateTexture( pTMObj, FALSE, NULL, (UCHAR *)pPixels ); + + /* We updated the SYS texture only so now blt to the VID. */ + rc = LoadTextureInVideo( pHAL, pTMObj ); + if ( rc == FALSE ) + return FALSE; + + /* Make this the current texture. */ + rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); + if ( FAILED(rc) ) + { + DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + return TRUE; + } + + /* At this point we have a valid Texture Manager Object with updated */ + /* links. We now need to create or update a texture surface that is */ + /* in system memory. Every texture has a copy in system so we can use*/ + /* blt to solve problems with textures allocated on the card (square */ + /* only textures, pixelformats...). */ + + // TODO: make support for update also. Dirty rectangle basicly... + + /* Kill the interface if we have one no matter what. */ + if ( pTMObj->lpD3DTexture2 ) + { + DPF(( DBG_TXT_INFO, "Release Texture2" )); + pTMObj->lpD3DTexture2->Release(); + pTMObj->lpD3DTexture2 = NULL; + } + + /* Kill the system surface. TODO: should try to get the SubIMage going again */ + if ( pTMObj->lpDDS_System ) + { + DPF(( DBG_TXT_INFO, "Release texture (SYS)" )); + DX_RESTORE( pTMObj->lpDDS_System ); + pTMObj->lpDDS_System->Release(); + pTMObj->lpDDS_System = NULL; + } + + /* Kill the Video surface. TODO: need some reuse system... */ + if ( pTMObj->lpDDS_Video ) + { + DPF(( DBG_TXT_INFO, "Release texture (VID)" )); + DX_RESTORE( pTMObj->lpDDS_Video ); + pTMObj->lpDDS_Video->Release(); + pTMObj->lpDDS_Video = NULL; + } + + /*================================================================*/ + /* Translate the the Mesa/OpenGL pixel channels to the D3D flags. */ + /*================================================================*/ + switch( dwRequestFlags ) + { + case GL_ALPHA: + dwRequestFlags = DDPF_ALPHA; + DPF(( DBG_TXT_WARN, "GL_ALPHA not supported!)" )); + return FALSE; + + case GL_INTENSITY: + case GL_LUMINANCE: + DPF(( DBG_TXT_WARN, "GL_INTENSITY/GL_LUMINANCE not supported!)" )); + dwRequestFlags = DDPF_LUMINANCE; + return FALSE; + + case GL_LUMINANCE_ALPHA: + DPF(( DBG_TXT_WARN, "GL_LUMINANCE_ALPHA not supported!)" )); + dwRequestFlags = DDPF_LUMINANCE | DDPF_ALPHAPIXELS; + return FALSE; + + case GL_RGB: + DPF(( DBG_TXT_INFO, "Texture -> GL_RGB" )); + dwRequestFlags = DDPF_RGB; + break; + + case GL_RGBA: + DPF(( DBG_TXT_INFO, "Texture -> GL_RGBA" )); + dwRequestFlags = DDPF_RGB | DDPF_ALPHAPIXELS; + break; + } + + /*==============================*/ + /* Populate the texture object. */ + /*==============================*/ + pTMObj->dwName = dwName; + pTMObj->lpD3DDevice = pHAL->lpD3DDevice; + pTMObj->dwFlags = dwRequestFlags; + if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) + { + DPF(( DBG_TXT_INFO, "Convert to Square..." )); + pTMObj->dwSHeight = dwHeight; + pTMObj->dwSWidth = dwWidth; + + /* Shrink non-square textures. */ + pTMObj->dwVHeight = (dwHeight > dwWidth) ? dwWidth : dwHeight; + pTMObj->dwVWidth = (dwHeight > dwWidth) ? dwWidth : dwHeight; + } + else + { + pTMObj->dwSHeight = dwHeight; + pTMObj->dwSWidth = dwWidth; + pTMObj->dwVHeight = dwHeight; + pTMObj->dwVWidth = dwWidth; + } + + /*========================*/ + /* Create SYSTEM surface. */ + /*========================*/ + + /* Request a surface in system memory. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); + ddsd2.dwWidth = pTMObj->dwSWidth; + ddsd2.dwHeight = pTMObj->dwSHeight; + ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; + ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY; + ddsd2.ddsCaps.dwCaps2 = 0L; + memset( &ddsd2.ddpfPixelFormat, 0, sizeof(DDPIXELFORMAT) ); + ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); + ddsd2.ddpfPixelFormat.dwFlags = dwRequestFlags; + rc = pHAL->lpD3DDevice->EnumTextureFormats( EnumPFHook, &ddsd2.ddpfPixelFormat ); + if ( FAILED(rc) ) + { + RIP( pHAL, "EnumerTextureFormats (SYSTEM)->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Create the surface using the enumerated pixelformat. */ + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pTMObj->lpDDS_System, NULL ); + if ( FAILED(rc) ) + { + RIP( pHAL, "CreateSurface (TEXTURE/SYSTEM)->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Solve the pixel mapping info using the surface pixelformat. */ + Solve8BitChannelPixelFormat( &ddsd2.ddpfPixelFormat, &pTMObj->pixel ); + + /*===================================================================*/ + /* Fill the texture using the PixelInfo structure to do the mapping. */ + /*===================================================================*/ + UpdateTexture( pTMObj, FALSE, NULL, (UCHAR *)pPixels ); + + /*=======================*/ + /* Create VIDEO surface. */ + /*=======================*/ + rc = LoadTextureInVideo( pHAL, pTMObj ); + if ( rc == FALSE ) + return FALSE; + + /* Make this the current texture. */ + rc = pHAL->lpD3DDevice->SetTexture( 0, pTMObj->lpD3DTexture2 ); + if ( FAILED(rc) ) + { + DPF(( DBG_TXT_WARN, "Failed SetTexture() (%s)", ErrorStringD3D(rc) )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + return TRUE; +} +/*===========================================================================*/ +/* This function will handle the creation and destruction of the texture */ +/* surfaces on the card. Using the dw'V'Width/Height dimensions the call */ +/* try and create the texture on the card and keep using FreeTextureMemory */ +/* until the surace can be created. Once the surface is created we get the */ +/* interface that we will use to make it the current texture. I didn't put */ +/* the code to make the texture current in this function as BIND needs to */ +/* use the same code and this function doesn't always get called when we do a*/ +/* bind. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +static BOOL LoadTextureInVideo( PMESAD3DHAL pHAL, PTM_OBJECT pTMObj ) +{ + DDSURFACEDESC2 ddsd2; + HRESULT rc; + + DPF(( DBG_FUNC, "LoadTextureInVideo();" )); + + /* Kill the interface if we have one no matter what. */ + if ( pTMObj->lpD3DTexture2 ) + { + DPF(( DBG_TXT_INFO, "Release Texture2" )); + pTMObj->lpD3DTexture2->Release(); + pTMObj->lpD3DTexture2 = NULL; + } + + /* Kill the Video surface. TODO: need some reuse system... */ + if ( pTMObj->lpDDS_Video ) + { + DPF(( DBG_TXT_INFO, "Release texture (VID)" )); + DX_RESTORE( pTMObj->lpDDS_Video ); + pTMObj->lpDDS_Video->Release(); + pTMObj->lpDDS_Video = NULL; + } + + /* Request a surface in Video memory. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof( DDSURFACEDESC2 ); + ddsd2.dwWidth = pTMObj->dwVWidth; + ddsd2.dwHeight = pTMObj->dwVHeight; + ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; + ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY; + ddsd2.ddsCaps.dwCaps2 = 0L; + memset( &ddsd2.ddpfPixelFormat, 0, sizeof(DDPIXELFORMAT) ); + ddsd2.ddpfPixelFormat.dwSize = sizeof( DDPIXELFORMAT ); + ddsd2.ddpfPixelFormat.dwFlags = pTMObj->dwFlags; + rc = pHAL->lpD3DDevice->EnumTextureFormats( EnumPFHook, &ddsd2.ddpfPixelFormat ); + if ( FAILED(rc) ) + { + RIP( pHAL, "EnumerTextureFormats ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Make sure we lock so we don't nuke this texture trying to free memory for it. */ + pTMObj->bLock = TRUE; + + /* Start a loop that will free all textures until we have created the texture */ + /* surface or we can't free up more memory. */ + do + { + /* Try to create the texture surface. */ + rc = pHAL->lpDD4->CreateSurface( &ddsd2, &pTMObj->lpDDS_Video, NULL ); + if ( !FAILED(rc) ) + break; + + DPF(( DBG_TXT_INFO, "Free Texture Memory" )); + + /* DestroyTexture will return TRUE if a surface was freed. */ + } while( FreeTextureMemory(pHAL,NULL) ); + + /* Make sure we unlock or we won't be able to nuke the TMO later. */ + pTMObj->bLock = FALSE; + + /* Did we create a valid texture surface? */ + if ( FAILED(rc) ) + { + DPF(( DBG_TXT_WARN, "Failed to load texture" )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + DX_RESTORE( pTMObj->lpDDS_System ); + DX_RESTORE( pTMObj->lpDDS_Video ); + + DPF(( DBG_TXT_INFO, "Texture Blt SYSTEM -> VID" )); + + /* Now blt the texture in system memory to the card. */ + rc = pTMObj->lpDDS_Video->Blt( NULL, pTMObj->lpDDS_System, NULL, DDBLT_WAIT, NULL ); + if ( FAILED(rc) ) + { + RIP( pHAL, "Blt (TEXTURE) ->", ErrorStringD3D(rc) ); + return FALSE; + } + + /* Get the Texture interface that is used to render with. */ + pTMObj->lpDDS_Video->QueryInterface( IID_IDirect3DTexture2, (void **)&pTMObj->lpD3DTexture2 ); + if ( pTMObj->lpD3DTexture2 == NULL ) + { + DPF(( DBG_TXT_WARN, "Failed QueryTextureInterface" )); + pHAL->lpD3DDevice->SetTexture( 0, NULL ); + return FALSE; + } + + return TRUE; +} +/*===========================================================================*/ +/* If this function gets a texture object struc then we will try and free */ +/* it. If we get a NULL then we will search from the bottom up and free one */ +/* VMEM surface. I can only free when the surface isn't locked and of course*/ +/* there must be a VMEM surface. We never free SMEM surfaces as that isn't */ +/* the point. */ +/* TODO: should have a pointer to the bottom of the stack really. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static BOOL FreeTextureMemory( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ) +{ + PTM_OBJECT pCurrent; + BOOL bFreed = FALSE; + + DPF(( DBG_FUNC, "FreeTextureMemory();" )); + DPF(( DBG_TXT_WARN, "FREE TEXTURE!" )); + + /* Just to be safe. */ + if ( !pHAL || !pHAL->pTMList ) + { + DPF(( DBG_TXT_WARN, "FreeTextureMemory() -> NULL pHAL/pHAL->pTMList" )); + return FALSE; + } + + /* Free the last texture in the list. */ + if ( pTMObject == NULL ) + { + DPF(( DBG_TXT_INFO, "Free Last texture in cache" )); + + /* Find the last texture object. */ + for( pCurrent = pHAL->pTMList; pCurrent->next; pCurrent = pCurrent->next ); + + /* Now backup until we find a texture on the card. */ + while( pCurrent && (pCurrent->lpDDS_Video == NULL) && (pCurrent->bLock == FALSE) ) + pCurrent = pCurrent->prev; + + /* Didn't find anything. */ + if ( pCurrent == NULL ) + { + DPF(( DBG_TXT_INFO, "No texture memory freed" )); + return FALSE; + } + } + else + { + /* See if we can find this texture object. */ + for( pCurrent = pHAL->pTMList; pCurrent && (pCurrent != pTMObject); pCurrent = pCurrent->next ); + + /* Didn't find anything. */ + if ( pCurrent == NULL ) + { + DPF(( DBG_TXT_INFO, "Requested texture to be freed NOT FOUND" )); + return FALSE; + } + } + + /* Can't free this baby. */ + if ( pCurrent->bLock == TRUE ) + { + DPF(( DBG_TXT_WARN, "Requested texture LOCKED" )); + return FALSE; + } + + /* Free the texture memory. */ + if ( pCurrent->lpD3DTexture2 ) + { + DPF(( DBG_TXT_INFO, "Release Texture2" )); + pCurrent->lpD3DTexture2->Release(); + pCurrent->lpD3DTexture2 = NULL; + bFreed = TRUE; + } + if ( pCurrent->lpDDS_Video ) + { + DPF(( DBG_TXT_INFO, "Release texture (VID):" )); + DPF(( DBG_TXT_INFO, "dwName: %d", pCurrent->dwName )); + DPF(( DBG_TXT_INFO, "cx: %d, cy: %d", pCurrent->dwVWidth, pCurrent->dwVHeight )); + pCurrent->lpDDS_Video->Release(); + pCurrent->lpDDS_Video = NULL; + bFreed = TRUE; + } + + return bFreed; +} +/*===========================================================================*/ +/* This function searches the linked list of texture objects in the supplied*/ +/* D3Dwrapper structure. If it finds a match it will free it and pull it out*/ +/* of the linked list. The function works on the bases of a matching pointer*/ +/* to the object (not matching content). */ +/* If the function gets passed a NULL then we want to free the last texture */ +/* object in the list. Used in a loop to destory all. */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +static BOOL DestroyTextureObject( PMESAD3DHAL pHAL, PTM_OBJECT pTMObject ) +{ + PTM_OBJECT pCurrent; + + DPF(( DBG_FUNC, "DestoryTextureObject();" )); + + /* Just to be safe. */ + if ( !pHAL || !pHAL->pTMList ) + { + DPF(( DBG_TXT_WARN, "DestroyTextureObject() -> NULL pHAL/pHAL->pTMList" )); + return FALSE; + } + + /* Free the last texture in the list. */ + if ( pTMObject == NULL ) + { + /* Find the last texture object. */ + for( pCurrent = pHAL->pTMList; pCurrent->next; pCurrent = pCurrent->next ); + } + else + { + /* See if we can find this texture object. */ + for( pCurrent = pHAL->pTMList; pCurrent && (pCurrent != pTMObject); pCurrent = pCurrent->next ); + + /* Didn't find anything. */ + if ( pCurrent == NULL ) + { + DPF(( DBG_TXT_WARN, "No textures to be freed" )); + return FALSE; + } + } + + /* Can't free this baby. */ + if ( pCurrent->bLock == TRUE ) + { + DPF(( DBG_TXT_WARN, "Requested texture to be freed LOCKED" )); + return FALSE; + } + + /* Free the texture memory. */ + if ( pCurrent->lpD3DTexture2 ) + { + DPF(( DBG_TXT_INFO, "Release Texture2" )); + pCurrent->lpD3DTexture2->Release(); + pCurrent->lpD3DTexture2 = NULL; + } + if ( pCurrent->lpDDS_Video ) + { + DPF(( DBG_TXT_INFO, "Release texture (VID):" )); + pCurrent->lpDDS_Video->Release(); + pCurrent->lpDDS_Video = NULL; + } + if ( pCurrent->lpDDS_System ) + { + DPF(( DBG_TXT_INFO, "Release texture (SYS):" )); + pCurrent->lpDDS_System->Release(); + pCurrent->lpDDS_System = NULL; + } + + /* Pull this texture out of the list. */ + if ( pCurrent == pHAL->pTMList ) + pHAL->pTMList = NULL; + if ( pCurrent->prev ) + (pCurrent->prev)->next = pCurrent->next; + if ( pCurrent->next ) + (pCurrent->next)->prev = pCurrent->prev; + FREE( pCurrent ); + + return TRUE; +} +/*===========================================================================*/ +/* This function is the callback function that gets called when we are doing*/ +/* an enumeration of the texture formats supported by this device. The choice*/ +/* is made by checking to see if we have a match with the supplied D3D pixel-*/ +/* format. So the enumeration has to pass a desired D3D PF as the user var. */ +/*===========================================================================*/ +/* RETURN: D3DENUMRET_OK, D3DENUMRET_CANCEL. */ +/*===========================================================================*/ +static void UpdateTexture( PTM_OBJECT pTMObj, BOOL bVideo, RECT *pRect, UCHAR *pixels ) +{ + LPDIRECTDRAWSURFACE4 lpDDS; + DDSURFACEDESC2 ddsd2; + DWORD srcPitch, + dwHeight, + dwWidth, + dwCol, + dwColor; + UCHAR *pSrc, + *pSrcRow, + *pDest, + *pDestRow; + int rc; + + // TODO: Do I need to pass the h/w when its in the object! + DPF(( DBG_FUNC, "UpdateTexture();" )); + + /* Get the surface pointer we are looking for. */ + lpDDS = (bVideo) ? pTMObj->lpDDS_Video : pTMObj->lpDDS_System; + + /*===================================================================*/ + /* Fill the texture using the PixelInfo structure to do the mapping. */ + /*===================================================================*/ + + /* Get the surface pointer. */ + memset( &ddsd2, 0, sizeof(DDSURFACEDESC2) ); + ddsd2.dwSize = sizeof(DDSURFACEDESC2); + rc = lpDDS->Lock( NULL, &ddsd2, DDLOCK_WAIT, NULL ); + if ( FAILED(rc) ) + { + RIP( NULL, "Lock (TEXTURE/SYSTEM)->", ErrorStringD3D(rc) ); + return; + } + + /* For now we are only updating the system surface so use its dimensions. */ + dwWidth = (bVideo) ? pTMObj->dwVWidth : pTMObj->dwSWidth; + dwHeight = (bVideo) ? pTMObj->dwVHeight : pTMObj->dwSHeight; + + /* If we are updating the whole surface then the pDest/pSrc will */ + /* always be the same. */ + if ( pRect == NULL ) + { + pDest = (UCHAR *)ddsd2.lpSurface; + pSrc = pixels; + } + + /* Fill the texture surface based on the pixelformat flags. */ + if ( pTMObj->dwFlags == (DDPF_RGB | DDPF_ALPHAPIXELS) ) + { + srcPitch = dwWidth * 4; + if ( pRect ) + { + pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); + pSrc = pixels + (pRect->top * dwWidth * 4) + (pRect->left * 4); + dwHeight = (pRect->bottom - pRect->top); + dwWidth = (pRect->right - pRect->left); + } + + for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) + { + for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) + { + dwColor = ( ((DWORD)(*(pSrc ) * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); + dwColor |= ( ((DWORD)(*(pSrc+1) * pTMObj->pixel.gScale)) << pTMObj->pixel.gShift ); + dwColor |= ( ((DWORD)(*(pSrc+2) * pTMObj->pixel.bScale)) << pTMObj->pixel.bShift ); + if ( pTMObj->pixel.aScale == -1.0 ) + dwColor |= ( (*(pSrc+3) & 0x80) ? (1 << pTMObj->pixel.aShift) : 0 ); + else + dwColor |= ( ((DWORD)(*(pSrc+3) * pTMObj->pixel.aScale)) << pTMObj->pixel.aShift ); + memcpy( pDest, &dwColor, pTMObj->pixel.cb ); + pDest += pTMObj->pixel.cb; + pSrc += 4; + } + } + } + else if ( pTMObj->dwFlags == DDPF_RGB ) + { + srcPitch = dwWidth * 3; + if ( pRect ) + { + pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); + pSrc = pixels + (pRect->top * dwWidth * 3) + (pRect->left * 3); + dwHeight = (pRect->bottom - pRect->top); + dwWidth = (pRect->right - pRect->left); + } + + for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) + { + for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) + { + dwColor = ( ((DWORD)(*(pSrc ) * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); + dwColor |= ( ((DWORD)(*(pSrc+1) * pTMObj->pixel.gScale)) << pTMObj->pixel.gShift ); + dwColor |= ( ((DWORD)(*(pSrc+2) * pTMObj->pixel.bScale)) << pTMObj->pixel.bShift ); + memcpy( pDest, &dwColor, pTMObj->pixel.cb ); + pDest += pTMObj->pixel.cb; + pSrc += 3; + } + } + } + else if ( pTMObj->dwFlags == (DDPF_LUMINANCE | DDPF_ALPHAPIXELS) ) + { + srcPitch = dwWidth * 2; + if ( pRect ) + { + pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); + pSrc = pixels + (pRect->top * dwWidth * 2) + (pRect->left * 2); + dwHeight = (pRect->bottom - pRect->top); + dwWidth = (pRect->right - pRect->left); + } + + for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) + { + for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) + { + dwColor = ( ((DWORD)(*(pSrc ) * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); + if ( pTMObj->pixel.aScale == -1.0 ) + dwColor |= ( (*(pSrc+1) & 0x80) ? (1 << pTMObj->pixel.aShift) : 0 ); + else + dwColor |= ( ((DWORD)(*(pSrc+1) * pTMObj->pixel.aScale)) << pTMObj->pixel.aShift ); + memcpy( pDest, &dwColor, pTMObj->pixel.cb ); + pDest += pTMObj->pixel.cb; + pSrc += 2; + } + } + } + else if ( pTMObj->dwFlags == DDPF_LUMINANCE ) + { + srcPitch = dwWidth; + if ( pRect ) + { + pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); + pSrc = pixels + (pRect->top * dwWidth) + (pRect->left); + dwHeight = (pRect->bottom - pRect->top); + dwWidth = (pRect->right - pRect->left); + } + + for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) + { + for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) + { + dwColor = ( ((DWORD)(*pSrc * pTMObj->pixel.rScale)) << pTMObj->pixel.rShift ); + memcpy( pDest, &dwColor, pTMObj->pixel.cb ); + pDest += pTMObj->pixel.cb; + pSrc++; + } + } + } + else if ( pTMObj->dwFlags == DDPF_ALPHAPIXELS ) + { + srcPitch = dwWidth; + if ( pRect ) + { + pDest = ((UCHAR *)ddsd2.lpSurface) + (pRect->top * ddsd2.lPitch) + (pRect->left * pTMObj->pixel.cb); + pSrc = pixels + (pRect->top * dwWidth) + (pRect->left); + dwHeight = (pRect->bottom - pRect->top); + dwWidth = (pRect->right - pRect->left); + } + + for( pDestRow = pDest, pSrcRow = pSrc; dwHeight > 0; dwHeight--, pDestRow += ddsd2.lPitch, pSrcRow += srcPitch ) + { + for( dwCol = 0, pDest = pDestRow, pSrc = pSrcRow; dwCol < dwWidth; dwCol++ ) + { + if ( pTMObj->pixel.aScale == -1.0 ) + dwColor = ( (*pSrc & 0x80) ? (1 << pTMObj->pixel.aShift) : 0 ); + else + dwColor = ( ((DWORD)(*pSrc * pTMObj->pixel.aScale)) << pTMObj->pixel.aShift ); + memcpy( pDest, &dwColor, pTMObj->pixel.cb ); + pDest += pTMObj->pixel.cb; + pSrc++; + } + } + } + + /* Unlock the surface. */ + rc = lpDDS->Unlock( NULL ); + if ( FAILED(rc) ) + { + RIP( NULL, "Unlock (TEXTURE/SYSTEM)->", ErrorStringD3D(rc) ); + } +} +/*===========================================================================*/ +/* This function is the callback function that gets called when we are doing*/ +/* an enumeration of the texture formats supported by this device. The choice*/ +/* is made by checking to see if we have a match with the supplied D3D pixel-*/ +/* format. So the enumeration has to pass a desired D3D PF as the user var. */ +/*===========================================================================*/ +/* RETURN: D3DENUMRET_OK, D3DENUMRET_CANCEL. */ +/*===========================================================================*/ +HRESULT CALLBACK EnumPFHook( LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext ) +{ + LPDDPIXELFORMAT lpDDPixFmtRequest = (LPDDPIXELFORMAT)lpContext; + PIXELINFO pixel; + + DPF(( DBG_FUNC, "EnumPFHook();" )); + + if ( lpDDPixFmt->dwFlags == lpDDPixFmtRequest->dwFlags ) + { + /* Are we looking for an alpha channel? */ + if ( lpDDPixFmtRequest->dwFlags & DDPF_ALPHAPIXELS ) + { + /* Try for something that has more then 1bits of Alpha. */ + Solve8BitChannelPixelFormat( lpDDPixFmt, &pixel ); + if ( pixel.aScale == -1.0 ) + { + /* Save this format no matter what as its a match of sorts. */ + memcpy( lpDDPixFmtRequest, lpDDPixFmt, sizeof(DDPIXELFORMAT) ); + return D3DENUMRET_OK; + } + } + + /* Save this format as its a good match. */ + memcpy( lpDDPixFmtRequest, lpDDPixFmt, sizeof(DDPIXELFORMAT) ); + + /* We are happy at this point so lets leave. */ + return D3DENUMRET_CANCEL; + } + + return D3DENUMRET_OK; +} + + --- mesa-7.2.orig/src/mesa/drivers/d3d/D3Dvbrender.c +++ mesa-7.2/src/mesa/drivers/d3d/D3Dvbrender.c @@ -0,0 +1,2149 @@ +/*===========================================================================*/ +/* */ +/* Mesa-3.0 DirectX 6 Driver */ +/* */ +/* By Leigh McRae */ +/* */ +/* http://www.altsoftware.com/ */ +/* */ +/* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */ +/*===========================================================================*/ +#include +#include "clip.h" +#include "context.h" +#include "light.h" +#include "lines.h" +#include "macros.h" +#include "matrix.h" +#include "pb.h" +#include "points.h" +#include "mtypes.h" +#include "vb.h" +#include "vbrender.h" +#include "xform.h" +#include "D3DMesa.h" + +static void SetRenderStates( GLcontext *ctx ); +static void DebugRenderStates( GLcontext *ctx, BOOL bForce ); + +static void RenderPointsVB( GLcontext *ctx, GLuint start, GLuint end ); +static void RenderTriangleVB( GLcontext *ctx, GLuint start, GLuint end ); +static void RenderTriangleFanVB( GLcontext *ctx, GLuint start, GLuint end ); +static void RenderTriangleStripVB( GLcontext *ctx, GLuint start, GLuint end ); +static void RenderQuadVB( GLcontext *ctx, GLuint start, GLuint end ); +static void RenderQuad( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4, GLuint pv ); +void RenderOneTriangle( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv ); +void RenderOneLine( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ); + +/* I went with a D3D vertex buffer that is 6 times that of the Mesa one */ +/* instead of having the D3D one flush when its full. This way Mesa will*/ +/* handle all the flushing. I need x6 as points can use 4 vertex each. */ +D3DTLVERTEX D3DTLVertices[ (VB_MAX*6) ]; +GLuint VList[VB_SIZE]; +/*===========================================================================*/ +/* Compute Z offsets for a polygon with plane defined by (A,B,C,D) */ +/* D is not needed. TODO: Currently we are calculating this but not using it.*/ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void OffsetPolygon( GLcontext *ctx, GLfloat a, GLfloat b, GLfloat c ) +{ + GLfloat ac, + bc, + m, + offset; + + DPF(( DBG_FUNC, "OffsetPolygon();" )); + + if ( (c < 0.001F) && (c > - 0.001F) ) + { + /* Prevents underflow problems. */ + ctx->PointZoffset = 0.0F; + ctx->LineZoffset = 0.0F; + ctx->PolygonZoffset = 0.0F; + } + else + { + ac = a / c; + bc = b / c; + if ( ac < 0.0F ) + ac = -ac; + if ( bc<0.0F ) + bc = -bc; + m = MAX2( ac, bc ); /* m = sqrt( ac*ac + bc*bc ); */ + + offset = (m * ctx->Polygon.OffsetFactor + ctx->Polygon.OffsetUnits); + ctx->PointZoffset = ctx->Polygon.OffsetPoint ? offset : 0.0F; + ctx->LineZoffset = ctx->Polygon.OffsetLine ? offset : 0.0F; + ctx->PolygonZoffset = ctx->Polygon.OffsetFill ? offset : 0.0F; + } + + DPF(( DBG_PRIM_INFO, "OffsetPolygon: %f", offset )); +} +/*===========================================================================*/ +/* Compute signed area of the n-sided polgyon specified by vertices */ +/* vb->Win[] and vertex list vlist[]. */ +/* A clockwise polygon will return a negative area. A counter-clockwise */ +/* polygon will return a positive area. I have changed this function to */ +/* actually calculate twice the area as its faster and still gives the sign. */ +/*===========================================================================*/ +/* RETURN: signed area of the polgon. */ +/*===========================================================================*/ +static GLfloat PolygonArea( const struct vertex_buffer *vb, GLuint n, const GLuint vlist[] ) +{ + GLfloat area; + GLuint i; + + DPF(( DBG_FUNC, "PolygonArea();" )); + +#define j0 vlist[i] +#define j1 vlist[(i+1)%n] +#define x0 vb->Win[j0][0] +#define y0 vb->Win[j0][1] +#define x1 vb->Win[j1][0] +#define y1 vb->Win[j1][1] + + /* area = sum of trapezoids */ + for( i = 0, area = 0.0; i < n; i++ ) + area += ((x0 - x1) * (y0 + y1)); /* Note: no divide by two here! */ + +#undef x0 +#undef y0 +#undef x1 +#undef y1 +#undef j1 +#undef j0 + + // TODO: I don't see the point or * 0.5 as we just want the sign... + return area; +} +/*===========================================================================*/ +/* Render a polygon that needs clipping on at least one vertex. The function*/ +/* will first clip the polygon to any user clipping planes then clip to the */ +/* viewing volume. The final polygon will be draw as single triangles that */ +/* first need minor proccessing (culling, offset, etc) before we draw the */ +/* polygon as a fan. NOTE: the fan is draw as single triangles as its not */ +/* formed sequentaly in the VB but is in the vlist[]. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void RenderClippedPolygon( GLcontext *ctx, GLuint n, GLuint vlist[] ) +{ + struct vertex_buffer *VB = ctx->VB; + GLfloat (*win)[3] = VB->Win, + *proj = ctx->ProjectionMatrix, + ex, ey, + fx, fy, c, + wInv; + GLuint index, + pv, + facing; + + DPF(( DBG_FUNC, "RenderClippedPolygon();" )); + + DPF(( DBG_PRIM_INFO, "RenderClippedtPolygon( %d )", n )); + + /* Which vertex dictates the color when flat shading. */ + pv = (ctx->Primitive==GL_POLYGON) ? vlist[0] : vlist[n-1]; + + /* Clipping may introduce new vertices. New vertices will be stored in */ + /* the vertex buffer arrays starting with location VB->Free. After we've*/ + /* rendered the polygon, these extra vertices can be overwritten. */ + VB->Free = VB_MAX; + + /* Clip against user clipping planes in eye coord space. */ + if ( ctx->Transform.AnyClip ) + { + n = gl_userclip_polygon( ctx, n, vlist ); + if ( n < 3 ) + return; + + /* Transform vertices from eye to clip coordinates: clip = Proj * eye */ + for( index = 0; index < n; index++ ) + { + TRANSFORM_POINT( VB->Clip[vlist[index]], proj, VB->Eye[vlist[index]] ); + } + } + + /* Clip against view volume in clip coord space */ + n = gl_viewclip_polygon( ctx, n, vlist ); + if ( n < 3 ) + return; + + /* Transform new vertices from clip to ndc to window coords. */ + /* ndc = clip / W window = viewport_mapping(ndc) */ + /* Note that window Z values are scaled to the range of integer */ + /* depth buffer values. */ + + /* Only need to compute window coords for new vertices */ + for( index = VB_MAX; index < VB->Free; index++ ) + { + if ( VB->Clip[index][3] != 0.0F ) + { + wInv = 1.0F / VB->Clip[index][3]; + + win[index][0] = VB->Clip[index][0] * wInv * ctx->Viewport.Sx + ctx->Viewport.Tx; + win[index][1] = VB->Clip[index][1] * wInv * ctx->Viewport.Sy + ctx->Viewport.Ty; + win[index][2] = VB->Clip[index][2] * wInv * ctx->Viewport.Sz + ctx->Viewport.Tz; + } + else + { + /* Can't divide by zero, so... */ + win[index][0] = win[index][1] = win[index][2] = 0.0F; + } + } + + /* Draw filled polygon as a triangle fan */ + for( index = 2; index < n; index++ ) + { + /* Compute orientation of triangle */ + ex = win[vlist[index-1]][0] - win[vlist[0]][0]; + ey = win[vlist[index-1]][1] - win[vlist[0]][1]; + fx = win[vlist[index]][0] - win[vlist[0]][0]; + fy = win[vlist[index]][1] - win[vlist[0]][1]; + c = (ex * fy) - (ey * fx); + + /* polygon is perpindicular to view plane, don't draw it */ + if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) + continue; + + /* Backface culling. */ + facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; + if ( (facing + 1) & ctx->Polygon.CullBits ) + continue; + + if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) + { + if ( facing == 1 ) + { + /* use back color */ + VB->Color = VB->Bcolor; + VB->Specular= VB->Bspec; + } + else + { + /* use front color */ + VB->Color = VB->Fcolor; + VB->Specular= VB->Fspec; + } + } + + if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) + { + /* finish computing plane equation of polygon, compute offset */ + GLfloat fz = win[vlist[index]][2] - win[vlist[0]][2]; + GLfloat ez = win[vlist[index-1]][2] - win[vlist[0]][2]; + GLfloat a = (ey * fz) - (ez * fy); + GLfloat b = (ez * fx) - (ex * fz); + OffsetPolygon( ctx, a, b, c ); + } + RenderOneTriangle( ctx, vlist[0], vlist[index-1], vlist[index], pv ); + } +} +/*===========================================================================*/ +/* This function gets called when either the vertex buffer is full or glEnd */ +/* has been called. If the we aren't in rendering mode (FEEDBACK) then I */ +/* pass the vertex buffer back to Mesa to deal with by returning FALSE. */ +/* If I can render the primitive types in the buffer directly then I will */ +/* return TRUE after I render the vertex buffer and reset the vertex buffer. */ +/* */ +/* TODO: I don't handle the special case of when the vertex buffer is full */ +/* and we have a primitive that bounds this buffer and the next one to */ +/* come. I'm not sure right now if Mesa handles this for me... */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +GLboolean RenderVertexBuffer( GLcontext *ctx, GLboolean allDone ) +{ + struct vertex_buffer *VB = ctx->VB; + GLuint index, + vlist[VB_SIZE]; + + DPF(( DBG_FUNC, "RenderVertexBuffer();" )); + + /* We only need to hook actual tri's that need rendering. */ + if ( ctx->RenderMode != GL_RENDER ) + { + // (ctx->Visual->AccumBits > 0) ) + // (ctx->Visual->StencilBits > 0) ) + DPF(( DBG_PRIM_INFO, "Passing VB back to Mesa" )); + return FALSE; + } + + /* I'm going to set the states here so that all functions will */ + /* be assured to have the right states. If Mesa's vertex bufefr */ + /* function calls one of my primitive functions (TRI,POINT,LINE) */ + /* it will need the right states. So instead of doing it in the */ + /* primitive function I will always do it here at risk of some */ + /* slow down to some cases... */ + SetRenderStates( ctx ); + + switch( ctx->Primitive ) + { + case GL_POINTS: + DPF(( DBG_PRIM_INFO, "GL_POINTS( %d )", VB->Count )); + RenderPointsVB( ctx, 0, VB->Count ); + break; + + case GL_LINES: + case GL_LINE_STRIP: + case GL_LINE_LOOP: + /* Not supported functions yet so pass back that we failed to */ + /* render the vertex buffer and Mesa will have to do it. */ + DPF(( DBG_PRIM_INFO, "GL_LINE_?( %d )", VB->Count )); + return FALSE; + + case GL_TRIANGLES: + if ( VB->Count < 3 ) + { + DPF(( DBG_PRIM_WARN, "GL_TRIANGLES( %d )", VB->Count )); + return FALSE; + } + + DPF(( DBG_PRIM_INFO, "GL_TRIANGLES( %d )", VB->Count )); + RenderTriangleVB( ctx, 0, VB->Count ); + break; + + case GL_TRIANGLE_STRIP: + if ( VB->Count < 3 ) + { + DPF(( DBG_PRIM_WARN, "GL_TRIANGLE_STRIP( %d )", VB->Count )); + return FALSE; + } + + DPF(( DBG_PRIM_INFO, "GL_TRIANGLE_STRIP( %d )", VB->Count )); + RenderTriangleStripVB( ctx, 0, VB->Count ); + break; + + case GL_TRIANGLE_FAN: + if ( VB->Count < 3 ) + { + DPF(( DBG_PRIM_WARN, "GL_TRIANGLE_FAN( %d )", VB->Count )); + return FALSE; + } + + DPF(( DBG_PRIM_INFO, "GL_TRIANGLE_FAN( %d )", VB->Count )); + RenderTriangleFanVB( ctx, 0, VB->Count ); + break; + + case GL_QUADS: + if ( VB->Count < 4 ) + { + DPF(( DBG_PRIM_WARN, "GL_QUADS( %d )", VB->Count )); + return FALSE; + } + + DPF(( DBG_PRIM_INFO, "GL_QUADS( %d )", VB->Count )); + RenderQuadVB( ctx, 0, VB->Count ); + break; + + case GL_QUAD_STRIP: + if ( VB->Count < 4 ) + { + DPF(( DBG_PRIM_WARN, "GL_QUAD_STRIP( %d )", VB->Count )); + return FALSE; + } + + DPF(( DBG_PRIM_INFO, "GL_QUAD_STRIP( %d )", VB->Count )); + + if ( VB->ClipOrMask ) + { + for( index = 3; index < VB->Count; index += 2 ) + { + if ( VB->ClipMask[index-3] & VB->ClipMask[index-2] & VB->ClipMask[index-1] & VB->ClipMask[index] & CLIP_ALL_BITS ) + { + /* All points clipped by common plane */ + DPF(( DBG_PRIM_WARN, "GL_QUAD_STRIP( %d )", VB->Count )); + continue; + } + else if ( VB->ClipMask[index-3] | VB->ClipMask[index-2] | VB->ClipMask[index-1] | VB->ClipMask[index] ) + { + vlist[0] = index - 3; + vlist[1] = index - 2; + vlist[2] = index; + vlist[3] = index - 1; + RenderClippedPolygon( ctx, 4, vlist ); + } + else + { + RenderQuad( ctx, (index-3), (index-2), index, (index-1), index ); + } + } + } + else + { + /* No clipping needed */ + for( index = 3; index < VB->Count; index += 2 ) + RenderQuad( ctx, (index-3), (index-2), index, (index-1), index ); + } + break; + + case GL_POLYGON: + if ( VB->Count < 3 ) + { + DPF(( DBG_PRIM_WARN, "GL_POLYGON( %d )", VB->Count )); + return FALSE; + } + + DPF(( DBG_PRIM_INFO, "GL_POLYGON( %d )", VB->Count )); + + /* All points clipped by common plane, draw nothing */ + if ( !(VB->ClipAndMask & CLIP_ALL_BITS) ) + RenderTriangleFanVB( ctx, 0, VB->Count ); + break; + + default: + /* should never get here */ + _mesa_problem( ctx, "invalid mode in gl_render_vb" ); + } + + DPF(( DBG_PRIM_INFO, "ResetVB" )); + + /* We return TRUE to indicate we rendered the VB. */ + gl_reset_vb( ctx, allDone ); + return TRUE; +} +/*===========================================================================*/ +/* This function will render the current vertex buffer as triangles. The */ +/* buffer has to be able to be rendered directly. This means that we are */ +/* filled, no offsets, no culling and one sided rendering. Also we must be */ +/* in render mode of course. */ +/* First I will fill the global D3D vertice buffer. Next I will set all the*/ +/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ +/* to the wrapper that call DrawPrimitives. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void RenderTriangleVB( GLcontext *ctx, GLuint start, GLuint end ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int index, + cVertex, + height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + DWORD dwPVColor; + GLfloat ex, ey, + fx, fy, c; + GLuint facing; + + DPF(( DBG_FUNC, "RenderTriangleVB" )); + + if ( !VB->ClipOrMask ) + { + DPF(( DBG_PRIM_INFO, "DirectTriangles( %d )", (end-start) )); + for( index = start, cVertex = 0; index < end; ) + { + dwPVColor = (VB->Color[(index+2)][3]<<24) | (VB->Color[(index+2)][0]<<16) | (VB->Color[(index+2)][1]<<8) | VB->Color[(index+2)][2]; + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; + index++; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; + index++; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color= dwPVColor; + index++; + } + } + else + { +#define v1 index +#define v2 (index+1) +#define v3 (index+2) + + for( index = start, cVertex = 0; index < end; index += 3 ) + { + if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & CLIP_ALL_BITS ) + { + continue; + } + else if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] ) + { + VList[0] = v1; + VList[1] = v2; + VList[2] = v3; + RenderClippedPolygon( ctx, 3, VList ); + continue; + } + + /* Compute orientation of triangle */ + ex = VB->Win[v2][0] - VB->Win[v1][0]; + ey = VB->Win[v2][1] - VB->Win[v1][1]; + fx = VB->Win[v3][0] - VB->Win[v1][0]; + fy = VB->Win[v3][1] - VB->Win[v1][1]; + c = (ex * fy) - (ey * fx); + + /* polygon is perpindicular to view plane, don't draw it */ + if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) + continue; + + /* Backface culling. */ + facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; + if ( (facing + 1) & ctx->Polygon.CullBits ) + continue; + + if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) + { + if ( facing == 1 ) + { + /* use back color */ + VB->Color = VB->Bcolor; + VB->Specular= VB->Bspec; + } + else + { + /* use front color */ + VB->Color = VB->Fcolor; + VB->Specular= VB->Fspec; + } + } + + if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) + { + /* Finish computing plane equation of polygon, compute offset */ + GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; + GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; + GLfloat a = (ey * fz) - (ez * fy); + GLfloat b = (ez * fx) - (ex * fz); + OffsetPolygon( ctx, a, b, c ); + } + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + /* Solve the prevoking vertex color as we need it for the 3rd triangle and flat shading. */ + dwPVColor = (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= dwPVColor; + } +#undef v1 +#undef v2 +#undef v3 + } + + /* Render the converted vertex buffer. */ + if ( cVertex > 2 ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); +} +/*===========================================================================*/ +/* This function will render the current vertex buffer as a triangle fan. */ +/* The buffer has to be able to be rendered directly. This means that we are*/ +/* filled, no offsets, no culling and one sided rendering. Also we must be */ +/* in render mode of course. */ +/* First I will fill the global D3D vertice buffer. Next I will set all the*/ +/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ +/* to the wrapper that call DrawPrimitives. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void RenderTriangleFanVB( GLcontext *ctx, GLuint start, GLuint end ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int index, + cVertex, + height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + GLfloat ex, ey, + fx, fy, c; + GLuint facing; + DWORD dwPVColor; + + DPF(( DBG_FUNC, "RenderTriangleFanVB();" )); + + /* Special case that we can blast the fan without culling, offset, etc... */ + if ( !VB->ClipOrMask && (ctx->Light.ShadeModel != GL_FLAT) ) + { + DPF(( DBG_PRIM_INFO, "DirectTriangles( %d )", (end-start) )); + + /* Seed the the fan. */ + D3DTLVertices[0].sx = D3DVAL( VB->Win[start][0] ); + D3DTLVertices[0].sy = D3DVAL( (height - VB->Win[start][1]) ); + D3DTLVertices[0].sz = D3DVAL( VB->Win[start][2] ); + D3DTLVertices[0].tu = D3DVAL( VB->TexCoord[start][0] ); + D3DTLVertices[0].tv = D3DVAL( VB->TexCoord[start][1] ); + D3DTLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[start][3]) ); + D3DTLVertices[0].color= (VB->Color[start][3]<<24) | (VB->Color[start][0]<<16) | (VB->Color[start][1]<<8) | VB->Color[start][2]; + + /* Seed the the fan. */ + D3DTLVertices[1].sx = D3DVAL( VB->Win[(start+1)][0] ); + D3DTLVertices[1].sy = D3DVAL( (height - VB->Win[(start+1)][1]) ); + D3DTLVertices[1].sz = D3DVAL( VB->Win[(start+1)][2] ); + D3DTLVertices[1].tu = D3DVAL( VB->TexCoord[(start+1)][0] ); + D3DTLVertices[1].tv = D3DVAL( VB->TexCoord[(start+1)][1] ); + D3DTLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[(start+1)][3]) ); + D3DTLVertices[1].color= (VB->Color[(start+1)][3]<<24) | (VB->Color[(start+1)][0]<<16) | (VB->Color[(start+1)][1]<<8) | VB->Color[(start+1)][2]; + + for( index = (start+2), cVertex = 2; index < end; index++, cVertex++ ) + { + /*=================================*/ + /* Add the next vertex to the fan. */ + /*=================================*/ + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex].color = (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; + } + + /* Render the converted vertex buffer. */ + if ( cVertex ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLEFAN, &D3DTLVertices[0], cVertex ); + } + else + { +#define v1 start +#define v2 (index-1) +#define v3 index + + for( index = (start+2), cVertex = 0; index < end; index++ ) + { + if ( VB->ClipOrMask ) + { + /* All points clipped by common plane */ + if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & CLIP_ALL_BITS ) + { + continue; + } + else if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] ) + { + VList[0] = v1; + VList[1] = v2; + VList[2] = v3; + RenderClippedPolygon( ctx, 3, VList ); + continue; + } + } + + /* Compute orientation of triangle */ + ex = VB->Win[v2][0] - VB->Win[v1][0]; + ey = VB->Win[v2][1] - VB->Win[v1][1]; + fx = VB->Win[v3][0] - VB->Win[v1][0]; + fy = VB->Win[v3][1] - VB->Win[v1][1]; + c = (ex * fy) - (ey * fx); + + /* polygon is perpindicular to view plane, don't draw it */ + if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) + continue; + + /* Backface culling. */ + facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; + if ( (facing + 1) & ctx->Polygon.CullBits ) + continue; + + if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) + { + /* Finish computing plane equation of polygon, compute offset */ + GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; + GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; + GLfloat a = (ey * fz) - (ez * fy); + GLfloat b = (ez * fx) - (ex * fz); + OffsetPolygon( ctx, a, b, c ); + } + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + dwPVColor = (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= dwPVColor; + } + + /* Render the converted vertex buffer. */ + if ( cVertex ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); +#undef v1 +#undef v2 +#undef v3 + } +} +/*===========================================================================*/ +/* This function will render the current vertex buffer as a triangle strip. */ +/* The buffer has to be able to be rendered directly. This means that we are*/ +/* filled, no offsets, no culling and one sided rendering. Also we must be */ +/* in render mode of course. */ +/* First I will fill the global D3D vertice buffer. Next I will set all the*/ +/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ +/* to the wrapper that call DrawPrimitives. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void RenderTriangleStripVB( GLcontext *ctx, GLuint start, GLuint end ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int index, + cVertex = 0, + v1, v2, v3, + height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + GLfloat ex, ey, + fx, fy, c; + GLuint facing; + DWORD dwPVColor; + + DPF(( DBG_FUNC, "RenderTriangleStripVB();" )); + + /* Special case that we can blast the fan without culling, offset, etc... */ + if ( !VB->ClipOrMask && (ctx->Light.ShadeModel != GL_FLAT) ) + { + DPF(( DBG_PRIM_PROFILE, "DirectTriangles" )); + + /* Seed the the strip. */ + D3DTLVertices[0].sx = D3DVAL( VB->Win[start][0] ); + D3DTLVertices[0].sy = D3DVAL( (height - VB->Win[start][1]) ); + D3DTLVertices[0].sz = D3DVAL( VB->Win[start][2] ); + D3DTLVertices[0].tu = D3DVAL( VB->TexCoord[start][0] ); + D3DTLVertices[0].tv = D3DVAL( VB->TexCoord[start][1] ); + D3DTLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[start][3]) ); + D3DTLVertices[0].color= (VB->Color[start][3]<<24) | (VB->Color[start][0]<<16) | (VB->Color[start][1]<<8) | VB->Color[start][2]; + + /* Seed the the strip. */ + D3DTLVertices[1].sx = D3DVAL( VB->Win[(start+1)][0] ); + D3DTLVertices[1].sy = D3DVAL( (height - VB->Win[(start+1)][1]) ); + D3DTLVertices[1].sz = D3DVAL( VB->Win[(start+1)][2] ); + D3DTLVertices[1].tu = D3DVAL( VB->TexCoord[(start+1)][0] ); + D3DTLVertices[1].tv = D3DVAL( VB->TexCoord[(start+1)][1] ); + D3DTLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[(start+1)][3]) ); + D3DTLVertices[1].color= (VB->Color[(start+1)][3]<<24) | (VB->Color[(start+1)][0]<<16) | (VB->Color[(start+1)][1]<<8) | VB->Color[(start+1)][2]; + + for( index = (start+2), cVertex = 2; index < end; index++, cVertex++ ) + { + /*===================================*/ + /* Add the next vertex to the strip. */ + /*===================================*/ + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[index][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[index][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[index][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[index][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[index][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex].color = (VB->Color[index][3]<<24) | (VB->Color[index][0]<<16) | (VB->Color[index][1]<<8) | VB->Color[index][2]; + } + + /* Render the converted vertex buffer. */ + if ( cVertex ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLESTRIP, &D3DTLVertices[0], cVertex ); + } + else + { + for( index = (start+2); index < end; index++ ) + { + /* We need to switch order so that winding won't be a problem. */ + if ( index & 1 ) + { + v1 = index - 1; + v2 = index - 2; + v3 = index - 0; + } + else + { + v1 = index - 2; + v2 = index - 1; + v3 = index - 0; + } + + /* All vertices clipped by common plane */ + if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & CLIP_ALL_BITS ) + continue; + + /* Check if any vertices need clipping. */ + if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] ) + { + VList[0] = v1; + VList[1] = v2; + VList[2] = v3; + RenderClippedPolygon( ctx, 3, VList ); + } + else + { + /* Compute orientation of triangle */ + ex = VB->Win[v2][0] - VB->Win[v1][0]; + ey = VB->Win[v2][1] - VB->Win[v1][1]; + fx = VB->Win[v3][0] - VB->Win[v1][0]; + fy = VB->Win[v3][1] - VB->Win[v1][1]; + c = (ex * fy) - (ey * fx); + + /* Polygon is perpindicular to view plane, don't draw it */ + if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) + continue; + + /* Backface culling. */ + facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; + if ( (facing + 1) & ctx->Polygon.CullBits ) + continue; + + /* Need right color if we have two sided lighting. */ + if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) + { + if ( facing == 1 ) + { + /* use back color */ + VB->Color = VB->Bcolor; + VB->Specular= VB->Bspec; + } + else + { + /* use front color */ + VB->Color = VB->Fcolor; + VB->Specular= VB->Fspec; + } + } + + if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) + { + /* Finish computing plane equation of polygon, compute offset */ + GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; + GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; + GLfloat a = (ey * fz) - (ez * fy); + GLfloat b = (ez * fx) - (ex * fz); + OffsetPolygon( ctx, a, b, c ); + } + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + + /* Solve the prevoking vertex color as we need it for the 3rd triangle and flat shading. */ + dwPVColor = (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= dwPVColor; + } + } + + /* Render the converted vertex buffer. */ + if ( cVertex ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); + } +} +/*===========================================================================*/ +/* This function will render the current vertex buffer as Quads. The buffer*/ +/* has to be able to be rendered directly. This means that we are filled, no*/ +/* offsets, no culling and one sided rendering. Also we must be in render */ +/* mode of cource. */ +/* First I will fill the global D3D vertice buffer. Next I will set all the*/ +/* states for D3D based on the current OGL state. Finally I pass the D3D VB */ +/* to the wrapper that call DrawPrimitives. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void RenderQuadVB( GLcontext *ctx, GLuint start, GLuint end ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int index, + cVertex, + height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + DWORD dwPVColor; + GLfloat ex, ey, + fx, fy, c; + GLuint facing; /* 0=front, 1=back */ + + DPF(( DBG_FUNC, "RenderQuadVB();" )); + +#define v1 (index) +#define v2 (index+1) +#define v3 (index+2) +#define v4 (index+3) + + if ( !VB->ClipOrMask ) + { + DPF(( DBG_PRIM_PROFILE, "DirectTriangles" )); + + for( cVertex = 0, index = start; index < end; index += 4 ) + { + if ( ctx->Light.ShadeModel == GL_FLAT ) + dwPVColor = (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v1][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v2][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v3][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v1][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v3][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v4][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v4][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( VB->Win[v4][2] ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v4][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v4][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v4][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; + } + } + else + { + for( cVertex = 0, index = start; index < end; index += 4 ) + { + if ( VB->ClipMask[v1] & VB->ClipMask[v2] & VB->ClipMask[v3] & VB->ClipMask[v4] & CLIP_ALL_BITS ) + { + continue; + } + else if ( VB->ClipMask[v1] | VB->ClipMask[v2] | VB->ClipMask[v3] | VB->ClipMask[v4] ) + { + VList[0] = v1; + VList[1] = v2; + VList[2] = v3; + VList[3] = v4; + RenderClippedPolygon( ctx, 4, VList ); + continue; + } + + /* Compute orientation of triangle */ + ex = VB->Win[v2][0] - VB->Win[v1][0]; + ey = VB->Win[v2][1] - VB->Win[v1][1]; + fx = VB->Win[v3][0] - VB->Win[v1][0]; + fy = VB->Win[v3][1] - VB->Win[v1][1]; + c = (ex * fy) - (ey * fx); + + /* polygon is perpindicular to view plane, don't draw it */ + if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) + continue; + + /* Backface culling. */ + facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; + if ( (facing + 1) & ctx->Polygon.CullBits ) + continue; + + if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) + { + if ( facing == 1 ) + { + /* use back color */ + VB->Color = VB->Bcolor; + VB->Specular= VB->Bspec; + } + else + { + /* use front color */ + VB->Color = VB->Fcolor; + VB->Specular= VB->Fspec; + } + } + + if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) + { + /* Finish computing plane equation of polygon, compute offset */ + GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; + GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; + GLfloat a = (ey * fz) - (ez * fy); + GLfloat b = (ez * fx) - (ex * fz); + OffsetPolygon( ctx, a, b, c ); + } + + if ( ctx->Light.ShadeModel == GL_FLAT ) + dwPVColor = (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v2][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v2][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v2][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v2][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v1][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v1][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v1][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v1][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v3][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v3][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v3][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v3][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + D3DTLVertices[cVertex].sx = D3DVAL( VB->Win[v4][0] ); + D3DTLVertices[cVertex].sy = D3DVAL( (height - VB->Win[v4][1]) ); + D3DTLVertices[cVertex].sz = D3DVAL( (VB->Win[v4][2] + ctx->PolygonZoffset) ); + D3DTLVertices[cVertex].tu = D3DVAL( VB->TexCoord[v4][0] ); + D3DTLVertices[cVertex].tv = D3DVAL( VB->TexCoord[v4][1] ); + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[v4][3]) ); + D3DTLVertices[cVertex++].color= (ctx->Light.ShadeModel == GL_FLAT) ? + dwPVColor : + (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; + } + } + +#undef v4 +#undef v3 +#undef v2 +#undef v1 + + /* Render the converted vertex buffer. */ + if ( cVertex ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); +} +/*===========================================================================*/ +/* */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +static void RenderQuad( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4, GLuint pv ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + DWORD dwPVColor; + GLfloat ex, ey, + fx, fy, c; + GLuint facing; /* 0=front, 1=back */ + static D3DTLVERTEX TLVertices[6]; + + DPF(( DBG_FUNC, "RenderQuad" )); + DPF(( DBG_PRIM_INFO, "RenderQuad( 1 )" )); + + /* Compute orientation of triangle */ + ex = VB->Win[v2][0] - VB->Win[v1][0]; + ey = VB->Win[v2][1] - VB->Win[v1][1]; + fx = VB->Win[v3][0] - VB->Win[v1][0]; + fy = VB->Win[v3][1] - VB->Win[v1][1]; + c = (ex * fy) - (ey * fx); + + /* polygon is perpindicular to view plane, don't draw it */ + if ( (c == 0.0F) && !ctx->Polygon.Unfilled ) + return; + + /* Backface culling. */ + facing = (c < 0.0F) ^ ctx->Polygon.FrontBit; + if ( (facing + 1) & ctx->Polygon.CullBits ) + return; + + if ( ctx->IndirectTriangles & DD_TRI_LIGHT_TWOSIDE ) + { + if ( facing == 1 ) + { + /* use back color */ + VB->Color = VB->Bcolor; + VB->Specular= VB->Bspec; + } + else + { + /* use front color */ + VB->Color = VB->Fcolor; + VB->Specular= VB->Fspec; + } + } + + if ( ctx->IndirectTriangles & DD_TRI_OFFSET ) + { + /* Finish computing plane equation of polygon, compute offset */ + GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2]; + GLfloat ez = VB->Win[v2][2] - VB->Win[v1][2]; + GLfloat a = (ey * fz) - (ez * fy); + GLfloat b = (ez * fx) - (ex * fz); + OffsetPolygon( ctx, a, b, c ); + } + + if ( ctx->Light.ShadeModel == GL_FLAT ) + dwPVColor = (VB->Color[pv][3]<<24) | (VB->Color[pv][0]<<16) | (VB->Color[pv][1]<<8) | VB->Color[pv][2]; + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + TLVertices[0].sx = D3DVAL( VB->Win[v1][0] ); + TLVertices[0].sy = D3DVAL( (height - VB->Win[v1][1]) ); + TLVertices[0].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + TLVertices[0].tu = D3DVAL( VB->TexCoord[v1][0] ); + TLVertices[0].tv = D3DVAL( VB->TexCoord[v1][1] ); + TLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + TLVertices[0].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + TLVertices[1].sx = D3DVAL( VB->Win[v2][0] ); + TLVertices[1].sy = D3DVAL( (height - VB->Win[v2][1]) ); + TLVertices[1].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); + TLVertices[1].tu = D3DVAL( VB->TexCoord[v2][0] ); + TLVertices[1].tv = D3DVAL( VB->TexCoord[v2][1] ); + TLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + TLVertices[1].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + TLVertices[2].sx = D3DVAL( VB->Win[v3][0] ); + TLVertices[2].sy = D3DVAL( (height - VB->Win[v3][1]) ); + TLVertices[2].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + TLVertices[2].tu = D3DVAL( VB->TexCoord[v3][0] ); + TLVertices[2].tv = D3DVAL( VB->TexCoord[v3][1] ); + TLVertices[2].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + TLVertices[2].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + TLVertices[3].sx = D3DVAL( VB->Win[v3][0] ); + TLVertices[3].sy = D3DVAL( (height - VB->Win[v3][1]) ); + TLVertices[3].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + TLVertices[3].tu = D3DVAL( VB->TexCoord[v3][0] ); + TLVertices[3].tv = D3DVAL( VB->TexCoord[v3][1] ); + TLVertices[3].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + TLVertices[3].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + + TLVertices[4].sx = D3DVAL( VB->Win[v4][0] ); + TLVertices[4].sy = D3DVAL( (height - VB->Win[v4][1]) ); + TLVertices[4].sz = D3DVAL( (VB->Win[v4][2] + ctx->PolygonZoffset) ); + TLVertices[4].tu = D3DVAL( VB->TexCoord[v4][0] ); + TLVertices[4].tv = D3DVAL( VB->TexCoord[v4][1] ); + TLVertices[4].rhw = D3DVAL( (1.0 / VB->Clip[v4][3]) ); + TLVertices[4].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v4][3]<<24) | (VB->Color[v4][0]<<16) | (VB->Color[v4][1]<<8) | VB->Color[v4][2]; + + TLVertices[5].sx = D3DVAL( VB->Win[v1][0] ); + TLVertices[5].sy = D3DVAL( (height - VB->Win[v1][1]) ); + TLVertices[5].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + TLVertices[5].tu = D3DVAL( VB->TexCoord[v1][0] ); + TLVertices[5].tv = D3DVAL( VB->TexCoord[v1][1] ); + TLVertices[5].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + TLVertices[5].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + /* Draw the two triangles. */ + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &TLVertices[0], 6 ); +} +/*===========================================================================*/ +/* */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +void RenderOneTriangle( GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint pv ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + DWORD dwPVColor; + static D3DTLVERTEX TLVertices[3]; + + DPF(( DBG_FUNC, "RenderOneTriangle" )); + DPF(( DBG_PRIM_INFO, "RenderTriangle( 1 )" )); + + /*=====================================*/ + /* Populate the the triangle vertices. */ + /*=====================================*/ + if ( ctx->Light.ShadeModel == GL_FLAT ) + dwPVColor = (VB->Color[pv][3]<<24) | (VB->Color[pv][0]<<16) | (VB->Color[pv][1]<<8) | VB->Color[pv][2]; + + TLVertices[0].sx = D3DVAL( VB->Win[v1][0] ); + TLVertices[0].sy = D3DVAL( (height - VB->Win[v1][1]) ); + TLVertices[0].sz = D3DVAL( (VB->Win[v1][2] + ctx->PolygonZoffset) ); + TLVertices[0].tu = D3DVAL( VB->TexCoord[v1][0] ); + TLVertices[0].tv = D3DVAL( VB->TexCoord[v1][1] ); + TLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + TLVertices[0].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + DPF(( DBG_PRIM_INFO, "V1 -> x:%f y:%f z:%f c:%x", + TLVertices[0].sx, + TLVertices[0].sy, + TLVertices[0].sz, + TLVertices[0].color )); + + TLVertices[1].sx = D3DVAL( VB->Win[v2][0] ); + TLVertices[1].sy = D3DVAL( (height - VB->Win[v2][1]) ); + TLVertices[1].sz = D3DVAL( (VB->Win[v2][2] + ctx->PolygonZoffset) ); + TLVertices[1].tu = D3DVAL( VB->TexCoord[v2][0] ); + TLVertices[1].tv = D3DVAL( VB->TexCoord[v2][1] ); + TLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + TLVertices[1].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + DPF(( DBG_PRIM_INFO, "V2 -> x:%f y:%f z:%f c:%x", + TLVertices[1].sx, + TLVertices[1].sy, + TLVertices[1].sz, + TLVertices[1].color )); + + TLVertices[2].sx = D3DVAL( VB->Win[v3][0] ); + TLVertices[2].sy = D3DVAL( (height - VB->Win[v3][1]) ); + TLVertices[2].sz = D3DVAL( (VB->Win[v3][2] + ctx->PolygonZoffset) ); + TLVertices[2].tu = D3DVAL( VB->TexCoord[v3][0] ); + TLVertices[2].tv = D3DVAL( VB->TexCoord[v3][1] ); + TLVertices[2].rhw = D3DVAL( (1.0 / VB->Clip[v3][3]) ); + TLVertices[2].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v3][3]<<24) | (VB->Color[v3][0]<<16) | (VB->Color[v3][1]<<8) | VB->Color[v3][2]; + DPF(( DBG_PRIM_INFO, "V3 -> x:%f y:%f z:%f c:%x", + TLVertices[2].sx, + TLVertices[2].sy, + TLVertices[2].sz, + TLVertices[2].color )); + + /* Draw the triangle. */ + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &TLVertices[0], 3 ); +} +/*===========================================================================*/ +/* */ +/*===========================================================================*/ +/* RETURN: TRUE, FALSE. */ +/*===========================================================================*/ +void RenderOneLine( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + int height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + DWORD dwPVColor; + static D3DTLVERTEX TLVertices[2]; + + DPF(( DBG_FUNC, "RenderOneLine" )); + DPF(( DBG_PRIM_INFO, "RenderLine( 1 )" )); + + if ( VB->MonoColor ) + dwPVColor = (pContext->aCurrent<<24) | (pContext->rCurrent<<16) | (pContext->gCurrent<<8) | pContext->bCurrent; + else + dwPVColor = (VB->Color[pv][3]<<24) | (VB->Color[pv][0]<<16) | (VB->Color[pv][1]<<8) | VB->Color[pv][2]; + + TLVertices[0].sx = D3DVAL( VB->Win[v1][0] ); + TLVertices[0].sy = D3DVAL( (height - VB->Win[v1][1]) ); + TLVertices[0].sz = D3DVAL( (VB->Win[v1][2] + ctx->LineZoffset) ); + TLVertices[0].tu = D3DVAL( VB->TexCoord[v1][0] ); + TLVertices[0].tv = D3DVAL( VB->TexCoord[v1][1] ); + TLVertices[0].rhw = D3DVAL( (1.0 / VB->Clip[v1][3]) ); + TLVertices[0].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v1][3]<<24) | (VB->Color[v1][0]<<16) | (VB->Color[v1][1]<<8) | VB->Color[v1][2]; + + TLVertices[1].sx = D3DVAL( VB->Win[v2][0] ); + TLVertices[1].sy = D3DVAL( (height - VB->Win[v2][1]) ); + TLVertices[1].sz = D3DVAL( (VB->Win[v2][2] + ctx->LineZoffset) ); + TLVertices[1].tu = D3DVAL( VB->TexCoord[v2][0] ); + TLVertices[1].tv = D3DVAL( VB->TexCoord[v2][1] ); + TLVertices[1].rhw = D3DVAL( (1.0 / VB->Clip[v2][3]) ); + TLVertices[1].color = (ctx->Light.ShadeModel == GL_FLAT) ? dwPVColor : + (VB->Color[v2][3]<<24) | (VB->Color[v2][0]<<16) | (VB->Color[v2][1]<<8) | VB->Color[v2][2]; + + /* Draw line from (x0,y0) to (x1,y1) with current pixel color/index */ + DrawPrimitiveHAL( pContext->pShared, D3DPT_LINELIST, &TLVertices[0], 2 ); +} +/*===========================================================================*/ +/* This function was written to convert points into triangles. I did this */ +/* as all card accelerate triangles and most drivers do this anyway. In hind*/ +/* thought this might be a bad idea as some cards do better. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void RenderPointsVB( GLcontext *ctx, GLuint start, GLuint end ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + struct pixel_buffer *PB = ctx->PB; + GLuint index; + GLfloat radius, z, + xmin, ymin, + xmax, ymax; + GLint cVertex, + height = (pContext->pShared->rectW.bottom - pContext->pShared->rectW.top); + DWORD dwPVColor; + + DPF(( DBG_FUNC, "RenderPointsVB();" )); + + radius = CLAMP( ctx->Point.Size, MIN_POINT_SIZE, MAX_POINT_SIZE ) * 0.5F; + + for( index = start, cVertex = 0; index <= end; index++ ) + { + if ( VB->ClipMask[index] == 0 ) + { + xmin = D3DVAL( VB->Win[index][0] - radius ); + xmax = D3DVAL( VB->Win[index][0] + radius ); + ymin = D3DVAL( height - VB->Win[index][1] - radius ); + ymax = D3DVAL( height - VB->Win[index][1] + radius ); + z = D3DVAL( (VB->Win[index][2] + ctx->PointZoffset) ); + + dwPVColor = (VB->Color[index][3]<<24) | + (VB->Color[index][0]<<16) | + (VB->Color[index][1]<<8) | + VB->Color[index][2]; + + D3DTLVertices[cVertex].sx = xmin; + D3DTLVertices[cVertex].sy = ymax; + D3DTLVertices[cVertex].sz = z; + D3DTLVertices[cVertex].tu = 0.0; + D3DTLVertices[cVertex].tv = 0.0; + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color = dwPVColor; + + D3DTLVertices[cVertex].sx = xmin; + D3DTLVertices[cVertex].sy = ymin; + D3DTLVertices[cVertex].sz = z; + D3DTLVertices[cVertex].tu = 0.0; + D3DTLVertices[cVertex].tv = 0.0; + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color = dwPVColor; + + D3DTLVertices[cVertex].sx = xmax; + D3DTLVertices[cVertex].sy = ymin; + D3DTLVertices[cVertex].sz = z; + D3DTLVertices[cVertex].tu = 0.0; + D3DTLVertices[cVertex].tv = 0.0; + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color = dwPVColor; + + D3DTLVertices[cVertex].sx = xmax; + D3DTLVertices[cVertex].sy = ymin; + D3DTLVertices[cVertex].sz = z; + D3DTLVertices[cVertex].tu = 0.0; + D3DTLVertices[cVertex].tv = 0.0; + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color = dwPVColor; + + D3DTLVertices[cVertex].sx = xmax; + D3DTLVertices[cVertex].sy = ymax; + D3DTLVertices[cVertex].sz = z; + D3DTLVertices[cVertex].tu = 0.0; + D3DTLVertices[cVertex].tv = 0.0; + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color = dwPVColor; + + D3DTLVertices[cVertex].sx = xmin; + D3DTLVertices[cVertex].sy = ymax; + D3DTLVertices[cVertex].sz = z; + D3DTLVertices[cVertex].tu = 0.0; + D3DTLVertices[cVertex].tv = 0.0; + D3DTLVertices[cVertex].rhw = D3DVAL( (1.0 / VB->Clip[index][3]) ); + D3DTLVertices[cVertex++].color = dwPVColor; + } + } + + /* Render the converted vertex buffer. */ + if ( cVertex ) + DrawPrimitiveHAL( pContext->pShared, D3DPT_TRIANGLELIST, &D3DTLVertices[0], cVertex ); +} +/*===========================================================================*/ +/* This gets call before we render any primitives so that the current OGL */ +/* states will be mapped the D3D context. I'm still not sure how D3D works */ +/* but I'm finding that it doesn't act like a state machine as OGL is. It */ +/* looks like the state gets set back to the defaults after a DrawPrimitives */ +/* or an EndScene. Also I set states that are the default even though this */ +/* is redundant as the defaults seem screwed up. */ +/* TODO: make a batch call. */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void SetRenderStates( GLcontext *ctx ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DWORD dwFunc; + static BOOL bTexture = FALSE; + static int texName = -1; + + DPF(( DBG_FUNC, "SetRenderStates();" )); + + if ( g_DBGMask & DBG_STATES ) + DebugRenderStates( ctx, FALSE ); + + SetStateHAL( pContext->pShared, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); + SetStateHAL( pContext->pShared, D3DRENDERSTATE_DITHERENABLE, (ctx->Color.DitherFlag) ? TRUE : FALSE ); + + /*================================================*/ + /* Check too see if there are new TEXTURE states. */ + /*================================================*/ + if ( ctx->Texture._EnabledUnits ) + { + switch( ctx->Texture.Set[ctx->Texture.CurrentSet].EnvMode ) + { + case GL_MODULATE: + if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format == GL_RGBA ) + dwFunc = pContext->pShared->dwTexFunc[d3dtblend_modulatealpha]; + else + dwFunc = pContext->pShared->dwTexFunc[d3dtblend_modulate]; + break; + + case GL_BLEND: + dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decalalpha]; + break; + + case GL_REPLACE: + dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decal]; + break; + + case GL_DECAL: + if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format == GL_RGBA ) + dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decalalpha]; + else + dwFunc = pContext->pShared->dwTexFunc[d3dtblend_decal]; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_TEXTUREMAPBLEND, dwFunc ); + + switch( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MagFilter ) + { + case GL_NEAREST: + dwFunc = D3DFILTER_NEAREST; + break; + case GL_LINEAR: + dwFunc = D3DFILTER_LINEAR; + break; + case GL_NEAREST_MIPMAP_NEAREST: + dwFunc = D3DFILTER_MIPNEAREST; + break; + case GL_LINEAR_MIPMAP_NEAREST: + dwFunc = D3DFILTER_LINEARMIPNEAREST; + break; + case GL_NEAREST_MIPMAP_LINEAR: + dwFunc = D3DFILTER_MIPLINEAR; + break; + case GL_LINEAR_MIPMAP_LINEAR: + dwFunc = D3DFILTER_LINEARMIPLINEAR; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_TEXTUREMAG, dwFunc ); + + switch( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MinFilter ) + { + case GL_NEAREST: + dwFunc = D3DFILTER_NEAREST; + break; + case GL_LINEAR: + dwFunc = D3DFILTER_LINEAR; + break; + case GL_NEAREST_MIPMAP_NEAREST: + dwFunc = D3DFILTER_MIPNEAREST; + break; + case GL_LINEAR_MIPMAP_NEAREST: + dwFunc = D3DFILTER_LINEARMIPNEAREST; + break; + case GL_NEAREST_MIPMAP_LINEAR: + dwFunc = D3DFILTER_MIPLINEAR; + break; + case GL_LINEAR_MIPMAP_LINEAR: + dwFunc = D3DFILTER_LINEARMIPLINEAR; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_TEXTUREMIN, dwFunc ); + + /* Another hack to cut down on redundant texture binding. */ + // if ( texName != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name ) + // { + texName = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name; + CreateTMgrHAL( pContext->pShared, + texName, + 0, + ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format, + (RECT *)NULL, + ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Width, + ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Height, + TM_ACTION_BIND, + (void *)ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Data ); + // } + bTexture = TRUE; + } + else + { + /* This is nasty but should cut down on the number of redundant calls. */ + if ( bTexture == TRUE ) + { + DisableTMgrHAL( pContext->pShared ); + bTexture = FALSE; + } + } + + /*===============================================*/ + /* Check too see if there are new RASTER states. */ + /*===============================================*/ + + // TODO: no concept of front & back. + switch( ctx->Polygon.FrontMode ) + { + case GL_POINT: + SetStateHAL( pContext->pShared, D3DRENDERSTATE_FILLMODE, D3DFILL_POINT ); + break; + case GL_LINE: + SetStateHAL( pContext->pShared, D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME ); + break; + case GL_FILL: + SetStateHAL( pContext->pShared, D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID ); + break; + } + + /*************/ + /* Z-Buffer. */ + /*************/ + if ( ctx->Depth.Test == GL_TRUE ) + { + switch( ctx->Depth.Func ) + { + case GL_NEVER: + dwFunc = D3DCMP_NEVER; + break; + case GL_LESS: + dwFunc = D3DCMP_LESS; + break; + case GL_GEQUAL: + dwFunc = D3DCMP_GREATEREQUAL; + break; + case GL_LEQUAL: + dwFunc = D3DCMP_LESSEQUAL; + break; + case GL_GREATER: + dwFunc = D3DCMP_GREATER; + break; + case GL_NOTEQUAL: + dwFunc = D3DCMP_NOTEQUAL; + break; + case GL_EQUAL: + dwFunc = D3DCMP_EQUAL; + break; + case GL_ALWAYS: + dwFunc = D3DCMP_ALWAYS; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZFUNC, dwFunc ); + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZENABLE, TRUE ); + } + else + { + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZENABLE, FALSE ); + } + + /*******************/ + /* Z-Write Enable. */ + /*******************/ + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ZWRITEENABLE , (ctx->Depth.Mask == GL_TRUE) ? TRUE : FALSE ); + + /***************/ + /* Alpha test. */ + /***************/ + if ( ctx->Color.AlphaEnabled == GL_TRUE ) + { + switch( ctx->Color.AlphaFunc ) + { + case GL_NEVER: + dwFunc = D3DCMP_NEVER; + break; + case GL_LESS: + dwFunc = D3DCMP_LESS; + break; + case GL_GEQUAL: + dwFunc = D3DCMP_GREATEREQUAL; + break; + case GL_LEQUAL: + dwFunc = D3DCMP_LESSEQUAL; + break; + case GL_GREATER: + dwFunc = D3DCMP_GREATER; + break; + case GL_NOTEQUAL: + dwFunc = D3DCMP_NOTEQUAL; + break; + case GL_EQUAL: + dwFunc = D3DCMP_EQUAL; + break; + case GL_ALWAYS: + dwFunc = D3DCMP_ALWAYS; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHAFUNC , dwFunc ); + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); + } + else + { + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); + } + + /****************/ + /* Alpha blend. */ + /****************/ + if ( ctx->Color.BlendEnabled == GL_TRUE ) + { + switch( ctx->Color.BlendSrc ) + { + case GL_ZERO: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_zero]; + break; + case GL_ONE: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_one]; + break; + case GL_DST_COLOR: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_dst_color]; + break; + case GL_ONE_MINUS_DST_COLOR: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_dst_color]; + break; + case GL_SRC_ALPHA: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_src_alpha]; + break; + case GL_ONE_MINUS_SRC_ALPHA: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_src_alpha]; + break; + case GL_DST_ALPHA: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_dst_alpha]; + break; + case GL_ONE_MINUS_DST_ALPHA: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_dst_alpha]; + break; + case GL_SRC_ALPHA_SATURATE: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_src_alpha_saturate]; + break; + case GL_CONSTANT_COLOR: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_constant_color]; + break; + case GL_ONE_MINUS_CONSTANT_COLOR: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_constant_color]; + break; + case GL_CONSTANT_ALPHA: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_constant_alpha]; + break; + case GL_ONE_MINUS_CONSTANT_ALPHA: + dwFunc = pContext->pShared->dwSrcBlendCaps[s_one_minus_constant_alpha]; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_SRCBLEND, dwFunc ); + + switch( ctx->Color.BlendDst ) + { + case GL_ZERO: + dwFunc = pContext->pShared->dwDestBlendCaps[d_zero]; + break; + case GL_ONE: + dwFunc = pContext->pShared->dwDestBlendCaps[d_one]; + break; + case GL_SRC_COLOR: + dwFunc = pContext->pShared->dwDestBlendCaps[d_src_color]; + break; + case GL_ONE_MINUS_SRC_COLOR: + dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_src_color]; + break; + case GL_SRC_ALPHA: + dwFunc = pContext->pShared->dwDestBlendCaps[d_src_alpha]; + break; + case GL_ONE_MINUS_SRC_ALPHA: + dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_src_alpha]; + break; + case GL_DST_ALPHA: + dwFunc = pContext->pShared->dwDestBlendCaps[d_dst_alpha]; + break; + case GL_ONE_MINUS_DST_ALPHA: + dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_dst_alpha]; + break; + case GL_CONSTANT_COLOR: + dwFunc = pContext->pShared->dwDestBlendCaps[d_constant_color]; + break; + case GL_ONE_MINUS_CONSTANT_COLOR: + dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_constant_color]; + break; + case GL_CONSTANT_ALPHA: + dwFunc = pContext->pShared->dwDestBlendCaps[d_constant_alpha]; + break; + case GL_ONE_MINUS_CONSTANT_ALPHA: + dwFunc = pContext->pShared->dwDestBlendCaps[d_one_minus_constant_alpha]; + break; + } + SetStateHAL( pContext->pShared, D3DRENDERSTATE_DESTBLEND, dwFunc ); + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); + } + else + { + SetStateHAL( pContext->pShared, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); + } +} +/*===========================================================================*/ +/* If this function is called it will track the changes to the current */ +/* states that I'm setting in Direct3D. I did this so that the DPF's would */ +/* be under control! */ +/*===========================================================================*/ +/* RETURN: */ +/*===========================================================================*/ +static void DebugRenderStates( GLcontext *ctx, BOOL bForce ) +{ + D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx; + DWORD dwFunc; + static int dither = -1, + texture = -1, + textName = -1, + textEnv = -1, + textMin = -1, + textMag = -1, + polyMode = -1, + depthTest = -1, + depthFunc = -1, + depthMask = -1, + alphaTest = -1, + alphaFunc = -1, + blend = -1, + blendSrc = -1, + blendDest = -1; + + /* Force a displayed update of all current states. */ + if ( bForce ) + { + dither = texture = textName = textEnv = textMin = textMag = -1; + polyMode = depthTest = depthFunc = depthMask = -1; + alphaTest = alphaFunc = blend = blendSrc = blendDest = -1; + } + + if ( dither != ctx->Color.DitherFlag ) + { + dither = ctx->Color.DitherFlag; + DPF(( 0, "\tDither\t\t%s", (dither) ? "ENABLED" : "--------" )); + } + if ( depthTest != ctx->Depth.Test ) + { + depthTest = ctx->Depth.Test; + DPF(( 0, "\tDepth Test\t%s", (depthTest) ? "ENABLED" : "--------" )); + } + if ( alphaTest != ctx->Color.AlphaEnabled ) + { + alphaTest = ctx->Color.AlphaEnabled; + + DPF(( 0, "\tAlpha Test\t%s", (alphaTest) ? "ENABLED" : "--------" )); + } + if ( blend != ctx->Color.BlendEnabled ) + { + blend = ctx->Color.BlendEnabled; + + DPF(( 0, "\tBlending\t%s", (blend) ? "ENABLED" : "--------" )); + } + + /*================================================*/ + /* Check too see if there are new TEXTURE states. */ + /*================================================*/ + if ( texture != ctx->Texture._EnabledUnits ) + { + texture = ctx->Texture._EnabledUnits; + DPF(( 0, "\tTexture\t\t%s", (texture) ? "ENABLED" : "--------" )); + } + + if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current ) + { + if ( ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name != textName ) + { + textName = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name; + DPF(( 0, "\tTexture Name:\t%d", textName )); + DPF(( 0, "\tTexture Format:\t%s", + (ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Image[0][0]->Format == GL_RGBA) ? + "GL_RGBA" : "GLRGB" )); + } + + if ( textEnv != ctx->Texture.Set[ctx->Texture.CurrentSet].EnvMode ) + { + textEnv = ctx->Texture.Set[ctx->Texture.CurrentSet].EnvMode; + + switch( textEnv ) + { + case GL_MODULATE: + DPF(( 0, "\tTexture\tMode\tGL_MODULATE" )); + break; + case GL_BLEND: + DPF(( 0, "\tTexture\tMode\tGL_BLEND" )); + break; + case GL_REPLACE: + DPF(( 0, "\tTexture\tMode\tGL_REPLACE" )); + break; + case GL_DECAL: + DPF(( 0, "\tTexture\tMode\tGL_DECAL" )); + break; + } + } + + if ( textMag != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MagFilter ) + { + textMag = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MagFilter; + + switch( textMag ) + { + case GL_NEAREST: + DPF(( 0, "\tTexture MAG\tGL_NEAREST" )); + break; + case GL_LINEAR: + DPF(( 0, "\tTexture MAG\tGL_LINEAR" )); + break; + case GL_NEAREST_MIPMAP_NEAREST: + DPF(( 0, "\tTexture MAG\tGL_NEAREST_MIPMAP_NEAREST" )); + break; + case GL_LINEAR_MIPMAP_NEAREST: + DPF(( 0, "\tTexture MAG\tGL_LINEAR_MIPMAP_NEAREST" )); + break; + case GL_NEAREST_MIPMAP_LINEAR: + DPF(( 0, "\tTexture MAG\tGL_NEAREST_MIPMAP_LINEAR" )); + break; + case GL_LINEAR_MIPMAP_LINEAR: + DPF(( 0, "\tTexture MAG\tGL_LINEAR_MIPMAP_LINEAR" )); + break; + } + } + + if ( textMin != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MinFilter ) + { + textMin = ctx->Texture.Set[ctx->Texture.CurrentSet].Current->MinFilter; + + switch( textMin ) + { + case GL_NEAREST: + DPF(( 0, "\tTexture MIN\tGL_NEAREST" )); + break; + case GL_LINEAR: + DPF(( 0, "\tTexture MIN\tGL_LINEAR" )); + break; + case GL_NEAREST_MIPMAP_NEAREST: + DPF(( 0, "\tTexture MIN\tGL_NEAREST_MIPMAP_NEAREST" )); + break; + case GL_LINEAR_MIPMAP_NEAREST: + DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_NEAREST" )); + break; + case GL_NEAREST_MIPMAP_LINEAR: + DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_LINEAR" )); + break; + case GL_LINEAR_MIPMAP_LINEAR: + DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_LINEAR" )); + break; + } + } + } + + if ( ctx->Polygon.FrontMode != polyMode ) + { + polyMode = ctx->Polygon.FrontMode; + + switch( polyMode ) + { + case GL_POINT: + DPF(( 0, "\tMode\t\tGL_POINT" )); + break; + case GL_LINE: + DPF(( 0, "\tMode\t\tGL_LINE" )); + break; + case GL_FILL: + DPF(( 0, "\tMode\t\tGL_FILL" )); + break; + } + } + + if ( depthFunc != ctx->Depth.Func ) + { + depthFunc = ctx->Depth.Func; + + switch( depthFunc ) + { + case GL_NEVER: + DPF(( 0, "\tDepth Func\tGL_NEVER" )); + break; + case GL_LESS: + DPF(( 0, "\tDepth Func\tGL_LESS" )); + break; + case GL_GEQUAL: + DPF(( 0, "\tDepth Func\tGL_GEQUAL" )); + break; + case GL_LEQUAL: + DPF(( 0, "\tDepth Func\tGL_LEQUAL" )); + break; + case GL_GREATER: + DPF(( 0, "\tDepth Func\tGL_GREATER" )); + break; + case GL_NOTEQUAL: + DPF(( 0, "\tDepth Func\tGL_NOTEQUAL" )); + break; + case GL_EQUAL: + DPF(( 0, "\tDepth Func\tGL_EQUAL" )); + break; + case GL_ALWAYS: + DPF(( 0, "\tDepth Func\tGL_ALWAYS" )); + break; + } + } + + if ( depthMask != ctx->Depth.Mask ) + { + depthMask = ctx->Depth.Mask; + DPF(( 0, "\tZWrite\t\t%s", (depthMask) ? "ENABLED" : "--------" )); + } + + if ( alphaFunc != ctx->Color.AlphaFunc ) + { + alphaFunc = ctx->Color.AlphaFunc; + + switch( alphaFunc ) + { + case GL_NEVER: + DPF(( 0, "\tAlpha Func\tGL_NEVER" )); + break; + case GL_LESS: + DPF(( 0, "\tAlpha Func\tGL_LESS" )); + break; + case GL_GEQUAL: + DPF(( 0, "\tAlpha Func\tGL_GEQUAL" )); + break; + case GL_LEQUAL: + DPF(( 0, "\tAlpha Func\tGL_LEQUAL" )); + break; + case GL_GREATER: + DPF(( 0, "\tAlpha Func\tGL_GREATER" )); + break; + case GL_NOTEQUAL: + DPF(( 0, "\tAlpha Func\tGL_NOTEQUAL" )); + break; + case GL_EQUAL: + DPF(( 0, "\tAlpha Func\tGL_EQUAL" )); + break; + case GL_ALWAYS: + DPF(( 0, "\tAlpha Func\tGL_ALWAYS" )); + break; + } + } + + if ( blendSrc != ctx->Color.BlendSrc ) + { + blendSrc = ctx->Color.BlendSrc; + + switch( blendSrc ) + { + case GL_ZERO: + DPF(( 0, "\tSRC Blend\tGL_ZERO" )); + break; + case GL_ONE: + DPF(( 0, "\tSRC Blend\tGL_ONE" )); + break; + case GL_DST_COLOR: + DPF(( 0, "\tSRC Blend\tGL_DST_COLOR" )); + break; + case GL_ONE_MINUS_DST_COLOR: + DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_DST_COLOR" )); + break; + case GL_SRC_ALPHA: + DPF(( 0, "\tSRC Blend\tGL_SRC_ALPHA" )); + break; + case GL_ONE_MINUS_SRC_ALPHA: + DPF(( 0, "\tSRC Blend\tGL_MINUS_SRC_ALPHA" )); + break; + case GL_DST_ALPHA: + DPF(( 0, "\tSRC Blend\tGL_DST_ALPHA" )); + break; + case GL_ONE_MINUS_DST_ALPHA: + DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_DST_ALPHA" )); + break; + case GL_SRC_ALPHA_SATURATE: + DPF(( 0, "\tSRC Blend\tGL_SRC_ALPHA_SATURATE" )); + break; + case GL_CONSTANT_COLOR: + DPF(( 0, "\tSRC Blend\tGL_CONSTANT_COLOR" )); + break; + case GL_ONE_MINUS_CONSTANT_COLOR: + DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_CONSTANT_COLOR" )); + break; + case GL_CONSTANT_ALPHA: + DPF(( 0, "\tSRC Blend\tGL_CONSTANT_ALPHA" )); + break; + case GL_ONE_MINUS_CONSTANT_ALPHA: + DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_CONSTANT_ALPHA" )); + break; + } + } + + if ( blendDest != ctx->Color.BlendDst ) + { + blendDest = ctx->Color.BlendDst; + + switch( blendDest ) + { + case GL_ZERO: + DPF(( 0, "\tDST Blend\tGL_ZERO" )); + break; + case GL_ONE: + DPF(( 0, "\tDST Blend\tGL_ONE" )); + break; + case GL_SRC_COLOR: + DPF(( 0, "\tDST Blend\tGL_SRC_COLOR" )); + break; + case GL_ONE_MINUS_SRC_COLOR: + DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_SRC_COLOR" )); + break; + case GL_SRC_ALPHA: + DPF(( 0, "\tDST Blend\tGL_SRC_ALPHA" )); + break; + case GL_ONE_MINUS_SRC_ALPHA: + DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_SRC_ALPHA" )); + break; + case GL_DST_ALPHA: + DPF(( 0, "\tDST Blend\tGL_DST_ALPHA" )); + break; + case GL_ONE_MINUS_DST_ALPHA: + DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_DST_ALPHA" )); + break; + case GL_CONSTANT_COLOR: + DPF(( 0, "\tDST Blend\tGL_CONSTANT_COLOR" )); + break; + case GL_ONE_MINUS_CONSTANT_COLOR: + DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_CONSTANT_COLOR" )); + break; + case GL_CONSTANT_ALPHA: + DPF(( 0, "\tDST Blend\tGL_CONSTANT_ALPHA" )); + break; + case GL_ONE_MINUS_CONSTANT_ALPHA: + DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_CONSTANT_ALPHA" )); + break; + } + } +} --- mesa-7.2.orig/src/mesa/shader/arbprogram.syn +++ mesa-7.2/src/mesa/shader/arbprogram.syn @@ -0,0 +1,2824 @@ +/* + * Mesa 3-D graphics library + * Version: 6.2 + * + * Copyright (C) 1999-2004 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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 arbprogram.syn + * ARB_fragment/vertex_program syntax + * \author Michal Krol + */ + +.syntax program; + +/* + This value must be incremented every time emit code values or structure of the production + array changes. This value is placed at the beginning of the production array. The loader + compares the value with its REVISION value. If they do not match, the loader is not up + to date. +*/ +.emtcode REVISION 0x0a + +/* program type */ +.emtcode FRAGMENT_PROGRAM 0x01 +.emtcode VERTEX_PROGRAM 0x02 + +/* program section */ +.emtcode OPTION 0x01 +.emtcode INSTRUCTION 0x02 +.emtcode DECLARATION 0x03 +.emtcode END 0x04 + +/* GL_ARB_fragment_program option */ +.emtcode ARB_PRECISION_HINT_FASTEST 0x00 +.emtcode ARB_PRECISION_HINT_NICEST 0x01 +.emtcode ARB_FOG_EXP 0x02 +.emtcode ARB_FOG_EXP2 0x03 +.emtcode ARB_FOG_LINEAR 0x04 + +/* GL_ARB_vertex_program option */ +.emtcode ARB_POSITION_INVARIANT 0x05 + +/* GL_ARB_fragment_program_shadow option */ +.emtcode ARB_FRAGMENT_PROGRAM_SHADOW 0x06 + +/* GL_ARB_draw_buffers option */ +.emtcode ARB_DRAW_BUFFERS 0x07 + +/* GL_MESA_texture_array option */ +.emtcode MESA_TEXTURE_ARRAY 0x08 + +/* GL_ARB_fragment_program instruction class */ +.emtcode OP_ALU_INST 0x00 +.emtcode OP_TEX_INST 0x01 + +/* GL_ARB_vertex_program instruction class */ +/* OP_ALU_INST */ + +/* GL_ARB_fragment_program instruction type */ +.emtcode OP_ALU_VECTOR 0x00 +.emtcode OP_ALU_SCALAR 0x01 +.emtcode OP_ALU_BINSC 0x02 +.emtcode OP_ALU_BIN 0x03 +.emtcode OP_ALU_TRI 0x04 +.emtcode OP_ALU_SWZ 0x05 +.emtcode OP_TEX_SAMPLE 0x06 +.emtcode OP_TEX_KIL 0x07 + +/* GL_ARB_vertex_program instruction type */ +.emtcode OP_ALU_ARL 0x08 +/* OP_ALU_VECTOR */ +/* OP_ALU_SCALAR */ +/* OP_ALU_BINSC */ +/* OP_ALU_BIN */ +/* OP_ALU_TRI */ +/* OP_ALU_SWZ */ + +/* GL_ARB_fragment_program instruction code */ +.emtcode OP_ABS 0x00 +.emtcode OP_ABS_SAT 0x1B +.emtcode OP_FLR 0x09 +.emtcode OP_FLR_SAT 0x26 +.emtcode OP_FRC 0x0A +.emtcode OP_FRC_SAT 0x27 +.emtcode OP_LIT 0x0C +.emtcode OP_LIT_SAT 0x2A +.emtcode OP_MOV 0x11 +.emtcode OP_MOV_SAT 0x30 +.emtcode OP_COS 0x1F +.emtcode OP_COS_SAT 0x20 +.emtcode OP_EX2 0x07 +.emtcode OP_EX2_SAT 0x25 +.emtcode OP_LG2 0x0B +.emtcode OP_LG2_SAT 0x29 +.emtcode OP_RCP 0x14 +.emtcode OP_RCP_SAT 0x33 +.emtcode OP_RSQ 0x15 +.emtcode OP_RSQ_SAT 0x34 +.emtcode OP_SIN 0x38 +.emtcode OP_SIN_SAT 0x39 +.emtcode OP_SCS 0x35 +.emtcode OP_SCS_SAT 0x36 +.emtcode OP_POW 0x13 +.emtcode OP_POW_SAT 0x32 +.emtcode OP_ADD 0x01 +.emtcode OP_ADD_SAT 0x1C +.emtcode OP_DP3 0x03 +.emtcode OP_DP3_SAT 0x21 +.emtcode OP_DP4 0x04 +.emtcode OP_DP4_SAT 0x22 +.emtcode OP_DPH 0x05 +.emtcode OP_DPH_SAT 0x23 +.emtcode OP_DST 0x06 +.emtcode OP_DST_SAT 0x24 +.emtcode OP_MAX 0x0F +.emtcode OP_MAX_SAT 0x2E +.emtcode OP_MIN 0x10 +.emtcode OP_MIN_SAT 0x2F +.emtcode OP_MUL 0x12 +.emtcode OP_MUL_SAT 0x31 +.emtcode OP_SGE 0x16 +.emtcode OP_SGE_SAT 0x37 +.emtcode OP_SLT 0x17 +.emtcode OP_SLT_SAT 0x3A +.emtcode OP_SUB 0x18 +.emtcode OP_SUB_SAT 0x3B +.emtcode OP_XPD 0x1A +.emtcode OP_XPD_SAT 0x43 +.emtcode OP_CMP 0x1D +.emtcode OP_CMP_SAT 0x1E +.emtcode OP_LRP 0x2B +.emtcode OP_LRP_SAT 0x2C +.emtcode OP_MAD 0x0E +.emtcode OP_MAD_SAT 0x2D +.emtcode OP_SWZ 0x19 +.emtcode OP_SWZ_SAT 0x3C +.emtcode OP_TEX 0x3D +.emtcode OP_TEX_SAT 0x3E +.emtcode OP_TXB 0x3F +.emtcode OP_TXB_SAT 0x40 +.emtcode OP_TXP 0x41 +.emtcode OP_TXP_SAT 0x42 +.emtcode OP_KIL 0x28 + +/* GL_ARB_vertex_program instruction code */ +.emtcode OP_ARL 0x02 +/* OP_ABS */ +/* OP_FLR */ +/* OP_FRC */ +/* OP_LIT */ +/* OP_MOV */ +/* OP_EX2 */ +.emtcode OP_EXP 0x08 +/* OP_LG2 */ +.emtcode OP_LOG 0x0D +/* OP_RCP */ +/* OP_RSQ */ +/* OP_POW */ +/* OP_ADD */ +/* OP_DP3 */ +/* OP_DP4 */ +/* OP_DPH */ +/* OP_DST */ +/* OP_MAX */ +/* OP_MIN */ +/* OP_MUL */ +/* OP_SGE */ +/* OP_SLT */ +/* OP_SUB */ +/* OP_XPD */ +/* OP_MAD */ +/* OP_SWZ */ + +/* fragment attribute binding */ +.emtcode FRAGMENT_ATTRIB_COLOR 0x01 +.emtcode FRAGMENT_ATTRIB_TEXCOORD 0x02 +.emtcode FRAGMENT_ATTRIB_FOGCOORD 0x03 +.emtcode FRAGMENT_ATTRIB_POSITION 0x04 + +/* vertex attribute binding */ +.emtcode VERTEX_ATTRIB_POSITION 0x01 +.emtcode VERTEX_ATTRIB_WEIGHT 0x02 +.emtcode VERTEX_ATTRIB_NORMAL 0x03 +.emtcode VERTEX_ATTRIB_COLOR 0x04 +.emtcode VERTEX_ATTRIB_FOGCOORD 0x05 +.emtcode VERTEX_ATTRIB_TEXCOORD 0x06 +.emtcode VERTEX_ATTRIB_MATRIXINDEX 0x07 +.emtcode VERTEX_ATTRIB_GENERIC 0x08 + +/* fragment result binding */ +.emtcode FRAGMENT_RESULT_COLOR 0x01 +.emtcode FRAGMENT_RESULT_DEPTH 0x02 + +/* vertex result binding */ +.emtcode VERTEX_RESULT_POSITION 0x01 +.emtcode VERTEX_RESULT_COLOR 0x02 +.emtcode VERTEX_RESULT_FOGCOORD 0x03 +.emtcode VERTEX_RESULT_POINTSIZE 0x04 +.emtcode VERTEX_RESULT_TEXCOORD 0x05 + +/* texture target */ +.emtcode TEXTARGET_1D 0x01 +.emtcode TEXTARGET_2D 0x02 +.emtcode TEXTARGET_3D 0x03 +.emtcode TEXTARGET_RECT 0x04 +.emtcode TEXTARGET_CUBE 0x05 +/* GL_ARB_fragment_program_shadow */ +.emtcode TEXTARGET_SHADOW1D 0x06 +.emtcode TEXTARGET_SHADOW2D 0x07 +.emtcode TEXTARGET_SHADOWRECT 0x08 +/* GL_MESA_texture_array */ +.emtcode TEXTARGET_1D_ARRAY 0x09 +.emtcode TEXTARGET_2D_ARRAY 0x0a +.emtcode TEXTARGET_SHADOW1D_ARRAY 0x0b +.emtcode TEXTARGET_SHADOW2D_ARRAY 0x0c + +/* face type */ +.emtcode FACE_FRONT 0x00 +.emtcode FACE_BACK 0x01 + +/* color type */ +.emtcode COLOR_PRIMARY 0x00 +.emtcode COLOR_SECONDARY 0x01 + +/* component */ +.emtcode COMPONENT_X 0x00 +.emtcode COMPONENT_Y 0x01 +.emtcode COMPONENT_Z 0x02 +.emtcode COMPONENT_W 0x03 +.emtcode COMPONENT_0 0x04 +.emtcode COMPONENT_1 0x05 + +/* array index type */ +.emtcode ARRAY_INDEX_ABSOLUTE 0x00 +.emtcode ARRAY_INDEX_RELATIVE 0x01 + +/* matrix name */ +.emtcode MATRIX_MODELVIEW 0x01 +.emtcode MATRIX_PROJECTION 0x02 +.emtcode MATRIX_MVP 0x03 +.emtcode MATRIX_TEXTURE 0x04 +.emtcode MATRIX_PALETTE 0x05 +.emtcode MATRIX_PROGRAM 0x06 + +/* matrix modifier */ +.emtcode MATRIX_MODIFIER_IDENTITY 0x00 +.emtcode MATRIX_MODIFIER_INVERSE 0x01 +.emtcode MATRIX_MODIFIER_TRANSPOSE 0x02 +.emtcode MATRIX_MODIFIER_INVTRANS 0x03 + +/* constant type */ +.emtcode CONSTANT_SCALAR 0x01 +.emtcode CONSTANT_VECTOR 0x02 + +/* program param type */ +.emtcode PROGRAM_PARAM_ENV 0x01 +.emtcode PROGRAM_PARAM_LOCAL 0x02 + +/* register type */ +.emtcode REGISTER_ATTRIB 0x01 +.emtcode REGISTER_PARAM 0x02 +.emtcode REGISTER_RESULT 0x03 +.emtcode REGISTER_ESTABLISHED_NAME 0x04 + +/* param binding */ +.emtcode PARAM_NULL 0x00 +.emtcode PARAM_ARRAY_ELEMENT 0x01 +.emtcode PARAM_STATE_ELEMENT 0x02 +.emtcode PARAM_PROGRAM_ELEMENT 0x03 +.emtcode PARAM_PROGRAM_ELEMENTS 0x04 +.emtcode PARAM_CONSTANT 0x05 + +/* param state property */ +.emtcode STATE_MATERIAL 0x01 +.emtcode STATE_LIGHT 0x02 +.emtcode STATE_LIGHT_MODEL 0x03 +.emtcode STATE_LIGHT_PROD 0x04 +.emtcode STATE_FOG 0x05 +.emtcode STATE_MATRIX_ROWS 0x06 +/* GL_ARB_fragment_program */ +.emtcode STATE_TEX_ENV 0x07 +.emtcode STATE_DEPTH 0x08 +/* GL_ARB_vertex_program */ +.emtcode STATE_TEX_GEN 0x09 +.emtcode STATE_CLIP_PLANE 0x0A +.emtcode STATE_POINT 0x0B + +/* state material property */ +.emtcode MATERIAL_AMBIENT 0x01 +.emtcode MATERIAL_DIFFUSE 0x02 +.emtcode MATERIAL_SPECULAR 0x03 +.emtcode MATERIAL_EMISSION 0x04 +.emtcode MATERIAL_SHININESS 0x05 + +/* state light property */ +.emtcode LIGHT_AMBIENT 0x01 +.emtcode LIGHT_DIFFUSE 0x02 +.emtcode LIGHT_SPECULAR 0x03 +.emtcode LIGHT_POSITION 0x04 +.emtcode LIGHT_ATTENUATION 0x05 +.emtcode LIGHT_HALF 0x06 +.emtcode LIGHT_SPOT_DIRECTION 0x07 + +/* state light model property */ +.emtcode LIGHT_MODEL_AMBIENT 0x01 +.emtcode LIGHT_MODEL_SCENECOLOR 0x02 + +/* state light product property */ +.emtcode LIGHT_PROD_AMBIENT 0x01 +.emtcode LIGHT_PROD_DIFFUSE 0x02 +.emtcode LIGHT_PROD_SPECULAR 0x03 + +/* state texture environment property */ +.emtcode TEX_ENV_COLOR 0x01 + +/* state texture generation coord property */ +.emtcode TEX_GEN_EYE 0x01 +.emtcode TEX_GEN_OBJECT 0x02 + +/* state fog property */ +.emtcode FOG_COLOR 0x01 +.emtcode FOG_PARAMS 0x02 + +/* state depth property */ +.emtcode DEPTH_RANGE 0x01 + +/* state point parameters property */ +.emtcode POINT_SIZE 0x01 +.emtcode POINT_ATTENUATION 0x02 + +/* declaration */ +.emtcode ATTRIB 0x01 +.emtcode PARAM 0x02 +.emtcode TEMP 0x03 +.emtcode OUTPUT 0x04 +.emtcode ALIAS 0x05 +/* GL_ARB_vertex_program */ +.emtcode ADDRESS 0x06 + +/* error messages */ +.errtext UNKNOWN_PROGRAM_SIGNATURE "1001: '$e_signature$': unknown program signature" +.errtext MISSING_END_OR_INVALID_STATEMENT "1002: '$e_statement$': invalid statement" +.errtext CODE_AFTER_END "1003: '$e_statement$': code after 'END' keyword" +.errtext INVALID_PROGRAM_OPTION "1004: '$e_identifier$': invalid program option" +.errtext EXT_SWIZ_COMP_EXPECTED "1005: extended swizzle component expected but '$e_token$' found" +.errtext TEX_TARGET_EXPECTED "1006: texture target expected but '$e_token$' found" +.errtext TEXTURE_EXPECTED "1007: 'texture' expected but '$e_identifier$' found" +.errtext SOURCE_REGISTER_EXPECTED "1008: source register expected but '$e_token$' found" +.errtext DESTINATION_REGISTER_EXPECTED "1009: destination register expected but '$e_token$' found" +.errtext INVALID_ADDRESS_COMPONENT "1010: '$e_identifier$': invalid address component" +.errtext INVALID_ADDRESS_WRITEMASK "1011: '$e_identifier$': invalid address writemask" +.errtext INVALID_COMPONENT "1012: '$e_charordigit$': invalid component" +.errtext INVALID_SUFFIX "1013: '$e_identifier$': invalid suffix" +.errtext INVALID_WRITEMASK "1014: '$e_identifier$': invalid writemask" +.errtext FRAGMENT_EXPECTED "1015: 'fragment' expected but '$e_identifier$' found" +.errtext VERTEX_EXPECTED "1016: 'vertex' expected but '$e_identifier$' found" +.errtext INVALID_FRAGMENT_PROPERTY "1017: '$e_identifier$': invalid fragment property" +.errtext INVALID_VERTEX_PROPERTY "1018: '$e_identifier$': invalid vertex property" +.errtext INVALID_STATE_PROPERTY "1019: '$e_identifier$': invalid state property" +.errtext INVALID_MATERIAL_PROPERTY "1020: '$e_identifier$': invalid material property" +.errtext INVALID_LIGHT_PROPERTY "1021: '$e_identifier$': invalid light property" +.errtext INVALID_SPOT_PROPERTY "1022: '$e_identifier$': invalid spot property" +.errtext INVALID_LIGHTMODEL_PROPERTY "1023: '$e_identifier$': invalid light model property" +.errtext INVALID_LIGHTPROD_PROPERTY "1024: '$e_identifier$': invalid light product property" +.errtext INVALID_TEXENV_PROPERTY "1025: '$e_identifier$': invalid texture environment property" +.errtext INVALID_TEXGEN_PROPERTY "1026: '$e_identifier$': invalid texture generating property" +.errtext INVALID_TEXGEN_COORD "1027: '$e_identifier$': invalid texture generating coord" +.errtext INVALID_FOG_PROPERTY "1028: '$e_identifier$': invalid fog property" +.errtext INVALID_DEPTH_PROPERTY "1029: '$e_identifier$': invalid depth property" +.errtext INVALID_CLIPPLANE_PROPERTY "1030: '$e_identifier$': invalid clip plane property" +.errtext INVALID_POINT_PROPERTY "1031: '$e_identifier$': invalid point property" +.errtext MATRIX_ROW_SELECTOR_OR_MODIFIER_EXPECTED "1032: matrix row selector or modifier expected but '$e_token$' found" +.errtext INVALID_MATRIX_NAME "1033: '$e_identifier$': invalid matrix name" +.errtext INVALID_PROGRAM_PROPERTY "1034: '$e_identifier$': invalid program property" +.errtext RESULT_EXPECTED "1035: 'result' expected but '$e_token$' found" +.errtext INVALID_RESULT_PROPERTY "1036: '$e_identifier$': invalid result property" +.errtext INVALID_FACE_PROPERTY "1037: '$e_identifier$': invalid face property" +.errtext INVALID_COLOR_PROPERTY "1038: '$e_identifier$': invalid color property" +.errtext IDENTIFIER_EXPECTED "1039: identifier expected but '$e_token$' found" +.errtext RESERVED_KEYWORD "1040: use of reserved keyword as an identifier" +.errtext INTEGER_EXPECTED "1041: integer value expected but '$e_token$' found" +.errtext MISSING_SEMICOLON "1042: ';' expected but '$e_token$' found" +.errtext MISSING_COMMA "1043: ',' expected but '$e_token$' found" +.errtext MISSING_LBRACKET "1044: '[' expected but '$e_token$' found" +.errtext MISSING_RBRACKET "1045: ']' expected but '$e_token$' found" +.errtext MISSING_DOT "1046: '.' expected but '$e_token$' found" +.errtext MISSING_EQUAL "1047: '=' expected but '$e_token$' found" +.errtext MISSING_LBRACE "1048: '{' expected but '$e_token$' found" +.errtext MISSING_RBRACE "1049: '}' expected but '$e_token$' found" +.errtext MISSING_DOTDOT "1050: '..' expected but '$e_token$' found" +.errtext MISSING_FRACTION_OR_EXPONENT "1051: missing fraction part or exponent" +.errtext MISSING_DOT_OR_EXPONENT "1052: missing '.' or exponent" +.errtext EXPONENT_VALUE_EXPECTED "1053: exponent value expected" +.errtext INTEGER_OUT_OF_RANGE "1054: integer value out of range" +.errtext OPERATION_NEEDS_DESTINATION_VARIABLE "1055: operation needs destination variable" +.errtext OPERATION_NEEDS_SOURCE_VARIABLE "1056: operation needs source variable" +.errtext ADDRESS_REGISTER_EXPECTED "1057: address register expected but '$e_token$' found" +.errtext ADDRESS_REGISTER_OR_INTEGER_EXPECTED "1058: address register or integer literal expected but '$e_token$' found" + +/* extension presence condition registers */ + +/* GL_ARB_vertex_blend */ +/* GL_EXT_vertex_weighting */ +.regbyte vertex_blend 0x00 + +/* GL_ARB_matrix_palette */ +.regbyte matrix_palette 0x00 + +/* GL_ARB_point_parameters */ +/* GL_EXT_point_parameters */ +.regbyte point_parameters 0x00 + +/* GL_EXT_secondary_color */ +.regbyte secondary_color 0x00 + +/* GL_EXT_fog_coord */ +.regbyte fog_coord 0x00 + +/* GL_EXT_texture_rectangle */ +/* GL_NV_texture_rectangle */ +.regbyte texture_rectangle 0x00 + +/* GL_ARB_fragment_program_shadow */ +.regbyte fragment_program_shadow 0x00 + +/* GL_ARB_draw_buffers */ +.regbyte draw_buffers 0x00 + +/* GL_MESA_texture_array */ +.regbyte texture_array 0x00 + +/* option presence condition registers */ +/* they are all initially set to zero - when a particular OPTION is encountered, the appropriate */ +/* register is set to 1 to indicate that the OPTION was specified. */ + +/* GL_ARB_fragment_program */ +.regbyte ARB_precision_hint_fastest 0x00 +.regbyte ARB_precision_hint_nicest 0x00 +.regbyte ARB_fog_exp 0x00 +.regbyte ARB_fog_exp2 0x00 +.regbyte ARB_fog_linear 0x00 + +/* GL_ARB_vertex_program */ +.regbyte ARB_position_invariant 0x00 + +/* GL_ARB_fragment_program_shadow */ +.regbyte ARB_fragment_program_shadow 0x00 + +/* GL_ARB_draw_buffers */ +.regbyte ARB_draw_buffers 0x00 + +/* GL_MESA_texture_array */ +.regbyte MESA_texture_array 0x00 + +/* program target condition register */ +/* this syntax script deals with two program targets - VERTEX_PROGRAM and FRAGMENT_PROGRAM. */ +/* to distinguish between them we need a register that will store for us the current target. */ +/* the client will typically set the register to apropriate value before parsing a particular */ +/* program. the mapping between program targets and their values is listed below. */ +/* */ +/* program target register value */ +/* ---------------------------------------------- */ +/* FRAGMENT_PROGRAM 0x10 */ +/* VERTEX_PROGRAM 0x20 */ +/* */ +/* the initial value of the register is 0 to catch potential errors with not setting the register */ +/* with the proper value. */ +.regbyte program_target 0x00 + +/* + ::= "END" +*/ +program + programs .error UNKNOWN_PROGRAM_SIGNATURE .emit REVISION; +programs + .if (program_target == 0x10) frag_program_1_0 .emit FRAGMENT_PROGRAM .emit 0x01 .emit 0x00 .or + .if (program_target == 0x20) vert_program_1_0 .emit VERTEX_PROGRAM .emit 0x01 .emit 0x00; +frag_program_1_0 + '!' .and '!' .and 'A' .and 'R' .and 'B' .and 'f' .and 'p' .and '1' .and '.' .and '0' .and + optional_space .and fp_optionSequence .and fp_statementSequence .and + "END" .error MISSING_END_OR_INVALID_STATEMENT .emit END .and optional_space .and + '\0' .error CODE_AFTER_END; +vert_program_1_0 + '!' .and '!' .and 'A' .and 'R' .and 'B' .and 'v' .and 'p' .and '1' .and '.' .and '0' .and + optional_space .and vp_optionSequence .and vp_statementSequence .and + "END" .error MISSING_END_OR_INVALID_STATEMENT .emit END .and optional_space .and + '\0' .error CODE_AFTER_END; + +/* + ::=