mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 13:13:27 +02:00
make TextureCache work with DependancyManager
This commit is contained in:
parent
c6b033fa0e
commit
7d75d2d1bf
13 changed files with 70 additions and 78 deletions
|
@ -620,10 +620,10 @@ void Application::paintGL() {
|
|||
// Set the desired FBO texture size. If it hasn't changed, this does nothing.
|
||||
// Otherwise, it must rebuild the FBOs
|
||||
if (OculusManager::isConnected()) {
|
||||
TextureCache::getInstance()->setFrameBufferSize(OculusManager::getRenderTargetSize());
|
||||
DependencyManager::get<TextureCache>()->setFrameBufferSize(OculusManager::getRenderTargetSize());
|
||||
} else {
|
||||
QSize fbSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
|
||||
TextureCache::getInstance()->setFrameBufferSize(fbSize);
|
||||
DependencyManager::get<TextureCache>()->setFrameBufferSize(fbSize);
|
||||
}
|
||||
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
|
@ -713,7 +713,7 @@ void Application::paintGL() {
|
|||
_glowEffect.prepare();
|
||||
|
||||
// Viewport is assigned to the size of the framebuffer
|
||||
QSize size = TextureCache::getInstance()->getPrimaryFramebufferObject()->size();
|
||||
QSize size = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->size();
|
||||
glViewport(0, 0, size.width(), size.height());
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
@ -2043,7 +2043,7 @@ void Application::init() {
|
|||
connect(_myAvatar, &MyAvatar::transformChanged, this, &Application::bumpSettings);
|
||||
|
||||
// make sure our texture cache knows about window size changes
|
||||
TextureCache::getInstance()->associateWithWidget(getGLWidget());
|
||||
DependencyManager::get<TextureCache>()->associateWithWidget(getGLWidget());
|
||||
}
|
||||
|
||||
void Application::closeMirrorView() {
|
||||
|
@ -2774,7 +2774,7 @@ glm::vec3 Application::getSunDirection() {
|
|||
|
||||
void Application::updateShadowMap() {
|
||||
PerformanceTimer perfTimer("shadowMap");
|
||||
QOpenGLFramebufferObject* fbo = TextureCache::getInstance()->getShadowFramebufferObject();
|
||||
QOpenGLFramebufferObject* fbo = DependencyManager::get<TextureCache>()->getShadowFramebufferObject();
|
||||
fbo->bind();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -2939,7 +2939,7 @@ void Application::setupWorldLight() {
|
|||
}
|
||||
|
||||
QImage Application::renderAvatarBillboard() {
|
||||
TextureCache::getInstance()->getPrimaryFramebufferObject()->bind();
|
||||
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->bind();
|
||||
|
||||
// the "glow" here causes an alpha of one
|
||||
Glower glower;
|
||||
|
@ -2950,7 +2950,7 @@ QImage Application::renderAvatarBillboard() {
|
|||
QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
|
||||
glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
|
||||
|
||||
TextureCache::getInstance()->getPrimaryFramebufferObject()->release();
|
||||
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->release();
|
||||
|
||||
return image;
|
||||
}
|
||||
|
@ -3301,12 +3301,12 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) {
|
|||
|
||||
// set the bounds of rear mirror view
|
||||
if (billboard) {
|
||||
QSize size = TextureCache::getInstance()->getFrameBufferSize();
|
||||
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
||||
glViewport(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
|
||||
glScissor(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
|
||||
} else {
|
||||
// if not rendering the billboard, the region is in device independent coordinates; must convert to device
|
||||
QSize size = TextureCache::getInstance()->getFrameBufferSize();
|
||||
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
||||
float ratio = QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
|
||||
int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
|
||||
glViewport(x, size.height() - y - height, width, height);
|
||||
|
|
|
@ -205,7 +205,7 @@ void MetavoxelSystem::render() {
|
|||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, true);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
@ -251,7 +251,7 @@ void MetavoxelSystem::render() {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false);
|
||||
|
||||
_baseHeightfieldProgram.release();
|
||||
|
||||
|
@ -348,7 +348,7 @@ void MetavoxelSystem::render() {
|
|||
}
|
||||
|
||||
if (!_voxelBaseBatches.isEmpty()) {
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, true);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glDisable(GL_BLEND);
|
||||
|
@ -383,7 +383,7 @@ void MetavoxelSystem::render() {
|
|||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false);
|
||||
|
||||
if (!_voxelSplatBatches.isEmpty()) {
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
@ -463,7 +463,7 @@ void MetavoxelSystem::render() {
|
|||
}
|
||||
|
||||
if (!_hermiteBatches.isEmpty() && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, true);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
|
@ -486,7 +486,7 @@ void MetavoxelSystem::render() {
|
|||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false);
|
||||
}
|
||||
_hermiteBatches.clear();
|
||||
|
||||
|
@ -797,7 +797,7 @@ void MetavoxelSystem::applyMaterialEdit(const MetavoxelEditMessage& message, boo
|
|||
Q_ARG(bool, reliable));
|
||||
return;
|
||||
}
|
||||
QSharedPointer<NetworkTexture> texture = TextureCache::getInstance()->getTexture(
|
||||
QSharedPointer<NetworkTexture> texture = DependencyManager::get<TextureCache>()->getTexture(
|
||||
material->getDiffuse(), SPLAT_TEXTURE);
|
||||
if (texture->isLoaded()) {
|
||||
MetavoxelEditMessage newMessage = message;
|
||||
|
@ -1180,7 +1180,7 @@ void VoxelBuffer::render(bool cursor) {
|
|||
for (int i = 0; i < _materials.size(); i++) {
|
||||
const SharedObjectPointer material = _materials.at(i);
|
||||
if (material) {
|
||||
_networkTextures[i] = TextureCache::getInstance()->getTexture(
|
||||
_networkTextures[i] = DependencyManager::get<TextureCache>()->getTexture(
|
||||
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
|
||||
}
|
||||
}
|
||||
|
@ -2234,7 +2234,7 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g
|
|||
for (int i = 0; i < materials.size(); i++) {
|
||||
const SharedObjectPointer& material = materials.at(i);
|
||||
if (material) {
|
||||
_networkTextures[i] = TextureCache::getInstance()->getTexture(
|
||||
_networkTextures[i] = DependencyManager::get<TextureCache>()->getTexture(
|
||||
static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -473,7 +473,7 @@ void ModelUploader::processCheck() {
|
|||
QMessageBox::Ok);
|
||||
GeometryCache::getInstance()->refresh(_url);
|
||||
foreach (const QByteArray& filename, _textureFilenames) {
|
||||
TextureCache::getInstance()->refresh(_textureBase + filename);
|
||||
DependencyManager::get<TextureCache>()->refresh(_textureBase + filename);
|
||||
}
|
||||
deleteLater();
|
||||
break;
|
||||
|
|
|
@ -449,7 +449,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p
|
|||
if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) {
|
||||
Application::getInstance()->getGlowEffect()->prepare();
|
||||
} else {
|
||||
TextureCache::getInstance()->getPrimaryFramebufferObject()->bind();
|
||||
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
@ -555,8 +555,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p
|
|||
QOpenGLFramebufferObject* fbo = Application::getInstance()->getGlowEffect()->render(true);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo->texture());
|
||||
} else {
|
||||
TextureCache::getInstance()->getPrimaryFramebufferObject()->release();
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getPrimaryFramebufferObject()->texture());
|
||||
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->release();
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->texture());
|
||||
}
|
||||
|
||||
// restore our normal viewport
|
||||
|
|
|
@ -98,7 +98,7 @@ void AmbientOcclusionEffect::render() {
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getPrimaryDepthTextureID());
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimaryDepthTextureID());
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, _rotationTextureID);
|
||||
|
@ -116,7 +116,7 @@ void AmbientOcclusionEffect::render() {
|
|||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
const int VIEWPORT_X_INDEX = 0;
|
||||
const int VIEWPORT_WIDTH_INDEX = 2;
|
||||
QOpenGLFramebufferObject* primaryFBO = TextureCache::getInstance()->getPrimaryFramebufferObject();
|
||||
QOpenGLFramebufferObject* primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject();
|
||||
float sMin = viewport[VIEWPORT_X_INDEX] / (float)primaryFBO->width();
|
||||
float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)primaryFBO->width();
|
||||
|
||||
|
@ -141,7 +141,7 @@ void AmbientOcclusionEffect::render() {
|
|||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// now render secondary to primary with 4x4 blur
|
||||
TextureCache::getInstance()->getPrimaryFramebufferObject()->bind();
|
||||
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->bind();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
|
||||
|
|
|
@ -37,7 +37,7 @@ void DeferredLightingEffect::init() {
|
|||
}
|
||||
|
||||
void DeferredLightingEffect::bindSimpleProgram() {
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, true, true);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true, true);
|
||||
_simpleProgram.bind();
|
||||
_simpleProgram.setUniformValue(_glowIntensityLocation, Application::getInstance()->getGlowEffect()->getIntensity());
|
||||
glDisable(GL_BLEND);
|
||||
|
@ -46,7 +46,7 @@ void DeferredLightingEffect::bindSimpleProgram() {
|
|||
void DeferredLightingEffect::releaseSimpleProgram() {
|
||||
glEnable(GL_BLEND);
|
||||
_simpleProgram.release();
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, false, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false, false);
|
||||
}
|
||||
|
||||
void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks) {
|
||||
|
@ -117,15 +117,15 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu
|
|||
|
||||
void DeferredLightingEffect::prepare() {
|
||||
// clear the normal and specular buffers
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(false, true, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(false, true, false);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(false, false, true);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(false, false, true);
|
||||
// clearing to zero alpha for specular causes problems on my Nvidia card; clear to lowest non-zero value instead
|
||||
const float MAX_SPECULAR_EXPONENT = 128.0f;
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f / MAX_SPECULAR_EXPONENT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, false, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false, false);
|
||||
}
|
||||
|
||||
void DeferredLightingEffect::render() {
|
||||
|
@ -138,7 +138,7 @@ void DeferredLightingEffect::render() {
|
|||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(false);
|
||||
|
||||
QOpenGLFramebufferObject* primaryFBO = TextureCache::getInstance()->getPrimaryFramebufferObject();
|
||||
QOpenGLFramebufferObject* primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject();
|
||||
primaryFBO->release();
|
||||
|
||||
QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject();
|
||||
|
@ -148,13 +148,13 @@ void DeferredLightingEffect::render() {
|
|||
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getPrimaryNormalTextureID());
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimaryNormalTextureID());
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getPrimarySpecularTextureID());
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimarySpecularTextureID());
|
||||
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getPrimaryDepthTextureID());
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPrimaryDepthTextureID());
|
||||
|
||||
// get the viewport side (left, right, both)
|
||||
int viewport[4];
|
||||
|
@ -173,7 +173,7 @@ void DeferredLightingEffect::render() {
|
|||
bool shadowsEnabled = Menu::getInstance()->getShadowsEnabled();
|
||||
if (shadowsEnabled) {
|
||||
glActiveTexture(GL_TEXTURE4);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getShadowDepthTextureID());
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getShadowDepthTextureID());
|
||||
|
||||
program = &_directionalLightShadowMap;
|
||||
locations = &_directionalLightShadowMapLocations;
|
||||
|
@ -188,7 +188,7 @@ void DeferredLightingEffect::render() {
|
|||
program->bind();
|
||||
}
|
||||
program->setUniformValue(locations->shadowScale,
|
||||
1.0f / TextureCache::getInstance()->getShadowFramebufferObject()->width());
|
||||
1.0f / DependencyManager::get<TextureCache>()->getShadowFramebufferObject()->width());
|
||||
|
||||
} else {
|
||||
program->bind();
|
||||
|
|
|
@ -712,19 +712,19 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
|
|||
QSharedPointer<NetworkTexture> matchingTexture = QSharedPointer<NetworkTexture>();
|
||||
if (part.diffuseTextureName == name) {
|
||||
part.diffuseTexture =
|
||||
TextureCache::getInstance()->getTexture(url, DEFAULT_TEXTURE,
|
||||
DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE,
|
||||
_geometry.meshes[i].isEye, QByteArray());
|
||||
part.diffuseTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.normalTextureName == name) {
|
||||
part.normalTexture = TextureCache::getInstance()->getTexture(url, DEFAULT_TEXTURE,
|
||||
part.normalTexture = DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.normalTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.specularTextureName == name) {
|
||||
part.specularTexture = TextureCache::getInstance()->getTexture(url, DEFAULT_TEXTURE,
|
||||
part.specularTexture = DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.specularTexture->setLoadPriorities(_loadPriorities);
|
||||
} else if (part.emissiveTextureName == name) {
|
||||
part.emissiveTexture = TextureCache::getInstance()->getTexture(url, DEFAULT_TEXTURE,
|
||||
part.emissiveTexture = DependencyManager::get<TextureCache>()->getTexture(url, DEFAULT_TEXTURE,
|
||||
false, QByteArray());
|
||||
part.emissiveTexture->setLoadPriorities(_loadPriorities);
|
||||
}
|
||||
|
@ -925,28 +925,28 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
|||
foreach (const FBXMeshPart& part, mesh.parts) {
|
||||
NetworkMeshPart networkPart;
|
||||
if (!part.diffuseTexture.filename.isEmpty()) {
|
||||
networkPart.diffuseTexture = TextureCache::getInstance()->getTexture(
|
||||
networkPart.diffuseTexture = DependencyManager::get<TextureCache>()->getTexture(
|
||||
_textureBase.resolved(QUrl(part.diffuseTexture.filename)), DEFAULT_TEXTURE,
|
||||
mesh.isEye, part.diffuseTexture.content);
|
||||
networkPart.diffuseTextureName = part.diffuseTexture.name;
|
||||
networkPart.diffuseTexture->setLoadPriorities(_loadPriorities);
|
||||
}
|
||||
if (!part.normalTexture.filename.isEmpty()) {
|
||||
networkPart.normalTexture = TextureCache::getInstance()->getTexture(
|
||||
networkPart.normalTexture = DependencyManager::get<TextureCache>()->getTexture(
|
||||
_textureBase.resolved(QUrl(part.normalTexture.filename)), NORMAL_TEXTURE,
|
||||
false, part.normalTexture.content);
|
||||
networkPart.normalTextureName = part.normalTexture.name;
|
||||
networkPart.normalTexture->setLoadPriorities(_loadPriorities);
|
||||
}
|
||||
if (!part.specularTexture.filename.isEmpty()) {
|
||||
networkPart.specularTexture = TextureCache::getInstance()->getTexture(
|
||||
networkPart.specularTexture = DependencyManager::get<TextureCache>()->getTexture(
|
||||
_textureBase.resolved(QUrl(part.specularTexture.filename)), SPECULAR_TEXTURE,
|
||||
false, part.specularTexture.content);
|
||||
networkPart.specularTextureName = part.specularTexture.name;
|
||||
networkPart.specularTexture->setLoadPriorities(_loadPriorities);
|
||||
}
|
||||
if (!part.emissiveTexture.filename.isEmpty()) {
|
||||
networkPart.emissiveTexture = TextureCache::getInstance()->getTexture(
|
||||
networkPart.emissiveTexture = DependencyManager::get<TextureCache>()->getTexture(
|
||||
_textureBase.resolved(QUrl(part.emissiveTexture.filename)), EMISSIVE_TEXTURE,
|
||||
false, part.emissiveTexture.content);
|
||||
networkPart.emissiveTextureName = part.emissiveTexture.name;
|
||||
|
|
|
@ -41,8 +41,8 @@ GlowEffect::~GlowEffect() {
|
|||
|
||||
QOpenGLFramebufferObject* GlowEffect::getFreeFramebufferObject() const {
|
||||
return (_isOddFrame ?
|
||||
TextureCache::getInstance()->getSecondaryFramebufferObject():
|
||||
TextureCache::getInstance()->getTertiaryFramebufferObject());
|
||||
DependencyManager::get<TextureCache>()->getSecondaryFramebufferObject():
|
||||
DependencyManager::get<TextureCache>()->getTertiaryFramebufferObject());
|
||||
}
|
||||
|
||||
static ProgramObject* createProgram(const QString& name) {
|
||||
|
@ -88,7 +88,7 @@ void GlowEffect::init() {
|
|||
}
|
||||
|
||||
void GlowEffect::prepare() {
|
||||
TextureCache::getInstance()->getPrimaryFramebufferObject()->bind();
|
||||
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
_isEmpty = true;
|
||||
|
@ -122,7 +122,7 @@ static void maybeRelease(QOpenGLFramebufferObject* fbo) {
|
|||
QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
|
||||
PerformanceTimer perfTimer("glowEffect");
|
||||
|
||||
QOpenGLFramebufferObject* primaryFBO = TextureCache::getInstance()->getPrimaryFramebufferObject();
|
||||
QOpenGLFramebufferObject* primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject();
|
||||
primaryFBO->release();
|
||||
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
|
||||
|
||||
|
@ -138,7 +138,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
|
|||
glDepthMask(GL_FALSE);
|
||||
|
||||
QOpenGLFramebufferObject* destFBO = toTexture ?
|
||||
TextureCache::getInstance()->getSecondaryFramebufferObject() : NULL;
|
||||
DependencyManager::get<TextureCache>()->getSecondaryFramebufferObject() : NULL;
|
||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) {
|
||||
// copy the primary to the screen
|
||||
if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) {
|
||||
|
@ -160,9 +160,9 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
|
|||
} else {
|
||||
// diffuse into the secondary/tertiary (alternating between frames)
|
||||
QOpenGLFramebufferObject* oldDiffusedFBO =
|
||||
TextureCache::getInstance()->getSecondaryFramebufferObject();
|
||||
DependencyManager::get<TextureCache>()->getSecondaryFramebufferObject();
|
||||
QOpenGLFramebufferObject* newDiffusedFBO =
|
||||
TextureCache::getInstance()->getTertiaryFramebufferObject();
|
||||
DependencyManager::get<TextureCache>()->getTertiaryFramebufferObject();
|
||||
if (_isOddFrame) {
|
||||
qSwap(oldDiffusedFBO, newDiffusedFBO);
|
||||
}
|
||||
|
|
|
@ -749,7 +749,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
}
|
||||
|
||||
|
||||
/*TextureCache::getInstance()->setPrimaryDrawBuffers(
|
||||
/*DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(
|
||||
mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE,
|
||||
mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE,
|
||||
mode == DEFAULT_RENDER_MODE);
|
||||
|
@ -789,7 +789,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
opaqueMeshPartsRendered += renderMeshes(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, true, true, false, args);
|
||||
|
||||
// render translucent meshes afterwards
|
||||
//TextureCache::getInstance()->setPrimaryDrawBuffers(false, true, true);
|
||||
//DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(false, true, true);
|
||||
{
|
||||
GLenum buffers[2];
|
||||
int bufferCount = 0;
|
||||
|
@ -814,7 +814,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
GLBATCH(glDepthMask)(false);
|
||||
GLBATCH(glDepthFunc)(GL_LEQUAL);
|
||||
|
||||
//TextureCache::getInstance()->setPrimaryDrawBuffers(true);
|
||||
//DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true);
|
||||
{
|
||||
GLenum buffers[1];
|
||||
int bufferCount = 0;
|
||||
|
@ -1705,7 +1705,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
|||
}
|
||||
|
||||
|
||||
/*TextureCache::getInstance()->setPrimaryDrawBuffers(
|
||||
/*DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(
|
||||
mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE,
|
||||
mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE,
|
||||
mode == DEFAULT_RENDER_MODE);
|
||||
|
@ -1745,7 +1745,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
|||
opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, true, true, false, args);
|
||||
|
||||
// render translucent meshes afterwards
|
||||
//TextureCache::getInstance()->setPrimaryDrawBuffers(false, true, true);
|
||||
//DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(false, true, true);
|
||||
{
|
||||
GLenum buffers[2];
|
||||
int bufferCount = 0;
|
||||
|
@ -1770,7 +1770,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
|||
GLBATCH(glDepthMask)(false);
|
||||
GLBATCH(glDepthFunc)(GL_LEQUAL);
|
||||
|
||||
//TextureCache::getInstance()->setPrimaryDrawBuffers(true);
|
||||
//DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true);
|
||||
{
|
||||
GLenum buffers[1];
|
||||
int bufferCount = 0;
|
||||
|
@ -2446,7 +2446,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
if (showDiffuse && diffuseMap) {
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, diffuseMap->getID());
|
||||
} else {
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, TextureCache::getInstance()->getWhiteTextureID());
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getWhiteTextureID());
|
||||
}
|
||||
|
||||
if (locations->texcoordMatrices >= 0) {
|
||||
|
@ -2464,7 +2464,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
GLBATCH(glActiveTexture)(GL_TEXTURE1);
|
||||
Texture* normalMap = networkPart.normalTexture.data();
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, !normalMap ?
|
||||
TextureCache::getInstance()->getBlueTextureID() : normalMap->getID());
|
||||
DependencyManager::get<TextureCache>()->getBlueTextureID() : normalMap->getID());
|
||||
GLBATCH(glActiveTexture)(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
|
@ -2472,7 +2472,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->specularTextureUnit);
|
||||
Texture* specularMap = networkPart.specularTexture.data();
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, !specularMap ?
|
||||
TextureCache::getInstance()->getWhiteTextureID() : specularMap->getID());
|
||||
DependencyManager::get<TextureCache>()->getWhiteTextureID() : specularMap->getID());
|
||||
GLBATCH(glActiveTexture)(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
|
@ -2493,7 +2493,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->emissiveTextureUnit);
|
||||
Texture* emissiveMap = networkPart.emissiveTexture.data();
|
||||
GLBATCH(glBindTexture)(GL_TEXTURE_2D, !emissiveMap ?
|
||||
TextureCache::getInstance()->getWhiteTextureID() : emissiveMap->getID());
|
||||
DependencyManager::get<TextureCache>()->getWhiteTextureID() : emissiveMap->getID());
|
||||
GLBATCH(glActiveTexture)(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,6 @@
|
|||
|
||||
#include "TextureCache.h"
|
||||
|
||||
TextureCache* TextureCache::getInstance() {
|
||||
static TextureCache instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
|
||||
TextureCache::TextureCache() :
|
||||
_permutationNormalTextureID(0),
|
||||
_whiteTextureID(0),
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QMap>
|
||||
#include <QGLWidget>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include <ResourceCache.h>
|
||||
|
||||
#include "InterfaceConfig.h"
|
||||
|
@ -29,16 +30,11 @@ typedef QSharedPointer<NetworkTexture> NetworkTexturePointer;
|
|||
enum TextureType { DEFAULT_TEXTURE, NORMAL_TEXTURE, SPECULAR_TEXTURE, EMISSIVE_TEXTURE, SPLAT_TEXTURE };
|
||||
|
||||
/// Stores cached textures, including render-to-texture targets.
|
||||
class TextureCache : public ResourceCache {
|
||||
class TextureCache : public ResourceCache, public DependencyManager::Dependency {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
static TextureCache* getInstance();
|
||||
|
||||
TextureCache();
|
||||
virtual ~TextureCache();
|
||||
|
||||
void associateWithWidget(QGLWidget* widget);
|
||||
|
||||
/// Sets the desired texture resolution for the framebuffer objects.
|
||||
|
@ -98,7 +94,9 @@ protected:
|
|||
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra);
|
||||
|
||||
private:
|
||||
|
||||
TextureCache();
|
||||
virtual ~TextureCache();
|
||||
friend class DependencyManager;
|
||||
friend class DilatableNetworkTexture;
|
||||
|
||||
QOpenGLFramebufferObject* createFramebufferObject();
|
||||
|
|
|
@ -916,7 +916,7 @@ void MaterialControl::updateTexture() {
|
|||
_texture.clear();
|
||||
return;
|
||||
}
|
||||
_texture = TextureCache::getInstance()->getTexture(material->getDiffuse(), SPLAT_TEXTURE);
|
||||
_texture = DependencyManager::get<TextureCache>()->getTexture(material->getDiffuse(), SPLAT_TEXTURE);
|
||||
if (_texture) {
|
||||
if (_texture->isLoaded()) {
|
||||
textureLoaded();
|
||||
|
|
|
@ -1170,7 +1170,7 @@ void VoxelSystem::render() {
|
|||
void VoxelSystem::applyScaleAndBindProgram(bool texture) {
|
||||
if (texture) {
|
||||
bindPerlinModulateProgram();
|
||||
glBindTexture(GL_TEXTURE_2D, TextureCache::getInstance()->getPermutationNormalTextureID());
|
||||
glBindTexture(GL_TEXTURE_2D, DependencyManager::get<TextureCache>()->getPermutationNormalTextureID());
|
||||
} else {
|
||||
_program.bind();
|
||||
}
|
||||
|
@ -1178,7 +1178,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) {
|
|||
glPushMatrix();
|
||||
glScalef(_treeScale, _treeScale, _treeScale);
|
||||
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, true);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true);
|
||||
}
|
||||
|
||||
void VoxelSystem::removeScaleAndReleaseProgram(bool texture) {
|
||||
|
@ -1192,7 +1192,7 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) {
|
|||
_program.release();
|
||||
}
|
||||
|
||||
TextureCache::getInstance()->setPrimaryDrawBuffers(true, false);
|
||||
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, false);
|
||||
}
|
||||
|
||||
int VoxelSystem::_nodeCount = 0;
|
||||
|
|
Loading…
Reference in a new issue