web textures work on image entities, create supports negative materialMappingScale

This commit is contained in:
HifiExperiments 2021-03-22 20:52:39 -07:00
parent a87d6e5182
commit 7ff796af3e
6 changed files with 30 additions and 15 deletions

View file

@ -274,6 +274,7 @@ void WebEntityRenderer::doRender(RenderArgs* args) {
// Try to update the texture // Try to update the texture
OffscreenQmlSurface::TextureAndFence newTextureAndFence; OffscreenQmlSurface::TextureAndFence newTextureAndFence;
QSize windowSize;
bool newTextureAvailable = false; bool newTextureAvailable = false;
if (!resultWithReadLock<bool>([&] { if (!resultWithReadLock<bool>([&] {
if (!_webSurface) { if (!_webSurface) {
@ -281,6 +282,7 @@ void WebEntityRenderer::doRender(RenderArgs* args) {
} }
newTextureAvailable = _webSurface->fetchTexture(newTextureAndFence); newTextureAvailable = _webSurface->fetchTexture(newTextureAndFence);
windowSize = _webSurface->size();
return true; return true;
})) { })) {
return; return;
@ -288,6 +290,8 @@ void WebEntityRenderer::doRender(RenderArgs* args) {
if (newTextureAvailable) { if (newTextureAvailable) {
_texture->setExternalTexture(newTextureAndFence.first, newTextureAndFence.second); _texture->setExternalTexture(newTextureAndFence.first, newTextureAndFence.second);
_texture->setSize(windowSize.width(), windowSize.height());
_texture->setOriginalSize(windowSize.width(), windowSize.height());
} }
static const glm::vec2 texMin(0.0f), texMax(1.0f), topLeft(-0.5f), bottomRight(0.5f); static const glm::vec2 texMin(0.0f), texMax(1.0f), topLeft(-0.5f), bottomRight(0.5f);

View file

@ -322,6 +322,16 @@ bool Texture::isDepthStencilRenderTarget() const {
return (_texelFormat.getSemantic() == gpu::DEPTH) || (_texelFormat.getSemantic() == gpu::DEPTH_STENCIL); return (_texelFormat.getSemantic() == gpu::DEPTH) || (_texelFormat.getSemantic() == gpu::DEPTH_STENCIL);
} }
void Texture::setSize(int width, int height) {
_width = width;
_height = height;
}
void Texture::setOriginalSize(int width, int height) {
_originalWidth = width;
_originalHeight = height;
}
uint16 Texture::evalDimMaxNumMips(uint16 size) { uint16 Texture::evalDimMaxNumMips(uint16 size) {
double largerDim = size; double largerDim = size;
double val = log(largerDim)/log(2.0); double val = log(largerDim)/log(2.0);
@ -894,12 +904,12 @@ const gpu::TexturePointer TextureSource::getGPUTexture() const {
return _gpuTexture; return _gpuTexture;
} }
void TextureSource::resetTexture(gpu::TexturePointer texture) { void TextureSource::resetTexture(const gpu::TexturePointer& texture) {
_gpuTexture = texture; _gpuTexture = texture;
_gpuTextureOperator = nullptr; _gpuTextureOperator = nullptr;
} }
void TextureSource::resetTextureOperator(std::function<gpu::TexturePointer()> textureOperator) { void TextureSource::resetTextureOperator(const std::function<gpu::TexturePointer()>& textureOperator) {
_gpuTexture = nullptr; _gpuTexture = nullptr;
_gpuTextureOperator = textureOperator; _gpuTextureOperator = textureOperator;
} }

View file

@ -417,11 +417,16 @@ public:
Element getTexelFormat() const { return _texelFormat; } Element getTexelFormat() const { return _texelFormat; }
void setSize(int width, int height);
Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); } Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); }
uint16 getWidth() const { return _width; } uint16 getWidth() const { return _width; }
uint16 getHeight() const { return _height; } uint16 getHeight() const { return _height; }
uint16 getDepth() const { return _depth; } uint16 getDepth() const { return _depth; }
void setOriginalSize(int width, int height);
int getOriginalWidth() const { return _originalWidth; }
int getOriginalHeight() const { return _originalHeight; }
// The number of faces is mostly used for cube map, and maybe for stereo ? otherwise it's 1 // The number of faces is mostly used for cube map, and maybe for stereo ? otherwise it's 1
// For cube maps, this means the pixels of the different faces are supposed to be packed back to back in a mip // For cube maps, this means the pixels of the different faces are supposed to be packed back to back in a mip
// as if the height was NUM_FACES time bigger. // as if the height was NUM_FACES time bigger.
@ -615,6 +620,8 @@ protected:
uint16 _width { 1 }; uint16 _width { 1 };
uint16 _height { 1 }; uint16 _height { 1 };
uint16 _depth { 1 }; uint16 _depth { 1 };
int _originalWidth { 0 };
int _originalHeight { 0 };
uint16 _numSamples { 1 }; uint16 _numSamples { 1 };
@ -711,8 +718,8 @@ public:
void setType(int type) { _type = type; } void setType(int type) { _type = type; }
int getType() const { return _type; } int getType() const { return _type; }
void resetTexture(gpu::TexturePointer texture); void resetTexture(const gpu::TexturePointer& texture);
void resetTextureOperator(std::function<gpu::TexturePointer()> textureOperator); void resetTextureOperator(const std::function<gpu::TexturePointer()>& textureOperator);
bool isDefined() const; bool isDefined() const;
std::function<gpu::TexturePointer()> getTextureOperator() const { return _gpuTextureOperator; } std::function<gpu::TexturePointer()> getTextureOperator() const { return _gpuTextureOperator; }

View file

@ -390,8 +390,6 @@ NetworkTexture::NetworkTexture(const NetworkTexture& other) :
_type(other._type), _type(other._type),
_sourceChannel(other._sourceChannel), _sourceChannel(other._sourceChannel),
_currentlyLoadingResourceType(other._currentlyLoadingResourceType), _currentlyLoadingResourceType(other._currentlyLoadingResourceType),
_originalWidth(other._originalWidth),
_originalHeight(other._originalHeight),
_width(other._width), _width(other._width),
_height(other._height), _height(other._height),
_maxNumPixels(other._maxNumPixels), _maxNumPixels(other._maxNumPixels),
@ -467,13 +465,12 @@ void NetworkTexture::setExtra(void* extra) {
void NetworkTexture::setImage(gpu::TexturePointer texture, int originalWidth, void NetworkTexture::setImage(gpu::TexturePointer texture, int originalWidth,
int originalHeight) { int originalHeight) {
_originalWidth = originalWidth;
_originalHeight = originalHeight;
// Passing ownership // Passing ownership
_textureSource->resetTexture(texture); _textureSource->resetTexture(texture);
if (texture) { if (texture) {
texture->setOriginalSize(originalWidth, originalHeight);
_width = texture->getWidth(); _width = texture->getWidth();
_height = texture->getHeight(); _height = texture->getHeight();
setSize(texture->getStoredSize()); setSize(texture->getStoredSize());

View file

@ -58,10 +58,10 @@ public:
QString getType() const override { return "NetworkTexture"; } QString getType() const override { return "NetworkTexture"; }
int getOriginalWidth() const { return _originalWidth; } int getOriginalWidth() const { return _textureSource->getGPUTexture() ? _textureSource->getGPUTexture()->getOriginalWidth() : 0; }
int getOriginalHeight() const { return _originalHeight; } int getOriginalHeight() const { return _textureSource->getGPUTexture() ? _textureSource->getGPUTexture()->getOriginalHeight() : 0; }
int getWidth() const { return _width; } int getWidth() const { return _textureSource->getGPUTexture() ? _textureSource->getGPUTexture()->getWidth() : 0; }
int getHeight() const { return _height; } int getHeight() const { return _textureSource->getGPUTexture() ? _textureSource->getGPUTexture()->getHeight() : 0; }
image::TextureUsage::Type getTextureType() const { return _type; } image::TextureUsage::Type getTextureType() const { return _type; }
gpu::TexturePointer getFallbackTexture() const; gpu::TexturePointer getFallbackTexture() const;
@ -143,8 +143,6 @@ private:
// mip offsets to change. // mip offsets to change.
ktx::KTXDescriptorPointer _originalKtxDescriptor; ktx::KTXDescriptorPointer _originalKtxDescriptor;
int _originalWidth { 0 };
int _originalHeight { 0 };
int _width { 0 }; int _width { 0 };
int _height { 0 }; int _height { 0 };
int _maxNumPixels { ABSOLUTE_MAX_TEXTURE_NUM_PIXELS }; int _maxNumPixels { ABSOLUTE_MAX_TEXTURE_NUM_PIXELS };

View file

@ -918,7 +918,6 @@ const GROUPS = [
label: "Material Scale", label: "Material Scale",
type: "vec2", type: "vec2",
vec2Type: "xyz", vec2Type: "xyz",
min: 0,
step: 0.1, step: 0.1,
decimals: 4, decimals: 4,
subLabels: [ "x", "y" ], subLabels: [ "x", "y" ],