- VectorCopy(vertex[i], v);
- R_Viewport_TransformToScreen(&r_refdef.view.viewport, v, v2);
- //Con_Printf("%.3f %.3f %.3f %.3f transformed to %.3f %.3f %.3f %.3f\n", v[0], v[1], v[2], v[3], v2[0], v2[1], v2[2], v2[3]);
- if (i)
- {
- if (x1 > v2[0]) x1 = v2[0];
- if (x2 < v2[0]) x2 = v2[0];
- if (y1 > v2[1]) y1 = v2[1];
- if (y2 < v2[1]) y2 = v2[1];
- }
- else
- {
- x1 = x2 = v2[0];
- y1 = y2 = v2[1];
- }
- }
-
- // now convert the scissor rectangle to integer screen coordinates
- ix1 = (int)(x1 - 1.0f);
- iy1 = vid.height - (int)(y2 - 1.0f);
- ix2 = (int)(x2 + 1.0f);
- iy2 = vid.height - (int)(y1 + 1.0f);
- //Con_Printf("%f %f %f %f\n", x1, y1, x2, y2);
-
- // clamp it to the screen
- if (ix1 < r_refdef.view.viewport.x) ix1 = r_refdef.view.viewport.x;
- if (iy1 < r_refdef.view.viewport.y) iy1 = r_refdef.view.viewport.y;
- if (ix2 > r_refdef.view.viewport.x + r_refdef.view.viewport.width) ix2 = r_refdef.view.viewport.x + r_refdef.view.viewport.width;
- if (iy2 > r_refdef.view.viewport.y + r_refdef.view.viewport.height) iy2 = r_refdef.view.viewport.y + r_refdef.view.viewport.height;
-
- // if it is inside out, it's not visible
- if (ix2 <= ix1 || iy2 <= iy1)
- return true;
-
- // the light area is visible, set up the scissor rectangle
- r_shadow_lightscissor[0] = ix1;
- r_shadow_lightscissor[1] = iy1;
- r_shadow_lightscissor[2] = ix2 - ix1;
- r_shadow_lightscissor[3] = iy2 - iy1;
-
- // 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:
- r_shadow_lightscissor[1] = vid.height - r_shadow_lightscissor[1] - r_shadow_lightscissor[3];
- break;
- case RENDERPATH_GL11:
- case RENDERPATH_GL13:
- case RENDERPATH_GL20:
- case RENDERPATH_CGGL:
- break;