X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=dpsoftrast.c;h=039e7fc5fe6531e47891c9f3daca2d496cf4ffb3;hb=a38c129ff5ec67a0fabc260b59d12922ebb497d8;hp=a79a9d363aee62cc8b45416277d572eca511b601;hpb=cfee52a1ec9db338098789cae89ae5cf1f7a6fbf;p=xonotic%2Fdarkplaces.git diff --git a/dpsoftrast.c b/dpsoftrast.c index a79a9d36..039e7fc5 100644 --- a/dpsoftrast.c +++ b/dpsoftrast.c @@ -617,9 +617,6 @@ int DPSOFTRAST_Texture_New(int flags, int width, int height, int depth) d = depth; size = 0; mipmaps = 0; - w = width; - h = height; - d = depth; for (;;) { s = w * h * d * sides * 4; @@ -748,12 +745,12 @@ void DPSOFTRAST_Texture_UpdatePartial(int index, int mip, const unsigned char *p DPSOFTRAST_Flush(); if (pixels) { - dst = texture->bytes + (blocky * texture->mipmap[0][2] + blockx) * 4; + 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; - dst += texture->mipmap[0][2] * 4; blockheight--; } } @@ -766,7 +763,16 @@ void DPSOFTRAST_Texture_UpdateFull(int index, const unsigned char *pixels) if (texture->binds) DPSOFTRAST_Flush(); if (pixels) - memcpy(texture->bytes, pixels, texture->mipmap[0][1]); + { + 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) @@ -1269,9 +1275,10 @@ void DPSOFTRAST_CopyRectangleToTexture(int index, int mip, int tx, int ty, int s if (th > sh) th = sh; if (tw < 1 || th < 1) return; - sy1 = sheight - 1 - sy1; + 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); + memcpy(tpixels + ((ty1 + y) * twidth + tx1), spixels + ((sy1 + y) * swidth + sx1), tw*4); if (texture->mipmaps > 1) DPSOFTRAST_Texture_CalculateMipmaps(index); } @@ -1304,7 +1311,8 @@ void DPSOFTRAST_SetTexture(int unitnum, int index) command->texture = texture; dpsoftrast.texbound[unitnum] = texture; - ATOMIC_ADD(texture->binds, dpsoftrast.numthreads); + if (texture) + ATOMIC_ADD(texture->binds, dpsoftrast.numthreads); } void DPSOFTRAST_SetVertexPointer(const float *vertex3f, size_t stride) @@ -1717,14 +1725,6 @@ static void DPSOFTRAST_Vertex_Copy(float *out4f, const float *in4f, int numitems out = _mm_shuffle_ps(p, p, _MM_SHUFFLE(0, 3, 2, 1)); \ } -#define DPSOFTRAST_PROJECTY(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); \ @@ -2044,11 +2044,9 @@ static void DPSOFTRAST_Draw_Span_FinishBGRA8(DPSOFTRAST_State_Thread *thread, co int subx; const unsigned int * RESTRICT ini = (const unsigned int *)in4ub; unsigned char * RESTRICT pixelmask = span->pixelmask; - unsigned char * RESTRICT pixel = (unsigned char *)dpsoftrast.fb_colorpixels[0]; unsigned int * RESTRICT pixeli = (unsigned int *)dpsoftrast.fb_colorpixels[0]; - if (!pixel) + if (!pixeli) return; - pixel += (span->y * dpsoftrast.fb_width + span->x) * 4; pixeli += span->y * dpsoftrast.fb_width + span->x; // handle alphatest now (this affects depth writes too) if (thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL) @@ -2293,7 +2291,7 @@ static void DPSOFTRAST_Texture2DBGRA8(DPSOFTRAST_Texture *texture, int mip, floa 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]; + 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] = { x * (width<<12) - 2048, y * (height<<12) - 2048}; @@ -2316,10 +2314,10 @@ static void DPSOFTRAST_Texture2DBGRA8(DPSOFTRAST_Texture *texture, int mip, floa tci1[0] &= wrapmask[0]; tci1[1] &= wrapmask[1]; } - pixel[0] = pixelbase + 4 * (tci[1]*width+tci[0]); - pixel[1] = pixelbase + 4 * (tci[1]*width+tci1[0]); - pixel[2] = pixelbase + 4 * (tci1[1]*width+tci[0]); - pixel[3] = pixelbase + 4 * (tci1[1]*width+tci1[0]); + 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; @@ -2338,7 +2336,7 @@ static void DPSOFTRAST_Texture2DBGRA8(DPSOFTRAST_Texture *texture, int mip, floa tci[0] &= wrapmask[0]; tci[1] &= wrapmask[1]; } - pixel[0] = pixelbase + 4 * (tci[1]*width+tci[0]); + pixel[0] = pixelbase + 4 * (tci[0] - tci[1]*width); c[0] = pixel[0][0]; c[1] = pixel[0][1]; c[2] = pixel[0][2]; @@ -2382,7 +2380,7 @@ static void DPSOFTRAST_Draw_Span_Texture2DVarying(DPSOFTRAST_State_Thread *threa return; } mip = triangle->mip[texunitindex]; - pixelbase = (unsigned char *)texture->bytes + texture->mipmap[mip][0]; + 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) { @@ -2404,7 +2402,7 @@ static void DPSOFTRAST_Draw_Span_Texture2DVarying(DPSOFTRAST_State_Thread *threa flags = texture->flags; tcscale[0] = texture->mipmap[mip][2]; tcscale[1] = texture->mipmap[mip][3]; - tciwidth = texture->mipmap[mip][2]; + tciwidth = -texture->mipmap[mip][2]; tcimin[0] = 0; tcimin[1] = 0; tcimax[0] = texture->mipmap[mip][2]-1; @@ -2569,7 +2567,7 @@ static void DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(DPSOFTRAST_State_Thread * return; } mip = triangle->mip[texunitindex]; - pixelbase = (const unsigned char *)texture->bytes + texture->mipmap[mip][0]; + 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) { @@ -2591,7 +2589,7 @@ static void DPSOFTRAST_Draw_Span_Texture2DVaryingBGRA8(DPSOFTRAST_State_Thread * 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_shuffle_epi32(tcsize, _MM_SHUFFLE(0, 0, 0, 0)), 18), _mm_set1_epi32(4)); + 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;) { @@ -3252,6 +3250,12 @@ static void DPSOFTRAST_PixelShader_Generic(DPSOFTRAST_State_Thread *thread, cons } 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); } @@ -4035,7 +4039,7 @@ void DPSOFTRAST_PixelShader_LightDirection(DPSOFTRAST_State_Thread *thread, cons { for (x = startx;x < endx;x++) { - z = buffer_z[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]; @@ -4145,7 +4149,7 @@ static void DPSOFTRAST_PixelShader_LightSource(DPSOFTRAST_State_Thread *thread, 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 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]; @@ -4165,10 +4169,12 @@ static void DPSOFTRAST_PixelShader_LightSource(DPSOFTRAST_State_Thread *thread, 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]; @@ -4440,7 +4446,7 @@ static void DPSOFTRAST_VertexShader_Refraction(void) 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; + //float z; int x, startx = span->startx, endx = span->endx; // texture reads @@ -4488,7 +4494,7 @@ static void DPSOFTRAST_PixelShader_Refraction(DPSOFTRAST_State_Thread *thread, c float iw; unsigned char c[4]; - z = buffer_z[x]; + //z = buffer_z[x]; // " vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n" iw = 1.0f / (ModelViewProjectionPositiondata[3] + ModelViewProjectionPositionslope[3]*x); // / z @@ -4572,7 +4578,7 @@ static void DPSOFTRAST_VertexShader_Water(void) 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; + // float z; int x, startx = span->startx, endx = span->endx; // texture reads @@ -4641,7 +4647,7 @@ static void DPSOFTRAST_PixelShader_Water(DPSOFTRAST_State_Thread *thread, const unsigned char c2[4]; float Fresnel; - z = buffer_z[x]; + // z = buffer_z[x]; // " vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n" iw = 1.0f / (ModelViewProjectionPositiondata[3] + ModelViewProjectionPositionslope[3]*x); // / z @@ -4687,23 +4693,6 @@ static void DPSOFTRAST_PixelShader_Water(DPSOFTRAST_State_Thread *thread, const -static void DPSOFTRAST_VertexShader_ShowDepth(void) -{ - DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1); -} - -static void DPSOFTRAST_PixelShader_ShowDepth(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_DeferredGeometry(void) { DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1); @@ -4765,7 +4754,6 @@ static const DPSOFTRAST_ShaderModeInfo DPSOFTRAST_ShaderModeTable[SHADERMODE_COU {2, DPSOFTRAST_VertexShader_LightSource, DPSOFTRAST_PixelShader_LightSource, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, ~0}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_CUBE, ~0}}, {2, DPSOFTRAST_VertexShader_Refraction, DPSOFTRAST_PixelShader_Refraction, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, ~0}, {GL20TU_NORMAL, GL20TU_REFRACTION, ~0}}, {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, ~0}, {GL20TU_NORMAL, GL20TU_REFLECTION, GL20TU_REFRACTION, ~0}}, - {2, DPSOFTRAST_VertexShader_ShowDepth, DPSOFTRAST_PixelShader_ShowDepth, {~0}}, {2, DPSOFTRAST_VertexShader_DeferredGeometry, DPSOFTRAST_PixelShader_DeferredGeometry, {~0}}, {2, DPSOFTRAST_VertexShader_DeferredLightSource, DPSOFTRAST_PixelShader_DeferredLightSource, {~0}}, }; @@ -4780,8 +4768,6 @@ static void DPSOFTRAST_Draw_DepthTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAS int depthslope; unsigned int d; unsigned char *pixelmask; - DPSOFTRAST_State_Triangle *triangle; - triangle = &thread->triangles[span->triangle]; depthpixel = dpsoftrast.fb_depthpixels + span->y * dpsoftrast.fb_width + span->x; startx = span->startx; endx = span->endx;