<ClCompile Include="csprogs.c" />\r
<ClCompile Include="curves.c" />\r
<ClCompile Include="cvar.c" />\r
- <ClCompile Include="dpsoftrast.c" />\r
<ClCompile Include="dpvsimpledecode.c" />\r
<ClCompile Include="filematch.c" />\r
<ClCompile Include="fractalnoise.c" />\r
<ClInclude Include="csprogs.h" />\r
<ClInclude Include="curves.h" />\r
<ClInclude Include="cvar.h" />\r
- <ClInclude Include="dpsoftrast.h" />\r
<ClInclude Include="dpvsimpledecode.h" />\r
<ClInclude Include="draw.h" />\r
<ClInclude Include="fs.h" />\r
<ClInclude Include="screen.h" />\r
<ClInclude Include="server.h" />\r
<ClInclude Include="shader_glsl.h" />\r
- <ClInclude Include="shader_hlsl.h" />\r
<ClInclude Include="snd_main.h" />\r
<ClInclude Include="snd_ogg.h" />\r
<ClInclude Include="snd_wav.h" />\r
<ClCompile Include="csprogs.c" />\r
<ClCompile Include="curves.c" />\r
<ClCompile Include="cvar.c" />\r
- <ClCompile Include="dpsoftrast.c" />\r
<ClCompile Include="dpvsimpledecode.c" />\r
<ClCompile Include="filematch.c" />\r
<ClCompile Include="fractalnoise.c" />\r
<ClInclude Include="csprogs.h" />\r
<ClInclude Include="curves.h" />\r
<ClInclude Include="cvar.h" />\r
- <ClInclude Include="dpsoftrast.h" />\r
<ClInclude Include="dpvsimpledecode.h" />\r
<ClInclude Include="draw.h" />\r
<ClInclude Include="fs.h" />\r
<ClInclude Include="SDLMain.h" />\r
<ClInclude Include="server.h" />\r
<ClInclude Include="shader_glsl.h" />\r
- <ClInclude Include="shader_hlsl.h" />\r
<ClInclude Include="snd_main.h" />\r
<ClInclude Include="snd_ogg.h" />\r
<ClInclude Include="snd_wav.h" />\r
<ClCompile Include="csprogs.c" />\r
<ClCompile Include="curves.c" />\r
<ClCompile Include="cvar.c" />\r
- <ClCompile Include="dpsoftrast.c" />\r
<ClCompile Include="dpvsimpledecode.c" />\r
<ClCompile Include="filematch.c" />\r
<ClCompile Include="fractalnoise.c" />\r
<ClInclude Include="csprogs.h" />\r
<ClInclude Include="curves.h" />\r
<ClInclude Include="cvar.h" />\r
- <ClInclude Include="dpsoftrast.h" />\r
<ClInclude Include="dpvsimpledecode.h" />\r
<ClInclude Include="draw.h" />\r
<ClInclude Include="fs.h" />\r
<ClInclude Include="screen.h" />\r
<ClInclude Include="server.h" />\r
<ClInclude Include="shader_glsl.h" />\r
- <ClInclude Include="shader_hlsl.h" />\r
<ClInclude Include="snd_main.h" />\r
<ClInclude Include="snd_ogg.h" />\r
<ClInclude Include="snd_wav.h" />\r
-#include <stdio.h>
-#include <string.h>
-#define _USE_MATH_DEFINES
-#include <math.h>
-#include "quakedef.h"
-#include "thread.h"
-#include "dpsoftrast.h"
-
-#ifdef _MSC_VER
-#pragma warning(disable : 4324)
-#endif
-
-#ifndef __cplusplus
-typedef qboolean bool;
-#endif
-
-#define ALIGN_SIZE 16
-#define ATOMIC_SIZE 4
-
-#ifdef SSE_POSSIBLE
- #if defined(__APPLE__)
- #include <libkern/OSAtomic.h>
- #define ALIGN(var) var __attribute__((__aligned__(16)))
- #define ATOMIC(var) var __attribute__((__aligned__(4)))
- #define MEMORY_BARRIER (_mm_sfence())
- #define ATOMIC_COUNTER volatile int32_t
- #define ATOMIC_INCREMENT(counter) (OSAtomicIncrement32Barrier(&(counter)))
- #define ATOMIC_DECREMENT(counter) (OSAtomicDecrement32Barrier(&(counter)))
- #define ATOMIC_ADD(counter, val) ((void)OSAtomicAdd32Barrier((val), &(counter)))
- #elif defined(__GNUC__) && defined(WIN32)
- #define ALIGN(var) var __attribute__((__aligned__(16)))
- #define ATOMIC(var) var __attribute__((__aligned__(4)))
- #define MEMORY_BARRIER (_mm_sfence())
- //(__sync_synchronize())
- #define ATOMIC_COUNTER volatile LONG
- // this LONG * cast serves to fix an issue with broken mingw
- // packages on Ubuntu; these only declare the function to take
- // a LONG *, causing a compile error here. This seems to be
- // error- and warn-free on platforms that DO declare
- // InterlockedIncrement correctly, like mingw on Windows.
- #define ATOMIC_INCREMENT(counter) (InterlockedIncrement((LONG *) &(counter)))
- #define ATOMIC_DECREMENT(counter) (InterlockedDecrement((LONG *) &(counter)))
- #define ATOMIC_ADD(counter, val) ((void)InterlockedExchangeAdd((LONG *) &(counter), (val)))
- #elif defined(__GNUC__)
- #define ALIGN(var) var __attribute__((__aligned__(16)))
- #define ATOMIC(var) var __attribute__((__aligned__(4)))
- #define MEMORY_BARRIER (_mm_sfence())
- //(__sync_synchronize())
- #define ATOMIC_COUNTER volatile int
- #define ATOMIC_INCREMENT(counter) (__sync_add_and_fetch(&(counter), 1))
- #define ATOMIC_DECREMENT(counter) (__sync_add_and_fetch(&(counter), -1))
- #define ATOMIC_ADD(counter, val) ((void)__sync_fetch_and_add(&(counter), (val)))
- #elif defined(_MSC_VER)
- #define ALIGN(var) __declspec(align(16)) var
- #define ATOMIC(var) __declspec(align(4)) var
- #define MEMORY_BARRIER (_mm_sfence())
- //(MemoryBarrier())
- #define ATOMIC_COUNTER volatile LONG
- #define ATOMIC_INCREMENT(counter) (InterlockedIncrement(&(counter)))
- #define ATOMIC_DECREMENT(counter) (InterlockedDecrement(&(counter)))
- #define ATOMIC_ADD(counter, val) ((void)InterlockedExchangeAdd(&(counter), (val)))
- #endif
-#endif
-
-#ifndef ALIGN
-#define ALIGN(var) var
-#endif
-#ifndef ATOMIC
-#define ATOMIC(var) var
-#endif
-#ifndef MEMORY_BARRIER
-#define MEMORY_BARRIER ((void)0)
-#endif
-#ifndef ATOMIC_COUNTER
-#define ATOMIC_COUNTER int
-#endif
-#ifndef ATOMIC_INCREMENT
-#define ATOMIC_INCREMENT(counter) (++(counter))
-#endif
-#ifndef ATOMIC_DECREMENT
-#define ATOMIC_DECREMENT(counter) (--(counter))
-#endif
-#ifndef ATOMIC_ADD
-#define ATOMIC_ADD(counter, val) ((void)((counter) += (val)))
-#endif
-
-#ifdef SSE_POSSIBLE
-#include <emmintrin.h>
-
-#if defined(__GNUC__) && (__GNUC < 4 || __GNUC_MINOR__ < 6) && !defined(__clang__)
- #define _mm_cvtss_f32(val) (__builtin_ia32_vec_ext_v4sf ((__v4sf)(val), 0))
-#endif
-
-#define MM_MALLOC(size) _mm_malloc(size, ALIGN_SIZE)
-
-static void *MM_CALLOC(size_t nmemb, size_t size)
-{
- void *ptr = _mm_malloc(nmemb*size, ALIGN_SIZE);
- if (ptr != NULL) memset(ptr, 0, nmemb*size);
- return ptr;
-}
-
-#define MM_FREE _mm_free
-#else
-#define MM_MALLOC(size) malloc(size)
-#define MM_CALLOC(nmemb, size) calloc(nmemb, size)
-#define MM_FREE free
-#endif
-
-typedef enum DPSOFTRAST_ARRAY_e
-{
- DPSOFTRAST_ARRAY_POSITION,
- DPSOFTRAST_ARRAY_COLOR,
- DPSOFTRAST_ARRAY_TEXCOORD0,
- DPSOFTRAST_ARRAY_TEXCOORD1,
- DPSOFTRAST_ARRAY_TEXCOORD2,
- DPSOFTRAST_ARRAY_TEXCOORD3,
- DPSOFTRAST_ARRAY_TEXCOORD4,
- DPSOFTRAST_ARRAY_TEXCOORD5,
- DPSOFTRAST_ARRAY_TEXCOORD6,
- DPSOFTRAST_ARRAY_TEXCOORD7,
- DPSOFTRAST_ARRAY_TOTAL
-}
-DPSOFTRAST_ARRAY;
-
-typedef struct DPSOFTRAST_Texture_s
-{
- int flags;
- int width;
- int height;
- int depth;
- int sides;
- DPSOFTRAST_TEXTURE_FILTER filter;
- int mipmaps;
- int size;
- ATOMIC_COUNTER binds;
- unsigned char *bytes;
- int mipmap[DPSOFTRAST_MAXMIPMAPS][5];
-}
-DPSOFTRAST_Texture;
-
-#define COMMAND_SIZE ALIGN_SIZE
-#define COMMAND_ALIGN(var) ALIGN(var)
-
-typedef COMMAND_ALIGN(struct DPSOFTRAST_Command_s
-{
- unsigned char opcode;
- unsigned short commandsize;
-}
-DPSOFTRAST_Command);
-
-enum { DPSOFTRAST_OPCODE_Reset = 0 };
-
-#define DEFCOMMAND(opcodeval, name, fields) \
- enum { DPSOFTRAST_OPCODE_##name = opcodeval }; \
- typedef COMMAND_ALIGN(struct DPSOFTRAST_Command_##name##_s \
- { \
- unsigned char opcode; \
- unsigned short commandsize; \
- fields \
- } DPSOFTRAST_Command_##name );
-
-#define DPSOFTRAST_DRAW_MAXCOMMANDPOOL 2097152
-#define DPSOFTRAST_DRAW_MAXCOMMANDSIZE 16384
-
-typedef ALIGN(struct DPSOFTRAST_State_Command_Pool_s
-{
- int freecommand;
- int usedcommands;
- ALIGN(unsigned char commands[DPSOFTRAST_DRAW_MAXCOMMANDPOOL]);
-}
-DPSOFTRAST_State_Command_Pool);
-
-typedef ALIGN(struct DPSOFTRAST_State_Triangle_s
-{
- unsigned char mip[DPSOFTRAST_MAXTEXTUREUNITS]; // texcoord to screen space density values (for picking mipmap of textures)
- float w[3];
- ALIGN(float attribs[DPSOFTRAST_ARRAY_TOTAL][3][4]);
-}
-DPSOFTRAST_State_Triangle);
-
-#define DPSOFTRAST_CALCATTRIB(triangle, span, data, slope, arrayindex) { \
- slope = _mm_load_ps((triangle)->attribs[arrayindex][0]); \
- data = _mm_add_ps(_mm_load_ps((triangle)->attribs[arrayindex][2]), \
- _mm_add_ps(_mm_mul_ps(_mm_set1_ps((span)->x), slope), \
- _mm_mul_ps(_mm_set1_ps((span)->y), _mm_load_ps((triangle)->attribs[arrayindex][1])))); \
-}
-#define DPSOFTRAST_CALCATTRIB4F(triangle, span, data, slope, arrayindex) { \
- slope[0] = (triangle)->attribs[arrayindex][0][0]; \
- slope[1] = (triangle)->attribs[arrayindex][0][1]; \
- slope[2] = (triangle)->attribs[arrayindex][0][2]; \
- slope[3] = (triangle)->attribs[arrayindex][0][3]; \
- data[0] = (triangle)->attribs[arrayindex][2][0] + (span->x)*slope[0] + (span->y)*(triangle)->attribs[arrayindex][1][0]; \
- data[1] = (triangle)->attribs[arrayindex][2][1] + (span->x)*slope[1] + (span->y)*(triangle)->attribs[arrayindex][1][1]; \
- data[2] = (triangle)->attribs[arrayindex][2][2] + (span->x)*slope[2] + (span->y)*(triangle)->attribs[arrayindex][1][2]; \
- data[3] = (triangle)->attribs[arrayindex][2][3] + (span->x)*slope[3] + (span->y)*(triangle)->attribs[arrayindex][1][3]; \
-}
-
-#define DPSOFTRAST_DRAW_MAXSUBSPAN 16
-
-typedef ALIGN(struct DPSOFTRAST_State_Span_s
-{
- int triangle; // triangle this span was generated by
- int x; // framebuffer x coord
- int y; // framebuffer y coord
- int startx; // usable range (according to pixelmask)
- int endx; // usable range (according to pixelmask)
- unsigned char *pixelmask; // true for pixels that passed depth test, false for others
- int depthbase; // depthbuffer value at x (add depthslope*startx to get first pixel's depthbuffer value)
- int depthslope; // depthbuffer value pixel delta
-}
-DPSOFTRAST_State_Span);
-
-#define DPSOFTRAST_DRAW_MAXSPANS 1024
-#define DPSOFTRAST_DRAW_MAXTRIANGLES 128
-#define DPSOFTRAST_DRAW_MAXSPANLENGTH 256
-
-#define DPSOFTRAST_VALIDATE_FB 1
-#define DPSOFTRAST_VALIDATE_DEPTHFUNC 2
-#define DPSOFTRAST_VALIDATE_BLENDFUNC 4
-#define DPSOFTRAST_VALIDATE_DRAW (DPSOFTRAST_VALIDATE_FB | DPSOFTRAST_VALIDATE_DEPTHFUNC | DPSOFTRAST_VALIDATE_BLENDFUNC)
-
-typedef enum DPSOFTRAST_BLENDMODE_e
-{
- DPSOFTRAST_BLENDMODE_OPAQUE,
- DPSOFTRAST_BLENDMODE_ALPHA,
- DPSOFTRAST_BLENDMODE_ADDALPHA,
- DPSOFTRAST_BLENDMODE_ADD,
- DPSOFTRAST_BLENDMODE_INVMOD,
- DPSOFTRAST_BLENDMODE_MUL,
- DPSOFTRAST_BLENDMODE_MUL2,
- DPSOFTRAST_BLENDMODE_SUBALPHA,
- DPSOFTRAST_BLENDMODE_PSEUDOALPHA,
- DPSOFTRAST_BLENDMODE_INVADD,
- DPSOFTRAST_BLENDMODE_TOTAL
-}
-DPSOFTRAST_BLENDMODE;
-
-typedef ALIGN(struct DPSOFTRAST_State_Thread_s
-{
- void *thread;
- int index;
-
- int cullface;
- int colormask[4];
- int blendfunc[2];
- int blendsubtract;
- int depthmask;
- int depthtest;
- int depthfunc;
- int scissortest;
- int viewport[4];
- int scissor[4];
- float depthrange[2];
- float polygonoffset[2];
- float clipplane[4];
- ALIGN(float fb_clipplane[4]);
-
- int shader_mode;
- dpuint64 shader_permutation;
- int shader_exactspecularmath;
-
- DPSOFTRAST_Texture *texbound[DPSOFTRAST_MAXTEXTUREUNITS];
-
- ALIGN(float uniform4f[DPSOFTRAST_UNIFORM_TOTAL*4]);
- int uniform1i[DPSOFTRAST_UNIFORM_TOTAL];
-
- // DPSOFTRAST_VALIDATE_ flags
- int validate;
-
- // derived values (DPSOFTRAST_VALIDATE_FB)
- int fb_colormask;
- int fb_scissor[4];
- ALIGN(float fb_viewportcenter[4]);
- ALIGN(float fb_viewportscale[4]);
-
- // derived values (DPSOFTRAST_VALIDATE_DEPTHFUNC)
- int fb_depthfunc;
-
- // derived values (DPSOFTRAST_VALIDATE_BLENDFUNC)
- int fb_blendmode;
-
- // band boundaries
- int miny1;
- int maxy1;
- int miny2;
- int maxy2;
-
- ATOMIC(volatile int commandoffset);
-
- volatile bool waiting;
- volatile bool starving;
- void *waitcond;
- void *drawcond;
- void *drawmutex;
-
- int numspans;
- int numtriangles;
- DPSOFTRAST_State_Span spans[DPSOFTRAST_DRAW_MAXSPANS];
- DPSOFTRAST_State_Triangle triangles[DPSOFTRAST_DRAW_MAXTRIANGLES];
- unsigned char pixelmaskarray[DPSOFTRAST_DRAW_MAXSPANLENGTH+4]; // LordHavoc: padded to allow some termination bytes
-}
-DPSOFTRAST_State_Thread);
-
-typedef ALIGN(struct DPSOFTRAST_State_s
-{
- int fb_width;
- int fb_height;
- unsigned int *fb_depthpixels;
- unsigned int *fb_colorpixels[4];
-
- int viewport[4];
- ALIGN(float fb_viewportcenter[4]);
- ALIGN(float fb_viewportscale[4]);
-
- float color[4];
- ALIGN(float uniform4f[DPSOFTRAST_UNIFORM_TOTAL*4]);
- int uniform1i[DPSOFTRAST_UNIFORM_TOTAL];
-
- const float *pointer_vertex3f;
- const float *pointer_color4f;
- const unsigned char *pointer_color4ub;
- const float *pointer_texcoordf[DPSOFTRAST_MAXTEXCOORDARRAYS];
- int stride_vertex;
- int stride_color;
- int stride_texcoord[DPSOFTRAST_MAXTEXCOORDARRAYS];
- int components_texcoord[DPSOFTRAST_MAXTEXCOORDARRAYS];
- DPSOFTRAST_Texture *texbound[DPSOFTRAST_MAXTEXTUREUNITS];
-
- int firstvertex;
- int numvertices;
- float *post_array4f[DPSOFTRAST_ARRAY_TOTAL];
- float *screencoord4f;
- int drawstarty;
- int drawendy;
- int drawclipped;
-
- int shader_mode;
- dpuint64 shader_permutation;
- int shader_exactspecularmath;
-
- int texture_max;
- int texture_end;
- int texture_firstfree;
- DPSOFTRAST_Texture *texture;
-
- int bigendian;
-
- // error reporting
- const char *errorstring;
-
- bool usethreads;
- int interlace;
- int numthreads;
- DPSOFTRAST_State_Thread *threads;
-
- ATOMIC(volatile int drawcommand);
-
- DPSOFTRAST_State_Command_Pool commandpool;
-}
-DPSOFTRAST_State);
-
-DPSOFTRAST_State dpsoftrast;
-
-#define DPSOFTRAST_DEPTHSCALE (1024.0f*1048576.0f)
-#define DPSOFTRAST_DEPTHOFFSET (128.0f)
-#define DPSOFTRAST_BGRA8_FROM_RGBA32F(r,g,b,a) (((int)(r * 255.0f + 0.5f) << 16) | ((int)(g * 255.0f + 0.5f) << 8) | (int)(b * 255.0f + 0.5f) | ((int)(a * 255.0f + 0.5f) << 24))
-#define DPSOFTRAST_DEPTH32_FROM_DEPTH32F(d) ((int)(DPSOFTRAST_DEPTHSCALE * (1-d)))
-
-static void DPSOFTRAST_Draw_DepthTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_State_Span *span);
-static void DPSOFTRAST_Draw_DepthWrite(const DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Span *span);
-
-static void DPSOFTRAST_RecalcViewport(const int *viewport, float *fb_viewportcenter, float *fb_viewportscale)
-{
- fb_viewportcenter[1] = viewport[0] + 0.5f * viewport[2] - 0.5f;
- fb_viewportcenter[2] = dpsoftrast.fb_height - viewport[1] - 0.5f * viewport[3] - 0.5f;
- fb_viewportcenter[3] = 0.5f;
- fb_viewportcenter[0] = 0.0f;
- fb_viewportscale[1] = 0.5f * viewport[2];
- fb_viewportscale[2] = -0.5f * viewport[3];
- fb_viewportscale[3] = 0.5f;
- fb_viewportscale[0] = 1.0f;
-}
-
-static void DPSOFTRAST_RecalcThread(DPSOFTRAST_State_Thread *thread)
-{
- if (dpsoftrast.interlace)
- {
- thread->miny1 = (thread->index*dpsoftrast.fb_height)/(2*dpsoftrast.numthreads);
- thread->maxy1 = ((thread->index+1)*dpsoftrast.fb_height)/(2*dpsoftrast.numthreads);
- thread->miny2 = ((dpsoftrast.numthreads+thread->index)*dpsoftrast.fb_height)/(2*dpsoftrast.numthreads);
- thread->maxy2 = ((dpsoftrast.numthreads+thread->index+1)*dpsoftrast.fb_height)/(2*dpsoftrast.numthreads);
- }
- else
- {
- thread->miny1 = thread->miny2 = (thread->index*dpsoftrast.fb_height)/dpsoftrast.numthreads;
- thread->maxy1 = thread->maxy2 = ((thread->index+1)*dpsoftrast.fb_height)/dpsoftrast.numthreads;
- }
-}
-
-static void DPSOFTRAST_RecalcClipPlane(DPSOFTRAST_State_Thread *thread)
-{
- thread->fb_clipplane[0] = thread->clipplane[0] / thread->fb_viewportscale[1];
- thread->fb_clipplane[1] = thread->clipplane[1] / thread->fb_viewportscale[2];
- thread->fb_clipplane[2] = thread->clipplane[2] / thread->fb_viewportscale[3];
- thread->fb_clipplane[3] = thread->clipplane[3] / thread->fb_viewportscale[0];
- thread->fb_clipplane[3] -= thread->fb_viewportcenter[1]*thread->fb_clipplane[0] + thread->fb_viewportcenter[2]*thread->fb_clipplane[1] + thread->fb_viewportcenter[3]*thread->fb_clipplane[2] + thread->fb_viewportcenter[0]*thread->fb_clipplane[3];
-}
-
-static void DPSOFTRAST_RecalcFB(DPSOFTRAST_State_Thread *thread)
-{
- // calculate framebuffer scissor, viewport, viewport clipped by scissor,
- // and viewport projection values
- int x1, x2;
- int y1, y2;
- x1 = thread->scissor[0];
- x2 = thread->scissor[0] + thread->scissor[2];
- y1 = dpsoftrast.fb_height - thread->scissor[1] - thread->scissor[3];
- y2 = dpsoftrast.fb_height - thread->scissor[1];
- if (!thread->scissortest) {x1 = 0;y1 = 0;x2 = dpsoftrast.fb_width;y2 = dpsoftrast.fb_height;}
- if (x1 < 0) x1 = 0;
- if (x2 > dpsoftrast.fb_width) x2 = dpsoftrast.fb_width;
- if (y1 < 0) y1 = 0;
- if (y2 > dpsoftrast.fb_height) y2 = dpsoftrast.fb_height;
- thread->fb_scissor[0] = x1;
- thread->fb_scissor[1] = y1;
- thread->fb_scissor[2] = x2 - x1;
- thread->fb_scissor[3] = y2 - y1;
-
- DPSOFTRAST_RecalcViewport(thread->viewport, thread->fb_viewportcenter, thread->fb_viewportscale);
- DPSOFTRAST_RecalcClipPlane(thread);
- DPSOFTRAST_RecalcThread(thread);
-}
-
-static void DPSOFTRAST_RecalcDepthFunc(DPSOFTRAST_State_Thread *thread)
-{
- thread->fb_depthfunc = thread->depthtest ? thread->depthfunc : GL_ALWAYS;
-}
-
-static void DPSOFTRAST_RecalcBlendFunc(DPSOFTRAST_State_Thread *thread)
-{
- if (thread->blendsubtract)
- {
- switch ((thread->blendfunc[0]<<16)|thread->blendfunc[1])
- {
- #define BLENDFUNC(sfactor, dfactor, blendmode) \
- case (sfactor<<16)|dfactor: thread->fb_blendmode = blendmode; break;
- BLENDFUNC(GL_SRC_ALPHA, GL_ONE, DPSOFTRAST_BLENDMODE_SUBALPHA)
- default: thread->fb_blendmode = DPSOFTRAST_BLENDMODE_OPAQUE; break;
- }
- }
- else
- {
- switch ((thread->blendfunc[0]<<16)|thread->blendfunc[1])
- {
- BLENDFUNC(GL_ONE, GL_ZERO, DPSOFTRAST_BLENDMODE_OPAQUE)
- BLENDFUNC(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, DPSOFTRAST_BLENDMODE_ALPHA)
- BLENDFUNC(GL_SRC_ALPHA, GL_ONE, DPSOFTRAST_BLENDMODE_ADDALPHA)
- BLENDFUNC(GL_ONE, GL_ONE, DPSOFTRAST_BLENDMODE_ADD)
- BLENDFUNC(GL_ZERO, GL_ONE_MINUS_SRC_COLOR, DPSOFTRAST_BLENDMODE_INVMOD)
- BLENDFUNC(GL_ZERO, GL_SRC_COLOR, DPSOFTRAST_BLENDMODE_MUL)
- BLENDFUNC(GL_DST_COLOR, GL_ZERO, DPSOFTRAST_BLENDMODE_MUL)
- BLENDFUNC(GL_DST_COLOR, GL_SRC_COLOR, DPSOFTRAST_BLENDMODE_MUL2)
- BLENDFUNC(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, DPSOFTRAST_BLENDMODE_PSEUDOALPHA)
- BLENDFUNC(GL_ONE_MINUS_DST_COLOR, GL_ONE, DPSOFTRAST_BLENDMODE_INVADD)
- default: thread->fb_blendmode = DPSOFTRAST_BLENDMODE_OPAQUE; break;
- }
- }
-}
-
-#define DPSOFTRAST_ValidateQuick(thread, f) ((thread->validate & (f)) ? (DPSOFTRAST_Validate(thread, f), 0) : 0)
-
-static void DPSOFTRAST_Validate(DPSOFTRAST_State_Thread *thread, int mask)
-{
- mask &= thread->validate;
- if (!mask)
- return;
- if (mask & DPSOFTRAST_VALIDATE_FB)
- {
- thread->validate &= ~DPSOFTRAST_VALIDATE_FB;
- DPSOFTRAST_RecalcFB(thread);
- }
- if (mask & DPSOFTRAST_VALIDATE_DEPTHFUNC)
- {
- thread->validate &= ~DPSOFTRAST_VALIDATE_DEPTHFUNC;
- DPSOFTRAST_RecalcDepthFunc(thread);
- }
- if (mask & DPSOFTRAST_VALIDATE_BLENDFUNC)
- {
- thread->validate &= ~DPSOFTRAST_VALIDATE_BLENDFUNC;
- DPSOFTRAST_RecalcBlendFunc(thread);
- }
-}
-
-static DPSOFTRAST_Texture *DPSOFTRAST_Texture_GetByIndex(int index)
-{
- if (index >= 1 && index < dpsoftrast.texture_end && dpsoftrast.texture[index].bytes)
- return &dpsoftrast.texture[index];
- return NULL;
-}
-
-static void DPSOFTRAST_Texture_Grow(void)
-{
- DPSOFTRAST_Texture *oldtexture = dpsoftrast.texture;
- DPSOFTRAST_State_Thread *thread;
- int i;
- int j;
- DPSOFTRAST_Flush();
- // expand texture array as needed
- if (dpsoftrast.texture_max < 1024)
- dpsoftrast.texture_max = 1024;
- else
- dpsoftrast.texture_max *= 2;
- dpsoftrast.texture = (DPSOFTRAST_Texture *)realloc(dpsoftrast.texture, dpsoftrast.texture_max * sizeof(DPSOFTRAST_Texture));
- for (i = 0; i < DPSOFTRAST_MAXTEXTUREUNITS; i++)
- if (dpsoftrast.texbound[i])
- dpsoftrast.texbound[i] = dpsoftrast.texture + (dpsoftrast.texbound[i] - oldtexture);
- for (j = 0; j < dpsoftrast.numthreads; j++)
- {
- thread = &dpsoftrast.threads[j];
- for (i = 0; i < DPSOFTRAST_MAXTEXTUREUNITS; i++)
- if (thread->texbound[i])
- thread->texbound[i] = dpsoftrast.texture + (thread->texbound[i] - oldtexture);
- }
-}
-
-int DPSOFTRAST_Texture_New(int flags, int width, int height, int depth)
-{
- int w;
- int h;
- int d;
- int size;
- int s;
- int texnum;
- int mipmaps;
- int sides = (flags & DPSOFTRAST_TEXTURE_FLAG_CUBEMAP) ? 6 : 1;
- int texformat = flags & DPSOFTRAST_TEXTURE_FORMAT_COMPAREMASK;
- DPSOFTRAST_Texture *texture;
- if (width*height*depth < 1)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: width, height or depth is less than 1";
- return 0;
- }
- if (width > DPSOFTRAST_TEXTURE_MAXSIZE || height > DPSOFTRAST_TEXTURE_MAXSIZE || depth > DPSOFTRAST_TEXTURE_MAXSIZE)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: texture size is too large";
- return 0;
- }
- switch(texformat)
- {
- case DPSOFTRAST_TEXTURE_FORMAT_BGRA8:
- case DPSOFTRAST_TEXTURE_FORMAT_RGBA8:
- case DPSOFTRAST_TEXTURE_FORMAT_ALPHA8:
- break;
- case DPSOFTRAST_TEXTURE_FORMAT_DEPTH:
- if (flags & DPSOFTRAST_TEXTURE_FLAG_CUBEMAP)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FORMAT_DEPTH only permitted on 2D textures";
- return 0;
- }
- if (depth != 1)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FORMAT_DEPTH only permitted on 2D textures";
- return 0;
- }
- if ((flags & DPSOFTRAST_TEXTURE_FLAG_MIPMAP) && (texformat == DPSOFTRAST_TEXTURE_FORMAT_DEPTH))
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FORMAT_DEPTH does not permit mipmaps";
- return 0;
- }
- break;
- }
- if (depth != 1 && (flags & DPSOFTRAST_TEXTURE_FLAG_CUBEMAP))
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FLAG_CUBEMAP can not be used on 3D textures";
- return 0;
- }
- if (depth != 1 && (flags & DPSOFTRAST_TEXTURE_FLAG_MIPMAP))
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FLAG_MIPMAP can not be used on 3D textures";
- return 0;
- }
- if (depth != 1 && (flags & DPSOFTRAST_TEXTURE_FLAG_MIPMAP))
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FLAG_MIPMAP can not be used on 3D textures";
- return 0;
- }
- if ((flags & DPSOFTRAST_TEXTURE_FLAG_CUBEMAP) && (flags & DPSOFTRAST_TEXTURE_FLAG_MIPMAP))
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: DPSOFTRAST_TEXTURE_FLAG_MIPMAP can not be used on cubemap textures";
- return 0;
- }
- if ((width & (width-1)) || (height & (height-1)) || (depth & (depth-1)))
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_New: dimensions are not power of two";
- return 0;
- }
- // find first empty slot in texture array
- for (texnum = dpsoftrast.texture_firstfree;texnum < dpsoftrast.texture_end;texnum++)
- if (!dpsoftrast.texture[texnum].bytes)
- break;
- dpsoftrast.texture_firstfree = texnum + 1;
- if (dpsoftrast.texture_max <= texnum)
- DPSOFTRAST_Texture_Grow();
- if (dpsoftrast.texture_end <= texnum)
- dpsoftrast.texture_end = texnum + 1;
- texture = &dpsoftrast.texture[texnum];
- memset(texture, 0, sizeof(*texture));
- texture->flags = flags;
- texture->width = width;
- texture->height = height;
- texture->depth = depth;
- texture->sides = sides;
- texture->binds = 0;
- w = width;
- h = height;
- d = depth;
- size = 0;
- mipmaps = 0;
- for (;;)
- {
- s = w * h * d * sides * 4;
- texture->mipmap[mipmaps][0] = size;
- texture->mipmap[mipmaps][1] = s;
- texture->mipmap[mipmaps][2] = w;
- texture->mipmap[mipmaps][3] = h;
- texture->mipmap[mipmaps][4] = d;
- size += s;
- mipmaps++;
- if (w * h * d == 1 || !(flags & DPSOFTRAST_TEXTURE_FLAG_MIPMAP))
- break;
- if (w > 1) w >>= 1;
- if (h > 1) h >>= 1;
- if (d > 1) d >>= 1;
- }
- texture->mipmaps = mipmaps;
- texture->size = size;
-
- // allocate the pixels now
- texture->bytes = (unsigned char *)MM_CALLOC(1, size);
-
- return texnum;
-}
-void DPSOFTRAST_Texture_Free(int index)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return;
- if (texture->binds)
- DPSOFTRAST_Flush();
- if (texture->bytes)
- MM_FREE(texture->bytes);
- texture->bytes = NULL;
- memset(texture, 0, sizeof(*texture));
- // adjust the free range and used range
- if (dpsoftrast.texture_firstfree > index)
- dpsoftrast.texture_firstfree = index;
- while (dpsoftrast.texture_end > 0 && dpsoftrast.texture[dpsoftrast.texture_end-1].bytes == NULL)
- dpsoftrast.texture_end--;
-}
-static void DPSOFTRAST_Texture_CalculateMipmaps(int index)
-{
- int i, x, y, z, w, layer0, layer1, row0, row1;
- unsigned char *o, *i0, *i1, *i2, *i3;
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return;
- if (texture->mipmaps <= 1)
- return;
- for (i = 1;i < texture->mipmaps;i++)
- {
- for (z = 0;z < texture->mipmap[i][4];z++)
- {
- layer0 = z*2;
- layer1 = z*2+1;
- if (layer1 >= texture->mipmap[i-1][4])
- layer1 = texture->mipmap[i-1][4]-1;
- for (y = 0;y < texture->mipmap[i][3];y++)
- {
- row0 = y*2;
- row1 = y*2+1;
- if (row1 >= texture->mipmap[i-1][3])
- row1 = texture->mipmap[i-1][3]-1;
- o = texture->bytes + texture->mipmap[i ][0] + 4*((texture->mipmap[i ][3] * z + y ) * texture->mipmap[i ][2]);
- i0 = texture->bytes + texture->mipmap[i-1][0] + 4*((texture->mipmap[i-1][3] * layer0 + row0) * texture->mipmap[i-1][2]);
- i1 = texture->bytes + texture->mipmap[i-1][0] + 4*((texture->mipmap[i-1][3] * layer0 + row1) * texture->mipmap[i-1][2]);
- i2 = texture->bytes + texture->mipmap[i-1][0] + 4*((texture->mipmap[i-1][3] * layer1 + row0) * texture->mipmap[i-1][2]);
- i3 = texture->bytes + texture->mipmap[i-1][0] + 4*((texture->mipmap[i-1][3] * layer1 + row1) * texture->mipmap[i-1][2]);
- w = texture->mipmap[i][2];
- if (layer1 > layer0)
- {
- if (texture->mipmap[i-1][2] > 1)
- {
- // average 3D texture
- for (x = 0;x < w;x++, o += 4, i0 += 8, i1 += 8, i2 += 8, i3 += 8)
- {
- o[0] = (i0[0] + i0[4] + i1[0] + i1[4] + i2[0] + i2[4] + i3[0] + i3[4] + 4) >> 3;
- o[1] = (i0[1] + i0[5] + i1[1] + i1[5] + i2[1] + i2[5] + i3[1] + i3[5] + 4) >> 3;
- o[2] = (i0[2] + i0[6] + i1[2] + i1[6] + i2[2] + i2[6] + i3[2] + i3[6] + 4) >> 3;
- o[3] = (i0[3] + i0[7] + i1[3] + i1[7] + i2[3] + i2[7] + i3[3] + i3[7] + 4) >> 3;
- }
- }
- else
- {
- // average 3D mipmap with parent width == 1
- for (x = 0;x < w;x++, o += 4, i0 += 8, i1 += 8)
- {
- o[0] = (i0[0] + i1[0] + i2[0] + i3[0] + 2) >> 2;
- o[1] = (i0[1] + i1[1] + i2[1] + i3[1] + 2) >> 2;
- o[2] = (i0[2] + i1[2] + i2[2] + i3[2] + 2) >> 2;
- o[3] = (i0[3] + i1[3] + i2[3] + i3[3] + 2) >> 2;
- }
- }
- }
- else
- {
- if (texture->mipmap[i-1][2] > 1)
- {
- // average 2D texture (common case)
- for (x = 0;x < w;x++, o += 4, i0 += 8, i1 += 8)
- {
- o[0] = (i0[0] + i0[4] + i1[0] + i1[4] + 2) >> 2;
- o[1] = (i0[1] + i0[5] + i1[1] + i1[5] + 2) >> 2;
- o[2] = (i0[2] + i0[6] + i1[2] + i1[6] + 2) >> 2;
- o[3] = (i0[3] + i0[7] + i1[3] + i1[7] + 2) >> 2;
- }
- }
- else
- {
- // 2D texture with parent width == 1
- o[0] = (i0[0] + i1[0] + 1) >> 1;
- o[1] = (i0[1] + i1[1] + 1) >> 1;
- o[2] = (i0[2] + i1[2] + 1) >> 1;
- o[3] = (i0[3] + i1[3] + 1) >> 1;
- }
- }
- }
- }
- }
-}
-void DPSOFTRAST_Texture_UpdatePartial(int index, int mip, const unsigned char *pixels, int blockx, int blocky, int blockwidth, int blockheight)
-{
- DPSOFTRAST_Texture *texture;
- unsigned char *dst;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return;
- if (texture->binds)
- DPSOFTRAST_Flush();
- if (pixels)
- {
- dst = texture->bytes + texture->mipmap[0][1] +(-blocky * texture->mipmap[0][2] + blockx) * 4;
- while (blockheight > 0)
- {
- dst -= texture->mipmap[0][2] * 4;
- memcpy(dst, pixels, blockwidth * 4);
- pixels += blockwidth * 4;
- blockheight--;
- }
- }
- DPSOFTRAST_Texture_CalculateMipmaps(index);
-}
-void DPSOFTRAST_Texture_UpdateFull(int index, const unsigned char *pixels)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return;
- if (texture->binds)
- DPSOFTRAST_Flush();
- if (pixels)
- {
- int i, stride = texture->mipmap[0][2]*4;
- unsigned char *dst = texture->bytes + texture->mipmap[0][1];
- for (i = texture->mipmap[0][3];i > 0;i--)
- {
- dst -= stride;
- memcpy(dst, pixels, stride);
- pixels += stride;
- }
- }
- DPSOFTRAST_Texture_CalculateMipmaps(index);
-}
-int DPSOFTRAST_Texture_GetWidth(int index, int mip)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return 0;
- return texture->mipmap[mip][2];
-}
-int DPSOFTRAST_Texture_GetHeight(int index, int mip)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return 0;
- return texture->mipmap[mip][3];
-}
-int DPSOFTRAST_Texture_GetDepth(int index, int mip)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return 0;
- return texture->mipmap[mip][4];
-}
-unsigned char *DPSOFTRAST_Texture_GetPixelPointer(int index, int mip)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return 0;
- if (texture->binds)
- DPSOFTRAST_Flush();
- return texture->bytes + texture->mipmap[mip][0];
-}
-void DPSOFTRAST_Texture_Filter(int index, DPSOFTRAST_TEXTURE_FILTER filter)
-{
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return;
- if (!(texture->flags & DPSOFTRAST_TEXTURE_FLAG_MIPMAP) && filter > DPSOFTRAST_TEXTURE_FILTER_LINEAR)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_Texture_Filter: requested filter mode requires mipmaps";
- return;
- }
- if (texture->binds)
- DPSOFTRAST_Flush();
- texture->filter = filter;
-}
-
-static void DPSOFTRAST_Draw_FlushThreads(void);
-
-static void DPSOFTRAST_Draw_SyncCommands(void)
-{
- if(dpsoftrast.usethreads) MEMORY_BARRIER;
- dpsoftrast.drawcommand = dpsoftrast.commandpool.freecommand;
-}
-
-static void DPSOFTRAST_Draw_FreeCommandPool(int space)
-{
- DPSOFTRAST_State_Thread *thread;
- int i;
- int freecommand = dpsoftrast.commandpool.freecommand;
- int usedcommands = dpsoftrast.commandpool.usedcommands;
- if (usedcommands <= DPSOFTRAST_DRAW_MAXCOMMANDPOOL-space)
- return;
- DPSOFTRAST_Draw_SyncCommands();
- for(;;)
- {
- int waitindex = -1;
- int commandoffset;
- usedcommands = 0;
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- thread = &dpsoftrast.threads[i];
- commandoffset = freecommand - thread->commandoffset;
- if (commandoffset < 0)
- commandoffset += DPSOFTRAST_DRAW_MAXCOMMANDPOOL;
- if (commandoffset > usedcommands)
- {
- waitindex = i;
- usedcommands = commandoffset;
- }
- }
- if (usedcommands <= DPSOFTRAST_DRAW_MAXCOMMANDPOOL-space || waitindex < 0)
- break;
- thread = &dpsoftrast.threads[waitindex];
- Thread_LockMutex(thread->drawmutex);
- if (thread->commandoffset != dpsoftrast.drawcommand)
- {
- thread->waiting = true;
- if (thread->starving) Thread_CondSignal(thread->drawcond);
- Thread_CondWait(thread->waitcond, thread->drawmutex);
- thread->waiting = false;
- }
- Thread_UnlockMutex(thread->drawmutex);
- }
- dpsoftrast.commandpool.usedcommands = usedcommands;
-}
-
-#define DPSOFTRAST_ALIGNCOMMAND(size) \
- ((size) + ((COMMAND_SIZE - ((size)&(COMMAND_SIZE-1))) & (COMMAND_SIZE-1)))
-#define DPSOFTRAST_ALLOCATECOMMAND(name) \
- ((DPSOFTRAST_Command_##name *) DPSOFTRAST_AllocateCommand( DPSOFTRAST_OPCODE_##name , DPSOFTRAST_ALIGNCOMMAND(sizeof( DPSOFTRAST_Command_##name ))))
-
-static void *DPSOFTRAST_AllocateCommand(int opcode, int size)
-{
- DPSOFTRAST_Command *command;
- int freecommand = dpsoftrast.commandpool.freecommand;
- int usedcommands = dpsoftrast.commandpool.usedcommands;
- int extra = sizeof(DPSOFTRAST_Command);
- if (DPSOFTRAST_DRAW_MAXCOMMANDPOOL - freecommand < size)
- extra += DPSOFTRAST_DRAW_MAXCOMMANDPOOL - freecommand;
- if (usedcommands > DPSOFTRAST_DRAW_MAXCOMMANDPOOL - (size + extra))
- {
- if (dpsoftrast.usethreads)
- DPSOFTRAST_Draw_FreeCommandPool(size + extra);
- else
- DPSOFTRAST_Draw_FlushThreads();
- freecommand = dpsoftrast.commandpool.freecommand;
- usedcommands = dpsoftrast.commandpool.usedcommands;
- }
- if (DPSOFTRAST_DRAW_MAXCOMMANDPOOL - freecommand < size)
- {
- command = (DPSOFTRAST_Command *) &dpsoftrast.commandpool.commands[freecommand];
- command->opcode = DPSOFTRAST_OPCODE_Reset;
- usedcommands += DPSOFTRAST_DRAW_MAXCOMMANDPOOL - freecommand;
- freecommand = 0;
- }
- command = (DPSOFTRAST_Command *) &dpsoftrast.commandpool.commands[freecommand];
- command->opcode = opcode;
- command->commandsize = size;
- freecommand += size;
- if (freecommand >= DPSOFTRAST_DRAW_MAXCOMMANDPOOL)
- freecommand = 0;
- dpsoftrast.commandpool.freecommand = freecommand;
- dpsoftrast.commandpool.usedcommands = usedcommands + size;
- return command;
-}
-
-static void DPSOFTRAST_UndoCommand(int size)
-{
- int freecommand = dpsoftrast.commandpool.freecommand;
- int usedcommands = dpsoftrast.commandpool.usedcommands;
- freecommand -= size;
- if (freecommand < 0)
- freecommand += DPSOFTRAST_DRAW_MAXCOMMANDPOOL;
- usedcommands -= size;
- dpsoftrast.commandpool.freecommand = freecommand;
- dpsoftrast.commandpool.usedcommands = usedcommands;
-}
-
-DEFCOMMAND(1, Viewport, int x; int y; int width; int height;)
-static void DPSOFTRAST_Interpret_Viewport(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_Command_Viewport *command)
-{
- thread->viewport[0] = command->x;
- thread->viewport[1] = command->y;
- thread->viewport[2] = command->width;
- thread->viewport[3] = command->height;
- thread->validate |= DPSOFTRAST_VALIDATE_FB;
-}
-void DPSOFTRAST_Viewport(int x, int y, int width, int height)
-{
- DPSOFTRAST_Command_Viewport *command = DPSOFTRAST_ALLOCATECOMMAND(Viewport);
- command->x = x;
- command->y = y;
- command->width = width;
- command->height = height;
-
- dpsoftrast.viewport[0] = x;
- dpsoftrast.viewport[1] = y;
- dpsoftrast.viewport[2] = width;
- dpsoftrast.viewport[3] = height;
- DPSOFTRAST_RecalcViewport(dpsoftrast.viewport, dpsoftrast.fb_viewportcenter, dpsoftrast.fb_viewportscale);
-}
-
-DEFCOMMAND(2, ClearColor, float r; float g; float b; float a;)
-static void DPSOFTRAST_Interpret_ClearColor(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_Command_ClearColor *command)
-{
- int i, x1, y1, x2, y2, w, h, x, y;
- int miny1, maxy1, miny2, maxy2;
- int bandy;
- unsigned int *p;
- unsigned int c;
- DPSOFTRAST_Validate(thread, DPSOFTRAST_VALIDATE_FB);
- miny1 = thread->miny1;
- maxy1 = thread->maxy1;
- miny2 = thread->miny2;
- maxy2 = thread->maxy2;
- x1 = thread->fb_scissor[0];
- y1 = thread->fb_scissor[1];
- x2 = thread->fb_scissor[0] + thread->fb_scissor[2];
- y2 = thread->fb_scissor[1] + thread->fb_scissor[3];
- if (y1 < miny1) y1 = miny1;
- if (y2 > maxy2) y2 = maxy2;
- w = x2 - x1;
- h = y2 - y1;
- if (w < 1 || h < 1)
- return;
- // FIXME: honor fb_colormask?
- c = DPSOFTRAST_BGRA8_FROM_RGBA32F(command->r,command->g,command->b,command->a);
- for (i = 0;i < 4;i++)
- {
- if (!dpsoftrast.fb_colorpixels[i])
- continue;
- for (y = y1, bandy = min(y2, maxy1); y < y2; bandy = min(y2, maxy2), y = max(y, miny2))
- for (;y < bandy;y++)
- {
- p = dpsoftrast.fb_colorpixels[i] + y * dpsoftrast.fb_width;
- for (x = x1;x < x2;x++)
- p[x] = c;
- }
- }
-}
-void DPSOFTRAST_ClearColor(float r, float g, float b, float a)
-{
- DPSOFTRAST_Command_ClearColor *command = DPSOFTRAST_ALLOCATECOMMAND(ClearColor);
- command->r = r;
- command->g = g;
- command->b = b;
- command->a = a;
-}
-
-DEFCOMMAND(3, ClearDepth, float depth;)
-static void DPSOFTRAST_Interpret_ClearDepth(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_ClearDepth *command)
-{
- int x1, y1, x2, y2, w, h, x, y;
- int miny1, maxy1, miny2, maxy2;
- int bandy;
- unsigned int *p;
- unsigned int c;
- DPSOFTRAST_Validate(thread, DPSOFTRAST_VALIDATE_FB);
- miny1 = thread->miny1;
- maxy1 = thread->maxy1;
- miny2 = thread->miny2;
- maxy2 = thread->maxy2;
- x1 = thread->fb_scissor[0];
- y1 = thread->fb_scissor[1];
- x2 = thread->fb_scissor[0] + thread->fb_scissor[2];
- y2 = thread->fb_scissor[1] + thread->fb_scissor[3];
- if (y1 < miny1) y1 = miny1;
- if (y2 > maxy2) y2 = maxy2;
- w = x2 - x1;
- h = y2 - y1;
- if (w < 1 || h < 1)
- return;
- c = DPSOFTRAST_DEPTH32_FROM_DEPTH32F(command->depth);
- for (y = y1, bandy = min(y2, maxy1); y < y2; bandy = min(y2, maxy2), y = max(y, miny2))
- for (;y < bandy;y++)
- {
- p = dpsoftrast.fb_depthpixels + y * dpsoftrast.fb_width;
- for (x = x1;x < x2;x++)
- p[x] = c;
- }
-}
-void DPSOFTRAST_ClearDepth(float d)
-{
- DPSOFTRAST_Command_ClearDepth *command = DPSOFTRAST_ALLOCATECOMMAND(ClearDepth);
- command->depth = d;
-}
-
-DEFCOMMAND(4, ColorMask, int r; int g; int b; int a;)
-static void DPSOFTRAST_Interpret_ColorMask(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_ColorMask *command)
-{
- thread->colormask[0] = command->r != 0;
- thread->colormask[1] = command->g != 0;
- thread->colormask[2] = command->b != 0;
- thread->colormask[3] = command->a != 0;
- thread->fb_colormask = ((-thread->colormask[0]) & 0x00FF0000) | ((-thread->colormask[1]) & 0x0000FF00) | ((-thread->colormask[2]) & 0x000000FF) | ((-thread->colormask[3]) & 0xFF000000);
-}
-void DPSOFTRAST_ColorMask(int r, int g, int b, int a)
-{
- DPSOFTRAST_Command_ColorMask *command = DPSOFTRAST_ALLOCATECOMMAND(ColorMask);
- command->r = r;
- command->g = g;
- command->b = b;
- command->a = a;
-}
-
-DEFCOMMAND(5, DepthTest, int enable;)
-static void DPSOFTRAST_Interpret_DepthTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_DepthTest *command)
-{
- thread->depthtest = command->enable;
- thread->validate |= DPSOFTRAST_VALIDATE_DEPTHFUNC;
-}
-void DPSOFTRAST_DepthTest(int enable)
-{
- DPSOFTRAST_Command_DepthTest *command = DPSOFTRAST_ALLOCATECOMMAND(DepthTest);
- command->enable = enable;
-}
-
-DEFCOMMAND(6, ScissorTest, int enable;)
-static void DPSOFTRAST_Interpret_ScissorTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_ScissorTest *command)
-{
- thread->scissortest = command->enable;
- thread->validate |= DPSOFTRAST_VALIDATE_FB;
-}
-void DPSOFTRAST_ScissorTest(int enable)
-{
- DPSOFTRAST_Command_ScissorTest *command = DPSOFTRAST_ALLOCATECOMMAND(ScissorTest);
- command->enable = enable;
-}
-
-DEFCOMMAND(7, Scissor, float x; float y; float width; float height;)
-static void DPSOFTRAST_Interpret_Scissor(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_Scissor *command)
-{
- thread->scissor[0] = command->x;
- thread->scissor[1] = command->y;
- thread->scissor[2] = command->width;
- thread->scissor[3] = command->height;
- thread->validate |= DPSOFTRAST_VALIDATE_FB;
-}
-void DPSOFTRAST_Scissor(float x, float y, float width, float height)
-{
- DPSOFTRAST_Command_Scissor *command = DPSOFTRAST_ALLOCATECOMMAND(Scissor);
- command->x = x;
- command->y = y;
- command->width = width;
- command->height = height;
-}
-
-DEFCOMMAND(8, BlendFunc, int sfactor; int dfactor;)
-static void DPSOFTRAST_Interpret_BlendFunc(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_BlendFunc *command)
-{
- thread->blendfunc[0] = command->sfactor;
- thread->blendfunc[1] = command->dfactor;
- thread->validate |= DPSOFTRAST_VALIDATE_BLENDFUNC;
-}
-void DPSOFTRAST_BlendFunc(int sfactor, int dfactor)
-{
- DPSOFTRAST_Command_BlendFunc *command = DPSOFTRAST_ALLOCATECOMMAND(BlendFunc);
- command->sfactor = sfactor;
- command->dfactor = dfactor;
-}
-
-DEFCOMMAND(9, BlendSubtract, int enable;)
-static void DPSOFTRAST_Interpret_BlendSubtract(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_BlendSubtract *command)
-{
- thread->blendsubtract = command->enable;
- thread->validate |= DPSOFTRAST_VALIDATE_BLENDFUNC;
-}
-void DPSOFTRAST_BlendSubtract(int enable)
-{
- DPSOFTRAST_Command_BlendSubtract *command = DPSOFTRAST_ALLOCATECOMMAND(BlendSubtract);
- command->enable = enable;
-}
-
-DEFCOMMAND(10, DepthMask, int enable;)
-static void DPSOFTRAST_Interpret_DepthMask(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_DepthMask *command)
-{
- thread->depthmask = command->enable;
-}
-void DPSOFTRAST_DepthMask(int enable)
-{
- DPSOFTRAST_Command_DepthMask *command = DPSOFTRAST_ALLOCATECOMMAND(DepthMask);
- command->enable = enable;
-}
-
-DEFCOMMAND(11, DepthFunc, int func;)
-static void DPSOFTRAST_Interpret_DepthFunc(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_DepthFunc *command)
-{
- thread->depthfunc = command->func;
-}
-void DPSOFTRAST_DepthFunc(int func)
-{
- DPSOFTRAST_Command_DepthFunc *command = DPSOFTRAST_ALLOCATECOMMAND(DepthFunc);
- command->func = func;
-}
-
-DEFCOMMAND(12, DepthRange, float nearval; float farval;)
-static void DPSOFTRAST_Interpret_DepthRange(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_DepthRange *command)
-{
- thread->depthrange[0] = command->nearval;
- thread->depthrange[1] = command->farval;
-}
-void DPSOFTRAST_DepthRange(float nearval, float farval)
-{
- DPSOFTRAST_Command_DepthRange *command = DPSOFTRAST_ALLOCATECOMMAND(DepthRange);
- command->nearval = nearval;
- command->farval = farval;
-}
-
-DEFCOMMAND(13, PolygonOffset, float alongnormal; float intoview;)
-static void DPSOFTRAST_Interpret_PolygonOffset(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_PolygonOffset *command)
-{
- thread->polygonoffset[0] = command->alongnormal;
- thread->polygonoffset[1] = command->intoview;
-}
-void DPSOFTRAST_PolygonOffset(float alongnormal, float intoview)
-{
- DPSOFTRAST_Command_PolygonOffset *command = DPSOFTRAST_ALLOCATECOMMAND(PolygonOffset);
- command->alongnormal = alongnormal;
- command->intoview = intoview;
-}
-
-DEFCOMMAND(14, CullFace, int mode;)
-static void DPSOFTRAST_Interpret_CullFace(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_CullFace *command)
-{
- thread->cullface = command->mode;
-}
-void DPSOFTRAST_CullFace(int mode)
-{
- DPSOFTRAST_Command_CullFace *command = DPSOFTRAST_ALLOCATECOMMAND(CullFace);
- command->mode = mode;
-}
-
-void DPSOFTRAST_Color4f(float r, float g, float b, float a)
-{
- dpsoftrast.color[0] = r;
- dpsoftrast.color[1] = g;
- dpsoftrast.color[2] = b;
- dpsoftrast.color[3] = a;
-}
-
-void DPSOFTRAST_GetPixelsBGRA(int blockx, int blocky, int blockwidth, int blockheight, unsigned char *outpixels)
-{
- int outstride = blockwidth * 4;
- int instride = dpsoftrast.fb_width * 4;
- int bx1 = blockx;
- int by1 = blocky;
- int bx2 = blockx + blockwidth;
- int by2 = blocky + blockheight;
- int bw;
- int x;
- int y;
- unsigned char *inpixels;
- unsigned char *b;
- unsigned char *o;
- DPSOFTRAST_Flush();
- if (bx1 < 0) bx1 = 0;
- if (by1 < 0) by1 = 0;
- if (bx2 > dpsoftrast.fb_width) bx2 = dpsoftrast.fb_width;
- if (by2 > dpsoftrast.fb_height) by2 = dpsoftrast.fb_height;
- bw = bx2 - bx1;
- inpixels = (unsigned char *)dpsoftrast.fb_colorpixels[0];
- if (dpsoftrast.bigendian)
- {
- for (y = by1;y < by2;y++)
- {
- b = (unsigned char *)inpixels + (dpsoftrast.fb_height - 1 - y) * instride + 4 * bx1;
- o = (unsigned char *)outpixels + (y - by1) * outstride;
- for (x = bx1;x < bx2;x++)
- {
- o[0] = b[3];
- o[1] = b[2];
- o[2] = b[1];
- o[3] = b[0];
- o += 4;
- b += 4;
- }
- }
- }
- else
- {
- for (y = by1;y < by2;y++)
- {
- b = (unsigned char *)inpixels + (dpsoftrast.fb_height - 1 - y) * instride + 4 * bx1;
- o = (unsigned char *)outpixels + (y - by1) * outstride;
- memcpy(o, b, bw*4);
- }
- }
-
-}
-void DPSOFTRAST_CopyRectangleToTexture(int index, int mip, int tx, int ty, int sx, int sy, int width, int height)
-{
- int tx1 = tx;
- int ty1 = ty;
- int tx2 = tx + width;
- int ty2 = ty + height;
- int sx1 = sx;
- int sy1 = sy;
- int sx2 = sx + width;
- int sy2 = sy + height;
- int swidth;
- int sheight;
- int twidth;
- int theight;
- int sw;
- int sh;
- int tw;
- int th;
- int y;
- unsigned int *spixels;
- unsigned int *tpixels;
- DPSOFTRAST_Texture *texture;
- texture = DPSOFTRAST_Texture_GetByIndex(index);if (!texture) return;
- if (mip < 0 || mip >= texture->mipmaps) return;
- DPSOFTRAST_Flush();
- spixels = dpsoftrast.fb_colorpixels[0];
- swidth = dpsoftrast.fb_width;
- sheight = dpsoftrast.fb_height;
- tpixels = (unsigned int *)(texture->bytes + texture->mipmap[mip][0]);
- twidth = texture->mipmap[mip][2];
- theight = texture->mipmap[mip][3];
- if (tx1 < 0) tx1 = 0;
- if (ty1 < 0) ty1 = 0;
- if (tx2 > twidth) tx2 = twidth;
- if (ty2 > theight) ty2 = theight;
- if (sx1 < 0) sx1 = 0;
- if (sy1 < 0) sy1 = 0;
- if (sx2 > swidth) sx2 = swidth;
- if (sy2 > sheight) sy2 = sheight;
- tw = tx2 - tx1;
- th = ty2 - ty1;
- sw = sx2 - sx1;
- sh = sy2 - sy1;
- if (tw > sw) tw = sw;
- if (th > sh) th = sh;
- if (tw < 1 || th < 1)
- return;
- sy1 = sheight - sy1 - th;
- ty1 = theight - ty1 - th;
- for (y = 0;y < th;y++)
- memcpy(tpixels + ((ty1 + y) * twidth + tx1), spixels + ((sy1 + y) * swidth + sx1), tw*4);
- if (texture->mipmaps > 1)
- DPSOFTRAST_Texture_CalculateMipmaps(index);
-}
-
-DEFCOMMAND(17, SetTexture, int unitnum; DPSOFTRAST_Texture *texture;)
-static void DPSOFTRAST_Interpret_SetTexture(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_SetTexture *command)
-{
- if (thread->texbound[command->unitnum])
- ATOMIC_DECREMENT(thread->texbound[command->unitnum]->binds);
- thread->texbound[command->unitnum] = command->texture;
-}
-void DPSOFTRAST_SetTexture(int unitnum, int index)
-{
- DPSOFTRAST_Command_SetTexture *command;
- DPSOFTRAST_Texture *texture;
- if (unitnum < 0 || unitnum >= DPSOFTRAST_MAXTEXTUREUNITS)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_SetTexture: invalid unit number";
- return;
- }
- texture = DPSOFTRAST_Texture_GetByIndex(index);
- if (index && !texture)
- {
- dpsoftrast.errorstring = "DPSOFTRAST_SetTexture: invalid texture handle";
- return;
- }
-
- command = DPSOFTRAST_ALLOCATECOMMAND(SetTexture);
- command->unitnum = unitnum;
- command->texture = texture;
-
- dpsoftrast.texbound[unitnum] = texture;
- if (texture)
- ATOMIC_ADD(texture->binds, dpsoftrast.numthreads);
-}
-
-void DPSOFTRAST_SetVertexPointer(const float *vertex3f, size_t stride)
-{
- dpsoftrast.pointer_vertex3f = vertex3f;
- dpsoftrast.stride_vertex = (int)stride;
-}
-void DPSOFTRAST_SetColorPointer(const float *color4f, size_t stride)
-{
- dpsoftrast.pointer_color4f = color4f;
- dpsoftrast.pointer_color4ub = NULL;
- dpsoftrast.stride_color = (int)stride;
-}
-void DPSOFTRAST_SetColorPointer4ub(const unsigned char *color4ub, size_t stride)
-{
- dpsoftrast.pointer_color4f = NULL;
- dpsoftrast.pointer_color4ub = color4ub;
- dpsoftrast.stride_color = (int)stride;
-}
-void DPSOFTRAST_SetTexCoordPointer(int unitnum, int numcomponents, size_t stride, const float *texcoordf)
-{
- dpsoftrast.pointer_texcoordf[unitnum] = texcoordf;
- dpsoftrast.components_texcoord[unitnum] = numcomponents;
- dpsoftrast.stride_texcoord[unitnum] = (int)stride;
-}
-
-DEFCOMMAND(18, SetShader, int mode; dpuint64 permutation; int exactspecularmath;)
-static void DPSOFTRAST_Interpret_SetShader(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_SetShader *command)
-{
- thread->shader_mode = command->mode;
- thread->shader_permutation = command->permutation;
- thread->shader_exactspecularmath = command->exactspecularmath;
-}
-void DPSOFTRAST_SetShader(int mode, dpuint64 permutation, int exactspecularmath)
-{
- DPSOFTRAST_Command_SetShader *command = DPSOFTRAST_ALLOCATECOMMAND(SetShader);
- command->mode = mode;
- command->permutation = permutation;
- command->exactspecularmath = exactspecularmath;
-
- dpsoftrast.shader_mode = mode;
- dpsoftrast.shader_permutation = permutation;
- dpsoftrast.shader_exactspecularmath = exactspecularmath;
-}
-
-DEFCOMMAND(19, Uniform4f, DPSOFTRAST_UNIFORM index; float val[4];)
-static void DPSOFTRAST_Interpret_Uniform4f(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_Uniform4f *command)
-{
- memcpy(&thread->uniform4f[command->index*4], command->val, sizeof(command->val));
-}
-void DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM index, float v0, float v1, float v2, float v3)
-{
- DPSOFTRAST_Command_Uniform4f *command = DPSOFTRAST_ALLOCATECOMMAND(Uniform4f);
- command->index = index;
- command->val[0] = v0;
- command->val[1] = v1;
- command->val[2] = v2;
- command->val[3] = v3;
-
- dpsoftrast.uniform4f[index*4+0] = v0;
- dpsoftrast.uniform4f[index*4+1] = v1;
- dpsoftrast.uniform4f[index*4+2] = v2;
- dpsoftrast.uniform4f[index*4+3] = v3;
-}
-void DPSOFTRAST_Uniform4fv(DPSOFTRAST_UNIFORM index, const float *v)
-{
- DPSOFTRAST_Command_Uniform4f *command = DPSOFTRAST_ALLOCATECOMMAND(Uniform4f);
- command->index = index;
- memcpy(command->val, v, sizeof(command->val));
-
- memcpy(&dpsoftrast.uniform4f[index*4], v, sizeof(float[4]));
-}
-
-DEFCOMMAND(20, UniformMatrix4f, DPSOFTRAST_UNIFORM index; ALIGN(float val[16]);)
-static void DPSOFTRAST_Interpret_UniformMatrix4f(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_UniformMatrix4f *command)
-{
- memcpy(&thread->uniform4f[command->index*4], command->val, sizeof(command->val));
-}
-void DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM uniform, int arraysize, int transpose, const float *v)
-{
-#ifdef SSE_POSSIBLE
- int i, index;
- for (i = 0, index = (int)uniform;i < arraysize;i++, index += 4, v += 16)
- {
- __m128 m0, m1, m2, m3;
- DPSOFTRAST_Command_UniformMatrix4f *command = DPSOFTRAST_ALLOCATECOMMAND(UniformMatrix4f);
- command->index = (DPSOFTRAST_UNIFORM)index;
- if (((size_t)v)&(ALIGN_SIZE-1))
- {
- m0 = _mm_loadu_ps(v);
- m1 = _mm_loadu_ps(v+4);
- m2 = _mm_loadu_ps(v+8);
- m3 = _mm_loadu_ps(v+12);
- }
- else
- {
- m0 = _mm_load_ps(v);
- m1 = _mm_load_ps(v+4);
- m2 = _mm_load_ps(v+8);
- m3 = _mm_load_ps(v+12);
- }
- if (transpose)
- {
- __m128 t0, t1, t2, t3;
- t0 = _mm_unpacklo_ps(m0, m1);
- t1 = _mm_unpacklo_ps(m2, m3);
- t2 = _mm_unpackhi_ps(m0, m1);
- t3 = _mm_unpackhi_ps(m2, m3);
- m0 = _mm_movelh_ps(t0, t1);
- m1 = _mm_movehl_ps(t1, t0);
- m2 = _mm_movelh_ps(t2, t3);
- m3 = _mm_movehl_ps(t3, t2);
- }
- _mm_store_ps(command->val, m0);
- _mm_store_ps(command->val+4, m1);
- _mm_store_ps(command->val+8, m2);
- _mm_store_ps(command->val+12, m3);
- _mm_store_ps(&dpsoftrast.uniform4f[index*4+0], m0);
- _mm_store_ps(&dpsoftrast.uniform4f[index*4+4], m1);
- _mm_store_ps(&dpsoftrast.uniform4f[index*4+8], m2);
- _mm_store_ps(&dpsoftrast.uniform4f[index*4+12], m3);
- }
-#endif
-}
-
-DEFCOMMAND(21, Uniform1i, DPSOFTRAST_UNIFORM index; int val;)
-static void DPSOFTRAST_Interpret_Uniform1i(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_Uniform1i *command)
-{
- thread->uniform1i[command->index] = command->val;
-}
-void DPSOFTRAST_Uniform1i(DPSOFTRAST_UNIFORM index, int i0)
-{
- DPSOFTRAST_Command_Uniform1i *command = DPSOFTRAST_ALLOCATECOMMAND(Uniform1i);
- command->index = index;
- command->val = i0;
-
- dpsoftrast.uniform1i[command->index] = i0;
-}
-
-DEFCOMMAND(24, ClipPlane, float clipplane[4];)
-static void DPSOFTRAST_Interpret_ClipPlane(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_ClipPlane *command)
-{
- memcpy(thread->clipplane, command->clipplane, 4*sizeof(float));
- thread->validate |= DPSOFTRAST_VALIDATE_FB;
-}
-void DPSOFTRAST_ClipPlane(float x, float y, float z, float w)
-{
- DPSOFTRAST_Command_ClipPlane *command = DPSOFTRAST_ALLOCATECOMMAND(ClipPlane);
- command->clipplane[0] = x;
- command->clipplane[1] = y;
- command->clipplane[2] = z;
- command->clipplane[3] = w;
-}
-
-#ifdef SSE_POSSIBLE
-static void DPSOFTRAST_Load4fTo4f(float *dst, const unsigned char *src, int size, int stride)
-{
- float *end = dst + size*4;
- if ((((size_t)src)|stride)&(ALIGN_SIZE - 1)) // check for alignment
- {
- while (dst < end)
- {
- _mm_store_ps(dst, _mm_loadu_ps((const float *)src));
- dst += 4;
- src += stride;
- }
- }
- else
- {
- while (dst < end)
- {
- _mm_store_ps(dst, _mm_load_ps((const float *)src));
- dst += 4;
- src += stride;
- }
- }
-}
-
-static void DPSOFTRAST_Load3fTo4f(float *dst, const unsigned char *src, int size, int stride)
-{
- float *end = dst + size*4;
- if (stride == sizeof(float[3]))
- {
- float *end4 = dst + (size&~3)*4;
- if (((size_t)src)&(ALIGN_SIZE - 1)) // check for alignment
- {
- while (dst < end4)
- {
- __m128 v1 = _mm_loadu_ps((const float *)src), v2 = _mm_loadu_ps((const float *)src + 4), v3 = _mm_loadu_ps((const float *)src + 8), dv;
- dv = _mm_shuffle_ps(v1, v1, _MM_SHUFFLE(2, 1, 0, 3));
- dv = _mm_move_ss(dv, _mm_set_ss(1.0f));
- _mm_store_ps(dst, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dv = _mm_shuffle_ps(v1, v2, _MM_SHUFFLE(1, 0, 3, 3));
- dv = _mm_move_ss(dv, _mm_set_ss(1.0f));
- _mm_store_ps(dst + 4, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dv = _mm_shuffle_ps(v2, v3, _MM_SHUFFLE(0, 0, 3, 2));
- dv = _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(2, 1, 0, 3));
- dv = _mm_move_ss(dv, _mm_set_ss(1.0f));
- _mm_store_ps(dst + 8, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dv = _mm_move_ss(v3, _mm_set_ss(1.0f));
- _mm_store_ps(dst + 12, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dst += 16;
- src += 4*sizeof(float[3]);
- }
- }
- else
- {
- while (dst < end4)
- {
- __m128 v1 = _mm_load_ps((const float *)src), v2 = _mm_load_ps((const float *)src + 4), v3 = _mm_load_ps((const float *)src + 8), dv;
- dv = _mm_shuffle_ps(v1, v1, _MM_SHUFFLE(2, 1, 0, 3));
- dv = _mm_move_ss(dv, _mm_set_ss(1.0f));
- _mm_store_ps(dst, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dv = _mm_shuffle_ps(v1, v2, _MM_SHUFFLE(1, 0, 3, 3));
- dv = _mm_move_ss(dv, _mm_set_ss(1.0f));
- _mm_store_ps(dst + 4, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dv = _mm_shuffle_ps(v2, v3, _MM_SHUFFLE(0, 0, 3, 2));
- dv = _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(2, 1, 0, 3));
- dv = _mm_move_ss(dv, _mm_set_ss(1.0f));
- _mm_store_ps(dst + 8, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dv = _mm_move_ss(v3, _mm_set_ss(1.0f));
- _mm_store_ps(dst + 12, _mm_shuffle_ps(dv, dv, _MM_SHUFFLE(0, 3, 2, 1)));
- dst += 16;
- src += 4*sizeof(float[3]);
- }
- }
- }
- if ((((size_t)src)|stride)&(ALIGN_SIZE - 1))
- {
- while (dst < end)
- {
- __m128 v = _mm_loadu_ps((const float *)src);
- v = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 1, 0, 3));
- v = _mm_move_ss(v, _mm_set_ss(1.0f));
- v = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 3, 2, 1));
- _mm_store_ps(dst, v);
- dst += 4;
- src += stride;
- }
- }
- else
- {
- while (dst < end)
- {
- __m128 v = _mm_load_ps((const float *)src);
- v = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 1, 0, 3));
- v = _mm_move_ss(v, _mm_set_ss(1.0f));
- v = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 3, 2, 1));
- _mm_store_ps(dst, v);
- dst += 4;
- src += stride;
- }
- }
-}
-
-static void DPSOFTRAST_Load2fTo4f(float *dst, const unsigned char *src, int size, int stride)
-{
- float *end = dst + size*4;
- __m128 v2 = _mm_setr_ps(0.0f, 0.0f, 0.0f, 1.0f);
- if (stride == sizeof(float[2]))
- {
- float *end2 = dst + (size&~1)*4;
- if (((size_t)src)&(ALIGN_SIZE - 1)) // check for alignment
- {
- while (dst < end2)
- {
- __m128 v = _mm_loadu_ps((const float *)src);
- _mm_store_ps(dst, _mm_shuffle_ps(v, v2, _MM_SHUFFLE(3, 2, 1, 0)));
- _mm_store_ps(dst + 4, _mm_movehl_ps(v2, v));
- dst += 8;
- src += 2*sizeof(float[2]);
- }
- }
- else
- {
- while (dst < end2)
- {
- __m128 v = _mm_load_ps((const float *)src);
- _mm_store_ps(dst, _mm_shuffle_ps(v, v2, _MM_SHUFFLE(3, 2, 1, 0)));
- _mm_store_ps(dst + 4, _mm_movehl_ps(v2, v));
- dst += 8;
- src += 2*sizeof(float[2]);
- }
- }
- }
- while (dst < end)
- {
- _mm_store_ps(dst, _mm_loadl_pi(v2, (__m64 *)src));
- dst += 4;
- src += stride;
- }
-}
-
-static void DPSOFTRAST_Load4bTo4f(float *dst, const unsigned char *src, int size, int stride)
-{
- float *end = dst + size*4;
- __m128 scale = _mm_set1_ps(1.0f/255.0f);
- if (stride == sizeof(unsigned char[4]))
- {
- float *end4 = dst + (size&~3)*4;
- if (((size_t)src)&(ALIGN_SIZE - 1)) // check for alignment
- {
- while (dst < end4)
- {
- __m128i v = _mm_loadu_si128((const __m128i *)src), v1 = _mm_unpacklo_epi8(v, _mm_setzero_si128()), v2 = _mm_unpackhi_epi8(v, _mm_setzero_si128());
- _mm_store_ps(dst, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(v1, _mm_setzero_si128())), scale));
- _mm_store_ps(dst + 4, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi16(v1, _mm_setzero_si128())), scale));
- _mm_store_ps(dst + 8, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(v2, _mm_setzero_si128())), scale));
- _mm_store_ps(dst + 12, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi16(v2, _mm_setzero_si128())), scale));
- dst += 16;
- src += 4*sizeof(unsigned char[4]);
- }
- }
- else
- {
- while (dst < end4)
- {
- __m128i v = _mm_load_si128((const __m128i *)src), v1 = _mm_unpacklo_epi8(v, _mm_setzero_si128()), v2 = _mm_unpackhi_epi8(v, _mm_setzero_si128());
- _mm_store_ps(dst, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(v1, _mm_setzero_si128())), scale));
- _mm_store_ps(dst + 4, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi16(v1, _mm_setzero_si128())), scale));
- _mm_store_ps(dst + 8, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(v2, _mm_setzero_si128())), scale));
- _mm_store_ps(dst + 12, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi16(v2, _mm_setzero_si128())), scale));
- dst += 16;
- src += 4*sizeof(unsigned char[4]);
- }
- }
- }
- while (dst < end)
- {
- __m128i v = _mm_cvtsi32_si128(*(const int *)src);
- _mm_store_ps(dst, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(_mm_unpacklo_epi8(v, _mm_setzero_si128()), _mm_setzero_si128())), scale));
- dst += 4;
- src += stride;
- }
-}
-
-static void DPSOFTRAST_Fill4f(float *dst, const float *src, int size)
-{
- float *end = dst + 4*size;
- __m128 v = _mm_loadu_ps(src);
- while (dst < end)
- {
- _mm_store_ps(dst, v);
- dst += 4;
- }
-}
-#endif
-
-static void DPSOFTRAST_Vertex_Transform(float *out4f, const float *in4f, int numitems, const float *inmatrix16f)
-{
-#ifdef SSE_POSSIBLE
- static const float identitymatrix16f[4][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
- __m128 m0, m1, m2, m3;
- float *end;
- if (!memcmp(identitymatrix16f, inmatrix16f, sizeof(float[16])))
- {
- // fast case for identity matrix
- if (out4f != in4f) memcpy(out4f, in4f, numitems * sizeof(float[4]));
- return;
- }
- end = out4f + numitems*4;
- m0 = _mm_loadu_ps(inmatrix16f);
- m1 = _mm_loadu_ps(inmatrix16f + 4);
- m2 = _mm_loadu_ps(inmatrix16f + 8);
- m3 = _mm_loadu_ps(inmatrix16f + 12);
- if (((size_t)in4f)&(ALIGN_SIZE-1)) // check alignment
- {
- while (out4f < end)
- {
- __m128 v = _mm_loadu_ps(in4f);
- _mm_store_ps(out4f,
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0)), m0),
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1)), m1),
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)), m2),
- _mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(3, 3, 3, 3)), m3)))));
- out4f += 4;
- in4f += 4;
- }
- }
- else
- {
- while (out4f < end)
- {
- __m128 v = _mm_load_ps(in4f);
- _mm_store_ps(out4f,
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0)), m0),
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1)), m1),
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)), m2),
- _mm_mul_ps(_mm_shuffle_ps(v, v, _MM_SHUFFLE(3, 3, 3, 3)), m3)))));
- out4f += 4;
- in4f += 4;
- }
- }
-#endif
-}
-
-#if 0
-static void DPSOFTRAST_Vertex_Copy(float *out4f, const float *in4f, int numitems)
-{
- memcpy(out4f, in4f, numitems * sizeof(float[4]));
-}
-#endif
-
-#ifdef SSE_POSSIBLE
-#define DPSOFTRAST_PROJECTVERTEX(out, in, viewportcenter, viewportscale) \
-{ \
- __m128 p = (in), w = _mm_shuffle_ps(p, p, _MM_SHUFFLE(3, 3, 3, 3)); \
- p = _mm_move_ss(_mm_shuffle_ps(p, p, _MM_SHUFFLE(2, 1, 0, 3)), _mm_set_ss(1.0f)); \
- p = _mm_add_ps(viewportcenter, _mm_div_ps(_mm_mul_ps(viewportscale, p), w)); \
- out = _mm_shuffle_ps(p, p, _MM_SHUFFLE(0, 3, 2, 1)); \
-}
-
-#define DPSOFTRAST_TRANSFORMVERTEX(out, in, m0, m1, m2, m3) \
-{ \
- __m128 p = (in); \
- out = _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(p, p, _MM_SHUFFLE(0, 0, 0, 0)), m0), \
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(p, p, _MM_SHUFFLE(1, 1, 1, 1)), m1), \
- _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(p, p, _MM_SHUFFLE(2, 2, 2, 2)), m2), \
- _mm_mul_ps(_mm_shuffle_ps(p, p, _MM_SHUFFLE(3, 3, 3, 3)), m3)))); \
-}
-
-static int DPSOFTRAST_Vertex_BoundY(int *starty, int *endy, const float *minposf, const float *maxposf, const float *inmatrix16f)
-{
- int clipmask = 0xFF;
- __m128 viewportcenter = _mm_load_ps(dpsoftrast.fb_viewportcenter), viewportscale = _mm_load_ps(dpsoftrast.fb_viewportscale);
- __m128 bb[8], clipdist[8], minproj = _mm_set_ss(2.0f), maxproj = _mm_set_ss(-2.0f);
- __m128 m0 = _mm_loadu_ps(inmatrix16f), m1 = _mm_loadu_ps(inmatrix16f + 4), m2 = _mm_loadu_ps(inmatrix16f + 8), m3 = _mm_loadu_ps(inmatrix16f + 12);
- __m128 minpos = _mm_load_ps(minposf), maxpos = _mm_load_ps(maxposf);
- m0 = _mm_shuffle_ps(m0, m0, _MM_SHUFFLE(3, 2, 0, 1));
- m1 = _mm_shuffle_ps(m1, m1, _MM_SHUFFLE(3, 2, 0, 1));
- m2 = _mm_shuffle_ps(m2, m2, _MM_SHUFFLE(3, 2, 0, 1));
- m3 = _mm_shuffle_ps(m3, m3, _MM_SHUFFLE(3, 2, 0, 1));
- #define BBFRONT(k, pos) \
- { \
- DPSOFTRAST_TRANSFORMVERTEX(bb[k], pos, m0, m1, m2, m3); \
- clipdist[k] = _mm_add_ss(_mm_shuffle_ps(bb[k], bb[k], _MM_SHUFFLE(2, 2, 2, 2)), _mm_shuffle_ps(bb[k], bb[k], _MM_SHUFFLE(3, 3, 3, 3))); \
- if (_mm_ucomige_ss(clipdist[k], _mm_setzero_ps())) \
- { \
- __m128 proj; \
- clipmask &= ~(1<<k); \
- proj = _mm_div_ss(bb[k], _mm_shuffle_ps(bb[k], bb[k], _MM_SHUFFLE(3, 3, 3, 3))); \
- minproj = _mm_min_ss(minproj, proj); \
- maxproj = _mm_max_ss(maxproj, proj); \
- } \
- }
- BBFRONT(0, minpos);
- BBFRONT(1, _mm_move_ss(minpos, maxpos));
- BBFRONT(2, _mm_shuffle_ps(_mm_move_ss(maxpos, minpos), minpos, _MM_SHUFFLE(3, 2, 1, 0)));
- BBFRONT(3, _mm_shuffle_ps(maxpos, minpos, _MM_SHUFFLE(3, 2, 1, 0)));
- BBFRONT(4, _mm_shuffle_ps(minpos, maxpos, _MM_SHUFFLE(3, 2, 1, 0)));
- BBFRONT(5, _mm_shuffle_ps(_mm_move_ss(minpos, maxpos), maxpos, _MM_SHUFFLE(3, 2, 1, 0)));
- BBFRONT(6, _mm_move_ss(maxpos, minpos));
- BBFRONT(7, maxpos);
- #define BBCLIP(k) \
- { \
- if (clipmask&(1<<k)) \
- { \
- if (!(clipmask&(1<<(k^1)))) \
- { \
- __m128 frac = _mm_div_ss(clipdist[k], _mm_sub_ss(clipdist[k], clipdist[k^1])); \
- __m128 proj = _mm_add_ps(bb[k], _mm_mul_ps(_mm_shuffle_ps(frac, frac, _MM_SHUFFLE(0, 0, 0, 0)), _mm_sub_ps(bb[k^1], bb[k]))); \
- proj = _mm_div_ss(proj, _mm_shuffle_ps(proj, proj, _MM_SHUFFLE(3, 3, 3, 3))); \
- minproj = _mm_min_ss(minproj, proj); \
- maxproj = _mm_max_ss(maxproj, proj); \
- } \
- if (!(clipmask&(1<<(k^2)))) \
- { \
- __m128 frac = _mm_div_ss(clipdist[k], _mm_sub_ss(clipdist[k], clipdist[k^2])); \
- __m128 proj = _mm_add_ps(bb[k], _mm_mul_ps(_mm_shuffle_ps(frac, frac, _MM_SHUFFLE(0, 0, 0, 0)), _mm_sub_ps(bb[k^2], bb[k]))); \
- proj = _mm_div_ss(proj, _mm_shuffle_ps(proj, proj, _MM_SHUFFLE(3, 3, 3, 3))); \
- minproj = _mm_min_ss(minproj, proj); \
- maxproj = _mm_max_ss(maxproj, proj); \
- } \
- if (!(clipmask&(1<<(k^4)))) \
- { \
- __m128 frac = _mm_div_ss(clipdist[k], _mm_sub_ss(clipdist[k], clipdist[k^4])); \
- __m128 proj = _mm_add_ps(bb[k], _mm_mul_ps(_mm_shuffle_ps(frac, frac, _MM_SHUFFLE(0, 0, 0, 0)), _mm_sub_ps(bb[k^4], bb[k]))); \
- proj = _mm_div_ss(proj, _mm_shuffle_ps(proj, proj, _MM_SHUFFLE(3, 3, 3, 3))); \
- minproj = _mm_min_ss(minproj, proj); \
- maxproj = _mm_max_ss(maxproj, proj); \
- } \
- } \
- }
- BBCLIP(0); BBCLIP(1); BBCLIP(2); BBCLIP(3); BBCLIP(4); BBCLIP(5); BBCLIP(6); BBCLIP(7);
- viewportcenter = _mm_shuffle_ps(viewportcenter, viewportcenter, _MM_SHUFFLE(0, 3, 1, 2));
- viewportscale = _mm_shuffle_ps(viewportscale, viewportscale, _MM_SHUFFLE(0, 3, 1, 2));
- minproj = _mm_max_ss(minproj, _mm_set_ss(-2.0f));
- maxproj = _mm_min_ss(maxproj, _mm_set_ss(2.0f));
- minproj = _mm_add_ss(viewportcenter, _mm_mul_ss(minproj, viewportscale));
- maxproj = _mm_add_ss(viewportcenter, _mm_mul_ss(maxproj, viewportscale));
- *starty = _mm_cvttss_si32(maxproj);
- *endy = _mm_cvttss_si32(minproj)+1;
- return clipmask;
-}
-
-static int DPSOFTRAST_Vertex_Project(float *out4f, float *screen4f, int *starty, int *endy, const float *in4f, int numitems)
-{
- static const float identitymatrix16f[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
- float *end = out4f + numitems*4;
- __m128 viewportcenter = _mm_load_ps(dpsoftrast.fb_viewportcenter), viewportscale = _mm_load_ps(dpsoftrast.fb_viewportscale);
- __m128 minpos, maxpos;
- if (((size_t)in4f)&(ALIGN_SIZE-1)) // check alignment
- {
- minpos = maxpos = _mm_loadu_ps(in4f);
- while (out4f < end)
- {
- __m128 v = _mm_loadu_ps(in4f);
- minpos = _mm_min_ps(minpos, v);
- maxpos = _mm_max_ps(maxpos, v);
- _mm_store_ps(out4f, v);
- DPSOFTRAST_PROJECTVERTEX(v, v, viewportcenter, viewportscale);
- _mm_store_ps(screen4f, v);
- in4f += 4;
- out4f += 4;
- screen4f += 4;
- }
- }
- else
- {
- minpos = maxpos = _mm_load_ps(in4f);
- while (out4f < end)
- {
- __m128 v = _mm_load_ps(in4f);
- minpos = _mm_min_ps(minpos, v);
- maxpos = _mm_max_ps(maxpos, v);
- _mm_store_ps(out4f, v);
- DPSOFTRAST_PROJECTVERTEX(v, v, viewportcenter, viewportscale);
- _mm_store_ps(screen4f, v);
- in4f += 4;
- out4f += 4;
- screen4f += 4;
- }
- }
- if (starty && endy)
- {
- ALIGN(float minposf[4]);
- ALIGN(float maxposf[4]);
- _mm_store_ps(minposf, minpos);
- _mm_store_ps(maxposf, maxpos);
- return DPSOFTRAST_Vertex_BoundY(starty, endy, minposf, maxposf, identitymatrix16f);
- }
- return 0;
-}
-
-static int DPSOFTRAST_Vertex_TransformProject(float *out4f, float *screen4f, int *starty, int *endy, const float *in4f, int numitems, const float *inmatrix16f)
-{
- static const float identitymatrix16f[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
- __m128 m0, m1, m2, m3, viewportcenter, viewportscale, minpos, maxpos;
- float *end;
- if (!memcmp(identitymatrix16f, inmatrix16f, sizeof(float[16])))
- return DPSOFTRAST_Vertex_Project(out4f, screen4f, starty, endy, in4f, numitems);
- end = out4f + numitems*4;
- viewportcenter = _mm_load_ps(dpsoftrast.fb_viewportcenter);
- viewportscale = _mm_load_ps(dpsoftrast.fb_viewportscale);
- m0 = _mm_loadu_ps(inmatrix16f);
- m1 = _mm_loadu_ps(inmatrix16f + 4);
- m2 = _mm_loadu_ps(inmatrix16f + 8);
- m3 = _mm_loadu_ps(inmatrix16f + 12);
- if (((size_t)in4f)&(ALIGN_SIZE-1)) // check alignment
- {
- minpos = maxpos = _mm_loadu_ps(in4f);
- while (out4f < end)
- {
- __m128 v = _mm_loadu_ps(in4f);
- minpos = _mm_min_ps(minpos, v);
- maxpos = _mm_max_ps(maxpos, v);
- DPSOFTRAST_TRANSFORMVERTEX(v, v, m0, m1, m2, m3);
- _mm_store_ps(out4f, v);
- DPSOFTRAST_PROJECTVERTEX(v, v, viewportcenter, viewportscale);
- _mm_store_ps(screen4f, v);
- in4f += 4;
- out4f += 4;
- screen4f += 4;
- }
- }
- else
- {
- minpos = maxpos = _mm_load_ps(in4f);
- while (out4f < end)
- {
- __m128 v = _mm_load_ps(in4f);
- minpos = _mm_min_ps(minpos, v);
- maxpos = _mm_max_ps(maxpos, v);
- DPSOFTRAST_TRANSFORMVERTEX(v, v, m0, m1, m2, m3);
- _mm_store_ps(out4f, v);
- DPSOFTRAST_PROJECTVERTEX(v, v, viewportcenter, viewportscale);
- _mm_store_ps(screen4f, v);
- in4f += 4;
- out4f += 4;
- screen4f += 4;
- }
- }
- if (starty && endy)
- {
- ALIGN(float minposf[4]);
- ALIGN(float maxposf[4]);
- _mm_store_ps(minposf, minpos);
- _mm_store_ps(maxposf, maxpos);
- return DPSOFTRAST_Vertex_BoundY(starty, endy, minposf, maxposf, inmatrix16f);
- }
- return 0;
-}
-#endif
-
-static float *DPSOFTRAST_Array_Load(int outarray, int inarray)
-{
-#ifdef SSE_POSSIBLE
- float *outf = dpsoftrast.post_array4f[outarray];
- const unsigned char *inb;
- int firstvertex = dpsoftrast.firstvertex;
- int numvertices = dpsoftrast.numvertices;
- int stride;
- switch(inarray)
- {
- case DPSOFTRAST_ARRAY_POSITION:
- stride = dpsoftrast.stride_vertex;
- inb = (unsigned char *)dpsoftrast.pointer_vertex3f + firstvertex * stride;
- DPSOFTRAST_Load3fTo4f(outf, inb, numvertices, stride);
- break;
- case DPSOFTRAST_ARRAY_COLOR:
- stride = dpsoftrast.stride_color;
- if (dpsoftrast.pointer_color4f)
- {
- inb = (const unsigned char *)dpsoftrast.pointer_color4f + firstvertex * stride;
- DPSOFTRAST_Load4fTo4f(outf, inb, numvertices, stride);
- }
- else if (dpsoftrast.pointer_color4ub)
- {
- stride = dpsoftrast.stride_color;
- inb = (const unsigned char *)dpsoftrast.pointer_color4ub + firstvertex * stride;
- DPSOFTRAST_Load4bTo4f(outf, inb, numvertices, stride);
- }
- else
- {
- DPSOFTRAST_Fill4f(outf, dpsoftrast.color, numvertices);
- }
- break;
- default:
- stride = dpsoftrast.stride_texcoord[inarray-DPSOFTRAST_ARRAY_TEXCOORD0];
- if (dpsoftrast.pointer_texcoordf[inarray-DPSOFTRAST_ARRAY_TEXCOORD0])
- {
- inb = (const unsigned char *)dpsoftrast.pointer_texcoordf[inarray-DPSOFTRAST_ARRAY_TEXCOORD0] + firstvertex * stride;
- switch(dpsoftrast.components_texcoord[inarray-DPSOFTRAST_ARRAY_TEXCOORD0])
- {
- case 2:
- DPSOFTRAST_Load2fTo4f(outf, inb, numvertices, stride);
- break;
- case 3:
- DPSOFTRAST_Load3fTo4f(outf, inb, numvertices, stride);
- break;
- case 4:
- DPSOFTRAST_Load4fTo4f(outf, inb, numvertices, stride);
- break;
- }
- }
- break;
- }
- return outf;
-#else
- return NULL;
-#endif
-}
-
-static float *DPSOFTRAST_Array_Transform(int outarray, int inarray, const float *inmatrix16f)
-{
- float *data = inarray >= 0 ? DPSOFTRAST_Array_Load(outarray, inarray) : dpsoftrast.post_array4f[outarray];
- DPSOFTRAST_Vertex_Transform(data, data, dpsoftrast.numvertices, inmatrix16f);
- return data;
-}
-
-#if 0
-static float *DPSOFTRAST_Array_Project(int outarray, int inarray)
-{
-#ifdef SSE_POSSIBLE
- float *data = inarray >= 0 ? DPSOFTRAST_Array_Load(outarray, inarray) : dpsoftrast.post_array4f[outarray];
- dpsoftrast.drawclipped = DPSOFTRAST_Vertex_Project(data, dpsoftrast.screencoord4f, &dpsoftrast.drawstarty, &dpsoftrast.drawendy, data, dpsoftrast.numvertices);
- return data;
-#else
- return NULL;
-#endif
-}
-#endif
-
-static float *DPSOFTRAST_Array_TransformProject(int outarray, int inarray, const float *inmatrix16f)
-{
-#ifdef SSE_POSSIBLE
- float *data = inarray >= 0 ? DPSOFTRAST_Array_Load(outarray, inarray) : dpsoftrast.post_array4f[outarray];
- dpsoftrast.drawclipped = DPSOFTRAST_Vertex_TransformProject(data, dpsoftrast.screencoord4f, &dpsoftrast.drawstarty, &dpsoftrast.drawendy, data, dpsoftrast.numvertices, inmatrix16f);
- return data;
-#else
- return NULL;
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_Begin(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *zf)
-{
- int x;
- int startx = span->startx;
- int endx = span->endx;
- float wslope = triangle->w[0];
- float w = triangle->w[2] + span->x*wslope + span->y*triangle->w[1];
- float endz = 1.0f / (w + wslope * startx);
- if (triangle->w[0] == 0)
- {
- // LordHavoc: fast flat polygons (HUD/menu)
- for (x = startx;x < endx;x++)
- zf[x] = endz;
- return;
- }
- for (x = startx;x < endx;)
- {
- int nextsub = x + DPSOFTRAST_DRAW_MAXSUBSPAN, endsub = nextsub - 1;
- float z = endz, dz;
- if (nextsub >= endx) nextsub = endsub = endx-1;
- endz = 1.0f / (w + wslope * nextsub);
- dz = x < nextsub ? (endz - z) / (nextsub - x) : 0.0f;
- for (; x <= endsub; x++, z += dz)
- zf[x] = z;
- }
-}
-
-static void DPSOFTRAST_Draw_Span_FinishBGRA8(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, const unsigned char* RESTRICT in4ub)
-{
-#ifdef SSE_POSSIBLE
- int x;
- int startx = span->startx;
- int endx = span->endx;
- int maskx;
- int subx;
- const unsigned int * RESTRICT ini = (const unsigned int *)in4ub;
- unsigned char * RESTRICT pixelmask = span->pixelmask;
- unsigned int * RESTRICT pixeli = (unsigned int *)dpsoftrast.fb_colorpixels[0];
- if (!pixeli)
- return;
- pixeli += span->y * dpsoftrast.fb_width + span->x;
- // handle alphatest now (this affects depth writes too)
- if (thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL)
- for (x = startx;x < endx;x++)
- if (in4ub[x*4+3] < 128)
- pixelmask[x] = false;
- // LordHavoc: clear pixelmask for some pixels in alphablend cases, this
- // helps sprites, text and hud artwork
- switch(thread->fb_blendmode)
- {
- case DPSOFTRAST_BLENDMODE_ALPHA:
- case DPSOFTRAST_BLENDMODE_ADDALPHA:
- case DPSOFTRAST_BLENDMODE_SUBALPHA:
- maskx = startx;
- for (x = startx;x < endx;x++)
- {
- if (in4ub[x*4+3] >= 1)
- {
- startx = x;
- for (;;)
- {
- while (++x < endx && in4ub[x*4+3] >= 1) ;
- maskx = x;
- if (x >= endx) break;
- ++x;
- while (++x < endx && in4ub[x*4+3] < 1) pixelmask[x] = false;
- if (x >= endx) break;
- }
- break;
- }
- }
- endx = maskx;
- break;
- case DPSOFTRAST_BLENDMODE_OPAQUE:
- case DPSOFTRAST_BLENDMODE_ADD:
- case DPSOFTRAST_BLENDMODE_INVMOD:
- case DPSOFTRAST_BLENDMODE_MUL:
- case DPSOFTRAST_BLENDMODE_MUL2:
- case DPSOFTRAST_BLENDMODE_PSEUDOALPHA:
- case DPSOFTRAST_BLENDMODE_INVADD:
- break;
- }
- // put some special values at the end of the mask to ensure the loops end
- pixelmask[endx] = 1;
- pixelmask[endx+1] = 0;
- // LordHavoc: use a double loop to identify subspans, this helps the
- // optimized copy/blend loops to perform at their best, most triangles
- // have only one run of pixels, and do the search using wide reads...
- x = startx;
- while (x < endx)
- {
- // if this pixel is masked off, it's probably not alone...
- if (!pixelmask[x])
- {
- x++;
-#if 1
- if (x + 8 < endx)
- {
- // the 4-item search must be aligned or else it stalls badly
- if ((x & 3) && !pixelmask[x])
- {
- if(pixelmask[x]) goto endmasked;
- x++;
- if (x & 3)
- {
- if(pixelmask[x]) goto endmasked;
- x++;
- if (x & 3)
- {
- if(pixelmask[x]) goto endmasked;
- x++;
- }
- }
- }
- while (*(unsigned int *)&pixelmask[x] == 0x00000000)
- x += 4;
- }
-#endif
- for (;!pixelmask[x];x++)
- ;
- // rather than continue the loop, just check the end variable
- if (x >= endx)
- break;
- }
- endmasked:
- // find length of subspan
- subx = x + 1;
-#if 1
- if (subx + 8 < endx)
- {
- if (subx & 3)
- {
- if(!pixelmask[subx]) goto endunmasked;
- subx++;
- if (subx & 3)
- {
- if(!pixelmask[subx]) goto endunmasked;
- subx++;
- if (subx & 3)
- {
- if(!pixelmask[subx]) goto endunmasked;
- subx++;
- }
- }
- }
- while (*(unsigned int *)&pixelmask[subx] == 0x01010101)
- subx += 4;
- }
-#endif
- for (;pixelmask[subx];subx++)
- ;
- // the checks can overshoot, so make sure to clip it...
- if (subx > endx)
- subx = endx;
- endunmasked:
- // now that we know the subspan length... process!
- switch(thread->fb_blendmode)
- {
- case DPSOFTRAST_BLENDMODE_OPAQUE:
-#if 0
- if (subx - x >= 16)
- {
- memcpy(pixeli + x, ini + x, (subx - x) * sizeof(pixeli[x]));
- x = subx;
- }
- else
-#elif 1
- while (x + 16 <= subx)
- {
- _mm_storeu_si128((__m128i *)&pixeli[x], _mm_loadu_si128((const __m128i *)&ini[x]));
- _mm_storeu_si128((__m128i *)&pixeli[x+4], _mm_loadu_si128((const __m128i *)&ini[x+4]));
- _mm_storeu_si128((__m128i *)&pixeli[x+8], _mm_loadu_si128((const __m128i *)&ini[x+8]));
- _mm_storeu_si128((__m128i *)&pixeli[x+12], _mm_loadu_si128((const __m128i *)&ini[x+12]));
- x += 16;
- }
-#endif
- {
- while (x + 4 <= subx)
- {
- _mm_storeu_si128((__m128i *)&pixeli[x], _mm_loadu_si128((const __m128i *)&ini[x]));
- x += 4;
- }
- if (x + 2 <= subx)
- {
- pixeli[x] = ini[x];
- pixeli[x+1] = ini[x+1];
- x += 2;
- }
- if (x < subx)
- {
- pixeli[x] = ini[x];
- x++;
- }
- }
- break;
- case DPSOFTRAST_BLENDMODE_ALPHA:
- #define FINISHBLEND(blend2, blend1) \
- for (;x + 1 < subx;x += 2) \
- { \
- __m128i src, dst; \
- src = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&ini[x]), _mm_setzero_si128()); \
- dst = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&pixeli[x]), _mm_setzero_si128()); \
- blend2; \
- _mm_storel_epi64((__m128i *)&pixeli[x], _mm_packus_epi16(dst, dst)); \
- } \
- if (x < subx) \
- { \
- __m128i src, dst; \
- src = _mm_unpacklo_epi8(_mm_cvtsi32_si128(ini[x]), _mm_setzero_si128()); \
- dst = _mm_unpacklo_epi8(_mm_cvtsi32_si128(pixeli[x]), _mm_setzero_si128()); \
- blend1; \
- pixeli[x] = _mm_cvtsi128_si32(_mm_packus_epi16(dst, dst)); \
- x++; \
- }
- FINISHBLEND({
- __m128i blend = _mm_shufflehi_epi16(_mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3)), _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_add_epi16(dst, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(src, dst), 4), _mm_slli_epi16(blend, 4)));
- }, {
- __m128i blend = _mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_add_epi16(dst, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(src, dst), 4), _mm_slli_epi16(blend, 4)));
- });
- break;
- case DPSOFTRAST_BLENDMODE_ADDALPHA:
- FINISHBLEND({
- __m128i blend = _mm_shufflehi_epi16(_mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3)), _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_add_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(src, blend), 8));
- }, {
- __m128i blend = _mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_add_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(src, blend), 8));
- });
- break;
- case DPSOFTRAST_BLENDMODE_ADD:
- FINISHBLEND({ dst = _mm_add_epi16(src, dst); }, { dst = _mm_add_epi16(src, dst); });
- break;
- case DPSOFTRAST_BLENDMODE_INVMOD:
- FINISHBLEND({
- dst = _mm_sub_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(dst, src), 8));
- }, {
- dst = _mm_sub_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(dst, src), 8));
- });
- break;
- case DPSOFTRAST_BLENDMODE_MUL:
- FINISHBLEND({ dst = _mm_srli_epi16(_mm_mullo_epi16(src, dst), 8); }, { dst = _mm_srli_epi16(_mm_mullo_epi16(src, dst), 8); });
- break;
- case DPSOFTRAST_BLENDMODE_MUL2:
- FINISHBLEND({ dst = _mm_srli_epi16(_mm_mullo_epi16(src, dst), 7); }, { dst = _mm_srli_epi16(_mm_mullo_epi16(src, dst), 7); });
- break;
- case DPSOFTRAST_BLENDMODE_SUBALPHA:
- FINISHBLEND({
- __m128i blend = _mm_shufflehi_epi16(_mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3)), _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_sub_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(src, blend), 8));
- }, {
- __m128i blend = _mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_sub_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(src, blend), 8));
- });
- break;
- case DPSOFTRAST_BLENDMODE_PSEUDOALPHA:
- FINISHBLEND({
- __m128i blend = _mm_shufflehi_epi16(_mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3)), _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_add_epi16(src, _mm_sub_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(dst, blend), 8)));
- }, {
- __m128i blend = _mm_shufflelo_epi16(src, _MM_SHUFFLE(3, 3, 3, 3));
- dst = _mm_add_epi16(src, _mm_sub_epi16(dst, _mm_srli_epi16(_mm_mullo_epi16(dst, blend), 8)));
- });
- break;
- case DPSOFTRAST_BLENDMODE_INVADD:
- FINISHBLEND({
- dst = _mm_add_epi16(dst, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(_mm_set1_epi16(255), dst), 4), _mm_slli_epi16(src, 4)));
- }, {
- dst = _mm_add_epi16(dst, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(_mm_set1_epi16(255), dst), 4), _mm_slli_epi16(src, 4)));
- });
- break;
- }
- }
-#endif
-}
-
-static void DPSOFTRAST_Texture2DBGRA8(DPSOFTRAST_Texture *texture, int mip, float x, float y, unsigned char c[4])
- // warning: this is SLOW, only use if the optimized per-span functions won't do
-{
- const unsigned char * RESTRICT pixelbase;
- const unsigned char * RESTRICT pixel[4];
- int width = texture->mipmap[mip][2], height = texture->mipmap[mip][3];
- int wrapmask[2] = { width-1, height-1 };
- pixelbase = (unsigned char *)texture->bytes + texture->mipmap[mip][0] + texture->mipmap[mip][1] - 4*width;
- if(texture->filter & DPSOFTRAST_TEXTURE_FILTER_LINEAR)
- {
- unsigned int tc[2] = { (unsigned int)floor(x) * (width<<12) - 2048, (unsigned int)floor(y) * (height<<12) - 2048};
- unsigned int frac[2] = { tc[0]&0xFFF, tc[1]&0xFFF };
- unsigned int ifrac[2] = { 0x1000 - frac[0], 0x1000 - frac[1] };
- unsigned int lerp[4] = { ifrac[0]*ifrac[1], frac[0]*ifrac[1], ifrac[0]*frac[1], frac[0]*frac[1] };
- int tci[2] = { (int)tc[0]>>12, (int)tc[1]>>12 };
- int tci1[2] = { (int)tci[0] + 1, (int)tci[1] + 1 };
- if (texture->flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
- {
- tci[0] = tci[0] >= 0 ? (tci[0] <= wrapmask[0] ? tci[0] : wrapmask[0]) : 0;
- tci[1] = tci[1] >= 0 ? (tci[1] <= wrapmask[1] ? tci[1] : wrapmask[1]) : 0;
- tci1[0] = tci1[0] >= 0 ? (tci1[0] <= wrapmask[0] ? tci1[0] : wrapmask[0]) : 0;
- tci1[1] = tci1[1] >= 0 ? (tci1[1] <= wrapmask[1] ? tci1[1] : wrapmask[1]) : 0;
- }
- else
- {
- tci[0] &= wrapmask[0];
- tci[1] &= wrapmask[1];
- tci1[0] &= wrapmask[0];
- tci1[1] &= wrapmask[1];
- }
- pixel[0] = pixelbase + 4 * (tci[0] - tci[1]*width);
- pixel[1] = pixelbase + 4 * (tci[0] - tci[1]*width);
- pixel[2] = pixelbase + 4 * (tci[0] - tci1[1]*width);
- pixel[3] = pixelbase + 4 * (tci[0] - tci1[1]*width);
- c[0] = (pixel[0][0]*lerp[0]+pixel[1][0]*lerp[1]+pixel[2][0]*lerp[2]+pixel[3][0]*lerp[3])>>24;
- c[1] = (pixel[0][1]*lerp[0]+pixel[1][1]*lerp[1]+pixel[2][1]*lerp[2]+pixel[3][1]*lerp[3])>>24;
- c[2] = (pixel[0][2]*lerp[0]+pixel[1][2]*lerp[1]+pixel[2][2]*lerp[2]+pixel[3][2]*lerp[3])>>24;
- c[3] = (pixel[0][3]*lerp[0]+pixel[1][3]*lerp[1]+pixel[2][3]*lerp[2]+pixel[3][3]*lerp[3])>>24;
- }
- else
- {
- int tci[2] = { (int)floor(x) * width, (int)floor(y) * height };
- if (texture->flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
- {
- tci[0] = tci[0] >= 0 ? (tci[0] <= wrapmask[0] ? tci[0] : wrapmask[0]) : 0;
- tci[1] = tci[1] >= 0 ? (tci[1] <= wrapmask[1] ? tci[1] : wrapmask[1]) : 0;
- }
- else
- {
- tci[0] &= wrapmask[0];
- tci[1] &= wrapmask[1];
- }
- pixel[0] = pixelbase + 4 * (tci[0] - tci[1]*width);
- c[0] = pixel[0][0];
- c[1] = pixel[0][1];
- c[2] = pixel[0][2];
- c[3] = pixel[0][3];
- }
-}
-
-#if 0
-static void DPSOFTRAST_Draw_Span_Texture2DVarying(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float * RESTRICT out4f, int texunitindex, int arrayindex, const float * RESTRICT zf)
-{
- int x;
- int startx = span->startx;
- int endx = span->endx;
- int flags;
- float c[4];
- float data[4];
- float slope[4];
- float tc[2], endtc[2];
- float tcscale[2];
- unsigned int tci[2];
- unsigned int tci1[2];
- unsigned int tcimin[2];
- unsigned int tcimax[2];
- int tciwrapmask[2];
- int tciwidth;
- int filter;
- int mip;
- const unsigned char * RESTRICT pixelbase;
- const unsigned char * RESTRICT pixel[4];
- DPSOFTRAST_Texture *texture = thread->texbound[texunitindex];
- // if no texture is bound, just fill it with white
- if (!texture)
- {
- for (x = startx;x < endx;x++)
- {
- out4f[x*4+0] = 1.0f;
- out4f[x*4+1] = 1.0f;
- out4f[x*4+2] = 1.0f;
- out4f[x*4+3] = 1.0f;
- }
- return;
- }
- mip = triangle->mip[texunitindex];
- pixelbase = (unsigned char *)texture->bytes + texture->mipmap[mip][0] + texture->mipmap[mip][1] - 4*texture->mipmap[mip][2];
- // if this mipmap of the texture is 1 pixel, just fill it with that color
- if (texture->mipmap[mip][1] == 4)
- {
- c[0] = texture->bytes[2] * (1.0f/255.0f);
- c[1] = texture->bytes[1] * (1.0f/255.0f);
- c[2] = texture->bytes[0] * (1.0f/255.0f);
- c[3] = texture->bytes[3] * (1.0f/255.0f);
- for (x = startx;x < endx;x++)
- {
- out4f[x*4+0] = c[0];
- out4f[x*4+1] = c[1];
- out4f[x*4+2] = c[2];
- out4f[x*4+3] = c[3];
- }
- return;
- }
- filter = texture->filter & DPSOFTRAST_TEXTURE_FILTER_LINEAR;
- DPSOFTRAST_CALCATTRIB4F(triangle, span, data, slope, arrayindex);
- flags = texture->flags;
- tcscale[0] = texture->mipmap[mip][2];
- tcscale[1] = texture->mipmap[mip][3];
- tciwidth = -texture->mipmap[mip][2];
- tcimin[0] = 0;
- tcimin[1] = 0;
- tcimax[0] = texture->mipmap[mip][2]-1;
- tcimax[1] = texture->mipmap[mip][3]-1;
- tciwrapmask[0] = texture->mipmap[mip][2]-1;
- tciwrapmask[1] = texture->mipmap[mip][3]-1;
- endtc[0] = (data[0] + slope[0]*startx) * zf[startx] * tcscale[0];
- endtc[1] = (data[1] + slope[1]*startx) * zf[startx] * tcscale[1];
- if (filter)
- {
- endtc[0] -= 0.5f;
- endtc[1] -= 0.5f;
- }
- for (x = startx;x < endx;)
- {
- unsigned int subtc[2];
- unsigned int substep[2];
- float subscale = 4096.0f/DPSOFTRAST_DRAW_MAXSUBSPAN;
- int nextsub = x + DPSOFTRAST_DRAW_MAXSUBSPAN, endsub = nextsub - 1;
- if (nextsub >= endx)
- {
- nextsub = endsub = endx-1;
- if (x < nextsub) subscale = 4096.0f / (nextsub - x);
- }
- tc[0] = endtc[0];
- tc[1] = endtc[1];
- endtc[0] = (data[0] + slope[0]*nextsub) * zf[nextsub] * tcscale[0];
- endtc[1] = (data[1] + slope[1]*nextsub) * zf[nextsub] * tcscale[1];
- if (filter)
- {
- endtc[0] -= 0.5f;
- endtc[1] -= 0.5f;
- }
- substep[0] = (endtc[0] - tc[0]) * subscale;
- substep[1] = (endtc[1] - tc[1]) * subscale;
- subtc[0] = tc[0] * (1<<12);
- subtc[1] = tc[1] * (1<<12);
- if (filter)
- {
- if (flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
- {
- for (; x <= endsub; x++, subtc[0] += substep[0], subtc[1] += substep[1])
- {
- unsigned int frac[2] = { subtc[0]&0xFFF, subtc[1]&0xFFF };
- unsigned int ifrac[2] = { 0x1000 - frac[0], 0x1000 - frac[1] };
- unsigned int lerp[4] = { ifrac[0]*ifrac[1], frac[0]*ifrac[1], ifrac[0]*frac[1], frac[0]*frac[1] };
- tci[0] = subtc[0]>>12;
- tci[1] = subtc[1]>>12;
- tci1[0] = tci[0] + 1;
- tci1[1] = tci[1] + 1;
- tci[0] = tci[0] >= tcimin[0] ? (tci[0] <= tcimax[0] ? tci[0] : tcimax[0]) : tcimin[0];
- tci[1] = tci[1] >= tcimin[1] ? (tci[1] <= tcimax[1] ? tci[1] : tcimax[1]) : tcimin[1];
- tci1[0] = tci1[0] >= tcimin[0] ? (tci1[0] <= tcimax[0] ? tci1[0] : tcimax[0]) : tcimin[0];
- tci1[1] = tci1[1] >= tcimin[1] ? (tci1[1] <= tcimax[1] ? tci1[1] : tcimax[1]) : tcimin[1];
- pixel[0] = pixelbase + 4 * (tci[1]*tciwidth+tci[0]);
- pixel[1] = pixelbase + 4 * (tci[1]*tciwidth+tci1[0]);
- pixel[2] = pixelbase + 4 * (tci1[1]*tciwidth+tci[0]);
- pixel[3] = pixelbase + 4 * (tci1[1]*tciwidth+tci1[0]);
- c[0] = (pixel[0][2]*lerp[0]+pixel[1][2]*lerp[1]+pixel[2][2]*lerp[2]+pixel[3][2]*lerp[3]) * (1.0f / 0xFF000000);
- c[1] = (pixel[0][1]*lerp[0]+pixel[1][1]*lerp[1]+pixel[2][1]*lerp[2]+pixel[3][1]*lerp[3]) * (1.0f / 0xFF000000);
- c[2] = (pixel[0][0]*lerp[0]+pixel[1][0]*lerp[1]+pixel[2][0]*lerp[2]+pixel[3][0]*lerp[3]) * (1.0f / 0xFF000000);
- c[3] = (pixel[0][3]*lerp[0]+pixel[1][3]*lerp[1]+pixel[2][3]*lerp[2]+pixel[3][3]*lerp[3]) * (1.0f / 0xFF000000);
- out4f[x*4+0] = c[0];
- out4f[x*4+1] = c[1];
- out4f[x*4+2] = c[2];
- out4f[x*4+3] = c[3];
- }
- }
- else
- {
- for (; x <= endsub; x++, subtc[0] += substep[0], subtc[1] += substep[1])
- {
- unsigned int frac[2] = { subtc[0]&0xFFF, subtc[1]&0xFFF };
- unsigned int ifrac[2] = { 0x1000 - frac[0], 0x1000 - frac[1] };
- unsigned int lerp[4] = { ifrac[0]*ifrac[1], frac[0]*ifrac[1], ifrac[0]*frac[1], frac[0]*frac[1] };
- tci[0] = subtc[0]>>12;
- tci[1] = subtc[1]>>12;
- tci1[0] = tci[0] + 1;
- tci1[1] = tci[1] + 1;
- tci[0] &= tciwrapmask[0];
- tci[1] &= tciwrapmask[1];
- tci1[0] &= tciwrapmask[0];
- tci1[1] &= tciwrapmask[1];
- pixel[0] = pixelbase + 4 * (tci[1]*tciwidth+tci[0]);
- pixel[1] = pixelbase + 4 * (tci[1]*tciwidth+tci1[0]);
- pixel[2] = pixelbase + 4 * (tci1[1]*tciwidth+tci[0]);
- pixel[3] = pixelbase + 4 * (tci1[1]*tciwidth+tci1[0]);
- c[0] = (pixel[0][2]*lerp[0]+pixel[1][2]*lerp[1]+pixel[2][2]*lerp[2]+pixel[3][2]*lerp[3]) * (1.0f / 0xFF000000);
- c[1] = (pixel[0][1]*lerp[0]+pixel[1][1]*lerp[1]+pixel[2][1]*lerp[2]+pixel[3][1]*lerp[3]) * (1.0f / 0xFF000000);
- c[2] = (pixel[0][0]*lerp[0]+pixel[1][0]*lerp[1]+pixel[2][0]*lerp[2]+pixel[3][0]*lerp[3]) * (1.0f / 0xFF000000);
- c[3] = (pixel[0][3]*lerp[0]+pixel[1][3]*lerp[1]+pixel[2][3]*lerp[2]+pixel[3][3]*lerp[3]) * (1.0f / 0xFF000000);
- out4f[x*4+0] = c[0];
- out4f[x*4+1] = c[1];
- out4f[x*4+2] = c[2];
- out4f[x*4+3] = c[3];
- }
- }
- }
- else if (flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
- {
- for (; x <= endsub; x++, subtc[0] += substep[0], subtc[1] += substep[1])
- {
- tci[0] = subtc[0]>>12;
- tci[1] = subtc[1]>>12;
- tci[0] = tci[0] >= tcimin[0] ? (tci[0] <= tcimax[0] ? tci[0] : tcimax[0]) : tcimin[0];
- tci[1] = tci[1] >= tcimin[1] ? (tci[1] <= tcimax[1] ? tci[1] : tcimax[1]) : tcimin[1];
- pixel[0] = pixelbase + 4 * (tci[1]*tciwidth+tci[0]);
- c[0] = pixel[0][2] * (1.0f / 255.0f);
- c[1] = pixel[0][1] * (1.0f / 255.0f);
- c[2] = pixel[0][0] * (1.0f / 255.0f);
- c[3] = pixel[0][3] * (1.0f / 255.0f);
- out4f[x*4+0] = c[0];
- out4f[x*4+1] = c[1];
- out4f[x*4+2] = c[2];
- out4f[x*4+3] = c[3];
- }
- }
- else
- {
- for (; x <= endsub; x++, subtc[0] += substep[0], subtc[1] += substep[1])
- {
- tci[0] = subtc[0]>>12;
- tci[1] = subtc[1]>>12;
- tci[0] &= tciwrapmask[0];
- tci[1] &= tciwrapmask[1];
- pixel[0] = pixelbase + 4 * (tci[1]*tciwidth+tci[0]);
- c[0] = pixel[0][2] * (1.0f / 255.0f);
- c[1] = pixel[0][1] * (1.0f / 255.0f);
- c[2] = pixel[0][0] * (1.0f / 255.0f);
- c[3] = pixel[0][3] * (1.0f / 255.0f);
- out4f[x*4+0] = c[0];
- out4f[x*4+1] = c[1];
- out4f[x*4+2] = c[2];
- out4f[x*4+3] = c[3];
- }
- }
- }
-}
-#endif
-
-static void DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char * RESTRICT out4ub, int texunitindex, int arrayindex, const float * RESTRICT zf)
-{
-#ifdef SSE_POSSIBLE
- int x;
- int startx = span->startx;
- int endx = span->endx;
- int flags;
- __m128 data, slope, tcscale;
- __m128i tcsize, tcmask, tcoffset, tcmax;
- __m128 tc, endtc;
- __m128i subtc, substep, endsubtc;
- int filter;
- int mip;
- int affine; // LordHavoc: optimized affine texturing case
- unsigned int * RESTRICT outi = (unsigned int *)out4ub;
- const unsigned char * RESTRICT pixelbase;
- DPSOFTRAST_Texture *texture = thread->texbound[texunitindex];
- // if no texture is bound, just fill it with white
- if (!texture)
- {
- memset(out4ub + startx*4, 255, (span->endx - span->startx)*4);
- return;
- }
- mip = triangle->mip[texunitindex];
- pixelbase = (const unsigned char *)texture->bytes + texture->mipmap[mip][0] + texture->mipmap[mip][1] - 4*texture->mipmap[mip][2];
- // if this mipmap of the texture is 1 pixel, just fill it with that color
- if (texture->mipmap[mip][1] == 4)
- {
- unsigned int k = *((const unsigned int *)pixelbase);
- for (x = startx;x < endx;x++)
- outi[x] = k;
- return;
- }
- affine = zf[startx] == zf[endx-1];
- filter = texture->filter & DPSOFTRAST_TEXTURE_FILTER_LINEAR;
- DPSOFTRAST_CALCATTRIB(triangle, span, data, slope, arrayindex);
- flags = texture->flags;
- tcsize = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i *)&texture->mipmap[mip][0]), _MM_SHUFFLE(3, 2, 3, 2));
- tcmask = _mm_sub_epi32(tcsize, _mm_set1_epi32(1));
- tcscale = _mm_cvtepi32_ps(tcsize);
- data = _mm_mul_ps(_mm_movelh_ps(data, data), tcscale);
- slope = _mm_mul_ps(_mm_movelh_ps(slope, slope), tcscale);
- endtc = _mm_mul_ps(_mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(startx))), _mm_load1_ps(&zf[startx]));
- if (filter)
- endtc = _mm_sub_ps(endtc, _mm_set1_ps(0.5f));
- endsubtc = _mm_cvtps_epi32(_mm_mul_ps(endtc, _mm_set1_ps(65536.0f)));
- tcoffset = _mm_add_epi32(_mm_slli_epi32(_mm_sub_epi32(_mm_setzero_si128(), _mm_shuffle_epi32(tcsize, _MM_SHUFFLE(0, 0, 0, 0))), 18), _mm_set1_epi32(4));
- tcmax = _mm_packs_epi32(tcmask, tcmask);
- for (x = startx;x < endx;)
- {
- int nextsub = x + DPSOFTRAST_DRAW_MAXSUBSPAN, endsub = nextsub - 1;
- __m128 subscale = _mm_set1_ps(65536.0f/DPSOFTRAST_DRAW_MAXSUBSPAN);
- if (nextsub >= endx || affine)
- {
- nextsub = endsub = endx-1;
- if (x < nextsub) subscale = _mm_set1_ps(65536.0f / (nextsub - x));
- }
- tc = endtc;
- subtc = endsubtc;
- endtc = _mm_mul_ps(_mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(nextsub))), _mm_load1_ps(&zf[nextsub]));
- if (filter)
- endtc = _mm_sub_ps(endtc, _mm_set1_ps(0.5f));
- substep = _mm_cvtps_epi32(_mm_mul_ps(_mm_sub_ps(endtc, tc), subscale));
- endsubtc = _mm_cvtps_epi32(_mm_mul_ps(endtc, _mm_set1_ps(65536.0f)));
- subtc = _mm_unpacklo_epi64(subtc, _mm_add_epi32(subtc, substep));
- substep = _mm_slli_epi32(substep, 1);
- if (filter)
- {
- __m128i tcrange = _mm_srai_epi32(_mm_unpacklo_epi64(subtc, _mm_add_epi32(endsubtc, substep)), 16);
- if (_mm_movemask_epi8(_mm_andnot_si128(_mm_cmplt_epi32(tcrange, _mm_setzero_si128()), _mm_cmplt_epi32(tcrange, tcmask))) == 0xFFFF)
- {
- int stride = _mm_cvtsi128_si32(tcoffset)>>16;
- for (; x + 1 <= endsub; x += 2, subtc = _mm_add_epi32(subtc, substep))
- {
- const unsigned char * RESTRICT ptr1, * RESTRICT ptr2;
- __m128i tci = _mm_shufflehi_epi16(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(3, 1, 3, 1)), pix1, pix2, pix3, pix4, fracm;
- tci = _mm_madd_epi16(tci, tcoffset);
- ptr1 = pixelbase + _mm_cvtsi128_si32(tci);
- ptr2 = pixelbase + _mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)));
- pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)ptr1), _mm_setzero_si128());
- pix2 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(ptr1 + stride)), _mm_setzero_si128());
- pix3 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)ptr2), _mm_setzero_si128());
- pix4 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(ptr2 + stride)), _mm_setzero_si128());
- fracm = _mm_srli_epi16(subtc, 1);
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shuffle_epi32(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(1, 0, 1, 0))));
- pix3 = _mm_add_epi16(pix3,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix4, pix3), 1),
- _mm_shuffle_epi32(_mm_shufflehi_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(3, 2, 3, 2))));
- pix2 = _mm_unpacklo_epi64(pix1, pix3);
- pix4 = _mm_unpackhi_epi64(pix1, pix3);
- pix2 = _mm_add_epi16(pix2,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix4, pix2), 1),
- _mm_shufflehi_epi16(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(0, 0, 0, 0)), _MM_SHUFFLE(0, 0, 0, 0))));
- _mm_storel_epi64((__m128i *)&outi[x], _mm_packus_epi16(pix2, _mm_shufflelo_epi16(pix2, _MM_SHUFFLE(3, 2, 3, 2))));
- }
- if (x <= endsub)
- {
- const unsigned char * RESTRICT ptr1;
- __m128i tci = _mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), pix1, pix2, fracm;
- tci = _mm_madd_epi16(tci, tcoffset);
- ptr1 = pixelbase + _mm_cvtsi128_si32(tci);
- pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)ptr1), _mm_setzero_si128());
- pix2 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(ptr1 + stride)), _mm_setzero_si128());
- fracm = _mm_srli_epi16(subtc, 1);
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shuffle_epi32(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(1, 0, 1, 0))));
- pix2 = _mm_shuffle_epi32(pix1, _MM_SHUFFLE(3, 2, 3, 2));
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shufflelo_epi16(fracm, _MM_SHUFFLE(0, 0, 0, 0))));
- outi[x] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- x++;
- }
- }
- else if (flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
- {
- for (; x + 1 <= endsub; x += 2, subtc = _mm_add_epi32(subtc, substep))
- {
- __m128i tci = _mm_shuffle_epi32(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(1, 0, 1, 0)), pix1, pix2, pix3, pix4, fracm;
- tci = _mm_min_epi16(_mm_max_epi16(_mm_add_epi16(tci, _mm_setr_epi32(0, 1, 0x10000, 0x10001)), _mm_setzero_si128()), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- pix1 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(tci)]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(1, 1, 1, 1)))])),
- _mm_setzero_si128());
- pix2 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(3, 3, 3, 3)))])),
- _mm_setzero_si128());
- tci = _mm_shuffle_epi32(_mm_shufflehi_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(3, 2, 3, 2));
- tci = _mm_and_si128(_mm_add_epi16(tci, _mm_setr_epi32(0, 1, 0x10000, 0x10001)), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- pix3 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(tci)]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(1, 1, 1, 1)))])),
- _mm_setzero_si128());
- pix4 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(3, 3, 3, 3)))])),
- _mm_setzero_si128());
- fracm = _mm_srli_epi16(subtc, 1);
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shuffle_epi32(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(1, 0, 1, 0))));
- pix3 = _mm_add_epi16(pix3,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix4, pix3), 1),
- _mm_shuffle_epi32(_mm_shufflehi_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(3, 2, 3, 2))));
- pix2 = _mm_unpacklo_epi64(pix1, pix3);
- pix4 = _mm_unpackhi_epi64(pix1, pix3);
- pix2 = _mm_add_epi16(pix2,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix4, pix2), 1),
- _mm_shufflehi_epi16(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(0, 0, 0, 0)), _MM_SHUFFLE(0, 0, 0, 0))));
- _mm_storel_epi64((__m128i *)&outi[x], _mm_packus_epi16(pix2, _mm_shufflelo_epi16(pix2, _MM_SHUFFLE(3, 2, 3, 2))));
- }
- if (x <= endsub)
- {
- __m128i tci = _mm_shuffle_epi32(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(1, 0, 1, 0)), pix1, pix2, fracm;
- tci = _mm_min_epi16(_mm_max_epi16(_mm_add_epi16(tci, _mm_setr_epi32(0, 1, 0x10000, 0x10001)), _mm_setzero_si128()), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- pix1 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(tci)]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(1, 1, 1, 1)))])),
- _mm_setzero_si128());
- pix2 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(3, 3, 3, 3)))])),
- _mm_setzero_si128());
- fracm = _mm_srli_epi16(subtc, 1);
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shuffle_epi32(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(1, 0, 1, 0))));
- pix2 = _mm_shuffle_epi32(pix1, _MM_SHUFFLE(3, 2, 3, 2));
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shufflelo_epi16(fracm, _MM_SHUFFLE(0, 0, 0, 0))));
- outi[x] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- x++;
- }
- }
- else
- {
- for (; x + 1 <= endsub; x += 2, subtc = _mm_add_epi32(subtc, substep))
- {
- __m128i tci = _mm_shuffle_epi32(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(1, 0, 1, 0)), pix1, pix2, pix3, pix4, fracm;
- tci = _mm_and_si128(_mm_add_epi16(tci, _mm_setr_epi32(0, 1, 0x10000, 0x10001)), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- pix1 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(tci)]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(1, 1, 1, 1)))])),
- _mm_setzero_si128());
- pix2 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(3, 3, 3, 3)))])),
- _mm_setzero_si128());
- tci = _mm_shuffle_epi32(_mm_shufflehi_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(3, 2, 3, 2));
- tci = _mm_and_si128(_mm_add_epi16(tci, _mm_setr_epi32(0, 1, 0x10000, 0x10001)), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- pix3 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(tci)]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(1, 1, 1, 1)))])),
- _mm_setzero_si128());
- pix4 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(3, 3, 3, 3)))])),
- _mm_setzero_si128());
- fracm = _mm_srli_epi16(subtc, 1);
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shuffle_epi32(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(1, 0, 1, 0))));
- pix3 = _mm_add_epi16(pix3,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix4, pix3), 1),
- _mm_shuffle_epi32(_mm_shufflehi_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(3, 2, 3, 2))));
- pix2 = _mm_unpacklo_epi64(pix1, pix3);
- pix4 = _mm_unpackhi_epi64(pix1, pix3);
- pix2 = _mm_add_epi16(pix2,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix4, pix2), 1),
- _mm_shufflehi_epi16(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(0, 0, 0, 0)), _MM_SHUFFLE(0, 0, 0, 0))));
- _mm_storel_epi64((__m128i *)&outi[x], _mm_packus_epi16(pix2, _mm_shufflelo_epi16(pix2, _MM_SHUFFLE(3, 2, 3, 2))));
- }
- if (x <= endsub)
- {
- __m128i tci = _mm_shuffle_epi32(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(1, 0, 1, 0)), pix1, pix2, fracm;
- tci = _mm_and_si128(_mm_add_epi16(tci, _mm_setr_epi32(0, 1, 0x10000, 0x10001)), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- pix1 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(tci)]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(1, 1, 1, 1)))])),
- _mm_setzero_si128());
- pix2 = _mm_unpacklo_epi8(_mm_unpacklo_epi32(_mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))]),
- _mm_cvtsi32_si128(*(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(3, 3, 3, 3)))])),
- _mm_setzero_si128());
- fracm = _mm_srli_epi16(subtc, 1);
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shuffle_epi32(_mm_shufflelo_epi16(fracm, _MM_SHUFFLE(2, 2, 2, 2)), _MM_SHUFFLE(1, 0, 1, 0))));
- pix2 = _mm_shuffle_epi32(pix1, _MM_SHUFFLE(3, 2, 3, 2));
- pix1 = _mm_add_epi16(pix1,
- _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 1),
- _mm_shufflelo_epi16(fracm, _MM_SHUFFLE(0, 0, 0, 0))));
- outi[x] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- x++;
- }
- }
- }
- else
- {
- if (flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
- {
- for (; x + 1 <= endsub; x += 2, subtc = _mm_add_epi32(subtc, substep))
- {
- __m128i tci = _mm_shufflehi_epi16(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(3, 1, 3, 1));
- tci = _mm_min_epi16(_mm_max_epi16(tci, _mm_setzero_si128()), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- outi[x] = *(const int *)&pixelbase[_mm_cvtsi128_si32(tci)];
- outi[x+1] = *(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))];
- }
- if (x <= endsub)
- {
- __m128i tci = _mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1));
- tci =_mm_min_epi16(_mm_max_epi16(tci, _mm_setzero_si128()), tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- outi[x] = *(const int *)&pixelbase[_mm_cvtsi128_si32(tci)];
- x++;
- }
- }
- else
- {
- for (; x + 1 <= endsub; x += 2, subtc = _mm_add_epi32(subtc, substep))
- {
- __m128i tci = _mm_shufflehi_epi16(_mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1)), _MM_SHUFFLE(3, 1, 3, 1));
- tci = _mm_and_si128(tci, tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- outi[x] = *(const int *)&pixelbase[_mm_cvtsi128_si32(tci)];
- outi[x+1] = *(const int *)&pixelbase[_mm_cvtsi128_si32(_mm_shuffle_epi32(tci, _MM_SHUFFLE(2, 2, 2, 2)))];
- }
- if (x <= endsub)
- {
- __m128i tci = _mm_shufflelo_epi16(subtc, _MM_SHUFFLE(3, 1, 3, 1));
- tci = _mm_and_si128(tci, tcmax);
- tci = _mm_madd_epi16(tci, tcoffset);
- outi[x] = *(const int *)&pixelbase[_mm_cvtsi128_si32(tci)];
- x++;
- }
- }
- }
- }
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_TextureCubeVaryingBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char * RESTRICT out4ub, int texunitindex, int arrayindex, const float * RESTRICT zf)
-{
- // TODO: IMPLEMENT
- memset(out4ub + span->startx*4, 255, (span->startx - span->endx)*4);
-}
-
-static float DPSOFTRAST_SampleShadowmap(const float *vector)
-{
- // TODO: IMPLEMENT
- return 1.0f;
-}
-
-#if 0
-static void DPSOFTRAST_Draw_Span_MultiplyVarying(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, const float *in4f, int arrayindex, const float *zf)
-{
- int x;
- int startx = span->startx;
- int endx = span->endx;
- float c[4];
- float data[4];
- float slope[4];
- float z;
- DPSOFTRAST_CALCATTRIB4F(triangle, span, data, slope, arrayindex);
- for (x = startx;x < endx;x++)
- {
- z = zf[x];
- c[0] = (data[0] + slope[0]*x) * z;
- c[1] = (data[1] + slope[1]*x) * z;
- c[2] = (data[2] + slope[2]*x) * z;
- c[3] = (data[3] + slope[3]*x) * z;
- out4f[x*4+0] = in4f[x*4+0] * c[0];
- out4f[x*4+1] = in4f[x*4+1] * c[1];
- out4f[x*4+2] = in4f[x*4+2] * c[2];
- out4f[x*4+3] = in4f[x*4+3] * c[3];
- }
-}
-#endif
-
-#if 0
-static void DPSOFTRAST_Draw_Span_Varying(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, int arrayindex, const float *zf)
-{
- int x;
- int startx = span->startx;
- int endx = span->endx;
- float c[4];
- float data[4];
- float slope[4];
- float z;
- DPSOFTRAST_CALCATTRIB4F(triangle, span, data, slope, arrayindex);
- for (x = startx;x < endx;x++)
- {
- z = zf[x];
- c[0] = (data[0] + slope[0]*x) * z;
- c[1] = (data[1] + slope[1]*x) * z;
- c[2] = (data[2] + slope[2]*x) * z;
- c[3] = (data[3] + slope[3]*x) * z;
- out4f[x*4+0] = c[0];
- out4f[x*4+1] = c[1];
- out4f[x*4+2] = c[2];
- out4f[x*4+3] = c[3];
- }
-}
-#endif
-
-#if 0
-static void DPSOFTRAST_Draw_Span_AddBloom(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, const float *ina4f, const float *inb4f, const float *subcolor)
-{
- int x, startx = span->startx, endx = span->endx;
- float c[4], localcolor[4];
- localcolor[0] = subcolor[0];
- localcolor[1] = subcolor[1];
- localcolor[2] = subcolor[2];
- localcolor[3] = subcolor[3];
- for (x = startx;x < endx;x++)
- {
- c[0] = inb4f[x*4+0] - localcolor[0];if (c[0] < 0.0f) c[0] = 0.0f;
- c[1] = inb4f[x*4+1] - localcolor[1];if (c[1] < 0.0f) c[1] = 0.0f;
- c[2] = inb4f[x*4+2] - localcolor[2];if (c[2] < 0.0f) c[2] = 0.0f;
- c[3] = inb4f[x*4+3] - localcolor[3];if (c[3] < 0.0f) c[3] = 0.0f;
- out4f[x*4+0] = ina4f[x*4+0] + c[0];
- out4f[x*4+1] = ina4f[x*4+1] + c[1];
- out4f[x*4+2] = ina4f[x*4+2] + c[2];
- out4f[x*4+3] = ina4f[x*4+3] + c[3];
- }
-}
-#endif
-
-#if 0
-static void DPSOFTRAST_Draw_Span_MultiplyBuffers(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, const float *ina4f, const float *inb4f)
-{
- int x, startx = span->startx, endx = span->endx;
- for (x = startx;x < endx;x++)
- {
- out4f[x*4+0] = ina4f[x*4+0] * inb4f[x*4+0];
- out4f[x*4+1] = ina4f[x*4+1] * inb4f[x*4+1];
- out4f[x*4+2] = ina4f[x*4+2] * inb4f[x*4+2];
- out4f[x*4+3] = ina4f[x*4+3] * inb4f[x*4+3];
- }
-}
-#endif
-
-#if 0
-static void DPSOFTRAST_Draw_Span_AddBuffers(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, const float *ina4f, const float *inb4f)
-{
- int x, startx = span->startx, endx = span->endx;
- for (x = startx;x < endx;x++)
- {
- out4f[x*4+0] = ina4f[x*4+0] + inb4f[x*4+0];
- out4f[x*4+1] = ina4f[x*4+1] + inb4f[x*4+1];
- out4f[x*4+2] = ina4f[x*4+2] + inb4f[x*4+2];
- out4f[x*4+3] = ina4f[x*4+3] + inb4f[x*4+3];
- }
-}
-#endif
-
-#if 0
-static void DPSOFTRAST_Draw_Span_MixBuffers(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, const float *ina4f, const float *inb4f)
-{
- int x, startx = span->startx, endx = span->endx;
- float a, b;
- for (x = startx;x < endx;x++)
- {
- a = 1.0f - inb4f[x*4+3];
- b = inb4f[x*4+3];
- out4f[x*4+0] = ina4f[x*4+0] * a + inb4f[x*4+0] * b;
- out4f[x*4+1] = ina4f[x*4+1] * a + inb4f[x*4+1] * b;
- out4f[x*4+2] = ina4f[x*4+2] * a + inb4f[x*4+2] * b;
- out4f[x*4+3] = ina4f[x*4+3] * a + inb4f[x*4+3] * b;
- }
-}
-#endif
-
-#if 0
-static void DPSOFTRAST_Draw_Span_MixUniformColor(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, float *out4f, const float *in4f, const float *color)
-{
- int x, startx = span->startx, endx = span->endx;
- float localcolor[4], ilerp, lerp;
- localcolor[0] = color[0];
- localcolor[1] = color[1];
- localcolor[2] = color[2];
- localcolor[3] = color[3];
- ilerp = 1.0f - localcolor[3];
- lerp = localcolor[3];
- for (x = startx;x < endx;x++)
- {
- out4f[x*4+0] = in4f[x*4+0] * ilerp + localcolor[0] * lerp;
- out4f[x*4+1] = in4f[x*4+1] * ilerp + localcolor[1] * lerp;
- out4f[x*4+2] = in4f[x*4+2] * ilerp + localcolor[2] * lerp;
- out4f[x*4+3] = in4f[x*4+3] * ilerp + localcolor[3] * lerp;
- }
-}
-#endif
-
-
-
-static void DPSOFTRAST_Draw_Span_MultiplyVaryingBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *in4ub, int arrayindex, const float *zf)
-{
-#ifdef SSE_POSSIBLE
- int x;
- int startx = span->startx;
- int endx = span->endx;
- __m128 data, slope;
- __m128 mod, endmod;
- __m128i submod, substep, endsubmod;
- DPSOFTRAST_CALCATTRIB(triangle, span, data, slope, arrayindex);
- data = _mm_shuffle_ps(data, data, _MM_SHUFFLE(3, 0, 1, 2));
- slope = _mm_shuffle_ps(slope, slope, _MM_SHUFFLE(3, 0, 1, 2));
- endmod = _mm_mul_ps(_mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(startx))), _mm_load1_ps(&zf[startx]));
- endsubmod = _mm_cvtps_epi32(_mm_mul_ps(endmod, _mm_set1_ps(256.0f)));
- for (x = startx; x < endx;)
- {
- int nextsub = x + DPSOFTRAST_DRAW_MAXSUBSPAN, endsub = nextsub - 1;
- __m128 subscale = _mm_set1_ps(256.0f/DPSOFTRAST_DRAW_MAXSUBSPAN);
- if (nextsub >= endx)
- {
- nextsub = endsub = endx-1;
- if (x < nextsub) subscale = _mm_set1_ps(256.0f / (nextsub - x));
- }
- mod = endmod;
- submod = endsubmod;
- endmod = _mm_mul_ps(_mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(nextsub))), _mm_load1_ps(&zf[nextsub]));
- substep = _mm_cvtps_epi32(_mm_mul_ps(_mm_sub_ps(endmod, mod), subscale));
- endsubmod = _mm_cvtps_epi32(_mm_mul_ps(endmod, _mm_set1_ps(256.0f)));
- submod = _mm_packs_epi32(submod, _mm_add_epi32(submod, substep));
- substep = _mm_packs_epi32(substep, substep);
- for (; x + 1 <= endsub; x += 2, submod = _mm_add_epi16(submod, substep))
- {
- __m128i pix = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_loadl_epi64((const __m128i *)&in4ub[x*4]));
- pix = _mm_mulhi_epu16(pix, submod);
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix, pix));
- }
- if (x <= endsub)
- {
- __m128i pix = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&in4ub[x*4]));
- pix = _mm_mulhi_epu16(pix, submod);
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- x++;
- }
- }
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_VaryingBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, int arrayindex, const float *zf)
-{
-#ifdef SSE_POSSIBLE
- int x;
- int startx = span->startx;
- int endx = span->endx;
- __m128 data, slope;
- __m128 mod, endmod;
- __m128i submod, substep, endsubmod;
- DPSOFTRAST_CALCATTRIB(triangle, span, data, slope, arrayindex);
- data = _mm_shuffle_ps(data, data, _MM_SHUFFLE(3, 0, 1, 2));
- slope = _mm_shuffle_ps(slope, slope, _MM_SHUFFLE(3, 0, 1, 2));
- endmod = _mm_mul_ps(_mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(startx))), _mm_load1_ps(&zf[startx]));
- endsubmod = _mm_cvtps_epi32(_mm_mul_ps(endmod, _mm_set1_ps(4095.0f)));
- for (x = startx; x < endx;)
- {
- int nextsub = x + DPSOFTRAST_DRAW_MAXSUBSPAN, endsub = nextsub - 1;
- __m128 subscale = _mm_set1_ps(4095.0f/DPSOFTRAST_DRAW_MAXSUBSPAN);
- if (nextsub >= endx)
- {
- nextsub = endsub = endx-1;
- if (x < nextsub) subscale = _mm_set1_ps(4095.0f / (nextsub - x));
- }
- mod = endmod;
- submod = endsubmod;
- endmod = _mm_mul_ps(_mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(nextsub))), _mm_load1_ps(&zf[nextsub]));
- substep = _mm_cvtps_epi32(_mm_mul_ps(_mm_sub_ps(endmod, mod), subscale));
- endsubmod = _mm_cvtps_epi32(_mm_mul_ps(endmod, _mm_set1_ps(4095.0f)));
- submod = _mm_packs_epi32(submod, _mm_add_epi32(submod, substep));
- substep = _mm_packs_epi32(substep, substep);
- for (; x + 1 <= endsub; x += 2, submod = _mm_add_epi16(submod, substep))
- {
- __m128i pix = _mm_srai_epi16(submod, 4);
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix, pix));
- }
- if (x <= endsub)
- {
- __m128i pix = _mm_srai_epi16(submod, 4);
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- x++;
- }
- }
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_AddBloomBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *ina4ub, const unsigned char *inb4ub, const float *subcolor)
-{
-#ifdef SSE_POSSIBLE
- int x, startx = span->startx, endx = span->endx;
- __m128i localcolor = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_loadu_ps(subcolor), _mm_set1_ps(255.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- localcolor = _mm_packs_epi32(localcolor, localcolor);
- for (x = startx;x+2 <= endx;x+=2)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&inb4ub[x*4]), _mm_setzero_si128());
- pix1 = _mm_add_epi16(pix1, _mm_subs_epu16(pix2, localcolor));
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix1, pix1));
- }
- if (x < endx)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&inb4ub[x*4]), _mm_setzero_si128());
- pix1 = _mm_add_epi16(pix1, _mm_subs_epu16(pix2, localcolor));
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- }
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_MultiplyBuffersBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *ina4ub, const unsigned char *inb4ub)
-{
-#ifdef SSE_POSSIBLE
- int x, startx = span->startx, endx = span->endx;
- for (x = startx;x+2 <= endx;x+=2)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_loadl_epi64((const __m128i *)&inb4ub[x*4]));
- pix1 = _mm_mulhi_epu16(pix1, pix2);
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix1, pix1));
- }
- if (x < endx)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&inb4ub[x*4]));
- pix1 = _mm_mulhi_epu16(pix1, pix2);
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- }
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_AddBuffersBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *ina4ub, const unsigned char *inb4ub)
-{
-#ifdef SSE_POSSIBLE
- int x, startx = span->startx, endx = span->endx;
- for (x = startx;x+2 <= endx;x+=2)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&inb4ub[x*4]), _mm_setzero_si128());
- pix1 = _mm_add_epi16(pix1, pix2);
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix1, pix1));
- }
- if (x < endx)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&inb4ub[x*4]), _mm_setzero_si128());
- pix1 = _mm_add_epi16(pix1, pix2);
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- }
-#endif
-}
-
-#if 0
-static void DPSOFTRAST_Draw_Span_TintedAddBuffersBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *ina4ub, const unsigned char *inb4ub, const float *inbtintbgra)
-{
-#ifdef SSE_POSSIBLE
- int x, startx = span->startx, endx = span->endx;
- __m128i tint = _mm_cvtps_epi32(_mm_mul_ps(_mm_loadu_ps(inbtintbgra), _mm_set1_ps(256.0f)));
- tint = _mm_packs_epi32(tint, tint);
- for (x = startx;x+2 <= endx;x+=2)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_loadl_epi64((const __m128i *)&inb4ub[x*4]));
- pix1 = _mm_add_epi16(pix1, _mm_mulhi_epu16(tint, pix2));
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix1, pix1));
- }
- if (x < endx)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&inb4ub[x*4]));
- pix1 = _mm_add_epi16(pix1, _mm_mulhi_epu16(tint, pix2));
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- }
-#endif
-}
-#endif
-
-static void DPSOFTRAST_Draw_Span_MixBuffersBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *ina4ub, const unsigned char *inb4ub)
-{
-#ifdef SSE_POSSIBLE
- int x, startx = span->startx, endx = span->endx;
- for (x = startx;x+2 <= endx;x+=2)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&inb4ub[x*4]), _mm_setzero_si128());
- __m128i blend = _mm_shufflehi_epi16(_mm_shufflelo_epi16(pix2, _MM_SHUFFLE(3, 3, 3, 3)), _MM_SHUFFLE(3, 3, 3, 3));
- pix1 = _mm_add_epi16(pix1, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 4), _mm_slli_epi16(blend, 4)));
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix1, pix1));
- }
- if (x < endx)
- {
- __m128i pix1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&ina4ub[x*4]), _mm_setzero_si128());
- __m128i pix2 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&inb4ub[x*4]), _mm_setzero_si128());
- __m128i blend = _mm_shufflelo_epi16(pix2, _MM_SHUFFLE(3, 3, 3, 3));
- pix1 = _mm_add_epi16(pix1, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(pix2, pix1), 4), _mm_slli_epi16(blend, 4)));
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix1, pix1));
- }
-#endif
-}
-
-static void DPSOFTRAST_Draw_Span_MixUniformColorBGRA8(const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span, unsigned char *out4ub, const unsigned char *in4ub, const float *color)
-{
-#ifdef SSE_POSSIBLE
- int x, startx = span->startx, endx = span->endx;
- __m128i localcolor = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_loadu_ps(color), _mm_set1_ps(255.0f))), _MM_SHUFFLE(3, 0, 1, 2)), blend;
- localcolor = _mm_packs_epi32(localcolor, localcolor);
- blend = _mm_slli_epi16(_mm_shufflehi_epi16(_mm_shufflelo_epi16(localcolor, _MM_SHUFFLE(3, 3, 3, 3)), _MM_SHUFFLE(3, 3, 3, 3)), 4);
- for (x = startx;x+2 <= endx;x+=2)
- {
- __m128i pix = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)&in4ub[x*4]), _mm_setzero_si128());
- pix = _mm_add_epi16(pix, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(localcolor, pix), 4), blend));
- _mm_storel_epi64((__m128i *)&out4ub[x*4], _mm_packus_epi16(pix, pix));
- }
- if (x < endx)
- {
- __m128i pix = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int *)&in4ub[x*4]), _mm_setzero_si128());
- pix = _mm_add_epi16(pix, _mm_mulhi_epi16(_mm_slli_epi16(_mm_sub_epi16(localcolor, pix), 4), blend));
- *(int *)&out4ub[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- }
-#endif
-}
-
-
-
-static void DPSOFTRAST_VertexShader_Generic(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_COLOR);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0);
- if (dpsoftrast.shader_permutation & SHADERPERMUTATION_SPECULAR)
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD1);
-}
-
-static void DPSOFTRAST_PixelShader_Generic(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_lightmapbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_DIFFUSE)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_FIRST, 2, buffer_z);
- DPSOFTRAST_Draw_Span_MultiplyVaryingBGRA8(triangle, span, buffer_FragColorbgra8, buffer_texture_colorbgra8, 1, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_SPECULAR)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_lightmapbgra8, GL20TU_SECOND, 2, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- // multiply
- DPSOFTRAST_Draw_Span_MultiplyBuffersBGRA8(triangle, span, buffer_FragColorbgra8, buffer_FragColorbgra8, buffer_texture_lightmapbgra8);
- }
- else if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- // add
- DPSOFTRAST_Draw_Span_AddBuffersBGRA8(triangle, span, buffer_FragColorbgra8, buffer_FragColorbgra8, buffer_texture_lightmapbgra8);
- }
- else if (thread->shader_permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND)
- {
- // alphablend
- DPSOFTRAST_Draw_Span_MixBuffersBGRA8(triangle, span, buffer_FragColorbgra8, buffer_FragColorbgra8, buffer_texture_lightmapbgra8);
- }
- }
- }
- else
- DPSOFTRAST_Draw_Span_VaryingBGRA8(triangle, span, buffer_FragColorbgra8, 1, buffer_z);
- if(thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL)
- {
- int x;
- for (x = span->startx;x < span->endx;x++)
- buffer_FragColorbgra8[x*4+3] = buffer_FragColorbgra8[x*4+3] * thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0];
- }
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_PostProcess(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD4);
-}
-
-static void DPSOFTRAST_PixelShader_PostProcess(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- // TODO: optimize!! at the very least there is no reason to use texture sampling on the frame texture
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_FragColorbgra8, GL20TU_FIRST, 2, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_BLOOM)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_SECOND, 3, buffer_z);
- DPSOFTRAST_Draw_Span_AddBloomBGRA8(triangle, span, buffer_FragColorbgra8, buffer_FragColorbgra8, buffer_texture_colorbgra8, thread->uniform4f + DPSOFTRAST_UNIFORM_BloomColorSubtract * 4);
- }
- DPSOFTRAST_Draw_Span_MixUniformColorBGRA8(triangle, span, buffer_FragColorbgra8, buffer_FragColorbgra8, thread->uniform4f + DPSOFTRAST_UNIFORM_ViewTintColor * 4);
- if (thread->shader_permutation & SHADERPERMUTATION_SATURATION)
- {
- // TODO: implement saturation
- }
- if (thread->shader_permutation & SHADERPERMUTATION_GAMMARAMPS)
- {
- // TODO: implement gammaramps
- }
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_Depth_Or_Shadow(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_Depth_Or_Shadow(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- // this is never called (because colormask is off when this shader is used)
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- memset(buffer_FragColorbgra8 + span->startx*4, 0, (span->endx - span->startx)*4);
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_FlatColor(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_FlatColor(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
-#ifdef SSE_POSSIBLE
- unsigned char * RESTRICT pixelmask = span->pixelmask;
- unsigned char * RESTRICT pixel = (unsigned char *)dpsoftrast.fb_colorpixels[0] + (span->y * dpsoftrast.fb_width + span->x) * 4;
- int x, startx = span->startx, endx = span->endx;
- __m128i Color_Ambientm;
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_COLOR, 2, buffer_z);
- if ((thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL) || thread->fb_blendmode != DPSOFTRAST_BLENDMODE_OPAQUE)
- pixel = buffer_FragColorbgra8;
- Color_Ambientm = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(&thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4]), _mm_set1_ps(256.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- Color_Ambientm = _mm_and_si128(Color_Ambientm, _mm_setr_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0));
- Color_Ambientm = _mm_or_si128(Color_Ambientm, _mm_setr_epi32(0, 0, 0, (int)(thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0]*255.0f)));
- Color_Ambientm = _mm_packs_epi32(Color_Ambientm, Color_Ambientm);
- for (x = startx;x < endx;x++)
- {
- __m128i color, pix;
- if (x + 4 <= endx && *(const unsigned int *)&pixelmask[x] == 0x01010101)
- {
- __m128i pix2;
- color = _mm_loadu_si128((const __m128i *)&buffer_texture_colorbgra8[x*4]);
- pix = _mm_mulhi_epu16(Color_Ambientm, _mm_unpacklo_epi8(_mm_setzero_si128(), color));
- pix2 = _mm_mulhi_epu16(Color_Ambientm, _mm_unpackhi_epi8(_mm_setzero_si128(), color));
- _mm_storeu_si128((__m128i *)&pixel[x*4], _mm_packus_epi16(pix, pix2));
- x += 3;
- continue;
- }
- if (!pixelmask[x])
- continue;
- color = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_colorbgra8[x*4]));
- pix = _mm_mulhi_epu16(Color_Ambientm, color);
- *(int *)&pixel[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- }
- if (pixel == buffer_FragColorbgra8)
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-#endif
-}
-
-
-
-static void DPSOFTRAST_VertexShader_VertexColor(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_COLOR);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_VertexColor(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
-#ifdef SSE_POSSIBLE
- unsigned char * RESTRICT pixelmask = span->pixelmask;
- unsigned char * RESTRICT pixel = (unsigned char *)dpsoftrast.fb_colorpixels[0] + (span->y * dpsoftrast.fb_width + span->x) * 4;
- int x, startx = span->startx, endx = span->endx;
- __m128i Color_Ambientm, Color_Diffusem;
- __m128 data, slope;
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- int arrayindex = DPSOFTRAST_ARRAY_COLOR;
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_COLOR, 2, buffer_z);
- if ((thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL) || thread->fb_blendmode != DPSOFTRAST_BLENDMODE_OPAQUE)
- pixel = buffer_FragColorbgra8;
- Color_Ambientm = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(&thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4]), _mm_set1_ps(256.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- Color_Ambientm = _mm_and_si128(Color_Ambientm, _mm_setr_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0));
- Color_Ambientm = _mm_or_si128(Color_Ambientm, _mm_setr_epi32(0, 0, 0, (int)(thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0]*255.0f)));
- Color_Ambientm = _mm_packs_epi32(Color_Ambientm, Color_Ambientm);
- Color_Diffusem = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(&thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4]), _mm_set1_ps(4096.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- Color_Diffusem = _mm_and_si128(Color_Diffusem, _mm_setr_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0));
- Color_Diffusem = _mm_packs_epi32(Color_Diffusem, Color_Diffusem);
- DPSOFTRAST_CALCATTRIB(triangle, span, data, slope, arrayindex);
- data = _mm_shuffle_ps(data, data, _MM_SHUFFLE(3, 0, 1, 2));
- slope = _mm_shuffle_ps(slope, slope, _MM_SHUFFLE(3, 0, 1, 2));
- data = _mm_add_ps(data, _mm_mul_ps(slope, _mm_set1_ps(startx)));
- data = _mm_mul_ps(data, _mm_set1_ps(4096.0f));
- slope = _mm_mul_ps(slope, _mm_set1_ps(4096.0f));
- for (x = startx;x < endx;x++, data = _mm_add_ps(data, slope))
- {
- __m128i color, mod, pix;
- if (x + 4 <= endx && *(const unsigned int *)&pixelmask[x] == 0x01010101)
- {
- __m128i pix2, mod2;
- __m128 z = _mm_loadu_ps(&buffer_z[x]);
- color = _mm_loadu_si128((const __m128i *)&buffer_texture_colorbgra8[x*4]);
- mod = _mm_cvtps_epi32(_mm_mul_ps(data, _mm_shuffle_ps(z, z, _MM_SHUFFLE(0, 0, 0, 0))));
- data = _mm_add_ps(data, slope);
- mod = _mm_packs_epi32(mod, _mm_cvtps_epi32(_mm_mul_ps(data, _mm_shuffle_ps(z, z, _MM_SHUFFLE(1, 1, 1, 1)))));
- data = _mm_add_ps(data, slope);
- mod2 = _mm_cvtps_epi32(_mm_mul_ps(data, _mm_shuffle_ps(z, z, _MM_SHUFFLE(2, 2, 2, 2))));
- data = _mm_add_ps(data, slope);
- mod2 = _mm_packs_epi32(mod2, _mm_cvtps_epi32(_mm_mul_ps(data, _mm_shuffle_ps(z, z, _MM_SHUFFLE(3, 3, 3, 3)))));
- pix = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, mod), Color_Ambientm),
- _mm_unpacklo_epi8(_mm_setzero_si128(), color));
- pix2 = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, mod2), Color_Ambientm),
- _mm_unpackhi_epi8(_mm_setzero_si128(), color));
- _mm_storeu_si128((__m128i *)&pixel[x*4], _mm_packus_epi16(pix, pix2));
- x += 3;
- continue;
- }
- if (!pixelmask[x])
- continue;
- color = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_colorbgra8[x*4]));
- mod = _mm_cvtps_epi32(_mm_mul_ps(data, _mm_load1_ps(&buffer_z[x])));
- mod = _mm_packs_epi32(mod, mod);
- pix = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(mod, Color_Diffusem), Color_Ambientm), color);
- *(int *)&pixel[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- }
- if (pixel == buffer_FragColorbgra8)
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-#endif
-}
-
-
-
-static void DPSOFTRAST_VertexShader_Lightmap(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD4);
-}
-
-static void DPSOFTRAST_PixelShader_Lightmap(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
-#ifdef SSE_POSSIBLE
- unsigned char * RESTRICT pixelmask = span->pixelmask;
- unsigned char * RESTRICT pixel = (unsigned char *)dpsoftrast.fb_colorpixels[0] + (span->y * dpsoftrast.fb_width + span->x) * 4;
- int x, startx = span->startx, endx = span->endx;
- __m128i Color_Ambientm, Color_Diffusem, Color_Glowm, Color_AmbientGlowm;
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_lightmapbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_glowbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_lightmapbgra8, GL20TU_LIGHTMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- if ((thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL) || thread->fb_blendmode != DPSOFTRAST_BLENDMODE_OPAQUE)
- pixel = buffer_FragColorbgra8;
- Color_Ambientm = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(&thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4]), _mm_set1_ps(256.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- Color_Ambientm = _mm_and_si128(Color_Ambientm, _mm_setr_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0));
- Color_Ambientm = _mm_or_si128(Color_Ambientm, _mm_setr_epi32(0, 0, 0, (int)(thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0]*255.0f)));
- Color_Ambientm = _mm_packs_epi32(Color_Ambientm, Color_Ambientm);
- Color_Diffusem = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(&thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4]), _mm_set1_ps(256.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- Color_Diffusem = _mm_and_si128(Color_Diffusem, _mm_setr_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0));
- Color_Diffusem = _mm_packs_epi32(Color_Diffusem, Color_Diffusem);
- if (thread->shader_permutation & SHADERPERMUTATION_GLOW)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_glowbgra8, GL20TU_GLOW, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- Color_Glowm = _mm_shuffle_epi32(_mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(&thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4]), _mm_set1_ps(256.0f))), _MM_SHUFFLE(3, 0, 1, 2));
- Color_Glowm = _mm_and_si128(Color_Glowm, _mm_setr_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0));
- Color_Glowm = _mm_packs_epi32(Color_Glowm, Color_Glowm);
- Color_AmbientGlowm = _mm_unpacklo_epi64(Color_Ambientm, Color_Glowm);
- for (x = startx;x < endx;x++)
- {
- __m128i color, lightmap, glow, pix;
- if (x + 4 <= endx && *(const unsigned int *)&pixelmask[x] == 0x01010101)
- {
- __m128i pix2;
- color = _mm_loadu_si128((const __m128i *)&buffer_texture_colorbgra8[x*4]);
- lightmap = _mm_loadu_si128((const __m128i *)&buffer_texture_lightmapbgra8[x*4]);
- glow = _mm_loadu_si128((const __m128i *)&buffer_texture_glowbgra8[x*4]);
- pix = _mm_add_epi16(_mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, _mm_unpacklo_epi8(_mm_setzero_si128(), lightmap)), Color_Ambientm),
- _mm_unpacklo_epi8(_mm_setzero_si128(), color)),
- _mm_mulhi_epu16(Color_Glowm, _mm_unpacklo_epi8(_mm_setzero_si128(), glow)));
- pix2 = _mm_add_epi16(_mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, _mm_unpackhi_epi8(_mm_setzero_si128(), lightmap)), Color_Ambientm),
- _mm_unpackhi_epi8(_mm_setzero_si128(), color)),
- _mm_mulhi_epu16(Color_Glowm, _mm_unpackhi_epi8(_mm_setzero_si128(), glow)));
- _mm_storeu_si128((__m128i *)&pixel[x*4], _mm_packus_epi16(pix, pix2));
- x += 3;
- continue;
- }
- if (!pixelmask[x])
- continue;
- color = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_colorbgra8[x*4]));
- lightmap = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_lightmapbgra8[x*4]));
- glow = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_glowbgra8[x*4]));
- pix = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, lightmap), Color_AmbientGlowm), _mm_unpacklo_epi64(color, glow));
- pix = _mm_add_epi16(pix, _mm_shuffle_epi32(pix, _MM_SHUFFLE(3, 2, 3, 2)));
- *(int *)&pixel[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- }
- }
- else
- {
- for (x = startx;x < endx;x++)
- {
- __m128i color, lightmap, pix;
- if (x + 4 <= endx && *(const unsigned int *)&pixelmask[x] == 0x01010101)
- {
- __m128i pix2;
- color = _mm_loadu_si128((const __m128i *)&buffer_texture_colorbgra8[x*4]);
- lightmap = _mm_loadu_si128((const __m128i *)&buffer_texture_lightmapbgra8[x*4]);
- pix = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, _mm_unpacklo_epi8(_mm_setzero_si128(), lightmap)), Color_Ambientm),
- _mm_unpacklo_epi8(_mm_setzero_si128(), color));
- pix2 = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(Color_Diffusem, _mm_unpackhi_epi8(_mm_setzero_si128(), lightmap)), Color_Ambientm),
- _mm_unpackhi_epi8(_mm_setzero_si128(), color));
- _mm_storeu_si128((__m128i *)&pixel[x*4], _mm_packus_epi16(pix, pix2));
- x += 3;
- continue;
- }
- if (!pixelmask[x])
- continue;
- color = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_colorbgra8[x*4]));
- lightmap = _mm_unpacklo_epi8(_mm_setzero_si128(), _mm_cvtsi32_si128(*(const int *)&buffer_texture_lightmapbgra8[x*4]));
- pix = _mm_mulhi_epu16(_mm_add_epi16(_mm_mulhi_epu16(lightmap, Color_Diffusem), Color_Ambientm), color);
- *(int *)&pixel[x*4] = _mm_cvtsi128_si32(_mm_packus_epi16(pix, pix));
- }
- }
- if (pixel == buffer_FragColorbgra8)
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-#endif
-}
-
-
-void DPSOFTRAST_VertexShader_LightDirection(void);
-void DPSOFTRAST_PixelShader_LightDirection(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span);
-
-static void DPSOFTRAST_VertexShader_FakeLight(void)
-{
- DPSOFTRAST_VertexShader_LightDirection();
-}
-
-static void DPSOFTRAST_PixelShader_FakeLight(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- DPSOFTRAST_PixelShader_LightDirection(thread, triangle, span);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_LightDirectionMap_ModelSpace(void)
-{
- DPSOFTRAST_VertexShader_LightDirection();
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD4);
-}
-
-static void DPSOFTRAST_PixelShader_LightDirectionMap_ModelSpace(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- DPSOFTRAST_PixelShader_LightDirection(thread, triangle, span);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_LightDirectionMap_TangentSpace(void)
-{
- DPSOFTRAST_VertexShader_LightDirection();
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD4);
-}
-
-static void DPSOFTRAST_PixelShader_LightDirectionMap_TangentSpace(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- DPSOFTRAST_PixelShader_LightDirection(thread, triangle, span);
-}
-
-
-
-void DPSOFTRAST_VertexShader_LightDirection(void)
-{
- int i;
- int numvertices = dpsoftrast.numvertices;
- float LightDir[4];
- float LightVector[4];
- float EyePosition[4];
- float EyeVectorModelSpace[4];
- float EyeVector[4];
- float position[4];
- float svector[4];
- float tvector[4];
- float normal[4];
- LightDir[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightDir*4+0];
- LightDir[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightDir*4+1];
- LightDir[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightDir*4+2];
- LightDir[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightDir*4+3];
- EyePosition[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+0];
- EyePosition[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+1];
- EyePosition[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+2];
- EyePosition[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+3];
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD2);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD3);
- for (i = 0;i < numvertices;i++)
- {
- position[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+0];
- position[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+1];
- position[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+2];
- svector[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+0];
- svector[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+1];
- svector[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+2];
- tvector[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+0];
- tvector[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+1];
- tvector[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+2];
- normal[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+0];
- normal[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+1];
- normal[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+2];
- LightVector[0] = svector[0] * LightDir[0] + svector[1] * LightDir[1] + svector[2] * LightDir[2];
- LightVector[1] = tvector[0] * LightDir[0] + tvector[1] * LightDir[1] + tvector[2] * LightDir[2];
- LightVector[2] = normal[0] * LightDir[0] + normal[1] * LightDir[1] + normal[2] * LightDir[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD5][i*4+0] = LightVector[0];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD5][i*4+1] = LightVector[1];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD5][i*4+2] = LightVector[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD5][i*4+3] = 0.0f;
- EyeVectorModelSpace[0] = EyePosition[0] - position[0];
- EyeVectorModelSpace[1] = EyePosition[1] - position[1];
- EyeVectorModelSpace[2] = EyePosition[2] - position[2];
- EyeVector[0] = svector[0] * EyeVectorModelSpace[0] + svector[1] * EyeVectorModelSpace[1] + svector[2] * EyeVectorModelSpace[2];
- EyeVector[1] = tvector[0] * EyeVectorModelSpace[0] + tvector[1] * EyeVectorModelSpace[1] + tvector[2] * EyeVectorModelSpace[2];
- EyeVector[2] = normal[0] * EyeVectorModelSpace[0] + normal[1] * EyeVectorModelSpace[1] + normal[2] * EyeVectorModelSpace[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+0] = EyeVector[0];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+1] = EyeVector[1];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+2] = EyeVector[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+3] = 0.0f;
- }
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, -1, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
-}
-
-#define DPSOFTRAST_Min(a,b) ((a) < (b) ? (a) : (b))
-#define DPSOFTRAST_Max(a,b) ((a) > (b) ? (a) : (b))
-#define DPSOFTRAST_Vector3Dot(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
-#define DPSOFTRAST_Vector3LengthSquared(v) (DPSOFTRAST_Vector3Dot((v),(v)))
-#define DPSOFTRAST_Vector3Length(v) (sqrt(DPSOFTRAST_Vector3LengthSquared(v)))
-#define DPSOFTRAST_Vector3Normalize(v)\
-do\
-{\
- float len = sqrt(DPSOFTRAST_Vector3Dot(v,v));\
- if (len)\
- {\
- len = 1.0f / len;\
- v[0] *= len;\
- v[1] *= len;\
- v[2] *= len;\
- }\
-}\
-while(0)
-
-void DPSOFTRAST_PixelShader_LightDirection(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_normalbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_glossbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_glowbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_pantsbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_shirtbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_deluxemapbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_lightmapbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- int x, startx = span->startx, endx = span->endx;
- float Color_Ambient[4], Color_Diffuse[4], Color_Specular[4], Color_Glow[4], Color_Pants[4], Color_Shirt[4], LightColor[4];
- float LightVectordata[4];
- float LightVectorslope[4];
- float EyeVectordata[4];
- float EyeVectorslope[4];
- float VectorSdata[4];
- float VectorSslope[4];
- float VectorTdata[4];
- float VectorTslope[4];
- float VectorRdata[4];
- float VectorRslope[4];
- float z;
- float diffusetex[4];
- float glosstex[4];
- float surfacenormal[4];
- float lightnormal[4];
- float lightnormal_modelspace[4];
- float eyenormal[4];
- float specularnormal[4];
- float diffuse;
- float specular;
- float SpecularPower;
- int d[4];
- Color_Glow[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+0];
- Color_Glow[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+1];
- Color_Glow[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+2];
- Color_Glow[3] = 0.0f;
- Color_Ambient[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+0];
- Color_Ambient[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+1];
- Color_Ambient[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+2];
- Color_Ambient[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0];
- Color_Pants[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+0];
- Color_Pants[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+1];
- Color_Pants[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+2];
- Color_Pants[3] = 0.0f;
- Color_Shirt[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+0];
- Color_Shirt[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+1];
- Color_Shirt[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+2];
- Color_Shirt[3] = 0.0f;
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_pantsbgra8, GL20TU_PANTS, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_shirtbgra8, GL20TU_SHIRT, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- }
- if (thread->shader_permutation & SHADERPERMUTATION_GLOW)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_glowbgra8, GL20TU_GLOW, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- }
- if (thread->shader_permutation & SHADERPERMUTATION_SPECULAR)
- {
- Color_Diffuse[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+0];
- Color_Diffuse[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+1];
- Color_Diffuse[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+2];
- Color_Diffuse[3] = 0.0f;
- LightColor[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+0];
- LightColor[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+1];
- LightColor[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+2];
- LightColor[3] = 0.0f;
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- Color_Specular[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+0];
- Color_Specular[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+1];
- Color_Specular[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+2];
- Color_Specular[3] = 0.0f;
- SpecularPower = thread->uniform4f[DPSOFTRAST_UNIFORM_SpecularPower*4+0] * (1.0f / 255.0f);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, EyeVectordata, EyeVectorslope, DPSOFTRAST_ARRAY_TEXCOORD6);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_glossbgra8, GL20TU_GLOSS, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
-
- if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE)
- {
- DPSOFTRAST_CALCATTRIB4F(triangle, span, VectorSdata, VectorSslope, DPSOFTRAST_ARRAY_TEXCOORD1);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, VectorTdata, VectorTslope, DPSOFTRAST_ARRAY_TEXCOORD2);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, VectorRdata, VectorRslope, DPSOFTRAST_ARRAY_TEXCOORD3);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_lightmapbgra8, GL20TU_LIGHTMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_deluxemapbgra8, GL20TU_DELUXEMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- }
- else if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_lightmapbgra8, GL20TU_LIGHTMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_deluxemapbgra8, GL20TU_DELUXEMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- }
- else if(thread->shader_mode == SHADERMODE_FAKELIGHT)
- {
- // nothing of this needed
- }
- else
- {
- DPSOFTRAST_CALCATTRIB4F(triangle, span, LightVectordata, LightVectorslope, DPSOFTRAST_ARRAY_TEXCOORD5);
- }
-
- for (x = startx;x < endx;x++)
- {
- z = buffer_z[x];
- diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
- diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
- diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
- diffusetex[3] = buffer_texture_colorbgra8[x*4+3];
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0];
- diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1];
- diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2];
- diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3];
- }
- glosstex[0] = buffer_texture_glossbgra8[x*4+0];
- glosstex[1] = buffer_texture_glossbgra8[x*4+1];
- glosstex[2] = buffer_texture_glossbgra8[x*4+2];
- glosstex[3] = buffer_texture_glossbgra8[x*4+3];
- surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- DPSOFTRAST_Vector3Normalize(surfacenormal);
-
- if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE)
- {
- // myhalf3 lightnormal_modelspace = myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n";
- lightnormal_modelspace[0] = buffer_texture_deluxemapbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- lightnormal_modelspace[1] = buffer_texture_deluxemapbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- lightnormal_modelspace[2] = buffer_texture_deluxemapbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
-
- // lightnormal.x = dot(lightnormal_modelspace, myhalf3(VectorS));\n"
- lightnormal[0] = lightnormal_modelspace[0] * (VectorSdata[0] + VectorSslope[0] * x)
- + lightnormal_modelspace[1] * (VectorSdata[1] + VectorSslope[1] * x)
- + lightnormal_modelspace[2] * (VectorSdata[2] + VectorSslope[2] * x);
-
- // lightnormal.y = dot(lightnormal_modelspace, myhalf3(VectorT));\n"
- lightnormal[1] = lightnormal_modelspace[0] * (VectorTdata[0] + VectorTslope[0] * x)
- + lightnormal_modelspace[1] * (VectorTdata[1] + VectorTslope[1] * x)
- + lightnormal_modelspace[2] * (VectorTdata[2] + VectorTslope[2] * x);
-
- // lightnormal.z = dot(lightnormal_modelspace, myhalf3(VectorR));\n"
- lightnormal[2] = lightnormal_modelspace[0] * (VectorRdata[0] + VectorRslope[0] * x)
- + lightnormal_modelspace[1] * (VectorRdata[1] + VectorRslope[1] * x)
- + lightnormal_modelspace[2] * (VectorRdata[2] + VectorRslope[2] * x);
-
- // lightnormal = normalize(lightnormal); // VectorS/T/R are not always perfectly normalized, and EXACTSPECULARMATH is very picky about this\n"
- DPSOFTRAST_Vector3Normalize(lightnormal);
-
- // myhalf3 lightcolor = myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n";
- {
- float f = 1.0f / (256.0f * max(0.25f, lightnormal[2]));
- LightColor[0] = buffer_texture_lightmapbgra8[x*4+0] * f;
- LightColor[1] = buffer_texture_lightmapbgra8[x*4+1] * f;
- LightColor[2] = buffer_texture_lightmapbgra8[x*4+2] * f;
- }
- }
- else if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE)
- {
- lightnormal[0] = buffer_texture_deluxemapbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- lightnormal[1] = buffer_texture_deluxemapbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- lightnormal[2] = buffer_texture_deluxemapbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- {
- float f = 1.0f / 256.0f;
- LightColor[0] = buffer_texture_lightmapbgra8[x*4+0] * f;
- LightColor[1] = buffer_texture_lightmapbgra8[x*4+1] * f;
- LightColor[2] = buffer_texture_lightmapbgra8[x*4+2] * f;
- }
- }
- else if(thread->shader_mode == SHADERMODE_FAKELIGHT)
- {
- lightnormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z;
- lightnormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z;
- lightnormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(lightnormal);
-
- LightColor[0] = 1.0;
- LightColor[1] = 1.0;
- LightColor[2] = 1.0;
- }
- else
- {
- lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z;
- lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z;
- lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(lightnormal);
- }
-
- diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f;
-
- if(thread->shader_exactspecularmath)
- {
- // reflect lightnormal at surfacenormal, take the negative of that
- // i.e. we want (2*dot(N, i) * N - I) for N=surfacenormal, I=lightnormal
- float f;
- f = DPSOFTRAST_Vector3Dot(lightnormal, surfacenormal);
- specularnormal[0] = 2*f*surfacenormal[0] - lightnormal[0];
- specularnormal[1] = 2*f*surfacenormal[1] - lightnormal[1];
- specularnormal[2] = 2*f*surfacenormal[2] - lightnormal[2];
-
- // dot of this and normalize(EyeVectorFogDepth.xyz)
- eyenormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z;
- eyenormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z;
- eyenormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(eyenormal);
-
- specular = DPSOFTRAST_Vector3Dot(eyenormal, specularnormal);if (specular < 0.0f) specular = 0.0f;
- }
- else
- {
- eyenormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z;
- eyenormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z;
- eyenormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(eyenormal);
-
- specularnormal[0] = lightnormal[0] + eyenormal[0];
- specularnormal[1] = lightnormal[1] + eyenormal[1];
- specularnormal[2] = lightnormal[2] + eyenormal[2];
- DPSOFTRAST_Vector3Normalize(specularnormal);
-
- specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < 0.0f) specular = 0.0f;
- }
- specular = pow(specular, 1.0f + SpecularPower * glosstex[3]);
-
- if (thread->shader_permutation & SHADERPERMUTATION_GLOW)
- {
- d[0] = (int)(buffer_texture_glowbgra8[x*4+0] * Color_Glow[0] + diffusetex[0] * Color_Ambient[0] + (diffusetex[0] * Color_Diffuse[0] * diffuse + glosstex[0] * Color_Specular[0] * specular) * LightColor[0]);if (d[0] > 255) d[0] = 255;
- d[1] = (int)(buffer_texture_glowbgra8[x*4+1] * Color_Glow[1] + diffusetex[1] * Color_Ambient[1] + (diffusetex[1] * Color_Diffuse[1] * diffuse + glosstex[1] * Color_Specular[1] * specular) * LightColor[1]);if (d[1] > 255) d[1] = 255;
- d[2] = (int)(buffer_texture_glowbgra8[x*4+2] * Color_Glow[2] + diffusetex[2] * Color_Ambient[2] + (diffusetex[2] * Color_Diffuse[2] * diffuse + glosstex[2] * Color_Specular[2] * specular) * LightColor[2]);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] * Color_Ambient[3]);if (d[3] > 255) d[3] = 255;
- }
- else
- {
- d[0] = (int)( diffusetex[0] * Color_Ambient[0] + (diffusetex[0] * Color_Diffuse[0] * diffuse + glosstex[0] * Color_Specular[0] * specular) * LightColor[0]);if (d[0] > 255) d[0] = 255;
- d[1] = (int)( diffusetex[1] * Color_Ambient[1] + (diffusetex[1] * Color_Diffuse[1] * diffuse + glosstex[1] * Color_Specular[1] * specular) * LightColor[1]);if (d[1] > 255) d[1] = 255;
- d[2] = (int)( diffusetex[2] * Color_Ambient[2] + (diffusetex[2] * Color_Diffuse[2] * diffuse + glosstex[2] * Color_Specular[2] * specular) * LightColor[2]);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] * Color_Ambient[3]);if (d[3] > 255) d[3] = 255;
- }
-
- buffer_FragColorbgra8[x*4+0] = d[0];
- buffer_FragColorbgra8[x*4+1] = d[1];
- buffer_FragColorbgra8[x*4+2] = d[2];
- buffer_FragColorbgra8[x*4+3] = d[3];
- }
- }
- else if (thread->shader_permutation & SHADERPERMUTATION_DIFFUSE)
- {
- Color_Diffuse[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+0];
- Color_Diffuse[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+1];
- Color_Diffuse[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+2];
- Color_Diffuse[3] = 0.0f;
- LightColor[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+0];
- LightColor[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+1];
- LightColor[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+2];
- LightColor[3] = 0.0f;
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
-
- if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE)
- {
- DPSOFTRAST_CALCATTRIB4F(triangle, span, VectorSdata, VectorSslope, DPSOFTRAST_ARRAY_TEXCOORD1);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, VectorTdata, VectorTslope, DPSOFTRAST_ARRAY_TEXCOORD2);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, VectorRdata, VectorRslope, DPSOFTRAST_ARRAY_TEXCOORD3);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_lightmapbgra8, GL20TU_LIGHTMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_deluxemapbgra8, GL20TU_DELUXEMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- }
- else if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_lightmapbgra8, GL20TU_LIGHTMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_deluxemapbgra8, GL20TU_DELUXEMAP, DPSOFTRAST_ARRAY_TEXCOORD4, buffer_z);
- }
- else if(thread->shader_mode == SHADERMODE_FAKELIGHT)
- {
- DPSOFTRAST_CALCATTRIB4F(triangle, span, EyeVectordata, EyeVectorslope, DPSOFTRAST_ARRAY_TEXCOORD6);
- }
- else
- {
- DPSOFTRAST_CALCATTRIB4F(triangle, span, LightVectordata, LightVectorslope, DPSOFTRAST_ARRAY_TEXCOORD5);
- }
-
- for (x = startx;x < endx;x++)
- {
- z = buffer_z[x];
- diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
- diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
- diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
- diffusetex[3] = buffer_texture_colorbgra8[x*4+3];
- surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- DPSOFTRAST_Vector3Normalize(surfacenormal);
-
- if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE)
- {
- // myhalf3 lightnormal_modelspace = myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n";
- lightnormal_modelspace[0] = buffer_texture_deluxemapbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- lightnormal_modelspace[1] = buffer_texture_deluxemapbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- lightnormal_modelspace[2] = buffer_texture_deluxemapbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
-
- // lightnormal.x = dot(lightnormal_modelspace, myhalf3(VectorS));\n"
- lightnormal[0] = lightnormal_modelspace[0] * (VectorSdata[0] + VectorSslope[0] * x)
- + lightnormal_modelspace[1] * (VectorSdata[1] + VectorSslope[1] * x)
- + lightnormal_modelspace[2] * (VectorSdata[2] + VectorSslope[2] * x);
-
- // lightnormal.y = dot(lightnormal_modelspace, myhalf3(VectorT));\n"
- lightnormal[1] = lightnormal_modelspace[0] * (VectorTdata[0] + VectorTslope[0] * x)
- + lightnormal_modelspace[1] * (VectorTdata[1] + VectorTslope[1] * x)
- + lightnormal_modelspace[2] * (VectorTdata[2] + VectorTslope[2] * x);
-
- // lightnormal.z = dot(lightnormal_modelspace, myhalf3(VectorR));\n"
- lightnormal[2] = lightnormal_modelspace[0] * (VectorRdata[0] + VectorRslope[0] * x)
- + lightnormal_modelspace[1] * (VectorRdata[1] + VectorRslope[1] * x)
- + lightnormal_modelspace[2] * (VectorRdata[2] + VectorRslope[2] * x);
-
- // lightnormal = normalize(lightnormal); // VectorS/T/R are not always perfectly normalized, and EXACTSPECULARMATH is very picky about this\n"
- DPSOFTRAST_Vector3Normalize(lightnormal);
-
- // myhalf3 lightcolor = myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n";
- {
- float f = 1.0f / (256.0f * max(0.25f, lightnormal[2]));
- LightColor[0] = buffer_texture_lightmapbgra8[x*4+0] * f;
- LightColor[1] = buffer_texture_lightmapbgra8[x*4+1] * f;
- LightColor[2] = buffer_texture_lightmapbgra8[x*4+2] * f;
- }
- }
- else if(thread->shader_mode == SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE)
- {
- lightnormal[0] = buffer_texture_deluxemapbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- lightnormal[1] = buffer_texture_deluxemapbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- lightnormal[2] = buffer_texture_deluxemapbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- {
- float f = 1.0f / 256.0f;
- LightColor[0] = buffer_texture_lightmapbgra8[x*4+0] * f;
- LightColor[1] = buffer_texture_lightmapbgra8[x*4+1] * f;
- LightColor[2] = buffer_texture_lightmapbgra8[x*4+2] * f;
- }
- }
- else if(thread->shader_mode == SHADERMODE_FAKELIGHT)
- {
- lightnormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z;
- lightnormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z;
- lightnormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(lightnormal);
-
- LightColor[0] = 1.0;
- LightColor[1] = 1.0;
- LightColor[2] = 1.0;
- }
- else
- {
- lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z;
- lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z;
- lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(lightnormal);
- }
-
- diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f;
- if (thread->shader_permutation & SHADERPERMUTATION_GLOW)
- {
- d[0] = (int)(buffer_texture_glowbgra8[x*4+0] * Color_Glow[0] + diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse * LightColor[0]));if (d[0] > 255) d[0] = 255;
- d[1] = (int)(buffer_texture_glowbgra8[x*4+1] * Color_Glow[1] + diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse * LightColor[1]));if (d[1] > 255) d[1] = 255;
- d[2] = (int)(buffer_texture_glowbgra8[x*4+2] * Color_Glow[2] + diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse * LightColor[2]));if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] * (Color_Ambient[3] ));if (d[3] > 255) d[3] = 255;
- }
- else
- {
- d[0] = (int)( + diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse * LightColor[0]));if (d[0] > 255) d[0] = 255;
- d[1] = (int)( + diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse * LightColor[1]));if (d[1] > 255) d[1] = 255;
- d[2] = (int)( + diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse * LightColor[2]));if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] * (Color_Ambient[3] ));if (d[3] > 255) d[3] = 255;
- }
- buffer_FragColorbgra8[x*4+0] = d[0];
- buffer_FragColorbgra8[x*4+1] = d[1];
- buffer_FragColorbgra8[x*4+2] = d[2];
- buffer_FragColorbgra8[x*4+3] = d[3];
- }
- }
- else
- {
- for (x = startx;x < endx;x++)
- {
- // z = buffer_z[x];
- diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
- diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
- diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
- diffusetex[3] = buffer_texture_colorbgra8[x*4+3];
-
- if (thread->shader_permutation & SHADERPERMUTATION_GLOW)
- {
- d[0] = (int)(buffer_texture_glowbgra8[x*4+0] * Color_Glow[0] + diffusetex[0] * Color_Ambient[0]);if (d[0] > 255) d[0] = 255;
- d[1] = (int)(buffer_texture_glowbgra8[x*4+1] * Color_Glow[1] + diffusetex[1] * Color_Ambient[1]);if (d[1] > 255) d[1] = 255;
- d[2] = (int)(buffer_texture_glowbgra8[x*4+2] * Color_Glow[2] + diffusetex[2] * Color_Ambient[2]);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] * Color_Ambient[3]);if (d[3] > 255) d[3] = 255;
- }
- else
- {
- d[0] = (int)( diffusetex[0] * Color_Ambient[0]);if (d[0] > 255) d[0] = 255;
- d[1] = (int)( diffusetex[1] * Color_Ambient[1]);if (d[1] > 255) d[1] = 255;
- d[2] = (int)( diffusetex[2] * Color_Ambient[2]);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] * Color_Ambient[3]);if (d[3] > 255) d[3] = 255;
- }
- buffer_FragColorbgra8[x*4+0] = d[0];
- buffer_FragColorbgra8[x*4+1] = d[1];
- buffer_FragColorbgra8[x*4+2] = d[2];
- buffer_FragColorbgra8[x*4+3] = d[3];
- }
- }
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_LightSource(void)
-{
- int i;
- int numvertices = dpsoftrast.numvertices;
- float LightPosition[4];
- float LightVector[4];
- float LightVectorModelSpace[4];
- float EyePosition[4];
- float EyeVectorModelSpace[4];
- float EyeVector[4];
- float position[4];
- float svector[4];
- float tvector[4];
- float normal[4];
- LightPosition[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+0];
- LightPosition[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+1];
- LightPosition[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+2];
- LightPosition[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_LightPosition*4+3];
- EyePosition[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+0];
- EyePosition[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+1];
- EyePosition[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+2];
- EyePosition[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+3];
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD2);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD3);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD4);
- for (i = 0;i < numvertices;i++)
- {
- position[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+0];
- position[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+1];
- position[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+2];
- svector[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+0];
- svector[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+1];
- svector[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+2];
- tvector[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+0];
- tvector[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+1];
- tvector[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+2];
- normal[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+0];
- normal[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+1];
- normal[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+2];
- LightVectorModelSpace[0] = LightPosition[0] - position[0];
- LightVectorModelSpace[1] = LightPosition[1] - position[1];
- LightVectorModelSpace[2] = LightPosition[2] - position[2];
- LightVector[0] = svector[0] * LightVectorModelSpace[0] + svector[1] * LightVectorModelSpace[1] + svector[2] * LightVectorModelSpace[2];
- LightVector[1] = tvector[0] * LightVectorModelSpace[0] + tvector[1] * LightVectorModelSpace[1] + tvector[2] * LightVectorModelSpace[2];
- LightVector[2] = normal[0] * LightVectorModelSpace[0] + normal[1] * LightVectorModelSpace[1] + normal[2] * LightVectorModelSpace[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+0] = LightVector[0];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+1] = LightVector[1];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+2] = LightVector[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+3] = 0.0f;
- EyeVectorModelSpace[0] = EyePosition[0] - position[0];
- EyeVectorModelSpace[1] = EyePosition[1] - position[1];
- EyeVectorModelSpace[2] = EyePosition[2] - position[2];
- EyeVector[0] = svector[0] * EyeVectorModelSpace[0] + svector[1] * EyeVectorModelSpace[1] + svector[2] * EyeVectorModelSpace[2];
- EyeVector[1] = tvector[0] * EyeVectorModelSpace[0] + tvector[1] * EyeVectorModelSpace[1] + tvector[2] * EyeVectorModelSpace[2];
- EyeVector[2] = normal[0] * EyeVectorModelSpace[0] + normal[1] * EyeVectorModelSpace[1] + normal[2] * EyeVectorModelSpace[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+0] = EyeVector[0];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+1] = EyeVector[1];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+2] = EyeVector[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+3] = 0.0f;
- }
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, -1, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelToLightM1);
-}
-
-static void DPSOFTRAST_PixelShader_LightSource(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
-#ifdef SSE_POSSIBLE
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_texture_colorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_normalbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_glossbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_cubebgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_pantsbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_texture_shirtbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- int x, startx = span->startx, endx = span->endx;
- float Color_Ambient[4], Color_Diffuse[4], Color_Specular[4], /*Color_Glow[4],*/ Color_Pants[4], Color_Shirt[4], LightColor[4];
- float CubeVectordata[4];
- float CubeVectorslope[4];
- float LightVectordata[4];
- float LightVectorslope[4];
- float EyeVectordata[4];
- float EyeVectorslope[4];
- float z;
- float diffusetex[4];
- float glosstex[4];
- float surfacenormal[4];
- float lightnormal[4];
- float eyenormal[4];
- float specularnormal[4];
- float diffuse;
- float specular;
- float SpecularPower;
- float CubeVector[4];
- float attenuation;
- int d[4];
-#if 0
- Color_Glow[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+0];
- Color_Glow[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+1];
- Color_Glow[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+2];
- Color_Glow[3] = 0.0f;
-#endif
- Color_Ambient[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+0];
- Color_Ambient[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+1];
- Color_Ambient[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+2];
- Color_Ambient[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0];
- Color_Diffuse[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+0];
- Color_Diffuse[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+1];
- Color_Diffuse[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Diffuse*4+2];
- Color_Diffuse[3] = 0.0f;
- Color_Specular[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+0];
- Color_Specular[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+1];
- Color_Specular[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Specular*4+2];
- Color_Specular[3] = 0.0f;
- Color_Pants[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+0];
- Color_Pants[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+1];
- Color_Pants[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Pants*4+2];
- Color_Pants[3] = 0.0f;
- Color_Shirt[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+0];
- Color_Shirt[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+1];
- Color_Shirt[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Shirt*4+2];
- Color_Shirt[3] = 0.0f;
- LightColor[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+0];
- LightColor[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+1];
- LightColor[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_LightColor*4+2];
- LightColor[3] = 0.0f;
- SpecularPower = thread->uniform4f[DPSOFTRAST_UNIFORM_SpecularPower*4+0] * (1.0f / 255.0f);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, LightVectordata, LightVectorslope, DPSOFTRAST_ARRAY_TEXCOORD1);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, EyeVectordata, EyeVectorslope, DPSOFTRAST_ARRAY_TEXCOORD2);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, CubeVectordata, CubeVectorslope, DPSOFTRAST_ARRAY_TEXCOORD3);
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- memset(buffer_FragColorbgra8 + startx*4, 0, (endx-startx)*4); // clear first, because we skip writing black pixels, and there are a LOT of them...
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_colorbgra8, GL20TU_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_pantsbgra8, GL20TU_PANTS, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_shirtbgra8, GL20TU_SHIRT, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- }
- if (thread->shader_permutation & SHADERPERMUTATION_CUBEFILTER)
- DPSOFTRAST_Draw_Span_TextureCubeVaryingBGRA8(triangle, span, buffer_texture_cubebgra8, GL20TU_CUBE, DPSOFTRAST_ARRAY_TEXCOORD3, buffer_z);
- if (thread->shader_permutation & SHADERPERMUTATION_SPECULAR)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_glossbgra8, GL20TU_GLOSS, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- for (x = startx;x < endx;x++)
- {
- z = buffer_z[x];
- CubeVector[0] = (CubeVectordata[0] + CubeVectorslope[0]*x) * z;
- CubeVector[1] = (CubeVectordata[1] + CubeVectorslope[1]*x) * z;
- CubeVector[2] = (CubeVectordata[2] + CubeVectorslope[2]*x) * z;
- attenuation = 1.0f - DPSOFTRAST_Vector3LengthSquared(CubeVector);
- if (attenuation < 0.01f)
- continue;
- if (thread->shader_permutation & SHADERPERMUTATION_SHADOWMAP2D)
- {
- attenuation *= DPSOFTRAST_SampleShadowmap(CubeVector);
- if (attenuation < 0.01f)
- continue;
- }
-
- diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
- diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
- diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
- diffusetex[3] = buffer_texture_colorbgra8[x*4+3];
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0];
- diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1];
- diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2];
- diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3];
- }
- glosstex[0] = buffer_texture_glossbgra8[x*4+0];
- glosstex[1] = buffer_texture_glossbgra8[x*4+1];
- glosstex[2] = buffer_texture_glossbgra8[x*4+2];
- glosstex[3] = buffer_texture_glossbgra8[x*4+3];
- surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- DPSOFTRAST_Vector3Normalize(surfacenormal);
-
- lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z;
- lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z;
- lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(lightnormal);
-
- diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f;
-
- if(thread->shader_exactspecularmath)
- {
- // reflect lightnormal at surfacenormal, take the negative of that
- // i.e. we want (2*dot(N, i) * N - I) for N=surfacenormal, I=lightnormal
- float f;
- f = DPSOFTRAST_Vector3Dot(lightnormal, surfacenormal);
- specularnormal[0] = 2*f*surfacenormal[0] - lightnormal[0];
- specularnormal[1] = 2*f*surfacenormal[1] - lightnormal[1];
- specularnormal[2] = 2*f*surfacenormal[2] - lightnormal[2];
-
- // dot of this and normalize(EyeVectorFogDepth.xyz)
- eyenormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z;
- eyenormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z;
- eyenormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(eyenormal);
-
- specular = DPSOFTRAST_Vector3Dot(eyenormal, specularnormal);if (specular < 0.0f) specular = 0.0f;
- }
- else
- {
- eyenormal[0] = (EyeVectordata[0] + EyeVectorslope[0]*x) * z;
- eyenormal[1] = (EyeVectordata[1] + EyeVectorslope[1]*x) * z;
- eyenormal[2] = (EyeVectordata[2] + EyeVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(eyenormal);
-
- specularnormal[0] = lightnormal[0] + eyenormal[0];
- specularnormal[1] = lightnormal[1] + eyenormal[1];
- specularnormal[2] = lightnormal[2] + eyenormal[2];
- DPSOFTRAST_Vector3Normalize(specularnormal);
-
- specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < 0.0f) specular = 0.0f;
- }
- specular = pow(specular, 1.0f + SpecularPower * glosstex[3]);
-
- if (thread->shader_permutation & SHADERPERMUTATION_CUBEFILTER)
- {
- // scale down the attenuation to account for the cubefilter multiplying everything by 255
- attenuation *= (1.0f / 255.0f);
- d[0] = (int)((diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse) + glosstex[0] * Color_Specular[0] * specular) * LightColor[0] * buffer_texture_cubebgra8[x*4+0] * attenuation);if (d[0] > 255) d[0] = 255;
- d[1] = (int)((diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse) + glosstex[1] * Color_Specular[1] * specular) * LightColor[1] * buffer_texture_cubebgra8[x*4+1] * attenuation);if (d[1] > 255) d[1] = 255;
- d[2] = (int)((diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse) + glosstex[2] * Color_Specular[2] * specular) * LightColor[2] * buffer_texture_cubebgra8[x*4+2] * attenuation);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255;
- }
- else
- {
- d[0] = (int)((diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse) + glosstex[0] * Color_Specular[0] * specular) * LightColor[0] * attenuation);if (d[0] > 255) d[0] = 255;
- d[1] = (int)((diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse) + glosstex[1] * Color_Specular[1] * specular) * LightColor[1] * attenuation);if (d[1] > 255) d[1] = 255;
- d[2] = (int)((diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse) + glosstex[2] * Color_Specular[2] * specular) * LightColor[2] * attenuation);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255;
- }
- buffer_FragColorbgra8[x*4+0] = d[0];
- buffer_FragColorbgra8[x*4+1] = d[1];
- buffer_FragColorbgra8[x*4+2] = d[2];
- buffer_FragColorbgra8[x*4+3] = d[3];
- }
- }
- else if (thread->shader_permutation & SHADERPERMUTATION_DIFFUSE)
- {
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
- for (x = startx;x < endx;x++)
- {
- z = buffer_z[x];
- CubeVector[0] = (CubeVectordata[0] + CubeVectorslope[0]*x) * z;
- CubeVector[1] = (CubeVectordata[1] + CubeVectorslope[1]*x) * z;
- CubeVector[2] = (CubeVectordata[2] + CubeVectorslope[2]*x) * z;
- attenuation = 1.0f - DPSOFTRAST_Vector3LengthSquared(CubeVector);
- if (attenuation < 0.01f)
- continue;
- if (thread->shader_permutation & SHADERPERMUTATION_SHADOWMAP2D)
- {
- attenuation *= DPSOFTRAST_SampleShadowmap(CubeVector);
- if (attenuation < 0.01f)
- continue;
- }
-
- diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
- diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
- diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
- diffusetex[3] = buffer_texture_colorbgra8[x*4+3];
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0];
- diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1];
- diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2];
- diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3];
- }
- surfacenormal[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- surfacenormal[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- DPSOFTRAST_Vector3Normalize(surfacenormal);
-
- lightnormal[0] = (LightVectordata[0] + LightVectorslope[0]*x) * z;
- lightnormal[1] = (LightVectordata[1] + LightVectorslope[1]*x) * z;
- lightnormal[2] = (LightVectordata[2] + LightVectorslope[2]*x) * z;
- DPSOFTRAST_Vector3Normalize(lightnormal);
-
- diffuse = DPSOFTRAST_Vector3Dot(surfacenormal, lightnormal);if (diffuse < 0.0f) diffuse = 0.0f;
- if (thread->shader_permutation & SHADERPERMUTATION_CUBEFILTER)
- {
- // scale down the attenuation to account for the cubefilter multiplying everything by 255
- attenuation *= (1.0f / 255.0f);
- d[0] = (int)((diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse)) * LightColor[0] * buffer_texture_cubebgra8[x*4+0] * attenuation);if (d[0] > 255) d[0] = 255;
- d[1] = (int)((diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse)) * LightColor[1] * buffer_texture_cubebgra8[x*4+1] * attenuation);if (d[1] > 255) d[1] = 255;
- d[2] = (int)((diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse)) * LightColor[2] * buffer_texture_cubebgra8[x*4+2] * attenuation);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255;
- }
- else
- {
- d[0] = (int)((diffusetex[0] * (Color_Ambient[0] + Color_Diffuse[0] * diffuse)) * LightColor[0] * attenuation);if (d[0] > 255) d[0] = 255;
- d[1] = (int)((diffusetex[1] * (Color_Ambient[1] + Color_Diffuse[1] * diffuse)) * LightColor[1] * attenuation);if (d[1] > 255) d[1] = 255;
- d[2] = (int)((diffusetex[2] * (Color_Ambient[2] + Color_Diffuse[2] * diffuse)) * LightColor[2] * attenuation);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255;
- }
- buffer_FragColorbgra8[x*4+0] = d[0];
- buffer_FragColorbgra8[x*4+1] = d[1];
- buffer_FragColorbgra8[x*4+2] = d[2];
- buffer_FragColorbgra8[x*4+3] = d[3];
- }
- }
- else
- {
- for (x = startx;x < endx;x++)
- {
- z = buffer_z[x];
- CubeVector[0] = (CubeVectordata[0] + CubeVectorslope[0]*x) * z;
- CubeVector[1] = (CubeVectordata[1] + CubeVectorslope[1]*x) * z;
- CubeVector[2] = (CubeVectordata[2] + CubeVectorslope[2]*x) * z;
- attenuation = 1.0f - DPSOFTRAST_Vector3LengthSquared(CubeVector);
- if (attenuation < 0.01f)
- continue;
- if (thread->shader_permutation & SHADERPERMUTATION_SHADOWMAP2D)
- {
- attenuation *= DPSOFTRAST_SampleShadowmap(CubeVector);
- if (attenuation < 0.01f)
- continue;
- }
-
- diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
- diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
- diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
- diffusetex[3] = buffer_texture_colorbgra8[x*4+3];
- if (thread->shader_permutation & SHADERPERMUTATION_COLORMAPPING)
- {
- diffusetex[0] += buffer_texture_pantsbgra8[x*4+0] * Color_Pants[0] + buffer_texture_shirtbgra8[x*4+0] * Color_Shirt[0];
- diffusetex[1] += buffer_texture_pantsbgra8[x*4+1] * Color_Pants[1] + buffer_texture_shirtbgra8[x*4+1] * Color_Shirt[1];
- diffusetex[2] += buffer_texture_pantsbgra8[x*4+2] * Color_Pants[2] + buffer_texture_shirtbgra8[x*4+2] * Color_Shirt[2];
- diffusetex[3] += buffer_texture_pantsbgra8[x*4+3] * Color_Pants[3] + buffer_texture_shirtbgra8[x*4+3] * Color_Shirt[3];
- }
- if (thread->shader_permutation & SHADERPERMUTATION_CUBEFILTER)
- {
- // scale down the attenuation to account for the cubefilter multiplying everything by 255
- attenuation *= (1.0f / 255.0f);
- d[0] = (int)((diffusetex[0] * (Color_Ambient[0])) * LightColor[0] * buffer_texture_cubebgra8[x*4+0] * attenuation);if (d[0] > 255) d[0] = 255;
- d[1] = (int)((diffusetex[1] * (Color_Ambient[1])) * LightColor[1] * buffer_texture_cubebgra8[x*4+1] * attenuation);if (d[1] > 255) d[1] = 255;
- d[2] = (int)((diffusetex[2] * (Color_Ambient[2])) * LightColor[2] * buffer_texture_cubebgra8[x*4+2] * attenuation);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255;
- }
- else
- {
- d[0] = (int)((diffusetex[0] * (Color_Ambient[0])) * LightColor[0] * attenuation);if (d[0] > 255) d[0] = 255;
- d[1] = (int)((diffusetex[1] * (Color_Ambient[1])) * LightColor[1] * attenuation);if (d[1] > 255) d[1] = 255;
- d[2] = (int)((diffusetex[2] * (Color_Ambient[2])) * LightColor[2] * attenuation);if (d[2] > 255) d[2] = 255;
- d[3] = (int)( diffusetex[3] );if (d[3] > 255) d[3] = 255;
- }
- buffer_FragColorbgra8[x*4+0] = d[0];
- buffer_FragColorbgra8[x*4+1] = d[1];
- buffer_FragColorbgra8[x*4+2] = d[2];
- buffer_FragColorbgra8[x*4+3] = d[3];
- }
- }
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-#endif
-}
-
-
-
-static void DPSOFTRAST_VertexShader_Refraction(void)
-{
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_Refraction(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- //float z;
- int x, startx = span->startx, endx = span->endx;
-
- // texture reads
- unsigned char buffer_texture_normalbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
-
- // varyings
- float ModelViewProjectionPositiondata[4];
- float ModelViewProjectionPositionslope[4];
-
- // uniforms
- float ScreenScaleRefractReflect[2];
- float ScreenCenterRefractReflect[2];
- float DistortScaleRefractReflect[2];
- float RefractColor[4];
-
- DPSOFTRAST_Texture *texture = thread->texbound[GL20TU_REFRACTION];
- if(!texture) return;
-
- // read textures
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
-
- // read varyings
- DPSOFTRAST_CALCATTRIB4F(triangle, span, ModelViewProjectionPositiondata, ModelViewProjectionPositionslope, DPSOFTRAST_ARRAY_TEXCOORD4);
-
- // read uniforms
- ScreenScaleRefractReflect[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect*4+0];
- ScreenScaleRefractReflect[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect*4+1];
- ScreenCenterRefractReflect[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect*4+0];
- ScreenCenterRefractReflect[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect*4+1];
- DistortScaleRefractReflect[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_DistortScaleRefractReflect*4+0];
- DistortScaleRefractReflect[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_DistortScaleRefractReflect*4+1];
- RefractColor[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+2];
- RefractColor[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+1];
- RefractColor[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+0];
- RefractColor[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+3];
-
- // do stuff
- for (x = startx;x < endx;x++)
- {
- float SafeScreenTexCoord[2];
- float ScreenTexCoord[2];
- float v[3];
- float iw;
- unsigned char c[4];
-
- //z = buffer_z[x];
-
- // " vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n"
- iw = 1.0f / (ModelViewProjectionPositiondata[3] + ModelViewProjectionPositionslope[3]*x); // / z
-
- // " vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
- SafeScreenTexCoord[0] = (ModelViewProjectionPositiondata[0] + ModelViewProjectionPositionslope[0]*x) * iw * ScreenScaleRefractReflect[0] + ScreenCenterRefractReflect[0]; // * z (disappears)
- SafeScreenTexCoord[1] = (ModelViewProjectionPositiondata[1] + ModelViewProjectionPositionslope[1]*x) * iw * ScreenScaleRefractReflect[1] + ScreenCenterRefractReflect[1]; // * z (disappears)
-
- // " vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(myhalf3(dp_texture2D(Texture_Normal, TexCoord)) - myhalf3(0.5))).xy * DistortScaleRefractReflect.zw;\n"
- v[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- v[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- v[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- DPSOFTRAST_Vector3Normalize(v);
- ScreenTexCoord[0] = SafeScreenTexCoord[0] + v[0] * DistortScaleRefractReflect[0];
- ScreenTexCoord[1] = SafeScreenTexCoord[1] + v[1] * DistortScaleRefractReflect[1];
-
- // " dp_FragColor = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord).rgb, 1.0) * RefractColor;\n"
- DPSOFTRAST_Texture2DBGRA8(texture, 0, ScreenTexCoord[0], ScreenTexCoord[1], c);
-
- buffer_FragColorbgra8[x*4+0] = c[0] * RefractColor[0];
- buffer_FragColorbgra8[x*4+1] = c[1] * RefractColor[1];
- buffer_FragColorbgra8[x*4+2] = c[2] * RefractColor[2];
- buffer_FragColorbgra8[x*4+3] = min(RefractColor[3] * 256, 255);
- }
-
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_Water(void)
-{
- int i;
- int numvertices = dpsoftrast.numvertices;
- float EyePosition[4];
- float EyeVectorModelSpace[4];
- float EyeVector[4];
- float position[4];
- float svector[4];
- float tvector[4];
- float normal[4];
- EyePosition[0] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+0];
- EyePosition[1] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+1];
- EyePosition[2] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+2];
- EyePosition[3] = dpsoftrast.uniform4f[DPSOFTRAST_UNIFORM_EyePosition*4+3];
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD1);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD2);
- DPSOFTRAST_Array_Load(DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD3);
- for (i = 0;i < numvertices;i++)
- {
- position[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+0];
- position[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+1];
- position[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION][i*4+2];
- svector[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+0];
- svector[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+1];
- svector[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD1][i*4+2];
- tvector[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+0];
- tvector[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+1];
- tvector[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD2][i*4+2];
- normal[0] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+0];
- normal[1] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+1];
- normal[2] = dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD3][i*4+2];
- EyeVectorModelSpace[0] = EyePosition[0] - position[0];
- EyeVectorModelSpace[1] = EyePosition[1] - position[1];
- EyeVectorModelSpace[2] = EyePosition[2] - position[2];
- EyeVector[0] = svector[0] * EyeVectorModelSpace[0] + svector[1] * EyeVectorModelSpace[1] + svector[2] * EyeVectorModelSpace[2];
- EyeVector[1] = tvector[0] * EyeVectorModelSpace[0] + tvector[1] * EyeVectorModelSpace[1] + tvector[2] * EyeVectorModelSpace[2];
- EyeVector[2] = normal[0] * EyeVectorModelSpace[0] + normal[1] * EyeVectorModelSpace[1] + normal[2] * EyeVectorModelSpace[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+0] = EyeVector[0];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+1] = EyeVector[1];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+2] = EyeVector[2];
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_TEXCOORD6][i*4+3] = 0.0f;
- }
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, -1, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
- DPSOFTRAST_Array_Transform(DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD0, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_TexMatrixM1);
-}
-
-
-static void DPSOFTRAST_PixelShader_Water(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- // float z;
- int x, startx = span->startx, endx = span->endx;
-
- // texture reads
- unsigned char buffer_texture_normalbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
-
- // varyings
- float ModelViewProjectionPositiondata[4];
- float ModelViewProjectionPositionslope[4];
- float EyeVectordata[4];
- float EyeVectorslope[4];
-
- // uniforms
- float ScreenScaleRefractReflect[4];
- float ScreenCenterRefractReflect[4];
- float DistortScaleRefractReflect[4];
- float RefractColor[4];
- float ReflectColor[4];
- float ReflectFactor;
- float ReflectOffset;
-
- DPSOFTRAST_Texture *texture_refraction = thread->texbound[GL20TU_REFRACTION];
- DPSOFTRAST_Texture *texture_reflection = thread->texbound[GL20TU_REFLECTION];
- if(!texture_refraction || !texture_reflection) return;
-
- // read textures
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(thread, triangle, span, buffer_texture_normalbgra8, GL20TU_NORMAL, DPSOFTRAST_ARRAY_TEXCOORD0, buffer_z);
-
- // read varyings
- DPSOFTRAST_CALCATTRIB4F(triangle, span, ModelViewProjectionPositiondata, ModelViewProjectionPositionslope, DPSOFTRAST_ARRAY_TEXCOORD4);
- DPSOFTRAST_CALCATTRIB4F(triangle, span, EyeVectordata, EyeVectorslope, DPSOFTRAST_ARRAY_TEXCOORD6);
-
- // read uniforms
- ScreenScaleRefractReflect[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect*4+0];
- ScreenScaleRefractReflect[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect*4+1];
- ScreenScaleRefractReflect[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect*4+2];
- ScreenScaleRefractReflect[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect*4+3];
- ScreenCenterRefractReflect[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect*4+0];
- ScreenCenterRefractReflect[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect*4+1];
- ScreenCenterRefractReflect[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect*4+2];
- ScreenCenterRefractReflect[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect*4+3];
- DistortScaleRefractReflect[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_DistortScaleRefractReflect*4+0];
- DistortScaleRefractReflect[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_DistortScaleRefractReflect*4+1];
- DistortScaleRefractReflect[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_DistortScaleRefractReflect*4+2];
- DistortScaleRefractReflect[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_DistortScaleRefractReflect*4+3];
- RefractColor[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+2];
- RefractColor[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+1];
- RefractColor[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+0];
- RefractColor[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_RefractColor*4+3];
- ReflectColor[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_ReflectColor*4+2];
- ReflectColor[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_ReflectColor*4+1];
- ReflectColor[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_ReflectColor*4+0];
- ReflectColor[3] = thread->uniform4f[DPSOFTRAST_UNIFORM_ReflectColor*4+3];
- ReflectFactor = thread->uniform4f[DPSOFTRAST_UNIFORM_ReflectFactor*4+0];
- ReflectOffset = thread->uniform4f[DPSOFTRAST_UNIFORM_ReflectOffset*4+0];
-
- // do stuff
- for (x = startx;x < endx;x++)
- {
- float SafeScreenTexCoord[4];
- float ScreenTexCoord[4];
- float v[3];
- float iw;
- unsigned char c1[4];
- unsigned char c2[4];
- float Fresnel;
-
- // z = buffer_z[x];
-
- // " vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
- iw = 1.0f / (ModelViewProjectionPositiondata[3] + ModelViewProjectionPositionslope[3]*x); // / z
-
- // " vec4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
- SafeScreenTexCoord[0] = (ModelViewProjectionPositiondata[0] + ModelViewProjectionPositionslope[0]*x) * iw * ScreenScaleRefractReflect[0] + ScreenCenterRefractReflect[0]; // * z (disappears)
- SafeScreenTexCoord[1] = (ModelViewProjectionPositiondata[1] + ModelViewProjectionPositionslope[1]*x) * iw * ScreenScaleRefractReflect[1] + ScreenCenterRefractReflect[1]; // * z (disappears)
- SafeScreenTexCoord[2] = (ModelViewProjectionPositiondata[0] + ModelViewProjectionPositionslope[0]*x) * iw * ScreenScaleRefractReflect[2] + ScreenCenterRefractReflect[2]; // * z (disappears)
- SafeScreenTexCoord[3] = (ModelViewProjectionPositiondata[1] + ModelViewProjectionPositionslope[1]*x) * iw * ScreenScaleRefractReflect[3] + ScreenCenterRefractReflect[3]; // * z (disappears)
-
- // " vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * DistortScaleRefractReflect;\n"
- v[0] = buffer_texture_normalbgra8[x*4+2] * (1.0f / 128.0f) - 1.0f;
- v[1] = buffer_texture_normalbgra8[x*4+1] * (1.0f / 128.0f) - 1.0f;
- v[2] = buffer_texture_normalbgra8[x*4+0] * (1.0f / 128.0f) - 1.0f;
- DPSOFTRAST_Vector3Normalize(v);
- ScreenTexCoord[0] = SafeScreenTexCoord[0] + v[0] * DistortScaleRefractReflect[0];
- ScreenTexCoord[1] = SafeScreenTexCoord[1] + v[1] * DistortScaleRefractReflect[1];
- ScreenTexCoord[2] = SafeScreenTexCoord[2] + v[0] * DistortScaleRefractReflect[2];
- ScreenTexCoord[3] = SafeScreenTexCoord[3] + v[1] * DistortScaleRefractReflect[3];
-
- // " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * ReflectFactor + ReflectOffset;\n"
- v[0] = (EyeVectordata[0] + EyeVectorslope[0] * x); // * z (disappears)
- v[1] = (EyeVectordata[1] + EyeVectorslope[1] * x); // * z (disappears)
- v[2] = (EyeVectordata[2] + EyeVectorslope[2] * x); // * z (disappears)
- DPSOFTRAST_Vector3Normalize(v);
- Fresnel = 1.0f - v[2];
- Fresnel = min(1.0f, Fresnel);
- Fresnel = Fresnel * Fresnel * ReflectFactor + ReflectOffset;
-
- // " dp_FragColor = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord).rgb, 1.0) * RefractColor;\n"
- // " dp_FragColor = mix(vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * RefractColor, vec4(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n"
- DPSOFTRAST_Texture2DBGRA8(texture_refraction, 0, ScreenTexCoord[0], ScreenTexCoord[1], c1);
- DPSOFTRAST_Texture2DBGRA8(texture_reflection, 0, ScreenTexCoord[2], ScreenTexCoord[3], c2);
-
- buffer_FragColorbgra8[x*4+0] = (c1[0] * RefractColor[0]) * (1.0f - Fresnel) + (c2[0] * ReflectColor[0]) * Fresnel;
- buffer_FragColorbgra8[x*4+1] = (c1[1] * RefractColor[1]) * (1.0f - Fresnel) + (c2[1] * ReflectColor[1]) * Fresnel;
- buffer_FragColorbgra8[x*4+2] = (c1[2] * RefractColor[2]) * (1.0f - Fresnel) + (c2[2] * ReflectColor[2]) * Fresnel;
- buffer_FragColorbgra8[x*4+3] = min(( RefractColor[3] * (1.0f - Fresnel) + ReflectColor[3] * Fresnel) * 256, 255);
- }
-
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_DeferredGeometry(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_DeferredGeometry(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- // TODO: IMPLEMENT
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- memset(buffer_FragColorbgra8 + span->startx*4, 0, (span->endx - span->startx)*4);
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-static void DPSOFTRAST_VertexShader_DeferredLightSource(void)
-{
- DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_DeferredLightSource(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
- // TODO: IMPLEMENT
- float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
- unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
- DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
- memset(buffer_FragColorbgra8 + span->startx*4, 0, (span->endx - span->startx)*4);
- DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
-typedef struct DPSOFTRAST_ShaderModeInfo_s
-{
- int lodarrayindex;
- void (*Vertex)(void);
- void (*Span)(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span);
- unsigned char arrays[DPSOFTRAST_ARRAY_TOTAL];
- unsigned char texunits[DPSOFTRAST_MAXTEXTUREUNITS];
-}
-DPSOFTRAST_ShaderModeInfo;
-
-static const DPSOFTRAST_ShaderModeInfo DPSOFTRAST_ShaderModeTable[SHADERMODE_COUNT] =
-{
- {2, DPSOFTRAST_VertexShader_Generic, DPSOFTRAST_PixelShader_Generic, {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, 0xFF}, {GL20TU_FIRST, GL20TU_SECOND, 0xFF}},
- {2, DPSOFTRAST_VertexShader_PostProcess, DPSOFTRAST_PixelShader_PostProcess, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, 0xFF}, {GL20TU_FIRST, GL20TU_SECOND, 0xFF}},
- {2, DPSOFTRAST_VertexShader_Depth_Or_Shadow, DPSOFTRAST_PixelShader_Depth_Or_Shadow, {0xFF}, {0xFF}},
- {2, DPSOFTRAST_VertexShader_FlatColor, DPSOFTRAST_PixelShader_FlatColor, {DPSOFTRAST_ARRAY_TEXCOORD0, 0xFF}, {GL20TU_COLOR, 0xFF}},
- {2, DPSOFTRAST_VertexShader_VertexColor, DPSOFTRAST_PixelShader_VertexColor, {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, 0xFF}, {GL20TU_COLOR, 0xFF}},
- {2, DPSOFTRAST_VertexShader_Lightmap, DPSOFTRAST_PixelShader_Lightmap, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_COLOR, GL20TU_LIGHTMAP, GL20TU_GLOW, 0xFF}},
- {2, DPSOFTRAST_VertexShader_FakeLight, DPSOFTRAST_PixelShader_FakeLight, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, 0xFF}},
- {2, DPSOFTRAST_VertexShader_LightDirectionMap_ModelSpace, DPSOFTRAST_PixelShader_LightDirectionMap_ModelSpace, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_LIGHTMAP, GL20TU_DELUXEMAP, 0xFF}},
- {2, DPSOFTRAST_VertexShader_LightDirectionMap_TangentSpace, DPSOFTRAST_PixelShader_LightDirectionMap_TangentSpace, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_LIGHTMAP, GL20TU_DELUXEMAP, 0xFF}},
- {2, DPSOFTRAST_VertexShader_Lightmap, DPSOFTRAST_PixelShader_Lightmap, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_COLOR, GL20TU_LIGHTMAP, GL20TU_GLOW, 0xFF}},
- {2, DPSOFTRAST_VertexShader_VertexColor, DPSOFTRAST_PixelShader_VertexColor, {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, 0xFF}, {GL20TU_COLOR, 0xFF}},
- {2, DPSOFTRAST_VertexShader_LightDirection, DPSOFTRAST_PixelShader_LightDirection, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, 0xFF}},
- {2, DPSOFTRAST_VertexShader_LightSource, DPSOFTRAST_PixelShader_LightSource, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_CUBE, 0xFF}},
- {2, DPSOFTRAST_VertexShader_Refraction, DPSOFTRAST_PixelShader_Refraction, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_NORMAL, GL20TU_REFRACTION, 0xFF}},
- {2, DPSOFTRAST_VertexShader_Water, DPSOFTRAST_PixelShader_Water, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_NORMAL, GL20TU_REFLECTION, GL20TU_REFRACTION, 0xFF}},
- {2, DPSOFTRAST_VertexShader_DeferredGeometry, DPSOFTRAST_PixelShader_DeferredGeometry, {0xFF}},
- {2, DPSOFTRAST_VertexShader_DeferredLightSource, DPSOFTRAST_PixelShader_DeferredLightSource, {0xFF}},
-};
-
-static void DPSOFTRAST_Draw_DepthTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_State_Span *span)
-{
- int x;
- int startx;
- int endx;
- unsigned int *depthpixel;
- int depth;
- int depthslope;
- unsigned int d;
- unsigned char *pixelmask;
- depthpixel = dpsoftrast.fb_depthpixels + span->y * dpsoftrast.fb_width + span->x;
- startx = span->startx;
- endx = span->endx;
- depth = span->depthbase;
- depthslope = span->depthslope;
- pixelmask = thread->pixelmaskarray;
- if (thread->depthtest && dpsoftrast.fb_depthpixels)
- {
- switch(thread->fb_depthfunc)
- {
- default:
- case GL_ALWAYS: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = true; break;
- case GL_LESS: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = depthpixel[x] < d; break;
- case GL_LEQUAL: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = depthpixel[x] <= d; break;
- case GL_EQUAL: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = depthpixel[x] == d; break;
- case GL_GEQUAL: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = depthpixel[x] >= d; break;
- case GL_GREATER: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = depthpixel[x] > d; break;
- case GL_NEVER: for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope) pixelmask[x] = false; break;
- }
- while (startx < endx && !pixelmask[startx])
- startx++;
- while (endx > startx && !pixelmask[endx-1])
- endx--;
- }
- else
- {
- // no depth testing means we're just dealing with color...
- memset(pixelmask + startx, 1, endx - startx);
- }
- span->pixelmask = pixelmask;
- span->startx = startx;
- span->endx = endx;
-}
-
-static void DPSOFTRAST_Draw_DepthWrite(const DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Span *span)
-{
- int x, d, depth, depthslope, startx, endx;
- const unsigned char *pixelmask;
- unsigned int *depthpixel;
- if (thread->depthmask && thread->depthtest && dpsoftrast.fb_depthpixels)
- {
- depth = span->depthbase;
- depthslope = span->depthslope;
- pixelmask = span->pixelmask;
- startx = span->startx;
- endx = span->endx;
- depthpixel = dpsoftrast.fb_depthpixels + span->y * dpsoftrast.fb_width + span->x;
- for (x = startx, d = depth + depthslope*startx;x < endx;x++, d += depthslope)
- if (pixelmask[x])
- depthpixel[x] = d;
- }
-}
-
-static void DPSOFTRAST_Draw_ProcessSpans(DPSOFTRAST_State_Thread *thread)
-{
- int i;
- DPSOFTRAST_State_Triangle *triangle;
- DPSOFTRAST_State_Span *span;
- for (i = 0; i < thread->numspans; i++)
- {
- span = &thread->spans[i];
- triangle = &thread->triangles[span->triangle];
- DPSOFTRAST_Draw_DepthTest(thread, span);
- if (span->startx >= span->endx)
- continue;
- // run pixel shader if appropriate
- // do this before running depthmask code, to allow the pixelshader
- // to clear pixelmask values for alpha testing
- if (dpsoftrast.fb_colorpixels[0] && thread->fb_colormask)
- DPSOFTRAST_ShaderModeTable[thread->shader_mode].Span(thread, triangle, span);
- DPSOFTRAST_Draw_DepthWrite(thread, span);
- }
- thread->numspans = 0;
-}
-
-DEFCOMMAND(22, Draw, int datasize; int starty; int endy; ATOMIC_COUNTER refcount; int clipped; int firstvertex; int numvertices; int numtriangles; float *arrays; int *element3i; unsigned short *element3s;)
-
-static void DPSOFTRAST_Interpret_Draw(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_Draw *command)
-{
-#ifdef SSE_POSSIBLE
- int cullface = thread->cullface;
- int minx, maxx, miny, maxy;
- int miny1, maxy1, miny2, maxy2;
- __m128i fbmin, fbmax;
- __m128 viewportcenter, viewportscale;
- int firstvertex = command->firstvertex;
- int numvertices = command->numvertices;
- int numtriangles = command->numtriangles;
- const int *element3i = command->element3i;
- const unsigned short *element3s = command->element3s;
- int clipped = command->clipped;
- int i;
- int j;
- int k;
- int y;
- int e[3];
- __m128i screeny;
- int starty, endy, bandy;
- int numpoints;
- int clipcase;
- float clipdist[4];
- float clip0origin, clip0slope;
- int clip0dir;
- __m128 triangleedge1, triangleedge2, trianglenormal;
- __m128 clipfrac[3];
- __m128 screen[4];
- DPSOFTRAST_State_Triangle *triangle;
- DPSOFTRAST_Texture *texture;
- DPSOFTRAST_ValidateQuick(thread, DPSOFTRAST_VALIDATE_DRAW);
- miny = thread->fb_scissor[1];
- maxy = thread->fb_scissor[1] + thread->fb_scissor[3];
- miny1 = bound(miny, thread->miny1, maxy);
- maxy1 = bound(miny, thread->maxy1, maxy);
- miny2 = bound(miny, thread->miny2, maxy);
- maxy2 = bound(miny, thread->maxy2, maxy);
- if ((command->starty >= maxy1 || command->endy <= miny1) && (command->starty >= maxy2 || command->endy <= miny2))
- {
- if (!ATOMIC_DECREMENT(command->refcount))
- {
- if (command->commandsize <= DPSOFTRAST_ALIGNCOMMAND(sizeof(DPSOFTRAST_Command_Draw)))
- MM_FREE(command->arrays);
- }
- return;
- }
- minx = thread->fb_scissor[0];
- maxx = thread->fb_scissor[0] + thread->fb_scissor[2];
- fbmin = _mm_setr_epi16(minx, miny1, minx, miny1, minx, miny1, minx, miny1);
- fbmax = _mm_sub_epi16(_mm_setr_epi16(maxx, maxy2, maxx, maxy2, maxx, maxy2, maxx, maxy2), _mm_set1_epi16(1));
- viewportcenter = _mm_load_ps(thread->fb_viewportcenter);
- viewportscale = _mm_load_ps(thread->fb_viewportscale);
- screen[3] = _mm_setzero_ps();
- clipfrac[0] = clipfrac[1] = clipfrac[2] = _mm_setzero_ps();
- for (i = 0;i < numtriangles;i++)
- {
- const float *screencoord4f = command->arrays;
- const float *arrays = screencoord4f + numvertices*4;
-
- // generate the 3 edges of this triangle
- // generate spans for the triangle - switch based on left split or right split classification of triangle
- if (element3s)
- {
- e[0] = element3s[i*3+0] - firstvertex;
- e[1] = element3s[i*3+1] - firstvertex;
- e[2] = element3s[i*3+2] - firstvertex;
- }
- else if (element3i)
- {
- e[0] = element3i[i*3+0] - firstvertex;
- e[1] = element3i[i*3+1] - firstvertex;
- e[2] = element3i[i*3+2] - firstvertex;
- }
- else
- {
- e[0] = i*3+0;
- e[1] = i*3+1;
- e[2] = i*3+2;
- }
-
-#define SKIPBACKFACE \
- triangleedge1 = _mm_sub_ps(screen[0], screen[1]); \
- triangleedge2 = _mm_sub_ps(screen[2], screen[1]); \
- /* store normal in 2, 0, 1 order instead of 0, 1, 2 as it requires fewer shuffles and leaves z component accessible as scalar */ \
- trianglenormal = _mm_sub_ss(_mm_mul_ss(triangleedge1, _mm_shuffle_ps(triangleedge2, triangleedge2, _MM_SHUFFLE(3, 0, 2, 1))), \
- _mm_mul_ss(_mm_shuffle_ps(triangleedge1, triangleedge1, _MM_SHUFFLE(3, 0, 2, 1)), triangleedge2)); \
- switch(cullface) \
- { \
- case GL_BACK: \
- if (_mm_ucomilt_ss(trianglenormal, _mm_setzero_ps())) \
- continue; \
- break; \
- case GL_FRONT: \
- if (_mm_ucomigt_ss(trianglenormal, _mm_setzero_ps())) \
- continue; \
- break; \
- }
-
-#define CLIPPEDVERTEXLERP(k,p1, p2) \
- clipfrac[p1] = _mm_set1_ps(clipdist[p1] / (clipdist[p1] - clipdist[p2])); \
- { \
- __m128 v1 = _mm_load_ps(&arrays[e[p1]*4]), v2 = _mm_load_ps(&arrays[e[p2]*4]); \
- DPSOFTRAST_PROJECTVERTEX(screen[k], _mm_add_ps(v1, _mm_mul_ps(_mm_sub_ps(v2, v1), clipfrac[p1])), viewportcenter, viewportscale); \
- }
-#define CLIPPEDVERTEXCOPY(k,p1) \
- screen[k] = _mm_load_ps(&screencoord4f[e[p1]*4]);
-
-#define GENATTRIBCOPY(attrib, p1) \
- attrib = _mm_load_ps(&arrays[e[p1]*4]);
-#define GENATTRIBLERP(attrib, p1, p2) \
- { \
- __m128 v1 = _mm_load_ps(&arrays[e[p1]*4]), v2 = _mm_load_ps(&arrays[e[p2]*4]); \
- attrib = _mm_add_ps(v1, _mm_mul_ps(_mm_sub_ps(v2, v1), clipfrac[p1])); \
- }
-#define GENATTRIBS(attrib0, attrib1, attrib2) \
- switch(clipcase) \
- { \
- default: \
- case 0: GENATTRIBCOPY(attrib0, 0); GENATTRIBCOPY(attrib1, 1); GENATTRIBCOPY(attrib2, 2); break; \
- case 1: GENATTRIBCOPY(attrib0, 0); GENATTRIBCOPY(attrib1, 1); GENATTRIBLERP(attrib2, 1, 2); break; \
- case 2: GENATTRIBCOPY(attrib0, 0); GENATTRIBLERP(attrib1, 0, 1); GENATTRIBLERP(attrib2, 1, 2); break; \
- case 3: GENATTRIBCOPY(attrib0, 0); GENATTRIBLERP(attrib1, 0, 1); GENATTRIBLERP(attrib2, 2, 0); break; \
- case 4: GENATTRIBLERP(attrib0, 0, 1); GENATTRIBCOPY(attrib1, 1); GENATTRIBCOPY(attrib2, 2); break; \
- case 5: GENATTRIBLERP(attrib0, 0, 1); GENATTRIBCOPY(attrib1, 1); GENATTRIBLERP(attrib2, 1, 2); break; \
- case 6: GENATTRIBLERP(attrib0, 1, 2); GENATTRIBCOPY(attrib1, 2); GENATTRIBLERP(attrib2, 2, 0); break; \
- }
-
- if (! clipped)
- goto notclipped;
-
- // calculate distance from nearplane
- clipdist[0] = arrays[e[0]*4+2] + arrays[e[0]*4+3];
- clipdist[1] = arrays[e[1]*4+2] + arrays[e[1]*4+3];
- clipdist[2] = arrays[e[2]*4+2] + arrays[e[2]*4+3];
- if (clipdist[0] >= 0.0f)
- {
- if (clipdist[1] >= 0.0f)
- {
- if (clipdist[2] >= 0.0f)
- {
- notclipped:
- // triangle is entirely in front of nearplane
- CLIPPEDVERTEXCOPY(0,0); CLIPPEDVERTEXCOPY(1,1); CLIPPEDVERTEXCOPY(2,2);
- SKIPBACKFACE;
- numpoints = 3;
- clipcase = 0;
- }
- else
- {
- CLIPPEDVERTEXCOPY(0,0); CLIPPEDVERTEXCOPY(1,1); CLIPPEDVERTEXLERP(2,1,2); CLIPPEDVERTEXLERP(3,2,0);
- SKIPBACKFACE;
- numpoints = 4;
- clipcase = 1;
- }
- }
- else
- {
- if (clipdist[2] >= 0.0f)
- {
- CLIPPEDVERTEXCOPY(0,0); CLIPPEDVERTEXLERP(1,0,1); CLIPPEDVERTEXLERP(2,1,2); CLIPPEDVERTEXCOPY(3,2);
- SKIPBACKFACE;
- numpoints = 4;
- clipcase = 2;
- }
- else
- {
- CLIPPEDVERTEXCOPY(0,0); CLIPPEDVERTEXLERP(1,0,1); CLIPPEDVERTEXLERP(2,2,0);
- SKIPBACKFACE;
- numpoints = 3;
- clipcase = 3;
- }
- }
- }
- else if (clipdist[1] >= 0.0f)
- {
- if (clipdist[2] >= 0.0f)
- {
- CLIPPEDVERTEXLERP(0,0,1); CLIPPEDVERTEXCOPY(1,1); CLIPPEDVERTEXCOPY(2,2); CLIPPEDVERTEXLERP(3,2,0);
- SKIPBACKFACE;
- numpoints = 4;
- clipcase = 4;
- }
- else
- {
- CLIPPEDVERTEXLERP(0,0,1); CLIPPEDVERTEXCOPY(1,1); CLIPPEDVERTEXLERP(2,1,2);
- SKIPBACKFACE;
- numpoints = 3;
- clipcase = 5;
- }
- }
- else if (clipdist[2] >= 0.0f)
- {
- CLIPPEDVERTEXLERP(0,1,2); CLIPPEDVERTEXCOPY(1,2); CLIPPEDVERTEXLERP(2,2,0);
- SKIPBACKFACE;
- numpoints = 3;
- clipcase = 6;
- }
- else continue; // triangle is entirely behind nearplane
-
- {
- // calculate integer y coords for triangle points
- __m128i screeni = _mm_packs_epi32(_mm_cvttps_epi32(_mm_movelh_ps(screen[0], screen[1])), _mm_cvttps_epi32(_mm_movelh_ps(screen[2], numpoints > 3 ? screen[3] : screen[2]))),
- screenir = _mm_shuffle_epi32(screeni, _MM_SHUFFLE(1, 0, 3, 2)),
- screenmin = _mm_min_epi16(screeni, screenir),
- screenmax = _mm_max_epi16(screeni, screenir);
- screenmin = _mm_min_epi16(screenmin, _mm_shufflelo_epi16(screenmin, _MM_SHUFFLE(1, 0, 3, 2)));
- screenmax = _mm_max_epi16(screenmax, _mm_shufflelo_epi16(screenmax, _MM_SHUFFLE(1, 0, 3, 2)));
- screenmin = _mm_max_epi16(screenmin, fbmin);
- screenmax = _mm_min_epi16(screenmax, fbmax);
- // skip offscreen triangles
- if (_mm_cvtsi128_si32(_mm_cmplt_epi16(screenmax, screenmin)))
- continue;
- starty = _mm_extract_epi16(screenmin, 1);
- endy = _mm_extract_epi16(screenmax, 1)+1;
- if (starty >= maxy1 && endy <= miny2)
- continue;
- screeny = _mm_srai_epi32(screeni, 16);
- }
-
- triangle = &thread->triangles[thread->numtriangles];
-
- // calculate attribute plans for triangle data...
- // okay, this triangle is going to produce spans, we'd better project
- // the interpolants now (this is what gives perspective texturing),
- // this consists of simply multiplying all arrays by the W coord
- // (which is basically 1/Z), which will be undone per-pixel
- // (multiplying by Z again) to get the perspective-correct array
- // values
- {
- __m128 attribuvslope, attribuxslope, attribuyslope, attribvxslope, attribvyslope, attriborigin, attribedge1, attribedge2, attribxslope, attribyslope, w0, w1, w2, x1, y1;
- __m128 mipedgescale, mipdensity;
- attribuvslope = _mm_div_ps(_mm_movelh_ps(triangleedge1, triangleedge2), _mm_shuffle_ps(trianglenormal, trianglenormal, _MM_SHUFFLE(0, 0, 0, 0)));
- attribuxslope = _mm_shuffle_ps(attribuvslope, attribuvslope, _MM_SHUFFLE(3, 3, 3, 3));
- attribuyslope = _mm_shuffle_ps(attribuvslope, attribuvslope, _MM_SHUFFLE(2, 2, 2, 2));
- attribvxslope = _mm_shuffle_ps(attribuvslope, attribuvslope, _MM_SHUFFLE(1, 1, 1, 1));
- attribvyslope = _mm_shuffle_ps(attribuvslope, attribuvslope, _MM_SHUFFLE(0, 0, 0, 0));
- w0 = _mm_shuffle_ps(screen[0], screen[0], _MM_SHUFFLE(3, 3, 3, 3));
- w1 = _mm_shuffle_ps(screen[1], screen[1], _MM_SHUFFLE(3, 3, 3, 3));
- w2 = _mm_shuffle_ps(screen[2], screen[2], _MM_SHUFFLE(3, 3, 3, 3));
- attribedge1 = _mm_sub_ss(w0, w1);
- attribedge2 = _mm_sub_ss(w2, w1);
- attribxslope = _mm_sub_ss(_mm_mul_ss(attribuxslope, attribedge1), _mm_mul_ss(attribvxslope, attribedge2));
- attribyslope = _mm_sub_ss(_mm_mul_ss(attribvyslope, attribedge2), _mm_mul_ss(attribuyslope, attribedge1));
- x1 = _mm_shuffle_ps(screen[1], screen[1], _MM_SHUFFLE(0, 0, 0, 0));
- y1 = _mm_shuffle_ps(screen[1], screen[1], _MM_SHUFFLE(1, 1, 1, 1));
- attriborigin = _mm_sub_ss(w1, _mm_add_ss(_mm_mul_ss(attribxslope, x1), _mm_mul_ss(attribyslope, y1)));
- _mm_store_ss(&triangle->w[0], attribxslope);
- _mm_store_ss(&triangle->w[1], attribyslope);
- _mm_store_ss(&triangle->w[2], attriborigin);
-
- clip0origin = 0;
- clip0slope = 0;
- clip0dir = 0;
- if(thread->fb_clipplane[0] || thread->fb_clipplane[1] || thread->fb_clipplane[2])
- {
- float cliporigin, clipxslope, clipyslope;
- attriborigin = _mm_shuffle_ps(screen[1], screen[1], _MM_SHUFFLE(2, 2, 2, 2));
- attribedge1 = _mm_sub_ss(_mm_shuffle_ps(screen[0], screen[0], _MM_SHUFFLE(2, 2, 2, 2)), attriborigin);
- attribedge2 = _mm_sub_ss(_mm_shuffle_ps(screen[2], screen[2], _MM_SHUFFLE(2, 2, 2, 2)), attriborigin);
- attribxslope = _mm_sub_ss(_mm_mul_ss(attribuxslope, attribedge1), _mm_mul_ss(attribvxslope, attribedge2));
- attribyslope = _mm_sub_ss(_mm_mul_ss(attribvyslope, attribedge2), _mm_mul_ss(attribuyslope, attribedge1));
- attriborigin = _mm_sub_ss(attriborigin, _mm_add_ss(_mm_mul_ss(attribxslope, x1), _mm_mul_ss(attribyslope, y1)));
- cliporigin = _mm_cvtss_f32(attriborigin)*thread->fb_clipplane[2] + thread->fb_clipplane[3];
- clipxslope = thread->fb_clipplane[0] + _mm_cvtss_f32(attribxslope)*thread->fb_clipplane[2];
- clipyslope = thread->fb_clipplane[1] + _mm_cvtss_f32(attribyslope)*thread->fb_clipplane[2];
- if(clipxslope != 0)
- {
- clip0origin = -cliporigin/clipxslope;
- clip0slope = -clipyslope/clipxslope;
- clip0dir = clipxslope > 0 ? 1 : -1;
- }
- else if(clipyslope > 0)
- {
- clip0origin = dpsoftrast.fb_width*floor(cliporigin/clipyslope);
- clip0slope = dpsoftrast.fb_width;
- clip0dir = -1;
- }
- else if(clipyslope < 0)
- {
- clip0origin = dpsoftrast.fb_width*ceil(cliporigin/clipyslope);
- clip0slope = -dpsoftrast.fb_width;
- clip0dir = -1;
- }
- else if(clip0origin < 0) continue;
- }
-
- mipedgescale = _mm_setzero_ps();
- for (j = 0;j < DPSOFTRAST_ARRAY_TOTAL; j++)
- {
- __m128 attrib0, attrib1, attrib2;
- k = DPSOFTRAST_ShaderModeTable[thread->shader_mode].arrays[j];
- if (k >= DPSOFTRAST_ARRAY_TOTAL)
- break;
- arrays += numvertices*4;
- GENATTRIBS(attrib0, attrib1, attrib2);
- attriborigin = _mm_mul_ps(attrib1, w1);
- attribedge1 = _mm_sub_ps(_mm_mul_ps(attrib0, w0), attriborigin);
- attribedge2 = _mm_sub_ps(_mm_mul_ps(attrib2, w2), attriborigin);
- attribxslope = _mm_sub_ps(_mm_mul_ps(attribuxslope, attribedge1), _mm_mul_ps(attribvxslope, attribedge2));
- attribyslope = _mm_sub_ps(_mm_mul_ps(attribvyslope, attribedge2), _mm_mul_ps(attribuyslope, attribedge1));
- attriborigin = _mm_sub_ps(attriborigin, _mm_add_ps(_mm_mul_ps(attribxslope, x1), _mm_mul_ps(attribyslope, y1)));
- _mm_storeu_ps(triangle->attribs[k][0], attribxslope);
- _mm_storeu_ps(triangle->attribs[k][1], attribyslope);
- _mm_storeu_ps(triangle->attribs[k][2], attriborigin);
- if (k == DPSOFTRAST_ShaderModeTable[thread->shader_mode].lodarrayindex)
- {
- mipedgescale = _mm_movelh_ps(triangleedge1, triangleedge2);
- mipedgescale = _mm_mul_ps(mipedgescale, mipedgescale);
- mipedgescale = _mm_rsqrt_ps(_mm_add_ps(mipedgescale, _mm_shuffle_ps(mipedgescale, mipedgescale, _MM_SHUFFLE(2, 3, 0, 1))));
- mipedgescale = _mm_mul_ps(_mm_sub_ps(_mm_movelh_ps(attrib0, attrib2), _mm_movelh_ps(attrib1, attrib1)), mipedgescale);
- }
- }
-
- memset(triangle->mip, 0, sizeof(triangle->mip));
- for (j = 0;j < DPSOFTRAST_MAXTEXTUREUNITS;j++)
- {
- int texunit = DPSOFTRAST_ShaderModeTable[thread->shader_mode].texunits[j];
- if (texunit >= DPSOFTRAST_MAXTEXTUREUNITS)
- break;
- texture = thread->texbound[texunit];
- if (texture && texture->filter > DPSOFTRAST_TEXTURE_FILTER_LINEAR)
- {
- mipdensity = _mm_mul_ps(mipedgescale, _mm_cvtepi32_ps(_mm_shuffle_epi32(_mm_loadl_epi64((const __m128i *)&texture->mipmap[0][2]), _MM_SHUFFLE(1, 0, 1, 0))));
- mipdensity = _mm_mul_ps(mipdensity, mipdensity);
- mipdensity = _mm_add_ps(mipdensity, _mm_shuffle_ps(mipdensity, mipdensity, _MM_SHUFFLE(2, 3, 0, 1)));
- mipdensity = _mm_min_ss(mipdensity, _mm_shuffle_ps(mipdensity, mipdensity, _MM_SHUFFLE(2, 2, 2, 2)));
- // this will be multiplied in the texturing routine by the texture resolution
- y = _mm_cvtss_si32(mipdensity);
- if (y > 0)
- {
- y = (int)(log((float)y)*0.5f/M_LN2);
- if (y > texture->mipmaps - 1)
- y = texture->mipmaps - 1;
- triangle->mip[texunit] = y;
- }
- }
- }
- }
-
- for (y = starty, bandy = min(endy, maxy1); y < endy; bandy = min(endy, maxy2), y = max(y, miny2))
- for (; y < bandy;)
- {
- __m128 xcoords, xslope;
- __m128i ycc = _mm_cmpgt_epi32(_mm_set1_epi32(y), screeny);
- int yccmask = _mm_movemask_epi8(ycc);
- int edge0p, edge0n, edge1p, edge1n;
- int nexty;
- float w, wslope;
- float clip0;
- if (numpoints == 4)
- {
- switch(yccmask)
- {
- default:
- case 0xFFFF: /*0000*/ y = endy; continue;
- case 0xFFF0: /*1000*/ edge0p = 3;edge0n = 0;edge1p = 1;edge1n = 0;break;
- case 0xFF0F: /*0100*/ edge0p = 0;edge0n = 1;edge1p = 2;edge1n = 1;break;
- case 0xFF00: /*1100*/ edge0p = 3;edge0n = 0;edge1p = 2;edge1n = 1;break;
- case 0xF0FF: /*0010*/ edge0p = 1;edge0n = 2;edge1p = 3;edge1n = 2;break;
- case 0xF0F0: /*1010*/ edge0p = 1;edge0n = 2;edge1p = 3;edge1n = 2;break; // concave - nonsense
- case 0xF00F: /*0110*/ edge0p = 0;edge0n = 1;edge1p = 3;edge1n = 2;break;
- case 0xF000: /*1110*/ edge0p = 3;edge0n = 0;edge1p = 3;edge1n = 2;break;
- case 0x0FFF: /*0001*/ edge0p = 2;edge0n = 3;edge1p = 0;edge1n = 3;break;
- case 0x0FF0: /*1001*/ edge0p = 2;edge0n = 3;edge1p = 1;edge1n = 0;break;
- case 0x0F0F: /*0101*/ edge0p = 2;edge0n = 3;edge1p = 2;edge1n = 1;break; // concave - nonsense
- case 0x0F00: /*1101*/ edge0p = 2;edge0n = 3;edge1p = 2;edge1n = 1;break;
- case 0x00FF: /*0011*/ edge0p = 1;edge0n = 2;edge1p = 0;edge1n = 3;break;
- case 0x00F0: /*1011*/ edge0p = 1;edge0n = 2;edge1p = 1;edge1n = 0;break;
- case 0x000F: /*0111*/ edge0p = 0;edge0n = 1;edge1p = 0;edge1n = 3;break;
- case 0x0000: /*1111*/ y++; continue;
- }
- }
- else
- {
- switch(yccmask)
- {
- default:
- case 0xFFFF: /*000*/ y = endy; continue;
- case 0xFFF0: /*100*/ edge0p = 2;edge0n = 0;edge1p = 1;edge1n = 0;break;
- case 0xFF0F: /*010*/ edge0p = 0;edge0n = 1;edge1p = 2;edge1n = 1;break;
- case 0xFF00: /*110*/ edge0p = 2;edge0n = 0;edge1p = 2;edge1n = 1;break;
- case 0x00FF: /*001*/ edge0p = 1;edge0n = 2;edge1p = 0;edge1n = 2;break;
- case 0x00F0: /*101*/ edge0p = 1;edge0n = 2;edge1p = 1;edge1n = 0;break;
- case 0x000F: /*011*/ edge0p = 0;edge0n = 1;edge1p = 0;edge1n = 2;break;
- case 0x0000: /*111*/ y++; continue;
- }
- }
- ycc = _mm_max_epi16(_mm_srli_epi16(ycc, 1), screeny);
- ycc = _mm_min_epi16(ycc, _mm_shuffle_epi32(ycc, _MM_SHUFFLE(1, 0, 3, 2)));
- ycc = _mm_min_epi16(ycc, _mm_shuffle_epi32(ycc, _MM_SHUFFLE(2, 3, 0, 1)));
- nexty = _mm_extract_epi16(ycc, 0);
- if (nexty >= bandy) nexty = bandy-1;
- xslope = _mm_sub_ps(_mm_movelh_ps(screen[edge0n], screen[edge1n]), _mm_movelh_ps(screen[edge0p], screen[edge1p]));
- xslope = _mm_div_ps(xslope, _mm_shuffle_ps(xslope, xslope, _MM_SHUFFLE(3, 3, 1, 1)));
- xcoords = _mm_add_ps(_mm_movelh_ps(screen[edge0p], screen[edge1p]),
- _mm_mul_ps(xslope, _mm_sub_ps(_mm_set1_ps(y), _mm_shuffle_ps(screen[edge0p], screen[edge1p], _MM_SHUFFLE(1, 1, 1, 1)))));
- xcoords = _mm_add_ps(xcoords, _mm_set1_ps(0.5f));
- if (_mm_ucomigt_ss(xcoords, _mm_shuffle_ps(xcoords, xcoords, _MM_SHUFFLE(1, 0, 3, 2))))
- {
- xcoords = _mm_shuffle_ps(xcoords, xcoords, _MM_SHUFFLE(1, 0, 3, 2));
- xslope = _mm_shuffle_ps(xslope, xslope, _MM_SHUFFLE(1, 0, 3, 2));
- }
- clip0 = clip0origin + (y+0.5f)*clip0slope + 0.5f;
- for(; y <= nexty; y++, xcoords = _mm_add_ps(xcoords, xslope), clip0 += clip0slope)
- {
- int startx, endx, offset;
- startx = _mm_cvtss_si32(xcoords);
- endx = _mm_cvtss_si32(_mm_movehl_ps(xcoords, xcoords));
- if (startx < minx) startx = minx;
- if (endx > maxx) endx = maxx;
- if (startx >= endx) continue;
-
- if (clip0dir)
- {
- if (clip0dir > 0)
- {
- if (startx < clip0)
- {
- if(endx <= clip0) continue;
- startx = (int)clip0;
- }
- }
- else if (endx > clip0)
- {
- if(startx >= clip0) continue;
- endx = (int)clip0;
- }
- }
-
- for (offset = startx; offset < endx;offset += DPSOFTRAST_DRAW_MAXSPANLENGTH)
- {
- DPSOFTRAST_State_Span *span = &thread->spans[thread->numspans];
- span->triangle = thread->numtriangles;
- span->x = offset;
- span->y = y;
- span->startx = 0;
- span->endx = min(endx - offset, DPSOFTRAST_DRAW_MAXSPANLENGTH);
- if (span->startx >= span->endx)
- continue;
- wslope = triangle->w[0];
- w = triangle->w[2] + span->x*wslope + span->y*triangle->w[1];
- span->depthslope = (int)(wslope*DPSOFTRAST_DEPTHSCALE);
- span->depthbase = (int)(w*DPSOFTRAST_DEPTHSCALE - DPSOFTRAST_DEPTHOFFSET*(thread->polygonoffset[1] + fabs(wslope)*thread->polygonoffset[0]));
- if (++thread->numspans >= DPSOFTRAST_DRAW_MAXSPANS)
- DPSOFTRAST_Draw_ProcessSpans(thread);
- }
- }
- }
-
- if (++thread->numtriangles >= DPSOFTRAST_DRAW_MAXTRIANGLES)
- {
- DPSOFTRAST_Draw_ProcessSpans(thread);
- thread->numtriangles = 0;
- }
- }
-
- if (!ATOMIC_DECREMENT(command->refcount))
- {
- if (command->commandsize <= DPSOFTRAST_ALIGNCOMMAND(sizeof(DPSOFTRAST_Command_Draw)))
- MM_FREE(command->arrays);
- }
-
- if (thread->numspans > 0 || thread->numtriangles > 0)
- {
- DPSOFTRAST_Draw_ProcessSpans(thread);
- thread->numtriangles = 0;
- }
-#endif
-}
-
-static DPSOFTRAST_Command_Draw *DPSOFTRAST_Draw_AllocateDrawCommand(int firstvertex, int numvertices, int numtriangles, const int *element3i, const unsigned short *element3s)
-{
- int i;
- int j;
- int commandsize = DPSOFTRAST_ALIGNCOMMAND(sizeof(DPSOFTRAST_Command_Draw));
- int datasize = 2*numvertices*sizeof(float[4]);
- DPSOFTRAST_Command_Draw *command;
- unsigned char *data;
- for (i = 0; i < DPSOFTRAST_ARRAY_TOTAL; i++)
- {
- j = DPSOFTRAST_ShaderModeTable[dpsoftrast.shader_mode].arrays[i];
- if (j >= DPSOFTRAST_ARRAY_TOTAL)
- break;
- datasize += numvertices*sizeof(float[4]);
- }
- if (element3s)
- datasize += numtriangles*sizeof(unsigned short[3]);
- else if (element3i)
- datasize += numtriangles*sizeof(int[3]);
- datasize = DPSOFTRAST_ALIGNCOMMAND(datasize);
- if (commandsize + datasize > DPSOFTRAST_DRAW_MAXCOMMANDSIZE)
- {
- command = (DPSOFTRAST_Command_Draw *) DPSOFTRAST_AllocateCommand(DPSOFTRAST_OPCODE_Draw, commandsize);
- data = (unsigned char *)MM_CALLOC(datasize, 1);
- }
- else
- {
- command = (DPSOFTRAST_Command_Draw *) DPSOFTRAST_AllocateCommand(DPSOFTRAST_OPCODE_Draw, commandsize + datasize);
- data = (unsigned char *)command + commandsize;
- }
- command->firstvertex = firstvertex;
- command->numvertices = numvertices;
- command->numtriangles = numtriangles;
- command->arrays = (float *)data;
- memset(dpsoftrast.post_array4f, 0, sizeof(dpsoftrast.post_array4f));
- dpsoftrast.firstvertex = firstvertex;
- dpsoftrast.numvertices = numvertices;
- dpsoftrast.screencoord4f = (float *)data;
- data += numvertices*sizeof(float[4]);
- dpsoftrast.post_array4f[DPSOFTRAST_ARRAY_POSITION] = (float *)data;
- data += numvertices*sizeof(float[4]);
- for (i = 0; i < DPSOFTRAST_ARRAY_TOTAL; i++)
- {
- j = DPSOFTRAST_ShaderModeTable[dpsoftrast.shader_mode].arrays[i];
- if (j >= DPSOFTRAST_ARRAY_TOTAL)
- break;
- dpsoftrast.post_array4f[j] = (float *)data;
- data += numvertices*sizeof(float[4]);
- }
- command->element3i = NULL;
- command->element3s = NULL;
- if (element3s)
- {
- command->element3s = (unsigned short *)data;
- memcpy(command->element3s, element3s, numtriangles*sizeof(unsigned short[3]));
- }
- else if (element3i)
- {
- command->element3i = (int *)data;
- memcpy(command->element3i, element3i, numtriangles*sizeof(int[3]));
- }
- return command;
-}
-
-void DPSOFTRAST_DrawTriangles(int firstvertex, int numvertices, int numtriangles, const int *element3i, const unsigned short *element3s)
-{
- DPSOFTRAST_Command_Draw *command = DPSOFTRAST_Draw_AllocateDrawCommand(firstvertex, numvertices, numtriangles, element3i, element3s);
- DPSOFTRAST_ShaderModeTable[dpsoftrast.shader_mode].Vertex();
- command->starty = bound(0, dpsoftrast.drawstarty, dpsoftrast.fb_height);
- command->endy = bound(0, dpsoftrast.drawendy, dpsoftrast.fb_height);
- if (command->starty >= command->endy)
- {
- if (command->commandsize <= DPSOFTRAST_ALIGNCOMMAND(sizeof(DPSOFTRAST_Command_Draw)))
- MM_FREE(command->arrays);
- DPSOFTRAST_UndoCommand(command->commandsize);
- return;
- }
- command->clipped = dpsoftrast.drawclipped;
- command->refcount = dpsoftrast.numthreads;
-
- if (dpsoftrast.usethreads)
- {
- int i;
- DPSOFTRAST_Draw_SyncCommands();
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- DPSOFTRAST_State_Thread *thread = &dpsoftrast.threads[i];
- if (((command->starty < thread->maxy1 && command->endy > thread->miny1) || (command->starty < thread->maxy2 && command->endy > thread->miny2)) && thread->starving)
- Thread_CondSignal(thread->drawcond);
- }
- }
- else
- {
- DPSOFTRAST_Draw_FlushThreads();
- }
-}
-
-DEFCOMMAND(23, SetRenderTargets, int width; int height;)
-static void DPSOFTRAST_Interpret_SetRenderTargets(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_Command_SetRenderTargets *command)
-{
- thread->validate |= DPSOFTRAST_VALIDATE_FB;
-}
-void DPSOFTRAST_SetRenderTargets(int width, int height, unsigned int *depthpixels, unsigned int *colorpixels0, unsigned int *colorpixels1, unsigned int *colorpixels2, unsigned int *colorpixels3)
-{
- DPSOFTRAST_Command_SetRenderTargets *command;
- if (width != dpsoftrast.fb_width || height != dpsoftrast.fb_height || depthpixels != dpsoftrast.fb_depthpixels ||
- colorpixels0 != dpsoftrast.fb_colorpixels[0] || colorpixels1 != dpsoftrast.fb_colorpixels[1] ||
- colorpixels2 != dpsoftrast.fb_colorpixels[2] || colorpixels3 != dpsoftrast.fb_colorpixels[3])
- DPSOFTRAST_Flush();
- dpsoftrast.fb_width = width;
- dpsoftrast.fb_height = height;
- dpsoftrast.fb_depthpixels = depthpixels;
- dpsoftrast.fb_colorpixels[0] = colorpixels0;
- dpsoftrast.fb_colorpixels[1] = colorpixels1;
- dpsoftrast.fb_colorpixels[2] = colorpixels2;
- dpsoftrast.fb_colorpixels[3] = colorpixels3;
- DPSOFTRAST_RecalcViewport(dpsoftrast.viewport, dpsoftrast.fb_viewportcenter, dpsoftrast.fb_viewportscale);
- command = DPSOFTRAST_ALLOCATECOMMAND(SetRenderTargets);
- command->width = width;
- command->height = height;
-}
-
-static void DPSOFTRAST_Draw_InterpretCommands(DPSOFTRAST_State_Thread *thread, int endoffset)
-{
- int commandoffset = thread->commandoffset;
- while (commandoffset != endoffset)
- {
- DPSOFTRAST_Command *command = (DPSOFTRAST_Command *)&dpsoftrast.commandpool.commands[commandoffset];
- switch (command->opcode)
- {
-#define INTERPCOMMAND(name) \
- case DPSOFTRAST_OPCODE_##name : \
- DPSOFTRAST_Interpret_##name (thread, (DPSOFTRAST_Command_##name *)command); \
- commandoffset += DPSOFTRAST_ALIGNCOMMAND(sizeof( DPSOFTRAST_Command_##name )); \
- if (commandoffset >= DPSOFTRAST_DRAW_MAXCOMMANDPOOL) \
- commandoffset = 0; \
- break;
- INTERPCOMMAND(Viewport)
- INTERPCOMMAND(ClearColor)
- INTERPCOMMAND(ClearDepth)
- INTERPCOMMAND(ColorMask)
- INTERPCOMMAND(DepthTest)
- INTERPCOMMAND(ScissorTest)
- INTERPCOMMAND(Scissor)
- INTERPCOMMAND(BlendFunc)
- INTERPCOMMAND(BlendSubtract)
- INTERPCOMMAND(DepthMask)
- INTERPCOMMAND(DepthFunc)
- INTERPCOMMAND(DepthRange)
- INTERPCOMMAND(PolygonOffset)
- INTERPCOMMAND(CullFace)
- INTERPCOMMAND(SetTexture)
- INTERPCOMMAND(SetShader)
- INTERPCOMMAND(Uniform4f)
- INTERPCOMMAND(UniformMatrix4f)
- INTERPCOMMAND(Uniform1i)
- INTERPCOMMAND(SetRenderTargets)
- INTERPCOMMAND(ClipPlane)
-
- case DPSOFTRAST_OPCODE_Draw:
- DPSOFTRAST_Interpret_Draw(thread, (DPSOFTRAST_Command_Draw *)command);
- commandoffset += command->commandsize;
- if (commandoffset >= DPSOFTRAST_DRAW_MAXCOMMANDPOOL)
- commandoffset = 0;
- thread->commandoffset = commandoffset;
- break;
-
- case DPSOFTRAST_OPCODE_Reset:
- commandoffset = 0;
- break;
- }
- }
- thread->commandoffset = commandoffset;
-}
-
-static int DPSOFTRAST_Draw_Thread(void *data)
-{
- DPSOFTRAST_State_Thread *thread = (DPSOFTRAST_State_Thread *)data;
- while(thread->index >= 0)
- {
- if (thread->commandoffset != dpsoftrast.drawcommand)
- {
- DPSOFTRAST_Draw_InterpretCommands(thread, dpsoftrast.drawcommand);
- }
- else
- {
- Thread_LockMutex(thread->drawmutex);
- if (thread->commandoffset == dpsoftrast.drawcommand && thread->index >= 0)
- {
- if (thread->waiting) Thread_CondSignal(thread->waitcond);
- thread->starving = true;
- Thread_CondWait(thread->drawcond, thread->drawmutex);
- thread->starving = false;
- }
- Thread_UnlockMutex(thread->drawmutex);
- }
- }
- return 0;
-}
-
-static void DPSOFTRAST_Draw_FlushThreads(void)
-{
- DPSOFTRAST_State_Thread *thread;
- int i;
- DPSOFTRAST_Draw_SyncCommands();
- if (dpsoftrast.usethreads)
- {
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- thread = &dpsoftrast.threads[i];
- if (thread->commandoffset != dpsoftrast.drawcommand)
- {
- Thread_LockMutex(thread->drawmutex);
- if (thread->commandoffset != dpsoftrast.drawcommand && thread->starving)
- Thread_CondSignal(thread->drawcond);
- Thread_UnlockMutex(thread->drawmutex);
- }
- }
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- thread = &dpsoftrast.threads[i];
- if (thread->commandoffset != dpsoftrast.drawcommand)
- {
- Thread_LockMutex(thread->drawmutex);
- if (thread->commandoffset != dpsoftrast.drawcommand)
- {
- thread->waiting = true;
- Thread_CondWait(thread->waitcond, thread->drawmutex);
- thread->waiting = false;
- }
- Thread_UnlockMutex(thread->drawmutex);
- }
- }
- }
- else
- {
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- thread = &dpsoftrast.threads[i];
- if (thread->commandoffset != dpsoftrast.drawcommand)
- DPSOFTRAST_Draw_InterpretCommands(thread, dpsoftrast.drawcommand);
- }
- }
- dpsoftrast.commandpool.usedcommands = 0;
-}
-
-void DPSOFTRAST_Flush(void)
-{
- DPSOFTRAST_Draw_FlushThreads();
-}
-
-void DPSOFTRAST_Finish(void)
-{
- DPSOFTRAST_Flush();
-}
-
-int DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels)
-{
- int i;
- union
- {
- int i;
- unsigned char b[4];
- }
- u;
- u.i = 1;
- memset(&dpsoftrast, 0, sizeof(dpsoftrast));
- dpsoftrast.bigendian = u.b[3];
- dpsoftrast.fb_width = width;
- dpsoftrast.fb_height = height;
- dpsoftrast.fb_depthpixels = depthpixels;
- dpsoftrast.fb_colorpixels[0] = colorpixels;
- dpsoftrast.fb_colorpixels[1] = NULL;
- dpsoftrast.fb_colorpixels[1] = NULL;
- dpsoftrast.fb_colorpixels[1] = NULL;
- dpsoftrast.viewport[0] = 0;
- dpsoftrast.viewport[1] = 0;
- dpsoftrast.viewport[2] = dpsoftrast.fb_width;
- dpsoftrast.viewport[3] = dpsoftrast.fb_height;
- DPSOFTRAST_RecalcViewport(dpsoftrast.viewport, dpsoftrast.fb_viewportcenter, dpsoftrast.fb_viewportscale);
- dpsoftrast.texture_firstfree = 1;
- dpsoftrast.texture_end = 1;
- dpsoftrast.texture_max = 0;
- dpsoftrast.color[0] = 1;
- dpsoftrast.color[1] = 1;
- dpsoftrast.color[2] = 1;
- dpsoftrast.color[3] = 1;
- dpsoftrast.usethreads = numthreads > 0 && Thread_HasThreads();
- dpsoftrast.interlace = dpsoftrast.usethreads ? bound(0, interlace, 1) : 0;
- dpsoftrast.numthreads = dpsoftrast.usethreads ? bound(1, numthreads, 64) : 1;
- dpsoftrast.threads = (DPSOFTRAST_State_Thread *)MM_CALLOC(dpsoftrast.numthreads, sizeof(DPSOFTRAST_State_Thread));
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- DPSOFTRAST_State_Thread *thread = &dpsoftrast.threads[i];
- thread->index = i;
- thread->cullface = GL_BACK;
- thread->colormask[0] = 1;
- thread->colormask[1] = 1;
- thread->colormask[2] = 1;
- thread->colormask[3] = 1;
- thread->blendfunc[0] = GL_ONE;
- thread->blendfunc[1] = GL_ZERO;
- thread->depthmask = true;
- thread->depthtest = true;
- thread->depthfunc = GL_LEQUAL;
- thread->scissortest = false;
- thread->viewport[0] = 0;
- thread->viewport[1] = 0;
- thread->viewport[2] = dpsoftrast.fb_width;
- thread->viewport[3] = dpsoftrast.fb_height;
- thread->scissor[0] = 0;
- thread->scissor[1] = 0;
- thread->scissor[2] = dpsoftrast.fb_width;
- thread->scissor[3] = dpsoftrast.fb_height;
- thread->depthrange[0] = 0;
- thread->depthrange[1] = 1;
- thread->polygonoffset[0] = 0;
- thread->polygonoffset[1] = 0;
- thread->clipplane[0] = 0;
- thread->clipplane[1] = 0;
- thread->clipplane[2] = 0;
- thread->clipplane[3] = 1;
-
- thread->numspans = 0;
- thread->numtriangles = 0;
- thread->commandoffset = 0;
- thread->waiting = false;
- thread->starving = false;
-
- thread->validate = -1;
- DPSOFTRAST_Validate(thread, -1);
-
- if (dpsoftrast.usethreads)
- {
- thread->waitcond = Thread_CreateCond();
- thread->drawcond = Thread_CreateCond();
- thread->drawmutex = Thread_CreateMutex();
- thread->thread = Thread_CreateThread(DPSOFTRAST_Draw_Thread, thread);
- }
- }
- return 0;
-}
-
-void DPSOFTRAST_Shutdown(void)
-{
- int i;
- if (dpsoftrast.usethreads && dpsoftrast.numthreads > 0)
- {
- DPSOFTRAST_State_Thread *thread;
- for (i = 0; i < dpsoftrast.numthreads; i++)
- {
- thread = &dpsoftrast.threads[i];
- Thread_LockMutex(thread->drawmutex);
- thread->index = -1;
- Thread_CondSignal(thread->drawcond);
- Thread_UnlockMutex(thread->drawmutex);
- Thread_WaitThread(thread->thread, 0);
- Thread_DestroyCond(thread->waitcond);
- Thread_DestroyCond(thread->drawcond);
- Thread_DestroyMutex(thread->drawmutex);
- }
- }
- for (i = 0;i < dpsoftrast.texture_end;i++)
- if (dpsoftrast.texture[i].bytes)
- MM_FREE(dpsoftrast.texture[i].bytes);
- if (dpsoftrast.texture)
- free(dpsoftrast.texture);
- if (dpsoftrast.threads)
- MM_FREE(dpsoftrast.threads);
- memset(&dpsoftrast, 0, sizeof(dpsoftrast));
-}
-
-
-#ifndef DPSOFTRAST_H
-#define DPSOFTRAST_H
-
-#include <stdlib.h>
-
-#define DPSOFTRAST_MAXMIPMAPS 16
-#define DPSOFTRAST_TEXTURE_MAXSIZE (1<<(DPSOFTRAST_MAXMIPMAPS - 1))
-#define DPSOFTRAST_MAXTEXTUREUNITS 16
-#define DPSOFTRAST_MAXTEXCOORDARRAYS 8
-
-// type of pixels in texture (some of these are converted to BGRA8 on update)
-#define DPSOFTRAST_TEXTURE_FORMAT_BGRA8 0
-#define DPSOFTRAST_TEXTURE_FORMAT_DEPTH 1
-#define DPSOFTRAST_TEXTURE_FORMAT_RGBA8 2
-#define DPSOFTRAST_TEXTURE_FORMAT_ALPHA8 3
-#define DPSOFTRAST_TEXTURE_FORMAT_RGBA16F 4
-#define DPSOFTRAST_TEXTURE_FORMAT_RGBA32F 5
-#define DPSOFTRAST_TEXTURE_FORMAT_COMPAREMASK 0x0F
-
-// modifier flags for texture (can not be changed after creation)
-#define DPSOFTRAST_TEXTURE_FLAG_MIPMAP 0x10
-#define DPSOFTRAST_TEXTURE_FLAG_CUBEMAP 0x20
-#define DPSOFTRAST_TEXTURE_FLAG_USEALPHA 0x40
-#define DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE 0x80
-
-typedef enum DPSOFTRAST_TEXTURE_FILTER_e
-{
- DPSOFTRAST_TEXTURE_FILTER_NEAREST = 0,
- DPSOFTRAST_TEXTURE_FILTER_LINEAR = 1,
- DPSOFTRAST_TEXTURE_FILTER_NEAREST_MIPMAP_TRIANGLE = 2,
- DPSOFTRAST_TEXTURE_FILTER_LINEAR_MIPMAP_TRIANGLE = 3,
-}
-DPSOFTRAST_TEXTURE_FILTER;
-
-int DPSOFTRAST_Init(int width, int height, int numthreads, int interlace, unsigned int *colorpixels, unsigned int *depthpixels);
-void DPSOFTRAST_Shutdown(void);
-void DPSOFTRAST_Flush(void);
-void DPSOFTRAST_Finish(void);
-
-int DPSOFTRAST_Texture_New(int flags, int width, int height, int depth);
-void DPSOFTRAST_Texture_Free(int index);
-void DPSOFTRAST_Texture_UpdatePartial(int index, int mip, const unsigned char *pixels, int blockx, int blocky, int blockwidth, int blockheight);
-void DPSOFTRAST_Texture_UpdateFull(int index, const unsigned char *pixels);
-int DPSOFTRAST_Texture_GetWidth(int index, int mip);
-int DPSOFTRAST_Texture_GetHeight(int index, int mip);
-int DPSOFTRAST_Texture_GetDepth(int index, int mip);
-unsigned char *DPSOFTRAST_Texture_GetPixelPointer(int index, int mip);
-void DPSOFTRAST_Texture_Filter(int index, DPSOFTRAST_TEXTURE_FILTER filter);
-
-void DPSOFTRAST_SetRenderTargets(int width, int height, unsigned int *depthpixels, unsigned int *colorpixels0, unsigned int *colorpixels1, unsigned int *colorpixels2, unsigned int *colorpixels3);
-void DPSOFTRAST_Viewport(int x, int y, int width, int height);
-void DPSOFTRAST_ClearColor(float r, float g, float b, float a);
-void DPSOFTRAST_ClearDepth(float d);
-void DPSOFTRAST_ColorMask(int r, int g, int b, int a);
-void DPSOFTRAST_DepthTest(int enable);
-void DPSOFTRAST_ScissorTest(int enable);
-void DPSOFTRAST_Scissor(float x, float y, float width, float height);
-void DPSOFTRAST_ClipPlane(float x, float y, float z, float w);
-
-void DPSOFTRAST_BlendFunc(int smodulate, int dmodulate);
-void DPSOFTRAST_BlendSubtract(int enable);
-void DPSOFTRAST_DepthMask(int enable);
-void DPSOFTRAST_DepthFunc(int comparemode);
-void DPSOFTRAST_DepthRange(float range0, float range1);
-void DPSOFTRAST_PolygonOffset(float alongnormal, float intoview);
-void DPSOFTRAST_CullFace(int mode);
-void DPSOFTRAST_Color4f(float r, float g, float b, float a);
-void DPSOFTRAST_GetPixelsBGRA(int blockx, int blocky, int blockwidth, int blockheight, unsigned char *outpixels);
-void DPSOFTRAST_CopyRectangleToTexture(int index, int mip, int tx, int ty, int sx, int sy, int width, int height);
-void DPSOFTRAST_SetTexture(int unitnum, int index);
-
-void DPSOFTRAST_SetVertexPointer(const float *vertex3f, size_t stride);
-void DPSOFTRAST_SetColorPointer(const float *color4f, size_t stride);
-void DPSOFTRAST_SetColorPointer4ub(const unsigned char *color4ub, size_t stride);
-void DPSOFTRAST_SetTexCoordPointer(int unitnum, int numcomponents, size_t stride, const float *texcoordf);
-
-typedef enum gl20_texunit_e
-{
- // postprocess shaders, and generic shaders:
- GL20TU_FIRST = 0,
- GL20TU_SECOND = 1,
- GL20TU_GAMMARAMPS = 2,
- // standard material properties
- GL20TU_NORMAL = 0,
- GL20TU_COLOR = 1,
- GL20TU_GLOSS = 2,
- GL20TU_GLOW = 3,
- // material properties for a second material
- GL20TU_SECONDARY_NORMAL = 4,
- GL20TU_SECONDARY_COLOR = 5,
- GL20TU_SECONDARY_GLOSS = 6,
- GL20TU_SECONDARY_GLOW = 7,
- // material properties for a colormapped material
- // conflicts with secondary material
- GL20TU_PANTS = 4,
- GL20TU_SHIRT = 7,
- // fog fade in the distance
- GL20TU_FOGMASK = 8,
- // compiled ambient lightmap and deluxemap
- GL20TU_LIGHTMAP = 9,
- GL20TU_DELUXEMAP = 10,
- // refraction, used by water shaders
- GL20TU_REFRACTION = 3,
- // reflection, used by water shaders, also with normal material rendering
- // conflicts with secondary material
- GL20TU_REFLECTION = 7,
- // rtlight attenuation (distance fade) and cubemap filter (projection texturing)
- // conflicts with lightmap/deluxemap
- GL20TU_ATTENUATION = 9,
- GL20TU_CUBE = 10,
- GL20TU_SHADOWMAP2D = 15,
- GL20TU_CUBEPROJECTION = 12,
- // rtlight prepass data (screenspace depth and normalmap)
-// GL20TU_UNUSED1 = 13,
- GL20TU_SCREENNORMALMAP = 14,
- // lightmap prepass data (screenspace diffuse and specular from lights)
- GL20TU_SCREENDIFFUSE = 11,
- GL20TU_SCREENSPECULAR = 12,
- // fake reflections
- GL20TU_REFLECTMASK = 5,
- GL20TU_REFLECTCUBE = 6,
- GL20TU_FOGHEIGHTTEXTURE = 14
-}
-gl20_texunit;
-
-typedef enum glsl_attrib_e
-{
- GLSLATTRIB_POSITION = 0,
- GLSLATTRIB_COLOR = 1,
- GLSLATTRIB_TEXCOORD0 = 2,
- GLSLATTRIB_TEXCOORD1 = 3,
- GLSLATTRIB_TEXCOORD2 = 4,
- GLSLATTRIB_TEXCOORD3 = 5,
- GLSLATTRIB_TEXCOORD4 = 6,
- GLSLATTRIB_TEXCOORD5 = 7,
- GLSLATTRIB_TEXCOORD6 = 8,
- GLSLATTRIB_TEXCOORD7 = 9,
-}
-glsl_attrib;
-
-typedef enum shaderlanguage_e
-{
- SHADERLANGUAGE_GLSL,
- SHADERLANGUAGE_HLSL,
- SHADERLANGUAGE_COUNT
-}
-shaderlanguage_t;
-
-// this enum selects which of the glslshadermodeinfo entries should be used
-typedef enum shadermode_e
-{
- SHADERMODE_GENERIC, ///< (particles/HUD/etc) vertex color, optionally multiplied by one texture
- SHADERMODE_POSTPROCESS, ///< postprocessing shader (r_glsl_postprocess)
- SHADERMODE_DEPTH_OR_SHADOW, ///< (depthfirst/shadows) vertex shader only
- SHADERMODE_FLATCOLOR, ///< (lightmap) modulate texture by uniform color (q1bsp, q3bsp)
- SHADERMODE_VERTEXCOLOR, ///< (lightmap) modulate texture by vertex colors (q3bsp)
- SHADERMODE_LIGHTMAP, ///< (lightmap) modulate texture by lightmap texture (q1bsp, q3bsp)
- SHADERMODE_FAKELIGHT, ///< (fakelight) modulate texture by "fake" lighting (no lightmaps, no nothing)
- SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE, ///< (lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp deluxemap)
- SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE, ///< (lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp deluxemap)
- SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP, // forced deluxemapping for lightmapped surfaces
- SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR, // forced deluxemapping for vertexlit surfaces
- SHADERMODE_LIGHTDIRECTION, ///< (lightmap) use directional pixel shading from fixed light direction (q3bsp)
- SHADERMODE_LIGHTSOURCE, ///< (lightsource) use directional pixel shading from light source (rtlight)
- SHADERMODE_REFRACTION, ///< refract background (the material is rendered normally after this pass)
- SHADERMODE_WATER, ///< refract background and reflection (the material is rendered normally after this pass)
- SHADERMODE_DEFERREDGEOMETRY, ///< (deferred) render material properties to screenspace geometry buffers
- SHADERMODE_DEFERREDLIGHTSOURCE, ///< (deferred) use directional pixel shading from light source (rtlight) on screenspace geometry buffers
- SHADERMODE_COUNT
-}
-shadermode_t;
-
-typedef enum shaderpermutation_e
-{
- SHADERPERMUTATION_DIFFUSE = 1<<0, ///< (lightsource) whether to use directional shading
- SHADERPERMUTATION_VERTEXTEXTUREBLEND = 1<<1, ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
- SHADERPERMUTATION_VIEWTINT = 1<<2, ///< view tint (postprocessing only), use vertex colors (generic only)
- SHADERPERMUTATION_COLORMAPPING = 1<<3, ///< indicates this is a colormapped skin
- SHADERPERMUTATION_SATURATION = 1<<4, ///< saturation (postprocessing only)
- SHADERPERMUTATION_FOGINSIDE = 1<<5, ///< tint the color by fog color or black if using additive blend mode
- SHADERPERMUTATION_FOGOUTSIDE = 1<<6, ///< tint the color by fog color or black if using additive blend mode
- SHADERPERMUTATION_FOGHEIGHTTEXTURE = 1<<7, ///< fog color and density determined by texture mapped on vertical axis
- SHADERPERMUTATION_FOGALPHAHACK = 1<<8, ///< fog color and density determined by texture mapped on vertical axis
- SHADERPERMUTATION_GAMMARAMPS = 1<<9, ///< gamma (postprocessing only)
- SHADERPERMUTATION_CUBEFILTER = 1<<10, ///< (lightsource) use cubemap light filter
- SHADERPERMUTATION_GLOW = 1<<11, ///< (lightmap) blend in an additive glow texture
- SHADERPERMUTATION_BLOOM = 1<<12, ///< bloom (postprocessing only)
- SHADERPERMUTATION_SPECULAR = 1<<13, ///< (lightsource or deluxemapping) render specular effects
- SHADERPERMUTATION_POSTPROCESSING = 1<<14, ///< user defined postprocessing (postprocessing only)
- SHADERPERMUTATION_REFLECTION = 1<<15, ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
- SHADERPERMUTATION_OFFSETMAPPING = 1<<16, ///< adjust texcoords to roughly simulate a displacement mapped surface
- SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING = 1<<17, ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
- SHADERPERMUTATION_SHADOWMAP2D = 1<<18, ///< (lightsource) use shadowmap texture as light filter
- SHADERPERMUTATION_SHADOWMAPVSDCT = 1<<19, ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
- SHADERPERMUTATION_SHADOWMAPORTHO = 1<<20, ///< (lightsource) use orthographic shadowmap projection
- SHADERPERMUTATION_DEFERREDLIGHTMAP = 1<<21, ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
- SHADERPERMUTATION_ALPHAKILL = 1<<22, ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
- SHADERPERMUTATION_REFLECTCUBE = 1<<23, ///< fake reflections using global cubemap (not HDRI light probe)
- SHADERPERMUTATION_NORMALMAPSCROLLBLEND = 1<<24, ///< (water) counter-direction normalmaps scrolling
- SHADERPERMUTATION_BOUNCEGRID = 1<<25, ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
- SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL = 1<<26, ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
- SHADERPERMUTATION_TRIPPY = 1<<27, ///< use trippy vertex shader effect
- SHADERPERMUTATION_DEPTHRGB = 1<<28, ///< read/write depth values in RGB color coded format for older hardware without depth samplers
- SHADERPERMUTATION_ALPHAGEN_VERTEX = 1<<29, ///< alphaGen vertex
- SHADERPERMUTATION_SKELETAL = 1<<30, ///< (skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
- SHADERPERMUTATION_OCCLUDE = 1<<31, ///< use occlusion buffer for corona
- SHADERPERMUTATION_COUNT = 32 ///< size of shaderpermutationinfo array
-}
-shaderpermutation_t;
-
-typedef enum DPSOFTRAST_UNIFORM_e
-{
- DPSOFTRAST_UNIFORM_Texture_First,
- DPSOFTRAST_UNIFORM_Texture_Second,
- DPSOFTRAST_UNIFORM_Texture_GammaRamps,
- DPSOFTRAST_UNIFORM_Texture_Normal,
- DPSOFTRAST_UNIFORM_Texture_Color,
- DPSOFTRAST_UNIFORM_Texture_Gloss,
- DPSOFTRAST_UNIFORM_Texture_Glow,
- DPSOFTRAST_UNIFORM_Texture_SecondaryNormal,
- DPSOFTRAST_UNIFORM_Texture_SecondaryColor,
- DPSOFTRAST_UNIFORM_Texture_SecondaryGloss,
- DPSOFTRAST_UNIFORM_Texture_SecondaryGlow,
- DPSOFTRAST_UNIFORM_Texture_Pants,
- DPSOFTRAST_UNIFORM_Texture_Shirt,
- DPSOFTRAST_UNIFORM_Texture_FogHeightTexture,
- DPSOFTRAST_UNIFORM_Texture_FogMask,
- DPSOFTRAST_UNIFORM_Texture_Lightmap,
- DPSOFTRAST_UNIFORM_Texture_Deluxemap,
- DPSOFTRAST_UNIFORM_Texture_Attenuation,
- DPSOFTRAST_UNIFORM_Texture_Cube,
- DPSOFTRAST_UNIFORM_Texture_Refraction,
- DPSOFTRAST_UNIFORM_Texture_Reflection,
- DPSOFTRAST_UNIFORM_Texture_ShadowMap2D,
- DPSOFTRAST_UNIFORM_Texture_CubeProjection,
- DPSOFTRAST_UNIFORM_Texture_ScreenNormalMap,
- DPSOFTRAST_UNIFORM_Texture_ScreenDiffuse,
- DPSOFTRAST_UNIFORM_Texture_ScreenSpecular,
- DPSOFTRAST_UNIFORM_Texture_ReflectMask,
- DPSOFTRAST_UNIFORM_Texture_ReflectCube,
- DPSOFTRAST_UNIFORM_Alpha,
- DPSOFTRAST_UNIFORM_BloomBlur_Parameters,
- DPSOFTRAST_UNIFORM_ClientTime,
- DPSOFTRAST_UNIFORM_Color_Ambient,
- DPSOFTRAST_UNIFORM_Color_Diffuse,
- DPSOFTRAST_UNIFORM_Color_Specular,
- DPSOFTRAST_UNIFORM_Color_Glow,
- DPSOFTRAST_UNIFORM_Color_Pants,
- DPSOFTRAST_UNIFORM_Color_Shirt,
- DPSOFTRAST_UNIFORM_DeferredColor_Ambient,
- DPSOFTRAST_UNIFORM_DeferredColor_Diffuse,
- DPSOFTRAST_UNIFORM_DeferredColor_Specular,
- DPSOFTRAST_UNIFORM_DeferredMod_Diffuse,
- DPSOFTRAST_UNIFORM_DeferredMod_Specular,
- DPSOFTRAST_UNIFORM_DistortScaleRefractReflect,
- DPSOFTRAST_UNIFORM_EyePosition,
- DPSOFTRAST_UNIFORM_FogColor,
- DPSOFTRAST_UNIFORM_FogHeightFade,
- DPSOFTRAST_UNIFORM_FogPlane,
- DPSOFTRAST_UNIFORM_FogPlaneViewDist,
- DPSOFTRAST_UNIFORM_FogRangeRecip,
- DPSOFTRAST_UNIFORM_LightColor,
- DPSOFTRAST_UNIFORM_LightDir,
- DPSOFTRAST_UNIFORM_LightPosition,
- DPSOFTRAST_UNIFORM_OffsetMapping_ScaleSteps,
- DPSOFTRAST_UNIFORM_PixelSize,
- DPSOFTRAST_UNIFORM_ReflectColor,
- DPSOFTRAST_UNIFORM_ReflectFactor,
- DPSOFTRAST_UNIFORM_ReflectOffset,
- DPSOFTRAST_UNIFORM_RefractColor,
- DPSOFTRAST_UNIFORM_Saturation,
- DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect,
- DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect,
- DPSOFTRAST_UNIFORM_ScreenToDepth,
- DPSOFTRAST_UNIFORM_ShadowMap_Parameters,
- DPSOFTRAST_UNIFORM_ShadowMap_TextureScale,
- DPSOFTRAST_UNIFORM_SpecularPower,
- DPSOFTRAST_UNIFORM_UserVec1,
- DPSOFTRAST_UNIFORM_UserVec2,
- DPSOFTRAST_UNIFORM_UserVec3,
- DPSOFTRAST_UNIFORM_UserVec4,
- DPSOFTRAST_UNIFORM_ViewTintColor,
- DPSOFTRAST_UNIFORM_ViewToLightM1,
- DPSOFTRAST_UNIFORM_ViewToLightM2,
- DPSOFTRAST_UNIFORM_ViewToLightM3,
- DPSOFTRAST_UNIFORM_ViewToLightM4,
- DPSOFTRAST_UNIFORM_ModelToLightM1,
- DPSOFTRAST_UNIFORM_ModelToLightM2,
- DPSOFTRAST_UNIFORM_ModelToLightM3,
- DPSOFTRAST_UNIFORM_ModelToLightM4,
- DPSOFTRAST_UNIFORM_TexMatrixM1,
- DPSOFTRAST_UNIFORM_TexMatrixM2,
- DPSOFTRAST_UNIFORM_TexMatrixM3,
- DPSOFTRAST_UNIFORM_TexMatrixM4,
- DPSOFTRAST_UNIFORM_BackgroundTexMatrixM1,
- DPSOFTRAST_UNIFORM_BackgroundTexMatrixM2,
- DPSOFTRAST_UNIFORM_BackgroundTexMatrixM3,
- DPSOFTRAST_UNIFORM_BackgroundTexMatrixM4,
- DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1,
- DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM2,
- DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM3,
- DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM4,
- DPSOFTRAST_UNIFORM_ModelViewMatrixM1,
- DPSOFTRAST_UNIFORM_ModelViewMatrixM2,
- DPSOFTRAST_UNIFORM_ModelViewMatrixM3,
- DPSOFTRAST_UNIFORM_ModelViewMatrixM4,
- DPSOFTRAST_UNIFORM_PixelToScreenTexCoord,
- DPSOFTRAST_UNIFORM_ModelToReflectCubeM1,
- DPSOFTRAST_UNIFORM_ModelToReflectCubeM2,
- DPSOFTRAST_UNIFORM_ModelToReflectCubeM3,
- DPSOFTRAST_UNIFORM_ModelToReflectCubeM4,
- DPSOFTRAST_UNIFORM_ShadowMapMatrixM1,
- DPSOFTRAST_UNIFORM_ShadowMapMatrixM2,
- DPSOFTRAST_UNIFORM_ShadowMapMatrixM3,
- DPSOFTRAST_UNIFORM_ShadowMapMatrixM4,
- DPSOFTRAST_UNIFORM_BloomColorSubtract,
- DPSOFTRAST_UNIFORM_NormalmapScrollBlend,
- DPSOFTRAST_UNIFORM_OffsetMapping_LodDistance,
- DPSOFTRAST_UNIFORM_OffsetMapping_Bias,
- DPSOFTRAST_UNIFORM_TOTAL
-}
-DPSOFTRAST_UNIFORM;
-
-void DPSOFTRAST_SetShader(int mode, dpuint64 permutation, int exactspecularmath);
-#define DPSOFTRAST_Uniform1f(index, v0) DPSOFTRAST_Uniform4f(index, v0, 0, 0, 0)
-#define DPSOFTRAST_Uniform2f(index, v0, v1) DPSOFTRAST_Uniform4f(index, v0, v1, 0, 0)
-#define DPSOFTRAST_Uniform3f(index, v0, v1, v2) DPSOFTRAST_Uniform4f(index, v0, v1, v2, 0)
-void DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM index, float v0, float v1, float v2, float v3);
-void DPSOFTRAST_Uniform4fv(DPSOFTRAST_UNIFORM index, const float *v);
-void DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM index, int arraysize, int transpose, const float *v);
-void DPSOFTRAST_Uniform1i(DPSOFTRAST_UNIFORM index, int i0);
-
-void DPSOFTRAST_DrawTriangles(int firstvertex, int numvertices, int numtriangles, const int *element3i, const unsigned short *element3s);
-
-#endif // DPSOFTRAST_H
#include "quakedef.h"
#include "cl_collision.h"
-#include "dpsoftrast.h"
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-extern LPDIRECT3DDEVICE9 vid_d3d9dev;
-extern D3DCAPS9 vid_d3d9caps;
-#endif
// on GLES we have to use some proper #define's
#ifndef GL_FRAMEBUFFER
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#endif
-//#ifndef GL_VERTEX_ARRAY
-//#define GL_VERTEX_ARRAY 0x8074
-//#define GL_COLOR_ARRAY 0x8076
-//#define GL_TEXTURE_COORD_ARRAY 0x8078
-//#endif
#ifndef GL_TEXTURE0
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#ifndef GL_TEXTURE_CUBE_MAP
#define GL_TEXTURE_CUBE_MAP 0x8513
#endif
-//#ifndef GL_MODELVIEW
-//#define GL_MODELVIEW 0x1700
-//#endif
-//#ifndef GL_PROJECTION
-//#define GL_PROJECTION 0x1701
-//#endif
-//#ifndef GL_DECAL
-//#define GL_DECAL 0x2101
-//#endif
-//#ifndef GL_INTERPOLATE
-//#define GL_INTERPOLATE 0x8575
-//#endif
#define MAX_RENDERTARGETS 4
cvar_t gl_mesh_drawrangeelements = {0, "gl_mesh_drawrangeelements", "1", "use glDrawRangeElements function if available instead of glDrawElements (for performance comparisons or bug testing)"};
-cvar_t gl_mesh_testmanualfeeding = {0, "gl_mesh_testmanualfeeding", "0", "use glBegin(GL_TRIANGLES);glTexCoord2f();glVertex3f();glEnd(); primitives instead of glDrawElements (useful to test for driver bugs with glDrawElements)"};
cvar_t gl_paranoid = {0, "gl_paranoid", "0", "enables OpenGL error checking and other tests"};
cvar_t gl_printcheckerror = {0, "gl_printcheckerror", "0", "prints all OpenGL error checks, useful to identify location of driver crashes"};
memexpandablearray_t meshbufferarray;
qboolean active;
-
-#ifdef SUPPORTD3D
-// rtexture_t *d3drt_depthtexture;
-// rtexture_t *d3drt_colortextures[MAX_RENDERTARGETS];
- IDirect3DSurface9 *d3drt_depthsurface;
- IDirect3DSurface9 *d3drt_colorsurfaces[MAX_RENDERTARGETS];
- IDirect3DSurface9 *d3drt_backbufferdepthsurface;
- IDirect3DSurface9 *d3drt_backbuffercolorsurface;
- void *d3dvertexbuffer;
- void *d3dvertexdata;
- int d3dvertexsize;
-#endif
}
gl_state_t;
static void GL_Backend_ResetState(void);
-static void R_Mesh_InitVertexDeclarations(void);
-static void R_Mesh_DestroyVertexDeclarations(void);
-
static void R_Mesh_SetUseVBO(void)
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
+ case RENDERPATH_GLES2:
gl_state.usevbo_staticvertex = (vid.support.arb_vertex_buffer_object && gl_vbo.integer) || vid.forcevbo;
gl_state.usevbo_staticindex = (vid.support.arb_vertex_buffer_object && (gl_vbo.integer == 1 || gl_vbo.integer == 3)) || vid.forcevbo;
gl_state.usevbo_dynamicvertex = (vid.support.arb_vertex_buffer_object && gl_vbo_dynamicvertex.integer && gl_vbo.integer) || vid.forcevbo;
gl_state.usevbo_dynamicindex = (vid.support.arb_vertex_buffer_object && gl_vbo_dynamicindex.integer && gl_vbo.integer) || vid.forcevbo;
break;
- case RENDERPATH_D3D9:
- gl_state.usevbo_staticvertex = gl_state.usevbo_staticindex = (vid.support.arb_vertex_buffer_object && gl_vbo.integer) || vid.forcevbo;
- gl_state.usevbo_dynamicvertex = gl_state.usevbo_dynamicindex = (vid.support.arb_vertex_buffer_object && gl_vbo_dynamicvertex.integer && gl_vbo_dynamicindex.integer && gl_vbo.integer) || vid.forcevbo;
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- gl_state.usevbo_staticvertex = false;
- gl_state.usevbo_staticindex = false;
- gl_state.usevbo_dynamicvertex = false;
- gl_state.usevbo_dynamicindex = false;
- break;
- case RENDERPATH_GLES2:
- gl_state.usevbo_staticvertex = (vid.support.arb_vertex_buffer_object && gl_vbo.integer) || vid.forcevbo;
- gl_state.usevbo_staticindex = (vid.support.arb_vertex_buffer_object && gl_vbo.integer) || vid.forcevbo;
- gl_state.usevbo_dynamicvertex = (vid.support.arb_vertex_buffer_object && gl_vbo_dynamicvertex.integer) || vid.forcevbo;
- gl_state.usevbo_dynamicindex = (vid.support.arb_vertex_buffer_object && gl_vbo_dynamicindex.integer) || vid.forcevbo;
- break;
}
}
{
memset(&gl_state, 0, sizeof(gl_state));
- R_Mesh_InitVertexDeclarations();
-
R_Mesh_SetUseVBO();
Mem_ExpandableArray_NewArray(&gl_state.meshbufferarray, r_main_mempool, sizeof(r_meshbuffer_t), 128);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// fetch current fbo here (default fbo is not 0 on some GLES devices)
if (vid.support.ext_framebuffer_object)
qglGetIntegerv(GL_FRAMEBUFFER_BINDING, &gl_state.defaultframebufferobject);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_GetDepthStencilSurface(vid_d3d9dev, &gl_state.d3drt_backbufferdepthsurface);
- IDirect3DDevice9_GetRenderTarget(vid_d3d9dev, 0, &gl_state.d3drt_backbuffercolorsurface);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
}
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DSurface9_Release(gl_state.d3drt_backbufferdepthsurface);
- IDirect3DSurface9_Release(gl_state.d3drt_backbuffercolorsurface);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
if (gl_state.preparevertices_tempdata)
Mem_ExpandableArray_FreeArray(&gl_state.meshbufferarray);
- R_Mesh_DestroyVertexDeclarations();
-
memset(&gl_state, 0, sizeof(gl_state));
}
{
int i, endindex;
r_meshbuffer_t *buffer;
-#ifdef SUPPORTD3D
- gl_state.d3dvertexbuffer = NULL;
-#endif
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DSurface9_Release(gl_state.d3drt_backbufferdepthsurface);
- IDirect3DSurface9_Release(gl_state.d3drt_backbuffercolorsurface);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
endindex = (int)Mem_ExpandableArray_IndexRange(&gl_state.meshbufferarray);
for (i = 0;i < endindex;i++)
continue;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (buffer->devicebuffer)
- {
- if (buffer->isindexbuffer)
- IDirect3DIndexBuffer9_Release((IDirect3DIndexBuffer9*)buffer->devicebuffer);
- else
- IDirect3DVertexBuffer9_Release((IDirect3DVertexBuffer9*)buffer->devicebuffer);
- buffer->devicebuffer = NULL;
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
}
}
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_GetDepthStencilSurface(vid_d3d9dev, &gl_state.d3drt_backbufferdepthsurface);
- IDirect3DDevice9_GetRenderTarget(vid_d3d9dev, 0, &gl_state.d3drt_backbuffercolorsurface);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
}
Cvar_RegisterVariable(&gl_printcheckerror);
Cvar_RegisterVariable(&gl_mesh_drawrangeelements);
- Cvar_RegisterVariable(&gl_mesh_testmanualfeeding);
Cmd_AddCommand("gl_vbostats", GL_VBOStats_f, "prints a list of all buffer objects (vertex data and triangle elements) and total video memory used by them");
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglFinish();
break;
- case RENDERPATH_D3D9:
- //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Finish();
- break;
}
}
// D3D Y coordinate is top to bottom, OpenGL is bottom to top, fix the D3D one
switch(vid.renderpath)
{
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- scissor[1] = vid.height - scissor[1] - scissor[3];
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
}
m[15] = 1;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- m[10] = -1/(zFar - zNear);
- m[14] = -zNear/(zFar-zNear);
- break;
}
v->screentodepth[0] = -farclip / (farclip - nearclip);
v->screentodepth[1] = farclip * nearclip / (farclip - nearclip);
Matrix4x4_Invert_Full(&tempmatrix, &v->cameramatrix);
Matrix4x4_Concat(&v->viewmatrix, &basematrix, &tempmatrix);
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_GL13:
- case RENDERPATH_GL11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
- break;
- case RENDERPATH_D3D9:
- m[5] *= -1;
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- }
-
if (nearplane)
R_Viewport_ApplyNearClipPlaneFloatGL(v, m, nearplane[0], nearplane[1], nearplane[2], nearplane[3]);
switch(vid.renderpath)
{
- case RENDERPATH_GL13:
- case RENDERPATH_GL11:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- {
- float m[16];
- CHECKGLERROR
- qglViewport(v->x, v->y, v->width, v->height);CHECKGLERROR
- // Load the projection matrix into OpenGL
- qglMatrixMode(GL_PROJECTION);CHECKGLERROR
- Matrix4x4_ToArrayFloatGL(&gl_projectionmatrix, m);
- qglLoadMatrixf(m);CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- }
-#endif
- break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- D3DVIEWPORT9 d3dviewport;
- d3dviewport.X = gl_viewport.x;
- d3dviewport.Y = gl_viewport.y;
- d3dviewport.Width = gl_viewport.width;
- d3dviewport.Height = gl_viewport.height;
- d3dviewport.MinZ = gl_state.depthrange[0];
- d3dviewport.MaxZ = gl_state.depthrange[1];
- IDirect3DDevice9_SetViewport(vid_d3d9dev, &d3dviewport);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Viewport(v->x, v->y, v->width, v->height);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
CHECKGLERROR
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (vid.support.arb_framebuffer_object)
{
return temp;
}
return 0;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- return 1;
- case RENDERPATH_SOFT:
- return 1;
}
return 0;
}
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (fbo)
{
qglDeleteFramebuffers(1, (GLuint*)&fbo);
}
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- break;
- }
-}
-
-#ifdef SUPPORTD3D
-void R_Mesh_SetRenderTargetsD3D9(IDirect3DSurface9 *depthsurface, IDirect3DSurface9 *colorsurface0, IDirect3DSurface9 *colorsurface1, IDirect3DSurface9 *colorsurface2, IDirect3DSurface9 *colorsurface3)
-{
- gl_state.framebufferobject = depthsurface != gl_state.d3drt_backbufferdepthsurface || colorsurface0 != gl_state.d3drt_backbuffercolorsurface;
- if (gl_state.d3drt_depthsurface != depthsurface)
- {
- gl_state.d3drt_depthsurface = depthsurface;
- IDirect3DDevice9_SetDepthStencilSurface(vid_d3d9dev, gl_state.d3drt_depthsurface);
- }
- if (gl_state.d3drt_colorsurfaces[0] != colorsurface0)
- {
- gl_state.d3drt_colorsurfaces[0] = colorsurface0;
- IDirect3DDevice9_SetRenderTarget(vid_d3d9dev, 0, gl_state.d3drt_colorsurfaces[0]);
- }
- if (gl_state.d3drt_colorsurfaces[1] != colorsurface1)
- {
- gl_state.d3drt_colorsurfaces[1] = colorsurface1;
- IDirect3DDevice9_SetRenderTarget(vid_d3d9dev, 1, gl_state.d3drt_colorsurfaces[1]);
- }
- if (gl_state.d3drt_colorsurfaces[2] != colorsurface2)
- {
- gl_state.d3drt_colorsurfaces[2] = colorsurface2;
- IDirect3DDevice9_SetRenderTarget(vid_d3d9dev, 2, gl_state.d3drt_colorsurfaces[2]);
- }
- if (gl_state.d3drt_colorsurfaces[3] != colorsurface3)
- {
- gl_state.d3drt_colorsurfaces[3] = colorsurface3;
- IDirect3DDevice9_SetRenderTarget(vid_d3d9dev, 3, gl_state.d3drt_colorsurfaces[3]);
}
}
-#endif
void R_Mesh_SetRenderTargets(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, rtexture_t *colortexture2, rtexture_t *colortexture3, rtexture_t *colortexture4)
{
if (gl_state.units[i].texture == textures[j])
R_Mesh_TexBind(i, NULL);
// set up framebuffer object or render targets for the active rendering API
- switch(vid.renderpath)
+ switch (vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (gl_state.framebufferobject != fbo)
{
qglBindFramebuffer(GL_FRAMEBUFFER, gl_state.framebufferobject ? gl_state.framebufferobject : gl_state.defaultframebufferobject);
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- // set up the new render targets, a NULL depthtexture intentionally binds nothing
- // TODO: optimize: keep surface pointer around in rtexture_t until texture is freed or lost
- if (fbo)
- {
- IDirect3DSurface9 *surfaces[5];
- for (i = 0;i < 5;i++)
- {
- surfaces[i] = NULL;
- if (textures[i])
- {
- if (textures[i]->d3dsurface)
- surfaces[i] = (IDirect3DSurface9 *)textures[i]->d3dsurface;
- else
- IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9 *)textures[i]->d3dtexture, 0, &surfaces[i]);
- }
- }
- // set the render targets for real
- R_Mesh_SetRenderTargetsD3D9(surfaces[4], surfaces[0], surfaces[1], surfaces[2], surfaces[3]);
- // release the texture surface levels (they won't be lost while bound...)
- for (i = 0;i < 5;i++)
- if (textures[i] && !textures[i]->d3dsurface)
- IDirect3DSurface9_Release(surfaces[i]);
- }
- else
- R_Mesh_SetRenderTargetsD3D9(gl_state.d3drt_backbufferdepthsurface, gl_state.d3drt_backbuffercolorsurface, NULL, NULL, NULL);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (fbo)
- {
- int width, height;
- unsigned int *pointers[5];
- memset(pointers, 0, sizeof(pointers));
- for (i = 0;i < 5;i++)
- pointers[i] = textures[i] ? (unsigned int *)DPSOFTRAST_Texture_GetPixelPointer(textures[i]->texnum, 0) : NULL;
- width = DPSOFTRAST_Texture_GetWidth(textures[0] ? textures[0]->texnum : textures[4]->texnum, 0);
- height = DPSOFTRAST_Texture_GetHeight(textures[0] ? textures[0]->texnum : textures[4]->texnum, 0);
- DPSOFTRAST_SetRenderTargets(width, height, pointers[4], pointers[0], pointers[1], pointers[2], pointers[3]);
- }
- else
- DPSOFTRAST_SetRenderTargets(vid.width, vid.height, vid.softdepthpixels, vid.softpixels, NULL, NULL, NULL);
- break;
- }
-}
-
-#ifdef SUPPORTD3D
-static int d3dcmpforglfunc(int f)
-{
- switch(f)
- {
- case GL_NEVER: return D3DCMP_NEVER;
- case GL_LESS: return D3DCMP_LESS;
- case GL_EQUAL: return D3DCMP_EQUAL;
- case GL_LEQUAL: return D3DCMP_LESSEQUAL;
- case GL_GREATER: return D3DCMP_GREATER;
- case GL_NOTEQUAL: return D3DCMP_NOTEQUAL;
- case GL_GEQUAL: return D3DCMP_GREATEREQUAL;
- case GL_ALWAYS: return D3DCMP_ALWAYS;
- default: Con_DPrintf("Unknown GL_DepthFunc\n");return D3DCMP_ALWAYS;
- }
-}
-
-static int d3dstencilopforglfunc(int f)
-{
- switch(f)
- {
- case GL_KEEP: return D3DSTENCILOP_KEEP;
- case GL_INCR: return D3DSTENCILOP_INCR; // note: GL_INCR is clamped, D3DSTENCILOP_INCR wraps
- case GL_DECR: return D3DSTENCILOP_DECR; // note: GL_DECR is clamped, D3DSTENCILOP_DECR wraps
- default: Con_DPrintf("Unknown GL_StencilFunc\n");return D3DSTENCILOP_KEEP;
}
}
-#endif
static void GL_Backend_ResetState(void)
{
switch(vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_COLORWRITEENABLE, gl_state.colormask);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CULLMODE, D3DCULL_NONE);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ZFUNC, d3dcmpforglfunc(gl_state.depthfunc));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ZENABLE, gl_state.depthtest);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ZWRITEENABLE, gl_state.depthmask);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_SLOPESCALEDEPTHBIAS, gl_state.polygonoffset[0]);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_DEPTHBIAS, gl_state.polygonoffset[1] * (1.0f / 16777216.0f));
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- CHECKGLERROR
-
- qglColorMask(1, 1, 1, 1);CHECKGLERROR
- qglAlphaFunc(gl_state.alphafunc, gl_state.alphafuncvalue);CHECKGLERROR
- qglDisable(GL_ALPHA_TEST);CHECKGLERROR
- if (qglBlendFuncSeparate)
- {
- qglBlendFuncSeparate(gl_state.blendfunc1, gl_state.blendfunc2, GL_ZERO, GL_ONE);CHECKGLERROR // ELUAN: Adreno 225 (and others) compositing workaround
- }
- else
- {
- qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR
- }
- qglDisable(GL_BLEND);CHECKGLERROR
- qglCullFace(gl_state.cullface);CHECKGLERROR
- qglDisable(GL_CULL_FACE);CHECKGLERROR
- qglDepthFunc(GL_LEQUAL);CHECKGLERROR
- qglEnable(GL_DEPTH_TEST);CHECKGLERROR
- qglDepthMask(gl_state.depthmask);CHECKGLERROR
- qglPolygonOffset(gl_state.polygonoffset[0], gl_state.polygonoffset[1]);
-
- if (vid.support.arb_vertex_buffer_object)
- {
- qglBindBufferARB(GL_ARRAY_BUFFER, 0);
- qglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
- }
-
- if (vid.support.ext_framebuffer_object)
- {
- //qglBindRenderbuffer(GL_RENDERBUFFER, 0);
- qglBindFramebuffer(GL_FRAMEBUFFER, 0);
- }
-
- qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), NULL);CHECKGLERROR
- qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
-
- qglColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL);CHECKGLERROR
- qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
- qglColor4f(1, 1, 1, 1);CHECKGLERROR
-
- if (vid.support.ext_framebuffer_object)
- qglBindFramebuffer(GL_FRAMEBUFFER, gl_state.framebufferobject);
-
- gl_state.unit = MAX_TEXTUREUNITS;
- gl_state.clientunit = MAX_TEXTUREUNITS;
- for (i = 0;i < vid.texunits;i++)
- {
- GL_ActiveTexture(i);
- GL_ClientActiveTexture(i);
- qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- qglBindTexture(GL_TEXTURE_2D, 0);CHECKGLERROR
- if (vid.support.ext_texture_3d)
- {
- qglDisable(GL_TEXTURE_3D);CHECKGLERROR
- qglBindTexture(GL_TEXTURE_3D, 0);CHECKGLERROR
- }
- if (vid.support.arb_texture_cube_map)
- {
- qglDisable(GL_TEXTURE_CUBE_MAP);CHECKGLERROR
- qglBindTexture(GL_TEXTURE_CUBE_MAP, 0);CHECKGLERROR
- }
- GL_BindVBO(0);
- qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), NULL);CHECKGLERROR
- qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- qglMatrixMode(GL_TEXTURE);CHECKGLERROR
- qglLoadIdentity();CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);CHECKGLERROR
- }
- CHECKGLERROR
-#endif
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_ColorMask(1,1,1,1);
- DPSOFTRAST_BlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);
- DPSOFTRAST_CullFace(gl_state.cullface);
- DPSOFTRAST_DepthFunc(gl_state.depthfunc);
- DPSOFTRAST_DepthMask(gl_state.depthmask);
- DPSOFTRAST_PolygonOffset(gl_state.polygonoffset[0], gl_state.polygonoffset[1]);
- DPSOFTRAST_SetRenderTargets(vid.width, vid.height, vid.softdepthpixels, vid.softpixels, NULL, NULL, NULL);
- DPSOFTRAST_Viewport(0, 0, vid.width, vid.height);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
CHECKGLERROR
gl_state.unit = num;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
- if (qglActiveTexture)
- {
- CHECKGLERROR
- qglActiveTexture(GL_TEXTURE0 + gl_state.unit);
- CHECKGLERROR
- }
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- break;
- }
- }
-}
-
-void GL_ClientActiveTexture(unsigned int num)
-{
- if (gl_state.clientunit != num)
- {
- gl_state.clientunit = num;
- switch(vid.renderpath)
- {
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- if (qglActiveTexture)
- {
- CHECKGLERROR
- qglClientActiveTexture(GL_TEXTURE0 + gl_state.clientunit);
- CHECKGLERROR
- }
-#endif
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
+ CHECKGLERROR
+ qglActiveTexture(GL_TEXTURE0 + gl_state.unit);
+ CHECKGLERROR
break;
}
}
blendenable = (gl_state.blendfunc1 != GL_ONE || gl_state.blendfunc2 != GL_ZERO);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if (qglBlendFuncSeparate)
}
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- int i;
- int glblendfunc[2];
- D3DBLEND d3dblendfunc[2];
- glblendfunc[0] = gl_state.blendfunc1;
- glblendfunc[1] = gl_state.blendfunc2;
- for (i = 0;i < 2;i++)
- {
- switch(glblendfunc[i])
- {
- case GL_ZERO: d3dblendfunc[i] = D3DBLEND_ZERO;break;
- case GL_ONE: d3dblendfunc[i] = D3DBLEND_ONE;break;
- case GL_SRC_COLOR: d3dblendfunc[i] = D3DBLEND_SRCCOLOR;break;
- case GL_ONE_MINUS_SRC_COLOR: d3dblendfunc[i] = D3DBLEND_INVSRCCOLOR;break;
- case GL_SRC_ALPHA: d3dblendfunc[i] = D3DBLEND_SRCALPHA;break;
- case GL_ONE_MINUS_SRC_ALPHA: d3dblendfunc[i] = D3DBLEND_INVSRCALPHA;break;
- case GL_DST_ALPHA: d3dblendfunc[i] = D3DBLEND_DESTALPHA;break;
- case GL_ONE_MINUS_DST_ALPHA: d3dblendfunc[i] = D3DBLEND_INVDESTALPHA;break;
- case GL_DST_COLOR: d3dblendfunc[i] = D3DBLEND_DESTCOLOR;break;
- case GL_ONE_MINUS_DST_COLOR: d3dblendfunc[i] = D3DBLEND_INVDESTCOLOR;break;
- }
- }
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_SRCBLEND, d3dblendfunc[0]);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_DESTBLEND, d3dblendfunc[1]);
- if (gl_state.blend != blendenable)
- {
- gl_state.blend = blendenable;
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ALPHABLENDENABLE, gl_state.blend);
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_BlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);
- break;
}
}
}
gl_state.depthmask = state;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
qglDepthMask(gl_state.depthmask);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ZWRITEENABLE, gl_state.depthmask);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_DepthMask(gl_state.depthmask);
- break;
}
}
}
gl_state.depthtest = state;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if (gl_state.depthtest)
qglDisable(GL_DEPTH_TEST);CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ZENABLE, gl_state.depthtest);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_DepthTest(gl_state.depthtest);
- break;
}
}
}
gl_state.depthfunc = state;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
qglDepthFunc(gl_state.depthfunc);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_ZFUNC, d3dcmpforglfunc(gl_state.depthfunc));
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_DepthFunc(gl_state.depthfunc);
- break;
}
}
}
gl_state.depthrange[1] = farfrac;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
#ifdef USE_GLES2
qglDepthRangef(gl_state.depthrange[0], gl_state.depthrange[1]);
qglDepthRange(gl_state.depthrange[0], gl_state.depthrange[1]);
#endif
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- D3DVIEWPORT9 d3dviewport;
- d3dviewport.X = gl_viewport.x;
- d3dviewport.Y = gl_viewport.y;
- d3dviewport.Width = gl_viewport.width;
- d3dviewport.Height = gl_viewport.height;
- d3dviewport.MinZ = gl_state.depthrange[0];
- d3dviewport.MaxZ = gl_state.depthrange[1];
- IDirect3DDevice9_SetViewport(vid_d3d9dev, &d3dviewport);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_DepthRange(gl_state.depthrange[0], gl_state.depthrange[1]);
- break;
}
}
}
{
switch (vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if (enable)
#endif
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_TWOSIDEDSTENCILMODE, true);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILENABLE, enable);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILWRITEMASK, writemask);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILFAIL, d3dstencilopforglfunc(frontfail));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILZFAIL, d3dstencilopforglfunc(frontzfail));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILPASS, d3dstencilopforglfunc(frontzpass));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILFUNC, d3dcmpforglfunc(frontcompare));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CCW_STENCILFAIL, d3dstencilopforglfunc(backfail));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CCW_STENCILZFAIL, d3dstencilopforglfunc(backzfail));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CCW_STENCILPASS, d3dstencilopforglfunc(backzpass));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CCW_STENCILFUNC, d3dcmpforglfunc(backcompare));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILREF, comparereference);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILMASK, comparemask);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
}
{
switch (vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if (enable)
qglStencilFunc(compare, comparereference, comparemask);CHECKGLERROR
CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (vid.support.ati_separate_stencil)
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_TWOSIDEDSTENCILMODE, true);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILENABLE, enable);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILWRITEMASK, writemask);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILFAIL, d3dstencilopforglfunc(fail));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILZFAIL, d3dstencilopforglfunc(zfail));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILPASS, d3dstencilopforglfunc(zpass));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILFUNC, d3dcmpforglfunc(compare));
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILREF, comparereference);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_STENCILMASK, comparemask);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
}
gl_state.polygonoffset[1] = depthoffset;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglPolygonOffset(gl_state.polygonoffset[0], gl_state.polygonoffset[1]);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_SLOPESCALEDEPTHBIAS, gl_state.polygonoffset[0]);
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_DEPTHBIAS, gl_state.polygonoffset[1] * (1.0f / 16777216.0f));
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_PolygonOffset(gl_state.polygonoffset[0], gl_state.polygonoffset[1]);
- break;
}
}
}
return;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglCullFace(gl_state.cullface);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CULLMODE, gl_state.cullface == GL_FRONT ? D3DCULL_CCW : D3DCULL_CW);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_CullFace(gl_state.cullface);
- break;
}
}
}
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
}
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (gl_state.cullface != state)
- {
- gl_state.cullface = state;
- switch(gl_state.cullface)
- {
- case GL_NONE:
- gl_state.cullfaceenable = false;
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CULLMODE, D3DCULL_NONE);
- break;
- case GL_FRONT:
- gl_state.cullfaceenable = true;
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CULLMODE, D3DCULL_CCW);
- break;
- case GL_BACK:
- gl_state.cullfaceenable = true;
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_CULLMODE, D3DCULL_CW);
- break;
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (gl_state.cullface != state)
- {
- gl_state.cullface = state;
- gl_state.cullfaceenable = state != GL_NONE ? true : false;
- DPSOFTRAST_CullFace(gl_state.cullface);
- }
- break;
- }
-}
-
-void GL_AlphaTest(int state)
-{
- if (gl_state.alphatest != state)
- {
- gl_state.alphatest = state;
- switch(vid.renderpath)
- {
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifdef GL_ALPHA_TEST
- // only fixed function uses alpha test, other paths use pixel kill capability in shaders
- CHECKGLERROR
- if (gl_state.alphatest)
- {
- qglEnable(GL_ALPHA_TEST);CHECKGLERROR
- }
- else
- {
- qglDisable(GL_ALPHA_TEST);CHECKGLERROR
- }
-#endif
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GL20:
- case RENDERPATH_GLES2:
- break;
- }
}
}
gl_state.alphatocoverage = state;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
break;
case RENDERPATH_GL20:
#ifdef GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
gl_state.colormask = state;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
qglColorMask((GLboolean)r, (GLboolean)g, (GLboolean)b, (GLboolean)a);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_COLORWRITEENABLE, state);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_ColorMask(r, g, b, a);
- break;
}
}
}
gl_state.color4f[3] = ca;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- CHECKGLERROR
- qglColor4f(gl_state.color4f[0], gl_state.color4f[1], gl_state.color4f[2], gl_state.color4f[3]);
- CHECKGLERROR
-#endif
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- // no equivalent in D3D
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Color4f(cr, cg, cb, ca);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
qglVertexAttrib4f(GLSLATTRIB_COLOR, cr, cg, cb, ca);
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
qglScissor(x, y,width,height);
CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- RECT d3drect;
- d3drect.left = x;
- d3drect.top = y;
- d3drect.right = x + width;
- d3drect.bottom = y + height;
- IDirect3DDevice9_SetScissorRect(vid_d3d9dev, &d3drect);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Scissor(x, y, width, height);
- break;
}
}
gl_state.scissortest = state;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if(gl_state.scissortest)
qglDisable(GL_SCISSOR_TEST);
CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_SCISSORTESTENABLE, gl_state.scissortest);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_ScissorTest(gl_state.scissortest);
- break;
}
}
}
}
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if (mask & GL_COLOR_BUFFER_BIT)
}
qglClear(mask);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_Clear(vid_d3d9dev, 0, NULL, ((mask & GL_COLOR_BUFFER_BIT) ? D3DCLEAR_TARGET : 0) | ((mask & GL_STENCIL_BUFFER_BIT) ? D3DCLEAR_STENCIL : 0) | ((mask & GL_DEPTH_BUFFER_BIT) ? D3DCLEAR_ZBUFFER : 0), D3DCOLOR_COLORVALUE(colorvalue[0], colorvalue[1], colorvalue[2], colorvalue[3]), depthvalue, stencilvalue);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (mask & GL_COLOR_BUFFER_BIT)
- DPSOFTRAST_ClearColor(colorvalue[0], colorvalue[1], colorvalue[2], colorvalue[3]);
- if (mask & GL_DEPTH_BUFFER_BIT)
- DPSOFTRAST_ClearDepth(depthvalue);
- break;
}
}
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
#ifndef GL_BGRA
qglReadPixels(x, y, width, height, GL_BGRA, GL_UNSIGNED_BYTE, outpixels);CHECKGLERROR
#endif
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- // LordHavoc: we can't directly download the backbuffer because it may be
- // multisampled, and it may not be lockable, so we blit it to a lockable
- // surface of the same dimensions (but without multisample) to resolve the
- // multisample buffer to a normal image, and then lock that...
- IDirect3DSurface9 *stretchsurface = NULL;
- if (!FAILED(IDirect3DDevice9_CreateRenderTarget(vid_d3d9dev, vid.width, vid.height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &stretchsurface, NULL)))
- {
- D3DLOCKED_RECT lockedrect;
- if (!FAILED(IDirect3DDevice9_StretchRect(vid_d3d9dev, gl_state.d3drt_backbuffercolorsurface, NULL, stretchsurface, NULL, D3DTEXF_POINT)))
- {
- if (!FAILED(IDirect3DSurface9_LockRect(stretchsurface, &lockedrect, NULL, D3DLOCK_READONLY)))
- {
- int line;
- unsigned char *row = (unsigned char *)lockedrect.pBits + x * 4 + lockedrect.Pitch * (vid.height - 1 - y);
- for (line = 0;line < height;line++, row -= lockedrect.Pitch)
- memcpy(outpixels + line * width * 4, row, width * 4);
- IDirect3DSurface9_UnlockRect(stretchsurface);
- }
- }
- IDirect3DSurface9_Release(stretchsurface);
- }
- // code scraps
- //IDirect3DSurface9 *syssurface = NULL;
- //if (!FAILED(IDirect3DDevice9_CreateRenderTarget(vid_d3d9dev, vid.width, vid.height, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &stretchsurface, NULL)))
- //if (!FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(vid_d3d9dev, vid.width, vid.height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &syssurface, NULL)))
- //IDirect3DDevice9_GetRenderTargetData(vid_d3d9dev, gl_state.d3drt_backbuffercolorsurface, syssurface);
- //if (!FAILED(IDirect3DDevice9_GetFrontBufferData(vid_d3d9dev, 0, syssurface)))
- //if (!FAILED(IDirect3DSurface9_LockRect(syssurface, &lockedrect, NULL, D3DLOCK_READONLY)))
- //IDirect3DSurface9_UnlockRect(syssurface);
- //IDirect3DSurface9_Release(syssurface);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_GetPixelsBGRA(x, y, width, height, outpixels);
- break;
}
}
element3s_bufferoffset += firsttriangle * 3 * sizeof(*element3s);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// check if the user specified to ignore static index buffers
if (!gl_state.usevbo_staticindex || (gl_vbo.integer == 3 && !vid.forcevbo && (element3i_bufferoffset || element3s_bufferoffset)))
element3s_indexbuffer = NULL;
}
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- break;
}
// upload a dynamic index buffer if needed
if (element3s)
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
CHECKGLERROR
- if (gl_mesh_testmanualfeeding.integer)
- {
-#ifndef USE_GLES2
- unsigned int i, j, element;
- const GLfloat *p;
- qglBegin(GL_TRIANGLES);
- if(vid.renderpath == RENDERPATH_GL20)
- {
- for (i = 0;i < (unsigned int) numtriangles * 3;i++)
- {
- if (element3i)
- element = element3i[i];
- else if (element3s)
- element = element3s[i];
- else
- element = firstvertex + i;
- for (j = 0;j < vid.texarrayunits;j++)
- {
- if (gl_state.units[j].pointer_texcoord_pointer && gl_state.units[j].arrayenabled)
- {
- if (gl_state.units[j].pointer_texcoord_gltype == GL_FLOAT)
- {
- p = (const GLfloat *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglVertexAttrib4f(GLSLATTRIB_TEXCOORD0 + j, p[0], p[1], p[2], p[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglVertexAttrib3f(GLSLATTRIB_TEXCOORD0 + j, p[0], p[1], p[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglVertexAttrib2f(GLSLATTRIB_TEXCOORD0 + j, p[0], p[1]);
- else
- qglVertexAttrib1f(GLSLATTRIB_TEXCOORD0 + j, p[0]);
- }
- else if (gl_state.units[j].pointer_texcoord_gltype == (int)(GL_SHORT | 0x80000000))
- {
- const GLshort *s = (const GLshort *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglVertexAttrib4f(GLSLATTRIB_TEXCOORD0 + j, s[0], s[1], s[2], s[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglVertexAttrib3f(GLSLATTRIB_TEXCOORD0 + j, s[0], s[1], s[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglVertexAttrib2f(GLSLATTRIB_TEXCOORD0 + j, s[0], s[1]);
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglVertexAttrib1f(GLSLATTRIB_TEXCOORD0 + j, s[0]);
- }
- else if (gl_state.units[j].pointer_texcoord_gltype == GL_BYTE)
- {
- const GLbyte *sb = (const GLbyte *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglVertexAttrib4f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 127.0f), sb[1] * (1.0f / 127.0f), sb[2] * (1.0f / 127.0f), sb[3] * (1.0f / 127.0f));
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglVertexAttrib3f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 127.0f), sb[1] * (1.0f / 127.0f), sb[2] * (1.0f / 127.0f));
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglVertexAttrib2f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 127.0f), sb[1] * (1.0f / 127.0f));
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglVertexAttrib1f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 127.0f));
- }
- else if (gl_state.units[j].pointer_texcoord_gltype == GL_UNSIGNED_BYTE)
- {
- const GLubyte *sb = (const GLubyte *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglVertexAttrib4f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 255.0f), sb[1] * (1.0f / 255.0f), sb[2] * (1.0f / 255.0f), sb[3] * (1.0f / 255.0f));
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglVertexAttrib3f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 255.0f), sb[1] * (1.0f / 255.0f), sb[2] * (1.0f / 255.0f));
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglVertexAttrib2f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 255.0f), sb[1] * (1.0f / 255.0f));
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglVertexAttrib1f(GLSLATTRIB_TEXCOORD0 + j, sb[0] * (1.0f / 255.0f));
- }
- else if (gl_state.units[j].pointer_texcoord_gltype == (int)(GL_UNSIGNED_BYTE | 0x80000000))
- {
- const GLubyte *sb = (const GLubyte *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglVertexAttrib4f(GLSLATTRIB_TEXCOORD0 + j, sb[0], sb[1], sb[2], sb[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglVertexAttrib3f(GLSLATTRIB_TEXCOORD0 + j, sb[0], sb[1], sb[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglVertexAttrib2f(GLSLATTRIB_TEXCOORD0 + j, sb[0], sb[1]);
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglVertexAttrib1f(GLSLATTRIB_TEXCOORD0 + j, sb[0]);
- }
- }
- }
- if (gl_state.pointer_color_pointer && gl_state.pointer_color_enabled && gl_state.pointer_color_components == 4)
- {
- if (gl_state.pointer_color_gltype == GL_FLOAT)
- {
- p = (const GLfloat *)((const unsigned char *)gl_state.pointer_color_pointer + element * gl_state.pointer_color_stride);
- qglVertexAttrib4f(GLSLATTRIB_COLOR, p[0], p[1], p[2], p[3]);
- }
- else if (gl_state.pointer_color_gltype == GL_UNSIGNED_BYTE)
- {
- const GLubyte *ub = (const GLubyte *)((const unsigned char *)gl_state.pointer_color_pointer + element * gl_state.pointer_color_stride);
- qglVertexAttrib4Nub(GLSLATTRIB_COLOR, ub[0], ub[1], ub[2], ub[3]);
- }
- }
- if (gl_state.pointer_vertex_gltype == GL_FLOAT)
- {
- p = (const GLfloat *)((const unsigned char *)gl_state.pointer_vertex_pointer + element * gl_state.pointer_vertex_stride);
- if (gl_state.pointer_vertex_components == 4)
- qglVertexAttrib4f(GLSLATTRIB_POSITION, p[0], p[1], p[2], p[3]);
- else if (gl_state.pointer_vertex_components == 3)
- qglVertexAttrib3f(GLSLATTRIB_POSITION, p[0], p[1], p[2]);
- else
- qglVertexAttrib2f(GLSLATTRIB_POSITION, p[0], p[1]);
- }
- }
- }
- else
- {
- for (i = 0;i < (unsigned int) numtriangles * 3;i++)
- {
- if (element3i)
- element = element3i[i];
- else if (element3s)
- element = element3s[i];
- else
- element = firstvertex + i;
- for (j = 0;j < vid.texarrayunits;j++)
- {
- if (gl_state.units[j].pointer_texcoord_pointer && gl_state.units[j].arrayenabled)
- {
- if (gl_state.units[j].pointer_texcoord_gltype == GL_FLOAT)
- {
- p = (const GLfloat *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (vid.texarrayunits > 1)
- {
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglMultiTexCoord4f(GL_TEXTURE0 + j, p[0], p[1], p[2], p[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglMultiTexCoord3f(GL_TEXTURE0 + j, p[0], p[1], p[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglMultiTexCoord2f(GL_TEXTURE0 + j, p[0], p[1]);
- else
- qglMultiTexCoord1f(GL_TEXTURE0 + j, p[0]);
- }
- else
- {
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglTexCoord4f(p[0], p[1], p[2], p[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglTexCoord3f(p[0], p[1], p[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglTexCoord2f(p[0], p[1]);
- else
- qglTexCoord1f(p[0]);
- }
- }
- else if (gl_state.units[j].pointer_texcoord_gltype == GL_SHORT)
- {
- const GLshort *s = (const GLshort *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (vid.texarrayunits > 1)
- {
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglMultiTexCoord4f(GL_TEXTURE0 + j, s[0], s[1], s[2], s[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglMultiTexCoord3f(GL_TEXTURE0 + j, s[0], s[1], s[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglMultiTexCoord2f(GL_TEXTURE0 + j, s[0], s[1]);
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglMultiTexCoord1f(GL_TEXTURE0 + j, s[0]);
- }
- else
- {
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglTexCoord4f(s[0], s[1], s[2], s[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglTexCoord3f(s[0], s[1], s[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglTexCoord2f(s[0], s[1]);
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglTexCoord1f(s[0]);
- }
- }
- else if (gl_state.units[j].pointer_texcoord_gltype == GL_BYTE)
- {
- const GLbyte *sb = (const GLbyte *)((const unsigned char *)gl_state.units[j].pointer_texcoord_pointer + element * gl_state.units[j].pointer_texcoord_stride);
- if (vid.texarrayunits > 1)
- {
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglMultiTexCoord4f(GL_TEXTURE0 + j, sb[0], sb[1], sb[2], sb[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglMultiTexCoord3f(GL_TEXTURE0 + j, sb[0], sb[1], sb[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglMultiTexCoord2f(GL_TEXTURE0 + j, sb[0], sb[1]);
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglMultiTexCoord1f(GL_TEXTURE0 + j, sb[0]);
- }
- else
- {
- if (gl_state.units[j].pointer_texcoord_components == 4)
- qglTexCoord4f(sb[0], sb[1], sb[2], sb[3]);
- else if (gl_state.units[j].pointer_texcoord_components == 3)
- qglTexCoord3f(sb[0], sb[1], sb[2]);
- else if (gl_state.units[j].pointer_texcoord_components == 2)
- qglTexCoord2f(sb[0], sb[1]);
- else if (gl_state.units[j].pointer_texcoord_components == 1)
- qglTexCoord1f(sb[0]);
- }
- }
- }
- }
- if (gl_state.pointer_color_pointer && gl_state.pointer_color_enabled && gl_state.pointer_color_components == 4)
- {
- if (gl_state.pointer_color_gltype == GL_FLOAT)
- {
- p = (const GLfloat *)((const unsigned char *)gl_state.pointer_color_pointer + element * gl_state.pointer_color_stride);
- qglColor4f(p[0], p[1], p[2], p[3]);
- }
- else if (gl_state.pointer_color_gltype == GL_UNSIGNED_BYTE)
- {
- const GLubyte *ub = (const GLubyte *)((const unsigned char *)gl_state.pointer_color_pointer + element * gl_state.pointer_color_stride);
- qglColor4ub(ub[0], ub[1], ub[2], ub[3]);
- }
- }
- if (gl_state.pointer_vertex_gltype == GL_FLOAT)
- {
- p = (const GLfloat *)((const unsigned char *)gl_state.pointer_vertex_pointer + element * gl_state.pointer_vertex_stride);
- if (gl_state.pointer_vertex_components == 4)
- qglVertex4f(p[0], p[1], p[2], p[3]);
- else if (gl_state.pointer_vertex_components == 3)
- qglVertex3f(p[0], p[1], p[2]);
- else
- qglVertex2f(p[0], p[1]);
- }
- }
- }
- qglEnd();
- CHECKGLERROR
-#endif
- }
- else if (bufferobject3s)
+ if (bufferobject3s)
{
GL_BindEBO(bufferobject3s);
#ifndef USE_GLES2
CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (gl_state.d3dvertexbuffer && ((element3s && element3s_indexbuffer) || (element3i && element3i_indexbuffer)))
- {
- if (element3s_indexbuffer)
- {
- IDirect3DDevice9_SetIndices(vid_d3d9dev, (IDirect3DIndexBuffer9 *)element3s_indexbuffer->devicebuffer);
- IDirect3DDevice9_DrawIndexedPrimitive(vid_d3d9dev, D3DPT_TRIANGLELIST, 0, firstvertex, numvertices, element3s_bufferoffset>>1, numtriangles);
- }
- else if (element3i_indexbuffer)
- {
- IDirect3DDevice9_SetIndices(vid_d3d9dev, (IDirect3DIndexBuffer9 *)element3i_indexbuffer->devicebuffer);
- IDirect3DDevice9_DrawIndexedPrimitive(vid_d3d9dev, D3DPT_TRIANGLELIST, 0, firstvertex, numvertices, element3i_bufferoffset>>2, numtriangles);
- }
- else
- IDirect3DDevice9_DrawPrimitive(vid_d3d9dev, D3DPT_TRIANGLELIST, firstvertex, numvertices);
- }
- else
- {
- if (element3s)
- IDirect3DDevice9_DrawIndexedPrimitiveUP(vid_d3d9dev, D3DPT_TRIANGLELIST, firstvertex, numvertices, numtriangles, element3s, D3DFMT_INDEX16, gl_state.d3dvertexdata, gl_state.d3dvertexsize);
- else if (element3i)
- IDirect3DDevice9_DrawIndexedPrimitiveUP(vid_d3d9dev, D3DPT_TRIANGLELIST, firstvertex, numvertices, numtriangles, element3i, D3DFMT_INDEX32, gl_state.d3dvertexdata, gl_state.d3dvertexsize);
- else
- IDirect3DDevice9_DrawPrimitiveUP(vid_d3d9dev, D3DPT_TRIANGLELIST, numvertices, (void *)gl_state.d3dvertexdata, gl_state.d3dvertexsize);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_DrawTriangles(firstvertex, numvertices, numtriangles, element3i, element3s);
- break;
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// GLES does not have glDrawRangeElements so this is a bit shorter than the GL20 path
if (bufferobject3s)
buffer->size = size;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (!buffer->bufferobject)
qglGenBuffersARB(1, (GLuint *)&buffer->bufferobject);
if (buffer->isuniformbuffer)
GL_BindUBO(0);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- int result;
- void *datapointer = NULL;
- if (buffer->isindexbuffer)
- {
- IDirect3DIndexBuffer9 *d3d9indexbuffer = (IDirect3DIndexBuffer9 *)buffer->devicebuffer;
- if (offset+size > buffer->size || !buffer->devicebuffer)
- {
- if (buffer->devicebuffer)
- IDirect3DIndexBuffer9_Release((IDirect3DIndexBuffer9*)buffer->devicebuffer);
- buffer->devicebuffer = NULL;
- if (FAILED(result = IDirect3DDevice9_CreateIndexBuffer(vid_d3d9dev, (unsigned int)(offset+size), buffer->isdynamic ? D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC : 0, buffer->isindex16 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, buffer->isdynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &d3d9indexbuffer, NULL)))
- Sys_Error("IDirect3DDevice9_CreateIndexBuffer(%p, %d, %x, %x, %x, %p, NULL) returned %x\n", vid_d3d9dev, (int)size, buffer->isdynamic ? (int)D3DUSAGE_DYNAMIC : 0, buffer->isindex16 ? (int)D3DFMT_INDEX16 : (int)D3DFMT_INDEX32, buffer->isdynamic ? (int)D3DPOOL_DEFAULT : (int)D3DPOOL_MANAGED, &d3d9indexbuffer, (int)result);
- buffer->devicebuffer = (void *)d3d9indexbuffer;
- buffer->size = offset+size;
- }
- if (!FAILED(IDirect3DIndexBuffer9_Lock(d3d9indexbuffer, (unsigned int)offset, (unsigned int)size, &datapointer, buffer->isdynamic ? D3DLOCK_DISCARD : 0)))
- {
- if (data)
- memcpy(datapointer, data, size);
- else
- memset(datapointer, 0, size);
- IDirect3DIndexBuffer9_Unlock(d3d9indexbuffer);
- }
- }
- else
- {
- IDirect3DVertexBuffer9 *d3d9vertexbuffer = (IDirect3DVertexBuffer9 *)buffer->devicebuffer;
- if (offset+size > buffer->size || !buffer->devicebuffer)
- {
- if (buffer->devicebuffer)
- IDirect3DVertexBuffer9_Release((IDirect3DVertexBuffer9*)buffer->devicebuffer);
- buffer->devicebuffer = NULL;
- if (FAILED(result = IDirect3DDevice9_CreateVertexBuffer(vid_d3d9dev, (unsigned int)(offset+size), buffer->isdynamic ? D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC : 0, 0, buffer->isdynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &d3d9vertexbuffer, NULL)))
- Sys_Error("IDirect3DDevice9_CreateVertexBuffer(%p, %d, %x, %x, %x, %p, NULL) returned %x\n", vid_d3d9dev, (int)size, buffer->isdynamic ? (int)D3DUSAGE_DYNAMIC : 0, 0, buffer->isdynamic ? (int)D3DPOOL_DEFAULT : (int)D3DPOOL_MANAGED, &d3d9vertexbuffer, (int)result);
- buffer->devicebuffer = (void *)d3d9vertexbuffer;
- buffer->size = offset+size;
- }
- if (!FAILED(IDirect3DVertexBuffer9_Lock(d3d9vertexbuffer, (unsigned int)offset, (unsigned int)size, &datapointer, buffer->isdynamic ? D3DLOCK_DISCARD : 0)))
- {
- if (data)
- memcpy(datapointer, data, size);
- else
- memset(datapointer, 0, size);
- IDirect3DVertexBuffer9_Unlock(d3d9vertexbuffer);
- }
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
}
return;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// GL clears the binding if we delete something bound
if (gl_state.uniformbufferobject == buffer->bufferobject)
gl_state.elementbufferobject = 0;
qglDeleteBuffersARB(1, (GLuint *)&buffer->bufferobject);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (gl_state.d3dvertexbuffer == (void *)buffer)
- gl_state.d3dvertexbuffer = NULL;
- if (buffer->devicebuffer)
- {
- if (buffer->isindexbuffer)
- IDirect3DIndexBuffer9_Release((IDirect3DIndexBuffer9 *)buffer->devicebuffer);
- else
- IDirect3DVertexBuffer9_Release((IDirect3DVertexBuffer9 *)buffer->devicebuffer);
- buffer->devicebuffer = NULL;
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
Mem_ExpandableArray_FreeRecord(&gl_state.meshbufferarray, (void *)buffer);
}
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- if (gl_state.pointer_vertex_components != components || gl_state.pointer_vertex_gltype != gltype || gl_state.pointer_vertex_stride != stride || gl_state.pointer_vertex_pointer != pointer || gl_state.pointer_vertex_vertexbuffer != vertexbuffer || gl_state.pointer_vertex_offset != bufferoffset)
- {
- int bufferobject = vertexbuffer ? vertexbuffer->bufferobject : 0;
- gl_state.pointer_vertex_components = components;
- gl_state.pointer_vertex_gltype = gltype;
- gl_state.pointer_vertex_stride = stride;
- gl_state.pointer_vertex_pointer = pointer;
- gl_state.pointer_vertex_vertexbuffer = vertexbuffer;
- gl_state.pointer_vertex_offset = bufferoffset;
- CHECKGLERROR
- GL_BindVBO(bufferobject);
- qglVertexPointer(components, gltype, (GLsizei)stride, bufferobject ? (void *)bufferoffset : pointer);CHECKGLERROR
- }
-#endif
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
if (gl_state.pointer_vertex_components != components || gl_state.pointer_vertex_gltype != gltype || gl_state.pointer_vertex_stride != stride || gl_state.pointer_vertex_pointer != pointer || gl_state.pointer_vertex_vertexbuffer != vertexbuffer || gl_state.pointer_vertex_offset != bufferoffset)
qglVertexAttribPointer(GLSLATTRIB_POSITION, components, gltype & ~0x80000000, (gltype & 0x80000000) == 0, (GLsizei)stride, bufferobject ? (void *)bufferoffset : pointer);CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
}
}
// the pointer only.
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- CHECKGLERROR
- if (pointer)
- {
- // caller wants color array enabled
- int bufferobject = vertexbuffer ? vertexbuffer->bufferobject : 0;
- if (!gl_state.pointer_color_enabled)
- {
- gl_state.pointer_color_enabled = true;
- CHECKGLERROR
- qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR
- }
- if (gl_state.pointer_color_components != components || gl_state.pointer_color_gltype != gltype || gl_state.pointer_color_stride != stride || gl_state.pointer_color_pointer != pointer || gl_state.pointer_color_vertexbuffer != vertexbuffer || gl_state.pointer_color_offset != bufferoffset)
- {
- gl_state.pointer_color_components = components;
- gl_state.pointer_color_gltype = gltype;
- gl_state.pointer_color_stride = stride;
- gl_state.pointer_color_pointer = pointer;
- gl_state.pointer_color_vertexbuffer = vertexbuffer;
- gl_state.pointer_color_offset = bufferoffset;
- CHECKGLERROR
- GL_BindVBO(bufferobject);
- qglColorPointer(components, gltype, (GLsizei)stride, bufferobject ? (void *)bufferoffset : pointer);CHECKGLERROR
- }
- }
- else
- {
- // caller wants color array disabled
- if (gl_state.pointer_color_enabled)
- {
- gl_state.pointer_color_enabled = false;
- CHECKGLERROR
- qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
- // when color array is on the glColor gets trashed, set it again
- qglColor4f(gl_state.color4f[0], gl_state.color4f[1], gl_state.color4f[2], gl_state.color4f[3]);CHECKGLERROR
- }
- }
-#endif
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
CHECKGLERROR
gl_state.pointer_color_enabled = false;
CHECKGLERROR
qglDisableVertexAttribArray(GLSLATTRIB_COLOR);CHECKGLERROR
- // when color array is on the glColor gets trashed, set it again
+ // when color array is on the current color gets trashed, set it again
qglVertexAttrib4f(GLSLATTRIB_COLOR, gl_state.color4f[0], gl_state.color4f[1], gl_state.color4f[2], gl_state.color4f[3]);CHECKGLERROR
}
}
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
}
}
// that involve a valid bufferobject also supply a texcoord array
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- CHECKGLERROR
- if (pointer)
- {
- int bufferobject = vertexbuffer ? vertexbuffer->bufferobject : 0;
- // texture array unit is enabled, enable the array
- if (!unit->arrayenabled)
- {
- unit->arrayenabled = true;
- GL_ClientActiveTexture(unitnum);
- qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- }
- // texcoord array
- if (unit->pointer_texcoord_components != components || unit->pointer_texcoord_gltype != gltype || unit->pointer_texcoord_stride != stride || unit->pointer_texcoord_pointer != pointer || unit->pointer_texcoord_vertexbuffer != vertexbuffer || unit->pointer_texcoord_offset != bufferoffset)
- {
- unit->pointer_texcoord_components = components;
- unit->pointer_texcoord_gltype = gltype;
- unit->pointer_texcoord_stride = stride;
- unit->pointer_texcoord_pointer = pointer;
- unit->pointer_texcoord_vertexbuffer = vertexbuffer;
- unit->pointer_texcoord_offset = bufferoffset;
- GL_ClientActiveTexture(unitnum);
- GL_BindVBO(bufferobject);
- qglTexCoordPointer(components, gltype, (GLsizei)stride, bufferobject ? (void *)bufferoffset : pointer);CHECKGLERROR
- }
- }
- else
- {
- // texture array unit is disabled, disable the array
- if (unit->arrayenabled)
- {
- unit->arrayenabled = false;
- GL_ClientActiveTexture(unitnum);
- qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
- }
- }
-#endif
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
CHECKGLERROR
}
}
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
}
}
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
R_Mesh_TexBind(0, tex);
GL_ActiveTexture(0);CHECKGLERROR
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, tx, ty, sx, sy, width, height);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- IDirect3DSurface9 *currentsurface = NULL;
- IDirect3DSurface9 *texturesurface = NULL;
- RECT sourcerect;
- RECT destrect;
- sourcerect.left = sx;
- sourcerect.top = sy;
- sourcerect.right = sx + width;
- sourcerect.bottom = sy + height;
- destrect.left = tx;
- destrect.top = ty;
- destrect.right = tx + width;
- destrect.bottom = ty + height;
- if (!FAILED(IDirect3DTexture9_GetSurfaceLevel(((IDirect3DTexture9 *)tex->d3dtexture), 0, &texturesurface)))
- {
- if (!FAILED(IDirect3DDevice9_GetRenderTarget(vid_d3d9dev, 0, ¤tsurface)))
- {
- IDirect3DDevice9_StretchRect(vid_d3d9dev, currentsurface, &sourcerect, texturesurface, &destrect, D3DTEXF_NONE);
- IDirect3DSurface9_Release(currentsurface);
- }
- IDirect3DSurface9_Release(texturesurface);
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_CopyRectangleToTexture(tex->texnum, 0, tx, ty, sx, sy, width, height);
- break;
}
}
-#ifdef SUPPORTD3D
-int d3drswrap[16] = {D3DRS_WRAP0, D3DRS_WRAP1, D3DRS_WRAP2, D3DRS_WRAP3, D3DRS_WRAP4, D3DRS_WRAP5, D3DRS_WRAP6, D3DRS_WRAP7, D3DRS_WRAP8, D3DRS_WRAP9, D3DRS_WRAP10, D3DRS_WRAP11, D3DRS_WRAP12, D3DRS_WRAP13, D3DRS_WRAP14, D3DRS_WRAP15};
-#endif
-
void R_Mesh_ClearBindingsForTexture(int texnum)
{
gltextureunit_t *unit;
void R_Mesh_TexBind(unsigned int unitnum, rtexture_t *tex)
{
gltextureunit_t *unit = gl_state.units + unitnum;
- int tex2d, tex3d, texcubemap, texnum;
+ int texnum;
if (unitnum >= vid.teximageunits)
return;
if (unit->texture == tex)
case GL_TEXTURE_CUBE_MAP: if (unit->tcubemap != texnum) {GL_ActiveTexture(unitnum);unit->tcubemap = texnum;qglBindTexture(GL_TEXTURE_CUBE_MAP, unit->tcubemap);CHECKGLERROR}break;
}
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- unit->texture = tex;
- tex2d = 0;
- tex3d = 0;
- texcubemap = 0;
- if (tex)
- {
- texnum = R_GetTexture(tex);
- switch(tex->gltexturetypeenum)
- {
- case GL_TEXTURE_2D:
- tex2d = texnum;
- break;
- case GL_TEXTURE_3D:
- tex3d = texnum;
- break;
- case GL_TEXTURE_CUBE_MAP:
- texcubemap = texnum;
- break;
- }
- }
- // update 2d texture binding
- if (unit->t2d != tex2d)
- {
- GL_ActiveTexture(unitnum);
- if (tex2d)
- {
- if (unit->t2d == 0)
- {
- qglEnable(GL_TEXTURE_2D);CHECKGLERROR
- }
- }
- else
- {
- if (unit->t2d)
- {
- qglDisable(GL_TEXTURE_2D);CHECKGLERROR
- }
- }
- unit->t2d = tex2d;
- qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
- }
- // update 3d texture binding
- if (unit->t3d != tex3d)
- {
- GL_ActiveTexture(unitnum);
- if (tex3d)
- {
- if (unit->t3d == 0)
- {
- qglEnable(GL_TEXTURE_3D);CHECKGLERROR
- }
- }
- else
- {
- if (unit->t3d)
- {
- qglDisable(GL_TEXTURE_3D);CHECKGLERROR
- }
- }
- unit->t3d = tex3d;
- qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR
- }
- // update cubemap texture binding
- if (unit->tcubemap != texcubemap)
- {
- GL_ActiveTexture(unitnum);
- if (texcubemap)
- {
- if (unit->tcubemap == 0)
- {
- qglEnable(GL_TEXTURE_CUBE_MAP);CHECKGLERROR
- }
- }
- else
- {
- if (unit->tcubemap)
- {
- qglDisable(GL_TEXTURE_CUBE_MAP);CHECKGLERROR
- }
- }
- unit->tcubemap = texcubemap;
- qglBindTexture(GL_TEXTURE_CUBE_MAP, unit->tcubemap);CHECKGLERROR
- }
- break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- extern cvar_t gl_texture_anisotropy;
- if (!tex)
- {
- tex = r_texture_white;
- // not initialized enough yet...
- if (!tex)
- return;
- }
- // upload texture if needed
- R_GetTexture(tex);
- if (unit->texture == tex)
- return;
- unit->texture = tex;
- IDirect3DDevice9_SetTexture(vid_d3d9dev, unitnum, (IDirect3DBaseTexture9*)tex->d3dtexture);
- //IDirect3DDevice9_SetRenderState(vid_d3d9dev, d3drswrap[unitnum], (tex->flags & TEXF_CLAMP) ? (D3DWRAPCOORD_0 | D3DWRAPCOORD_1 | D3DWRAPCOORD_2) : 0);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_ADDRESSU, tex->d3daddressu);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_ADDRESSV, tex->d3daddressv);
- if (tex->d3daddressw)
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_ADDRESSW, tex->d3daddressw);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_MAGFILTER, tex->d3dmagfilter);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_MINFILTER, tex->d3dminfilter);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_MIPFILTER, tex->d3dmipfilter);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_MIPMAPLODBIAS, tex->d3dmipmaplodbias);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_MAXMIPLEVEL, tex->d3dmaxmiplevelfilter);
- IDirect3DDevice9_SetSamplerState(vid_d3d9dev, unitnum, D3DSAMP_MAXANISOTROPY, gl_texture_anisotropy.integer);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (!tex)
- {
- tex = r_texture_white;
- // not initialized enough yet...
- if (!tex)
- return;
- }
- texnum = R_GetTexture(tex);
- if (unit->texture == tex)
- return;
- unit->texture = tex;
- DPSOFTRAST_SetTexture(unitnum, texnum);
- break;
- }
-}
-
-void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix)
-{
- switch(vid.renderpath)
- {
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
-#ifdef GL_MODELVIEW
- if (matrix && matrix->m[3][3])
- {
- gltextureunit_t *unit = gl_state.units + unitnum;
- // texmatrix specified, check if it is different
- if (!unit->texmatrixenabled || memcmp(&unit->matrix, matrix, sizeof(matrix4x4_t)))
- {
- float glmatrix[16];
- unit->texmatrixenabled = true;
- unit->matrix = *matrix;
- CHECKGLERROR
- Matrix4x4_ToArrayFloatGL(&unit->matrix, glmatrix);
- GL_ActiveTexture(unitnum);
- qglMatrixMode(GL_TEXTURE);CHECKGLERROR
- qglLoadMatrixf(glmatrix);CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- }
- }
- else
- {
- // no texmatrix specified, revert to identity
- gltextureunit_t *unit = gl_state.units + unitnum;
- if (unit->texmatrixenabled)
- {
- unit->texmatrixenabled = false;
- unit->matrix = identitymatrix;
- CHECKGLERROR
- GL_ActiveTexture(unitnum);
- qglMatrixMode(GL_TEXTURE);CHECKGLERROR
- qglLoadIdentity();CHECKGLERROR
- qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- }
- }
-#endif
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- break;
- }
-}
-
-void R_Mesh_TexCombine(unsigned int unitnum, int combinergb, int combinealpha, int rgbscale, int alphascale)
-{
-#if defined(GL_TEXTURE_ENV) && !defined(USE_GLES2)
- gltextureunit_t *unit = gl_state.units + unitnum;
- CHECKGLERROR
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_GLES2:
- // do nothing
- break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- // GL_ARB_texture_env_combine
- if (!combinergb)
- combinergb = GL_MODULATE;
- if (!combinealpha)
- combinealpha = GL_MODULATE;
- if (!rgbscale)
- rgbscale = 1;
- if (!alphascale)
- alphascale = 1;
- if (combinergb != combinealpha || rgbscale != 1 || alphascale != 1)
- {
- if (combinergb == GL_DECAL)
- combinergb = GL_INTERPOLATE;
- if (unit->combine != GL_COMBINE)
- {
- unit->combine = GL_COMBINE;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);CHECKGLERROR
- qglTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE);CHECKGLERROR // for GL_INTERPOLATE mode
- }
- if (unit->combinergb != combinergb)
- {
- unit->combinergb = combinergb;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, unit->combinergb);CHECKGLERROR
- }
- if (unit->combinealpha != combinealpha)
- {
- unit->combinealpha = combinealpha;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, unit->combinealpha);CHECKGLERROR
- }
- if (unit->rgbscale != rgbscale)
- {
- unit->rgbscale = rgbscale;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, unit->rgbscale);CHECKGLERROR
- }
- if (unit->alphascale != alphascale)
- {
- unit->alphascale = alphascale;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, unit->alphascale);CHECKGLERROR
- }
- }
- else
- {
- if (unit->combine != combinergb)
- {
- unit->combine = combinergb;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combine);CHECKGLERROR
- }
- }
- break;
- case RENDERPATH_GL11:
- // normal GL texenv
- if (!combinergb)
- combinergb = GL_MODULATE;
- if (unit->combine != combinergb)
- {
- unit->combine = combinergb;
- GL_ActiveTexture(unitnum);
- qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combine);CHECKGLERROR
- }
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- break;
- }
-#endif
-}
-
-void R_Mesh_ResetTextureState(void)
-{
- unsigned int unitnum;
-
- BACKENDACTIVECHECK
-
- for (unitnum = 0;unitnum < vid.teximageunits;unitnum++)
- R_Mesh_TexBind(unitnum, NULL);
- for (unitnum = 0;unitnum < vid.texarrayunits;unitnum++)
- R_Mesh_TexCoordPointer(unitnum, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_GLES2:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- for (unitnum = 0;unitnum < vid.texunits;unitnum++)
- {
- R_Mesh_TexCombine(unitnum, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexMatrix(unitnum, NULL);
- }
- break;
- }
-}
-
-
-
-#ifdef SUPPORTD3D
-//#define r_vertex3f_d3d9fvf (D3DFVF_XYZ)
-//#define r_vertexgeneric_d3d9fvf (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)
-//#define r_vertexmesh_d3d9fvf (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX5 | D3DFVF_TEXCOORDSIZE1(3) | D3DFVF_TEXCOORDSIZE2(3) | D3DFVF_TEXCOORDSIZE3(3))
-
-D3DVERTEXELEMENT9 r_vertex3f_d3d9elements[] =
-{
- {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
- D3DDECL_END()
-};
-
-D3DVERTEXELEMENT9 r_vertexgeneric_d3d9elements[] =
-{
- {0, (int)((size_t)&((r_vertexgeneric_t *)0)->vertex3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
- {0, (int)((size_t)&((r_vertexgeneric_t *)0)->color4f ), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
- {0, (int)((size_t)&((r_vertexgeneric_t *)0)->texcoord2f), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
- D3DDECL_END()
-};
-
-D3DVERTEXELEMENT9 r_vertexmesh_d3d9elements[] =
-{
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->vertex3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->color4f ), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->texcoordtexture2f ), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->svector3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->tvector3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->normal3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->texcoordlightmap2f), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->skeletalindex4ub ), D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 6},
- {0, (int)((size_t)&((r_vertexmesh_t *)0)->skeletalweight4ub ), D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 7},
- D3DDECL_END()
-};
-
-IDirect3DVertexDeclaration9 *r_vertex3f_d3d9decl;
-IDirect3DVertexDeclaration9 *r_vertexgeneric_d3d9decl;
-IDirect3DVertexDeclaration9 *r_vertexmesh_d3d9decl;
-#endif
-
-static void R_Mesh_InitVertexDeclarations(void)
-{
-#ifdef SUPPORTD3D
- r_vertex3f_d3d9decl = NULL;
- r_vertexgeneric_d3d9decl = NULL;
- r_vertexmesh_d3d9decl = NULL;
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_GL13:
- case RENDERPATH_GL11:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
- break;
- case RENDERPATH_D3D9:
- IDirect3DDevice9_CreateVertexDeclaration(vid_d3d9dev, r_vertex3f_d3d9elements, &r_vertex3f_d3d9decl);
- IDirect3DDevice9_CreateVertexDeclaration(vid_d3d9dev, r_vertexgeneric_d3d9elements, &r_vertexgeneric_d3d9decl);
- IDirect3DDevice9_CreateVertexDeclaration(vid_d3d9dev, r_vertexmesh_d3d9elements, &r_vertexmesh_d3d9decl);
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
- }
-#endif
-}
-
-static void R_Mesh_DestroyVertexDeclarations(void)
-{
-#ifdef SUPPORTD3D
- if (r_vertex3f_d3d9decl)
- IDirect3DVertexDeclaration9_Release(r_vertex3f_d3d9decl);
- r_vertex3f_d3d9decl = NULL;
- if (r_vertexgeneric_d3d9decl)
- IDirect3DVertexDeclaration9_Release(r_vertexgeneric_d3d9decl);
- r_vertexgeneric_d3d9decl = NULL;
- if (r_vertexmesh_d3d9decl)
- IDirect3DVertexDeclaration9_Release(r_vertexmesh_d3d9decl);
- r_vertexmesh_d3d9decl = NULL;
-#endif
-}
-
-void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *vertexbuffer, int bufferoffset)
-{
- // upload temporary vertexbuffer for this rendering
- if (!gl_state.usevbo_staticvertex)
- vertexbuffer = NULL;
- if (!vertexbuffer && gl_state.usevbo_dynamicvertex)
- vertexbuffer = R_BufferData_Store(numvertices * sizeof(float[3]), (void *)vertex3f, R_BUFFERDATA_VERTEX, &bufferoffset);
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_GLES2:
- if (vertexbuffer)
+ }
+}
+
+void R_Mesh_ResetTextureState(void)
+{
+ unsigned int unitnum;
+
+ BACKENDACTIVECHECK
+
+ for (unitnum = 0;unitnum < vid.teximageunits;unitnum++)
+ R_Mesh_TexBind(unitnum, NULL);
+ for (unitnum = 0;unitnum < vid.texarrayunits;unitnum++)
+ R_Mesh_TexCoordPointer(unitnum, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
+}
+
+
+
+void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *vertexbuffer, int bufferoffset)
+{
+ // upload temporary vertexbuffer for this rendering
+ if (!gl_state.usevbo_staticvertex)
+ vertexbuffer = NULL;
+ if (!vertexbuffer && gl_state.usevbo_dynamicvertex)
+ vertexbuffer = R_BufferData_Store(numvertices * sizeof(float[3]), (void *)vertex3f, R_BUFFERDATA_VERTEX, &bufferoffset);
+ switch(vid.renderpath)
+ {
+ case RENDERPATH_GL20:
+ case RENDERPATH_GLES2:
+ if (vertexbuffer)
{
R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, bufferoffset);
R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0);
R_Mesh_TexCoordPointer(7, 4, GL_UNSIGNED_BYTE, sizeof(unsigned char[4]), NULL, NULL, 0);
}
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (vertexbuffer)
- {
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, bufferoffset);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- }
- else
- {
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, 0);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- }
- break;
- case RENDERPATH_GL11:
- if (vertexbuffer)
- {
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, bufferoffset);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- }
- else
- {
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, vertexbuffer, 0);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- }
- break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetVertexDeclaration(vid_d3d9dev, r_vertex3f_d3d9decl);
- if (vertexbuffer)
- IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, bufferoffset, sizeof(float[3]));
- else
- IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, NULL, 0, 0);
- gl_state.d3dvertexbuffer = (void *)vertexbuffer;
- gl_state.d3dvertexdata = (void *)vertex3f;
- gl_state.d3dvertexsize = sizeof(float[3]);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_SetVertexPointer(vertex3f, sizeof(float[3]));
- DPSOFTRAST_SetColorPointer(NULL, 0);
- DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(1, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(2, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(3, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(4, 2, sizeof(float[2]), NULL);
- break;
}
}
return;
}
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (!vid.useinterleavedarrays)
- {
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, NULL, 0);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), color4f, NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), texcoord2f, NULL, 0);
- if (vid.texunits >= 2)
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- if (vid.texunits >= 3)
- R_Mesh_TexCoordPointer(2, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- return;
- }
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_SetVertexPointer(vertex3f, sizeof(float[3]));
- DPSOFTRAST_SetColorPointer(color4f, sizeof(float[4]));
- DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(float[2]), texcoord2f);
- DPSOFTRAST_SetTexCoordPointer(1, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(2, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(3, 2, sizeof(float[2]), NULL);
- DPSOFTRAST_SetTexCoordPointer(4, 2, sizeof(float[2]), NULL);
- return;
}
// no quick path for this case, convert to vertex structs
R_Mesh_TexCoordPointer(7, 4, GL_UNSIGNED_BYTE, sizeof(unsigned char[4]), NULL, NULL, 0);
}
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (vertexbuffer)
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex));
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex));
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex));
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- }
- else
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0);
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , NULL, 0);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- }
- break;
- case RENDERPATH_GL11:
- if (vertexbuffer)
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex));
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex));
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex));
- }
- else
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0);
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , NULL, 0);
- }
- break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetVertexDeclaration(vid_d3d9dev, r_vertexgeneric_d3d9decl);
- if (vertexbuffer)
- IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, bufferoffset, sizeof(*vertex));
- else
- IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, NULL, 0, 0);
- gl_state.d3dvertexbuffer = (void *)vertexbuffer;
- gl_state.d3dvertexdata = (void *)vertex;
- gl_state.d3dvertexsize = sizeof(*vertex);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_SetVertexPointer(vertex->vertex3f, sizeof(*vertex));
- DPSOFTRAST_SetColorPointer(vertex->color4f, sizeof(*vertex));
- DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(*vertex), vertex->texcoord2f);
- DPSOFTRAST_SetTexCoordPointer(1, 2, sizeof(*vertex), NULL);
- DPSOFTRAST_SetTexCoordPointer(2, 2, sizeof(*vertex), NULL);
- DPSOFTRAST_SetTexCoordPointer(3, 2, sizeof(*vertex), NULL);
- DPSOFTRAST_SetTexCoordPointer(4, 2, sizeof(*vertex), NULL);
- break;
}
}
return;
}
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (!vid.useinterleavedarrays)
- {
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), vertex3f, NULL, 0);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), color4f, NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), texcoordtexture2f, NULL, 0);
- if (vid.texunits >= 2)
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), texcoordlightmap2f, NULL, 0);
- if (vid.texunits >= 3)
- R_Mesh_TexCoordPointer(2, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
- return;
- }
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_SetVertexPointer(vertex3f, sizeof(float[3]));
- DPSOFTRAST_SetColorPointer(color4f, sizeof(float[4]));
- DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(float[2]), texcoordtexture2f);
- DPSOFTRAST_SetTexCoordPointer(1, 3, sizeof(float[3]), svector3f);
- DPSOFTRAST_SetTexCoordPointer(2, 3, sizeof(float[3]), tvector3f);
- DPSOFTRAST_SetTexCoordPointer(3, 3, sizeof(float[3]), normal3f);
- DPSOFTRAST_SetTexCoordPointer(4, 2, sizeof(float[2]), texcoordlightmap2f);
- return;
}
vertex = R_Mesh_PrepareVertices_Mesh_Lock(numvertices);
R_Mesh_TexCoordPointer(7, 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->skeletalweight4ub , NULL, 0);
}
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (vertexbuffer)
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex));
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex));
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex));
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordlightmap2f - (unsigned char *)vertex));
- }
- else
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0);
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , NULL, 0);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, NULL, 0);
- }
- break;
- case RENDERPATH_GL11:
- if (vertexbuffer)
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex));
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex));
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, bufferoffset + (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex));
- }
- else
- {
- R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0);
- R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , NULL, 0);
- }
- break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetVertexDeclaration(vid_d3d9dev, r_vertexmesh_d3d9decl);
- if (vertexbuffer)
- IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, (IDirect3DVertexBuffer9*)vertexbuffer->devicebuffer, bufferoffset, sizeof(*vertex));
- else
- IDirect3DDevice9_SetStreamSource(vid_d3d9dev, 0, NULL, 0, 0);
- gl_state.d3dvertexbuffer = (void *)vertexbuffer;
- gl_state.d3dvertexdata = (void *)vertex;
- gl_state.d3dvertexsize = sizeof(*vertex);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_SetVertexPointer(vertex->vertex3f, sizeof(*vertex));
- DPSOFTRAST_SetColorPointer(vertex->color4f, sizeof(*vertex));
- DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(*vertex), vertex->texcoordtexture2f);
- DPSOFTRAST_SetTexCoordPointer(1, 3, sizeof(*vertex), vertex->svector3f);
- DPSOFTRAST_SetTexCoordPointer(2, 3, sizeof(*vertex), vertex->tvector3f);
- DPSOFTRAST_SetTexCoordPointer(3, 3, sizeof(*vertex), vertex->normal3f);
- DPSOFTRAST_SetTexCoordPointer(4, 2, sizeof(*vertex), vertex->texcoordlightmap2f);
- break;
}
}
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_BLENDOP, D3DBLENDOP_SUBTRACT);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_BlendSubtract(true);
- break;
}
}
else
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglBlendEquationEXT(GL_FUNC_ADD);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- IDirect3DDevice9_SetRenderState(vid_d3d9dev, D3DRS_BLENDOP, D3DBLENDOP_ADD);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_BlendSubtract(false);
- break;
}
}
}
ih = (int)(0.5 + height * ((float)r_refdef.view.height / vid_conheight.integer));
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
- case RENDERPATH_SOFT:
GL_Scissor(ix, vid.height - iy - ih, iw, ih);
break;
- case RENDERPATH_D3D9:
- GL_Scissor(ix, iy, iw, ih);
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
GL_ScissorTest(true);
#include "ft2.h"
#include "csprogs.h"
#include "cl_video.h"
-#include "dpsoftrast.h"
#include "cl_collision.h"
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-extern LPDIRECT3DDEVICE9 vid_d3d9dev;
-#endif
-
#ifdef WIN32
// Enable NVIDIA High Performance Graphics while using Integrated Graphics.
#ifdef __cplusplus
0
};
-const char *builtinhlslshaderstrings[] =
-{
-#include "shader_hlsl.h"
-0
-};
-
//=======================================================================================================================================================
typedef struct shaderpermutationinfo_s
{"combined", "glsl", builtinshaderstrings, "#define MODE_DEFERREDGEOMETRY\n", " deferredgeometry"},
{"combined", "glsl", builtinshaderstrings, "#define MODE_DEFERREDLIGHTSOURCE\n", " deferredlightsource"},
},
- // SHADERLANGUAGE_HLSL
- {
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_GENERIC\n", " generic"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_POSTPROCESS\n", " postprocess"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_DEPTH_OR_SHADOW\n", " depth/shadow"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_FLATCOLOR\n", " flatcolor"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_VERTEXCOLOR\n", " vertexcolor"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTMAP\n", " lightmap"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_FAKELIGHT\n", " fakelight"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " lightdirectionmap_modelspace"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP\n", " lightdirectionmap_forced_lightmap"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR\n", " lightdirectionmap_forced_vertexcolor"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTDIRECTION\n", " lightdirection"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_LIGHTSOURCE\n", " lightsource"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_REFRACTION\n", " refraction"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_WATER\n", " water"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_DEFERREDGEOMETRY\n", " deferredgeometry"},
- {"combined", "hlsl", builtinhlslshaderstrings, "#define MODE_DEFERREDLIGHTSOURCE\n", " deferredlightsource"},
- },
};
struct r_glsl_permutation_s;
CHECKGLERROR
}
-#ifdef SUPPORTD3D
-
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-extern LPDIRECT3DDEVICE9 vid_d3d9dev;
-extern D3DCAPS9 vid_d3d9caps;
-#endif
-
-struct r_hlsl_permutation_s;
-typedef struct r_hlsl_permutation_s
-{
- /// hash lookup data
- struct r_hlsl_permutation_s *hashnext;
- unsigned int mode;
- dpuint64 permutation;
-
- /// indicates if we have tried compiling this permutation already
- qboolean compiled;
- /// NULL if compilation failed
- IDirect3DVertexShader9 *vertexshader;
- IDirect3DPixelShader9 *pixelshader;
-}
-r_hlsl_permutation_t;
-
-typedef enum D3DVSREGISTER_e
-{
- D3DVSREGISTER_TexMatrix = 0, // float4x4
- D3DVSREGISTER_BackgroundTexMatrix = 4, // float4x4
- D3DVSREGISTER_ModelViewProjectionMatrix = 8, // float4x4
- D3DVSREGISTER_ModelViewMatrix = 12, // float4x4
- D3DVSREGISTER_ShadowMapMatrix = 16, // float4x4
- D3DVSREGISTER_ModelToLight = 20, // float4x4
- D3DVSREGISTER_EyePosition = 24,
- D3DVSREGISTER_FogPlane = 25,
- D3DVSREGISTER_LightDir = 26,
- D3DVSREGISTER_LightPosition = 27,
-}
-D3DVSREGISTER_t;
-
-typedef enum D3DPSREGISTER_e
-{
- D3DPSREGISTER_Alpha = 0,
- D3DPSREGISTER_BloomBlur_Parameters = 1,
- D3DPSREGISTER_ClientTime = 2,
- D3DPSREGISTER_Color_Ambient = 3,
- D3DPSREGISTER_Color_Diffuse = 4,
- D3DPSREGISTER_Color_Specular = 5,
- D3DPSREGISTER_Color_Glow = 6,
- D3DPSREGISTER_Color_Pants = 7,
- D3DPSREGISTER_Color_Shirt = 8,
- D3DPSREGISTER_DeferredColor_Ambient = 9,
- D3DPSREGISTER_DeferredColor_Diffuse = 10,
- D3DPSREGISTER_DeferredColor_Specular = 11,
- D3DPSREGISTER_DeferredMod_Diffuse = 12,
- D3DPSREGISTER_DeferredMod_Specular = 13,
- D3DPSREGISTER_DistortScaleRefractReflect = 14,
- D3DPSREGISTER_EyePosition = 15, // unused
- D3DPSREGISTER_FogColor = 16,
- D3DPSREGISTER_FogHeightFade = 17,
- D3DPSREGISTER_FogPlane = 18,
- D3DPSREGISTER_FogPlaneViewDist = 19,
- D3DPSREGISTER_FogRangeRecip = 20,
- D3DPSREGISTER_LightColor = 21,
- D3DPSREGISTER_LightDir = 22, // unused
- D3DPSREGISTER_LightPosition = 23,
- D3DPSREGISTER_OffsetMapping_ScaleSteps = 24,
- D3DPSREGISTER_PixelSize = 25,
- D3DPSREGISTER_ReflectColor = 26,
- D3DPSREGISTER_ReflectFactor = 27,
- D3DPSREGISTER_ReflectOffset = 28,
- D3DPSREGISTER_RefractColor = 29,
- D3DPSREGISTER_Saturation = 30,
- D3DPSREGISTER_ScreenCenterRefractReflect = 31,
- D3DPSREGISTER_ScreenScaleRefractReflect = 32,
- D3DPSREGISTER_ScreenToDepth = 33,
- D3DPSREGISTER_ShadowMap_Parameters = 34,
- D3DPSREGISTER_ShadowMap_TextureScale = 35,
- D3DPSREGISTER_SpecularPower = 36,
- D3DPSREGISTER_UserVec1 = 37,
- D3DPSREGISTER_UserVec2 = 38,
- D3DPSREGISTER_UserVec3 = 39,
- D3DPSREGISTER_UserVec4 = 40,
- D3DPSREGISTER_ViewTintColor = 41,
- D3DPSREGISTER_PixelToScreenTexCoord = 42,
- D3DPSREGISTER_BloomColorSubtract = 43,
- D3DPSREGISTER_ViewToLight = 44, // float4x4
- D3DPSREGISTER_ModelToReflectCube = 48, // float4x4
- D3DPSREGISTER_NormalmapScrollBlend = 52,
- D3DPSREGISTER_OffsetMapping_LodDistance = 53,
- D3DPSREGISTER_OffsetMapping_Bias = 54,
- // next at 54
-}
-D3DPSREGISTER_t;
-
-/// information about each possible shader permutation
-r_hlsl_permutation_t *r_hlsl_permutationhash[SHADERMODE_COUNT][SHADERPERMUTATION_HASHSIZE];
-/// currently selected permutation
-r_hlsl_permutation_t *r_hlsl_permutation;
-/// storage for permutations linked in the hash table
-memexpandablearray_t r_hlsl_permutationarray;
-
-static r_hlsl_permutation_t *R_HLSL_FindPermutation(unsigned int mode, dpuint64 permutation)
-{
- //unsigned int hashdepth = 0;
- unsigned int hashindex = (permutation * 0x1021) & (SHADERPERMUTATION_HASHSIZE - 1);
- r_hlsl_permutation_t *p;
- for (p = r_hlsl_permutationhash[mode][hashindex];p;p = p->hashnext)
- {
- if (p->mode == mode && p->permutation == permutation)
- {
- //if (hashdepth > 10)
- // Con_Printf("R_HLSL_FindPermutation: Warning: %i:%i has hashdepth %i\n", mode, permutation, hashdepth);
- return p;
- }
- //hashdepth++;
- }
- p = (r_hlsl_permutation_t*)Mem_ExpandableArray_AllocRecord(&r_hlsl_permutationarray);
- p->mode = mode;
- p->permutation = permutation;
- p->hashnext = r_hlsl_permutationhash[mode][hashindex];
- r_hlsl_permutationhash[mode][hashindex] = p;
- //if (hashdepth > 10)
- // Con_Printf("R_HLSL_FindPermutation: Warning: %i:%i has hashdepth %i\n", mode, permutation, hashdepth);
- return p;
-}
-
-#include <d3dx9.h>
-//#include <d3dx9shader.h>
-//#include <d3dx9mesh.h>
-
-static void R_HLSL_CacheShader(r_hlsl_permutation_t *p, const char *cachename, const char *vertstring, const char *fragstring)
-{
- DWORD *vsbin = NULL;
- DWORD *psbin = NULL;
- fs_offset_t vsbinsize;
- fs_offset_t psbinsize;
-// IDirect3DVertexShader9 *vs = NULL;
-// IDirect3DPixelShader9 *ps = NULL;
- ID3DXBuffer *vslog = NULL;
- ID3DXBuffer *vsbuffer = NULL;
- ID3DXConstantTable *vsconstanttable = NULL;
- ID3DXBuffer *pslog = NULL;
- ID3DXBuffer *psbuffer = NULL;
- ID3DXConstantTable *psconstanttable = NULL;
- int vsresult = 0;
- int psresult = 0;
- char temp[MAX_INPUTLINE];
- const char *vsversion = "vs_3_0", *psversion = "ps_3_0";
- char vabuf[1024];
- qboolean debugshader = gl_paranoid.integer != 0;
- if (p->permutation & SHADERPERMUTATION_OFFSETMAPPING) {vsversion = "vs_3_0";psversion = "ps_3_0";}
- if (p->permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) {vsversion = "vs_3_0";psversion = "ps_3_0";}
- if (!debugshader)
- {
- vsbin = (DWORD *)FS_LoadFile(va(vabuf, sizeof(vabuf), "%s.vsbin", cachename), r_main_mempool, true, &vsbinsize);
- psbin = (DWORD *)FS_LoadFile(va(vabuf, sizeof(vabuf), "%s.psbin", cachename), r_main_mempool, true, &psbinsize);
- }
- if ((!vsbin && vertstring) || (!psbin && fragstring))
- {
- const char* dllnames_d3dx9 [] =
- {
- "d3dx9_43.dll",
- "d3dx9_42.dll",
- "d3dx9_41.dll",
- "d3dx9_40.dll",
- "d3dx9_39.dll",
- "d3dx9_38.dll",
- "d3dx9_37.dll",
- "d3dx9_36.dll",
- "d3dx9_35.dll",
- "d3dx9_34.dll",
- "d3dx9_33.dll",
- "d3dx9_32.dll",
- "d3dx9_31.dll",
- "d3dx9_30.dll",
- "d3dx9_29.dll",
- "d3dx9_28.dll",
- "d3dx9_27.dll",
- "d3dx9_26.dll",
- "d3dx9_25.dll",
- "d3dx9_24.dll",
- NULL
- };
- dllhandle_t d3dx9_dll = NULL;
- HRESULT (WINAPI *qD3DXCompileShaderFromFileA)(LPCSTR pSrcFile, CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable);
- HRESULT (WINAPI *qD3DXPreprocessShader)(LPCSTR pSrcData, UINT SrcDataSize, CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPD3DXBUFFER* ppShaderText, LPD3DXBUFFER* ppErrorMsgs);
- HRESULT (WINAPI *qD3DXCompileShader)(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable);
- dllfunction_t d3dx9_dllfuncs[] =
- {
- {"D3DXCompileShaderFromFileA", (void **) &qD3DXCompileShaderFromFileA},
- {"D3DXPreprocessShader", (void **) &qD3DXPreprocessShader},
- {"D3DXCompileShader", (void **) &qD3DXCompileShader},
- {NULL, NULL}
- };
- // LordHavoc: the June 2010 SDK lacks these macros to make ID3DXBuffer usable in C, and to make it work in both C and C++ the macros are needed...
-#ifndef ID3DXBuffer_GetBufferPointer
-#if !defined(__cplusplus) || defined(CINTERFACE)
-#define ID3DXBuffer_GetBufferPointer(p) (p)->lpVtbl->GetBufferPointer(p)
-#define ID3DXBuffer_GetBufferSize(p) (p)->lpVtbl->GetBufferSize(p)
-#define ID3DXBuffer_Release(p) (p)->lpVtbl->Release(p)
-#else
-#define ID3DXBuffer_GetBufferPointer(p) (p)->GetBufferPointer()
-#define ID3DXBuffer_GetBufferSize(p) (p)->GetBufferSize()
-#define ID3DXBuffer_Release(p) (p)->Release()
-#endif
-#endif
- if (Sys_LoadLibrary(dllnames_d3dx9, &d3dx9_dll, d3dx9_dllfuncs))
- {
- DWORD shaderflags = 0;
- if (debugshader)
- shaderflags = D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION;
- vsbin = (DWORD *)Mem_Realloc(tempmempool, vsbin, 0);
- psbin = (DWORD *)Mem_Realloc(tempmempool, psbin, 0);
- if (vertstring && vertstring[0])
- {
- if (debugshader)
- {
- FS_WriteFile(va(vabuf, sizeof(vabuf), "%s_vs.fx", cachename), vertstring, strlen(vertstring));
- vsresult = qD3DXCompileShaderFromFileA(va(vabuf, sizeof(vabuf), "%s/%s_vs.fx", fs_gamedir, cachename), NULL, NULL, "main", vsversion, shaderflags, &vsbuffer, &vslog, &vsconstanttable);
- }
- else
- vsresult = qD3DXCompileShader(vertstring, (unsigned int)strlen(vertstring), NULL, NULL, "main", vsversion, shaderflags, &vsbuffer, &vslog, &vsconstanttable);
- if (vsbuffer)
- {
- vsbinsize = ID3DXBuffer_GetBufferSize(vsbuffer);
- vsbin = (DWORD *)Mem_Alloc(tempmempool, vsbinsize);
- memcpy(vsbin, ID3DXBuffer_GetBufferPointer(vsbuffer), vsbinsize);
- ID3DXBuffer_Release(vsbuffer);
- }
- if (vslog)
- {
- strlcpy(temp, (const char *)ID3DXBuffer_GetBufferPointer(vslog), min(sizeof(temp), ID3DXBuffer_GetBufferSize(vslog)));
- Con_DPrintf("HLSL vertex shader compile output for %s follows:\n%s\n", cachename, temp);
- ID3DXBuffer_Release(vslog);
- }
- }
- if (fragstring && fragstring[0])
- {
- if (debugshader)
- {
- FS_WriteFile(va(vabuf, sizeof(vabuf), "%s_ps.fx", cachename), fragstring, strlen(fragstring));
- psresult = qD3DXCompileShaderFromFileA(va(vabuf, sizeof(vabuf), "%s/%s_ps.fx", fs_gamedir, cachename), NULL, NULL, "main", psversion, shaderflags, &psbuffer, &pslog, &psconstanttable);
- }
- else
- psresult = qD3DXCompileShader(fragstring, (unsigned int)strlen(fragstring), NULL, NULL, "main", psversion, shaderflags, &psbuffer, &pslog, &psconstanttable);
- if (psbuffer)
- {
- psbinsize = ID3DXBuffer_GetBufferSize(psbuffer);
- psbin = (DWORD *)Mem_Alloc(tempmempool, psbinsize);
- memcpy(psbin, ID3DXBuffer_GetBufferPointer(psbuffer), psbinsize);
- ID3DXBuffer_Release(psbuffer);
- }
- if (pslog)
- {
- strlcpy(temp, (const char *)ID3DXBuffer_GetBufferPointer(pslog), min(sizeof(temp), ID3DXBuffer_GetBufferSize(pslog)));
- Con_DPrintf("HLSL pixel shader compile output for %s follows:\n%s\n", cachename, temp);
- ID3DXBuffer_Release(pslog);
- }
- }
- Sys_UnloadLibrary(&d3dx9_dll);
- }
- else
- Con_DPrintf("Unable to compile shader - D3DXCompileShader function not found\n");
- }
- if (vsbin && psbin)
- {
- vsresult = IDirect3DDevice9_CreateVertexShader(vid_d3d9dev, vsbin, &p->vertexshader);
- if (FAILED(vsresult))
- Con_DPrintf("HLSL CreateVertexShader failed for %s (hresult = %8x)\n", cachename, vsresult);
- psresult = IDirect3DDevice9_CreatePixelShader(vid_d3d9dev, psbin, &p->pixelshader);
- if (FAILED(psresult))
- Con_DPrintf("HLSL CreatePixelShader failed for %s (hresult = %8x)\n", cachename, psresult);
- }
- // free the shader data
- vsbin = (DWORD *)Mem_Realloc(tempmempool, vsbin, 0);
- psbin = (DWORD *)Mem_Realloc(tempmempool, psbin, 0);
-}
-
-static void R_HLSL_CompilePermutation(r_hlsl_permutation_t *p, unsigned int mode, dpuint64 permutation)
-{
- int i;
- shadermodeinfo_t *modeinfo = &shadermodeinfo[SHADERLANGUAGE_HLSL][mode];
- int vertstring_length = 0;
- int geomstring_length = 0;
- int fragstring_length = 0;
- char *t;
- char *sourcestring;
- char *vertstring, *geomstring, *fragstring;
- char permutationname[256];
- char cachename[256];
- int vertstrings_count = 0;
- int geomstrings_count = 0;
- int fragstrings_count = 0;
- const char *vertstrings_list[32+5+SHADERSTATICPARMS_COUNT+1];
- const char *geomstrings_list[32+5+SHADERSTATICPARMS_COUNT+1];
- const char *fragstrings_list[32+5+SHADERSTATICPARMS_COUNT+1];
-
- if (p->compiled)
- return;
- p->compiled = true;
- p->vertexshader = NULL;
- p->pixelshader = NULL;
-
- permutationname[0] = 0;
- cachename[0] = 0;
- sourcestring = ShaderModeInfo_GetShaderText(modeinfo, true, false);
-
- strlcat(permutationname, modeinfo->filename, sizeof(permutationname));
- strlcat(cachename, "hlsl/", sizeof(cachename));
-
- // define HLSL so that the shader can tell apart the HLSL compiler and the Cg compiler
- vertstrings_count = 0;
- geomstrings_count = 0;
- fragstrings_count = 0;
- vertstrings_list[vertstrings_count++] = "#define HLSL\n";
- geomstrings_list[geomstrings_count++] = "#define HLSL\n";
- fragstrings_list[fragstrings_count++] = "#define HLSL\n";
-
- // the first pretext is which type of shader to compile as
- // (later these will all be bound together as a program object)
- vertstrings_list[vertstrings_count++] = "#define VERTEX_SHADER\n";
- geomstrings_list[geomstrings_count++] = "#define GEOMETRY_SHADER\n";
- fragstrings_list[fragstrings_count++] = "#define FRAGMENT_SHADER\n";
-
- // the second pretext is the mode (for example a light source)
- vertstrings_list[vertstrings_count++] = modeinfo->pretext;
- geomstrings_list[geomstrings_count++] = modeinfo->pretext;
- fragstrings_list[fragstrings_count++] = modeinfo->pretext;
- strlcat(permutationname, modeinfo->name, sizeof(permutationname));
- strlcat(cachename, modeinfo->name, sizeof(cachename));
-
- // now add all the permutation pretexts
- for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
- {
- if (permutation & (1ll<<i))
- {
- vertstrings_list[vertstrings_count++] = shaderpermutationinfo[i].pretext;
- geomstrings_list[geomstrings_count++] = shaderpermutationinfo[i].pretext;
- fragstrings_list[fragstrings_count++] = shaderpermutationinfo[i].pretext;
- strlcat(permutationname, shaderpermutationinfo[i].name, sizeof(permutationname));
- strlcat(cachename, shaderpermutationinfo[i].name, sizeof(cachename));
- }
- else
- {
- // keep line numbers correct
- vertstrings_list[vertstrings_count++] = "\n";
- geomstrings_list[geomstrings_count++] = "\n";
- fragstrings_list[fragstrings_count++] = "\n";
- }
- }
-
- // add static parms
- R_CompileShader_AddStaticParms(mode, permutation);
- memcpy(vertstrings_list + vertstrings_count, shaderstaticparmstrings_list, sizeof(*vertstrings_list) * shaderstaticparms_count);
- vertstrings_count += shaderstaticparms_count;
- memcpy(geomstrings_list + geomstrings_count, shaderstaticparmstrings_list, sizeof(*vertstrings_list) * shaderstaticparms_count);
- geomstrings_count += shaderstaticparms_count;
- memcpy(fragstrings_list + fragstrings_count, shaderstaticparmstrings_list, sizeof(*vertstrings_list) * shaderstaticparms_count);
- fragstrings_count += shaderstaticparms_count;
-
- // replace spaces in the cachename with _ characters
- for (i = 0;cachename[i];i++)
- if (cachename[i] == ' ')
- cachename[i] = '_';
-
- // now append the shader text itself
- vertstrings_list[vertstrings_count++] = sourcestring;
- geomstrings_list[geomstrings_count++] = sourcestring;
- fragstrings_list[fragstrings_count++] = sourcestring;
-
- vertstring_length = 0;
- for (i = 0;i < vertstrings_count;i++)
- vertstring_length += (int)strlen(vertstrings_list[i]);
- vertstring = t = (char *)Mem_Alloc(tempmempool, vertstring_length + 1);
- for (i = 0;i < vertstrings_count;t += (int)strlen(vertstrings_list[i]), i++)
- memcpy(t, vertstrings_list[i], strlen(vertstrings_list[i]));
-
- geomstring_length = 0;
- for (i = 0;i < geomstrings_count;i++)
- geomstring_length += (int)strlen(geomstrings_list[i]);
- geomstring = t = (char *)Mem_Alloc(tempmempool, geomstring_length + 1);
- for (i = 0;i < geomstrings_count;t += (int)strlen(geomstrings_list[i]), i++)
- memcpy(t, geomstrings_list[i], strlen(geomstrings_list[i]));
-
- fragstring_length = 0;
- for (i = 0;i < fragstrings_count;i++)
- fragstring_length += (int)strlen(fragstrings_list[i]);
- fragstring = t = (char *)Mem_Alloc(tempmempool, fragstring_length + 1);
- for (i = 0;i < fragstrings_count;t += (int)strlen(fragstrings_list[i]), i++)
- memcpy(t, fragstrings_list[i], strlen(fragstrings_list[i]));
-
- // try to load the cached shader, or generate one
- R_HLSL_CacheShader(p, cachename, vertstring, fragstring);
-
- if ((p->vertexshader || !vertstring[0]) && (p->pixelshader || !fragstring[0]))
- Con_DPrintf("^5HLSL shader %s compiled.\n", permutationname);
- else
- Con_Printf("^1HLSL shader %s failed! some features may not work properly.\n", permutationname);
-
- // free the strings
- if (vertstring)
- Mem_Free(vertstring);
- if (geomstring)
- Mem_Free(geomstring);
- if (fragstring)
- Mem_Free(fragstring);
- if (sourcestring)
- Mem_Free(sourcestring);
-}
-
-static inline void hlslVSSetParameter16f(D3DVSREGISTER_t r, const float *a) {IDirect3DDevice9_SetVertexShaderConstantF(vid_d3d9dev, r, a, 4);}
-static inline void hlslVSSetParameter4fv(D3DVSREGISTER_t r, const float *a) {IDirect3DDevice9_SetVertexShaderConstantF(vid_d3d9dev, r, a, 1);}
-static inline void hlslVSSetParameter4f(D3DVSREGISTER_t r, float x, float y, float z, float w) {float temp[4];Vector4Set(temp, x, y, z, w);IDirect3DDevice9_SetVertexShaderConstantF(vid_d3d9dev, r, temp, 1);}
-static inline void hlslVSSetParameter3f(D3DVSREGISTER_t r, float x, float y, float z) {float temp[4];Vector4Set(temp, x, y, z, 0);IDirect3DDevice9_SetVertexShaderConstantF(vid_d3d9dev, r, temp, 1);}
-static inline void hlslVSSetParameter2f(D3DVSREGISTER_t r, float x, float y) {float temp[4];Vector4Set(temp, x, y, 0, 0);IDirect3DDevice9_SetVertexShaderConstantF(vid_d3d9dev, r, temp, 1);}
-static inline void hlslVSSetParameter1f(D3DVSREGISTER_t r, float x) {float temp[4];Vector4Set(temp, x, 0, 0, 0);IDirect3DDevice9_SetVertexShaderConstantF(vid_d3d9dev, r, temp, 1);}
-
-static inline void hlslPSSetParameter16f(D3DPSREGISTER_t r, const float *a) {IDirect3DDevice9_SetPixelShaderConstantF(vid_d3d9dev, r, a, 4);}
-static inline void hlslPSSetParameter4fv(D3DPSREGISTER_t r, const float *a) {IDirect3DDevice9_SetPixelShaderConstantF(vid_d3d9dev, r, a, 1);}
-static inline void hlslPSSetParameter4f(D3DPSREGISTER_t r, float x, float y, float z, float w) {float temp[4];Vector4Set(temp, x, y, z, w);IDirect3DDevice9_SetPixelShaderConstantF(vid_d3d9dev, r, temp, 1);}
-static inline void hlslPSSetParameter3f(D3DPSREGISTER_t r, float x, float y, float z) {float temp[4];Vector4Set(temp, x, y, z, 0);IDirect3DDevice9_SetPixelShaderConstantF(vid_d3d9dev, r, temp, 1);}
-static inline void hlslPSSetParameter2f(D3DPSREGISTER_t r, float x, float y) {float temp[4];Vector4Set(temp, x, y, 0, 0);IDirect3DDevice9_SetPixelShaderConstantF(vid_d3d9dev, r, temp, 1);}
-static inline void hlslPSSetParameter1f(D3DPSREGISTER_t r, float x) {float temp[4];Vector4Set(temp, x, 0, 0, 0);IDirect3DDevice9_SetPixelShaderConstantF(vid_d3d9dev, r, temp, 1);}
-
-void R_SetupShader_SetPermutationHLSL(unsigned int mode, dpuint64 permutation)
-{
- r_hlsl_permutation_t *perm = R_HLSL_FindPermutation(mode, permutation);
- if (r_hlsl_permutation != perm)
- {
- r_hlsl_permutation = perm;
- if (!r_hlsl_permutation->vertexshader && !r_hlsl_permutation->pixelshader)
- {
- if (!r_hlsl_permutation->compiled)
- R_HLSL_CompilePermutation(perm, mode, permutation);
- if (!r_hlsl_permutation->vertexshader && !r_hlsl_permutation->pixelshader)
- {
- // remove features until we find a valid permutation
- int i;
- for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
- {
- // reduce i more quickly whenever it would not remove any bits
- dpuint64 j = 1ll<<(SHADERPERMUTATION_COUNT-1-i);
- if (!(permutation & j))
- continue;
- permutation -= j;
- r_hlsl_permutation = R_HLSL_FindPermutation(mode, permutation);
- if (!r_hlsl_permutation->compiled)
- R_HLSL_CompilePermutation(perm, mode, permutation);
- if (r_hlsl_permutation->vertexshader || r_hlsl_permutation->pixelshader)
- break;
- }
- if (i >= SHADERPERMUTATION_COUNT)
- {
- //Con_Printf("Could not find a working HLSL shader for permutation %s %s\n", shadermodeinfo[mode].filename, shadermodeinfo[mode].pretext);
- r_hlsl_permutation = R_HLSL_FindPermutation(mode, permutation);
- return; // no bit left to clear, entire mode is broken
- }
- }
- }
- IDirect3DDevice9_SetVertexShader(vid_d3d9dev, r_hlsl_permutation->vertexshader);
- IDirect3DDevice9_SetPixelShader(vid_d3d9dev, r_hlsl_permutation->pixelshader);
- }
- hlslVSSetParameter16f(D3DVSREGISTER_ModelViewProjectionMatrix, gl_modelviewprojection16f);
- hlslVSSetParameter16f(D3DVSREGISTER_ModelViewMatrix, gl_modelview16f);
- hlslPSSetParameter1f(D3DPSREGISTER_ClientTime, cl.time);
-}
-#endif
-
-static void R_SetupShader_SetPermutationSoft(unsigned int mode, dpuint64 permutation)
-{
- DPSOFTRAST_SetShader(mode, permutation, r_shadow_glossexact.integer);
- DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1, 1, false, gl_modelviewprojection16f);
- DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ModelViewMatrixM1, 1, false, gl_modelview16f);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_ClientTime, cl.time);
-}
-
void R_GLSL_Restart_f(void)
{
unsigned int i, limit;
switch(vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- r_hlsl_permutation_t *p;
- r_hlsl_permutation = NULL;
- limit = (unsigned int)Mem_ExpandableArray_IndexRange(&r_hlsl_permutationarray);
- for (i = 0;i < limit;i++)
- {
- if ((p = (r_hlsl_permutation_t*)Mem_ExpandableArray_RecordAtIndex(&r_hlsl_permutationarray, i)))
- {
- if (p->vertexshader)
- IDirect3DVertexShader9_Release(p->vertexshader);
- if (p->pixelshader)
- IDirect3DPixelShader9_Release(p->pixelshader);
- Mem_ExpandableArray_FreeRecord(&r_hlsl_permutationarray, (void*)p);
- }
- }
- memset(r_hlsl_permutationhash, 0, sizeof(r_hlsl_permutationhash));
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
{
memset(r_glsl_permutationhash, 0, sizeof(r_glsl_permutationhash));
}
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- break;
- case RENDERPATH_SOFT:
- break;
}
}
GL_AlphaToCoverage(false);
switch (vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- R_SetupShader_SetPermutationHLSL(SHADERMODE_GENERIC, permutation);
- R_Mesh_TexBind(GL20TU_FIRST , first );
- R_Mesh_TexBind(GL20TU_SECOND, second);
- if (permutation & SHADERPERMUTATION_GAMMARAMPS)
- R_Mesh_TexBind(GL20TU_GAMMARAMPS, r_texture_gammaramps);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
R_SetupShader_SetPermutationGLSL(SHADERMODE_GENERIC, permutation);
if (r_glsl_permutation->tex_Texture_GammaRamps >= 0)
R_Mesh_TexBind(r_glsl_permutation->tex_Texture_GammaRamps, r_texture_gammaramps);
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- R_Mesh_TexBind(0, first );
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexMatrix(0, NULL);
- R_Mesh_TexBind(1, second);
- if (second)
- {
- R_Mesh_TexCombine(1, texturemode, texturemode, rgbscale, 1);
- R_Mesh_TexMatrix(1, NULL);
- }
- break;
- case RENDERPATH_GL11:
- R_Mesh_TexBind(0, first );
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexMatrix(0, NULL);
- break;
- case RENDERPATH_SOFT:
- R_SetupShader_SetPermutationSoft(SHADERMODE_GENERIC, permutation);
- R_Mesh_TexBind(GL20TU_FIRST , first );
- R_Mesh_TexBind(GL20TU_SECOND, second);
- break;
}
}
GL_AlphaToCoverage(false);
switch (vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- R_SetupShader_SetPermutationHLSL(SHADERMODE_DEPTH_OR_SHADOW, permutation);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
R_SetupShader_SetPermutationGLSL(SHADERMODE_DEPTH_OR_SHADOW, permutation);
if (r_glsl_permutation->ubiloc_Skeletal_Transform12_UniformBlock >= 0 && rsurface.batchskeletaltransform3x4buffer) qglBindBufferRange(GL_UNIFORM_BUFFER, r_glsl_permutation->ubibind_Skeletal_Transform12_UniformBlock, rsurface.batchskeletaltransform3x4buffer->bufferobject, rsurface.batchskeletaltransform3x4offset, rsurface.batchskeletaltransform3x4size);
#endif
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- R_Mesh_TexBind(0, 0);
- R_Mesh_TexBind(1, 0);
- break;
- case RENDERPATH_GL11:
- R_Mesh_TexBind(0, 0);
- break;
- case RENDERPATH_SOFT:
- R_SetupShader_SetPermutationSoft(SHADERMODE_DEPTH_OR_SHADOW, permutation);
- break;
}
}
permutation |= SHADERPERMUTATION_FOGALPHAHACK;
switch(vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- RSurf_PrepareVerticesForBatch(BATCHNEED_VERTEXMESH_VERTEX | BATCHNEED_VERTEXMESH_NORMAL | BATCHNEED_VERTEXMESH_VECTOR | (rsurface.modellightmapcolor4f ? BATCHNEED_VERTEXMESH_VERTEXCOLOR : 0) | BATCHNEED_VERTEXMESH_TEXCOORD | (rsurface.uselightmaptexture ? BATCHNEED_VERTEXMESH_LIGHTMAP : 0) | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist);
- R_Mesh_PrepareVertices_Mesh(rsurface.batchnumvertices, rsurface.batchvertexmesh, rsurface.batchvertexmesh_vertexbuffer, rsurface.batchvertexmesh_bufferoffset);
- R_SetupShader_SetPermutationHLSL(mode, permutation);
- Matrix4x4_ToArrayFloatGL(&rsurface.matrix, m16f);hlslPSSetParameter16f(D3DPSREGISTER_ModelToReflectCube, m16f);
- if (mode == SHADERMODE_LIGHTSOURCE)
- {
- Matrix4x4_ToArrayFloatGL(&rsurface.entitytolight, m16f);hlslVSSetParameter16f(D3DVSREGISTER_ModelToLight, m16f);
- hlslVSSetParameter3f(D3DVSREGISTER_LightPosition, rsurface.entitylightorigin[0], rsurface.entitylightorigin[1], rsurface.entitylightorigin[2]);
- }
- else
- {
- if (mode == SHADERMODE_LIGHTDIRECTION)
- {
- hlslVSSetParameter3f(D3DVSREGISTER_LightDir, t->render_modellight_lightdir[0], t->render_modellight_lightdir[1], t->render_modellight_lightdir[2]);
- }
- }
- Matrix4x4_ToArrayFloatGL(&t->currenttexmatrix, m16f);hlslVSSetParameter16f(D3DVSREGISTER_TexMatrix, m16f);
- Matrix4x4_ToArrayFloatGL(&t->currentbackgroundtexmatrix, m16f);hlslVSSetParameter16f(D3DVSREGISTER_BackgroundTexMatrix, m16f);
- Matrix4x4_ToArrayFloatGL(&r_shadow_shadowmapmatrix, m16f);hlslVSSetParameter16f(D3DVSREGISTER_ShadowMapMatrix, m16f);
- hlslVSSetParameter3f(D3DVSREGISTER_EyePosition, rsurface.localvieworigin[0], rsurface.localvieworigin[1], rsurface.localvieworigin[2]);
- hlslVSSetParameter4f(D3DVSREGISTER_FogPlane, rsurface.fogplane[0], rsurface.fogplane[1], rsurface.fogplane[2], rsurface.fogplane[3]);
-
- if (mode == SHADERMODE_LIGHTSOURCE)
- {
- hlslPSSetParameter3f(D3DPSREGISTER_LightPosition, rsurface.entitylightorigin[0], rsurface.entitylightorigin[1], rsurface.entitylightorigin[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_LightColor, 1, 1, 1); // DEPRECATED
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Ambient, rtlightambient[0], rtlightambient[1], rtlightambient[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Diffuse, rtlightdiffuse[0], rtlightdiffuse[1], rtlightdiffuse[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Specular, rtlightspecular[0], rtlightspecular[1], rtlightspecular[2]);
-
- // additive passes are only darkened by fog, not tinted
- hlslPSSetParameter3f(D3DPSREGISTER_FogColor, 0, 0, 0);
- hlslPSSetParameter1f(D3DPSREGISTER_SpecularPower, t->specularpower * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f);
- }
- else
- {
- hlslPSSetParameter3f(D3DPSREGISTER_DeferredMod_Diffuse, t->render_rtlight_diffuse[0], t->render_rtlight_diffuse[1], t->render_rtlight_diffuse[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_DeferredMod_Specular, t->render_rtlight_specular[0], t->render_rtlight_specular[1], t->render_rtlight_specular[2]);
- if (mode == SHADERMODE_FLATCOLOR)
- {
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Ambient, t->render_modellight_ambient[0], t->render_modellight_ambient[1], t->render_modellight_ambient[2]);
- }
- else if (mode == SHADERMODE_LIGHTDIRECTION)
- {
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Ambient, t->render_modellight_ambient[0], t->render_modellight_ambient[1], t->render_modellight_ambient[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Diffuse, t->render_modellight_diffuse[0], t->render_modellight_diffuse[1], t->render_modellight_diffuse[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Specular, t->render_modellight_specular[0], t->render_modellight_specular[1], t->render_modellight_specular[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_LightColor, 1, 1, 1); // DEPRECATED
- hlslPSSetParameter3f(D3DPSREGISTER_LightDir, t->render_modellight_lightdir[0], t->render_modellight_lightdir[1], t->render_modellight_lightdir[2]);
- }
- else
- {
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Ambient, t->render_lightmap_ambient[0], t->render_lightmap_ambient[1], t->render_lightmap_ambient[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Diffuse, t->render_lightmap_diffuse[0], t->render_lightmap_diffuse[1], t->render_lightmap_diffuse[2]);
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Specular, t->render_lightmap_specular[0], t->render_lightmap_specular[1], t->render_lightmap_specular[2]);
- }
- // additive passes are only darkened by fog, not tinted
- if(blendfuncflags & BLENDFUNC_ALLOWS_FOG_HACK0)
- hlslPSSetParameter3f(D3DPSREGISTER_FogColor, 0, 0, 0);
- else
- hlslPSSetParameter3f(D3DPSREGISTER_FogColor, r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2]);
- hlslPSSetParameter4f(D3DPSREGISTER_DistortScaleRefractReflect, r_water_refractdistort.value * t->refractfactor, r_water_refractdistort.value * t->refractfactor, r_water_reflectdistort.value * t->reflectfactor, r_water_reflectdistort.value * t->reflectfactor);
- hlslPSSetParameter4f(D3DPSREGISTER_ScreenScaleRefractReflect, r_fb.water.screenscale[0], r_fb.water.screenscale[1], r_fb.water.screenscale[0], r_fb.water.screenscale[1]);
- hlslPSSetParameter4f(D3DPSREGISTER_ScreenCenterRefractReflect, r_fb.water.screencenter[0], r_fb.water.screencenter[1], r_fb.water.screencenter[0], r_fb.water.screencenter[1]);
- hlslPSSetParameter4f(D3DPSREGISTER_RefractColor, t->refractcolor4f[0], t->refractcolor4f[1], t->refractcolor4f[2], t->refractcolor4f[3] * t->currentalpha);
- hlslPSSetParameter4f(D3DPSREGISTER_ReflectColor, t->reflectcolor4f[0], t->reflectcolor4f[1], t->reflectcolor4f[2], t->reflectcolor4f[3] * t->currentalpha);
- hlslPSSetParameter1f(D3DPSREGISTER_ReflectFactor, t->reflectmax - t->reflectmin);
- hlslPSSetParameter1f(D3DPSREGISTER_ReflectOffset, t->reflectmin);
- hlslPSSetParameter1f(D3DPSREGISTER_SpecularPower, (t->specularpower - 1.0f) * (r_shadow_glossexact.integer ? 0.25f : 1.0f));
- if (mode == SHADERMODE_WATER)
- hlslPSSetParameter2f(D3DPSREGISTER_NormalmapScrollBlend, t->r_water_waterscroll[0], t->r_water_waterscroll[1]);
- }
- if (permutation & SHADERPERMUTATION_SHADOWMAPORTHO)
- {
- hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_TextureScale, r_shadow_modelshadowmap_texturescale[0], r_shadow_modelshadowmap_texturescale[1], r_shadow_modelshadowmap_texturescale[2], r_shadow_modelshadowmap_texturescale[3]);
- hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_Parameters, r_shadow_modelshadowmap_parameters[0], r_shadow_modelshadowmap_parameters[1], r_shadow_modelshadowmap_parameters[2], r_shadow_modelshadowmap_parameters[3]);
- }
- else
- {
- hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_TextureScale, r_shadow_lightshadowmap_texturescale[0], r_shadow_lightshadowmap_texturescale[1], r_shadow_lightshadowmap_texturescale[2], r_shadow_lightshadowmap_texturescale[3]);
- hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_Parameters, r_shadow_lightshadowmap_parameters[0], r_shadow_lightshadowmap_parameters[1], r_shadow_lightshadowmap_parameters[2], r_shadow_lightshadowmap_parameters[3]);
- }
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Glow, t->render_glowmod[0], t->render_glowmod[1], t->render_glowmod[2]);
- hlslPSSetParameter1f(D3DPSREGISTER_Alpha, t->currentalpha * ((t->basematerialflags & MATERIALFLAG_WATERSHADER && r_fb.water.enabled && !r_refdef.view.isoverlay) ? t->r_water_wateralpha : 1));
- hlslPSSetParameter3f(D3DPSREGISTER_EyePosition, rsurface.localvieworigin[0], rsurface.localvieworigin[1], rsurface.localvieworigin[2]);
- if (t->pantstexture)
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Pants, t->render_colormap_pants[0], t->render_colormap_pants[1], t->render_colormap_pants[2]);
- else
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Pants, 0, 0, 0);
- if (t->shirttexture)
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Shirt, t->render_colormap_shirt[0], t->render_colormap_shirt[1], t->render_colormap_shirt[2]);
- else
- hlslPSSetParameter3f(D3DPSREGISTER_Color_Shirt, 0, 0, 0);
- hlslPSSetParameter4f(D3DPSREGISTER_FogPlane, rsurface.fogplane[0], rsurface.fogplane[1], rsurface.fogplane[2], rsurface.fogplane[3]);
- hlslPSSetParameter1f(D3DPSREGISTER_FogPlaneViewDist, rsurface.fogplaneviewdist);
- hlslPSSetParameter1f(D3DPSREGISTER_FogRangeRecip, rsurface.fograngerecip);
- hlslPSSetParameter1f(D3DPSREGISTER_FogHeightFade, rsurface.fogheightfade);
- hlslPSSetParameter4f(D3DPSREGISTER_OffsetMapping_ScaleSteps,
- r_glsl_offsetmapping_scale.value*t->offsetscale,
- max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
- 1.0 / max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
- max(1, r_glsl_offsetmapping_reliefmapping_refinesteps.integer)
- );
- hlslPSSetParameter1f(D3DPSREGISTER_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer * r_refdef.view.quality);
- hlslPSSetParameter1f(D3DPSREGISTER_OffsetMapping_Bias, t->offsetbias);
- hlslPSSetParameter2f(D3DPSREGISTER_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
- hlslPSSetParameter2f(D3DPSREGISTER_PixelToScreenTexCoord, 1.0f/vid.width, 1.0/vid.height);
-
- R_Mesh_TexBind(GL20TU_NORMAL , t->nmaptexture );
- R_Mesh_TexBind(GL20TU_COLOR , t->basetexture );
- R_Mesh_TexBind(GL20TU_GLOSS , t->glosstexture );
- R_Mesh_TexBind(GL20TU_GLOW , t->glowtexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_NORMAL , t->backgroundnmaptexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_COLOR , t->backgroundbasetexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_GLOSS , t->backgroundglosstexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_GLOW , t->backgroundglowtexture );
- if (permutation & SHADERPERMUTATION_COLORMAPPING) R_Mesh_TexBind(GL20TU_PANTS , t->pantstexture );
- if (permutation & SHADERPERMUTATION_COLORMAPPING) R_Mesh_TexBind(GL20TU_SHIRT , t->shirttexture );
- if (permutation & SHADERPERMUTATION_REFLECTCUBE) R_Mesh_TexBind(GL20TU_REFLECTMASK , t->reflectmasktexture );
- if (permutation & SHADERPERMUTATION_REFLECTCUBE) R_Mesh_TexBind(GL20TU_REFLECTCUBE , t->reflectcubetexture ? t->reflectcubetexture : r_texture_whitecube);
- if (permutation & SHADERPERMUTATION_FOGHEIGHTTEXTURE) R_Mesh_TexBind(GL20TU_FOGHEIGHTTEXTURE , r_texture_fogheighttexture );
- if (permutation & (SHADERPERMUTATION_FOGINSIDE | SHADERPERMUTATION_FOGOUTSIDE)) R_Mesh_TexBind(GL20TU_FOGMASK , r_texture_fogattenuation );
- R_Mesh_TexBind(GL20TU_LIGHTMAP , rsurface.lightmaptexture ? rsurface.lightmaptexture : r_texture_white);
- R_Mesh_TexBind(GL20TU_DELUXEMAP , rsurface.deluxemaptexture ? rsurface.deluxemaptexture : r_texture_blanknormalmap);
- if (rsurface.rtlight ) R_Mesh_TexBind(GL20TU_ATTENUATION , r_shadow_attenuationgradienttexture );
- if (rsurfacepass == RSURFPASS_BACKGROUND)
- {
- R_Mesh_TexBind(GL20TU_REFRACTION , waterplane->rt_refraction ? waterplane->rt_refraction->colortexture[0] : r_texture_black);
- if(mode == SHADERMODE_GENERIC) R_Mesh_TexBind(GL20TU_FIRST , waterplane->rt_camera ? waterplane->rt_camera->colortexture[0] : r_texture_black);
- R_Mesh_TexBind(GL20TU_REFLECTION , waterplane->rt_reflection ? waterplane->rt_reflection->colortexture[0] : r_texture_black);
- }
- else
- {
- if (permutation & SHADERPERMUTATION_REFLECTION ) R_Mesh_TexBind(GL20TU_REFLECTION , waterplane->rt_reflection ? waterplane->rt_reflection->colortexture[0] : r_texture_black);
- }
-// if (rsurfacepass == RSURFPASS_DEFERREDLIGHT ) R_Mesh_TexBind(GL20TU_SCREENNORMALMAP , r_shadow_prepassgeometrynormalmaptexture );
- if (permutation & SHADERPERMUTATION_DEFERREDLIGHTMAP ) R_Mesh_TexBind(GL20TU_SCREENDIFFUSE , r_shadow_prepasslightingdiffusetexture );
- if (permutation & SHADERPERMUTATION_DEFERREDLIGHTMAP ) R_Mesh_TexBind(GL20TU_SCREENSPECULAR , r_shadow_prepasslightingspeculartexture );
- if (rsurface.rtlight || (r_shadow_usingshadowmaportho && !(rsurface.ent_flags & RENDER_NOSELFSHADOW)))
- {
- R_Mesh_TexBind(GL20TU_SHADOWMAP2D, r_shadow_shadowmap2ddepthtexture);
- if (rsurface.rtlight)
- {
- if (permutation & SHADERPERMUTATION_CUBEFILTER ) R_Mesh_TexBind(GL20TU_CUBE , rsurface.rtlight->currentcubemap );
- if (permutation & SHADERPERMUTATION_SHADOWMAPVSDCT ) R_Mesh_TexBind(GL20TU_CUBEPROJECTION , r_shadow_shadowmapvsdcttexture );
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
if (!vid.useinterleavedarrays)
if (r_glsl_permutation->tex_Texture_BounceGrid >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_BounceGrid, r_shadow_bouncegrid_state.texture);
CHECKGLERROR
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- break;
- case RENDERPATH_SOFT:
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_VECTOR | (rsurface.modellightmapcolor4f ? BATCHNEED_ARRAY_VERTEXCOLOR : 0) | BATCHNEED_ARRAY_TEXCOORD | (rsurface.uselightmaptexture ? BATCHNEED_ARRAY_LIGHTMAP : 0) | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist);
- R_Mesh_PrepareVertices_Mesh_Arrays(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.batchsvector3f, rsurface.batchtvector3f, rsurface.batchnormal3f, rsurface.batchlightmapcolor4f, rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordlightmap2f);
- R_SetupShader_SetPermutationSoft(mode, permutation);
- {Matrix4x4_ToArrayFloatGL(&rsurface.matrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ModelToReflectCubeM1, 1, false, m16f);}
- if (mode == SHADERMODE_LIGHTSOURCE)
- {
- {Matrix4x4_ToArrayFloatGL(&rsurface.entitytolight, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ModelToLightM1, 1, false, m16f);}
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_LightPosition, rsurface.entitylightorigin[0], rsurface.entitylightorigin[1], rsurface.entitylightorigin[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_LightColor, 1, 1, 1); // DEPRECATED
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Ambient, rtlightambient[0], rtlightambient[1], rtlightambient[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Diffuse, rtlightdiffuse[0], rtlightdiffuse[1], rtlightdiffuse[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Specular, rtlightspecular[0], rtlightspecular[1], rtlightspecular[2]);
-
- // additive passes are only darkened by fog, not tinted
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_FogColor, 0, 0, 0);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_SpecularPower, t->specularpower * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f);
- }
- else
- {
- if (mode == SHADERMODE_FLATCOLOR)
- {
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Ambient, t->render_modellight_ambient[0], t->render_modellight_ambient[1], t->render_modellight_ambient[2]);
- }
- else if (mode == SHADERMODE_LIGHTDIRECTION)
- {
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Ambient, t->render_modellight_ambient[0], t->render_modellight_ambient[1], t->render_modellight_ambient[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Diffuse, t->render_modellight_diffuse[0], t->render_modellight_diffuse[1], t->render_modellight_diffuse[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Specular, t->render_modellight_specular[0], t->render_modellight_specular[1], t->render_modellight_specular[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_LightColor, 1, 1, 1); // DEPRECATED
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_LightDir, t->render_modellight_lightdir[0], t->render_modellight_lightdir[1], t->render_modellight_lightdir[2]);
- }
- else
- {
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Ambient, t->render_lightmap_ambient[0], t->render_lightmap_ambient[1], t->render_lightmap_ambient[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Diffuse, t->render_lightmap_diffuse[0], t->render_lightmap_diffuse[1], t->render_lightmap_diffuse[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Specular, t->render_lightmap_specular[0], t->render_lightmap_specular[1], t->render_lightmap_specular[2]);
- }
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_DeferredMod_Diffuse, t->render_rtlight_diffuse[0], t->render_rtlight_diffuse[1], t->render_rtlight_diffuse[2]);
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_DeferredMod_Specular, t->render_rtlight_specular[0], t->render_rtlight_specular[1], t->render_rtlight_specular[2]);
- // additive passes are only darkened by fog, not tinted
- if(blendfuncflags & BLENDFUNC_ALLOWS_FOG_HACK0)
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_FogColor, 0, 0, 0);
- else
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_FogColor, r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_DistortScaleRefractReflect, r_water_refractdistort.value * t->refractfactor, r_water_refractdistort.value * t->refractfactor, r_water_reflectdistort.value * t->reflectfactor, r_water_reflectdistort.value * t->reflectfactor);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ScreenScaleRefractReflect, r_fb.water.screenscale[0], r_fb.water.screenscale[1], r_fb.water.screenscale[0], r_fb.water.screenscale[1]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ScreenCenterRefractReflect, r_fb.water.screencenter[0], r_fb.water.screencenter[1], r_fb.water.screencenter[0], r_fb.water.screencenter[1]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_RefractColor, t->refractcolor4f[0], t->refractcolor4f[1], t->refractcolor4f[2], t->refractcolor4f[3] * t->currentalpha);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ReflectColor, t->reflectcolor4f[0], t->reflectcolor4f[1], t->reflectcolor4f[2], t->reflectcolor4f[3] * t->currentalpha);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_ReflectFactor, t->reflectmax - t->reflectmin);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_ReflectOffset, t->reflectmin);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_SpecularPower, t->specularpower * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f);
- DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_NormalmapScrollBlend, t->r_water_waterscroll[0], t->r_water_waterscroll[1]);
- }
- {Matrix4x4_ToArrayFloatGL(&t->currenttexmatrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_TexMatrixM1, 1, false, m16f);}
- {Matrix4x4_ToArrayFloatGL(&t->currentbackgroundtexmatrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_BackgroundTexMatrixM1, 1, false, m16f);}
- {Matrix4x4_ToArrayFloatGL(&r_shadow_shadowmapmatrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ShadowMapMatrixM1, 1, false, m16f);}
- if (permutation & SHADERPERMUTATION_SHADOWMAPORTHO)
- {
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ShadowMap_TextureScale, r_shadow_modelshadowmap_texturescale[0], r_shadow_modelshadowmap_texturescale[1], r_shadow_modelshadowmap_texturescale[2], r_shadow_modelshadowmap_texturescale[3]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ShadowMap_Parameters, r_shadow_modelshadowmap_parameters[0], r_shadow_modelshadowmap_parameters[1], r_shadow_modelshadowmap_parameters[2], r_shadow_modelshadowmap_parameters[3]);
- }
- else
- {
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ShadowMap_TextureScale, r_shadow_lightshadowmap_texturescale[0], r_shadow_lightshadowmap_texturescale[1], r_shadow_lightshadowmap_texturescale[2], r_shadow_lightshadowmap_texturescale[3]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ShadowMap_Parameters, r_shadow_lightshadowmap_parameters[0], r_shadow_lightshadowmap_parameters[1], r_shadow_lightshadowmap_parameters[2], r_shadow_lightshadowmap_parameters[3]);
- }
-
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Glow, t->render_glowmod[0], t->render_glowmod[1], t->render_glowmod[2]);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_Alpha, t->currentalpha * ((t->basematerialflags & MATERIALFLAG_WATERSHADER && r_fb.water.enabled && !r_refdef.view.isoverlay) ? t->r_water_wateralpha : 1));
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_EyePosition, rsurface.localvieworigin[0], rsurface.localvieworigin[1], rsurface.localvieworigin[2]);
- if (DPSOFTRAST_UNIFORM_Color_Pants >= 0)
- {
- if (t->pantstexture)
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Pants, t->render_colormap_pants[0], t->render_colormap_pants[1], t->render_colormap_pants[2]);
- else
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Pants, 0, 0, 0);
- }
- if (DPSOFTRAST_UNIFORM_Color_Shirt >= 0)
- {
- if (t->shirttexture)
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Shirt, t->render_colormap_shirt[0], t->render_colormap_shirt[1], t->render_colormap_shirt[2]);
- else
- DPSOFTRAST_Uniform3f(DPSOFTRAST_UNIFORM_Color_Shirt, 0, 0, 0);
- }
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_FogPlane, rsurface.fogplane[0], rsurface.fogplane[1], rsurface.fogplane[2], rsurface.fogplane[3]);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_FogPlaneViewDist, rsurface.fogplaneviewdist);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_FogRangeRecip, rsurface.fograngerecip);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_FogHeightFade, rsurface.fogheightfade);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_OffsetMapping_ScaleSteps,
- r_glsl_offsetmapping_scale.value*t->offsetscale,
- max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
- 1.0 / max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
- max(1, r_glsl_offsetmapping_reliefmapping_refinesteps.integer)
- );
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer * r_refdef.view.quality);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_OffsetMapping_Bias, t->offsetbias);
- DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
- DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
-
- R_Mesh_TexBind(GL20TU_NORMAL , t->nmaptexture );
- R_Mesh_TexBind(GL20TU_COLOR , t->basetexture );
- R_Mesh_TexBind(GL20TU_GLOSS , t->glosstexture );
- R_Mesh_TexBind(GL20TU_GLOW , t->glowtexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_NORMAL , t->backgroundnmaptexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_COLOR , t->backgroundbasetexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_GLOSS , t->backgroundglosstexture );
- if (permutation & SHADERPERMUTATION_VERTEXTEXTUREBLEND) R_Mesh_TexBind(GL20TU_SECONDARY_GLOW , t->backgroundglowtexture );
- if (permutation & SHADERPERMUTATION_COLORMAPPING) R_Mesh_TexBind(GL20TU_PANTS , t->pantstexture );
- if (permutation & SHADERPERMUTATION_COLORMAPPING) R_Mesh_TexBind(GL20TU_SHIRT , t->shirttexture );
- if (permutation & SHADERPERMUTATION_REFLECTCUBE) R_Mesh_TexBind(GL20TU_REFLECTMASK , t->reflectmasktexture );
- if (permutation & SHADERPERMUTATION_REFLECTCUBE) R_Mesh_TexBind(GL20TU_REFLECTCUBE , t->reflectcubetexture ? t->reflectcubetexture : r_texture_whitecube);
- if (permutation & SHADERPERMUTATION_FOGHEIGHTTEXTURE) R_Mesh_TexBind(GL20TU_FOGHEIGHTTEXTURE , r_texture_fogheighttexture );
- if (permutation & (SHADERPERMUTATION_FOGINSIDE | SHADERPERMUTATION_FOGOUTSIDE)) R_Mesh_TexBind(GL20TU_FOGMASK , r_texture_fogattenuation );
- R_Mesh_TexBind(GL20TU_LIGHTMAP , rsurface.lightmaptexture ? rsurface.lightmaptexture : r_texture_white);
- R_Mesh_TexBind(GL20TU_DELUXEMAP , rsurface.deluxemaptexture ? rsurface.deluxemaptexture : r_texture_blanknormalmap);
- if (rsurface.rtlight ) R_Mesh_TexBind(GL20TU_ATTENUATION , r_shadow_attenuationgradienttexture );
- if (rsurfacepass == RSURFPASS_BACKGROUND)
- {
- R_Mesh_TexBind(GL20TU_REFRACTION , waterplane->rt_refraction ? waterplane->rt_refraction->colortexture[0] : r_texture_black);
- if(mode == SHADERMODE_GENERIC) R_Mesh_TexBind(GL20TU_FIRST , waterplane->rt_camera ? waterplane->rt_camera->colortexture[0] : r_texture_black);
- R_Mesh_TexBind(GL20TU_REFLECTION , waterplane->rt_reflection ? waterplane->rt_reflection->colortexture[0] : r_texture_black);
- }
- else
- {
- if (permutation & SHADERPERMUTATION_REFLECTION ) R_Mesh_TexBind(GL20TU_REFLECTION , waterplane->rt_reflection ? waterplane->rt_reflection->colortexture[0] : r_texture_black);
- }
-// if (rsurfacepass == RSURFPASS_DEFERREDLIGHT ) R_Mesh_TexBind(GL20TU_SCREENNORMALMAP , r_shadow_prepassgeometrynormalmaptexture );
- if (permutation & SHADERPERMUTATION_DEFERREDLIGHTMAP ) R_Mesh_TexBind(GL20TU_SCREENDIFFUSE , r_shadow_prepasslightingdiffusetexture );
- if (permutation & SHADERPERMUTATION_DEFERREDLIGHTMAP ) R_Mesh_TexBind(GL20TU_SCREENSPECULAR , r_shadow_prepasslightingspeculartexture );
- if (rsurface.rtlight || (r_shadow_usingshadowmaportho && !(rsurface.ent_flags & RENDER_NOSELFSHADOW)))
- {
- R_Mesh_TexBind(GL20TU_SHADOWMAP2D, r_shadow_shadowmap2ddepthtexture);
- if (rsurface.rtlight)
- {
- if (permutation & SHADERPERMUTATION_CUBEFILTER ) R_Mesh_TexBind(GL20TU_CUBE , rsurface.rtlight->currentcubemap );
- if (permutation & SHADERPERMUTATION_SHADOWMAPVSDCT ) R_Mesh_TexBind(GL20TU_CUBEPROJECTION , r_shadow_shadowmapvsdcttexture );
- }
- }
- break;
}
}
Matrix4x4_ToArrayFloatGL(&viewtolight, viewtolight16f);
switch(vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- R_SetupShader_SetPermutationHLSL(mode, permutation);
- hlslPSSetParameter3f(D3DPSREGISTER_LightPosition, viewlightorigin[0], viewlightorigin[1], viewlightorigin[2]);
- hlslPSSetParameter16f(D3DPSREGISTER_ViewToLight, viewtolight16f);
- hlslPSSetParameter3f(D3DPSREGISTER_DeferredColor_Ambient , lightcolorbase[0] * ambientscale , lightcolorbase[1] * ambientscale , lightcolorbase[2] * ambientscale );
- hlslPSSetParameter3f(D3DPSREGISTER_DeferredColor_Diffuse , lightcolorbase[0] * diffusescale , lightcolorbase[1] * diffusescale , lightcolorbase[2] * diffusescale );
- hlslPSSetParameter3f(D3DPSREGISTER_DeferredColor_Specular, lightcolorbase[0] * specularscale, lightcolorbase[1] * specularscale, lightcolorbase[2] * specularscale);
- hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_TextureScale, r_shadow_lightshadowmap_texturescale[0], r_shadow_lightshadowmap_texturescale[1], r_shadow_lightshadowmap_texturescale[2], r_shadow_lightshadowmap_texturescale[3]);
- hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_Parameters, r_shadow_lightshadowmap_parameters[0], r_shadow_lightshadowmap_parameters[1], r_shadow_lightshadowmap_parameters[2], r_shadow_lightshadowmap_parameters[3]);
- hlslPSSetParameter1f(D3DPSREGISTER_SpecularPower, (r_shadow_gloss.integer == 2 ? r_shadow_gloss2exponent.value : r_shadow_glossexponent.value) * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f);
- hlslPSSetParameter2f(D3DPSREGISTER_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
- hlslPSSetParameter2f(D3DPSREGISTER_PixelToScreenTexCoord, 1.0f/vid.width, 1.0/vid.height);
-
- R_Mesh_TexBind(GL20TU_ATTENUATION , r_shadow_attenuationgradienttexture );
- R_Mesh_TexBind(GL20TU_SCREENNORMALMAP , r_shadow_prepassgeometrynormalmaptexture );
- R_Mesh_TexBind(GL20TU_CUBE , rsurface.rtlight->currentcubemap );
- R_Mesh_TexBind(GL20TU_SHADOWMAP2D , r_shadow_shadowmap2ddepthtexture );
- R_Mesh_TexBind(GL20TU_CUBEPROJECTION , r_shadow_shadowmapvsdcttexture );
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
R_SetupShader_SetPermutationGLSL(mode, permutation);
if (r_glsl_permutation->tex_Texture_ShadowMap2D >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_ShadowMap2D , r_shadow_shadowmap2ddepthtexture );
if (r_glsl_permutation->tex_Texture_CubeProjection >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_CubeProjection , r_shadow_shadowmapvsdcttexture );
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- break;
- case RENDERPATH_SOFT:
- R_SetupShader_SetPermutationGLSL(mode, permutation);
- DPSOFTRAST_Uniform3f( DPSOFTRAST_UNIFORM_LightPosition , viewlightorigin[0], viewlightorigin[1], viewlightorigin[2]);
- DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ViewToLightM1 , 1, false, viewtolight16f);
- DPSOFTRAST_Uniform3f( DPSOFTRAST_UNIFORM_DeferredColor_Ambient , lightcolorbase[0] * ambientscale , lightcolorbase[1] * ambientscale , lightcolorbase[2] * ambientscale );
- DPSOFTRAST_Uniform3f( DPSOFTRAST_UNIFORM_DeferredColor_Diffuse , lightcolorbase[0] * diffusescale , lightcolorbase[1] * diffusescale , lightcolorbase[2] * diffusescale );
- DPSOFTRAST_Uniform3f( DPSOFTRAST_UNIFORM_DeferredColor_Specular , lightcolorbase[0] * specularscale, lightcolorbase[1] * specularscale, lightcolorbase[2] * specularscale);
- DPSOFTRAST_Uniform4f( DPSOFTRAST_UNIFORM_ShadowMap_TextureScale , r_shadow_lightshadowmap_texturescale[0], r_shadow_lightshadowmap_texturescale[1], r_shadow_lightshadowmap_texturescale[2], r_shadow_lightshadowmap_texturescale[3]);
- DPSOFTRAST_Uniform4f( DPSOFTRAST_UNIFORM_ShadowMap_Parameters , r_shadow_lightshadowmap_parameters[0], r_shadow_lightshadowmap_parameters[1], r_shadow_lightshadowmap_parameters[2], r_shadow_lightshadowmap_parameters[3]);
- DPSOFTRAST_Uniform1f( DPSOFTRAST_UNIFORM_SpecularPower , (r_shadow_gloss.integer == 2 ? r_shadow_gloss2exponent.value : r_shadow_glossexponent.value) * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f);
- DPSOFTRAST_Uniform2f( DPSOFTRAST_UNIFORM_ScreenToDepth , r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
- DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
-
- R_Mesh_TexBind(GL20TU_ATTENUATION , r_shadow_attenuationgradienttexture );
- R_Mesh_TexBind(GL20TU_SCREENNORMALMAP , r_shadow_prepassgeometrynormalmaptexture );
- R_Mesh_TexBind(GL20TU_CUBE , rsurface.rtlight->currentcubemap );
- R_Mesh_TexBind(GL20TU_SHADOWMAP2D , r_shadow_shadowmap2ddepthtexture );
- R_Mesh_TexBind(GL20TU_CUBEPROJECTION , r_shadow_shadowmapvsdcttexture );
- break;
}
}
switch(vid.renderpath)
{
case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
case RENDERPATH_GLES2:
Cvar_SetValueQuick(&r_textureunits, vid.texunits);
Cvar_SetValueQuick(&gl_combine, 1);
qglGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &r_uniformbufferalignment);
#endif
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- Cvar_SetValueQuick(&r_textureunits, vid.texunits);
- Cvar_SetValueQuick(&gl_combine, 1);
- Cvar_SetValueQuick(&r_glsl, 0);
- r_loadnormalmap = false;
- r_loadgloss = false;
- r_loadfog = true;
- break;
- case RENDERPATH_GL11:
- Cvar_SetValueQuick(&r_textureunits, vid.texunits);
- Cvar_SetValueQuick(&gl_combine, 0);
- Cvar_SetValueQuick(&r_glsl, 0);
- r_loadnormalmap = false;
- r_loadgloss = false;
- r_loadfog = true;
- break;
}
R_AnimCache_Free();
r_glsl_permutation = NULL;
memset(r_glsl_permutationhash, 0, sizeof(r_glsl_permutationhash));
Mem_ExpandableArray_NewArray(&r_glsl_permutationarray, r_main_mempool, sizeof(r_glsl_permutation_t), 256);
-#ifdef SUPPORTD3D
- r_hlsl_permutation = NULL;
- memset(r_hlsl_permutationhash, 0, sizeof(r_hlsl_permutationhash));
- Mem_ExpandableArray_NewArray(&r_hlsl_permutationarray, r_main_mempool, sizeof(r_hlsl_permutation_t), 256);
-#endif
memset(&r_svbsp, 0, sizeof (r_svbsp));
memset(r_texture_cubemaps, 0, sizeof(r_texture_cubemaps));
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
if (r_maxqueries)
qglDeleteQueriesARB(r_maxqueries, r_queries);
#endif
break;
- case RENDERPATH_D3D9:
- //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
r_numqueries = 0;
r_glsl_permutation = NULL;
memset(r_glsl_permutationhash, 0, sizeof(r_glsl_permutationhash));
Mem_ExpandableArray_FreeArray(&r_glsl_permutationarray);
-#ifdef SUPPORTD3D
- r_hlsl_permutation = NULL;
- memset(r_hlsl_permutationhash, 0, sizeof(r_hlsl_permutationhash));
- Mem_ExpandableArray_FreeArray(&r_hlsl_permutationarray);
-#endif
}
static void gl_main_newmap(void)
void R_AnimCache_CacheVisibleEntities(void)
{
int i;
- qboolean wantnormals = true;
- qboolean wanttangents = !r_showsurfaces.integer;
-
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_GLES2:
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- wanttangents = false;
- break;
- case RENDERPATH_SOFT:
- break;
- }
-
- if (r_shownormals.integer)
- wanttangents = wantnormals = true;
// TODO: thread this
// NOTE: R_PrepareRTLights() also caches entities
for (i = 0;i < r_refdef.scene.numentities;i++)
if (r_refdef.viewcache.entityvisible[i])
- R_AnimCache_GetEntity(r_refdef.scene.entities[i], wantnormals, wanttangents);
+ R_AnimCache_GetEntity(r_refdef.scene.entities[i], true, true);
}
//==================================================================================
// flipped x coordinates (because x points left here)
fpx = 1.0 - 2.0 * (scissor[0] - r_refdef.view.viewport.x) / (double) (r_refdef.view.viewport.width);
fnx = 1.0 - 2.0 * (scissor[0] + scissor[2] - r_refdef.view.viewport.x) / (double) (r_refdef.view.viewport.width);
-
- // D3D Y coordinate is top to bottom, OpenGL is bottom to top, fix the D3D one
- switch(vid.renderpath)
- {
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- // non-flipped y coordinates
- fny = -1.0 + 2.0 * (vid.height - scissor[1] - scissor[3] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
- fpy = -1.0 + 2.0 * (vid.height - scissor[1] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
- break;
- case RENDERPATH_SOFT:
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
- // non-flipped y coordinates
- fny = -1.0 + 2.0 * (scissor[1] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
- fpy = -1.0 + 2.0 * (scissor[1] + scissor[3] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
- break;
- }
+ // non-flipped y coordinates
+ fny = -1.0 + 2.0 * (scissor[1] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
+ fpy = -1.0 + 2.0 * (scissor[1] + scissor[3] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
}
// we can't trust r_refdef.view.forward and friends in reflected scenes
plane[1] = r_refdef.view.clipplane.normal[1];
plane[2] = r_refdef.view.clipplane.normal[2];
plane[3] = -dist;
- if(vid.renderpath != RENDERPATH_SOFT) customclipplane = plane;
}
//rtwidth = viewfbo ? R_TextureWidth(viewdepthtexture ? viewdepthtexture : viewcolortexture) : vid.width;
R_Viewport_InitPerspective(&r_refdef.view.viewport, &r_refdef.view.matrix, viewx, rtheight - viewheight - viewy, viewwidth, viewheight, r_refdef.view.frustum_x, r_refdef.view.frustum_y, r_refdef.nearclip, r_refdef.farclip, customclipplane);
R_Mesh_SetRenderTargets(viewfbo, viewdepthtexture, viewcolortexture, NULL, NULL, NULL);
R_SetViewport(&r_refdef.view.viewport);
- if (r_refdef.view.useclipplane && allowwaterclippingplane && vid.renderpath == RENDERPATH_SOFT)
- {
- matrix4x4_t mvpmatrix, invmvpmatrix, invtransmvpmatrix;
- float screenplane[4];
- Matrix4x4_Concat(&mvpmatrix, &r_refdef.view.viewport.projectmatrix, &r_refdef.view.viewport.viewmatrix);
- Matrix4x4_Invert_Full(&invmvpmatrix, &mvpmatrix);
- Matrix4x4_Transpose(&invtransmvpmatrix, &invmvpmatrix);
- Matrix4x4_Transform4(&invtransmvpmatrix, plane, screenplane);
- DPSOFTRAST_ClipPlane(screenplane[0], screenplane[1], screenplane[2], screenplane[3]);
- }
}
void R_EntityMatrix(const matrix4x4_t *matrix)
CHECKGLERROR
switch(vid.renderpath)
{
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- hlslVSSetParameter16f(D3DVSREGISTER_ModelViewProjectionMatrix, gl_modelviewprojection16f);
- hlslVSSetParameter16f(D3DVSREGISTER_ModelViewMatrix, gl_modelview16f);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 shader %s:%i\n", __FILE__, __LINE__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 shader %s:%i\n", __FILE__, __LINE__);
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
-#ifndef USE_GLES2
- qglLoadMatrixf(gl_modelview16f);CHECKGLERROR
-#endif
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1, 1, false, gl_modelviewprojection16f);
- DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ModelViewMatrixM1, 1, false, gl_modelview16f);
- break;
case RENDERPATH_GL20:
case RENDERPATH_GLES2:
if (r_glsl_permutation && r_glsl_permutation->loc_ModelViewProjectionMatrix >= 0) qglUniformMatrix4fv(r_glsl_permutation->loc_ModelViewProjectionMatrix, 1, false, gl_modelviewprojection16f);
R_SetStencil(false, 255, GL_KEEP, GL_KEEP, GL_KEEP, GL_ALWAYS, 128, 255);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglEnable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
}
GL_CullFace(GL_NONE);
R_SetStencil(false, 255, GL_KEEP, GL_KEEP, GL_KEEP, GL_ALWAYS, 128, 255);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
qglEnable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
}
GL_CullFace(r_refdef.view.cullface_back);
}
static void R_CalcTexCoordsForView(float x, float y, float w, float h, float tw, float th, float *texcoord2f)
{
float iw = 1.0f / tw, ih = 1.0f / th, x1, y1, x2, y2;
- switch (vid.renderpath)
- {
- case RENDERPATH_D3D9:
- x1 = (x + 0.5f) * iw;
- x2 = (x + 0.5f + w) * iw;
- y1 = (y + 0.5f) * ih;
- y2 = (y + 0.5f + h) * ih;
- break;
- default:
- x1 = x * iw;
- x2 = (x + w) * iw;
- y1 = (th - y) * ih;
- y2 = (th - y - h) * ih;
- break;
- }
+ x1 = x * iw;
+ x2 = (x + w) * iw;
+ y1 = (th - y) * ih;
+ y2 = (th - y - h) * ih;
texcoord2f[0] = x1;
texcoord2f[2] = x2;
texcoord2f[4] = x2;
if (vid.width > (int)vid.maxtexturesize_2d || vid.height > (int)vid.maxtexturesize_2d)
return;
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- return;
- }
-
// set waterwidth and waterheight to the water resolution that will be
// used (often less than the screen resolution for faster rendering)
waterwidth = (int)bound(1, r_refdef.view.width * r_water_resolutionmultiplier.value, r_refdef.view.width);
}
}
- if(vid.renderpath==RENDERPATH_SOFT) DPSOFTRAST_ClipPlane(0, 0, 0, 1);
r_fb.water.renderingscene = false;
r_refdef.view = originalview;
R_ResetViewRendering3D(fbo, depthtexture, colortexture, viewx, viewy, viewwidth, viewheight);
if (!vid.support.ext_framebuffer_object)
return;
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- return; // don't bother
case RENDERPATH_GLES2:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
r_fb.usedepthtextures = false;
break;
- case RENDERPATH_SOFT:
- r_fb.usedepthtextures = true;
- break;
}
if (r_viewscale_fpsscaling.integer)
R_EntityMatrix(&identitymatrix);
- switch (vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- permutation =
- (r_fb.bloomwidth ? SHADERPERMUTATION_BLOOM : 0)
- | (r_refdef.viewblend[3] > 0 ? SHADERPERMUTATION_VIEWTINT : 0)
- | (!vid_gammatables_trivial ? SHADERPERMUTATION_GAMMARAMPS : 0)
- | (r_glsl_postprocess.integer ? SHADERPERMUTATION_POSTPROCESSING : 0)
- | ((!R_Stereo_ColorMasking() && r_glsl_saturation.value != 1) ? SHADERPERMUTATION_SATURATION : 0);
-
- if(r_refdef.view.ismain && !R_Stereo_Active() && (r_motionblur.value > 0 || r_damageblur.value > 0) && r_fb.ghosttexture)
- {
- // declare variables
- float blur_factor, blur_mouseaccel, blur_velocity;
- static float blur_average;
- static vec3_t blur_oldangles; // used to see how quickly the mouse is moving
-
- // set a goal for the factoring
- blur_velocity = bound(0, (VectorLength(cl.movement_velocity) - r_motionblur_velocityfactor_minspeed.value)
- / max(1, r_motionblur_velocityfactor_maxspeed.value - r_motionblur_velocityfactor_minspeed.value), 1);
- blur_mouseaccel = bound(0, ((fabs(VectorLength(cl.viewangles) - VectorLength(blur_oldangles)) * 10) - r_motionblur_mousefactor_minspeed.value)
- / max(1, r_motionblur_mousefactor_maxspeed.value - r_motionblur_mousefactor_minspeed.value), 1);
- blur_factor = ((blur_velocity * r_motionblur_velocityfactor.value)
- + (blur_mouseaccel * r_motionblur_mousefactor.value));
-
- // from the goal, pick an averaged value between goal and last value
- cl.motionbluralpha = bound(0, (cl.time - cl.oldtime) / max(0.001, r_motionblur_averaging.value), 1);
- blur_average = blur_average * (1 - cl.motionbluralpha) + blur_factor * cl.motionbluralpha;
-
- // enforce minimum amount of blur
- blur_factor = blur_average * (1 - r_motionblur_minblur.value) + r_motionblur_minblur.value;
-
- //Con_Printf("motionblur: direct factor: %f, averaged factor: %f, velocity: %f, mouse accel: %f \n", blur_factor, blur_average, blur_velocity, blur_mouseaccel);
-
- // calculate values into a standard alpha
- cl.motionbluralpha = 1 - exp(-
- (
- (r_motionblur.value * blur_factor / 80)
- +
- (r_damageblur.value * (cl.cshifts[CSHIFT_DAMAGE].percent / 1600))
- )
- /
- max(0.0001, cl.time - cl.oldtime) // fps independent
- );
-
- // randomization for the blur value to combat persistent ghosting
- cl.motionbluralpha *= lhrandom(1 - r_motionblur_randomize.value, 1 + r_motionblur_randomize.value);
- cl.motionbluralpha = bound(0, cl.motionbluralpha, r_motionblur_maxblur.value);
-
- // apply the blur
- R_ResetViewRendering2D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
- if (cl.motionbluralpha > 0 && !r_refdef.envmap && r_fb.ghosttexture_valid)
- {
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- GL_Color(1, 1, 1, cl.motionbluralpha);
- R_CalcTexCoordsForView(0, 0, viewwidth, viewheight, viewwidth, viewheight, r_fb.ghosttexcoord2f);
- R_Mesh_PrepareVertices_Generic_Arrays(4, r_screenvertex3f, NULL, r_fb.ghosttexcoord2f);
- R_SetupShader_Generic(r_fb.ghosttexture, NULL, GL_MODULATE, 1, false, true, true);
- R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
- r_refdef.stats[r_stat_bloom_drawpixels] += viewwidth * viewheight;
- }
-
- // updates old view angles for next pass
- VectorCopy(cl.viewangles, blur_oldangles);
-
- // copy view into the ghost texture
- R_Mesh_CopyToTexture(r_fb.ghosttexture, 0, 0, viewx, viewy, viewwidth, viewheight);
- r_refdef.stats[r_stat_bloom_copypixels] += viewwidth * viewheight;
- r_fb.ghosttexture_valid = true;
- }
-
- if (r_fb.bloomwidth)
+ if(r_refdef.view.ismain && !R_Stereo_Active() && (r_motionblur.value > 0 || r_damageblur.value > 0) && r_fb.ghosttexture)
+ {
+ // declare variables
+ float blur_factor, blur_mouseaccel, blur_velocity;
+ static float blur_average;
+ static vec3_t blur_oldangles; // used to see how quickly the mouse is moving
+
+ // set a goal for the factoring
+ blur_velocity = bound(0, (VectorLength(cl.movement_velocity) - r_motionblur_velocityfactor_minspeed.value)
+ / max(1, r_motionblur_velocityfactor_maxspeed.value - r_motionblur_velocityfactor_minspeed.value), 1);
+ blur_mouseaccel = bound(0, ((fabs(VectorLength(cl.viewangles) - VectorLength(blur_oldangles)) * 10) - r_motionblur_mousefactor_minspeed.value)
+ / max(1, r_motionblur_mousefactor_maxspeed.value - r_motionblur_mousefactor_minspeed.value), 1);
+ blur_factor = ((blur_velocity * r_motionblur_velocityfactor.value)
+ + (blur_mouseaccel * r_motionblur_mousefactor.value));
+
+ // from the goal, pick an averaged value between goal and last value
+ cl.motionbluralpha = bound(0, (cl.time - cl.oldtime) / max(0.001, r_motionblur_averaging.value), 1);
+ blur_average = blur_average * (1 - cl.motionbluralpha) + blur_factor * cl.motionbluralpha;
+
+ // enforce minimum amount of blur
+ blur_factor = blur_average * (1 - r_motionblur_minblur.value) + r_motionblur_minblur.value;
+
+ //Con_Printf("motionblur: direct factor: %f, averaged factor: %f, velocity: %f, mouse accel: %f \n", blur_factor, blur_average, blur_velocity, blur_mouseaccel);
+
+ // calculate values into a standard alpha
+ cl.motionbluralpha = 1 - exp(-
+ (
+ (r_motionblur.value * blur_factor / 80)
+ +
+ (r_damageblur.value * (cl.cshifts[CSHIFT_DAMAGE].percent / 1600))
+ )
+ /
+ max(0.0001, cl.time - cl.oldtime) // fps independent
+ );
+
+ // randomization for the blur value to combat persistent ghosting
+ cl.motionbluralpha *= lhrandom(1 - r_motionblur_randomize.value, 1 + r_motionblur_randomize.value);
+ cl.motionbluralpha = bound(0, cl.motionbluralpha, r_motionblur_maxblur.value);
+
+ // apply the blur
+ R_ResetViewRendering2D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
+ if (cl.motionbluralpha > 0 && !r_refdef.envmap && r_fb.ghosttexture_valid)
{
- // make the bloom texture
- R_Bloom_MakeTexture();
+ GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ GL_Color(1, 1, 1, cl.motionbluralpha);
+ R_CalcTexCoordsForView(0, 0, viewwidth, viewheight, viewwidth, viewheight, r_fb.ghosttexcoord2f);
+ R_Mesh_PrepareVertices_Generic_Arrays(4, r_screenvertex3f, NULL, r_fb.ghosttexcoord2f);
+ R_SetupShader_Generic(r_fb.ghosttexture, NULL, GL_MODULATE, 1, false, true, true);
+ R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+ r_refdef.stats[r_stat_bloom_drawpixels] += viewwidth * viewheight;
}
-#if _MSC_VER >= 1400
-#define sscanf sscanf_s
-#endif
- memset(uservecs, 0, sizeof(uservecs));
- if (r_glsl_postprocess_uservec1_enable.integer)
- sscanf(r_glsl_postprocess_uservec1.string, "%f %f %f %f", &uservecs[0][0], &uservecs[0][1], &uservecs[0][2], &uservecs[0][3]);
- if (r_glsl_postprocess_uservec2_enable.integer)
- sscanf(r_glsl_postprocess_uservec2.string, "%f %f %f %f", &uservecs[1][0], &uservecs[1][1], &uservecs[1][2], &uservecs[1][3]);
- if (r_glsl_postprocess_uservec3_enable.integer)
- sscanf(r_glsl_postprocess_uservec3.string, "%f %f %f %f", &uservecs[2][0], &uservecs[2][1], &uservecs[2][2], &uservecs[2][3]);
- if (r_glsl_postprocess_uservec4_enable.integer)
- sscanf(r_glsl_postprocess_uservec4.string, "%f %f %f %f", &uservecs[3][0], &uservecs[3][1], &uservecs[3][2], &uservecs[3][3]);
+ // updates old view angles for next pass
+ VectorCopy(cl.viewangles, blur_oldangles);
- // render to the screen fbo
- R_ResetViewRendering2D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
- GL_Color(1, 1, 1, 1);
- GL_BlendFunc(GL_ONE, GL_ZERO);
+ // copy view into the ghost texture
+ R_Mesh_CopyToTexture(r_fb.ghosttexture, 0, 0, viewx, viewy, viewwidth, viewheight);
+ r_refdef.stats[r_stat_bloom_copypixels] += viewwidth * viewheight;
+ r_fb.ghosttexture_valid = true;
+ }
+
+ if (r_fb.bloomwidth)
+ {
+ // make the bloom texture
+ R_Bloom_MakeTexture();
+ }
- viewtexture = r_fb.rt_screen->colortexture[0];
- bloomtexture = r_fb.rt_bloom ? r_fb.rt_bloom->colortexture[0] : NULL;
+#if _MSC_VER >= 1400
+#define sscanf sscanf_s
+#endif
+ memset(uservecs, 0, sizeof(uservecs));
+ if (r_glsl_postprocess_uservec1_enable.integer)
+ sscanf(r_glsl_postprocess_uservec1.string, "%f %f %f %f", &uservecs[0][0], &uservecs[0][1], &uservecs[0][2], &uservecs[0][3]);
+ if (r_glsl_postprocess_uservec2_enable.integer)
+ sscanf(r_glsl_postprocess_uservec2.string, "%f %f %f %f", &uservecs[1][0], &uservecs[1][1], &uservecs[1][2], &uservecs[1][3]);
+ if (r_glsl_postprocess_uservec3_enable.integer)
+ sscanf(r_glsl_postprocess_uservec3.string, "%f %f %f %f", &uservecs[2][0], &uservecs[2][1], &uservecs[2][2], &uservecs[2][3]);
+ if (r_glsl_postprocess_uservec4_enable.integer)
+ sscanf(r_glsl_postprocess_uservec4.string, "%f %f %f %f", &uservecs[3][0], &uservecs[3][1], &uservecs[3][2], &uservecs[3][3]);
+
+ // render to the screen fbo
+ R_ResetViewRendering2D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
+ GL_Color(1, 1, 1, 1);
+ GL_BlendFunc(GL_ONE, GL_ZERO);
- if (r_rendertarget_debug.integer >= 0)
- {
- r_rendertarget_t *rt = (r_rendertarget_t *)Mem_ExpandableArray_RecordAtIndex(&r_fb.rendertargets, r_rendertarget_debug.integer);
- if (rt && rt->colortexture[0])
- {
- viewtexture = rt->colortexture[0];
- bloomtexture = NULL;
- }
- }
+ viewtexture = r_fb.rt_screen->colortexture[0];
+ bloomtexture = r_fb.rt_bloom ? r_fb.rt_bloom->colortexture[0] : NULL;
- R_Mesh_PrepareVertices_Mesh_Arrays(4, r_screenvertex3f, NULL, NULL, NULL, NULL, r_fb.rt_screen->texcoord2f, bloomtexture ? r_fb.rt_bloom->texcoord2f : NULL);
- switch(vid.renderpath)
+ if (r_rendertarget_debug.integer >= 0)
+ {
+ r_rendertarget_t *rt = (r_rendertarget_t *)Mem_ExpandableArray_RecordAtIndex(&r_fb.rendertargets, r_rendertarget_debug.integer);
+ if (rt && rt->colortexture[0])
{
- case RENDERPATH_GL20:
- case RENDERPATH_GLES2:
- R_SetupShader_SetPermutationGLSL(SHADERMODE_POSTPROCESS, permutation);
- if (r_glsl_permutation->tex_Texture_First >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_First , viewtexture);
- if (r_glsl_permutation->tex_Texture_Second >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_Second , bloomtexture);
- if (r_glsl_permutation->tex_Texture_GammaRamps >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_GammaRamps, r_texture_gammaramps );
- if (r_glsl_permutation->loc_ViewTintColor >= 0) qglUniform4f(r_glsl_permutation->loc_ViewTintColor , r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
- if (r_glsl_permutation->loc_PixelSize >= 0) qglUniform2f(r_glsl_permutation->loc_PixelSize , 1.0/r_fb.screentexturewidth, 1.0/r_fb.screentextureheight);
- if (r_glsl_permutation->loc_UserVec1 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec1 , uservecs[0][0], uservecs[0][1], uservecs[0][2], uservecs[0][3]);
- if (r_glsl_permutation->loc_UserVec2 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec2 , uservecs[1][0], uservecs[1][1], uservecs[1][2], uservecs[1][3]);
- if (r_glsl_permutation->loc_UserVec3 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec3 , uservecs[2][0], uservecs[2][1], uservecs[2][2], uservecs[2][3]);
- if (r_glsl_permutation->loc_UserVec4 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec4 , uservecs[3][0], uservecs[3][1], uservecs[3][2], uservecs[3][3]);
- if (r_glsl_permutation->loc_Saturation >= 0) qglUniform1f(r_glsl_permutation->loc_Saturation , r_glsl_saturation.value);
- if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
- if (r_glsl_permutation->loc_BloomColorSubtract >= 0) qglUniform4f(r_glsl_permutation->loc_BloomColorSubtract , r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, 0.0f);
- break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- R_SetupShader_SetPermutationHLSL(SHADERMODE_POSTPROCESS, permutation);
- R_Mesh_TexBind(GL20TU_FIRST , viewtexture);
- R_Mesh_TexBind(GL20TU_SECOND , bloomtexture);
- R_Mesh_TexBind(GL20TU_GAMMARAMPS, r_texture_gammaramps );
- hlslPSSetParameter4f(D3DPSREGISTER_ViewTintColor , r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
- hlslPSSetParameter2f(D3DPSREGISTER_PixelSize , 1.0/r_fb.screentexturewidth, 1.0/r_fb.screentextureheight);
- hlslPSSetParameter4f(D3DPSREGISTER_UserVec1 , uservecs[0][0], uservecs[0][1], uservecs[0][2], uservecs[0][3]);
- hlslPSSetParameter4f(D3DPSREGISTER_UserVec2 , uservecs[1][0], uservecs[1][1], uservecs[1][2], uservecs[1][3]);
- hlslPSSetParameter4f(D3DPSREGISTER_UserVec3 , uservecs[2][0], uservecs[2][1], uservecs[2][2], uservecs[2][3]);
- hlslPSSetParameter4f(D3DPSREGISTER_UserVec4 , uservecs[3][0], uservecs[3][1], uservecs[3][2], uservecs[3][3]);
- hlslPSSetParameter1f(D3DPSREGISTER_Saturation , r_glsl_saturation.value);
- hlslPSSetParameter2f(D3DPSREGISTER_PixelToScreenTexCoord, 1.0f/vid.width, 1.0/vid.height);
- hlslPSSetParameter4f(D3DPSREGISTER_BloomColorSubtract , r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, 0.0f);
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- R_SetupShader_SetPermutationSoft(SHADERMODE_POSTPROCESS, permutation);
- R_Mesh_TexBind(GL20TU_FIRST , viewtexture);
- R_Mesh_TexBind(GL20TU_SECOND , bloomtexture);
- R_Mesh_TexBind(GL20TU_GAMMARAMPS, r_texture_gammaramps );
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_ViewTintColor , r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
- DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_PixelSize , 1.0/r_fb.screentexturewidth, 1.0/r_fb.screentextureheight);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_UserVec1 , uservecs[0][0], uservecs[0][1], uservecs[0][2], uservecs[0][3]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_UserVec2 , uservecs[1][0], uservecs[1][1], uservecs[1][2], uservecs[1][3]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_UserVec3 , uservecs[2][0], uservecs[2][1], uservecs[2][2], uservecs[2][3]);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_UserVec4 , uservecs[3][0], uservecs[3][1], uservecs[3][2], uservecs[3][3]);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_Saturation , r_glsl_saturation.value);
- DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
- DPSOFTRAST_Uniform4f(DPSOFTRAST_UNIFORM_BloomColorSubtract , r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, 0.0f);
- break;
- default:
- break;
- }
- R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
- r_refdef.stats[r_stat_bloom_drawpixels] += r_refdef.view.width * r_refdef.view.height;
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (r_refdef.viewblend[3] >= (1.0f / 256.0f))
- {
- // apply a color tint to the whole view
- R_ResetViewRendering2D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
- GL_Color(r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
- R_Mesh_PrepareVertices_Generic_Arrays(4, r_screenvertex3f, NULL, NULL);
- R_SetupShader_Generic_NoTexture(false, true);
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+ viewtexture = rt->colortexture[0];
+ bloomtexture = NULL;
}
+ }
+
+ R_Mesh_PrepareVertices_Mesh_Arrays(4, r_screenvertex3f, NULL, NULL, NULL, NULL, r_fb.rt_screen->texcoord2f, bloomtexture ? r_fb.rt_bloom->texcoord2f : NULL);
+ switch(vid.renderpath)
+ {
+ case RENDERPATH_GL20:
+ case RENDERPATH_GLES2:
+ permutation =
+ (r_fb.bloomwidth ? SHADERPERMUTATION_BLOOM : 0)
+ | (r_refdef.viewblend[3] > 0 ? SHADERPERMUTATION_VIEWTINT : 0)
+ | (!vid_gammatables_trivial ? SHADERPERMUTATION_GAMMARAMPS : 0)
+ | (r_glsl_postprocess.integer ? SHADERPERMUTATION_POSTPROCESSING : 0)
+ | ((!R_Stereo_ColorMasking() && r_glsl_saturation.value != 1) ? SHADERPERMUTATION_SATURATION : 0);
+ R_SetupShader_SetPermutationGLSL(SHADERMODE_POSTPROCESS, permutation);
+ if (r_glsl_permutation->tex_Texture_First >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_First , viewtexture);
+ if (r_glsl_permutation->tex_Texture_Second >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_Second , bloomtexture);
+ if (r_glsl_permutation->tex_Texture_GammaRamps >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_GammaRamps, r_texture_gammaramps );
+ if (r_glsl_permutation->loc_ViewTintColor >= 0) qglUniform4f(r_glsl_permutation->loc_ViewTintColor , r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
+ if (r_glsl_permutation->loc_PixelSize >= 0) qglUniform2f(r_glsl_permutation->loc_PixelSize , 1.0/r_fb.screentexturewidth, 1.0/r_fb.screentextureheight);
+ if (r_glsl_permutation->loc_UserVec1 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec1 , uservecs[0][0], uservecs[0][1], uservecs[0][2], uservecs[0][3]);
+ if (r_glsl_permutation->loc_UserVec2 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec2 , uservecs[1][0], uservecs[1][1], uservecs[1][2], uservecs[1][3]);
+ if (r_glsl_permutation->loc_UserVec3 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec3 , uservecs[2][0], uservecs[2][1], uservecs[2][2], uservecs[2][3]);
+ if (r_glsl_permutation->loc_UserVec4 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec4 , uservecs[3][0], uservecs[3][1], uservecs[3][2], uservecs[3][3]);
+ if (r_glsl_permutation->loc_Saturation >= 0) qglUniform1f(r_glsl_permutation->loc_Saturation , r_glsl_saturation.value);
+ if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
+ if (r_glsl_permutation->loc_BloomColorSubtract >= 0) qglUniform4f(r_glsl_permutation->loc_BloomColorSubtract , r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, 0.0f);
break;
}
+ R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+ r_refdef.stats[r_stat_bloom_drawpixels] += r_refdef.view.width * r_refdef.view.height;
}
matrix4x4_t r_waterscrollmatrix;
{
case RENDERPATH_GL20:
r_gpuskeletal = vid.support.arb_uniform_buffer_object && r_glsl_skeletal.integer && !r_showsurfaces.integer; // FIXME add r_showsurfaces support to GLSL skeletal!
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
case RENDERPATH_GLES2:
if(!vid_gammatables_trivial)
{
// remove GLSL gamma texture
}
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- break;
}
}
R_RenderView
================
*/
-int dpsoftrast_test;
extern cvar_t r_shadow_bouncegrid;
extern cvar_t v_isometric;
extern void V_MakeViewIsometric(void);
// finish any 2D rendering that was queued
DrawQ_Finish();
- dpsoftrast_test = r_test.integer;
-
if (r_timereport_active)
R_TimeReport("start");
r_textureframe++; // used only by R_GetCurrentTexture
R_TimeReport("coronas");
}
-#if 0
- {
- GL_DepthTest(false);
- qglPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- GL_Color(1, 1, 1, 1);
- qglBegin(GL_POLYGON);
- qglVertex3f(r_refdef.view.frustumcorner[0][0], r_refdef.view.frustumcorner[0][1], r_refdef.view.frustumcorner[0][2]);
- qglVertex3f(r_refdef.view.frustumcorner[1][0], r_refdef.view.frustumcorner[1][1], r_refdef.view.frustumcorner[1][2]);
- qglVertex3f(r_refdef.view.frustumcorner[3][0], r_refdef.view.frustumcorner[3][1], r_refdef.view.frustumcorner[3][2]);
- qglVertex3f(r_refdef.view.frustumcorner[2][0], r_refdef.view.frustumcorner[2][1], r_refdef.view.frustumcorner[2][2]);
- qglEnd();
- qglBegin(GL_POLYGON);
- qglVertex3f(r_refdef.view.frustumcorner[0][0] + 1000 * r_refdef.view.forward[0], r_refdef.view.frustumcorner[0][1] + 1000 * r_refdef.view.forward[1], r_refdef.view.frustumcorner[0][2] + 1000 * r_refdef.view.forward[2]);
- qglVertex3f(r_refdef.view.frustumcorner[1][0] + 1000 * r_refdef.view.forward[0], r_refdef.view.frustumcorner[1][1] + 1000 * r_refdef.view.forward[1], r_refdef.view.frustumcorner[1][2] + 1000 * r_refdef.view.forward[2]);
- qglVertex3f(r_refdef.view.frustumcorner[3][0] + 1000 * r_refdef.view.forward[0], r_refdef.view.frustumcorner[3][1] + 1000 * r_refdef.view.forward[1], r_refdef.view.frustumcorner[3][2] + 1000 * r_refdef.view.forward[2]);
- qglVertex3f(r_refdef.view.frustumcorner[2][0] + 1000 * r_refdef.view.forward[0], r_refdef.view.frustumcorner[2][1] + 1000 * r_refdef.view.forward[1], r_refdef.view.frustumcorner[2][2] + 1000 * r_refdef.view.forward[2]);
- qglEnd();
- qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
-#endif
-
// don't let sound skip if going slow
if (r_refdef.scene.extraupdate)
S_ExtraUpdate ();
rsurface.batchelement3s = NULL;
rsurface.batchelement3s_indexbuffer = NULL;
rsurface.batchelement3s_bufferoffset = 0;
- rsurface.passcolor4f = NULL;
- rsurface.passcolor4f_vertexbuffer = NULL;
- rsurface.passcolor4f_bufferoffset = 0;
rsurface.forcecurrenttextureupdate = false;
}
rsurface.batchelement3s = NULL;
rsurface.batchelement3s_indexbuffer = NULL;
rsurface.batchelement3s_bufferoffset = 0;
- rsurface.passcolor4f = NULL;
- rsurface.passcolor4f_vertexbuffer = NULL;
- rsurface.passcolor4f_bufferoffset = 0;
rsurface.forcecurrenttextureupdate = true;
if (rsurface.modelnumvertices && rsurface.modelelement3i)
// render multiple smaller batches
}
-static void RSurf_DrawBatch_GL11_MakeFullbrightLightmapColorArray(void)
-{
- int i;
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0;i < rsurface.batchnumvertices;i++)
- Vector4Set(rsurface.passcolor4f + 4*i, 0.5f, 0.5f, 0.5f, 1.0f);
-}
-
-static void RSurf_DrawBatch_GL11_ApplyFog(void)
-{
- int i;
- float f;
- const float *v;
- const float *c;
- float *c2;
- if (rsurface.passcolor4f)
- {
- // generate color arrays
- c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3, c2 = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, v += 3, c += 4, c2 += 4)
- {
- f = RSurf_FogVertex(v);
- c2[0] = c[0] * f;
- c2[1] = c[1] * f;
- c2[2] = c[2] * f;
- c2[3] = c[3];
- }
- }
- else
- {
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3, c2 = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, v += 3, c2 += 4)
- {
- f = RSurf_FogVertex(v);
- c2[0] = f;
- c2[1] = f;
- c2[2] = f;
- c2[3] = 1;
- }
- }
-}
-
-static void RSurf_DrawBatch_GL11_ApplyFogToFinishedVertexColors(void)
-{
- int i;
- float f;
- const float *v;
- const float *c;
- float *c2;
- if (!rsurface.passcolor4f)
- return;
- c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3, c2 = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, v += 3, c += 4, c2 += 4)
- {
- f = RSurf_FogVertex(v);
- c2[0] = c[0] * f + r_refdef.fogcolor[0] * (1 - f);
- c2[1] = c[1] * f + r_refdef.fogcolor[1] * (1 - f);
- c2[2] = c[2] * f + r_refdef.fogcolor[2] * (1 - f);
- c2[3] = c[3];
- }
-}
-
-static void RSurf_DrawBatch_GL11_ApplyColor(float r, float g, float b, float a)
-{
- int i;
- const float *c;
- float *c2;
- if (!rsurface.passcolor4f)
- return;
- c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, c2 = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, c += 4, c2 += 4)
- {
- c2[0] = c[0] * r;
- c2[1] = c[1] * g;
- c2[2] = c[2] * b;
- c2[3] = c[3] * a;
- }
-}
-
-static void RSurf_DrawBatch_GL11_ApplyAmbient(void)
-{
- int i;
- const float *c;
- float *c2;
- if (!rsurface.passcolor4f)
- return;
- c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, c2 = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, c += 4, c2 += 4)
- {
- c2[0] = c[0] + rsurface.texture->render_lightmap_ambient[0];
- c2[1] = c[1] + rsurface.texture->render_lightmap_ambient[1];
- c2[2] = c[2] + rsurface.texture->render_lightmap_ambient[2];
- c2[3] = c[3];
- }
-}
-
-static void RSurf_DrawBatch_GL11_Lightmap(float r, float g, float b, float a, qboolean applycolor, qboolean applyfog)
-{
- // TODO: optimize
- rsurface.passcolor4f = NULL;
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- if (applyfog) RSurf_DrawBatch_GL11_ApplyFog();
- if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(r, g, b, a);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, rsurface.passcolor4f_vertexbuffer, rsurface.passcolor4f_bufferoffset);
- GL_Color(r, g, b, a);
- R_Mesh_TexBind(0, rsurface.lightmaptexture);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexMatrix(0, NULL);
- RSurf_DrawBatch();
-}
-
-static void RSurf_DrawBatch_GL11_Unlit(float r, float g, float b, float a, qboolean applycolor, qboolean applyfog)
-{
- // TODO: optimize applyfog && applycolor case
- // just apply fog if necessary, and tint the fog color array if necessary
- rsurface.passcolor4f = NULL;
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- if (applyfog) RSurf_DrawBatch_GL11_ApplyFog();
- if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(r, g, b, a);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, rsurface.passcolor4f_vertexbuffer, rsurface.passcolor4f_bufferoffset);
- GL_Color(r, g, b, a);
- RSurf_DrawBatch();
-}
-
-static void RSurf_DrawBatch_GL11_VertexColor(float r, float g, float b, float a, qboolean applycolor, qboolean applyfog)
-{
- // TODO: optimize
- rsurface.passcolor4f = rsurface.batchlightmapcolor4f;
- rsurface.passcolor4f_vertexbuffer = rsurface.batchlightmapcolor4f_vertexbuffer;
- rsurface.passcolor4f_bufferoffset = rsurface.batchlightmapcolor4f_bufferoffset;
- if (applyfog) RSurf_DrawBatch_GL11_ApplyFog();
- if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(r, g, b, a);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, rsurface.passcolor4f_vertexbuffer, rsurface.passcolor4f_bufferoffset);
- GL_Color(r, g, b, a);
- RSurf_DrawBatch();
-}
-
-static void RSurf_DrawBatch_GL11_ClampColor(void)
-{
- int i;
- const float *c1;
- float *c2;
- if (!rsurface.passcolor4f)
- return;
- for (i = 0, c1 = rsurface.passcolor4f + 4*rsurface.batchfirstvertex, c2 = rsurface.passcolor4f + 4*rsurface.batchfirstvertex;i < rsurface.batchnumvertices;i++, c1 += 4, c2 += 4)
- {
- c2[0] = bound(0.0f, c1[0], 1.0f);
- c2[1] = bound(0.0f, c1[1], 1.0f);
- c2[2] = bound(0.0f, c1[2], 1.0f);
- c2[3] = bound(0.0f, c1[3], 1.0f);
- }
-}
-
-static void RSurf_DrawBatch_GL11_ApplyFakeLight(float fakelightintensity)
-{
- int i;
- float f;
- const float *v;
- const float *n;
- float *c;
- //vec3_t eyedir;
-
- // fake shading
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3, n = rsurface.batchnormal3f + rsurface.batchfirstvertex * 3, c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, v += 3, n += 3, c += 4)
- {
- f = -DotProduct(r_refdef.view.forward, n);
- f = max(0, f);
- f = f * 0.85 + 0.15; // work around so stuff won't get black
- f *= fakelightintensity;
- Vector4Set(c, f, f, f, 1);
- }
-}
-
-static void RSurf_DrawBatch_GL11_FakeLight(float r, float g, float b, float a, qboolean applycolor, qboolean applyfog)
-{
- RSurf_DrawBatch_GL11_ApplyFakeLight(r_refdef.scene.lightmapintensity * r_fakelight_intensity.value);
- if (applyfog) RSurf_DrawBatch_GL11_ApplyFog();
- if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(r, g, b, a);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, rsurface.passcolor4f_vertexbuffer, rsurface.passcolor4f_bufferoffset);
- GL_Color(r, g, b, a);
- RSurf_DrawBatch();
-}
-
-static void RSurf_DrawBatch_GL11_ApplyVertexShade(float *r, float *g, float *b, float *a, float lightmapintensity, qboolean *applycolor)
-{
- int i;
- float f;
- float alpha;
- const float *v;
- const float *n;
- float *c;
- vec3_t ambientcolor;
- vec3_t diffusecolor;
- vec3_t lightdir;
- // TODO: optimize
- // model lighting
- VectorCopy(rsurface.texture->render_modellight_lightdir, lightdir);
- f = 0.5f * lightmapintensity;
- ambientcolor[0] = rsurface.texture->render_modellight_ambient[0] * *r * f;
- ambientcolor[1] = rsurface.texture->render_modellight_ambient[1] * *g * f;
- ambientcolor[2] = rsurface.texture->render_modellight_ambient[2] * *b * f;
- diffusecolor[0] = rsurface.texture->render_modellight_diffuse[0] * *r * f;
- diffusecolor[1] = rsurface.texture->render_modellight_diffuse[1] * *g * f;
- diffusecolor[2] = rsurface.texture->render_modellight_diffuse[2] * *b * f;
- alpha = *a;
- if (VectorLength2(diffusecolor) > 0)
- {
- // q3-style directional shading
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- for (i = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3, n = rsurface.batchnormal3f + rsurface.batchfirstvertex * 3, c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, v += 3, n += 3, c += 4)
- {
- if ((f = DotProduct(n, lightdir)) > 0)
- VectorMA(ambientcolor, f, diffusecolor, c);
- else
- VectorCopy(ambientcolor, c);
- c[3] = alpha;
- }
- *r = 1;
- *g = 1;
- *b = 1;
- *a = 1;
- *applycolor = false;
- }
- else
- {
- *r = ambientcolor[0];
- *g = ambientcolor[1];
- *b = ambientcolor[2];
- rsurface.passcolor4f = NULL;
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
- }
-}
-
-static void RSurf_DrawBatch_GL11_VertexShade(float r, float g, float b, float a, qboolean applycolor, qboolean applyfog)
-{
- RSurf_DrawBatch_GL11_ApplyVertexShade(&r, &g, &b, &a, r_refdef.scene.lightmapintensity, &applycolor);
- if (applyfog) RSurf_DrawBatch_GL11_ApplyFog();
- if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(r, g, b, a);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, rsurface.passcolor4f_vertexbuffer, rsurface.passcolor4f_bufferoffset);
- GL_Color(r, g, b, a);
- RSurf_DrawBatch();
-}
-
-static void RSurf_DrawBatch_GL11_MakeFogColor(float r, float g, float b, float a)
-{
- int i;
- float f;
- const float *v;
- float *c;
-
- // fake shading
- rsurface.passcolor4f = (float *)R_FrameData_Alloc(rsurface.batchnumvertices * sizeof(float[4]));
- rsurface.passcolor4f_vertexbuffer = 0;
- rsurface.passcolor4f_bufferoffset = 0;
-
- for (i = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3, c = rsurface.passcolor4f + rsurface.batchfirstvertex * 4;i < rsurface.batchnumvertices;i++, v += 3, c += 4)
- {
- f = 1 - RSurf_FogVertex(v);
- c[0] = r;
- c[1] = g;
- c[2] = b;
- c[3] = f * a;
- }
-}
-
void RSurf_SetupDepthAndCulling(void)
{
// submodels are biased to avoid z-fighting with world surfaces that they
RSurf_DrawBatch();
}
-static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth)
-{
- // OpenGL 1.3 path - anything not completely ancient
- qboolean applycolor;
- qboolean applyfog;
- int layerindex;
- const texturelayer_t *layer;
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | ((!rsurface.uselightmaptexture && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)) ? BATCHNEED_ARRAY_VERTEXCOLOR : 0) | BATCHNEED_ARRAY_TEXCOORD | (rsurface.modeltexcoordlightmap2f ? BATCHNEED_ARRAY_LIGHTMAP : 0) | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset);
-
- for (layerindex = 0, layer = rsurface.texture->currentlayers;layerindex < rsurface.texture->currentnumlayers;layerindex++, layer++)
- {
- vec4_t layercolor;
- int layertexrgbscale;
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
- {
- if (layerindex == 0)
- GL_AlphaTest(true);
- else
- {
- GL_AlphaTest(false);
- GL_DepthFunc(GL_EQUAL);
- }
- }
- GL_DepthMask(layer->depthmask && writedepth);
- GL_BlendFunc(layer->blendfunc1, layer->blendfunc2);
- if (layer->color[0] > 2 || layer->color[1] > 2 || layer->color[2] > 2)
- {
- layertexrgbscale = 4;
- VectorScale(layer->color, 0.25f, layercolor);
- }
- else if (layer->color[0] > 1 || layer->color[1] > 1 || layer->color[2] > 1)
- {
- layertexrgbscale = 2;
- VectorScale(layer->color, 0.5f, layercolor);
- }
- else
- {
- layertexrgbscale = 1;
- VectorScale(layer->color, 1.0f, layercolor);
- }
- layercolor[3] = layer->color[3];
- applycolor = layercolor[0] != 1 || layercolor[1] != 1 || layercolor[2] != 1 || layercolor[3] != 1;
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, 0, 0);
- applyfog = r_refdef.fogenabled && (rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED);
- switch (layer->type)
- {
- case TEXTURELAYERTYPE_LITTEXTURE:
- // single-pass lightmapped texture with 2x rgbscale
- R_Mesh_TexBind(0, r_texture_white);
- R_Mesh_TexMatrix(0, NULL);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordlightmap2f, rsurface.batchtexcoordlightmap2f_vertexbuffer, rsurface.batchtexcoordlightmap2f_bufferoffset);
- R_Mesh_TexBind(1, layer->texture);
- R_Mesh_TexMatrix(1, &layer->texmatrix);
- R_Mesh_TexCombine(1, GL_MODULATE, GL_MODULATE, layertexrgbscale, 1);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
- RSurf_DrawBatch_GL11_VertexShade(layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
- else if (FAKELIGHT_ENABLED)
- RSurf_DrawBatch_GL11_FakeLight(layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
- else if (rsurface.uselightmaptexture)
- RSurf_DrawBatch_GL11_Lightmap(layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
- else
- RSurf_DrawBatch_GL11_VertexColor(layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
- break;
- case TEXTURELAYERTYPE_TEXTURE:
- // singletexture unlit texture with transparency support
- R_Mesh_TexBind(0, layer->texture);
- R_Mesh_TexMatrix(0, &layer->texmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, layertexrgbscale, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- R_Mesh_TexBind(1, 0);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, 0, 0);
- RSurf_DrawBatch_GL11_Unlit(layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
- break;
- case TEXTURELAYERTYPE_FOG:
- // singletexture fogging
- if (layer->texture)
- {
- R_Mesh_TexBind(0, layer->texture);
- R_Mesh_TexMatrix(0, &layer->texmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, layertexrgbscale, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- }
- else
- {
- R_Mesh_TexBind(0, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, 0, 0);
- }
- R_Mesh_TexBind(1, 0);
- R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, 0, 0);
- // generate a color array for the fog pass
- RSurf_DrawBatch_GL11_MakeFogColor(layercolor[0], layercolor[1], layercolor[2], layercolor[3]);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, 0, 0);
- RSurf_DrawBatch();
- break;
- default:
- Con_Printf("R_DrawTextureSurfaceList: unknown layer type %i\n", layer->type);
- }
- }
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
- {
- GL_DepthFunc(GL_LEQUAL);
- GL_AlphaTest(false);
- }
-}
-
-static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth)
-{
- // OpenGL 1.1 - crusty old voodoo path
- qboolean applyfog;
- int layerindex;
- const texturelayer_t *layer;
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | ((!rsurface.uselightmaptexture && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)) ? BATCHNEED_ARRAY_VERTEXCOLOR : 0) | BATCHNEED_ARRAY_TEXCOORD | (rsurface.modeltexcoordlightmap2f ? BATCHNEED_ARRAY_LIGHTMAP : 0) | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset);
-
- for (layerindex = 0, layer = rsurface.texture->currentlayers;layerindex < rsurface.texture->currentnumlayers;layerindex++, layer++)
- {
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
- {
- if (layerindex == 0)
- GL_AlphaTest(true);
- else
- {
- GL_AlphaTest(false);
- GL_DepthFunc(GL_EQUAL);
- }
- }
- GL_DepthMask(layer->depthmask && writedepth);
- GL_BlendFunc(layer->blendfunc1, layer->blendfunc2);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), NULL, 0, 0);
- applyfog = r_refdef.fogenabled && (rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED);
- switch (layer->type)
- {
- case TEXTURELAYERTYPE_LITTEXTURE:
- if (layer->blendfunc1 == GL_ONE && layer->blendfunc2 == GL_ZERO && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))
- {
- // two-pass lit texture with 2x rgbscale
- // first the lightmap pass
- R_Mesh_TexBind(0, r_texture_white);
- R_Mesh_TexMatrix(0, NULL);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordlightmap2f, rsurface.batchtexcoordlightmap2f_vertexbuffer, rsurface.batchtexcoordlightmap2f_bufferoffset);
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
- RSurf_DrawBatch_GL11_VertexShade(1, 1, 1, 1, false, false);
- else if (FAKELIGHT_ENABLED)
- RSurf_DrawBatch_GL11_FakeLight(1, 1, 1, 1, false, false);
- else if (rsurface.uselightmaptexture)
- RSurf_DrawBatch_GL11_Lightmap(1, 1, 1, 1, false, false);
- else
- RSurf_DrawBatch_GL11_VertexColor(1, 1, 1, 1, false, false);
- // then apply the texture to it
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- R_Mesh_TexBind(0, layer->texture);
- R_Mesh_TexMatrix(0, &layer->texmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- RSurf_DrawBatch_GL11_Unlit(layer->color[0] * 0.5f, layer->color[1] * 0.5f, layer->color[2] * 0.5f, layer->color[3], layer->color[0] != 2 || layer->color[1] != 2 || layer->color[2] != 2 || layer->color[3] != 1, false);
- }
- else
- {
- // single pass vertex-lighting-only texture with 1x rgbscale and transparency support
- R_Mesh_TexBind(0, layer->texture);
- R_Mesh_TexMatrix(0, &layer->texmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
- RSurf_DrawBatch_GL11_VertexShade(layer->color[0], layer->color[1], layer->color[2], layer->color[3], layer->color[0] != 1 || layer->color[1] != 1 || layer->color[2] != 1 || layer->color[3] != 1, applyfog);
- else if (FAKELIGHT_ENABLED)
- RSurf_DrawBatch_GL11_FakeLight(layer->color[0], layer->color[1], layer->color[2], layer->color[3], layer->color[0] != 1 || layer->color[1] != 1 || layer->color[2] != 1 || layer->color[3] != 1, applyfog);
- else
- RSurf_DrawBatch_GL11_VertexColor(layer->color[0], layer->color[1], layer->color[2], layer->color[3], layer->color[0] != 1 || layer->color[1] != 1 || layer->color[2] != 1 || layer->color[3] != 1, applyfog);
- }
- break;
- case TEXTURELAYERTYPE_TEXTURE:
- // singletexture unlit texture with transparency support
- R_Mesh_TexBind(0, layer->texture);
- R_Mesh_TexMatrix(0, &layer->texmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- RSurf_DrawBatch_GL11_Unlit(layer->color[0], layer->color[1], layer->color[2], layer->color[3], layer->color[0] != 1 || layer->color[1] != 1 || layer->color[2] != 1 || layer->color[3] != 1, applyfog);
- break;
- case TEXTURELAYERTYPE_FOG:
- // singletexture fogging
- if (layer->texture)
- {
- R_Mesh_TexBind(0, layer->texture);
- R_Mesh_TexMatrix(0, &layer->texmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- }
- else
- {
- R_Mesh_TexBind(0, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), NULL, 0, 0);
- }
- // generate a color array for the fog pass
- RSurf_DrawBatch_GL11_MakeFogColor(layer->color[0], layer->color[1], layer->color[2], layer->color[3]);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, 0, 0);
- RSurf_DrawBatch();
- break;
- default:
- Con_Printf("R_DrawTextureSurfaceList: unknown layer type %i\n", layer->type);
- }
- }
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
- {
- GL_DepthFunc(GL_LEQUAL);
- GL_AlphaTest(false);
- }
-}
-
static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth)
{
int vi;
GL_DepthMask(writedepth);
}
- if (r_showsurfaces.integer == 3)
- {
- rsurface.passcolor4f = NULL;
-
- if (t->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
- {
- qboolean applycolor = true;
- float one = 1.0;
-
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
-
- RSurf_DrawBatch_GL11_ApplyVertexShade(&one, &one, &one, &one, 1.0f, &applycolor);
- }
- else if (FAKELIGHT_ENABLED)
- {
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
-
- RSurf_DrawBatch_GL11_ApplyFakeLight(r_fakelight_intensity.value);
- }
- else
- {
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_VERTEXCOLOR | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
-
- rsurface.passcolor4f = rsurface.batchlightmapcolor4f;
- rsurface.passcolor4f_vertexbuffer = rsurface.batchlightmapcolor4f_vertexbuffer;
- rsurface.passcolor4f_bufferoffset = rsurface.batchlightmapcolor4f_bufferoffset;
- RSurf_DrawBatch_GL11_ApplyAmbient();
- }
-
- if(!rsurface.passcolor4f)
- RSurf_DrawBatch_GL11_MakeFullbrightLightmapColorArray();
-
- RSurf_DrawBatch_GL11_ApplyColor(c[0], c[1], c[2], c[3]);
- if(r_refdef.fogenabled)
- RSurf_DrawBatch_GL11_ApplyFogToFinishedVertexColors();
- RSurf_DrawBatch_GL11_ClampColor();
-
- R_Mesh_PrepareVertices_Generic_Arrays(rsurface.batchnumvertices, rsurface.batchvertex3f, rsurface.passcolor4f, NULL);
- R_SetupShader_Generic_NoTexture(false, false);
- RSurf_DrawBatch();
- }
- else if (!r_refdef.view.showdebug)
+ if (!r_refdef.view.showdebug)
{
RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
batchvertex = R_Mesh_PrepareVertices_Generic_Lock(rsurface.batchnumvertices);
batchvertex = R_Mesh_PrepareVertices_Generic_Lock(rsurface.batchnumvertices);
for (j = 0, vi = 0;j < rsurface.batchnumvertices;j++, vi++)
{
- unsigned char d = (vi << 3) * (1.0f / 256.0f);
+ float d = (vi << 3) * (1.0f / 256.0f);
VectorCopy(rsurface.batchvertex3f + 3*vi, batchvertex[vi].vertex3f);
Vector4Set(batchvertex[vi].color4f, d, d, d, 1);
}
batchvertex = R_Mesh_PrepareVertices_Generic_Lock(3*rsurface.batchnumtriangles);
for (j = 0, e = rsurface.batchelement3i + 3 * rsurface.batchfirsttriangle;j < rsurface.batchnumtriangles;j++, e += 3)
{
- unsigned char d = ((j + rsurface.batchfirsttriangle) << 3) * (1.0f / 256.0f);
+ float d = ((j + rsurface.batchfirsttriangle) << 3) * (1.0f / 256.0f);
VectorCopy(rsurface.batchvertex3f + 3*e[0], batchvertex[j*3+0].vertex3f);
VectorCopy(rsurface.batchvertex3f + 3*e[1], batchvertex[j*3+1].vertex3f);
VectorCopy(rsurface.batchvertex3f + 3*e[2], batchvertex[j*3+2].vertex3f);
switch (vid.renderpath)
{
case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
case RENDERPATH_GLES2:
R_DrawTextureSurfaceList_GL20(texturenumsurfaces, texturesurfacelist, writedepth, prepass);
break;
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- R_DrawTextureSurfaceList_GL13(texturenumsurfaces, texturesurfacelist, writedepth);
- break;
- case RENDERPATH_GL11:
- R_DrawTextureSurfaceList_GL11(texturenumsurfaces, texturesurfacelist, writedepth);
- break;
}
CHECKGLERROR
}
const msurface_t *surface;
const msurface_t *texturesurfacelist[MESHQUEUE_TRANSPARENT_BATCHSIZE];
- if (r_showsurfaces.integer && r_showsurfaces.integer != 3)
- RSurf_ActiveModelEntity(ent, false, false, false);
- else
- {
- switch (vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- RSurf_ActiveModelEntity(ent, true, true, false);
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- RSurf_ActiveModelEntity(ent, true, false, false);
- break;
- }
- }
+ RSurf_ActiveModelEntity(ent, true, true, false);
if (r_transparentdepthmasking.integer)
{
rsurface.texture = NULL;
}
+# if 0
+ // FIXME! implement r_shownormals with just triangles
if (r_shownormals.value != 0 && qglBegin)
{
int l, k;
}
rsurface.texture = NULL;
}
+# endif
#endif
}
else if (prepass)
RSurf_ActiveModelEntity(ent, true, true, true);
else if (depthonly)
- {
- switch (vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- RSurf_ActiveModelEntity(ent, model->wantnormals, model->wanttangents, false);
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- RSurf_ActiveModelEntity(ent, model->wantnormals, false, false);
- break;
- }
- }
+ RSurf_ActiveModelEntity(ent, model->wantnormals, model->wanttangents, false);
else
- {
- switch (vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- RSurf_ActiveModelEntity(ent, true, true, false);
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- RSurf_ActiveModelEntity(ent, true, false, false);
- break;
- }
- }
+ RSurf_ActiveModelEntity(ent, true, true, false);
surfaces = model->data_surfaces;
update = model->brushq1.lightmapupdateflags;
#include "quakedef.h"
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-extern LPDIRECT3DDEVICE9 vid_d3d9dev;
-#endif
#include "image.h"
#include "jpeg.h"
#include "image_png.h"
#include "intoverflow.h"
-#include "dpsoftrast.h"
#ifndef GL_TEXTURE_3D
#define GL_TEXTURE_3D 0x806F
qboolean gl_filter_force = false;
int gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
int gl_filter_mag = GL_LINEAR;
-DPSOFTRAST_TEXTURE_FILTER dpsoftrast_filter_mipmap = DPSOFTRAST_TEXTURE_FILTER_LINEAR_MIPMAP_TRIANGLE;
-DPSOFTRAST_TEXTURE_FILTER dpsoftrast_filter_nomipmap = DPSOFTRAST_TEXTURE_FILTER_LINEAR;
-
-#ifdef SUPPORTD3D
-int d3d_filter_flatmin = D3DTEXF_LINEAR;
-int d3d_filter_flatmag = D3DTEXF_LINEAR;
-int d3d_filter_flatmix = D3DTEXF_POINT;
-int d3d_filter_mipmin = D3DTEXF_LINEAR;
-int d3d_filter_mipmag = D3DTEXF_LINEAR;
-int d3d_filter_mipmix = D3DTEXF_LINEAR;
-int d3d_filter_nomip = false;
-#endif
static mempool_t *texturemempool;
qboolean dirty; // indicates that R_RealGetTexture should be called
qboolean glisdepthstencil; // indicates that FBO attachment has to be GL_DEPTH_STENCIL_ATTACHMENT
int gltexturetypeenum; // used by R_Mesh_TexBind
- // d3d stuff the backend needs
- void *d3dtexture;
- void *d3dsurface;
-#ifdef SUPPORTD3D
- qboolean d3disrendertargetsurface;
- qboolean d3disdepthstencilsurface;
- int d3dformat;
- int d3dusage;
- int d3dpool;
- int d3daddressu;
- int d3daddressv;
- int d3daddressw;
- int d3dmagfilter;
- int d3dminfilter;
- int d3dmipfilter;
- int d3dmaxmiplevelfilter;
- int d3dmipmaplodbias;
- int d3dmaxmiplevel;
-#endif
// dynamic texture stuff [11/22/2007 Black]
updatecallback_t updatecallback;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (glt->texnum)
{
qglDeleteRenderbuffers(1, (GLuint *)&glt->renderbuffernum);CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (glt->d3dsurface)
- IDirect3DSurface9_Release((IDirect3DSurface9 *)glt->d3dsurface);
- else if (glt->tiledepth > 1)
- IDirect3DVolumeTexture9_Release((IDirect3DVolumeTexture9 *)glt->d3dtexture);
- else if (glt->sides == 6)
- IDirect3DCubeTexture9_Release((IDirect3DCubeTexture9 *)glt->d3dtexture);
- else
- IDirect3DTexture9_Release((IDirect3DTexture9 *)glt->d3dtexture);
- glt->d3dtexture = NULL;
- glt->d3dsurface = NULL;
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (glt->texnum)
- DPSOFTRAST_Texture_Free(glt->texnum);
- break;
}
if (glt->inputtexels)
{
const char *name;
int minification, magnification;
- DPSOFTRAST_TEXTURE_FILTER dpsoftrastfilter_mipmap, dpsoftrastfilter_nomipmap;
}
glmode_t;
static glmode_t modes[6] =
{
- {"GL_NEAREST", GL_NEAREST, GL_NEAREST, DPSOFTRAST_TEXTURE_FILTER_NEAREST, DPSOFTRAST_TEXTURE_FILTER_NEAREST},
- {"GL_LINEAR", GL_LINEAR, GL_LINEAR, DPSOFTRAST_TEXTURE_FILTER_LINEAR, DPSOFTRAST_TEXTURE_FILTER_LINEAR},
- {"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST, DPSOFTRAST_TEXTURE_FILTER_NEAREST_MIPMAP_TRIANGLE, DPSOFTRAST_TEXTURE_FILTER_NEAREST},
- {"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR, DPSOFTRAST_TEXTURE_FILTER_LINEAR_MIPMAP_TRIANGLE, DPSOFTRAST_TEXTURE_FILTER_LINEAR},
- {"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST, DPSOFTRAST_TEXTURE_FILTER_NEAREST_MIPMAP_TRIANGLE, DPSOFTRAST_TEXTURE_FILTER_NEAREST},
- {"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, DPSOFTRAST_TEXTURE_FILTER_LINEAR_MIPMAP_TRIANGLE, DPSOFTRAST_TEXTURE_FILTER_LINEAR}
+ {"GL_NEAREST", GL_NEAREST, GL_NEAREST},
+ {"GL_LINEAR", GL_LINEAR, GL_LINEAR},
+ {"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
+ {"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
+ {"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
+ {"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
};
-#ifdef SUPPORTD3D
-typedef struct d3dmode_s
-{
- const char *name;
- int m1, m2;
-}
-d3dmode_t;
-
-static d3dmode_t d3dmodes[6] =
-{
- {"GL_NEAREST", D3DTEXF_POINT, D3DTEXF_POINT},
- {"GL_LINEAR", D3DTEXF_LINEAR, D3DTEXF_POINT},
- {"GL_NEAREST_MIPMAP_NEAREST", D3DTEXF_POINT, D3DTEXF_POINT},
- {"GL_LINEAR_MIPMAP_NEAREST", D3DTEXF_LINEAR, D3DTEXF_POINT},
- {"GL_NEAREST_MIPMAP_LINEAR", D3DTEXF_POINT, D3DTEXF_LINEAR},
- {"GL_LINEAR_MIPMAP_LINEAR", D3DTEXF_LINEAR, D3DTEXF_LINEAR}
-};
-#endif
-
static void GL_TextureMode_f (void)
{
int i;
gl_filter_mag = modes[i].magnification;
gl_filter_force = ((Cmd_Argc() > 2) && !strcasecmp(Cmd_Argv(2), "force"));
- dpsoftrast_filter_mipmap = modes[i].dpsoftrastfilter_mipmap;
- dpsoftrast_filter_nomipmap = modes[i].dpsoftrastfilter_nomipmap;
-
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// change all the existing mipmap texture objects
// FIXME: force renderer(/client/something?) restart instead?
}
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- d3d_filter_flatmin = d3dmodes[i].m1;
- d3d_filter_flatmag = d3dmodes[i].m1;
- d3d_filter_flatmix = D3DTEXF_POINT;
- d3d_filter_mipmin = d3dmodes[i].m1;
- d3d_filter_mipmag = d3dmodes[i].m1;
- d3d_filter_mipmix = d3dmodes[i].m2;
- d3d_filter_nomip = i < 2;
- if (gl_texture_anisotropy.integer > 1 && i == 5)
- d3d_filter_mipmin = d3d_filter_mipmag = D3DTEXF_ANISOTROPIC;
- for (pool = gltexturepoolchain;pool;pool = pool->next)
- {
- for (glt = pool->gltchain;glt;glt = glt->chain)
- {
- // only update already uploaded images
- if (glt->d3dtexture && !glt->d3dsurface && (gl_filter_force || !(glt->flags & (TEXF_FORCENEAREST | TEXF_FORCELINEAR))))
- {
- if (glt->flags & TEXF_MIPMAP)
- {
- glt->d3dminfilter = d3d_filter_mipmin;
- glt->d3dmagfilter = d3d_filter_mipmag;
- glt->d3dmipfilter = d3d_filter_mipmix;
- glt->d3dmaxmiplevelfilter = 0;
- }
- else
- {
- glt->d3dminfilter = d3d_filter_flatmin;
- glt->d3dmagfilter = d3d_filter_flatmag;
- glt->d3dmipfilter = d3d_filter_flatmix;
- glt->d3dmaxmiplevelfilter = 0;
- }
- }
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- // change all the existing texture objects
- for (pool = gltexturepoolchain;pool;pool = pool->next)
- for (glt = pool->gltchain;glt;glt = glt->chain)
- if (glt->texnum && (gl_filter_force || !(glt->flags & (TEXF_FORCENEAREST | TEXF_FORCELINEAR))))
- DPSOFTRAST_Texture_Filter(glt->texnum, (glt->flags & TEXF_MIPMAP) ? dpsoftrast_filter_mipmap : dpsoftrast_filter_nomipmap);
- break;
}
}
for (depth2 >>= picmip;depth2 > maxsize;depth2 >>= 1);
}
- switch(vid.renderpath)
- {
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GL20:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
- break;
- case RENDERPATH_D3D9:
-#if 0
- // for some reason the REF rasterizer (and hence the PIX debugger) does not like small textures...
- if (texturetype == GLTEXTURETYPE_2D)
- {
- width2 = max(width2, 2);
- height2 = max(height2, 2);
- }
-#endif
- break;
- }
-
miplevels = 1;
if (flags & TEXF_MIPMAP)
{
for (glt = pool->gltchain;glt;glt = glt->chain)
{
glsize = R_CalcTexelDataSize(glt);
- isloaded = glt->texnum != 0 || glt->renderbuffernum != 0 || glt->d3dtexture || glt->d3dsurface;
+ isloaded = glt->texnum != 0 || glt->renderbuffernum != 0;
pooltotal++;
pooltotalt += glsize;
pooltotalp += glt->inputdatasize;
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// LordHavoc: allow any alignment
CHECKGLERROR
qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);CHECKGLERROR
qglPixelStorei(GL_PACK_ALIGNMENT, 1);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
texturemempool = Mem_AllocPool("texture management", 0, NULL);
continue;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (glt->d3dsurface)
- IDirect3DSurface9_Release((IDirect3DSurface9 *)glt->d3dsurface);
- else if (glt->tiledepth > 1)
- IDirect3DVolumeTexture9_Release((IDirect3DVolumeTexture9 *)glt->d3dtexture);
- else if (glt->sides == 6)
- IDirect3DCubeTexture9_Release((IDirect3DCubeTexture9 *)glt->d3dtexture);
- else
- IDirect3DTexture9_Release((IDirect3DTexture9 *)glt->d3dtexture);
- glt->d3dtexture = NULL;
- glt->d3dsurface = NULL;
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
}
}
continue;
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- HRESULT d3dresult;
- if (glt->d3disrendertargetsurface)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateRenderTarget(vid_d3d9dev, glt->tilewidth, glt->tileheight, (D3DFORMAT)glt->d3dformat, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)&glt->d3dsurface, NULL)))
- Sys_Error("IDirect3DDevice9_CreateRenderTarget failed!");
- }
- else if (glt->d3disdepthstencilsurface)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateDepthStencilSurface(vid_d3d9dev, glt->tilewidth, glt->tileheight, (D3DFORMAT)glt->d3dformat, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)&glt->d3dsurface, NULL)))
- Sys_Error("IDirect3DDevice9_CreateDepthStencilSurface failed!");
- }
- else if (glt->tiledepth > 1)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateVolumeTexture(vid_d3d9dev, glt->tilewidth, glt->tileheight, glt->tiledepth, glt->miplevels, glt->d3dusage, (D3DFORMAT)glt->d3dformat, (D3DPOOL)glt->d3dpool, (IDirect3DVolumeTexture9 **)&glt->d3dtexture, NULL)))
- Sys_Error("IDirect3DDevice9_CreateVolumeTexture failed!");
- }
- else if (glt->sides == 6)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateCubeTexture(vid_d3d9dev, glt->tilewidth, glt->miplevels, glt->d3dusage, (D3DFORMAT)glt->d3dformat, (D3DPOOL)glt->d3dpool, (IDirect3DCubeTexture9 **)&glt->d3dtexture, NULL)))
- Sys_Error("IDirect3DDevice9_CreateCubeTexture failed!");
- }
- else
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateTexture(vid_d3d9dev, glt->tilewidth, glt->tileheight, glt->miplevels, glt->d3dusage, (D3DFORMAT)glt->d3dformat, (D3DPOOL)glt->d3dpool, (IDirect3DTexture9 **)&glt->d3dtexture, NULL)))
- Sys_Error("IDirect3DDevice9_CreateTexture failed!");
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- break;
}
}
}
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
// ignore the first difference, any textures loaded by now probably had the same aniso value
if (first_time_aniso)
}
}
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- break;
}
}
#endif
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
{
int oldbindtexnum;
qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- RECT d3drect;
- D3DLOCKED_RECT d3dlockedrect;
- int y;
- memset(&d3drect, 0, sizeof(d3drect));
- d3drect.left = fragx;
- d3drect.top = fragy;
- d3drect.right = fragx+fragwidth;
- d3drect.bottom = fragy+fragheight;
- if (IDirect3DTexture9_LockRect((IDirect3DTexture9*)glt->d3dtexture, 0, &d3dlockedrect, &d3drect, 0) == D3D_OK && d3dlockedrect.pBits)
- {
- for (y = 0;y < fragheight;y++)
- memcpy((unsigned char *)d3dlockedrect.pBits + d3dlockedrect.Pitch * y, data + fragwidth*glt->bytesperpixel * y, fragwidth*glt->bytesperpixel);
- IDirect3DTexture9_UnlockRect((IDirect3DTexture9*)glt->d3dtexture, 0);
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Texture_UpdatePartial(glt->texnum, 0, data, fragx, fragy, fragwidth, fragheight);
- break;
}
}
// do the appropriate upload type...
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (glt->texnum) // not renderbuffers
{
qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (!(glt->flags & TEXF_RENDERTARGET) && glt->d3dtexture && !glt->d3dsurface)
- {
- D3DLOCKED_RECT d3dlockedrect;
- D3DLOCKED_BOX d3dlockedbox;
- switch(glt->texturetype)
- {
- case GLTEXTURETYPE_2D:
- if (IDirect3DTexture9_LockRect((IDirect3DTexture9*)glt->d3dtexture, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits)
- {
- if (prevbuffer)
- memcpy(d3dlockedrect.pBits, prevbuffer, width*height*glt->bytesperpixel);
- else
- memset(d3dlockedrect.pBits, 255, width*height*glt->bytesperpixel);
- IDirect3DTexture9_UnlockRect((IDirect3DTexture9*)glt->d3dtexture, mip);
- }
- mip++;
- if ((glt->flags & TEXF_MIPMAP) && prevbuffer)
- {
- while (width > 1 || height > 1 || depth > 1)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
- prevbuffer = resizebuffer;
- if (IDirect3DTexture9_LockRect((IDirect3DTexture9*)glt->d3dtexture, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits)
- {
- memcpy(d3dlockedrect.pBits, prevbuffer, width*height*glt->bytesperpixel);
- IDirect3DTexture9_UnlockRect((IDirect3DTexture9*)glt->d3dtexture, mip);
- }
- mip++;
- }
- }
- break;
- case GLTEXTURETYPE_3D:
- if (IDirect3DVolumeTexture9_LockBox((IDirect3DVolumeTexture9*)glt->d3dtexture, mip, &d3dlockedbox, NULL, 0) == D3D_OK && d3dlockedbox.pBits)
- {
- // we are not honoring the RowPitch or SlicePitch, hopefully this works with all sizes
- memcpy(d3dlockedbox.pBits, prevbuffer, width*height*depth*glt->bytesperpixel);
- IDirect3DVolumeTexture9_UnlockBox((IDirect3DVolumeTexture9*)glt->d3dtexture, mip);
- }
- mip++;
- if (glt->flags & TEXF_MIPMAP)
- {
- while (width > 1 || height > 1 || depth > 1)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
- prevbuffer = resizebuffer;
- if (IDirect3DVolumeTexture9_LockBox((IDirect3DVolumeTexture9*)glt->d3dtexture, mip, &d3dlockedbox, NULL, 0) == D3D_OK && d3dlockedbox.pBits)
- {
- // we are not honoring the RowPitch or SlicePitch, hopefully this works with all sizes
- memcpy(d3dlockedbox.pBits, prevbuffer, width*height*depth*glt->bytesperpixel);
- IDirect3DVolumeTexture9_UnlockBox((IDirect3DVolumeTexture9*)glt->d3dtexture, mip);
- }
- mip++;
- }
- }
- break;
- case GLTEXTURETYPE_CUBEMAP:
- // convert and upload each side in turn,
- // from a continuous block of input texels
- texturebuffer = (unsigned char *)prevbuffer;
- for (i = 0;i < 6;i++)
- {
- prevbuffer = texturebuffer;
- texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel;
- if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer);
- prevbuffer = resizebuffer;
- }
- // picmip/max_size
- while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth);
- prevbuffer = resizebuffer;
- }
- mip = 0;
- if (IDirect3DCubeTexture9_LockRect((IDirect3DCubeTexture9*)glt->d3dtexture, (D3DCUBEMAP_FACES)i, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits)
- {
- memcpy(d3dlockedrect.pBits, prevbuffer, width*height*glt->bytesperpixel);
- IDirect3DCubeTexture9_UnlockRect((IDirect3DCubeTexture9*)glt->d3dtexture, (D3DCUBEMAP_FACES)i, mip);
- }
- mip++;
- if (glt->flags & TEXF_MIPMAP)
- {
- while (width > 1 || height > 1 || depth > 1)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
- prevbuffer = resizebuffer;
- if (IDirect3DCubeTexture9_LockRect((IDirect3DCubeTexture9*)glt->d3dtexture, (D3DCUBEMAP_FACES)i, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits)
- {
- memcpy(d3dlockedrect.pBits, prevbuffer, width*height*glt->bytesperpixel);
- IDirect3DCubeTexture9_UnlockRect((IDirect3DCubeTexture9*)glt->d3dtexture, (D3DCUBEMAP_FACES)i, mip);
- }
- mip++;
- }
- }
- }
- break;
- }
- }
- glt->d3daddressw = 0;
- if (glt->flags & TEXF_CLAMP)
- {
- glt->d3daddressu = D3DTADDRESS_CLAMP;
- glt->d3daddressv = D3DTADDRESS_CLAMP;
- if (glt->tiledepth > 1)
- glt->d3daddressw = D3DTADDRESS_CLAMP;
- }
- else
- {
- glt->d3daddressu = D3DTADDRESS_WRAP;
- glt->d3daddressv = D3DTADDRESS_WRAP;
- if (glt->tiledepth > 1)
- glt->d3daddressw = D3DTADDRESS_WRAP;
- }
- glt->d3dmipmaplodbias = 0;
- glt->d3dmaxmiplevel = 0;
- glt->d3dmaxmiplevelfilter = d3d_filter_nomip ? 0 : glt->d3dmaxmiplevel;
- if (glt->flags & TEXF_FORCELINEAR)
- {
- glt->d3dminfilter = D3DTEXF_LINEAR;
- glt->d3dmagfilter = D3DTEXF_LINEAR;
- glt->d3dmipfilter = D3DTEXF_POINT;
- }
- else if (glt->flags & TEXF_FORCENEAREST)
- {
- glt->d3dminfilter = D3DTEXF_POINT;
- glt->d3dmagfilter = D3DTEXF_POINT;
- glt->d3dmipfilter = D3DTEXF_POINT;
- }
- else if (glt->flags & TEXF_MIPMAP)
- {
- glt->d3dminfilter = d3d_filter_mipmin;
- glt->d3dmagfilter = d3d_filter_mipmag;
- glt->d3dmipfilter = d3d_filter_mipmix;
- }
- else
- {
- glt->d3dminfilter = d3d_filter_flatmin;
- glt->d3dmagfilter = d3d_filter_flatmag;
- glt->d3dmipfilter = d3d_filter_flatmix;
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- switch(glt->texturetype)
- {
- case GLTEXTURETYPE_2D:
- DPSOFTRAST_Texture_UpdateFull(glt->texnum, prevbuffer);
- break;
- case GLTEXTURETYPE_3D:
- DPSOFTRAST_Texture_UpdateFull(glt->texnum, prevbuffer);
- break;
- case GLTEXTURETYPE_CUBEMAP:
- if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
- {
- unsigned char *combinedbuffer = (unsigned char *)Mem_Alloc(tempmempool, glt->tilewidth*glt->tileheight*glt->tiledepth*glt->sides*glt->bytesperpixel);
- // convert and upload each side in turn,
- // from a continuous block of input texels
- // copy the results into combinedbuffer
- texturebuffer = (unsigned char *)prevbuffer;
- for (i = 0;i < 6;i++)
- {
- prevbuffer = texturebuffer;
- texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel;
- if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer);
- prevbuffer = resizebuffer;
- }
- // picmip/max_size
- while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth)
- {
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
- Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth);
- prevbuffer = resizebuffer;
- }
- memcpy(combinedbuffer + i*glt->tilewidth*glt->tileheight*glt->tiledepth*glt->bytesperpixel, prevbuffer, glt->tilewidth*glt->tileheight*glt->tiledepth*glt->bytesperpixel);
- }
- DPSOFTRAST_Texture_UpdateFull(glt->texnum, combinedbuffer);
- Mem_Free(combinedbuffer);
- }
- else
- DPSOFTRAST_Texture_UpdateFull(glt->texnum, prevbuffer);
- break;
- }
- if (glt->flags & TEXF_FORCELINEAR)
- DPSOFTRAST_Texture_Filter(glt->texnum, DPSOFTRAST_TEXTURE_FILTER_LINEAR);
- else if (glt->flags & TEXF_FORCENEAREST)
- DPSOFTRAST_Texture_Filter(glt->texnum, DPSOFTRAST_TEXTURE_FILTER_NEAREST);
- else if (glt->flags & TEXF_MIPMAP)
- DPSOFTRAST_Texture_Filter(glt->texnum, dpsoftrast_filter_mipmap);
- else
- DPSOFTRAST_Texture_Filter(glt->texnum, dpsoftrast_filter_nomipmap);
- break;
}
}
// data may be NULL (blank texture for dynamic rendering)
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
qglGenTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- D3DFORMAT d3dformat;
- D3DPOOL d3dpool;
- DWORD d3dusage;
- HRESULT d3dresult;
- d3dusage = 0;
- d3dpool = D3DPOOL_MANAGED;
- if (flags & TEXF_RENDERTARGET)
- {
- d3dusage |= D3DUSAGE_RENDERTARGET;
- d3dpool = D3DPOOL_DEFAULT;
- }
- switch(textype)
- {
- case TEXTYPE_PALETTE: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8;break;
- case TEXTYPE_RGBA: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8B8G8R8 : D3DFMT_X8B8G8R8;break;
- case TEXTYPE_BGRA: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8;break;
- case TEXTYPE_COLORBUFFER: d3dformat = D3DFMT_A8R8G8B8;break;
- case TEXTYPE_COLORBUFFER16F: d3dformat = D3DFMT_A16B16G16R16F;break;
- case TEXTYPE_COLORBUFFER32F: d3dformat = D3DFMT_A32B32G32R32F;break;
- case TEXTYPE_ALPHA: d3dformat = D3DFMT_A8;break;
- default: d3dformat = D3DFMT_A8R8G8B8;Sys_Error("R_LoadTexture: unsupported texture type %i when picking D3DFMT", (int)textype);break;
- }
- glt->d3dformat = d3dformat;
- glt->d3dusage = d3dusage;
- glt->d3dpool = d3dpool;
- glt->d3disrendertargetsurface = false;
- glt->d3disdepthstencilsurface = false;
- if (glt->tiledepth > 1)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateVolumeTexture(vid_d3d9dev, glt->tilewidth, glt->tileheight, glt->tiledepth, glt->miplevels, glt->d3dusage, (D3DFORMAT)glt->d3dformat, (D3DPOOL)glt->d3dpool, (IDirect3DVolumeTexture9 **)&glt->d3dtexture, NULL)))
- Sys_Error("IDirect3DDevice9_CreateVolumeTexture failed!");
- }
- else if (glt->sides == 6)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateCubeTexture(vid_d3d9dev, glt->tilewidth, glt->miplevels, glt->d3dusage, (D3DFORMAT)glt->d3dformat, (D3DPOOL)glt->d3dpool, (IDirect3DCubeTexture9 **)&glt->d3dtexture, NULL)))
- Sys_Error("IDirect3DDevice9_CreateCubeTexture failed!");
- }
- else
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateTexture(vid_d3d9dev, glt->tilewidth, glt->tileheight, glt->miplevels, glt->d3dusage, (D3DFORMAT)glt->d3dformat, (D3DPOOL)glt->d3dpool, (IDirect3DTexture9 **)&glt->d3dtexture, NULL)))
- Sys_Error("IDirect3DDevice9_CreateTexture failed!");
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- {
- int tflags = 0;
- switch(textype)
- {
- case TEXTYPE_PALETTE: tflags = DPSOFTRAST_TEXTURE_FORMAT_BGRA8;break;
- case TEXTYPE_RGBA: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA8;break;
- case TEXTYPE_BGRA: tflags = DPSOFTRAST_TEXTURE_FORMAT_BGRA8;break;
- case TEXTYPE_COLORBUFFER: tflags = DPSOFTRAST_TEXTURE_FORMAT_BGRA8;break;
- case TEXTYPE_COLORBUFFER16F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA16F;break;
- case TEXTYPE_COLORBUFFER32F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA32F;break;
- case TEXTYPE_SHADOWMAP16_COMP:
- case TEXTYPE_SHADOWMAP16_RAW:
- case TEXTYPE_SHADOWMAP24_COMP:
- case TEXTYPE_SHADOWMAP24_RAW: tflags = DPSOFTRAST_TEXTURE_FORMAT_DEPTH;break;
- case TEXTYPE_DEPTHBUFFER16:
- case TEXTYPE_DEPTHBUFFER24:
- case TEXTYPE_DEPTHBUFFER24STENCIL8: tflags = DPSOFTRAST_TEXTURE_FORMAT_DEPTH;break;
- case TEXTYPE_ALPHA: tflags = DPSOFTRAST_TEXTURE_FORMAT_ALPHA8;break;
- default: Sys_Error("R_LoadTexture: unsupported texture type %i when picking DPSOFTRAST_TEXTURE_FLAGS", (int)textype);
- }
- if (glt->miplevels > 1) tflags |= DPSOFTRAST_TEXTURE_FLAG_MIPMAP;
- if (flags & TEXF_ALPHA) tflags |= DPSOFTRAST_TEXTURE_FLAG_USEALPHA;
- if (glt->sides == 6) tflags |= DPSOFTRAST_TEXTURE_FLAG_CUBEMAP;
- if (glt->flags & TEXF_CLAMP) tflags |= DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE;
- glt->texnum = DPSOFTRAST_Texture_New(tflags, glt->tilewidth, glt->tileheight, glt->tiledepth);
- }
- break;
}
R_UploadFullTexture(glt, data);
// data may be NULL (blank texture for dynamic rendering)
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
qglGenRenderbuffers(1, (GLuint *)&glt->renderbuffernum);CHECKGLERROR
// note we can query the renderbuffer for info with glGetRenderbufferParameteriv for GL_WIDTH, GL_HEIGHt, GL_RED_SIZE, GL_GREEN_SIZE, GL_BLUE_SIZE, GL_GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_INTERNAL_FORMAT
qglBindRenderbuffer(GL_RENDERBUFFER, 0);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- D3DFORMAT d3dformat;
- HRESULT d3dresult;
- glt->d3disrendertargetsurface = false;
- glt->d3disdepthstencilsurface = false;
- switch(textype)
- {
- case TEXTYPE_COLORBUFFER: d3dformat = D3DFMT_A8R8G8B8;glt->d3disrendertargetsurface = true;break;
- case TEXTYPE_COLORBUFFER16F: d3dformat = D3DFMT_A16B16G16R16F;glt->d3disrendertargetsurface = true;break;
- case TEXTYPE_COLORBUFFER32F: d3dformat = D3DFMT_A32B32G32R32F;glt->d3disrendertargetsurface = true;break;
- case TEXTYPE_DEPTHBUFFER16: d3dformat = D3DFMT_D16;glt->d3disdepthstencilsurface = true;break;
- case TEXTYPE_DEPTHBUFFER24: d3dformat = D3DFMT_D24X8;glt->d3disdepthstencilsurface = true;break;
- case TEXTYPE_DEPTHBUFFER24STENCIL8: d3dformat = D3DFMT_D24S8;glt->d3disdepthstencilsurface = true;break;
- default: d3dformat = D3DFMT_A8R8G8B8;Sys_Error("R_LoadTextureRenderbuffer: unsupported texture type %i when picking D3DFMT", (int)textype);break;
- }
- glt->d3dformat = d3dformat;
- glt->d3dusage = 0;
- glt->d3dpool = 0;
- if (glt->d3disrendertargetsurface)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateRenderTarget(vid_d3d9dev, glt->tilewidth, glt->tileheight, (D3DFORMAT)glt->d3dformat, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)&glt->d3dsurface, NULL)))
- Sys_Error("IDirect3DDevice9_CreateRenderTarget failed!");
- }
- else if (glt->d3disdepthstencilsurface)
- {
- if (FAILED(d3dresult = IDirect3DDevice9_CreateDepthStencilSurface(vid_d3d9dev, glt->tilewidth, glt->tileheight, (D3DFORMAT)glt->d3dformat, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)&glt->d3dsurface, NULL)))
- Sys_Error("IDirect3DDevice9_CreateDepthStencilSurface failed!");
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- {
- int tflags = 0;
- switch(textype)
- {
- case TEXTYPE_COLORBUFFER: tflags = DPSOFTRAST_TEXTURE_FORMAT_BGRA8 | DPSOFTRAST_TEXTURE_FLAG_USEALPHA | DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE;break;
- case TEXTYPE_COLORBUFFER16F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA16F | DPSOFTRAST_TEXTURE_FLAG_USEALPHA | DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE;break;
- case TEXTYPE_COLORBUFFER32F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA32F | DPSOFTRAST_TEXTURE_FLAG_USEALPHA | DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE;break;
- case TEXTYPE_DEPTHBUFFER16:
- case TEXTYPE_DEPTHBUFFER24:
- case TEXTYPE_DEPTHBUFFER24STENCIL8: tflags = DPSOFTRAST_TEXTURE_FORMAT_DEPTH | DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE;break;
- default: Sys_Error("R_LoadTextureRenderbuffer: unsupported texture type %i when picking DPSOFTRAST_TEXTURE_FLAGS", (int)textype);
- }
- glt->texnum = DPSOFTRAST_Texture_New(tflags, glt->tilewidth, glt->tileheight, glt->tiledepth);
- }
- break;
}
return (rtexture_t *)glt;
// create the texture object
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
GL_ActiveTexture(0);
qglGenTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- D3DFORMAT d3dformat;
- D3DPOOL d3dpool;
- DWORD d3dusage;
- switch(textype)
- {
- case TEXTYPE_BGRA: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8;break;
- case TEXTYPE_DXT1: case TEXTYPE_DXT1A: d3dformat = D3DFMT_DXT1;break;
- case TEXTYPE_DXT3: d3dformat = D3DFMT_DXT3;break;
- case TEXTYPE_DXT5: d3dformat = D3DFMT_DXT5;break;
- default: d3dformat = D3DFMT_A8R8G8B8;Host_Error("R_LoadTextureDDSFile: unsupported texture type %i when picking D3DFMT", (int)textype);break;
- }
- d3dusage = 0;
- d3dpool = D3DPOOL_MANAGED;
- IDirect3DDevice9_CreateTexture(vid_d3d9dev, glt->tilewidth, glt->tileheight, glt->miplevels, d3dusage, d3dformat, d3dpool, (IDirect3DTexture9 **)&glt->d3dtexture, NULL);
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- glt->texnum = DPSOFTRAST_Texture_New(((glt->flags & TEXF_CLAMP) ? DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE : 0) | (dds_miplevels > 1 ? DPSOFTRAST_TEXTURE_FLAG_MIPMAP : 0), glt->tilewidth, glt->tileheight, glt->tiledepth);
- break;
}
// upload the texture
}
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (bytesperblock)
{
qglTexImage2D(GL_TEXTURE_2D, mip, glt->glinternalformat, upload_mipwidth, upload_mipheight, 0, glt->glformat, glt->gltype, upload_mippixels);CHECKGLERROR
}
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- {
- D3DLOCKED_RECT d3dlockedrect;
- if (IDirect3DTexture9_LockRect((IDirect3DTexture9*)glt->d3dtexture, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits)
- {
- memcpy(d3dlockedrect.pBits, upload_mippixels, mipsize);
- IDirect3DTexture9_UnlockRect((IDirect3DTexture9*)glt->d3dtexture, mip);
- }
- break;
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (bytesperblock)
- Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- else
- DPSOFTRAST_Texture_UpdateFull(glt->texnum, upload_mippixels);
- // DPSOFTRAST calculates its own mipmaps
- mip = dds_miplevels;
- break;
}
if(upload_mippixels != mippixels)
Mem_Free(upload_mippixels);
// after upload we have to set some parameters...
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
#ifdef GL_TEXTURE_MAX_LEVEL
if (dds_miplevels >= 1 && !mipcomplete)
GL_SetupTextureParameters(glt->flags, glt->textype->textype, glt->texturetype);
qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- glt->d3daddressw = 0;
- if (glt->flags & TEXF_CLAMP)
- {
- glt->d3daddressu = D3DTADDRESS_CLAMP;
- glt->d3daddressv = D3DTADDRESS_CLAMP;
- if (glt->tiledepth > 1)
- glt->d3daddressw = D3DTADDRESS_CLAMP;
- }
- else
- {
- glt->d3daddressu = D3DTADDRESS_WRAP;
- glt->d3daddressv = D3DTADDRESS_WRAP;
- if (glt->tiledepth > 1)
- glt->d3daddressw = D3DTADDRESS_WRAP;
- }
- glt->d3dmipmaplodbias = 0;
- glt->d3dmaxmiplevel = 0;
- glt->d3dmaxmiplevelfilter = 0;
- if (glt->flags & TEXF_MIPMAP)
- {
- glt->d3dminfilter = d3d_filter_mipmin;
- glt->d3dmagfilter = d3d_filter_mipmag;
- glt->d3dmipfilter = d3d_filter_mipmix;
- }
- else
- {
- glt->d3dminfilter = d3d_filter_flatmin;
- glt->d3dmagfilter = d3d_filter_flatmag;
- glt->d3dmipfilter = d3d_filter_flatmix;
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- if (glt->flags & TEXF_FORCELINEAR)
- DPSOFTRAST_Texture_Filter(glt->texnum, DPSOFTRAST_TEXTURE_FILTER_LINEAR);
- else if (glt->flags & TEXF_FORCENEAREST)
- DPSOFTRAST_Texture_Filter(glt->texnum, DPSOFTRAST_TEXTURE_FILTER_NEAREST);
- else if (glt->flags & TEXF_MIPMAP)
- DPSOFTRAST_Texture_Filter(glt->texnum, dpsoftrast_filter_mipmap);
- else
- DPSOFTRAST_Texture_Filter(glt->texnum, dpsoftrast_filter_nomipmap);
- break;
}
Mem_Free(dds);
Host_Error("R_UpdateTexture: no data supplied");
if (glt == NULL)
Host_Error("R_UpdateTexture: no texture supplied");
- if (!glt->texnum && !glt->d3dtexture)
+ if (!glt->texnum)
{
Con_DPrintf("R_UpdateTexture: texture %p \"%s\" in pool %p has not been uploaded yet\n", (void *)glt, glt->identifier, (void *)glt->pool);
return;
#endif
// GL_ARB_multitexture
-extern void (GLAPIENTRY *qglMultiTexCoord1f) (GLenum, GLfloat);
-extern void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
-extern void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
-extern void (GLAPIENTRY *qglMultiTexCoord4f) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
extern void (GLAPIENTRY *qglActiveTexture) (GLenum);
-extern void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
#ifndef GL_ACTIVE_TEXTURE
#define GL_ACTIVE_TEXTURE 0x84E0
-#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
#define GL_MAX_TEXTURE_UNITS 0x84E2
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
extern void (GLAPIENTRY *qglClear)(GLbitfield mask);
-extern void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
extern void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
extern void (GLAPIENTRY *qglCullFace)(GLenum mode);
extern void (GLAPIENTRY *qglDisable)(GLenum cap);
extern GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
-extern void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
-extern void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
-
extern void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
extern void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
extern void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
extern void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
extern void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
extern void (GLAPIENTRY *qglDrawArrays)(GLenum mode, GLint first, GLsizei count);
-extern void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
-extern void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
-extern void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
-extern void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
-extern void (GLAPIENTRY *qglArrayElement)(GLint i);
-
-extern void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-extern void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-extern void (GLAPIENTRY *qglTexCoord1f)(GLfloat s);
-extern void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
-extern void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
-extern void (GLAPIENTRY *qglTexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
-extern void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
-extern void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
-extern void (GLAPIENTRY *qglVertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-extern void (GLAPIENTRY *qglBegin)(GLenum mode);
-extern void (GLAPIENTRY *qglEnd)(void);
-
-extern void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
-//extern void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
-//extern void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
+
extern void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
-//extern void (GLAPIENTRY *qglPushMatrix)(void);
-//extern void (GLAPIENTRY *qglPopMatrix)(void);
-extern void (GLAPIENTRY *qglLoadIdentity)(void);
-//extern void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
-extern void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
-//extern void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
-//extern void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
-//extern void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
-//extern void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-//extern void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
-//extern void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
-//extern void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
-//extern void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
extern void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
extern void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
extern void (GLAPIENTRY *qglClearStencil)(GLint s);
-extern void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
-extern void (GLAPIENTRY *qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
-extern void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
extern void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
extern void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
extern void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
//extern void (GLAPIENTRY *qglGetClipPlane)(GLenum plane, GLdouble *equation);
//[515]: added on 29.07.2005
-extern void (GLAPIENTRY *qglLineWidth)(GLfloat width);
extern void (GLAPIENTRY *qglPointSize)(GLfloat size);
// GL 2.0 shader objects
#define qglGetString glGetString
//#define qglActiveStencilFaceEXT glActiveStencilFace
#define qglActiveTexture glActiveTexture
-#define qglAlphaFunc glAlphaFunc
-#define qglArrayElement glArrayElement
#define qglAttachShader glAttachShader
-//#define qglBegin glBegin
//#define qglBeginQueryARB glBeginQuery
#define qglBindAttribLocation glBindAttribLocation
//#define qglBindFragDataLocation glBindFragDataLocation
#define qglClearColor glClearColor
#define qglClearDepthf glClearDepthf
#define qglClearStencil glClearStencil
-#define qglClientActiveTexture glClientActiveTexture
-#define qglColor4f glColor4f
-#define qglColor4ub glColor4ub
#define qglColorMask glColorMask
-#define qglColorPointer glColorPointer
#define qglCompileShader glCompileShader
#define qglCompressedTexImage2DARB glCompressedTexImage2D
#define qglCompressedTexImage3DARB glCompressedTexImage3D
#define qglDepthRangef glDepthRangef
#define qglDetachShader glDetachShader
#define qglDisable glDisable
-#define qglDisableClientState glDisableClientState
#define qglDisableVertexAttribArray glDisableVertexAttribArray
#define qglDrawArrays glDrawArrays
//#define qglDrawBuffer glDrawBuffer
#define qglDrawElements glDrawElements
//#define qglDrawRangeElements glDrawRangeElements
#define qglEnable glEnable
-#define qglEnableClientState glEnableClientState
#define qglEnableVertexAttribArray glEnableVertexAttribArray
-//#define qglEnd glEnd
//#define qglEndQueryARB glEndQuery
#define qglFinish glFinish
#define qglFlush glFlush
#define qglGetUniformfv glGetUniformfv
#define qglGetUniformiv glGetUniformiv
#define qglHint glHint
-#define qglLineWidth glLineWidth
#define qglLinkProgram glLinkProgram
-#define qglLoadIdentity glLoadIdentity
-#define qglLoadMatrixf glLoadMatrixf
-#define qglMatrixMode glMatrixMode
-#define qglMultiTexCoord1f glMultiTexCoord1f
-#define qglMultiTexCoord2f glMultiTexCoord2f
-#define qglMultiTexCoord3f glMultiTexCoord3f
-#define qglMultiTexCoord4f glMultiTexCoord4f
-#define qglNormalPointer glNormalPointer
#define qglPixelStorei glPixelStorei
#define qglPointSize glPointSize
//#define qglPolygonMode glPolygonMode
#define qglStencilMask glStencilMask
#define qglStencilOp glStencilOp
#define qglStencilOpSeparate glStencilOpSeparate
-#define qglTexCoord1f glTexCoord1f
-#define qglTexCoord2f glTexCoord2f
-#define qglTexCoord3f glTexCoord3f
-#define qglTexCoord4f glTexCoord4f
-#define qglTexCoordPointer glTexCoordPointer
-#define qglTexEnvf glTexEnvf
-#define qglTexEnvfv glTexEnvfv
-#define qglTexEnvi glTexEnvi
#define qglTexImage2D glTexImage2D
#define qglTexImage3D glTexImage3D
#define qglTexParameterf glTexParameterf
#define qglUniformMatrix4fv glUniformMatrix4fv
#define qglUseProgram glUseProgram
#define qglValidateProgram glValidateProgram
-#define qglVertex2f glVertex2f
-#define qglVertex3f glVertex3f
-#define qglVertex4f glVertex4f
#define qglVertexAttribPointer glVertexAttribPointer
-#define qglVertexPointer glVertexPointer
#define qglViewport glViewport
#define qglVertexAttrib1f glVertexAttrib1f
//#define qglVertexAttrib1s glVertexAttrib1s
q3dlightgrid_t *a, *s;
// scale lighting by lightstyle[0] so that darkmode in dpmod works properly
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- // LordHavoc: FIXME: is this true?
- stylescale = 1; // added while render
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- stylescale = r_refdef.scene.rtlightstylevalue[0];
- break;
- }
+ // LadyHavoc: FIXME: is this true?
+ stylescale = 1; // added while render
+ //stylescale = r_refdef.scene.rtlightstylevalue[0];
if (!model->brushq3.num_lightgrid)
{
#include "cl_collision.h"
#include "portals.h"
#include "image.h"
-#include "dpsoftrast.h"
-
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-extern LPDIRECT3DDEVICE9 vid_d3d9dev;
-#endif
static void R_Shadow_EditLights_Init(void);
R_SHADOW_RENDERMODE_ZFAIL_STENCIL,
R_SHADOW_RENDERMODE_ZFAIL_SEPARATESTENCIL,
R_SHADOW_RENDERMODE_ZFAIL_STENCILTWOSIDE,
- R_SHADOW_RENDERMODE_LIGHT_VERTEX,
- R_SHADOW_RENDERMODE_LIGHT_VERTEX2DATTEN,
- R_SHADOW_RENDERMODE_LIGHT_VERTEX2D1DATTEN,
- R_SHADOW_RENDERMODE_LIGHT_VERTEX3DATTEN,
R_SHADOW_RENDERMODE_LIGHT_GLSL,
R_SHADOW_RENDERMODE_VISIBLEVOLUMES,
R_SHADOW_RENDERMODE_VISIBLELIGHTING,
r_shadow_shadowmapsampler = false;
r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- r_shadow_shadowmapsampler = false;
- r_shadow_shadowmappcf = 1;
- r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
break;
}
// for performance reasons, do not use directional shading on GLES devices
r_shadow_bouncegrid_state.capable = vid.support.ext_texture_3d;
break;
- // these renderpaths do not currently have the code to display the bouncegrid, so disable it on them...
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- case RENDERPATH_SOFT:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- break;
}
}
r_shadow_shadowingrendermode_zfail = R_SHADOW_RENDERMODE_ZFAIL_STENCIL;
}
- switch(vid.renderpath)
- {
- case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES2:
- r_shadow_lightingrendermode = R_SHADOW_RENDERMODE_LIGHT_GLSL;
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
- if (r_textureunits.integer >= 2 && vid.texunits >= 2 && r_shadow_texture3d.integer && r_shadow_attenuation3dtexture)
- r_shadow_lightingrendermode = R_SHADOW_RENDERMODE_LIGHT_VERTEX3DATTEN;
- else if (r_textureunits.integer >= 3 && vid.texunits >= 3)
- r_shadow_lightingrendermode = R_SHADOW_RENDERMODE_LIGHT_VERTEX2D1DATTEN;
- else if (r_textureunits.integer >= 2 && vid.texunits >= 2)
- r_shadow_lightingrendermode = R_SHADOW_RENDERMODE_LIGHT_VERTEX2DATTEN;
- else
- r_shadow_lightingrendermode = R_SHADOW_RENDERMODE_LIGHT_VERTEX;
- break;
- }
+ r_shadow_lightingrendermode = R_SHADOW_RENDERMODE_LIGHT_GLSL;
CHECKGLERROR
#if 0
GL_ColorMask(0, 0, 0, 0);
switch (vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
GL_CullFace(r_refdef.view.cullface_back);
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- // we invert the cull mode because we flip the projection matrix
- // NOTE: this actually does nothing because the DrawShadowMap code sets it to doublesided...
- GL_CullFace(r_refdef.view.cullface_front);
- break;
}
Vector4Set(clearcolor, 1, 1, 1, 1);
if (r_shadow_shadowmap2ddepthbuffer)
GL_ColorMask(0,0,0,0);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
GL_CullFace(r_refdef.view.cullface_back);
break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- // we invert the cull mode because we flip the projection matrix
- // NOTE: this actually does nothing because the DrawShadowMap code sets it to doublesided...
- GL_CullFace(r_refdef.view.cullface_front);
- break;
}
// used in R_Q1BSP_DrawShadowMap code to check surfacesides[]
return false;
}
-static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int numverts, const float *diffusecolor, const float *ambientcolor)
-{
- int i;
- const float *vertex3f;
- const float *normal3f;
- float *color4f;
- float dist, dot, distintensity, shadeintensity, v[3], n[3];
- switch (r_shadow_rendermode)
- {
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX3DATTEN:
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX2D1DATTEN:
- if (VectorLength2(diffusecolor) > 0)
- {
- for (i = 0, vertex3f = rsurface.batchvertex3f + 3*firstvertex, normal3f = rsurface.batchnormal3f + 3*firstvertex, color4f = rsurface.passcolor4f + 4 * firstvertex;i < numverts;i++, vertex3f += 3, normal3f += 3, color4f += 4)
- {
- Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
- Matrix4x4_Transform3x3(&rsurface.entitytolight, normal3f, n);
- if ((dot = DotProduct(n, v)) < 0)
- {
- shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n));
- VectorMA(ambientcolor, shadeintensity, diffusecolor, color4f);
- }
- else
- VectorCopy(ambientcolor, color4f);
- if (r_refdef.fogenabled)
- {
- float f;
- f = RSurf_FogVertex(vertex3f);
- VectorScale(color4f, f, color4f);
- }
- color4f[3] = 1;
- }
- }
- else
- {
- for (i = 0, vertex3f = rsurface.batchvertex3f + 3*firstvertex, color4f = rsurface.passcolor4f + 4 * firstvertex;i < numverts;i++, vertex3f += 3, color4f += 4)
- {
- VectorCopy(ambientcolor, color4f);
- if (r_refdef.fogenabled)
- {
- float f;
- Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
- f = RSurf_FogVertex(vertex3f);
- VectorScale(color4f + 4*i, f, color4f);
- }
- color4f[3] = 1;
- }
- }
- break;
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX2DATTEN:
- if (VectorLength2(diffusecolor) > 0)
- {
- for (i = 0, vertex3f = rsurface.batchvertex3f + 3*firstvertex, normal3f = rsurface.batchnormal3f + 3*firstvertex, color4f = rsurface.passcolor4f + 4 * firstvertex;i < numverts;i++, vertex3f += 3, normal3f += 3, color4f += 4)
- {
- Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
- if ((dist = fabs(v[2])) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
- {
- Matrix4x4_Transform3x3(&rsurface.entitytolight, normal3f, n);
- if ((dot = DotProduct(n, v)) < 0)
- {
- shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n));
- color4f[0] = (ambientcolor[0] + shadeintensity * diffusecolor[0]) * distintensity;
- color4f[1] = (ambientcolor[1] + shadeintensity * diffusecolor[1]) * distintensity;
- color4f[2] = (ambientcolor[2] + shadeintensity * diffusecolor[2]) * distintensity;
- }
- else
- {
- color4f[0] = ambientcolor[0] * distintensity;
- color4f[1] = ambientcolor[1] * distintensity;
- color4f[2] = ambientcolor[2] * distintensity;
- }
- if (r_refdef.fogenabled)
- {
- float f;
- f = RSurf_FogVertex(vertex3f);
- VectorScale(color4f, f, color4f);
- }
- }
- else
- VectorClear(color4f);
- color4f[3] = 1;
- }
- }
- else
- {
- for (i = 0, vertex3f = rsurface.batchvertex3f + 3*firstvertex, color4f = rsurface.passcolor4f + 4 * firstvertex;i < numverts;i++, vertex3f += 3, color4f += 4)
- {
- Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
- if ((dist = fabs(v[2])) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
- {
- color4f[0] = ambientcolor[0] * distintensity;
- color4f[1] = ambientcolor[1] * distintensity;
- color4f[2] = ambientcolor[2] * distintensity;
- if (r_refdef.fogenabled)
- {
- float f;
- f = RSurf_FogVertex(vertex3f);
- VectorScale(color4f, f, color4f);
- }
- }
- else
- VectorClear(color4f);
- color4f[3] = 1;
- }
- }
- break;
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
- if (VectorLength2(diffusecolor) > 0)
- {
- for (i = 0, vertex3f = rsurface.batchvertex3f + 3*firstvertex, normal3f = rsurface.batchnormal3f + 3*firstvertex, color4f = rsurface.passcolor4f + 4 * firstvertex;i < numverts;i++, vertex3f += 3, normal3f += 3, color4f += 4)
- {
- Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
- if ((dist = VectorLength(v)) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
- {
- distintensity = (1 - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist);
- Matrix4x4_Transform3x3(&rsurface.entitytolight, normal3f, n);
- if ((dot = DotProduct(n, v)) < 0)
- {
- shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n));
- color4f[0] = (ambientcolor[0] + shadeintensity * diffusecolor[0]) * distintensity;
- color4f[1] = (ambientcolor[1] + shadeintensity * diffusecolor[1]) * distintensity;
- color4f[2] = (ambientcolor[2] + shadeintensity * diffusecolor[2]) * distintensity;
- }
- else
- {
- color4f[0] = ambientcolor[0] * distintensity;
- color4f[1] = ambientcolor[1] * distintensity;
- color4f[2] = ambientcolor[2] * distintensity;
- }
- if (r_refdef.fogenabled)
- {
- float f;
- f = RSurf_FogVertex(vertex3f);
- VectorScale(color4f, f, color4f);
- }
- }
- else
- VectorClear(color4f);
- color4f[3] = 1;
- }
- }
- else
- {
- for (i = 0, vertex3f = rsurface.batchvertex3f + 3*firstvertex, color4f = rsurface.passcolor4f + 4 * firstvertex;i < numverts;i++, vertex3f += 3, color4f += 4)
- {
- Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
- if ((dist = VectorLength(v)) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
- {
- distintensity = (1 - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist);
- color4f[0] = ambientcolor[0] * distintensity;
- color4f[1] = ambientcolor[1] * distintensity;
- color4f[2] = ambientcolor[2] * distintensity;
- if (r_refdef.fogenabled)
- {
- float f;
- f = RSurf_FogVertex(vertex3f);
- VectorScale(color4f, f, color4f);
- }
- }
- else
- VectorClear(color4f);
- color4f[3] = 1;
- }
- }
- break;
- default:
- break;
- }
-}
-
static void R_Shadow_RenderLighting_VisibleLighting(int texturenumsurfaces, const msurface_t **texturesurfacelist)
{
// used to display how many times a surface is lit for level design purposes
RSurf_DrawBatch();
}
-static void R_Shadow_RenderLighting_Light_Vertex_Pass(int firstvertex, int numvertices, int numtriangles, const int *element3i, vec3_t diffusecolor2, vec3_t ambientcolor2)
-{
- int renders;
- int i;
- int stop;
- int newfirstvertex;
- int newlastvertex;
- int newnumtriangles;
- int *newe;
- const int *e;
- float *c;
- int maxtriangles = 1024;
- int newelements[1024*3];
- R_Shadow_RenderLighting_Light_Vertex_Shading(firstvertex, numvertices, diffusecolor2, ambientcolor2);
- for (renders = 0;renders < 4;renders++)
- {
- stop = true;
- newfirstvertex = 0;
- newlastvertex = 0;
- newnumtriangles = 0;
- newe = newelements;
- // due to low fillrate on the cards this vertex lighting path is
- // designed for, we manually cull all triangles that do not
- // contain a lit vertex
- // this builds batches of triangles from multiple surfaces and
- // renders them at once
- for (i = 0, e = element3i;i < numtriangles;i++, e += 3)
- {
- if (VectorLength2(rsurface.passcolor4f + e[0] * 4) + VectorLength2(rsurface.passcolor4f + e[1] * 4) + VectorLength2(rsurface.passcolor4f + e[2] * 4) >= 0.01)
- {
- if (newnumtriangles)
- {
- newfirstvertex = min(newfirstvertex, e[0]);
- newlastvertex = max(newlastvertex, e[0]);
- }
- else
- {
- newfirstvertex = e[0];
- newlastvertex = e[0];
- }
- newfirstvertex = min(newfirstvertex, e[1]);
- newlastvertex = max(newlastvertex, e[1]);
- newfirstvertex = min(newfirstvertex, e[2]);
- newlastvertex = max(newlastvertex, e[2]);
- newe[0] = e[0];
- newe[1] = e[1];
- newe[2] = e[2];
- newnumtriangles++;
- newe += 3;
- if (newnumtriangles >= maxtriangles)
- {
- R_Mesh_Draw(newfirstvertex, newlastvertex - newfirstvertex + 1, 0, newnumtriangles, newelements, NULL, 0, NULL, NULL, 0);
- newnumtriangles = 0;
- newe = newelements;
- stop = false;
- }
- }
- }
- if (newnumtriangles >= 1)
- {
- R_Mesh_Draw(newfirstvertex, newlastvertex - newfirstvertex + 1, 0, newnumtriangles, newelements, NULL, 0, NULL, NULL, 0);
- stop = false;
- }
- // if we couldn't find any lit triangles, exit early
- if (stop)
- break;
- // now reduce the intensity for the next overbright pass
- // we have to clamp to 0 here incase the drivers have improper
- // handling of negative colors
- // (some old drivers even have improper handling of >1 color)
- stop = true;
- for (i = 0, c = rsurface.passcolor4f + 4 * firstvertex;i < numvertices;i++, c += 4)
- {
- if (c[0] > 1 || c[1] > 1 || c[2] > 1)
- {
- c[0] = max(0, c[0] - 1);
- c[1] = max(0, c[1] - 1);
- c[2] = max(0, c[2] - 1);
- stop = false;
- }
- else
- VectorClear(c);
- }
- // another check...
- if (stop)
- break;
- }
-}
-
-static void R_Shadow_RenderLighting_Light_Vertex(int texturenumsurfaces, const msurface_t **texturesurfacelist, const float ambientcolor[3], const float diffusecolor[3])
-{
- // OpenGL 1.1 path (anything)
- float ambientcolorbase[3], diffusecolorbase[3];
- float ambientcolorpants[3], diffusecolorpants[3];
- float ambientcolorshirt[3], diffusecolorshirt[3];
- const float *surfacepants = rsurface.texture->render_colormap_pants;
- const float *surfaceshirt = rsurface.texture->render_colormap_shirt;
- rtexture_t *basetexture = rsurface.texture->basetexture;
- rtexture_t *pantstexture = rsurface.texture->pantstexture;
- rtexture_t *shirttexture = rsurface.texture->shirttexture;
- qboolean dopants = pantstexture && VectorLength2(surfacepants) >= (1.0f / 1048576.0f);
- qboolean doshirt = shirttexture && VectorLength2(surfaceshirt) >= (1.0f / 1048576.0f);
- VectorCopy(ambientcolor, ambientcolorbase);
- VectorCopy(diffusecolor, diffusecolorbase);
- ambientcolorpants[0] = ambientcolorbase[0] * surfacepants[0];ambientcolorpants[1] = ambientcolorbase[1] * surfacepants[1];ambientcolorpants[2] = ambientcolorbase[2] * surfacepants[2];
- diffusecolorpants[0] = diffusecolorbase[0] * surfacepants[0];diffusecolorpants[1] = diffusecolorbase[1] * surfacepants[1];diffusecolorpants[2] = diffusecolorbase[2] * surfacepants[2];
- ambientcolorshirt[0] = ambientcolorbase[0] * surfaceshirt[0];ambientcolorshirt[1] = ambientcolorbase[1] * surfaceshirt[1];ambientcolorshirt[2] = ambientcolorbase[2] * surfaceshirt[2];
- diffusecolorshirt[0] = diffusecolorbase[0] * surfaceshirt[0];diffusecolorshirt[1] = diffusecolorbase[1] * surfaceshirt[1];diffusecolorshirt[2] = diffusecolorbase[2] * surfaceshirt[2];
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | (VectorLength2(diffusecolor) > 0 ? BATCHNEED_ARRAY_NORMAL : 0) | BATCHNEED_ARRAY_TEXCOORD | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
- rsurface.passcolor4f = (float *)R_FrameData_Alloc((rsurface.batchfirstvertex + rsurface.batchnumvertices) * sizeof(float[4]));
- R_Mesh_VertexPointer(3, GL_FLOAT, sizeof(float[3]), rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset);
- R_Mesh_ColorPointer(4, GL_FLOAT, sizeof(float[4]), rsurface.passcolor4f, 0, 0);
- R_Mesh_TexCoordPointer(0, 2, GL_FLOAT, sizeof(float[2]), rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordtexture2f_vertexbuffer, rsurface.batchtexcoordtexture2f_bufferoffset);
- R_Mesh_TexBind(0, basetexture);
- R_Mesh_TexMatrix(0, &rsurface.texture->currenttexmatrix);
- R_Mesh_TexCombine(0, GL_MODULATE, GL_MODULATE, 1, 1);
- switch(r_shadow_rendermode)
- {
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX3DATTEN:
- R_Mesh_TexBind(1, r_shadow_attenuation3dtexture);
- R_Mesh_TexMatrix(1, &rsurface.entitytoattenuationxyz);
- R_Mesh_TexCombine(1, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(1, 3, GL_FLOAT, sizeof(float[3]), rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset);
- break;
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX2D1DATTEN:
- R_Mesh_TexBind(2, r_shadow_attenuation2dtexture);
- R_Mesh_TexMatrix(2, &rsurface.entitytoattenuationz);
- R_Mesh_TexCombine(2, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(2, 3, GL_FLOAT, sizeof(float[3]), rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset);
- // fall through
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX2DATTEN:
- R_Mesh_TexBind(1, r_shadow_attenuation2dtexture);
- R_Mesh_TexMatrix(1, &rsurface.entitytoattenuationxyz);
- R_Mesh_TexCombine(1, GL_MODULATE, GL_MODULATE, 1, 1);
- R_Mesh_TexCoordPointer(1, 3, GL_FLOAT, sizeof(float[3]), rsurface.batchvertex3f, rsurface.batchvertex3f_vertexbuffer, rsurface.batchvertex3f_bufferoffset);
- break;
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
- break;
- default:
- break;
- }
- //R_Mesh_TexBind(0, basetexture);
- R_Shadow_RenderLighting_Light_Vertex_Pass(rsurface.batchfirstvertex, rsurface.batchnumvertices, rsurface.batchnumtriangles, rsurface.batchelement3i + 3*rsurface.batchfirsttriangle, diffusecolorbase, ambientcolorbase);
- if (dopants)
- {
- R_Mesh_TexBind(0, pantstexture);
- R_Shadow_RenderLighting_Light_Vertex_Pass(rsurface.batchfirstvertex, rsurface.batchnumvertices, rsurface.batchnumtriangles, rsurface.batchelement3i + 3*rsurface.batchfirsttriangle, diffusecolorpants, ambientcolorpants);
- }
- if (doshirt)
- {
- R_Mesh_TexBind(0, shirttexture);
- R_Shadow_RenderLighting_Light_Vertex_Pass(rsurface.batchfirstvertex, rsurface.batchnumvertices, rsurface.batchnumtriangles, rsurface.batchelement3i + 3*rsurface.batchfirsttriangle, diffusecolorshirt, ambientcolorshirt);
- }
-}
-
extern cvar_t gl_lightmaps;
void R_Shadow_RenderLighting(int texturenumsurfaces, const msurface_t **texturesurfacelist)
{
case R_SHADOW_RENDERMODE_LIGHT_GLSL:
R_Shadow_RenderLighting_Light_GLSL(texturenumsurfaces, texturesurfacelist, ambientcolor, diffusecolor, specularcolor);
break;
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX3DATTEN:
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX2D1DATTEN:
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX2DATTEN:
- case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
- R_Shadow_RenderLighting_Light_Vertex(texturenumsurfaces, texturesurfacelist, ambientcolor, diffusecolor);
- break;
default:
Con_Printf("R_Shadow_RenderLighting: unknown r_shadow_rendermode %i\n", r_shadow_rendermode);
break;
switch (vid.renderpath)
{
case RENDERPATH_GL20:
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- case RENDERPATH_SOFT:
#ifndef USE_GLES2
if (!r_shadow_deferred.integer || r_shadow_shadowmode == R_SHADOW_SHADOWMODE_STENCIL || !vid.support.ext_framebuffer_object || vid.maxdrawbuffers < 2)
{
}
#endif
break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
r_shadow_usingdeferredprepass = false;
break;
Matrix4x4_AdjustOrigin(&scalematrix, 0, size, -0.5f * bias);
Matrix4x4_Concat(&texmatrix, &scalematrix, &shadowmatrix);
Matrix4x4_Concat(&r_shadow_shadowmapmatrix, &texmatrix, &invmvpmatrix);
-
- switch (vid.renderpath)
- {
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GL20:
- case RENDERPATH_SOFT:
- case RENDERPATH_GLES1:
- case RENDERPATH_GLES2:
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
-#ifdef MATRIX4x4_OPENGLORIENTATION
- r_shadow_shadowmapmatrix.m[0][0] *= -1.0f;
- r_shadow_shadowmapmatrix.m[0][1] *= -1.0f;
- r_shadow_shadowmapmatrix.m[0][2] *= -1.0f;
- r_shadow_shadowmapmatrix.m[0][3] *= -1.0f;
-#else
- r_shadow_shadowmapmatrix.m[0][0] *= -1.0f;
- r_shadow_shadowmapmatrix.m[1][0] *= -1.0f;
- r_shadow_shadowmapmatrix.m[2][0] *= -1.0f;
- r_shadow_shadowmapmatrix.m[3][0] *= -1.0f;
-#endif
- break;
- }
}
void R_Shadow_DrawModelShadows(void)
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
CHECKGLERROR
CHECKGLERROR
#endif
break;
- case RENDERPATH_D3D9:
- Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
}
rtlight->corona_visibility = bound(0, (zdist - 32) / 32, 1);
switch(vid.renderpath)
{
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
// See if we can use the GPU-side method to prevent implicit sync
CHECKGLERROR
break;
}
- // fallthrough
-#else
- return;
-#endif
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
-#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
CHECKGLERROR
qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, &visiblepixels);
qglGetQueryObjectivARB(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT_ARB, &allpixels);
#else
return;
#endif
- case RENDERPATH_D3D9:
- Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- return;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- return;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- return;
- case RENDERPATH_SOFT:
- //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- return;
- default:
- return;
}
}
else
r_numqueries = 0;
switch (vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
usequery = vid.support.arb_occlusion_query && r_coronas_occlusionquery.integer;
#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
}
#endif
break;
- case RENDERPATH_D3D9:
- usequery = false;
- //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D10:
- Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_D3D11:
- Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
- case RENDERPATH_SOFT:
- usequery = false;
- //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
- break;
}
for (lightindex = 0;lightindex < range;lightindex++)
{
}
textype_t;
-/*
-#ifdef WIN32
-#define SUPPORTD3D
-#define SUPPORTDIRECTX
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-#endif
-#endif
-*/
-
// contents of this structure are mostly private to gl_textures.c
typedef struct rtexture_s
{
qboolean dirty; // indicates that R_RealGetTexture should be called
qboolean glisdepthstencil; // indicates that FBO attachment has to be GL_DEPTH_STENCIL_ATTACHMENT
int gltexturetypeenum; // used by R_Mesh_TexBind
- // d3d stuff the backend needs
- void *d3dtexture;
- void *d3dsurface;
-#ifdef SUPPORTD3D
- qboolean d3disrendertargetsurface;
- qboolean d3disdepthstencilsurface;
- int d3dformat;
- int d3dusage;
- int d3dpool;
- int d3daddressu;
- int d3daddressv;
- int d3daddressw;
- int d3dmagfilter;
- int d3dminfilter;
- int d3dmipfilter;
- int d3dmaxmiplevelfilter;
- int d3dmipmaplodbias;
- int d3dmaxmiplevel;
-#endif
}
rtexture_t;
#include "svbsp.h"
+typedef enum gl20_texunit_e
+{
+ // postprocess shaders, and generic shaders:
+ GL20TU_FIRST = 0,
+ GL20TU_SECOND = 1,
+ GL20TU_GAMMARAMPS = 2,
+ // standard material properties
+ GL20TU_NORMAL = 0,
+ GL20TU_COLOR = 1,
+ GL20TU_GLOSS = 2,
+ GL20TU_GLOW = 3,
+ // material properties for a second material
+ GL20TU_SECONDARY_NORMAL = 4,
+ GL20TU_SECONDARY_COLOR = 5,
+ GL20TU_SECONDARY_GLOSS = 6,
+ GL20TU_SECONDARY_GLOW = 7,
+ // material properties for a colormapped material
+ // conflicts with secondary material
+ GL20TU_PANTS = 4,
+ GL20TU_SHIRT = 7,
+ // fog fade in the distance
+ GL20TU_FOGMASK = 8,
+ // compiled ambient lightmap and deluxemap
+ GL20TU_LIGHTMAP = 9,
+ GL20TU_DELUXEMAP = 10,
+ // refraction, used by water shaders
+ GL20TU_REFRACTION = 3,
+ // reflection, used by water shaders, also with normal material rendering
+ // conflicts with secondary material
+ GL20TU_REFLECTION = 7,
+ // rtlight attenuation (distance fade) and cubemap filter (projection texturing)
+ // conflicts with lightmap/deluxemap
+ GL20TU_ATTENUATION = 9,
+ GL20TU_CUBE = 10,
+ GL20TU_SHADOWMAP2D = 15,
+ GL20TU_CUBEPROJECTION = 12,
+ // rtlight prepass data (screenspace depth and normalmap)
+// GL20TU_UNUSED1 = 13,
+ GL20TU_SCREENNORMALMAP = 14,
+ // lightmap prepass data (screenspace diffuse and specular from lights)
+ GL20TU_SCREENDIFFUSE = 11,
+ GL20TU_SCREENSPECULAR = 12,
+ // fake reflections
+ GL20TU_REFLECTMASK = 5,
+ GL20TU_REFLECTCUBE = 6,
+ GL20TU_FOGHEIGHTTEXTURE = 14
+}
+gl20_texunit;
+
+typedef enum glsl_attrib_e
+{
+ GLSLATTRIB_POSITION = 0,
+ GLSLATTRIB_COLOR = 1,
+ GLSLATTRIB_TEXCOORD0 = 2,
+ GLSLATTRIB_TEXCOORD1 = 3,
+ GLSLATTRIB_TEXCOORD2 = 4,
+ GLSLATTRIB_TEXCOORD3 = 5,
+ GLSLATTRIB_TEXCOORD4 = 6,
+ GLSLATTRIB_TEXCOORD5 = 7,
+ GLSLATTRIB_TEXCOORD6 = 8,
+ GLSLATTRIB_TEXCOORD7 = 9,
+}
+glsl_attrib;
+
+typedef enum shaderlanguage_e
+{
+ SHADERLANGUAGE_GLSL,
+ SHADERLANGUAGE_COUNT
+}
+shaderlanguage_t;
+
+// this enum selects which of the glslshadermodeinfo entries should be used
+typedef enum shadermode_e
+{
+ SHADERMODE_GENERIC, ///< (particles/HUD/etc) vertex color, optionally multiplied by one texture
+ SHADERMODE_POSTPROCESS, ///< postprocessing shader (r_glsl_postprocess)
+ SHADERMODE_DEPTH_OR_SHADOW, ///< (depthfirst/shadows) vertex shader only
+ SHADERMODE_FLATCOLOR, ///< (lightmap) modulate texture by uniform color (q1bsp, q3bsp)
+ SHADERMODE_VERTEXCOLOR, ///< (lightmap) modulate texture by vertex colors (q3bsp)
+ SHADERMODE_LIGHTMAP, ///< (lightmap) modulate texture by lightmap texture (q1bsp, q3bsp)
+ SHADERMODE_FAKELIGHT, ///< (fakelight) modulate texture by "fake" lighting (no lightmaps, no nothing)
+ SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE, ///< (lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp deluxemap)
+ SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE, ///< (lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp deluxemap)
+ SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP, // forced deluxemapping for lightmapped surfaces
+ SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR, // forced deluxemapping for vertexlit surfaces
+ SHADERMODE_LIGHTDIRECTION, ///< (lightmap) use directional pixel shading from fixed light direction (q3bsp)
+ SHADERMODE_LIGHTSOURCE, ///< (lightsource) use directional pixel shading from light source (rtlight)
+ SHADERMODE_REFRACTION, ///< refract background (the material is rendered normally after this pass)
+ SHADERMODE_WATER, ///< refract background and reflection (the material is rendered normally after this pass)
+ SHADERMODE_DEFERREDGEOMETRY, ///< (deferred) render material properties to screenspace geometry buffers
+ SHADERMODE_DEFERREDLIGHTSOURCE, ///< (deferred) use directional pixel shading from light source (rtlight) on screenspace geometry buffers
+ SHADERMODE_COUNT
+}
+shadermode_t;
+
+typedef enum shaderpermutation_e
+{
+ SHADERPERMUTATION_DIFFUSE = 1<<0, ///< (lightsource) whether to use directional shading
+ SHADERPERMUTATION_VERTEXTEXTUREBLEND = 1<<1, ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
+ SHADERPERMUTATION_VIEWTINT = 1<<2, ///< view tint (postprocessing only), use vertex colors (generic only)
+ SHADERPERMUTATION_COLORMAPPING = 1<<3, ///< indicates this is a colormapped skin
+ SHADERPERMUTATION_SATURATION = 1<<4, ///< saturation (postprocessing only)
+ SHADERPERMUTATION_FOGINSIDE = 1<<5, ///< tint the color by fog color or black if using additive blend mode
+ SHADERPERMUTATION_FOGOUTSIDE = 1<<6, ///< tint the color by fog color or black if using additive blend mode
+ SHADERPERMUTATION_FOGHEIGHTTEXTURE = 1<<7, ///< fog color and density determined by texture mapped on vertical axis
+ SHADERPERMUTATION_FOGALPHAHACK = 1<<8, ///< fog color and density determined by texture mapped on vertical axis
+ SHADERPERMUTATION_GAMMARAMPS = 1<<9, ///< gamma (postprocessing only)
+ SHADERPERMUTATION_CUBEFILTER = 1<<10, ///< (lightsource) use cubemap light filter
+ SHADERPERMUTATION_GLOW = 1<<11, ///< (lightmap) blend in an additive glow texture
+ SHADERPERMUTATION_BLOOM = 1<<12, ///< bloom (postprocessing only)
+ SHADERPERMUTATION_SPECULAR = 1<<13, ///< (lightsource or deluxemapping) render specular effects
+ SHADERPERMUTATION_POSTPROCESSING = 1<<14, ///< user defined postprocessing (postprocessing only)
+ SHADERPERMUTATION_REFLECTION = 1<<15, ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
+ SHADERPERMUTATION_OFFSETMAPPING = 1<<16, ///< adjust texcoords to roughly simulate a displacement mapped surface
+ SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING = 1<<17, ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
+ SHADERPERMUTATION_SHADOWMAP2D = 1<<18, ///< (lightsource) use shadowmap texture as light filter
+ SHADERPERMUTATION_SHADOWMAPVSDCT = 1<<19, ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
+ SHADERPERMUTATION_SHADOWMAPORTHO = 1<<20, ///< (lightsource) use orthographic shadowmap projection
+ SHADERPERMUTATION_DEFERREDLIGHTMAP = 1<<21, ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
+ SHADERPERMUTATION_ALPHAKILL = 1<<22, ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
+ SHADERPERMUTATION_REFLECTCUBE = 1<<23, ///< fake reflections using global cubemap (not HDRI light probe)
+ SHADERPERMUTATION_NORMALMAPSCROLLBLEND = 1<<24, ///< (water) counter-direction normalmaps scrolling
+ SHADERPERMUTATION_BOUNCEGRID = 1<<25, ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
+ SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL = 1<<26, ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
+ SHADERPERMUTATION_TRIPPY = 1<<27, ///< use trippy vertex shader effect
+ SHADERPERMUTATION_DEPTHRGB = 1<<28, ///< read/write depth values in RGB color coded format for older hardware without depth samplers
+ SHADERPERMUTATION_ALPHAGEN_VERTEX = 1<<29, ///< alphaGen vertex
+ SHADERPERMUTATION_SKELETAL = 1<<30, ///< (skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
+ SHADERPERMUTATION_OCCLUDE = 1<<31, ///< use occlusion buffer for corona
+ SHADERPERMUTATION_COUNT = 32 ///< size of shaderpermutationinfo array
+}
+shaderpermutation_t;
+
// 1.0f / N table
extern float ixtable[4096];
const r_meshbuffer_t *batchskeletaltransform3x4buffer; // uniform buffer
int batchskeletaltransform3x4offset;
int batchskeletaltransform3x4size;
- // rendering pass processing arrays in GL11 and GL13 paths
- float *passcolor4f;
- const r_meshbuffer_t *passcolor4f_vertexbuffer;
- int passcolor4f_bufferoffset;
// some important fields from the entity
int ent_skinnum;
-"// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n",
-"// written by Forest 'LordHavoc' Hale\n",
-"// shadowmapping enhancements by Lee 'eihrul' Salzman\n",
-"\n",
-"// FIXME: we need to get rid of ModelViewProjectionPosition to make room for the texcoord for this\n",
-"#if defined(USEREFLECTION)\n",
-"#undef USESHADOWMAPORTHO\n",
-"#endif\n",
-"\n",
-"#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n",
-"# define USEFOG\n",
-"#endif\n",
-"#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n",
-"#define USELIGHTMAP\n",
-"#endif\n",
-"#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n",
-"#define USEEYEVECTOR\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"#ifdef HLSL\n",
-"//#undef USESHADOWMAPPCF\n",
-"//#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n",
-"#define texDepth2D(tex,texcoord) dot(tex2D(tex,texcoord).rgb, float3(1.0, 255.0/65536.0, 255.0/16777216.0))\n",
-"#else\n",
-"#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n",
-"#endif\n",
-"#endif\n",
-"\n",
-"#ifdef VERTEX_SHADER\n",
-"#ifdef USETRIPPY\n",
-"// LordHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n",
-"// tweaked scale\n",
-"float4 TrippyVertex\n",
-"(\n",
-"float4 position,\n",
-"float ClientTime\n",
-")\n",
-"{\n",
-" float worldTime = ClientTime;\n",
-" // tweaked for Quake\n",
-" worldTime *= 10.0;\n",
-" position *= 0.125;\n",
-" //~tweaked for Quake\n",
-" float distanceSquared = (position.x * position.x + position.z * position.z);\n",
-" position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n",
-" float y = position.y;\n",
-" float x = position.x;\n",
-" float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n",
-" position.y = x*sin(om)+y*cos(om);\n",
-" position.x = x*cos(om)-y*sin(om);\n",
-" return position;\n",
-"}\n",
-"#endif\n",
-"#endif\n",
-"\n",
-"#ifdef MODE_DEPTH_OR_SHADOW\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"uniform float ClientTime : register(c2),\n",
-"out float4 gl_Position : POSITION,\n",
-"out float Depth : TEXCOORD0\n",
-")\n",
-"{\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-"#ifdef USETRIPPY\n",
-" gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
-"#endif\n",
-" Depth = gl_Position.z;\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"void main\n",
-"(\n",
-"float Depth : TEXCOORD0,\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-"// float4 temp = float4(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0),0.0);\n",
-" float4 temp = float4(Depth,Depth*256.0,Depth*65536.0,0.0);\n",
-" temp.yz -= floor(temp.yz);\n",
-" dp_FragColor = temp;\n",
-"// dp_FragColor = float4(Depth,0,0,0);\n",
-"}\n",
-"#endif\n",
-"#else // !MODE_DEPTH_OR_SHADOW\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_POSTPROCESS\n",
-"\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
-"out float4 gl_Position : POSITION,\n",
-"out float2 TexCoord1 : TEXCOORD0\n",
-"#ifdef USEBLOOM\n",
-", out float2 TexCoord2 : TEXCOORD1\n",
-"#endif\n",
-")\n",
-"{\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-" TexCoord1 = gl_MultiTexCoord0.xy;\n",
-"#ifdef USEBLOOM\n",
-" TexCoord2 = gl_MultiTexCoord4.xy;\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"#ifdef USEFXAA\n",
-"// graphitemaster: based off the white paper by Timothy Lottes\n",
-"// http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf\n",
-"float4 fxaa\n",
-"(\n",
-" float4 inColor,\n",
-" float maxspan,\n",
-" float2 TexCoord1,\n",
-" uniform sampler Texture_First,\n",
-" uniform float2 PixelSize\n",
-")\n",
-"{\n",
-" float4 ret = inColor; // preserve old\n",
-" float mulreduct = 1.0/maxspan;\n",
-" float minreduct = (1.0 / 128.0);\n",
-"\n",
-" float3 NW = tex2D(Texture_First, TexCoord1 + (float2(-1.0, -1.0) * PixelSize)).xyz;\n",
-" float3 NE = tex2D(Texture_First, TexCoord1 + (float2(+1.0, -1.0) * PixelSize)).xyz;\n",
-" float3 SW = tex2D(Texture_First, TexCoord1 + (float2(-1.0, +1.0) * PixelSize)).xyz;\n",
-" float3 SE = tex2D(Texture_First, TexCoord1 + (float2(+1.0, +1.0) * PixelSize)).xyz;\n",
-" float3 M = tex2D(Texture_First, TexCoord1).xyz;\n",
-"\n",
-" // luminance directions\n",
-" float3 luma = float3(0.299, 0.587, 0.114);\n",
-" float lNW = dot(NW, luma);\n",
-" float lNE = dot(NE, luma);\n",
-" float lSW = dot(SW, luma);\n",
-" float lSE = dot(SE, luma);\n",
-" float lM = dot(M, luma);\n",
-" float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE)));\n",
-" float lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n",
-"\n",
-" // direction and reciprocal\n",
-" float2 dir = float2(-((lNW + lNE) - (lSW + lSE)), ((lNW + lSW) - (lNE + lSE)));\n",
-" float rcp = 1.0/(min(abs(dir.x), abs(dir.y)) + max((lNW + lNE + lSW + lSE) * (0.25 * mulreduct), minreduct));\n",
-"\n",
-" // span\n",
-" dir = min(float2(maxspan, maxspan), max(float2(-maxspan, -maxspan), dir * rcp)) * PixelSize;\n",
-"\n",
-" float3 rA = (1.0/2.0) * (\n",
-" tex2D(Texture_First, TexCoord1 + dir * (1.0/3.0 - 0.5)).xyz +\n",
-" tex2D(Texture_First, TexCoord1 + dir * (2.0/3.0 - 0.5)).xyz);\n",
-" float3 rB = rA * (1.0/2.0) + (1.0/4.0) * (\n",
-" tex2D(Texture_First, TexCoord1 + dir * (0.0/3.0 - 0.5)).xyz +\n",
-" tex2D(Texture_First, TexCoord1 + dir * (3.0/3.0 - 0.5)).xyz);\n",
-" float lB = dot(rB, luma);\n",
-"\n",
-" ret.xyz = ((lB < lMin) || (lB > lMax)) ? rA : rB;\n",
-" ret.a = 1.0;\n",
-" return ret;\n",
-"}\n",
-"#endif\n",
-"\n",
-"void main\n",
-"(\n",
-"float2 TexCoord1 : TEXCOORD0,\n",
-"#ifdef USEBLOOM\n",
-"float2 TexCoord2 : TEXCOORD1,\n",
-"#endif\n",
-"uniform sampler Texture_First : register(s0),\n",
-"#ifdef USEBLOOM\n",
-"uniform sampler Texture_Second : register(s1),\n",
-"#endif\n",
-"#ifdef USEGAMMARAMPS\n",
-"uniform sampler Texture_GammaRamps : register(s2),\n",
-"#endif\n",
-"#ifdef USESATURATION\n",
-"uniform float Saturation : register(c30),\n",
-"#endif\n",
-"#ifdef USEVIEWTINT\n",
-"uniform float4 ViewTintColor : register(c41),\n",
-"#endif\n",
-"uniform float4 UserVec1 : register(c37),\n",
-"uniform float4 UserVec2 : register(c38),\n",
-"uniform float4 UserVec3 : register(c39),\n",
-"uniform float4 UserVec4 : register(c40),\n",
-"uniform float ClientTime : register(c2),\n",
-"uniform float2 PixelSize : register(c25),\n",
-"uniform float4 BloomColorSubtract : register(c43),\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-" dp_FragColor = tex2D(Texture_First, TexCoord1);\n",
-"\n",
-"#ifdef USEFXAA\n",
-" dp_FragColor = fxaa(dp_FragColor, 8.0, TexCoord1, Texture_First, PixelSize); // 8.0 can be changed for larger span\n",
-"#endif\n",
-"\n",
-"#ifdef USEPOSTPROCESSING\n",
-"// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n",
-"// this code does a blur with the radius specified in the first component of r_glsl_postprocess_uservec1 and blends it using the second component\n",
-"#if defined(USERVEC1) || defined(USERVEC2)\n",
-" float sobel = 1.0;\n",
-" // float2 ts = textureSize(Texture_First, 0);\n",
-" // float2 px = float2(1/ts.x, 1/ts.y);\n",
-" float2 px = PixelSize;\n",
-" float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
-" float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n",
-" float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
-" float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
-" float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n",
-" float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
-" float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n",
-" float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n",
-" float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n",
-" float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n",
-" float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n",
-" float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n",
-" float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n",
-" float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n",
-" float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n",
-" float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n",
-" float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n",
-" float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n",
-" float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n",
-" float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n",
-" float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n",
-" float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n",
-" float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n",
-" float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n",
-" sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n",
-" dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n",
-" dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n",
-" dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n",
-" dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n",
-" dp_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n",
-" dp_FragColor /= (1.0 + 5.0 * UserVec1.y);\n",
-" dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n",
-"#endif\n",
-"#endif\n",
-"\n",
-"#ifdef USEBLOOM\n",
-" dp_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n",
-"#endif\n",
-"\n",
-"#ifdef USEVIEWTINT\n",
-" dp_FragColor = lerp(dp_FragColor, ViewTintColor, ViewTintColor.a);\n",
-"#endif\n",
-"\n",
-"#ifdef USESATURATION\n",
-" //apply saturation BEFORE gamma ramps, so v_glslgamma value does not matter\n",
-" float y = dot(dp_FragColor.rgb, float3(0.299, 0.587, 0.114));\n",
-" // 'vampire sight' effect, wheres red is compensated\n",
-" #ifdef SATURATION_REDCOMPENSATE\n",
-" float rboost = max(0.0, (dp_FragColor.r - max(dp_FragColor.g, dp_FragColor.b))*(1.0 - Saturation));\n",
-" dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
-" dp_FragColor.r += r;\n",
-" #else\n",
-" // normal desaturation\n",
-" //dp_FragColor = float3(y,y,y) + (dp_FragColor.rgb - float3(y)) * Saturation;\n",
-" dp_FragColor.rgb = lerp(float3(y,y,y), dp_FragColor.rgb, Saturation);\n",
-" #endif\n",
-"#endif\n",
-"\n",
-"#ifdef USEGAMMARAMPS\n",
-" dp_FragColor.r = tex2D(Texture_GammaRamps, float2(dp_FragColor.r, 0)).r;\n",
-" dp_FragColor.g = tex2D(Texture_GammaRamps, float2(dp_FragColor.g, 0)).g;\n",
-" dp_FragColor.b = tex2D(Texture_GammaRamps, float2(dp_FragColor.b, 0)).b;\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"#else // !MODE_POSTPROCESS\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_GENERIC\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"float4 gl_Color : COLOR0,\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
-"uniform float ClientTime : register(c2),\n",
-"out float4 gl_Position : POSITION,\n",
-"#ifdef USEDIFFUSE\n",
-"out float2 TexCoord1 : TEXCOORD0,\n",
-"#endif\n",
-"#ifdef USESPECULAR\n",
-"out float2 TexCoord2 : TEXCOORD1,\n",
-"#endif\n",
-"out float4 gl_FrontColor : COLOR\n",
-")\n",
-"{\n",
-" gl_FrontColor = gl_Color;\n",
-"#ifdef USEDIFFUSE\n",
-" TexCoord1 = gl_MultiTexCoord0.xy;\n",
-"#endif\n",
-"#ifdef USESPECULAR\n",
-" TexCoord2 = gl_MultiTexCoord1.xy;\n",
-"#endif\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-"#ifdef USETRIPPY\n",
-" gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"\n",
-"void main\n",
-"(\n",
-"float4 gl_FrontColor : COLOR0,\n",
-"float2 TexCoord1 : TEXCOORD0,\n",
-"float2 TexCoord2 : TEXCOORD1,\n",
-"#ifdef USEDIFFUSE\n",
-"uniform sampler Texture_First : register(s0),\n",
-"#endif\n",
-"#ifdef USESPECULAR\n",
-"uniform sampler Texture_Second : register(s1),\n",
-"#endif\n",
-"#ifdef USEGAMMARAMPS\n",
-"uniform sampler Texture_GammaRamps : register(s2),\n",
-"#endif\n",
-"uniform half Alpha : register(c0),\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-"#ifdef USEVIEWTINT\n",
-" dp_FragColor = gl_FrontColor;\n",
-"#else\n",
-" dp_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n",
-"#endif\n",
-"#ifdef USEDIFFUSE\n",
-"# ifdef USEREFLECTCUBE\n",
-" // suppress texture alpha\n",
-" dp_FragColor.rgb *= tex2D(Texture_First, TexCoord1).rgb;\n",
-"# else\n",
-" dp_FragColor *= tex2D(Texture_First, TexCoord1);\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#ifdef USESPECULAR\n",
-" float4 tex2 = tex2D(Texture_Second, TexCoord2);\n",
-"# ifdef USECOLORMAPPING\n",
-" dp_FragColor *= tex2;\n",
-"# endif\n",
-"# ifdef USEGLOW\n",
-" dp_FragColor += tex2;\n",
-"# endif\n",
-"# ifdef USEVERTEXTEXTUREBLEND\n",
-" dp_FragColor = lerp(dp_FragColor, tex2, tex2.a);\n",
-"# endif\n",
-"#endif\n",
-"#ifdef USEGAMMARAMPS\n",
-" dp_FragColor.r = tex2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n",
-" dp_FragColor.g = tex2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n",
-" dp_FragColor.b = tex2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n",
-"#endif\n",
-"#ifdef USEALPHAKILL\n",
-" dp_FragColor.a *= Alpha;\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"#else // !MODE_GENERIC\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_BLOOMBLUR\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"out float4 gl_Position : POSITION,\n",
-"out float2 TexCoord : TEXCOORD0\n",
-")\n",
-"{\n",
-" TexCoord = gl_MultiTexCoord0.xy;\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"\n",
-"void main\n",
-"(\n",
-"float2 TexCoord : TEXCOORD0,\n",
-"uniform sampler Texture_First : register(s0),\n",
-"uniform float4 BloomBlur_Parameters : register(c1),\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-" int i;\n",
-" float2 tc = TexCoord;\n",
-" float3 color = tex2D(Texture_First, tc).rgb;\n",
-" tc += BloomBlur_Parameters.xy;\n",
-" for (i = 1;i < SAMPLES;i++)\n",
-" {\n",
-" color += tex2D(Texture_First, tc).rgb;\n",
-" tc += BloomBlur_Parameters.xy;\n",
-" }\n",
-" dp_FragColor = float4(color * BloomBlur_Parameters.z + float3(BloomBlur_Parameters.w), 1);\n",
-"}\n",
-"#endif\n",
-"#else // !MODE_BLOOMBLUR\n",
-"#ifdef MODE_REFRACTION\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"#ifdef USEALPHAGENVERTEX\n",
-"float4 gl_Color : COLOR0,\n",
-"#endif\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"uniform float4x4 TexMatrix : register(c0),\n",
-"uniform float3 EyePosition : register(c24),\n",
-"uniform float ClientTime : register(c2),\n",
-"#ifdef USEALPHAGENVERTEX\n",
-"out float4 gl_FrontColor : COLOR,\n",
-"#endif\n",
-"out float4 gl_Position : POSITION,\n",
-"out float2 TexCoord : TEXCOORD0,\n",
-"out float3 EyeVector : TEXCOORD1,\n",
-"out float4 ModelViewProjectionPosition : TEXCOORD2\n",
-")\n",
-"{\n",
-"#ifdef USEALPHAGENVERTEX\n",
-" gl_FrontColor = gl_Color;\n",
-"#endif\n",
-" TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-" ModelViewProjectionPosition = gl_Position;\n",
-"#ifdef USETRIPPY\n",
-" gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"void main\n",
-"(\n",
-"#ifdef USEALPHAGENVERTEX\n",
-"float4 gl_FrontColor : COLOR,\n",
-"#endif\n",
-"float2 TexCoord : TEXCOORD0,\n",
-"float3 EyeVector : TEXCOORD1,\n",
-"float4 ModelViewProjectionPosition : TEXCOORD2,\n",
-"uniform sampler Texture_Normal : register(s0),\n",
-"uniform sampler Texture_Refraction : register(s3),\n",
-"uniform sampler Texture_Reflection : register(s7),\n",
-"uniform float4 DistortScaleRefractReflect : register(c14),\n",
-"uniform float4 ScreenScaleRefractReflect : register(c32),\n",
-"uniform float4 ScreenCenterRefractReflect : register(c31),\n",
-"uniform float4 RefractColor : register(c29),\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-" float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n",
-" //float2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
-" float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n",
-"#ifdef USEALPHAGENVERTEX\n",
-" float2 distort = DistortScaleRefractReflect.xy * gl_FrontColor.a;\n",
-" float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
-"#else\n",
-" float2 distort = DistortScaleRefractReflect.xy;\n",
-" float4 refractcolor = RefractColor;\n",
-"#endif\n",
-" float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * distort;\n",
-" // FIXME temporary hack to detect the case that the reflection\n",
-" // gets blackened at edges due to leaving the area that contains actual\n",
-" // content.\n",
-" // Remove this 'ack once we have a better way to stop this thing from\n",
-" // 'appening.\n",
-" float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
-" ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
-" dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * refractcolor;\n",
-"}\n",
-"#endif\n",
-"#else // !MODE_REFRACTION\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_WATER\n",
-"#ifdef VERTEX_SHADER\n",
-"\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"#ifdef USEALPHAGENVERTEX\n",
-"float4 gl_Color : COLOR0,\n",
-"#endif\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
-"float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
-"float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
-"uniform float4x4 TexMatrix : register(c0),\n",
-"uniform float3 EyePosition : register(c24),\n",
-"uniform float ClientTime : register(c2),\n",
-"#ifdef USEALPHAGENVERTEX\n",
-"out float4 gl_FrontColor : COLOR,\n",
-"#endif\n",
-"out float4 gl_Position : POSITION,\n",
-"out float2 TexCoord : TEXCOORD0,\n",
-"out float3 EyeVector : TEXCOORD1,\n",
-"out float4 ModelViewProjectionPosition : TEXCOORD2\n",
-")\n",
-"{\n",
-"#ifdef USEALPHAGENVERTEX\n",
-" gl_FrontColor = gl_Color;\n",
-"#endif\n",
-" TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n",
-" float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
-" EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-" ModelViewProjectionPosition = gl_Position;\n",
-"#ifdef USETRIPPY\n",
-" gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"void main\n",
-"(\n",
-"#ifdef USEALPHAGENVERTEX\n",
-"float4 gl_FrontColor : COLOR,\n",
-"#endif\n",
-"float2 TexCoord : TEXCOORD0,\n",
-"float3 EyeVector : TEXCOORD1,\n",
-"float4 ModelViewProjectionPosition : TEXCOORD2,\n",
-"uniform sampler Texture_Normal : register(s0),\n",
-"uniform sampler Texture_Refraction : register(s3),\n",
-"uniform sampler Texture_Reflection : register(s7),\n",
-"uniform float4 DistortScaleRefractReflect : register(c14),\n",
-"uniform float4 ScreenScaleRefractReflect : register(c32),\n",
-"uniform float4 ScreenCenterRefractReflect : register(c31),\n",
-"uniform float4 RefractColor : register(c29),\n",
-"uniform float4 ReflectColor : register(c26),\n",
-"uniform float ReflectFactor : register(c27),\n",
-"uniform float ReflectOffset : register(c28),\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-" float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
-" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
-" float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
-" //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n",
-"#ifdef USEALPHAGENVERTEX\n",
-" float4 distort = DistortScaleRefractReflect * gl_FrontColor.a;\n",
-" float reflectoffset = ReflectOffset * gl_FrontColor.a;\n",
-" float reflectfactor = ReflectFactor * gl_FrontColor.a;\n",
-" float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n",
-"#else\n",
-" float4 distort = DistortScaleRefractReflect;\n",
-" float reflectoffset = ReflectOffset;\n",
-" float reflectfactor = ReflectFactor;\n",
-" float4 refractcolor = RefractColor;\n",
-"#endif\n",
-" float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * distort;\n",
-" // FIXME temporary hack to detect the case that the reflection\n",
-" // gets blackened at edges due to leaving the area that contains actual\n",
-" // content.\n",
-" // Remove this 'ack once we have a better way to stop this thing from\n",
-" // 'appening.\n",
-" float f = min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(0.01, -0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord.xy + float2(-0.01, -0.01)).rgb) / 0.05);\n",
-" ScreenTexCoord.xy = lerp(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\n",
-" f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(0.01, -0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n",
-" ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n",
-" float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n",
-" dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n",
-"}\n",
-"#endif\n",
-"#else // !MODE_WATER\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"// TODO: get rid of tangentt (texcoord2) and use a crossproduct to regenerate it from tangents (texcoord1) and normal (texcoord3), this would require sending a 4 component texcoord1 with W as 1 or -1 according to which side the texcoord2 should be on\n",
-"\n",
-"// fragment shader specific:\n",
-"#ifdef FRAGMENT_SHADER\n",
-"\n",
-"#ifdef USEFOG\n",
-"float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n",
-"{\n",
-" float fogfrac;\n",
-" float3 fc = FogColor;\n",
-"#ifdef USEFOGALPHAHACK\n",
-" fc *= surfacecolor.a;\n",
-"#endif\n",
-"#ifdef USEFOGHEIGHTTEXTURE\n",
-" float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n",
-" fogfrac = fogheightpixel.a;\n",
-" return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
-"#else\n",
-"# ifdef USEFOGOUTSIDE\n",
-" fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n",
-"# else\n",
-" fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n",
-"# endif\n",
-" return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n",
-"#endif\n",
-"}\n",
-"#endif\n",
-"\n",
-"#ifdef USEOFFSETMAPPING\n",
-"float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n",
-"{\n",
-" float i;\n",
-" // distance-based LOD\n",
-"#ifdef USEOFFSETMAPPING_LOD\n",
-" //float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
-" //float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n",
-" float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n",
-"#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
-" // stupid workaround because 1-step and 2-step reliefmapping is void\n",
-" float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n",
-"#else\n",
-" float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n",
-"#endif\n",
-" float LODFactor = LODSteps / OffsetMapping_ScaleSteps.y;\n",
-" float4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, LODSteps, 1.0 / LODSteps, OffsetMapping_ScaleSteps.w * LODFactor);\n",
-"#else\n",
-" #define ScaleSteps OffsetMapping_ScaleSteps\n",
-"#endif\n",
-"#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n",
-" // 14 sample relief mapping: linear search and then binary search\n",
-" // this basically steps forward a small amount repeatedly until it finds\n",
-" // itself inside solid, then jitters forward and back using decreasing\n",
-" // amounts to find the impact\n",
-" //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n",
-" //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n",
-" float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n",
-" float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n",
-" OffsetVector *= ScaleSteps.z;\n",
-" for(i = 1.0; i < ScaleSteps.y; ++i)\n",
-" RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n",
-" for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n",
-" RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n",
-" return RT.xy;\n",
-"#else\n",
-" // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n",
-" //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n",
-" //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n",
-" float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n",
-" OffsetVector *= ScaleSteps.z;\n",
-" for(i = 0.0; i < ScaleSteps.y; ++i)\n",
-" TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n",
-" return TexCoord;\n",
-"#endif\n",
-"}\n",
-"#endif // USEOFFSETMAPPING\n",
-"\n",
-"#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
-"#if defined(USESHADOWMAP2D)\n",
-"# ifdef USESHADOWMAPORTHO\n",
-"# define GetShadowMapTC2D(dir, ShadowMap_Parameters) (max(float3(0.0, 0.0, 0.0), min(dir, ShadowMap_Parameters.xyz)))\n",
-"# else\n",
-"# ifdef USESHADOWMAPVSDCT\n",
-"float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n",
-"{\n",
-" float3 adir = abs(dir);\n",
-" float2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n",
-" float4 proj = texCUBE(Texture_CubeProjection, dir);\n",
-" return float3(lerp(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
-"}\n",
-"# else\n",
-"float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n",
-"{\n",
-" float3 adir = abs(dir);\n",
-" float m; float4 proj;\n",
-" if (adir.x > adir.y) { m = adir.x; proj = float4(dir.zyx, 0.5); } else { m = adir.y; proj = float4(dir.xzy, 1.5); }\n",
-" if (adir.z > m) { m = adir.z; proj = float4(dir, 2.5); }\n",
-"#ifdef HLSL\n",
-" return float3(proj.xy * ShadowMap_Parameters.x / m + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, m + 64 * ShadowMap_Parameters.w);\n",
-"#else\n",
-" float2 mparams = ShadowMap_Parameters.xy / m;\n",
-" return float3(proj.xy * mparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n",
-"#endif\n",
-"}\n",
-"# endif\n",
-"# endif\n",
-"#endif // defined(USESHADOWMAP2D)\n",
-"\n",
-"# ifdef USESHADOWMAP2D\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-"float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float4 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n",
-"#else\n",
-"float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float4 ShadowMap_TextureScale)\n",
-"#endif\n",
-"{\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-" float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters, Texture_CubeProjection) + float3(ShadowMap_TextureScale.zw, 0.0f);\n",
-"#else\n",
-" float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters) + float3(ShadowMap_TextureScale.zw, 0.0f);\n",
-"#endif\n",
-" float f;\n",
-"\n",
-"# ifdef USESHADOWSAMPLER\n",
-"# ifdef USESHADOWMAPPCF\n",
-"# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale.xy, shadowmaptc.z, 1.0)).r \n",
-" float2 center = shadowmaptc.xy*ShadowMap_TextureScale.xy;\n",
-" f = dot(float4(0.25,0.25,0.25,0.25), float4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n",
-"# else\n",
-" f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale.xy, shadowmaptc.z, 1.0)).r;\n",
-"# endif\n",
-"# else\n",
-"# ifdef USESHADOWMAPPCF\n",
-"# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n",
-"# ifdef GL_ARB_texture_gather\n",
-"# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n",
-"# else\n",
-"# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale.xy)\n",
-"# endif\n",
-" float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale.xy;\n",
-"# if USESHADOWMAPPCF > 1\n",
-" float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n",
-" float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n",
-" float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n",
-" float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n",
-" float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n",
-" float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n",
-" float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n",
-" float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n",
-" float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n",
-" float4 locols = float4(group1.ab, group3.ab);\n",
-" float4 hicols = float4(group7.rg, group9.rg);\n",
-" locols.yz += group2.ab;\n",
-" hicols.yz += group8.rg;\n",
-" float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n",
-" float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n",
-" lerp(locols, hicols, offset.y);\n",
-" float4 cols = group5 + float4(group2.rg, group8.ab);\n",
-" cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n",
-" f = dot(cols, float4(1.0/25.0));\n",
-"# else\n",
-" float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n",
-" float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n",
-" float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n",
-" float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n",
-" float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n",
-" lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n",
-" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
-"# endif\n",
-"# else\n",
-"# ifdef GL_EXT_gpu_shader4\n",
-"# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n",
-"# else\n",
-"# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale.xy).r \n",
-"# endif\n",
-"# if USESHADOWMAPPCF > 1\n",
-" float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n",
-" center *= ShadowMap_TextureScale.xy;\n",
-" float4 row1 = step(shadowmaptc.z, float4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n",
-" float4 row2 = step(shadowmaptc.z, float4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n",
-" float4 row3 = step(shadowmaptc.z, float4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n",
-" float4 row4 = step(shadowmaptc.z, float4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n",
-" float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n",
-" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n",
-"# else\n",
-" float2 center = shadowmaptc.xy*ShadowMap_TextureScale.xy, offset = frac(shadowmaptc.xy);\n",
-" float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n",
-" float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n",
-" float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n",
-" float3 cols = row2 + lerp(row1, row3, offset.y);\n",
-" f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n",
-"# endif\n",
-"# endif\n",
-"# else\n",
-" f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale.xy).r);\n",
-"# endif\n",
-"# endif\n",
-"# ifdef USESHADOWMAPORTHO\n",
-" return lerp(ShadowMap_Parameters.w, 1.0, f);\n",
-"# else\n",
-" return f;\n",
-"# endif\n",
-"}\n",
-"# endif\n",
-"#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
-"#endif // FRAGMENT_SHADER\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_DEFERREDGEOMETRY\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"float4 gl_Color : COLOR0,\n",
-"#endif\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
-"float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
-"float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
-"uniform float4x4 TexMatrix : register(c0),\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"uniform float4x4 BackgroundTexMatrix : register(c4),\n",
-"#endif\n",
-"uniform float4x4 ModelViewMatrix : register(c12),\n",
-"#ifdef USEOFFSETMAPPING\n",
-"uniform float3 EyePosition : register(c24),\n",
-"#endif\n",
-"uniform float ClientTime : register(c2),\n",
-"out float4 gl_Position : POSITION,\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"out float4 gl_FrontColor : COLOR,\n",
-"#endif\n",
-"out float4 TexCoordBoth : TEXCOORD0,\n",
-"#ifdef USEOFFSETMAPPING\n",
-"out float3 EyeVector : TEXCOORD2,\n",
-"#endif\n",
-"out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
-"out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
-"out float4 VectorR : TEXCOORD7 // direction of R texcoord (surface normal), Depth value\n",
-")\n",
-"{\n",
-" TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" gl_FrontColor = gl_Color;\n",
-" TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n",
-"#endif\n",
-"\n",
-" // transform unnormalized eye direction into tangent space\n",
-"#ifdef USEOFFSETMAPPING\n",
-" float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
-" EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
-"#endif\n",
-"\n",
-" VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n",
-" VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n",
-" VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-"#ifdef USETRIPPY\n",
-" gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
-"#endif\n",
-" VectorR.w = mul(ModelViewMatrix, gl_Vertex).z;\n",
-"}\n",
-"#endif // VERTEX_SHADER\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"void main\n",
-"(\n",
-"float4 TexCoordBoth : TEXCOORD0,\n",
-"float3 EyeVector : TEXCOORD2,\n",
-"float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
-"float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
-"float4 VectorR : TEXCOORD7, // direction of R texcoord (surface normal), Depth value\n",
-"uniform sampler Texture_Normal : register(s0),\n",
-"#ifdef USEALPHAKILL\n",
-"uniform sampler Texture_Color : register(s1),\n",
-"#endif\n",
-"uniform sampler Texture_Gloss : register(s2),\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"uniform sampler Texture_SecondaryNormal : register(s4),\n",
-"uniform sampler Texture_SecondaryGloss : register(s6),\n",
-"#endif\n",
-"#ifdef USEOFFSETMAPPING\n",
-"uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
-"uniform float4 OffsetMapping_LodDistance : register(c53),\n",
-"uniform float OffsetMapping_Bias : register(c54),\n",
-"#endif\n",
-"uniform half SpecularPower : register(c36),\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-" float2 TexCoord = TexCoordBoth.xy;\n",
-"#ifdef USEOFFSETMAPPING\n",
-" // apply offsetmapping\n",
-" float2 dPdx = ddx(TexCoord);\n",
-" float2 dPdy = ddy(TexCoord);\n",
-" float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
-"# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
-"#else\n",
-"# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
-"#endif\n",
-"\n",
-"#ifdef USEALPHAKILL\n",
-" if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n",
-" discard;\n",
-"#endif\n",
-"\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" float alpha = offsetMappedTexture2D(Texture_Color).a;\n",
-" float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n",
-" //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n",
-" //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n",
-"#endif\n",
-"\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n",
-" float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n",
-"#else\n",
-" float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n",
-" float a = offsetMappedTexture2D(Texture_Gloss).a;\n",
-"#endif\n",
-"\n",
-" float3 pixelnormal = normalize(surfacenormal.x * VectorS.xyz + surfacenormal.y * VectorT.xyz + surfacenormal.z * VectorR.xyz);\n",
-" dp_FragColor = float4(pixelnormal.x, pixelnormal.y, VectorR.w, a);\n",
-"}\n",
-"#endif // FRAGMENT_SHADER\n",
-"#else // !MODE_DEFERREDGEOMETRY\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"uniform float4x4 ModelViewMatrix : register(c12),\n",
-"out float4 gl_Position : POSITION,\n",
-"out float4 ModelViewPosition : TEXCOORD0\n",
-")\n",
-"{\n",
-" ModelViewPosition = mul(ModelViewMatrix, gl_Vertex);\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-"}\n",
-"#endif // VERTEX_SHADER\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"void main\n",
-"(\n",
-"#ifdef HLSL\n",
-"float2 Pixel : VPOS,\n",
-"#else\n",
-"float2 Pixel : WPOS,\n",
-"#endif\n",
-"float4 ModelViewPosition : TEXCOORD0,\n",
-"uniform float4x4 ViewToLight : register(c44),\n",
-"uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n",
-"uniform float3 LightPosition : register(c23),\n",
-"uniform half2 PixelToScreenTexCoord : register(c42),\n",
-"uniform half3 DeferredColor_Ambient : register(c9),\n",
-"uniform half3 DeferredColor_Diffuse : register(c10),\n",
-"#ifdef USESPECULAR\n",
-"uniform half3 DeferredColor_Specular : register(c11),\n",
-"uniform half SpecularPower : register(c36),\n",
-"#endif\n",
-"uniform sampler Texture_Attenuation : register(s9),\n",
-"uniform sampler Texture_ScreenDepth : register(s13),\n",
-"uniform sampler Texture_ScreenNormalMap : register(s14),\n",
-"\n",
-"#ifdef USECUBEFILTER\n",
-"uniform samplerCUBE Texture_Cube : register(s10),\n",
-"#endif\n",
-"\n",
-"#ifdef USESHADOWMAP2D\n",
-"# ifdef USESHADOWSAMPLER\n",
-"uniform sampler Texture_ShadowMap2D : register(s15),\n",
-"# else\n",
-"uniform sampler Texture_ShadowMap2D : register(s15),\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-"uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
-"#endif\n",
-"\n",
-"#if defined(USESHADOWMAP2D)\n",
-"uniform float4 ShadowMap_TextureScale : register(c35),\n",
-"uniform float4 ShadowMap_Parameters : register(c34),\n",
-"#endif\n",
-"\n",
-"out float4 gl_FragData0 : COLOR0,\n",
-"out float4 gl_FragData1 : COLOR1\n",
-")\n",
-"{\n",
-" // calculate viewspace pixel position\n",
-" float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
-" float3 position;\n",
-" // get the geometry information (depth, normal, specular exponent)\n",
-" half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n",
-" // decode viewspace pixel normal\n",
-"// float3 surfacenormal = normalize(normalmap.rgb - cast_myhalf3(0.5,0.5,0.5));\n",
-" float3 surfacenormal = half3(normalmap.rg, sqrt(1.0-dot(normalmap.rg, normalmap.rg)));\n",
-" // decode viewspace pixel position\n",
-"// position.z = decodedepthmacro(dp_texture2D(Texture_ScreenDepth, ScreenTexCoord));\n",
-" position.z = normalmap.b;\n",
-"// position.z = ScreenToDepth.y / (dp_texture2D(Texture_ScreenDepth, ScreenTexCoord).r + ScreenToDepth.x);\n",
-" position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n",
-"\n",
-" // now do the actual shading\n",
-" // surfacenormal = pixel normal in viewspace\n",
-" // LightVector = pixel to light in viewspace\n",
-" // CubeVector = position in lightspace\n",
-" // eyevector = pixel to view in viewspace\n",
-" float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n",
-" half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
-"#ifdef USEDIFFUSE\n",
-" // calculate diffuse shading\n",
-" half3 lightnormal = half3(normalize(LightPosition - position));\n",
-" half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
-"#endif\n",
-"#ifdef USESPECULAR\n",
-" // calculate directional shading\n",
-" float3 eyevector = position * -1.0;\n",
-"# ifdef USEEXACTSPECULARMATH\n",
-" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
-"# else\n",
-" half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n",
-" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#if defined(USESHADOWMAP2D)\n",
-" fade *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-", Texture_CubeProjection\n",
-"#endif\n",
-" ));\n",
-"#endif\n",
-"\n",
-"#ifdef USEDIFFUSE\n",
-" gl_FragData0 = float4((DeferredColor_Ambient + DeferredColor_Diffuse * diffuse) * fade, 1.0);\n",
-"#else\n",
-" gl_FragData0 = float4(DeferredColor_Ambient * fade, 1.0);\n",
-"#endif\n",
-"#ifdef USESPECULAR\n",
-" gl_FragData1 = float4(DeferredColor_Specular * (specular * fade), 1.0);\n",
-"#else\n",
-" gl_FragData1 = float4(0.0, 0.0, 0.0, 1.0);\n",
-"#endif\n",
-"\n",
-"# ifdef USECUBEFILTER\n",
-" float3 cubecolor = texCUBE(Texture_Cube, CubeVector).rgb;\n",
-" gl_FragData0.rgb *= cubecolor;\n",
-" gl_FragData1.rgb *= cubecolor;\n",
-"# endif\n",
-"}\n",
-"#endif // FRAGMENT_SHADER\n",
-"#else // !MODE_DEFERREDLIGHTSOURCE\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef VERTEX_SHADER\n",
-"void main\n",
-"(\n",
-"float4 gl_Vertex : POSITION,\n",
-"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n",
-"#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
-"float4 gl_Color : COLOR0,\n",
-"#endif\n",
-"float4 gl_MultiTexCoord0 : TEXCOORD0,\n",
-"float4 gl_MultiTexCoord1 : TEXCOORD1,\n",
-"float4 gl_MultiTexCoord2 : TEXCOORD2,\n",
-"float4 gl_MultiTexCoord3 : TEXCOORD3,\n",
-"float4 gl_MultiTexCoord4 : TEXCOORD4,\n",
-"\n",
-"uniform float3 EyePosition : register(c24),\n",
-"uniform float4x4 TexMatrix : register(c0),\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"uniform float4x4 BackgroundTexMatrix : register(c4),\n",
-"#endif\n",
-"#ifdef MODE_LIGHTSOURCE\n",
-"uniform float4x4 ModelToLight : register(c20),\n",
-"#endif\n",
-"#ifdef MODE_LIGHTSOURCE\n",
-"uniform float3 LightPosition : register(c27),\n",
-"#endif\n",
-"#ifdef MODE_LIGHTDIRECTION\n",
-"uniform float3 LightDir : register(c26),\n",
-"#endif\n",
-"uniform float4 FogPlane : register(c25),\n",
-"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
-"uniform float3 LightPosition : register(c27),\n",
-"#endif\n",
-"#ifdef USESHADOWMAPORTHO\n",
-"uniform float4x4 ShadowMapMatrix : register(c16),\n",
-"#endif\n",
-"uniform float ClientTime : register(c2),\n",
-"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
-"out float4 gl_FrontColor : COLOR,\n",
-"#endif\n",
-"out float4 TexCoordBoth : TEXCOORD0,\n",
-"#ifdef USELIGHTMAP\n",
-"out float2 TexCoordLightmap : TEXCOORD1,\n",
-"#endif\n",
-"#ifdef USEEYEVECTOR\n",
-"out float3 EyeVector : TEXCOORD2,\n",
-"#endif\n",
-"#ifdef USEREFLECTION\n",
-"out float4 ModelViewProjectionPosition : TEXCOORD3,\n",
-"#endif\n",
-"#ifdef USEFOG\n",
-"out float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
-"#endif\n",
-"#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE) || defined(USEDIFFUSE)\n",
-"out float3 LightVector : TEXCOORD1,\n",
-"#endif\n",
-"#ifdef MODE_LIGHTSOURCE\n",
-"out float3 CubeVector : TEXCOORD3,\n",
-"#endif\n",
-"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
-"out float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
-"out float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
-"out float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
-"#endif\n",
-"#ifdef USESHADOWMAPORTHO\n",
-"out float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
-"#endif\n",
-"out float4 gl_Position : POSITION\n",
-")\n",
-"{\n",
-"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n",
-" gl_FrontColor = gl_Color;\n",
-"#endif\n",
-" // copy the surface texcoord\n",
-" TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n",
-"#endif\n",
-"#ifdef USELIGHTMAP\n",
-" TexCoordLightmap = gl_MultiTexCoord4.xy;\n",
-"#endif\n",
-"\n",
-"#ifdef MODE_LIGHTSOURCE\n",
-" // transform vertex position into light attenuation/cubemap space\n",
-" // (-1 to +1 across the light box)\n",
-" CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n",
-"\n",
-"# ifdef USEDIFFUSE\n",
-" // transform unnormalized light direction into tangent space\n",
-" // (we use unnormalized to ensure that it interpolates correctly and then\n",
-" // normalize it per pixel)\n",
-" float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n",
-" LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n",
-" LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n",
-"#endif\n",
-"\n",
-" // transform unnormalized eye direction into tangent space\n",
-"#ifdef USEEYEVECTOR\n",
-" float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n",
-" EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n",
-"#endif\n",
-"\n",
-"#ifdef USEFOG\n",
-" EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - gl_Vertex.xyz;\n",
-" EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, gl_Vertex);\n",
-"#endif\n",
-"\n",
-"#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
-" VectorS = gl_MultiTexCoord1.xyz;\n",
-" VectorT = gl_MultiTexCoord2.xyz;\n",
-" VectorR = gl_MultiTexCoord3.xyz;\n",
-"#endif\n",
-"\n",
-" // transform vertex to camera space, using ftransform to match non-VS rendering\n",
-" gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n",
-"\n",
-"#ifdef USESHADOWMAPORTHO\n",
-" ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n",
-"#endif\n",
-"\n",
-"#ifdef USEREFLECTION\n",
-" ModelViewProjectionPosition = gl_Position;\n",
-"#endif\n",
-"#ifdef USETRIPPY\n",
-" gl_Position = TrippyVertex(gl_Position, ClientTime);\n",
-"#endif\n",
-"}\n",
-"#endif // VERTEX_SHADER\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef FRAGMENT_SHADER\n",
-"void main\n",
-"(\n",
-"#ifdef USEDEFERREDLIGHTMAP\n",
-"#ifdef HLSL\n",
-"float2 Pixel : VPOS,\n",
-"#else\n",
-"float2 Pixel : WPOS,\n",
-"#endif\n",
-"#endif\n",
-"float4 gl_FrontColor : COLOR,\n",
-"float4 TexCoordBoth : TEXCOORD0,\n",
-"#ifdef USELIGHTMAP\n",
-"float2 TexCoordLightmap : TEXCOORD1,\n",
-"#endif\n",
-"#ifdef USEEYEVECTOR\n",
-"float3 EyeVector : TEXCOORD2,\n",
-"#endif\n",
-"#ifdef USEREFLECTION\n",
-"float4 ModelViewProjectionPosition : TEXCOORD3,\n",
-"#endif\n",
-"#ifdef USEFOG\n",
-"float4 EyeVectorModelSpaceFogPlaneVertexDist : TEXCOORD4,\n",
-"#endif\n",
-"#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n",
-"float3 LightVector : TEXCOORD1,\n",
-"#endif\n",
-"#ifdef MODE_LIGHTSOURCE\n",
-"float3 CubeVector : TEXCOORD3,\n",
-"#endif\n",
-"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
-"float4 ModelViewPosition : TEXCOORD0,\n",
-"#endif\n",
-"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n",
-"float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n",
-"float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n",
-"float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n",
-"#endif\n",
-"#ifdef USESHADOWMAPORTHO\n",
-"float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n",
-"#endif\n",
-"\n",
-"uniform sampler Texture_Normal : register(s0),\n",
-"uniform sampler Texture_Color : register(s1),\n",
-"#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
-"uniform sampler Texture_Gloss : register(s2),\n",
-"#endif\n",
-"#ifdef USEGLOW\n",
-"uniform sampler Texture_Glow : register(s3),\n",
-"#endif\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"uniform sampler Texture_SecondaryNormal : register(s4),\n",
-"uniform sampler Texture_SecondaryColor : register(s5),\n",
-"#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
-"uniform sampler Texture_SecondaryGloss : register(s6),\n",
-"#endif\n",
-"#ifdef USEGLOW\n",
-"uniform sampler Texture_SecondaryGlow : register(s7),\n",
-"#endif\n",
-"#endif\n",
-"#ifdef USECOLORMAPPING\n",
-"uniform sampler Texture_Pants : register(s4),\n",
-"uniform sampler Texture_Shirt : register(s7),\n",
-"#endif\n",
-"#ifdef USEFOG\n",
-"uniform sampler Texture_FogHeightTexture : register(s14),\n",
-"uniform sampler Texture_FogMask : register(s8),\n",
-"#endif\n",
-"#ifdef USELIGHTMAP\n",
-"uniform sampler Texture_Lightmap : register(s9),\n",
-"#endif\n",
-"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n",
-"uniform sampler Texture_Deluxemap : register(s10),\n",
-"#endif\n",
-"#ifdef USEREFLECTION\n",
-"uniform sampler Texture_Reflection : register(s7),\n",
-"#endif\n",
-"\n",
-"#ifdef MODE_DEFERREDLIGHTSOURCE\n",
-"uniform sampler Texture_ScreenDepth : register(s13),\n",
-"uniform sampler Texture_ScreenNormalMap : register(s14),\n",
-"#endif\n",
-"#ifdef USEDEFERREDLIGHTMAP\n",
-"uniform sampler Texture_ScreenDepth : register(s13),\n",
-"uniform sampler Texture_ScreenNormalMap : register(s14),\n",
-"uniform sampler Texture_ScreenDiffuse : register(s11),\n",
-"uniform sampler Texture_ScreenSpecular : register(s12),\n",
-"#endif\n",
-"\n",
-"#ifdef USECOLORMAPPING\n",
-"uniform half3 Color_Pants : register(c7),\n",
-"uniform half3 Color_Shirt : register(c8),\n",
-"#endif\n",
-"#ifdef USEFOG\n",
-"uniform float3 FogColor : register(c16),\n",
-"uniform float FogRangeRecip : register(c20),\n",
-"uniform float FogPlaneViewDist : register(c19),\n",
-"uniform float FogHeightFade : register(c17),\n",
-"#endif\n",
-"\n",
-"#ifdef USEOFFSETMAPPING\n",
-"uniform float4 OffsetMapping_ScaleSteps : register(c24),\n",
-"uniform float OffsetMapping_Bias : register(c54),\n",
-"#endif\n",
-"\n",
-"#ifdef USEDEFERREDLIGHTMAP\n",
-"uniform half2 PixelToScreenTexCoord : register(c42),\n",
-"uniform half3 DeferredMod_Diffuse : register(c12),\n",
-"uniform half3 DeferredMod_Specular : register(c13),\n",
-"#endif\n",
-"uniform half3 Color_Ambient : register(c3),\n",
-"uniform half3 Color_Diffuse : register(c4),\n",
-"uniform half3 Color_Specular : register(c5),\n",
-"uniform half SpecularPower : register(c36),\n",
-"#ifdef USEGLOW\n",
-"uniform half3 Color_Glow : register(c6),\n",
-"#endif\n",
-"uniform half Alpha : register(c0),\n",
-"#ifdef USEREFLECTION\n",
-"uniform float4 DistortScaleRefractReflect : register(c14),\n",
-"uniform float4 ScreenScaleRefractReflect : register(c32),\n",
-"uniform float4 ScreenCenterRefractReflect : register(c31),\n",
-"uniform half4 ReflectColor : register(c26),\n",
-"#endif\n",
-"#ifdef USEREFLECTCUBE\n",
-"uniform float4x4 ModelToReflectCube : register(c48),\n",
-"uniform sampler Texture_ReflectMask : register(s5),\n",
-"uniform samplerCUBE Texture_ReflectCube : register(s6),\n",
-"#endif\n",
-"\n",
-"#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n",
-"uniform sampler Texture_Attenuation : register(s9),\n",
-"uniform samplerCUBE Texture_Cube : register(s10),\n",
-"#endif\n",
-"\n",
-"#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n",
-"\n",
-"#ifdef USESHADOWMAP2D\n",
-"# ifdef USESHADOWSAMPLER\n",
-"uniform sampler Texture_ShadowMap2D : register(s15),\n",
-"# else\n",
-"uniform sampler Texture_ShadowMap2D : register(s15),\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-"uniform samplerCUBE Texture_CubeProjection : register(s12),\n",
-"#endif\n",
-"\n",
-"#if defined(USESHADOWMAP2D)\n",
-"uniform float4 ShadowMap_TextureScale : register(c35),\n",
-"uniform float4 ShadowMap_Parameters : register(c34),\n",
-"#endif\n",
-"#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n",
-"\n",
-"out float4 dp_FragColor : COLOR\n",
-")\n",
-"{\n",
-" float2 TexCoord = TexCoordBoth.xy;\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" float2 TexCoord2 = TexCoordBoth.zw;\n",
-"#endif\n",
-"#ifdef USEOFFSETMAPPING\n",
-" // apply offsetmapping\n",
-" float2 dPdx = ddx(TexCoord);\n",
-" float2 dPdy = ddy(TexCoord);\n",
-" float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n",
-"# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n",
-"#else\n",
-"# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n",
-"#endif\n",
-"\n",
-" // combine the diffuse textures (base, pants, shirt)\n",
-" half4 color = half4(offsetMappedTexture2D(Texture_Color));\n",
-"#ifdef USEALPHAKILL\n",
-" if (color.a < 0.5)\n",
-" discard;\n",
-"#endif\n",
-" color.a *= Alpha;\n",
-"#ifdef USECOLORMAPPING\n",
-" color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n",
-"#endif\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-"#ifdef USEBOTHALPHAS\n",
-" half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n",
-" half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n",
-" color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n",
-"#else\n",
-" half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n",
-" //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n",
-" //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n",
-" color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n",
-" color.a = 1.0;\n",
-" //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n",
-"#endif\n",
-"#endif\n",
-"#ifdef USEALPHAGENVERTEX\n",
-" color.a *= gl_FrontColor.a;\n",
-"#endif\n",
-"\n",
-" // get the surface normal\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n",
-"#else\n",
-" half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n",
-"#endif\n",
-"\n",
-" // get the material colors\n",
-" half3 diffusetex = color.rgb;\n",
-"#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n",
-"# ifdef USEVERTEXTEXTUREBLEND\n",
-" half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n",
-"# else\n",
-" half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#ifdef USEREFLECTCUBE\n",
-" float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n",
-" float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n",
-" float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n",
-" diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n",
-"#endif\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_LIGHTSOURCE\n",
-" // light source\n",
-"#ifdef USEDIFFUSE\n",
-" half3 lightnormal = half3(normalize(LightVector));\n",
-" half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
-" color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n",
-"#ifdef USESPECULAR\n",
-"#ifdef USEEXACTSPECULARMATH\n",
-" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
-"#else\n",
-" half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
-" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
-"#endif\n",
-" color.rgb += glosstex.rgb * (specular * Color_Specular);\n",
-"#endif\n",
-"#else\n",
-" color.rgb = diffusetex * Color_Ambient;\n",
-"#endif\n",
-" color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n",
-"#if defined(USESHADOWMAP2D)\n",
-" color.rgb *= half(ShadowMapCompare(CubeVector, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-", Texture_CubeProjection\n",
-"#endif\n",
-" ));\n",
-"\n",
-"#endif\n",
-"# ifdef USECUBEFILTER\n",
-" color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n",
-"# endif\n",
-"\n",
-"#ifdef USESHADOWMAP2D\n",
-"#ifdef USESHADOWMAPVSDCT\n",
-"// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection);\n",
-"#else\n",
-"// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n",
-"#endif\n",
-"// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
-"// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy).rgb);\n",
-"// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale.xy,1.0));\n",
-"// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
-"// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n",
-"// color.rgb = half3(tex2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy).rgb);\n",
-"// color.rgb = half3(shadowmaptc.xyz * float3(ShadowMap_TextureScale.xy,1.0));\n",
-"// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
-"// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
-"// color.r = half(shadowmaptc.z);\n",
-"// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale.xy));\n",
-"// color.r = half(shadowmaptc.z);\n",
-"// color.r = 1;\n",
-"// color.rgb = abs(CubeVector);\n",
-"#endif\n",
-"// color.rgb = half3(1,1,1);\n",
-"#endif // MODE_LIGHTSOURCE\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_LIGHTDIRECTION\n",
-" #define SHADING\n",
-" #ifdef USEDIFFUSE\n",
-" half3 lightnormal = half3(normalize(LightVector));\n",
-" #endif\n",
-" #define lightcolor 1\n",
-"#endif // MODE_LIGHTDIRECTION\n",
-"#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
-" #define SHADING\n",
-" // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n",
-" half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
-" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
-" // convert modelspace light vector to tangentspace\n",
-" half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n",
-" // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n",
-" // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n",
-" // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n",
-" // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n",
-" // to map the luxels to coordinates on the draw surfaces), which also causes\n",
-" // deluxemaps to be wrong because light contributions from the wrong side of the surface\n",
-" // are added up. To prevent divisions by zero or strong exaggerations, a max()\n",
-" // nudge is done here at expense of some additional fps. This is ONLY needed for\n",
-" // deluxemaps, tangentspace deluxemap avoid this problem by design.\n",
-" lightcolor *= 1.0 / max(0.25, lightnormal.z);\n",
-"#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n",
-"#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n",
-" #define SHADING\n",
-" // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n",
-" half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n",
-" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
-"#endif\n",
-"#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n",
-" #define SHADING\n",
-" // forced deluxemap on lightmapped/vertexlit surfaces\n",
-" half3 lightnormal = half3(0.0, 0.0, 1.0);\n",
-" #ifdef USELIGHTMAP\n",
-" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n",
-" #else\n",
-" half3 lightcolor = half3(gl_FrontColor.rgb);\n",
-" #endif\n",
-"#endif\n",
-"#ifdef MODE_FAKELIGHT\n",
-" #define SHADING\n",
-" half3 lightnormal = half3(normalize(EyeVector));\n",
-" #define lightcolor 1\n",
-"#endif // MODE_FAKELIGHT\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef MODE_LIGHTMAP\n",
-" color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n",
-"#endif // MODE_LIGHTMAP\n",
-"#ifdef MODE_VERTEXCOLOR\n",
-" color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n",
-"#endif // MODE_VERTEXCOLOR\n",
-"#ifdef MODE_FLATCOLOR\n",
-" color.rgb = diffusetex * Color_Ambient;\n",
-"#endif // MODE_FLATCOLOR\n",
-"\n",
-"\n",
-"\n",
-"\n",
-"#ifdef SHADING\n",
-"# ifdef USEDIFFUSE\n",
-" half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n",
-"# ifdef USESPECULAR\n",
-"# ifdef USEEXACTSPECULARMATH\n",
-" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
-"# else\n",
-" half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n",
-" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n",
-"# endif\n",
-" color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n",
-"# else\n",
-" color.rgb = diffusetex * (Color_Ambient + Color_Diffuse * diffuse * lightcolor);\n",
-"# endif\n",
-"# else\n",
-" color.rgb = diffusetex * Color_Ambient;\n",
-"# endif\n",
-"#endif\n",
-"\n",
-"#ifdef USESHADOWMAPORTHO\n",
-" color.rgb *= half(ShadowMapCompare(ShadowMapTC, Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale));\n",
-"#endif\n",
-"\n",
-"#ifdef USEDEFERREDLIGHTMAP\n",
-" float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n",
-" color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n",
-" color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n",
-"// color.rgb = half3(tex2D(Texture_ScreenDepth, ScreenTexCoord).rgb);\n",
-"// color.r = half(texDepth2D(Texture_ScreenDepth, ScreenTexCoord)) * 1.0;\n",
-"#endif\n",
-"\n",
-"#ifdef USEGLOW\n",
-"#ifdef USEVERTEXTEXTUREBLEND\n",
-" color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n",
-"#else\n",
-" color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n",
-"#endif\n",
-"#endif\n",
-"\n",
-"#ifdef USEFOG\n",
-" color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n",
-"#endif\n",
-"\n",
-" // reflection must come last because it already contains exactly the correct fog (the reflection render preserves camera distance from the plane, it only flips the side) and ContrastBoost/SceneBrightness\n",
-"#ifdef USEREFLECTION\n",
-" float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
-" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n",
-" float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n",
-" float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n",
-" // FIXME temporary hack to detect the case that the reflection\n",
-" // gets blackened at edges due to leaving the area that contains actual\n",
-" // content.\n",
-" // Remove this 'ack once we have a better way to stop this thing from\n",
-" // 'appening.\n",
-" float f = min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(0.01, -0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n",
-" f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n",
-" ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n",
-" color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n",
-"#endif\n",
-"\n",
-" dp_FragColor = float4(color);\n",
-"}\n",
-"#endif // FRAGMENT_SHADER\n",
-"\n",
-"#endif // !MODE_DEFERREDLIGHTSOURCE\n",
-"#endif // !MODE_DEFERREDGEOMETRY\n",
-"#endif // !MODE_WATER\n",
-"#endif // !MODE_REFRACTION\n",
-"#endif // !MODE_BLOOMBLUR\n",
-"#endif // !MODE_GENERIC\n",
-"#endif // !MODE_POSTPROCESS\n",
-"#endif // !MODE_DEPTH_OR_SHADOW\n",
typedef enum renderpath_e
{
- RENDERPATH_GL11,
- RENDERPATH_GL13,
RENDERPATH_GL20,
- RENDERPATH_D3D9,
- RENDERPATH_D3D10,
- RENDERPATH_D3D11,
- RENDERPATH_SOFT,
- RENDERPATH_GLES1,
RENDERPATH_GLES2
}
renderpath_t;
viddef_support_t support;
- // in RENDERPATH_SOFT this is a 32bpp native-endian ARGB framebuffer
- // (native-endian ARGB meaning that in little endian it is BGRA bytes,
- // in big endian it is ARGB byte order, the format is converted during
- // blit to the window)
- unsigned int *softpixels;
- unsigned int *softdepthpixels;
-
int forcetextype; // always use GL_BGRA for D3D, always use GL_RGBA for GLES, etc
} viddef_t;
extern qboolean vid_activewindow;
extern qboolean vid_supportrefreshrate;
-extern cvar_t vid_soft;
-extern cvar_t vid_soft_threads;
-extern cvar_t vid_soft_interlace;
-
extern cvar_t vid_fullscreen;
extern cvar_t vid_width;
extern cvar_t vid_height;
#include "quakedef.h"
#include "image.h"
-#include "dpsoftrast.h"
#include "utf8lib.h"
#ifndef __IPHONEOS__
static SDL_Window *window;
static int window_flags;
#endif
-static SDL_Surface *vid_softsurface;
static vid_mode_t desktop_mode;
/////////////////////////
vid.height = event.resize.h;
if (!vid_isfullscreen)
video_screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags);
- if (vid_softsurface)
- {
- SDL_FreeSurface(vid_softsurface);
- vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
- SDL_SetAlpha(vid_softsurface, 0, 255);
- vid.softpixels = (unsigned int *)vid_softsurface->pixels;
- if (vid.softdepthpixels)
- free(vid.softdepthpixels);
- vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
- }
#ifdef SDL_R_RESTART
// better not call R_Modules_Restart from here directly, as this may wreak havoc...
// so, let's better queue it for next frame
{
vid.width = event.window.data1;
vid.height = event.window.data2;
- if (vid_softsurface)
- {
- SDL_FreeSurface(vid_softsurface);
- vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
- SDL_SetSurfaceBlendMode(vid_softsurface, SDL_BLENDMODE_NONE);
- vid.softpixels = (unsigned int *)vid_softsurface->pixels;
- if (vid.softdepthpixels)
- free(vid.softdepthpixels);
- vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
- }
#ifdef SDL_R_RESTART
// better not call R_Modules_Restart from here directly, as this may wreak havoc...
// so, let's better queue it for next frame
const GLubyte* wrapglGetString(GLenum name) {PRECALL;return (const GLubyte*)glGetString(name);POSTCALL;}
void wrapglActiveStencilFace(GLenum e) {PRECALL;Con_Printf("glActiveStencilFace(e)\n");POSTCALL;}
void wrapglActiveTexture(GLenum e) {PRECALL;glActiveTexture(e);POSTCALL;}
-void wrapglAlphaFunc(GLenum func, GLclampf ref) {PRECALL;Con_Printf("glAlphaFunc(func, ref)\n");POSTCALL;}
void wrapglArrayElement(GLint i) {PRECALL;Con_Printf("glArrayElement(i)\n");POSTCALL;}
void wrapglAttachShader(GLuint containerObj, GLuint obj) {PRECALL;glAttachShader(containerObj, obj);POSTCALL;}
-//void wrapglBegin(GLenum mode) {PRECALL;Con_Printf("glBegin(mode)\n");POSTCALL;}
//void wrapglBeginQuery(GLenum target, GLuint qid) {PRECALL;glBeginQuery(target, qid);POSTCALL;}
void wrapglBindAttribLocation(GLuint programObj, GLuint index, const GLchar *name) {PRECALL;glBindAttribLocation(programObj, index, name);POSTCALL;}
//void wrapglBindFragDataLocation(GLuint programObj, GLuint index, const GLchar *name) {PRECALL;glBindFragDataLocation(programObj, index, name);POSTCALL;}
void wrapglClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {PRECALL;glClearColor(red, green, blue, alpha);POSTCALL;}
void wrapglClearDepth(GLclampd depth) {PRECALL;/*Con_Printf("glClearDepth(%f)\n", depth);glClearDepthf((float)depth);*/POSTCALL;}
void wrapglClearStencil(GLint s) {PRECALL;glClearStencil(s);POSTCALL;}
-void wrapglClientActiveTexture(GLenum target) {PRECALL;Con_Printf("glClientActiveTexture(target)\n");POSTCALL;}
-void wrapglColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {PRECALL;Con_Printf("glColor4f(red, green, blue, alpha)\n");POSTCALL;}
-void wrapglColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) {PRECALL;Con_Printf("glColor4ub(red, green, blue, alpha)\n");POSTCALL;}
void wrapglColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {PRECALL;glColorMask(red, green, blue, alpha);POSTCALL;}
-void wrapglColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) {PRECALL;Con_Printf("glColorPointer(size, type, stride, ptr)\n");POSTCALL;}
void wrapglCompileShader(GLuint shaderObj) {PRECALL;glCompileShader(shaderObj);POSTCALL;}
void wrapglCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data) {PRECALL;glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);POSTCALL;}
void wrapglCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data) {PRECALL;Con_Printf("glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data)\n");POSTCALL;}
void wrapglDepthRangef(GLclampf near_val, GLclampf far_val) {PRECALL;glDepthRangef(near_val, far_val);POSTCALL;}
void wrapglDetachShader(GLuint containerObj, GLuint attachedObj) {PRECALL;glDetachShader(containerObj, attachedObj);POSTCALL;}
void wrapglDisable(GLenum cap) {PRECALL;glDisable(cap);POSTCALL;}
-void wrapglDisableClientState(GLenum cap) {PRECALL;Con_Printf("glDisableClientState(cap)\n");POSTCALL;}
void wrapglDisableVertexAttribArray(GLuint index) {PRECALL;glDisableVertexAttribArray(index);POSTCALL;}
void wrapglDrawArrays(GLenum mode, GLint first, GLsizei count) {PRECALL;glDrawArrays(mode, first, count);POSTCALL;}
void wrapglDrawBuffer(GLenum mode) {PRECALL;Con_Printf("glDrawBuffer(mode)\n");POSTCALL;}
//void wrapglDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices) {PRECALL;glDrawRangeElements(mode, start, end, count, type, indices);POSTCALL;}
//void wrapglDrawRangeElementsEXT(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices) {PRECALL;glDrawRangeElements(mode, start, end, count, type, indices);POSTCALL;}
void wrapglEnable(GLenum cap) {PRECALL;glEnable(cap);POSTCALL;}
-void wrapglEnableClientState(GLenum cap) {PRECALL;Con_Printf("glEnableClientState(cap)\n");POSTCALL;}
void wrapglEnableVertexAttribArray(GLuint index) {PRECALL;glEnableVertexAttribArray(index);POSTCALL;}
-//void wrapglEnd(void) {PRECALL;Con_Printf("glEnd()\n");POSTCALL;}
//void wrapglEndQuery(GLenum target) {PRECALL;glEndQuery(target);POSTCALL;}
void wrapglFinish(void) {PRECALL;glFinish();POSTCALL;}
void wrapglFlush(void) {PRECALL;glFlush();POSTCALL;}
void wrapglGetUniformfv(GLuint programObj, GLint location, GLfloat *params) {PRECALL;glGetUniformfv(programObj, location, params);POSTCALL;}
void wrapglGetUniformiv(GLuint programObj, GLint location, GLint *params) {PRECALL;glGetUniformiv(programObj, location, params);POSTCALL;}
void wrapglHint(GLenum target, GLenum mode) {PRECALL;glHint(target, mode);POSTCALL;}
-void wrapglLineWidth(GLfloat width) {PRECALL;glLineWidth(width);POSTCALL;}
void wrapglLinkProgram(GLuint programObj) {PRECALL;glLinkProgram(programObj);POSTCALL;}
-void wrapglLoadIdentity(void) {PRECALL;Con_Printf("glLoadIdentity()\n");POSTCALL;}
-void wrapglLoadMatrixf(const GLfloat *m) {PRECALL;Con_Printf("glLoadMatrixf(m)\n");POSTCALL;}
-void wrapglMatrixMode(GLenum mode) {PRECALL;Con_Printf("glMatrixMode(mode)\n");POSTCALL;}
-void wrapglMultiTexCoord1f(GLenum target, GLfloat s) {PRECALL;Con_Printf("glMultiTexCoord1f(target, s)\n");POSTCALL;}
-void wrapglMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t) {PRECALL;Con_Printf("glMultiTexCoord2f(target, s, t)\n");POSTCALL;}
-void wrapglMultiTexCoord3f(GLenum target, GLfloat s, GLfloat t, GLfloat r) {PRECALL;Con_Printf("glMultiTexCoord3f(target, s, t, r)\n");POSTCALL;}
-void wrapglMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {PRECALL;Con_Printf("glMultiTexCoord4f(target, s, t, r, q)\n");POSTCALL;}
-void wrapglNormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr) {PRECALL;Con_Printf("glNormalPointer(type, stride, ptr)\n");POSTCALL;}
void wrapglPixelStorei(GLenum pname, GLint param) {PRECALL;glPixelStorei(pname, param);POSTCALL;}
void wrapglPointSize(GLfloat size) {PRECALL;Con_Printf("glPointSize(size)\n");POSTCALL;}
//void wrapglPolygonMode(GLenum face, GLenum mode) {PRECALL;Con_Printf("glPolygonMode(face, mode)\n");POSTCALL;}
void wrapglStencilMask(GLuint mask) {PRECALL;glStencilMask(mask);POSTCALL;}
void wrapglStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {PRECALL;glStencilOp(fail, zfail, zpass);POSTCALL;}
void wrapglStencilOpSeparate(GLenum e1, GLenum e2, GLenum e3, GLenum e4) {PRECALL;Con_Printf("glStencilOpSeparate(e1, e2, e3, e4)\n");POSTCALL;}
-void wrapglTexCoord1f(GLfloat s) {PRECALL;Con_Printf("glTexCoord1f(s)\n");POSTCALL;}
-void wrapglTexCoord2f(GLfloat s, GLfloat t) {PRECALL;Con_Printf("glTexCoord2f(s, t)\n");POSTCALL;}
-void wrapglTexCoord3f(GLfloat s, GLfloat t, GLfloat r) {PRECALL;Con_Printf("glTexCoord3f(s, t, r)\n");POSTCALL;}
-void wrapglTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) {PRECALL;Con_Printf("glTexCoord4f(s, t, r, q)\n");POSTCALL;}
-void wrapglTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) {PRECALL;Con_Printf("glTexCoordPointer(size, type, stride, ptr)\n");POSTCALL;}
-void wrapglTexEnvf(GLenum target, GLenum pname, GLfloat param) {PRECALL;Con_Printf("glTexEnvf(target, pname, param)\n");POSTCALL;}
-void wrapglTexEnvfv(GLenum target, GLenum pname, const GLfloat *params) {PRECALL;Con_Printf("glTexEnvfv(target, pname, params)\n");POSTCALL;}
-void wrapglTexEnvi(GLenum target, GLenum pname, GLint param) {PRECALL;Con_Printf("glTexEnvi(target, pname, param)\n");POSTCALL;}
void wrapglTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {PRECALL;glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels);POSTCALL;}
void wrapglTexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {PRECALL;Con_Printf("glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels)\n");POSTCALL;}
void wrapglTexParameterf(GLenum target, GLenum pname, GLfloat param) {PRECALL;glTexParameterf(target, pname, param);POSTCALL;}
qglGetString = wrapglGetString;
// qglActiveStencilFaceEXT = wrapglActiveStencilFace;
qglActiveTexture = wrapglActiveTexture;
- qglAlphaFunc = wrapglAlphaFunc;
qglArrayElement = wrapglArrayElement;
qglAttachShader = wrapglAttachShader;
-// qglBegin = wrapglBegin;
// qglBeginQueryARB = wrapglBeginQuery;
qglBindAttribLocation = wrapglBindAttribLocation;
// qglBindFragDataLocation = wrapglBindFragDataLocation;
qglClearColor = wrapglClearColor;
qglClearDepth = wrapglClearDepth;
qglClearStencil = wrapglClearStencil;
- qglClientActiveTexture = wrapglClientActiveTexture;
- qglColor4f = wrapglColor4f;
- qglColor4ub = wrapglColor4ub;
qglColorMask = wrapglColorMask;
- qglColorPointer = wrapglColorPointer;
qglCompileShader = wrapglCompileShader;
qglCompressedTexImage2DARB = wrapglCompressedTexImage2D;
qglCompressedTexImage3DARB = wrapglCompressedTexImage3D;
qglDepthRangef = wrapglDepthRangef;
qglDetachShader = wrapglDetachShader;
qglDisable = wrapglDisable;
- qglDisableClientState = wrapglDisableClientState;
qglDisableVertexAttribArray = wrapglDisableVertexAttribArray;
qglDrawArrays = wrapglDrawArrays;
// qglDrawBuffer = wrapglDrawBuffer;
qglDrawElements = wrapglDrawElements;
// qglDrawRangeElements = wrapglDrawRangeElements;
qglEnable = wrapglEnable;
- qglEnableClientState = wrapglEnableClientState;
qglEnableVertexAttribArray = wrapglEnableVertexAttribArray;
-// qglEnd = wrapglEnd;
// qglEndQueryARB = wrapglEndQuery;
qglFinish = wrapglFinish;
qglFlush = wrapglFlush;
qglGetUniformfv = wrapglGetUniformfv;
qglGetUniformiv = wrapglGetUniformiv;
qglHint = wrapglHint;
- qglLineWidth = wrapglLineWidth;
qglLinkProgram = wrapglLinkProgram;
- qglLoadIdentity = wrapglLoadIdentity;
- qglLoadMatrixf = wrapglLoadMatrixf;
- qglMatrixMode = wrapglMatrixMode;
- qglMultiTexCoord1f = wrapglMultiTexCoord1f;
- qglMultiTexCoord2f = wrapglMultiTexCoord2f;
- qglMultiTexCoord3f = wrapglMultiTexCoord3f;
- qglMultiTexCoord4f = wrapglMultiTexCoord4f;
- qglNormalPointer = wrapglNormalPointer;
qglPixelStorei = wrapglPixelStorei;
qglPointSize = wrapglPointSize;
// qglPolygonMode = wrapglPolygonMode;
qglStencilMask = wrapglStencilMask;
qglStencilOp = wrapglStencilOp;
qglStencilOpSeparate = wrapglStencilOpSeparate;
- qglTexCoord1f = wrapglTexCoord1f;
- qglTexCoord2f = wrapglTexCoord2f;
- qglTexCoord3f = wrapglTexCoord3f;
- qglTexCoord4f = wrapglTexCoord4f;
- qglTexCoordPointer = wrapglTexCoordPointer;
- qglTexEnvf = wrapglTexEnvf;
- qglTexEnvfv = wrapglTexEnvfv;
- qglTexEnvi = wrapglTexEnvi;
qglTexImage2D = wrapglTexImage2D;
qglTexImage3D = wrapglTexImage3D;
qglTexParameterf = wrapglTexParameterf;
}
#endif
- vid_softsurface = NULL;
- vid.softpixels = NULL;
-
#if SDL_MAJOR_VERSION == 1
// init keyboard
SDL_EnableUNICODE( SDL_ENABLE );
extern cvar_t gl_info_platform;
extern cvar_t gl_info_driver;
-static qboolean VID_InitModeSoft(viddef_mode_t *mode)
-{
-#if SDL_MAJOR_VERSION == 1
- int flags = SDL_HWSURFACE;
- if(!COM_CheckParm("-noasyncblit")) flags |= SDL_ASYNCBLIT;
-#else
- int windowflags = SDL_WINDOW_SHOWN;
-#endif
-
- win_half_width = mode->width>>1;
- win_half_height = mode->height>>1;
-
- if(vid_resizable.integer)
-#if SDL_MAJOR_VERSION == 1
- flags |= SDL_RESIZABLE;
-#else
- windowflags |= SDL_WINDOW_RESIZABLE;
-#endif
-
- VID_OutputVersion();
-
- vid_isfullscreen = false;
- if (mode->fullscreen) {
-#if SDL_MAJOR_VERSION == 1
- const SDL_VideoInfo *vi = SDL_GetVideoInfo();
- mode->width = vi->current_w;
- mode->height = vi->current_h;
- mode->bitsperpixel = vi->vfmt->BitsPerPixel;
- flags |= SDL_FULLSCREEN;
-#else
- if (vid_desktopfullscreen.integer)
- windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
- else
- windowflags |= SDL_WINDOW_FULLSCREEN;
-#endif
- vid_isfullscreen = true;
- }
-
- video_bpp = mode->bitsperpixel;
-#if SDL_MAJOR_VERSION == 1
- video_flags = flags;
- video_screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
- if (video_screen == NULL)
- {
- Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
- VID_Shutdown();
- return false;
- }
- mode->width = video_screen->w;
- mode->height = video_screen->h;
-#else
- window_flags = windowflags;
- window = SDL_CreateWindow(gamename, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mode->width, mode->height, windowflags);
- if (window == NULL)
- {
- Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
- VID_Shutdown();
- return false;
- }
- SDL_GetWindowSize(window, &mode->width, &mode->height);
-#endif
-
- // create a framebuffer using our specific color format, we let the SDL blit function convert it in VID_Finish
- vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, mode->width, mode->height, 32, 0x00FF0000, 0x0000FF00, 0x00000000FF, 0xFF000000);
- if (vid_softsurface == NULL)
- {
- Con_Printf("Failed to setup software rasterizer framebuffer %ix%ix32bpp: %s\n", mode->width, mode->height, SDL_GetError());
- VID_Shutdown();
- return false;
- }
-#if SDL_MAJOR_VERSION == 1
- SDL_SetAlpha(vid_softsurface, 0, 255);
-#else
- SDL_SetSurfaceBlendMode(vid_softsurface, SDL_BLENDMODE_NONE);
-#endif
-
- vid.softpixels = (unsigned int *)vid_softsurface->pixels;
- vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4);
- if (DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, vid_soft_interlace.integer, (unsigned int *)vid_softsurface->pixels, (unsigned int *)vid.softdepthpixels) < 0)
- {
- Con_Printf("Failed to initialize software rasterizer\n");
- VID_Shutdown();
- return false;
- }
-
-#if SDL_MAJOR_VERSION == 1
- // init keyboard
- SDL_EnableUNICODE( SDL_ENABLE );
- // enable key repeat since everyone expects it
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-#endif
-
- VID_Soft_SharedSetup();
-
- vid_hidden = false;
- vid_activewindow = false;
- vid_hasfocus = true;
- vid_usingmouse = false;
- vid_usinghidecursor = false;
-
-#if SDL_MAJOR_VERSION == 1
- SDL_WM_GrabInput(SDL_GRAB_OFF);
-#endif
- return true;
-}
-
qboolean VID_InitMode(viddef_mode_t *mode)
{
// GAME_STEELSTORM specific
#if SDL_MAJOR_VERSION != 1
Cvar_SetValueQuick(&vid_touchscreen_supportshowkeyboard, SDL_HasScreenKeyboardSupport() ? 1 : 0);
#endif
-#ifdef SSE_POSSIBLE
- if (vid_soft.integer)
- return VID_InitModeSoft(mode);
- else
-#endif
- return VID_InitModeGL(mode);
+ return VID_InitModeGL(mode);
}
void VID_Shutdown (void)
#endif
#endif
- if (vid_softsurface)
- SDL_FreeSurface(vid_softsurface);
- vid_softsurface = NULL;
- vid.softpixels = NULL;
- if (vid.softdepthpixels)
- free(vid.softdepthpixels);
- vid.softdepthpixels = NULL;
-
#if SDL_MAJOR_VERSION != 1
SDL_DestroyWindow(window);
window = NULL;
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
CHECKGLERROR
if (r_speeds.integer == 2 || gl_finish.integer)
SDL_GL_SwapWindow(window);
#endif
break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Finish();
-#if SDL_MAJOR_VERSION == 1
-// if (!r_test.integer)
- {
- SDL_BlitSurface(vid_softsurface, NULL, video_screen, NULL);
- SDL_Flip(video_screen);
- }
-#else
- {
- SDL_Surface *screen = SDL_GetWindowSurface(window);
- SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
- SDL_UpdateWindowSurface(window);
- }
-#endif
- break;
- case RENDERPATH_D3D9:
- case RENDERPATH_D3D10:
- case RENDERPATH_D3D11:
- if (r_speeds.integer == 2 || gl_finish.integer)
- GL_Finish();
- break;
}
}
}
#endif
#include "image.h"
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-#ifdef _MSC_VER
-#pragma comment(lib, "d3d9.lib")
-#endif
-
-LPDIRECT3DDEVICE9 vid_d3d9dev;
-#endif
-
#ifdef WIN32
//#include <XInput.h>
#define XINPUT_GAMEPAD_DPAD_UP 0x0001
cvar_t joy_x360_sensitivityyaw = {0, "joy_x360_sensitivityyaw", "-1", "movement multiplier"};
cvar_t joy_x360_sensitivityroll = {0, "joy_x360_sensitivityroll", "1", "movement multiplier"};
-// cvars for DPSOFTRAST
-cvar_t vid_soft = {CVAR_SAVE, "vid_soft", "0", "enables use of the DarkPlaces Software Rasterizer rather than OpenGL or Direct3D"};
-cvar_t vid_soft_threads = {CVAR_SAVE, "vid_soft_threads", "8", "the number of threads the DarkPlaces Software Rasterizer should use"};
-cvar_t vid_soft_interlace = {CVAR_SAVE, "vid_soft_interlace", "1", "whether the DarkPlaces Software Rasterizer should interlace the screen bands occupied by each thread"};
-
// VorteX: more info cvars, mostly set in VID_CheckExtensions
cvar_t gl_info_vendor = {CVAR_READONLY, "gl_info_vendor", "", "indicates brand of graphics chip"};
cvar_t gl_info_renderer = {CVAR_READONLY, "gl_info_renderer", "", "indicates graphics chip model and other information"};
cvar_t vid_grabkeyboard = {CVAR_SAVE, "vid_grabkeyboard", "0", "whether to grab the keyboard when mouse is active (prevents use of volume control keys, music player keys, etc on some keyboards)"};
cvar_t vid_minwidth = {0, "vid_minwidth", "0", "minimum vid_width that is acceptable (to be set in default.cfg in mods)"};
cvar_t vid_minheight = {0, "vid_minheight", "0", "minimum vid_height that is acceptable (to be set in default.cfg in mods)"};
-cvar_t vid_gl13 = {0, "vid_gl13", "1", "enables faster rendering using OpenGL 1.3 features (such as GL_ARB_texture_env_combine extension)"};
-cvar_t vid_gl20 = {0, "vid_gl20", "1", "enables faster rendering using OpenGL 2.0 features (such as GL_ARB_fragment_shader extension)"};
cvar_t gl_finish = {0, "gl_finish", "0", "make the cpu wait for the graphics processor at the end of each rendered frame (can help with strange input or video lag problems on some machines)"};
cvar_t vid_sRGB = {CVAR_SAVE, "vid_sRGB", "0", "if hardware is capable, modify rendering to be gamma corrected for the sRGB color standard (computer monitors, TVs), recommended"};
cvar_t vid_sRGB_fallback = {CVAR_SAVE, "vid_sRGB_fallback", "0", "do an approximate sRGB fallback if not properly supported by hardware (2: also use the fallback if framebuffer is 8bit, 3: always use the fallback even if sRGB is supported)"};
#ifndef USE_GLES2
// GL_ARB_multitexture
-void (GLAPIENTRY *qglMultiTexCoord1f) (GLenum, GLfloat);
-void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
-void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
-void (GLAPIENTRY *qglMultiTexCoord4f) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
void (GLAPIENTRY *qglActiveTexture) (GLenum);
-void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
// general GL functions
void (GLAPIENTRY *qglClear)(GLbitfield mask);
-void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
void (GLAPIENTRY *qglCullFace)(GLenum mode);
void (GLAPIENTRY *qglDisable)(GLenum cap);
GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
-void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
-void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
-
void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
void (GLAPIENTRY *qglDrawArrays)(GLenum mode, GLint first, GLsizei count);
-void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
-void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
-void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
-void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
-void (GLAPIENTRY *qglArrayElement)(GLint i);
-
-void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-void (GLAPIENTRY *qglTexCoord1f)(GLfloat s);
-void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
-void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
-void (GLAPIENTRY *qglTexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
-void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
-void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
-void (GLAPIENTRY *qglVertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-void (GLAPIENTRY *qglBegin)(GLenum mode);
-void (GLAPIENTRY *qglEnd)(void);
-
-void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
-//void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
-//void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
+
void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
-//void (GLAPIENTRY *qglPushMatrix)(void);
-//void (GLAPIENTRY *qglPopMatrix)(void);
-void (GLAPIENTRY *qglLoadIdentity)(void);
-//void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
-void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
-//void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
-//void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
-//void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
-//void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-//void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
-//void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
-//void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
-//void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
void (GLAPIENTRY *qglClearStencil)(GLint s);
-void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
-void (GLAPIENTRY *qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
-void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
//void (GLAPIENTRY *qglGetClipPlane)(GLenum plane, GLdouble *equation);
//[515]: added on 29.07.2005
-void (GLAPIENTRY *qglLineWidth)(GLfloat width);
void (GLAPIENTRY *qglPointSize)(GLfloat size);
void (GLAPIENTRY *qglBlendEquationEXT)(GLenum);
{
{"glClearColor", (void **) &qglClearColor},
{"glClear", (void **) &qglClear},
- {"glAlphaFunc", (void **) &qglAlphaFunc},
{"glBlendFunc", (void **) &qglBlendFunc},
{"glCullFace", (void **) &qglCullFace},
{"glDrawBuffer", (void **) &qglDrawBuffer},
{"glEnable", (void **) &qglEnable},
{"glDisable", (void **) &qglDisable},
{"glIsEnabled", (void **) &qglIsEnabled},
- {"glEnableClientState", (void **) &qglEnableClientState},
- {"glDisableClientState", (void **) &qglDisableClientState},
{"glGetBooleanv", (void **) &qglGetBooleanv},
{"glGetDoublev", (void **) &qglGetDoublev},
{"glGetFloatv", (void **) &qglGetFloatv},
{"glDrawElements", (void **) &qglDrawElements},
{"glDrawArrays", (void **) &qglDrawArrays},
{"glColorMask", (void **) &qglColorMask},
- {"glVertexPointer", (void **) &qglVertexPointer},
- {"glNormalPointer", (void **) &qglNormalPointer},
- {"glColorPointer", (void **) &qglColorPointer},
- {"glTexCoordPointer", (void **) &qglTexCoordPointer},
- {"glArrayElement", (void **) &qglArrayElement},
- {"glColor4ub", (void **) &qglColor4ub},
- {"glColor4f", (void **) &qglColor4f},
- {"glTexCoord1f", (void **) &qglTexCoord1f},
- {"glTexCoord2f", (void **) &qglTexCoord2f},
- {"glTexCoord3f", (void **) &qglTexCoord3f},
- {"glTexCoord4f", (void **) &qglTexCoord4f},
- {"glVertex2f", (void **) &qglVertex2f},
- {"glVertex3f", (void **) &qglVertex3f},
- {"glVertex4f", (void **) &qglVertex4f},
- {"glBegin", (void **) &qglBegin},
- {"glEnd", (void **) &qglEnd},
//[515]: added on 29.07.2005
- {"glLineWidth", (void**) &qglLineWidth},
{"glPointSize", (void**) &qglPointSize},
-//
- {"glMatrixMode", (void **) &qglMatrixMode},
-// {"glOrtho", (void **) &qglOrtho},
-// {"glFrustum", (void **) &qglFrustum},
{"glViewport", (void **) &qglViewport},
-// {"glPushMatrix", (void **) &qglPushMatrix},
-// {"glPopMatrix", (void **) &qglPopMatrix},
- {"glLoadIdentity", (void **) &qglLoadIdentity},
-// {"glLoadMatrixd", (void **) &qglLoadMatrixd},
- {"glLoadMatrixf", (void **) &qglLoadMatrixf},
-// {"glMultMatrixd", (void **) &qglMultMatrixd},
-// {"glMultMatrixf", (void **) &qglMultMatrixf},
-// {"glRotated", (void **) &qglRotated},
-// {"glRotatef", (void **) &qglRotatef},
-// {"glScaled", (void **) &qglScaled},
-// {"glScalef", (void **) &qglScalef},
-// {"glTranslated", (void **) &qglTranslated},
-// {"glTranslatef", (void **) &qglTranslatef},
{"glReadPixels", (void **) &qglReadPixels},
{"glStencilFunc", (void **) &qglStencilFunc},
{"glStencilMask", (void **) &qglStencilMask},
{"glStencilOp", (void **) &qglStencilOp},
{"glClearStencil", (void **) &qglClearStencil},
- {"glTexEnvf", (void **) &qglTexEnvf},
- {"glTexEnvfv", (void **) &qglTexEnvfv},
- {"glTexEnvi", (void **) &qglTexEnvi},
{"glTexParameterf", (void **) &qglTexParameterf},
{"glTexParameterfv", (void **) &qglTexParameterfv},
{"glTexParameteri", (void **) &qglTexParameteri},
static dllfunction_t multitexturefuncs[] =
{
- {"glMultiTexCoord1fARB", (void **) &qglMultiTexCoord1f},
- {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
- {"glMultiTexCoord3fARB", (void **) &qglMultiTexCoord3f},
- {"glMultiTexCoord4fARB", (void **) &qglMultiTexCoord4f},
{"glActiveTextureARB", (void **) &qglActiveTexture},
- {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
{NULL, NULL}
};
// clear the extension flags
memset(&vid.support, 0, sizeof(vid.support));
- vid.renderpath = RENDERPATH_GL11;
+ vid.renderpath = RENDERPATH_GL20;
vid.sRGBcapable2D = false;
vid.sRGBcapable3D = false;
vid.useinterleavedarrays = false;
qglDrawRangeElements = qglDrawRangeElementsEXT;
qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
- if (vid.support.ext_texture_filter_anisotropic)
- qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
- if (vid.support.arb_texture_cube_map)
- qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_cubemap);
- if (vid.support.ext_texture_3d)
- qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
+ qglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&vid.max_anisotropy);
+ qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_cubemap);
+ qglGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_3d);
// verify that 3d textures are really supported
if (vid.support.ext_texture_3d && vid.maxtexturesize_3d < 32)
}
vid.texunits = vid.teximageunits = vid.texarrayunits = 1;
- if (vid.support.arb_multitexture)
- qglGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&vid.texunits);
- if (vid_gl20.integer && vid.support.gl20shaders && vid.support.ext_framebuffer_object && vid.support.arb_texture_non_power_of_two)
+ qglGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&vid.texunits);
+ if (vid.support.gl20shaders && vid.support.ext_framebuffer_object && vid.support.arb_texture_non_power_of_two)
{
qglGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&vid.texunits);
qglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (int *)&vid.teximageunits);CHECKGLERROR
Con_Printf("vid.support.gl20shaders %i\n", vid.support.gl20shaders);
vid.allowalphatocoverage = true; // but see below, it may get turned to false again if GL_SAMPLES_ARB is <= 1
}
- else if (vid.support.arb_texture_env_combine && vid.texunits >= 2 && vid_gl13.integer)
- {
- qglGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&vid.texunits);
- vid.texunits = bound(1, vid.texunits, MAX_TEXTUREUNITS);
- vid.teximageunits = vid.texunits;
- vid.texarrayunits = vid.texunits;
- Con_DPrintf("Using GL1.3 rendering path - %i texture units, single pass rendering\n", vid.texunits);
- vid.renderpath = RENDERPATH_GL13;
- vid.sRGBcapable2D = false;
- vid.sRGBcapable3D = false;
- vid.useinterleavedarrays = false;
- }
else
- {
- vid.texunits = bound(1, vid.texunits, MAX_TEXTUREUNITS);
- vid.teximageunits = vid.texunits;
- vid.texarrayunits = vid.texunits;
- Con_DPrintf("Using GL1.1 rendering path - %i texture units, two pass rendering\n", vid.texunits);
- vid.renderpath = RENDERPATH_GL11;
- vid.sRGBcapable2D = false;
- vid.sRGBcapable3D = false;
- vid.useinterleavedarrays = false;
- }
+ Sys_Error("OpenGL 2.0 and GL_EXT_framebuffer_object required");
// enable multisample antialiasing if possible
if(vid.support.arb_multisample)
void VID_Shared_Init(void)
{
-#ifdef SSE_POSSIBLE
- if (Sys_HaveSSE2())
- {
- Con_Printf("DPSOFTRAST available (SSE2 instructions detected)\n");
- Cvar_RegisterVariable(&vid_soft);
- Cvar_RegisterVariable(&vid_soft_threads);
- Cvar_RegisterVariable(&vid_soft_interlace);
- }
- else
- Con_Printf("DPSOFTRAST not available (SSE2 disabled or not detected)\n");
-#else
- Con_Printf("DPSOFTRAST not available (SSE2 not compiled in)\n");
-#endif
-
Cvar_RegisterVariable(&gl_info_vendor);
Cvar_RegisterVariable(&gl_info_renderer);
Cvar_RegisterVariable(&gl_info_version);
Cvar_RegisterVariable(&vid_desktopfullscreen);
Cvar_RegisterVariable(&vid_minwidth);
Cvar_RegisterVariable(&vid_minheight);
- Cvar_RegisterVariable(&vid_gl13);
- Cvar_RegisterVariable(&vid_gl20);
Cvar_RegisterVariable(&gl_finish);
Cvar_RegisterVariable(&vid_sRGB);
Cvar_RegisterVariable(&vid_sRGB_fallback);
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
#ifdef GL_STEREO
{
}
#endif
break;
+ case RENDERPATH_GLES2:
default:
vid.stereobuffer = false;
break;
}
return count;
}
-
-void VID_Soft_SharedSetup(void)
-{
- gl_platform = "DPSOFTRAST";
- gl_platformextensions = "";
-
- gl_renderer = "DarkPlaces-Soft";
- gl_vendor = "Forest Hale";
- gl_version = "0.0";
- gl_extensions = "";
-
- // clear the extension flags
- memset(&vid.support, 0, sizeof(vid.support));
- Cvar_SetQuick(&gl_info_extensions, "");
-
- // DPSOFTRAST requires BGRA
- vid.forcetextype = TEXTYPE_BGRA;
-
- vid.forcevbo = false;
- vid.support.arb_depth_texture = true;
- vid.support.arb_draw_buffers = true;
- vid.support.arb_occlusion_query = true;
- vid.support.arb_query_buffer_object = false;
- vid.support.arb_shadow = true;
- //vid.support.arb_texture_compression = true;
- vid.support.arb_texture_cube_map = true;
- vid.support.arb_texture_non_power_of_two = false;
- vid.support.arb_vertex_buffer_object = true;
- vid.support.ext_blend_subtract = true;
- vid.support.ext_draw_range_elements = true;
- vid.support.ext_framebuffer_object = true;
-
- vid.support.ext_texture_3d = true;
- //vid.support.ext_texture_compression_s3tc = true;
- vid.support.ext_texture_filter_anisotropic = true;
- vid.support.ati_separate_stencil = true;
- vid.support.ext_texture_srgb = false;
-
- vid.maxtexturesize_2d = 16384;
- vid.maxtexturesize_3d = 512;
- vid.maxtexturesize_cubemap = 16384;
- vid.texunits = 4;
- vid.teximageunits = 32;
- vid.texarrayunits = 8;
- vid.max_anisotropy = 1;
- vid.maxdrawbuffers = 4;
-
- vid.texunits = bound(4, vid.texunits, MAX_TEXTUREUNITS);
- vid.teximageunits = bound(16, vid.teximageunits, MAX_TEXTUREUNITS);
- vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
- Con_DPrintf("Using DarkPlaces Software Rasterizer rendering path\n");
- vid.renderpath = RENDERPATH_SOFT;
- vid.sRGBcapable2D = false;
- vid.sRGBcapable3D = false;
- vid.useinterleavedarrays = false;
-
- Cvar_SetQuick(&gl_info_vendor, gl_vendor);
- Cvar_SetQuick(&gl_info_renderer, gl_renderer);
- Cvar_SetQuick(&gl_info_version, gl_version);
- Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
- Cvar_SetQuick(&gl_info_driver, gl_driver);
-
- // LordHavoc: report supported extensions
-#ifdef CONFIG_MENU
- Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
-#else
- Con_DPrintf("\nQuakeC extensions for server and client: %s\n", vm_sv_extensions );
-#endif
-
- // clear to black (loading plaque will be seen over this)
- GL_Clear(GL_COLOR_BUFFER_BIT, NULL, 1.0f, 128);
-}
#ifdef SUPPORTDIRECTX
#include <dinput.h>
#endif
-#include "dpsoftrast.h"
-
-#ifdef SUPPORTD3D
-#include <d3d9.h>
-
-cvar_t vid_dx9 = {CVAR_SAVE, "vid_dx9", "0", "use Microsoft Direct3D9(r) for rendering"};
-cvar_t vid_dx9_hal = {CVAR_SAVE, "vid_dx9_hal", "1", "enables hardware rendering (1), otherwise software reference rasterizer (0 - very slow), note that 0 is necessary when using NVPerfHUD (which renders in hardware but requires this option to enable it)"};
-cvar_t vid_dx9_softvertex = {CVAR_SAVE, "vid_dx9_softvertex", "0", "enables software vertex processing (for compatibility testing? or if you have a very fast CPU), usually you want this off"};
-cvar_t vid_dx9_triplebuffer = {CVAR_SAVE, "vid_dx9_triplebuffer", "0", "enables triple buffering when using vid_vsync in fullscreen, this options adds some latency and only helps when framerate is below 60 so you usually don't want it"};
-//cvar_t vid_dx10 = {CVAR_SAVE, "vid_dx10", "1", "use Microsoft Direct3D10(r) for rendering"};
-//cvar_t vid_dx11 = {CVAR_SAVE, "vid_dx11", "1", "use Microsoft Direct3D11(r) for rendering"};
-
-D3DPRESENT_PARAMETERS vid_d3dpresentparameters;
-
-// we declare this in vid_shared.c because it is required by dedicated server and all clients when SUPPORTD3D is defined
-extern LPDIRECT3DDEVICE9 vid_d3d9dev;
-
-LPDIRECT3D9 vid_d3d9;
-D3DCAPS9 vid_d3d9caps;
-qboolean vid_d3ddevicelost;
-#endif
extern HINSTANCE global_hInstance;
static HDC baseDC;
static HGLRC baseRC;
-static HDC vid_softhdc;
-static HGDIOBJ vid_softhdc_backup;
-static BITMAPINFO vid_softbmi;
-static HBITMAP vid_softdibhandle;
-
//HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
static qboolean vid_isfullscreen;
//====================================
qboolean vid_reallyhidden = true;
-#ifdef SUPPORTD3D
-qboolean vid_begunscene = false;
-#endif
void VID_Finish (void)
{
-#ifdef SUPPORTD3D
- HRESULT hr;
-#endif
vid_hidden = vid_reallyhidden;
vid_usevsync = vid_vsync.integer && !cls.timedemo && qwglSwapIntervalEXT;
{
switch(vid.renderpath)
{
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
case RENDERPATH_GL20:
- case RENDERPATH_GLES1:
case RENDERPATH_GLES2:
if (vid_usingvsync != vid_usevsync)
{
GL_Finish();
SwapBuffers(baseDC);
break;
- case RENDERPATH_D3D9:
-#ifdef SUPPORTD3D
- if (vid_begunscene)
- {
- IDirect3DDevice9_EndScene(vid_d3d9dev);
- vid_begunscene = false;
- }
- if (!vid_reallyhidden)
- {
- if (!vid_d3ddevicelost)
- {
- vid_hidden = vid_reallyhidden;
- hr = IDirect3DDevice9_Present(vid_d3d9dev, NULL, NULL, NULL, NULL);
- if (hr == D3DERR_DEVICELOST)
- {
- vid_d3ddevicelost = true;
- vid_hidden = true;
- Sleep(100);
- }
- }
- else
- {
- hr = IDirect3DDevice9_TestCooperativeLevel(vid_d3d9dev);
- switch(hr)
- {
- case D3DERR_DEVICELOST:
- vid_d3ddevicelost = true;
- vid_hidden = true;
- Sleep(100);
- break;
- case D3DERR_DEVICENOTRESET:
- vid_d3ddevicelost = false;
- vid_hidden = vid_reallyhidden;
- R_Modules_DeviceLost();
- IDirect3DDevice9_Reset(vid_d3d9dev, &vid_d3dpresentparameters);
- R_Modules_DeviceRestored();
- break;
- case D3D_OK:
- vid_hidden = vid_reallyhidden;
- IDirect3DDevice9_Present(vid_d3d9dev, NULL, NULL, NULL, NULL);
- break;
- }
- }
- if (!vid_begunscene && !vid_hidden)
- {
- IDirect3DDevice9_BeginScene(vid_d3d9dev);
- vid_begunscene = true;
- }
- }
-#endif
- break;
- case RENDERPATH_D3D10:
- break;
- case RENDERPATH_D3D11:
- break;
- case RENDERPATH_SOFT:
- DPSOFTRAST_Finish();
-// baseDC = GetDC(mainwindow);
- BitBlt(baseDC, 0, 0, vid.width, vid.height, vid_softhdc, 0, 0, SRCCOPY);
-// ReleaseDC(mainwindow, baseDC);
-// baseDC = NULL;
- break;
}
}
{
WNDCLASS wc;
-#ifdef SUPPORTD3D
- Cvar_RegisterVariable(&vid_dx9);
- Cvar_RegisterVariable(&vid_dx9_hal);
- Cvar_RegisterVariable(&vid_dx9_softvertex);
- Cvar_RegisterVariable(&vid_dx9_triplebuffer);
-// Cvar_RegisterVariable(&vid_dx10);
-// Cvar_RegisterVariable(&vid_dx11);
-#endif
-
InitCommonControls();
hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON1));
rect->bottom += CenterY;
}
-#ifdef SUPPORTD3D
-static D3DADAPTER_IDENTIFIER9 d3d9adapteridentifier;
-
-extern cvar_t gl_info_extensions;
-extern cvar_t gl_info_vendor;
-extern cvar_t gl_info_renderer;
-extern cvar_t gl_info_version;
-extern cvar_t gl_info_platform;
-extern cvar_t gl_info_driver;
-qboolean VID_InitModeDX(viddef_mode_t *mode, int version)
-{
- int deviceindex;
- RECT rect;
- MSG msg;
- DWORD WindowStyle, ExWindowStyle;
- int bpp = mode->bitsperpixel;
- int width = mode->width;
- int height = mode->height;
- int refreshrate = (int)floor(mode->refreshrate+0.5);
-// int stereobuffer = mode->stereobuffer;
- int samples = mode->samples;
- int fullscreen = mode->fullscreen;
- int numdevices;
-
- if (vid_initialized)
- Sys_Error("VID_InitMode called when video is already initialised");
-
- vid_isfullscreen = fullscreen != 0;
- if (fullscreen)
- {
- WindowStyle = WS_POPUP;
- ExWindowStyle = WS_EX_TOPMOST;
- }
- else
- {
- WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
- ExWindowStyle = 0;
- }
-
- AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
-
- gl_extensions = "";
- gl_platformextensions = "";
-
- mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
- if (!mainwindow)
- {
- Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), (void *)NULL, (void *)NULL, global_hInstance, (void *)NULL);
- VID_Shutdown();
- return false;
- }
-
- baseDC = GetDC(mainwindow);
-
- vid_d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
- if (!vid_d3d9)
- Sys_Error("VID_InitMode: Direct3DCreate9 failed");
-
- numdevices = IDirect3D9_GetAdapterCount(vid_d3d9);
- vid_d3d9dev = NULL;
- memset(&d3d9adapteridentifier, 0, sizeof(d3d9adapteridentifier));
- for (deviceindex = 0;deviceindex < numdevices && !vid_d3d9dev;deviceindex++)
- {
- memset(&vid_d3dpresentparameters, 0, sizeof(vid_d3dpresentparameters));
-// vid_d3dpresentparameters.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
- vid_d3dpresentparameters.Flags = 0;
- vid_d3dpresentparameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
- vid_d3dpresentparameters.hDeviceWindow = mainwindow;
- vid_d3dpresentparameters.BackBufferWidth = width;
- vid_d3dpresentparameters.BackBufferHeight = height;
- vid_d3dpresentparameters.MultiSampleType = samples > 1 ? (D3DMULTISAMPLE_TYPE)samples : D3DMULTISAMPLE_NONE;
- vid_d3dpresentparameters.BackBufferCount = fullscreen ? (vid_dx9_triplebuffer.integer ? 3 : 2) : 1;
- vid_d3dpresentparameters.FullScreen_RefreshRateInHz = fullscreen ? refreshrate : 0;
- vid_d3dpresentparameters.Windowed = !fullscreen;
- vid_d3dpresentparameters.EnableAutoDepthStencil = true;
- vid_d3dpresentparameters.AutoDepthStencilFormat = bpp > 16 ? D3DFMT_D24S8 : D3DFMT_D16;
- vid_d3dpresentparameters.BackBufferFormat = fullscreen?D3DFMT_X8R8G8B8:D3DFMT_UNKNOWN;
- vid_d3dpresentparameters.PresentationInterval = vid_vsync.integer ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
-
- memset(&d3d9adapteridentifier, 0, sizeof(d3d9adapteridentifier));
- IDirect3D9_GetAdapterIdentifier(vid_d3d9, deviceindex, 0, &d3d9adapteridentifier);
-
- IDirect3D9_CreateDevice(vid_d3d9, deviceindex, vid_dx9_hal.integer ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, mainwindow, vid_dx9_softvertex.integer ? D3DCREATE_SOFTWARE_VERTEXPROCESSING : D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid_d3dpresentparameters, &vid_d3d9dev);
- }
-
- if (!vid_d3d9dev)
- {
- VID_Shutdown();
- return false;
- }
-
- IDirect3DDevice9_GetDeviceCaps(vid_d3d9dev, &vid_d3d9caps);
-
- Con_Printf("Using D3D9 device: %s\n", d3d9adapteridentifier.Description);
- gl_extensions = "";
- gl_platform = "D3D9";
- gl_platformextensions = "";
-
- ShowWindow (mainwindow, SW_SHOWDEFAULT);
- UpdateWindow (mainwindow);
-
- // now we try to make sure we get the focus on the mode switch, because
- // sometimes in some systems we don't. We grab the foreground, then
- // finish setting up, pump all our messages, and sleep for a little while
- // to let messages finish bouncing around the system, then we put
- // ourselves at the top of the z order, then grab the foreground again,
- // Who knows if it helps, but it probably doesn't hurt
- SetForegroundWindow (mainwindow);
-
- while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
-
- Sleep (100);
-
- SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
-
- SetForegroundWindow (mainwindow);
-
- // fix the leftover Alt from any Alt-Tab or the like that switched us away
- ClearAllStates ();
-
- gl_renderer = d3d9adapteridentifier.Description;
- gl_vendor = d3d9adapteridentifier.Driver;
- gl_version = "";
- gl_extensions = "";
-
- Con_Printf("D3D9 adapter info:\n");
- Con_Printf("Description: %s\n", d3d9adapteridentifier.Description);
- Con_Printf("DeviceId: %x\n", (unsigned int)d3d9adapteridentifier.DeviceId);
- Con_Printf("DeviceName: %p\n", d3d9adapteridentifier.DeviceName);
- Con_Printf("Driver: %s\n", d3d9adapteridentifier.Driver);
- Con_Printf("DriverVersion: %08x%08x\n", (unsigned int)d3d9adapteridentifier.DriverVersion.u.HighPart, (unsigned int)d3d9adapteridentifier.DriverVersion.u.LowPart);
- Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
- Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
-
- // clear the extension flags
- memset(&vid.support, 0, sizeof(vid.support));
- Cvar_SetQuick(&gl_info_extensions, "");
-
- // D3D9 requires BGRA
- vid.forcetextype = TEXTYPE_BGRA;
-
- vid.forcevbo = false;
- vid.support.arb_depth_texture = true;
- vid.support.arb_draw_buffers = vid_d3d9caps.NumSimultaneousRTs > 1;
- vid.support.arb_occlusion_query = true; // can't find a cap for this
- vid.support.arb_query_buffer_object = true;
- vid.support.arb_shadow = true;
- vid.support.arb_texture_compression = true;
- vid.support.arb_texture_cube_map = true;
- vid.support.arb_texture_non_power_of_two = (vid_d3d9caps.TextureCaps & D3DPTEXTURECAPS_POW2) == 0;
- vid.support.arb_vertex_buffer_object = true;
- vid.support.ext_blend_subtract = true;
- vid.support.ext_draw_range_elements = true;
- vid.support.ext_framebuffer_object = true;
-
- vid.support.ext_texture_3d = true;
- vid.support.ext_texture_compression_s3tc = true;
- vid.support.ext_texture_filter_anisotropic = true;
- vid.support.ati_separate_stencil = (vid_d3d9caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) != 0;
- vid.support.ext_texture_srgb = false; // FIXME use D3DSAMP_SRGBTEXTURE if CheckDeviceFormat agrees
-
- vid.maxtexturesize_2d = min(vid_d3d9caps.MaxTextureWidth, vid_d3d9caps.MaxTextureHeight);
- vid.maxtexturesize_3d = vid_d3d9caps.MaxVolumeExtent;
- vid.maxtexturesize_cubemap = vid.maxtexturesize_2d;
- vid.texunits = 4;
- vid.teximageunits = vid_d3d9caps.MaxSimultaneousTextures;
- vid.texarrayunits = 8; // can't find a caps field for this?
- vid.max_anisotropy = vid_d3d9caps.MaxAnisotropy;
- vid.maxdrawbuffers = vid_d3d9caps.NumSimultaneousRTs;
-
- vid.texunits = bound(4, vid.texunits, MAX_TEXTUREUNITS);
- vid.teximageunits = bound(16, vid.teximageunits, MAX_TEXTUREUNITS);
- vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
- Con_DPrintf("Using D3D9.0 rendering path - %i texture matrix, %i texture images, %i texcoords, shadowmapping supported%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.maxdrawbuffers > 1 ? ", MRT detected (allows prepass deferred lighting)" : "");
- vid.renderpath = RENDERPATH_D3D9;
- vid.sRGBcapable2D = false;
- vid.sRGBcapable3D = true;
- vid.useinterleavedarrays = true;
-
- Cvar_SetQuick(&gl_info_vendor, gl_vendor);
- Cvar_SetQuick(&gl_info_renderer, gl_renderer);
- Cvar_SetQuick(&gl_info_version, gl_version);
- Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
- Cvar_SetQuick(&gl_info_driver, gl_driver);
-
- // LordHavoc: report supported extensions
- Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
-
- // clear to black (loading plaque will be seen over this)
- IDirect3DDevice9_Clear(vid_d3d9dev, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
- IDirect3DDevice9_BeginScene(vid_d3d9dev);
- IDirect3DDevice9_EndScene(vid_d3d9dev);
- IDirect3DDevice9_Present(vid_d3d9dev, NULL, NULL, NULL, NULL);
- // because the only time we end/begin scene is in VID_Finish, we'd better start a scene now...
- IDirect3DDevice9_BeginScene(vid_d3d9dev);
- vid_begunscene = true;
-
- //vid_menudrawfn = VID_MenuDraw;
- //vid_menukeyfn = VID_MenuKey;
- vid_usingmouse = false;
- vid_usinghidecursor = false;
- vid_usingvsync = false;
- vid_hidden = vid_reallyhidden = false;
- vid_initialized = true;
-
- IN_StartupMouse ();
-
- return true;
-}
-#endif
-
-qboolean VID_InitModeSOFT(viddef_mode_t *mode)
-{
- int i;
- HDC hdc;
- RECT rect;
- MSG msg;
- int pixelformat, newpixelformat;
- DWORD WindowStyle, ExWindowStyle;
- int depth;
- DEVMODE thismode;
- qboolean foundmode, foundgoodmode;
- int bpp = mode->bitsperpixel;
- int width = mode->width;
- int height = mode->height;
- int refreshrate = (int)floor(mode->refreshrate+0.5);
- int fullscreen = mode->fullscreen;
-
- if (vid_initialized)
- Sys_Error("VID_InitMode called when video is already initialised");
-
- memset(&gdevmode, 0, sizeof(gdevmode));
-
- vid_isfullscreen = false;
- if (fullscreen)
- {
- if(vid_forcerefreshrate.integer)
- {
- foundmode = true;
- gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
- gdevmode.dmBitsPerPel = bpp;
- gdevmode.dmPelsWidth = width;
- gdevmode.dmPelsHeight = height;
- gdevmode.dmSize = sizeof (gdevmode);
- if(refreshrate)
- {
- gdevmode.dmFields |= DM_DISPLAYFREQUENCY;
- gdevmode.dmDisplayFrequency = refreshrate;
- }
- }
- else
- {
- if(refreshrate == 0)
- refreshrate = initialdevmode.dmDisplayFrequency; // default vid_refreshrate to the rate of the desktop
-
- foundmode = false;
- foundgoodmode = false;
-
- thismode.dmSize = sizeof(thismode);
- thismode.dmDriverExtra = 0;
- for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i)
- {
- if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY))
- {
- Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
- continue;
- }
- if(developer_extra.integer)
- Con_DPrintf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
- if(thismode.dmBitsPerPel != (DWORD)bpp)
- {
- if(developer_extra.integer)
- Con_DPrintf("wrong bpp\n");
- continue;
- }
- if(thismode.dmPelsWidth != (DWORD)width)
- {
- if(developer_extra.integer)
- Con_DPrintf("wrong width\n");
- continue;
- }
- if(thismode.dmPelsHeight != (DWORD)height)
- {
- if(developer_extra.integer)
- Con_DPrintf("wrong height\n");
- continue;
- }
-
- if(foundgoodmode)
- {
- // if we have a good mode, make sure this mode is better than the previous one, and allowed by the refreshrate
- if(thismode.dmDisplayFrequency > (DWORD)refreshrate)
- {
- if(developer_extra.integer)
- Con_DPrintf("too high refresh rate\n");
- continue;
- }
- else if(thismode.dmDisplayFrequency <= gdevmode.dmDisplayFrequency)
- {
- if(developer_extra.integer)
- Con_DPrintf("doesn't beat previous best match (too low)\n");
- continue;
- }
- }
- else if(foundmode)
- {
- // we do have one, but it isn't good... make sure it has a lower frequency than the previous one
- if(thismode.dmDisplayFrequency >= gdevmode.dmDisplayFrequency)
- {
- if(developer_extra.integer)
- Con_DPrintf("doesn't beat previous best match (too high)\n");
- continue;
- }
- }
- // otherwise, take anything
-
- memcpy(&gdevmode, &thismode, sizeof(gdevmode));
- if(thismode.dmDisplayFrequency <= (DWORD)refreshrate)
- foundgoodmode = true;
- else
- {
- if(developer_extra.integer)
- Con_DPrintf("(out of range)\n");
- }
- foundmode = true;
- if(developer_extra.integer)
- Con_DPrintf("accepted\n");
- }
- }
-
- if (!foundmode)
- {
- VID_Shutdown();
- Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp);
- return false;
- }
- else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
- {
- VID_Shutdown();
- Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
- return false;
- }
-
- vid_isfullscreen = true;
- WindowStyle = WS_POPUP;
- ExWindowStyle = WS_EX_TOPMOST;
- }
- else
- {
- hdc = GetDC (NULL);
- i = GetDeviceCaps(hdc, RASTERCAPS);
- depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
- ReleaseDC (NULL, hdc);
- if (i & RC_PALETTE)
- {
- VID_Shutdown();
- Con_Print("Can't run in non-RGB mode\n");
- return false;
- }
- if (bpp > depth)
- {
- VID_Shutdown();
- Con_Print("A higher desktop depth is required to run this video mode\n");
- return false;
- }
-
- WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
- ExWindowStyle = 0;
- }
-
- AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
-
- pixelformat = 0;
- newpixelformat = 0;
- gl_extensions = "";
- gl_platformextensions = "";
-
- mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
- if (!mainwindow)
- {
- Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), (void *)NULL, (void *)NULL, (void *)global_hInstance, (void *)NULL);
- VID_Shutdown();
- return false;
- }
-
- baseDC = GetDC(mainwindow);
- vid.softpixels = NULL;
- memset(&vid_softbmi, 0, sizeof(vid_softbmi));
- vid_softbmi.bmiHeader.biSize = sizeof(vid_softbmi.bmiHeader);
- vid_softbmi.bmiHeader.biWidth = width;
- vid_softbmi.bmiHeader.biHeight = -height; // negative to make a top-down bitmap
- vid_softbmi.bmiHeader.biPlanes = 1;
- vid_softbmi.bmiHeader.biBitCount = 32;
- vid_softbmi.bmiHeader.biCompression = BI_RGB;
- vid_softbmi.bmiHeader.biSizeImage = width*height*4;
- vid_softbmi.bmiHeader.biClrUsed = 256;
- vid_softbmi.bmiHeader.biClrImportant = 256;
- vid_softdibhandle = CreateDIBSection(baseDC, &vid_softbmi, DIB_RGB_COLORS, (void **)&vid.softpixels, NULL, 0);
- if (!vid_softdibhandle)
- {
- Con_Printf("CreateDIBSection failed\n");
- VID_Shutdown();
- return false;
- }
-
- vid_softhdc = CreateCompatibleDC(baseDC);
- vid_softhdc_backup = SelectObject(vid_softhdc, vid_softdibhandle);
- if (!vid_softhdc_backup)
- {
- Con_Printf("SelectObject failed\n");
- VID_Shutdown();
- return false;
- }
-// ReleaseDC(mainwindow, baseDC);
-// baseDC = NULL;
-
- vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4);
- if (DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, vid_soft_interlace.integer, (unsigned int *)vid.softpixels, (unsigned int *)vid.softdepthpixels) < 0)
- {
- Con_Printf("Failed to initialize software rasterizer\n");
- VID_Shutdown();
- return false;
- }
-
- VID_Soft_SharedSetup();
-
- ShowWindow (mainwindow, SW_SHOWDEFAULT);
- UpdateWindow (mainwindow);
-
- // now we try to make sure we get the focus on the mode switch, because
- // sometimes in some systems we don't. We grab the foreground, then
- // finish setting up, pump all our messages, and sleep for a little while
- // to let messages finish bouncing around the system, then we put
- // ourselves at the top of the z order, then grab the foreground again,
- // Who knows if it helps, but it probably doesn't hurt
- SetForegroundWindow (mainwindow);
-
- while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
-
- Sleep (100);
-
- SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
-
- SetForegroundWindow (mainwindow);
-
- // fix the leftover Alt from any Alt-Tab or the like that switched us away
- ClearAllStates ();
-
- //vid_menudrawfn = VID_MenuDraw;
- //vid_menukeyfn = VID_MenuKey;
- vid_usingmouse = false;
- vid_usinghidecursor = false;
- vid_usingvsync = false;
- vid_reallyhidden = vid_hidden = false;
- vid_initialized = true;
-
- IN_StartupMouse ();
-
- return true;
-}
-
qboolean VID_InitMode(viddef_mode_t *mode)
{
-#ifdef SSE_POSSIBLE
- if (vid_soft.integer)
- return VID_InitModeSOFT(mode);
-#endif
-#ifdef SUPPORTD3D
-// if (vid_dx11.integer)
-// return VID_InitModeDX(mode, 11);
-// if (vid_dx10.integer)
-// return VID_InitModeDX(mode, 10);
- if (vid_dx9.integer)
- return VID_InitModeDX(mode, 9);
-#endif
return VID_InitModeGL(mode);
}
gl_extensions = "";
gl_platform = "";
gl_platformextensions = "";
- if (vid_softhdc)
- {
- SelectObject(vid_softhdc, vid_softhdc_backup);
- ReleaseDC(mainwindow, vid_softhdc);
- }
- vid_softhdc = NULL;
- vid_softhdc_backup = NULL;
- if (vid_softdibhandle)
- DeleteObject(vid_softdibhandle);
- vid_softdibhandle = NULL;
- vid.softpixels = NULL;
- if (vid.softdepthpixels)
- free(vid.softdepthpixels);
- vid.softdepthpixels = NULL;
-#ifdef SUPPORTD3D
- if (vid_d3d9dev)
- {
- if (vid_begunscene)
- IDirect3DDevice9_EndScene(vid_d3d9dev);
- vid_begunscene = false;
-// Cmd_ExecuteString("r_texturestats", src_command, true);
-// Cmd_ExecuteString("memlist", src_command, true);
- IDirect3DDevice9_Release(vid_d3d9dev);
- }
- vid_d3d9dev = NULL;
- if (vid_d3d9)
- IDirect3D9_Release(vid_d3d9);
- vid_d3d9 = NULL;
-#endif
if (qwglMakeCurrent)
qwglMakeCurrent(NULL, NULL);
qwglMakeCurrent = NULL;