mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 03:22:09 +02:00
Merge pull request #611 from overte-org/feature/hdr_lightmaps
Initial support for HDR lightmaps
This commit is contained in:
commit
79a58da068
2 changed files with 66 additions and 2 deletions
|
@ -156,7 +156,7 @@ gpu::TexturePointer TextureUsage::createEmissiveTextureFromImage(Image&& srcImag
|
|||
|
||||
gpu::TexturePointer TextureUsage::createLightmapTextureFromImage(Image&& srcImage, const std::string& srcImageName,
|
||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing) {
|
||||
return process2DTextureColorFromImage(std::move(srcImage), srcImageName, compress, target, false, abortProcessing);
|
||||
return process2DHDRTextureColorFromImage(std::move(srcImage), srcImageName, compress, target, false, abortProcessing);
|
||||
}
|
||||
|
||||
gpu::TexturePointer TextureUsage::createNormalTextureFromNormalImage(Image&& srcImage, const std::string& srcImageName,
|
||||
|
@ -926,6 +926,8 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(Image&& srcImag
|
|||
}
|
||||
} else {
|
||||
if (target == BackendTarget::GLES32) {
|
||||
//TODO: is this correct? It seems that no format is set for uncompressed texture on GLES
|
||||
qDebug() << "TextureUsage::process2DTextureColorFromImage: no format is set for uncompressed texture on GLES";
|
||||
} else {
|
||||
formatGPU = gpu::Element::COLOR_SRGBA_32;
|
||||
formatMip = gpu::Element::COLOR_SBGRA_32;
|
||||
|
@ -954,6 +956,65 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(Image&& srcImag
|
|||
return theTexture;
|
||||
}
|
||||
|
||||
gpu::TexturePointer TextureUsage::process2DHDRTextureColorFromImage(Image&& srcImage, const std::string& srcImageName, bool compress,
|
||||
BackendTarget target, bool isStrict, const std::atomic<bool>& abortProcessing) {
|
||||
PROFILE_RANGE(resource_parse, "process2DHDRTextureColorFromImage");
|
||||
Image image = processSourceImage(std::move(srcImage), false, target);
|
||||
|
||||
bool validAlpha = image.hasAlphaChannel();
|
||||
bool alphaAsMask = false;
|
||||
|
||||
auto hasTargetHDRFormat = isHDRTextureFormatEnabledForTarget(target);
|
||||
if (hasTargetHDRFormat && image.getFormat() != Image::Format_PACKED_FLOAT) {
|
||||
// If the target format is HDR but the image isn't, we need to convert the
|
||||
// image to HDR.
|
||||
image = convertToHDRFormat(std::move(image), GPU_CUBEMAP_HDR_FORMAT);
|
||||
} else if (!hasTargetHDRFormat && image.getFormat() == Image::Format_PACKED_FLOAT) {
|
||||
// If the target format isn't HDR (such as on GLES) but the image is, we need to
|
||||
// convert the image to LDR
|
||||
image = convertToLDRFormat(std::move(image), Image::Format_ARGB32);
|
||||
}
|
||||
|
||||
gpu::TexturePointer theTexture = nullptr;
|
||||
|
||||
if ((image.getWidth() > 0) && (image.getHeight() > 0)) {
|
||||
gpu::Element formatMip;
|
||||
gpu::Element formatGPU;
|
||||
if (target == BackendTarget::GLES32) {
|
||||
if (compress) {
|
||||
// GLES does not support GL_BGRA
|
||||
formatGPU = gpu::Element::COLOR_COMPRESSED_ETC2_SRGBA;
|
||||
formatMip = formatGPU;
|
||||
} else {
|
||||
//TODO: is this correct? It seems that no format is set for uncompressed texture on GLES
|
||||
qDebug() << "TextureUsage::process2DHDRTextureColorFromImage: no format is set for uncompressed texture on GLES";
|
||||
}
|
||||
} else {
|
||||
formatMip = formatGPU = getHDRTextureFormatForTarget(target, compress);
|
||||
}
|
||||
|
||||
if (isStrict) {
|
||||
theTexture = gpu::Texture::createStrict(formatGPU, image.getWidth(), image.getHeight(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR));
|
||||
} else {
|
||||
theTexture = gpu::Texture::create2D(formatGPU, image.getWidth(), image.getHeight(), gpu::Texture::MAX_NUM_MIPS, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR));
|
||||
}
|
||||
theTexture->setSource(srcImageName);
|
||||
auto usage = gpu::Texture::Usage::Builder().withColor();
|
||||
if (validAlpha) {
|
||||
usage.withAlpha();
|
||||
if (alphaAsMask) {
|
||||
usage.withAlphaMask();
|
||||
}
|
||||
}
|
||||
theTexture->setUsage(usage.build());
|
||||
theTexture->setStoredMipFormat(formatMip);
|
||||
theTexture->assignStoredMip(0, image.getByteCount(), image.getBits());
|
||||
convertToTextureWithMips(theTexture.get(), std::move(image), target, abortProcessing);
|
||||
}
|
||||
|
||||
return theTexture;
|
||||
}
|
||||
|
||||
int clampPixelCoordinate(int coordinate, int maxCoordinate) {
|
||||
return coordinate - ((int)(coordinate < 0) * coordinate) + ((int)(coordinate > maxCoordinate) * (maxCoordinate - coordinate));
|
||||
}
|
||||
|
|
|
@ -106,6 +106,8 @@ gpu::TexturePointer createLightmapTextureFromImage(Image&& image, const std::str
|
|||
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||
gpu::TexturePointer process2DTextureColorFromImage(Image&& srcImage, const std::string& srcImageName, bool compress,
|
||||
gpu::BackendTarget target, bool isStrict, const std::atomic<bool>& abortProcessing);
|
||||
gpu::TexturePointer process2DHDRTextureColorFromImage(Image&& srcImage, const std::string& srcImageName, bool compress,
|
||||
gpu::BackendTarget target, bool isStrict, const std::atomic<bool>& abortProcessing);
|
||||
gpu::TexturePointer process2DTextureNormalMapFromImage(Image&& srcImage, const std::string& srcImageName, bool compress,
|
||||
gpu::BackendTarget target, bool isBumpMap, const std::atomic<bool>& abortProcessing);
|
||||
gpu::TexturePointer process2DTextureGrayscaleFromImage(Image&& srcImage, const std::string& srcImageName, bool compress,
|
||||
|
@ -128,7 +130,8 @@ std::pair<gpu::TexturePointer, glm::ivec2> processImage(std::shared_ptr<QIODevic
|
|||
|
||||
void convertToTextureWithMips(gpu::Texture* texture, Image&& image, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing = false, int face = -1);
|
||||
void convertToTexture(gpu::Texture* texture, Image&& image, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing = false, int face = -1, int mipLevel = 0);
|
||||
|
||||
Image convertToHDRFormat(Image&& srcImage, gpu::Element format);
|
||||
Image convertToLDRFormat(Image&& srcImage, Image::Format format);
|
||||
} // namespace image
|
||||
|
||||
#endif // hifi_image_TextureProcessing_h
|
||||
|
|
Loading…
Reference in a new issue