本文整理汇总了C++中PixelBuffer::getWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ PixelBuffer::getWidth方法的具体用法?C++ PixelBuffer::getWidth怎么用?C++ PixelBuffer::getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelBuffer
的用法示例。
在下文中一共展示了PixelBuffer::getWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadTexture
void Image::loadTexture(const char *path) {
PixelBuffer<uint8_t> pb;
if(!pb.load(path))
throw "Failed to load texture";
VkFormatProperties &props = formatProperties[VK_FORMAT_R8G8B8A8_UNORM];
bool direct = (props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0;
VkImageSubresource subres = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 };
VkSubresourceLayout sublayout;
createTexture(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_LINEAR, direct ? VK_IMAGE_USAGE_SAMPLED_BIT : VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, pb.getWidth(), pb.getHeight());
vkGetImageSubresourceLayout(vk, image, &subres, &sublayout);
uint8_t *data = NULL;
OBJ_CHECK(vkMapMemory(vk, mem, 0, allocInfo.allocationSize, 0, (void **)&data));
uint32_t x = 0, y = 0;
uint8_t temp[4] = {0, 0, 0, 255};
for (y = 0; y < pb.getHeight(); y++) {
uint32_t *dest = (uint32_t *)data;
uint8_t *src = pb(0, y);
switch (pb.getChannels()) {
case 4:
memcpy(dest, src, pb.getWidth() * 4);
break;
case 3:
for (x = 0; x < pb.getWidth(); x++) {
temp[0] = *src++; // R
temp[1] = *src++; // G
temp[2] = *src++; // B
*dest++ = *(uint32_t *)temp;
}
break;
case 2:
for (x = 0; x < pb.getWidth(); x++) {
temp[0] = *src++; // R
temp[1] = *src++; // G
*dest++ = *(uint32_t *)temp;
}
break;
case 1:
for (x = 0; x < pb.getWidth(); x++) {
temp[0] = *src++; // R
*dest++ = *(uint32_t *)temp;
}
break;
}
data += sublayout.rowPitch;
}
vkUnmapMemory(vk, mem);
if (direct) {
setLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
} else {
// Create a staging image visible to the host to load the texture into with linear tiling
Image staging;
Math::Swap(staging.image, image);
Math::Swap(mem, staging.mem);
Math::Swap(layout, staging.layout);
Math::Swap(imageInfo, staging.imageInfo);
Math::Swap(allocInfo, staging.allocInfo);
staging.setLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
// Now create the actual device-local image and copy into it from the staging image
createTexture(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, pb.getWidth(), pb.getHeight());
setLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
ImageCopy copy_region(pb.getWidth(), pb.getHeight());
vkCmdCopyImage(vk, staging.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©_region);
setLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
vk.flush(); // Wait for the copy command to complete before the staging texture goes out of scope!
}
ImageViewCreateInfo viewInfo(image, imageInfo.format, VK_IMAGE_ASPECT_COLOR_BIT);
OBJ_CHECK(vkCreateImageView(vk, &viewInfo, NULL, &view));
}