123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #include "MLRHeaders.hpp"
- //#############################################################################
- //##################### MLRIndexedPrimitive #############################
- //#############################################################################
- MLRIndexedPrimitive::ClassData*
- MLRIndexedPrimitive::DefaultData = NULL;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::InitializeClass()
- {
- Verify(!DefaultData);
- DefaultData =
- new ClassData(
- MLRIndexedPrimitiveClassID,
- "MidLevelRenderer::MLRIndexedPrimitive",
- MLRPrimitive::DefaultData,
- NULL
- );
- Register_Object(DefaultData);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::TerminateClass()
- {
- Unregister_Object(DefaultData);
- delete DefaultData;
- DefaultData = NULL;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRIndexedPrimitive::MLRIndexedPrimitive(
- ClassData *class_data,
- MemoryStream *stream,
- int version
- ):
- MLRPrimitive(class_data, stream, version)
- {
- Check_Pointer(this);
- Check_Object(stream);
- MemoryStreamIO_Read(stream, &index);
- visibleIndexedVerticesKey = false;
- visibleIndexedVertices.SetLength(numVertices);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::Save(MemoryStream *stream)
- {
- Check_Object(this);
- Check_Object(stream);
- MLRPrimitive::Save(stream);
- MemoryStreamIO_Write(stream, &index);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRIndexedPrimitive::MLRIndexedPrimitive(ClassData *class_data):
- MLRPrimitive(class_data), index(0)
- {
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRIndexedPrimitive::~MLRIndexedPrimitive()
- {
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::TestInstance() const
- {
- Verify(IsDerivedFrom(DefaultData));
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::InitializeDrawPrimitive(int vis, int parameter)
- {
- MLRPrimitive::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
- MLRIndexedPrimitive::SetCoordData(
- const Point3D *data,
- int dataSize
- )
- {
- Check_Object(this);
- Check_Pointer(data);
- Verify(colors.GetLength() == 0 || dataSize == colors.GetLength());
- Verify(normals.GetLength() == 0 || dataSize == normals.GetLength());
- Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
- #if defined (MAX_NUMBER_VERTICES)
- Verify(dataSize <= MAX_NUMBER_VERTICES);
- #endif
- coords.AssignData(data, dataSize);
- transformedCoords.SetLength(dataSize);
- numVertices = dataSize;
- if(index.GetLength() > 0 && visibleIndexedVertices.GetLength() != dataSize)
- {
- visibleIndexedVertices.SetLength(dataSize);
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::SetIndexData(
- unsigned short *index_array,
- int index_count
- )
- {
- Check_Object(this);
- Check_Pointer(index_array);
- if(coords.GetLength() > 0)
- {
- visibleIndexedVertices.SetLength(coords.GetLength());
- }
- index.AssignData(index_array, index_count);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::GetIndexData(
- unsigned short **index_array,
- int *index_count
- )
- {
- Check_Object(this);
- *index_array = index.GetData();
- *index_count = index.GetLength();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::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
- Statistics::MLR_TransformedVertices += len;
- #endif
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLRIndexedPrimitive::Lighting (
- MLRLight **lights,
- int nrLights
- )
- {
- Check_Object(this);
- // set the to use colors to the original colors ...
- // only lighting could overwrite this;
- actualColors = &colors;
- if(nrLights == 0)
- {
- return;
- }
- if(normals.GetLength() == 0)
- {
- return;
- }
- if(lights == NULL)
- {
- return;
- }
- switch (GetCurrentState().GetLightingMode())
- {
- case MLRState::LightingOffMode:
- return;
- case MLRState::LightingClassicOnlyMode:
- {
- Verify(colors.GetLength() == litColors.GetLength());
- Verify(normals.GetLength() == colors.GetLength());
- Verify(coords.GetLength() == colors.GetLength());
- int i, k, len = colors.GetLength();
- MLRVertexData vertexData;
- #if COLOR_AS_DWORD
- TO_DO;
- #else
- RGBAColor *color = &colors[0];
- RGBAColor *litColor = &litColors[0];
- #if USE_ASSEMBLER_CODE
- _asm {
- push esi
- push edi
- mov esi, color
- mov edi, litColor
- mov ecx, len
- _loop1:
- mov eax, dword ptr [esi]
- mov ebx, dword ptr [esi+4]
- mov dword ptr [edi], eax
- mov dword ptr [edi+ 4], ebx
- mov eax, dword ptr [esi + 8]
- mov ebx, dword ptr [esi + 12]
- mov dword ptr [edi + 8], eax
- mov dword ptr [edi + 12], ebx
- add esi,16
- add edi,16
- dec ecx
- jnz _loop1
- pop edi
- pop esi
- }
- #else // it doesnt know that ...
- memcpy(litColor, color, (len<<2)*sizeof(Scalar));
- #endif
- #endif
- //
- //-----------------------------------
- // Test each light against the vertex
- //-----------------------------------
- //
- for (i=0;i<nrLights;i++)
- {
- MLRLight *light = lights[i];
- Check_Object(light);
- vertexData.point = &coords[0];
- vertexData.color = &litColors[0];
- vertexData.normal = &normals[0];
- for(k=0;k<len;k++)
- {
- light->LightVertex(vertexData);
- vertexData.point++;
- vertexData.color++;
- vertexData.normal++;
- }
- }
- #ifdef LAB_ONLY
- Statistics::MLR_LitVertices += len*nrLights;
- #endif
- // set the to use colors to the original colors ...
- // only lighting could overwrite this;
- actualColors = &litColors;
- }
- break;
- case MLRState::LightingLightMapOnlyMode:
- {
- Verify(state.GetAlphaMode() == MLRState::OneZeroMode);
- STOP(("Lightmaps not implemented yet."));
- }
- break;
- case MLRState::LightingClassicAndLightMapMode:
- {
- Verify(state.GetAlphaMode() == MLRState::OneZeroMode);
- Verify(colors.GetLength() == litColors.GetLength());
- Verify(normals.GetLength() == colors.GetLength());
- Verify(coords.GetLength() == colors.GetLength());
- int i, k, len = colors.GetLength();
- MLRVertexData vertexData;
- #if COLOR_AS_DWORD
- TO_DO;
- #else
- RGBAColor *color = &colors[0];
- RGBAColor *litColor = &litColors[0];
- #if USE_ASSEMBLER_CODE
- _asm {
- push esi
- push edi
- mov esi, color
- mov edi, litColor
- mov ecx, len
- _loop2:
- mov eax, dword ptr [esi]
- mov ebx, dword ptr [esi+4]
- mov dword ptr [edi], eax
- mov dword ptr [edi+ 4], ebx
- mov eax, dword ptr [esi + 8]
- mov ebx, dword ptr [esi + 12]
- mov dword ptr [edi + 8], eax
- mov dword ptr [edi + 12], ebx
- add esi,16
- add edi,16
- dec ecx
- jnz _loop2
- pop edi
- pop esi
- }
- #else // it doesnt know that ...
- memcpy(litColor, color, (len<<2)*sizeof(Scalar));
- #endif
- #endif
- //
- //-----------------------------------
- // Test each light against the vertex
- //-----------------------------------
- //
- for (i=0;i<nrLights;i++)
- {
- MLRLight *light = lights[i];
- Check_Object(light);
- vertexData.point = &coords[0];
- vertexData.color = &litColors[0];
- vertexData.normal = &normals[0];
- for(k=0;k<len;k++)
- {
- light->LightVertex(vertexData);
- vertexData.point++;
- vertexData.color++;
- vertexData.normal++;
- }
- }
- #ifdef LAB_ONLY
- Statistics::MLR_LitVertices += len*nrLights;
- #endif
- // set the to use colors to the original colors ...
- // only lighting could overwrite this;
- actualColors = &litColors;
- STOP(("Lightmaps not implemented yet."));
- }
- break;
- }
- }
|