Add method to change texture colors
diff --git a/tests/tony_objs.cpp b/tests/tony_objs.cpp
index 076bf03..de18601 100644
--- a/tests/tony_objs.cpp
+++ b/tests/tony_objs.cpp
@@ -114,7 +114,6 @@
xglCmdBindDescriptorSet(commandBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
}
-
XglTextureObj::XglTextureObj(XglDevice *device):
m_texture(XGL_NULL_HANDLE),
m_textureMem(XGL_NULL_HANDLE),
@@ -122,8 +121,8 @@
{
m_device = device;
const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM };
- const XGL_INT tex_width = 16;
- const XGL_INT tex_height = 16;
+ m_texWidth = 16;
+ m_texHeight = 16;
const uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
XGL_RESULT err;
XGL_UINT i;
@@ -137,7 +136,7 @@
.pNext = NULL,
.imageType = XGL_IMAGE_2D,
.format = tex_format,
- .extent = { tex_width, tex_height, 1 },
+ .extent = { m_texWidth, m_texHeight, 1 },
.mipLevels = 1,
.arraySize = 1,
.samples = 1,
@@ -217,13 +216,14 @@
err = xglGetImageSubresourceInfo(m_texture, &subres,
XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout);
assert(!err && layout_size == sizeof(layout));
+ m_rowPitch = layout.rowPitch;
err = xglMapMemory(m_textureMem, 0, &data);
assert(!err);
- for (y = 0; y < tex_height; y++) {
+ for (y = 0; y < m_texHeight; y++) {
uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
- for (x = 0; x < tex_width; x++)
+ for (x = 0; x < m_texWidth; x++)
row[x] = tex_colors[(x & 1) ^ (y & 1)];
}
@@ -234,7 +234,24 @@
}
+void XglTextureObj::ChangeColors(uint32_t color1, uint32_t color2)
+{
+ XGL_RESULT err;
+ const uint32_t tex_colors[2] = { color1, color2 };
+ XGL_VOID *data;
+ err = xglMapMemory(m_textureMem, 0, &data);
+ assert(!err);
+
+ for (int y = 0; y < m_texHeight; y++) {
+ uint32_t *row = (uint32_t *) ((char *) data + m_rowPitch * y);
+ for (int x = 0; x < m_texWidth; x++)
+ row[x] = tex_colors[(x & 1) ^ (y & 1)];
+ }
+
+ err = xglUnmapMemory(m_textureMem);
+ assert(!err);
+}
XglSamplerObj::XglSamplerObj(XglDevice *device)
{
diff --git a/tests/xglrenderframework.h b/tests/xglrenderframework.h
index 8757ea3..9dfcb61 100644
--- a/tests/xglrenderframework.h
+++ b/tests/xglrenderframework.h
@@ -137,6 +137,7 @@
{
public:
XglTextureObj(XglDevice *device);
+ void ChangeColors(uint32_t color1, uint32_t color2);
XGL_IMAGE m_texture;
XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
XGL_GPU_MEMORY m_textureMem;
@@ -144,6 +145,9 @@
protected:
XglDevice *m_device;
XGL_IMAGE_VIEW m_textureView;
+ int m_texHeight;
+ int m_texWidth;
+ int m_rowPitch;
};