Siv3D / OpenSiv3D

C++20 framework for creative coding 🎮🎨🎹 / Cross-platform support (Windows, macOS, Linux, and the Web)
https://siv3d.github.io/
MIT License
1k stars 138 forks source link

動的テクスチャのミップマップ生成対応 #1130

Closed Reputeless closed 10 months ago

Reputeless commented 10 months ago

テストコード

# include <Siv3D.hpp>

constexpr Size TextureSize{ 400, 360 };
constexpr ColorF TestColor{ 0.8, 0.9, 1.0 };

Image CreateImage()
{
    Image image{ TextureSize, TestColor };

    for (int32 x = 0; x < 200; x += 4)
    {
        Rect{ x, 0, 1, 360 }.overwrite(image, ColorF{ 0.0 });
    }

    for (int32 y = 0; y < 180; y += 4)
    {
        Rect{ 0, y, 400, 1 }.overwrite(image, ColorF{ 0.0 });
    }

    Circle{ 200, 180, 100 }.pieAsPolygon(Scene::Time() * 90_deg, 270_deg).paint(image, ColorF{ 0.0 });

    return image;
}

// 0~11
# define MODE 0

void Main()
{
    Window::Resize(1600, 800);
    Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });

# if (MODE/4 == 0)

    DynamicTexture texture{ TextureSize, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Unmipped }; // 画像の中身は不定
    DynamicTexture textureMipMap{ TextureSize, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Mipped }; // 画像の中身は不定
    DynamicTexture textureFill{ TextureSize, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Unmipped };
    DynamicTexture textureMipMapFill{ TextureSize, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Mipped };

# elif (MODE/4 == 1)

    DynamicTexture texture{ TextureSize, TestColor, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Unmipped };
    DynamicTexture textureMipMap{ TextureSize, TestColor, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Mipped };
    DynamicTexture textureFill{ TextureSize, TestColor, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Unmipped };
    DynamicTexture textureMipMapFill{ TextureSize, TestColor, TextureFormat::R8G8B8A8_Unorm, TextureDesc::Mipped };

# elif (MODE/4 == 2)

    DynamicTexture texture{ CreateImage(), TextureDesc::Unmipped };
    DynamicTexture textureMipMap{ CreateImage(), TextureDesc::Mipped };
    DynamicTexture textureFill{ CreateImage(), TextureDesc::Unmipped };
    DynamicTexture textureMipMapFill{ CreateImage(), TextureDesc::Mipped };

# endif

    if ((texture.hasMipMap() == true)
        || (textureMipMap.hasMipMap() == false)
        || (textureFill.hasMipMap() == true)
        || (textureMipMapFill.hasMipMap() == false))
    {
        Print << U"Error";
    }

    while (System::Update())
    {
        {
        # if (MODE%4 == 0)
            Image image = CreateImage();
            textureFill.fill(image);
            textureMipMapFill.fill(image);
        # elif (MODE%4 == 1)
            Image image = CreateImage();
            textureFill.fillRegion(image, Rect{ 300 });
            textureMipMapFill.fillRegion(image, Rect{ 300 });
        # elif (MODE%4 == 2)
            textureFill.fill(HSV{ Scene::FrameCount() });
            textureMipMapFill.fill(HSV{ Scene::FrameCount() });
        # elif (MODE%4 == 3)
            textureFill.fillRegion(HSV{Scene::FrameCount()}, Rect{ 300 });
            textureMipMapFill.fillRegion(HSV{Scene::FrameCount()}, Rect{ 300 });
        # endif
            textureMipMapFill.generateMips();
        }

        texture.draw(0, 0);
        texture.scaled(0.5).draw(400, 0);
        texture.scaled(0.25).draw(600, 0);
        texture.scaled(0.125).draw(700, 0);
        texture.scaled(0.0625).draw(750, 0);
        texture.scaled(0.03125).draw(775, 0);

        textureMipMap.draw(0, 400);
        textureMipMap.scaled(0.5).draw(400, 400);
        textureMipMap.scaled(0.25).draw(600, 400);
        textureMipMap.scaled(0.125).draw(700, 400);
        textureMipMap.scaled(0.0625).draw(750, 400);
        textureMipMap.scaled(0.03125).draw(775, 400);

        textureFill.draw(800, 0);
        textureFill.scaled(0.5).draw(1200, 0);
        textureFill.scaled(0.25).draw(1400, 0);
        textureFill.scaled(0.125).draw(1500, 0);
        textureFill.scaled(0.0625).draw(1550, 0);
        textureFill.scaled(0.03125).draw(1575, 0);

        textureMipMapFill.draw(800, 400);
        textureMipMapFill.scaled(0.5).draw(1200, 400);
        textureMipMapFill.scaled(0.25).draw(1400, 400);
        textureMipMapFill.scaled(0.125).draw(1500, 400);
        textureMipMapFill.scaled(0.0625).draw(1550, 400);
        textureMipMapFill.scaled(0.03125).draw(1575, 400);
    }
}

0

20231114-215602-517

1

20231114-215611-584

2

20231114-215626-868

3

20231114-215635-619

4

20231114-215646-036

5

20231114-215658-853

6

20231114-215714-121

7

20231114-215722-755

8

20231114-215754-756

9

20231114-215809-357

10

20231114-215819-107

11

20231114-215829-424