📄 mlrsorter.cpp
字号:
//===========================================================================//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
#include "MLRHeaders.hpp"
#ifdef CalDraw
GOSVertexPool *ToBeDrawnPrimitive::allVerticesToDraw;
#endif
MLRSorter::ClassData*
MLRSorter::DefaultData = NULL;
bool dontSeeMe = true;
SortData::DrawFunc SortData::Draw[LastMode] =
{
&SortData::DrawTriList,
&SortData::DrawTriIndexedList,
&SortData::DrawPointCloud,
&SortData::DrawQuads,
&SortData::DrawLineCloud
};
SortData::LoadSortAlphaFunc SortData::LoadSortAlpha[LastMode] =
{
&SortData::LoadAlphaFromTriList,
&SortData::LoadAlphaFromTriIndexedList,
&SortData::LoadAlphaFromPointCloud,
&SortData::LoadAlphaFromQuads,
&SortData::LoadAlphaFromLineCloud
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
SortData::DrawTriList()
{
Start_Timer(GOS_Draw_Time);
#ifdef LAB_ONLY
if(dontSeeMe == true)
#endif
{
if(texture2==0)
{
GOSVertex *v = (GOSVertex *)vertices;
if ((v[0].z >= 0.0f) &&
(v[0].z < 1.0f) &&
(v[1].z >= 0.0f) &&
(v[1].z < 1.0f) &&
(v[2].z >= 0.0f) &&
(v[2].z < 1.0f))
{
gos_DrawTriangles( (GOSVertex *)vertices, numVertices);
}
}
else
{
STOP(("GOS doesnt suppert gos_DrawTriangles for gos_VERTEX_2UV yet."));
// gos_DrawTriangles( (GOSVertex2UV *)vertices, numVertices);
}
}
Stop_Timer(GOS_Draw_Time);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
SortData::DrawTriIndexedList()
{
Start_Timer(GOS_Draw_Time);
#ifdef LAB_ONLY
if(dontSeeMe == true)
#endif
{
WORD newIndicies[4096];
long startIndex = 0;
GOSVertex *v = (GOSVertex *)vertices;
for (long i=0;i<numIndices;i+=3)
{
if (((v[indices[i]].z >= 0.0f) && (v[indices[i]].z < 1.0f)) &&
((v[indices[i+1]].z >= 0.0f) && (v[indices[i+1]].z < 1.0f)) &&
((v[indices[i+2]].z >= 0.0f) && (v[indices[i+2]].z < 1.0f)))
{
//Copy these indicies to new array.
newIndicies[startIndex] = indices[i];
newIndicies[startIndex+1] = indices[i+1];
newIndicies[startIndex+2] = indices[i+2];
startIndex += 3;
}
}
if (startIndex)
{
if(texture2==0)
{
gos_RenderIndexedArray( (GOSVertex *)vertices, numVertices, newIndicies, startIndex);
}
else
{
gos_RenderIndexedArray( (GOSVertex2UV *)vertices, numVertices, indices, numIndices);
}
}
}
Stop_Timer(GOS_Draw_Time);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
SortData::DrawPointCloud()
{
Verify(texture2==0);
Start_Timer(GOS_Draw_Time);
#ifdef LAB_ONLY
if(dontSeeMe == true)
#endif
{
GOSVertex pArray[32*3];
float size = (float)numIndices;
if( size == 0 )
{
size = 2.4f;
}
else
{
size *= 2.4f;
}
int Triangle = 0, Vertex = 0;
//
// Warning! - These points need clipping!
//
for( int i=numVertices; i; i-- )
{
pArray[Triangle+0] = *((GOSVertex *)vertices + Vertex);
pArray[Triangle+1] = *((GOSVertex *)vertices + Vertex);
pArray[Triangle+2] = *((GOSVertex *)vertices + Vertex);
pArray[Triangle+1].x += size;
pArray[Triangle+2].y += size;
Triangle +=3;
Vertex++;
if( Triangle==32*3 || i==1)
{
if ((pArray[0].z >= 0.0f) &&
(pArray[0].z < 1.0f) &&
(pArray[1].z >= 0.0f) &&
(pArray[1].z < 1.0f) &&
(pArray[2].z >= 0.0f) &&
(pArray[2].z < 1.0f))
{
gos_DrawTriangles( pArray, Triangle );
}
Triangle=0;
}
}
}
Stop_Timer(GOS_Draw_Time);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
SortData::DrawQuads()
{
Start_Timer(GOS_Draw_Time);
#ifdef LAB_ONLY
if(dontSeeMe == true)
#endif
{
if(texture2==0)
{
// gos_DrawTriangles( (GOSVertex *)vertices, numVertices);
gos_DrawQuads( (GOSVertex *)vertices, numVertices);
}
else
{
STOP(("GOS doesnt suppert gos_DrawQuads for gos_VERTEX_2UV yet."));
// gos_DrawQuads( (GOSVertex2UV *)vertices, numVertices);
}
}
Stop_Timer(GOS_Draw_Time);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
SortData::DrawLineCloud()
{
Verify(texture2==0);
Start_Timer(GOS_Draw_Time);
for(int i=0;i<numVertices;i++)
{
if(((GOSVertex *)vertices)[i].x > Environment.screenWidth-1)
{
((GOSVertex *)vertices)[i].x = static_cast<Scalar>(Environment.screenWidth-1);
}
if(((GOSVertex *)vertices)[i].y > Environment.screenHeight-1)
{
((GOSVertex *)vertices)[i].y = static_cast<Scalar>(Environment.screenHeight-1);
}
}
#ifdef LAB_ONLY
if(dontSeeMe == true)
#endif
{
gos_DrawLines( (GOSVertex *)vertices, numVertices);
}
Stop_Timer(GOS_Draw_Time);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
int
SortData::LoadAlphaFromTriList(SortAlpha **alpha)
{
Start_Timer(Alpha_Sorting_Time);
int i, index = 0, end = (int)(numVertices*0.333333333333333333333333);
Verify(texture2==0);
for(i=0;i<end;i++)
{
alpha[i]->state = &state;
alpha[i]->triangle[0] = ((GOSVertex *)vertices)[index++];
alpha[i]->triangle[1] = ((GOSVertex *)vertices)[index++];
alpha[i]->triangle[2] = ((GOSVertex *)vertices)[index++];
alpha[i]->distance = alpha[i]->triangle[0].z;
alpha[i]->distance += alpha[i]->triangle[1].z;
alpha[i]->distance += alpha[i]->triangle[2].z;
}
Stop_Timer(Alpha_Sorting_Time);
return i;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
int
SortData::LoadAlphaFromTriIndexedList(SortAlpha **alpha)
{
Start_Timer(Alpha_Sorting_Time);
int i, index = 0, end = numIndices/3;
Verify(texture2==0);
for(i=0;i<end;i++)
{
alpha[i]->state = &state;
alpha[i]->triangle[0] = ((GOSVertex *)vertices)[indices[index++]];
alpha[i]->triangle[1] = ((GOSVertex *)vertices)[indices[index++]];
alpha[i]->triangle[2] = ((GOSVertex *)vertices)[indices[index++]];
alpha[i]->distance = alpha[i]->triangle[0].z;
alpha[i]->distance += alpha[i]->triangle[1].z;
alpha[i]->distance += alpha[i]->triangle[2].z;
}
Stop_Timer(Alpha_Sorting_Time);
return i;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
int
SortData::LoadAlphaFromPointCloud(SortAlpha**)
{
Start_Timer(Alpha_Sorting_Time);
STOP(("Not implemented"));
Stop_Timer(Alpha_Sorting_Time);
return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
int
SortData::LoadAlphaFromQuads(SortAlpha**)
{
Start_Timer(Alpha_Sorting_Time);
STOP(("Not implemented"));
Stop_Timer(Alpha_Sorting_Time);
return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
int
SortData::LoadAlphaFromLineCloud(SortAlpha**)
{
Start_Timer(Alpha_Sorting_Time);
STOP(("Not implemented"));
Stop_Timer(Alpha_Sorting_Time);
return 0;
}
#ifdef CalDraw
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
ToBeDrawnPrimitive::ToBeDrawnPrimitive()
{
primitive = NULL;
cameraPosition = Stuff::LinearMatrix4D::Identity;
shapeToClipMatrix = Stuff::LinearMatrix4D::Identity;
for(int i=0;i<Limits::Max_Number_Of_Lights_Per_Primitive;i++)
{
activeLights[i] = NULL;
}
nrOfActiveLights = 0;
}
#endif
//#############################################################################
//############################ MLRSorter ################################
//#############################################################################
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLRSorter::InitializeClass()
{
Verify(!DefaultData);
Verify(gos_GetCurrentHeap() == StaticHeap);
DefaultData =
new ClassData(
MLRSorterClassID,
"MidLevelRenderer::MLRSorter",
RegisteredClass::DefaultData
);
Register_Object(DefaultData);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLRSorter::TerminateClass()
{
Unregister_Object(DefaultData);
delete DefaultData;
DefaultData = NULL;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLRSorter::MLRSorter(ClassData *class_data, MLRTexturePool *tp):
RegisteredClass(class_data)
{
Verify(gos_GetCurrentHeap() == Heap);
texturePool = tp;
gos_PushCurrentHeap(StaticHeap);
rawDrawData.SetLength(Limits::Max_Number_Primitives_Per_Frame);
#ifdef CalDraw
for(int i=0;i<MLRState::PriorityCount;i++)
{
lastUsedInBucketNotDrawn[i] = 0;
priorityBucketsNotDrawn[i].SetLength(Limits::Max_Number_Primitives_Per_Frame + Limits::Max_Number_ScreenQuads_Per_Frame);
}
drawData.SetLength(Limits::Max_Number_Primitives_Per_Frame);
#endif
gos_PopCurrentHeap();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -