123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #include "FactoryCraftModel.h"
- #include <Shader.h>
- #include "CustomDX11API.h"
- #include "Globals.h"
- #include "World.h"
- FactoryCraftModel::FactoryCraftModel()
- : Model3D()
- {
- vertexLightBuffer = 0;
- lightBuffer = 0;
- vertexLightBufferCount = 0;
- visible = 1;
- destroyedState = 0;
- breakTextur
- = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur(
- "blocks.ltdb/crack.png", 0);
- effectAlpha = 0;
- }
- FactoryCraftModel::~FactoryCraftModel()
- {
- breakTextur->release();
- if (vertexLightBuffer) vertexLightBuffer->release();
- delete[] lightBuffer;
- }
- struct TexturEffect
- {
- bool enabled;
- float percentage;
- };
- void FactoryCraftModel::beforeRender(Framework::GraphicsApi* api,
- Framework::Shader* zVertexShader,
- Framework::Shader* zPixelShader)
- {
- if (!World::INSTANCE) return;
- CustomDX11API* cApi = dynamic_cast<CustomDX11API*>(api);
- if (cApi)
- {
- char buffer[8];
- *(int*)buffer
- = vertexLightBufferCount == 0 ? 1 : vertexLightBufferCount;
- *(float*)(buffer + 4) = World::INSTANCE->getDayLightFactor();
- zVertexShader->füllConstBuffer(
- buffer, cApi->getVertexShaderLightBufferIndex(), 8);
- if (vertexLightBuffer)
- {
- cApi->setVertexLightBuffer(vertexLightBuffer);
- }
- else
- {
- cApi->setVertexLightBuffer(
- World::INSTANCE->zFallbackVertexLightBuffer());
- }
- if (destroyedState > 0 && effectAlpha)
- {
- TexturEffect e = {1, 1.f + destroyedState};
- zPixelShader->füllConstBuffer(
- (char*)&e, 3, sizeof(TexturEffect));
- }
- }
- }
- void FactoryCraftModel::afterRender(Framework::GraphicsApi* api,
- Framework::Shader* zVertexShader,
- Framework::Shader* zPixelShader)
- {
- if (!World::INSTANCE) return;
- CustomDX11API* cApi = dynamic_cast<CustomDX11API*>(api);
- if (cApi)
- {
- char buffer[8];
- *(int*)buffer = 0;
- *(float*)(buffer + 4) = World::INSTANCE->getDayLightFactor();
- zVertexShader->füllConstBuffer(
- buffer, cApi->getVertexShaderLightBufferIndex(), 8);
- }
- }
- void FactoryCraftModel::setVertexLightBuffer(__int64* data, int vertexCount)
- {
- if (!vertexLightBuffer)
- {
- vertexLightBuffer = uiFactory.initParam.bildschirm->zGraphicsApi()
- ->createStructuredBuffer(16);
- }
- if (lightBuffer)
- {
- delete[] lightBuffer;
- }
- lightBuffer = data;
- vertexLightBufferCount = vertexCount;
- vertexLightBuffer->setData(data);
- vertexLightBuffer->setLength(vertexCount * 8);
- vertexLightBuffer->copieren();
- }
- __int64* FactoryCraftModel::zLightBuffer()
- {
- if (vertexLightBuffer)
- {
- vertexLightBuffer->setChanged();
- }
- return lightBuffer;
- }
- void FactoryCraftModel::copyLightToGPU()
- {
- if (vertexLightBuffer)
- {
- vertexLightBuffer->copieren();
- }
- }
- void FactoryCraftModel::setVisible(bool visible)
- {
- this->visible = visible;
- }
- void FactoryCraftModel::setDestroyedState(float percentage)
- {
- destroyedState = percentage;
- }
- void FactoryCraftModel::setUseEffectAlpha(bool useAlpha)
- {
- effectAlpha = useAlpha;
- }
- bool FactoryCraftModel::needRenderPolygon(int index)
- {
- return visible;
- }
- Textur* FactoryCraftModel::zEffectTextur()
- {
- return destroyedState > 0 ? breakTextur : 0;
- }
- float FactoryCraftModel::getEffectPercentage()
- {
- return destroyedState;
- }
|