This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathDepthBufferRasterizerScalar.cpp
158 lines (139 loc) · 5.38 KB
/
DepthBufferRasterizerScalar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
////////////////////////////////////////////////////////////////////////////////
#include "DepthBufferRasterizerScalar.h"
DepthBufferRasterizerScalar::DepthBufferRasterizerScalar()
: DepthBufferRasterizer(),
mpTransformedModels1(NULL),
mNumModels1(0),
mpXformedPosOffset1(NULL),
mpStartV1(NULL),
mpStartT1(NULL),
mNumVertices1(0),
mNumTriangles1(0),
mOccluderSizeThreshold(0.0f),
mTimeCounter(0),
mEnableFCulling(true)
{
mpXformedPos[0] = mpXformedPos[1] = NULL;
mpCamera[0] = mpCamera[1] = NULL;
mpRenderTargetPixels[0] = NULL;
mpRenderTargetPixels[1] = NULL;
mNumRasterized[0] = mNumRasterized[1] = NULL;
mpBin[0] = mpBin[1] = NULL;
mpBinModel[0] = mpBinModel[1] = NULL;
mpBinMesh[0] = mpBinMesh[1] = NULL;
mpNumTrisInBin[0] = mpNumTrisInBin[1] = NULL;
mpModelIndexA[0] = mpModelIndexA[1] = NULL;
for(UINT i = 0; i < AVG_COUNTER; i++)
{
mRasterizeTime[i] = 0.0;
}
}
DepthBufferRasterizerScalar::~DepthBufferRasterizerScalar()
{
SAFE_DELETE_ARRAY(mpTransformedModels1);
SAFE_DELETE_ARRAY(mpXformedPosOffset1);
SAFE_DELETE_ARRAY(mpStartV1);
SAFE_DELETE_ARRAY(mpStartT1);
SAFE_DELETE_ARRAY(mpModelIndexA[0]);
SAFE_DELETE_ARRAY(mpModelIndexA[1]);
SAFE_DELETE_ARRAY(mpXformedPos[0]);
SAFE_DELETE_ARRAY(mpXformedPos[1]);
}
//--------------------------------------------------------------------
// * Go through the asset set and determine the model count in it
// * Create data structures for all the models in the asset set
// * For each model create the place holders for the transformed vertices
//--------------------------------------------------------------------
void DepthBufferRasterizerScalar::CreateTransformedModels(CPUTAssetSet **mpAssetSet, UINT numAssetSets)
{
for(UINT assetId = 0; assetId < numAssetSets; assetId++)
{
for(UINT nodeId = 0; nodeId < mpAssetSet[assetId]->GetAssetCount(); nodeId++)
{
CPUTRenderNode* pRenderNode = NULL;
CPUTResult result = mpAssetSet[assetId]->GetAssetByIndex(nodeId, &pRenderNode);
ASSERT((CPUT_SUCCESS == result), _L ("Failed getting asset by index"));
if(pRenderNode->IsModel())
{
mNumModels1++;
}
pRenderNode->Release();
}
}
mpTransformedModels1 = new TransformedModelScalar[mNumModels1];
mpXformedPosOffset1 = new UINT[mNumModels1];
mpStartV1 = new UINT[mNumModels1 + 1];
mpStartT1 = new UINT[mNumModels1 + 1];
mpModelIndexA[0] = new UINT[mNumModels1];
mpModelIndexA[1] = new UINT[mNumModels1];
UINT modelId = 0;
for(UINT assetId = 0; assetId < numAssetSets; assetId++)
{
for(UINT nodeId = 0; nodeId< mpAssetSet[assetId]->GetAssetCount(); nodeId++)
{
CPUTRenderNode* pRenderNode = NULL;
CPUTResult result = mpAssetSet[assetId]->GetAssetByIndex(nodeId, &pRenderNode);
ASSERT((CPUT_SUCCESS == result), _L ("Failed getting asset by index"));
if(pRenderNode->IsModel())
{
CPUTModelDX11* model = (CPUTModelDX11*)pRenderNode;
ASSERT((model != NULL), _L("model is NULL"));
model = (CPUTModelDX11*)pRenderNode;
mpTransformedModels1[modelId].CreateTransformedMeshes(model);
mpXformedPosOffset1[modelId] = mpTransformedModels1[modelId].GetNumVertices();
mpStartV1[modelId] = mNumVertices1;
mNumVertices1 += mpTransformedModels1[modelId].GetNumVertices();
mpStartT1[modelId] = mNumTriangles1;
mNumTriangles1 += mpTransformedModels1[modelId].GetNumTriangles();
modelId++;
}
pRenderNode->Release();
}
}
mpStartV1[modelId] = mNumVertices1;
mpStartT1[modelId] = mNumTriangles1;
//multiply by 4 for x, y, z, w
mpXformedPos[0] = new float[mNumVertices1 * 4];
mpXformedPos[1] = new float[mNumVertices1 * 4];
for(UINT i = 0; i < mNumModels1; i++)
{
mpTransformedModels1[i].SetXformedPos((float4*)&mpXformedPos[0][mpStartV1[i] * 4],
(float4*)&mpXformedPos[1][mpStartV1[i] * 4],
mpStartV1[i]);
}
}
//--------------------------------------------------------------------
// Clear depth buffer for a tile
//--------------------------------------------------------------------
void DepthBufferRasterizerScalar::ClearDepthTile(int startX, int startY, int endX, int endY, UINT idx)
{
assert(startX % 2 == 0 && startY % 2 == 0);
assert(endX % 2 == 0 && endY % 2 == 0);
float* pDepthBuffer = (float*)mpRenderTargetPixels[idx];
int width = endX - startX;
// Note we need to account for tiling pattern here
for(int r = startY; r < endY; r++)
{
int rowIdx = r * SCREENW + startX;
memset(&pDepthBuffer[rowIdx], 0, sizeof(float) * width);
}
}
void DepthBufferRasterizerScalar::SetViewProj(float4x4 *viewMatrix, float4x4 *projMatrix, UINT idx)
{
mpViewMatrix[idx] = *viewMatrix;
mpProjMatrix[idx] = *projMatrix;
}