Skip to content

Commit

Permalink
texturehelper improvement, image renderer will use null texture as white
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Feb 16, 2024
1 parent 8d89e30 commit 3e8fef2
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Editor/CameraComponentWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void CameraPreview::Render(const wi::Canvas& canvas, wi::graphics::CommandList c
params.corners_rounding[1].radius = 10;
params.corners_rounding[2].radius = 10;
params.corners_rounding[3].radius = 10;
wi::image::Draw(wi::texturehelper::getWhite(), params, cmd);
wi::image::Draw(nullptr, params, cmd);

params.pos.x += 4;
params.pos.y += 4;
Expand Down
4 changes: 2 additions & 2 deletions Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ void EditorComponent::Render() const

// Draw solid blocks of selected materials
fx.stencilRef = EDITORSTENCILREF_HIGHLIGHT_MATERIAL;
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);

device->RenderPassEnd(cmd);
}
Expand Down Expand Up @@ -2150,7 +2150,7 @@ void EditorComponent::Render() const

// Draw solid blocks of selected objects
fx.stencilRef = EDITORSTENCILREF_HIGHLIGHT_OBJECT;
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);

device->RenderPassEnd(cmd);
}
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ namespace wi
fx.enableFullScreen();
fx.color = fadeManager.color;
fx.opacity = fadeManager.opacity;
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

// Draw the information display
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiBacklog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ namespace wi::backlog
{
inputbg.enableLinearOutputMapping(9);
}
wi::image::Draw(wi::texturehelper::getWhite(), inputbg, cmd);
wi::image::Draw(nullptr, inputbg, cmd);

if (colorspace != ColorSpace::SRGB)
{
Expand Down
42 changes: 21 additions & 21 deletions WickedEngine/wiGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ namespace wi::gui
tooltipSprite.params.siz.y + tooltip_shadow * 2,
tooltip_shadow_color
);
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

tooltipSprite.Draw(cmd);
Expand Down Expand Up @@ -930,7 +930,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

font_description.Draw(cmd);
Expand Down Expand Up @@ -1127,7 +1127,7 @@ namespace wi::gui
fx.pos = XMFLOAT3(translation.x, translation.y, 0);
fx.siz = XMFLOAT2(scale.x, scale.y);
fx.color = sprites[IDLE].params.color;
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);

// scrollbar knob
sprites_knob[scrollbar_state].Draw(cmd);
Expand All @@ -1139,7 +1139,7 @@ namespace wi::gui
//scissorRect.top = (int32_t)(0);
//GraphicsDevice* device = wi::graphics::GetDevice();
//device->BindScissorRects(1, &scissorRect, cmd);
//wi::image::Draw(wi::texturehelper::getWhite(), wi::image::Params(hitBox.pos.x, hitBox.pos.y, hitBox.siz.x, hitBox.siz.y, wi::Color(255,0,0,100)), cmd);
//wi::image::Draw(nullptr, wi::image::Params(hitBox.pos.x, hitBox.pos.y, hitBox.siz.x, hitBox.siz.y, wi::Color(255,0,0,100)), cmd);

}
void ScrollBar::SetColor(wi::Color color, int id)
Expand Down Expand Up @@ -1294,7 +1294,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

ApplyScissor(canvas, scissorRect, cmd);
Expand Down Expand Up @@ -1584,7 +1584,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

font_description.Draw(cmd);
Expand Down Expand Up @@ -1626,7 +1626,7 @@ namespace wi::gui
params.siz.y = scale.y - 2;
params.blendFlag = wi::enums::BLENDMODE_ALPHA;
params.color = wi::Color::lerp(font_input.params.color, wi::Color::Transparent(), 0.5f);
wi::image::Draw(wi::texturehelper::getWhite(), params, cmd);
wi::image::Draw(nullptr, params, cmd);
}

//Rect scissorRect;
Expand Down Expand Up @@ -1941,7 +1941,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

font.Draw(cmd);
Expand Down Expand Up @@ -2111,7 +2111,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

font.Draw(cmd);
Expand Down Expand Up @@ -2160,7 +2160,7 @@ namespace wi::gui
scale.y * 0.5f
);
params.color = font.params.color;
wi::image::Draw(wi::texturehelper::getWhite(), params, cmd);
wi::image::Draw(nullptr, params, cmd);
}
}
else if (!uncheck_text.empty())
Expand Down Expand Up @@ -2435,7 +2435,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

wi::Color color = GetColor();
Expand Down Expand Up @@ -2473,7 +2473,7 @@ namespace wi::gui
wi::image::Params fx = sprites[state].params;
fx.pos = XMFLOAT3(translation.x + scale.x + 1, translation.y, 0);
fx.siz = XMFLOAT2(scale.y, scale.y);
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);

