Skip to content

Commit f99600e

Browse files
committed
update
1 parent d4ad17b commit f99600e

9 files changed

Lines changed: 203 additions & 140 deletions

File tree

Editor/Editor.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,7 +5226,7 @@ void EditorComponent::SaveAs()
52265226
});
52275227
}
52285228

5229-
Texture EditorComponent::CreateThumbnail(Texture texture, uint32_t target_width, uint32_t target_height) const
5229+
Texture EditorComponent::CreateThumbnail(Texture texture, uint32_t target_width, uint32_t target_height, bool mipmaps) const
52305230
{
52315231
GraphicsDevice* device = GetDevice();
52325232
CommandList cmd = device->BeginCommandList();
@@ -5246,7 +5246,7 @@ Texture EditorComponent::CreateThumbnail(Texture texture, uint32_t target_width,
52465246
TextureDesc desc = thumbnail.desc;
52475247
desc.width = current_width;
52485248
desc.height = current_height;
5249-
desc.mip_levels = 1;
5249+
desc.mip_levels = mipmaps? 0 : 1;
52505250
desc.bind_flags = BindFlag::SHADER_RESOURCE | BindFlag::RENDER_TARGET | BindFlag::UNORDERED_ACCESS;
52515251
Texture upsized;
52525252
device->CreateTexture(&desc, nullptr, &upsized);
@@ -5301,14 +5301,20 @@ Texture EditorComponent::CreateThumbnail(Texture texture, uint32_t target_width,
53015301
TextureDesc desc = thumbnail.desc;
53025302
desc.width = std::max(target_width, desc.width / 4u);
53035303
desc.height = std::max(target_height, desc.height / 4u);
5304-
desc.mip_levels = 1;
5304+
desc.mip_levels = mipmaps ? 0 : 1;
53055305
desc.bind_flags = BindFlag::SHADER_RESOURCE | BindFlag::RENDER_TARGET | BindFlag::UNORDERED_ACCESS;
53065306
Texture downsized;
53075307
device->CreateTexture(&desc, nullptr, &downsized);
53085308
wi::renderer::Postprocess_Downsample4x(thumbnail, downsized, cmd);
53095309
thumbnail = downsized;
53105310
}
53115311

5312+
if (mipmaps)
5313+
{
5314+
device->CreateMipgenSubresources(thumbnail);
5315+
wi::renderer::GenerateMipChain(thumbnail, wi::renderer::MIPGENFILTER_LINEAR, cmd);
5316+
}
5317+
53125318
return thumbnail;
53135319
}
53145320
Texture EditorComponent::CreateThumbnailScreenshot() const

Editor/Editor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class EditorComponent : public wi::RenderPath2D
185185
void SaveAs();
186186
bool deleting = false;
187187

188-
wi::graphics::Texture CreateThumbnail(wi::graphics::Texture texture, uint32_t target_width, uint32_t target_height) const;
188+
wi::graphics::Texture CreateThumbnail(wi::graphics::Texture texture, uint32_t target_width, uint32_t target_height, bool mipmaps = false) const;
189189
wi::graphics::Texture CreateThumbnailScreenshot() const;
190190

191191
std::string save_text_message = "";

Editor/ProjectCreatorWindow.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor)
4545
wi::Resource res = wi::resourcemanager::Load(fileName);
4646
if (!res.IsValid())
4747
return;
48-
iconResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 128, 128));
48+
iconResource.SetTexture(editor->CreateThumbnail(res.GetTexture(), 128, 128, true));
4949
iconName = fileName;
5050
iconButton.SetImage(iconResource);
5151
});
@@ -162,6 +162,7 @@ end)
162162
if (iconResource.IsValid())
163163
{
164164
wi::helper::saveTextureToFile(iconResource.GetTexture(), directory + "icon.png");
165+
wi::helper::saveTextureToFile(iconResource.GetTexture(), directory + "icon.ico");
165166
}
166167
if (thumbnailResource.IsValid())
167168
{
@@ -260,41 +261,46 @@ end)
260261
uint32_t biClrImportant; // Important colors
261262
};
262263

