void PolyDrawArgs::SetTexture(FSoftwareTexture *texture, uint32_t translationID, FRenderStyle style) { // Alphatexture overrides translations. if (translationID != 0xffffffff && translationID != 0 && !(style.Flags & STYLEF_RedIsAlpha)) { FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) { if (PolyTriangleDrawer::IsBgra()) mTranslation = (uint8_t*)table->Palette; else mTranslation = table->Remap; mTexture = texture; mTextureWidth = texture->GetPhysicalWidth(); mTextureHeight = texture->GetPhysicalHeight(); mTexturePixels = texture->GetPixels(style); return; } } if (style.Flags & STYLEF_RedIsAlpha) { mTexture = texture; mTextureWidth = texture->GetPhysicalWidth(); mTextureHeight = texture->GetPhysicalHeight(); mTexturePixels = texture->GetPixels(style); } else { SetTexture(texture, style); } }
void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal) { if (translationID != 0xffffffff && translationID != 0) { FRemapTable *table = TranslationToTable(translationID); if (table != nullptr && !table->Inactive) { if (PolyRenderer::Instance()->RenderTarget->IsBgra()) mTranslation = (uint8_t*)table->Palette; else mTranslation = table->Remap; mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); mTexturePixels = texture->GetPixels(); return; } } if (forcePal) { mTextureWidth = texture->GetWidth(); mTextureHeight = texture->GetHeight(); mTexturePixels = texture->GetPixels(); } else { SetTexture(texture); } }
BYTE * GetBlendMap(PalEntry blend, BYTE *blendwork) { switch (blend.a==0 ? blend.r : -1) { case BLEND_INVERSEMAP: return InverseColormap; case BLEND_GOLDMAP: return GoldColormap; case BLEND_REDMAP: return RedColormap; case BLEND_GREENMAP: return GreenColormap; case BLEND_ICEMAP: return TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap; default: if (blend.r >= BLEND_DESATURATE1 && blend.r <= BLEND_DESATURATE31) { return DesaturateColormap[blend.r - BLEND_DESATURATE1]; } else { blendwork[0]=0; if (blend.a == 255) { for(int i=1;i<256;i++) { int rr = (blend.r * GPalette.BaseColors[i].r) / 255; int gg = (blend.g * GPalette.BaseColors[i].g) / 255; int bb = (blend.b * GPalette.BaseColors[i].b) / 255; blendwork[i] = ColorMatcher.Pick(rr, gg, bb); } return blendwork; } else if (blend.a != 0) { for(int i=1;i<256;i++) { int rr = (blend.r * blend.a + GPalette.BaseColors[i].r * (255-blend.a)) / 255; int gg = (blend.g * blend.a + GPalette.BaseColors[i].g * (255-blend.a)) / 255; int bb = (blend.b * blend.a + GPalette.BaseColors[i].b * (255-blend.a)) / 255; blendwork[i] = ColorMatcher.Pick(rr, gg, bb); } return blendwork; } } } return NULL; }
BYTE *GetBlendMap(PalEntry blend, BYTE *blendwork) { switch (blend.a==0 ? int(blend) : -1) { case BLEND_ICEMAP: return TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap; default: if (blend >= BLEND_SPECIALCOLORMAP1 && blend < BLEND_SPECIALCOLORMAP1 + SpecialColormaps.Size()) { return SpecialColormaps[blend - BLEND_SPECIALCOLORMAP1].Colormap; } else if (blend >= BLEND_DESATURATE1 && blend <= BLEND_DESATURATE31) { return DesaturateColormap[blend - BLEND_DESATURATE1]; } else { blendwork[0]=0; if (blend.a == 255) { for(int i=1;i<256;i++) { int rr = (blend.r * GPalette.BaseColors[i].r) / 255; int gg = (blend.g * GPalette.BaseColors[i].g) / 255; int bb = (blend.b * GPalette.BaseColors[i].b) / 255; blendwork[i] = ColorMatcher.Pick(rr, gg, bb); } return blendwork; } else if (blend.a != 0) { for(int i=1;i<256;i++) { int rr = (blend.r * blend.a + GPalette.BaseColors[i].r * (255-blend.a)) / 255; int gg = (blend.g * blend.a + GPalette.BaseColors[i].g * (255-blend.a)) / 255; int bb = (blend.b * blend.a + GPalette.BaseColors[i].b * (255-blend.a)) / 255; blendwork[i] = ColorMatcher.Pick(rr, gg, bb); } return blendwork; } } } return NULL; }
void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags) { if (!tex->isHardwareCanvas()) { if (translation <= 0) { translation = -translation; } else { auto remap = TranslationToTable(translation); translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); } FTextureBuffer texbuffer = tex->CreateTexBuffer(translation, flags | CTF_ProcessData); CreateTexture(texbuffer.mWidth, texbuffer.mHeight, 4, VK_FORMAT_B8G8R8A8_UNORM, texbuffer.mBuffer); } else { auto fb = GetVulkanFrameBuffer(); VkFormat format = VK_FORMAT_R8G8B8A8_UNORM; int w = tex->GetWidth(); int h = tex->GetHeight(); ImageBuilder imgbuilder; imgbuilder.setFormat(format); imgbuilder.setSize(w, h); imgbuilder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); mImage.Image = imgbuilder.create(fb->device); mImage.Image->SetDebugName("VkHardwareTexture.mImage"); ImageViewBuilder viewbuilder; viewbuilder.setImage(mImage.Image.get(), format); mImage.View = viewbuilder.create(fb->device); mImage.View->SetDebugName("VkHardwareTexture.mImageView"); auto cmdbuffer = fb->GetTransferCommands(); VkImageTransition imageTransition; imageTransition.addImage(&mImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, true); imageTransition.execute(cmdbuffer); } }