// control-arrow-triangle
{
Expand Down Expand Up @@ -2524,7 +2524,7 @@ namespace wi::gui
fx.pos = XMFLOAT3(translation.x + scale.x + 1, translation.y + scale.y + drop_offset, 0);
fx.siz = XMFLOAT2(scale.y, scale.y * maxVisibleItemCount);
fx.color = drop_color;
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

// control-scrollbar-grab
Expand Down Expand Up @@ -2577,7 +2577,7 @@ namespace wi::gui
fx.color = sprites[ACTIVE].params.color;
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);

wi::font::Params fp = wi::font::Params(
translation.x + scale.x * 0.5f,
Expand Down Expand Up @@ -3197,7 +3197,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

// base:
Expand Down Expand Up @@ -3228,12 +3228,12 @@ namespace wi::gui
//scissorRect.top = (int32_t)(0);
//GraphicsDevice* device = wi::graphics::GetDevice();
//device->BindScissorRects(1, &scissorRect, cmd);
//wi::image::Draw(wi::texturehelper::getWhite(), wi::image::Params(scrollable_area.active_area.pos.x, scrollable_area.active_area.pos.y, scrollable_area.active_area.siz.x, scrollable_area.active_area.siz.y, wi::Color(255,0,255,100)), cmd);
//wi::image::Draw(nullptr, wi::image::Params(scrollable_area.active_area.pos.x, scrollable_area.active_area.pos.y, scrollable_area.active_area.siz.x, scrollable_area.active_area.siz.y, wi::Color(255,0,255,100)), cmd);
//Hitbox2D p = scrollable_area.GetPointerHitbox();
//wi::image::Draw(wi::texturehelper::getWhite(), wi::image::Params(p.pos.x, p.pos.y, p.siz.x * 10, p.siz.y * 10, wi::Color(255,0,0,100)), cmd);
//wi::image::Draw(nullptr, wi::image::Params(p.pos.x, p.pos.y, p.siz.x * 10, p.siz.y * 10, wi::Color(255,0,0,100)), cmd);
//if (!IsCollapsed())
//{
// wi::image::Draw(wi::texturehelper::getWhite(), wi::image::Params(scrollable_area.translation.x, scrollable_area.translation.y, scale.x, 10, wi::Color(255,0,255,100)), cmd);
// wi::image::Draw(nullptr, wi::image::Params(scrollable_area.translation.x, scrollable_area.translation.y, scale.x, 10, wi::Color(255,0,255,100)), cmd);
//}

GetDevice()->EventEnd(cmd);
Expand Down Expand Up @@ -4657,7 +4657,7 @@ namespace wi::gui
}
}
}
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
}

// control-base
Expand All @@ -4675,7 +4675,7 @@ namespace wi::gui
fx.color = sprites[IDLE].params.color;
fx.pos = XMFLOAT3(itemlist_box.pos.x, itemlist_box.pos.y, 0);
fx.siz = XMFLOAT2(itemlist_box.siz.x, itemlist_box.siz.y);
wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);

Rect rect_without_scrollbar;
rect_without_scrollbar.left = (int)itemlist_box.pos.x;
Expand Down Expand Up @@ -4732,7 +4732,7 @@ namespace wi::gui
// selected box:
if (item.selected || item_highlight == i)
{
wi::image::Draw(wi::texturehelper::getWhite()
wi::image::Draw(nullptr
, wi::image::Params(name_box.pos.x, name_box.pos.y, name_box.siz.x, name_box.siz.y,
sprites[item.selected ? FOCUS : IDLE].params.color), cmd);
}
Expand Down
11 changes: 8 additions & 3 deletions WickedEngine/wiImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,14 @@ namespace wi::image
image.flags |= IMAGE_FLAG_MIRROR;
}

const TextureDesc& desc = texture->GetDesc();
const float inv_width = 1.0f / float(desc.width);
const float inv_height = 1.0f / float(desc.height);
float inv_width = 1.0f;
float inv_height = 1.0f;
if (texture != nullptr)
{
const TextureDesc& desc = texture->GetDesc();
inv_width = 1.0f / float(desc.width);
inv_height = 1.0f / float(desc.height);
}

if (params.isDrawRectEnabled())
{
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ namespace wi::profiler
fx.enableLinearOutputMapping(9);
}

wi::image::Draw(wi::texturehelper::getWhite(), fx, cmd);
wi::image::Draw(nullptr, fx, cmd);
wi::font::Draw(ss.str(), params, cmd);


Expand Down
2 changes: 2 additions & 0 deletions WickedEngine/wiRenderPath3D_PathTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ namespace wi
wi::renderer::CreateLuminanceResources(luminanceResources, internalResolution);
wi::renderer::CreateBloomResources(bloomResources, internalResolution);

setLightShaftsEnabled(getLightShaftsEnabled());

resetProgress();

