Skip to content

Commit 86e8909

Browse files
committed
Display colour swatch when showing cbuffer values as RGB. Closes #3533
1 parent 959d330 commit 86e8909

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

qrenderdoc/Code/QRDUtils.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,27 @@ QString GetComponentString(byte mask)
18351835
return ret;
18361836
}
18371837

1838+
QIcon MakeSwatchIcon(QWidget *parentWidget, QColor swatchColor)
1839+
{
1840+
int h = parentWidget->fontMetrics().height();
1841+
QPixmap pm(1, 1);
1842+
pm.fill(swatchColor);
1843+
pm = pm.scaled(QSize(h, h));
1844+
1845+
{
1846+
QPainter painter(&pm);
1847+
1848+
QPen pen(parentWidget->palette().foreground(), 1.0);
1849+
painter.setPen(pen);
1850+
painter.drawLine(QPoint(0, 0), QPoint(h - 1, 0));
1851+
painter.drawLine(QPoint(h - 1, 0), QPoint(h - 1, h - 1));
1852+
painter.drawLine(QPoint(h - 1, h - 1), QPoint(0, h - 1));
1853+
painter.drawLine(QPoint(0, h - 1), QPoint(0, 0));
1854+
}
1855+
1856+
return QIcon(pm);
1857+
}
1858+
18381859
float ConvertLinearToSRGB(float linear)
18391860
{
18401861
if(linear <= 0.0031308f)

qrenderdoc/Code/QRDUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ QString TypeString(const SigParameter &sig);
267267
QString D3DSemanticString(const SigParameter &sig);
268268
QString GetComponentString(byte mask);
269269

270+
QIcon MakeSwatchIcon(QWidget *parentWidget, QColor swatchColor);
270271
float ConvertLinearToSRGB(float linear);
271272
void CombineUsageEvents(
272273
ICaptureContext &ctx, const rdcarray<EventUsage> &usage,

qrenderdoc/Windows/BufferViewer.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -4264,6 +4264,27 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff
42644264
RDTreeWidgetItem *n =
42654265
new RDTreeWidgetItem({v.name, VarString(v, c), offsetStr, TypeString(v, c)});
42664266

4267+
// display colour swatch for floats with RGB display
4268+
if((v.flags & ShaderVariableFlags::RGBDisplay) && VarTypeCompType(v.type) == CompType::Float &&
4269+
v.rows == 1 && v.columns >= 1 && v.members.empty())
4270+
{
4271+
QColor swatchColor(0, 0, 0, 255);
4272+
float rgb[3] = {0.0f, 0.0f, 0.0f};
4273+
for(uint8_t col = 0; col < v.columns && col < 4; col++)
4274+
{
4275+
float fval = 0.0f;
4276+
if(v.type == VarType::Float)
4277+
fval = v.value.f32v[col];
4278+
else if(v.type == VarType::Double)
4279+
fval = float(v.value.f64v[col]);
4280+
else if(v.type == VarType::Half)
4281+
fval = float(v.value.f16v[col]);
4282+
rgb[col] = ConvertLinearToSRGB(fval);
4283+
}
4284+
swatchColor.setRgbF(rgb[0], rgb[1], rgb[2], 1.0f);
4285+
n->setIcon(1, MakeSwatchIcon(ui->fixedVars, swatchColor));
4286+
}
4287+
42674288
n->setTag(QVariant::fromValue(FixedVarTag(v.name, baseOffset + c.byteOffset)));
42684289

42694290
root->addChild(n);

qrenderdoc/Windows/ShaderViewer.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -4618,23 +4618,7 @@ bool ShaderViewer::updateWatchVariable(RDTreeWidgetItem *watchItem, const RDTree
46184618
}
46194619
else
46204620
{
4621-
int h = ui->watch->fontMetrics().height();
4622-
QPixmap pm(1, 1);
4623-
pm.fill(swatchColor);
4624-
pm = pm.scaled(QSize(h, h));
4625-
4626-
{
4627-
QPainter painter(&pm);
4628-
4629-
QPen pen(ui->watch->palette().foreground(), 1.0);
4630-
painter.setPen(pen);
4631-
painter.drawLine(QPoint(0, 0), QPoint(h - 1, 0));
4632-
painter.drawLine(QPoint(h - 1, 0), QPoint(h - 1, h - 1));
4633-
painter.drawLine(QPoint(h - 1, h - 1), QPoint(0, h - 1));
4634-
painter.drawLine(QPoint(0, h - 1), QPoint(0, 0));
4635-
}
4636-
4637-
watchItem->setIcon(3, QIcon(pm));
4621+
watchItem->setIcon(3, MakeSwatchIcon(ui->watch, swatchColor));
46384622
}
46394623

46404624
watchItem->setText(3, val);

0 commit comments

Comments
 (0)