123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #include "MLRHeaders.hpp"
- //#############################################################################
- //##################### MLRIndexedPrimitiveBase #########################
- //#############################################################################
- DynamicArrayOf<unsigned short>
- *MLRIndexedPrimitiveBase::clipExtraIndex;
- MLRIndexedPrimitiveBase::ClassData*
- MLRIndexedPrimitiveBase::DefaultData = NULL;
- unsigned short
- *indexOffset;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::InitializeClass()
- {
- Verify(!DefaultData);
- Verify(gos_GetCurrentHeap() == StaticHeap);
- DefaultData =
- new ClassData(
- MLRIndexedPrimitiveBaseClassID,
- "MidLevelRenderer::MLRIndexedPrimitiveBase",
- MLRPrimitiveBase::DefaultData,
- NULL
- );
- Register_Object(DefaultData);
-
- clipExtraIndex = new DynamicArrayOf<unsigned short> (Limits::Max_Number_Vertices_Per_Mesh);
- Register_Pointer(clipExtraIndex);
- indexOffset = new unsigned short [Limits::Max_Number_Vertices_Per_Mesh+1];
- Register_Pointer(indexOffset);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::TerminateClass()
- {
- Unregister_Pointer(clipExtraIndex);
- delete clipExtraIndex;
- Unregister_Pointer(indexOffset);
- delete [] indexOffset;
- Unregister_Object(DefaultData);
- delete DefaultData;
- DefaultData = NULL;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRIndexedPrimitiveBase::MLRIndexedPrimitiveBase(
- ClassData *class_data,
- MemoryStream *stream,
- int version
- ):
- MLRPrimitiveBase(class_data, stream, version)
- {
- Check_Pointer(this);
- Check_Object(stream);
- Verify(gos_GetCurrentHeap() == Heap);
- switch(version)
- {
- case 1:
- case 2:
- {
- STOP(("This class got created only after version 2 !"));
- }
- break;
- default:
- {
- MemoryStreamIO_Read(stream, &index);
- }
- break;
- }
- visibleIndexedVerticesKey = false;
- visibleIndexedVertices.SetLength(coords.GetLength());
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::Save(MemoryStream *stream)
- {
- Check_Object(this);
- Check_Object(stream);
- MLRPrimitiveBase::Save(stream);
- MemoryStreamIO_Write(stream, &index);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRIndexedPrimitiveBase::MLRIndexedPrimitiveBase(ClassData *class_data):
- MLRPrimitiveBase(class_data), index(0)
- {
- Verify(gos_GetCurrentHeap() == Heap);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRIndexedPrimitiveBase::~MLRIndexedPrimitiveBase()
- {
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::TestInstance() const
- {
- Verify(IsDerivedFrom(DefaultData));
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::InitializeDrawPrimitive(unsigned char vis, int parameter)
- {
- MLRPrimitiveBase::InitializeDrawPrimitive(vis, parameter);
- gos_indices = NULL;
- numGOSIndices = -1;
- visibleIndexedVerticesKey = false;
- int i, len = visibleIndexedVertices.GetLength();
- for(i=0;i<len;i++)
- {
- visibleIndexedVertices[i] = 0;
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::SetCoordData(
- const Point3D *data,
- int dataSize
- )
- {
- Check_Object(this);
- Check_Pointer(data);
- Verify(gos_GetCurrentHeap() == Heap);
- Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
- #if defined (MAX_NUMBER_VERTICES)
- Verify(dataSize <= MAX_NUMBER_VERTICES);
- #endif
- coords.AssignData(data, dataSize);
- if(index.GetLength() > 0 && visibleIndexedVertices.GetLength() != dataSize)
- {
- visibleIndexedVertices.SetLength(dataSize);
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::SetIndexData(
- unsigned short *index_array,
- int index_count
- )
- {
- Check_Object(this);
- Check_Pointer(index_array);
- Verify(gos_GetCurrentHeap() == Heap);
- if(coords.GetLength() > 0)
- {
- visibleIndexedVertices.SetLength(coords.GetLength());
- }
- #ifdef _ARMOR
- int len = coords.GetLength();
- for(int i=0;i<index_count;i++)
- {
- Verify(index_array[i] < len);
- }
- #endif
- index.AssignData(index_array, index_count);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::GetIndexData(
- unsigned short **index_array,
- int *index_count
- )
- {
- Check_Object(this);
- *index_array = index.GetData();
- *index_count = index.GetLength();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitiveBase::Transform(Matrix4D *mat)
- {
- Check_Object(this);
- int i, len = coords.GetLength();
- for(i=0;i<len;i++)
- {
- (*transformedCoords)[i].Multiply(coords[i], *mat);
- }
-
- #ifdef LAB_ONLY
- Set_Statistic(TransformedVertices, TransformedVertices+len);
- #endif
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- bool
- MLRIndexedPrimitiveBase::CheckIndicies()
- {
- for(int i=0;i<numGOSIndices;i++)
- {
- if(gos_indices[i] >= numGOSVertices)
- {
- STOP(("Invalid indicies detected !"));
- }
- }
- return true;
- }
|