263-
const uint32_t pixelCount = tex.desc.width * tex.desc.height;
264-
const uint32_t rgbDataSize = pixelCount * 4; // 32-bit RGBA
265-
const uint32_t maskSize = ((tex.desc.width + 7) / 8) * tex.desc.height; // 1-bit mask, padded to byte
266-
const uint32_t bmpInfoHeaderSize = sizeof(BITMAPINFOHEADER);
267-
const uint32_t iconDirSize = sizeof(ICONDIR);
268-
const uint32_t iconDirEntrySize = sizeof(ICONDIRENTRY);
269-
const uint32_t imageDataSize = bmpInfoHeaderSize + rgbDataSize + maskSize;
270-
271-
BITMAPINFOHEADER bmpHeader = {
272-
bmpInfoHeaderSize, // Size of header
273-
int32_t(tex.desc.width), // Width
274-
int32_t(tex.desc.height * 2), // Height (doubled for XOR + AND mask)
275-
1, // Planes
276-
32, // Bits per pixel
277-
0, // No compression
278-
rgbDataSize + maskSize, // Image size
279-
0, // X pixels per meter
280-
0, // Y pixels per meter
281-
0, // Colors used
282-
0 // Important colors
283-
};
284-
285-
wi::vector<uint8_t> bmpvec(sizeof(bmpHeader));
286-
std::memcpy(bmpvec.data(), &bmpHeader, sizeof(bmpHeader));
264+
const int resolutions[] = {128,64,32};
287265

288-
// searches for exact BMP header match:
289-
auto it = std::search(exedata.begin(), exedata.end(), bmpvec.begin(), bmpvec.end());
290-
if (it != exedata.end())
266+
for (int res : resolutions)
291267
{
292-
wi::vector<uint8_t> iconfiledata;
293-
if (wi::helper::saveTextureToMemoryFile(tex, "ico", iconfiledata))
268+
const uint32_t pixelCount = res * res;
269+
const uint32_t rgbDataSize = pixelCount * 4; // 32-bit RGBA
270+
const uint32_t maskSize = ((res + 7) / 8) * res; // 1-bit mask, padded to byte
271+
const uint32_t bmpInfoHeaderSize = sizeof(BITMAPINFOHEADER);
272+
const uint32_t iconDirSize = sizeof(ICONDIR);
273+
const uint32_t iconDirEntrySize = sizeof(ICONDIRENTRY);
274+
const uint32_t imageDataSize = bmpInfoHeaderSize + rgbDataSize + maskSize;
275+
276+
BITMAPINFOHEADER bmpHeader = {
277+
bmpInfoHeaderSize, // Size of header
278+
int32_t(res), // Width
279+
int32_t(res * 2), // Height (doubled for XOR + AND mask)
280+
1, // Planes
281+
32, // Bits per pixel
282+
0, // No compression
283+
rgbDataSize + maskSize, // Image size
284+
0, // X pixels per meter
285+
0, // Y pixels per meter
286+
0, // Colors used
287+
0 // Important colors
288+
};
289+
290+
wi::vector<uint8_t> bmpvec(sizeof(bmpHeader));
291+
std::memcpy(bmpvec.data(), &bmpHeader, sizeof(bmpHeader));
292+
293+
// searches for exact BMP header match:
294+
auto it = std::search(exedata.begin(), exedata.end(), bmpvec.begin(), bmpvec.end());
295+
if (it != exedata.end())
294296
{
295-
// replace the BMP header and data part:
296-
std::copy(iconfiledata.begin() + sizeof(ICONDIR) + sizeof(ICONDIRENTRY), iconfiledata.end(), it);
297-
wilog("\tOverwritten Win32 icon");
297+
wi::vector<uint8_t> iconfiledata;
298+
if (wi::helper::saveTextureToMemoryFile(editor->CreateThumbnail(tex, res, res), "ico", iconfiledata))
299+
{
300+
// replace the BMP header and data part:
301+
std::copy(iconfiledata.begin() + sizeof(ICONDIR) + sizeof(ICONDIRENTRY), iconfiledata.end(), it);
302+
wilog("\tOverwritten Win32 icon at %d * %d resolution", res, res);
303+
}
298304
}
299305
}
300306
}

Editor/main_Windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
119119
wcex.cbWndExtra = 0;
120120
wcex.hInstance = hInstance;
121121
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(1001)); // 1001 = icon from Resource.rc file
122-
wcex.hIconSm = wcex.hIcon;
122+
wcex.hIconSm = NULL;
123123
wcex.hCursor = LoadCursor(hInstance, IDC_ARROW);
124124
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
125125
wcex.lpszMenuName = NULL;

Editor/wicked.ico

20.7 KB
Binary file not shown.

Samples/Example_ImGui/wicked.ico

20.7 KB
Binary file not shown.
20.7 KB
Binary file not shown.

Samples/Tests/wicked.ico

20.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)