123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #pragma once
- #define MLR_MLRCLIPPINGSTATE_HPP
- #if !defined(MLR_MLR_HPP)
- #include <MLR\MLR.hpp>
- #endif
- namespace MidLevelRenderer {
- //##########################################################################
- //#################### MLRClippingState ##############################
- //##########################################################################
- class MLRClippingState
- {
- protected:
- int
- clippingState;
- public:
- MLRClippingState()
- { clippingState = 0; };
- MLRClippingState(int i)
- { clippingState = i; };
- MLRClippingState(const MLRClippingState& state)
- { clippingState = state.clippingState;}
- //##########################################################################
- // Attention !!! when changing the flags also change them in
- // Stuff::Vector4D::MultiplySetClip the assembler block
- //
- //##########################################################################
- enum {
- TopClipBit = 0,
- BottomClipBit,
- LeftClipBit,
- RightClipBit,
- NearClipBit,
- FarClipBit,
- NextBit
- };
- enum {
- TopClipFlag = 1<<TopClipBit,
- BottomClipFlag = 1<<BottomClipBit,
- LeftClipFlag = 1<<LeftClipBit,
- RightClipFlag = 1<<RightClipBit,
- NearClipFlag = 1<<NearClipBit,
- FarClipFlag = 1<<FarClipBit,
- ClipMask =
- TopClipFlag | BottomClipFlag | LeftClipFlag
- | RightClipFlag | NearClipFlag | FarClipFlag
- };
- bool
- IsFarClipped()
- {Check_Pointer(this); return (clippingState&FarClipFlag) != 0;}
- void
- SetFarClip()
- {Check_Pointer(this); clippingState |= FarClipFlag;}
- void
- ClearFarClip()
- {Check_Pointer(this); clippingState &= ~FarClipFlag;}
- bool
- IsNearClipped()
- {Check_Pointer(this); return (clippingState&NearClipFlag) != 0;}
- void
- SetNearClip()
- {Check_Pointer(this); clippingState |= NearClipFlag;}
- void
- ClearNearClip()
- {Check_Pointer(this); clippingState &= ~NearClipFlag;}
- bool
- IsTopClipped()
- {Check_Pointer(this); return clippingState&TopClipFlag;}
- void
- SetTopClip()
- {Check_Pointer(this); clippingState |= TopClipFlag;}
- void
- ClearTopClip()
- {Check_Pointer(this); clippingState &= ~TopClipFlag;}
- bool
- IsBottomClipped()
- {Check_Pointer(this); return (clippingState&BottomClipFlag) != 0;}
- void
- SetBottomClip()
- {Check_Pointer(this); clippingState |= BottomClipFlag;}
- void
- ClearBottomClip()
- {Check_Pointer(this); clippingState &= ~BottomClipFlag;}
- bool
- IsLeftClipped()
- {Check_Pointer(this); return (clippingState&LeftClipFlag) != 0;}
- void
- SetLeftClip()
- {Check_Pointer(this); clippingState |= LeftClipFlag;}
- void
- ClearLeftClip()
- {Check_Pointer(this); clippingState &= ~LeftClipFlag;}
- bool
- IsRightClipped()
- {Check_Pointer(this); return (clippingState&RightClipFlag) != 0;}
- void
- SetRightClip()
- {Check_Pointer(this); clippingState |= RightClipFlag;}
- void
- ClearRightClip()
- {Check_Pointer(this); clippingState &= ~RightClipFlag;}
- void
- SetClip(int mask, int flag)
- {
- Check_Pointer(this);
- #if USE_ASSEMBLER_CODE
- _asm {
- xor ecx, ecx
- mov ebx, mask
- test ebx, 0ffffffffh
- seta cl
- xor eax, eax
- sub eax, ecx
- and flag, eax
- }
- clippingState |= flag;
- #else
- if(mask != 0)
- {
- clippingState |= flag;
- }
- #endif
- }
- bool
- IsClipped(int mask)
- {Check_Pointer(this); return (clippingState & mask) != 0;}
- int
- GetClippingState()
- {Check_Pointer(this); return (clippingState & ClipMask);}
- void
- SetClippingState(int state)
- {Check_Pointer(this); clippingState = state & ClipMask;}
- int
- GetNumberOfSetBits()
- {Check_Pointer(this); Verify(clippingState<=ClipMask);
- return numberBitsLookUpTable[clippingState]; }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // Assignment operators
- //
- public:
- MLRClippingState&
- operator=(const MLRClippingState &s)
- {
- Check_Pointer(this);
- clippingState = s.clippingState;
- return *this;
- }
- MLRClippingState&
- operator&=(const MLRClippingState &s)
- {
- Check_Pointer(this);
- clippingState &= s.clippingState;
- return *this;
- }
- MLRClippingState&
- operator|=(const MLRClippingState &s)
- {
- Check_Pointer(this);
- clippingState |= s.clippingState;
- return *this;
- }
- bool
- operator==(const MLRClippingState &s)
- {
- Check_Pointer(this);
- return (clippingState == s.clippingState);
- }
- bool
- operator==(const int &s)
- {
- Check_Pointer(this);
- return (clippingState == s);
- }
- bool
- operator!=(const MLRClippingState &s)
- {
- Check_Pointer(this);
- return (clippingState != s.clippingState);
- }
- bool
- operator!=(const int &s)
- {
- Check_Pointer(this);
- return (clippingState != s);
- }
- void
- Save(Stuff::MemoryStream *stream);
- void
- Load(Stuff::MemoryStream *stream);
- inline void
- Clip4dVertex(Stuff::Vector4D *v4d);
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // Testing
- //
- public:
- void
- TestInstance()
- {}
- private:
- static int numberBitsLookUpTable[ClipMask+1];
- };
- inline void
- MLRClippingState::Clip4dVertex(Stuff::Vector4D *v4d)
- {
- #if USE_ASSEMBLER_CODE
- int _ret = 0;
- _asm {
- mov edi, v4d
- xor ecx,ecx
- xor edx, edx
- test dword ptr [edi], 080000000h
- setne cl
- sub edx, ecx
- and edx, 8 // RightClipFlag
- xor ebx, ebx
- test dword ptr [edi+4], 080000000h
- setne cl
- sub ebx, ecx
- and ebx, 2 // BottomClipFlag
- or edx, ebx
- xor ebx, ebx
- test dword ptr [edi+8], 080000000h
- setne cl
- sub ebx, ecx
- and ebx, 16 // NearClipFlag
- or edx, ebx
- fld dword ptr [edi+0Ch]
- xor ebx, ebx
- fcom dword ptr [edi]
- fnstsw ax
- test ah, 1
- setne cl
- sub ebx, ecx
- and ebx, 4 // LeftClipFlag
- or edx, ebx
- xor ebx, ebx
- fcom dword ptr [edi+4]
- fnstsw ax
- test ah, 1
- setne cl
- sub ebx, ecx
- and ebx, 1 // TopClipFlag
- or edx, ebx
- xor ebx, ebx
- fcomp dword ptr [edi+8]
- fnstsw ax
- test ah, 41h
- setne cl
- sub ebx, ecx
- and ebx, 32 // FarClipFlag
- or edx, ebx
- mov _ret, edx
- }
-
- clippingState = _ret;
- #else
- clippingState = 0;
- if(v4d->w <= v4d->z)
- {
- SetFarClip();
- }
- if(v4d->z < 0.0f)
- {
- SetNearClip();
- }
- if(v4d->x < 0.0f)
- {
- SetRightClip();
- }
- if(v4d->w < v4d->x)
- {
- SetLeftClip();
- }
- if(v4d->y < 0.0f)
- {
- SetBottomClip();
- }
- if(v4d->w < v4d->y)
- {
- SetTopClip();
- }
- #endif
- }
- }
|