29 #include "../idlib/precompiled.h"
34 #include <vecLib/vecLib.h>
36 #if defined(MACOS_X) && defined(__i386__)
37 #include <xmmintrin.h>
100 if ( rect.
y1 >
y1 ) {
103 if ( rect.
y2 <
y2 ) {
114 if ( rect.
x1 <
x1 ) {
117 if ( rect.
x2 >
x2 ) {
120 if ( rect.
y1 <
y1 ) {
123 if ( rect.
y2 >
y2 ) {
134 return (
x1 == rect.
x1 &&
x2 == rect.
x2 &&
y1 == rect.
y1 &&
y2 == rect.
y2 );
203 for ( block = frame->
memory ; block ; block = block->
next ) {
213 #define MEMORY_BLOCK_SIZE 0x100000
233 for ( block = frame->
memory ; block ; block = nextBlock ) {
234 nextBlock = block->
next;
281 for ( block = frame->
memory ; block ; block=block->
next ) {
282 count += block->
used;
283 if ( block == frame->
alloc ) {
311 if ( !buf && ( bytes != 0 ) ) {
370 bytes = (bytes+16)&~15;
373 block = frame->
alloc;
375 if ( block->
size - block->
used >= bytes ) {
377 block->
used += bytes;
400 if ( bytes > block->
size ) {
405 frame->
alloc = block;
446 modelMatrix[0] = axis[0][0];
447 modelMatrix[4] = axis[1][0];
448 modelMatrix[8] = axis[2][0];
449 modelMatrix[12] = origin[0];
451 modelMatrix[1] = axis[0][1];
452 modelMatrix[5] = axis[1][1];
453 modelMatrix[9] = axis[2][1];
454 modelMatrix[13] = origin[1];
456 modelMatrix[2] = axis[0][2];
457 modelMatrix[6] = axis[1][2];
458 modelMatrix[10] = axis[2][2];
459 modelMatrix[14] = origin[2];
471 #if defined(MACOS_X) && defined(__i386__)
472 __m128 m0, m1, m2, m3;
473 __m128 in0, in1, in2;
479 m0 = _mm_loadu_ps(&modelMatrix[0]);
480 m1 = _mm_loadu_ps(&modelMatrix[4]);
481 m2 = _mm_loadu_ps(&modelMatrix[8]);
482 m3 = _mm_loadu_ps(&modelMatrix[12]);
484 in0 = _mm_load1_ps(&i0);
485 in1 = _mm_load1_ps(&i1);
486 in2 = _mm_load1_ps(&i2);
488 m0 = _mm_mul_ps(m0, in0);
489 m1 = _mm_mul_ps(m1, in1);
490 m2 = _mm_mul_ps(m2, in2);
492 m0 = _mm_add_ps(m0, m1);
493 m0 = _mm_add_ps(m0, m2);
494 m0 = _mm_add_ps(m0, m3);
496 _mm_store_ss(&out[0], m0);
497 m1 = (__m128) _mm_shuffle_epi32((__m128i)m0, 0x55);
498 _mm_store_ss(&out[1], m1);
499 m2 = _mm_movehl_ps(m2, m0);
500 _mm_store_ss(&out[2], m2);
502 out[0] = in[0] * modelMatrix[0] + in[1] * modelMatrix[4]
503 + in[2] * modelMatrix[8] + modelMatrix[12];
504 out[1] = in[0] * modelMatrix[1] + in[1] * modelMatrix[5]
505 + in[2] * modelMatrix[9] + modelMatrix[13];
506 out[2] = in[0] * modelMatrix[2] + in[1] * modelMatrix[6]
507 + in[2] * modelMatrix[10] + modelMatrix[14];
512 out[0] = in[0] * modelMatrix[0] + in[1] * modelMatrix[4]
513 + in[2] * modelMatrix[8] + modelMatrix[12];
514 out[1] = in[0] * modelMatrix[1] + in[1] * modelMatrix[5]
515 + in[2] * modelMatrix[9] + modelMatrix[13];
516 out[2] = in[0] * modelMatrix[2] + in[1] * modelMatrix[6]
517 + in[2] * modelMatrix[10] + modelMatrix[14];
518 out[3] = in[0] * modelMatrix[3] + in[1] * modelMatrix[7]
519 + in[2] * modelMatrix[11] + modelMatrix[15];
533 out[0] = in[0] * modelMatrix[0] + in[1] * modelMatrix[4]
534 + in[2] * modelMatrix[8];
535 out[1] = in[0] * modelMatrix[1] + in[1] * modelMatrix[5]
536 + in[2] * modelMatrix[9];
537 out[2] = in[0] * modelMatrix[2] + in[1] * modelMatrix[6]
538 + in[2] * modelMatrix[10];
551 out[3] = in[3] + modelMatrix[12] * in[0] + modelMatrix[13] * in[1] + modelMatrix[14] * in[2];
559 offset = modelMatrix[12] * out[0] + modelMatrix[13] * out[1] + modelMatrix[14] * out[2];
565 float clip_z, clip_w;
568 clip_z = src_z * projectionMatrix[ 2 + 2 * 4 ] + projectionMatrix[ 2 + 3 * 4 ];
569 clip_w = src_z * projectionMatrix[ 3 + 2 * 4 ] + projectionMatrix[ 3 + 3 * 4 ];
571 if ( clip_w <= 0.0
f ) {
574 dst_z = clip_z / clip_w;
575 dst_z = dst_z * 0.5f + 0.5f;
599 idVec3 localOrigin = ( bounds[0] + bounds[1] ) * 0.5;
603 worldRadius = (bounds[0] - localOrigin).Length();
605 for ( i = 0 ; i < numPlanes ; i++ ) {
608 if ( d > worldRadius ) {
638 for ( i = 0 ; i < 8 ; i++ ) {
639 v[0] = bounds[i&1][0];
640 v[1] = bounds[(i>>1)&1][1];
641 v[2] = bounds[(i>>2)&1][2];
647 for ( i = 0 ; i < numPlanes ; i++ ) {
649 for ( j = 0 ; j < 8 ; j++ ) {
650 dists[
j] = frust->
Distance( transformed[j] );
651 if ( dists[j] < 0 ) {
690 for ( i = 0 ; i < 4 ; i++ ) {
692 src[0] * modelMatrix[ i + 0 * 4 ] +
693 src[1] * modelMatrix[ i + 1 * 4 ] +
694 src[2] * modelMatrix[ i + 2 * 4 ] +
695 1 * modelMatrix[ i + 3 * 4 ];
698 for ( i = 0 ; i < 4 ; i++ ) {
700 eye[0] * projectionMatrix[ i + 0 * 4 ] +
701 eye[1] * projectionMatrix[ i + 1 * 4 ] +
702 eye[2] * projectionMatrix[ i + 2 * 4 ] +
703 eye[3] * projectionMatrix[ i + 3 * 4 ];
722 for ( i = 0 ; i < 4 ; i ++ ) {
730 for ( i = 0 ; i < 4 ; i ++ ) {
740 for ( i = 0 ; i < 4 ; i ++ ) {
749 for ( i = 0 ; i < 4 ; i ++ ) {
759 ndc[0] = clip[0] / clip[3];
760 ndc[1] = clip[1] / clip[3];
761 ndc[2] = ( clip[2] + clip[3] ) / ( 2 * clip[3] );
772 normalized[0] = clip[0] / clip[3];
773 normalized[1] = clip[1] / clip[3];
774 normalized[2] = clip[2] / clip[3];
787 for ( i = 0 ; i < 4 ; i++ ) {
788 for ( j = 0 ; j < 4 ; j++ ) {
790 a [ i * 4 + 0 ] * b [ 0 * 4 +
j ]
791 + a [ i * 4 + 1 ] * b [ 1 * 4 +
j ]
792 + a [ i * 4 + 2 ] * b [ 2 * 4 +
j ]
793 + a [ i * 4 + 3 ] * b [ 3 * 4 +
j ];
797 out[0*4+0] = a[0*4+0]*b[0*4+0] + a[0*4+1]*b[1*4+0] + a[0*4+2]*b[2*4+0] + a[0*4+3]*b[3*4+0];
798 out[0*4+1] = a[0*4+0]*b[0*4+1] + a[0*4+1]*b[1*4+1] + a[0*4+2]*b[2*4+1] + a[0*4+3]*b[3*4+1];
799 out[0*4+2] = a[0*4+0]*b[0*4+2] + a[0*4+1]*b[1*4+2] + a[0*4+2]*b[2*4+2] + a[0*4+3]*b[3*4+2];
800 out[0*4+3] = a[0*4+0]*b[0*4+3] + a[0*4+1]*b[1*4+3] + a[0*4+2]*b[2*4+3] + a[0*4+3]*b[3*4+3];
801 out[1*4+0] = a[1*4+0]*b[0*4+0] + a[1*4+1]*b[1*4+0] + a[1*4+2]*b[2*4+0] + a[1*4+3]*b[3*4+0];
802 out[1*4+1] = a[1*4+0]*b[0*4+1] + a[1*4+1]*b[1*4+1] + a[1*4+2]*b[2*4+1] + a[1*4+3]*b[3*4+1];
803 out[1*4+2] = a[1*4+0]*b[0*4+2] + a[1*4+1]*b[1*4+2] + a[1*4+2]*b[2*4+2] + a[1*4+3]*b[3*4+2];
804 out[1*4+3] = a[1*4+0]*b[0*4+3] + a[1*4+1]*b[1*4+3] + a[1*4+2]*b[2*4+3] + a[1*4+3]*b[3*4+3];
805 out[2*4+0] = a[2*4+0]*b[0*4+0] + a[2*4+1]*b[1*4+0] + a[2*4+2]*b[2*4+0] + a[2*4+3]*b[3*4+0];
806 out[2*4+1] = a[2*4+0]*b[0*4+1] + a[2*4+1]*b[1*4+1] + a[2*4+2]*b[2*4+1] + a[2*4+3]*b[3*4+1];
807 out[2*4+2] = a[2*4+0]*b[0*4+2] + a[2*4+1]*b[1*4+2] + a[2*4+2]*b[2*4+2] + a[2*4+3]*b[3*4+2];
808 out[2*4+3] = a[2*4+0]*b[0*4+3] + a[2*4+1]*b[1*4+3] + a[2*4+2]*b[2*4+3] + a[2*4+3]*b[3*4+3];
809 out[3*4+0] = a[3*4+0]*b[0*4+0] + a[3*4+1]*b[1*4+0] + a[3*4+2]*b[2*4+0] + a[3*4+3]*b[3*4+0];
810 out[3*4+1] = a[3*4+0]*b[0*4+1] + a[3*4+1]*b[1*4+1] + a[3*4+2]*b[2*4+1] + a[3*4+3]*b[3*4+1];
811 out[3*4+2] = a[3*4+0]*b[0*4+2] + a[3*4+1]*b[1*4+2] + a[3*4+2]*b[2*4+2] + a[3*4+3]*b[3*4+2];
812 out[3*4+3] = a[3*4+0]*b[0*4+3] + a[3*4+1]*b[1*4+3] + a[3*4+2]*b[2*4+3] + a[3*4+3]*b[3*4+3];
824 for ( i = 0 ; i < 4 ; i++ ) {
825 for ( j = 0 ; j < 4 ; j++ ) {
826 out[i*4+
j] = in[j*4+
i];
841 float viewerMatrix[16];
842 static float s_flipMatrix[16] = {
853 memset( world, 0,
sizeof(*world) );
866 viewerMatrix[12] = -origin[0] * viewerMatrix[0] + -origin[1] * viewerMatrix[4] + -origin[2] * viewerMatrix[8];
871 viewerMatrix[13] = -origin[0] * viewerMatrix[1] + -origin[1] * viewerMatrix[5] + -origin[2] * viewerMatrix[9];
876 viewerMatrix[14] = -origin[0] * viewerMatrix[2] + -origin[1] * viewerMatrix[6] + -origin[2] * viewerMatrix[10];
880 viewerMatrix[11] = 0;
881 viewerMatrix[15] = 1;
896 float xmin, xmax, ymin, ymax;
899 float jitterx, jittery;
909 jitterx = jittery = 0;
927 height = ymax - ymin;
968 static void R_SetupViewFrustum(
void ) {
988 for ( i = 0; i < 5; i++ ) {
996 float dNear, dFar, dLeft, dUp;
1016 static void R_ConstrainViewFrustum(
void ) {
1022 bounds.
AddBounds( vLight->lightDef->frustumTris->bounds );
1025 bounds.
AddBounds( vEntity->entityDef->referenceBounds );
1049 static int R_QsortSurfaces(
const void *
a,
const void *
b ) {
1070 static void R_SortDrawSurfs(
void ) {
1116 R_SetupViewFrustum();
1127 R_ConstrainViewFrustum();
void R_ClearCommandChain(void)
bool R_RadiusCullLocalBox(const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes)
bool AddBounds(const idBounds &a)
void SetOrigin(const idVec3 &origin)
void * R_ClearedStaticAlloc(int bytes)
void myGlMultMatrix(const float a[16], const float b[16], float out[16])
void * R_StaticAlloc(int bytes)
const idVec3 & Normal(void) const
void R_AddModelSurfaces(void)
GLdouble GLdouble GLdouble GLdouble zNear
float GetFloat(void) const
#define VectorSubtract(a, b, c)
void MoveFarDistance(float dFar)
float Distance(const idVec3 &v) const
void R_GlobalPointToLocal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
bool ConstrainToBounds(const idBounds &bounds)
void SetSize(float dNear, float dFar, float dLeft, float dUp)
void R_SetupProjection(void)
void R_RemoveUnecessaryViewLights(void)
void R_LocalPlaneToGlobal(const float modelMatrix[16], const idPlane &in, idPlane &out)
void Union(const idScreenRect &rect)
int R_CountFrameData(void)
bool R_CornerCullLocalBox(const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes)
void R_TransformModelToClip(const idVec3 &src, const float *modelMatrix, const float *projectionMatrix, idPlane &eye, idPlane &dst)
void R_TransformClipToDevice(const idPlane &clip, const viewDef_t *view, idVec3 &normalized)
void R_GlobalPlaneToLocal(const float modelMatrix[16], const idPlane &in, idPlane &out)
virtual void VPCALL Memset(void *dst, const int val, const int count)=0
idCVar r_lockSurfaces("r_lockSurfaces","0", CVAR_RENDERER|CVAR_BOOL,"allow moving the view point without changing the composition of the scene, including culling")
float projectionMatrix[16]
static void SinCos(float a, float &s, float &c)
struct viewLight_s * next
void R_SetViewMatrix(viewDef_t *viewDef)
struct viewLight_s * viewLights
void R_AddDrawViewCmd(viewDef_t *parms)
GLuint GLuint GLsizei count
void R_TransposeGLMatrix(const float in[16], float out[16])
bool R_GenerateSubViews(void)
void AddPoint(float x, float y)
void R_InitFrameData(void)
void R_PointTimesMatrix(const float modelMatrix[16], const idVec4 &in, idVec4 &out)
void R_FrameFree(void *data)
struct viewEntity_s * next
static int FtoiFast(float f)
#define MEMORY_BLOCK_SIZE
void * R_ClearedFrameAlloc(int bytes)
idCVar r_useDepthBoundsTest("r_useDepthBoundsTest","1", CVAR_RENDERER|CVAR_BOOL,"use depth bounds test to reduce shadow fill")
idCVar r_subviewOnly("r_subviewOnly","0", CVAR_RENDERER|CVAR_BOOL,"1 = don't render main view, allowing subviews to be debugged")
GLsizei GLsizei GLenum GLenum const GLvoid * data
idCVar r_jitter("r_jitter","0", CVAR_RENDERER|CVAR_BOOL,"randomly subpixel jitter the projection matrix")
int GetInteger(void) const
idScreenRect R_ScreenRectFromViewFrustumBounds(const idBounds &bounds)
struct frameMemoryBlock_s * next
void R_LocalVectorToGlobal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
frameMemoryBlock_t * alloc
virtual void virtual void FatalError(const char *fmt,...) id_attribute((format(printf
virtual void DebugScreenRect(const idVec4 &color, const idScreenRect &rect, const viewDef_t *viewDef, const int lifetime=0)
void Intersect(const idScreenRect &rect)
void R_RenderView(viewDef_t *parms)
void R_GlobalVectorToLocal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
void SetAxis(const idMat3 &axis)
GLubyte GLubyte GLubyte a
idCVar r_znear("r_znear","3", CVAR_RENDERER|CVAR_FLOAT,"near Z clip plane distance", 0.001f, 200.0f)
GLenum GLsizei GLsizei height
void R_FreeDeferredTriSurfs(frameData_t *frame)
void R_GlobalToNormalizedDeviceCoordinates(const idVec3 &global, idVec3 &ndc)
idCVar r_useCulling("r_useCulling","2", CVAR_RENDERER|CVAR_INTEGER,"0 = none, 1 = sphere, 2 = sphere + box", 0, 2, idCmdSystem::ArgCompletion_Integer< 0, 2 >)
GLdouble GLdouble GLdouble r
struct viewEntity_s * viewEntitys
frameMemoryBlock_t * memory
void R_AddLightSurfaces(void)
void R_ShowColoredScreenRect(const idScreenRect &rect, int colorIndex)
float modelViewMatrix[16]
void R_AxisToModelMatrix(const idMat3 &axis, const idVec3 &origin, float modelMatrix[16])
void * Mem_ClearedAlloc(const int size)
void R_TransformEyeZToWin(float src_z, const float *projectionMatrix, float &dst_z)
void * R_FrameAlloc(int bytes)
void * Mem_Alloc(const int size)
bool R_CullLocalBox(const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes)
idRenderWorldLocal * renderWorld
void R_LocalPointToGlobal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
void R_ToggleSmpFrame(void)
void R_StaticFree(void *data)
void R_ShutdownFrameData(void)
bool Equals(const idScreenRect &rect) const
GLint GLenum GLboolean normalized
idCVar r_useFrustumFarDistance("r_useFrustumFarDistance","0", CVAR_RENDERER|CVAR_FLOAT,"if != 0 force the view frustum far distance to this distance")
idSIMDProcessor * SIMDProcessor