MCPcopy Create free account
hub / github.com/axmolengine/axmol / draw

Method draw

core/3d/Terrain.cpp:123–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123void Terrain::draw(ax::Renderer* renderer, const ax::Mat4& transform, uint32_t flags)
124{
125 auto modelMatrix = getNodeToWorldTransform();
126 if (memcmp(&modelMatrix, &_terrainModelMatrix, sizeof(Mat4)) != 0)
127 {
128 _terrainModelMatrix = modelMatrix;
129 _quadRoot->preCalculateAABB(_terrainModelMatrix);
130 }
131
132 auto& projectionMatrix = _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
133 auto finalMatrix = projectionMatrix * transform;
134 _programState->setUniform(_mvpMatrixLocation, &finalMatrix.m, sizeof(finalMatrix.m));
135
136 _programState->setUniform(_lightDirLocation, &_lightDir, sizeof(_lightDir));
137 if (!_alphaMap)
138 {
139 _programState->setTexture(_detailMapLocation[0], 0, _detailMapTextures[0]->getBackendTexture());
140 int hasAlphaMap = 0;
141 _programState->setUniform(_alphaIsHasAlphaMapLocation, &hasAlphaMap, sizeof(hasAlphaMap));
142 }
143 else
144 {
145 float detailMapSize[4] = {0.0f, 0.0f, 0.0f, 0.0f};
146 for (int i = 0; i < _maxDetailMapValue; ++i)
147 {
148 _programState->setTexture(_detailMapLocation[i], i, _detailMapTextures[i]->getBackendTexture());
149 detailMapSize[i] = _terrainData._detailMaps[i]._detailMapSize;
150 }
151 _programState->setUniform(_detailMapSizeLocation, detailMapSize, sizeof(detailMapSize));
152
153 int hasAlphaMap = 1;
154 _programState->setUniform(_alphaIsHasAlphaMapLocation, &hasAlphaMap, sizeof(hasAlphaMap));
155 _programState->setTexture(_alphaMapLocation, 4, _alphaMap->getBackendTexture());
156 }
157 if (_lightMap)
158 {
159 int hasLightMap = 1;
160 _programState->setUniform(_lightMapCheckLocation, &hasLightMap, sizeof(hasLightMap));
161 _programState->setTexture(_lightMapLocation, 5, _lightMap->getBackendTexture());
162 }
163 else
164 {
165 int hasLightMap = 0;
166 _programState->setUniform(_lightMapCheckLocation, &hasLightMap, sizeof(hasLightMap));
167#ifdef AX_USE_METAL
168 _programState->setTexture(_lightMapLocation, 5, _dummyTexture->getBackendTexture());
169#endif
170 }
171 auto camera = Camera::getVisitingCamera();
172
173 if (memcmp(&_CameraMatrix, &camera->getViewMatrix(), sizeof(Mat4)) != 0)
174 {
175 _isCameraViewChanged = true;
176 _CameraMatrix = camera->getViewMatrix();
177 }
178
179 if (_isCameraViewChanged)
180 {

Callers

nothing calls this directly

Calls 9

preCalculateAABBMethod · 0.80
getBackendTextureMethod · 0.80
resetNeedDrawMethod · 0.80
cullByCameraMethod · 0.80
bindAndDrawMethod · 0.80
Vec3Function · 0.50
setUniformMethod · 0.45
setTextureMethod · 0.45

Tested by

no test coverage detected