diff --git a/engine/Makefile b/engine/Makefile index 7cc85f031..f60440da8 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -180,8 +180,7 @@ endif CLIENT_DIR=$(BASE_DIR)/client GL_DIR=$(BASE_DIR)/gl -D3D7_DIR=$(BASE_DIR)/d3d -D3D9_DIR=$(BASE_DIR)/d3d9 +D3D_DIR=$(BASE_DIR)/d3d SERVER_DIR=$(BASE_DIR)/server COMMON_DIR=$(BASE_DIR)/common HTTP_DIR=$(BASE_DIR)/http @@ -197,13 +196,6 @@ PROFILE_DIR=$(BASE_DIR)/profile ALL_CFLAGS=$(HAVECONFIG) $(CFLAGS) $(BASE_CFLAGS) $(WCFLAGS) DO_CC=@echo $< && $(CC) $(ALL_CFLAGS) -o $@ -c $< -ifeq ($(USEASM),true) - ifdef windir - DO_AS=$(CC) $(BASE_CFLAGS) $(WCFLAGS) -x assembler-with-cpp -o $@ -c $< $(CFLAGS) - else - DO_AS=$(CC) $(BASE_CFLAGS) $(WCFLAGS) -x assembler-with-cpp -DELF -o $@ -c $< $(CFLAGS) - endif -endif ifeq ($(FTE_TARGET),vc) BASELDFLAGS= @@ -251,34 +243,6 @@ GLSLDFLAGS=-L/usr/X11R6/lib -lMesaGL -lglide -lvga XLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext $(IMAGELDFLAGS) SLDFLAGS=-lvga -ifeq ($(USEASM),true) - COMMON_ASM_OBJS = \ - worlda.o \ - math.o - - CLIENT_ASM_OBJS = \ - snd_mixa.o - - SOFTWARE_ASM_OBJS = \ - r_aclipa.o \ - r_aliasa.o \ - r_drawa.o \ - r_edgea.o \ - r_varsa.o \ - d_draw.o \ - d_draw16.o \ - d_parta.o \ - d_polysa.o \ - d_scana.o \ - d_spr8.o \ - d_varsa.o \ - surf16.o \ - surf8.o - -else - BASE_ASM_CFLAGS = -DNOASM -endif - ifeq ($(FTE_TARGET),vc) WARNINGFLAGS=-W3 -D_CRT_SECURE_NO_WARNINGS GNUC_FUNCS= @@ -288,7 +252,7 @@ else GNUC_FUNCS= -Dstrnicmp=strncasecmp -Dstricmp=strcasecmp -D_vsnprintf=vsnprintf -D_snprintf=snprintf endif -BASE_CFLAGS=$(BASE_ASM_CFLAGS) $(WARNINGFLAGS) $(GNUC_FUNCS) -I$(CLIENT_DIR) -I$(SERVER_DIR) -I$(COMMON_DIR) -I$(GL_DIR) -I$(D3D9_DIR) -I$(D3D7_DIR) -I$(PROGS_DIR) -I$(LIBS_DIR) -I$(LIBS_DIR)/dxsdk7/include -I$(LIBS_DIR)/dxsdk9/include -I$(LIBS_DIR)/sdl/include -I/usr/include/SDL -I$(LIBS_DIR)/sdl/include/SDL -I./libs/freetype2/include -I./libs/freetype2/include/freetype -I./libs/speex $(SVNREVISION) +BASE_CFLAGS=$(WARNINGFLAGS) $(GNUC_FUNCS) -I$(CLIENT_DIR) -I$(SERVER_DIR) -I$(COMMON_DIR) -I$(GL_DIR) -I$(D3D_DIR) -I$(PROGS_DIR) -I$(LIBS_DIR) -I$(LIBS_DIR)/dxsdk9/include -I$(LIBS_DIR)/sdl/include -I/usr/include/SDL -I$(LIBS_DIR)/sdl/include/SDL -I./libs/freetype2/include -I./libs/freetype2/include/freetype -I./libs/speex $(SVNREVISION) CLIENT_ONLY_CFLAGS=-DCLIENTONLY SERVER_ONLY_CFLAGS=-DSERVERONLY JOINT_CFLAGS= @@ -334,7 +298,7 @@ GLCFLAGS=-DGLQUAKE D3DCFLAGS=-DD3DQUAKE NPQTVCFLAGS=-DNPQTV -CLIENT_OBJS = $(CLIENT_ASM_OBJS) \ +CLIENT_OBJS = \ textedit.o \ fragstats.o \ teamplay.o \ @@ -498,7 +462,7 @@ WINDOWSSERVERONLY_OBJS = \ svmodel.o \ sv_sys_win.o -COMMON_OBJS = $(COMMON_ASM_OBJS) \ +COMMON_OBJS = \ com_mesh.o \ com_phys_ode.o \ common.o \ @@ -580,7 +544,7 @@ ifeq ($(FTE_TARGET),win32_SDL) else GL_LDFLAGS=$(IMAGELDFLAGS) -lws2_32 -lmingw32 ./libs/mingw-libs/libSDL.a ./libs/mingw-libs/libSDLmain.a -mwindows -ldxguid -lwinmm -lole32 $(GLLDFLAGS) `sdl-config --libs` endif - GL_CFLAGS=-D_MINGW_VFPRINTF -D_SDL -I./libs/ -I./libs/mingw-libs/ -I./libs/dxsdk7/include/ -I./libs/mingw-libs $(GLCFLAGS) `sdl-config --cflags` + GL_CFLAGS=-D_MINGW_VFPRINTF -D_SDL -I./libs/ -I./libs/mingw-libs/ -I./libs/mingw-libs $(GLCFLAGS) `sdl-config --cflags` GLB_DIR=gl_mgw_sdl$(BITS) GLCL_DIR=glcl_mgw_sdl$(BITS) @@ -595,7 +559,7 @@ ifeq ($(FTE_TARGET),win32_SDL) MB_DIR=m_mgw_sdl$(BITS) M_EXE_NAME=../fteqw_sdl.exe MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(D3DQUAKE_OBJS) gl_vidsdl.o snd_sdl.o cd_sdl.o sys_sdl.o in_sdl.o snd_directx.o resources.o - M_CFLAGS=$(D3DCFLAGS) -D_MINGW_VFPRINTF -D_SDL -I./libs/ -I./libs/mingw-libs/ -I./libs/dxsdk7/include/ -I./libs/mingw-libs $(GLCFLAGS) `sdl-config --cflags` -D_MERGED_SDL + M_CFLAGS=$(D3DCFLAGS) -D_MINGW_VFPRINTF -D_SDL -I./libs/ -I./libs/mingw-libs/ -I./libs/mingw-libs $(GLCFLAGS) `sdl-config --cflags` -D_MERGED_SDL M_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) ifdef windir @@ -609,7 +573,7 @@ ifeq ($(FTE_TARGET),win32_SDL) D3D_EXE_NAME=../fted3dqw.exe D3DCL_EXE_NAME=../fted3dclqw.exe D3D_LDFLAGS=$(IMAGELDFLAGS) -lws2_32 -lmingw32 ./libs/mingw-libs/libSDL.a ./libs/mingw-libs/libSDLmain.a -mwindows -ldxguid -lwinmm -lole32 - D3D_CFLAGS=$(D3DCFLAGS) -D_MINGW_VFPRINTF -D_SDL -DNO_XFLIP -I./libs/ -I./libs/mingw-libs/ -I./libs/dxsdk7/include/ -I./libs/mingw-libs `sdl-config --cflags` + D3D_CFLAGS=$(D3DCFLAGS) -D_MINGW_VFPRINTF -D_SDL -DNO_XFLIP -I./libs/ -I./libs/mingw-libs/ -I./libs/mingw-libs `sdl-config --cflags` D3DB_DIR=d3d_mgw D3DCL_DIR=d3dcl_mgw @@ -626,7 +590,7 @@ ifeq ($(FTE_TARGET),win64_SDL) else GL_LDFLAGS=$(IMAGELDFLAGS) -lws2_32 -lmingw32 ./libs/mingw64-libs/libSDL.a ./libs/mingw64-libs/libSDLmain.a -mwindows -ldxguid -lwinmm -lole32 $(GLLDFLAGS) `sdl-config --libs` endif - GL_CFLAGS=-D_SDL -I./libs/ -I./libs/mingw64-libs/ -I./libs/dxsdk7/include/ -I./libs/mingw64-libs $(GLCFLAGS) `sdl-config --cflags` + GL_CFLAGS=-D_SDL -I./libs/ -I./libs/mingw64-libs/ -I./libs/mingw64-libs $(GLCFLAGS) `sdl-config --cflags` GLB_DIR=gl_mgw_sdl$(BITS) GLCL_DIR=glcl_mgw_sdl$(BITS) @@ -641,7 +605,7 @@ ifeq ($(FTE_TARGET),win64_SDL) MB_DIR=m_mgw_sdl$(BITS) M_EXE_NAME=../fteqw_sdl64.exe MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(D3DQUAKE_OBJS) gl_vidsdl.o snd_sdl.o cd_sdl.o sys_sdl.o in_sdl.o snd_directx.o resources.o - M_CFLAGS= $(D3DCFLAGS) -D_MINGW_VFPRINTF -D_SDL -I./libs/ -I./libs/mingw64-libs/ -I./libs/dxsdk7/include/ -I./libs/mingw64-libs $(GLCFLAGS) `sdl-config --cflags` -D_MERGED_SDL + M_CFLAGS= $(D3DCFLAGS) -D_MINGW_VFPRINTF -D_SDL -I./libs/ -I./libs/mingw64-libs/ -I./libs/mingw64-libs $(GLCFLAGS) `sdl-config --cflags` -D_MERGED_SDL M_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) ifdef windir @@ -678,7 +642,7 @@ ifeq ($(FTE_TARGET),vc) MCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o resources.o M_CFLAGS=$(GLCFLAGS) $(W32_CFLAGS) $(D3DCFLAGS) MB_DIR=m_vc - M_LDFLAGS=$(GLLDFLAGS) libs/jpeg.lib libs/libpng.lib libs/zlib.lib uuid.lib gdi32.lib ole32.lib libs/dxsdk7/lib/dxguid.lib /subsystem:windows + M_LDFLAGS=$(GLLDFLAGS) libs/jpeg.lib libs/libpng.lib libs/zlib.lib uuid.lib gdi32.lib ole32.lib /subsystem:windows endif ifeq ($(FTE_TARGET),win32) @@ -699,11 +663,7 @@ ifeq ($(FTE_TARGET),win32) SV_OBJS=$(COMMON_OBJS) $(SERVER_OBJS) $(PROGS_OBJS) $(WINDOWSSERVERONLY_OBJS) fs_win32.o resources.o -ifeq ($(USEASM),true) - GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o sys_dosa.o resources.o -else GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o resources.o -endif GL_EXE_NAME=../fteglqw.exe GLCL_EXE_NAME=../fteglqwcl.exe GL_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) -ldxguid -lws2_32 -lwinmm -lgdi32 -lole32 @@ -711,11 +671,7 @@ endif GLB_DIR=gl_mgw GLCL_DIR=glcl_mgw -ifeq ($(USEASM),true) - NPQTVCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o sys_dosa.o npplug.o sys_npqtv.o sys_plugfte.o ../../ftequake/npapi.def -else NPQTVCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o npplug.o sys_npqtv.o sys_plugfte.o ../../ftequake/npapi.def -endif NPQTV_DLL_NAME=../npqtv.dll NPQTVCL_DLL_NAME=../npqtvcl.dll NPQTV_LDFLAGS=--enable-stdcall-fixup $(GLLDFLAGS) $(IMAGELDFLAGS) -ldxguid -lws2_32 -lwinmm -lgdi32 -lole32 -shared @@ -723,11 +679,7 @@ endif NPQTVB_DIR=npqtv_mgw NPQTVCL_DIR=npqtvcl_mgw -ifeq ($(USEASM),true) - MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(D3DQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o sys_dosa.o resources.o -else MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(D3DQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o resources.o -endif M_EXE_NAME=../fteqw.exe MCL_EXE_NAME=../fteqwcl.exe M_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) -ldxguid -lws2_32 -lwinmm -lgdi32 -lole32 @@ -765,11 +717,7 @@ ifeq ($(FTE_TARGET),win64) SV_OBJS=$(COMMON_OBJS) $(SERVER_OBJS) $(PROGS_OBJS) $(WINDOWSSERVERONLY_OBJS) fs_win32.o resources.o -ifeq ($(USEASM),true) - GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o sys_dosa.o resources.o -else GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o resources.o -endif GL_EXE_NAME=../fteglqw64.exe GLCL_EXE_NAME=../fteglqwcl64.exe GL_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) -ldxguid -lws2_32 -lwinmm -lgdi32 -lole32 @@ -777,11 +725,7 @@ endif GLB_DIR=gl_mgw64 GLCL_DIR=glcl_mgw64 -ifeq ($(USEASM),true) - NPQTVCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o sys_dosa.o npplug.o sys_npqtv.o sys_plugfte.o ../../ftequake/npapi.def -else NPQTVCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o npplug.o sys_npqtv.o sys_plugfte.o ../../ftequake/npapi.def -endif NPQTV_DLL_NAME=../npqtv64.dll NPQTVCL_DLL_NAME=../npqtvcl64.dll NPQTV_LDFLAGS=--enable-stdcall-fixup $(GLLDFLAGS) $(IMAGELDFLAGS) -ldxguid -lws2_32 -lwinmm -lgdi32 -lole32 -shared @@ -789,11 +733,7 @@ endif NPQTVB_DIR=npqtv_mgw64 NPQTVCL_DIR=npqtvcl_mgw64 -ifeq ($(USEASM),true) - MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(D3DQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o sys_dosa.o resources.o -else MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(D3DQUAKE_OBJS) fs_win32.o gl_vidnt.o snd_win.o snd_directx.o cd_win.o in_win.o sys_win.o resources.o -endif M_EXE_NAME=../fteqw64.exe MCL_EXE_NAME=../fteqwcl64.exe M_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) -ldxguid -lws2_32 -lwinmm -lgdi32 -lole32 @@ -820,11 +760,7 @@ ifeq ($(FTE_TARGET),bsd) SV_DIR=sv_linux SV_LDFLAGS=-lz -ldl -ifeq ($(USEASM),true) - GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o sys_dosa.o -else GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o -endif GL_EXE_NAME=../fteqw.gl GLCL_EXE_NAME=../fteqwcl.gl GL_LDFLAGS= -L/usr/local/lib $(GLLDFLAGS) $(GLXLDFLAGS) -lXxf86vm -lpthread @@ -832,11 +768,7 @@ endif GLB_DIR=gl_bsd GLCL_DIR=glcl_bsd -ifeq ($(USEASM),true) - MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o sys_dosa.o -else MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o -endif M_EXE_NAME=../fteqw MCL_EXE_NAME=../fteqwcl M_LDFLAGS=$(GLLDFLAGS) $(GLXLDFLAGS) -lXxf86vm -lpthread @@ -854,9 +786,6 @@ ifneq ($(shell echo $(FTE_TARGET)|grep linux),) SV_EXE_NAME=../fteqw.sv$(BITS) GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_vidlinuxglx.o snd_alsa.o snd_linux.o cd_linux.o sys_linux.o -ifeq ($(USEASM),true) - GLCL_OBJS+= sys_dosa.o -endif GL_EXE_NAME=../fteqw.gl$(BITS) GLCL_EXE_NAME=../fteqwcl.gl$(BITS) GL_LDFLAGS=$(GLLDFLAGS) $(GLXLDFLAGS) -lXxf86vm -lXxf86dga @@ -865,9 +794,6 @@ endif GLCL_DIR=glcl_linux$(BITS) MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) gl_vidlinuxglx.o snd_linux.o snd_alsa.o cd_linux.o sys_linux.o -ifeq ($(USEASM),true) - MCL_OBJS+= sys_dosa.o -endif M_EXE_NAME=../fteqw$(BITS) MCL_EXE_NAME=../fteqwcl$(BITS) M_LDFLAGS=$(GLLDFLAGS) $(GLXLDFLAGS) -lXxf86vm -lXxf86dga @@ -947,11 +873,7 @@ ifeq ($(FTE_TARGET),cygwin) SV_DIR=sv_cygwin SV_LDFLAGS=-lz -ifeq ($(USEASM),true) - GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o sys_dosa.o -else GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o -endif GL_EXE_NAME=../fteqwglcyg.exe GLCL_EXE_NAME=../fteqwclglcyg.exe GL_LDFLAGS=$(GLLDFLAGS) $(GLXLDFLAGS) @@ -959,11 +881,7 @@ endif GLB_DIR=gl_cygwin GLCL_DIR=glcl_cygwin -ifeq ($(USEASM),true) - MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o sys_dosa.o -else MCL_OBJS=$(GLQUAKE_OBJS) $(SOFTWARE_OBJS) gl_vidlinuxglx.o snd_linux.o cd_null.o sys_linux.o -endif M_EXE_NAME=../fteqwcyg.exe MCL_EXE_NAME=../fteqwclcyg.exe M_LDFLAGS=$(GLLDFLAGS) $(GLXLDFLAGS) @@ -1012,7 +930,7 @@ ifneq ($(OUT_DIR),) endif -VPATH = $(BASE_DIR) : $(CLIENT_DIR) : $(GL_DIR) : $(COMMON_DIR) : $(SERVER_DIR) : $(HTTP_DIR) : $(BASE_DIR)/irc : $(BASE_DIR)/email : $(QUX_DIR) : $(PROGS_DIR) : $(SNDCODEC_DIR) : $(D3D7_DIR) : $(D3D9_DIR) +VPATH = $(BASE_DIR) : $(CLIENT_DIR) : $(GL_DIR) : $(COMMON_DIR) : $(SERVER_DIR) : $(HTTP_DIR) : $(BASE_DIR)/irc : $(BASE_DIR)/email : $(QUX_DIR) : $(PROGS_DIR) : $(SNDCODEC_DIR) : $(D3D_DIR) # This is for linking the FTE icon to the MinGW target $(OUT_DIR)/resources.o : winquake.rc diff --git a/engine/client/snd_mixa.s b/engine/client/snd_mixa.s deleted file mode 100644 index 80e595799..000000000 --- a/engine/client/snd_mixa.s +++ /dev/null @@ -1,229 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// -// snd_mixa.s -// x86 assembly-language sound code -// - -#include "asm_i386.h" -#include "quakeasm.h" - -#define NOSOUNDASM //we no longer use any of this code, now that we have multiple sound cards. - -#if !defined(NOSOUNDASM) && id386 - - .text - -//---------------------------------------------------------------------- -// 8-bit sound-mixing code -//---------------------------------------------------------------------- - -#define ch 4+16 -#define sc 8+16 -#define count 12+16 - -#if 0 -// This code isn't maintained. It needs the snd_scaletable references removed. -// snd_scaletable[x][y] -> x * 8 * y - -.globl C(SND_PaintChannelFrom8) -C(SND_PaintChannelFrom8): - pushl %esi // preserve register variables - pushl %edi - pushl %ebx - pushl %ebp - -// int data; -// short *lscale, *rscale; -// unsigned char *sfx; -// int i; - - movl ch(%esp),%ebx - movl sc(%esp),%esi - -// if (ch->leftvol > 255) -// ch->leftvol = 255; -// if (ch->rightvol > 255) -// ch->rightvol = 255; - movl ch_vol(%ebx),%eax - movl ch_vol(%ebx),%edx - cmpl $255,%eax - jna LLeftSet - movl $255,%eax -LLeftSet: - cmpl $255,%edx - jna LRightSet - movl $255,%edx -LRightSet: - -// lscale = snd_scaletable[ch->leftvol >> 3]; -// rscale = snd_scaletable[ch->rightvol >> 3]; -// sfx = (signed char *)sc->data + ch->pos; -// ch->pos += count; - andl $0xF8,%eax - addl $(sfxc_data),%esi - andl $0xF8,%edx - movl ch_pos(%ebx),%edi - movl count(%esp),%ecx - addl %edi,%esi - shll $7,%eax - addl %ecx,%edi - shll $7,%edx - movl %edi,ch_pos(%ebx) - addl $(C(snd_scaletable)),%eax - addl $(C(snd_scaletable)),%edx - subl %ebx,%ebx - movb -1(%esi,%ecx,1),%bl - - testl $1,%ecx - jz LMix8Loop - - movl (%eax,%ebx,4),%edi - movl (%edx,%ebx,4),%ebp - addl C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size),%edi - addl C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size),%ebp - movl %edi,C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size) - movl %ebp,C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size) - movb -2(%esi,%ecx,1),%bl - - decl %ecx - jz LDone - -// for (i=0 ; i>8; -// if (val > 0x7fff) -// snd_out[i] = 0x7fff; -// else if (val < (short)0x8000) -// snd_out[i] = (short)0x8000; -// else -// snd_out[i] = val; - movl -8(%ebx,%ecx,4),%eax - imull %esi,%eax - sarl $8,%eax - cmpl $0x7FFF,%eax - jg LClampHigh - cmpl $0xFFFF8000,%eax - jnl LClampDone - movl $0xFFFF8000,%eax - jmp LClampDone -LClampHigh: - movl $0x7FFF,%eax -LClampDone: - -// val = (snd_p[i+1]*snd_vol)>>8; -// if (val > 0x7fff) -// snd_out[i+1] = 0x7fff; -// else if (val < (short)0x8000) -// snd_out[i+1] = (short)0x8000; -// else -// snd_out[i+1] = val; - movl -4(%ebx,%ecx,4),%edx - imull %esi,%edx - sarl $8,%edx - cmpl $0x7FFF,%edx - jg LClampHigh2 - cmpl $0xFFFF8000,%edx - jnl LClampDone2 - movl $0xFFFF8000,%edx - jmp LClampDone2 -LClampHigh2: - movl $0x7FFF,%edx -LClampDone2: - shll $16,%edx - andl $0xFFFF,%eax - orl %eax,%edx - movl %edx,-4(%edi,%ecx,2) - -// } - subl $2,%ecx - jnz LWLBLoopTop - -// snd_p += snd_linear_count; - - popl %ebx - popl %edi - popl %esi - - ret -#endif - - -#endif // id386 diff --git a/engine/client/sys_dosa.s b/engine/client/sys_dosa.s deleted file mode 100644 index 7b0ea6189..000000000 --- a/engine/client/sys_dosa.s +++ /dev/null @@ -1,95 +0,0 @@ -// -// sys_dosa.s -// x86 assembly-language DOS-dependent routines. - -#include "asm_i386.h" -#include "quakeasm.h" - - - .data - - .align 4 -fpenv: - .long 0, 0, 0, 0, 0, 0, 0, 0 - - .text - -.globl C(MaskExceptions) -C(MaskExceptions): - fnstenv fpenv - orl $0x3F,fpenv - fldenv fpenv - - ret - -#if 0 -.globl C(unmaskexceptions) -C(unmaskexceptions): - fnstenv fpenv - andl $0xFFFFFFE0,fpenv - fldenv fpenv - - ret -#endif - - .data - - .align 4 -.globl ceil_cw, single_cw, full_cw, cw, pushed_cw -ceil_cw: .long 0 -single_cw: .long 0 -full_cw: .long 0 -cw: .long 0 -pushed_cw: .long 0 - - .text - -.globl C(Sys_LowFPPrecision) -C(Sys_LowFPPrecision): - fldcw single_cw - - ret - -.globl C(Sys_HighFPPrecision) -C(Sys_HighFPPrecision): - fldcw full_cw - - ret - -.globl C(Sys_PushFPCW_SetHigh) -C(Sys_PushFPCW_SetHigh): - fnstcw pushed_cw - fldcw full_cw - - ret - -.globl C(Sys_PopFPCW) -C(Sys_PopFPCW): - fldcw pushed_cw - - ret - -.globl C(Sys_SetFPCW) -C(Sys_SetFPCW): - fnstcw cw - movl cw,%eax -#if id386 - andb $0xF0,%ah - orb $0x03,%ah // round mode, 64-bit precision -#endif - movl %eax,full_cw - -#if id386 - andb $0xF0,%ah - orb $0x0C,%ah // chop mode, single precision -#endif - movl %eax,single_cw - -#if id386 - andb $0xF0,%ah - orb $0x08,%ah // ceil mode, single precision -#endif - movl %eax,ceil_cw - - ret - diff --git a/engine/client/sys_linux.c b/engine/client/sys_linux.c index 4aa2d021d..becec06af 100644 --- a/engine/client/sys_linux.c +++ b/engine/client/sys_linux.c @@ -224,9 +224,6 @@ void Sys_Quit (void) void Sys_Init(void) { -#if id386 - Sys_SetFPCW(); -#endif } void Sys_Error (const char *error, ...) @@ -573,7 +570,6 @@ char *Sys_ConsoleInput(void) return NULL; } -#if !id386 void Sys_HighFPPrecision (void) { } @@ -581,7 +577,6 @@ void Sys_HighFPPrecision (void) void Sys_LowFPPrecision (void) { } -#endif int main (int c, char **v) { diff --git a/engine/client/sys_win.c b/engine/client/sys_win.c index 49fefa482..1a88bb624 100644 --- a/engine/client/sys_win.c +++ b/engine/client/sys_win.c @@ -277,10 +277,6 @@ static HANDLE tevent; void Sys_InitFloatTime (void); -void VARGS MaskExceptions (void); -void Sys_PopFPCW (void); -void Sys_PushFPCW_SetHigh (void); - int VARGS Sys_DebugLog(char *file, char *fmt, ...) { FILE *fd; @@ -648,12 +644,6 @@ void Sys_Init (void) } #endif - -#ifndef SERVERONLY - MaskExceptions (); - Sys_SetFPCW (); -#endif - #if 0 if (!QueryPerformanceFrequency (&PerformanceFreq)) Sys_Error ("No hardware timer available"); @@ -1789,7 +1779,6 @@ qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refres } -#if !id386 //these couldn't be found... (it is a masm thing, right?) void Sys_HighFPPrecision (void) { } @@ -1805,7 +1794,6 @@ void VARGS Sys_SetFPCW (void) void VARGS MaskExceptions (void) { } -#endif #ifdef MULTITHREAD /* Thread creation calls */ diff --git a/engine/client/sys_wina.s b/engine/client/sys_wina.s deleted file mode 100644 index 2ef941233..000000000 --- a/engine/client/sys_wina.s +++ /dev/null @@ -1,118 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// -// sys_wina.s -// x86 assembly-language Win-dependent routines. - -#include "asm_i386.h" -#include "quakeasm.h" - -#ifndef NOASM - -//@@@ should be id386-dependent, and have an equivalent C path - - .data - - .align 4 -fpenv: - .long 0, 0, 0, 0, 0, 0, 0, 0 - - .text - -.globl C(MaskExceptions) -C(MaskExceptions): - fnstenv fpenv - orl $0x3F,fpenv - fldenv fpenv - - ret - -#if 0 -.globl C(unmaskexceptions) -C(unmaskexceptions): - fnstenv fpenv - andl $0xFFFFFFE0,fpenv - fldenv fpenv - - ret -#endif - - .data - - .align 4 -.globl ceil_cw, single_cw, full_cw, cw, pushed_cw -ceil_cw: .long 0 -single_cw: .long 0 -full_cw: .long 0 -cw: .long 0 -pushed_cw: .long 0 - - .text - -.globl C(Sys_LowFPPrecision) -C(Sys_LowFPPrecision): - fldcw single_cw - - ret - -.globl C(Sys_HighFPPrecision) -C(Sys_HighFPPrecision): - fldcw full_cw - - ret - -.globl C(Sys_PushFPCW_SetHigh) -C(Sys_PushFPCW_SetHigh): - fnstcw pushed_cw - fldcw full_cw - - ret - -.globl C(Sys_PopFPCW) -C(Sys_PopFPCW): - fldcw pushed_cw - - ret - -.globl C(Sys_SetFPCW) -C(Sys_SetFPCW): - fnstcw cw - movl cw,%eax -#if id386 - andb $0xF0,%ah - orb $0x03,%ah // round mode, 64-bit precision -#endif - movl %eax,full_cw - -#if id386 - andb $0xF0,%ah - orb $0x0C,%ah // chop mode, single precision -#endif - movl %eax,single_cw - -#if id386 - andb $0xF0,%ah - orb $0x08,%ah // ceil mode, single precision -#endif - movl %eax,ceil_cw - - ret - -#endif \ No newline at end of file diff --git a/engine/common/asm_i386.h b/engine/common/asm_i386.h deleted file mode 100644 index a521107a9..000000000 --- a/engine/common/asm_i386.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#ifndef __ASM_I386__ -#define __ASM_I386__ - -#if defined(CYGORELF) || defined(ELF) -#define C(label) label -#else -#define C(label) _##label -#endif - -// -// !!! note that this file must match the corresponding C structures at all -// times !!! -// - -// plane_t structure -// !!! if this is changed, it must be changed in model.h too !!! -// !!! if the size of this is changed, the array lookup in SV_HullPointContents -// must be changed too !!! -#define pl_normal 0 -#define pl_dist 12 -#define pl_type 16 -#define pl_signbits 17 -#define pl_pad 18 -#define pl_size 20 - -// hull_t structure -// !!! if this is changed, it must be changed in model.h too !!! -#define hu_clipnodes 0 -#define hu_planes 4 -#define hu_firstclipnode 8 -#define hu_lastclipnode 12 -#define hu_clip_mins 16 -#define hu_clip_maxs 28 -#define hu_available 40 -#define hu_size 44 - -// dnode_t structure -// !!! if this is changed, it must be changed in bspfile.h too !!! -#define nd_planenum 0 -#define nd_children 4 -#define nd_mins 8 -#define nd_maxs 20 -#define nd_firstface 32 -#define nd_numfaces 36 -#define nd_size 40 - -// sfxcache_t structure -// !!! if this is changed, it much be changed in sound.h too !!! -#define sfxc_length 0 -#define sfxc_loopstart 4 -#define sfxc_speed 8 -#define sfxc_width 12 -#define sfxc_stereo 16 -#define sfxc_data 20 - -// channel_t structure -// !!! if this is changed, it much be changed in sound.h too !!! -#define MAXSOUNDCHANNELS 6 -#define ch_sfx 0 -#define ch_vol ch_sfx+4 -#define ch_end ch_vol+4*MAXSOUNDCHANNELS -#define ch_pos ch_end+4 -#define ch_looping ch_looping+4 -#define ch_entnum ch_entnum+4 -#define ch_entchannel ch_entchannel+4 -#define ch_origin ch_origin+4 -#define ch_dist_mult ch_dist_mult+4 -#define ch_master_vol ch_master_vol+4 -#define ch_size ch_size+4 - -// portable_samplepair_t structure -// !!! if this is changed, it much be changed in sound.h too !!! -#define psp_left 0 -#define psp_right 4 -#define psp_size 8 - -#endif - diff --git a/engine/common/bothdefs.h b/engine/common/bothdefs.h index 3445b5189..4fbe796bc 100644 --- a/engine/common/bothdefs.h +++ b/engine/common/bothdefs.h @@ -61,7 +61,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #define AVAIL_OPENAL /* Jogi's OpenAL support */ #endif - #define AVAIL_MASM #if defined(MINGW) || defined(MACOSX) #define AVAIL_PNGLIB @@ -104,9 +103,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef NO_OGG #undef AVAIL_OGGVORBIS #endif -#if defined(NO_MASM) || !defined(_WIN32) - #undef AVAIL_MASM -#endif #if defined(NO_FREETYPE) #undef AVAIL_FREETYPE #endif @@ -114,14 +110,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //#define AVAIL_FREETYPE //set any additional defines or libs in win32 - #ifndef AVAIL_MASM - #ifdef _WIN32 - #define NOASM - #else - #undef AVAIL_MASM //fixme - #endif - #endif - #define SVRANKING #ifdef MINIMAL @@ -130,7 +118,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #undef AVAIL_JPEGLIB //no jpeg support #undef AVAIL_PNGLIB //no png support #undef USE_MADLIB //no internal mp3 playing - #undef USE_D3D //no d3d support #define NOMEDIA //NO playing of avis/cins/roqs #define MD3MODELS //we DO want to use quake3 alias models. This might be a minimal build, but we still want this. @@ -240,10 +227,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif #endif -#if !defined(AVAIL_D3D) || !defined(GLQUAKE) - #undef USE_D3D -#endif - #ifdef NPQTV #undef TEXTEDITOR #undef WEBSERVER @@ -367,17 +350,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif -#if (defined(_M_IX86) || defined(__i386__)) && !defined(id386) && !defined(__amd64__) && !defined(_AMD64_) -#define id386 1 -#else -#define id386 0 -#endif - -#if defined(NOASM) // no asm in dedicated server -#undef id386 -#endif - -#if id386 +#if (defined(_M_IX86) || defined(__i386__)) && !defined(__amd64__) && !defined(_AMD64_) #define UNALIGNED_OK 1 // set to 0 if unaligned accesses are not supported #else #define UNALIGNED_OK 0 diff --git a/engine/common/common.c b/engine/common/common.c index 00756bf1a..06278abb4 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -3130,9 +3130,6 @@ void COM_Version_f (void) #ifdef D3DQUAKE Con_Printf("Direct3D available\n"); #endif -#ifdef USE_D3D - Con_Printf("FakeGL available\n"); -#endif #ifdef _SDL Con_Printf("SDL version: %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL); diff --git a/engine/common/math.s b/engine/common/math.s deleted file mode 100644 index a3d240e7c..000000000 --- a/engine/common/math.s +++ /dev/null @@ -1,370 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// -// math.s -// x86 assembly-language math routines. - -#include "asm_i386.h" -#include "quakeasm.h" - - -#if id386 - - .data - - .align 4 -Ljmptab: .long Lcase0, Lcase1, Lcase2, Lcase3 - .long Lcase4, Lcase5, Lcase6, Lcase7 - - .text - -// TODO: rounding needed? -// stack parameter offset -#define val 4 - -.globl C(Invert24To16) -C(Invert24To16): - - movl val(%esp),%ecx - movl $0x100,%edx // 0x10000000000 as dividend - cmpl %edx,%ecx - jle LOutOfRange - - subl %eax,%eax - divl %ecx - - ret - -LOutOfRange: - movl $0xFFFFFFFF,%eax - ret - -#define EMINS 4+4 -#define EMAXS 4+8 -#define P 4+12 - - .align 2 -.globl C(BoxOnPlaneSide) -C(BoxOnPlaneSide): - pushl %ebx - - movl P(%esp),%edx - movl EMINS(%esp),%ecx - xorl %eax,%eax - movl EMAXS(%esp),%ebx - movb pl_signbits(%edx),%al - cmpb $8,%al - jge Lerror - flds pl_normal(%edx) // p->normal[0] - fld %st(0) // p->normal[0] | p->normal[0] - jmp Ljmptab(,%eax,4) - - -//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; -//dist2= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; -Lcase0: - fmuls (%ebx) // p->normal[0]*emaxs[0] | p->normal[0] - flds pl_normal+4(%edx) // p->normal[1] | p->normal[0]*emaxs[0] | - // p->normal[0] - fxch %st(2) // p->normal[0] | p->normal[0]*emaxs[0] | - // p->normal[1] - fmuls (%ecx) // p->normal[0]*emins[0] | - // p->normal[0]*emaxs[0] | p->normal[1] - fxch %st(2) // p->normal[1] | p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fld %st(0) // p->normal[1] | p->normal[1] | - // p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fmuls 4(%ebx) // p->normal[1]*emaxs[1] | p->normal[1] | - // p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - flds pl_normal+8(%edx) // p->normal[2] | p->normal[1]*emaxs[1] | - // p->normal[1] | p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fxch %st(2) // p->normal[1] | p->normal[1]*emaxs[1] | - // p->normal[2] | p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fmuls 4(%ecx) // p->normal[1]*emins[1] | - // p->normal[1]*emaxs[1] | - // p->normal[2] | p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fxch %st(2) // p->normal[2] | p->normal[1]*emaxs[1] | - // p->normal[1]*emins[1] | - // p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fld %st(0) // p->normal[2] | p->normal[2] | - // p->normal[1]*emaxs[1] | - // p->normal[1]*emins[1] | - // p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fmuls 8(%ebx) // p->normal[2]*emaxs[2] | - // p->normal[2] | - // p->normal[1]*emaxs[1] | - // p->normal[1]*emins[1] | - // p->normal[0]*emaxs[0] | - // p->normal[0]*emins[0] - fxch %st(5) // p->normal[0]*emins[0] | - // p->normal[2] | - // p->normal[1]*emaxs[1] | - // p->normal[1]*emins[1] | - // p->normal[0]*emaxs[0] | - // p->normal[2]*emaxs[2] - faddp %st(0),%st(3) //p->normal[2] | - // p->normal[1]*emaxs[1] | - // p->normal[1]*emins[1]+p->normal[0]*emins[0]| - // p->normal[0]*emaxs[0] | - // p->normal[2]*emaxs[2] - fmuls 8(%ecx) //p->normal[2]*emins[2] | - // p->normal[1]*emaxs[1] | - // p->normal[1]*emins[1]+p->normal[0]*emins[0]| - // p->normal[0]*emaxs[0] | - // p->normal[2]*emaxs[2] - fxch %st(1) //p->normal[1]*emaxs[1] | - // p->normal[2]*emins[2] | - // p->normal[1]*emins[1]+p->normal[0]*emins[0]| - // p->normal[0]*emaxs[0] | - // p->normal[2]*emaxs[2] - faddp %st(0),%st(3) //p->normal[2]*emins[2] | - // p->normal[1]*emins[1]+p->normal[0]*emins[0]| - // p->normal[0]*emaxs[0]+p->normal[1]*emaxs[1]| - // p->normal[2]*emaxs[2] - fxch %st(3) //p->normal[2]*emaxs[2] + - // p->normal[1]*emins[1]+p->normal[0]*emins[0]| - // p->normal[0]*emaxs[0]+p->normal[1]*emaxs[1]| - // p->normal[2]*emins[2] - faddp %st(0),%st(2) //p->normal[1]*emins[1]+p->normal[0]*emins[0]| - // dist1 | p->normal[2]*emins[2] - - jmp LSetSides - -//dist1= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; -//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; -Lcase1: - fmuls (%ecx) // emins[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ebx) // emaxs[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ebx) // emaxs[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ecx) // emins[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ebx) // emaxs[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ecx) // emins[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - - jmp LSetSides - -//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; -//dist2= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; -Lcase2: - fmuls (%ebx) // emaxs[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ecx) // emins[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ecx) // emins[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ebx) // emaxs[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ebx) // emaxs[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ecx) // emins[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - - jmp LSetSides - -//dist1= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; -//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; -Lcase3: - fmuls (%ecx) // emins[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ebx) // emaxs[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ecx) // emins[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ebx) // emaxs[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ebx) // emaxs[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ecx) // emins[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - - jmp LSetSides - -//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; -//dist2= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; -Lcase4: - fmuls (%ebx) // emaxs[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ecx) // emins[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ebx) // emaxs[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ecx) // emins[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ecx) // emins[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ebx) // emaxs[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - - jmp LSetSides - -//dist1= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; -//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; -Lcase5: - fmuls (%ecx) // emins[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ebx) // emaxs[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ebx) // emaxs[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ecx) // emins[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ecx) // emins[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ebx) // emaxs[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - - jmp LSetSides - -//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; -//dist2= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; -Lcase6: - fmuls (%ebx) // emaxs[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ecx) // emins[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ecx) // emins[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ebx) // emaxs[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ecx) // emins[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ebx) // emaxs[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - - jmp LSetSides - -//dist1= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; -//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; -Lcase7: - fmuls (%ecx) // emins[0] - flds pl_normal+4(%edx) - fxch %st(2) - fmuls (%ebx) // emaxs[0] - fxch %st(2) - fld %st(0) - fmuls 4(%ecx) // emins[1] - flds pl_normal+8(%edx) - fxch %st(2) - fmuls 4(%ebx) // emaxs[1] - fxch %st(2) - fld %st(0) - fmuls 8(%ecx) // emins[2] - fxch %st(5) - faddp %st(0),%st(3) - fmuls 8(%ebx) // emaxs[2] - fxch %st(1) - faddp %st(0),%st(3) - fxch %st(3) - faddp %st(0),%st(2) - -LSetSides: - -// sides = 0; -// if (dist1 >= p->dist) -// sides = 1; -// if (dist2 < p->dist) -// sides |= 2; - - faddp %st(0),%st(2) // dist1 | dist2 - fcomps pl_dist(%edx) - xorl %ecx,%ecx - fnstsw %ax - fcomps pl_dist(%edx) - andb $1,%ah - xorb $1,%ah - addb %ah,%cl - - fnstsw %ax - andb $1,%ah - addb %ah,%ah - addb %ah,%cl - -// return sides; - - popl %ebx - movl %ecx,%eax // return status - - ret - - -Lerror: - call C(BOPS_Error) - -#endif // id386 diff --git a/engine/common/mathlib.c b/engine/common/mathlib.c index 45c01beb0..36cf7f21a 100644 --- a/engine/common/mathlib.c +++ b/engine/common/mathlib.c @@ -172,8 +172,6 @@ void VARGS BOPS_Error (void) Sys_Error ("BoxOnPlaneSide: Bad signbits"); } -#if !id386 - /* ================== BoxOnPlaneSide @@ -281,8 +279,6 @@ if (sides == 0) return sides; } -#endif - @@ -694,8 +690,6 @@ int GreatestCommonDivisor (int i1, int i2) } -#if !id386 - // TODO: move to nonintel.c /* @@ -715,7 +709,6 @@ fixed16_t Invert24To16(fixed16_t val) (((double)0x10000 * (double)0x1000000 / (double)val) + 0.5); } -#endif diff --git a/engine/common/q1bsp.c b/engine/common/q1bsp.c index 2f91d7a9a..44aed1844 100644 --- a/engine/common/q1bsp.c +++ b/engine/common/q1bsp.c @@ -23,8 +23,6 @@ void Q1BSP_CheckHullNodes(hull_t *hull) } } -#if !id386 - /* ================== SV_HullPointContents @@ -54,9 +52,6 @@ static int Q1_HullPointContents (hull_t *hull, int num, vec3_t p) return num; } -#else -int VARGS Q1_HullPointContents (hull_t *hull, int num, vec3_t p); -#endif // !id386 diff --git a/engine/common/quakeasm.h b/engine/common/quakeasm.h deleted file mode 100644 index 8ed67c419..000000000 --- a/engine/common/quakeasm.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// -// quakeasm.h: general asm header file -// -#ifdef _WIN32 -#define __i386__ 1 -#endif - -#if defined(NOASM) -#define id386 0 -#else -#ifdef __i386__ -#define id386 1 -#else -#define id386 0 -#endif -#endif - - -#ifdef MQUAKE -#define GLQUAKE -#endif - -// !!! must be kept the same as in d_iface.h !!! -#define TRANSPARENT_COLOR 255 - -#ifndef NeXT - - .extern C(paintbuffer) -// .extern C(snd_linear_count) - .extern C(cursndcard) - .extern C(snd_p) - .extern C(snd_vol) - .extern C(snd_out) - .extern C(vright) - .extern C(vup) - .extern C(vpn) - .extern C(BOPS_Error) - -#endif diff --git a/engine/common/sys.h b/engine/common/sys.h index bf3259291..d22818d79 100644 --- a/engine/common/sys.h +++ b/engine/common/sys.h @@ -85,10 +85,6 @@ void Sys_ServerActivity(void); void Sys_SendKeyEvents (void); // Perform Key_Event () callbacks until the input que is empty -void Sys_LowFPPrecision (void); -void Sys_HighFPPrecision (void); -void VARGS Sys_SetFPCW (void); - int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, int, void *), void *parm); qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refreshrate); diff --git a/engine/d3d7/d3d7_draw.c b/engine/d3d7/d3d7_draw.c deleted file mode 100644 index 81fbb9a77..000000000 --- a/engine/d3d7/d3d7_draw.c +++ /dev/null @@ -1,828 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "d3dquake.h" - -#define MAX_WIDTH 512 -#define MAX_HEIGHT 512 - -void *d3dexplosiontexture; -void *d3dballtexture; - -LPDIRECTDRAWSURFACE7 draw_chars_tex; -mpic_t *conback_tex; - -typedef struct d3dcachepic_s -{ - char name[MAX_QPATH]; - mpic_t pic; -} d3dcachepic_t; -#define MAX_CACHED_PICS 512 //a temporary solution -d3dcachepic_t d3dmenu_cachepics[MAX_CACHED_PICS]; -int d3dmenu_numcachepics; - - - -typedef struct { - float x, y, z; - int colour; - float s, t; -} d3dquadvert_t; -d3dquadvert_t d3dquadvert[4]; -index_t d3dquadindexes[6] = { - 0, 1, 2, - 0, 2, 3 -}; -//pD3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX2, d3dstate.vertbuf, d3dstate.numverts, d3dstate.indexbuf, d3dstate.numindicies, 0); - - -static void Upload_Texture_32(LPDIRECTDRAWSURFACE7 surf, unsigned int *data, int width, int height) -{ - int x, y; - unsigned int *dest; - unsigned char swapbuf[4]; - unsigned char swapbuf2[4]; - DDSURFACEDESC2 desc; - - memset(&desc, 0, sizeof(desc)); - - surf->lpVtbl->Lock(surf, NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - - if (width == desc.dwWidth && height == desc.dwHeight) - { -// if (desc.lPitch == twidth*4) -// { -// memcpy(desc.lpSurface, data, width*height*4); -// } -// else - { - for (y = 0; y < desc.dwHeight; y++) - { - dest = (unsigned int *)((char *)desc.lpSurface + desc.lPitch*y); - for (x = 0; x < desc.dwWidth; x++) - { - *(unsigned int*)swapbuf2 = *(unsigned int*)swapbuf = data[x]; - swapbuf[0] = swapbuf2[2]; - swapbuf[2] = swapbuf2[0]; - dest[x] = *(unsigned int*)swapbuf; - } - data += width; - } - } - } - else - { - int x, y; - int iny; - unsigned int *row, *inrow; - - for (y = 0; y < desc.dwHeight; y++) - { - row = (unsigned int*)((char *)desc.lpSurface + desc.lPitch*y); - iny = (y * height) / desc.dwHeight; - inrow = data + width*iny; - for (x = 0; x < desc.dwWidth; x++) - { - *(unsigned int*)swapbuf2 = *(unsigned int*)swapbuf = inrow[(x * width)/desc.dwWidth]; - swapbuf[0] = swapbuf2[2]; - swapbuf[2] = swapbuf2[0]; - row[x] = *(unsigned int*)swapbuf; - } - } - - - - //mimic opengl and draw it white -// memset(desc.lpSurface, 255, twidth*theight*4); - } - - surf->lpVtbl->Unlock(surf, NULL); -} - -void D3D7_MipMap (qbyte *out, qbyte *in, int width, int height) -{ - int i, j; - - width <<=2; - height >>= 1; - for (i=0 ; i>2; - out[1] = (in[1] + in[5] + in[width+1] + in[width+5])>>2; - out[2] = (in[2] + in[6] + in[width+2] + in[width+6])>>2; - out[3] = (in[3] + in[7] + in[width+3] + in[width+7])>>2; - } - } -} - -//create a basic shader from a 32bit image -void *D3D7_LoadTexture_32(char *name, unsigned int *data, int width, int height, int flags) -{ - static unsigned char mipdata[(MAX_WIDTH/2)*(MAX_HEIGHT/2)][4]; - - DWORD tflags; - DWORD twidth = width; - DWORD theight = height; - D3DX_SURFACEFORMAT tformat = D3DX_SF_A8R8G8B8; - LPDIRECTDRAWSURFACE7 newsurf; - DWORD nummips; - -/* if (!(flags & TF_MANDATORY)) - { - Con_Printf("Texture upload missing flags\n"); - return NULL; - } -*/ - if (flags & TF_MIPMAP) - tflags = 0; - else - tflags = D3DX_TEXTURE_NOMIPMAP; - - D3DXCreateTexture(pD3DDev, &tflags, &twidth, &theight, &tformat, NULL, &newsurf, &nummips); - if (!newsurf) - return NULL; - - if (tformat != D3DX_SF_A8R8G8B8) - Sys_Error("Couldn't create a d3d texture with a usable texture format"); - - - Upload_Texture_32(newsurf, data, width, height); - - if (flags & TF_MIPMAP) - { - LPDIRECTDRAWSURFACE7 miptex; - LPDIRECTDRAWSURFACE7 lasttex; - DDSCAPS2 caps; - memset(&caps, 0, sizeof(caps)); - caps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; - newsurf->lpVtbl->GetAttachedSurface(newsurf, &caps, &miptex); - while (miptex) - { - D3D7_MipMap(mipdata, data, width, height); - data = mipdata; - width/=2; - height/=2; - - Upload_Texture_32(miptex, mipdata, width, height); - - lasttex = miptex; - miptex->lpVtbl->GetAttachedSurface(miptex, &caps, &miptex); - lasttex->lpVtbl->Release(lasttex); - } - } - - return newsurf; -} - -//create a basic shader from an 8bit image with 24bit palette -void *D3D7_LoadTexture_8_Pal24(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette, int transparentpix) -{ - //just expands it to 32bpp and passes it on - static unsigned char out[MAX_WIDTH*MAX_HEIGHT][4]; - int i; - - if (!(flags & TF_ALPHA)) - transparentpix = 256; - - if (width*height > MAX_WIDTH*MAX_HEIGHT) - Sys_Error("GL_Upload8_Pal24: too big"); - - for (i = width*height; i >= 0 ; i--) - { - out[i][0] = palette[data[i]*3+0]; - out[i][1] = palette[data[i]*3+1]; - out[i][2] = palette[data[i]*3+2]; - out[i][3] = 255*(data[i] != transparentpix); - } - - - return D3D7_LoadTexture_32(name, (unsigned int*)out, width, height, flags); -} - -void *D3D7_LoadTexture_8_Pal32(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette) -{ - //just expands it to 32bpp and passes it on - static unsigned char out[MAX_WIDTH*MAX_HEIGHT][4]; - int i; - - if (width*height > MAX_WIDTH*MAX_HEIGHT) - Sys_Error("GL_Upload8_Pal24: too big"); - - for (i = width*height; i >= 0 ; i--) - { - out[i][0] = palette[data[i]*4+0]; - out[i][1] = palette[data[i]*4+1]; - out[i][2] = palette[data[i]*4+2]; - out[i][3] = palette[data[i]*4+3]; - } - - - return D3D7_LoadTexture_32(name, (unsigned int*)out, width, height, flags); -} - - -void D3D7_UnloadTexture(LPDIRECTDRAWSURFACE7 tex) -{ - tex->lpVtbl->Release(tex); -} - - - - - - - - -static qbyte exptexture[16][16] = -{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0}, - {0,0,0,1,1,1,1,1,3,1,1,2,1,0,0,0}, - {0,0,0,1,1,1,1,4,4,4,5,4,2,1,1,0}, - {0,0,1,1,6,5,5,8,6,8,3,6,3,2,1,0}, - {0,0,1,5,6,7,5,6,8,8,8,3,3,1,0,0}, - {0,0,0,1,6,8,9,9,9,9,4,6,3,1,0,0}, - {0,0,2,1,7,7,9,9,9,9,5,3,1,0,0,0}, - {0,0,2,4,6,8,9,9,9,9,8,6,1,0,0,0}, - {0,0,2,2,3,5,6,8,9,8,8,4,4,1,0,0}, - {0,0,1,2,4,1,8,7,8,8,6,5,4,1,0,0}, - {0,1,1,1,7,8,1,6,7,5,4,7,1,0,0,0}, - {0,1,2,1,1,5,1,3,4,3,1,1,0,0,0,0}, - {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, -}; -void D3D7_InitParticleTexture (void) -{ -#define PARTICLETEXTURESIZE 64 - int x,y; - float dx, dy, d; - qbyte data[PARTICLETEXTURESIZE*PARTICLETEXTURESIZE][4]; - -//Explosion texture - - - for (x=0 ; x<16 ; x++) - { - for (y=0 ; y<16 ; y++) - { - data[y*16+x][0] = 255; - data[y*16+x][1] = 255; - data[y*16+x][2] = 255; - data[y*16+x][3] = exptexture[x][y]*255/9.0; - } - } - d3dexplosiontexture = D3D7_LoadTexture_32("", (unsigned int*)data, 16, 16, TF_ALPHA|TF_NOTBUMPMAP|TF_NOMIPMAP); - - memset(data, 255, sizeof(data)); - for (y = 0;y < PARTICLETEXTURESIZE;y++) - { - dy = (y - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1); - for (x = 0;x < PARTICLETEXTURESIZE;x++) - { - dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1); - d = 256 * (1 - (dx*dx+dy*dy)); - d = bound(0, d, 255); - data[y*PARTICLETEXTURESIZE+x][3] = (qbyte) d; - } - } - - d3dballtexture = D3D7_LoadTexture_32("", (unsigned int*)data, PARTICLETEXTURESIZE, PARTICLETEXTURESIZE, TF_ALPHA|TF_NOTBUMPMAP|TF_NOMIPMAP); -} - - - - - - - - - -mpic_t *(D3D7_Draw_SafePicFromWad) (char *name) -{ - LPDIRECTDRAWSURFACE7 *p; - d3dcachepic_t *pic; - qpic_t *qpic; - int i; - - for (i = 0; i < d3dmenu_numcachepics; i++) - { - if (!strcmp(d3dmenu_cachepics[i].name, name)) - return &d3dmenu_cachepics[i].pic; - } - - qpic = (qpic_t *)W_SafeGetLumpName (name); - if (!qpic) - { - return NULL; - } - - SwapPic (qpic); - - pic = &d3dmenu_cachepics[d3dmenu_numcachepics++]; - - Q_strncpyz (pic->name, name, sizeof(pic->name)); - - pic->pic.width = qpic->width; - pic->pic.height = qpic->height; - p = (LPDIRECTDRAWSURFACE7*)&pic->pic.d.data; - if (!strcmp(name, "conchars")) - *p = draw_chars_tex; - else - { - *p = (LPDIRECTDRAWSURFACE7)Mod_LoadReplacementTexture(pic->name, "wad", false, true, true); - if (!*p) - *p = D3D7_LoadTexture_8_Pal24(name, (unsigned char*)(qpic+1), qpic->width, qpic->height, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP, host_basepal, 255); - } - -// Con_Printf("Fixme: D3D_Draw_SafePicFromWad\n"); - return &pic->pic; -} -mpic_t *(D3D7_Draw_SafeCachePic) (char *path) -{ - LPDIRECTDRAWSURFACE7 *p; - d3dcachepic_t *pic; - qpic_t *qpic; - int i; - - - for (i = 0; i < d3dmenu_numcachepics; i++) - { - if (!strcmp(d3dmenu_cachepics[i].name, path)) - return &d3dmenu_cachepics[i].pic; - } - - qpic = (qpic_t *)COM_LoadTempFile (path); - if (!qpic) - { - return NULL; - } - - SwapPic (qpic); - - pic = &d3dmenu_cachepics[d3dmenu_numcachepics++]; - - Q_strncpyz (pic->name, path, sizeof(pic->name)); - - pic->pic.width = qpic->width; - pic->pic.height = qpic->height; - p = (LPDIRECTDRAWSURFACE7*)&pic->pic.d.data; - *p = (LPDIRECTDRAWSURFACE7)Mod_LoadReplacementTexture(pic->name, "gfx", false, true, true); - if (!*p) - *p = D3D7_LoadTexture_8_Pal24(path, (unsigned char*)(qpic+1), qpic->width, qpic->height, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP, host_basepal, 255); - -// Con_Printf("Fixme: D3D_Draw_SafeCachePic\n"); - return &pic->pic; -} -mpic_t *(D3D7_Draw_CachePic) (char *path) -{ - mpic_t *pic; - pic = D3D7_Draw_SafeCachePic(path); - if (!pic) - Sys_Error("Couldn't load picture %s", path); - return pic; -} -void (D3D7_Draw_ReInit) (void) -{ - d3dmenu_numcachepics = 0; - - draw_chars = W_SafeGetLumpName ("conchars"); - - draw_chars_tex = (LPDIRECTDRAWSURFACE7)Mod_LoadReplacementTexture("conchars", "gfx", false, true, true); - if (!draw_chars_tex) - { - if (draw_chars) - draw_chars_tex = D3D7_LoadTexture_8_Pal24("conchars", draw_chars, 128, 128, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP, host_basepal, 0); - if (!draw_chars_tex) - draw_chars_tex = (LPDIRECTDRAWSURFACE7)Mod_LoadHiResTexture("gfx/2d/bigchars.tga", NULL, false, true, false); //try q3 path - if (!draw_chars_tex) - draw_chars_tex = (LPDIRECTDRAWSURFACE7)Mod_LoadHiResTexture("pics/conchars.pcx", NULL, false, true, false); //try low res q2 path - if (!draw_chars_tex) - { - extern qbyte default_conchar[11356]; - int width, height; - int i; - qbyte *image; - - image = ReadTargaFile(default_conchar, sizeof(default_conchar), &width, &height, false); - for (i = 0; i < width*height; i++) - { - image[i*4+3] = image[i*4]; - image[i*4+0] = 255; - image[i*4+1] = 255; - image[i*4+2] = 255; - } - draw_chars_tex = D3D7_LoadTexture_32("charset", (void*)image, width, height, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP); - } - } - - - //now emit the conchars picture as if from a wad. - strcpy(d3dmenu_cachepics[d3dmenu_numcachepics].name, "conchars"); - d3dmenu_cachepics[d3dmenu_numcachepics].pic.width = 128; - d3dmenu_cachepics[d3dmenu_numcachepics].pic.height = 128; - *(int *)&d3dmenu_cachepics[d3dmenu_numcachepics].pic.d.data = (int)draw_chars_tex; - d3dmenu_numcachepics++; - - - conback_tex = D3D7_Draw_SafeCachePic("gfx/conback.lmp"); - - - Plug_DrawReloadImages(); - D3D7_InitParticleTexture(); -} -void (D3D7_Draw_Init) (void) -{ - D3D7_Draw_ReInit(); -} -void (D3D7_Draw_Character) (int x, int y, unsigned int num) -{ - int row; - int col; - float frow, fcol, size; - -#define char_instep 0 - num &= 255; - if (num == ' ') - return; - - row = num>>4; - col = num&15; - - frow = row*0.0625+char_instep; - fcol = col*0.0625+char_instep; - size = 0.0625-char_instep*2; - - d3dquadvert[0].x = x; - d3dquadvert[0].y = y; - d3dquadvert[0].z = 0; - d3dquadvert[0].colour = 0xffffffff; - d3dquadvert[0].s = fcol; - d3dquadvert[0].t = frow; - - d3dquadvert[1].x = x+8; - d3dquadvert[1].y = y; - d3dquadvert[1].z = 0; - d3dquadvert[1].colour = 0xffffffff; - d3dquadvert[1].s = fcol+size; - d3dquadvert[1].t = frow; - - d3dquadvert[2].x = x+8; - d3dquadvert[2].y = y+8; - d3dquadvert[2].z = 0; - d3dquadvert[2].colour = 0xffffffff; - d3dquadvert[2].s = fcol+size; - d3dquadvert[2].t = frow+size; - - d3dquadvert[3].x = x; - d3dquadvert[3].y = y+8; - d3dquadvert[3].z = 0; - d3dquadvert[3].colour = 0xffffffff; - d3dquadvert[3].s = fcol; - d3dquadvert[3].t = frow+size; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, draw_chars_tex); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_TEXCOORDINDEX, 0); - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dquadvert, 4, d3dquadindexes, 6, 0); -} - -void (D3D7_Draw_ColouredCharacter) (int x, int y, unsigned int num) -{ - int row; - int col; - float frow, fcol, size; - unsigned int imgcolour; - unsigned char *c = (unsigned char *)&imgcolour; - -#define char_instep 0 - - if (num&0xffff == ' ') - return; - - col = (num & CON_FGMASK) >> CON_FGSHIFT; - c[0] = consolecolours[col].fb*255; - c[1] = consolecolours[col].fg*255; - c[2] = consolecolours[col].fr*255; - c[3] = (num & CON_HALFALPHA)?128:255; - - - num &= 0xff; - row = num>>4; - col = num&15; - - frow = row*0.0625+char_instep; - fcol = col*0.0625+char_instep; - size = 0.0625-char_instep*2; - - d3dquadvert[0].x = x; - d3dquadvert[0].y = y; - d3dquadvert[0].z = 0; - d3dquadvert[0].colour = imgcolour; - d3dquadvert[0].s = fcol; - d3dquadvert[0].t = frow; - - d3dquadvert[1].x = x+8; - d3dquadvert[1].y = y; - d3dquadvert[1].z = 0; - d3dquadvert[1].colour = imgcolour; - d3dquadvert[1].s = fcol+size; - d3dquadvert[1].t = frow; - - d3dquadvert[2].x = x+8; - d3dquadvert[2].y = y+8; - d3dquadvert[2].z = 0; - d3dquadvert[2].colour = imgcolour; - d3dquadvert[2].s = fcol+size; - d3dquadvert[2].t = frow+size; - - d3dquadvert[3].x = x; - d3dquadvert[3].y = y+8; - d3dquadvert[3].z = 0; - d3dquadvert[3].colour = imgcolour; - d3dquadvert[3].s = fcol; - d3dquadvert[3].t = frow+size; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, draw_chars_tex); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_TEXCOORDINDEX, 0); - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dquadvert, 4, d3dquadindexes, 6, 0); -} -void (D3D7_Draw_String) (int x, int y, const qbyte *str) -{ - while(*str) - { - D3D7_Draw_Character(x, y, *str++); - x+=8; - } -} -void (D3D7_Draw_Alt_String) (int x, int y, const qbyte *str) -{ - while(*str) - { - D3D7_Draw_Character(x, y, *str++ | 128); - x+=8; - } -} -void (D3D7_Draw_Crosshair) (void) -{ - D3D7_Draw_Character(vid.width/2 - 4, vid.height/2 - 4, '+'); -} -void (D3D7_Draw_DebugChar) (qbyte num) -{ - Sys_Error("D3D function not implemented\n"); -} -void (D3D7_Draw_TransPicTranslate) (int x, int y, int w, int h, qbyte *pic, qbyte *translation) -{ -// Sys_Error("D3D function not implemented\n"); -} -void (D3D7_Draw_TileClear) (int x, int y, int w, int h) -{ -// Sys_Error("D3D function not implemented\n"); -} -void (D3D7_Draw_Fill_I) (int x, int y, int w, int h, unsigned int imgcolour) -{ - d3dquadvert[0].x = x; - d3dquadvert[0].y = y; - d3dquadvert[0].z = 0; - d3dquadvert[0].colour = imgcolour; - d3dquadvert[0].s = 0; - d3dquadvert[0].t = 0; - - d3dquadvert[1].x = x+w; - d3dquadvert[1].y = y; - d3dquadvert[1].z = 0; - d3dquadvert[1].colour = imgcolour; - d3dquadvert[1].s = 0; - d3dquadvert[1].t = 0; - - d3dquadvert[2].x = x+w; - d3dquadvert[2].y = y+h; - d3dquadvert[2].z = 0; - d3dquadvert[2].colour = imgcolour; - d3dquadvert[2].s = 0; - d3dquadvert[2].t = 0; - - d3dquadvert[3].x = x; - d3dquadvert[3].y = y+h; - d3dquadvert[3].z = 0; - d3dquadvert[3].colour = imgcolour; - d3dquadvert[3].s = 0; - d3dquadvert[3].t = 0; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, NULL); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dquadvert, 4, d3dquadindexes, 6, 0); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); -} - -void (D3D7_Draw_FillRGB) (int x, int y, int w, int h, float r, float g, float b) -{ - char colours[4]; - colours[0] = b*255; - colours[1] = g*255; - colours[2] = r*255; - colours[3] = 255; - - D3D7_Draw_Fill_I(x, y, w, h, *(unsigned int*)colours); -} - -void (D3D7_Draw_Fill) (int x, int y, int w, int h, unsigned int c) -{ - D3D7_Draw_FillRGB(x, y, w, h, host_basepal[c*3+0]/255.0f, host_basepal[c*3+1]/255.0f, host_basepal[c*3+2]/255.0f); -} -void (D3D7_Draw_FadeScreen) (void) -{ -// Sys_Error("D3D function not implemented\n"); -} -void (D3D7_Draw_BeginDisc) (void) -{ -// Sys_Error("D3D function not implemented\n"); -} -void (D3D7_Draw_EndDisc) (void) -{ -// Sys_Error("D3D function not implemented\n"); -} - -static int imgcolour; - -void (D3D7_Draw_Fill_Colours) (int x, int y, int w, int h) -{ - D3D7_Draw_Fill_I(x, y, w, h, imgcolour); -} - -void (D3D7_Draw_Image) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, mpic_t *pic) -{ - LPDIRECTDRAWSURFACE7 *p; - if (!conback_tex) - return; - if (!pic) - return; - - d3dquadvert[0].x = x; - d3dquadvert[0].y = y; - d3dquadvert[0].z = 0; - d3dquadvert[0].colour = imgcolour; - d3dquadvert[0].s = s1;// - 3.0/pic->width; - d3dquadvert[0].t = t1; - - d3dquadvert[1].x = x+w; - d3dquadvert[1].y = y; - d3dquadvert[1].z = 0; - d3dquadvert[1].colour = imgcolour; - d3dquadvert[1].s = s2;// - 3.0/pic->width; - d3dquadvert[1].t = t1; - - d3dquadvert[2].x = x+w; - d3dquadvert[2].y = y+h; - d3dquadvert[2].z = 0; - d3dquadvert[2].colour = imgcolour; - d3dquadvert[2].s = s2;// - 3.0/pic->width; - d3dquadvert[2].t = t2; - - d3dquadvert[3].x = x; - d3dquadvert[3].y = y+h; - d3dquadvert[3].z = 0; - d3dquadvert[3].colour = imgcolour; - d3dquadvert[3].s = s1;// - 3.0/pic->width; - d3dquadvert[3].t = t2; - - p = (LPDIRECTDRAWSURFACE7*)&pic->d.data; - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, *p); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_TEXCOORDINDEX, 0); - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dquadvert, 4, d3dquadindexes, 6, 0); -} - -void (D3D7_Draw_ScalePic) (int x, int y, int width, int height, mpic_t *pic) -{ - D3D7_Draw_Image(x, y, width, height, 0, 0, 1, 1, pic); -} -void (D3D7_Draw_SubPic) (int x, int y, mpic_t *pic, int srcx, int srcy, int width, int height) -{ - float s, t; - float sw, tw; - if (!pic) - return; - - s = (float)srcx/pic->width; - t = (float)srcy/pic->height; - sw = (float)width/pic->width; - tw = (float)height/pic->height; - D3D7_Draw_Image(x, y, width, height, s, t, s+sw, t+tw, pic); -} -void (D3D7_Draw_TransPic) (int x, int y, mpic_t *pic) -{ - if (!pic) - return; - D3D7_Draw_Image(x, y, pic->width, pic->height, 0, 0, 1, 1, pic); -} -void (D3D7_Draw_Pic) (int x, int y, mpic_t *pic) -{ - if (!pic) - return; - D3D7_Draw_Image(x, y, pic->width, pic->height, 0, 0, 1, 1, pic); -} -void (D3D7_Draw_ImageColours) (float r, float g, float b, float a) -{ - unsigned char *c = (unsigned char *)&imgcolour; - - c[0] = b*255; - c[1] = g*255; - c[2] = r*255; - c[3] = a*255; -} - -void (D3D7_Draw_ConsoleBackground) (int firstline, int lastline, qboolean forceopaque) -{ - D3D7_Draw_ImageColours(1,1,1,1); - D3D7_Draw_Image(0, 0, vid.width, lastline, 0, 1 - (float)lastline/vid.height, 1, 1, conback_tex); -} -void (D3D7_Draw_EditorBackground) (int lines) -{ - D3D7_Draw_ConsoleBackground(0, lines, false); -} - - - - -void (D3D7_Media_ShowFrameBGR_24_Flip) (qbyte *framedata, int inwidth, int inheight) -{ - mpic_t pic; - LPDIRECTDRAWSURFACE7 *p; - p = (LPDIRECTDRAWSURFACE7*)&pic.d.data; - *p = D3D7_LoadTexture_32("", (unsigned int*)framedata, inwidth, inheight, TF_NOMIPMAP|TF_NOALPHA|TF_NOTBUMPMAP); - - D3D7_Set2D (); - D3D7_Draw_ImageColours(1,1,1,1); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - D3D7_Draw_Image(0, 0, vid.width, vid.height, 0, 1, 1, 0, &pic); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - - D3D7_UnloadTexture(*p); -} //input is bottom up... -void (D3D7_Media_ShowFrameRGBA_32) (qbyte *framedata, int inwidth, int inheight) -{ - mpic_t pic; - LPDIRECTDRAWSURFACE7 *p; - - pic.width = inwidth; - pic.height = inheight; - pic.flags = 0; - p = (LPDIRECTDRAWSURFACE7*)&pic.d.data; - *p = D3D7_LoadTexture_32("", (unsigned int*)framedata, inwidth, inheight, TF_NOMIPMAP|TF_NOALPHA|TF_NOTBUMPMAP); - - D3D7_Set2D (); - D3D7_Draw_ImageColours(1,1,1,1); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - D3D7_Draw_Image(0, 0, vid.width, vid.height, 0, 0, 1, 1, &pic); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - - D3D7_UnloadTexture(*p); -} //top down -void (D3D7_Media_ShowFrame8bit) (qbyte *framedata, int inwidth, int inheight, qbyte *palette) -{ - mpic_t pic; - LPDIRECTDRAWSURFACE7 *p; - p = (LPDIRECTDRAWSURFACE7*)&pic.d.data; - *p = D3D7_LoadTexture_8_Pal24("", (unsigned char*)framedata, inwidth, inheight, TF_NOMIPMAP|TF_NOALPHA|TF_NOTBUMPMAP, palette, 256); - - D3D7_Set2D (); - D3D7_Draw_ImageColours(1,1,1,1); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - D3D7_Draw_Image(0, 0, vid.width, vid.height, 0, 1, 1, 0, &pic); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - - D3D7_UnloadTexture(*p); -} //paletted topdown (framedata is 8bit indexes into palette) -#endif diff --git a/engine/d3d7/d3d7_mesh.c b/engine/d3d7/d3d7_mesh.c deleted file mode 100644 index 3440c1a03..000000000 --- a/engine/d3d7/d3d7_mesh.c +++ /dev/null @@ -1,681 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "d3dquake.h" - -#include "com_mesh.h" - -#ifdef _WIN32 -#include -#else -#include -#endif - -extern cvar_t r_fullbrightSkins; -extern cvar_t r_vertexdlights; - - -typedef struct { - float x, y, z; - float s, t; -} meshvert_t; - -typedef struct { - float x, y, z; - unsigned int colour; - float s, t; -} meshcolouredvert_t; - -void D3D_DrawMesh(mesh_t *mesh) -{ - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - { - int v; - vec3_t *xyz; - byte_vec4_t *colour; - vec2_t *wm; - xyz = mesh->xyz_array; - wm = mesh->st_array; - colour = mesh->colors_array; - - if (colour) - { - meshcolouredvert_t *meshvert = alloca(sizeof(meshcolouredvert_t)*mesh->numvertexes); - - for (v = 0; v < mesh->numvertexes; v++, xyz++, wm++, colour++) - { - meshvert[v].x = (*xyz)[0]; - meshvert[v].y = (*xyz)[1]; - meshvert[v].z = (*xyz)[2]; - meshvert[v].colour = *(unsigned int*)colour; - meshvert[v].s = (*wm)[0]; - meshvert[v].t = (*wm)[1]; - } - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, meshvert, mesh->numvertexes, mesh->indexes, mesh->numindexes, 0); - } - else - { - meshvert_t *meshvert = alloca(sizeof(meshvert_t)*mesh->numvertexes); - - for (v = 0; v < mesh->numvertexes; v++, xyz++, wm++) - { - meshvert[v].x = (*xyz)[0]; - meshvert[v].y = (*xyz)[1]; - meshvert[v].z = (*xyz)[2]; - meshvert[v].s = (*wm)[0]; - meshvert[v].t = (*wm)[1]; - } - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_TEX1, meshvert, mesh->numvertexes, mesh->indexes, mesh->numindexes, 0); - } - } -} - - - - -hashtable_t skincolourmapped; - -void d3d_GAliasFlushSkinCache(void) -{ - int i; - bucket_t *b; - for (i = 0; i < skincolourmapped.numbuckets; i++) - { - while((b = skincolourmapped.bucket[i])) - { - skincolourmapped.bucket[i] = b->next; - BZ_Free(b->data); - } - } - if (skincolourmapped.bucket) - BZ_Free(skincolourmapped.bucket); - skincolourmapped.bucket = NULL; - skincolourmapped.numbuckets = 0; -} - -static galiastexnum_t *D3D7_ChooseSkin(galiasinfo_t *inf, char *modelname, int surfnum, entity_t *e) -{ - galiasskin_t *skins; - galiastexnum_t *texnums; - int frame; - - int tc, bc; - int local; - - if (!gl_nocolors.value) - { - if (e->scoreboard) - { - if (!e->scoreboard->skin) - Skin_Find(e->scoreboard); - tc = e->scoreboard->ttopcolor; - bc = e->scoreboard->tbottomcolor; - } - else - { - tc = 1; - bc = 1; - } - - if (tc != 1 || bc != 1 || (e->scoreboard && e->scoreboard->skin)) - { - int inwidth, inheight; - int tinwidth, tinheight; - char *skinname; - qbyte *original; - galiascolourmapped_t *cm; - char hashname[512]; - - if (e->scoreboard && e->scoreboard->skin && !gl_nocolors.value) - { - snprintf(hashname, sizeof(hashname), "%s$%s$%i", modelname, e->scoreboard->skin->name, surfnum); - skinname = hashname; - } - else if (surfnum) - { - snprintf(hashname, sizeof(hashname), "%s$%i", modelname, surfnum); - skinname = hashname; - } - else - skinname = modelname; - - if (!skincolourmapped.numbuckets) - { - void *buckets = BZ_Malloc(Hash_BytesForBuckets(256)); - memset(buckets, 0, Hash_BytesForBuckets(256)); - Hash_InitTable(&skincolourmapped, 256, buckets); - } - - for (cm = Hash_Get(&skincolourmapped, skinname); cm; cm = Hash_GetNext(&skincolourmapped, skinname, cm)) - { - if (cm->tcolour == tc && cm->bcolour == bc && cm->skinnum == e->skinnum) - { - return &cm->texnum; - } - } - - if (!inf->numskins) - { - skins = NULL; - texnums = NULL; - } - else - { - skins = (galiasskin_t*)((char *)inf + inf->ofsskins); - if (!skins->texnums) - { - skins = NULL; - texnums = NULL; - } - else - { - if (e->skinnum >= 0 && e->skinnum < inf->numskins) - skins += e->skinnum; - texnums = (galiastexnum_t*)((char *)skins + skins->ofstexnums); - } - } - - //colourmap isn't present yet. - cm = BZ_Malloc(sizeof(*cm)); - Q_strncpyz(cm->name, skinname, sizeof(cm->name)); - Hash_Add(&skincolourmapped, cm->name, cm, &cm->bucket); - cm->tcolour = tc; - cm->bcolour = bc; - cm->skinnum = e->skinnum; - cm->texnum.fullbright = 0; - cm->texnum.base = 0; -#ifdef Q3SHADERS - cm->texnum.shader = NULL; -#endif - - if (!texnums) - { //load just the skin (q2) -/* if (e->scoreboard && e->scoreboard->skin) - { - if (cls.protocol == CP_QUAKE2) - { - original = Skin_Cache32(e->scoreboard->skin); - if (original) - { - inwidth = e->scoreboard->skin->width; - inheight = e->scoreboard->skin->height; - cm->texnum.base = cm->texnum.fullbright = GL_LoadTexture32(e->scoreboard->skin->name, inwidth, inheight, (unsigned int*)original, true, false); - return &cm->texnum; - } - } - else - { - original = Skin_Cache8(e->scoreboard->skin); - if (original) - { - inwidth = e->scoreboard->skin->width; - inheight = e->scoreboard->skin->height; - cm->texnum.base = cm->texnum.fullbright = GL_LoadTexture(e->scoreboard->skin->name, inwidth, inheight, original, true, false); - return &cm->texnum; - } - } - - cm->texnum.base = Mod_LoadHiResTexture(e->scoreboard->skin->name, "skins", true, false, true); - return &cm->texnum; - } -*/ - return NULL; - } - - cm->texnum.bump = texnums[cm->skinnum].bump; //can't colour bumpmapping - if (cls.protocol != CP_QUAKE2 && ((!texnums || !strcmp(modelname, "progs/player.mdl")) && e->scoreboard && e->scoreboard->skin)) - { - original = Skin_Cache8(e->scoreboard->skin); - inwidth = e->scoreboard->skin->width; - inheight = e->scoreboard->skin->height; - } - else - { - original = NULL; - inwidth = 0; - inheight = 0; - } - if (!original) - { - if (skins->ofstexels) - { - original = (qbyte *)skins + skins->ofstexels; - inwidth = skins->skinwidth; - inheight = skins->skinheight; - } - else - { - original = NULL; - inwidth = 0; - inheight = 0; - } - } - tinwidth = skins->skinwidth; - tinheight = skins->skinheight; - if (original) - { - int i, j; - qbyte translate[256]; - unsigned translate32[256]; - static unsigned pixels[512*512]; - unsigned *out; - unsigned frac, fracstep; - - unsigned scaled_width, scaled_height; - qbyte *inrow; - - texnums = &cm->texnum; - - texnums->base = 0; - texnums->fullbright = 0; - - if (gl_max_size.value <= 0) - gl_max_size.value = 512; - - scaled_width = gl_max_size.value < 512 ? gl_max_size.value : 512; - scaled_height = gl_max_size.value < 512 ? gl_max_size.value : 512; - - for (i=0 ; i<256 ; i++) - translate[i] = i; - - tc<<=4; - bc<<=4; - - for (i=0 ; i<16 ; i++) - { - if (tc < 128) // the artists made some backwards ranges. sigh. - translate[TOP_RANGE+i] = tc+i; - else - translate[TOP_RANGE+i] = tc+15-i; - - if (bc < 128) - translate[BOTTOM_RANGE+i] = bc+i; - else - translate[BOTTOM_RANGE+i] = bc+15-i; - } - - - for (i=0 ; i<256 ; i++) - translate32[i] = d_8to24rgbtable[translate[i]]; - - out = pixels; - fracstep = tinwidth*0x10000/scaled_width; - for (i=0 ; i> 1; - for (j=0 ; j>16]] | 0xff000000; - frac += fracstep; - out[j+1] = translate32[inrow[frac>>16]] | 0xff000000; - frac += fracstep; - out[j+2] = translate32[inrow[frac>>16]] | 0xff000000; - frac += fracstep; - out[j+3] = translate32[inrow[frac>>16]] | 0xff000000; - frac += fracstep; - } - } - texnums->base = D3D7_LoadTexture_32 ("", pixels, scaled_width, scaled_height, 0); -/* texnums->base = texture_extension_number++; - GL_Bind(texnums->base); - qglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -*/ - - //now do the fullbrights. - out = pixels; - fracstep = tinwidth*0x10000/scaled_width; - for (i=0 ; i> 1; - for (j=0 ; j>16] < 255-vid.fullbright) - ((char *) (&out[j]))[3] = 0; //alpha 0 - frac += fracstep; - } - } -/* texnums->fullbright = texture_extension_number++; - GL_Bind(texnums->fullbright); - qglTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -*/ - } - else - { - skins = (galiasskin_t*)((char *)inf + inf->ofsskins); - if (e->skinnum >= 0 && e->skinnum < inf->numskins) - skins += e->skinnum; - - if (!inf->numskins || !skins->texnums) - return NULL; - - frame = cl.time*skins->skinspeed; - frame = frame%skins->texnums; - texnums = (galiastexnum_t*)((char *)skins + skins->ofstexnums + frame*sizeof(galiastexnum_t)); - memcpy(&cm->texnum, texnums, sizeof(cm->texnum)); - } - return &cm->texnum; - } - } - - if (!inf->numskins) - return NULL; - - skins = (galiasskin_t*)((char *)inf + inf->ofsskins); - if (e->skinnum >= 0 && e->skinnum < inf->numskins) - skins += e->skinnum; - else - { - Con_DPrintf("Skin number out of range\n"); - if (!inf->numskins) - return NULL; - } - - if (!skins->texnums) - return NULL; - - frame = cl.time*skins->skinspeed; - frame = frame%skins->texnums; - texnums = (galiastexnum_t*)((char *)skins + skins->ofstexnums + frame*sizeof(galiastexnum_t)); - - return texnums; -} - - -extern vec3_t shadevector; -extern vec3_t ambientlight; -extern vec3_t shadelight; - -static void LotsOfLightDirectionHacks(entity_t *e, model_t *m, vec3_t lightaxis[3]) -{ - int i; - vec3_t dist; - float add; - qboolean nolightdir; - vec3_t lightdir; - - - if (!(r_refdef.flags & Q2RDF_NOWORLDMODEL)) - { - if (e->flags & Q2RF_WEAPONMODEL) - cl.worldmodel->funcs.LightPointValues(cl.worldmodel, r_refdef.vieworg, shadelight, ambientlight, lightdir); - else - cl.worldmodel->funcs.LightPointValues(cl.worldmodel, e->origin, shadelight, ambientlight, lightdir); - } - else - { - ambientlight[0] = ambientlight[1] = ambientlight[2] = shadelight[0] = shadelight[1] = shadelight[2] = 255; - lightdir[0] = 0; - lightdir[1] = 1; - lightdir[2] = 1; - } - - if (!r_vertexdlights.value) - { - for (i=0 ; iorigin, - cl_dlights[i].origin, - dist); - add = cl_dlights[i].radius - Length(dist); - - if (add > 0) { - add*=5; - ambientlight[0] += add * cl_dlights[i].color[0]; - ambientlight[1] += add * cl_dlights[i].color[1]; - ambientlight[2] += add * cl_dlights[i].color[2]; - //ZOID models should be affected by dlights as well - shadelight[0] += add * cl_dlights[i].color[0]; - shadelight[1] += add * cl_dlights[i].color[1]; - shadelight[2] += add * cl_dlights[i].color[2]; - } - } - } - } - else - { - } - - for (i = 0; i < 3; i++) //clamp light so it doesn't get vulgar. - { - if (ambientlight[i] > 128) - ambientlight[i] = 128; - if (ambientlight[i] + shadelight[i] > 192) - shadelight[i] = 192 - ambientlight[i]; - } - - if (e->flags & Q2RF_WEAPONMODEL) - { - for (i = 0; i < 3; i++) - { - if (ambientlight[i] < 24) - ambientlight[i] = shadelight[i] = 24; - } - } - -//MORE HUGE HACKS! WHEN WILL THEY CEASE! - // clamp lighting so it doesn't overbright as much - // ZOID: never allow players to go totally black - nolightdir = false; - if (m->engineflags & MDLF_PLAYER) - { - float fb = r_fullbrightSkins.value; - if (fb > cls.allow_fbskins) - fb = cls.allow_fbskins; - if (fb < 0) - fb = 0; - if (fb) - { - extern cvar_t r_fb_models; - - if (fb >= 1 && r_fb_models.value) - { - ambientlight[0] = ambientlight[1] = ambientlight[2] = 4096; - shadelight[0] = shadelight[1] = shadelight[2] = 4096; - nolightdir = true; - } - else - { - for (i = 0; i < 3; i++) - { - ambientlight[i] = max(ambientlight[i], 8 + fb * 120); - shadelight[i] = max(shadelight[i], 8 + fb * 120); - } - } - } - for (i = 0; i < 3; i++) - { - if (ambientlight[i] < 8) - ambientlight[i] = shadelight[i] = 8; - } - } - if (m->engineflags & MDLF_FLAME) - { - shadelight[0] = shadelight[1] = shadelight[2] = 4096; - ambientlight[0] = ambientlight[1] = ambientlight[2] = 4096; - nolightdir = true; - } - else - { - for (i = 0; i < 3; i++) - { - if (ambientlight[i] > 128) - ambientlight[i] = 128; - - shadelight[i] /= 200.0/255; - ambientlight[i] /= 200.0/255; - } - } - - if ((e->drawflags & MLS_MASKIN) == MLS_ABSLIGHT) - { - shadelight[0] = shadelight[1] = shadelight[2] = e->abslight; - ambientlight[0] = ambientlight[1] = ambientlight[2] = 0; - } - if ((e->drawflags & MLS_MASKIN) == MLS_FULLBRIGHT || (e->flags & Q2RF_FULLBRIGHT)) - { - shadelight[0] = shadelight[1] = shadelight[2] = 255; - ambientlight[0] = ambientlight[1] = ambientlight[2] = 0; - nolightdir = true; - } - -//#define SHOWLIGHTDIR - { //lightdir is absolute, shadevector is relative - shadevector[0] = DotProduct(lightdir, e->axis[0]); - shadevector[1] = DotProduct(lightdir, e->axis[1]); - shadevector[2] = DotProduct(lightdir, e->axis[2]); - - if (e->flags & Q2RF_WEAPONMODEL) - { - vec3_t temp; - temp[0] = DotProduct(shadevector, vpn); - temp[1] = DotProduct(shadevector, vright); - temp[2] = DotProduct(shadevector, vup); - - VectorCopy(temp, shadevector); - } - - VectorNormalize(shadevector); - - VectorCopy(shadevector, lightaxis[2]); - VectorVectors(lightaxis[2], lightaxis[1], lightaxis[0]); - VectorInverse(lightaxis[1]); - } - - if (e->flags & Q2RF_GLOW) - { - shadelight[0] += sin(cl.time)*0.25; - shadelight[1] += sin(cl.time)*0.25; - shadelight[2] += sin(cl.time)*0.25; - } - - //d3d is bgra - //ogl is rgba - //so switch em and use the gl code - add = shadelight[0]; - shadelight[0] = shadelight[2]; - shadelight[2] = add; - - add = ambientlight[0]; - ambientlight[0] = ambientlight[2]; - ambientlight[2] = add; -} - - -qboolean R_GAliasBuildMesh(mesh_t *mesh, galiasinfo_t *inf, int frame1, int frame2, float lerp, float alpha, float fg1time, float fg2time, qboolean nolightdir); -//draws currententity -void D3D7_DrawAliasModel(void) -{ - mesh_t mesh; - extern entity_t *currententity; - entity_t *e = currententity; - galiasinfo_t *inf; - model_t *m; - galiastexnum_t *skin; - int i; - - if (r_secondaryview && e->flags & Q2RF_WEAPONMODEL) - return; - - { - extern int cl_playerindex; - if (e->scoreboard && e->model == cl.model_precache[cl_playerindex]) - { - m = e->scoreboard->model; - if (!m || m->type != mod_alias) - m = e->model; - } - else - m = e->model; - } - - if (!(e->flags & Q2RF_WEAPONMODEL)) - if (R_CullEntityBox (e, m->mins, m->maxs)) - return; - - - inf = GLMod_Extradata (m); - - if (!inf) - return; - - - LotsOfLightDirectionHacks(e, m, mesh.lightaxis); - - - { - float matrix[16]; - - if (e->flags & Q2RF_WEAPONMODEL && r_refdef.currentplayernum>=0) - { //view weapons need to be rotated onto the screen first - float view[16]; - float ent[16]; - Matrix4_ModelMatrixFromAxis(view, cl.viewent[r_refdef.currentplayernum].axis[0], cl.viewent[r_refdef.currentplayernum].axis[1], cl.viewent[r_refdef.currentplayernum].axis[2], cl.viewent[r_refdef.currentplayernum].origin); - Matrix4_ModelMatrixFromAxis(ent, e->axis[0], e->axis[1], e->axis[2], e->origin); - Matrix4_Multiply(view, ent, matrix); - } - else - { - Matrix4_ModelMatrixFromAxis(matrix, e->axis[0], e->axis[1], e->axis[2], e->origin); - } - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)matrix); - } - -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - -if (e->flags & Q2RF_DEPTHHACK) -{ //apply the depth hack to stop things from poking into walls. - //(basically moving it closer to the screen) - D3DVIEWPORT7 viewport; - pD3DDev->lpVtbl->GetViewport(pD3DDev, &viewport); - viewport.dvMinZ = 0; - viewport.dvMaxZ = 0.3; - pD3DDev->lpVtbl->SetViewport(pD3DDev, &viewport); -} - - for(i = 0;; i++) - { - Alias_GAliasBuildMesh(&mesh, inf, e, e->shaderRGBAf[3], false); - - skin = D3D7_ChooseSkin(inf, m->name, e->skinnum, e); - if (!skin) - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, NULL); - else - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, skin->base); - D3D_DrawMesh(&mesh); - - if (inf->nextsurf == 0) - break; - inf = (galiasinfo_t*)((char*)inf + inf->nextsurf); - } - -if (e->flags & Q2RF_DEPTHHACK) -{ - D3DVIEWPORT7 viewport; - pD3DDev->lpVtbl->GetViewport(pD3DDev, &viewport); - viewport.dvMinZ = 0; - viewport.dvMaxZ = 1; - pD3DDev->lpVtbl->SetViewport(pD3DDev, &viewport); -} - - { - float matrix[16]; - Matrix4_Identity(matrix); - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)matrix); - } -} -#endif diff --git a/engine/d3d7/d3d7_rmain.c b/engine/d3d7/d3d7_rmain.c deleted file mode 100644 index ee35e1e24..000000000 --- a/engine/d3d7/d3d7_rmain.c +++ /dev/null @@ -1,1455 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "d3dquake.h" -#include "glquake.h" -#include "renderque.h" - -extern mleaf_t *r_viewleaf, *r_oldviewleaf; -extern mleaf_t *r_viewleaf2, *r_oldviewleaf2; -extern int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2; -extern qbyte areabits[MAX_Q2MAP_AREAS/8]; - - -int r_visframecount; -entity_t r_worldentity; -refdef_t r_refdef; -vec3_t r_origin, vpn, vright, vup; -extern float r_projection_matrix[16]; -extern float r_view_matrix[16]; - - -//mplane_t frustum[4]; - -vec3_t modelorg; - -entity_t *currententity; -extern cvar_t gl_mindist; - - -void (D3D7_R_DeInit) (void) -{ -} -void (D3D7_R_ReInit) (void) -{ -} -void (D3D7_R_Init) (void) -{ - D3D7_R_ReInit(); -} - -//most of this is a direct copy from gl -void (D3D7_SetupFrame) (void) -{ - mleaf_t *leaf; - vec3_t temp; - - GLR_AnimateLight(); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); - VectorCopy (r_refdef.vieworg, r_origin); - r_framecount++; - - r_oldviewleaf = r_viewleaf; - r_oldviewleaf2 = r_viewleaf2; - r_viewleaf = GLMod_PointInLeaf (cl.worldmodel, r_origin); - - if (!r_viewleaf) - { - } - else if (r_viewleaf->contents == Q1CONTENTS_EMPTY) - { //look down a bit - VectorCopy (r_origin, temp); - temp[2] -= 16; - leaf = GLMod_PointInLeaf (cl.worldmodel, temp); - if (leaf->contents <= Q1CONTENTS_WATER && leaf->contents >= Q1CONTENTS_LAVA) - r_viewleaf2 = leaf; - else - r_viewleaf2 = NULL; - } - else if (r_viewleaf->contents <= Q1CONTENTS_WATER && r_viewleaf->contents >= Q1CONTENTS_LAVA) - { //in water, look up a bit. - - VectorCopy (r_origin, temp); - temp[2] += 16; - leaf = GLMod_PointInLeaf (cl.worldmodel, temp); - if (leaf->contents == Q1CONTENTS_EMPTY) - r_viewleaf2 = leaf; - else - r_viewleaf2 = NULL; - } - else - r_viewleaf2 = NULL; - - if (r_viewleaf) - V_SetContentsColor (r_viewleaf->contents); -} - -void D3D7_SetupViewPort(void) -{ - float screenaspect; - int glwidth = vid.width, glheight=vid.height; - int x, x2, y2, y, w, h; - - float fov_x, fov_y; - - D3DVIEWPORT7 vport; - - D3D7_GetBufferSize(&glwidth, &glheight); - - // - // set up viewpoint - // - x = r_refdef.vrect.x * glwidth/(int)vid.width; - x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/(int)vid.width; - y = (/*vid.height-*/r_refdef.vrect.y) * glheight/(int)vid.height; - y2 = ((int)/*vid.height - */(r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/(int)vid.height; - - // fudge around because of frac screen scale - if (x > 0) - x--; - if (x2 < glwidth) - x2++; - if (y < 0) - y--; - if (y2 < glheight) - y2++; - - w = x2 - x; - h = y2 - y; - -/* if (envmap) - { - x = y2 = 0; - w = h = 256; - } -*/ - - vport.dwX = x; - vport.dwY = y; - vport.dwWidth = w; - vport.dwHeight = h; - vport.dvMinZ = 0; - vport.dvMaxZ = 1; - pD3DDev->lpVtbl->SetViewport(pD3DDev, &vport); - - fov_x = r_refdef.fov_x;//+sin(cl.time)*5; - fov_y = r_refdef.fov_y;//-sin(cl.time+1)*5; - - if (r_waterwarp.value<0 && r_viewleaf->contents <= Q1CONTENTS_WATER) - { - fov_x *= 1 + (((sin(cl.time * 4.7) + 1) * 0.015) * r_waterwarp.value); - fov_y *= 1 + (((sin(cl.time * 3.0) + 1) * 0.015) * r_waterwarp.value); - } - - screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height; -// if (r_refdef.useperspective) - { -/* if ((!r_shadows.value || !gl_canstencil) && gl_maxdist.value>256)//gl_nv_range_clamp) - { - // yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI; - // yfov = (2.0 * tan (scr_fov.value/360*M_PI)) / screenaspect; - // yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*(scr_fov.value*2)/M_PI; - // MYgluPerspective (yfov, screenaspect, 4, 4096); - MYgluPerspective (fov_x, fov_y, gl_mindist.value, gl_maxdist.value); - } - else*/ - { - GL_InfinatePerspective(fov_x, fov_y, gl_mindist.value); - } - } -/* else - { - if (gl_maxdist.value>=1) - GL_ParallelPerspective(-fov_x/2, fov_x/2, fov_y/2, -fov_y/2, -gl_maxdist.value, gl_maxdist.value); - else - GL_ParallelPerspective(0, r_refdef.vrect.width, 0, r_refdef.vrect.height, -9999, 9999); - }*/ - - Matrix4_ModelViewMatrixFromAxis(r_view_matrix, vpn, vright, vup, r_refdef.vieworg); - - - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX*)r_projection_matrix); - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_VIEW, (D3DMATRIX*)r_view_matrix); - - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE); -} - - - - - - -qbyte *Q1BSP_LeafPVS (model_t *model, mleaf_t *leaf, qbyte *buffer); - - - -//fixme: direct copy from gl (apart from lightmaps) -static void D3D7_RecursiveWorldNode (mnode_t *node) -{ - int c, side; - mplane_t *plane; - msurface_t *surf, **mark; - mleaf_t *pleaf; - double dot; - int shift; - -start: - - if (node->contents == Q1CONTENTS_SOLID) - return; // solid - - if (node->visframe != r_visframecount) - return; - if (R_CullBox (node->minmaxs, node->minmaxs+3)) - return; - -// if a leaf node, draw stuff - if (node->contents < 0) - { - pleaf = (mleaf_t *)node; - - mark = pleaf->firstmarksurface; - c = pleaf->nummarksurfaces; - - if (c) - { - do - { - (*mark++)->visframe = r_framecount; - } while (--c); - } - - // deal with model fragments in this leaf - if (pleaf->efrags) - R_StoreEfrags (&pleaf->efrags); - return; - } - -// node is just a decision point, so go down the apropriate sides - -// find which side of the node we are on - plane = node->plane; - - switch (plane->type) - { - case PLANE_X: - dot = modelorg[0] - plane->dist; - break; - case PLANE_Y: - dot = modelorg[1] - plane->dist; - break; - case PLANE_Z: - dot = modelorg[2] - plane->dist; - break; - default: - dot = DotProduct (modelorg, plane->normal) - plane->dist; - break; - } - - if (dot >= 0) - side = 0; - else - side = 1; - -// recurse down the children, front side first - D3D7_RecursiveWorldNode (node->children[side]); - -// draw stuff - c = node->numsurfaces; - - if (c) - { - surf = cl.worldmodel->surfaces + node->firstsurface; - - shift = 0;//GLR_LightmapShift(cl.worldmodel); - -// if (dot < 0 -BACKFACE_EPSILON) -// side = SURF_PLANEBACK; -// else if (dot > BACKFACE_EPSILON) -// side = 0; - { - for ( ; c ; c--, surf++) - { - if (surf->visframe != r_framecount) - continue; - -// if (((dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))) -// continue; // wrong side - - D3DR_RenderDynamicLightmaps (surf, shift); - // if sorting by texture, just store it out -/* if (surf->flags & SURF_DRAWALPHA) - { // add to the translucent chain - surf->nextalphasurface = r_alpha_surfaces; - r_alpha_surfaces = surf; - surf->ownerent = &r_worldentity; - } - else -*/ { - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; - } - } - } - } - -// recurse down the back side -// GLR_RecursiveWorldNode (node->children[!side]); - node = node->children[!side]; - goto start; -} - -struct { - float x, y, z; -// unsigned colour; - float wms, wmt; - float lms, lmt; -} worldvert[64]; -void D3D7_DrawTextureChains(void) -{ - texture_t *t; - msurface_t *s; - vec3_t *xyz; - vec2_t *wm; - vec2_t *lm; - mesh_t *m; - int i; - int v; - int lmnum; - extern int skytexturenum; // index in cl.loadmodel, not gl texture object - - if (skytexturenum>=0) - { - t = currentmodel->textures[skytexturenum]; - if (t) - { - s = t->texturechain; - if (s) - { - t->texturechain = NULL; - D3D7_DrawSkyChain (s); - } - } - } - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - for (i = 0; i < currentmodel->numtextures; i++) - { - t = currentmodel->textures[i]; - if (!t) - continue; //happens on e1m2 - s = t->texturechain; - if (!s) - continue; - t->texturechain = NULL; - -pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, (LPDIRECTDRAWSURFACE7)t->tn.base); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_TEXCOORDINDEX, 0); - -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); -pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - - while(s) - { - m = s->mesh; - if (m) - { - - lmnum = s->lightmaptexturenum; - if (lmnum >= 0) - { - if (lightmap[lmnum]->modified) - { - DDSURFACEDESC2 desc; - - desc.dwSize = sizeof(desc); - lightmap_d3dtextures[lmnum]->lpVtbl->Lock(lightmap_d3dtextures[lmnum], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[lmnum]->lightmaps, LMBLOCK_WIDTH*LMBLOCK_HEIGHT*4); - /* { - int i; - unsigned char *c; - unsigned char v; - c = desc.lpSurface; - for (i = 0; i < LMBLOCK_WIDTH*LMBLOCK_HEIGHT; i++) - { - v = rand(); - *c++ = v; - *c++ = v; - *c++ = v; - c++; - } - }*/ - lightmap_d3dtextures[lmnum]->lpVtbl->Unlock(lightmap_d3dtextures[lmnum], NULL); - - lightmap[lmnum]->modified = false; - } - - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 1, (LPDIRECTDRAWSURFACE7)lightmap_d3dtextures[lmnum]); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLORARG2, D3DTA_CURRENT); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_MODULATE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_TEXCOORDINDEX, 1); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - } - else - { - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - } - -//pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - - xyz = m->xyz_array; - wm = m->st_array; - lm = m->lmst_array; - - for (v = 0; v < m->numvertexes; v++, xyz++, wm++, lm++) - { - worldvert[v].x = (*xyz)[0]; - worldvert[v].y = (*xyz)[1]; - worldvert[v].z = (*xyz)[2]; -// worldvert[v].colour = 0; - worldvert[v].wms = (*wm)[0]; - worldvert[v].wmt = (*wm)[1]; - worldvert[v].lms = (*lm)[0]; - worldvert[v].lmt = (*lm)[1]; - } - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_TEX2, worldvert, m->numvertexes, m->indexes, m->numindexes, 0); - } - s = s->texturechain; - } - } - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); -} - -void D3D7_BaseBModelTextures(entity_t *e) -{ - texture_t *t; - msurface_t *s; - vec3_t *xyz; - vec2_t *wm; - vec2_t *lm; - mesh_t *m; - int i; - int v; - float matrix[16]; - int lmnum = -1; - currentmodel = e->model; - - - for (s = currentmodel->surfaces+currentmodel->firstmodelsurface, i = 0; i < currentmodel->nummodelsurfaces; i++, s++) - { - t = R_TextureAnimation(s->texinfo->texture); - - { - m = s->mesh; - if (m) - D3DR_RenderDynamicLightmaps (s, 0); - } - } - - - - Matrix4_ModelMatrixFromAxis(matrix, e->axis[0], e->axis[1], e->axis[2], e->origin); - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)matrix); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - for (s = currentmodel->surfaces+currentmodel->firstmodelsurface, i = 0; i < currentmodel->nummodelsurfaces; i++, s++) - { - t = R_TextureAnimation(s->texinfo->texture); - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, (LPDIRECTDRAWSURFACE7)t->tn.base); - pD3DDev->lpVtbl->SetTexture(pD3DDev, 1, (LPDIRECTDRAWSURFACE7)lightmap_d3dtextures[s->lightmaptexturenum]); - { - m = s->mesh; - if (m) - { - - if (lmnum != s->lightmaptexturenum) - { - lmnum = s->lightmaptexturenum; - if (lmnum >= 0) - { - if (lightmap[lmnum]->modified) - { - DDSURFACEDESC2 desc; - - desc.dwSize = sizeof(desc); - lightmap_d3dtextures[lmnum]->lpVtbl->Lock(lightmap_d3dtextures[lmnum], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[lmnum]->lightmaps, LMBLOCK_WIDTH*LMBLOCK_HEIGHT*4); - /* { - int i; - unsigned char *c; - unsigned char v; - c = desc.lpSurface; - for (i = 0; i < LMBLOCK_WIDTH*LMBLOCK_HEIGHT; i++) - { - v = rand(); - *c++ = v; - *c++ = v; - *c++ = v; - c++; - } - }*/ - lightmap_d3dtextures[lmnum]->lpVtbl->Unlock(lightmap_d3dtextures[lmnum], NULL); - - lightmap[lmnum]->modified = false; - } - - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 1, (LPDIRECTDRAWSURFACE7)lightmap_d3dtextures[lmnum]); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLORARG2, D3DTA_CURRENT); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_MODULATE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_TEXCOORDINDEX, 1); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - } - else - { - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - } - } - - - - xyz = m->xyz_array; - wm = m->st_array; - lm = m->lmst_array; - - for (v = 0; v < m->numvertexes; v++, xyz++, wm++, lm++) - { - worldvert[v].x = (*xyz)[0]; - worldvert[v].y = (*xyz)[1]; - worldvert[v].z = (*xyz)[2]; -// worldvert[v].colour = 0; - worldvert[v].wms = (*wm)[0]; - worldvert[v].wmt = (*wm)[1]; - worldvert[v].lms = (*lm)[0]; - worldvert[v].lmt = (*lm)[1]; - } - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_TEX2, worldvert, m->numvertexes, m->indexes, m->numindexes, 0); - } - } - } - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - - - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)matrix); -} - - - -typedef struct { - float pos[3]; - int colour; - float tc[2]; -} d3dvert_t; -/* -================ -R_GetSpriteFrame -================ -*/ -/* -mspriteframe_t *R_GetSpriteFrame (entity_t *currententity) -{ - msprite_t *psprite; - mspritegroup_t *pspritegroup; - mspriteframe_t *pspriteframe; - int i, numframes, frame; - float *pintervals, fullinterval, targettime, time; - - psprite = currententity->model->cache.data; - frame = currententity->frame; - - if ((frame >= psprite->numframes) || (frame < 0)) - { - Con_DPrintf ("R_DrawSprite: no such frame %d (%s)\n", frame, currententity->model->name); - frame = 0; - } - - if (psprite->frames[frame].type == SPR_SINGLE) - { - pspriteframe = psprite->frames[frame].frameptr; - } - else if (psprite->frames[frame].type == SPR_ANGLED) - { - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - pspriteframe = pspritegroup->frames[(int)((r_refdef.viewangles[1]-currententity->angles[1])/360*8 + 0.5-4)&7]; - } - else - { - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - pintervals = pspritegroup->intervals; - numframes = pspritegroup->numframes; - fullinterval = pintervals[numframes-1]; - - time = currententity->frame1time; - - // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values - // are positive, so we don't have to worry about division by 0 - targettime = time - ((int)(time / fullinterval)) * fullinterval; - - for (i=0 ; i<(numframes-1) ; i++) - { - if (pintervals[i] > targettime) - break; - } - - pspriteframe = pspritegroup->frames[i]; - } - - return pspriteframe; -} -*/ -static void D3D7_DrawSpriteModel (entity_t *e) -{ - vec3_t point; - mspriteframe_t *frame; - vec3_t forward, right, up; - msprite_t *psprite; - - d3dvert_t d3dvert[4]; - index_t vertindexes[6] = { - 0, 1, 2, - 0, 2, 3 - }; - - if (!e->model) - return; - - if (e->flags & RF_NODEPTHTEST) - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS); - - // don't even bother culling, because it's just a single - // polygon without a surface cache - frame = R_GetSpriteFrame (e); - psprite = e->model->cache.data; -// frame = 0x05b94140; - - switch(psprite->type) - { - case SPR_ORIENTED: - // bullet marks on walls - AngleVectors (e->angles, forward, right, up); - break; - - case SPR_FACING_UPRIGHT: - up[0] = 0;up[1] = 0;up[2]=1; - right[0] = e->origin[1] - r_origin[1]; - right[1] = -(e->origin[0] - r_origin[0]); - right[2] = 0; - VectorNormalize (right); - break; - case SPR_VP_PARALLEL_UPRIGHT: - up[0] = 0;up[1] = 0;up[2]=1; - VectorCopy (vright, right); - break; - - default: - case SPR_VP_PARALLEL: - //normal sprite - VectorCopy(vup, up); - VectorCopy(vright, right); - break; - } - up[0]*=e->scale; - up[1]*=e->scale; - up[2]*=e->scale; - right[0]*=e->scale; - right[1]*=e->scale; - right[2]*=e->scale; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, *(LPDIRECTDRAWSURFACE7*)frame->p.d.data); - -/* { - extern int gldepthfunc; - qglDepthFunc(gldepthfunc); - qglDepthMask(0); - if (gldepthmin == 0.5) - qglCullFace ( GL_BACK ); - else - qglCullFace ( GL_FRONT ); - - GL_TexEnv(GL_MODULATE); - - qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - qglDisable (GL_ALPHA_TEST); - qglDisable(GL_BLEND); - }*/ - -/* if (e->flags & Q2RF_ADDATIVE) - { - qglEnable(GL_BLEND); - qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - qglBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - else if (e->shaderRGBAf[3]<1 || gl_blendsprites.value) - { - qglEnable(GL_BLEND); - qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } - else - qglEnable (GL_ALPHA_TEST); -*/ - - d3dvert[0].colour = 0xffffffff; - d3dvert[0].tc[0] = 0; - d3dvert[0].tc[1] = 1; - VectorMA (e->origin, frame->down, up, point); - VectorMA (point, frame->left, right, d3dvert[0].pos); - - d3dvert[1].colour = 0xffffffff; - d3dvert[1].tc[0] = 0; - d3dvert[1].tc[0] = 0; - VectorMA (e->origin, frame->up, up, point); - VectorMA (point, frame->left, right, d3dvert[1].pos); - - d3dvert[2].colour = 0xffffffff; - d3dvert[2].tc[0] = 1; - d3dvert[2].tc[1] = 0; - VectorMA (e->origin, frame->up, up, point); - VectorMA (point, frame->right, right, d3dvert[2].pos); - - d3dvert[3].colour = 0xffffffff; - d3dvert[3].tc[0] = 1; - d3dvert[3].tc[1] = 1; - VectorMA (e->origin, frame->down, up, point); - VectorMA (point, frame->right, right, d3dvert[3].pos); - - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLEFAN, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dvert, 4, vertindexes, 6, 0); - - - if (e->flags & RF_NODEPTHTEST) - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL); - -// if (e->flags & Q2RF_ADDATIVE) //back to regular blending for us! -// qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} - -//================================================================================== - -void D3D7R_DrawSprite(int count, void **e, void *parm) -{ - while(count--) - { - currententity = *e++; - - D3D7_DrawSpriteModel (currententity); - } -} - - -qboolean D3D7_ShouldDraw(void) -{ - { - if (currententity->flags & Q2RF_EXTERNALMODEL) - return false; -// if (currententity->keynum == (cl.viewentity[r_refdef.currentplayernum]?cl.viewentity[r_refdef.currentplayernum]:(cl.playernum[r_refdef.currentplayernum]+1))) -// return false; -// if (cl.viewentity[r_refdef.currentplayernum] && currententity->keynum == cl.viewentity[r_refdef.currentplayernum]) -// continue; - if (!Cam_DrawPlayer(r_refdef.currentplayernum, currententity->keynum-1)) - return false; - } - return true; -} - - -void D3D7R_DrawEntitiesOnList (void) -{ - int i; - - if (!r_drawentities.value) - return; - - // draw sprites seperately, because of alpha blending - for (i=0 ; irtype) - { - case RT_SPRITE: - RQ_AddDistReorder(D3D7R_DrawSprite, currententity, NULL, currententity->origin); - continue; -#ifdef Q3SHADERS - case RT_BEAM: - case RT_RAIL_RINGS: - case RT_LIGHTNING: - R_DrawLightning(currententity); - continue; - case RT_RAIL_CORE: - R_DrawRailCore(currententity); - continue; -#endif - case RT_MODEL: //regular model - break; - case RT_PORTALSURFACE: - continue; //this doesn't do anything anyway, does it? - default: - case RT_POLY: //these are a little painful, we need to do them some time... just not yet. - continue; - } - if (currententity->flags & Q2RF_BEAM) - { -// R_DrawBeam(currententity); - continue; - } - if (!currententity->model) - continue; - - - if (cl.lerpents && (cls.allow_anyparticles || currententity->visframe)) //allowed or static - { -/* if (gl_part_flame.value) - { - if (currententity->model->engineflags & MDLF_ENGULPHS) - continue; - }*/ - } - - switch (currententity->model->type) - { - - case mod_alias: -// if (r_refdef.flags & Q2RDF_NOWORLDMODEL || !cl.worldmodel || cl.worldmodel->type != mod_brush || cl.worldmodel->fromgame == fg_doom) - D3D7_DrawAliasModel (); - break; - -#ifdef HALFLIFEMODELS - case mod_halflife: - R_DrawHLModel (currententity); - break; -#endif - - case mod_brush: -// if (!cl.worldmodel || cl.worldmodel->type != mod_brush || cl.worldmodel->fromgame == fg_doom) - D3D7_BaseBModelTextures (currententity); - break; - - case mod_sprite: - RQ_AddDistReorder(D3D7R_DrawSprite, currententity, NULL, currententity->origin); - break; -/* -#ifdef TERRAIN - case mod_heightmap: - D3D_DrawHeightmapModel(currententity); - break; -#endif -*/ - default: - break; - } - } - - { - float m_identity[16] = { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - }; - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)m_identity); - } -} - -void D3D7_DrawWorld(void) -{ - RSpeedLocals(); - entity_t ent; - - memset (&ent, 0, sizeof(ent)); - ent.model = cl.worldmodel; - currentmodel = cl.worldmodel; - - VectorCopy (r_refdef.vieworg, modelorg); - - currententity = &ent; -#ifdef TERRAIN -// FIXME: Dunno what needs to be fixed here? -// if (currentmodel->type == mod_heightmap) -// D3D_DrawHeightmapModel(currententity); -// else -#endif - { -// qglColor3f (1,1,1); - - RSpeedRemark(); -/* -#ifdef Q2BSPS - if (ent.model->fromgame == fg_quake2 || ent.model->fromgame == fg_quake3) - { - int leafnum; - int clientarea; -#ifdef QUAKE2 - if (cls.protocol == CP_QUAKE2) //we can get server sent info - memcpy(areabits, cl.q2frame.areabits, sizeof(areabits)); - else -#endif - { //generate the info each frame. - leafnum = CM_PointLeafnum (cl.worldmodel, r_refdef.vieworg); - clientarea = CM_LeafArea (cl.worldmodel, leafnum); - CM_WriteAreaBits(cl.worldmodel, areabits, clientarea); - } -#ifdef Q3BSPS - if (ent.model->fromgame == fg_quake3) - { - R_MarkLeaves_Q3 (); - D3D7_LeafWorldNode (); - } - else -#endif - { - R_MarkLeaves_Q2 (); - D3D7_RecursiveQ2WorldNode (cl.worldmodel->nodes); - } - } - else -#endif -*/ - { - R_MarkLeaves_Q1 (); - D3D7_RecursiveWorldNode (cl.worldmodel->nodes); - } - - RSpeedEnd(RSPEED_WORLDNODE); - TRACE(("dbg: calling PPL_DrawWorld\n")); -// if (r_shadows.value >= 2 && gl_canstencil && gl_mtexable) - D3D7_DrawTextureChains(); -// else -// DrawTextureChains (cl.worldmodel, 1, r_refdef.vieworg); - - -//qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - -// GLR_LessenStains(); - } -} - -void D3D7_R_RenderScene(void) -{ - if (!cl.worldmodel || (!cl.worldmodel->nodes && cl.worldmodel->type != mod_heightmap)) - r_refdef.flags |= Q2RDF_NOWORLDMODEL; - - if (!(r_refdef.flags & Q2RDF_NOWORLDMODEL)) - { - D3D7_DrawWorld (); // adds static entities to the list - } - - D3D7R_DrawEntitiesOnList (); - - P_DrawParticles(); -} - -void (D3D7_R_RenderView) (void) -{ - D3D7_SetupFrame(); - D3D7_SetupViewPort(); - R_SetFrustum(); - D3D7_R_RenderScene(); -} - - - - -#ifdef PSET_SCRIPT - -#include "particles.h" -#define TYPESONLY -#include "p_script.c" - -#define APPLYD3DBLEND(bm) \ - switch (bm) \ - { \ - case BM_ADD: \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE); \ - break; \ - case BM_SUBTRACT: \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCCOLOR); \ - break; \ - case BM_BLENDCOLOUR: \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCCOLOR); \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCCOLOR); \ - break; \ - case BM_BLEND: \ - default: \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); \ - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); \ - break; \ - } - - -extern vec3_t pright, pup; -static float particletime; - -typedef struct d3dparticlevert_s { - float org[3]; - unsigned int colour; - float s, t; //these could actually be preinitialised -} d3dparticlevert_t; -static d3dparticlevert_t d3dparticlevert[4]; - -typedef struct d3dparticlevertut_s { - float org[3]; - unsigned int colour; -} d3dparticlevertut_t; -static d3dparticlevertut_t d3dparticlevertut[4]; - -static unsigned short d3dparticlevertindexes[] = -{ - 0, 1, 2, - 0, 2, 3 -}; - -static void D3D_DrawParticleBlob(int count, particle_t **plist, plooks_t *type) -{ - float scale; - float x; - float y; - unsigned int colour; - int cb, cg, cr, ca; - particle_t *p; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, type->d3dtexture); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - APPLYD3DBLEND(type->blendmode); - - while(count--) - { - p = *plist++; - - scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1] - + (p->org[2] - r_origin[2])*vpn[2]; - scale = (scale*p->scale)*(type->invscalefactor) + p->scale * (type->scalefactor*250); - if (scale < 20) - scale = 0.25; - else - scale = 0.25 + scale * 0.001; - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - if (p->angle) - { - x = sin(p->angle)*scale; - y = cos(p->angle)*scale; - } - else - { - x = 0; - y = scale; - } - d3dparticlevert[0].s = 0; - d3dparticlevert[0].t = 0; - d3dparticlevert[0].colour = colour; - d3dparticlevert[0].org[0] = p->org[0] - x*pright[0] - y*pup[0]; - d3dparticlevert[0].org[1] = p->org[1] - x*pright[1] - y*pup[1]; - d3dparticlevert[0].org[2] = p->org[2] - x*pright[2] - y*pup[2]; - - d3dparticlevert[1].s = 0; - d3dparticlevert[1].t = 1; - d3dparticlevert[1].colour = colour; - d3dparticlevert[1].org[0] = p->org[0] - y*pright[0] + x*pup[0]; - d3dparticlevert[1].org[1] = p->org[1] - y*pright[1] + x*pup[1]; - d3dparticlevert[1].org[2] = p->org[2] - y*pright[2] + x*pup[2]; - - d3dparticlevert[2].s = 1; - d3dparticlevert[2].t = 1; - d3dparticlevert[2].colour = colour; - d3dparticlevert[2].org[0] = p->org[0] + x*pright[0] + y*pup[0]; - d3dparticlevert[2].org[1] = p->org[1] + x*pright[1] + y*pup[1]; - d3dparticlevert[2].org[2] = p->org[2] + x*pright[2] + y*pup[2]; - - d3dparticlevert[3].s = 1; - d3dparticlevert[3].t = 0; - d3dparticlevert[3].colour = colour; - d3dparticlevert[3].org[0] = p->org[0] + y*pright[0] - x*pup[0]; - d3dparticlevert[3].org[1] = p->org[1] + y*pright[1] - x*pup[1]; - d3dparticlevert[3].org[2] = p->org[2] + y*pright[2] - x*pup[2]; - - //FIXME: batch properly - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dparticlevert, 4, d3dparticlevertindexes, 6, 0); - } -} -static void D3D_DrawParticleSpark(int count, particle_t **plist, plooks_t *type) -{ - vec3_t v, crv, o2; - - unsigned int colour; - int cb, cg, cr, ca; - particle_t *p; - - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, type->d3dtexture); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - APPLYD3DBLEND(type->blendmode); - - - while(count--) - { - p = *plist++; - - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - - - VectorSubtract(r_refdef.vieworg, p->org, v); - CrossProduct(v, p->vel, crv); - VectorNormalize(crv); - - VectorMA(p->org, -p->scale/2, crv, d3dparticlevert[0].org); - d3dparticlevert[0].s = 0; - d3dparticlevert[0].t = 0; - d3dparticlevert[0].colour = colour; - - VectorMA(p->org, p->scale/2, crv, d3dparticlevert[1].org); - d3dparticlevert[1].s = 0; - d3dparticlevert[1].t = 1; - d3dparticlevert[1].colour = colour; - - - VectorMA(p->org, 0.1, p->vel, o2); - - VectorSubtract(r_refdef.vieworg, o2, v); - CrossProduct(v, p->vel, crv); - VectorNormalize(crv); - - VectorMA(o2, p->scale/2, crv, d3dparticlevert[2].org); - d3dparticlevert[2].s = 1; - d3dparticlevert[2].t = 1; - d3dparticlevert[2].colour = colour; - - VectorMA(o2, -p->scale/2, crv, d3dparticlevert[3].org); - d3dparticlevert[3].s = 1; - d3dparticlevert[3].t = 0; - d3dparticlevert[3].colour = colour; - - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dparticlevert, 4, d3dparticlevertindexes, 6, 0); - } -} -static void D3D_DrawParticleBeam(int count, beamseg_t **blist, plooks_t *type) -{ - vec3_t v; - vec3_t crv; - beamseg_t *b, *c; - particle_t *p; - particle_t *q; - float ts; - - - unsigned int colour; - int cb, cg, cr, ca; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, type->d3dtexture); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - APPLYD3DBLEND(type->blendmode); - - - - while(count--) - { - b = *blist++; - c = b->next; - q = c->p; - p = b->p; - - - cr = q->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = q->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = q->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = q->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - - - - c = b->next; - - q = c->p; - - p = b->p; - - VectorSubtract(r_refdef.vieworg, q->org, v); - VectorNormalize(v); - CrossProduct(c->dir, v, crv); - ts = c->texture_s*q->angle + particletime*q->rotationspeed; - - VectorMA(q->org, -q->scale, crv, d3dparticlevert[0].org); - d3dparticlevert[0].s = ts; - d3dparticlevert[0].t = 0; - d3dparticlevert[0].colour = colour; - - VectorMA(q->org, q->scale, crv, d3dparticlevert[1].org); - d3dparticlevert[1].s = ts; - d3dparticlevert[1].t = 1; - d3dparticlevert[1].colour = colour; - - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - VectorSubtract(r_refdef.vieworg, p->org, v); - VectorNormalize(v); - CrossProduct(b->dir, v, crv); // replace with old p->dir? - ts = b->texture_s*p->angle + particletime*p->rotationspeed; - - VectorMA(p->org, p->scale, crv, d3dparticlevert[2].org); - d3dparticlevert[2].s = ts; - d3dparticlevert[2].t = 1; - d3dparticlevert[2].colour = colour; - - VectorMA(p->org, -p->scale, crv, d3dparticlevert[3].org); - d3dparticlevert[3].s = ts; - d3dparticlevert[3].t = 0; - d3dparticlevert[3].colour = colour; - - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dparticlevert, 4, d3dparticlevertindexes, 6, 0); - } -} - -static void D3D_DrawParticleBeamUT(int count, beamseg_t **blist, plooks_t *type) -{ - vec3_t v; - vec3_t crv; - beamseg_t *b, *c; - particle_t *p; - particle_t *q; - float ts; - - - unsigned int colour; - int cb, cg, cr, ca; - -// D3D_DrawParticleBeam(b, type); -// return; - - pD3DDev->lpVtbl->SetTexture(pD3DDev, 0, NULL); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2); - - - APPLYD3DBLEND(type->blendmode); - - - while (count--) - { - b = *blist++; - - c = b->next; - q = c->p; - p = b->p; - - - cr = q->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = q->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = q->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = q->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - - - - c = b->next; - - q = c->p; - - p = b->p; - - VectorSubtract(r_refdef.vieworg, q->org, v); - VectorNormalize(v); - CrossProduct(c->dir, v, crv); - ts = c->texture_s*q->angle + particletime*q->rotationspeed; - - VectorMA(q->org, -q->scale, crv, d3dparticlevertut[0].org); - d3dparticlevertut[0].colour = colour; - - VectorMA(q->org, q->scale, crv, d3dparticlevertut[1].org); - d3dparticlevertut[1].colour = colour; - - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - VectorSubtract(r_refdef.vieworg, p->org, v); - VectorNormalize(v); - CrossProduct(b->dir, v, crv); // replace with old p->dir? - ts = b->texture_s*p->angle + particletime*p->rotationspeed; - - VectorMA(p->org, p->scale, crv, d3dparticlevertut[2].org); - d3dparticlevertut[2].colour = colour; - - VectorMA(p->org, -p->scale, crv, d3dparticlevertut[3].org); - d3dparticlevertut[3].colour = colour; - - - pD3DDev->lpVtbl->DrawIndexedPrimitive(pD3DDev, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE, d3dparticlevertut, 4, d3dparticlevertindexes, 6, 0); - } -} - -qboolean D3D7_DrawParticles(float ptime) -{ - RSpeedLocals(); - - if (!pD3DDev) - return false; - - particletime = ptime; - - PScript_DrawParticleTypes(D3D_DrawParticleBlob, D3D_DrawParticleSpark, D3D_DrawParticleSpark, D3D_DrawParticleSpark, D3D_DrawParticleBeam, D3D_DrawParticleBeamUT, NULL); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZWRITEENABLE, FALSE ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, FALSE ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); - - RSpeedRemark(); - RQ_RenderDistAndClear(); - RSpeedEnd(RSPEED_PARTICLESDRAW); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZWRITEENABLE, TRUE ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - return true; -} - -#endif -#endif \ No newline at end of file diff --git a/engine/d3d7/d3d7_rsurf.c b/engine/d3d7/d3d7_rsurf.c deleted file mode 100644 index 04dd8b2de..000000000 --- a/engine/d3d7/d3d7_rsurf.c +++ /dev/null @@ -1,1373 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "d3dquake.h" - -int numlightmaps; - -mvertex_t *r_pcurrentvertbase; - -LPDIRECTDRAWSURFACE7 *lightmap_d3dtextures; -LPDIRECTDRAWSURFACE7 *deluxmap_d3dtextures; -lightmapinfo_t **lightmap; - - - -void D3D7_BuildSurfaceDisplayList (msurface_t *fa) -{ - int i, lindex, lnumverts; - medge_t *pedges, *r_pedge; - int vertpage; - float *vec; - float s, t; - int lm; - - int size; - mesh_t *mesh; - -// reconstruct the polygon - pedges = currentmodel->edges; - lnumverts = fa->numedges; - vertpage = 0; - - - if (lnumverts<3) - return; //q3 map. - - size = sizeof(mesh_t) + sizeof(index_t)*(lnumverts-2)*3 + (sizeof(vec3_t) + sizeof(vec3_t) + 2*sizeof(vec2_t) + sizeof(byte_vec4_t))*lnumverts; - - fa->mesh = mesh = Hunk_Alloc(size); - mesh->xyz_array = (vec3_t*)(mesh + 1); - mesh->normals_array = (vec3_t*)(mesh->xyz_array + lnumverts); - mesh->st_array = (vec2_t*)(mesh->normals_array + lnumverts); - mesh->lmst_array = (vec2_t*)(mesh->st_array + lnumverts); - mesh->colors_array = (byte_vec4_t*)(mesh->lmst_array + lnumverts); - mesh->indexes = (index_t*)(mesh->colors_array + lnumverts); - - mesh->numindexes = (lnumverts-2)*3; - mesh->numvertexes = lnumverts; - mesh->patchWidth = mesh->patchHeight = 1; - - for (i=0 ; iindexes[i*3] = 0; - mesh->indexes[i*3+1] = i+1; - mesh->indexes[i*3+2] = i+2; - } - - for (i=0 ; isurfedges[fa->firstedge + i]; - - if (lindex > 0) - { - r_pedge = &pedges[lindex]; - vec = r_pcurrentvertbase[r_pedge->v[0]].position; - } - else - { - r_pedge = &pedges[-lindex]; - vec = r_pcurrentvertbase[r_pedge->v[1]].position; - } - - s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; - t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; - - VectorCopy (vec, mesh->xyz_array[i]); - mesh->xyz_array[i][3] = 1; - mesh->st_array[i][0] = s/fa->texinfo->texture->width; - mesh->st_array[i][1] = t/fa->texinfo->texture->height; - - s -= fa->texturemins[0]; - lm = s*fa->light_t; - s += fa->light_s*16; - s += 8; - s /= LMBLOCK_WIDTH*16; - - t -= fa->texturemins[1]; - lm += t; - t += fa->light_t*16; - t += 8; - t /= LMBLOCK_HEIGHT*16; - - mesh->lmst_array[i][0] = s; - mesh->lmst_array[i][1] = t; - - if (fa->flags & SURF_PLANEBACK) - VectorNegate(fa->plane->normal, mesh->normals_array[i]); - else - VectorCopy(fa->plane->normal, mesh->normals_array[i]); - - mesh->colors_array[i][0] = 255; - mesh->colors_array[i][1] = 255; - mesh->colors_array[i][2] = 255; - mesh->colors_array[i][3] = 255; - } -} - - - - - - - -#define MAX_LIGHTMAP_SIZE 18 - -vec3_t blocknormals[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -unsigned greenblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blueblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -void D3D7R_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift) -{ - int smax, tmax; - int t; - int i, j, size; - qbyte *lightmap; - unsigned scale; - int maps; - unsigned *bl; - qboolean isstained; - extern cvar_t r_ambient; - extern cvar_t gl_lightmap_shift; - - unsigned *blg; - unsigned *blb; - - int r, g, b; - int cr, cg, cb; - - int stride = LMBLOCK_WIDTH*lightmap_bytes; - - shift += 7; // increase to base value - surf->cached_dlight = (surf->dlightframe == r_framecount); - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - size = smax*tmax; - lightmap = surf->samples; - - if (size > MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE) - { //fixme: fill in? - Con_Printf("Lightmap too large\n"); - return; - } - -// if (currentmodel->deluxdata) -// GLR_BuildDeluxMap(surf, deluxdest); - - - - if (true) - { - // set to full bright if no light data - if (r_fullbright.value>0) //not qw - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - goto store; - } - if (!currentmodel->lightdata) - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - goto store; - } - -// clear to no light - t = r_ambient.value*255; - for (i=0 ; ifromgame == fg_quake3) //rgb - { - /* for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) //no light styles in q3 apparently. - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - } - */ - for (i = 0; i < tmax; i++) //q3 maps store their light in a block fashion, q1/q2/hl store it in a linear fashion. - { - for (j = 0; j < smax; j++) - { - blocklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3]; - greenblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+1]; - blueblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+2]; - } - } -// memset(blocklights, 255, sizeof(blocklights)); - } - else if (currentmodel->engineflags & MDLF_RGBLIGHTING) //rgb - { - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - else - { - // set to full bright if no light data - if (r_fullbright.value || !currentmodel->lightdata) - { - for (i=0 ; iengineflags & MDLF_RGBLIGHTING) //rgb - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]/3; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLights (surf); - } - -// bound, invert, and shift -store: -#define INVERTLIGHTMAPS -#ifdef INVERTLIGHTMAPS - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -//*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#else - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 255; - else if (t < 0) - dest[0] = 0; - else - dest[0] = t; - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 255; - else if (t < 0) - dest[1] = 0; - else - dest[1] = t; - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 255; - else if (t < 0) - dest[2] = 0; - else - dest[2] = t; - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 255; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#endif -} - - - -int D3D7FillBlock (int texnum, int w, int h, int x, int y) -{ - int i, l; - while (texnum >= numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap[numlightmaps+0] = 0; - lightmap[numlightmaps+1] = 0; - lightmap[numlightmaps+2] = 0; - lightmap[numlightmaps+3] = 0; - - lightmap_d3dtextures = BZ_Realloc(lightmap_d3dtextures, sizeof(*lightmap_d3dtextures)*(numlightmaps+4)); - lightmap_d3dtextures[numlightmaps+0] = 0; - lightmap_d3dtextures[numlightmaps+1] = 0; - lightmap_d3dtextures[numlightmaps+2] = 0; - lightmap_d3dtextures[numlightmaps+3] = 0; - - deluxmap_d3dtextures = BZ_Realloc(deluxmap_d3dtextures, sizeof(*deluxmap_d3dtextures)*(numlightmaps+4)); - deluxmap_d3dtextures[numlightmaps+0] = 0; - deluxmap_d3dtextures[numlightmaps+1] = 0; - deluxmap_d3dtextures[numlightmaps+2] = 0; - deluxmap_d3dtextures[numlightmaps+3] = 0; - numlightmaps+=4; - } - for (i = texnum; i >= 0; i--) - { - if (!lightmap[i]) - { - lightmap[i] = BZ_Malloc(sizeof(*lightmap[i])); - for (l=0 ; lallocated[l] = LMBLOCK_HEIGHT; - } - - //maybe someone screwed with my lightmap... - memset(lightmap[i]->lightmaps, 255, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); - if (cl.worldmodel->lightdata) - memcpy(lightmap[i]->lightmaps, cl.worldmodel->lightdata+3*LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*i, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); - - } - else - break; - } - return texnum; -} - -int D3D7_AllocBlock (int w, int h, int *x, int *y) -{ - int i, j; - int best, best2; - int texnum; - - for (texnum=0 ; ; texnum++) - { - if (texnum == numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap[numlightmaps+0] = 0; - lightmap[numlightmaps+1] = 0; - lightmap[numlightmaps+2] = 0; - lightmap[numlightmaps+3] = 0; - - lightmap_d3dtextures = BZ_Realloc(lightmap_d3dtextures, sizeof(*lightmap_d3dtextures)*(numlightmaps+4)); - lightmap_d3dtextures[numlightmaps+0] = 0; - lightmap_d3dtextures[numlightmaps+1] = 0; - lightmap_d3dtextures[numlightmaps+2] = 0; - lightmap_d3dtextures[numlightmaps+3] = 0; - - deluxmap_d3dtextures = BZ_Realloc(deluxmap_d3dtextures, sizeof(*deluxmap_d3dtextures)*(numlightmaps+4)); - deluxmap_d3dtextures[numlightmaps+0] = 0; - deluxmap_d3dtextures[numlightmaps+1] = 0; - deluxmap_d3dtextures[numlightmaps+2] = 0; - deluxmap_d3dtextures[numlightmaps+3] = 0; - numlightmaps+=4; - } - if (!lightmap[texnum]) - { - lightmap[texnum] = Z_Malloc(sizeof(*lightmap[texnum])); - // reset stainmap since it now starts at 255 - memset(lightmap[texnum]->stainmaps, 255, sizeof(lightmap[texnum]->stainmaps)); - } - - - best = LMBLOCK_HEIGHT; - - for (i=0 ; iallocated[i+j] >= best) - break; - if (lightmap[texnum]->allocated[i+j] > best2) - best2 = lightmap[texnum]->allocated[i+j]; - } - if (j == w) - { // this is a valid spot - *x = i; - *y = best = best2; - } - } - - if (best + h > LMBLOCK_HEIGHT) - continue; - - for (i=0 ; iallocated[*x + i] = best + h; - - return texnum; - } - - Sys_Error ("AllocBlock: full"); - return 0; -} - - -void D3D7_CreateSurfaceLightmap (msurface_t *surf, int shift) -{ - int smax, tmax; - qbyte *base, *luxbase; stmap *stainbase; - - if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB)) - surf->lightmaptexturenum = -1; - if (surf->texinfo->flags & TEX_SPECIAL) - surf->lightmaptexturenum = -1; - if (surf->lightmaptexturenum<0) - return; - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - - if (smax > LMBLOCK_WIDTH || tmax > LMBLOCK_HEIGHT || smax < 0 || tmax < 0) - { //whoa, buggy. - surf->lightmaptexturenum = -1; - return; - } - - if (currentmodel->fromgame == fg_quake3) - D3D7FillBlock(surf->lightmaptexturenum, smax, tmax, surf->light_s, surf->light_t); - else - surf->lightmaptexturenum = D3D7_AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); - base = lightmap[surf->lightmaptexturenum]->lightmaps; - base += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - luxbase = lightmap[surf->lightmaptexturenum]->deluxmaps; - luxbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - stainbase = lightmap[surf->lightmaptexturenum]->stainmaps; - stainbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * 3; - - D3D7R_BuildLightMap (surf, base, luxbase, stainbase, shift); -} - - -void D3DR_RenderDynamicLightmaps (msurface_t *fa, int shift) -{ - qbyte *base, *luxbase; - stmap *stainbase; - int maps; - glRect_t *theRect; - int smax, tmax; - - if (!fa->mesh) - return; - -// c_brush_polys++; - - if (fa->lightmaptexturenum<0) - return; - - if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) ) - return; - - if (fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP)) - return; - - if (fa->texinfo->flags & (TEX_SPECIAL)) - { - if (cl.worldmodel->fromgame == fg_halflife) - return; //some textures do this. - } - -// fa->polys->chain = lightmap[fa->lightmaptexturenum]->polys; -// lightmap[fa->lightmaptexturenum]->polys = fa->polys; - - // check for lightmap modification -// if (cl.worldmodel->fromgame != fg_quake3) //no lightstyles on q3 maps - { - for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ; - maps++) - if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps] - || cl_lightstyle[fa->styles[maps]].colour != fa->cached_colour[maps] - ) - { - goto dynamic; - } - } - - if (fa->dlightframe == r_framecount // dynamic this frame - || fa->cached_dlight) // dynamic previously - { - RSpeedLocals(); -dynamic: - RSpeedRemark(); - - lightmap[fa->lightmaptexturenum]->modified = true; - - smax = (fa->extents[0]>>4)+1; - tmax = (fa->extents[1]>>4)+1; - - theRect = &lightmap[fa->lightmaptexturenum]->rectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - lightmap[fa->lightmaptexturenum]->deluxmodified = true; - theRect = &lightmap[fa->lightmaptexturenum]->deluxrectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - - base = lightmap[fa->lightmaptexturenum]->lightmaps; - base += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - luxbase = lightmap[fa->lightmaptexturenum]->deluxmaps; - luxbase += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - stainbase = lightmap[fa->lightmaptexturenum]->stainmaps; - stainbase += (fa->light_t * LMBLOCK_WIDTH + fa->light_s) * 3; - D3D7R_BuildLightMap (fa, base, luxbase, stainbase, shift); - - RSpeedEnd(RSPEED_DYNAMIC); - } -} - - - -LPDIRECTDRAWSURFACE7 D3D7_NewLightmap(void) -{ - DWORD tflags = D3DX_TEXTURE_NOMIPMAP; //for now - DWORD twidth = LMBLOCK_WIDTH; - DWORD theight = LMBLOCK_HEIGHT; - D3DX_SURFACEFORMAT tformat = D3DX_SF_A8R8G8B8; - LPDIRECTDRAWSURFACE7 newsurf; - DWORD nummips; - - D3DXCreateTexture(pD3DDev, &tflags, &twidth, &theight, &tformat, NULL, &newsurf, &nummips); - if (!newsurf) - return NULL; - - return newsurf; -} - -void D3D7_BuildLightmaps (void) -{ - DDSURFACEDESC2 desc; - - int i, j; - model_t *m; - int shift; - - r_framecount = 1; // no dlightcache -/* - for (i = 0; i < numlightmaps; i++) - { - if (!lightmap[i]) - break; - BZ_Free(lightmap[i]); - lightmap[i] = NULL; - } - - if (cl.worldmodel->fromgame == fg_doom) - return; //no lightmaps. - - if ((cl.worldmodel->engineflags & MDLF_RGBLIGHTING) || cl.worldmodel->deluxdata || r_loadlits.value) - gl_lightmap_format = GL_RGB; - else - gl_lightmap_format = GL_LUMINANCE; - - - if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA) - gl_lightmap_format = GL_RGB; - - - switch (gl_lightmap_format) - { - case GL_RGBA: - lightmap_bytes = 4; - break; - case GL_RGB: - lightmap_bytes = 3; - break; - case GL_LUMINANCE: - case GL_INTENSITY: - case GL_ALPHA: - lightmap_bytes = 1; - break; - } -*/ - for (j=1 ; jname[0] == '*') - continue; - - r_pcurrentvertbase = m->vertexes; - currentmodel = m; - shift = 0;//GLR_LightmapShift(currentmodel); - - for (i=0 ; inumsurfaces ; i++) - { - D3D7_CreateSurfaceLightmap (m->surfaces + i, shift); - P_EmitSkyEffectTris(m, &m->surfaces[i]); - if (m->surfaces[i].mesh) //there are some surfaces that have a display list already (the subdivided ones) - continue; - D3D7_BuildSurfaceDisplayList (m->surfaces + i); - } - } - - // - // upload all lightmaps that were filled - // - for (i=0 ; imodified = false; - lightmap[i]->rectchange.l = LMBLOCK_WIDTH; - lightmap[i]->rectchange.t = LMBLOCK_HEIGHT; - lightmap[i]->rectchange.w = 0; - lightmap[i]->rectchange.h = 0; - - if (!lightmap_d3dtextures[i]) - { - lightmap_d3dtextures[i] = D3D7_NewLightmap(); - - if (!lightmap_d3dtextures[i]) - { - Con_Printf("Couldn't create new lightmap\n"); - return; - } - } - - desc.dwSize = sizeof(desc); - lightmap_d3dtextures[i]->lpVtbl->Lock(lightmap_d3dtextures[i], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[i]->lightmaps, sizeof(lightmap[i]->lightmaps)); - /* memset(desc.lpSurface, 0, sizeof(lightmap[i]->lightmaps)); - { - int i; - unsigned char *c; - c = desc.lpSurface; - for (i = 0; i < sizeof(lightmap[i]->lightmaps); i++) - *c++ = rand(); - }*/ - lightmap_d3dtextures[i]->lpVtbl->Unlock(lightmap_d3dtextures[i], NULL); - - if (deluxmap_d3dtextures[i]) - { - deluxmap_d3dtextures[i]->lpVtbl->Lock(deluxmap_d3dtextures[i], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[i]->lightmaps, sizeof(lightmap[i]->deluxmaps)); - deluxmap_d3dtextures[i]->lpVtbl->Unlock(deluxmap_d3dtextures[i], NULL); - } - } - -} -#endif diff --git a/engine/d3d7/d3d7quake.h b/engine/d3d7/d3d7quake.h deleted file mode 100644 index fc995dbf2..000000000 --- a/engine/d3d7/d3d7quake.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef __D3DQUAKE_H__ -#define __D3DQUAKE_H__ - -#ifdef __GNUC__ -#define _inline static inline -#endif - -#include "ddraw.h" -#include "d3d.h" -#include "d3dx.h" -#include "glquake.h" - -void *D3D7_LoadTexture_32(char *name, unsigned int *data, int width, int height, int flags); -void *D3D7_LoadTexture_8_Pal24(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette, int transparentpix); -void *D3D7_LoadTexture_8_Pal32(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette); -/* -#define D3D9_LoadTexture8Pal32(skinname,width,height,data,palette,usemips,alpha) (int)D3D9_LoadTexture_8_Pal32(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP, host_basepal) -#define D3D9_LoadTexture(skinname,width,height,data,usemips,alpha) (int)D3D9_LoadTexture_8_Pal24(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP, host_basepal, 255) -#define D3D9_LoadTexture32(skinname,width,height,data,usemips,alpha) (int)D3D9_LoadTexture_32(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP) -#define D3D9_LoadTextureFB(skinname,width,height,data,usemips,alpha) 0 -#define D3D9_LoadTexture8Bump(skinname,width,height,data,usemips,alpha) 0 - -#define D3D9_FindTexture(name) -1 -#define D3D9_LoadCompressed(name) 0 -*/ - - -void *D3D9_LoadTexture_32(char *name, unsigned int *data, int width, int height, int flags); -void *D3D9_LoadTexture_8_Pal24(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette, int transparentpix); -void *D3D9_LoadTexture_8_Pal32(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette); - - -#define D3D_LoadTexture8Pal32(skinname,width,height,data,palette,usemips,alpha) (int)(pD3DDev?D3D7_LoadTexture_8_Pal32:D3D9_LoadTexture_8_Pal32)(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP, palette) -#define D3D_LoadTexture8Pal24(skinname,width,height,data,palette,usemips,alpha) (int)(pD3DDev?D3D7_LoadTexture_8_Pal24:D3D9_LoadTexture_8_Pal24)(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP, palette, 255) -#define D3D_LoadTexture(skinname,width,height,data,usemips,alpha) (int)(pD3DDev?D3D7_LoadTexture_8_Pal24:D3D9_LoadTexture_8_Pal24)(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP, host_basepal, 255) -#define D3D_LoadTexture32(skinname,width,height,data,usemips,alpha) (int)(pD3DDev?D3D7_LoadTexture_32:D3D9_LoadTexture_32)(skinname, data, width, height, (usemips?TF_MIPMAP:TF_NOMIPMAP) | (alpha?TF_ALPHA:TF_NOALPHA) | TF_NOTBUMPMAP) -#define D3D_LoadTextureFB(skinname,width,height,data,usemips,alpha) 0 -#define D3D_LoadTexture8Bump(skinname,width,height,data,usemips,alpha) 0 - -#define D3D_FindTexture(name) -1 -#define D3D_LoadCompressed(name) 0 - - - -extern LPDIRECT3DDEVICE7 pD3DDev; - -extern int d_lightstylevalue[256]; // 8.8 fraction of base light value - -#define lightmap_bytes 4 - - -extern int numlightmaps; - -extern mvertex_t *r_pcurrentvertbase; - -#ifndef LMBLOCK_WIDTH -#define LMBLOCK_WIDTH 128 -#define LMBLOCK_HEIGHT LMBLOCK_WIDTH -typedef struct glRect_s { - unsigned char l,t,w,h; -} glRect_t; -typedef unsigned char stmap; - -typedef struct { - qboolean modified; - qboolean deluxmodified; - glRect_t rectchange; - glRect_t deluxrectchange; - int allocated[LMBLOCK_WIDTH]; - qbyte lightmaps[4*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; - qbyte deluxmaps[4*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; //fixme: make seperate structure for easy disabling with less memory usage. - stmap stainmaps[3*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; //rgb no a. added to lightmap for added (hopefully) speed. -} lightmapinfo_t; -#endif - -extern LPDIRECTDRAWSURFACE7 *lightmap_d3dtextures; -extern LPDIRECTDRAWSURFACE7 *deluxmap_d3dtextures; -extern lightmapinfo_t **lightmap; - -extern void *d3dexplosiontexture; -extern void *d3dballtexture; - -#endif - diff --git a/engine/d3d7/vid_d3d7.c b/engine/d3d7/vid_d3d7.c deleted file mode 100644 index 3913f9300..000000000 --- a/engine/d3d7/vid_d3d7.c +++ /dev/null @@ -1,1139 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "winquake.h" -#include "d3dquake.h" -#include "glquake.h" - -#ifndef WM_XBUTTONDOWN - #define WM_XBUTTONDOWN 0x020B - #define WM_XBUTTONUP 0x020C -#endif -#ifndef MK_XBUTTON1 - #define MK_XBUTTON1 0x0020 -#endif -#ifndef MK_XBUTTON2 - #define MK_XBUTTON2 0x0040 -#endif -// copied from DarkPlaces in an attempt to grab more buttons -#ifndef MK_XBUTTON3 - #define MK_XBUTTON3 0x0080 -#endif -#ifndef MK_XBUTTON4 - #define MK_XBUTTON4 0x0100 -#endif -#ifndef MK_XBUTTON5 - #define MK_XBUTTON5 0x0200 -#endif -#ifndef MK_XBUTTON6 - #define MK_XBUTTON6 0x0400 -#endif -#ifndef MK_XBUTTON7 - #define MK_XBUTTON7 0x0800 -#endif - -#ifndef WM_INPUT - #define WM_INPUT 255 -#endif - - -int gl_bumpmappingpossible; - -static LPD3DXCONTEXT pD3DX; -static LPDIRECTDRAW7 pDD; -static LPDIRECT3D7 pD3D; -LPDIRECT3DDEVICE7 pD3DDev; -static LPDIRECTDRAWSURFACE7 pPrimary; -static LPDIRECTDRAWGAMMACONTROL pGammaControl; - - -static qboolean vid_initializing; - -extern qboolean scr_initialized; // ready to draw -extern qboolean scr_drawloading; - - -cvar_t vid_hardwaregamma; - - -HWND mainwindow; - -struct texture_s *r_notexture_mip; - -int r_framecount; - -mleaf_t *r_viewleaf; - -#define MAX_MOD_KNOWN 1024 -int mod_numknown; -model_t mod_known[MAX_MOD_KNOWN]; -model_t *loadmodel; -model_t *currentmodel; -char loadname[32]; -qbyte *mod_base; - -model_t *lightmodel; -int relitsurface; - -int window_center_x, window_center_y; -RECT window_rect; -int window_x, window_y; - -qboolean r_cache_thrash; // set if thrashing the surface cache - -mpic_t *draw_disc; // also used on sbar - -#if !defined(GLQUAKE) -qbyte GetPaletteIndex(int red, int green, int blue) -{ - //slow, horrible method. - { - int i, best=15; - int bestdif=256*256*256, curdif; - extern qbyte *host_basepal; - qbyte *pa; - - #define _abs(x) ((x)*(x)) - - pa = host_basepal; - for (i = 0; i < 256; i++, pa+=3) - { - curdif = _abs(red - pa[0]) + _abs(green - pa[1]) + _abs(blue - pa[2]); - if (curdif < bestdif) - { - if (curdif<1) - return i; - bestdif = curdif; - best = i; - } - } - return best; - } -} -#endif - -void BuildGammaTable (float g, float c); -void D3D7_VID_GenPaletteTables (unsigned char *palette) -{ - qbyte *pal; - unsigned r,g,b; - unsigned v; - unsigned short i; - unsigned *table; - extern qbyte gammatable[256]; - - if (palette) - { - BuildGammaTable(1, 1); - - // - // 8 8 8 encoding - // - if (vid_hardwaregamma.value) - { - // don't built in the gamma table - - pal = palette; - table = d_8to24rgbtable; - for (i=0 ; i<256 ; i++) - { - r = pal[0]; - g = pal[1]; - b = pal[2]; - pal += 3; - - // v = (255<<24) + (r<<16) + (g<<8) + (b<<0); - // v = (255<<0) + (r<<8) + (g<<16) + (b<<24); - v = (255<<24) + (r<<0) + (g<<8) + (b<<16); - *table++ = v; - } - d_8to24rgbtable[255] &= 0xffffff; // 255 is transparent - } - else - { - //computer has no hardware gamma (poor suckers) increase table accordingly - - pal = palette; - table = d_8to24rgbtable; - for (i=0 ; i<256 ; i++) - { - r = gammatable[pal[0]]; - g = gammatable[pal[1]]; - b = gammatable[pal[2]]; - pal += 3; - - // v = (255<<24) + (r<<16) + (g<<8) + (b<<0); - // v = (255<<0) + (r<<8) + (g<<16) + (b<<24); - v = (255<<24) + (r<<0) + (g<<8) + (b<<16); - *table++ = v; - } - d_8to24rgbtable[255] &= 0xffffff; // 255 is transparent - } - - if (LittleLong(1) != 1) - for (i=0 ; i<256 ; i++) - d_8to24rgbtable[i] = LittleLong(d_8to24rgbtable[i]); - } -} - - - - -void D3DMod_Think (void) -{ -} -void D3DMod_NowLoadExternal(void) -{ -} -void D3DMod_TouchModel (char *name) -{ -} -void *D3DMod_Extradata (struct model_s *mod) // handles caching -{ - return NULL; -} -struct model_s *D3DMod_FindName (char *name) -{ - return NULL; -} -struct model_s *D3DMod_ForName (char *name, qboolean crash) -{ - return NULL; -} -void D3DMod_ClearAll (void) -{ -} -void D3DMod_Init (void) -{ -} - - -typedef enum {MS_WINDOWED, MS_FULLSCREEN, MS_FULLDIB, MS_UNINIT} modestate_t; -static modestate_t modestate; - -qboolean D3DAppActivate(BOOL fActive, BOOL minimize) -/**************************************************************************** -* -* Function: AppActivate -* Parameters: fActive - True if app is activating -* -* Description: If the application is activating, then swap the system -* into SYSPAL_NOSTATIC mode so that our palettes will display -* correctly. -* -****************************************************************************/ -{ - static BOOL sound_active; - - if (ActiveApp == fActive && Minimized == minimize) - return false; //so windows doesn't crash us over and over again. - - ActiveApp = fActive; - Minimized = minimize; - -// enable/disable sound on focus gain/loss - if (!ActiveApp && sound_active) - { - S_BlockSound (); - sound_active = false; - } - else if (ActiveApp && !sound_active) - { - S_UnblockSound (); - sound_active = true; - } - - IN_UpdateGrabs(modestate != MS_WINDOWED, ActiveApp); - - if (fActive) - { - Cvar_ForceCallback(&v_gamma); - } - - if (!fActive) - { - Cvar_ForceCallback(&v_gamma); //wham bam thanks. - } - - return true; -} - - - - - -static LRESULT WINAPI D3D7_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - LONG lRet = 1; - int fActive, fMinimized, temp; - extern unsigned int uiWheelMessage; - - if ( uMsg == uiWheelMessage ) - uMsg = WM_MOUSEWHEEL; - - switch (uMsg) - { - case WM_KILLFOCUS: - if (modestate == MS_FULLDIB) - ShowWindow(mainwindow, SW_SHOWMINNOACTIVE); - break; - - case WM_CREATE: - break; - - case WM_MOVE: - GetWindowRect(mainwindow, &window_rect); - window_x = (int) LOWORD(lParam); - window_y = (int) HIWORD(lParam); -// VID_UpdateWindowStatus (); - break; - - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - if (!vid_initializing) - IN_TranslateKeyEvent(wParam, lParam, true, 0); - break; - - case WM_KEYUP: - case WM_SYSKEYUP: - if (!vid_initializing) - IN_TranslateKeyEvent(wParam, lParam, false, 0); - break; - - case WM_SYSCHAR: - // keep Alt-Space from happening - break; - - // this is complicated because Win32 seems to pack multiple mouse events into - // one update sometimes, so we always check all states and look for events - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MOUSEMOVE: - case WM_XBUTTONDOWN: - case WM_XBUTTONUP: - temp = 0; - - if (wParam & MK_LBUTTON) - temp |= 1; - - if (wParam & MK_RBUTTON) - temp |= 2; - - if (wParam & MK_MBUTTON) - temp |= 4; - - if (wParam & MK_XBUTTON1) - temp |= 8; - - if (wParam & MK_XBUTTON2) - temp |= 16; - - if (wParam & MK_XBUTTON3) - temp |= 32; - - if (wParam & MK_XBUTTON4) - temp |= 64; - - if (wParam & MK_XBUTTON5) - temp |= 128; - - if (wParam & MK_XBUTTON6) - temp |= 256; - - if (wParam & MK_XBUTTON7) - temp |= 512; - - if (!vid_initializing) - IN_MouseEvent (temp); - - break; - - // JACK: This is the mouse wheel with the Intellimouse - // Its delta is either positive or neg, and we generate the proper - // Event. - case WM_MOUSEWHEEL: - if (!vid_initializing) - { - if ((short) HIWORD(wParam) > 0) - { - Key_Event(K_MWHEELUP, 0, true); - Key_Event(K_MWHEELUP, 0, false); - } - else - { - Key_Event(K_MWHEELDOWN, 0, true); - Key_Event(K_MWHEELDOWN, 0, false); - } - } - break; - - case WM_INPUT: - // raw input handling - if (!vid_initializing) - IN_RawInput_MouseRead((HANDLE)lParam); - break; - - case WM_SIZE: - if (!vid_initializing) - { - GetWindowRect(mainwindow, &window_rect); - // force width/height to be updated -// glwidth = window_rect.right - window_rect.left; -// glheight = window_rect.bottom - window_rect.top; -// Cvar_ForceCallback(&vid_conautoscale); -// Cvar_ForceCallback(&vid_conwidth); - } - break; - - case WM_CLOSE: - if (!vid_initializing) - if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", - MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES) - { - Sys_Quit (); - } - - break; - - case WM_ACTIVATE: - fActive = LOWORD(wParam); - fMinimized = (BOOL) HIWORD(wParam); - if (!D3DAppActivate(!(fActive == WA_INACTIVE), fMinimized)) - break;//so, urm, tell me microsoft, what changed? - if (modestate == MS_FULLDIB) - ShowWindow(mainwindow, SW_SHOWNORMAL); - - // fix the leftover Alt from any Alt-Tab or the like that switched us away -// ClearAllStates (); - - break; - - case WM_DESTROY: - { -// if (dibwindow) -// DestroyWindow (dibwindow); - } - break; - - case MM_MCINOTIFY: - lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam); - break; - - default: - /* pass all unhandled messages to DefWindowProc */ - lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); - break; - } - - /* return 1 if handled message, 0 if not */ - return lRet; -} - - - -qboolean D3D7_VID_Init(rendererstate_t *info, unsigned char *palette) -{ - DWORD width = info->width; - DWORD height = info->height; - DWORD bpp = info->bpp; - DWORD zbpp = 16; - DWORD flags = 0; - MSG msg; - - extern cvar_t vid_conwidth; - extern cvar_t vid_conheight; - - DDGAMMARAMP gammaramp; - char errs[1024]; - int i; - HRESULT hr; - - char *CLASSNAME = "FTED3D7QUAKE"; - WNDCLASS wc = { - 0, - &D3D7_WindowProc, - 0, - 0, - NULL, - NULL, - NULL, - NULL, - NULL, - CLASSNAME - }; - -// wc.style = 0; - wc.lpfnWndProc = D3D7_WindowProc; -// wc.cbClsExtra; -// wc.cbWndExtra; -// wc.hInstance; -// wc.hIcon; -// wc.hCursor; -// wc.hbrBackground; -// wc.lpszMenuName; - wc.lpszClassName = CLASSNAME; - - vid_initializing = true; - - if( FAILED(hr = D3DXInitialize()) ) - { - D3DXGetErrorString(hr, sizeof(errs), errs); - Con_Printf("D3D initialisation failed: error %X: %s\n", hr, errs); - return false; - } - - RegisterClass(&wc); - - flags |= info->fullscreen ? D3DX_CONTEXT_FULLSCREEN : 0; - - if (flags & D3DX_CONTEXT_FULLSCREEN) - mainwindow = CreateWindow(CLASSNAME, "Direct3D", 0, 0, 0, width, height, NULL, NULL, NULL, NULL); - else - mainwindow = CreateWindow(CLASSNAME, "Direct3D", WS_OVERLAPPEDWINDOW, 0, 0, width, height, NULL, NULL, NULL, NULL); -/* - width = vid_conwidth.value; - height = vid_conheight.value; -*/ - // Try as specified. - hr = D3DXCreateContextEx(D3DX_DEFAULT, flags, - mainwindow, NULL, bpp, 0, - zbpp, 0, 1, width, height, D3DX_DEFAULT, &pD3DX); - if( FAILED(hr) ) - { - D3DXGetErrorString(hr, sizeof(errs), errs); - printf("D3D initialisation failed: error %X: %s\n", hr, errs); - - // default z-buffer - hr = D3DXCreateContextEx(D3DX_DEFAULT, flags, - mainwindow, NULL, bpp, 0, - D3DX_DEFAULT, 0, 1, width, height, D3DX_DEFAULT, &pD3DX); - if( FAILED(hr) ) - { - // default depth and z-buffer - hr = D3DXCreateContextEx(D3DX_DEFAULT, flags, - mainwindow, NULL, D3DX_DEFAULT, 0, - D3DX_DEFAULT, 0, 1, width, height, D3DX_DEFAULT, &pD3DX); - if( FAILED(hr) ) - { - // default everything - hr = D3DXCreateContextEx(D3DX_DEFAULT, flags, - mainwindow, NULL, D3DX_DEFAULT, 0, - D3DX_DEFAULT, 0, 1, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, &pD3DX); - if( FAILED(hr) ) - { - D3DXGetErrorString(hr, sizeof(errs), errs); - Con_Printf("D3D fallbacks failed: error %X: %s\n", hr, errs); - - DestroyWindow(mainwindow); - mainwindow = NULL; - return false; - } - } - } - } - //the void* casts are because microsoft screwed up in the header files I have - pDD = pD3DX->lpVtbl->GetDD((void*)pD3DX); - pD3D = pD3DX->lpVtbl->GetD3D((void*)pD3DX); - pD3DDev = pD3DX->lpVtbl->GetD3DDevice((void*)pD3DX); - pPrimary = pD3DX->lpVtbl->GetPrimary((void*)pD3DX); - - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - ShowWindow(mainwindow, SW_NORMAL); - pD3DX->lpVtbl->SetClearColor((void*)pD3DX, 0xffffffff); - pD3DX->lpVtbl->Clear((void*)pD3DX, D3DCLEAR_TARGET); - pD3DX->lpVtbl->UpdateFrame((void*)pD3DX, 0); - - - - pD3DX->lpVtbl->GetBufferSize((void*)pD3DX, &width, &height); - vid.width = width; - vid.height = height; - vid.recalc_refdef = true; - - pDD->lpVtbl->QueryInterface ((void*)pDD, &IID_IDirectDrawGammaControl, (void**)&pGammaControl); - if (pGammaControl) - { - for (i = 0; i < 256; i++) - gammaramp.red[i] = i*2; - pGammaControl->lpVtbl->SetGammaRamp(pGammaControl, 0, &gammaramp); - } - else - Con_Printf("Couldn't get gamma controls\n"); - - vid_initializing = false; - - - - - - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHAFUNC, D3DCMP_GREATER ); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHAREF, 0.666*256 ); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ALPHATESTENABLE, TRUE ); - - - //pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_DITHERENABLE, FALSE); - //pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_SPECULARENABLE, FALSE); - //pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_LIGHTING, FALSE); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZWRITEENABLE, TRUE); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZVISIBLE, TRUE); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL); - - - GetWindowRect(mainwindow, &window_rect); - - - D3D7_VID_GenPaletteTables(palette); - - - - { - extern cvar_t vid_conwidth, vid_conheight; - vid.conwidth = vid_conwidth.value; - vid.conheight = vid_conheight.value; - if (vid.width != vid.conwidth || vid.height != vid.conheight) - vid.recalc_refdef = true; - vid.width = vid.conwidth; - vid.height = vid.conheight; - } - - return true; -} - - - -qboolean (D3D7_R_CheckSky) (void) -{ - return false; -} -void (D3D7_R_SetSky) (char *name, float rotate, vec3_t axis) -{ -} - -void (D3D7_R_NewMap) (void) -{ - extern int skytexturenum; - int i; - r_worldentity.model = cl.worldmodel; - GLR_AnimateLight(); - D3D7_BuildLightmaps(); - - P_ClearParticles(); - - skytexturenum = -1; - - for (i=0 ; inumtextures ; i++) - { - if (!cl.worldmodel->textures[i]) - continue; - if (!Q_strncmp(cl.worldmodel->textures[i]->name,"sky",3) ) - skytexturenum = i; -// if (!Q_strncmp(cl.worldmodel->textures[i]->name,"window02_1",10) ) -// mirrortexturenum = i; - cl.worldmodel->textures[i]->texturechain = NULL; - } -} - -mleaf_t *r_viewleaf, *r_oldviewleaf; -mleaf_t *r_viewleaf2, *r_oldviewleaf2; -void (D3D7_R_PreNewMap) (void) -{ - r_viewleaf = NULL; - r_oldviewleaf = NULL; - r_viewleaf2 = NULL; - r_oldviewleaf2 = NULL; -} -int (D3D7_R_LightPoint) (vec3_t point) -{ - return 0; -} - -void (D3D7_R_PushDlights) (void) -{ -} -void (D3D7_R_AddStain) (vec3_t org, float red, float green, float blue, float radius) -{ -} -void (D3D7_R_LessenStains) (void) -{ -} - -void (D3D7_VID_DeInit) (void) -{ - if (pPrimary) - { - pPrimary->lpVtbl->Release(pPrimary); - pPrimary = NULL; - } - if (pD3DDev) - { - pD3DDev->lpVtbl->Release(pD3DDev); - pD3DDev = NULL; - } - if (pD3D) - { - pD3D->lpVtbl->Release(pD3D); - pD3D = NULL; - } - if (pDD) - { - pDD->lpVtbl->Release(pDD); - pDD = NULL; - } - if (pD3DX) - { - pD3DX->lpVtbl->Release((void*)pD3DX); - pD3DX = NULL; - } - if (mainwindow) - { - DestroyWindow(mainwindow); - mainwindow = NULL; - } -} -void (D3D7_VID_LockBuffer) (void) -{ -} -void (D3D7_VID_UnlockBuffer) (void) -{ -} -void (D3D7_D_BeginDirectRect) (int x, int y, qbyte *pbitmap, int width, int height) -{ -} -void (D3D7_D_EndDirectRect) (int x, int y, int width, int height) -{ -} -void (D3D7_VID_ForceLockState) (int lk) -{ -} -int (D3D7_VID_ForceUnlockedAndReturnState) (void) -{ - return 0; -} - -void (D3D7_VID_SetPalette) (unsigned char *palette) -{ - D3D7_VID_GenPaletteTables(palette); -} -void (D3D7_VID_ShiftPalette) (unsigned char *palette) -{ - D3D7_VID_GenPaletteTables(palette); -} -char *(D3D7_VID_GetRGBInfo) (int prepad, int *truevidwidth, int *truevidheight) -{ - return NULL; -} -void (D3D7_VID_SetWindowCaption) (char *msg) -{ - SetWindowText(mainwindow, msg); -} - -void d3d7_ortho(float *m) -{ - D3DXMatrixOrthoOffCenter((D3DXMATRIX*)m, 0, vid.width, vid.height, 0, -100, 100); -} - -void D3D7_Set2D (void) -{ - int r; - float m[16]; - D3DVIEWPORT7 vport; -// pD3DDev->lpVtbl->EndScene(pD3DDev); - - D3DXMatrixOrthoOffCenter((D3DXMATRIX*)m, 0, vid.width, vid.height, 0, -100, 100); - r = pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX*)m); - - D3DXMatrixIdentity((D3DXMATRIX*)m); - r = pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX*)m); - - D3DXMatrixIdentity((D3DXMATRIX*)m); - pD3DDev->lpVtbl->SetTransform(pD3DDev, D3DTRANSFORMSTATE_VIEW, (D3DMATRIX*)m); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_CULLMODE, D3DCULL_CCW ); - - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS); - pD3DDev->lpVtbl->SetRenderState(pD3DDev, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_MAGFILTER, D3DTFG_LINEAR); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_MIPFILTER, D3DTFP_LINEAR); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_MIPFILTER, D3DTFP_LINEAR); - - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 0, D3DTSS_MINFILTER, D3DTFN_LINEAR); - pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_MINFILTER, D3DTFN_LINEAR); - - vport.dwX = 0; - vport.dwY = 0; - pD3DX->lpVtbl->GetBufferSize((void*)pD3DX, &vport.dwWidth, &vport.dwHeight); - vport.dvMinZ = 0; - vport.dvMaxZ = 1; - pD3DDev->lpVtbl->SetViewport(pD3DDev, &vport); - -// pD3DDev->lpVtbl->BeginScene(pD3DDev); -} - -void D3D7_GetBufferSize(int *width, int *height) -{ - pD3DX->lpVtbl->GetBufferSize((void*)pD3DX, width, height); -} - - -void (D3D7_SCR_UpdateScreen) (void) -{ - extern cvar_t vid_conheight; - int uimenu; -#ifdef TEXTEDITOR - extern qboolean editormodal; -#endif - qboolean nohud; - RSpeedMark(); - - vid.numpages = 2;// + gl_triplebuffer.value; - - if (scr_disabled_for_loading) - { - extern float scr_disabled_time; - if (Sys_DoubleTime() - scr_disabled_time > 60 || key_dest != key_game) - { - scr_disabled_for_loading = false; - } - else - { - pD3DDev->lpVtbl->BeginScene(pD3DDev); - scr_drawloading = true; - SCR_DrawLoading (); - scr_drawloading = false; - pD3DDev->lpVtbl->EndScene(pD3DDev); - pD3DX->lpVtbl->UpdateFrame((void*)pD3DX, 0); - RSpeedEnd(RSPEED_TOTALREFRESH); - return; - } - } - - if (!scr_initialized || !con_initialized) - { - RSpeedEnd(RSPEED_TOTALREFRESH); - return; // not initialized yet - } - - { - extern cvar_t vid_conwidth, vid_conheight; - vid.conwidth = vid_conwidth.value; - vid.conheight = vid_conheight.value; - { - DWORD w, h; - pD3DX->lpVtbl->GetBufferSize((void*)pD3DX, &w, &h); - if (vid.conwidth <= 0) - vid.conwidth = w; - if (vid.conheight <= 0) - vid.conheight = h; - } - if (vid.width != vid.conwidth || vid.height != vid.conheight) - vid.recalc_refdef = true; - vid.width = vid.conwidth; - vid.height = vid.conheight; - } - - -#ifdef VM_UI - uimenu = UI_MenuState(); -#else - uimenu = 0; -#endif - - pD3DDev->lpVtbl->BeginScene(pD3DDev); - D3D7_Set2D (); -/* -#ifdef TEXTEDITOR - if (editormodal) - { - Editor_Draw(); - GLV_UpdatePalette (false, host_frametime); -#if defined(_WIN32) && defined(GLQUAKE) - Media_RecordFrame(); -#endif - GLR_BrightenScreen(); - - if (key_dest == key_console) - Con_DrawConsole(vid_conheight.value/2, false); - GL_EndRendering (); - GL_DoSwap(); - RSpeedEnd(RSPEED_TOTALREFRESH); - return; - } -#endif -*/ - if (Media_ShowFilm()) - { - M_Draw(0); -// GLV_UpdatePalette (false, host_frametime); -#if defined(_WIN32) - Media_RecordFrame(); -#endif -// GLR_BrightenScreen(); - pD3DDev->lpVtbl->EndScene(pD3DDev); - pD3DX->lpVtbl->UpdateFrame((void*)pD3DX, 0); - - pD3DX->lpVtbl->SetClearColor((void*)pD3DX, rand()); - pD3DX->lpVtbl->Clear((void*)pD3DX, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER); - -// pD3DDev->lpVtbl->BeginScene(pD3DDev); - - RSpeedEnd(RSPEED_TOTALREFRESH); - return; - } - - // - // determine size of refresh window - // - if (vid.recalc_refdef) - SCR_CalcRefdef (); - -// -// do 3D refresh drawing, and then update the screen -// - SCR_SetUpToDrawConsole (); - - nohud = false; - -#ifdef VM_CG - if (CG_Refresh()) - nohud = true; - else -#endif -#ifdef CSQC_DAT - if (cls.state == ca_active && CSQC_DrawView()) - nohud = true; - else -#endif - if (r_worldentity.model && uimenu != 1) - { - V_RenderView (); -// Q1BSP_TestClipDecal(); - } - - - D3D7_Set2D (); - -// GLR_BrightenScreen(); - - if (!nohud) - SCR_TileClear (); - - SCR_DrawTwoDimensional(uimenu, nohud); - -// GLV_UpdatePalette (false, host_frametime); -#if defined(_WIN32) && defined(GLQUAKE) - Media_RecordFrame(); -#endif - - RSpeedEnd(RSPEED_TOTALREFRESH); - RSpeedShow(); - - - - pD3DDev->lpVtbl->EndScene(pD3DDev); - pD3DX->lpVtbl->UpdateFrame((void*)pD3DX, 0); - - - pD3DX->lpVtbl->SetClearColor((void*)pD3DX, rand()); - pD3DX->lpVtbl->Clear((void*)pD3DX, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER); - - - window_center_x = (window_rect.left + window_rect.right)/2; - window_center_y = (window_rect.top + window_rect.bottom)/2; - - - - IN_UpdateGrabs(modestate != MS_WINDOWED, ActiveApp); -} - - - - - -mpic_t *(D3D7_Draw_SafePicFromWad) (char *name); -mpic_t *(D3D7_Draw_CachePic) (char *path); -mpic_t *(D3D7_Draw_SafeCachePic) (char *path); -void (D3D7_Draw_Init) (void); -void (D3D7_Draw_ReInit) (void); -void (D3D7_Draw_Character) (int x, int y, unsigned int num); -void (D3D7_Draw_ColouredCharacter) (int x, int y, unsigned int num); -void (D3D7_Draw_String) (int x, int y, const qbyte *str); -void (D3D7_Draw_Alt_String) (int x, int y, const qbyte *str); -void (D3D7_Draw_Crosshair) (void); -void (D3D7_Draw_DebugChar) (qbyte num); -void (D3D7_Draw_Pic) (int x, int y, mpic_t *pic); -void (D3D7_Draw_ScalePic) (int x, int y, int width, int height, mpic_t *pic); -void (D3D7_Draw_SubPic) (int x, int y, mpic_t *pic, int srcx, int srcy, int width, int height); -void (D3D7_Draw_TransPic) (int x, int y, mpic_t *pic); -void (D3D7_Draw_TransPicTranslate) (int x, int y, int w, int h, qbyte *pic, qbyte *translation); -void (D3D7_Draw_ConsoleBackground) (int lines); -void (D3D7_Draw_EditorBackground) (int lines); -void (D3D7_Draw_TileClear) (int x, int y, int w, int h); -void (D3D7_Draw_Fill) (int x, int y, int w, int h, int c); -void (D3D7_Draw_FillRGB) (int x, int y, int w, int h, float r, float g, float b); -void (D3D7_Draw_FadeScreen) (void); -void (D3D7_Draw_BeginDisc) (void); -void (D3D7_Draw_EndDisc) (void); - -void (D3D7_Draw_Image) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, mpic_t *pic); //gl-style scaled/coloured/subpic -void (D3D7_Draw_ImageColours) (float r, float g, float b, float a); - -void (D3D7_R_Init) (void); -void (D3D7_R_DeInit) (void); -void (D3D7_R_ReInit) (void); -void (D3D7_R_RenderView) (void); // must set r_refdef first - -qboolean (D3D7_R_CheckSky) (void); -void (D3D7_R_SetSky) (char *name, float rotate, vec3_t axis); - -void (D3D7_R_NewMap) (void); -void (D3D7_R_PreNewMap) (void); -int (D3D7_R_LightPoint) (vec3_t point); - -void (D3D7_R_PushDlights) (void); -void (D3D7_R_AddStain) (vec3_t org, float red, float green, float blue, float radius); -void (D3D7_R_LessenStains) (void); - -void (D3D7_Media_ShowFrameBGR_24_Flip) (qbyte *framedata, int inwidth, int inheight); //input is bottom up... -void (D3D7_Media_ShowFrameRGBA_32) (qbyte *framedata, int inwidth, int inheight); //top down -void (D3D7_Media_ShowFrame8bit) (qbyte *framedata, int inwidth, int inheight, qbyte *palette); //paletted topdown (framedata is 8bit indexes into palette) - -void (D3D7_Mod_Init) (void); -void (D3D7_Mod_ClearAll) (void); -struct model_s *(D3D7_Mod_ForName) (char *name, qboolean crash); -struct model_s *(D3D7_Mod_FindName) (char *name); -void *(D3D7_Mod_Extradata) (struct model_s *mod); // handles caching -void (D3D7_Mod_TouchModel) (char *name); - -void (D3D7_Mod_NowLoadExternal) (void); -void (D3D7_Mod_Think) (void); -int (D3D7_Mod_TagNumForName) (struct model_s *model, char *name); -int (D3D7_Mod_SkinForName) (struct model_s *model, char *name); - - -qboolean (D3D7_VID_Init) (rendererstate_t *info, unsigned char *palette); -void (D3D7_VID_DeInit) (void); -void (D3D7_VID_LockBuffer) (void); -void (D3D7_VID_UnlockBuffer) (void); -void (D3D7_D_BeginDirectRect) (int x, int y, qbyte *pbitmap, int width, int height); -void (D3D7_D_EndDirectRect) (int x, int y, int width, int height); -void (D3D7_VID_ForceLockState) (int lk); -int (D3D7_VID_ForceUnlockedAndReturnState) (void); -void (D3D7_VID_SetPalette) (unsigned char *palette); -void (D3D7_VID_ShiftPalette) (unsigned char *palette); -char *(D3D7_VID_GetRGBInfo) (int prepad, int *truevidwidth, int *truevidheight); -void (D3D7_VID_SetWindowCaption) (char *msg); - -void (D3D7_SCR_UpdateScreen) (void); - - - - - - - -rendererinfo_t d3d7rendererinfo = -{ - "Direct3D7 Native", - { - "D3D7" - }, - QR_DIRECT3D, - - D3D7_Draw_SafePicFromWad, - D3D7_Draw_CachePic, - D3D7_Draw_SafeCachePic, - D3D7_Draw_Init, - D3D7_Draw_ReInit, - D3D7_Draw_Character, - D3D7_Draw_ColouredCharacter, - NULL, - D3D7_Draw_String, - D3D7_Draw_Alt_String, - D3D7_Draw_Crosshair, - D3D7_Draw_DebugChar, - D3D7_Draw_Pic, - D3D7_Draw_ScalePic, - D3D7_Draw_SubPic, - D3D7_Draw_TransPic, - D3D7_Draw_TransPicTranslate, - D3D7_Draw_ConsoleBackground, - D3D7_Draw_EditorBackground, - D3D7_Draw_TileClear, - D3D7_Draw_Fill, - D3D7_Draw_FillRGB, - D3D7_Draw_FadeScreen, - D3D7_Draw_BeginDisc, - D3D7_Draw_EndDisc, - - D3D7_Draw_Image, - D3D7_Draw_ImageColours, - - D3D7_R_Init, - D3D7_R_DeInit, - D3D7_R_ReInit, - D3D7_R_RenderView, - - D3D7_R_CheckSky, - D3D7_R_SetSky, - - D3D7_R_NewMap, - D3D7_R_PreNewMap, - D3D7_R_LightPoint, - - D3D7_R_PushDlights, - D3D7_R_AddStain, - D3D7_R_LessenStains, - - D3D7_Media_ShowFrameBGR_24_Flip, - D3D7_Media_ShowFrameRGBA_32, - D3D7_Media_ShowFrame8bit, - - GLMod_Init, - GLMod_ClearAll, - GLMod_ForName, - GLMod_FindName, - GLMod_Extradata, - GLMod_TouchModel, - - GLMod_NowLoadExternal, - GLMod_Think, - Mod_GetTag, - Mod_TagNumForName, - Mod_SkinNumForName, - Mod_FrameNumForName, - Mod_FrameDuration, - - - D3D7_VID_Init, - D3D7_VID_DeInit, - D3D7_VID_LockBuffer, - D3D7_VID_UnlockBuffer, - D3D7_D_BeginDirectRect, - D3D7_D_EndDirectRect, - D3D7_VID_ForceLockState, - D3D7_VID_ForceUnlockedAndReturnState, - D3D7_VID_SetPalette, - D3D7_VID_ShiftPalette, - D3D7_VID_GetRGBInfo, - D3D7_VID_SetWindowCaption, - - D3D7_SCR_UpdateScreen - -}; -#endif diff --git a/engine/d3d9/d3d9_draw.c b/engine/d3d9/d3d9_draw.c deleted file mode 100644 index 284133f83..000000000 --- a/engine/d3d9/d3d9_draw.c +++ /dev/null @@ -1,883 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "winquake.h" -#include "d3d9quake.h" - -#define MAX_WIDTH 512 -#define MAX_HEIGHT 512 - -void *d3dexplosiontexture; -void *d3dballtexture; - -LPDIRECT3DBASETEXTURE9 d3d9chars_tex; -mpic_t *conback_tex; - -extern cvar_t gl_picmip; -extern cvar_t gl_picmip2d; - -typedef struct d3dcachepic_s -{ - char name[MAX_QPATH]; - mpic_t pic; -} d3dcachepic_t; -#define MAX_CACHED_PICS 512 //a temporary solution -d3dcachepic_t d3dmenu_cachepics[MAX_CACHED_PICS]; -int d3dmenu_numcachepics; - -#ifdef MINGW // these are undefined in MinGW - const unsigned int TF_COLOR = 1; - const unsigned int TF_ALPHA = 2; - const unsigned int TF_MASKED = 4; - const unsigned int TF_MIPMAP = 8; - const unsigned int TF_CLAMP = 16; - const unsigned int TF_ANISOTROPIC = 32; - const unsigned int TF_SPHEREMAP = 64; - const unsigned int TF_CUBEMAP = 128; - const unsigned int TF_NORMALCUBE = 512; - const unsigned int TF_NOTBUMPMAP = 0; //made this up - const unsigned int TF_NOMIPMAP = 0; //made this up - const unsigned int TF_NOALPHA = 0; //made this up -#endif - - - -typedef struct { - float x, y, z; - int colour; - float s, t; -} d3dquadvert_t; -d3dquadvert_t d3d9quadvert[4]; -index_t d3d9quadindexes[6] = { - 0, 1, 2, - 0, 2, 3 -}; -//pD3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX2, d3dstate.vertbuf, d3dstate.numverts, d3dstate.indexbuf, d3dstate.numindicies, 0); - - -static void Upload_Texture_32(LPDIRECT3DTEXTURE9 surf, unsigned int *data, int width, int height) -{ - int x, y; - unsigned int *dest; - unsigned char swapbuf[4]; - unsigned char swapbuf2[4]; - D3DLOCKED_RECT lock; - - D3DSURFACE_DESC desc; - IDirect3DTexture9_GetLevelDesc(surf, 0, &desc); - - IDirect3DTexture9_LockRect(surf, 0, &lock, NULL, DDLOCK_NOSYSLOCK|D3DLOCK_READONLY); - - //(surf, NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - - if (width == desc.Width && height == desc.Height) - { -// if (desc.lPitch == twidth*4) -// { -// memcpy(desc.lpSurface, data, width*height*4); -// } -// else - { - for (y = 0; y < height; y++) - { - dest = (unsigned int *)((char *)lock.pBits + lock.Pitch*y); - for (x = 0; x < width; x++) - { - *(unsigned int*)swapbuf2 = *(unsigned int*)swapbuf = data[x]; - swapbuf[0] = swapbuf2[2]; - swapbuf[2] = swapbuf2[0]; - dest[x] = *(unsigned int*)swapbuf; - } - data += width; - } - } - } - else - { - int x, y; - int iny; - unsigned int *row, *inrow; - - for (y = 0; y < desc.Height; y++) - { - row = (unsigned int*)((char *)lock.pBits + lock.Pitch*y); - iny = (y * height) / desc.Height; - inrow = data + width*iny; - for (x = 0; x < desc.Width; x++) - { - *(unsigned int*)swapbuf2 = *(unsigned int*)swapbuf = inrow[(x * width)/desc.Width]; - swapbuf[0] = swapbuf2[2]; - swapbuf[2] = swapbuf2[0]; - row[x] = *(unsigned int*)swapbuf; - } - } - - - - //mimic opengl and draw it white -// memset(desc.lpSurface, 255, twidth*theight*4); - } - - IDirect3DTexture9_UnlockRect(surf, 0); -} - -void D3D9_RoundDimensions(int *scaled_width, int *scaled_height, qboolean mipmap) -{ -// if (gl_config.arb_texture_non_power_of_two) //NPOT is a simple extension that relaxes errors. -// { -// TRACE(("dbg: GL_RoundDimensions: GL_ARB_texture_non_power_of_two\n")); -// } -// else - { - int width = *scaled_width; - int height = *scaled_height; - for (*scaled_width = 1 ; *scaled_width < width ; *scaled_width<<=1) - ; - for (*scaled_height = 1 ; *scaled_height < height ; *scaled_height<<=1) - ; - } - - if (mipmap) - { - TRACE(("dbg: GL_RoundDimensions: %i\n", gl_picmip.ival)); - *scaled_width >>= gl_picmip.ival; - *scaled_height >>= gl_picmip.ival; - } - else - { - *scaled_width >>= gl_picmip2d.ival; - *scaled_height >>= gl_picmip2d.ival; - } - - TRACE(("dbg: GL_RoundDimensions: %i\n", gl_max_size.ival)); - if (gl_max_size.ival) - { - if (*scaled_width > gl_max_size.ival) - *scaled_width = gl_max_size.ival; - if (*scaled_height > gl_max_size.ival) - *scaled_height = gl_max_size.ival; - } - - if (*scaled_width < 1) - *scaled_width = 1; - if (*scaled_height < 1) - *scaled_height = 1; -} - -void D3D9_MipMap (qbyte *out, qbyte *in, int width, int height) -{ - int i, j; - - width <<=2; - height >>= 1; - for (i=0 ; i>2; - out[1] = (in[1] + in[5] + in[width+1] + in[width+5])>>2; - out[2] = (in[2] + in[6] + in[width+2] + in[width+6])>>2; - out[3] = (in[3] + in[7] + in[width+3] + in[width+7])>>2; - } - } -} - -//create a basic shader from a 32bit image -LPDIRECT3DBASETEXTURE9 D3D9_LoadTexture_32(char *name, unsigned int *data, int width, int height, int flags) -{ - int nwidth, nheight; - - LPDIRECT3DTEXTURE9 newsurf; -/* - if (!(flags & TF_MANDATORY)) - { - Con_Printf("Texture upload missing flags\n"); - return NULL; - } -*/ - - nwidth = width; - nheight = height; - D3D9_RoundDimensions(&nwidth, &nheight, flags & TF_MIPMAP); - - IDirect3DDevice9_CreateTexture(pD3DDev9, nwidth, nheight, 0, 0|((flags & TF_MIPMAP)?D3DUSAGE_AUTOGENMIPMAP:0), D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &newsurf, NULL); - - if (!newsurf) - return NULL; - - Upload_Texture_32(newsurf, data, width, height); - - if (flags & TF_MIPMAP) - IDirect3DBaseTexture9_GenerateMipSubLevels(newsurf); - - return (LPDIRECT3DBASETEXTURE9)newsurf; -} - -//create a basic shader from an 8bit image with 24bit palette -LPDIRECT3DBASETEXTURE9 D3D9_LoadTexture_8_Pal24(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette, int transparentpix) -{ - //just expands it to 32bpp and passes it on - static unsigned char out[MAX_WIDTH*MAX_HEIGHT][4]; - int i; - - if (!(flags & TF_ALPHA)) - transparentpix = 256; - - if (width*height > MAX_WIDTH*MAX_HEIGHT) - Sys_Error("GL_Upload8_Pal24: too big"); - - for (i = width*height; i >= 0 ; i--) - { - out[i][0] = palette[data[i]*3+0]; - out[i][1] = palette[data[i]*3+1]; - out[i][2] = palette[data[i]*3+2]; - out[i][3] = 255*(data[i] != transparentpix); - } - - - return D3D9_LoadTexture_32(name, (unsigned int*)out, width, height, flags); -} - -LPDIRECT3DBASETEXTURE9 D3D9_LoadTexture_8_Pal32(char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette) -{ - //just expands it to 32bpp and passes it on - static unsigned char out[MAX_WIDTH*MAX_HEIGHT][4]; - int i; - - if (width*height > MAX_WIDTH*MAX_HEIGHT) - Sys_Error("GL_Upload8_Pal24: too big"); - - for (i = width*height; i >= 0 ; i--) - { - out[i][0] = palette[data[i]*4+0]; - out[i][1] = palette[data[i]*4+1]; - out[i][2] = palette[data[i]*4+2]; - out[i][3] = palette[data[i]*4+3]; - } - - - return D3D9_LoadTexture_32(name, (unsigned int*)out, width, height, flags); -} - - -void D3D9_UnloadTexture(LPDIRECT3DBASETEXTURE9 tex) -{ - if (tex) - IDirect3DBaseTexture9_Release(tex); -} - - - - - - - - -static qbyte exptexture[16][16] = -{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0}, - {0,0,0,1,1,1,1,1,3,1,1,2,1,0,0,0}, - {0,0,0,1,1,1,1,4,4,4,5,4,2,1,1,0}, - {0,0,1,1,6,5,5,8,6,8,3,6,3,2,1,0}, - {0,0,1,5,6,7,5,6,8,8,8,3,3,1,0,0}, - {0,0,0,1,6,8,9,9,9,9,4,6,3,1,0,0}, - {0,0,2,1,7,7,9,9,9,9,5,3,1,0,0,0}, - {0,0,2,4,6,8,9,9,9,9,8,6,1,0,0,0}, - {0,0,2,2,3,5,6,8,9,8,8,4,4,1,0,0}, - {0,0,1,2,4,1,8,7,8,8,6,5,4,1,0,0}, - {0,1,1,1,7,8,1,6,7,5,4,7,1,0,0,0}, - {0,1,2,1,1,5,1,3,4,3,1,1,0,0,0,0}, - {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, -}; -void D3D9_InitParticleTexture (void) -{ -#define PARTICLETEXTURESIZE 64 - int x,y; - float dx, dy, d; - qbyte data[PARTICLETEXTURESIZE*PARTICLETEXTURESIZE][4]; - -//Explosion texture - - - for (x=0 ; x<16 ; x++) - { - for (y=0 ; y<16 ; y++) - { - data[y*16+x][0] = 255; - data[y*16+x][1] = 255; - data[y*16+x][2] = 255; - data[y*16+x][3] = exptexture[x][y]*255/9.0; - } - } - d3dexplosiontexture = D3D9_LoadTexture_32("", (unsigned int*)data, 16, 16, TF_ALPHA|TF_NOTBUMPMAP|TF_NOMIPMAP); - - memset(data, 255, sizeof(data)); - for (y = 0;y < PARTICLETEXTURESIZE;y++) - { - dy = (y - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1); - for (x = 0;x < PARTICLETEXTURESIZE;x++) - { - dx = (x - 0.5f*PARTICLETEXTURESIZE) / (PARTICLETEXTURESIZE*0.5f-1); - d = 256 * (1 - (dx*dx+dy*dy)); - d = bound(0, d, 255); - data[y*PARTICLETEXTURESIZE+x][3] = (qbyte) d; - } - } - - d3dballtexture = D3D9_LoadTexture_32("", (unsigned int*)data, PARTICLETEXTURESIZE, PARTICLETEXTURESIZE, TF_ALPHA|TF_NOTBUMPMAP|TF_NOMIPMAP); -} - - - - - - - - - -mpic_t *D3D9_Draw_SafePicFromWad (char *name) -{ - LPDIRECT3DBASETEXTURE9 *p; - d3dcachepic_t *pic; - qpic_t *qpic; - int i; - - for (i = 0; i < d3dmenu_numcachepics; i++) - { - if (!strcmp(d3dmenu_cachepics[i].name, name)) - return &d3dmenu_cachepics[i].pic; - } - - qpic = (qpic_t *)W_SafeGetLumpName (name); - if (qpic) - SwapPic (qpic); - - pic = &d3dmenu_cachepics[d3dmenu_numcachepics]; - - Q_strncpyz (pic->name, name, sizeof(pic->name)); - - p = (LPDIRECT3DBASETEXTURE9*)&pic->pic.d.data; - if (!strcmp(name, "conchars")) - { - pic->pic.width = 256; - pic->pic.height = 256; - *p = d3d9chars_tex; - } - else if (qpic) - { - pic->pic.width = qpic->width; - pic->pic.height = qpic->height; - - *p = (LPDIRECT3DBASETEXTURE9)Mod_LoadReplacementTexture(pic->name, "wad", false, true, true); - if (!*p) - *p = D3D9_LoadTexture_8_Pal24(name, (unsigned char*)(qpic+1), qpic->width, qpic->height, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP, host_basepal, 255); - } - else - { - extern int image_width, image_height; - *p = (LPDIRECT3DBASETEXTURE9)Mod_LoadHiResTexture(pic->name, "wad", false, true, true); - if (!p) - return NULL; - pic->pic.width = image_width; - pic->pic.height = image_height; - } - - d3dmenu_numcachepics++; - -// Con_Printf("Fixme: D3D9_Draw_SafePicFromWad\n"); - return &pic->pic; -} -mpic_t *D3D9_Draw_SafeCachePic (char *path) -{ - LPDIRECT3DBASETEXTURE9 *p; - d3dcachepic_t *pic; - qpic_t *qpic; - int i; - - - for (i = 0; i < d3dmenu_numcachepics; i++) - { - if (!strcmp(d3dmenu_cachepics[i].name, path)) - return &d3dmenu_cachepics[i].pic; - } - - qpic = (qpic_t *)COM_LoadTempFile (path); - if (qpic) - SwapPic (qpic); - - pic = &d3dmenu_cachepics[d3dmenu_numcachepics]; - - Q_strncpyz (pic->name, path, sizeof(pic->name)); - - p = (LPDIRECT3DBASETEXTURE9*)&pic->pic.d.data; - - if (qpic) - { - pic->pic.width = qpic->width; - pic->pic.height = qpic->height; - *p = (LPDIRECT3DBASETEXTURE9)Mod_LoadReplacementTexture(pic->name, "gfx", false, true, true); - if (!*p && qpic) - *p = D3D9_LoadTexture_8_Pal24(path, (unsigned char*)(qpic+1), qpic->width, qpic->height, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP, host_basepal, 255); - } - else - { - extern int image_width, image_height; - *p = (LPDIRECT3DBASETEXTURE9)Mod_LoadHiResTexture(pic->name, "gfx", false, true, true); - if (!*p) - { - return NULL; - } - pic->pic.width = image_width; - pic->pic.height = image_height; - } - - d3dmenu_numcachepics++; - -// Con_Printf("Fixme: D3D9_Draw_SafeCachePic\n"); - return &pic->pic; -} -mpic_t *D3D9_Draw_CachePic (char *path) -{ - mpic_t *pic; - pic = D3D9_Draw_SafeCachePic(path); - if (!pic) - Sys_Error("Couldn't load picture %s", path); - return pic; -} -void D3D9_Draw_ReInit (void) -{ - d3dmenu_numcachepics = 0; - - draw_chars = W_SafeGetLumpName ("conchars"); - - d3d9chars_tex = (LPDIRECT3DBASETEXTURE9)Mod_LoadReplacementTexture("conchars", "gfx", false, true, true); - if (!d3d9chars_tex) - { - if (draw_chars) - d3d9chars_tex = D3D9_LoadTexture_8_Pal24("conchars", draw_chars, 128, 128, TF_NOMIPMAP|TF_ALPHA|TF_NOTBUMPMAP, host_basepal, 0); - if (!d3d9chars_tex) - d3d9chars_tex = (LPDIRECT3DBASETEXTURE9)Mod_LoadHiResTexture("gfx/2d/bigchars.tga", NULL, false, true, false); //try q3 path - if (!d3d9chars_tex) - d3d9chars_tex = (LPDIRECT3DBASETEXTURE9)Mod_LoadHiResTexture("pics/conchars.pcx", NULL, false, true, false); //try low res q2 path - } - - - //now emit the conchars picture as if from a wad. - strcpy(d3dmenu_cachepics[d3dmenu_numcachepics].name, "conchars"); - d3dmenu_cachepics[d3dmenu_numcachepics].pic.width = 128; - d3dmenu_cachepics[d3dmenu_numcachepics].pic.height = 128; - *(int *)&d3dmenu_cachepics[d3dmenu_numcachepics].pic.d.data = (int)d3d9chars_tex; - d3dmenu_numcachepics++; - - - conback_tex = D3D9_Draw_SafeCachePic("gfx/conback.lmp"); - if (!conback_tex) - conback_tex = D3D9_Draw_SafeCachePic("textures/sfx/logo512.jpg"); //try q3 path - if (!conback_tex) - conback_tex = D3D9_Draw_SafeCachePic("pics/conback.pcx"); - - - Plug_DrawReloadImages(); - D3D9_InitParticleTexture(); -} -void D3D9_Draw_Init (void) -{ - D3D9_Draw_ReInit(); -} -void D3D9_Draw_Character (int x, int y, unsigned int num) -{ - int row; - int col; - float frow, fcol, size; - -#define char_instep 0 - num &= 255; - if (num == ' ') - return; - - row = num>>4; - col = num&15; - - frow = row*0.0625+char_instep; - fcol = col*0.0625+char_instep; - size = 0.0625-char_instep*2; - - d3d9quadvert[0].x = x; - d3d9quadvert[0].y = y; - d3d9quadvert[0].z = 0; - d3d9quadvert[0].colour = 0xffffffff; - d3d9quadvert[0].s = fcol; - d3d9quadvert[0].t = frow; - - d3d9quadvert[1].x = x+8; - d3d9quadvert[1].y = y; - d3d9quadvert[1].z = 0; - d3d9quadvert[1].colour = 0xffffffff; - d3d9quadvert[1].s = fcol+size; - d3d9quadvert[1].t = frow; - - d3d9quadvert[2].x = x+8; - d3d9quadvert[2].y = y+8; - d3d9quadvert[2].z = 0; - d3d9quadvert[2].colour = 0xffffffff; - d3d9quadvert[2].s = fcol+size; - d3d9quadvert[2].t = frow+size; - - d3d9quadvert[3].x = x; - d3d9quadvert[3].y = y+8; - d3d9quadvert[3].z = 0; - d3d9quadvert[3].colour = 0xffffffff; - d3d9quadvert[3].s = fcol; - d3d9quadvert[3].t = frow+size; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, d3d9chars_tex); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_TEXCOORDINDEX, 0); - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, d3d9quadindexes, D3DFMT_QINDEX, d3d9quadvert, sizeof(d3d9quadvert[0])); -} - -void D3D9_Draw_ColouredCharacter (int x, int y, unsigned int num) -{ - int row; - int col; - float frow, fcol, size; - unsigned int imgcolour; - unsigned char *c = (unsigned char *)&imgcolour; - -#define char_instep 0 - - if (num&0xffff == ' ') - return; - - col = (num & CON_FGMASK) >> CON_FGSHIFT; - c[0] = consolecolours[col].fb*255; - c[1] = consolecolours[col].fg*255; - c[2] = consolecolours[col].fr*255; - c[3] = (num & CON_HALFALPHA)?128:255; - - - num &= 0xff; - row = num>>4; - col = num&15; - - frow = row*0.0625+char_instep; - fcol = col*0.0625+char_instep; - size = 0.0625-char_instep*2; - - d3d9quadvert[0].x = x; - d3d9quadvert[0].y = y; - d3d9quadvert[0].z = 0; - d3d9quadvert[0].colour = imgcolour; - d3d9quadvert[0].s = fcol; - d3d9quadvert[0].t = frow; - - d3d9quadvert[1].x = x+8; - d3d9quadvert[1].y = y; - d3d9quadvert[1].z = 0; - d3d9quadvert[1].colour = imgcolour; - d3d9quadvert[1].s = fcol+size; - d3d9quadvert[1].t = frow; - - d3d9quadvert[2].x = x+8; - d3d9quadvert[2].y = y+8; - d3d9quadvert[2].z = 0; - d3d9quadvert[2].colour = imgcolour; - d3d9quadvert[2].s = fcol+size; - d3d9quadvert[2].t = frow+size; - - d3d9quadvert[3].x = x; - d3d9quadvert[3].y = y+8; - d3d9quadvert[3].z = 0; - d3d9quadvert[3].colour = imgcolour; - d3d9quadvert[3].s = fcol; - d3d9quadvert[3].t = frow+size; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, d3d9chars_tex); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_TEXCOORDINDEX, 0); - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, d3d9quadindexes, D3DFMT_QINDEX, d3d9quadvert, sizeof(d3d9quadvert[0])); -} -void D3D9_Draw_String (int x, int y, const qbyte *str) -{ - while(*str) - { - D3D9_Draw_Character(x, y, *str++); - x+=8; - } -} -void D3D9_Draw_Alt_String (int x, int y, const qbyte *str) -{ - while(*str) - { - D3D9_Draw_Character(x, y, *str++ | 128); - x+=8; - } -} -void D3D9_Draw_Crosshair (void) -{ - D3D9_Draw_Character(vid.width/2 - 4, vid.height/2 - 4, '+'); -} -void D3D9_Draw_DebugChar (qbyte num) -{ - Sys_Error("D3D function not implemented\n"); -} -void D3D9_Draw_TransPicTranslate (int x, int y, int w, int h, qbyte *pic, qbyte *translation) -{ -// Sys_Error("D3D function not implemented\n"); -} -void D3D9_Draw_TileClear (int x, int y, int w, int h) -{ -// Sys_Error("D3D function not implemented\n"); -} -void D3D9_Draw_Fill_I (int x, int y, int w, int h, unsigned int imgcolour) -{ - d3d9quadvert[0].x = x; - d3d9quadvert[0].y = y; - d3d9quadvert[0].z = 0; - d3d9quadvert[0].colour = imgcolour; - d3d9quadvert[0].s = 0; - d3d9quadvert[0].t = 0; - - d3d9quadvert[1].x = x+w; - d3d9quadvert[1].y = y; - d3d9quadvert[1].z = 0; - d3d9quadvert[1].colour = imgcolour; - d3d9quadvert[1].s = 0; - d3d9quadvert[1].t = 0; - - d3d9quadvert[2].x = x+w; - d3d9quadvert[2].y = y+h; - d3d9quadvert[2].z = 0; - d3d9quadvert[2].colour = imgcolour; - d3d9quadvert[2].s = 0; - d3d9quadvert[2].t = 0; - - d3d9quadvert[3].x = x; - d3d9quadvert[3].y = y+h; - d3d9quadvert[3].z = 0; - d3d9quadvert[3].colour = imgcolour; - d3d9quadvert[3].s = 0; - d3d9quadvert[3].t = 0; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, NULL); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, d3d9quadindexes, D3DFMT_QINDEX, d3d9quadvert, sizeof(d3d9quadvert[0])); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, FALSE ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); -} - -void D3D9_Draw_FillRGB (int x, int y, int w, int h, float r, float g, float b) -{ - char colours[4]; - colours[0] = b*255; - colours[1] = g*255; - colours[2] = r*255; - colours[3] = 255; - - D3D9_Draw_Fill_I(x, y, w, h, *(unsigned int*)colours); -} - -void D3D9_Draw_Fill (int x, int y, int w, int h, unsigned int c) -{ - D3D9_Draw_FillRGB(x, y, w, h, host_basepal[c*3+0]/255.0f, host_basepal[c*3+1]/255.0f, host_basepal[c*3+2]/255.0f); -} -void D3D9_Draw_FadeScreen (void) -{ -// Sys_Error("D3D function not implemented\n"); -} -void D3D9_Draw_BeginDisc (void) -{ -// Sys_Error("D3D function not implemented\n"); -} -void D3D9_Draw_EndDisc (void) -{ -// Sys_Error("D3D function not implemented\n"); -} - -static int imgcolour; - -void D3D9_Draw_Fill_Colours (int x, int y, int w, int h) -{ - D3D9_Draw_Fill_I(x, y, w, h, imgcolour); -} - -void D3D9_Draw_Image (float x, float y, float w, float h, float s1, float t1, float s2, float t2, mpic_t *pic) -{ - LPDIRECT3DBASETEXTURE9 *p; - if (!conback_tex) - return; - if (!pic) - return; - - d3d9quadvert[0].x = x; - d3d9quadvert[0].y = y; - d3d9quadvert[0].z = 0; - d3d9quadvert[0].colour = imgcolour; - d3d9quadvert[0].s = s1;// - 3.0/pic->width; - d3d9quadvert[0].t = t1; - - d3d9quadvert[1].x = x+w; - d3d9quadvert[1].y = y; - d3d9quadvert[1].z = 0; - d3d9quadvert[1].colour = imgcolour; - d3d9quadvert[1].s = s2;// - 3.0/pic->width; - d3d9quadvert[1].t = t1; - - d3d9quadvert[2].x = x+w; - d3d9quadvert[2].y = y+h; - d3d9quadvert[2].z = 0; - d3d9quadvert[2].colour = imgcolour; - d3d9quadvert[2].s = s2;// - 3.0/pic->width; - d3d9quadvert[2].t = t2; - - d3d9quadvert[3].x = x; - d3d9quadvert[3].y = y+h; - d3d9quadvert[3].z = 0; - d3d9quadvert[3].colour = imgcolour; - d3d9quadvert[3].s = s1;// - 3.0/pic->width; - d3d9quadvert[3].t = t2; - - p = (LPDIRECT3DBASETEXTURE9*)&pic->d.data; - IDirect3DDevice9_SetTexture(pD3DDev9, 0, *p); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_TEXCOORDINDEX, 0); - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, d3d9quadindexes, D3DFMT_QINDEX, d3d9quadvert, sizeof(d3d9quadvert[0])); - -} - -void D3D9_Draw_ScalePic (int x, int y, int width, int height, mpic_t *pic) -{ - D3D9_Draw_Image(x, y, width, height, 0, 0, 1, 1, pic); -} -void D3D9_Draw_SubPic (int x, int y, mpic_t *pic, int srcx, int srcy, int width, int height) -{ - float s, t; - float sw, tw; - if (!pic) - return; - - s = (float)srcx/pic->width; - t = (float)srcy/pic->height; - sw = (float)width/pic->width; - tw = (float)height/pic->height; - D3D9_Draw_Image(x, y, width, height, s, t, s+sw, t+tw, pic); -} -void D3D9_Draw_TransPic (int x, int y, mpic_t *pic) -{ - if (!pic) - return; - D3D9_Draw_Image(x, y, pic->width, pic->height, 0, 0, 1, 1, pic); -} -void D3D9_Draw_Pic (int x, int y, mpic_t *pic) -{ - if (!pic) - return; - D3D9_Draw_Image(x, y, pic->width, pic->height, 0, 0, 1, 1, pic); -} -void D3D9_Draw_ImageColours (float r, float g, float b, float a) -{ - unsigned char *c = (unsigned char *)&imgcolour; - - c[0] = b*255; - c[1] = g*255; - c[2] = r*255; - c[3] = a*255; -} - -void D3D9_Draw_ConsoleBackground (int firstline, int lastline, qboolean forceopaque) -{ - D3D9_Draw_ImageColours(1,1,1,1); - D3D9_Draw_Image(0, 0, vid.width, lastline, 0, 1 - (float)lastline/vid.height, 1, 1, conback_tex); -} -void D3D9_Draw_EditorBackground (int lines) -{ - D3D9_Draw_ConsoleBackground(0, lines, false); -} - - - - -void D3D9_Media_ShowFrameBGR_24_Flip (qbyte *framedata, int inwidth, int inheight) -{ - mpic_t pic; - LPDIRECT3DBASETEXTURE9 *p; - p = (LPDIRECT3DBASETEXTURE9*)&pic.d.data; - *p = D3D9_LoadTexture_32("", (unsigned int*)framedata, inwidth, inheight, TF_NOMIPMAP|TF_NOALPHA|TF_NOTBUMPMAP); - - D3D9_Set2D (); - D3D9_Draw_ImageColours(1,1,1,1); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - D3D9_Draw_Image(0, 0, vid.width, vid.height, 0, 1, 1, 0, &pic); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - D3D9_UnloadTexture(*p); -} //input is bottom up... -void D3D9_Media_ShowFrameRGBA_32 (qbyte *framedata, int inwidth, int inheight) -{ - mpic_t pic; - LPDIRECT3DBASETEXTURE9 *p; - - pic.width = inwidth; - pic.height = inheight; - pic.flags = 0; - p = (LPDIRECT3DBASETEXTURE9*)&pic.d; - *p = D3D9_LoadTexture_32("", (unsigned int*)framedata, inwidth, inheight, TF_NOMIPMAP|TF_NOALPHA|TF_NOTBUMPMAP); - - D3D9_Set2D (); - D3D9_Draw_ImageColours(1,1,1,1); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - D3D9_Draw_Image(0, 0, vid.width, vid.height, 0, 0, 1, 1, &pic); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - D3D9_UnloadTexture(*p); -} //top down -void (D3D9_Media_ShowFrame8bit) (qbyte *framedata, int inwidth, int inheight, qbyte *palette) -{ - mpic_t pic; - LPDIRECT3DBASETEXTURE9 *p; - p = (LPDIRECT3DBASETEXTURE9*)&pic.d; - *p = D3D9_LoadTexture_8_Pal24("", (unsigned char*)framedata, inwidth, inheight, TF_NOMIPMAP|TF_NOALPHA|TF_NOTBUMPMAP, palette, 256); - - D3D9_Set2D (); - D3D9_Draw_ImageColours(1,1,1,1); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - D3D9_Draw_Image(0, 0, vid.width, vid.height, 0, 0, 1, 1, &pic); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - D3D9_UnloadTexture(*p); -} //paletted topdown (framedata is 8bit indexes into palette) -#endif diff --git a/engine/d3d9/d3d9_mesh.c b/engine/d3d9/d3d9_mesh.c deleted file mode 100644 index a3f0b23ff..000000000 --- a/engine/d3d9/d3d9_mesh.c +++ /dev/null @@ -1,728 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "d3d9quake.h" - -#ifdef _WIN32 -#include -#else -#include -#endif - -extern cvar_t r_fullbrightSkins; -extern cvar_t r_vertexdlights; - - -typedef struct { - float x, y, z; - float s, t; -} meshvert_t; - -typedef struct { - float x, y, z; - unsigned int colour; - float s, t; -} meshcolouredvert_t; - -void D3D9_DrawMesh(mesh_t *mesh) -{ - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - { - int v; - vec3_t *xyz; - byte_vec4_t *colour; - vec2_t *wm; - xyz = mesh->xyz_array; - wm = mesh->st_array; - colour = mesh->colors_array; - - if (colour) - { - meshcolouredvert_t *meshvert = alloca(sizeof(meshcolouredvert_t)*mesh->numvertexes); - - for (v = 0; v < mesh->numvertexes; v++, xyz++, wm++, colour++) - { - meshvert[v].x = (*xyz)[0]; - meshvert[v].y = (*xyz)[1]; - meshvert[v].z = (*xyz)[2]; - meshvert[v].colour = *(unsigned int*)colour; - meshvert[v].s = (*wm)[0]; - meshvert[v].t = (*wm)[1]; - } - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, mesh->numvertexes, mesh->numindexes/3, mesh->indexes, D3DFMT_QINDEX, meshvert, sizeof(meshvert[0])); - } - else - { - meshvert_t *meshvert = alloca(sizeof(meshvert_t)*mesh->numvertexes); - - for (v = 0; v < mesh->numvertexes; v++, xyz++, wm++) - { - meshvert[v].x = (*xyz)[0]; - meshvert[v].y = (*xyz)[1]; - meshvert[v].z = (*xyz)[2]; - meshvert[v].s = (*wm)[0]; - meshvert[v].t = (*wm)[1]; - } - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, mesh->numvertexes, mesh->numindexes/3, mesh->indexes, D3DFMT_QINDEX, meshvert, sizeof(meshvert[0])); - } - } -} - - - - -hashtable_t skincolourmapped; - -void d3d9_GAliasFlushSkinCache(void) -{ - int i; - bucket_t *b; - for (i = 0; i < skincolourmapped.numbuckets; i++) - { - while((b = skincolourmapped.bucket[i])) - { - skincolourmapped.bucket[i] = b->next; - BZ_Free(b->data); - } - } - if (skincolourmapped.bucket) - BZ_Free(skincolourmapped.bucket); - skincolourmapped.bucket = NULL; - skincolourmapped.numbuckets = 0; -} - -static galiastexnum_t *D3D9_ChooseSkin(galiasinfo_t *inf, char *modelname, int surfnum, entity_t *e) -{ - galiasskin_t *skins; - galiastexnum_t *texnums; - int frame; - - int tc, bc; - - if (!gl_nocolors.value) - { - if (e->scoreboard) - { - if (!e->scoreboard->skin) - Skin_Find(e->scoreboard); - tc = e->scoreboard->ttopcolor; - bc = e->scoreboard->tbottomcolor; - } - else - { - tc = 1; - bc = 1; - } - - if (tc != 1 || bc != 1 || (e->scoreboard && e->scoreboard->skin)) - { - int inwidth, inheight; - int tinwidth, tinheight; - char *skinname; - qbyte *original; - galiascolourmapped_t *cm; - char hashname[512]; - - if (e->scoreboard && e->scoreboard->skin && !gl_nocolors.value) - { - snprintf(hashname, sizeof(hashname), "%s$%s$%i", modelname, e->scoreboard->skin->name, surfnum); - skinname = hashname; - } - else if (surfnum) - { - snprintf(hashname, sizeof(hashname), "%s$%i", modelname, surfnum); - skinname = hashname; - } - else - skinname = modelname; - - if (!skincolourmapped.numbuckets) - { - void *buckets = BZ_Malloc(Hash_BytesForBuckets(256)); - memset(buckets, 0, Hash_BytesForBuckets(256)); - Hash_InitTable(&skincolourmapped, 256, buckets); - } - - for (cm = Hash_Get(&skincolourmapped, skinname); cm; cm = Hash_GetNext(&skincolourmapped, skinname, cm)) - { - if (cm->tcolour == tc && cm->bcolour == bc && cm->skinnum == e->skinnum) - { - return &cm->texnum; - } - } - - if (!inf->numskins) - { - skins = NULL; - texnums = NULL; - } - else - { - skins = (galiasskin_t*)((char *)inf + inf->ofsskins); - if (!skins->texnums) - { - skins = NULL; - texnums = NULL; - } - else - { - if (e->skinnum >= 0 && e->skinnum < inf->numskins) - skins += e->skinnum; - texnums = (galiastexnum_t*)((char *)skins + skins->ofstexnums); - } - } - - //colourmap isn't present yet. - cm = BZ_Malloc(sizeof(*cm)); - Q_strncpyz(cm->name, skinname, sizeof(cm->name)); - Hash_Add(&skincolourmapped, cm->name, cm, &cm->bucket); - cm->tcolour = tc; - cm->bcolour = bc; - cm->skinnum = e->skinnum; - cm->texnum.fullbright = 0; - cm->texnum.base = 0; -#ifdef Q3SHADERS - cm->texnum.shader = NULL; -#endif - - if (!texnums) - { //load just the skin (q2) -/* if (e->scoreboard && e->scoreboard->skin) - { - if (cls.protocol == CP_QUAKE2) - { - original = Skin_Cache32(e->scoreboard->skin); - if (original) - { - inwidth = e->scoreboard->skin->width; - inheight = e->scoreboard->skin->height; - cm->texnum.base = cm->texnum.fullbright = GL_LoadTexture32(e->scoreboard->skin->name, inwidth, inheight, (unsigned int*)original, true, false); - return &cm->texnum; - } - } - else - { - original = Skin_Cache8(e->scoreboard->skin); - if (original) - { - inwidth = e->scoreboard->skin->width; - inheight = e->scoreboard->skin->height; - cm->texnum.base = cm->texnum.fullbright = GL_LoadTexture(e->scoreboard->skin->name, inwidth, inheight, original, true, false); - return &cm->texnum; - } - } - - cm->texnum.base = Mod_LoadHiResTexture(e->scoreboard->skin->name, "skins", true, false, true); - return &cm->texnum; - } -*/ - return NULL; - } - - cm->texnum.bump = texnums[cm->skinnum].bump; //can't colour bumpmapping - if (cls.protocol != CP_QUAKE2 && ((!texnums || !strcmp(modelname, "progs/player.mdl")) && e->scoreboard && e->scoreboard->skin)) - { - original = Skin_Cache8(e->scoreboard->skin); - inwidth = e->scoreboard->skin->width; - inheight = e->scoreboard->skin->height; - } - else - { - original = NULL; - inwidth = 0; - inheight = 0; - } - if (!original) - { - if (skins->ofstexels) - { - original = (qbyte *)skins + skins->ofstexels; - inwidth = skins->skinwidth; - inheight = skins->skinheight; - } - else - { - original = NULL; - inwidth = 0; - inheight = 0; - } - } - tinwidth = skins->skinwidth; - tinheight = skins->skinheight; - if (original) - { - int i, j; - qbyte translate[256]; - unsigned translate32[256]; - static unsigned pixels[512*512]; - unsigned *out; - unsigned frac, fracstep; - - unsigned scaled_width, scaled_height; - qbyte *inrow; - - texnums = &cm->texnum; - - texnums->base = 0; - texnums->fullbright = 0; - - if (gl_max_size.value <= 0) - gl_max_size.value = 512; - - scaled_width = gl_max_size.value < 512 ? gl_max_size.value : 512; - scaled_height = gl_max_size.value < 512 ? gl_max_size.value : 512; - -#if 1 - { - for (i=0 ; i<256 ; i++) - translate32[i] = d_8to24rgbtable[i]; - - for (i = 0; i < 16; i++) - { - if (tc >= 16) - { - //assumption: row 0 is pure white. - *((unsigned char*)&translate32[TOP_RANGE+i]+0) = (((tc&0xff0000)>>16)**((unsigned char*)&d_8to24rgbtable[i]+0))>>8; - *((unsigned char*)&translate32[TOP_RANGE+i]+1) = (((tc&0x00ff00)>> 8)**((unsigned char*)&d_8to24rgbtable[i]+1))>>8; - *((unsigned char*)&translate32[TOP_RANGE+i]+2) = (((tc&0x0000ff)>> 0)**((unsigned char*)&d_8to24rgbtable[i]+2))>>8; - *((unsigned char*)&translate32[TOP_RANGE+i]+3) = 0xff; - } - else - { - if (tc < 8) - translate32[TOP_RANGE+i] = d_8to24rgbtable[(tc<<4)+i]; - else - translate32[BOTTOM_RANGE+i] = d_8to24rgbtable[(tc<<4)+15-i]; - } - if (bc >= 16) - { - *((unsigned char*)&translate32[BOTTOM_RANGE+i]+0) = (((bc&0xff0000)>>16)**((unsigned char*)&d_8to24rgbtable[i]+0))>>8; - *((unsigned char*)&translate32[BOTTOM_RANGE+i]+1) = (((bc&0x00ff00)>> 8)**((unsigned char*)&d_8to24rgbtable[i]+1))>>8; - *((unsigned char*)&translate32[BOTTOM_RANGE+i]+2) = (((bc&0x0000ff)>> 0)**((unsigned char*)&d_8to24rgbtable[i]+2))>>8; - *((unsigned char*)&translate32[BOTTOM_RANGE+i]+3) = 0xff; - } - else - { - if (bc < 8) - translate32[BOTTOM_RANGE+i] = d_8to24rgbtable[(bc<<4)+i]; - else - translate32[BOTTOM_RANGE+i] = d_8to24rgbtable[(bc<<4)+15-i]; - } - } - } -#else - for (i=0 ; i<256 ; i++) - translate[i] = i; - - tc<<=4; - bc<<=4; - - for (i=0 ; i<16 ; i++) - { - if (tc < 128) // the artists made some backwards ranges. sigh. - translate[TOP_RANGE+i] = tc+i; - else - translate[TOP_RANGE+i] = tc+15-i; - - if (bc < 128) - translate[BOTTOM_RANGE+i] = bc+i; - else - translate[BOTTOM_RANGE+i] = bc+15-i; - } - - - for (i=0 ; i<256 ; i++) - translate32[i] = d_8to24rgbtable[translate[i]]; -#endif - - out = pixels; - fracstep = tinwidth*0x10000/scaled_width; - for (i=0 ; i> 1; - for (j=0 ; j>16]] | 0xff000000; - frac += fracstep; - out[j+1] = translate32[inrow[frac>>16]] | 0xff000000; - frac += fracstep; - out[j+2] = translate32[inrow[frac>>16]] | 0xff000000; - frac += fracstep; - out[j+3] = translate32[inrow[frac>>16]] | 0xff000000; - frac += fracstep; - } - } - texnums->base = D3D9_LoadTexture_32 ("", pixels, scaled_width, scaled_height, TF_NOTBUMPMAP); -/* texnums->base = texture_extension_number++; - GL_Bind(texnums->base); - qglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -*/ - - //now do the fullbrights. - out = pixels; - fracstep = tinwidth*0x10000/scaled_width; - for (i=0 ; i> 1; - for (j=0 ; j>16] < 255-vid.fullbright) - ((char *) (&out[j]))[3] = 0; //alpha 0 - frac += fracstep; - } - } -/* texnums->fullbright = texture_extension_number++; - GL_Bind(texnums->fullbright); - qglTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -*/ - } - else - { - skins = (galiasskin_t*)((char *)inf + inf->ofsskins); - if (e->skinnum >= 0 && e->skinnum < inf->numskins) - skins += e->skinnum; - - if (!inf->numskins || !skins->texnums) - return NULL; - - frame = cl.time*skins->skinspeed; - frame = frame%skins->texnums; - texnums = (galiastexnum_t*)((char *)skins + skins->ofstexnums + frame*sizeof(galiastexnum_t)); - memcpy(&cm->texnum, texnums, sizeof(cm->texnum)); - } - return &cm->texnum; - } - } - - if (!inf->numskins) - return NULL; - - skins = (galiasskin_t*)((char *)inf + inf->ofsskins); - if (e->skinnum >= 0 && e->skinnum < inf->numskins) - skins += e->skinnum; - else - { - Con_DPrintf("Skin number out of range\n"); - if (!inf->numskins) - return NULL; - } - - if (!skins->texnums) - return NULL; - - frame = cl.time*skins->skinspeed; - frame = frame%skins->texnums; - texnums = (galiastexnum_t*)((char *)skins + skins->ofstexnums + frame*sizeof(galiastexnum_t)); - - return texnums; -} - - -extern vec3_t shadevector; -extern vec3_t ambientlight; -extern vec3_t shadelight; - -static void LotsOfLightDirectionHacks(entity_t *e, model_t *m, vec3_t lightaxis[3]) -{ - int i; - vec3_t dist; - float add; - qboolean nolightdir; - vec3_t lightdir; - - - if (!(r_refdef.flags & Q2RDF_NOWORLDMODEL)) - { - if (e->flags & Q2RF_WEAPONMODEL) - cl.worldmodel->funcs.LightPointValues(cl.worldmodel, r_refdef.vieworg, shadelight, ambientlight, lightdir); - else - cl.worldmodel->funcs.LightPointValues(cl.worldmodel, e->origin, shadelight, ambientlight, lightdir); - } - else - { - ambientlight[0] = ambientlight[1] = ambientlight[2] = shadelight[0] = shadelight[1] = shadelight[2] = 255; - lightdir[0] = 0; - lightdir[1] = 1; - lightdir[2] = 1; - } - - if (!r_vertexdlights.value) - { - for (i=0 ; iorigin, - cl_dlights[i].origin, - dist); - add = cl_dlights[i].radius - Length(dist); - - if (add > 0) { - add*=5; - ambientlight[0] += add * cl_dlights[i].color[0]; - ambientlight[1] += add * cl_dlights[i].color[1]; - ambientlight[2] += add * cl_dlights[i].color[2]; - //ZOID models should be affected by dlights as well - shadelight[0] += add * cl_dlights[i].color[0]; - shadelight[1] += add * cl_dlights[i].color[1]; - shadelight[2] += add * cl_dlights[i].color[2]; - } - } - } - } - else - { - } - - for (i = 0; i < 3; i++) //clamp light so it doesn't get vulgar. - { - if (ambientlight[i] > 128) - ambientlight[i] = 128; - if (ambientlight[i] + shadelight[i] > 192) - shadelight[i] = 192 - ambientlight[i]; - } - - if (e->flags & Q2RF_WEAPONMODEL) - { - for (i = 0; i < 3; i++) - { - if (ambientlight[i] < 24) - ambientlight[i] = shadelight[i] = 24; - } - } - -//MORE HUGE HACKS! WHEN WILL THEY CEASE! - // clamp lighting so it doesn't overbright as much - // ZOID: never allow players to go totally black - nolightdir = false; - if (m->engineflags & MDLF_PLAYER) - { - float fb = r_fullbrightSkins.value; - if (fb > cls.allow_fbskins) - fb = cls.allow_fbskins; - if (fb < 0) - fb = 0; - if (fb) - { - extern cvar_t r_fb_models; - - if (fb >= 1 && r_fb_models.value) - { - ambientlight[0] = ambientlight[1] = ambientlight[2] = 4096; - shadelight[0] = shadelight[1] = shadelight[2] = 4096; - nolightdir = true; - } - else - { - for (i = 0; i < 3; i++) - { - ambientlight[i] = max(ambientlight[i], 8 + fb * 120); - shadelight[i] = max(shadelight[i], 8 + fb * 120); - } - } - } - for (i = 0; i < 3; i++) - { - if (ambientlight[i] < 8) - ambientlight[i] = shadelight[i] = 8; - } - } - if (m->engineflags & MDLF_FLAME) - { - shadelight[0] = shadelight[1] = shadelight[2] = 4096; - ambientlight[0] = ambientlight[1] = ambientlight[2] = 4096; - nolightdir = true; - } - else - { - for (i = 0; i < 3; i++) - { - if (ambientlight[i] > 128) - ambientlight[i] = 128; - - shadelight[i] /= 200.0/255; - ambientlight[i] /= 200.0/255; - } - } - - if ((e->drawflags & MLS_MASKIN) == MLS_ABSLIGHT) - { - shadelight[0] = shadelight[1] = shadelight[2] = e->abslight; - ambientlight[0] = ambientlight[1] = ambientlight[2] = 0; - } - if ((e->drawflags & MLS_MASKIN) == MLS_FULLBRIGHT || (e->flags & Q2RF_FULLBRIGHT)) - { - shadelight[0] = shadelight[1] = shadelight[2] = 255; - ambientlight[0] = ambientlight[1] = ambientlight[2] = 0; - nolightdir = true; - } - -//#define SHOWLIGHTDIR - { //lightdir is absolute, shadevector is relative - shadevector[0] = DotProduct(lightdir, e->axis[0]); - shadevector[1] = DotProduct(lightdir, e->axis[1]); - shadevector[2] = DotProduct(lightdir, e->axis[2]); - - if (e->flags & Q2RF_WEAPONMODEL) - { - vec3_t temp; - temp[0] = DotProduct(shadevector, vpn); - temp[1] = DotProduct(shadevector, vright); - temp[2] = DotProduct(shadevector, vup); - - VectorCopy(temp, shadevector); - } - - VectorNormalize(shadevector); - - VectorCopy(shadevector, lightaxis[2]); - VectorVectors(lightaxis[2], lightaxis[1], lightaxis[0]); - VectorInverse(lightaxis[1]); - } - - if (e->flags & Q2RF_GLOW) - { - shadelight[0] += sin(cl.time)*0.25; - shadelight[1] += sin(cl.time)*0.25; - shadelight[2] += sin(cl.time)*0.25; - } - - //d3d is bgra - //ogl is rgba - //so switch em and use the gl code - add = shadelight[0]; - shadelight[0] = shadelight[2]; - shadelight[2] = add; - - add = ambientlight[0]; - ambientlight[0] = ambientlight[2]; - ambientlight[2] = add; -} - - -qboolean R_GAliasBuildMesh(mesh_t *mesh, galiasinfo_t *inf, int frame1, int frame2, float lerp, float alpha, float fg1time, float fg2time, qboolean nolightdir); -//draws currententity -void D3D9_DrawAliasModel(void) -{ - mesh_t mesh; - extern entity_t *currententity; - entity_t *e = currententity; - galiasinfo_t *inf; - model_t *m; - galiastexnum_t *skin; - int i; - - if (r_secondaryview && e->flags & Q2RF_WEAPONMODEL) - return; - - { - extern int cl_playerindex; - if (e->scoreboard && e->model == cl.model_precache[cl_playerindex]) - { - m = e->scoreboard->model; - if (!m || m->type != mod_alias) - m = e->model; - } - else - m = e->model; - } - - if (!(e->flags & Q2RF_WEAPONMODEL)) - if (R_CullEntityBox (e, m->mins, m->maxs)) - return; - - - inf = GLMod_Extradata (m); - - if (!inf) - return; - - - LotsOfLightDirectionHacks(e, m, mesh.lightaxis); - - - { - float matrix[16]; - - if (e->flags & Q2RF_WEAPONMODEL && r_refdef.currentplayernum>=0) - { //view weapons need to be rotated onto the screen first - float view[16]; - float ent[16]; - Matrix4_ModelMatrixFromAxis(view, cl.viewent[r_refdef.currentplayernum].axis[0], cl.viewent[r_refdef.currentplayernum].axis[1], cl.viewent[r_refdef.currentplayernum].axis[2], cl.viewent[r_refdef.currentplayernum].origin); - Matrix4_ModelMatrixFromAxis(ent, e->axis[0], e->axis[1], e->axis[2], e->origin); - Matrix4_Multiply(view, ent, matrix); - } - else - { - Matrix4_ModelMatrixFromAxis(matrix, e->axis[0], e->axis[1], e->axis[2], e->origin); - } - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_WORLD, (D3DMATRIX*)matrix); - } - -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - -if (e->flags & Q2RF_DEPTHHACK) -{ //apply the depth hack to stop things from poking into walls. - //(basically moving it closer to the screen) - D3DVIEWPORT9 viewport; - IDirect3DDevice9_GetViewport(pD3DDev9, &viewport); - viewport.MinZ = 0; - viewport.MaxZ = 0.3; - IDirect3DDevice9_SetViewport(pD3DDev9, &viewport); -} - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - - for(i = 0;; i++) - { - Alias_GAliasBuildMesh(&mesh, inf, e, e->shaderRGBAf[3], 0); - - skin = D3D9_ChooseSkin(inf, m->name, e->skinnum, e); - if (!skin) - IDirect3DDevice9_SetTexture(pD3DDev9, 0, NULL); - else - IDirect3DDevice9_SetTexture(pD3DDev9, 0, skin->base); - D3D9_DrawMesh(&mesh); - - if (inf->nextsurf == 0) - break; - inf = (galiasinfo_t*)((char*)inf + inf->nextsurf); - } - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); - -if (e->flags & Q2RF_DEPTHHACK) -{ - D3DVIEWPORT9 viewport; - IDirect3DDevice9_GetViewport(pD3DDev9, &viewport); - viewport.MinZ = 0; - viewport.MaxZ = 1; - IDirect3DDevice9_SetViewport(pD3DDev9, &viewport); -} - - { - float matrix[16]; - Matrix4_Identity(matrix); - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_WORLD, (D3DMATRIX*)matrix); - } -} -#endif diff --git a/engine/d3d9/d3d9_rmain.c b/engine/d3d9/d3d9_rmain.c deleted file mode 100644 index 6edb64fa5..000000000 --- a/engine/d3d9/d3d9_rmain.c +++ /dev/null @@ -1,1890 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "winquake.h" -#include "d3d9quake.h" -#include "renderque.h" - -mleaf_t *r_viewleaf, *r_oldviewleaf; -mleaf_t *r_viewleaf2, *r_oldviewleaf2; -int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2; -extern qbyte areabits[MAX_Q2MAP_AREAS/8]; - - -int r_visframecount; -entity_t r_worldentity; -refdef_t r_refdef; -vec3_t r_origin, vpn, vright, vup; -extern float r_projection_matrix[16]; -extern float r_view_matrix[16]; - - -extern mplane_t frustum[4]; - -vec3_t modelorg; - -entity_t *currententity; -extern cvar_t gl_mindist; - - -void (D3D9_R_DeInit) (void) -{ - int i; - -#ifdef Q3SHADERS - Shader_Shutdown(); -#endif - - - for (i = 0; i < numlightmaps; i++) - { - if (!lightmap[i]) - break; - BZ_Free(lightmap[i]); - lightmap[i] = NULL; - } - - if (lightmap_d3d9textures) - BZ_Free(lightmap_d3d9textures); - if (lightmap) - BZ_Free(lightmap); - - lightmap_d3d9textures=NULL; - lightmap=NULL; - numlightmaps=0; -} -void (D3D9_R_ReInit) (void) -{ -} -void (D3D9_R_Init) (void) -{ - D3D9_R_ReInit(); -} - -//most of this is a direct copy from gl -void (D3D9_SetupFrame) (void) -{ - mleaf_t *leaf; - vec3_t temp; - - GLR_AnimateLight(); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); - VectorCopy (r_refdef.vieworg, r_origin); - r_framecount++; - - if (r_refdef.flags & Q2RDF_NOWORLDMODEL) - { - } -#ifdef Q2BSPS - else if (cl.worldmodel && (cl.worldmodel->fromgame == fg_quake2 || cl.worldmodel->fromgame == fg_quake3)) - { - static mleaf_t fakeleaf; - mleaf_t *leaf; - - r_viewleaf = &fakeleaf; //so we can use quake1 rendering routines for q2 bsps. - r_viewleaf->contents = Q1CONTENTS_EMPTY; - r_viewleaf2 = NULL; - - r_oldviewcluster = r_viewcluster; - r_oldviewcluster2 = r_viewcluster2; - leaf = GLMod_PointInLeaf (cl.worldmodel, r_origin); - r_viewcluster = r_viewcluster2 = leaf->cluster; - - // check above and below so crossing solid water doesn't draw wrong - if (!leaf->contents) - { // look down a bit - vec3_t temp; - - VectorCopy (r_origin, temp); - temp[2] -= 16; - leaf = GLMod_PointInLeaf (cl.worldmodel, temp); - if ( !(leaf->contents & Q2CONTENTS_SOLID) && - (leaf->cluster != r_viewcluster2) ) - r_viewcluster2 = leaf->cluster; - } - else - { // look up a bit - vec3_t temp; - - VectorCopy (r_origin, temp); - temp[2] += 16; - leaf = GLMod_PointInLeaf (cl.worldmodel, temp); - if ( !(leaf->contents & Q2CONTENTS_SOLID) && - (leaf->cluster != r_viewcluster2) ) - r_viewcluster2 = leaf->cluster; - } - } -#endif - else - { - r_oldviewleaf = r_viewleaf; - r_oldviewleaf2 = r_viewleaf2; - r_viewleaf = GLMod_PointInLeaf (cl.worldmodel, r_origin); - - if (!r_viewleaf) - { - } - else if (r_viewleaf->contents == Q1CONTENTS_EMPTY) - { //look down a bit - VectorCopy (r_origin, temp); - temp[2] -= 16; - leaf = GLMod_PointInLeaf (cl.worldmodel, temp); - if (leaf->contents <= Q1CONTENTS_WATER && leaf->contents >= Q1CONTENTS_LAVA) - r_viewleaf2 = leaf; - else - r_viewleaf2 = NULL; - } - else if (r_viewleaf->contents <= Q1CONTENTS_WATER && r_viewleaf->contents >= Q1CONTENTS_LAVA) - { //in water, look up a bit. - - VectorCopy (r_origin, temp); - temp[2] += 16; - leaf = GLMod_PointInLeaf (cl.worldmodel, temp); - if (leaf->contents == Q1CONTENTS_EMPTY) - r_viewleaf2 = leaf; - else - r_viewleaf2 = NULL; - } - else - r_viewleaf2 = NULL; - - if (r_viewleaf) - V_SetContentsColor (r_viewleaf->contents); - } -} - -void D3D9_SetupViewPort(void) -{ - float screenaspect; - int glwidth = vid.width, glheight=vid.height; - int x, x2, y2, y, w, h; - - float fov_x, fov_y; - - D3DVIEWPORT9 vport; - - D3D9_GetBufferSize(&glwidth, &glheight); - - // - // set up viewpoint - // - x = r_refdef.vrect.x * glwidth/(int)vid.width; - x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/(int)vid.width; - y = (/*vid.height-*/r_refdef.vrect.y) * glheight/(int)vid.height; - y2 = ((int)/*vid.height - */(r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/(int)vid.height; - - // fudge around because of frac screen scale - if (x > 0) - x--; - if (x2 < glwidth) - x2++; - if (y < 0) - y--; - if (y2 < glheight) - y2++; - - w = x2 - x; - h = y2 - y; - -/* if (envmap) - { - x = y2 = 0; - w = h = 256; - } -*/ - - vport.X = x; - vport.Y = y; - vport.Width = w; - vport.Height = h; - vport.MinZ = 0; - vport.MaxZ = 1; - IDirect3DDevice9_SetViewport(pD3DDev9, &vport); - - fov_x = r_refdef.fov_x;//+sin(cl.time)*5; - fov_y = r_refdef.fov_y;//-sin(cl.time+1)*5; - - if (r_waterwarp.value<0 && r_viewleaf->contents <= Q1CONTENTS_WATER) - { - fov_x *= 1 + (((sin(cl.time * 4.7) + 1) * 0.015) * r_waterwarp.value); - fov_y *= 1 + (((sin(cl.time * 3.0) + 1) * 0.015) * r_waterwarp.value); - } - - screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height; -// if (r_refdef.useperspective) - { -/* if ((!r_shadows.value || !gl_canstencil) && gl_maxdist.value>256)//gl_nv_range_clamp) - { - // yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI; - // yfov = (2.0 * tan (scr_fov.value/360*M_PI)) / screenaspect; - // yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*(scr_fov.value*2)/M_PI; - // MYgluPerspective (yfov, screenaspect, 4, 4096); - MYgluPerspective (fov_x, fov_y, gl_mindist.value, gl_maxdist.value); - } - else*/ - { - GL_InfinatePerspective(fov_x, fov_y, gl_mindist.value); - } - } -/* else - { - if (gl_maxdist.value>=1) - GL_ParallelPerspective(-fov_x/2, fov_x/2, fov_y/2, -fov_y/2, -gl_maxdist.value, gl_maxdist.value); - else - GL_ParallelPerspective(0, r_refdef.vrect.width, 0, r_refdef.vrect.height, -9999, 9999); - }*/ - - Matrix4_ModelViewMatrixFromAxis(r_view_matrix, vpn, vright, vup, r_refdef.vieworg); - - - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_PROJECTION, (D3DMATRIX*)r_projection_matrix); - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_VIEW, (D3DMATRIX*)r_view_matrix); - - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_LESSEQUAL); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZENABLE, D3DZB_TRUE); -} - - - - - - -qbyte *Q1BSP_LeafPVS (model_t *model, mleaf_t *leaf, qbyte *buffer); - - - -//fixme: direct copy from gl (apart from lightmaps) -static void D3D9_RecursiveWorldNode (mnode_t *node) -{ - int c, side; - mplane_t *plane; - msurface_t *surf, **mark; - mleaf_t *pleaf; - double dot; - int shift; - -start: - - if (node->contents == Q1CONTENTS_SOLID) - return; // solid - - if (node->visframe != r_visframecount) - return; - if (R_CullBox (node->minmaxs, node->minmaxs+3)) - return; - -// if a leaf node, draw stuff - if (node->contents < 0) - { - pleaf = (mleaf_t *)node; - - mark = pleaf->firstmarksurface; - c = pleaf->nummarksurfaces; - - if (c) - { - do - { - (*mark++)->visframe = r_framecount; - } while (--c); - } - - // deal with model fragments in this leaf - if (pleaf->efrags) - R_StoreEfrags (&pleaf->efrags); - return; - } - -// node is just a decision point, so go down the apropriate sides - -// find which side of the node we are on - plane = node->plane; - - switch (plane->type) - { - case PLANE_X: - dot = modelorg[0] - plane->dist; - break; - case PLANE_Y: - dot = modelorg[1] - plane->dist; - break; - case PLANE_Z: - dot = modelorg[2] - plane->dist; - break; - default: - dot = DotProduct (modelorg, plane->normal) - plane->dist; - break; - } - - if (dot >= 0) - side = 0; - else - side = 1; - -// recurse down the children, front side first - D3D9_RecursiveWorldNode (node->children[side]); - -// draw stuff - c = node->numsurfaces; - - if (c) - { - surf = cl.worldmodel->surfaces + node->firstsurface; - - shift = 0;//GLR_LightmapShift(cl.worldmodel); - -// if (dot < 0 -BACKFACE_EPSILON) -// side = SURF_PLANEBACK; -// else if (dot > BACKFACE_EPSILON) -// side = 0; - { - for ( ; c ; c--, surf++) - { - if (surf->visframe != r_framecount) - continue; - -// if (((dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))) -// continue; // wrong side - - D3DR_RenderDynamicLightmaps (surf, shift); - // if sorting by texture, just store it out -/* if (surf->flags & SURF_DRAWALPHA) - { // add to the translucent chain - surf->nextalphasurface = r_alpha_surfaces; - r_alpha_surfaces = surf; - surf->ownerent = &r_worldentity; - } - else -*/ { - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; - } - } - } - } - -// recurse down the back side -// D3D9_RecursiveWorldNode (node->children[!side]); - node = node->children[!side]; - goto start; -} - -//fixme: direct copy from gl (apart from lightmaps) -static void D3D9_RecursiveQ2WorldNode (mnode_t *node) -{ - int c, side; - mplane_t *plane; - msurface_t *surf, **mark; - mleaf_t *pleaf; - double dot; - int shift; - -start: - - if (node->contents == Q2CONTENTS_SOLID) - return; // solid - - if (node->visframe != r_visframecount) - return; - if (R_CullBox (node->minmaxs, node->minmaxs+3)) - return; - -// if a leaf node, draw stuff - if (node->contents < 0) - { - pleaf = (mleaf_t *)node; - - mark = pleaf->firstmarksurface; - c = pleaf->nummarksurfaces; - - if (c) - { - do - { - (*mark++)->visframe = r_framecount; - } while (--c); - } - - // deal with model fragments in this leaf - if (pleaf->efrags) - R_StoreEfrags (&pleaf->efrags); - return; - } - -// node is just a decision point, so go down the apropriate sides - -// find which side of the node we are on - plane = node->plane; - - switch (plane->type) - { - case PLANE_X: - dot = modelorg[0] - plane->dist; - break; - case PLANE_Y: - dot = modelorg[1] - plane->dist; - break; - case PLANE_Z: - dot = modelorg[2] - plane->dist; - break; - default: - dot = DotProduct (modelorg, plane->normal) - plane->dist; - break; - } - - if (dot >= 0) - side = 0; - else - side = 1; - -// recurse down the children, front side first - D3D9_RecursiveQ2WorldNode (node->children[side]); - -// draw stuff - c = node->numsurfaces; - - if (c) - { - surf = cl.worldmodel->surfaces + node->firstsurface; - - shift = 0;//GLR_LightmapShift(cl.worldmodel); - -// if (dot < 0 -BACKFACE_EPSILON) -// side = SURF_PLANEBACK; -// else if (dot > BACKFACE_EPSILON) -// side = 0; - { - for ( ; c ; c--, surf++) - { - if (surf->visframe != r_framecount) - continue; - -// if (((dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))) -// continue; // wrong side - - D3DR_RenderDynamicLightmaps (surf, shift); - // if sorting by texture, just store it out -/* if (surf->flags & SURF_DRAWALPHA) - { // add to the translucent chain - surf->nextalphasurface = r_alpha_surfaces; - r_alpha_surfaces = surf; - surf->ownerent = &r_worldentity; - } - else -*/ { - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; - } - } - } - } - -// recurse down the back side -// D3D9_RecursiveWorldNode (node->children[!side]); - node = node->children[!side]; - goto start; -} - -#ifdef Q3BSPS -extern mleaf_t *r_vischain; // linked list of visible leafs -static void D3D9_LeafWorldNode (void) -{ - int i; - int clipflags; - msurface_t **mark, *surf; - mleaf_t *pleaf; - - - int clipped; - mplane_t *clipplane; - - - for ( pleaf = r_vischain; pleaf; pleaf = pleaf->vischain ) - { - // check for door connected areas -// if ( areabits ) - { -// if (! (areabits[pleaf->area>>3] & (1<<(pleaf->area&7)) ) ) -// { -// continue; // not visible -// } - } - - clipflags = 15; // 1 | 2 | 4 | 8 -// if ( !r_nocull->value ) - { - - for (i=0,clipplane=frustum ; i<4 ; i++,clipplane++) - { - clipped = BoxOnPlaneSide ( pleaf->minmaxs, pleaf->minmaxs+3, clipplane ); - if ( clipped == 2 ) { - break; - } else if ( clipped == 1 ) { - clipflags &= ~(1<nummarksurfaces; - mark = pleaf->firstmarksurface; - - do - { - surf = *mark++; - if ( surf->visframe != r_framecount ) //sufraces exist in multiple leafs. - { - surf->visframe = r_framecount; - - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; - } - } while (--i); - -// c_world_leafs++; - } -} -#endif - -struct { - float x, y, z; -// unsigned colour; - float wms, wmt; - float lms, lmt; -} worldvert[1024]; -void D3D9_DrawTextureChains(void) -{ - texture_t *t; - msurface_t *s; - vec3_t *xyz; - vec2_t *wm; - vec2_t *lm; - mesh_t *m; - int i; - int v; - int lmnum; - extern int skytexturenum; // index in cl.loadmodel, not gl texture object - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - - - if (skytexturenum>=0) - { - t = currentmodel->textures[skytexturenum]; - if (t) - { - s = t->texturechain; - if (s) - { - t->texturechain = NULL; - D3D9_DrawSkyChain (s); - } - } - } - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - for (i = 0; i < currentmodel->numtextures; i++) - { - t = currentmodel->textures[i]; - if (!t) - continue; //happens on e1m2 - s = t->texturechain; - if (!s) - continue; - t->texturechain = NULL; - - if (s->flags & SURF_DRAWTURB) - { - IDirect3DDevice9_SetTexture(pD3DDev9, 0, (void*)t->tn.base); - -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_TEXCOORDINDEX, 0); -IDirect3DDevice9_SetTexture(pD3DDev9, 0, (void*)t->tn.base); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_TEXCOORDINDEX, 1); -IDirect3DDevice9_SetTexture(pD3DDev9, 1, (void*)t->tn.base); - -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLORARG2, D3DTA_CURRENT); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X); - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - - - while(s) - { - m = s->mesh; - xyz = m->xyz_array; - wm = m->st_array; - lm = m->lmst_array; - for (v = 0; v < m->numvertexes; v++, xyz++, wm++, lm++) - { - worldvert[v].x = (*xyz)[0]; - worldvert[v].y = (*xyz)[1]; - worldvert[v].z = (*xyz)[2]; - // worldvert[v].colour = 0; - worldvert[v].wms = (*wm)[0] + cl.time*0.2; - worldvert[v].wmt = (*wm)[1] + cl.time*0.2 + 0.5; - worldvert[v].lms = (*wm)[0] + cl.time*0.1; - worldvert[v].lmt = (*wm)[1] + cl.time*0.1; - } - - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX2); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, m->numvertexes, m->numindexes/3, m->indexes, D3DFMT_QINDEX, worldvert, sizeof(worldvert[0])); - - s = s->texturechain; - } - lmnum = -4; - - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT); - - continue; - } - -IDirect3DDevice9_SetTexture(pD3DDev9, 0, (void*)t->tn.base); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_TEXCOORDINDEX, 0); - -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); -IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - - while(s) - { - m = s->mesh; - if (m) - { - - lmnum = s->lightmaptexturenum; - if (lmnum >= 0) - { - if (lightmap[lmnum]->modified) - { - D3DLOCKED_RECT desc; - - IDirect3DTexture9_LockRect(lightmap_d3d9textures[lmnum], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); - memcpy(desc.pBits, lightmap[lmnum]->lightmaps, LMBLOCK_WIDTH*LMBLOCK_HEIGHT*4); - /* { - int i; - unsigned char *c; - unsigned char v; - c = desc.lpSurface; - for (i = 0; i < LMBLOCK_WIDTH*LMBLOCK_HEIGHT; i++) - { - v = rand(); - *c++ = v; - *c++ = v; - *c++ = v; - c++; - } - }*/ - IDirect3DTexture9_UnlockRect(lightmap_d3d9textures[lmnum], 0); - - lightmap[lmnum]->modified = false; - } - - - IDirect3DDevice9_SetTexture(pD3DDev9, 1, (void*)lightmap_d3d9textures[lmnum]); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLORARG2, D3DTA_CURRENT); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_MODULATE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_TEXCOORDINDEX, 1); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - } - else - { - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - } - -//pD3DDev->lpVtbl->SetTextureStageState(pD3DDev, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - - xyz = m->xyz_array; - wm = m->st_array; - lm = m->lmst_array; - - if (!wm || !lm) - { - s = s->texturechain; - continue; - } - - for (v = 0; v < m->numvertexes; v++, xyz++, wm++, lm++) - { - worldvert[v].x = (*xyz)[0]; - worldvert[v].y = (*xyz)[1]; - worldvert[v].z = (*xyz)[2]; -// worldvert[v].colour = 0; - worldvert[v].wms = (*wm)[0]; - worldvert[v].wmt = (*wm)[1]; - worldvert[v].lms = (*lm)[0]; - worldvert[v].lmt = (*lm)[1]; - } - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX2); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, m->numvertexes, m->numindexes/3, m->indexes, D3DFMT_QINDEX, worldvert, sizeof(worldvert[0])); -// IDirect3DDevice9_DrawIndexedPrimitive(pD3DDev9, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_TEX2, worldvert, m->numvertexes, m->indexes, m->numindexes, 0); - } - s = s->texturechain; - } - } - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); -} - -void D3D9_BaseBModelTextures(entity_t *e) -{ - texture_t *t; - msurface_t *s; - vec3_t *xyz; - vec2_t *wm; - vec2_t *lm; - mesh_t *m; - int i; - int v; - float matrix[16]; - int lmnum = -1; - currentmodel = e->model; - - - for (s = currentmodel->surfaces+currentmodel->firstmodelsurface, i = 0; i < currentmodel->nummodelsurfaces; i++, s++) - { - t = R_TextureAnimation(s->texinfo->texture); - - { - m = s->mesh; - if (m) - D3DR_RenderDynamicLightmaps (s, 0); - } - } - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - - Matrix4_ModelMatrixFromAxis(matrix, e->axis[0], e->axis[1], e->axis[2], e->origin); - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_WORLD, (D3DMATRIX*)matrix); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - for (s = currentmodel->surfaces+currentmodel->firstmodelsurface, i = 0; i < currentmodel->nummodelsurfaces; i++, s++) - { - t = R_TextureAnimation(s->texinfo->texture); - - if (s->lightmaptexturenum < 0) - continue; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, (void*)t->tn.base); - IDirect3DDevice9_SetTexture(pD3DDev9, 1, (void*)lightmap_d3d9textures[s->lightmaptexturenum]); - { - m = s->mesh; - if (m) - { - - if (lmnum != s->lightmaptexturenum) - { - lmnum = s->lightmaptexturenum; - if (lmnum >= 0) - { -#if 0 - if (lightmap[lmnum]->modified) - { - DDSURFACEDESC2 desc; - - desc.dwSize = sizeof(desc); - lightmap_d3d9textures[lmnum]->lpVtbl->Lock(lightmap_d3dtextures[lmnum], NULL, &desc, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS, NULL); - memcpy(desc.lpSurface, lightmap[lmnum]->lightmaps, LMBLOCK_WIDTH*LMBLOCK_HEIGHT*4); - /* { - int i; - unsigned char *c; - unsigned char v; - c = desc.lpSurface; - for (i = 0; i < LMBLOCK_WIDTH*LMBLOCK_HEIGHT; i++) - { - v = rand(); - *c++ = v; - *c++ = v; - *c++ = v; - c++; - } - }*/ - lightmap_d3d9textures[lmnum]->lpVtbl->Unlock(lightmap_d3d9textures[lmnum], NULL); - - lightmap[lmnum]->modified = false; - } -#endif - - IDirect3DDevice9_SetTexture(pD3DDev9, 1, (void*)lightmap_d3d9textures[lmnum]); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLORARG2, D3DTA_CURRENT); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_MODULATE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_TEXCOORDINDEX, 1); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - } - else - { - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - } - } - - - - xyz = m->xyz_array; - wm = m->st_array; - lm = m->lmst_array; - - for (v = 0; v < m->numvertexes; v++, xyz++, wm++, lm++) - { - worldvert[v].x = (*xyz)[0]; - worldvert[v].y = (*xyz)[1]; - worldvert[v].z = (*xyz)[2]; -// worldvert[v].colour = 0; - worldvert[v].wms = (*wm)[0]; - worldvert[v].wmt = (*wm)[1]; - worldvert[v].lms = (*lm)[0]; - worldvert[v].lmt = (*lm)[1]; - } - - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX2); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, m->numvertexes, m->numindexes/3, m->indexes, D3DFMT_QINDEX, worldvert, sizeof(worldvert[0])); -// IDirect3DDevice9_DrawIndexedPrimitive(pD3DDev9, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_TEX2, worldvert, m->numvertexes, m->indexes, m->numindexes, 0); - } - } - } - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); - - - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_WORLD, (D3DMATRIX*)matrix); - - - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); -} - - - -typedef struct { - float pos[3]; - int colour; - float tc[2]; -} d3dvert_t; -/* -================ -R_GetSpriteFrame -================ -*/ -/* -mspriteframe_t *R_GetSpriteFrame (entity_t *currententity) -{ - msprite_t *psprite; - mspritegroup_t *pspritegroup; - mspriteframe_t *pspriteframe; - int i, numframes, frame; - float *pintervals, fullinterval, targettime, time; - - psprite = currententity->model->cache.data; - frame = currententity->frame; - - if ((frame >= psprite->numframes) || (frame < 0)) - { - Con_DPrintf ("R_DrawSprite: no such frame %d (%s)\n", frame, currententity->model->name); - frame = 0; - } - - if (psprite->frames[frame].type == SPR_SINGLE) - { - pspriteframe = psprite->frames[frame].frameptr; - } - else if (psprite->frames[frame].type == SPR_ANGLED) - { - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - pspriteframe = pspritegroup->frames[(int)((r_refdef.viewangles[1]-currententity->angles[1])/360*8 + 0.5-4)&7]; - } - else - { - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - pintervals = pspritegroup->intervals; - numframes = pspritegroup->numframes; - fullinterval = pintervals[numframes-1]; - - time = currententity->frame1time; - - // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values - // are positive, so we don't have to worry about division by 0 - targettime = time - ((int)(time / fullinterval)) * fullinterval; - - for (i=0 ; i<(numframes-1) ; i++) - { - if (pintervals[i] > targettime) - break; - } - - pspriteframe = pspritegroup->frames[i]; - } - - return pspriteframe; -} -*/ -static void D3D9_DrawSpriteModel (entity_t *e) -{ - vec3_t point; - mspriteframe_t *frame; - vec3_t forward, right, up; - msprite_t *psprite; - - d3dvert_t d3dvert[4]; - index_t vertindexes[6] = { - 0, 1, 2, - 0, 2, 3 - }; - -#ifdef Q3SHADERS - mpic_t *pic = e->forcedshader; -#else - mpic_t *pic = NULL; -#endif - - if (pic || !e->model) - { - int colour; - - colour = 0; - - ((unsigned char*)&colour)[0] = e->shaderRGBAf[2]*255; - ((unsigned char*)&colour)[1] = e->shaderRGBAf[1]*255; - ((unsigned char*)&colour)[2] = e->shaderRGBAf[0]*255; - ((unsigned char*)&colour)[3] = e->shaderRGBAf[3]*255; - - VectorCopy(vup, up); - VectorCopy(vright, right); - - up[0]*=e->scale; - up[1]*=e->scale; - up[2]*=e->scale; - right[0]*=e->scale; - right[1]*=e->scale; - right[2]*=e->scale; - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); \ - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE); - - if (pic) - IDirect3DDevice9_SetTexture(pD3DDev9, 0, *(LPDIRECT3DBASETEXTURE9*)&pic->d); - else - IDirect3DDevice9_SetTexture(pD3DDev9, 0, NULL); - - if (e->flags & RF_NODEPTHTEST) - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_ALWAYS); - - d3dvert[0].colour = colour; - d3dvert[0].tc[0] = 0; - d3dvert[0].tc[1] = 1; - VectorMA (e->origin, -1, up, point); - VectorMA (point, -1, right, d3dvert[0].pos); - - d3dvert[1].colour = colour; - d3dvert[1].tc[0] = 0; - d3dvert[1].tc[0] = 0; - VectorMA (e->origin, 1, up, point); - VectorMA (point, -1, right, d3dvert[1].pos); - - d3dvert[2].colour = colour; - d3dvert[2].tc[0] = 1; - d3dvert[2].tc[1] = 0; - VectorMA (e->origin, 1, up, point); - VectorMA (point, 1, right, d3dvert[2].pos); - - d3dvert[3].colour = colour; - d3dvert[3].tc[0] = 1; - d3dvert[3].tc[1] = 1; - VectorMA (e->origin, -1, up, point); - VectorMA (point, 1, right, d3dvert[3].pos); - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, vertindexes, D3DFMT_QINDEX, d3dvert, sizeof(d3dvert[0])); - - - if (e->flags & RF_NODEPTHTEST) - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_LESSEQUAL); - - return; - } - - if (!e->model) - return; - - if (e->flags & RF_NODEPTHTEST) - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_ALWAYS); - - // don't even bother culling, because it's just a single - // polygon without a surface cache - frame = R_GetSpriteFrame (e); - if (!frame) - return; - psprite = e->model->cache.data; -// frame = 0x05b94140; - - switch(psprite->type) - { - case SPR_ORIENTED: - // bullet marks on walls - AngleVectors (e->angles, forward, right, up); - break; - - case SPR_FACING_UPRIGHT: - up[0] = 0;up[1] = 0;up[2]=1; - right[0] = e->origin[1] - r_origin[1]; - right[1] = -(e->origin[0] - r_origin[0]); - right[2] = 0; - VectorNormalize (right); - break; - case SPR_VP_PARALLEL_UPRIGHT: - up[0] = 0;up[1] = 0;up[2]=1; - VectorCopy (vright, right); - break; - - default: - case SPR_VP_PARALLEL: - //normal sprite - VectorCopy(vup, up); - VectorCopy(vright, right); - break; - } - up[0]*=e->scale; - up[1]*=e->scale; - up[2]*=e->scale; - right[0]*=e->scale; - right[1]*=e->scale; - right[2]*=e->scale; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, *(void**)&frame->p.d); - -/* { - extern int gldepthfunc; - qglDepthFunc(gldepthfunc); - qglDepthMask(0); - if (gldepthmin == 0.5) - qglCullFace ( GL_BACK ); - else - qglCullFace ( GL_FRONT ); - - GL_TexEnv(GL_MODULATE); - - qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - qglDisable (GL_ALPHA_TEST); - qglDisable(GL_BLEND); - }*/ - -/* if (e->flags & Q2RF_ADDATIVE) - { - qglEnable(GL_BLEND); - qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - qglBlendFunc(GL_SRC_ALPHA, GL_ONE); - } - else if (e->shaderRGBAf[3]<1 || gl_blendsprites.value) - { - qglEnable(GL_BLEND); - qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } - else - qglEnable (GL_ALPHA_TEST); -*/ - - d3dvert[0].colour = 0xffffffff; - d3dvert[0].tc[0] = 0; - d3dvert[0].tc[1] = 1; - VectorMA (e->origin, frame->down, up, point); - VectorMA (point, frame->left, right, d3dvert[0].pos); - - d3dvert[1].colour = 0xffffffff; - d3dvert[1].tc[0] = 0; - d3dvert[1].tc[0] = 0; - VectorMA (e->origin, frame->up, up, point); - VectorMA (point, frame->left, right, d3dvert[1].pos); - - d3dvert[2].colour = 0xffffffff; - d3dvert[2].tc[0] = 1; - d3dvert[2].tc[1] = 0; - VectorMA (e->origin, frame->up, up, point); - VectorMA (point, frame->right, right, d3dvert[2].pos); - - d3dvert[3].colour = 0xffffffff; - d3dvert[3].tc[0] = 1; - d3dvert[3].tc[1] = 1; - VectorMA (e->origin, frame->down, up, point); - VectorMA (point, frame->right, right, d3dvert[3].pos); - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, vertindexes, D3DFMT_QINDEX, d3dvert, sizeof(d3dvert[0])); - - - if (e->flags & RF_NODEPTHTEST) - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_LESSEQUAL); - -// if (e->flags & Q2RF_ADDATIVE) //back to regular blending for us! -// qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} - -//================================================================================== - -void D3D9R_DrawSprite(int count, void **e, void *parm) -{ - while(count--) - { - currententity = *e++; - - D3D9_DrawSpriteModel (currententity); - } -} - - - -qboolean D3D9_ShouldDraw(void) -{ - { - if (currententity->flags & Q2RF_EXTERNALMODEL) - return false; -// if (currententity->keynum == (cl.viewentity[r_refdef.currentplayernum]?cl.viewentity[r_refdef.currentplayernum]:(cl.playernum[r_refdef.currentplayernum]+1))) -// return false; -// if (cl.viewentity[r_refdef.currentplayernum] && currententity->keynum == cl.viewentity[r_refdef.currentplayernum]) -// continue; - if (!Cam_DrawPlayer(r_refdef.currentplayernum, currententity->keynum-1)) - return false; - } - return true; -} - - -void D3D9_R_DrawEntitiesOnList (void) -{ - int i; - - if (!r_drawentities.value) - return; - - // draw sprites seperately, because of alpha blending - for (i=0 ; irtype) - { - case RT_SPRITE: - RQ_AddDistReorder(D3D9R_DrawSprite, currententity, NULL, currententity->origin); - continue; -#ifdef Q3SHADERS - case RT_BEAM: - case RT_RAIL_RINGS: - case RT_LIGHTNING: -// R_DrawLightning(currententity); - continue; - case RT_RAIL_CORE: -// R_DrawRailCore(currententity); - continue; -#endif - case RT_MODEL: //regular model - break; - case RT_PORTALSURFACE: - continue; //this doesn't do anything anyway, does it? - default: - case RT_POLY: //these are a little painful, we need to do them some time... just not yet. - continue; - } - if (currententity->flags & Q2RF_BEAM) - { -// R_DrawBeam(currententity); - continue; - } - if (!currententity->model) - continue; - - - if (cl.lerpents && (cls.allow_anyparticles || currententity->visframe)) //allowed or static - { -/* if (gl_part_flame.value) - { - if (currententity->model->engineflags & MDLF_ENGULPHS) - continue; - }*/ - } - - switch (currententity->model->type) - { - - case mod_alias: -// if (r_refdef.flags & Q2RDF_NOWORLDMODEL || !cl.worldmodel || cl.worldmodel->type != mod_brush || cl.worldmodel->fromgame == fg_doom) - D3D9_DrawAliasModel (); - break; - -#ifdef HALFLIFEMODELS - case mod_halflife: - R_DrawHLModel (currententity); - break; -#endif - - case mod_brush: -// if (!cl.worldmodel || cl.worldmodel->type != mod_brush || cl.worldmodel->fromgame == fg_doom) - D3D9_BaseBModelTextures (currententity); - break; - - case mod_sprite: - RQ_AddDistReorder(D3D9R_DrawSprite, currententity, NULL, currententity->origin); - break; -/* -#ifdef TERRAIN - case mod_heightmap: - D3D9_DrawHeightmapModel(currententity); - break; -#endif -*/ - default: - break; - } - } - - { - float m_identity[16] = { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - }; - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_WORLD, (D3DMATRIX*)m_identity); - } -} - -void D3D9_DrawWorld(void) -{ - RSpeedLocals(); - entity_t ent; - - memset (&ent, 0, sizeof(ent)); - ent.model = cl.worldmodel; - currentmodel = cl.worldmodel; - - VectorCopy (r_refdef.vieworg, modelorg); - - currententity = &ent; -#ifdef TERRAIN -// FIXME: Dunno what needs to be fixed here? -// if (currentmodel->type == mod_heightmap) -// D3D9_DrawHeightmapModel(currententity); -// else -#endif - { -// qglColor3f (1,1,1); - - RSpeedRemark(); - -#ifdef Q2BSPS - if (ent.model->fromgame == fg_quake2 || ent.model->fromgame == fg_quake3) - { - int leafnum; - int clientarea; -#ifdef QUAKE2 - if (cls.protocol == CP_QUAKE2) //we can get server sent info - memcpy(areabits, cl.q2frame.areabits, sizeof(areabits)); - else -#endif - { //generate the info each frame. - leafnum = CM_PointLeafnum (cl.worldmodel, r_refdef.vieworg); - clientarea = CM_LeafArea (cl.worldmodel, leafnum); - CM_WriteAreaBits(cl.worldmodel, areabits, clientarea); - } -#ifdef Q3BSPS - if (ent.model->fromgame == fg_quake3) - { - R_MarkLeaves_Q3 (); - D3D9_LeafWorldNode (); - } - else -#endif - { - R_MarkLeaves_Q2 (); - D3D9_RecursiveQ2WorldNode (cl.worldmodel->nodes); - } - } - else -#endif - { - R_MarkLeaves_Q1 (); - D3D9_RecursiveWorldNode (cl.worldmodel->nodes); - } - - RSpeedEnd(RSPEED_WORLDNODE); - TRACE(("dbg: calling PPL_DrawWorld\n")); -// if (r_shadows.value >= 2 && gl_canstencil && gl_mtexable) - D3D9_DrawTextureChains(); -// else -// DrawTextureChains (cl.worldmodel, 1, r_refdef.vieworg); - - -//qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - -// GLR_LessenStains(); - } -} - -void D3D9_R_RenderScene(void) -{ - if (!cl.worldmodel || (!cl.worldmodel->nodes && cl.worldmodel->type != mod_heightmap)) - r_refdef.flags |= Q2RDF_NOWORLDMODEL; - - if (!(r_refdef.flags & Q2RDF_NOWORLDMODEL)) - { - D3D9_DrawWorld (); // adds static entities to the list - } - - D3D9_R_DrawEntitiesOnList (); - - if (!(r_refdef.flags & Q2RDF_NOWORLDMODEL)) - P_DrawParticles(); - - D3D9_Set2D(); -} - -void (D3D9_R_RenderView) (void) -{ - D3D9_SetupFrame(); - D3D9_SetupViewPort(); - R_SetFrustum(); - D3D9_R_RenderScene(); -} - - -#ifdef PSET_SCRIPT - -#include "particles.h" -#define TYPESONLY -#include "p_script.c" - -#define APPLYD3D9BLEND(bm) \ - switch (bm) \ - { \ - case BM_ADD: \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_ONE); \ - break; \ - case BM_SUBTRACT: \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); \ - break; \ - case BM_BLENDCOLOUR: \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR); \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); \ - break; \ - case BM_BLEND: \ - default: \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); \ - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); \ - break; \ - } - - -typedef struct d3dparticlevert_s { - float org[3]; - unsigned int colour; - float s, t; //these could actually be preinitialised -} d3dparticlevert_t; -d3dparticlevert_t d3dparticlevert[4]; - -typedef struct d3dparticlevertut_s { - float org[3]; - unsigned int colour; -} d3dparticlevertut_t; -d3dparticlevertut_t d3dparticlevertut[4]; - -static vec3_t pright, pup; -static float particletime; - -void IDirect3DDevice9_DrawIndexedPrimitive7(LPDIRECT3DDEVICE9 pD3DDev9, int mode, int fvf, void *verts, int numverts, index_t *indicies, int numindicies, int wasted) -{ - int size = 0; - if (fvf & D3DFVF_XYZ) - size += 12; - if (fvf & D3DFVF_DIFFUSE) - size += 4; - if (fvf & D3DFVF_TEX1) - size += 8; - - IDirect3DDevice9_SetFVF(pD3DDev9, fvf); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, mode, 0, numverts, numindicies/3, indicies, D3DFMT_QINDEX, verts, size); -} - -index_t d3d9particlevertindexes[] = -{ - 0, 1, 2, - 0, 2, 3 -}; - -void D3D9_DrawParticleBlob(int count, particle_t **plist, plooks_t *type) -{ - float scale; - float x; - float y; - unsigned int colour; - int cb, cg, cr, ca; - particle_t *p; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, type->d3dtexture); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - APPLYD3D9BLEND(type->blendmode); - - - while(count--) - { - p = *plist++; - - scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1] - + (p->org[2] - r_origin[2])*vpn[2]; - scale = (scale*p->scale)*(type->invscalefactor) + p->scale * (type->scalefactor*250); - if (scale < 20) - scale = 0.25; - else - scale = 0.25 + scale * 0.001; - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - if (p->angle) - { - x = sin(p->angle)*scale; - y = cos(p->angle)*scale; - } - else - { - x = 0; - y = scale; - } - d3dparticlevert[0].s = 0; - d3dparticlevert[0].t = 0; - d3dparticlevert[0].colour = colour; - d3dparticlevert[0].org[0] = p->org[0] - x*pright[0] - y*pup[0]; - d3dparticlevert[0].org[1] = p->org[1] - x*pright[1] - y*pup[1]; - d3dparticlevert[0].org[2] = p->org[2] - x*pright[2] - y*pup[2]; - - d3dparticlevert[1].s = 0; - d3dparticlevert[1].t = 1; - d3dparticlevert[1].colour = colour; - d3dparticlevert[1].org[0] = p->org[0] - y*pright[0] + x*pup[0]; - d3dparticlevert[1].org[1] = p->org[1] - y*pright[1] + x*pup[1]; - d3dparticlevert[1].org[2] = p->org[2] - y*pright[2] + x*pup[2]; - - d3dparticlevert[2].s = 1; - d3dparticlevert[2].t = 1; - d3dparticlevert[2].colour = colour; - d3dparticlevert[2].org[0] = p->org[0] + x*pright[0] + y*pup[0]; - d3dparticlevert[2].org[1] = p->org[1] + x*pright[1] + y*pup[1]; - d3dparticlevert[2].org[2] = p->org[2] + x*pright[2] + y*pup[2]; - - d3dparticlevert[3].s = 1; - d3dparticlevert[3].t = 0; - d3dparticlevert[3].colour = colour; - d3dparticlevert[3].org[0] = p->org[0] + y*pright[0] - x*pup[0]; - d3dparticlevert[3].org[1] = p->org[1] + y*pright[1] - x*pup[1]; - d3dparticlevert[3].org[2] = p->org[2] + y*pright[2] - x*pup[2]; - - //FIXME: batch properly - IDirect3DDevice9_DrawIndexedPrimitive7(pD3DDev9, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dparticlevert, 4, d3d9particlevertindexes, 6, 0); - } -} -void D3D9_DrawParticleSpark(int count, particle_t **plist, plooks_t *type) -{ - vec3_t v, crv, o2; - - unsigned int colour; - int cb, cg, cr, ca; - particle_t *p; - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, type->d3dtexture); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - APPLYD3D9BLEND(type->blendmode); - - while(count--) - { - p = *plist++; - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - - - VectorSubtract(r_refdef.vieworg, p->org, v); - CrossProduct(v, p->vel, crv); - VectorNormalize(crv); - - VectorMA(p->org, -p->scale/2, crv, d3dparticlevert[0].org); - d3dparticlevert[0].s = 0; - d3dparticlevert[0].t = 0; - d3dparticlevert[0].colour = colour; - - VectorMA(p->org, p->scale/2, crv, d3dparticlevert[1].org); - d3dparticlevert[1].s = 0; - d3dparticlevert[1].t = 1; - d3dparticlevert[1].colour = colour; - - - VectorMA(p->org, 0.1, p->vel, o2); - - VectorSubtract(r_refdef.vieworg, o2, v); - CrossProduct(v, p->vel, crv); - VectorNormalize(crv); - - VectorMA(o2, p->scale/2, crv, d3dparticlevert[2].org); - d3dparticlevert[2].s = 1; - d3dparticlevert[2].t = 1; - d3dparticlevert[2].colour = colour; - - VectorMA(o2, -p->scale/2, crv, d3dparticlevert[3].org); - d3dparticlevert[3].s = 1; - d3dparticlevert[3].t = 0; - d3dparticlevert[3].colour = colour; - - //FIXME: batch properly - IDirect3DDevice9_DrawIndexedPrimitive7(pD3DDev9, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dparticlevert, 4, d3d9particlevertindexes, 6, 0); - } -} -void D3D9_DrawParticleBeam(int count, beamseg_t **blist, plooks_t *type) -{ - vec3_t v; - vec3_t crv; - beamseg_t *b, *c; - particle_t *p; - particle_t *q; - float ts; - - - unsigned int colour; - int cb, cg, cr, ca; - - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, type->d3dtexture); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - APPLYD3D9BLEND(type->blendmode); - - - - while(count--) - { - b = *blist++; - c = b->next; - q = c->p; - p = b->p; - - - cr = q->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = q->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = q->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = q->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - - - - c = b->next; - - q = c->p; - - p = b->p; - - VectorSubtract(r_refdef.vieworg, q->org, v); - VectorNormalize(v); - CrossProduct(c->dir, v, crv); - ts = c->texture_s*q->angle + particletime*q->rotationspeed; - - VectorMA(q->org, -q->scale, crv, d3dparticlevert[0].org); - d3dparticlevert[0].s = ts; - d3dparticlevert[0].t = 0; - d3dparticlevert[0].colour = colour; - - VectorMA(q->org, q->scale, crv, d3dparticlevert[1].org); - d3dparticlevert[1].s = ts; - d3dparticlevert[1].t = 1; - d3dparticlevert[1].colour = colour; - - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - VectorSubtract(r_refdef.vieworg, p->org, v); - VectorNormalize(v); - CrossProduct(b->dir, v, crv); // replace with old p->dir? - ts = b->texture_s*p->angle + particletime*p->rotationspeed; - - VectorMA(p->org, p->scale, crv, d3dparticlevert[2].org); - d3dparticlevert[2].s = ts; - d3dparticlevert[2].t = 1; - d3dparticlevert[2].colour = colour; - - VectorMA(p->org, -p->scale, crv, d3dparticlevert[3].org); - d3dparticlevert[3].s = ts; - d3dparticlevert[3].t = 0; - d3dparticlevert[3].colour = colour; - - - //FIXME: batch properly - IDirect3DDevice9_DrawIndexedPrimitive7(pD3DDev9, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, d3dparticlevert, 4, d3d9particlevertindexes, 6, 0); - } -} - -void D3D9_DrawParticleBeamUT(int count, beamseg_t **blist, plooks_t *type) -{ - vec3_t v; - vec3_t crv; - beamseg_t *b, *c; - particle_t *p; - particle_t *q; - float ts; - - - unsigned int colour; - int cb, cg, cr, ca; - - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, NULL); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2); - - - APPLYD3D9BLEND(type->blendmode); - - - while(count--) - { - b = *blist++; - c = b->next; - q = c->p; - p = b->p; - - - cr = q->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = q->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = q->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = q->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - - - - c = b->next; - - q = c->p; - - p = b->p; - - VectorSubtract(r_refdef.vieworg, q->org, v); - VectorNormalize(v); - CrossProduct(c->dir, v, crv); - ts = c->texture_s*q->angle + particletime*q->rotationspeed; - - VectorMA(q->org, -q->scale, crv, d3dparticlevertut[0].org); - d3dparticlevertut[0].colour = colour; - - VectorMA(q->org, q->scale, crv, d3dparticlevertut[1].org); - d3dparticlevertut[1].colour = colour; - - - cr = p->rgb[0]*255; - if (cr < 0) cr = 0; - if (cr > 255) cr = 255; - - cg = p->rgb[1]*255; - if (cg < 0) cg = 0; - if (cg > 255) cg = 255; - - cb = p->rgb[2]*255; - if (cb < 0) cb = 0; - if (cb > 255) cb = 255; - - ca = p->alpha*255; - if (ca < 0) ca = 0; - if (ca > 255) ca = 255; - - colour = (cb) | (cg<<8) | (cr << 16) | (ca << 24); - - - VectorSubtract(r_refdef.vieworg, p->org, v); - VectorNormalize(v); - CrossProduct(b->dir, v, crv); // replace with old p->dir? - ts = b->texture_s*p->angle + particletime*p->rotationspeed;; - - VectorMA(p->org, p->scale, crv, d3dparticlevertut[2].org); - d3dparticlevertut[2].colour = colour; - - VectorMA(p->org, -p->scale, crv, d3dparticlevertut[3].org); - d3dparticlevertut[3].colour = colour; - - - IDirect3DDevice9_DrawIndexedPrimitive7(pD3DDev9, D3DPT_TRIANGLELIST, D3DFVF_XYZ|D3DFVF_DIFFUSE, d3dparticlevertut, 4, d3d9particlevertindexes, 6, 0); - } -} - - - - - - -void D3D9_DrawParticles(float ptime) -{ - RSpeedLocals(); - - particletime = ptime; - VectorScale (vup, 1.5, pup); - VectorScale (vright, 1.5, pright); - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); //they're not all mipmapped - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - - PScript_DrawParticleTypes(D3D9_DrawParticleBlob, D3D9_DrawParticleSpark, D3D9_DrawParticleSpark, D3D9_DrawParticleSpark, D3D9_DrawParticleBeam, D3D9_DrawParticleBeamUT, NULL); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZWRITEENABLE, FALSE ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE ); - - RSpeedRemark(); - RQ_RenderDistAndClear(); - RSpeedEnd(RSPEED_PARTICLESDRAW); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZWRITEENABLE, TRUE ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, FALSE ); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); -} -#endif -#endif diff --git a/engine/d3d9/d3d9_rsurf.c b/engine/d3d9/d3d9_rsurf.c deleted file mode 100644 index 6fc386bc7..000000000 --- a/engine/d3d9/d3d9_rsurf.c +++ /dev/null @@ -1,1418 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "winquake.h" -#include "d3d9quake.h" - -int numlightmaps; - -mvertex_t *r_pcurrentvertbase; - -LPDIRECT3DTEXTURE9 *lightmap_d3d9textures; -LPDIRECT3DTEXTURE9 *deluxmap_d3d9textures; -lightmapinfo_t **lightmap; - - - -void D3D9_BuildSurfaceDisplayList (msurface_t *fa) -{ - int i, lindex, lnumverts; - medge_t *pedges, *r_pedge; - int vertpage; - float *vec; - float s, t; - int lm; - - int size; - mesh_t *mesh; - -// reconstruct the polygon - pedges = currentmodel->edges; - lnumverts = fa->numedges; - vertpage = 0; - - - if (lnumverts<3) - return; //q3 map. - - size = sizeof(mesh_t) + sizeof(index_t)*(lnumverts-2)*3 + (sizeof(vec3_t) + sizeof(vec3_t) + 2*sizeof(vec2_t) + sizeof(byte_vec4_t))*lnumverts; - - fa->mesh = mesh = Hunk_Alloc(size); - mesh->xyz_array = (vec3_t*)(mesh + 1); - mesh->normals_array = (vec3_t*)(mesh->xyz_array + lnumverts); - mesh->st_array = (vec2_t*)(mesh->normals_array + lnumverts); - mesh->lmst_array = (vec2_t*)(mesh->st_array + lnumverts); - mesh->colors_array = (byte_vec4_t*)(mesh->lmst_array + lnumverts); - mesh->indexes = (index_t*)(mesh->colors_array + lnumverts); - - mesh->numindexes = (lnumverts-2)*3; - mesh->numvertexes = lnumverts; - mesh->patchWidth = mesh->patchHeight = 1; - - for (i=0 ; iindexes[i*3] = 0; - mesh->indexes[i*3+1] = i+1; - mesh->indexes[i*3+2] = i+2; - } - - for (i=0 ; isurfedges[fa->firstedge + i]; - - if (lindex > 0) - { - r_pedge = &pedges[lindex]; - vec = r_pcurrentvertbase[r_pedge->v[0]].position; - } - else - { - r_pedge = &pedges[-lindex]; - vec = r_pcurrentvertbase[r_pedge->v[1]].position; - } - - s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3]; - t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3]; - - VectorCopy (vec, mesh->xyz_array[i]); - mesh->xyz_array[i][3] = 1; - mesh->st_array[i][0] = s/fa->texinfo->texture->width; - mesh->st_array[i][1] = t/fa->texinfo->texture->height; - - s -= fa->texturemins[0]; - lm = s*fa->light_t; - s += fa->light_s*16; - s += 8; - s /= LMBLOCK_WIDTH*16; - - t -= fa->texturemins[1]; - lm += t; - t += fa->light_t*16; - t += 8; - t /= LMBLOCK_HEIGHT*16; - - mesh->lmst_array[i][0] = s; - mesh->lmst_array[i][1] = t; - - if (fa->flags & SURF_PLANEBACK) - VectorNegate(fa->plane->normal, mesh->normals_array[i]); - else - VectorCopy(fa->plane->normal, mesh->normals_array[i]); - - mesh->colors_array[i][0] = 255; - mesh->colors_array[i][1] = 255; - mesh->colors_array[i][2] = 255; - mesh->colors_array[i][3] = 255; - } -} - - - - - - - -#define MAX_LIGHTMAP_SIZE LMBLOCK_WIDTH - -vec3_t blocknormals[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -unsigned greenblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; -unsigned blueblklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE]; - -void D3D9R_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift) -{ - int smax, tmax; - int t; - int i, j, size; - qbyte *lightmap; - unsigned scale; - int maps; - unsigned *bl; - qboolean isstained; - extern cvar_t r_ambient; - extern cvar_t gl_lightmap_shift; - - unsigned *blg; - unsigned *blb; - - int r, g, b; - int cr, cg, cb; - - int stride = LMBLOCK_WIDTH*lightmap_bytes; - - shift += 7; // increase to base value - surf->cached_dlight = (surf->dlightframe == r_framecount); - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - size = smax*tmax; - lightmap = surf->samples; - - if (size > MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE) - { //fixme: fill in? - Con_Printf("Lightmap too large\n"); - return; - } - -// if (currentmodel->deluxdata) -// GLR_BuildDeluxMap(surf, deluxdest); - - - - if (true) - { - // set to full bright if no light data - if (r_fullbright.value>0) //not qw - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - goto store; - } - if (!currentmodel->lightdata) - { - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - goto store; - } - -// clear to no light - t = r_ambient.value*255; - for (i=0 ; ifromgame == fg_quake3) //rgb - { - /* for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) //no light styles in q3 apparently. - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - } - */ - for (i = 0; i < tmax; i++) //q3 maps store their light in a block fashion, q1/q2/hl store it in a linear fashion. - { - for (j = 0; j < smax; j++) - { - blocklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3]; - greenblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+1]; - blueblklights[i*smax+j] = 255*lightmap[(i*LMBLOCK_WIDTH+j)*3+2]; - } - } -// memset(blocklights, 255, sizeof(blocklights)); - } - else if (currentmodel->engineflags & MDLF_RGBLIGHTING) //rgb - { - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - - if (cl_lightstyle[surf->styles[maps]].colour == 7) //hopefully a faster alternative. - { - for (i=0 ; istyles[maps]].colour & 1) - for (i=0 ; istyles[maps]].colour & 2) - for (i=0 ; istyles[maps]].colour & 4) - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLightsColours (surf); - } - else - { - // set to full bright if no light data - if (r_fullbright.value || !currentmodel->lightdata) - { - for (i=0 ; iengineflags & MDLF_RGBLIGHTING) //rgb - for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]/3; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; istyles[maps] != 255 ; - maps++) - { - scale = d_lightstylevalue[surf->styles[maps]]; - surf->cached_light[maps] = scale; // 8.8 fraction - surf->cached_colour[maps] = cl_lightstyle[surf->styles[maps]].colour; - for (i=0 ; idlightframe == r_framecount) -// GLR_AddDynamicLights (surf); - } - -// bound, invert, and shift -store: -#define INVERTLIGHTMAPS -#ifdef INVERTLIGHTMAPS - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -//*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - /* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[2] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#else - switch (lightmap_bytes) - { - case 4: - stride -= (smax<<2); - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 0; - else if (t < 0) - dest[0] = 256; - else - dest[0] = (255-t); - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 0; - else if (t < 0) - dest[1] = 256; - else - dest[1] = (255-t); - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 0; - else if (t < 0) - dest[2] = 256; - else - dest[2] = (255-t); - - dest[3] = 0;//(dest[0]+dest[1]+dest[2])/3; - dest += 4; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 0; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 255; - else - dest[2] = 255-(r+cr); - - if ((g+cg) > 255) - dest[1] = 0; - else if ((g+cg) < 0) - dest[1] = 255; - else - dest[1] = 255-(g+cg); - - if ((b+cb) > 255) - dest[0] = 0; - else if ((b+cb) < 0) - dest[0] = 255; - else - dest[0] = 255-(b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -*/ - - - - dest[3] = (dest[0]+dest[1]+dest[2])/3; //alpha?!?! - dest += 4; - } - } - } - break; - - case 3: - stride -= smax*3; - bl = blocklights; - blg = greenblklights; - blb = blueblklights; - -// if (!r_stains.value) - isstained = false; -// else -// isstained = surf->stained; - -/* if (!gl_lightcomponantreduction.value) - { - for (i=0 ; i>= 7; - if (t > 255) - dest[0] = 255; - else if (t < 0) - dest[0] = 0; - else - dest[0] = t; - - t = *blg++; - t >>= 7; - if (t > 255) - dest[1] = 255; - else if (t < 0) - dest[1] = 0; - else - dest[1] = t; - - t = *blb++; - t >>= 7; - if (t > 255) - dest[2] = 255; - else if (t < 0) - dest[2] = 0; - else - dest[2] = t; - - dest += 3; - } - } - } - else -*/ { - stmap *stain; - for (i=0 ; i>= shift; - g >>= shift; - b >>= shift; - - if (isstained) // merge in stain - { - r = (127+r*(*stain++)) >> 8; - g = (127+g*(*stain++)) >> 8; - b = (127+b*(*stain++)) >> 8; - } - - cr = 0; - cg = 0; - cb = 0; - - if (r > 255) //ak too much red - { - cr -= (255-r)/2; - cg += (255-r)/4; //reduce it, and indicate to drop the others too. - cb += (255-r)/4; - r = 255; - } -// else if (r < 0) -// r = 0; - - if (g > 255) - { - cr += (255-g)/4; - cg -= (255-g)/2; - cb += (255-g)/4; - g = 255; - } -// else if (g < 0) -// g = 0; - - if (b > 255) - { - cr += (255-b)/4; - cg += (255-b)/4; - cb -= (255-b)/2; - b = 255; - } -// else if (b < 0) -// b = 0; - //* - if ((r+cr) > 255) - dest[2] = 255; //inverse lighting - else if ((r+cr) < 0) - dest[2] = 0; - else - dest[2] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[0] = 255; - else if ((b+cb) < 0) - dest[0] = 0; - else - dest[0] = (b+cb); -/*/ - if ((r+cr) > 255) - dest[0] = 255; //non-inverse lighting - else if ((r+cr) < 0) - dest[0] = 0; - else - dest[0] = (r+cr); - - if ((g+cg) > 255) - dest[1] = 255; - else if ((g+cg) < 0) - dest[1] = 0; - else - dest[1] = (g+cg); - - if ((b+cb) > 255) - dest[2] = 255; - else if ((b+cb) < 0) - dest[2] = 0; - else - dest[2] = (b+cb); -// */ - dest += 3; - } - } - } - break; - default: - Sys_Error ("Bad lightmap format"); - } -#endif -} - - - -int D3D9_FillBlock (int texnum, int w, int h, int x, int y) -{ - int i, l; - while (texnum >= numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap[numlightmaps+0] = 0; - lightmap[numlightmaps+1] = 0; - lightmap[numlightmaps+2] = 0; - lightmap[numlightmaps+3] = 0; - - lightmap_d3d9textures = BZ_Realloc(lightmap_d3d9textures, sizeof(*lightmap_d3d9textures)*(numlightmaps+4)); - lightmap_d3d9textures[numlightmaps+0] = 0; - lightmap_d3d9textures[numlightmaps+1] = 0; - lightmap_d3d9textures[numlightmaps+2] = 0; - lightmap_d3d9textures[numlightmaps+3] = 0; - - deluxmap_d3d9textures = BZ_Realloc(deluxmap_d3d9textures, sizeof(*deluxmap_d3d9textures)*(numlightmaps+4)); - deluxmap_d3d9textures[numlightmaps+0] = 0; - deluxmap_d3d9textures[numlightmaps+1] = 0; - deluxmap_d3d9textures[numlightmaps+2] = 0; - deluxmap_d3d9textures[numlightmaps+3] = 0; - numlightmaps+=4; - } - for (i = texnum; i >= 0; i--) - { - if (!lightmap[i]) - { - lightmap[i] = BZ_Malloc(sizeof(*lightmap[i])); - for (l=0 ; lallocated[l] = LMBLOCK_HEIGHT; - } - - //maybe someone screwed with my lightmap... - memset(lightmap[i]->lightmaps, 255, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); -// if (cl.worldmodel->lightdata) -// memcpy(lightmap[i]->lightmaps, cl.worldmodel->lightdata+3*LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*i, LMBLOCK_HEIGHT*LMBLOCK_HEIGHT*3); - - } - else - break; - } - return texnum; -} - -int D3D9_AllocBlock (int w, int h, int *x, int *y) -{ - int i, j; - int best, best2; - int texnum; - - for (texnum=0 ; ; texnum++) - { - if (texnum == numlightmaps) //allocate 4 more lightmap slots. not much memory usage, but we don't want any caps here. - { - lightmap = BZ_Realloc(lightmap, sizeof(*lightmap)*(numlightmaps+4)); - lightmap[numlightmaps+0] = 0; - lightmap[numlightmaps+1] = 0; - lightmap[numlightmaps+2] = 0; - lightmap[numlightmaps+3] = 0; - - lightmap_d3d9textures = BZ_Realloc(lightmap_d3d9textures, sizeof(*lightmap_d3d9textures)*(numlightmaps+4)); - lightmap_d3d9textures[numlightmaps+0] = 0; - lightmap_d3d9textures[numlightmaps+1] = 0; - lightmap_d3d9textures[numlightmaps+2] = 0; - lightmap_d3d9textures[numlightmaps+3] = 0; - - deluxmap_d3d9textures = BZ_Realloc(deluxmap_d3d9textures, sizeof(*deluxmap_d3d9textures)*(numlightmaps+4)); - deluxmap_d3d9textures[numlightmaps+0] = 0; - deluxmap_d3d9textures[numlightmaps+1] = 0; - deluxmap_d3d9textures[numlightmaps+2] = 0; - deluxmap_d3d9textures[numlightmaps+3] = 0; - numlightmaps+=4; - } - if (!lightmap[texnum]) - { - lightmap[texnum] = Z_Malloc(sizeof(*lightmap[texnum])); - // reset stainmap since it now starts at 255 - memset(lightmap[texnum]->stainmaps, 255, sizeof(lightmap[texnum]->stainmaps)); - } - - - best = LMBLOCK_HEIGHT; - - for (i=0 ; iallocated[i+j] >= best) - break; - if (lightmap[texnum]->allocated[i+j] > best2) - best2 = lightmap[texnum]->allocated[i+j]; - } - if (j == w) - { // this is a valid spot - *x = i; - *y = best = best2; - } - } - - if (best + h > LMBLOCK_HEIGHT) - continue; - - for (i=0 ; iallocated[*x + i] = best + h; - - return texnum; - } - - Sys_Error ("AllocBlock: full"); - return 0; -} - - -void D3D9_CreateSurfaceLightmap (msurface_t *surf, int shift) -{ - int smax, tmax; - qbyte *base, *luxbase; stmap *stainbase; - - if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB)) - surf->lightmaptexturenum = -1; - if (surf->texinfo->flags & TEX_SPECIAL) - surf->lightmaptexturenum = -1; - if (surf->lightmaptexturenum<0) - return; - - smax = (surf->extents[0]>>4)+1; - tmax = (surf->extents[1]>>4)+1; - - if (smax > LMBLOCK_WIDTH || tmax > LMBLOCK_HEIGHT || smax < 0 || tmax < 0) - { //whoa, buggy. - surf->lightmaptexturenum = -1; - return; - } - - if (currentmodel->fromgame == fg_quake3) - D3D9_FillBlock(surf->lightmaptexturenum, smax, tmax, surf->light_s, surf->light_t); - else - surf->lightmaptexturenum = D3D9_AllocBlock (smax, tmax, &surf->light_s, &surf->light_t); - base = lightmap[surf->lightmaptexturenum]->lightmaps; - base += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - luxbase = lightmap[surf->lightmaptexturenum]->deluxmaps; - luxbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * lightmap_bytes; - - stainbase = lightmap[surf->lightmaptexturenum]->stainmaps; - stainbase += (surf->light_t * LMBLOCK_WIDTH + surf->light_s) * 3; - - D3D9R_BuildLightMap (surf, base, luxbase, stainbase, shift); -} - - -void D3D9R_RenderDynamicLightmaps (msurface_t *fa, int shift) -{ - qbyte *base, *luxbase; - stmap *stainbase; - int maps; - glRect_t *theRect; - int smax, tmax; - - if (!fa->mesh) - return; - -// c_brush_polys++; - - if (fa->lightmaptexturenum<0) - return; - - if (fa->flags & ( SURF_DRAWSKY | SURF_DRAWTURB) ) - return; - - if (fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP)) - return; - - if (fa->texinfo->flags & (TEX_SPECIAL)) - { - if (cl.worldmodel->fromgame == fg_halflife) - return; //some textures do this. - } - -// fa->polys->chain = lightmap[fa->lightmaptexturenum]->polys; -// lightmap[fa->lightmaptexturenum]->polys = fa->polys; - - // check for lightmap modification -// if (cl.worldmodel->fromgame != fg_quake3) //no lightstyles on q3 maps - { - for (maps = 0 ; maps < MAXLIGHTMAPS && fa->styles[maps] != 255 ; - maps++) - if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps] - #ifdef PEXT_LIGHTSTYLECOL - || cl_lightstyle[fa->styles[maps]].colour != fa->cached_colour[maps] - #endif - ) - { - goto dynamic; - } - } - - if (fa->dlightframe == r_framecount // dynamic this frame - || fa->cached_dlight) // dynamic previously - { - RSpeedLocals(); -dynamic: - RSpeedRemark(); - - lightmap[fa->lightmaptexturenum]->modified = true; - - smax = (fa->extents[0]>>4)+1; - tmax = (fa->extents[1]>>4)+1; - - theRect = &lightmap[fa->lightmaptexturenum]->rectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - lightmap[fa->lightmaptexturenum]->deluxmodified = true; - theRect = &lightmap[fa->lightmaptexturenum]->deluxrectchange; - if (fa->light_t < theRect->t) { - if (theRect->h) - theRect->h += theRect->t - fa->light_t; - theRect->t = fa->light_t; - } - if (fa->light_s < theRect->l) { - if (theRect->w) - theRect->w += theRect->l - fa->light_s; - theRect->l = fa->light_s; - } - - if ((theRect->w + theRect->l) < (fa->light_s + smax)) - theRect->w = (fa->light_s-theRect->l)+smax; - if ((theRect->h + theRect->t) < (fa->light_t + tmax)) - theRect->h = (fa->light_t-theRect->t)+tmax; - - - base = lightmap[fa->lightmaptexturenum]->lightmaps; - base += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - luxbase = lightmap[fa->lightmaptexturenum]->deluxmaps; - luxbase += fa->light_t * LMBLOCK_WIDTH * lightmap_bytes + fa->light_s * lightmap_bytes; - stainbase = lightmap[fa->lightmaptexturenum]->stainmaps; - stainbase += (fa->light_t * LMBLOCK_WIDTH + fa->light_s) * 3; - D3D9R_BuildLightMap (fa, base, luxbase, stainbase, shift); - - RSpeedEnd(RSPEED_DYNAMIC); - } -} - - - -LPDIRECT3DTEXTURE9 D3D9_NewLightmap(void) -{ - LPDIRECT3DTEXTURE9 newsurf; - IDirect3DDevice9_CreateTexture(pD3DDev9, LMBLOCK_WIDTH, LMBLOCK_WIDTH, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &newsurf, NULL); - - if (!newsurf) - return NULL; - - return newsurf; -} - -void D3D9_BuildLightmaps (void) -{ - D3DLOCKED_RECT desc; - - int i, j; - model_t *m; - int shift; - - r_framecount = 1; // no dlightcache -/* - for (i = 0; i < numlightmaps; i++) - { - if (!lightmap[i]) - break; - BZ_Free(lightmap[i]); - lightmap[i] = NULL; - } - - if (cl.worldmodel->fromgame == fg_doom) - return; //no lightmaps. - - if ((cl.worldmodel->engineflags & MDLF_RGBLIGHTING) || cl.worldmodel->deluxdata || r_loadlits.value) - gl_lightmap_format = GL_RGB; - else - gl_lightmap_format = GL_LUMINANCE; - - - if (cl.worldmodel->fromgame == fg_quake3 && gl_lightmap_format != GL_RGB && gl_lightmap_format != GL_RGBA) - gl_lightmap_format = GL_RGB; - - - switch (gl_lightmap_format) - { - case GL_RGBA: - lightmap_bytes = 4; - break; - case GL_RGB: - lightmap_bytes = 3; - break; - case GL_LUMINANCE: - case GL_INTENSITY: - case GL_ALPHA: - lightmap_bytes = 1; - break; - } -*/ - for (j=1 ; jname[0] == '*') - continue; - - r_pcurrentvertbase = m->vertexes; - currentmodel = m; - shift = 0;//GLR_LightmapShift(currentmodel); - - for (i=0 ; inumsurfaces ; i++) - { - D3D9_CreateSurfaceLightmap (m->surfaces + i, shift); - P_EmitSkyEffectTris(m, &m->surfaces[i]); - if (m->surfaces[i].mesh) //there are some surfaces that have a display list already (the subdivided ones) - continue; - D3D9_BuildSurfaceDisplayList (m->surfaces + i); - } - } - - // - // upload all lightmaps that were filled - // - for (i=0 ; imodified = false; - lightmap[i]->rectchange.l = LMBLOCK_WIDTH; - lightmap[i]->rectchange.t = LMBLOCK_HEIGHT; - lightmap[i]->rectchange.w = 0; - lightmap[i]->rectchange.h = 0; - - if (!lightmap_d3d9textures[i]) - { - lightmap_d3d9textures[i] = D3D9_NewLightmap(); - - if (!lightmap_d3d9textures[i]) - { - Con_Printf("Couldn't create new lightmap\n"); - return; - } - } - - IDirect3DTexture9_LockRect(lightmap_d3d9textures[i], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); - memcpy(desc.pBits, lightmap[i]->lightmaps, sizeof(lightmap[i]->lightmaps)); - /* memset(desc.lpSurface, 0, sizeof(lightmap[i]->lightmaps)); - { - int i; - unsigned char *c; - c = desc.lpSurface; - for (i = 0; i < sizeof(lightmap[i]->lightmaps); i++) - *c++ = rand(); - }*/ - IDirect3DTexture9_UnlockRect(lightmap_d3d9textures[i], 0); - - if (deluxmap_d3d9textures[i]) - { - IDirect3DTexture9_LockRect(deluxmap_d3d9textures[i], 0, &desc, NULL, DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY|DDLOCK_DISCARDCONTENTS); - memcpy(desc.pBits, lightmap[i]->lightmaps, sizeof(lightmap[i]->deluxmaps)); - IDirect3DTexture9_UnlockRect(deluxmap_d3d9textures[i], 0); - } - } - -} - - - - - - -void D3D9_DrawSkyMesh(int pass, int texture, void *verts, int numverts, void *indicies, int numelements) -{ - if (pass == 0) - { - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, FALSE ); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, (LPDIRECT3DBASETEXTURE9)texture); - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, numverts, numelements, indicies, D3DFMT_QINDEX, verts, 20); - } - - if (pass == 1) - { - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLORARG2, D3DTA_CURRENT); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - IDirect3DDevice9_SetTextureStageState(pD3DDev9, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - - IDirect3DDevice9_SetTexture(pD3DDev9, 0, (LPDIRECT3DBASETEXTURE9)texture); - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_TEX1); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, numverts, numelements, indicies, D3DFMT_QINDEX, verts, 20); - - - - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, FALSE); - } -} - -#endif diff --git a/engine/d3d9/d3d9quake.h b/engine/d3d9/d3d9quake.h deleted file mode 100644 index 9fc6a7d08..000000000 --- a/engine/d3d9/d3d9quake.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifdef MINGW - #include "ddraw.h" // resolve DDLOCK_NOSYSLOCK -#endif - -#ifndef D3D9QUAKE_H -#define D3D9QUAKE_H - - -#include "d3d9.h" -#include "com_mesh.h" -#include "glquake.h" - -// -// d3d9_draw.c -// -void D3D9_Draw_Alt_String (int x, int y, const qbyte *str); -mpic_t* D3D9_Draw_CachePic (char *path); -void D3D9_Draw_Character (int x, int y, unsigned int num); -void D3D9_Draw_ColouredCharacter (int x, int y, unsigned int num); -void D3D9_Draw_ConsoleBackground (int firstline, int lastline, qboolean forceopaque); -void D3D9_Draw_DebugChar (qbyte num); -void D3D9_Draw_EditorBackground (int lines); -void D3D9_Draw_Image (float x, float y, float w, float h, float s1, float t1, float s2, float t2, mpic_t *pic); -void D3D9_Draw_ImageColours (float r, float g, float b, float a); -mpic_t* D3D9_Draw_SafeCachePic (char *path); -mpic_t* D3D9_Draw_SafePicFromWad (char *name); -void D3D9_Draw_ScalePic (int x, int y, int width, int height, mpic_t *pic); -void D3D9_Draw_String (int x, int y, const qbyte *str); -void D3D9_Draw_SubPic (int x, int y, int width, int height, mpic_t *pic, int srcx, int srcy, int srcwidth, int srcheight); -void D3D9_Draw_TileClear (int x, int y, int w, int h); -void D3D9_InitParticleTexture (void); -LPDIRECT3DBASETEXTURE9 D3D9_LoadTexture_32 (char *name, unsigned int *data, int width, int height, int flags); -LPDIRECT3DBASETEXTURE9 D3D9_LoadTexture_8_Pal24 (char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette, int transparentpix); -LPDIRECT3DBASETEXTURE9 D3D9_LoadTexture_8_Pal32 (char *name, unsigned char *data, int width, int height, int flags, unsigned char *palette); -void D3D9_Media_ShowFrame8bit (qbyte *framedata, int inwidth, int inheight, qbyte *palette); -void D3D9_Media_ShowFrameBGR_24_Flip (qbyte *framedata, int inwidth, int inheight); -void D3D9_Media_ShowFrameRGBA_32 (qbyte *framedata, int inwidth, int inheight); -void D3D9_MipMap (qbyte *out, qbyte *in, int width, int height); -void D3D9_RoundDimensions (int *scaled_width, int *scaled_height, qboolean mipmap); -void D3D9_UnloadTexture (LPDIRECT3DBASETEXTURE9 tex); -static void Upload_Texture_32(LPDIRECT3DTEXTURE9 surf, unsigned int *data, int width, int height); - -// -// d3d9_mesh.c -// -void D3D9_DrawAliasModel (void); -void D3D9_DrawMesh (mesh_t *mesh); -void d3d9_GAliasFlushSkinCache (void); -static void LotsOfLightDirectionHacks (entity_t *e, model_t *m, vec3_t lightaxis[3]); - -// -// d3d9_rmain.c -// -void D3D9_BaseBModelTextures (entity_t *e); -/* -void D3D9_DrawParticleBeam (beamseg_t *b, part_type_t *type); -void D3D9_DrawParticleBeamUT (beamseg_t *b, part_type_t *type); -void D3D9_DrawParticleBlob (particle_t *p, part_type_t *type); -void D3D9_DrawParticleSpark (particle_t *p, part_type_t *type); -*/ -void D3D9_DrawParticles (float ptime); -static void D3D9_DrawSpriteModel (entity_t *e); -void D3D9_DrawTextureChains (void); -void D3D9_DrawWorld (void); -void D3D9_R_DrawEntitiesOnList (void); -void D3D9_R_ReInit (void); -void D3D9_R_RenderScene (void); -static void D3D9_RecursiveQ2WorldNode (mnode_t *node); -static void D3D9_RecursiveWorldNode (mnode_t *node); -void D3D9_SetupFrame (void); -qboolean D3D9_ShouldDraw (void); -void D3D9R_DrawSprite(int count, void **e, void *parm); -void IDirect3DDevice9_DrawIndexedPrimitive7 (LPDIRECT3DDEVICE9 pD3DDev9, int mode, int fvf, void *verts, int numverts, index_t *indicies, int numindicies, int wasted); - -// -// d3d9_rsurf.c -// -int D3D9_AllocBlock (int w, int h, int *x, int *y); -void D3D9_BuildLightmaps (void); -void D3D9_BuildSurfaceDisplayList (msurface_t *fa); -void D3D9_CreateSurfaceLightmap (msurface_t *surf, int shift); -void D3D9_DrawSkyMesh(int pass, int texture, void *verts, int numverts, void *indicies, int numelements); -int D3D9_FillBlock (int texnum, int w, int h, int x, int y); -LPDIRECT3DTEXTURE9 D3D9_NewLightmap (void); -//void D3D9R_BuildLightMap (msurface_t *surf, qbyte *dest, qbyte *deluxdest, stmap *stainsrc, int shift); -void D3D9R_RenderDynamicLightmaps (msurface_t *fa, int shift); - -// -// vid_d3d9.c -// -void D3D9_D_BeginDirectRect (int x, int y, qbyte *pbitmap, int width, int height); -void D3D9_D_EndDirectRect (int x, int y, int width, int height); -void D3D9_Mod_ClearAll (void); -void* D3D9_Mod_Extradata (struct model_s *mod); -struct model_s* D3D9_Mod_FindName (char *name); -struct model_s* D3D9_Mod_ForName (char *name, qboolean crash); -void D3D9_Mod_Init (void); -void D3D9_Mod_NowLoadExternal (void); -int D3D9_Mod_SkinForName (struct model_s *model, char *name); -void D3D9_Mod_Think (void); -void D3D9_Mod_TouchModel (char *name); -qboolean D3D9_R_CheckSky (void); -void D3D9_Set2D (void); -void D3D9_VID_ForceLockState (int lk); -int D3D9_VID_ForceUnlockedAndReturnState (void); -void D3D9_VID_LockBuffer (void); -void D3D9_VID_UnlockBuffer (void); -static LRESULT WINAPI D3D9_WindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - -texid_t D3D9_LoadTexture (char *identifier, int width, int height, enum uploadfmt fmt, void *data, unsigned int flags); -texid_t D3D9_LoadTexture8Pal24 (char *identifier, int width, int height, qbyte *data, qbyte *palette24, unsigned int flags); -texid_t D3D9_LoadTexture8Pal32 (char *identifier, int width, int height, qbyte *data, qbyte *palette32, unsigned int flags); -texid_t D3D9_LoadCompressed (char *name); -texid_t D3D9_FindTexture (char *identifier); -texid_t D3D9_AllocNewTexture (int w, int h); -void D3D9_Upload (texid_t tex, char *name, enum uploadfmt fmt, void *data, void *palette, int width, int height, unsigned int flags); -void D3D9_DestroyTexture (texid_t tex); - -extern LPDIRECT3DDEVICE9 pD3DDev9; - -extern int d_lightstylevalue[256]; // 8.8 fraction of base light value - -#define lightmap_bytes 4 - - -extern int numlightmaps; - -extern mvertex_t *r_pcurrentvertbase; - -#ifndef LMBLOCK_WIDTH -#define LMBLOCK_WIDTH 128 -#define LMBLOCK_HEIGHT LMBLOCK_WIDTH -typedef struct glRect_s { - unsigned char l,t,w,h; -} glRect_t; -typedef unsigned char stmap; - -typedef struct { - qboolean modified; - qboolean deluxmodified; - glRect_t rectchange; - glRect_t deluxrectchange; - int allocated[LMBLOCK_WIDTH]; - qbyte lightmaps[4*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; - qbyte deluxmaps[4*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; //fixme: make seperate structure for easy disabling with less memory usage. - stmap stainmaps[3*LMBLOCK_WIDTH*LMBLOCK_HEIGHT]; //rgb no a. added to lightmap for added (hopefully) speed. -} lightmapinfo_t; -#endif - -extern LPDIRECT3DTEXTURE9 *lightmap_d3d9textures; -extern LPDIRECT3DTEXTURE9 *deluxmap_d3d9textures; -extern lightmapinfo_t **lightmap; - -extern void *d3dexplosiontexture; -extern void *d3dballtexture; - -extern index_t dummyindex; -#if sizeof_index_t == 2 - #define D3DFMT_QINDEX D3DFMT_INDEX16 -#else - #define D3DFMT_QINDEX D3DFMT_INDEX32 -#endif - -#endif diff --git a/engine/d3d9/vid_d3d9.c b/engine/d3d9/vid_d3d9.c deleted file mode 100644 index 92f540b88..000000000 --- a/engine/d3d9/vid_d3d9.c +++ /dev/null @@ -1,1393 +0,0 @@ -#include "quakedef.h" -#ifdef D3DQUAKE -#include "winquake.h" -#include "d3d9quake.h" - -//#include "d3d9.h" - - -//#pragma comment(lib, "../libs/dxsdk9/lib/d3d9.lib") - - -#ifndef WM_XBUTTONDOWN - #define WM_XBUTTONDOWN 0x020B - #define WM_XBUTTONUP 0x020C -#endif -#ifndef MK_XBUTTON1 - #define MK_XBUTTON1 0x0020 -#endif -#ifndef MK_XBUTTON2 - #define MK_XBUTTON2 0x0040 -#endif -// copied from DarkPlaces in an attempt to grab more buttons -#ifndef MK_XBUTTON3 - #define MK_XBUTTON3 0x0080 -#endif -#ifndef MK_XBUTTON4 - #define MK_XBUTTON4 0x0100 -#endif -#ifndef MK_XBUTTON5 - #define MK_XBUTTON5 0x0200 -#endif -#ifndef MK_XBUTTON6 - #define MK_XBUTTON6 0x0400 -#endif -#ifndef MK_XBUTTON7 - #define MK_XBUTTON7 0x0800 -#endif - -#ifndef WM_INPUT - #define WM_INPUT 255 -#endif - - -int gl_bumpmappingpossible; - -void D3D9_GetBufferSize(int *width, int *height); -static LPDIRECT3D9 pD3D; -LPDIRECT3DDEVICE9 pD3DDev9; -//static LPDIRECTDRAWGAMMACONTROL pGammaControl; - - -static qboolean vid_initializing; - -extern qboolean scr_initialized; // ready to draw -extern qboolean scr_drawloading; - - -cvar_t vid_hardwaregamma; - - -HWND mainwindow; - -struct texture_s *r_notexture_mip; - -int r_framecount; - -mleaf_t *r_viewleaf; - -#define MAX_MOD_KNOWN 1024 -int mod_numknown; -model_t mod_known[MAX_MOD_KNOWN]; -model_t *loadmodel; -model_t *currentmodel; -char loadname[32]; -qbyte *mod_base; - -model_t *lightmodel; -int relitsurface; - -int window_center_x, window_center_y; -RECT window_rect; -int window_x, window_y; - -mpic_t *draw_disc; // also used on sbar - -int d3d9width, d3d9height; -#if 0 -#if !defined(GLQUAKE) -qbyte GetPaletteIndex(int red, int green, int blue) -{ - //slow, horrible method. - { - int i, best=15; - int bestdif=256*256*256, curdif; - extern qbyte *host_basepal; - qbyte *pa; - - #define _abs(x) ((x)*(x)) - - pa = host_basepal; - for (i = 0; i < 256; i++, pa+=3) - { - curdif = _abs(red - pa[0]) + _abs(green - pa[1]) + _abs(blue - pa[2]); - if (curdif < bestdif) - { - if (curdif<1) - return i; - bestdif = curdif; - best = i; - } - } - return best; - } -} -#endif -#endif - -void BuildGammaTable (float g, float c); -void D3D9_VID_GenPaletteTables (unsigned char *palette) -{ - extern unsigned short ramps[3][256]; - qbyte *pal; - unsigned r,g,b; - unsigned v; - unsigned short i; - unsigned *table; - extern qbyte gammatable[256]; - - if (palette) - { - extern cvar_t v_contrast; - BuildGammaTable(v_gamma.value, v_contrast.value); - - // - // 8 8 8 encoding - // - if (1)//vid_hardwaregamma.value) - { - // don't built in the gamma table - - pal = palette; - table = d_8to24rgbtable; - for (i=0 ; i<256 ; i++) - { - r = pal[0]; - g = pal[1]; - b = pal[2]; - pal += 3; - - // v = (255<<24) + (r<<16) + (g<<8) + (b<<0); - // v = (255<<0) + (r<<8) + (g<<16) + (b<<24); - v = (255<<24) + (r<<0) + (g<<8) + (b<<16); - *table++ = v; - } - d_8to24rgbtable[255] &= 0xffffff; // 255 is transparent - } - else - { - //computer has no hardware gamma (poor suckers) increase table accordingly - - pal = palette; - table = d_8to24rgbtable; - for (i=0 ; i<256 ; i++) - { - r = gammatable[pal[0]]; - g = gammatable[pal[1]]; - b = gammatable[pal[2]]; - pal += 3; - - // v = (255<<24) + (r<<16) + (g<<8) + (b<<0); - // v = (255<<0) + (r<<8) + (g<<16) + (b<<24); - v = (255<<24) + (r<<0) + (g<<8) + (b<<16); - *table++ = v; - } - d_8to24rgbtable[255] &= 0xffffff; // 255 is transparent - } - - if (LittleLong(1) != 1) - { - for (i=0 ; i<256 ; i++) - d_8to24rgbtable[i] = LittleLong(d_8to24rgbtable[i]); - } - } - - if (pD3DDev9) - IDirect3DDevice9_SetGammaRamp(pD3DDev9, 0, D3DSGR_NO_CALIBRATION, (D3DGAMMARAMP *)ramps); -} - -/* - -void D3D9_Mod_Think (void) -{ -} -void D3D9_Mod_NowLoadExternal(void) -{ -} -void D3D9_Mod_TouchModel (char *name) -{ -} -void *D3D9_Mod_Extradata (struct model_s *mod) // handles caching -{ - return NULL; -} -struct model_s *D3D9_Mod_FindName (char *name) -{ - return NULL; -} -struct model_s *D3D9_Mod_ForName (char *name, qboolean crash) -{ - return NULL; -} -void D3D9_Mod_ClearAll (void) -{ -} -void D3D9_Mod_Init (void) -{ -}*/ - - -typedef enum {MS_WINDOWED, MS_FULLSCREEN, MS_FULLDIB, MS_UNINIT} modestate_t; -static modestate_t modestate; - -qboolean D3D9AppActivate(BOOL fActive, BOOL minimize) -/**************************************************************************** -* -* Function: AppActivate -* Parameters: fActive - True if app is activating -* -* Description: If the application is activating, then swap the system -* into SYSPAL_NOSTATIC mode so that our palettes will display -* correctly. -* -****************************************************************************/ -{ - static BOOL sound_active; - - if (ActiveApp == fActive && Minimized == minimize) - return false; //so windows doesn't crash us over and over again. - - ActiveApp = fActive; - Minimized = minimize; - -// enable/disable sound on focus gain/loss - if (!ActiveApp && sound_active) - { - S_BlockSound (); - sound_active = false; - } - else if (ActiveApp && !sound_active) - { - S_UnblockSound (); - sound_active = true; - } - - IN_UpdateGrabs(modestate != MS_WINDOWED, ActiveApp); - - if (fActive) - { - Cvar_ForceCallback(&v_gamma); - } - if (!fActive) - { - Cvar_ForceCallback(&v_gamma); //wham bam thanks. - } - - return true; -} - - - - - -static LRESULT WINAPI D3D9_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - LONG lRet = 1; - int fActive, fMinimized, temp; - extern unsigned int uiWheelMessage; - - if ( uMsg == uiWheelMessage ) - uMsg = WM_MOUSEWHEEL; - - switch (uMsg) - { - case WM_KILLFOCUS: - if (modestate == MS_FULLDIB) - ShowWindow(mainwindow, SW_SHOWMINNOACTIVE); - break; - - case WM_CREATE: - break; - - case WM_MOVE: - GetWindowRect(mainwindow, &window_rect); - window_x = (int) LOWORD(lParam); - window_y = (int) HIWORD(lParam); -// VID_UpdateWindowStatus (); - break; - - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - if (!vid_initializing) - IN_TranslateKeyEvent (wParam, lParam, true, 0); - break; - - case WM_KEYUP: - case WM_SYSKEYUP: - if (!vid_initializing) - IN_TranslateKeyEvent (wParam, lParam, false, 0); - break; - - case WM_SYSCHAR: - // keep Alt-Space from happening - break; - - // this is complicated because Win32 seems to pack multiple mouse events into - // one update sometimes, so we always check all states and look for events - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MOUSEMOVE: - case WM_XBUTTONDOWN: - case WM_XBUTTONUP: - temp = 0; - - if (wParam & MK_LBUTTON) - temp |= 1; - - if (wParam & MK_RBUTTON) - temp |= 2; - - if (wParam & MK_MBUTTON) - temp |= 4; - - if (wParam & MK_XBUTTON1) - temp |= 8; - - if (wParam & MK_XBUTTON2) - temp |= 16; - - if (wParam & MK_XBUTTON3) - temp |= 32; - - if (wParam & MK_XBUTTON4) - temp |= 64; - - if (wParam & MK_XBUTTON5) - temp |= 128; - - if (wParam & MK_XBUTTON6) - temp |= 256; - - if (wParam & MK_XBUTTON7) - temp |= 512; - - if (!vid_initializing) - IN_MouseEvent (temp); - - break; - - // JACK: This is the mouse wheel with the Intellimouse - // Its delta is either positive or neg, and we generate the proper - // Event. - case WM_MOUSEWHEEL: - if (!vid_initializing) - { - if ((short) HIWORD(wParam) > 0) - { - Key_Event(K_MWHEELUP, 0, true); - Key_Event(K_MWHEELUP, 0, false); - } - else - { - Key_Event(K_MWHEELDOWN, 0, true); - Key_Event(K_MWHEELDOWN, 0, false); - } - } - break; - - case WM_INPUT: - // raw input handling - if (!vid_initializing) - IN_RawInput_Read((HANDLE)lParam); - break; - - case WM_SIZE: - if (!vid_initializing) - { - GetWindowRect(mainwindow, &window_rect); - // force width/height to be updated -// glwidth = window_rect.right - window_rect.left; -// glheight = window_rect.bottom - window_rect.top; -// Cvar_ForceCallback(&vid_conautoscale); -// Cvar_ForceCallback(&vid_conwidth); - } - break; - - case WM_CLOSE: - if (!vid_initializing) - if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", - MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES) - { - Sys_Quit (); - } - - break; - - case WM_ACTIVATE: - fActive = LOWORD(wParam); - fMinimized = (BOOL) HIWORD(wParam); - if (!D3D9AppActivate(!(fActive == WA_INACTIVE), fMinimized)) - break;//so, urm, tell me microsoft, what changed? - if (modestate == MS_FULLDIB) - ShowWindow(mainwindow, SW_SHOWNORMAL); - - // fix the leftover Alt from any Alt-Tab or the like that switched us away -// ClearAllStates (); - - break; - - case WM_DESTROY: - { -// if (dibwindow) -// DestroyWindow (dibwindow); - } - break; - - case MM_MCINOTIFY: - lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam); - break; - - default: - /* pass all unhandled messages to DefWindowProc */ - lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); - break; - } - - /* return 1 if handled message, 0 if not */ - return lRet; -} - -static D3DPRESENT_PARAMETERS d3dpp; -void resetD3D9(void) -{ - IDirect3DDevice9_Reset(pD3DDev9, &d3dpp); - - - IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0); - IDirect3DDevice9_BeginScene(pD3DDev9); - IDirect3DDevice9_EndScene(pD3DDev9); - IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL); - - - - - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHAFUNC, D3DCMP_GREATER ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHAREF, 0.666*256 ); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - - //IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRENDERSTATE_DITHERENABLE, FALSE); - //IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRENDERSTATE_SPECULARENABLE, FALSE); - //IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_LIGHTING, FALSE); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZWRITEENABLE, TRUE); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_LESSEQUAL); - -} - -#if (WINVER < 0x500) && !defined(__GNUC__) -typedef struct tagMONITORINFO -{ - DWORD cbSize; - RECT rcMonitor; - RECT rcWork; - DWORD dwFlags; -} MONITORINFO, *LPMONITORINFO; -#endif -/* -void testD3D(HWND hWnd) -{ - - D3DPRESENT_PARAMETERS d3dpp[2]; - - int i; - int numadaptors; - int err; - D3DADAPTER_IDENTIFIER9 inf; - - static HMODULE d3d9dll; - LPDIRECT3D9 (WINAPI *pDirect3DCreate9) (int version); - - if (!d3d9dll) - d3d9dll = LoadLibrary("d3d9.dll"); - if (!d3d9dll) - { - Con_Printf("Direct3d 9 does not appear to be installed\n"); - return; - } - pDirect3DCreate9 = (void*)GetProcAddress(d3d9dll, "Direct3DCreate9"); - if (!pDirect3DCreate9) - { - Con_Printf("Direct3d 9 does not appear to be installed properly\n"); - return; - } - - pD3D = pDirect3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface - if (!pD3D) - return; - - for (i = 0; i < 2; i++) - { - memset(&d3dpp[0], 0, sizeof(d3dpp)); // clear out the struct for use - d3dpp[0].SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames - d3dpp[0].hDeviceWindow = hWnd; // set the window to be used by Direct3D - d3dpp[0].BackBufferWidth = d3d9width = info->width; - d3dpp[0].BackBufferHeight = d3d9height = info->height; - d3dpp[0].MultiSampleType = info->multisample; - d3dpp[0].BackBufferCount = 3; - d3dpp[0].FullScreen_RefreshRateInHz = info->fullscreen?info->rate:0; //don't pass a rate if not fullscreen, d3d doesn't like it. - d3dpp[0].Windowed = !info->fullscreen; - - d3dpp[0].EnableAutoDepthStencil = true; - d3dpp[0].AutoDepthStencilFormat = D3DFMT_D16; - d3dpp[0].BackBufferFormat = info->fullscreen?D3DFMT_X8R8G8B8:D3DFMT_UNKNOWN; - } - - IDirect3D9_CreateDevice(pD3D, - i, - D3DDEVTYPE_HAL, - hWnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, - &d3dpp, - &pD3DDev9); - -} -*/ -void initD3D9(HWND hWnd, rendererstate_t *info) -{ - int i; - int numadaptors; - int err; - D3DADAPTER_IDENTIFIER9 inf; - extern cvar_t _vid_wait_override; - - static HMODULE d3d9dll; - LPDIRECT3D9 (WINAPI *pDirect3DCreate9) (int version); - - if (!d3d9dll) - d3d9dll = LoadLibrary("d3d9.dll"); - if (!d3d9dll) - { - Con_Printf("Direct3d 9 does not appear to be installed\n"); - return; - } - pDirect3DCreate9 = (void*)GetProcAddress(d3d9dll, "Direct3DCreate9"); - if (!pDirect3DCreate9) - { - Con_Printf("Direct3d 9 does not appear to be installed properly\n"); - return; - } - - pD3D = pDirect3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface - if (!pD3D) - return; - - numadaptors = IDirect3D9_GetAdapterCount(pD3D); - for (i = 0; i < numadaptors; i++) - { //try each adaptor in turn until we get one that actually works - memset(&d3dpp, 0, sizeof(d3dpp)); // clear out the struct for use - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames - d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D - d3dpp.BackBufferWidth = d3d9width = info->width; - d3dpp.BackBufferHeight = d3d9height = info->height; - d3dpp.MultiSampleType = info->multisample; - d3dpp.BackBufferCount = 3; - d3dpp.FullScreen_RefreshRateInHz = info->fullscreen?info->rate:0; //don't pass a rate if not fullscreen, d3d doesn't like it. - d3dpp.Windowed = !info->fullscreen; - - d3dpp.EnableAutoDepthStencil = true; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - d3dpp.BackBufferFormat = info->fullscreen?D3DFMT_X8R8G8B8:D3DFMT_UNKNOWN; - - if (!*_vid_wait_override.string) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - else - { - if (_vid_wait_override.value == 1) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - else if (_vid_wait_override.value == 2) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_TWO; - else if (_vid_wait_override.value == 3) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_THREE; - else if (_vid_wait_override.value == 4) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_FOUR; - else - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } - - memset(&inf, 0, sizeof(inf)); - err = IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &inf); - - // create a device class using this information and information from the d3dpp stuct - IDirect3D9_CreateDevice(pD3D, - i, - D3DDEVTYPE_HAL, - hWnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, - &d3dpp, - &pD3DDev9); - - if (pD3DDev9) - { - HMONITOR hm; - MONITORINFO mi; - char *s; - for (s = inf.Description + strlen(inf.Description)-1; s >= inf.Description && *s <= ' '; s--) - *s = 0; - Con_Printf("D3D9: Using device %s\n", inf.Description); - - if (d3dpp.Windowed) //fullscreen we get positioned automagically. - { //windowed, we get positioned at 0,0... which is often going to be on the wrong screen - //the user can figure it out from here - static HANDLE huser32; - BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR hMonitor, LPMONITORINFO lpmi); - if (!huser32) - huser32 = LoadLibrary("user32.dll"); - if (!huser32) - return; - pGetMonitorInfoA = (void*)GetProcAddress(huser32, "GetMonitorInfoA"); - if (!pGetMonitorInfoA) - return; - - hm = IDirect3D9_GetAdapterMonitor(pD3D, i); - memset(&mi, 0, sizeof(mi)); - mi.cbSize = sizeof(mi); - pGetMonitorInfoA(hm, &mi); - MoveWindow(d3dpp.hDeviceWindow, mi.rcWork.left, mi.rcWork.top, d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, false); - } - return; //successful - } - } - - - Con_Printf("IDirect3D9_CreateDevice failed\n"); - - - return; -} - -qboolean D3D9_VID_Init(rendererstate_t *info, unsigned char *palette) -{ - DWORD width = info->width; - DWORD height = info->height; - DWORD bpp = info->bpp; - DWORD zbpp = 16; - DWORD flags = 0; - MSG msg; - - extern cvar_t vid_conwidth; - extern cvar_t vid_conheight; - - //DDGAMMARAMP gammaramp; - //int i; - - char *CLASSNAME = "FTED3D9QUAKE"; - WNDCLASS wc = { - 0, - &D3D9_WindowProc, - 0, - 0, - NULL, - NULL, - NULL, - NULL, - NULL, - CLASSNAME - }; - - vid_initializing = true; - - RegisterClass(&wc); - - if (info->fullscreen) - mainwindow = CreateWindow(CLASSNAME, "Direct3D", 0, 0, 0, width, height, NULL, NULL, NULL, NULL); - else - mainwindow = CreateWindow(CLASSNAME, "Direct3D", WS_OVERLAPPEDWINDOW, 0, 0, width, height, NULL, NULL, NULL, NULL); -/* - width = vid_conwidth.value; - height = vid_conheight.value; -*/ - // Try as specified. - - initD3D9(mainwindow, info); - if (!pD3DDev9) - return false; - - - - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - ShowWindow(mainwindow, SW_NORMAL); - //IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1, 0); - //IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL); - - IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); - IDirect3DDevice9_BeginScene(pD3DDev9); - IDirect3DDevice9_EndScene(pD3DDev9); - IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL); - - - -// pD3DX->lpVtbl->GetBufferSize((void*)pD3DX, &width, &height); - vid.width = width; - vid.height = height; - vid.recalc_refdef = true; - -// pDD->lpVtbl->QueryInterface ((void*)pDD, &IID_IDirectDrawGammaControl, (void**)&pGammaControl); -/* if (pGammaControl) - { - for (i = 0; i < 256; i++) - gammaramp.red[i] = i*2; - pGammaControl->lpVtbl->SetGammaRamp(pGammaControl, 0, &gammaramp); - } - else*/ - Con_Printf("Couldn't get gamma controls\n"); - - vid_initializing = false; - - - -resetD3D9();/* - - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHAFUNC, D3DCMP_GREATER ); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHAREF, 0.666*256 ); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHATESTENABLE, TRUE ); - - - //IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRENDERSTATE_DITHERENABLE, FALSE); - //IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRENDERSTATE_SPECULARENABLE, FALSE); - //IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_LIGHTING, FALSE); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZWRITEENABLE, TRUE); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_LESSEQUAL); - -*/ - GetWindowRect(mainwindow, &window_rect); - - - D3D9_VID_GenPaletteTables(palette); - - { - extern qboolean mouseactive; - mouseactive = false; - } - - { - extern cvar_t v_contrast; - void GLV_Gamma_Callback(struct cvar_s *var, char *oldvalue); - Cvar_Hook(&v_gamma, GLV_Gamma_Callback); - Cvar_Hook(&v_contrast, GLV_Gamma_Callback); - - Cvar_ForceCallback(&v_gamma); - } - - { - extern cvar_t vid_conwidth, vid_conheight; - vid.conwidth = vid_conwidth.value; - vid.conheight = vid_conheight.value; - if (vid.width != vid.conwidth || vid.height != vid.conheight) - vid.recalc_refdef = true; - vid.width = vid.conwidth; - vid.height = vid.conheight; - } - - return true; -} - - - -qboolean (D3D9_R_CheckSky) (void) -{ - return false; -} -void (D3D9_R_SetSky) (char *name, float rotate, vec3_t axis) -{ -} - -void (D3D9_R_NewMap) (void) -{ - extern int skytexturenum; - int i; - r_worldentity.model = cl.worldmodel; - GLR_AnimateLight(); - D3D9_BuildLightmaps(); - - P_ClearParticles(); - - skytexturenum = -1; - - for (i=0 ; inumtextures ; i++) - { - if (!cl.worldmodel->textures[i]) - continue; - if (!Q_strncmp(cl.worldmodel->textures[i]->name,"sky",3) ) - skytexturenum = i; -// if (!Q_strncmp(cl.worldmodel->textures[i]->name,"window02_1",10) ) -// mirrortexturenum = i; - cl.worldmodel->textures[i]->texturechain = NULL; - } -} - -extern mleaf_t *r_viewleaf, *r_oldviewleaf; -extern mleaf_t *r_viewleaf2, *r_oldviewleaf2; -void (D3D9_R_PreNewMap) (void) -{ - r_viewleaf = NULL; - r_oldviewleaf = NULL; - r_viewleaf2 = NULL; - r_oldviewleaf2 = NULL; -} -int (D3D9_R_LightPoint) (vec3_t point) -{ - return 0; -} - -void (D3D9_R_PushDlights) (void) -{ -} -void (D3D9_R_AddStain) (vec3_t org, float red, float green, float blue, float radius) -{ -} -void (D3D9_R_LessenStains) (void) -{ -} - -void (D3D9_VID_DeInit) (void) -{ - if (pD3DDev9) - { - IDirect3DDevice9_Release(pD3DDev9); - pD3DDev9 = NULL; - } - if (pD3D) - { - IDirect3D9_Release(pD3D); - pD3D = NULL; - } - if (mainwindow) - { - DestroyWindow(mainwindow); - mainwindow = NULL; - } -} - -void (D3D9_VID_SetPalette) (unsigned char *palette) -{ - D3D9_VID_GenPaletteTables(palette); -} -void (D3D9_VID_ShiftPalette) (unsigned char *palette) -{ - D3D9_VID_GenPaletteTables(palette); -} -char *(D3D9_VID_GetRGBInfo) (int prepad, int *truevidwidth, int *truevidheight) -{ - return NULL; -} -void (D3D9_VID_SetWindowCaption) (char *msg) -{ - SetWindowText(mainwindow, msg); -} - -#if 0 -#undef IDirect3DDevice9_SetRenderState -void IDirect3DDevice9_SetRenderState(void *pD3DDev9, int D3DRS, int param) -{ -} -#endif - -void D3D9_Set2D (void) -{ - float m[16]; - D3DVIEWPORT9 vport; -// IDirect3DDevice9_EndScene(pD3DDev9); - - Matrix4_Orthographic(m, 0, vid.width, vid.height, 0, -100, 100); - d3d7_ortho(m); - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_PROJECTION, (D3DMATRIX*)m); - - Matrix4_Identity(m); - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_WORLD, (D3DMATRIX*)m); - - Matrix4_Identity(m); - IDirect3DDevice9_SetTransform(pD3DDev9, D3DTS_VIEW, (D3DMATRIX*)m); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_CULLMODE, D3DCULL_CCW ); - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZFUNC, D3DCMP_ALWAYS); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ZENABLE, D3DZB_FALSE); - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE ); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MIPFILTER, D3DTEXF_NONE ); - - IDirect3DDevice9_SetSamplerState(pD3DDev9, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); - IDirect3DDevice9_SetSamplerState(pD3DDev9, 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); - - vport.X = 0; - vport.Y = 0; - D3D9_GetBufferSize(&vport.Width, &vport.Height); - vport.MinZ = 0; - vport.MaxZ = 1; - IDirect3DDevice9_SetViewport(pD3DDev9, &vport); - -// IDirect3DDevice9_BeginScene(pD3DDev9); -} - -void D3D9_GetBufferSize(int *width, int *height) -{ - *width = d3d9width;//vid.width; - *height = d3d9height;//vid.height; -// IDirect3DDevice9_GetBufferSize((void*)pD3DX, width, height); -} - -int d3d9error(int i) -{ - if (FAILED(i))// != D3D_OK) - Con_Printf("D3D error: %x %i\n", i); - return i; -} - -typedef struct { - float x, y, z; - unsigned int colour; -} d3d9bsvert_t; -void D3D9_BrightenScreen (void) -{ - d3d9bsvert_t d3d9bsvert[4]; -index_t d3d9quadindexes[6] = { - 0, 1, 2, - 0, 2, 3 -}; - -extern cvar_t gl_contrast; - float f; - unsigned int colour; - - RSpeedMark(); - - if (gl_contrast.value <= 1.0) - return; - - f = gl_contrast.value; - f = min (f, 3); - - IDirect3DDevice9_SetTexture (pD3DDev9, 0, NULL); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, TRUE); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_ONE); - - while (f > 1) - { - if (f >= 2) - colour = 0xffffffff; - else - { - colour = (f-1)*255; - colour = (colour * 0x010101) | 0xff000000; - } - - - d3d9bsvert[0].x = 0; - d3d9bsvert[0].y = 0; - d3d9bsvert[0].z = 0; - d3d9bsvert[0].colour = colour; - - d3d9bsvert[1].x = vid.width; - d3d9bsvert[1].y = 0; - d3d9bsvert[1].z = 0; - d3d9bsvert[1].colour = colour; - - d3d9bsvert[2].x = vid.width; - d3d9bsvert[2].y = vid.height; - d3d9bsvert[2].z = 0; - d3d9bsvert[2].colour = colour; - - d3d9bsvert[3].x = 0; - d3d9bsvert[3].y = vid.height; - d3d9bsvert[3].z = 0; - d3d9bsvert[3].colour = colour; - - IDirect3DDevice9_SetFVF(pD3DDev9, D3DFVF_XYZ|D3DFVF_DIFFUSE); - IDirect3DDevice9_DrawIndexedPrimitiveUP(pD3DDev9, D3DPT_TRIANGLELIST, 0, 4, 2, d3d9quadindexes, D3DFMT_QINDEX, d3d9bsvert, sizeof(d3d9bsvert[0])); - - - f *= 0.5; - } - - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - IDirect3DDevice9_SetRenderState(pD3DDev9, D3DRS_ALPHABLENDENABLE, FALSE); - - RSpeedEnd(RSPEED_PALETTEFLASHES); -} - -void (D3D9_SCR_UpdateScreen) (void) -{ - extern int keydown[]; - extern cvar_t vid_conheight; - int uimenu; -#ifdef TEXTEDITOR - extern qboolean editormodal; -#endif - qboolean nohud; - RSpeedMark(); - - switch (IDirect3DDevice9_TestCooperativeLevel(pD3DDev9)) - { - case D3DERR_DEVICELOST: - //the user has task switched away from us or something - return; - case D3DERR_DEVICENOTRESET: - resetD3D9(); - if (FAILED(IDirect3DDevice9_TestCooperativeLevel(pD3DDev9))) - Sys_Error("D3D9 Device lost. Additionally restoration failed.\n"); - // D3DSucks(); - // scr_disabled_for_loading = false; - - VID_ShiftPalette (NULL); - break; - default: - break; - } - - - if (keydown['k']) - { - d3d9error(IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(rand()&255, rand()&255, rand()&255), 1.0f, 0)); - d3d9error(IDirect3DDevice9_BeginScene(pD3DDev9)); - d3d9error(IDirect3DDevice9_EndScene(pD3DDev9)); - d3d9error(IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL)); - - VID_ShiftPalette (NULL); - } - - vid.numpages = 2;// + gl_triplebuffer.value; - - if (scr_disabled_for_loading) - { - extern float scr_disabled_time; - if (Sys_DoubleTime() - scr_disabled_time > 60 || key_dest != key_game) - { - scr_disabled_for_loading = false; - } - else - { - IDirect3DDevice9_BeginScene(pD3DDev9); - scr_drawloading = true; - SCR_DrawLoading (); - scr_drawloading = false; - IDirect3DDevice9_EndScene(pD3DDev9); - IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL); - RSpeedEnd(RSPEED_TOTALREFRESH); - return; - } - } - - if (!scr_initialized || !con_initialized) - { - RSpeedEnd(RSPEED_TOTALREFRESH); - return; // not initialized yet - } - - { - extern cvar_t vid_conwidth, vid_conheight; - vid.conwidth = vid_conwidth.value; - vid.conheight = vid_conheight.value; - if (vid.width != vid.conwidth || vid.height != vid.conheight) - vid.recalc_refdef = true; - vid.width = vid.conwidth; - vid.height = vid.conheight; - } - - -#ifdef VM_UI - uimenu = UI_MenuState(); -#else - uimenu = 0; -#endif - - d3d9error(IDirect3DDevice9_BeginScene(pD3DDev9)); - D3D9_Set2D (); -/* -#ifdef TEXTEDITOR - if (editormodal) - { - Editor_Draw(); - GLV_UpdatePalette (false, host_frametime); -#if defined(_WIN32) && defined(GLQUAKE) - Media_RecordFrame(); -#endif - GLR_BrightenScreen(); - - if (key_dest == key_console) - Con_DrawConsole(vid_conheight.value/2, false); - GL_EndRendering (); - GL_DoSwap(); - RSpeedEnd(RSPEED_TOTALREFRESH); - return; - } -#endif -*/ - if (Media_ShowFilm()) - { - M_Draw(0); -// GLV_UpdatePalette (false, host_frametime); -#if defined(_WIN32) - Media_RecordFrame(); -#endif -// GLR_BrightenScreen(); - IDirect3DDevice9_EndScene(pD3DDev9); - IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL); - - d3d9error(IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(rand()&255, rand()&255, rand()&255), 1, 0)); - -// pD3DDev->lpVtbl->BeginScene(pD3DDev); - - RSpeedEnd(RSPEED_TOTALREFRESH); - return; - } - - // - // determine size of refresh window - // - if (vid.recalc_refdef) - SCR_CalcRefdef (); - -// -// do 3D refresh drawing, and then update the screen -// - SCR_SetUpToDrawConsole (); - - nohud = false; - -#ifdef VM_CG - if (CG_Refresh()) - nohud = true; - else -#endif -#ifdef CSQC_DAT - if (cls.state == ca_active && CSQC_DrawView()) - nohud = true; - else -#endif - if (r_worldentity.model && uimenu != 1) - { - V_RenderView (); -// Q1BSP_TestClipDecal(); - } - - - D3D9_Set2D (); - - D3D9_BrightenScreen(); - - if (!nohud) - SCR_TileClear (); - - SCR_DrawTwoDimensional(uimenu, nohud); - - GLV_UpdatePalette (false, host_frametime); -#if defined(_WIN32) && defined(GLQUAKE) - Media_RecordFrame(); -#endif - - RSpeedEnd(RSPEED_TOTALREFRESH); - RSpeedShow(); - - - - d3d9error(IDirect3DDevice9_EndScene(pD3DDev9)); - d3d9error(IDirect3DDevice9_Present(pD3DDev9, NULL, NULL, NULL, NULL)); - - - - d3d9error(IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, rand()&255), 1, 0)); - d3d9error(IDirect3DDevice9_Clear(pD3DDev9, 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(rand()&255, rand()&255, rand()&255), 1, 0)); - - window_center_x = (window_rect.left + window_rect.right)/2; - window_center_y = (window_rect.top + window_rect.bottom)/2; - - - IN_UpdateGrabs(modestate != MS_WINDOWED, ActiveApp); - - VID_ShiftPalette (NULL); -} - - - - - -mpic_t *(D3D9_Draw_SafePicFromWad) (char *name); -mpic_t *(D3D9_Draw_CachePic) (char *path); -mpic_t *(D3D9_Draw_SafeCachePic) (char *path); -void (D3D9_Draw_Init) (void); -void (D3D9_Draw_ReInit) (void); -void (D3D9_Draw_Character) (int x, int y, unsigned int num); -void (D3D9_Draw_ColouredCharacter) (int x, int y, unsigned int num); -void (D3D9_Draw_String) (int x, int y, const qbyte *str); -void (D3D9_Draw_Alt_String) (int x, int y, const qbyte *str); -void (D3D9_Draw_Crosshair) (void); -void (D3D9_Draw_DebugChar) (qbyte num); -void (D3D9_Draw_Pic) (int x, int y, mpic_t *pic); -void (D3D9_Draw_ScalePic) (int x, int y, int width, int height, mpic_t *pic); -void (D3D9_Draw_SubPic) (int x, int y, mpic_t *pic, int srcx, int srcy, int width, int height); -void (D3D9_Draw_TransPic) (int x, int y, mpic_t *pic); -void (D3D9_Draw_TransPicTranslate) (int x, int y, int w, int h, qbyte *pic, qbyte *translation); -void D3D9_Draw_ConsoleBackground (int firstline, int lastline, qboolean forceopaque); -void (D3D9_Draw_EditorBackground) (int lines); -void (D3D9_Draw_TileClear) (int x, int y, int w, int h); -void (D3D9_Draw_Fill) (int x, int y, int w, int h, unsigned int c); -void (D3D9_Draw_FillRGB) (int x, int y, int w, int h, float r, float g, float b); -void (D3D9_Draw_FadeScreen) (void); -void (D3D9_Draw_BeginDisc) (void); -void (D3D9_Draw_EndDisc) (void); - -void (D3D9_Draw_Image) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, mpic_t *pic); //gl-style scaled/coloured/subpic -void (D3D9_Draw_ImageColours) (float r, float g, float b, float a); - -void (D3D9_R_Init) (void); -void (D3D9_R_DeInit) (void); -void (D3D9_R_ReInit) (void); -void (D3D9_R_RenderView) (void); // must set r_refdef first - -qboolean (D3D9_R_CheckSky) (void); -void (D3D9_R_SetSky) (char *name, float rotate, vec3_t axis); - -void (D3D9_R_NewMap) (void); -void (D3D9_R_PreNewMap) (void); -int (D3D9_R_LightPoint) (vec3_t point); - -void (D3D9_R_PushDlights) (void); -void (D3D9_R_AddStain) (vec3_t org, float red, float green, float blue, float radius); -void (D3D9_R_LessenStains) (void); - -void (D3D9_Media_ShowFrameBGR_24_Flip) (qbyte *framedata, int inwidth, int inheight); //input is bottom up... -void (D3D9_Media_ShowFrameRGBA_32) (qbyte *framedata, int inwidth, int inheight); //top down -void (D3D9_Media_ShowFrame8bit) (qbyte *framedata, int inwidth, int inheight, qbyte *palette); //paletted topdown (framedata is 8bit indexes into palette) - -void (D3D9_Mod_Init) (void); -void (D3D9_Mod_ClearAll) (void); -struct model_s *(D3D9_Mod_ForName) (char *name, qboolean crash); -struct model_s *(D3D9_Mod_FindName) (char *name); -void *(D3D9_Mod_Extradata) (struct model_s *mod); // handles caching -void (D3D9_Mod_TouchModel) (char *name); - -void (D3D9_Mod_NowLoadExternal) (void); -void (D3D9_Mod_Think) (void); -qboolean(D3D9_Mod_GetTag) (struct model_s *model, int tagnum, int frame1, int frame2, float f2ness, float f1time, float f2time, float *result); -int (D3D9_Mod_TagNumForName) (struct model_s *model, char *name); -int (D3D9_Mod_SkinForName) (struct model_s *model, char *name); - - -qboolean (D3D9_VID_Init) (rendererstate_t *info, unsigned char *palette); -void (D3D9_VID_DeInit) (void); -void (D3D9_VID_LockBuffer) (void); -void (D3D9_VID_UnlockBuffer) (void); -void (D3D9_D_BeginDirectRect) (int x, int y, qbyte *pbitmap, int width, int height); -void (D3D9_D_EndDirectRect) (int x, int y, int width, int height); -void (D3D9_VID_ForceLockState) (int lk); -int (D3D9_VID_ForceUnlockedAndReturnState) (void); -void (D3D9_VID_SetPalette) (unsigned char *palette); -void (D3D9_VID_ShiftPalette) (unsigned char *palette); -char *(D3D9_VID_GetRGBInfo) (int prepad, int *truevidwidth, int *truevidheight); -void (D3D9_VID_SetWindowCaption) (char *msg); - -void (D3D9_SCR_UpdateScreen) (void); - - - - - - - -rendererinfo_t d3d9rendererinfo = -{ - "Direct3D9 Native", - { - "D3D9", - "Direct3d", - "DirectX", - "DX" - }, - QR_DIRECT3D, - - D3D9_Draw_SafePicFromWad, - D3D9_Draw_CachePic, - D3D9_Draw_SafeCachePic, - D3D9_Draw_Init, - D3D9_Draw_ReInit, - D3D9_Draw_Character, - D3D9_Draw_ColouredCharacter, - NULL, - D3D9_Draw_String, - D3D9_Draw_Alt_String, - D3D9_Draw_Crosshair, - D3D9_Draw_DebugChar, - D3D9_Draw_Pic, - D3D9_Draw_ScalePic, - D3D9_Draw_SubPic, - D3D9_Draw_TransPic, - D3D9_Draw_TransPicTranslate, - D3D9_Draw_ConsoleBackground, - D3D9_Draw_EditorBackground, - D3D9_Draw_TileClear, - D3D9_Draw_Fill, - D3D9_Draw_FillRGB, - D3D9_Draw_FadeScreen, - D3D9_Draw_BeginDisc, - D3D9_Draw_EndDisc, - - D3D9_Draw_Image, - D3D9_Draw_ImageColours, - - D3D9_R_Init, - D3D9_R_DeInit, - D3D9_R_ReInit, - D3D9_R_RenderView, - - D3D9_R_CheckSky, - D3D9_R_SetSky, - - D3D9_R_NewMap, - D3D9_R_PreNewMap, - D3D9_R_LightPoint, - - D3D9_R_PushDlights, - D3D9_R_AddStain, - D3D9_R_LessenStains, - - D3D9_Media_ShowFrameBGR_24_Flip, - D3D9_Media_ShowFrameRGBA_32, - D3D9_Media_ShowFrame8bit, - - GLMod_Init, - GLMod_ClearAll, - GLMod_ForName, - GLMod_FindName, - GLMod_Extradata, - GLMod_TouchModel, - - GLMod_NowLoadExternal, - GLMod_Think, - Mod_GetTag, - Mod_TagNumForName, - Mod_SkinNumForName, - Mod_FrameNumForName, - Mod_FrameDuration, - - - D3D9_VID_Init, - D3D9_VID_DeInit, - D3D9_VID_LockBuffer, - D3D9_VID_UnlockBuffer, - D3D9_D_BeginDirectRect, - D3D9_D_EndDirectRect, - D3D9_VID_ForceLockState, - D3D9_VID_ForceUnlockedAndReturnState, - D3D9_VID_SetPalette, - D3D9_VID_ShiftPalette, - D3D9_VID_GetRGBInfo, - D3D9_VID_SetWindowCaption, - - D3D9_SCR_UpdateScreen - -}; -#endif diff --git a/engine/gl/gl_rmain.c b/engine/gl/gl_rmain.c index 95a8e07b6..fe574d361 100644 --- a/engine/gl/gl_rmain.c +++ b/engine/gl/gl_rmain.c @@ -514,7 +514,7 @@ void R_RotateForEntity (float *modelview, const entity_t *e, const model_t *mod) { /*FIXME: no bob*/ float simpleview[16]; - vec3_t ang, f, r, u; + vec3_t ang; ang[0] = 0; ang[1] = 0; ang[2] = gl_screenangle.value; diff --git a/engine/gl/gl_vidnt.c b/engine/gl/gl_vidnt.c index ae8851e2b..a65971d9c 100644 --- a/engine/gl/gl_vidnt.c +++ b/engine/gl/gl_vidnt.c @@ -93,10 +93,6 @@ extern cvar_t vid_wndalpha; typedef enum {MS_WINDOWED, MS_FULLSCREEN, MS_FULLDIB, MS_UNINIT} modestate_t; -#ifdef USE_D3D -void D3DInitialize(void); -void d3dSetMode(int fullscreen, int width, int height, int bpp, int zbpp); -#endif BOOL bSetupPixelFormat(HDC hDC); //qboolean VID_SetWindowedMode (int modenum); @@ -872,26 +868,6 @@ qboolean VID_AttachGL (rendererstate_t *info) { //make sure we can get a valid renderer. do { -#ifdef USE_D3D - if (!Q_strcasecmp(info->glrenderer, "D3D")) - { - int zbpp = info->bpp > 16 ? 24 : 16; - gl_canstencil = false; - TRACE(("dbg: VID_AttachGL: D3DInitialize\n")); - D3DInitialize(); //replacement of GLInitialise, to get the function pointers set up. - if (COM_CheckParm("-zbpp")) - { - zbpp = Q_atoi(com_argv[COM_CheckParm("-zbpp")+1]); - } - TRACE(("dbg: VID_AttachGL: d3dSetMode\n")); - d3dSetMode(info->fullscreen, info->width, info->height, info->bpp, zbpp); //d3d cheats to get it's dimensions and stuff... One that we can currently live with though. - - maindc = GetDC(mainwindow); - - Con_Printf(CON_NOTICE "OpenGL to Direct3D wrapper enabled\n"); //green to make it show. - break; - } -#endif TRACE(("dbg: VID_AttachGL: GLInitialise\n")); if (GLInitialise(info->glrenderer)) { diff --git a/engine/gl/gltod3d/gl_fakegl.cpp b/engine/gl/gltod3d/gl_fakegl.cpp deleted file mode 100644 index 481a42efd..000000000 --- a/engine/gl/gltod3d/gl_fakegl.cpp +++ /dev/null @@ -1,4174 +0,0 @@ -/* -Copyright (C) 2000 Jack Palevich. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// gl_fakegl.cpp -- Uses Direct3D 7.0 to implement a subset of OpenGL. - -/* -This would probably be faster if it wasn't written in cpp. -the fact that it uses wrapper functions to call methods in a class could be a reasonable hit in speed. -*/ - -#include "bothdefs.h" //our always-present config file - -#ifdef USE_D3D - - -#define WIN32_LEAN_AND_MEAN -#include - -#if 0 -#undef WINGDIAPI -#define WINGDIAPI -#undef APIENTRY -#define APIENTRY -#endif - -#include - -#if 0 -#undef APIENTRY -#define APIENTRY WINAPI -#undef WINGDIAPI -#define WINGDIAPI DECLSPEC_IMPORT -#endif - -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4820 ) - -#if (_MSC_VER < 1400) -#define D3D_OVERLOADS -#endif - -#define RELEASENULL(object) if (object) {object->Release();} - -#include "ddraw.h" -#include "d3d.h" -#include "d3dx.h" - -typedef HRESULT (WINAPI *qD3DXInitialize_t)(); -qD3DXInitialize_t qD3DXInitialize; -typedef HRESULT (WINAPI *qD3DXUninitialize_t)(); -qD3DXUninitialize_t qD3DXUninitialize; -typedef D3DXMATRIX* (WINAPI *qD3DXMatrixScaling_t) ( D3DXMATRIX *pOut, float sx, float sy, float sz ); -qD3DXMatrixScaling_t qD3DXMatrixScaling; -typedef void (WINAPI *qD3DXGetErrorString_t)(HRESULT hr, DWORD strLength, LPSTR pStr); -qD3DXGetErrorString_t qD3DXGetErrorString; -typedef D3DXMATRIX* (WINAPI *qD3DXMatrixPerspectiveOffCenter_t) ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn, float zf ); -qD3DXMatrixPerspectiveOffCenter_t qD3DXMatrixPerspectiveOffCenter; -typedef D3DXMATRIX* (WINAPI *qD3DXMatrixOrthoOffCenter_t) ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn, float zf ); -qD3DXMatrixOrthoOffCenter_t qD3DXMatrixOrthoOffCenter; -typedef HRESULT (WINAPI *qD3DXCreateContextEx_t)(DWORD deviceIndex, DWORD flags,HWND hwnd,HWND hwndFocus, DWORD numColorBits,DWORD numAlphaBits,DWORD numDepthbits,DWORD numStencilBits,DWORD numBackBuffers,DWORD width, DWORD height,DWORD refreshRate,LPD3DXCONTEXT* ppCtx); -qD3DXCreateContextEx_t qD3DXCreateContextEx; -typedef HRESULT (WINAPI *qD3DXCreateMatrixStack_t)( DWORD flags, LPD3DXMATRIXSTACK *ppStack ); -qD3DXCreateMatrixStack_t qD3DXCreateMatrixStack; -typedef HRESULT (WINAPI *qD3DXCheckTextureRequirements_t)( LPDIRECT3DDEVICE7 pd3dDevice, LPDWORD pFlags, LPDWORD pWidth, LPDWORD pHeight, D3DX_SURFACEFORMAT* pPixelFormat); -qD3DXCheckTextureRequirements_t qD3DXCheckTextureRequirements; -typedef HRESULT (WINAPI *qD3DXMakeDDPixelFormat_t) (D3DX_SURFACEFORMAT d3dxFormat, DDPIXELFORMAT* pddpf); -qD3DXMakeDDPixelFormat_t qD3DXMakeDDPixelFormat; -typedef D3DXMATRIX* (WINAPI *qD3DXMatrixTranslation_t) ( D3DXMATRIX *pOut, float x, float y, float z ); -qD3DXMatrixTranslation_t qD3DXMatrixTranslation; - -extern "C" { -#include "quakedef.h" -#include "glquake.h" -} -#ifdef USE_D3D - -// Choose one of the following. D3DXContext is new in DX7, and -// provides a standard way of managing DX. D3DFrame is from -// the D3DIM sample code. -// Advantages of D3DXContext: -// + less code. -// + official standard. -// + Does standard things correctly. (For example I can get Gamma -// correction to work. I can't get it to work with D3DFrame, -// probably because I've left out some stupid step.) -// -// Advantages of D3DFrame -// + Some hacked DX7 drivers that are really DX6 drivers will crash -// with D3DXContext, but work with D3DFrame. Pre-release Windows 2000 -// Voodoo drivers are an example. -// + Source is available, so you can do things any way you want. - -#define USE_D3DXCONTEXT -// #define USE_D3DFRAME - -#ifdef USE_D3DFRAME -#include "d3denum.h" -#include "d3dframe.h" -#include "d3dutil.h" -#endif - -#if 0 -#undef APIENTRY -#define APIENTRY -#endif - -#define TEXTURE0_SGIS 0x835E -#define TEXTURE1_SGIS 0x835F - - -#ifdef _DEBUG -void LocalDebugBreak(){ - DebugBreak(); -} -#else -void LocalDebugBreak(){ -} -#endif - -// Globals -bool g_force16bitTextures; -bool gFullScreen = true; -DWORD gWidth = 640; -DWORD gHeight = 480; -DWORD gBpp = 16; -DWORD gZbpp = 16; -class FakeGL; -static FakeGL* gFakeGL; - -class TextureEntry { -public: - TextureEntry(){ - m_id = 0; - m_texture = 0; - m_format = D3DX_SF_UNKNOWN; - m_internalFormat = 0; - - m_glTexParameter2DMinFilter = GL_NEAREST_MIPMAP_LINEAR; - m_glTexParameter2DMagFilter = GL_LINEAR; - m_glTexParameter2DWrapS = GL_REPEAT; - m_glTexParameter2DWrapT = GL_REPEAT; - m_maxAnisotropy = 1.0; - } - ~TextureEntry(){ - } - GLuint m_id; - LPDIRECTDRAWSURFACE7 m_texture; - D3DX_SURFACEFORMAT m_format; - GLint m_internalFormat; - - GLint m_glTexParameter2DMinFilter; - GLint m_glTexParameter2DMagFilter; - GLint m_glTexParameter2DWrapS; - GLint m_glTexParameter2DWrapT; - float m_maxAnisotropy; -}; - - -#define TASIZE 2000 - -class TextureTable { -public: - TextureTable(){ - m_count = 0; - m_size = 0; - m_textures = 0; - m_currentTexture = 0; - m_currentID = 0; - BindTexture(0); - } - ~TextureTable(){ - DWORD i; - for(i = 0; i < m_count; i++) { - RELEASENULL(m_textures[i].m_texture); - } - for(i = 0; i < TASIZE; i++) { - RELEASENULL(m_textureArray[i].m_texture); - } - - delete [] m_textures; - } - - void BindTexture(GLuint id){ - TextureEntry* oldEntry = m_currentTexture; - m_currentID = id; - - if ( id < TASIZE ) { - m_currentTexture = m_textureArray + id; - if ( m_currentTexture->m_id ) { - return; - } - } - else { - // Check overflow table. - // Really ought to be a hash table. - for(DWORD i = 0; i < m_count; i++){ - if ( id == m_textures[i].m_id ) { - m_currentTexture = m_textures + i; - return; - } - } - // It's a new ID. - // Ensure space in the table - if ( m_count >= m_size ) { - int newSize = m_size * 2 + 10; - TextureEntry* newTextures = new TextureEntry[newSize]; - for(DWORD i = 0; i < m_count; i++ ) { - newTextures[i] = m_textures[i]; - } - delete[] m_textures; - m_textures = newTextures; - m_size = newSize; - } - // Put new entry in table - oldEntry = m_currentTexture; - m_currentTexture = m_textures + m_count; - m_count++; - } - if ( oldEntry ) { - *m_currentTexture = *oldEntry; - } - m_currentTexture->m_id = id; - m_currentTexture->m_texture = NULL; - } - - int GetCurrentID() { - return m_currentID; - } - - TextureEntry* GetCurrentEntry() { - return m_currentTexture; - } - - TextureEntry* GetEntry(GLuint id){ - if ( m_currentID == id && m_currentTexture ) { - return m_currentTexture; - } - if ( id < TASIZE ) { - return &m_textureArray[id]; - } - else { - // Check overflow table. - // Really ought to be a hash table. - for(DWORD i = 0; i < m_count; i++){ - if ( id == m_textures[i].m_id ) { - return &m_textures[i]; - } - } - } - return 0; - } - - LPDIRECTDRAWSURFACE7 GetTexture(){ - if ( m_currentTexture ) { - return m_currentTexture->m_texture; - } - return 0; - } - - LPDIRECTDRAWSURFACE7 GetTexture(int id){ - TextureEntry* entry = GetEntry(id); - if ( entry ) { - return entry->m_texture; - } - return 0; - } - - D3DX_SURFACEFORMAT GetSurfaceFormat() { - if ( m_currentTexture ) { - return m_currentTexture->m_format; - } - return D3DX_SF_UNKNOWN; - } - - GLint GetInternalFormat() { - if ( m_currentTexture ) { - return m_currentTexture->m_internalFormat; - } - return 0; - } - void SetTexture(LPDIRECTDRAWSURFACE7 texture, D3DX_SURFACEFORMAT d3dFormat, GLint internalFormat){ - if ( !m_currentTexture ) { - BindTexture(0); - } - RELEASENULL ( m_currentTexture->m_texture ); - m_currentTexture->m_texture = texture; - m_currentTexture->m_format = d3dFormat; - m_currentTexture->m_internalFormat = internalFormat; - } -private: - GLuint m_currentID; - DWORD m_count; - DWORD m_size; - TextureEntry m_textureArray[TASIZE]; // IDs 0..TASIZE-1 - TextureEntry* m_textures; // Overflow - - TextureEntry* m_currentTexture; -}; - - -#if 1 -#define Clamp(x) (x) // No clamping -- we've made sure the inputs are in the range 0..1 -#else -float Clamp(float x) { - if ( x < 0 ) { - x = 0; - LocalDebugBreak(); - } - else if ( x > 1 ) { - x = 1; - LocalDebugBreak(); - } - return x; -} -#endif - -static DWORD GLToDXSBlend(GLenum glBlend){ - DWORD result = D3DBLEND_ONE; - switch ( glBlend ) { - case GL_ZERO: result = D3DBLEND_ZERO; break; - case GL_ONE: result = D3DBLEND_ONE; break; - case GL_DST_COLOR: result = D3DBLEND_DESTCOLOR; break; - case GL_ONE_MINUS_DST_COLOR: result = D3DBLEND_INVDESTCOLOR; break; - case GL_SRC_ALPHA: result = D3DBLEND_SRCALPHA; break; - case GL_ONE_MINUS_SRC_ALPHA: result = D3DBLEND_INVSRCALPHA; break; - case GL_DST_ALPHA: result = D3DBLEND_DESTALPHA; break; - case GL_ONE_MINUS_DST_ALPHA: result = D3DBLEND_INVDESTALPHA; break; - case GL_SRC_ALPHA_SATURATE: result = D3DBLEND_SRCALPHASAT; break; - default: LocalDebugBreak(); break; - } - return result; -} - -static DWORD GLToDXDBlend(GLenum glBlend){ - DWORD result = D3DBLEND_ONE; - switch ( glBlend ) { - case GL_ZERO: result = D3DBLEND_ZERO; break; - case GL_ONE: result = D3DBLEND_ONE; break; - case GL_SRC_COLOR: result = D3DBLEND_SRCCOLOR; break; - case GL_ONE_MINUS_SRC_COLOR: result = D3DBLEND_INVSRCCOLOR; break; - case GL_SRC_ALPHA: result = D3DBLEND_SRCALPHA; break; - case GL_ONE_MINUS_SRC_ALPHA: result = D3DBLEND_INVSRCALPHA; break; - case GL_DST_ALPHA: result = D3DBLEND_DESTALPHA; break; - case GL_ONE_MINUS_DST_ALPHA: result = D3DBLEND_INVDESTALPHA; break; - default: LocalDebugBreak(); break; - } - return result; -} - -static DWORD GLToDXCompare(GLenum func){ - DWORD result = D3DCMP_ALWAYS; - switch ( func ) { - case GL_NEVER: result = D3DCMP_NEVER; break; - case GL_LESS: result = D3DCMP_LESS; break; - case GL_EQUAL: result = D3DCMP_EQUAL; break; - case GL_LEQUAL: result = D3DCMP_LESSEQUAL; break; - case GL_GREATER: result = D3DCMP_GREATER; break; - case GL_NOTEQUAL: result = D3DCMP_NOTEQUAL; break; - case GL_GEQUAL: result = D3DCMP_GREATEREQUAL; break; - case GL_ALWAYS: result = D3DCMP_ALWAYS; break; - default: break; - } - return result; -} - -/* - OpenGL MinFilter MipFilter Comments - GL_NEAREST D3DTFN_POINT D3DTFP_NONE - GL_LINEAR D3DTFN_LINEAR D3DTFP_NONE - GL_NEAREST_MIPMAP_NEAREST D3DTFN_POINT D3DTFP_POINT - GL_LINEAR_MIPMAP_NEAREST D3DTFN_LINEAR D3DTFP_POINT bilinear - GL_NEAREST_MIPMAP_LINEAR D3DTFN_POINT D3DTFP_LINEAR - GL_LINEAR_MIPMAP_LINEAR D3DTFN_LINEAR D3DTFP_LINEAR trilinear -*/ -static DWORD GLToDXMinFilter(GLint filter){ - DWORD result = D3DTFN_LINEAR; - switch ( filter ) { - case GL_NEAREST: result = D3DTFN_POINT; break; - case GL_LINEAR: result = D3DTFN_LINEAR; break; - case GL_NEAREST_MIPMAP_NEAREST: result = D3DTFN_POINT; break; - case GL_LINEAR_MIPMAP_NEAREST: result = D3DTFN_LINEAR; break; - case GL_NEAREST_MIPMAP_LINEAR: result = D3DTFN_POINT; break; - case GL_LINEAR_MIPMAP_LINEAR: result = D3DTFN_LINEAR; break; - default: - LocalDebugBreak(); - break; - } - return result; -} - -static DWORD GLToDXMipFilter(GLint filter){ - DWORD result = D3DTFP_POINT; - switch ( filter ) { - case GL_NEAREST: result = D3DTFP_NONE; break; - case GL_LINEAR: result = D3DTFP_NONE; break; - case GL_NEAREST_MIPMAP_NEAREST: result = D3DTFP_POINT; break; - case GL_LINEAR_MIPMAP_NEAREST: result = D3DTFP_POINT; break; - case GL_NEAREST_MIPMAP_LINEAR: result = D3DTFP_LINEAR; break; - case GL_LINEAR_MIPMAP_LINEAR: result = D3DTFP_LINEAR; break; - default: - LocalDebugBreak(); - break; - } - return result; -} - -static DWORD GLToDXMagFilter(GLint filter){ - DWORD result = D3DTFG_POINT; - switch ( filter ) { - case GL_NEAREST: result = D3DTFG_POINT; break; - case GL_LINEAR: result = D3DTFG_LINEAR; break; - default: - LocalDebugBreak(); - break; - } - return result; -} - -static DWORD GLToDXTextEnvMode(GLint mode){ - DWORD result = D3DTOP_MODULATE; - switch ( mode ) { - case GL_MODULATE: result = D3DTOP_MODULATE; break; - case GL_DECAL: result = D3DTOP_SELECTARG1; break; // Fix this - case GL_BLEND: result = D3DTOP_BLENDTEXTUREALPHA; break; - case GL_REPLACE: result = D3DTOP_SELECTARG1; break; - default: break; - } - return result; -} - -#define MAXSTATES 8 - -class TextureStageState { -public: - TextureStageState() { - m_currentTexture = 0; - m_glTextEnvMode = GL_MODULATE; - m_glTexture2D = false; - m_dirty = true; - } - - bool GetDirty() { return m_dirty; } - void SetDirty(bool dirty) { m_dirty = dirty; } - - void DirtyTexture(GLuint textureID) { - if ( textureID == m_currentTexture ) { - m_dirty = true; - } - } - - GLuint GetCurrentTexture() { return m_currentTexture; } - void SetCurrentTexture(GLuint texture) { m_dirty = true; m_currentTexture = texture; } - - GLfloat GetTextEnvMode() { return m_glTextEnvMode; } - void SetTextEnvMode(GLfloat mode) { m_dirty = true; m_glTextEnvMode = mode; } - - bool GetTexture2D() { return m_glTexture2D; } - void SetTexture2D(bool texture2D) { m_dirty = true; m_glTexture2D = texture2D; } - -private: - - GLuint m_currentTexture; - GLfloat m_glTextEnvMode; - bool m_glTexture2D; - bool m_dirty; -}; - -class TextureState { -public: - TextureState(){ - m_currentStage = 0; - memset(&m_stage, 0, sizeof(m_stage)); - m_dirty = false; - m_mainBlend = false; - } - - void SetMaxStages(int maxStages){ - m_maxStages = maxStages; - for(int i = 0; i < m_maxStages;i++){ - m_stage[i].SetDirty(true); - } - m_dirty = true; - } - - // Keep track of changes to texture stage state - void SetCurrentStage(int index){ - m_currentStage = index; - } - - int GetMaxStages() { return m_maxStages; } - bool GetDirty() { return m_dirty; } - void DirtyTexture(int textureID){ - for(int i = 0; i < m_maxStages;i++){ - m_stage[i].DirtyTexture(textureID); - } - m_dirty = true; - } - - void SetMainBlend(bool mainBlend){ - m_mainBlend = mainBlend; - m_stage[0].SetDirty(true); - m_dirty = true; - } - - // These methods apply to the current stage - - GLuint GetCurrentTexture() { return Get()->GetCurrentTexture(); } - void SetCurrentTexture(GLuint texture) { m_dirty = true; Get()->SetCurrentTexture(texture); } - - GLfloat GetTextEnvMode() { return Get()->GetTextEnvMode(); } - void SetTextEnvMode(GLfloat mode) { m_dirty = true; Get()->SetTextEnvMode(mode); } - - bool GetTexture2D() { return Get()->GetTexture2D(); } - void SetTexture2D(bool texture2D) { m_dirty = true; Get()->SetTexture2D(texture2D); } - - void SetTextureStageState(LPDIRECT3DDEVICE7 pD3DDev, TextureTable* textures){ - if ( ! m_dirty ) { - return; - } - - m_dirty = false; - - for(int i = 0; i < m_maxStages; i++ ) { - if ( ! m_stage[i].GetDirty() ) { - continue; - } - m_stage[i].SetDirty(false); - if ( m_stage[i].GetTexture2D() ) { - DWORD color1 = D3DTA_TEXTURE; - int textEnvMode = m_stage[i].GetTextEnvMode(); - DWORD colorOp = GLToDXTextEnvMode(textEnvMode); - if ( i > 0 && textEnvMode == GL_BLEND ) { - // Assume we're doing multi-texture light mapping. - // I don't think this is the right way to do this - // but it works for D3DQuake. - colorOp = D3DTOP_MODULATE; - color1 |= D3DTA_COMPLEMENT; - } - pD3DDev->SetTextureStageState( i, D3DTSS_COLORARG1, color1); - pD3DDev->SetTextureStageState( i, D3DTSS_COLORARG2, i == 0 ? D3DTA_DIFFUSE : D3DTA_CURRENT); - pD3DDev->SetTextureStageState( i, D3DTSS_COLOROP, colorOp); - DWORD alpha1 = D3DTA_TEXTURE; - DWORD alpha2 = D3DTA_DIFFUSE; - DWORD alphaOp; - alphaOp = GLToDXTextEnvMode(textEnvMode); - if (i == 0 && m_mainBlend ) { - alphaOp = D3DTOP_MODULATE; // Otherwise the console is never transparent - } - pD3DDev->SetTextureStageState( i, D3DTSS_ALPHAARG1, alpha1); - pD3DDev->SetTextureStageState( i, D3DTSS_ALPHAARG2, alpha2); - pD3DDev->SetTextureStageState( i, D3DTSS_ALPHAOP, alphaOp); - - TextureEntry* entry = textures->GetEntry(m_stage[i].GetCurrentTexture()); - if ( entry ) { - int minFilter = entry->m_glTexParameter2DMinFilter; - DWORD dxMinFilter = GLToDXMinFilter(minFilter); - DWORD dxMipFilter = GLToDXMipFilter(minFilter); - DWORD dxMagFilter = GLToDXMagFilter(entry->m_glTexParameter2DMagFilter); - - // Avoid setting anisotropic if the user doesn't request it. - static bool bSetMaxAnisotropy = false; - if ( entry->m_maxAnisotropy != 1.0f ) { - bSetMaxAnisotropy = true; - if ( dxMagFilter == D3DTFG_LINEAR) { - dxMagFilter = D3DTFG_ANISOTROPIC; - } - if ( dxMinFilter == D3DTFN_LINEAR) { - dxMinFilter = D3DTFN_ANISOTROPIC; - } - } - if ( bSetMaxAnisotropy ) { - pD3DDev->SetTextureStageState( i, D3DTSS_MAXANISOTROPY, entry->m_maxAnisotropy); - } - pD3DDev->SetTextureStageState( i, D3DTSS_MINFILTER, dxMinFilter ); - pD3DDev->SetTextureStageState( i, D3DTSS_MIPFILTER, dxMipFilter ); - pD3DDev->SetTextureStageState( i, D3DTSS_MAGFILTER, dxMagFilter); - LPDIRECTDRAWSURFACE7 pTexture = entry->m_texture; - if ( pTexture ) { - pD3DDev->SetTexture( i, pTexture); - } - } - } - else { - pD3DDev->SetTexture( i, NULL); - pD3DDev->SetTextureStageState( i, D3DTSS_COLORARG1, D3DTA_TEXTURE); - pD3DDev->SetTextureStageState( i, D3DTSS_COLORARG2, i == 0 ? D3DTA_DIFFUSE : D3DTA_CURRENT); - pD3DDev->SetTextureStageState( i, D3DTSS_COLOROP, D3DTOP_DISABLE); - } - } - } - -private: - TextureStageState* Get() { - return m_stage + m_currentStage; - } - - bool m_dirty; - bool m_mainBlend; - int m_maxStages; - int m_currentStage; - TextureStageState m_stage[MAXSTATES]; -}; - -// This class buffers up all the glVertex calls between -// glBegin and glEnd. -// -// Choose one of these three -// USE_DRAWINDEXEDPRIMITIVE seems slightly faster (54 fps vs 53 fps) than USE_DRAWPRIMITIVE. -// USE_DRAWINDEXEDPRIMITIVEVB is much slower (30fps vs 54fps), at least on GeForce Win9x 3.75. - -// #define USE_DRAWPRIMITIVE -#define USE_DRAWINDEXEDPRIMITIVE -//#define USE_DRAWINDEXEDPRIMITIVEVB - -#if defined(USE_DRAWINDEXEDPRIMITIVE) || defined(USE_DRAWINDEXEDPRIMITIVEVB) -#define USE_INDECIES -#endif - -#ifdef USE_DRAWINDEXEDPRIMITIVEVB -// The DX 7 docs suggest that you can get away with just one -// vertex buffer. But drivers (NVIDIA 3.75 on Win2K) don't seem to like that. - -#endif - -#ifdef USE_INDECIES -#define VERTSUSED 1024 -#define VERTSSLOP 100 -#endif - -#ifdef USE_INDECIES - -class OGLPrimitiveVertexBuffer { -public: - OGLPrimitiveVertexBuffer(){ - m_drawMode = (GLuint) -1; - m_size = 0; - m_count = 0; - m_OGLPrimitiveVertexBuffer = 0; - m_vertexCount = 0; - m_vertexTypeDesc = 0; - memset(m_textureCoords, 0, sizeof(m_textureCoords)); - - m_pD3DDev = 0; -#ifdef USE_DRAWINDEXEDPRIMITIVEVB - m_buffer = 0; -#else - m_buffer = 0; -#endif - m_color = (DWORD) D3DRGBA(0.0,0.0,0.0,1.0); // Don't know if this is correct - m_indecies = 0; - m_indexCount = 0; - } - - ~OGLPrimitiveVertexBuffer(){ - delete [] m_indecies; -#ifdef USE_DRAWINDEXEDPRIMITIVEVB - RELEASENULL(m_buffer); -#else - delete[] m_buffer; -#endif - } - - HRESULT Initialize(LPDIRECT3DDEVICE7 pD3DDev, IDirect3D7* pD3D7, bool hardwareTandL, DWORD typeDesc){ - m_pD3DDev = pD3DDev; - - int numVerts = VERTSUSED + VERTSSLOP; - - m_vertexTypeDesc = typeDesc; - m_vertexSize = 0; - if ( m_vertexTypeDesc & D3DFVF_XYZ ) { - m_vertexSize += 3 * sizeof(float); - } - if ( m_vertexTypeDesc & D3DFVF_DIFFUSE ) { - m_vertexSize += 4; - } - int textureStages = (m_vertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; - m_vertexSize += 2 * sizeof(float) * textureStages; - - m_indexSize = numVerts * 3; - delete [] m_indecies; - m_indecies = new WORD[m_indexSize]; - -#ifdef USE_DRAWINDEXEDPRIMITIVEVB - D3DVERTEXBUFFERDESC vbdesc = {sizeof(D3DVERTEXBUFFERDESC)}; - vbdesc.dwCaps = D3DVBCAPS_WRITEONLY; - if ( ! hardwareTandL ) { - vbdesc.dwCaps |= D3DVBCAPS_SYSTEMMEMORY; - } - vbdesc.dwFVF = typeDesc; - vbdesc.dwNumVertices = numVerts; - RELEASENULL(m_buffer); - HRESULT hr = pD3D7->CreateVertexBuffer(&vbdesc, &m_buffer, 0); - if ( FAILED(hr) ) { - return hr; - } -#else - m_size = (VERTSUSED + VERTSSLOP) * m_vertexSize; - delete[] m_buffer; - m_buffer = new char[m_size]; -#endif - - return S_OK; - } - - DWORD GetVertexTypeDesc(){ - return m_vertexTypeDesc; - } - - LPVOID GetOGLPrimitiveVertexBuffer(){ - return m_OGLPrimitiveVertexBuffer; - } - - DWORD GetVertexCount(){ - return m_vertexCount; - } - - inline void SetColor(D3DCOLOR color){ - m_color = color; - } - - inline void SetTextureCoord0(float u, float v){ - DWORD* pCoords = (DWORD*) m_textureCoords; - pCoords[0] = *(DWORD*)& u; - pCoords[1] = *(DWORD*)& v; - } - - inline void SetTextureCoord(int textStage, float u, float v){ - DWORD* pCoords = (DWORD*) m_textureCoords + (textStage << 1); - pCoords[0] = *(DWORD*)& u; - pCoords[1] = *(DWORD*)& v; - } - - void CheckFlush() { - if ( m_size && m_indexCount && - ((m_count + m_vertexSize * VERTSSLOP > m_size ) - || (m_indexCount + VERTSSLOP*6 > m_indexSize) ) ) { - Flush(); - } - } - - void Flush() { - if ( m_indexCount > 0 ) { -#ifdef USE_DRAWINDEXEDPRIMITIVEVB - m_OGLPrimitiveVertexBuffer = 0; - m_buffer->Unlock(); - HRESULT hr = m_pD3DDev->DrawIndexedPrimitiveVB( - D3DPT_TRIANGLELIST, m_buffer, - 0, m_vertexCount, m_indecies, m_indexCount, 0); - if ( FAILED(hr) ) { - // LocalDebugBreak(); // ? NVidia driver sometimes says it's out of memory - } -#else - m_OGLPrimitiveVertexBuffer = 0; - HRESULT hr = m_pD3DDev->DrawIndexedPrimitive( - D3DPT_TRIANGLELIST, m_vertexTypeDesc, m_buffer, - m_vertexCount, m_indecies, m_indexCount, 0); - if ( FAILED(hr) ) { - LocalDebugBreak(); // ? NVidia driver sometimes says it's out of memory - } -#endif - } - else { - LocalDebugBreak(); - } - m_indexCount = 0; - m_vertexState = 0; - } - - void SetVertex(float x, float y, float z){ - bool bCheckFlush = false; - if (m_count + m_vertexSize > m_size) { - Ensure(m_vertexSize); - } - if ( ! m_OGLPrimitiveVertexBuffer ) { - LockBuffer(); - } - DWORD* pFloat = (DWORD*) (m_OGLPrimitiveVertexBuffer + m_count); - pFloat[0] = *(DWORD*)& x; - pFloat[1] = *(DWORD*)& y; - pFloat[2] = *(DWORD*)& z; - const DWORD* pCoords = (DWORD*) m_textureCoords; - switch(m_vertexTypeDesc){ - case (D3DFVF_XYZ | D3DFVF_DIFFUSE | (1 << D3DFVF_TEXCOUNT_SHIFT)): - pFloat[3] = m_color; - pFloat[4] = pCoords[0]; - pFloat[5] = pCoords[1]; - break; - case (D3DFVF_XYZ | D3DFVF_DIFFUSE | (2 << D3DFVF_TEXCOUNT_SHIFT)): - pFloat[3] = m_color; - pFloat[4] = pCoords[0]; - pFloat[5] = pCoords[1]; - pFloat[6] = pCoords[2]; - pFloat[7] = pCoords[3]; - break; - default: - { - if ( m_vertexTypeDesc & D3DFVF_DIFFUSE ) { - *pFloat++ = m_color; - } - int textureStages = (m_vertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; - for ( int i = 0; i < textureStages; i++ ) { - *pFloat++ = *pCoords++; - *pFloat++ = *pCoords++; - } - } - break; - } - - if( m_indexCount < m_indexSize - 5){ - // Convert quads to double triangles - switch ( m_drawMode ) { - default: - LocalDebugBreak(); - break; - case GL_LINES: - { - m_indecies[m_indexCount++] = m_vertexCount; - if ( m_vertexState++==1) - { - SetVertex(x+1, y+1, z+1); -// m_indecies[m_indexCount++] = m_vertexCount; - m_vertexState = 0; - bCheckFlush = true; // Flush for long sequences of quads. - } - } - break; - case GL_TRIANGLES: - m_indecies[m_indexCount++] = m_vertexCount; - if ( m_vertexState++ == 2 ) { - m_vertexState = 0; - bCheckFlush = true; // Flush for long sequences of triangles. - } - break; - case GL_QUADS: - { - if ( m_vertexState++ < 3) { - m_indecies[m_indexCount++] = m_vertexCount; - } - else { - // We've already done triangle (0 , 1, 2), now draw (2, 3, 0) - m_indecies[m_indexCount++] = m_vertexCount-1; - m_indecies[m_indexCount++] = m_vertexCount; - m_indecies[m_indexCount++] = m_vertexCount-3; - m_vertexState = 0; - bCheckFlush = true; // Flush for long sequences of quads. - } - } - break; - case GL_TRIANGLE_STRIP: - { - if ( m_vertexState > VERTSSLOP ) { - // This is a strip that's too big for us to buffer. - // (We can't just flush the buffer because we have to keep - // track of the last two vertices. - LocalDebugBreak(); - } - if ( m_vertexState++ < 3) { - m_indecies[m_indexCount++] = m_vertexCount; - } - else { - // Flip triangles between clockwise and counter clockwise - if (m_vertexState & 1) { - // draw triangle [n-2 n-1 n] - m_indecies[m_indexCount++] = m_vertexCount-2; - m_indecies[m_indexCount++] = m_vertexCount-1; - m_indecies[m_indexCount++] = m_vertexCount; - } - else { - // draw triangle [n-1 n-2 n] - m_indecies[m_indexCount++] = m_vertexCount-1; - m_indecies[m_indexCount++] = m_vertexCount-2; - m_indecies[m_indexCount++] = m_vertexCount; - } - } - } - break; - case GL_TRIANGLE_FAN: - case GL_POLYGON: - { - if ( m_vertexState > VERTSSLOP ) { - // This is a polygon or fan that's too big for us to buffer. - // (We can't just flush the buffer because we have to keep - // track of the starting vertex. - LocalDebugBreak(); - } - if ( m_vertexState++ < 3) { - m_indecies[m_indexCount++] = m_vertexCount; - } - else { - // Draw triangle [0 n-1 n] - m_indecies[m_indexCount++] = m_vertexCount-(m_vertexState-1); - m_indecies[m_indexCount++] = m_vertexCount-1; - m_indecies[m_indexCount++] = m_vertexCount; - } - } - break; - } - } - else { - LocalDebugBreak(); - } - - m_count += m_vertexSize; - m_vertexCount++; - if ( bCheckFlush ) { - CheckFlush(); - } - } - - inline bool IsMergableMode(GLenum /* mode */){ - CheckFlush(); - return true; - } - - void Begin(GLuint drawMode){ - m_drawMode = drawMode; - CheckFlush(); - if ( ! m_OGLPrimitiveVertexBuffer ) { - LockBuffer(); - } - m_vertexState = 0; - } - - void Append(GLuint drawMode){ - m_drawMode = drawMode; - CheckFlush(); - m_vertexState = 0; - } - - void LockBuffer(){ - if ( ! m_OGLPrimitiveVertexBuffer ) { -#ifdef USE_DRAWINDEXEDPRIMITIVEVB - void* memory = 0; - // If there's room in the buffer, we try to append to what's already there. - DWORD dwFlags = DDLOCK_WAIT | DDLOCK_WRITEONLY; - if ( m_vertexCount > 0 && m_vertexCount < VERTSUSED ){ - dwFlags |= DDLOCK_NOOVERWRITE; - } - else { - m_vertexCount = 0; - m_count = 0; - dwFlags |= DDLOCK_DISCARDCONTENTS; - } - HRESULT hr = m_buffer->Lock(dwFlags, & memory, &m_size); - if ( FAILED(hr) || ! memory) { -// LocalDebugBreak(); - - while (!memory) - hr = m_buffer->Lock(dwFlags, & memory, &m_size); - } - m_OGLPrimitiveVertexBuffer = (char*) memory; -#else - m_OGLPrimitiveVertexBuffer = (char*) m_buffer; - m_vertexCount = 0; - m_count = 0; -#endif - m_indexCount = 0; - } - } - - void End(){ - if ( m_indexCount == 0 ) { // Startup - return; - } - Flush(); - } -private: - void Ensure(int size){ - if (( m_count + size ) > m_size ) { - LocalDebugBreak(); - } - } - - GLuint m_drawMode; - DWORD m_vertexTypeDesc; - int m_vertexSize; // in bytes - - LPDIRECT3DDEVICE7 m_pD3DDev; -#ifdef USE_DRAWINDEXEDPRIMITIVEVB - IDirect3DVertexBuffer7* m_buffer; -#else - char* m_buffer; -#endif - char* m_OGLPrimitiveVertexBuffer; - DWORD m_size; // total vertex buffer size in bytes - DWORD m_count; // used ammount of vertex buffer, in bytes - DWORD m_vertexCount; - DWORD m_indexCount; - int m_vertexState; // Cycles from 0..n-1 where n is the number of verticies in a primitive. - DWORD m_indexSize; - WORD* m_indecies; - D3DCOLOR m_color; - float m_textureCoords[MAXSTATES*2]; -}; -#endif - -#ifdef USE_DRAWPRIMITIVE -class OGLPrimitiveVertexBuffer { -public: - OGLPrimitiveVertexBuffer(){ - m_drawMode = -1; - m_size = 0; - m_count = 0; - m_OGLPrimitiveVertexBuffer = 0; - m_vertexCount = 0; - m_vertexTypeDesc = 0; - memset(m_textureCoords, 0, sizeof(m_textureCoords)); - - m_pD3DDev = 0; - m_color = D3DRGBA(0.0,0.0,0.0,1.0); // Don't know if this is correct - } - - ~OGLPrimitiveVertexBuffer(){ - delete [] m_OGLPrimitiveVertexBuffer; - } - - HRESULT Initialize(LPDIRECT3DDEVICE7 pD3DDev, IDirect3D7* pD3D7, bool hardwareTandL, DWORD typeDesc){ - m_pD3DDev = pD3DDev; - if (m_vertexTypeDesc != typeDesc) { - m_vertexTypeDesc = typeDesc; - m_vertexSize = 0; - if ( m_vertexTypeDesc & D3DFVF_XYZ ) { - m_vertexSize += 3 * sizeof(float); - } - if ( m_vertexTypeDesc & D3DFVF_DIFFUSE ) { - m_vertexSize += 4; - } - int textureStages = (m_vertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; - m_vertexSize += 2 * sizeof(float) * textureStages; - } - return S_OK; - } - - DWORD GetVertexTypeDesc(){ - return m_vertexTypeDesc; - } - - LPVOID GetOGLPrimitiveVertexBuffer(){ - return m_OGLPrimitiveVertexBuffer; - } - - DWORD GetVertexCount(){ - return m_vertexCount; - } - - inline void SetColor(D3DCOLOR color){ - m_color = color; - } - - inline void SetTextureCoord0(float u, float v){ - DWORD* pCoords = (DWORD*) m_textureCoords; - pCoords[0] = *(DWORD*)& u; - pCoords[1] = *(DWORD*)& v; - } - - inline void SetTextureCoord(int textStage, float u, float v){ - DWORD* pCoords = (DWORD*) m_textureCoords + (textStage << 1); - pCoords[0] = *(DWORD*)& u; - pCoords[1] = *(DWORD*)& v; - } - - void SetVertex(float x, float y, float z){ - int newCount = m_count + m_vertexSize; - if (newCount > m_size) { - Ensure(m_vertexSize); - } - DWORD* pFloat = (DWORD*) (m_OGLPrimitiveVertexBuffer + m_count); - pFloat[0] = *(DWORD*)& x; - pFloat[1] = *(DWORD*)& y; - pFloat[2] = *(DWORD*)& z; - const DWORD* pCoords = (DWORD*) m_textureCoords; - switch(m_vertexTypeDesc){ - case (D3DFVF_XYZ | D3DFVF_DIFFUSE | (1 << D3DFVF_TEXCOUNT_SHIFT)): - pFloat[3] = m_color; - pFloat[4] = pCoords[0]; - pFloat[5] = pCoords[1]; - break; - case (D3DFVF_XYZ | D3DFVF_DIFFUSE | (2 << D3DFVF_TEXCOUNT_SHIFT)): - pFloat[3] = m_color; - pFloat[4] = pCoords[0]; - pFloat[5] = pCoords[1]; - pFloat[6] = pCoords[2]; - pFloat[7] = pCoords[3]; - break; - default: - { - if ( m_vertexTypeDesc & D3DFVF_DIFFUSE ) { - *pFloat++ = m_color; - } - int textureStages = (m_vertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; - for ( int i = 0; i < textureStages; i++ ) { - *pFloat++ = *pCoords++; - *pFloat++ = *pCoords++; - } - } - break; - } - m_count = newCount; - m_vertexCount++; - - // TO DO: Flush vertex buffer if larger than 1000 vertexes. - // Have to do this modulo vertexes-per-primitive - } - - inline IsMergableMode(GLenum mode){ - return ( mode == m_drawMode ) && ( mode == GL_QUADS || mode == GL_TRIANGLES ); - } - - void Begin(GLuint drawMode){ - m_drawMode = drawMode; - } - - void Append(GLuint drawMode){ - } - - void End(){ - if ( m_vertexCount == 0 ) { // Startup - return; - } - D3DPRIMITIVETYPE dptPrimitiveType; - switch ( m_drawMode ) { - case GL_POINTS: dptPrimitiveType = D3DPT_POINTLIST; break; - case GL_LINES: dptPrimitiveType = D3DPT_LINELIST; break; - case GL_LINE_STRIP: dptPrimitiveType = D3DPT_LINESTRIP; break; - case GL_LINE_LOOP: - dptPrimitiveType = D3DPT_LINESTRIP; - LocalDebugBreak(); // Need to add one more point - break; - case GL_TRIANGLES: dptPrimitiveType = D3DPT_TRIANGLELIST; break; - case GL_TRIANGLE_STRIP: dptPrimitiveType = D3DPT_TRIANGLESTRIP; break; - case GL_TRIANGLE_FAN: dptPrimitiveType = D3DPT_TRIANGLEFAN; break; - case GL_QUADS: - if ( m_vertexCount <= 4 ) { - dptPrimitiveType = D3DPT_TRIANGLEFAN; - } - else { - dptPrimitiveType = D3DPT_TRIANGLELIST; - ConvertQuadsToTriangles(); - } - break; - case GL_QUAD_STRIP: - if ( m_vertexCount <= 4 ) { - dptPrimitiveType = D3DPT_TRIANGLEFAN; - } - else { - dptPrimitiveType = D3DPT_TRIANGLESTRIP; - ConvertQuadStripToTriangleStrip(); - } - break; - - case GL_POLYGON: - dptPrimitiveType = D3DPT_TRIANGLEFAN; - if ( m_vertexCount < 3) { - goto exit; - } - // How is this different from GL_TRIANGLE_FAN, other than - // that polygons are planar? - break; - default: - LocalDebugBreak(); - goto exit; - } - { - HRESULT hr = m_pD3DDev->DrawPrimitive( - dptPrimitiveType, m_vertexTypeDesc, - m_OGLPrimitiveVertexBuffer, - m_vertexCount, 0); - if ( FAILED(hr) ) { - // LocalDebugBreak(); - } - } -exit: - m_vertexCount = 0; - m_count = 0; - } - -private: - void ConvertQuadsToTriangles(){ - int quadCount = m_vertexCount / 4; - int addedVerticies = 2 * quadCount; - int addedDataSize = addedVerticies * m_vertexSize; - Ensure( addedDataSize ); - - // A quad is v0, v1, v2, v3 - // The corresponding triangle pair is v0 v1 v2 , v0 v2 v3 - for(int i = quadCount-1; i >= 0; i--) { - int startOfQuad = i * m_vertexSize * 4; - int startOfTrianglePair = i * m_vertexSize * 6; - // Copy the last two verticies of the second triangle - memcpy(m_OGLPrimitiveVertexBuffer + startOfTrianglePair + 4 * m_vertexSize, - m_OGLPrimitiveVertexBuffer + startOfQuad + m_vertexSize * 2, m_vertexSize * 2); - // Copy the first vertex of the second triangle - memcpy(m_OGLPrimitiveVertexBuffer + startOfTrianglePair + 3 * m_vertexSize, - m_OGLPrimitiveVertexBuffer + startOfQuad, m_vertexSize); - // Copy the first triangle - if ( i > 0 ) { - memcpy(m_OGLPrimitiveVertexBuffer + startOfTrianglePair, m_OGLPrimitiveVertexBuffer + startOfQuad, 3 * m_vertexSize); - } - } - m_count += addedDataSize; - m_vertexCount += addedVerticies; - } - - void ConvertQuadStripToTriangleStrip(){ - int vertexPairCount = m_vertexCount / 2; - - // Doesn't add any points, but does reorder the verticies. - // Swap each pair of verticies. - - for(int i = 0; i < vertexPairCount; i++) { - int startOfPair = i * m_vertexSize * 2; - int middleOfPair = startOfPair + m_vertexSize; - for(int j = 0; j < m_vertexSize; j++) { - int c = m_OGLPrimitiveVertexBuffer[startOfPair + j]; - m_OGLPrimitiveVertexBuffer[startOfPair + j] = m_OGLPrimitiveVertexBuffer[middleOfPair + j]; - m_OGLPrimitiveVertexBuffer[middleOfPair + j] = c; - } - } - } - - void Ensure(int size){ - if (( m_count + size ) > m_size ) { - int newSize = m_size * 2; - if ( newSize < m_count + size ) newSize = m_count + size; - char* newVB = new char[newSize]; - if ( m_OGLPrimitiveVertexBuffer ) { - memcpy(newVB, m_OGLPrimitiveVertexBuffer, m_count); - } - delete[] m_OGLPrimitiveVertexBuffer; - m_OGLPrimitiveVertexBuffer = newVB; - m_size = newSize; - } - } - - GLuint m_drawMode; - DWORD m_vertexTypeDesc; - int m_vertexSize; // in bytes - - LPDIRECT3DDEVICE7 m_pD3DDev; - char* m_OGLPrimitiveVertexBuffer; - int m_size; - int m_count; - DWORD m_vertexCount; - D3DCOLOR m_color; - float m_textureCoords[MAXSTATES*2]; -}; - -#endif // USE_DRAWPRIMITIVE - -class FakeGL { -private: - LPDIRECT3DDEVICE7 m_pD3DDev; - LPDIRECTDRAW7 m_pDD; - LPDIRECT3D7 m_pD3D; - LPDIRECTDRAWSURFACE7 m_pPrimary; -#ifdef USE_D3DXCONTEXT - ID3DXContext* m_pD3DX; -#endif - bool m_hardwareTandL; - - BOOL m_bD3DXReady; - HWND m_hwndMain; - - bool m_glRenderStateDirty; - - bool m_glAlphaStateDirty; - GLenum m_glAlphaFunc; - GLclampf m_glAlphaFuncRef; - bool m_glAlphaTest; - - bool m_glBlendStateDirty; - bool m_glBlend; - GLenum m_glBlendFuncSFactor; - GLenum m_glBlendFuncDFactor; - - bool m_glCullStateDirty; - bool m_glCullFace; - GLenum m_glCullFaceMode; - - bool m_glDepthStateDirty; - bool m_glDepthTest; - GLenum m_glDepthFunc; - bool m_glDepthMask; - - GLclampd m_glDepthRangeNear; - GLclampd m_glDepthRangeFar; - - GLenum m_glMatrixMode; - - GLenum m_glPolygonModeFront; - GLenum m_glPolygonModeBack; - - bool m_glShadeModelStateDirty; - GLenum m_glShadeModel; - - bool m_bViewPortDirty; - GLint m_glViewPortX; - GLint m_glViewPortY; - GLsizei m_glViewPortWidth; - GLsizei m_glViewPortHeight; - - TextureState m_textureState; - TextureTable m_textures; - - bool m_modelViewMatrixStateDirty; - bool m_projectionMatrixStateDirty; - bool m_textureMatrixStateDirty; - bool* m_currentMatrixStateDirty; // an alias to one of the preceeding stacks - - ID3DXMatrixStack* m_modelViewMatrixStack; - ID3DXMatrixStack* m_projectionMatrixStack; - ID3DXMatrixStack* m_textureMatrixStack; - ID3DXMatrixStack* m_currentMatrixStack; // an alias to one of the preceeding stacks - - bool m_viewMatrixStateDirty; - D3DXMATRIX m_d3dViewMatrix; - - OGLPrimitiveVertexBuffer m_OGLPrimitiveVertexBuffer; - - bool m_needBeginScene; - - const char* m_vendor; - const char* m_renderer; - char m_version[64]; - const char* m_extensions; - DDDEVICEIDENTIFIER2 m_dddi; - DWORD m_windowHeight; - - char* m_stickyAlloc; - DWORD m_stickyAllocSize; - - bool m_hintGenerateMipMaps; - -#ifdef USE_D3DFRAME - D3DCOLOR m_clearColor; -#endif - - HRESULT ReleaseD3DX() - { -#ifdef USE_D3DFRAME - Cleanup3DEnvironment(); -#endif -#ifdef USE_D3DXCONTEXT - RELEASENULL(m_pDD); - RELEASENULL(m_pD3D); - RELEASENULL(m_pD3DDev); - RELEASENULL(m_pPrimary); - RELEASENULL(m_pD3DX); -#endif - m_bD3DXReady = FALSE; - qD3DXUninitialize(); - return S_OK; - } - -#ifdef USE_D3DFRAME - static HRESULT AppConfirmFn(DDCAPS* caps, D3DDEVICEDESC7* desc){ - return S_OK; - } -#endif - - HRESULT InitD3DX() - { - HRESULT hr; - if( FAILED(hr = qD3DXInitialize()) ) - return hr; - -#ifdef USE_D3DFRAME - // Choose device - - hr = D3DEnum_EnumerateDevices(&AppConfirmFn); - if( FAILED(hr) ) - return hr; - - hr = D3DEnum_SelectDefaultDevice(&m_pDeviceInfo, 0); - if( FAILED(hr) ) - return hr; - - m_pDeviceInfo->bWindowed = gFullScreen ? 0 : 1; - - m_pFramework = new CD3DFramework7(); - - if( FAILED( hr = Initialize3DEnvironment() ) ) - return hr; -#endif - -#ifdef USE_D3DXCONTEXT - - DWORD width = gWidth; - DWORD height = gHeight; - DWORD bpp = gBpp; - DWORD zbpp = gZbpp; - - // Try as specified. - hr = qD3DXCreateContextEx(D3DX_DEFAULT, gFullScreen ? D3DX_CONTEXT_FULLSCREEN : 0, - m_hwndMain, NULL, bpp, 0, - zbpp, 0, 1, width, height, D3DX_DEFAULT, &m_pD3DX); - if( FAILED(hr) ) { - // default z-buffer - hr = qD3DXCreateContextEx(D3DX_DEFAULT, gFullScreen ? D3DX_CONTEXT_FULLSCREEN : 0, - m_hwndMain, NULL, bpp, 0, - D3DX_DEFAULT, 0, 1, width, height, D3DX_DEFAULT, &m_pD3DX); - if( FAILED(hr) ) { - // default depth and z-buffer - hr = qD3DXCreateContextEx(D3DX_DEFAULT, gFullScreen ? D3DX_CONTEXT_FULLSCREEN : 0, - m_hwndMain, NULL, D3DX_DEFAULT, 0, - D3DX_DEFAULT, 0, 1, width, height, D3DX_DEFAULT, &m_pD3DX); - if( FAILED(hr) ) { - // default everything - hr = qD3DXCreateContextEx(D3DX_DEFAULT, gFullScreen ? D3DX_CONTEXT_FULLSCREEN : 0, - m_hwndMain, NULL, D3DX_DEFAULT, 0, - D3DX_DEFAULT, 0, 1, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, &m_pD3DX); - if( FAILED(hr) ) { - return hr; - } - } - } - } - m_pDD = m_pD3DX->GetDD(); - m_pD3D = m_pD3DX->GetD3D(); - m_pD3DDev = m_pD3DX->GetD3DDevice(); - m_pPrimary = m_pD3DX->GetPrimary(); -#endif - m_bD3DXReady = TRUE; - - return hr; - } - - void InterpretError(HRESULT hr) - { - char errStr[100]; - qD3DXGetErrorString(hr, 100, errStr ); - Con_Printf("%s\n", errStr); -// MessageBox(NULL,errStr,"D3DX Error",MB_OK); -// LocalDebugBreak(); - } - -#ifdef USE_D3DFRAME - D3DEnum_DeviceInfo* m_pDeviceInfo; - LPDIRECTDRAWSURFACE7 m_pddsRenderTargetLeft; - DDSURFACEDESC2 m_ddsdRenderTarget; - - CD3DFramework7* m_pFramework; - - //----------------------------------------------------------------------------- - // Name: Initialize3DEnvironment() - // Desc: Initializes the sample framework, then calls the app-specific function - // to initialize device specific objects. This code is structured to - // handled any errors that may occur duing initialization - //----------------------------------------------------------------------------- - HRESULT Initialize3DEnvironment() - { - HRESULT hr; - DWORD dwFrameworkFlags = 0L; - dwFrameworkFlags |= ( !m_pDeviceInfo->bWindowed ? D3DFW_FULLSCREEN : 0L ); - dwFrameworkFlags |= ( m_pDeviceInfo->bStereo ? D3DFW_STEREO : 0L ); - dwFrameworkFlags |= ( D3DFW_ZBUFFER ); - - // Initialize the D3D framework - if( SUCCEEDED( hr = m_pFramework->Initialize( m_hwndMain, - m_pDeviceInfo->pDriverGUID, m_pDeviceInfo->pDeviceGUID, - &m_pDeviceInfo->ddsdFullscreenMode, dwFrameworkFlags ) ) ) - { - m_pDD = m_pFramework->GetDirectDraw(); - m_pD3D = m_pFramework->GetDirect3D(); - m_pD3DDev = m_pFramework->GetD3DDevice(); - - m_pPrimary = m_pFramework->GetRenderSurface(); - m_pddsRenderTargetLeft = m_pFramework->GetRenderSurfaceLeft(); - - m_ddsdRenderTarget.dwSize = sizeof(m_ddsdRenderTarget); - m_pPrimary->GetSurfaceDesc( &m_ddsdRenderTarget ); - - // Let the app run its startup code which creates the 3d scene. - if( SUCCEEDED( hr = InitDeviceObjects() ) ) - return S_OK; - else - { - DeleteDeviceObjects(); - m_pFramework->DestroyObjects(); - } - } - - // If we get here, the first initialization passed failed. If that was with a - // hardware device, try again using a software rasterizer instead. - if( m_pDeviceInfo->bHardware ) - { - // Try again with a software rasterizer - // DisplayFrameworkError( hr, MSGWARN_SWITCHEDTOSOFTWARE ); - D3DEnum_SelectDefaultDevice( &m_pDeviceInfo, D3DENUM_SOFTWAREONLY ); - return Initialize3DEnvironment(); - } - - return hr; - } - - //----------------------------------------------------------------------------- - // Name: Change3DEnvironment() - // Desc: Handles driver, device, and/or mode changes for the app. - //----------------------------------------------------------------------------- - HRESULT Change3DEnvironment() - { - HRESULT hr; - static BOOL bOldWindowedState = TRUE; - static DWORD dwSavedStyle; - static RECT rcSaved; - - // Release all scene objects that will be re-created for the new device - DeleteDeviceObjects(); - - // Release framework objects, so a new device can be created - if( FAILED( hr = m_pFramework->DestroyObjects() ) ) - { - // DisplayFrameworkError( hr, MSGERR_APPMUSTEXIT ); - SendMessage( m_hwndMain, WM_CLOSE, 0, 0 ); - return hr; - } - - // Check if going from fullscreen to windowed mode, or vice versa. - if( bOldWindowedState != m_pDeviceInfo->bWindowed ) - { - if( m_pDeviceInfo->bWindowed ) - { - // Coming from fullscreen mode, so restore window properties - SetWindowLong( m_hwndMain, GWL_STYLE, dwSavedStyle ); - SetWindowPos( m_hwndMain, HWND_NOTOPMOST, rcSaved.left, rcSaved.top, - ( rcSaved.right - rcSaved.left ), - ( rcSaved.bottom - rcSaved.top ), SWP_SHOWWINDOW ); - } - else - { - // Going to fullscreen mode, save/set window properties as needed - dwSavedStyle = GetWindowLong( m_hwndMain, GWL_STYLE ); - GetWindowRect( m_hwndMain, &rcSaved ); - SetWindowLong( m_hwndMain, GWL_STYLE, WS_POPUP|WS_SYSMENU|WS_VISIBLE ); - } - - bOldWindowedState = m_pDeviceInfo->bWindowed; - } - - // Inform the framework class of the driver change. It will internally - // re-create valid surfaces, a d3ddevice, etc. - if( FAILED( hr = Initialize3DEnvironment() ) ) - { - // DisplayFrameworkError( hr, MSGERR_APPMUSTEXIT ); - SendMessage( m_hwndMain, WM_CLOSE, 0, 0 ); - return hr; - } - - return S_OK; - } - - - //----------------------------------------------------------------------------- - // Name: Render3DEnvironment() - // Desc: Draws the scene. - //----------------------------------------------------------------------------- - HRESULT Render3DEnvironment() - { - HRESULT hr; - - // Check the cooperative level before rendering - if( FAILED( hr = m_pDD->TestCooperativeLevel() ) ) - { - switch( hr ) - { - case DDERR_EXCLUSIVEMODEALREADYSET: - case DDERR_NOEXCLUSIVEMODE: - // Do nothing because some other app has exclusive mode - return S_OK; - - case DDERR_WRONGMODE: - // The display mode changed on us. Resize accordingly - if( m_pDeviceInfo->bWindowed ) - return Change3DEnvironment(); - break; - } - return hr; - } - - // Show the frame on the primary surface. - if( FAILED( hr = m_pFramework->ShowFrame() ) ) - { - if( DDERR_SURFACELOST != hr ) - return hr; - - m_pFramework->RestoreSurfaces(); - RestoreSurfaces(); - } - - return S_OK; - } - - - - //----------------------------------------------------------------------------- - // Name: Cleanup3DEnvironment() - // Desc: Cleanup scene objects - //----------------------------------------------------------------------------- - void Cleanup3DEnvironment() - { - if( m_pFramework ) - { - DeleteDeviceObjects(); - delete m_pFramework; m_pFramework = 0; - - FinalCleanup(); - } - - D3DEnum_FreeResources(); - } - - // Overridable functions for the 3D scene created by the app - virtual HRESULT OneTimeSceneInit() { return S_OK; } - virtual HRESULT InitDeviceObjects() { return S_OK; } - virtual HRESULT DeleteDeviceObjects() { return S_OK; } - virtual HRESULT Render() { return S_OK; } - virtual HRESULT FrameMove( FLOAT ) { return S_OK; } - virtual HRESULT RestoreSurfaces() { return S_OK; } - virtual HRESULT FinalCleanup() { return S_OK; } - -#endif - -public: - FakeGL(HWND hwndMain){ - m_hwndMain = hwndMain; - - RECT rect; - GetClientRect(m_hwndMain, &rect); - m_windowHeight = rect.bottom - rect.top; - m_bD3DXReady = TRUE; - - m_pD3DDev = 0; - m_pDD = 0; - m_pD3D = 0; - m_pPrimary = 0; -#ifdef USE_D3DXCONTEXT - m_pD3DX = 0; -#endif -#ifdef USE_D3DFRAME - m_clearColor = 0; -#endif - m_hardwareTandL = false; - - m_glRenderStateDirty = true; - - m_glAlphaStateDirty = true; - m_glAlphaFunc = GL_ALWAYS; - m_glAlphaFuncRef = 0; - m_glAlphaTest = false; - - m_glBlendStateDirty = true; - m_glBlend = false; - m_glBlendFuncSFactor = GL_ONE; // Not sure this is the default - m_glBlendFuncDFactor = GL_ZERO; // Not sure this is the default - - m_glCullStateDirty = true; - m_glCullFace = false; - m_glCullFaceMode = GL_BACK; - - m_glDepthStateDirty = true; - m_glDepthTest = false; - m_glDepthMask = true; - m_glDepthFunc = GL_ALWAYS; // not sure if this is the default - - m_glDepthRangeNear = 0; // not sure if this is the default - m_glDepthRangeFar = 1.0; // not sure if this is the default - - m_glMatrixMode = GL_MODELVIEW; // Not sure this is the default - - m_glPolygonModeFront = GL_FILL; - m_glPolygonModeBack = GL_FILL; - - m_glShadeModelStateDirty = true; - m_glShadeModel = GL_SMOOTH; - - - m_bViewPortDirty = true; - m_glViewPortX = 0; - m_glViewPortY = 0; - m_glViewPortWidth = rect.right - rect.left; - m_glViewPortHeight = rect.bottom - rect.top; - - m_vendor = 0; - m_renderer = 0; - m_extensions = 0; - - m_hintGenerateMipMaps = true; - - HRESULT hr = InitD3DX(); - if ( FAILED(hr) ) { - InterpretError(hr); - } - - hr = qD3DXCreateMatrixStack(0, &m_modelViewMatrixStack); - hr = qD3DXCreateMatrixStack(0, &m_projectionMatrixStack); - hr = qD3DXCreateMatrixStack(0, &m_textureMatrixStack); - m_currentMatrixStack = m_modelViewMatrixStack; - m_modelViewMatrixStack->LoadIdentity(); // Not sure this is correct - m_projectionMatrixStack->LoadIdentity(); - m_textureMatrixStack->LoadIdentity(); - m_modelViewMatrixStateDirty = true; - m_projectionMatrixStateDirty = true; - m_textureMatrixStateDirty = true; - m_currentMatrixStateDirty = &m_modelViewMatrixStateDirty; - m_viewMatrixStateDirty = true; - - D3DXMatrixIdentity(&m_d3dViewMatrix); - - m_needBeginScene = true; - - m_stickyAlloc = 0; - m_stickyAllocSize = 0; - - { - // Check for multitexture. - D3DDEVICEDESC7 deviceCaps; - HRESULT hr = m_pD3DDev->GetCaps(&deviceCaps); - if ( ! FAILED(hr)) { - // Clamp texture blend stages to 2. Some cards can do eight, but that's more - // than we need. - int maxStages = deviceCaps.wMaxTextureBlendStages; - - if ( maxStages > 2 ){ - maxStages = 2; - } - m_textureState.SetMaxStages(maxStages); - - m_hardwareTandL = (deviceCaps.dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0; - - for(int i = 0; i < maxStages; i++ ) { - m_pD3DDev->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, i); - } - } - } - - // One-time render state initialization - - m_pD3DDev->SetRenderState( D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000 ); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_DITHERENABLE, TRUE ); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_SPECULARENABLE, FALSE ); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE ); - m_pD3DDev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE); - } - - ~FakeGL(){ - delete [] m_stickyAlloc; - ReleaseD3DX(); - RELEASENULL(m_modelViewMatrixStack); - RELEASENULL(m_projectionMatrixStack); - RELEASENULL(m_textureMatrixStack); - } - - void cglAlphaFunc (GLenum func, GLclampf ref){ - if ( m_glAlphaFunc != func || m_glAlphaFuncRef != ref ) { - SetRenderStateDirty(); - m_glAlphaFunc = func; - m_glAlphaFuncRef = ref; - m_glAlphaStateDirty = true; - } - } - - void cglBegin (GLenum mode){ - if ( m_needBeginScene ){ - HRESULT hr = m_pD3DDev->BeginScene(); - if ( FAILED(hr) ) { - InterpretError(hr); - return; - } - else - m_needBeginScene = false; - } - -#if 0 - // statistics - static int beginCount; - static int stateChangeCount; - static int primitivesCount; - beginCount++; - if ( m_glRenderStateDirty ) - stateChangeCount++; - if ( m_glRenderStateDirty || ! m_OGLPrimitiveVertexBuffer.IsMergableMode(mode) ) - primitivesCount++; -#endif - - if ( m_glRenderStateDirty || ! m_OGLPrimitiveVertexBuffer.IsMergableMode(mode) ) { - internalEnd(); - SetGLRenderState(); - DWORD typeDesc; - typeDesc = D3DFVF_XYZ | D3DFVF_DIFFUSE; - typeDesc |= (m_textureState.GetMaxStages() << D3DFVF_TEXCOUNT_SHIFT); - - if ( typeDesc != m_OGLPrimitiveVertexBuffer.GetVertexTypeDesc()) { - m_OGLPrimitiveVertexBuffer.Initialize(m_pD3DDev, m_pD3D, m_hardwareTandL, typeDesc); - } - m_OGLPrimitiveVertexBuffer.Begin(mode); - } - else { - m_OGLPrimitiveVertexBuffer.Append(mode); - } - } - - void cglBindTexture(GLenum target, GLuint texture){ - if ( target != GL_TEXTURE_2D ) { - LocalDebugBreak(); - return; - } - if ( m_textureState.GetCurrentTexture() != texture ) { - SetRenderStateDirty(); - m_textureState.SetCurrentTexture(texture); - m_textures.BindTexture(texture); - } - } - - inline void cglMTexCoord2fSGIS(GLenum target, GLfloat s, GLfloat t){ - int textStage = target - TEXTURE0_SGIS; - m_OGLPrimitiveVertexBuffer.SetTextureCoord(textStage, s, t); - } - - void cglSelectTextureSGIS(GLenum target){ - int textStage = target - TEXTURE0_SGIS; - m_textureState.SetCurrentStage(textStage); - m_textures.BindTexture(m_textureState.GetCurrentTexture()); - // Does not, by itself, dirty the render state - } - - void cglBlendFunc (GLenum sfactor, GLenum dfactor){ - if ( m_glBlendFuncSFactor != sfactor || m_glBlendFuncDFactor != dfactor ) { - SetRenderStateDirty(); - m_glBlendFuncSFactor = sfactor; - m_glBlendFuncDFactor = dfactor; - m_glBlendStateDirty = true; - } - } - - void cglClear (GLbitfield mask){ - HRESULT hr; - internalEnd(); - SetGLRenderState(); - DWORD clearMask = 0; - if ( mask & GL_COLOR_BUFFER_BIT ) { - clearMask |= D3DCLEAR_TARGET; - } - - if ( mask & GL_DEPTH_BUFFER_BIT ) { - clearMask |= D3DCLEAR_ZBUFFER; - } -#ifdef USE_D3DXCONTEXT - hr = m_pD3DX->Clear(clearMask); -#endif - -#ifdef USE_D3DFRAME - hr = m_pD3DDev->Clear( 0, 0, clearMask, m_clearColor, 1.0f, 0L ); -#endif - if ( FAILED(hr) ){ - InterpretError(hr); - } - } - - void cglClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){ - D3DCOLOR clearColor = D3DRGBA(Clamp(red), Clamp(green), Clamp(blue), Clamp(alpha)); -#ifdef USE_D3DXCONTEXT - HRESULT hr = m_pD3DX->SetClearColor(clearColor); - if( FAILED(hr) ) { - InterpretError(hr); - } -#endif -#ifdef USE_D3DFRAME - m_clearColor = clearColor; -#endif - } - - inline void cglColor3f (GLfloat red, GLfloat green, GLfloat blue){ - // Note: On x86 architectures this function will chew up a lot of time - // converting floating point to integer by calling _ftol - // unless the /QIfist flag is specified. - m_OGLPrimitiveVertexBuffer.SetColor(D3DRGB(Clamp(red), Clamp(green), Clamp(blue))); - } - - inline void cglColor3ubv (const GLubyte *v){ - m_OGLPrimitiveVertexBuffer.SetColor(RGBA_MAKE(v[0], v[1], v[2], 0xff)); - } - - inline void cglColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha){ - // Note: On x86 architectures this function will chew up a lot of time - // converting floating point to integer by calling _ftol - // unless the /QIfist flag is specified. - m_OGLPrimitiveVertexBuffer.SetColor(D3DRGBA(Clamp(red), Clamp(green), Clamp(blue), Clamp(alpha))); - } - - inline void cglColor4fv (const GLfloat *v){ - // Note: On x86 architectures this function will chew up a lot of time - // converting floating point to integer by calling _ftol - // unless the /QIfist flag is specified. - m_OGLPrimitiveVertexBuffer.SetColor(D3DRGBA(Clamp(v[0]), Clamp(v[1]), Clamp(v[2]), Clamp(v[3]))); - } - - void cglCullFace (GLenum mode){ - if ( m_glCullFaceMode != mode ) { - SetRenderStateDirty(); - m_glCullFaceMode = mode; - m_glCullStateDirty = true; - } - } - - void cglDepthFunc (GLenum func){ - if ( m_glDepthFunc != func ) { - SetRenderStateDirty(); - m_glDepthFunc = func; - m_glDepthStateDirty = true; - } - } - - void cglDepthMask (GLboolean flag){ - if ( m_glDepthMask != (flag != 0) ) { - SetRenderStateDirty(); - m_glDepthMask = flag != 0 ? true : false; - m_glDepthStateDirty = true; - } - } - - void cglDepthRange (GLclampd zNear, GLclampd zFar){ - if ( m_glDepthRangeNear != zNear || m_glDepthRangeFar != zFar ) { - SetRenderStateDirty(); - m_glDepthRangeNear = zNear; - m_glDepthRangeFar = zFar; - m_bViewPortDirty = true; - } - } - - void cglDisable (GLenum cap){ - EnableDisableSet(cap, false); - } - - void cglDrawBuffer (GLenum /* mode */){ - // Do nothing. (Can DirectX render to the front buffer at all?) - } - - void cglEnable (GLenum cap){ - EnableDisableSet(cap, true); - } - - void EnableDisableSet(GLenum cap, bool value){ - switch ( cap ) { - case GL_ALPHA_TEST: - if ( m_glAlphaTest != value ) { - SetRenderStateDirty(); - m_glAlphaTest = value; - m_glAlphaStateDirty = true; - } - break; - case GL_BLEND: - if ( m_glBlend != value ) { - SetRenderStateDirty(); - m_textureState.SetMainBlend(value); - m_glBlend = value; - m_glBlendStateDirty = true; - } - break; - case GL_CULL_FACE: - if ( m_glCullFace != value ) { - SetRenderStateDirty(); - m_glCullFace = value; - m_glCullStateDirty = true; - } - break; - case GL_DEPTH_TEST: - if ( m_glDepthTest != value ) { - SetRenderStateDirty(); - m_glDepthTest = value; - m_glDepthStateDirty = true; - } - break; - case GL_TEXTURE_2D: - if ( m_textureState.GetTexture2D() != value ) { - SetRenderStateDirty(); - m_textureState.SetTexture2D(value); - } - break; - - case GL_TEXTURE_GEN_S: - case GL_TEXTURE_GEN_T: - break; - case GL_NORMALIZE: - break; - case GL_AUTO_NORMAL: - break; - case GL_DITHER: - case GL_FOG: - break; - case GL_POLYGON_OFFSET_FILL: // I fear for the shaders. - break; - default: - LocalDebugBreak(); - break; - } - } - - void cglEnd (void){ - // internalEnd(); - } - - void internalEnd(){ - m_OGLPrimitiveVertexBuffer.End(); - } - - void cglFinish (void){ - // To Do: This is supposed to flush all pending commands - internalEnd(); - } - - void cglFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){ - SetRenderStateDirty(); - D3DXMATRIX m; - // Note that D3D takes top, bottom arguments in opposite order - qD3DXMatrixPerspectiveOffCenter(&m, left, right, bottom, top, zNear, zFar); - m_currentMatrixStack->MultMatrixLocal(&m); - *m_currentMatrixStateDirty = true; - } - - void cglGetFloatv (GLenum pname, GLfloat *params){ - switch(pname){ - case GL_MODELVIEW_MATRIX: - memcpy(params,m_modelViewMatrixStack->GetTop(), sizeof(D3DMATRIX)); - break; - default: - LocalDebugBreak(); - break; - } - } - - const GLubyte * cglGetString (GLenum name){ - const char* result = ""; - EnsureDriverInfo(); - switch ( name ) { - case GL_VENDOR: - result = m_vendor; - break; - case GL_RENDERER: - result = m_renderer; - break; - case GL_VERSION: - result = m_version; - break; - case GL_EXTENSIONS: - result = m_extensions; - break; - default: - break; - } - return (const GLubyte *) result; - } - - void cglHint (GLenum /* target */, GLenum /* mode */){ - LocalDebugBreak(); - } - - void cglLoadIdentity (void){ - SetRenderStateDirty(); - m_currentMatrixStack->LoadIdentity(); - *m_currentMatrixStateDirty = true; - } - - void cglLoadMatrixf (const GLfloat *m){ - SetRenderStateDirty(); - m_currentMatrixStack->LoadMatrix((D3DXMATRIX*) m); - *m_currentMatrixStateDirty = true; - } - void cglMultMatrixf (const GLfloat *m){ - SetRenderStateDirty(); - m_currentMatrixStack->MultMatrixLocal((D3DXMATRIX*) m); - *m_currentMatrixStateDirty = true; - } - - void cglMatrixMode (GLenum mode){ - m_glMatrixMode = mode; - switch ( mode ) { - case GL_MODELVIEW: - m_currentMatrixStack = m_modelViewMatrixStack; - m_currentMatrixStateDirty = &m_modelViewMatrixStateDirty; - break; - case GL_PROJECTION: - m_currentMatrixStack = m_projectionMatrixStack; - m_currentMatrixStateDirty = &m_projectionMatrixStateDirty; - break; - case GL_TEXTURE: - m_currentMatrixStack = m_textureMatrixStack; - m_currentMatrixStateDirty = &m_textureMatrixStateDirty; - break; - default: - LocalDebugBreak(); - break; - } - } - - void cglOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){ - SetRenderStateDirty(); - D3DXMATRIX m; - qD3DXMatrixOrthoOffCenter(&m, left, right, top, bottom, zNear, zFar); - m_currentMatrixStack->MultMatrixLocal(&m); - *m_currentMatrixStateDirty = true; - } - - void cglPolygonMode (GLenum face, GLenum mode){ - SetRenderStateDirty(); - switch ( face ) { - case GL_FRONT: - m_glPolygonModeFront = mode; - break; - case GL_BACK: - m_glPolygonModeBack = mode; - break; - case GL_FRONT_AND_BACK: - m_glPolygonModeFront = mode; - m_glPolygonModeBack = mode; - break; - default: - LocalDebugBreak(); - break; - } - } - - void cglPopMatrix (void){ - SetRenderStateDirty(); - m_currentMatrixStack->Pop(); - *m_currentMatrixStateDirty = true; - } - - void cglPushMatrix (void){ - m_currentMatrixStack->Push(); - // Doesn't dirty matrix state - } - - void cglReadBuffer (GLenum /* mode */){ - // Not that we allow reading from various buffers anyway. - } - - void cglReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels){ - if ( format != GL_RGB || type != GL_UNSIGNED_BYTE) { - LocalDebugBreak(); - return; - } - internalEnd(); -#ifdef USE_D3DXCONTEXT - LPDIRECTDRAWSURFACE7 back = m_pD3DX->GetBackBuffer(0); -#endif -#ifdef USE_D3DFRAME - LPDIRECTDRAWSURFACE7 back = m_pFramework->GetBackBuffer(); -#endif - if(back) { - DDSURFACEDESC2 desc = {sizeof(desc) }; - HRESULT hr = back->Lock(NULL, &desc, DDLOCK_READONLY | DDLOCK_WAIT, 0); - if ( FAILED(hr) ) { - InterpretError(hr); - return; - } - CopyBitsToRGB(pixels, x, y, width, height, &desc); - back->Unlock(NULL); - RELEASENULL(back); - } - } - - static WORD GetNumberOfBits( DWORD dwMask ) - { - WORD wBits = 0; - while( dwMask ) - { - dwMask = dwMask & ( dwMask - 1 ); - wBits++; - } - return wBits; - } - - static WORD GetShift( DWORD dwMask ) - { - for(WORD i = 0; i < 32; i++ ) { - if ( (1 << i) & dwMask ) { - return i; - } - } - return 0; // no bits in mask. - } - - // Extract the bits and replicate out to an eight bit value - static DWORD ExtractAndNormalize(DWORD rgba, DWORD shift, DWORD bits, DWORD mask){ - DWORD v = (rgba & mask) >> shift; - // Assume bits >= 4 - v = (v | (v << bits)); - v = v >> (bits*2 - 8); - return v; - } - - void CopyBitsToRGB(void* pixels, DWORD sx, DWORD sy, DWORD width, DWORD height, LPDDSURFACEDESC2 pDesc){ - if ( ! (pDesc->ddpfPixelFormat.dwFlags & DDPF_RGB) ) { - return; // Can't handle non-RGB surfaces - } - // We have to flip the Y axis to convert from D3D to openGL - long destEndOfLineSkip = -2 * (width * 3); - unsigned char* pDest = ((unsigned char*) pixels) + (height - 1) * width * 3 ; - switch ( pDesc->ddpfPixelFormat.dwRGBBitCount ) { - default: - return; - case 16: - { - unsigned short* pSource = (unsigned short*) - (((unsigned char*) pDesc->lpSurface) + sx * sizeof(unsigned short) + sy * pDesc->lPitch); - DWORD endOfLineSkip = pDesc->lPitch / sizeof(unsigned short) - pDesc->dwWidth; - DWORD rMask = pDesc->ddpfPixelFormat.dwRBitMask; - DWORD gMask = pDesc->ddpfPixelFormat.dwGBitMask; - DWORD bMask = pDesc->ddpfPixelFormat.dwBBitMask; - DWORD rShift = GetShift(rMask); - DWORD rBits = GetNumberOfBits(rMask); - DWORD gShift = GetShift(gMask); - DWORD gBits = GetNumberOfBits(gMask); - DWORD bShift = GetShift(bMask); - DWORD bBits = GetNumberOfBits(bMask); - for(DWORD y = 0; y < height; y++ ) { - for (DWORD x = 0; x < width; x++ ) { - unsigned short rgba = *pSource++; - *pDest++ = ExtractAndNormalize(rgba, rShift, rBits, rMask); - *pDest++ = ExtractAndNormalize(rgba, gShift, gBits, gMask); - *pDest++ = ExtractAndNormalize(rgba, bShift, bBits, bMask); - } - pSource += endOfLineSkip; - pDest += destEndOfLineSkip; - } - } - break; - case 32: - { - unsigned long* pSource = (unsigned long*) - (((unsigned char*) pDesc->lpSurface) + sx * sizeof(unsigned long) + sy * pDesc->lPitch); - DWORD endOfLineSkip = pDesc->lPitch / sizeof(unsigned long) - pDesc->dwWidth; - for(DWORD y = 0; y < height; y++ ) { - for (DWORD x = 0; x < width; x++ ) { - unsigned long rgba = *pSource++; - *pDest++ = RGBA_GETRED(rgba); - *pDest++ = RGBA_GETGREEN(rgba); - *pDest++ = RGBA_GETBLUE(rgba); - } - pSource += endOfLineSkip; - pDest += destEndOfLineSkip; - } - } - break; - } - } - - void cglRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z){ - SetRenderStateDirty(); - D3DXMATRIX m; - D3DXVECTOR3 v; - v.x = x; - v.y = y; - v.z = z; - // GL uses counterclockwise degrees, DX uses clockwise radians - float dxAngle = angle * 3.14159 / 180; - m_currentMatrixStack->RotateAxisLocal(&v, dxAngle); - *m_currentMatrixStateDirty = true; - } - - void cglScalef (GLfloat x, GLfloat y, GLfloat z){ - SetRenderStateDirty(); - D3DXMATRIX m; - qD3DXMatrixScaling(&m, x, y, z); - m_currentMatrixStack->MultMatrixLocal(&m); - *m_currentMatrixStateDirty = true; - } - - void cglShadeModel (GLenum mode){ - if ( m_glShadeModel != mode ) { - SetRenderStateDirty(); - m_glShadeModel = mode; - m_glShadeModelStateDirty = true; - } - } - - inline void cglTexCoord2f (GLfloat s, GLfloat t){ - m_OGLPrimitiveVertexBuffer.SetTextureCoord0(s, t); - } - - void cglTexEnvf (GLenum /* target */, GLenum /* pname */, GLfloat param){ - // ignore target, which must be GL_TEXTURE_ENV - // ignore pname, which must be GL_TEXTURE_ENV_MODE - if ( m_textureState.GetTextEnvMode() != param ) { - SetRenderStateDirty(); - m_textureState.SetTextEnvMode(param); - } - } - - static int MipMapSize(DWORD width, DWORD height){ - DWORD n = width < height? width : height; - DWORD result = 1; - while (n > (DWORD) (1 << result) ) { - result++; - } - return result; - } - -#define LOAD_OURSELVES - - void cglTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, - GLsizei height, GLint /* border */, GLenum format, GLenum type, const GLvoid *pixels){ - HRESULT hr; - if ( target != GL_TEXTURE_2D || type != GL_UNSIGNED_BYTE) { - InterpretError(E_FAIL); - return; - } - - bool isDynamic = format == GL_LUMINANCE; // Lightmaps use this format. - - DWORD dxWidth = width; - DWORD dxHeight = height; - - D3DX_SURFACEFORMAT srcPixelFormat = GLToDXPixelFormat(internalformat, format); - D3DX_SURFACEFORMAT destPixelFormat = srcPixelFormat; - // Can the surface handle that format? - hr = qD3DXCheckTextureRequirements(m_pD3DDev, NULL, &dxWidth, &dxHeight, &destPixelFormat); - if ( FAILED(hr) ) { - if ( g_force16bitTextures ) { - destPixelFormat = D3DX_SF_A4R4G4B4; - hr = qD3DXCheckTextureRequirements(m_pD3DDev, NULL, NULL, NULL, &destPixelFormat); - if ( FAILED(hr) ) { - // Don't know what to do. - InterpretError(E_FAIL); - return; - } - } - else { - destPixelFormat = D3DX_SF_A8R8G8B8; - hr = qD3DXCheckTextureRequirements(m_pD3DDev, NULL, NULL, NULL, &destPixelFormat); - if ( FAILED(hr) ) { - // The card can't handle this pixel format. Switch to D3DX_SF_A4R4G4B4 - destPixelFormat = D3DX_SF_A4R4G4B4; - hr = qD3DXCheckTextureRequirements(m_pD3DDev, NULL, NULL, NULL, &destPixelFormat); - if ( FAILED(hr) ) { - // Don't know what to do. - InterpretError(E_FAIL); - return; - } - } - } - } - -#ifdef LOAD_OURSELVES - - char* goodSizeBits = (char*) pixels; - if ( dxWidth != (DWORD) width || dxHeight != (DWORD) height ) { - // Most likely this is because there is a 256 x 256 limit on the texture size. - goodSizeBits = new char[sizeof(DWORD) * dxWidth * dxHeight]; - DWORD* dest = ((DWORD*) goodSizeBits); - for ( DWORD y = 0; y < dxHeight; y++) { - DWORD sy = y * height / dxHeight; - for(DWORD x = 0; x < dxWidth; x++) { - DWORD sx = x * width / dxWidth; - DWORD* source = ((DWORD*) pixels) + sy * dxWidth + sx; - *dest++ = *source; - } - } - width = dxWidth; - height = dxHeight; - } - // To do: Convert the pixels on the fly while copying into the DX texture. - char* compatablePixels; - DWORD compatablePixelsPitch; - - hr = ConvertToCompatablePixels(internalformat, width, height, format, - type, destPixelFormat, goodSizeBits, &compatablePixels, &compatablePixelsPitch); - - if ( goodSizeBits != pixels ) { - delete [] goodSizeBits; - } - if ( FAILED(hr)) { - InterpretError(hr); - return; - } - -#endif - - // It the current texture of the right size? - LPDIRECTDRAWSURFACE7 pTexture = m_textures.GetTexture(); - if ( pTexture ) { - DDSURFACEDESC2 surface; - memset(&surface, 0, sizeof(surface)); - surface.dwSize = sizeof(surface); - hr = pTexture->GetSurfaceDesc(&surface); - if ( FAILED(hr) ) { - InterpretError(hr); - return; - } - // Is this texture being resized or re-color-formatted? - if ( level == 0 && - ( surface.dwWidth != (DWORD) width || surface.dwHeight != (DWORD) height - || destPixelFormat != m_textures.GetCurrentEntry()->m_format)) { - m_textures.SetTexture(NULL, D3DX_SF_UNKNOWN, 0); - pTexture = 0; - } - // For non-square textures, OpenGL uses more MIPMAP levels than DirectX does. - else if ( (surface.dwWidth >> level) <= 0 || (surface.dwHeight >> level) <= 0 ) { - return; - } - } - - if( ! pTexture) { -#ifdef USE_D3DXCREATETEXTURE - DWORD dxwidth = width; - DWORD dxheight = height; - D3DX_SURFACEFORMAT pixelFormat = destPixelFormat; - DWORD numMapsGenerated = 0; - hr = D3DXCreateTexture(m_pD3DDev, NULL, &dxwidth, &dxheight, &pixelFormat, - NULL, &pTexture, &numMapsGenerated); - if ( FAILED(hr) ) { - InterpretError(hr); - return; - } -#else - DDSURFACEDESC2 sd = {sizeof(sd)}; - D3DX_SURFACEFORMAT pixelFormat = destPixelFormat; - sd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT| - DDSD_PIXELFORMAT; - sd.dwHeight = dxHeight; - sd.dwWidth = dxWidth; - qD3DXMakeDDPixelFormat(pixelFormat, &sd.ddpfPixelFormat); - sd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; - if ( m_hintGenerateMipMaps ) { - sd.ddsCaps.dwCaps |= DDSCAPS_MIPMAP|DDSCAPS_COMPLEX; - } - sd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE; - if ( isDynamic ) { - sd.ddsCaps.dwCaps2 |= DDSCAPS2_HINTDYNAMIC; - } - else { - sd.ddsCaps.dwCaps2 |= DDSCAPS2_OPAQUE; // DDSCAPS2_HINTSTATIC; - } - - hr = m_pDD->CreateSurface(&sd, &pTexture, NULL); - if ( FAILED(hr) ) { - InterpretError(hr); - return; - } - - int bytesThisTexture = height * compatablePixelsPitch; - if ( m_hintGenerateMipMaps ) { - bytesThisTexture = bytesThisTexture * 4 / 3; - } - static int gNumBytesOfTextures = 0; // For debugging - gNumBytesOfTextures += bytesThisTexture; -#endif - m_textures.SetTexture(pTexture, pixelFormat, internalformat); - } - -#ifdef LOAD_OURSELVES - - glTexSubImage2D_Imp(pTexture, level, 0, 0, width, height, format, type, compatablePixels, - compatablePixelsPitch); - -#else - // This function is useful because it can scale large textures to fit into smaller textures. - hr = D3DXLoadTextureFromMemory(m_pD3DDev, pTexture, level, (void*) pixels, NULL, srcPixelFormat, D3DX_DEFAULT, - NULL, D3DX_FT_DEFAULT); -#endif - - if ( FAILED(hr) ) { - InterpretError(hr); - return; - } - } - - void cglTexParameterf (GLenum target, GLenum pname, GLfloat param){ - - switch(target){ - case GL_TEXTURE_2D: - { - SetRenderStateDirty(); - TextureEntry* current = m_textures.GetCurrentEntry(); - m_textureState.DirtyTexture(m_textures.GetCurrentID()); - switch(pname) { - case GL_TEXTURE_MIN_FILTER: - current->m_glTexParameter2DMinFilter = param; - break; - case GL_TEXTURE_MAG_FILTER: - current->m_glTexParameter2DMagFilter = param; - break; - case GL_TEXTURE_WRAP_S: - current->m_glTexParameter2DWrapS = param; - break; - case GL_TEXTURE_WRAP_T: - current->m_glTexParameter2DWrapT = param; - break; - case GL_TEXTURE_MAX_ANISOTROPY_EXT: - current->m_maxAnisotropy = param; - break; - default: - LocalDebugBreak(); - } - } - break; - default: - LocalDebugBreak(); - break; - } - } - - void cglTexSubImage2D (GLenum target, GLint level, - GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid *pixels){ - if ( target != GL_TEXTURE_2D ) { - LocalDebugBreak(); - return; - } - if ( width <= 0 || height <= 0 ) { - return; - } - - LPDIRECTDRAWSURFACE7 pTexture = m_textures.GetTexture(); - if ( ! pTexture ) { - return; - } - - internalEnd(); // We may have a pending drawing using the old texture state. - - // To do: Convert the pixels on the fly while copying into the DX texture. - - char* compatablePixels = 0; - DWORD compatablePixelsPitch; - if ( FAILED(ConvertToCompatablePixels(m_textures.GetInternalFormat(), - width, height, - format, type, m_textures.GetSurfaceFormat(), - pixels, &compatablePixels, &compatablePixelsPitch))) { - LocalDebugBreak(); - return; - } - - glTexSubImage2D_Imp(pTexture, level, xoffset, yoffset, width, height, format, type, - compatablePixels, compatablePixelsPitch); - } - - char* StickyAlloc(DWORD size){ - if ( m_stickyAllocSize < size ) { - delete [] m_stickyAlloc; - m_stickyAlloc = new char[size]; - m_stickyAllocSize = size; - } - return m_stickyAlloc; - } - - void glTexSubImage2D_Imp (LPDIRECTDRAWSURFACE7 pTexture, GLint level, - GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum /* format */, GLenum /* type */, const char* compatablePixels, int compatablePixelsPitch){ - - HRESULT hr = S_OK; - - // Walk MIPMAP chain - - LPDIRECTDRAWSURFACE7 lpDDLevel; - - { - LPDIRECTDRAWSURFACE7 lpDDNextLevel; - DDSCAPS2 ddsCaps; - - lpDDLevel = pTexture; - lpDDLevel->AddRef(); - memset(&ddsCaps, 0, sizeof(ddsCaps)); - ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; - hr = DD_OK; - while (hr == DD_OK && level > 0) - { - hr = lpDDLevel->GetAttachedSurface(&ddsCaps, &lpDDNextLevel); - lpDDLevel->Release(); - lpDDLevel = lpDDNextLevel; - level--; - } - } - - if ( FAILED(hr) ) { - InterpretError(hr); - RELEASENULL(lpDDLevel); - return; - } - - DDSURFACEDESC2 surfaceDesc; - memset(&surfaceDesc, 0, sizeof(DDSURFACEDESC2)); - surfaceDesc.dwSize = sizeof(DDSURFACEDESC2); - RECT lockRect; - lockRect.top = yoffset; - lockRect.left = xoffset; - lockRect.bottom = yoffset + height; - lockRect.right = xoffset + width; - hr = lpDDLevel->Lock(&lockRect, &surfaceDesc, - DDLOCK_NOSYSLOCK|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL); - if ( FAILED(hr) ) { - InterpretError(hr); - } - else { - const char* sp = compatablePixels; - char* dp = (char*) surfaceDesc.lpSurface; - if ( compatablePixelsPitch != surfaceDesc.lPitch ) { - for(int i = 0; i < height; i++ ) { - memcpy(dp, sp, compatablePixelsPitch); - sp += compatablePixelsPitch; - dp += surfaceDesc.lPitch; - } - } - else { - memcpy(dp, sp, compatablePixelsPitch * height); - } - lpDDLevel->Unlock(&lockRect); - } - - RELEASENULL(lpDDLevel); - - if ( FAILED(hr) ) { - InterpretError(hr); - } - } - - void cglTranslatef (GLfloat x, GLfloat y, GLfloat z){ - SetRenderStateDirty(); - D3DXMATRIX m; - qD3DXMatrixTranslation(&m, x, y, z); - m_currentMatrixStack->MultMatrixLocal(&m); - *m_currentMatrixStateDirty = true; - } - - inline void cglVertex2f (GLfloat x, GLfloat y){ - m_OGLPrimitiveVertexBuffer.SetVertex(x, y, 0); - } - - inline void cglVertex3f (GLfloat x, GLfloat y, GLfloat z){ - m_OGLPrimitiveVertexBuffer.SetVertex(x, y, z); - } - - inline void cglVertex3fv (const GLfloat *v){ - m_OGLPrimitiveVertexBuffer.SetVertex(v[0], v[1], v[2]); - } - - void cglViewport (GLint x, GLint y, GLsizei width, GLsizei height){ - if ( m_glViewPortX != x || m_glViewPortY != y || - m_glViewPortWidth != width || m_glViewPortHeight != height ) { - SetRenderStateDirty(); - m_glViewPortX = x; - m_glViewPortY = y; - m_glViewPortWidth = width; - m_glViewPortHeight = height; - - m_bViewPortDirty = true; - } - } - - void SwapBuffers(){ - HRESULT hr = S_OK; - internalEnd(); - m_pD3DDev->EndScene(); - m_needBeginScene = true; -#ifdef USE_D3DXCONTEXT - hr = m_pD3DX->UpdateFrame( D3DX_UPDATE_NOVSYNC ); - if ( hr == DDERR_SURFACELOST || hr == DDERR_SURFACEBUSY ) - hr = HandleWindowedModeChanges(); -#endif -#ifdef USE_D3DFRAME - if( FAILED( hr = m_pFramework->ShowFrame() ) ) - { - if( DDERR_SURFACELOST != hr ) - return; - - m_pFramework->RestoreSurfaces(); - RestoreSurfaces(); - } -#endif - } - - void SetGammaRamp(const unsigned char* gammaTable){ - DDCAPS caps = {sizeof(DDCAPS)}; - HRESULT hr; - hr = m_pDD->GetCaps(&caps, NULL); - if ( caps.dwCaps2 & DDCAPS2_PRIMARYGAMMA ) { - DDGAMMARAMP gammaRamp; - for(int i = 0; i < 256; i++ ) { - WORD value = gammaTable[i]; - value = value + (value << 8); // * 257 - gammaRamp.red[i] = value; - gammaRamp.green[i] = value; - gammaRamp.blue[i] = value; - } -/* - if(m_pPrimary) { - IDirectDrawGammaControl* lpDDGammaControl = 0; - hr = m_pPrimary->QueryInterface(IID_IDirectDrawGammaControl,(void**)&lpDDGammaControl); - if ( ! FAILED(hr) && lpDDGammaControl ) { - DWORD dwFlags = 0; - if ( caps.dwCaps2 & DDCAPS2_CANCALIBRATEGAMMA ) { - dwFlags = DDSGR_CALIBRATE; - } - hr = lpDDGammaControl->SetGammaRamp(dwFlags, &gammaRamp); - - RELEASENULL(lpDDGammaControl); - } - } - */ - } - } - - void Hint_GenerateMipMaps(int value){ - m_hintGenerateMipMaps = value != 0; - } - - void EvictTextures(){ - m_pD3D->EvictManagedTextures(); - } -private: - - void SetRenderStateDirty(){ - if ( ! m_glRenderStateDirty ) { - internalEnd(); - m_glRenderStateDirty = true; - } - } - - HRESULT HandleWindowedModeChanges() - { -#ifdef USE_D3DFRAME - return Change3DEnvironment(); -#endif - HRESULT hr; - hr = m_pDD->TestCooperativeLevel(); - - if( SUCCEEDED( hr ) ) - { - // This means that mode changes had taken place, surfaces - // were lost but still we are in the original mode, so we - // simply restore all surfaces and keep going. - if( FAILED( m_pDD->RestoreAllSurfaces() ) ) - return hr; - } - else if( hr == DDERR_WRONGMODE ) - { - // This means that the desktop mode has changed - // we can destroy and recreate everything back again. - if(FAILED(hr = ReleaseD3DX())) - return hr; - if(FAILED(hr = InitD3DX())) - return hr; - } - else if( hr == DDERR_EXCLUSIVEMODEALREADYSET ) - { - // This means that some app took exclusive mode access - // we need to sit in a loop till we get back to the right mode. - do - { - Sleep( 500 ); - } while( DDERR_EXCLUSIVEMODEALREADYSET == - (hr = m_pDD->TestCooperativeLevel()) ); - if( SUCCEEDED( hr ) ) - { - // This means that the exclusive mode app relinquished its - // control and we are back to the safe mode, so simply restore - if( FAILED( m_pDD->RestoreAllSurfaces() ) ) - return hr; - } - else if( DDERR_WRONGMODE == hr ) - { - // This means that the exclusive mode app relinquished its - // control BUT we are back to some strange mode, so destroy - // and recreate. - if(FAILED(hr = ReleaseD3DX())) - return hr; - if(FAILED(hr = InitD3DX())) - return hr; - } - else - { - // Busted!! - return hr; - } - } - else - { - // Busted!! - return hr; - } - return S_OK; - } - - void SetGLRenderState(){ - if ( ! m_glRenderStateDirty ) { - return; - } - m_glRenderStateDirty = false; - HRESULT hr; - if ( m_glAlphaStateDirty ){ - m_glAlphaStateDirty = false; - // Alpha test - m_pD3DDev->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, - m_glAlphaTest ? TRUE : FALSE ); - m_pD3DDev->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, - m_glAlphaTest ? GLToDXCompare(m_glAlphaFunc) : D3DCMP_ALWAYS); - m_pD3DDev->SetRenderState(D3DRENDERSTATE_ALPHAREF, 255 * m_glAlphaFuncRef); - } - if ( m_glBlendStateDirty ){ - m_glBlendStateDirty = false; - // Alpha blending - DWORD srcBlend = m_glBlend ? GLToDXSBlend(m_glBlendFuncSFactor) : D3DBLEND_ONE; - DWORD destBlend = m_glBlend ? GLToDXDBlend(m_glBlendFuncDFactor) : D3DBLEND_ZERO; - m_pD3DDev->SetRenderState( D3DRENDERSTATE_SRCBLEND, srcBlend ); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_DESTBLEND, destBlend ); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, m_glBlend ? TRUE : FALSE ); - } - if ( m_glCullStateDirty ) { - m_glCullStateDirty = false; - D3DCULL cull = D3DCULL_NONE; - if ( m_glCullFace ) { - switch(m_glCullFaceMode){ - default: - case GL_BACK: - // Should deal with frontface function - cull = D3DCULL_CCW; - break; - } - } - hr = m_pD3DDev->SetRenderState(D3DRENDERSTATE_CULLMODE, cull); - if ( FAILED(hr) ){ - InterpretError(hr); - } - } - if ( m_glShadeModelStateDirty ){ - m_glShadeModelStateDirty = false; - // Shade model - m_pD3DDev->SetRenderState( D3DRENDERSTATE_SHADEMODE, - m_glShadeModel == GL_SMOOTH ? D3DSHADE_GOURAUD : D3DSHADE_FLAT ); - } - - { - m_textureState.SetTextureStageState(m_pD3DDev, &m_textures); - } - - if ( m_glDepthStateDirty ) { - m_glDepthStateDirty = false; - m_pD3DDev->SetRenderState( D3DRENDERSTATE_ZENABLE, m_glDepthTest ? D3DZB_TRUE : D3DZB_FALSE); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE, m_glDepthMask ? TRUE : FALSE); - DWORD zfunc = GLToDXCompare(m_glDepthFunc); - m_pD3DDev->SetRenderState( D3DRENDERSTATE_ZFUNC, zfunc ); - } - if ( m_modelViewMatrixStateDirty ) { - m_modelViewMatrixStateDirty = false; - m_pD3DDev->SetTransform( D3DTRANSFORMSTATE_WORLD, (LPD3DMATRIX) m_modelViewMatrixStack->GetTop() ); - } - if ( m_viewMatrixStateDirty ) { - m_viewMatrixStateDirty = false; - m_pD3DDev->SetTransform( D3DTRANSFORMSTATE_VIEW, (LPD3DMATRIX) & m_d3dViewMatrix ); - } - if ( m_projectionMatrixStateDirty ) { - m_projectionMatrixStateDirty = false; - m_pD3DDev->SetTransform( D3DTRANSFORMSTATE_PROJECTION, (LPD3DMATRIX) m_projectionMatrixStack->GetTop() ); - } - if ( m_textureMatrixStateDirty ) { - m_textureMatrixStateDirty = false; - m_pD3DDev->SetTransform( D3DTRANSFORMSTATE_TEXTURE0, (LPD3DMATRIX) m_textureMatrixStack->GetTop() ); - } - if ( m_bViewPortDirty ) { - m_bViewPortDirty = false; - D3DVIEWPORT7 viewData; - viewData.dwX = m_glViewPortX; - viewData.dwY = m_windowHeight - (m_glViewPortY + m_glViewPortHeight); - viewData.dwWidth = m_glViewPortWidth; - viewData.dwHeight = m_glViewPortHeight; - viewData.dvMinZ = m_glDepthRangeNear; - viewData.dvMaxZ = m_glDepthRangeFar; - - if (r_secondaryview) - { - m_pD3DDev->EndScene(); - m_needBeginScene = true; - } - - m_pD3DDev->SetViewport(&viewData); - } - } - - void EnsureDriverInfo() { - if ( ! m_vendor ) { - memset(&m_dddi, 0, sizeof(m_dddi)); - m_pDD->GetDeviceIdentifier(&m_dddi, 0); - m_vendor = m_dddi.szDriver; - m_renderer = m_dddi.szDescription; - wsprintf(m_version, "%u.%u.%u.%u %u.%u.%u.%u %u", - HIWORD(m_dddi.liDriverVersion.HighPart), - LOWORD(m_dddi.liDriverVersion.HighPart), - HIWORD(m_dddi.liDriverVersion.LowPart), - LOWORD(m_dddi.liDriverVersion.LowPart), - m_dddi.dwVendorId, - m_dddi.dwDeviceId, - m_dddi.dwSubSysId, - m_dddi.dwRevision, - m_dddi.dwWHQLLevel - ); - if ( m_textureState.GetMaxStages() > 1 ) { - m_extensions = " GL_SGIS_multitexture GL_EXT_texture_object "; - } - else { - m_extensions = " GL_EXT_texture_object "; - } - } - } - - D3DX_SURFACEFORMAT GLToDXPixelFormat(GLint internalformat, GLenum format){ - D3DX_SURFACEFORMAT d3dFormat = D3DX_SF_UNKNOWN; - if ( g_force16bitTextures ) { - switch ( format ) { - case GL_RGBA: - switch ( internalformat ) { - default: - case 4: -// d3dFormat = D3DX_SF_A1R5G5B5; break; - d3dFormat = D3DX_SF_A4R4G4B4; break; - case 3: - d3dFormat = D3DX_SF_R5G6B5; break; - } - break; - case GL_RGB: d3dFormat = D3DX_SF_R5G5B5; break; - case GL_COLOR_INDEX: d3dFormat = D3DX_SF_PALETTE8; break; - case GL_LUMINANCE: d3dFormat = D3DX_SF_L8; break; - case GL_ALPHA: d3dFormat = D3DX_SF_A8; break; - case GL_INTENSITY: d3dFormat = D3DX_SF_L8; break; - case GL_RGBA4: d3dFormat = D3DX_SF_A4R4G4B4; break; - default: - InterpretError(E_FAIL); - } - } - else { - // for - switch ( format ) { - case GL_RGBA: - switch ( internalformat ) { - default: - case 4: - d3dFormat = D3DX_SF_A8R8G8B8; break; - case 3: - d3dFormat = D3DX_SF_X8R8G8B8; break; - } - break; - case GL_RGB: - d3dFormat = D3DX_SF_R8G8B8; - break; - case GL_COLOR_INDEX: d3dFormat = D3DX_SF_PALETTE8; break; - case GL_LUMINANCE: d3dFormat = D3DX_SF_L8; break; - case GL_ALPHA: d3dFormat = D3DX_SF_A8; break; - case GL_INTENSITY: d3dFormat = D3DX_SF_L8; break; - case GL_RGBA4: d3dFormat = D3DX_SF_A4R4G4B4; break; - default: - InterpretError(E_FAIL); - } - } - return d3dFormat; - } - -// Avoid warning 4061, enumerant 'foo' in switch of enum 'bar' is not explicitly handled by a case label. -#pragma warning( push ) -#pragma warning( disable : 4061) - - HRESULT ConvertToCompatablePixels(GLint internalformat, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - D3DX_SURFACEFORMAT dxPixelFormat, - const GLvoid *pixels, char** compatablePixels, - DWORD* newPitch){ - HRESULT hr = S_OK; - if ( type != GL_UNSIGNED_BYTE ) { - return E_FAIL; - } - switch ( dxPixelFormat ) { - default: - LocalDebugBreak(); - break; - case D3DX_SF_PALETTE8: - case D3DX_SF_L8: - case D3DX_SF_A8: - { - char* copy = StickyAlloc(width*height); - memcpy(copy,pixels,width * height); - *compatablePixels = copy; - if ( newPitch ) { - *newPitch = width; - } - } - break; - case D3DX_SF_A4R4G4B4: - { - int textureElementSize = 2; - const unsigned char* glpixels = (const unsigned char*) pixels; - char* dxpixels = StickyAlloc(textureElementSize * width * height); - switch ( internalformat ) { - default: - LocalDebugBreak(); - break; - case 1: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const unsigned char* sp = glpixels + (y*width+x); - unsigned short v; - unsigned short s = 0xf & (sp[0] >> 4); - v = s; // blue - v |= s << 4; // green - v |= s << 8; // red - v |= s << 12; // alpha - *dp = v; - } - } - } - break; - case 3: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const unsigned char* sp = glpixels + (y*width+x)*4; - unsigned short v; - v = (0xf & (sp[2] >> 4)); // blue - v |= (0xf & (sp[1] >> 4)) << 4; // green - v |= (0xf & (sp[0] >> 4)) << 8; // red - v |= 0xf000; // alpha - *dp = v; - } - } - } - break; - case 4: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*)(dxpixels + (y*width+x)*textureElementSize); - const unsigned char* sp = glpixels + (y*width+x)*4; - unsigned short v; - v = (0xf & (sp[2] >> 4)); // blue - v |= (0xf & (sp[1] >> 4)) << 4; // green - v |= (0xf & (sp[0] >> 4)) << 8; // red - v |= (0xf & (sp[3] >> 4)) << 12; // alpha - *dp = v; - } - } - } - break; - } - *compatablePixels = dxpixels; - if ( newPitch ) { - *newPitch = 2 * width; - } - } - break; - case D3DX_SF_R5G6B5: - { - int textureElementSize = 2; - const char* glpixels = (const char*) pixels; - char* dxpixels = StickyAlloc(textureElementSize * width * height); - switch ( internalformat ) { - default: - LocalDebugBreak(); - break; - case 1: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const char* sp = glpixels + (y*width+x); - unsigned short v; - v = (0x1f & (sp[0] >> 3)); // blue - v |= (0x3f & (sp[0] >> 2)) << 5; // green - v |= (0x1f & (sp[0] >> 3)) << 11; // red - *dp = v; - } - } - } - break; - case 3: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const char* sp = glpixels + (y*width+x)*4; - unsigned short v; - v = (0x1f & (sp[2] >> 3)); // blue - v |= (0x3f & (sp[1] >> 2)) << 5; // green - v |= (0x1f & (sp[0] >> 3)) << 11; // red - *dp = v; - } - } - } - break; - case 4: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const char* sp = glpixels + (y*width+x)*4; - unsigned short v; - v = (0x1f & (sp[2] >> 3)); // blue - v |= (0x3f & (sp[1] >> 2)) << 5; // green - v |= (0x1f & (sp[0] >> 3)) << 11; // red - *dp = v; - } - } - } - break; - } - *compatablePixels = dxpixels; - if ( newPitch ) { - *newPitch = 2 * width; - } - } - break; - case D3DX_SF_R5G5B5: - { - int textureElementSize = 2; - const char* glpixels = (const char*) pixels; - char* dxpixels = StickyAlloc(textureElementSize * width * height); - switch ( internalformat ) { - default: - LocalDebugBreak(); - break; - case 1: - { -#define RGBTOR5G5B5(R, G, B) (0x8000 | (0x1f & ((B) >> 3)) | ((0x1f & ((G) >> 3)) << 5) | ((0x1f & ((R) >> 3)) << 10)) -#define Y5TOR5G5B5(Y) (0x8000 | ((Y) << 10) | ((Y) << 5) | (Y)) - static const unsigned short table[32] = { - Y5TOR5G5B5(0), Y5TOR5G5B5(1), Y5TOR5G5B5(2), Y5TOR5G5B5(3), - Y5TOR5G5B5(4), Y5TOR5G5B5(5), Y5TOR5G5B5(6), Y5TOR5G5B5(7), - Y5TOR5G5B5(8), Y5TOR5G5B5(9), Y5TOR5G5B5(10), Y5TOR5G5B5(11), - Y5TOR5G5B5(12), Y5TOR5G5B5(13), Y5TOR5G5B5(14), Y5TOR5G5B5(15), - Y5TOR5G5B5(16), Y5TOR5G5B5(17), Y5TOR5G5B5(18), Y5TOR5G5B5(19), - Y5TOR5G5B5(20), Y5TOR5G5B5(21), Y5TOR5G5B5(22), Y5TOR5G5B5(23), - Y5TOR5G5B5(24), Y5TOR5G5B5(25), Y5TOR5G5B5(26), Y5TOR5G5B5(27), - Y5TOR5G5B5(28), Y5TOR5G5B5(29), Y5TOR5G5B5(30), Y5TOR5G5B5(31) - }; - unsigned short* dp = (unsigned short*) dxpixels; - const unsigned char* sp = (const unsigned char*) glpixels; - int numPixels = height * width; - int i = numPixels >> 2; - while(i > 0) { - *dp++ = table[(*sp++) >> 3]; - *dp++ = table[(*sp++) >> 3]; - *dp++ = table[(*sp++) >> 3]; - *dp++ = table[(*sp++) >> 3]; - --i; - } - - i = numPixels & 3; - while(i > 0) { - *dp++ = table[(*sp++) >> 3]; - --i; - } - } - break; - case 3: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const unsigned char* sp = (const unsigned char*) glpixels + (y*width+x)*4; - unsigned short v; - v = (sp[2] >> 3); // blue - v |= (sp[1] >> 3) << 5; // green - v |= (sp[0] >> 3) << 10; // red - v |= 0x8000; // alpha - *dp = v; - } - } - } - break; - case 4: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const unsigned char* sp = (const unsigned char*) glpixels + (y*width+x)*4; - unsigned short v; - v = (sp[2] >> 3); // blue - v |= (sp[1] >> 3) << 5; // green - v |= (sp[0] >> 3) << 10; // red - v |= 0x8000; // alpha - *dp = v; - } - } - } - break; - } - *compatablePixels = dxpixels; - if ( newPitch ) { - *newPitch = 2 * width; - } - } - break; - case D3DX_SF_A1R5G5B5: - { - int textureElementSize = 2; - const char* glpixels = (const char*) pixels; - char* dxpixels = StickyAlloc(textureElementSize * width * height); - switch ( internalformat ) { - default: - LocalDebugBreak(); - break; - case 1: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const char* sp = glpixels + (y*width+x); - unsigned short v; - v = (0x1f & (sp[0] >> 3)); // blue - v |= (0x1f & (sp[0] >> 3)) << 5; // green - v |= (0x1f & (sp[0] >> 3)) << 10; // red - v |= (0x01 & (sp[0] >> 7)) << 15; // alpha - *dp = v; - } - } - } - break; - case 3: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const char* sp = glpixels + (y*width+x)*4; - unsigned short v; - v = (0x1f & (sp[2] >> 3)); // blue - v |= (0x1f & (sp[1] >> 3)) << 5; // green - v |= (0x1f & (sp[0] >> 3)) << 10; // red - v |= 0x8000; // alpha - *dp = v; - } - } - } - break; - case 4: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned short* dp = (unsigned short*) (dxpixels + (y*width+x)*textureElementSize); - const char* sp = glpixels + (y*width+x)*4; - unsigned short v; - v = (0x1f & (sp[2] >> 3)); // blue - v |= (0x1f & (sp[1] >> 3)) << 5; // green - v |= (0x1f & (sp[0] >> 3)) << 10; // red - v |= (0x01 & (sp[3] >> 7)) << 15; // alpha - *dp = v; - } - } - } - break; - } - *compatablePixels = dxpixels; - if ( newPitch ) { - *newPitch = 2 * width; - } - } - break; - case D3DX_SF_X8R8G8B8: - case D3DX_SF_A8R8G8B8: - { - int textureElementSize = 4; - const char* glpixels = (const char*) pixels; - char* dxpixels = StickyAlloc(textureElementSize * width * height); - switch ( internalformat ) { - default: - LocalDebugBreak(); - break; - case 1: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - char* dp = dxpixels + (y*width+x)*textureElementSize; - const char* sp = glpixels + (y*width+x); - dp[0] = sp[0]; // blue - dp[1] = sp[0]; // green - dp[2] = sp[0]; // red - dp[3] = sp[0]; - } - } - } - break; - case 3: - if (format == GL_RGB) - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned char* dp = (unsigned char*) dxpixels + (y*width+x)*textureElementSize; - const unsigned char* sp = (unsigned char*) glpixels + (y*width+x)*3; - dp[0] = sp[2]; // blue - dp[1] = sp[1]; // green - dp[2] = sp[0]; // red - dp[3] = 0xff; - } - } - } - else - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - unsigned char* dp = (unsigned char*) dxpixels + (y*width+x)*textureElementSize; - const unsigned char* sp = (unsigned char*) glpixels + (y*width+x)*4; - dp[0] = sp[2]; // blue - dp[1] = sp[1]; // green - dp[2] = sp[0]; // red - dp[3] = 0xff; - } - } - } - break; - case 4: - { - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++){ - char* dp = dxpixels + (y*width+x)*textureElementSize; - const char* sp = glpixels + (y*width+x)*4; - dp[0] = sp[2]; // blue - dp[1] = sp[1]; // green - dp[2] = sp[0]; // red - dp[3] = sp[3]; // alpha - } - } - } - break; - } - *compatablePixels = dxpixels; - if ( newPitch ) { - *newPitch = 4 * width; - } - } - } - - return hr; - } -}; - -#pragma warning( pop ) - -// TODO Fix this warning instead of disableing it -#pragma warning(disable:4273) - -void APIENTRY D3DAlphaFunc (GLenum func, GLclampf ref){ - gFakeGL->cglAlphaFunc(func, ref); -} - -void APIENTRY D3DBegin (GLenum mode){ - gFakeGL->cglBegin(mode); -} - -void APIENTRY D3DBlendFunc (GLenum sfactor, GLenum dfactor){ - gFakeGL->cglBlendFunc(sfactor, dfactor); -} - -void APIENTRY D3DClear (GLbitfield mask){ - gFakeGL->cglClear(mask); -} - -void APIENTRY D3DClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){ - gFakeGL->cglClearColor(red, green, blue, alpha); -} - -void APIENTRY D3DColor3f (GLfloat red, GLfloat green, GLfloat blue){ - if (red > 1) red = 1; - if (green > 1) green = 1; - if (blue > 1) blue = 1; - if (red < 0) red = 0; - if (green < 0) green = 0; - if (blue < 0) blue = 0; - gFakeGL->cglColor3f(red, green, blue); -} - -void APIENTRY D3DColor3ubv (const GLubyte *v){ - gFakeGL->cglColor3ubv(v); -} -void APIENTRY D3DColor3ub (GLubyte v1, GLubyte v2, GLubyte v3) -{ - gFakeGL->cglColor3f(v1/255.0, v2/255.0, v3/255.0); -} -void APIENTRY D3DColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha){ - if (red>1) red = 1; - if (green>1) green = 1; - if (blue>1) blue = 1; - if (alpha>1) alpha = 1; - if (red < 0) red = 0; - if (green < 0) green = 0; - if (blue < 0) blue = 0; - if (alpha < 0) alpha = 0; - gFakeGL->cglColor4f(red, green, blue, alpha); -} - -void APIENTRY D3DColor4fv (const GLfloat *v){ - gFakeGL->cglColor4fv(v); -} - -void APIENTRY D3DColor4ubv (const GLubyte *v) //no bounds checking needed -{ - gFakeGL->cglColor4f(v[0]/255.0, v[1]/255.0, v[2]/255.0, v[3]/255.0); -} -void APIENTRY D3DColor4ub (GLubyte v1, GLubyte v2, GLubyte v3, GLubyte v4) -{ - gFakeGL->cglColor4f(v1/255.0, v2/255.0, v3/255.0, v4/255.0); -} - -void APIENTRY D3DCullFace (GLenum mode){ - gFakeGL->cglCullFace(mode); -} - -void APIENTRY D3DDepthFunc (GLenum func){ - gFakeGL->cglDepthFunc(func); -} - -void APIENTRY D3DDepthMask (GLboolean flag){ - gFakeGL->cglDepthMask(flag); -} - -void APIENTRY D3DDepthRange (GLclampd zNear, GLclampd zFar){ - gFakeGL->cglDepthRange(zNear, zFar); -} - -void APIENTRY D3DDisable (GLenum cap){ - gFakeGL->cglDisable(cap); -} - -void APIENTRY D3DDrawBuffer (GLenum mode){ - gFakeGL->cglDrawBuffer(mode); -} - -void APIENTRY D3DEnable (GLenum cap){ - gFakeGL->cglEnable(cap); -} - -void APIENTRY D3DEnd (void){ - return; // Does nothing -// gFakeGL->glEnd(); -} - -void APIENTRY D3DFinish (void){ - gFakeGL->cglFinish(); -} - -void APIENTRY D3DFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){ - gFakeGL->cglFrustum(left, right, bottom, top, zNear, zFar); -} - -void APIENTRY D3DGetFloatv (GLenum pname, GLfloat *params){ - gFakeGL->cglGetFloatv(pname, params); -} - -const GLubyte * APIENTRY D3DGetString (GLenum name){ - return gFakeGL->cglGetString(name); -} - -void APIENTRY D3DHint (GLenum target, GLenum mode){ - gFakeGL->cglHint(target, mode); -} - -void APIENTRY D3DLoadIdentity (void){ - gFakeGL->cglLoadIdentity(); -} - -void APIENTRY D3DLoadMatrixf (const GLfloat *m){ - gFakeGL->cglLoadMatrixf(m); -} - -void APIENTRY D3DMatrixMode (GLenum mode){ - gFakeGL->cglMatrixMode(mode); -} - -void APIENTRY D3DOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){ - gFakeGL->cglOrtho(left, right, top, bottom, zNear, zFar); -} - -void APIENTRY D3DPolygonMode (GLenum face, GLenum mode){ - gFakeGL->cglPolygonMode(face, mode); -} - -void APIENTRY D3DPopMatrix (void){ - gFakeGL->cglPopMatrix(); -} - -void APIENTRY D3DPushMatrix (void){ - gFakeGL->cglPushMatrix(); -} - -void APIENTRY D3DReadBuffer (GLenum mode){ - gFakeGL->cglReadBuffer(mode); -} - -void APIENTRY D3DReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels){ - gFakeGL->cglReadPixels(x, y, width, height, format, type, pixels); -} - -void APIENTRY D3DRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z){ - gFakeGL->cglRotatef(angle, x, y, z); -} - -void APIENTRY D3DScalef (GLfloat x, GLfloat y, GLfloat z){ - gFakeGL->cglScalef(x, y, z); -} - -void APIENTRY D3DShadeModel (GLenum mode){ - gFakeGL->cglShadeModel(mode); -} - -void APIENTRY D3DTexCoord2f (GLfloat s, GLfloat t){ - gFakeGL->cglTexCoord2f(s, t); -} - -void APIENTRY D3DTexEnvf (GLenum target, GLenum pname, GLfloat param){ - gFakeGL->cglTexEnvf(target, pname, param); -} - -void APIENTRY D3DTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels){ - gFakeGL->cglTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); -} - -void APIENTRY D3DTexParameterf (GLenum target, GLenum pname, GLfloat param){ - gFakeGL->cglTexParameterf(target, pname, param); -} - -void APIENTRY D3DTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels){ - gFakeGL->cglTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); -} - -void APIENTRY D3DTranslatef (GLfloat x, GLfloat y, GLfloat z){ - gFakeGL->cglTranslatef(x, y, z); -} - -void APIENTRY D3DVertex2f (GLfloat x, GLfloat y){ - gFakeGL->cglVertex2f(x, y); -} - -void APIENTRY D3DVertex3f (GLfloat x, GLfloat y, GLfloat z){ - gFakeGL->cglVertex3f(x, y, z); -} - -void APIENTRY D3DVertex3fv (const GLfloat *v){ - gFakeGL->cglVertex3fv(v); -} - -void APIENTRY D3DViewport (GLint x, GLint y, GLsizei width, GLsizei height){ - gFakeGL->cglViewport(x, y, width, height); -} - - -int APIENTRY D3DGetError (void) -{ - return 0; -} - -HDC gHDC; -HGLRC gHGLRC; - -extern "C" { - -extern HWND mainwindow; - -}; - - -HGLRC WINAPI D3DwglCreateContext(HDC /* hdc */){ - return (HGLRC) new FakeGL(mainwindow); -} - -BOOL WINAPI D3DwglDeleteContext(HGLRC hglrc){ - FakeGL* fgl = (FakeGL*) hglrc; - delete fgl; - return true; -} - -HGLRC WINAPI D3DwglGetCurrentContext(VOID){ - return gHGLRC; -} - -HDC WINAPI D3DwglGetCurrentDC(VOID){ - return gHDC; -} - -static void APIENTRY D3DBindTextureExt(GLenum target, GLuint texture){ - gFakeGL->cglBindTexture(target, texture); -} - -static void APIENTRY D3DMTexCoord2fSGIS(GLenum target, GLfloat s, GLfloat t){ - gFakeGL->cglMTexCoord2fSGIS(target, s, t); -} - -static void APIENTRY D3DSelectTextureSGIS(GLenum target){ - gFakeGL->cglSelectTextureSGIS(target); -} - -// type cast unsafe conversion from -#pragma warning( push ) -#pragma warning( disable : 4191) - -typedef struct { - char *funcname; - PROC functionp; -} d3dglfunc_t; -extern d3dglfunc_t glfuncs[]; - -PROC WINAPI D3DwglGetProcAddress(LPCSTR s) -{ - int i; - static LPCSTR kBindTextureEXT = "glBindTextureEXT"; - static LPCSTR kMTexCoord2fSGIS = "glMTexCoord2fSGIS"; // Multitexture - static LPCSTR kSelectTextureSGIS = "glSelectTextureSGIS"; - if ( strcmp(s, kBindTextureEXT) == 0){ - return (PROC) D3DBindTextureExt; - } - else if ( strcmp(s, kMTexCoord2fSGIS) == 0){ - return (PROC) D3DMTexCoord2fSGIS; - } - else if ( strcmp(s, kSelectTextureSGIS) == 0){ - return (PROC) D3DSelectTextureSGIS; - } - for (i = 0; glfuncs[i].funcname; i++) - { - if (!strcmp(s, glfuncs[i].funcname)) - return glfuncs[i].functionp; - } - - // LocalDebugBreak(); - return 0; -} - -#pragma warning( pop ) - -BOOL WINAPI D3DwglMakeCurrent(HDC hdc, HGLRC hglrc){ - gHDC = hdc; - gHGLRC = hglrc; - gFakeGL = (FakeGL*) hglrc; - return TRUE; -} - -extern "C"{ - -void d3dSetMode(int fullscreen, int width, int height, int bpp, int zbpp); -void d3dEvictTextures(); -BOOL APIENTRY FakeSwapBuffers(HDC hdc); -void d3dSetGammaRamp(const unsigned char* gammaTable); -void d3dInitSetForce16BitTextures(int force16bitTextures); -void d3dHint_GenerateMipMaps(int value); -float d3dGetD3DDriverVersion(); -void D3DInitialize(void); -}; - -void d3dEvictTextures(){ - gFakeGL->EvictTextures(); -} - -void d3dSetMode(int fullscreen, int width, int height, int bpp, int zbpp){ - gFullScreen = fullscreen != 0; - gWidth = width; - gHeight = height; - gBpp = bpp; - gZbpp = zbpp; -} - -BOOL APIENTRY FakeSwapBuffers(HDC hdc){ - if ( ! gFakeGL ) { - return false; - } - gFakeGL->SwapBuffers(); - - return true; -} - -void d3dSetGammaRamp(const unsigned char* gammaTable){ - gFakeGL->SetGammaRamp(gammaTable); -} - -void d3dInitSetForce16BitTextures(int force16bitTextures){ - // called before gFakeGL exits. That's why we set a global - g_force16bitTextures = force16bitTextures != 0; -} - -void d3dHint_GenerateMipMaps(int value){ - gFakeGL->Hint_GenerateMipMaps(value); -} - -float d3dGetD3DDriverVersion(){ - return 0.73f; -} - -void APIENTRY D3DTexCoord2fv(const GLfloat *f) -{ - D3DTexCoord2f(f[0], f[1]); -} -void APIENTRY D3DTexCoord1f(GLfloat f) -{ - D3DTexCoord2f(f, f); -} -void APIENTRY D3DTexParameteri (GLenum target, GLenum pname, GLint param) -{ - D3DTexParameterf(target, pname, param); -} -void APIENTRY D3DTexEnvi (GLenum target, GLenum pname, GLint param) -{ - D3DTexEnvf(target, pname, param); -} -void APIENTRY D3DMultMatrixf (const GLfloat *m) -{ - gFakeGL->cglMultMatrixf(m); -} - -void APIENTRY D3DNormal3f(GLfloat x, GLfloat y, GLfloat z) -{} -void APIENTRY D3DNormal3fv (const GLfloat *v) -{D3DNormal3f(v[0], v[1], v[2]);} -void APIENTRY D3DFogf (GLenum pname, GLfloat param) -{} -void APIENTRY D3DFogi (GLenum pname, GLint param) -{} -void APIENTRY D3DFogfv (GLenum pname, const GLfloat *params) -{} -void APIENTRY D3DGetIntegerv (GLenum pname, GLint *params) -{ - switch(pname) - { - case GL_MAX_TEXTURE_SIZE: - params[0]=2048; - break; - case GL_MAX_TEXTURE_UNITS_ARB: - params[0]=2; - break; - default: - Sys_Error("Bad D3DGetIntegerv\n"); - } -} -void APIENTRY D3DNewList (GLuint list, GLenum mode) -{} -void APIENTRY D3DEndList (void) -{} -void APIENTRY D3DCallList (GLuint list) -{} -void APIENTRY D3DTexGeni (GLenum coord, GLenum pname, GLint param) -{} - - - -int texarraystride; -bool texarrayenabled; -const float *texarray; - -int vertarraystride; -bool vertarrayenabled; -const float *vertarray; - -bool colourarrayenabled; -int colourarraystride; -const qbyte *colourarray; - -void APIENTRY D3DDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) -{ - int *index; - if (!texarrayenabled || !vertarrayenabled) - return; //please explain? - - D3DBegin(mode); - if (colourarrayenabled) - { - for (index = (int*)indices; count--; index++) - { - D3DTexCoord2fv(texarray + *index*texarraystride); - D3DColor4ubv(colourarray + *index*colourarraystride); - D3DVertex3fv(vertarray + *index*vertarraystride); - } - - } - else - { - for (index = (int*)indices; count--; index++) - { - D3DTexCoord2fv(texarray + *index*texarraystride); - D3DVertex3fv(vertarray + *index*vertarraystride); - } - } - D3DEnd(); -} -void APIENTRY D3DVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) -{ - vertarray = (float *)pointer; - if (size != 3 || type != GL_FLOAT || (stride%4)) - Sys_Error("D3DVertexPointer is limited"); - - if (!stride) - stride = sizeof(float)*size; - - vertarraystride = stride/4; -} -void APIENTRY D3DTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) -{ - texarray = (float *)pointer; - if (size != 2 || type != GL_FLOAT || (stride%4)) - Sys_Error("D3DTexCoordPointer is limited"); - - if (!stride) - stride = sizeof(float)*size; - - texarraystride = stride/4; -} -void APIENTRY D3DColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) -{ - colourarray = (qbyte *)pointer; - if (size != 4 || type != GL_UNSIGNED_BYTE || (stride%4)) - Sys_Error("D3DColourPointer is limited"); - - if (!stride) - stride = sizeof(float)*size; - - colourarraystride = stride/4; -} -void APIENTRY D3DEnableClientState(unsigned int e) -{ - switch(e) - { - case GL_TEXTURE_COORD_ARRAY: - texarrayenabled = true; - break; - case GL_COLOR_ARRAY: - colourarrayenabled = true; - break; - case GL_VERTEX_ARRAY: - vertarrayenabled = true; - break; - } -} -void APIENTRY D3DDisableClientState(unsigned int e) -{ - switch(e) - { - case GL_TEXTURE_COORD_ARRAY: - texarrayenabled = false; - break; - case GL_COLOR_ARRAY: - colourarrayenabled = false; - break; - case GL_VERTEX_ARRAY: - vertarrayenabled = false; - break; - } -} - - - - -#if 1 - -#pragma comment(lib, "../libs/dxsdk7/lib/ddraw.lib") -#pragma comment(lib, "../libs/dxsdk7/lib/d3dx.lib") - -#else -HMODULE ddrawdll; -#endif - -void D3DInitialize(void) -{ -#if 1 - qD3DXMatrixScaling = D3DXMatrixScaling; - qD3DXGetErrorString = D3DXGetErrorString; - qD3DXMatrixPerspectiveOffCenter = D3DXMatrixPerspectiveOffCenter; - qD3DXMatrixOrthoOffCenter = D3DXMatrixOrthoOffCenter; - qD3DXInitialize = D3DXInitialize; - qD3DXUninitialize = D3DXUninitialize; - qD3DXCreateContextEx = D3DXCreateContextEx; - qD3DXCreateMatrixStack = D3DXCreateMatrixStack; - qD3DXCheckTextureRequirements = D3DXCheckTextureRequirements; - qD3DXMakeDDPixelFormat = D3DXMakeDDPixelFormat; - qD3DXMatrixTranslation = D3DXMatrixTranslation; -#else - if (!ddrawdll) - ddrawdll = LoadLibrary("d3drm.dll"); //yeah, right, these are staticly linked. DLLS get speed hits. - qD3DXMatrixScaling = (qD3DXMatrixScaling_t) GetProcAddress(ddrawdll, "D3DXMatrixScaling"); - qD3DXGetErrorString = (qD3DXGetErrorString_t) GetProcAddress(ddrawdll, "D3DXGetErrorString"); - qD3DXMatrixPerspectiveOffCenter = (qD3DXMatrixPerspectiveOffCenter_t) GetProcAddress(ddrawdll, "D3DXMatrixPerspectiveOffCenter"); - qD3DXMatrixOrthoOffCenter = (qD3DXMatrixOrthoOffCenter_t) GetProcAddress(ddrawdll, "D3DXMatrixOrthoOffCenter"); - qD3DXInitialize = (qD3DXInitialize_t) GetProcAddress(ddrawdll, "D3DXInitialize"); - qD3DXUninitialize = (qD3DXUninitialize_t) GetProcAddress(ddrawdll, "D3DXUninitialize"); - qD3DXCreateContextEx = (qD3DXCreateContextEx_t) GetProcAddress(ddrawdll, "D3DXCreateContextEx"); - qD3DXCreateMatrixStack = (qD3DXCreateMatrixStack_t) GetProcAddress(ddrawdll, "D3DXCreateMatrixStack"); - qD3DXCheckTextureRequirements = (qD3DXCheckTextureRequirements_t) GetProcAddress(ddrawdll, "D3DXCheckTextureRequirements"); - qD3DXMakeDDPixelFormat = (qD3DXMakeDDPixelFormat_t) GetProcAddress(ddrawdll, "D3DXMakeDDPixelFormat"); - qD3DXMatrixTranslation = (qD3DXMatrixTranslation_t) GetProcAddress(ddrawdll, "D3DXMatrixTranslation"); -#endif - - if (!qD3DXCreateMatrixStack || !qD3DXMatrixScaling || !qD3DXMatrixTranslation || !qD3DXMatrixPerspectiveOffCenter - || !qD3DXMatrixOrthoOffCenter || !qD3DXGetErrorString || !qD3DXInitialize || !qD3DXUninitialize - || !qD3DXCreateContextEx || !qD3DXCheckTextureRequirements || !qD3DXMakeDDPixelFormat) - Sys_Error("You don't have directx 7"); -/* - qglAlphaFunc = D3DAlphaFunc; - qglBegin = D3DBegin; - qglBlendFunc = D3DBlendFunc; - qglClear = D3DClear; - qglClearColor = D3DClearColor; - qglColor3f = D3DColor3f; - qglColor3ub = D3DColor3ub; - qglColor4f = D3DColor4f; - qglColor4fv = D3DColor4fv; - qglColor4ub = D3DColor4ub; - qglColor4ubv = D3DColor4ubv; - qglCullFace = D3DCullFace; - qglDepthFunc = D3DDepthFunc; - qglDepthMask = D3DDepthMask; - qglDepthRange = D3DDepthRange; - qglDisable = D3DDisable; - qglDrawBuffer = D3DDrawBuffer; - qglEnable = D3DEnable; - qglEnd = D3DEnd; - qglFinish = D3DFinish; - qglFrustum = D3DFrustum; - qglGetFloatv = D3DGetFloatv; - qglGetIntegerv = D3DGetIntegerv; - qglGetString = D3DGetString; - qglHint = D3DHint; - qglLoadIdentity = D3DLoadIdentity; - qglLoadMatrixf = D3DLoadMatrixf; - qglNormal3f = D3DNormal3f; - qglNormal3fv = D3DNormal3fv; - qglMatrixMode = D3DMatrixMode; - qglMultMatrixf = D3DMultMatrixf; - qglOrtho = D3DOrtho; - qglPolygonMode = D3DPolygonMode; - qglPopMatrix = D3DPopMatrix; - qglPushMatrix = D3DPushMatrix; - qglReadBuffer = D3DReadBuffer; - qglReadPixels = D3DReadPixels; - qglRotatef = D3DRotatef; - qglScalef = D3DScalef; - qglShadeModel = D3DShadeModel; - qglTexCoord1f = D3DTexCoord1f; - qglTexCoord2f = D3DTexCoord2f; - qglTexCoord2fv = D3DTexCoord2fv; - qglTexEnvf = D3DTexEnvf; - qglTexEnvi = D3DTexEnvi; - qglTexGeni = D3DTexGeni; - qglTexImage2D = D3DTexImage2D; - qglTexParameteri = D3DTexParameteri; - qglTexParameterf = D3DTexParameterf; - qglTexSubImage2D = D3DTexSubImage2D; - qglTranslatef = D3DTranslatef; - qglVertex2f = D3DVertex2f; - qglVertex3f = D3DVertex3f; - qglVertex3fv = D3DVertex3fv; - qglViewport = D3DViewport; - - qglDrawElements = D3DDrawElements; - qglVertexPointer = D3DVertexPointer; - qglTexCoordPointer = D3DTexCoordPointer; - qglEnableClientState = D3DEnableClientState; - qglDisableClientState = D3DDisableClientState; -*/ - qwglCreateContext = D3DwglCreateContext; - qwglDeleteContext = D3DwglDeleteContext; - qwglGetCurrentContext = D3DwglGetCurrentContext; - qwglGetCurrentDC = D3DwglGetCurrentDC; - qwglGetProcAddress = D3DwglGetProcAddress; - qwglMakeCurrent = D3DwglMakeCurrent; - qSwapBuffers = FakeSwapBuffers; -} - - - - -d3dglfunc_t glfuncs[] = { - {"glAlphaFunc", (PROC)D3DAlphaFunc}, - {"glBegin", (PROC)D3DBegin}, - {"glBlendFunc", (PROC)D3DBlendFunc}, - {"glClear", (PROC)D3DClear}, - {"glClearColor", (PROC)D3DClearColor}, - {"glClearDepth", NULL}, - {"glClearStencil", NULL}, - {"glColor3f", (PROC)D3DColor3f}, - {"glColor3ub", (PROC)D3DColor3ub}, - {"glColor4f", (PROC)D3DColor4f}, - {"glColor4fv", (PROC)D3DColor4fv}, - {"glColor4ub", (PROC)D3DColor4ub}, - {"glColor4ubv", (PROC)D3DColor4ubv}, - {"glColorMask", NULL},//(PROC)D3DColorMask}, - {"glCullFace", (PROC)D3DCullFace}, - {"glDepthFunc", (PROC)D3DDepthFunc}, - {"glDepthMask", (PROC)D3DDepthMask}, - {"glDepthRange", (PROC)D3DDepthRange}, - {"glDisable", (PROC)D3DDisable}, - {"glDrawBuffer", (PROC)D3DDrawBuffer}, - {"glDrawPixels", NULL},//(PROC)D3DDrawPixels}, - {"glEnable", (PROC)D3DEnable}, - {"glEnd", (PROC)D3DEnd}, - {"glFlush", NULL},//(PROC)D3DFlush}, - {"glFinish", (PROC)D3DFinish}, - {"glFrustum", (PROC)D3DFrustum}, - {"glGetFloatv", (PROC)D3DGetFloatv}, - {"glGetIntegerv", (PROC)D3DGetIntegerv}, - {"glGetString", (PROC)D3DGetString}, - - - - {"glHint", (PROC)D3DHint}, - {"glLoadIdentity", (PROC)D3DLoadIdentity}, - {"glLoadMatrixf", (PROC)D3DLoadMatrixf}, - {"glNormal3f", (PROC)D3DNormal3f}, - {"glNormal3fv", (PROC)D3DNormal3fv}, - {"glMatrixMode", (PROC)D3DMatrixMode}, - {"glMultMatrixf", (PROC)D3DMultMatrixf}, - {"glOrtho", (PROC)D3DOrtho}, - {"glPolygonMode", (PROC)D3DPolygonMode}, - {"glPopMatrix", (PROC)D3DPopMatrix}, - {"glPushMatrix", (PROC)D3DPushMatrix}, - {"glReadBuffer", (PROC)D3DReadBuffer}, - {"glReadPixels", (PROC)D3DReadPixels}, - {"glRotatef", (PROC)D3DRotatef}, - {"glScalef", (PROC)D3DScalef}, - {"glShadeModel", (PROC)D3DShadeModel}, - {"glTexCoord1f", (PROC)D3DTexCoord1f}, - {"glTexCoord2f", (PROC)D3DTexCoord2f}, - {"glTexCoord2fv", (PROC)D3DTexCoord2fv}, - {"glTexEnvf", (PROC)D3DTexEnvf}, - {"glTexEnvi", (PROC)D3DTexEnvi}, - {"glTexGeni", (PROC)D3DTexGeni}, - {"glTexImage2D", (PROC)D3DTexImage2D}, - {"glTexParameteri", (PROC)D3DTexParameteri}, - {"glTexParameterf", (PROC)D3DTexParameterf}, - {"glTexSubImage2D", (PROC)D3DTexSubImage2D}, - {"glTranslatef", (PROC)D3DTranslatef}, - {"glVertex2f", (PROC)D3DVertex2f}, - {"glVertex3f", (PROC)D3DVertex3f}, - {"glVertex3fv", (PROC)D3DVertex3fv}, - {"glViewport", (PROC)D3DViewport}, - - {"glDrawElements", (PROC)D3DDrawElements}, - {"glVertexPointer", (PROC)D3DVertexPointer}, - {"glTexCoordPointer", (PROC)D3DTexCoordPointer}, - {"glColorPointer", (PROC)D3DColorPointer}, - {"glEnableClientState", (PROC)D3DEnableClientState}, - {"glDisableClientState", (PROC)D3DDisableClientState}, - - {"glGetError", (PROC)D3DGetError}, -/* - qwglCreateContext = D3DwglCreateContext; - qwglDeleteContext = D3DwglDeleteContext; - qwglGetCurrentContext = D3DwglGetCurrentContext; - qwglGetCurrentDC = D3DwglGetCurrentDC; - qwglGetProcAddress = D3DwglGetProcAddress; - qwglMakeCurrent = D3DwglMakeCurrent; - qSwapBuffers = FakeSwapBuffers;*/ - {NULL} -}; - - -static qboolean D3DVID_Init(rendererstate_t *info, unsigned char *palette) -{ - strcpy(info->glrenderer, "D3D"); - return GLVID_Init(info, palette); -} - -extern "C" { -#include "gl_draw.h" -} - -rendererinfo_t d3dfglrendererinfo = { - "Direct3D Wrapper", - { - "faked3d", - "crap" - }, - QR_OPENGL, - - - R2D_SafePicFromWad, - R2D_SafeCachePic, - GLDraw_Init, - GLDraw_ReInit, - GLDraw_Crosshair, - R2D_ScalePic, - R2D_SubPic, - GLDraw_TransPicTranslate, - R2D_ConsoleBackground, - R2D_EditorBackground, - R2D_TileClear, - GLDraw_Fill, - GLDraw_FillRGB, - GLDraw_FadeScreen, - GLDraw_BeginDisc, - GLDraw_EndDisc, - - R2D_Image, - R2D_ImageColours, - - GL_LoadTextureFmt, - GL_LoadTexture8Pal24, - GL_LoadTexture8Pal32, - GL_LoadCompressed, - GL_FindTexture, - GL_AllocNewTexture, - GL_UploadFmt, - GL_DestroyTexture, - - GLR_Init, - GLR_DeInit, - GLR_RenderView, - - - GLR_NewMap, - GLR_PreNewMap, - GLR_LightPoint, - - - Surf_AddStain, - Surf_LessenStains, - - RMod_Init, - RMod_ClearAll, - RMod_ForName, - RMod_FindName, - RMod_Extradata, - RMod_TouchModel, - - RMod_NowLoadExternal, - RMod_Think, - - Mod_GetTag, - Mod_TagNumForName, - Mod_SkinNumForName, - Mod_FrameNumForName, - Mod_FrameDuration, - - D3DVID_Init, - GLVID_DeInit, - GLVID_SetPalette, - GLVID_ShiftPalette, - GLVID_GetRGBInfo, - - GLVID_SetCaption, //setcaption - - - GLSCR_UpdateScreen, - - /*backend*/ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - - "" -}; -extern "C" { -rendererinfo_t *pd3dfglrendererinfo = &d3dfglrendererinfo; -} - -#endif - -#endif -