diff options
author | Roland Scheidegger <sroland@tungstengraphics.com> | 2007-08-18 22:31:43 +0200 |
---|---|---|
committer | Roland Scheidegger <sroland@tungstengraphics.com> | 2007-08-18 22:31:43 +0200 |
commit | 4b4fc25c3fab92bf292a78cb9c16a5a32a8bb01b (patch) | |
tree | a7fb45a41c6558a3304210fd72cf211258996dbc | |
parent | 7aefdd518578687f961bb512a2b408857f0b9824 (diff) | |
parent | 53cf87be1b93c760228e6a9af8115d2a9ff99337 (diff) |
Merge branch 'origin' into i915tex_privbuffersi915tex_privbuffers
Conflicts:
src/mesa/drivers/dri/i915tex/intel_buffers.c
src/mesa/drivers/dri/i915tex/intel_context.c
src/mesa/drivers/dri/i915tex/intel_pixel_draw.c
src/mesa/drivers/dri/nouveau/nouveau_buffers.c
src/mesa/main/buffers.c
src/mesa/main/buffers.h
src/mesa/main/fbobject.c
src/mesa/main/framebuffer.c
238 files changed, 6828 insertions, 3326 deletions
@@ -66,6 +66,7 @@ aix-64 \ aix-64-static \ aix-gcc \ aix-static \ +bluegene-osmesa \ beos \ darwin \ darwin-static \ @@ -151,8 +152,9 @@ sunos5-v8 \ sunos5-v8-static \ sunos5-v9 \ sunos5-v9-static \ +sunos5-v9-cc-g++ \ ultrix-gcc: - @ if [ -e configs/current ] ; then \ + @ if test -f configs/current || test -L configs/current ; then \ echo "Please run 'make realclean' before changing configs" ; \ exit 1 ; \ fi @@ -288,17 +290,6 @@ MAIN_FILES = \ $(DIRECTORY)/vms/analyze_map.com \ $(DIRECTORY)/vms/xlib.opt \ $(DIRECTORY)/vms/xlib_share.opt \ - $(DIRECTORY)/windows/VC6/mesa/gdi/gdi.dsp \ - $(DIRECTORY)/windows/VC6/mesa/glu/*.txt \ - $(DIRECTORY)/windows/VC6/mesa/glu/glu.dsp \ - $(DIRECTORY)/windows/VC6/mesa/mesa.dsw \ - $(DIRECTORY)/windows/VC6/mesa/mesa/mesa.dsp \ - $(DIRECTORY)/windows/VC6/mesa/osmesa/osmesa.dsp \ - $(DIRECTORY)/windows/VC7/mesa/gdi/gdi.vcproj \ - $(DIRECTORY)/windows/VC7/mesa/glu/glu.vcproj \ - $(DIRECTORY)/windows/VC7/mesa/mesa.sln \ - $(DIRECTORY)/windows/VC7/mesa/mesa/mesa.vcproj \ - $(DIRECTORY)/windows/VC7/mesa/osmesa/osmesa.vcproj \ $(DIRECTORY)/windows/VC8/mesa/mesa.sln \ $(DIRECTORY)/windows/VC8/mesa/gdi/gdi.vcproj \ $(DIRECTORY)/windows/VC8/mesa/glu/glu.vcproj \ @@ -328,6 +319,7 @@ SGI_GLU_FILES = \ $(DIRECTORY)/src/glu/Makefile \ $(DIRECTORY)/src/glu/descrip.mms \ $(DIRECTORY)/src/glu/sgi/Makefile \ + $(DIRECTORY)/src/glu/sgi/Makefile.mgw \ $(DIRECTORY)/src/glu/sgi/Makefile.win \ $(DIRECTORY)/src/glu/sgi/Makefile.DJ \ $(DIRECTORY)/src/glu/sgi/glu.def \ @@ -372,6 +364,8 @@ DEMO_FILES = \ $(DIRECTORY)/progs/demos/*.cxx \ $(DIRECTORY)/progs/demos/*.dat \ $(DIRECTORY)/progs/demos/README \ + $(DIRECTORY)/progs/fbdev/Makefile \ + $(DIRECTORY)/progs/fbdev/glfbdevtest.c \ $(DIRECTORY)/progs/osdemos/Makefile \ $(DIRECTORY)/progs/osdemos/*.c \ $(DIRECTORY)/progs/xdemos/Makefile* \ diff --git a/Makefile.mgw b/Makefile.mgw index 948860890c..3dc9f62643 100644 --- a/Makefile.mgw +++ b/Makefile.mgw @@ -53,11 +53,13 @@ # MinGW core makefile updated for Mesa 7.0 # -# updated : by Heromyth, 2007-6-25 +# Updated : by Heromyth, on 2007-7-21 # Email : zxpmyth@yahoo.com.cn -# Bug : All the default settings work fine. But the setting X86=1 can't work. +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. # The others havn't been tested yet. - +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) MAlthough more tests are needed, it can be used individually! .PHONY : all libgl clean realclean @@ -73,13 +75,14 @@ CFLAGS += -O2 -ffast-math export CFLAGS + ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) UNLINK = del $(subst /,\,$(1)) else UNLINK = $(RM) $(1) endif -all: libgl libglu libglut +all: libgl libglu libglut example libgl: lib $(MAKE) -f Makefile.mgw -C src/mesa diff --git a/configs/bluegene-osmesa b/configs/bluegene-osmesa new file mode 100644 index 0000000000..02c69e6c67 --- /dev/null +++ b/configs/bluegene-osmesa @@ -0,0 +1,29 @@ +# Configuration for building only libOSMesa on BlueGene, no Xlib driver +# This doesn't really have a lot of dependencies, so it should be usable +# on other (gcc-based) systems too. +# It uses static linking and disables multithreading. + +include $(TOP)/configs/default + +CONFIG_NAME = bluegene-osmesa + +# Compiler and flags +CC = /bgl/BlueLight/ppcfloor/blrts-gnu/bin/powerpc-bgl-blrts-gnu-gcc +CXX = /bgl/BlueLight/ppcfloor/blrts-gnu/bin/powerpc-bgl-blrts-gnu-g++ +CFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE +CXXFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURC + +MKLIB_OPTIONS = -static + +OSMESA_LIB_NAME = libOSMesa.a + +# Directories +SRC_DIRS = mesa glu +DRIVER_DIRS = osmesa +PROGRAM_DIRS = osdemos + + +# Dependencies +OSMESA_LIB_DEPS = -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lOSMesa -lGLU -lm diff --git a/configs/config.mgw b/configs/config.mgw new file mode 100644 index 0000000000..b961eb965c --- /dev/null +++ b/configs/config.mgw @@ -0,0 +1,42 @@ +# MinGW config include file updated for Mesa 7.0
+#
+# Updated : by Heromyth, on 2007-7-21
+# Email : zxpmyth@yahoo.com.cn
+# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work.
+# The others havn't been tested yet.
+# 2) The generated DLLs are *not* compatible with the ones built
+# with the other compilers like VC8, especially for GLUT.
+# 3) Although more tests are needed, it can be used individually!
+
+# The generated DLLs by MingW with STDCALL are not totally compatible
+# with the ones linked by Microsoft's compilers.
+#
+# xxx_USING_STDCALL = 1 Compiling MESA with __stdcall. This is default!
+#
+# xxx_USING_STDCALL = 0 Compiling MESA without __stdcall. I like this:)
+#
+
+# In fact, GL_USING_STDCALL and GLUT_USING_STDCALL can be
+# different. For example:
+#
+# GL_USING_STDCALL = 0
+# GLUT_USING_STDCALL = 1
+#
+# Suggested setting:
+#
+# ALL_USING_STDCALL = 1
+#
+# That's default!
+#
+
+
+ALL_USING_STDCALL = 1
+
+
+ifeq ($(ALL_USING_STDCALL),1)
+ GL_USING_STDCALL = 1
+ GLUT_USING_STDCALL = 1
+else
+ GL_USING_STDCALL = 0
+ GLUT_USING_STDCALL = 0
+endif
diff --git a/configs/freebsd b/configs/freebsd index db7dd3b78a..447faf9f4c 100644 --- a/configs/freebsd +++ b/configs/freebsd @@ -13,7 +13,7 @@ OPT_FLAGS = -O2 PIC_FLAGS = -fPIC DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -DUSE_XSHM \ - -DHZ=100 -DHAVE_POSIX_MEMALIGN + -DHZ=100 X11_INCLUDES = -I/usr/X11R6/include diff --git a/configs/freebsd-dri b/configs/freebsd-dri index 402883d1de..5a9310a04e 100644 --- a/configs/freebsd-dri +++ b/configs/freebsd-dri @@ -15,7 +15,7 @@ EXPAT_INCLUDES = -I/usr/local/include X11_INCLUDES = -I/usr/X11R6/include DEFINES = -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER \ -DGLX_DIRECT_RENDERING -DGLX_INDIRECT_RENDERING \ - -DHAVE_ALIAS -DHAVE_POSIX_MEMALIGN + -DHAVE_ALIAS CFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) -Wmissing-prototypes -std=c99 -Wundef -ffast-math \ $(ASM_FLAGS) $(X11_INCLUDES) $(DEFINES) diff --git a/configs/sunos5-v9-cc-g++ b/configs/sunos5-v9-cc-g++ new file mode 100644 index 0000000000..37b775cc08 --- /dev/null +++ b/configs/sunos5-v9-cc-g++ @@ -0,0 +1,32 @@ +# Configuration for SunOS 5, SPARC V9 and cc/g++ (for C and C++ sources) + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-v9-cc-g++ + +MKLIB_OPTIONS = -cplusplus + +LIB_DIR = lib64 + +# Compiler and flags +CC = cc +CXX = g++ + +CXX_WARN_FLAGS = -Wall +CXX_PIC_FLAGS = -fPIC +CXX_OPT_FLAGS = -O3 -m64 -mcpu=ultrasparc -mv8plus -mvis -g -fomit-frame-pointer -pipe +CXX_ARCH_FLAGS = -m64 + + +CXXFLAGS = $(CXX_WARN_FLAGS) $(CXX_OPT_FLAGS) $(CXX_PIC_FLAGS) $(CXX_ARCH_FLAGS) $(DEFINES) \ + -I/usr/openwin/include + +CFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DPTHREADS +#CXXFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DPTHREADS +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +GL_LIB_DEPS = -L/usr/openwin/lib -L/usr/dt/lib -lX11 -lXext -lXmu -lXi -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCstd -lCrun +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm diff --git a/docs/README.MINGW32 b/docs/README.MINGW32 index 2b39f12090..9477b2bd31 100644 --- a/docs/README.MINGW32 +++ b/docs/README.MINGW32 @@ -88,3 +88,66 @@ Running the Build: Paul G. <pgarceau@users.sourceforge.net> Daniel Borca <dborca@users.sourceforge.net> + + + +******This section is added by Heromyth <zxpmyth@yahoo.com.cn>************* + +==================== +Updated on 2007-7-21 +==================== + +Notice: + 1) The generated DLLs are *not* compatible with the ones built +with the other compilers like VC8, especially for GLUT. + + 2) Although more tests are needed, it can be used individually! + + 3) You can set the options about whether using STDCALL to build MESA. The +config file is <Mesa3D-root>\configs\config.mgw. The default setting is that: + ALL_USING_STDCALL = 1 +, which means using STDCALL to build MESA. + + 4) Of course, you can MESA without using STDCALL,I like this:) +The setting is : + ALL_USING_STDCALL = 0 +To do this, however, you must modify wingdi.h which is in MingW's include dir. +For example, run: + notepad C:\MingW\include\wingdi.h +, and delete all the lines where all the wgl*() functions are. Because they would +be conflicted with the ones in <Mesa3D-root>\include\GL\mesa_wgl.h. + +>>>>>>>>>> Conflicted Functions List >>>>>>>>>> +WINGDIAPI BOOL WINAPI wglCopyContext(HGLRC,HGLRC,UINT); +WINGDIAPI HGLRC WINAPI wglCreateContext(HDC); +WINGDIAPI HGLRC WINAPI wglCreateLayerContext(HDC,int); +WINGDIAPI BOOL WINAPI wglDeleteContext(HGLRC); +WINGDIAPI BOOL WINAPI wglDescribeLayerPlane(HDC,int,int,UINT,LPLAYERPLANEDESCRIPTOR); +WINGDIAPI HGLRC WINAPI wglGetCurrentContext(void); +WINGDIAPI HDC WINAPI wglGetCurrentDC(void); +WINGDIAPI int WINAPI wglGetLayerPaletteEntries(HDC,int,int,int,COLORREF*); +WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR); +WINGDIAPI BOOL WINAPI wglMakeCurrent(HDC,HGLRC); +WINGDIAPI BOOL WINAPI wglRealizeLayerPalette(HDC,int,BOOL); +WINGDIAPI int WINAPI wglSetLayerPaletteEntries(HDC,int,int,int,const COLORREF*); +WINGDIAPI BOOL WINAPI wglShareLists(HGLRC,HGLRC); +WINGDIAPI BOOL WINAPI wglSwapLayerBuffers(HDC,UINT); +WINGDIAPI BOOL WINAPI wglUseFontBitmapsA(HDC,DWORD,DWORD,DWORD); +WINGDIAPI BOOL WINAPI wglUseFontBitmapsW(HDC,DWORD,DWORD,DWORD); +WINGDIAPI BOOL WINAPI wglUseFontOutlinesA(HDC,DWORD,DWORD,DWORD,FLOAT,FLOAT,int,LPGLYPHMETRICSFLOAT); +WINGDIAPI BOOL WINAPI wglUseFontOutlinesW(HDC,DWORD,DWORD,DWORD,FLOAT,FLOAT,int,LPGLYPHMETRICSFLOAT); +<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +==================== +Updated on 2007-7-22 +==================== + I havn't thought that I would find a better way to solve my problems so soon. +I changed the method in which the import-libs and DLLs are made. After this update, +the DLLs of MESA are more optimized and more compatible. + It seems that there is no need to keep the building way of 'NO-STDCALL'.The +way of USING_STDCALL is so nice! The file <Mesa3D-root>\configs\config.mgw is +also not needed, and can be deleted safely! + + + +*********************************************************************************
\ No newline at end of file diff --git a/include/GL/gl.h b/include/GL/gl.h index a388de36e4..3891a71875 100644 --- a/include/GL/gl.h +++ b/include/GL/gl.h @@ -84,7 +84,8 @@ #include <windows.h> #endif -#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) \ + && !defined(OPENSTEP) && !defined(__CYGWIN__) || defined(__MINGW32__) #include <GL/mesa_wgl.h> #endif @@ -2161,11 +2162,11 @@ typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLsh #define GL_DEBUG_PRINT_MESA 0x875A #define GL_DEBUG_ASSERT_MESA 0x875B -GLAPI GLhandleARB APIENTRY glCreateDebugObjectMESA (void); -GLAPI void APIENTRY glClearDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); -GLAPI void APIENTRY glGetDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType, GLsizei maxLength, +GLAPI GLhandleARB GLAPIENTRY glCreateDebugObjectMESA (void); +GLAPI void GLAPIENTRY glClearDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); +GLAPI void GLAPIENTRY glGetDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType, GLsizei maxLength, GLsizei *length, GLcharARB *debugLog); -GLAPI GLsizei APIENTRY glGetDebugLogLengthMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); +GLAPI GLsizei GLAPIENTRY glGetDebugLogLengthMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); #endif /* GL_MESA_shader_debug */ diff --git a/include/GL/glut.h b/include/GL/glut.h index e0fad6e5cb..137b8efa13 100644 --- a/include/GL/glut.h +++ b/include/GL/glut.h @@ -10,6 +10,10 @@ #include <GL/gl.h> #include <GL/glu.h> +#if defined(__MINGW32__) +#include <GL/mesa_wgl.h> +#endif + #ifdef __cplusplus extern "C" { #endif @@ -130,8 +134,9 @@ extern _CRTIMP void __cdecl exit(int); # pragma message( "----: being multiply defined you should include WINDOWS.H priot to gl/glut.h" ) # endif # define CALLBACK __stdcall -typedef int (GLUTAPIENTRY *PROC)(); + #if !defined(__MINGW32__) + typedef int (GLUTAPIENTRY *PROC)(); typedef void *HGLRC; typedef void *HDC; #endif diff --git a/include/GL/mesa_wgl.h b/include/GL/mesa_wgl.h index acc7eac2a7..57147232b7 100644 --- a/include/GL/mesa_wgl.h +++ b/include/GL/mesa_wgl.h @@ -26,11 +26,12 @@ /* prototypes for the Mesa WGL functions */ /* relocated here so that I could make GLUT get them properly */ -#define _mesa_wgl_h_ - #ifndef _mesa_wgl_h_ #define _mesa_wgl_h_ +#if defined(__MINGW32__) +# define __W32API_USE_DLLIMPORT__ +#endif #include <GL/gl.h> @@ -39,23 +40,16 @@ extern "C" { #endif -#if !defined(OPENSTEP) && (defined(__WIN32__) || defined(__CYGWIN32__)) -# if (defined(_MSC_VER) || defined(__MINGW32__)) && 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(__MINGW32__)) && 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 -#else -/* non-Windows compilation */ -# define GLAPI extern -# define GLAPIENTRY -#endif /* WIN32 / CYGWIN32 bracket */ +#ifndef WGLAPI +#define WGLAPI GLAPI +#endif + +#if defined(__MINGW32__) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN 1 +# endif +# include <windows.h> +#endif #if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) @@ -80,23 +74,23 @@ typedef struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESC # pragma warning( disable : 4273 ) /* 'function' : inconsistent DLL linkage. dllexport assumed. */ #endif -WGLAPI int GLAPIENTRY wglDeleteContext(HGLRC); -WGLAPI int GLAPIENTRY wglMakeCurrent(HDC,HGLRC); + WGLAPI int GLAPIENTRY wglSetPixelFormat(HDC, int, const PIXELFORMATDESCRIPTOR *); WGLAPI int GLAPIENTRY wglSwapBuffers(HDC hdc); -WGLAPI HDC GLAPIENTRY wglGetCurrentDC(void); -WGLAPI HGLRC GLAPIENTRY wglCreateContext(HDC); -WGLAPI HGLRC GLAPIENTRY wglCreateLayerContext(HDC,int); -WGLAPI HGLRC GLAPIENTRY wglGetCurrentContext(void); -WGLAPI PROC GLAPIENTRY wglGetProcAddress(const char*); WGLAPI int GLAPIENTRY wglChoosePixelFormat(HDC, const PIXELFORMATDESCRIPTOR *); +WGLAPI int GLAPIENTRY wglDescribePixelFormat(HDC,int, unsigned int, LPPIXELFORMATDESCRIPTOR); +WGLAPI int GLAPIENTRY wglGetPixelFormat(HDC hdc); + WGLAPI int GLAPIENTRY wglCopyContext(HGLRC, HGLRC, unsigned int); +WGLAPI HGLRC GLAPIENTRY wglCreateContext(HDC); +WGLAPI HGLRC GLAPIENTRY wglCreateLayerContext(HDC,int); WGLAPI int GLAPIENTRY wglDeleteContext(HGLRC); WGLAPI int GLAPIENTRY wglDescribeLayerPlane(HDC, int, int, unsigned int,LPLAYERPLANEDESCRIPTOR); -WGLAPI int GLAPIENTRY wglDescribePixelFormat(HDC,int, unsigned int, LPPIXELFORMATDESCRIPTOR); +WGLAPI HGLRC GLAPIENTRY wglGetCurrentContext(void); +WGLAPI HDC GLAPIENTRY wglGetCurrentDC(void); WGLAPI int GLAPIENTRY wglGetLayerPaletteEntries(HDC, int, int, int,COLORREF *); -WGLAPI int GLAPIENTRY wglGetPixelFormat(HDC hdc); -WGLAPI int GLAPIENTRY wglMakeCurrent(HDC, HGLRC); +WGLAPI PROC GLAPIENTRY wglGetProcAddress(const char*); +WGLAPI int GLAPIENTRY wglMakeCurrent(HDC,HGLRC); WGLAPI int GLAPIENTRY wglRealizeLayerPalette(HDC, int, int); WGLAPI int GLAPIENTRY wglSetLayerPaletteEntries(HDC, int, int, int,const COLORREF *); WGLAPI int GLAPIENTRY wglShareLists(HGLRC, HGLRC); @@ -105,12 +99,14 @@ WGLAPI int GLAPIENTRY wglUseFontBitmapsA(HDC, unsigned long, unsigned long, un WGLAPI int GLAPIENTRY wglUseFontBitmapsW(HDC, unsigned long, unsigned long, unsigned long); WGLAPI int GLAPIENTRY wglUseFontOutlinesA(HDC, unsigned long, unsigned long, unsigned long, float,float, int, LPGLYPHMETRICSFLOAT); WGLAPI int GLAPIENTRY wglUseFontOutlinesW(HDC, unsigned long, unsigned long, unsigned long, float,float, int, LPGLYPHMETRICSFLOAT); + +#ifndef __MINGW32__ WGLAPI int GLAPIENTRY SwapBuffers(HDC); WGLAPI int GLAPIENTRY ChoosePixelFormat(HDC,const PIXELFORMATDESCRIPTOR *); WGLAPI int GLAPIENTRY DescribePixelFormat(HDC,int,unsigned int,LPPIXELFORMATDESCRIPTOR); WGLAPI int GLAPIENTRY GetPixelFormat(HDC); WGLAPI int GLAPIENTRY SetPixelFormat(HDC,int,const PIXELFORMATDESCRIPTOR *); - +#endif #ifndef WGL_ARB_extensions_string #define WGL_ARB_extensions_string 1 diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c index 3feb2a0524..8363f2abc6 100644 --- a/progs/demos/geartrain.c +++ b/progs/demos/geartrain.c @@ -1053,6 +1053,7 @@ main (int argc, char *argv[]) else file = argv[1]; + glutInit(&argc, argv); glutInitWindowPosition (0, 0); glutInitWindowSize(640,480); glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); diff --git a/progs/demos/gltestperf.c b/progs/demos/gltestperf.c index be95390101..2188b02419 100644 --- a/progs/demos/gltestperf.c +++ b/progs/demos/gltestperf.c @@ -569,6 +569,7 @@ main(int ac, char **av) if (ac == 2) frontbuffer = 0; + glutInit(&ac, av); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(0, 0); glutInitWindowSize(640, 480); diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c index 0710bc6047..10f94b6ace 100644 --- a/progs/demos/isosurf.c +++ b/progs/demos/isosurf.c @@ -1042,6 +1042,7 @@ int main(int argc, char **argv) read_surface( "isosurf.dat" ); + glutInit( &argc, argv); glutInitWindowPosition(0, 0); glutInitWindowSize(400, 400); diff --git a/progs/demos/morph3d.c b/progs/demos/morph3d.c index 162a6ff847..6aca8270ff 100644 --- a/progs/demos/morph3d.c +++ b/progs/demos/morph3d.c @@ -826,7 +826,7 @@ static void pinit(void) } -static void INIT(void) +int main(int argc, char **argv) { printf("Morph 3D - Shows morphing platonic polyhedra\n"); printf("Author: Marcelo Fernandes Vianna (vianna@cat.cbpf.br)\n\n"); @@ -841,6 +841,7 @@ static void INIT(void) object=1; + glutInit(&argc, argv); glutInitWindowPosition(0,0); glutInitWindowSize(640,480); @@ -888,9 +889,3 @@ static void INIT(void) glutMainLoop(); } - -int main(int argc, char **argv) -{ - INIT(); - return(0); -} diff --git a/progs/demos/winpos.c b/progs/demos/winpos.c index 3a1a19ecdb..b58e330864 100644 --- a/progs/demos/winpos.c +++ b/progs/demos/winpos.c @@ -100,6 +100,7 @@ static void init( void ) int main( int argc, char *argv[] ) { + glutInit(&argc, argv); glutInitWindowPosition(0, 0); glutInitWindowSize(500, 500); glutInitDisplayMode( GLUT_RGB ); diff --git a/progs/fbdev/glfbdevtest.c b/progs/fbdev/glfbdevtest.c index a461c55e2f..6d9f807030 100644 --- a/progs/fbdev/glfbdevtest.c +++ b/progs/fbdev/glfbdevtest.c @@ -23,11 +23,21 @@ #include <GL/glfbdev.h> #include <math.h> -#define DEFAULT_DEPTH 8 + +/** + * Choose one of these modes + */ +/*static const int XRes = 1280, YRes = 1024, Hz = 75;*/ +/*static const int XRes = 1280, YRes = 1024, Hz = 70;*/ +/*static const int XRes = 1280, YRes = 1024, Hz = 60;*/ +static const int XRes = 1024, YRes = 768, Hz = 70; + +static int DesiredDepth = 32; + +static int NumFrames = 100; static struct fb_fix_screeninfo FixedInfo; static struct fb_var_screeninfo VarInfo, OrigVarInfo; -static int DesiredDepth = 0; static int OriginalVT = -1; static int ConsoleFD = -1; static int FrameBufferFD = -1; @@ -227,7 +237,6 @@ initialize_fbdev( void ) VarInfo = OrigVarInfo; /* set the depth, resolution, etc */ - DesiredDepth = 32; if (DesiredDepth) VarInfo.bits_per_pixel = DesiredDepth; @@ -251,16 +260,60 @@ initialize_fbdev( void ) VarInfo.blue.length = 8; VarInfo.transp.length = 8; } - /* timing values taken from /etc/fb.modes (1280x1024 @ 75Hz) */ - VarInfo.xres_virtual = VarInfo.xres = 1280; - VarInfo.yres_virtual = VarInfo.yres = 1024; - VarInfo.pixclock = 7408; - VarInfo.left_margin = 248; - VarInfo.right_margin = 16; - VarInfo.upper_margin = 38; - VarInfo.lower_margin = 1; - VarInfo.hsync_len = 144; - VarInfo.vsync_len = 3; + + /* timing values taken from /etc/fb.modes */ + if (XRes == 1280 && YRes == 1024) { + VarInfo.xres_virtual = VarInfo.xres = XRes; + VarInfo.yres_virtual = VarInfo.yres = YRes; + if (Hz == 75) { + VarInfo.pixclock = 7408; + VarInfo.left_margin = 248; + VarInfo.right_margin = 16; + VarInfo.upper_margin = 38; + VarInfo.lower_margin = 1; + VarInfo.hsync_len = 144; + VarInfo.vsync_len = 3; + } + else if (Hz == 70) { + VarInfo.pixclock = 7937; + VarInfo.left_margin = 216; + VarInfo.right_margin = 80; + VarInfo.upper_margin = 36; + VarInfo.lower_margin = 1; + VarInfo.hsync_len = 112; + VarInfo.vsync_len = 5; + } + else if (Hz == 60) { + VarInfo.pixclock = 9260; + VarInfo.left_margin = 248; + VarInfo.right_margin = 48; + VarInfo.upper_margin = 38; + VarInfo.lower_margin = 1; + VarInfo.hsync_len = 112; + VarInfo.vsync_len = 3; + } + else { + fprintf(stderr, "invalid rate for 1280x1024\n"); + exit(1); + } + } + else if (XRes == 1024 && YRes == 768 && Hz == 70) { + VarInfo.xres_virtual = VarInfo.xres = XRes; + VarInfo.yres_virtual = VarInfo.yres = YRes; + if (Hz == 70) { + VarInfo.pixclock = 13334; + VarInfo.left_margin = 144; + VarInfo.right_margin = 24; + VarInfo.upper_margin = 29; + VarInfo.lower_margin = 3; + VarInfo.hsync_len = 136; + VarInfo.vsync_len = 6; + } + else { + fprintf(stderr, "invalid rate for 1024x768\n"); + exit(1); + } + } VarInfo.xoffset = 0; VarInfo.yoffset = 0; @@ -338,7 +391,7 @@ initialize_fbdev( void ) printf("MMIOAddress = %p\n", MMIOAddress); /* try out some simple MMIO register reads */ - if (1) + if (0) { typedef unsigned int CARD32; typedef unsigned char CARD8; @@ -452,6 +505,7 @@ gltest( void ) GLFBDevVisualPtr vis; int bytes, r, g, b, a; float ang; + int i; printf("GLFBDEV_VENDOR = %s\n", glFBDevGetString(GLFBDEV_VENDOR)); printf("GLFBDEV_VERSION = %s\n", glFBDevGetString(GLFBDEV_VERSION)); @@ -491,13 +545,17 @@ gltest( void ) glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); - for (ang = 0; ang <= 180; ang += 15) { + printf("Drawing %d frames...\n", NumFrames); + + ang = 0.0; + for (i = 0; i < NumFrames; i++) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(ang, 1, 0, 0); doughnut(1, 3, 40, 20); glPopMatrix(); glFBDevSwapBuffers(buf); + ang += 15.0; } /* clean up */ @@ -510,12 +568,29 @@ gltest( void ) } +static void +parse_args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-f") == 0) { + NumFrames = atoi(argv[i+1]); + i++; + } + } +} + + int main( int argc, char *argv[] ) { signal(SIGUSR1, signal_handler); /* exit if someone tries a vt switch */ signal(SIGSEGV, signal_handler); /* catch segfaults */ + parse_args(argc, argv); + + printf("Setting mode to %d x %d @ %d Hz, %d bpp\n", XRes, YRes, Hz, DesiredDepth); initialize_fbdev(); gltest(); shutdown_fbdev(); diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 37fa312c30..a9800c5414 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -8,13 +8,16 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) PROGS = \ + bitmap \ brick \ bump \ deriv \ mandelbrot \ noise \ + points \ + texdemo1 \ toyball \ - texdemo1 + trirast ##### RULES ##### @@ -48,12 +51,16 @@ readtex.h: $(TOP)/progs/util/readtex.h readtex.o: readtex.c readtex.h $(CC) -c -I$(INCDIR) $(CFLAGS) readtex.c +bitmap.c: extfuncs.h + brick.c: extfuncs.h bump.c: extfuncs.h mandelbrot.c: extfuncs.h +points.c: extfuncs.h + toyball.c: extfuncs.h texdemo1: texdemo1.o readtex.o diff --git a/progs/glsl/bitmap.c b/progs/glsl/bitmap.c new file mode 100644 index 0000000000..4b62686cbf --- /dev/null +++ b/progs/glsl/bitmap.c @@ -0,0 +1,368 @@ +/** + * Implement glRasterPos + glBitmap with textures + shaders. + * Brian Paul + * 14 May 2007 + */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" + + +static GLuint FragShader; +static GLuint VertShader; +static GLuint Program; + +static GLint Win = 0; +static GLint WinWidth = 500, WinHeight = 500; +static GLboolean Anim = GL_TRUE; +static GLboolean Bitmap = GL_FALSE; +static GLfloat Xrot = 20.0f, Yrot = 70.0f; +static GLint uTex, uScale; +static GLuint Textures[2]; + +#define TEX_WIDTH 16 +#define TEX_HEIGHT 8 + + +static void +BitmapText(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static void +Redisplay(void) +{ + static const GLfloat px[3] = { 1.2, 0, 0}; + static const GLfloat nx[3] = {-1.2, 0, 0}; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(Xrot, 1.0f, 0.0f, 0.0f); + glRotatef(Yrot, 0.0f, 1.0f, 0.0f); + + glEnable(GL_LIGHTING); + + glPushMatrix(); + glScalef(0.5, 0.5, 0.5); + glutSolidDodecahedron(); + glPopMatrix(); + + glDisable(GL_LIGHTING); + + glColor3f(0, 1, 0); + glBegin(GL_LINES); + glVertex3f(-1, 0, 0); + glVertex3f( 1, 0, 0); + glEnd(); + + glColor3f(1, 1, 0); + + if (Bitmap) { + glRasterPos3fv(px); + BitmapText("+X"); + glRasterPos3fv(nx); + BitmapText("-X"); + } + else { + glUseProgram_func(Program); + + /* vertex positions (deltas) depend on texture size and window size */ + if (uScale != -1) { + glUniform2f_func(uScale, + 2.0 * TEX_WIDTH / WinWidth, + 2.0 * TEX_HEIGHT / WinHeight); + } + + /* draw +X */ + glBindTexture(GL_TEXTURE_2D, Textures[0]); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex3fv(px); + glTexCoord2f(1, 0); glVertex3fv(px); + glTexCoord2f(1, 1); glVertex3fv(px); + glTexCoord2f(0, 1); glVertex3fv(px); + glEnd(); + + /* draw -X */ + glBindTexture(GL_TEXTURE_2D, Textures[1]); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex3fv(nx); + glTexCoord2f(1, 0); glVertex3fv(nx); + glTexCoord2f(1, 1); glVertex3fv(nx); + glTexCoord2f(0, 1); glVertex3fv(nx); + glEnd(); + + glUseProgram_func(0); + } + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Idle(void) +{ + Yrot = glutGet(GLUT_ELAPSED_TIME) * 0.01; + glutPostRedisplay(); +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -10.0f); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case ' ': + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'b': + Bitmap = !Bitmap; + if (Bitmap) + printf("Using glBitmap\n"); + else + printf("Using billboard texture\n"); + break; + case 27: + glDeleteShader_func(FragShader); + glDeleteShader_func(VertShader); + glDeleteProgram_func(Program); + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + const GLfloat step = 0.125f; + switch(key) { + case GLUT_KEY_UP: + Xrot -= step; + break; + case GLUT_KEY_DOWN: + Xrot += step; + break; + case GLUT_KEY_LEFT: + Yrot -= step; + break; + case GLUT_KEY_RIGHT: + Yrot += step; + break; + } + /*printf("Xrot: %f Yrot: %f\n", Xrot, Yrot);*/ + glutPostRedisplay(); +} + + +static void +MakeTexImage(const char *p, GLuint texobj) +{ + GLubyte image[TEX_HEIGHT][TEX_WIDTH]; + GLuint i, j, k; + + for (i = 0; i < TEX_HEIGHT; i++) { + for (j = 0; j < TEX_WIDTH; j++) { + k = i * TEX_WIDTH + j; + if (p[k] == ' ') { + image[i][j] = 0; + } + else { + image[i][j] = 255; + } + } + } + + glBindTexture(GL_TEXTURE_2D, texobj); + glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, TEX_WIDTH, TEX_HEIGHT, 0, + GL_RED, GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +} + + +static void +MakeBitmapTextures(void) +{ + const char *px = + " X X " + " X X X " + " X X X " + " XXXXX X " + " X X X " + " X X X " + " X X " + " X X "; + const char *nx = + " X X " + " X X " + " X X " + " XXXXX X " + " X X " + " X X " + " X X " + " X X "; + glGenTextures(2, Textures); + MakeTexImage(px, Textures[0]); + MakeTexImage(nx, Textures[1]); +} + + +static void +LoadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + + glShaderSource_func(shader, 1, (const GLchar **) &text, NULL); + + glCompileShader_func(shader); + + glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog_func(shader, 1000, &len, log); + fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log); + exit(1); + } +} + + +static void +CheckLink(GLuint prog) +{ + GLint stat; + glGetProgramiv_func(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog_func(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } +} + + +static void +Init(void) +{ + /* Fragment shader: modulate raster color by texture, discard fragments + * with alpha < 1.0 + */ + static const char *fragShaderText = + "uniform sampler2D tex2d; \n" + "void main() {\n" + " vec4 c = texture2D(tex2d, gl_TexCoord[0].xy); \n" + " if (c.w < 1.0) \n" + " discard; \n" + " gl_FragColor = c * gl_Color; \n" + "}\n"; + /* Vertex shader: compute new vertex position based on incoming vertex pos, + * texcoords and special scale factor. + */ + static const char *vertShaderText = + "uniform vec2 scale; \n" + "void main() {\n" + " vec4 p = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " gl_Position.xy = p.xy + gl_MultiTexCoord0.xy * scale * p.w; \n" + " gl_Position.zw = p.zw; \n" + " gl_TexCoord[0] = gl_MultiTexCoord0; \n" + " gl_FrontColor = gl_Color; \n" + "}\n"; + const char *version; + + version = (const char *) glGetString(GL_VERSION); + if (version[0] != '2' || version[1] != '.') { + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); + } + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + GetExtensionFuncs(); + + FragShader = glCreateShader_func(GL_FRAGMENT_SHADER); + LoadAndCompileShader(FragShader, fragShaderText); + + VertShader = glCreateShader_func(GL_VERTEX_SHADER); + LoadAndCompileShader(VertShader, vertShaderText); + + Program = glCreateProgram_func(); + glAttachShader_func(Program, FragShader); + glAttachShader_func(Program, VertShader); + glLinkProgram_func(Program); + CheckLink(Program); + glUseProgram_func(Program); + + uScale = glGetUniformLocation_func(Program, "scale"); + uTex = glGetUniformLocation_func(Program, "tex2d"); + if (uTex != -1) { + glUniform1i_func(uTex, 0); /* tex unit 0 */ + } + + glUseProgram_func(0); + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + glEnable(GL_DEPTH_TEST); + glEnable(GL_NORMALIZE); + glEnable(GL_LIGHT0); + + MakeBitmapTextures(); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Redisplay); + if (Anim) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} + + diff --git a/progs/glsl/points.c b/progs/glsl/points.c new file mode 100644 index 0000000000..85115de504 --- /dev/null +++ b/progs/glsl/points.c @@ -0,0 +1,305 @@ +/** + * Implement smooth (AA) points with shaders. + * A simple variation could be used for sprite points. + * Brian Paul + * 29 July 2007 + */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" + + +static GLuint FragShader; +static GLuint VertShader; +static GLuint Program; + +static GLint Win = 0; +static GLint WinWidth = 500, WinHeight = 200; +static GLfloat Xpos = 0.0f, Ypos = 0.0f; +static GLint uViewportInv; +static GLboolean Smooth = GL_TRUE, Blend = GL_TRUE; + + +/** + * Issue vertices for a "shader point". + * The position is duplicated, only texcoords (or other vertex attrib) change. + * The vertex program will compute the "real" quad corners. + */ +static void +PointVertex3f(GLfloat x, GLfloat y, GLfloat z) +{ + glTexCoord2f(-1, -1); + glVertex3f(x, y, z); + + glTexCoord2f( 1, -1); + glVertex3f(x, y, z); + + glTexCoord2f( 1, 1); + glVertex3f(x, y, z); + + glTexCoord2f(-1, 1); + glVertex3f(x, y, z); +} + + +static void +DrawPoints(GLboolean shaderPoints) +{ + int i; + for (i = 0; i < 9; i++) { + GLfloat x = i - 4, y = 0, z = 0; + /* note: can't call glPointSize inside Begin/End :( */ + glPointSize( 2 + i * 5 ); + if (shaderPoints) { + glBegin(GL_QUADS); + PointVertex3f(x, y, z); + glEnd(); + } + else { + glBegin(GL_POINTS); + glVertex3f(x, y, z); + glEnd(); + } + } +} + + +/** + * Top row of points rendered convetionally, + * bottom row rendered with shaders. + */ +static void +Redisplay(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (Smooth) + glEnable(GL_POINT_SMOOTH); + else + glDisable(GL_POINT_SMOOTH); + + if (Blend) + glEnable(GL_BLEND); + else + glDisable(GL_BLEND); + + glPushMatrix(); + glTranslatef(Xpos, Ypos, 0); + + /* + * regular points + */ + glPushMatrix(); + glTranslatef(0, 1.2, 0); + glUseProgram_func(0); + DrawPoints(GL_FALSE); + glPopMatrix(); + + /* + * shader points + */ + glPushMatrix(); + glTranslatef(0, -1.2, 0); + glUseProgram_func(Program); + if (uViewportInv != -1) { + glUniform2f_func(uViewportInv, 1.0 / WinWidth, 1.0 / WinHeight); + } + DrawPoints(GL_TRUE); + glPopMatrix(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 4.0, 30.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -20.0f); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case 'b': + Blend = !Blend; + break; + case 's': + Smooth = !Smooth; + break; + case 27: + glDeleteShader_func(FragShader); + glDeleteShader_func(VertShader); + glDeleteProgram_func(Program); + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + const GLfloat step = 1/100.0; + switch(key) { + case GLUT_KEY_UP: + Ypos += step; + break; + case GLUT_KEY_DOWN: + Ypos -= step; + break; + case GLUT_KEY_LEFT: + Xpos -= step; + break; + case GLUT_KEY_RIGHT: + Xpos += step; + break; + } + glutPostRedisplay(); +} + + +static void +LoadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + + glShaderSource_func(shader, 1, (const GLchar **) &text, NULL); + + glCompileShader_func(shader); + + glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog_func(shader, 1000, &len, log); + fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log); + exit(1); + } +} + + +static void +CheckLink(GLuint prog) +{ + GLint stat; + glGetProgramiv_func(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog_func(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } +} + + +static void +Init(void) +{ + /* Fragment shader: compute distance of fragment from center of point + * (we're using texcoords but another varying could be used). + * if dist > 1, discard (coverage==0) + * if dist < k, coverage = 1 + * else, coverage = func(dist) + * Note: length() uses sqrt() and may be expensive. The distance could + * be squared instead (with adjustments to the threshold (k) test) + */ + static const char *fragShaderText = + "void main() {\n" + " float cover; \n" + " float k = 2.0 / gl_Point.size; \n" + " float d = length(gl_TexCoord[0].xy); \n" + " if (d >= 1.0) \n" + " discard; \n" + " if (d < 1.0 - k) \n" + " cover = 1.0; \n" + " else \n" + " cover = (1.0 - d) * 0.5 * gl_Point.size; \n" + " gl_FragColor.rgb = gl_Color.rgb; \n" + " gl_FragColor.a = cover; \n" + "}\n"; + /* Vertex shader: compute new vertex position based on incoming vertex pos, + * texcoords, point size, and inverse viewport scale factor. + * Note: should compute point size attenuation here too. + */ + static const char *vertShaderText = + "uniform vec2 viewportInv; \n" + "void main() {\n" + " vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " gl_Position.xy = pos.xy + gl_MultiTexCoord0.xy * viewportInv \n" + " * gl_Point.size * pos.w; \n" + " gl_Position.zw = pos.zw; \n" + " gl_TexCoord[0] = gl_MultiTexCoord0; \n" + " gl_FrontColor = gl_Color; \n" + "}\n"; + const char *version; + + version = (const char *) glGetString(GL_VERSION); + if (version[0] != '2' || version[1] != '.') { + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); + } + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + GetExtensionFuncs(); + + FragShader = glCreateShader_func(GL_FRAGMENT_SHADER); + LoadAndCompileShader(FragShader, fragShaderText); + + VertShader = glCreateShader_func(GL_VERTEX_SHADER); + LoadAndCompileShader(VertShader, vertShaderText); + + Program = glCreateProgram_func(); + glAttachShader_func(Program, FragShader); + glAttachShader_func(Program, VertShader); + glLinkProgram_func(Program); + CheckLink(Program); + glUseProgram_func(Program); + + uViewportInv = glGetUniformLocation_func(Program, "viewportInv"); + + glUseProgram_func(0); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Redisplay); + Init(); + glutMainLoop(); + return 0; +} + + diff --git a/progs/glsl/trirast.c b/progs/glsl/trirast.c new file mode 100644 index 0000000000..e4325deb1f --- /dev/null +++ b/progs/glsl/trirast.c @@ -0,0 +1,326 @@ +/** + * Demonstration of doing triangle rasterization with a fragment program. + * Basic idea: + * 1. Draw screen-aligned quad / bounding box around the triangle verts. + * 2. For each pixel in the quad, determine if pixel is inside/outside + * the triangle edges. + * + * Brian Paul + * 1 Aug 2007 + */ + + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" + + +static GLint WinWidth = 300, WinHeight = 300; +static char *FragProgFile = NULL; +static char *VertProgFile = NULL; +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; +static GLint win = 0; +static GLboolean anim = GL_TRUE; +static GLfloat Zrot = 0.0f; +static GLint uv0, uv1, uv2; + + +static const GLfloat TriVerts[3][2] = { + { 50, 50 }, + { 250, 50 }, + { 150, 250 } +}; + + +static void +RotateVerts(GLfloat a, + GLuint n, const GLfloat vertsIn[][2], GLfloat vertsOut[][2]) +{ + GLuint i; + GLfloat cx = WinWidth / 2, cy = WinHeight / 2; + for (i = 0; i < n; i++) { + float x = vertsIn[i][0] - cx; + float y = vertsIn[i][1] - cy; + + vertsOut[i][0] = x * cos(a) + y * sin(a) + cx; + vertsOut[i][1] = -x * sin(a) + y * cos(a) + cy; + } +} + +static void +ComputeBounds(GLuint n, GLfloat vertsIn[][2], + GLfloat *xmin, GLfloat *ymin, + GLfloat *xmax, GLfloat *ymax) +{ + GLuint i; + *xmin = *xmax = vertsIn[0][0]; + *ymin = *ymax = vertsIn[0][1]; + for (i = 1; i < n; i++) { + if (vertsIn[i][0] < *xmin) + *xmin = vertsIn[i][0]; + else if (vertsIn[i][0] > *xmax) + *xmax = vertsIn[i][0]; + if (vertsIn[i][1] < *ymin) + *ymin = vertsIn[i][1]; + else if (vertsIn[i][1] > *ymax) + *ymax = vertsIn[i][1]; + } +} + + +static void +Redisplay(void) +{ + GLfloat v[3][2], xmin, ymin, xmax, ymax; + + RotateVerts(Zrot, 3, TriVerts, v); + ComputeBounds(3, v, &xmin, &ymin, &xmax, &ymax); + + glUniform2fv_func(uv0, 1, v[0]); + glUniform2fv_func(uv1, 1, v[1]); + glUniform2fv_func(uv2, 1, v[2]); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glBegin(GL_POLYGON); + glVertex2f(xmin, ymin); + glVertex2f(xmax, ymin); + glVertex2f(xmax, ymax); + glVertex2f(xmin, ymax); + glEnd(); + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Idle(void) +{ + Zrot = glutGet(GLUT_ELAPSED_TIME) * 0.0005; + glutPostRedisplay(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, 0, height, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +CleanUp(void) +{ + glDeleteShader_func(fragShader); + glDeleteShader_func(vertShader); + glDeleteProgram_func(program); + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case ' ': + case 'a': + anim = !anim; + if (anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +LoadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + + glShaderSource_func(shader, 1, (const GLchar **) &text, NULL); + + glCompileShader_func(shader); + + glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog_func(shader, 1000, &len, log); + fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log); + exit(1); + } +} + + +/** + * 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, "fslight: Unable to open shader file %s\n", filename); + exit(1); + } + + n = fread(buffer, 1, max, f); + printf("fslight: read %d bytes from shader file %s\n", n, filename); + if (n > 0) { + buffer[n] = 0; + LoadAndCompileShader(shader, buffer); + } + + fclose(f); + free(buffer); +} + + +static void +CheckLink(GLuint prog) +{ + GLint stat; + glGetProgramiv_func(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog_func(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } +} + + +static void +Init(void) +{ + static const char *fragShaderText = + "uniform vec2 v0, v1, v2; \n" + "float crs(const vec2 u, const vec2 v) \n" + "{ \n" + " return u.x * v.y - u.y * v.x; \n" + "} \n" + "\n" + "void main() {\n" + " vec2 p = gl_FragCoord.xy; \n" + " if (crs(v1 - v0, p - v0) >= 0 && \n" + " crs(v2 - v1, p - v1) >= 0 && \n" + " crs(v0 - v2, p - v2) >= 0) \n" + " gl_FragColor = vec4(1.0); \n" + " else \n" + " gl_FragColor = vec4(0.5); \n" + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + "}\n"; + const char *version; + + version = (const char *) glGetString(GL_VERSION); + if (version[0] != '2' || version[1] != '.') { + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); + } + + GetExtensionFuncs(); + + fragShader = glCreateShader_func(GL_FRAGMENT_SHADER); + if (FragProgFile) + ReadShader(fragShader, FragProgFile); + else + LoadAndCompileShader(fragShader, fragShaderText); + + vertShader = glCreateShader_func(GL_VERTEX_SHADER); + if (VertProgFile) + ReadShader(vertShader, VertProgFile); + else + LoadAndCompileShader(vertShader, vertShaderText); + + program = glCreateProgram_func(); + glAttachShader_func(program, fragShader); + glAttachShader_func(program, vertShader); + glLinkProgram_func(program); + CheckLink(program); + glUseProgram_func(program); + + uv0 = glGetUniformLocation_func(program, "v0"); + uv1 = glGetUniformLocation_func(program, "v1"); + uv2 = glGetUniformLocation_func(program, "v2"); + printf("Uniforms: %d %d %d\n", uv0, uv1, uv2); + + /*assert(glGetError() == 0);*/ + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + glEnable(GL_DEPTH_TEST); + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + assert(glIsProgram_func(program)); + assert(glIsShader_func(fragShader)); + assert(glIsShader_func(vertShader)); + + glColor3f(1, 0, 0); +} + + +static void +ParseOptions(int argc, char *argv[]) +{ + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-fs") == 0) { + FragProgFile = argv[i+1]; + } + else if (strcmp(argv[i], "-vs") == 0) { + VertProgFile = argv[i+1]; + } + } +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition( 0, 0); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Redisplay); + if (anim) + glutIdleFunc(Idle); + ParseOptions(argc, argv); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/osdemos/ostest1.c b/progs/osdemos/ostest1.c index 001e368616..2c7adfc353 100644 --- a/progs/osdemos/ostest1.c +++ b/progs/osdemos/ostest1.c @@ -409,6 +409,8 @@ test(GLenum type, GLint bits, const char *filename) printf("Rendering %d bit/channel image: %s\n", bits, filename); + OSMesaColorClamp(GL_TRUE); + init_context(); render_image(); if (Gradient) @@ -421,7 +423,7 @@ test(GLenum type, GLint bits, const char *filename) if (WriteFiles && filename != NULL) { if (type == GL_UNSIGNED_SHORT) { GLushort *buffer16 = (GLushort *) buffer; - GLubyte *buffer8 = malloc(WIDTH * HEIGHT * 4); + GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4); int i; for (i = 0; i < WIDTH * HEIGHT * 4; i++) buffer8[i] = buffer16[i] >> 8; @@ -430,8 +432,9 @@ test(GLenum type, GLint bits, const char *filename) } else if (type == GL_FLOAT) { GLfloat *buffer32 = (GLfloat *) buffer; - GLubyte *buffer8 = malloc(WIDTH * HEIGHT * 4); + GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4); int i; + /* colors may be outside [0,1] so we need to clamp */ for (i = 0; i < WIDTH * HEIGHT * 4; i++) buffer8[i] = (GLubyte) (buffer32[i] * 255.0); write_ppm(filename, buffer8, WIDTH, HEIGHT); diff --git a/progs/samples/Makefile.mgw b/progs/samples/Makefile.mgw index 1193540578..8bb975be9d 100644 --- a/progs/samples/Makefile.mgw +++ b/progs/samples/Makefile.mgw @@ -26,6 +26,15 @@ # Email : dborca@users.sourceforge.net # Web : http://www.geocities.com/dborca +# MinGW samples makefile updated for Mesa 7.0 +# +# Updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! # # Available options: @@ -45,14 +54,14 @@ TOP = ../.. CC = mingw32-gcc -CFLAGS = -Wall -W -pedantic -CFLAGS += -O2 -ffast-math +CFLAGS = -Wall -pedantic +CFLAGS += -O2 -ffast-math -D_DLL CFLAGS += -I$(TOP)/include -I../util ifeq ($(FX),1) -CFLAGS += -DFX + CFLAGS += -DFX endif -CFLAGS += -DGLUT_DISABLE_ATEXIT_HACK -D_STDCALL_SUPPORTED -CFLAGS += -D_WINDEF_ -D_WINGDI_ + +CFLAGS += -DGLUT_DISABLE_ATEXIT_HACK LD = mingw32-g++ LDFLAGS = -s -L$(TOP)/lib @@ -62,7 +71,8 @@ LDLIBS = -lglut32 -lglu32 -lopengl32 .c.o: $(CC) -o $@ $(CFLAGS) -c $< %.exe: ../util/readtex.o ../util/showbuffer.o %.o - $(LD) -o $@ $(LDFLAGS) $^ $(LDLIBS) + $(LD) -o $@ $(LDFLAGS) $(LDLIBS) $^ + all: $(error Must specify <filename.exe> to build) diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h index 5d647cdae7..716bb7df3b 100644 --- a/progs/util/extfuncs.h +++ b/progs/util/extfuncs.h @@ -26,6 +26,13 @@ static PFNGLISSHADERPROC glIsShader_func = NULL; static PFNGLLINKPROGRAMPROC glLinkProgram_func = NULL; static PFNGLSHADERSOURCEPROC glShaderSource_func = NULL; static PFNGLUNIFORM1IPROC glUniform1i_func = NULL; +static PFNGLUNIFORM2IPROC glUniform2i_func = NULL; +static PFNGLUNIFORM3IPROC glUniform3i_func = NULL; +static PFNGLUNIFORM4IPROC glUniform4i_func = NULL; +static PFNGLUNIFORM1FPROC glUniform1f_func = NULL; +static PFNGLUNIFORM2FPROC glUniform2f_func = NULL; +static PFNGLUNIFORM3FPROC glUniform3f_func = NULL; +static PFNGLUNIFORM4FPROC glUniform4f_func = NULL; static PFNGLUNIFORM1FVPROC glUniform1fv_func = NULL; static PFNGLUNIFORM2FVPROC glUniform2fv_func = NULL; static PFNGLUNIFORM3FVPROC glUniform3fv_func = NULL; @@ -47,6 +54,9 @@ static PFNGLUNIFORMMATRIX4X2FVPROC glUniformMatrix4x2fv_func = NULL; static PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv_func = NULL; static PFNGLUNIFORMMATRIX4X3FVPROC glUniformMatrix4x3fv_func = NULL; +/* OpenGL 1.4 */ +static PFNGLPOINTPARAMETERFVPROC glPointParameterfv_func = NULL; + /* GL_ARB_vertex/fragment_program */ static PFNGLBINDPROGRAMARBPROC glBindProgramARB_func = NULL; static PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB_func = NULL; @@ -94,6 +104,13 @@ GetExtensionFuncs(void) glLinkProgram_func = (PFNGLLINKPROGRAMPROC) glutGetProcAddress("glLinkProgram"); glShaderSource_func = (PFNGLSHADERSOURCEPROC) glutGetProcAddress("glShaderSource"); glUniform1i_func = (PFNGLUNIFORM1IPROC) glutGetProcAddress("glUniform1i"); + glUniform2i_func = (PFNGLUNIFORM2IPROC) glutGetProcAddress("glUniform2i"); + glUniform3i_func = (PFNGLUNIFORM3IPROC) glutGetProcAddress("glUniform3i"); + glUniform4i_func = (PFNGLUNIFORM4IPROC) glutGetProcAddress("glUniform3i"); + glUniform1f_func = (PFNGLUNIFORM1FPROC) glutGetProcAddress("glUniform1f"); + glUniform2f_func = (PFNGLUNIFORM2FPROC) glutGetProcAddress("glUniform2f"); + glUniform3f_func = (PFNGLUNIFORM3FPROC) glutGetProcAddress("glUniform3f"); + glUniform4f_func = (PFNGLUNIFORM4FPROC) glutGetProcAddress("glUniform3f"); glUniform1fv_func = (PFNGLUNIFORM1FVPROC) glutGetProcAddress("glUniform1fv"); glUniform2fv_func = (PFNGLUNIFORM2FVPROC) glutGetProcAddress("glUniform2fv"); glUniform3fv_func = (PFNGLUNIFORM3FVPROC) glutGetProcAddress("glUniform3fv"); @@ -115,6 +132,8 @@ GetExtensionFuncs(void) glUniformMatrix3x4fv_func = (PFNGLUNIFORMMATRIX3X4FVPROC) glutGetProcAddress("glUniformMatrix3x4fv"); glUniformMatrix4x3fv_func = (PFNGLUNIFORMMATRIX4X3FVPROC) glutGetProcAddress("glUniformMatrix4x3fv"); + glPointParameterfv_func = (PFNGLPOINTPARAMETERFVPROC) glutGetProcAddress("glPointParameterfv"); + /* GL_ARB_vertex/fragment_program */ glBindProgramARB_func = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB"); glDeleteProgramsARB_func = (PFNGLDELETEPROGRAMSARBPROC) glutGetProcAddress("glDeleteProgramsARB"); diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c index 75d63e51a2..ec431c16f0 100644 --- a/progs/xdemos/glxgears.c +++ b/progs/xdemos/glxgears.c @@ -433,7 +433,7 @@ make_window( Display *dpy, const char *name, attr.override_redirect = fullscreen; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; - win = XCreateWindow( dpy, root, 0, 0, width, height, + win = XCreateWindow( dpy, root, x, y, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr ); @@ -548,13 +548,16 @@ usage(void) printf(" -stereo run in stereo mode\n"); printf(" -fullscreen run in fullscreen mode\n"); printf(" -info display OpenGL renderer info\n"); + printf(" -winwidth <width> window width (default: 300)\n"); + printf(" -winheight <height> window height (default: 300)\n"); } int main(int argc, char *argv[]) { - const int winWidth = 300, winHeight = 300; + unsigned int winWidth = 300, winHeight = 300; + int x = 0, y = 0; Display *dpy; Window win; GLXContext ctx; @@ -576,6 +579,10 @@ main(int argc, char *argv[]) else if (strcmp(argv[i], "-fullscreen") == 0) { fullscreen = GL_TRUE; } + else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) { + XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight); + i++; + } else { usage(); return -1; @@ -589,7 +596,7 @@ main(int argc, char *argv[]) return -1; } - make_window(dpy, "glxgears", 0, 0, winWidth, winHeight, &win, &ctx); + make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx); XMapWindow(dpy, win); glXMakeCurrent(dpy, win, ctx); diff --git a/progs/xdemos/glxswapcontrol.c b/progs/xdemos/glxswapcontrol.c index d9be984be5..e429d58ecc 100644 --- a/progs/xdemos/glxswapcontrol.c +++ b/progs/xdemos/glxswapcontrol.c @@ -814,6 +814,11 @@ main(int argc, char *argv[]) init(); + /* Set initial projection/viewing transformation. + * same as glxgears.c + */ + reshape(300, 300); + event_loop(dpy, win); glXDestroyContext(dpy, ctx); diff --git a/progs/xdemos/offset.c b/progs/xdemos/offset.c index 3e92e68daa..0ad9147aea 100644 --- a/progs/xdemos/offset.c +++ b/progs/xdemos/offset.c @@ -71,12 +71,12 @@ typedef Vertex Quad[4]; /* data to define the six faces of a unit cube */ Quad quads[MAXQUAD] = { - { {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} }, - { {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} }, - { {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} }, - { {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} }, - { {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} }, - { {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} } + { {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} }, /* x = 0 */ + { {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} }, /* y = 0 */ + { {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} }, /* z = 0 */ + { {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} }, /* x = 1 */ + { {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} }, /* y = 1 */ + { {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} } /* z = 1 */ }; #define WIREFRAME 0 @@ -86,7 +86,7 @@ static void error(const char* prog, const char* msg); static void cubes(int mx, int my, int mode); static void fill(Quad quad); static void outline(Quad quad); -static void draw_hidden(Quad quad, int mode); +static void draw_hidden(Quad quad, int mode, int face); static void process_input(Display *dpy, Window win); static int query_extension(char* extName); @@ -101,6 +101,7 @@ int main(int argc, char** argv) { XSetWindowAttributes swa; Window win; GLXContext cx; + GLint z; dpy = XOpenDisplay(0); if (!dpy) error(argv[0], "can't open display"); @@ -134,13 +135,16 @@ int main(int argc, char** argv) { /* set up viewing parameters */ glMatrixMode(GL_PROJECTION); - gluPerspective(20, 1, 0.1, 20); + gluPerspective(20, 1, 10, 20); glMatrixMode(GL_MODELVIEW); glTranslatef(0, 0, -15); /* set other relevant state information */ glEnable(GL_DEPTH_TEST); + glGetIntegerv(GL_DEPTH_BITS, &z); + printf("GL_DEPTH_BITS = %d\n", z); + #ifdef GL_EXT_polygon_offset printf("using 1.0 offset extension\n"); glPolygonOffsetEXT( 1.0, 0.00001 ); @@ -160,6 +164,7 @@ int main(int argc, char** argv) { static void draw_scene(int mx, int my) { + glClearColor(0.25, 0.25, 0.25, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); @@ -206,7 +211,7 @@ cubes(int mx, int my, int mode) { glTranslatef(x, y, z); glScalef(0.8, 0.8, 0.8); for (i = 0; i < MAXQUAD; i++) - draw_hidden(quads[i], mode); + draw_hidden(quads[i], mode, i); glPopMatrix(); } } @@ -236,13 +241,18 @@ outline(Quad quad) { } static void -draw_hidden(Quad quad, int mode) { +draw_hidden(Quad quad, int mode, int face) { + static const GLfloat colors[3][3] = { + {0.5, 0.5, 0.0}, + {0.8, 0.5, 0.0}, + {0.0, 0.5, 0.8} + }; if (mode == HIDDEN_LINE) { - glColor3f(0, 0, 0); + glColor3fv(colors[face % 3]); fill(quad); } - /* draw the outline using white, optionally fill the interior with black */ + /* draw the outline using white */ glColor3f(1, 1, 1); outline(quad); } diff --git a/progs/xdemos/pbdemo.c b/progs/xdemos/pbdemo.c index efdfdfa452..7db0017b33 100644 --- a/progs/xdemos/pbdemo.c +++ b/progs/xdemos/pbdemo.c @@ -93,7 +93,7 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) None }, { - /* Single bufferd, without depth buffer */ + /* Single buffered, without depth buffer */ GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 1, @@ -105,7 +105,7 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) None }, { - /* Double bufferd, without depth buffer */ + /* Double buffered, without depth buffer */ GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 1, @@ -130,9 +130,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) /* Get list of possible frame buffer configurations */ fbConfigs = ChooseFBConfig(dpy, screen, fbAttribs[attempt], &nConfigs); if (nConfigs==0 || !fbConfigs) { - printf("Error: glXChooseFBConfig failed\n"); - XCloseDisplay(dpy); - return 0; + printf("Note: glXChooseFBConfig(%s) failed\n", fbString[attempt]); + continue; } #if 0 /*DEBUG*/ diff --git a/src/glu/sgi/Makefile.mgw b/src/glu/sgi/Makefile.mgw new file mode 100644 index 0000000000..d00d97a3b6 --- /dev/null +++ b/src/glu/sgi/Makefile.mgw @@ -0,0 +1,230 @@ +# Mesa 3-D graphics library +# Version: 5.1 +# +# Copyright (C) 1999-2003 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. + +# MinGW core makefile v1.4 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : dborca@users.sourceforge.net +# Web : http://www.geocities.com/dborca + +# MinGW core-glu makefile updated for Mesa 7.0 +# +# Updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! + +# +# Available options: +# +# Environment variables: +# CFLAGS +# +# GLIDE path to Glide3 SDK; used with FX. +# default = $(TOP)/glide3 +# FX=1 build for 3dfx Glide3. Note that this disables +# compilation of most WMesa code and requires fxMesa. +# As a consequence, you'll need the Win32 Glide3 +# library to build any application. +# default = no +# ICD=1 build the installable client driver interface +# (windows opengl driver interface) +# default = no +# X86=1 optimize for x86 (if possible, use MMX, SSE, 3DNow). +# default = no +# +# Targets: +# all: build GL +# clean: remove object files +# + + + +.PHONY: all clean +.INTERMEDIATE: x86/gen_matypes.exe +.SUFFIXES: .rc .res + +# Set this to the prefix of your build tools, i.e. mingw32- +TOOLS_PREFIX = mingw32- + +TOP = ../../.. +LIBDIR = $(TOP)/lib + +LIB_NAME = glu32 +DLL_EXT = .dll +IMP_EXT = .a +LIB_PRE = lib +STRIP = -s + +AR = ar +ARFLAGS = crus +DLLTOOL = dlltool + +GLU_DLL = $(LIB_NAME)$(DLL_EXT) +GLU_IMP = $(LIB_PRE)$(LIB_NAME)$(IMP_EXT) +GLU_DEF = $(LIB_NAME).def + +LDLIBS = -L$(LIBDIR) -lopengl32 +LDFLAGS = $(STRIP) -shared -fPIC -Wl,--kill-at + +CFLAGS += -DBUILD_GLU32 -D_DLL + + +CC = $(TOOLS_PREFIX)gcc +CFLAGS += -DNDEBUG -DLIBRARYBUILD -I$(TOP)/include -Iinclude +CXX = $(TOOLS_PREFIX)g++ +CXXFLAGS = $(CFLAGS) -Ilibnurbs/internals -Ilibnurbs/interface -Ilibnurbs/nurbtess + +AR = ar +ARFLAGS = crus + +UNLINK = del $(subst /,\,$(1)) +ifneq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif +ifneq ($(wildcard $(addsuffix /rm,$(subst :, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif + +C_SOURCES = \ + libutil/error.c \ + libutil/glue.c \ + libutil/mipmap.c \ + libutil/project.c \ + libutil/quad.c \ + libutil/registry.c \ + libtess/dict.c \ + libtess/geom.c \ + libtess/memalloc.c \ + libtess/mesh.c \ + libtess/normal.c \ + libtess/priorityq.c \ + libtess/render.c \ + libtess/sweep.c \ + libtess/tess.c \ + libtess/tessmono.c + +CC_SOURCES = \ + libnurbs/interface/bezierEval.cc \ + libnurbs/interface/bezierPatch.cc \ + libnurbs/interface/bezierPatchMesh.cc \ + libnurbs/interface/glcurveval.cc \ + libnurbs/interface/glinterface.cc \ + libnurbs/interface/glrenderer.cc \ + libnurbs/interface/glsurfeval.cc \ + libnurbs/interface/incurveeval.cc \ + libnurbs/interface/insurfeval.cc \ + libnurbs/internals/arc.cc \ + libnurbs/internals/arcsorter.cc \ + libnurbs/internals/arctess.cc \ + libnurbs/internals/backend.cc \ + libnurbs/internals/basiccrveval.cc \ + libnurbs/internals/basicsurfeval.cc \ + libnurbs/internals/bin.cc \ + libnurbs/internals/bufpool.cc \ + libnurbs/internals/cachingeval.cc \ + libnurbs/internals/ccw.cc \ + libnurbs/internals/coveandtiler.cc \ + libnurbs/internals/curve.cc \ + libnurbs/internals/curvelist.cc \ + libnurbs/internals/curvesub.cc \ + libnurbs/internals/dataTransform.cc \ + libnurbs/internals/displaylist.cc \ + libnurbs/internals/flist.cc \ + libnurbs/internals/flistsorter.cc \ + libnurbs/internals/hull.cc \ + libnurbs/internals/intersect.cc \ + libnurbs/internals/knotvector.cc \ + libnurbs/internals/mapdesc.cc \ + libnurbs/internals/mapdescv.cc \ + libnurbs/internals/maplist.cc \ + libnurbs/internals/mesher.cc \ + libnurbs/internals/monoTriangulationBackend.cc \ + libnurbs/internals/monotonizer.cc \ + libnurbs/internals/mycode.cc \ + libnurbs/internals/nurbsinterfac.cc \ + libnurbs/internals/nurbstess.cc \ + libnurbs/internals/patch.cc \ + libnurbs/internals/patchlist.cc \ + libnurbs/internals/quilt.cc \ + libnurbs/internals/reader.cc \ + libnurbs/internals/renderhints.cc \ + libnurbs/internals/slicer.cc \ + libnurbs/internals/sorter.cc \ + libnurbs/internals/splitarcs.cc \ + libnurbs/internals/subdivider.cc \ + libnurbs/internals/tobezier.cc \ + libnurbs/internals/trimline.cc \ + libnurbs/internals/trimregion.cc \ + libnurbs/internals/trimvertpool.cc \ + libnurbs/internals/uarray.cc \ + libnurbs/internals/varray.cc \ + libnurbs/nurbtess/directedLine.cc \ + libnurbs/nurbtess/gridWrap.cc \ + libnurbs/nurbtess/monoChain.cc \ + libnurbs/nurbtess/monoPolyPart.cc \ + libnurbs/nurbtess/monoTriangulation.cc \ + libnurbs/nurbtess/partitionX.cc \ + libnurbs/nurbtess/partitionY.cc \ + libnurbs/nurbtess/polyDBG.cc \ + libnurbs/nurbtess/polyUtil.cc \ + libnurbs/nurbtess/primitiveStream.cc \ + libnurbs/nurbtess/quicksort.cc \ + libnurbs/nurbtess/rectBlock.cc \ + libnurbs/nurbtess/sampleComp.cc \ + libnurbs/nurbtess/sampleCompBot.cc \ + libnurbs/nurbtess/sampleCompRight.cc \ + libnurbs/nurbtess/sampleCompTop.cc \ + libnurbs/nurbtess/sampleMonoPoly.cc \ + libnurbs/nurbtess/sampledLine.cc \ + libnurbs/nurbtess/searchTree.cc + +SOURCES = $(C_SOURCES) $(CC_SOURCES) + +OBJECTS = $(addsuffix .o,$(basename $(SOURCES))) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +.cc.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + + +all: $(LIBDIR) $(LIBDIR)/$(GLU_DLL) $(LIBDIR)/$(GLU_IMP) + +$(LIBDIR): + mkdir -p $(LIBDIR) + +$(LIBDIR)/$(GLU_DLL) $(LIBDIR)/$(GLU_IMP): $(OBJECTS) + $(CXX) $(LDFLAGS) -o $(LIBDIR)/$(GLU_DLL) $^ $(LDLIBS) + $(DLLTOOL) --as=as --dllname $(LIB_NAME) --output-def $(LIBDIR)/$(GLU_DEF) $^ + $(DLLTOOL) --as=as -k --dllname $(LIB_NAME) --output-lib $(LIBDIR)/$(GLU_IMP) --def $(LIBDIR)/$(GLU_DEF) + + +clean: + -$(call UNLINK,libutil/*.o) + -$(call UNLINK,libtess/*.o) + -$(call UNLINK,libnurbs/interface/*.o) + -$(call UNLINK,libnurbs/internals/*.o) + -$(call UNLINK,libnurbs/nurbtess/*.o) diff --git a/src/glu/sgi/libnurbs/interface/bezierPatch.cc b/src/glu/sgi/libnurbs/interface/bezierPatch.cc index 836ae94e0a..5b7bda1a00 100644 --- a/src/glu/sgi/libnurbs/interface/bezierPatch.cc +++ b/src/glu/sgi/libnurbs/interface/bezierPatch.cc @@ -111,8 +111,11 @@ void bezierPatchDelete(bezierPatch *b) void bezierPatchDeleteList(bezierPatch *b) { bezierPatch *temp; - for(temp = b; temp != NULL; temp = temp->next) - bezierPatchDelete(temp); + while (b != NULL) { + temp = b; + b = b->next; + bezierPatchDelete(temp); + } } bezierPatch* bezierPatchInsert(bezierPatch *list, bezierPatch *b) diff --git a/src/glu/sgi/libnurbs/interface/glcurveval.h b/src/glu/sgi/libnurbs/interface/glcurveval.h index 4b44f6e847..a09a74d04c 100644 --- a/src/glu/sgi/libnurbs/interface/glcurveval.h +++ b/src/glu/sgi/libnurbs/interface/glcurveval.h @@ -93,7 +93,7 @@ public: output_triangles = flag; } #ifdef _WIN32 - void putCallBack(GLenum which, void (APIENTRY *fn)() ); + void putCallBack(GLenum which, void (GLAPIENTRY *fn)() ); #else void putCallBack(GLenum which, _GLUfuncptr fn ); #endif diff --git a/src/glu/sgi/libnurbs/interface/glsurfeval.cc b/src/glu/sgi/libnurbs/interface/glsurfeval.cc index a36b304508..b5bfab1e28 100644 --- a/src/glu/sgi/libnurbs/interface/glsurfeval.cc +++ b/src/glu/sgi/libnurbs/interface/glsurfeval.cc @@ -1184,8 +1184,11 @@ return; } -void -OpenGLSurfaceEvaluator::putCallBack(GLenum which, _GLUfuncptr fn ) +#ifdef _WIN32 +void OpenGLSurfaceEvaluator::putCallBack(GLenum which, void (GLAPIENTRY *fn)() ) +#else +void OpenGLSurfaceEvaluator::putCallBack(GLenum which, _GLUfuncptr fn ) +#endif { switch(which) { diff --git a/src/glu/sgi/libnurbs/interface/glsurfeval.h b/src/glu/sgi/libnurbs/interface/glsurfeval.h index c34a58cb9b..b7a88069f5 100644 --- a/src/glu/sgi/libnurbs/interface/glsurfeval.h +++ b/src/glu/sgi/libnurbs/interface/glsurfeval.h @@ -145,7 +145,7 @@ public: void newtmeshvert( long, long ); #ifdef _WIN32 - void putCallBack(GLenum which, void (APIENTRY *fn)() ); + void putCallBack(GLenum which, void (GLAPIENTRY *fn)() ); #else void putCallBack(GLenum which, _GLUfuncptr fn ); #endif diff --git a/src/glu/sgi/libnurbs/interface/insurfeval.cc b/src/glu/sgi/libnurbs/interface/insurfeval.cc index b314699c7a..e4ee3ef6a2 100644 --- a/src/glu/sgi/libnurbs/interface/insurfeval.cc +++ b/src/glu/sgi/libnurbs/interface/insurfeval.cc @@ -1533,8 +1533,8 @@ void OpenGLSurfaceEvaluator::inEvalVStrip(int n_left, REAL u_left, REAL* left_va } //clean up free(leftXYZ); - free(leftXYZ); - free(rightNormal); + free(rightXYZ); + free(leftNormal); free(rightNormal); } diff --git a/src/glu/sgi/libutil/error.c b/src/glu/sgi/libutil/error.c index 3d1ce9b210..c200056942 100644 --- a/src/glu/sgi/libutil/error.c +++ b/src/glu/sgi/libutil/error.c @@ -82,7 +82,7 @@ gluErrorString(GLenum errorCode) if ((errorCode >= GLU_NURBS_ERROR1) && (errorCode <= GLU_NURBS_ERROR37)) { return (const GLubyte *) __gluNURBSErrorString(errorCode - (GLU_NURBS_ERROR1 - 1)); } - if ((errorCode >= GLU_TESS_ERROR1) && (errorCode <= GLU_TESS_ERROR8)) { + if ((errorCode >= GLU_TESS_ERROR1) && (errorCode <= GLU_TESS_ERROR6)) { return (const GLubyte *) __gluTessErrorString(errorCode - (GLU_TESS_ERROR1 - 1)); } return (const GLubyte *) 0; diff --git a/src/glut/glx/Makefile.mgw b/src/glut/glx/Makefile.mgw new file mode 100644 index 0000000000..9fff2e1503 --- /dev/null +++ b/src/glut/glx/Makefile.mgw @@ -0,0 +1,191 @@ +# Mesa 3-D graphics library +# Version: 5.1 +# +# Copyright (C) 1999-2003 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. + +# MinGW core makefile v1.4 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : dborca@users.sourceforge.net +# Web : http://www.geocities.com/dborca + +# MinGW core-glut makefile updated for Mesa 7.0 +# +# Updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! + + +# +# Available options: +# +# Environment variables: +# CFLAGS +# +# GLIDE path to Glide3 SDK; used with FX. +# default = $(TOP)/glide3 +# FX=1 build for 3dfx Glide3. Note that this disables +# compilation of most WMesa code and requires fxMesa. +# As a consequence, you'll need the Win32 Glide3 +# library to build any application. +# default = no +# ICD=1 build the installable client driver interface +# (windows opengl driver interface) +# default = no +# X86=1 optimize for x86 (if possible, use MMX, SSE, 3DNow). +# default = no +# +# Targets: +# all: build GL +# clean: remove object files +# + + + +.PHONY: all clean +.INTERMEDIATE: x86/gen_matypes.exe +.SUFFIXES: .rc .res + +# Set this to the prefix of your build tools, i.e. mingw32- +TOOLS_PREFIX = mingw32- + +TOP = ../../.. + +LIBDIR = $(TOP)/lib + +LIB_NAME = glut32 + +DLL_EXT = .dll +IMP_EXT = .a +LIB_PRE = lib +STRIP = -s + +AR = ar +ARFLAGS = crus +DLLTOOL = dlltool + +GLUT_DLL = $(LIB_NAME)$(DLL_EXT) +GLUT_IMP = $(LIB_PRE)$(LIB_NAME)$(IMP_EXT) +GLUT_DEF = $(LIB_NAME).def + +LDLIBS = -L$(LIBDIR) -lwinmm -lgdi32 -luser32 -lopengl32 -lglu32 +LDFLAGS = $(STRIP) -shared -fPIC -Wl,--kill-at + +CFLAGS += -DBUILD_GLUT32 -DGLUT_BUILDING_LIB -DMESA -D_DLL +CFLAGS += -DNDEBUG -DLIBRARYBUILD -I$(TOP)/include + +CC = $(TOOLS_PREFIX)gcc +CXX = $(TOOLS_PREFIX)g++ +CXXFLAGS = $(CFLAGS) + +AR = ar +ARFLAGS = crus + +UNLINK = del $(subst /,\,$(1)) +ifneq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif +ifneq ($(wildcard $(addsuffix /rm,$(subst :, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif + +HDRS = glutint.h glutstroke.h glutbitmap.h glutwin32.h stroke.h win32_glx.h win32_x11.h + +SRCS = \ + glut_bitmap.c \ + glut_bwidth.c \ + glut_cindex.c \ + glut_cmap.c \ + glut_cursor.c \ + glut_dials.c \ + glut_dstr.c \ + glut_event.c \ + glut_ext.c \ + glut_fbc.c \ + glut_fullscrn.c \ + glut_gamemode.c \ + glut_get.c \ + glut_init.c \ + glut_input.c \ + glut_joy.c \ + glut_key.c \ + glut_keyctrl.c \ + glut_keyup.c \ + glut_mesa.c \ + glut_modifier.c \ + glut_overlay.c \ + glut_shapes.c \ + glut_space.c \ + glut_stroke.c \ + glut_swap.c \ + glut_swidth.c \ + glut_tablet.c \ + glut_teapot.c \ + glut_util.c \ + glut_vidresize.c \ + glut_warp.c \ + glut_win.c \ + glut_winmisc.c \ + win32_glx.c \ + win32_menu.c \ + win32_util.c \ + win32_winproc.c \ + win32_x11.c + + +SRCSSEMIGENS = \ + glut_8x13.c \ + glut_9x15.c \ + glut_hel10.c \ + glut_hel12.c \ + glut_hel18.c \ + glut_mroman.c \ + glut_roman.c \ + glut_tr10.c \ + glut_tr24.c + + + +SOURCES = $(SRCS) $(SRCSSEMIGENS) + +OBJECTS = $(addsuffix .o,$(basename $(SOURCES))) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +.cc.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + + +all: $(LIBDIR) $(LIBDIR)/$(GLUT_DLL) $(LIBDIR)/$(GLUT_IMP) + +$(LIBDIR): + mkdir -p $(LIBDIR) + +$(LIBDIR)/$(GLUT_DLL) $(LIBDIR)/$(GLUT_IMP): $(OBJECTS) + $(CXX) $(LDFLAGS) -o $(LIBDIR)/$(GLUT_DLL) $^ $(LDLIBS) + $(DLLTOOL) --as=as --dllname $(LIB_NAME) --output-def $(LIBDIR)/$(GLUT_DEF) $^ + $(DLLTOOL) --as=as -k --dllname $(LIB_NAME) --output-lib $(LIBDIR)/$(GLUT_IMP) --def $(LIBDIR)/$(GLUT_DEF) + +clean: + -$(call UNLINK,*.o)
\ No newline at end of file diff --git a/src/glut/glx/glut_dstr.c b/src/glut/glx/glut_dstr.c index ec9386f3e5..2513af4539 100644 --- a/src/glut/glx/glut_dstr.c +++ b/src/glut/glx/glut_dstr.c @@ -291,6 +291,7 @@ loadVisuals(int *nitems_return) fbmodes = (FrameBufferMode *) malloc(n * sizeof(FrameBufferMode)); if (fbmodes == NULL) { *nitems_return = -1; + free(vlist); return NULL; } for (i = 0; i < n; i++) { diff --git a/src/glut/glx/glut_event.c b/src/glut/glx/glut_event.c index 4e67da674e..0a96e8cf71 100644 --- a/src/glut/glx/glut_event.c +++ b/src/glut/glx/glut_event.c @@ -24,7 +24,7 @@ # ifdef __sgi # include <bstring.h> /* prototype for bzero used by FD_ZERO */ # endif -# if (defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE) +# if (defined(__FreeBSD__) || defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE) # include <sys/select.h> /* select system call interface */ # ifdef luna # include <sysent.h> diff --git a/src/glut/glx/glut_fbc.c b/src/glut/glx/glut_fbc.c index deb46c3d8d..e93188b862 100644 --- a/src/glut/glx/glut_fbc.c +++ b/src/glut/glx/glut_fbc.c @@ -18,7 +18,7 @@ /* Set a Fortran callback function. */ -void GLUTAPIENTRY +void APIENTRY __glutSetFCB(int which, void *func) { #ifdef SUPPORT_FORTRAN @@ -100,7 +100,7 @@ __glutSetFCB(int which, void *func) /* Get a Fortran callback function. */ -void* GLUTAPIENTRY +void* APIENTRY __glutGetFCB(int which) { #ifdef SUPPORT_FORTRAN diff --git a/src/glut/glx/glutint.h b/src/glut/glx/glutint.h index 6fe09ffe7e..a962c78023 100644 --- a/src/glut/glx/glutint.h +++ b/src/glut/glx/glutint.h @@ -26,7 +26,10 @@ #include <GL/glx.h> #endif +#ifndef GLUT_BUILDING_LIB #define GLUT_BUILDING_LIB /* Building the GLUT library itself. */ +#endif + #include <GL/glut.h> #if defined(MESA) && defined(_WIN32) && !defined(__CYGWIN32__) diff --git a/src/glut/glx/win32_winproc.c b/src/glut/glx/win32_winproc.c index a54bac75fa..e1fc785ebb 100644 --- a/src/glut/glx/win32_winproc.c +++ b/src/glut/glx/win32_winproc.c @@ -9,6 +9,9 @@ #include "glutint.h" #include <sys/timeb.h> +#ifdef __MINGW32__ +#include <ctype.h> +#endif #if defined(_WIN32) && !defined(__CYGWIN32__) #include <mmsystem.h> /* Win32 Multimedia API header. */ diff --git a/src/glx/x11/glxext.c b/src/glx/x11/glxext.c index af3a5166dc..8fe10338a8 100644 --- a/src/glx/x11/glxext.c +++ b/src/glx/x11/glxext.c @@ -672,8 +672,11 @@ filter_modes( __GLcontextModes ** server_modes, if ( do_delete && (m->visualID != 0) ) { do_delete = GL_FALSE; - fprintf(stderr, "libGL warning: 3D driver claims to not support " - "visual 0x%02x\n", m->visualID); + /* don't warn for this visual (Novell #247471 / X.Org #6689) */ + if (m->visualRating != GLX_NON_CONFORMANT_CONFIG) { + fprintf(stderr, "libGL warning: 3D driver claims to not " + "support visual 0x%02x\n", m->visualID); + } } if ( do_delete ) { diff --git a/src/mesa/Makefile.mgw b/src/mesa/Makefile.mgw index ebec5c055a..6244ded876 100644 --- a/src/mesa/Makefile.mgw +++ b/src/mesa/Makefile.mgw @@ -1,5 +1,5 @@ # Mesa 3-D graphics library -# Version: 5.1 +# Version: 7.0 # # Copyright (C) 1999-2003 Brian Paul All Rights Reserved. # @@ -26,6 +26,16 @@ # Email : dborca@users.sourceforge.net # Web : http://www.geocities.com/dborca +# MinGW core-gl makefile updated for Mesa 7.0 +# +# updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! + # # Available options: @@ -52,7 +62,6 @@ # - .PHONY: all clean .INTERMEDIATE: x86/gen_matypes.exe .SUFFIXES: .rc .res @@ -60,23 +69,37 @@ # Set this to the prefix of your build tools, i.e. mingw32- TOOLS_PREFIX = mingw32- -TOP = ../.. -GLIDE ?= $(TOP)/glide3 -LIBDIR = $(TOP)/lib ifeq ($(ICD),1) - GL_DLL = mesa32.dll - GL_IMP = libmesa32.a + LIB_NAME = mesa32 else - GL_DLL = opengl32.dll - GL_IMP = libopengl32.a + LIB_NAME = opengl32 endif -LDLIBS = -lgdi32 +DLL_EXT = .dll +IMP_EXT = .a +LIB_PRE = lib +STRIP = -s + +AR = ar +ARFLAGS = crus +DLLTOOL = dlltool + +TOP = ../.. +GLIDE ?= $(TOP)/glide3 +LIBDIR = $(TOP)/lib +GL_DLL = $(LIB_NAME)$(DLL_EXT) +GL_IMP = $(LIB_PRE)$(LIB_NAME)$(IMP_EXT) + +MESA_LIB = libmesa.a CC = $(TOOLS_PREFIX)gcc -CFLAGS += -DBUILD_GL32 -D_OPENGL32_ -CFLAGS += $(INCLUDE_DIRS) -CFLAGS += -DUSE_EXTERNAL_DXTN_LIB=1 + +LDLIBS = -lgdi32 -luser32 -liberty +LDFLAGS = $(STRIP) -shared -fPIC -Wl,--kill-at + +CFLAGS += -DBUILD_GL32 -D_DLL -DMESA_MINWARN +CFLAGS += -DNDEBUG -DUSE_EXTERNAL_DXTN_LIB=1 + ifeq ($(FX),1) CFLAGS += -I$(GLIDE)/include -DFX LDLIBS += -L$(GLIDE)/lib -lglide3x @@ -87,12 +110,11 @@ else CFLAGS += -DUSE_MGL_NAMESPACE GL_DEF = drivers/windows/icd/mesa.def else - GL_DEF = drivers/windows/gdi/mesa.def + GL_DEF = $(LIB_NAME).def endif endif -AR = ar -ARFLAGS = crus + UNLINK = del $(subst /,\,$(1)) ifneq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) @@ -104,6 +126,8 @@ endif include sources +CFLAGS += $(INCLUDE_DIRS) + ifeq ($(X86),1) CFLAGS += -DUSE_X86_ASM CFLAGS += -DUSE_MMX_ASM @@ -140,22 +164,23 @@ RESOURCE = $(GL_RES:.rc=.res) .c.o: $(CC) -o $@ $(CFLAGS) -c $< -.S.o: - $(CC) -o $@ $(CFLAGS) -c $< .s.o: $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $< + .rc.res: windres -o $@ -Irc -Ocoff $< + all: $(LIBDIR) $(LIBDIR)/$(GL_DLL) $(LIBDIR)/$(GL_IMP) $(LIBDIR): mkdir -p $(LIBDIR) $(LIBDIR)/$(GL_DLL) $(LIBDIR)/$(GL_IMP): $(OBJECTS) $(RESOURCE) - $(TOOLS_PREFIX)dllwrap -o $(LIBDIR)/$(GL_DLL) --output-lib $(LIBDIR)/$(GL_IMP) \ - --target i386-mingw32 --def $(GL_DEF) -Wl,-enable-stdcall-fixup \ - $^ $(LDLIBS) + $(CC) $(LDFLAGS) -o $(LIBDIR)/$(GL_DLL) $^ $(LDLIBS) + $(DLLTOOL) --as=as --dllname $(LIB_NAME) --output-def $(LIBDIR)/$(GL_DEF) $^ + $(DLLTOOL) --as=as -k --dllname $(LIB_NAME) --output-lib $(LIBDIR)/$(GL_IMP) --def $(LIBDIR)/$(GL_DEF) + $(X86_OBJECTS): x86/matypes.h @@ -187,17 +212,21 @@ tnl/t_vtx_x86_gcc.o: tnl/t_vtx_x86_gcc.S $(CC) -o $@ $(CFLAGS) -DSTDCALL_API -c $< clean: - -$(call UNLINK,array_cache/*.o) -$(call UNLINK,glapi/*.o) -$(call UNLINK,main/*.o) -$(call UNLINK,math/*.o) + -$(call UNLINK,vbo/*.o) -$(call UNLINK,shader/*.o) + -$(call UNLINK,shader/slang/*.o) + -$(call UNLINK,shader/grammar/*.o) -$(call UNLINK,sparc/*.o) -$(call UNLINK,ppc/*.o) -$(call UNLINK,swrast/*.o) -$(call UNLINK,swrast_setup/*.o) -$(call UNLINK,tnl/*.o) -$(call UNLINK,x86/*.o) + -$(call UNLINK,x86/rtasm/*.o) + -$(call UNLINK,x86-64/*.o) -$(call UNLINK,drivers/common/*.o) -$(call UNLINK,drivers/glide/*.o) -$(call UNLINK,drivers/windows/fx/*.o) diff --git a/src/mesa/drivers/dri/common/dri_drmpool.c b/src/mesa/drivers/dri/common/dri_drmpool.c index 878a148b39..592ac10542 100644 --- a/src/mesa/drivers/dri/common/dri_drmpool.c +++ b/src/mesa/drivers/dri/common/dri_drmpool.c @@ -51,6 +51,7 @@ pool_create(struct _DriBufferPool *pool, return NULL; if ((alignment > pageSize) && (alignment % pageSize)) { + free(buf); return NULL; } diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index d785382f39..6e8a5b5218 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -434,10 +434,12 @@ __driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp) if (pdp->pClipRects) { _mesa_free(pdp->pClipRects); + pdp->pClipRects = NULL; } if (pdp->pBackClipRects) { _mesa_free(pdp->pBackClipRects); + pdp->pBackClipRects = NULL; } DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); diff --git a/src/mesa/drivers/dri/common/spantmp2.h b/src/mesa/drivers/dri/common/spantmp2.h index 50f3cf5581..53f5f846a0 100644 --- a/src/mesa/drivers/dri/common/spantmp2.h +++ b/src/mesa/drivers/dri/common/spantmp2.h @@ -114,7 +114,7 @@ do { \ GLuint p = *(volatile GLuint *) GET_PTR(_x, _y); \ __asm__ __volatile__( "bswap %0; rorl $8, %0" \ - : "=r" (p) : "r" (p) ); \ + : "=r" (p) : "0" (p) ); \ ((GLuint *)rgba)[0] = p; \ } while (0) # elif defined( MESA_BIG_ENDIAN ) diff --git a/src/mesa/drivers/dri/i810/i810screen.c b/src/mesa/drivers/dri/i810/i810screen.c index f64c10a9ae..f8cf050d7e 100644 --- a/src/mesa/drivers/dri/i810/i810screen.c +++ b/src/mesa/drivers/dri/i810/i810screen.c @@ -288,8 +288,8 @@ i810InitDriver(__DRIscreenPrivate *sPriv) i810Screen->depth.handle, i810Screen->depth.size, (drmAddress *)&i810Screen->depth.map) != 0) { - FREE(i810Screen); drmUnmap(i810Screen->back.map, i810Screen->back.size); + FREE(i810Screen); sPriv->private = NULL; __driUtilMessage("i810InitDriver: drmMap (2) failed"); return GL_FALSE; diff --git a/src/mesa/drivers/dri/i810/i810state.c b/src/mesa/drivers/dri/i810/i810state.c index 3ad25282d9..e0d5b2b487 100644 --- a/src/mesa/drivers/dri/i810/i810state.c +++ b/src/mesa/drivers/dri/i810/i810state.c @@ -380,7 +380,10 @@ static void i810CullFaceFrontFace(GLcontext *ctx, GLenum unused) static void i810LineWidth( GLcontext *ctx, GLfloat widthf ) { i810ContextPtr imesa = I810_CONTEXT( ctx ); - int width = (int)ctx->Line._Width; + /* AA, non-AA limits are same */ + const int width = (int) CLAMP(ctx->Line.Width, + ctx->Const.MinLineWidth, + ctx->Const.MaxLineWidth); imesa->LcsLineWidth = 0; if (width & 1) imesa->LcsLineWidth |= LCS_LINEWIDTH_1_0; @@ -396,7 +399,10 @@ static void i810LineWidth( GLcontext *ctx, GLfloat widthf ) static void i810PointSize( GLcontext *ctx, GLfloat sz ) { i810ContextPtr imesa = I810_CONTEXT( ctx ); - int size = (int)ctx->Point._Size; + /* AA, non-AA limits are same */ + const int size = (int) CLAMP(ctx->Point.Size, + ctx->Const.MinPointSize, + ctx->Const.MaxPointSize); imesa->LcsPointSize = 0; if (size & 1) imesa->LcsPointSize |= LCS_LINEWIDTH_1_0; diff --git a/src/mesa/drivers/dri/i810/i810tris.c b/src/mesa/drivers/dri/i810/i810tris.c index 3e09427bb9..2c4ee06633 100644 --- a/src/mesa/drivers/dri/i810/i810tris.c +++ b/src/mesa/drivers/dri/i810/i810tris.c @@ -112,7 +112,9 @@ static __inline__ void i810_draw_quad( i810ContextPtr imesa, static __inline__ void i810_draw_point( i810ContextPtr imesa, i810VertexPtr tmp ) { - GLfloat sz = imesa->glCtx->Point._Size * .5; + GLfloat sz = 0.5 * CLAMP(imesa->glCtx->Point.Size, + imesa->glCtx->Const.MinPointSize, + imesa->glCtx->Const.MaxPointSize); int vertsize = imesa->vertex_size; GLuint *vb = i810AllocDmaLow( imesa, 2 * 4 * vertsize ); int j; diff --git a/src/mesa/drivers/dri/i915/i830_vtbl.c b/src/mesa/drivers/dri/i915/i830_vtbl.c index d40cf705a3..cf1d0b0c1e 100644 --- a/src/mesa/drivers/dri/i915/i830_vtbl.c +++ b/src/mesa/drivers/dri/i915/i830_vtbl.c @@ -59,6 +59,11 @@ do { \ #define VRTX_TEX_SET_FMT(n, x) ((x)<<((n)*2)) #define TEXBIND_SET(n, x) ((x)<<((n)*4)) + static void +i830_render_prevalidate(struct intel_context *intel) +{ +} + static void i830_render_start( intelContextPtr intel ) { GLcontext *ctx = &intel->ctx; @@ -531,4 +536,5 @@ void i830InitVtbl( i830ContextPtr i830 ) i830->intel.vtbl.update_texture_state = i830UpdateTextureState; i830->intel.vtbl.emit_flush = i830_emit_flush; i830->intel.vtbl.render_start = i830_render_start; + i830->intel.vtbl.render_prevalidate = i830_render_prevalidate; } diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c index 702b878828..abca0bbffe 100644 --- a/src/mesa/drivers/dri/i915/i915_fragprog.c +++ b/src/mesa/drivers/dri/i915/i915_fragprog.c @@ -304,7 +304,7 @@ static void upload_program( struct i915_fragment_program *p ) A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, src0, - i915_emit_const1f(p, 1.0/(M_PI * 2)), + i915_emit_const1f(p, 1.0/(M_PI)), 0); i915_emit_arith( p, @@ -319,7 +319,7 @@ static void upload_program( struct i915_fragment_program *p ) A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, tmp, - i915_emit_const1f(p, (M_PI * 2)), + i915_emit_const1f(p, (M_PI)), 0); /* @@ -645,7 +645,7 @@ static void upload_program( struct i915_fragment_program *p ) A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, src0, - i915_emit_const1f(p, 1.0/(M_PI * 2)), + i915_emit_const1f(p, 1.0/(M_PI)), 0); i915_emit_arith( p, @@ -660,7 +660,7 @@ static void upload_program( struct i915_fragment_program *p ) A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, tmp, - i915_emit_const1f(p, (M_PI * 2)), + i915_emit_const1f(p, (M_PI)), 0); /* diff --git a/src/mesa/drivers/dri/i915/i915_texstate.c b/src/mesa/drivers/dri/i915/i915_texstate.c index a19d4b6584..2b806cc36e 100644 --- a/src/mesa/drivers/dri/i915/i915_texstate.c +++ b/src/mesa/drivers/dri/i915/i915_texstate.c @@ -60,6 +60,33 @@ static GLint step_offsets[6][2] = { {0,2}, #define I915_TEX_UNIT_ENABLED(unit) (1<<unit) +static GLuint i915_compressed_alignment(GLint internal_fmt) +{ + GLuint alignment = 4; + + switch (internal_fmt) { + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: + alignment = 8; + break; + + default: + break; + } + + return alignment; +} + +static int align(int value, GLuint alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + +static GLuint minify(GLuint d) +{ + return MAX2(1, d >> 1); +} + static void i915LayoutTextureImages( i915ContextPtr i915, struct gl_texture_object *tObj ) { @@ -161,8 +188,15 @@ static void i915LayoutTextureImages( i915ContextPtr i915, break; } default: - pitch = tObj->Image[0][firstLevel]->Width * t->intel.texelBytes; - pitch = (pitch + 3) & ~3; + if (baseImage->IsCompressed) { + GLuint alignment = i915_compressed_alignment(baseImage->InternalFormat); + + pitch = align(tObj->Image[0][firstLevel]->Width, alignment) * t->intel.texelBytes; + } else { + pitch = tObj->Image[0][firstLevel]->Width * t->intel.texelBytes; + pitch = (pitch + 3) & ~3; + } + t->intel.base.dirty_images[0] = ~0; for ( total_height = i = 0 ; i < numLevels ; i++ ) { @@ -343,8 +377,23 @@ static void i945LayoutTextureImages( i915ContextPtr i915, break; } default: - pitch = tObj->Image[0][firstLevel]->Width * t->intel.texelBytes; - pitch = (pitch + 3) & ~3; + if (baseImage->IsCompressed) { + GLuint alignment = i915_compressed_alignment(baseImage->InternalFormat); + + pitch = align(tObj->Image[0][firstLevel]->Width, alignment); + if (numLevels > 2) { + GLint width0 = align(minify(tObj->Image[0][firstLevel]->Width), alignment) + + + align(minify(minify(tObj->Image[0][firstLevel]->Width)), alignment); + + if (width0 > pitch) + pitch = width0; + } + pitch = pitch * t->intel.texelBytes; + } else { + pitch = tObj->Image[0][firstLevel]->Width * t->intel.texelBytes; + pitch = (pitch + 3) & ~3; + } + t->intel.base.dirty_images[0] = ~0; max_offset = 0; diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c index b0e5f87fc7..4ad95cf4e3 100644 --- a/src/mesa/drivers/dri/i915/i915_vtbl.c +++ b/src/mesa/drivers/dri/i915/i915_vtbl.c @@ -41,7 +41,8 @@ #include "i915_reg.h" #include "i915_context.h" -static void i915_render_start( intelContextPtr intel ) +static void +i915_render_prevalidate(struct intel_context *intel) { GLcontext *ctx = &intel->ctx; i915ContextPtr i915 = I915_CONTEXT(intel); @@ -54,6 +55,10 @@ static void i915_render_start( intelContextPtr intel ) } } +static void i915_render_start( intelContextPtr intel ) +{ +} + static void i915_reduced_primitive_state( intelContextPtr intel, GLenum rprim ) @@ -64,6 +69,7 @@ static void i915_reduced_primitive_state( intelContextPtr intel, st1 &= ~ST1_ENABLE; switch (rprim) { + case GL_QUADS: /* from RASTERIZE(GL_QUADS) in t_dd_tritemp.h */ case GL_TRIANGLES: if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple) @@ -453,6 +459,7 @@ void i915InitVtbl( i915ContextPtr i915 ) i915->intel.vtbl.lost_hardware = i915_lost_hardware; i915->intel.vtbl.reduced_primitive_state = i915_reduced_primitive_state; i915->intel.vtbl.render_start = i915_render_start; + i915->intel.vtbl.render_prevalidate = i915_render_prevalidate; i915->intel.vtbl.set_color_region = i915_set_color_region; i915->intel.vtbl.set_z_region = i915_set_z_region; i915->intel.vtbl.update_color_z_regions = i915_update_color_z_regions; diff --git a/src/mesa/drivers/dri/i915/intel_context.h b/src/mesa/drivers/dri/i915/intel_context.h index 3b50107d73..914533d11b 100644 --- a/src/mesa/drivers/dri/i915/intel_context.h +++ b/src/mesa/drivers/dri/i915/intel_context.h @@ -112,6 +112,7 @@ struct intel_context void (*update_texture_state)( intelContextPtr intel ); void (*render_start)( intelContextPtr intel ); + void (*render_prevalidate) (struct intel_context * intel); void (*set_color_region)( intelContextPtr intel, const intelRegion *reg ); void (*set_z_region)( intelContextPtr intel, const intelRegion *reg ); void (*update_color_z_regions)(intelContextPtr intel, diff --git a/src/mesa/drivers/dri/i915/intel_pixel.c b/src/mesa/drivers/dri/i915/intel_pixel.c index d175870a0c..c3030d42b0 100644 --- a/src/mesa/drivers/dri/i915/intel_pixel.c +++ b/src/mesa/drivers/dri/i915/intel_pixel.c @@ -450,10 +450,16 @@ intelDrawPixels( GLcontext *ctx, * wise happily run the fragment program on each pixel in the image). */ struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; + /* can't just set current frag prog to 0 here as on buffer resize + we'll get new state checks which will segfault. Remains a hack. */ ctx->FragmentProgram._Current = NULL; + ctx->FragmentProgram._UseTexEnvProgram = GL_FALSE; + ctx->FragmentProgram._Active = GL_FALSE; _swrast_DrawPixels( ctx, x, y, width, height, format, type, unpack, pixels ); ctx->FragmentProgram._Current = fpSave; + ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + ctx->FragmentProgram._Active = GL_TRUE; } else { _swrast_DrawPixels( ctx, x, y, width, height, format, type, diff --git a/src/mesa/drivers/dri/i915/intel_render.c b/src/mesa/drivers/dri/i915/intel_render.c index d9438ba0fd..7bc02ba807 100644 --- a/src/mesa/drivers/dri/i915/intel_render.c +++ b/src/mesa/drivers/dri/i915/intel_render.c @@ -199,6 +199,8 @@ static GLboolean intel_run_render( GLcontext *ctx, struct vertex_buffer *VB = &tnl->vb; GLuint i; + intel->vtbl.render_prevalidate( intel ); + /* Don't handle clipping or indexed vertices. */ if (intel->RenderIndex != 0 || diff --git a/src/mesa/drivers/dri/i915/intel_tex.c b/src/mesa/drivers/dri/i915/intel_tex.c index 5bd280652a..978945f26b 100644 --- a/src/mesa/drivers/dri/i915/intel_tex.c +++ b/src/mesa/drivers/dri/i915/intel_tex.c @@ -643,17 +643,19 @@ static void intelUploadTexImage( intelContextPtr intel, switch (image->InternalFormat) { case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_RGBA_FXT1_3DFX: + row_len = ((image->Width + 7) & ~7) * 2; + break; case GL_RGB_S3TC: case GL_RGB4_S3TC: case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - row_len = (image->Width * 2 + 7) & ~7; + row_len = ((image->Width + 3) & ~3) * 2; break; case GL_RGBA_S3TC: case GL_RGBA4_S3TC: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - row_len = (image->Width * 4 + 15) & ~15; + row_len = ((image->Width + 3) & ~3) * 4; break; default: fprintf(stderr,"Internal Compressed format not supported %d\n", image->InternalFormat); diff --git a/src/mesa/drivers/dri/i915tex/Makefile b/src/mesa/drivers/dri/i915tex/Makefile index b218929dce..445327f243 100644 --- a/src/mesa/drivers/dri/i915tex/Makefile +++ b/src/mesa/drivers/dri/i915tex/Makefile @@ -37,6 +37,7 @@ DRIVER_SOURCES = \ i915_texstate.c \ i915_context.c \ i915_debug.c \ + i915_debug_fp.c \ i915_fragprog.c \ i915_metaops.c \ i915_program.c \ diff --git a/src/mesa/drivers/dri/i915tex/i830_vtbl.c b/src/mesa/drivers/dri/i915tex/i830_vtbl.c index 20c6900025..d78d1f2adf 100644 --- a/src/mesa/drivers/dri/i915tex/i830_vtbl.c +++ b/src/mesa/drivers/dri/i915tex/i830_vtbl.c @@ -524,6 +524,16 @@ i830_emit_state(struct intel_context *intel) static void i830_destroy_context(struct intel_context *intel) { + GLuint i; + struct i830_context *i830 = i830_context(&intel->ctx); + + for (i = 0; i < I830_TEX_UNITS; i++) { + if (i830->state.tex_buffer[i] != NULL) { + driBOUnReference(i830->state.tex_buffer[i]); + i830->state.tex_buffer[i] = NULL; + } + } + _tnl_free_vertices(&intel->ctx); } diff --git a/src/mesa/drivers/dri/i915tex/i915_debug.c b/src/mesa/drivers/dri/i915tex/i915_debug.c index 974527e14c..c0e1242a0e 100644 --- a/src/mesa/drivers/dri/i915tex/i915_debug.c +++ b/src/mesa/drivers/dri/i915tex/i915_debug.c @@ -25,310 +25,819 @@ * **************************************************************************/ +#include "imports.h" + #include "i915_reg.h" #include "i915_context.h" -#include <stdio.h> - - -static const char *opcodes[0x20] = { - "NOP", - "ADD", - "MOV", - "MUL", - "MAD", - "DP2ADD", - "DP3", - "DP4", - "FRC", - "RCP", - "RSQ", - "EXP", - "LOG", - "CMP", - "MIN", - "MAX", - "FLR", - "MOD", - "TRC", - "SGE", - "SLT", - "TEXLD", - "TEXLDP", - "TEXLDB", - "TEXKILL", - "DCL", - "0x1a", - "0x1b", - "0x1c", - "0x1d", - "0x1e", - "0x1f", -}; - - -static const int args[0x20] = { - 0, /* 0 nop */ - 2, /* 1 add */ - 1, /* 2 mov */ - 2, /* 3 m ul */ - 3, /* 4 mad */ - 3, /* 5 dp2add */ - 2, /* 6 dp3 */ - 2, /* 7 dp4 */ - 1, /* 8 frc */ - 1, /* 9 rcp */ - 1, /* a rsq */ - 1, /* b exp */ - 1, /* c log */ - 3, /* d cmp */ - 2, /* e min */ - 2, /* f max */ - 1, /* 10 flr */ - 1, /* 11 mod */ - 1, /* 12 trc */ - 2, /* 13 sge */ - 2, /* 14 slt */ - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, -}; - - -static const char *regname[0x8] = { - "R", - "T", - "CONST", - "S", - "OC", - "OD", - "U", - "UNKNOWN", -}; - -static void -print_reg_type_nr(GLuint type, GLuint nr) +#include "i915_debug.h" + +#define PRINTF( ... ) _mesa_printf( __VA_ARGS__ ) + +static GLboolean debug( struct debug_stream *stream, const char *name, GLuint len ) { - switch (type) { - case REG_TYPE_T: - switch (nr) { - case T_DIFFUSE: - fprintf(stderr, "T_DIFFUSE"); - return; - case T_SPECULAR: - fprintf(stderr, "T_SPECULAR"); - return; - case T_FOG_W: - fprintf(stderr, "T_FOG_W"); - return; - default: - fprintf(stderr, "T_TEX%d", nr); - return; - } - case REG_TYPE_OC: - if (nr == 0) { - fprintf(stderr, "oC"); - return; - } - break; - case REG_TYPE_OD: - if (nr == 0) { - fprintf(stderr, "oD"); - return; - } - break; - default: - break; + GLuint i; + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + + if (len == 0) { + PRINTF("Error - zero length packet (0x%08x)\n", stream->ptr[0]); + assert(0); + return GL_FALSE; } - fprintf(stderr, "%s[%d]", regname[type], nr); + if (stream->print_addresses) + PRINTF("%08x: ", stream->offset); + + + PRINTF("%s (%d dwords):\n", name, len); + for (i = 0; i < len; i++) + PRINTF("\t0x%08x\n", ptr[i]); + PRINTF("\n"); + + stream->offset += len * sizeof(GLuint); + + return GL_TRUE; +} + + +static const char *get_prim_name( GLuint val ) +{ + switch (val & PRIM3D_MASK) { + case PRIM3D_TRILIST: return "TRILIST"; break; + case PRIM3D_TRISTRIP: return "TRISTRIP"; break; + case PRIM3D_TRISTRIP_RVRSE: return "TRISTRIP_RVRSE"; break; + case PRIM3D_TRIFAN: return "TRIFAN"; break; + case PRIM3D_POLY: return "POLY"; break; + case PRIM3D_LINELIST: return "LINELIST"; break; + case PRIM3D_LINESTRIP: return "LINESTRIP"; break; + case PRIM3D_RECTLIST: return "RECTLIST"; break; + case PRIM3D_POINTLIST: return "POINTLIST"; break; + case PRIM3D_DIB: return "DIB"; break; + case PRIM3D_CLEAR_RECT: return "CLEAR_RECT"; break; + case PRIM3D_ZONE_INIT: return "ZONE_INIT"; break; + default: return "????"; break; + } } -#define REG_SWIZZLE_MASK 0x7777 -#define REG_NEGATE_MASK 0x8888 +static GLboolean debug_prim( struct debug_stream *stream, const char *name, + GLboolean dump_floats, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + const char *prim = get_prim_name( ptr[0] ); + GLuint i; + -#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \ - (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \ - (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \ - (SRC_W << A2_SRC2_CHANNEL_W_SHIFT)) + + PRINTF("%s %s (%d dwords):\n", name, prim, len); + PRINTF("\t0x%08x\n", ptr[0]); + for (i = 1; i < len; i++) { + if (dump_floats) + PRINTF("\t0x%08x // %f\n", ptr[i], *(GLfloat *)&ptr[i]); + else + PRINTF("\t0x%08x\n", ptr[i]); + } + + + PRINTF("\n"); + + stream->offset += len * sizeof(GLuint); + + return GL_TRUE; +} + -static void -print_reg_neg_swizzle(GLuint reg) + +static GLboolean debug_program( struct debug_stream *stream, const char *name, GLuint len ) { - int i; - - if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW && - (reg & REG_NEGATE_MASK) == 0) - return; - - fprintf(stderr, "."); - - for (i = 3; i >= 0; i--) { - if (reg & (1 << ((i * 4) + 3))) - fprintf(stderr, "-"); - - switch ((reg >> (i * 4)) & 0x7) { - case 0: - fprintf(stderr, "x"); - break; - case 1: - fprintf(stderr, "y"); - break; - case 2: - fprintf(stderr, "z"); - break; - case 3: - fprintf(stderr, "w"); - break; - case 4: - fprintf(stderr, "0"); - break; - case 5: - fprintf(stderr, "1"); - break; - default: - fprintf(stderr, "?"); - break; + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + + if (len == 0) { + PRINTF("Error - zero length packet (0x%08x)\n", stream->ptr[0]); + assert(0); + return GL_FALSE; + } + + if (stream->print_addresses) + PRINTF("%08x: ", stream->offset); + + PRINTF("%s (%d dwords):\n", name, len); + i915_disassemble_program( ptr, len ); + + stream->offset += len * sizeof(GLuint); + return GL_TRUE; +} + + +static GLboolean debug_chain( struct debug_stream *stream, const char *name, GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + GLuint old_offset = stream->offset + len * sizeof(GLuint); + GLuint i; + + PRINTF("%s (%d dwords):\n", name, len); + for (i = 0; i < len; i++) + PRINTF("\t0x%08x\n", ptr[i]); + + stream->offset = ptr[1] & ~0x3; + + if (stream->offset < old_offset) + PRINTF("\n... skipping backwards from 0x%x --> 0x%x ...\n\n", + old_offset, stream->offset ); + else + PRINTF("\n... skipping from 0x%x --> 0x%x ...\n\n", + old_offset, stream->offset ); + + + return GL_TRUE; +} + + +static GLboolean debug_variable_length_prim( struct debug_stream *stream ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + const char *prim = get_prim_name( ptr[0] ); + GLuint i, len; + + GLushort *idx = (GLushort *)(ptr+1); + for (i = 0; idx[i] != 0xffff; i++) + ; + + len = 1+(i+2)/2; + + PRINTF("3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len); + for (i = 0; i < len; i++) + PRINTF("\t0x%08x\n", ptr[i]); + PRINTF("\n"); + + stream->offset += len * sizeof(GLuint); + return GL_TRUE; +} + + +#define BITS( dw, hi, lo, ... ) \ +do { \ + unsigned himask = ~0UL >> (31 - (hi)); \ + PRINTF("\t\t "); \ + PRINTF(__VA_ARGS__); \ + PRINTF(": 0x%x\n", ((dw) & himask) >> (lo)); \ +} while (0) + +#define MBZ( dw, hi, lo) do { \ + unsigned x = (dw) >> (lo); \ + unsigned lomask = (1 << (lo)) - 1; \ + unsigned himask; \ + himask = (1UL << (hi)) - 1; \ + assert ((x & himask & ~lomask) == 0); \ +} while (0) + +#define FLAG( dw, bit, ... ) \ +do { \ + if (((dw) >> (bit)) & 1) { \ + PRINTF("\t\t "); \ + PRINTF(__VA_ARGS__); \ + PRINTF("\n"); \ + } \ +} while (0) + +static GLboolean debug_load_immediate( struct debug_stream *stream, + const char *name, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + GLuint bits = (ptr[0] >> 4) & 0xff; + GLuint j = 0; + + PRINTF("%s (%d dwords, flags: %x):\n", name, len, bits); + PRINTF("\t0x%08x\n", ptr[j++]); + + if (bits & (1<<0)) { + PRINTF("\t LIS0: 0x%08x\n", ptr[j]); + PRINTF("\t vb address: 0x%08x\n", (ptr[j] & ~0x3)); + BITS(ptr[j], 0, 0, "vb invalidate disable"); + j++; + } + if (bits & (1<<1)) { + PRINTF("\t LIS1: 0x%08x\n", ptr[j]); + BITS(ptr[j], 29, 24, "vb dword width"); + BITS(ptr[j], 21, 16, "vb dword pitch"); + BITS(ptr[j], 15, 0, "vb max index"); + j++; + } + if (bits & (1<<2)) { + int i; + PRINTF("\t LIS2: 0x%08x\n", ptr[j]); + for (i = 0; i < 8; i++) { + unsigned tc = (ptr[j] >> (i * 4)) & 0xf; + if (tc != 0xf) + BITS(tc, 3, 0, "tex coord %d", i); + } + j++; + } + if (bits & (1<<3)) { + PRINTF("\t LIS3: 0x%08x\n", ptr[j]); + j++; + } + if (bits & (1<<4)) { + PRINTF("\t LIS4: 0x%08x\n", ptr[j]); + BITS(ptr[j], 31, 23, "point width"); + BITS(ptr[j], 22, 19, "line width"); + FLAG(ptr[j], 18, "alpha flatshade"); + FLAG(ptr[j], 17, "fog flatshade"); + FLAG(ptr[j], 16, "spec flatshade"); + FLAG(ptr[j], 15, "rgb flatshade"); + BITS(ptr[j], 14, 13, "cull mode"); + FLAG(ptr[j], 12, "vfmt: point width"); + FLAG(ptr[j], 11, "vfmt: specular/fog"); + FLAG(ptr[j], 10, "vfmt: rgba"); + FLAG(ptr[j], 9, "vfmt: depth offset"); + BITS(ptr[j], 8, 6, "vfmt: position (2==xyzw)"); + FLAG(ptr[j], 5, "force dflt diffuse"); + FLAG(ptr[j], 4, "force dflt specular"); + FLAG(ptr[j], 3, "local depth offset enable"); + FLAG(ptr[j], 2, "vfmt: fp32 fog coord"); + FLAG(ptr[j], 1, "sprite point"); + FLAG(ptr[j], 0, "antialiasing"); + j++; + } + if (bits & (1<<5)) { + PRINTF("\t LIS5: 0x%08x\n", ptr[j]); + BITS(ptr[j], 31, 28, "rgba write disables"); + FLAG(ptr[j], 27, "force dflt point width"); + FLAG(ptr[j], 26, "last pixel enable"); + FLAG(ptr[j], 25, "global z offset enable"); + FLAG(ptr[j], 24, "fog enable"); + BITS(ptr[j], 23, 16, "stencil ref"); + BITS(ptr[j], 15, 13, "stencil test"); + BITS(ptr[j], 12, 10, "stencil fail op"); + BITS(ptr[j], 9, 7, "stencil pass z fail op"); + BITS(ptr[j], 6, 4, "stencil pass z pass op"); + FLAG(ptr[j], 3, "stencil write enable"); + FLAG(ptr[j], 2, "stencil test enable"); + FLAG(ptr[j], 1, "color dither enable"); + FLAG(ptr[j], 0, "logiop enable"); + j++; + } + if (bits & (1<<6)) { + PRINTF("\t LIS6: 0x%08x\n", ptr[j]); + FLAG(ptr[j], 31, "alpha test enable"); + BITS(ptr[j], 30, 28, "alpha func"); + BITS(ptr[j], 27, 20, "alpha ref"); + FLAG(ptr[j], 19, "depth test enable"); + BITS(ptr[j], 18, 16, "depth func"); + FLAG(ptr[j], 15, "blend enable"); + BITS(ptr[j], 14, 12, "blend func"); + BITS(ptr[j], 11, 8, "blend src factor"); + BITS(ptr[j], 7, 4, "blend dst factor"); + FLAG(ptr[j], 3, "depth write enable"); + FLAG(ptr[j], 2, "color write enable"); + BITS(ptr[j], 1, 0, "provoking vertex"); + j++; + } + + + PRINTF("\n"); + + assert(j == len); + + stream->offset += len * sizeof(GLuint); + + return GL_TRUE; +} + + + +static GLboolean debug_load_indirect( struct debug_stream *stream, + const char *name, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + GLuint bits = (ptr[0] >> 8) & 0x3f; + GLuint i, j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); + + for (i = 0; i < 6; i++) { + if (bits & (1<<i)) { + switch (1<<(8+i)) { + case LI0_STATE_STATIC_INDIRECT: + PRINTF(" STATIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++; + PRINTF(" 0x%08x\n", ptr[j++]); + break; + case LI0_STATE_DYNAMIC_INDIRECT: + PRINTF(" DYNAMIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++; + break; + case LI0_STATE_SAMPLER: + PRINTF(" SAMPLER: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++; + PRINTF(" 0x%08x\n", ptr[j++]); + break; + case LI0_STATE_MAP: + PRINTF(" MAP: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++; + PRINTF(" 0x%08x\n", ptr[j++]); + break; + case LI0_STATE_PROGRAM: + PRINTF(" PROGRAM: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++; + PRINTF(" 0x%08x\n", ptr[j++]); + break; + case LI0_STATE_CONSTANTS: + PRINTF(" CONSTANTS: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++; + PRINTF(" 0x%08x\n", ptr[j++]); + break; + default: + assert(0); + break; + } } } + + if (bits == 0) { + PRINTF("\t DUMMY: 0x%08x\n", ptr[j++]); + } + + PRINTF("\n"); + + + assert(j == len); + + stream->offset += len * sizeof(GLuint); + + return GL_TRUE; +} + +static void BR13( struct debug_stream *stream, + GLuint val ) +{ + PRINTF("\t0x%08x\n", val); + FLAG(val, 30, "clipping enable"); + BITS(val, 25, 24, "color depth (3==32bpp)"); + BITS(val, 23, 16, "raster op"); + BITS(val, 15, 0, "dest pitch"); } -static void -print_src_reg(GLuint dword) +static void BR22( struct debug_stream *stream, + GLuint val ) { - GLuint nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK; - GLuint type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK; - print_reg_type_nr(type, nr); - print_reg_neg_swizzle(dword); + PRINTF("\t0x%08x\n", val); + BITS(val, 31, 16, "dest y1"); + BITS(val, 15, 0, "dest x1"); } -void -i915_print_ureg(const char *msg, GLuint ureg) +static void BR23( struct debug_stream *stream, + GLuint val ) +{ + PRINTF("\t0x%08x\n", val); + BITS(val, 31, 16, "dest y2"); + BITS(val, 15, 0, "dest x2"); +} + +static void BR09( struct debug_stream *stream, + GLuint val ) { - fprintf(stderr, "%s: ", msg); - print_src_reg(ureg >> 8); - fprintf(stderr, "\n"); + PRINTF("\t0x%08x -- dest address\n", val); } -static void -print_dest_reg(GLuint dword) +static void BR26( struct debug_stream *stream, + GLuint val ) { - GLuint nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK; - GLuint type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK; - print_reg_type_nr(type, nr); - if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL) - return; - fprintf(stderr, "."); - if (dword & A0_DEST_CHANNEL_X) - fprintf(stderr, "x"); - if (dword & A0_DEST_CHANNEL_Y) - fprintf(stderr, "y"); - if (dword & A0_DEST_CHANNEL_Z) - fprintf(stderr, "z"); - if (dword & A0_DEST_CHANNEL_W) - fprintf(stderr, "w"); + PRINTF("\t0x%08x\n", val); + BITS(val, 31, 16, "src y1"); + BITS(val, 15, 0, "src x1"); } +static void BR11( struct debug_stream *stream, + GLuint val ) +{ + PRINTF("\t0x%08x\n", val); + BITS(val, 15, 0, "src pitch"); +} -#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT)) -#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT)) -#define GET_SRC2_REG(r) (r) +static void BR12( struct debug_stream *stream, + GLuint val ) +{ + PRINTF("\t0x%08x -- src address\n", val); +} +static void BR16( struct debug_stream *stream, + GLuint val ) +{ + PRINTF("\t0x%08x -- color\n", val); +} + +static GLboolean debug_copy_blit( struct debug_stream *stream, + const char *name, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); + + BR13(stream, ptr[j++]); + BR22(stream, ptr[j++]); + BR23(stream, ptr[j++]); + BR09(stream, ptr[j++]); + BR26(stream, ptr[j++]); + BR11(stream, ptr[j++]); + BR12(stream, ptr[j++]); + + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; +} -static void -print_arith_op(GLuint opcode, const GLuint * program) +static GLboolean debug_color_blit( struct debug_stream *stream, + const char *name, + GLuint len ) { - if (opcode != A0_NOP) { - print_dest_reg(program[0]); - if (program[0] & A0_DEST_SATURATE) - fprintf(stderr, " = SATURATE "); - else - fprintf(stderr, " = "); - } + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; - fprintf(stderr, "%s ", opcodes[opcode]); + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); - print_src_reg(GET_SRC0_REG(program[0], program[1])); - if (args[opcode] == 1) { - fprintf(stderr, "\n"); - return; + BR13(stream, ptr[j++]); + BR22(stream, ptr[j++]); + BR23(stream, ptr[j++]); + BR09(stream, ptr[j++]); + BR16(stream, ptr[j++]); + + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; +} + +static GLboolean debug_modes4( struct debug_stream *stream, + const char *name, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j]); + BITS(ptr[j], 21, 18, "logicop func"); + FLAG(ptr[j], 17, "stencil test mask modify-enable"); + FLAG(ptr[j], 16, "stencil write mask modify-enable"); + BITS(ptr[j], 15, 8, "stencil test mask"); + BITS(ptr[j], 7, 0, "stencil write mask"); + j++; + + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; +} + +static GLboolean debug_map_state( struct debug_stream *stream, + const char *name, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); + + { + PRINTF("\t0x%08x\n", ptr[j]); + BITS(ptr[j], 15, 0, "map mask"); + j++; } - fprintf(stderr, ", "); - print_src_reg(GET_SRC1_REG(program[1], program[2])); - if (args[opcode] == 2) { - fprintf(stderr, "\n"); - return; + while (j < len) { + { + PRINTF("\t TMn.0: 0x%08x\n", ptr[j]); + PRINTF("\t map address: 0x%08x\n", (ptr[j] & ~0x3)); + FLAG(ptr[j], 1, "vertical line stride"); + FLAG(ptr[j], 0, "vertical line stride offset"); + j++; + } + + { + PRINTF("\t TMn.1: 0x%08x\n", ptr[j]); + BITS(ptr[j], 31, 21, "height"); + BITS(ptr[j], 20, 10, "width"); + BITS(ptr[j], 9, 7, "surface format"); + BITS(ptr[j], 6, 3, "texel format"); + FLAG(ptr[j], 2, "use fence regs"); + FLAG(ptr[j], 1, "tiled surface"); + FLAG(ptr[j], 0, "tile walk ymajor"); + j++; + } + { + PRINTF("\t TMn.2: 0x%08x\n", ptr[j]); + BITS(ptr[j], 31, 21, "dword pitch"); + BITS(ptr[j], 20, 15, "cube face enables"); + BITS(ptr[j], 14, 9, "max lod"); + FLAG(ptr[j], 8, "mip layout right"); + BITS(ptr[j], 7, 0, "depth"); + j++; + } } - fprintf(stderr, ", "); - print_src_reg(GET_SRC2_REG(program[2])); - fprintf(stderr, "\n"); - return; + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; } - -static void -print_tex_op(GLuint opcode, const GLuint * program) +static GLboolean debug_sampler_state( struct debug_stream *stream, + const char *name, + GLuint len ) { - print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL); - fprintf(stderr, " = "); + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); + + { + PRINTF("\t0x%08x\n", ptr[j]); + BITS(ptr[j], 15, 0, "sampler mask"); + j++; + } - fprintf(stderr, "%s ", opcodes[opcode]); + while (j < len) { + { + PRINTF("\t TSn.0: 0x%08x\n", ptr[j]); + FLAG(ptr[j], 31, "reverse gamma"); + FLAG(ptr[j], 30, "planar to packed"); + FLAG(ptr[j], 29, "yuv->rgb"); + BITS(ptr[j], 28, 27, "chromakey index"); + BITS(ptr[j], 26, 22, "base mip level"); + BITS(ptr[j], 21, 20, "mip mode filter"); + BITS(ptr[j], 19, 17, "mag mode filter"); + BITS(ptr[j], 16, 14, "min mode filter"); + BITS(ptr[j], 13, 5, "lod bias (s4.4)"); + FLAG(ptr[j], 4, "shadow enable"); + FLAG(ptr[j], 3, "max-aniso-4"); + BITS(ptr[j], 2, 0, "shadow func"); + j++; + } - fprintf(stderr, "S[%d],", program[0] & T0_SAMPLER_NR_MASK); + { + PRINTF("\t TSn.1: 0x%08x\n", ptr[j]); + BITS(ptr[j], 31, 24, "min lod"); + MBZ( ptr[j], 23, 18 ); + FLAG(ptr[j], 17, "kill pixel enable"); + FLAG(ptr[j], 16, "keyed tex filter mode"); + FLAG(ptr[j], 15, "chromakey enable"); + BITS(ptr[j], 14, 12, "tcx wrap mode"); + BITS(ptr[j], 11, 9, "tcy wrap mode"); + BITS(ptr[j], 8, 6, "tcz wrap mode"); + FLAG(ptr[j], 5, "normalized coords"); + BITS(ptr[j], 4, 1, "map (surface) index"); + FLAG(ptr[j], 0, "EAST deinterlacer enable"); + j++; + } + { + PRINTF("\t TSn.2: 0x%08x (default color)\n", ptr[j]); + j++; + } + } - print_reg_type_nr((program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) & - REG_TYPE_MASK, - (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK); - fprintf(stderr, "\n"); + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; } -static void -print_dcl_op(GLuint opcode, const GLuint * program) +static GLboolean debug_dest_vars( struct debug_stream *stream, + const char *name, + GLuint len ) { - fprintf(stderr, "%s ", opcodes[opcode]); - print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL); - fprintf(stderr, "\n"); + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); + + { + PRINTF("\t0x%08x\n", ptr[j]); + FLAG(ptr[j], 31, "early classic ztest"); + FLAG(ptr[j], 30, "opengl tex default color"); + FLAG(ptr[j], 29, "bypass iz"); + FLAG(ptr[j], 28, "lod preclamp"); + BITS(ptr[j], 27, 26, "dither pattern"); + FLAG(ptr[j], 25, "linear gamma blend"); + FLAG(ptr[j], 24, "debug dither"); + BITS(ptr[j], 23, 20, "dstorg x"); + BITS(ptr[j], 19, 16, "dstorg y"); + MBZ (ptr[j], 15, 15 ); + BITS(ptr[j], 14, 12, "422 write select"); + BITS(ptr[j], 11, 8, "cbuf format"); + BITS(ptr[j], 3, 2, "zbuf format"); + FLAG(ptr[j], 1, "vert line stride"); + FLAG(ptr[j], 1, "vert line stride offset"); + j++; + } + + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; } +static GLboolean debug_buf_info( struct debug_stream *stream, + const char *name, + GLuint len ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF("%s (%d dwords):\n", name, len); + PRINTF("\t0x%08x\n", ptr[j++]); + + { + PRINTF("\t0x%08x\n", ptr[j]); + BITS(ptr[j], 28, 28, "aux buffer id"); + BITS(ptr[j], 27, 24, "buffer id (7=depth, 3=back)"); + FLAG(ptr[j], 23, "use fence regs"); + FLAG(ptr[j], 22, "tiled surface"); + FLAG(ptr[j], 21, "tile walk ymajor"); + MBZ (ptr[j], 20, 14); + BITS(ptr[j], 13, 2, "dword pitch"); + MBZ (ptr[j], 2, 0); + j++; + } + + PRINTF("\t0x%08x -- buffer base address\n", ptr[j++]); + + stream->offset += len * sizeof(GLuint); + assert(j == len); + return GL_TRUE; +} + +static GLboolean i915_debug_packet( struct debug_stream *stream ) +{ + GLuint *ptr = (GLuint *)(stream->ptr + stream->offset); + GLuint cmd = *ptr; + + switch (((cmd >> 29) & 0x7)) { + case 0x0: + switch ((cmd >> 23) & 0x3f) { + case 0x0: + return debug(stream, "MI_NOOP", 1); + case 0x3: + return debug(stream, "MI_WAIT_FOR_EVENT", 1); + case 0x4: + return debug(stream, "MI_FLUSH", 1); + case 0xA: + debug(stream, "MI_BATCH_BUFFER_END", 1); + return GL_FALSE; + case 0x22: + return debug(stream, "MI_LOAD_REGISTER_IMM", 3); + case 0x31: + return debug_chain(stream, "MI_BATCH_BUFFER_START", 2); + default: + break; + } + break; + case 0x1: + break; + case 0x2: + switch ((cmd >> 22) & 0xff) { + case 0x50: + return debug_color_blit(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2); + case 0x53: + return debug_copy_blit(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2); + default: + return debug(stream, "blit command", (cmd & 0xff) + 2); + } + break; + case 0x3: + switch ((cmd >> 24) & 0x1f) { + case 0x6: + return debug(stream, "3DSTATE_ANTI_ALIASING", 1); + case 0x7: + return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1); + case 0x8: + return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 2); + case 0x9: + return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1); + case 0xb: + return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1); + case 0xc: + return debug(stream, "3DSTATE_MODES5", 1); + case 0xd: + return debug_modes4(stream, "3DSTATE_MODES4", 1); + case 0x15: + return debug(stream, "3DSTATE_FOG_COLOR", 1); + case 0x16: + return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1); + case 0x1c: + /* 3DState16NP */ + switch((cmd >> 19) & 0x1f) { + case 0x10: + return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1); + case 0x11: + return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1); + default: + break; + } + break; + case 0x1d: + /* 3DStateMW */ + switch ((cmd >> 16) & 0xff) { + case 0x0: + return debug_map_state(stream, "3DSTATE_MAP_STATE", (cmd & 0x1f) + 2); + case 0x1: + return debug_sampler_state(stream, "3DSTATE_SAMPLER_STATE", (cmd & 0x1f) + 2); + case 0x4: + return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE", (cmd & 0xf) + 2); + case 0x5: + return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM", (cmd & 0x1ff) + 2); + case 0x6: + return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS", (cmd & 0xff) + 2); + case 0x7: + return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT", (cmd & 0xff) + 2); + case 0x80: + return debug(stream, "3DSTATE_DRAWING_RECTANGLE", (cmd & 0xffff) + 2); + case 0x81: + return debug(stream, "3DSTATE_SCISSOR_RECTANGLE", (cmd & 0xffff) + 2); + case 0x83: + return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2); + case 0x85: + return debug_dest_vars(stream, "3DSTATE_DEST_BUFFER_VARS", (cmd & 0xffff) + 2); + case 0x88: + return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR", (cmd & 0xffff) + 2); + case 0x89: + return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2); + case 0x8e: + return debug_buf_info(stream, "3DSTATE_BUFFER_INFO", (cmd & 0xffff) + 2); + case 0x97: + return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE", (cmd & 0xffff) + 2); + case 0x98: + return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2); + case 0x99: + return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2); + case 0x9a: + return debug(stream, "3DSTATE_DEFAULT_SPECULAR", (cmd & 0xffff) + 2); + case 0x9c: + return debug(stream, "3DSTATE_CLEAR_PARAMETERS", (cmd & 0xffff) + 2); + default: + assert(0); + return 0; + } + break; + case 0x1e: + if (cmd & (1 << 23)) + return debug(stream, "???", (cmd & 0xffff) + 1); + else + return debug(stream, "", 1); + break; + case 0x1f: + if ((cmd & (1 << 23)) == 0) + return debug_prim(stream, "3DPRIM (inline)", 1, (cmd & 0x1ffff) + 2); + else if (cmd & (1 << 17)) + { + if ((cmd & 0xffff) == 0) + return debug_variable_length_prim(stream); + else + return debug_prim(stream, "3DPRIM (indexed)", 0, (((cmd & 0xffff) + 1) / 2) + 1); + } + else + return debug_prim(stream, "3DPRIM (indirect sequential)", 0, 2); + break; + default: + return debug(stream, "", 0); + } + default: + assert(0); + return 0; + } + + assert(0); + return 0; +} + + void -i915_disassemble_program(const GLuint * program, GLuint sz) +i915_dump_batchbuffer( GLuint *start, + GLuint *end ) { - GLuint size = program[0] & 0x1ff; - GLint i; + struct debug_stream stream; + GLuint bytes = (end - start) * 4; + GLboolean done = GL_FALSE; - fprintf(stderr, "BEGIN\n"); + PRINTF("\n\nBATCH: (%d)\n", bytes / 4); - if (size + 2 != sz) { - fprintf(stderr, "%s: program size mismatch %d/%d\n", __FUNCTION__, - size + 2, sz); - exit(1); - } + stream.offset = 0; + stream.ptr = (char *)start; + stream.print_addresses = 0; - program++; - for (i = 1; i < sz; i += 3, program += 3) { - GLuint opcode = program[0] & (0x1f << 24); + while (!done && + stream.offset < bytes && + stream.offset >= 0) + { + if (!i915_debug_packet( &stream )) + break; - if ((GLint) opcode >= A0_NOP && opcode <= A0_SLT) - print_arith_op(opcode >> 24, program); - else if (opcode >= T0_TEXLD && opcode <= T0_TEXKILL) - print_tex_op(opcode >> 24, program); - else if (opcode == D0_DCL) - print_dcl_op(opcode >> 24, program); - else - fprintf(stderr, "Unknown opcode 0x%x\n", opcode); + assert(stream.offset <= bytes && + stream.offset >= 0); } - fprintf(stderr, "END\n\n"); + PRINTF("END-BATCH\n\n\n"); } + + diff --git a/src/mesa/drivers/dri/i915tex/i915_debug.h b/src/mesa/drivers/dri/i915tex/i915_debug.h new file mode 100644 index 0000000000..0643a8c631 --- /dev/null +++ b/src/mesa/drivers/dri/i915tex/i915_debug.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell <keith@tungstengraphics.com> + */ + +#ifndef I915_DEBUG_H +#define I915_DEBUG_H + +struct i915_context; + +struct debug_stream +{ + unsigned offset; /* current gtt offset */ + char *ptr; /* pointer to gtt offset zero */ + char *end; /* pointer to gtt offset zero */ + unsigned print_addresses; +}; + + + +extern void i915_disassemble_program(const unsigned *program, unsigned sz); +extern void i915_print_ureg(const char *msg, unsigned ureg); + + +void +i915_dump_batchbuffer( unsigned *start, + unsigned *end ); + + +#endif diff --git a/src/mesa/drivers/dri/i915tex/i915_debug_fp.c b/src/mesa/drivers/dri/i915tex/i915_debug_fp.c new file mode 100644 index 0000000000..84347a01ef --- /dev/null +++ b/src/mesa/drivers/dri/i915tex/i915_debug_fp.c @@ -0,0 +1,333 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include <stdio.h> + +#include "i915_reg.h" +#include "i915_debug.h" +#include "main/imports.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_print.h" + +#define PRINTF( ... ) _mesa_printf( __VA_ARGS__ ) + +static const char *opcodes[0x20] = { + "NOP", + "ADD", + "MOV", + "MUL", + "MAD", + "DP2ADD", + "DP3", + "DP4", + "FRC", + "RCP", + "RSQ", + "EXP", + "LOG", + "CMP", + "MIN", + "MAX", + "FLR", + "MOD", + "TRC", + "SGE", + "SLT", + "TEXLD", + "TEXLDP", + "TEXLDB", + "TEXKILL", + "DCL", + "0x1a", + "0x1b", + "0x1c", + "0x1d", + "0x1e", + "0x1f", +}; + + +static const int args[0x20] = { + 0, /* 0 nop */ + 2, /* 1 add */ + 1, /* 2 mov */ + 2, /* 3 m ul */ + 3, /* 4 mad */ + 3, /* 5 dp2add */ + 2, /* 6 dp3 */ + 2, /* 7 dp4 */ + 1, /* 8 frc */ + 1, /* 9 rcp */ + 1, /* a rsq */ + 1, /* b exp */ + 1, /* c log */ + 3, /* d cmp */ + 2, /* e min */ + 2, /* f max */ + 1, /* 10 flr */ + 1, /* 11 mod */ + 1, /* 12 trc */ + 2, /* 13 sge */ + 2, /* 14 slt */ + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; + + +static const char *regname[0x8] = { + "R", + "T", + "CONST", + "S", + "OC", + "OD", + "U", + "UNKNOWN", +}; + +static void +print_reg_type_nr(GLuint type, GLuint nr) +{ + switch (type) { + case REG_TYPE_T: + switch (nr) { + case T_DIFFUSE: + PRINTF("T_DIFFUSE"); + return; + case T_SPECULAR: + PRINTF("T_SPECULAR"); + return; + case T_FOG_W: + PRINTF("T_FOG_W"); + return; + default: + PRINTF("T_TEX%d", nr); + return; + } + case REG_TYPE_OC: + if (nr == 0) { + PRINTF("oC"); + return; + } + break; + case REG_TYPE_OD: + if (nr == 0) { + PRINTF("oD"); + return; + } + break; + default: + break; + } + + PRINTF("%s[%d]", regname[type], nr); +} + +#define REG_SWIZZLE_MASK 0x7777 +#define REG_NEGATE_MASK 0x8888 + +#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \ + (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \ + (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \ + (SRC_W << A2_SRC2_CHANNEL_W_SHIFT)) + + +static void +print_reg_neg_swizzle(GLuint reg) +{ + int i; + + if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW && + (reg & REG_NEGATE_MASK) == 0) + return; + + PRINTF("."); + + for (i = 3; i >= 0; i--) { + if (reg & (1 << ((i * 4) + 3))) + PRINTF("-"); + + switch ((reg >> (i * 4)) & 0x7) { + case 0: + PRINTF("x"); + break; + case 1: + PRINTF("y"); + break; + case 2: + PRINTF("z"); + break; + case 3: + PRINTF("w"); + break; + case 4: + PRINTF("0"); + break; + case 5: + PRINTF("1"); + break; + default: + PRINTF("?"); + break; + } + } +} + + +static void +print_src_reg(GLuint dword) +{ + GLuint nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK; + GLuint type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK; + print_reg_type_nr(type, nr); + print_reg_neg_swizzle(dword); +} + + +static void +print_dest_reg(GLuint dword) +{ + GLuint nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK; + GLuint type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK; + print_reg_type_nr(type, nr); + if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL) + return; + PRINTF("."); + if (dword & A0_DEST_CHANNEL_X) + PRINTF("x"); + if (dword & A0_DEST_CHANNEL_Y) + PRINTF("y"); + if (dword & A0_DEST_CHANNEL_Z) + PRINTF("z"); + if (dword & A0_DEST_CHANNEL_W) + PRINTF("w"); +} + + +#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT)) +#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT)) +#define GET_SRC2_REG(r) (r) + + +static void +print_arith_op(GLuint opcode, const GLuint * program) +{ + if (opcode != A0_NOP) { + print_dest_reg(program[0]); + if (program[0] & A0_DEST_SATURATE) + PRINTF(" = SATURATE "); + else + PRINTF(" = "); + } + + PRINTF("%s ", opcodes[opcode]); + + print_src_reg(GET_SRC0_REG(program[0], program[1])); + if (args[opcode] == 1) { + PRINTF("\n"); + return; + } + + PRINTF(", "); + print_src_reg(GET_SRC1_REG(program[1], program[2])); + if (args[opcode] == 2) { + PRINTF("\n"); + return; + } + + PRINTF(", "); + print_src_reg(GET_SRC2_REG(program[2])); + PRINTF("\n"); + return; +} + + +static void +print_tex_op(GLuint opcode, const GLuint * program) +{ + print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL); + PRINTF(" = "); + + PRINTF("%s ", opcodes[opcode]); + + PRINTF("S[%d],", program[0] & T0_SAMPLER_NR_MASK); + + print_reg_type_nr((program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) & + REG_TYPE_MASK, + (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK); + PRINTF("\n"); +} + +static void +print_dcl_op(GLuint opcode, const GLuint * program) +{ + PRINTF("%s ", opcodes[opcode]); + print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL); + PRINTF("\n"); +} + + +void +i915_disassemble_program(const GLuint * program, GLuint sz) +{ + GLuint size = program[0] & 0x1ff; + GLint i; + + PRINTF("\t\tBEGIN\n"); + + assert(size + 2 == sz); + + program++; + for (i = 1; i < sz; i += 3, program += 3) { + GLuint opcode = program[0] & (0x1f << 24); + + PRINTF("\t\t"); + + if ((GLint) opcode >= A0_NOP && opcode <= A0_SLT) + print_arith_op(opcode >> 24, program); + else if (opcode >= T0_TEXLD && opcode <= T0_TEXKILL) + print_tex_op(opcode >> 24, program); + else if (opcode == D0_DCL) + print_dcl_op(opcode >> 24, program); + else + PRINTF("Unknown opcode 0x%x\n", opcode); + } + + PRINTF("\t\tEND\n\n"); +} + + diff --git a/src/mesa/drivers/dri/i915tex/i915_vtbl.c b/src/mesa/drivers/dri/i915tex/i915_vtbl.c index 13ca9aee6b..16fb92ce4b 100644 --- a/src/mesa/drivers/dri/i915tex/i915_vtbl.c +++ b/src/mesa/drivers/dri/i915tex/i915_vtbl.c @@ -66,6 +66,7 @@ i915_reduced_primitive_state(struct intel_context *intel, GLenum rprim) st1 &= ~ST1_ENABLE; switch (rprim) { + case GL_QUADS: /* from RASTERIZE(GL_QUADS) in t_dd_tritemp.h */ case GL_TRIANGLES: if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple) st1 |= ST1_ENABLE; @@ -202,7 +203,7 @@ i915_emit_invarient_state(struct intel_context *intel) /* Need to initialize this to zero. */ - OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | (1)); + OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | (0)); OUT_BATCH(0); /* XXX: Use this */ @@ -220,6 +221,7 @@ i915_emit_invarient_state(struct intel_context *intel) /* Don't support twosided stencil yet */ OUT_BATCH(_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_TWO_SIDE | 0); + OUT_BATCH(0); ADVANCE_BATCH(); } @@ -251,6 +253,9 @@ get_state_size(struct i915_hw_state *state) GLuint i; GLuint sz = 0; + if (dirty & I915_UPLOAD_INVARIENT) + sz += 30 * 4; + if (dirty & I915_UPLOAD_CTX) sz += sizeof(state->Ctx); @@ -306,6 +311,7 @@ i915_emit_state(struct intel_context *intel) * causing more state to be dirty! */ dirty = get_dirty(state); + state->emitted |= dirty; if (INTEL_DEBUG & DEBUG_STATE) fprintf(stderr, "%s dirty: %x\n", __FUNCTION__, dirty); @@ -428,12 +434,22 @@ i915_emit_state(struct intel_context *intel) i915_disassemble_program(state->Program, state->ProgramSize); } - state->emitted |= dirty; + assert(get_dirty(state) == 0); } static void i915_destroy_context(struct intel_context *intel) { + GLuint i; + struct i915_context *i915 = i915_context(&intel->ctx); + + for (i = 0; i < I915_TEX_UNITS; i++) { + if (i915->state.tex_buffer[i] != NULL) { + driBOUnReference(i915->state.tex_buffer[i]); + i915->state.tex_buffer[i] = NULL; + } + } + _tnl_free_vertices(&intel->ctx); } diff --git a/src/mesa/drivers/dri/i915tex/intel_batchbuffer.c b/src/mesa/drivers/dri/i915tex/intel_batchbuffer.c index c92b83bcb3..6665629d03 100644 --- a/src/mesa/drivers/dri/i915tex/intel_batchbuffer.c +++ b/src/mesa/drivers/dri/i915tex/intel_batchbuffer.c @@ -27,6 +27,7 @@ #include "intel_batchbuffer.h" #include "intel_ioctl.h" +#include "i915_debug.h" /* Relocations in kernel space: * - pass dma buffer seperately @@ -71,9 +72,8 @@ intel_dump_batchbuffer(GLuint offset, GLuint * ptr, GLuint count) { int i; fprintf(stderr, "\n\n\nSTART BATCH (%d dwords):\n", count / 4); - for (i = 0; i < count / 4; i += 4) - fprintf(stderr, "0x%x:\t0x%08x 0x%08x 0x%08x 0x%08x\n", - offset + i * 4, ptr[i], ptr[i + 1], ptr[i + 2], ptr[i + 3]); + for (i = 0; i < count / 4; i += 1) + fprintf(stderr, "\t0x%08x\n", ptr[i]); fprintf(stderr, "END BATCH\n\n\n"); } @@ -186,8 +186,11 @@ do_flush_locked(struct intel_batchbuffer *batch, ptr[r->offset / 4] = driBOOffset(r->buf) + r->delta; } - if (INTEL_DEBUG & DEBUG_BATCH) + if (INTEL_DEBUG & DEBUG_BATCH) { + if (0) i915_dump_batchbuffer(ptr, ptr + used/4); intel_dump_batchbuffer(0, ptr, used); + } + driBOUnmap(batch->buffer); batch->map = NULL; diff --git a/src/mesa/drivers/dri/i915tex/intel_buffers.c b/src/mesa/drivers/dri/i915tex/intel_buffers.c index 4b2a4acaf9..13f26137aa 100644 --- a/src/mesa/drivers/dri/i915tex/intel_buffers.c +++ b/src/mesa/drivers/dri/i915tex/intel_buffers.c @@ -250,7 +250,8 @@ intelWindowMoved(struct intel_context *intel) flags = intel_fb->vblank_flags & ~VBLANK_FLAG_SECONDARY; } - if (flags != intel_fb->vblank_flags) { + if (flags != intel_fb->vblank_flags && intel_fb->vblank_flags && + !(intel_fb->vblank_flags & VBLANK_FLAG_NO_IRQ)) { drmVBlank vbl; int i; @@ -261,7 +262,9 @@ intelWindowMoved(struct intel_context *intel) } for (i = 0; i < intel_fb->pf_num_pages; i++) { - if (!intel_fb->color_rb[i]) + if (!intel_fb->color_rb[i] || + (intel_fb->vbl_waited - intel_fb->color_rb[i]->vbl_pending) <= + (1<<23)) continue; vbl.request.sequence = intel_fb->color_rb[i]->vbl_pending; diff --git a/src/mesa/drivers/dri/i915tex/intel_context.c b/src/mesa/drivers/dri/i915tex/intel_context.c index f032c97dfb..8a5b4d1f83 100644 --- a/src/mesa/drivers/dri/i915tex/intel_context.c +++ b/src/mesa/drivers/dri/i915tex/intel_context.c @@ -605,12 +605,23 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv, if (intel->ctx.DrawBuffer == &intel_fb->Base) { if (intel->driDrawable != driDrawPriv) { - intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0) - ? driGetDefaultVBlankFlags(&intel->optionCache) - : VBLANK_FLAG_NO_IRQ; - (*dri_interface->getUST) (&intel_fb->swap_ust); - driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags, - &intel_fb->vbl_seq); + if (driDrawPriv->pdraw->swap_interval == (unsigned)-1) { + int i; + + intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0) + ? driGetDefaultVBlankFlags(&intel->optionCache) + : VBLANK_FLAG_NO_IRQ; + + (*dri_interface->getUST) (&intel_fb->swap_ust); + driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags, + &intel_fb->vbl_seq); + intel_fb->vbl_waited = intel_fb->vbl_seq; + + for (i = 0; i < (2); i++) { + if (intel_fb->color_rb[i]) + intel_fb->color_rb[i]->vbl_pending = intel_fb->vbl_seq; + } + } } } @@ -660,37 +671,27 @@ intelContendedLock(struct intel_context *intel, GLuint flags) if (sarea->width != intel->width || sarea->height != intel->height || sarea->rotation != intel->current_rotation) { - - void *batchMap = intel->batch->map; - + int numClipRects = intel->numClipRects; + /* * FIXME: Really only need to do this when drawing to a * common back- or front buffer. */ /* - * This will drop the outstanding batchbuffer on the floor + * This will essentially drop the outstanding batchbuffer on the floor. */ + intel->numClipRects = 0; - if (batchMap != NULL) { - driBOUnmap(intel->batch->buffer); - intel->batch->map = NULL; - } - - intel_batchbuffer_reset(intel->batch); + if (intel->Fallback) + _swrast_flush(&intel->ctx); - if (batchMap == NULL) { - driBOUnmap(intel->batch->buffer); - intel->batch->map = NULL; - } + INTEL_FIREVERTICES(intel); - /* lose all primitives */ - intel->prim.primitive = ~0; - intel->prim.start_ptr = 0; - intel->prim.flush = 0; + if (intel->batch->map != intel->batch->ptr) + intel_batchbuffer_flush(intel->batch); - /* re-emit all state */ - intel->vtbl.lost_hardware(intel); + intel->numClipRects = numClipRects; /* force window update */ intel->lastStamp = 0; @@ -724,7 +725,9 @@ void LOCK_HARDWARE( struct intel_context *intel ) BUFFER_BACK_LEFT); } - if (intel_rb && (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) { + if (intel_rb && intel_fb->vblank_flags && + !(intel_fb->vblank_flags & VBLANK_FLAG_NO_IRQ) && + (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) { drmVBlank vbl; vbl.request.type = DRM_VBLANK_ABSOLUTE; diff --git a/src/mesa/drivers/dri/i915tex/intel_mipmap_tree.c b/src/mesa/drivers/dri/i915tex/intel_mipmap_tree.c index 843a78eb82..74f6b2d851 100644 --- a/src/mesa/drivers/dri/i915tex/intel_mipmap_tree.c +++ b/src/mesa/drivers/dri/i915tex/intel_mipmap_tree.c @@ -97,9 +97,19 @@ intel_miptree_create(struct intel_context *intel, break; } - if (ok) + if (ok) { + if (!mt->compressed) { + /* XXX: Align pitch to multiple of 64 bytes for now to allow + * render-to-texture to work in all cases. This should probably be + * replaced at some point by some scheme to only do this when really + * necessary. + */ + mt->pitch = ((mt->pitch * cpp + 63) & ~63) / cpp; + } + mt->region = intel_region_alloc(intel->intelScreen, mt->cpp, mt->pitch, mt->total_height); + } if (!mt->region) { free(mt); @@ -325,6 +335,7 @@ intel_miptree_image_data(struct intel_context *intel, } } +extern GLuint intel_compressed_alignment(GLenum); /* Copy mipmap image between trees */ void @@ -342,8 +353,12 @@ intel_miptree_image_copy(struct intel_context *intel, const GLuint *src_depth_offset = intel_miptree_depth_offsets(src, level); GLuint i; - if (dst->compressed) - height /= 4; + if (dst->compressed) { + GLuint alignment = intel_compressed_alignment(dst->internal_format); + height = (height + 3) / 4; + width = ((width + alignment - 1) & ~(alignment - 1)); + } + for (i = 0; i < depth; i++) { intel_region_copy(intel->intelScreen, dst->region, dst_offset + dst_depth_offset[i], diff --git a/src/mesa/drivers/dri/i915tex/intel_span.c b/src/mesa/drivers/dri/i915tex/intel_span.c index 5a978d9ce2..cc0dec1843 100644 --- a/src/mesa/drivers/dri/i915tex/intel_span.c +++ b/src/mesa/drivers/dri/i915tex/intel_span.c @@ -190,9 +190,9 @@ intel_map_unmap_buffers(struct intel_context *intel, GLboolean map) intel_region_map(intel->intelScreen, irb->region); else intel_region_unmap(intel->intelScreen, irb->region); + irb->pfMap = irb->region->map; + irb->pfPitch = irb->region->pitch; } - irb->pfMap = irb->region->map; - irb->pfPitch = irb->region->pitch; } } } diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h index e8f878a701..9bb7d2f703 100644 --- a/src/mesa/drivers/dri/i965/brw_defines.h +++ b/src/mesa/drivers/dri/i965/brw_defines.h @@ -240,6 +240,8 @@ #define BRW_FRONTWINDING_CW 0 #define BRW_FRONTWINDING_CCW 1 +#define BRW_SPRITE_POINT_ENABLE 16 + #define BRW_INDEX_BYTE 0 #define BRW_INDEX_WORD 1 #define BRW_INDEX_DWORD 2 diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c index d5175399d6..73232b3c7c 100644 --- a/src/mesa/drivers/dri/i965/brw_sf.c +++ b/src/mesa/drivers/dri/i965/brw_sf.c @@ -74,6 +74,11 @@ static void compile_sf_prog( struct brw_context *brw, if (c.key.attrs & (1<<i)) { c.attr_to_idx[i] = idx; c.idx_to_attr[idx] = i; + if (i >= VERT_RESULT_TEX0 && i <= VERT_RESULT_TEX7) { + c.point_attrs[i].CoordReplace = + brw->attribs.Point->CoordReplace[i - VERT_RESULT_TEX0]; + } else + c.point_attrs[i].CoordReplace = GL_FALSE; idx++; } @@ -90,7 +95,10 @@ static void compile_sf_prog( struct brw_context *brw, break; case SF_POINTS: c.nr_verts = 1; - brw_emit_point_setup( &c ); + if (key->do_point_sprite) + brw_emit_point_sprite_setup( &c ); + else + brw_emit_point_setup( &c ); break; case SF_UNFILLED_TRIS: c.nr_verts = 3; @@ -162,7 +170,8 @@ static void upload_sf_prog( struct brw_context *brw ) break; } - + key.do_point_sprite = brw->attribs.Point->PointSprite; + key.SpriteOrigin = brw->attribs.Point->SpriteOrigin; /* _NEW_LIGHT */ key.do_flat_shading = (brw->attribs.Light->ShadeModel == GL_FLAT); key.do_twoside_color = (brw->attribs.Light->Enabled && brw->attribs.Light->Model.TwoSide); @@ -179,7 +188,7 @@ static void upload_sf_prog( struct brw_context *brw ) const struct brw_tracked_state brw_sf_prog = { .dirty = { - .mesa = (_NEW_LIGHT|_NEW_POLYGON), + .mesa = (_NEW_LIGHT|_NEW_POLYGON|_NEW_POINT), .brw = (BRW_NEW_REDUCED_PRIMITIVE), .cache = CACHE_NEW_VS_PROG }, diff --git a/src/mesa/drivers/dri/i965/brw_sf.h b/src/mesa/drivers/dri/i965/brw_sf.h index fb72b84ba8..e374e372bb 100644 --- a/src/mesa/drivers/dri/i965/brw_sf.h +++ b/src/mesa/drivers/dri/i965/brw_sf.h @@ -50,9 +50,14 @@ struct brw_sf_prog_key { GLuint do_flat_shading:1; GLuint attrs:16; GLuint frontface_ccw:1; - GLuint pad:11; + GLuint do_point_sprite:1; + GLuint pad:10; + GLenum SpriteOrigin; }; +struct brw_sf_point_tex { + GLboolean CoordReplace; +}; struct brw_sf_compile { struct brw_compile func; @@ -94,12 +99,14 @@ struct brw_sf_compile { GLubyte attr_to_idx[VERT_RESULT_MAX]; GLubyte idx_to_attr[VERT_RESULT_MAX]; + struct brw_sf_point_tex point_attrs[VERT_RESULT_MAX]; }; void brw_emit_tri_setup( struct brw_sf_compile *c ); void brw_emit_line_setup( struct brw_sf_compile *c ); void brw_emit_point_setup( struct brw_sf_compile *c ); +void brw_emit_point_sprite_setup( struct brw_sf_compile *c ); void brw_emit_anyprim_setup( struct brw_sf_compile *c ); #endif diff --git a/src/mesa/drivers/dri/i965/brw_sf_emit.c b/src/mesa/drivers/dri/i965/brw_sf_emit.c index cbaf018c44..22911a4649 100644 --- a/src/mesa/drivers/dri/i965/brw_sf_emit.c +++ b/src/mesa/drivers/dri/i965/brw_sf_emit.c @@ -497,6 +497,86 @@ void brw_emit_line_setup( struct brw_sf_compile *c ) } } +void brw_emit_point_sprite_setup( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + GLuint i; + + c->nr_verts = 1; + alloc_regs(c); + copy_z_inv_w(c); + for (i = 0; i < c->nr_setup_regs; i++) + { + struct brw_sf_point_tex *tex = &c->point_attrs[c->idx_to_attr[2*i]]; + struct brw_reg a0 = offset(c->vert[0], i); + GLushort pc, pc_persp, pc_linear; + GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear); + + if (pc_persp) + { + if (!tex->CoordReplace) { + brw_set_predicate_control_flag_value(p, pc_persp); + brw_MUL(p, a0, a0, c->inv_w[0]); + } + } + + if (tex->CoordReplace) { + /* Caculate 1.0/PointWidth */ + brw_math(&c->func, + c->tmp, + BRW_MATH_FUNCTION_INV, + BRW_MATH_SATURATE_NONE, + 0, + c->dx0, + BRW_MATH_DATA_SCALAR, + BRW_MATH_PRECISION_FULL); + + if (c->key.SpriteOrigin == GL_UPPER_LEFT) { + brw_MUL(p, c->m1Cx, c->tmp, c->inv_w[0]); + brw_MOV(p, vec1(suboffset(c->m1Cx, 1)), brw_imm_f(0.0)); + brw_MUL(p, c->m2Cy, c->tmp, negate(c->inv_w[0])); + brw_MOV(p, vec1(suboffset(c->m2Cy, 0)), brw_imm_f(0.0)); + } else { + brw_MUL(p, c->m1Cx, c->tmp, c->inv_w[0]); + brw_MOV(p, vec1(suboffset(c->m1Cx, 1)), brw_imm_f(0.0)); + brw_MUL(p, c->m2Cy, c->tmp, c->inv_w[0]); + brw_MOV(p, vec1(suboffset(c->m2Cy, 0)), brw_imm_f(0.0)); + } + } else { + brw_MOV(p, c->m1Cx, brw_imm_ud(0)); + brw_MOV(p, c->m2Cy, brw_imm_ud(0)); + } + + { + brw_set_predicate_control_flag_value(p, pc); + if (tex->CoordReplace) { + if (c->key.SpriteOrigin == GL_UPPER_LEFT) { + brw_MUL(p, c->m3C0, c->inv_w[0], brw_imm_f(1.0)); + brw_MOV(p, vec1(suboffset(c->m3C0, 0)), brw_imm_f(0.0)); + } + else + brw_MOV(p, c->m3C0, brw_imm_f(0.0)); + } else { + brw_MOV(p, c->m3C0, a0); /* constant value */ + } + + /* Copy m0..m3 to URB. + */ + brw_urb_WRITE(p, + brw_null_reg(), + 0, + brw_vec8_grf(0, 0), + 0, /* allocate */ + 1, /* used */ + 4, /* msg len */ + 0, /* response len */ + last, /* eot */ + last, /* writes complete */ + i*4, /* urb destination offset */ + BRW_URB_SWIZZLE_TRANSPOSE); + } + } +} /* Points setup - several simplifications as all attributes are * constant across the face of the point (point sprites excluded!) @@ -561,6 +641,7 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c ) struct brw_compile *p = &c->func; struct brw_reg ip = brw_ip_reg(); struct brw_reg payload_prim = brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0); + struct brw_reg payload_attr = get_element_ud(brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0), 0); struct brw_reg primmask; struct brw_instruction *jmp; struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD)); @@ -601,6 +682,14 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c ) } brw_land_fwd_jump(p, jmp); + brw_set_conditionalmod(p, BRW_CONDITIONAL_Z); + brw_AND(p, v1_null_ud, payload_attr, brw_imm_ud(1<<BRW_SPRITE_POINT_ENABLE)); + jmp = brw_JMPI(p, ip, ip, brw_imm_w(0)); + { + brw_emit_point_sprite_setup( c ); + } + brw_land_fwd_jump(p, jmp); + brw_emit_point_setup( c ); } diff --git a/src/mesa/drivers/dri/i965/brw_sf_state.c b/src/mesa/drivers/dri/i965/brw_sf_state.c index bfac52d765..236c6fd42a 100644 --- a/src/mesa/drivers/dri/i965/brw_sf_state.c +++ b/src/mesa/drivers/dri/i965/brw_sf_state.c @@ -173,7 +173,8 @@ static void upload_sf_unit( struct brw_context *brw ) /* _NEW_LINE */ - sf.sf6.line_width = brw->attribs.Line->_Width * (1<<1); + /* XXX use ctx->Const.Min/MaxLineWidth here */ + sf.sf6.line_width = CLAMP(brw->attribs.Line->Width, 1.0, 5.0) * (1<<1); sf.sf6.line_endcap_aa_region_width = 1; if (brw->attribs.Line->SmoothFlag) @@ -183,7 +184,10 @@ static void upload_sf_unit( struct brw_context *brw ) /* _NEW_POINT */ sf.sf6.point_rast_rule = 1; /* opengl conventions */ - sf.sf7.point_size = brw->attribs.Point->_Size * (1<<3); + /* XXX clamp max depends on AA vs. non-AA */ + + sf.sf7.sprite_point = brw->attribs.Point->PointSprite; + sf.sf7.point_size = CLAMP(brw->attribs.Point->Size, 1.0, 255.0) * (1<<3); sf.sf7.use_point_size_state = !brw->attribs.Point->_Attenuated; /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons: diff --git a/src/mesa/drivers/dri/i965/brw_tex.c b/src/mesa/drivers/dri/i965/brw_tex.c index 9d4b9867d2..ad29316a42 100644 --- a/src/mesa/drivers/dri/i965/brw_tex.c +++ b/src/mesa/drivers/dri/i965/brw_tex.c @@ -154,13 +154,19 @@ brwChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGB_S3TC: case GL_RGB4_S3TC: + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + return &_mesa_texformat_rgb_dxt1; + + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + return &_mesa_texformat_rgba_dxt1; + case GL_RGBA_S3TC: case GL_RGBA4_S3TC: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + return &_mesa_texformat_rgba_dxt3; + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - return &_mesa_texformat_rgb_dxt1; /* there is no rgba support? */ + return &_mesa_texformat_rgba_dxt5; case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT16: @@ -168,6 +174,25 @@ brwChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_DEPTH_COMPONENT32: return &_mesa_texformat_z16; + case GL_SRGB_EXT: + case GL_SRGB8_EXT: + case GL_SRGB_ALPHA_EXT: + case GL_SRGB8_ALPHA8_EXT: + case GL_SLUMINANCE_EXT: + case GL_SLUMINANCE8_EXT: + case GL_SLUMINANCE_ALPHA_EXT: + case GL_SLUMINANCE8_ALPHA8_EXT: + case GL_COMPRESSED_SRGB_EXT: + case GL_COMPRESSED_SRGB_ALPHA_EXT: + case GL_COMPRESSED_SLUMINANCE_EXT: + case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: + return &_mesa_texformat_srgba8; + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + return &_mesa_texformat_srgb_dxt1; + default: fprintf(stderr, "unexpected texture format %s in %s\n", _mesa_lookup_enum_by_nr(internalFormat), diff --git a/src/mesa/drivers/dri/i965/brw_tex_layout.c b/src/mesa/drivers/dri/i965/brw_tex_layout.c index af1ad0f1ef..2094a1c8ad 100644 --- a/src/mesa/drivers/dri/i965/brw_tex_layout.c +++ b/src/mesa/drivers/dri/i965/brw_tex_layout.c @@ -37,6 +37,7 @@ #include "intel_tex_layout.h" #include "macros.h" +#define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) GLboolean brw_miptree_layout( struct intel_mipmap_tree *mt ) { @@ -53,11 +54,20 @@ GLboolean brw_miptree_layout( struct intel_mipmap_tree *mt ) GLuint pack_x_pitch, pack_x_nr; GLuint pack_y_pitch; GLuint level; + GLuint align_h = 2; + GLuint align_w = 4; - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; mt->total_height = 0; + + if (mt->compressed) { + align_w = intel_compressed_alignment(mt->internal_format); + mt->pitch = ALIGN(width, align_w); + pack_y_pitch = (height + 3) / 4; + } else { + mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; + pack_y_pitch = ALIGN(mt->height0, align_h); + } - pack_y_pitch = MAX2(mt->height0, 2); pack_x_pitch = mt->pitch; pack_x_nr = 1; @@ -83,20 +93,30 @@ GLboolean brw_miptree_layout( struct intel_mipmap_tree *mt ) mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->pitch); - } - - if (pack_y_pitch > 2) { - pack_y_pitch >>= 1; - } - width = minify(width); height = minify(height); depth = minify(depth); + + if (mt->compressed) { + pack_y_pitch = (height + 3) / 4; + + if (pack_x_pitch > ALIGN(width, align_w)) { + pack_x_pitch = ALIGN(width, align_w); + pack_x_nr <<= 1; + } + } else { + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= mt->pitch); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + pack_y_pitch = ALIGN(pack_y_pitch, align_h); + } + } + } break; } diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index 6eb11b19ad..d00f0c71a8 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -201,7 +201,7 @@ static void unalias2( struct brw_vs_compile *c, struct brw_reg, struct brw_reg )) { - if ((dst.file == arg0.file && dst.nr == arg0.nr) && + if ((dst.file == arg0.file && dst.nr == arg0.nr) || (dst.file == arg1.file && dst.nr == arg1.nr)) { struct brw_compile *p = &c->func; struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask); diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index 1497dc7968..904c00bef8 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -285,7 +285,7 @@ static void brw_wm_populate_key( struct brw_context *brw, /* BRW_NEW_WM_INPUT_DIMENSIONS */ - key->projtex_mask = brw->wm.input_size_masks[4-1]; + key->projtex_mask = brw->wm.input_size_masks[4-1] >> (FRAG_ATTRIB_TEX0 - FRAG_ATTRIB_WPOS); /* _NEW_LIGHT */ key->flat_shade = (brw->attribs.Light->ShadeModel == GL_FLAT); diff --git a/src/mesa/drivers/dri/i965/brw_wm_fp.c b/src/mesa/drivers/dri/i965/brw_wm_fp.c index ff97d87dc4..62bb081206 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_fp.c +++ b/src/mesa/drivers/dri/i965/brw_wm_fp.c @@ -660,7 +660,7 @@ static GLboolean projtex( struct brw_wm_compile *c, return 0; /* ut2004 gun rendering !?! */ else if (src.File == PROGRAM_INPUT && GET_SWZ(src.Swizzle, W) == W && - (c->key.projtex_mask & (1<<src.Index)) == 0) + (c->key.projtex_mask & (1<<(src.Index + FRAG_ATTRIB_WPOS - FRAG_ATTRIB_TEX0))) == 0) return 0; else return 1; diff --git a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c index 93d4cfc3a5..83a4b02e48 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c @@ -54,7 +54,7 @@ static GLuint translate_wrap_mode( GLenum wrap ) case GL_REPEAT: return BRW_TEXCOORDMODE_WRAP; case GL_CLAMP: - return BRW_TEXCOORDMODE_CLAMP_BORDER; /* conform likes it this way */ + return BRW_TEXCOORDMODE_CLAMP; case GL_CLAMP_TO_EDGE: return BRW_TEXCOORDMODE_CLAMP; /* conform likes it this way */ case GL_CLAMP_TO_BORDER: diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index d24c618a66..0a45164a0f 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -114,11 +114,24 @@ static GLuint translate_tex_format( GLuint mesa_format ) return BRW_SURFACEFORMAT_FXT1; case MESA_FORMAT_Z16: - return BRW_SURFACEFORMAT_L16_UNORM; + return BRW_SURFACEFORMAT_I16_UNORM; - case MESA_FORMAT_RGBA_DXT1: case MESA_FORMAT_RGB_DXT1: - return BRW_SURFACEFORMAT_DXT1_RGB; + return BRW_SURFACEFORMAT_DXT1_RGB; + + case MESA_FORMAT_RGBA_DXT1: + return BRW_SURFACEFORMAT_BC1_UNORM; + + case MESA_FORMAT_RGBA_DXT3: + return BRW_SURFACEFORMAT_BC2_UNORM; + + case MESA_FORMAT_RGBA_DXT5: + return BRW_SURFACEFORMAT_BC3_UNORM; + + case MESA_FORMAT_SRGBA8: + return BRW_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB; + case MESA_FORMAT_SRGB_DXT1: + return BRW_SURFACEFORMAT_BC1_UNORM_SRGB; default: assert(0); diff --git a/src/mesa/drivers/dri/i965/intel_blit.c b/src/mesa/drivers/dri/i965/intel_blit.c index 173d1d5b6c..f88cbb2328 100644 --- a/src/mesa/drivers/dri/i965/intel_blit.c +++ b/src/mesa/drivers/dri/i965/intel_blit.c @@ -532,12 +532,15 @@ intelEmitImmediateColorExpandBlit(struct intel_context *intel, GLuint dst_offset, GLboolean dst_tiled, GLshort x, GLshort y, - GLshort w, GLshort h) + GLshort w, GLshort h, + GLenum logic_op) { struct xy_setup_blit setup; struct xy_text_immediate_blit text; int dwords = ((src_size + 7) & ~7) / 4; + assert( logic_op - GL_CLEAR >= 0 ); + assert( logic_op - GL_CLEAR < 0x10 ); if (w < 0 || h < 0) return; @@ -561,7 +564,7 @@ intelEmitImmediateColorExpandBlit(struct intel_context *intel, setup.br0.length = (sizeof(setup) / sizeof(int)) - 2; setup.br13.dest_pitch = dst_pitch; - setup.br13.rop = 0xcc; + setup.br13.rop = translate_raster_op(logic_op); setup.br13.color_depth = (cpp == 4) ? BR13_8888 : BR13_565; setup.br13.clipping_enable = 0; setup.br13.mono_source_transparency = 1; diff --git a/src/mesa/drivers/dri/i965/intel_blit.h b/src/mesa/drivers/dri/i965/intel_blit.h index 8b0cc65243..e361545c8f 100644 --- a/src/mesa/drivers/dri/i965/intel_blit.h +++ b/src/mesa/drivers/dri/i965/intel_blit.h @@ -72,6 +72,7 @@ intelEmitImmediateColorExpandBlit(struct intel_context *intel, GLuint dst_offset, GLboolean dst_tiled, GLshort dst_x, GLshort dst_y, - GLshort w, GLshort h); + GLshort w, GLshort h, + GLenum logic_op ); #endif diff --git a/src/mesa/drivers/dri/i965/intel_context.c b/src/mesa/drivers/dri/i965/intel_context.c index 4f51fefe0f..eafe809d3a 100644 --- a/src/mesa/drivers/dri/i965/intel_context.c +++ b/src/mesa/drivers/dri/i965/intel_context.c @@ -66,6 +66,7 @@ int INTEL_DEBUG = (0); #endif +#define need_GL_NV_point_sprite #define need_GL_ARB_multisample #define need_GL_ARB_point_parameters #define need_GL_ARB_texture_compression @@ -81,6 +82,7 @@ int INTEL_DEBUG = (0); #define need_GL_EXT_fog_coord #define need_GL_EXT_multi_draw_arrays #define need_GL_EXT_secondary_color +#define need_GL_EXT_point_parameters #include "extension_helper.h" #ifndef VERBOSE @@ -146,6 +148,7 @@ const struct dri_extension card_extensions[] = { "GL_ARB_multisample", GL_ARB_multisample_functions }, { "GL_ARB_multitexture", NULL }, { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions }, + { "GL_NV_point_sprite", GL_NV_point_sprite_functions }, { "GL_ARB_texture_border_clamp", NULL }, { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions }, { "GL_ARB_texture_cube_map", NULL }, @@ -158,6 +161,8 @@ const struct dri_extension card_extensions[] = { "GL_NV_texture_rectangle", NULL }, { "GL_EXT_texture_rectangle", NULL }, { "GL_ARB_texture_rectangle", NULL }, + { "GL_ARB_point_sprite", NULL}, + { "GL_ARB_point_parameters", NULL }, { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions }, { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, { "GL_ARB_window_pos", GL_ARB_window_pos_functions }, @@ -177,6 +182,7 @@ const struct dri_extension card_extensions[] = { "GL_EXT_texture_env_dot3", NULL }, { "GL_EXT_texture_filter_anisotropic", NULL }, { "GL_EXT_texture_lod_bias", NULL }, + { "GL_EXT_texture_sRGB", NULL }, { "GL_3DFX_texture_compression_FXT1", NULL }, { "GL_APPLE_client_storage", NULL }, { "GL_MESA_pack_invert", NULL }, diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c index 8486086b27..0fb33e27f4 100644 --- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c +++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c @@ -75,7 +75,7 @@ struct intel_mipmap_tree *intel_miptree_create( struct intel_context *intel, mt->width0 = width0; mt->height0 = height0; mt->depth0 = depth0; - mt->cpp = compressed ? 2 : cpp; + mt->cpp = cpp; mt->compressed = compressed; switch (intel->intelScreen->deviceID) { @@ -211,7 +211,7 @@ GLuint intel_miptree_image_offset(struct intel_mipmap_tree *mt, - +extern GLuint intel_compressed_alignment(GLenum); /* Upload data for a particular image. */ GLboolean intel_miptree_image_data(struct intel_context *intel, @@ -226,6 +226,17 @@ GLboolean intel_miptree_image_data(struct intel_context *intel, GLuint dst_offset = intel_miptree_image_offset(dst, face, level); const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level); GLuint i; + GLuint width, height, alignment; + + width = dst->level[level].width; + height = dst->level[level].height; + + if (dst->compressed) { + alignment = intel_compressed_alignment(dst->internal_format); + src_row_pitch = ((src_row_pitch + alignment - 1) & ~(alignment - 1)); + width = ((width + alignment - 1) & ~(alignment - 1)); + height = (height + 3) / 4; + } DBG("%s\n", __FUNCTION__); for (i = 0; i < depth; i++) { @@ -237,8 +248,8 @@ GLboolean intel_miptree_image_data(struct intel_context *intel, src, src_row_pitch, 0, 0, /* source x,y */ - dst->level[level].width, - dst->level[level].height)) + width, + height)) return GL_FALSE; src += src_image_pitch; } diff --git a/src/mesa/drivers/dri/i965/intel_pixel_bitmap.c b/src/mesa/drivers/dri/i965/intel_pixel_bitmap.c index 5841afaa3e..f3f062e651 100644 --- a/src/mesa/drivers/dri/i965/intel_pixel_bitmap.c +++ b/src/mesa/drivers/dri/i965/intel_pixel_bitmap.c @@ -226,10 +226,10 @@ do_blit_bitmap( GLcontext *ctx, dsty = dPriv->y + (dPriv->h - dsty - height); dstx = dPriv->x + dstx; - dest_rect.x1 = dstx; - dest_rect.y1 = dsty; - dest_rect.x2 = dstx + width; - dest_rect.y2 = dsty + height; + dest_rect.x1 = dstx < 0 ? 0 : dstx; + dest_rect.y1 = dsty < 0 ? 0 : dsty; + dest_rect.x2 = dstx + width < 0 ? 0 : dstx + width; + dest_rect.y2 = dsty + height < 0 ? 0 : dsty + height; for (i = 0; i < nbox; i++) { drm_clip_rect_t rect; @@ -260,7 +260,9 @@ do_blit_bitmap( GLcontext *ctx, int h = MIN2(DY, box_h - py); int w = MIN2(DX, box_w - px); GLuint sz = align(align(w,8) * h, 64)/8; - + GLenum logic_op = ctx->Color.ColorLogicOpEnabled ? + ctx->Color.LogicOp : GL_COPY; + assert(sz <= sizeof(stipple)); memset(stipple, 0, sz); @@ -288,7 +290,8 @@ do_blit_bitmap( GLcontext *ctx, dst->tiled, rect.x1 + px, rect.y2 - (py + h), - w, h); + w, h, + logic_op); } } } diff --git a/src/mesa/drivers/dri/i965/intel_tex_validate.c b/src/mesa/drivers/dri/i965/intel_tex_validate.c index 44ee94614d..8c05e7cdab 100644 --- a/src/mesa/drivers/dri/i965/intel_tex_validate.c +++ b/src/mesa/drivers/dri/i965/intel_tex_validate.c @@ -122,6 +122,29 @@ static void intel_texture_invalidate_cb( struct intel_context *intel, intel_texture_invalidate( (struct intel_texture_object *) ptr ); } +#include "texformat.h" +static GLuint intel_compressed_num_bytes(GLenum mesaFormat) +{ + GLuint bytes = 0; + + switch (mesaFormat) { + case MESA_FORMAT_RGB_FXT1: + case MESA_FORMAT_RGBA_FXT1: + case MESA_FORMAT_RGB_DXT1: + case MESA_FORMAT_RGBA_DXT1: + bytes = 2; + break; + + case MESA_FORMAT_RGBA_DXT3: + case MESA_FORMAT_RGBA_DXT5: + bytes = 4; + + default: + break; + } + + return bytes; +} /* */ @@ -132,7 +155,8 @@ GLuint intel_finalize_mipmap_tree( struct intel_context *intel, GLuint face, i; GLuint nr_faces = 0; struct gl_texture_image *firstImage; - + GLuint cpp = 0; + if( tObj == intel->frame_buffer_texobj ) return GL_FALSE; @@ -165,6 +189,12 @@ GLuint intel_finalize_mipmap_tree( struct intel_context *intel, + if (firstImage->IsCompressed) { + cpp = intel_compressed_num_bytes(firstImage->TexFormat->MesaFormat); + } else { + cpp = firstImage->TexFormat->TexelBytes; + } + /* Check tree can hold all active levels. Check tree matches * target, imageFormat, etc. */ @@ -176,7 +206,7 @@ GLuint intel_finalize_mipmap_tree( struct intel_context *intel, intelObj->mt->width0 != firstImage->Width || intelObj->mt->height0 != firstImage->Height || intelObj->mt->depth0 != firstImage->Depth || - intelObj->mt->cpp != firstImage->TexFormat->TexelBytes || + intelObj->mt->cpp != cpp || intelObj->mt->compressed != firstImage->IsCompressed)) { intel_miptree_destroy(intel, intelObj->mt); @@ -199,7 +229,7 @@ GLuint intel_finalize_mipmap_tree( struct intel_context *intel, firstImage->Width, firstImage->Height, firstImage->Depth, - firstImage->TexFormat->TexelBytes, + cpp, firstImage->IsCompressed); /* Tell the buffer manager that we will manage the backing diff --git a/src/mesa/drivers/dri/intel/intel_tex_layout.c b/src/mesa/drivers/dri/intel/intel_tex_layout.c index fcb5cc3906..fdecd3e186 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_layout.c +++ b/src/mesa/drivers/dri/intel/intel_tex_layout.c @@ -40,6 +40,23 @@ static int align(int value, int alignment) return (value + alignment - 1) & ~(alignment - 1); } +GLuint intel_compressed_alignment(GLenum internalFormat) +{ + GLuint alignment = 4; + + switch (internalFormat) { + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: + alignment = 8; + break; + + default: + break; + } + + return alignment; +} + void i945_miptree_layout_2d( struct intel_mipmap_tree *mt ) { GLint align_h = 2, align_w = 4; @@ -51,17 +68,30 @@ void i945_miptree_layout_2d( struct intel_mipmap_tree *mt ) mt->pitch = mt->width0; + if (mt->compressed) { + align_w = intel_compressed_alignment(mt->internal_format); + mt->pitch = align(mt->width0, align_w); + } + /* May need to adjust pitch to accomodate the placement of * the 2nd mipmap. This occurs when the alignment * constraints of mipmap placement push the right edge of the * 2nd mipmap out past the width of its parent. */ if (mt->first_level != mt->last_level) { - GLuint mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); + GLuint mip1_width; + + if (mt->compressed) { + mip1_width = align(minify(mt->width0), align_w) + + align(minify(minify(mt->width0)), align_w); + } else { + mip1_width = align(minify(mt->width0), align_w) + + minify(minify(mt->width0)); + } - if (mip1_width > mt->width0) - mt->pitch = mip1_width; + if (mip1_width > mt->pitch) { + mt->pitch = mip1_width; + } } /* Pitch must be a whole number of dwords, even though we diff --git a/src/mesa/drivers/dri/intel/intel_tex_layout.h b/src/mesa/drivers/dri/intel/intel_tex_layout.h index 1e37f8f525..99d41c3629 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_layout.h +++ b/src/mesa/drivers/dri/intel/intel_tex_layout.h @@ -39,3 +39,4 @@ static GLuint minify( GLuint d ) } extern void i945_miptree_layout_2d( struct intel_mipmap_tree *mt ); +extern GLuint intel_compressed_alignment(GLenum); diff --git a/src/mesa/drivers/dri/mach64/mach64_native_vb.c b/src/mesa/drivers/dri/mach64/mach64_native_vb.c index 75cf0e2ed2..248fa2a9a2 100644 --- a/src/mesa/drivers/dri/mach64/mach64_native_vb.c +++ b/src/mesa/drivers/dri/mach64/mach64_native_vb.c @@ -103,7 +103,7 @@ void TAG(translate_vertex)(GLcontext *ctx, assert( p + 1 - (CARD32 *)src == 10 ); - dst->pointSize = ctx->Point._Size; + dst->pointSize = ctx->Point.Size; } diff --git a/src/mesa/drivers/dri/mach64/mach64_tris.c b/src/mesa/drivers/dri/mach64/mach64_tris.c index 08cc1849a1..369f610442 100644 --- a/src/mesa/drivers/dri/mach64/mach64_tris.c +++ b/src/mesa/drivers/dri/mach64/mach64_tris.c @@ -673,7 +673,10 @@ static __inline void mach64_draw_line( mach64ContextPtr mmesa, #if MACH64_NATIVE_VTXFMT GLcontext *ctx = mmesa->glCtx; const GLuint vertsize = mmesa->vertex_size; - GLint width = (GLint)(mmesa->glCtx->Line._Width * 2.0); /* 2 fractional bits for hardware */ + /* 2 fractional bits for hardware: */ + const int width = (int) (2.0 * CLAMP(mmesa->glCtx->Line.Width, + mmesa->glCtx->Const.MinLineWidth, + mmesa->glCtx->Const.MaxLineWidth)); GLfloat ooa; GLuint *pxy0, *pxy1; GLuint xy0old, xy0, xy1old, xy1; @@ -691,9 +694,6 @@ static __inline void mach64_draw_line( mach64ContextPtr mmesa, mach64_print_vertex( ctx, v1 ); } - if( !width ) - width = 1; /* round to the nearest supported width */ - pxy0 = &v0->ui[xyoffset]; xy0old = *pxy0; xy0 = LE32_IN( &xy0old ); @@ -961,7 +961,10 @@ static __inline void mach64_draw_point( mach64ContextPtr mmesa, #if MACH64_NATIVE_VTXFMT GLcontext *ctx = mmesa->glCtx; const GLuint vertsize = mmesa->vertex_size; - GLint sz = (GLint)(mmesa->glCtx->Point._Size * 2.0); /* 2 fractional bits for hardware */ + /* 2 fractional bits for hardware: */ + GLint sz = (GLint) (2.0 * CLAMP(mmesa->glCtx->Point.Size, + ctx->Const.MinPointSize, + ctx->Const.MaxPointSize)); GLfloat ooa; GLuint *pxy; GLuint xyold, xy; diff --git a/src/mesa/drivers/dri/mga/mgatris.c b/src/mesa/drivers/dri/mga/mgatris.c index 2b7ea05b14..91b413ae76 100644 --- a/src/mesa/drivers/dri/mga/mgatris.c +++ b/src/mesa/drivers/dri/mga/mgatris.c @@ -104,8 +104,10 @@ static void __inline__ mga_draw_quad( mgaContextPtr mmesa, static __inline__ void mga_draw_point( mgaContextPtr mmesa, mgaVertexPtr tmp ) { - GLfloat sz = mmesa->glCtx->Point._Size * .5; - int vertex_size = mmesa->vertex_size; + const GLfloat sz = 0.5 * CLAMP(mmesa->glCtx->Point.Size, + mmesa->glCtx->Const.MinPointSize, + mmesa->glCtx->Const.MaxPointSize); + const int vertex_size = mmesa->vertex_size; GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size ); int j; @@ -165,7 +167,9 @@ static __inline__ void mga_draw_line( mgaContextPtr mmesa, GLuint vertex_size = mmesa->vertex_size; GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size ); GLfloat dx, dy, ix, iy; - GLfloat width = mmesa->glCtx->Line._Width; + const GLfloat width = CLAMP(mmesa->glCtx->Line.Width, + mmesa->glCtx->Const.MinLineWidth, + mmesa->glCtx->Const.MaxLineWidth); GLint j; #if 0 diff --git a/src/mesa/drivers/dri/nouveau/Makefile b/src/mesa/drivers/dri/nouveau/Makefile index 20d2de5eef..6ea4594f1e 100644 --- a/src/mesa/drivers/dri/nouveau/Makefile +++ b/src/mesa/drivers/dri/nouveau/Makefile @@ -9,12 +9,13 @@ MINIGLX_SOURCES = DRIVER_SOURCES = \ nouveau_bufferobj.c \ - nouveau_buffers.c \ nouveau_card.c \ nouveau_context.c \ nouveau_driver.c \ + nouveau_fbo.c \ nouveau_fifo.c \ nouveau_lock.c \ + nouveau_mem.c \ nouveau_object.c \ nouveau_screen.c \ nouveau_span.c \ diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c index fc14060c04..be6455a01e 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c @@ -2,11 +2,11 @@ #include "enums.h" #include "nouveau_bufferobj.h" -#include "nouveau_buffers.h" #include "nouveau_context.h" #include "nouveau_drm.h" -#include "nouveau_object.h" +#include "nouveau_mem.h" #include "nouveau_msg.h" +#include "nouveau_object.h" #define NOUVEAU_MEM_FREE(mem) do { \ nouveau_mem_free(ctx, (mem)); \ diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h index 3439a35e7c..cbc89a151d 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h @@ -2,7 +2,7 @@ #define __NOUVEAU_BUFFEROBJ_H__ #include "mtypes.h" -#include "nouveau_buffers.h" +#include "nouveau_mem.h" #define NOUVEAU_BO_VRAM_OK (NOUVEAU_MEM_FB | NOUVEAU_MEM_FB_ACCEPTABLE) #define NOUVEAU_BO_GART_OK (NOUVEAU_MEM_AGP | NOUVEAU_MEM_AGP_ACCEPTABLE) diff --git a/src/mesa/drivers/dri/nouveau/nouveau_buffers.c b/src/mesa/drivers/dri/nouveau/nouveau_buffers.c deleted file mode 100644 index 6a2c2013e3..0000000000 --- a/src/mesa/drivers/dri/nouveau/nouveau_buffers.c +++ /dev/null @@ -1,441 +0,0 @@ -#include "utils.h" -#include "framebuffer.h" -#include "renderbuffer.h" -#include "fbobject.h" - -#include "nouveau_context.h" -#include "nouveau_buffers.h" -#include "nouveau_object.h" -#include "nouveau_fifo.h" -#include "nouveau_reg.h" -#include "nouveau_msg.h" - -#define MAX_MEMFMT_LENGTH 32768 - -/* Unstrided blit using NV_MEMORY_TO_MEMORY_FORMAT */ -GLboolean -nouveau_memformat_flat_emit(GLcontext *ctx, - nouveau_mem *dst, nouveau_mem *src, - GLuint dst_offset, GLuint src_offset, - GLuint size) -{ - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - uint32_t src_handle, dst_handle; - GLuint count; - - if (src_offset + size > src->size) { - MESSAGE("src out of nouveau_mem bounds\n"); - return GL_FALSE; - } - if (dst_offset + size > dst->size) { - MESSAGE("dst out of nouveau_mem bounds\n"); - return GL_FALSE; - } - - src_handle = (src->type & NOUVEAU_MEM_FB) ? NvDmaFB : NvDmaTT; - dst_handle = (dst->type & NOUVEAU_MEM_FB) ? NvDmaFB : NvDmaTT; - src_offset += nouveau_mem_gpu_offset_get(ctx, src); - dst_offset += nouveau_mem_gpu_offset_get(ctx, dst); - - BEGIN_RING_SIZE(NvSubMemFormat, NV_MEMORY_TO_MEMORY_FORMAT_OBJECT_IN, 2); - OUT_RING (src_handle); - OUT_RING (dst_handle); - - count = (size / MAX_MEMFMT_LENGTH) + ((size % MAX_MEMFMT_LENGTH) ? 1 : 0); - - while (count--) { - GLuint length = (size > MAX_MEMFMT_LENGTH) ? MAX_MEMFMT_LENGTH : size; - - BEGIN_RING_SIZE(NvSubMemFormat, NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); - OUT_RING (src_offset); - OUT_RING (dst_offset); - OUT_RING (0); /* pitch in */ - OUT_RING (0); /* pitch out */ - OUT_RING (length); /* line length */ - OUT_RING (1); /* number of lines */ - OUT_RING ((1 << 8) /* dst_inc */ | (1 << 0) /* src_inc */); - OUT_RING (0); /* buffer notify? */ - FIRE_RING(); - - src_offset += length; - dst_offset += length; - size -= length; - } - - return GL_TRUE; -} - -void -nouveau_mem_free(GLcontext *ctx, nouveau_mem *mem) -{ - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - drm_nouveau_mem_free_t memf; - - if (NOUVEAU_DEBUG & DEBUG_MEM) { - fprintf(stderr, "%s: type=0x%x, offset=0x%x, size=0x%x\n", - __func__, mem->type, (GLuint)mem->offset, (GLuint)mem->size); - } - - if (mem->map) - drmUnmap(mem->map, mem->size); - memf.flags = mem->type; - memf.region_offset = mem->offset; - drmCommandWrite(nmesa->driFd, DRM_NOUVEAU_MEM_FREE, &memf, sizeof(memf)); - FREE(mem); -} - -nouveau_mem * -nouveau_mem_alloc(GLcontext *ctx, int type, GLuint size, GLuint align) -{ - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - drm_nouveau_mem_alloc_t mema; - nouveau_mem *mem; - int ret; - - if (NOUVEAU_DEBUG & DEBUG_MEM) { - fprintf(stderr, "%s: requested: type=0x%x, size=0x%x, align=0x%x\n", - __func__, type, (GLuint)size, align); - } - - mem = CALLOC(sizeof(nouveau_mem)); - if (!mem) - return NULL; - - mema.flags = type; - mema.size = mem->size = size; - mema.alignment = align; - mem->map = NULL; - ret = drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_MEM_ALLOC, - &mema, sizeof(mema)); - if (ret) { - FREE(mem); - return NULL; - } - mem->offset = mema.region_offset; - mem->type = mema.flags; - - if (NOUVEAU_DEBUG & DEBUG_MEM) { - fprintf(stderr, "%s: actual: type=0x%x, offset=0x%x, size=0x%x\n", - __func__, mem->type, (GLuint)mem->offset, (GLuint)mem->size); - } - - if (type & NOUVEAU_MEM_MAPPED) - ret = drmMap(nmesa->driFd, mem->offset, mem->size, &mem->map); - if (ret) { - mem->map = NULL; - nouveau_mem_free(ctx, mem); - mem = NULL; - } - - return mem; -} - -uint32_t -nouveau_mem_gpu_offset_get(GLcontext *ctx, nouveau_mem *mem) -{ - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - - if (mem->type & NOUVEAU_MEM_FB) - return (uint32_t)mem->offset - nmesa->vram_phys; - else if (mem->type & NOUVEAU_MEM_AGP) - return (uint32_t)mem->offset - nmesa->gart_phys; - else - return 0xDEADF00D; -} - -static GLboolean -nouveau_renderbuffer_pixelformat(nouveau_renderbuffer *nrb, - GLenum internalFormat) -{ - nrb->mesa.InternalFormat = internalFormat; - - /*TODO: We probably want to extend this a bit, and maybe make - * card-specific? - */ - switch (internalFormat) { - case GL_RGBA: - case GL_RGBA8: - nrb->mesa._BaseFormat = GL_RGBA; - nrb->mesa._ActualFormat= GL_RGBA8; - nrb->mesa.DataType = GL_UNSIGNED_BYTE; - nrb->mesa.RedBits = 8; - nrb->mesa.GreenBits = 8; - nrb->mesa.BlueBits = 8; - nrb->mesa.AlphaBits = 8; - nrb->cpp = 4; - break; - case GL_RGB: - case GL_RGB5: - nrb->mesa._BaseFormat = GL_RGB; - nrb->mesa._ActualFormat= GL_RGB5; - nrb->mesa.DataType = GL_UNSIGNED_BYTE; - nrb->mesa.RedBits = 5; - nrb->mesa.GreenBits = 6; - nrb->mesa.BlueBits = 5; - nrb->mesa.AlphaBits = 0; - nrb->cpp = 2; - break; - case GL_DEPTH_COMPONENT16: - nrb->mesa._BaseFormat = GL_DEPTH_COMPONENT; - nrb->mesa._ActualFormat= GL_DEPTH_COMPONENT16; - nrb->mesa.DataType = GL_UNSIGNED_SHORT; - nrb->mesa.DepthBits = 16; - nrb->cpp = 2; - break; - case GL_DEPTH_COMPONENT24: - nrb->mesa._BaseFormat = GL_DEPTH_COMPONENT; - nrb->mesa._ActualFormat= GL_DEPTH24_STENCIL8_EXT; - nrb->mesa.DataType = GL_UNSIGNED_INT_24_8_EXT; - nrb->mesa.DepthBits = 24; - nrb->cpp = 4; - break; - case GL_STENCIL_INDEX8_EXT: - nrb->mesa._BaseFormat = GL_STENCIL_INDEX; - nrb->mesa._ActualFormat= GL_DEPTH24_STENCIL8_EXT; - nrb->mesa.DataType = GL_UNSIGNED_INT_24_8_EXT; - nrb->mesa.StencilBits = 8; - nrb->cpp = 4; - break; - case GL_DEPTH24_STENCIL8_EXT: - nrb->mesa._BaseFormat = GL_DEPTH_STENCIL_EXT; - nrb->mesa._ActualFormat= GL_DEPTH24_STENCIL8_EXT; - nrb->mesa.DataType = GL_UNSIGNED_INT_24_8_EXT; - nrb->mesa.DepthBits = 24; - nrb->mesa.StencilBits = 8; - nrb->cpp = 4; - break; - default: - return GL_FALSE; - break; - } - - return GL_TRUE; -} - -static GLboolean -nouveau_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, - GLuint width, - GLuint height) -{ - nouveau_renderbuffer *nrb = (nouveau_renderbuffer*)rb; - - if (!nouveau_renderbuffer_pixelformat(nrb, internalFormat)) { - fprintf(stderr, "%s: unknown internalFormat\n", __func__); - return GL_FALSE; - } - - /* If this buffer isn't statically alloc'd, we may need to ask the - * drm for more memory */ - if (!nrb->dPriv && (rb->Width != width || rb->Height != height)) { - GLuint pitch; - - /* align pitches to 64 bytes */ - pitch = ((width * nrb->cpp) + 63) & ~63; - - if (nrb->mem) - nouveau_mem_free(ctx, nrb->mem); - nrb->mem = nouveau_mem_alloc(ctx, - NOUVEAU_MEM_FB | NOUVEAU_MEM_MAPPED, - pitch*height, - 0); - if (!nrb->mem) - return GL_FALSE; - - /* update nouveau_renderbuffer info */ - nrb->offset = nouveau_mem_gpu_offset_get(ctx, nrb->mem); - nrb->pitch = pitch; - } - - rb->Width = width; - rb->Height = height; - rb->InternalFormat = internalFormat; - return GL_TRUE; -} - -static void -nouveau_renderbuffer_delete(struct gl_renderbuffer *rb) -{ - GET_CURRENT_CONTEXT(ctx); - nouveau_renderbuffer *nrb = (nouveau_renderbuffer*)rb; - - if (nrb->mem) - nouveau_mem_free(ctx, nrb->mem); - FREE(nrb); -} - -nouveau_renderbuffer * -nouveau_renderbuffer_new(GLenum internalFormat, GLvoid *map, - GLuint offset, GLuint pitch, - __DRIdrawablePrivate *dPriv) -{ - nouveau_renderbuffer *nrb; - - nrb = CALLOC_STRUCT(nouveau_renderbuffer_t); - if (nrb) { - _mesa_init_renderbuffer(&nrb->mesa, 0); - - nouveau_renderbuffer_pixelformat(nrb, internalFormat); - - nrb->mesa.AllocStorage = nouveau_renderbuffer_storage; - nrb->mesa.Delete = nouveau_renderbuffer_delete; - - nrb->dPriv = dPriv; - nrb->offset = offset; - nrb->pitch = pitch; - nrb->map = map; - } - - return nrb; -} - -static void -nouveau_cliprects_drawable_set(nouveauContextPtr nmesa, - nouveau_renderbuffer *nrb) -{ - __DRIdrawablePrivate *dPriv = nrb->dPriv; - - nmesa->numClipRects = dPriv->numClipRects; - nmesa->pClipRects = dPriv->pClipRects; - nmesa->drawX = dPriv->x; - nmesa->drawY = dPriv->y; - nmesa->drawW = dPriv->w; - nmesa->drawH = dPriv->h; -} - -static void -nouveau_cliprects_renderbuffer_set(nouveauContextPtr nmesa, - nouveau_renderbuffer *nrb) -{ - nmesa->numClipRects = 1; - nmesa->pClipRects = &nmesa->osClipRect; - nmesa->osClipRect.x1 = 0; - nmesa->osClipRect.y1 = 0; - nmesa->osClipRect.x2 = nrb->mesa.Width; - nmesa->osClipRect.y2 = nrb->mesa.Height; - nmesa->drawX = 0; - nmesa->drawY = 0; - nmesa->drawW = nrb->mesa.Width; - nmesa->drawH = nrb->mesa.Height; -} - -void -nouveau_window_moved(GLcontext *ctx) -{ - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - nouveau_renderbuffer *nrb; - - nrb = (nouveau_renderbuffer *)ctx->DrawBuffer->_ColorDrawBuffers[0][0]; - if (!nrb) - return; - - if (!nrb->dPriv) - nouveau_cliprects_renderbuffer_set(nmesa, nrb); - else - nouveau_cliprects_drawable_set(nmesa, nrb); - - /* Viewport depends on window size/position, nouveauCalcViewport - * will take care of calling the hw-specific WindowMoved - */ - ctx->Driver.Viewport(ctx, ctx->Viewport.X, ctx->Viewport.Y, - ctx->Viewport.Width, ctx->Viewport.Height); - /* Scissor depends on window position */ - ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y, - ctx->Scissor.Width, ctx->Scissor.Height); -} - -GLboolean -nouveau_build_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) -{ - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - nouveau_renderbuffer *color[MAX_DRAW_BUFFERS]; - nouveau_renderbuffer *depth; - - _mesa_update_framebuffer(ctx); - _mesa_update_draw_buffer_bounds(ctx); - - color[0] = (nouveau_renderbuffer *)fb->_ColorDrawBuffers[0][0]; - if (fb->_DepthBuffer && fb->_DepthBuffer->Wrapped) - depth = (nouveau_renderbuffer *)fb->_DepthBuffer->Wrapped; - else - depth = (nouveau_renderbuffer *)fb->_DepthBuffer; - - if (!nmesa->hw_func.BindBuffers(nmesa, 1, color, depth)) - return GL_FALSE; - nouveau_window_moved(ctx); - - return GL_TRUE; -} - -static void -nouveauDrawBuffer(GLcontext *ctx, GLenum buffer) -{ - nouveau_build_framebuffer(ctx, ctx->DrawBuffer); -} - -static struct gl_framebuffer * -nouveauNewFramebuffer(GLcontext *ctx, GLuint name) -{ - return _mesa_new_framebuffer(ctx, name); -} - -static struct gl_renderbuffer * -nouveauNewRenderbuffer(GLcontext *ctx, GLuint name) -{ - nouveau_renderbuffer *nrb; - - nrb = CALLOC_STRUCT(nouveau_renderbuffer_t); - if (nrb) { - _mesa_init_renderbuffer(&nrb->mesa, name); - - nrb->mesa.AllocStorage = nouveau_renderbuffer_storage; - nrb->mesa.Delete = nouveau_renderbuffer_delete; - } - return &nrb->mesa; -} - -static void -nouveauBindFramebuffer(GLcontext *ctx, GLenum target, - struct gl_framebuffer *fb, struct gl_framebuffer *fbread) -{ - if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) { - nouveau_build_framebuffer(ctx, fb); - } -} - -static void -nouveauFramebufferRenderbuffer(GLcontext *ctx, - struct gl_framebuffer *fb, - GLenum attachment, - struct gl_renderbuffer *rb) -{ - _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); - nouveau_build_framebuffer(ctx, fb); -} - -static void -nouveauRenderTexture(GLcontext *ctx, - struct gl_framebuffer *fb, - struct gl_renderbuffer_attachment *att) -{ -} - -static void -nouveauFinishRenderTexture(GLcontext *ctx, - struct gl_renderbuffer_attachment *att) -{ -} - -void -nouveauInitBufferFuncs(struct dd_function_table *func) -{ - func->DrawBuffer = nouveauDrawBuffer; - - func->NewFramebuffer = nouveauNewFramebuffer; - func->NewRenderbuffer = nouveauNewRenderbuffer; - func->BindFramebuffer = nouveauBindFramebuffer; - func->FramebufferRenderbuffer = nouveauFramebufferRenderbuffer; - func->RenderTexture = nouveauRenderTexture; - func->FinishRenderTexture = nouveauFinishRenderTexture; -} - diff --git a/src/mesa/drivers/dri/nouveau/nouveau_buffers.h b/src/mesa/drivers/dri/nouveau/nouveau_buffers.h deleted file mode 100644 index d86455184c..0000000000 --- a/src/mesa/drivers/dri/nouveau/nouveau_buffers.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __NOUVEAU_BUFFERS_H__ -#define __NOUVEAU_BUFFERS_H__ - -#include <stdint.h> -#include "mtypes.h" -#include "utils.h" -#include "renderbuffer.h" - -typedef struct nouveau_mem_t { - int type; - uint64_t offset; - uint64_t size; - void* map; -} nouveau_mem; - -extern nouveau_mem *nouveau_mem_alloc(GLcontext *ctx, int type, - GLuint size, GLuint align); -extern void nouveau_mem_free(GLcontext *ctx, nouveau_mem *mem); -extern uint32_t nouveau_mem_gpu_offset_get(GLcontext *ctx, nouveau_mem *mem); - -extern GLboolean nouveau_memformat_flat_emit(GLcontext *ctx, - nouveau_mem *dst, - nouveau_mem *src, - GLuint dst_offset, - GLuint src_offset, - GLuint size); - -typedef struct nouveau_renderbuffer_t { - struct gl_renderbuffer mesa; /* must be first! */ - __DRIdrawablePrivate *dPriv; - - nouveau_mem *mem; - void * map; - - int cpp; - uint32_t offset; - uint32_t pitch; -} nouveau_renderbuffer; - -extern nouveau_renderbuffer *nouveau_renderbuffer_new(GLenum internalFormat, - GLvoid *map, GLuint offset, GLuint pitch, __DRIdrawablePrivate *dPriv); -extern void nouveau_window_moved(GLcontext *ctx); -extern GLboolean nouveau_build_framebuffer(GLcontext *, struct gl_framebuffer *); -extern nouveau_renderbuffer *nouveau_current_draw_buffer(GLcontext *ctx); - -extern void nouveauInitBufferFuncs(struct dd_function_table *func); - -#endif diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c index d96b00242c..1e13324b98 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_context.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c @@ -180,7 +180,7 @@ GLboolean nouveauCreateContext( const __GLcontextModes *glVisual, driParseConfigFiles (&nmesa->optionCache, &screen->optionCache, screen->driScreen->myNum, "nouveau"); - nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA + + nmesa->sarea = (struct drm_nouveau_sarea *)((char *)sPriv->pSAREA + screen->sarea_priv_offset); /* Enable any supported extensions */ @@ -224,6 +224,8 @@ GLboolean nouveauCreateContext( const __GLcontextModes *glVisual, nv04TriInitFunctions( ctx ); break; case NV_10: + case NV_11: + case NV_17: case NV_20: case NV_30: case NV_40: @@ -313,21 +315,24 @@ GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv ) return GL_TRUE; } -static void nouveauDoSwapBuffers(nouveauContextPtr nmesa, - __DRIdrawablePrivate *dPriv) +void +nouveauDoSwapBuffers(nouveauContextPtr nmesa, __DRIdrawablePrivate *dPriv) { struct gl_framebuffer *fb; - nouveau_renderbuffer *src, *dst; + nouveauScreenPtr screen = dPriv->driScreenPriv->private; + nouveau_renderbuffer_t *src; drm_clip_rect_t *box; int nbox, i; fb = (struct gl_framebuffer *)dPriv->driverPrivate; - dst = (nouveau_renderbuffer*) - fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; - src = (nouveau_renderbuffer*) - fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer; + if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) { + src = (nouveau_renderbuffer_t *) + fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; + } else { + src = (nouveau_renderbuffer_t *) + fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer; + } -#ifdef ALLOW_MULTI_SUBCHANNEL LOCK_HARDWARE(nmesa); nbox = dPriv->numClipRects; box = dPriv->pClipRects; @@ -339,9 +344,10 @@ static void nouveauDoSwapBuffers(nouveauContextPtr nmesa, OUT_RING (6); /* X8R8G8B8 */ else OUT_RING (4); /* R5G6B5 */ - OUT_RING ((dst->pitch << 16) | src->pitch); - OUT_RING (src->offset); - OUT_RING (dst->offset); + OUT_RING(((screen->frontPitch * screen->fbFormat) << 16) | + src->pitch); + OUT_RING(src->offset); + OUT_RING(screen->frontOffset); } for (i=0; i<nbox; i++, box++) { @@ -355,7 +361,6 @@ static void nouveauDoSwapBuffers(nouveauContextPtr nmesa, FIRE_RING(); UNLOCK_HARDWARE(nmesa); -#endif } void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv) diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.h b/src/mesa/drivers/dri/nouveau/nouveau_context.h index 10d2ed6e17..65ecf21cab 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_context.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.h @@ -36,25 +36,24 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "mtypes.h" #include "tnl/t_vertex.h" +#include "nouveau_fbo.h" #include "nouveau_screen.h" -#include "nouveau_state_cache.h" -#include "nouveau_buffers.h" #include "nouveau_shader.h" +#include "nouveau_state_cache.h" #include "nouveau_sync.h" #include "xmlconfig.h" -typedef struct nouveau_fifo_t{ - int channel; - u_int32_t* buffer; - u_int32_t* mmio; - u_int32_t put_base; - u_int32_t current; - u_int32_t put; - u_int32_t free; - u_int32_t max; -} -nouveau_fifo; +typedef struct nouveau_fifo { + struct drm_nouveau_channel_alloc drm; + uint32_t *pushbuf; + uint32_t *mmio; + uint32_t *notifier_block; + uint32_t current; + uint32_t put; + uint32_t free; + uint32_t max; +} nouveau_fifo_t; #define TAG(x) nouveau##x #include "tnl_dd/t_dd_vertex.h" @@ -83,8 +82,8 @@ typedef struct nouveau_hw_func_t { GLboolean (*InitCard)(struct nouveau_context *); /* Update buffer offset/pitch/format */ GLboolean (*BindBuffers)(struct nouveau_context *, int num_color, - nouveau_renderbuffer **color, - nouveau_renderbuffer *depth); + nouveau_renderbuffer_t **color, + nouveau_renderbuffer_t *depth); /* Update anything that depends on the window position/size */ void (*WindowMoved)(struct nouveau_context *); } nouveau_hw_func; @@ -94,13 +93,7 @@ typedef struct nouveau_context { GLcontext *glCtx; /* The per-context fifo */ - nouveau_fifo fifo; - - /* The read-only regs */ - volatile unsigned char* mmio; - - /* The per-channel notifier block */ - volatile void *notifier_block; + nouveau_fifo_t fifo; /* Physical addresses of AGP/VRAM apertures */ uint64_t vram_phys; @@ -109,12 +102,12 @@ typedef struct nouveau_context { uint64_t gart_size; /* Channel synchronisation */ - drm_nouveau_notifier_alloc_t *syncNotifier; + struct drm_nouveau_notifierobj_alloc *syncNotifier; /* ARB_occlusion_query / EXT_timer_query */ GLuint query_object_max; GLboolean * query_alloc; - drm_nouveau_notifier_alloc_t *queryNotifier; + struct drm_nouveau_notifierobj_alloc *queryNotifier; /* Additional hw-specific functions */ nouveau_hw_func hw_func; @@ -130,6 +123,10 @@ typedef struct nouveau_context { struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX]; GLuint vertex_attr_count; + /* Color and depth renderbuffers */ + nouveau_renderbuffer_t *color_buffer[2]; + nouveau_renderbuffer_t *depth_buffer; + /* Color buffer clear value */ uint32_t clear_color_value; @@ -168,7 +165,7 @@ typedef struct nouveau_context { nouveauShader *passthrough_fp; nouveauScreenRec *screen; - drm_nouveau_sarea_t *sarea; + struct drm_nouveau_sarea *sarea; __DRIcontextPrivate *driContext; /* DRI context */ __DRIscreenPrivate *driScreen; /* DRI screen */ @@ -223,6 +220,9 @@ extern GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv, extern GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv ); +extern void nouveauDoSwapBuffers(nouveauContextPtr nmesa, + __DRIdrawablePrivate *dPriv); + extern void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv); extern void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv, diff --git a/src/mesa/drivers/dri/nouveau/nouveau_driver.c b/src/mesa/drivers/dri/nouveau/nouveau_driver.c index 00956aa8f8..4851c66835 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_driver.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_driver.c @@ -41,7 +41,7 @@ GLboolean nouveauDRMGetParam(nouveauContextPtr nmesa, unsigned int param, uint64_t* value) { - drm_nouveau_getparam_t getp; + struct drm_nouveau_getparam getp; getp.param = param; if (!value || drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_GETPARAM, @@ -56,7 +56,7 @@ GLboolean nouveauDRMSetParam(nouveauContextPtr nmesa, unsigned int param, uint64_t value) { - drm_nouveau_setparam_t setp; + struct drm_nouveau_setparam setp; setp.param = param; setp.value = value; @@ -117,6 +117,9 @@ static const GLubyte *nouveauGetString( GLcontext *ctx, GLenum name ) static void nouveauFlush( GLcontext *ctx ) { nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + + if (ctx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) + nouveauDoSwapBuffers(nmesa, nmesa->driDrawable); FIRE_RING(); } @@ -124,6 +127,7 @@ static void nouveauFlush( GLcontext *ctx ) static void nouveauFinish( GLcontext *ctx ) { nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + nouveauFlush( ctx ); nouveauWaitForIdle( nmesa ); } diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fbo.c b/src/mesa/drivers/dri/nouveau/nouveau_fbo.c new file mode 100644 index 0000000000..cc3da8b9bd --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_fbo.c @@ -0,0 +1,290 @@ +#include "utils.h" +#include "framebuffer.h" +#include "renderbuffer.h" +#include "fbobject.h" + +#include "nouveau_context.h" +#include "nouveau_fbo.h" +#include "nouveau_fifo.h" +#include "nouveau_msg.h" +#include "nouveau_object.h" +#include "nouveau_reg.h" + +static GLboolean +nouveau_renderbuffer_pixelformat(nouveau_renderbuffer_t * nrb, + GLenum internalFormat) +{ + nrb->mesa.InternalFormat = internalFormat; + + /*TODO: We probably want to extend this a bit, and maybe make + * card-specific? + */ + switch (internalFormat) { + case GL_RGBA: + case GL_RGBA8: + nrb->mesa._BaseFormat = GL_RGBA; + nrb->mesa._ActualFormat = GL_RGBA8; + nrb->mesa.DataType = GL_UNSIGNED_BYTE; + nrb->mesa.RedBits = 8; + nrb->mesa.GreenBits = 8; + nrb->mesa.BlueBits = 8; + nrb->mesa.AlphaBits = 8; + nrb->cpp = 4; + break; + case GL_RGB: + case GL_RGB5: + nrb->mesa._BaseFormat = GL_RGB; + nrb->mesa._ActualFormat = GL_RGB5; + nrb->mesa.DataType = GL_UNSIGNED_BYTE; + nrb->mesa.RedBits = 5; + nrb->mesa.GreenBits = 6; + nrb->mesa.BlueBits = 5; + nrb->mesa.AlphaBits = 0; + nrb->cpp = 2; + break; + case GL_DEPTH_COMPONENT16: + nrb->mesa._BaseFormat = GL_DEPTH_COMPONENT; + nrb->mesa._ActualFormat = GL_DEPTH_COMPONENT16; + nrb->mesa.DataType = GL_UNSIGNED_SHORT; + nrb->mesa.DepthBits = 16; + nrb->cpp = 2; + break; + case GL_DEPTH_COMPONENT24: + nrb->mesa._BaseFormat = GL_DEPTH_COMPONENT; + nrb->mesa._ActualFormat = GL_DEPTH24_STENCIL8_EXT; + nrb->mesa.DataType = GL_UNSIGNED_INT_24_8_EXT; + nrb->mesa.DepthBits = 24; + nrb->cpp = 4; + break; + case GL_STENCIL_INDEX8_EXT: + nrb->mesa._BaseFormat = GL_STENCIL_INDEX; + nrb->mesa._ActualFormat = GL_DEPTH24_STENCIL8_EXT; + nrb->mesa.DataType = GL_UNSIGNED_INT_24_8_EXT; + nrb->mesa.StencilBits = 8; + nrb->cpp = 4; + break; + case GL_DEPTH24_STENCIL8_EXT: + nrb->mesa._BaseFormat = GL_DEPTH_STENCIL_EXT; + nrb->mesa._ActualFormat = GL_DEPTH24_STENCIL8_EXT; + nrb->mesa.DataType = GL_UNSIGNED_INT_24_8_EXT; + nrb->mesa.DepthBits = 24; + nrb->mesa.StencilBits = 8; + nrb->cpp = 4; + break; + default: + return GL_FALSE; + break; + } + + return GL_TRUE; +} + +static GLboolean +nouveau_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb, + GLenum internalFormat, + GLuint width, GLuint height) +{ + nouveau_renderbuffer_t *nrb = (nouveau_renderbuffer_t *) rb; + + if (!nouveau_renderbuffer_pixelformat(nrb, internalFormat)) { + fprintf(stderr, "%s: unknown internalFormat\n", __func__); + return GL_FALSE; + } + + /* If this buffer isn't statically alloc'd, we may need to ask the + * drm for more memory */ + if (rb->Width != width || rb->Height != height) { + GLuint pitch; + + /* align pitches to 64 bytes */ + pitch = ((width * nrb->cpp) + 63) & ~63; + + if (nrb->mem) + nouveau_mem_free(ctx, nrb->mem); + nrb->mem = nouveau_mem_alloc(ctx, + NOUVEAU_MEM_FB | + NOUVEAU_MEM_MAPPED, + pitch * height, 0); + if (!nrb->mem) + return GL_FALSE; + + /* update nouveau_renderbuffer info */ + nrb->offset = nouveau_mem_gpu_offset_get(ctx, nrb->mem); + nrb->pitch = pitch; + } + + rb->Width = width; + rb->Height = height; + rb->InternalFormat = internalFormat; + + nouveauSpanSetFunctions(nrb); + + return GL_TRUE; +} + +static void +nouveau_renderbuffer_delete(struct gl_renderbuffer *rb) +{ + GET_CURRENT_CONTEXT(ctx); + nouveau_renderbuffer_t *nrb = (nouveau_renderbuffer_t *) rb; + + if (nrb->mem) + nouveau_mem_free(ctx, nrb->mem); + FREE(nrb); +} + +nouveau_renderbuffer_t * +nouveau_renderbuffer_new(GLenum internalFormat) +{ + nouveau_renderbuffer_t *nrb; + + nrb = CALLOC_STRUCT(nouveau_renderbuffer); + if (!nrb) + return NULL; + + _mesa_init_renderbuffer(&nrb->mesa, 0); + + if (!nouveau_renderbuffer_pixelformat(nrb, internalFormat)) { + fprintf(stderr, "%s: unknown internalFormat\n", __func__); + return GL_FALSE; + } + + nrb->mesa.AllocStorage = nouveau_renderbuffer_storage; + nrb->mesa.Delete = nouveau_renderbuffer_delete; + + return nrb; +} + +static void +nouveau_cliprects_renderbuffer_set(nouveauContextPtr nmesa, + nouveau_renderbuffer_t * nrb) +{ + nmesa->numClipRects = 1; + nmesa->pClipRects = &nmesa->osClipRect; + nmesa->osClipRect.x1 = 0; + nmesa->osClipRect.y1 = 0; + nmesa->osClipRect.x2 = nrb->mesa.Width; + nmesa->osClipRect.y2 = nrb->mesa.Height; + nmesa->drawX = 0; + nmesa->drawY = 0; + nmesa->drawW = nrb->mesa.Width; + nmesa->drawH = nrb->mesa.Height; +} + +void +nouveau_window_moved(GLcontext * ctx) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + nouveau_renderbuffer_t *nrb; + + nrb = (nouveau_renderbuffer_t *) + ctx->DrawBuffer->_ColorDrawBuffers[0][0]; + if (!nrb) + return; + + nouveau_cliprects_renderbuffer_set(nmesa, nrb); + + /* Viewport depends on window size/position, nouveauCalcViewport + * will take care of calling the hw-specific WindowMoved + */ + ctx->Driver.Viewport(ctx, ctx->Viewport.X, ctx->Viewport.Y, + ctx->Viewport.Width, ctx->Viewport.Height); + /* Scissor depends on window position */ + ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y, + ctx->Scissor.Width, ctx->Scissor.Height); +} + +GLboolean +nouveau_build_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + nouveau_renderbuffer_t *color[MAX_DRAW_BUFFERS]; + nouveau_renderbuffer_t *depth; + + _mesa_update_framebuffer(ctx); + _mesa_update_draw_buffer_bounds(ctx); + + color[0] = (nouveau_renderbuffer_t *) fb->_ColorDrawBuffers[0][0]; + if (fb->_DepthBuffer && fb->_DepthBuffer->Wrapped) + depth = (nouveau_renderbuffer_t *) fb->_DepthBuffer->Wrapped; + else + depth = (nouveau_renderbuffer_t *) fb->_DepthBuffer; + + if (!nmesa->hw_func.BindBuffers(nmesa, 1, color, depth)) + return GL_FALSE; + nouveau_window_moved(ctx); + + return GL_TRUE; +} + +static void +nouveauDrawBuffer(GLcontext *ctx, GLenum buffer) +{ + nouveau_build_framebuffer(ctx, ctx->DrawBuffer); +} + +static struct gl_framebuffer * +nouveauNewFramebuffer(GLcontext *ctx, GLuint name) +{ + return _mesa_new_framebuffer(ctx, name); +} + +static struct gl_renderbuffer * +nouveauNewRenderbuffer(GLcontext *ctx, GLuint name) +{ + nouveau_renderbuffer_t *nrb; + + nrb = CALLOC_STRUCT(nouveau_renderbuffer); + if (!nrb) + return NULL; + + _mesa_init_renderbuffer(&nrb->mesa, name); + + nrb->mesa.AllocStorage = nouveau_renderbuffer_storage; + nrb->mesa.Delete = nouveau_renderbuffer_delete; + return &nrb->mesa; +} + +static void +nouveauBindFramebuffer(GLcontext *ctx, GLenum target, + struct gl_framebuffer *fb, + struct gl_framebuffer *fbread) +{ + if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) { + nouveau_build_framebuffer(ctx, fb); + } +} + +static void +nouveauFramebufferRenderbuffer(GLcontext *ctx, struct gl_framebuffer *fb, + GLenum attachment, struct gl_renderbuffer *rb) +{ + _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); + nouveau_build_framebuffer(ctx, fb); +} + +static void +nouveauRenderTexture(GLcontext * ctx, struct gl_framebuffer *fb, + struct gl_renderbuffer_attachment *att) +{ +} + +static void +nouveauFinishRenderTexture(GLcontext * ctx, + struct gl_renderbuffer_attachment *att) +{ +} + +void +nouveauInitBufferFuncs(struct dd_function_table *func) +{ + func->DrawBuffer = nouveauDrawBuffer; + + func->NewFramebuffer = nouveauNewFramebuffer; + func->NewRenderbuffer = nouveauNewRenderbuffer; + func->BindFramebuffer = nouveauBindFramebuffer; + func->FramebufferRenderbuffer = nouveauFramebufferRenderbuffer; + func->RenderTexture = nouveauRenderTexture; + func->FinishRenderTexture = nouveauFinishRenderTexture; +} + diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fbo.h b/src/mesa/drivers/dri/nouveau/nouveau_fbo.h new file mode 100644 index 0000000000..787af4e9e4 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_fbo.h @@ -0,0 +1,30 @@ +#ifndef __NOUVEAU_BUFFERS_H__ +#define __NOUVEAU_BUFFERS_H__ + +#include <stdint.h> +#include "mtypes.h" +#include "utils.h" +#include "renderbuffer.h" + +#include "nouveau_mem.h" + +typedef struct nouveau_renderbuffer { + struct gl_renderbuffer mesa; /* must be first! */ + + nouveau_mem *mem; + void *map; + + int cpp; + uint32_t offset; + uint32_t pitch; +} nouveau_renderbuffer_t; + +extern nouveau_renderbuffer_t *nouveau_renderbuffer_new(GLenum internalFormat); +extern void nouveau_window_moved(GLcontext *); +extern GLboolean nouveau_build_framebuffer(GLcontext *, + struct gl_framebuffer *); +extern nouveau_renderbuffer_t *nouveau_current_draw_buffer(GLcontext *); + +extern void nouveauInitBufferFuncs(struct dd_function_table *); + +#endif diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fifo.c b/src/mesa/drivers/dri/nouveau/nouveau_fifo.c index e9320918f9..5dc94e0520 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_fifo.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_fifo.c @@ -57,7 +57,8 @@ void WAIT_RING(nouveauContextPtr nmesa,u_int32_t size) if(nmesa->fifo.put >= fifo_get) { nmesa->fifo.free = nmesa->fifo.max - nmesa->fifo.current; if(nmesa->fifo.free < size+1) { - OUT_RING(NV03_FIFO_CMD_JUMP | nmesa->fifo.put_base); + OUT_RING(NV03_FIFO_CMD_JUMP | + nmesa->fifo.drm.put_base); if(fifo_get <= RING_SKIPS) { if(nmesa->fifo.put <= RING_SKIPS) /* corner case - will be idle */ NV_FIFO_WRITE_PUT(RING_SKIPS + 1); @@ -98,54 +99,54 @@ void nouveauWaitForIdle(nouveauContextPtr nmesa) // here we call the fifo initialization ioctl and fill in stuff accordingly GLboolean nouveauFifoInit(nouveauContextPtr nmesa) { - drm_nouveau_fifo_alloc_t fifo_init; int i, ret; #ifdef NOUVEAU_RING_DEBUG return GL_TRUE; #endif - fifo_init.fb_ctxdma_handle = NvDmaFB; - fifo_init.tt_ctxdma_handle = NvDmaTT; - ret=drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_FIFO_ALLOC, &fifo_init, sizeof(fifo_init)); + nmesa->fifo.drm.fb_ctxdma_handle = NvDmaFB; + nmesa->fifo.drm.tt_ctxdma_handle = NvDmaTT; + ret = drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_CHANNEL_ALLOC, + &nmesa->fifo.drm, sizeof(nmesa->fifo.drm)); if (ret) { - FATAL("Fifo initialization ioctl failed (returned %d)\n",ret); + FATAL("Fifo initialization ioctl failed (returned %d)\n", ret); return GL_FALSE; } - ret = drmMap(nmesa->driFd, fifo_init.cmdbuf, fifo_init.cmdbuf_size, &nmesa->fifo.buffer); + ret = drmMap(nmesa->driFd, nmesa->fifo.drm.cmdbuf, + nmesa->fifo.drm.cmdbuf_size, &nmesa->fifo.pushbuf); if (ret) { - FATAL("Unable to map the fifo (returned %d)\n",ret); + FATAL("Unable to map the fifo (returned %d)\n", ret); return GL_FALSE; } - ret = drmMap(nmesa->driFd, fifo_init.ctrl, fifo_init.ctrl_size, &nmesa->fifo.mmio); + ret = drmMap(nmesa->driFd, nmesa->fifo.drm.ctrl, + nmesa->fifo.drm.ctrl_size, &nmesa->fifo.mmio); if (ret) { - FATAL("Unable to map the control regs (returned %d)\n",ret); + FATAL("Unable to map the control regs (returned %d)\n", ret); return GL_FALSE; } - ret = drmMap(nmesa->driFd, fifo_init.notifier, - fifo_init.notifier_size, - &nmesa->notifier_block); + ret = drmMap(nmesa->driFd, nmesa->fifo.drm.notifier, + nmesa->fifo.drm.notifier_size, + &nmesa->fifo.notifier_block); if (ret) { - FATAL("Unable to map the notifier block (returned %d)\n",ret); + FATAL("Unable to map the notifier block (returned %d)\n", ret); return GL_FALSE; } /* Setup our initial FIFO tracking params */ - nmesa->fifo.channel = fifo_init.channel; - nmesa->fifo.put_base = fifo_init.put_base; nmesa->fifo.current = 0; nmesa->fifo.put = 0; - nmesa->fifo.max = (fifo_init.cmdbuf_size >> 2) - 1; + nmesa->fifo.max = (nmesa->fifo.drm.cmdbuf_size >> 2) - 1; nmesa->fifo.free = nmesa->fifo.max - nmesa->fifo.current; for (i=0; i<RING_SKIPS; i++) OUT_RING(0); nmesa->fifo.free -= RING_SKIPS; - MESSAGE("Fifo init ok. Using context %d\n", fifo_init.channel); + MESSAGE("Fifo init ok. Using context %d\n", nmesa->fifo.drm.channel); return GL_TRUE; } diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fifo.h b/src/mesa/drivers/dri/nouveau/nouveau_fifo.h index 23325dcea5..956dd549dc 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_fifo.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_fifo.h @@ -48,14 +48,14 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV_FIFO_READ(reg) *(volatile u_int32_t *)(nmesa->fifo.mmio + (reg/4)) #define NV_FIFO_WRITE(reg,value) *(volatile u_int32_t *)(nmesa->fifo.mmio + (reg/4)) = value; -#define NV_FIFO_READ_GET() ((NV_FIFO_READ(NV03_FIFO_REGS_DMAGET) - nmesa->fifo.put_base) >> 2) +#define NV_FIFO_READ_GET() ((NV_FIFO_READ(NV03_FIFO_REGS_DMAGET) - nmesa->fifo.drm.put_base) >> 2) #define NV_FIFO_WRITE_PUT(val) do { \ if (NOUVEAU_RING_TRACE) {\ printf("FIRE_RING : 0x%08x\n", nmesa->fifo.current << 2); \ fflush(stdout); \ sleep(1); \ } \ - NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT, ((val)<<2) + nmesa->fifo.put_base); \ + NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT, ((val)<<2) + nmesa->fifo.drm.put_base); \ } while(0) /* @@ -110,20 +110,20 @@ nouveau_fifo_remaining-=sz; \ uint32_t* p=(uint32_t*)(ptr); \ int i; printf("OUT_RINGp: (size 0x%x dwords) (%s)\n",sz, __func__); for(i=0;i<sz;i++) printf(" [0x%08x] 0x%08x %f\n", (nmesa->fifo.current+i) << 2, *(p+i), *((float*)(p+i))); \ } \ - memcpy(nmesa->fifo.buffer+nmesa->fifo.current,ptr,(sz)*4); \ + memcpy(nmesa->fifo.pushbuf+nmesa->fifo.current,ptr,(sz)*4); \ nmesa->fifo.current+=(sz); \ }while(0) #define OUT_RING(n) do { \ if (NOUVEAU_RING_TRACE) \ printf("OUT_RINGn: [0x%08x] 0x%08x (%s)\n", nmesa->fifo.current << 2, n, __func__); \ -nmesa->fifo.buffer[nmesa->fifo.current++]=(n); \ +nmesa->fifo.pushbuf[nmesa->fifo.current++]=(n); \ }while(0) #define OUT_RINGf(n) do { \ if (NOUVEAU_RING_TRACE) \ printf("OUT_RINGf: [0x%08x] %.04f (%s)\n", nmesa->fifo.current << 2, n, __func__); \ -*((float*)(nmesa->fifo.buffer+nmesa->fifo.current++))=(n); \ +*((float*)(nmesa->fifo.pushbuf+nmesa->fifo.current++))=(n); \ }while(0) #define BEGIN_RING_SIZE(subchannel,tag,size) do { \ diff --git a/src/mesa/drivers/dri/nouveau/nouveau_lock.c b/src/mesa/drivers/dri/nouveau/nouveau_lock.c index c119d14dd7..aa86c9e783 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_lock.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_lock.c @@ -44,7 +44,7 @@ void nouveauGetLock( nouveauContextPtr nmesa, GLuint flags ) { __DRIdrawablePrivate *dPriv = nmesa->driDrawable; __DRIscreenPrivate *sPriv = nmesa->driScreen; - drm_nouveau_sarea_t *sarea = nmesa->sarea; + struct drm_nouveau_sarea *sarea = nmesa->sarea; drmGetLock( nmesa->driFd, nmesa->hHWContext, flags ); diff --git a/src/mesa/drivers/dri/nouveau/nouveau_mem.c b/src/mesa/drivers/dri/nouveau/nouveau_mem.c new file mode 100644 index 0000000000..35c53268b0 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_mem.c @@ -0,0 +1,144 @@ +#include "mtypes.h" + +#include "nouveau_context.h" +#include "nouveau_fifo.h" +#include "nouveau_mem.h" +#include "nouveau_msg.h" +#include "nouveau_object.h" +#include "nouveau_reg.h" + +#define MAX_MEMFMT_LENGTH 32768 + +/* Unstrided blit using NV_MEMORY_TO_MEMORY_FORMAT */ +GLboolean +nouveau_memformat_flat_emit(GLcontext * ctx, + nouveau_mem * dst, nouveau_mem * src, + GLuint dst_offset, GLuint src_offset, + GLuint size) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + uint32_t src_handle, dst_handle; + GLuint count; + + if (src_offset + size > src->size) { + MESSAGE("src out of nouveau_mem bounds\n"); + return GL_FALSE; + } + if (dst_offset + size > dst->size) { + MESSAGE("dst out of nouveau_mem bounds\n"); + return GL_FALSE; + } + + src_handle = (src->type & NOUVEAU_MEM_FB) ? NvDmaFB : NvDmaTT; + dst_handle = (dst->type & NOUVEAU_MEM_FB) ? NvDmaFB : NvDmaTT; + src_offset += nouveau_mem_gpu_offset_get(ctx, src); + dst_offset += nouveau_mem_gpu_offset_get(ctx, dst); + + BEGIN_RING_SIZE(NvSubMemFormat, + NV_MEMORY_TO_MEMORY_FORMAT_OBJECT_IN, 2); + OUT_RING(src_handle); + OUT_RING(dst_handle); + + count = (size / MAX_MEMFMT_LENGTH) + + ((size % MAX_MEMFMT_LENGTH) ? 1 : 0); + + while (count--) { + GLuint length = + (size > MAX_MEMFMT_LENGTH) ? MAX_MEMFMT_LENGTH : size; + + BEGIN_RING_SIZE(NvSubMemFormat, + NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); + OUT_RING(src_offset); + OUT_RING(dst_offset); + OUT_RING(0); /* pitch in */ + OUT_RING(0); /* pitch out */ + OUT_RING(length); /* line length */ + OUT_RING(1); /* number of lines */ + OUT_RING((1 << 8) /* dst_inc */ |(1 << 0) /* src_inc */ ); + OUT_RING(0); /* buffer notify? */ + FIRE_RING(); + + src_offset += length; + dst_offset += length; + size -= length; + } + + return GL_TRUE; +} + +void nouveau_mem_free(GLcontext * ctx, nouveau_mem * mem) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + struct drm_nouveau_mem_free memf; + + if (NOUVEAU_DEBUG & DEBUG_MEM) { + fprintf(stderr, "%s: type=0x%x, offset=0x%x, size=0x%x\n", + __func__, mem->type, (GLuint) mem->offset, + (GLuint) mem->size); + } + + if (mem->map) + drmUnmap(mem->map, mem->size); + memf.flags = mem->type; + memf.offset = mem->offset; + drmCommandWrite(nmesa->driFd, DRM_NOUVEAU_MEM_FREE, &memf, + sizeof(memf)); + FREE(mem); +} + +nouveau_mem *nouveau_mem_alloc(GLcontext *ctx, uint32_t flags, GLuint size, + GLuint align) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + struct drm_nouveau_mem_alloc mema; + nouveau_mem *mem; + int ret; + + if (NOUVEAU_DEBUG & DEBUG_MEM) { + fprintf(stderr, + "%s: requested: flags=0x%x, size=0x%x, align=0x%x\n", + __func__, flags, (GLuint) size, align); + } + + mem = CALLOC(sizeof(nouveau_mem)); + if (!mem) + return NULL; + + mema.flags = flags; + mema.size = mem->size = size; + mema.alignment = align; + mem->map = NULL; + ret = drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_MEM_ALLOC, + &mema, sizeof(mema)); + if (ret) { + FREE(mem); + return NULL; + } + mem->offset = mema.offset; + mem->type = mema.flags; + + if (NOUVEAU_DEBUG & DEBUG_MEM) { + fprintf(stderr, + "%s: actual: type=0x%x, offset=0x%x, size=0x%x\n", + __func__, mem->type, (GLuint) mem->offset, + (GLuint) mem->size); + } + + if (flags & NOUVEAU_MEM_MAPPED) + ret = drmMap(nmesa->driFd, mema.map_handle, mem->size, + &mem->map); + if (ret) { + mem->map = NULL; + nouveau_mem_free(ctx, mem); + mem = NULL; + } + + return mem; +} + +uint32_t nouveau_mem_gpu_offset_get(GLcontext * ctx, nouveau_mem * mem) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + + return mem->offset; +} diff --git a/src/mesa/drivers/dri/nouveau/nouveau_mem.h b/src/mesa/drivers/dri/nouveau/nouveau_mem.h new file mode 100644 index 0000000000..6db73f4708 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_mem.h @@ -0,0 +1,23 @@ +#ifndef __NOUVEAU_MEM_H__ +#define __NOUVEAU_MEM_H__ + +typedef struct nouveau_mem_t { + int type; + uint64_t offset; + uint64_t size; + void *map; +} nouveau_mem; + +extern nouveau_mem *nouveau_mem_alloc(GLcontext *, uint32_t flags, + GLuint size, GLuint align); +extern void nouveau_mem_free(GLcontext *, nouveau_mem *); +extern uint32_t nouveau_mem_gpu_offset_get(GLcontext *, nouveau_mem *); + +extern GLboolean nouveau_memformat_flat_emit(GLcontext *, + nouveau_mem *dst, + nouveau_mem *src, + GLuint dst_offset, + GLuint src_offset, + GLuint size); + +#endif diff --git a/src/mesa/drivers/dri/nouveau/nouveau_object.c b/src/mesa/drivers/dri/nouveau/nouveau_object.c index 69f8dbf794..4169530be6 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_object.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_object.c @@ -7,10 +7,10 @@ GLboolean nouveauCreateContextObject(nouveauContextPtr nmesa, uint32_t handle, int class) { - drm_nouveau_grobj_alloc_t cto; + struct drm_nouveau_grobj_alloc cto; int ret; - cto.channel = nmesa->fifo.channel; + cto.channel = nmesa->fifo.drm.channel; cto.handle = handle; cto.class = class; ret = drmCommandWrite(nmesa->driFd, DRM_NOUVEAU_GROBJ_ALLOC, @@ -34,15 +34,22 @@ void nouveauObjectInit(nouveauContextPtr nmesa) nouveauCreateContextObject(nmesa, Nv3D, nmesa->screen->card->class_3d); if (nmesa->screen->card->type>=NV_10) { nouveauCreateContextObject(nmesa, NvCtxSurf2D, NV10_CONTEXT_SURFACES_2D); - nouveauCreateContextObject(nmesa, NvImageBlit, NV10_IMAGE_BLIT); } else { nouveauCreateContextObject(nmesa, NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D); nouveauCreateContextObject(nmesa, NvCtxSurf3D, NV04_CONTEXT_SURFACES_3D); + } + if (nmesa->screen->card->type>=NV_11) { + nouveauCreateContextObject(nmesa, NvImageBlit, NV10_IMAGE_BLIT); + } else { nouveauCreateContextObject(nmesa, NvImageBlit, NV_IMAGE_BLIT); } + if ((nmesa->screen->card->type>=NV_10) && (nmesa->screen->card->type<NV_20)) { + nouveauCreateContextObject(nmesa, NvGdiRectText, NV04_GDI_RECTANGLE_TEXT); + nouveauCreateContextObject(nmesa, NvRasterOp, NV03_PRIMITIVE_RASTER_OP); + nouveauCreateContextObject(nmesa, NvPattern, NV04_IMAGE_PATTERN); + } nouveauCreateContextObject(nmesa, NvMemFormat, NV_MEMORY_TO_MEMORY_FORMAT); -#ifdef ALLOW_MULTI_SUBCHANNEL nouveauObjectOnSubchannel(nmesa, NvSubCtxSurf2D, NvCtxSurf2D); BEGIN_RING_SIZE(NvSubCtxSurf2D, NV10_CONTEXT_SURFACES_2D_SET_DMA_IN_MEMORY0, 2); OUT_RING(NvDmaFB); @@ -54,8 +61,35 @@ void nouveauObjectInit(nouveauContextPtr nmesa) BEGIN_RING_SIZE(NvSubImageBlit, NV10_IMAGE_BLIT_SET_OPERATION, 1); OUT_RING(3); /* SRCCOPY */ + if ((nmesa->screen->card->type>=NV_10) && (nmesa->screen->card->type<NV_20)) { + nouveauObjectOnSubchannel(nmesa, NvSubPattern, NvPattern); + + BEGIN_RING_SIZE(NvSubPattern, NV04_IMAGE_PATTERN_COLOR_FORMAT, 4); + OUT_RING(1); /* A16R5G6B5 */ + OUT_RING(1); /* little endian */ + OUT_RING(0); /* 8x8 */ + OUT_RING(1); /* monochrome */ + + nouveauObjectOnSubchannel(nmesa, NvSubRasterOp, NvRasterOp); + + BEGIN_RING_SIZE(NvSubRasterOp, NV03_PRIMITIVE_RASTER_OP_DMA_NOTIFY, 1); + OUT_RING(NvDmaFB); + + nouveauObjectOnSubchannel(nmesa, NvSubGdiRectText, NvGdiRectText); + + BEGIN_RING_SIZE(NvSubGdiRectText, NV04_GDI_RECTANGLE_TEXT_SET_DMA_NOTIFY, 1); + OUT_RING(NvDmaFB); + BEGIN_RING_SIZE(NvSubGdiRectText, NV04_GDI_RECTANGLE_TEXT_PATTERN, 2); + OUT_RING(NvPattern); + OUT_RING(NvRasterOp); + BEGIN_RING_SIZE(NvSubGdiRectText, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1); + OUT_RING(NvCtxSurf2D); + BEGIN_RING_SIZE(NvSubGdiRectText, NV04_GDI_RECTANGLE_TEXT_FORMAT, 2); + OUT_RING(1); /* X1R5G5B5 */ + OUT_RING(1); /* little endian */ + } + nouveauObjectOnSubchannel(nmesa, NvSubMemFormat, NvMemFormat); -#endif nouveauObjectOnSubchannel(nmesa, NvSub3D, Nv3D); } diff --git a/src/mesa/drivers/dri/nouveau/nouveau_object.h b/src/mesa/drivers/dri/nouveau/nouveau_object.h index 8c72d014da..10859de119 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_object.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_object.h @@ -3,8 +3,6 @@ #include "nouveau_context.h" -#define ALLOW_MULTI_SUBCHANNEL - void nouveauObjectInit(nouveauContextPtr nmesa); enum DMAObjects { @@ -13,6 +11,9 @@ enum DMAObjects { NvImageBlit = 0x80000021, NvMemFormat = 0x80000022, NvCtxSurf3D = 0x80000023, + NvGdiRectText = 0x80000024, + NvPattern = 0x80000025, + NvRasterOp = 0x80000026, NvDmaFB = 0xD0FB0001, NvDmaTT = 0xD0AA0001, NvSyncNotify = 0xD0000001, @@ -24,6 +25,9 @@ enum DMASubchannel { NvSubImageBlit = 1, NvSubMemFormat = 2, NvSubCtxSurf3D = 3, + NvSubGdiRectText= 4, + NvSubPattern = 5, + NvSubRasterOp = 6, NvSub3D = 7, }; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_query.c b/src/mesa/drivers/dri/nouveau/nouveau_query.c index 0154140069..e5c1750a8e 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_query.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_query.c @@ -167,7 +167,8 @@ nouveauQueryInitFuncs(GLcontext *ctx) if (nmesa->screen->card->type < NV_20) return; - nmesa->query_object_max = (0x4000 / 32); + /* Reserve half the notifier block for use as query objects */ + nmesa->query_object_max = (nmesa->fifo.drm.notifier_size / 2) / 32; nmesa->queryNotifier = nouveau_notifier_new(ctx, NvQueryNotify, nmesa->query_object_max); diff --git a/src/mesa/drivers/dri/nouveau/nouveau_screen.c b/src/mesa/drivers/dri/nouveau/nouveau_screen.c index bc7f39b042..065aa81746 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_screen.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_screen.c @@ -132,10 +132,11 @@ nouveauCreateBuffer(__DRIscreenPrivate *driScrnPriv, GLboolean isPixmap) { nouveauScreenPtr screen = (nouveauScreenPtr) driScrnPriv->private; - nouveau_renderbuffer *nrb; + nouveau_renderbuffer_t *nrb; struct gl_framebuffer *fb; const GLboolean swAccum = mesaVis->accumRedBits > 0; - const GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24; + const GLboolean swStencil = (mesaVis->stencilBits > 0 && + mesaVis->depthBits != 24); GLenum color_format = screen->fbFormat == 4 ? GL_RGBA8 : GL_RGB5; if (isPixmap) @@ -146,44 +147,26 @@ nouveauCreateBuffer(__DRIscreenPrivate *driScrnPriv, return GL_FALSE; /* Front buffer */ - nrb = nouveau_renderbuffer_new(color_format, - driScrnPriv->pFB + screen->frontOffset, - screen->frontOffset, - screen->frontPitch * screen->fbFormat, - driDrawPriv); - nouveauSpanSetFunctions(nrb, mesaVis); + nrb = nouveau_renderbuffer_new(color_format); _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &nrb->mesa); - if (0 /* unified buffers if we choose to support them.. */) { - } else { - if (mesaVis->doubleBufferMode) { - nrb = nouveau_renderbuffer_new(color_format, NULL, - 0, 0, - NULL); - nouveauSpanSetFunctions(nrb, mesaVis); - _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &nrb->mesa); - } + if (mesaVis->doubleBufferMode) { + nrb = nouveau_renderbuffer_new(color_format); + _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &nrb->mesa); + } - if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) { - nrb = nouveau_renderbuffer_new(GL_DEPTH24_STENCIL8_EXT, NULL, - 0, 0, - NULL); - nouveauSpanSetFunctions(nrb, mesaVis); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa); - _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &nrb->mesa); - } else if (mesaVis->depthBits == 24) { - nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT24, NULL, - 0, 0, - NULL); - nouveauSpanSetFunctions(nrb, mesaVis); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa); - } else if (mesaVis->depthBits == 16) { - nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT16, NULL, - 0, 0, - NULL); - nouveauSpanSetFunctions(nrb, mesaVis); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa); - } + if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) { + nrb = nouveau_renderbuffer_new(GL_DEPTH24_STENCIL8_EXT); + _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa); + _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &nrb->mesa); + } else + if (mesaVis->depthBits == 24) { + nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT24); + _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa); + } else + if (mesaVis->depthBits == 16) { + nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT16); + _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa); } _mesa_add_soft_renderbuffers(fb, @@ -328,7 +311,7 @@ void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn, __DRIsc static const __DRIversion ddx_expected = { 1, 2, 0 }; static const __DRIversion dri_expected = { 4, 0, 0 }; static const __DRIversion drm_expected = { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL }; -#if NOUVEAU_DRM_HEADER_PATCHLEVEL != 7 +#if NOUVEAU_DRM_HEADER_PATCHLEVEL != 10 #error nouveau_drm.h version doesn't match expected version #endif dri_interface = interface; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_span.c b/src/mesa/drivers/dri/nouveau/nouveau_span.c index 6e3f9fadf4..d62830ff53 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_span.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_span.c @@ -37,8 +37,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #define HAVE_HW_STENCIL_SPANS 0 #define HAVE_HW_STENCIL_PIXELS 0 -static char *fake_span[1280*1024*4]; - #define HW_CLIPLOOP() \ do { \ int _nc = nmesa->numClipRects; \ @@ -50,11 +48,10 @@ static char *fake_span[1280*1024*4]; #define LOCAL_VARS \ nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); \ - nouveau_renderbuffer *nrb = (nouveau_renderbuffer *)rb; \ + nouveau_renderbuffer_t *nrb = (nouveau_renderbuffer_t *)rb; \ GLuint height = nrb->mesa.Height; \ GLubyte *map = (GLubyte *)(nrb->map ? nrb->map : nrb->mem->map) + \ (nmesa->drawY * nrb->pitch) + (nmesa->drawX * nrb->cpp); \ - map = fake_span; \ GLuint p; \ (void) p; @@ -70,7 +67,7 @@ static char *fake_span[1280*1024*4]; * Color buffers */ -/* RGB565 */ +/* RGB565 */ #define SPANTMP_PIXEL_FMT GL_RGB #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5 @@ -89,40 +86,38 @@ static char *fake_span[1280*1024*4]; #define GET_PTR(X,Y) (map + (Y)*nrb->pitch + (X)*nrb->cpp) #include "spantmp2.h" -static void -nouveauSpanRenderStart( GLcontext *ctx ) +static void nouveauSpanRenderStart(GLcontext * ctx) { - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - FIRE_RING(); - LOCK_HARDWARE(nmesa); - nouveauWaitForIdleLocked( nmesa ); + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + FIRE_RING(); + LOCK_HARDWARE(nmesa); + nouveauWaitForIdleLocked(nmesa); } -static void -nouveauSpanRenderFinish( GLcontext *ctx ) +static void nouveauSpanRenderFinish(GLcontext * ctx) { - nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - _swrast_flush( ctx ); - nouveauWaitForIdleLocked( nmesa ); - UNLOCK_HARDWARE( nmesa ); + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + _swrast_flush(ctx); + nouveauWaitForIdleLocked(nmesa); + UNLOCK_HARDWARE(nmesa); } -void nouveauSpanInitFunctions( GLcontext *ctx ) +void nouveauSpanInitFunctions(GLcontext * ctx) { - struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx); - swdd->SpanRenderStart = nouveauSpanRenderStart; - swdd->SpanRenderFinish = nouveauSpanRenderFinish; + struct swrast_device_driver *swdd = + _swrast_GetDeviceDriverReference(ctx); + swdd->SpanRenderStart = nouveauSpanRenderStart; + swdd->SpanRenderFinish = nouveauSpanRenderFinish; } /** * Plug in the Get/Put routines for the given driRenderbuffer. */ -void -nouveauSpanSetFunctions(nouveau_renderbuffer *nrb, const GLvisual *vis) +void nouveauSpanSetFunctions(nouveau_renderbuffer_t * nrb) { - if (nrb->mesa._ActualFormat == GL_RGBA8) - nouveauInitPointers_ARGB8888(&nrb->mesa); - else // if (nrb->mesa._ActualFormat == GL_RGB5) - nouveauInitPointers_RGB565(&nrb->mesa); + if (nrb->mesa._ActualFormat == GL_RGBA8) + nouveauInitPointers_ARGB8888(&nrb->mesa); + else // if (nrb->mesa._ActualFormat == GL_RGB5) + nouveauInitPointers_RGB565(&nrb->mesa); } diff --git a/src/mesa/drivers/dri/nouveau/nouveau_span.h b/src/mesa/drivers/dri/nouveau/nouveau_span.h index bc39ecd17b..d3f31c9cb2 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_span.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_span.h @@ -30,10 +30,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #define __NOUVEAU_SPAN_H__ #include "drirenderbuffer.h" -#include "nouveau_buffers.h" +#include "nouveau_fbo.h" -extern void nouveauSpanInitFunctions( GLcontext *ctx ); -extern void nouveauSpanSetFunctions(nouveau_renderbuffer *nrb, const GLvisual *vis); +extern void nouveauSpanInitFunctions(GLcontext *ctx); +extern void nouveauSpanSetFunctions(nouveau_renderbuffer_t *nrb); #endif /* __NOUVEAU_SPAN_H__ */ diff --git a/src/mesa/drivers/dri/nouveau/nouveau_state.c b/src/mesa/drivers/dri/nouveau/nouveau_state.c index 7cb805902a..f618dcfc99 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_state.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_state.c @@ -162,6 +162,8 @@ void nouveauDDInitState(nouveauContextPtr nmesa) nv04InitStateFuncs(nmesa->glCtx, &nmesa->glCtx->Driver); break; case NV_10: + case NV_11: + case NV_17: nv10InitStateFuncs(nmesa->glCtx, &nmesa->glCtx->Driver); break; case NV_20: diff --git a/src/mesa/drivers/dri/nouveau/nouveau_sync.c b/src/mesa/drivers/dri/nouveau/nouveau_sync.c index 1d1eeede18..2ca038f4f8 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_sync.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_sync.c @@ -28,36 +28,36 @@ #include "vblank.h" /* for DO_USLEEP */ #include "nouveau_context.h" -#include "nouveau_buffers.h" -#include "nouveau_object.h" #include "nouveau_fifo.h" -#include "nouveau_reg.h" +#include "nouveau_mem.h" #include "nouveau_msg.h" +#include "nouveau_object.h" +#include "nouveau_reg.h" #include "nouveau_sync.h" #define NOTIFIER(__v) \ nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); \ - volatile uint32_t *__v = (void*)nmesa->notifier_block + notifier->offset + volatile uint32_t *__v = (void*)nmesa->fifo.notifier_block + \ + notifier->offset -drm_nouveau_notifier_alloc_t * +struct drm_nouveau_notifierobj_alloc * nouveau_notifier_new(GLcontext *ctx, GLuint handle, GLuint count) { nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); - drm_nouveau_notifier_alloc_t *notifier; + struct drm_nouveau_notifierobj_alloc *notifier; int ret; #ifdef NOUVEAU_RING_DEBUG return NULL; #endif - - notifier = CALLOC_STRUCT(drm_nouveau_notifier_alloc); + notifier = CALLOC_STRUCT(drm_nouveau_notifierobj_alloc); if (!notifier) return NULL; - notifier->channel = nmesa->fifo.channel; + notifier->channel = nmesa->fifo.drm.channel; notifier->handle = handle; notifier->count = count; - ret = drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_NOTIFIER_ALLOC, + ret = drmCommandWriteRead(nmesa->driFd, DRM_NOUVEAU_NOTIFIEROBJ_ALLOC, notifier, sizeof(*notifier)); if (ret) { MESSAGE("Failed to create notifier 0x%08x: %d\n", handle, ret); @@ -69,14 +69,16 @@ nouveau_notifier_new(GLcontext *ctx, GLuint handle, GLuint count) } void -nouveau_notifier_destroy(GLcontext *ctx, drm_nouveau_notifier_alloc_t *notifier) +nouveau_notifier_destroy(GLcontext *ctx, + struct drm_nouveau_notifierobj_alloc *notifier) { /*XXX: free notifier object.. */ FREE(notifier); } void -nouveau_notifier_reset(GLcontext *ctx, drm_nouveau_notifier_alloc_t *notifier, +nouveau_notifier_reset(GLcontext *ctx, + struct drm_nouveau_notifierobj_alloc *notifier, GLuint id) { NOTIFIER(n); @@ -93,7 +95,8 @@ nouveau_notifier_reset(GLcontext *ctx, drm_nouveau_notifier_alloc_t *notifier, } GLuint -nouveau_notifier_status(GLcontext *ctx, drm_nouveau_notifier_alloc_t *notifier, +nouveau_notifier_status(GLcontext *ctx, + struct drm_nouveau_notifierobj_alloc *notifier, GLuint id) { NOTIFIER(n); @@ -103,7 +106,8 @@ nouveau_notifier_status(GLcontext *ctx, drm_nouveau_notifier_alloc_t *notifier, GLuint nouveau_notifier_return_val(GLcontext *ctx, - drm_nouveau_notifier_alloc_t *notifier, GLuint id) + struct drm_nouveau_notifierobj_alloc *notifier, + GLuint id) { NOTIFIER(n); @@ -112,8 +116,8 @@ nouveau_notifier_return_val(GLcontext *ctx, GLboolean nouveau_notifier_wait_status(GLcontext *ctx, - drm_nouveau_notifier_alloc_t *notifier, GLuint id, - GLuint status, GLuint timeout) + struct drm_nouveau_notifierobj_alloc *notifier, + GLuint id, GLuint status, GLuint timeout) { NOTIFIER(n); unsigned int time = 0; @@ -146,7 +150,8 @@ nouveau_notifier_wait_status(GLcontext *ctx, void nouveau_notifier_wait_nop(GLcontext *ctx, - drm_nouveau_notifier_alloc_t *notifier, GLuint subc) + struct drm_nouveau_notifierobj_alloc *notifier, + GLuint subc) { NOTIFIER(n); GLboolean ret; @@ -184,11 +189,9 @@ GLboolean nouveauSyncInitFuncs(GLcontext *ctx) */ BEGIN_RING_CACHE(NvSub3D, 0x180, 1); OUT_RING_CACHE (NvSyncNotify); -#ifdef ALLOW_MULTI_SUBCHANNEL BEGIN_RING_SIZE(NvSubMemFormat, NV_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1); OUT_RING (NvSyncNotify); -#endif return GL_TRUE; } diff --git a/src/mesa/drivers/dri/nouveau/nouveau_sync.h b/src/mesa/drivers/dri/nouveau/nouveau_sync.h index b56cc5fb54..fc37efbe6b 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_sync.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_sync.h @@ -28,8 +28,6 @@ #ifndef __NOUVEAU_SYNC_H__ #define __NOUVEAU_SYNC_H__ -#include "nouveau_buffers.h" - #define NV_NOTIFIER_SIZE 32 #define NV_NOTIFY_TIME_0 0x00000000 #define NV_NOTIFY_TIME_1 0x00000004 @@ -47,22 +45,24 @@ #define NV_NOTIFY 0x00000104 #define NV_NOTIFY_STYLE_WRITE_ONLY 0 -extern drm_nouveau_notifier_alloc_t * +extern struct drm_nouveau_notifierobj_alloc * nouveau_notifier_new(GLcontext *, GLuint handle, GLuint count); extern void -nouveau_notifier_destroy(GLcontext *, drm_nouveau_notifier_alloc_t *); +nouveau_notifier_destroy(GLcontext *, struct drm_nouveau_notifierobj_alloc *); extern void -nouveau_notifier_reset(GLcontext *, drm_nouveau_notifier_alloc_t *, GLuint id); +nouveau_notifier_reset(GLcontext *, struct drm_nouveau_notifierobj_alloc *, + GLuint id); extern GLuint -nouveau_notifier_status(GLcontext *, drm_nouveau_notifier_alloc_t *, GLuint id); +nouveau_notifier_status(GLcontext *, struct drm_nouveau_notifierobj_alloc *, + GLuint id); extern GLuint -nouveau_notifier_return_val(GLcontext *, drm_nouveau_notifier_alloc_t *, +nouveau_notifier_return_val(GLcontext *, struct drm_nouveau_notifierobj_alloc *, GLuint id); extern GLboolean -nouveau_notifier_wait_status(GLcontext *, drm_nouveau_notifier_alloc_t *, +nouveau_notifier_wait_status(GLcontext *, struct drm_nouveau_notifierobj_alloc *, GLuint id, GLuint status, GLuint timeout); extern void -nouveau_notifier_wait_nop(GLcontext *ctx, drm_nouveau_notifier_alloc_t *, +nouveau_notifier_wait_nop(GLcontext *ctx, struct drm_nouveau_notifierobj_alloc *, GLuint subc); extern GLboolean nouveauSyncInitFuncs(GLcontext *ctx); diff --git a/src/mesa/drivers/dri/nouveau/nv04_state.c b/src/mesa/drivers/dri/nouveau/nv04_state.c index 25df3d2a62..d3031aa5b1 100644 --- a/src/mesa/drivers/dri/nouveau/nv04_state.c +++ b/src/mesa/drivers/dri/nouveau/nv04_state.c @@ -451,8 +451,8 @@ static GLboolean nv04InitCard(nouveauContextPtr nmesa) /* Update buffer offset/pitch/format */ static GLboolean nv04BindBuffers(nouveauContextPtr nmesa, int num_color, - nouveau_renderbuffer **color, - nouveau_renderbuffer *depth) + nouveau_renderbuffer_t **color, + nouveau_renderbuffer_t *depth) { GLuint x, y, w, h; uint32_t depth_pitch=(depth?depth->pitch:0+15)&~15+16; diff --git a/src/mesa/drivers/dri/nouveau/nv10_state.c b/src/mesa/drivers/dri/nouveau/nv10_state.c index 5f304ccab9..4a3646ea4f 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_state.c +++ b/src/mesa/drivers/dri/nouveau/nv10_state.c @@ -111,9 +111,62 @@ static void nv10BlendFuncSeparate(GLcontext *ctx, GLenum sfactorRGB, GLenum dfac OUT_RING_CACHE(dfactorRGB); } +static void nv10ClearBuffer(GLcontext *ctx, nouveau_renderbuffer_t *buffer, int fill, int mask) +{ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + int dimensions; + + if (!buffer) { + return; + } + + /* Surface that we will work on */ + nouveauObjectOnSubchannel(nmesa, NvSubCtxSurf2D, NvCtxSurf2D); + + BEGIN_RING_SIZE(NvSubCtxSurf2D, NV10_CONTEXT_SURFACES_2D_FORMAT, 4); + OUT_RING(0x0b); /* Y32 color format */ + OUT_RING((buffer->pitch<<16)|buffer->pitch); + OUT_RING(buffer->offset); + OUT_RING(buffer->offset); + + /* Now clear a rectangle */ + dimensions = ((buffer->mesa.Height)<<16) | (buffer->mesa.Width); + + nouveauObjectOnSubchannel(nmesa, NvSubGdiRectText, NvGdiRectText); + + BEGIN_RING_SIZE(NvSubGdiRectText, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1); + OUT_RING(3); /* SRCCOPY */ + + BEGIN_RING_SIZE(NvSubGdiRectText, NV04_GDI_RECTANGLE_TEXT_BLOCK_LEVEL1_TL, 5); + OUT_RING(0); /* top left */ + OUT_RING(dimensions); /* bottom right */ + OUT_RING(fill); + OUT_RING(0); /* top left */ + OUT_RING(dimensions); /* bottom right */ +} + static void nv10Clear(GLcontext *ctx, GLbitfield mask) { - /* TODO */ + nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); + + if (mask & (BUFFER_BIT_FRONT_LEFT)) { + nv10ClearBuffer(ctx, nmesa->color_buffer[0], + nmesa->clear_color_value, 0xffffffff); + } + if (mask & (BUFFER_BIT_BACK_LEFT)) { + nv10ClearBuffer(ctx, nmesa->color_buffer[1], + nmesa->clear_color_value, 0xffffffff); + } + /* FIXME: check depth bits */ + if (mask & (BUFFER_BIT_DEPTH)) { + nv10ClearBuffer(ctx, nmesa->depth_buffer, + nmesa->clear_value, 0xffffff00); + } + /* FIXME: check about stencil? */ + if (mask & (BUFFER_BIT_STENCIL)) { + nv10ClearBuffer(ctx, nmesa->depth_buffer, + nmesa->clear_value, 0x000000ff); + } } static void nv10ClearColor(GLcontext *ctx, const GLfloat color[4]) @@ -697,8 +750,7 @@ static GLboolean nv10InitCard(nouveauContextPtr nmesa) BEGIN_RING_SIZE(NvSub3D, 0x03f4, 1); OUT_RING(0); - /* not for nv10, only for >= nv11 */ - if ((nmesa->screen->card->id>>4) >= 0x11) { + if (nmesa->screen->card->type >= NV_11) { BEGIN_RING_SIZE(NvSub3D, 0x120, 3); OUT_RING(0); OUT_RING(1); @@ -710,12 +762,17 @@ static GLboolean nv10InitCard(nouveauContextPtr nmesa) /* Update buffer offset/pitch/format */ static GLboolean nv10BindBuffers(nouveauContextPtr nmesa, int num_color, - nouveau_renderbuffer **color, - nouveau_renderbuffer *depth) + nouveau_renderbuffer_t **color, + nouveau_renderbuffer_t *depth) { GLuint x, y, w, h; GLuint pitch, format, depth_pitch; + /* Store buffer pointers in context */ + nmesa->color_buffer[0] = color[0]; + nmesa->color_buffer[1] = color[1]; + nmesa->depth_buffer = depth; + w = color[0]->mesa.Width; h = color[0]->mesa.Height; x = nmesa->drawX; @@ -739,11 +796,11 @@ static GLboolean nv10BindBuffers(nouveauContextPtr nmesa, int num_color, OUT_RING_CACHE(depth ? depth->offset : color[0]->offset); /* Always set to bottom left of buffer */ - BEGIN_RING_CACHE(NvSub3D, NV10_TCL_PRIMITIVE_3D_VIEWPORT_ORIGIN_X, 4); + /*BEGIN_RING_CACHE(NvSub3D, NV10_TCL_PRIMITIVE_3D_VIEWPORT_ORIGIN_X, 4); OUT_RING_CACHEf (0.0); OUT_RING_CACHEf ((GLfloat) h); OUT_RING_CACHEf (0.0); - OUT_RING_CACHEf (0.0); + OUT_RING_CACHEf (0.0);*/ return GL_TRUE; } diff --git a/src/mesa/drivers/dri/nouveau/nv10_swtcl.c b/src/mesa/drivers/dri/nouveau/nv10_swtcl.c index 4576c1ede4..611469b6e4 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_swtcl.c +++ b/src/mesa/drivers/dri/nouveau/nv10_swtcl.c @@ -58,7 +58,7 @@ static void nv10ResetLineStipple( GLcontext *ctx ); static inline void nv10StartPrimitive(struct nouveau_context* nmesa,uint32_t primitive,uint32_t size) { - if (nmesa->screen->card->type==NV_10) + if ((nmesa->screen->card->type>=NV_10) && (nmesa->screen->card->type<=NV_17)) BEGIN_RING_SIZE(NvSub3D,NV10_TCL_PRIMITIVE_3D_BEGIN_END,1); else if (nmesa->screen->card->type==NV_20) BEGIN_RING_SIZE(NvSub3D,NV20_TCL_PRIMITIVE_3D_BEGIN_END,1); @@ -66,7 +66,7 @@ static inline void nv10StartPrimitive(struct nouveau_context* nmesa,uint32_t pri BEGIN_RING_SIZE(NvSub3D,NV30_TCL_PRIMITIVE_3D_BEGIN_END,1); OUT_RING(primitive); - if (nmesa->screen->card->type==NV_10) + if ((nmesa->screen->card->type>=NV_10) && (nmesa->screen->card->type<=NV_17)) BEGIN_RING_SIZE(NvSub3D,NV10_TCL_PRIMITIVE_3D_VERTEX_ARRAY_DATA|NONINC_METHOD,size); else if (nmesa->screen->card->type==NV_20) BEGIN_RING_SIZE(NvSub3D,NV20_TCL_PRIMITIVE_3D_VERTEX_DATA|NONINC_METHOD,size); @@ -76,7 +76,7 @@ static inline void nv10StartPrimitive(struct nouveau_context* nmesa,uint32_t pri inline void nv10FinishPrimitive(struct nouveau_context *nmesa) { - if (nmesa->screen->card->type==NV_10) + if ((nmesa->screen->card->type>=NV_10) && (nmesa->screen->card->type<=NV_17)) BEGIN_RING_SIZE(NvSub3D,NV10_TCL_PRIMITIVE_3D_BEGIN_END,1); else if (nmesa->screen->card->type==NV_20) BEGIN_RING_SIZE(NvSub3D,NV20_TCL_PRIMITIVE_3D_BEGIN_END,1); @@ -454,7 +454,7 @@ static inline void nv10OutputVertexFormat(struct nouveau_context* nmesa) /* * Tell the hardware about the vertex format */ - if (nmesa->screen->card->type==NV_10) { + if ((nmesa->screen->card->type>=NV_10) && (nmesa->screen->card->type<=NV_17)) { int size; #define NV_VERTEX_ATTRIBUTE_TYPE_FLOAT 2 diff --git a/src/mesa/drivers/dri/nouveau/nv20_state.c b/src/mesa/drivers/dri/nouveau/nv20_state.c index 3d8d83a865..6b583980a4 100644 --- a/src/mesa/drivers/dri/nouveau/nv20_state.c +++ b/src/mesa/drivers/dri/nouveau/nv20_state.c @@ -568,10 +568,10 @@ static void nv20Scissor(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) y += nmesa->drawY; } - BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_SCISSOR_X2_X1, 1); + /*BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_SCISSOR_X2_X1, 1); OUT_RING_CACHE((w << 16) | x ); BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_SCISSOR_Y2_Y1, 1); - OUT_RING_CACHE((h << 16) | y ); + OUT_RING_CACHE((h << 16) | y );*/ } @@ -728,8 +728,8 @@ static GLboolean nv20InitCard(nouveauContextPtr nmesa) /* Update buffer offset/pitch/format */ static GLboolean nv20BindBuffers(nouveauContextPtr nmesa, int num_color, - nouveau_renderbuffer **color, - nouveau_renderbuffer *depth) + nouveau_renderbuffer_t **color, + nouveau_renderbuffer_t *depth) { GLuint x, y, w, h; GLuint pitch, format, depth_pitch; @@ -764,11 +764,11 @@ static GLboolean nv20BindBuffers(nouveauContextPtr nmesa, int num_color, } /* Always set to bottom left of buffer */ - BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_VIEWPORT_ORIGIN_X, 4); + /*BEGIN_RING_CACHE(NvSub3D, NV20_TCL_PRIMITIVE_3D_VIEWPORT_ORIGIN_X, 4); OUT_RING_CACHEf (0.0); OUT_RING_CACHEf ((GLfloat) h); OUT_RING_CACHEf (0.0); - OUT_RING_CACHEf (0.0); + OUT_RING_CACHEf (0.0);*/ return GL_TRUE; } diff --git a/src/mesa/drivers/dri/nouveau/nv30_state.c b/src/mesa/drivers/dri/nouveau/nv30_state.c index 9b010954b3..cd3ee98688 100644 --- a/src/mesa/drivers/dri/nouveau/nv30_state.c +++ b/src/mesa/drivers/dri/nouveau/nv30_state.c @@ -905,9 +905,9 @@ static GLboolean nv40InitCard(nouveauContextPtr nmesa) return GL_TRUE; } -static GLboolean nv30BindBuffers(nouveauContextPtr nmesa, int num_color, - nouveau_renderbuffer **color, - nouveau_renderbuffer *depth) +static GLboolean +nv30BindBuffers(nouveauContextPtr nmesa, int num_color, + nouveau_renderbuffer_t **color, nouveau_renderbuffer_t *depth) { GLuint x, y, w, h; diff --git a/src/mesa/drivers/dri/nouveau/nv50_state.c b/src/mesa/drivers/dri/nouveau/nv50_state.c index 818e268615..a9236f093c 100644 --- a/src/mesa/drivers/dri/nouveau/nv50_state.c +++ b/src/mesa/drivers/dri/nouveau/nv50_state.c @@ -584,9 +584,9 @@ static GLboolean nv50InitCard(nouveauContextPtr nmesa) return GL_FALSE; } -static GLboolean nv50BindBuffers(nouveauContextPtr nmesa, int num_color, - nouveau_renderbuffer **color, - nouveau_renderbuffer *depth) +static GLboolean +nv50BindBuffers(nouveauContextPtr nmesa, int num_color, + nouveau_renderbuffer_t **color, nouveau_renderbuffer_t *depth) { return GL_FALSE; } diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c index 2115799b9b..1d975ecd57 100644 --- a/src/mesa/drivers/dri/r200/r200_state.c +++ b/src/mesa/drivers/dri/r200/r200_state.c @@ -772,9 +772,11 @@ static void r200LineWidth( GLcontext *ctx, GLfloat widthf ) R200_STATECHANGE( rmesa, set ); /* Line width is stored in U6.4 format. + * Same min/max limits for AA, non-AA lines. */ rmesa->hw.lin.cmd[LIN_SE_LINE_WIDTH] &= ~0xffff; - rmesa->hw.lin.cmd[LIN_SE_LINE_WIDTH] |= (GLuint)(ctx->Line._Width * 16.0); + rmesa->hw.lin.cmd[LIN_SE_LINE_WIDTH] |= (GLuint) + (CLAMP(widthf, ctx->Const.MinLineWidth, ctx->Const.MaxLineWidth) * 16.0); if ( widthf > 1.0 ) { rmesa->hw.set.cmd[SET_SE_CNTL] |= R200_WIDELINE_ENABLE; diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h index 6615bc79fb..be6909724a 100644 --- a/src/mesa/drivers/dri/r300/r300_context.h +++ b/src/mesa/drivers/dri/r300/r300_context.h @@ -568,19 +568,10 @@ struct r300_vertex_shader_fragment { union { GLuint d[VSF_MAX_FRAGMENT_LENGTH]; float f[VSF_MAX_FRAGMENT_LENGTH]; - VERTEX_SHADER_INSTRUCTION i[VSF_MAX_FRAGMENT_LENGTH / 4]; + GLuint i[VSF_MAX_FRAGMENT_LENGTH]; } body; }; -#define VSF_DEST_PROGRAM 0x0 -#define VSF_DEST_MATRIX0 0x200 -#define VSF_DEST_MATRIX1 0x204 -#define VSF_DEST_MATRIX2 0x208 -#define VSF_DEST_VECTOR0 0x20c -#define VSF_DEST_VECTOR1 0x20d -#define VSF_DEST_UNKNOWN1 0x400 -#define VSF_DEST_UNKNOWN2 0x406 - struct r300_vertex_shader_state { struct r300_vertex_shader_fragment program; }; diff --git a/src/mesa/drivers/dri/r300/r300_emit.c b/src/mesa/drivers/dri/r300/r300_emit.c index 229439dfa8..424bf44e59 100644 --- a/src/mesa/drivers/dri/r300/r300_emit.c +++ b/src/mesa/drivers/dri/r300/r300_emit.c @@ -299,13 +299,14 @@ GLuint r300VAPOutputCntl0(GLcontext * ctx, GLuint OutputsWritten) if (OutputsWritten & (1 << VERT_RESULT_COL1)) ret |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT; -#if 0 - if (OutputsWritten & (1 << VERT_RESULT_BFC0)) - ret |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT; - - if (OutputsWritten & (1 << VERT_RESULT_BFC1)) - ret |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT; + if (OutputsWritten & (1 << VERT_RESULT_BFC0) + || OutputsWritten & (1 << VERT_RESULT_BFC1)) + ret |= + R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT | + R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT | + R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT; +#if 0 if (OutputsWritten & (1 << VERT_RESULT_FOGC)) ; #endif diff --git a/src/mesa/drivers/dri/r300/r300_reg.h b/src/mesa/drivers/dri/r300/r300_reg.h index e59919be49..1baa74c526 100644 --- a/src/mesa/drivers/dri/r300/r300_reg.h +++ b/src/mesa/drivers/dri/r300/r300_reg.h @@ -282,9 +282,32 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define R300_VAP_PVS_UPLOAD_ADDRESS 0x2200 # define R300_PVS_UPLOAD_PROGRAM 0x00000000 +/* gap */ # define R300_PVS_UPLOAD_PARAMETERS 0x00000200 +/* gap */ +# define R300_PVS_UPLOAD_CLIP_PLANE0 0x00000400 +# define R300_PVS_UPLOAD_CLIP_PLANE1 0x00000401 +# define R300_PVS_UPLOAD_CLIP_PLANE2 0x00000402 +# define R300_PVS_UPLOAD_CLIP_PLANE3 0x00000403 +# define R300_PVS_UPLOAD_CLIP_PLANE4 0x00000404 +# define R300_PVS_UPLOAD_CLIP_PLANE5 0x00000405 # define R300_PVS_UPLOAD_POINTSIZE 0x00000406 +/* + * These are obsolete defines form r300_context.h, but they might give some + * clues when investigating the addresses further... + */ +#if 0 +#define VSF_DEST_PROGRAM 0x0 +#define VSF_DEST_MATRIX0 0x200 +#define VSF_DEST_MATRIX1 0x204 +#define VSF_DEST_MATRIX2 0x208 +#define VSF_DEST_VECTOR0 0x20c +#define VSF_DEST_VECTOR1 0x20d +#define VSF_DEST_UNKNOWN1 0x400 +#define VSF_DEST_UNKNOWN2 0x406 +#endif + /* gap */ #define R300_VAP_PVS_UPLOAD_DATA 0x2208 diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index b5cf21d644..088216c76e 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -82,6 +82,8 @@ static void r300BlendColor(GLcontext * ctx, const GLfloat cf[4]) rmesa->hw.blend_color.cmd[1] = PACK_COLOR_8888(color[3], color[0], color[1], color[2]); + rmesa->hw.blend_color.cmd[2] = 0; + rmesa->hw.blend_color.cmd[3] = 0; } /** @@ -317,20 +319,34 @@ static void r300UpdateCulling(GLcontext * ctx) r300ContextPtr r300 = R300_CONTEXT(ctx); uint32_t val = 0; - R300_STATECHANGE(r300, cul); if (ctx->Polygon.CullFlag) { - if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) - val = R300_CULL_FRONT | R300_CULL_BACK; - else if (ctx->Polygon.CullFaceMode == GL_FRONT) + switch (ctx->Polygon.CullFaceMode) { + case GL_FRONT: val = R300_CULL_FRONT; - else + break; + case GL_BACK: val = R300_CULL_BACK; + break; + case GL_FRONT_AND_BACK: + val = R300_CULL_FRONT | R300_CULL_BACK; + break; + default: + break; + } + } - if (ctx->Polygon.FrontFace == GL_CW) - val |= R300_FRONT_FACE_CW; - else - val |= R300_FRONT_FACE_CCW; + switch (ctx->Polygon.FrontFace) { + case GL_CW: + val |= R300_FRONT_FACE_CW; + break; + case GL_CCW: + val |= R300_FRONT_FACE_CCW; + break; + default: + break; } + + R300_STATECHANGE(r300, cul); r300->hw.cul.cmd[R300_CUL_CULL] = val; } @@ -344,6 +360,20 @@ static void r300SetEarlyZState(GLcontext * ctx) r300ContextPtr r300 = R300_CONTEXT(ctx); R300_STATECHANGE(r300, zstencil_format); + switch (ctx->Visual.depthBits) { + case 16: + r300->hw.zstencil_format.cmd[1] = R300_DEPTH_FORMAT_16BIT_INT_Z; + break; + case 24: + r300->hw.zstencil_format.cmd[1] = R300_DEPTH_FORMAT_24BIT_INT_Z; + break; + default: + fprintf(stderr, "Error: Unsupported depth %d... exiting\n", ctx->Visual.depthBits); + _mesa_exit(-1); + } + + // r300->hw.zstencil_format.cmd[1] |= R300_DEPTH_FORMAT_UNK32; + if (ctx->Color.AlphaEnabled && ctx->Color.AlphaFunc != GL_ALWAYS) /* disable early Z */ r300->hw.zstencil_format.cmd[2] = R300_EARLY_Z_DISABLE; @@ -355,6 +385,9 @@ static void r300SetEarlyZState(GLcontext * ctx) /* disable early Z */ r300->hw.zstencil_format.cmd[2] = R300_EARLY_Z_DISABLE; } + + r300->hw.zstencil_format.cmd[3] = 0x00000003; + r300->hw.zstencil_format.cmd[4] = 0x00000000; } static void r300SetAlphaState(GLcontext * ctx) @@ -403,6 +436,7 @@ static void r300SetAlphaState(GLcontext * ctx) R300_STATECHANGE(r300, at); r300->hw.at.cmd[R300_AT_ALPHA_TEST] = pp_misc; + r300->hw.at.cmd[R300_AT_UNKNOWN] = 0; r300SetEarlyZState(ctx); } @@ -513,6 +547,9 @@ static void r300UpdatePolygonMode(GLcontext * ctx) R300_STATECHANGE(r300, polygon_mode); r300->hw.polygon_mode.cmd[1] = hw_mode; } + + r300->hw.polygon_mode.cmd[2] = 0x00000001; + r300->hw.polygon_mode.cmd[3] = 0x00000000; } /** @@ -696,8 +733,8 @@ static void r300Fogfv(GLcontext * ctx, GLenum pname, const GLfloat * param) static void r300PointSize(GLcontext * ctx, GLfloat size) { r300ContextPtr r300 = R300_CONTEXT(ctx); - - size = ctx->Point._Size; + /* same size limits for AA, non-AA points */ + size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize); R300_STATECHANGE(r300, ps); r300->hw.ps.cmd[R300_PS_POINTSIZE] = @@ -712,8 +749,9 @@ static void r300LineWidth(GLcontext * ctx, GLfloat widthf) { r300ContextPtr r300 = R300_CONTEXT(ctx); - widthf = ctx->Line._Width; - + widthf = CLAMP(widthf, + ctx->Const.MinPointSize, + ctx->Const.MaxPointSize); R300_STATECHANGE(r300, lcntl); r300->hw.lcntl.cmd[1] = R300_LINE_CNT_HO | R300_LINE_CNT_VE | (int)(widthf * 6.0); @@ -762,6 +800,7 @@ static void r300ShadeModel(GLcontext * ctx, GLenum mode) r300ContextPtr rmesa = R300_CONTEXT(ctx); R300_STATECHANGE(rmesa, shade); + rmesa->hw.shade.cmd[1] = 0x00000002; switch (mode) { case GL_FLAT: rmesa->hw.shade.cmd[2] = R300_RE_SHADE_MODEL_FLAT; @@ -772,6 +811,8 @@ static void r300ShadeModel(GLcontext * ctx, GLenum mode) default: return; } + rmesa->hw.shade.cmd[3] = 0x00000000; + rmesa->hw.shade.cmd[4] = 0x00000000; } static void r300StencilFuncSeparate(GLcontext * ctx, GLenum face, @@ -1526,30 +1567,31 @@ static void r300SetupDefaultVertexProgram(r300ContextPtr rmesa) for (i = VERT_ATTRIB_POS; i < VERT_ATTRIB_MAX; i++) { if (rmesa->state.sw_tcl_inputs[i] != -1) { - prog->program.body.i[program_end].op = EASY_VSF_OP(MUL, o_reg++, ALL, RESULT); - prog->program.body.i[program_end].src[0] = VSF_REG(rmesa->state.sw_tcl_inputs[i]); - prog->program.body.i[program_end].src[1] = VSF_ATTR_UNITY(rmesa->state.sw_tcl_inputs[i]); - prog->program.body.i[program_end].src[2] = VSF_UNITY(rmesa->state.sw_tcl_inputs[i]); - program_end++; + prog->program.body.i[program_end + 0] = EASY_VSF_OP(MUL, o_reg++, ALL, RESULT); + prog->program.body.i[program_end + 1] = VSF_REG(rmesa->state.sw_tcl_inputs[i]); + prog->program.body.i[program_end + 2] = VSF_ATTR_UNITY(rmesa->state.sw_tcl_inputs[i]); + prog->program.body.i[program_end + 3] = VSF_UNITY(rmesa->state.sw_tcl_inputs[i]); + program_end += 4; } } - prog->program.length = program_end * 4; + prog->program.length = program_end; - r300SetupVertexProgramFragment(rmesa, VSF_DEST_PROGRAM, &(prog->program)); + r300SetupVertexProgramFragment(rmesa, R300_PVS_UPLOAD_PROGRAM, + &(prog->program)); inst_count = (prog->program.length / 4) - 1; R300_STATECHANGE(rmesa, pvs); rmesa->hw.pvs.cmd[R300_PVS_CNTL_1] = - (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT) | - (inst_count << R300_PVS_CNTL_1_POS_END_SHIFT) | - (inst_count << R300_PVS_CNTL_1_PROGRAM_END_SHIFT); + (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT) | + (inst_count << R300_PVS_CNTL_1_POS_END_SHIFT) | + (inst_count << R300_PVS_CNTL_1_PROGRAM_END_SHIFT); rmesa->hw.pvs.cmd[R300_PVS_CNTL_2] = - (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT) | - (param_count << R300_PVS_CNTL_2_PARAM_COUNT_SHIFT); + (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT) | + (param_count << R300_PVS_CNTL_2_PARAM_COUNT_SHIFT); rmesa->hw.pvs.cmd[R300_PVS_CNTL_3] = - (inst_count << R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT) | - (inst_count << R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT); + (inst_count << R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT) | + (inst_count << R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT); } static void r300SetupRealVertexProgram(r300ContextPtr rmesa) @@ -1570,7 +1612,7 @@ static void r300SetupRealVertexProgram(r300ContextPtr rmesa) bump_vpu_count(rmesa->hw.vpp.cmd, param_count); param_count /= 4; - r300SetupVertexProgramFragment(rmesa, VSF_DEST_PROGRAM, &(prog->program)); + r300SetupVertexProgramFragment(rmesa, R300_PVS_UPLOAD_PROGRAM, &(prog->program)); inst_count = (prog->program.length / 4) - 1; R300_STATECHANGE(rmesa, pvs); @@ -1848,15 +1890,10 @@ static void r300ResetHwState(r300ContextPtr r300) r300->hw.unk4260.cmd[2] = r300PackFloat32(0.0); r300->hw.unk4260.cmd[3] = r300PackFloat32(1.0); - r300->hw.shade.cmd[1] = 0x00000002; r300ShadeModel(ctx, ctx->Light.ShadeModel); - r300->hw.shade.cmd[3] = 0x00000000; - r300->hw.shade.cmd[4] = 0x00000000; r300PolygonMode(ctx, GL_FRONT, ctx->Polygon.FrontMode); r300PolygonMode(ctx, GL_BACK, ctx->Polygon.BackMode); - r300->hw.polygon_mode.cmd[2] = 0x00000001; - r300->hw.polygon_mode.cmd[3] = 0x00000000; r300->hw.zbias_cntl.cmd[1] = 0x00000000; r300PolygonOffset(ctx, ctx->Polygon.OffsetFactor, @@ -1887,14 +1924,11 @@ static void r300ResetHwState(r300ContextPtr r300) r300Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color); r300Fogfv(ctx, GL_FOG_COORDINATE_SOURCE_EXT, NULL); - r300->hw.at.cmd[R300_AT_UNKNOWN] = 0; r300->hw.unk4BD8.cmd[1] = 0; r300->hw.unk4E00.cmd[1] = 0; r300BlendColor(ctx, ctx->Color.BlendColor); - r300->hw.blend_color.cmd[2] = 0; - r300->hw.blend_color.cmd[3] = 0; /* Again, r300ClearBuffer uses this */ r300->hw.cb.cmd[R300_CB_OFFSET] = @@ -1925,25 +1959,6 @@ static void r300ResetHwState(r300ContextPtr r300) r300->hw.unk4EA0.cmd[1] = 0x00000000; r300->hw.unk4EA0.cmd[2] = 0xffffffff; - switch (ctx->Visual.depthBits) { - case 16: - r300->hw.zstencil_format.cmd[1] = R300_DEPTH_FORMAT_16BIT_INT_Z; - break; - case 24: - r300->hw.zstencil_format.cmd[1] = R300_DEPTH_FORMAT_24BIT_INT_Z; - break; - default: - fprintf(stderr, "Error: Unsupported depth %d... exiting\n", - ctx->Visual.depthBits); - _mesa_exit(-1); - - } - /* z compress? */ - //r300->hw.zstencil_format.cmd[1] |= R300_DEPTH_FORMAT_UNK32; - - r300->hw.zstencil_format.cmd[3] = 0x00000003; - r300->hw.zstencil_format.cmd[4] = 0x00000000; - r300->hw.zb.cmd[R300_ZB_OFFSET] = r300->radeon.radeonScreen->depthOffset + r300->radeon.radeonScreen->fbLocation; diff --git a/src/mesa/drivers/dri/r300/r300_texmem.c b/src/mesa/drivers/dri/r300/r300_texmem.c index 38f0da8b7c..723601ac4a 100644 --- a/src/mesa/drivers/dri/r300/r300_texmem.c +++ b/src/mesa/drivers/dri/r300/r300_texmem.c @@ -505,7 +505,7 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face) t->base.lastLevel); } - if (!t || t->base.totalSize == 0) + if (t->base.totalSize == 0) return 0; if (RADEON_DEBUG & DEBUG_SYNC) { diff --git a/src/mesa/drivers/dri/r300/r300_vertprog.c b/src/mesa/drivers/dri/r300/r300_vertprog.c index 16dddf6557..7d4e8c9511 100644 --- a/src/mesa/drivers/dri/r300/r300_vertprog.c +++ b/src/mesa/drivers/dri/r300/r300_vertprog.c @@ -29,6 +29,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. * \file * * \author Aapo Tahkola <aet@rasterburn.org> + * + * \author Oliver McFadden <z3ro.geek@gmail.com> + * + * For a description of the vertex program instruction set see r300_reg.h. */ #include "glheader.h" @@ -55,54 +59,58 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #error Cannot change these! #endif -#define SCALAR_FLAG (1<<31) -#define FLAG_MASK (1<<31) -#define OP_MASK (0xf) /* we are unlikely to have more than 15 */ -#define OPN(operator, ip) {#operator, OPCODE_##operator, ip} - -static struct { - char *name; - int opcode; - unsigned long ip; /* number of input operands and flags */ -} op_names[] = { - /* *INDENT-OFF* */ - OPN(ABS, 1), - OPN(ADD, 2), - OPN(ARL, 1 | SCALAR_FLAG), - OPN(DP3, 2), - OPN(DP4, 2), - OPN(DPH, 2), - OPN(DST, 2), - OPN(EX2, 1 | SCALAR_FLAG), - OPN(EXP, 1 | SCALAR_FLAG), - OPN(FLR, 1), - OPN(FRC, 1), - OPN(LG2, 1 | SCALAR_FLAG), - OPN(LIT, 1), - OPN(LOG, 1 | SCALAR_FLAG), - OPN(MAD, 3), - OPN(MAX, 2), - OPN(MIN, 2), - OPN(MOV, 1), - OPN(MUL, 2), - OPN(POW, 2 | SCALAR_FLAG), - OPN(RCP, 1 | SCALAR_FLAG), - OPN(RSQ, 1 | SCALAR_FLAG), - OPN(SGE, 2), - OPN(SLT, 2), - OPN(SUB, 2), - OPN(SWZ, 1), - OPN(XPD, 2), - OPN(RCC, 0), //extra - OPN(PRINT, 0), - OPN(END, 0) - /* *INDENT-ON* */ -}; - -#undef OPN +/* TODO: Get rid of t_src_class call */ +#define CMP_SRCS(a, b) ((a.RelAddr != b.RelAddr) || (a.Index != b.Index && \ + ((t_src_class(a.File) == VSF_IN_CLASS_PARAM && \ + t_src_class(b.File) == VSF_IN_CLASS_PARAM) || \ + (t_src_class(a.File) == VSF_IN_CLASS_ATTR && \ + t_src_class(b.File) == VSF_IN_CLASS_ATTR)))) \ + +#define ZERO_SRC_0 (MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), \ + SWIZZLE_ZERO, SWIZZLE_ZERO, \ + SWIZZLE_ZERO, SWIZZLE_ZERO, \ + t_src_class(src[0].File), VSF_FLAG_NONE) | (src[0].RelAddr << 4)) + +#define ZERO_SRC_1 (MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), \ + SWIZZLE_ZERO, SWIZZLE_ZERO, \ + SWIZZLE_ZERO, SWIZZLE_ZERO, \ + t_src_class(src[1].File), VSF_FLAG_NONE) | (src[1].RelAddr << 4)) + +#define ZERO_SRC_2 (MAKE_VSF_SOURCE(t_src_index(vp, &src[2]), \ + SWIZZLE_ZERO, SWIZZLE_ZERO, \ + SWIZZLE_ZERO, SWIZZLE_ZERO, \ + t_src_class(src[2].File), VSF_FLAG_NONE) | (src[2].RelAddr << 4)) + +#define ONE_SRC_0 (MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), \ + SWIZZLE_ONE, SWIZZLE_ONE, \ + SWIZZLE_ONE, SWIZZLE_ONE, \ + t_src_class(src[0].File), VSF_FLAG_NONE) | (src[0].RelAddr << 4)) + +#define ONE_SRC_1 (MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), \ + SWIZZLE_ONE, SWIZZLE_ONE, \ + SWIZZLE_ONE, SWIZZLE_ONE, \ + t_src_class(src[1].File), VSF_FLAG_NONE) | (src[1].RelAddr << 4)) + +#define ONE_SRC_2 (MAKE_VSF_SOURCE(t_src_index(vp, &src[2]), \ + SWIZZLE_ONE, SWIZZLE_ONE, \ + SWIZZLE_ONE, SWIZZLE_ONE, \ + t_src_class(src[2].File), VSF_FLAG_NONE) | (src[2].RelAddr << 4)) + +/* DP4 version seems to trigger some hw peculiarity */ +//#define PREFER_DP4 + +#define FREE_TEMPS() \ + do { \ + if(u_temp_i < vp->num_temporaries) { \ + WARN_ONCE("Ran out of temps, num temps %d, us %d\n", vp->num_temporaries, u_temp_i); \ + vp->native = GL_FALSE; \ + } \ + u_temp_i=VSF_MAX_FRAGMENT_TEMPS-1; \ + } while (0) int r300VertexProgUpdateParams(GLcontext * ctx, - struct r300_vertex_program_cont *vp, float *dst) + struct r300_vertex_program_cont *vp, + float *dst) { int pi; struct gl_vertex_program *mesa_vp = &vp->mesa_program; @@ -234,8 +242,8 @@ static void vp_dump_inputs(struct r300_vertex_program *vp, char *caller) int i; if (vp == NULL) { - fprintf(stderr, "vp null in call to %s from %s\n", __FUNCTION__, - caller); + fprintf(stderr, "vp null in call to %s from %s\n", + __FUNCTION__, caller); return; } @@ -276,6 +284,8 @@ static unsigned long t_src_index(struct r300_vertex_program *vp, } } +/* these two functions should probably be merged... */ + static unsigned long t_src(struct r300_vertex_program *vp, struct prog_src_register *src) { @@ -294,7 +304,9 @@ static unsigned long t_src(struct r300_vertex_program *vp, static unsigned long t_src_scalar(struct r300_vertex_program *vp, struct prog_src_register *src) { - + /* src->NegateBase uses the NEGATE_ flags from program_instruction.h, + * which equal our VSF_FLAGS_ values, so it's safe to just pass it here. + */ return MAKE_VSF_SOURCE(t_src_index(vp, src), t_swizzle(GET_SWZ(src->Swizzle, 0)), t_swizzle(GET_SWZ(src->Swizzle, 0)), @@ -306,128 +318,741 @@ static unsigned long t_src_scalar(struct r300_vertex_program *vp, (src->RelAddr << 4); } -static unsigned long t_opcode(enum prog_opcode opcode) +static GLboolean valid_dst(struct r300_vertex_program *vp, + struct prog_dst_register *dst) { + if (dst->File == PROGRAM_OUTPUT && vp->outputs[dst->Index] == -1) { + return GL_FALSE; + } else if (dst->File == PROGRAM_ADDRESS) { + assert(dst->Index == 0); + } - switch (opcode) { - /* *INDENT-OFF* */ - case OPCODE_ARL: return R300_VPI_OUT_OP_ARL; - case OPCODE_DST: return R300_VPI_OUT_OP_DST; - case OPCODE_EX2: return R300_VPI_OUT_OP_EX2; - case OPCODE_EXP: return R300_VPI_OUT_OP_EXP; - case OPCODE_FRC: return R300_VPI_OUT_OP_FRC; - case OPCODE_LG2: return R300_VPI_OUT_OP_LG2; - case OPCODE_LOG: return R300_VPI_OUT_OP_LOG; - case OPCODE_MAX: return R300_VPI_OUT_OP_MAX; - case OPCODE_MIN: return R300_VPI_OUT_OP_MIN; - case OPCODE_MUL: return R300_VPI_OUT_OP_MUL; - case OPCODE_RCP: return R300_VPI_OUT_OP_RCP; - case OPCODE_RSQ: return R300_VPI_OUT_OP_RSQ; - case OPCODE_SGE: return R300_VPI_OUT_OP_SGE; - case OPCODE_SLT: return R300_VPI_OUT_OP_SLT; - case OPCODE_DP4: return R300_VPI_OUT_OP_DOT; - /* *INDENT-ON* */ + return GL_TRUE; +} - default: - fprintf(stderr, "%s: Should not be called with opcode %d!", - __FUNCTION__, opcode); - } - _mesa_exit(-1); - return 0; +/* + * Instruction Inputs Output Description + * ----------- ------ ------ -------------------------------- + * ABS v v absolute value + * ADD v,v v add + * ARL s a address register load + * DP3 v,v ssss 3-component dot product + * DP4 v,v ssss 4-component dot product + * DPH v,v ssss homogeneous dot product + * DST v,v v distance vector + * EX2 s ssss exponential base 2 + * EXP s v exponential base 2 (approximate) + * FLR v v floor + * FRC v v fraction + * LG2 s ssss logarithm base 2 + * LIT v v compute light coefficients + * LOG s v logarithm base 2 (approximate) + * MAD v,v,v v multiply and add + * MAX v,v v maximum + * MIN v,v v minimum + * MOV v v move + * MUL v,v v multiply + * POW s,s ssss exponentiate + * RCP s ssss reciprocal + * RSQ s ssss reciprocal square root + * SGE v,v v set on greater than or equal + * SLT v,v v set on less than + * SUB v,v v subtract + * SWZ v v extended swizzle + * XPD v,v v cross product + * + * Table X.5: Summary of vertex program instructions. "v" indicates a + * floating-point vector input or output, "s" indicates a floating-point + * scalar input, "ssss" indicates a scalar output replicated across a + * 4-component result vector, and "a" indicates a single address register + * component. + */ + +static GLuint *t_opcode_abs(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + //MAX RESULT 1.X Y Z W PARAM 0{} {X Y Z W} PARAM 0{X Y Z W } {X Y Z W} neg Xneg Yneg Zneg W + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_MAX, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_swizzle(GET_SWZ(src[0].Swizzle, 1)), + t_swizzle(GET_SWZ(src[0].Swizzle, 2)), + t_swizzle(GET_SWZ(src[0].Swizzle, 3)), + t_src_class(src[0].File), + (!src[0]. + NegateBase) ? VSF_FLAG_ALL : VSF_FLAG_NONE) | + (src[0].RelAddr << 4); + inst[3] = 0; + + return inst; } -static unsigned long op_operands(enum prog_opcode opcode) +static GLuint *t_opcode_add(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) { - int i; + unsigned long hw_op; - /* Can we trust mesas opcodes to be in order ? */ - for (i = 0; i < sizeof(op_names) / sizeof(*op_names); i++) - if (op_names[i].opcode == opcode) - return op_names[i].ip; +#if 1 + hw_op = (src[0].File == PROGRAM_TEMPORARY + && src[1].File == + PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : + R300_VPI_OUT_OP_MAD; + + inst[0] = + MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = ONE_SRC_0; + inst[2] = t_src(vp, &src[0]); + inst[3] = t_src(vp, &src[1]); +#else + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; - fprintf(stderr, "op %d not found in op_names\n", opcode); - _mesa_exit(-1); - return 0; +#endif + + return inst; } -static GLboolean valid_dst(struct r300_vertex_program *vp, - struct prog_dst_register *dst) +static GLuint *t_opcode_arl(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) { - if (dst->File == PROGRAM_OUTPUT && vp->outputs[dst->Index] == -1) { - return GL_FALSE; - } else if (dst->File == PROGRAM_ADDRESS) { - assert(dst->Index == 0); - } + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ARL, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); - return GL_TRUE; + inst[1] = t_src(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; } -/* TODO: Get rid of t_src_class call */ -#define CMP_SRCS(a, b) ((a.RelAddr != b.RelAddr) || (a.Index != b.Index && \ - ((t_src_class(a.File) == VSF_IN_CLASS_PARAM && \ - t_src_class(b.File) == VSF_IN_CLASS_PARAM) || \ - (t_src_class(a.File) == VSF_IN_CLASS_ATTR && \ - t_src_class(b.File) == VSF_IN_CLASS_ATTR)))) \ +static GLuint *t_opcode_dp3(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + //DOT RESULT 1.X Y Z W PARAM 0{} {X Y Z ZERO} PARAM 0{} {X Y Z ZERO} + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_DOT, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_swizzle(GET_SWZ(src[0].Swizzle, 1)), + t_swizzle(GET_SWZ(src[0].Swizzle, 2)), + SWIZZLE_ZERO, t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_XYZ : VSF_FLAG_NONE) | + (src[0].RelAddr << 4); + + inst[2] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), + t_swizzle(GET_SWZ(src[1].Swizzle, 0)), + t_swizzle(GET_SWZ(src[1].Swizzle, 1)), + t_swizzle(GET_SWZ(src[1].Swizzle, 2)), + SWIZZLE_ZERO, t_src_class(src[1].File), + src[1]. + NegateBase ? VSF_FLAG_XYZ : VSF_FLAG_NONE) | + (src[1].RelAddr << 4); + + inst[3] = ZERO_SRC_1; + + return inst; +} -#define ZERO_SRC_0 (MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), \ - SWIZZLE_ZERO, SWIZZLE_ZERO, \ - SWIZZLE_ZERO, SWIZZLE_ZERO, \ - t_src_class(src[0].File), VSF_FLAG_NONE) | (src[0].RelAddr << 4)) +static GLuint *t_opcode_dp4(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_DOT, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); -#define ZERO_SRC_1 (MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), \ - SWIZZLE_ZERO, SWIZZLE_ZERO, \ - SWIZZLE_ZERO, SWIZZLE_ZERO, \ - t_src_class(src[1].File), VSF_FLAG_NONE) | (src[1].RelAddr << 4)) + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; -#define ZERO_SRC_2 (MAKE_VSF_SOURCE(t_src_index(vp, &src[2]), \ - SWIZZLE_ZERO, SWIZZLE_ZERO, \ - SWIZZLE_ZERO, SWIZZLE_ZERO, \ - t_src_class(src[2].File), VSF_FLAG_NONE) | (src[2].RelAddr << 4)) + return inst; +} -#define ONE_SRC_0 (MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), \ - SWIZZLE_ONE, SWIZZLE_ONE, \ - SWIZZLE_ONE, SWIZZLE_ONE, \ - t_src_class(src[0].File), VSF_FLAG_NONE) | (src[0].RelAddr << 4)) +static GLuint *t_opcode_dph(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + //DOT RESULT 1.X Y Z W PARAM 0{} {X Y Z ONE} PARAM 0{} {X Y Z W} + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_DOT, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_swizzle(GET_SWZ(src[0].Swizzle, 1)), + t_swizzle(GET_SWZ(src[0].Swizzle, 2)), + VSF_IN_COMPONENT_ONE, t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_XYZ : VSF_FLAG_NONE) | + (src[0].RelAddr << 4); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; + + return inst; +} -#define ONE_SRC_1 (MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), \ - SWIZZLE_ONE, SWIZZLE_ONE, \ - SWIZZLE_ONE, SWIZZLE_ONE, \ - t_src_class(src[1].File), VSF_FLAG_NONE) | (src[1].RelAddr << 4)) +static GLuint *t_opcode_dst(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_DST, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); -#define ONE_SRC_2 (MAKE_VSF_SOURCE(t_src_index(vp, &src[2]), \ - SWIZZLE_ONE, SWIZZLE_ONE, \ - SWIZZLE_ONE, SWIZZLE_ONE, \ - t_src_class(src[2].File), VSF_FLAG_NONE) | (src[2].RelAddr << 4)) + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; -/* DP4 version seems to trigger some hw peculiarity */ -//#define PREFER_DP4 + return inst; +} -#define FREE_TEMPS() \ - do { \ - if(u_temp_i < vp->num_temporaries) { \ - WARN_ONCE("Ran out of temps, num temps %d, us %d\n", vp->num_temporaries, u_temp_i); \ - vp->native = GL_FALSE; \ - } \ - u_temp_i=VSF_MAX_FRAGMENT_TEMPS-1; \ - } while (0) +static GLuint *t_opcode_ex2(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_EX2, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); -static void r300TranslateVertexShader(struct r300_vertex_program *vp, - struct prog_instruction *vpi) + inst[1] = t_src_scalar(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_exp(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_EXP, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src_scalar(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_flr(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3], int *u_temp_i) +{ + /* FRC TMP 0.X Y Z W PARAM 0{} {X Y Z W} + ADD RESULT 1.X Y Z W PARAM 0{} {X Y Z W} TMP 0{X Y Z W } {X Y Z W} neg Xneg Yneg Zneg W */ + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_FRC, *u_temp_i, + t_dst_mask(vpi->DstReg.WriteMask), + VSF_OUT_CLASS_TMP); + + inst[1] = t_src(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + inst += 4; + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = + MAKE_VSF_SOURCE(*u_temp_i, VSF_IN_COMPONENT_X, + VSF_IN_COMPONENT_Y, VSF_IN_COMPONENT_Z, + VSF_IN_COMPONENT_W, VSF_IN_CLASS_TMP, + /* Not 100% sure about this */ + (!src[0]. + NegateBase) ? VSF_FLAG_ALL : VSF_FLAG_NONE + /*VSF_FLAG_ALL */ ); + + inst[3] = ZERO_SRC_0; + (*u_temp_i)--; + + return inst; +} + +static GLuint *t_opcode_frc(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_FRC, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_lg2(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + // LG2 RESULT 1.X Y Z W PARAM 0{} {X X X X} + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_LG2, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), + t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_ALL : VSF_FLAG_NONE) | + (src[0].RelAddr << 4); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_lit(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + //LIT TMP 1.Y Z TMP 1{} {X W Z Y} TMP 1{} {Y W Z X} TMP 1{} {Y X Z W} + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_LIT, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + /* NOTE: Users swizzling might not work. */ + inst[1] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x + t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w + VSF_IN_COMPONENT_ZERO, // z + t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y + t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[0].RelAddr << 4); + inst[2] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y + t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w + VSF_IN_COMPONENT_ZERO, // z + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x + t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[0].RelAddr << 4); + inst[3] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x + VSF_IN_COMPONENT_ZERO, // z + t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w + t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[0].RelAddr << 4); + + return inst; +} + +static GLuint *t_opcode_log(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_LOG, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src_scalar(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_mad(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) { - int i, cur_reg = 0; - VERTEX_SHADER_INSTRUCTION *o_inst; - unsigned long operands; - int are_srcs_scalar; unsigned long hw_op; - /* Initial value should be last tmp reg that hw supports. - Strangely enough r300 doesnt mind even though these would be out of range. - Smart enough to realize that it doesnt need it? */ - int u_temp_i = VSF_MAX_FRAGMENT_TEMPS - 1; - struct prog_src_register src[3]; - vp->pos_end = 0; /* Not supported yet */ - vp->program.length = 0; - /*vp->num_temporaries=mesa_vp->Base.NumTemporaries; */ + hw_op = (src[0].File == PROGRAM_TEMPORARY + && src[1].File == PROGRAM_TEMPORARY + && src[2].File == + PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : + R300_VPI_OUT_OP_MAD; + + inst[0] = + MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = t_src(vp, &src[2]); + + return inst; +} + +static GLuint *t_opcode_max(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_MAX, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; + + return inst; +} + +static GLuint *t_opcode_min(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_MIN, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; + + return inst; +} + +static GLuint *t_opcode_mov(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + //ADD RESULT 1.X Y Z W PARAM 0{} {X Y Z W} PARAM 0{} {ZERO ZERO ZERO ZERO} + +#if 1 + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; +#else + hw_op = + (src[0].File == + PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : + R300_VPI_OUT_OP_MAD; + + inst[0] = + MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = ONE_SRC_0; + inst[3] = ZERO_SRC_0; +#endif + + return inst; +} + +static GLuint *t_opcode_mul(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + unsigned long hw_op; + + // HW mul can take third arg but appears to have some other limitations. + + hw_op = (src[0].File == PROGRAM_TEMPORARY + && src[1].File == + PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : + R300_VPI_OUT_OP_MAD; + + inst[0] = + MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + + inst[3] = ZERO_SRC_1; + + return inst; +} + +static GLuint *t_opcode_pow(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_POW, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src_scalar(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = t_src_scalar(vp, &src[1]); + + return inst; +} + +static GLuint *t_opcode_rcp(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_RCP, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src_scalar(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_rsq(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_RSQ, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src_scalar(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + + return inst; +} + +static GLuint *t_opcode_sge(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_SGE, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; + + return inst; +} + +static GLuint *t_opcode_slt(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_SLT, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = t_src(vp, &src[1]); + inst[3] = ZERO_SRC_1; + + return inst; +} + +static GLuint *t_opcode_sub(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + unsigned long hw_op; + + //ADD RESULT 1.X Y Z W TMP 0{} {X Y Z W} PARAM 1{X Y Z W } {X Y Z W} neg Xneg Yneg Zneg W + +#if 1 + hw_op = (src[0].File == PROGRAM_TEMPORARY + && src[1].File == + PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : + R300_VPI_OUT_OP_MAD; + + inst[0] = + MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = ONE_SRC_0; + inst[3] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), + t_swizzle(GET_SWZ(src[1].Swizzle, 0)), + t_swizzle(GET_SWZ(src[1].Swizzle, 1)), + t_swizzle(GET_SWZ(src[1].Swizzle, 2)), + t_swizzle(GET_SWZ(src[1].Swizzle, 3)), + t_src_class(src[1].File), + (!src[1]. + NegateBase) ? VSF_FLAG_ALL : VSF_FLAG_NONE) | + (src[1].RelAddr << 4); +#else + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = t_src(vp, &src[0]); + inst[2] = + MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), + t_swizzle(GET_SWZ(src[1].Swizzle, 0)), + t_swizzle(GET_SWZ(src[1].Swizzle, 1)), + t_swizzle(GET_SWZ(src[1].Swizzle, 2)), + t_swizzle(GET_SWZ(src[1].Swizzle, 3)), + t_src_class(src[1].File), + (!src[1]. + NegateBase) ? VSF_FLAG_ALL : VSF_FLAG_NONE) | + (src[1].RelAddr << 4); + inst[3] = 0; +#endif + + return inst; +} + +static GLuint *t_opcode_swz(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3]) +{ + //ADD RESULT 1.X Y Z W PARAM 0{} {X Y Z W} PARAM 0{} {ZERO ZERO ZERO ZERO} + +#if 1 + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; +#else + hw_op = + (src[0].File == + PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : + R300_VPI_OUT_OP_MAD; + + inst[0] = + MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + inst[1] = t_src(vp, &src[0]); + inst[2] = ONE_SRC_0; + inst[3] = ZERO_SRC_0; +#endif + + return inst; +} + +static GLuint *t_opcode_xpd(struct r300_vertex_program *vp, + struct prog_instruction *vpi, GLuint * inst, + struct prog_src_register src[3], int *u_temp_i) +{ + /* mul r0, r1.yzxw, r2.zxyw + mad r0, -r2.yzxw, r1.zxyw, r0 + NOTE: might need MAD_2 + */ + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_MAD, *u_temp_i, + t_dst_mask(vpi->DstReg.WriteMask), + VSF_OUT_CLASS_TMP); + + inst[1] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y + t_swizzle(GET_SWZ(src[0].Swizzle, 2)), // z + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x + t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w + t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[0].RelAddr << 4); + + inst[2] = MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), t_swizzle(GET_SWZ(src[1].Swizzle, 2)), // z + t_swizzle(GET_SWZ(src[1].Swizzle, 0)), // x + t_swizzle(GET_SWZ(src[1].Swizzle, 1)), // y + t_swizzle(GET_SWZ(src[1].Swizzle, 3)), // w + t_src_class(src[1].File), + src[1]. + NegateBase ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[1].RelAddr << 4); + + inst[3] = ZERO_SRC_1; + inst += 4; + (*u_temp_i)--; + + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_MAD, t_dst_index(vp, &vpi->DstReg), + t_dst_mask(vpi->DstReg.WriteMask), + t_dst_class(vpi->DstReg.File)); + + inst[1] = MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), t_swizzle(GET_SWZ(src[1].Swizzle, 1)), // y + t_swizzle(GET_SWZ(src[1].Swizzle, 2)), // z + t_swizzle(GET_SWZ(src[1].Swizzle, 0)), // x + t_swizzle(GET_SWZ(src[1].Swizzle, 3)), // w + t_src_class(src[1].File), + (!src[1]. + NegateBase) ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[1].RelAddr << 4); + + inst[2] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 2)), // z + t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x + t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y + t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w + t_src_class(src[0].File), + src[0]. + NegateBase ? VSF_FLAG_ALL : + VSF_FLAG_NONE) | (src[0].RelAddr << 4); + + inst[3] = + MAKE_VSF_SOURCE(*u_temp_i + 1, VSF_IN_COMPONENT_X, + VSF_IN_COMPONENT_Y, VSF_IN_COMPONENT_Z, + VSF_IN_COMPONENT_W, VSF_IN_CLASS_TMP, + VSF_FLAG_NONE); + + return inst; +} + +static void t_inputs_outputs(struct r300_vertex_program *vp) +{ + int i; + int cur_reg = 0; for (i = 0; i < VERT_ATTRIB_MAX; i++) vp->inputs[i] = -1; @@ -437,39 +1062,71 @@ static void r300TranslateVertexShader(struct r300_vertex_program *vp, assert(vp->key.OutputsWritten & (1 << VERT_RESULT_HPOS)); - /* Assign outputs */ - if (vp->key.OutputsWritten & (1 << VERT_RESULT_HPOS)) + if (vp->key.OutputsWritten & (1 << VERT_RESULT_HPOS)) { vp->outputs[VERT_RESULT_HPOS] = cur_reg++; + } - if (vp->key.OutputsWritten & (1 << VERT_RESULT_PSIZ)) + if (vp->key.OutputsWritten & (1 << VERT_RESULT_PSIZ)) { vp->outputs[VERT_RESULT_PSIZ] = cur_reg++; + } - if (vp->key.OutputsWritten & (1 << VERT_RESULT_COL0)) + if (vp->key.OutputsWritten & (1 << VERT_RESULT_COL0)) { vp->outputs[VERT_RESULT_COL0] = cur_reg++; + } - if (vp->key.OutputsWritten & (1 << VERT_RESULT_COL1)) - vp->outputs[VERT_RESULT_COL1] = cur_reg++; - -#if 0 /* Not supported yet */ - if (vp->key.OutputsWritten & (1 << VERT_RESULT_BFC0)) - vp->outputs[VERT_RESULT_BFC0] = cur_reg++; + if (vp->key.OutputsWritten & (1 << VERT_RESULT_COL1)) { + vp->outputs[VERT_RESULT_COL1] = + vp->outputs[VERT_RESULT_COL0] + 1; + cur_reg = vp->outputs[VERT_RESULT_COL1] + 1; + } - if (vp->key.OutputsWritten & (1 << VERT_RESULT_BFC1)) - vp->outputs[VERT_RESULT_BFC1] = cur_reg++; + if (vp->key.OutputsWritten & (1 << VERT_RESULT_BFC0)) { + vp->outputs[VERT_RESULT_BFC0] = + vp->outputs[VERT_RESULT_COL0] + 2; + cur_reg = vp->outputs[VERT_RESULT_BFC0] + 2; + } - if (vp->key.OutputsWritten & (1 << VERT_RESULT_FOGC)) + if (vp->key.OutputsWritten & (1 << VERT_RESULT_BFC1)) { + vp->outputs[VERT_RESULT_BFC1] = + vp->outputs[VERT_RESULT_COL0] + 3; + cur_reg = vp->outputs[VERT_RESULT_BFC1] + 1; + } +#if 0 + if (vp->key.OutputsWritten & (1 << VERT_RESULT_FOGC)) { vp->outputs[VERT_RESULT_FOGC] = cur_reg++; + } #endif - for (i = VERT_RESULT_TEX0; i <= VERT_RESULT_TEX7; i++) - if (vp->key.OutputsWritten & (1 << i)) + for (i = VERT_RESULT_TEX0; i <= VERT_RESULT_TEX7; i++) { + if (vp->key.OutputsWritten & (1 << i)) { vp->outputs[i] = cur_reg++; + } + } +} + +static void r300TranslateVertexShader(struct r300_vertex_program *vp, + struct prog_instruction *vpi) +{ + int i; + GLuint *inst; + unsigned long num_operands; + /* Initial value should be last tmp reg that hw supports. + Strangely enough r300 doesnt mind even though these would be out of range. + Smart enough to realize that it doesnt need it? */ + int u_temp_i = VSF_MAX_FRAGMENT_TEMPS - 1; + struct prog_src_register src[3]; + vp->pos_end = 0; /* Not supported yet */ + vp->program.length = 0; + /*vp->num_temporaries=mesa_vp->Base.NumTemporaries; */ vp->translated = GL_TRUE; vp->native = GL_TRUE; - o_inst = vp->program.body.i; - for (; vpi->Opcode != OPCODE_END; vpi++, o_inst++) { + t_inputs_outputs(vp); + + for (inst = vp->program.body.i; vpi->Opcode != OPCODE_END; + vpi++, inst += 4) { + FREE_TEMPS(); if (!valid_dst(vp, &vpi->DstReg)) { @@ -478,61 +1135,62 @@ static void r300TranslateVertexShader(struct r300_vertex_program *vp, vpi->DstReg.Index = u_temp_i; } - operands = op_operands(vpi->Opcode); - are_srcs_scalar = operands & SCALAR_FLAG; - operands &= OP_MASK; + num_operands = _mesa_num_inst_src_regs(vpi->Opcode); - for (i = 0; i < operands; i++) + /* copy the sources (src) from mesa into a local variable... is this needed? */ + for (i = 0; i < num_operands; i++) { src[i] = vpi->SrcReg[i]; + } - if (operands == 3) { /* TODO: scalars */ + if (num_operands == 3) { /* TODO: scalars */ if (CMP_SRCS(src[1], src[2]) || CMP_SRCS(src[0], src[2])) { - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, u_temp_i, - VSF_FLAG_ALL, + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, + u_temp_i, VSF_FLAG_ALL, VSF_OUT_CLASS_TMP); - o_inst->src[0] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[2]), + inst[1] = + MAKE_VSF_SOURCE(t_src_index + (vp, &src[2]), SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, - t_src_class(src[2].File), - VSF_FLAG_NONE) | (src[2]. - RelAddr << - 4); + t_src_class(src[2]. + File), + VSF_FLAG_NONE) | + (src[2].RelAddr << 4); - o_inst->src[1] = ZERO_SRC_2; - o_inst->src[2] = ZERO_SRC_2; - o_inst++; + inst[2] = ZERO_SRC_2; + inst[3] = ZERO_SRC_2; + inst += 4; src[2].File = PROGRAM_TEMPORARY; src[2].Index = u_temp_i; src[2].RelAddr = 0; u_temp_i--; } - } - if (operands >= 2) { + if (num_operands >= 2) { if (CMP_SRCS(src[1], src[0])) { - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, u_temp_i, - VSF_FLAG_ALL, + inst[0] = + MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, + u_temp_i, VSF_FLAG_ALL, VSF_OUT_CLASS_TMP); - o_inst->src[0] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), + inst[1] = + MAKE_VSF_SOURCE(t_src_index + (vp, &src[0]), SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, - t_src_class(src[0].File), - VSF_FLAG_NONE) | (src[0]. - RelAddr << - 4); + t_src_class(src[0]. + File), + VSF_FLAG_NONE) | + (src[0].RelAddr << 4); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = ZERO_SRC_0; - o_inst++; + inst[2] = ZERO_SRC_0; + inst[3] = ZERO_SRC_0; + inst += 4; src[0].File = PROGRAM_TEMPORARY; src[0].Index = u_temp_i; @@ -541,517 +1199,103 @@ static void r300TranslateVertexShader(struct r300_vertex_program *vp, } } - /* These ops need special handling. */ switch (vpi->Opcode) { - case OPCODE_POW: - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_POW, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src_scalar(vp, &src[0]); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = t_src_scalar(vp, &src[1]); - goto next; - - case OPCODE_MOV: //ADD RESULT 1.X Y Z W PARAM 0{} {X Y Z W} PARAM 0{} {ZERO ZERO ZERO ZERO} - case OPCODE_SWZ: -#if 1 - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = ZERO_SRC_0; -#else - hw_op = - (src[0].File == - PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : - R300_VPI_OUT_OP_MAD; - - o_inst->op = - MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = ONE_SRC_0; - o_inst->src[2] = ZERO_SRC_0; -#endif - - goto next; - + case OPCODE_ABS: + inst = t_opcode_abs(vp, vpi, inst, src); + break; case OPCODE_ADD: -#if 1 - hw_op = (src[0].File == PROGRAM_TEMPORARY && - src[1].File == - PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : - R300_VPI_OUT_OP_MAD; - - o_inst->op = - MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = ONE_SRC_0; - o_inst->src[1] = t_src(vp, &src[0]); - o_inst->src[2] = t_src(vp, &src[1]); -#else - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = t_src(vp, &src[1]); - o_inst->src[2] = ZERO_SRC_1; - -#endif - goto next; - - case OPCODE_MAD: - hw_op = (src[0].File == PROGRAM_TEMPORARY && - src[1].File == PROGRAM_TEMPORARY && - src[2].File == - PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : - R300_VPI_OUT_OP_MAD; - - o_inst->op = - MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = t_src(vp, &src[1]); - o_inst->src[2] = t_src(vp, &src[2]); - goto next; - - case OPCODE_MUL: /* HW mul can take third arg but appears to have some other limitations. */ - hw_op = (src[0].File == PROGRAM_TEMPORARY && - src[1].File == - PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : - R300_VPI_OUT_OP_MAD; - - o_inst->op = - MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = t_src(vp, &src[1]); - - o_inst->src[2] = ZERO_SRC_1; - goto next; - - case OPCODE_DP3: //DOT RESULT 1.X Y Z W PARAM 0{} {X Y Z ZERO} PARAM 0{} {X Y Z ZERO} - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_DOT, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 1)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 2)), - SWIZZLE_ZERO, - t_src_class(src[0].File), - src[0]. - NegateBase ? VSF_FLAG_XYZ : - VSF_FLAG_NONE) | (src[0]. - RelAddr << 4); - - o_inst->src[1] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), - t_swizzle(GET_SWZ - (src[1].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 1)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 2)), - SWIZZLE_ZERO, - t_src_class(src[1].File), - src[1]. - NegateBase ? VSF_FLAG_XYZ : - VSF_FLAG_NONE) | (src[1]. - RelAddr << 4); - - o_inst->src[2] = ZERO_SRC_1; - goto next; - - case OPCODE_SUB: //ADD RESULT 1.X Y Z W TMP 0{} {X Y Z W} PARAM 1{X Y Z W } {X Y Z W} neg Xneg Yneg Zneg W -#if 1 - hw_op = (src[0].File == PROGRAM_TEMPORARY && - src[1].File == - PROGRAM_TEMPORARY) ? R300_VPI_OUT_OP_MAD_2 : - R300_VPI_OUT_OP_MAD; - - o_inst->op = - MAKE_VSF_OP(hw_op, t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = ONE_SRC_0; - o_inst->src[2] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), - t_swizzle(GET_SWZ - (src[1].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 1)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 2)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 3)), - t_src_class(src[1].File), - (!src[1]. - NegateBase) ? VSF_FLAG_ALL : - VSF_FLAG_NONE) | (src[1]. - RelAddr << 4); -#else - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), - t_swizzle(GET_SWZ - (src[1].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 1)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 2)), - t_swizzle(GET_SWZ - (src[1].Swizzle, 3)), - t_src_class(src[1].File), - (!src[1]. - NegateBase) ? VSF_FLAG_ALL : - VSF_FLAG_NONE) | (src[1]. - RelAddr << 4); - o_inst->src[2] = 0; -#endif - goto next; - - case OPCODE_ABS: //MAX RESULT 1.X Y Z W PARAM 0{} {X Y Z W} PARAM 0{X Y Z W } {X Y Z W} neg Xneg Yneg Zneg W - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_MAX, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 1)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 2)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 3)), - t_src_class(src[0].File), - (!src[0]. - NegateBase) ? VSF_FLAG_ALL : - VSF_FLAG_NONE) | (src[0]. - RelAddr << 4); - o_inst->src[2] = 0; - goto next; - + inst = t_opcode_add(vp, vpi, inst, src); + break; + case OPCODE_ARL: + inst = t_opcode_arl(vp, vpi, inst, src); + break; + case OPCODE_DP3: + inst = t_opcode_dp3(vp, vpi, inst, src); + break; + case OPCODE_DP4: + inst = t_opcode_dp4(vp, vpi, inst, src); + break; + case OPCODE_DPH: + inst = t_opcode_dph(vp, vpi, inst, src); + break; + case OPCODE_DST: + inst = t_opcode_dst(vp, vpi, inst, src); + break; + case OPCODE_EX2: + inst = t_opcode_ex2(vp, vpi, inst, src); + break; + case OPCODE_EXP: + inst = t_opcode_exp(vp, vpi, inst, src); + break; case OPCODE_FLR: - /* FRC TMP 0.X Y Z W PARAM 0{} {X Y Z W} - ADD RESULT 1.X Y Z W PARAM 0{} {X Y Z W} TMP 0{X Y Z W } {X Y Z W} neg Xneg Yneg Zneg W */ - - o_inst->op = MAKE_VSF_OP(R300_VPI_OUT_OP_FRC, u_temp_i, - t_dst_mask(vpi->DstReg. - WriteMask), - VSF_OUT_CLASS_TMP); - - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = ZERO_SRC_0; - o_inst++; - - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_ADD, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = MAKE_VSF_SOURCE(u_temp_i, - VSF_IN_COMPONENT_X, - VSF_IN_COMPONENT_Y, - VSF_IN_COMPONENT_Z, - VSF_IN_COMPONENT_W, - VSF_IN_CLASS_TMP, - /* Not 100% sure about this */ - (!src[0]. - NegateBase) ? - VSF_FLAG_ALL : - VSF_FLAG_NONE - /*VSF_FLAG_ALL */ ); - - o_inst->src[2] = ZERO_SRC_0; - u_temp_i--; - goto next; - - case OPCODE_LG2: // LG2 RESULT 1.X Y Z W PARAM 0{} {X X X X} - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_LG2, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_src_class(src[0].File), - src[0]. - NegateBase ? VSF_FLAG_ALL : - VSF_FLAG_NONE) | (src[0]. - RelAddr << 4); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = ZERO_SRC_0; - goto next; - - case OPCODE_LIT: //LIT TMP 1.Y Z TMP 1{} {X W Z Y} TMP 1{} {Y W Z X} TMP 1{} {Y X Z W} - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_LIT, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - /* NOTE: Users swizzling might not work. */ - o_inst->src[0] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x - t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w - VSF_IN_COMPONENT_ZERO, // z - t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y - t_src_class(src[0]. - File), - src[0]. - NegateBase ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[0].RelAddr << 4); - o_inst->src[1] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y - t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w - VSF_IN_COMPONENT_ZERO, // z - t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x - t_src_class(src[0]. - File), - src[0]. - NegateBase ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[0].RelAddr << 4); - o_inst->src[2] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y - t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x - VSF_IN_COMPONENT_ZERO, // z - t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w - t_src_class(src[0]. - File), - src[0]. - NegateBase ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[0].RelAddr << 4); - goto next; - - case OPCODE_DPH: //DOT RESULT 1.X Y Z W PARAM 0{} {X Y Z ONE} PARAM 0{} {X Y Z W} - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_DOT, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = - MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), - t_swizzle(GET_SWZ - (src[0].Swizzle, 0)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 1)), - t_swizzle(GET_SWZ - (src[0].Swizzle, 2)), - VSF_IN_COMPONENT_ONE, - t_src_class(src[0].File), - src[0]. - NegateBase ? VSF_FLAG_XYZ : - VSF_FLAG_NONE) | (src[0]. - RelAddr << 4); - o_inst->src[1] = t_src(vp, &src[1]); - o_inst->src[2] = ZERO_SRC_1; - goto next; - - case OPCODE_XPD: - /* mul r0, r1.yzxw, r2.zxyw - mad r0, -r2.yzxw, r1.zxyw, r0 - NOTE: might need MAD_2 - */ - - o_inst->op = MAKE_VSF_OP(R300_VPI_OUT_OP_MAD, u_temp_i, - t_dst_mask(vpi->DstReg. - WriteMask), - VSF_OUT_CLASS_TMP); - - o_inst->src[0] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y - t_swizzle(GET_SWZ(src[0].Swizzle, 2)), // z - t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x - t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w - t_src_class(src[0]. - File), - src[0]. - NegateBase ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[0].RelAddr << 4); - - o_inst->src[1] = MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), t_swizzle(GET_SWZ(src[1].Swizzle, 2)), // z - t_swizzle(GET_SWZ(src[1].Swizzle, 0)), // x - t_swizzle(GET_SWZ(src[1].Swizzle, 1)), // y - t_swizzle(GET_SWZ(src[1].Swizzle, 3)), // w - t_src_class(src[1]. - File), - src[1]. - NegateBase ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[1].RelAddr << 4); - - o_inst->src[2] = ZERO_SRC_1; - o_inst++; - u_temp_i--; - - o_inst->op = - MAKE_VSF_OP(R300_VPI_OUT_OP_MAD, - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - o_inst->src[0] = MAKE_VSF_SOURCE(t_src_index(vp, &src[1]), t_swizzle(GET_SWZ(src[1].Swizzle, 1)), // y - t_swizzle(GET_SWZ(src[1].Swizzle, 2)), // z - t_swizzle(GET_SWZ(src[1].Swizzle, 0)), // x - t_swizzle(GET_SWZ(src[1].Swizzle, 3)), // w - t_src_class(src[1]. - File), - (!src[1]. - NegateBase) ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[1].RelAddr << 4); - - o_inst->src[1] = MAKE_VSF_SOURCE(t_src_index(vp, &src[0]), t_swizzle(GET_SWZ(src[0].Swizzle, 2)), // z - t_swizzle(GET_SWZ(src[0].Swizzle, 0)), // x - t_swizzle(GET_SWZ(src[0].Swizzle, 1)), // y - t_swizzle(GET_SWZ(src[0].Swizzle, 3)), // w - t_src_class(src[0]. - File), - src[0]. - NegateBase ? - VSF_FLAG_ALL : - VSF_FLAG_NONE) | - (src[0].RelAddr << 4); - - o_inst->src[2] = MAKE_VSF_SOURCE(u_temp_i + 1, - VSF_IN_COMPONENT_X, - VSF_IN_COMPONENT_Y, - VSF_IN_COMPONENT_Z, - VSF_IN_COMPONENT_W, - VSF_IN_CLASS_TMP, - VSF_FLAG_NONE); - - goto next; - - case OPCODE_RCC: - fprintf(stderr, "Dont know how to handle op %d yet\n", - vpi->Opcode); - _mesa_exit(-1); + inst = + t_opcode_flr(vp, vpi, inst, src, /* FIXME */ + &u_temp_i); + break; + case OPCODE_FRC: + inst = t_opcode_frc(vp, vpi, inst, src); + break; + case OPCODE_LG2: + inst = t_opcode_lg2(vp, vpi, inst, src); + break; + case OPCODE_LIT: + inst = t_opcode_lit(vp, vpi, inst, src); + break; + case OPCODE_LOG: + inst = t_opcode_log(vp, vpi, inst, src); + break; + case OPCODE_MAD: + inst = t_opcode_mad(vp, vpi, inst, src); + break; + case OPCODE_MAX: + inst = t_opcode_max(vp, vpi, inst, src); + break; + case OPCODE_MIN: + inst = t_opcode_min(vp, vpi, inst, src); + break; + case OPCODE_MOV: + inst = t_opcode_mov(vp, vpi, inst, src); break; - case OPCODE_END: + case OPCODE_MUL: + inst = t_opcode_mul(vp, vpi, inst, src); + break; + case OPCODE_POW: + inst = t_opcode_pow(vp, vpi, inst, src); + break; + case OPCODE_RCP: + inst = t_opcode_rcp(vp, vpi, inst, src); + break; + case OPCODE_RSQ: + inst = t_opcode_rsq(vp, vpi, inst, src); + break; + case OPCODE_SGE: + inst = t_opcode_sge(vp, vpi, inst, src); + break; + case OPCODE_SLT: + inst = t_opcode_slt(vp, vpi, inst, src); + break; + case OPCODE_SUB: + inst = t_opcode_sub(vp, vpi, inst, src); + break; + case OPCODE_SWZ: + inst = t_opcode_swz(vp, vpi, inst, src); + break; + case OPCODE_XPD: + inst = + t_opcode_xpd(vp, vpi, inst, src, /* FIXME */ + &u_temp_i); break; default: + assert(0); break; } - - o_inst->op = - MAKE_VSF_OP(t_opcode(vpi->Opcode), - t_dst_index(vp, &vpi->DstReg), - t_dst_mask(vpi->DstReg.WriteMask), - t_dst_class(vpi->DstReg.File)); - - if (are_srcs_scalar) { - switch (operands) { - case 1: - o_inst->src[0] = t_src_scalar(vp, &src[0]); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = ZERO_SRC_0; - break; - - case 2: - o_inst->src[0] = t_src_scalar(vp, &src[0]); - o_inst->src[1] = t_src_scalar(vp, &src[1]); - o_inst->src[2] = ZERO_SRC_1; - break; - - case 3: - o_inst->src[0] = t_src_scalar(vp, &src[0]); - o_inst->src[1] = t_src_scalar(vp, &src[1]); - o_inst->src[2] = t_src_scalar(vp, &src[2]); - break; - - default: - fprintf(stderr, - "scalars and op RCC not handled yet"); - _mesa_exit(-1); - break; - } - } else { - switch (operands) { - case 1: - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = ZERO_SRC_0; - o_inst->src[2] = ZERO_SRC_0; - break; - - case 2: - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = t_src(vp, &src[1]); - o_inst->src[2] = ZERO_SRC_1; - break; - - case 3: - o_inst->src[0] = t_src(vp, &src[0]); - o_inst->src[1] = t_src(vp, &src[1]); - o_inst->src[2] = t_src(vp, &src[2]); - break; - - default: - fprintf(stderr, - "scalars and op RCC not handled yet"); - _mesa_exit(-1); - break; - } - } - next:; } - /* Will most likely segfault before we get here... fix later. */ - if (o_inst - vp->program.body.i >= VSF_MAX_FRAGMENT_LENGTH / 4) { + vp->program.length = (inst - vp->program.body.i); + if (vp->program.length >= VSF_MAX_FRAGMENT_LENGTH) { vp->program.length = 0; vp->native = GL_FALSE; - return; } - vp->program.length = (o_inst - vp->program.body.i) * 4; #if 0 fprintf(stderr, "hw program:\n"); for (i = 0; i < vp->program.length; i++) @@ -1065,7 +1309,8 @@ static void position_invariant(struct gl_program *prog) struct gl_program_parameter_list *paramList; int i; - gl_state_index tokens[STATE_LENGTH] = { STATE_MVP_MATRIX, 0, 0, 0, 0 }; + gl_state_index tokens[STATE_LENGTH] = + { STATE_MVP_MATRIX, 0, 0, 0, 0 }; /* tokens[4] = matrix modifier */ #ifdef PREFER_DP4 @@ -1159,8 +1404,8 @@ static void insert_wpos(struct r300_vertex_program *vp, prog->NumInstructions - 1); /* END */ _mesa_copy_instructions(&vpi[prog->NumInstructions + 1], - &prog->Instructions[prog->NumInstructions - 1], - 1); + &prog->Instructions[prog->NumInstructions - + 1], 1); vpi_insert = &vpi[prog->NumInstructions - 1]; vpi_insert[i].Opcode = OPCODE_MOV; @@ -1206,8 +1451,8 @@ static void pos_as_texcoord(struct r300_vertex_program *vp, prog->NumTemporaries++; for (vpi = prog->Instructions; vpi->Opcode != OPCODE_END; vpi++) { - if (vpi->DstReg.File == PROGRAM_OUTPUT && - vpi->DstReg.Index == VERT_RESULT_HPOS) { + if (vpi->DstReg.File == PROGRAM_OUTPUT + && vpi->DstReg.Index == VERT_RESULT_HPOS) { vpi->DstReg.File = PROGRAM_TEMPORARY; vpi->DstReg.Index = tempregi; } @@ -1223,20 +1468,18 @@ static struct r300_vertex_program *build_program(struct r300_vertex_program_key vp = _mesa_calloc(sizeof(*vp)); _mesa_memcpy(&vp->key, wanted_key, sizeof(vp->key)); - vp->wpos_idx = wpos_idx; if (mesa_vp->IsPositionInvariant) { position_invariant(&mesa_vp->Base); } - if (wpos_idx > -1) + if (wpos_idx > -1) { pos_as_texcoord(vp, &mesa_vp->Base); + } assert(mesa_vp->Base.NumInstructions); - vp->num_temporaries = mesa_vp->Base.NumTemporaries; - r300TranslateVertexShader(vp, mesa_vp->Base.Instructions); return vp; @@ -1252,11 +1495,10 @@ void r300SelectVertexShader(r300ContextPtr r300) struct r300_vertex_program *vp; GLint wpos_idx; - vpc = (struct r300_vertex_program_cont *)ctx->VertexProgram._Current; + vpc = + (struct r300_vertex_program_cont *)ctx->VertexProgram._Current; InputsRead = ctx->FragmentProgram._Current->Base.InputsRead; - wanted_key.OutputsWritten |= 1 << VERT_RESULT_HPOS; - wpos_idx = -1; if (InputsRead & FRAG_BIT_WPOS) { for (i = 0; i < ctx->Const.MaxTextureUnits; i++) @@ -1271,28 +1513,35 @@ void r300SelectVertexShader(r300ContextPtr r300) InputsRead |= (FRAG_BIT_TEX0 << i); wpos_idx = i; } + wanted_key.InputsRead = vpc->mesa_program.Base.InputsRead; + wanted_key.OutputsWritten = vpc->mesa_program.Base.OutputsWritten; + + wanted_key.OutputsWritten |= 1 << VERT_RESULT_HPOS; - if (InputsRead & FRAG_BIT_COL0) + if (InputsRead & FRAG_BIT_COL0) { wanted_key.OutputsWritten |= 1 << VERT_RESULT_COL0; + } - if ((InputsRead & FRAG_BIT_COL1) /*|| - (InputsRead & FRAG_BIT_FOGC) */ ) + if ((InputsRead & FRAG_BIT_COL1)) { wanted_key.OutputsWritten |= 1 << VERT_RESULT_COL1; + } - for (i = 0; i < ctx->Const.MaxTextureUnits; i++) - if (InputsRead & (FRAG_BIT_TEX0 << i)) + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { + if (InputsRead & (FRAG_BIT_TEX0 << i)) { wanted_key.OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i); + } + } - wanted_key.InputsRead = vpc->mesa_program.Base.InputsRead; if (vpc->mesa_program.IsPositionInvariant) { /* we wan't position don't we ? */ wanted_key.InputsRead |= (1 << VERT_ATTRIB_POS); + wanted_key.OutputsWritten |= (1 << VERT_RESULT_HPOS); } for (vp = vpc->progs; vp; vp = vp->next) - if (_mesa_memcmp(&vp->key, &wanted_key, sizeof(wanted_key)) == - 0) { + if (_mesa_memcmp(&vp->key, &wanted_key, sizeof(wanted_key)) + == 0) { r300->selected_vp = vp; return; } diff --git a/src/mesa/drivers/dri/r300/r300_vertprog.h b/src/mesa/drivers/dri/r300/r300_vertprog.h index 252d5a901f..3df0eee799 100644 --- a/src/mesa/drivers/dri/r300/r300_vertprog.h +++ b/src/mesa/drivers/dri/r300/r300_vertprog.h @@ -3,11 +3,6 @@ #include "r300_reg.h" -typedef struct { - GLuint op; - GLuint src[3]; -} VERTEX_SHADER_INSTRUCTION; - #define VSF_FLAG_X 1 #define VSF_FLAG_Y 2 #define VSF_FLAG_Z 4 diff --git a/src/mesa/drivers/dri/savage/savagetris.c b/src/mesa/drivers/dri/savage/savagetris.c index 3dd821a4d3..4ce2f60b4f 100644 --- a/src/mesa/drivers/dri/savage/savagetris.c +++ b/src/mesa/drivers/dri/savage/savagetris.c @@ -131,7 +131,9 @@ static __inline__ void savage_draw_point (savageContextPtr imesa, u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize); const GLfloat x = tmp->v.x; const GLfloat y = tmp->v.y; - const GLfloat sz = imesa->glCtx->Point._Size * .5; + const GLfloat sz = 0.5 * CLAMP(imesa->glCtx->Point.Size, + imesa->glCtx->Const.MinPointSize, + imesa->glCtx->Const.MaxPointSize); GLuint j; *(float *)&vb[0] = x - sz; @@ -164,7 +166,9 @@ static __inline__ void savage_draw_line (savageContextPtr imesa, savageVertexPtr v1 ) { GLuint vertsize = imesa->HwVertexSize; u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize); - GLfloat width = imesa->glCtx->Line._Width; + const GLfloat width = CLAMP(imesa->glCtx->Line.Width, + imesa->glCtx->Const.MinLineWidth, + imesa->glCtx->Const.MaxLineWidth); GLfloat dx, dy, ix, iy; GLuint j; @@ -234,7 +238,9 @@ static __inline__ void savage_ptex_line (savageContextPtr imesa, savageVertexPtr v1 ) { GLuint vertsize = imesa->HwVertexSize; u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize); - GLfloat width = imesa->glCtx->Line._Width; + const GLfloat width = CLAMP(imesa->glCtx->Line.Width, + imesa->glCtx->Const.MinLineWidth, + imesa->glCtx->Const.MaxLineWidth); GLfloat dx, dy, ix, iy; savageVertex tmp0, tmp1; GLuint j; @@ -281,7 +287,9 @@ static __inline__ void savage_ptex_point (savageContextPtr imesa, u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize); const GLfloat x = v0->v.x; const GLfloat y = v0->v.y; - const GLfloat sz = imesa->glCtx->Point._Size * .5; + const GLfloat sz = 0.5 * CLAMP(imesa->glCtx->Point.Size, + imesa->glCtx->Const.MinPointSize, + imesa->glCtx->Const.MaxPointSize); savageVertex tmp; GLuint j; diff --git a/src/mesa/drivers/dri/sis/sis_tex.c b/src/mesa/drivers/dri/sis/sis_tex.c index be87f16e29..8fd7b26ba5 100644 --- a/src/mesa/drivers/dri/sis/sis_tex.c +++ b/src/mesa/drivers/dri/sis/sis_tex.c @@ -130,6 +130,8 @@ sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level, static void sisFreeTexImage( sisContextPtr smesa, sisTexObjPtr t, int level ) { + assert(level >= 0); + assert(level < SIS_MAX_TEXTURE_LEVELS); if (t->image[level].Data == NULL) return; @@ -213,7 +215,7 @@ sisDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj ) */ return; } - for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { + for (i = 0; i < SIS_MAX_TEXTURE_LEVELS; i++) { sisFreeTexImage( smesa, t, i ); } diff --git a/src/mesa/drivers/dri/tdfx/tdfx_tex.c b/src/mesa/drivers/dri/tdfx/tdfx_tex.c index 89865d9637..64946385b6 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_tex.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_tex.c @@ -1822,7 +1822,7 @@ tdfxTestProxyTexImage(GLcontext *ctx, GLenum target, tdfxTexInfo *ti; int memNeeded; - tObj = ctx->Texture.Proxy2D; + tObj = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; if (!tObj->DriverData) tObj->DriverData = fxAllocTexObjData(fxMesa); ti = TDFX_TEXTURE_DATA(tObj); diff --git a/src/mesa/drivers/dri/tdfx/tdfx_tris.c b/src/mesa/drivers/dri/tdfx/tdfx_tris.c index 96f9ae27fc..7252a7e7dc 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_tris.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_tris.c @@ -184,7 +184,7 @@ tdfx_translate_vertex( GLcontext *ctx, const tdfxVertex *src, SWvertex *dst) } } - dst->pointSize = ctx->Point._Size; + dst->pointSize = ctx->Point.Size; } diff --git a/src/mesa/drivers/dri/unichrome/via_context.c b/src/mesa/drivers/dri/unichrome/via_context.c index 4d25d328e3..7c73877720 100644 --- a/src/mesa/drivers/dri/unichrome/via_context.c +++ b/src/mesa/drivers/dri/unichrome/via_context.c @@ -733,14 +733,15 @@ void viaXMesaWindowMoved(struct via_context *vmesa) { __DRIdrawablePrivate *const drawable = vmesa->driDrawable; __DRIdrawablePrivate *const readable = vmesa->driReadable; - struct via_renderbuffer *const draw_buffer = - (struct via_renderbuffer *) drawable->driverPrivate; - struct via_renderbuffer *const read_buffer = - (struct via_renderbuffer *) readable->driverPrivate; + struct via_renderbuffer * draw_buffer; + struct via_renderbuffer * read_buffer; GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3; if (!drawable) return; + + draw_buffer = (struct via_renderbuffer *) drawable->driverPrivate; + read_buffer = (struct via_renderbuffer *) readable->driverPrivate; switch (vmesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0]) { case BUFFER_BIT_BACK_LEFT: diff --git a/src/mesa/drivers/fbdev/glfbdev.c b/src/mesa/drivers/fbdev/glfbdev.c index 6c6511b7e5..e95a424698 100644 --- a/src/mesa/drivers/fbdev/glfbdev.c +++ b/src/mesa/drivers/fbdev/glfbdev.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.1 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -63,6 +63,9 @@ #include "drivers/common/driverfuncs.h" +/** + * Pixel formats we support: + */ #define PF_B8G8R8 1 #define PF_B8G8R8A8 2 #define PF_B5G6R5 3 @@ -70,7 +73,7 @@ #define PF_CI8 5 -/* +/** * Derived from Mesa's GLvisual class. */ struct GLFBDevVisualRec { @@ -80,7 +83,7 @@ struct GLFBDevVisualRec { int pixelFormat; }; -/* +/** * Derived from Mesa's GLframebuffer class. */ struct GLFBDevBufferRec { @@ -92,7 +95,7 @@ struct GLFBDevBufferRec { GLuint bytesPerPixel; }; -/* +/** * Derived from Mesa's GLcontext class. */ struct GLFBDevContextRec { @@ -103,7 +106,7 @@ struct GLFBDevContextRec { GLFBDevBufferPtr curBuffer; }; -/* +/** * Derived from Mesa's gl_renderbuffer class. */ struct GLFBDevRenderbufferRec { @@ -114,11 +117,6 @@ struct GLFBDevRenderbufferRec { }; - -#define GLFBDEV_CONTEXT(CTX) ((GLFBDevContextPtr) (CTX)) -#define GLFBDEV_BUFFER(BUF) ((GLFBDevBufferPtr) (BUF)) - - /**********************************************************************/ /* Internal device driver functions */ /**********************************************************************/ @@ -151,7 +149,7 @@ update_state( GLcontext *ctx, GLuint new_state ) static void get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { - const GLFBDevBufferPtr fbdevbuffer = GLFBDEV_BUFFER(buffer); + const GLFBDevBufferPtr fbdevbuffer = (GLFBDevBufferPtr) buffer; *width = fbdevbuffer->var.xres; *height = fbdevbuffer->var.yres; } @@ -389,8 +387,8 @@ glFBDevCreateVisual( const struct fb_fix_screeninfo *fixInfo, /* ignored for now */ break; case GLFBDEV_MULTISAMPLE: - numSamples = attrib[1]; - attrib++; + numSamples = attrib[1]; + attrib++; break; default: /* unexpected token */ @@ -406,36 +404,36 @@ glFBDevCreateVisual( const struct fb_fix_screeninfo *fixInfo, alphaBits = varInfo->transp.length; if (fixInfo->visual == FB_VISUAL_TRUECOLOR || - fixInfo->visual == FB_VISUAL_DIRECTCOLOR) { - if(varInfo->bits_per_pixel == 24 - && varInfo->red.offset == 16 - && varInfo->green.offset == 8 - && varInfo->blue.offset == 0) - vis->pixelFormat = PF_B8G8R8; - - else if(varInfo->bits_per_pixel == 32 - && varInfo->red.offset == 16 - && varInfo->green.offset == 8 - && varInfo->blue.offset == 0) - vis->pixelFormat = PF_B8G8R8A8; - - else if(varInfo->bits_per_pixel == 16 - && varInfo->red.offset == 11 - && varInfo->green.offset == 5 - && varInfo->blue.offset == 0) - vis->pixelFormat = PF_B5G6R5; - - else if(varInfo->bits_per_pixel == 16 - && varInfo->red.offset == 10 - && varInfo->green.offset == 5 - && varInfo->blue.offset == 0) - vis->pixelFormat = PF_B5G5R5; - - else { - _mesa_problem(NULL, "Unsupported fbdev RGB visual/bitdepth!\n"); - _mesa_free(vis); - return NULL; - } + fixInfo->visual == FB_VISUAL_DIRECTCOLOR) { + if (varInfo->bits_per_pixel == 24 + && varInfo->red.offset == 16 + && varInfo->green.offset == 8 + && varInfo->blue.offset == 0) { + vis->pixelFormat = PF_B8G8R8; + } + else if (varInfo->bits_per_pixel == 32 + && varInfo->red.offset == 16 + && varInfo->green.offset == 8 + && varInfo->blue.offset == 0) { + vis->pixelFormat = PF_B8G8R8A8; + } + else if (varInfo->bits_per_pixel == 16 + && varInfo->red.offset == 11 + && varInfo->green.offset == 5 + && varInfo->blue.offset == 0) { + vis->pixelFormat = PF_B5G6R5; + } + else if (varInfo->bits_per_pixel == 16 + && varInfo->red.offset == 10 + && varInfo->green.offset == 5 + && varInfo->blue.offset == 0) { + vis->pixelFormat = PF_B5G5R5; + } + else { + _mesa_problem(NULL, "Unsupported fbdev RGB visual/bitdepth!\n"); + _mesa_free(vis); + return NULL; + } } } else { @@ -578,7 +576,7 @@ new_glfbdev_renderbuffer(void *bufferStart, const GLFBDevVisualPtr visual) rb->rowStride = visual->var.xres_virtual * visual->var.bits_per_pixel / 8; rb->bottom = (GLubyte *) bufferStart - + (visual->var.yres - 1) * rb->rowStride; + + (visual->var.yres - 1) * rb->rowStride; rb->Base.Width = visual->var.xres; rb->Base.Height = visual->var.yres; @@ -635,7 +633,7 @@ glFBDevCreateBuffer( const struct fb_fix_screeninfo *fixInfo, &frontrb->Base); /* add back renderbuffer */ if (visual->glvisual.doubleBufferMode) { - int malloced = !backBuffer; + const int malloced = !backBuffer; if (malloced) { /* malloc a back buffer */ backBuffer = _mesa_malloc(size); @@ -647,8 +645,11 @@ glFBDevCreateBuffer( const struct fb_fix_screeninfo *fixInfo, } backrb = new_glfbdev_renderbuffer(backBuffer, visual); - if(malloced) - backrb->mallocedBuffer = GL_TRUE; + if (!backrb) { + /* out of mem */ + return NULL; + } + backrb->mallocedBuffer = malloced; _mesa_add_renderbuffer(&buf->glframebuffer, BUFFER_BACK_LEFT, &backrb->Base); @@ -682,16 +683,10 @@ glFBDevDestroyBuffer( GLFBDevBufferPtr buffer ) if (buffer == curDraw || buffer == curRead) { glFBDevMakeCurrent( NULL, NULL, NULL); } -#if 0 - /* free the software depth, stencil, accum buffers */ - _mesa_free_framebuffer_data(&buffer->glframebuffer); - _mesa_free(buffer); -#else { struct gl_framebuffer *fb = &buffer->glframebuffer; _mesa_unreference_framebuffer(&fb); } -#endif } } diff --git a/src/mesa/drivers/windows/gdi/wgl.c b/src/mesa/drivers/windows/gdi/wgl.c index fb23d210db..dad3dc1160 100644 --- a/src/mesa/drivers/windows/gdi/wgl.c +++ b/src/mesa/drivers/windows/gdi/wgl.c @@ -33,15 +33,30 @@ /* We're essentially building part of GDI here, so define this so that * we get the right export linkage. */ #ifdef __MINGW32__ -#include <GL/gl.h> + +#include <stdarg.h> +#include <windef.h> +#include <wincon.h> +#include <winbase.h> + +# if defined(BUILD_GL32) +# define WINGDIAPI __declspec(dllexport) +# else +# define __W32API_USE_DLLIMPORT__ +# endif + +#include <wingdi.h> +#include "GL/mesa_wgl.h" #include <stdlib.h> + #else + #define _GDI32_ -#endif #include <windows.h> -#include "glapi.h" +#endif +#include "glapi.h" #include "GL/wmesa.h" /* protos for wmesa* functions */ /* @@ -339,7 +354,7 @@ WINGDIAPI int GLAPIENTRY wglGetPixelFormat(HDC hdc) } WINGDIAPI BOOL GLAPIENTRY wglSetPixelFormat(HDC hdc,int iPixelFormat, - const PIXELFORMATDESCRIPTOR *ppfd) + const PIXELFORMATDESCRIPTOR *ppfd) { (void) hdc; @@ -392,12 +407,12 @@ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar, bitDevice = CreateCompatibleDC(fontDevice); - // Swap fore and back colors so the bitmap has the right polarity + /* Swap fore and back colors so the bitmap has the right polarity */ tempColor = GetBkColor(bitDevice); SetBkColor(bitDevice, GetTextColor(bitDevice)); SetTextColor(bitDevice, tempColor); - // Place chars based on base line + /* Place chars based on base line */ VERIFY(SetTextAlign(bitDevice, TA_BASELINE) != GDI_ERROR ? 1 : 0); for(i = 0; i < (int)numChars; i++) { @@ -410,36 +425,36 @@ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar, curChar = (char)(i + firstChar); - // Find how high/wide this character is + /* Find how high/wide this character is */ VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size)); - // Create the output bitmap + /* Create the output bitmap */ charWidth = size.cx; charHeight = size.cy; - // Round up to the next multiple of 32 bits + /* Round up to the next multiple of 32 bits */ bmapWidth = ((charWidth + 31) / 32) * 32; bmapHeight = charHeight; bitObject = CreateCompatibleBitmap(bitDevice, bmapWidth, bmapHeight); - //VERIFY(bitObject); + /* VERIFY(bitObject); */ - // Assign the output bitmap to the device + /* Assign the output bitmap to the device */ origBmap = SelectObject(bitDevice, bitObject); (void) VERIFY(origBmap); VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) ); - // Use our source font on the device + /* Use our source font on the device */ VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT))); - // Draw the character + /* Draw the character */ VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1)); - // Unselect our bmap object + /* Unselect our bmap object */ VERIFY(SelectObject(bitDevice, origBmap)); - // Convert the display dependant representation to a 1 bit deep DIB + /* Convert the display dependant representation to a 1 bit deep DIB */ numBytes = (bmapWidth * bmapHeight) / 8; bmap = malloc(numBytes); dibInfo->bmiHeader.biWidth = bmapWidth; @@ -447,24 +462,24 @@ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar, res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap, dibInfo, DIB_RGB_COLORS); - //VERIFY(res); + /* VERIFY(res); */ - // Create the GL object + /* Create the GL object */ glNewList(i + listBase, GL_COMPILE); glBitmap(bmapWidth, bmapHeight, 0.0, (GLfloat)metric.tmDescent, (GLfloat)charWidth, 0.0, bmap); glEndList(); - // CheckGL(); + /* CheckGL(); */ - // Destroy the bmap object + /* Destroy the bmap object */ DeleteObject(bitObject); - // Deallocate the bitmap data + /* Deallocate the bitmap data */ free(bmap); } - // Destroy the DC + /* Destroy the DC */ VERIFY(DeleteDC(bitDevice)); free(dibInfo); diff --git a/src/mesa/drivers/windows/gdi/wmesa.c b/src/mesa/drivers/windows/gdi/wmesa.c index 2eec188912..5b67439f0f 100644 --- a/src/mesa/drivers/windows/gdi/wmesa.c +++ b/src/mesa/drivers/windows/gdi/wmesa.c @@ -6,6 +6,7 @@ #include "wmesadef.h" #include "colors.h" #include <GL/wmesa.h> +#include <winuser.h> #include "context.h" #include "extensions.h" #include "framebuffer.h" @@ -114,7 +115,7 @@ static void wmSetPixelFormat(WMesaFramebuffer pwfb, HDC hDC) { pwfb->cColorBits = GetDeviceCaps(hDC, BITSPIXEL); - // Only 16 and 32 bit targets are supported now + /* Only 16 and 32 bit targets are supported now */ assert(pwfb->cColorBits == 0 || pwfb->cColorBits == 16 || pwfb->cColorBits == 32); @@ -1171,7 +1172,7 @@ WMesaContext WMesaCreateContext(HDC hDC, /* I do not understand this contributed code */ /* Support memory and device contexts */ if(WindowFromDC(hDC) != NULL) { - c->hDC = GetDC(WindowFromDC(hDC)); // huh ???? + c->hDC = GetDC(WindowFromDC(hDC)); /* huh ???? */ } else { c->hDC = hDC; @@ -1404,6 +1405,7 @@ void WMesaSwapBuffers( HDC hdc ) * table entries. Hopefully, I'll find a better solution. The * dispatch table generation scripts ought to be making these dummy * stubs as well. */ +#if !defined(__MINGW32__) || !defined(GL_NO_STDCALL) void gl_dispatch_stub_543(void){} void gl_dispatch_stub_544(void){} void gl_dispatch_stub_545(void){} @@ -1471,3 +1473,4 @@ void gl_dispatch_stub_769(void){} void gl_dispatch_stub_770(void){} void gl_dispatch_stub_771(void){} +#endif diff --git a/src/mesa/drivers/windows/gdi/wmesadef.h b/src/mesa/drivers/windows/gdi/wmesadef.h index 97b063a8ba..83a42e6082 100644 --- a/src/mesa/drivers/windows/gdi/wmesadef.h +++ b/src/mesa/drivers/windows/gdi/wmesadef.h @@ -1,6 +1,8 @@ #ifndef WMESADEF_H #define WMESADEF_H - +#ifdef __MINGW32__ +#include <windows.h> +#endif #include "context.h" diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c index 1587df66bc..7a170b4d3d 100644 --- a/src/mesa/drivers/x11/fakeglx.c +++ b/src/mesa/drivers/x11/fakeglx.c @@ -296,6 +296,11 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo, } } + if (stereoFlag) { + /* stereo not supported */ + return NULL; + } + /* Comparing IDs uses less memory but sometimes fails. */ /* XXX revisit this after 3.0 is finished. */ if (_mesa_getenv("MESA_GLX_VISUAL_HACK")) @@ -1079,7 +1084,7 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig ) else { stereo_flag = GL_TRUE; } - return NULL; /* stereo not supported */ + break; case GLX_AUX_BUFFERS: parselist++; numAux = *parselist++; diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c index 1899975213..72091b0789 100644 --- a/src/mesa/main/api_arrayelt.c +++ b/src/mesa/main/api_arrayelt.c @@ -31,8 +31,8 @@ #include "context.h" #include "imports.h" #include "macros.h" -#include "glapioffsets.h" -#include "dispatch.h" +#include "glapi/glapioffsets.h" +#include "glapi/dispatch.h" typedef void (GLAPIENTRY *array_func)( const void * ); diff --git a/src/mesa/main/api_loopback.c b/src/mesa/main/api_loopback.c index efe5a77d58..924d7134a2 100644 --- a/src/mesa/main/api_loopback.c +++ b/src/mesa/main/api_loopback.c @@ -30,14 +30,14 @@ #include "glheader.h" -#include "glapi.h" -#include "glapitable.h" #include "macros.h" #include "colormac.h" #include "api_loopback.h" -#include "glthread.h" #include "mtypes.h" -#include "dispatch.h" +#include "glapi/glapi.h" +#include "glapi/glapitable.h" +#include "glapi/glthread.h" +#include "glapi/dispatch.h" /* KW: A set of functions to convert unusual Color/Normal/Vertex/etc * calls to a smaller set of driver-provided formats. Currently just diff --git a/src/mesa/main/api_noop.c b/src/mesa/main/api_noop.c index 0c1a35361f..3df64362ea 100644 --- a/src/mesa/main/api_noop.c +++ b/src/mesa/main/api_noop.c @@ -31,7 +31,7 @@ #include "light.h" #include "macros.h" #include "dlist.h" -#include "dispatch.h" +#include "glapi/dispatch.h" /** diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c index 3d20ba7d14..18dead61c3 100644 --- a/src/mesa/main/api_validate.c +++ b/src/mesa/main/api_validate.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.1 + * Version: 7.0.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -35,6 +35,7 @@ _mesa_validate_DrawElements(GLcontext *ctx, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { + GLboolean mapped = GL_FALSE; ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); if (count <= 0) { @@ -67,13 +68,19 @@ _mesa_validate_DrawElements(GLcontext *ctx, /* Vertex buffer object tests */ if (ctx->Array.ElementArrayBufferObj->Name) { GLuint indexBytes; + const GLvoid *map = ctx->Driver.MapBuffer(ctx, + GL_ELEMENT_ARRAY_BUFFER_ARB, + GL_READ_ONLY, + ctx->Array.ElementArrayBufferObj); /* use indices in the buffer object */ - if (!ctx->Array.ElementArrayBufferObj->Data) { + if (!map) { _mesa_warning(ctx, "DrawElements with empty vertex elements buffer!"); return GL_FALSE; } + mapped = GL_TRUE; + /* make sure count doesn't go outside buffer bounds */ if (type == GL_UNSIGNED_INT) { indexBytes = count * sizeof(GLuint); @@ -86,20 +93,25 @@ _mesa_validate_DrawElements(GLcontext *ctx, indexBytes = count * sizeof(GLushort); } - if ((GLubyte *) indices + indexBytes > - ctx->Array.ElementArrayBufferObj->Data + - ctx->Array.ElementArrayBufferObj->Size) { + if (ADD_POINTERS(map, indices) + indexBytes > + (GLubyte *)map + ctx->Array.ElementArrayBufferObj->Size) { _mesa_warning(ctx, "glDrawElements index out of buffer bounds"); + ctx->Driver.UnmapBuffer(ctx, + GL_ELEMENT_ARRAY_BUFFER_ARB, + ctx->Array.ElementArrayBufferObj); return GL_FALSE; } /* Actual address is the sum of pointers. Indices may be used below. */ if (ctx->Const.CheckArrayBounds) { - indices = (const GLvoid *) - ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data, - (const GLubyte *) indices); + indices = ADD_POINTERS(map, indices); } } + else { + /* not using a VBO */ + if (!indices) + return GL_FALSE; + } if (ctx->Const.CheckArrayBounds) { /* find max array index */ @@ -121,12 +133,25 @@ _mesa_validate_DrawElements(GLcontext *ctx, if (((GLubyte *) indices)[i] > max) max = ((GLubyte *) indices)[i]; } + if (max >= ctx->Array._MaxElement) { /* the max element is out of bounds of one or more enabled arrays */ + if (mapped) { + ctx->Driver.UnmapBuffer(ctx, + GL_ELEMENT_ARRAY_BUFFER_ARB, + ctx->Array.ElementArrayBufferObj); + } + return GL_FALSE; } } + if (mapped) { + ctx->Driver.UnmapBuffer(ctx, + GL_ELEMENT_ARRAY_BUFFER_ARB, + ctx->Array.ElementArrayBufferObj); + } + return GL_TRUE; } @@ -170,6 +195,16 @@ _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, && !(ctx->VertexProgram._Enabled && ctx->Array.ArrayObj->VertexAttrib[0].Enabled)) return GL_FALSE; + /* Vertex buffer object tests */ + if (ctx->Array.ElementArrayBufferObj->Name) { + /* XXX re-use code from above? */ + } + else { + /* not using VBO */ + if (!indices) + return GL_FALSE; + } + if (ctx->Const.CheckArrayBounds) { /* Find max array index. * We don't trust the user's start and end values. diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c index d601ee461e..f08f99d8e1 100644 --- a/src/mesa/main/arrayobj.c +++ b/src/mesa/main/arrayobj.c @@ -46,7 +46,7 @@ #include "bufferobj.h" #endif #include "arrayobj.h" -#include "dispatch.h" +#include "glapi/dispatch.h" /** diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index b422198f92..3199c9b426 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -52,6 +52,24 @@ /** + * Special struct for saving/restoring texture state (GL_TEXTURE_BIT) + */ +struct texture_state +{ + struct gl_texture_attrib Texture; /**< The usual context state */ + + /** to save per texture object state (wrap modes, filters, etc): */ + struct gl_texture_object SavedObj[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS]; + + /** + * To save references to texture objects (so they don't get accidentally + * deleted while saved in the attribute stack). + */ + struct gl_texture_object *SavedTexRef[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS]; +}; + + +/** * Allocate a new attribute state node. These nodes have a * "kind" value and a pointer to a struct of state data. */ @@ -339,46 +357,61 @@ _mesa_PushAttrib(GLbitfield mask) } if (mask & GL_TEXTURE_BIT) { - struct gl_texture_attrib *attr; + struct texture_state *texstate = CALLOC_STRUCT(texture_state); GLuint u; + if (!texstate) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib(GL_TEXTURE_BIT)"); + goto end; + } + _mesa_lock_context_textures(ctx); - /* Bump the texture object reference counts so that they don't - * inadvertantly get deleted. + + /* copy/save the bulk of texture state here */ + _mesa_memcpy(&texstate->Texture, &ctx->Texture, sizeof(ctx->Texture)); + + /* Save references to the currently bound texture objects so they don't + * accidentally get deleted while referenced in the attribute stack. */ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - ctx->Texture.Unit[u].Current1D->RefCount++; - ctx->Texture.Unit[u].Current2D->RefCount++; - ctx->Texture.Unit[u].Current3D->RefCount++; - ctx->Texture.Unit[u].CurrentCubeMap->RefCount++; - ctx->Texture.Unit[u].CurrentRect->RefCount++; - ctx->Texture.Unit[u].Current1DArray->RefCount++; - ctx->Texture.Unit[u].Current2DArray->RefCount++; + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_1D_INDEX], + ctx->Texture.Unit[u].Current1D); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_2D_INDEX], + ctx->Texture.Unit[u].Current2D); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_3D_INDEX], + ctx->Texture.Unit[u].Current3D); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_CUBE_INDEX], + ctx->Texture.Unit[u].CurrentCubeMap); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_RECT_INDEX], + ctx->Texture.Unit[u].CurrentRect); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_1D_ARRAY_INDEX], + ctx->Texture.Unit[u].Current1DArray); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_2D_ARRAY_INDEX], + ctx->Texture.Unit[u].Current2DArray); } - attr = MALLOC_STRUCT( gl_texture_attrib ); - MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) ); - /* copy state of the currently bound texture objects */ + + /* copy state/contents of the currently bound texture objects */ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - _mesa_copy_texture_object(&attr->Unit[u].Saved1D, - attr->Unit[u].Current1D); - _mesa_copy_texture_object(&attr->Unit[u].Saved2D, - attr->Unit[u].Current2D); - _mesa_copy_texture_object(&attr->Unit[u].Saved3D, - attr->Unit[u].Current3D); - _mesa_copy_texture_object(&attr->Unit[u].SavedCubeMap, - attr->Unit[u].CurrentCubeMap); - _mesa_copy_texture_object(&attr->Unit[u].SavedRect, - attr->Unit[u].CurrentRect); - _mesa_copy_texture_object(&attr->Unit[u].Saved1DArray, - attr->Unit[u].Current1DArray); - _mesa_copy_texture_object(&attr->Unit[u].Saved2DArray, - attr->Unit[u].Current2DArray); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_1D_INDEX], + ctx->Texture.Unit[u].Current1D); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_2D_INDEX], + ctx->Texture.Unit[u].Current2D); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_3D_INDEX], + ctx->Texture.Unit[u].Current3D); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_CUBE_INDEX], + ctx->Texture.Unit[u].CurrentCubeMap); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_RECT_INDEX], + ctx->Texture.Unit[u].CurrentRect); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_1D_ARRAY_INDEX], + ctx->Texture.Unit[u].Current1DArray); + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_2D_ARRAY_INDEX], + ctx->Texture.Unit[u].Current2DArray); } _mesa_unlock_context_textures(ctx); newnode = new_attrib_node( GL_TEXTURE_BIT ); - newnode->data = attr; + newnode->data = texstate; newnode->next = head; head = newnode; } @@ -414,6 +447,7 @@ _mesa_PushAttrib(GLbitfield mask) head = newnode; } +end: ctx->AttribStack[ctx->AttribStackDepth] = head; ctx->AttribStackDepth++; } @@ -623,14 +657,19 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable) } +/** + * Pop/restore texture attribute/group state. + */ static void -pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib) +pop_texture_group(GLcontext *ctx, struct texture_state *texstate) { GLuint u; + _mesa_lock_context_textures(ctx); + for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - const struct gl_texture_unit *unit = &texAttrib->Unit[u]; - GLuint i; + const struct gl_texture_unit *unit = &texstate->Texture.Unit[u]; + GLuint tgt; _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + u); _mesa_set_enable(ctx, GL_TEXTURE_1D, @@ -723,53 +762,33 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib) 1 << unit->Combine.ScaleShiftA); } - /* Restore texture object state */ - for (i = 0; i < NUM_TEXTURE_TARGETS; i++) { - GLenum target = 0; + /* Restore texture object state for each target */ + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { const struct gl_texture_object *obj = NULL; GLfloat bordColor[4]; + GLenum target; - switch (i) { - case 0: - target = GL_TEXTURE_1D; - obj = &unit->Saved1D; - break; - case 1: - target = GL_TEXTURE_2D; - obj = &unit->Saved2D; - break; - case 2: - target = GL_TEXTURE_3D; - obj = &unit->Saved3D; - break; - case 3: - if (!ctx->Extensions.ARB_texture_cube_map) - continue; - target = GL_TEXTURE_CUBE_MAP_ARB; - obj = &unit->SavedCubeMap; - break; - case 4: - if (!ctx->Extensions.NV_texture_rectangle) - continue; - target = GL_TEXTURE_RECTANGLE_NV; - obj = &unit->SavedRect; - break; - case 5: - if (!ctx->Extensions.MESA_texture_array) - continue; - target = GL_TEXTURE_1D_ARRAY_EXT; - obj = &unit->Saved1DArray; - break; - case 6: - if (!ctx->Extensions.MESA_texture_array) - continue; - target = GL_TEXTURE_2D_ARRAY_EXT; - obj = &unit->Saved2DArray; - break; - default: - ; /* silence warnings */ + obj = &texstate->SavedObj[u][tgt]; + + /* don't restore state for unsupported targets to prevent + * raising GL errors. + */ + if (obj->Target == GL_TEXTURE_CUBE_MAP_ARB && + !ctx->Extensions.ARB_texture_cube_map) { + continue; + } + else if (obj->Target == GL_TEXTURE_RECTANGLE_NV && + !ctx->Extensions.NV_texture_rectangle) { + continue; + } + else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT || + obj->Target == GL_TEXTURE_2D_ARRAY_EXT) && + !ctx->Extensions.MESA_texture_array) { + continue; } + target = obj->Target; + _mesa_BindTexture(target, obj->Name); bordColor[0] = CHAN_TO_FLOAT(obj->BorderColor[0]); @@ -777,8 +796,8 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib) bordColor[2] = CHAN_TO_FLOAT(obj->BorderColor[2]); bordColor[3] = CHAN_TO_FLOAT(obj->BorderColor[3]); - _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority); _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, bordColor); + _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority); _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS); _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT); _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR); @@ -804,25 +823,17 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib) _mesa_TexParameterf(target, GL_SHADOW_AMBIENT_SGIX, obj->ShadowAmbient); } + } + /* remove saved references to the texture objects */ + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL); } } - _mesa_ActiveTextureARB(GL_TEXTURE0_ARB - + texAttrib->CurrentUnit); - /* "un-bump" the texture object reference counts. We did that so they - * wouldn't inadvertantly get deleted while they were still referenced - * inside the attribute state stack. - */ - for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - ctx->Texture.Unit[u].Current1D->RefCount--; - ctx->Texture.Unit[u].Current2D->RefCount--; - ctx->Texture.Unit[u].Current3D->RefCount--; - ctx->Texture.Unit[u].CurrentCubeMap->RefCount--; - ctx->Texture.Unit[u].CurrentRect->RefCount--; - ctx->Texture.Unit[u].Current1DArray->RefCount--; - ctx->Texture.Unit[u].Current2DArray->RefCount--; - } + _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit); + + _mesa_unlock_context_textures(ctx); } @@ -1201,9 +1212,9 @@ _mesa_PopAttrib(void) case GL_TEXTURE_BIT: /* Take care of texture object reference counters */ { - const struct gl_texture_attrib *texture; - texture = (const struct gl_texture_attrib *) attr->data; - pop_texture_group(ctx, texture); + struct texture_state *texstate + = (struct texture_state *) attr->data; + pop_texture_group(ctx, texstate); ctx->NewState |= _NEW_TEXTURE; } break; @@ -1425,6 +1436,42 @@ _mesa_PopClientAttrib(void) } +/** + * Free any attribute state data that might be attached to the context. + */ +void +_mesa_free_attrib_data(GLcontext *ctx) +{ + while (ctx->AttribStackDepth > 0) { + struct gl_attrib_node *attr, *next; + + ctx->AttribStackDepth--; + attr = ctx->AttribStack[ctx->AttribStackDepth]; + + while (attr) { + if (attr->kind == GL_TEXTURE_BIT) { + struct texture_state *texstate = (struct texture_state*)attr->data; + GLuint u, tgt; + /* clear references to the saved texture objects */ + for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL); + } + } + } + else { + /* any other chunks of state that requires special handling? */ + } + + next = attr->next; + _mesa_free(attr->data); + _mesa_free(attr); + attr = next; + } + } +} + + void _mesa_init_attrib( GLcontext *ctx ) { /* Renderer and client attribute stacks */ diff --git a/src/mesa/main/attrib.h b/src/mesa/main/attrib.h index 09d75196b2..2cf8fe6934 100644 --- a/src/mesa/main/attrib.h +++ b/src/mesa/main/attrib.h @@ -1,18 +1,8 @@ -/** - * \file attrib.h - * Attribute stacks. - * - * \if subset - * (No-op) - * - * \endif - */ - /* * Mesa 3-D graphics library - * Version: 5.1 + * Version: 7.1 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -32,8 +22,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - - #ifndef ATTRIB_H #define ATTRIB_H @@ -58,10 +46,14 @@ _mesa_PopClientAttrib( void ); extern void _mesa_init_attrib( GLcontext *ctx ); +extern void +_mesa_free_attrib_data( GLcontext *ctx ); + #else /** No-op */ #define _mesa_init_attrib( c ) ((void)0) +#define _mesa_free_attrib_data( c ) ((void)0) #endif diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 0e6ca8ea1c..cbbe3e8698 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -336,6 +336,20 @@ read_buffer_enum_to_index(GLenum buffer) * \sa _mesa_DrawBuffersARB * * \param buffer buffer token such as GL_LEFT or GL_FRONT_AND_BACK, etc. + * + * Note that the behaviour of this function depends on whether the + * current ctx->DrawBuffer is a window-system framebuffer (Name=0) or + * a user-created framebuffer object (Name!=0). + * In the former case, we update the per-context ctx->Color.DrawBuffer + * state var _and_ the FB's ColorDrawBuffer state. + * In the later case, we update the FB's ColorDrawBuffer state only. + * + * Furthermore, upon a MakeCurrent() or BindFramebuffer() call, if the + * new FB is a window system FB, we need to re-update the FB's + * ColorDrawBuffer state to match the context. This is handled in + * _mesa_update_framebuffer(). + * + * See the GL_EXT_framebuffer_object spec for more info. */ void GLAPIENTRY _mesa_DrawBuffer(GLenum buffer) @@ -479,17 +493,22 @@ set_color_output(GLcontext *ctx, GLuint output, GLenum buffer, /* not really needed, will be set later */ fb->_NumColorDrawBuffers[output] = 0; - if (fb->Name == 0) - /* Set traditional state var */ + if (fb->Name == 0) { + /* Only set the per-context DrawBuffer state if we're currently + * drawing to a window system framebuffer. + */ ctx->Color.DrawBuffer[output] = buffer; + } } /** - * Helper routine used by _mesa_DrawBuffer, _mesa_DrawBuffersARB and - * other places (window fbo fixup) to set fbo (and the old ctx) fields. + * Helper function to set the GL_DRAW_BUFFER state in the context and + * current FBO. + * * All error checking will have been done prior to calling this function * so nothing should go wrong at this point. + * * \param ctx current context * \param n number of color outputs to set * \param buffers array[n] of colorbuffer names, like GL_LEFT. @@ -529,43 +548,29 @@ _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, } -GLboolean -_mesa_readbuffer_update_fields(GLcontext *ctx, GLenum buffer) +/** + * Like \sa _mesa_drawbuffers(), this is a helper function for setting + * GL_READ_BUFFER state in the context and current FBO. + * \param ctx the rendering context + * \param buffer GL_FRONT, GL_BACK, GL_COLOR_ATTACHMENT0, etc. + * \param bufferIndex the numerical index corresponding to 'buffer' + */ +void +_mesa_readbuffer(GLcontext *ctx, GLenum buffer, GLint bufferIndex) { - struct gl_framebuffer *fb; - GLbitfield supportedMask; - GLint srcBuffer; - - fb = ctx->ReadBuffer; - - if (MESA_VERBOSE & VERBOSE_API) - _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer)); - - if (fb->Name > 0 && buffer == GL_NONE) { - /* This is legal for user-created framebuffer objects */ - srcBuffer = -1; - } - else { - /* general case / window-system framebuffer */ - srcBuffer = read_buffer_enum_to_index(buffer); - if (srcBuffer == -1) { - _mesa_error(ctx, GL_INVALID_ENUM, "glReadBuffer(buffer=0x%x)", buffer); - return GL_FALSE; - } - supportedMask = supported_buffer_bitmask(ctx, fb); - if (((1 << srcBuffer) & supportedMask) == 0) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glReadBuffer(buffer=0x%x)", buffer); - return GL_FALSE; - } - } + struct gl_framebuffer *fb = ctx->ReadBuffer; if (fb->Name == 0) { + /* Only update the per-context READ_BUFFER state if we're bound to + * a window-system framebuffer. + */ ctx->Pixel.ReadBuffer = buffer; } + fb->ColorReadBuffer = buffer; - fb->_ColorReadBufferIndex = srcBuffer; + fb->_ColorReadBufferIndex = bufferIndex; - return GL_TRUE; + ctx->NewState |= _NEW_PIXEL; } @@ -577,16 +582,43 @@ _mesa_readbuffer_update_fields(GLcontext *ctx, GLenum buffer) void GLAPIENTRY _mesa_ReadBuffer(GLenum buffer) { + struct gl_framebuffer *fb; + GLbitfield supportedMask; + GLint srcBuffer; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer)); - if (!_mesa_readbuffer_update_fields(ctx, buffer)) - return; + fb = ctx->ReadBuffer; - ctx->NewState |= _NEW_PIXEL; + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glReadBuffer %s\n", _mesa_lookup_enum_by_nr(buffer)); + + if (fb->Name > 0 && buffer == GL_NONE) { + /* This is legal for user-created framebuffer objects */ + srcBuffer = -1; + } + else { + /* general case / window-system framebuffer */ + srcBuffer = read_buffer_enum_to_index(buffer); + if (srcBuffer == -1) { + _mesa_error(ctx, GL_INVALID_ENUM, + "glReadBuffer(buffer=0x%x)", buffer); + return; + } + supportedMask = supported_buffer_bitmask(ctx, fb); + if (((1 << srcBuffer) & supportedMask) == 0) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glReadBuffer(buffer=0x%x)", buffer); + return; + } + } + + /* OK, all error checking has been completed now */ + + _mesa_readbuffer(ctx, buffer, srcBuffer); /* * Call device driver function. diff --git a/src/mesa/main/buffers.h b/src/mesa/main/buffers.h index 208e7af2b9..9c0070e00f 100644 --- a/src/mesa/main/buffers.h +++ b/src/mesa/main/buffers.h @@ -5,9 +5,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.1 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -56,8 +56,8 @@ extern void _mesa_drawbuffers(GLcontext *ctx, GLuint n, const GLenum *buffers, const GLbitfield *destMask); -extern GLboolean -_mesa_readbuffer_update_fields(GLcontext *ctx, GLenum buffer); +extern void +_mesa_readbuffer(GLcontext *ctx, GLenum buffer, GLint bufferIndex); extern void GLAPIENTRY _mesa_ReadBuffer( GLenum mode ); diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c index 610acba306..97120398f9 100644 --- a/src/mesa/main/colortab.c +++ b/src/mesa/main/colortab.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 + * Version: 7.1 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * @@ -30,6 +30,7 @@ #include "image.h" #include "macros.h" #include "state.h" +#include "teximage.h" /** @@ -305,49 +306,6 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */ switch (target) { - case GL_TEXTURE_1D: - texObj = texUnit->Current1D; - table = &texObj->Palette; - break; - case GL_TEXTURE_2D: - texObj = texUnit->Current2D; - table = &texObj->Palette; - break; - case GL_TEXTURE_3D: - texObj = texUnit->Current3D; - table = &texObj->Palette; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); - return; - } - texObj = texUnit->CurrentCubeMap; - table = &texObj->Palette; - break; - case GL_PROXY_TEXTURE_1D: - texObj = ctx->Texture.Proxy1D; - table = &texObj->Palette; - proxy = GL_TRUE; - break; - case GL_PROXY_TEXTURE_2D: - texObj = ctx->Texture.Proxy2D; - table = &texObj->Palette; - proxy = GL_TRUE; - break; - case GL_PROXY_TEXTURE_3D: - texObj = ctx->Texture.Proxy3D; - table = &texObj->Palette; - proxy = GL_TRUE; - break; - case GL_PROXY_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); - return; - } - texObj = ctx->Texture.ProxyCubeMap; - table = &texObj->Palette; - break; case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; @@ -396,8 +354,19 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, proxy = GL_TRUE; break; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); - return; + /* try texture targets */ + { + struct gl_texture_object *texobj + = _mesa_select_tex_object(ctx, texUnit, target); + if (texobj) { + table = &texobj->Palette; + proxy = _mesa_is_proxy_texture(target); + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); + return; + } + } } assert(table); @@ -499,26 +468,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); switch (target) { - case GL_TEXTURE_1D: - texObj = texUnit->Current1D; - table = &texObj->Palette; - break; - case GL_TEXTURE_2D: - texObj = texUnit->Current2D; - table = &texObj->Palette; - break; - case GL_TEXTURE_3D: - texObj = texUnit->Current3D; - table = &texObj->Palette; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); - return; - } - texObj = texUnit->CurrentCubeMap; - table = &texObj->Palette; - break; case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; @@ -547,8 +496,15 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]; break; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); - return; + /* try texture targets */ + texObj = _mesa_select_tex_object(ctx, texUnit, target); + if (texObj && !_mesa_is_proxy_texture(target)) { + table = &texObj->Palette; + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); + return; + } } assert(table); @@ -636,22 +592,6 @@ _mesa_GetColorTable( GLenum target, GLenum format, } switch (target) { - case GL_TEXTURE_1D: - table = &texUnit->Current1D->Palette; - break; - case GL_TEXTURE_2D: - table = &texUnit->Current2D->Palette; - break; - case GL_TEXTURE_3D: - table = &texUnit->Current3D->Palette; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); - return; - } - table = &texUnit->CurrentCubeMap->Palette; - break; case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; @@ -672,8 +612,18 @@ _mesa_GetColorTable( GLenum target, GLenum format, table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX]; break; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); - return; + /* try texture targets */ + { + struct gl_texture_object *texobj + = _mesa_select_tex_object(ctx, texUnit, target); + if (texobj && !_mesa_is_proxy_texture(target)) { + table = &texobj->Palette; + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); + return; + } + } } ASSERT(table); @@ -781,65 +731,41 @@ _mesa_GetColorTable( GLenum target, GLenum format, void GLAPIENTRY _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) { + GLfloat *scale, *bias; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); switch (target) { - case GL_COLOR_TABLE_SGI: - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION], params); - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION], params); - } - else { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); - return; - } - break; - case GL_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); - return; - } - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - COPY_4V(ctx->Pixel.TextureColorTableScale, params); - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - COPY_4V(ctx->Pixel.TextureColorTableBias, params); - } - else { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); - return; - } - break; - case GL_POST_CONVOLUTION_COLOR_TABLE_SGI: - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION], params); - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION], params); - } - else { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); - return; - } - break; - case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI: - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX], params); - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX], params); - } - else { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); - return; - } - break; - default: - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); - return; + case GL_COLOR_TABLE_SGI: + scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]; + bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]; + break; + case GL_TEXTURE_COLOR_TABLE_SGI: + scale = ctx->Pixel.TextureColorTableScale; + bias = ctx->Pixel.TextureColorTableBias; + break; + case GL_POST_CONVOLUTION_COLOR_TABLE_SGI: + scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]; + bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]; + break; + case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI: + scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]; + bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]; + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); + return; + } + + if (pname == GL_COLOR_TABLE_SCALE_SGI) { + COPY_4V(scale, params); + } + else if (pname == GL_COLOR_TABLE_BIAS_SGI) { + COPY_4V(bias, params); + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); + return; } ctx->NewState |= _NEW_PIXEL; @@ -879,40 +805,6 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) ASSERT_OUTSIDE_BEGIN_END(ctx); switch (target) { - case GL_TEXTURE_1D: - table = &texUnit->Current1D->Palette; - break; - case GL_TEXTURE_2D: - table = &texUnit->Current2D->Palette; - break; - case GL_TEXTURE_3D: - table = &texUnit->Current3D->Palette; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetColorTableParameterfv(target)"); - return; - } - table = &texUnit->CurrentCubeMap->Palette; - break; - case GL_PROXY_TEXTURE_1D: - table = &ctx->Texture.Proxy1D->Palette; - break; - case GL_PROXY_TEXTURE_2D: - table = &ctx->Texture.Proxy2D->Palette; - break; - case GL_PROXY_TEXTURE_3D: - table = &ctx->Texture.Proxy3D->Palette; - break; - case GL_PROXY_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetColorTableParameterfv(target)"); - return; - } - table = &ctx->Texture.ProxyCubeMap->Palette; - break; case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; @@ -981,8 +873,19 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX]; break; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)"); - return; + /* try texture targets */ + { + struct gl_texture_object *texobj + = _mesa_select_tex_object(ctx, texUnit, target); + if (texobj) { + table = &texobj->Palette; + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, + "glGetColorTableParameterfv(target)"); + return; + } + } } assert(table); @@ -1029,40 +932,6 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) ASSERT_OUTSIDE_BEGIN_END(ctx); switch (target) { - case GL_TEXTURE_1D: - table = &texUnit->Current1D->Palette; - break; - case GL_TEXTURE_2D: - table = &texUnit->Current2D->Palette; - break; - case GL_TEXTURE_3D: - table = &texUnit->Current3D->Palette; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetColorTableParameteriv(target)"); - return; - } - table = &texUnit->CurrentCubeMap->Palette; - break; - case GL_PROXY_TEXTURE_1D: - table = &ctx->Texture.Proxy1D->Palette; - break; - case GL_PROXY_TEXTURE_2D: - table = &ctx->Texture.Proxy2D->Palette; - break; - case GL_PROXY_TEXTURE_3D: - table = &ctx->Texture.Proxy3D->Palette; - break; - case GL_PROXY_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetColorTableParameteriv(target)"); - return; - } - table = &ctx->Texture.ProxyCubeMap->Palette; - break; case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; @@ -1161,8 +1030,19 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX]; break; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)"); - return; + /* Try texture targets */ + { + struct gl_texture_object *texobj + = _mesa_select_tex_object(ctx, texUnit, target); + if (texobj) { + table = &texobj->Palette; + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, + "glGetColorTableParameteriv(target)"); + return; + } + } } assert(table); diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 92d8ceda29..bb48109317 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -6,9 +6,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -97,12 +97,9 @@ #include "fog.h" #include "framebuffer.h" #include "get.h" -#include "glthread.h" -#include "glapioffsets.h" #include "histogram.h" #include "hint.h" #include "hash.h" -#include "atifragshader.h" #include "light.h" #include "lines.h" #include "macros.h" @@ -110,9 +107,6 @@ #include "pixel.h" #include "points.h" #include "polygon.h" -#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program -#include "program.h" -#endif #include "queryobj.h" #include "rastpos.h" #include "simple_list.h" @@ -126,13 +120,19 @@ #include "varray.h" #include "version.h" #include "vtxfmt.h" +#include "glapi/glthread.h" +#include "glapi/glapioffsets.h" +#if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program +#include "shader/program.h" +#endif +#include "shader/shader_api.h" +#include "shader/atifragshader.h" #if _HAVE_FULL_GL #include "math/m_translate.h" #include "math/m_matrix.h" #include "math/m_xform.h" #include "math/mathmod.h" #endif -#include "shader_api.h" #ifdef USE_SPARC_ASM #include "sparc/sparc.h" @@ -475,19 +475,12 @@ alloc_shared_state( GLcontext *ctx ) if (!ss->Default2DArray) goto cleanup; - /* Effectively bind the default textures to all texture units */ - ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS; - ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS; - ss->Default3D->RefCount += MAX_TEXTURE_IMAGE_UNITS; - ss->DefaultCubeMap->RefCount += MAX_TEXTURE_IMAGE_UNITS; - ss->DefaultRect->RefCount += MAX_TEXTURE_IMAGE_UNITS; - ss->Default1DArray->RefCount += MAX_TEXTURE_IMAGE_UNITS; - ss->Default2DArray->RefCount += MAX_TEXTURE_IMAGE_UNITS; + /* sanity check */ + assert(ss->Default1D->RefCount == 1); _glthread_INIT_MUTEX(ss->TexMutex); ss->TextureStateStamp = 0; - #if FEATURE_EXT_framebuffer_object ss->FrameBuffers = _mesa_NewHashTable(); if (!ss->FrameBuffers) @@ -497,10 +490,9 @@ alloc_shared_state( GLcontext *ctx ) goto cleanup; #endif - return GL_TRUE; - cleanup: +cleanup: /* Ran out of memory at some point. Free everything and return NULL */ if (ss->DisplayList) _mesa_DeleteHashTable(ss->DisplayList); @@ -552,6 +544,10 @@ alloc_shared_state( GLcontext *ctx ) (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap); if (ss->DefaultRect) (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect); + if (ss->Default1DArray) + (*ctx->Driver.DeleteTexture)(ctx, ss->Default1DArray); + if (ss->Default2DArray) + (*ctx->Driver.DeleteTexture)(ctx, ss->Default2DArray); if (ss) _mesa_free(ss); return GL_FALSE; @@ -644,6 +640,33 @@ delete_shader_cb(GLuint id, void *data, void *userData) } } +/** + * Callback for deleting a framebuffer object. Called by _mesa_HashDeleteAll() + */ +static void +delete_framebuffer_cb(GLuint id, void *data, void *userData) +{ + struct gl_framebuffer *fb = (struct gl_framebuffer *) data; + /* The fact that the framebuffer is in the hashtable means its refcount + * is one, but we're removing from the hashtable now. So clear refcount. + */ + /*assert(fb->RefCount == 1);*/ + fb->RefCount = 0; + fb->Delete(fb); +} + +/** + * Callback for deleting a renderbuffer object. Called by _mesa_HashDeleteAll() + */ +static void +delete_renderbuffer_cb(GLuint id, void *data, void *userData) +{ + struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data; + rb->RefCount = 0; /* see comment for FBOs above */ + rb->Delete(rb); +} + + /** * Deallocate a shared state object and all children structures. @@ -666,20 +689,6 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) _mesa_HashDeleteAll(ss->DisplayList, delete_displaylist_cb, ctx); _mesa_DeleteHashTable(ss->DisplayList); - /* - * Free texture objects - */ - ASSERT(ctx->Driver.DeleteTexture); - /* the default textures */ - ctx->Driver.DeleteTexture(ctx, ss->Default1D); - ctx->Driver.DeleteTexture(ctx, ss->Default2D); - ctx->Driver.DeleteTexture(ctx, ss->Default3D); - ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap); - ctx->Driver.DeleteTexture(ctx, ss->DefaultRect); - /* all other textures */ - _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx); - _mesa_DeleteHashTable(ss->TexObjects); - #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_NV_fragment_program) _mesa_HashDeleteAll(ss->Programs, delete_program_cb, ctx); _mesa_DeleteHashTable(ss->Programs); @@ -711,10 +720,29 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) #endif #if FEATURE_EXT_framebuffer_object + _mesa_HashDeleteAll(ss->FrameBuffers, delete_framebuffer_cb, ctx); _mesa_DeleteHashTable(ss->FrameBuffers); + _mesa_HashDeleteAll(ss->RenderBuffers, delete_renderbuffer_cb, ctx); _mesa_DeleteHashTable(ss->RenderBuffers); #endif + /* + * Free texture objects (after FBOs since some textures might have + * been bound to FBOs). + */ + ASSERT(ctx->Driver.DeleteTexture); + /* the default textures */ + ctx->Driver.DeleteTexture(ctx, ss->Default1D); + ctx->Driver.DeleteTexture(ctx, ss->Default2D); + ctx->Driver.DeleteTexture(ctx, ss->Default3D); + ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap); + ctx->Driver.DeleteTexture(ctx, ss->DefaultRect); + ctx->Driver.DeleteTexture(ctx, ss->Default1DArray); + ctx->Driver.DeleteTexture(ctx, ss->Default2DArray); + /* all other textures */ + _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx); + _mesa_DeleteHashTable(ss->TexObjects); + _glthread_DESTROY_MUTEX(ss->Mutex); _mesa_free(ss); @@ -1168,18 +1196,20 @@ _mesa_create_context(const GLvisual *visual, void _mesa_free_context_data( GLcontext *ctx ) { - /* if we're destroying the current context, unbind it first */ - if (ctx == _mesa_get_current_context()) { - _mesa_make_current(NULL, NULL, NULL); - } - else { - /* unreference WinSysDraw/Read buffers */ - _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer); - _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer); - _mesa_unreference_framebuffer(&ctx->DrawBuffer); - _mesa_unreference_framebuffer(&ctx->ReadBuffer); + if (!_mesa_get_current_context()){ + /* No current context, but we may need one in order to delete + * texture objs, etc. So temporarily bind the context now. + */ + _mesa_make_current(ctx, NULL, NULL); } + /* unreference WinSysDraw/Read buffers */ + _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer); + _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer); + _mesa_unreference_framebuffer(&ctx->DrawBuffer); + _mesa_unreference_framebuffer(&ctx->ReadBuffer); + + _mesa_free_attrib_data(ctx); _mesa_free_lighting_data( ctx ); _mesa_free_eval_data( ctx ); _mesa_free_texture_data( ctx ); @@ -1211,6 +1241,11 @@ _mesa_free_context_data( GLcontext *ctx ) if (ctx->Extensions.String) _mesa_free((void *) ctx->Extensions.String); + + /* unbind the context if it's currently bound */ + if (ctx == _mesa_get_current_context()) { + _mesa_make_current(NULL, NULL, NULL); + } } @@ -1495,21 +1530,14 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer, */ if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) { _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer); - /* fix up the fb fields - these will end up wrong otherwise - if the DRIdrawable changes, and everything relies on them. - This is a bit messy (same as needed in _mesa_BindFramebufferEXT) */ - int i; - GLenum buffers[MAX_DRAW_BUFFERS]; - for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) { - buffers[i] = newCtx->Color.DrawBuffer[i]; - } - _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers, buffers, NULL); } if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) { _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer); - _mesa_readbuffer_update_fields(newCtx, newCtx->Pixel.ReadBuffer); } + /* XXX only set this flag if we're really changing the draw/read + * framebuffer bindings. + */ newCtx->NewState |= _NEW_BUFFERS; #if 1 diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index b6a9d13149..099912aa15 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -49,7 +49,7 @@ #define CONTEXT_H -#include "glapi.h" +#include "glapi/glapi.h" #include "imports.h" #include "mtypes.h" diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 91ddcbf9ed..be2f438a94 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.1 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -33,10 +33,6 @@ #include "api_arrayelt.h" #include "api_loopback.h" #include "config.h" -#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program -#include "arbprogram.h" -#include "program.h" -#endif #include "attrib.h" #include "blend.h" #include "buffers.h" @@ -57,7 +53,7 @@ #include "extensions.h" #include "feedback.h" #include "get.h" -#include "glapi.h" +#include "glapi/glapi.h" #include "hash.h" #include "histogram.h" #include "image.h" @@ -76,18 +72,22 @@ #include "texstate.h" #include "mtypes.h" #include "varray.h" +#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program +#include "shader/arbprogram.h" +#include "shader/program.h" +#endif #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program -#include "nvprogram.h" -#include "program.h" +#include "shader/nvprogram.h" +#include "shader/program.h" #endif #if FEATURE_ATI_fragment_shader -#include "atifragshader.h" +#include "shader/atifragshader.h" #endif #include "math/m_matrix.h" #include "math/m_xform.h" -#include "dispatch.h" +#include "glapi/dispatch.h" /** @@ -2716,21 +2716,20 @@ save_PolygonMode(GLenum face, GLenum mode) } -/* - * Polygon stipple must have been upacked already! - */ static void GLAPIENTRY save_PolygonStipple(const GLubyte * pattern) { GET_CURRENT_CONTEXT(ctx); + GLvoid *image = unpack_image(2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP, + pattern, &ctx->Unpack); Node *n; ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx); n = ALLOC_INSTRUCTION(ctx, OPCODE_POLYGON_STIPPLE, 1); if (n) { - void *data; - n[1].data = _mesa_malloc(32 * 4); - data = n[1].data; /* This needed for Acorn compiler */ - MEMCPY(data, pattern, 32 * 4); + n[1].data = image; + } + else if (image) { + _mesa_free(image); } if (ctx->ExecuteFlag) { CALL_PolygonStipple(ctx->Exec, ((GLubyte *) pattern)); @@ -6169,7 +6168,12 @@ execute_list(GLcontext *ctx, GLuint list) CALL_PolygonMode(ctx->Exec, (n[1].e, n[2].e)); break; case OPCODE_POLYGON_STIPPLE: - CALL_PolygonStipple(ctx->Exec, ((GLubyte *) n[1].data)); + { + const struct gl_pixelstore_attrib save = ctx->Unpack; + ctx->Unpack = ctx->DefaultPacking; + CALL_PolygonStipple(ctx->Exec, ((GLubyte *) n[1].data)); + ctx->Unpack = save; /* restore */ + } break; case OPCODE_POLYGON_OFFSET: CALL_PolygonOffset(ctx->Exec, (n[1].f, n[2].f)); diff --git a/src/mesa/main/execmem.c b/src/mesa/main/execmem.c index df3095232d..40f66d7da2 100644 --- a/src/mesa/main/execmem.c +++ b/src/mesa/main/execmem.c @@ -32,7 +32,7 @@ #include "imports.h" -#include "glthread.h" +#include "glapi/glthread.h" diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 6f7effcce7..db04c785de 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -151,22 +151,18 @@ _mesa_remove_attachment(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { if (att->Type == GL_TEXTURE) { ASSERT(att->Texture); - att->Texture->RefCount--; - if (att->Texture->RefCount == 0) { - ctx->Driver.DeleteTexture(ctx, att->Texture); + if (ctx->Driver.FinishRenderTexture) { + /* tell driver we're done rendering to this texobj */ + ctx->Driver.FinishRenderTexture(ctx, att); } - else { - /* tell driver that we're done rendering to this texture. */ - if (ctx->Driver.FinishRenderTexture) { - ctx->Driver.FinishRenderTexture(ctx, att); - } - } - att->Texture = NULL; + _mesa_reference_texobj(&att->Texture, NULL); /* unbind */ + ASSERT(!att->Texture); } if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) { ASSERT(att->Renderbuffer); ASSERT(!att->Texture); - _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); + _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */ + ASSERT(!att->Renderbuffer); } att->Type = GL_NONE; att->Complete = GL_TRUE; @@ -192,8 +188,8 @@ _mesa_set_texture_attachment(GLcontext *ctx, /* new attachment */ _mesa_remove_attachment(ctx, att); att->Type = GL_TEXTURE; - att->Texture = texObj; - texObj->RefCount++; + assert(!att->Texture); + _mesa_reference_texobj(&att->Texture, texObj); } /* always update these fields */ @@ -966,9 +962,11 @@ _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) } FLUSH_VERTICES(ctx, _NEW_BUFFERS); + if (ctx->Driver.Flush) { ctx->Driver.Flush(ctx); } + if (framebuffer) { /* Binding a user-created framebuffer object */ newFb = _mesa_lookup_framebuffer(ctx, framebuffer); @@ -1002,32 +1000,18 @@ _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) * XXX check if re-binding same buffer and skip some of this code. */ - /* for window-framebuffers, re-initialize the fbo values, as they - could be wrong (makecurrent with a new drawable while still a fbo - was bound will lead to default init fbo values). - note that therefore the context ReadBuffer/DrawBuffer values are not - valid while fbo's are bound!!! */ if (bindReadBuf) { _mesa_reference_framebuffer(&ctx->ReadBuffer, newFbread); - if (!newFbread->Name) { - _mesa_readbuffer_update_fields(ctx, ctx->Pixel.ReadBuffer); - } } if (bindDrawBuf) { /* check if old FB had any texture attachments */ check_end_texture_render(ctx, ctx->DrawBuffer); + /* check if time to delete this framebuffer */ _mesa_reference_framebuffer(&ctx->DrawBuffer, newFb); - if (!newFb->Name) { - GLuint i; - GLenum buffers[MAX_DRAW_BUFFERS]; - for(i = 0; i < ctx->Const.MaxDrawBuffers; i++) { - buffers[i] = ctx->Color.DrawBuffer[i]; - } - _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, buffers, NULL); - } - else { + + if (newFb->Name != 0) { /* check if newly bound framebuffer has any texture attachments */ check_begin_texture_render(ctx, newFb); } diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index f737c74f35..3e36197d88 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -32,12 +32,14 @@ #include "glheader.h" #include "imports.h" +#include "buffers.h" #include "context.h" #include "depthstencil.h" #include "mtypes.h" #include "fbobject.h" #include "framebuffer.h" #include "renderbuffer.h" +#include "texobj.h" @@ -65,7 +67,9 @@ compute_depth_max(struct gl_framebuffer *fb) fb->_DepthMax = 0xffffffff; } fb->_DepthMaxF = (GLfloat) fb->_DepthMax; - fb->_MRD = 1.0; /* Minimum resolvable depth value, for polygon offset */ + + /* Minimum resolvable depth value, for polygon offset */ + fb->_MRD = 1.0 / fb->_DepthMaxF; } @@ -135,7 +139,7 @@ _mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual) /* save the visual */ fb->Visual = *visual; - /* Init glRead/DrawBuffer state */ + /* Init read/draw renderbuffer state */ if (visual->doubleBufferMode) { fb->ColorDrawBuffer[0] = GL_BACK; fb->_ColorDrawBufferMask[0] = BUFFER_BIT_BACK_LEFT; @@ -190,17 +194,11 @@ _mesa_free_framebuffer_data(struct gl_framebuffer *fb) _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); } if (att->Texture) { - /* render to texture */ - att->Texture->RefCount--; - if (att->Texture->RefCount == 0) { - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - ctx->Driver.DeleteTexture(ctx, att->Texture); - } - } + _mesa_reference_texobj(&att->Texture, NULL); } + ASSERT(!att->Renderbuffer); + ASSERT(!att->Texture); att->Type = GL_NONE; - att->Texture = NULL; } /* unbind _Depth/_StencilBuffer to decr ref counts */ @@ -586,7 +584,7 @@ _mesa_update_stencil_buffer(GLcontext *ctx, /** - * Update the list of color drawing renderbuffer pointers. + * Update the (derived) list of color drawing renderbuffer pointers. * Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers * writing colors. */ @@ -630,7 +628,7 @@ update_color_draw_buffers(GLcontext *ctx, struct gl_framebuffer *fb) /** - * Update the color read renderbuffer pointer. + * Update the (derived) color read renderbuffer pointer. * Unlike the DrawBuffer, we can only read from one (or zero) color buffers. */ static void @@ -652,19 +650,51 @@ update_color_read_buffer(GLcontext *ctx, struct gl_framebuffer *fb) } +/** + * Update a gl_framebuffer's derived state. + * + * Specifically, update these framebuffer fields: + * _ColorDrawBuffers + * _NumColorDrawBuffers + * _ColorReadBuffer + * _DepthBuffer + * _StencilBuffer + * + * If the framebuffer is user-created, make sure it's complete. + * + * The following functions (at least) can effect framebuffer state: + * glReadBuffer, glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT, + * glRenderbufferStorageEXT. + */ static void update_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) { - /* Completeness only matters for user-created framebuffers */ - if (fb->Name != 0) { - /* XXX: EXT_framebuffer_blit: - framebuffer must still be complete wrt read/draw? */ + if (fb->Name == 0) { + /* This is a window-system framebuffer */ + /* Need to update the FB's GL_DRAW_BUFFER state to match the + * context state (GL_READ_BUFFER too). + */ + if (fb->ColorDrawBuffer[0] != ctx->Color.DrawBuffer[0]) { + _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, + ctx->Color.DrawBuffer, NULL); + } + if (fb->ColorReadBuffer != ctx->Pixel.ReadBuffer) { + + } + } + else { + /* This is a user-created framebuffer. + * Completeness only matters for user-created framebuffers. + */ _mesa_test_framebuffer_completeness(ctx, fb); _mesa_update_framebuffer_visual(fb); } - /* update_color_draw/read_buffers not needed for - read/draw only fb, but shouldn't hurt ??? */ + /* Strictly speaking, we don't need to update the draw-state + * if this FB is bound as ctx->ReadBuffer (and conversely, the + * read-state if this FB is bound as ctx->DrawBuffer), but no + * harm. + */ update_color_draw_buffers(ctx, fb); update_color_read_buffer(ctx, fb); _mesa_update_depth_buffer(ctx, fb, BUFFER_DEPTH); @@ -673,28 +703,19 @@ update_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) compute_depth_max(fb); } + /** * Update state related to the current draw/read framebuffers. - * Specifically, update these framebuffer fields: - * _ColorDrawBuffers - * _NumColorDrawBuffers - * _ColorReadBuffer - * _DepthBuffer - * _StencilBuffer - * If the current framebuffer is user-created, make sure it's complete. - * The following functions can effect this state: glReadBuffer, - * glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT, - * glRenderbufferStorageEXT. */ void _mesa_update_framebuffer(GLcontext *ctx) { - struct gl_framebuffer *fb = ctx->DrawBuffer; - struct gl_framebuffer *fbread = ctx->ReadBuffer; + struct gl_framebuffer *drawFb = ctx->DrawBuffer; + struct gl_framebuffer *readFb = ctx->ReadBuffer; - update_framebuffer(ctx, fb); - if (fbread != fb) - update_framebuffer(ctx, fbread); + update_framebuffer(ctx, drawFb); + if (readFb != drawFb) + update_framebuffer(ctx, readFb); } diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h index 63dd002a41..fd4127558a 100644 --- a/src/mesa/main/glheader.h +++ b/src/mesa/main/glheader.h @@ -92,7 +92,7 @@ #endif #ifdef WGLAPI -#undef WGLAPI +# undef WGLAPI #endif #if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__)) && !defined(BUILD_FOR_SNAP) diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c index 2d5bcc3e01..ffb2c4d946 100644 --- a/src/mesa/main/hash.c +++ b/src/mesa/main/hash.c @@ -37,7 +37,7 @@ #include "glheader.h" #include "imports.h" -#include "glthread.h" +#include "glapi/glthread.h" #include "hash.h" diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index e2e7f806ab..347cec66ef 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -850,7 +850,7 @@ _mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels, return NULL; } - if (packing->SkipPixels == 0) { + if ((packing->SkipPixels & 7) == 0) { _mesa_memcpy( dst, src, width_in_bytes ); if (packing->LsbFirst) { flip_bytes( dst, width_in_bytes ); @@ -942,7 +942,7 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, if (!dst) return; - if (packing->SkipPixels == 0) { + if ((packing->SkipPixels & 7) == 0) { _mesa_memcpy( dst, src, width_in_bytes ); if (packing->LsbFirst) { flip_bytes( dst, width_in_bytes ); @@ -961,20 +961,20 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, if (*s & srcMask) { *d |= dstMask; } - if (srcMask == 128) { - srcMask = 1; + if (srcMask == 1) { + srcMask = 128; s++; } else { - srcMask = srcMask << 1; + srcMask = srcMask >> 1; } - if (dstMask == 1) { - dstMask = 128; + if (dstMask == 128) { + dstMask = 1; d++; *d = 0; } else { - dstMask = dstMask >> 1; + dstMask = dstMask << 1; } } } @@ -3648,11 +3648,13 @@ _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n, * Try simple cases first */ if (transferOps == 0 && + !ctx->Pixel.MapStencilFlag && srcType == GL_UNSIGNED_BYTE && dstType == GL_UNSIGNED_BYTE) { _mesa_memcpy(dest, source, n * sizeof(GLubyte)); } else if (transferOps == 0 && + !ctx->Pixel.MapStencilFlag && srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) { @@ -3668,19 +3670,17 @@ _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n, extract_uint_indexes(n, indexes, GL_STENCIL_INDEX, srcType, source, srcPacking); - if (transferOps) { - if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { - /* shift and offset indexes */ - shift_and_offset_ci(ctx, n, indexes); - } + if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { + /* shift and offset indexes */ + shift_and_offset_ci(ctx, n, indexes); + } - if (ctx->Pixel.MapStencilFlag) { - /* Apply stencil lookup table */ - GLuint mask = ctx->PixelMaps.StoS.Size - 1; - GLuint i; - for (i=0;i<n;i++) { - indexes[i] = ctx->PixelMaps.StoS.Map[ indexes[i] & mask ]; - } + if (ctx->Pixel.MapStencilFlag) { + /* Apply stencil lookup table */ + const GLuint mask = ctx->PixelMaps.StoS.Size - 1; + GLuint i; + for (i = 0; i < n; i++) { + indexes[i] = ctx->PixelMaps.StoS.Map[ indexes[i] & mask ]; } } @@ -3733,7 +3733,7 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, switch (dstType) { case GL_UNSIGNED_BYTE: - if (sizeof(GLstencil) == 8) { + if (sizeof(GLstencil) == 1) { _mesa_memcpy( dest, source, n ); } else { @@ -3745,14 +3745,11 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, } break; case GL_BYTE: - if (sizeof(GLstencil) == 8) { - _mesa_memcpy( dest, source, n ); - } - else { + { GLbyte *dst = (GLbyte *) dest; GLuint i; for (i=0;i<n;i++) { - dst[i] = (GLbyte) source[i]; + dst[i] = (GLbyte) (source[i] & 0x7f); } } break; @@ -3797,7 +3794,7 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, GLint *dst = (GLint *) dest; GLuint i; for (i=0;i<n;i++) { - *dst++ = (GLint) source[i]; + dst[i] = (GLint) source[i]; } if (dstPacking->SwapBytes) { _mesa_swap4( (GLuint *) dst, n ); @@ -3882,9 +3879,19 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, } \ } while (0) + +/** + * Unpack a row of depth/z values from memory, returning GLushort, GLuint + * or GLfloat values. + * The glPixelTransfer (scale/bias) params will be applied. + * + * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT + * \param depthMax max value for returned GLushort or GLuint values + * (ignored for GLfloat). + */ void _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, - GLenum dstType, GLvoid *dest, GLfloat depthScale, + GLenum dstType, GLvoid *dest, GLuint depthMax, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking ) { @@ -3907,7 +3914,9 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, } return; } - if (srcType == GL_UNSIGNED_SHORT && dstType == GL_UNSIGNED_INT) { + if (srcType == GL_UNSIGNED_SHORT + && dstType == GL_UNSIGNED_INT + && depthMax == 0xffffffff) { const GLushort *src = (const GLushort *) source; GLuint *dst = (GLuint *) dest; GLuint i; @@ -3955,7 +3964,7 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, break; case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */ if (dstType == GL_UNSIGNED_INT && - depthScale == (GLfloat) 0xffffff && + depthMax == 0xffffff && ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) { const GLuint *src = (const GLuint *) source; @@ -4033,16 +4042,16 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, if (dstType == GL_UNSIGNED_INT) { GLuint *zValues = (GLuint *) dest; GLuint i; - if (depthScale <= (GLfloat) 0xffffff) { + if (depthMax <= 0xffffff) { /* no overflow worries */ for (i = 0; i < n; i++) { - zValues[i] = (GLuint) (depthValues[i] * depthScale); + zValues[i] = (GLuint) (depthValues[i] * (GLfloat) depthMax); } } else { /* need to use double precision to prevent overflow problems */ for (i = 0; i < n; i++) { - GLdouble z = depthValues[i] * depthScale; + GLdouble z = depthValues[i] * (GLfloat) depthMax; if (z >= (GLdouble) 0xffffffff) zValues[i] = 0xffffffff; else @@ -4053,14 +4062,14 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, else if (dstType == GL_UNSIGNED_SHORT) { GLushort *zValues = (GLushort *) dest; GLuint i; - ASSERT(depthScale <= 65535.0); + ASSERT(depthMax <= 0xffff); for (i = 0; i < n; i++) { - zValues[i] = (GLushort) (depthValues[i] * depthScale); + zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax); } } else { ASSERT(dstType == GL_FLOAT); - ASSERT(depthScale == 1.0F); + /*ASSERT(depthMax == 1.0F);*/ } } diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h index 990398a7c4..2a16989fa7 100644 --- a/src/mesa/main/image.h +++ b/src/mesa/main/image.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.2 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -181,7 +181,7 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, extern void _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, - GLenum dstType, GLvoid *dest, GLfloat depthScale, + GLenum dstType, GLvoid *dest, GLuint depthMax, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking ); diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 8a5dfdb4b8..3ae56c8b0b 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -575,7 +575,11 @@ _mesa_ffs(int i) * if no bits set. */ int +#ifdef __MINGW32__ +_mesa_ffsll(long val) +#else _mesa_ffsll(long long val) +#endif { #ifdef ffsll return ffsll(val); diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index 9be8014a13..ebdfc452a7 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -700,7 +700,11 @@ extern int _mesa_ffs(int i); extern int +#ifdef __MINGW32__ +_mesa_ffsll(long i); +#else _mesa_ffsll(long long i); +#endif extern unsigned int _mesa_bitcount(unsigned int n); diff --git a/src/mesa/main/lines.c b/src/mesa/main/lines.c index dc7195d4eb..0c2dbf915a 100644 --- a/src/mesa/main/lines.c +++ b/src/mesa/main/lines.c @@ -55,9 +55,6 @@ _mesa_LineWidth( GLfloat width ) FLUSH_VERTICES(ctx, _NEW_LINE); ctx->Line.Width = width; - ctx->Line._Width = CLAMP(width, - ctx->Const.MinLineWidth, - ctx->Const.MaxLineWidth); if (ctx->Driver.LineWidth) ctx->Driver.LineWidth(ctx, width); @@ -105,13 +102,12 @@ _mesa_LineStipple( GLint factor, GLushort pattern ) * Initializes __GLcontextRec::Line and line related constants in * __GLcontextRec::Const. */ -void GLAPIENTRY _mesa_init_line( GLcontext * ctx ) +void GLAPIENTRY +_mesa_init_line( GLcontext * ctx ) { - /* Line group */ ctx->Line.SmoothFlag = GL_FALSE; ctx->Line.StippleFlag = GL_FALSE; ctx->Line.Width = 1.0; - ctx->Line._Width = 1.0; ctx->Line.StipplePattern = 0xffff; ctx->Line.StippleFactor = 1; } diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c index 9f3db22b75..a9260c847b 100644 --- a/src/mesa/main/mipmap.c +++ b/src/mesa/main/mipmap.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.2 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -957,7 +957,8 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target, GLint components, size; GLchan *dst; - assert(texObj->Target == GL_TEXTURE_2D); + assert(texObj->Target == GL_TEXTURE_2D || + texObj->Target == GL_TEXTURE_CUBE_MAP_ARB); if (srcImage->_BaseFormat == GL_RGB) { convertFormat = &_mesa_texformat_rgb; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 05c08c19fe..1145f361b1 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -38,8 +38,8 @@ #include "glheader.h" #include <GL/internal/glcore.h> /* __GLcontextModes (GLvisual) */ #include "config.h" /* Hardwired parameters */ -#include "glapitable.h" -#include "glthread.h" +#include "glapi/glapitable.h" +#include "glapi/glthread.h" #include "math/m_matrix.h" /* GLmatrix */ #include "bitset.h" @@ -917,7 +917,6 @@ struct gl_line_attrib GLushort StipplePattern; /**< Stipple pattern */ GLint StippleFactor; /**< Stipple repeat factor */ GLfloat Width; /**< Line width */ - GLfloat _Width; /**< Clamped Line width */ }; @@ -1063,7 +1062,6 @@ struct gl_point_attrib { GLboolean SmoothFlag; /**< True if GL_POINT_SMOOTH is enabled */ GLfloat Size; /**< User-specified point size */ - GLfloat _Size; /**< Size clamped to Const.Min/MaxPointSize */ GLfloat Params[3]; /**< GL_EXT_point_parameters */ GLfloat MinSize, MaxSize; /**< GL_EXT_point_parameters */ GLfloat Threshold; /**< GL_EXT_point_parameters */ @@ -1133,13 +1131,13 @@ struct gl_stencil_attrib * An index for each type of texture object */ /*@{*/ -#define TEXTURE_1D_INDEX 0 -#define TEXTURE_2D_INDEX 1 -#define TEXTURE_3D_INDEX 2 -#define TEXTURE_CUBE_INDEX 3 -#define TEXTURE_RECT_INDEX 4 -#define TEXTURE_1D_ARRAY_INDEX 5 -#define TEXTURE_2D_ARRAY_INDEX 6 +#define TEXTURE_1D_INDEX 0 +#define TEXTURE_2D_INDEX 1 +#define TEXTURE_3D_INDEX 2 +#define TEXTURE_CUBE_INDEX 3 +#define TEXTURE_RECT_INDEX 4 +#define TEXTURE_1D_ARRAY_INDEX 5 +#define TEXTURE_2D_ARRAY_INDEX 6 /*@}*/ /** @@ -1147,13 +1145,13 @@ struct gl_stencil_attrib * Used for Texture.Unit[]._ReallyEnabled flags. */ /*@{*/ -#define TEXTURE_1D_BIT (1 << TEXTURE_1D_INDEX) -#define TEXTURE_2D_BIT (1 << TEXTURE_2D_INDEX) -#define TEXTURE_3D_BIT (1 << TEXTURE_3D_INDEX) -#define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX) -#define TEXTURE_RECT_BIT (1 << TEXTURE_RECT_INDEX) -#define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX) -#define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX) +#define TEXTURE_1D_BIT (1 << TEXTURE_1D_INDEX) +#define TEXTURE_2D_BIT (1 << TEXTURE_2D_INDEX) +#define TEXTURE_3D_BIT (1 << TEXTURE_3D_INDEX) +#define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX) +#define TEXTURE_RECT_BIT (1 << TEXTURE_RECT_INDEX) +#define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX) +#define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX) /*@}*/ @@ -1327,8 +1325,6 @@ struct gl_texture_format }; -#define MAX_3D_TEXTURE_SIZE (1 << (MAX_3D_TEXTURE_LEVELS - 1)) - /** * Texture image state. Describes the dimensions of a texture image, * the texel format and pointers to Texel Fetch functions. @@ -1393,7 +1389,7 @@ struct gl_texture_image #define FACE_NEG_Y 3 #define FACE_POS_Z 4 #define FACE_NEG_Z 5 -#define MAX_FACES 6 +#define MAX_FACES 6 /*@}*/ @@ -1404,6 +1400,7 @@ struct gl_texture_image */ struct gl_texture_object { + _glthread_Mutex Mutex; /**< for thread safety */ GLint RefCount; /**< reference count */ GLuint Name; /**< the user-visible texture object ID */ GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */ @@ -1539,17 +1536,6 @@ struct gl_texture_unit struct gl_texture_object *_Current; /**< Points to really enabled tex obj */ - /** These are used for glPush/PopAttrib */ - /*@{*/ - struct gl_texture_object Saved1D; - struct gl_texture_object Saved2D; - struct gl_texture_object Saved3D; - struct gl_texture_object SavedCubeMap; - struct gl_texture_object SavedRect; - struct gl_texture_object Saved1DArray; - struct gl_texture_object Saved2DArray; - /*@}*/ - /** GL_SGI_texture_color_table */ /*@{*/ struct gl_color_table ColorTable; @@ -1590,13 +1576,8 @@ struct gl_texture_attrib struct gl_texture_unit Unit[MAX_TEXTURE_UNITS]; - struct gl_texture_object *Proxy1D; - struct gl_texture_object *Proxy2D; - struct gl_texture_object *Proxy3D; - struct gl_texture_object *ProxyCubeMap; - struct gl_texture_object *ProxyRect; - struct gl_texture_object *Proxy1DArray; - struct gl_texture_object *Proxy2DArray; + /** Proxy texture objects */ + struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS]; /** GL_EXT_shared_texture_palette */ GLboolean SharedPalette; @@ -2193,12 +2174,11 @@ struct gl_shared_state * \todo Improve the granularity of locking. */ /*@{*/ - _glthread_Mutex TexMutex; /**< texobj thread safety */ - GLuint TextureStateStamp; /**< state notification for shared tex */ + _glthread_Mutex TexMutex; /**< texobj thread safety */ + GLuint TextureStateStamp; /**< state notification for shared tex */ /*@}*/ - /** * \name Vertex/fragment programs */ diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c index 0f562420b0..88e4989405 100644 --- a/src/mesa/main/points.c +++ b/src/mesa/main/points.c @@ -5,7 +5,7 @@ /* * Mesa 3-D graphics library - * Version: 7.0 + * Version: 7.1 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * @@ -57,10 +57,6 @@ _mesa_PointSize( GLfloat size ) FLUSH_VERTICES(ctx, _NEW_POINT); ctx->Point.Size = size; - /* XXX correct clamp limits? */ - ctx->Point._Size = CLAMP(ctx->Point.Size, - ctx->Point.MinSize, - ctx->Point.MaxSize); if (ctx->Driver.PointSize) ctx->Driver.PointSize(ctx, size); @@ -86,8 +82,13 @@ _mesa_PointParameteriNV( GLenum pname, GLint param ) void GLAPIENTRY _mesa_PointParameterivNV( GLenum pname, const GLint *params ) { - const GLfloat value = (GLfloat) params[0]; - _mesa_PointParameterfvEXT(pname, &value); + GLfloat p[3]; + p[0] = (GLfloat) params[0]; + if (pname == GL_DISTANCE_ATTENUATION_EXT) { + p[1] = (GLfloat) params[1]; + p[2] = (GLfloat) params[2]; + } + _mesa_PointParameterfvEXT(pname, p); } @@ -253,7 +254,6 @@ _mesa_init_point(GLcontext *ctx) ctx->Point.SmoothFlag = GL_FALSE; ctx->Point.Size = 1.0; - ctx->Point._Size = 1.0; ctx->Point.Params[0] = 1.0; ctx->Point.Params[1] = 0.0; ctx->Point.Params[2] = 0.0; diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c index 58be1f46e5..7bf8808767 100644 --- a/src/mesa/main/shaders.c +++ b/src/mesa/main/shaders.c @@ -83,7 +83,7 @@ _mesa_CreateShader(GLenum type) } -GLhandleARB APIENTRY +GLhandleARB GLAPIENTRY _mesa_CreateShaderObjectARB(GLenum type) { GET_CURRENT_CONTEXT(ctx); @@ -99,7 +99,7 @@ _mesa_CreateProgram(void) } -GLhandleARB APIENTRY +GLhandleARB GLAPIENTRY _mesa_CreateProgramObjectARB(void) { GET_CURRENT_CONTEXT(ctx); @@ -319,7 +319,7 @@ _mesa_GetUniformivARB(GLhandleARB program, GLint location, GLint * params) #if 0 -GLint APIENTRY +GLint GLAPIENTRY _mesa_GetUniformLocation(GLuint program, const GLcharARB *name) { GET_CURRENT_CONTEXT(ctx); @@ -336,7 +336,7 @@ _mesa_GetHandleARB(GLenum pname) } -GLint APIENTRY +GLint GLAPIENTRY _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name) { GET_CURRENT_CONTEXT(ctx); diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 0a83abc7dd..444f227760 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -35,10 +35,10 @@ #include "accum.h" #include "api_loopback.h" #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program -#include "arbprogram.h" +#include "shader/arbprogram.h" #endif #if FEATURE_ATI_fragment_shader -#include "atifragshader.h" +#include "shader/atifragshader.h" #endif #include "attrib.h" #include "blend.h" @@ -85,18 +85,18 @@ #include "mtypes.h" #include "varray.h" #if FEATURE_NV_vertex_program -#include "nvprogram.h" +#include "shader/nvprogram.h" #endif #if FEATURE_NV_fragment_program -#include "nvprogram.h" -#include "program.h" +#include "shader/nvprogram.h" +#include "shader/program.h" #include "texenvprogram.h" #endif #if FEATURE_ARB_shader_objects #include "shaders.h" #endif #include "debug.h" -#include "dispatch.h" +#include "glapi/dispatch.h" @@ -1068,7 +1068,7 @@ update_tricaps(GLcontext *ctx, GLbitfield new_state) if (1/*new_state & _NEW_POINT*/) { if (ctx->Point.SmoothFlag) ctx->_TriangleCaps |= DD_POINT_SMOOTH; - if (ctx->Point._Size != 1.0F) + if (ctx->Point.Size != 1.0F) ctx->_TriangleCaps |= DD_POINT_SIZE; if (ctx->Point._Attenuated) ctx->_TriangleCaps |= DD_POINT_ATTEN; @@ -1082,7 +1082,7 @@ update_tricaps(GLcontext *ctx, GLbitfield new_state) ctx->_TriangleCaps |= DD_LINE_SMOOTH; if (ctx->Line.StippleFlag) ctx->_TriangleCaps |= DD_LINE_STIPPLE; - if (ctx->Line._Width != 1.0) + if (ctx->Line.Width != 1.0) ctx->_TriangleCaps |= DD_LINE_WIDTH; } diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c index 411d51cfcc..b6991f45ed 100644 --- a/src/mesa/main/texcompress_fxt1.c +++ b/src/mesa/main/texcompress_fxt1.c @@ -302,7 +302,12 @@ const struct gl_texture_format _mesa_texformat_rgba_fxt1 = { #define FX64_NATIVE 1 +#ifdef __MINGW32__ +typedef unsigned long Fx64; +#else typedef unsigned long long Fx64; +#endif + #define FX64_MOV32(a, b) a = b #define FX64_OR32(a, b) a |= b diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c index c48063d919..4f329cdf59 100644 --- a/src/mesa/main/texcompress_s3tc.c +++ b/src/mesa/main/texcompress_s3tc.c @@ -577,6 +577,32 @@ const struct gl_texture_format _mesa_texformat_rgb_dxt1 = { NULL /* StoreTexel */ }; +#if FEATURE_EXT_texture_sRGB +const struct gl_texture_format _mesa_texformat_srgb_dxt1 = { + MESA_FORMAT_SRGB_DXT1, /* MesaFormat */ + GL_RGB, /* BaseFormat */ + GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ + 4, /*approx*/ /* RedBits */ + 4, /*approx*/ /* GreenBits */ + 4, /*approx*/ /* BlueBits */ + 0, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 0, /* StencilBits */ + 0, /* TexelBytes */ + texstore_rgb_dxt1, /* StoreTexImageFunc */ + NULL, /*impossible*/ /* FetchTexel1D */ + fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */ + NULL, /*impossible*/ /* FetchTexel3D */ + NULL, /*impossible*/ /* FetchTexel1Df */ + fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */ + NULL, /*impossible*/ /* FetchTexel3Df */ + NULL /* StoreTexel */ +}; +#endif + const struct gl_texture_format _mesa_texformat_rgba_dxt1 = { MESA_FORMAT_RGBA_DXT1, /* MesaFormat */ GL_RGBA, /* BaseFormat */ diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 1a46c10ffa..9c84da985e 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -28,17 +28,17 @@ #include "glheader.h" #include "macros.h" #include "enums.h" -#include "prog_parameter.h" -#include "prog_instruction.h" -#include "prog_print.h" -#include "prog_statevars.h" +#include "shader/prog_parameter.h" +#include "shader/prog_instruction.h" +#include "shader/prog_print.h" +#include "shader/prog_statevars.h" #include "texenvprogram.h" /** * According to Glean's texCombine test, no more than 21 instructions * are needed. Allow a few extra just in case. */ -#define MAX_INSTRUCTIONS 24 +#define MAX_INSTRUCTIONS ((MAX_TEXTURE_UNITS * 6) + 10) /* see bug 9829 */ #define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM) diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h index 55851db701..82023b946d 100644 --- a/src/mesa/main/texformat.h +++ b/src/mesa/main/texformat.h @@ -97,6 +97,7 @@ enum _format { MESA_FORMAT_SRGBA8, MESA_FORMAT_SL8, MESA_FORMAT_SLA8, + MESA_FORMAT_SRGB_DXT1, /*@}*/ #endif @@ -168,6 +169,7 @@ extern const struct gl_texture_format _mesa_texformat_srgb8; extern const struct gl_texture_format _mesa_texformat_srgba8; extern const struct gl_texture_format _mesa_texformat_sl8; extern const struct gl_texture_format _mesa_texformat_sla8; +extern const struct gl_texture_format _mesa_texformat_srgb_dxt1; /*@}*/ #endif diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index f902365b9b..1bc52d220a 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -760,15 +760,15 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, case GL_TEXTURE_1D: return texUnit->Current1D; case GL_PROXY_TEXTURE_1D: - return ctx->Texture.Proxy1D; + return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; case GL_TEXTURE_2D: return texUnit->Current2D; case GL_PROXY_TEXTURE_2D: - return ctx->Texture.Proxy2D; + return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; case GL_TEXTURE_3D: return texUnit->Current3D; case GL_PROXY_TEXTURE_3D: - return ctx->Texture.Proxy3D; + return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: @@ -780,25 +780,25 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, ? texUnit->CurrentCubeMap : NULL; case GL_PROXY_TEXTURE_CUBE_MAP_ARB: return ctx->Extensions.ARB_texture_cube_map - ? ctx->Texture.ProxyCubeMap : NULL; + ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL; case GL_TEXTURE_RECTANGLE_NV: return ctx->Extensions.NV_texture_rectangle ? texUnit->CurrentRect : NULL; case GL_PROXY_TEXTURE_RECTANGLE_NV: return ctx->Extensions.NV_texture_rectangle - ? ctx->Texture.ProxyRect : NULL; + ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL; case GL_TEXTURE_1D_ARRAY_EXT: return ctx->Extensions.MESA_texture_array ? texUnit->Current1DArray : NULL; case GL_PROXY_TEXTURE_1D_ARRAY_EXT: return ctx->Extensions.MESA_texture_array - ? ctx->Texture.Proxy1DArray : NULL; + ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL; case GL_TEXTURE_2D_ARRAY_EXT: return ctx->Extensions.MESA_texture_array ? texUnit->Current2DArray : NULL; case GL_PROXY_TEXTURE_2D_ARRAY_EXT: return ctx->Extensions.MESA_texture_array - ? ctx->Texture.Proxy2DArray : NULL; + ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; default: _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); return NULL; @@ -924,106 +924,106 @@ _mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level) case GL_PROXY_TEXTURE_1D: if (level >= ctx->Const.MaxTextureLevels) return NULL; - texImage = ctx->Texture.Proxy1D->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.Proxy1D->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.Proxy1D; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]; } return texImage; case GL_PROXY_TEXTURE_2D: if (level >= ctx->Const.MaxTextureLevels) return NULL; - texImage = ctx->Texture.Proxy2D->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.Proxy2D->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.Proxy2D; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]; } return texImage; case GL_PROXY_TEXTURE_3D: if (level >= ctx->Const.Max3DTextureLevels) return NULL; - texImage = ctx->Texture.Proxy3D->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.Proxy3D->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.Proxy3D; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]; } return texImage; case GL_PROXY_TEXTURE_CUBE_MAP: if (level >= ctx->Const.MaxCubeTextureLevels) return NULL; - texImage = ctx->Texture.ProxyCubeMap->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.ProxyCubeMap->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.ProxyCubeMap; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]; } return texImage; case GL_PROXY_TEXTURE_RECTANGLE_NV: if (level > 0) return NULL; - texImage = ctx->Texture.ProxyRect->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.ProxyRect->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.ProxyRect; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]; } return texImage; case GL_PROXY_TEXTURE_1D_ARRAY_EXT: if (level >= ctx->Const.MaxTextureLevels) return NULL; - texImage = ctx->Texture.Proxy1DArray->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.Proxy1DArray->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.Proxy1DArray; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]; } return texImage; case GL_PROXY_TEXTURE_2D_ARRAY_EXT: if (level >= ctx->Const.MaxTextureLevels) return NULL; - texImage = ctx->Texture.Proxy2DArray->Image[0][level]; + texImage = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level]; if (!texImage) { texImage = ctx->Driver.NewTextureImage(ctx); if (!texImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation"); return NULL; } - ctx->Texture.Proxy2DArray->Image[0][level] = texImage; + ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level] = texImage; /* Set the 'back' pointer */ - texImage->TexObject = ctx->Texture.Proxy2DArray; + texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]; } return texImage; default: @@ -1264,6 +1264,10 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target, * A hardware driver might override this function if, for example, the * max 3D texture size is 512x512x64 (i.e. not a cube). * + * Note that width, height, depth == 0 is not an error. However, a + * texture with zero width/height/depth will be considered "incomplete" + * and texturing will effectively be disabled. + * * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D, * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV, * GL_PROXY_TEXTURE_CUBE_MAP_ARB. @@ -1293,7 +1297,7 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); if (width < 2 * border || width > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(width - 2 * border) != 1) || + width >0 && _mesa_bitcount(width - 2 * border) != 1) || level >= ctx->Const.MaxTextureLevels) { /* bad width or level */ return GL_FALSE; @@ -1303,10 +1307,10 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); if (width < 2 * border || width > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(width - 2 * border) != 1) || + width > 0 && _mesa_bitcount(width - 2 * border) != 1) || height < 2 * border || height > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(height - 2 * border) != 1) || + height > 0 && _mesa_bitcount(height - 2 * border) != 1) || level >= ctx->Const.MaxTextureLevels) { /* bad width or height or level */ return GL_FALSE; @@ -1316,21 +1320,21 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); if (width < 2 * border || width > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(width - 2 * border) != 1) || + width > 0 && _mesa_bitcount(width - 2 * border) != 1) || height < 2 * border || height > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(height - 2 * border) != 1) || + height > 0 && _mesa_bitcount(height - 2 * border) != 1) || depth < 2 * border || depth > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(depth - 2 * border) != 1) || + depth > 0 && _mesa_bitcount(depth - 2 * border) != 1) || level >= ctx->Const.Max3DTextureLevels) { /* bad width or height or depth or level */ return GL_FALSE; } return GL_TRUE; case GL_PROXY_TEXTURE_RECTANGLE_NV: - if (width < 1 || width > ctx->Const.MaxTextureRectSize || - height < 1 || height > ctx->Const.MaxTextureRectSize || + if (width < 0 || width > ctx->Const.MaxTextureRectSize || + height < 0 || height > ctx->Const.MaxTextureRectSize || level != 0) { /* bad width or height or level */ return GL_FALSE; @@ -1340,10 +1344,10 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1); if (width < 2 * border || width > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(width - 2 * border) != 1) || + width > 0 && _mesa_bitcount(width - 2 * border) != 1) || height < 2 * border || height > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(height - 2 * border) != 1) || + height > 0 && _mesa_bitcount(height - 2 * border) != 1) || level >= ctx->Const.MaxCubeTextureLevels) { /* bad width or height */ return GL_FALSE; @@ -1353,7 +1357,7 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); if (width < 2 * border || width > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(width - 2 * border) != 1) || + width > 0 && _mesa_bitcount(width - 2 * border) != 1) || level >= ctx->Const.MaxTextureLevels) { /* bad width or level */ return GL_FALSE; @@ -1367,10 +1371,10 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); if (width < 2 * border || width > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(width - 2 * border) != 1) || + width > 0 && _mesa_bitcount(width - 2 * border) != 1) || height < 2 * border || height > 2 + maxSize || (!ctx->Extensions.ARB_texture_non_power_of_two && - _mesa_bitcount(height - 2 * border) != 1) || + height > 0 && _mesa_bitcount(height - 2 * border) != 1) || level >= ctx->Const.MaxTextureLevels) { /* bad width or height or level */ return GL_FALSE; @@ -1472,7 +1476,7 @@ texture_error_check( GLcontext *ctx, GLenum target, if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) { proxy_target = GL_PROXY_TEXTURE_1D; height = 1; - width = 1; + depth = 1; } else { _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); @@ -1994,7 +1998,7 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions, } if (is_compressed_format(ctx, internalFormat)) { - if (target != GL_TEXTURE_2D) { + if (!target_can_be_compressed(ctx, target)) { _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%d(target)", dimensions); return GL_TRUE; @@ -2177,7 +2181,7 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions, } if (teximage->IsCompressed) { - if (target != GL_TEXTURE_2D) { + if (!target_can_be_compressed(ctx, target)) { _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexSubImage%d(target)", dimensions); return GL_TRUE; @@ -2587,7 +2591,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, 1, border)) { /* when error, clear all proxy texture image parameters */ if (texImage) - clear_teximage_fields(ctx->Texture.Proxy2D->Image[0][level]); + clear_teximage_fields(ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level]); } else { /* no error, set the tex image parameters */ diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index df64002f99..3e017c1eda 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -5,9 +5,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -106,6 +106,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj, _mesa_bzero(obj, sizeof(*obj)); /* init the non-zero fields */ + _glthread_INIT_MUTEX(obj->Mutex); obj->RefCount = 1; obj->Name = name; obj->Target = target; @@ -153,6 +154,11 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj ) (void) ctx; + /* Set Target to an invalid value. With some assertions elsewhere + * we can try to detect possible use of deleted textures. + */ + texObj->Target = 0x99; + _mesa_free_colortable_data(&texObj->Palette); /* free the texture images */ @@ -164,6 +170,9 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj ) } } + /* destroy the mutex -- it may have allocated memory (eg on bsd) */ + _glthread_DESTROY_MUTEX(texObj->Mutex); + /* free this object */ _mesa_free(texObj); } @@ -182,6 +191,7 @@ void _mesa_copy_texture_object( struct gl_texture_object *dest, const struct gl_texture_object *src ) { + dest->Target = src->Target; dest->Name = src->Name; dest->Priority = src->Priority; dest->BorderColor[0] = src->BorderColor[0]; @@ -214,6 +224,94 @@ _mesa_copy_texture_object( struct gl_texture_object *dest, /** + * Check if the given texture object is valid by examining its Target field. + * For debugging only. + */ +static GLboolean +valid_texture_object(const struct gl_texture_object *tex) +{ + switch (tex->Target) { + case 0: + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_CUBE_MAP_ARB: + case GL_TEXTURE_RECTANGLE_NV: + case GL_TEXTURE_1D_ARRAY_EXT: + case GL_TEXTURE_2D_ARRAY_EXT: + return GL_TRUE; + case 0x99: + _mesa_problem(NULL, "invalid reference to a deleted texture object"); + return GL_FALSE; + default: + _mesa_problem(NULL, "invalid texture object Target value"); + return GL_FALSE; + } +} + + +/** + * Reference (or unreference) a texture object. + * If '*ptr', decrement *ptr's refcount (and delete if it becomes zero). + * If 'tex' is non-null, increment its refcount. + */ +void +_mesa_reference_texobj(struct gl_texture_object **ptr, + struct gl_texture_object *tex) +{ + assert(ptr); + if (*ptr == tex) { + /* no change */ + return; + } + + if (*ptr) { + /* Unreference the old texture */ + GLboolean deleteFlag = GL_FALSE; + struct gl_texture_object *oldTex = *ptr; + + assert(valid_texture_object(oldTex)); + + _glthread_LOCK_MUTEX(oldTex->Mutex); + ASSERT(oldTex->RefCount > 0); + oldTex->RefCount--; + + deleteFlag = (oldTex->RefCount == 0); + _glthread_UNLOCK_MUTEX(oldTex->Mutex); + + if (deleteFlag) { + GET_CURRENT_CONTEXT(ctx); + if (ctx) + ctx->Driver.DeleteTexture(ctx, oldTex); + else + _mesa_problem(NULL, "Unable to delete texture, no context"); + } + + *ptr = NULL; + } + assert(!*ptr); + + if (tex) { + /* reference new texture */ + assert(valid_texture_object(tex)); + _glthread_LOCK_MUTEX(tex->Mutex); + if (tex->RefCount == 0) { + /* this texture's being deleted (look just above) */ + /* Not sure this can every really happen. Warn if it does. */ + _mesa_problem(NULL, "referencing deleted texture object"); + *ptr = NULL; + } + else { + tex->RefCount++; + *ptr = tex; + } + _glthread_UNLOCK_MUTEX(tex->Mutex); + } +} + + + +/** * Report why a texture object is incomplete. * * \param t texture object. @@ -609,8 +707,7 @@ unbind_texobj_from_fbo(GLcontext *ctx, struct gl_texture_object *texObj) /** * Check if the given texture object is bound to any texture image units and - * unbind it if so. - * XXX all RefCount accesses should be protected by a mutex. + * unbind it if so (revert to default textures). */ static void unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj) @@ -619,42 +716,26 @@ unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj) for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) { struct gl_texture_unit *unit = &ctx->Texture.Unit[u]; - struct gl_texture_object **curr = NULL; - if (texObj == unit->Current1D) { - curr = &unit->Current1D; - unit->Current1D = ctx->Shared->Default1D; + _mesa_reference_texobj(&unit->Current1D, ctx->Shared->Default1D); } else if (texObj == unit->Current2D) { - curr = &unit->Current2D; - unit->Current2D = ctx->Shared->Default2D; + _mesa_reference_texobj(&unit->Current2D, ctx->Shared->Default2D); } else if (texObj == unit->Current3D) { - curr = &unit->Current3D; - unit->Current3D = ctx->Shared->Default3D; + _mesa_reference_texobj(&unit->Current3D, ctx->Shared->Default3D); } else if (texObj == unit->CurrentCubeMap) { - curr = &unit->CurrentCubeMap; - unit->CurrentCubeMap = ctx->Shared->DefaultCubeMap; + _mesa_reference_texobj(&unit->CurrentCubeMap, ctx->Shared->DefaultCubeMap); } else if (texObj == unit->CurrentRect) { - curr = &unit->CurrentRect; - unit->CurrentRect = ctx->Shared->DefaultRect; + _mesa_reference_texobj(&unit->CurrentRect, ctx->Shared->DefaultRect); } else if (texObj == unit->Current1DArray) { - curr = &unit->Current1DArray; - unit->CurrentRect = ctx->Shared->Default1DArray; + _mesa_reference_texobj(&unit->Current1DArray, ctx->Shared->Default1DArray); } else if (texObj == unit->Current2DArray) { - curr = &unit->Current1DArray; - unit->CurrentRect = ctx->Shared->Default2DArray; - } - - if (curr) { - (*curr)->RefCount++; - texObj->RefCount--; - if (texObj == unit->_Current) - unit->_Current = *curr; + _mesa_reference_texobj(&unit->Current2DArray, ctx->Shared->Default2DArray); } } } @@ -690,8 +771,6 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures) = _mesa_lookup_texture(ctx, textures[i]); if (delObj) { - GLboolean deleted; - _mesa_lock_texture(ctx, delObj); /* Check if texture is bound to any framebuffer objects. @@ -701,10 +780,12 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures) unbind_texobj_from_fbo(ctx, delObj); /* Check if this texture is currently bound to any texture units. - * If so, unbind it and decrement the reference count. + * If so, unbind it. */ unbind_texobj_from_texunits(ctx, delObj); + _mesa_unlock_texture(ctx, delObj); + ctx->NewState |= _NEW_TEXTURE; /* The texture _name_ is now free for re-use. @@ -714,23 +795,10 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures) _mesa_HashRemove(ctx->Shared->TexObjects, delObj->Name); _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); - /* The actual texture object will not be freed until it's no - * longer bound in any context. - * XXX all RefCount accesses should be protected by a mutex. + /* Unreference the texobj. If refcount hits zero, the texture + * will be deleted. */ - delObj->RefCount--; - deleted = (delObj->RefCount == 0); - _mesa_unlock_texture(ctx, delObj); - - /* We know that refcount went to zero above, so this is - * the only pointer left to delObj, so we don't have to - * worry about locking any more: - */ - if (deleted) { - ASSERT(delObj->Name != 0); /* Never delete default tex objs */ - ASSERT(ctx->Driver.DeleteTexture); - (*ctx->Driver.DeleteTexture)(ctx, delObj); - } + _mesa_reference_texobj(&delObj, NULL); } } } @@ -758,7 +826,6 @@ _mesa_BindTexture( GLenum target, GLuint texName ) GET_CURRENT_CONTEXT(ctx); const GLuint unit = ctx->Texture.CurrentUnit; struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - struct gl_texture_object *oldTexObj; struct gl_texture_object *newTexObj = NULL; ASSERT_OUTSIDE_BEGIN_END(ctx); @@ -767,62 +834,6 @@ _mesa_BindTexture( GLenum target, GLuint texName ) _mesa_lookup_enum_by_nr(target), (GLint) texName); /* - * Get pointer to currently bound texture object (oldTexObj) - */ - switch (target) { - case GL_TEXTURE_1D: - oldTexObj = texUnit->Current1D; - break; - case GL_TEXTURE_2D: - oldTexObj = texUnit->Current2D; - break; - case GL_TEXTURE_3D: - oldTexObj = texUnit->Current3D; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - if (!ctx->Extensions.ARB_texture_cube_map) { - _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); - return; - } - oldTexObj = texUnit->CurrentCubeMap; - break; - case GL_TEXTURE_RECTANGLE_NV: - if (!ctx->Extensions.NV_texture_rectangle) { - _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); - return; - } - oldTexObj = texUnit->CurrentRect; - break; - case GL_TEXTURE_1D_ARRAY_EXT: - if (!ctx->Extensions.MESA_texture_array) { - _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); - return; - } - oldTexObj = texUnit->Current1DArray; - break; - case GL_TEXTURE_2D_ARRAY_EXT: - if (!ctx->Extensions.MESA_texture_array) { - _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); - return; - } - oldTexObj = texUnit->Current2DArray; - break; - default: - _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); - return; - } - - if (oldTexObj->Name == texName) { - /* XXX this might be wrong. If the texobj is in use by another - * context and a texobj parameter was changed, this might be our - * only chance to update this context's hardware state. - * Note that some applications re-bind the same texture a lot so we - * want to handle that case quickly. - */ - return; /* rebinding the same texture- no change */ - } - - /* * Get pointer to new texture object (newTexObj) */ if (texName == 0) { @@ -896,28 +907,30 @@ _mesa_BindTexture( GLenum target, GLuint texName ) newTexObj->Target = target; } - /* XXX all RefCount accesses should be protected by a mutex. */ - newTexObj->RefCount++; + assert(valid_texture_object(newTexObj)); - /* do the actual binding, but first flush outstanding vertices: - */ + /* flush before changing binding */ FLUSH_VERTICES(ctx, _NEW_TEXTURE); + /* Do the actual binding. The refcount on the previously bound + * texture object will be decremented. It'll be deleted if the + * count hits zero. + */ switch (target) { case GL_TEXTURE_1D: - texUnit->Current1D = newTexObj; + _mesa_reference_texobj(&texUnit->Current1D, newTexObj); break; case GL_TEXTURE_2D: - texUnit->Current2D = newTexObj; + _mesa_reference_texobj(&texUnit->Current2D, newTexObj); break; case GL_TEXTURE_3D: - texUnit->Current3D = newTexObj; + _mesa_reference_texobj(&texUnit->Current3D, newTexObj); break; case GL_TEXTURE_CUBE_MAP_ARB: - texUnit->CurrentCubeMap = newTexObj; + _mesa_reference_texobj(&texUnit->CurrentCubeMap, newTexObj); break; case GL_TEXTURE_RECTANGLE_NV: - texUnit->CurrentRect = newTexObj; + _mesa_reference_texobj(&texUnit->CurrentRect, newTexObj); break; case GL_TEXTURE_1D_ARRAY_EXT: texUnit->Current1DArray = newTexObj; @@ -933,18 +946,6 @@ _mesa_BindTexture( GLenum target, GLuint texName ) /* Pass BindTexture call to device driver */ if (ctx->Driver.BindTexture) (*ctx->Driver.BindTexture)( ctx, target, newTexObj ); - - /* Decrement the reference count on the old texture and check if it's - * time to delete it. - */ - /* XXX all RefCount accesses should be protected by a mutex. */ - oldTexObj->RefCount--; - ASSERT(oldTexObj->RefCount >= 0); - if (oldTexObj->RefCount == 0) { - ASSERT(oldTexObj->Name != 0); - ASSERT(ctx->Driver.DeleteTexture); - (*ctx->Driver.DeleteTexture)( ctx, oldTexObj ); - } } diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h index 2a2bde3601..d5374c5d6c 100644 --- a/src/mesa/main/texobj.h +++ b/src/mesa/main/texobj.h @@ -58,6 +58,10 @@ _mesa_copy_texture_object( struct gl_texture_object *dest, const struct gl_texture_object *src ); extern void +_mesa_reference_texobj(struct gl_texture_object **ptr, + struct gl_texture_object *tex); + +extern void _mesa_test_texobj_completeness( const GLcontext *ctx, struct gl_texture_object *obj ); diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index c9f8a0656e..020e3eef4c 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -63,31 +63,6 @@ static const struct gl_tex_env_combine_state default_combine_state = { }; -/** - * Copy a texture binding. Helper used by _mesa_copy_texture_state(). - */ -static void -copy_texture_binding(const GLcontext *ctx, - struct gl_texture_object **dst, - struct gl_texture_object *src) -{ - /* only copy if names differ (per OpenGL SI) */ - if ((*dst)->Name != src->Name) { - /* unbind/delete dest binding which we're changing */ - (*dst)->RefCount--; - if ((*dst)->RefCount == 0) { - /* time to delete this texture object */ - ASSERT((*dst)->Name != 0); - ASSERT(ctx->Driver.DeleteTexture); - /* XXX cast-away const, unfortunately */ - (*ctx->Driver.DeleteTexture)((GLcontext *) ctx, *dst); - } - /* make new binding, incrementing ref count */ - *dst = src; - src->RefCount++; - } -} - /** * Used by glXCopyContext to copy texture state from one context to another. @@ -144,20 +119,20 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst ) /* copy texture object bindings, not contents of texture objects */ _mesa_lock_context_textures(dst); - copy_texture_binding(src, &dst->Texture.Unit[i].Current1D, - src->Texture.Unit[i].Current1D); - copy_texture_binding(src, &dst->Texture.Unit[i].Current2D, - src->Texture.Unit[i].Current2D); - copy_texture_binding(src, &dst->Texture.Unit[i].Current3D, - src->Texture.Unit[i].Current3D); - copy_texture_binding(src, &dst->Texture.Unit[i].CurrentCubeMap, - src->Texture.Unit[i].CurrentCubeMap); - copy_texture_binding(src, &dst->Texture.Unit[i].CurrentRect, - src->Texture.Unit[i].CurrentRect); - copy_texture_binding(src, &dst->Texture.Unit[i].Current1DArray, - src->Texture.Unit[i].Current1DArray); - copy_texture_binding(src, &dst->Texture.Unit[i].Current2DArray, - src->Texture.Unit[i].Current2DArray); + _mesa_reference_texobj(&dst->Texture.Unit[i].Current1D, + src->Texture.Unit[i].Current1D); + _mesa_reference_texobj(&dst->Texture.Unit[i].Current2D, + src->Texture.Unit[i].Current2D); + _mesa_reference_texobj(&dst->Texture.Unit[i].Current3D, + src->Texture.Unit[i].Current3D); + _mesa_reference_texobj(&dst->Texture.Unit[i].CurrentCubeMap, + src->Texture.Unit[i].CurrentCubeMap); + _mesa_reference_texobj(&dst->Texture.Unit[i].CurrentRect, + src->Texture.Unit[i].CurrentRect); + _mesa_reference_texobj(&dst->Texture.Unit[i].Current1DArray, + src->Texture.Unit[i].Current1DArray); + _mesa_reference_texobj(&dst->Texture.Unit[i].Current2DArray, + src->Texture.Unit[i].Current2DArray); _mesa_unlock_context_textures(dst); } @@ -3085,52 +3060,32 @@ _mesa_update_texture( GLcontext *ctx, GLuint new_state ) static GLboolean alloc_proxy_textures( GLcontext *ctx ) { - ctx->Texture.Proxy1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D); - if (!ctx->Texture.Proxy1D) - goto cleanup; - - ctx->Texture.Proxy2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D); - if (!ctx->Texture.Proxy2D) - goto cleanup; - - ctx->Texture.Proxy3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D); - if (!ctx->Texture.Proxy3D) - goto cleanup; - - ctx->Texture.ProxyCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB); - if (!ctx->Texture.ProxyCubeMap) - goto cleanup; - - ctx->Texture.ProxyRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV); - if (!ctx->Texture.ProxyRect) - goto cleanup; - - ctx->Texture.Proxy1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT); - if (!ctx->Texture.Proxy1DArray) - goto cleanup; - - ctx->Texture.Proxy2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT); - if (!ctx->Texture.Proxy2DArray) - goto cleanup; + static const GLenum targets[] = { + GL_TEXTURE_1D, + GL_TEXTURE_2D, + GL_TEXTURE_3D, + GL_TEXTURE_CUBE_MAP_ARB, + GL_TEXTURE_RECTANGLE_NV, + GL_TEXTURE_1D_ARRAY_EXT, + GL_TEXTURE_2D_ARRAY_EXT + }; + GLint tgt; + + ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS); + + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + if (!(ctx->Texture.ProxyTex[tgt] + = ctx->Driver.NewTextureObject(ctx, 0, targets[tgt]))) { + /* out of memory, free what we did allocate */ + while (--tgt >= 0) { + ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]); + } + return GL_FALSE; + } + } + assert(ctx->Texture.ProxyTex[0]->RefCount == 1); /* sanity check */ return GL_TRUE; - - cleanup: - if (ctx->Texture.Proxy1D) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D); - if (ctx->Texture.Proxy2D) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D); - if (ctx->Texture.Proxy3D) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D); - if (ctx->Texture.ProxyCubeMap) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap); - if (ctx->Texture.ProxyRect) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect); - if (ctx->Texture.Proxy1DArray) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1DArray); - if (ctx->Texture.Proxy2DArray) - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2DArray); - return GL_FALSE; } @@ -3172,13 +3127,14 @@ init_texture_unit( GLcontext *ctx, GLuint unit ) ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 ); ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 ); - texUnit->Current1D = ctx->Shared->Default1D; - texUnit->Current2D = ctx->Shared->Default2D; - texUnit->Current3D = ctx->Shared->Default3D; - texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap; - texUnit->CurrentRect = ctx->Shared->DefaultRect; - texUnit->Current1DArray = ctx->Shared->Default1DArray; - texUnit->Current2DArray = ctx->Shared->Default2DArray; + /* initialize current texture object ptrs to the shared default objects */ + _mesa_reference_texobj(&texUnit->Current1D, ctx->Shared->Default1D); + _mesa_reference_texobj(&texUnit->Current2D, ctx->Shared->Default2D); + _mesa_reference_texobj(&texUnit->Current3D, ctx->Shared->Default3D); + _mesa_reference_texobj(&texUnit->CurrentCubeMap, ctx->Shared->DefaultCubeMap); + _mesa_reference_texobj(&texUnit->CurrentRect, ctx->Shared->DefaultRect); + _mesa_reference_texobj(&texUnit->Current1DArray, ctx->Shared->Default1DArray); + _mesa_reference_texobj(&texUnit->Current2DArray, ctx->Shared->Default2DArray); } @@ -3193,23 +3149,20 @@ _mesa_init_texture(GLcontext *ctx) assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS); assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS); - /* Effectively bind the default textures to all texture units */ - ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS; - ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS; - ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS; - ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS; - ctx->Shared->DefaultRect->RefCount += MAX_TEXTURE_UNITS; - ctx->Shared->Default1DArray->RefCount += MAX_TEXTURE_UNITS; - ctx->Shared->Default2DArray->RefCount += MAX_TEXTURE_UNITS; - /* Texture group */ ctx->Texture.CurrentUnit = 0; /* multitexture */ ctx->Texture._EnabledUnits = 0; - for (i=0; i<MAX_TEXTURE_UNITS; i++) - init_texture_unit( ctx, i ); ctx->Texture.SharedPalette = GL_FALSE; _mesa_init_colortable(&ctx->Texture.Palette); + for (i = 0; i < MAX_TEXTURE_UNITS; i++) + init_texture_unit( ctx, i ); + + /* After we're done initializing the context's texture state the default + * texture objects' refcounts should be at least MAX_TEXTURE_UNITS + 1. + */ + assert(ctx->Shared->Default1D->RefCount >= MAX_TEXTURE_UNITS + 1); + _mesa_TexEnvProgramCacheInit( ctx ); /* Allocate proxy textures */ @@ -3226,19 +3179,26 @@ _mesa_init_texture(GLcontext *ctx) void _mesa_free_texture_data(GLcontext *ctx) { - GLuint i; + GLuint u, tgt; + + /* unreference current textures */ + for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) { + struct gl_texture_unit *unit = ctx->Texture.Unit + u; + _mesa_reference_texobj(&unit->Current1D, NULL); + _mesa_reference_texobj(&unit->Current2D, NULL); + _mesa_reference_texobj(&unit->Current3D, NULL); + _mesa_reference_texobj(&unit->CurrentCubeMap, NULL); + _mesa_reference_texobj(&unit->CurrentRect, NULL); + _mesa_reference_texobj(&unit->Current1DArray, NULL); + _mesa_reference_texobj(&unit->Current2DArray, NULL); + } /* Free proxy texture objects */ - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D ); - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D ); - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D ); - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap ); - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect ); - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1DArray ); - (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2DArray ); - - for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) - _mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable ); + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) + ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]); + + for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) + _mesa_free_colortable_data( &ctx->Texture.Unit[u].ColorTable ); _mesa_TexEnvProgramCacheDestroy( ctx ); } diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 9b8a06df14..3b5151ed17 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1077,7 +1077,7 @@ _mesa_texstore_rgba(TEXSTORE_PARAMS) GLboolean _mesa_texstore_z32(TEXSTORE_PARAMS) { - const GLfloat depthScale = (GLfloat) 0xffffffff; + const GLuint depthScale = 0xffffffff; (void) dims; ASSERT(dstFormat == &_mesa_texformat_z32); ASSERT(dstFormat->TexelBytes == sizeof(GLuint)); @@ -1124,7 +1124,7 @@ _mesa_texstore_z32(TEXSTORE_PARAMS) GLboolean _mesa_texstore_z16(TEXSTORE_PARAMS) { - const GLfloat depthScale = 65535.0f; + const GLuint depthScale = 0xffff; (void) dims; ASSERT(dstFormat == &_mesa_texformat_z16); ASSERT(dstFormat->TexelBytes == sizeof(GLushort)); @@ -2319,6 +2319,8 @@ _mesa_texstore_ycbcr(TEXSTORE_PARAMS) GLboolean _mesa_texstore_z24_s8(TEXSTORE_PARAMS) { + const GLuint depthScale = 0xffffff; + ASSERT(dstFormat == &_mesa_texformat_z24_s8); ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT); ASSERT(srcType == GL_UNSIGNED_INT_24_8_EXT); @@ -2357,7 +2359,7 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS) _mesa_unpack_depth_span(ctx, srcWidth, GL_UNSIGNED_INT, /* dst type */ dstRow, /* dst addr */ - (GLfloat) 0xffffff, /* depthScale */ + depthScale, srcType, src, srcPacking); /* get the 8-bit stencil values */ _mesa_unpack_stencil_span(ctx, srcWidth, diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index bf1ad0165e..fe4a7c684f 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -32,7 +32,7 @@ #include "mtypes.h" #include "varray.h" #include "arrayobj.h" -#include "dispatch.h" +#include "glapi/dispatch.h" /** diff --git a/src/mesa/main/vtxfmt_tmp.h b/src/mesa/main/vtxfmt_tmp.h index 783b06558d..6f5d01e40f 100644 --- a/src/mesa/main/vtxfmt_tmp.h +++ b/src/mesa/main/vtxfmt_tmp.h @@ -29,8 +29,8 @@ #define PRE_LOOPBACK( FUNC ) #endif -#include "dispatch.h" -#include "glapioffsets.h" +#include "glapi/dispatch.h" +#include "glapi/glapioffsets.h" static void GLAPIENTRY TAG(ArrayElement)( GLint i ) { diff --git a/src/mesa/math/m_eval.c b/src/mesa/math/m_eval.c index 42ffd4133d..d324673c5d 100644 --- a/src/mesa/math/m_eval.c +++ b/src/mesa/math/m_eval.c @@ -37,8 +37,8 @@ */ -#include "glheader.h" -#include "config.h" +#include "main/glheader.h" +#include "main/config.h" #include "m_eval.h" static GLfloat inv_tab[MAX_EVAL_ORDER]; diff --git a/src/mesa/math/m_eval.h b/src/mesa/math/m_eval.h index a23cbd402e..d73ecaafb2 100644 --- a/src/mesa/math/m_eval.h +++ b/src/mesa/math/m_eval.h @@ -26,7 +26,7 @@ #ifndef _M_EVAL_H #define _M_EVAL_H -#include "glheader.h" +#include "main/glheader.h" void _math_init_eval( void ); diff --git a/src/mesa/math/m_translate.h b/src/mesa/math/m_translate.h index 0bcf96005c..c677682d50 100644 --- a/src/mesa/math/m_translate.h +++ b/src/mesa/math/m_translate.h @@ -26,8 +26,8 @@ #ifndef _M_TRANSLATE_H_ #define _M_TRANSLATE_H_ -#include "config.h" -#include "mtypes.h" /* hack for GLchan */ +#include "main/config.h" +#include "main/mtypes.h" /* hack for GLchan */ /** diff --git a/src/mesa/math/m_xform.c b/src/mesa/math/m_xform.c index fa3f57a8e5..901ae5b416 100644 --- a/src/mesa/math/m_xform.c +++ b/src/mesa/math/m_xform.c @@ -33,8 +33,8 @@ * 3. Transformation of a point p by a matrix M is: p' = M * p */ -#include "glheader.h" -#include "macros.h" +#include "main/glheader.h" +#include "main/macros.h" #include "m_eval.h" #include "m_matrix.h" diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 5d8f763741..9a5290d920 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -30,10 +30,10 @@ * \author Karl Rasche */ -#include "glheader.h" -#include "imports.h" +#include "main/glheader.h" +#include "main/imports.h" +#include "shader/grammar/grammar_mesa.h" #include "arbprogparse.h" -#include "grammar_mesa.h" #include "program.h" #include "prog_parameter.h" #include "prog_statevars.h" @@ -3573,7 +3573,7 @@ parse_instructions(GLcontext * ctx, const GLubyte * inst, /* XXX temporary */ LONGSTRING static char core_grammar_text[] = -#include "grammar_syn.h" +#include "shader/grammar/grammar_syn.h" ; diff --git a/src/mesa/shader/atifragshader.c b/src/mesa/shader/atifragshader.c index 4727c1a436..854c911874 100644 --- a/src/mesa/shader/atifragshader.c +++ b/src/mesa/shader/atifragshader.c @@ -440,7 +440,7 @@ _mesa_PassTexCoordATI(GLuint dst, GLuint coord, GLenum swizzle) _mesa_error(ctx, GL_INVALID_OPERATION, "glPassTexCoordATI(coord)"); return; } - if ((swizzle < GL_SWIZZLE_STR_ATI) && (swizzle > GL_SWIZZLE_STQ_DQ_ATI)) { + if (!(swizzle >= GL_SWIZZLE_STR_ATI) && (swizzle <= GL_SWIZZLE_STQ_DQ_ATI)) { _mesa_error(ctx, GL_INVALID_ENUM, "glPassTexCoordATI(swizzle)"); return; } @@ -513,7 +513,7 @@ _mesa_SampleMapATI(GLuint dst, GLuint interp, GLenum swizzle) _mesa_error(ctx, GL_INVALID_OPERATION, "glSampleMapATI(interp)"); return; } - if ((swizzle < GL_SWIZZLE_STR_ATI) && (swizzle > GL_SWIZZLE_STQ_DQ_ATI)) { + if (!(swizzle >= GL_SWIZZLE_STR_ATI) && (swizzle <= GL_SWIZZLE_STQ_DQ_ATI)) { _mesa_error(ctx, GL_INVALID_ENUM, "glSampleMapATI(swizzle)"); return; } diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c index 9faf9d8613..28d195d0ee 100644 --- a/src/mesa/shader/prog_execute.c +++ b/src/mesa/shader/prog_execute.c @@ -43,7 +43,7 @@ #include "prog_instruction.h" #include "prog_parameter.h" #include "prog_print.h" -#include "slang_library_noise.h" +#include "shader/slang/slang_library_noise.h" /* See comments below for info about this */ diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 4205919828..1f227390af 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -333,7 +333,7 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog) { struct gl_program *clone; - clone = _mesa_new_program(ctx, prog->Target, prog->Id); + clone = ctx->Driver.NewProgram(ctx, prog->Target, prog->Id); if (!clone) return NULL; diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 3a54e68d0d..a1e73ef125 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -43,10 +43,9 @@ #include "prog_parameter.h" #include "prog_print.h" #include "prog_statevars.h" -#include "shader_api.h" - -#include "slang_compile.h" -#include "slang_link.h" +#include "shader/shader_api.h" +#include "shader/slang/slang_compile.h" +#include "shader/slang/slang_link.h" @@ -378,7 +377,7 @@ _mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader) struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); - const GLuint n = shProg->NumShaders; + GLuint n; GLuint i; if (!shProg || !sh) { @@ -387,6 +386,8 @@ _mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader) return; } + n = shProg->NumShaders; + for (i = 0; i < n; i++) { if (shProg->Shaders[i] == sh) { /* already attached */ @@ -548,7 +549,7 @@ _mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader) { struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); - const GLuint n = shProg->NumShaders; + GLuint n; GLuint i, j; if (!shProg) { @@ -557,6 +558,8 @@ _mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader) return; } + n = shProg->NumShaders; + for (i = 0; i < n; i++) { if (shProg->Shaders[i]->Name == shader) { /* found it */ @@ -780,7 +783,7 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program, *params = shProg->Validated; break; case GL_INFO_LOG_LENGTH: - *params = shProg->InfoLog ? strlen(shProg->InfoLog) : 0; + *params = shProg->InfoLog ? strlen(shProg->InfoLog) + 1 : 0; break; case GL_ATTACHED_SHADERS: *params = shProg->NumShaders; @@ -832,10 +835,10 @@ _mesa_get_shaderiv(GLcontext *ctx, GLuint name, GLenum pname, GLint *params) *params = shader->CompileStatus; break; case GL_INFO_LOG_LENGTH: - *params = shader->InfoLog ? strlen(shader->InfoLog) : 0; + *params = shader->InfoLog ? strlen(shader->InfoLog) + 1 : 0; break; case GL_SHADER_SOURCE_LENGTH: - *params = shader->Source ? strlen((char *) shader->Source) : 0; + *params = shader->Source ? strlen((char *) shader->Source) + 1 : 0; break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glGetShaderiv(pname)"); diff --git a/src/mesa/shader/slang/slang_builtin.c b/src/mesa/shader/slang/slang_builtin.c index 6ee0fd33b6..1081d8ff8d 100644 --- a/src/mesa/shader/slang/slang_builtin.c +++ b/src/mesa/shader/slang/slang_builtin.c @@ -28,14 +28,14 @@ * \author Brian Paul */ -#include "imports.h" -#include "slang_builtin.h" -#include "slang_ir.h" -#include "mtypes.h" -#include "program.h" -#include "prog_instruction.h" -#include "prog_parameter.h" -#include "prog_statevars.h" +#include "main/imports.h" +#include "main/mtypes.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/prog_statevars.h" +#include "shader/slang/slang_ir.h" +#include "shader/slang/slang_builtin.h" /** diff --git a/src/mesa/shader/slang/slang_builtin.h b/src/mesa/shader/slang/slang_builtin.h index ae20c844d5..58629f4f7f 100644 --- a/src/mesa/shader/slang/slang_builtin.h +++ b/src/mesa/shader/slang/slang_builtin.h @@ -26,7 +26,7 @@ #ifndef SLANG_BUILTIN_H #define SLANG_BUILTIN_H -#include "prog_parameter.h" +#include "shader/prog_parameter.h" #include "slang_utility.h" #include "slang_ir.h" diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index f3a6d04428..d368009ca5 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 + * Version: 7.1 * * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. * @@ -37,13 +37,13 @@ -#include "imports.h" -#include "macros.h" -#include "mtypes.h" -#include "program.h" -#include "prog_instruction.h" -#include "prog_parameter.h" -#include "prog_statevars.h" +#include "main/imports.h" +#include "main/macros.h" +#include "main/mtypes.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/prog_statevars.h" #include "slang_typeinfo.h" #include "slang_codegen.h" #include "slang_compile.h" @@ -491,6 +491,9 @@ new_node0(slang_ir_opcode op) } +/** + * Create sequence of two nodes. + */ static slang_ir_node * new_seq(slang_ir_node *left, slang_ir_node *right) { @@ -531,12 +534,12 @@ new_not(slang_ir_node *n) /** - * Inlined subroutine. + * Non-inlined function call. */ static slang_ir_node * -new_inlined_function_call(slang_ir_node *code, slang_label *name) +new_function_call(slang_ir_node *code, slang_label *name) { - slang_ir_node *n = new_node1(IR_FUNC, code); + slang_ir_node *n = new_node1(IR_CALL, code); assert(name); if (n) n->Label = name; @@ -1202,17 +1205,29 @@ _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, /* non-assembly function */ inlined = slang_inline_function_call(A, fun, oper, dest); if (inlined && _slang_find_node_type(inlined, SLANG_OPER_RETURN)) { - /* This inlined function has one or more 'return' statements. + slang_operation *callOper; + /* The function we're calling has one or more 'return' statements. * So, we can't truly inline this function because we need to * implement 'return' with RET (and CAL). + * Nevertheless, we performed "inlining" to make a new instance + * of the function body to deal with static register allocation. + * * XXX check if there's one 'return' and if it's the very last * statement in the function - we can optimize that case. */ assert(inlined->type == SLANG_OPER_BLOCK_NEW_SCOPE || inlined->type == SLANG_OPER_SEQUENCE); - inlined->type = SLANG_OPER_INLINED_CALL; - inlined->fun = fun; - inlined->label = _slang_label_new_unique((char*) fun->header.a_name); + if (_slang_function_has_return_value(fun) && !dest) { + assert(inlined->children[0].type == SLANG_OPER_VARIABLE_DECL); + assert(inlined->children[2].type == SLANG_OPER_IDENTIFIER); + callOper = &inlined->children[1]; + } + else { + callOper = inlined; + } + callOper->type = SLANG_OPER_NON_INLINED_CALL; + callOper->fun = fun; + callOper->label = _slang_label_new_unique((char*) fun->header.a_name); } } @@ -1949,8 +1964,7 @@ static slang_ir_node * _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) { const GLboolean haveReturnValue - = (oper->num_children == 1 && - oper->children[0].type != SLANG_OPER_VOID); + = (oper->num_children == 1 && oper->children[0].type != SLANG_OPER_VOID); /* error checking */ assert(A->CurFunction); @@ -1960,7 +1974,7 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) return NULL; } else if (!haveReturnValue && - A->CurFunction->header.type.specifier.type != SLANG_SPEC_VOID) { + A->CurFunction->header.type.specifier.type != SLANG_SPEC_VOID) { slang_info_log_error(A->log, "return statement requires an expression"); return NULL; } @@ -2045,7 +2059,8 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) } /* XXX make copy of this initializer? */ rhs = _slang_gen_operation(A, &oper->children[0]); - assert(rhs); + if (!rhs) + return NULL; /* must have found an error */ init = new_node2(IR_MOVE, var, rhs); /*assert(rhs->Opcode != IR_SEQ);*/ n = new_seq(varDecl, init); @@ -2236,7 +2251,9 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper) } if (var->type.qualifier == SLANG_QUAL_CONST || var->type.qualifier == SLANG_QUAL_ATTRIBUTE || - var->type.qualifier == SLANG_QUAL_UNIFORM) { + var->type.qualifier == SLANG_QUAL_UNIFORM || + (var->type.qualifier == SLANG_QUAL_VARYING && + A->program->Target == GL_FRAGMENT_PROGRAM_ARB)) { slang_info_log_error(A->log, "illegal assignment to read-only variable '%s'", (char *) oper->children[0].a_id); @@ -2264,10 +2281,11 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper) lhs = _slang_gen_operation(A, &oper->children[0]); if (lhs) { - if (lhs->Store->File != PROGRAM_OUTPUT && - lhs->Store->File != PROGRAM_TEMPORARY && - lhs->Store->File != PROGRAM_VARYING && - lhs->Store->File != PROGRAM_UNDEFINED) { + if (!(lhs->Store->File == PROGRAM_OUTPUT || + lhs->Store->File == PROGRAM_TEMPORARY || + (lhs->Store->File == PROGRAM_VARYING && + A->program->Target == GL_VERTEX_PROGRAM_ARB) || + lhs->Store->File == PROGRAM_UNDEFINED)) { slang_info_log_error(A->log, "illegal assignment to read-only l-value"); return NULL; @@ -2328,7 +2346,8 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper) n = _slang_gen_swizzle(n, swizzle); return n; } - else if (ti.spec.type == SLANG_SPEC_FLOAT) { + else if ( ti.spec.type == SLANG_SPEC_FLOAT + || ti.spec.type == SLANG_SPEC_INT) { const GLuint rows = 1; slang_swizzle swz; slang_ir_node *n; @@ -2570,7 +2589,7 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) _slang_free_ir_tree(tree); return NULL; /* error must have occured */ } - tree = tree ? new_seq(tree, n) : n; + tree = new_seq(tree, n); } #if 00 @@ -2798,17 +2817,17 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return n; } - case SLANG_OPER_INLINED_CALL: + case SLANG_OPER_NON_INLINED_CALL: case SLANG_OPER_SEQUENCE: { slang_ir_node *tree = NULL; GLuint i; for (i = 0; i < oper->num_children; i++) { slang_ir_node *n = _slang_gen_operation(A, &oper->children[i]); - tree = tree ? new_seq(tree, n) : n; + tree = new_seq(tree, n); } - if (oper->type == SLANG_OPER_INLINED_CALL) { - tree = new_inlined_function_call(tree, oper->label); + if (oper->type == SLANG_OPER_NON_INLINED_CALL) { + tree = new_function_call(tree, oper->label); } return tree; } diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index a4dd5b8b4a..4e29e8dcc9 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -28,11 +28,11 @@ * \author Michal Krol */ -#include "imports.h" -#include "context.h" -#include "program.h" -#include "prog_parameter.h" -#include "grammar_mesa.h" +#include "main/imports.h" +#include "main/context.h" +#include "shader/program.h" +#include "shader/prog_parameter.h" +#include "shader/grammar/grammar_mesa.h" #include "slang_codegen.h" #include "slang_compile.h" #include "slang_preprocess.h" @@ -2135,7 +2135,7 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) progTarget = GL_FRAGMENT_PROGRAM_ARB; shader->Programs = (struct gl_program **) malloc(sizeof(struct gl_program*)); - shader->Programs[0] = _mesa_new_program(ctx, progTarget, 1); + shader->Programs[0] = ctx->Driver.NewProgram(ctx, progTarget, 1); shader->NumPrograms = 1; shader->Programs[0]->Parameters = _mesa_new_parameter_list(); diff --git a/src/mesa/shader/slang/slang_compile_operation.h b/src/mesa/shader/slang/slang_compile_operation.h index d497b6f66f..d5cbe779a6 100644 --- a/src/mesa/shader/slang/slang_compile_operation.h +++ b/src/mesa/shader/slang/slang_compile_operation.h @@ -93,7 +93,7 @@ typedef enum slang_operation_type_ SLANG_OPER_NOT, /* "!" [expr] */ SLANG_OPER_SUBSCRIPT, /* [expr] "[" [expr] "]" */ SLANG_OPER_CALL, /* [func name] [param] [param] [...] */ - SLANG_OPER_INLINED_CALL, /* inlined function call */ + SLANG_OPER_NON_INLINED_CALL, /* a real function call */ SLANG_OPER_FIELD, /* i.e.: ".next" or ".xzy" or ".xxx" etc */ SLANG_OPER_POSTINCREMENT, /* [var] "++" */ SLANG_OPER_POSTDECREMENT /* [var] "--" */ diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 7804e19236..fe13f2865c 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -36,13 +36,13 @@ ***/ -#include "imports.h" -#include "context.h" -#include "macros.h" -#include "program.h" -#include "prog_instruction.h" -#include "prog_parameter.h" -#include "prog_print.h" +#include "main/imports.h" +#include "main/context.h" +#include "main/macros.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/prog_print.h" #include "slang_builtin.h" #include "slang_emit.h" #include "slang_mem.h" @@ -780,16 +780,18 @@ emit_label(slang_emit_info *emitInfo, const slang_ir_node *n) /** - * Emit code for an inlined function call (subroutine). + * Emit code for a function call. + * Note that for each time a function is called, we emit the function's + * body code again because the set of available registers may be different. */ static struct prog_instruction * -emit_func(slang_emit_info *emitInfo, slang_ir_node *n) +emit_fcall(slang_emit_info *emitInfo, slang_ir_node *n) { struct gl_program *progSave; struct prog_instruction *inst; GLuint subroutineId; - assert(n->Opcode == IR_FUNC); + assert(n->Opcode == IR_CALL); assert(n->Label); /* save/push cur program */ @@ -1687,10 +1689,10 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n) case IR_KILL: return emit_kill(emitInfo); - case IR_FUNC: - /* new variable scope for subroutines/function calls*/ + case IR_CALL: + /* new variable scope for subroutines/function calls */ _slang_push_var_table(emitInfo->vt); - inst = emit_func(emitInfo, n); + inst = emit_fcall(emitInfo, n); _slang_pop_var_table(emitInfo->vt); return inst; @@ -1782,7 +1784,7 @@ _slang_resolve_subroutines(slang_emit_info *emitInfo) emitInfo->NumSubroutines = 0; /* Examine CAL instructions. - * At this point, the BranchTarget field of the CAL instructions is + * At this point, the BranchTarget field of the CAL instruction is * the number/id of the subroutine to call (an index into the * emitInfo->Subroutines list). * Translate that into an actual instruction location now. diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c index a6903cc8b6..92e8d0345e 100644 --- a/src/mesa/shader/slang/slang_ir.c +++ b/src/mesa/shader/slang/slang_ir.c @@ -27,7 +27,7 @@ #include "context.h" #include "slang_ir.h" #include "slang_mem.h" -#include "prog_print.h" +#include "shader/prog_print.h" static const slang_ir_info IrInfo[] = { @@ -311,7 +311,7 @@ _slang_print_ir_tree(const slang_ir_node *n, int indent) printf("RETURN\n"); break; case IR_CALL: - printf("CALL\n"); + printf("CALL %s\n", n->Label->Name); break; case IR_LOOP: diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h index 69db4b5451..c7c0ddbf9a 100644 --- a/src/mesa/shader/slang/slang_ir.h +++ b/src/mesa/shader/slang/slang_ir.h @@ -62,8 +62,6 @@ typedef enum IR_RETURN, /* return from subroutine */ IR_CALL, /* call subroutine */ - IR_FUNC, /* inlined function code */ - IR_LOOP, /* high-level loop-begin / loop-end */ /* Children[0] = loop body */ /* Children[1] = loop tail code, or NULL */ diff --git a/src/mesa/shader/slang/slang_label.h b/src/mesa/shader/slang/slang_label.h index 0f1a45b30f..87068ae7a7 100644 --- a/src/mesa/shader/slang/slang_label.h +++ b/src/mesa/shader/slang/slang_label.h @@ -1,9 +1,9 @@ #ifndef SLANG_LABEL_H #define SLANG_LABEL_H 1 -#include "imports.h" -#include "mtypes.h" -#include "prog_instruction.h" +#include "main/imports.h" +#include "main/mtypes.h" +#include "shader/prog_instruction.h" struct slang_label_ diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index d6d1c7523e..c8457fc483 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -28,16 +28,16 @@ * \author Brian Paul */ -#include "imports.h" -#include "context.h" -#include "hash.h" -#include "macros.h" -#include "program.h" -#include "prog_instruction.h" -#include "prog_parameter.h" -#include "prog_print.h" -#include "prog_statevars.h" -#include "shader_api.h" +#include "main/imports.h" +#include "main/context.h" +#include "main/hash.h" +#include "main/macros.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/prog_print.h" +#include "shader/prog_statevars.h" +#include "shader/shader_api.h" #include "slang_link.h" @@ -329,8 +329,10 @@ _slang_resolve_attributes(struct gl_shader_program *shProg, * glVertex/position. */ for (attr = 1; attr < MAX_VERTEX_ATTRIBS; attr++) { - if (((1 << attr) & usedAttributes) == 0) + if (((1 << attr) & usedAttributes) == 0) { + usedAttributes |= (1 << attr); break; + } } if (attr == MAX_VERTEX_ATTRIBS) { /* too many! XXX record error log */ diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c index 72281eda57..076e982f8f 100644 --- a/src/mesa/shader/slang/slang_preprocess.c +++ b/src/mesa/shader/slang/slang_preprocess.c @@ -29,7 +29,7 @@ */ #include "imports.h" -#include "grammar_mesa.h" +#include "shader/grammar/grammar_mesa.h" #include "slang_preprocess.h" LONGSTRING static const char *slang_pp_directives_syn = diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index da0b32bc44..8a1c3abf48 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -28,12 +28,12 @@ * \author Michal Krol */ -#include "imports.h" +#include "main/imports.h" +#include "shader/prog_instruction.h" #include "slang_typeinfo.h" #include "slang_compile.h" #include "slang_log.h" #include "slang_mem.h" -#include "prog_instruction.h" /** diff --git a/src/mesa/shader/slang/slang_vartable.c b/src/mesa/shader/slang/slang_vartable.c index 8a3c299d19..1d817000c6 100644 --- a/src/mesa/shader/slang/slang_vartable.c +++ b/src/mesa/shader/slang/slang_vartable.c @@ -1,11 +1,11 @@ -#include "imports.h" +#include "main/imports.h" +#include "shader/prog_instruction.h" #include "slang_compile.h" #include "slang_compile_variable.h" #include "slang_mem.h" #include "slang_vartable.h" #include "slang_ir.h" -#include "prog_instruction.h" static int dbg = 0; diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h index 69a1f0cd39..e7911fec3b 100644 --- a/src/mesa/swrast/s_aalinetemp.h +++ b/src/mesa/swrast/s_aalinetemp.h @@ -132,7 +132,9 @@ NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1) line.dx = line.x1 - line.x0; line.dy = line.y1 - line.y0; line.len = SQRTF(line.dx * line.dx + line.dy * line.dy); - line.halfWidth = 0.5F * ctx->Line._Width; + line.halfWidth = 0.5F * CLAMP(ctx->Line.Width, + ctx->Const.MinLineWidthAA, + ctx->Const.MaxLineWidthAA); if (line.len == 0.0 || IS_INF_OR_NAN(line.len)) return; diff --git a/src/mesa/swrast/s_atifragshader.c b/src/mesa/swrast/s_atifragshader.c index 947054faa3..55ec757ee0 100644 --- a/src/mesa/swrast/s_atifragshader.c +++ b/src/mesa/swrast/s_atifragshader.c @@ -23,11 +23,10 @@ #include "glheader.h" #include "colormac.h" #include "context.h" -#include "atifragshader.h" #include "macros.h" -#include "program.h" - -#include "s_atifragshader.h" +#include "shader/program.h" +#include "shader/atifragshader.h" +#include "swrast/s_atifragshader.h" /** diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 791850cb50..3956925651 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -31,9 +31,9 @@ #include "context.h" #include "colormac.h" #include "mtypes.h" -#include "prog_statevars.h" #include "teximage.h" #include "swrast.h" +#include "shader/prog_statevars.h" #include "s_blend.h" #include "s_context.h" #include "s_lines.h" diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index f118eb92ca..daa07e1578 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -43,10 +43,10 @@ #ifndef S_CONTEXT_H #define S_CONTEXT_H -#include "mtypes.h" +#include "main/mtypes.h" +#include "shader/prog_execute.h" #include "swrast.h" #include "s_span.h" -#include "prog_execute.h" typedef void (*texture_sample_func)(GLcontext *ctx, diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index 1c9f64b275..0cf425e1c6 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -484,7 +484,7 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, } else { /* General case */ - const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF; + const GLuint depthMax = ctx->DrawBuffer->_DepthMax; GLint skipPixels = 0; /* in case width > MAX_WIDTH do the copy in chunks */ @@ -695,7 +695,7 @@ draw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y, const GLint imgX = x, imgY = y; const GLboolean scaleOrBias = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0; - const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF; + const GLuint depthMax = ctx->DrawBuffer->_DepthMax; const GLuint stencilMask = ctx->Stencil.WriteMask[0]; const GLuint stencilType = (STENCIL_BITS == 8) ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT; @@ -783,7 +783,7 @@ draw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* general case */ GLuint zValues[MAX_WIDTH]; /* 16 or 32-bit Z value storage */ _mesa_unpack_depth_span(ctx, width, - depthRb->DataType, zValues, depthScale, + depthRb->DataType, zValues, depthMax, type, depthStencilSrc, &clippedUnpack); if (zoom) { _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x, diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 923b67e78e..14c9868c18 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -22,11 +22,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "glheader.h" -#include "colormac.h" -#include "context.h" -#include "prog_instruction.h" -#include "texstate.h" +#include "main/glheader.h" +#include "main/colormac.h" +#include "main/context.h" +#include "main/texstate.h" +#include "shader/prog_instruction.h" #include "s_fragprog.h" #include "s_span.h" diff --git a/src/mesa/swrast/s_lines.c b/src/mesa/swrast/s_lines.c index 781146e67f..3de438760b 100644 --- a/src/mesa/swrast/s_lines.c +++ b/src/mesa/swrast/s_lines.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 + * Version: 7.1 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * @@ -63,12 +63,13 @@ compute_stipple_mask( GLcontext *ctx, GLuint len, GLubyte mask[] ) static void draw_wide_line( GLcontext *ctx, SWspan *span, GLboolean xMajor ) { - GLint width, start; + const GLint width = (GLint) CLAMP(ctx->Line.Width, + ctx->Const.MinLineWidth, + ctx->Const.MaxLineWidth); + GLint start; ASSERT(span->end < MAX_WIDTH); - width = (GLint) CLAMP( ctx->Line._Width, MIN_LINE_WIDTH, MAX_LINE_WIDTH ); - if (width & 1) start = width / 2; else @@ -143,7 +144,7 @@ draw_wide_line( GLcontext *ctx, SWspan *span, GLboolean xMajor ) span.arrayMask |= SPAN_MASK; \ compute_stipple_mask(ctx, span.end, span.array->mask); \ } \ - if (ctx->Line._Width > 1.0) { \ + if (ctx->Line.Width > 1.0) { \ draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \ } \ else { \ @@ -161,7 +162,7 @@ draw_wide_line( GLcontext *ctx, SWspan *span, GLboolean xMajor ) span.arrayMask |= SPAN_MASK; \ compute_stipple_mask(ctx, span.end, span.array->mask); \ } \ - if (ctx->Line._Width > 1.0) { \ + if (ctx->Line.Width > 1.0) { \ draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \ } \ else { \ @@ -180,7 +181,7 @@ draw_wide_line( GLcontext *ctx, SWspan *span, GLboolean xMajor ) span.arrayMask |= SPAN_MASK; \ compute_stipple_mask(ctx, span.end, span.array->mask); \ } \ - if (ctx->Line._Width > 1.0) { \ + if (ctx->Line.Width > 1.0) { \ draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \ } \ else { \ @@ -274,16 +275,21 @@ _swrast_choose_line( GLcontext *ctx ) USE(general_line); } else if (ctx->Depth.Test - || ctx->Line._Width != 1.0 + || ctx->Line.Width != 1.0 || ctx->Line.StippleFlag) { /* no texture, but Z, fog, width>1, stipple, etc. */ if (rgbmode) +#if CHAN_BITS == 32 + USE(general_line); +#else USE(rgba_line); +#endif else USE(ci_line); } else { ASSERT(!ctx->Depth.Test); + ASSERT(ctx->Line.Width == 1.0); /* simple lines */ if (rgbmode) USE(simple_no_z_rgba_line); diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c index 8eba53c807..21316372e8 100644 --- a/src/mesa/swrast/s_points.c +++ b/src/mesa/swrast/s_points.c @@ -76,7 +76,7 @@ sprite_point(GLcontext *ctx, const SWvertex *vert) } else { /* use constant point size */ - size = ctx->Point._Size; /* already clamped to user range */ + size = ctx->Point.Size; } /* clamp to non-AA implementation limits */ size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize); @@ -172,9 +172,9 @@ sprite_point(GLcontext *ctx, const SWvertex *vert) } else { /* even size */ - xmin = (GLint) x - iRadius + 1; + xmin = (GLint) x - iRadius; xmax = xmin + iSize - 1; - ymin = (GLint) y - iRadius + 1; + ymin = (GLint) y - iRadius; ymax = ymin + iSize - 1; } @@ -227,7 +227,7 @@ smooth_point(GLcontext *ctx, const SWvertex *vert) } else { /* use constant point size */ - size = ctx->Point._Size; /* this is already clamped */ + size = ctx->Point.Size; } /* clamp to AA implementation limits */ size = CLAMP(size, ctx->Const.MinPointSizeAA, ctx->Const.MaxPointSizeAA); @@ -361,7 +361,7 @@ large_point(GLcontext *ctx, const SWvertex *vert) } else { /* use constant point size */ - size = ctx->Point._Size; /* already clamped to user range */ + size = ctx->Point.Size; } /* clamp to non-AA implementation limits */ size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize); @@ -418,9 +418,9 @@ large_point(GLcontext *ctx, const SWvertex *vert) } else { /* even size */ - xmin = (GLint) x - iRadius + 1; + xmin = (GLint) x - iRadius; xmax = xmin + iSize - 1; - ymin = (GLint) y - iRadius + 1; + ymin = (GLint) y - iRadius; ymax = ymin + iSize - 1; } @@ -550,7 +550,7 @@ _swrast_choose_point(GLcontext *ctx) else if (ctx->Point.SmoothFlag) { swrast->Point = smooth_point; } - else if (ctx->Point._Size > 1.0 || + else if (ctx->Point.Size > 1.0 || ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) { swrast->Point = large_point; diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index f23272c2be..bbde0025f4 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -873,7 +873,7 @@ _swrast_write_index_span( GLcontext *ctx, SWspan *span) #endif /* we have to wait until after occlusion to do this test */ - if (ctx->Color.DrawBuffer == GL_NONE || ctx->Color.IndexMask == 0) { + if (ctx->Color.IndexMask == 0) { /* write no pixels */ span->arrayMask = origArrayMask; return; @@ -1358,7 +1358,7 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span) #if CHAN_BITS == 32 if ((span->arrayAttribs & FRAG_BIT_COL0) == 0) { - interpolate_int_colors(ctx, span); + interpolate_active_attribs(ctx, span, FRAG_BIT_COL0); } #else if ((span->arrayMask & SPAN_RGBA) == 0) { diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c index 89991fad02..d0cbdd6917 100644 --- a/src/mesa/swrast/s_stencil.c +++ b/src/mesa/swrast/s_stencil.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.1 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -392,6 +392,23 @@ do_stencil_test( GLcontext *ctx, GLuint face, GLuint n, GLstencil stencil[], } +/** + * Compute the zpass/zfail masks by comparing the pre- and post-depth test + * masks. + */ +static INLINE void +compute_pass_fail_masks(GLuint n, const GLubyte origMask[], + const GLubyte newMask[], + GLubyte passMask[], GLubyte failMask[]) +{ + GLuint i; + for (i = 0; i < n; i++) { + ASSERT(newMask[i] == 0 || newMask[i] == 1); + passMask[i] = origMask[i] & newMask[i]; + failMask[i] = origMask[i] & (newMask[i] ^ 1); + } +} + /** * Apply stencil and depth testing to the span of pixels. @@ -460,39 +477,24 @@ stencil_and_ztest_span(GLcontext *ctx, SWspan *span, GLuint face) /* * Perform depth buffering, then apply zpass or zfail stencil function. */ - GLubyte passmask[MAX_WIDTH], failmask[MAX_WIDTH], oldmask[MAX_WIDTH]; - GLuint i; + GLubyte passMask[MAX_WIDTH], failMask[MAX_WIDTH], origMask[MAX_WIDTH]; /* save the current mask bits */ - _mesa_memcpy(oldmask, mask, n * sizeof(GLubyte)); + _mesa_memcpy(origMask, mask, n * sizeof(GLubyte)); /* apply the depth test */ _swrast_depth_test_span(ctx, span); - /* Set the stencil pass/fail flags according to result of depth testing. - * if oldmask[i] == 0 then - * Don't touch the stencil value - * else if oldmask[i] and newmask[i] then - * Depth test passed - * else - * assert(oldmask[i] && !newmask[i]) - * Depth test failed - * endif - */ - for (i=0;i<n;i++) { - ASSERT(mask[i] == 0 || mask[i] == 1); - passmask[i] = oldmask[i] & mask[i]; - failmask[i] = oldmask[i] & (mask[i] ^ 1); - } + compute_pass_fail_masks(n, origMask, mask, passMask, failMask); /* apply the pass and fail operations */ if (ctx->Stencil.ZFailFunc[face] != GL_KEEP) { apply_stencil_op( ctx, ctx->Stencil.ZFailFunc[face], face, - n, stencil, failmask ); + n, stencil, failMask ); } if (ctx->Stencil.ZPassFunc[face] != GL_KEEP) { apply_stencil_op( ctx, ctx->Stencil.ZPassFunc[face], face, - n, stencil, passmask ); + n, stencil, passMask ); } } @@ -902,6 +904,7 @@ stencil_test_pixels( GLcontext *ctx, GLuint face, GLuint n, static GLboolean stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face ) { + GLubyte passMask[MAX_WIDTH], failMask[MAX_WIDTH], origMask[MAX_WIDTH]; struct gl_framebuffer *fb = ctx->DrawBuffer; struct gl_renderbuffer *rb = fb->_StencilBuffer; const GLuint n = span->end; @@ -916,13 +919,10 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face ) if (!rb->GetPointer(ctx, rb, 0, 0)) { /* No direct access */ GLstencil stencil[MAX_WIDTH]; - GLubyte origMask[MAX_WIDTH]; ASSERT(rb->DataType == GL_UNSIGNED_BYTE); _swrast_get_values(ctx, rb, n, x, y, stencil, sizeof(GLubyte)); - _mesa_memcpy(origMask, mask, n * sizeof(GLubyte)); - (void) do_stencil_test(ctx, face, n, stencil, mask); if (ctx->Depth.Test == GL_FALSE) { @@ -930,27 +930,19 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face ) n, stencil, mask); } else { + _mesa_memcpy(origMask, mask, n * sizeof(GLubyte)); + _swrast_depth_test_span(ctx, span); + compute_pass_fail_masks(n, origMask, mask, passMask, failMask); + if (ctx->Stencil.ZFailFunc[face] != GL_KEEP) { - GLubyte failmask[MAX_WIDTH]; - GLuint i; - for (i = 0; i < n; i++) { - ASSERT(mask[i] == 0 || mask[i] == 1); - failmask[i] = origMask[i] & (mask[i] ^ 1); - } apply_stencil_op(ctx, ctx->Stencil.ZFailFunc[face], face, - n, stencil, failmask); + n, stencil, failMask); } if (ctx->Stencil.ZPassFunc[face] != GL_KEEP) { - GLubyte passmask[MAX_WIDTH]; - GLuint i; - for (i = 0; i < n; i++) { - ASSERT(mask[i] == 0 || mask[i] == 1); - passmask[i] = origMask[i] & mask[i]; - } apply_stencil_op(ctx, ctx->Stencil.ZPassFunc[face], face, - n, stencil, passmask); + n, stencil, passMask); } } @@ -972,28 +964,21 @@ stencil_and_ztest_pixels( GLcontext *ctx, SWspan *span, GLuint face ) ctx->Stencil.ZPassFunc[face], face, mask); } else { - GLubyte passmask[MAX_WIDTH], failmask[MAX_WIDTH], oldmask[MAX_WIDTH]; - GLuint i; - - _mesa_memcpy(oldmask, mask, n * sizeof(GLubyte)); + _mesa_memcpy(origMask, mask, n * sizeof(GLubyte)); _swrast_depth_test_span(ctx, span); - for (i=0;i<n;i++) { - ASSERT(mask[i] == 0 || mask[i] == 1); - passmask[i] = oldmask[i] & mask[i]; - failmask[i] = oldmask[i] & (mask[i] ^ 1); - } + compute_pass_fail_masks(n, origMask, mask, passMask, failMask); if (ctx->Stencil.ZFailFunc[face] != GL_KEEP) { apply_stencil_op_to_pixels(ctx, n, x, y, ctx->Stencil.ZFailFunc[face], - face, failmask); + face, failMask); } if (ctx->Stencil.ZPassFunc[face] != GL_KEEP) { apply_stencil_op_to_pixels(ctx, n, x, y, ctx->Stencil.ZPassFunc[face], - face, passmask); + face, passMask); } } diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index d101a9e2ae..85a27fd55b 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -32,7 +32,7 @@ #ifndef SWRAST_H #define SWRAST_H -#include "mtypes.h" +#include "main/mtypes.h" /** * \struct SWvertex diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c index f8a1cadfa5..a9c7d941e5 100644 --- a/src/mesa/swrast_setup/ss_context.c +++ b/src/mesa/swrast_setup/ss_context.c @@ -280,26 +280,29 @@ _swsetup_Translate( GLcontext *ctx, const void *vertex, SWvertex *dest ) /** XXX try to limit these loops someday */ for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) - _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_TEX0+i, + _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_TEX0 + i, dest->attrib[FRAG_ATTRIB_TEX0 + i] ); for (i = 0 ; i < ctx->Const.MaxVarying ; i++) - _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_GENERIC0+i, + _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_GENERIC0 + i, dest->attrib[FRAG_ATTRIB_VAR0 + i] ); - _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR0, tmp ); - /* XXX need float color FRAG_ATTRIB_COL0?? */ - UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->color, tmp ); + if (ctx->Visual.rgbMode) { + _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR0, + dest->attrib[FRAG_ATTRIB_COL0] ); + UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->color, tmp ); - _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR1, tmp ); - COPY_4V(dest->attrib[FRAG_ATTRIB_COL1], tmp); + _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR1, + dest->attrib[FRAG_ATTRIB_COL1]); + } + else { + _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR_INDEX, tmp ); + dest->attrib[FRAG_ATTRIB_CI][0] = tmp[0]; + } _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_FOG, tmp ); dest->attrib[FRAG_ATTRIB_FOGC][0] = tmp[0]; - _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR_INDEX, tmp ); - dest->attrib[FRAG_ATTRIB_CI][0] = tmp[0]; - /* XXX See _tnl_get_attr about pointsize ... */ _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp ); dest->pointSize = tmp[0]; diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h index c14468e951..f6b738d60d 100644 --- a/src/mesa/swrast_setup/ss_tritmp.h +++ b/src/mesa/swrast_setup/ss_tritmp.h @@ -37,7 +37,7 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; SWvertex *v[3]; GLfloat z[3]; - GLfloat offset; + GLfloat offset, oz0, oz1, oz2; GLenum mode = GL_FILL; GLuint facing = 0; GLchan saved_color[3][4]; @@ -142,12 +142,16 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) } } - if (IND & SS_OFFSET_BIT) - { - offset = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD; + if (IND & SS_OFFSET_BIT) { + const GLfloat max = ctx->DrawBuffer->_DepthMaxF; + /* save original Z values (restored later) */ z[0] = v[0]->attrib[FRAG_ATTRIB_WPOS][2]; z[1] = v[1]->attrib[FRAG_ATTRIB_WPOS][2]; z[2] = v[2]->attrib[FRAG_ATTRIB_WPOS][2]; + /* Note that Z values are already scaled to [0,65535] (for example) + * so no MRD value is used here. + */ + offset = ctx->Polygon.OffsetUnits; if (cc * cc > 1e-16) { const GLfloat ez = z[0] - z[2]; const GLfloat fz = z[1] - z[2]; @@ -155,35 +159,33 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) const GLfloat dzdx = FABSF((ey * fz - ez * fy) * oneOverArea); const GLfloat dzdy = FABSF((ez * fx - ex * fz) * oneOverArea); offset += MAX2(dzdx, dzdy) * ctx->Polygon.OffsetFactor; - /* Unfortunately, we need to clamp to prevent negative Zs below. - * Technically, we should do the clamping per-fragment. - */ - offset = MAX2(offset, -v[0]->attrib[FRAG_ATTRIB_WPOS][2]); - offset = MAX2(offset, -v[1]->attrib[FRAG_ATTRIB_WPOS][2]); - offset = MAX2(offset, -v[2]->attrib[FRAG_ATTRIB_WPOS][2]); } + /* new Z values */ + oz0 = CLAMP(v[0]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0, max); + oz1 = CLAMP(v[1]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0, max); + oz2 = CLAMP(v[2]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0, max); } } if (mode == GL_POINT) { if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) { - v[0]->attrib[FRAG_ATTRIB_WPOS][2] += offset; - v[1]->attrib[FRAG_ATTRIB_WPOS][2] += offset; - v[2]->attrib[FRAG_ATTRIB_WPOS][2] += offset; + v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0; + v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1; + v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2; } _swsetup_render_point_tri( ctx, e0, e1, e2, facing ); } else if (mode == GL_LINE) { if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) { - v[0]->attrib[FRAG_ATTRIB_WPOS][2] += offset; - v[1]->attrib[FRAG_ATTRIB_WPOS][2] += offset; - v[2]->attrib[FRAG_ATTRIB_WPOS][2] += offset; + v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0; + v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1; + v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2; } _swsetup_render_line_tri( ctx, e0, e1, e2, facing ); } else { if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) { - v[0]->attrib[FRAG_ATTRIB_WPOS][2] += offset; - v[1]->attrib[FRAG_ATTRIB_WPOS][2] += offset; - v[2]->attrib[FRAG_ATTRIB_WPOS][2] += offset; + v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0; + v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1; + v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2; } _swrast_Triangle( ctx, v[0], v[1], v[2] ); } diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c index 3017c73cf1..3b8dd18bbb 100644 --- a/src/mesa/tnl/t_context.c +++ b/src/mesa/tnl/t_context.c @@ -26,12 +26,12 @@ */ -#include "glheader.h" -#include "imports.h" -#include "context.h" -#include "macros.h" -#include "mtypes.h" -#include "light.h" +#include "main/glheader.h" +#include "main/imports.h" +#include "main/context.h" +#include "main/macros.h" +#include "main/mtypes.h" +#include "main/light.h" #include "tnl.h" #include "t_context.h" diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h index 31b89aca41..baf283ef0f 100644 --- a/src/mesa/tnl/t_context.h +++ b/src/mesa/tnl/t_context.h @@ -49,8 +49,8 @@ #ifndef _T_CONTEXT_H #define _T_CONTEXT_H -#include "glheader.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/mtypes.h" #include "math/m_matrix.h" #include "math/m_vector.h" diff --git a/src/mesa/tnl/t_pipeline.c b/src/mesa/tnl/t_pipeline.c index c7188da34a..2a0ed8852a 100644 --- a/src/mesa/tnl/t_pipeline.c +++ b/src/mesa/tnl/t_pipeline.c @@ -25,11 +25,11 @@ * Keith Whitwell <keith@tungstengraphics.com> */ -#include "glheader.h" -#include "context.h" -#include "imports.h" -#include "state.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/imports.h" +#include "main/state.h" +#include "main/mtypes.h" #include "t_context.h" #include "t_pipeline.h" diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index 9961af70ce..f8e561ac57 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -35,16 +35,16 @@ #include "context.h" #include "macros.h" #include "imports.h" -#include "prog_instruction.h" -#include "prog_statevars.h" -#include "prog_execute.h" +#include "shader/prog_instruction.h" +#include "shader/prog_statevars.h" +#include "shader/prog_execute.h" +#include "swrast/s_context.h" +#include "swrast/s_texfilter.h" #include "tnl.h" #include "t_context.h" #include "t_pipeline.h" -#include "swrast/s_context.h" -#include "swrast/s_texfilter.h" /** * XXX the texture sampling code in this module is a bit of a hack. diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c index 6aae602037..a6728c318f 100644 --- a/src/mesa/tnl/t_vertex.c +++ b/src/mesa/tnl/t_vertex.c @@ -233,7 +233,7 @@ void _tnl_get_attr( GLcontext *ctx, const void *vin, /* If the hardware vertex doesn't have point size then use size from * GLcontext. XXX this will be wrong if drawing attenuated points! */ - dest[0] = ctx->Point._Size; + dest[0] = ctx->Point.Size; } else { _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat)); diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c index 2a1cae77f2..ee1a2498b3 100644 --- a/src/mesa/tnl/t_vp_build.c +++ b/src/mesa/tnl/t_vp_build.c @@ -33,11 +33,11 @@ #include "glheader.h" #include "macros.h" #include "enums.h" -#include "program.h" -#include "prog_instruction.h" -#include "prog_parameter.h" -#include "prog_print.h" -#include "prog_statevars.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/prog_print.h" +#include "shader/prog_statevars.h" #include "t_context.h" /* NOTE: very light dependency on this */ #include "t_vp_build.h" diff --git a/src/mesa/tnl/tnl.h b/src/mesa/tnl/tnl.h index 20bed5546d..047b764dcb 100644 --- a/src/mesa/tnl/tnl.h +++ b/src/mesa/tnl/tnl.h @@ -29,7 +29,7 @@ #ifndef _TNL_H #define _TNL_H -#include "mtypes.h" +#include "main/mtypes.h" diff --git a/src/mesa/tnl_dd/t_dd_vb.c b/src/mesa/tnl_dd/t_dd_vb.c index ab3bb37631..3cedd90119 100644 --- a/src/mesa/tnl_dd/t_dd_vb.c +++ b/src/mesa/tnl_dd/t_dd_vb.c @@ -184,7 +184,7 @@ void TAG(translate_vertex)(GLcontext *ctx, } } - dst->pointSize = ctx->Point._Size; + dst->pointSize = ctx->Point.Size; } diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h index 874a5f9e0e..04c59c05b2 100644 --- a/src/mesa/vbo/vbo.h +++ b/src/mesa/vbo/vbo.h @@ -32,7 +32,7 @@ #ifndef _VBO_H #define _VBO_H -#include "mtypes.h" +#include "main/mtypes.h" struct _mesa_prim { GLuint mode:8; diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c index f64f59d11e..656b27f28c 100644 --- a/src/mesa/vbo/vbo_context.c +++ b/src/mesa/vbo/vbo_context.c @@ -25,11 +25,11 @@ * Keith Whitwell <keith@tungstengraphics.com> */ -#include "mtypes.h" +#include "main/imports.h" +#include "main/mtypes.h" +#include "main/api_arrayelt.h" #include "vbo.h" #include "vbo_context.h" -#include "imports.h" -#include "api_arrayelt.h" /* Reach out and grab this to use as the default: */ @@ -112,6 +112,8 @@ static void init_mat_currval(GLcontext *ctx) struct gl_client_array *arrays = vbo->mat_currval; GLuint i; + ASSERT(NR_MAT_ATTRIBS == MAT_ATTRIB_MAX); + memset(arrays, 0, sizeof(*arrays) * NR_MAT_ATTRIBS); /* Set up a constant (StrideB == 0) array for each current @@ -137,11 +139,7 @@ static void init_mat_currval(GLcontext *ctx) break; } - if (i < MAT_ATTRIB_MAX) - cl->Ptr = (const void *)ctx->Light.Material.Attrib[i]; - else - cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i]; - + cl->Ptr = (const void *)ctx->Light.Material.Attrib[i]; cl->Type = GL_FLOAT; cl->Stride = 0; cl->StrideB = 0; diff --git a/src/mesa/vbo/vbo_exec.c b/src/mesa/vbo/vbo_exec.c index 7d95873247..1efa74945d 100644 --- a/src/mesa/vbo/vbo_exec.c +++ b/src/mesa/vbo/vbo_exec.c @@ -26,14 +26,14 @@ */ -#include "api_arrayelt.h" -#include "glheader.h" -#include "imports.h" -#include "context.h" -#include "macros.h" -#include "mtypes.h" -#include "dlist.h" -#include "vtxfmt.h" +#include "main/api_arrayelt.h" +#include "main/glheader.h" +#include "main/imports.h" +#include "main/context.h" +#include "main/macros.h" +#include "main/mtypes.h" +#include "main/dlist.h" +#include "main/vtxfmt.h" #include "vbo_context.h" diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h index a9b01e08e6..b7e8c9fe79 100644 --- a/src/mesa/vbo/vbo_exec.h +++ b/src/mesa/vbo/vbo_exec.h @@ -34,7 +34,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef __VBO_EXEC_H__ #define __VBO_EXEC_H__ -#include "mtypes.h" +#include "main/mtypes.h" #include "vbo.h" #include "vbo_attrib.h" diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index 2d4ded0f98..7f56b3b629 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -30,16 +30,16 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. * Keith Whitwell <keith@tungstengraphics.com> */ -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "vtxfmt.h" -#include "dlist.h" -#include "state.h" -#include "light.h" -#include "api_arrayelt.h" -#include "api_noop.h" -#include "dispatch.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/macros.h" +#include "main/vtxfmt.h" +#include "main/dlist.h" +#include "main/state.h" +#include "main/light.h" +#include "main/api_arrayelt.h" +#include "main/api_noop.h" +#include "glapi/dispatch.h" #include "vbo_context.h" diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c index 1e4c310203..77f3cf1455 100644 --- a/src/mesa/vbo/vbo_exec_array.c +++ b/src/mesa/vbo/vbo_exec_array.c @@ -25,12 +25,12 @@ * **************************************************************************/ -#include "glheader.h" -#include "context.h" -#include "state.h" -#include "api_validate.h" -#include "api_noop.h" -#include "dispatch.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/state.h" +#include "main/api_validate.h" +#include "main/api_noop.h" +#include "glapi/dispatch.h" #include "vbo_context.h" diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c index d8f167b357..0ef26cdfe3 100644 --- a/src/mesa/vbo/vbo_exec_draw.c +++ b/src/mesa/vbo/vbo_exec_draw.c @@ -25,11 +25,11 @@ * Keith Whitwell <keith@tungstengraphics.com> */ -#include "glheader.h" -#include "context.h" -#include "enums.h" -#include "state.h" -#include "macros.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/enums.h" +#include "main/state.h" +#include "main/macros.h" #include "vbo_context.h" diff --git a/src/mesa/vbo/vbo_exec_eval.c b/src/mesa/vbo/vbo_exec_eval.c index fe533290bd..0ba5585d24 100644 --- a/src/mesa/vbo/vbo_exec_eval.c +++ b/src/mesa/vbo/vbo_exec_eval.c @@ -25,13 +25,13 @@ * Keith Whitwell <keith@tungstengraphics.com> */ -#include "glheader.h" -#include "api_eval.h" -#include "context.h" -#include "macros.h" +#include "main/glheader.h" +#include "main/api_eval.h" +#include "main/context.h" +#include "main/macros.h" #include "math/m_eval.h" +#include "glapi/dispatch.h" #include "vbo_exec.h" -#include "dispatch.h" static void clear_active_eval1( struct vbo_exec_context *exec, GLuint attr ) diff --git a/src/mesa/vbo/vbo_rebase.c b/src/mesa/vbo/vbo_rebase.c index bc4211d852..dae778e741 100644 --- a/src/mesa/vbo/vbo_rebase.c +++ b/src/mesa/vbo/vbo_rebase.c @@ -46,9 +46,9 @@ * of zero. */ -#include "glheader.h" -#include "imports.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/imports.h" +#include "main/mtypes.h" #include "vbo.h" diff --git a/src/mesa/vbo/vbo_save.c b/src/mesa/vbo/vbo_save.c index e7f4687963..87248e10f3 100644 --- a/src/mesa/vbo/vbo_save.c +++ b/src/mesa/vbo/vbo_save.c @@ -26,10 +26,10 @@ */ -#include "mtypes.h" -#include "dlist.h" -#include "vtxfmt.h" -#include "imports.h" +#include "main/mtypes.h" +#include "main/dlist.h" +#include "main/vtxfmt.h" +#include "main/imports.h" #include "vbo_context.h" diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h index b81f275a60..b7e9baabf8 100644 --- a/src/mesa/vbo/vbo_save.h +++ b/src/mesa/vbo/vbo_save.h @@ -34,7 +34,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef VBO_SAVE_H #define VBO_SAVE_H -#include "mtypes.h" +#include "main/mtypes.h" #include "vbo.h" #include "vbo_attrib.h" diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index e7794c2a6c..f62be5c14c 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -67,15 +67,15 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "glheader.h" -#include "context.h" -#include "dlist.h" -#include "enums.h" -#include "macros.h" -#include "api_validate.h" -#include "api_arrayelt.h" -#include "vtxfmt.h" -#include "dispatch.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/dlist.h" +#include "main/enums.h" +#include "main/macros.h" +#include "main/api_validate.h" +#include "main/api_arrayelt.h" +#include "main/vtxfmt.h" +#include "glapi/dispatch.h" #include "vbo_context.h" @@ -864,6 +864,9 @@ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum _ae_map_vbos( ctx ); + if (ctx->Array.ElementArrayBufferObj->Name) + indices = ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Pointer, indices); + vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK ); switch (type) { diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c index 8940551d08..3c6f0fccd9 100644 --- a/src/mesa/vbo/vbo_save_draw.c +++ b/src/mesa/vbo/vbo_save_draw.c @@ -26,13 +26,13 @@ * Keith Whitwell <keith@tungstengraphics.com> */ -#include "glheader.h" -#include "context.h" -#include "imports.h" -#include "mtypes.h" -#include "macros.h" -#include "light.h" -#include "state.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/imports.h" +#include "main/mtypes.h" +#include "main/macros.h" +#include "main/light.h" +#include "main/state.h" #include "vbo_context.h" diff --git a/src/mesa/vbo/vbo_save_loopback.c b/src/mesa/vbo/vbo_save_loopback.c index 430333b84d..f2cef698fb 100644 --- a/src/mesa/vbo/vbo_save_loopback.c +++ b/src/mesa/vbo/vbo_save_loopback.c @@ -28,17 +28,17 @@ #include "swrast_setup/swrast_setup.h" #include "swrast/swrast.h" #include "tnl/tnl.h" -#include "context.h" +#include "main/context.h" +#include "main/glheader.h" +#include "main/enums.h" +#include "main/imports.h" +#include "main/macros.h" +#include "main/mtypes.h" +#include "glapi/dispatch.h" +#include "glapi/glapi.h" #include "vbo_context.h" -#include "glheader.h" -#include "enums.h" -#include "glapi.h" -#include "imports.h" -#include "macros.h" -#include "mtypes.h" -#include "dispatch.h" typedef void (*attr_func)( GLcontext *ctx, GLint target, const GLfloat * ); diff --git a/src/mesa/vbo/vbo_split.c b/src/mesa/vbo/vbo_split.c index ef205a3bb1..58e879628d 100644 --- a/src/mesa/vbo/vbo_split.c +++ b/src/mesa/vbo/vbo_split.c @@ -47,9 +47,9 @@ * limitations on drivers which want to use it as a fallback path. */ -#include "glheader.h" -#include "imports.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/imports.h" +#include "main/mtypes.h" #include "vbo_split.h" #include "vbo.h" diff --git a/src/mesa/vbo/vbo_split_copy.c b/src/mesa/vbo/vbo_split_copy.c index e142dde680..685cc0fdf6 100644 --- a/src/mesa/vbo/vbo_split_copy.c +++ b/src/mesa/vbo/vbo_split_copy.c @@ -29,11 +29,11 @@ /* Split indexed primitives with per-vertex copying. */ -#include "glheader.h" -#include "imports.h" -#include "macros.h" -#include "enums.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/imports.h" +#include "main/macros.h" +#include "main/enums.h" +#include "main/mtypes.h" #include "vbo_split.h" #include "vbo.h" @@ -129,6 +129,13 @@ static GLuint attr_size( const struct gl_client_array *array ) */ static GLboolean check_flush( struct copy_context *copy ) { + GLenum mode = copy->dstprim[copy->dstprim_nr].mode; + + if (GL_TRIANGLE_STRIP == mode && + copy->dstelt_nr & 1) { /* see bug9962 */ + return GL_FALSE; + } + if (copy->dstbuf_nr + 4 > copy->dstbuf_size) return GL_TRUE; @@ -458,7 +465,7 @@ static void replay_init( struct copy_context *copy ) dst->StrideB = copy->vertex_size; dst->Ptr = copy->dstbuf + offset; dst->Enabled = GL_TRUE; - dst->Normalized = GL_TRUE; + dst->Normalized = src->Normalized; dst->BufferObj = ctx->Array.NullBufferObj; dst->_MaxElement = copy->dstbuf_size; /* may be less! */ diff --git a/src/mesa/vbo/vbo_split_inplace.c b/src/mesa/vbo/vbo_split_inplace.c index ea62866e7c..958afccd0c 100644 --- a/src/mesa/vbo/vbo_split_inplace.c +++ b/src/mesa/vbo/vbo_split_inplace.c @@ -27,9 +27,9 @@ */ -#include "mtypes.h" -#include "macros.h" -#include "enums.h" +#include "main/mtypes.h" +#include "main/macros.h" +#include "main/enums.h" #include "vbo_split.h" |