RenderPath2D::ResizeBuffers(); // we don't need to use any buffers from RenderPath3D, so skip those
Expand Down
70 changes: 27 additions & 43 deletions WickedEngine/wiTextureHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ namespace wi::texturehelper
HELPERTEXTURE_LOGO,
HELPERTEXTURE_RANDOM64X64,
HELPERTEXTURE_COLORGRADEDEFAULT,
HELPERTEXTURE_NORMALMAPDEFAULT,
HELPERTEXTURE_BLACKCUBEMAP,
HELPERTEXTURE_UINT4,
HELPERTEXTURE_BLUENOISE,
HELPERTEXTURE_WATERRIPPLE,
HELPERTEXTURE_BLACK,
HELPERTEXTURE_WHITE,
HELPERTEXTURE_TRANSPARENT,
HELPERTEXTURE_NORMALMAPDEFAULT,
HELPERTEXTURE_COUNT
};
wi::graphics::Texture helperTextures[HELPERTEXTURE_COUNT];
Expand Down Expand Up @@ -188,6 +191,25 @@ namespace wi::texturehelper
device->SetName(&helperTextures[HELPERTEXTURE_WATERRIPPLE], "HELPERTEXTURE_WATERRIPPLE");
}

// Single colors:
{
wi::Color color = wi::Color::Black();
CreateTexture(helperTextures[HELPERTEXTURE_BLACK], (const uint8_t*)&color, 1, 1);
device->SetName(&helperTextures[HELPERTEXTURE_BLACK], "HELPERTEXTURE_BLACK");

color = wi::Color::White();
CreateTexture(helperTextures[HELPERTEXTURE_WHITE], (const uint8_t*)&color, 1, 1);
device->SetName(&helperTextures[HELPERTEXTURE_WHITE], "HELPERTEXTURE_WHITE");

color = wi::Color::Transparent();
CreateTexture(helperTextures[HELPERTEXTURE_TRANSPARENT], (const uint8_t*)&color, 1, 1);
device->SetName(&helperTextures[HELPERTEXTURE_TRANSPARENT], "HELPERTEXTURE_TRANSPARENT");

color = wi::Color(127, 127, 255, 255);
CreateTexture(helperTextures[HELPERTEXTURE_NORMALMAPDEFAULT], (const uint8_t*)&color, 1, 1);
device->SetName(&helperTextures[HELPERTEXTURE_NORMALMAPDEFAULT], "HELPERTEXTURE_NORMALMAPDEFAULT");
}

wi::backlog::post("wi::texturehelper Initialized (" + std::to_string((int)std::round(timer.elapsed())) + " ms)");
}

Expand All @@ -205,7 +227,7 @@ namespace wi::texturehelper
}
const Texture* getNormalMapDefault()
{
return getColor(wi::Color(127, 127, 255, 255));
return &helperTextures[HELPERTEXTURE_NORMALMAPDEFAULT];
}
const Texture* getBlackCubeMap()
{
Expand All @@ -225,53 +247,15 @@ namespace wi::texturehelper
}
const Texture* getWhite()
{
return getColor(wi::Color(255, 255, 255, 255));
return &helperTextures[HELPERTEXTURE_WHITE];
}
const Texture* getBlack()
{
return getColor(wi::Color(0, 0, 0, 255));
return &helperTextures[HELPERTEXTURE_BLACK];
}
const Texture* getTransparent()
{
return getColor(wi::Color(0, 0, 0, 0));
}
const Texture* getColor(wi::Color color)
{
colorlock.lock();
auto it = colorTextures.find(color.rgba);
auto end = colorTextures.end();
colorlock.unlock();

if (it != end)
{
return &it->second;
}

GraphicsDevice* device = wi::graphics::GetDevice();

static const int dim = 1;
static const int dataLength = dim * dim * 4;
uint8_t data[dataLength];
for (int i = 0; i < dataLength; i += 4)
{
data[i] = color.getR();
data[i + 1] = color.getG();
data[i + 2] = color.getB();
data[i + 3] = color.getA();
}

Texture texture;
if (CreateTexture(texture, data, dim, dim) == false)
{
return nullptr;
}
device->SetName(&texture, "HELPERTEXTURE_COLOR");

colorlock.lock();
colorTextures[color.rgba] = texture;
colorlock.unlock();

return &colorTextures[color.rgba];
return &helperTextures[HELPERTEXTURE_TRANSPARENT];
}


Expand Down
1 change: 0 additions & 1 deletion WickedEngine/wiTextureHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace wi::texturehelper
const wi::graphics::Texture* getWhite();
const wi::graphics::Texture* getBlack();
const wi::graphics::Texture* getTransparent();
const wi::graphics::Texture* getColor(wi::Color color);

bool CreateTexture(
wi::graphics::Texture& texture,
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 379;
const int revision = 380;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit 3e8fef2

Please sign in to comment.